mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-25 12:30:15 +00:00
Input-GUI: Fix most PR issues
This commit is contained in:
parent
523ca1841f
commit
3740f03ef9
@ -2,7 +2,7 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
#include "citra_qt/config.h"
|
||||
#include "citra_qt/ui_settings.h"
|
||||
@ -49,9 +49,9 @@ void Config::ReadValues() {
|
||||
Settings::values.use_shader_jit = qt_config->value("use_shader_jit", true).toBool();
|
||||
Settings::values.use_scaled_resolution = qt_config->value("use_scaled_resolution", false).toBool();
|
||||
|
||||
Settings::values.bg_red = qt_config->value("bg_red", 1.0).toFloat();
|
||||
Settings::values.bg_red = qt_config->value("bg_red", 1.0).toFloat();
|
||||
Settings::values.bg_green = qt_config->value("bg_green", 1.0).toFloat();
|
||||
Settings::values.bg_blue = qt_config->value("bg_blue", 1.0).toFloat();
|
||||
Settings::values.bg_blue = qt_config->value("bg_blue", 1.0).toFloat();
|
||||
qt_config->endGroup();
|
||||
|
||||
qt_config->beginGroup("Audio");
|
||||
@ -104,9 +104,9 @@ void Config::ReadValues() {
|
||||
for (auto hotkey : hotkeys) {
|
||||
qt_config->beginGroup(hotkey);
|
||||
UISettings::values.shortcuts.emplace_back(
|
||||
UISettings::Shortcut(group + "/" + hotkey,
|
||||
UISettings::ContextualShortcut(qt_config->value("KeySeq").toString(),
|
||||
qt_config->value("Context").toInt())));
|
||||
UISettings::Shortcut(group + "/" + hotkey,
|
||||
UISettings::ContextualShortcut(qt_config->value("KeySeq").toString(),
|
||||
qt_config->value("Context").toInt())));
|
||||
qt_config->endGroup();
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ void Config::ReadValues() {
|
||||
|
||||
UISettings::values.single_window_mode = qt_config->value("singleWindowMode", true).toBool();
|
||||
UISettings::values.display_titlebar = qt_config->value("displayTitleBars", true).toBool();
|
||||
UISettings::values.confirm_before_closing = qt_config->value("confirmClose",true).toBool();
|
||||
UISettings::values.confirm_before_closing = qt_config->value("confirmClose", true).toBool();
|
||||
UISettings::values.first_start = qt_config->value("firstStart", true).toBool();
|
||||
|
||||
qt_config->endGroup();
|
||||
@ -141,9 +141,9 @@ void Config::SaveValues() {
|
||||
qt_config->setValue("use_scaled_resolution", Settings::values.use_scaled_resolution);
|
||||
|
||||
// Cast to double because Qt's written float values are not human-readable
|
||||
qt_config->setValue("bg_red", (double)Settings::values.bg_red);
|
||||
qt_config->setValue("bg_red", (double)Settings::values.bg_red);
|
||||
qt_config->setValue("bg_green", (double)Settings::values.bg_green);
|
||||
qt_config->setValue("bg_blue", (double)Settings::values.bg_blue);
|
||||
qt_config->setValue("bg_blue", (double)Settings::values.bg_blue);
|
||||
qt_config->endGroup();
|
||||
|
||||
qt_config->beginGroup("Audio");
|
||||
@ -188,7 +188,7 @@ void Config::SaveValues() {
|
||||
qt_config->endGroup();
|
||||
|
||||
qt_config->beginGroup("Shortcuts");
|
||||
for (auto shortcut : UISettings::values.shortcuts ) {
|
||||
for (auto shortcut : UISettings::values.shortcuts) {
|
||||
qt_config->setValue(shortcut.first + "/KeySeq", shortcut.second.first);
|
||||
qt_config->setValue(shortcut.first + "/Context", shortcut.second.second);
|
||||
}
|
||||
|
@ -4,11 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "core/settings.h"
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
class QSettings;
|
||||
|
||||
|
@ -3,13 +3,13 @@
|
||||
// Refer to the license.txt file included.
|
||||
#include "configure_input.h"
|
||||
|
||||
ConfigureInput::ConfigureInput(QWidget *parent) :
|
||||
ConfigureInput::ConfigureInput(QWidget* parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ConfigureInput)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
//Initialize mapping of input enum to UI button.
|
||||
// Initialize mapping of input enum to UI button.
|
||||
input_mapping = {
|
||||
{ std::make_pair(Settings::NativeInput::Values::A, ui->btnFaceA) },
|
||||
{ std::make_pair(Settings::NativeInput::Values::B, ui->btnFaceB) },
|
||||
@ -36,11 +36,11 @@ ConfigureInput::ConfigureInput(QWidget *parent) :
|
||||
{ std::make_pair(Settings::NativeInput::Values::CIRCLE_RIGHT, ui->btnCircleRight) },
|
||||
};
|
||||
|
||||
//Attach handle click method to each button click.
|
||||
for (auto &ent1 : input_mapping) {
|
||||
connect(ent1.second, &QPushButton::released, this, &ConfigureInput::HandleClick);
|
||||
// Attach handle click method to each button click.
|
||||
for (const auto& entry : input_mapping) {
|
||||
connect(entry.second, SIGNAL(released()), this, SLOT(handleClick()));
|
||||
}
|
||||
connect(ui->btnRestoreDefaults, &QPushButton::released, this, &ConfigureInput::RestoreDefaults);
|
||||
connect(ui->btnRestoreDefaults, SIGNAL(released()), this, SLOT(restoreDefaults()));
|
||||
setFocusPolicy(Qt::ClickFocus);
|
||||
this->setConfiguration();
|
||||
}
|
||||
@ -49,44 +49,44 @@ ConfigureInput::~ConfigureInput()
|
||||
{
|
||||
}
|
||||
|
||||
///Event handler for all button released() event.
|
||||
void ConfigureInput::HandleClick()
|
||||
/// Event handler for all button released() event.
|
||||
void ConfigureInput::handleClick()
|
||||
{
|
||||
QPushButton* sender = qobject_cast<QPushButton*>(QObject::sender());
|
||||
sender->setText("[waiting]");
|
||||
sender->setText(tr("[waiting]"));
|
||||
sender->setFocus();
|
||||
grabKeyboard();
|
||||
grabMouse();
|
||||
changingButton = sender;
|
||||
changing_button = sender;
|
||||
}
|
||||
|
||||
///Save all button configurations to settings file
|
||||
/// Save all button configurations to settings file
|
||||
void ConfigureInput::applyConfiguration()
|
||||
{
|
||||
for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) {
|
||||
int value = GetKeyValue(input_mapping[Settings::NativeInput::Values(i)]->text());
|
||||
int value = getKeyValue(input_mapping[Settings::NativeInput::Values(i)]->text());
|
||||
Settings::values.input_mappings[Settings::NativeInput::All[i]] = value;
|
||||
}
|
||||
Settings::Apply();
|
||||
}
|
||||
|
||||
///Load configuration settings into button text
|
||||
/// Load configuration settings into button text
|
||||
void ConfigureInput::setConfiguration()
|
||||
{
|
||||
for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) {
|
||||
QString keyValue = GetKeyName(Settings::values.input_mappings[i]);
|
||||
QString keyValue = getKeyName(Settings::values.input_mappings[i]);
|
||||
input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue);
|
||||
}
|
||||
}
|
||||
|
||||
///Handle key press event for input tab when a button is 'waiting'.
|
||||
void ConfigureInput::keyPressEvent(QKeyEvent *event)
|
||||
/// Handle key press event for input tab when a button is 'waiting'.
|
||||
void ConfigureInput::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
if (changingButton != nullptr && event->key() > 0)
|
||||
if (changing_button != nullptr && event->key() != Qt::Key_unknown)
|
||||
{
|
||||
keysPressed.push_back(event->key());
|
||||
keys_pressed.push_back(event->key());
|
||||
|
||||
//Can't save Modifier + Keys yet as input. Will re-enable after settings refactor
|
||||
// Can't save Modifier + Keys yet as input. Will re-enable after settings refactor
|
||||
/*if (event->key() == Qt::Key_Shift)
|
||||
return;
|
||||
|
||||
@ -99,68 +99,68 @@ void ConfigureInput::keyPressEvent(QKeyEvent *event)
|
||||
else if (event->key() == Qt::Key_Meta)
|
||||
return;
|
||||
else*/
|
||||
SetKey();
|
||||
setKey();
|
||||
}
|
||||
}
|
||||
|
||||
///Set button text to name of key pressed.
|
||||
void ConfigureInput::SetKey()
|
||||
/// Set button text to name of key pressed.
|
||||
void ConfigureInput::setKey()
|
||||
{
|
||||
QString keyValue = "";
|
||||
for (int i : keysPressed) // Will only contain one key until settings refactor
|
||||
QString key_value = "";
|
||||
for (int i : keys_pressed) // Will only contain one key until settings refactor
|
||||
{
|
||||
keyValue += GetKeyName(i);
|
||||
key_value += getKeyName(i);
|
||||
}
|
||||
//RemoveDuplicates(keyValue);
|
||||
changingButton->setText(keyValue);
|
||||
// RemoveDuplicates(keyValue);
|
||||
changing_button->setText(key_value);
|
||||
|
||||
keysPressed.clear();
|
||||
keys_pressed.clear();
|
||||
releaseKeyboard();
|
||||
releaseMouse();
|
||||
changingButton = nullptr;
|
||||
changing_button = nullptr;
|
||||
}
|
||||
|
||||
///Convert key ASCII value to its' letter/name
|
||||
QString ConfigureInput::GetKeyName(int key_code)
|
||||
/// Convert key ASCII value to its' letter/name
|
||||
QString ConfigureInput::getKeyName(int key_code) const
|
||||
{
|
||||
if (key_code == Qt::Key_Shift)
|
||||
return tr("Shift");
|
||||
|
||||
else if (key_code == Qt::Key_Control)
|
||||
if (key_code == Qt::Key_Control)
|
||||
return tr("Ctrl");
|
||||
|
||||
else if (key_code == Qt::Key_Alt)
|
||||
if (key_code == Qt::Key_Alt)
|
||||
return tr("Alt");
|
||||
|
||||
else if (key_code == Qt::Key_Meta)
|
||||
if (key_code == Qt::Key_Meta)
|
||||
return "";
|
||||
else if (key_code == -1)
|
||||
if (key_code == -1)
|
||||
return "";
|
||||
|
||||
return QKeySequence(key_code).toString();
|
||||
}
|
||||
|
||||
///Convert letter/name of key to its ASCII value.
|
||||
int ConfigureInput::GetKeyValue(QString text)
|
||||
/// Convert letter/name of key to its ASCII value.
|
||||
Qt::Key ConfigureInput::getKeyValue(const QString& text) const
|
||||
{
|
||||
if (text == "Shift")
|
||||
return Qt::Key_Shift;
|
||||
else if (text == "Ctrl")
|
||||
if (text == "Ctrl")
|
||||
return Qt::Key_Control;
|
||||
else if (text == "Alt")
|
||||
if (text == "Alt")
|
||||
return Qt::Key_Alt;
|
||||
else if (text == "Meta")
|
||||
return -1;
|
||||
else if (text == "")
|
||||
return -1;
|
||||
return QKeySequence(text)[0];
|
||||
if (text == "Meta")
|
||||
return Qt::Key_unknown;
|
||||
if (text == "")
|
||||
return Qt::Key_unknown;
|
||||
return Qt::Key(QKeySequence(text)[0]);
|
||||
}
|
||||
|
||||
///Check all inputs for duplicate keys. Clears out any other button with same key as new button.
|
||||
void ConfigureInput::RemoveDuplicates(QString newValue)
|
||||
/// Check all inputs for duplicate keys. Clears out any other button with same key as new button.
|
||||
void ConfigureInput::removeDuplicates(const QString& newValue)
|
||||
{
|
||||
for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) {
|
||||
if (changingButton != input_mapping[Settings::NativeInput::Values(i)]) {
|
||||
if (changing_button != input_mapping[Settings::NativeInput::Values(i)]) {
|
||||
QString oldValue = input_mapping[Settings::NativeInput::Values(i)]->text();
|
||||
if (newValue == oldValue)
|
||||
input_mapping[Settings::NativeInput::Values(i)]->setText("");
|
||||
@ -168,11 +168,10 @@ void ConfigureInput::RemoveDuplicates(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());
|
||||
/// 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());
|
||||
input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue);
|
||||
}
|
||||
}
|
@ -1,20 +1,20 @@
|
||||
// Copyright 2016 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QObject>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
#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;
|
||||
}
|
||||
@ -24,22 +24,23 @@ class ConfigureInput : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfigureInput(QWidget *parent = 0);
|
||||
explicit ConfigureInput(QWidget* parent = nullptr);
|
||||
~ConfigureInput();
|
||||
void applyConfiguration();
|
||||
|
||||
public Q_SLOTS:
|
||||
void handleClick();
|
||||
void restoreDefaults();
|
||||
private:
|
||||
std::unique_ptr<Ui::ConfigureInput> ui;
|
||||
std::map<Settings::NativeInput::Values, QPushButton*> input_mapping;
|
||||
std::vector<int> keysPressed;
|
||||
QPushButton* changingButton = nullptr; /// button currently waiting for key press.
|
||||
std::vector<int> keys_pressed;
|
||||
QPushButton* changing_button = nullptr; /// button currently waiting for key press.
|
||||
|
||||
void HandleClick();
|
||||
void setConfiguration();
|
||||
void SetKey();
|
||||
void RemoveDuplicates(QString newValue);
|
||||
void RestoreDefaults();
|
||||
virtual void keyPressEvent(QKeyEvent *event);
|
||||
QString GetKeyName(int key_code);
|
||||
int GetKeyValue(QString text);
|
||||
void setKey();
|
||||
void removeDuplicates(const QString& newValue);
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
QString getKeyName(int key_code) const;
|
||||
Qt::Key ConfigureInput::getKeyValue(const QString& text) const;
|
||||
};
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user