mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
qss font symbols
This commit is contained in:
parent
7a292b815e
commit
f7f0f696d8
|
@ -21,24 +21,45 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QStyle>
|
||||||
|
|
||||||
// helper function
|
// helper functions
|
||||||
QFont appFont(int pixelSize, int weight) {
|
QFont appFont(int pixelSize, int weight)
|
||||||
|
{
|
||||||
auto font = QFont();
|
auto font = QFont();
|
||||||
font.setPixelSize(pixelSize);
|
font.setPixelSize(pixelSize);
|
||||||
font.setWeight(weight);
|
font.setWeight(weight);
|
||||||
return font;
|
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)
|
QString Style::getStylesheet(const QString &filename)
|
||||||
{
|
{
|
||||||
if (!Settings::getInstance().getUseNativeStyle())
|
if (!Settings::getInstance().getUseNativeStyle())
|
||||||
{
|
{
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
if (file.open(QFile::ReadOnly | QFile::Text))
|
if (file.open(QFile::ReadOnly | QFile::Text))
|
||||||
return file.readAll();
|
return resolve(file.readAll());
|
||||||
else
|
else
|
||||||
qWarning() << "Stylesheet " << filename << " not found";
|
qWarning() << "Style: Stylesheet " << filename << " not found";
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString();
|
return QString();
|
||||||
|
@ -79,6 +100,7 @@ QFont Style::getFont(Style::Font font)
|
||||||
QString Style::resolve(QString qss)
|
QString Style::resolve(QString qss)
|
||||||
{
|
{
|
||||||
static QMap<QString, QString> dict = {
|
static QMap<QString, QString> dict = {
|
||||||
|
// colors
|
||||||
{"@green", getColor(Green).name()},
|
{"@green", getColor(Green).name()},
|
||||||
{"@yellow", getColor(Yellow).name()},
|
{"@yellow", getColor(Yellow).name()},
|
||||||
{"@red", getColor(Red).name()},
|
{"@red", getColor(Red).name()},
|
||||||
|
@ -88,13 +110,37 @@ QString Style::resolve(QString qss)
|
||||||
{"@mediumGreyLight", getColor(MediumGreyLight).name()},
|
{"@mediumGreyLight", getColor(MediumGreyLight).name()},
|
||||||
{"@lightGrey", getColor(LightGrey).name()},
|
{"@lightGrey", getColor(LightGrey).name()},
|
||||||
{"@white", getColor(White).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())
|
for (const QString& key : dict.keys())
|
||||||
{
|
{
|
||||||
qDebug() << key;
|
|
||||||
qss.replace(QRegularExpression(QString("%1\\b").arg(key)), dict[key]);
|
qss.replace(QRegularExpression(QString("%1\\b").arg(key)), dict[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return qss;
|
return qss;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Style::repolish(QWidget *w)
|
||||||
|
{
|
||||||
|
w->style()->unpolish(w);
|
||||||
|
w->style()->polish(w);
|
||||||
|
|
||||||
|
for (QObject* o : w->children())
|
||||||
|
{
|
||||||
|
QWidget* c = qobject_cast<QWidget*>(o);
|
||||||
|
if (c)
|
||||||
|
{
|
||||||
|
c->style()->unpolish(c);
|
||||||
|
c->style()->polish(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
class Style
|
class Style
|
||||||
{
|
{
|
||||||
|
@ -53,6 +54,7 @@ public:
|
||||||
static QColor getColor(ColorPalette entry);
|
static QColor getColor(ColorPalette entry);
|
||||||
static QFont getFont(Font font);
|
static QFont getFont(Font font);
|
||||||
static QString resolve(QString qss);
|
static QString resolve(QString qss);
|
||||||
|
static void repolish(QWidget* w);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Style();
|
Style();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user