Input-GUI: More cleanup

This commit is contained in:
Steven Cherry 2016-06-12 08:54:41 -05:00
parent 61144d2ab1
commit ce0cc37045
5 changed files with 61 additions and 62 deletions

View File

@ -18,7 +18,7 @@ Config::Config() {
Reload();
}
const std::array<QVariant, Settings::NativeInput::NUM_INPUTS> defaults = {
const std::array<QVariant, Settings::NativeInput::NUM_INPUTS> Config::defaults = {
// directly mapped keys
Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X,
Qt::Key_Q, Qt::Key_W, Qt::Key_1, Qt::Key_2,
@ -31,6 +31,11 @@ const std::array<QVariant, Settings::NativeInput::NUM_INPUTS> defaults = {
Qt::Key_D,
};
const std::array<QVariant, Settings::NativeInput::NUM_INPUTS>& Config::getDefaultInput()
{
return defaults;
}
void Config::ReadValues() {
qt_config->beginGroup("Controls");
for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) {

View File

@ -3,9 +3,10 @@
// Refer to the license.txt file included.
#pragma once
#include <string>
#include <QVariant>
#include "core/settings.h"
#include <QVariant>
class QSettings;
@ -13,6 +14,8 @@ class Config {
QSettings* qt_config;
std::string qt_config_loc;
static const std::array<QVariant, Settings::NativeInput::NUM_INPUTS> defaults;
void ReadValues();
void SaveValues();
public:
@ -21,5 +24,5 @@ public:
void Reload();
void Save();
static const std::array<QVariant, Settings::NativeInput::NUM_INPUTS>& getDefaultInput();
};
extern const std::array<QVariant, Settings::NativeInput::NUM_INPUTS> defaults;

View File

@ -1,31 +1,31 @@
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "citra_qt/config.h"
#include "citra_qt/configure_dialog.h"
#include "ui_configure.h"
#include "core/settings.h"
ConfigureDialog::ConfigureDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ConfigureDialog)
{
ui->setupUi(this);
this->setConfiguration();
}
ConfigureDialog::~ConfigureDialog() {
}
void ConfigureDialog::setConfiguration() {
}
void ConfigureDialog::applyConfiguration() {
ui->generalTab->applyConfiguration();
ui->audioTab->applyConfiguration();
ui->debugTab->applyConfiguration();
ui->inputTab->applyConfiguration();
}
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "citra_qt/config.h"
#include "citra_qt/configure_dialog.h"
#include "ui_configure.h"
#include "core/settings.h"
ConfigureDialog::ConfigureDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ConfigureDialog)
{
ui->setupUi(this);
this->setConfiguration();
}
ConfigureDialog::~ConfigureDialog() {
}
void ConfigureDialog::setConfiguration() {
}
void ConfigureDialog::applyConfiguration() {
ui->generalTab->applyConfiguration();
ui->inputTab->applyConfiguration();
ui->audioTab->applyConfiguration();
ui->debugTab->applyConfiguration();
}

View File

@ -1,7 +1,10 @@
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "configure_input.h"
#include <utility>
#include "citra_qt/configure_input.h"
ConfigureInput::ConfigureInput(QWidget* parent) :
QWidget(parent),
@ -53,6 +56,7 @@ ConfigureInput::~ConfigureInput()
void ConfigureInput::handleClick()
{
QPushButton* sender = qobject_cast<QPushButton*>(QObject::sender());
previous_mapping = sender->text();
sender->setText(tr("[waiting]"));
sender->setFocus();
grabKeyboard();
@ -84,21 +88,7 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event)
{
if (changing_button != nullptr && event->key() != Qt::Key_unknown)
{
keys_pressed.push_back(event->key());
// Can't save Modifier + Keys yet as input. Will re-enable after settings refactor
/*if (event->key() == Qt::Key_Shift)
return;
else if (event->key() == Qt::Key_Control)
return;
else if (event->key() == Qt::Key_Alt)
return;
else if (event->key() == Qt::Key_Meta)
return;
else*/
key_pressed = event->key();
setKey();
}
}
@ -106,18 +96,17 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event)
/// Set button text to name of key pressed.
void ConfigureInput::setKey()
{
QString key_value = "";
for (int i : keys_pressed) // Will only contain one key until settings refactor
{
key_value += getKeyName(i);
}
// RemoveDuplicates(keyValue);
changing_button->setText(key_value);
QString key_value = getKeyName(key_pressed);
if (key_pressed == Qt::Key_Escape)
changing_button->setText(previous_mapping);
else
changing_button->setText(key_value);
keys_pressed.clear();
key_pressed = Qt::Key_unknown;
releaseKeyboard();
releaseMouse();
changing_button = nullptr;
previous_mapping = nullptr;
}
/// Convert key ASCII value to its' letter/name
@ -134,6 +123,7 @@ QString ConfigureInput::getKeyName(int key_code) const
if (key_code == Qt::Key_Meta)
return "";
if (key_code == -1)
return "";
@ -171,7 +161,7 @@ void ConfigureInput::removeDuplicates(const QString& newValue)
/// Restore all buttons to their default values.
void ConfigureInput::restoreDefaults() {
for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) {
QString keyValue = getKeyName(defaults[i].toInt());
QString keyValue = getKeyName(Config::getDefaultInput()[i].toInt());
input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue);
}
}

View File

@ -3,17 +3,17 @@
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <QWidget>
#include <QKeyEvent>
#include "citra_qt/config.h"
#include "core/settings.h"
#include "ui_configure_input.h"
class QObject;
class QPushButton;
class QString;
class QWidget;
namespace Ui {
class ConfigureInput;
@ -34,8 +34,9 @@ public:
private:
std::unique_ptr<Ui::ConfigureInput> ui;
std::map<Settings::NativeInput::Values, QPushButton*> input_mapping;
std::vector<int> keys_pressed;
int key_pressed;
QPushButton* changing_button = nullptr; /// button currently waiting for key press.
QString previous_mapping;
void setConfiguration();
void setKey();