5
6
7
8
9
10
11
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
82
83
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
295
296
297
298
299
300
301
306#ifndef QT_NO_DEBUG_STREAM
307#include <QtCore/qdebug.h>
308#include <QtCore/qstring.h>
311#ifndef QT_NO_DATASTREAM
312#include <QtCore/qdatastream.h>
315#include <QtCore/qpoint.h>
316#include <QtCore/qlist.h>
322 return (type >= QEasingCurve::InElastic
323 && type <= QEasingCurve::OutInBounce) ||
324 type == QEasingCurve::BezierSpline ||
325 type == QEasingCurve::TCBSpline;
340 return _point == other._point &&
341 qFuzzyCompare(_t, other._t) &&
342 qFuzzyCompare(_c, other._c) &&
343 qFuzzyCompare(_b, other._b);
350 stream << point._point
359 stream >> point._point
395 if (stream.version() > QDataStream::Qt_5_12) {
396 stream << func->_bezierCurves;
409 if (stream.version() > QDataStream::Qt_5_12) {
410 stream >> func->_bezierCurves;
421 QEasingCurve::EasingFunction func = curveToFunc(_t);
428 rv->_bezierCurves = _bezierCurves;
435 return _t == other._t &&
436 qFuzzyCompare(_p, other._p) &&
437 qFuzzyCompare(_a, other._a) &&
438 qFuzzyCompare(_o, other._o) &&
439 _bezierCurves == other._bezierCurves &&
440 _tcbPoints == other._tcbPoints;
443QT_BEGIN_INCLUDE_NAMESPACE
444#include "../../3rdparty/easing/easing.cpp"
445QT_END_INCLUDE_NAMESPACE
447class QEasingCurvePrivate
450 QEasingCurvePrivate()
451 : type(QEasingCurve::Linear),
455 QEasingCurvePrivate(
const QEasingCurvePrivate &other)
457 config(other.config ? other.config->copy() :
nullptr),
460 ~QEasingCurvePrivate() {
delete config; }
461 void setType_helper(QEasingCurve::Type);
463 QEasingCurve::Type type;
464 QEasingCurveFunction *config;
465 QEasingCurve::EasingFunction func;
489 if (_bezierCurves.constLast() == QPointF(1.0, 1.0)) {
491 _curveCount = _bezierCurves.size() / 3;
494 _intervals[i] = _bezierCurves.at(i * 3 + 2).x();
497 _curves[0].p0x = 0.0;
498 _curves[0].p0y = 0.0;
500 _curves[0].p1x = _bezierCurves.at(0).x();
501 _curves[0].p1y = _bezierCurves.at(0).y();
503 _curves[0].p2x = _bezierCurves.at(1).x();
504 _curves[0].p2y = _bezierCurves.at(1).y();
506 _curves[0].p3x = _bezierCurves.at(2).x();
507 _curves[0].p3y = _bezierCurves.at(2).y();
510 _curves[i].p0x = _bezierCurves.at(_bezierCurves.size() - 4).x();
511 _curves[i].p0y = _bezierCurves.at(_bezierCurves.size() - 4).y();
513 _curves[i].p1x = _bezierCurves.at(_bezierCurves.size() - 3).x();
514 _curves[i].p1y = _bezierCurves.at(_bezierCurves.size() - 3).y();
516 _curves[i].p2x = _bezierCurves.at(_bezierCurves.size() - 2).x();
517 _curves[i].p2y = _bezierCurves.at(_bezierCurves.size() - 2).y();
519 _curves[i].p3x = _bezierCurves.at(_bezierCurves.size() - 1).x();
520 _curves[i].p3y = _bezierCurves.at(_bezierCurves.size() - 1).y();
522 _curves[i].p0x = _bezierCurves.at(i * 3 - 1).x();
523 _curves[i].p0y = _bezierCurves.at(i * 3 - 1).y();
525 _curves[i].p1x = _bezierCurves.at(i * 3).x();
526 _curves[i].p1y = _bezierCurves.at(i * 3).y();
528 _curves[i].p2x = _bezierCurves.at(i * 3 + 1).x();
529 _curves[i].p2y = _bezierCurves.at(i * 3 + 1).y();
531 _curves[i].p3x = _bezierCurves.at(i * 3 + 2).x();
532 _curves[i].p3y = _bezierCurves.at(i * 3 + 2).y();
548 rv->_bezierCurves = _bezierCurves;
556 int currentSegment = 0;
559 if (x <= _intervals.data()[currentSegment])
564 singleCubicBezier = &_curves.data()[currentSegment];
570 qreal currentXValue = evaluateForX(singleCubicBezier, t);
572 const qreal newT = t - (currentXValue - x) / evaluateDerivateForX(singleCubicBezier, t);
579 Q_ASSERT(_bezierCurves.size() % 3 == 0);
581 if (_bezierCurves.isEmpty()) {
589 qWarning(
"QEasingCurve: Invalid bezier curve");
600 getBezierSegment(singleCubicBezier, x);
602 return evaluateSegmentForY(*singleCubicBezier, findTForX(*singleCubicBezier, x));
607 const qreal p0 = singleCubicBezier.p0y;
608 const qreal p1 = singleCubicBezier.p1y;
609 const qreal p2 = singleCubicBezier.p2y;
610 const qreal p3 = singleCubicBezier.p3y;
612 const qreal s = 1 - t;
614 const qreal s_squared = s * s;
615 const qreal t_squared = t * t;
617 const qreal s_cubic = s_squared * s;
618 const qreal t_cubic = t_squared * t;
620 return s_cubic * p0 + 3 * s_squared * t * p1 + 3 * s * t_squared * p2 + t_cubic * p3;
625 const qreal p0 = singleCubicBezier.p0x;
626 const qreal p1 = singleCubicBezier.p1x;
627 const qreal p2 = singleCubicBezier.p2x;
628 const qreal p3 = singleCubicBezier.p3x;
630 const qreal s = 1 - t;
632 const qreal s_squared = s * s;
633 const qreal t_squared = t * t;
635 const qreal s_cubic = s_squared * s;
636 const qreal t_cubic = t_squared * t;
638 return s_cubic * p0 + 3 * s_squared * t * p1 + 3 * s * t_squared * p2 + t_cubic * p3;
643 const qreal p0 = singleCubicBezier.p0x;
644 const qreal p1 = singleCubicBezier.p1x;
645 const qreal p2 = singleCubicBezier.p2x;
646 const qreal p3 = singleCubicBezier.p3x;
648 const qreal t_squared = t * t;
650 return -3*p0 + 3*p1 + 6*p0*t - 12*p1*t + 6*p2*t + 3*p3*t_squared - 3*p0*t_squared + 9*p1*t_squared - 9*p2*t_squared;
660 qreal t = _fast_cbrt(d);
663 const qreal t_cubic = t * t * t;
664 const qreal f = t_cubic + t_cubic + d;
666 t = t * (t_cubic + d + d) / f;
670
671
683 const unsigned int B1 = 709921077;
686 ux.i = (ux.i / 3 + B1);
698 const unsigned int B1 = 715094163;
700#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
708 quint32 hx = ux.pt[h0];
709 ut.pt[h0] = hx / 3 + B1;
716 return std::sqrt(1-x)*(1.5707963267948966192313216916398f + x*(-0.213300989f + x*(0.077980478f + x*-0.02164095f)));
721 const qreal pi_times2 = 2 *
M_PI;
722 const qreal pi_neg = -1 *
M_PI;
723 const qreal pi_by2 =
M_PI / 2.0;
732 const qreal a = 0.405284735;
733 const qreal b = 1.27323954;
735 const qreal x_squared = x * x;
738 qreal cos = b * x + a * x_squared;
741 return 0.225 * (cos * -1 * cos - cos) + cos;
742 return 0.225 * (cos * cos - cos) + cos;
745 qreal cos = b * x - a * x_squared;
748 return 0.225 * (cos * 1 * -cos - cos) + cos;
749 return 0.225 * (cos * cos - cos) + cos;
754 return (f >= -0.01 && f <= 1.01);
757 void static inline cosacos(qreal x, qreal &s1, qreal &s2, qreal &s3 )
762 const qreal x_squared = x * x;
763 const qreal x_plus_one_sqrt = qSqrt(1.0 + x);
764 const qreal one_minus_x_sqrt = qSqrt(1.0 - x);
768 s1 = 0.463614 - 0.0347815 * x + 0.00218245 * x_squared + 0.402421 * x_plus_one_sqrt;
772 s3 = 0.463614 + 0.402421 * one_minus_x_sqrt + 0.0347815 * x + 0.00218245 * x_squared;
776 s2 = -0.401644 * one_minus_x_sqrt - 0.0686804 * x + 0.401644 * x_plus_one_sqrt;
787 if (c < 0.000001 && c > -0.000001)
790 const qreal a_by3 = a / 3.0;
792 const qreal a_cubic = a * a * a;
794 const qreal p = b - a * a_by3;
795 const qreal q = 2.0 * a_cubic / 27.0 - a * b / 3.0 + c;
797 const qreal q_squared = q * q;
798 const qreal p_cubic = p * p * p;
799 const qreal D = 0.25 * q_squared + p_cubic / 27.0;
802 const qreal D_sqrt = qSqrt(D);
803 qreal u = _cbrt(-q * 0.5 + D_sqrt);
804 qreal v = _cbrt(-q * 0.5 - D_sqrt);
807 qreal t1 = z1 - a_by3;
812 qreal t2 = z2 - a_by3;
817 const qreal p_minus_sqrt = qSqrt(-p);
820 const qreal f = qSqrt(4.0 / 3.0) * p_minus_sqrt;
823 const qreal sqrtP = -3.0*qSqrt(3.0) / (p_minus_sqrt * p);
826 const qreal g = -q * 0.5 * sqrtP;
832 cosacos(g, s1, s2, s3);
834 qreal z1 = -1 * f * s2;
835 qreal t1 = z1 - a_by3;
840 qreal t2 = z2 - a_by3;
844 qreal z3 = -1 * f * s3;
845 qreal t3 = z3 - a_by3;
853 return value > -1e-3 && value < 1e-3;
858 const qreal p0 = singleCubicBezier.p0x;
859 const qreal p1 = singleCubicBezier.p1x;
860 const qreal p2 = singleCubicBezier.p2x;
861 const qreal p3 = singleCubicBezier.p3x;
863 const qreal factorT3 = p3 - p0 + 3 * p1 - 3 * p2;
864 const qreal factorT2 = 3 * p0 - 6 * p1 + 3 * p2;
865 const qreal factorT1 = -3 * p0 + 3 * p1;
866 const qreal factorT0 = p0 - x;
869 if (almostZero(factorT3)) {
870 if (almostZero(factorT2)) {
871 if (almostZero(factorT1))
874 return -factorT0 / factorT1;
876 const qreal discriminant = factorT1 * factorT1 - 4.0 * factorT2 * factorT0;
877 if (discriminant < 0.0)
880 if (discriminant == 0.0)
881 return -factorT1 / (2.0 * factorT2);
883 const qreal solution1 = (-factorT1 +
std::sqrt(discriminant)) / (2.0 * factorT2);
884 if (solution1 >= 0.0 && solution1 <= 1.0)
887 const qreal solution2 = (-factorT1 -
std::sqrt(discriminant)) / (2.0 * factorT2);
888 if (solution2 >= 0.0 && solution2 <= 1.0)
894 const qreal a = factorT2 / factorT3;
895 const qreal b = factorT1 / factorT3;
896 const qreal c = factorT0 / factorT3;
898 return singleRealSolutionForCubic(a, b, c);
913 Q_ASSERT(_bezierCurves.size() % 3 == 0);
915 if (_bezierCurves.isEmpty()) {
916 qWarning(
"QEasingCurve: Invalid tcb curve");
920 return BezierEase::value(x);
940 rv->_bezierCurves = _bezierCurves;
947 qreal p = (_p < 0) ? qreal(0.3) : _p;
948 qreal a = (_a < 0) ? qreal(1.0) : _a;
950 case QEasingCurve::InElastic:
951 return easeInElastic(t, a, p);
952 case QEasingCurve::OutElastic:
953 return easeOutElastic(t, a, p);
954 case QEasingCurve::InOutElastic:
955 return easeInOutElastic(t, a, p);
956 case QEasingCurve::OutInElastic:
957 return easeOutInElastic(t, a, p);
974 rv->_bezierCurves = _bezierCurves;
981 qreal a = (_a < 0) ? qreal(1.0) : _a;
983 case QEasingCurve::InBounce:
984 return easeInBounce(t, a);
985 case QEasingCurve::OutBounce:
986 return easeOutBounce(t, a);
987 case QEasingCurve::InOutBounce:
988 return easeInOutBounce(t, a);
989 case QEasingCurve::OutInBounce:
990 return easeOutInBounce(t, a);
1007 rv->_bezierCurves = _bezierCurves;
1019 qreal o = (_o < 0) ? qreal(1.70158) : _o;
1021 case QEasingCurve::InBack:
1022 return easeInBack(t, o);
1023 case QEasingCurve::OutBack:
1024 return easeOutBack(t, o);
1025 case QEasingCurve::InOutBack:
1026 return easeInOutBack(t, o);
1027 case QEasingCurve::OutInBack:
1028 return easeOutInBack(t, o);
1038 case QEasingCurve::Linear:
1040 case QEasingCurve::InQuad:
1042 case QEasingCurve::OutQuad:
1043 return &easeOutQuad;
1044 case QEasingCurve::InOutQuad:
1045 return &easeInOutQuad;
1046 case QEasingCurve::OutInQuad:
1047 return &easeOutInQuad;
1048 case QEasingCurve::InCubic:
1049 return &easeInCubic;
1050 case QEasingCurve::OutCubic:
1051 return &easeOutCubic;
1052 case QEasingCurve::InOutCubic:
1053 return &easeInOutCubic;
1054 case QEasingCurve::OutInCubic:
1055 return &easeOutInCubic;
1056 case QEasingCurve::InQuart:
1057 return &easeInQuart;
1058 case QEasingCurve::OutQuart:
1059 return &easeOutQuart;
1060 case QEasingCurve::InOutQuart:
1061 return &easeInOutQuart;
1062 case QEasingCurve::OutInQuart:
1063 return &easeOutInQuart;
1064 case QEasingCurve::InQuint:
1065 return &easeInQuint;
1066 case QEasingCurve::OutQuint:
1067 return &easeOutQuint;
1068 case QEasingCurve::InOutQuint:
1069 return &easeInOutQuint;
1070 case QEasingCurve::OutInQuint:
1071 return &easeOutInQuint;
1072 case QEasingCurve::InSine:
1074 case QEasingCurve::OutSine:
1075 return &easeOutSine;
1076 case QEasingCurve::InOutSine:
1077 return &easeInOutSine;
1078 case QEasingCurve::OutInSine:
1079 return &easeOutInSine;
1080 case QEasingCurve::InExpo:
1082 case QEasingCurve::OutExpo:
1083 return &easeOutExpo;
1084 case QEasingCurve::InOutExpo:
1085 return &easeInOutExpo;
1086 case QEasingCurve::OutInExpo:
1087 return &easeOutInExpo;
1088 case QEasingCurve::InCirc:
1090 case QEasingCurve::OutCirc:
1091 return &easeOutCirc;
1092 case QEasingCurve::InOutCirc:
1093 return &easeInOutCirc;
1094 case QEasingCurve::OutInCirc:
1095 return &easeOutInCirc;
1097 case QEasingCurve::InCurve:
1098 return &easeInCurve;
1099 case QEasingCurve::OutCurve:
1100 return &easeOutCurve;
1101 case QEasingCurve::SineCurve:
1102 return &easeSineCurve;
1103 case QEasingCurve::CosineCurve:
1104 return &easeCosineCurve;
1113 case QEasingCurve::InElastic:
1114 case QEasingCurve::OutElastic:
1115 case QEasingCurve::InOutElastic:
1116 case QEasingCurve::OutInElastic:
1117 return new ElasticEase(type);
1118 case QEasingCurve::OutBounce:
1119 case QEasingCurve::InBounce:
1120 case QEasingCurve::OutInBounce:
1121 case QEasingCurve::InOutBounce:
1122 return new BounceEase(type);
1123 case QEasingCurve::InBack:
1124 case QEasingCurve::OutBack:
1125 case QEasingCurve::InOutBack:
1126 case QEasingCurve::OutInBack:
1127 return new BackEase(type);
1128 case QEasingCurve::BezierSpline:
1129 return new BezierEase;
1130 case QEasingCurve::TCBSpline:
1133 return new QEasingCurveFunction(type, qreal(0.3), qreal(1.0), qreal(1.70158));
1140
1141
1142
1143
1144
1145
1146
1149
1150
1151QEasingCurve::QEasingCurve(Type type)
1152 : d_ptr(
new QEasingCurvePrivate)
1158
1159
1160QEasingCurve::QEasingCurve(
const QEasingCurve &other)
1161 : d_ptr(
new QEasingCurvePrivate(*other.d_ptr))
1167
1168
1170QEasingCurve::~QEasingCurve()
1176
1177
1178
1181
1182
1183
1184
1185
1186
1189
1190
1191
1192
1195
1196
1197
1198
1199
1200
1203 bool res = lhs.d_ptr->func == rhs.d_ptr->func
1204 && lhs.d_ptr->type == rhs.d_ptr->type;
1206 if (lhs.d_ptr->config && rhs.d_ptr->config) {
1208 res = lhs.d_ptr->config->operator==(*(rhs.d_ptr->config));
1210 }
else if (lhs.d_ptr->config || rhs.d_ptr->config) {
1212 res = qFuzzyCompare(lhs.amplitude(), rhs.amplitude())
1213 && qFuzzyCompare(lhs.period(), rhs.period())
1214 && qFuzzyCompare(lhs.overshoot(), rhs.overshoot());
1221
1222
1223
1224
1225
1226
1227
1228
1231
1232
1233
1234
1235
1236
1237qreal QEasingCurve::amplitude()
const
1239 return d_ptr->config ? d_ptr->config->_a : qreal(1.0);
1243
1244
1245
1246
1247
1248
1249void QEasingCurve::setAmplitude(qreal amplitude)
1252 d_ptr->config = curveToFunctionObject(d_ptr->type);
1253 d_ptr->config->_a = amplitude;
1257
1258
1259
1260
1261qreal QEasingCurve::period()
const
1263 return d_ptr->config ? d_ptr->config->_p : qreal(0.3);
1267
1268
1269
1270
1271
1272
1273void QEasingCurve::setPeriod(qreal period)
1276 d_ptr->config = curveToFunctionObject(d_ptr->type);
1277 d_ptr->config->_p = period;
1281
1282
1283
1284
1285qreal QEasingCurve::overshoot()
const
1287 return d_ptr->config ? d_ptr->config->_o : qreal(1.70158);
1291
1292
1293
1294
1295
1296
1297void QEasingCurve::setOvershoot(qreal overshoot)
1300 d_ptr->config = curveToFunctionObject(d_ptr->type);
1301 d_ptr->config->_o = overshoot;
1305
1306
1307
1308
1309
1310
1311
1312void QEasingCurve::addCubicBezierSegment(
const QPointF & c1,
const QPointF & c2,
const QPointF & endPoint)
1315 d_ptr->config = curveToFunctionObject(d_ptr->type);
1316 d_ptr->config->_bezierCurves << c1 << c2 << endPoint;
1321 const int count = tcbPoints.size();
1322 QList<QPointF> bezierPoints;
1323 bezierPoints.reserve(3 * (count - 1));
1325 for (
int i = 1; i < count; i++) {
1326 const qreal t_0 = tcbPoints.at(i - 1)._t;
1327 const qreal c_0 = tcbPoints.at(i - 1)._c;
1330 qreal
const t_1 = tcbPoints.at(i)._t;
1331 qreal
const c_1 = tcbPoints.at(i)._c;
1335 const QPointF c0(tcbPoints.at(i - 1)._point);
1336 const QPointF c3(tcbPoints.at(i)._point);
1340 c_minusOne = tcbPoints.at(i - 2)._point;
1341 b_0 = tcbPoints.at(i - 1)._b;
1344 if (i < (count - 1)) {
1345 c4 = tcbPoints.at(i + 1)._point;
1346 b_1 = tcbPoints.at(i)._b;
1349 const qreal dx_0 = 0.5 * (1-t_0) * ((1 + b_0) * (1 + c_0) * (c0.x() - c_minusOne.x()) + (1- b_0) * (1 - c_0) * (c3.x() - c0.x()));
1350 const qreal dy_0 = 0.5 * (1-t_0) * ((1 + b_0) * (1 + c_0) * (c0.y() - c_minusOne.y()) + (1- b_0) * (1 - c_0) * (c3.y() - c0.y()));
1352 const qreal dx_1 = 0.5 * (1-t_1) * ((1 + b_1) * (1 - c_1) * (c3.x() - c0.x()) + (1 - b_1) * (1 + c_1) * (c4.x() - c3.x()));
1353 const qreal dy_1 = 0.5 * (1-t_1) * ((1 + b_1) * (1 - c_1) * (c3.y() - c0.y()) + (1 - b_1) * (1 + c_1) * (c4.y() - c3.y()));
1355 const QPointF d_0 = QPointF(dx_0, dy_0);
1356 const QPointF d_1 = QPointF(dx_1, dy_1);
1358 QPointF c1 = (3 * c0 + d_0) / 3;
1359 QPointF c2 = (3 * c3 - d_1) / 3;
1360 bezierPoints << c1 << c2 << c3;
1362 return bezierPoints;
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379void QEasingCurve::addTCBSegment(
const QPointF &nextPoint, qreal t, qreal c, qreal b)
1382 d_ptr->config = curveToFunctionObject(d_ptr->type);
1384 d_ptr->config->_tcbPoints.append(TCBPoint(nextPoint, t, c, b));
1386 if (nextPoint == QPointF(1.0, 1.0)) {
1387 d_ptr->config->_bezierCurves = tcbToBezier(d_ptr->config->_tcbPoints);
1388 d_ptr->config->_tcbPoints.clear();
1394
1395
1396
1397
1398
1399
1400QList<QPointF> QEasingCurve::toCubicSpline()
const
1402 return d_ptr->config ? d_ptr->config->_bezierCurves : QList<QPointF>();
1406
1407
1408QEasingCurve::Type QEasingCurve::type()
const
1413void QEasingCurvePrivate::setType_helper(QEasingCurve::Type newType)
1416 qreal period = -1.0;
1417 qreal overshoot = -1.0;
1418 QList<QPointF> bezierCurves;
1419 QList<TCBPoint> tcbPoints;
1423 period = config->_p;
1424 overshoot = config->_o;
1425 bezierCurves =
std::move(config->_bezierCurves);
1432 if (isConfigFunction(newType) || (amp != -1.0) || (period != -1.0) || (overshoot != -1.0) ||
1433 !bezierCurves.isEmpty()) {
1438 config->_p = period;
1439 if (overshoot != -1.0)
1440 config->_o = overshoot;
1441 config->_bezierCurves =
std::move(bezierCurves);
1444 }
else if (newType != QEasingCurve::Custom) {
1445 func = curveToFunc(newType);
1447 Q_ASSERT((func ==
nullptr) == (config !=
nullptr));
1452
1453
1454void QEasingCurve::setType(Type type)
1456 if (d_ptr->type == type)
1458 if (type < Linear || type >= NCurveTypes - 1) {
1459 qWarning(
"QEasingCurve: Invalid curve type %d", type);
1463 d_ptr->setType_helper(type);
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477void QEasingCurve::setCustomType(EasingFunction func)
1480 qWarning(
"Function pointer must not be null");
1484 d_ptr->setType_helper(Custom);
1488
1489
1490
1491
1492QEasingCurve::EasingFunction QEasingCurve::customType()
const
1494 return d_ptr->type == Custom ? d_ptr->func :
nullptr;
1498
1499
1500
1501
1502
1503qreal QEasingCurve::valueForProgress(qreal progress)
const
1505 progress = qBound<qreal>(0, progress, 1);
1507 return d_ptr->func(progress);
1508 else if (d_ptr->config)
1509 return d_ptr->config->value(progress);
1514#ifndef QT_NO_DEBUG_STREAM
1517 QDebugStateSaver saver(debug);
1518 debug <<
"type:" << item.d_ptr->type
1519 <<
"func:" <<
reinterpret_cast<
const void *>(item.d_ptr->func);
1520 if (item.d_ptr->config) {
1521 debug << QString::fromLatin1(
"period:%1").arg(item.d_ptr->config->_p, 0,
'f', 20)
1522 << QString::fromLatin1(
"amp:%1").arg(item.d_ptr->config->_a, 0,
'f', 20)
1523 << QString::fromLatin1(
"overshoot:%1").arg(item.d_ptr->config->_o, 0,
'f', 20);
1529#ifndef QT_NO_DATASTREAM
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1545 if (easing.d_ptr->type == QEasingCurve::Custom) {
1546 qWarning(
"QEasingCurve: Cannot serialize an easing curve with a custom easing function");
1553 static_assert(isConfigFunction(QEasingCurve::InElastic));
1554 stream << QEasingCurve(QEasingCurve::InElastic);
1558 stream << quint8(easing.d_ptr->type);
1560 stream << quint64(0);
1562 bool hasConfig = easing.d_ptr->config;
1563 stream << hasConfig;
1565 stream << easing.d_ptr->config;
1571
1572
1573
1574
1575
1576
1577
1578
1582 QEasingCurve::Type type;
1585 type =
static_cast<QEasingCurve::Type>(int_type);
1586 if (type == QEasingCurve::Custom) {
1587 qWarning(
"QEasingCurve: Cannot deserialize an easing curve with a custom easing function");
1588 stream.setStatus(QDataStream::ReadCorruptData);
1589 type = QEasingCurve::Linear;
1591 easing.setType(type);
1594 [[maybe_unused]] quint64 ptr_func;
1598 stream >> hasConfig;
1599 delete easing.d_ptr->config;
1600 easing.d_ptr->config =
nullptr;
1604 easing.d_ptr->config = config;
1612#include "moc_qeasingcurve.cpp"
virtual ~QEasingCurveFunction()
bool operator==(const QEasingCurveFunction &other) const
QEasingCurveFunction(QEasingCurve::Type type, qreal period=0.3, qreal amplitude=1.0, qreal overshoot=1.70158)
virtual qreal value(qreal t)
virtual QEasingCurveFunction * copy() const
QList< QPointF > _bezierCurves
\inmodule QtCore\reentrant
static QList< QPointF > tcbToBezier(const TCBPoints &tcbPoints)
static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve)
Q_DECLARE_TYPEINFO(TCBPoint, Q_PRIMITIVE_TYPE)
static QT_BEGIN_NAMESPACE constexpr bool isConfigFunction(QEasingCurve::Type type)
QDataStream & operator<<(QDataStream &stream, QEasingCurveFunction *func)
QList< TCBPoint > TCBPoints
QDataStream & operator>>(QDataStream &stream, QEasingCurveFunction *func)
QDataStream & operator>>(QDataStream &stream, TCBPoint &point)
static QEasingCurveFunction * curveToFunctionObject(QEasingCurve::Type type)
QDataStream & operator<<(QDataStream &stream, const TCBPoint &point)
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
bool comparesEqual(const QFileInfo &lhs, const QFileInfo &rhs)
QDataStream & operator<<(QDataStream &stream, const QImage &image)
[0]
QDataStream & operator>>(QDataStream &stream, QImage &image)
QEasingCurveFunction * copy() const override
qreal value(qreal t) override
BackEase(QEasingCurve::Type type)
static float _fast_cbrt(float x)
static qreal evaluateDerivateForX(const SingleCubicBezier &singleCubicBezier, qreal t)
static qreal evaluateForX(const SingleCubicBezier &singleCubicBezier, qreal t)
static qreal _acos(qreal x)
static void cosacos(qreal x, qreal &s1, qreal &s2, qreal &s3)
static qreal _cos(qreal x)
static qreal _cbrt(qreal d)
static qreal newtonIteration(const SingleCubicBezier &singleCubicBezier, qreal t, qreal x)
static qreal evaluateSegmentForY(const SingleCubicBezier &singleCubicBezier, qreal t)
QList< SingleCubicBezier > _curves
static qreal singleRealSolutionForCubic(qreal a, qreal b, qreal c)
qreal value(qreal x) override
QEasingCurveFunction * copy() const override
void getBezierSegment(SingleCubicBezier *&singleCubicBezier, qreal x)
static qreal findTForX(const SingleCubicBezier &singleCubicBezier, qreal x)
BezierEase(QEasingCurve::Type type=QEasingCurve::BezierSpline)
QList< qreal > _intervals
static double _fast_cbrt(double d)
static bool inRange(qreal f)
static bool almostZero(qreal value)
BounceEase(QEasingCurve::Type type)
QEasingCurveFunction * copy() const override
qreal value(qreal t) override
qreal value(qreal t) override
ElasticEase(QEasingCurve::Type type)
QEasingCurveFunction * copy() const override
QEasingCurveFunction * copy() const override
qreal value(qreal x) override
bool operator==(const TCBPoint &other) const
TCBPoint(QPointF point, qreal t, qreal c, qreal b)