aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util/qquickanimation.cpp
blob: 4cf019c7f04553141d2be2ea27c63ec31bd45759 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qquickanimation_p.h"
#include "qquickanimation_p_p.h"

#include "qquickanimatorjob_p.h"

#include <private/qquickstatechangescript_p.h>
#include <private/qqmlcontext_p.h>

#include <qqmlpropertyvaluesource.h>
#include <qqml.h>
#include <qqmlinfo.h>
#include <qqmlexpression.h>
#include <private/qqmlstringconverters_p.h>
#include <private/qqmlglobal_p.h>
#include <private/qqmlmetatype_p.h>
#include <private/qqmlvaluetype_p.h>
#include <private/qqmlproperty_p.h>
#include <private/qqmlengine_p.h>

#include <qvariant.h>
#include <qcolor.h>
#include <qfile.h>
#include "private/qparallelanimationgroupjob_p.h"
#include "private/qsequentialanimationgroupjob_p.h"
#include <QtCore/qset.h>
#include <QtCore/qrect.h>
#include <QtCore/qpoint.h>
#include <QtCore/qsize.h>
#include <QtCore/qmath.h>

QT_BEGIN_NAMESPACE

/*!
    \qmltype Animation
    \instantiates QQuickAbstractAnimation
    \inqmlmodule QtQuick
    \ingroup qtquick-transitions-animations
    \brief Is the base of all QML animations.

    The Animation type cannot be used directly in a QML file.  It exists
    to provide a set of common properties and methods, available across all the
    other animation types that inherit from it.  Attempting to use the Animation
    type directly will result in an error.
*/

QQuickAbstractAnimation::QQuickAbstractAnimation(QObject *parent)
: QObject(*(new QQuickAbstractAnimationPrivate), parent)
{
}

QQuickAbstractAnimation::~QQuickAbstractAnimation()
{
    Q_D(QQuickAbstractAnimation);
    if (d->group)
        setGroup(nullptr);    //remove from group
    delete d->animationInstance;
}

QQuickAbstractAnimation::QQuickAbstractAnimation(QQuickAbstractAnimationPrivate &dd, QObject *parent)
: QObject(dd, parent)
{
}

QAbstractAnimationJob* QQuickAbstractAnimation::qtAnimation()
{
    Q_D(QQuickAbstractAnimation);
    return d->animationInstance;
}

/*!
    \qmlproperty bool QtQuick::Animation::running
    This property holds whether the animation is currently running.

    The \c running property can be set to declaratively control whether or not
    an animation is running.  The following example will animate a rectangle
    whenever the \l MouseArea is pressed.

    \code
    Rectangle {
        width: 100; height: 100
        NumberAnimation on x {
            running: myMouse.pressed
            from: 0; to: 100
        }
        MouseArea { id: myMouse }
    }
    \endcode

    Likewise, the \c running property can be read to determine if the animation
    is running.  In the following example the Text item will indicate whether
    or not the animation is running.

    \code
    NumberAnimation { id: myAnimation }
    Text { text: myAnimation.running ? "Animation is running" : "Animation is not running" }
    \endcode

    Animations can also be started and stopped imperatively from JavaScript
    using the \c start() and \c stop() methods.

    By default, animations are not running. Though, when the animations are assigned to properties,
    as property value sources using the \e on syntax, they are set to running by default.
*/
bool QQuickAbstractAnimation::isRunning() const
{
    Q_D(const QQuickAbstractAnimation);
    return d->running;
}

// the behavior calls this function
void QQuickAbstractAnimation::notifyRunningChanged(bool running)
{
    Q_D(QQuickAbstractAnimation);
    if (d->disableUserControl && d->running != running) {
        d->running = running;
        emit runningChanged(running);
    }
}

//commence is called to start an animation when it is used as a
//simple animation, and not as part of a transition
void QQuickAbstractAnimationPrivate::commence()
{
    Q_Q(QQuickAbstractAnimation);

    QQuickStateActions actions;
    QQmlProperties properties;

    QAbstractAnimationJob *oldInstance = animationInstance;
    animationInstance = q->transition(actions, properties, QQuickAbstractAnimation::Forward);
    if (oldInstance && oldInstance != animationInstance)
        delete oldInstance;

    if (animationInstance) {
        if (oldInstance != animationInstance) {
            if (q->threadingModel() == QQuickAbstractAnimation::RenderThread)
                animationInstance = new QQuickAnimatorProxyJob(animationInstance, q);
            animationInstance->addAnimationChangeListener(this, QAbstractAnimationJob::Completion);
        }
        emit q->started();
        animationInstance->start();
    }
}

QQmlProperty QQuickAbstractAnimationPrivate::createProperty(QObject *obj, const QString &str, QObject *infoObj, QString *errorMessage)
{
    QQmlProperty prop(obj, str, qmlContext(infoObj));
    if (!prop.isValid()) {
        const QString message = QQuickAbstractAnimation::tr("Cannot animate non-existent property \"%1\"").arg(str);
        if (errorMessage)
            *errorMessage = message;
        else
            qmlWarning(infoObj) << message;
        return QQmlProperty();
    } else if (!prop.isWritable()) {
        const QString message = QQuickAbstractAnimation::tr("Cannot animate read-only property \"%1\"").arg(str);
        if (errorMessage)
            *errorMessage = message;
        else
            qmlWarning(infoObj) << message;
        return QQmlProperty();
    }
    return prop;
}

/*!
    \qmlsignal QtQuick::Animation::started()

    This signal is emitted when the animation begins.

    It is only triggered for top-level, standalone animations. It will not be
    triggered for animations in a Behavior or Transition, or animations
    that are part of an animation group.
*/

/*!
    \qmlsignal QtQuick::Animation::stopped()

    This signal is emitted when the animation ends.

    The animation may have been stopped manually, or may have run to completion.

    It is only triggered for top-level, standalone animations. It will not be
    triggered for animations in a Behavior or Transition, or animations
    that are part of an animation group.

    If \l alwaysRunToEnd is true, this signal will not be emitted until the animation
    has completed its current iteration.
*/

/*!
    \qmlsignal QtQuick::Animation::finished()
    \since 5.12

    This signal is emitted when the animation has finished naturally.

    It is not emitted when \l running is set to \c false, nor for animations whose
    \l loops property is set to \c Animation.Infinite.

    In addition, it is only emitted for top-level, standalone animations. It
    will not be emitted for animations in a Behavior or Transition, or
    animations that are part of an animation group.

    If \l alwaysRunToEnd is true, this signal will not be emitted until the
    animation has completed its current iteration.

    \sa stopped(), started(), running
*/

void QQuickAbstractAnimation::setRunning(bool r)
{
    Q_D(QQuickAbstractAnimation);
    if (!d->componentComplete) {
        d->running = r;
        if (r == false)
            d->avoidPropertyValueSourceStart = true;
        else if (!d->registered) {
            d->registered = true;
            QQmlEnginePrivate *engPriv = QQmlEnginePrivate::get(qmlEngine(this));
            static int finalizedIdx = -1;
            if (finalizedIdx < 0)
                finalizedIdx = metaObject()->indexOfSlot("componentFinalized()");
            engPriv->registerFinalizeCallback(this, finalizedIdx);
        }
        return;
    }

    if (d->running == r)
        return;

    if (d->group || d->disableUserControl) {
        qmlWarning(this) << "setRunning() cannot be used on non-root animation nodes.";
        return;
    }

    d->running = r;
    if (d->running) {
        bool supressStart = false;
        if (d->alwaysRunToEnd && d->loopCount != 1
            && d->animationInstance && d->animationInstance->isRunning()) {
            //we've restarted before the final loop finished; restore proper loop count
            if (d->loopCount == -1)
                d->animationInstance->setLoopCount(d->loopCount);
            else
                d->animationInstance->setLoopCount(d->animationInstance->currentLoop() + d->loopCount);
            supressStart = true;    //we want the animation to continue, rather than restart
        }
        if (!supressStart)
            d->commence();
    } else {
        if (d->paused) {
            d->paused = false; //reset paused state to false when stopped
            emit pausedChanged(d->paused);
        }

        if (d->animationInstance) {
            if (d->alwaysRunToEnd) {
                if (d->loopCount != 1)
                    d->animationInstance->setLoopCount(d->animationInstance->currentLoop()+1);    //finish the current loop
            } else {
                d->animationInstance->stop();
                emit stopped();
            }
        }
    }


    if (r == d->running) {
        // This might happen if we start an animation with 0 duration: This will result in that
        // commence() will emit started(), and then when it starts it will call setCurrentTime(0),
        // (which is both start and end time of the animation), so it will also end up calling
        // setRunning(false) (recursively) and stop the animation.
        // Therefore, the state of d->running will in that case be different than r if we are back in
        // the root stack frame of the recursive calls to setRunning()
        emit runningChanged(d->running);
    }
}

/*!
    \qmlproperty bool QtQuick::Animation::paused
    This property holds whether the animation is currently paused.

    The \c paused property can be set to declaratively control whether or not
    an animation is paused.

    Animations can also be paused and resumed imperatively from JavaScript
    using the \c pause() and \c resume() methods.

    By default, animations are not paused.
*/
bool QQuickAbstractAnimation::isPaused() const
{
    Q_D(const QQuickAbstractAnimation);
    Q_ASSERT((d->paused && d->running) || !d->paused);
    return d->paused;
}

void QQuickAbstractAnimation::setPaused(bool p)
{
    Q_D(QQuickAbstractAnimation);
    if (d->paused == p)
        return;

    if (!d->running) {
        qmlWarning(this) << "setPaused() cannot be used when animation isn't running.";
        return;
    }

    if (d->group || d->disableUserControl) {
        qmlWarning(this) << "setPaused() cannot be used on non-root animation nodes.";
        return;
    }

    d->paused = p;

    if (!d->componentComplete || !d->animationInstance)
        return;

    if (d->paused)
        d->animationInstance->pause();
    else
        d->animationInstance->resume();

    emit pausedChanged(d->paused);
}

void QQuickAbstractAnimation::classBegin()
{
    Q_D(QQuickAbstractAnimation);
    d->componentComplete = false;
}

void QQuickAbstractAnimation::componentComplete()
{
    Q_D(QQuickAbstractAnimation);
    d->componentComplete = true;
}

void QQuickAbstractAnimation::componentFinalized()
{
    Q_D(QQuickAbstractAnimation);
    if (d->running) {
        d->running = false;
        setRunning(true);
    }
    if (d->paused) {
        d->paused = false;
        setPaused(true);
    }
}

