keyboardwidget.cpp
6.82 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
#include <QKeyEvent>
#include <QDebug>
#include "keyboardwidget.h"
#include "ui_keyboardwidget.h"
#include "soundplayer.h"
KeyboardWidget::KeyboardWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::KeyboardWidget)
{
ui->setupUi(this);
m_pSignalMapper = new QSignalMapper(this);
m_pSignalMapper->setMapping(ui->pushButton_1, tr("1"));
m_pSignalMapper->setMapping(ui->pushButton_2, tr("2"));
m_pSignalMapper->setMapping(ui->pushButton_3, tr("3"));
m_pSignalMapper->setMapping(ui->pushButton_4, tr("4"));
m_pSignalMapper->setMapping(ui->pushButton_5, tr("5"));
m_pSignalMapper->setMapping(ui->pushButton_6, tr("6"));
m_pSignalMapper->setMapping(ui->pushButton_7, tr("7"));
m_pSignalMapper->setMapping(ui->pushButton_8, tr("8"));
m_pSignalMapper->setMapping(ui->pushButton_9, tr("9"));
m_pSignalMapper->setMapping(ui->pushButton_10, tr("0"));
m_pSignalMapper->setMapping(ui->pushButton_11, tr("Q"));
m_pSignalMapper->setMapping(ui->pushButton_12, tr("W"));
m_pSignalMapper->setMapping(ui->pushButton_13, tr("E"));
m_pSignalMapper->setMapping(ui->pushButton_14, tr("R"));
m_pSignalMapper->setMapping(ui->pushButton_15, tr("T"));
m_pSignalMapper->setMapping(ui->pushButton_16, tr("Y"));
m_pSignalMapper->setMapping(ui->pushButton_17, tr("U"));
m_pSignalMapper->setMapping(ui->pushButton_18, tr("I"));
m_pSignalMapper->setMapping(ui->pushButton_19, tr("O"));
m_pSignalMapper->setMapping(ui->pushButton_20, tr("P"));
m_pSignalMapper->setMapping(ui->pushButton_21, tr("A"));
m_pSignalMapper->setMapping(ui->pushButton_22, tr("S"));
m_pSignalMapper->setMapping(ui->pushButton_23, tr("D"));
m_pSignalMapper->setMapping(ui->pushButton_24, tr("F"));
m_pSignalMapper->setMapping(ui->pushButton_25, tr("G"));
m_pSignalMapper->setMapping(ui->pushButton_26, tr("H"));
m_pSignalMapper->setMapping(ui->pushButton_27, tr("J"));
m_pSignalMapper->setMapping(ui->pushButton_28, tr("K"));
m_pSignalMapper->setMapping(ui->pushButton_29, tr("L"));
m_pSignalMapper->setMapping(ui->pushButton_30, tr("Z"));
m_pSignalMapper->setMapping(ui->pushButton_31, tr("X"));
m_pSignalMapper->setMapping(ui->pushButton_32, tr("C"));
m_pSignalMapper->setMapping(ui->pushButton_33, tr("V"));
m_pSignalMapper->setMapping(ui->pushButton_34, tr("B"));
m_pSignalMapper->setMapping(ui->pushButton_35, tr("N"));
m_pSignalMapper->setMapping(ui->pushButton_36, tr("M"));
m_pSignalMapper->setMapping(ui->pushButton_37, tr("-"));
m_pSignalMapper->setMapping(ui->pushButton_38, tr(","));
m_pSignalMapper->setMapping(ui->pushButton_40, tr(" "));
connect(ui->pushButton_1,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_2,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_3,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_4,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_5,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_6,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_7,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_8,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_9,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_10,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_11,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_12,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_13,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_14,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_15,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_16,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_17,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_18,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_19,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_20,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_21,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_22,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_23,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_24,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_25,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_26,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_27,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_28,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_29,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_30,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_31,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_32,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_33,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_34,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_35,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_36,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_37,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_38,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(ui->pushButton_40,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
connect(m_pSignalMapper,SIGNAL(mapped(QString)), this, SLOT(onKeyboardClicked(QString)));
foreach (QPushButton *button, findChildren<QPushButton *>())
connect(button, &QPushButton::pressed, SoundPlayer::playClick);
}
KeyboardWidget::~KeyboardWidget()
{
delete ui;
}
void KeyboardWidget::on_pushButton_41_clicked()
{
QKeyEvent key(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
QGuiApplication::sendEvent(QApplication::focusObject(),&key);
emit onOkKeyClicked();
}
void KeyboardWidget::on_pushButton_42_clicked()
{
emit onCancelKeyClicked();
}
void KeyboardWidget::on_pushButton_39_clicked()
{
QKeyEvent key(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
QGuiApplication::sendEvent(QApplication::focusObject(),&key);
emit onBackspaceKeyClicked();
}
void KeyboardWidget::onKeyboardClicked(const QString in){
QInputMethodEvent event;
event.setCommitString(in);
QGuiApplication::sendEvent(QApplication::focusObject(),&event);
emit onKeyboardClickSignal(in);
}
void KeyboardWidget::on_pushButton_40_clicked()
{
emit onSpaceKeyClicked();
}