[Kst] branches/kst/hfi_calib/kst/kst

George Staikos staikos at kde.org
Fri Feb 24 16:19:06 CET 2006


SVN commit 513197 by staikos:

fix \n and \t handling and add textbf, textit, underline


 M  +8 -1      kstviewlabel.cpp  
 M  +60 -12    labelparser.cpp  
 M  +3 -0      labelparser.h  
 M  +26 -3     labelrenderer.cpp  


--- branches/kst/hfi_calib/kst/kst/kstviewlabel.cpp #513196:513197
@@ -622,11 +622,15 @@
     }
 
   } else { 
+    // No, this is broken.  It kills latex.
+#if 0
     // replace \n & \t with tabs and newlines for the text edit box
     QString tmpstr = text();
     tmpstr.replace(QString("\\n"), "\n");
     tmpstr.replace(QString("\\t"), "\t");
     widget->_text->setText(tmpstr);
+#endif 
+    widget->_text->setText(text());
 
     widget->_precision->setValue(int(dataPrecision()));
     widget->_rotation->setValue(double(rotation()));
@@ -654,10 +658,13 @@
     return false;
   }
 
+  _txt = widget->_text->text();
+    // No, this is broken.  It kills latex.
+#if 0
   // Replace tabs and newlines in text edit box with \n and \t 
-  _txt = widget->_text->text();
   _txt.replace(QString("\n"), "\\n");
   _txt.replace(QString("\t"), "\\t");
+#endif
 
   setDataPrecision(widget->_precision->value());
   setRotation(widget->_rotation->value());
--- branches/kst/hfi_calib/kst/kst/labelparser.cpp #513196:513197
@@ -24,7 +24,7 @@
 using namespace Label;
 
 Chunk::Chunk(Chunk *parent, VOffset dir, bool group)
