diff --git a/selfdrive/ui/qt/widgets/input.cc b/selfdrive/ui/qt/widgets/input.cc index 095967a6ab..0754f2693d 100644 --- a/selfdrive/ui/qt/widgets/input.cc +++ b/selfdrive/ui/qt/widgets/input.cc @@ -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); } } diff --git a/selfdrive/ui/qt/widgets/input.h b/selfdrive/ui/qt/widgets/input.h index adab7178ef..3532d426b5 100644 --- a/selfdrive/ui/qt/widgets/input.h +++ b/selfdrive/ui/qt/widgets/input.h @@ -43,7 +43,7 @@ public slots: int exec() override; private slots: - void handleInput(const QString &s); + void handleEnter(); signals: void cancel(); diff --git a/selfdrive/ui/qt/widgets/keyboard.cc b/selfdrive/ui/qt/widgets/keyboard.cc index d11889cf89..615228a4c7 100644 --- a/selfdrive/ui/qt/widgets/keyboard.cc +++ b/selfdrive/ui/qt/widgets/keyboard.cc @@ -11,7 +11,7 @@ const QString ENTER_KEY = "→"; const QMap 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); } } diff --git a/selfdrive/ui/qt/widgets/keyboard.h b/selfdrive/ui/qt/widgets/keyboard.h index 14df6c7331..3179e5761d 100644 --- a/selfdrive/ui/qt/widgets/keyboard.h +++ b/selfdrive/ui/qt/widgets/keyboard.h @@ -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(); };