keyboard: separate signals (#21629)
* separate signals * clean up clean up clean up * clean up * Revert "clean up" This reverts commitpull/21633/head38c1f18a56
. * Revert "clean up" This reverts commit06430e29bf
. * Revert "separate signals" This reverts commit77ca8e3d17
. * separate signals * clean up * caps fix
parent
c5bd6735d6
commit
0f93cb12ac
|
@ -99,10 +99,17 @@ InputDialog::InputDialog(const QString &title, QWidget *parent, const QString &s
|
||||||
}
|
}
|
||||||
|
|
||||||
main_layout->addWidget(textbox_widget, 0, Qt::AlignBottom);
|
main_layout->addWidget(textbox_widget, 0, Qt::AlignBottom);
|
||||||
|
|
||||||
main_layout->addSpacing(25);
|
main_layout->addSpacing(25);
|
||||||
|
|
||||||
k = new Keyboard(this);
|
k = new Keyboard(this);
|
||||||
QObject::connect(k, &Keyboard::emitButton, this, &InputDialog::handleInput);
|
QObject::connect(k, &Keyboard::emitEnter, this, &InputDialog::handleEnter);
|
||||||
|
QObject::connect(k, &Keyboard::emitBackspace, this, [=]() {
|
||||||
|
line->backspace();
|
||||||
|
});
|
||||||
|
QObject::connect(k, &Keyboard::emitKey, this, [=](const QString &key) {
|
||||||
|
line->insert(key.left(1));
|
||||||
|
});
|
||||||
|
|
||||||
main_layout->addWidget(k, 2, Qt::AlignBottom);
|
main_layout->addWidget(k, 2, Qt::AlignBottom);
|
||||||
|
|
||||||
setStyleSheet(R"(
|
setStyleSheet(R"(
|
||||||
|
@ -137,18 +144,12 @@ void InputDialog::show() {
|
||||||
setMainWindow(this);
|
setMainWindow(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDialog::handleInput(const QString &s) {
|
void InputDialog::handleEnter() {
|
||||||
if (!QString::compare(s,"⌫")) {
|
if (line->text().length() >= minLength) {
|
||||||
line->backspace();
|
done(QDialog::Accepted);
|
||||||
} else if (!QString::compare(s,"→")) {
|
emitText(line->text());
|
||||||
if (line->text().length() >= minLength) {
|
|
||||||
done(QDialog::Accepted);
|
|
||||||
emitText(line->text());
|
|
||||||
} else {
|
|
||||||
setMessage("Need at least "+QString::number(minLength)+" characters!", false);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
line->insert(s.left(1));
|
setMessage("Need at least "+QString::number(minLength)+" characters!", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ public slots:
|
||||||
int exec() override;
|
int exec() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleInput(const QString &s);
|
void handleEnter();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|
|
@ -11,7 +11,7 @@ const QString ENTER_KEY = "→";
|
||||||
|
|
||||||
const QMap<QString, int> KEY_STRETCH = {{" ", 5}, {ENTER_KEY, 2}};
|
const QMap<QString, int> KEY_STRETCH = {{" ", 5}, {ENTER_KEY, 2}};
|
||||||
|
|
||||||
const QStringList CONTROL_BUTTONS = {"↑", "↓", "ABC", "#+=", "123"};
|
const QStringList CONTROL_BUTTONS = {"↑", "↓", "ABC", "#+=", "123", BACKSPACE_KEY, ENTER_KEY};
|
||||||
|
|
||||||
const float key_spacing_vertical = 20;
|
const float key_spacing_vertical = 20;
|
||||||
const float key_spacing_horizontal = 15;
|
const float key_spacing_horizontal = 15;
|
||||||
|
@ -113,28 +113,26 @@ Keyboard::Keyboard(QWidget *parent) : QFrame(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Keyboard::handleButton(QAbstractButton* btn) {
|
void Keyboard::handleButton(QAbstractButton* btn) {
|
||||||
const QString key = btn->text();
|
const QString &key = btn->text();
|
||||||
if (!QString::compare(key, "↓") || !QString::compare(key, "ABC")) {
|
if (CONTROL_BUTTONS.contains(key)) {
|
||||||
main_layout->setCurrentIndex(0);
|
if (key == "↓" || key == "ABC") {
|
||||||
}
|
main_layout->setCurrentIndex(0);
|
||||||
if (!QString::compare(key, "↑")) {
|
} else if (key == "↑") {
|
||||||
main_layout->setCurrentIndex(1);
|
main_layout->setCurrentIndex(1);
|
||||||
}
|
} else if (key == "123") {
|
||||||
if (!QString::compare(key, "123")) {
|
main_layout->setCurrentIndex(2);
|
||||||
main_layout->setCurrentIndex(2);
|
} else if (key == "#+=") {
|
||||||
}
|
main_layout->setCurrentIndex(3);
|
||||||
if (!QString::compare(key, "#+=")) {
|
} else if (key == ENTER_KEY) {
|
||||||
main_layout->setCurrentIndex(3);
|
main_layout->setCurrentIndex(0);
|
||||||
}
|
emit emitEnter();
|
||||||
if (!QString::compare(key, ENTER_KEY)) {
|
} else if (key == BACKSPACE_KEY) {
|
||||||
main_layout->setCurrentIndex(0);
|
emit emitBackspace();
|
||||||
}
|
}
|
||||||
if ("A" <= key && key <= "Z") {
|
} else {
|
||||||
main_layout->setCurrentIndex(0);
|
if ("A" <= key && key <= "Z") {
|
||||||
}
|
main_layout->setCurrentIndex(0);
|
||||||
|
}
|
||||||
// TODO: break up into separate signals
|
emit emitKey(key);
|
||||||
if (!CONTROL_BUTTONS.contains(key)) {
|
|
||||||
emit emitButton(key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,5 +28,7 @@ private slots:
|
||||||
void handleButton(QAbstractButton* m_button);
|
void handleButton(QAbstractButton* m_button);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void emitButton(const QString &s);
|
void emitKey(const QString &s);
|
||||||
|
void emitBackspace();
|
||||||
|
void emitEnter();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue