+ return QSize(document.idealWidth() + 5, fm.height() + 4)
+
+
+
+
+class ElemNodeDelegate(QAbstractItemDelegate):
+ def 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"
+ paint(self, painter, option, index)
+
+ def sizeHint(self, option, index):
+ sizeHint(self, option, index)
+
+class CommentNodeDelegate(QAbstractItemDelegate):
+ def paint(self, painter, option, index):
+ #print "TEXT DELEG CALLED"
+ paint(self, painter, option, index)
+
+def paint(self, painter, option, index):
+ text = index.model().data(index).property('content').toString()
+ palette = QApplication.palette()
+ document = QTextDocument()
+ document.setDefaultFont(option.font)
+ if option.state & QStyle.State_Selected:
+ rx = QRegExp(QString('<font .*>'))
+ rx.setMinimal(True)
+ # If selected, I remove the <font color="..."> by hand,
+ # and give the highlight color
+ document.setHtml(QString("<font color=%1>%2</font>") \
+ .arg(palette.highlightedText().color().name())\
+ .arg(text.replace(rx, QString('')).
+ replace(QString('</font>'),QString(''))))
+ else:
+ document.setHtml(text)
+ color = palette.highlight().color() \
+ if option.state & QStyle.State_Selected \
+ else palette.base().color()
+ painter.save()
+ # voodoo: if not highlighted, filling the rect
+ # with the base color makes no difference
+ painter.fillRect(option.rect, color)
+ painter.translate(option.rect.x(), option.rect.y())
+ document.drawContents(painter)
+ painter.restore()
+
+