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
qquickellipseshape_p_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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#ifndef QQUICKELLIPSESHAPE_P_P_H
6#define QQUICKELLIPSESHAPE_P_P_H
7
9#include <QtQml/private/qqmlpropertyutils_p.h>
10#include <QtQuickShapes/private/qquickshape_p_p.h>
11
12//
13// W A R N I N G
14// -------------
15//
16// This file is not part of the Qt API. It exists purely as an
17// implementation detail. This header file may change from version to
18// version without notice, or even be removed.
19//
20// We mean it.
21//
22
24
25class Q_QUICKSHAPESDESIGNHELPERS_EXPORT QQuickEllipseShapePrivate : public QQuickShapePrivate
26{
27 Q_DECLARE_PUBLIC(QQuickEllipseShape)
28
29public:
30 QQuickEllipseShapePrivate();
31 ~QQuickEllipseShapePrivate() override;
32
33 struct RoundedCorner
34 {
35 void update(qreal diff, QVector2D a, QVector2D b, QVector2D c, qreal alpha, qreal radius)
36 {
37 A = a;
38 B = b;
39 C = c;
40 this->alpha = alpha;
41 this->radius = radius;
42 this->diff = diff;
43 }
44
45 void reset()
46 {
47 A = QVector2D();
48 B = QVector2D();
49 C = QVector2D();
50 alpha = 0;
51 radius = 0;
52 diff = 0;
53 }
54
55 // A - a point, where the rounding corner is located
56 QVector2D A;
57 // B - tangent point of the rounded corner arc, which is located on the ellipse's arc
58 // for the rounded corner at the ellipse's center this is a point on the edge defined by the
59 // end angle
60 // for the rounded corner at the begin angle this is a point on the outer arc of the ellipse
61 QVector2D B;
62 // C - tangent point of the rounded corner arc, which is located on the ellipse's edge
63 // for the rounded corner at the ellipse's center this is a point on the edge defined by the
64 // begin angle
65 QVector2D C;
66 qreal alpha = 0; // angle between AB and AC
67 qreal radius = 0; // rounded corner radius
68 // not a rounded corner data, but a helper used to compare
69 // currently calculated radius to the previously calculated radius
70 qreal diff = 0;
71 };
72
73 enum class RoundedCornerIndex { Center, InnerEnd, OuterEnd, InnerBegin, OuterBegin };
74
75 // helper, to avoid typing static_cast<int>(RoundedCornerIndex) every time
76 class RoundedCornerArray
77 {
78 public:
79 RoundedCorner &operator[](RoundedCornerIndex index)
80 {
81 return array[static_cast<int>(index)];
82 }
83
84 void reset()
85 {
86 for (auto &rc : array)
87 rc.reset();
88 }
89
90 private:
91 RoundedCorner array[5];
92 } roundedCorners;
93
94 void addLine(QVector2D point);
95 void addArc(QVector2D point, QVector2D arcRadius, QQuickPathArc::ArcDirection dir,
96 bool largeArc = false);
97
98 qreal getBorderOffset() const;
99
100 // calculates rounded corner at the ellipse center
101 void roundCenter(QVector2D center, QVector2D ellipseRadius);
102 // runs loop where begin and end rounded corners are calculated
103 void roundBeginEnd(QVector2D center, QVector2D ellipseRadius);
104 // calculates rounded corners on the outer arc
105 bool roundOuter(QVector2D center, QVector2D ellipseRadius, qreal deg, qreal arcAngle1,
106 qreal arcAngle2, RoundedCornerIndex index);
107 // calculates rounded corners on the inner arc
108 bool roundInner(QVector2D center, QVector2D ellipseRadius, qreal deg, qreal arcAngle1,
109 qreal arcAngle2, RoundedCornerIndex index);
110
111 // starts path at the center rounded corner and draws center rounded corner
112 void drawCenterCorner();
113 // connects outer and inner arcs with line and draws end rounded corner
114 void drawInnerEndCorner();
115 // starts path at the begin rounded corner and draws begin rounded corner
116 void drawInnerBeginCorner();
117 // connects previous rounded corner (center or begin) with line and draws begin rounded corner
118 void drawOuterBeginCorner();
119
120 // draw outer arc path from begin rounded corner to the end rounded corner
121 void drawOuterArcRounded(QVector2D center, QVector2D ellipseRadius);
122 // draw inner arc path from end rounded corner to the begin rounded corner
123 void drawInnerArcRounded(QVector2D center, QVector2D ellipseRadius);
124
125 // draws outer arc when no rounded corners involved
126 void drawOuterArc(QVector2D center, QVector2D ellipseRadius);
127 // draws full inner arc (no rounded corners)
128 void drawFullInnerArc(QVector2D center, QVector2D ellipseRadius);
129
130 // draws an ellipse when inner radius is not zero
131 void drawWithInnerRadius(QVector2D center, QVector2D ellipseRadius);
132 // draws an ellipse when inner radius is greater than zero
133 void drawWithoutInnerRadius(QVector2D center, QVector2D ellipseRadius);
134
135 void updatePath();
136
137 QQuickShapePath *path = nullptr;
138
139 qreal startAngle = 0;
140 qreal sweepAngle = 360;
141 qreal innerArcRatio = 0;
142 qreal cornerRadius = 10;
143 QQuickEllipseShape::BorderMode borderMode = QQuickEllipseShape::BorderMode::Inside;
144};
145
146QT_END_NAMESPACE
147
148#endif // QQUICKELLIPSE1SHAPE_P_P_H
Combined button and popup list for selecting options.
qreal angle_between_vectors(QVector2D a, QVector2D b)
qreal cross(QVector2D a, QVector2D b)
qreal arc_angle(qreal angle)
QVector2D tangent_ccw(QVector2D radius, qreal angle)
bool lines_intersect(QVector2D a, QVector2D b, QVector2D c, QVector2D d, qreal *s, qreal *t)
qreal cross(QVector2D a, QVector2D b, QVector2D c, QVector2D d)
bool is_equal(qreal a, qreal b, qreal epsilon=DBL_EPSILON)
QVector2D arc_point(QVector2D center, QVector2D radius, qreal angle)