src/platform/qt/GBAKeyEditor.h (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef QGBA_GBA_KEY_EDITOR
7#define QGBA_GBA_KEY_EDITOR
8
9#include <QList>
10#include <QPicture>
11#include <QSet>
12#include <QWidget>
13
14extern "C" {
15#include "gba/input.h"
16}
17
18class QComboBox;
19class QTimer;
20
21namespace QGBA {
22
23class InputController;
24class KeyEditor;
25
26class GBAKeyEditor : public QWidget {
27Q_OBJECT
28
29public:
30 GBAKeyEditor(InputController* controller, int type, const QString& profile = QString(), QWidget* parent = nullptr);
31 virtual ~GBAKeyEditor();
32
33public slots:
34 void setAll();
35 void save();
36
37protected:
38 virtual void resizeEvent(QResizeEvent*) override;
39 virtual void paintEvent(QPaintEvent*) override;
40 virtual bool event(QEvent*) override;
41 virtual void closeEvent(QCloseEvent*) override;
42 virtual bool eventFilter(QObject* obj, QEvent* event) override;
43
44private slots:
45 void setNext();
46 void refresh();
47#ifdef BUILD_SDL
48 void setAxisValue(int axis, int32_t value);
49 void selectGamepad(int index);
50 void updateJoysticks();
51#endif
52
53private:
54 static const qreal DPAD_CENTER_X;
55 static const qreal DPAD_CENTER_Y;
56 static const qreal DPAD_WIDTH;
57 static const qreal DPAD_HEIGHT;
58
59 void setLocation(QWidget* widget, qreal x, qreal y);
60
61 void lookupBinding(const mInputMap*, KeyEditor*, GBAKey);
62 void bindKey(const KeyEditor*, GBAKey);
63
64 bool findFocus(KeyEditor* needle = nullptr);
65
66#ifdef BUILD_SDL
67 void lookupAxes(const mInputMap*);
68#endif
69
70 KeyEditor* keyById(GBAKey);
71
72 QComboBox* m_profileSelect;
73 QWidget* m_clear;
74 QWidget* m_buttons;
75 KeyEditor* m_keyDU;
76 KeyEditor* m_keyDD;
77 KeyEditor* m_keyDL;
78 KeyEditor* m_keyDR;
79 KeyEditor* m_keySelect;
80 KeyEditor* m_keyStart;
81 KeyEditor* m_keyA;
82 KeyEditor* m_keyB;
83 KeyEditor* m_keyL;
84 KeyEditor* m_keyR;
85 QList<KeyEditor*> m_keyOrder;
86 QList<KeyEditor*>::iterator m_currentKey;
87
88 uint32_t m_type;
89 QString m_profile;
90 InputController* m_controller;
91
92 QPicture m_background;
93};
94
95}
96
97#endif