From c4169ba15ad18b79efd8e25887b285e105597740 Mon Sep 17 00:00:00 2001 From: Clayton Groeneveld Date: Tue, 15 Oct 2019 23:20:35 -0500 Subject: [PATCH] UI: Add stats reset hotkey --- UI/data/locale/en-US.ini | 1 + UI/window-basic-main.cpp | 21 +++++++++++++++++++++ UI/window-basic-main.hpp | 3 +++ UI/window-basic-stats.hpp | 4 +++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index 096c860d1..12b91a537 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -210,6 +210,7 @@ Basic.Stats.DroppedFrames="Dropped Frames (Network)" Basic.Stats.MegabytesSent="Total Data Output" Basic.Stats.Bitrate="Bitrate" Basic.Stats.DiskFullIn="Disk full in (approx.)" +Basic.Stats.ResetStats="Reset Stats" ResetUIWarning.Title="Are you sure you want to reset the UI?" ResetUIWarning.Text="Resetting the UI will hide additional docks. You will need to unhide these docks from the view menu if you want them to be visible.\n\nAre you sure you want to reset the UI?" diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 94723f150..1e4ca2a6b 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -2214,6 +2214,19 @@ void OBSBasic::CreateHotkeys() transitionHotkey = obs_hotkey_register_frontend( "OBSBasic.Transition", Str("Transition"), transition, this); LoadHotkey(transitionHotkey, "OBSBasic.Transition"); + + auto resetStats = [](void *data, obs_hotkey_id, obs_hotkey_t *, + bool pressed) { + if (pressed) + QMetaObject::invokeMethod(static_cast(data), + "ResetStatsHotkey", + Qt::QueuedConnection); + }; + + statsHotkey = obs_hotkey_register_frontend( + "OBSBasic.ResetStats", Str("Basic.Stats.ResetStats"), + resetStats, this); + LoadHotkey(statsHotkey, "OBSBasic.ResetStats"); } void OBSBasic::ClearHotkeys() @@ -2226,6 +2239,7 @@ void OBSBasic::ClearHotkeys() obs_hotkey_unregister(forceStreamingStopHotkey); obs_hotkey_unregister(togglePreviewProgramHotkey); obs_hotkey_unregister(transitionHotkey); + obs_hotkey_unregister(statsHotkey); } OBSBasic::~OBSBasic() @@ -7622,3 +7636,10 @@ void OBSBasic::ScenesReordered(const QModelIndex &parent, int start, int end, OBSProjector::UpdateMultiviewProjectors(); } + +void OBSBasic::ResetStatsHotkey() +{ + QList list = findChildren(); + + foreach(OBSBasicStats * s, list) s->Reset(); +} diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 66caa65ba..0a0c6208b 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -386,6 +386,7 @@ private: volatile bool previewProgramMode = false; obs_hotkey_id togglePreviewProgramHotkey = 0; obs_hotkey_id transitionHotkey = 0; + obs_hotkey_id statsHotkey = 0; int quickTransitionIdCounter = 1; bool overridingTransition = false; @@ -563,6 +564,8 @@ private slots: void ScenesReordered(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row); + void ResetStatsHotkey(); + private: /* OBS Callbacks */ static void SceneReordered(void *data, calldata_t *params); diff --git a/UI/window-basic-stats.hpp b/UI/window-basic-stats.hpp index 8a44e423e..81f993d1a 100644 --- a/UI/window-basic-stats.hpp +++ b/UI/window-basic-stats.hpp @@ -56,7 +56,6 @@ class OBSBasicStats : public QWidget { void AddOutputLabels(QString name); void Update(); - void Reset(); virtual void closeEvent(QCloseEvent *event) override; @@ -77,6 +76,9 @@ private: private slots: void RecordingTimeLeft(); +public slots: + void Reset(); + protected: virtual void showEvent(QShowEvent *event) override; virtual void hideEvent(QHideEvent *event) override;