Make next and prev buttons (#2598)
* Make next and prev buttons * cleanup * reduce diff * Revert previous commit * change scaling old-commit-hash: f6ed146e8f027e83a7a99e6e89e909cc680f730a
This commit is contained in:
@@ -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)));
|
||||
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);
|
||||
// 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);
|
||||
// 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++);
|
||||
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;
|
||||
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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user