From f2d7e497f80e9acc1e6b9eaec0838a7069c81ac5 Mon Sep 17 00:00:00 2001 From: grekiki Date: Mon, 23 Nov 2020 22:56:56 +0100 Subject: [PATCH] Make next and prev buttons (#2598) * Make next and prev buttons * cleanup * reduce diff * Revert previous commit * change scaling old-commit-hash: f6ed146e8f027e83a7a99e6e89e909cc680f730a --- selfdrive/ui/qt/offroad/wifi.cc | 124 ++++++++++++++++++++----------- selfdrive/ui/qt/offroad/wifi.hpp | 4 + 2 files changed, 86 insertions(+), 42 deletions(-) diff --git a/selfdrive/ui/qt/offroad/wifi.cc b/selfdrive/ui/qt/offroad/wifi.cc index 4b86f4e989..00088d7bd2 100644 --- a/selfdrive/ui/qt/offroad/wifi.cc +++ b/selfdrive/ui/qt/offroad/wifi.cc @@ -55,6 +55,7 @@ WifiUI::WifiUI(QWidget *parent) : QWidget(parent) { // Scan on startup wifi->request_scan(); + page = 0; } void WifiUI::refresh() { @@ -74,49 +75,81 @@ void WifiUI::refresh() { for (Network &network : wifi->seen_networks){ QHBoxLayout *hlayout = new QHBoxLayout; - // SSID - hlayout->addSpacing(50); - hlayout->addWidget(new QLabel(QString::fromUtf8(network.ssid))); - - // strength indicator - unsigned int strength_scale = network.strength / 17; - QPixmap pix("../assets/images/network_" + QString::number(strength_scale) + ".png"); - QLabel *icon = new QLabel(); - icon->setPixmap(pix.scaledToWidth(100, Qt::SmoothTransformation)); - icon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); - hlayout->addWidget(icon); - hlayout->addSpacing(20); - - // connect button - QPushButton* btn = new QPushButton(network.connected ? "Connected" : "Connect"); - btn->setFixedWidth(300); - btn->setDisabled(network.connected || network.security_type == SecurityType::UNSUPPORTED); - hlayout->addWidget(btn); - hlayout->addSpacing(20); - - connectButtons->addButton(btn, i++); - - QWidget * w = new QWidget; - w->setLayout(hlayout); - vlayout->addWidget(w); - w->setStyleSheet(R"( - QLabel { - font-size: 40px; - } - QPushButton:enabled { - background-color: #114265; - } - QPushButton:disabled { - background-color: #323C43; - } - * { - background-color: #114265; - } - )"); - if(i > 10){ - return; + if(page * networks_per_page <= i && i < (page + 1) * networks_per_page){ + // SSID + hlayout->addSpacing(50); + hlayout->addWidget(new QLabel(QString::fromUtf8(network.ssid))); + + // strength indicator + unsigned int strength_scale = network.strength / 17; + QPixmap pix("../assets/images/network_" + QString::number(strength_scale) + ".png"); + QLabel *icon = new QLabel(); + icon->setPixmap(pix.scaledToWidth(100, Qt::SmoothTransformation)); + icon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); + hlayout->addWidget(icon); + hlayout->addSpacing(20); + + // connect button + QPushButton* btn = new QPushButton(network.connected ? "Connected" : "Connect"); + btn->setFixedWidth(300); + btn->setDisabled(network.connected || network.security_type == SecurityType::UNSUPPORTED); + hlayout->addWidget(btn); + hlayout->addSpacing(20); + + connectButtons->addButton(btn, i); + + QWidget * w = new QWidget; + w->setLayout(hlayout); + vlayout->addWidget(w); + w->setStyleSheet(R"( + QLabel { + font-size: 40px; + } + QPushButton:enabled { + background-color: #114265; + } + QPushButton:disabled { + background-color: #323C43; + } + * { + background-color: #114265; + } + )"); } + i+=1; } + 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); + } + 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; + w->setLayout(prev_next_buttons); + w->setStyleSheet(R"( + QPushButton:enabled { + background-color: #114265; + } + QPushButton:disabled { + background-color: #323C43; + } + * { + background-color: #114265; + } + )"); + vlayout->addWidget(w); } void WifiUI::handleButton(QAbstractButton* button) { @@ -130,7 +163,6 @@ void WifiUI::handleButton(QAbstractButton* button) { wifi->connect(n); } else if (n.security_type == SecurityType::WPA){ QString password = getStringFromUser(); - if(password.size()){ wifi->connect(n, password); } @@ -150,3 +182,11 @@ void WifiUI::receiveText(QString t) { loop.quit(); text = t; } +void WifiUI::prevPage() { + page--; + refresh(); +} +void WifiUI::nextPage() { + page++; + refresh(); +} diff --git a/selfdrive/ui/qt/offroad/wifi.hpp b/selfdrive/ui/qt/offroad/wifi.hpp index b04bb5bf8e..0343e6be5e 100644 --- a/selfdrive/ui/qt/offroad/wifi.hpp +++ b/selfdrive/ui/qt/offroad/wifi.hpp @@ -15,6 +15,8 @@ class WifiUI : public QWidget { private: WifiManager* wifi; + int page; + const int networks_per_page = 10; QStackedWidget* swidget; QVBoxLayout* vlayout; @@ -35,4 +37,6 @@ private slots: void handleButton(QAbstractButton* m_button); void refresh(); void receiveText(QString text); + void prevPage(); + void nextPage(); };