Angel Ezquerra  committed 8a8cbed

repowidget, status, manifest: change background color when a filter is applied

This patch changes the background color of filtered lists and trees.

This takes into account whether the default background color is light or dark.
If the default background color is light, the filtered color is a light yellow,
while when the background color dark, the filtered color is a dark grey.

In order to make it easy to filter different lists with the same colors, a new
PaletteSwitcher class has been added to qtlib. An instance of this class must
be added to any view that must change its background color when filtered. The
class constructor takes the "parent" or "target" object as its only parameter.

In order to change the background color, one must simply call the
"enablefilterpalette" method of the PaletteSwitcher instance to enable or
disable the background change.

  • Participants
  • Parent commits fe5be77
  • Branches default

Comments (0)

Files changed (5)

File tortoisehg/hgqt/

         self._filterupdatetimer = QTimer(self, interval=200, singleShot=True)
+        def applyFilter():
+            filtertext = self.le.text()
+            self._treemodel.setNameFilter(filtertext)
+            self._treeview.enablefilterpalette(filtertext)
-            lambda: self._treemodel.setNameFilter(self.le.text()))
+            applyFilter)
     def _autoexpandtree(self):
 class QManifestTreeView(QTreeView):
     topreached = pyqtSignal(int)
+    def __init__(self, *args, **kwargs):
+        QTreeView.__init__(self, *args, **kwargs)
+        self._paletteswitcher = qtlib.PaletteSwitcher(self)
     def keyPressEvent(self, event):
         if self.currentIndex().row() == 0 \
                 and not self.currentIndex().parent().isValid():
         # default handler for event
         super(QManifestTreeView, self).keyPressEvent(event)
+    def enablefilterpalette(self, enable):
+        self._paletteswitcher.enablefilterpalette(enable)

File tortoisehg/hgqt/

     """Create [QShortcut,...] for all key bindings of the given StandardKey"""
     return [QShortcut(keyseq, *args, **kwargs)
             for keyseq in QKeySequence.keyBindings(key)]
+class PaletteSwitcher(object):
+    """
+    Class that can be used to enable a predefined, alterantive background color
+    for a widget
+    This is normally used to change the color of widgets when they display some
+    "filtered" content which is a subset of the actual widget contents.
+    The alternative background color is fixed, and depends on the original
+    background color (dark and light backgrounds use a different alternative
+    color).
+    The alterenative color cannot be changed because the idea is to set a
+    consistent "filter" style for all widgets.
+    An instance of this class must be added as a property of the widget whose
+    background we want to change. The constructor takes the "target widget" as
+    its only parameter.
+    In order to enable or disable the background change, simply call the
+    enablefilterpalette() method.
+    """
+    def __init__(self, targetwidget):
+        self._targetwidget = targetwidget
+        self._defaultpalette = targetwidget.palette()
+        bgcolor = self._defaultpalette.color(QPalette.Base)
+        if <= 128:
+            # Light theme
+            filterbgcolor = QColor('#FFFFB7')
+        else:
+            # Dark theme
+            filterbgcolor = QColor('darkgrey')
+        self._filterpalette = QPalette()
+        self._filterpalette.setColor(QPalette.Base, filterbgcolor)
+    def enablefilterpalette(self, enabled=False):
+        if enabled:
+            pl = self._filterpalette
+        else:
+            pl = self._defaultpalette
+        self._targetwidget.setPalette(pl)

File tortoisehg/hgqt/

 from tortoisehg.util import hglib
 from tortoisehg.hgqt.i18n import _
-from tortoisehg.hgqt import htmldelegate
+from tortoisehg.hgqt import htmldelegate, qtlib
 from tortoisehg.hgqt.logcolumns import ColumnSelectDialog
 from PyQt4.QtCore import *
+        self._paletteswitcher = qtlib.PaletteSwitcher(self)
         super(HgRepoView, self).resizeEvent(e)
+    def enablefilterpalette(self, enable):
+        self._paletteswitcher.enablefilterpalette(enable)
 class HgRepoViewStyle(QStyle):
     "Override a style's drawPrimitive method to customize the drop indicator"
     def __init__(self, style):

File tortoisehg/hgqt/

     def _unapplyRevisionSet(self):
         self.outgoingMode = False
+        self.repoview.enablefilterpalette(False)
         if not self.revset:
             return False
         self.revset = []
         self._reload_rev = self.revset[0]
+        self.repoview._paletteswitcher.enablefilterpalette(revs)
     def filterToggled(self, checked):

File tortoisehg/hgqt/

         model =
         if model:
     def updateCheckCount(self):
         model =
+        self._paletteswitcher = qtlib.PaletteSwitcher(self)
     def scrollTo(self, index, hint=QAbstractItemView.EnsureVisible):
         # don't update horizontal position by selection change
         # Invalid selectionModel found
         return []
+    def enablefilterpalette(self, enable):
+        self._paletteswitcher.enablefilterpalette(enable)
 class WctxModel(QAbstractTableModel):
     checkToggled = pyqtSignal()