done with sizeHint. Next: it a bit slow in changing the orientation of the arrow...
authorGiovanni Gherdovich <ggherdov@brentaal.inria.fr>
Tue, 19 Oct 2010 16:24:51 +0000 (18:24 +0200)
committerGiovanni Gherdovich <ggherdov@brentaal.inria.fr>
Tue, 19 Oct 2010 16:24:51 +0000 (18:24 +0200)
sface/xmlwidget.py

index 865f276..2a57587 100644 (file)
@@ -231,25 +231,25 @@ class XmlDelegate(QItemDelegate):
             # doesn't know about my QMap strategy.
             QItemDelegate.paint(self, painter, option, index)
 
-#    def sizeHint(self, option, index):
-#        fm = option.fontMetrics
-#        print "TYPE:", str(type(index.model().data(index).convert(QObject)))
-#        text = "the fish doesn't talk"
-#        #text = str(index.model().data(index).property('content').toString())
-#        nodeType = str(index.model().data(index).property('nodeType').toString())
-#        if nodeType == 'element' or nodeType == 'comment':
-#            numlines = 1
-#        elif nodeType == 'text':
-#            numlines = text.count('\n')
-#            sys.__stdout__.write("TEXT: \n" + text)
-#        else:
-#            numlines = 1
-#        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) * numlines)    
+    def sizeHint(self, option, index):
+        fm = option.fontMetrics
+        text = "the fish doesn't talk"
+        dataAsQVarMap = index.model().data(index)
+        nodeType = str(QVarMapAccess(dataAsQVarMap, 'nodeType'))
+        if nodeType == 'element' or nodeType == 'comment':
+            numlines = 1
+        elif nodeType == 'text':
+            nl = text.count('\n')
+            numlines = nl if nl > 0 else 1
+            sys.__stdout__.write("TEXT: \n" + text)
+        else:
+            numlines = 1
+        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) * numlines)    
 
 class ElemNodeDelegate(QAbstractItemDelegate):
     def paint(self, painter, option, index):