/*!
    \qmlproperty bool QtQuick::Animation::alwaysRunToEnd
    This property holds whether the animation should run to completion when it is stopped.

    If this true the animation will complete its current iteration when it
    is stopped - either by setting the \c running property to false, or by
    calling the \c stop() method.  The \c complete() method is not effected
    by this value.

    This behavior is most useful when the \c loops property is set, as the
    animation will finish playing normally but not restart.

    By default, the alwaysRunToEnd property is not set.

    \note alwaysRunToEnd has no effect on animations in a Transition.
*/
bool QQuickAbstractAnimation::alwaysRunToEnd() const
{
    Q_D(const QQuickAbstractAnimation);
    return d->alwaysRunToEnd;
}

void QQuickAbstractAnimation::setAlwaysRunToEnd(bool f)
{
    Q_D(QQuickAbstractAnimation);
    if (d->alwaysRunToEnd == f)
        return;

    d->alwaysRunToEnd = f;
    emit alwaysRunToEndChanged(f);
}

/*!
    \qmlproperty int QtQuick::Animation::loops
    This property holds the number of times the animation should play.

    By default, \c loops is 1: the animation will play through once and then stop.

    If set to Animation.Infinite, the animation will continuously repeat until it is explicitly
    stopped - either by setting the \c running property to false, or by calling
    the \c stop() method.

    In the following example, the rectangle will spin indefinitely.

    \code
    Rectangle {
        width: 100; height: 100; color: "green"
        RotationAnimation on rotation {
            loops: Animation.Infinite
            from: 0
            to: 360
        }
    }
    \endcode
*/
int QQuickAbstractAnimation::loops() const
{
    Q_D(const QQuickAbstractAnimation);
    return d->loopCount;
}

void QQuickAbstractAnimation::setLoops(int loops)
{
    Q_D(QQuickAbstractAnimation);
    if (loops < 0)
        loops = -1;

    if (loops == d->loopCount)
        return;

    d->loopCount = loops;
    emit loopCountChanged(loops);
}

int QQuickAbstractAnimation::duration() const
{
    Q_D(const QQuickAbstractAnimation);
    return d->animationInstance ? d->animationInstance->duration() : 0;
}

int QQuickAbstractAnimation::currentTime()
{
    Q_D(QQuickAbstractAnimation);
    return d->animationInstance ? d->animationInstance->currentLoopTime() : 0;
}

void QQuickAbstractAnimation::setCurrentTime(int time)
{
    Q_D(QQuickAbstractAnimation);
    if (d->animationInstance)
        d->animationInstance->setCurrentTime(time);
    //TODO save value for start?
}

QQuickAnimationGroup *QQuickAbstractAnimation::group() const
{
    Q_D(const QQuickAbstractAnimation);
    return d->group;
}

void QQuickAbstractAnimation::setGroup(QQuickAnimationGroup *g, int index)
{
    Q_D(QQuickAbstractAnimation);
    if (d->group == g)
        return;
    if (d->group)
        d->group->d_func()->animations.removeAll(this);

    d->group = g;

    if (d->group && !d->group->d_func()->animations.contains(this)) {
        if (index >= 0)
            d->group->d_func()->animations.insert(index, this);
        else
            d->group->d_func()->animations.append(this);
    }
}

/*!
    \qmlmethod QtQuick::Animation::start()
    \brief Starts the animation

    If the animation is already running, calling this method has no effect.  The
    \c running property will be true following a call to \c start().
*/
void QQuickAbstractAnimation::start()
{
    setRunning(true);
}

/*!
    \qmlmethod QtQuick::Animation::pause()
    \brief Pauses the animation

    If the animation is already paused or not \c running, calling this method has no effect.
    The \c paused property will be true following a call to \c pause().
*/
void QQuickAbstractAnimation::pause()
{
    setPaused(true);
}

/*!
    \qmlmethod QtQuick::Animation::resume()
    \brief Resumes a paused animation

    If the animation is not paused or not \c running, calling this method has no effect.
    The \c paused property will be false following a call to \c resume().
*/
void QQuickAbstractAnimation::resume()
{
    setPaused(false);
}

/*!
    \qmlmethod QtQuick::Animation::stop()
    \brief Stops the animation

    If the animation is not running, calling this method has no effect.  Both the
    \c running and \c paused properties will be false following a call to \c stop().

    Normally \c stop() stops the animation immediately, and the animation has
    no further influence on property values.  In this example animation
    \code
    Rectangle {
        NumberAnimation on x { from: 0; to: 100; duration: 500 }
    }
    \endcode
    was stopped at time 250ms, the \c x property will have a value of 50.

    However, if the \c alwaysRunToEnd property is set, the animation will
    continue running until it completes and then stop.  The \c running property
    will still become false immediately.
*/
void QQuickAbstractAnimation::stop()
{
    setRunning(false);
}

/*!
    \qmlmethod QtQuick::Animation::restart()
    \brief Restarts the animation

    This is a convenience method, and is equivalent to calling \c stop() and
    then \c start().
*/
void QQuickAbstractAnimation::restart()
{
    stop();
    start();
}

/*!
    \qmlmethod QtQuick::Animation::complete()
    \brief Stops the animation, jumping to the final property values

    If the animation is not running, calling this method has no effect.  The
    \c running property will be false following a call to \c complete().

    Unlike \c stop(), \c complete() immediately fast-forwards the animation to
    its end.  In the following example,
    \code
    Rectangle {
        NumberAnimation on x { from: 0; to: 100; duration: 500 }
    }
    \endcode
    calling \c stop() at time 250ms will result in the \c x property having
    a value of 50, while calling \c complete() will set the \c x property to
    100, exactly as though the animation had played the whole way through.
*/
void QQuickAbstractAnimation::complete()
{
    Q_D(QQuickAbstractAnimation);
    if (isRunning() && d->animationInstance) {
         d->animationInstance->setCurrentTime(d->animationInstance->duration());
    }
}

void QQuickAbstractAnimation::setTarget(const QQmlProperty &p)
{
    Q_D(QQuickAbstractAnimation);
    d->defaultProperty = p;

    if (!d->avoidPropertyValueSourceStart)
        setRunning(true);
}

/*
    we rely on setTarget only being called when used as a value source
    so this function allows us to do the same thing as setTarget without
    that assumption
*/
void QQuickAbstractAnimation::setDefaultTarget(const QQmlProperty &p)
{
    Q_D(QQuickAbstractAnimation);
    d->defaultProperty = p;
}

/*
    don't allow start/stop/pause/resume to be manually invoked,
    because something else (like a Behavior) already has control
    over the animation.
*/
void QQuickAbstractAnimation::setDisableUserControl()
{
    Q_D(QQuickAbstractAnimation);
    d->disableUserControl = true;
}

void QQuickAbstractAnimation::setEnableUserControl()
{
    Q_D(QQuickAbstractAnimation);
    d->disableUserControl = false;

}

bool QQuickAbstractAnimation::userControlDisabled() const
{
    Q_D(const QQuickAbstractAnimation);
    return d->disableUserControl;
}

QAbstractAnimationJob* QQuickAbstractAnimation::initInstance(QAbstractAnimationJob *animation)
{
    Q_D(QQuickAbstractAnimation);
    animation->setLoopCount(d->loopCount);
    return animation;
}

QAbstractAnimationJob* QQuickAbstractAnimation::transition(QQuickStateActions &actions,
                                      QQmlProperties &modified,
                                      TransitionDirection direction,
                                      QObject *defaultTarget)
{
    Q_UNUSED(actions);
    Q_UNUSED(modified);
    Q_UNUSED(direction);
    Q_UNUSED(defaultTarget);
    return nullptr;
}

void QQuickAbstractAnimationPrivate::animationFinished(QAbstractAnimationJob*)
{
    Q_Q(QQuickAbstractAnimation);
    q->setRunning(false);
    if (alwaysRunToEnd) {
        emit q->stopped();
        //restore the proper loopCount for the next run
        if (loopCount != 1)
            animationInstance->setLoopCount(loopCount);
    }
    emit q->finished();
}

QQuickAbstractAnimation::ThreadingModel QQuickAbstractAnimation::threadingModel() const
{
    return GuiThread;
}

/*!
    \qmltype PauseAnimation
    \instantiates QQuickPauseAnimation
    \inqmlmodule QtQuick
    \ingroup qtquick-transitions-animations
    \inherits Animation
    \brief Provides a pause for an animation.

    When used in a SequentialAnimation, PauseAnimation is a step when
    nothing happens, for a specified duration.

    A 500ms animation sequence, with a 100ms pause between two animations:
    \code
    SequentialAnimation {
        NumberAnimation { ... duration: 200 }
        PauseAnimation { duration: 100 }
        NumberAnimation { ... duration: 200 }
    }
    \endcode

    \sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
*/
QQuickPauseAnimation::QQuickPauseAnimation(QObject *parent)
: QQuickAbstractAnimation(*(new QQuickPauseAnimationPrivate), parent)
{
}

QQuickPauseAnimation::~QQuickPauseAnimation()
{
}

/*!
    \qmlproperty int QtQuick::PauseAnimation::duration
    This property holds the duration of the pause in milliseconds

    The default value is 250.
*/
int QQuickPauseAnimation::duration() const
{
    Q_D(const QQuickPauseAnimation);
    return d->duration;
}

void QQuickPauseAnimation::setDuration(int duration)
{
    if (duration < 0) {
        qmlWarning(this) << tr("Cannot set a duration of < 0");
        return;
    }

    Q_D(QQuickPauseAnimation);
    if (d->duration == duration)
        return;
    d->duration = duration;
    emit durationChanged(duration);
}

QAbstractAnimationJob* QQuickPauseAnimation::transition(QQuickStateActions &actions,
                                    QQmlProperties &modified,
                                    TransitionDirection direction,
                                    QObject *defaultTarget)
{
    Q_D(QQuickPauseAnimation);
    Q_UNUSED(actions);
    Q_UNUSED(modified);
    Q_UNUSED(direction);
    Q_UNUSED(defaultTarget);

    return initInstance(new QPauseAnimationJob(d->duration));
}

