mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-06 02:16:04 +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);
|
return m_styleSheetUtility.updateFont(fontFamily, fontSize, fontStyle, fontWeight, fontColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CGuiApplication::updateFont(const QString &qss)
|
||||||
|
{
|
||||||
|
return m_styleSheetUtility.updateFont(qss);
|
||||||
|
}
|
||||||
|
|
||||||
bool CGuiApplication::resetFont()
|
bool CGuiApplication::resetFont()
|
||||||
{
|
{
|
||||||
return m_styleSheetUtility.resetFont();
|
return m_styleSheetUtility.resetFont();
|
||||||
|
|||||||
@@ -156,6 +156,9 @@ namespace BlackGui
|
|||||||
//! Update the fonts
|
//! Update the fonts
|
||||||
bool updateFont(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor);
|
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
|
//! Reset the font to default
|
||||||
bool resetFont();
|
bool resetFont();
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,14 @@ namespace BlackGui
|
|||||||
return w.append(" ").append(s);
|
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
|
QString CStyleSheetUtility::fontColor() const
|
||||||
{
|
{
|
||||||
const QString s = this->style(fileNameFonts()).toLower();
|
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)
|
bool CStyleSheetUtility::updateFont(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor)
|
||||||
{
|
{
|
||||||
static const QString indent(" ");
|
QString qss = CStyleSheetUtility::asStylesheet(fontFamily, fontSize, fontStyle, fontWeight, fontColor);
|
||||||
QString fontStyleSheet;
|
return CStyleSheetUtility::updateFont(qss);
|
||||||
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("QWidget {\n");
|
bool CStyleSheetUtility::updateFont(const QString &qss)
|
||||||
qss.append(fontStyleSheet);
|
{
|
||||||
qss.append("}\n");
|
QString qssWidget("QWidget {\n");
|
||||||
|
qssWidget.append(qss);
|
||||||
|
qssWidget.append("}\n");
|
||||||
|
|
||||||
QFile fontFile(CBuildConfig::getStylesheetsDir() + "/" + fileNameFontsModified());
|
QFile fontFile(CBuildConfig::getStylesheetsDir() + "/" + fileNameFontsModified());
|
||||||
bool ok = fontFile.open(QFile::Text | QFile::WriteOnly);
|
bool ok = fontFile.open(QFile::Text | QFile::WriteOnly);
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
QTextStream out(&fontFile);
|
QTextStream out(&fontFile);
|
||||||
out << qss;
|
out << qssWidget;
|
||||||
fontFile.close();
|
fontFile.close();
|
||||||
ok = this->read();
|
ok = this->read();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ namespace BlackGui
|
|||||||
//! Update the fonts
|
//! Update the fonts
|
||||||
bool updateFont(const QFont &font);
|
bool updateFont(const QFont &font);
|
||||||
|
|
||||||
|
//! Update the fonts
|
||||||
|
bool updateFont(const QString &qss);
|
||||||
|
|
||||||
//! Update the fonts
|
//! Update the fonts
|
||||||
bool updateFont(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor);
|
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
|
//! Font as combined weight and style
|
||||||
static QString fontAsCombinedWeightStyle(const QFont &font);
|
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
|
//! Use style sheets in derived widgets
|
||||||
//! \sa QWidget::paintEvent
|
//! \sa QWidget::paintEvent
|
||||||
static bool useStyleSheetInDerivedWidget(QWidget *derivedWidget, QStyle::PrimitiveElement element = QStyle::PE_Widget);
|
static bool useStyleSheetInDerivedWidget(QWidget *derivedWidget, QStyle::PrimitiveElement element = QStyle::PE_Widget);
|
||||||
|
|||||||
Reference in New Issue
Block a user