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
qquickclipnode.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// Qt-Security score:significant reason:default
4
5
7
8#include <QtGui/qvector2d.h>
9#include <QtCore/qmath.h>
10
12
13QQuickDefaultClipNode::QQuickDefaultClipNode(const QRectF &rect)
14 : m_rect(rect)
15 , m_radius(0)
16 , m_dirty_geometry(true)
17 , m_geometry(QSGGeometry::defaultAttributes_Point2D(), 0)
18{
19 Q_UNUSED(m_reserved);
20 setGeometry(&m_geometry);
21 setIsRectangular(true);
22}
23
24void QQuickDefaultClipNode::setRect(const QRectF &rect)
25{
26 m_rect = rect;
27 m_dirty_geometry = true;
28}
29
30void QQuickDefaultClipNode::setRadius(qreal radius)
31{
32 m_radius = radius;
33 m_dirty_geometry = true;
34 setIsRectangular(radius == 0);
35}
36
37void QQuickDefaultClipNode::update()
38{
39 if (m_dirty_geometry) {
40 updateGeometry();
41 m_dirty_geometry = false;
42 }
43}
44
45void QQuickDefaultClipNode::updateGeometry()
46{
47 QSGGeometry *g = geometry();
48
49 // Radius should never exceed half of the width or half of the height
50 const qreal radius = qMin(qMin(m_rect.width() / 2, m_rect.height() / 2), m_radius);
51
52 if (radius < 0 || qFuzzyIsNull(radius)) {
53 g->allocate(4);
54 QSGGeometry::updateRectGeometry(g, m_rect);
55
56 } else {
57 int vertexCount = 0;
58
59 QRectF rect = m_rect;
60 rect.adjust(radius, radius, -radius, -radius);
61
62 int segments = qMin(30, qCeil(radius)); // Number of segments per corner.
63
64 g->allocate((segments + 1) * 4);
65
66 QVector2D *vertices = (QVector2D *)g->vertexData();
67
68 for (int part = 0; part < 2; ++part) {
69 for (int i = 0; i <= segments; ++i) {
70 //### Should change to calculate sin/cos only once.
71 qreal angle = qreal(0.5 * M_PI) * (part + i / qreal(segments));
72 qreal s = qFastSin(angle);
73 qreal c = qFastCos(angle);
74 qreal y = (part ? rect.bottom() : rect.top()) - radius * c; // current inner y-coordinate.
75 qreal lx = rect.left() - radius * s; // current inner left x-coordinate.
76 qreal rx = rect.right() + radius * s; // current inner right x-coordinate.
77
78 vertices[vertexCount++] = QVector2D(rx, y);
79 vertices[vertexCount++] = QVector2D(lx, y);
80 }
81 }
82
83 }
84#ifdef QSG_RUNTIME_DESCRIPTION
85#ifndef QT_NO_DEBUG_STREAM
86 QString desc;
87 {
88 QDebug dbg(&desc);
89 dbg << m_rect;
90 if (!qFuzzyIsNull(m_radius))
91 dbg << "radius" << m_radius;
92 }
93 qsgnode_set_description(this, desc);
94#endif
95#endif
96 setClipRect(m_rect);
97 markDirty(DirtyGeometry);
98}
99
100QT_END_NAMESPACE
Combined button and popup list for selecting options.