1 /*
2  * editableimagelayer.h
3  * Copyright 2019, Thorbjørn Lindeijer <bjorn@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 "editablelayer.h"
24 #include "imagelayer.h"
25 
26 namespace Tiled {
27 
28 class ScriptImage;
29 
30 class EditableImageLayer : public EditableLayer
31 {
32     Q_OBJECT
33 
34     Q_PROPERTY(QColor transparentColor READ transparentColor WRITE setTransparentColor)
35     Q_PROPERTY(QUrl imageSource READ imageSource WRITE setImageSource)
36 
37 public:
38     Q_INVOKABLE explicit EditableImageLayer(const QString &name = QString(),
39                                             QObject *parent = nullptr);
40 
41     EditableImageLayer(EditableMap *map,
42                        ImageLayer *imageLayer,
43                        QObject *parent = nullptr);
44 
45     const QColor &transparentColor() const;
46     const QUrl &imageSource() const;
47 
48     void setTransparentColor(const QColor &transparentColor);
49     void setImageSource(const QUrl &imageSource);
50 
51     Q_INVOKABLE void setImage(Tiled::ScriptImage *image, const QUrl &source = QUrl());
52 
53 private:
54     ImageLayer *imageLayer() const;
55 
56 };
57 
transparentColor()58 inline const QColor &EditableImageLayer::transparentColor() const
59 {
60     return imageLayer()->transparentColor();
61 }
62 
imageSource()63 inline const QUrl &EditableImageLayer::imageSource() const
64 {
65     return imageLayer()->imageSource();
66 }
67 
imageLayer()68 inline ImageLayer *EditableImageLayer::imageLayer() const
69 {
70     return static_cast<ImageLayer*>(layer());
71 }
72 
73 } // namespace Tiled
74