1 /*
2  * changeobjectgroupproperties.cpp
3  * Copyright 2010, Jeff Bland <jksb@member.fsf.org>
4  * Copyright 2010, 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 #include "changeobjectgroupproperties.h"
23 
24 #include "changeevents.h"
25 #include "document.h"
26 
27 #include <QCoreApplication>
28 
29 using namespace Tiled;
30 
ChangeObjectGroupProperties(Document * document,ObjectGroup * objectGroup,const QColor & newColor,ObjectGroup::DrawOrder newDrawOrder)31 ChangeObjectGroupProperties::ChangeObjectGroupProperties(Document *document,
32                                                          ObjectGroup *objectGroup,
33                                                          const QColor &newColor,
34                                                          ObjectGroup::DrawOrder newDrawOrder)
35     : QUndoCommand(
36           QCoreApplication::translate(
37               "Undo Commands", "Change Object Layer Properties"))
38     , mDocument(document)
39     , mObjectGroup(objectGroup)
40     , mUndoColor(objectGroup->color())
41     , mRedoColor(newColor)
42     , mUndoDrawOrder(objectGroup->drawOrder())
43     , mRedoDrawOrder(newDrawOrder)
44 {
45 }
46 
undo()47 void ChangeObjectGroupProperties::undo()
48 {
49     int properties = 0;
50 
51     if (mObjectGroup->color() != mUndoColor) {
52         mObjectGroup->setColor(mUndoColor);
53         properties |= ObjectGroupChangeEvent::ColorProperty;
54     }
55 
56     if (mObjectGroup->drawOrder() != mUndoDrawOrder) {
57         mObjectGroup->setDrawOrder(mUndoDrawOrder);
58         properties |= ObjectGroupChangeEvent::DrawOrderProperty;
59     }
60 
61     emit mDocument->changed(ObjectGroupChangeEvent(mObjectGroup, properties));
62 }
63 
redo()64 void ChangeObjectGroupProperties::redo()
65 {
66     int properties = 0;
67 
68     if (mObjectGroup->color() != mRedoColor) {
69         mObjectGroup->setColor(mRedoColor);
70         properties |= ObjectGroupChangeEvent::ColorProperty;
71     }
72 
73     if (mObjectGroup->drawOrder() != mRedoDrawOrder) {
74         mObjectGroup->setDrawOrder(mRedoDrawOrder);
75         properties |= ObjectGroupChangeEvent::DrawOrderProperty;
76     }
77 
78     emit mDocument->changed(ObjectGroupChangeEvent(mObjectGroup, properties));
79 }
80