14Clavier::Clavier(QWidget *parent) : QDialog(parent), majusculeActive(true), isSymbolMode(false)
16 setWindowTitle(
"Clavier GPS");
19 this->setWindowState(Qt::WindowFullScreen);
20 currentLayout = AZERTY;
22 QVBoxLayout *mainLayout =
new QVBoxLayout(
this);
23 mainLayout->setSpacing(5);
24 mainLayout->setContentsMargins(8, 8, 8, 8);
27 mainLayout->addStretch(1);
30 suggestionList =
new QListWidget(
this);
31 suggestionList->setVisible(
false);
32 suggestionList->setMaximumHeight(100);
33 suggestionList->setStyleSheet(
"font-size: 16px; background: white; color: black; border-radius: 10px;");
34 mainLayout->addWidget(suggestionList);
37 lineEdit =
new QLineEdit(
this);
38 lineEdit->setFixedHeight(45);
39 lineEdit->setStyleSheet(
"font-size: 18px; padding: 10px; font-weight: bold; background: #2a2f3a; color: white; border-radius: 8px;");
40 mainLayout->addWidget(lineEdit);
43 connect(suggestionList, &QListWidget::itemClicked,
this, [=](QListWidgetItem *item){
44 lineEdit->setText(item->text());
45 suggestionList->hide();
50 gridLayout =
new QGridLayout();
51 gridLayout->setSpacing(4);
55 QString keyStyle =
"QPushButton { font-size: 16px; font-weight: bold; border-radius: 8px; background: #333a4a; color: white; } "
56 "QPushButton:pressed { background: #4a5468; }";
59 QStringList chiffres = {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0"};
60 for (
int i = 0; i < chiffres.size(); ++i) {
61 QPushButton *btn =
new QPushButton(chiffres[i],
this);
62 btn->setFixedSize(btnW, btnH);
63 btn->setStyleSheet(keyStyle);
64 connect(btn, &QPushButton::clicked,
this, &Clavier::handleButton);
65 gridLayout->addWidget(btn, 0, i);
69 QPushButton *btnDel =
new QPushButton(
"⌫",
this);
70 btnDel->setFixedSize(80, btnH);
71 btnDel->setStyleSheet(
"QPushButton { font-size: 26px; background: #852222; color: white; border-radius: 8px; font-weight: bold; }");
72 connect(btnDel, &QPushButton::pressed,
this, &Clavier::startDeleteDelay);
73 connect(btnDel, &QPushButton::released,
this, &Clavier::stopDelete);
74 gridLayout->addWidget(btnDel, 0, 10);
77 QStringList r1 = {
"A",
"Z",
"E",
"R",
"T",
"Y",
"U",
"I",
"O",
"P"};
78 QStringList r2 = {
"Q",
"S",
"D",
"F",
"G",
"H",
"J",
"K",
"L",
"M"};
79 QStringList r3 = {
"W",
"X",
"C",
"V",
"B",
"N"};
82 auto createRow = [&](
const QStringList& keys,
int rowIdx, QList<QPushButton*>& list,
int colOffset = 0) {
83 for (
int i = 0; i < keys.size(); ++i) {
84 QPushButton *btn =
new QPushButton(keys[i],
this);
85 btn->setFixedSize(btnW, btnH);
86 btn->setStyleSheet(keyStyle);
88 allButtons.append(btn);
89 connect(btn, &QPushButton::pressed,
this, &Clavier::startLongPress);
90 connect(btn, &QPushButton::released,
this, &Clavier::stopLongPress);
91 connect(btn, &QPushButton::clicked,
this, &Clavier::handleButton);
92 gridLayout->addWidget(btn, rowIdx, i + colOffset);
96 createRow(r1, 1, row1Buttons);
97 createRow(r2, 2, row2Buttons);
98 createRow(r3, 3, row3Buttons, 1);
101 apostropheButton =
new QPushButton(
"'",
this);
102 apostropheButton->setFixedSize(btnW, btnH);
103 apostropheButton->setStyleSheet(keyStyle);
104 allButtons.append(apostropheButton);
105 connect(apostropheButton, &QPushButton::clicked,
this, &Clavier::handleButton);
106 gridLayout->addWidget(apostropheButton, 3, 8);
108 shiftButton =
new QPushButton(
"⇧",
this);
109 shiftButton->setFixedSize(80, btnH);
110 shiftButton->setStyleSheet(keyStyle);
111 connect(shiftButton, &QPushButton::clicked,
this, &Clavier::toggleShift);
112 gridLayout->addWidget(shiftButton, 3, 9, 1, 2);
114 langueButton =
new QPushButton(
"🌍 AZERTY",
this);
115 langueButton->setFixedSize(140, btnH);
116 langueButton->setStyleSheet(keyStyle);
117 connect(langueButton, &QPushButton::clicked,
this, &Clavier::switchLayout);
118 gridLayout->addWidget(langueButton, 4, 0, 1, 2);
120 switchButton =
new QPushButton(
"123?",
this);
121 switchButton->setFixedSize(100, btnH);
122 switchButton->setStyleSheet(keyStyle);
123 connect(switchButton, &QPushButton::clicked,
this, &Clavier::switchKeyboard);
124 gridLayout->addWidget(switchButton, 4, 2);
126 QPushButton *btnSpace =
new QPushButton(
"ESPACE",
this);
127 btnSpace->setFixedSize(250, btnH);
128 btnSpace->setStyleSheet(keyStyle);
129 connect(btnSpace, &QPushButton::clicked,
this, &Clavier::addSpace);
130 gridLayout->addWidget(btnSpace, 4, 3, 1, 4);
132 QPushButton *btnUnderscore =
new QPushButton(
"_",
this);
133 btnUnderscore->setFixedSize(btnW, btnH);
134 btnUnderscore->setStyleSheet(keyStyle);
135 connect(btnUnderscore, &QPushButton::clicked,
this, &Clavier::addUnderscore);
136 gridLayout->addWidget(btnUnderscore, 4, 7);
138 QPushButton *btnVal =
new QPushButton(
"✔",
this);
139 btnVal->setFixedSize(100, btnH);
140 btnVal->setStyleSheet(
"QPushButton { background-color: #2e7d32; color: white; font-size: 28px; font-weight: bold; border-radius: 8px; }");
141 connect(btnVal, &QPushButton::clicked,
this, &Clavier::validateText);
142 gridLayout->addWidget(btnVal, 4, 9, 1, 2);
145 QStringList syms = {
"@",
"#",
"$",
"%",
"&",
"*",
"(",
")",
"-",
"+",
"=",
"/",
"\\",
"{",
"}",
"[",
"]",
";",
":",
"\"",
"<",
">",
",",
".",
"?",
"!",
"|"};
146 int sRow = 1, sCol = 0;
147 for (
const QString &s : syms) {
148 QPushButton *sb =
new QPushButton(s,
this);
149 sb->setFixedSize(btnW, btnH);
150 sb->setStyleSheet(keyStyle);
151 sb->setVisible(
false);
152 symbolButtons.append(sb);
153 connect(sb, &QPushButton::clicked,
this, &Clavier::handleButton);
154 gridLayout->addWidget(sb, sRow, sCol++);
155 if (sCol > 9) { sCol = 0; sRow++; }
158 mainLayout->addLayout(gridLayout);
161 deleteTimer =
new QTimer(
this);
162 deleteDelayTimer =
new QTimer(
this);
163 deleteDelayTimer->setSingleShot(
true);
164 connect(deleteDelayTimer, &QTimer::timeout,
this, &Clavier::startDelete);
165 connect(deleteTimer, &QTimer::timeout,
this, &Clavier::deleteChar);
167 longPressTimer =
new QTimer(
this);
168 longPressTimer->setSingleShot(
true);
169 connect(longPressTimer, &QTimer::timeout,
this, &Clavier::handleLongPress);
172 accentMap.insert(
"e", {
"é",
"è",
"ê",
"ë"});
173 accentMap.insert(
"a", {
"à",
"â"});
174 accentMap.insert(
"i", {
"î",
"ï"});
175 accentMap.insert(
"o", {
"ô",
"ö"});
176 accentMap.insert(
"u", {
"û",
"ù"});
177 accentMap.insert(
"c", {
"ç"});
181 updateKeyboardLayout();