diff options
-rw-r--r-- | gui/keyboard.h | 6 | ||||
-rw-r--r-- | gui/keyboard_listener.ui | 35 | ||||
-rw-r--r-- | gui/options-dialog.cpp | 23 |
3 files changed, 23 insertions, 41 deletions
diff --git a/gui/keyboard.h b/gui/keyboard.h index d35fe675..58d4e674 100644 --- a/gui/keyboard.h +++ b/gui/keyboard.h @@ -4,11 +4,11 @@ #include "logic/win32-shortcuts.h" #include "dinput/keybinding-worker.hpp" #endif -#include <QLabel> +#include <QDialog> #include <QKeyEvent> #include <QDebug> -class KeyboardListener : public QLabel +class KeyboardListener : public QDialog { Q_OBJECT Ui_keyboard_listener ui; @@ -16,7 +16,7 @@ class KeyboardListener : public QLabel KeybindingWorker::Token token; #endif public: - KeyboardListener(QWidget* parent = nullptr) : QLabel(parent) + KeyboardListener(QWidget* parent = nullptr) : QDialog(parent) #ifdef _WIN32 , token([&](const Key& k) { if(k.guid != "") diff --git a/gui/keyboard_listener.ui b/gui/keyboard_listener.ui index b6977df0..f7f29468 100644 --- a/gui/keyboard_listener.ui +++ b/gui/keyboard_listener.ui @@ -1,36 +1,27 @@ <?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> + <widget class="QDialog" name="keyboard_listener"> <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>224</width> - <height>33</height> + <width>587</width> + <height>273</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><html><head/><body><p>Press a key or close this window to remove the keybinding.</p></body></html></string> - </property> - <property name="textFormat"> - <enum>Qt::RichText</enum> - </property> - <property name="margin"> - <number>10</number> + <string>Dialog</string> </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item alignment="Qt::AlignHCenter|Qt::AlignVCenter"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Press a key or close this window to remove the keybinding.</string> + </property> + </widget> + </item> + </layout> </widget> <resources/> <connections/> diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp index 98953086..b1dfc472 100644 --- a/gui/options-dialog.cpp +++ b/gui/options-dialog.cpp @@ -150,31 +150,22 @@ void OptionsDialog::bind_key(key_opts& kopts, QLabel* label) kopts.button = -1; kopts.guid = ""; kopts.keycode = ""; - auto d = new QDialog(this, Qt::MSWindowsFixedSizeDialogHint); - auto l = new QHBoxLayout; - l->setMargin(0); auto k = new KeyboardListener; - l->addWidget(k); - d->setLayout(l); - d->setFixedSize(QSize(500, 300)); - d->setWindowModality(Qt::ApplicationModal); - - d->deleteLater(); - l->deleteLater(); + k->setWindowModality(Qt::ApplicationModal); k->deleteLater(); connect(k, &KeyboardListener::key_pressed, - d, + this, [&](QKeySequence s) { kopts.keycode = s.toString(QKeySequence::PortableText); kopts.guid = ""; kopts.button = -1; - d->close(); + k->close(); }); connect(k, &KeyboardListener::joystick_button_pressed, - d, + this, [&](QString guid, int idx, bool held) { if (!held) @@ -182,12 +173,12 @@ void OptionsDialog::bind_key(key_opts& kopts, QLabel* label) kopts.guid = guid; kopts.keycode = ""; kopts.button = idx; - d->close(); + k->close(); } }); - connect(main.b.get(), &options::detail::bundle::reloading, d, &QDialog::close); + connect(main.b.get(), &options::detail::bundle::reloading, k, &QDialog::close); pause_keybindings(true); - d->exec(); + k->exec(); pause_keybindings(false); label->setText(kopts_to_string(kopts)); } |