Пример #1
0
QString Style::resolve(QString qss)
{
    static QMap<QString, QString> dict = {
        // colors
        {"@green", getColor(Green).name()},
        {"@yellow", getColor(Yellow).name()},
        {"@red", getColor(Red).name()},
        {"@black", getColor(Black).name()},
        {"@darkGrey", getColor(DarkGrey).name()},
        {"@mediumGrey", getColor(MediumGrey).name()},
        {"@mediumGreyLight", getColor(MediumGreyLight).name()},
        {"@lightGrey", getColor(LightGrey).name()},
        {"@white", getColor(White).name()},

        // fonts
        {"@extraBig", qssifyFont(getFont(ExtraBig))},
        {"@big", qssifyFont(getFont(Big))},
        {"@bigBold", qssifyFont(getFont(BigBold))},
        {"@medium", qssifyFont(getFont(Medium))},
        {"@mediumBold", qssifyFont(getFont(MediumBold))},
        {"@small", qssifyFont(getFont(Small))},
        {"@smallLight", qssifyFont(getFont(SmallLight))},
    };

    for (const QString& key : dict.keys())
    {
        qss.replace(QRegularExpression(QString("%1\\b").arg(key)), dict[key]);
    }

    return qss;
}
Пример #2
0
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()},
                {"@yellow", Style::getColor(Style::Yellow).name()},
                {"@red", Style::getColor(Style::Red).name()},
                {"@black", Style::getColor(Style::Black).name()},
                {"@darkGrey", Style::getColor(Style::DarkGrey).name()},
                {"@mediumGrey", Style::getColor(Style::MediumGrey).name()},
                {"@mediumGreyLight", Style::getColor(Style::MediumGreyLight).name()},
                {"@lightGrey", Style::getColor(Style::LightGrey).name()},
                {"@white", Style::getColor(Style::White).name()},
                {"@orange", Style::getColor(Style::Orange).name()},
                {"@themeDark", Style::getColor(Style::ThemeDark).name()},
                {"@themeMediumDark", Style::getColor(Style::ThemeMediumDark).name()},
                {"@themeMedium", Style::getColor(Style::ThemeMedium).name()},
                {"@themeLight", Style::getColor(Style::ThemeLight).name()},

                // fonts
                {"@baseFont",
                 QString::fromUtf8("'%1' %2px").arg(baseFont.family()).arg(QFontInfo(baseFont).pixelSize())},
                {"@extraBig", qssifyFont(Style::getFont(Style::ExtraBig))},
                {"@big", qssifyFont(Style::getFont(Style::Big))},
                {"@bigBold", qssifyFont(Style::getFont(Style::BigBold))},
                {"@medium", qssifyFont(Style::getFont(Style::Medium))},
                {"@mediumBold", qssifyFont(Style::getFont(Style::MediumBold))},
                {"@small", qssifyFont(Style::getFont(Style::Small))},
                {"@smallLight", qssifyFont(Style::getFont(Style::SmallLight))}};
    }

    for (const QString& key : dict.keys()) {
        qss.replace(QRegularExpression(QString("%1\\b").arg(key)), dict[key]);
    }
    return qss;
}
Пример #3
0
QString Style::resolve(QString qss)
{
    if (dict.isEmpty())
    {
        dict = {
            // colors
            {"@green", Style::getColor(Style::Green).name()},
            {"@yellow", Style::getColor(Style::Yellow).name()},
            {"@red", Style::getColor(Style::Red).name()},
            {"@black", Style::getColor(Style::Black).name()},
            {"@darkGrey", Style::getColor(Style::DarkGrey).name()},
            {"@mediumGrey", Style::getColor(Style::MediumGrey).name()},
            {"@mediumGreyLight", Style::getColor(Style::MediumGreyLight).name()},
            {"@lightGrey", Style::getColor(Style::LightGrey).name()},
            {"@white", Style::getColor(Style::White).name()},
            {"@orange", Style::getColor(Style::Orange).name()},
            {"@themeDark", Style::getColor(Style::ThemeDark).name()},
            {"@themeMediumDark", Style::getColor(Style::ThemeMediumDark).name()},
            {"@themeMedium", Style::getColor(Style::ThemeMedium).name()},
            {"@themeLight", Style::getColor(Style::ThemeLight).name()},

            // fonts
            {"@extraBig", qssifyFont(Style::getFont(Style::ExtraBig))},
            {"@big", qssifyFont(Style::getFont(Style::Big))},
            {"@bigBold", qssifyFont(Style::getFont(Style::BigBold))},
            {"@medium", qssifyFont(Style::getFont(Style::Medium))},
            {"@mediumBold", qssifyFont(Style::getFont(Style::MediumBold))},
            {"@small", qssifyFont(Style::getFont(Style::Small))},
            {"@smallLight", qssifyFont(Style::getFont(Style::SmallLight))},
        };
    }

    for (const QString& key : dict.keys())
    {
        qss.replace(QRegularExpression(QString("%1\\b").arg(key)), dict[key]);
    }

    return qss;
}