Make help/about dialog themable

Just the hardcoded colors used, the rest of the dialog will be themed by Qt.
This commit is contained in:
luisangelsm
2026-01-25 10:25:00 +01:00
parent 07718e50db
commit 6b3fcc63d3
8 changed files with 94 additions and 6 deletions

View File

@ -3,6 +3,8 @@
#include <QtGui>
#include "help_about_dialog_theme.h"
struct ToolbarThemeTemplates {
QString toolbarQSS = "QToolBar { border: none; background: %1; }\n"
"QToolBar::separator { background: %2; width: 1px; margin: 5px 4px; }\n"
@ -128,6 +130,7 @@ struct Theme {
ToolbarTheme toolbar;
ViewerTheme viewer;
GoToFlowWidgetTheme goToFlowWidget;
HelpAboutDialogTheme helpAboutDialog;
};
#endif // THEME_H

View File

@ -45,6 +45,7 @@ struct ThemeParams {
ToolbarParams toolbarParams;
ViewerParams viewerParams;
GoToFlowWidgetParams goToFlowWidgetParams;
HelpAboutDialogTheme helpAboutDialogParams;
};
void setToolbarIconPair(QIcon &icon,
@ -152,6 +153,10 @@ Theme makeTheme(const ThemeParams &params)
theme.goToFlowWidget.goToIcon = QIcon(goToIconPath);
// end GoToFlowWidget
// HelpAboutDialog
theme.helpAboutDialog = params.helpAboutDialogParams;
// end HelpAboutDialog
return theme;
}
@ -212,6 +217,9 @@ ThemeParams classicThemeParams()
params.goToFlowWidgetParams = goToFlowWidgetParams;
params.helpAboutDialogParams.headingColor = QColor(0x302f2d);
params.helpAboutDialogParams.linkColor = QColor(0xC19441);
return params;
}
@ -256,6 +264,9 @@ ThemeParams lightThemeParams()
params.goToFlowWidgetParams = goToFlowWidgetParams;
params.helpAboutDialogParams.headingColor = QColor(0x302f2d);
params.helpAboutDialogParams.linkColor = QColor(0xC19441);
return params;
}
@ -300,6 +311,9 @@ ThemeParams darkThemeParams()
params.goToFlowWidgetParams = goToFlowWidgetParams;
params.helpAboutDialogParams.headingColor = QColor(0xE0E0E0);
params.helpAboutDialogParams.linkColor = QColor(0xD4A84B);
return params;
}

View File

@ -4,6 +4,7 @@
#include <QtGui>
#include "yacreader_icon.h"
#include "help_about_dialog_theme.h"
struct ComicVineThemeTemplates {
QString defaultLabelQSS = "QLabel {color:%1; font-size:12px;font-family:Arial;}";
@ -130,6 +131,7 @@ struct ComicVineTheme {
struct Theme {
ComicFlowColors comicFlow;
ComicVineTheme comicVine;
HelpAboutDialogTheme helpAboutDialog;
};
#endif // THEME_H

View File

@ -54,6 +54,7 @@ struct ThemeParams {
ComicFlowColors comicFlowColors;
ComicVineParams comicVineParams;
HelpAboutDialogTheme helpAboutDialogParams;
};
Theme makeTheme(const ThemeParams &params)
@ -115,6 +116,10 @@ Theme makeTheme(const ThemeParams &params)
theme.comicVine.rowUpIcon = { QIcon(recolor(t.rowUpIcon, cv.rowIconColor)), t.rowIconSize };
theme.comicVine.rowDownIcon = { QIcon(recolor(t.rowDownIcon, cv.rowIconColor)), t.rowIconSize };
// HelpAboutDialog
theme.helpAboutDialog = params.helpAboutDialogParams;
// end HelpAboutDialog
return theme;
}
@ -194,6 +199,9 @@ ThemeParams classicThemeParams()
params.comicFlowColors = cf;
params.comicVineParams = cv;
params.helpAboutDialogParams.headingColor = QColor(0x302f2d);
params.helpAboutDialogParams.linkColor = QColor(0xC19441);
return params;
}
@ -255,6 +263,9 @@ ThemeParams lightThemeParams()
params.comicFlowColors = cf;
params.comicVineParams = cv;
params.helpAboutDialogParams.headingColor = QColor(0x302f2d);
params.helpAboutDialogParams.linkColor = QColor(0xC19441);
return params;
}
@ -316,5 +327,8 @@ ThemeParams darkThemeParams()
params.comicFlowColors = cf;
params.comicVineParams = cv;
params.helpAboutDialogParams.headingColor = QColor(0xE0E0E0);
params.helpAboutDialogParams.linkColor = QColor(0xD4A84B);
return params;
}

