Skip to content

Commit

Permalink
ui: handle two dynamic toggle icon cases (#26517)
Browse files Browse the repository at this point in the history
handles two cases
old-commit-hash: 797c626
  • Loading branch information
sshane authored Nov 16, 2022
1 parent cd33325 commit 097f501
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions selfdrive/ui/qt/widgets/controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,10 @@ class ParamControl : public ToggleControl {
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);
}
});
}

Expand All @@ -175,8 +170,10 @@ class ParamControl : public ToggleControl {
}

void refresh() {
if (params.getBool(key) != toggle.on) {
bool state = params.getBool(key);
if (state != toggle.on) {
toggle.togglePosition();
setIcon(state);
}
};

Expand All @@ -185,6 +182,14 @@ class ParamControl : public ToggleControl {
};

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;
Expand Down

0 comments on commit 097f501

Please sign in to comment.