Parse mIRC colors in stylesheets
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 25 Jun 2009 18:17:13 +0000 (20:17 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 6 Aug 2009 18:25:05 +0000 (20:25 +0200)
Use a condition like [fg-color="03"] or [bg-color="05"] to specify formats for
mIRC colors. We use this more verbose format (rather than adding extra attributes
to ChatLine instead, like "color-03: red;") to allow for maximum flexibility in
styling. The idea is to be able to specify formats e.g. for a particular combination
of foreground and background.

src/uisupport/qssparser.cpp

index f46147b..52ce79a 100644 (file)
@@ -199,7 +199,7 @@ quint64 QssParser::parseFormatType(const QString &decl) {
   }
 
   // Next up: conditional (formats, labels, nickhash)
   }
 
   // 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)) {
   if(!conditions.isEmpty()) {
     foreach(const QString &cond, conditions.split(',', QString::SkipEmptyParts)) {
       if(!condRx.exactMatch(cond)) {
@@ -236,19 +236,31 @@ quint64 QssParser::parseFormatType(const QString &decl) {
       } else if(condName == "format") {
         if(condValue == "bold")
           fmtType |= UiStyle::Bold;
       } else if(condName == "format") {
         if(condValue == "bold")
           fmtType |= UiStyle::Bold;
-        if(condValue == "italic")
+        else if(condValue == "italic")
           fmtType |= UiStyle::Italic;
           fmtType |= UiStyle::Italic;
-        if(condValue == "underline")
+        else if(condValue == "underline")
           fmtType |= UiStyle::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;
         }
           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
     }
   }
 
     }
   }