mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 02:06:08 +08:00
Ref T30, more utility functions for style sheets
This commit is contained in:
committed by
Mathew Sutcliffe
parent
9c52334017
commit
c0fb236b25
@@ -101,8 +101,24 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
static const QString indent(" ");
|
static const QString indent(" ");
|
||||||
static const QString lf("\n");
|
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");
|
static const 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);
|
static const QString fontStyleSheetNoColor("%1font-family: \"%3\";%2%1font-size: %4;%2%1font-style: %5;%2%1font-weight: %6;%2");
|
||||||
|
|
||||||
|
return fontColor.isEmpty() ?
|
||||||
|
fontStyleSheetNoColor.arg(indent, lf, fontFamily, fontSize, fontStyle, fontWeight) :
|
||||||
|
fontStyleSheet.arg(indent, lf, fontFamily, fontSize, fontStyle, fontWeight, fontColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CStyleSheetUtility::asStylesheet(const QWidget *widget, int pointSize)
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(widget, Q_FUNC_INFO, "Missing widget");
|
||||||
|
const QFont f = widget->font();
|
||||||
|
return CStyleSheetUtility::asStylesheet(
|
||||||
|
f.family(),
|
||||||
|
QString("%1pt").arg(pointSize < 0 ? f.pointSize() : pointSize),
|
||||||
|
CStyleSheetUtility::fontStyleAsString(f),
|
||||||
|
CStyleSheetUtility::fontWeightAsString(f)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CStyleSheetUtility::fontColor() const
|
QString CStyleSheetUtility::fontColor() const
|
||||||
@@ -155,7 +171,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
QString CStyleSheetUtility::style(const QString &fileName) const
|
QString CStyleSheetUtility::style(const QString &fileName) const
|
||||||
{
|
{
|
||||||
if (!this->containsStyle(fileName)) return QString();
|
if (!this->containsStyle(fileName)) { return QString(); }
|
||||||
return this->m_styleSheets[fileName.toLower()].trimmed();
|
return this->m_styleSheets[fileName.toLower()].trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +229,7 @@ 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)
|
||||||
{
|
{
|
||||||
QString qss = CStyleSheetUtility::asStylesheet(fontFamily, fontSize, fontStyle, fontWeight, fontColor);
|
const QString qss = CStyleSheetUtility::asStylesheet(fontFamily, fontSize, fontStyle, fontWeight, fontColor);
|
||||||
return CStyleSheetUtility::updateFont(qss);
|
return CStyleSheetUtility::updateFont(qss);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +260,7 @@ namespace BlackGui
|
|||||||
QString CStyleSheetUtility::fontStyle(const QString &combinedStyleAndWeight)
|
QString CStyleSheetUtility::fontStyle(const QString &combinedStyleAndWeight)
|
||||||
{
|
{
|
||||||
static const QString n("normal");
|
static const QString n("normal");
|
||||||
QString c = combinedStyleAndWeight.toLower();
|
const QString c = combinedStyleAndWeight.toLower();
|
||||||
for (const QString &s : fontStyles())
|
for (const QString &s : fontStyles())
|
||||||
{
|
{
|
||||||
if (c.contains(s))
|
if (c.contains(s))
|
||||||
@@ -258,7 +274,7 @@ namespace BlackGui
|
|||||||
QString CStyleSheetUtility::fontWeight(const QString &combinedStyleAndWeight)
|
QString CStyleSheetUtility::fontWeight(const QString &combinedStyleAndWeight)
|
||||||
{
|
{
|
||||||
static const QString n("normal");
|
static const QString n("normal");
|
||||||
QString c = combinedStyleAndWeight.toLower();
|
const QString c = combinedStyleAndWeight.toLower();
|
||||||
for (const QString &w : fontWeights())
|
for (const QString &w : fontWeights())
|
||||||
{
|
{
|
||||||
if (c.contains(w))
|
if (c.contains(w))
|
||||||
|
|||||||
@@ -131,8 +131,12 @@ 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
|
//! Parameters as stylesheet
|
||||||
static QString asStylesheet(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor);
|
static QString asStylesheet(const QString &fontFamily, const QString &fontSize, const QString &fontStyle,
|
||||||
|
const QString &fontWeight, const QString &fontColor = {});
|
||||||
|
|
||||||
|
//! Widget's font as stylesheet
|
||||||
|
static QString asStylesheet(const QWidget *widget, int pointSize = -1);
|
||||||
|
|
||||||
//! Use style sheets in derived widgets
|
//! Use style sheets in derived widgets
|
||||||
//! \sa QWidget::paintEvent
|
//! \sa QWidget::paintEvent
|
||||||
@@ -163,8 +167,8 @@ namespace BlackGui
|
|||||||
//! Check existance of qss file
|
//! Check existance of qss file
|
||||||
static bool qssFileExists(const QString &filename);
|
static bool qssFileExists(const QString &filename);
|
||||||
|
|
||||||
QMap<QString, QString> m_styleSheets; //!< filename, stylesheet
|
QMap<QString, QString> m_styleSheets; //!< filename, stylesheet
|
||||||
QFileSystemWatcher m_fileWatcher {this}; //!< Monitor my qss files
|
QFileSystemWatcher m_fileWatcher {this}; //!< Monitor my qss files
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
Reference in New Issue
Block a user