diff --git a/src/app/Glyphs.cpp b/src/app/Glyphs.cpp index 24255ad..ff901a5 100644 --- a/src/app/Glyphs.cpp +++ b/src/app/Glyphs.cpp @@ -1,8 +1,11 @@ #include "Glyphs.hpp" +#include #include #include #include +#include +#include #include #include #include @@ -11,6 +14,11 @@ #include #include +#include +#include + +#include "Theme.hpp" + namespace geopro::app { namespace { @@ -150,4 +158,33 @@ QString writeChevronIcon(bool open, const QColor& color) return path; } +namespace { +// 当前主题下的 chrome 图标色:取主题主文本色(暗=浅、亮=深),保证两种模式都清晰。 +QColor themedIconColor() +{ + return eTheme->getThemeColor( + isDarkTheme() ? ElaThemeType::Dark : ElaThemeType::Light, ElaThemeType::BasicText); +} +} // namespace + +void setThemedGlyph(QLabel* label, Glyph type, int px) +{ + if (!label) return; + auto apply = [label, type, px]() { + label->setPixmap(makeGlyph(type, themedIconColor(), px).pixmap(px, px)); + }; + apply(); + QObject::connect(eTheme, &ElaTheme::themeModeChanged, label, + [apply](ElaThemeType::ThemeMode) { apply(); }); +} + +void setThemedGlyph(QAbstractButton* button, Glyph type, int px) +{ + if (!button) return; + auto apply = [button, type, px]() { button->setIcon(makeGlyph(type, themedIconColor(), px)); }; + apply(); + QObject::connect(eTheme, &ElaTheme::themeModeChanged, button, + [apply](ElaThemeType::ThemeMode) { apply(); }); +} + } // namespace geopro::app diff --git a/src/app/Glyphs.hpp b/src/app/Glyphs.hpp index 9ac1347..90eeaba 100644 --- a/src/app/Glyphs.hpp +++ b/src/app/Glyphs.hpp @@ -7,6 +7,9 @@ #include #include +class QLabel; +class QAbstractButton; + namespace geopro::app { enum class Glyph { @@ -34,6 +37,11 @@ enum class Glyph { // 生成指定颜色、像素尺寸的图标(默认 16px,内部按 2x 绘制保证清晰)。 QIcon makeGlyph(Glyph type, const QColor& color, int px = 16); +// 随 ElaTheme 明暗自动着色的 glyph(取主题文本色:暗色用浅色、亮色用深色),主题切换时自动重绘。 +// 用于面板表头/页签等 chrome 图标,避免固定色在暗色下看不清。 +void setThemedGlyph(QLabel* label, Glyph type, int px); +void setThemedGlyph(QAbstractButton* button, Glyph type, int px); + // 生成树展开/折叠箭头 PNG 到临时目录,返回文件路径(供树的 QSS `image: url(...)` 引用)。 // 配合 QTreeView::branch 背景使用,可让选中高亮不覆盖左侧缩进/箭头列且不丢箭头。 QString writeChevronIcon(bool open, const QColor& color); diff --git a/src/app/PanelHeader.cpp b/src/app/PanelHeader.cpp index 25418dc..e953b8c 100644 --- a/src/app/PanelHeader.cpp +++ b/src/app/PanelHeader.cpp @@ -83,7 +83,7 @@ QWidget* buildPanelHeader(Glyph icon, const QString& title, const QVector
setSpacing(8); auto* iconLbl = new QLabel(header); - iconLbl->setPixmap(makeGlyph(icon, QColor("#44546B"), kTitleIcon).pixmap(kTitleIcon, kTitleIcon)); + setThemedGlyph(iconLbl, icon, kTitleIcon); // 随主题着色(暗色下也清晰) lay->addWidget(iconLbl); auto* titleLbl = new QLabel(title, header); @@ -126,7 +126,7 @@ TabbedPanel buildTabbedPanel(const QVector& tabs, const QVector
setObjectName(QStringLiteral("tabBtn")); btn->setText(t.title); - btn->setIcon(makeGlyph(t.icon, QColor("#5A6B85"), kTabIcon)); + setThemedGlyph(btn, t.icon, kTabIcon); // 随主题着色 btn->setIconSize(QSize(kTabIcon, kTabIcon)); btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); btn->setCheckable(true);