From 797c626984080e1ff17206b99e67a11bba87992f Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 15 Nov 2022 21:07:11 -0800 Subject: [PATCH] ui: handle two dynamic toggle icon cases (#26517) handles two cases --- selfdrive/ui/qt/widgets/controls.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index 0540088a78..770b9b92dd 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -153,15 +153,10 @@ public: if (!confirm || confirmed || !state || dialog.exec()) { if (store_confirm && state) params.putBool(key + "Confirmed", true); params.putBool(key, state); + setIcon(state); } 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); - } }); } @@ -175,8 +170,10 @@ public: } void refresh() { - if (params.getBool(key) != toggle.on) { + bool state = params.getBool(key); + if (state != toggle.on) { toggle.togglePosition(); + setIcon(state); } }; @@ -185,6 +182,14 @@ public: }; private: + void setIcon(bool state) { + if (state && !active_icon_pixmap.isNull()) { + icon_label->setPixmap(active_icon_pixmap); + } else if (!icon_pixmap.isNull()) { + icon_label->setPixmap(icon_pixmap); + } + }; + std::string key; Params params; QPixmap active_icon_pixmap;