diff --git a/release/files_common b/release/files_common index a144e1bd00..551f670a9d 100644 --- a/release/files_common +++ b/release/files_common @@ -353,6 +353,8 @@ selfdrive/ui/qt/*.cc selfdrive/ui/qt/*.hpp selfdrive/ui/qt/offroad/*.cc selfdrive/ui/qt/offroad/*.hpp +selfdrive/ui/qt/widgets/*.cc +selfdrive/ui/qt/widgets/*.hpp selfdrive/ui/android/*.cc selfdrive/ui/android/*.hpp diff --git a/selfdrive/ui/SConscript b/selfdrive/ui/SConscript index 519b1919fd..102f0ce493 100644 --- a/selfdrive/ui/SConscript +++ b/selfdrive/ui/SConscript @@ -73,8 +73,8 @@ else: qt_env.Library("qt_widgets", - ["qt/qt_window.cc", "qt/qt_sound.cc", "qt/offroad/keyboard.cc", "qt/offroad/input_field.cc", - "qt/offroad/wifi.cc", "qt/offroad/wifiManager.cc", "qt/offroad/toggle.cc"], + ["qt/qt_window.cc", "qt/qt_sound.cc", "qt/widgets/keyboard.cc", "qt/widgets/input_field.cc", + "qt/offroad/wifi.cc", "qt/offroad/wifiManager.cc", "qt/widgets/toggle.cc"], LIBS=qt_libs) qt_libs.append("qt_widgets") diff --git a/selfdrive/ui/qt/offroad/input_field.cc b/selfdrive/ui/qt/offroad/input_field.cc deleted file mode 100644 index 8409b18048..0000000000 --- a/selfdrive/ui/qt/offroad/input_field.cc +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include -#include -#include - -#include "input_field.hpp" -#include "keyboard.hpp" - -InputField::InputField(QWidget *parent): QWidget(parent) { - l = new QVBoxLayout(); - QHBoxLayout *r = new QHBoxLayout(); - label = new QLabel(this); - label->setText("password"); - r->addWidget(label); - QPushButton* cancel = new QPushButton("cancel"); - QObject::connect(cancel, SIGNAL(released()), this, SLOT(emitEmpty())); - cancel->setFixedHeight(150); - cancel->setFixedWidth(300); - r->addWidget(cancel); - l->addLayout(r); - l->addSpacing(80); - - line = new QLineEdit(""); - l->addWidget(line); - l->addSpacing(80); - - k = new Keyboard(this); - QObject::connect(k, SIGNAL(emitButton(QString)), this, SLOT(getText(QString))); - l->addWidget(k); - setLayout(l); -} - -void InputField::emitEmpty(){ - emitText(""); - line->setText(""); -} -void InputField::getText(QString s){ - if(!QString::compare(s,"⌫")){ - line->backspace(); - } - - if(!QString::compare(s,"⏎")){ - emitText(line->text()); - line->setText(""); - } - - QVector control_buttons {"⇧", "↑", "ABC", "⏎", "#+=", "⌫", "123"}; - for(QString c :control_buttons){ - if(!QString::compare(s, c)){ - return; - } - } - line->insert(s.left(1)); -} - diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 550fdb4aea..8d5424df08 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -12,8 +12,7 @@ #include "wifi.hpp" #include "settings.hpp" -#include "input_field.hpp" -#include "toggle.hpp" +#include "widgets/toggle.hpp" #include "common/params.h" #include "common/utilpp.h" @@ -22,8 +21,8 @@ const int SIDEBAR_WIDTH = 400; ParamsToggle::ParamsToggle(QString param, QString title, QString description, QString icon_path, QWidget *parent): QFrame(parent) , param(param) { QHBoxLayout *hlayout = new QHBoxLayout; - - //Parameter image + + // Parameter image hlayout->addSpacing(25); if (icon_path.length()){ QPixmap pix(icon_path); @@ -35,12 +34,12 @@ ParamsToggle::ParamsToggle(QString param, QString title, QString description, QS hlayout->addSpacing(100); } hlayout->addSpacing(25); - - //Name of the parameter + + // Name of the parameter QLabel *label = new QLabel(title); label->setWordWrap(true); - //toggle switch + // toggle switch Toggle* toggle_switch = new Toggle(this); QSizePolicy switch_policy(QSizePolicy::Preferred, QSizePolicy::Preferred); switch_policy.setHorizontalStretch(1); diff --git a/selfdrive/ui/qt/offroad/wifi.cc b/selfdrive/ui/qt/offroad/wifi.cc index 2b99443a52..269149f75c 100644 --- a/selfdrive/ui/qt/offroad/wifi.cc +++ b/selfdrive/ui/qt/offroad/wifi.cc @@ -20,7 +20,7 @@ void clearLayout(QLayout* layout) { } } -WifiUI::WifiUI(QWidget *parent) : QWidget(parent) { +WifiUI::WifiUI(QWidget *parent, int page_length) : QWidget(parent), networks_per_page(page_length) { wifi = new WifiManager; QObject::connect(wifi, SIGNAL(wrongPassword(QString)), this, SLOT(wrongPassword(QString))); @@ -34,18 +34,13 @@ WifiUI::WifiUI(QWidget *parent) : QWidget(parent) { swidget->addWidget(wifi_widget); // Keyboard page - a = new InputField(); - QObject::connect(a, SIGNAL(emitText(QString)), this, SLOT(receiveText(QString))); - swidget->addWidget(a); + input_field = new InputField(); + QObject::connect(input_field, SIGNAL(emitText(QString)), this, SLOT(receiveText(QString))); + swidget->addWidget(input_field); swidget->setCurrentIndex(0); top_layout->addWidget(swidget); setLayout(top_layout); - a->setStyleSheet(R"( - QLineEdit { - background-color: #114265; - } - )"); // Update network list timer = new QTimer(this); @@ -53,10 +48,11 @@ WifiUI::WifiUI(QWidget *parent) : QWidget(parent) { timer->start(2000); // Scan on startup + QLabel *scanning = new QLabel("Scanning for networks"); + scanning->setStyleSheet(R"(font-size: 65px;)"); + vlayout->addWidget(scanning, 0, Qt::AlignCenter); + wifi->request_scan(); - QLabel* scanning = new QLabel(this); - scanning->setText("Scanning for networks"); - vlayout->addWidget(scanning); refresh(); page = 0; } @@ -108,7 +104,9 @@ void WifiUI::refresh() { QLabel { font-size: 50px; } - QPushButton:enabled { + QPushButton { + padding: 0; + font-size: 40px; background-color: #114265; } QPushButton:disabled { @@ -118,39 +116,37 @@ void WifiUI::refresh() { background-color: #114265; } )"); - countWidgets+=1; + countWidgets += 1; } - i+=1; + i += 1; } - //Pad vlayout to prevert oversized network widgets in case of low visible network count - for(int i = countWidgets ; i < networks_per_page ; i++){ - QWidget * w = new QWidget; + // Pad vlayout to prevert oversized network widgets in case of low visible network count + for(int i = countWidgets; i < networks_per_page; i++) { + QWidget *w = new QWidget; vlayout->addWidget(w); } - + QHBoxLayout *prev_next_buttons = new QHBoxLayout; QPushButton* prev = new QPushButton("Previous"); prev->setEnabled(page); prev->setFixedHeight(100); QPushButton* next = new QPushButton("Next"); next->setFixedHeight(100); - - //If there are more visible networks then we can show, enable going to next page - if(wifi->seen_networks.size() > (page + 1) * networks_per_page){ - next->setEnabled(true); - }else{ - next->setDisabled(true); - } + + // If there are more visible networks then we can show, enable going to next page + next->setEnabled(wifi->seen_networks.size() > (page + 1) * networks_per_page); + QObject::connect(prev, SIGNAL(released()), this, SLOT(prevPage())); QObject::connect(next, SIGNAL(released()), this, SLOT(nextPage())); prev_next_buttons->addWidget(prev); prev_next_buttons->addWidget(next); - QWidget * w = new QWidget; + QWidget *w = new QWidget; w->setLayout(prev_next_buttons); w->setStyleSheet(R"( - QPushButton:enabled { + QPushButton { + padding: 0; background-color: #114265; } QPushButton:disabled { @@ -167,7 +163,7 @@ void WifiUI::handleButton(QAbstractButton* button) { QPushButton* btn = static_cast(button); Network n = wifi->seen_networks[connectButtons->id(btn)]; - a->label->setText("Enter password for \"" + n.ssid + "\""); + input_field->setPromptText("Enter password for \"" + n.ssid + "\""); connectToNetwork(n); } @@ -206,7 +202,7 @@ void WifiUI::wrongPassword(QString ssid){ } for(Network n : wifi->seen_networks){ if(n.ssid == ssid){ - a->label->setText("Wrong password for \"" + n.ssid +"\""); + input_field->setPromptText("Wrong password for \"" + n.ssid +"\""); connectToNetwork(n); } } diff --git a/selfdrive/ui/qt/offroad/wifi.hpp b/selfdrive/ui/qt/offroad/wifi.hpp index bbda7a1450..3be80b79b0 100644 --- a/selfdrive/ui/qt/offroad/wifi.hpp +++ b/selfdrive/ui/qt/offroad/wifi.hpp @@ -7,33 +7,33 @@ #include #include "wifiManager.hpp" -#include "input_field.hpp" +#include "widgets/input_field.hpp" class WifiUI : public QWidget { Q_OBJECT +public: + int page; + explicit WifiUI(QWidget *parent = 0, int page_length = 8); + private: WifiManager* wifi; - const int networks_per_page = 8; + const int networks_per_page; - QStackedWidget* swidget; - QVBoxLayout* vlayout; - QWidget * wifi_widget; + QStackedWidget *swidget; + QVBoxLayout *vlayout; + QWidget *wifi_widget; - InputField *a; + InputField *input_field; QEventLoop loop; - QTimer * timer; + QTimer *timer; QString text; QButtonGroup *connectButtons; void connectToNetwork(Network n); QString getStringFromUser(); -public: - int page; - explicit WifiUI(QWidget *parent = 0); - private slots: void handleButton(QAbstractButton* m_button); void refresh(); diff --git a/selfdrive/ui/qt/setup/setup.cc b/selfdrive/ui/qt/setup/setup.cc index 31938707be..a617c283c4 100644 --- a/selfdrive/ui/qt/setup/setup.cc +++ b/selfdrive/ui/qt/setup/setup.cc @@ -11,9 +11,10 @@ #include #include "setup.hpp" +#include "offroad/wifi.hpp" #include "qt_window.hpp" -#define USER_AGENT "AGNOS-0.1" +#define USER_AGENT "AGNOSSetup-0.1" int download(std::string url) { CURL *curl; @@ -67,14 +68,24 @@ QWidget * Setup::getting_started() { } QWidget * Setup::network_setup() { + QVBoxLayout *main_layout = new QVBoxLayout(); - main_layout->setMargin(100); + main_layout->setContentsMargins(50, 50, 50, 50); - main_layout->addWidget(title_label("Connect to WiFi"), 0, Qt::AlignCenter); + main_layout->addWidget(title_label("Connect to WiFi"), 0, Qt::AlignTop); - QPushButton *btn = new QPushButton("Continue"); - main_layout->addWidget(btn); - QObject::connect(btn, SIGNAL(released()), this, SLOT(nextPage())); + WifiUI *wifi = new WifiUI(this, 6); + main_layout->addWidget(wifi); + QObject::connect(wifi, &WifiUI::openKeyboard, this, [=](){ + this->continue_btn->setVisible(false); + }); + QObject::connect(wifi, &WifiUI::closeKeyboard, this, [=](){ + this->continue_btn->setVisible(true); + }); + + continue_btn = new QPushButton("Continue"); + main_layout->addWidget(continue_btn); + QObject::connect(continue_btn, SIGNAL(released()), this, SLOT(nextPage())); QWidget *widget = new QWidget(); widget->setLayout(main_layout); @@ -93,9 +104,7 @@ QWidget * Setup::software_selection() { main_layout->addSpacing(50); - const char* env_url = getenv("CUSTOM_URL"); - QString default_url = env_url == NULL ? "" : QString::fromStdString(env_url); - url_input = new QLineEdit(default_url); + url_input = new QLineEdit(); url_input->setStyleSheet(R"( color: black; background-color: white; diff --git a/selfdrive/ui/qt/setup/setup.hpp b/selfdrive/ui/qt/setup/setup.hpp index dec2ef084c..fc98c29818 100644 --- a/selfdrive/ui/qt/setup/setup.hpp +++ b/selfdrive/ui/qt/setup/setup.hpp @@ -1,5 +1,6 @@ #include #include +#include #include class Setup : public QStackedWidget { @@ -10,6 +11,7 @@ public: private: QLineEdit *url_input; + QPushButton *continue_btn; QWidget *getting_started(); QWidget *network_setup(); diff --git a/selfdrive/ui/qt/widgets/input_field.cc b/selfdrive/ui/qt/widgets/input_field.cc new file mode 100644 index 0000000000..8492f36d83 --- /dev/null +++ b/selfdrive/ui/qt/widgets/input_field.cc @@ -0,0 +1,65 @@ +#include + +#include "input_field.hpp" + +InputField::InputField(QWidget *parent): QWidget(parent) { + layout = new QGridLayout(); + layout->setSpacing(30); + + label = new QLabel(this); + label->setStyleSheet(R"(font-size: 55px;)"); + layout->addWidget(label, 0, 0, Qt::AlignVCenter | Qt::AlignLeft); + layout->setColumnStretch(0, 1); + + QPushButton* cancel = new QPushButton("Cancel"); + cancel->setFixedSize(300, 150); + cancel->setStyleSheet(R"(padding: 0;)"); + layout->addWidget(cancel, 0, 1, Qt::AlignVCenter | Qt::AlignRight); + QObject::connect(cancel, SIGNAL(released()), this, SLOT(emitEmpty())); + + // text box + line = new QLineEdit(); + line->setStyleSheet(R"( + color: black; + background-color: white; + font-size: 45px; + padding: 25px; + )"); + layout->addWidget(line, 1, 0, 1, -1); + + k = new Keyboard(this); + QObject::connect(k, SIGNAL(emitButton(QString)), this, SLOT(getText(QString))); + layout->addWidget(k, 2, 0, 1, -1); + + setLayout(layout); +} + +void InputField::setPromptText(QString text) { + label->setText(text); +} + +void InputField::emitEmpty() { + emitText(""); + line->setText(""); +} + +void InputField::getText(QString s) { + if(!QString::compare(s,"⌫")){ + line->backspace(); + } + + if(!QString::compare(s,"⏎")){ + emitText(line->text()); + line->setText(""); + } + + QVector control_buttons {"⇧", "↑", "ABC", "⏎", "#+=", "⌫", "123"}; + for(QString c : control_buttons){ + if(!QString::compare(s, c)){ + return; + } + } + + line->insert(s.left(1)); +} + diff --git a/selfdrive/ui/qt/offroad/input_field.hpp b/selfdrive/ui/qt/widgets/input_field.hpp similarity index 77% rename from selfdrive/ui/qt/offroad/input_field.hpp rename to selfdrive/ui/qt/widgets/input_field.hpp index a56bac2619..8dad0c0dda 100644 --- a/selfdrive/ui/qt/offroad/input_field.hpp +++ b/selfdrive/ui/qt/widgets/input_field.hpp @@ -1,10 +1,10 @@ #pragma once +#include +#include #include #include -#include -#include -#include +#include #include "keyboard.hpp" @@ -13,12 +13,13 @@ class InputField : public QWidget { public: explicit InputField(QWidget* parent = 0); - QLabel *label; - + void setPromptText(QString text); + private: QLineEdit *line; Keyboard *k; - QVBoxLayout *l; + QLabel *label; + QGridLayout *layout; public slots: void emitEmpty(); diff --git a/selfdrive/ui/qt/offroad/keyboard.cc b/selfdrive/ui/qt/widgets/keyboard.cc similarity index 97% rename from selfdrive/ui/qt/offroad/keyboard.cc rename to selfdrive/ui/qt/widgets/keyboard.cc index 8f94348cb6..0f7dd58ca2 100644 --- a/selfdrive/ui/qt/offroad/keyboard.cc +++ b/selfdrive/ui/qt/widgets/keyboard.cc @@ -88,7 +88,10 @@ Keyboard::Keyboard(QWidget *parent) : QWidget(parent) { main_layout->setCurrentIndex(0); setStyleSheet(R"( - QPushButton { font-size: 50px } + QPushButton { + padding: 0; + font-size: 50px; + } * { background-color: #99777777; } diff --git a/selfdrive/ui/qt/offroad/keyboard.hpp b/selfdrive/ui/qt/widgets/keyboard.hpp similarity index 100% rename from selfdrive/ui/qt/offroad/keyboard.hpp rename to selfdrive/ui/qt/widgets/keyboard.hpp diff --git a/selfdrive/ui/qt/offroad/toggle.cc b/selfdrive/ui/qt/widgets/toggle.cc similarity index 100% rename from selfdrive/ui/qt/offroad/toggle.cc rename to selfdrive/ui/qt/widgets/toggle.cc diff --git a/selfdrive/ui/qt/offroad/toggle.hpp b/selfdrive/ui/qt/widgets/toggle.hpp similarity index 100% rename from selfdrive/ui/qt/offroad/toggle.hpp rename to selfdrive/ui/qt/widgets/toggle.hpp diff --git a/selfdrive/ui/qt/window.cc b/selfdrive/ui/qt/window.cc index 5fdcb27b97..4a47e70c4a 100644 --- a/selfdrive/ui/qt/window.cc +++ b/selfdrive/ui/qt/window.cc @@ -11,7 +11,6 @@ #include "window.hpp" #include "qt_window.hpp" -#include "offroad/input_field.hpp" #include "offroad/settings.hpp" #include "offroad/onboarding.hpp"