From 62024176c6e0386401374873e73512ab76f4204a Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 15 Nov 2022 20:52:31 -0800 Subject: [PATCH] ui: toggle control supports active icons (#26514) * support active icons * function * fix crash if not setting icon but active icon * revert * clean up --- selfdrive/ui/qt/widgets/controls.cc | 6 +++--- selfdrive/ui/qt/widgets/controls.h | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/selfdrive/ui/qt/widgets/controls.cc b/selfdrive/ui/qt/widgets/controls.cc index 619fd3cb4c..456cf748f4 100644 --- a/selfdrive/ui/qt/widgets/controls.cc +++ b/selfdrive/ui/qt/widgets/controls.cc @@ -26,10 +26,10 @@ AbstractControl::AbstractControl(const QString &title, const QString &desc, cons hlayout->setSpacing(20); // left icon + icon_label = new QLabel(); if (!icon.isEmpty()) { - QPixmap pix(icon); - QLabel *icon_label = new QLabel(); - icon_label->setPixmap(pix.scaledToWidth(80, Qt::SmoothTransformation)); + icon_pixmap = QPixmap(icon).scaledToWidth(80, Qt::SmoothTransformation); + icon_label->setPixmap(icon_pixmap); icon_label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); hlayout->addWidget(icon_label); } diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index e2fd9d1b9d..0540088a78 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -54,6 +54,9 @@ public: return description->text(); } + QLabel *icon_label; + QPixmap icon_pixmap; + public slots: void showDescription() { description->setVisible(true); @@ -153,6 +156,12 @@ public: } else { 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; }; + void setActiveIcon(const QString &icon) { + active_icon_pixmap = QPixmap(icon).scaledToWidth(80, Qt::SmoothTransformation); + } + void refresh() { if (params.getBool(key) != toggle.on) { toggle.togglePosition(); @@ -174,6 +187,7 @@ public: private: std::string key; Params params; + QPixmap active_icon_pixmap; bool confirm = false; bool store_confirm = false; };