1 /*
2  * resizemap.cpp
3  * Copyright 2009, 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 #include "resizemap.h"
22 
23 #include "map.h"
24 #include "mapdocument.h"
25 
26 #include <QCoreApplication>
27 
28 namespace Tiled {
29 
ResizeMap(MapDocument * mapDocument,QSize size,QUndoCommand * parent)30 ResizeMap::ResizeMap(MapDocument *mapDocument,
31                      QSize size,
32                      QUndoCommand *parent)
33     : QUndoCommand(QCoreApplication::translate("Undo Commands",
34                                                "Resize Map"),
35                    parent)
36     , mMapDocument(mapDocument)
37     , mSize(size)
38 {
39 }
40 
undo()41 void ResizeMap::undo()
42 {
43     swapSize();
44 }
45 
redo()46 void ResizeMap::redo()
47 {
48     swapSize();
49 }
50 
swapSize()51 void ResizeMap::swapSize()
52 {
53     Map *map = mMapDocument->map();
54     QSize oldSize(map->width(), map->height());
55     map->setWidth(mSize.width());
56     map->setHeight(mSize.height());
57     mSize = oldSize;
58 
59     emit mMapDocument->mapChanged();
60 }
61 
62 } // namespace Tiled
63