Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
theme_preview_widget.h
Go to the documentation of this file.
1
9
10#ifndef THEME_PREVIEW_WIDGET_H
11#define THEME_PREVIEW_WIDGET_H
12
13#include <QColor>
14#include <QFont>
15#include <QFontMetricsF>
16#include <QHash>
17#include <QImage>
18#include <QPair>
19#include <QPainterPath>
20#include <QRect>
21#include <QRectF>
22#include <QWidget>
23
24#include <memory>
25
26class QPainter;
27class QPaintEvent;
28class QContextMenuEvent;
29class QMenu;
30class QMouseEvent;
31class QSize;
32
36
48class ThemePreviewWidget : public QWidget
49{
50 Q_OBJECT
51public:
52 explicit ThemePreviewWidget(QWidget *parent = nullptr);
53
66 void setPreviewColors(const QHash<ThemeManager::ThemeToken, QColor> &colors,
67 bool declaresWindow = false);
68
84 void setShowColoringRules(bool show);
85
91 void setPreviewFonts(const QFont &regular, const QFont &monospace);
92
93 bool showColoringRules() const { return show_coloring_rules_; }
94
100 ThemePreviewPicker &picker() { return picker_; }
101
102signals:
103 void showColoringRulesChanged(bool show);
104
107
112 void pickMenuRequested(QMenu *menu, QAction *before,
113 const QList<ThemePreviewPick::Layer> &layers);
114
117
118protected:
119 void paintEvent(QPaintEvent *evt) override;
120 void contextMenuEvent(QContextMenuEvent *event) override;
121 void mouseMoveEvent(QMouseEvent *event) override;
122 void mousePressEvent(QMouseEvent *event) override;
123 QSize minimumSizeHint() const override;
124
125private:
126 QHash<ThemeManager::ThemeToken, QColor> colors_;
127
130 bool declaresWindow_ = false;
131
134 bool show_coloring_rules_ = false;
135
137 bool has_preview_fonts_ = false;
138 QFont preview_regular_font_;
139 QFont preview_mono_font_;
140
144 QHash<QString, QPair<QColor, QColor>> ruleColors_;
145
147 std::unique_ptr<ThemePreviewWidget> pick_probe_;
149 bool key_render_ = false;
150
152 ThemePreviewPicker picker_;
153
155 QImage renderPickImage();
156
158 QPair<QFont, QFont> resolvedFonts() const;
159
161 int pickTextHeight() const;
162
169 QColor c(ThemeManager::ThemeToken token,
170 const QColor &fallback = QColor()) const;
171
176 QPalette previewPalette() const;
177
191 struct Layout {
192 QRect content;
193 QFont labelFont;
194 QFont monoFont;
195 QFontMetricsF labelFm;
196 QFontMetricsF monoFm;
197 int rowH;
198 QRect toolbarRect;
199 QRect filterRect;
200 QRect headerRect;
201 QRect listRect;
202 QRect detailsRect;
203 QRect bytesRect;
204 QRect statusRect;
205 };
206
213 struct WindowChrome {
214 QPainterPath framePath;
215 QColor border;
216 QRect content;
217 };
218
223 Layout buildLayout(const QRect &content) const;
224
232 WindowChrome paintWindowChrome(QPainter &p, const QRect &outer,
233 const QColor &window,
234 const NativeTitleBar::Style &titleBar);
235
242 void drawWindowControls(QPainter &p, const QRectF &titleRect, bool darkChrome,
243 const QColor &glyphColor);
244
246 void strokeWindowFrame(QPainter &p, const WindowChrome &chrome);
247
254 QRectF cellRect(const QRect &content, int idx, int top, int h) const;
255
257 int cellFlags(int idx) const;
258
262 void drawToolbar(QPainter &p, const Layout &layout);
263
269 void drawFilterBar(QPainter &p, const Layout &layout);
270
272 void drawColumnHeader(QPainter &p, const Layout &layout);
273
283 void drawPacketList(QPainter &p, const Layout &layout);
284
286 void rebuildRuleColors();
287
289 void drawDetailsPane(QPainter &p, const Layout &layout);
290
292 void drawBytesPane(QPainter &p, const Layout &layout);
293
295 void drawStatusBar(QPainter &p, const Layout &layout);
296
302 void saveAsImage();
303};
304
305#endif // THEME_PREVIEW_WIDGET_H
Definition theme_preview_pick.h:171
ThemePreviewPicker & picker()
Definition theme_preview_widget.h:100
void setPreviewFonts(const QFont &regular, const QFont &monospace)
Definition theme_preview_widget.cpp:124
void setShowColoringRules(bool show)
Definition theme_preview_widget.cpp:136
void layerPicked(const ThemePreviewPick::Layer &layer)
void pickMenuRequested(QMenu *menu, QAction *before, const QList< ThemePreviewPick::Layer > &layers)
void setPreviewColors(const QHash< ThemeManager::ThemeToken, QColor > &colors, bool declaresWindow=false)
Definition theme_preview_widget.cpp:112
Definition theme_preview_pick.h:60