X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=sface%2Fxmlwidget.py;fp=sface%2Fxmlwidget.py;h=a2d3ec2312d6a9a24c484e843ba4c68df92e5779;hb=5ca19693a97294cff7be4a2e3cbb92ce5a039794;hp=da6563ed585007983b9d8f6b99fcebbf753a52b7;hpb=99a5613d5bf887070a67eb2208ba907091fe41fb;p=sface.git
diff --git a/sface/xmlwidget.py b/sface/xmlwidget.py
index da6563e..a2d3ec2 100644
--- a/sface/xmlwidget.py
+++ b/sface/xmlwidget.py
@@ -252,18 +252,53 @@ class XmlDelegate(QItemDelegate):
# fm.height just give it too small.
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()
+ text = index.model().data(index)
+ palette = QApplication.palette()
+ document = QTextDocument()
+ document.setDefaultFont(option.font)
+ nonHighGlobPattern = '<%s%s>'
+ nonHighAttPattern = ' %s="%s"'
+ highGlobPattern = '<%s%s>'
+ highAttPattern = ' %s="%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:
+ # many elems don't have atts...
+ attList = tmp[1].split()
+ for att in attList:
+ tmp = att.split('=')
+ attName = tmp[0]
+ attValue = tmp[1][1:-1]
+ AttListHtml += (nonHighAttPattern % (attName, attValue))
+ html = (globPattern % (elemName, AttListHtml))
+ return html
+ def colorize(color, text):
+ return '' + text + ''
+ 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))
+ document.setHtml(QString(htmlText))
+ else:
+ htmlText = getHtmlText(text, nonHighGlobPattern, nonHighAttPattern)
+ document.setHtml(QString(htmlText))
+ color = palette.highlight().color() \
+ if option.state & QStyle.State_Selected \
+ else palette.base().color()
painter.save()
- font = option.font
- font.setBold(True)
- painter.setFont(font)
- painter.drawText(option.rect, Qt.AlignLeft, QString(text))
- #print "ELEM DELEG CALLED"
+ print "COLOR:", color.name()
+ # 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):