Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions plugins/dde-dock/power/powerapplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,29 @@ void PowerApplet::onHighPerformanceSupportChanged(const bool isSupport)

void PowerApplet::refreshBatteryIcon(const QString &icon)
{
QString path = ":/batteryicons/batteryicons/" + icon;
QString iconName = icon;
QString fallbackPath = ":/batteryicons/batteryicons/" + icon + ".svg";

if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
path.append("-dark");
iconName.append("-dark");
fallbackPath = ":/batteryicons/batteryicons/" + icon + "-dark.svg";
}

// 首先尝试从主题加载图标
QIcon themeIcon = QIcon::fromTheme(iconName);
if (!themeIcon.isNull()) {
// 如果主题图标存在,使用主题图标
QPixmap pixmap = themeIcon.pixmap(m_batteryIcon->size());
m_batteryIcon->setPixmap(pixmap);
return;
}

// fallback使用资源文件
QSvgRenderer renderer(fallbackPath);
if (!renderer.isValid()) {
QString normalPath = ":/batteryicons/batteryicons/" + icon + ".svg";
renderer.load(normalPath);
}
path += ".svg";

QSvgRenderer renderer(path);

QSize size = m_batteryIcon->size();
QImage image(QSize(size * devicePixelRatioF()), QImage::Format_ARGB32_Premultiplied);
Expand Down
2 changes: 1 addition & 1 deletion plugins/dde-dock/power/powerstatuswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void PowerStatusWidget::refreshIcon()
.arg(percentageStr, plugged ? "plugged-symbolic" : "symbolic");
}

m_iconWidget->setIcon(iconStr, ":/batteryicons/resources/batteryicons/" + iconStr + ".svg");
m_iconWidget->setIcon(iconStr, ":/batteryicons/batteryicons/" + iconStr + ".svg");
m_applet->refreshBatteryIcon(iconStr);
}

Expand Down