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

grep: use column delegate, avoid a duplicate class

Changeset e4482e1d8bd9

Parent f2b7cd75a6fc

by Steve Borho

Changes to 2 files · Browse files at e4482e1d8bd9 Showing diff from parent f2b7cd75a6fc Diff from another changeset...

 
10
11
12
13
 
14
15
16
 
27
28
29
30
31
32
33
 
227
228
229
230
 
 
231
232
233
 
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
 
10
11
12
 
13
14
15
16
 
27
28
29
 
30
31
32
 
226
227
228
 
229
230
231
232
233
 
325
326
327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
329
@@ -10,7 +10,7 @@
   from mercurial import ui, hg, error, commands   -from tortoisehg.hgqt import htmlui, visdiff, qtlib +from tortoisehg.hgqt import htmlui, visdiff, qtlib, htmllistview  from tortoisehg.util import paths, hglib  from tortoisehg.hgqt.i18n import _   @@ -27,7 +27,6 @@
 # context menu for matches  # emit errors to parent's status bar  # emit to parent's progress bar -# turn HTMLDelegate into a column delegate, merge back with htmllistview    class SearchWidget(QWidget):   def __init__(self, root=None, parent=None): @@ -227,7 +226,8 @@
  def __init__(self, repo, parent=None):   QTreeView.__init__(self, parent)   self.repo = repo - self.setItemDelegate(HTMLDelegate(self)) + self.delegate = htmllistview.HTMLDelegate(self) + self.setItemDelegateForColumn(COL_TEXT, self.delegate)   self.setSelectionMode(QTreeView.ExtendedSelection)   self.setContextMenuPolicy(Qt.CustomContextMenu)   self.connect(self, SIGNAL('customContextMenuRequested(const QPoint &)'), @@ -325,38 +325,5 @@
  self.rows = []   self.endRemoveRows()   -class HTMLDelegate(QStyledItemDelegate): - def __init__(self, parent=0): - QStyledItemDelegate.__init__(self, parent) - - def paint(self, painter, option, index): - if index.column() != COL_TEXT: - return QStyledItemDelegate.paint(self, painter, option, index) - text = index.model().data(index, Qt.DisplayRole).toString() - palette = QApplication.palette() - doc = QTextDocument() - doc.setDefaultFont(option.font) - doc.setDefaultStyleSheet(qtlib.thgstylesheet) - painter.save() - if option.state & QStyle.State_Selected: - doc.setHtml('<font color=%s>%s</font>' % ( - palette.highlightedText().color().name(), text)) - bgcolor = palette.highlight().color() - painter.fillRect(option.rect, bgcolor) - else: - doc.setHtml(text) - painter.translate(option.rect.left(), option.rect.top()) - doc.drawContents(painter) - painter.restore() - - def sizeHint(self, option, index): - text = index.model().data(index, Qt.DisplayRole).toString() - doc = QTextDocument() - doc.setDefaultStyleSheet(qtlib.thgstylesheet) - doc.setDefaultFont(option.font) - doc.setHtml(text) - doc.setTextWidth(option.rect.width()) - return QSize(doc.idealWidth() + 5, doc.size().height()) -  def run(ui, *pats, **opts):   return SearchWidget()
 
86
87
88
89
 
90
 
91
92
 
 
93
94
95
 
86
87
88
 
89
90
91
92
93
94
95
96
97
98
@@ -86,10 +86,13 @@
     class HTMLDelegate(QStyledItemDelegate): - def __init__(self, parent=0): + def __init__(self, parent=0, cols=None):   QStyledItemDelegate.__init__(self, parent) + self.cols = cols     def paint(self, painter, option, index): + if self.cols and index.column() not in self.cols: + return QStyledItemDelegate.paint(self, painter, option, index)   text = index.model().data(index, Qt.DisplayRole).toString()   palette = QApplication.palette()   doc = QTextDocument()