Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
theme_color_editor.h
Go to the documentation of this file.
1
9
10#ifndef THEME_COLOR_EDITOR_H
11#define THEME_COLOR_EDITOR_H
12
15
16#include <QColor>
17#include <QHash>
18#include <QIcon>
19#include <QList>
20#include <QMap>
21#include <QPair>
22#include <QString>
23#include <QStringList>
24#include <QVector>
25#include <QWidget>
26
27class QLabel;
28class QPoint;
29class QPushButton;
30class QTreeWidgetItem;
31class SyntaxLineEdit;
32
33namespace Ui {
34class ThemeColorEditor;
35}
36
52class ThemeColorEditor : public QWidget
53{
54 Q_OBJECT
55public:
56 explicit ThemeColorEditor(QWidget *parent = nullptr);
57 ~ThemeColorEditor();
58
67 void setDrafts(const ThemeDraft &base, const ThemeDraft &draft);
68
70 const ThemeDraft &draft() const { return draft_; }
71
73 void setDarkSide(bool dark);
74
76 int editedCount() const;
77
79 int changedCount() const;
80
82 int invalidCount() const { return static_cast<int>(pending_.size()); }
83
88 QString firstInvalidPath() const;
89
94 static QString editedMarkHtml();
95
105 bool selectToken(ThemeManager::ThemeToken token, bool *filter_cleared = nullptr);
106
108 QString tokenLabel(ThemeManager::ThemeToken token) const;
109
111 QIcon tokenSwatch(ThemeManager::ThemeToken token) const;
112
113signals:
116
119
120private:
121 enum class RowKind { Color, Graph, NoGraphs, Derived };
122 enum class RowState { None, Edited, Changed, Required };
123
124 struct Row {
125 RowKind kind = RowKind::Color;
126 ThemeManager::ThemeToken token = ThemeManager::NoRole;
127 int graph = -1;
128 QString label;
129 QString section;
130 QString path;
131 QString description;
132 bool required = false;
133 RowState state = RowState::None;
134 QTreeWidgetItem *item = nullptr;
135
137 int id() const { return rowIdFor(kind, token, graph); }
138
140 bool editable() const { return kind == RowKind::Color || kind == RowKind::Graph; }
141 };
142
143 using ResolvedMap = QHash<ThemeManager::ThemeToken, QColor>;
144
145 static int rowIdFor(RowKind kind, ThemeManager::ThemeToken token, int graph);
146 static QString graphDescription();
147 static QString tokenName(ThemeManager::ThemeToken token);
149 static QString chooseTitle(const Row &row, int side);
150 static void resolveBoth(const ThemeDraft &draft, ResolvedMap out[2],
151 ThemeTokenHandler::SourceMap *sources = nullptr);
152
153 void rebuildTree();
154 void recompute();
155 void refreshRows();
156 void applyFilter();
157 void updateDetail(bool force_fields);
158 void updateField(int side);
159
160 const Row *currentRow() const;
161 QColor inputColor(const Row &row, int side, bool *is_set = nullptr) const;
162 QColor shownColor(const Row &row, int side) const;
163 QString rowDescription(const Row &row) const;
165 QString derivedText(ThemeManager::ThemeToken token) const;
167 QString autoValueText(const QColor &shown) const;
168 QStringList affectedTokens(ThemeManager::ThemeToken token) const;
173 QList<ThemeManager::ThemeToken> sourceTokens(const Row &row) const;
175 bool offersSources(const Row &row) const;
176 void setColor(const Row &row, int side, const QColor &color);
177 void dropPending(int row_id);
178 void shiftGraphPending(int from, int delta);
179 void removeGraphSlot(int slot);
186 void finishChange(bool force_fields = false);
192 bool sideValueEdited(const Row &row, int side) const;
194 bool sideEdited(const Row &row, int side) const;
195
196 void currentItemChanged(QTreeWidgetItem *current);
197 void hexEdited(int side, const QString &text);
198 void hexEditingFinished(int side);
199 void chooseColor(int side);
200 void useAuto();
201 void revertColor();
202 void revertSide(int side);
203 void showContextMenu(const QPoint &pos);
204 void addGraphColor();
205 void removeGraphColor();
206 void themeChanged();
207
208 ThemeDraft base_;
209 ThemeDraft draft_;
210 ResolvedMap base_resolved_[2];
211 ResolvedMap draft_resolved_[2];
213 bool dark_ = false;
214 int current_row_id_ = -1;
215
216 QVector<Row> rows_;
217 QHash<int, int> row_index_;
218 QList<QTreeWidgetItem *> group_items_;
219 // Text that is not a color, per (row id, side 0 = light / 1 = dark).
220 QMap<QPair<int, int>, QString> pending_;
221
222 Ui::ThemeColorEditor *ui_;
223 // The light (0) and dark (1) field rows of the form, indexed by side.
224 QWidget *side_widget_[2];
225 QLabel *swatch_label_[2];
226 SyntaxLineEdit *hex_edit_[2];
227 QPushButton *choose_button_[2];
228 QPushButton *revert_button_[2];
229};
230
231#endif // THEME_COLOR_EDITOR_H
Represents a single data graph within a QCustomPlot, managing its data, visual style,...
Definition graph.h:25
QLineEdit subclass that adds syntax-state colouring, error messaging, and partial token-based autocom...
Definition syntax_line_edit.h:28
void setDarkSide(bool dark)
Definition theme_color_editor.cpp:156
bool selectToken(ThemeManager::ThemeToken token, bool *filter_cleared=nullptr)
Definition theme_color_editor.cpp:932
QIcon tokenSwatch(ThemeManager::ThemeToken token) const
Definition theme_color_editor.cpp:965
int editedCount() const
Definition theme_color_editor.cpp:165
int changedCount() const
Definition theme_color_editor.cpp:177
QString firstInvalidPath() const
Definition theme_color_editor.cpp:187
QString tokenLabel(ThemeManager::ThemeToken token) const
Definition theme_color_editor.cpp:957
static QString editedMarkHtml()
Definition theme_color_editor.cpp:1044
const ThemeDraft & draft() const
Definition theme_color_editor.h:70
void childDialogClosed()
int invalidCount() const
Definition theme_color_editor.h:82
void setDrafts(const ThemeDraft &base, const ThemeDraft &draft)
Definition theme_color_editor.cpp:137
QHash< ThemeManager::ThemeToken, const char * > SourceMap
Definition theme_token_handler.h:58
Definition theme_manager.h:973