-: next(0L), prev(0L), up(0L), down(0L), scalar(false), group(group), linebreak(false), tab(false), vector(false), vOffset(dir) {
+: next(0L), prev(0L), up(0L), down(0L), scalar(false), group(group), linebreak(false), tab(false), vector(false), bold(false), italic(false), underline(false), vOffset(dir) {
   assert(parent || vOffset == None);
   if (parent) {  // attach and inherit
     switch (vOffset) {
@@ -71,7 +71,7 @@
 
 
 bool Chunk::locked() const {
-  return scalar || group || linebreak || tab || vector;
+  return scalar || group || linebreak || tab || vector || bold || italic || underline;
 }
 
 
@@ -115,16 +115,14 @@
   short x = 0;
 
   switch (c.unicode()) {
-    EXPAND_GREEK('B', 'b', "eta",   4, 0x392)
-    EXPAND_GREEK('D', 'd', "elta",  5, 0x394)
-    EXPAND_GREEK('Z', 'z', "eta",   4, 0x396)
-    EXPAND_GREEK('K', 'k', "appa",  5, 0x39a)
-    EXPAND_GREEK('M', 'm', "u",     2, 0x39c)
-    EXPAND_GREEK('X', 'x', "i",     2, 0x39e)
-    EXPAND_GREEK('R', 'r', "ho",    3, 0x3a1)
-    EXPAND_GREEK('U', 'u', "psilon",7, 0x3a5)
+    EXPAND_GREEK('B', 'b', "eta",  4, 0x392)
+    EXPAND_GREEK('D', 'd', "elta", 5, 0x394)
+    EXPAND_GREEK('Z', 'z', "eta",  4, 0x396)
+    EXPAND_GREEK('K', 'k', "appa", 5, 0x39a)
+    EXPAND_GREEK('M', 'm', "u",    2, 0x39c)
+    EXPAND_GREEK('X', 'x', "i",    2, 0x39e)
+    EXPAND_GREEK('R', 'r', "ho",   3, 0x3a1)
 
-
     case 'a':
       x = 0x20;
     case 'A':
@@ -290,7 +288,28 @@
     case 't':
       x = 0x20;
     case 'T':
-      if (txt.mid(from + 1).startsWith("heta")) {
+      if (txt.mid(from + 1).startsWith("extcolor")) { // \textcolor{color}{text}
+        *skip = 9;
+        if (!*tail || !(*tail)->text.isEmpty() || (*tail)->locked()) {
+          *tail = new Chunk(*tail);
+        }
+        // FIXME: parse out the color
+        return true;
+      } else if (txt.mid(from + 1).startsWith("extbf")) {
+        *skip = 6;
+        if (!*tail || !(*tail)->text.isEmpty() || (*tail)->locked()) {
+          *tail = new Chunk(*tail);
+        }
+        (*tail)->bold = true;
+        return true;
+      } else if (txt.mid(from + 1).startsWith("extit")) {
+        *skip = 6;
+        if (!*tail || !(*tail)->text.isEmpty() || (*tail)->locked()) {
+          *tail = new Chunk(*tail);
+        }
+        (*tail)->italic = true;
+        return true;
+      } else if (txt.mid(from + 1).startsWith("heta")) {
         *skip = 5;
         setNormalChar(QChar(0x398+x), tail);
         return true;
@@ -326,6 +345,23 @@
       }
       break;
 
+    case 'u':
+      x = 0x20;
+    case 'U':
+      if (txt.mid(from + 1).startsWith("nderline")) {
+        *skip = 9;
+        if (!*tail || !(*tail)->text.isEmpty() || (*tail)->locked()) {
+          *tail = new Chunk(*tail);
+        }
+        (*tail)->underline = true;
+        return true;
+      } else if (txt.mid(from + 1).startsWith("psilon")) {
+        *skip = 7;
+        setNormalChar(QChar(0x3A5+x), tail);
+        return true;
+      }
+      break;
+
     default:
       break;
   }
@@ -345,6 +381,18 @@
     QChar c = txt[i];
     Chunk::VOffset dir = Chunk::Down;
     switch (c.unicode()) {
+      case '\n':
+        if (!ctail || !ctail->text.isEmpty() || ctail->locked()) {
+          ctail = new Chunk(ctail);
+        }
+        ctail->linebreak = true;
+        break;
+      case '\t':
+        if (!ctail || !ctail->text.isEmpty() || ctail->locked()) {
+          ctail = new Chunk(ctail);
+        }
+        ctail->tab = true;
+        break;
       case 0x5c:   // \ /**/
         if (ctail->vOffset != Chunk::None && !ctail->text.isEmpty()) {
           ctail = new Chunk(ctail->prev);
--- branches/kst/hfi_calib/kst/kst/labelparser.h #513196:513197
@@ -53,6 +53,9 @@
     bool linebreak : 1;
     bool tab : 1;
     bool vector : 1;
+    bool bold : 1;
+    bool italic : 1;
+    bool underline : 1;
     VOffset vOffset : 2;
     QString text;
     QString expression;
--- branches/kst/hfi_calib/kst/kst/labelrenderer.cpp #513196:513197
@@ -51,9 +51,25 @@
       rc.setFont(f);
     }
 
-    if (fi->group) { // groups have no contents
-      fi = fi->next;
-      continue;
+    QFont f = rc.font();
+    bool wasBold = f.bold();
+    bool wasItalic = f.italic();
+    bool wasUnderline = f.underline();
+    bool wasGroup = fi->group;
+    if (wasGroup) {
+      if (fi->bold) {
+        f.setBold(fi->bold);
+      }
+      if (fi->italic) {
+        f.setItalic(fi->italic);
+      }
+      if (fi->underline) {
+        f.setUnderline(fi->underline);
+      }
+      rc.setFont(f);
+
+      fi = fi->next; // groups have no contents
+      //continue;
     }
 
     if (fi->linebreak) {
@@ -174,6 +190,13 @@
       xNext = kMax(xNext, rc.x);
     }
 
+    if (wasGroup) {
+      f.setBold(wasBold);
+      f.setItalic(wasItalic);
+      f.setUnderline(wasUnderline);
+      rc.setFont(f);
+    }
+
     rc.x = xNext;
     rc.xMax = kMax(rc.xMax, rc.x);
 


More information about the Kst mailing list