Initial implementation of theming

This commit is contained in:
luisangelsm
2026-02-19 17:39:22 +01:00
parent ed28c94f66
commit 044176d6b7
303 changed files with 4634 additions and 2119 deletions

View File

@ -1270,9 +1270,8 @@ void YACReaderFlow3D::setTextColor(const QColor &color)
{
textColor = color;
QPalette palette = indexLabel->palette();
palette.setColor(QPalette::WindowText, textColor);
indexLabel->setPalette(palette);
auto styleSheet = QString("QLabel { color: %1; }").arg(textColor.name());
indexLabel->setStyleSheet(styleSheet);
update();
}
@ -1424,9 +1423,8 @@ void YACReaderFlow3D::updateIndexLabelStyle()
QFont font("Arial", newFontSize);
indexLabel->setFont(font);
QPalette palette = indexLabel->palette();
palette.setColor(QPalette::WindowText, textColor);
indexLabel->setPalette(palette);
auto styleSheet = QString("QLabel { color: %1; }").arg(textColor.name());
indexLabel->setStyleSheet(styleSheet);
indexLabel->move(10, 10);
indexLabel->adjustSize();
@ -1435,9 +1433,7 @@ void YACReaderFlow3D::updateIndexLabelStyle()
#if defined(YACREADER_RHI_PERF)
if (perfLabel) {
perfLabel->setFont(font);
QPalette p = perfLabel->palette();
p.setColor(QPalette::WindowText, textColor);
perfLabel->setPalette(p);
perfLabel->setStyleSheet(styleSheet);
perfLabel->move(10, 10 + indexLabel->height() + 4);
perfLabel->adjustSize();
}

View File

@ -1,7 +1,28 @@
#include "icon_utils.h"
#include <QSvgRenderer>
#include "yacreader_global.h"
QPixmap renderSvgToPixmap(const QString &svgPath, int logicalSize, qreal devicePixelRatio)
{
return renderSvgToPixmap(svgPath, logicalSize, logicalSize, devicePixelRatio);
}
QPixmap renderSvgToPixmap(const QString &svgPath, int logicalWidth, int logicalHeight, qreal devicePixelRatio)
{
const int pixelWidth = qRound(logicalWidth * devicePixelRatio);
const int pixelHeight = qRound(logicalHeight * devicePixelRatio);
QPixmap pixmap(pixelWidth, pixelHeight);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
QSvgRenderer renderer(svgPath);
renderer.render(&painter);
painter.end();
pixmap.setDevicePixelRatio(devicePixelRatio);
return pixmap;
}
QString readSvg(const QString &resourcePath)
{
QFile in(resourcePath);

View File

@ -3,6 +3,11 @@
#include <QtGui>
// Render an SVG file to a QPixmap at a specific logical size with HiDPI support.
// Uses QSvgRenderer to rasterize directly at the target resolution (no upscaling).
QPixmap renderSvgToPixmap(const QString &svgPath, int logicalSize, qreal devicePixelRatio);
QPixmap renderSvgToPixmap(const QString &svgPath, int logicalWidth, int logicalHeight, qreal devicePixelRatio);
struct RecolorOptions {
QString suffix;
QString fileName;

View File

@ -0,0 +1,17 @@
#ifndef WHATS_NEW_DIALOG_THEME_H
#define WHATS_NEW_DIALOG_THEME_H
#include <QColor>
#include <QPixmap>
struct WhatsNewDialogTheme {
QColor backgroundColor;
QColor headerTextColor;
QColor versionTextColor;
QColor contentTextColor;
QColor linkColor;
QPixmap closeButtonIcon;
QPixmap headerDecoration;
};
#endif // WHATS_NEW_DIALOG_THEME_H

View File

@ -6,6 +6,8 @@
#include <QGuiApplication>
#include <QStyleHints>
// TODO: add API to force color scheme //styleHints->setColorScheme(Qt::ColorScheme::Dark);
ThemeManager::ThemeManager()
{
}

View File

@ -8,6 +8,7 @@ HEADERS += \
$$PWD/themable.h \
$$PWD/yacreader_icon.h \
$$PWD/shared/help_about_dialog_theme.h \
$$PWD/shared/whats_new_dialog_theme.h \
SOURCES += \

View File

@ -53,22 +53,6 @@ QList<qulonglong> YACReader::mimeDataToComicsIds(const QMimeData *data)
return comicIds;
}
// TODO some SVG assets are missing in macos (WIP)
// we need two sets of icons, one for the toolbar and one for the context menu because of this bug (QTBUG-96553): https://bugreports.qt.io/browse/QTBUG-96553
QString YACReader::addExtensionToIconPath(const QString &path)
{
#ifdef YACREADER_LIBRARY
#ifdef Q_OS_MACOS // TODO_Y_MAC_UI
return path + ".png";
#else
return path + ".svg";
#endif
#else
return path + ".svg";
#endif
}
QString YACReader::addExtensionToIconPathInToolbar(const QString &path)
{
return path + "_18x18.svg";

View File

@ -110,7 +110,6 @@ QAction *createSeparator();
QIcon noHighlightedIcon(const QString &path);
void colorize(QImage &img, const QColor &col);
QList<qulonglong> mimeDataToComicsIds(const QMimeData *data);
QString addExtensionToIconPath(const QString &path);
QString addExtensionToIconPathInToolbar(const QString &path);
QAction *actionWithCustomIcon(const QIcon &icon, QAction *action);
QPixmap hdpiPixmap(const QString &file, QSize size);