ui: toggle control supports active icons (#26514)

* support active icons

* function

* fix crash if not setting icon but active icon

* revert

* clean up
pull/26517/head
Shane Smiskol 2 years ago committed by GitHub
parent b3f75b0c5b
commit 62024176c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      selfdrive/ui/qt/widgets/controls.cc
  2. 14
      selfdrive/ui/qt/widgets/controls.h

@ -26,10 +26,10 @@ AbstractControl::AbstractControl(const QString &title, const QString &desc, cons
hlayout->setSpacing(20); hlayout->setSpacing(20);
// left icon // left icon
icon_label = new QLabel();
if (!icon.isEmpty()) { if (!icon.isEmpty()) {
QPixmap pix(icon); icon_pixmap = QPixmap(icon).scaledToWidth(80, Qt::SmoothTransformation);
QLabel *icon_label = new QLabel(); icon_label->setPixmap(icon_pixmap);
icon_label->setPixmap(pix.scaledToWidth(80, Qt::SmoothTransformation));
icon_label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); icon_label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
hlayout->addWidget(icon_label); hlayout->addWidget(icon_label);
} }

@ -54,6 +54,9 @@ public:
return description->text(); return description->text();
} }
QLabel *icon_label;
QPixmap icon_pixmap;
public slots: public slots:
void showDescription() { void showDescription() {
description->setVisible(true); description->setVisible(true);
@ -153,6 +156,12 @@ public:
} else { } else {
toggle.togglePosition(); toggle.togglePosition();
} }
if (state && !active_icon_pixmap.isNull()) {
icon_label->setPixmap(active_icon_pixmap);
} else if (!icon_pixmap.isNull()) {
icon_label->setPixmap(icon_pixmap);
}
}); });
} }
@ -161,6 +170,10 @@ public:
store_confirm = _store_confirm; store_confirm = _store_confirm;
}; };
void setActiveIcon(const QString &icon) {
active_icon_pixmap = QPixmap(icon).scaledToWidth(80, Qt::SmoothTransformation);
}
void refresh() { void refresh() {
if (params.getBool(key) != toggle.on) { if (params.getBool(key) != toggle.on) {
toggle.togglePosition(); toggle.togglePosition();
@ -174,6 +187,7 @@ public:
private: private:
std::string key; std::string key;
Params params; Params params;
QPixmap active_icon_pixmap;
bool confirm = false; bool confirm = false;
bool store_confirm = false; bool store_confirm = false;
}; };

Loading…
Cancel
Save