/*!
    \qmltype ColorAnimation
    \instantiates QQuickColorAnimation
    \inqmlmodule QtQuick
    \ingroup qtquick-animation-properties
    \inherits PropertyAnimation
    \brief Animates changes in color values.

    ColorAnimation is a specialized PropertyAnimation that defines an
    animation to be applied when a color value changes.

    Here is a ColorAnimation applied to the \c color property of a \l Rectangle
    as a property value source. It animates the \c color property's value from
    its current value to a value of "red", over 1000 milliseconds:

    \snippet qml/coloranimation.qml 0

    Like any other animation type, a ColorAnimation can be applied in a
    number of ways, including transitions, behaviors and property value
    sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
    variety of methods for creating animations.

    For convenience, when a ColorAnimation is used in a \l Transition, it will
    animate any \c color properties that have been modified during the state
    change. If a \l{PropertyAnimation::}{property} or
    \l{PropertyAnimation::}{properties} are explicitly set for the animation,
    then those are used instead.

    \sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
*/
QQuickColorAnimation::QQuickColorAnimation(QObject *parent)
: QQuickPropertyAnimation(parent)
{
    Q_D(QQuickPropertyAnimation);
    d->interpolatorType = QMetaType::QColor;
    d->defaultToInterpolatorType = true;
    d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
}

QQuickColorAnimation::~QQuickColorAnimation()
{
}

/*!
    \qmlproperty color QtQuick::ColorAnimation::from
    This property holds the color value at which the animation should begin.

    For example, the following animation is not applied until a color value
    has reached "#c0c0c0":

    \qml
    Item {
        states: [
            // States are defined here...
        ]

        transitions: Transition {
            ColorAnimation { from: "#c0c0c0"; duration: 2000 }
        }
    }
    \endqml

    If the ColorAnimation is defined within a \l Transition or \l Behavior,
    this value defaults to the value defined in the starting state of the
    \l Transition, or the current value of the property at the moment the
    \l Behavior is triggered.

    \sa {Animation and Transitions in Qt Quick}
*/
QColor QQuickColorAnimation::from() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->from.value<QColor>();
}

void QQuickColorAnimation::setFrom(const QColor &f)
{
    QQuickPropertyAnimation::setFrom(f);
}

/*!
    \qmlproperty color QtQuick::ColorAnimation::to

    This property holds the color value at which the animation should end.

    If the ColorAnimation is defined within a \l Transition or \l Behavior,
    this value defaults to the value defined in the end state of the
    \l Transition, or the value of the property change that triggered the
    \l Behavior.

    \sa {Animation and Transitions in Qt Quick}
*/
QColor QQuickColorAnimation::to() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->to.value<QColor>();
}

void QQuickColorAnimation::setTo(const QColor &t)
{
    QQuickPropertyAnimation::setTo(t);
}

QActionAnimation::QActionAnimation()
    : QAbstractAnimationJob(), animAction(nullptr)
{
}

QActionAnimation::QActionAnimation(QAbstractAnimationAction *action)
    : QAbstractAnimationJob(), animAction(action)
{
}

QActionAnimation::~QActionAnimation()
{
    delete animAction;
}

int QActionAnimation::duration() const
{
    return 0;
}

void QActionAnimation::setAnimAction(QAbstractAnimationAction *action)
{
    if (isRunning())
        stop();
    animAction = action;
}

void QActionAnimation::updateCurrentTime(int)
{
}

void QActionAnimation::updateState(State newState, State oldState)
{
    Q_UNUSED(oldState);

    if (newState == Running) {
        if (animAction) {
            animAction->doAction();
        }
    }
}

void QActionAnimation::debugAnimation(QDebug d) const
{
    d << "ActionAnimation(" << Qt::hex << (const void *) this << Qt::dec << ")";

    if (animAction) {
        int indentLevel = 1;
        const QAbstractAnimationJob *job = this;
        while ((job = job->group()))
            ++indentLevel;
        animAction->debugAction(d, indentLevel);
    }
}

/*!
    \qmltype ScriptAction
    \instantiates QQuickScriptAction
    \inqmlmodule QtQuick
    \ingroup qtquick-transitions-animations
    \inherits Animation
    \brief Defines scripts to be run during an animation.

    ScriptAction can be used to run a script at a specific point in an animation.

    \qml
    SequentialAnimation {
        NumberAnimation {
            // ...
        }
        ScriptAction { script: doSomething(); }
        NumberAnimation {
            // ...
        }
    }
    \endqml

    When used as part of a Transition, you can also target a specific
    StateChangeScript to run using the \c scriptName property.

    \snippet qml/states/statechangescript.qml state and transition

    \sa StateChangeScript
*/
QQuickScriptAction::QQuickScriptAction(QObject *parent)
    :QQuickAbstractAnimation(*(new QQuickScriptActionPrivate), parent)
{
}

QQuickScriptAction::~QQuickScriptAction()
{
}

QQuickScriptActionPrivate::QQuickScriptActionPrivate()
    : QQuickAbstractAnimationPrivate(), hasRunScriptScript(false), reversing(false){}

/*!
    \qmlproperty script QtQuick::ScriptAction::script
    This property holds the script to run.
*/
QQmlScriptString QQuickScriptAction::script() const
{
    Q_D(const QQuickScriptAction);
    return d->script;
}

void QQuickScriptAction::setScript(const QQmlScriptString &script)
{
    Q_D(QQuickScriptAction);
    d->script = script;
}

/*!
    \qmlproperty string QtQuick::ScriptAction::scriptName
    This property holds the name of the StateChangeScript to run.

    This property is only valid when ScriptAction is used as part of a transition.
    If both script and scriptName are set, scriptName will be used.

    \note When using scriptName in a reversible transition, the script will only
    be run when the transition is being run forwards.
*/
QString QQuickScriptAction::stateChangeScriptName() const
{
    Q_D(const QQuickScriptAction);
    return d->name;
}

void QQuickScriptAction::setStateChangeScriptName(const QString &name)
{
    Q_D(QQuickScriptAction);
    d->name = name;
}

QAbstractAnimationAction* QQuickScriptActionPrivate::createAction()
{
    return new Proxy(this);
}

void QQuickScriptActionPrivate::debugAction(QDebug d, int indentLevel) const
{
    QQmlScriptString scriptStr = hasRunScriptScript ? runScriptScript : script;

    if (!scriptStr.isEmpty()) {
        QQmlExpression expr(scriptStr);

        QByteArray ind(indentLevel, ' ');
        QString exprStr = expr.expression();
        int endOfFirstLine = exprStr.indexOf('\n');
        d << "\n" << ind.constData() << exprStr.leftRef(endOfFirstLine);
        if (endOfFirstLine != -1 && endOfFirstLine < exprStr.length())
            d << "...";
    }
}

void QQuickScriptActionPrivate::execute()
{
    Q_Q(QQuickScriptAction);
    if (hasRunScriptScript && reversing)
        return;

    QQmlScriptString scriptStr = hasRunScriptScript ? runScriptScript : script;

    if (!scriptStr.isEmpty()) {
        QQmlExpression expr(scriptStr);
        expr.evaluate();
        if (expr.hasError())
            qmlWarning(q) << expr.error();
    }
}

QAbstractAnimationJob* QQuickScriptAction::transition(QQuickStateActions &actions,
                                    QQmlProperties &modified,
                                    TransitionDirection direction,
                                    QObject *defaultTarget)
{
    Q_D(QQuickScriptAction);
    Q_UNUSED(modified);
    Q_UNUSED(defaultTarget);

    d->hasRunScriptScript = false;
    d->reversing = (direction == Backward);
    if (!d->name.isEmpty()) {
        for (int ii = 0; ii < actions.count(); ++ii) {
            QQuickStateAction &action = actions[ii];

            if (action.event && action.event->type() == QQuickStateActionEvent::Script
                && static_cast<QQuickStateChangeScript*>(action.event)->name() == d->name) {
                d->runScriptScript = static_cast<QQuickStateChangeScript*>(action.event)->script();
                d->hasRunScriptScript = true;
                action.actionDone = true;
                break;  //only match one (names should be unique)
            }
        }
    }
    return initInstance(new QActionAnimation(d->createAction()));
}

/*!
    \qmltype PropertyAction
    \instantiates QQuickPropertyAction
    \inqmlmodule QtQuick
    \ingroup qtquick-transitions-animations
    \inherits Animation
    \brief Specifies immediate property changes during animation.

    PropertyAction is used to specify an immediate property change during an
    animation. The property change is not animated.

    It is useful for setting non-animated property values during an animation.

    For example, here is a SequentialAnimation that sets the image's
    \l {Item::}{opacity} property to \c .5, animates the width of the image,
    then sets \l {Item::}{opacity} back to \c 1:

    \snippet qml/propertyaction.qml standalone

    PropertyAction is also useful for setting the exact point at which a property
    change should occur during a \l Transition. For example, if PropertyChanges
    was used in a \l State to rotate an item around a particular
    \l {Item::}{transformOrigin}, it might be implemented like this:

    \snippet qml/propertyaction.qml transition

    However, with this code, the \c transformOrigin is not set until \e after
    the animation, as a \l State is taken to define the values at the \e end of
    a transition. The animation would rotate at the default \c transformOrigin,
    then jump to \c Item.BottomRight. To fix this, insert a PropertyAction
    before the RotationAnimation begins:

    \snippet qml/propertyaction-sequential.qml sequential

    This immediately sets the \c transformOrigin property to the value defined
    in the end state of the \l Transition (i.e. the value defined in the
    PropertyAction object) so that the rotation animation begins with the
    correct transform origin.

    \sa {Animation and Transitions in Qt Quick}, {Qt QML}
*/
QQuickPropertyAction::QQuickPropertyAction(QObject *parent)
: QQuickAbstractAnimation(*(new QQuickPropertyActionPrivate), parent)
{
}

QQuickPropertyAction::~QQuickPropertyAction()
{
}

QObject *QQuickPropertyAction::target() const
{
    Q_D(const QQuickPropertyAction);
    return d->target;
}

void QQuickPropertyAction::setTargetObject(QObject *o)
{
    Q_D(QQuickPropertyAction);
    if (d->target == o)
        return;
    d->target = o;
    emit targetChanged();
}

QString QQuickPropertyAction::property() const
{
    Q_D(const QQuickPropertyAction);
    return d->propertyName;
}

void QQuickPropertyAction::setProperty(const QString &n)
{
    Q_D(QQuickPropertyAction);
    if (d->propertyName == n)
        return;
    d->propertyName = n;
    emit propertyChanged();
}

