summaryrefslogtreecommitdiff
path: root/src/declarative/graphicsitems/qmlgraphicsitem.cpp
blob: 070c70fd2d660de3a6f75cdd32f78af83d7c286d (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
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qmlgraphicsitem_p.h"
#include "qmlgraphicsitem.h"

#include "qmlgraphicsevents_p_p.h"

#include <qfxperf_p_p.h>
#include <qmlengine.h>
#include <qmlopenmetaobject_p.h>
#include <qmlstate_p.h>
#include <qmlview.h>
#include <qmlstategroup_p.h>
#include <qmlcomponent.h>

#include <QDebug>
#include <QPen>
#include <QFile>
#include <QEvent>
#include <QGraphicsSceneMouseEvent>
#include <QtCore/qnumeric.h>
#include <QtScript/qscriptengine.h>
#include <QtGui/qgraphicstransform.h>
#include <QtGui/qgraphicseffect.h>
#include <qlistmodelinterface_p.h>

QT_BEGIN_NAMESPACE

#ifndef FLT_MAX
#define FLT_MAX 1E+37
#endif

#include "qmlgraphicseffects.cpp"

/*!
    \qmlclass Transform QGraphicsTransform
    \brief The Transform elements provide a way of building advanced transformations on Items.

    The Transform elements let you create and control advanced transformations that can be configured
    independently using specialized properties.

    You can assign any number of Transform elements to an Item. Each Transform is applied in order,
    one at a time, to the Item it's assigned to.

    \sa Rotation, Scale
*/

/*!
    \qmlclass Scale QGraphicsScale
    \brief The Scale object provides a way to scale an Item.

    The Scale object gives more control over scaling than using Item's scale property. Specifically,
    it allows a different scale for the x and y axes, and allows the scale to be relative to an
    arbitrary point.

    The following example scales the X axis of the Rectangle, relative to its interior point 25, 25:
    \qml
    Rectangle {
        width: 100; height: 100
        color: "blue"
        transform: Scale { origin.x: 25; origin.y: 25; xScale: 3}
    }
    \endqml
*/

/*!
    \qmlproperty real Scale::origin.x
    \qmlproperty real Scale::origin.y

    The point that the item is scaled from (i.e., the point that stays fixed relative to the parent as
    the rest of the item grows). By default the origin is 0, 0.
*/

/*!
    \qmlproperty real Scale::xScale

    The scaling factor for the X axis.
*/

/*!
    \qmlproperty real Scale::yScale

    The scaling factor for the Y axis.
*/

/*!
    \qmlclass Rotation QGraphicsRotation
    \brief The Rotation object provides a way to rotate an Item.

    The Rotation object gives more control over rotation than using Item's rotation property.
    Specifically, it allows (z axis) rotation to be relative to an arbitrary point.

    The following example rotates a Rectangle around its interior point 25, 25:
    \qml
    Rectangle {
        width: 100; height: 100
        color: "blue"
        transform: Rotation { origin.x: 25; origin.y: 25; angle: 45}
    }
    \endqml

    Rotation also provides a way to specify 3D-like rotations for Items. For these types of
    rotations you must specify the axis to rotate around in addition to the origin point.

    The following example shows various 3D-like rotations applied to an \l Image.
    \snippet doc/src/snippets/declarative/rotation.qml 0

    \image axisrotation.png
*/

/*!
    \qmlproperty real Rotation::origin.x
    \qmlproperty real Rotation::origin.y

    The origin point of the rotation (i.e., the point that stays fixed relative to the parent as
    the rest of the item rotates). By default the origin is 0, 0.
*/

/*!
    \qmlproperty real Rotation::axis.x
    \qmlproperty real Rotation::axis.y
    \qmlproperty real Rotation::axis.z

    The axis to rotate around. For simple (2D) rotation around a point, you do not need to specify an axis,
    as the default axis is the z axis (\c{ axis { x: 0; y: 0; z: 1 } }).

    For a typical 3D-like rotation you will usually specify both the origin and the axis.

    \image 3d-rotation-axis.png
*/

/*!
    \qmlproperty real Rotation::angle

    The angle to rotate, in degrees clockwise.
*/


/*!
    \group group_animation
    \title Animation
*/

/*!
    \group group_coreitems
    \title Basic Items
*/

/*!
    \group group_effects
    \title Effects
*/

/*!
    \group group_layouts
    \title Layouts
*/

/*!
    \group group_states
    \title States and Transitions
*/

/*!
    \group group_utility
    \title Utility
*/

/*!
    \group group_views
    \title Views
*/

/*!
    \group group_widgets
    \title Widgets
*/

/*!
    \internal
    \class QmlGraphicsContents
    \ingroup group_utility
    \brief The QmlGraphicsContents class gives access to the height and width of an item's contents.

*/

QmlGraphicsContents::QmlGraphicsContents() : m_x(0), m_y(0), m_width(0), m_height(0)
{
}

/*!
    \qmlproperty real Item::childrenRect.x
    \qmlproperty real Item::childrenRect.y
    \qmlproperty real Item::childrenRect.width
    \qmlproperty real Item::childrenRect.height

    The childrenRect properties allow an item access to the geometry of its
    children. This property is useful if you have an item that needs to be
    sized to fit its children.
*/

QRectF QmlGraphicsContents::rectF() const
{
    return QRectF(m_x, m_y, m_width, m_height);
}

//TODO: optimization: only check sender(), if there is one
void QmlGraphicsContents::calcHeight()
{
    qreal oldy = m_y;
    qreal oldheight = m_height;

    qreal top = FLT_MAX;
    qreal bottom = 0;

    QList<QGraphicsItem *> children = m_item->childItems();
    for (int i = 0; i < children.count(); ++i) {
        QmlGraphicsItem *child = qobject_cast<QmlGraphicsItem *>(children.at(i));
        if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects?
            continue;
        qreal y = child->y();
        if (y + child->height() > bottom)
            bottom = y + child->height();
        if (y < top)
            top = y;
    }
    if (!children.isEmpty())
        m_y = top;
    m_height = qMax(bottom - top, qreal(0.0));

    if (m_height != oldheight || m_y != oldy)
        emit rectChanged();
}

//TODO: optimization: only check sender(), if there is one
void QmlGraphicsContents::calcWidth()
{
    qreal oldx = m_x;
    qreal oldwidth = m_width;

    qreal left = FLT_MAX;
    qreal right = 0;

    QList<QGraphicsItem *> children = m_item->childItems();
    for (int i = 0; i < children.count(); ++i) {
        QmlGraphicsItem *child = qobject_cast<QmlGraphicsItem *>(children.at(i));
        if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects?
            continue;
        qreal x = child->x();
        if (x + child->width() > right)
            right = x + child->width();
        if (x < left)
            left = x;
    }
    if (!children.isEmpty())
        m_x = left;
    m_width = qMax(right - left, qreal(0.0));

    if (m_width != oldwidth || m_x != oldx)
        emit rectChanged();
}

void QmlGraphicsContents::setItem(QmlGraphicsItem *item)
{
    m_item = item;

    QList<QGraphicsItem *> children = m_item->childItems();
    for (int i = 0; i < children.count(); ++i) {
        QmlGraphicsItem *child = qobject_cast<QmlGraphicsItem *>(children.at(i));
        if(!child)//### Should this be ignoring non-QmlGraphicsItem graphicsobjects?
            continue;
        connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight()));
        connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight()));
        connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth()));
        connect(child, SIGNAL(xChanged()), this, SLOT(calcWidth()));
        connect(this, SIGNAL(rectChanged()), m_item, SIGNAL(childrenRectChanged()));
    }

    calcHeight();
    calcWidth();
}

QmlGraphicsItemKeyFilter::QmlGraphicsItemKeyFilter(QmlGraphicsItem *item)
: m_next(0)
{
    QmlGraphicsItemPrivate *p =
        item?static_cast<QmlGraphicsItemPrivate *>(QGraphicsItemPrivate::get(item)):0;
    if (p) {
        m_next = p->keyHandler;
        p->keyHandler = this;
    }
}

QmlGraphicsItemKeyFilter::~QmlGraphicsItemKeyFilter()
{
}

void QmlGraphicsItemKeyFilter::keyPressed(QKeyEvent *event)
{
    if (m_next) m_next->keyPressed(event);
}

void QmlGraphicsItemKeyFilter::keyReleased(QKeyEvent *event)
{
    if (m_next) m_next->keyReleased(event);
}

void QmlGraphicsItemKeyFilter::inputMethodEvent(QInputMethodEvent *event)
{
    if (m_next) m_next->inputMethodEvent(event);
}

