refactor/pure-qt-ui #3
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue