diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-05-15 12:30:35 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-05-15 12:30:35 +0200 |
commit | 7ed453de4a77266e7e29f2f944b285b4fe3b248b (patch) | |
tree | c03ef2cee93ee78c259542ad2fdc8594ae0c7264 /gui | |
parent | 2ab0343a75e165684dba64aea4b54a5abbe8086c (diff) |
api,gui: disable all keyboard shortcuts while binding a key
Previous disallowed binding an already-bound key on Unix since Qxt
doesn't pass through bound keys unlike the Windows implementation.
Refactor some common code.
The Windows implementation isn't even compile-tested.
Diffstat (limited to 'gui')
-rwxr-xr-x | gui/options-dialog.cpp | 3 | ||||
-rw-r--r-- | gui/options-dialog.hpp | 3 | ||||
-rwxr-xr-x | gui/ui.cpp | 33 | ||||
-rwxr-xr-x | gui/ui.h | 2 |
4 files changed, 25 insertions, 16 deletions
diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp index c99bc730..e7a54bb2 100755 --- a/gui/options-dialog.cpp +++ b/gui/options-dialog.cpp @@ -30,10 +30,8 @@ static QString kopts_to_string(const key_opts& kopts) } OptionsDialog::OptionsDialog(main_settings& main, - std::function<void()> register_global_keys, std::function<void(bool)> pause_keybindings) : main(main), - register_global_keys(register_global_keys), pause_keybindings(pause_keybindings) { ui.setupUi(this); @@ -131,7 +129,6 @@ void OptionsDialog::bind_key(key_opts& kopts, QLabel* label) d.show(); d.exec(); pause_keybindings(false); - register_global_keys(); label->setText(kopts_to_string(kopts)); delete l; } diff --git a/gui/options-dialog.hpp b/gui/options-dialog.hpp index 7700162b..a879a208 100644 --- a/gui/options-dialog.hpp +++ b/gui/options-dialog.hpp @@ -12,10 +12,9 @@ class OptionsDialog: public QWidget signals: void reload(); public: - OptionsDialog(main_settings& main, std::function<void()> register_global_keys, std::function<void(bool)> pause_keybindings); + OptionsDialog(main_settings& main, std::function<void(bool)> pause_keybindings); private: main_settings& main; - std::function<void()> register_global_keys; std::function<void(bool)> pause_keybindings; Ui::UI_Settings ui; void closeEvent(QCloseEvent *) override { doCancel(); } @@ -22,8 +22,7 @@ MainWindow::MainWindow() : pose_update_timer(this), kbd_quit(QKeySequence("Ctrl+Q"), this), - is_refreshing_profiles(false), - keys_paused(false) + is_refreshing_profiles(false) { ui.setupUi(this); @@ -109,19 +108,19 @@ MainWindow::MainWindow() : QMessageBox::Ok, QMessageBox::NoButton); connect(this, &MainWindow::emit_start_tracker, - this, [&]() -> void { if (keys_paused) return; qDebug() << "start tracker"; startTracker(); }, + this, [&]() -> void { qDebug() << "start tracker"; startTracker(); }, Qt::QueuedConnection); connect(this, &MainWindow::emit_stop_tracker, - this, [&]() -> void { if (keys_paused) return; qDebug() << "stop tracker"; stopTracker(); }, + this, [&]() -> void { qDebug() << "stop tracker"; stopTracker(); }, Qt::QueuedConnection); connect(this, &MainWindow::emit_toggle_tracker, - this, [&]() -> void { if (keys_paused) return; qDebug() << "toggle tracker"; if (work) stopTracker(); else startTracker(); }, + this, [&]() -> void { qDebug() << "toggle tracker"; if (work) stopTracker(); else startTracker(); }, Qt::QueuedConnection); connect(this, &MainWindow::emit_restart_tracker, - this, [&]() -> void { if (keys_paused) return; qDebug() << "retart tracker"; stopTracker(); startTracker(); }, + this, [&]() -> void { qDebug() << "restart tracker"; stopTracker(); startTracker(); }, Qt::QueuedConnection); register_shortcuts(); @@ -504,11 +503,10 @@ bool mk_window(mem<t>* place, Args&&... params) } void MainWindow::show_options_dialog() { - if (mk_window(&options_widget, - s, - [&]() -> void { register_shortcuts(); }, - [&](bool flag) -> void { keys_paused = flag; })) + if (mk_window(&options_widget, s, [&](bool flag) -> void { set_keys_enabled(!flag); })) + { connect(options_widget.get(), SIGNAL(reload()), this, SLOT(reload_options())); + } } void MainWindow::showCurveConfiguration() { @@ -606,6 +604,21 @@ void MainWindow::maybe_start_profile_from_executable() } } +void MainWindow::set_keys_enabled(bool flag) +{ + if (!flag) + { + if (work) + work->sc->reload({}); + global_shortcuts.reload({}); + } + else + { + register_shortcuts(); + } + qDebug() << "keybindings set to" << flag; +} + void MainWindow::set_profile(const QString &profile) { QSettings settings(OPENTRACK_ORG); @@ -55,7 +55,6 @@ class MainWindow : public QMainWindow, private State process_detector_worker det; QMenu profile_menu; bool is_refreshing_profiles; - volatile bool keys_paused; QTimer save_timer; mem<dylib> current_tracker() @@ -120,4 +119,5 @@ public: void save_mappings(); void load_mappings(); static void set_working_directory(); + void set_keys_enabled(bool flag); }; |