mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-23 05:42:07 +08:00
ui: toggle control supports active icons (#26514)
* support active icons
* function
* fix crash if not setting icon but active icon
* revert
* clean up
old-commit-hash: 62024176c6
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user