1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Designer of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #ifndef DESIGNERPROPERTYMANAGER_H |
30 | #define DESIGNERPROPERTYMANAGER_H |
31 | |
32 | #include "qtvariantproperty.h" |
33 | #include "brushpropertymanager.h" |
34 | #include "fontpropertymanager.h" |
35 | |
36 | #include <qdesigner_utils_p.h> |
37 | #include <shared_enums_p.h> |
38 | |
39 | #include <QtCore/qurl.h> |
40 | #include <QtCore/qmap.h> |
41 | #include <QtGui/qfont.h> |
42 | #include <QtGui/qicon.h> |
43 | |
44 | QT_BEGIN_NAMESPACE |
45 | |
46 | typedef QPair<QString, uint> DesignerIntPair; |
47 | using DesignerFlagList = QList<DesignerIntPair>; |
48 | |
49 | class QDesignerFormEditorInterface; |
50 | class QLineEdit; |
51 | class QUrl; |
52 | class QKeySequenceEdit; |
53 | |
54 | namespace qdesigner_internal |
55 | { |
56 | |
57 | class ResetWidget; |
58 | |
59 | class TextEditor; |
60 | class PaletteEditorButton; |
61 | class PixmapEditor; |
62 | class StringListEditorButton; |
63 | class FormWindowBase; |
64 | |
65 | class ResetDecorator : public QObject |
66 | { |
67 | Q_OBJECT |
68 | public: |
69 | explicit ResetDecorator(const QDesignerFormEditorInterface *core, QObject *parent = nullptr); |
70 | ~ResetDecorator(); |
71 | |
72 | void connectPropertyManager(QtAbstractPropertyManager *manager); |
73 | QWidget *editor(QWidget *subEditor, bool resettable, QtAbstractPropertyManager *manager, QtProperty *property, |
74 | QWidget *parent); |
75 | void disconnectPropertyManager(QtAbstractPropertyManager *manager); |
76 | void setSpacing(int spacing); |
77 | signals: |
78 | void resetProperty(QtProperty *property); |
79 | private slots: |
80 | void slotPropertyChanged(QtProperty *property); |
81 | void slotEditorDestroyed(QObject *object); |
82 | private: |
83 | QMap<QtProperty *, QList<ResetWidget *> > m_createdResetWidgets; |
84 | QMap<ResetWidget *, QtProperty *> m_resetWidgetToProperty; |
85 | int m_spacing; |
86 | const QDesignerFormEditorInterface *m_core; |
87 | }; |
88 | |
89 | // Helper for handling sub-properties of properties inheriting PropertySheetTranslatableData |
90 | // (translatable, disambiguation, comment). |
91 | template <class PropertySheetValue> |
92 | class TranslatablePropertyManager |
93 | { |
94 | public: |
95 | void initialize(QtVariantPropertyManager *m, QtProperty *property, const PropertySheetValue &value); |
96 | bool uninitialize(QtProperty *property); |
97 | bool destroy(QtProperty *subProperty); |
98 | |
99 | bool value(const QtProperty *property, QVariant *rc) const; |
100 | int valueChanged(QtVariantPropertyManager *m, QtProperty *property, |
101 | const QVariant &value); |
102 | |
103 | int setValue(QtVariantPropertyManager *m, QtProperty *property, |
104 | int expectedTypeId, const QVariant &value); |
105 | |
106 | private: |
107 | QHash<QtProperty *, PropertySheetValue> m_values; |
108 | QHash<QtProperty *, QtProperty *> ; |
109 | QHash<QtProperty *, QtProperty *> m_valueToTranslatable; |
110 | QHash<QtProperty *, QtProperty *> m_valueToDisambiguation; |
111 | QHash<QtProperty *, QtProperty *> m_valueToId; |
112 | |
113 | QHash<QtProperty *, QtProperty *> ; |
114 | QHash<QtProperty *, QtProperty *> m_translatableToValue; |
115 | QHash<QtProperty *, QtProperty *> m_disambiguationToValue; |
116 | QHash<QtProperty *, QtProperty *> m_idToValue; |
117 | }; |
118 | |
119 | class DesignerPropertyManager : public QtVariantPropertyManager |
120 | { |
121 | Q_OBJECT |
122 | public: |
123 | enum ValueChangedResult { NoMatch, Unchanged, Changed }; |
124 | |
125 | explicit DesignerPropertyManager(QDesignerFormEditorInterface *core, QObject *parent = nullptr); |
126 | ~DesignerPropertyManager(); |
127 | |
128 | QStringList attributes(int propertyType) const override; |
129 | int attributeType(int propertyType, const QString &attribute) const override; |
130 | |
131 | QVariant attributeValue(const QtProperty *property, const QString &attribute) const override; |
132 | bool isPropertyTypeSupported(int propertyType) const override; |
133 | QVariant value(const QtProperty *property) const override; |
134 | int valueType(int propertyType) const override; |
135 | QString valueText(const QtProperty *property) const override; |
136 | QIcon valueIcon(const QtProperty *property) const override; |
137 | |
138 | bool resetTextAlignmentProperty(QtProperty *property); |
139 | bool resetFontSubProperty(QtProperty *property); |
140 | bool resetIconSubProperty(QtProperty *subProperty); |
141 | |
142 | void reloadResourceProperties(); |
143 | |
144 | static int designerFlagTypeId(); |
145 | static int designerFlagListTypeId(); |
146 | static int designerAlignmentTypeId(); |
147 | static int designerPixmapTypeId(); |
148 | static int designerIconTypeId(); |
149 | static int designerStringTypeId(); |
150 | static int designerStringListTypeId(); |
151 | static int designerKeySequenceTypeId(); |
152 | |
153 | void setObject(QObject *object) { m_object = object; } |
154 | |
155 | static void setUseIdBasedTranslations(bool v) |
156 | { m_IdBasedTranslations = v; } |
157 | static bool useIdBasedTranslations() |
158 | { return m_IdBasedTranslations; } |
159 | |
160 | static QString alignDefaultAttribute(); |
161 | |
162 | static uint alignDefault(const QtVariantProperty *prop); |
163 | |
164 | public Q_SLOTS: |
165 | void setAttribute(QtProperty *property, const QString &attribute, const QVariant &value) override; |
166 | void setValue(QtProperty *property, const QVariant &value) override; |
167 | Q_SIGNALS: |
168 | // sourceOfChange - a subproperty (or just property) which caused a change |
169 | //void valueChanged(QtProperty *property, const QVariant &value, QtProperty *sourceOfChange); |
170 | void valueChanged(QtProperty *property, const QVariant &value, bool enableSubPropertyHandling); |
171 | protected: |
172 | void initializeProperty(QtProperty *property) override; |
173 | void uninitializeProperty(QtProperty *property) override; |
174 | private Q_SLOTS: |
175 | void slotValueChanged(QtProperty *property, const QVariant &value); |
176 | void slotPropertyDestroyed(QtProperty *property); |
177 | private: |
178 | void createIconSubProperty(QtProperty *iconProperty, QIcon::Mode mode, QIcon::State state, const QString &subName); |
179 | |
180 | typedef QMap<QtProperty *, bool> PropertyBoolMap; |
181 | PropertyBoolMap m_resetMap; |
182 | |
183 | int bitCount(int mask) const; |
184 | struct FlagData |
185 | { |
186 | uint val{0}; |
187 | DesignerFlagList flags; |
188 | QList<uint> values; |
189 | }; |
190 | typedef QMap<QtProperty *, FlagData> PropertyFlagDataMap; |
191 | PropertyFlagDataMap m_flagValues; |
192 | typedef QMap<QtProperty *, QList<QtProperty *> > PropertyToPropertyListMap; |
193 | PropertyToPropertyListMap m_propertyToFlags; |
194 | QMap<QtProperty *, QtProperty *> m_flagToProperty; |
195 | |
196 | int alignToIndexH(uint align) const; |
197 | int alignToIndexV(uint align) const; |
198 | uint indexHToAlign(int idx) const; |
199 | uint indexVToAlign(int idx) const; |
200 | QString indexHToString(int idx) const; |
201 | QString indexVToString(int idx) const; |
202 | QMap<QtProperty *, uint> m_alignValues; |
203 | typedef QMap<QtProperty *, QtProperty *> PropertyToPropertyMap; |
204 | PropertyToPropertyMap m_propertyToAlignH; |
205 | PropertyToPropertyMap m_propertyToAlignV; |
206 | PropertyToPropertyMap m_alignHToProperty; |
207 | PropertyToPropertyMap m_alignVToProperty; |
208 | QHash<const QtProperty *, Qt::Alignment> m_alignDefault; |
209 | |
210 | QMap<QtProperty *, QMap<QPair<QIcon::Mode, QIcon::State>, QtProperty *> > m_propertyToIconSubProperties; |
211 | QMap<QtProperty *, QPair<QIcon::Mode, QIcon::State> > m_iconSubPropertyToState; |
212 | PropertyToPropertyMap m_iconSubPropertyToProperty; |
213 | PropertyToPropertyMap m_propertyToTheme; |
214 | |
215 | TranslatablePropertyManager<PropertySheetStringValue> m_stringManager; |
216 | TranslatablePropertyManager<PropertySheetKeySequenceValue> m_keySequenceManager; |
217 | TranslatablePropertyManager<PropertySheetStringListValue> m_stringListManager; |
218 | |
219 | struct PaletteData |
220 | { |
221 | QPalette val; |
222 | QPalette superPalette; |
223 | }; |
224 | typedef QMap<QtProperty *, PaletteData> PropertyPaletteDataMap; |
225 | PropertyPaletteDataMap m_paletteValues; |
226 | |
227 | QMap<QtProperty *, qdesigner_internal::PropertySheetPixmapValue> m_pixmapValues; |
228 | QMap<QtProperty *, qdesigner_internal::PropertySheetIconValue> m_iconValues; |
229 | |
230 | QMap<QtProperty *, uint> m_uintValues; |
231 | QMap<QtProperty *, qlonglong> m_longLongValues; |
232 | QMap<QtProperty *, qulonglong> m_uLongLongValues; |
233 | QMap<QtProperty *, QUrl> m_urlValues; |
234 | QMap<QtProperty *, QByteArray> m_byteArrayValues; |
235 | |
236 | typedef QMap<QtProperty *, int> PropertyIntMap; |
237 | PropertyIntMap m_stringAttributes; |
238 | typedef QMap<QtProperty *, QFont> PropertyFontMap; |
239 | PropertyFontMap m_stringFontAttributes; |
240 | PropertyBoolMap m_stringThemeAttributes; |
241 | |
242 | BrushPropertyManager m_brushManager; |
243 | FontPropertyManager m_fontManager; |
244 | |
245 | QMap<QtProperty *, QPixmap> m_defaultPixmaps; |
246 | QMap<QtProperty *, QIcon> m_defaultIcons; |
247 | |
248 | bool m_changingSubValue; |
249 | QDesignerFormEditorInterface *m_core; |
250 | |
251 | QObject *m_object; |
252 | |
253 | QtProperty *m_sourceOfChange; |
254 | static bool m_IdBasedTranslations; |
255 | }; |
256 | |
257 | class DesignerEditorFactory : public QtVariantEditorFactory |
258 | { |
259 | Q_OBJECT |
260 | public: |
261 | explicit DesignerEditorFactory(QDesignerFormEditorInterface *core, QObject *parent = nullptr); |
262 | ~DesignerEditorFactory(); |
263 | void setSpacing(int spacing); |
264 | void setFormWindowBase(FormWindowBase *fwb); |
265 | signals: |
266 | void resetProperty(QtProperty *property); |
267 | protected: |
268 | void connectPropertyManager(QtVariantPropertyManager *manager) override; |
269 | QWidget *createEditor(QtVariantPropertyManager *manager, QtProperty *property, |
270 | QWidget *parent) override; |
271 | void disconnectPropertyManager(QtVariantPropertyManager *manager) override; |
272 | private slots: |
273 | void slotEditorDestroyed(QObject *object); |
274 | void slotAttributeChanged(QtProperty *property, const QString &attribute, const QVariant &value); |
275 | void slotPropertyChanged(QtProperty *property); |
276 | void slotValueChanged(QtProperty *property, const QVariant &value); |
277 | void slotStringTextChanged(const QString &value); |
278 | void slotKeySequenceChanged(const QKeySequence &value); |
279 | void slotPaletteChanged(const QPalette &value); |
280 | void slotPixmapChanged(const QString &value); |
281 | void slotIconChanged(const QString &value); |
282 | void slotIconThemeChanged(const QString &value); |
283 | void slotUintChanged(const QString &value); |
284 | void slotLongLongChanged(const QString &value); |
285 | void slotULongLongChanged(const QString &value); |
286 | void slotUrlChanged(const QString &value); |
287 | void slotByteArrayChanged(const QString &value); |
288 | void slotStringListChanged(const QStringList &value); |
289 | private: |
290 | TextEditor *createTextEditor(QWidget *parent, TextPropertyValidationMode vm, const QString &value); |
291 | |
292 | ResetDecorator *m_resetDecorator; |
293 | bool m_changingPropertyValue; |
294 | QDesignerFormEditorInterface *m_core; |
295 | FormWindowBase *m_fwb; |
296 | |
297 | int m_spacing; |
298 | |
299 | QMap<QtProperty *, QList<TextEditor *> > m_stringPropertyToEditors; |
300 | QMap<TextEditor *, QtProperty *> m_editorToStringProperty; |
301 | QMap<QtProperty *, QList<QKeySequenceEdit *> > m_keySequencePropertyToEditors; |
302 | QMap<QKeySequenceEdit *, QtProperty *> m_editorToKeySequenceProperty; |
303 | QMap<QtProperty *, QList<PaletteEditorButton *> > m_palettePropertyToEditors; |
304 | QMap<PaletteEditorButton *, QtProperty *> m_editorToPaletteProperty; |
305 | QMap<QtProperty *, QList<PixmapEditor *> > m_pixmapPropertyToEditors; |
306 | QMap<PixmapEditor *, QtProperty *> m_editorToPixmapProperty; |
307 | QMap<QtProperty *, QList<PixmapEditor *> > m_iconPropertyToEditors; |
308 | QMap<PixmapEditor *, QtProperty *> m_editorToIconProperty; |
309 | QMap<QtProperty *, QList<QLineEdit *> > m_uintPropertyToEditors; |
310 | QMap<QLineEdit *, QtProperty *> m_editorToUintProperty; |
311 | QMap<QtProperty *, QList<QLineEdit *> > m_longLongPropertyToEditors; |
312 | QMap<QLineEdit *, QtProperty *> m_editorToLongLongProperty; |
313 | QMap<QtProperty *, QList<QLineEdit *> > m_uLongLongPropertyToEditors; |
314 | QMap<QLineEdit *, QtProperty *> m_editorToULongLongProperty; |
315 | QMap<QtProperty *, QList<TextEditor *> > m_urlPropertyToEditors; |
316 | QMap<TextEditor *, QtProperty *> m_editorToUrlProperty; |
317 | QMap<QtProperty *, QList<TextEditor *> > m_byteArrayPropertyToEditors; |
318 | QMap<TextEditor *, QtProperty *> m_editorToByteArrayProperty; |
319 | QMap<QtProperty *, QList<StringListEditorButton *> > m_stringListPropertyToEditors; |
320 | QMap<StringListEditorButton *, QtProperty *> m_editorToStringListProperty; |
321 | }; |
322 | |
323 | } // namespace qdesigner_internal |
324 | |
325 | QT_END_NAMESPACE |
326 | |
327 | Q_DECLARE_METATYPE(DesignerIntPair) |
328 | Q_DECLARE_METATYPE(DesignerFlagList) |
329 | |
330 | #endif |
331 | |
332 | |