Explorar el Código

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 hace 3 años
padre
commit
0df774cd01

+ 1 - 1
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);
 }
 

+ 1 - 1
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);
 }
 

+ 1 - 1
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);
 }
 

+ 1 - 1
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);
 }
 

+ 1 - 1
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);
 }
 

+ 1 - 1
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);
 }
 

+ 10 - 0
UI/qt-wrappers.cpp

@@ -30,6 +30,7 @@
 #include <QStandardItemModel>
 #include <QLabel>
 #include <QPushButton>
+#include <QToolBar>
 
 #if !defined(_WIN32) && !defined(__APPLE__)
 #include <obs-nix-platform.h>
@@ -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);
+	}
+}

+ 3 - 0
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);

+ 15 - 2
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);
 

+ 1 - 0
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;