Repository navigation
Expand file tree
/
Copy pathdigitalinputpanelcontext.cpp
More file actions
142 lines (112 loc) · 2.88 KB
/
Copy pathdigitalinputpanelcontext.cpp
File metadata and controls
142 lines (112 loc) · 2.88 KB
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
#include "digitalinputpanelcontext.h"
#include <QtCore>
#include "util.h"
//! [0]
DigitalInputPanelContext::DigitalInputPanelContext()
{
inputPanel = new DigitalInputPanel;
fullPanel = new FullInputPanel;
connect(inputPanel, SIGNAL(characterGenerated(QChar)), SLOT(sendCharacter(QChar)));
connect(fullPanel, SIGNAL(fullcharacterGenerated(QChar)), SLOT(sendCharacter(QChar)));
inputPanel->hide();
fullPanel->hide();
fullPanel->move(110,280);
inputPanel->move(90,500);
}
//! [0]
DigitalInputPanelContext::~DigitalInputPanelContext()
{
delete inputPanel;
}
//! [1]
bool DigitalInputPanelContext::filterEvent(const QEvent* event)
{
//qDebug("event %d",event->type());
// if (event->type() == QEvent::MouseButtonRelease ) {
// //updatePosition();
// inputPanel->show();
// inputPanel->move(25,480);
// qDebug("event %d",event->type());
// return true;
// } else if (event->type() == QEvent::CloseSoftwareInputPanel) {
// inputPanel->hide();
// return true;
// }
return false;
}
//! [1]
QString DigitalInputPanelContext::identifierName()
{
return "MyInputPanelContext";
}
void DigitalInputPanelContext::reset()
{
}
bool DigitalInputPanelContext::isComposing() const
{
return false;
}
QString DigitalInputPanelContext::language()
{
return "en_US";
}
//! [2]
void DigitalInputPanelContext::sendCharacter(QChar character)
{
QPointer<QWidget> w = focusWidget();
Util::SysLogD("press %d\n",character);
if(character == 35)
{
if (!w)
return;
QKeyEvent keyPress(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
QApplication::sendEvent(w, &keyPress);
}else
{
if (!w)
return;
QKeyEvent keyPress(QEvent::KeyPress, character.unicode(), Qt::NoModifier, QString(character));
QApplication::sendEvent(w, &keyPress);
if (!w)
return;
QKeyEvent keyRelease(QEvent::KeyPress, character.unicode(), Qt::NoModifier, QString());
QApplication::sendEvent(w, &keyRelease);
}
}
void DigitalInputPanelContext::panelChange(int flag)
{
if(flag == 1)
{
inputPanel->show();
fullPanel->hide();
}else if(flag == 2)
{
fullPanel->show();
inputPanel->hide();
}else if(flag == 3)
{
fullPanel->hide();
inputPanel->hide();
}
}
void DigitalInputPanelContext::updatePosition()
{
QWidget *widget = focusWidget();
if (!widget)
return;
QRect widgetRect = widget->rect();
QPoint panelPos = QPoint(widgetRect.left(), widgetRect.bottom() + 2);
panelPos = widget->mapToGlobal(panelPos);
inputPanel->move(panelPos);
}
void DigitalInputPanelContext::hideWidget(bool flag)
{
if(flag){
fullPanel->hide();
inputPanel->hide();
}else{
inputPanel->show();
fullPanel->hide();
}
}
//! [3]