X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fqssparser.cpp;h=52ce79ac2ef610b642ab8826b62c064adba9af8f;hp=585b769dd3de86156a59a80e68190d7ccfb731cb;hb=0ff679f6bdd6729d12bee1ed7a2b6ac812c3e31c;hpb=c870a4980ba79f784781e75b89ec537f1ec343ac diff --git a/src/uisupport/qssparser.cpp b/src/uisupport/qssparser.cpp index 585b769d..52ce79ac 100644 --- a/src/uisupport/qssparser.cpp +++ b/src/uisupport/qssparser.cpp @@ -51,30 +51,21 @@ QssParser::QssParser() _paletteColorRoles["window-text"] = QPalette::WindowText; } -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 +79,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) { @@ -209,7 +199,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)) { @@ -246,19 +236,31 @@ quint64 QssParser::parseFormatType(const QString &decl) { } else if(condName == "format") { if(condValue == "bold") fmtType |= UiStyle::Bold; - if(condValue == "italic") + else if(condValue == "italic") fmtType |= UiStyle::Italic; - if(condValue == "underline") + else if(condValue == "underline") fmtType |= UiStyle::Underline; - if(condValue == "reverse") + 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 } }