1 /*
2  * tilesetchanges.h
3  * Copyright 2011, Maus <Zeitmaus@github>
4  * Copyright 2011-2013, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
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 #pragma once
23 
24 #include "tileset.h"
25 #include "undocommands.h"
26 
27 #include <QColor>
28 #include <QPoint>
29 #include <QSize>
30 #include <QUndoCommand>
31 
32 namespace Tiled {
33 
34 class Tileset;
35 
36 class TilesetDocument;
37 
38 class RenameTileset : public QUndoCommand
39 {
40 public:
41     RenameTileset(TilesetDocument *tilesetDocument,
42                   const QString &newName);
43 
44     void undo() override;
45     void redo() override;
46 
47 private:
48     TilesetDocument *mTilesetDocument;
49     QString mOldName;
50     QString mNewName;
51 };
52 
53 
54 class ChangeTilesetTileOffset : public QUndoCommand
55 {
56 public:
57     ChangeTilesetTileOffset(TilesetDocument *tilesetDocument,
58                             QPoint tileOffset);
59 
60     void undo() override;
61     void redo() override;
62 
id()63     int id() const override { return Cmd_ChangeTilesetTileOffset; }
64     bool mergeWith(const QUndoCommand *other) override;
65 
66 private:
67     TilesetDocument *mTilesetDocument;
68     QPoint mOldTileOffset;
69     QPoint mNewTileOffset;
70 };
71 
72 
73 struct TilesetParameters
74 {
TilesetParametersTilesetParameters75     TilesetParameters()
76         : tileSpacing(0)
77         , margin(0)
78     {}
79 
80     explicit TilesetParameters(const Tileset &tileset);
81 
82     bool operator != (const TilesetParameters &other) const;
83 
84     QUrl imageSource;
85     QColor transparentColor;
86     QSize tileSize;
87     int tileSpacing;
88     int margin;
89 };
90 
91 class ChangeTilesetParameters : public QUndoCommand
92 {
93 public:
94     ChangeTilesetParameters(TilesetDocument *tilesetDocument,
95                             const TilesetParameters &parameters);
96 
97     void undo() override;
98     void redo() override;
99 
100 private:
101     void apply(const TilesetParameters &parameters);
102 
103     TilesetDocument *mTilesetDocument;
104     TilesetParameters mOldParameters;
105     TilesetParameters mNewParameters;
106 };
107 
108 
109 class ChangeTilesetColumnCount : public QUndoCommand
110 {
111 public:
112     ChangeTilesetColumnCount(TilesetDocument *tilesetDocument,
113                              int columnCount);
114 
undo()115     void undo() override { swap(); }
redo()116     void redo() override { swap(); }
117 
118 private:
119     void swap();
120 
121     TilesetDocument *mTilesetDocument;
122     int mColumnCount;
123 };
124 
125 
126 class ChangeTilesetBackgroundColor : public QUndoCommand
127 {
128 public:
129     ChangeTilesetBackgroundColor(TilesetDocument *tilesetDocument,
130                                  const QColor &color);
131 
undo()132     void undo() override { swap(); }
redo()133     void redo() override { swap(); }
134 
135 private:
136     void swap();
137 
138     TilesetDocument *mTilesetDocument;
139     QColor mColor;
140 };
141 
142 
143 class ChangeTilesetOrientation : public QUndoCommand
144 {
145 public:
146     ChangeTilesetOrientation(TilesetDocument *tilesetDocument,
147                              Tileset::Orientation orientation);
148 
undo()149     void undo() override { swap(); }
redo()150     void redo() override { swap(); }
151 
152 private:
153     void swap();
154 
155     TilesetDocument *mTilesetDocument;
156     Tileset::Orientation mOrientation;
157 };
158 
159 
160 class ChangeTilesetObjectAlignment : public QUndoCommand
161 {
162 public:
163     ChangeTilesetObjectAlignment(TilesetDocument *tilesetDocument,
164                                  Alignment objectAlignment);
165 
undo()166     void undo() override { swap(); }
redo()167     void redo() override { swap(); }
168 
169 private:
170     void swap();
171 
172     TilesetDocument *mTilesetDocument;
173     Alignment mObjectAlignment;
174 };
175 
176 
177 class ChangeTilesetGridSize : public QUndoCommand
178 {
179 public:
180     ChangeTilesetGridSize(TilesetDocument *tilesetDocument,
181                           QSize gridSize);
182 
undo()183     void undo() override { swap(); }
redo()184     void redo() override { swap(); }
185 
186 private:
187     void swap();
188 
189     TilesetDocument *mTilesetDocument;
190     QSize mGridSize;
191 };
192 
193 class ChangeTilesetTransformationFlags : public QUndoCommand
194 {
195 public:
196     ChangeTilesetTransformationFlags(TilesetDocument *TilesetDocument,
197                                      Tileset::TransformationFlags newValue);
198 
199     void undo() override;
200     void redo() override;
201 
202 private:
203     TilesetDocument *mTilesetDocument;
204     const Tileset::TransformationFlags mOldValue;
205     const Tileset::TransformationFlags mNewValue;
206 };
207 
208 } // namespace Tiled
209