/*!
    \qmlproperty Object QtQuick::PropertyAction::target
    \qmlproperty list<Object> QtQuick::PropertyAction::targets
    \qmlproperty string QtQuick::PropertyAction::property
    \qmlproperty string QtQuick::PropertyAction::properties

    These properties determine the items and their properties that are
    affected by this action.

    The details of how these properties are interpreted in different situations
    is covered in the \l{PropertyAnimation::properties}{corresponding} PropertyAnimation
    documentation.

    \sa exclude
*/
QString QQuickPropertyAction::properties() const
{
    Q_D(const QQuickPropertyAction);
    return d->properties;
}

void QQuickPropertyAction::setProperties(const QString &p)
{
    Q_D(QQuickPropertyAction);
    if (d->properties == p)
        return;
    d->properties = p;
    emit propertiesChanged(p);
}

QQmlListProperty<QObject> QQuickPropertyAction::targets()
{
    Q_D(QQuickPropertyAction);
    return QQmlListProperty<QObject>(this, &(d->targets));
}

/*!
    \qmlproperty list<Object> QtQuick::PropertyAction::exclude
    This property holds the objects that should not be affected by this action.

    \sa targets
*/
QQmlListProperty<QObject> QQuickPropertyAction::exclude()
{
    Q_D(QQuickPropertyAction);
    return QQmlListProperty<QObject>(this, &(d->exclude));
}

/*!
    \qmlproperty any QtQuick::PropertyAction::value
    This property holds the value to be set on the property.

    If the PropertyAction is defined within a \l Transition or \l Behavior,
    this value defaults to the value defined in the end state of the
    \l Transition, or the value of the property change that triggered the
    \l Behavior.
*/
QVariant QQuickPropertyAction::value() const
{
    Q_D(const QQuickPropertyAction);
    return d->value;
}

void QQuickPropertyAction::setValue(const QVariant &v)
{
    Q_D(QQuickPropertyAction);
    if (d->value.isNull || d->value != v) {
        d->value = v;
        emit valueChanged(v);
    }
}

QAbstractAnimationJob* QQuickPropertyAction::transition(QQuickStateActions &actions,
                                      QQmlProperties &modified,
                                      TransitionDirection direction,
                                      QObject *defaultTarget)
{
    Q_D(QQuickPropertyAction);
    Q_UNUSED(direction);

    struct QQuickSetPropertyAnimationAction : public QAbstractAnimationAction
    {
        QQuickStateActions actions;
        void doAction() override
        {
            for (int ii = 0; ii < actions.count(); ++ii) {
                const QQuickStateAction &action = actions.at(ii);
                QQmlPropertyPrivate::write(action.property, action.toValue, QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
            }
        }
        void debugAction(QDebug d, int indentLevel) const override {
            QByteArray ind(indentLevel, ' ');
            for (int ii = 0; ii < actions.count(); ++ii) {
                const QQuickStateAction &action = actions.at(ii);
                d << "\n" << ind.constData() << "target:" << action.property.object() << "property:" << action.property.name()
                  << "value:" << action.toValue;
            }
        }
    };

    QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(','));
    for (int ii = 0; ii < props.count(); ++ii)
        props[ii] = props.at(ii).trimmed();
    if (!d->propertyName.isEmpty())
        props << d->propertyName;

    QList<QObject*> targets = d->targets;
    if (d->target)
        targets.append(d->target);

    bool hasSelectors = !props.isEmpty() || !targets.isEmpty() || !d->exclude.isEmpty();

    if (d->defaultProperty.isValid() && !hasSelectors) {
        props << d->defaultProperty.name();
        targets << d->defaultProperty.object();
    }

    if (defaultTarget && targets.isEmpty())
        targets << defaultTarget;

    QQuickSetPropertyAnimationAction *data = new QQuickSetPropertyAnimationAction;

    bool hasExplicit = false;
    //an explicit animation has been specified
    if (d->value.isValid()) {
        for (int i = 0; i < props.count(); ++i) {
            for (int j = 0; j < targets.count(); ++j) {
                QQuickStateAction myAction;
                myAction.property = d->createProperty(targets.at(j), props.at(i), this);
                if (myAction.property.isValid()) {
                    myAction.toValue = d->value;
                    QQuickPropertyAnimationPrivate::convertVariant(myAction.toValue, myAction.property.propertyType());
                    data->actions << myAction;
                    hasExplicit = true;
                    for (int ii = 0; ii < actions.count(); ++ii) {
                        QQuickStateAction &action = actions[ii];
                        if (action.property.object() == myAction.property.object() &&
                            myAction.property.name() == action.property.name()) {
                            modified << action.property;
                            break;  //### any chance there could be multiples?
                        }
                    }
                }
            }
        }
    }

    if (!hasExplicit)
    for (int ii = 0; ii < actions.count(); ++ii) {
        QQuickStateAction &action = actions[ii];

        QObject *obj = action.property.object();
        QString propertyName = action.property.name();
        QObject *sObj = action.specifiedObject;
        QString sPropertyName = action.specifiedProperty;
        bool same = (obj == sObj);

        if ((targets.isEmpty() || targets.contains(obj) || (!same && targets.contains(sObj))) &&
           (!d->exclude.contains(obj)) && (same || (!d->exclude.contains(sObj))) &&
           (props.contains(propertyName) || (!same && props.contains(sPropertyName)))) {
            QQuickStateAction myAction = action;

            if (d->value.isValid())
                myAction.toValue = d->value;
            QQuickPropertyAnimationPrivate::convertVariant(myAction.toValue, myAction.property.propertyType());

            modified << action.property;
            data->actions << myAction;
            action.fromValue = myAction.toValue;
        }
    }

    QActionAnimation *action = new QActionAnimation;
    if (data->actions.count()) {
        action->setAnimAction(data);
    } else {
        delete data;
    }
    return initInstance(action);
}

/*!
    \qmltype NumberAnimation
    \instantiates QQuickNumberAnimation
    \inqmlmodule QtQuick
    \ingroup qtquick-animation-properties
    \inherits PropertyAnimation
    \brief Animates changes in qreal-type values.

    NumberAnimation is a specialized PropertyAnimation that defines an
    animation to be applied when a numerical value changes.

    Here is a NumberAnimation applied to the \c x property of a \l Rectangle
    as a property value source. It animates the \c x value from its current
    value to a value of 50, over 1000 milliseconds:

    \snippet qml/numberanimation.qml 0

    Like any other animation type, a NumberAnimation can be applied in a
    number of ways, including transitions, behaviors and property value
    sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
    variety of methods for creating animations.

    Note that NumberAnimation may not animate smoothly if there are irregular
    changes in the number value that it is tracking. If this is the case, use
    SmoothedAnimation instead.

    \sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
*/
QQuickNumberAnimation::QQuickNumberAnimation(QObject *parent)
: QQuickPropertyAnimation(parent)
{
    init();
}

QQuickNumberAnimation::QQuickNumberAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent)
: QQuickPropertyAnimation(dd, parent)
{
    init();
}

QQuickNumberAnimation::~QQuickNumberAnimation()
{
}

void QQuickNumberAnimation::init()
{
    Q_D(QQuickPropertyAnimation);
    d->interpolatorType = QMetaType::QReal;
    d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
}

/*!
    \qmlproperty real QtQuick::NumberAnimation::from
    This property holds the starting value for the animation.

    For example, the following animation is not applied until the \c x value
    has reached 100:

    \qml
    Item {
        states: [
            // ...
        ]

        transition: Transition {
            NumberAnimation { properties: "x"; from: 100; duration: 200 }
        }
    }
    \endqml

    If the NumberAnimation is defined within a \l Transition or \l Behavior,
    this value defaults to the value defined in the starting state of the
    \l Transition, or the current value of the property at the moment the
    \l Behavior is triggered.

    \sa {Animation and Transitions in Qt Quick}
*/

qreal QQuickNumberAnimation::from() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->from.toReal();
}

void QQuickNumberAnimation::setFrom(qreal f)
{
    QQuickPropertyAnimation::setFrom(f);
}

/*!
    \qmlproperty real QtQuick::NumberAnimation::to
    This property holds the end value for the animation.

    If the NumberAnimation is defined within a \l Transition or \l Behavior,
    this value defaults to the value defined in the end state of the
    \l Transition, or the value of the property change that triggered the
    \l Behavior.

    \sa {Animation and Transitions in Qt Quick}
*/
qreal QQuickNumberAnimation::to() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->to.toReal();
}

void QQuickNumberAnimation::setTo(qreal t)
{
    QQuickPropertyAnimation::setTo(t);
}



/*!
    \qmltype Vector3dAnimation
    \instantiates QQuickVector3dAnimation
    \inqmlmodule QtQuick
    \ingroup qtquick-animation-properties
    \inherits PropertyAnimation
    \brief Animates changes in QVector3d values.

    Vector3dAnimation is a specialized PropertyAnimation that defines an
    animation to be applied when a Vector3d value changes.

    Like any other animation type, a Vector3dAnimation can be applied in a
    number of ways, including transitions, behaviors and property value
    sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
    variety of methods for creating animations.

    \sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
*/
QQuickVector3dAnimation::QQuickVector3dAnimation(QObject *parent)
: QQuickPropertyAnimation(parent)
{
    Q_D(QQuickPropertyAnimation);
    d->interpolatorType = QMetaType::QVector3D;
    d->defaultToInterpolatorType = true;
    d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
}

QQuickVector3dAnimation::~QQuickVector3dAnimation()
{
}

/*!
    \qmlproperty vector3d QtQuick::Vector3dAnimation::from
    This property holds the starting value for the animation.

    If the Vector3dAnimation is defined within a \l Transition or \l Behavior,
    this value defaults to the value defined in the starting state of the
    \l Transition, or the current value of the property at the moment the
    \l Behavior is triggered.

    \sa {Animation and Transitions in Qt Quick}
*/
QVector3D QQuickVector3dAnimation::from() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->from.value<QVector3D>();
}

void QQuickVector3dAnimation::setFrom(QVector3D f)
{
    QQuickPropertyAnimation::setFrom(f);
}

/*!
    \qmlproperty vector3d QtQuick::Vector3dAnimation::to
    This property holds the end value for the animation.

    If the Vector3dAnimation is defined within a \l Transition or \l Behavior,
    this value defaults to the value defined in the end state of the
    \l Transition, or the value of the property change that triggered the
    \l Behavior.

    \sa {Animation and Transitions in Qt Quick}
*/
QVector3D QQuickVector3dAnimation::to() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->to.value<QVector3D>();
}

