mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-09-27 09:46:20 -04:00
idian: Debounce widget repolishing
Uses Qt's QGlobalStatic macro to create a shared Utils singleton for repolishing widgets. This means that multiple calls to the Utils' styling class helpers only trigger a single repolish per widget during a one tick of the Qt event loop.
This commit is contained in:
@@ -26,6 +26,38 @@
|
||||
#include <QStyleOptionFrame>
|
||||
|
||||
namespace idian {
|
||||
Q_GLOBAL_STATIC(Utils, utils);
|
||||
|
||||
Utils::Utils() : QObject(nullptr) {}
|
||||
|
||||
void Utils::addToPolishQueue(QWidget *widget)
|
||||
{
|
||||
widgetPolishQueue.push_back(widget);
|
||||
|
||||
if (isPolishPending) {
|
||||
return;
|
||||
}
|
||||
|
||||
isPolishPending = true;
|
||||
|
||||
QMetaObject::invokeMethod(this, &Utils::processPolishQueue, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void Utils::processPolishQueue()
|
||||
{
|
||||
widgetPolishQueue.sort();
|
||||
widgetPolishQueue.unique();
|
||||
|
||||
for (QPointer<QWidget> widget : widgetPolishQueue) {
|
||||
if (widget) {
|
||||
widget->style()->polish(widget);
|
||||
}
|
||||
}
|
||||
|
||||
isPolishPending = false;
|
||||
widgetPolishQueue.clear();
|
||||
}
|
||||
|
||||
void Utils::polishChildren(QWidget *widget)
|
||||
{
|
||||
for (QWidget *child : widget->findChildren<QWidget *>()) {
|
||||
@@ -35,7 +67,7 @@ void Utils::polishChildren(QWidget *widget)
|
||||
|
||||
void Utils::repolish(QWidget *widget)
|
||||
{
|
||||
widget->style()->polish(widget);
|
||||
utils->addToPolishQueue(widget);
|
||||
}
|
||||
|
||||
void Utils::addClass(QWidget *widget, const QString &classname)
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QPointer>
|
||||
#include <QRegularExpression>
|
||||
#include <QStyle>
|
||||
#include <QWidget>
|
||||
@@ -38,7 +39,12 @@ class Utils : public QObject {
|
||||
}
|
||||
|
||||
public:
|
||||
Utils(QObject *parent = nullptr) {};
|
||||
Utils();
|
||||
|
||||
bool isPolishPending{false};
|
||||
std::list<QPointer<QWidget>> widgetPolishQueue;
|
||||
void addToPolishQueue(QWidget *widget);
|
||||
void processPolishQueue();
|
||||
|
||||
// Force all children widgets to repaint
|
||||
static void polishChildren(QWidget *widget);
|
||||
|
||||
Reference in New Issue
Block a user