mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
Ref T30, allow to set font as string (stylesheet string)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
3780bc18e0
commit
0c7ead7977
@@ -557,6 +557,11 @@ namespace BlackGui
|
||||
return m_styleSheetUtility.updateFont(fontFamily, fontSize, fontStyle, fontWeight, fontColor);
|
||||
}
|
||||
|
||||
bool CGuiApplication::updateFont(const QString &qss)
|
||||
{
|
||||
return m_styleSheetUtility.updateFont(qss);
|
||||
}
|
||||
|
||||
bool CGuiApplication::resetFont()
|
||||
{
|
||||
return m_styleSheetUtility.resetFont();
|
||||
|
||||
@@ -156,6 +156,9 @@ namespace BlackGui
|
||||
//! Update the fonts
|
||||
bool updateFont(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor);
|
||||
|
||||
//! Update the fonts
|
||||
bool updateFont(const QString &qss);
|
||||
|
||||
//! Reset the font to default
|
||||
bool resetFont();
|
||||
|
||||
|
||||
@@ -97,6 +97,14 @@ namespace BlackGui
|
||||
return w.append(" ").append(s);
|
||||
}
|
||||
|
||||
QString CStyleSheetUtility::asStylesheet(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor)
|
||||
{
|
||||
static const QString indent(" ");
|
||||
static const QString lf("\n");
|
||||
static QString fontStyleSheet("%1font-family: \"%3\";%2%1font-size: %4;%2%1font-style: %5;%2%1font-weight: %6;%2%1color: %7;%2");
|
||||
return fontStyleSheet.arg(indent, lf, fontFamily, fontSize, fontStyle, fontWeight, fontColor);
|
||||
}
|
||||
|
||||
QString CStyleSheetUtility::fontColor() const
|
||||
{
|
||||
const QString s = this->style(fileNameFonts()).toLower();
|
||||
@@ -205,24 +213,22 @@ namespace BlackGui
|
||||
|
||||
bool CStyleSheetUtility::updateFont(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor)
|
||||
{
|
||||
static const QString indent(" ");
|
||||
QString fontStyleSheet;
|
||||
fontStyleSheet.append(indent).append("font-family: \"").append(fontFamily).append("\";\n");
|
||||
fontStyleSheet.append(indent).append("font-size: ").append(fontSize).append(";\n");
|
||||
fontStyleSheet.append(indent).append("font-style: ").append(fontStyle).append(";\n");
|
||||
fontStyleSheet.append(indent).append("font-weight: ").append(fontWeight).append(";\n");
|
||||
fontStyleSheet.append(indent).append("color: ").append(fontColor).append(";\n");
|
||||
QString qss = CStyleSheetUtility::asStylesheet(fontFamily, fontSize, fontStyle, fontWeight, fontColor);
|
||||
return CStyleSheetUtility::updateFont(qss);
|
||||
}
|
||||
|
||||
QString qss("QWidget {\n");
|
||||
qss.append(fontStyleSheet);
|
||||
qss.append("}\n");
|
||||
bool CStyleSheetUtility::updateFont(const QString &qss)
|
||||
{
|
||||
QString qssWidget("QWidget {\n");
|
||||
qssWidget.append(qss);
|
||||
qssWidget.append("}\n");
|
||||
|
||||
QFile fontFile(CBuildConfig::getStylesheetsDir() + "/" + fileNameFontsModified());
|
||||
bool ok = fontFile.open(QFile::Text | QFile::WriteOnly);
|
||||
if (ok)
|
||||
{
|
||||
QTextStream out(&fontFile);
|
||||
out << qss;
|
||||
out << qssWidget;
|
||||
fontFile.close();
|
||||
ok = this->read();
|
||||
}
|
||||
|
||||
@@ -53,6 +53,9 @@ namespace BlackGui
|
||||
//! Update the fonts
|
||||
bool updateFont(const QFont &font);
|
||||
|
||||
//! Update the fonts
|
||||
bool updateFont(const QString &qss);
|
||||
|
||||
//! Update the fonts
|
||||
bool updateFont(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor);
|
||||
|
||||
@@ -128,6 +131,9 @@ namespace BlackGui
|
||||
//! Font as combined weight and style
|
||||
static QString fontAsCombinedWeightStyle(const QFont &font);
|
||||
|
||||
//! Parameter as stylesheet
|
||||
static QString asStylesheet(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor);
|
||||
|
||||
//! Use style sheets in derived widgets
|
||||
//! \sa QWidget::paintEvent
|
||||
static bool useStyleSheetInDerivedWidget(QWidget *derivedWidget, QStyle::PrimitiveElement element = QStyle::PE_Widget);
|
||||
|
||||
Reference in New Issue
Block a user