+
+/******** Font Properties ********/
+
+bool QssParser::parseFont(const QString &value, QFont *font) {
+ QRegExp rx("((?:(?:normal|italic|oblique|bold|100|200|300|400|500|600|700|800|900) ){0,2}) ?(\\d+)(pt|px)? \"(.*)\"");
+ if(!rx.exactMatch(value)) {
+ qWarning() << Q_FUNC_INFO << tr("Invalid font specification: %1").arg(value);
+ return false;
+ }
+ font->setStyle(QFont::StyleNormal);
+ font->setWeight(QFont::Normal);
+ QStringList proplist = rx.cap(1).split(' ', QString::SkipEmptyParts);
+ foreach(QString prop, proplist) {
+ if(prop == "italic")
+ font->setStyle(QFont::StyleItalic);
+ else if(prop == "oblique")
+ font->setStyle(QFont::StyleOblique);
+ else if(prop == "bold")
+ font->setWeight(QFont::Bold);
+ else { // number
+ int w = prop.toInt();
+ font->setWeight(qMin(w / 8, 99)); // taken from Qt's qss parser
+ }
+ }
+
+ if(rx.cap(3) == "px")
+ font->setPixelSize(rx.cap(2).toInt());
+ else
+ font->setPointSize(rx.cap(2).toInt());
+
+ font->setFamily(rx.cap(4));
+ return true;
+}
+
+bool QssParser::parseFontStyle(const QString &value, QFont *font) {
+ if(value == "normal")
+ font->setStyle(QFont::StyleNormal);
+ else if(value == "italic")
+ font->setStyle(QFont::StyleItalic);
+ else if(value == "oblique")
+ font->setStyle(QFont::StyleOblique);
+ else {
+ qWarning() << Q_FUNC_INFO << tr("Invalid font style specification: %1").arg(value);
+ return false;
+ }
+ return true;
+}
+
+bool QssParser::parseFontWeight(const QString &value, QFont *font) {
+ if(value == "normal")
+ font->setWeight(QFont::Normal);
+ else if(value == "bold")
+ font->setWeight(QFont::Bold);
+ else {
+ bool ok;
+ int w = value.toInt(&ok);
+ if(!ok) {
+ qWarning() << Q_FUNC_INFO << tr("Invalid font weight specification: %1").arg(value);
+ return false;
+ }
+ font->setWeight(qMin(w / 8, 99)); // taken from Qt's qss parser
+ }
+ return true;
+}
+
+bool QssParser::parseFontSize(const QString &value, QFont *font) {
+ QRegExp rx("\\(d+)(pt|px)");
+ if(!rx.exactMatch(value)) {
+ qWarning() << Q_FUNC_INFO << tr("Invalid font size specification: %1").arg(value);
+ return false;
+ }
+ if(rx.cap(2) == "px")
+ font->setPixelSize(rx.cap(1).toInt());
+ else
+ font->setPointSize(rx.cap(1).toInt());
+ return true;
+}
+
+bool QssParser::parseFontFamily(const QString &value, QFont *font) {
+ QString family = value;
+ if(family.startsWith('"') && family.endsWith('"')) {
+ family = family.mid(1, family.length() -2);
+ }
+ font->setFamily(family);
+ return true;
+}