Skip to content

Commit 8ecdb6c

Browse files
committed
fix(ui): make compat mode hint icon follow system theme
The tips.dci icon uses alpha8 format, requiring DDciIconPalette for proper colorization. Pass theme-aware palette via DDciIconPalette::fromQPalette() and connect themeTypeChanged. 兼容模式提示图标使用alpha8格式,需要DDciIconPalette正确着色。 通过DDciIconPalette::fromQPalette()传入主题调色板,并连接 themeTypeChanged信号实现主题切换自动更新。 Log: 修复兼容模式提示图标不跟随系统深浅主题变化 PMS: BUG-362547 Influence: 兼容模式安装界面的提示图标现在会跟随系统深浅色主题自动切换颜色
1 parent f0b0462 commit 8ecdb6c

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

src/deb-installer/view/pages/singleinstallpage.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,10 @@ void SingleInstallPage::initPkgInstallProcessView(int fontinfosize)
514514
m_compatHintLabel->setWordWrap(true);
515515
m_compatHintLabel->setTextFormat(Qt::RichText);
516516
m_compatHintLabel->setAlignment(Qt::AlignCenter);
517-
const QString compatHintText = tr("If this software is an older version (already adapted for a legacy system version), you can try installing it in compatibility mode.");
517+
m_compatHintText = tr("If this software is an older version (already adapted for a legacy system version), you can try installing it in compatibility mode.");
518518
m_compatToolTip = tr("UOS V25 Compatibility Mode is a feature that allows you to continue using V20 version applications on the V25 system. It creates a compatibility environment for you, enabling software that originally could only run on the V20 system to work properly on the V25 system as well.");
519-
// 将图标 pixmap 转为 base64 data URI 嵌入富文本,使图标随文本换行到最后一行末尾
520-
QByteArray iconData;
521-
QBuffer iconBuf(&iconData);
522-
iconBuf.open(QIODevice::WriteOnly);
523-
Dtk::Gui::DDciIcon tipsIcon(QString(":/icons/deepin/uab/tips.dci"));
524-
tipsIcon.pixmap(qApp->devicePixelRatio(), 16, Dtk::Gui::DDciIcon::Light).save(&iconBuf, "PNG");
525-
m_compatHintLabel->setText(compatHintText
526-
+ QString(" <img src=\"data:image/png;base64,%1\" width=\"16\" height=\"16\" style=\"vertical-align:middle;\"/>")
527-
.arg(QString(iconData.toBase64())));
519+
updateCompatHintIcon();
520+
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &SingleInstallPage::updateCompatHintIcon);
528521
m_compatHintLabel->setMouseTracking(true);
529522
m_compatHintLabel->installEventFilter(this);
530523
m_compatHintLabel->setVisible(false);
@@ -1467,6 +1460,25 @@ bool SingleInstallPage::dependsError(int status) const
14671460
return status != Pkg::DependsOk && status != Pkg::DependsAvailable;
14681461
}
14691462

1463+
void SingleInstallPage::updateCompatHintIcon()
1464+
{
1465+
const auto theme = DGuiApplicationHelper::instance()->themeType();
1466+
Dtk::Gui::DDciIcon tipsIcon(QString(":/icons/deepin/uab/tips.dci"));
1467+
const auto iconTheme = (theme == DGuiApplicationHelper::DarkType) ? Dtk::Gui::DDciIcon::Dark : Dtk::Gui::DDciIcon::Light;
1468+
1469+
DDciIconPalette dciPalette = DDciIconPalette::fromQPalette(DPaletteHelper::instance()->palette(m_compatHintLabel));
1470+
QPixmap px = tipsIcon.pixmap(qApp->devicePixelRatio(), 16, iconTheme, DDciIcon::Normal, dciPalette);
1471+
1472+
QByteArray iconData;
1473+
QBuffer iconBuf(&iconData);
1474+
iconBuf.open(QIODevice::WriteOnly);
1475+
px.save(&iconBuf, "PNG");
1476+
1477+
m_compatHintLabel->setText(m_compatHintText
1478+
+ QString(" <img src=\"data:image/png;base64,%1\" width=\"16\" height=\"16\" style=\"vertical-align:middle;\"/>")
1479+
.arg(QString(iconData.toBase64())));
1480+
}
1481+
14701482
void SingleInstallPage::DealDependResult(int authStatus, QString dependName)
14711483
{
14721484
qCDebug(appLog) << "Deal depend result";

src/deb-installer/view/pages/singleinstallpage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ public slots:
188188

189189
bool dependsError(int status) const;
190190

191+
/**
192+
* @brief updateCompatHintIcon 根据当前主题重新渲染 tips.dci 图标并更新提示标签
193+
*/
194+
void updateCompatHintIcon();
195+
191196
private slots:
192197

193198
/**
@@ -307,6 +312,7 @@ private slots:
307312
static constexpr const char *kDefaultRootfs = "uos-rootfs-20";
308313
static constexpr const char *kDefaultRootfsOsName = "UOS 20";
309314
DLabel *m_compatHintLabel = nullptr;
315+
QString m_compatHintText;
310316
QString m_compatToolTip;
311317
DCheckBox *m_compatCheckBox = nullptr;
312318
DLabel *m_compatDescLabel = nullptr;

0 commit comments

Comments
 (0)