From 0df774cd01c08d1e813103faf6fe6fae20a68597 Mon Sep 17 00:00:00 2001 From: cg2121 Date: Wed, 14 Sep 2022 21:15:58 -0500 Subject: [PATCH] UI: Disable toolbar buttons when no source is selected When no source is selected, disable the toolbar buttons so the user knows the buttons can't be clicked. They would just do nothing before. --- UI/data/themes/Acri.qss | 2 +- UI/data/themes/Dark.qss | 2 +- UI/data/themes/Grey.qss | 2 +- UI/data/themes/Light.qss | 2 +- UI/data/themes/Rachni.qss | 2 +- UI/data/themes/Yami.qss | 2 +- UI/qt-wrappers.cpp | 10 ++++++++++ UI/qt-wrappers.hpp | 3 +++ UI/window-basic-main.cpp | 17 +++++++++++++++-- UI/window-basic-main.hpp | 1 + 10 files changed, 35 insertions(+), 8 deletions(-) diff --git a/UI/data/themes/Acri.qss b/UI/data/themes/Acri.qss index 5c7495bf1..a2c7a7947 100644 --- a/UI/data/themes/Acri.qss +++ b/UI/data/themes/Acri.qss @@ -823,7 +823,7 @@ QPushButton:pressed { background-color: rgb(22,31,65); } -QPushButton:disabled { +QPushButton:disabled, QToolButton:disabled { background-color: rgb(22,31,65); } diff --git a/UI/data/themes/Dark.qss b/UI/data/themes/Dark.qss index a94491226..ea08353ad 100644 --- a/UI/data/themes/Dark.qss +++ b/UI/data/themes/Dark.qss @@ -534,7 +534,7 @@ QPushButton:pressed { background-color: palette(base); } -QPushButton:disabled { +QPushButton:disabled, QToolButton:disabled { background-color: rgb(46,45,46); } diff --git a/UI/data/themes/Grey.qss b/UI/data/themes/Grey.qss index 2d2f188e1..102b3fe4b 100644 --- a/UI/data/themes/Grey.qss +++ b/UI/data/themes/Grey.qss @@ -812,7 +812,7 @@ QPushButton:pressed { background-color: rgb(28,28,28); } -QPushButton:disabled { +QPushButton:disabled, QToolButton:disabled { background-color: rgb(28,28,28); } diff --git a/UI/data/themes/Light.qss b/UI/data/themes/Light.qss index 74249a9bd..7476697e6 100644 --- a/UI/data/themes/Light.qss +++ b/UI/data/themes/Light.qss @@ -812,7 +812,7 @@ QPushButton:pressed { background-color: rgb(193,193,193); } -QPushButton:disabled { +QPushButton:disabled, QToolButton:disabled { background-color: rgb(193,193,193); } diff --git a/UI/data/themes/Rachni.qss b/UI/data/themes/Rachni.qss index 7488b5050..eb8cef6e0 100644 --- a/UI/data/themes/Rachni.qss +++ b/UI/data/themes/Rachni.qss @@ -816,7 +816,7 @@ QPushButton:pressed { background-color: rgb(240,98,146); } -QPushButton:disabled { +QPushButton:disabled, QToolButton:disabled { background-color: rgb(0,139,163); } diff --git a/UI/data/themes/Yami.qss b/UI/data/themes/Yami.qss index 5f16c322e..b557138b2 100644 --- a/UI/data/themes/Yami.qss +++ b/UI/data/themes/Yami.qss @@ -816,7 +816,7 @@ QPushButton:pressed { background-color: rgb(25,27,38); } -QPushButton:disabled { +QPushButton:disabled, QToolButton:disabled { background-color: rgb(25,27,38); } diff --git a/UI/qt-wrappers.cpp b/UI/qt-wrappers.cpp index 5cd56e258..4a89dc8fc 100644 --- a/UI/qt-wrappers.cpp +++ b/UI/qt-wrappers.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #if !defined(_WIN32) && !defined(__APPLE__) #include @@ -406,3 +407,12 @@ void TruncateLabel(QLabel *label, QString newText, int length) SetLabelText(label, newText); } + +void RefreshToolBarStyling(QToolBar *toolBar) +{ + for (QAction *action : toolBar->actions()) { + QWidget *widget = toolBar->widgetForAction(action); + widget->style()->unpolish(widget); + widget->style()->polish(widget); + } +} diff --git a/UI/qt-wrappers.hpp b/UI/qt-wrappers.hpp index b01242334..c841e0bbd 100644 --- a/UI/qt-wrappers.hpp +++ b/UI/qt-wrappers.hpp @@ -39,6 +39,7 @@ class QLayout; class QString; struct gs_window; class QLabel; +class QToolBar; class OBSMessageBox { public: @@ -122,3 +123,5 @@ QStringList OpenFiles(QWidget *parent, QString title, QString path, void TruncateLabel(QLabel *label, QString newText, int length = MAX_LABEL_LENGTH); + +void RefreshToolBarStyling(QToolBar *toolBar); diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index af7e97b08..e63dad4d7 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -3077,13 +3077,26 @@ void OBSBasic::UpdateContextBarDeferred(bool force) Qt::QueuedConnection, Q_ARG(bool, force)); } +void OBSBasic::SourceToolBarActionsSetEnabled(bool enable) +{ + ui->actionRemoveSource->setEnabled(enable); + ui->actionSourceProperties->setEnabled(enable); + ui->actionSourceUp->setEnabled(enable); + ui->actionSourceDown->setEnabled(enable); + + RefreshToolBarStyling(ui->sourcesToolbar); +} + void OBSBasic::UpdateContextBar(bool force) { + OBSSceneItem item = GetCurrentSceneItem(); + bool enable = item != nullptr; + + SourceToolBarActionsSetEnabled(enable); + if (!ui->contextContainer->isVisible() && !force) return; - OBSSceneItem item = GetCurrentSceneItem(); - if (item) { obs_source_t *source = obs_sceneitem_get_source(item); diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 5b28a5fdc..9dab98cbc 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -637,6 +637,7 @@ private: bool drawSpacingHelpers = true; float GetDevicePixelRatio(); + void SourceToolBarActionsSetEnabled(bool enable); std::string lastScreenshot; std::string lastReplay;