forked from nspire-emus/firebird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtkeypadbridge.cpp
125 lines (111 loc) · 3.55 KB
/
qtkeypadbridge.cpp
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
#include "qtkeypadbridge.h"
#include "keymap.h"
#include "core/keypad.h"
#include "qmlbridge.h"
QtKeypadBridge qt_keypad_bridge;
void QtKeypadBridge::keyPressEvent(QKeyEvent *event)
{
Qt::Key key = static_cast<Qt::Key>(event->key());
switch(key)
{
case Qt::Key_Down:
touchpad_x = TOUCHPAD_X_MAX / 2;
touchpad_y = 0;
break;
case Qt::Key_Up:
touchpad_x = TOUCHPAD_X_MAX / 2;
touchpad_y = TOUCHPAD_Y_MAX;
break;
case Qt::Key_Left:
touchpad_y = TOUCHPAD_Y_MAX / 2;
touchpad_x = 0;
break;
case Qt::Key_Right:
touchpad_y = TOUCHPAD_Y_MAX / 2;
touchpad_x = TOUCHPAD_X_MAX;
break;
case Qt::Key_Return:
key = Qt::Key_Enter;
default:
auto& keymap = keymap_tp;
for(unsigned int row = 0; row < sizeof(keymap)/sizeof(*keymap); ++row)
{
for(unsigned int col = 0; col < sizeof(*keymap)/sizeof(**keymap); ++col)
{
if(key == keymap[row][col].key && keymap[row][col].alt == (bool(event->modifiers() & Qt::AltModifier) || bool(event->modifiers() & Qt::MetaModifier)))
{
if(row == 0 && col == 9)
keypad_on_pressed();
key_map[row] |= 1 << col;
notifyKeypadStateChanged(row, col, true);
keypad_int_check();
return;
}
}
}
return;
}
touchpad_contact = touchpad_down = true;
notifyTouchpadStateChanged();
kpc.gpio_int_active |= 0x800;
keypad_int_check();
}
void QtKeypadBridge::keyReleaseEvent(QKeyEvent *event)
{
Qt::Key key = static_cast<Qt::Key>(event->key());
switch(key)
{
case Qt::Key_Down:
if(touchpad_x == TOUCHPAD_X_MAX / 2
&& touchpad_y == 0)
touchpad_contact = touchpad_down = false;
break;
case Qt::Key_Up:
if(touchpad_x == TOUCHPAD_X_MAX / 2
&& touchpad_y == TOUCHPAD_Y_MAX)
touchpad_contact = touchpad_down = false;
break;
case Qt::Key_Left:
if(touchpad_y == TOUCHPAD_Y_MAX / 2
&& touchpad_x == 0)
touchpad_contact = touchpad_down = false;
break;
case Qt::Key_Right:
if(touchpad_y == TOUCHPAD_Y_MAX / 2
&& touchpad_x == TOUCHPAD_X_MAX)
touchpad_contact = touchpad_down = false;
break;
case Qt::Key_Return:
key = Qt::Key_Enter;
default:
auto& keymap = keymap_tp;
for(unsigned int row = 0; row < sizeof(keymap)/sizeof(*keymap); ++row)
{
for(unsigned int col = 0; col < sizeof(*keymap)/sizeof(**keymap); ++col)
{
if(key == keymap[row][col].key && keymap[row][col].alt == (bool(event->modifiers() & Qt::AltModifier) || bool(event->modifiers() & Qt::MetaModifier)))
{
key_map[row] &= ~(1 << col);
notifyKeypadStateChanged(row, col, false);
keypad_int_check();
return;
}
}
}
return;
}
notifyTouchpadStateChanged();
kpc.gpio_int_active |= 0x800;
keypad_int_check();
}
bool QtKeypadBridge::eventFilter(QObject *obj, QEvent *event)
{
Q_UNUSED(obj);
if(event->type() == QEvent::KeyPress)
keyPressEvent(static_cast<QKeyEvent*>(event));
else if(event->type() == QEvent::KeyRelease)
keyReleaseEvent(static_cast<QKeyEvent*>(event));
else
return false;
return true;
}