From 76e181886699fa77f5ee2564b173b248802b100f Mon Sep 17 00:00:00 2001 From: gxalpha Date: Sat, 18 Jan 2025 15:45:26 +0100 Subject: [PATCH] frontend: Highlight control dock buttons using style class Checkable buttons are troublesome because QAccessible interprets them as checkboxes, and doesn't pass the "clicked" signal to them (see QTBUG-110737). Instead, we only get the "toggled" signal, which also gets triggered by things other than user input (i.e., the button getting changed by the program). Making them uncheckable means that they behave like normal buttons again. To style them, we can just add a class and address them that way. Note that uncheckable here means *actually* not checkable - unlike the cursed NonCheckableButton class previously used that makes a button that *is* checkable ignore the user input (and only allow check state changes via code, effectively making it solely a styling tool). --- frontend/data/themes/Yami.obt | 26 +++++++++-------- frontend/data/themes/Yami_Acri.ovt | 39 ++++++++++++++------------ frontend/data/themes/Yami_Rachni.ovt | 13 +++++---- frontend/forms/OBSBasicControls.ui | 40 ++++----------------------- frontend/widgets/OBSBasicControls.cpp | 25 +++++++++-------- 5 files changed, 61 insertions(+), 82 deletions(-) diff --git a/frontend/data/themes/Yami.obt b/frontend/data/themes/Yami.obt index ef996a816..b33c87af0 100644 --- a/frontend/data/themes/Yami.obt +++ b/frontend/data/themes/Yami.obt @@ -1125,22 +1125,24 @@ QDoubleSpinBox::down-arrow { } /* Primary Control Button Checked Coloring */ -#streamButton:!hover:!pressed:checked, -#recordButton:!hover:!pressed:checked, -#replayBufferButton:!hover:!pressed:checked, -#virtualCamButton:!hover:!pressed:checked, -#modeSwitch:!hover:!pressed:checked, -#broadcastButton:!hover:!pressed:checked { +#streamButton:!hover:!pressed.state-active, +#recordButton:!hover:!pressed.state-active, +#pauseRecordButton:!hover:!pressed.state-active, +#replayBufferButton:!hover:!pressed.state-active, +#virtualCamButton:!hover:!pressed.state-active, +#modeSwitch:!hover:!pressed.state-active, +#broadcastButton:!hover:!pressed.state-active { background: var(--primary); } /* Primary Control Button Hover Coloring */ -#streamButton:hover:!pressed:checked, -#recordButton:hover:!pressed:checked, -#replayBufferButton:!pressed:checked, -#virtualCamButton:!pressed:checked, -#modeSwitch:hover:!pressed:checked, -#broadcastButton:hover:!pressed:checked { +#streamButton:hover:!pressed.state-active, +#recordButton:hover:!pressed.state-active, +#pauseRecordButton:hover:!pressed.state-active, +#replayBufferButton:!pressed.state-active, +#virtualCamButton:!pressed.state-active, +#modeSwitch:hover:!pressed.state-active, +#broadcastButton:hover:!pressed.state-active { background: var(--primary_light); color: var(--text); } diff --git a/frontend/data/themes/Yami_Acri.ovt b/frontend/data/themes/Yami_Acri.ovt index 978400a7d..76d3f215e 100644 --- a/frontend/data/themes/Yami_Acri.ovt +++ b/frontend/data/themes/Yami_Acri.ovt @@ -145,33 +145,36 @@ QTabBar QToolButton { } /* Primary Control Button Checked Coloring */ -#streamButton:!hover:!pressed:checked, -#recordButton:!hover:!pressed:checked, -#replayBufferButton:!hover:!pressed:checked, -#virtualCamButton:!hover:!pressed:checked, -#modeSwitch:!hover:!pressed:checked, -#broadcastButton:!hover:!pressed:checked { +#streamButton:!hover:!pressed.state-active, +#recordButton:!hover:!pressed.state-active, +#pauseRecordButton:!hover:!pressed.state-active, +#replayBufferButton:!hover:!pressed.state-active, +#virtualCamButton:!hover:!pressed.state-active, +#modeSwitch:!hover:!pressed.state-active, +#broadcastButton:!hover:!pressed.state-active { background: var(--button_bg_red); border-color: var(--button_bg_red); } /* Primary Control Button Hover Coloring */ -#streamButton:hover:!pressed:checked, -#recordButton:hover:!pressed:checked, -#replayBufferButton:hover:!pressed:checked, -#virtualCamButton:hover:!pressed:checked, -#modeSwitch:hover:!pressed:checked, -#broadcastButton:hover:!pressed:checked { +#streamButton:hover:!pressed.state-active, +#recordButton:hover:!pressed.state-active, +#pauseRecordButton:hover:!pressed.state-active, +#replayBufferButton:hover:!pressed.state-active, +#virtualCamButton:hover:!pressed.state-active, +#modeSwitch:hover:!pressed.state-active, +#broadcastButton:hover:!pressed.state-active { background: var(--button_bg_red_hover); } /* Primary Control Button Checked + Pressed Coloring */ -#streamButton:pressed:checked, -#recordButton:pressed:checked, -#replayBufferButton:pressed:checked, -#virtualCamButton:pressed:checked, -#modeSwitch:pressed:checked, -#broadcastButton:pressed:checked { +#streamButton:pressed.state-active, +#recordButton:pressed.state-active, +#pauseRecordButton:pressed.state-active, +#replayBufferButton:pressed.state-active, +#virtualCamButton:pressed.state-active, +#modeSwitch:pressed.state-active, +#broadcastButton:pressed.state-active { background: var(--button_bg_red_down); } diff --git a/frontend/data/themes/Yami_Rachni.ovt b/frontend/data/themes/Yami_Rachni.ovt index ed653a469..bc22851a0 100644 --- a/frontend/data/themes/Yami_Rachni.ovt +++ b/frontend/data/themes/Yami_Rachni.ovt @@ -221,11 +221,12 @@ VolumeMeter { } /* Primary Control Button Checked Coloring */ -#streamButton:!hover:!pressed:checked, -#recordButton:!hover:!pressed:checked, -#replayBufferButton:!hover:!pressed:checked, -#virtualCamButton:!hover:!pressed:checked, -#modeSwitch:!hover:!pressed:checked, -#broadcastButton:!hover:!pressed:checked { +#streamButton:!hover:!pressed.state-active, +#recordButton:!hover:!pressed.state-active, +#pauseRecordButton:!hover:!pressed.state-active, +#replayBufferButton:!hover:!pressed.state-active, +#virtualCamButton:!hover:!pressed.state-active, +#modeSwitch:!hover:!pressed.state-active, +#broadcastButton:!hover:!pressed.state-active { background: var(--primary_light); } diff --git a/frontend/forms/OBSBasicControls.ui b/frontend/forms/OBSBasicControls.ui index d05432fd4..9ee1fbbbf 100644 --- a/frontend/forms/OBSBasicControls.ui +++ b/frontend/forms/OBSBasicControls.ui @@ -47,7 +47,7 @@ - + true @@ -66,13 +66,10 @@ Basic.Main.StartStreaming - - true - - + true @@ -91,9 +88,6 @@ Basic.Main.StartBroadcast - - true - @@ -116,7 +110,7 @@ 0 - + true @@ -135,9 +129,6 @@ Basic.Main.StartRecording - - true - @@ -161,9 +152,6 @@ :/res/images/media-pause.svg:/res/images/media-pause.svg - - true - icon-media-pause @@ -189,7 +177,7 @@ 0 - + true @@ -208,9 +196,6 @@ Basic.Main.StartReplayBuffer - - true - @@ -259,7 +244,7 @@ 0 - + true @@ -278,9 +263,6 @@ Basic.Main.StartVirtualCam - - true - @@ -312,7 +294,7 @@ - + 0 @@ -328,9 +310,6 @@ Basic.TogglePreviewProgramMode - - true - @@ -370,13 +349,6 @@ - - - NonCheckableButton - QPushButton -
components/NonCheckableButton.hpp
-
-
diff --git a/frontend/widgets/OBSBasicControls.cpp b/frontend/widgets/OBSBasicControls.cpp index 1ba36ec96..c3638c0a8 100644 --- a/frontend/widgets/OBSBasicControls.cpp +++ b/frontend/widgets/OBSBasicControls.cpp @@ -1,5 +1,6 @@ #include "OBSBasicControls.hpp" #include "OBSBasic.hpp" +#include "qt-wrappers.hpp" #include "moc_OBSBasicControls.cpp" @@ -121,7 +122,7 @@ void OBSBasicControls::StreamingStarting(bool broadcastAutoStart) void OBSBasicControls::StreamingStarted(bool withDelay) { ui->streamButton->setEnabled(true); - ui->streamButton->setChecked(true); + setClasses(ui->streamButton, "state-active"); ui->streamButton->setText(QTStr("Basic.Main.StopStreaming")); if (withDelay) { @@ -139,7 +140,7 @@ void OBSBasicControls::StreamingStopping() void OBSBasicControls::StreamingStopped(bool withDelay) { ui->streamButton->setEnabled(true); - ui->streamButton->setChecked(false); + setClasses(ui->streamButton, ""); ui->streamButton->setText(QTStr("Basic.Main.StartStreaming")); if (withDelay) { @@ -155,7 +156,7 @@ void OBSBasicControls::StreamingStopped(bool withDelay) void OBSBasicControls::BroadcastStreamReady(bool ready) { - ui->broadcastButton->setChecked(ready); + setClasses(ui->broadcastButton, ready ? "state-active" : ""); } void OBSBasicControls::BroadcastStreamActive() @@ -176,7 +177,7 @@ void OBSBasicControls::BroadcastStreamStarted(bool autoStop) void OBSBasicControls::RecordingStarted(bool pausable) { - ui->recordButton->setChecked(true); + setClasses(ui->recordButton, "state-active"); ui->recordButton->setText(QTStr("Basic.Main.StopRecording")); if (pausable) { @@ -189,7 +190,7 @@ void OBSBasicControls::RecordingPaused() { QString text = QTStr("Basic.Main.UnpauseRecording"); - ui->pauseRecordButton->setChecked(true); + setClasses(ui->pauseRecordButton, "icon-media-pause state-active"); ui->pauseRecordButton->setAccessibleName(text); ui->pauseRecordButton->setToolTip(text); @@ -200,7 +201,7 @@ void OBSBasicControls::RecordingUnpaused() { QString text = QTStr("Basic.Main.PauseRecording"); - ui->pauseRecordButton->setChecked(false); + setClasses(ui->pauseRecordButton, "icon-media-pause"); ui->pauseRecordButton->setAccessibleName(text); ui->pauseRecordButton->setToolTip(text); @@ -214,7 +215,7 @@ void OBSBasicControls::RecordingStopping() void OBSBasicControls::RecordingStopped() { - ui->recordButton->setChecked(false); + setClasses(ui->recordButton, ""); ui->recordButton->setText(QTStr("Basic.Main.StartRecording")); ui->pauseRecordButton->setVisible(false); @@ -222,7 +223,7 @@ void OBSBasicControls::RecordingStopped() void OBSBasicControls::ReplayBufferStarted() { - ui->replayBufferButton->setChecked(true); + setClasses(ui->replayBufferButton, "state-active"); ui->replayBufferButton->setText(QTStr("Basic.Main.StopReplayBuffer")); ui->saveReplayButton->setVisible(true); @@ -235,7 +236,7 @@ void OBSBasicControls::ReplayBufferStopping() void OBSBasicControls::ReplayBufferStopped() { - ui->replayBufferButton->setChecked(false); + setClasses(ui->replayBufferButton, ""); ui->replayBufferButton->setText(QTStr("Basic.Main.StartReplayBuffer")); ui->saveReplayButton->setVisible(false); @@ -243,19 +244,19 @@ void OBSBasicControls::ReplayBufferStopped() void OBSBasicControls::VirtualCamStarted() { - ui->virtualCamButton->setChecked(true); + setClasses(ui->virtualCamButton, "state-active"); ui->virtualCamButton->setText(QTStr("Basic.Main.StopVirtualCam")); } void OBSBasicControls::VirtualCamStopped() { - ui->virtualCamButton->setChecked(false); + setClasses(ui->virtualCamButton, ""); ui->virtualCamButton->setText(QTStr("Basic.Main.StartVirtualCam")); } void OBSBasicControls::UpdateStudioModeState(bool enabled) { - ui->modeSwitch->setChecked(enabled); + setClasses(ui->modeSwitch, enabled ? "state-active" : ""); } void OBSBasicControls::EnableBroadcastFlow(bool enabled)