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