mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Add toolbar and background theming to YACReader
This commit is contained in:
@ -1,7 +1,100 @@
|
||||
#ifndef THEME_H
|
||||
#define THEME_H
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
struct ToolbarThemeTemplates {
|
||||
QString toolbarQSS = "QToolBar { border: none; background: %1; }\n"
|
||||
"QToolBar::separator { background: %2; width: 1px; margin: 5px 4px; }\n"
|
||||
"QToolButton:checked { background-color: %3; }\n"
|
||||
"QToolButton::menu-button {border: none; width: 18px; }\n"
|
||||
"QToolButton::menu-arrow { image: url(%4); width: 8px; height: 8px; }\n";
|
||||
QString menuArrowPath = ":/images/viewer_toolbar/menuArrow.svg";
|
||||
};
|
||||
|
||||
struct ViewerThemeTemplates {
|
||||
QString infoLabelQSS = "QLabel { color : %1; font-size:%2px; }";
|
||||
};
|
||||
|
||||
struct ToolbarTheme {
|
||||
QString toolbarQSS;
|
||||
|
||||
QIcon openAction;
|
||||
QIcon openAction18x18;
|
||||
QIcon openFolderAction;
|
||||
QIcon openFolderAction18x18;
|
||||
QIcon openLatestComicAction;
|
||||
QIcon openLatestComicAction18x18;
|
||||
QIcon saveImageAction;
|
||||
QIcon saveImageAction18x18;
|
||||
QIcon openComicOnTheLeftAction;
|
||||
QIcon openComicOnTheLeftAction18x18;
|
||||
QIcon openComicOnTheRightAction;
|
||||
QIcon openComicOnTheRightAction18x18;
|
||||
QIcon goToPageOnTheLeftAction;
|
||||
QIcon goToPageOnTheLeftAction18x18;
|
||||
QIcon goToPageOnTheRightAction;
|
||||
QIcon goToPageOnTheRightAction18x18;
|
||||
QIcon adjustHeightAction;
|
||||
QIcon adjustHeightAction18x18;
|
||||
QIcon adjustWidthAction;
|
||||
QIcon adjustWidthAction18x18;
|
||||
QIcon leftRotationAction;
|
||||
QIcon leftRotationAction18x18;
|
||||
QIcon rightRotationAction;
|
||||
QIcon rightRotationAction18x18;
|
||||
QIcon doublePageAction;
|
||||
QIcon doublePageAction18x18;
|
||||
QIcon doubleMangaPageAction;
|
||||
QIcon doubleMangaPageAction18x18;
|
||||
QIcon increasePageZoomAction;
|
||||
QIcon increasePageZoomAction18x18;
|
||||
QIcon decreasePageZoomAction;
|
||||
QIcon decreasePageZoomAction18x18;
|
||||
QIcon resetZoomAction;
|
||||
QIcon resetZoomAction18x18;
|
||||
QIcon showZoomSliderlAction;
|
||||
QIcon showZoomSliderlAction18x18;
|
||||
QIcon goToPageAction;
|
||||
QIcon goToPageAction18x18;
|
||||
QIcon optionsAction;
|
||||
QIcon optionsAction18x18;
|
||||
QIcon helpAboutAction;
|
||||
QIcon helpAboutAction18x18;
|
||||
QIcon showMagnifyingGlassAction;
|
||||
QIcon showMagnifyingGlassAction18x18;
|
||||
QIcon setBookmarkAction;
|
||||
QIcon setBookmarkAction18x18;
|
||||
QIcon showBookmarksAction;
|
||||
QIcon showBookmarksAction18x18;
|
||||
QIcon showShorcutsAction;
|
||||
QIcon showShorcutsAction18x18;
|
||||
QIcon showInfoAction;
|
||||
QIcon showInfoAction18x18;
|
||||
QIcon closeAction;
|
||||
QIcon closeAction18x18;
|
||||
QIcon showDictionaryAction;
|
||||
QIcon showDictionaryAction18x18;
|
||||
QIcon adjustToFullSizeAction;
|
||||
QIcon adjustToFullSizeAction18x18;
|
||||
QIcon fitToPageAction;
|
||||
QIcon fitToPageAction18x18;
|
||||
QIcon showFlowAction;
|
||||
QIcon showFlowAction18x18;
|
||||
};
|
||||
|
||||
struct ViewerTheme {
|
||||
QColor defaultBackgroundColor;
|
||||
QColor defaultTextColor;
|
||||
|
||||
QColor infoBackgroundColor;
|
||||
|
||||
QString infoLabelQSS;
|
||||
};
|
||||
|
||||
struct Theme {
|
||||
ToolbarTheme toolbar;
|
||||
ViewerTheme viewer;
|
||||
};
|
||||
|
||||
#endif // THEME_H
|
||||
|
||||
223
YACReader/themes/theme_factory.cpp
Normal file
223
YACReader/themes/theme_factory.cpp
Normal file
@ -0,0 +1,223 @@
|
||||
#include "theme_factory.h"
|
||||
|
||||
#include "icon_utils.h"
|
||||
|
||||
struct ToolbarParams {
|
||||
ToolbarThemeTemplates t;
|
||||
|
||||
QColor iconColor;
|
||||
QColor iconDisabledColor;
|
||||
QColor iconCheckedColor;
|
||||
QColor backgroundColor;
|
||||
QColor separatorColor;
|
||||
QColor checkedButtonColor;
|
||||
QColor menuIndicatorColor;
|
||||
};
|
||||
|
||||
struct ViewerParams {
|
||||
ViewerThemeTemplates t;
|
||||
|
||||
QColor defaultBackgroundColor;
|
||||
QColor defaultTextColor;
|
||||
QColor infoBackgroundColor;
|
||||
QColor infoTextColor;
|
||||
};
|
||||
|
||||
struct ThemeParams {
|
||||
QString themeName;
|
||||
|
||||
ToolbarParams toolbarParams;
|
||||
ViewerParams viewerParams;
|
||||
};
|
||||
|
||||
void setToolbarIconPair(QIcon &icon,
|
||||
QIcon &icon18,
|
||||
const QString &basePath,
|
||||
const QColor &iconColor,
|
||||
const QColor &disabledColor,
|
||||
const QColor &checkedColor,
|
||||
const QString &themeName)
|
||||
{
|
||||
QString path18 = basePath;
|
||||
if (path18.endsWith(".svg"))
|
||||
path18.insert(path18.size() - 4, "_18x18");
|
||||
else
|
||||
path18.append("_18x18");
|
||||
|
||||
// Normal
|
||||
const QString normalPath = recoloredSvgToThemeFile(basePath, iconColor, themeName);
|
||||
const QString normalPath18 = recoloredSvgToThemeFile(path18, iconColor, themeName);
|
||||
// Disabled
|
||||
const QString disabledPath = recoloredSvgToThemeFile(basePath, disabledColor, themeName, "_disabled");
|
||||
const QString disabledPath18 = recoloredSvgToThemeFile(path18, disabledColor, themeName, "_disabled");
|
||||
// Checked (On state)
|
||||
const QString checkedPath = recoloredSvgToThemeFile(basePath, checkedColor, themeName, "_checked");
|
||||
const QString checkedPath18 = recoloredSvgToThemeFile(path18, checkedColor, themeName, "_checked");
|
||||
|
||||
icon.addFile(normalPath, QSize(), QIcon::Normal, QIcon::Off);
|
||||
icon.addFile(disabledPath, QSize(), QIcon::Disabled, QIcon::Off);
|
||||
icon.addFile(checkedPath, QSize(), QIcon::Normal, QIcon::On);
|
||||
icon.addFile(disabledPath, QSize(), QIcon::Disabled, QIcon::On);
|
||||
|
||||
icon18.addFile(normalPath18, QSize(), QIcon::Normal, QIcon::Off);
|
||||
icon18.addFile(disabledPath18, QSize(), QIcon::Disabled, QIcon::Off);
|
||||
icon18.addFile(checkedPath18, QSize(), QIcon::Normal, QIcon::On);
|
||||
icon18.addFile(disabledPath18, QSize(), QIcon::Disabled, QIcon::On);
|
||||
}
|
||||
|
||||
Theme makeTheme(const ThemeParams ¶ms)
|
||||
{
|
||||
Theme theme;
|
||||
|
||||
// Toolbar & actions
|
||||
theme.toolbar.toolbarQSS = params.toolbarParams.t.toolbarQSS.arg(params.toolbarParams.backgroundColor.name(), params.toolbarParams.separatorColor.name(), params.toolbarParams.checkedButtonColor.name(), recoloredSvgToThemeFile(params.toolbarParams.t.menuArrowPath, params.toolbarParams.menuIndicatorColor, params.themeName));
|
||||
|
||||
auto setToolbarIconPairT = [&](QIcon &icon, QIcon &icon18, const QString &basePath) {
|
||||
setToolbarIconPair(icon, icon18, basePath, params.toolbarParams.iconColor, params.toolbarParams.iconDisabledColor, params.toolbarParams.iconCheckedColor, params.themeName);
|
||||
};
|
||||
|
||||
setToolbarIconPairT(theme.toolbar.openAction, theme.toolbar.openAction18x18, ":/images/viewer_toolbar/open.svg");
|
||||
setToolbarIconPairT(theme.toolbar.openFolderAction, theme.toolbar.openFolderAction18x18, ":/images/viewer_toolbar/openFolder.svg");
|
||||
setToolbarIconPairT(theme.toolbar.openLatestComicAction, theme.toolbar.openLatestComicAction18x18, ":/images/viewer_toolbar/openNext.svg");
|
||||
setToolbarIconPairT(theme.toolbar.saveImageAction, theme.toolbar.saveImageAction18x18, ":/images/viewer_toolbar/save.svg");
|
||||
setToolbarIconPairT(theme.toolbar.openComicOnTheLeftAction, theme.toolbar.openComicOnTheLeftAction18x18, ":/images/viewer_toolbar/openPrevious.svg");
|
||||
setToolbarIconPairT(theme.toolbar.openComicOnTheRightAction, theme.toolbar.openComicOnTheRightAction18x18, ":/images/viewer_toolbar/openNext.svg");
|
||||
setToolbarIconPairT(theme.toolbar.goToPageOnTheLeftAction, theme.toolbar.goToPageOnTheLeftAction18x18, ":/images/viewer_toolbar/previous.svg");
|
||||
setToolbarIconPairT(theme.toolbar.goToPageOnTheRightAction, theme.toolbar.goToPageOnTheRightAction18x18, ":/images/viewer_toolbar/next.svg");
|
||||
setToolbarIconPairT(theme.toolbar.adjustHeightAction, theme.toolbar.adjustHeightAction18x18, ":/images/viewer_toolbar/toHeight.svg");
|
||||
setToolbarIconPairT(theme.toolbar.adjustWidthAction, theme.toolbar.adjustWidthAction18x18, ":/images/viewer_toolbar/toWidth.svg");
|
||||
setToolbarIconPairT(theme.toolbar.leftRotationAction, theme.toolbar.leftRotationAction18x18, ":/images/viewer_toolbar/rotateL.svg");
|
||||
setToolbarIconPairT(theme.toolbar.rightRotationAction, theme.toolbar.rightRotationAction18x18, ":/images/viewer_toolbar/rotateR.svg");
|
||||
setToolbarIconPairT(theme.toolbar.doublePageAction, theme.toolbar.doublePageAction18x18, ":/images/viewer_toolbar/doublePage.svg");
|
||||
setToolbarIconPairT(theme.toolbar.doubleMangaPageAction, theme.toolbar.doubleMangaPageAction18x18, ":/images/viewer_toolbar/doubleMangaPage.svg");
|
||||
setToolbarIconPairT(theme.toolbar.showZoomSliderlAction, theme.toolbar.showZoomSliderlAction18x18, ":/images/viewer_toolbar/zoom.svg");
|
||||
setToolbarIconPairT(theme.toolbar.goToPageAction, theme.toolbar.goToPageAction18x18, ":/images/viewer_toolbar/goto.svg");
|
||||
setToolbarIconPairT(theme.toolbar.optionsAction, theme.toolbar.optionsAction18x18, ":/images/viewer_toolbar/options.svg");
|
||||
setToolbarIconPairT(theme.toolbar.helpAboutAction, theme.toolbar.helpAboutAction18x18, ":/images/viewer_toolbar/help.svg");
|
||||
setToolbarIconPairT(theme.toolbar.showMagnifyingGlassAction, theme.toolbar.showMagnifyingGlassAction18x18, ":/images/viewer_toolbar/magnifyingGlass.svg");
|
||||
setToolbarIconPairT(theme.toolbar.setBookmarkAction, theme.toolbar.setBookmarkAction18x18, ":/images/viewer_toolbar/bookmark.svg");
|
||||
setToolbarIconPairT(theme.toolbar.showBookmarksAction, theme.toolbar.showBookmarksAction18x18, ":/images/viewer_toolbar/showBookmarks.svg");
|
||||
setToolbarIconPairT(theme.toolbar.showShorcutsAction, theme.toolbar.showShorcutsAction18x18, ":/images/viewer_toolbar/shortcuts.svg");
|
||||
setToolbarIconPairT(theme.toolbar.showInfoAction, theme.toolbar.showInfoAction18x18, ":/images/viewer_toolbar/info.svg");
|
||||
setToolbarIconPairT(theme.toolbar.closeAction, theme.toolbar.closeAction18x18, ":/images/viewer_toolbar/close.svg");
|
||||
setToolbarIconPairT(theme.toolbar.showDictionaryAction, theme.toolbar.showDictionaryAction18x18, ":/images/viewer_toolbar/translator.svg");
|
||||
setToolbarIconPairT(theme.toolbar.adjustToFullSizeAction, theme.toolbar.adjustToFullSizeAction18x18, ":/images/viewer_toolbar/full.svg");
|
||||
setToolbarIconPairT(theme.toolbar.fitToPageAction, theme.toolbar.fitToPageAction18x18, ":/images/viewer_toolbar/fitToPage.svg");
|
||||
setToolbarIconPairT(theme.toolbar.showFlowAction, theme.toolbar.showFlowAction18x18, ":/images/viewer_toolbar/flow.svg");
|
||||
// end Toolbar & actions
|
||||
|
||||
// Viewer
|
||||
theme.viewer.defaultBackgroundColor = params.viewerParams.defaultBackgroundColor;
|
||||
theme.viewer.defaultTextColor = params.viewerParams.defaultTextColor;
|
||||
theme.viewer.infoBackgroundColor = params.viewerParams.infoBackgroundColor;
|
||||
theme.viewer.infoLabelQSS = params.viewerParams.t.infoLabelQSS.arg(params.viewerParams.infoTextColor.name());
|
||||
// end Viewer
|
||||
|
||||
return theme;
|
||||
}
|
||||
|
||||
ThemeParams classicThemeParams();
|
||||
ThemeParams lightThemeParams();
|
||||
ThemeParams darkThemeParams();
|
||||
|
||||
Theme makeTheme(ThemeId themeId)
|
||||
{
|
||||
switch (themeId) {
|
||||
case ThemeId::Classic:
|
||||
return makeTheme(classicThemeParams());
|
||||
case ThemeId::Light:
|
||||
return makeTheme(lightThemeParams());
|
||||
case ThemeId::Dark:
|
||||
return makeTheme(darkThemeParams());
|
||||
}
|
||||
}
|
||||
|
||||
ThemeParams classicThemeParams()
|
||||
{
|
||||
ThemeParams params;
|
||||
params.themeName = "classic";
|
||||
|
||||
ToolbarParams toolbarParams;
|
||||
toolbarParams.iconColor = QColor(0x404040);
|
||||
toolbarParams.iconDisabledColor = QColor(0x858585);
|
||||
toolbarParams.iconCheckedColor = QColor(0x5A5A5A);
|
||||
toolbarParams.backgroundColor = QColor(0xF3F3F3);
|
||||
toolbarParams.separatorColor = QColor(0xCCCCCC);
|
||||
toolbarParams.checkedButtonColor = QColor(0xCCCCCC);
|
||||
toolbarParams.menuIndicatorColor = QColor(0x404040);
|
||||
|
||||
params.toolbarParams = toolbarParams;
|
||||
|
||||
ViewerParams viewerParams;
|
||||
viewerParams.defaultBackgroundColor = QColor(0x282828);
|
||||
viewerParams.defaultTextColor = Qt::white;
|
||||
viewerParams.infoBackgroundColor = QColor::fromRgba(0xBB000000);
|
||||
viewerParams.infoTextColor = Qt::white;
|
||||
viewerParams.t = ViewerThemeTemplates();
|
||||
|
||||
params.viewerParams = viewerParams;
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
ThemeParams lightThemeParams()
|
||||
{
|
||||
ThemeParams params;
|
||||
params.themeName = "light";
|
||||
|
||||
ToolbarParams toolbarParams;
|
||||
toolbarParams.iconColor = QColor(0x404040);
|
||||
toolbarParams.iconDisabledColor = QColor(0xB0B0B0);
|
||||
toolbarParams.iconCheckedColor = QColor(0x5A5A5A);
|
||||
toolbarParams.backgroundColor = QColor(0xF3F3F3);
|
||||
toolbarParams.separatorColor = QColor(0xCCCCCC);
|
||||
toolbarParams.checkedButtonColor = QColor(0xCCCCCC);
|
||||
toolbarParams.menuIndicatorColor = QColor(0x404040);
|
||||
|
||||
params.toolbarParams = toolbarParams;
|
||||
|
||||
ViewerParams viewerParams;
|
||||
viewerParams.defaultBackgroundColor = QColor(0xF6F6F6);
|
||||
viewerParams.defaultTextColor = QColor(0x202020);
|
||||
viewerParams.infoBackgroundColor = QColor::fromRgba(0xBBFFFFFF);
|
||||
viewerParams.infoTextColor = QColor(0x404040);
|
||||
viewerParams.t = ViewerThemeTemplates();
|
||||
|
||||
params.viewerParams = viewerParams;
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
ThemeParams darkThemeParams()
|
||||
{
|
||||
ThemeParams params;
|
||||
params.themeName = "dark";
|
||||
|
||||
ToolbarParams toolbarParams;
|
||||
toolbarParams.iconColor = QColor(0xCCCCCC);
|
||||
toolbarParams.iconDisabledColor = QColor(0x444444);
|
||||
toolbarParams.iconCheckedColor = QColor(0xDADADA);
|
||||
toolbarParams.backgroundColor = QColor(0x202020);
|
||||
toolbarParams.separatorColor = QColor(0x444444);
|
||||
toolbarParams.checkedButtonColor = QColor(0x3A3A3A);
|
||||
toolbarParams.menuIndicatorColor = QColor(0xCCCCCC);
|
||||
|
||||
params.toolbarParams = toolbarParams;
|
||||
|
||||
ViewerParams viewerParams;
|
||||
viewerParams.defaultBackgroundColor = QColor(40, 40, 40);
|
||||
viewerParams.defaultTextColor = Qt::white;
|
||||
viewerParams.infoBackgroundColor = QColor::fromRgba(0xBB000000);
|
||||
viewerParams.infoTextColor = QColor(0xB0B0B0);
|
||||
viewerParams.t = ViewerThemeTemplates();
|
||||
|
||||
params.viewerParams = viewerParams;
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
// TODO
|
||||
ThemeParams paramsFromFile(const QString &filePath)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
9
YACReader/themes/theme_factory.h
Normal file
9
YACReader/themes/theme_factory.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef THEME_FACTORY_H
|
||||
#define THEME_FACTORY_H
|
||||
|
||||
#include "theme.h"
|
||||
#include "theme_id.h"
|
||||
|
||||
Theme makeTheme(ThemeId themeId);
|
||||
|
||||
#endif // THEME_FACTORY_H
|
||||
@ -2,3 +2,6 @@ INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/theme.h \
|
||||
$$PWD/theme_factory.h
|
||||
SOURCES += \
|
||||
$$PWD/theme_factory.cpp
|
||||
|
||||
Reference in New Issue
Block a user