Qt settings: highlight selected nav button

pull/214/head
Adeeb Shihadeh 4 years ago
parent 3c00e6792c
commit c0b1518a9b
  1. 19
      selfdrive/ui/qt/offroad/settings.cc
  2. 2
      selfdrive/ui/qt/offroad/settings.hpp

@ -213,12 +213,12 @@ QWidget * network_panel(QWidget * parent) {
void SettingsWindow::setActivePanel() { void SettingsWindow::setActivePanel() {
QPushButton *btn = qobject_cast<QPushButton*>(sender()); auto *btn = qobject_cast<QPushButton *>(nav_btns->checkedButton());
panel_layout->setCurrentWidget(panels[btn->text()]); panel_layout->setCurrentWidget(panels[btn->text()]);
} }
SettingsWindow::SettingsWindow(QWidget *parent) : QWidget(parent) { SettingsWindow::SettingsWindow(QWidget *parent) : QWidget(parent) {
// sidebar // two main layouts
QVBoxLayout *sidebar_layout = new QVBoxLayout(); QVBoxLayout *sidebar_layout = new QVBoxLayout();
panel_layout = new QStackedLayout(); panel_layout = new QStackedLayout();
@ -228,7 +228,7 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QWidget(parent) {
QPushButton { QPushButton {
padding: 50px; padding: 50px;
font-weight: bold; font-weight: bold;
font-size: 100px; font-size: 110px;
} }
)"); )");
sidebar_layout->addWidget(close_button); sidebar_layout->addWidget(close_button);
@ -242,26 +242,33 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QWidget(parent) {
{"toggles", toggles_panel()}, {"toggles", toggles_panel()},
}; };
nav_btns = new QButtonGroup();
for (auto &panel : panels) { for (auto &panel : panels) {
QPushButton *btn = new QPushButton(panel.first); QPushButton *btn = new QPushButton(panel.first);
btn->setCheckable(true);
btn->setStyleSheet(R"( btn->setStyleSheet(R"(
QPushButton { QPushButton {
padding-top: 35px; padding-top: 35px;
padding-bottom: 35px; padding-bottom: 35px;
font-size: 60px;
text-align: right;
border: none; border: none;
background: none; background: none;
font-size: 55px;
}
QPushButton:checked {
font-size: 50px;
font-weight: bold; font-weight: bold;
} }
)"); )");
sidebar_layout->addWidget(btn); nav_btns->addButton(btn);
sidebar_layout->addWidget(btn, 0, Qt::AlignRight);
panel_layout->addWidget(panel.second); panel_layout->addWidget(panel.second);
QObject::connect(btn, SIGNAL(released()), this, SLOT(setActivePanel())); QObject::connect(btn, SIGNAL(released()), this, SLOT(setActivePanel()));
} }
qobject_cast<QPushButton *>(nav_btns->buttons()[0])->setChecked(true);
QHBoxLayout *settings_layout = new QHBoxLayout(); QHBoxLayout *settings_layout = new QHBoxLayout();
settings_layout->setMargin(0);
settings_layout->addSpacing(45); settings_layout->addSpacing(45);
sidebar_widget = new QWidget; sidebar_widget = new QWidget;

@ -4,6 +4,7 @@
#include <QFrame> #include <QFrame>
#include <QTimer> #include <QTimer>
#include <QPushButton> #include <QPushButton>
#include <QButtonGroup>
#include <QStackedLayout> #include <QStackedLayout>
#include "wifi.hpp" #include "wifi.hpp"
@ -40,6 +41,7 @@ private:
QPushButton *sidebar_alert_widget; QPushButton *sidebar_alert_widget;
QWidget *sidebar_widget; QWidget *sidebar_widget;
std::map<QString, QWidget *> panels; std::map<QString, QWidget *> panels;
QButtonGroup *nav_btns;
QStackedLayout *panel_layout; QStackedLayout *panel_layout;
public slots: public slots:

Loading…
Cancel
Save