all repos — mgba @ 67905d281bfecbb06f51f2ca5ac939df378734a5

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
11#include <QLineEdit>
12#include <QTimer>
13
14namespace QGBA {
15
16class KeyEditor : public QLineEdit {
17Q_OBJECT
18
19public:
20	KeyEditor(QWidget* parent = nullptr);
21
22	int value() const { return m_key; }
23
24	GamepadAxisEvent::Direction direction() const { return m_direction; }
25	int axis() const { return m_axis; }
26
27	virtual QSize sizeHint() const override;
28
29public slots:
30	void setValue(int key);
31	void setValueKey(int key);
32	void setValueButton(int button);
33	void setValueAxis(int axis, int32_t value);
34	void clearButton();
35	void clearAxis();
36
37signals:
38	void valueChanged(int key);
39	void axisChanged(int key, int direction);
40
41protected:
42	virtual void keyPressEvent(QKeyEvent* event) override;
43	virtual bool event(QEvent* event) override;
44
45private:
46	static const int KEY_TIME = 2000;
47
48	void updateButtonText();
49
50	int m_key;
51	int m_axis;
52	bool m_button;
53	GamepadAxisEvent::Direction m_direction;
54	QTimer m_lastKey;
55};
56
57}
58
59#endif