1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKPAINTEDITEM_P_H
5#define QQUICKPAINTEDITEM_P_H
6
7#include <QtQuick/qquickitem.h>
8#include <QtGui/qcolor.h>
9#include <QtCore/qrect.h>
10
11QT_BEGIN_NAMESPACE
12
13class QQuickPaintedItemPrivate;
14class QPainter;
15class Q_QUICK_EXPORT QQuickPaintedItem : public QQuickItem
16{
17 Q_OBJECT
18
19 Q_PROPERTY(QSize contentsSize READ contentsSize WRITE setContentsSize NOTIFY contentsSizeChanged)
20 Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged)
21 Q_PROPERTY(qreal contentsScale READ contentsScale WRITE setContentsScale NOTIFY contentsScaleChanged)
22 Q_PROPERTY(RenderTarget renderTarget READ renderTarget WRITE setRenderTarget NOTIFY renderTargetChanged)
23 Q_PROPERTY(QSize textureSize READ textureSize WRITE setTextureSize NOTIFY textureSizeChanged)
24
25 QML_NAMED_ELEMENT(PaintedItem)
26 QML_ADDED_IN_VERSION(2, 0)
27 QML_UNCREATABLE("Cannot create instance of abstract class PaintedItem.")
28
29public:
30 explicit QQuickPaintedItem(QQuickItem *parent = nullptr);
31 ~QQuickPaintedItem() override;
32
33 enum RenderTarget {
34 Image,
35 FramebufferObject,
36 InvertedYFramebufferObject
37 };
38 Q_ENUM(RenderTarget)
39
40 enum PerformanceHint {
41 FastFBOResizing = 0x1
42 };
43 Q_DECLARE_FLAGS(PerformanceHints, PerformanceHint)
44 Q_FLAG(PerformanceHints)
45
46 void update(const QRect &rect = QRect());
47
48 bool opaquePainting() const;
49 void setOpaquePainting(bool opaque);
50
51 bool antialiasing() const;
52 void setAntialiasing(bool enable);
53
54 bool mipmap() const;
55 void setMipmap(bool enable);
56
57 PerformanceHints performanceHints() const;
58 void setPerformanceHint(PerformanceHint hint, bool enabled = true);
59 void setPerformanceHints(PerformanceHints hints);
60
61 QRectF contentsBoundingRect() const;
62
63 QSize contentsSize() const;
64 void setContentsSize(const QSize &);
65 void resetContentsSize();
66
67 qreal contentsScale() const;
68 void setContentsScale(qreal);
69
70 QSize textureSize() const;
71 void setTextureSize(const QSize &size);
72
73 QColor fillColor() const;
74 void setFillColor(const QColor&);
75
76 RenderTarget renderTarget() const;
77 void setRenderTarget(RenderTarget target);
78
79 virtual void paint(QPainter *painter) = 0;
80
81 bool isTextureProvider() const override;
82 QSGTextureProvider *textureProvider() const override;
83
84Q_SIGNALS:
85 void fillColorChanged();
86 void contentsSizeChanged();
87 void contentsScaleChanged();
88 void renderTargetChanged();
89 void textureSizeChanged();
90
91protected:
92 QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *parent = nullptr);
93 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
94 void releaseResources() override;
95 void itemChange(ItemChange, const ItemChangeData &) override;
96
97private Q_SLOTS:
98 void invalidateSceneGraph();
99
100private:
101 Q_DISABLE_COPY(QQuickPaintedItem)
102 Q_DECLARE_PRIVATE(QQuickPaintedItem)
103};
104
105Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPaintedItem::PerformanceHints)
106
107QT_END_NAMESPACE
108
109#endif // QQUICKPAINTEDITEM_P_H
110

source code of qtdeclarative/src/quick/items/qquickpainteditem.h