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())); connect(ui->btnRestoreDefaults, SIGNAL(released()), this, SLOT(restoreDefaults()));
setFocusPolicy(Qt::ClickFocus); setFocusPolicy(Qt::ClickFocus);
timer->setSingleShot(true);
connect(timer, &QTimer::timeout, this, [&]() { key_pressed = Qt::Key_Escape; setKey(); });
this->setConfiguration(); this->setConfiguration();
} }
ConfigureInput::~ConfigureInput() ConfigureInput::~ConfigureInput()
{ {
delete timer;
} }
/// Event handler for all button released() event. /// Event handler for all button released() event.
@ -62,6 +65,7 @@ void ConfigureInput::handleClick()
grabKeyboard(); grabKeyboard();
grabMouse(); grabMouse();
changing_button = sender; changing_button = sender;
timer->start(5000); //Cancel after 5 seconds
} }
/// Save all button configurations to settings file /// 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) if (changing_button != nullptr && event->key() != Qt::Key_unknown)
{ {
key_pressed = event->key(); key_pressed = event->key();
timer->stop();
setKey(); setKey();
} }
} }
@ -164,4 +169,4 @@ void ConfigureInput::restoreDefaults() {
QString keyValue = getKeyName(Config::GetDefaultInput()[i].toInt()); QString keyValue = getKeyName(Config::GetDefaultInput()[i].toInt());
input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue);
} }
} }

View File

@ -1,47 +1,50 @@
// Copyright 2016 Citra Emulator Project // Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#pragma once #pragma once
#include <memory> #include <memory>
#include <QWidget> #include <QWidget>
#include <QKeyEvent> #include <QKeyEvent>
#include <QTimer>
#include "citra_qt/config.h"
#include "core/settings.h" #include "citra_qt/config.h"
#include "ui_configure_input.h" #include "core/settings.h"
#include "ui_configure_input.h"
class QPushButton;
class QString; class QPushButton;
class QString;
namespace Ui {
class ConfigureInput; namespace Ui {
} class ConfigureInput;
}
class ConfigureInput : public QWidget
{ class ConfigureInput : public QWidget
Q_OBJECT {
Q_OBJECT
public:
explicit ConfigureInput(QWidget* parent = nullptr); public:
~ConfigureInput(); explicit ConfigureInput(QWidget* parent = nullptr);
void applyConfiguration(); ~ConfigureInput();
void applyConfiguration();
public Q_SLOTS:
void handleClick(); public Q_SLOTS:
void restoreDefaults(); void handleClick();
private: void restoreDefaults();
std::unique_ptr<Ui::ConfigureInput> ui; private:
std::map<Settings::NativeInput::Values, QPushButton*> input_mapping; std::unique_ptr<Ui::ConfigureInput> ui;
int key_pressed; std::map<Settings::NativeInput::Values, QPushButton*> input_mapping;
QPushButton* changing_button = nullptr; /// button currently waiting for key press. int key_pressed;
QString previous_mapping; QPushButton* changing_button = nullptr; /// button currently waiting for key press.
QString previous_mapping;
void setConfiguration(); QTimer* timer = new QTimer();
void setKey();
void removeDuplicates(const QString& newValue); void setConfiguration();
void keyPressEvent(QKeyEvent* event) override; void removeDuplicates(const QString& newValue);
QString getKeyName(int key_code) const; void keyPressEvent(QKeyEvent* event) override;
Qt::Key getKeyValue(const QString& text) const; QString getKeyName(int key_code) const;
}; Qt::Key getKeyValue(const QString& text) const;
private Q_SLOTS:
void setKey();
};