1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQUICKPAINTEDITEM_P_H
41#define QQUICKPAINTEDITEM_P_H
42
43#include <QtQuick/qquickitem.h>
44#include <QtGui/qcolor.h>
45
46QT_BEGIN_NAMESPACE
47
48class QQuickPaintedItemPrivate;
49class Q_QUICK_EXPORT QQuickPaintedItem : public QQuickItem
50{
51 Q_OBJECT
52
53 Q_PROPERTY(QSize contentsSize READ contentsSize WRITE setContentsSize NOTIFY contentsSizeChanged)
54 Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged)
55 Q_PROPERTY(qreal contentsScale READ contentsScale WRITE setContentsScale NOTIFY contentsScaleChanged)
56 Q_PROPERTY(RenderTarget renderTarget READ renderTarget WRITE setRenderTarget NOTIFY renderTargetChanged)
57 Q_PROPERTY(QSize textureSize READ textureSize WRITE setTextureSize NOTIFY textureSizeChanged)
58
59public:
60 explicit QQuickPaintedItem(QQuickItem *parent = nullptr);
61 ~QQuickPaintedItem() override;
62
63 enum RenderTarget {
64 Image,
65 FramebufferObject,
66 InvertedYFramebufferObject
67 };
68 Q_ENUM(RenderTarget)
69
70 enum PerformanceHint {
71 FastFBOResizing = 0x1
72 };
73 Q_DECLARE_FLAGS(PerformanceHints, PerformanceHint)
74 Q_FLAG(PerformanceHints)
75
76 void update(const QRect &rect = QRect());
77
78 bool opaquePainting() const;
79 void setOpaquePainting(bool opaque);
80
81 bool antialiasing() const;
82 void setAntialiasing(bool enable);
83
84 bool mipmap() const;
85 void setMipmap(bool enable);
86
87 PerformanceHints performanceHints() const;
88 void setPerformanceHint(PerformanceHint hint, bool enabled = true);
89 void setPerformanceHints(PerformanceHints hints);
90
91 QRectF contentsBoundingRect() const;
92
93 QSize contentsSize() const;
94 void setContentsSize(const QSize &);
95 void resetContentsSize();
96
97 qreal contentsScale() const;
98 void setContentsScale(qreal);
99
100 QSize textureSize() const;
101 void setTextureSize(const QSize &size);
102
103 QColor fillColor() const;
104 void setFillColor(const QColor&);
105
106 RenderTarget renderTarget() const;
107 void setRenderTarget(RenderTarget target);
108
109 virtual void paint(QPainter *painter) = 0;
110
111 bool isTextureProvider() const override;
112 QSGTextureProvider *textureProvider() const override;
113
114Q_SIGNALS:
115 void fillColorChanged();
116 void contentsSizeChanged();
117 void contentsScaleChanged();
118 void renderTargetChanged();
119 void textureSizeChanged();
120
121protected:
122 QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *parent = nullptr);
123 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
124 void releaseResources() override;
125 void itemChange(ItemChange, const ItemChangeData &) override;
126
127private Q_SLOTS:
128 void invalidateSceneGraph();
129
130private:
131 Q_DISABLE_COPY(QQuickPaintedItem)
132 Q_DECLARE_PRIVATE(QQuickPaintedItem)
133};
134
135Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPaintedItem::PerformanceHints)
136
137QT_END_NAMESPACE
138
139#endif // QQUICKPAINTEDITEM_P_H
140