diff --git a/gitfourchette/graphview/commitlogdelegate.py b/gitfourchette/graphview/commitlogdelegate.py index d874b60f..48eda5c8 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 GraphRefBoxWidth from gitfourchette.toolbox import * @@ -463,7 +464,9 @@ def _paintRefbox( maxWidth = settings.prefs.refBoxMaxWidth if text and maxWidth != 0: text, fittedFont, textWidth = FittedText.fit( - font, maxWidth, text, Qt.TextElideMode.ElideMiddle, limit=QFont.Stretch.Condensed) + font, maxWidth, text, Qt.TextElideMode.ElideMiddle, limit=QFont.Stretch.Condensed, + stretchMaxWidth=min(maxWidth, GraphRefBoxWidth.Standard), + ) else: textWidth = -rPadding # Negate rPadding diff --git a/gitfourchette/settings.py b/gitfourchette/settings.py index 64f8891c..4954b12a 100644 --- a/gitfourchette/settings.py +++ b/gitfourchette/settings.py @@ -65,6 +65,13 @@ class QtApiNames(enum.StrEnum): PyQt5 = "pyqt5" +class CondensedFonts(enum.Enum): + # For compatibility with old prefs.json files: + Never = False + Stretch = True + Always = "always" + + class LoggingLevel(enum.IntEnum): Benchmark = BENCHMARK_LOGGING_LEVEL Debug = logging.DEBUG @@ -144,7 +151,7 @@ class Prefs(PrefsFile): middleClickToStage : bool = False flattenLanes : bool = True animations : bool = True - condensedFonts : bool = True + condensedFonts : CondensedFonts = CondensedFonts.Stretch pygmentsPlugins : bool = False verbosity : LoggingLevel = LoggingLevel.Debug if APP_TESTMODE else LoggingLevel.Warning forceQtApi : QtApiNames = QtApiNames.Automatic diff --git a/gitfourchette/toolbox/fittedtext.py b/gitfourchette/toolbox/fittedtext.py index 0ba4fff6..fcde45e2 100644 --- a/gitfourchette/toolbox/fittedtext.py +++ b/gitfourchette/toolbox/fittedtext.py @@ -7,6 +7,7 @@ from math import ceil from gitfourchette.qt import * +from gitfourchette.settings import CondensedFonts class FittedText: enable = True @@ -37,9 +38,16 @@ def fit( mode=Qt.TextElideMode.ElideRight, limit=defaultStretchLimit, bypassSetting=False, + # When set, stretch the text as though the max width were this value: + stretchMaxWidth: int | None = None, ) -> tuple[str, QFont, int]: metrics = QFontMetricsF(wideFont) width = ceil(metrics.horizontalAdvance(text)) + if stretchMaxWidth is None: + stretchMaxWidth = maxWidth + if cls.enable == CondensedFonts.Always: + # Stretch as hard as we can -- as though there's no space + stretchMaxWidth = 0 if width < 1: return text, wideFont, 0 @@ -48,7 +56,7 @@ def fit( font = wideFont else: # Figure out upper bound for the stretch factor - baselineStretch = int(100 * maxWidth / width) + baselineStretch = int(100 * stretchMaxWidth / width) if baselineStretch >= 100: # No condensing needed - early out diff --git a/gitfourchette/trtables.py b/gitfourchette/trtables.py index 3077288d..3ca0bb64 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 GraphRowHeight, QtApiNames, GraphRefBoxWidth, RefSort, CondensedFonts from gitfourchette.toolbox import PatchPurpose, PathDisplayStyle, AuthorDisplayStyle from gitfourchette.repomodel import GpgStatus @@ -234,6 +234,12 @@ def _init_enums(): RefSort.UseGlobalPref : "", }, + CondensedFonts: { + CondensedFonts.Never : _p("never use condensed fonts", "Never"), + CondensedFonts.Stretch : _p("shrink only long text using condensed fonts", "For long text"), + CondensedFonts.Always : _p("use condensed fonts whenever possible", "Always"), + } + GpgStatus: { GpgStatus.Unsigned : _("Not signed"), GpgStatus.Pending : _("Signature not verified yet"),