|
Wireshark 5.1.0
The Wireshark network protocol analyzer
|
#include <font_manager.h>
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 |
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:
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.
|
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.
|
signal |
The regular font changed (theme load excepted — see class docs).
|
inline |
Whether zoomIn() would change the zoom level.
|
inline |
Whether zoomOut() would change the zoom level.
|
static |
Family, style name and point size with one decimal, e.g. "Menlo Regular 12.0".
|
static |
Base (unzoomed) regular/proportional font.
|
static |
Resolves a font descriptor (QFont::toString() form) or bare family name without touching FontManager state.
|
static |
Returns font, or a fixed-pitch substitute when it is proportional. Only the substitute is reset to the normal (upright) style.
|
static |
Returns the process-wide singleton, constructing it on first use.
|
static |
Base (unzoomed) monospace font.
|
signal |
The monospace font changed (theme load excepted).
|
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().
| 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.
| 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).
|
static |
base with the current zoom level applied, in the same way as the regular and monospace fonts.
| 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.
| fontName | font descriptor, or empty. |
| 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.
| fontName | font descriptor, or empty for the system default. |
| 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.
|
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().
|
signal |
The zoom level changed. ThemeManager turns this into a themeChanged so stylesheet-driven widgets reload their zoom-scaled stylesheets.
|
static |
Regular font with the current zoom level applied.
|
static |
Monospace font with the current zoom level applied.
|
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.
|
staticconstexpr |
Lowest and highest zoom level.