1 /*
2  * tilecollisiondock.h
3  * Copyright 2013-2017, Thorbjørn Lindeijer <bjorn@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 "clipboardmanager.h"
24 #include "mapdocument.h"
25 
26 #include <QDockWidget>
27 
28 class QSplitter;
29 
30 namespace Tiled {
31 
32 class Object;
33 class Tile;
34 class Tileset;
35 
36 class AbstractTool;
37 class EditableMapObject;
38 class MapScene;
39 class MapView;
40 class ObjectsView;
41 class TilesetDocument;
42 class ToolManager;
43 
44 class TileCollisionDock : public QDockWidget
45 {
46     Q_OBJECT
47 
48     Q_PROPERTY(QList<QObject*> selectedObjects READ selectedObjectsForScript WRITE setSelectedObjectsFromScript)
49     Q_PROPERTY(Tiled::MapView *view READ mapView)
50 
51 public:
52     enum Operation {
53         Cut,
54         Delete
55     };
56 
57     enum ObjectsViewVisibility {
58         Hidden,
59         ShowRight,
60         ShowBottom
61     };
62     Q_ENUM(ObjectsViewVisibility)
63 
64     explicit TileCollisionDock(QWidget *parent = nullptr);
65     ~TileCollisionDock() override;
66 
67     void saveState();
68     void restoreState();
69 
70     void setTilesetDocument(TilesetDocument *tilesetDocument);
71 
72     MapDocument *dummyMapDocument() const;
73     MapView *mapView() const;
74 
75     ToolManager *toolManager() const;
76 
77     bool hasSelectedObjects() const;
78 
79     QList<QObject*> selectedObjectsForScript() const;
80     void setSelectedObjectsFromScript(const QList<QObject*> &selectedObjects);
81 
82     Q_INVOKABLE void focusObject(Tiled::EditableMapObject *object);
83 
84 signals:
85     void dummyMapDocumentChanged(MapDocument *mapDocument);
86     void hasSelectedObjectsChanged();
87     void statusInfoChanged(const QString &info);
88 
89 public slots:
90     void setTile(Tile *tile);
91 
92     void cut();
93     void copy();
94     void paste();
95     void pasteInPlace();
96     void paste(ClipboardManager::PasteFlags flags);
97     void delete_(Operation operation = Delete);
98     void autoDetectMask();
99 
100 protected:
101     void changeEvent(QEvent *e) override;
102 
103 private:
104     void applyChanges();
105     void documentChanged(const ChangeEvent &change);
106     void tileObjectGroupChanged(Tile*);
107     void tilesetTileOffsetChanged(Tileset *tileset);
108 
109     void selectedObjectsChanged();
110     void setHasSelectedObjects(bool hasSelectedObjects);
111 
112     void selectAll();
113 
114     void duplicateObjects();
115     void removeObjects();
116     void moveObjectsUp();
117     void moveObjectsDown();
118     void objectProperties();
119 
120     void setObjectsViewVisibility(ObjectsViewVisibility);
121 
122     MapObject *clonedObjectForScriptObject(EditableMapObject *scriptObject);
123 
124     void retranslateUi();
125 
126     Tile *mTile = nullptr;
127     TilesetDocument *mTilesetDocument = nullptr;
128     MapDocumentPtr mDummyMapDocument;
129     MapScene *mMapScene;
130     MapView *mMapView;
131     ObjectsView *mObjectsView;
132     QWidget *mObjectsWidget;
133     QSplitter *mObjectsViewSplitter;
134     QAction *mObjectsViewHiddenAction;
135     QAction *mObjectsViewShowRightAction;
136     QAction *mObjectsViewShowBottomAction;
137     ToolManager *mToolManager;
138     QAction *mActionAutoDetectMask;
139     QAction *mActionDuplicateObjects;
140     QAction *mActionRemoveObjects;
141     QAction *mActionMoveUp;
142     QAction *mActionMoveDown;
143     QAction *mActionObjectProperties;
144     bool mApplyingChanges = false;
145     bool mSynchronizing = false;
146     bool mHasSelectedObjects = false;
147     ObjectsViewVisibility mObjectsViewVisibility = Hidden;
148 };
149 
dummyMapDocument()150 inline MapDocument *TileCollisionDock::dummyMapDocument() const
151 {
152     return mDummyMapDocument.data();
153 }
154 
mapView()155 inline MapView *TileCollisionDock::mapView() const
156 {
157     return mMapView;
158 }
159 
toolManager()160 inline ToolManager *TileCollisionDock::toolManager() const
161 {
162     return mToolManager;
163 }
164 
hasSelectedObjects()165 inline bool TileCollisionDock::hasSelectedObjects() const
166 {
167     return mHasSelectedObjects;
168 }
169 
170 } // namespace Tiled
171 
172 Q_DECLARE_METATYPE(Tiled::TileCollisionDock*)
173