16 #include <QApplication>
22 #include <QStringList>
25 #include "../../util/btassert.h"
26 #include "../../util/directory.h"
27 #include "../../backend/managers/cdisplaytemplatemgr.h"
34 auto const & palette = qApp->palette();
35 return palette.color(QPalette::WindowText).value()
36 > palette.color(QPalette::Window).value();
39 using ColorMaps = std::map<QString, std::map<QString, QString> >;
43 QDir::Filters
const readableFileFilter(QDir::Files | QDir::Readable);
44 QStringList
const cssFilter(QStringLiteral(
"*.css"));
48 auto const loadColorMap =
50 QFileInfo
const cssInfo(filePath);
51 static auto const cMapPathTemplate(
52 QStringLiteral(
"%1/%2.cmap"));
53 auto cMapPath(cMapPathTemplate.arg(cssInfo.path())
54 .arg(cssInfo.completeBaseName()));
55 QFileInfo
const cMapInfo(cMapPath);
56 auto fileName(cssInfo.fileName());
59 std::map<QString, QString> colorMap;
60 auto const p(qApp->palette());
62 colorMap.emplace(QStringLiteral(
"FOREGROUND_COLOR"),
63 p.color(QPalette::WindowText).name());
64 colorMap.emplace(QStringLiteral(
"BACKGROUND_COLOR"),
65 p.color(QPalette::Base).name());
66 colorMap.emplace(QStringLiteral(
"HIGHLIGHT"),
67 QStringLiteral(
"#ffff00"));
68 colorMap.emplace(QStringLiteral(
"BACKGROUND_HIGHLIGHT"),
69 QStringLiteral(
"#444466"));
70 colorMap.emplace(QStringLiteral(
"CROSSREF_COLOR"),
71 QStringLiteral(
"#aac2ff"));
72 colorMap.emplace(QStringLiteral(
"JESUS_WORDS_COLOR"),
73 QStringLiteral(
"#ff0000"));
75 colorMap.emplace(QStringLiteral(
"FOREGROUND_COLOR"),
76 p.color(QPalette::WindowText).name());
77 colorMap.emplace(QStringLiteral(
"BACKGROUND_COLOR"),
78 p.color(QPalette::Base).name());
79 colorMap.emplace(QStringLiteral(
"HIGHLIGHT"),
80 QStringLiteral(
"#ffff00"));
81 colorMap.emplace(QStringLiteral(
"BACKGROUND_HIGHLIGHT"),
82 QStringLiteral(
"#ddddff"));
83 colorMap.emplace(QStringLiteral(
"CROSSREF_COLOR"),
84 QStringLiteral(
"#1414ff"));
85 colorMap.emplace(QStringLiteral(
"JESUS_WORDS_COLOR"),
86 QStringLiteral(
"#ff0000"));
89 if (cMapInfo.exists()) {
90 QSettings cMapSettings(cMapPath, QSettings::IniFormat);
91 static auto const dark = QStringLiteral(
"dark");
92 static auto const light = QStringLiteral(
"light");
93 cMapSettings.beginGroup(
darkMode() ? dark : light);
94 for (
auto const & colorKey : cMapSettings.childKeys())
95 colorMap[colorKey] = cMapSettings.value(colorKey).toString();
97 colorMaps[std::move(fileName)] = std::move(colorMap);
102 for (
auto const & file : td.entryList(cssFilter, readableFileFilter))
103 loadColorMap(QStringLiteral(
"%1/%2").arg(td.canonicalPath(), file));
107 for (
auto const & file : utd.entryList(cssFilter, readableFileFilter))
108 loadColorMap(QStringLiteral(
"%1/%2").arg(utd.canonicalPath(), file));
122 auto const mapIt(maps.find(templateName));
124 auto const valueIt(mapIt->second.find(pattern));
125 BT_ASSERT(valueIt != mapIt->second.end());
127 return valueIt->second;
140 auto const mapsIt = maps.find(templateName);
142 for (
auto const & [key, value] : mapsIt->second)
143 content.replace(QStringLiteral(
"#%1#").arg(key), value);
static QString activeTemplateName()
ColorMaps createColorMaps()
std::map< QString, std::map< QString, QString > > ColorMaps
QString getColorByPattern(QString const &pattern, QString const &templateName)
QString getForegroundColor()
QString getBackgroundColor()
QString replaceColors(QString content)
QString getBackgroundHighlightColor()
QString getCrossRefColor()
const QDir & getDisplayTemplatesDir()
const QDir & getUserDisplayTemplatesDir()