summaryrefslogtreecommitdiffstats
path: root/src/citra_qt/configure_input.h
blob: fe8ea5580251fdf34041049a2951a2f4dac65407 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <QWidget>
#include <QKeyEvent>

#include "citra_qt/config.h"
#include "core/settings.h"
#include "ui_configure_input.h"

class QPushButton;
class QString;
class QTimer;

namespace Ui {
    class ConfigureInput;
}

class ConfigureInput : public QWidget {
    Q_OBJECT

public:
    explicit ConfigureInput(QWidget* parent = nullptr);

    /// Save all button configurations to settings file
    void applyConfiguration();

private:
    std::unique_ptr<Ui::ConfigureInput> ui;
    std::map<Settings::NativeInput::Values, QPushButton*> input_mapping;
    int key_pressed;
    QPushButton* changing_button = nullptr; ///< button currently waiting for key press.
    QString previous_mapping;
    QTimer* timer;

    /// Load configuration settings into button text
    void setConfiguration();

    /// Check all inputs for duplicate keys. Clears out any other button with the same value as this button's new value.
    void removeDuplicates(const QString& newValue);

    /// Handle key press event for input tab when a button is 'waiting'.
    void keyPressEvent(QKeyEvent* event) override;

    /// Convert key ASCII value to its' letter/name
    QString getKeyName(int key_code) const;

    /// Convert letter/name of key to its ASCII value.
    Qt::Key getKeyValue(const QString& text) const;

    /// Set button text to name of key pressed.
    void setKey();

private slots:
    /// Event handler for all button released() event.
    void handleClick();

    /// Restore all buttons to their default values.
    void restoreDefaults();
};