author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
/* |
|
43 |
||
44 |
| *property* | *Used for type* | |
|
45 |
| period | QEasingCurve::{In,Out,InOut,OutIn}Elastic | |
|
46 |
| amplitude | QEasingCurve::{In,Out,InOut,OutIn}Bounce, QEasingCurve::{In,Out,InOut,OutIn}Elastic | |
|
47 |
| overshoot | QEasingCurve::{In,Out,InOut,OutIn}Back | |
|
48 |
||
49 |
*/ |
|
50 |
||
51 |
||
52 |
||
53 |
||
54 |
/*! |
|
55 |
\class QEasingCurve |
|
56 |
\since 4.6 |
|
57 |
\ingroup animation |
|
58 |
\brief The QEasingCurve class provides easing curves for controlling animation. |
|
59 |
||
60 |
Easing curves describe a function that controls how the speed of the interpolation |
|
61 |
between 0 and 1 should be. Easing curves allow transitions from |
|
62 |
one value to another to appear more natural than a simple constant speed would allow. |
|
63 |
The QEasingCurve class is usually used in conjunction with the QVariantAnimation and |
|
64 |
QPropertyAnimation classes but can be used on its own. It is usually used to accelerate |
|
65 |
the interpolation from zero velocity (ease in) or decelerate to zero velocity (ease out). |
|
66 |
Ease in and ease out can also be combined in the same easing curve. |
|
67 |
||
68 |
To calculate the speed of the interpolation, the easing curve provides the function |
|
69 |
valueForProgress(), where the \a progress argument specifies the progress of the |
|
70 |
interpolation: 0 is the start value of the interpolation, 1 is the end value of the |
|
71 |
interpolation. The returned value is the effective progress of the interpolation. |
|
72 |
If the returned value is the same as the input value for all input values the easing |
|
73 |
curve is a linear curve. This is the default behaviour. |
|
74 |
||
75 |
For example, |
|
76 |
\code |
|
77 |
QEasingCurve easing(QEasingCurve::InOutQuad); |
|
78 |
||
79 |
for(qreal t = 0.0; t < 1.0; t+=0.1) |
|
80 |
qWarning() << "Effective progress" << t << " is |
|
81 |
<< easing.valueForProgress(t); |
|
82 |
\endcode |
|
83 |
will print the effective progress of the interpolation between 0 and 1. |
|
84 |
||
85 |
When using a QPropertyAnimation, the associated easing curve will be used to control the |
|
86 |
progress of the interpolation between startValue and endValue: |
|
87 |
\code |
|
88 |
QPropertyAnimation animation; |
|
89 |
animation.setStartValue(0); |
|
90 |
animation.setEndValue(1000); |
|
91 |
animation.setDuration(1000); |
|
92 |
animation.setEasingCurve(QEasingCurve::InOutQuad); |
|
93 |
\endcode |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
94 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
95 |
The ability to set an amplitude, overshoot, or period depends on the QEasingCurve type. Amplitude access |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
96 |
is available to curves that behave as springs such as elastic and bounce curves. Changing the amplitude changes |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
97 |
the height of the curve. Period access is only available to elastic curves and setting a higher period slows |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
98 |
the rate of bounce. Only curves that have "boomerang" behaviors such as the InBack, OutBack, InOutBack, and OutInBack |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
99 |
have overshoot settings. These curves will interpolate beyond the end points and return to the end point, |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
100 |
acting similar to a boomerang. |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
101 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
102 |
The \l{Easing Curves Example} contains samples of QEasingCurve types and lets you change the curve settings. |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
103 |
|
0 | 104 |
*/ |
105 |
||
106 |
/*! |
|
107 |
\enum QEasingCurve::Type |
|
108 |
||
109 |
The type of easing curve. |
|
110 |
||
111 |
\value Linear \inlineimage qeasingcurve-linear.png |
|
112 |
\br |
|
113 |
Easing curve for a linear (t) function: |
|
114 |
velocity is constant. |
|
115 |
\value InQuad \inlineimage qeasingcurve-inquad.png |
|
116 |
\br |
|
117 |
Easing curve for a quadratic (t^2) function: |
|
118 |
accelerating from zero velocity. |
|
119 |
\value OutQuad \inlineimage qeasingcurve-outquad.png |
|
120 |
\br |
|
121 |
Easing curve for a quadratic (t^2) function: |
|
122 |
decelerating to zero velocity. |
|
123 |
\value InOutQuad \inlineimage qeasingcurve-inoutquad.png |
|
124 |
\br |
|
125 |
Easing curve for a quadratic (t^2) function: |
|
126 |
acceleration until halfway, then deceleration. |
|
127 |
\value OutInQuad \inlineimage qeasingcurve-outinquad.png |
|
128 |
\br |
|
129 |
Easing curve for a quadratic (t^2) function: |
|
130 |
deceleration until halfway, then acceleration. |
|
131 |
\value InCubic \inlineimage qeasingcurve-incubic.png |
|
132 |
\br |
|
133 |
Easing curve for a cubic (t^3) function: |
|
134 |
accelerating from zero velocity. |
|
135 |
\value OutCubic \inlineimage qeasingcurve-outcubic.png |
|
136 |
\br |
|
137 |
Easing curve for a cubic (t^3) function: |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
decelerating to zero velocity. |
0 | 139 |
\value InOutCubic \inlineimage qeasingcurve-inoutcubic.png |
140 |
\br |
|
141 |
Easing curve for a cubic (t^3) function: |
|
142 |
acceleration until halfway, then deceleration. |
|
143 |
\value OutInCubic \inlineimage qeasingcurve-outincubic.png |
|
144 |
\br |
|
145 |
Easing curve for a cubic (t^3) function: |
|
146 |
deceleration until halfway, then acceleration. |
|
147 |
\value InQuart \inlineimage qeasingcurve-inquart.png |
|
148 |
\br |
|
149 |
Easing curve for a quartic (t^4) function: |
|
150 |
accelerating from zero velocity. |
|
151 |
\value OutQuart \inlineimage qeasingcurve-outquart.png |
|
152 |
\br |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
153 |
Easing curve for a quartic (t^4) function: |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
decelerating to zero velocity. |
0 | 155 |
\value InOutQuart \inlineimage qeasingcurve-inoutquart.png |
156 |
\br |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
157 |
Easing curve for a quartic (t^4) function: |
0 | 158 |
acceleration until halfway, then deceleration. |
159 |
\value OutInQuart \inlineimage qeasingcurve-outinquart.png |
|
160 |
\br |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
161 |
Easing curve for a quartic (t^4) function: |
0 | 162 |
deceleration until halfway, then acceleration. |
163 |
\value InQuint \inlineimage qeasingcurve-inquint.png |
|
164 |
\br |
|
165 |
Easing curve for a quintic (t^5) easing |
|
166 |
in: accelerating from zero velocity. |
|
167 |
\value OutQuint \inlineimage qeasingcurve-outquint.png |
|
168 |
\br |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
169 |
Easing curve for a quintic (t^5) function: |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
decelerating to zero velocity. |
0 | 171 |
\value InOutQuint \inlineimage qeasingcurve-inoutquint.png |
172 |
\br |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
173 |
Easing curve for a quintic (t^5) function: |
0 | 174 |
acceleration until halfway, then deceleration. |
175 |
\value OutInQuint \inlineimage qeasingcurve-outinquint.png |
|
176 |
\br |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
177 |
Easing curve for a quintic (t^5) function: |
0 | 178 |
deceleration until halfway, then acceleration. |
179 |
\value InSine \inlineimage qeasingcurve-insine.png |
|
180 |
\br |
|
181 |
Easing curve for a sinusoidal (sin(t)) function: |
|
182 |
accelerating from zero velocity. |
|
183 |
\value OutSine \inlineimage qeasingcurve-outsine.png |
|
184 |
\br |
|
185 |
Easing curve for a sinusoidal (sin(t)) function: |
|
186 |
decelerating from zero velocity. |
|
187 |
\value InOutSine \inlineimage qeasingcurve-inoutsine.png |
|
188 |
\br |
|
189 |
Easing curve for a sinusoidal (sin(t)) function: |
|
190 |
acceleration until halfway, then deceleration. |
|
191 |
\value OutInSine \inlineimage qeasingcurve-outinsine.png |
|
192 |
\br |
|
193 |
Easing curve for a sinusoidal (sin(t)) function: |
|
194 |
deceleration until halfway, then acceleration. |
|
195 |
\value InExpo \inlineimage qeasingcurve-inexpo.png |
|
196 |
\br |
|
197 |
Easing curve for an exponential (2^t) function: |
|
198 |
accelerating from zero velocity. |
|
199 |
\value OutExpo \inlineimage qeasingcurve-outexpo.png |
|
200 |
\br |
|
201 |
Easing curve for an exponential (2^t) function: |
|
202 |
decelerating from zero velocity. |
|
203 |
\value InOutExpo \inlineimage qeasingcurve-inoutexpo.png |
|
204 |
\br |
|
205 |
Easing curve for an exponential (2^t) function: |
|
206 |
acceleration until halfway, then deceleration. |
|
207 |
\value OutInExpo \inlineimage qeasingcurve-outinexpo.png |
|
208 |
\br |
|
209 |
Easing curve for an exponential (2^t) function: |
|
210 |
deceleration until halfway, then acceleration. |
|
211 |
\value InCirc \inlineimage qeasingcurve-incirc.png |
|
212 |
\br |
|
213 |
Easing curve for a circular (sqrt(1-t^2)) function: |
|
214 |
accelerating from zero velocity. |
|
215 |
\value OutCirc \inlineimage qeasingcurve-outcirc.png |
|
216 |
\br |
|
217 |
Easing curve for a circular (sqrt(1-t^2)) function: |
|
218 |
decelerating from zero velocity. |
|
219 |
\value InOutCirc \inlineimage qeasingcurve-inoutcirc.png |
|
220 |
\br |
|
221 |
Easing curve for a circular (sqrt(1-t^2)) function: |
|
222 |
acceleration until halfway, then deceleration. |
|
223 |
\value OutInCirc \inlineimage qeasingcurve-outincirc.png |
|
224 |
\br |
|
225 |
Easing curve for a circular (sqrt(1-t^2)) function: |
|
226 |
deceleration until halfway, then acceleration. |
|
227 |
\value InElastic \inlineimage qeasingcurve-inelastic.png |
|
228 |
\br |
|
229 |
Easing curve for an elastic |
|
230 |
(exponentially decaying sine wave) function: |
|
231 |
accelerating from zero velocity. The peak amplitude |
|
232 |
can be set with the \e amplitude parameter, and the |
|
233 |
period of decay by the \e period parameter. |
|
234 |
\value OutElastic \inlineimage qeasingcurve-outelastic.png |
|
235 |
\br |
|
236 |
Easing curve for an elastic |
|
237 |
(exponentially decaying sine wave) function: |
|
238 |
decelerating from zero velocity. The peak amplitude |
|
239 |
can be set with the \e amplitude parameter, and the |
|
240 |
period of decay by the \e period parameter. |
|
241 |
\value InOutElastic \inlineimage qeasingcurve-inoutelastic.png |
|
242 |
\br |
|
243 |
Easing curve for an elastic |
|
244 |
(exponentially decaying sine wave) function: |
|
245 |
acceleration until halfway, then deceleration. |
|
246 |
\value OutInElastic \inlineimage qeasingcurve-outinelastic.png |
|
247 |
\br |
|
248 |
Easing curve for an elastic |
|
249 |
(exponentially decaying sine wave) function: |
|
250 |
deceleration until halfway, then acceleration. |
|
251 |
\value InBack \inlineimage qeasingcurve-inback.png |
|
252 |
\br |
|
253 |
Easing curve for a back (overshooting |
|
254 |
cubic function: (s+1)*t^3 - s*t^2) easing in: |
|
255 |
accelerating from zero velocity. |
|
256 |
\value OutBack \inlineimage qeasingcurve-outback.png |
|
257 |
\br |
|
258 |
Easing curve for a back (overshooting |
|
259 |
cubic function: (s+1)*t^3 - s*t^2) easing out: |
|
260 |
decelerating to zero velocity. |
|
261 |
\value InOutBack \inlineimage qeasingcurve-inoutback.png |
|
262 |
\br |
|
263 |
Easing curve for a back (overshooting |
|
264 |
cubic function: (s+1)*t^3 - s*t^2) easing in/out: |
|
265 |
acceleration until halfway, then deceleration. |
|
266 |
\value OutInBack \inlineimage qeasingcurve-outinback.png |
|
267 |
\br |
|
268 |
Easing curve for a back (overshooting |
|
269 |
cubic easing: (s+1)*t^3 - s*t^2) easing out/in: |
|
270 |
deceleration until halfway, then acceleration. |
|
271 |
\value InBounce \inlineimage qeasingcurve-inbounce.png |
|
272 |
\br |
|
273 |
Easing curve for a bounce (exponentially |
|
274 |
decaying parabolic bounce) function: accelerating |
|
275 |
from zero velocity. |
|
276 |
\value OutBounce \inlineimage qeasingcurve-outbounce.png |
|
277 |
\br |
|
278 |
Easing curve for a bounce (exponentially |
|
279 |
decaying parabolic bounce) function: decelerating |
|
280 |
from zero velocity. |
|
281 |
\value InOutBounce \inlineimage qeasingcurve-inoutbounce.png |
|
282 |
\br |
|
283 |
Easing curve for a bounce (exponentially |
|
284 |
decaying parabolic bounce) function easing in/out: |
|
285 |
acceleration until halfway, then deceleration. |
|
286 |
\value OutInBounce \inlineimage qeasingcurve-outinbounce.png |
|
287 |
\br |
|
288 |
Easing curve for a bounce (exponentially |
|
289 |
decaying parabolic bounce) function easing out/in: |
|
290 |
deceleration until halfway, then acceleration. |
|
291 |
\omitvalue InCurve |
|
292 |
\omitvalue OutCurve |
|
293 |
\omitvalue SineCurve |
|
294 |
\omitvalue CosineCurve |
|
295 |
\value Custom This is returned if the user specified a custom curve type with |
|
296 |
setCustomType(). Note that you cannot call setType() with this value, |
|
297 |
but type() can return it. |
|
298 |
\omitvalue NCurveTypes |
|
299 |
*/ |
|
300 |
||
301 |
/*! |
|
302 |
\typedef QEasingCurve::EasingFunction |
|
303 |
||
304 |
This is a typedef for a pointer to a function with the following |
|
305 |
signature: |
|
306 |
||
307 |
\snippet doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp 0 |
|
308 |
*/ |
|
309 |
||
310 |
#include "qeasingcurve.h" |
|
311 |
||
312 |
#ifndef QT_NO_DEBUG_STREAM |
|
313 |
#include <QtCore/qdebug.h> |
|
314 |
#include <QtCore/qstring.h> |
|
315 |
#endif |
|
316 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
317 |
#ifndef QT_NO_DATASTREAM |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
318 |
#include <QtCore/qdatastream.h> |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
319 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
320 |
|
0 | 321 |
QT_BEGIN_NAMESPACE |
322 |
||
323 |
static bool isConfigFunction(QEasingCurve::Type type) |
|
324 |
{ |
|
325 |
return type >= QEasingCurve::InElastic |
|
326 |
&& type <= QEasingCurve::OutInBounce; |
|
327 |
} |
|
328 |
||
329 |
class QEasingCurveFunction |
|
330 |
{ |
|
331 |
public: |
|
332 |
enum Type { In, Out, InOut, OutIn }; |
|
333 |
||
334 |
QEasingCurveFunction(QEasingCurveFunction::Type type = In, qreal period = 0.3, qreal amplitude = 1.0, |
|
335 |
qreal overshoot = 1.70158f) |
|
336 |
: _t(type), _p(period), _a(amplitude), _o(overshoot) |
|
337 |
{ } |
|
338 |
virtual ~QEasingCurveFunction() {} |
|
339 |
virtual qreal value(qreal t); |
|
340 |
virtual QEasingCurveFunction *copy() const; |
|
341 |
bool operator==(const QEasingCurveFunction& other); |
|
342 |
||
343 |
Type _t; |
|
344 |
qreal _p; |
|
345 |
qreal _a; |
|
346 |
qreal _o; |
|
347 |
}; |
|
348 |
||
349 |
qreal QEasingCurveFunction::value(qreal t) |
|
350 |
{ |
|
351 |
return t; |
|
352 |
} |
|
353 |
||
354 |
QEasingCurveFunction *QEasingCurveFunction::copy() const |
|
355 |
{ |
|
356 |
return new QEasingCurveFunction(_t, _p, _a, _o); |
|
357 |
} |
|
358 |
||
359 |
bool QEasingCurveFunction::operator==(const QEasingCurveFunction& other) |
|
360 |
{ |
|
361 |
return _t == other._t && |
|
362 |
_p == other._p && |
|
363 |
_a == other._a && |
|
364 |
_o == other._o; |
|
365 |
} |
|
366 |
||
367 |
QT_BEGIN_INCLUDE_NAMESPACE |
|
368 |
#include "../../3rdparty/easing/easing.cpp" |
|
369 |
QT_END_INCLUDE_NAMESPACE |
|
370 |
||
371 |
class QEasingCurvePrivate |
|
372 |
{ |
|
373 |
public: |
|
374 |
QEasingCurvePrivate() |
|
375 |
: type(QEasingCurve::Linear), |
|
376 |
config(0), |
|
377 |
func(&easeNone) |
|
378 |
{ } |
|
379 |
~QEasingCurvePrivate() { delete config; } |
|
380 |
void setType_helper(QEasingCurve::Type); |
|
381 |
||
382 |
QEasingCurve::Type type; |
|
383 |
QEasingCurveFunction *config; |
|
384 |
QEasingCurve::EasingFunction func; |
|
385 |
}; |
|
386 |
||
387 |
struct ElasticEase : public QEasingCurveFunction |
|
388 |
{ |
|
389 |
ElasticEase(Type type) |
|
390 |
: QEasingCurveFunction(type, qreal(0.3), qreal(1.0)) |
|
391 |
{ } |
|
392 |
||
393 |
QEasingCurveFunction *copy() const |
|
394 |
{ |
|
395 |
ElasticEase *rv = new ElasticEase(_t); |
|
396 |
rv->_p = _p; |
|
397 |
rv->_a = _a; |
|
398 |
return rv; |
|
399 |
} |
|
400 |
||
401 |
qreal value(qreal t) |
|
402 |
{ |
|
403 |
qreal p = (_p < 0) ? 0.3f : _p; |
|
404 |
qreal a = (_a < 0) ? 1.0f : _a; |
|
405 |
switch(_t) { |
|
406 |
case In: |
|
407 |
return easeInElastic(t, a, p); |
|
408 |
case Out: |
|
409 |
return easeOutElastic(t, a, p); |
|
410 |
case InOut: |
|
411 |
return easeInOutElastic(t, a, p); |
|
412 |
case OutIn: |
|
413 |
return easeOutInElastic(t, a, p); |
|
414 |
default: |
|
415 |
return t; |
|
416 |
} |
|
417 |
} |
|
418 |
}; |
|
419 |
||
420 |
struct BounceEase : public QEasingCurveFunction |
|
421 |
{ |
|
422 |
BounceEase(Type type) |
|
423 |
: QEasingCurveFunction(type, 0.3f, 1.0f) |
|
424 |
{ } |
|
425 |
||
426 |
QEasingCurveFunction *copy() const |
|
427 |
{ |
|
428 |
BounceEase *rv = new BounceEase(_t); |
|
429 |
rv->_a = _a; |
|
430 |
return rv; |
|
431 |
} |
|
432 |
||
433 |
qreal value(qreal t) |
|
434 |
{ |
|
435 |
qreal a = (_a < 0) ? 1.0f : _a; |
|
436 |
switch(_t) { |
|
437 |
case In: |
|
438 |
return easeInBounce(t, a); |
|
439 |
case Out: |
|
440 |
return easeOutBounce(t, a); |
|
441 |
case InOut: |
|
442 |
return easeInOutBounce(t, a); |
|
443 |
case OutIn: |
|
444 |
return easeOutInBounce(t, a); |
|
445 |
default: |
|
446 |
return t; |
|
447 |
} |
|
448 |
} |
|
449 |
}; |
|
450 |
||
451 |
struct BackEase : public QEasingCurveFunction |
|
452 |
{ |
|
453 |
BackEase(Type type) |
|
454 |
: QEasingCurveFunction(type, 0.3f, 1.0f, 1.70158f) |
|
455 |
{ } |
|
456 |
||
457 |
QEasingCurveFunction *copy() const |
|
458 |
{ |
|
459 |
BackEase *rv = new BackEase(_t); |
|
460 |
rv->_o = _o; |
|
461 |
return rv; |
|
462 |
} |
|
463 |
||
464 |
qreal value(qreal t) |
|
465 |
{ |
|
466 |
qreal o = (_o < 0) ? 1.70158f : _o; |
|
467 |
switch(_t) { |
|
468 |
case In: |
|
469 |
return easeInBack(t, o); |
|
470 |
case Out: |
|
471 |
return easeOutBack(t, o); |
|
472 |
case InOut: |
|
473 |
return easeInOutBack(t, o); |
|
474 |
case OutIn: |
|
475 |
return easeOutInBack(t, o); |
|
476 |
default: |
|
477 |
return t; |
|
478 |
} |
|
479 |
} |
|
480 |
}; |
|
481 |
||
482 |
static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve) |
|
483 |
{ |
|
484 |
switch(curve) { |
|
485 |
case QEasingCurve::Linear: |
|
486 |
return &easeNone; |
|
487 |
case QEasingCurve::InQuad: |
|
488 |
return &easeInQuad; |
|
489 |
case QEasingCurve::OutQuad: |
|
490 |
return &easeOutQuad; |
|
491 |
case QEasingCurve::InOutQuad: |
|
492 |
return &easeInOutQuad; |
|
493 |
case QEasingCurve::OutInQuad: |
|
494 |
return &easeOutInQuad; |
|
495 |
case QEasingCurve::InCubic: |
|
496 |
return &easeInCubic; |
|
497 |
case QEasingCurve::OutCubic: |
|
498 |
return &easeOutCubic; |
|
499 |
case QEasingCurve::InOutCubic: |
|
500 |
return &easeInOutCubic; |
|
501 |
case QEasingCurve::OutInCubic: |
|
502 |
return &easeOutInCubic; |
|
503 |
case QEasingCurve::InQuart: |
|
504 |
return &easeInQuart; |
|
505 |
case QEasingCurve::OutQuart: |
|
506 |
return &easeOutQuart; |
|
507 |
case QEasingCurve::InOutQuart: |
|
508 |
return &easeInOutQuart; |
|
509 |
case QEasingCurve::OutInQuart: |
|
510 |
return &easeOutInQuart; |
|
511 |
case QEasingCurve::InQuint: |
|
512 |
return &easeInQuint; |
|
513 |
case QEasingCurve::OutQuint: |
|
514 |
return &easeOutQuint; |
|
515 |
case QEasingCurve::InOutQuint: |
|
516 |
return &easeInOutQuint; |
|
517 |
case QEasingCurve::OutInQuint: |
|
518 |
return &easeOutInQuint; |
|
519 |
case QEasingCurve::InSine: |
|
520 |
return &easeInSine; |
|
521 |
case QEasingCurve::OutSine: |
|
522 |
return &easeOutSine; |
|
523 |
case QEasingCurve::InOutSine: |
|
524 |
return &easeInOutSine; |
|
525 |
case QEasingCurve::OutInSine: |
|
526 |
return &easeOutInSine; |
|
527 |
case QEasingCurve::InExpo: |
|
528 |
return &easeInExpo; |
|
529 |
case QEasingCurve::OutExpo: |
|
530 |
return &easeOutExpo; |
|
531 |
case QEasingCurve::InOutExpo: |
|
532 |
return &easeInOutExpo; |
|
533 |
case QEasingCurve::OutInExpo: |
|
534 |
return &easeOutInExpo; |
|
535 |
case QEasingCurve::InCirc: |
|
536 |
return &easeInCirc; |
|
537 |
case QEasingCurve::OutCirc: |
|
538 |
return &easeOutCirc; |
|
539 |
case QEasingCurve::InOutCirc: |
|
540 |
return &easeInOutCirc; |
|
541 |
case QEasingCurve::OutInCirc: |
|
542 |
return &easeOutInCirc; |
|
543 |
// Internal for, compatibility with QTimeLine only ?? |
|
544 |
case QEasingCurve::InCurve: |
|
545 |
return &easeInCurve; |
|
546 |
case QEasingCurve::OutCurve: |
|
547 |
return &easeOutCurve; |
|
548 |
case QEasingCurve::SineCurve: |
|
549 |
return &easeSineCurve; |
|
550 |
case QEasingCurve::CosineCurve: |
|
551 |
return &easeCosineCurve; |
|
552 |
default: |
|
553 |
return 0; |
|
554 |
}; |
|
555 |
} |
|
556 |
||
557 |
static QEasingCurveFunction *curveToFunctionObject(QEasingCurve::Type type) |
|
558 |
{ |
|
559 |
QEasingCurveFunction *curveFunc = 0; |
|
560 |
switch(type) { |
|
561 |
case QEasingCurve::InElastic: |
|
562 |
curveFunc = new ElasticEase(ElasticEase::In); |
|
563 |
break; |
|
564 |
case QEasingCurve::OutElastic: |
|
565 |
curveFunc = new ElasticEase(ElasticEase::Out); |
|
566 |
break; |
|
567 |
case QEasingCurve::InOutElastic: |
|
568 |
curveFunc = new ElasticEase(ElasticEase::InOut); |
|
569 |
break; |
|
570 |
case QEasingCurve::OutInElastic: |
|
571 |
curveFunc = new ElasticEase(ElasticEase::OutIn); |
|
572 |
break; |
|
573 |
case QEasingCurve::OutBounce: |
|
574 |
curveFunc = new BounceEase(BounceEase::Out); |
|
575 |
break; |
|
576 |
case QEasingCurve::InBounce: |
|
577 |
curveFunc = new BounceEase(BounceEase::In); |
|
578 |
break; |
|
579 |
case QEasingCurve::OutInBounce: |
|
580 |
curveFunc = new BounceEase(BounceEase::OutIn); |
|
581 |
break; |
|
582 |
case QEasingCurve::InOutBounce: |
|
583 |
curveFunc = new BounceEase(BounceEase::InOut); |
|
584 |
break; |
|
585 |
case QEasingCurve::InBack: |
|
586 |
curveFunc = new BackEase(BackEase::In); |
|
587 |
break; |
|
588 |
case QEasingCurve::OutBack: |
|
589 |
curveFunc = new BackEase(BackEase::Out); |
|
590 |
break; |
|
591 |
case QEasingCurve::InOutBack: |
|
592 |
curveFunc = new BackEase(BackEase::InOut); |
|
593 |
break; |
|
594 |
case QEasingCurve::OutInBack: |
|
595 |
curveFunc = new BackEase(BackEase::OutIn); |
|
596 |
break; |
|
597 |
default: |
|
598 |
curveFunc = new QEasingCurveFunction(QEasingCurveFunction::In, 0.3f, 1.0f, 1.70158f); // ### |
|
599 |
} |
|
600 |
||
601 |
return curveFunc; |
|
602 |
} |
|
603 |
||
604 |
/*! |
|
605 |
Constructs an easing curve of the given \a type. |
|
606 |
*/ |
|
607 |
QEasingCurve::QEasingCurve(Type type) |
|
608 |
: d_ptr(new QEasingCurvePrivate) |
|
609 |
{ |
|
610 |
setType(type); |
|
611 |
} |
|
612 |
||
613 |
/*! |
|
614 |
Construct a copy of \a other. |
|
615 |
*/ |
|
616 |
QEasingCurve::QEasingCurve(const QEasingCurve &other) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
617 |
: d_ptr(new QEasingCurvePrivate) |
0 | 618 |
{ |
619 |
// ### non-atomic, requires malloc on shallow copy |
|
620 |
*d_ptr = *other.d_ptr; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
621 |
if (other.d_ptr->config) |
0 | 622 |
d_ptr->config = other.d_ptr->config->copy(); |
623 |
} |
|
624 |
||
625 |
/*! |
|
626 |
Destructor. |
|
627 |
*/ |
|
628 |
||
629 |
QEasingCurve::~QEasingCurve() |
|
630 |
{ |
|
631 |
delete d_ptr; |
|
632 |
} |
|
633 |
||
634 |
/*! |
|
635 |
Copy \a other. |
|
636 |
*/ |
|
637 |
QEasingCurve &QEasingCurve::operator=(const QEasingCurve &other) |
|
638 |
{ |
|
639 |
// ### non-atomic, requires malloc on shallow copy |
|
640 |
if (d_ptr->config) { |
|
641 |
delete d_ptr->config; |
|
642 |
d_ptr->config = 0; |
|
643 |
} |
|
644 |
||
645 |
*d_ptr = *other.d_ptr; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
646 |
if (other.d_ptr->config) |
0 | 647 |
d_ptr->config = other.d_ptr->config->copy(); |
648 |
||
649 |
return *this; |
|
650 |
} |
|
651 |
||
652 |
/*! |
|
653 |
Compare this easing curve with \a other and returns true if they are |
|
654 |
equal. It will also compare the properties of a curve. |
|
655 |
*/ |
|
656 |
bool QEasingCurve::operator==(const QEasingCurve &other) const |
|
657 |
{ |
|
658 |
bool res = d_ptr->func == other.d_ptr->func |
|
659 |
&& d_ptr->type == other.d_ptr->type; |
|
660 |
if (res && d_ptr->config && other.d_ptr->config) { |
|
661 |
// catch the config content |
|
662 |
res = d_ptr->config->operator==(*(other.d_ptr->config)); |
|
663 |
} |
|
664 |
return res; |
|
665 |
} |
|
666 |
||
667 |
/*! |
|
668 |
\fn bool QEasingCurve::operator!=(const QEasingCurve &other) const |
|
669 |
Compare this easing curve with \a other and returns true if they are not equal. |
|
670 |
It will also compare the properties of a curve. |
|
671 |
||
672 |
\sa operator==() |
|
673 |
*/ |
|
674 |
||
675 |
/*! |
|
676 |
Returns the amplitude. This is not applicable for all curve types. |
|
677 |
It is only applicable for bounce and elastic curves (curves of type() |
|
678 |
QEasingCurve::InBounce, QEasingCurve::OutBounce, QEasingCurve::InOutBounce, |
|
679 |
QEasingCurve::OutInBounce, QEasingCurve::InElastic, QEasingCurve::OutElastic, |
|
680 |
QEasingCurve::InOutElastic or QEasingCurve::OutInElastic). |
|
681 |
*/ |
|
682 |
qreal QEasingCurve::amplitude() const |
|
683 |
{ |
|
684 |
return d_ptr->config ? d_ptr->config->_a : 1.0; |
|
685 |
} |
|
686 |
||
687 |
/*! |
|
688 |
Sets the amplitude to \a amplitude. |
|
689 |
||
690 |
This will set the amplitude of the bounce or the amplitude of the |
|
691 |
elastic "spring" effect. The higher the number, the higher the amplitude. |
|
692 |
\sa amplitude() |
|
693 |
*/ |
|
694 |
void QEasingCurve::setAmplitude(qreal amplitude) |
|
695 |
{ |
|
696 |
if (!d_ptr->config) |
|
697 |
d_ptr->config = curveToFunctionObject(d_ptr->type); |
|
698 |
d_ptr->config->_a = amplitude; |
|
699 |
} |
|
700 |
||
701 |
/*! |
|
702 |
Returns the period. This is not applicable for all curve types. |
|
703 |
It is only applicable if type() is QEasingCurve::InElastic, QEasingCurve::OutElastic, |
|
704 |
QEasingCurve::InOutElastic or QEasingCurve::OutInElastic. |
|
705 |
*/ |
|
706 |
qreal QEasingCurve::period() const |
|
707 |
{ |
|
708 |
return d_ptr->config ? d_ptr->config->_p : 0.3; |
|
709 |
} |
|
710 |
||
711 |
/*! |
|
712 |
Sets the period to \a period. |
|
713 |
Setting a small period value will give a high frequency of the curve. A |
|
714 |
large period will give it a small frequency. |
|
715 |
||
716 |
\sa period() |
|
717 |
*/ |
|
718 |
void QEasingCurve::setPeriod(qreal period) |
|
719 |
{ |
|
720 |
if (!d_ptr->config) |
|
721 |
d_ptr->config = curveToFunctionObject(d_ptr->type); |
|
722 |
d_ptr->config->_p = period; |
|
723 |
} |
|
724 |
||
725 |
/*! |
|
726 |
Returns the overshoot. This is not applicable for all curve types. |
|
727 |
It is only applicable if type() is QEasingCurve::InBack, QEasingCurve::OutBack, |
|
728 |
QEasingCurve::InOutBack or QEasingCurve::OutInBack. |
|
729 |
*/ |
|
730 |
qreal QEasingCurve::overshoot() const |
|
731 |
{ |
|
732 |
return d_ptr->config ? d_ptr->config->_o : 1.70158f; |
|
733 |
} |
|
734 |
||
735 |
/*! |
|
736 |
Sets the overshoot to \a overshoot. |
|
737 |
||
738 |
0 produces no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent. |
|
739 |
||
740 |
\sa overshoot() |
|
741 |
*/ |
|
742 |
void QEasingCurve::setOvershoot(qreal overshoot) |
|
743 |
{ |
|
744 |
if (!d_ptr->config) |
|
745 |
d_ptr->config = curveToFunctionObject(d_ptr->type); |
|
746 |
d_ptr->config->_o = overshoot; |
|
747 |
} |
|
748 |
||
749 |
/*! |
|
750 |
Returns the type of the easing curve. |
|
751 |
*/ |
|
752 |
QEasingCurve::Type QEasingCurve::type() const |
|
753 |
{ |
|
754 |
return d_ptr->type; |
|
755 |
} |
|
756 |
||
757 |
void QEasingCurvePrivate::setType_helper(QEasingCurve::Type newType) |
|
758 |
{ |
|
759 |
qreal amp = -1.0; |
|
760 |
qreal period = -1.0; |
|
761 |
qreal overshoot = -1.0; |
|
762 |
||
763 |
if (config) { |
|
764 |
amp = config->_a; |
|
765 |
period = config->_p; |
|
766 |
overshoot = config->_o; |
|
767 |
delete config; |
|
768 |
config = 0; |
|
769 |
} |
|
770 |
||
771 |
if (isConfigFunction(newType) || (amp != -1.0) || (period != -1.0) || (overshoot != -1.0)) { |
|
772 |
config = curveToFunctionObject(newType); |
|
773 |
if (amp != -1.0) |
|
774 |
config->_a = amp; |
|
775 |
if (period != -1.0) |
|
776 |
config->_p = period; |
|
777 |
if (overshoot != -1.0) |
|
778 |
config->_o = overshoot; |
|
779 |
func = 0; |
|
780 |
} else if (newType != QEasingCurve::Custom) { |
|
781 |
func = curveToFunc(newType); |
|
782 |
} |
|
783 |
Q_ASSERT((func == 0) == (config != 0)); |
|
784 |
type = newType; |
|
785 |
} |
|
786 |
||
787 |
/*! |
|
788 |
Sets the type of the easing curve to \a type. |
|
789 |
*/ |
|
790 |
void QEasingCurve::setType(Type type) |
|
791 |
{ |
|
792 |
if (d_ptr->type == type) |
|
793 |
return; |
|
794 |
if (type < Linear || type >= NCurveTypes - 1) { |
|
795 |
qWarning("QEasingCurve: Invalid curve type %d", type); |
|
796 |
return; |
|
797 |
} |
|
798 |
||
799 |
d_ptr->setType_helper(type); |
|
800 |
} |
|
801 |
||
802 |
/*! |
|
803 |
Sets a custom easing curve that is defined by the user in the function \a func. |
|
804 |
The signature of the function is qreal myEasingFunction(qreal progress), |
|
805 |
where \e progress and the return value is considered to be normalized between 0 and 1. |
|
806 |
(In some cases the return value can be outside that range) |
|
807 |
After calling this function type() will return QEasingCurve::Custom. |
|
808 |
\a func cannot be zero. |
|
809 |
||
810 |
\sa customType() |
|
811 |
\sa valueForProgress() |
|
812 |
*/ |
|
813 |
void QEasingCurve::setCustomType(EasingFunction func) |
|
814 |
{ |
|
815 |
if (!func) { |
|
816 |
qWarning("Function pointer must not be null"); |
|
817 |
return; |
|
818 |
} |
|
819 |
d_ptr->func = func; |
|
820 |
d_ptr->setType_helper(Custom); |
|
821 |
} |
|
822 |
||
823 |
/*! |
|
824 |
Returns the function pointer to the custom easing curve. |
|
825 |
If type() does not return QEasingCurve::Custom, this function |
|
826 |
will return 0. |
|
827 |
*/ |
|
828 |
QEasingCurve::EasingFunction QEasingCurve::customType() const |
|
829 |
{ |
|
830 |
return d_ptr->type == Custom ? d_ptr->func : 0; |
|
831 |
} |
|
832 |
||
833 |
/*! |
|
834 |
Return the effective progress for the easing curve at \a progress. |
|
835 |
While \a progress must be between 0 and 1, the returned effective progress |
|
836 |
can be outside those bounds. For instance, QEasingCurve::InBack will |
|
837 |
return negative values in the beginning of the function. |
|
838 |
*/ |
|
839 |
qreal QEasingCurve::valueForProgress(qreal progress) const |
|
840 |
{ |
|
841 |
progress = qBound<qreal>(0, progress, 1); |
|
842 |
if (d_ptr->func) |
|
843 |
return d_ptr->func(progress); |
|
844 |
else if (d_ptr->config) |
|
845 |
return d_ptr->config->value(progress); |
|
846 |
else |
|
847 |
return progress; |
|
848 |
} |
|
849 |
||
850 |
#ifndef QT_NO_DEBUG_STREAM |
|
851 |
QDebug operator<<(QDebug debug, const QEasingCurve &item) |
|
852 |
{ |
|
853 |
debug << "type:" << item.d_ptr->type |
|
854 |
<< "func:" << item.d_ptr->func; |
|
855 |
if (item.d_ptr->config) { |
|
856 |
debug << QString::fromAscii("period:%1").arg(item.d_ptr->config->_p, 0, 'f', 20) |
|
857 |
<< QString::fromAscii("amp:%1").arg(item.d_ptr->config->_a, 0, 'f', 20) |
|
858 |
<< QString::fromAscii("overshoot:%1").arg(item.d_ptr->config->_o, 0, 'f', 20); |
|
859 |
} |
|
860 |
return debug; |
|
861 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
862 |
#endif // QT_NO_DEBUG_STREAM |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
863 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
864 |
#ifndef QT_NO_DATASTREAM |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
865 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
866 |
\fn QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
867 |
\relates QEasingCurve |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
868 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
869 |
Writes the given \a easing curve to the given \a stream and returns a |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
870 |
reference to the stream. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
871 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
872 |
\sa {Serializing Qt Data Types} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
873 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
874 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
875 |
QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
876 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
877 |
stream << quint8(easing.d_ptr->type); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
878 |
stream << quint64(quintptr(easing.d_ptr->func)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
879 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
880 |
bool hasConfig = easing.d_ptr->config; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
881 |
stream << hasConfig; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
882 |
if (hasConfig) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
883 |
stream << easing.d_ptr->config->_p; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
884 |
stream << easing.d_ptr->config->_a; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
885 |
stream << easing.d_ptr->config->_o; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
886 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
887 |
return stream; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
888 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
889 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
890 |
/*! |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
891 |
\fn QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
892 |
\relates QQuaternion |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
893 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
894 |
Reads an easing curve from the given \a stream into the given \a |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
895 |
easing curve and returns a reference to the stream. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
896 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
897 |
\sa {Serializing Qt Data Types} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
898 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
899 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
900 |
QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
901 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
902 |
QEasingCurve::Type type; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
903 |
quint8 int_type; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
904 |
stream >> int_type; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
905 |
type = static_cast<QEasingCurve::Type>(int_type); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
906 |
easing.setType(type); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
907 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
908 |
quint64 ptr_func; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
909 |
stream >> ptr_func; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
910 |
easing.d_ptr->func = QEasingCurve::EasingFunction(quintptr(ptr_func)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
911 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
912 |
bool hasConfig; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
913 |
stream >> hasConfig; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
914 |
if (hasConfig) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
915 |
QEasingCurveFunction *config = curveToFunctionObject(type); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
916 |
stream >> config->_p; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
917 |
stream >> config->_a; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
918 |
stream >> config->_o; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
919 |
easing.d_ptr->config = config; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
920 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
921 |
return stream; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
922 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
923 |
#endif // QT_NO_DATASTREAM |
0 | 924 |
|
925 |
QT_END_NAMESPACE |