QVariant QmlGraphicsItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query) const
{
    if (m_next) return m_next->inputMethodQuery(query);
    return QVariant();
}

void QmlGraphicsItemKeyFilter::componentComplete()
{
    if (m_next) m_next->componentComplete();
}


/*!
    \qmlclass KeyNavigation
    \brief The KeyNavigation attached property supports key navigation by arrow keys.

    It is common in key-based UIs to use arrow keys to navigate
    between focussed items.  The KeyNavigation property provides a
    convenient way of specifying which item will gain focus
    when an arrow key is pressed.  The following example provides
    key navigation for a 2x2 grid of items.

    \code
    Grid {
        columns: 2
        width: 100; height: 100
        Rectangle {
            id: item1
            focus: true
            width: 50; height: 50
            color: focus ? "red" : "lightgray"
            KeyNavigation.right: item2
            KeyNavigation.down: item3
        }
        Rectangle {
            id: item2
            width: 50; height: 50
            color: focus ? "red" : "lightgray"
            KeyNavigation.left: item1
            KeyNavigation.down: item4
        }
        Rectangle {
            id: item3
            width: 50; height: 50
            color: focus ? "red" : "lightgray"
            KeyNavigation.right: item4
            KeyNavigation.up: item1
        }
        Rectangle {
            id: item4
            width: 50; height: 50
            color: focus ? "red" : "lightgray"
            KeyNavigation.left: item3
            KeyNavigation.up: item2
        }
    }
    \endcode

    KeyNavigation receives key events after the item it is attached to.
    If the item accepts an arrow key event, the KeyNavigation
    attached property will not receive an event for that key.

    If an item has been set for a direction and the KeyNavigation
    attached property receives the corresponding
    key press and release events, the events will be accepted by
    KeyNaviagtion and will not propagate any further.

    \sa {Keys}{Keys attached property}
*/

/*!
    \qmlproperty Item KeyNavigation::left
    \qmlproperty Item KeyNavigation::right
    \qmlproperty Item KeyNavigation::up
    \qmlproperty Item KeyNavigation::down

    These properties hold the item to assign focus to
    when Key_Left, Key_Right, Key_Up or Key_Down are
    pressed.
*/

QmlGraphicsKeyNavigationAttached::QmlGraphicsKeyNavigationAttached(QObject *parent)
: QObject(*(new QmlGraphicsKeyNavigationAttachedPrivate), parent),
  QmlGraphicsItemKeyFilter(qobject_cast<QmlGraphicsItem*>(parent))
{
}

QmlGraphicsKeyNavigationAttached *
QmlGraphicsKeyNavigationAttached::qmlAttachedProperties(QObject *obj)
{
    return new QmlGraphicsKeyNavigationAttached(obj);
}

QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::left() const
{
    Q_D(const QmlGraphicsKeyNavigationAttached);
    return d->left;
}

void QmlGraphicsKeyNavigationAttached::setLeft(QmlGraphicsItem *i)
{
    Q_D(QmlGraphicsKeyNavigationAttached);
    d->left = i;
    emit changed();
}

QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::right() const
{
    Q_D(const QmlGraphicsKeyNavigationAttached);
    return d->right;
}

void QmlGraphicsKeyNavigationAttached::setRight(QmlGraphicsItem *i)
{
    Q_D(QmlGraphicsKeyNavigationAttached);
    d->right = i;
    emit changed();
}

QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::up() const
{
    Q_D(const QmlGraphicsKeyNavigationAttached);
    return d->up;
}

void QmlGraphicsKeyNavigationAttached::setUp(QmlGraphicsItem *i)
{
    Q_D(QmlGraphicsKeyNavigationAttached);
    d->up = i;
    emit changed();
}

QmlGraphicsItem *QmlGraphicsKeyNavigationAttached::down() const
{
    Q_D(const QmlGraphicsKeyNavigationAttached);
    return d->down;
}

void QmlGraphicsKeyNavigationAttached::setDown(QmlGraphicsItem *i)
{
    Q_D(QmlGraphicsKeyNavigationAttached);
    d->down = i;
    emit changed();
}

void QmlGraphicsKeyNavigationAttached::keyPressed(QKeyEvent *event)
{
    Q_D(QmlGraphicsKeyNavigationAttached);

    event->ignore();

    switch(event->key()) {
    case Qt::Key_Left:
        if (d->left) {
            d->left->setFocus(true);
            event->accept();
        }
        break;
    case Qt::Key_Right:
        if (d->right) {
            d->right->setFocus(true);
            event->accept();
        }
        break;
    case Qt::Key_Up:
        if (d->up) {
            d->up->setFocus(true);
            event->accept();
        }
        break;
    case Qt::Key_Down:
        if (d->down) {
            d->down->setFocus(true);
            event->accept();
        }
        break;
    default:
        break;
    }

    if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyPressed(event);
}

void QmlGraphicsKeyNavigationAttached::keyReleased(QKeyEvent *event)
{
    Q_D(QmlGraphicsKeyNavigationAttached);

    event->ignore();

    switch(event->key()) {
    case Qt::Key_Left:
        if (d->left) {
            event->accept();
        }
        break;
    case Qt::Key_Right:
        if (d->right) {
            event->accept();
        }
        break;
    case Qt::Key_Up:
        if (d->up) {
            event->accept();
        }
        break;
    case Qt::Key_Down:
        if (d->down) {
            event->accept();
        }
        break;
    default:
        break;
    }

    if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyReleased(event);
}

/*!
    \qmlclass Keys
    \brief The Keys attached property provides key handling to Items.

    All visual primitives support key handling via the \e Keys
    attached property.  Keys can be handled via the \e onPressed
    and \e onReleased signal properties.

    The signal properties have a \l KeyEvent parameter, named
    \e event which contains details of the event.  If a key is
    handled \e event.accepted should be set to true to prevent the
    event from propagating up the item heirarchy.

    \code
    Item {
        focus: true
        Keys.onPressed: {
            if (event.key == Qt.Key_Left) {
                console.log("move left");
                event.accepted = true;
            }
        }
    }
    \endcode

    Some keys may alternatively be handled via specific signal properties,
    for example \e onSelectPressed.  These handlers automatically set
    \e event.accepted to true.

    \code
    Item {
        focus: true
        Keys.onLeftPressed: console.log("move left")
    }
    \endcode

    See \l {Qt::Key}{Qt.Key} for the list of keyboard codes.

    \sa KeyEvent, {KeyNavigation}{KeyNavigation attached property}
*/

/*!
    \qmlproperty bool Keys::enabled

    This flags enables key handling if true (default); otherwise
    no key handlers will be called.
*/

/*!
    \qmlproperty List<Object> Keys::forwardTo

    This property provides a way to forward key presses, key releases, and keyboard input
    coming from input methods to other items. This can be useful when you want
    one item to handle some keys (e.g. the up and down arrow keys), and another item to
    handle other keys (e.g. the left and right arrow keys).  Once an item that has been
    forwarded keys accepts the event it is no longer forwarded to items later in the
    list.

    This example forwards key events to two lists:
    \qml
    ListView { id: list1 ... }
    ListView { id: list2 ... }
    Keys.forwardTo: [list1, list2]
    focus: true
    \endqml
*/

/*!
    \qmlsignal Keys::onPressed(event)

    This handler is called when a key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onReleased(event)

    This handler is called when a key has been released. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDigit0Pressed(event)

    This handler is called when the digit '0' has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDigit1Pressed(event)

    This handler is called when the digit '1' has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDigit2Pressed(event)

    This handler is called when the digit '2' has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDigit3Pressed(event)

    This handler is called when the digit '3' has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDigit4Pressed(event)

    This handler is called when the digit '4' has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDigit5Pressed(event)

    This handler is called when the digit '5' has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDigit6Pressed(event)

    This handler is called when the digit '6' has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDigit7Pressed(event)

    This handler is called when the digit '7' has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDigit8Pressed(event)

    This handler is called when the digit '8' has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDigit9Pressed(event)

    This handler is called when the digit '9' has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onLeftPressed(event)

    This handler is called when the Left arrow has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onRightPressed(event)

    This handler is called when the Right arrow has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onUpPressed(event)

    This handler is called when the Up arrow has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDownPressed(event)

    This handler is called when the Down arrow has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onAsteriskPressed(event)

    This handler is called when the Asterisk '*' has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onEscapePressed(event)

    This handler is called when the Escape key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onReturnPressed(event)

    This handler is called when the Return key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onEnterPressed(event)

    This handler is called when the Enter key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onDeletePressed(event)

    This handler is called when the Delete key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onSpacePressed(event)

    This handler is called when the Space key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onBackPressed(event)

    This handler is called when the Back key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onCancelPressed(event)

    This handler is called when the Cancel key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onSelectPressed(event)

    This handler is called when the Select key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onYesPressed(event)

    This handler is called when the Yes key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onNoPressed(event)

    This handler is called when the No key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onContext1Pressed(event)

    This handler is called when the Context1 key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onContext2Pressed(event)

    This handler is called when the Context2 key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onContext3Pressed(event)

    This handler is called when the Context3 key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onContext4Pressed(event)

    This handler is called when the Context4 key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onCallPressed(event)

    This handler is called when the Call key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onHangupPressed(event)

    This handler is called when the Hangup key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onFlipPressed(event)

    This handler is called when the Flip key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onMenuPressed(event)

    This handler is called when the Menu key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onVolumeUpPressed(event)

    This handler is called when the VolumeUp key has been pressed. The \a event
    parameter provides information about the event.
*/

