class ElemNodeDelegate(QAbstractItemDelegate):
def paint(self, painter, option, index):
- text = index.model().data(index)
palette = QApplication.palette()
document = QTextDocument()
document.setDefaultFont(option.font)
highGlobPattern = '<<b>%s</b>%s>'
highAttPattern = ' <b>%s</b>="%s"'
def getHtmlText(plainText, globPattern, attPattern):
- print "PLAIN TEXT:", plainText
tmp = plainText.split(' ', 1)
- print "TMP:", tmp
elemName = tmp[0]
AttListHtml = ''
if len(tmp) > 1:
def colorize(color, text):
return '<font color=' + color + '>' + text + '</font>'
text = str(index.model().data(index).property('content').toString())
- print "TEXT:", text
if option.state & QStyle.State_Selected:
htmlText = colorize(palette.highlightedText().color().name(),
getHtmlText(text, highGlobPattern, highAttPattern))
if option.state & QStyle.State_Selected \
else palette.base().color()
painter.save()
- print "COLOR:", color.name()
# voodoo: if not highlighted, filling the rect
# with the base color makes no difference
painter.fillRect(option.rect, color)
class TextNodeDelegate(QAbstractItemDelegate):
def paint(self, painter, option, index):
- #print "TEXT DELEG CALLED"
- paint(self, painter, option, index)
+ palette = QApplication.palette()
+ document = QTextDocument()
+ document.setDefaultFont(option.font)
+ def verbatimize(text):
+ text.replace('\n', '<br>')
+ return '<pre>' + text + '</pre'
+ def colorize(color, text):
+ return '<font color=' + color + '>' + text + '</font>'
+ text = str(index.model().data(index).property('content').toString())
+ if option.state & QStyle.State_Selected:
+ htmlText = colorize(palette.highlightedText().color().name(),
+ verbatimize(text))
+ document.setHtml(QString(htmlText))
+ else:
+ htmlText = verbatimize(text)
+ document.setHtml(QString(htmlText))
+ 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()
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):