aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/yuzu/configuration/configure_touch_from_button.h
blob: c926db0123b7b07b0252448f377cdfe060a0774c (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2020 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <functional>
#include <memory>
#include <optional>
#include <vector>
#include <QDialog>
#include "core/frontend/framebuffer_layout.h"
#include "core/settings.h"

class QItemSelection;
class QModelIndex;
class QStandardItemModel;
class QStandardItem;
class QTimer;

namespace Common {
class ParamPackage;
}

namespace InputCommon {
namespace Polling {
class DevicePoller;
}
} // namespace InputCommon

namespace Ui {
class ConfigureTouchFromButton;
}

class ConfigureTouchFromButton : public QDialog {
    Q_OBJECT

public:
    explicit ConfigureTouchFromButton(QWidget* parent,
                                      const std::vector<Settings::TouchFromButtonMap>& touch_maps,
                                      int default_index = 0);
    ~ConfigureTouchFromButton() override;

    int GetSelectedIndex() const;
    std::vector<Settings::TouchFromButtonMap> GetMaps() const;

public slots:
    void ApplyConfiguration();
    void NewBinding(const QPoint& pos);
    void SetActiveBinding(int dot_id);
    void SetCoordinates(int dot_id, const QPoint& pos);

protected:
    virtual void showEvent(QShowEvent* ev) override;
    virtual void keyPressEvent(QKeyEvent* event) override;

private slots:
    void NewMapping();
    void DeleteMapping();
    void RenameMapping();
    void EditBinding(const QModelIndex& qi);
    void DeleteBinding();
    void OnBindingSelection(const QItemSelection& selected, const QItemSelection& deselected);
    void OnBindingChanged(QStandardItem* item);
    void OnBindingDeleted(const QModelIndex& parent, int first, int last);

private:
    void SetConfiguration();
    void UpdateUiDisplay();
    void ConnectEvents();
    void GetButtonInput(int row_index, bool is_new);
    void SetPollingResult(const Common::ParamPackage& params, bool cancel);
    void SaveCurrentMapping();

    std::unique_ptr<Ui::ConfigureTouchFromButton> ui;
    std::unique_ptr<QStandardItemModel> binding_list_model;
    std::vector<Settings::TouchFromButtonMap> touch_maps;
    int selected_index;

    std::unique_ptr<QTimer> timeout_timer;
    std::unique_ptr<QTimer> poll_timer;
    std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers;
    std::optional<std::function<void(const Common::ParamPackage&, bool)>> input_setter;

    static constexpr int DataRoleDot = Qt::ItemDataRole::UserRole + 2;
};