aboutsummaryrefslogtreecommitdiffstats
path: root/src/gamepad/qgamepadkeynavigation.h
blob: 03ea42221cd2b66f0f5a3bdec986a5f2b38e5892 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Gamepad module
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QGAMEPADKEYNAVIGATION_H
#define QGAMEPADKEYNAVIGATION_H

#include <QtCore/QObject>
#include <QtCore/QMap>
#include <QtGamepad/qtgamepadglobal.h>

#include <QtGamepad/QGamepadManager>

QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE

class QKeyEvent;
class QGamepad;
class Q_GAMEPAD_EXPORT QGamepadKeyNavigation : public QObject
{
    Q_OBJECT
    Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
    Q_PROPERTY(QGamepad *gamepad READ gamepad WRITE setGamepad NOTIFY gamepadChanged)
    Q_PROPERTY(Qt::Key upKey READ upKey WRITE setUpKey NOTIFY upKeyChanged)
    Q_PROPERTY(Qt::Key downKey READ downKey WRITE setDownKey NOTIFY downKeyChanged)
    Q_PROPERTY(Qt::Key leftKey READ leftKey WRITE setLeftKey NOTIFY leftKeyChanged)
    Q_PROPERTY(Qt::Key rightKey READ rightKey WRITE setRightKey NOTIFY rightKeyChanged)
    Q_PROPERTY(Qt::Key buttonAKey READ buttonAKey WRITE setButtonAKey NOTIFY buttonAKeyChanged)
    Q_PROPERTY(Qt::Key buttonBKey READ buttonBKey WRITE setButtonBKey NOTIFY buttonBKeyChanged)
    Q_PROPERTY(Qt::Key buttonXKey READ buttonXKey WRITE setButtonXKey NOTIFY buttonXKeyChanged)
    Q_PROPERTY(Qt::Key buttonYKey READ buttonYKey WRITE setButtonYKey NOTIFY buttonYKeyChanged)
    Q_PROPERTY(Qt::Key buttonSelectKey READ buttonSelectKey WRITE setButtonSelectKey NOTIFY buttonSelectKeyChanged)
    Q_PROPERTY(Qt::Key buttonStartKey READ buttonStartKey WRITE setButtonStartKey NOTIFY buttonStartKeyChanged)
    Q_PROPERTY(Qt::Key buttonGuideKey READ buttonGuideKey WRITE setButtonGuideKey NOTIFY buttonGuideKeyChanged)
    Q_PROPERTY(Qt::Key buttonL1Key READ buttonL1Key WRITE setButtonL1Key NOTIFY buttonL1KeyChanged)
    Q_PROPERTY(Qt::Key buttonR1Key READ buttonR1Key WRITE setButtonR1Key NOTIFY buttonR1KeyChanged)
    Q_PROPERTY(Qt::Key buttonL2Key READ buttonL2Key WRITE setButtonL2Key NOTIFY buttonL2KeyChanged)
    Q_PROPERTY(Qt::Key buttonR2Key READ buttonR2Key WRITE setButtonR2Key NOTIFY buttonR2KeyChanged)
    Q_PROPERTY(Qt::Key buttonL3Key READ buttonL3Key WRITE setButtonL3Key NOTIFY buttonL3KeyChanged)
    Q_PROPERTY(Qt::Key buttonR3Key READ buttonR3Key WRITE setButtonR3Key NOTIFY buttonR3KeyChanged)
public:
    explicit QGamepadKeyNavigation(QObject *parent = 0);

    bool active() const;
    QGamepad *gamepad() const;

    Qt::Key upKey() const;
    Qt::Key downKey() const;
    Qt::Key leftKey() const;
    Qt::Key rightKey() const;
    Qt::Key buttonAKey() const;
    Qt::Key buttonBKey() const;
    Qt::Key buttonXKey() const;
    Qt::Key buttonYKey() const;
    Qt::Key buttonSelectKey() const;
    Qt::Key buttonStartKey() const;
    Qt::Key buttonGuideKey() const;
    Qt::Key buttonL1Key() const;
    Qt::Key buttonR1Key() const;
    Qt::Key buttonL2Key() const;
    Qt::Key buttonR2Key() const;
    Qt::Key buttonL3Key() const;
    Qt::Key buttonR3Key() const;

signals:
    void activeChanged(bool isActive);
    void gamepadChanged(QGamepad *gamepad);

    void upKeyChanged(Qt::Key key);
    void downKeyChanged(Qt::Key key);
    void leftKeyChanged(Qt::Key key);
    void rightKeyChanged(Qt::Key key);
    void buttonAKeyChanged(Qt::Key key);
    void buttonBKeyChanged(Qt::Key key);
    void buttonXKeyChanged(Qt::Key key);
    void buttonYKeyChanged(Qt::Key key);
    void buttonSelectKeyChanged(Qt::Key key);
    void buttonStartKeyChanged(Qt::Key key);
    void buttonGuideKeyChanged(Qt::Key key);
    void buttonL1KeyChanged(Qt::Key key);
    void buttonR1KeyChanged(Qt::Key key);
    void buttonL2KeyChanged(Qt::Key key);
    void buttonR2KeyChanged(Qt::Key key);
    void buttonL3KeyChanged(Qt::Key key);
    void buttonR3KeyChanged(Qt::Key key);

public slots:
    void setActive(bool isActive);
    void setGamepad(QGamepad *gamepad);

    void setUpKey(Qt::Key key);
    void setDownKey(Qt::Key key);
    void setLeftKey(Qt::Key key);
    void setRightKey(Qt::Key key);
    void setButtonAKey(Qt::Key key);
    void setButtonBKey(Qt::Key key);
    void setButtonXKey(Qt::Key key);
    void setButtonYKey(Qt::Key key);
    void setButtonSelectKey(Qt::Key key);
    void setButtonStartKey(Qt::Key key);
    void setButtonGuideKey(Qt::Key key);
    void setButtonL1Key(Qt::Key key);
    void setButtonR1Key(Qt::Key key);
    void setButtonL2Key(Qt::Key key);
    void setButtonR2Key(Qt::Key key);
    void setButtonL3Key(Qt::Key key);
    void setButtonR3Key(Qt::Key key);

private slots:
    void processGamepadButtonPressEvent(int index, QGamepadManager::GamepadButton button, double value);
    void procressGamepadButtonReleaseEvent(int index, QGamepadManager::GamepadButton button);

private:
    void sendGeneratedKeyEvent(QKeyEvent *event);

    bool m_active;
    QGamepad *m_gamepad;
    QGamepadManager *m_gamepadManger;
    bool m_buttonL2Pressed;
    bool m_buttonR2Pressed;
    QMap<QGamepadManager::GamepadButton, Qt::Key> m_keyMapping;
};

QT_END_NAMESPACE
QT_END_HEADER

#endif // QGAMEPADKEYNAVIGATION_H