From 975431a7c78df56b97c03a23277f31216e906af9 Mon Sep 17 00:00:00 2001 From: SuslikV Date: Wed, 23 Jan 2019 16:55:51 +0200 Subject: [PATCH 1/3] UI: Add default color for the preview background If custom theme for obs UI has no record about background custom property in the qss file, then application can set random color per display initialization. This fixes this issue. --- UI/qt-display.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/UI/qt-display.hpp b/UI/qt-display.hpp index 11231f99e..94960b2a0 100644 --- a/UI/qt-display.hpp +++ b/UI/qt-display.hpp @@ -3,6 +3,8 @@ #include #include +#define GREY_COLOR_BACKGROUND 0xFF4C4C4C + class OBSQTDisplay : public QWidget { Q_OBJECT Q_PROPERTY(QColor displayBackgroundColor MEMBER backgroundColor @@ -27,7 +29,7 @@ public: inline obs_display_t *GetDisplay() const {return display;} - uint32_t backgroundColor; + uint32_t backgroundColor = GREY_COLOR_BACKGROUND; private slots: void SetDisplayBackgroundColor(const QColor &color); From e2be33956b68f59af2ce99efab609353601ec6e0 Mon Sep 17 00:00:00 2001 From: SuslikV Date: Wed, 23 Jan 2019 17:05:48 +0200 Subject: [PATCH 2/3] UI: Correct custom property implementation - Fixes Q_PROPERTY macro syntax - Removes excessive notification declaration and slot - Removes unneeded dynamic property - Improves Themes versatility --- UI/data/themes/Acri.qss | 4 ++-- UI/data/themes/Dark.qss | 4 ++-- UI/data/themes/Rachni.qss | 4 ++-- UI/data/themes/System.qss | 4 ++-- UI/qt-display.cpp | 23 +++++++++++++++++++++-- UI/qt-display.hpp | 4 +++- 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/UI/data/themes/Acri.qss b/UI/data/themes/Acri.qss index 1417da15d..62cbac30d 100644 --- a/UI/data/themes/Acri.qss +++ b/UI/data/themes/Acri.qss @@ -904,8 +904,8 @@ FocusList::item { /* Preview background color */ -* [themeID="displayBackgroundColor"] { - qproperty-displayBackgroundColor: #28282A; +OBSQTDisplay { + qproperty-displayBackgroundColor: #28282A; } /* Preview/Program labels */ diff --git a/UI/data/themes/Dark.qss b/UI/data/themes/Dark.qss index 8b50f7f65..34fa8d73c 100644 --- a/UI/data/themes/Dark.qss +++ b/UI/data/themes/Dark.qss @@ -695,8 +695,8 @@ QLabel#errorLabel { /* Preview background color */ -* [themeID="displayBackgroundColor"] { - qproperty-displayBackgroundColor: rgb(76, 76, 76); +OBSQTDisplay { + qproperty-displayBackgroundColor: rgb(76, 76, 76); } /* Preview/Program labels */ diff --git a/UI/data/themes/Rachni.qss b/UI/data/themes/Rachni.qss index e3af6e16b..6855aa7b6 100644 --- a/UI/data/themes/Rachni.qss +++ b/UI/data/themes/Rachni.qss @@ -1260,8 +1260,8 @@ QToolTip { /* Preview background color */ -* [themeID="displayBackgroundColor"] { - qproperty-displayBackgroundColor: rgb(35, 38, 41); +OBSQTDisplay { + qproperty-displayBackgroundColor: rgb(35, 38, 41); } /* Preview/Program labels */ diff --git a/UI/data/themes/System.qss b/UI/data/themes/System.qss index 2ea5c4ad4..543618924 100644 --- a/UI/data/themes/System.qss +++ b/UI/data/themes/System.qss @@ -138,8 +138,8 @@ QLabel#errorLabel { /* Preview background color */ -* [themeID="displayBackgroundColor"] { - qproperty-displayBackgroundColor: rgb(76, 76, 76); +OBSQTDisplay { + qproperty-displayBackgroundColor: rgb(76, 76, 76); } /* Preview/Program labels */ diff --git a/UI/qt-display.cpp b/UI/qt-display.cpp index 0640ca32e..f2ca5979c 100644 --- a/UI/qt-display.cpp +++ b/UI/qt-display.cpp @@ -19,6 +19,13 @@ static inline long long color_to_int(QColor color) shift(color.alpha(), 24); } +static inline QColor rgba_to_color(uint32_t rgba) +{ + return QColor::fromRgb(rgba & 0xFF, + (rgba >> 8) & 0xFF, + (rgba >> 16) & 0xFF, + (rgba >> 24) & 0xFF); +} OBSQTDisplay::OBSQTDisplay(QWidget *parent, Qt::WindowFlags flags) : QWidget(parent, flags) @@ -53,13 +60,25 @@ OBSQTDisplay::OBSQTDisplay(QWidget *parent, Qt::WindowFlags flags) connect(windowHandle(), &QWindow::visibleChanged, windowVisible); connect(windowHandle(), &QWindow::screenChanged, sizeChanged); +} - this->setProperty("themeID", "displayBackgroundColor"); +QColor OBSQTDisplay::GetDisplayBackgroundColor() const +{ + return rgba_to_color(backgroundColor); } void OBSQTDisplay::SetDisplayBackgroundColor(const QColor &color) { - backgroundColor = (uint32_t)color_to_int(color); + uint32_t newBackgroundColor = (uint32_t)color_to_int(color); + + if (newBackgroundColor != backgroundColor) { + backgroundColor = newBackgroundColor; + UpdateDisplayBackgroundColor(); + } +} + +void OBSQTDisplay::UpdateDisplayBackgroundColor() +{ obs_display_set_background_color(display, backgroundColor); } diff --git a/UI/qt-display.hpp b/UI/qt-display.hpp index 94960b2a0..de4fdacc2 100644 --- a/UI/qt-display.hpp +++ b/UI/qt-display.hpp @@ -8,6 +8,7 @@ class OBSQTDisplay : public QWidget { Q_OBJECT Q_PROPERTY(QColor displayBackgroundColor MEMBER backgroundColor + READ GetDisplayBackgroundColor WRITE SetDisplayBackgroundColor) OBSDisplay display; @@ -31,6 +32,7 @@ public: uint32_t backgroundColor = GREY_COLOR_BACKGROUND; -private slots: + QColor GetDisplayBackgroundColor() const; void SetDisplayBackgroundColor(const QColor &color); + void UpdateDisplayBackgroundColor(); }; From 8a22889e3d732532141db6b79b438f01c9cefc98 Mon Sep 17 00:00:00 2001 From: SuslikV Date: Wed, 23 Jan 2019 17:15:18 +0200 Subject: [PATCH 3/3] UI: Use theme colors setting for Projectors too Don't override the theme color settings for the Projector. If required, the background color of the projector can be changed via OBSProjector {qproperty-...} record placed after "OBSQTDisplay {qproperty-...}" section in the theme file (qss). --- UI/window-projector.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/UI/window-projector.cpp b/UI/window-projector.cpp index 6cb934a42..5a3e5fb71 100644 --- a/UI/window-projector.cpp +++ b/UI/window-projector.cpp @@ -67,7 +67,6 @@ OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_, int monitor, obs_display_add_draw_callback(GetDisplay(), isMultiview ? OBSRenderMultiview : OBSRender, this); - obs_display_set_background_color(GetDisplay(), 0x000000); }; connect(this, &OBSQTDisplay::DisplayCreated, addDrawCallback);