/*!
    \qmlsignal Keys::onVolumeDownPressed(event)

    This handler is called when the VolumeDown key has been pressed. The \a event
    parameter provides information about the event.
*/


const QmlGraphicsKeysAttached::SigMap QmlGraphicsKeysAttached::sigMap[] = {
    { Qt::Key_Left, "leftPressed" },
    { Qt::Key_Right, "rightPressed" },
    { Qt::Key_Up, "upPressed" },
    { Qt::Key_Down, "downPressed" },
    { Qt::Key_Asterisk, "asteriskPressed" },
    { Qt::Key_NumberSign, "numberSignPressed" },
    { Qt::Key_Escape, "escapePressed" },
    { Qt::Key_Return, "returnPressed" },
    { Qt::Key_Enter, "enterPressed" },
    { Qt::Key_Delete, "deletePressed" },
    { Qt::Key_Space, "spacePressed" },
    { Qt::Key_Back, "backPressed" },
    { Qt::Key_Cancel, "cancelPressed" },
    { Qt::Key_Select, "selectPressed" },
    { Qt::Key_Yes, "yesPressed" },
    { Qt::Key_No, "noPressed" },
    { Qt::Key_Context1, "context1Pressed" },
    { Qt::Key_Context2, "context2Pressed" },
    { Qt::Key_Context3, "context3Pressed" },
    { Qt::Key_Context4, "context4Pressed" },
    { Qt::Key_Call, "callPressed" },
    { Qt::Key_Hangup, "hangupPressed" },
    { Qt::Key_Flip, "flipPressed" },
    { Qt::Key_Menu, "menuPressed" },
    { Qt::Key_VolumeUp, "volumeUpPressed" },
    { Qt::Key_VolumeDown, "volumeDownPressed" },
    { 0, 0 }
};

bool QmlGraphicsKeysAttachedPrivate::isConnected(const char *signalName)
{
    return isSignalConnected(signalIndex(signalName));
}

QmlGraphicsKeysAttached::QmlGraphicsKeysAttached(QObject *parent)
: QObject(*(new QmlGraphicsKeysAttachedPrivate), parent),
  QmlGraphicsItemKeyFilter(qobject_cast<QmlGraphicsItem*>(parent))
{
    Q_D(QmlGraphicsKeysAttached);
    d->item = qobject_cast<QmlGraphicsItem*>(parent);
}

QmlGraphicsKeysAttached::~QmlGraphicsKeysAttached()
{
}

void QmlGraphicsKeysAttached::componentComplete()
{
    Q_D(QmlGraphicsKeysAttached);
    if (d->item) {
        for (int ii = 0; ii < d->targets.count(); ++ii) {
            QGraphicsItem *targetItem = d->finalFocusProxy(d->targets.at(ii));
            if (targetItem && (targetItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
                d->item->setFlag(QGraphicsItem::ItemAcceptsInputMethod);
                break;
            }
        }
    }
}

void QmlGraphicsKeysAttached::keyPressed(QKeyEvent *event)
{
    Q_D(QmlGraphicsKeysAttached);
    if (!d->enabled || d->inPress) {
        event->ignore();
        return;
    }

    // first process forwards
    if (d->item && d->item->scene()) {
        d->inPress = true;
        for (int ii = 0; ii < d->targets.count(); ++ii) {
            QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
            if (i) {
                d->item->scene()->sendEvent(i, event);
                if (event->isAccepted()) {
                    d->inPress = false;
                    return;
                }
            }
        }
        d->inPress = false;
    }

    QmlGraphicsKeyEvent ke(*event);
    QByteArray keySignal = keyToSignal(event->key());
    if (!keySignal.isEmpty()) {
        keySignal += "(QmlGraphicsKeyEvent*)";
        if (d->isConnected(keySignal)) {
            // If we specifically handle a key then default to accepted
            ke.setAccepted(true);
            int idx = QmlGraphicsKeysAttached::staticMetaObject.indexOfSignal(keySignal);
            metaObject()->method(idx).invoke(this, Qt::DirectConnection, Q_ARG(QmlGraphicsKeyEvent*, &ke));
        }
    }
    if (!ke.isAccepted())
        emit pressed(&ke);
    event->setAccepted(ke.isAccepted());

    if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyPressed(event);
}

void QmlGraphicsKeysAttached::keyReleased(QKeyEvent *event)
{
    Q_D(QmlGraphicsKeysAttached);
    if (!d->enabled || d->inRelease) {
        event->ignore();
        return;
    }

    if (d->item && d->item->scene()) {
        d->inRelease = true;
        for (int ii = 0; ii < d->targets.count(); ++ii) {
            QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
            if (i) {
                d->item->scene()->sendEvent(i, event);
                if (event->isAccepted()) {
                    d->inRelease = false;
                    return;
                }
            }
        }
        d->inRelease = false;
    }

    QmlGraphicsKeyEvent ke(*event);
    emit released(&ke);
    event->setAccepted(ke.isAccepted());

    if (!event->isAccepted()) QmlGraphicsItemKeyFilter::keyReleased(event);
}

void QmlGraphicsKeysAttached::inputMethodEvent(QInputMethodEvent *event)
{
    Q_D(QmlGraphicsKeysAttached);
    if (d->item && !d->inIM && d->item->scene()) {
        d->inIM = true;
        for (int ii = 0; ii < d->targets.count(); ++ii) {
            QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
            if (i && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
                d->item->scene()->sendEvent(i, event);
                if (event->isAccepted()) {
                    d->imeItem = i;
                    d->inIM = false;
                    return;
                }
            }
        }
        d->inIM = false;
    }
    if (!event->isAccepted()) QmlGraphicsItemKeyFilter::inputMethodEvent(event);
}

class QmlGraphicsItemAccessor : public QGraphicsItem
{
public:
    QVariant doInputMethodQuery(Qt::InputMethodQuery query) const {
        return QGraphicsItem::inputMethodQuery(query);
    }
};

QVariant QmlGraphicsKeysAttached::inputMethodQuery(Qt::InputMethodQuery query) const
{
    Q_D(const QmlGraphicsKeysAttached);
    if (d->item) {
        for (int ii = 0; ii < d->targets.count(); ++ii) {
                QGraphicsItem *i = d->finalFocusProxy(d->targets.at(ii));
            if (i && (i->flags() & QGraphicsItem::ItemAcceptsInputMethod) && i == d->imeItem) { //### how robust is i == d->imeItem check?
                QVariant v = static_cast<QmlGraphicsItemAccessor *>(i)->doInputMethodQuery(query);
                if (v.userType() == QVariant::RectF)
                    v = d->item->mapRectFromItem(i, v.toRectF());  //### cost?
                return v;
            }
        }
    }
    return QmlGraphicsItemKeyFilter::inputMethodQuery(query);
}

QmlGraphicsKeysAttached *QmlGraphicsKeysAttached::qmlAttachedProperties(QObject *obj)
{
    return new QmlGraphicsKeysAttached(obj);
}

/*!
    \class QmlGraphicsItem
    \brief The QmlGraphicsItem class provides the most basic of all visual items in QML.

    All visual items in Qt Declarative inherit from QmlGraphicsItem.  Although QmlGraphicsItem
    has no visual appearance, it defines all the properties that are
    common across visual items - such as the x and y position, the
    width and height, \l {anchor-layout}{anchoring} and key handling.

    You can subclass QmlGraphicsItem to provide your own custom visual item that inherits
    these features.
*/

/*!
    \qmlclass Item QmlGraphicsItem
    \brief The Item is the most basic of all visual items in QML.

    All visual items in Qt Declarative inherit from Item.  Although Item
    has no visual appearance, it defines all the properties that are
    common across visual items - such as the x and y position, the
    width and height, \l {anchor-layout}{anchoring} and key handling.

    Item is also useful for grouping items together.

    \qml
    Item {
        Image {
            source: "tile.png"
        }
        Image {
            x: 80
            width: 100
            height: 100
            source: "tile.png"
        }
        Image {
            x: 190
            width: 100
            height: 100
            fillMode: Image.Tile
            source: "tile.png"
        }
    }
    \endqml

    \section1 Identity

    Each item has an "id" - the identifier of the Item.

    The identifier can be used in bindings and other expressions to
    refer to the item. For example:

    \qml
    Text { id: myText; ... }
    Text { text: myText.text }
    \endqml

    The identifier is available throughout to the \l {components}{component}
    where it is declared.  The identifier must be unique in the component.

    The id should not be thought of as a "property" - it makes no sense
    to write \c myText.id, for example.

    \section1 Key Handling

    Key handling is available to all Item-based visual elements via the \l {Keys}{Keys}
    attached property.  The \e Keys attached property provides basic handlers such
    as \l {Keys::onPressed}{onPressed} and \l {Keys::onReleased}{onReleased},
    as well as handlers for specific keys, such as
    \l {Keys::onCancelPressed}{onCancelPressed}.  The example below
    assigns \l {qmlfocus}{focus} to the item and handles
    the Left key via the general \e onPressed handler and the Select key via the
    onSelectPressed handler:

    \qml
    Item {
        focus: true
        Keys.onPressed: {
            if (event.key == Qt.Key_Left) {
                console.log("move left");
                event.accepted = true;
            }
        }
        Keys.onSelectPressed: console.log("Selected");
    }
    \endqml

    See the \l {Keys}{Keys} attached property for detailed documentation.

    \ingroup group_coreitems
*/

/*!
    \property QmlGraphicsItem::baseline
    \internal
*/

/*!
    \property QmlGraphicsItem::effect
    \internal
*/

/*!
    \property QmlGraphicsItem::focus
    \internal
*/

/*!
    \property QmlGraphicsItem::wantsFocus
    \internal
*/

/*!
    \property QmlGraphicsItem::transformOrigin
    \internal
*/

/*!
    \fn void QmlGraphicsItem::childrenRectChanged()
    \internal
*/

/*!
    \fn void QmlGraphicsItem::baselineOffsetChanged()
    \internal
*/

/*!
    \fn void QmlGraphicsItem::widthChanged()
    \internal
*/

/*!
    \fn void QmlGraphicsItem::heightChanged()
    \internal
*/

/*!
    \fn void QmlGraphicsItem::stateChanged(const QString &state)
    \internal
*/

/*!
    \fn void QmlGraphicsItem::parentChanged()
    \internal
*/

/*!
    \fn void QmlGraphicsItem::childrenChanged()
    \internal
*/

/*!
    \fn void QmlGraphicsItem::focusChanged()
    \internal
*/

/*!
    \fn void QmlGraphicsItem::wantsFocusChanged()
    \internal
*/

// ### Must fix
struct RegisterAnchorLineAtStartup {
    RegisterAnchorLineAtStartup() {
        qRegisterMetaType<QmlGraphicsAnchorLine>("QmlGraphicsAnchorLine");
    }
};
static RegisterAnchorLineAtStartup registerAnchorLineAtStartup;


/*!
    \fn QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItem *parent)

    Constructs a QmlGraphicsItem with the given \a parent.
*/
QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItem* parent)
  : QGraphicsObject(*(new QmlGraphicsItemPrivate), parent, 0)
{
    Q_D(QmlGraphicsItem);
    d->init(parent);
}

