Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0, 2.0.1, and 2.0.2

stable htmldelegate: unify method to build QTextDocument

Both paint() and sizeHint() should use doc of the same option.

Changeset b99f942c55e5

Parent 6b3624b649cf

by Yuya Nishihara

Changes to one file · Browse files at b99f942c55e5 Showing diff from parent 6b3624b649cf Diff from another changeset...

 
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
37
38
39
40
41
 
55
56
57
 
 
 
 
 
58
59
60
 
61
62
63
64
 
 
65
66
67
 
 
22
23
24
 
 
 
 
 
25
26
27
28
29
30
 
31
32
 
33
34
35
 
49
50
51
52
53
54
55
56
57
58
59
60
61
 
 
 
62
63
64
 
 
65
@@ -22,20 +22,14 @@
  def paint(self, painter, option, index):   if self.cols and index.column() not in self.cols:   return QStyledItemDelegate.paint(self, painter, option, index) - try: - text = index.model().data(index, Qt.DisplayRole).toString() - except error.RevlogError, e: - # this can happen if revlog is being truncated while we read it - text = _('?? Error: %s ??') % hglib.tounicode(str(e))     # draw selection   option = QStyleOptionViewItemV4(option)   self.parent().style().drawControl(QStyle.CE_ItemViewItem, option, painter)     # draw text - doc = QTextDocument(defaultFont=option.font) + doc = self._builddoc(option, index)   painter.save() - doc.setHtml(text)   painter.setClipRect(option.rect)   painter.translate(QPointF(   option.rect.left(), @@ -55,13 +49,17 @@
  painter.restore()     def sizeHint(self, option, index): + doc = self._builddoc(option, index) + doc.setTextWidth(option.rect.width()) + return QSize(doc.idealWidth() + 5, doc.size().height()) + + def _builddoc(self, option, index):   try:   text = index.model().data(index, Qt.DisplayRole).toString()   except error.RevlogError, e: + # this can happen if revlog is being truncated while we read it   text = _('?? Error: %s ??') % hglib.tounicode(str(e)) - doc = QTextDocument() - doc.setDefaultStyleSheet(qtlib.thgstylesheet) - doc.setDefaultFont(option.font) + + doc = QTextDocument(defaultFont=option.font)   doc.setHtml(text) - doc.setTextWidth(option.rect.width()) - return QSize(doc.idealWidth() + 5, doc.size().height()) + return doc