From 7ed453de4a77266e7e29f2f944b285b4fe3b248b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 15 May 2016 12:30:35 +0200 Subject: 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. --- gui/ui.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'gui/ui.cpp') diff --git a/gui/ui.cpp b/gui/ui.cpp index 2832126b..004b67c4 100755 --- a/gui/ui.cpp +++ b/gui/ui.cpp @@ -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* 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); -- cgit v1.2.3