Input GUI: Add 5 second timeout to button click.

This commit is contained in:
Steven Cherry 2016-06-21 20:09:34 -05:00 committed by Anon
parent a0b9ea36fc
commit ee8b3cba8c
2 changed files with 56 additions and 48 deletions

View File

@ -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();
}
}

View File

@ -7,6 +7,7 @@
#include <memory>
#include <QWidget>
#include <QKeyEvent>
#include <QTimer>
#include "citra_qt/config.h"
#include "core/settings.h"
@ -37,11 +38,13 @@ private:
int key_pressed;
QPushButton* changing_button = nullptr; /// button currently waiting for key press.
QString previous_mapping;
QTimer* timer = new QTimer();
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;
private Q_SLOTS:
void setKey();
};