summaryrefslogtreecommitdiffhomepage
path: root/facetracknoir
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
parent7d0c58540103e9182ba584b440b91068df03a49c (diff)
initial impl of arbitrary keybindings
Issue: #118 Linux and OSX likely broken for now.
Diffstat (limited to 'facetracknoir')
-rw-r--r--facetracknoir/keyboard.h33
-rw-r--r--facetracknoir/keyboard_listener.ui37
-rw-r--r--facetracknoir/options-dialog.cpp50
-rw-r--r--facetracknoir/options-dialog.hpp1
-rw-r--r--facetracknoir/settings.ui193
5 files changed, 129 insertions, 185 deletions
diff --git a/facetracknoir/keyboard.h b/facetracknoir/keyboard.h
new file mode 100644
index 00000000..65f5c58e
--- /dev/null
+++ b/facetracknoir/keyboard.h
@@ -0,0 +1,33 @@
+#pragma once
+#include "ui_keyboard_listener.h"
+#include <QLabel>
+#include <QKeyEvent>
+
+class KeyboardListener : public QLabel
+{
+ Q_OBJECT
+ Ui_keyboard_listener ui;
+public:
+ KeyboardListener(QWidget* parent = nullptr) : QLabel(parent)
+ {
+ ui.setupUi(this);
+ setFocusPolicy(Qt::StrongFocus);
+ }
+ void keyPressEvent(QKeyEvent* event) override
+ {
+ {
+ switch (event->key() | event->modifiers())
+ {
+ case 83886113: // ctrl
+ case 50331680: // shift
+ case 150994979: // alt
+ case 16777250: // meta
+ return;
+ default: break;
+ }
+ }
+ emit key_pressed(QKeySequence(event->key()));
+ }
+signals:
+ void key_pressed(QKeySequence k);
+};
diff --git a/facetracknoir/keyboard_listener.ui b/facetracknoir/keyboard_listener.ui
new file mode 100644
index 00000000..69ec530d
--- /dev/null
+++ b/facetracknoir/keyboard_listener.ui
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>keyboard_listener</class>
+ <widget class="QLabel" name="keyboard_listener">
+ <property name="windowModality">
+ <enum>Qt::ApplicationModal</enum>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>224</width>
+ <height>33</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="windowTitle">
+ <string>Bind a shortcut</string>
+ </property>
+ <property name="text">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Press a key or close this window to cancel.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+ <property name="margin">
+ <number>10</number>
+ </property>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
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() {
diff --git a/facetracknoir/options-dialog.hpp b/facetracknoir/options-dialog.hpp
index 71a3acda..0ab9849d 100644
--- a/facetracknoir/options-dialog.hpp
+++ b/facetracknoir/options-dialog.hpp
@@ -18,4 +18,5 @@ private:
private slots:
void doOK();
void doCancel();
+ void bind_key(value<int>& ret, QLabel* label);
};
diff --git a/facetracknoir/settings.ui b/facetracknoir/settings.ui
index 34b15b47..5eea9e57 100644
--- a/facetracknoir/settings.ui
+++ b/facetracknoir/settings.ui
@@ -62,82 +62,48 @@
<string notr="true">QGroupBox { border: 0; }</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
- <item row="3" column="0">
- <widget class="QLabel" name="textLabel2_5">
+ <item row="0" column="1">
+ <widget class="QLabel" name="center_text">
<property name="text">
- <string>Toggle</string>
- </property>
- <property name="wordWrap">
- <bool>false</bool>
+ <string/>
</property>
</widget>
</item>
- <item row="2" column="1">
- <widget class="QCheckBox" name="chkCenterShift">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="textLabel2_3">
<property name="text">
- <string>Shift</string>
+ <string>Center</string>
+ </property>
+ <property name="wordWrap">
+ <bool>false</bool>
</property>
</widget>
</item>
- <item row="2" column="2">
- <widget class="QCheckBox" name="chkCenterCtrl">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
+ <item row="6" column="1">
+ <widget class="QLabel" name="zero_text">
<property name="text">
- <string>Ctrl</string>
+ <string/>
</property>
</widget>
</item>
- <item row="2" column="4">
- <widget class="QComboBox" name="cbxCenterKey">
- <property name="minimumSize">
- <size>
- <width>90</width>
- <height>0</height>
- </size>
- </property>
- <property name="toolTip">
- <string>Select Number</string>
- </property>
- <property name="insertPolicy">
- <enum>QComboBox::InsertAlphabetically</enum>
+ <item row="5" column="1">
+ <widget class="QLabel" name="toggle_text">
+ <property name="text">
+ <string/>
</property>
</widget>
</item>
- <item row="2" column="0">
- <widget class="QLabel" name="textLabel2_3">
+ <item row="5" column="0">
+ <widget class="QLabel" name="textLabel2_5">
<property name="text">
- <string>Center</string>
+ <string>Toggle</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
- <item row="2" column="3">
- <widget class="QCheckBox" name="chkCenterAlt">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Alt</string>
- </property>
- </widget>
- </item>
- <item row="4" column="0">
+ <item row="6" column="0">
<widget class="QLabel" name="textLabel2_6">
<property name="text">
<string>Zero</string>
@@ -147,113 +113,24 @@
</property>
</widget>
</item>
- <item row="4" column="3">
- <widget class="QCheckBox" name="chkZeroAlt">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Alt</string>
- </property>
- </widget>
- </item>
- <item row="3" column="2">
- <widget class="QCheckBox" name="chkToggleCtrl">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Ctrl</string>
- </property>
- </widget>
- </item>
- <item row="3" column="3">
- <widget class="QCheckBox" name="chkToggleAlt">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Alt</string>
- </property>
- </widget>
- </item>
- <item row="4" column="2">
- <widget class="QCheckBox" name="chkZeroCtrl">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
+ <item row="0" column="2">
+ <widget class="QPushButton" name="bind_center">
<property name="text">
- <string>Ctrl</string>
+ <string>Bind</string>
</property>
</widget>
</item>
- <item row="4" column="1">
- <widget class="QCheckBox" name="chkZeroShift">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
+ <item row="5" column="2">
+ <widget class="QPushButton" name="bind_toggle">
<property name="text">
- <string>Shift</string>
+ <string>Bind</string>
</property>
</widget>
</item>
- <item row="4" column="4">
- <widget class="QComboBox" name="cbxZeroKey">
- <property name="minimumSize">
- <size>
- <width>90</width>
- <height>0</height>
- </size>
- </property>
- <property name="toolTip">
- <string>Select Number</string>
- </property>
- <property name="insertPolicy">
- <enum>QComboBox::InsertAlphabetically</enum>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <widget class="QCheckBox" name="chkToggleShift">
- <property name="maximumSize">
- <size>
- <width>50</width>
- <height>16777215</height>
- </size>
- </property>
+ <item row="6" column="2">
+ <widget class="QPushButton" name="bind_zero">
<property name="text">
- <string>Shift</string>
- </property>
- </widget>
- </item>
- <item row="3" column="4">
- <widget class="QComboBox" name="cbxToggleKey">
- <property name="minimumSize">
- <size>
- <width>90</width>
- <height>0</height>
- </size>
- </property>
- <property name="toolTip">
- <string>Select Number</string>
- </property>
- <property name="insertPolicy">
- <enum>QComboBox::InsertAlphabetically</enum>
+ <string>Bind</string>
</property>
</widget>
</item>
@@ -1152,21 +1029,9 @@
</customwidget>
</customwidgets>
<tabstops>
- <tabstop>chkCenterShift</tabstop>
<tabstop>tabWidget</tabstop>
- <tabstop>chkCenterAlt</tabstop>
- <tabstop>cbxCenterKey</tabstop>
- <tabstop>chkToggleShift</tabstop>
- <tabstop>chkToggleCtrl</tabstop>
- <tabstop>chkToggleAlt</tabstop>
- <tabstop>cbxToggleKey</tabstop>
- <tabstop>chkZeroShift</tabstop>
- <tabstop>chkZeroCtrl</tabstop>
- <tabstop>chkZeroAlt</tabstop>
- <tabstop>cbxZeroKey</tabstop>
<tabstop>center_at_startup</tabstop>
<tabstop>trayp</tabstop>
- <tabstop>chkCenterCtrl</tabstop>
<tabstop>camera_yaw</tabstop>
<tabstop>camera_pitch</tabstop>
<tabstop>camera_roll</tabstop>