1 /*
2  * clipboardmanager.h
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 #pragma once
22 
23 #include "properties.h"
24 
25 #include <QObject>
26 
27 #include <memory>
28 
29 class QClipboard;
30 
31 namespace Tiled {
32 
33 class ObjectGroup;
34 class Map;
35 
36 class MapDocument;
37 class MapView;
38 
39 /**
40  * The clipboard manager deals with interaction with the clipboard.
41  */
42 class ClipboardManager : public QObject
43 {
44     Q_OBJECT
45     Q_DISABLE_COPY(ClipboardManager)
46 
47     ClipboardManager();
48 
49 public:
50     static ClipboardManager *instance();
51 
52     bool hasMap() const;
53     std::unique_ptr<Map> map() const;
54     void setMap(const Map &map);
55 
56     bool hasProperties() const;
57     Properties properties() const;
58     void setProperties(const Properties &properties);
59 
60     bool copySelection(const MapDocument &mapDocument);
61 
62     enum PasteFlag {
63         PasteDefault        = 0x0,
64         PasteNoTileObjects  = 0x1,
65         PasteInPlace        = 0x2,
66     };
67     Q_DECLARE_FLAGS(PasteFlags, PasteFlag)
68     Q_FLAG(PasteFlags)
69 
70     void pasteObjectGroup(const ObjectGroup *objectGroup,
71                           MapDocument *mapDocument,
72                           const MapView *view,
73                           PasteFlags flags = PasteDefault);
74 
75 signals:
76     void hasMapChanged();
77     void hasPropertiesChanged();
78 
79 private:
80     void update();
81 
82     QClipboard *mClipboard;
83     bool mHasMap;
84     bool mHasProperties;
85 };
86 
87 /**
88  * Returns whether the clipboard has a map.
89  */
hasMap()90 inline bool ClipboardManager::hasMap() const
91 {
92     return mHasMap;
93 }
94 
95 /**
96  * Returns whether the clipboard holds some custom properties.
97  */
hasProperties()98 inline bool ClipboardManager::hasProperties() const
99 {
100     return mHasProperties;
101 }
102 
103 } // namespace Tiled
104 
105 Q_DECLARE_OPERATORS_FOR_FLAGS(Tiled::ClipboardManager::PasteFlags)
106