shared/idian: Rename OBSIdianUtils

This commit is contained in:
Sebastian Beckmann
2025-08-22 16:21:52 -04:00
committed by Ryan Foster
parent 872ea5fb91
commit d097ff24ad
14 changed files with 73 additions and 85 deletions
+1 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -28,7 +28,7 @@
namespace idian {
class Group : public QFrame, public OBSIdianUtils {
class Group : public QFrame, public Utils {
Q_OBJECT
public:
@@ -17,7 +17,7 @@
#pragma once
#include "../OBSIdianWidget.hpp"
#include <Idian/Utils.hpp>
#include <QFrame>
#include <QLayout>
+11 -11
View File
@@ -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);
}
@@ -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);
}
@@ -17,34 +17,29 @@
#pragma once
#include <QWidget>
#include <QStyle>
#include <QFocusEvent>
#include <QRegularExpression>
#include <QStyle>
#include <QWidget>
/*
* 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
+6 -6
View File
@@ -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
View File
@@ -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
View File
@@ -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);
}