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
14#include <mgba/internal/gba/input.h>
15
16class QComboBox;
17class QTimer;
18
19namespace QGBA {
20
21class InputController;
22class KeyEditor;
23
24class GBAKeyEditor : public QWidget {
25Q_OBJECT
26
27public:
28 GBAKeyEditor(InputController* controller, int type, const QString& profile = QString(), QWidget* parent = nullptr);
29 virtual ~GBAKeyEditor();
30
31public slots:
32 void setAll();
33 void save();
34
35protected:
36 virtual void resizeEvent(QResizeEvent*) override;
37 virtual void paintEvent(QPaintEvent*) override;
38 virtual bool event(QEvent*) override;
39 virtual void closeEvent(QCloseEvent*) override;
40 virtual bool eventFilter(QObject* obj, QEvent* event) override;
41
42private slots:
43 void setNext();
44 void refresh();
45#ifdef BUILD_SDL
46 void setAxisValue(int axis, int32_t value);
47 void selectGamepad(int index);
48 void updateJoysticks();
49#endif
50
51private:
52 static const qreal DPAD_CENTER_X;
53 static const qreal DPAD_CENTER_Y;
54 static const qreal DPAD_WIDTH;
55 static const qreal DPAD_HEIGHT;
56
57 void setLocation(QWidget* widget, qreal x, qreal y);
58
59 void lookupBinding(const mInputMap*, KeyEditor*, GBAKey);
60 void bindKey(const KeyEditor*, GBAKey);
61
62 bool findFocus(KeyEditor* needle = nullptr);
63
64#ifdef BUILD_SDL
65 void lookupAxes(const mInputMap*);
66 void lookupHats(const mInputMap*);
67#endif
68
69 KeyEditor* keyById(GBAKey);
70
71 QComboBox* m_profileSelect;
72 QWidget* m_clear;
73 QWidget* m_buttons;
74 KeyEditor* m_keyDU;
75 KeyEditor* m_keyDD;
76 KeyEditor* m_keyDL;
77 KeyEditor* m_keyDR;
78 KeyEditor* m_keySelect;
79 KeyEditor* m_keyStart;
80 KeyEditor* m_keyA;
81 KeyEditor* m_keyB;
82 KeyEditor* m_keyL;
83 KeyEditor* m_keyR;
84 QList<KeyEditor*> m_keyOrder;
85 QList<KeyEditor*>::iterator m_currentKey;
86
87 uint32_t m_type;
88 QString m_profile;
89 InputController* m_controller;
90
91 QPicture m_background;
92};
93
94}
95
96#endif