From 8494245b92e02f982a506ed044a555db239bd4d6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Jul 2015 05:18:01 +0200 Subject: shortcuts: store .ini value as portable string --- facetracknoir/options-dialog.cpp | 14 +++++++------- facetracknoir/options-dialog.hpp | 2 +- opentrack/shortcuts.cpp | 15 +++++++++++---- opentrack/shortcuts.h | 4 ++-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/facetracknoir/options-dialog.cpp b/facetracknoir/options-dialog.cpp index 1d8e636a..8ac95b71 100644 --- a/facetracknoir/options-dialog.cpp +++ b/facetracknoir/options-dialog.cpp @@ -54,14 +54,14 @@ OptionsDialog::OptionsDialog() 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()); + ui.center_text->setText(s.center.keycode == "" ? "None" : static_cast(s.center.keycode)); + ui.toggle_text->setText(s.toggle.keycode == "" ? "None" : static_cast(s.toggle.keycode)); + ui.zero_text->setText(s.zero.keycode == "" ? "None" : static_cast(s.zero.keycode)); } -void OptionsDialog::bind_key(value& ret, QLabel* label) +void OptionsDialog::bind_key(value& ret, QLabel* label) { - ret = 0; + ret = ""; QDialog d; auto l = new QHBoxLayout; l->setMargin(0); @@ -70,9 +70,9 @@ void OptionsDialog::bind_key(value& ret, QLabel* label) d.setLayout(l); d.setFixedSize(QSize(500, 500)); d.setWindowFlags(Qt::Dialog); - connect(k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void { ret = static_cast(s).toInt(); d.close(); }); + connect(k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void { ret = s.toString(QKeySequence::PortableText); d.close(); }); d.exec(); - label->setText(QKeySequence(ret).toString()); + label->setText(ret == "" ? "None" : static_cast(ret)); delete k; delete l; } diff --git a/facetracknoir/options-dialog.hpp b/facetracknoir/options-dialog.hpp index 0ab9849d..9ad656a4 100644 --- a/facetracknoir/options-dialog.hpp +++ b/facetracknoir/options-dialog.hpp @@ -18,5 +18,5 @@ private: private slots: void doOK(); void doCancel(); - void bind_key(value& ret, QLabel* label); + void bind_key(value& ret, QLabel* label); }; diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp index d68da30e..81393ae3 100644 --- a/opentrack/shortcuts.cpp +++ b/opentrack/shortcuts.cpp @@ -132,18 +132,25 @@ void Shortcuts::bind_keyboard_shortcut(K &key, key_opts& k) key->setShortcut(QKeySequence::UnknownKey); } - if (k.keycode) + if (k.keycode != "") { - key->setShortcut(QKeySequence(k.keycode)); + key->setShortcut(QKeySequence::fromString(k.keycode, QKeySequence::PortableText)); key->setEnabled(); } } #else key = K(); int idx = 0; + QKeySequence seq;; + + if (k.keycode == "") + code = QKeySequence(Qt::Key_unknown); + else + code = QKeySequence::fromString(k.keycode, QKeySequence::PortableText) + Qt::KeyboardModifiers mods = Qt::NoModifier; - if (k.keycode != Qt::Key_unknown) - win_key::from_qt(QKeySequence(k.keycode), idx, mods); + if (code != Qt::Key_unknown) + win_key::from_qt(code, idx, mods); key.shift = !!(mods & Qt::ShiftModifier); key.alt = !!(mods & Qt::AltModifier); key.ctrl = !!(mods & Qt::ControlModifier); diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h index 6a9a6f77..2d7fec54 100644 --- a/opentrack/shortcuts.h +++ b/opentrack/shortcuts.h @@ -27,10 +27,10 @@ using namespace options; extern QList global_key_sequences; struct key_opts { - value keycode; + value keycode; key_opts(pbundle b, const QString& name) : - keycode(b, QString("keycode-%1").arg(name), 0) + keycode(b, QString("keycode-%1").arg(name), "") {} }; -- cgit v1.2.3