Make next and prev buttons (#2598)

* Make next and prev buttons

* cleanup

* reduce diff

* Revert previous commit

* change scaling
old-commit-hash: f6ed146e8f
commatwo_master
grekiki 4 years ago committed by GitHub
parent d2710f2fcf
commit f2d7e497f8
  1. 124
      selfdrive/ui/qt/offroad/wifi.cc
  2. 4
      selfdrive/ui/qt/offroad/wifi.hpp

@ -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();
}

@ -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();
};

Loading…
Cancel
Save