Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
FontManager Class Reference

#include <font_manager.h>

Inheritance diagram for FontManager:

Public Types

enum class  ZoomScope { AppWide , ContentOnly }

Signals

void applicationFontChanged (QFont font)
void monospaceFontChanged (QFont font)
void zoomChanged ()

Public Member Functions

void setRegularFont (const QString &fontName)
void setMonospaceFont (const QString &fontName)
void zoomIn ()
void zoomOut ()
void resetZoom ()
void setZoomLevel (int level)
void restoreZoomLevel ()
int zoomLevel () const
bool canZoomIn () const
bool canZoomOut () const
void reapplyApplicationFonts ()

Static Public Member Functions

static FontManager * instance ()
static QFont font ()
static QFont monospaceFont ()
static QFont zoomedFont ()
static QFont zoomedMonospaceFont ()
static qreal zoomFactor ()
static QFont scaledFont (const QFont &base)
static QFont fontFromName (const QString &name)
static QString displayName (const QFont &font)
static QFont guaranteeMonospace (const QFont &font)
static QFont themeFont (const QString &fontName, bool monospace)
static QFont preferenceMonospaceFont (const QFont &font)

Static Public Attributes

static constexpr int MinZoomLevel = -10
static constexpr int MaxZoomLevel = 10

Protected Member Functions

 FontManager (QObject *parent=nullptr)
bool eventFilter (QObject *watched, QEvent *event) override

Detailed Description

Single authority for the application's fonts.

A singleton (like ThemeManager): access via FontManager::instance(). Its lifecycle is initiated by ThemeManager at startup — ThemeManager forces the instance into existence and feeds it the configured font names — but every font decision lives here: resolution/validation, the systemwide regular-font push, zoom, catching external (OS) font changes, and notification.

ThemeManager's entire font role is to read a configured font name and hand it to setRegularFont()/setMonospaceFont(). It performs no validation, fixed-pitch checking, or fallback — that is exclusively this class.

Three independent sources can change the font, and all converge here:

  • a theme switch (ThemeManager applies the theme fully, then calls the setters, so this class emits its normal font signals once the theme is in place — no separate silent path);
  • a zoom action (zoomIn/zoomOut/resetZoom);
  • the OS changing the system font (caught via QEvent::ThemeChange, after which the system general font is re-read and adopted unless a theme or preference overrides the regular font).

Per-class fonts: the platform gives some widget classes their own font (on macOS menus, tool buttons and small/mini controls are smaller than the general font). QApplication::setFont() without a class name discards them, so the constructor captures every class font the platform defined, and each push of the application font re-pushes them, zoomed. While the regular font is the platform general font the captured class fonts are used as they are; otherwise each class font is the regular font with the platform's size ratio between that class and the general font.

Consumer contract: a font-using widget owns its own font handling. In its constructor it seeds the current font from the static accessors (e.g. zoomedMonospaceFont()) and connects to the signal it needs (applicationFontChanged and/or monospaceFontChanged) for later theme, zoom, and OS changes. No external party wires a widget's fonts for it, so a widget created at any time is correct immediately and stays in sync on its own.

Member Enumeration Documentation

◆ ZoomScope

enum class FontManager::ZoomScope
strong

Whether a zoom step scales the whole application or only content views.

AppWide — zoom changes the app-default font via QApplication, so chrome (menus/toolbars/dialogs) scales too. ContentOnly — the app-default font stays at the base size; only widgets that explicitly pull the zoomed fonts scale.

v1 fixes this in the constructor. v2 will drive it from a preference on the "Font & Themes" page.

Member Function Documentation

◆ applicationFontChanged

void FontManager::applicationFontChanged ( QFont font)
signal

The regular font changed (theme load excepted — see class docs).

◆ canZoomIn()

bool FontManager::canZoomIn ( ) const
inline

Whether zoomIn() would change the zoom level.

◆ canZoomOut()

bool FontManager::canZoomOut ( ) const
inline

Whether zoomOut() would change the zoom level.

◆ displayName()

QString FontManager::displayName ( const QFont & font)
static

Family, style name and point size with one decimal, e.g. "Menlo Regular 12.0".

◆ font()

QFont FontManager::font ( )
static

