diff --git a/misc/style.cpp b/misc/style.cpp index 6b4322e70..fb8378579 100644 --- a/misc/style.cpp +++ b/misc/style.cpp @@ -21,24 +21,45 @@ #include #include #include +#include +#include -// helper function -QFont appFont(int pixelSize, int weight) { +// helper functions +QFont appFont(int pixelSize, int weight) +{ auto font = QFont(); font.setPixelSize(pixelSize); font.setWeight(weight); return font; } +QString cssifyWeight(int weight) +{ + QString weightStr = "normal"; + if (weight == QFont::Bold) + weightStr = "bold"; + if (weight == QFont::Light) + weightStr = "lighter"; + + return QString("%1").arg(weightStr); +} + +QString cssifyFont(QFont font) +{ + return QString("%1px %2") + .arg(font.pixelSize()) + .arg(font.weight()); +} + QString Style::getStylesheet(const QString &filename) { if (!Settings::getInstance().getUseNativeStyle()) { QFile file(filename); if (file.open(QFile::ReadOnly | QFile::Text)) - return file.readAll(); + return resolve(file.readAll()); else - qWarning() << "Stylesheet " << filename << " not found"; + qWarning() << "Style: Stylesheet " << filename << " not found"; } return QString(); @@ -79,6 +100,7 @@ QFont Style::getFont(Style::Font font) QString Style::resolve(QString qss) { static QMap dict = { + // colors {"@green", getColor(Green).name()}, {"@yellow", getColor(Yellow).name()}, {"@red", getColor(Red).name()}, @@ -88,13 +110,37 @@ QString Style::resolve(QString qss) {"@mediumGreyLight", getColor(MediumGreyLight).name()}, {"@lightGrey", getColor(LightGrey).name()}, {"@white", getColor(White).name()}, + + // fonts + {"@extraBig", cssifyFont(getFont(ExtraBig))}, + {"@big", cssifyFont(getFont(Big))}, + {"@bigBold", cssifyFont(getFont(BigBold))}, + {"@medium", cssifyFont(getFont(Medium))}, + {"@mediumBold", cssifyFont(getFont(MediumBold))}, + {"@small", cssifyFont(getFont(Small))}, + {"@smallLight", cssifyFont(getFont(SmallLight))}, }; for (const QString& key : dict.keys()) { - qDebug() << key; qss.replace(QRegularExpression(QString("%1\\b").arg(key)), dict[key]); } return qss; } + +void Style::repolish(QWidget *w) +{ + w->style()->unpolish(w); + w->style()->polish(w); + + for (QObject* o : w->children()) + { + QWidget* c = qobject_cast(o); + if (c) + { + c->style()->unpolish(c); + c->style()->polish(c); + } + } +} diff --git a/misc/style.h b/misc/style.h index eba949325..35c0b7e98 100644 --- a/misc/style.h +++ b/misc/style.h @@ -21,6 +21,7 @@ #include class QString; +class QWidget; class Style { @@ -53,6 +54,7 @@ public: static QColor getColor(ColorPalette entry); static QFont getFont(Font font); static QString resolve(QString qss); + static void repolish(QWidget* w); private: Style();