~ubuntu-branches/ubuntu/raring/tiled-qt/raring

« back to all changes in this revision

Viewing changes to src/tiled/mapdocument.h

  • Committer: Bazaar Package Importer
  • Author(s): Ying-Chun Liu (PaulLiu)
  • Date: 2010-07-05 21:35:45 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100705213545-ol5zjn85kun26ywx
Tags: 0.5.0-1
* New upstream release
* debian/patches/addrpath.patch: Modify library install path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * mapdocument.h
 
3
 * Copyright 2008-2010, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
 
4
 * Copyright 2009, Jeff Bland <jeff@teamphobic.com>
 
5
 *
 
6
 * This file is part of Tiled.
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify it
 
9
 * under the terms of the GNU General Public License as published by the Free
 
10
 * Software Foundation; either version 2 of the License, or (at your option)
 
11
 * any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
15
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
16
 * more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License along with
 
19
 * this program. If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
#ifndef MAPDOCUMENT_H
 
23
#define MAPDOCUMENT_H
 
24
 
 
25
#include <QObject>
 
26
#include <QRegion>
 
27
#include <QString>
 
28
 
 
29
class QPoint;
 
30
class QRect;
 
31
class QSize;
 
32
class QUndoStack;
 
33
 
 
34
namespace Tiled {
 
35
 
 
36
class Map;
 
37
class MapObject;
 
38
class Tileset;
 
39
 
 
40
namespace Internal {
 
41
 
 
42
class LayerModel;
 
43
class MapRenderer;
 
44
class TileSelectionModel;
 
45
 
 
46
/**
 
47
 * Represents an editable map. The purpose of this class is to make sure that
 
48
 * any editing operations will cause the appropriate signals to be emitted, in
 
49
 * order to allow the GUI to update accordingly.
 
50
 *
 
51
 * At the moment the map document provides the layer model, keeps track of the
 
52
 * the currently selected layer and provides an API for adding and removing
 
53
 * map objects. It also owns the QUndoStack.
 
54
 */
 
55
class MapDocument : public QObject
 
56
{
 
57
    Q_OBJECT
 
58
 
 
59
public:
 
60
    /**
 
61
     * Constructs a map document around the given map. The map document takes
 
62
     * ownership of the map.
 
63
     */
 
64
    MapDocument(Map *map, const QString &fileName = QString());
 
65
 
 
66
    /**
 
67
     * Destructor.
 
68
     */
 
69
    ~MapDocument();
 
70
 
 
71
    QString fileName() const { return mFileName; }
 
72
 
 
73
    void setFileName(const QString &fileName) { mFileName = fileName; }
 
74
 
 
75
    /**
 
76
     * Returns the map instance. Be aware that directly modifying the map will
 
77
     * not allow the GUI to update itself appropriately.
 
78
     */
 
79
    Map *map() const { return mMap; }
 
80
 
 
81
    /**
 
82
     * Sets the current layer to the given index.
 
83
     */
 
84
    void setCurrentLayer(int index);
 
85
 
 
86
    /**
 
87
     * Returns the index of the currently selected layer. Returns -1 if no
 
88
     * layer is currently selected.
 
89
     */
 
90
    int currentLayer() const;
 
91
 
 
92
    /**
 
93
     * Resize this map to the given \a size, while at the same time shifting
 
94
     * the contents by \a offset.
 
95
     */
 
96
    void resizeMap(const QSize &size, const QPoint &offset);
 
97
 
 
98
    /**
 
99
     * Offsets the layers at \a layerIndexes by \a offset, within \a bounds,
 
100
     * and optionally wraps on the X or Y axis.
 
101
     */
 
102
    void offsetMap(const QList<int> &layerIndexes,
 
103
                   const QPoint &offset,
 
104
                   const QRect &bounds,
 
105
                   bool wrapX, bool wrapY);
 
106
 
 
107
    enum LayerType {
 
108
        TileLayerType,
 
109
        ObjectLayerType
 
110
    };
 
111
    void addLayer(LayerType layerType);
 
112
    void duplicateLayer();
 
113
    void moveLayerUp(int index);
 
114
    void moveLayerDown(int index);
 
115
    void removeLayer(int index);
 
116
 
 
117
    void insertTileset(int index, Tileset *tileset);
 
118
    void removeTilesetAt(int index);
 
119
    void moveTileset(int from, int to);
 
120
 
 
121
    /**
 
122
     * Returns the layer model. Can be used to modify the layer stack of the
 
123
     * map, and to display the layer stack in a view.
 
124
     */
 
125
    LayerModel *layerModel() const { return mLayerModel; }
 
126
 
 
127
    /**
 
128
     * Returns the map renderer.
 
129
     */
 
130
    MapRenderer *renderer() const { return mRenderer; }
 
131
 
 
132
    /**
 
133
     * Returns the undo stack of this map document. Should be used to push any
 
134
     * commands on that modify the map.
 
135
     */
 
136
    QUndoStack *undoStack() const { return mUndoStack; }
 
137
 
 
138
    /**
 
139
     * Returns the selected area of tiles.
 
140
     */
 
141
    const QRegion &tileSelection() const { return mTileSelection; }
 
142
 
 
143
    /**
 
144
     * Sets the selected area of tiles.
 
145
     */
 
146
    void setTileSelection(const QRegion &selection);
 
147
 
 
148
    void emitMapChanged();
 
149
 
 
150
    /**
 
151
     * Emits the region changed signal for the specified region. The region
 
152
     * should be in tile coordinates. This method is used by the TilePainter.
 
153
     */
 
154
    void emitRegionChanged(const QRegion &region);
 
155
 
 
156
    void emitObjectsAdded(const QList<MapObject*> &objects);
 
157
    void emitObjectsRemoved(const QList<MapObject*> &objects);
 
158
    void emitObjectsChanged(const QList<MapObject*> &objects);
 
159
 
 
160
    inline void emitObjectAdded(MapObject *object)
 
161
    { emitObjectsAdded(QList<MapObject*>() << object); }
 
162
 
 
163
    inline void emitObjectRemoved(MapObject *object)
 
164
    { emitObjectsRemoved(QList<MapObject*>() << object); }
 
165
 
 
166
    inline void emitObjectChanged(MapObject *object)
 
167
    { emitObjectsChanged(QList<MapObject*>() << object); }
 
168
 
 
169
signals:
 
170
    /**
 
171
     * Emitted when the selected tile region changes. Sends the currently
 
172
     * selected region and the previously selected region.
 
173
     */
 
174
    void tileSelectionChanged(const QRegion &newSelection,
 
175
                              const QRegion &oldSelection);
 
176
 
 
177
    /**
 
178
     * Emitted when the map size or its tile size changes.
 
179
     */
 
180
    void mapChanged();
 
181
 
 
182
    void layerAdded(int index);
 
183
    void layerRemoved(int index);
 
184
    void layerChanged(int index);
 
185
 
 
186
    /**
 
187
     * Emitted after a new layer was added and the name should be edited.
 
188
     * Applies to the current layer.
 
189
     */
 
190
    void editLayerNameRequested();
 
191
 
 
192
    /**
 
193
     * Emitted when the current layer changes.
 
194
     */
 
195
    void currentLayerChanged(int index);
 
196
 
 
197
    /**
 
198
     * Emitted when a certain region of the map changes. The region is given in
 
199
     * tile coordinates.
 
200
     */
 
201
    void regionChanged(const QRegion &region);
 
202
 
 
203
    void tilesetAdded(int index, Tileset *tileset);
 
204
    void tilesetRemoved(Tileset *tileset);
 
205
    void tilesetMoved(int from, int to);
 
206
 
 
207
    void objectsAdded(const QList<MapObject*> &objects);
 
208
    void objectsRemoved(const QList<MapObject*> &objects);
 
209
    void objectsChanged(const QList<MapObject*> &objects);
 
210
 
 
211
private slots:
 
212
    void onLayerAdded(int index);
 
213
    void onLayerRemoved(int index);
 
214
 
 
215
private:
 
216
    QString mFileName;
 
217
    Map *mMap;
 
218
    LayerModel *mLayerModel;
 
219
    QRegion mTileSelection;
 
220
    MapRenderer *mRenderer;
 
221
    int mCurrentLayer;
 
222
    QUndoStack *mUndoStack;
 
223
};
 
224
 
 
225
} // namespace Internal
 
226
} // namespace Tiled
 
227
 
 
228
#endif // MAPDOCUMENT_H