1 /*
2 * rotatemapobject.cpp
3 * Copyright 2012, Przemysław Grzywacz <nexather@gmail.com>
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 "rotatemapobject.h"
22
23 #include "changeevents.h"
24 #include "document.h"
25 #include "mapobject.h"
26
27 #include <QCoreApplication>
28
29 using namespace Tiled;
30
RotateMapObject(Document * document,MapObject * mapObject,qreal oldRotation)31 RotateMapObject::RotateMapObject(Document *document,
32 MapObject *mapObject,
33 qreal oldRotation)
34 : RotateMapObject(document,
35 mapObject,
36 mapObject->rotation(),
37 oldRotation)
38 {
39 }
40
RotateMapObject(Document * document,MapObject * mapObject,qreal newRotation,qreal oldRotation)41 RotateMapObject::RotateMapObject(Document *document,
42 MapObject *mapObject,
43 qreal newRotation,
44 qreal oldRotation)
45 : mDocument(document)
46 , mMapObject(mapObject)
47 , mOldRotation(oldRotation)
48 , mNewRotation(newRotation)
49 , mOldChangeState(mapObject->propertyChanged(MapObject::RotationProperty))
50 {
51 setText(QCoreApplication::translate("Undo Commands", "Rotate Object"));
52 }
53
undo()54 void RotateMapObject::undo()
55 {
56 mMapObject->setRotation(mOldRotation);
57 mMapObject->setPropertyChanged(MapObject::RotationProperty, mOldChangeState);
58
59 emit mDocument->changed(MapObjectsChangeEvent(mMapObject, MapObject::RotationProperty));
60 }
61
redo()62 void RotateMapObject::redo()
63 {
64 mMapObject->setRotation(mNewRotation);
65 mMapObject->setPropertyChanged(MapObject::RotationProperty);
66
67 emit mDocument->changed(MapObjectsChangeEvent(mMapObject, MapObject::RotationProperty));
68 }
69