Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
info_banner_widget.h
Go to the documentation of this file.
1
10#ifndef INFO_BANNER_WIDGET_H
11#define INFO_BANNER_WIDGET_H
12
13#include <QFrame>
14#include <QColor>
15#include <QDate>
16#include <QString>
17#include <QList>
18#include <QMap>
19#include <QPair>
20#include <QTimer>
21
22class QJsonObject;
23
24 enum BannerSlideType {
25 BannerEvents,
26 BannerSponsorship,
27 BannerTips,
28 BannerSeasonal,
29 };
30 Q_DECLARE_METATYPE(BannerSlideType)
31
32 struct BannerSlide {
33 BannerSlideType type;
34 QString tag; // type label shown as subheader, e.g. "Tip of the Day"
35 QString title; // main heading, e.g. "Quick Filter Shortcut"
36 QString description; // primary text shown in highlight box
37 QString description_sub; // secondary line in highlight box
38 QString body_text; // additional text below the highlight box
39 QString button_label; // action button text, e.g. "More Tips"
40 QString url; // click/button target
41 QString image; // banner image filename, resolved under :/json/banners/
42 int date_month; // optional month for seasonal slides (1-12)
43 int date_day; // optional day for seasonal slides (1-31)
44 QString application; // optional application filter (e.g. "tshark"), empty = all
45 QDate date_from; // slide visible from this date (inclusive), invalid = always
46 QDate date_until; // slide visible until this date (inclusive), invalid = always
47 };
48
50 bool randomized = false;
51 int maxdisplay = 0; // 0 = show all (no limit)
52 bool only = false; // only slides from this file for this type
53 bool hidden = false; // suppress this type entirely (custom files only)
54 QColor color_start; // gradient start color for this type, default if not specified in file
55 QColor color_end; // gradient end color for this type, default if not specified in file
56 int color_gradient; // optional gradient angle in degrees (0 = left-to-right, 90 = top-to-bottom, etc.)
57 QList<QColor> steps; // optional discrete gradient steps (overrides color_start/color_end if specified)
58 };
59
60class InfoBannerWidget : public QFrame {
61 Q_OBJECT
62public:
63 explicit InfoBannerWidget(QWidget *parent = nullptr);
64
65 void setCompactMode(bool compact);
66 bool isCompactMode() const;
67 void setSlideTypeVisible(BannerSlideType type, bool visible);
68 void setAutoAdvanceInterval(unsigned seconds);
69 void applySlideFilter();
70 bool hasVisibleSlides() const;
71
72 QSize sizeHint() const override;
73 QSize minimumSizeHint() const override;
74
75 void startRotation();
76
77protected:
78 void paintEvent(QPaintEvent *event) override;
79 void mousePressEvent(QMouseEvent *event) override;
80 void mouseMoveEvent(QMouseEvent *event) override;
81 void leaveEvent(QEvent *event) override;
82 void changeEvent(QEvent *event) override;
83 bool event(QEvent *event) override;
84
85private:
86 QList<BannerSlide> slides_;
87 int current_slide_;
88 bool compact_mode_;
89 bool hovered_;
90 QMap<BannerSlideType, bool> slide_type_visible_;
91 QTimer *auto_advance_timer_;
92 int auto_advance_ms_;
93
94 // Per-type configuration (merged from predefined + custom)
95 QMap<BannerSlideType, SlideTypeConfig> type_config_;
96 // Per-type slide lists (date-filtered, after only/hidden processing)
97 QMap<BannerSlideType, QList<BannerSlide>> slides_by_type_;
98 // Per-type rotation offset for maxdisplay windowing
99 QMap<BannerSlideType, int> type_offsets_;
100 // Default gradient colors (for types not in config)
101 QColor default_color_start_;
102 QColor default_color_end_;
103
104 void setupSlides();
105 QString resolveI18nField(const QJsonObject &obj,
106 const QString &field,
107 bool is_custom) const;
108 void loadSlidesFromResource(const QString &resource_path,
109 bool is_custom,
110 QMap<BannerSlideType, SlideTypeConfig> &file_config,
111 QMap<BannerSlideType, QList<BannerSlide>> &file_slides);
112 void buildSlideSequence();
113
114 void advanceSlide();
115 // Updates accessibleName/Description to reflect the current slide and
116 // notifies the platform AT via QAccessible::NameChanged. Must be called
117 // whenever current_slide_ changes, because this widget is fully
118 // custom-painted — there are no child widgets for AT to interrogate.
119 void updateAccessibility();
120 int dotHitTest(const QPoint &pos) const;
121 QRect dotRect(int index) const;
122 QRect buttonRect() const;
123 static BannerSlideType typeFromString(const QString &type_str);
124 static BannerSlideType validTypeFromString(const QString &type_str,
125 const QString &resource_path,
126 const QString &context,
127 bool is_custom);
128
129 // Layout constants
130 static constexpr int kCardWidth = 300;
131 static constexpr int kCardHeight = 360;
132 static constexpr int kCardHeightCompact = 180;
133 static constexpr int kIllustrationHeight = 120;
134 static constexpr int kContentLeftMargin = 16;
135 static constexpr int kContentRightMargin = 16;
136 static constexpr int kDotRadius = 4;
137 static constexpr int kDotSpacing = 12;
138 static constexpr int kDotBottomMargin = 14;
139 static constexpr int kDefaultAutoAdvanceMs = 8000;
140};
141
142#endif // INFO_BANNER_WIDGET_H
Definition info_banner_widget.h:60
Definition info_banner_widget.h:32
Definition info_banner_widget.h:49