Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion gitfourchette/graphview/commitlogdelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *


Expand Down Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion gitfourchette/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion gitfourchette/toolbox/fittedtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from math import ceil

from gitfourchette.qt import *
from gitfourchette.settings import CondensedFonts

class FittedText:
enable = True
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion gitfourchette/trtables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"),
Expand Down
Loading