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

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