Fix that sometimes % wasn't escaped properly, triggering an assert
[quassel.git] / src / uisupport / uistyle.cpp
index 3fc53bd..84a4099 100644 (file)
@@ -5,7 +5,7 @@
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
+ *   (at your option) version 3.                                           *
  *                                                                         *
  *   This program is distributed in the hope that it will be useful,       *
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 UiStyle::UiStyle() {
   // Default format
   QTextCharFormat def;
-  def.setForeground(QBrush("black"));
+  def.setForeground(QBrush("#000000"));
   def.setFont(QFont("Verdana",9));
 
   _formats = QVector<QTextCharFormat>(NumFormatTypes, def);
 
   // Initialize color codes according to mIRC "standard"
   QStringList colors;
-  colors << "white" << "black" << "navy" << "green" << "red" << "maroon" << "purple" << "orange";
-  colors << "yellow" << "lime" << "teal" << "aqua" << "royalblue" << "fuchsia" << "grey" << "silver";
+  //colors << "white" << "black" << "navy" << "green" << "red" << "maroon" << "purple" << "orange";
+  //colors << "yellow" << "lime" << "teal" << "aqua" << "royalblue" << "fuchsia" << "grey" << "silver";
+  colors << "#ffffff" << "#000000" << "#000080" << "#008000" << "#ff0000" << "#800000" << "#800080" << "#ffa500";
+  colors << "#ffff00" << "#00ff00" << "#008080" << "#00ffff" << "#4169E1" << "#ff00ff" << "#808080" << "#c0c0c0";
 
   // Now initialize the mapping between FormatCodes and FormatTypes...
   _formatCodes["%O"] = None;
@@ -104,8 +106,8 @@ QString UiStyle::formatCode(FormatType ftype) const {
   return _formatCodes.key(ftype);
 }
 
-UiStyle::StyledString UiStyle::styleString(QString s) {
-  StyledString result;
+UiStyle::StyledText UiStyle::styleString(QString s) {
+  StyledText result;
   QList<FormatType> fmtList;
   fmtList.append(None);
   QTextLayout::FormatRange curFmtRng;
@@ -158,16 +160,20 @@ UiStyle::StyledString UiStyle::styleString(QString s) {
       fmtList.clear(); fmtList.append(None);
       curFmtRng.format = format(None);
       fgCol = bgCol = -1;
-      length = 1;
+      length = 2;
     } else if(s[pos+1] == 'R') { // reverse
       // TODO: implement reverse formatting
 
-      length = 1;
+      length = 2;
     } else { // all others are toggles
       QString code = QString("%") + s[pos+1];
       if(s[pos+1] == 'D') code += s[pos+2];
       FormatType ftype = formatType(code);
-      Q_ASSERT(ftype != Invalid);
+      if(ftype == Invalid) {
+        qWarning(qPrintable(QString("Invalid format code in string: %1").arg(s)));
+        continue;
+      }
+      //Q_ASSERT(ftype != Invalid);
       length = code.length();
       if(!fmtList.contains(ftype)) {
         // toggle it on