void QQuickVector3dAnimation::setTo(QVector3D t)
{
    QQuickPropertyAnimation::setTo(t);
}



/*!
    \qmltype RotationAnimation
    \instantiates QQuickRotationAnimation
    \inqmlmodule QtQuick
    \ingroup qtquick-animation-properties
    \inherits PropertyAnimation
    \brief Animates changes in rotation values.

    RotationAnimation is a specialized PropertyAnimation that gives control
    over the direction of rotation during an animation.

    By default, it rotates in the direction
    of the numerical change; a rotation from 0 to 240 will rotate 240 degrees
    clockwise, while a rotation from 240 to 0 will rotate 240 degrees
    counterclockwise. The \l direction property can be set to specify the
    direction in which the rotation should occur.

    In the following example we use RotationAnimation to animate the rotation
    between states via the shortest path:

    \snippet qml/rotationanimation.qml 0

    Notice the RotationAnimation did not need to set a \c target
    value. As a convenience, when used in a transition, RotationAnimation will rotate all
    properties named "rotation" or "angle". You can override this by providing
    your own properties via \l {PropertyAnimation::properties}{properties} or
    \l {PropertyAnimation::property}{property}.

    Also, note the \l Rectangle will be rotated around its default
    \l {Item::}{transformOrigin} (which is \c Item.Center). To use a different
    transform origin, set the origin in the PropertyChanges object and apply
    the change at the start of the animation using PropertyAction. See the
    PropertyAction documentation for more details.

    Like any other animation type, a RotationAnimation can be applied in a
    number of ways, including transitions, behaviors and property value
    sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
    variety of methods for creating animations.

    \sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
*/
QVariant _q_interpolateShortestRotation(qreal &f, qreal &t, qreal progress)
{
    qreal newt = t;
    qreal diff = t-f;
    while(diff > 180.0){
        newt -= 360.0;
        diff -= 360.0;
    }
    while(diff < -180.0){
        newt += 360.0;
        diff += 360.0;
    }
    return QVariant(f + (newt - f) * progress);
}

QVariant _q_interpolateClockwiseRotation(qreal &f, qreal &t, qreal progress)
{
    qreal newt = t;
    qreal diff = t-f;
    while(diff < 0.0){
        newt += 360.0;
        diff += 360.0;
    }
    return QVariant(f + (newt - f) * progress);
}

QVariant _q_interpolateCounterclockwiseRotation(qreal &f, qreal &t, qreal progress)
{
    qreal newt = t;
    qreal diff = t-f;
    while(diff > 0.0){
        newt -= 360.0;
        diff -= 360.0;
    }
    return QVariant(f + (newt - f) * progress);
}

QQuickRotationAnimation::QQuickRotationAnimation(QObject *parent)
: QQuickPropertyAnimation(*(new QQuickRotationAnimationPrivate), parent)
{
    Q_D(QQuickRotationAnimation);
    d->interpolatorType = QMetaType::QReal;
    d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
    d->defaultProperties = QLatin1String("rotation,angle");
}

QQuickRotationAnimation::~QQuickRotationAnimation()
{
}

/*!
    \qmlproperty real QtQuick::RotationAnimation::from
    This property holds the starting value for the animation.

    For example, the following animation is not applied until the \c angle value
    has reached 100:

    \qml
    Item {
        states: [
            // ...
        ]

        transition: Transition {
            RotationAnimation { properties: "angle"; from: 100; duration: 2000 }
        }
    }
    \endqml

    If the RotationAnimation is defined within a \l Transition or \l Behavior,
    this value defaults to the value defined in the starting state of the
    \l Transition, or the current value of the property at the moment the
    \l Behavior is triggered.

    \sa {Animation and Transitions in Qt Quick}
*/
qreal QQuickRotationAnimation::from() const
{
    Q_D(const QQuickRotationAnimation);
    return d->from.toReal();
}

void QQuickRotationAnimation::setFrom(qreal f)
{
    QQuickPropertyAnimation::setFrom(f);
}

/*!
    \qmlproperty real QtQuick::RotationAnimation::to
    This property holds the end value for the animation..

    If the RotationAnimation is defined within a \l Transition or \l Behavior,
    this value defaults to the value defined in the end state of the
    \l Transition, or the value of the property change that triggered the
    \l Behavior.

    \sa {Animation and Transitions in Qt Quick}
*/
qreal QQuickRotationAnimation::to() const
{
    Q_D(const QQuickRotationAnimation);
    return d->to.toReal();
}

void QQuickRotationAnimation::setTo(qreal t)
{
    QQuickPropertyAnimation::setTo(t);
}

/*!
    \qmlproperty enumeration QtQuick::RotationAnimation::direction
    This property holds the direction of the rotation.

    Possible values are:

    \list
    \li RotationAnimation.Numerical (default) - Rotate by linearly interpolating between the two numbers.
           A rotation from 10 to 350 will rotate 340 degrees clockwise.
    \li RotationAnimation.Clockwise - Rotate clockwise between the two values
    \li RotationAnimation.Counterclockwise - Rotate counterclockwise between the two values
    \li RotationAnimation.Shortest - Rotate in the direction that produces the shortest animation path.
           A rotation from 10 to 350 will rotate 20 degrees counterclockwise.
    \endlist
*/
QQuickRotationAnimation::RotationDirection QQuickRotationAnimation::direction() const
{
    Q_D(const QQuickRotationAnimation);
    return d->direction;
}

void QQuickRotationAnimation::setDirection(QQuickRotationAnimation::RotationDirection direction)
{
    Q_D(QQuickRotationAnimation);
    if (d->direction == direction)
        return;

    d->direction = direction;
    switch(d->direction) {
    case Clockwise:
        d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(reinterpret_cast<void *>(&_q_interpolateClockwiseRotation));
        break;
    case Counterclockwise:
        d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(reinterpret_cast<void *>(&_q_interpolateCounterclockwiseRotation));
        break;
    case Shortest:
        d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(reinterpret_cast<void *>(&_q_interpolateShortestRotation));
        break;
    default:
        d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
        break;
    }
    emit directionChanged();
}



QQuickAnimationGroup::QQuickAnimationGroup(QObject *parent)
: QQuickAbstractAnimation(*(new QQuickAnimationGroupPrivate), parent)
{
}

QQuickAnimationGroup::QQuickAnimationGroup(QQuickAnimationGroupPrivate &dd, QObject *parent)
    : QQuickAbstractAnimation(dd, parent)
{
}

void QQuickAnimationGroupPrivate::append_animation(QQmlListProperty<QQuickAbstractAnimation> *list, QQuickAbstractAnimation *a)
{
    QQuickAnimationGroup *q = qmlobject_cast<QQuickAnimationGroup *>(list->object);
    if (q && a)
        a->setGroup(q);
}

QQuickAbstractAnimation *QQuickAnimationGroupPrivate::at_animation(QQmlListProperty<QQuickAbstractAnimation> *list, int index)
{
    if (auto q = qmlobject_cast<QQuickAnimationGroup *>(list->object))
        return q->d_func()->animations.at(index);
    return nullptr;
}

int QQuickAnimationGroupPrivate::count_animation(QQmlListProperty<QQuickAbstractAnimation> *list)
{
    if (auto q = qmlobject_cast<QQuickAnimationGroup *>(list->object))
        return q->d_func()->animations.count();
    return 0;
}

void QQuickAnimationGroupPrivate::clear_animation(QQmlListProperty<QQuickAbstractAnimation> *list)
{
    QQuickAnimationGroup *q = qobject_cast<QQuickAnimationGroup *>(list->object);
    if (q) {
        while (q->d_func()->animations.count()) {
            QQuickAbstractAnimation *firstAnim = q->d_func()->animations.at(0);
            firstAnim->setGroup(nullptr);
        }
    }
}

void QQuickAnimationGroupPrivate::replace_animation(QQmlListProperty<QQuickAbstractAnimation> *list,
                                                    int i, QQuickAbstractAnimation *a)
{
    if (auto *q = qmlobject_cast<QQuickAnimationGroup *>(list->object)) {
        if (QQuickAbstractAnimation *anim = q->d_func()->animations.at(i))
            anim->setGroup(nullptr);
        if (a)
            a->setGroup(q, i);
    }
}

void QQuickAnimationGroupPrivate::removeLast_animation(QQmlListProperty<QQuickAbstractAnimation> *list)
{
    if (auto *q = qobject_cast<QQuickAnimationGroup *>(list->object))
        q->d_func()->animations.last()->setGroup(nullptr);
}

QQuickAnimationGroup::~QQuickAnimationGroup()
{
    Q_D(QQuickAnimationGroup);
    for (int i = 0; i < d->animations.count(); ++i)
        d->animations.at(i)->d_func()->group = nullptr;
    d->animations.clear();
}

QQmlListProperty<QQuickAbstractAnimation> QQuickAnimationGroup::animations()
{
    Q_D(QQuickAnimationGroup);
    return QQmlListProperty<QQuickAbstractAnimation>(
                this, &(d->animations),
                &QQuickAnimationGroupPrivate::append_animation,
                &QQuickAnimationGroupPrivate::count_animation,
                &QQuickAnimationGroupPrivate::at_animation,
                &QQuickAnimationGroupPrivate::clear_animation,
                &QQuickAnimationGroupPrivate::replace_animation,
                &QQuickAnimationGroupPrivate::removeLast_animation);
}

/*!
    \qmltype SequentialAnimation
    \instantiates QQuickSequentialAnimation
    \inqmlmodule QtQuick
    \ingroup qtquick-transitions-animations
    \inherits Animation
    \brief Allows animations to be run sequentially.

    The SequentialAnimation and ParallelAnimation types allow multiple
    animations to be run together. Animations defined in a SequentialAnimation
    are run one after the other, while animations defined in a ParallelAnimation
    are run at the same time.

    The following example runs two number animations in a sequence.  The \l Rectangle
    animates to a \c x position of 50, then to a \c y position of 50.

    \snippet qml/sequentialanimation.qml 0

    Animations defined within a \l Transition are automatically run in parallel,
    so SequentialAnimation can be used to enclose the animations in a \l Transition
    if this is the preferred behavior.

    Like any other animation type, a SequentialAnimation can be applied in a
    number of ways, including transitions, behaviors and property value
    sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
    variety of methods for creating animations.

    \note Once an animation has been grouped into a SequentialAnimation or
    ParallelAnimation, it cannot be individually started and stopped; the
    SequentialAnimation or ParallelAnimation must be started and stopped as a group.

    \sa ParallelAnimation, {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
*/

