Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgsimplerectnode.cpp
Go to the documentation of this file.
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
6
8
9/*!
10 \class QSGSimpleRectNode
11
12 \brief The QSGSimpleRectNode class is a convenience class for drawing
13 solid filled rectangles using scenegraph.
14 \inmodule QtQuick
15
16 \warning This utility class is only functional when running with the default
17 or software backends of the Qt Quick scenegraph. As an alternative, prefer
18 using QSGRectangleNode via QQuickWindow::createRectangleNode(). However, this
19 standalone class is still useful when used via subclassing and the
20 application knows that no special scenegraph backends will be involved.
21 */
22
23
24
25/*!
26 Constructs a QSGSimpleRectNode instance which is spanning \a rect with
27 the color \a color.
28 */
29QSGSimpleRectNode::QSGSimpleRectNode(const QRectF &rect, const QColor &color)
30 : m_geometry(QSGGeometry::defaultAttributes_Point2D(), 4)
31{
32 Q_UNUSED(reserved);
33 QSGGeometry::updateRectGeometry(&m_geometry, rect);
34 m_material.setColor(color);
35 setMaterial(&m_material);
36 setGeometry(&m_geometry);
37}
38
39
40
41/*!
42 Constructs a QSGSimpleRectNode instance with an empty rectangle and
43 white color.
44 */
45QSGSimpleRectNode::QSGSimpleRectNode()
46 : m_geometry(QSGGeometry::defaultAttributes_Point2D(), 4)
47{
48 QSGGeometry::updateRectGeometry(&m_geometry, QRectF());
49 setMaterial(&m_material);
50 setGeometry(&m_geometry);
51}
52
53
54
55/*!
56 Sets the rectangle of this rect node to \a rect.
57 */
58void QSGSimpleRectNode::setRect(const QRectF &rect)
59{
60 QSGGeometry::updateRectGeometry(&m_geometry, rect);
61 markDirty(QSGNode::DirtyGeometry);
62}
63
64
65/*!
66 \fn void QSGSimpleRectNode::setRect(qreal x, qreal y, qreal w, qreal h)
67 \overload
68
69 Sets the rectangle of this rect node to begin at (\a x, \a y) and have
70 width \a w and height \a h.
71 */
72
73/*!
74 Returns the rectangle that this rect node covers.
75 */
76QRectF QSGSimpleRectNode::rect() const
77{
78 const QSGGeometry::Point2D *pts = m_geometry.vertexDataAsPoint2D();
79 return QRectF(pts[0].x,
80 pts[0].y,
81 pts[3].x - pts[0].x,
82 pts[3].y - pts[0].y);
83}
84
85
86/*!
87 Sets the color of this rectangle to \a color. The default
88 color will be white.
89 */
90void QSGSimpleRectNode::setColor(const QColor &color)
91{
92 if (color != m_material.color()) {
93 m_material.setColor(color);
94 markDirty(QSGNode::DirtyMaterial);
95 }
96}
97
98
99
100/*!
101 Returns the color of this rectangle.
102 */
103QColor QSGSimpleRectNode::color() const
104{
105 return m_material.color();
106}
107
108QT_END_NAMESPACE
Combined button and popup list for selecting options.