/*! \internal
*/
QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItemPrivate &dd, QmlGraphicsItem *parent)
  : QGraphicsObject(dd, parent, 0)
{
    Q_D(QmlGraphicsItem);
    d->init(parent);
}

/*!
    Destroys the QmlGraphicsItem.
*/
QmlGraphicsItem::~QmlGraphicsItem()
{
    Q_D(QmlGraphicsItem);
    for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
        QmlGraphicsAnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate();
        if (anchor)
            anchor->clearItem(this);
    }
    if (!d->parent || (parentItem() && !parentItem()->QGraphicsItem::d_ptr->inDestructor)) {
        for (int ii = 0; ii < d->changeListeners.count(); ++ii) {
            QmlGraphicsAnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate();
            if (anchor && anchor->item && anchor->item->parentItem() != this) //child will be deleted anyway
                anchor->updateOnComplete();
        }
    }
    for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
        const QmlGraphicsItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
        if (change.types & QmlGraphicsItemPrivate::Destroyed)
            change.listener->itemDestroyed(this);
    }
    d->changeListeners.clear();
    delete d->_anchorLines; d->_anchorLines = 0;
    delete d->_anchors; d->_anchors = 0;
    delete d->_stateGroup; d->_stateGroup = 0;
}

/*!
    \qmlproperty enum Item::transformOrigin
    This property holds the origin point around which scale and rotation transform.

    Nine transform origins are available, as shown in the image below.

    \image declarative-transformorigin.png

    This example rotates an image around its bottom-right corner.
    \qml
    Image {
        source: "myimage.png"
        transformOrigin: Item.BottomRight
        rotate: 45
    }
    \endqml

    The default transform origin is \c Center.
*/

/*!
    \qmlproperty Item Item::parent
    This property holds the parent of the item.
*/

/*!
    \property QmlGraphicsItem::parent
    This property holds the parent of the item.
*/
void QmlGraphicsItem::setParentItem(QmlGraphicsItem *parent)
{
    QmlGraphicsItem *oldParent = parentItem();
    if (parent == oldParent || !parent) return;

    Q_D(QmlGraphicsItem);
    QObject::setParent(parent);
    d->setParentItemHelper(parent, /*newParentVariant=*/0, /*thisPointerVariant=*/0);
    if (oldParent)
        emit oldParent->childrenChanged();
    emit parentChanged();
}

/*!
    \fn void QmlGraphicsItem::setParent(QmlGraphicsItem *parent)
    \overload
    Sets both the parent object and parent item to \a parent. This
    function avoids the programming error of calling setParent()
    when you mean setParentItem().
*/

/*!
    Returns the QmlGraphicsItem parent of this item.
*/
QmlGraphicsItem *QmlGraphicsItem::parentItem() const
{
    return qobject_cast<QmlGraphicsItem *>(QGraphicsObject::parentItem());
}

/*!
    \qmlproperty list<Item> Item::children
    \qmlproperty list<Object> Item::resources

    The children property contains the list of visual children of this item.
    The resources property contains non-visual resources that you want to
    reference by name.

    Generally you can rely on Item's default property to handle all this for
    you, but it can come in handy in some cases.

    \qml
    Item {
        children: [
            Text {},
            Rectangle {}
        ]
        resources: [
            Component {
                id: myComponent
                Text {}
            }
        ]
    }
    \endqml
*/

/*!
    \property QmlGraphicsItem::children
    \internal
*/

/*!
    \property QmlGraphicsItem::resources
    \internal
*/

/*!
    Returns true if construction of the QML component is complete; otherwise
    returns false.

    It is often desireable to delay some processing until the component is
    completed.

    \sa componentComplete()
*/
bool QmlGraphicsItem::isComponentComplete() const
{
    Q_D(const QmlGraphicsItem);
    return d->_componentComplete;
}

/*!
    \property QmlGraphicsItem::anchors
    \internal
*/

/*! \internal */
QmlGraphicsAnchors *QmlGraphicsItem::anchors()
{
    Q_D(QmlGraphicsItem);
    return d->anchors();
}

void QmlGraphicsItemPrivate::data_removeAt(int)
{
    // ###
}

int QmlGraphicsItemPrivate::data_count() const
{
    // ###
    return 0;
}

void QmlGraphicsItemPrivate::data_append(QObject *o)
{
    Q_Q(QmlGraphicsItem);
    QmlGraphicsItem *i = qobject_cast<QmlGraphicsItem *>(o);
    if (i)
        q->fxChildren()->append(i);
    else
        resources_append(o);
}

void QmlGraphicsItemPrivate::data_insert(int, QObject *)
{
    // ###
}

QObject *QmlGraphicsItemPrivate::data_at(int) const
{
    // ###
    return 0;
}

void QmlGraphicsItemPrivate::data_clear()
{
    // ###
}

void QmlGraphicsItemPrivate::resources_removeAt(int)
{
    // ###
}

int QmlGraphicsItemPrivate::resources_count() const
{
    Q_Q(const QmlGraphicsItem);
    return q->children().count();
}

void QmlGraphicsItemPrivate::resources_append(QObject *o)
{
    Q_Q(QmlGraphicsItem);
    o->setParent(q);
}

