Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
font_selection_widget.h
Go to the documentation of this file.
1
9
10#ifndef FONT_SELECTION_WIDGET_H
11#define FONT_SELECTION_WIDGET_H
12
13#include <QFont>
14#include <QString>
15#include <QWidget>
16
17namespace Ui {
18class FontSelectionWidget;
19}
20
31class FontSelectionWidget : public QWidget
32{
33 Q_OBJECT
34
35public:
41
43 enum class FontClass {
46 };
47
54 Q_DECLARE_FLAGS(Features, Feature)
55
56
57 struct Selection {
58 QString family;
59 qreal pointSize = 0;
60
62 bool operator==(const Selection &other) const;
64 bool operator!=(const Selection &other) const { return !(*this == other); }
65 };
66
71 explicit FontSelectionWidget(QWidget *parent = nullptr);
72
75
84 void setFamilyFilter(FamilyFilter filter);
85
88
94
96 FontClass fontClass() const;
97
102 void setFeatures(Features features);
103
105 Features features() const;
106
115 void setDefaultAllowed(bool allowed);
116
118 bool defaultAllowed() const;
119
124 void setSelection(const Selection &sel);
125
127 Selection selection() const;
128
137 void setSelectedFont(const QFont &font);
138
146 QFont selectedFont() const;
147
155 QFont resolvedFont() const;
156
161 void setSampleText(const QString &text);
162
163signals:
165 void changed();
166
167protected:
169 void showEvent(QShowEvent *event) override;
170
171private:
172 QString lookupFamily() const;
173 void fillFamilyList();
174 void applyFamilyTextFilter();
175 void fillStyleList();
176 void fillSizeList();
177 void updateSizeSpin();
178 void selectSizeRow();
179 void updateEffects();
180 void resetTo(const QFont &font, const Selection &sel);
181 void refreshAll();
182 void refreshSample();
183 void familySelectionChanged();
184 void monospaceToggled(bool checked);
185 void styleSelectionChanged();
186 void sizeSelectionChanged();
187 void sizeValueChanged(double value);
188 void strikeOutToggled(bool checked);
189 void underlineToggled(bool checked);
190
191 Ui::FontSelectionWidget *ui;
192 QFont base_;
193 Selection sel_;
194 QString style_;
195 bool strikeOut_ = false;
196 bool underline_ = false;
197 bool familyEdited_ = false;
198 bool styleEdited_ = false;
199 bool sizeEdited_ = false;
200 bool strikeOutEdited_ = false;
201 bool underlineEdited_ = false;
203 FontClass fontClass_ = FontClass::Regular;
204 Features features_ = Features(StyleFeature | EffectsFeature | FamilyFilterFeature);
205 bool defaultAllowed_ = false;
206 int filledGeneration_ = -1;
207 QString sampleText_;
208};
209
210Q_DECLARE_OPERATORS_FOR_FLAGS(FontSelectionWidget::Features)
211
212#endif // FONT_SELECTION_WIDGET_H
Selection selection() const
Return the current Selection.
Definition font_selection_widget.cpp:269
Features features() const
Return the shown optional parts.
Definition font_selection_widget.cpp:226
void setFontClass(FontClass fontClass)
Choose what an empty family resolves to. The default is Regular.
Definition font_selection_widget.cpp:206
QFont selectedFont() const
Return the edited font.
Definition font_selection_widget.cpp:279
FontSelectionWidget(QWidget *parent=nullptr)
Construct a FontSelectionWidget.
Definition font_selection_widget.cpp:139
void setDefaultAllowed(bool allowed)
Allow the "no explicit font" state.
Definition font_selection_widget.cpp:231
FontClass
What an empty family resolves to.
Definition font_selection_widget.h:43
@ Monospace
the system fixed font, guaranteed fixed-pitch
Definition font_selection_widget.h:45
@ Regular
the system general font
Definition font_selection_widget.h:44
void setSampleText(const QString &text)
Replace the sample text.
Definition font_selection_widget.cpp:322
FamilyFilter
Which families the family list offers.
Definition font_selection_widget.h:37
@ FixedPitchOnly
fixed-pitch families only
Definition font_selection_widget.h:39
@ AllFamilies
every installed family
Definition font_selection_widget.h:38
Feature
Optional parts of the selector.
Definition font_selection_widget.h:49
@ StyleFeature
the style label and list
Definition font_selection_widget.h:50
@ EffectsFeature
the Effects group (strikeout, underline)
Definition font_selection_widget.h:51
@ FamilyFilterFeature
the "Show only monospaced fonts" checkbox
Definition font_selection_widget.h:52
void setFeatures(Features features)
Show or hide the optional parts. The default is all features.
Definition font_selection_widget.cpp:217
FontClass fontClass() const
Return the font class.
Definition font_selection_widget.cpp:212
void setFamilyFilter(FamilyFilter filter)
Choose which families are offered. The default is AllFamilies.
Definition font_selection_widget.cpp:191
bool defaultAllowed() const
Return whether the default state is allowed.
Definition font_selection_widget.cpp:237
void setSelectedFont(const QFont &font)
Set the value from a QFont without emitting changed().
Definition font_selection_widget.cpp:274
QFont resolvedFont() const
Return the font the sample is drawn with.
Definition font_selection_widget.cpp:309
FamilyFilter familyFilter() const
Return the active family filter.
Definition font_selection_widget.cpp:201
~FontSelectionWidget()
Destroy the widget and its UI form.
Definition font_selection_widget.cpp:186
void showEvent(QShowEvent *event) override
Fill the lists on first show and refresh the sample.
Definition font_selection_widget.cpp:328
void changed()
Emitted when the user changes family, style, size or an effect.
void setSelection(const Selection &sel)
Set the value from a Selection without emitting changed().
Definition font_selection_widget.cpp:257
The edited value: family and point size.
Definition font_selection_widget.h:57
bool operator==(const Selection &other) const
Compare family and point size.
Definition font_selection_widget.cpp:134
qreal pointSize
<= 0: default size (only meaningful with defaultAllowed)
Definition font_selection_widget.h:59
QString family
empty: platform default (only meaningful with defaultAllowed)
Definition font_selection_widget.h:58
bool operator!=(const Selection &other) const
Negation of operator==.
Definition font_selection_widget.h:64