From fff6c5d9b7dce04eaee2b3639f2711d70b7bf6e1 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 27 Oct 2018 06:30:57 +0000 Subject: trackmouse: connect slider to mouse sensitivity --- variant/trackmouse/lang/nl_NL.ts | 8 ++++---- variant/trackmouse/lang/ru_RU.ts | 8 ++++---- variant/trackmouse/lang/stub.ts | 8 ++++---- variant/trackmouse/lang/zh_CN.ts | 8 ++++---- variant/trackmouse/window.cpp | 33 +++++++++++++++++++++++++++++++++ variant/trackmouse/window.hpp | 8 ++++++++ variant/trackmouse/window.ui | 5 ++++- 7 files changed, 61 insertions(+), 17 deletions(-) (limited to 'variant/trackmouse') diff --git a/variant/trackmouse/lang/nl_NL.ts b/variant/trackmouse/lang/nl_NL.ts index 239c183e..92f790af 100644 --- a/variant/trackmouse/lang/nl_NL.ts +++ b/variant/trackmouse/lang/nl_NL.ts @@ -46,10 +46,6 @@ Exiting now. Alt+F11 - - freeze - - Alt+F12 @@ -70,5 +66,9 @@ Exiting now. Stop + + freeze toggle + + diff --git a/variant/trackmouse/lang/ru_RU.ts b/variant/trackmouse/lang/ru_RU.ts index 611b59ab..dd9011c4 100644 --- a/variant/trackmouse/lang/ru_RU.ts +++ b/variant/trackmouse/lang/ru_RU.ts @@ -46,10 +46,6 @@ Exiting now. Alt+F11 - - freeze - - Alt+F12 @@ -70,5 +66,9 @@ Exiting now. Stop + + freeze toggle + + diff --git a/variant/trackmouse/lang/stub.ts b/variant/trackmouse/lang/stub.ts index 5a3dd52d..968e31c5 100644 --- a/variant/trackmouse/lang/stub.ts +++ b/variant/trackmouse/lang/stub.ts @@ -46,10 +46,6 @@ Exiting now. Alt+F11 - - freeze - - Alt+F12 @@ -70,5 +66,9 @@ Exiting now. Stop + + freeze toggle + + diff --git a/variant/trackmouse/lang/zh_CN.ts b/variant/trackmouse/lang/zh_CN.ts index 5a3dd52d..968e31c5 100644 --- a/variant/trackmouse/lang/zh_CN.ts +++ b/variant/trackmouse/lang/zh_CN.ts @@ -46,10 +46,6 @@ Exiting now. Alt+F11 - - freeze - - Alt+F12 @@ -70,5 +66,9 @@ Exiting now. Stop + + freeze toggle + + diff --git a/variant/trackmouse/window.cpp b/variant/trackmouse/window.cpp index bb94f1da..d893b5c1 100644 --- a/variant/trackmouse/window.cpp +++ b/variant/trackmouse/window.cpp @@ -83,6 +83,39 @@ main_window::main_window() : State(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH) connect(ui.btnStartTracker, SIGNAL(clicked()), this, SLOT(start_tracker_())); connect(ui.btnStopTracker, SIGNAL(clicked()), this, SLOT(stop_tracker_())); + { + tie_setting(mouse.sensitivity_x, ui.sensitivity_slider); + tie_setting(mouse.sensitivity_x, ui.sensitivity_label, + [](double x) { return QString::number(x) + QStringLiteral("%"); }); + // one-way only + tie_setting(mouse.sensitivity_x, this, + [this](double x) { mouse.sensitivity_y = *mouse.sensitivity_x; }); + + // no "ok" button, gotta save on timer + auto save = [this] { + qDebug() << "trackmouse: saving settings"; + mouse.b->save(); + save_settings_timer.stop(); + }; + + auto start_save_timer = [this](double) { + save_settings_timer.start(); + }; + + save_settings_timer.setInterval(save_settings_interval_ms); + save_settings_timer.setSingleShot(true); + + ui.sensitivity_slider->setTracking(false); + connect(&save_settings_timer, &QTimer::timeout, this, save, Qt::DirectConnection); +#if 1 + // this doesn't fire the timer on application load + connect(ui.sensitivity_slider, &QSlider::valueChanged, this, start_save_timer, Qt::DirectConnection); +#else + // but this does so let's not not use it + tie_setting(mouse.sensitivity_x, this, start_save_timer); +#endif + } + force_trackmouse_settings(); register_shortcuts(); diff --git a/variant/trackmouse/window.hpp b/variant/trackmouse/window.hpp index af3a3043..dc335148 100644 --- a/variant/trackmouse/window.hpp +++ b/variant/trackmouse/window.hpp @@ -10,6 +10,8 @@ #pragma once +#include "proto-mouse/mouse-settings.hpp" + #include "api/plugin-support.hpp" #include "logic/main-settings.hpp" #include "logic/pipeline.hpp" @@ -36,13 +38,17 @@ class main_window final : public QMainWindow, private State Ui::window ui; + QTimer save_settings_timer { this }; + Shortcuts global_shortcuts; module_settings m; + mouse_settings mouse; QShortcut kbd_quit { QKeySequence("Ctrl+Q"), this }; std::unique_ptr pFilterDialog; std::unique_ptr pProtocolDialog; std::unique_ptr pTrackerDialog; + bool exiting_already { false }; using dylib_ptr = Modules::dylib_ptr; using dylib_list = Modules::dylib_list; @@ -65,6 +71,8 @@ class main_window final : public QMainWindow, private State bool maybe_die_on_config_not_writable(const QString& current); void die_on_config_not_writable(); + static constexpr inline int save_settings_interval_ms = 2500; + private slots: void save_modules(); void exit(int status = EXIT_SUCCESS); diff --git a/variant/trackmouse/window.ui b/variant/trackmouse/window.ui index f9a45daf..be3efd35 100644 --- a/variant/trackmouse/window.ui +++ b/variant/trackmouse/window.ui @@ -350,6 +350,9 @@ 0 + + 475 + 1 @@ -360,7 +363,7 @@ QSlider::TicksAbove - 10 + 50 -- cgit v1.2.3