diff options
Diffstat (limited to 'gui/keyboard.h')
| -rw-r--r-- | gui/keyboard.h | 82 |
1 files changed, 27 insertions, 55 deletions
diff --git a/gui/keyboard.h b/gui/keyboard.h index 690bd651..ea35d372 100644 --- a/gui/keyboard.h +++ b/gui/keyboard.h @@ -1,68 +1,40 @@ #pragma once -#include "ui_keyboard_listener.h" + +/* Copyright (c) 2015, 2017 Stanislaw Halik + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#include "export.hpp" + #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> +#include <QtEvents> -class KeyboardListener : public QDialog +class OTR_GUI_EXPORT keyboard_listener : public QDialog { Q_OBJECT - Ui_keyboard_listener ui; -#ifdef _WIN32 - 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); - } -#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; + void receive_key(const Key& k); - default: - emit key_pressed(QKeySequence(event->key() | event->modifiers())); - break; - } - } + KeybindingWorker::Token token{[this](const Key& k) {receive_key(k);}}; +#else + void keyPressEvent(QKeyEvent* event) override; #endif + + Ui_keyboard_listener ui; + +public: + keyboard_listener(QWidget* parent = nullptr); signals: void key_pressed(QKeySequence k); void joystick_button_pressed(QString guid, int idx, bool held); |
