summaryrefslogtreecommitdiffhomepage
path: root/facetracknoir/options-dialog.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-25 02:50:52 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-25 02:51:44 +0200
commit95114eccc774bbb0fbeade8904aafa4f9b6d143d (patch)
treee80f681b8374a91579ebd0fbfff9ecd48402e136 /facetracknoir/options-dialog.cpp
parent7d0c58540103e9182ba584b440b91068df03a49c (diff)
initial impl of arbitrary keybindings
Issue: #118 Linux and OSX likely broken for now.
Diffstat (limited to 'facetracknoir/options-dialog.cpp')
-rw-r--r--facetracknoir/options-dialog.cpp50
1 files changed, 29 insertions, 21 deletions
diff --git a/facetracknoir/options-dialog.cpp b/facetracknoir/options-dialog.cpp
index ca4c6c3e..1d8e636a 100644
--- a/facetracknoir/options-dialog.cpp
+++ b/facetracknoir/options-dialog.cpp
@@ -7,6 +7,9 @@
*/
#include "options-dialog.hpp"
+#include "keyboard.h"
+#include <QPushButton>
+#include <QLayout>
OptionsDialog::OptionsDialog()
{
@@ -15,27 +18,6 @@ OptionsDialog::OptionsDialog()
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);
@@ -67,6 +49,32 @@ OptionsDialog::OptionsDialog()
tie_setting(s.s_main.camera_yaw, ui.camera_yaw);
tie_setting(s.s_main.camera_pitch, ui.camera_pitch);
tie_setting(s.s_main.camera_roll, ui.camera_roll);
+
+ 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(QKeySequence(s.center.keycode).toString());
+ ui.zero_text->setText(QKeySequence(s.zero.keycode).toString());
+ ui.toggle_text->setText(QKeySequence(s.toggle.keycode).toString());
+}
+
+void OptionsDialog::bind_key(value<int>& ret, QLabel* label)
+{
+ ret = 0;
+ QDialog d;
+ auto l = new QHBoxLayout;
+ l->setMargin(0);
+ auto k = new KeyboardListener;
+ l->addWidget(k);
+ d.setLayout(l);
+ d.setFixedSize(QSize(500, 500));
+ d.setWindowFlags(Qt::Dialog);
+ connect(k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void { ret = static_cast<QVariant>(s).toInt(); d.close(); });
+ d.exec();
+ label->setText(QKeySequence(ret).toString());
+ delete k;
+ delete l;
}
void OptionsDialog::doOK() {