From ee8b3cba8c1415ee446c71717bfe9516e050c0f4 Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Tue, 21 Jun 2016 20:09:34 -0500 Subject: [PATCH] Input GUI: Add 5 second timeout to button click. --- src/citra_qt/configure_input.cpp | 7 ++- src/citra_qt/configure_input.h | 97 ++++++++++++++++---------------- 2 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index 9922f45a9..64e16d0b5 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -45,11 +45,14 @@ ConfigureInput::ConfigureInput(QWidget* parent) : } connect(ui->btnRestoreDefaults, SIGNAL(released()), this, SLOT(restoreDefaults())); setFocusPolicy(Qt::ClickFocus); + timer->setSingleShot(true); + connect(timer, &QTimer::timeout, this, [&]() { key_pressed = Qt::Key_Escape; setKey(); }); this->setConfiguration(); } ConfigureInput::~ConfigureInput() { + delete timer; } /// Event handler for all button released() event. @@ -62,6 +65,7 @@ void ConfigureInput::handleClick() grabKeyboard(); grabMouse(); changing_button = sender; + timer->start(5000); //Cancel after 5 seconds } /// Save all button configurations to settings file @@ -89,6 +93,7 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) if (changing_button != nullptr && event->key() != Qt::Key_unknown) { key_pressed = event->key(); + timer->stop(); setKey(); } } @@ -164,4 +169,4 @@ void ConfigureInput::restoreDefaults() { QString keyValue = getKeyName(Config::GetDefaultInput()[i].toInt()); input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); } -} +} \ No newline at end of file diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index a3df7fc97..1718d69e8 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -1,47 +1,50 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include - -#include "citra_qt/config.h" -#include "core/settings.h" -#include "ui_configure_input.h" - -class QPushButton; -class QString; - -namespace Ui { - class ConfigureInput; -} - -class ConfigureInput : public QWidget -{ - Q_OBJECT - -public: - explicit ConfigureInput(QWidget* parent = nullptr); - ~ConfigureInput(); - void applyConfiguration(); - - public Q_SLOTS: - void handleClick(); - void restoreDefaults(); -private: - std::unique_ptr ui; - std::map input_mapping; - int key_pressed; - QPushButton* changing_button = nullptr; /// button currently waiting for key press. - QString previous_mapping; - - void setConfiguration(); - void setKey(); - void removeDuplicates(const QString& newValue); - void keyPressEvent(QKeyEvent* event) override; - QString getKeyName(int key_code) const; - Qt::Key getKeyValue(const QString& text) const; -}; +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include + +#include "citra_qt/config.h" +#include "core/settings.h" +#include "ui_configure_input.h" + +class QPushButton; +class QString; + +namespace Ui { + class ConfigureInput; +} + +class ConfigureInput : public QWidget +{ + Q_OBJECT + +public: + explicit ConfigureInput(QWidget* parent = nullptr); + ~ConfigureInput(); + void applyConfiguration(); + + public Q_SLOTS: + void handleClick(); + void restoreDefaults(); +private: + std::unique_ptr ui; + std::map input_mapping; + int key_pressed; + QPushButton* changing_button = nullptr; /// button currently waiting for key press. + QString previous_mapping; + QTimer* timer = new QTimer(); + + void setConfiguration(); + void removeDuplicates(const QString& newValue); + void keyPressEvent(QKeyEvent* event) override; + QString getKeyName(int key_code) const; + Qt::Key getKeyValue(const QString& text) const; + private Q_SLOTS: + void setKey(); +};