Debian Codegraph @

src/Gui/Dialogs/DlgThemeEditor.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /****************************************************************************
3 * *
4 * Copyright (c) 2025 Kacper Donat <[email protected]> *
5 * *
6 * This file is part of FreeCAD. *
7 * *
8 * FreeCAD is free software: you can redistribute it and/or modify it *
9 * under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation, either version 2.1 of the *
11 * License, or (at your option) any later version. *
12 * *
13 * FreeCAD is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with FreeCAD. If not, see *
20 * <https://www.gnu.org/licenses/>. *
21 * *
22 ***************************************************************************/
23
24 #ifndef DLGTHEMEEDITOR_H
25 #define DLGTHEMEEDITOR_H
26
27
28 #include "StyleParameters/ParameterManager.h"
29
30 #include <QDialog>
31 #include <QTreeView>
32 #include <optional>
33
34 QT_BEGIN_NAMESPACE
35 class QAbstractButton;
36 QT_END_NAMESPACE
37
38 namespace Gui
39 {
40
41 namespace StyleParameters
42 {
43 class ParameterManager;
44 }
45
46 QT_BEGIN_NAMESPACE
47 namespace Ui
48 {
49 class DlgThemeEditor;
50 }
51 QT_END_NAMESPACE
52
53 class GuiExport TokenTreeView: public QTreeView
54 {
55 Q_OBJECT
56 public:
57 using QTreeView::QTreeView;
58
59 protected:
60 void keyPressEvent(QKeyEvent* event) override;
61
62 Q_SIGNALS:
63 void requestRemove(const QModelIndex& index);
64 };
65
66 class GuiExport StyleParametersModel: public QAbstractItemModel,
67 public StyleParameters::ParameterSource
68 {
69 Q_OBJECT
70
71 class Node;
72
73 public:
74 struct Item;
75 struct GroupItem;
76 struct ParameterItem;
77
78 enum Column : std::uint8_t
79 {
80 ParameterName,
81 ParameterExpression,
82 ParameterType,
83 ParameterPreview,
84 ColumnCount
85 };
86
87 FC_DISABLE_COPY_MOVE(StyleParametersModel);
88
89 explicit StyleParametersModel(const std::list<ParameterSource*>& sources, QObject* parent = nullptr);
90
91 ~StyleParametersModel() override;
92
93 std::list<StyleParameters::Parameter> all() const override;
94 std::optional<StyleParameters::Parameter> get(const std::string& name) const override;
95
96 void reset();
97 void flush() override;
98
99 int rowCount(const QModelIndex& index) const override;
100 int columnCount(const QModelIndex& index) const override;
101
102 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
103 QVariant data(const QModelIndex& index, int role) const override;
104 bool setData(const QModelIndex& index, const QVariant& value, int role) override;
105
106 Qt::ItemFlags flags(const QModelIndex& index) const override;
107
108 QModelIndex index(int row, int col, const QModelIndex& parent) const override;
109 QModelIndex parent(const QModelIndex& index) const override;
110
111 Node* node(const QModelIndex& index) const;
112 Item* item(const QModelIndex& index) const;
113
114 template<typename T>
115 T* item(const QModelIndex& index) const
116 {
117 return dynamic_cast<T*>(item(index));
118 }
119
120 bool isAddPlaceholder(const QModelIndex& index) const;
121
122 public Q_SLOTS:
123 void removeItem(const QModelIndex& index);
124
125 Q_SIGNALS:
126 void newParameterAdded(const QModelIndex& index);
127
128 private:
129 std::list<ParameterSource*> sources;
130 std::unique_ptr<StyleParameters::ParameterManager> manager;
131 std::unique_ptr<Node> root;
132 };
133
134 class GuiExport DlgThemeEditor: public QDialog
135 {
136 Q_OBJECT
137
138 class Delegate;
139
140 public:
141 FC_DISABLE_COPY_MOVE(DlgThemeEditor);
142
143 explicit DlgThemeEditor(QWidget* parent = nullptr);
144
145 ~DlgThemeEditor() override;
146
147 public Q_SLOTS:
148 void handleButtonClick(QAbstractButton* button);
149
150 private:
151 std::unique_ptr<Ui::DlgThemeEditor> ui;
152 std::unique_ptr<StyleParameters::ParameterManager> manager;
153 std::unique_ptr<StyleParametersModel> model;
154 };
155 } // namespace Gui
156
157 #endif // DLGTHEMEEDITOR_H