From 33b64d6c915793cb1068f5122c25f678b7accbc3 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Mon, 13 Nov 2023 15:04:12 -0800 Subject: [PATCH] InterfacePane: Add BalloonTip to cursor visible radio buttons --- .../Config/ConfigControls/ConfigRadio.cpp | 13 ++-- .../Config/ConfigControls/ConfigRadio.h | 6 ++ Source/Core/DolphinQt/Settings.cpp | 6 -- Source/Core/DolphinQt/Settings.h | 1 - .../Core/DolphinQt/Settings/InterfacePane.cpp | 67 +++++++++---------- .../Core/DolphinQt/Settings/InterfacePane.h | 11 ++- 6 files changed, 49 insertions(+), 55 deletions(-) diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigRadio.cpp b/Source/Core/DolphinQt/Config/ConfigControls/ConfigRadio.cpp index 98977dfdc9..11a049d910 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigRadio.cpp +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigRadio.cpp @@ -27,8 +27,13 @@ ConfigRadioInt::ConfigRadioInt(const QString& label, const Config::Info& se void ConfigRadioInt::Update() { - if (!isChecked()) - return; - - Config::SetBaseOrCurrent(m_setting, m_value); + if (isChecked()) + { + Config::SetBaseOrCurrent(m_setting, m_value); + emit OnSelected(m_value); + } + else + { + emit OnDeselected(m_value); + } } diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigRadio.h b/Source/Core/DolphinQt/Config/ConfigControls/ConfigRadio.h index d3f5c7e258..147c6391f9 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigRadio.h +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigRadio.h @@ -13,6 +13,12 @@ class ConfigRadioInt : public ToolTipRadioButton public: ConfigRadioInt(const QString& label, const Config::Info& setting, int value); +signals: + // Since selecting a new radio button deselects the old one, ::toggled will generate two signals. + // These are convenience functions so you can receive only one signal if desired. + void OnSelected(int new_value); + void OnDeselected(int old_value); + private: void Update(); diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp index 2a4a62741a..0ffdadb119 100644 --- a/Source/Core/DolphinQt/Settings.cpp +++ b/Source/Core/DolphinQt/Settings.cpp @@ -418,12 +418,6 @@ void Settings::SetStateSlot(int slot) GetQSettings().setValue(QStringLiteral("Emulation/StateSlot"), slot); } -void Settings::SetCursorVisibility(Config::ShowCursor hideCursor) -{ - Config::SetBaseOrCurrent(Config::MAIN_SHOW_CURSOR, hideCursor); - emit CursorVisibilityChanged(); -} - Config::ShowCursor Settings::GetCursorVisibility() const { return Config::Get(Config::MAIN_SHOW_CURSOR); diff --git a/Source/Core/DolphinQt/Settings.h b/Source/Core/DolphinQt/Settings.h index 03c805da5b..479d723e59 100644 --- a/Source/Core/DolphinQt/Settings.h +++ b/Source/Core/DolphinQt/Settings.h @@ -122,7 +122,6 @@ public: void SetUSBKeyboardConnected(bool connected); // Graphics - void SetCursorVisibility(Config::ShowCursor hideCursor); Config::ShowCursor GetCursorVisibility() const; bool GetLockCursor() const; void SetKeepWindowOnTop(bool top); diff --git a/Source/Core/DolphinQt/Settings/InterfacePane.cpp b/Source/Core/DolphinQt/Settings/InterfacePane.cpp index 70f4badf61..b7774cfd81 100644 --- a/Source/Core/DolphinQt/Settings/InterfacePane.cpp +++ b/Source/Core/DolphinQt/Settings/InterfacePane.cpp @@ -25,6 +25,7 @@ #include "DolphinQt/Config/ConfigControls/ConfigBool.h" #include "DolphinQt/Config/ConfigControls/ConfigChoice.h" +#include "DolphinQt/Config/ConfigControls/ConfigRadio.h" #include "DolphinQt/Config/ToolTipControls/ToolTipCheckBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/SignalBlocking.h" @@ -196,14 +197,13 @@ void InterfacePane::CreateInGame() auto* m_vboxlayout_hide_mouse = new QVBoxLayout; mouse_groupbox->setLayout(m_vboxlayout_hide_mouse); - m_radio_cursor_visible_movement = new QRadioButton(tr("On Movement")); - m_radio_cursor_visible_movement->setToolTip( - tr("Mouse Cursor hides after inactivity and returns upon Mouse Cursor movement.")); - m_radio_cursor_visible_never = new QRadioButton(tr("Never")); - m_radio_cursor_visible_never->setToolTip( - tr("Mouse Cursor will never be visible while a game is running.")); - m_radio_cursor_visible_always = new QRadioButton(tr("Always")); - m_radio_cursor_visible_always->setToolTip(tr("Mouse Cursor will always be visible.")); + m_radio_cursor_visible_movement = + new ConfigRadioInt(tr("On Movement"), Config::MAIN_SHOW_CURSOR, + static_cast(Config::ShowCursor::OnMovement)); + m_radio_cursor_visible_never = new ConfigRadioInt(tr("Never"), Config::MAIN_SHOW_CURSOR, + static_cast(Config::ShowCursor::Never)); + m_radio_cursor_visible_always = new ConfigRadioInt( + tr("Always"), Config::MAIN_SHOW_CURSOR, static_cast(Config::ShowCursor::Constantly)); m_vboxlayout_hide_mouse->addWidget(m_radio_cursor_visible_movement); m_vboxlayout_hide_mouse->addWidget(m_radio_cursor_visible_never); @@ -244,12 +244,12 @@ void InterfacePane::ConnectLayout() [this]() { OnLanguageChanged(); }); connect(m_checkbox_top_window, &QCheckBox::toggled, &Settings::Instance(), &Settings::KeepWindowOnTopChanged); - connect(m_radio_cursor_visible_movement, &QRadioButton::toggled, this, - &InterfacePane::OnCursorVisibleMovement); - connect(m_radio_cursor_visible_never, &QRadioButton::toggled, this, - &InterfacePane::OnCursorVisibleNever); - connect(m_radio_cursor_visible_always, &QRadioButton::toggled, this, - &InterfacePane::OnCursorVisibleAlways); + connect(m_radio_cursor_visible_movement, &ConfigRadioInt::OnSelected, &Settings::Instance(), + &Settings::CursorVisibilityChanged); + connect(m_radio_cursor_visible_never, &ConfigRadioInt::OnSelected, &Settings::Instance(), + &Settings::CursorVisibilityChanged); + connect(m_radio_cursor_visible_always, &ConfigRadioInt::OnSelected, &Settings::Instance(), + &Settings::CursorVisibilityChanged); connect(m_checkbox_lock_mouse, &QCheckBox::toggled, &Settings::Instance(), [this]() { Settings::Instance().LockCursorChanged(); }); } @@ -296,14 +296,6 @@ void InterfacePane::LoadConfig() if (index > 0) SignalBlocking(m_combobox_userstyle)->setCurrentIndex(index); - - // Render Window Options - SignalBlocking(m_radio_cursor_visible_movement) - ->setChecked(Settings::Instance().GetCursorVisibility() == Config::ShowCursor::OnMovement); - SignalBlocking(m_radio_cursor_visible_always) - ->setChecked(Settings::Instance().GetCursorVisibility() == Config::ShowCursor::Constantly); - SignalBlocking(m_radio_cursor_visible_never) - ->setChecked(Settings::Instance().GetCursorVisibility() == Config::ShowCursor::Never); } void InterfacePane::OnSaveConfig() @@ -321,21 +313,6 @@ void InterfacePane::OnSaveConfig() Config::Save(); } -void InterfacePane::OnCursorVisibleMovement() -{ - Settings::Instance().SetCursorVisibility(Config::ShowCursor::OnMovement); -} - -void InterfacePane::OnCursorVisibleNever() -{ - Settings::Instance().SetCursorVisibility(Config::ShowCursor::Never); -} - -void InterfacePane::OnCursorVisibleAlways() -{ - Settings::Instance().SetCursorVisibility(Config::ShowCursor::Constantly); -} - void InterfacePane::OnLanguageChanged() { ModalMessageBox::information( @@ -393,6 +370,16 @@ void InterfacePane::AddDescriptions() QT_TR_NOOP("Locks the Mouse Cursor to the Render Widget as long as it has focus. You can " "set a hotkey to unlock it." "

If unsure, leave this unchecked."); + static constexpr char TR_CURSOR_VISIBLE_MOVEMENT_DESCRIPTION[] = + QT_TR_NOOP("Shows the Mouse Cursor briefly whenever it has recently moved, then hides it." + "

If unsure, select this mode."); + static constexpr char TR_CURSOR_VISIBLE_NEVER_DESCRIPTION[] = QT_TR_NOOP( + "Hides the Mouse Cursor whenever it is inside the render window and the render window is " + "focused." + "

If unsure, select "On Movement"."); + static constexpr char TR_CURSOR_VISIBLE_ALWAYS_DESCRIPTION[] = QT_TR_NOOP( + "Shows the Mouse Cursor at all times." + "

If unsure, select "On Movement"."); m_checkbox_use_builtin_title_database->SetDescription(tr(TR_TITLE_DATABASE_DESCRIPTION)); @@ -421,4 +408,10 @@ void InterfacePane::AddDescriptions() m_checkbox_pause_on_focus_lost->SetDescription(tr(TR_PAUSE_ON_FOCUS_LOST_DESCRIPTION)); m_checkbox_lock_mouse->SetDescription(tr(TR_LOCK_MOUSE_DESCRIPTION)); + + m_radio_cursor_visible_movement->SetDescription(tr(TR_CURSOR_VISIBLE_MOVEMENT_DESCRIPTION)); + + m_radio_cursor_visible_never->SetDescription(tr(TR_CURSOR_VISIBLE_NEVER_DESCRIPTION)); + + m_radio_cursor_visible_always->SetDescription(tr(TR_CURSOR_VISIBLE_ALWAYS_DESCRIPTION)); } diff --git a/Source/Core/DolphinQt/Settings/InterfacePane.h b/Source/Core/DolphinQt/Settings/InterfacePane.h index 90cd75e3af..17be1377d6 100644 --- a/Source/Core/DolphinQt/Settings/InterfacePane.h +++ b/Source/Core/DolphinQt/Settings/InterfacePane.h @@ -6,10 +6,10 @@ #include class ConfigBool; +class ConfigRadioInt; class ConfigStringChoice; class QComboBox; class QLabel; -class QRadioButton; class QVBoxLayout; class ToolTipCheckBox; @@ -28,9 +28,6 @@ private: void UpdateShowDebuggingCheckbox(); void LoadConfig(); void OnSaveConfig(); - void OnCursorVisibleMovement(); - void OnCursorVisibleNever(); - void OnCursorVisibleAlways(); void OnLanguageChanged(); QVBoxLayout* m_main_layout; @@ -51,8 +48,8 @@ private: ConfigBool* m_checkbox_enable_osd; ConfigBool* m_checkbox_show_active_title; ConfigBool* m_checkbox_pause_on_focus_lost; - QRadioButton* m_radio_cursor_visible_movement; - QRadioButton* m_radio_cursor_visible_never; - QRadioButton* m_radio_cursor_visible_always; + ConfigRadioInt* m_radio_cursor_visible_movement; + ConfigRadioInt* m_radio_cursor_visible_never; + ConfigRadioInt* m_radio_cursor_visible_always; ConfigBool* m_checkbox_lock_mouse; };