Base (unzoomed) regular/proportional font.

◆ fontFromName()

QFont FontManager::fontFromName ( const QString & name)
static

Resolves a font descriptor (QFont::toString() form) or bare family name without touching FontManager state.

◆ guaranteeMonospace()

QFont FontManager::guaranteeMonospace ( const QFont & font)
static

Returns font, or a fixed-pitch substitute when it is proportional. Only the substitute is reset to the normal (upright) style.

◆ instance()

FontManager * FontManager::instance ( )
static

Returns the process-wide singleton, constructing it on first use.

◆ monospaceFont()

QFont FontManager::monospaceFont ( )
static

Base (unzoomed) monospace font.

◆ monospaceFontChanged

void FontManager::monospaceFontChanged ( QFont font)
signal

The monospace font changed (theme load excepted).

◆ preferenceMonospaceFont()

QFont FontManager::preferenceMonospaceFont ( const QFont & font)
static

The monospace font the gui.font_name preference resolves to. A family the user picked is used as chosen, also a proportional one; a family that is not installed, or a fixed-pitch family Qt matched to a proportional face, is passed through guaranteeMonospace().

◆ reapplyApplicationFonts()

void FontManager::reapplyApplicationFonts ( )

Pushes the application font and every captured per-class font again, and notifies all widgets, even when the application font did not change. Needed after QApplication::setStyle(), which rebuilds Qt's per-class font table from the platform theme.

◆ restoreZoomLevel()

void FontManager::restoreZoomLevel ( )

Applies the stored zoom level (recent.gui_zoom_level). Call it after every recent_read_profile_static() (at startup before the main window is created, and after a profile switch) and after the command line recent overrides (-o gui.zoom_level:N).

◆ scaledFont()

QFont FontManager::scaledFont ( const QFont & base)
static

base with the current zoom level applied, in the same way as the regular and monospace fonts.

◆ setMonospaceFont()

void FontManager::setMonospaceFont ( const QString & fontName)

Sets the monospace font. The user preference gui.font_name always wins when set; otherwise fontName; otherwise the system fixed font. A theme or system font is guaranteed to be fixed-pitch; the preference font is resolved by preferenceMonospaceFont(). Emits monospaceFontChanged when the resolved font actually changes.

Parameters
fontNamefont descriptor, or empty.

◆ setRegularFont()

void FontManager::setRegularFont ( const QString & fontName)

Sets the regular (proportional) font from a font descriptor string (QFont::toString() form, or a bare family name). An empty string means "no preference" and falls back to the system general font.

Emits applicationFontChanged when the resolved font actually changes, and always reconciles the QApplication font.

Parameters
fontNamefont descriptor, or empty for the system default.

◆ setZoomLevel()

void FontManager::setZoomLevel ( int level)

Sets the zoom level, clamped to MinZoomLevel..MaxZoomLevel, and stores the clamped level in recent.gui_zoom_level, also when it is unchanged.

◆ themeFont()

QFont FontManager::themeFont ( const QString & fontName,
bool monospace )
static

The font a theme's font descriptor resolves to, without the gui.font_name preference: the system general (or fixed) font when fontName is empty, else fontFromName(); a monospace result is passed through guaranteeMonospace().

◆ zoomChanged

void FontManager::zoomChanged ( )
signal

The zoom level changed. ThemeManager turns this into a themeChanged so stylesheet-driven widgets reload their zoom-scaled stylesheets.

◆ zoomedFont()

QFont FontManager::zoomedFont ( )
static

Regular font with the current zoom level applied.

◆ zoomedMonospaceFont()

QFont FontManager::zoomedMonospaceFont ( )
static

Monospace font with the current zoom level applied.

◆ zoomFactor()

qreal FontManager::zoomFactor ( )
static

Current zoom multiplier relative to the base regular font (1.0 at zoom level 0). For fractional values such as stylesheet font sizes; scale pixel values with ZoomScaling::scaledPixels() and fonts with scaledFont() instead of multiplying by this factor.

Member Data Documentation

◆ MinZoomLevel

int FontManager::MinZoomLevel = -10
staticconstexpr

Lowest and highest zoom level.


The documentation for this class was generated from the following files: