ui: handle two dynamic toggle icon cases (#26517)

handles two cases
pull/26498/head
Shane Smiskol 2 years ago committed by GitHub
parent 62024176c6
commit 797c626984
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      selfdrive/ui/qt/widgets/controls.h

@ -153,15 +153,10 @@ public:
if (!confirm || confirmed || !state || dialog.exec()) { if (!confirm || confirmed || !state || dialog.exec()) {
if (store_confirm && state) params.putBool(key + "Confirmed", true); if (store_confirm && state) params.putBool(key + "Confirmed", true);
params.putBool(key, state); params.putBool(key, state);
setIcon(state);
} 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);
}
}); });
} }
@ -175,8 +170,10 @@ public:
} }
void refresh() { void refresh() {
if (params.getBool(key) != toggle.on) { bool state = params.getBool(key);
if (state != toggle.on) {
toggle.togglePosition(); toggle.togglePosition();
setIcon(state);
} }
}; };
@ -185,6 +182,14 @@ public:
}; };
private: 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; std::string key;
Params params; Params params;
QPixmap active_icon_pixmap; QPixmap active_icon_pixmap;

Loading…
Cancel
Save