|
|
|
@ -92,15 +92,23 @@ QStringList Style::getThemeColorNames()
@@ -92,15 +92,23 @@ QStringList Style::getThemeColorNames()
|
|
|
|
|
QList<QColor> Style::themeColorColors = {QColor(), QColor("#004aa4"), QColor("#97ba00"), |
|
|
|
|
QColor("#c23716"), QColor("#4617b5")}; |
|
|
|
|
|
|
|
|
|
QString Style::getStylesheet(const QString& filename, const QFont& baseFont) |
|
|
|
|
// stylesheet filename, font -> stylesheet
|
|
|
|
|
// QString implicit sharing deduplicates stylesheets rather than constructing a new one each time
|
|
|
|
|
std::map<std::pair<const QString, const QFont>, const QString> Style::stylesheetsCache; |
|
|
|
|
|
|
|
|
|
const QString Style::getStylesheet(const QString& filename, const QFont& baseFont) |
|
|
|
|
{ |
|
|
|
|
QFile file(filename); |
|
|
|
|
if (!file.open(QFile::ReadOnly | QFile::Text)) { |
|
|
|
|
qWarning() << "Stylesheet " << filename << " not found"; |
|
|
|
|
return QString(); |
|
|
|
|
const std::pair<const QString, const QFont> cacheKey(filename, baseFont); |
|
|
|
|
auto it = stylesheetsCache.find(cacheKey); |
|
|
|
|
if (it != stylesheetsCache.end()) |
|
|
|
|
{ |
|
|
|
|
// cache hit
|
|
|
|
|
return it->second; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return resolve(file.readAll(), baseFont); |
|
|
|
|
// cache miss, new styleSheet, read it from file and add to cache
|
|
|
|
|
const QString newStylesheet = resolve(filename, baseFont); |
|
|
|
|
stylesheetsCache.insert(std::make_pair(cacheKey, newStylesheet)); |
|
|
|
|
return newStylesheet; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QColor Style::getColor(Style::ColorPalette entry) |
|
|
|
@ -128,8 +136,15 @@ QFont Style::getFont(Style::Font font)
@@ -128,8 +136,15 @@ QFont Style::getFont(Style::Font font)
|
|
|
|
|
return fonts[font]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString Style::resolve(QString qss, const QFont& baseFont) |
|
|
|
|
const QString Style::resolve(const QString& filename, const QFont& baseFont) |
|
|
|
|
{ |
|
|
|
|
QFile file{filename}; |
|
|
|
|
if (!file.open(QFile::ReadOnly | QFile::Text)) { |
|
|
|
|
qWarning() << "Stylesheet " << filename << " not found"; |
|
|
|
|
return QString(""); |
|
|
|
|
} |
|
|
|
|
QString qss = file.readAll(); |
|
|
|
|
|
|
|
|
|
if (dict.isEmpty()) { |
|
|
|
|
dict = {// colors
|
|
|
|
|
{"@green", Style::getColor(Style::Green).name()}, |
|
|
|
@ -162,7 +177,6 @@ QString Style::resolve(QString qss, const QFont& baseFont)
@@ -162,7 +177,6 @@ QString Style::resolve(QString qss, const QFont& baseFont)
|
|
|
|
|
for (const QString& key : dict.keys()) { |
|
|
|
|
qss.replace(QRegularExpression(QString("%1\\b").arg(key)), dict[key]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return qss; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|