diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-25 11:43:10 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-25 11:43:10 +0200 |
commit | 10ac081b3c4ebb9b29b81b30f5efe6622f4212bc (patch) | |
tree | fedfe7efc494145d0b46e91ba5a94c47cb0c1b6f /facetracknoir/options-dialog.cpp | |
parent | 6baa8ca1070612e5d7cbae7aa62cbe4a9e51ad40 (diff) | |
parent | 24538cf3a3a91481851618791b11be81437563e4 (diff) |
Merge branch 'unstable' into trackhat-ui
Diffstat (limited to 'facetracknoir/options-dialog.cpp')
-rw-r--r-- | facetracknoir/options-dialog.cpp | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/facetracknoir/options-dialog.cpp b/facetracknoir/options-dialog.cpp index f77c7cc1..207c1afb 100644 --- a/facetracknoir/options-dialog.cpp +++ b/facetracknoir/options-dialog.cpp @@ -8,6 +8,9 @@ #include "options-dialog.hpp" #include "ftnoir_tracker_pt/camera.h" +#include "keyboard.h" +#include <QPushButton> +#include <QLayout> OptionsDialog::OptionsDialog(State& state) : state(state), trans_calib_running(false) { @@ -16,27 +19,6 @@ OptionsDialog::OptionsDialog(State& state) : state(state), trans_calib_running(f connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); - for ( int i = 0; i < global_key_sequences.size(); i++) { - ui.cbxCenterKey->addItem(global_key_sequences.at(i)); - ui.cbxToggleKey->addItem(global_key_sequences.at(i)); - ui.cbxZeroKey->addItem(global_key_sequences.at(i)); - } - - tie_setting(s.center.key_index, ui.cbxCenterKey); - tie_setting(s.center.alt, ui.chkCenterAlt); - tie_setting(s.center.shift, ui.chkCenterShift); - tie_setting(s.center.ctrl, ui.chkCenterCtrl); - - tie_setting(s.toggle.key_index, ui.cbxToggleKey); - tie_setting(s.toggle.alt, ui.chkToggleAlt); - tie_setting(s.toggle.shift, ui.chkToggleShift); - tie_setting(s.toggle.ctrl, ui.chkToggleCtrl); - - tie_setting(s.zero.key_index, ui.cbxZeroKey); - tie_setting(s.zero.alt, ui.chkZeroAlt); - tie_setting(s.zero.shift, ui.chkZeroShift); - tie_setting(s.zero.ctrl, ui.chkZeroCtrl); - tie_setting(s.s_main.tray_enabled, ui.trayp); tie_setting(s.s_main.center_at_startup, ui.center_at_startup); @@ -102,6 +84,32 @@ OptionsDialog::OptionsDialog(State& state) : state(state), trans_calib_running(f connect( ui.tcalib_button,SIGNAL(toggled(bool)), this,SLOT(startstop_trans_calib(bool)) ); timer.start(100); + + connect(ui.bind_center, &QPushButton::pressed, [&]() -> void { bind_key(s.center.keycode, ui.center_text); }); + connect(ui.bind_zero, &QPushButton::pressed, [&]() -> void { bind_key(s.zero.keycode, ui.zero_text); }); + connect(ui.bind_toggle, &QPushButton::pressed, [&]() -> void { bind_key(s.toggle.keycode, ui.toggle_text); }); + + ui.center_text->setText(s.center.keycode == "" ? "None" : static_cast<QString>(s.center.keycode)); + ui.toggle_text->setText(s.toggle.keycode == "" ? "None" : static_cast<QString>(s.toggle.keycode)); + ui.zero_text->setText(s.zero.keycode == "" ? "None" : static_cast<QString>(s.zero.keycode)); +} + +void OptionsDialog::bind_key(value<QString>& ret, QLabel* label) +{ + ret = ""; + QDialog d; + auto l = new QHBoxLayout; + l->setMargin(0); + auto k = new KeyboardListener; + l->addWidget(k); + d.setLayout(l); + d.setFixedSize(QSize(500, 300)); + d.setWindowFlags(Qt::Dialog); + connect(k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void { ret = s.toString(QKeySequence::PortableText); d.close(); }); + d.exec(); + label->setText(ret == "" ? "None" : static_cast<QString>(ret)); + delete k; + delete l; } void OptionsDialog::doOK() { |