QQuickSequentialAnimation::QQuickSequentialAnimation(QObject *parent) :
    QQuickAnimationGroup(parent)
{
}

QQuickSequentialAnimation::~QQuickSequentialAnimation()
{
}

QQuickAbstractAnimation::ThreadingModel QQuickSequentialAnimation::threadingModel() const
{
    Q_D(const QQuickAnimationGroup);

    ThreadingModel style = AnyThread;
    for (int i=0; i<d->animations.size(); ++i) {
        ThreadingModel ces = d->animations.at(i)->threadingModel();
        if (ces == GuiThread)
            return GuiThread;
        else if (ces == RenderThread)
            style = RenderThread;
    }
    return style;
}

QAbstractAnimationJob* QQuickSequentialAnimation::transition(QQuickStateActions &actions,
                                    QQmlProperties &modified,
                                    TransitionDirection direction,
                                    QObject *defaultTarget)
{
    Q_D(QQuickAnimationGroup);

    QSequentialAnimationGroupJob *ag = new QSequentialAnimationGroupJob;

    int inc = 1;
    int from = 0;
    if (direction == Backward) {
        inc = -1;
        from = d->animations.count() - 1;
    }

    ThreadingModel execution = threadingModel();

    bool valid = d->defaultProperty.isValid();
    QAbstractAnimationJob* anim;
    for (int ii = from; ii < d->animations.count() && ii >= 0; ii += inc) {
        if (valid)
            d->animations.at(ii)->setDefaultTarget(d->defaultProperty);
        anim = d->animations.at(ii)->transition(actions, modified, direction, defaultTarget);
        if (anim) {
            if (d->animations.at(ii)->threadingModel() == RenderThread && execution != RenderThread)
                anim = new QQuickAnimatorProxyJob(anim, this);
            inc == -1 ? ag->prependAnimation(anim) : ag->appendAnimation(anim);
        }
    }

    return initInstance(ag);
}



/*!
    \qmltype ParallelAnimation
    \instantiates QQuickParallelAnimation
    \inqmlmodule QtQuick
    \ingroup qtquick-transitions-animations
    \inherits Animation
    \brief Enables animations to be run in parallel.

    The SequentialAnimation and ParallelAnimation types allow multiple
    animations to be run together. Animations defined in a SequentialAnimation
    are run one after the other, while animations defined in a ParallelAnimation
    are run at the same time.

    The following animation runs two number animations in parallel. The \l Rectangle
    moves to (50,50) by animating its \c x and \c y properties at the same time.

    \snippet qml/parallelanimation.qml 0

    Like any other animation type, a ParallelAnimation can be applied in a
    number of ways, including transitions, behaviors and property value
    sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
    variety of methods for creating animations.

    \note Once an animation has been grouped into a SequentialAnimation or
    ParallelAnimation, it cannot be individually started and stopped; the
    SequentialAnimation or ParallelAnimation must be started and stopped as a group.

    \sa SequentialAnimation, {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
*/
QQuickParallelAnimation::QQuickParallelAnimation(QObject *parent) :
    QQuickAnimationGroup(parent)
{
}

QQuickParallelAnimation::~QQuickParallelAnimation()
{
}

QQuickAbstractAnimation::ThreadingModel QQuickParallelAnimation::threadingModel() const
{
    Q_D(const QQuickAnimationGroup);

    ThreadingModel style = AnyThread;
    for (int i=0; i<d->animations.size(); ++i) {
        ThreadingModel ces = d->animations.at(i)->threadingModel();
        if (ces == GuiThread)
            return GuiThread;
        else if (ces == RenderThread)
            style = RenderThread;
    }
    return style;
}



QAbstractAnimationJob* QQuickParallelAnimation::transition(QQuickStateActions &actions,
                                      QQmlProperties &modified,
                                      TransitionDirection direction,
                                      QObject *defaultTarget)
{
    Q_D(QQuickAnimationGroup);
    QParallelAnimationGroupJob *ag = new QParallelAnimationGroupJob;

    ThreadingModel style = threadingModel();

    bool valid = d->defaultProperty.isValid();
    QAbstractAnimationJob* anim;
    for (int ii = 0; ii < d->animations.count(); ++ii) {
        if (valid)
            d->animations.at(ii)->setDefaultTarget(d->defaultProperty);
        anim = d->animations.at(ii)->transition(actions, modified, direction, defaultTarget);
        if (anim) {
            if (d->animations.at(ii)->threadingModel() == RenderThread && style != RenderThread)
                anim = new QQuickAnimatorProxyJob(anim, this);
            ag->appendAnimation(anim);
        }
    }
    return initInstance(ag);
}

//convert a variant from string type to another animatable type
void QQuickPropertyAnimationPrivate::convertVariant(QVariant &variant, int type)
{
    if (variant.userType() != QMetaType::QString) {
        variant.convert(type);
        return;
    }

    switch (type) {
    case QMetaType::QRect:
    case QMetaType::QRectF:
    case QMetaType::QPoint:
    case QMetaType::QPointF:
    case QMetaType::QSize:
    case QMetaType::QSizeF:
    case QMetaType::QColor:
    case QMetaType::QVector3D:
        {
        bool ok = false;
        variant = QQmlStringConverters::variantFromString(variant.toString(), type, &ok);
        }
        break;
    default:
        if (QQmlValueTypeFactory::isValueType((uint)type)) {
            variant.convert(type);
        } else {
            QQmlMetaType::StringConverter converter = QQmlMetaType::customStringConverter(type);
            if (converter)
                variant = converter(variant.toString());
        }
        break;
    }
}

QQuickBulkValueAnimator::QQuickBulkValueAnimator()
    : QAbstractAnimationJob(), animValue(nullptr), fromIsSourced(nullptr), m_duration(250)
{
}

QQuickBulkValueAnimator::~QQuickBulkValueAnimator()
{
    delete animValue;
}

void QQuickBulkValueAnimator::setAnimValue(QQuickBulkValueUpdater *value)
{
    if (isRunning())
        stop();
    animValue = value;
}

void QQuickBulkValueAnimator::updateCurrentTime(int currentTime)
{
    if (isStopped())
        return;

    const qreal progress = easing.valueForProgress(((m_duration == 0) ? qreal(1) : qreal(currentTime) / qreal(m_duration)));

    if (animValue)
        animValue->setValue(progress);
}

void QQuickBulkValueAnimator::topLevelAnimationLoopChanged()
{
    //check for new from every top-level loop (when the top level animation is started and all subsequent loops)
    if (fromIsSourced)
        *fromIsSourced = false;
    QAbstractAnimationJob::topLevelAnimationLoopChanged();
}

void QQuickBulkValueAnimator::debugAnimation(QDebug d) const
{
    d << "BulkValueAnimation(" << Qt::hex << (const void *) this << Qt::dec << ")" << "duration:" << duration();

    if (animValue) {
        int indentLevel = 1;
        const QAbstractAnimationJob *job = this;
        while ((job = job->group()))
            ++indentLevel;
        animValue->debugUpdater(d, indentLevel);
    }
}

/*!
    \qmltype PropertyAnimation
    \instantiates QQuickPropertyAnimation
    \inqmlmodule QtQuick
    \ingroup qtquick-animation-properties
    \inherits Animation
    \brief Animates changes in property values.

    PropertyAnimation provides a way to animate changes to a property's value.

    It can be used to define animations in a number of ways:

    \list
    \li In a \l Transition

    For example, to animate any objects that have changed their \c x or \c y properties
    as a result of a state change, using an \c InOutQuad easing curve:

    \snippet qml/propertyanimation.qml transition


    \li In a \l Behavior

    For example, to animate all changes to a rectangle's \c x property:

    \snippet qml/propertyanimation.qml behavior


    \li As a property value source

    For example, to repeatedly animate the rectangle's \c x property:

    \snippet qml/propertyanimation.qml propertyvaluesource


    \li In a signal handler

    For example, to fade out \c theObject when clicked:
    \qml
    MouseArea {
        anchors.fill: theObject
        onClicked: PropertyAnimation { target: theObject; property: "opacity"; to: 0 }
    }
    \endqml

    \li Standalone

    For example, to animate \c rect's \c width property over 500ms, from its current width to 30:

    \snippet qml/propertyanimation.qml standalone

    \endlist

    Depending on how the animation is used, the set of properties normally used will be
    different. For more information see the individual property documentation, as well
    as the \l{Animation and Transitions in Qt Quick} introduction.

    Note that PropertyAnimation inherits the abstract \l Animation type.
    This includes additional properties and methods for controlling the animation.

    \sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
*/

QQuickPropertyAnimation::QQuickPropertyAnimation(QObject *parent)
: QQuickAbstractAnimation(*(new QQuickPropertyAnimationPrivate), parent)
{
}

QQuickPropertyAnimation::QQuickPropertyAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent)
: QQuickAbstractAnimation(dd, parent)
{
}

QQuickPropertyAnimation::~QQuickPropertyAnimation()
{
}

/*!
    \qmlproperty int QtQuick::PropertyAnimation::duration
    This property holds the duration of the animation, in milliseconds.

    The default value is 250.
*/
int QQuickPropertyAnimation::duration() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->duration;
}

void QQuickPropertyAnimation::setDuration(int duration)
{
    if (duration < 0) {
        qmlWarning(this) << tr("Cannot set a duration of < 0");
        return;
    }

    Q_D(QQuickPropertyAnimation);
    if (d->duration == duration)
        return;
    d->duration = duration;
    emit durationChanged(duration);
}

/*!
    \qmlproperty variant QtQuick::PropertyAnimation::from
    This property holds the starting value for the animation.

    If the PropertyAnimation is defined within a \l Transition or \l Behavior,
    this value defaults to the value defined in the starting state of the
    \l Transition, or the current value of the property at the moment the
    \l Behavior is triggered.

    \sa {Animation and Transitions in Qt Quick}
*/
QVariant QQuickPropertyAnimation::from() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->from;
}

void QQuickPropertyAnimation::setFrom(const QVariant &f)
{
    Q_D(QQuickPropertyAnimation);
    if (d->fromIsDefined && f == d->from)
        return;
    d->from = f;
    d->fromIsDefined = f.isValid();
    emit fromChanged();
}

