Yuya Nishihara avatar Yuya Nishihara committed 79e5745

import filter palette, etc.

Comments (0)

Files changed (4)

docdiff-base.diff

 # HG changeset patch
-# Parent 10e32e43f5a1f583fc278cfd097e2317d3d595a3
+# Date 1346680648 -32400
+# Parent f23bf9738240c16fd709e8167761fa1210f7c643
 docdiff: don't clobber 'base' argument (fixes #2076)
 
 f5ff1858e79e changed to overwrite 'base' by basename of 'output' argument,
 which is unwanted side effect, I guess.
 
-
 diff --git a/win32/docdiff.py b/win32/docdiff.py
 --- a/win32/docdiff.py
 +++ b/win32/docdiff.py

filter-palette.patch

+# HG changeset patch
+# User Angel Ezquerra <angel.ezquerra@gmail.com>
+# Date 1345665431 -7200
+# Branch stable
+# Node ID a0f2dad9a121679761124e22533211c749db8a4c
+# Parent  cd0980debb0a5a331ee1d625b00beca032dad375
+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.
+
+diff --git a/tortoisehg/hgqt/manifestdialog.py b/tortoisehg/hgqt/manifestdialog.py
+--- a/tortoisehg/hgqt/manifestdialog.py
++++ b/tortoisehg/hgqt/manifestdialog.py
+@@ -283,8 +283,13 @@
+         self._filterupdatetimer = QTimer(self, interval=200, singleShot=True)
+         self.le.returnPressed.connect(self._treeview.expandAll)
+         self.le.textChanged.connect(self._filterupdatetimer.start)
++        def applyFilter():
++            filtertext = self.le.text()
++            self._treemodel.setNameFilter(filtertext)
++            self._treeview.enablefilterpalette(filtertext)
++
+         self._filterupdatetimer.timeout.connect(
+-            lambda: self._treemodel.setNameFilter(self.le.text()))
++            applyFilter)
+ 
+     @pyqtSlot()
+     def _autoexpandtree(self):
+@@ -444,6 +449,11 @@
+ 
+ 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():
+@@ -453,3 +463,6 @@
+                 return
+         # default handler for event
+         super(QManifestTreeView, self).keyPressEvent(event)
++
++    def enablefilterpalette(self, enable):
++        self._paletteswitcher.enablefilterpalette(enable)
+diff --git a/tortoisehg/hgqt/qtlib.py b/tortoisehg/hgqt/qtlib.py
+--- a/tortoisehg/hgqt/qtlib.py
++++ b/tortoisehg/hgqt/qtlib.py
+@@ -1135,3 +1135,44 @@
+     """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=None):
++        self._targetwidget = targetwidget
++        self._defaultpalette = targetwidget.palette()
++        bgcolor = self._defaultpalette.color(QPalette.Base)
++        if bgcolor.black() <= 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)
+diff --git a/tortoisehg/hgqt/repoview.py b/tortoisehg/hgqt/repoview.py
+--- a/tortoisehg/hgqt/repoview.py
++++ b/tortoisehg/hgqt/repoview.py
+@@ -18,7 +18,7 @@
+ 
+ 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 *
+@@ -68,6 +68,7 @@
+         self.setDragDropMode(QAbstractItemView.InternalMove)
+ 
+         self.setStyle(HgRepoViewStyle(self.style()))
++        self._paletteswitcher = qtlib.PaletteSwitcher(self)
+ 
+         self.setSelectionMode(QAbstractItemView.ExtendedSelection)
+         self.setSelectionBehavior(QAbstractItemView.SelectRows)
+@@ -321,6 +322,9 @@
+ 
+         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):
+diff --git a/tortoisehg/hgqt/repowidget.py b/tortoisehg/hgqt/repowidget.py
+--- a/tortoisehg/hgqt/repowidget.py
++++ b/tortoisehg/hgqt/repowidget.py
+@@ -514,6 +514,7 @@
+     def _unapplyRevisionSet(self):
+         self.toolbarVisibilityChanged.emit()
+         self.outgoingMode = False
++        self.repoview.enablefilterpalette(False)
+         if not self.revset:
+             return False
+         self.revset = []
+@@ -536,6 +537,7 @@
+             self.refresh()
+         self.repoview.resetBrowseHistory(self.revset)
+         self._reload_rev = self.revset[0]
++        self.repoview._paletteswitcher.enablefilterpalette(revs)
+ 
+     @pyqtSlot(bool)
+     def filterToggled(self, checked):
+diff --git a/tortoisehg/hgqt/status.py b/tortoisehg/hgqt/status.py
+--- a/tortoisehg/hgqt/status.py
++++ b/tortoisehg/hgqt/status.py
+@@ -352,6 +352,7 @@
+         model = self.tv.model()
+         if model:
+             model.setFilter(match)
++            self.tv.enablefilterpalette(bool(match))
+ 
+     def updateCheckCount(self):
+         model = self.tv.model()
+@@ -500,6 +501,7 @@
+         self.setContextMenuPolicy(Qt.CustomContextMenu)
+         self.customContextMenuRequested.connect(self.menuRequested)
+         self.setTextElideMode(Qt.ElideLeft)
++        self._paletteswitcher = qtlib.PaletteSwitcher(self)
+ 
+     def scrollTo(self, index, hint=QAbstractItemView.EnsureVisible):
+         # don't update horizontal position by selection change
+@@ -552,6 +554,9 @@
+             return self.selectionModel().selectedRows()
+         # Invalid selectionModel found
+         return []
++    
++    def enablefilterpalette(self, enable):
++        self._paletteswitcher.enablefilterpalette(enable)
+ 
+ class WctxModel(QAbstractTableModel):
+     checkToggled = pyqtSignal()
 shortcut.diff
 docdiff-base.diff
+filter-palette.patch
 fileview-time.diff
 reporeg-moveactions.diff
 reporeg-saverestore.diff
 # HG changeset patch
-# Parent 32c7eba79008386c967241aa7c5dd67f84261ae0
+# Date 1346680656 -32400
+# Parent cd0980debb0a5a331ee1d625b00beca032dad375
 shortcuts: give Ctrl+Shift+L for openlocal (fixes #2118)
 
 Ctrl+Shift+O conflicts with "Show Repository Registry".
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.