X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fuisupport%2Fqssparser.cpp;h=091ac4b2dfa61fd742f606d1364bb017d92ed46b;hb=120861b909702039da9993278d8319dad14fd292;hp=d7a788e9f1635687f766e9ac89772b5194851cf3;hpb=03976b69a41261782602d745805a178d8f3f1dc9;p=quassel.git diff --git a/src/uisupport/qssparser.cpp b/src/uisupport/qssparser.cpp index d7a788e9..091ac4b2 100644 --- a/src/uisupport/qssparser.cpp +++ b/src/uisupport/qssparser.cpp @@ -49,32 +49,39 @@ QssParser::QssParser() _paletteColorRoles["tooltip-text"] = QPalette::ToolTipText; _paletteColorRoles["window"] = QPalette::Window; _paletteColorRoles["window-text"] = QPalette::WindowText; + + _uiStylePalette = QVector(UiStyle::NumRoles, QBrush()); + + _uiStyleColorRoles["marker-line"] = UiStyle::MarkerLine; + _uiStyleColorRoles["active-nick"] = UiStyle::ActiveNick; + _uiStyleColorRoles["inactive-nick"] = UiStyle::InactiveNick; + _uiStyleColorRoles["channel"] = UiStyle::Channel; + _uiStyleColorRoles["inactive-channel"] = UiStyle::InactiveChannel; + _uiStyleColorRoles["active-channel"] = UiStyle::ActiveChannel; + _uiStyleColorRoles["unread-channel"] = UiStyle::UnreadChannel; + _uiStyleColorRoles["highlighted-channel"] = UiStyle::HighlightedChannel; + _uiStyleColorRoles["query"] = UiStyle::Query; + _uiStyleColorRoles["inactive-query"] = UiStyle::InactiveQuery; + _uiStyleColorRoles["active-query"] = UiStyle::ActiveQuery; + _uiStyleColorRoles["unread-query"] = UiStyle::UnreadQuery; + _uiStyleColorRoles["highlighted-query"] = UiStyle::HighlightedQuery; } -void QssParser::loadStyleSheet(const QString &styleSheet) { - QString ss = styleSheet; - ss = "file:////home/sputnick/devel/quassel/test.qss"; // FIXME - if(ss.startsWith("file:///")) { - ss.remove(0, 8); - QFile file(ss); - if(file.open(QFile::ReadOnly)) { - QTextStream stream(&file); - ss = stream.readAll(); - } else { - qWarning() << tr("Could not read stylesheet \"%1\"!").arg(file.fileName()); - return; - } - } +void QssParser::processStyleSheet(QString &ss) { if(ss.isEmpty()) return; - // Now we have the stylesheet itself in ss, start parsing + // Remove C-style comments /* */ or // + QRegExp commentRx("(//.*(\\n|$)|/\\*.*\\*/)"); + commentRx.setMinimal(true); + ss.remove(commentRx); + // Palette definitions first, so we can apply roles later on QRegExp paletterx("(Palette[^{]*)\\{([^}]+)\\}"); int pos = 0; while((pos = paletterx.indexIn(ss, pos)) >= 0) { parsePaletteData(paletterx.cap(1).trimmed(), paletterx.cap(2).trimmed()); - pos += paletterx.matchedLength(); + ss.remove(pos, paletterx.matchedLength()); } // Now we can parse the rest of our custom blocks @@ -88,9 +95,8 @@ void QssParser::loadStyleSheet(const QString &styleSheet) { //else // TODO: add moar here - pos += blockrx.matchedLength(); + ss.remove(pos, blockrx.matchedLength()); } - } void QssParser::parseChatLineData(const QString &decl, const QString &contents) { @@ -137,7 +143,7 @@ void QssParser::parseChatLineData(const QString &decl, const QString &contents) } } - _formats[fmtType] = format; + _formats[fmtType].merge(format); } quint64 QssParser::parseFormatType(const QString &decl) { @@ -209,7 +215,7 @@ quint64 QssParser::parseFormatType(const QString &decl) { } // Next up: conditional (formats, labels, nickhash) - QRegExp condRx("\\s*(\\w+)\\s*=\\s*\"(\\w+)\"\\s*"); + QRegExp condRx("\\s*([\\w\\-]+)\\s*=\\s*\"(\\w+)\"\\s*"); if(!conditions.isEmpty()) { foreach(const QString &cond, conditions.split(',', QString::SkipEmptyParts)) { if(!condRx.exactMatch(cond)) { @@ -222,6 +228,8 @@ quint64 QssParser::parseFormatType(const QString &decl) { quint64 labeltype = 0; if(condValue == "highlight") labeltype = UiStyle::Highlight; + else if(condValue == "selected") + labeltype = UiStyle::Selected; else { qWarning() << Q_FUNC_INFO << tr("Invalid message label: %1").arg(condValue); return UiStyle::Invalid; @@ -237,14 +245,40 @@ quint64 QssParser::parseFormatType(const QString &decl) { qWarning() << Q_FUNC_INFO << tr("Invalid senderhash specification: %1").arg(condValue); return UiStyle::Invalid; } - if(val >= 255) { - qWarning() << Q_FUNC_INFO << tr("Senderhash can be at most \"fe\"!"); + if(val >= 16) { + qWarning() << Q_FUNC_INFO << tr("Senderhash can be at most \"0x0f\"!"); return UiStyle::Invalid; } fmtType |= val << 48; } + } else if(condName == "format") { + if(condValue == "bold") + fmtType |= UiStyle::Bold; + else if(condValue == "italic") + fmtType |= UiStyle::Italic; + else if(condValue == "underline") + fmtType |= UiStyle::Underline; + else if(condValue == "reverse") + fmtType |= UiStyle::Reverse; + else { + qWarning() << Q_FUNC_INFO << tr("Invalid format name: %1").arg(condValue); + return UiStyle::Invalid; + } + } else if(condName == "fg-color" || condName == "bg-color") { + bool ok; + quint8 col = condValue.toUInt(&ok, 16); + if(!ok || col > 0x0f) { + qWarning() << Q_FUNC_INFO << tr("Illegal IRC color specification (must be between 00 and 0f): %1").arg(condValue); + return UiStyle::Invalid; + } + if(condName == "fg-color") + fmtType |= 0x00400000 | (col << 24); + else + fmtType |= 0x00800000 | (col << 28); + } else { + qWarning() << Q_FUNC_INFO << tr("Unhandled condition: %1").arg(condName); + return UiStyle::Invalid; } - // TODO: colors } } @@ -284,16 +318,18 @@ void QssParser::parsePaletteData(const QString &decl, const QString &contents) { } QString rolestr = line.left(idx).trimmed(); QString brushstr = line.mid(idx + 1).trimmed(); - if(!_paletteColorRoles.contains(rolestr)) { - qWarning() << Q_FUNC_INFO << tr("Unknown palette role name: %1").arg(rolestr); - continue; - } - QBrush brush = parseBrush(brushstr); - if(colorGroups.count()) { - foreach(QPalette::ColorGroup group, colorGroups) - _palette.setBrush(group, _paletteColorRoles.value(rolestr), brush); + + if(_paletteColorRoles.contains(rolestr)) { + QBrush brush = parseBrush(brushstr); + if(colorGroups.count()) { + foreach(QPalette::ColorGroup group, colorGroups) + _palette.setBrush(group, _paletteColorRoles.value(rolestr), brush); + } else + _palette.setBrush(_paletteColorRoles.value(rolestr), brush); + } else if(_uiStyleColorRoles.contains(rolestr)) { + _uiStylePalette[_uiStyleColorRoles.value(rolestr)] = parseBrush(brushstr); } else - _palette.setBrush(_paletteColorRoles.value(rolestr), brush); + qWarning() << Q_FUNC_INFO << tr("Unknown palette role name: %1").arg(rolestr); } } @@ -313,11 +349,12 @@ QBrush QssParser::parseBrush(const QString &str, bool *ok) { qWarning() << Q_FUNC_INFO << tr("Invalid palette color role specification: %1").arg(str); return QBrush(); } - if(!_paletteColorRoles.contains(rx.cap(1))) { - qWarning() << Q_FUNC_INFO << tr("Unknown palette color role: %1").arg(rx.cap(1)); - return QBrush(); - } - return QBrush(_palette.brush(_paletteColorRoles.value(rx.cap(1)))); + if(_paletteColorRoles.contains(rx.cap(1))) + return QBrush(_palette.brush(_paletteColorRoles.value(rx.cap(1)))); + if(_uiStyleColorRoles.contains(rx.cap(1))) + return QBrush(_uiStylePalette.at(_uiStyleColorRoles.value(rx.cap(1)))); + qWarning() << Q_FUNC_INFO << tr("Unknown palette color role: %1").arg(rx.cap(1)); + return QBrush(); } else if(str.startsWith("qlineargradient")) { static QString rxFloat("\\s*(-?\\s*[0-9]*\\.?[0-9]+)\\s*"); @@ -470,7 +507,7 @@ QGradientStops QssParser::parseGradientStops(const QString &str_) { /******** Font Properties ********/ void QssParser::parseFont(const QString& value, QTextCharFormat* format) { - QRegExp rx("((?:(?:normal|italic|oblique|bold|100|200|300|400|500|600|700|800|900) ){0,2}) ?(\\d+)(pt|px)? \"(.*)\""); + QRegExp rx("((?:(?:normal|italic|oblique|underline|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; @@ -481,6 +518,8 @@ void QssParser::parseFont(const QString& value, QTextCharFormat* format) { foreach(QString prop, proplist) { if(prop == "italic") format->setFontItalic(true); + else if(prop == "underline") + format->setFontUnderline(true); //else if(prop == "oblique") // format->setStyle(QFont::StyleOblique); else if(prop == "bold") @@ -504,6 +543,8 @@ void QssParser::parseFontStyle(const QString& value, QTextCharFormat* format) { format->setFontItalic(false); else if(value == "italic") format->setFontItalic(true); + else if(value == "underline") + format->setFontUnderline(true); //else if(value == "oblique") // format->setStyle(QFont::StyleOblique); else {