void QmlGraphicsItemPrivate::resources_insert(int, QObject *)
{
    // ###
}

QObject *QmlGraphicsItemPrivate::resources_at(int idx) const
{
    Q_Q(const QmlGraphicsItem);
    QObjectList children = q->children();
    if (idx < children.count())
        return children.at(idx);
    else
        return 0;
}

void QmlGraphicsItemPrivate::resources_clear()
{
    // ###
}

void QmlGraphicsItemPrivate::children_removeAt(int)
{
    // ###
}

int QmlGraphicsItemPrivate::children_count() const
{
    Q_Q(const QmlGraphicsItem);
    return q->childItems().count();
}

void QmlGraphicsItemPrivate::children_append(QmlGraphicsItem *i)
{
    Q_Q(QmlGraphicsItem);
    i->setParentItem(q);
}

void QmlGraphicsItemPrivate::children_insert(int, QmlGraphicsItem *)
{
    // ###
}

QmlGraphicsItem *QmlGraphicsItemPrivate::children_at(int idx) const
{
    Q_Q(const QmlGraphicsItem);
    QList<QGraphicsItem *> children = q->childItems();
    if (idx < children.count())
        return qobject_cast<QmlGraphicsItem *>(children.at(idx));
    else
        return 0;
}

void QmlGraphicsItemPrivate::children_clear()
{
    // ###
}


void QmlGraphicsItemPrivate::transform_removeAt(int i)
{
    if (!transformData)
        return;
    transformData->graphicsTransforms.removeAt(i);
    dirtySceneTransform = 1;
}

int QmlGraphicsItemPrivate::transform_count() const
{
    return transformData ? transformData->graphicsTransforms.size() : 0;
}

void QmlGraphicsItemPrivate::transform_append(QGraphicsTransform *item)
{
    appendGraphicsTransform(item);
}

void QmlGraphicsItemPrivate::transform_insert(int, QGraphicsTransform *)
{
    // ###
}

QGraphicsTransform *QmlGraphicsItemPrivate::transform_at(int idx) const
{
    if (!transformData)
        return 0;
    return transformData->graphicsTransforms.at(idx);
}

void QmlGraphicsItemPrivate::transform_clear()
{
    if (!transformData)
        return;
    Q_Q(QmlGraphicsItem);
    q->setTransformations(QList<QGraphicsTransform *>());
}

/*!
    \qmlproperty list<Object> Item::data
    \default

    The data property is allows you to freely mix visual children and resources
    of an item.  If you assign a visual item to the data list it becomes
    a child and if you assign any other object type, it is added as a resource.

    So you can write:
    \qml
    Item {
        Text {}
        Rectangle {}
        Script {}
    }
    \endqml

    instead of:
    \qml
    Item {
        children: [
            Text {},
            Rectangle {}
        ]
        resources: [
            Script {}
        ]
    }
    \endqml

    data is a behind-the-scenes property: you should never need to explicitly
    specify it.
 */

/*!
    \property QmlGraphicsItem::data
    \internal
*/

/*! \internal */
QmlList<QObject *> *QmlGraphicsItem::data()
{
    Q_D(QmlGraphicsItem);
    return &d->data;
}

/*!
    \property QmlGraphicsItem::childrenRect
    \brief The geometry of an item's children.

    childrenRect provides an easy way to access the (collective) position and size of the item's children.
*/
QRectF QmlGraphicsItem::childrenRect()
{
    Q_D(QmlGraphicsItem);
    if (!d->_contents) {
        d->_contents = new QmlGraphicsContents;
        d->_contents->setParent(this);
        d->_contents->setItem(this);
    }
    return d->_contents->rectF();
}

bool QmlGraphicsItem::clip() const
{
    return flags() & ItemClipsChildrenToShape;
}

void QmlGraphicsItem::setClip(bool c)
{
    setFlag(ItemClipsChildrenToShape, c);
}

/*!
  \qmlproperty real Item::x
  \qmlproperty real Item::y
  \qmlproperty real Item::width
  \qmlproperty real Item::height

  Defines the item's position and size relative to its parent.

  \qml
  Item { x: 100; y: 100; width: 100; height: 100 }
  \endqml
 */

/*!
  \property QmlGraphicsItem::width

  Defines the item's width relative to its parent.
 */

/*!
  \property QmlGraphicsItem::height

  Defines the item's height relative to its parent.
 */

/*!
  \qmlproperty real Item::z

  Sets the stacking order of the item.  By default the stacking order is 0.

  Items with a higher stacking value are drawn on top of items with a
  lower stacking order.  Items with the same stacking value are drawn
  bottom up in the order they appear.  Items with a negative stacking
  value are drawn under their parent's content.

  The following example shows the various effects of stacking order.

  \table
  \row
  \o \image declarative-item_stacking1.png
  \o Same \c z - later children above earlier children:
  \qml
  Item {
      Rectangle {
          color: "red"
          width: 100; height: 100
      }
      Rectangle {
          color: "blue"
          x: 50; y: 50; width: 100; height: 100
      }
  }
  \endqml
  \row
  \o \image declarative-item_stacking2.png
  \o Higher \c z on top:
  \qml
  Item {
      Rectangle {
          z: 1
          color: "red"
          width: 100; height: 100
      }
      Rectangle {
          color: "blue"
          x: 50; y: 50; width: 100; height: 100
      }
  }
  \endqml
  \row
  \o \image declarative-item_stacking3.png
  \o Same \c z - children above parents:
  \qml
  Item {
      Rectangle {
          color: "red"
          width: 100; height: 100
          Rectangle {
              color: "blue"
              x: 50; y: 50; width: 100; height: 100
          }
      }
  }
  \endqml
  \row
  \o \image declarative-item_stacking4.png
  \o Lower \c z below:
  \qml
  Item {
      Rectangle {
          color: "red"
          width: 100; height: 100
          Rectangle {
              z: -1
              color: "blue"
              x: 50; y: 50; width: 100; height: 100
          }
      }
  }
  \endqml
  \endtable
 */

/*!
    \qmlproperty bool Item::visible

    Whether the item is visible. By default this is true.

    \note visible is not linked to actual visibility; if an item
    moves off screen, or the opacity changes to 0, this will
    not affect the visible property.
*/


/*!
  This function is called to handle this item's changes in
  geometry from \a oldGeometry to \a newGeometry. If the two
  geometries are the same, it doesn't do anything.
 */
void QmlGraphicsItem::geometryChanged(const QRectF &newGeometry,
                              const QRectF &oldGeometry)
{
    Q_D(QmlGraphicsItem);

    if (d->_anchors)
        d->_anchors->d_func()->updateMe();

    if (transformOrigin() != QmlGraphicsItem::TopLeft)
        setTransformOriginPoint(d->computeTransformOrigin());

    if (newGeometry.x() != oldGeometry.x())
        emit xChanged();
    if (newGeometry.width() != oldGeometry.width())
        emit widthChanged();
    if (newGeometry.y() != oldGeometry.y())
        emit yChanged();
    if (newGeometry.height() != oldGeometry.height())
        emit heightChanged();

    for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
        const QmlGraphicsItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
        if (change.types & QmlGraphicsItemPrivate::Geometry)
            change.listener->itemGeometryChanged(this, newGeometry, oldGeometry);
    }
}

void QmlGraphicsItemPrivate::removeItemChangeListener(QmlGraphicsItemChangeListener *listener, ChangeTypes types)
{
    ChangeListener change(listener, types);
    changeListeners.removeOne(change);
}

/*! \internal */
void QmlGraphicsItem::keyPressEvent(QKeyEvent *event)
{
    Q_D(QmlGraphicsItem);
    if (d->keyHandler)
        d->keyHandler->keyPressed(event);
    else
        event->ignore();
}

/*! \internal */
void QmlGraphicsItem::keyReleaseEvent(QKeyEvent *event)
{
    Q_D(QmlGraphicsItem);
    if (d->keyHandler)
        d->keyHandler->keyReleased(event);
    else
        event->ignore();
}

/*! \internal */
void QmlGraphicsItem::inputMethodEvent(QInputMethodEvent *event)
{
    Q_D(QmlGraphicsItem);
    if (d->keyHandler)
        d->keyHandler->inputMethodEvent(event);
    else
        event->ignore();
}

/*! \internal */
QVariant QmlGraphicsItem::inputMethodQuery(Qt::InputMethodQuery query) const
{
    Q_D(const QmlGraphicsItem);
    QVariant v;
    if (d->keyHandler)
        v = d->keyHandler->inputMethodQuery(query);

    if (!v.isValid())
        v = QGraphicsObject::inputMethodQuery(query);

    return v;
}