/*!
    \qmlproperty variant QtQuick::PropertyAnimation::to
    This property holds the end value for the animation.

    If the PropertyAnimation is defined within a \l Transition or \l Behavior,
    this value defaults to the value defined in the end state of the
    \l Transition, or the value of the property change that triggered the
    \l Behavior.

    \sa {Animation and Transitions in Qt Quick}
*/
QVariant QQuickPropertyAnimation::to() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->to;
}

void QQuickPropertyAnimation::setTo(const QVariant &t)
{
    Q_D(QQuickPropertyAnimation);
    if (d->toIsDefined && t == d->to)
        return;
    d->to = t;
    d->toIsDefined = t.isValid();
    emit toChanged();
}

/*!
    \qmlpropertygroup QtQuick::PropertyAnimation::easing
    \qmlproperty enumeration QtQuick::PropertyAnimation::easing.type
    \qmlproperty real QtQuick::PropertyAnimation::easing.amplitude
    \qmlproperty real QtQuick::PropertyAnimation::easing.overshoot
    \qmlproperty real QtQuick::PropertyAnimation::easing.period
    \qmlproperty list<real> QtQuick::PropertyAnimation::easing.bezierCurve

//! propertyanimation.easing
    \brief Specifies the easing curve used for the animation

    To specify an easing curve you need to specify at least the type. For some curves you can also specify
    amplitude, period and/or overshoot (more details provided after the table). The default easing curve is
    \c Easing.Linear.

    \qml
    PropertyAnimation { properties: "y";
                        easing.type: Easing.InOutElastic;
                        easing.amplitude: 2.0;
                        easing.period: 1.5 }
    \endqml

    Available types are:

    \table
    \row
        \li \c Easing.Linear
        \li Easing curve for a linear (t) function: velocity is constant.
        \li \inlineimage qeasingcurve-linear.png
    \row
        \li \c Easing.InQuad
        \li Easing curve for a quadratic (t^2) function: accelerating from zero velocity.
        \li \inlineimage qeasingcurve-inquad.png
    \row
        \li \c Easing.OutQuad
        \li Easing curve for a quadratic (t^2) function: decelerating to zero velocity.
        \li \inlineimage qeasingcurve-outquad.png
    \row
        \li \c Easing.InOutQuad
        \li Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration.
        \li \inlineimage qeasingcurve-inoutquad.png
    \row
        \li \c Easing.OutInQuad
        \li Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration.
        \li \inlineimage qeasingcurve-outinquad.png
    \row
        \li \c Easing.InCubic
        \li Easing curve for a cubic (t^3) function: accelerating from zero velocity.
        \li \inlineimage qeasingcurve-incubic.png
    \row
        \li \c Easing.OutCubic
        \li Easing curve for a cubic (t^3) function: decelerating to zero velocity.
        \li \inlineimage qeasingcurve-outcubic.png
    \row
        \li \c Easing.InOutCubic
        \li Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration.
        \li \inlineimage qeasingcurve-inoutcubic.png
    \row
        \li \c Easing.OutInCubic
        \li Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration.
        \li \inlineimage qeasingcurve-outincubic.png
    \row
        \li \c Easing.InQuart
        \li Easing curve for a quartic (t^4) function: accelerating from zero velocity.
        \li \inlineimage qeasingcurve-inquart.png
    \row
        \li \c Easing.OutQuart
        \li Easing curve for a quartic (t^4) function: decelerating to zero velocity.
        \li \inlineimage qeasingcurve-outquart.png
    \row
        \li \c Easing.InOutQuart
        \li Easing curve for a quartic (t^4) function: acceleration until halfway, then deceleration.
        \li \inlineimage qeasingcurve-inoutquart.png
    \row
        \li \c Easing.OutInQuart
        \li Easing curve for a quartic (t^4) function: deceleration until halfway, then acceleration.
        \li \inlineimage qeasingcurve-outinquart.png
    \row
        \li \c Easing.InQuint
        \li Easing curve for a quintic (t^5) function: accelerating from zero velocity.
        \li \inlineimage qeasingcurve-inquint.png
    \row
        \li \c Easing.OutQuint
        \li Easing curve for a quintic (t^5) function: decelerating to zero velocity.
        \li \inlineimage qeasingcurve-outquint.png
    \row
        \li \c Easing.InOutQuint
        \li Easing curve for a quintic (t^5) function: acceleration until halfway, then deceleration.
        \li \inlineimage qeasingcurve-inoutquint.png
    \row
        \li \c Easing.OutInQuint
        \li Easing curve for a quintic (t^5) function: deceleration until halfway, then acceleration.
        \li \inlineimage qeasingcurve-outinquint.png
    \row
        \li \c Easing.InSine
        \li Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity.
        \li \inlineimage qeasingcurve-insine.png
    \row
        \li \c Easing.OutSine
        \li Easing curve for a sinusoidal (sin(t)) function: decelerating to zero velocity.
        \li \inlineimage qeasingcurve-outsine.png
    \row
        \li \c Easing.InOutSine
        \li Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration.
        \li \inlineimage qeasingcurve-inoutsine.png
    \row
        \li \c Easing.OutInSine
        \li Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration.
        \li \inlineimage qeasingcurve-outinsine.png
    \row
        \li \c Easing.InExpo
        \li Easing curve for an exponential (2^t) function: accelerating from zero velocity.
        \li \inlineimage qeasingcurve-inexpo.png
    \row
        \li \c Easing.OutExpo
        \li Easing curve for an exponential (2^t) function: decelerating to zero velocity.
        \li \inlineimage qeasingcurve-outexpo.png
    \row
        \li \c Easing.InOutExpo
        \li Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration.
        \li \inlineimage qeasingcurve-inoutexpo.png
    \row
        \li \c Easing.OutInExpo
        \li Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration.
        \li \inlineimage qeasingcurve-outinexpo.png
    \row
        \li \c Easing.InCirc
        \li Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity.
        \li \inlineimage qeasingcurve-incirc.png
    \row
        \li \c Easing.OutCirc
        \li Easing curve for a circular (sqrt(1-t^2)) function: decelerating to zero velocity.
        \li \inlineimage qeasingcurve-outcirc.png
    \row
        \li \c Easing.InOutCirc
        \li Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration.
        \li \inlineimage qeasingcurve-inoutcirc.png
    \row
        \li \c Easing.OutInCirc
        \li Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration.
        \li \inlineimage qeasingcurve-outincirc.png
    \row
        \li \c Easing.InElastic
        \li Easing curve for an elastic (exponentially decaying sine wave) function: accelerating from zero velocity.
        \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter.
        \li \inlineimage qeasingcurve-inelastic.png
    \row
        \li \c Easing.OutElastic
        \li Easing curve for an elastic (exponentially decaying sine wave) function: decelerating to zero velocity.
        \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter.
        \li \inlineimage qeasingcurve-outelastic.png
    \row
        \li \c Easing.InOutElastic
        \li Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration.
        \li \inlineimage qeasingcurve-inoutelastic.png
    \row
        \li \c Easing.OutInElastic
        \li Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration.
        \li \inlineimage qeasingcurve-outinelastic.png
    \row
        \li \c Easing.InBack
        \li Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
        \li \inlineimage qeasingcurve-inback.png
    \row
        \li \c Easing.OutBack
        \li Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity.
        \li \inlineimage qeasingcurve-outback.png
    \row
        \li \c Easing.InOutBack
        \li Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
        \li \inlineimage qeasingcurve-inoutback.png
    \row
        \li \c Easing.OutInBack
        \li Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
        \li \inlineimage qeasingcurve-outinback.png
    \row
        \li \c Easing.InBounce
        \li Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity.
        \li \inlineimage qeasingcurve-inbounce.png
    \row
        \li \c Easing.OutBounce
        \li Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating to zero velocity.
        \li \inlineimage qeasingcurve-outbounce.png
    \row
        \li \c Easing.InOutBounce
        \li Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration.
        \li \inlineimage qeasingcurve-inoutbounce.png
    \row
        \li \c Easing.OutInBounce
        \li Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration.
        \li \inlineimage qeasingcurve-outinbounce.png
    \row
        \li \c Easing.Bezier
        \li Custom easing curve defined by the easing.bezierCurve property.
        \li
    \endtable

    \c easing.amplitude is only applicable for bounce and elastic curves (curves of type
    \c Easing.InBounce, \c Easing.OutBounce, \c Easing.InOutBounce, \c Easing.OutInBounce, \c Easing.InElastic,
    \c Easing.OutElastic, \c Easing.InOutElastic or \c Easing.OutInElastic).

    \c easing.overshoot is only applicable if \c easing.type is: \c Easing.InBack, \c Easing.OutBack,
    \c Easing.InOutBack or \c Easing.OutInBack.

    \c easing.period is only applicable if easing.type is: \c Easing.InElastic, \c Easing.OutElastic,
    \c Easing.InOutElastic or \c Easing.OutInElastic.

    \c easing.bezierCurve is only applicable if easing.type is: \c Easing.Bezier.  This property is a list<real> containing
    groups of three points defining a curve from 0,0 to 1,1 - control1, control2,
    end point: [cx1, cy1, cx2, cy2, endx, endy, ...].  The last point must be 1,1.

    See the \l {Qt Quick Examples - Animation#Easing Curves}{Easing Curves} for a demonstration of the different easing settings.
//! propertyanimation.easing
*/
QEasingCurve QQuickPropertyAnimation::easing() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->easing;
}

void QQuickPropertyAnimation::setEasing(const QEasingCurve &e)
{
    Q_D(QQuickPropertyAnimation);
    if (d->easing == e)
        return;

    d->easing = e;
    emit easingChanged(e);
}

QObject *QQuickPropertyAnimation::target() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->target;
}

void QQuickPropertyAnimation::setTargetObject(QObject *o)
{
    Q_D(QQuickPropertyAnimation);
    if (d->target == o)
        return;
    d->target = o;
    emit targetChanged();
}

QString QQuickPropertyAnimation::property() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->propertyName;
}

void QQuickPropertyAnimation::setProperty(const QString &n)
{
    Q_D(QQuickPropertyAnimation);
    if (d->propertyName == n)
        return;
    d->propertyName = n;
    emit propertyChanged();
}

QString QQuickPropertyAnimation::properties() const
{
    Q_D(const QQuickPropertyAnimation);
    return d->properties;
}

