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#pragma once
7
8#include "GamepadAxisEvent.h"
9#include "GamepadHatEvent.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 GamepadHatEvent::Direction hatDirection() const { return m_hatDirection; }
28 int hat() const { return m_hat; }
29
30 virtual QSize sizeHint() const override;
31
32public slots:
33 void setValue(int key);
34 void setValueKey(int key);
35 void setValueButton(int button);
36 void setValueAxis(int axis, int32_t value);
37 void setValueHat(int hat, GamepadHatEvent::Direction value);
38 void clearButton();
39 void clearAxis();
40 void clearHat();
41
42signals:
43 void valueChanged(int key);
44 void axisChanged(int axis, int direction);
45 void hatChanged(int hat, int direction);
46
47protected:
48 virtual void keyPressEvent(QKeyEvent* event) override;
49 virtual bool event(QEvent* event) override;
50
51private:
52 static const int KEY_TIME = 2000;
53
54 void updateButtonText();
55
56 int m_key = -1;
57 int m_axis = -1;
58 int m_hat = -1;
59 bool m_button = false;
60 GamepadAxisEvent::Direction m_direction;
61 GamepadHatEvent::Direction m_hatDirection;
62 QTimer m_lastKey;
63};
64
65}