From f24c9b7fff9d54a90384e83feb63308683afd60c Mon Sep 17 00:00:00 2001 From: Aneesh Maganti <28660350+aminoa@users.noreply.github.com> Date: Thu, 23 Jan 2025 15:08:50 -0500 Subject: [PATCH] DolphinQT: Create toggle for enabling/disabling time tracking Introduce a new "Enable Time Tracking" checkbox in the InterfacePane UI. The checkbox is dynamically enabled or disabled based on the emulation state, preventing changes while emulation is active. --- .../Core/DolphinQt/Settings/InterfacePane.cpp | 20 +++++++++++++++++++ .../Core/DolphinQt/Settings/InterfacePane.h | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/Source/Core/DolphinQt/Settings/InterfacePane.cpp b/Source/Core/DolphinQt/Settings/InterfacePane.cpp index e52fb6920001..581cddfe6895 100644 --- a/Source/Core/DolphinQt/Settings/InterfacePane.cpp +++ b/Source/Core/DolphinQt/Settings/InterfacePane.cpp @@ -22,6 +22,7 @@ #include "Core/AchievementManager.h" #include "Core/Config/MainSettings.h" #include "Core/Config/UISettings.h" +#include "Core/System.h" #include "DolphinQt/Config/ConfigControls/ConfigBool.h" #include "DolphinQt/Config/ConfigControls/ConfigChoice.h" @@ -32,6 +33,7 @@ #include "DolphinQt/QtUtils/SignalBlocking.h" #include "DolphinQt/Settings.h" +#include #include "UICommon/GameFile.h" static ConfigStringChoice* MakeLanguageComboBox() @@ -95,6 +97,10 @@ InterfacePane::InterfacePane(QWidget* parent) : QWidget(parent) connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, &InterfacePane::UpdateShowDebuggingCheckbox); + connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, + &InterfacePane::OnEmulationStateChanged); + + OnEmulationStateChanged(Core::GetState(Core::System::GetInstance())); } void InterfacePane::CreateLayout() @@ -168,12 +174,14 @@ void InterfacePane::CreateUI() new ConfigBool(tr("Hotkeys Require Window Focus"), Config::MAIN_FOCUSED_HOTKEYS); m_checkbox_disable_screensaver = new ConfigBool(tr("Inhibit Screensaver During Emulation"), Config::MAIN_DISABLE_SCREENSAVER); + m_checkbox_time_tracking = new ConfigBool(tr("Enable Time Tracking"), Config::MAIN_TIME_TRACKING); groupbox_layout->addWidget(m_checkbox_use_builtin_title_database); groupbox_layout->addWidget(m_checkbox_use_covers); groupbox_layout->addWidget(m_checkbox_show_debugging_ui); groupbox_layout->addWidget(m_checkbox_focused_hotkeys); groupbox_layout->addWidget(m_checkbox_disable_screensaver); + groupbox_layout->addWidget(m_checkbox_time_tracking); } void InterfacePane::CreateInGame() @@ -313,6 +321,12 @@ void InterfacePane::OnLanguageChanged() tr("You must restart Dolphin in order for the change to take effect.")); } +void InterfacePane::OnEmulationStateChanged(Core::State state) +{ + const bool running = state != Core::State::Uninitialized; + m_checkbox_time_tracking->setEnabled(!running); +} + void InterfacePane::AddDescriptions() { static constexpr char TR_TITLE_DATABASE_DESCRIPTION[] = QT_TR_NOOP( @@ -341,6 +355,10 @@ void InterfacePane::AddDescriptions() static constexpr char TR_DISABLE_SCREENSAVER_DESCRIPTION[] = QT_TR_NOOP("Disables your screensaver while running a game." "

If unsure, leave this checked."); + static constexpr char TR_TIME_TRACKING[] = + QT_TR_NOOP("Tracks hours/minutes while playing games and displays this in the List View." + "

This setting cannot be changed while emulation is active." + "

If unsure, leave this checked."); static constexpr char TR_CONFIRM_ON_STOP_DESCRIPTION[] = QT_TR_NOOP("Prompts you to confirm that you want to end emulation when you press Stop." "

If unsure, leave this checked."); @@ -394,6 +412,8 @@ void InterfacePane::AddDescriptions() m_checkbox_disable_screensaver->SetDescription(tr(TR_DISABLE_SCREENSAVER_DESCRIPTION)); + m_checkbox_time_tracking->SetDescription(tr(TR_TIME_TRACKING)); + m_checkbox_confirm_on_stop->SetDescription(tr(TR_CONFIRM_ON_STOP_DESCRIPTION)); m_checkbox_use_panic_handlers->SetDescription(tr(TR_USE_PANIC_HANDLERS_DESCRIPTION)); diff --git a/Source/Core/DolphinQt/Settings/InterfacePane.h b/Source/Core/DolphinQt/Settings/InterfacePane.h index 90a81d2114e2..ffe1efa0872e 100644 --- a/Source/Core/DolphinQt/Settings/InterfacePane.h +++ b/Source/Core/DolphinQt/Settings/InterfacePane.h @@ -13,6 +13,11 @@ class QVBoxLayout; class ToolTipCheckBox; class ToolTipComboBox; +namespace Core +{ +enum class State; +} + class InterfacePane final : public QWidget { Q_OBJECT @@ -30,6 +35,8 @@ class InterfacePane final : public QWidget void OnUserStyleChanged(); void OnLanguageChanged(); + void OnEmulationStateChanged(Core::State state); + QVBoxLayout* m_main_layout; ConfigStringChoice* m_combobox_language; @@ -42,6 +49,7 @@ class InterfacePane final : public QWidget ConfigBool* m_checkbox_focused_hotkeys; ConfigBool* m_checkbox_use_covers; ConfigBool* m_checkbox_disable_screensaver; + ConfigBool* m_checkbox_time_tracking; ConfigBool* m_checkbox_confirm_on_stop; ConfigBool* m_checkbox_use_panic_handlers;