Row.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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/PropertiesList.hpp>
  16. #include "../../OBSIdianWidget.hpp"
  17. #include "../../OBSToggleSwitch.hpp"
  18. #include "../../OBSComboBox.hpp"
  19. #include "../../OBSSpinBox.hpp"
  20. #include "../../OBSDoubleSpinBox.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 OBSIdianUtils {
  31. Q_OBJECT
  32. public:
  33. GenericRow(QWidget *parent = nullptr) : QFrame(parent), OBSIdianUtils(this) { setAccessibleName(""); };
  34. };
  35. // Row widget containing one or more controls
  36. class Row : public GenericRow {
  37. Q_OBJECT
  38. public:
  39. Row(QWidget *parent = nullptr);
  40. void setPrefix(QWidget *w, bool autoConnect = true);
  41. void setSuffix(QWidget *w, bool autoConnect = true);
  42. bool hasPrefix() { return prefix_; }
  43. bool hasSuffix() { return suffix_; }
  44. QWidget *prefix() const { return prefix_; }
  45. QWidget *suffix() const { return suffix_; }
  46. void setPrefixEnabled(bool enabled);
  47. void setSuffixEnabled(bool enabled);
  48. void setTitle(QString name);
  49. void setDescription(QString description);
  50. void showTitle(bool visible);
  51. void showDescription(bool visible);
  52. void setBuddy(QWidget *w);
  53. void setChangeCursor(bool change);
  54. signals:
  55. void clicked();
  56. protected:
  57. void enterEvent(QEnterEvent *) override;
  58. void leaveEvent(QEvent *) override;
  59. void mouseReleaseEvent(QMouseEvent *) override;
  60. void keyReleaseEvent(QKeyEvent *) override;
  61. bool hasDescription() const { return descriptionLabel != nullptr; }
  62. void focusInEvent(QFocusEvent *event) override
  63. {
  64. OBSIdianUtils::showKeyFocused(event);
  65. QFrame::focusInEvent(event);
  66. }
  67. void focusOutEvent(QFocusEvent *event) override
  68. {
  69. OBSIdianUtils::hideKeyFocused(event);
  70. QFrame::focusOutEvent(event);
  71. }
  72. private:
  73. QGridLayout *layout;
  74. QVBoxLayout *labelLayout = nullptr;
  75. QLabel *nameLabel = nullptr;
  76. QLabel *descriptionLabel = nullptr;
  77. QWidget *prefix_ = nullptr;
  78. QWidget *suffix_ = nullptr;
  79. QWidget *buddyWidget = nullptr;
  80. void connectBuddyWidget(QWidget *widget);
  81. bool changeCursor = false;
  82. };
  83. // Collapsible row expand button
  84. class ExpandButton : public QAbstractButton, public OBSIdianUtils {
  85. Q_OBJECT
  86. private:
  87. QPixmap extendDown;
  88. QPixmap extendUp;
  89. friend class CollapsibleRow;
  90. protected:
  91. explicit ExpandButton(QWidget *parent = nullptr);
  92. void paintEvent(QPaintEvent *) override;
  93. void focusInEvent(QFocusEvent *event) override
  94. {
  95. OBSIdianUtils::showKeyFocused(event);
  96. QAbstractButton::focusInEvent(event);
  97. }
  98. void focusOutEvent(QFocusEvent *event) override
  99. {
  100. OBSIdianUtils::hideKeyFocused(event);
  101. QAbstractButton::focusOutEvent(event);
  102. }
  103. };
  104. class RowFrame : protected QFrame, protected OBSIdianUtils {
  105. Q_OBJECT
  106. signals:
  107. void clicked();
  108. protected:
  109. explicit RowFrame(QWidget *parent = nullptr);
  110. void enterEvent(QEnterEvent *) override;
  111. void leaveEvent(QEvent *) override;
  112. void focusInEvent(QFocusEvent *event) override
  113. {
  114. OBSIdianUtils::showKeyFocused(event);
  115. QWidget::focusInEvent(event);
  116. }
  117. void focusOutEvent(QFocusEvent *event) override
  118. {
  119. OBSIdianUtils::hideKeyFocused(event);
  120. QWidget::focusOutEvent(event);
  121. }
  122. private:
  123. friend class CollapsibleRow;
  124. };
  125. // Collapsible Generic OBS property container
  126. class CollapsibleRow : public GenericRow {
  127. Q_OBJECT
  128. public:
  129. CollapsibleRow(const QString &name, QWidget *parent = nullptr);
  130. CollapsibleRow(const QString &name, const QString &desc = nullptr, QWidget *parent = nullptr);
  131. void setCheckable(bool check);
  132. bool isCheckable() { return checkable; }
  133. void addRow(GenericRow *actionRow);
  134. private:
  135. void toggleVisibility();
  136. QPixmap extendDown;
  137. QPixmap extendUp;
  138. QVBoxLayout *layout;
  139. RowFrame *rowWidget;
  140. QHBoxLayout *rowLayout;
  141. Row *actionRow;
  142. QFrame *expandFrame;
  143. QHBoxLayout *btnLayout;
  144. ExpandButton *expandButton;
  145. PropertiesList *propertyList;
  146. OBSToggleSwitch *toggleSwitch = nullptr;
  147. bool checkable = false;
  148. };
  149. } // namespace idian