diff --git a/shared/qt/idian/CMakeLists.txt b/shared/qt/idian/CMakeLists.txt index 48e03ac31..743d155e3 100644 --- a/shared/qt/idian/CMakeLists.txt +++ b/shared/qt/idian/CMakeLists.txt @@ -22,7 +22,7 @@ target_sources( include/Idian/Row.hpp include/Idian/SpinBox.hpp include/Idian/ToggleSwitch.hpp - OBSIdianWidget.hpp + include/Idian/Utils.hpp widgets/Group.cpp widgets/PropertiesList.cpp widgets/Row.cpp diff --git a/shared/qt/idian/components/CheckBox.cpp b/shared/qt/idian/components/CheckBox.cpp index d00793616..1f083b1c2 100644 --- a/shared/qt/idian/components/CheckBox.cpp +++ b/shared/qt/idian/components/CheckBox.cpp @@ -21,4 +21,4 @@ using idian::CheckBox; -CheckBox::CheckBox(QWidget *parent) : QCheckBox(parent), OBSIdianUtils(this) {} +CheckBox::CheckBox(QWidget *parent) : QCheckBox(parent), Utils(this) {} diff --git a/shared/qt/idian/components/ComboBox.cpp b/shared/qt/idian/components/ComboBox.cpp index 6554272ab..7e84b3272 100644 --- a/shared/qt/idian/components/ComboBox.cpp +++ b/shared/qt/idian/components/ComboBox.cpp @@ -25,12 +25,11 @@ using idian::ComboBox; -ComboBox::ComboBox(QWidget *parent) : QComboBox(parent), OBSIdianUtils(this) {} +ComboBox::ComboBox(QWidget *parent) : QComboBox(parent), Utils(this) {} void ComboBox::showPopup() { if (allowOpeningPopup) { - allowOpeningPopup = false; QComboBox::showPopup(); } } diff --git a/shared/qt/idian/components/ToggleSwitch.cpp b/shared/qt/idian/components/ToggleSwitch.cpp index d833e35e0..5d3c3413a 100644 --- a/shared/qt/idian/components/ToggleSwitch.cpp +++ b/shared/qt/idian/components/ToggleSwitch.cpp @@ -36,7 +36,7 @@ ToggleSwitch::ToggleSwitch(QWidget *parent) : QAbstractButton(parent), animHandle(new QPropertyAnimation(this, "xpos", this)), animBgColor(new QPropertyAnimation(this, "blend", this)), - OBSIdianUtils(this) + Utils(this) { offPos = rect().width() / 2 - 18; onPos = rect().width() / 2 + 18; @@ -98,7 +98,7 @@ void ToggleSwitch::updateBackgroundColor() void ToggleSwitch::changeEvent(QEvent *event) { if (event->type() == QEvent::EnabledChange) { - OBSIdianUtils::toggleClass("disabled", !isEnabled()); + Utils::toggleClass("disabled", !isEnabled()); updateBackgroundColor(); } } diff --git a/shared/qt/idian/include/Idian/CheckBox.hpp b/shared/qt/idian/include/Idian/CheckBox.hpp index c372b8354..8e2cd510b 100644 --- a/shared/qt/idian/include/Idian/CheckBox.hpp +++ b/shared/qt/idian/include/Idian/CheckBox.hpp @@ -17,13 +17,13 @@ #pragma once -#include "../OBSIdianWidget.hpp" +#include #include namespace idian { -class CheckBox : public QCheckBox, public OBSIdianUtils { +class CheckBox : public QCheckBox, public Utils { Q_OBJECT; public: @@ -32,13 +32,13 @@ public: protected: void focusInEvent(QFocusEvent *e) override { - OBSIdianUtils::showKeyFocused(e); + Utils::showKeyFocused(e); QAbstractButton::focusInEvent(e); } void focusOutEvent(QFocusEvent *e) override { - OBSIdianUtils::hideKeyFocused(e); + Utils::hideKeyFocused(e); QAbstractButton::focusOutEvent(e); } }; diff --git a/shared/qt/idian/include/Idian/ComboBox.hpp b/shared/qt/idian/include/Idian/ComboBox.hpp index aef8cb878..3eb8e94b9 100644 --- a/shared/qt/idian/include/Idian/ComboBox.hpp +++ b/shared/qt/idian/include/Idian/ComboBox.hpp @@ -17,14 +17,14 @@ #pragma once -#include "../OBSIdianWidget.hpp" +#include #include #include namespace idian { -class ComboBox : public QComboBox, public OBSIdianUtils { +class ComboBox : public QComboBox, public Utils { Q_OBJECT public: @@ -44,13 +44,13 @@ protected: void focusInEvent(QFocusEvent *e) override { - OBSIdianUtils::showKeyFocused(e); + Utils::showKeyFocused(e); QComboBox::focusInEvent(e); } void focusOutEvent(QFocusEvent *e) override { - OBSIdianUtils::hideKeyFocused(e); + Utils::hideKeyFocused(e); QComboBox::focusOutEvent(e); } }; diff --git a/shared/qt/idian/include/Idian/Group.hpp b/shared/qt/idian/include/Idian/Group.hpp index 7c0693504..030361995 100644 --- a/shared/qt/idian/include/Idian/Group.hpp +++ b/shared/qt/idian/include/Idian/Group.hpp @@ -28,7 +28,7 @@ namespace idian { -class Group : public QFrame, public OBSIdianUtils { +class Group : public QFrame, public Utils { Q_OBJECT public: diff --git a/shared/qt/idian/include/Idian/PropertiesList.hpp b/shared/qt/idian/include/Idian/PropertiesList.hpp index c19abf8b9..b0fe840d6 100644 --- a/shared/qt/idian/include/Idian/PropertiesList.hpp +++ b/shared/qt/idian/include/Idian/PropertiesList.hpp @@ -17,7 +17,7 @@ #pragma once -#include "../OBSIdianWidget.hpp" +#include #include #include diff --git a/shared/qt/idian/include/Idian/Row.hpp b/shared/qt/idian/include/Idian/Row.hpp index 21f32b363..b153d0c56 100644 --- a/shared/qt/idian/include/Idian/Row.hpp +++ b/shared/qt/idian/include/Idian/Row.hpp @@ -22,7 +22,7 @@ #include #include #include -#include "../../OBSIdianWidget.hpp" +#include #include #include @@ -35,11 +35,11 @@ namespace idian { // Base class mostly so adding stuff to a list is easier -class GenericRow : public QFrame, public OBSIdianUtils { +class GenericRow : public QFrame, public Utils { Q_OBJECT public: - GenericRow(QWidget *parent = nullptr) : QFrame(parent), OBSIdianUtils(this) { setAccessibleName(""); }; + GenericRow(QWidget *parent = nullptr) : QFrame(parent), Utils(this) { setAccessibleName(""); }; }; // Row widget containing one or more controls @@ -83,13 +83,13 @@ protected: void focusInEvent(QFocusEvent *event) override { - OBSIdianUtils::showKeyFocused(event); + Utils::showKeyFocused(event); QFrame::focusInEvent(event); } void focusOutEvent(QFocusEvent *event) override { - OBSIdianUtils::hideKeyFocused(event); + Utils::hideKeyFocused(event); QFrame::focusOutEvent(event); } @@ -111,7 +111,7 @@ private: }; // Collapsible row expand button -class ExpandButton : public QAbstractButton, public OBSIdianUtils { +class ExpandButton : public QAbstractButton, public Utils { Q_OBJECT private: @@ -127,18 +127,18 @@ protected: void focusInEvent(QFocusEvent *event) override { - OBSIdianUtils::showKeyFocused(event); + Utils::showKeyFocused(event); QAbstractButton::focusInEvent(event); } void focusOutEvent(QFocusEvent *event) override { - OBSIdianUtils::hideKeyFocused(event); + Utils::hideKeyFocused(event); QAbstractButton::focusOutEvent(event); } }; -class RowFrame : protected QFrame, protected OBSIdianUtils { +class RowFrame : protected QFrame, protected Utils { Q_OBJECT signals: @@ -152,13 +152,13 @@ protected: void focusInEvent(QFocusEvent *event) override { - OBSIdianUtils::showKeyFocused(event); + Utils::showKeyFocused(event); QWidget::focusInEvent(event); } void focusOutEvent(QFocusEvent *event) override { - OBSIdianUtils::hideKeyFocused(event); + Utils::hideKeyFocused(event); QWidget::focusOutEvent(event); } diff --git a/shared/qt/idian/include/Idian/ToggleSwitch.hpp b/shared/qt/idian/include/Idian/ToggleSwitch.hpp index acb639aa8..251cdb42b 100644 --- a/shared/qt/idian/include/Idian/ToggleSwitch.hpp +++ b/shared/qt/idian/include/Idian/ToggleSwitch.hpp @@ -17,7 +17,7 @@ #pragma once -#include "../OBSIdianWidget.hpp" +#include #include #include @@ -31,7 +31,7 @@ namespace idian { -class ToggleSwitch : public QAbstractButton, public OBSIdianUtils { +class ToggleSwitch : public QAbstractButton, public Utils { Q_OBJECT Q_PROPERTY(int xpos MEMBER xPos WRITE setPos) Q_PROPERTY(QColor background MEMBER backgroundInactive DESIGNABLE true) @@ -84,13 +84,13 @@ protected: void focusInEvent(QFocusEvent *e) override { - OBSIdianUtils::showKeyFocused(e); + Utils::showKeyFocused(e); QAbstractButton::focusInEvent(e); } void focusOutEvent(QFocusEvent *e) override { - OBSIdianUtils::hideKeyFocused(e); + Utils::hideKeyFocused(e); QAbstractButton::focusOutEvent(e); } diff --git a/shared/qt/idian/OBSIdianWidget.hpp b/shared/qt/idian/include/Idian/Utils.hpp similarity index 84% rename from shared/qt/idian/OBSIdianWidget.hpp rename to shared/qt/idian/include/Idian/Utils.hpp index f6e249c1e..a052a905b 100644 --- a/shared/qt/idian/OBSIdianWidget.hpp +++ b/shared/qt/idian/include/Idian/Utils.hpp @@ -17,34 +17,29 @@ #pragma once -#include -#include #include #include +#include +#include -/* - * Helpers for OBS Idian widgets - */ +namespace idian { -static const QRegularExpression classRegex = QRegularExpression("^[a-zA-Z][a-zA-Z0-9_-]*$"); - -class OBSIdianUtils { +// Helpers for OBS Idian widgets +class Utils { static bool classNameIsValid(const QString &name) { - QRegularExpressionMatch match = classRegex.match(name); + static const QRegularExpression classRegex("^[a-zA-Z][a-zA-Z0-9_-]*$"); + const QRegularExpressionMatch match = classRegex.match(name); return match.hasMatch(); } public: QWidget *parent = nullptr; - OBSIdianUtils(QWidget *w) { parent = w; } + Utils(QWidget *w) { parent = w; } - /* - * Set a custom property whenever the widget has - * keyboard focus specifically - */ + // Set a custom property whenever the widget has keyboard focus specifically void showKeyFocused(QFocusEvent *e) { if (e->reason() != Qt::MouseFocusReason && e->reason() != Qt::PopupFocusReason) { @@ -61,9 +56,7 @@ public: } } - /* - * Force all children widgets to repaint - */ + // Force all children widgets to repaint void polishChildren() { polishChildren(parent); } static void polishChildren(QWidget *widget) @@ -81,9 +74,7 @@ public: widget->style()->polish(widget); } - /* - * Adds a style class to the widget - */ + // Adds a style class to the widget void addClass(const QString &classname) { addClass(parent, classname); } static void addClass(QWidget *widget, const QString &classname) @@ -107,9 +98,7 @@ public: repolish(widget); } - /* - * Removes a style class from a widget - */ + // Removes a style class from a widget void removeClass(const QString &classname) { removeClass(parent, classname); } static void removeClass(QWidget *widget, const QString &classname) @@ -136,9 +125,7 @@ public: repolish(widget); } - /* - * Forces the addition or removal of a style class from a widget - */ + // Forces the addition or removal of a style class from a widget void toggleClass(const QString &classname, bool toggle) { toggleClass(parent, classname, toggle); } static void toggleClass(QWidget *widget, const QString &classname, bool toggle) @@ -150,3 +137,5 @@ public: } } }; + +} // namespace idian diff --git a/shared/qt/idian/widgets/Group.cpp b/shared/qt/idian/widgets/Group.cpp index 04525a36e..dde3bed5e 100644 --- a/shared/qt/idian/widgets/Group.cpp +++ b/shared/qt/idian/widgets/Group.cpp @@ -17,13 +17,13 @@ #include -#include "../OBSIdianWidget.hpp" +#include #include using idian::Group; -Group::Group(QWidget *parent) : QFrame(parent), OBSIdianUtils(this) +Group::Group(QWidget *parent) : QFrame(parent), Utils(this) { layout = new QVBoxLayout(this); layout->setSpacing(0); @@ -34,7 +34,7 @@ Group::Group(QWidget *parent) : QFrame(parent), OBSIdianUtils(this) headerLayout->setSpacing(0); headerLayout->setContentsMargins(0, 0, 0, 0); headerContainer->setLayout(headerLayout); - OBSIdianUtils::addClass(headerContainer, "header"); + Utils::addClass(headerContainer, "header"); labelContainer = new QWidget(); labelLayout = new QVBoxLayout(); @@ -57,7 +57,7 @@ Group::Group(QWidget *parent) : QFrame(parent), OBSIdianUtils(this) contentsLayout->setSpacing(0); contentsLayout->setContentsMargins(0, 0, 0, 0); contentsContainer->setLayout(contentsLayout); - OBSIdianUtils::addClass(contentsContainer, "contents"); + Utils::addClass(contentsContainer, "contents"); layout->addWidget(headerContainer); layout->addWidget(contentsContainer); @@ -69,12 +69,12 @@ Group::Group(QWidget *parent) : QFrame(parent), OBSIdianUtils(this) contentsLayout->addWidget(propertyList); nameLabel = new QLabel(); - OBSIdianUtils::addClass(nameLabel, "title"); + Utils::addClass(nameLabel, "title"); nameLabel->setVisible(false); labelLayout->addWidget(nameLabel); descriptionLabel = new QLabel(); - OBSIdianUtils::addClass(descriptionLabel, "description"); + Utils::addClass(descriptionLabel, "description"); descriptionLabel->setVisible(false); labelLayout->addWidget(descriptionLabel); } diff --git a/shared/qt/idian/widgets/PropertiesList.cpp b/shared/qt/idian/widgets/PropertiesList.cpp index c7416558c..342bbea19 100644 --- a/shared/qt/idian/widgets/PropertiesList.cpp +++ b/shared/qt/idian/widgets/PropertiesList.cpp @@ -48,16 +48,16 @@ void PropertiesList::addRow(GenericRow *row) // Custom properties to work around :first and :last not existing. if (!first) { - OBSIdianUtils::addClass(row, "first"); + Utils::addClass(row, "first"); first = row; } // Remove last property from existing last item if (last) - OBSIdianUtils::removeClass(last, "last"); + Utils::removeClass(last, "last"); // Most recently added item is also always last - OBSIdianUtils::addClass(row, "last"); + Utils::addClass(row, "last"); last = row; row->setParent(this); diff --git a/shared/qt/idian/widgets/Row.cpp b/shared/qt/idian/widgets/Row.cpp index 99c75fd31..a251c4e49 100644 --- a/shared/qt/idian/widgets/Row.cpp +++ b/shared/qt/idian/widgets/Row.cpp @@ -46,11 +46,11 @@ Row::Row(QWidget *parent) : GenericRow(parent) nameLabel = new QLabel(); nameLabel->setVisible(false); - OBSIdianUtils::addClass(nameLabel, "title"); + Utils::addClass(nameLabel, "title"); descriptionLabel = new QLabel(); descriptionLabel->setVisible(false); - OBSIdianUtils::addClass(descriptionLabel, "description"); + Utils::addClass(descriptionLabel, "description"); labelLayout->addWidget(nameLabel); labelLayout->addWidget(descriptionLabel); @@ -139,13 +139,13 @@ void Row::showDescription(bool visible) void Row::setBuddy(QWidget *widget) { buddyWidget = widget; - OBSIdianUtils::addClass(widget, "row-buddy"); + Utils::addClass(widget, "row-buddy"); } void Row::setChangeCursor(bool change) { changeCursor = change; - OBSIdianUtils::toggleClass("cursor-pointer", change); + Utils::toggleClass("cursor-pointer", change); } void Row::enterEvent(QEnterEvent *event) @@ -157,13 +157,13 @@ void Row::enterEvent(QEnterEvent *event) setCursor(Qt::PointingHandCursor); } - OBSIdianUtils::addClass("hover"); + Utils::addClass("hover"); if (buddyWidget) - OBSIdianUtils::repolish(buddyWidget); + Utils::repolish(buddyWidget); if (hasPrefix() || hasSuffix()) { - OBSIdianUtils::polishChildren(); + Utils::polishChildren(); } GenericRow::enterEvent(event); @@ -171,13 +171,13 @@ void Row::enterEvent(QEnterEvent *event) void Row::leaveEvent(QEvent *event) { - OBSIdianUtils::removeClass("hover"); + Utils::removeClass("hover"); if (buddyWidget) - OBSIdianUtils::repolish(buddyWidget); + Utils::repolish(buddyWidget); if (hasPrefix() || hasSuffix()) { - OBSIdianUtils::polishChildren(); + Utils::polishChildren(); } GenericRow::leaveEvent(event); @@ -234,7 +234,7 @@ void Row::connectBuddyWidget(QWidget *widget) } // Button for expanding a collapsible ActionRow -ExpandButton::ExpandButton(QWidget *parent) : QAbstractButton(parent), OBSIdianUtils(this) +ExpandButton::ExpandButton(QWidget *parent) : QAbstractButton(parent), Utils(this) { setCheckable(true); } @@ -287,7 +287,7 @@ CollapsibleRow::CollapsibleRow(const QString &name, QWidget *parent) : GenericRo btnLayout->setContentsMargins(0, 0, 0, 0); btnLayout->setSpacing(0); expandFrame->setLayout(btnLayout); - OBSIdianUtils::addClass(expandFrame, "btn-frame"); + Utils::addClass(expandFrame, "btn-frame"); actionRow->setBuddy(expandFrame); expandButton = new ExpandButton(this); @@ -316,7 +316,7 @@ void CollapsibleRow::setCheckable(bool check) if (checkable && !toggleSwitch) { propertyList->setEnabled(false); - OBSIdianUtils::polishChildren(propertyList); + Utils::polishChildren(propertyList); toggleSwitch = new ToggleSwitch(false); @@ -326,7 +326,7 @@ void CollapsibleRow::setCheckable(bool check) if (!checkable && toggleSwitch) { propertyList->setEnabled(true); - OBSIdianUtils::polishChildren(propertyList); + Utils::polishChildren(propertyList); actionRow->suffix()->deleteLater(); } @@ -345,22 +345,22 @@ void CollapsibleRow::addRow(GenericRow *actionRow) propertyList->addRow(actionRow); } -RowFrame::RowFrame(QWidget *parent) : QFrame(parent), OBSIdianUtils(this) {} +RowFrame::RowFrame(QWidget *parent) : QFrame(parent), Utils(this) {} void RowFrame::enterEvent(QEnterEvent *event) { setCursor(Qt::PointingHandCursor); - OBSIdianUtils::addClass("hover"); - OBSIdianUtils::polishChildren(); + Utils::addClass("hover"); + Utils::polishChildren(); QWidget::enterEvent(event); } void RowFrame::leaveEvent(QEvent *event) { - OBSIdianUtils::removeClass("hover"); - OBSIdianUtils::polishChildren(); + Utils::removeClass("hover"); + Utils::polishChildren(); QWidget::leaveEvent(event); }