Преглед изворни кода

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.
cg2121 пре 3 година
родитељ
комит
0df774cd01

+ 1 - 1
UI/data/themes/Acri.qss

@@ -823,7 +823,7 @@ QPushButton:pressed {
     background-color: rgb(22,31,65);
     background-color: rgb(22,31,65);
 }
 }
 
 
-QPushButton:disabled {
+QPushButton:disabled, QToolButton:disabled {
     background-color: rgb(22,31,65);
     background-color: rgb(22,31,65);
 }
 }
 
 

+ 1 - 1
UI/data/themes/Dark.qss

@@ -534,7 +534,7 @@ QPushButton:pressed {
     background-color: palette(base);
     background-color: palette(base);
 }
 }
 
 
-QPushButton:disabled {
+QPushButton:disabled, QToolButton:disabled {
     background-color: rgb(46,45,46);
     background-color: rgb(46,45,46);
 }
 }
 
 

+ 1 - 1
UI/data/themes/Grey.qss

@@ -812,7 +812,7 @@ QPushButton:pressed {
     background-color: rgb(28,28,28);
     background-color: rgb(28,28,28);
 }
 }
 
 
-QPushButton:disabled {
+QPushButton:disabled, QToolButton:disabled {
     background-color: rgb(28,28,28);
     background-color: rgb(28,28,28);
 }
 }
 
 

+ 1 - 1
UI/data/themes/Light.qss

@@ -812,7 +812,7 @@ QPushButton:pressed {
     background-color: rgb(193,193,193);
     background-color: rgb(193,193,193);
 }
 }
 
 
-QPushButton:disabled {
+QPushButton:disabled, QToolButton:disabled {
     background-color: rgb(193,193,193);
     background-color: rgb(193,193,193);
 }
 }
 
 

+ 1 - 1
UI/data/themes/Rachni.qss

@@ -816,7 +816,7 @@ QPushButton:pressed {
     background-color: rgb(240,98,146);
     background-color: rgb(240,98,146);
 }
 }
 
 
-QPushButton:disabled {
+QPushButton:disabled, QToolButton:disabled {
     background-color: rgb(0,139,163);
     background-color: rgb(0,139,163);
 }
 }
 
 

+ 1 - 1
UI/data/themes/Yami.qss

@@ -816,7 +816,7 @@ QPushButton:pressed {
     background-color: rgb(25,27,38);
     background-color: rgb(25,27,38);
 }
 }
 
 
-QPushButton:disabled {
+QPushButton:disabled, QToolButton:disabled {
     background-color: rgb(25,27,38);
     background-color: rgb(25,27,38);
 }
 }
 
 

+ 10 - 0
UI/qt-wrappers.cpp

@@ -30,6 +30,7 @@
 #include <QStandardItemModel>
 #include <QStandardItemModel>
 #include <QLabel>
 #include <QLabel>
 #include <QPushButton>
 #include <QPushButton>
+#include <QToolBar>
 
 
 #if !defined(_WIN32) && !defined(__APPLE__)
 #if !defined(_WIN32) && !defined(__APPLE__)
 #include <obs-nix-platform.h>
 #include <obs-nix-platform.h>
@@ -406,3 +407,12 @@ void TruncateLabel(QLabel *label, QString newText, int length)
 
 
 	SetLabelText(label, newText);
 	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);
+	}
+}

+ 3 - 0
UI/qt-wrappers.hpp

@@ -39,6 +39,7 @@ class QLayout;
 class QString;
 class QString;
 struct gs_window;
 struct gs_window;
 class QLabel;
 class QLabel;
+class QToolBar;
 
 
 class OBSMessageBox {
 class OBSMessageBox {
 public:
 public:
@@ -122,3 +123,5 @@ QStringList OpenFiles(QWidget *parent, QString title, QString path,
 
 
 void TruncateLabel(QLabel *label, QString newText,
 void TruncateLabel(QLabel *label, QString newText,
 		   int length = MAX_LABEL_LENGTH);
 		   int length = MAX_LABEL_LENGTH);
+
+void RefreshToolBarStyling(QToolBar *toolBar);

+ 15 - 2
UI/window-basic-main.cpp

@@ -3077,13 +3077,26 @@ void OBSBasic::UpdateContextBarDeferred(bool force)
 				  Qt::QueuedConnection, Q_ARG(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)
 void OBSBasic::UpdateContextBar(bool force)
 {
 {
+	OBSSceneItem item = GetCurrentSceneItem();
+	bool enable = item != nullptr;
+
+	SourceToolBarActionsSetEnabled(enable);
+
 	if (!ui->contextContainer->isVisible() && !force)
 	if (!ui->contextContainer->isVisible() && !force)
 		return;
 		return;
 
 
-	OBSSceneItem item = GetCurrentSceneItem();
-
 	if (item) {
 	if (item) {
 		obs_source_t *source = obs_sceneitem_get_source(item);
 		obs_source_t *source = obs_sceneitem_get_source(item);
 
 

+ 1 - 0
UI/window-basic-main.hpp

@@ -637,6 +637,7 @@ private:
 	bool drawSpacingHelpers = true;
 	bool drawSpacingHelpers = true;
 
 
 	float GetDevicePixelRatio();
 	float GetDevicePixelRatio();
+	void SourceToolBarActionsSetEnabled(bool enable);
 
 
 	std::string lastScreenshot;
 	std::string lastScreenshot;
 	std::string lastReplay;
 	std::string lastReplay;