11 #include <QGridLayout> 12 #include <QSignalMapper> 13 #include <QPushButton> 16 #define NEXT_ROW_MARKER 0 28 { Qt::Key_1,
"1", Qt::Key_Ampersand,
"&" },
29 { Qt::Key_2,
"2", Qt::Key_Eacute,
"é" },
30 { Qt::Key_3,
"3", Qt::Key_QuoteDbl,
"\"" },
31 { Qt::Key_4,
"4", Qt::Key_Apostrophe,
"'" },
32 { Qt::Key_5,
"5", Qt::Key_ParenRight,
"(" },
33 { Qt::Key_6,
"6", Qt::Key_hyphen,
"-" },
34 { Qt::Key_7,
"7", Qt::Key_Egrave,
"è" },
35 { Qt::Key_8,
"8", Qt::Key_Underscore,
"_" },
36 { Qt::Key_9,
"9", Qt::Key_cedilla,
"ç" },
37 { Qt::Key_0,
"0", Qt::Key_Agrave,
"à" },
38 { Qt::Key_Percent,
"%", Qt::Key_ParenLeft,
")" },
39 { Qt::Key_Plus,
"+", Qt::Key_Equal,
"=" },
40 { Qt::Key_Backspace,
"<-", Qt::Key_Backspace,
"<-"},
42 { Qt::Key_A,
"a", Qt::Key_A,
"A" },
43 { Qt::Key_Z,
"z", Qt::Key_Z,
"Z" },
44 { Qt::Key_E,
"e", Qt::Key_E,
"E" },
45 { Qt::Key_R,
"r", Qt::Key_R,
"R" },
46 { Qt::Key_T,
"t", Qt::Key_T,
"T" },
47 { Qt::Key_Y,
"y", Qt::Key_Y,
"Y" },
48 { Qt::Key_U,
"u", Qt::Key_U,
"U" },
49 { Qt::Key_I,
"i", Qt::Key_I,
"I" },
50 { Qt::Key_O,
"o", Qt::Key_O,
"O" },
51 { Qt::Key_P,
"p", Qt::Key_P,
"P" },
52 { Qt::Key_At,
"@", Qt::Key_Dollar,
"$" },
53 { Qt::Key_Escape,
"Esc", Qt::Key_Escape,
"Esc" },
54 { Qt::Key_Delete,
"X", Qt::Key_Delete,
"X"},
56 { Qt::Key_Q,
"q", Qt::Key_Q,
"Q" },
57 { Qt::Key_S,
"s", Qt::Key_S,
"S" },
58 { Qt::Key_D,
"d", Qt::Key_D,
"D" },
59 { Qt::Key_F,
"f", Qt::Key_F,
"F" },
60 { Qt::Key_G,
"g", Qt::Key_G,
"G" },
61 { Qt::Key_H,
"h", Qt::Key_H,
"H" },
62 { Qt::Key_J,
"j", Qt::Key_J,
"J" },
63 { Qt::Key_K,
"k", Qt::Key_K,
"K" },
64 { Qt::Key_L,
"l", Qt::Key_L,
"L" },
65 { Qt::Key_M,
"m", Qt::Key_M,
"M" },
66 { Qt::Key_Ooblique,
"/", Qt::Key_Backslash,
"\\" },
67 { Qt::Key_multiply,
"*", Qt::Key_ssharp,
"#" },
68 { Qt::Key_Space,
" ", Qt::Key_Space,
" " },
70 { Qt::Key_CapsLock,
"Maj", Qt::Key_CapsLock,
"Maj" },
71 { Qt::Key_Less,
"<", Qt::Key_Greater,
">" },
72 { Qt::Key_W,
"w", Qt::Key_W,
"W"},
73 { Qt::Key_X,
"x", Qt::Key_X,
"X"},
74 { Qt::Key_C,
"c", Qt::Key_C,
"C"},
75 { Qt::Key_V,
"v", Qt::Key_V,
"V"},
76 { Qt::Key_B,
"b", Qt::Key_B,
"B"},
77 { Qt::Key_N,
"n", Qt::Key_N,
"N"},
78 { Qt::Key_Comma,
",", Qt::Key_Question,
"?"},
79 { Qt::Key_Semicolon,
";", Qt::Key_Period,
"."},
80 { Qt::Key_Colon,
":", Qt::Key_AsciiTilde,
"~"},
81 { Qt::Key_exclamdown,
"!", Qt::Key_section,
"§"},
82 { Qt::Key_Enter,
"Entrée", Qt::Key_Enter,
"Entrée"}
87 #ifdef KEYBOARD_SINGLETON 88 Keyboard* Keyboard::instance = Q_NULLPTR;
92 if(instance == Q_NULLPTR)
94 instance =
new Keyboard(lineEdit, parent);
102 #ifdef DEBUG_KEYBOARD 103 qDebug() << Q_FUNC_INFO <<
this <<
lineEdit;
109 setStyleSheet(
"/*QWidget{background-color:white;}*/QPushButton{font-family:\"Ubuntu Mono\";font:bold;font-size:16px;background-color:palegoldenrod;border-width:1px;border-color:darkkhaki;border-style:solid;border-radius:5;padding:1px;}QPushButton:hover{background-color:khaki;}QPushButton:pressed{background-color:#d0d67c;}");
110 setAttribute(Qt::WA_TranslucentBackground,
true);
115 QPainter painter(
this);
117 pen.setBrush(QBrush(QColor(128, 128, 128, 64)));
119 painter.drawRoundedRect(0,0,width()-1, height()-1,5,5);
120 QWidget::paintEvent(e);
125 if(lineEdit && this->lineEdit != lineEdit)
127 #ifdef DEBUG_KEYBOARD 128 qDebug() << Q_FUNC_INFO <<
this <<
lineEdit;
138 QWidget::move(globalX, globalY);
159 return QWidget::isVisible();
164 #ifdef DEBUG_KEYBOARD 165 qDebug() << Q_FUNC_INFO << key;
167 if ((key == Qt::Key_Escape))
182 if ((key == Qt::Key_CapsLock))
188 if ((key == Qt::Key_Delete))
194 if ((key == Qt::Key_Enter) || (key == Qt::Key_Backspace))
208 #ifdef DEBUG_KEYBOARD 209 qDebug() << Q_FUNC_INFO << oldWidget << newWidget;
213 QPoint globalPos(0, 0);
214 globalPos = newWidget->mapToGlobal(QPoint(0, newWidget->height()));
225 #ifdef DEBUG_KEYBOARD 226 qDebug() << Q_FUNC_INFO <<
this << key;
231 if (key == Qt::Key_Enter)
233 QKeyEvent *pressEvent =
new QKeyEvent(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
234 QGuiApplication::postEvent(
lineEdit, pressEvent);
236 QKeyEvent *releaseEvent =
new QKeyEvent(QEvent::KeyRelease, Qt::Key_Enter, Qt::NoModifier);
237 QGuiApplication::postEvent(
lineEdit, releaseEvent);
239 else if (key == Qt::Key_Backspace)
241 QKeyEvent *pressEvent =
new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
242 QGuiApplication::postEvent(
lineEdit, pressEvent);
244 QKeyEvent *releaseEvent =
new QKeyEvent(QEvent::KeyRelease, Qt::Key_Backspace, Qt::NoModifier);
245 QGuiApplication::postEvent(
lineEdit, releaseEvent);
251 #ifdef DEBUG_KEYBOARD 252 qDebug() << Q_FUNC_INFO <<
lineEdit << characters;
257 QInputMethodEvent event;
258 event.setCommitString(characters);
260 QGuiApplication::sendEvent(
lineEdit, &event);
265 setWindowFlags(Qt::WindowDoesNotAcceptFocus | Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::BypassWindowManagerHint);
274 mapper =
new QSignalMapper(
this);
290 if (keyboardLayout[i].key == Qt::Key_Enter)
291 button->setFixedWidth(55);
293 button->setFixedWidth(35);
294 button->setFixedHeight(25);
295 button->setText(QString::fromUtf8(keyboardLayout[i].label));
297 mapper->setMapping(button, keyboardLayout[i].key);
298 connect(button, SIGNAL(clicked()),
mapper, SLOT(map()));
300 if (keyboardLayout[i].key == Qt::Key_Escape)
304 buttonEsc->setText(QString::fromUtf8(keyboardLayout[i].label));
312 widgetMask->setFixedSize(
hBoxLayout->sizeHint());
333 mapper->setMapping(button, keyboardLayout[i].keyCapsLock);
334 button->setText(QString::fromUtf8(keyboardLayout[i].labelCapsLock));
338 mapper->setMapping(button, keyboardLayout[i].key);
339 button->setText(QString::fromUtf8(keyboardLayout[i].label));
349 if (keyboardLayout[i].key == key)
352 return QString::fromUtf8(keyboardLayout[i].labelCapsLock);
354 return QString::fromUtf8(keyboardLayout[i].label);
356 else if (keyboardLayout[i].keyCapsLock == key)
357 return QString::fromUtf8(keyboardLayout[i].labelCapsLock);
const char * labelCapsLock
Déclaration de la classe Keyboard.
void paintEvent(QPaintEvent *e)
static Keyboard * getInstance(QWidget *parent=Q_NULLPTR)
void setLineEdit(QLineEdit *lineEdit)
QStackedWidget * stackedWidget
void showKeyboard(int globalX, int globalY)
void buttonClicked(int key)
void keyboardSpecialKeyClicked(int key)
Fichier qui contient la déclaration de la classe Keyboard.
void focusChange(QWidget *, QWidget *)
KeyboardLayoutEntry keyboardLayout[]
void keyClicked(const QString &text)
bool keyboardVisible() const
static const int layoutSize
QString keyToCharacter(int key)
void specialKeyClicked(int key)
Keyboard(QLineEdit *lineEdit=Q_NULLPTR, QWidget *parent=Q_NULLPTR)
void keyboardKeyClicked(const QString &characters)