keyboard: separate signals (#21629)

* separate signals

* clean up

clean up

clean up

* clean up

* Revert "clean up"

This reverts commit 38c1f18a56.

* Revert "clean up"

This reverts commit 06430e29bf.

* Revert "separate signals"

This reverts commit 77ca8e3d17.

* separate signals

* clean up

* caps fix
pull/21633/head
sshane 2021-07-16 17:27:43 -07:00 committed by GitHub
parent c5bd6735d6
commit 0f93cb12ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 39 deletions

View File

@ -99,10 +99,17 @@ InputDialog::InputDialog(const QString &title, QWidget *parent, const QString &s
}
main_layout->addWidget(textbox_widget, 0, Qt::AlignBottom);
main_layout->addSpacing(25);
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);
setStyleSheet(R"(
@ -137,18 +144,12 @@ void InputDialog::show() {
setMainWindow(this);
}
void InputDialog::handleInput(const QString &s) {
if (!QString::compare(s,"")) {
line->backspace();
} else if (!QString::compare(s,"")) {
if (line->text().length() >= minLength) {
done(QDialog::Accepted);
emitText(line->text());
} else {
setMessage("Need at least "+QString::number(minLength)+" characters!", false);
}
void InputDialog::handleEnter() {
if (line->text().length() >= minLength) {
done(QDialog::Accepted);
emitText(line->text());
} else {
line->insert(s.left(1));
setMessage("Need at least "+QString::number(minLength)+" characters!", false);
}
}

View File

@ -43,7 +43,7 @@ public slots:
int exec() override;
private slots:
void handleInput(const QString &s);
void handleEnter();
signals:
void cancel();

View File

@ -11,7 +11,7 @@ const QString ENTER_KEY = "→";
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_horizontal = 15;
@ -113,28 +113,26 @@ Keyboard::Keyboard(QWidget *parent) : QFrame(parent) {
}
void Keyboard::handleButton(QAbstractButton* btn) {
const QString key = btn->text();
if (!QString::compare(key, "") || !QString::compare(key, "ABC")) {
main_layout->setCurrentIndex(0);
}
if (!QString::compare(key, "")) {
main_layout->setCurrentIndex(1);
}
if (!QString::compare(key, "123")) {
main_layout->setCurrentIndex(2);
}
if (!QString::compare(key, "#+=")) {
main_layout->setCurrentIndex(3);
}
if (!QString::compare(key, ENTER_KEY)) {
main_layout->setCurrentIndex(0);
}
if ("A" <= key && key <= "Z") {
main_layout->setCurrentIndex(0);
}
// TODO: break up into separate signals
if (!CONTROL_BUTTONS.contains(key)) {
emit emitButton(key);
const QString &key = btn->text();
if (CONTROL_BUTTONS.contains(key)) {
if (key == "" || key == "ABC") {
main_layout->setCurrentIndex(0);
} else if (key == "") {
main_layout->setCurrentIndex(1);
} else if (key == "123") {
main_layout->setCurrentIndex(2);
} else if (key == "#+=") {
main_layout->setCurrentIndex(3);
} else if (key == ENTER_KEY) {
main_layout->setCurrentIndex(0);
emit emitEnter();
} else if (key == BACKSPACE_KEY) {
emit emitBackspace();
}
} else {
if ("A" <= key && key <= "Z") {
main_layout->setCurrentIndex(0);
}
emit emitKey(key);
}
}

View File

@ -28,5 +28,7 @@ private slots:
void handleButton(QAbstractButton* m_button);
signals:
void emitButton(const QString &s);
void emitKey(const QString &s);
void emitBackspace();
void emitEnter();
};