/*!
    \internal
*/
QmlGraphicsAnchorLine QmlGraphicsItem::left() const
{
    Q_D(const QmlGraphicsItem);
    return d->anchorLines()->left;
}

/*!
    \internal
*/
QmlGraphicsAnchorLine QmlGraphicsItem::right() const
{
    Q_D(const QmlGraphicsItem);
    return d->anchorLines()->right;
}

/*!
    \internal
*/
QmlGraphicsAnchorLine QmlGraphicsItem::horizontalCenter() const
{
    Q_D(const QmlGraphicsItem);
    return d->anchorLines()->hCenter;
}

/*!
    \internal
*/
QmlGraphicsAnchorLine QmlGraphicsItem::top() const
{
    Q_D(const QmlGraphicsItem);
    return d->anchorLines()->top;
}

/*!
    \internal
*/
QmlGraphicsAnchorLine QmlGraphicsItem::bottom() const
{
    Q_D(const QmlGraphicsItem);
    return d->anchorLines()->bottom;
}

/*!
    \internal
*/
QmlGraphicsAnchorLine QmlGraphicsItem::verticalCenter() const
{
    Q_D(const QmlGraphicsItem);
    return d->anchorLines()->vCenter;
}


/*!
    \internal
*/
QmlGraphicsAnchorLine QmlGraphicsItem::baseline() const
{
    Q_D(const QmlGraphicsItem);
    return d->anchorLines()->baseline;
}

/*!
  \property QmlGraphicsItem::top
  \internal
*/

/*!
  \property QmlGraphicsItem::bottom
  \internal
*/

/*!
  \property QmlGraphicsItem::left
  \internal
*/

/*!
  \property QmlGraphicsItem::right
  \internal
*/

/*!
  \property QmlGraphicsItem::horizontalCenter
  \internal
*/

/*!
  \property QmlGraphicsItem::verticalCenter
  \internal
*/

/*!
  \qmlproperty AnchorLine Item::top
  \qmlproperty AnchorLine Item::bottom
  \qmlproperty AnchorLine Item::left
  \qmlproperty AnchorLine Item::right
  \qmlproperty AnchorLine Item::horizontalCenter
  \qmlproperty AnchorLine Item::verticalCenter
  \qmlproperty AnchorLine Item::baseline

  The anchor lines of the item.

  For more information see \l {anchor-layout}{Anchor Layouts}.
*/

/*!
  \qmlproperty AnchorLine Item::anchors.top
  \qmlproperty AnchorLine Item::anchors.bottom
  \qmlproperty AnchorLine Item::anchors.left
  \qmlproperty AnchorLine Item::anchors.right
  \qmlproperty AnchorLine Item::anchors.horizontalCenter
  \qmlproperty AnchorLine Item::anchors.verticalCenter
  \qmlproperty AnchorLine Item::anchors.baseline

  \qmlproperty Item Item::anchors.fill
  \qmlproperty Item Item::anchors.centerIn

  \qmlproperty real Item::anchors.margins
  \qmlproperty real Item::anchors.topMargin
  \qmlproperty real Item::anchors.bottomMargin
  \qmlproperty real Item::anchors.leftMargin
  \qmlproperty real Item::anchors.rightMargin
  \qmlproperty real Item::anchors.horizontalCenterOffset
  \qmlproperty real Item::anchors.verticalCenterOffset
  \qmlproperty real Item::anchors.baselineOffset

  Anchors provide a way to position an item by specifying its
  relationship with other items.

  Margins apply to top, bottom, left, right, and fill anchors.
  The margins property can be used to set all of the various margins at once, to the same value.

  Offsets apply for horizontal center, vertical center, and baseline anchors.

  \table
  \row
  \o \image declarative-anchors_example.png
  \o Text anchored to Image, horizontally centered and vertically below, with a margin.
  \qml
  Image { id: pic; ... }
  Text {
      id: label
      anchors.horizontalCenter: pic.horizontalCenter
      anchors.top: pic.bottom
      anchors.topMargin: 5
      ...
  }
  \endqml
  \row
  \o \image declarative-anchors_example2.png
  \o
  Left of Text anchored to right of Image, with a margin. The y
  property of both defaults to 0.

  \qml
    Image { id: pic; ... }
    Text {
        id: label
        anchors.left: pic.right
        anchors.leftMargin: 5
        ...
    }
  \endqml
  \endtable

  anchors.fill provides a convenient way for one item to have the
  same geometry as another item, and is equivalent to connecting all
  four directional anchors.

  \note You can only anchor an item to siblings or a parent.

  For more information see \l {anchor-layout}{Anchor Layouts}.
*/

/*!
  \property QmlGraphicsItem::baselineOffset
  \brief The position of the item's baseline in local coordinates.

  The baseline of a Text item is the imaginary line on which the text
  sits. Controls containing text usually set their baseline to the
  baseline of their text.

  For non-text items, a default baseline offset of 0 is used.
*/
qreal QmlGraphicsItem::baselineOffset() const
{
    Q_D(const QmlGraphicsItem);
    if (!d->_baselineOffset.isValid()) {
        return 0.0;
    } else
        return d->_baselineOffset;
}

void QmlGraphicsItem::setBaselineOffset(qreal offset)
{
    Q_D(QmlGraphicsItem);
    if (offset == d->_baselineOffset)
        return;

    d->_baselineOffset = offset;
    emit baselineOffsetChanged();

    for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
        const QmlGraphicsItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
        if (change.types & QmlGraphicsItemPrivate::Geometry) {
            QmlGraphicsAnchorsPrivate *anchor = change.listener->anchorPrivate();
            if (anchor)
                anchor->updateVerticalAnchors();
        }
    }
}

/*!
  \qmlproperty real Item::rotation
  This property holds the rotation of the item in degrees clockwise.

  This specifies how many degrees to rotate the item around its transformOrigin.
  The default rotation is 0 degrees (i.e. not rotated at all).

  \table
  \row
  \o \image declarative-rotation.png
  \o
  \qml
  Rectangle {
      color: "blue"
      width: 100; height: 100
      Rectangle {
          color: "green"
          width: 25; height: 25
      }
      Rectangle {
          color: "red"
          x: 25; y: 25; width: 50; height: 50
          rotation: 30
      }
  }
  \endqml
  \endtable
*/

/*!
  \qmlproperty real Item::scale
  This property holds the scale of the item.

  A scale of less than 1 means the item will be displayed smaller than
  normal, and a scale of greater than 1 means the item will be
  displayed larger than normal.  A negative scale means the item will
  be mirrored.

  By default, items are displayed at a scale of 1 (i.e. at their
  normal size).

  Scaling is from the item's transformOrigin.

  \table
  \row
  \o \image declarative-scale.png
  \o
  \qml
  Rectangle {
      color: "blue"
      width: 100; height: 100
      Rectangle {
          color: "green"
          width: 25; height: 25
      }
      Rectangle {
          color: "red"
          x: 25; y: 25; width: 50; height: 50
          scale: 1.4
      }
  }
  \endqml
  \endtable
*/

/*!
  \qmlproperty real Item::opacity

  The opacity of the item.  Opacity is specified as a number between 0
  (fully transparent) and 1 (fully opaque).  The default is 1.

  Opacity is an \e inherited attribute.  That is, the opacity is
  also applied individually to child items.  In almost all cases this
  is what you want.  If you can spot the issue in the following
  example, you might need to use an \l Opacity effect instead.

  \table
  \row
  \o \image declarative-item_opacity1.png
  \o
  \qml
    Item {
        Rectangle {
            color: "red"
            width: 100; height: 100
            Rectangle {
                color: "blue"
                x: 50; y: 50; width: 100; height: 100
            }
        }
    }
  \endqml
  \row
  \o \image declarative-item_opacity2.png
  \o
  \qml
    Item {
        Rectangle {
            opacity: 0.5
            color: "red"
            width: 100; height: 100
            Rectangle {
                color: "blue"
                x: 50; y: 50; width: 100; height: 100
            }
        }
    }
  \endqml
  \endtable
*/

/*!
  Returns a value indicating whether mouse input should
  remain with this item exclusively.

  \sa setKeepMouseGrab()
 */
bool QmlGraphicsItem::keepMouseGrab() const
{
    Q_D(const QmlGraphicsItem);
    return d->_keepMouse;
}

/*!
  The flag indicating whether the mouse should remain
  with this item is set to \a keep.

  This is useful for items that wish to grab and keep mouse
  interaction following a predefined gesture.  For example,
  an item that is interested in horizontal mouse movement
  may set keepMouseGrab to true once a threshold has been
  exceeded.  Once keepMouseGrab has been set to true, filtering
  items will not react to mouse events.

  If the item does not indicate that it wishes to retain mouse grab,
  a filtering item may steal the grab. For example, Flickable may attempt
  to steal a mouse grab if it detects that the user has begun to
  move the viewport.

  \sa keepMouseGrab()
 */