void QQuickPropertyAnimation::setProperties(const QString &prop)
{
    Q_D(QQuickPropertyAnimation);
    if (d->properties == prop)
        return;

    d->properties = prop;
    emit propertiesChanged(prop);
}

/*!
    \qmlproperty string QtQuick::PropertyAnimation::properties
    \qmlproperty list<Object> QtQuick::PropertyAnimation::targets
    \qmlproperty string QtQuick::PropertyAnimation::property
    \qmlproperty Object QtQuick::PropertyAnimation::target

    These properties are used as a set to determine which properties should be animated.
    The singular and plural forms are functionally identical, e.g.
    \qml
    NumberAnimation { target: theItem; property: "x"; to: 500 }
    \endqml
    has the same meaning as
    \qml
    NumberAnimation { targets: theItem; properties: "x"; to: 500 }
    \endqml
    The singular forms are slightly optimized, so if you do have only a single target/property
    to animate you should try to use them.

    The \c targets property allows multiple targets to be set. For example, this animates the
    \c x property of both \c itemA and \c itemB:

    \qml
    NumberAnimation { targets: [itemA, itemB]; properties: "x"; to: 500 }
    \endqml

    In many cases these properties do not need to be explicitly specified, as they can be
    inferred from the animation framework:

    \table 80%
    \row
    \li Value Source / Behavior
    \li When an animation is used as a value source or in a Behavior, the default target and property
       name to be animated can both be inferred.
       \qml
       Rectangle {
           id: theRect
           width: 100; height: 100
           color: Qt.rgba(0,0,1)
           NumberAnimation on x { to: 500; loops: Animation.Infinite } //animate theRect's x property
           Behavior on y { NumberAnimation {} } //animate theRect's y property
       }
       \endqml
    \row
    \li Transition
    \li When used in a transition, a property animation is assumed to match \e all targets
       but \e no properties. In practice, that means you need to specify at least the properties
       in order for the animation to do anything.
       \qml
       Rectangle {
           id: theRect
           width: 100; height: 100
           color: Qt.rgba(0,0,1)
           Item { id: uselessItem }
           states: State {
               name: "state1"
               PropertyChanges { target: theRect; x: 200; y: 200; z: 4 }
               PropertyChanges { target: uselessItem; x: 10; y: 10; z: 2 }
           }
           transitions: Transition {
               //animate both theRect's and uselessItem's x and y to their final values
               NumberAnimation { properties: "x,y" }

               //animate theRect's z to its final value
               NumberAnimation { target: theRect; property: "z" }
           }
       }
       \endqml
    \row
    \li Standalone
    \li When an animation is used standalone, both the target and property need to be
       explicitly specified.
       \qml
       Rectangle {
           id: theRect
           width: 100; height: 100
           color: Qt.rgba(0,0,1)
           //need to explicitly specify target and property
           NumberAnimation { id: theAnim; target: theRect; property: "x"; to: 500 }
           MouseArea {
               anchors.fill: parent
               onClicked: theAnim.start()
           }
       }
       \endqml
    \endtable

    As seen in the above example, properties is specified as a comma-separated string of property names to animate.

    \sa exclude, {Animation and Transitions in Qt Quick}
*/
QQmlListProperty<QObject> QQuickPropertyAnimation::targets()
{
    Q_D(QQuickPropertyAnimation);
    return QQmlListProperty<QObject>(this, &(d->targets));
}

/*!
    \qmlproperty list<Object> QtQuick::PropertyAnimation::exclude
    This property holds the items not to be affected by this animation.
    \sa PropertyAnimation::targets
*/
QQmlListProperty<QObject> QQuickPropertyAnimation::exclude()
{
    Q_D(QQuickPropertyAnimation);
    return QQmlListProperty<QObject>(this, &(d->exclude));
}

void QQuickAnimationPropertyUpdater::setValue(qreal v)
{
    bool deleted = false;
    wasDeleted = &deleted;
    if (reverse)
        v = 1 - v;
    for (int ii = 0; ii < actions.count(); ++ii) {
        QQuickStateAction &action = actions[ii];

        if (v == 1.) {
            QQmlPropertyPrivate::write(action.property, action.toValue, QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
        } else {
            if (!fromIsSourced && !fromIsDefined) {
                action.fromValue = action.property.read();
                if (interpolatorType) {
                    QQuickPropertyAnimationPrivate::convertVariant(action.fromValue, interpolatorType);
                }
            }
            if (!interpolatorType) {
                int propType = action.property.propertyType();
                if (!prevInterpolatorType || prevInterpolatorType != propType) {
                    prevInterpolatorType = propType;
                    interpolator = QVariantAnimationPrivate::getInterpolator(prevInterpolatorType);
                }
            }
            if (interpolator)
                QQmlPropertyPrivate::write(action.property, interpolator(action.fromValue.constData(), action.toValue.constData(), v), QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
        }
        if (deleted)
            return;
    }
    wasDeleted = nullptr;
    fromIsSourced = true;
}

void QQuickAnimationPropertyUpdater::debugUpdater(QDebug d, int indentLevel) const
{
    QByteArray ind(indentLevel, ' ');
    for (int i = 0; i < actions.count(); ++i) {
        const QQuickStateAction &action = actions.at(i);
        d << "\n" << ind.constData() << "target:" << action.property.object() << "property:" << action.property.name()
          << "from:" << action.fromValue << "to:" << action.toValue;
    }
}

QQuickStateActions QQuickPropertyAnimation::createTransitionActions(QQuickStateActions &actions,
                                                                                QQmlProperties &modified,
                                                                                QObject *defaultTarget)
{
    Q_D(QQuickPropertyAnimation);
    QQuickStateActions newActions;

    QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(','));
    for (int ii = 0; ii < props.count(); ++ii)
        props[ii] = props.at(ii).trimmed();
    if (!d->propertyName.isEmpty())
        props << d->propertyName;

    QList<QObject*> targets = d->targets;
    if (d->target)
        targets.append(d->target);

    bool hasSelectors = !props.isEmpty() || !targets.isEmpty() || !d->exclude.isEmpty();
    bool useType = (props.isEmpty() && d->defaultToInterpolatorType) ? true : false;

    if (d->defaultProperty.isValid() && !hasSelectors) {
        props << d->defaultProperty.name();
        targets << d->defaultProperty.object();
    }

    if (defaultTarget && targets.isEmpty())
        targets << defaultTarget;

    bool usingDefaultProperties = false;
    if (props.isEmpty() && !d->defaultProperties.isEmpty()) {
        props << d->defaultProperties.split(QLatin1Char(','));
        usingDefaultProperties = true;
    }

    bool hasExplicit = false;
    //an explicit animation has been specified
    if (d->toIsDefined) {
        QVector<QString> errorMessages;
        bool successfullyCreatedDefaultProperty = false;

        for (int i = 0; i < props.count(); ++i) {
            for (int j = 0; j < targets.count(); ++j) {
                QQuickStateAction myAction;
                QString errorMessage;
                const QString &propertyName = props.at(i);
                myAction.property = d->createProperty(targets.at(j), propertyName, this, &errorMessage);
                if (myAction.property.isValid()) {
                    if (usingDefaultProperties)
                        successfullyCreatedDefaultProperty = true;

                    if (d->fromIsDefined) {
                        myAction.fromValue = d->from;
                        d->convertVariant(myAction.fromValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
                    }
                    myAction.toValue = d->to;
                    d->convertVariant(myAction.toValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
                    newActions << myAction;
                    hasExplicit = true;
                    for (int ii = 0; ii < actions.count(); ++ii) {
                        QQuickStateAction &action = actions[ii];
                        if (action.property.object() == myAction.property.object() &&
                            myAction.property.name() == action.property.name()) {
                            modified << action.property;
                            break;  //### any chance there could be multiples?
                        }
                    }
                } else {
                    errorMessages.append(errorMessage);
                }
            }
        }

        if (!successfullyCreatedDefaultProperty) {
            for (const QString &errorMessage : qAsConst(errorMessages))
                qmlWarning(this) << errorMessage;
        }
    }

    if (!hasExplicit)
    for (int ii = 0; ii < actions.count(); ++ii) {
        QQuickStateAction &action = actions[ii];

        QObject *obj = action.property.object();
        QString propertyName = action.property.name();
        QObject *sObj = action.specifiedObject;
        QString sPropertyName = action.specifiedProperty;
        bool same = (obj == sObj);

        if ((targets.isEmpty() || targets.contains(obj) || (!same && targets.contains(sObj))) &&
           (!d->exclude.contains(obj)) && (same || (!d->exclude.contains(sObj))) &&
           (props.contains(propertyName) || (!same && props.contains(sPropertyName))
               || (useType && action.property.propertyType() == d->interpolatorType))) {
            QQuickStateAction myAction = action;

            if (d->fromIsDefined)
                myAction.fromValue = d->from;
            else
                myAction.fromValue = QVariant();
            if (d->toIsDefined)
                myAction.toValue = d->to;

            d->convertVariant(myAction.fromValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
            d->convertVariant(myAction.toValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());

            modified << action.property;

            newActions << myAction;
            action.fromValue = myAction.toValue;
        }
    }
    return newActions;
}

QAbstractAnimationJob* QQuickPropertyAnimation::transition(QQuickStateActions &actions,
                                                                     QQmlProperties &modified,
                                                                     TransitionDirection direction,
                                                                     QObject *defaultTarget)
{
    Q_D(QQuickPropertyAnimation);

    QQuickStateActions dataActions = createTransitionActions(actions, modified, defaultTarget);

    QQuickBulkValueAnimator *animator = new QQuickBulkValueAnimator;
    animator->setDuration(d->duration);
    animator->setEasingCurve(d->easing);

    if (!dataActions.isEmpty()) {
        QQuickAnimationPropertyUpdater *data = new QQuickAnimationPropertyUpdater;
        data->interpolatorType = d->interpolatorType;
        data->interpolator = d->interpolator;
        data->reverse = direction == Backward ? true : false;
        data->fromIsSourced = false;
        data->fromIsDefined = d->fromIsDefined;
        data->actions = dataActions;
        animator->setAnimValue(data);
        animator->setFromIsSourcedValue(&data->fromIsSourced);
        d->actions = &data->actions; //remove this?
    }

    return initInstance(animator);
}

QQuickAnimationPropertyUpdater::~QQuickAnimationPropertyUpdater()
{
    if (wasDeleted) *wasDeleted = true;
}

QT_END_NAMESPACE

#include "moc_qquickanimation_p.cpp"