element nodes randered by QPainter without html help. On the way.
authorGiovanni Gherdovich <ggherdov@brentaal.inria.fr>
Mon, 11 Oct 2010 17:42:54 +0000 (19:42 +0200)
committerGiovanni Gherdovich <ggherdov@brentaal.inria.fr>
Mon, 11 Oct 2010 17:42:54 +0000 (19:42 +0200)
sface/xmlwidget.py

index 512d35a..da6563e 100644 (file)
@@ -39,7 +39,7 @@ class DomModel(QAbstractItemModel):
                     attr = attributeMap.item(i)
                     elem = ' %s="%s"' % (attr.nodeName(), attr.nodeValue())
                     qslist.append(elem)
-                ElemNameAndAtts = QString('&lt;%s%s&gt;'% (node.nodeName(), qslist.join(' ')))
+                ElemNameAndAtts = '%s%s'% (node.nodeName(), qslist.join(' '))
                 obj = QObject()
                 obj.setProperty('nodeType', QString('element'))
                 obj.setProperty('content', ElemNameAndAtts)
@@ -230,29 +230,48 @@ class XmlDelegate(QItemDelegate):
     def paint(self, painter, option, index):
         nodeType = index.model().data(index).property('nodeType')
         delegate = self.delegates.get(str(nodeType.toString()))
-        print "TYPE:", str(type(str(nodeType.toString())))
-        print "DELEGS DICT:", self.delegates
-        print "NODETYPE:", nodeType.toString()
+        #print "TYPE:", str(type(str(nodeType.toString())))
+        #print "DELEGS DICT:", self.delegates
+        #print "NODETYPE:", nodeType.toString()
         if delegate is not None:
-            print "WOW DELEG ISNT NONE"
+            #print "WOW DELEG ISNT NONE"
             delegate.paint(painter, option, index)
         else:
-            print "ELSE BRANCH"
+            #print "ELSE BRANCH"
             # not sure this will ever work. this delegate
             # doesn't know about my QObject strategy.
             QItemDelegate.paint(self, painter, option, index)
 
+    def sizeHint(self, option, index):
+        fm = option.fontMetrics
+        text = index.model().data(index).property('content').toString()
+        document = QTextDocument()
+        document.setDefaultFont(option.font)
+        document.setHtml(text)
+        # the +5 is for margin. The +4 is voodoo;
+        # fm.height just give it too small.
+        return QSize(document.idealWidth() + 5, fm.height() + 4)    
+
+
+
+
 class ElemNodeDelegate(QAbstractItemDelegate):
     def paint(self, painter, option, index): 
-        print "ELEM DELEG CALLED"         
-        paint(self, painter, option, index)
+        text = index.model().data(index).property('content').toString()
+        painter.save()
+        font = option.font
+        font.setBold(True)
+        painter.setFont(font)
+        painter.drawText(option.rect, Qt.AlignLeft, QString(text))
+        #print "ELEM DELEG CALLED"
+        painter.restore()
 
     def sizeHint(self, option, index):
         sizeHint(self, option, index)
 
 class TextNodeDelegate(QAbstractItemDelegate):
     def paint(self, painter, option, index): 
-        print "TEXT DELEG CALLED"
+        #print "TEXT DELEG CALLED"
         paint(self, painter, option, index)
 
     def sizeHint(self, option, index):
@@ -260,13 +279,9 @@ class TextNodeDelegate(QAbstractItemDelegate):
 
 class CommentNodeDelegate(QAbstractItemDelegate):
     def paint(self, painter, option, index): 
-        print "TEXT DELEG CALLED"
+        #print "TEXT DELEG CALLED"
         paint(self, painter, option, index)
 
-    def sizeHint(self, option, index):
-        sizeHint(self, option, index)
-    
-
 def paint(self, painter, option, index):
     text = index.model().data(index).property('content').toString()
     palette = QApplication.palette()
@@ -294,12 +309,4 @@ def paint(self, painter, option, index):
     document.drawContents(painter)
     painter.restore()
 
-def sizeHint(self, option, index):
-    fm = option.fontMetrics
-    text = index.model().data(index)
-    document = QTextDocument()
-    document.setDefaultFont(option.font)
-    document.setHtml(text)
-    # the +5 is for margin. The +4 is voodoo;
-    # fm.height just give it too small.
-    return QSize(document.idealWidth() + 5, fm.height() + 4)
+