From 77ca8e3d17b34e84d8d1331b565b0b2ef6bc55d0 Mon Sep 17 00:00:00 2001 From: ShaneSmiskol Date: Fri, 16 Jul 2021 14:58:35 -0700 Subject: [PATCH] separate signals --- selfdrive/ui/qt/widgets/input.cc | 28 +++++++++++++++------------- selfdrive/ui/qt/widgets/input.h | 2 +- selfdrive/ui/qt/widgets/keyboard.cc | 27 ++++++++++++--------------- selfdrive/ui/qt/widgets/keyboard.h | 4 +++- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/selfdrive/ui/qt/widgets/input.cc b/selfdrive/ui/qt/widgets/input.cc index 09ee117f50..440958b261 100644 --- a/selfdrive/ui/qt/widgets/input.cc +++ b/selfdrive/ui/qt/widgets/input.cc @@ -4,6 +4,7 @@ #include "selfdrive/ui/qt/qt_window.h" #include "selfdrive/hardware/hw.h" +#include QDialogBase::QDialogBase(QWidget *parent) : QDialog(parent) { @@ -98,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"( @@ -136,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 fbef7b7e60..470059cc3e 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..c75986e85b 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,25 @@ Keyboard::Keyboard(QWidget *parent) : QFrame(parent) { } void Keyboard::handleButton(QAbstractButton* btn) { - const QString key = btn->text(); - if (!QString::compare(key, "↓") || !QString::compare(key, "ABC")) { + const QString &key = btn->text(); + if (key == "↓" || key == "ABC") { main_layout->setCurrentIndex(0); - } - if (!QString::compare(key, "↑")) { + } else if (key == "↑") { main_layout->setCurrentIndex(1); - } - if (!QString::compare(key, "123")) { + } else if (key == "123") { main_layout->setCurrentIndex(2); - } - if (!QString::compare(key, "#+=")) { + } else if (key == "#+=") { main_layout->setCurrentIndex(3); - } - if (!QString::compare(key, ENTER_KEY)) { + } else if ("A" <= key && key <= "Z") { main_layout->setCurrentIndex(0); - } - if ("A" <= key && key <= "Z") { + } else if (key == ENTER_KEY) { main_layout->setCurrentIndex(0); + emit emitEnter(); + } else if (key == BACKSPACE_KEY) { + emit emitBackspace(); } - // TODO: break up into separate signals if (!CONTROL_BUTTONS.contains(key)) { - emit emitButton(key); + 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(); };