Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

repoview: html styling in Log column

Using StyledItemDelegate & QTextDocument approach taken from
http://stackoverflow.com/questions/2959850/how-to-make-item-view-render-rich-html-text-in-pyqt
Doesn't correctly render selection highlighting.

Changeset 6bba8bd1044f

Parent 2e774bd77439

by George Marrows

Changes to one file · Browse files at 6bba8bd1044f Showing diff from parent 2e774bd77439 Diff from another changeset...

 
23
24
25
 
 
26
27
28
 
62
63
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
66
67
 
76
77
78
 
 
 
79
80
81
 
23
24
25
26
27
28
29
30
 
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 
115
116
117
118
119
120
121
122
123
@@ -23,6 +23,8 @@
 from PyQt4.QtCore import *  from PyQt4.QtGui import *   +from tortoisehg.hgqt import qtlib +  connect = QObject.connect     @@ -62,6 +64,43 @@
  # QObject::startTimer: QTimer can only be used with threads started with QThread   self.entry.setCompleter(None)   +class HgItemDelegate(QStyledItemDelegate): + + # Possibly also useful: + # http://discussion.forum.nokia.com/forum/showthread.php?199279-qt-listview-problems + # http://talk.maemo.org/showthread.php?s=1b81e1a45eca6837ecc70e91f904b5ce&p=629592#post629592 + # http://stackoverflow.com/questions/2434004/how-does-one-paint-the-entire-rows-background-in-a-qstyleditemdelegate + + # This approach taken from + # http://stackoverflow.com/questions/2959850/how-to-make-item-view-render-rich-html-text-in-pyqt + def paint(self, painter, option, index): + if index.column() <> 3: # FIXME hardcoded + QStyledItemDelegate.paint(self, painter, option, index) + return + model = index.model() + record = model.data(index, Qt.DisplayRole) + doc = QTextDocument(self) + opts = dict(fg='black', bg='#ffffaa') # FIXME expect this from the model + doc.setHtml(qtlib.markup(str(record.toString()), **opts)) + doc.setTextWidth(option.rect.width()) + painter.save() + painter.translate(option.rect.topLeft()); + painter.setClipRect(option.rect.translated(-option.rect.topLeft())) + ctx = QAbstractTextDocumentLayout.PaintContext() + dl = doc.documentLayout() + dl.draw(painter, ctx) + painter.restore() + """ + This was in the original example but perhaps not needed by thg? + def sizeHint(self, option, index): + model = index.model() + record = model.data[index.row()] + doc = QTextDocument(self) + doc.setHtml(get_html_box(record)) + doc.setTextWidth(option.rect.width()) + return QSize(doc.idealWidth(), doc.size().height()) + """ +  class HgRepoView(QTableView):   """   A QTableView for displaying a HgRepoListModel, @@ -76,6 +115,9 @@
  self.horizontalHeader().setHighlightSections(False)   self.setSelectionMode(QAbstractItemView.SingleSelection)   self.setSelectionBehavior(QAbstractItemView.SelectRows) + + # FIXME use setItemDelegateForColumn + self.setItemDelegate(HgItemDelegate(self))     self.createActions()   self.createToolbars()