-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputview.cpp
65 lines (57 loc) · 1.88 KB
/
inputview.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
#include "inputview.h"
#include "ui_inputview.h"
#include "inputcontext.h"
#include <QKeyEvent>
#include <QDebug>
InputView::InputView(InputContext *inputContext, QWidget *parent)
: QWidget(parent)
, ui(new Ui::InputView)
, m_inputContext(inputContext)
, m_focusItem(NULL)
{
ui->setupUi(this);
Q_ASSERT(m_inputContext != NULL);
//setWindowModality(Qt::WindowModal);
setWindowFlags(/*windowFlags() |*/ Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus);
connect(ui->btn1, &QPushButton::clicked, [&](){
qDebug() << "btn1 click!";
normalBtn_onClick(ui->btn1);
});
connect(ui->btn2, &QPushButton::clicked, [&](){
normalBtn_onClick(ui->btn2);
});
connect(ui->backspaceBtn, &QPushButton::clicked, [&](){
sendKeyToFocusItem("\x7F");
});
connect(ui->hideBtn, &QPushButton::clicked, [&](){
m_inputContext->hideInputPanel();
});
}
InputView::~InputView()
{
delete ui;
}
void InputView::normalBtn_onClick(QPushButton* btn)
{
sendKeyToFocusItem(btn->text());
}
void InputView::setFocusItem(QObject* focusItem)
{
m_focusItem = focusItem;
}
void InputView::sendKeyToFocusItem(const QString& text)
{
qDebug() << "focusItem:" << m_focusItem;
if(!m_focusItem)
return;
if(text == QString("\x7F")) //backspace
{
QCoreApplication::sendEvent(m_focusItem, new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier));
QCoreApplication::sendEvent(m_focusItem, new QKeyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier));
}
else
{
QCoreApplication::sendEvent(m_focusItem, new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier, text));
QCoreApplication::sendEvent(m_focusItem, new QKeyEvent(QEvent::KeyRelease, 0, Qt::NoModifier, text));
}
}