summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-06-05 08:58:11 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-06-05 08:58:11 +0200
commit8682714c74f66e2e33e47db559e983208d6a2aaa (patch)
treef48b175abece2e9f811de7c3544b38acfac9938b
parent8c0955603770bd130ae1290a0fdeca0e6c0039b6 (diff)
gui: split from header
-rw-r--r--gui/keyboard.cpp54
-rw-r--r--gui/keyboard.h57
2 files changed, 62 insertions, 49 deletions
diff --git a/gui/keyboard.cpp b/gui/keyboard.cpp
new file mode 100644
index 00000000..1426300f
--- /dev/null
+++ b/gui/keyboard.cpp
@@ -0,0 +1,54 @@
+#include "keyboard.h"
+
+#include <QDebug>
+
+KeyboardListener::KeyboardListener(QWidget* parent) :
+ QDialog(parent)
+#if defined _WIN32
+ , token([&](const Key& k) {
+ if(k.guid != "")
+ {
+ int mods = 0;
+ if (k.alt) mods |= Qt::AltModifier;
+ if (k.shift) mods |= Qt::ShiftModifier;
+ if (k.ctrl) mods |= Qt::ControlModifier;
+ joystick_button_pressed(k.guid, k.keycode | mods, k.held);
+ }
+ else
+ {
+ Qt::KeyboardModifiers m;
+ QKeySequence k_;
+ if (win_key::to_qt(k, k_, m))
+ key_pressed(static_cast<QVariant>(k_).toInt() | m);
+ }
+ })
+// token initializer ends, real ctor body begins
+#endif
+{
+ ui.setupUi(this);
+ setFocusPolicy(Qt::StrongFocus);
+}
+
+#if !defined _WIN32
+void KeyboardListener::keyPressEvent(QKeyEvent* event)
+{
+ switch (event->key())
+ {
+ case Qt::Key_Control:
+ case Qt::Key_Shift:
+ case Qt::Key_Meta:
+ case Qt::Key_Alt:
+ case Qt::Key_AltGr:
+ case Qt::Key_CapsLock:
+ case Qt::Key_NumLock:
+ break;
+ case Qt::Key_Escape:
+ close();
+ break;
+
+ default:
+ emit key_pressed(QKeySequence(event->key() | event->modifiers()));
+ break;
+ }
+}
+#endif
diff --git a/gui/keyboard.h b/gui/keyboard.h
index 690bd651..f4e5f7c0 100644
--- a/gui/keyboard.h
+++ b/gui/keyboard.h
@@ -1,12 +1,14 @@
#pragma once
-#include "ui_keyboard_listener.h"
+
#ifdef _WIN32
-#include "logic/win32-shortcuts.h"
-#include "dinput/keybinding-worker.hpp"
+# include "logic/win32-shortcuts.h"
+# include "dinput/keybinding-worker.hpp"
#endif
+
+#include "ui_keyboard_listener.h"
+
#include <QDialog>
#include <QKeyEvent>
-#include <QDebug>
class KeyboardListener : public QDialog
{
@@ -16,52 +18,9 @@ class KeyboardListener : public QDialog
KeybindingWorker::Token token;
#endif
public:
- KeyboardListener(QWidget* parent = nullptr) : QDialog(parent)
-#ifdef _WIN32
- , token([&](const Key& k) {
- if(k.guid != "")
- {
- int mods = 0;
- if (k.alt) mods |= Qt::AltModifier;
- if (k.shift) mods |= Qt::ShiftModifier;
- if (k.ctrl) mods |= Qt::ControlModifier;
- joystick_button_pressed(k.guid, k.keycode | mods, k.held);
- }
- else
- {
- Qt::KeyboardModifiers m;
- QKeySequence k_;
- if (win_key::to_qt(k, k_, m))
- key_pressed(static_cast<QVariant>(k_).toInt() | m);
- }
- })
-#endif
- {
- ui.setupUi(this);
- setFocusPolicy(Qt::StrongFocus);
- }
+ KeyboardListener(QWidget* parent = nullptr);
#ifndef _WIN32
- void keyPressEvent(QKeyEvent* event) override
- {
- switch (event->key())
- {
- case Qt::Key_Control:
- case Qt::Key_Shift:
- case Qt::Key_Meta:
- case Qt::Key_Alt:
- case Qt::Key_AltGr:
- case Qt::Key_CapsLock:
- case Qt::Key_NumLock:
- break;
- case Qt::Key_Escape:
- close();
- break;
-
- default:
- emit key_pressed(QKeySequence(event->key() | event->modifiers()));
- break;
- }
- }
+ void keyPressEvent(QKeyEvent* event) override;
#endif
signals:
void key_pressed(QKeySequence k);