void QmlGraphicsItem::setKeepMouseGrab(bool keep)
{
    Q_D(QmlGraphicsItem);
    d->_keepMouse = keep;
}

/*!
  \internal

  This function emits the \e focusChanged signal.

  Subclasses overriding this function should call up
  to their base class.
*/
void QmlGraphicsItem::focusChanged(bool flag)
{
    Q_UNUSED(flag);
    emit focusChanged();
}

/*! \internal */
QmlList<QmlGraphicsItem *> *QmlGraphicsItem::fxChildren()
{
    Q_D(QmlGraphicsItem);
    return &(d->children);
}

/*! \internal */
QmlList<QObject *> *QmlGraphicsItem::resources()
{
    Q_D(QmlGraphicsItem);
    return &(d->resources);
}

/*!
  \qmlproperty list<State> Item::states
  This property holds a list of states defined by the item.

  \qml
  Item {
    states: [
      State { ... },
      State { ... }
      ...
    ]
  }
  \endqml

  \sa {qmlstate}{States}
*/

/*!
  \property QmlGraphicsItem::states
  \internal
*/
/*! \internal */
QmlList<QmlState *>* QmlGraphicsItem::states()
{
    Q_D(QmlGraphicsItem);
    return d->states()->statesProperty();
}

/*!
  \qmlproperty list<Transition> Item::transitions
  This property holds a list of transitions defined by the item.

  \qml
  Item {
    transitions: [
      Transition { ... },
      Transition { ... }
      ...
    ]
  }
  \endqml

  \sa {state-transitions}{Transitions}
*/

/*!
  \property QmlGraphicsItem::transitions
  \internal
*/

/*! \internal */
QmlList<QmlTransition *>* QmlGraphicsItem::transitions()
{
    Q_D(QmlGraphicsItem);
    return d->states()->transitionsProperty();
}

/*
  \qmlproperty list<Filter> Item::filter
  This property holds a list of graphical filters to be applied to the item.

  \l {Filter}{Filters} include things like \l {Blur}{blurring}
  the item, or giving it a \l Reflection.  Some
  filters may not be available on all canvases; if a filter is not
  available on a certain canvas, it will simply not be applied for
  that canvas (but the QML will still be considered valid).

  \qml
  Item {
    filter: [
      Blur { ... },
      Relection { ... }
      ...
    ]
  }
  \endqml
*/

/*!
  \qmlproperty bool Item::clip
  This property holds whether clipping is enabled.

  if clipping is enabled, an item will clip its own painting, as well
  as the painting of its children, to its bounding rectangle.

  Non-rectangular clipping regions are not supported for performance reasons.
*/

/*!
  \property QmlGraphicsItem::clip
  This property holds whether clipping is enabled.

  if clipping is enabled, an item will clip its own painting, as well
  as the painting of its children, to its bounding rectangle.

  Non-rectangular clipping regions are not supported for performance reasons.
*/

/*!
  \qmlproperty string Item::state

  This property holds the name of the current state of the item.

  This property is often used in scripts to change between states. For
  example:

  \qml
    Script {
        function toggle() {
            if (button.state == 'On')
                button.state = 'Off';
            else
                button.state = 'On';
        }
    }
  \endqml

  If the item is in its base state (i.e. no explicit state has been
  set), \c state will be a blank string. Likewise, you can return an
  item to its base state by setting its current state to \c ''.

  \sa {qmlstates}{States}
*/

/*!
  \property QmlGraphicsItem::state
  \internal
*/

/*! \internal */
QString QmlGraphicsItem::state() const
{
    Q_D(const QmlGraphicsItem);
    if (!d->_stateGroup)
        return QString();
    else
        return d->_stateGroup->state();
}

/*! \internal */
void QmlGraphicsItem::setState(const QString &state)
{
    Q_D(QmlGraphicsItem);
    d->states()->setState(state);
}

/*!
  \qmlproperty list<Transform> Item::transform
  This property holds the list of transformations to apply.

  For more information see \l Transform.
*/

/*!
  \property QmlGraphicsItem::transform
  \internal
*/

/*! \internal */
QmlList<QGraphicsTransform *>* QmlGraphicsItem::transform()
{
    Q_D(QmlGraphicsItem);
    return &(d->transform);
}

/*!
  \internal

  classBegin() is called when the item is constructed, but its
  properties have not yet been set.

  \sa componentComplete(), isComponentComplete()
*/
void QmlGraphicsItem::classBegin()
{
    Q_D(QmlGraphicsItem);
    d->_componentComplete = false;
    if (d->_stateGroup)
        d->_stateGroup->classBegin();
    if (d->_anchors)
        d->_anchors->classBegin();
}

/*!
  \internal

  componentComplete() is called when all items in the component
  have been constructed.  It is often desireable to delay some
  processing until the component is complete an all bindings in the
  component have been resolved.
*/
void QmlGraphicsItem::componentComplete()
{
#ifdef Q_ENABLE_PERFORMANCE_LOG
    QmlPerfTimer<QmlPerf::ItemComponentComplete> cc;
#endif

    Q_D(QmlGraphicsItem);
    d->_componentComplete = true;
    if (d->_stateGroup)
        d->_stateGroup->componentComplete();
    if (d->_anchors) {
        d->_anchors->componentComplete();
        d->_anchors->d_func()->updateOnComplete();
    }
    if (d->keyHandler)
        d->keyHandler->componentComplete();
}

QmlStateGroup *QmlGraphicsItemPrivate::states()
{
    Q_Q(QmlGraphicsItem);
    if (!_stateGroup) {
        _stateGroup = new QmlStateGroup;
        if (!_componentComplete)
            _stateGroup->classBegin();
        QObject::connect(_stateGroup, SIGNAL(stateChanged(QString)),
                         q, SIGNAL(stateChanged(QString)));
    }

    return _stateGroup;
}

QmlGraphicsItemPrivate::AnchorLines::AnchorLines(QmlGraphicsItem *q)
{
    left.item = q;
    left.anchorLine = QmlGraphicsAnchorLine::Left;
    right.item = q;
    right.anchorLine = QmlGraphicsAnchorLine::Right;
    hCenter.item = q;
    hCenter.anchorLine = QmlGraphicsAnchorLine::HCenter;
    top.item = q;
    top.anchorLine = QmlGraphicsAnchorLine::Top;
    bottom.item = q;
    bottom.anchorLine = QmlGraphicsAnchorLine::Bottom;
    vCenter.item = q;
    vCenter.anchorLine = QmlGraphicsAnchorLine::VCenter;
    baseline.item = q;
    baseline.anchorLine = QmlGraphicsAnchorLine::Baseline;
}

QPointF QmlGraphicsItemPrivate::computeTransformOrigin() const
{
    Q_Q(const QmlGraphicsItem);

    QRectF br = q->boundingRect();

    switch(origin) {
    default:
    case QmlGraphicsItem::TopLeft:
        return QPointF(0, 0);
    case QmlGraphicsItem::Top:
        return QPointF(br.width() / 2., 0);
    case QmlGraphicsItem::TopRight:
        return QPointF(br.width(), 0);
    case QmlGraphicsItem::Left:
        return QPointF(0, br.height() / 2.);
    case QmlGraphicsItem::Center:
        return QPointF(br.width() / 2., br.height() / 2.);
    case QmlGraphicsItem::Right:
        return QPointF(br.width(), br.height() / 2.);
    case QmlGraphicsItem::BottomLeft:
        return QPointF(0, br.height());
    case QmlGraphicsItem::Bottom:
        return QPointF(br.width() / 2., br.height());
    case QmlGraphicsItem::BottomRight:
        return QPointF(br.width(), br.height());
    }
}

/*! \internal */
bool QmlGraphicsItem::sceneEvent(QEvent *event)
{
    bool rv = QGraphicsItem::sceneEvent(event);

    if (event->type() == QEvent::FocusIn ||
        event->type() == QEvent::FocusOut) {
        focusChanged(hasFocus());
    }

    return rv;
}

