add wifi to setup (#2604)
* add wifi to setup * wifi looks better * move widgets * this looks ok * small fixups * fix relase tests old-commit-hash: 6a2678aae7fa353617ec111bd46181cdc422e15b
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
#include <QEvent>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
|
||||
#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<QString> control_buttons {"⇧", "↑", "ABC", "⏎", "#+=", "⌫", "123"};
|
||||
for(QString c :control_buttons){
|
||||
if(!QString::compare(s, c)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
line->insert(s.left(1));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<QPushButton*>(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,33 +7,33 @@
|
||||
#include <QTimer>
|
||||
|
||||
#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();
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
#include <QApplication>
|
||||
|
||||
#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;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <QWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QStackedWidget>
|
||||
|
||||
class Setup : public QStackedWidget {
|
||||
@@ -10,6 +11,7 @@ public:
|
||||
|
||||
private:
|
||||
QLineEdit *url_input;
|
||||
QPushButton *continue_btn;
|
||||
|
||||
QWidget *getting_started();
|
||||
QWidget *network_setup();
|
||||
|
||||
65
selfdrive/ui/qt/widgets/input_field.cc
Normal file
65
selfdrive/ui/qt/widgets/input_field.cc
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <QPushButton>
|
||||
|
||||
#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<QString> control_buttons {"⇧", "↑", "ABC", "⏎", "#+=", "⌫", "123"};
|
||||
for(QString c : control_buttons){
|
||||
if(!QString::compare(s, c)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
line->insert(s.left(1));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <QLabel>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QStackedLayout>
|
||||
#include <QLabel>
|
||||
#include <QGridLayout>
|
||||
|
||||
#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();
|
||||
@@ -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;
|
||||
}
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
#include "window.hpp"
|
||||
#include "qt_window.hpp"
|
||||
#include "offroad/input_field.hpp"
|
||||
#include "offroad/settings.hpp"
|
||||
#include "offroad/onboarding.hpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user