diff --git a/gitfourchette/graphview/commitlogdelegate.py b/gitfourchette/graphview/commitlogdelegate.py index d874b60f..8ce81a36 100644 --- a/gitfourchette/graphview/commitlogdelegate.py +++ b/gitfourchette/graphview/commitlogdelegate.py @@ -17,6 +17,7 @@ from gitfourchette.porcelain import * from gitfourchette.qt import * from gitfourchette.repomodel import UC_FAKEID, UC_FAKEREF, RepoModel, GpgStatus +from gitfourchette.settings import CommitHashDisplay from gitfourchette.toolbox import * @@ -157,10 +158,16 @@ def _paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelI dateWidth = 0 elif rect.width() <= NARROW_WIDTH[1]: authorWidth = int(lerp(authorWidth/2, authorWidth, rect.width(), NARROW_WIDTH[0], NARROW_WIDTH[1])) - leftBoundHash = rect.left() - leftBoundSummary = leftBoundHash + hcw * settings.prefs.shortHashChars + XSPACING + + hashLeft = settings.prefs.commitHashDisplay == CommitHashDisplay.Left + hashRight = settings.prefs.commitHashDisplay == CommitHashDisplay.Right + hashWidth = hcw * settings.prefs.shortHashChars + XSPACING * (3 if hashRight else 1) + hashMonospace = hashLeft + + leftBoundSummary = rect.left() + (hashWidth if hashLeft else 0) leftBoundDate = rect.width() - dateWidth - leftBoundName = leftBoundDate - authorWidth + leftBoundName = leftBoundDate - authorWidth - (hashWidth if hashRight else 0) + leftBoundHash = rect.left() if hashLeft else leftBoundDate - hashWidth rightBound = rect.right() # Get the info we need about the commit @@ -197,7 +204,7 @@ def _paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelI else: commit = None oid = None - hashText = "·" * settings.prefs.shortHashChars + hashText = "·" * settings.prefs.shortHashChars if hashLeft else "" authorText = "" dateText = "" searchTerm = "" @@ -237,14 +244,19 @@ def highlight(fullText: str, needlePos: int, needleLen: int): SearchBar.highlightNeedle(painter, rect, fullText, needlePos, needleLen) # ------ Hash - charRect = QRect(leftBoundHash, rect.top(), hcw, rect.height()) - painter.save() - if not isSelected: # use muted color for hash if not selected - painter.setPen(palette.color(colorGroup, QPalette.ColorRole.PlaceholderText)) - for hashChar in hashText: - painter.drawText(charRect, Qt.AlignmentFlag.AlignCenter, hashChar) - charRect.translate(hcw, 0) - painter.restore() + if hashLeft or hashRight: + width = hcw if hashMonospace else hashWidth + charRect = QRect(leftBoundHash, rect.top(), width, rect.height()) + painter.save() + if not isSelected: # use muted color for hash if not selected + painter.setPen(palette.color(colorGroup, QPalette.ColorRole.PlaceholderText)) + if hashMonospace: + for hashChar in hashText: + painter.drawText(charRect, Qt.AlignmentFlag.AlignCenter, hashChar) + charRect.translate(hcw, 0) + else: + painter.drawText(charRect, Qt.AlignmentFlag.AlignVCenter, hashText) + painter.restore() # ------ Highlight searched hash if searchTerm and searchTermLooksLikeHash and commit and str(commit).startswith(searchTerm): diff --git a/gitfourchette/settings.py b/gitfourchette/settings.py index 64f8891c..88aa6007 100644 --- a/gitfourchette/settings.py +++ b/gitfourchette/settings.py @@ -52,6 +52,12 @@ class GraphRowHeight(enum.IntEnum): Spacious = 175 +class CommitHashDisplay(enum.IntEnum): + Left = 0 + Right = 1 + Hide = 2 + + class GraphRefBoxWidth(enum.IntEnum): IconsOnly = 0 Standard = 120 @@ -105,6 +111,7 @@ class Prefs(PrefsFile): graphRowHeight : GraphRowHeight = GraphRowHeight.Relaxed refBoxMaxWidth : GraphRefBoxWidth = GraphRefBoxWidth.Standard authorDisplayStyle : AuthorDisplayStyle = AuthorDisplayStyle.FullName + commitHashDisplay : CommitHashDisplay = CommitHashDisplay.Left shortTimeFormat : str = list(SHORT_DATE_PRESETS.values())[0] maxCommits : int = 10000 authorDiffAsterisk : bool = True diff --git a/gitfourchette/trtables.py b/gitfourchette/trtables.py index 3077288d..9ec0191a 100644 --- a/gitfourchette/trtables.py +++ b/gitfourchette/trtables.py @@ -103,7 +103,7 @@ def _init_enums(): from gitfourchette.porcelain import FileMode, NameValidationError from gitfourchette.toolbox import toLengthVariants from gitfourchette.sidebar.sidebarmodel import SidebarItem - from gitfourchette.settings import GraphRowHeight, QtApiNames, GraphRefBoxWidth, RefSort + from gitfourchette.settings import CommitHashDisplay, GraphRowHeight, QtApiNames, GraphRefBoxWidth, RefSort from gitfourchette.toolbox import PatchPurpose, PathDisplayStyle, AuthorDisplayStyle from gitfourchette.repomodel import GpgStatus @@ -205,6 +205,12 @@ def _init_enums(): AuthorDisplayStyle.EmailUserName: _("Abbreviated email"), }, + CommitHashDisplay: { + CommitHashDisplay.Left : _p("show commit hashes", "On left"), + CommitHashDisplay.Right : _p("show commit hashes", "On right"), + CommitHashDisplay.Hide : _p("show commit hashes", "Hide"), + }, + GraphRowHeight: { GraphRowHeight.Cramped : _p("row spacing", "Cramped"), GraphRowHeight.Tight : _p("row spacing", "Tight"), @@ -381,6 +387,7 @@ def _init_prefKeys(): "shortTimeFormat_help": TrTables._timeFormatTable(), "pathDisplayStyle": _("Path display style"), "authorDisplayStyle": _("Author display style"), + "commitHashDisplay": _("Show commit hashes"), "maxRecentRepos": _("Remember up to # recent repositories"), "showStatusBar": _("Show status bar"), "showToolBar": _("Show toolbar"),