1 /*
2  * changeselectedarea.cpp
3  * Copyright 2009-2010, 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 "changeselectedarea.h"
22 
23 #include "mapdocument.h"
24 
25 #include <QCoreApplication>
26 
27 using namespace Tiled;
28 
ChangeSelectedArea(MapDocument * mapDocument,const QRegion & newSelection,QUndoCommand * parent)29 ChangeSelectedArea::ChangeSelectedArea(MapDocument *mapDocument,
30                                        const QRegion &newSelection,
31                                        QUndoCommand *parent)
32     : QUndoCommand(QCoreApplication::translate("Undo Commands",
33                                                "Change Selection"),
34                    parent)
35     , mMapDocument(mapDocument)
36     , mSelection(newSelection)
37 {
38 }
39 
undo()40 void ChangeSelectedArea::undo()
41 {
42     swapSelection();
43 }
44 
redo()45 void ChangeSelectedArea::redo()
46 {
47     swapSelection();
48 }
49 
swapSelection()50 void ChangeSelectedArea::swapSelection()
51 {
52     const QRegion oldSelection = mMapDocument->selectedArea();
53     mMapDocument->setSelectedArea(mSelection);
54     mSelection = oldSelection;
55 }
56