Row.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /******************************************************************************
  2. Copyright (C) 2023 by Dennis Sädtler <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <Idian/ComboBox.hpp>
  16. #include <Idian/DoubleSpinBox.hpp>
  17. #include <Idian/PropertiesList.hpp>
  18. #include <Idian/SpinBox.hpp>
  19. #include <Idian/ToggleSwitch.hpp>
  20. #include <Idian/Utils.hpp>
  21. #include <QCheckBox>
  22. #include <QFrame>
  23. #include <QLabel>
  24. #include <QLayout>
  25. #include <QMouseEvent>
  26. #include <QScrollArea>
  27. #include <QWidget>
  28. namespace idian {
  29. // Base class mostly so adding stuff to a list is easier
  30. class GenericRow : public QFrame, public Utils {
  31. Q_OBJECT
  32. public:
  33. GenericRow(QWidget *parent = nullptr) : QFrame(parent), Utils(this) { setAccessibleName(""); };
  34. virtual void setTitle(const QString &title) = 0;
  35. virtual void setDescription(const QString &description) = 0;
  36. };
  37. // Row widget containing one or more controls
  38. class Row : public GenericRow {
  39. Q_OBJECT
  40. public:
  41. Row(QWidget *parent = nullptr);
  42. void setPrefix(QWidget *w, bool autoConnect = true);
  43. void setSuffix(QWidget *w, bool autoConnect = true);
  44. bool hasPrefix() { return prefix_; }
  45. bool hasSuffix() { return suffix_; }
  46. QWidget *prefix() const { return prefix_; }
  47. QWidget *suffix() const { return suffix_; }
  48. void setPrefixEnabled(bool enabled);
  49. void setSuffixEnabled(bool enabled);
  50. virtual void setTitle(const QString &title) override;
  51. virtual void setDescription(const QString &description) override;
  52. void showTitle(bool visible);
  53. void showDescription(bool visible);
  54. void setBuddy(QWidget *w);
  55. void setChangeCursor(bool change);
  56. signals:
  57. void clicked();
  58. protected:
  59. void enterEvent(QEnterEvent *) override;
  60. void leaveEvent(QEvent *) override;
  61. void mouseReleaseEvent(QMouseEvent *) override;
  62. void keyReleaseEvent(QKeyEvent *) override;
  63. bool hasDescription() const { return descriptionLabel != nullptr; }
  64. void focusInEvent(QFocusEvent *event) override
  65. {
  66. Utils::showKeyFocused(event);
  67. QFrame::focusInEvent(event);
  68. }
  69. void focusOutEvent(QFocusEvent *event) override
  70. {
  71. Utils::hideKeyFocused(event);
  72. QFrame::focusOutEvent(event);
  73. }
  74. private:
  75. QGridLayout *layout;
  76. QVBoxLayout *labelLayout = nullptr;
  77. QLabel *nameLabel = nullptr;
  78. QLabel *descriptionLabel = nullptr;
  79. QWidget *prefix_ = nullptr;
  80. QWidget *suffix_ = nullptr;
  81. QWidget *buddyWidget = nullptr;
  82. void connectBuddyWidget(QWidget *widget);
  83. bool changeCursor = false;
  84. };
  85. // Collapsible row expand button
  86. class ExpandButton : public QAbstractButton, public Utils {
  87. Q_OBJECT
  88. private:
  89. QPixmap extendDown;
  90. QPixmap extendUp;
  91. friend class CollapsibleRow;
  92. protected:
  93. explicit ExpandButton(QWidget *parent = nullptr);
  94. void paintEvent(QPaintEvent *) override;
  95. void focusInEvent(QFocusEvent *event) override
  96. {
  97. Utils::showKeyFocused(event);
  98. QAbstractButton::focusInEvent(event);
  99. }
  100. void focusOutEvent(QFocusEvent *event) override
  101. {
  102. Utils::hideKeyFocused(event);
  103. QAbstractButton::focusOutEvent(event);
  104. }
  105. };
  106. class RowFrame : protected QFrame, protected Utils {
  107. Q_OBJECT
  108. signals:
  109. void clicked();
  110. protected:
  111. explicit RowFrame(QWidget *parent = nullptr);
  112. void enterEvent(QEnterEvent *) override;
  113. void leaveEvent(QEvent *) override;
  114. void focusInEvent(QFocusEvent *event) override
  115. {
  116. Utils::showKeyFocused(event);
  117. QWidget::focusInEvent(event);
  118. }
  119. void focusOutEvent(QFocusEvent *event) override
  120. {
  121. Utils::hideKeyFocused(event);
  122. QWidget::focusOutEvent(event);
  123. }
  124. private:
  125. friend class CollapsibleRow;
  126. };
  127. // Collapsible Generic OBS property container
  128. class CollapsibleRow : public GenericRow {
  129. Q_OBJECT
  130. public:
  131. CollapsibleRow(QWidget *parent = nullptr);
  132. void setCheckable(bool check);
  133. bool isCheckable() { return checkable; }
  134. void setChecked(bool checked);
  135. bool isChecked() { return toggleSwitch->isChecked(); };
  136. virtual void setTitle(const QString &title) override;
  137. virtual void setDescription(const QString &description) override;
  138. void addRow(GenericRow *actionRow);
  139. signals:
  140. void toggled(bool checked);
  141. private:
  142. void toggleVisibility();
  143. QPixmap extendDown;
  144. QPixmap extendUp;
  145. QVBoxLayout *layout;
  146. RowFrame *rowWidget;
  147. QHBoxLayout *rowLayout;
  148. Row *actionRow;
  149. QFrame *expandFrame;
  150. QHBoxLayout *btnLayout;
  151. ExpandButton *expandButton;
  152. PropertiesList *propertyList;
  153. ToggleSwitch *toggleSwitch = nullptr;
  154. bool checkable = false;
  155. };
  156. } // namespace idian