Wireshark 4.7.2
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
font_manager.h
Go to the documentation of this file.
1
9
10#ifndef FONT_MANAGER_H
11#define FONT_MANAGER_H
12
13#include <QFont>
14#include <QMutex>
15#include <QObject>
16
45class FontManager : public QObject
46{
47 Q_OBJECT
48public:
60 enum class ZoomScope {
61 AppWide,
62 ContentOnly
63 };
64
66 static FontManager *instance();
67
68 // --- Value accessors: static only (single instance, no instance
69 // duplicates, so there is no static/instance name clash) ---
70
72 static QFont font();
74 static QFont monospaceFont();
76 static QFont zoomedFont();
78 static QFont zoomedMonospaceFont();
79
83 static qreal zoomFactor();
84
85 // --- Mutators & queries ---
86
97 void setRegularFont(const QString &fontName);
98
107 void setMonospaceFont(const QString &fontName);
108
109 void zoomIn();
110 void zoomOut();
111 void resetZoom();
112 void setZoomLevel(int level);
113 int zoomLevel() const { return zoom_level_; }
114
115signals:
123
124protected:
125 explicit FontManager(QObject *parent = nullptr);
126 ~FontManager();
127
128 // Catches QEvent::ApplicationFontChange on qApp. Distinguishes our own
129 // push from an external/OS change by comparing the now-current
130 // qApp->font() against applicationFont() (the value we would push): when
131 // they match the change is ours and is ignored; when they differ the OS
132 // changed the font and we adopt it (unless a theme/pref overrides regular).
133 bool eventFilter(QObject *watched, QEvent *event) override;
134
135private:
136 static FontManager *instance_;
137 static QMutex mutex_;
138
139 QFont base_regular_;
140 QFont base_monospace_;
141 int zoom_level_ = 0;
142 ZoomScope zoom_scope_;
143
144 // True when a theme or pref explicitly set the regular font; while set,
145 // an external OS font change is NOT adopted (our override wins).
146 bool regular_overridden_ = false;
147
148 QFont applicationFont() const;
149 QFont zoomed(const QFont &base) const;
150 void applyApplicationFont();
151 void applyZoom();
152 void syncMonospacePref();
153
154 static QFont fontFromName(const QString &name);
155 static QFont guaranteeMonospace(const QFont &font);
156};
157
158#endif /* FONT_MANAGER_H */
Definition font_manager.h:46
static QFont zoomedFont()
Definition font_manager.cpp:111
void monospaceFontChanged(QFont font)
static QFont monospaceFont()
Definition font_manager.cpp:106
static QFont zoomedMonospaceFont()
Definition font_manager.cpp:117
void setRegularFont(const QString &fontName)
Definition font_manager.cpp:138
ZoomScope
Definition font_manager.h:60
static qreal zoomFactor()
Definition font_manager.cpp:123
void applicationFontChanged(QFont font)
void setMonospaceFont(const QString &fontName)
Definition font_manager.cpp:155
static QFont font()
Definition font_manager.cpp:101
static FontManager * instance()
Definition font_manager.cpp:54
void zoomChanged()