Jelajahi Sumber

shared/idian: Rename OBSIdianUtils

Sebastian Beckmann 4 bulan lalu
induk
melakukan
d097ff24ad

+ 1 - 1
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

+ 1 - 1
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) {}

+ 1 - 2
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();
 	}
 }

+ 2 - 2
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();
 	}
 }

+ 4 - 4
shared/qt/idian/include/Idian/CheckBox.hpp

@@ -17,13 +17,13 @@
 
 #pragma once
 
-#include "../OBSIdianWidget.hpp"
+#include <Idian/Utils.hpp>
 
 #include <QCheckBox>
 
 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);
 	}
 };

+ 4 - 4
shared/qt/idian/include/Idian/ComboBox.hpp

@@ -17,14 +17,14 @@
 
 #pragma once
 
-#include "../OBSIdianWidget.hpp"
+#include <Idian/Utils.hpp>
 
 #include <QComboBox>
 #include <QAbstractItemView>
 
 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);
 	}
 };

+ 1 - 1
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:

+ 1 - 1
shared/qt/idian/include/Idian/PropertiesList.hpp

@@ -17,7 +17,7 @@
 
 #pragma once
 
-#include "../OBSIdianWidget.hpp"
+#include <Idian/Utils.hpp>
 
 #include <QFrame>
 #include <QLayout>

+ 11 - 11
shared/qt/idian/include/Idian/Row.hpp

@@ -22,7 +22,7 @@
 #include <Idian/PropertiesList.hpp>
 #include <Idian/SpinBox.hpp>
 #include <Idian/ToggleSwitch.hpp>
-#include "../../OBSIdianWidget.hpp"
+#include <Idian/Utils.hpp>
 
 #include <QCheckBox>
 #include <QFrame>
@@ -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);
 	}
 

+ 4 - 4
shared/qt/idian/include/Idian/ToggleSwitch.hpp

@@ -17,7 +17,7 @@
 
 #pragma once
 
-#include "../OBSIdianWidget.hpp"
+#include <Idian/Utils.hpp>
 
 #include <QAbstractButton>
 #include <QAccessibleWidget>
@@ -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);
 	}
 

+ 15 - 26
shared/qt/idian/OBSIdianWidget.hpp → shared/qt/idian/include/Idian/Utils.hpp

@@ -17,34 +17,29 @@
 
 #pragma once
 
-#include <QWidget>
-#include <QStyle>
 #include <QFocusEvent>
 #include <QRegularExpression>
+#include <QStyle>
+#include <QWidget>
 
-/*
- * Helpers for OBS Idian widgets
- */
-
-static const QRegularExpression classRegex = QRegularExpression("^[a-zA-Z][a-zA-Z0-9_-]*$");
+namespace idian {
 
-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

+ 6 - 6
shared/qt/idian/widgets/Group.cpp

@@ -17,13 +17,13 @@
 
 #include <Idian/Group.hpp>
 
-#include "../OBSIdianWidget.hpp"
+#include <Idian/Utils.hpp>
 
 #include <Idian/moc_Group.cpp>
 
 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);
 }

+ 3 - 3
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);

+ 19 - 19
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);
 }