/*! \internal */
QVariant QmlGraphicsItem::itemChange(GraphicsItemChange change,
                                       const QVariant &value)
{
    Q_D(const QmlGraphicsItem);
    switch (change) {
    case ItemParentHasChanged:
        emit parentChanged();
        break;
    case ItemChildAddedChange:
    case ItemChildRemovedChange:
        emit childrenChanged();
        break;
    case ItemVisibleHasChanged: {
            for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
                const QmlGraphicsItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
                if (change.types & QmlGraphicsItemPrivate::Visibility) {
                    change.listener->itemVisibilityChanged(this);
                }
            }
        }
        break;
    case ItemOpacityHasChanged: {
            for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
                const QmlGraphicsItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
                if (change.types & QmlGraphicsItemPrivate::Opacity) {
                    change.listener->itemOpacityChanged(this);
                }
            }
        }
        break;
    default:
        break;
    }

    return QGraphicsItem::itemChange(change, value);
}

/*! \internal */
QRectF QmlGraphicsItem::boundingRect() const
{
    Q_D(const QmlGraphicsItem);
    return QRectF(0, 0, d->width, d->height);
}

/*!
    \enum QmlGraphicsItem::TransformOrigin

    Controls the point about which simple transforms like scale apply.

    \value TopLeft The top-left corner of the item.
    \value Top The center point of the top of the item.
    \value TopRight The top-right corner of the item.
    \value Left The left most point of the vertical middle.
    \value Center The center of the item.
    \value Right The right most point of the vertical middle.
    \value BottomLeft The bottom-left corner of the item.
    \value Bottom The center point of the bottom of the item.
    \value BottomRight The bottom-right corner of the item.
*/

/*!
    Returns the current transform origin.
*/
QmlGraphicsItem::TransformOrigin QmlGraphicsItem::transformOrigin() const
{
    Q_D(const QmlGraphicsItem);
    return d->origin;
}

/*!
    Set the transform \a origin.
*/
void QmlGraphicsItem::setTransformOrigin(TransformOrigin origin)
{
    Q_D(QmlGraphicsItem);
    if (origin != d->origin) {
        d->origin = origin;
        QGraphicsItem::setTransformOriginPoint(d->computeTransformOrigin());
        emit transformOriginChanged(d->origin);
    }
}

/*!
    \property QmlGraphicsItem::smooth
    \brief whether the item is smoothly transformed.

    This property is provided purely for the purpose of optimization. Turning
    smooth transforms off is faster, but looks worse; turning smooth
    transformations on is slower, but looks better.

    By default smooth transformations are off.
*/

/*!
    Returns true if the item should be drawn with antialiasing and
    smooth pixmap filtering, false otherwise.

    The default is false.

    \sa setSmooth()
*/
bool QmlGraphicsItem::smooth() const
{
    Q_D(const QmlGraphicsItem);
    return d->smooth;
}

/*!
    Sets whether the item should be drawn with antialiasing and
    smooth pixmap filtering to \a smooth.

    \sa smooth()
*/
void QmlGraphicsItem::setSmooth(bool smooth)
{
    Q_D(QmlGraphicsItem);
    if (d->smooth == smooth)
        return;
    d->smooth = smooth;
    update();
}

qreal QmlGraphicsItem::width() const
{
    Q_D(const QmlGraphicsItem);
    return d->width;
}

void QmlGraphicsItem::setWidth(qreal w)
{
    Q_D(QmlGraphicsItem);
    if (qIsNaN(w))
        return;

    d->widthValid = true;
    if (d->width == w)
        return;

    qreal oldWidth = d->width;

    prepareGeometryChange();
    d->width = w;
    update();

    geometryChanged(QRectF(x(), y(), width(), height()),
                    QRectF(x(), y(), oldWidth, height()));
}

void QmlGraphicsItem::resetWidth()
{
    Q_D(QmlGraphicsItem);
    d->widthValid = false;
    setImplicitWidth(implicitWidth());
}

/*!
    Returns the width of the item that is implied by other properties that determine the content.
*/
qreal QmlGraphicsItem::implicitWidth() const
{
    Q_D(const QmlGraphicsItem);
    return d->implicitWidth;
}

/*!
    Sets the implied width of the item to \a w.
    This is the width implied by other properties that determine the content.
*/
void QmlGraphicsItem::setImplicitWidth(qreal w)
{
    Q_D(QmlGraphicsItem);
    d->implicitWidth = w;
    if (d->width == w || widthValid())
        return;

    qreal oldWidth = d->width;

    prepareGeometryChange();
    d->width = w;
    update();

    geometryChanged(QRectF(x(), y(), width(), height()),
                    QRectF(x(), y(), oldWidth, height()));
}

/*!
    Returns whether the width property has been set explicitly.
*/
bool QmlGraphicsItem::widthValid() const
{
    Q_D(const QmlGraphicsItem);
    return d->widthValid;
}

qreal QmlGraphicsItem::height() const
{
    Q_D(const QmlGraphicsItem);
    return d->height;
}

void QmlGraphicsItem::setHeight(qreal h)
{
    Q_D(QmlGraphicsItem);
    if (qIsNaN(h))
        return;

    d->heightValid = true;
    if (d->height == h)
        return;

    qreal oldHeight = d->height;

    prepareGeometryChange();
    d->height = h;
    update();

    geometryChanged(QRectF(x(), y(), width(), height()),
                    QRectF(x(), y(), width(), oldHeight));
}

void QmlGraphicsItem::resetHeight()
{
    Q_D(QmlGraphicsItem);
    d->heightValid = false;
    setImplicitHeight(implicitHeight());
}

/*!
    Returns the height of the item that is implied by other properties that determine the content.
*/
qreal QmlGraphicsItem::implicitHeight() const
{
    Q_D(const QmlGraphicsItem);
    return d->implicitHeight;
}

/*!
    Sets the implied height of the item to \a h.
    This is the height implied by other properties that determine the content.
*/
void QmlGraphicsItem::setImplicitHeight(qreal h)
{
    Q_D(QmlGraphicsItem);
    d->implicitHeight = h;
    if (d->height == h || heightValid())
        return;

    qreal oldHeight = d->height;

    prepareGeometryChange();
    d->height = h;
    update();

    geometryChanged(QRectF(x(), y(), width(), height()),
                    QRectF(x(), y(), width(), oldHeight));
}

/*!
    Returns whether the height property has been set explicitly.
*/
bool QmlGraphicsItem::heightValid() const
{
    Q_D(const QmlGraphicsItem);
    return d->heightValid;
}

/*!
  \qmlproperty bool Item::wantsFocus

  This property indicates whether the item has has an active focus request.

  \sa {qmlfocus}{Keyboard Focus}
*/

/*! \internal */
bool QmlGraphicsItem::wantsFocus() const
{
    return focusItem() != 0;
}

/*!
  \qmlproperty bool Item::focus
  This property indicates whether the item has keyboard input focus. Set this
  property to true to request focus.

  \sa {qmlfocus}{Keyboard Focus}
*/

/*! \internal */
bool QmlGraphicsItem::hasFocus() const
{
    return QGraphicsItem::hasFocus();
}

/*! \internal */
void QmlGraphicsItem::setFocus(bool focus)
{
    if (focus)
        QGraphicsItem::setFocus(Qt::OtherFocusReason);
    else
        QGraphicsItem::clearFocus();
}

/*!
    \reimp
    \internal
*/
void QmlGraphicsItem::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *)
{
}

/*!
    \reimp
    \internal
*/
bool QmlGraphicsItem::event(QEvent *ev)
{
    return QGraphicsObject::event(ev);
}

QDebug operator<<(QDebug debug, QmlGraphicsItem *item)
{
    if (!item) {
        debug << "QmlGraphicsItem(0)";
        return debug;
    }

    debug << item->metaObject()->className() << "(this =" << ((void*)item)
          << ", parent =" << ((void*)item->parentItem())
          << ", geometry =" << QRectF(item->pos(), QSizeF(item->width(), item->height()))
          << ", z =" << item->zValue() << ')';
    return debug;
}

int QmlGraphicsItemPrivate::consistentTime = -1;
void QmlGraphicsItemPrivate::setConsistentTime(int t)
{
    consistentTime = t;
}

QTime QmlGraphicsItemPrivate::currentTime()
{
    if (consistentTime == -1)
        return QTime::currentTime();
    else
        return QTime(0, 0).addMSecs(consistentTime);
}

void QmlGraphicsItemPrivate::start(QTime &t)
{
    t = currentTime();
}

int QmlGraphicsItemPrivate::elapsed(QTime &t)
{
    int n = t.msecsTo(currentTime());
    if (n < 0)                                // passed midnight
        n += 86400 * 1000;
    return n;
}

int QmlGraphicsItemPrivate::restart(QTime &t)
{
    QTime time = currentTime();
    int n = t.msecsTo(time);
    if (n < 0)                                // passed midnight
        n += 86400*1000;
    t = time;
    return n;
}

QT_END_NAMESPACE

#include <moc_qmlgraphicsitem.cpp>