From 4d6e3bad7e38a80375c4888cf630aa71960d2899 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 24 Feb 2017 11:43:34 +0100 Subject: gui: simplify keyboard listener dialog It's now generated from .ui QDialog, not a manually created QDialog from QLabel in .ui. --- gui/keyboard.h | 6 +++--- gui/keyboard_listener.ui | 35 +++++++++++++---------------------- gui/options-dialog.cpp | 23 +++++++---------------- 3 files changed, 23 insertions(+), 41 deletions(-) (limited to 'gui') 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 +#include #include #include -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 @@ keyboard_listener - - - Qt::ApplicationModal - + 0 0 - 224 - 33 + 587 + 273 - - - 0 - 0 - - - Bind a shortcut - - - <html><head/><body><p>Press a key or close this window to remove the keybinding.</p></body></html> - - - Qt::RichText - - - 10 + Dialog + + + + + Press a key or close this window to remove the keybinding. + + + + 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)); } -- cgit v1.2.3