OBSActionRow.hpp 5.1 KB

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