View File

@ -0,0 +1,11 @@
#ifndef HELP_ABOUT_DIALOG_THEME_H
#define HELP_ABOUT_DIALOG_THEME_H
#include <QColor>
struct HelpAboutDialogTheme {
QColor headingColor;
QColor linkColor;
};
#endif // HELP_ABOUT_DIALOG_THEME_H

View File

@ -1,4 +1,5 @@
INCLUDEPATH += $$PWD
INCLUDEPATH += $$PWD \
$$PWD/shared
HEADERS += \
$$PWD/icon_utils.h \
@ -6,6 +7,7 @@ HEADERS += \
$$PWD/theme_manager.h \
$$PWD/themable.h \
$$PWD/yacreader_icon.h \
$$PWD/shared/help_about_dialog_theme.h \
SOURCES += \

View File

@ -50,6 +50,8 @@ HelpAboutDialog::HelpAboutDialog(QWidget *parent)
resize(500, heightDesktopResolution * 0.83);
loadSystemInfo();
initTheme(this);
}
HelpAboutDialog::HelpAboutDialog(const QString &pathAbout, const QString &pathHelp, QWidget *parent)
@ -67,14 +69,14 @@ void HelpAboutDialog::loadAboutInformation(const QString &path)
buildNumber = BUILD_NUMBER;
#endif
aboutText->setHtml(fileToString(path).arg(VERSION, buildNumber));
aboutText->moveCursor(QTextCursor::Start);
aboutHtmlContent = fileToString(path).arg(VERSION, buildNumber);
applyHtmlTheme();
}
void HelpAboutDialog::loadHelp(const QString &path)
{
helpText->setHtml(fileToString(path));
helpText->moveCursor(QTextCursor::Start);
helpHtmlContent = fileToString(path);
applyHtmlTheme();
}
QString HelpAboutDialog::fileToString(const QString &path)
@ -104,3 +106,34 @@ void HelpAboutDialog::loadSystemInfo()
systemInfoText->setText(text);
}
void HelpAboutDialog::applyTheme(const Theme &theme)
{
Q_UNUSED(theme)
applyHtmlTheme();
}
void HelpAboutDialog::applyHtmlTheme()
{
auto helpTheme = theme.helpAboutDialog;
// Original colors in the HTML CSS
const QString originalHeadingColor = "#302f2d";
const QString originalLinkColor = "#C19441";
if (!aboutHtmlContent.isEmpty()) {
QString themedAbout = aboutHtmlContent;
themedAbout.replace(originalHeadingColor, helpTheme.headingColor.name(), Qt::CaseInsensitive);
themedAbout.replace(originalLinkColor, helpTheme.linkColor.name(), Qt::CaseInsensitive);
aboutText->setHtml(themedAbout);
aboutText->moveCursor(QTextCursor::Start);
}
if (!helpHtmlContent.isEmpty()) {
QString themedHelp = helpHtmlContent;
themedHelp.replace(originalHeadingColor, helpTheme.headingColor.name(), Qt::CaseInsensitive);
themedHelp.replace(originalLinkColor, helpTheme.linkColor.name(), Qt::CaseInsensitive);
helpText->setHtml(themedHelp);
helpText->moveCursor(QTextCursor::Start);
}
}

View File

@ -3,12 +3,17 @@
#include <QDialog>
#include "themable.h"
class QTabWidget;
class QTextBrowser;
class HelpAboutDialog : public QDialog
class HelpAboutDialog : public QDialog, protected Themable
{
Q_OBJECT
protected:
void applyTheme(const Theme &theme) override;
public:
HelpAboutDialog(QWidget *parent = 0);
HelpAboutDialog(const QString &pathAbout, const QString &pathHelp, QWidget *parent = 0);
@ -23,6 +28,10 @@ private:
QTextBrowser *systemInfoText;
QString fileToString(const QString &path);
void loadSystemInfo();
void applyHtmlTheme();
QString aboutHtmlContent;
QString helpHtmlContent;
};
#endif // HELP_ABOUT_DIALOG_H