all repos — mgba @ f4a61f91d46b8a90a61ca0f9ef04f431f0a4fd9f

mGBA Game Boy Advance Emulator

src/platform/qt/KeyEditor.h (view raw)

 1/* Copyright (c) 2013-2014 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_KEY_EDITOR
 7#define QGBA_KEY_EDITOR
 8
 9#include "GamepadAxisEvent.h"
10#include "GamepadHatEvent.h"
11
12#include <QLineEdit>
13#include <QTimer>
14
15namespace QGBA {
16
17class KeyEditor : public QLineEdit {
18Q_OBJECT
19
20public:
21	KeyEditor(QWidget* parent = nullptr);
22
23	int value() const { return m_key; }
24
25	GamepadAxisEvent::Direction direction() const { return m_direction; }
26	int axis() const { return m_axis; }
27
28	GamepadHatEvent::Direction hatDirection() const { return m_hatDirection; }
29	int hat() const { return m_hat; }
30
31	virtual QSize sizeHint() const override;
32
33public slots:
34	void setValue(int key);
35	void setValueKey(int key);
36	void setValueButton(int button);
37	void setValueAxis(int axis, int32_t value);
38	void setValueHat(int hat, GamepadHatEvent::Direction value);
39	void clearButton();
40	void clearAxis();
41	void clearHat();
42
43signals:
44	void valueChanged(int key);
45	void axisChanged(int axis, int direction);
46	void hatChanged(int hat, int direction);
47
48protected:
49	virtual void keyPressEvent(QKeyEvent* event) override;
50	virtual bool event(QEvent* event) override;
51
52private:
53	static const int KEY_TIME = 2000;
54
55	void updateButtonText();
56
57	int m_key;
58	int m_axis;
59	int m_hat;
60	bool m_button;
61	GamepadAxisEvent::Direction m_direction;
62	GamepadHatEvent::Direction m_hatDirection;
63	QTimer m_lastKey;
64};
65
66}
67
68#endif