fix(ela): 面板表头/页签图标随主题着色(点3)

- 新增 setThemedGlyph(QLabel*/QAbstractButton*, Glyph, px): 取 ElaTheme 主文本色(暗=浅/亮=深)绘制,
  主题切换自动重绘
- PanelHeader 表头标题图标(原 #44546B 固定→暗色看不清)、页签图标(原 #5A6B85) 改走 setThemedGlyph
  → 对象显示栏/数据集显示栏/异常列表等所有面板图标在明暗下都清晰
This commit is contained in:
gaozheng 2026-06-10 10:47:16 +08:00
parent 2be49b205c
commit 5a945e51a7
3 changed files with 47 additions and 2 deletions

View File

@ -1,8 +1,11 @@
#include "Glyphs.hpp"
#include <QAbstractButton>
#include <QByteArray>
#include <QDir>
#include <QImage>
#include <QLabel>
#include <QObject>
#include <QPainter>
#include <QPen>
#include <QPixmap>
@ -11,6 +14,11 @@
#include <QString>
#include <QSvgRenderer>
#include <ElaDef.h>
#include <ElaTheme.h>
#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

View File

@ -7,6 +7,9 @@
#include <QIcon>
#include <QString>
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);

View File

@ -83,7 +83,7 @@ QWidget* buildPanelHeader(Glyph icon, const QString& title, const QVector<Header
lay->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<PanelTab>& tabs, const QVector<Header
auto* btn = new ElaToolButton(header); // Fluent tab(选中态由 Ela checked 高亮)
btn->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);