1 /*
2 * propertybrowser.h
3 * Copyright 2013, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
4 *
5 * This file is part of Tiled.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #pragma once
22
23 #include "changeevents.h"
24 #include "map.h"
25 #include "properties.h"
26
27 #include <QtTreePropertyBrowser>
28
29 #include <QHash>
30
31 class QUndoCommand;
32
33 class QtGroupPropertyManager;
34 class QtVariantProperty;
35 class QtVariantPropertyManager;
36
37 namespace Tiled {
38
39 class GroupLayer;
40 class ImageLayer;
41 class MapObject;
42 class ObjectGroup;
43 class Tile;
44 class TileLayer;
45 class Tileset;
46
47 class Document;
48 class MapDocument;
49 class TilesetDocument;
50
51 class PropertyBrowser : public QtTreePropertyBrowser
52 {
53 Q_OBJECT
54
55 public:
56 explicit PropertyBrowser(QWidget *parent = nullptr);
57
58 void setObject(Object *object);
59 Object *object() const;
60
61 void setDocument(Document *document);
62
63 bool isCustomPropertyItem(const QtBrowserItem *item) const;
64 bool allCustomPropertyItems(const QList<QtBrowserItem*> &items) const;
65
66 void selectCustomProperty(const QString &name);
67 void editCustomProperty(const QString &name);
68
69 QSize sizeHint() const override;
70
71 protected:
72 bool event(QEvent *event) override;
73
74 private:
75 void documentChanged(const ChangeEvent &change);
76 void mapChanged();
77 void objectsChanged(const MapObjectsChangeEvent &mapObjectsChange);
78 void imageLayerChanged(ImageLayer *imageLayer);
79 void tilesetChanged(Tileset *tileset);
80 void tileChanged(Tile *tile);
81 void tileTypeChanged(Tile *tile);
82 void wangSetChanged(Tileset *tileset, int index);
83
84 void propertyAdded(Object *object, const QString &name);
85 void propertyRemoved(Object *object, const QString &name);
86 void propertyChanged(Object *object, const QString &name);
87 void propertiesChanged(Object *object);
88 void selectedObjectsChanged();
89 void selectedLayersChanged();
90 void selectedTilesChanged();
91
92 void objectTypesChanged();
93
94 void valueChanged(QtProperty *property, const QVariant &val);
95
96 void resetProperty(QtProperty *property);
97
98 enum PropertyId {
99 NameProperty,
100 TypeProperty,
101 XProperty,
102 YProperty,
103 WidthProperty,
104 HeightProperty,
105 RotationProperty,
106 VisibleProperty,
107 LockedProperty,
108 OpacityProperty,
109 TextProperty,
110 TextAlignmentProperty,
111 FontProperty,
112 WordWrapProperty,
113 OffsetXProperty,
114 OffsetYProperty,
115 ParallaxFactorProperty,
116 ColorProperty,
117 BackgroundColorProperty,
118 TileWidthProperty,
119 TileHeightProperty,
120 GridWidthProperty,
121 GridHeightProperty,
122 OrientationProperty,
123 HexSideLengthProperty,
124 StaggerAxisProperty,
125 StaggerIndexProperty,
126 RenderOrderProperty,
127 LayerFormatProperty,
128 ImageSourceProperty,
129 TilesetImageParametersProperty,
130 FlippingProperty,
131 DrawOrderProperty,
132 FileNameProperty,
133 ObjectAlignmentProperty,
134 TileOffsetProperty,
135 MarginProperty,
136 SpacingProperty,
137 TileProbabilityProperty,
138 ColumnCountProperty,
139 IdProperty,
140 ColorCountProperty,
141 WangColorProbabilityProperty,
142 WangSetTypeProperty,
143 CustomProperty,
144 InfiniteProperty,
145 TemplateProperty,
146 CompressionLevelProperty,
147 ChunkWidthProperty,
148 ChunkHeightProperty,
149 TintColorProperty,
150 AllowFlipHorizontallyProperty,
151 AllowFlipVerticallyProperty,
152 AllowRotateProperty,
153 PreferUntransformedProperty,
154 };
155
156 void addMapProperties();
157 void addMapObjectProperties();
158 void addLayerProperties(QtProperty *parent);
159 void addTileLayerProperties();
160 void addObjectGroupProperties();
161 void addImageLayerProperties();
162 void addGroupLayerProperties();
163 void addTilesetProperties();
164 void addTileProperties();
165 void addWangSetProperties();
166 void addWangColorProperties();
167
168 void applyMapValue(PropertyId id, const QVariant &val);
169 void applyMapObjectValue(PropertyId id, const QVariant &val);
170 QUndoCommand *applyMapObjectValueTo(PropertyId id, const QVariant &val, MapObject *mapObject);
171 void applyLayerValue(PropertyId id, const QVariant &val);
172 QUndoCommand *applyLayerValueTo(PropertyId id, const QVariant &val, Layer *layer);
173 QUndoCommand *applyTileLayerValueTo(PropertyId id, const QVariant &val, TileLayer *tileLayer);
174 QUndoCommand *applyObjectGroupValueTo(PropertyId id, const QVariant &val, ObjectGroup *objectGroup);
175 QUndoCommand *applyImageLayerValueTo(PropertyId id, const QVariant &val, ImageLayer *imageLayer);
176 QUndoCommand *applyGroupLayerValueTo(PropertyId id, const QVariant &val, GroupLayer *groupLayer);
177 void applyTilesetValue(PropertyId id, const QVariant &val);
178 void applyTileValue(PropertyId id, const QVariant &val);
179 void applyWangSetValue(PropertyId id, const QVariant &val);
180 void applyWangColorValue(PropertyId id, const QVariant &val);
181
182 QtVariantProperty *createProperty(PropertyId id,
183 int type,
184 const QString &name);
185
186 using QtTreePropertyBrowser::addProperty;
187 QtVariantProperty *addProperty(PropertyId id,
188 int type,
189 const QString &name,
190 QtProperty *parent);
191
192 QtVariantProperty *createCustomProperty(const QString &name, const QVariant &value);
193 void deleteCustomProperty(QtVariantProperty *property);
194 void setCustomPropertyValue(QtVariantProperty *property, const QVariant &value);
195
196 void addProperties();
197 void removeProperties();
198 void updateProperties();
199 void updateCustomProperties();
200 void updateCustomPropertyColor(const QString &name);
201
202 QVariant toDisplayValue(const QVariant &value) const;
203 QVariant fromDisplayValue(const QVariant &value) const;
204
205 void retranslateUi();
206
207 bool mUpdating = false;
208 int mMapObjectFlags = 0;
209 Object *mObject = nullptr;
210 Document *mDocument = nullptr;
211 MapDocument *mMapDocument = nullptr;
212 TilesetDocument *mTilesetDocument = nullptr;
213
214 QtVariantPropertyManager *mVariantManager;
215 QtGroupPropertyManager *mGroupManager;
216 QtProperty *mCustomPropertiesGroup;
217
218 QHash<QtProperty *, PropertyId> mPropertyToId;
219 QHash<PropertyId, QtVariantProperty *> mIdToProperty;
220 QHash<QString, QtVariantProperty *> mNameToProperty;
221
222 Properties mCombinedProperties;
223
224 QStringList mStaggerAxisNames;
225 QStringList mStaggerIndexNames;
226 QStringList mOrientationNames;
227 QStringList mTilesetOrientationNames;
228 QStringList mLayerFormatNames;
229 QList<Map::LayerDataFormat> mLayerFormatValues;
230 QStringList mRenderOrderNames;
231 QStringList mAlignmentNames;
232 QStringList mFlippingFlagNames;
233 QStringList mDrawOrderNames;
234 QStringList mWangSetTypeNames;
235 QMap<int, QIcon> mWangSetIcons;
236 };
237
238 /**
239 * Returns the object for which the properties are displayed.
240 */
object()241 inline Object *PropertyBrowser::object() const
242 {
243 return mObject;
244 }
245
246 } // namespace Tiled
247