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
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui 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$
**
****************************************************************************/
/*!
\class QGraphicsItem
\brief The QGraphicsItem class is the base class for all graphical
items in a QGraphicsScene.
\since 4.2
\ingroup graphicsview-api
It provides a light-weight foundation for writing your own custom items.
This includes defining the item's geometry, collision detection, its
painting implementation and item interaction through its event handlers.
QGraphicsItem is part of \l{The Graphics View Framework}
\img graphicsview-items.png
For convenience, Qt provides a set of standard graphics items for the most
common shapes. These are:
\list
\o QGraphicsEllipseItem provides an ellipse item
\o QGraphicsLineItem provides a line item
\o QGraphicsPathItem provides an arbitrary path item
\o QGraphicsPixmapItem provides a pixmap item
\o QGraphicsPolygonItem provides a polygon item
\o QGraphicsRectItem provides a rectangular item
\o QGraphicsSimpleTextItem provides a simple text label item
\o QGraphicsTextItem provides an advanced text browser item
\endlist
All of an item's geometric information is based on its local coordinate
system. The item's position, pos(), is the only function that does not
operate in local coordinates, as it returns a position in parent
coordinates. \l {The Graphics View Coordinate System} describes the coordinate
system in detail.
You can set whether an item should be visible (i.e., drawn, and accepting
events), by calling setVisible(). Hiding an item will also hide its
children. Similarly, you can enable or disable an item by calling
setEnabled(). If you disable an item, all its children will also be
disabled. By default, items are both visible and enabled. To toggle
whether an item is selected or not, first enable selection by setting
the ItemIsSelectable flag, and then call setSelected(). Normally,
selection is toggled by the scene, as a result of user interaction.
To write your own graphics item, you first create a subclass of
QGraphicsItem, and then start by implementing its two pure virtual public
functions: boundingRect(), which returns an estimate of the area painted
by the item, and paint(), which implements the actual painting. For
example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 0
The boundingRect() function has many different purposes.
QGraphicsScene bases its item index on boundingRect(), and
QGraphicsView uses it both for culling invisible items, and for
determining the area that needs to be recomposed when drawing
overlapping items. In addition, QGraphicsItem's collision
detection mechanisms use boundingRect() to provide an efficient
cut-off. The fine grained collision algorithm in
collidesWithItem() is based on calling shape(), which returns an
accurate outline of the item's shape as a QPainterPath.
QGraphicsScene expects all items boundingRect() and shape() to
remain unchanged unless it is notified. If you want to change an
item's geometry in any way, you must first call
prepareGeometryChange() to allow QGraphicsScene to update its
bookkeeping.
Collision detection can be done in two ways:
\list 1
\o Reimplement shape() to return an accurate shape for your item,
and rely on the default implementation of collidesWithItem() to do
shape-shape intersection. This can be rather expensive if the
shapes are complex.
\o Reimplement collidesWithItem() to provide your own custom item
and shape collision algorithm.
\endlist
The contains() function can be called to determine whether the item \e
contains a point or not. This function can also be reimplemented by the
item. The default behavior of contains() is based on calling shape().
Items can contain other items, and also be contained by other items. All
items can have a parent item and a list of children. Unless the item has
no parent, its position is in \e parent coordinates (i.e., the parent's
local coordinates). Parent items propagate both their position and their
transformation to all children.
\img graphicsview-parentchild.png
\section1 Transformation
QGraphicsItem supports projective transformations in addition to its base
position, pos(). There are several ways to change an item's transformation.
For simple transformations, you can call either of the convenience
functions setRotation() or setScale(), or you can pass any transformation
matrix to setTransform(). For advanced transformation control you also have
the option of setting several combined transformations by calling
setTransformations().
Item transformations accumulate from parent to child, so if both a parent
and child item are rotated 90 degrees, the child's total transformation
will be 180 degrees. Similarly, if the item's parent is scaled to 2x its
original size, its children will also be twice as large. An item's
transformation does not affect its own local geometry; all geometry
functions (e.g., contains(), update(), and all the mapping functions) still
operate in local coordinates. For convenience, QGraphicsItem provides the
functions sceneTransform(), which returns the item's total transformation
matrix (including its position and all parents' positions and
transformations), and scenePos(), which returns its position in scene
coordinates. To reset an item's matrix, call resetTransform().
Certain transformation operations produce a different outcome depending on
the order in which they are applied. For example, if you scale an
transform, and then rotate it, you may get a different result than if the
transform was rotated first. However, the order you set the transformation
properties on QGraphicsItem does not affect the resulting transformation;
QGraphicsItem always applies the properties in a fixed, defined order:
\list
\o The item's base transform is applied (transform())
\o The item's transformations list is applied in order (transformations())
\o The item is rotated relative to its transform origin point (rotation(), transformOriginPoint())
\o The item is scaled relative to its transform origin point (scale(), transformOriginPoint())
\endlist
\section1 Painting
The paint() function is called by QGraphicsView to paint the item's
contents. The item has no background or default fill of its own; whatever
is behind the item will shine through all areas that are not explicitly
painted in this function. You can call update() to schedule a repaint,
optionally passing the rectangle that needs a repaint. Depending on
whether or not the item is visible in a view, the item may or may not be
repainted; there is no equivalent to QWidget::repaint() in QGraphicsItem.
Items are painted by the view, starting with the parent items and then
drawing children, in ascending stacking order. You can set an item's
stacking order by calling setZValue(), and test it by calling
zValue(), where items with low z-values are painted before items with
high z-values. Stacking order applies to sibling items; parents are always
drawn before their children.
\section1 Events
QGraphicsItem receives events from QGraphicsScene through the virtual
function sceneEvent(). This function distributes the most common events
to a set of convenience event handlers:
\list
\o contextMenuEvent() handles context menu events
\o focusInEvent() and focusOutEvent() handle focus in and out events
\o hoverEnterEvent(), hoverMoveEvent(), and hoverLeaveEvent() handles
hover enter, move and leave events
\o inputMethodEvent() handles input events, for accessibility support
\o keyPressEvent() and keyReleaseEvent handle key press and release events
\o mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(), and
mouseDoubleClickEvent() handles mouse press, move, release, click and
doubleclick events
\endlist
You can filter events for any other item by installing event
filters. This functionaly is separate from from Qt's regular
event filters (see QObject::installEventFilter()), which only
work on subclasses of QObject. After installing your item as an
event filter for another item by calling
installSceneEventFilter(), the filtered events will be received
by the virtual function sceneEventFilter(). You can remove item
event filters by calling removeSceneEventFilter().
\section1 Custom Data
Sometimes it's useful to register custom data with an item, be it a custom
item, or a standard item. You can call setData() on any item to store data
in it using a key-value pair (the key being an integer, and the value is a
QVariant). To get custom data from an item, call data(). This
functionality is completely untouched by Qt itself; it is provided for the
user's convenience.
\sa QGraphicsScene, QGraphicsView, {The Graphics View Framework}
*/
/*!
\variable QGraphicsItem::UserType
The lowest permitted type value for custom items (subclasses
of QGraphicsItem or any of the standard items). This value is
used in conjunction with a reimplementation of QGraphicsItem::type()
and declaring a Type enum value. Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 1
*/
/*!
\enum QGraphicsItem::GraphicsItemFlag
This enum describes different flags that you can set on an item to
toggle different features in the item's behavior.
All flags are disabled by default.
\value ItemIsMovable The item supports interactive movement using
the mouse. By clicking on the item and then dragging, the item
will move together with the mouse cursor. If the item has
children, all children are also moved. If the item is part of a
selection, all selected items are also moved. This feature is
provided as a convenience through the base implementation of
QGraphicsItem's mouse event handlers.
\value ItemIsSelectable The item supports selection. Enabling this
feature will enable setSelected() to toggle selection for the
item. It will also let the item be selected automatically as a
result of calling QGraphicsScene::setSelectionArea(), by clicking
on an item, or by using rubber band selection in QGraphicsView.
\value ItemIsFocusable The item supports keyboard input focus (i.e., it is
an input item). Enabling this flag will allow the item to accept focus,
which again allows the delivery of key events to
QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent().
\value ItemClipsToShape The item clips to its own shape. The item cannot
draw or receive mouse, tablet, drag and drop or hover events outside ts
shape. It is disabled by default. This behavior is enforced by
QGraphicsView::drawItems() or QGraphicsScene::drawItems(). This flag was
introduced in Qt 4.3.
\value ItemClipsChildrenToShape The item clips the painting of all its
descendants to its own shape. Items that are either direct or indirect
children of this item cannot draw outside this item's shape. By default,
this flag is disabled; children can draw anywhere. This behavior is
enforced by QGraphicsView::drawItems() or
QGraphicsScene::drawItems(). This flag was introduced in Qt 4.3.
\value ItemIgnoresTransformations The item ignores inherited
transformations (i.e., its position is still anchored to its parent, but
the parent or view rotation, zoom or shear transformations are ignored).
This flag is useful for keeping text label items horizontal and unscaled,
so they will still be readable if the view is transformed. When set, the
item's view geometry and scene geometry will be maintained separately. You
must call deviceTransform() to map coordinates and detect collisions in
the view. By default, this flag is disabled. This flag was introduced in
Qt 4.3. \note With this flag set you can still scale the item itself, and
that scale transformation will influence the item's children.
\value ItemIgnoresParentOpacity The item ignores its parent's opacity. The
item's effective opacity is the same as its own; it does not combine with
the parent's opacity. This flags allows your item to keep its absolute
opacity even if the parent is semitransparent. This flag was introduced in
Qt 4.5.
\value ItemDoesntPropagateOpacityToChildren The item doesn't propagate its
opacity to its children. This flag allows you to create a semitransparent
item that does not affect the opacity of its children. This flag was
introduced in Qt 4.5.
\value ItemStacksBehindParent The item is stacked behind its parent. By
default, child items are stacked on top of the parent item. But setting
this flag, the child will be stacked behind it. This flag is useful for
drop shadow effects and for decoration objects that follow the parent
item's geometry without drawing on top of it.
\value ItemUsesExtendedStyleOption The item makes use of either the
exposedRect or matrix member of the QStyleOptionGraphicsItem. Implementers
of QGraphicsItem subclasses should set that flag if this data is required.
By default, the exposedRect is initialized to the item's boundingRect and
the matrix is untransformed. Enable this flag for more fine-grained values.
Use QStyleOptionGraphicsItem::levelOfDetailFromTransform() for a more
fine-grained value.
\value ItemHasNoContents The item does not paint anything (i.e., calling
paint() on the item has no effect). You should set this flag on items that
do not need to be painted to ensure that Graphics View avoids unnecessary
painting preparations. This flag was introduced in Qt 4.6.
\value ItemSendsGeometryChanges The item enables itemChange()
notifications for ItemPositionChange, ItemPositionHasChanged,
ItemMatrixChange, ItemTransformChange, and ItemTransformHasChanged. For
performance reasons, these notifications are disabled by default. You must
enable this flag to receive notifications for position and transform
changes. This flag was introduced in Qt 4.6.
\value ItemAcceptsInputMethod The item supports input methods typically
used for Asian languages.
This flag was introduced in Qt 4.6.
\value ItemNegativeZStacksBehindParent The item automatically stacks behind
it's parent if it's z-value is negative. This flag enables setZValue() to
toggle ItemStacksBehindParent.
\value ItemAutoDetectsFocusProxy The item will assign any child that
gains input focus as its focus proxy. See also focusProxy().
This flag was introduced in Qt 4.6.
\value ItemIsPanel. The item is a panel. A panel provides activation and
contained focus handling. Only one panel can be active at a time (see
QGraphicsItem::isActive()). When no panel is active, QGraphicsScene
activates all non-panel items. Window items (i.e.,
QGraphicsItem::isWindow() returns true) are panels. This flag was
introduced in Qt 4.6.
*/
/*!
\enum QGraphicsItem::GraphicsItemChange
ItemVisibleHasChanged,
ItemEnabledHasChanged,
ItemSelectedHasChanged,
ItemParentHasChanged,
ItemSceneHasChanged
This enum describes the state changes that are notified by
QGraphicsItem::itemChange(). The notifications are sent as the state
changes, and in some cases, adjustments can be made (see the documentation
for each change for details).
Note: Be careful with calling functions on the QGraphicsItem itself inside
itemChange(), as certain function calls can lead to unwanted
recursion. For example, you cannot call setPos() in itemChange() on an
ItemPositionChange notification, as the setPos() function will again call
itemChange(ItemPositionChange). Instead, you can return the new, adjusted
position from itemChange().
\value ItemEnabledChange The item's enabled state changes. If the item is
presently enabled, it will become disabled, and vice verca. The value
argument is the new enabled state (i.e., true or false). Do not call
setEnabled() in itemChange() as this notification is delivered. Instead,
you can return the new state from itemChange().
\value ItemEnabledHasChanged The item's enabled state has changed. The
value argument is the new enabled state (i.e., true or false). Do not call
setEnabled() in itemChange() as this notification is delivered. The return
value is ignored.
\value ItemMatrixChange The item's affine transformation matrix is
changing. This value is obsolete; you can use ItemTransformChange instead.
\value ItemPositionChange The item's position changes. This notification
is sent if the ItemSendsGeometryChanges flag is enabled, and when the
item's local position changes, relative to its parent (i.e., as a result
of calling setPos() or moveBy()). The value argument is the new position
(i.e., a QPointF). You can call pos() to get the original position. Do
not call setPos() or moveBy() in itemChange() as this notification is
delivered; instead, you can return the new, adjusted position from
itemChange(). After this notification, QGraphicsItem immediately sends the
ItemPositionHasChanged notification if the position changed.
\value ItemPositionHasChanged The item's position has changed. This
notification is sent if the ItemSendsGeometryChanges flag is enabled, and
after the item's local position, relative to its parent, has changed. The
value argument is the new position (the same as pos()), and QGraphicsItem
ignores the return value for this notification (i.e., a read-only
notification).
\value ItemTransformChange The item's transformation matrix changes. This
notification is send if the ItemSendsGeometryChanges flag is enabled, and
when the item's local transformation matrix changes (i.e., as a result of
calling setTransform(). The value argument is the new matrix (i.e., a
QTransform); to get the old matrix, call transform(). Do not call
setTransform() or set any of the transformation properties in itemChange()
as this notification is delivered; instead, you can return the new matrix
from itemChange(). This notification is not sent if you change the
transformation properties.
\value ItemTransformHasChanged The item's transformation matrix has
changed either because setTransform is called, or one of the
transformation properties is changed. This notification is sent if the
ItemSendsGeometryChanges flag is enabled, and after the item's local
transformation matrix has changed. The value argument is the new matrix
(same as transform()), and QGraphicsItem ignores the return value for this
notification (i.e., a read-only notification).
\value ItemSelectedChange The item's selected state changes. If the item
is presently selected, it will become unselected, and vice verca. The
value argument is the new selected state (i.e., true or false). Do not
call setSelected() in itemChange() as this notification is delivered();
instead, you can return the new selected state from itemChange().
\value ItemSelectedHasChanged The item's selected state has changed. The
value argument is the new selected state (i.e., true or false). Do not
call setSelected() in itemChange() as this notification is delivered. The
return value is ignored.
\value ItemVisibleChange The item's visible state changes. If the item is
presently visible, it will become invisible, and vice verca. The value
argument is the new visible state (i.e., true or false). Do not call
setVisible() in itemChange() as this notification is delivered; instead,
you can return the new visible state from itemChange().
\value ItemVisibleHasChanged The item's visible state has changed. The
value argument is the new visible state (i.e., true or false). Do not call
setVisible() in itemChange() as this notification is delivered. The return
value is ignored.
\value ItemParentChange The item's parent changes. The value argument is
the new parent item (i.e., a QGraphicsItem pointer). Do not call
setParentItem() in itemChange() as this notification is delivered;
instead, you can return the new parent from itemChange().
\value ItemParentHasChanged The item's parent has changed. The value
argument is the new parent (i.e., a pointer to a QGraphicsItem). Do not
call setParentItem() in itemChange() as this notification is
delivered. The return value is ignored.
\value ItemChildAddedChange A child is added to this item. The value
argument is the new child item (i.e., a QGraphicsItem pointer). Do not
pass this item to any item's setParentItem() function as this notification
is delivered. The return value is unused; you cannot adjust anything in
this notification. Note that the new child might not be fully constructed
when this notification is sent; calling pure virtual functions on
the child can lead to a crash.
\value ItemChildRemovedChange A child is removed from this item. The value
argument is the child item that is about to be removed (i.e., a
QGraphicsItem pointer). The return value is unused; you cannot adjust
anything in this notification.
\value ItemSceneChange The item is moved to a new scene. This notification
is also sent when the item is added to its initial scene, and when it is
removed. The value argument is the new scene (i.e., a QGraphicsScene
pointer), or a null pointer if the item is removed from a scene. Do not
override this change by passing this item to QGraphicsScene::addItem() as
this notification is delivered; instead, you can return the new scene from
itemChange(). Use this feature with caution; objecting to a scene change can
quickly lead to unwanted recursion.
\value ItemSceneHasChanged The item's scene has changed. The value
argument is the new scene (i.e., a pointer to a QGraphicsScene). Do not
call setScene() in itemChange() as this notification is delivered. The
return value is ignored.
\value ItemCursorChange The item's cursor changes. The value argument is
the new cursor (i.e., a QCursor). Do not call setCursor() in itemChange()
as this notification is delivered. Instead, you can return a new cursor
from itemChange().
\value ItemCursorHasChanged The item's cursor has changed. The value
argument is the new cursor (i.e., a QCursor). Do not call setCursor() as
this notification is delivered. The return value is ignored.
\value ItemToolTipChange The item's tooltip changes. The value argument is
the new tooltip (i.e., a QToolTip). Do not call setToolTip() in
itemChange() as this notification is delivered. Instead, you can return a
new tooltip from itemChange().
\value ItemToolTipHasChanged The item's tooltip has changed. The value
argument is the new tooltip (i.e., a QToolTip). Do not call setToolTip()
as this notification is delivered. The return value is ignored.
\value ItemFlagsChange The item's flags change. The value argument is the
new flags (i.e., a quint32). Do not call setFlags() in itemChange() as
this notification is delivered. Instead, you can return the new flags from
itemChange().
\value ItemFlagsHaveChanged The item's flags have changed. The value
argument is the new flags (i.e., a quint32). Do not call setFlags() in
itemChange() as this notification is delivered. The return value is
ignored.
\value ItemZValueChange The item's Z-value changes. The value argument is
the new Z-value (i.e., a double). Do not call setZValue() in itemChange()
as this notification is delivered. Instead, you can return a new Z-value
from itemChange().
\value ItemZValueHasChanged The item's Z-value has changed. The value
argument is the new Z-value (i.e., a double). Do not call setZValue() as
this notification is delivered. The return value is ignored.
\value ItemOpacityChange The item's opacity changes. The value argument is
the new opacity (i.e., a double). Do not call setOpacity() in itemChange()
as this notification is delivered. Instead, you can return a new opacity
from itemChange().
\value ItemOpacityHasChanged The item's opacity has changed. The value
argument is the new opacity (i.e., a double). Do not call setOpacity() as
this notification is delivered. The return value is ignored.
*/
/*!
\enum QGraphicsItem::CacheMode
\since 4.4
This enum describes QGraphicsItem's cache modes. Caching is used to speed
up rendering by allocating and rendering to an off-screen pixel buffer,
which can be reused when the item requires redrawing. For some paint
devices, the cache is stored directly in graphics memory, which makes
rendering very quick.
\value NoCache The default; all item caching is
disabled. QGraphicsItem::paint() is called every time the item needs
redrawing.
\value ItemCoordinateCache Caching is enabled for the item's logical
(local) coordinate system. QGraphicsItem creates an off-screen pixel
buffer with a configurable size / resolution that you can pass to
QGraphicsItem::setCacheMode(). Rendering quality will typically degrade,
depending on the resolution of the cache and the item transformation. The
first time the item is redrawn, it will render itself into the cache, and
the cache is then reused for every subsequent expose. The cache is also
reused as the item is transformed. To adjust the resolution of the cache,
you can call setCacheMode() again.
\value DeviceCoordinateCache Caching is enabled at the paint device level,
in device coordinates. This mode is for items that can move, but are not
rotated, scaled or sheared. If the item is transformed directly or
indirectly, the cache will be regenerated automatically. Unlike
ItemCoordinateCacheMode, DeviceCoordinateCache always renders at maximum
quality.
\sa QGraphicsItem::setCacheMode()
*/
/*!
\enum QGraphicsItem::Extension
\internal
Note: This is provided as a hook to avoid future problems related
to adding virtual functions. See also extension(),
supportsExtension() and setExtension().
*/
#include "qgraphicsitem.h"
#ifndef QT_NO_GRAPHICSVIEW
#include "qgraphicsscene.h"
#include "qgraphicsscene_p.h"
#include "qgraphicssceneevent.h"
#include "qgraphicsview.h"
#include "qgraphicswidget.h"
#include "qgraphicsproxywidget.h"
#include "qgraphicsscenebsptreeindex_p.h"
#include <QtCore/qbitarray.h>
#include <QtCore/qdebug.h>
#include <QtCore/qpoint.h>
#include <QtCore/qstack.h>
#include <QtCore/qtimer.h>
#include <QtCore/qvariant.h>
#include <QtCore/qvarlengtharray.h>
#include <QtGui/qapplication.h>
#include <QtGui/qbitmap.h>
#include <QtGui/qpainter.h>
#include <QtGui/qpainterpath.h>
#include <QtGui/qpixmapcache.h>
#include <QtGui/qstyleoption.h>
#include <QtGui/qevent.h>
#include <QtGui/qinputcontext.h>
#include <QtGui/qgraphicseffect.h>
#include <private/qgraphicsitem_p.h>
#include <private/qgraphicswidget_p.h>
#include <private/qtextcontrol_p.h>
#include <private/qtextdocumentlayout_p.h>
#include <private/qtextengine_p.h>
#include <private/qwidget_p.h>
#ifdef Q_WS_X11
#include <private/qt_x11_p.h>
#include <private/qpixmap_x11_p.h>
#endif
#include <math.h>
QT_BEGIN_NAMESPACE
static inline void _q_adjustRect(QRect *rect)
{
Q_ASSERT(rect);
if (!rect->width())
rect->adjust(0, 0, 1, 0);
if (!rect->height())
rect->adjust(0, 0, 0, 1);
}
/*
### Move this into QGraphicsItemPrivate
*/
class QGraphicsItemCustomDataStore
{
public:
QMap<const QGraphicsItem *, QMap<int, QVariant> > data;
};
Q_GLOBAL_STATIC(QGraphicsItemCustomDataStore, qt_dataStore)
/*!
\internal
Returns a QPainterPath of \a path when stroked with the \a pen.
Ignoring dash pattern.
*/
static QPainterPath qt_graphicsItem_shapeFromPath(const QPainterPath &path, const QPen &pen)
{
// We unfortunately need this hack as QPainterPathStroker will set a width of 1.0
// if we pass a value of 0.0 to QPainterPathStroker::setWidth()
const qreal penWidthZero = qreal(0.00000001);
if (path == QPainterPath())
return path;
QPainterPathStroker ps;
ps.setCapStyle(pen.capStyle());
if (pen.widthF() <= 0.0)
ps.setWidth(penWidthZero);
else
ps.setWidth(pen.widthF());
ps.setJoinStyle(pen.joinStyle());
ps.setMiterLimit(pen.miterLimit());
QPainterPath p = ps.createStroke(path);
p.addPath(path);
return p;
}
/*!
\internal
Propagates the ancestor flag \a flag with value \a enabled to all this
item's children. If \a root is false, the flag is also set on this item
(default is true).
*/
void QGraphicsItemPrivate::updateAncestorFlag(QGraphicsItem::GraphicsItemFlag childFlag,
AncestorFlag flag, bool enabled, bool root)
{
Q_Q(QGraphicsItem);
if (root) {
// For root items only. This is the item that has either enabled or
// disabled \a childFlag, or has been reparented.
switch (int(childFlag)) {
case -2:
flag = AncestorFiltersChildEvents;
enabled = q->filtersChildEvents();
break;
case -1:
flag = AncestorHandlesChildEvents;
enabled = q->handlesChildEvents();
break;
case QGraphicsItem::ItemClipsChildrenToShape:
flag = AncestorClipsChildren;
enabled = flags & QGraphicsItem::ItemClipsChildrenToShape;
invalidateCachedClipPathRecursively(/*childrenOnly=*/true);
break;
case QGraphicsItem::ItemIgnoresTransformations:
flag = AncestorIgnoresTransformations;
enabled = flags & QGraphicsItem::ItemIgnoresTransformations;
break;
default:
return;
}
if (parent) {
// Inherit the enabled-state from our parents.
if ((parent->d_ptr->ancestorFlags & flag)
|| (int(parent->d_ptr->flags & childFlag) == childFlag)
|| (childFlag == -1 && parent->d_ptr->handlesChildEvents)
|| (childFlag == -2 && parent->d_ptr->filtersDescendantEvents)) {
enabled = true;
ancestorFlags |= flag;
} else {
ancestorFlags &= ~flag;
}
} else {
// Top-level root items don't have any ancestors, so there are no
// ancestor flags either.
ancestorFlags = 0;
}
} else {
// Don't set or propagate the ancestor flag if it's already correct.
if (((ancestorFlags & flag) && enabled) || (!(ancestorFlags & flag) && !enabled))
return;
// Set the flag.
if (enabled)
ancestorFlags |= flag;
else
ancestorFlags &= ~flag;
// Don't process children if the item has the main flag set on itself.
if ((childFlag != -1 && int(flags & childFlag) == childFlag)
|| (int(childFlag) == -1 && handlesChildEvents)
|| (int(childFlag) == -2 && filtersDescendantEvents))
return;
}
foreach (QGraphicsItem *child, children)
child->d_ptr->updateAncestorFlag(childFlag, flag, enabled, false);
}
/*!
\internal
Propagates item group membership.
*/
void QGraphicsItemPrivate::setIsMemberOfGroup(bool enabled)
{
Q_Q(QGraphicsItem);
isMemberOfGroup = enabled;
if (!qgraphicsitem_cast<QGraphicsItemGroup *>(q)) {
foreach (QGraphicsItem *child, children)
child->d_func()->setIsMemberOfGroup(enabled);
}
}
/*!
\internal
Maps any item pos properties of \a event to \a item's coordinate system.
*/
void QGraphicsItemPrivate::remapItemPos(QEvent *event, QGraphicsItem *item)
{
Q_Q(QGraphicsItem);
switch (event->type()) {
case QEvent::GraphicsSceneMouseMove:
case QEvent::GraphicsSceneMousePress:
case QEvent::GraphicsSceneMouseRelease:
case QEvent::GraphicsSceneMouseDoubleClick: {
QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
mouseEvent->setPos(item->mapFromItem(q, mouseEvent->pos()));
mouseEvent->setLastPos(item->mapFromItem(q, mouseEvent->pos()));
for (int i = 0x1; i <= 0x10; i <<= 1) {
if (mouseEvent->buttons() & i) {
Qt::MouseButton button = Qt::MouseButton(i);
mouseEvent->setButtonDownPos(button, item->mapFromItem(q, mouseEvent->buttonDownPos(button)));
}
}
break;
}
case QEvent::GraphicsSceneWheel: {
QGraphicsSceneWheelEvent *wheelEvent = static_cast<QGraphicsSceneWheelEvent *>(event);
wheelEvent->setPos(item->mapFromItem(q, wheelEvent->pos()));
break;
}
case QEvent::GraphicsSceneContextMenu: {
QGraphicsSceneContextMenuEvent *contextEvent = static_cast<QGraphicsSceneContextMenuEvent *>(event);
contextEvent->setPos(item->mapFromItem(q, contextEvent->pos()));
break;
}
case QEvent::GraphicsSceneHoverMove: {
QGraphicsSceneHoverEvent *hoverEvent = static_cast<QGraphicsSceneHoverEvent *>(event);
hoverEvent->setPos(item->mapFromItem(q, hoverEvent->pos()));
break;
}
default:
break;
}
}
/*!
\internal
Maps the point \a pos from scene to item coordinates. If \a view is passed and the item
is untransformable, this function will correctly map \a pos from the scene using the
view's transformation.
*/
QPointF QGraphicsItemPrivate::genericMapFromScene(const QPointF &pos,
const QWidget *viewport) const
{
Q_Q(const QGraphicsItem);
if (!itemIsUntransformable())
return q->mapFromScene(pos);
QGraphicsView *view = 0;
if (viewport)
view = qobject_cast<QGraphicsView *>(viewport->parentWidget());
if (!view)
return q->mapFromScene(pos);
// ### More ping pong than needed.
return q->deviceTransform(view->viewportTransform()).inverted().map(view->mapFromScene(pos));
}
/*!
\internal
Combines this item's position and transform onto \a transform.
If you need to change this function (e.g., adding more transformation
modes / options), make sure to change all places marked with COMBINE.
*/
void QGraphicsItemPrivate::combineTransformToParent(QTransform *x, const QTransform *viewTransform) const
{
// COMBINE
if (viewTransform && itemIsUntransformable()) {
*x = q_ptr->deviceTransform(*viewTransform);
} else {
if (transformData)
*x *= transformData->computedFullTransform();
if (!pos.isNull())
*x *= QTransform::fromTranslate(pos.x(), pos.y());
}
}
/*!
\internal
Combines this item's position and transform onto \a transform.
If you need to change this function (e.g., adding more transformation
modes / options), make sure to change QGraphicsItem::deviceTransform() as
well.
*/
void QGraphicsItemPrivate::combineTransformFromParent(QTransform *x, const QTransform *viewTransform) const
{
// COMBINE
if (viewTransform && itemIsUntransformable()) {
*x = q_ptr->deviceTransform(*viewTransform);
} else {
x->translate(pos.x(), pos.y());
if (transformData)
*x = transformData->computedFullTransform(x);
}
}
void QGraphicsItemPrivate::updateSceneTransformFromParent()
{
if (parent) {
Q_ASSERT(!parent->d_ptr->dirtySceneTransform);
if (parent->d_ptr->sceneTransformTranslateOnly) {
sceneTransform = QTransform::fromTranslate(parent->d_ptr->sceneTransform.dx() + pos.x(),
parent->d_ptr->sceneTransform.dy() + pos.y());
} else {
sceneTransform = parent->d_ptr->sceneTransform;
sceneTransform.translate(pos.x(), pos.y());
}
if (transformData) {
sceneTransform = transformData->computedFullTransform(&sceneTransform);
sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
} else {
sceneTransformTranslateOnly = parent->d_ptr->sceneTransformTranslateOnly;
}
} else if (!transformData) {
sceneTransform = QTransform::fromTranslate(pos.x(), pos.y());
sceneTransformTranslateOnly = 1;
} else if (transformData->onlyTransform) {
sceneTransform = transformData->transform;
if (!pos.isNull())
sceneTransform *= QTransform::fromTranslate(pos.x(), pos.y());
sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
} else if (pos.isNull()) {
sceneTransform = transformData->computedFullTransform();
sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
} else {
sceneTransform = QTransform::fromTranslate(pos.x(), pos.y());
sceneTransform = transformData->computedFullTransform(&sceneTransform);
sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
}
dirtySceneTransform = 0;
}
/*!
\internal
This helper function helped us add input method query support in
Qt 4.4.1 without having to reimplement the inputMethodQuery()
function in QGraphicsProxyWidget. ### Qt 5: Remove. We cannot
remove it in 4.5+ even if we do reimplement the function properly,
because apps compiled with 4.4 will not be able to call the
reimplementation.
*/
QVariant QGraphicsItemPrivate::inputMethodQueryHelper(Qt::InputMethodQuery query) const
{
Q_UNUSED(query);
return QVariant();
}
/*!
\internal
Make sure not to trigger any pure virtual function calls (e.g.,
prepareGeometryChange) if the item is in its destructor, i.e.
inDestructor is 1.
*/
void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent)
{
Q_Q(QGraphicsItem);
if (newParent == q) {
qWarning("QGraphicsItem::setParentItem: cannot assign %p as a parent of itself", this);
return;
}
if (newParent == parent)
return;
const QVariant newParentVariant(q->itemChange(QGraphicsItem::ItemParentChange,
qVariantFromValue<QGraphicsItem *>(newParent)));
newParent = qVariantValue<QGraphicsItem *>(newParentVariant);
if (newParent == parent)
return;
if (scene) {
// Deliver the change to the index
scene->d_func()->index->itemChange(q, QGraphicsItem::ItemParentChange, newParentVariant);
}
QGraphicsItem *lastSubFocusItem = subFocusItem;
if (subFocusItem) {
// Update the child focus chain; when reparenting an item that has a
// focus child, ensure that that focus child clears its focus child
// chain from our parents before it's reparented.
subFocusItem->clearFocus();
}
// We anticipate geometry changes. If the item is deleted, it will be
// removed from the index at a later stage, and the whole scene will be
// updated.
if (!inDestructor)
q_ptr->prepareGeometryChange();
const QVariant thisPointerVariant(qVariantFromValue<QGraphicsItem *>(q));
if (parent) {
// Remove from current parent
parent->d_ptr->removeChild(q);
parent->itemChange(QGraphicsItem::ItemChildRemovedChange, thisPointerVariant);
}
// Auto-update focus proxy. Any ancestor that has this as focus proxy
//needs to be nulled.
QGraphicsItem *p = parent;
while (p) {
if ((p->d_ptr->flags & QGraphicsItem::ItemAutoDetectsFocusProxy) &&
(p->focusProxy() == q)) {
p->setFocusProxy(0);
}
p = p->d_ptr->parent;
}
// Update toplevelitem list. If this item is being deleted, its parent
// will be 0 but we don't want to register/unregister it in the TLI list.
if (scene && !inDestructor) {
if (parent && !newParent) {
scene->d_func()->registerTopLevelItem(q);
} else if (!parent && newParent) {
scene->d_func()->unregisterTopLevelItem(q);
}
}
if ((parent = newParent)) {
bool implicitUpdate = false;
if (parent->d_func()->scene && parent->d_func()->scene != scene) {
// Move this item to its new parent's scene
parent->d_func()->scene->addItem(q);
implicitUpdate = true;
} else if (!parent->d_func()->scene && scene) {
// Remove this item from its former scene
scene->removeItem(q);
}
parent->d_ptr->addChild(q);
parent->itemChange(QGraphicsItem::ItemChildAddedChange, thisPointerVariant);
if (!implicitUpdate && scene) {
scene->d_func()->markDirty(q_ptr, QRect(),
/*invalidateChildren=*/false,
/*maybeDirtyClipPath=*/true);
}
// Inherit ancestor flags from the new parent.
updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-2));
updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1));
updateAncestorFlag(QGraphicsItem::ItemClipsChildrenToShape);
updateAncestorFlag(QGraphicsItem::ItemIgnoresTransformations);
// Update item visible / enabled.
if (parent->isVisible() != visible) {
if (!parent->isVisible() || !explicitlyHidden)
setVisibleHelper(parent->isVisible(), /* explicit = */ false, /* update = */ !implicitUpdate);
}
if (parent->isEnabled() != enabled) {
if (!parent->isEnabled() || !explicitlyDisabled)
setEnabledHelper(parent->isEnabled(), /* explicit = */ false, /* update = */ !implicitUpdate);
}
} else {
// Inherit ancestor flags from the new parent.
updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-2));
updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1));
updateAncestorFlag(QGraphicsItem::ItemClipsChildrenToShape);
updateAncestorFlag(QGraphicsItem::ItemIgnoresTransformations);
if (!inDestructor) {
// Update item visible / enabled.
if (!visible && !explicitlyHidden)
setVisibleHelper(true, /* explicit = */ false);
if (!enabled && !explicitlyDisabled)
setEnabledHelper(true, /* explicit = */ false);
// If the item is being deleted, the whole scene will be updated.
if (scene) {
scene->d_func()->markDirty(q_ptr, QRect(),
/*invalidateChildren=*/false,
/*maybeDirtyClipPath=*/true);
}
}
}
// Resolve depth.
invalidateDepthRecursively();
dirtySceneTransform = 1;
// Restore the sub focus chain.
if (lastSubFocusItem)
lastSubFocusItem->d_ptr->setSubFocus();
// Auto-update focus proxy. The closest parent that detects
// focus proxies is updated as the proxy gains or loses focus.
p = newParent;
while (p) {
if (p->d_ptr->flags & QGraphicsItem::ItemAutoDetectsFocusProxy) {
p->setFocusProxy(q);
break;
}
p = p->d_ptr->parent;
}
// Deliver post-change notification
q->itemChange(QGraphicsItem::ItemParentHasChanged, newParentVariant);
if (isObject)
emit static_cast<QGraphicsObject *>(q)->parentChanged();
}
/*!
\internal
Returns the bounding rect of this item's children (excluding itself).
*/
void QGraphicsItemPrivate::childrenBoundingRectHelper(QTransform *x, QRectF *rect)
{
for (int i = 0; i < children.size(); ++i) {
QGraphicsItem *child = children.at(i);
QGraphicsItemPrivate *childd = child->d_ptr.data();
bool hasPos = !childd->pos.isNull();
if (hasPos || childd->transformData) {
// COMBINE
QTransform matrix = childd->transformToParent();
if (x)
matrix *= *x;
*rect |= matrix.mapRect(child->boundingRect());
if (!childd->children.isEmpty())
childd->childrenBoundingRectHelper(&matrix, rect);
} else {
if (x)
*rect |= x->mapRect(child->boundingRect());
else
*rect |= child->boundingRect();
if (!childd->children.isEmpty())
childd->childrenBoundingRectHelper(x, rect);
}
}
}
void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform,
const QRegion &exposedRegion, bool allItems) const
{
Q_ASSERT(option);
Q_Q(const QGraphicsItem);
// Initialize standard QStyleOption values.
const QRectF brect = q->boundingRect();
option->state = QStyle::State_None;
option->rect = brect.toRect();
option->levelOfDetail = 1;
option->exposedRect = brect;
if (selected)
option->state |= QStyle::State_Selected;
if (enabled)
option->state |= QStyle::State_Enabled;
if (q->hasFocus())
option->state |= QStyle::State_HasFocus;
if (scene) {
if (scene->d_func()->hoverItems.contains(q_ptr))
option->state |= QStyle::State_MouseOver;
if (q == scene->mouseGrabberItem())
option->state |= QStyle::State_Sunken;
}
if (!(flags & QGraphicsItem::ItemUsesExtendedStyleOption))
return;
// Initialize QStyleOptionGraphicsItem specific values (matrix, exposedRect).
option->matrix = worldTransform.toAffine(); //### discards perspective
if (!allItems) {
// Determine the item's exposed area
option->exposedRect = QRectF();
const QTransform reverseMap = worldTransform.inverted();
const QVector<QRect> exposedRects(exposedRegion.rects());
for (int i = 0; i < exposedRects.size(); ++i) {
option->exposedRect |= reverseMap.mapRect(exposedRects.at(i));
if (option->exposedRect.contains(brect))
break;
}
option->exposedRect &= brect;
}
}
/*!
\internal
Empty all cached pixmaps from the pixmap cache.
*/
void QGraphicsItemCache::purge()
{
QPixmapCache::remove(key);
key = QPixmapCache::Key();
QMutableMapIterator<QPaintDevice *, DeviceData> it(deviceData);
while (it.hasNext()) {
DeviceData &data = it.next().value();
QPixmapCache::remove(data.key);
data.cacheIndent = QPoint();
}
deviceData.clear();
allExposed = true;
exposed.clear();
}
/*!
Constructs a QGraphicsItem with the given \a parent.
If \a parent is 0, you can add the item to a scene by calling
QGraphicsScene::addItem(). The item will then become a top-level item.
\sa QGraphicsScene::addItem(), setParentItem()
*/
QGraphicsItem::QGraphicsItem(QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: d_ptr(new QGraphicsItemPrivate)
{
d_ptr->q_ptr = this;
setParentItem(parent);
if (scene && parent && parent->scene() != scene) {
qWarning("QGraphicsItem::QGraphicsItem: ignoring scene (%p), which is"
" different from parent's scene (%p)",
scene, parent->scene());
return;
}
if (scene && !parent)
scene->addItem(this);
}
/*!
\internal
*/
QGraphicsItem::QGraphicsItem(QGraphicsItemPrivate &dd, QGraphicsItem *parent,
QGraphicsScene *scene)
: d_ptr(&dd)
{
d_ptr->q_ptr = this;
setParentItem(parent);
if (scene && parent && parent->scene() != scene) {
qWarning("QGraphicsItem::QGraphicsItem: ignoring scene (%p), which is"
" different from parent's scene (%p)",
scene, parent->scene());
return;
}
if (scene && !parent)
scene->addItem(this);
}
/*!
Destroys the QGraphicsItem and all its children. If this item is currently
associated with a scene, the item will be removed from the scene before it
is deleted.
\note It is more efficient to remove the item from the QGraphicsScene before
destroying the item.
*/
QGraphicsItem::~QGraphicsItem()
{
d_ptr->inDestructor = 1;
d_ptr->removeExtraItemCache();
clearFocus();
if (!d_ptr->children.isEmpty()) {
QList<QGraphicsItem *> oldChildren = d_ptr->children;
qDeleteAll(oldChildren);
Q_ASSERT(d_ptr->children.isEmpty());
}
if (d_ptr->scene) {
d_ptr->scene->d_func()->removeItemHelper(this);
} else {
d_ptr->resetFocusProxy();
d_ptr->setParentItemHelper(0);
}
delete d_ptr->graphicsEffect;
if (d_ptr->transformData) {
for(int i = 0; i < d_ptr->transformData->graphicsTransforms.size(); ++i) {
QGraphicsTransform *t = d_ptr->transformData->graphicsTransforms.at(i);
static_cast<QGraphicsTransformPrivate *>(t->d_ptr.data())->item = 0;
delete t;
}
}
delete d_ptr->transformData;
qt_dataStore()->data.remove(this);
}
/*!
Returns the current scene for the item, or 0 if the item is not stored in
a scene.
To add or move an item to a scene, call QGraphicsScene::addItem().
*/
QGraphicsScene *QGraphicsItem::scene() const
{
return d_ptr->scene;
}
/*!
Returns a pointer to this item's item group, or 0 if this item is not
member of a group.
\sa QGraphicsItemGroup, QGraphicsScene::createItemGroup()
*/
QGraphicsItemGroup *QGraphicsItem::group() const
{
if (!d_ptr->isMemberOfGroup)
return 0;
QGraphicsItem *parent = const_cast<QGraphicsItem *>(this);
while ((parent = parent->d_ptr->parent)) {
if (QGraphicsItemGroup *group = qgraphicsitem_cast<QGraphicsItemGroup *>(parent))
return group;
}
// Unreachable; if d_ptr->isMemberOfGroup is != 0, then one parent of this
// item is a group item.
return 0;
}
/*!
Adds this item to the item group \a group. If \a group is 0, this item is
removed from any current group and added as a child of the previous
group's parent.
\sa group(), QGraphicsScene::createItemGroup()
*/
void QGraphicsItem::setGroup(QGraphicsItemGroup *group)
{
if (!group) {
if (QGraphicsItemGroup *group = this->group())
group->removeFromGroup(this);
} else {
group->addToGroup(this);
}
}
/*!
Returns a pointer to this item's parent item. If this item does not have a
parent, 0 is returned.
\sa setParentItem(), childItems()
*/
QGraphicsItem *QGraphicsItem::parentItem() const
{
return d_ptr->parent;
}
/*!
Returns this item's top-level item. The top-level item is the item's
topmost ancestor item whose parent is 0. If an item has no parent, its own
pointer is returned (i.e., a top-level item is its own top-level item).
\sa parentItem()
*/
QGraphicsItem *QGraphicsItem::topLevelItem() const
{
QGraphicsItem *parent = const_cast<QGraphicsItem *>(this);
while (QGraphicsItem *grandPa = parent->parentItem())
parent = grandPa;
return parent;
}
/*!
\since 4.6
Returns a pointer to the item's parent, cast to a QGraphicsObject. returns 0 if the parent item
is not a QGraphicsObject.
\sa parentItem(), childItems()
*/
QGraphicsObject *QGraphicsItem::parentObject() const
{
QGraphicsItem *p = d_ptr->parent;
return (p && p->d_ptr->isObject) ? static_cast<QGraphicsObject *>(p) : 0;
}
/*!
\since 4.4
Returns a pointer to the item's parent widget. The item's parent widget is
the closest parent item that is a widget.
\sa parentItem(), childItems()
*/
QGraphicsWidget *QGraphicsItem::parentWidget() const
{
QGraphicsItem *p = parentItem();
while (p && !p->isWidget())
p = p->parentItem();
return (p && p->isWidget()) ? static_cast<QGraphicsWidget *>(p) : 0;
}
/*!
\since 4.4
Returns a pointer to the item's top level widget (i.e., the item's
ancestor whose parent is 0, or whose parent is not a widget), or 0 if this
item does not have a top level widget. If the item is its own top level
widget, this function returns a pointer to the item itself.
*/
QGraphicsWidget *QGraphicsItem::topLevelWidget() const
{
if (const QGraphicsWidget *p = parentWidget())
return p->topLevelWidget();
return isWidget() ? static_cast<QGraphicsWidget *>(const_cast<QGraphicsItem *>(this)) : 0;
}
/*!
\since 4.4
Returns the item's window, or 0 if this item does not have a window. If
the item is a window, it will return itself. Otherwise it will return the
closest ancestor that is a window.
\sa QGraphicsWidget::isWindow()
*/
QGraphicsWidget *QGraphicsItem::window() const
{
QGraphicsItem *p = panel();
if (p && p->isWindow())
return static_cast<QGraphicsWidget *>(p);
return 0;
}
/*!
\since 4.6
Returns the item's panel, or 0 if this item does not have a panel. If the
item is a panel, it will return itself. Otherwise it will return the
closest ancestor that is a panel.
\sa isPanel(), ItemIsPanel
*/
QGraphicsItem *QGraphicsItem::panel() const
{
if (d_ptr->flags & ItemIsPanel)
return const_cast<QGraphicsItem *>(this);
return d_ptr->parent ? d_ptr->parent->panel() : 0;
}
/*!
\since 4.6
Return the graphics item cast to a QGraphicsObject, if the class is actually a
graphics object, 0 otherwise.
*/
QGraphicsObject *QGraphicsItem::toGraphicsObject()
{
return d_ptr->isObject ? static_cast<QGraphicsObject *>(this) : 0;
}
/*!
\since 4.6
Return the graphics item cast to a QGraphicsObject, if the class is actually a
graphics object, 0 otherwise.
*/
const QGraphicsObject *QGraphicsItem::toGraphicsObject() const
{
return d_ptr->isObject ? static_cast<const QGraphicsObject *>(this) : 0;
}
/*!
Sets this item's parent item to \a parent. If this item already has a
parent, it is first removed from the previous parent. If \a parent is 0,
this item will become a top-level item.
Note that this implicitly adds this graphics item to the scene of
the parent. You should not \l{QGraphicsScene::addItem()}{add} the
item to the scene yourself.
\sa parentItem(), childItems()
*/
void QGraphicsItem::setParentItem(QGraphicsItem *parent)
{
d_ptr->setParentItemHelper(parent);
}
/*!
\obsolete
Use childItems() instead.
\sa setParentItem()
*/
QList<QGraphicsItem *> QGraphicsItem::children() const
{
return childItems();
}
/*!
\since 4.4
Returns a list of this item's children. The items are returned in no
particular order.
\sa setParentItem()
*/
QList<QGraphicsItem *> QGraphicsItem::childItems() const
{
return d_ptr->children;
}
/*!
\since 4.4
Returns true if this item is a widget (i.e., QGraphicsWidget); otherwise,
returns false.
*/
bool QGraphicsItem::isWidget() const
{
return d_ptr->isWidget;
}
/*!
\since 4.4
Returns true if the item is a QGraphicsWidget window, otherwise returns
false.
\sa QGraphicsWidget::windowFlags()
*/
bool QGraphicsItem::isWindow() const
{
return isWidget() && (static_cast<const QGraphicsWidget *>(this)->windowType() & Qt::Window);
}
/*!
\since 4.6
Returns true if the item is a panel; otherwise returns false.
\sa QGraphicsItem::panel(), ItemIsPanel
*/
bool QGraphicsItem::isPanel() const
{
return d_ptr->flags & ItemIsPanel;
}
/*!
Returns this item's flags. The flags describe what configurable features
of the item are enabled and not. For example, if the flags include
ItemIsFocusable, the item can accept input focus.
By default, no flags are enabled.
\sa setFlags(), setFlag()
*/
QGraphicsItem::GraphicsItemFlags QGraphicsItem::flags() const
{
return GraphicsItemFlags(d_ptr->flags);
}
/*!
If \a enabled is true, the item flag \a flag is enabled; otherwise, it is
disabled.
\sa flags(), setFlags()
*/
void QGraphicsItem::setFlag(GraphicsItemFlag flag, bool enabled)
{
if (enabled)
setFlags(flags() | flag);
else
setFlags(flags() & ~flag);
}
/*!
\internal
Sets the flag \a flag on \a item and all its children, to \a enabled.
*/
static void _q_qgraphicsItemSetFlag(QGraphicsItem *item, QGraphicsItem::GraphicsItemFlag flag,
bool enabled)
{
if (item->flags() & flag) {
// If this item already has the correct flag set, we don't have to
// propagate it.
return;
}
item->setFlag(flag, enabled);
foreach (QGraphicsItem *child, item->children())
_q_qgraphicsItemSetFlag(child, flag, enabled);
}
/*!
Sets the item flags to \a flags. All flags in \a flags are enabled; all
flags not in \a flags are disabled.
If the item had focus and \a flags does not enable ItemIsFocusable, the
item loses focus as a result of calling this function. Similarly, if the
item was selected, and \a flags does not enabled ItemIsSelectable, the
item is automatically unselected.
By default, no flags are enabled. (QGraphicsWidget enables the
ItemSendsGeometryChanges flag by default in order to track position
changes.)
\sa flags(), setFlag()
*/
void QGraphicsItem::setFlags(GraphicsItemFlags flags)
{
if (isWindow())
flags |= ItemIsPanel;
// Notify change and check for adjustment.
if (quint32(d_ptr->flags) == quint32(flags))
return;
flags = GraphicsItemFlags(itemChange(ItemFlagsChange, quint32(flags)).toUInt());
if (quint32(d_ptr->flags) == quint32(flags))
return;
if (d_ptr->scene)
d_ptr->scene->d_func()->index->itemChange(this, ItemFlagsChange, quint32(flags));
// Flags that alter the geometry of the item (or its children).
const quint32 geomChangeFlagsMask = (ItemClipsChildrenToShape | ItemClipsToShape | ItemIgnoresTransformations);
bool fullUpdate = (quint32(flags) & geomChangeFlagsMask) != (d_ptr->flags & geomChangeFlagsMask);
if (fullUpdate)
d_ptr->paintedViewBoundingRectsNeedRepaint = 1;
// Keep the old flags to compare the diff.
GraphicsItemFlags oldFlags = this->flags();
// Update flags.
d_ptr->flags = flags;
if (!(d_ptr->flags & ItemIsFocusable) && hasFocus()) {
// Clear focus on the item if it has focus when the focusable flag
// is unset.
clearFocus();
}
if (!(d_ptr->flags & ItemIsSelectable) && isSelected()) {
// Unselect the item if it is selected when the selectable flag is
// unset.
setSelected(false);
}
if ((flags & ItemClipsChildrenToShape) != (oldFlags & ItemClipsChildrenToShape)) {
// Item children clipping changes. Propagate the ancestor flag to
// all children.
d_ptr->updateAncestorFlag(ItemClipsChildrenToShape);
}
if ((flags & ItemClipsToShape) != (oldFlags & ItemClipsToShape))
d_ptr->invalidateCachedClipPath();
if ((flags & ItemIgnoresTransformations) != (oldFlags & ItemIgnoresTransformations)) {
// Item children clipping changes. Propagate the ancestor flag to
// all children.
d_ptr->updateAncestorFlag(ItemIgnoresTransformations);
}
if ((flags & ItemStacksBehindParent) != (oldFlags & ItemStacksBehindParent)) {
// Ensure child item sorting is up to date when toggling this flag.
if (d_ptr->parent)
d_ptr->parent->d_ptr->needSortChildren = 1;
else if (d_ptr->scene)
d_ptr->scene->d_func()->needSortTopLevelItems = 1;
}
if ((flags & ItemAcceptsInputMethod) != (oldFlags & ItemAcceptsInputMethod)) {
// Update input method sensitivity in any views.
if (d_ptr->scene)
d_ptr->scene->d_func()->updateInputMethodSensitivityInViews();
}
if ((flags & ItemNegativeZStacksBehindParent) != (oldFlags & ItemNegativeZStacksBehindParent)) {
// Update stack-behind.
setFlag(ItemStacksBehindParent, d_ptr->z < qreal(0.0));
}
if (d_ptr->scene) {
d_ptr->scene->d_func()->markDirty(this, QRectF(),
/*invalidateChildren=*/true,
/*maybeDirtyClipPath*/true);
}
// Notify change.
itemChange(ItemFlagsHaveChanged, quint32(flags));
}
/*!
\since 4.4
Returns the cache mode for this item. The default mode is NoCache (i.e.,
cache is disabled and all painting is immediate).
\sa setCacheMode()
*/
QGraphicsItem::CacheMode QGraphicsItem::cacheMode() const
{
return QGraphicsItem::CacheMode(d_ptr->cacheMode);
}
/*!
\since 4.4
Sets the item's cache mode to \a mode.
The optional \a logicalCacheSize argument is used only by
ItemCoordinateCache mode, and describes the resolution of the cache
buffer; if \a logicalCacheSize is (100, 100), QGraphicsItem will fit the
item into 100x100 pixels in graphics memory, regardless of the logical
size of the item itself. By default QGraphicsItem uses the size of
boundingRect(). For all other cache modes than ItemCoordinateCache, \a
logicalCacheSize is ignored.
Caching can speed up rendering if your item spends a significant time
redrawing itself. In some cases the cache can also slow down rendering, in
particular when the item spends less time redrawing than QGraphicsItem
spends redrawing from the cache. When enabled, the item's paint() function
will be called only once for each call to update(); for any subsequent
repaint requests, the Graphics View framework will redraw from the
cache. This approach works particularly well with QGLWidget, which stores
all the cache as OpenGL textures.
Be aware that QPixmapCache's cache limit may need to be changed to obtain
optimal performance.
You can read more about the different cache modes in the CacheMode
documentation.
\sa CacheMode, QPixmapCache::setCacheLimit()
*/
void QGraphicsItem::setCacheMode(CacheMode mode, const QSize &logicalCacheSize)
{
CacheMode lastMode = CacheMode(d_ptr->cacheMode);
d_ptr->cacheMode = mode;
bool noVisualChange = (mode == NoCache && lastMode == NoCache)
|| (mode == NoCache && lastMode == DeviceCoordinateCache)
|| (mode == DeviceCoordinateCache && lastMode == NoCache);
if (mode == NoCache) {
d_ptr->removeExtraItemCache();
} else {
QGraphicsItemCache *cache = d_ptr->extraItemCache();
// Reset old cache
cache->purge();
if (mode == ItemCoordinateCache) {
if (lastMode == mode && cache->fixedSize == logicalCacheSize)
noVisualChange = true;
cache->fixedSize = logicalCacheSize;
}
}
if (!noVisualChange)
update();
}
#ifndef QT_NO_TOOLTIP
/*!
Returns the item's tool tip, or an empty QString if no tool tip has been
set.
\sa setToolTip(), QToolTip
*/
QString QGraphicsItem::toolTip() const
{
return d_ptr->extra(QGraphicsItemPrivate::ExtraToolTip).toString();
}
/*!
Sets the item's tool tip to \a toolTip. If \a toolTip is empty, the item's
tool tip is cleared.
\sa toolTip(), QToolTip
*/
void QGraphicsItem::setToolTip(const QString &toolTip)
{
const QVariant toolTipVariant(itemChange(ItemToolTipChange, toolTip));
d_ptr->setExtra(QGraphicsItemPrivate::ExtraToolTip, toolTipVariant.toString());
itemChange(ItemToolTipHasChanged, toolTipVariant);
}
#endif // QT_NO_TOOLTIP
#ifndef QT_NO_CURSOR
/*!
Returns the current cursor shape for the item. The mouse cursor
will assume this shape when it's over this item. See the \link
Qt::CursorShape list of predefined cursor objects\endlink for a
range of useful shapes.
An editor item might want to use an I-beam cursor:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 2
If no cursor has been set, the parent's cursor is used.
\sa setCursor(), hasCursor(), unsetCursor(), QWidget::cursor,
QApplication::overrideCursor()
*/
QCursor QGraphicsItem::cursor() const
{
return qVariantValue<QCursor>(d_ptr->extra(QGraphicsItemPrivate::ExtraCursor));
}
/*!
Sets the current cursor shape for the item to \a cursor. The mouse cursor
will assume this shape when it's over this item. See the \link
Qt::CursorShape list of predefined cursor objects\endlink for a range of
useful shapes.
An editor item might want to use an I-beam cursor:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 3
If no cursor has been set, the cursor of the item beneath is used.
\sa cursor(), hasCursor(), unsetCursor(), QWidget::cursor,
QApplication::overrideCursor()
*/
void QGraphicsItem::setCursor(const QCursor &cursor)
{
const QVariant cursorVariant(itemChange(ItemCursorChange, qVariantFromValue<QCursor>(cursor)));
d_ptr->setExtra(QGraphicsItemPrivate::ExtraCursor, qVariantValue<QCursor>(cursorVariant));
d_ptr->hasCursor = 1;
if (d_ptr->scene) {
d_ptr->scene->d_func()->allItemsUseDefaultCursor = false;
foreach (QGraphicsView *view, d_ptr->scene->views()) {
view->viewport()->setMouseTracking(true);
// Note: Some of this logic is duplicated in QGraphicsView's mouse events.
if (view->underMouse()) {
foreach (QGraphicsItem *itemUnderCursor, view->items(view->mapFromGlobal(QCursor::pos()))) {
if (itemUnderCursor->hasCursor()) {
QMetaObject::invokeMethod(view, "_q_setViewportCursor",
Q_ARG(QCursor, itemUnderCursor->cursor()));
break;
}
}
break;
}
}
}
itemChange(ItemCursorHasChanged, cursorVariant);
}
/*!
Returns true if this item has a cursor set; otherwise, false is returned.
By default, items don't have any cursor set. cursor() will return a
standard pointing arrow cursor.
\sa unsetCursor()
*/
bool QGraphicsItem::hasCursor() const
{
return d_ptr->hasCursor;
}
/*!
Clears the cursor from this item.
\sa hasCursor(), setCursor()
*/
void QGraphicsItem::unsetCursor()
{
d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraCursor);
d_ptr->hasCursor = 0;
if (d_ptr->scene) {
foreach (QGraphicsView *view, d_ptr->scene->views()) {
if (view->underMouse() && view->itemAt(view->mapFromGlobal(QCursor::pos())) == this) {
QMetaObject::invokeMethod(view, "_q_unsetViewportCursor");
break;
}
}
}
}
#endif // QT_NO_CURSOR
/*!
Returns true if the item is visible; otherwise, false is returned.
Note that the item's general visibility is unrelated to whether or not it
is actually being visualized by a QGraphicsView.
\sa setVisible()
*/
bool QGraphicsItem::isVisible() const
{
return d_ptr->visible;
}
/*!
\since 4.4
Returns true if the item is visible to \a parent; otherwise, false is
returned. \a parent can be 0, in which case this function will return
whether the item is visible to the scene or not.
An item may not be visible to its ancestors even if isVisible() is true. If
any ancestor is hidden, the item itself will be implicitly hidden, in which
case this function will return false.
\sa isVisible(), setVisible()
*/
bool QGraphicsItem::isVisibleTo(const QGraphicsItem *parent) const
{
if (!d_ptr->visible)
return false;
if (parent == this)
return true;
if (parentItem() && parentItem()->isVisibleTo(parent))
return true;
if (!parent && !parentItem())
return true;
return false;
}
/*!
\internal
Sets this item's visibility to \a newVisible. If \a explicitly is true,
this item will be "explicitly" \a newVisible; otherwise, it.. will not be.
*/
void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bool update)
{
Q_Q(QGraphicsItem);
// Update explicit bit.
if (explicitly)
explicitlyHidden = newVisible ? 0 : 1;
// Check if there's nothing to do.
if (visible == quint32(newVisible))
return;
// Don't show child if parent is not visible
if (parent && newVisible && !parent->d_ptr->visible)
return;
// Modify the property.
const QVariant newVisibleVariant(q_ptr->itemChange(QGraphicsItem::ItemVisibleChange,
quint32(newVisible)));
newVisible = newVisibleVariant.toBool();
if (visible == quint32(newVisible))
return;
visible = newVisible;
// Schedule redrawing
if (update) {
QGraphicsItemCache *c = (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData));
if (c)
c->purge();
if (scene) {
scene->d_func()->markDirty(q_ptr, QRectF(),
/*invalidateChildren=*/false,
/*maybeDirtyClipPath=*/false,
/*force=*/true);
}
}
// Certain properties are dropped as an item becomes invisible.
if (!newVisible) {
if (scene) {
if (scene->d_func()->mouseGrabberItems.contains(q))
q->ungrabMouse();
if (scene->d_func()->keyboardGrabberItems.contains(q))
q->ungrabKeyboard();
}
if (q_ptr->hasFocus() && scene) {
// Hiding the closest non-panel ancestor of the focus item
QGraphicsItem *focusItem = scene->focusItem();
bool clear = true;
if (isWidget && !focusItem->isPanel()) {
do {
if (focusItem == q_ptr) {
clear = !static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true);
break;
}
} while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());
}
if (clear)
q_ptr->clearFocus();
}
if (q_ptr->isSelected())
q_ptr->setSelected(false);
} else {
geometryChanged = 1;
paintedViewBoundingRectsNeedRepaint = 1;
if (isWidget && scene) {
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(q_ptr);
if (widget->windowType() == Qt::Popup)
scene->d_func()->addPopup(widget);
}
}
// Update children with explicitly = false.
const bool updateChildren = update && !(flags & QGraphicsItem::ItemClipsChildrenToShape);
foreach (QGraphicsItem *child, children) {
if (!newVisible || !child->d_ptr->explicitlyHidden)
child->d_ptr->setVisibleHelper(newVisible, false, updateChildren);
}
// Enable subfocus
if (newVisible && isWidget) {
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(q_ptr);
QGraphicsWidget *fw = widget->focusWidget();
if (fw && fw != scene->focusItem())
scene->setFocusItem(fw);
}
// Deliver post-change notification.
q_ptr->itemChange(QGraphicsItem::ItemVisibleHasChanged, newVisibleVariant);
if (isObject)
emit static_cast<QGraphicsObject *>(q_ptr)->visibleChanged();
}
/*!
If \a visible is true, the item is made visible. Otherwise, the item is
made invisible. Invisible items are not painted, nor do they receive any
events. In particular, mouse events pass right through invisible items,
and are delivered to any item that may be behind. Invisible items are also
unselectable, they cannot take input focus, and are not detected by
QGraphicsScene's item location functions.
If an item becomes invisible while grabbing the mouse, (i.e., while it is
receiving mouse events,) it will automatically lose the mouse grab, and
the grab is not regained by making the item visible again; it must receive
a new mouse press to regain the mouse grab.
Similarly, an invisible item cannot have focus, so if the item has focus
when it becomes invisible, it will lose focus, and the focus is not
regained by simply making the item visible again.
If you hide a parent item, all its children will also be hidden. If you
show a parent item, all children will be shown, unless they have been
explicitly hidden (i.e., if you call setVisible(false) on a child, it will
not be reshown even if its parent is hidden, and then shown again).
Items are visible by default; it is unnecessary to call
setVisible() on a new item.
\sa isVisible(), show(), hide()
*/
void QGraphicsItem::setVisible(bool visible)
{
d_ptr->setVisibleHelper(visible, /* explicit = */ true);
}
/*!
\fn void QGraphicsItem::hide()
Hides the item. (Items are visible by default.)
This convenience function is equivalent to calling \c setVisible(false).
\sa show(), setVisible()
*/
/*!
\fn void QGraphicsItem::show()
Shows the item. (Items are visible by default.)
This convenience function is equivalent to calling \c setVisible(true).
\sa hide(), setVisible()
*/
/*!
Returns true if the item is enabled; otherwise, false is returned.
\sa setEnabled()
*/
bool QGraphicsItem::isEnabled() const
{
return d_ptr->enabled;
}
/*!
\internal
Sets this item's visibility to \a newEnabled. If \a explicitly is true,
this item will be "explicitly" \a newEnabled; otherwise, it.. will not be.
*/
void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bool update)
{
// Update explicit bit.
if (explicitly)
explicitlyDisabled = newEnabled ? 0 : 1;
// Check if there's nothing to do.
if (enabled == quint32(newEnabled))
return;
// Certain properties are dropped when an item is disabled.
if (!newEnabled) {
if (scene && scene->mouseGrabberItem() == q_ptr)
q_ptr->ungrabMouse();
if (q_ptr->hasFocus()) {
// Disabling the closest non-panel ancestor of the focus item
// causes focus to pop to the next item, otherwise it's cleared.
QGraphicsItem *focusItem = scene->focusItem();
bool clear = true;
if (isWidget && !focusItem->isPanel() && q_ptr->isAncestorOf(focusItem)) {
do {
if (focusItem == q_ptr) {
clear = !static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true);
break;
}
} while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());
}
if (clear)
q_ptr->clearFocus();
}
if (q_ptr->isSelected())
q_ptr->setSelected(false);
}
// Modify the property.
const QVariant newEnabledVariant(q_ptr->itemChange(QGraphicsItem::ItemEnabledChange,
quint32(newEnabled)));
enabled = newEnabledVariant.toBool();
// Schedule redraw.
if (update)
q_ptr->update();
foreach (QGraphicsItem *child, children) {
if (!newEnabled || !child->d_ptr->explicitlyDisabled)
child->d_ptr->setEnabledHelper(newEnabled, /* explicitly = */ false);
}
// Deliver post-change notification.
q_ptr->itemChange(QGraphicsItem::ItemEnabledHasChanged, newEnabledVariant);
if (isObject)
emit static_cast<QGraphicsObject *>(q_ptr)->enabledChanged();
}
/*!
If \a enabled is true, the item is enabled; otherwise, it is disabled.
Disabled items are visible, but they do not receive any events, and cannot
take focus nor be selected. Mouse events are discarded; they are not
propagated unless the item is also invisible, or if it does not accept
mouse events (see acceptedMouseButtons()). A disabled item cannot become the
mouse grabber, and as a result of this, an item loses the grab if it
becomes disabled when grabbing the mouse, just like it loses focus if it
had focus when it was disabled.
Disabled items are traditionally drawn using grayed-out colors (see \l
QPalette::Disabled).
If you disable a parent item, all its children will also be disabled. If
you enable a parent item, all children will be enabled, unless they have
been explicitly disabled (i.e., if you call setEnabled(false) on a child,
it will not be reenabled if its parent is disabled, and then enabled
again).
Items are enabled by default.
\note If you install an event filter, you can still intercept events
before they are delivered to items; this mechanism disregards the item's
enabled state.
\sa isEnabled()
*/
void QGraphicsItem::setEnabled(bool enabled)
{
d_ptr->setEnabledHelper(enabled, /* explicitly = */ true);
}
/*!
Returns true if this item is selected; otherwise, false is returned.
Items that are in a group inherit the group's selected state.
Items are not selected by default.
\sa setSelected(), QGraphicsScene::setSelectionArea()
*/
bool QGraphicsItem::isSelected() const
{
if (QGraphicsItemGroup *group = this->group())
return group->isSelected();
return d_ptr->selected;
}
/*!
If \a selected is true and this item is selectable, this item is selected;
otherwise, it is unselected.
If the item is in a group, the whole group's selected state is toggled by
this function. If the group is selected, all items in the group are also
selected, and if the group is not selected, no item in the group is
selected.
Only visible, enabled, selectable items can be selected. If \a selected
is true and this item is either invisible or disabled or unselectable,
this function does nothing.
By default, items cannot be selected. To enable selection, set the
ItemIsSelectable flag.
This function is provided for convenience, allowing individual toggling of
the selected state of an item. However, a more common way of selecting
items is to call QGraphicsScene::setSelectionArea(), which will call this
function for all visible, enabled, and selectable items within a specified
area on the scene.
\sa isSelected(), QGraphicsScene::selectedItems()
*/
void QGraphicsItem::setSelected(bool selected)
{
if (QGraphicsItemGroup *group = this->group()) {
group->setSelected(selected);
return;
}
if (!(d_ptr->flags & ItemIsSelectable) || !d_ptr->enabled || !d_ptr->visible)
selected = false;
if (d_ptr->selected == selected)
return;
const QVariant newSelectedVariant(itemChange(ItemSelectedChange, quint32(selected)));
bool newSelected = newSelectedVariant.toBool();
if (d_ptr->selected == newSelected)
return;
d_ptr->selected = newSelected;
update();
if (d_ptr->scene) {
QGraphicsScenePrivate *sceneD = d_ptr->scene->d_func();
if (selected) {
sceneD->selectedItems << this;
} else {
// QGraphicsScene::selectedItems() lazily pulls out all items that are
// no longer selected.
}
if (!sceneD->selectionChanging)
emit d_ptr->scene->selectionChanged();
}
// Deliver post-change notification.
itemChange(QGraphicsItem::ItemSelectedHasChanged, newSelectedVariant);
}
/*!
\since 4.5
Returns this item's local opacity, which is between 0.0 (transparent) and
1.0 (opaque). This value is combined with parent and ancestor values into
the effectiveOpacity(). The effective opacity decides how the item is
rendered.
The opacity property decides the state of the painter passed to the
paint() function. If the item is cached, i.e., ItemCoordinateCache or
DeviceCoordinateCache, the effective property will be applied to the item's
cache as it is rendered.
The default opacity is 1.0; fully opaque.
\sa setOpacity(), paint(), ItemIgnoresParentOpacity,
ItemDoesntPropagateOpacityToChildren
*/
qreal QGraphicsItem::opacity() const
{
return d_ptr->opacity;
}
/*!
\since 4.5
Returns this item's \e effective opacity, which is between 0.0
(transparent) and 1.0 (opaque). This value is a combination of this item's
local opacity, and its parent and ancestors' opacities. The effective
opacity decides how the item is rendered.
\sa opacity(), setOpacity(), paint(), ItemIgnoresParentOpacity,
ItemDoesntPropagateOpacityToChildren
*/
qreal QGraphicsItem::effectiveOpacity() const
{
return d_ptr->effectiveOpacity();
}
/*!
\since 4.5
Sets this item's local \a opacity, between 0.0 (transparent) and 1.0
(opaque). The item's local opacity is combined with parent and ancestor
opacities into the effectiveOpacity().
By default, opacity propagates from parent to child, so if a parent's
opacity is 0.5 and the child is also 0.5, the child's effective opacity
will be 0.25.
The opacity property decides the state of the painter passed to the
paint() function. If the item is cached, i.e., ItemCoordinateCache or
DeviceCoordinateCache, the effective property will be applied to the
item's cache as it is rendered.
There are two item flags that affect how the item's opacity is combined
with the parent: ItemIgnoresParentOpacity and
ItemDoesntPropagateOpacityToChildren.
\sa opacity(), effectiveOpacity()
*/
void QGraphicsItem::setOpacity(qreal opacity)
{
// Notify change.
const QVariant newOpacityVariant(itemChange(ItemOpacityChange, opacity));
// Normalized opacity
qreal newOpacity = qBound(qreal(0), newOpacityVariant.toReal(), qreal(1));
// No change? Done.
if (newOpacity == d_ptr->opacity)
return;
d_ptr->opacity = newOpacity;
// Notify change.
itemChange(ItemOpacityHasChanged, newOpacityVariant);
// Update.
if (d_ptr->scene)
d_ptr->scene->d_func()->markDirty(this, QRectF(),
/*invalidateChildren=*/true,
/*maybeDirtyClipPath=*/false,
/*force=*/false,
/*ignoreOpacity=*/true);
if (d_ptr->isObject)
emit static_cast<QGraphicsObject *>(this)->opacityChanged();
}
/*!
Returns a pointer to this item's effect if it has one; otherwise 0.
\since 4.6
*/
QGraphicsEffect *QGraphicsItem::graphicsEffect() const
{
return d_ptr->graphicsEffect;
}
/*!
Sets \a effect as the item's effect. If there already is an effect installed
on this item, QGraphicsItem will delete the existing effect before installing
the new \a effect.
If \a effect is the installed on a different item, setGraphicsEffect() will remove
the effect from the item and install it on this item.
\note This function will apply the effect on itself and all its children.
\since 4.6
*/
void QGraphicsItem::setGraphicsEffect(QGraphicsEffect *effect)
{
if (d_ptr->graphicsEffect == effect)
return;
if (d_ptr->graphicsEffect && effect) {
delete d_ptr->graphicsEffect;
d_ptr->graphicsEffect = 0;
}
if (!effect) {
// Unset current effect.
QGraphicsEffectPrivate *oldEffectPrivate = d_ptr->graphicsEffect->d_func();
d_ptr->graphicsEffect = 0;
if (oldEffectPrivate) {
oldEffectPrivate->setGraphicsEffectSource(0); // deletes the current source.
if (d_ptr->scene) // Update the views directly.
d_ptr->scene->d_func()->markDirty(this, QRectF(), false, false, false, false, true);
}
} else {
// Set new effect.
QGraphicsEffectSourcePrivate *sourced = new QGraphicsItemEffectSourcePrivate(this);
QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced);
d_ptr->graphicsEffect = effect;
effect->d_func()->setGraphicsEffectSource(source);
}
prepareGeometryChange();
}
/*!
\internal
\since 4.6
Returns the effective bounding rect of the item.
If the item has no effect, this is the same as the item's bounding rect.
If the item has an effect, the effective rect can be larger than the item's
bouding rect, depending on the effect.
\sa boundingRect()
*/
QRectF QGraphicsItemPrivate::effectiveBoundingRect() const
{
QGraphicsEffect *effect = graphicsEffect;
QRectF brect = effect && effect->isEnabled() ? effect->boundingRect() : q_ptr->boundingRect();
if (ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)
return brect;
const QGraphicsItem *effectParent = parent;
while (effectParent) {
effect = effectParent->d_ptr->graphicsEffect;
if (effect && effect->isEnabled())
brect = effect->boundingRectFor(brect);
if (effectParent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)
return brect;
effectParent = effectParent->d_ptr->parent;
}
return brect;
}
/*!
\internal
\since 4.6
Returns the effective bounding rect of this item in scene coordinates,
by combining sceneTransform() with boundingRect(), taking into account
the effect that the item might have.
If the item has no effect, this is the same as sceneBoundingRect().
\sa effectiveBoundingRect(), sceneBoundingRect()
*/
QRectF QGraphicsItemPrivate::sceneEffectiveBoundingRect() const
{
// Find translate-only offset
// COMBINE
QPointF offset;
const QGraphicsItem *parentItem = q_ptr;
const QGraphicsItemPrivate *itemd;
do {
itemd = parentItem->d_ptr.data();
if (itemd->transformData)
break;
offset += itemd->pos;
} while ((parentItem = itemd->parent));
QRectF br = effectiveBoundingRect();
br.translate(offset);
return !parentItem ? br : parentItem->sceneTransform().mapRect(br);
}
/*!
Returns true if this item can accept drag and drop events; otherwise,
returns false. By default, items do not accept drag and drop events; items
are transparent to drag and drop.
\sa setAcceptDrops()
*/
bool QGraphicsItem::acceptDrops() const
{
return d_ptr->acceptDrops;
}
/*!
If \a on is true, this item will accept drag and drop events; otherwise,
it is transparent for drag and drop events. By default, items do not
accept drag and drop events.
\sa acceptDrops()
*/
void QGraphicsItem::setAcceptDrops(bool on)
{
d_ptr->acceptDrops = on;
}
/*!
Returns the mouse buttons that this item accepts mouse events for. By
default, all mouse buttons are accepted.
If an item accepts a mouse button, it will become the mouse
grabber item when a mouse press event is delivered for that mouse
button. However, if the item does not accept the button,
QGraphicsScene will forward the mouse events to the first item
beneath it that does.
\sa setAcceptedMouseButtons(), mousePressEvent()
*/
Qt::MouseButtons QGraphicsItem::acceptedMouseButtons() const
{
return Qt::MouseButtons(d_ptr->acceptedMouseButtons);
}
/*!
Sets the mouse \a buttons that this item accepts mouse events for.
By default, all mouse buttons are accepted. If an item accepts a
mouse button, it will become the mouse grabber item when a mouse
press event is delivered for that button. However, if the item
does not accept the mouse button, QGraphicsScene will forward the
mouse events to the first item beneath it that does.
To disable mouse events for an item (i.e., make it transparent for mouse
events), call setAcceptedMouseButtons(0).
\sa acceptedMouseButtons(), mousePressEvent()
*/
void QGraphicsItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
{
if (Qt::MouseButtons(d_ptr->acceptedMouseButtons) != buttons) {
if (buttons == 0 && d_ptr->scene && d_ptr->scene->mouseGrabberItem() == this
&& d_ptr->scene->d_func()->lastMouseGrabberItemHasImplicitMouseGrab) {
ungrabMouse();
}
d_ptr->acceptedMouseButtons = quint32(buttons);
}
}
/*!
\since 4.4
Returns true if an item accepts hover events
(QGraphicsSceneHoverEvent); otherwise, returns false. By default,
items do not accept hover events.
\sa setAcceptedMouseButtons()
*/
bool QGraphicsItem::acceptHoverEvents() const
{
return d_ptr->acceptsHover;
}
/*!
\obsolete
Call acceptHoverEvents() instead.
*/
bool QGraphicsItem::acceptsHoverEvents() const
{
return d_ptr->acceptsHover;
}
/*!
\since 4.4
If \a enabled is true, this item will accept hover events;
otherwise, it will ignore them. By default, items do not accept
hover events.
Hover events are delivered when there is no current mouse grabber
item. They are sent when the mouse cursor enters an item, when it
moves around inside the item, and when the cursor leaves an
item. Hover events are commonly used to highlight an item when
it's entered, and for tracking the mouse cursor as it hovers over
the item (equivalent to QWidget::mouseTracking).
Parent items receive hover enter events before their children, and
leave events after their children. The parent does not receive a
hover leave event if the cursor enters a child, though; the parent
stays "hovered" until the cursor leaves its area, including its
children's areas.
If a parent item handles child events, it will receive hover move,
drag move, and drop events as the cursor passes through its
children, but it does not receive hover enter and hover leave, nor
drag enter and drag leave events on behalf of its children.
A QGraphicsWidget with window decorations will accept hover events
regardless of the value of acceptHoverEvents().
\sa acceptHoverEvents(), hoverEnterEvent(), hoverMoveEvent(),
hoverLeaveEvent()
*/
void QGraphicsItem::setAcceptHoverEvents(bool enabled)
{
if (d_ptr->acceptsHover == quint32(enabled))
return;
d_ptr->acceptsHover = quint32(enabled);
if (d_ptr->acceptsHover && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreHoverEvents) {
d_ptr->scene->d_func()->allItemsIgnoreHoverEvents = false;
d_ptr->scene->d_func()->enableMouseTrackingOnViews();
}
}
/*!
\obsolete
Use setAcceptHoverEvents(\a enabled) instead.
*/
void QGraphicsItem::setAcceptsHoverEvents(bool enabled)
{
setAcceptHoverEvents(enabled);
}
/*! \since 4.6
Returns true if an item accepts \l{QTouchEvent}{touch events};
otherwise, returns false. By default, items do not accept touch events.
\sa setAcceptTouchEvents()
*/
bool QGraphicsItem::acceptTouchEvents() const
{
return d_ptr->acceptTouchEvents;
}
/*!
\since 4.6
If \a enabled is true, this item will accept \l{QTouchEvent}{touch events};
otherwise, it will ignore them. By default, items do not accept
touch events.
*/
void QGraphicsItem::setAcceptTouchEvents(bool enabled)
{
if (d_ptr->acceptTouchEvents == quint32(enabled))
return;
d_ptr->acceptTouchEvents = quint32(enabled);
if (d_ptr->acceptTouchEvents && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreTouchEvents) {
d_ptr->scene->d_func()->allItemsIgnoreTouchEvents = false;
d_ptr->scene->d_func()->enableTouchEventsOnViews();
}
}
/*!
\since 4.6
Returns true if this item filters child events (i.e., all events
intended for any of its children are instead sent to this item);
otherwise, false is returned.
The default value is false; child events are not filtered.
\sa setFiltersChildEvents()
*/
bool QGraphicsItem::filtersChildEvents() const
{
return d_ptr->filtersDescendantEvents;
}
/*!
\since 4.6
If \a enabled is true, this item is set to filter all events for
all its children (i.e., all events intented for any of its
children are instead sent to this item); otherwise, if \a enabled
is false, this item will only handle its own events. The default
value is false.
\sa filtersChildEvents()
*/
void QGraphicsItem::setFiltersChildEvents(bool enabled)
{
if (d_ptr->filtersDescendantEvents == enabled)
return;
d_ptr->filtersDescendantEvents = enabled;
d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-2));
}
/*!
\obsolete
Returns true if this item handles child events (i.e., all events
intended for any of its children are instead sent to this item);
otherwise, false is returned.
This property is useful for item groups; it allows one item to
handle events on behalf of its children, as opposed to its
children handling their events individually.
The default is to return false; children handle their own events.
The exception for this is if the item is a QGraphicsItemGroup, then
it defaults to return true.
\sa setHandlesChildEvents()
*/
bool QGraphicsItem::handlesChildEvents() const
{
return d_ptr->handlesChildEvents;
}
/*!
\obsolete
If \a enabled is true, this item is set to handle all events for
all its children (i.e., all events intented for any of its
children are instead sent to this item); otherwise, if \a enabled
is false, this item will only handle its own events. The default
value is false.
This property is useful for item groups; it allows one item to
handle events on behalf of its children, as opposed to its
children handling their events individually.
If a child item accepts hover events, its parent will receive
hover move events as the cursor passes through the child, but it
does not receive hover enter and hover leave events on behalf of
its child.
\sa handlesChildEvents()
*/
void QGraphicsItem::setHandlesChildEvents(bool enabled)
{
if (d_ptr->handlesChildEvents == enabled)
return;
d_ptr->handlesChildEvents = enabled;
d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1));
}
/*!
\since 4.6
Returns true if this item is active; otherwise returns false.
An item can only be active if the scene is active. An item is active
if it is, or is a descendent of, an active panel. Items in non-active
panels are not active.
Items that are not part of a panel follow scene activation when the
scene has no active panel.
Only active items can gain input focus.
\sa QGraphicsScene::isActive(), QGraphicsScene::activePanel(), panel(), isPanel()
*/
bool QGraphicsItem::isActive() const
{
if (!d_ptr->scene || !d_ptr->scene->isActive())
return false;
return panel() == d_ptr->scene->activePanel();
}
/*!
Returns true if this item is active, and it or its \l{focusProxy()}{focus
proxy} has keyboard input focus; otherwise, returns false.
\sa focusItem(), setFocus(), QGraphicsScene::setFocusItem(), isActive()
*/
bool QGraphicsItem::hasFocus() const
{
if (d_ptr->focusProxy)
return d_ptr->focusProxy->hasFocus();
return (d_ptr->scene && d_ptr->scene->focusItem() == this);
}
/*!
Gives keyboard input focus to this item. The \a focusReason argument will
be passed into any \l{QFocusEvent}{focus event} generated by this function;
it is used to give an explanation of what caused the item to get focus.
Only enabled items that set the ItemIsFocusable flag can accept keyboard
focus.
If this item is not visible, not active, or not associated with a scene,
it will not gain immediate input focus. However, it will be registered as
the preferred focus item for its subtree of items, should it later become
visible.
As a result of calling this function, this item will receive a
\l{focusInEvent()}{focus in event} with \a focusReason. If another item
already has focus, that item will first receive a \l{focusOutEvent()}
{focus out event} indicating that it has lost input focus.
\sa clearFocus(), hasFocus(), focusItem(), focusProxy()
*/
void QGraphicsItem::setFocus(Qt::FocusReason focusReason)
{
// Disabled / unfocusable items cannot accept focus.
if (!isEnabled() || !(d_ptr->flags & QGraphicsItem::ItemIsFocusable))
return;
// Find focus proxy.
QGraphicsItem *f = this;
while (f->d_ptr->focusProxy)
f = f->d_ptr->focusProxy;
// Return if it already has focus.
if (d_ptr->scene && d_ptr->scene->focusItem() == f)
return;
// Update the child focus chain.
d_ptr->setSubFocus();
// Update the scene's focus item.
if (d_ptr->scene) {
QGraphicsItem *p = panel();
if (!p || p->isActive()) {
// Visible items immediately gain focus from scene.
d_ptr->scene->d_func()->setFocusItemHelper(f, focusReason);
}
}
}
/*!
Takes keyboard input focus from the item.
If it has focus, a \l{focusOutEvent()}{focus out event} is sent to this
item to tell it that it is about to lose the focus.
Only items that set the ItemIsFocusable flag, or widgets that set an
appropriate focus policy, can accept keyboard focus.
\sa setFocus(), hasFocus(), QGraphicsWidget::focusPolicy
*/
void QGraphicsItem::clearFocus()
{
if (!d_ptr->scene)
return;
// Invisible items with focus must explicitly clear subfocus.
d_ptr->clearSubFocus();
if (hasFocus()) {
// If this item has the scene's input focus, clear it.
d_ptr->scene->setFocusItem(0);
}
}
/*!
\since 4.6
Returns this item's focus proxy, or 0 if this item has no
focus proxy.
\sa setFocusProxy(), ItemAutoDetectsFocusProxy, setFocus(), hasFocus()
*/
QGraphicsItem *QGraphicsItem::focusProxy() const
{
return d_ptr->focusProxy;
}
/*!
\since 4.6
Sets the item's focus proxy to \a item.
If an item has a focus proxy, the focus proxy will receive
input focus when the item gains input focus. The item itself
will still have focus (i.e., hasFocus() will return true),
but only the focus proxy will receive the keyboard input.
A focus proxy can itself have a focus proxy, and so on. In
such case, keyboard input will be handled by the outermost
focus proxy.
The focus proxy \a item must belong to the same scene as
this item.
\sa focusProxy(), ItemAutoDetectsFocusProxy, setFocus(), hasFocus()
*/
void QGraphicsItem::setFocusProxy(QGraphicsItem *item)
{
if (item == d_ptr->focusProxy)
return;
if (item == this) {
qWarning("QGraphicsItem::setFocusProxy: cannot assign self as focus proxy");
return;
}
if (item) {
if (item->d_ptr->scene != d_ptr->scene) {
qWarning("QGraphicsItem::setFocusProxy: focus proxy must be in same scene");
return;
}
for (QGraphicsItem *f = item->focusProxy(); f != 0; f = f->focusProxy()) {
if (f == this) {
qWarning("QGraphicsItem::setFocusProxy: %p is already in the focus proxy chain", item);
return;
}
}
}
QGraphicsItem *lastFocusProxy = d_ptr->focusProxy;
if (lastFocusProxy)
lastFocusProxy->d_ptr->focusProxyRefs.removeOne(&d_ptr->focusProxy);
d_ptr->focusProxy = item;
if (item)
item->d_ptr->focusProxyRefs << &d_ptr->focusProxy;
}
/*!
\since 4.6
If this item, a child or descendant of this item currently has input
focus, this function will return a pointer to that item. If
no descendant has input focus, 0 is returned.
\sa hasFocus(), setFocus(), QWidget::focusWidget()
*/
QGraphicsItem *QGraphicsItem::focusItem() const
{
return d_ptr->subFocusItem;
}
/*!
\since 4.4
Grabs the mouse input.
This item will receive all mouse events for the scene until any of the
following events occurs:
\list
\o The item becomes invisible
\o The item is removed from the scene
\o The item is deleted
\o The item call ungrabMouse()
\o Another item calls grabMouse(); the item will regain the mouse grab
when the other item calls ungrabMouse().
\endlist
When an item gains the mouse grab, it receives a QEvent::GrabMouse
event. When it loses the mouse grab, it receives a QEvent::UngrabMouse
event. These events can be used to detect when your item gains or loses
the mouse grab through other means than receiving mouse button events.
It is almost never necessary to explicitly grab the mouse in Qt, as Qt
grabs and releases it sensibly. In particular, Qt grabs the mouse when you
press a mouse button, and keeps the mouse grabbed until you release the
last mouse button. Also, Qt::Popup widgets implicitly call grabMouse()
when shown, and ungrabMouse() when hidden.
Note that only visible items can grab mouse input. Calling grabMouse() on
an invisible item has no effect.
Keyboard events are not affected.
\sa QGraphicsScene::mouseGrabberItem(), ungrabMouse(), grabKeyboard()
*/
void QGraphicsItem::grabMouse()
{
if (!d_ptr->scene) {
qWarning("QGraphicsItem::grabMouse: cannot grab mouse without scene");
return;
}
if (!d_ptr->visible) {
qWarning("QGraphicsItem::grabMouse: cannot grab mouse while invisible");
return;
}
d_ptr->scene->d_func()->grabMouse(this);
}
/*!
\since 4.4
Releases the mouse grab.
\sa grabMouse(), ungrabKeyboard()
*/
void QGraphicsItem::ungrabMouse()
{
if (!d_ptr->scene) {
qWarning("QGraphicsItem::ungrabMouse: cannot ungrab mouse without scene");
return;
}
d_ptr->scene->d_func()->ungrabMouse(this);
}
/*!
\since 4.4
Grabs the keyboard input.
The item will receive all keyboard input to the scene until one of the
following events occur:
\list
\o The item becomes invisible
\o The item is removed from the scene
\o The item is deleted
\o The item calls ungrabKeyboard()
\o Another item calls grabKeyboard(); the item will regain the keyboard grab
when the other item calls ungrabKeyboard().
\endlist
When an item gains the keyboard grab, it receives a QEvent::GrabKeyboard
event. When it loses the keyboard grab, it receives a
QEvent::UngrabKeyboard event. These events can be used to detect when your
item gains or loses the keyboard grab through other means than gaining
input focus.
It is almost never necessary to explicitly grab the keyboard in Qt, as Qt
grabs and releases it sensibly. In particular, Qt grabs the keyboard when
your item gains input focus, and releases it when your item loses input
focus, or when the item is hidden.
Note that only visible items can grab keyboard input. Calling
grabKeyboard() on an invisible item has no effect.
Keyboard events are not affected.
\sa ungrabKeyboard(), grabMouse(), setFocus()
*/
void QGraphicsItem::grabKeyboard()
{
if (!d_ptr->scene) {
qWarning("QGraphicsItem::grabKeyboard: cannot grab keyboard without scene");
return;
}
if (!d_ptr->visible) {
qWarning("QGraphicsItem::grabKeyboard: cannot grab keyboard while invisible");
return;
}
d_ptr->scene->d_func()->grabKeyboard(this);
}
/*!
\since 4.4
Releases the keyboard grab.
\sa grabKeyboard(), ungrabMouse()
*/
void QGraphicsItem::ungrabKeyboard()
{
if (!d_ptr->scene) {
qWarning("QGraphicsItem::ungrabKeyboard: cannot ungrab keyboard without scene");
return;
}
d_ptr->scene->d_func()->ungrabKeyboard(this);
}
/*!
Returns the position of the item in parent coordinates. If the item has no
parent, its position is given in scene coordinates.
The position of the item describes its origin (local coordinate
(0, 0)) in parent coordinates; this function returns the same as
mapToParent(0, 0).
For convenience, you can also call scenePos() to determine the
item's position in scene coordinates, regardless of its parent.
\sa x(), y(), setPos(), transform(), {The Graphics View Coordinate System}
*/
QPointF QGraphicsItem::pos() const
{
return d_ptr->pos;
}
/*!
\fn QGraphicsItem::x() const
This convenience function is equivalent to calling pos().x().
\sa y()
*/
/*!
\since 4.6
Set's the \a x coordinate of the item's position. Equivalent to
calling setPos(x, y()).
\sa x(), setPos()
*/
void QGraphicsItem::setX(qreal x)
{
d_ptr->setPosHelper(QPointF(x, d_ptr->pos.y()));
}
/*!
\fn QGraphicsItem::y() const
This convenience function is equivalent to calling pos().y().
\sa x()
*/
/*!
\since 4.6
Set's the \a y coordinate of the item's position. Equivalent to
calling setPos(x(), y).
\sa x(), setPos()
*/
void QGraphicsItem::setY(qreal y)
{
d_ptr->setPosHelper(QPointF(d_ptr->pos.x(), y));
}
/*!
Returns the item's position in scene coordinates. This is
equivalent to calling \c mapToScene(0, 0).
\sa pos(), sceneTransform(), {The Graphics View Coordinate System}
*/
QPointF QGraphicsItem::scenePos() const
{
return mapToScene(0, 0);
}
/*!
\internal
Sets the position \a pos.
*/
void QGraphicsItemPrivate::setPosHelper(const QPointF &pos)
{
Q_Q(QGraphicsItem);
inSetPosHelper = 1;
updateCachedClipPathFromSetPosHelper(pos);
if (scene)
q->prepareGeometryChange();
QPointF oldPos = this->pos;
this->pos = pos;
dirtySceneTransform = 1;
inSetPosHelper = 0;
if (isObject) {
if (pos.x() != oldPos.x())
emit static_cast<QGraphicsObject *>(q_ptr)->xChanged();
if (pos.y() != oldPos.y())
emit static_cast<QGraphicsObject *>(q_ptr)->yChanged();
}
}
/*!
\internal
Sets the transform \a transform.
*/
void QGraphicsItemPrivate::setTransformHelper(const QTransform &transform)
{
q_ptr->prepareGeometryChange();
transformData->transform = transform;
dirtySceneTransform = 1;
}
/*!
Sets the position of the item to \a pos, which is in parent
coordinates. For items with no parent, \a pos is in scene
coordinates.
The position of the item describes its origin (local coordinate
(0, 0)) in parent coordinates.
\sa pos(), scenePos(), {The Graphics View Coordinate System}
*/
void QGraphicsItem::setPos(const QPointF &pos)
{
if (d_ptr->pos == pos)
return;
// Update and repositition.
if (!(d_ptr->flags & ItemSendsGeometryChanges)) {
d_ptr->setPosHelper(pos);
return;
}
// Notify the item that the position is changing.
const QVariant newPosVariant(itemChange(ItemPositionChange, qVariantFromValue<QPointF>(pos)));
QPointF newPos = newPosVariant.toPointF();
if (newPos == d_ptr->pos)
return;
// Update and repositition.
d_ptr->setPosHelper(newPos);
// Send post-notification.
itemChange(QGraphicsItem::ItemPositionHasChanged, newPosVariant);
}
/*!
\fn void QGraphicsItem::setPos(qreal x, qreal y)
\overload
This convenience function is equivalent to calling setPos(QPointF(\a x, \a
y)).
*/
/*!
\fn void QGraphicsItem::moveBy(qreal dx, qreal dy)
Moves the item by \a dx points horizontally, and \a dy point
vertically. This function is equivalent to calling setPos(pos() +
QPointF(\a dx, \a dy)).
*/
/*!
If this item is part of a scene that is viewed by a QGraphicsView, this
convenience function will attempt to scroll the view to ensure that \a
rect is visible inside the view's viewport. If \a rect is a null rect (the
default), QGraphicsItem will default to the item's bounding rect. \a xmargin
and \a ymargin are the number of pixels the view should use for margins.
If the specified rect cannot be reached, the contents are scrolled to the
nearest valid position.
If this item is not viewed by a QGraphicsView, this function does nothing.
\sa QGraphicsView::ensureVisible()
*/
void QGraphicsItem::ensureVisible(const QRectF &rect, int xmargin, int ymargin)
{
if (d_ptr->scene) {
QRectF sceneRect;
if (!rect.isNull())
sceneRect = sceneTransform().mapRect(rect);
else
sceneRect = sceneBoundingRect();
foreach (QGraphicsView *view, d_ptr->scene->d_func()->views)
view->ensureVisible(sceneRect, xmargin, ymargin);
}
}
/*!
\fn void QGraphicsItem::ensureVisible(qreal x, qreal y, qreal w, qreal h,
int xmargin = 50, int ymargin = 50)
This convenience function is equivalent to calling
ensureVisible(QRectF(\a x, \a y, \a w, \a h), \a xmargin, \a ymargin):
*/
/*!
\obsolete
Returns the item's affine transformation matrix. This is a subset or the
item's full transformation matrix, and might not represent the item's full
transformation.
Use transform() instead.
\sa setTransform(), sceneTransform()
*/
QMatrix QGraphicsItem::matrix() const
{
return transform().toAffine();
}
/*!
\since 4.3
Returns this item's transformation matrix.
The transformation matrix is combined with the item's rotation(), scale()
and transformations() into a combined transformations for the item.
The default transformation matrix is an identity matrix.
\sa setTransform(), sceneTransform()
*/
QTransform QGraphicsItem::transform() const
{
if (!d_ptr->transformData)
return QTransform();
return d_ptr->transformData->transform;
}
/*!
\since 4.6
Returns the clockwise rotation, in degrees, around the Z axis. The default
value is 0 (i.e., the item is not rotated).
The rotation is combined with the item's scale(), transform() and
transformations() to map the item's coordinate system to the parent item.
\sa setRotation(), transformOriginPoint(), {Transformations}
*/
qreal QGraphicsItem::rotation() const
{
if (!d_ptr->transformData)
return 0;
return d_ptr->transformData->rotation;
}
/*!
\since 4.6
Sets the clockwise rotation \a angle, in degrees, around the Z axis. The
default value is 0 (i.e., the item is not rotated). Assigning a negative
value will rotate the item counter-clockwise. Normally the rotation angle
is in the range (-360, 360), but it's also possible to assign values
outside of this range (e.g., a rotation of 370 degrees is the same as a
rotation of 10 degrees).
The item is rotated around its transform origin point, which by default
is (0, 0). You can select a different transformation origin by calling
setTransformOriginPoint().
The rotation is combined with the item's scale(), transform() and
transformations() to map the item's coordinate system to the parent item.
\sa rotation(), setTransformOriginPoint(), {Transformations}
*/
void QGraphicsItem::setRotation(qreal angle)
{
prepareGeometryChange();
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->rotation = angle;
d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
if (d_ptr->isObject)
emit static_cast<QGraphicsObject *>(this)->rotationChanged();
}
/*!
\since 4.6
Returns the scale factor of the item. The default scale factor is 1.0
(i.e., the item is not scaled).
The scale is combined with the item's rotation(), transform() and
transformations() to map the item's coordinate system to the parent item.
\sa setScale(), rotation(), {Transformations}
*/
qreal QGraphicsItem::scale() const
{
if (!d_ptr->transformData)
return 1.;
return d_ptr->transformData->scale;
}
/*!
\since 4.6
Sets the scale \a factor of the item. The default scale factor is 1.0
(i.e., the item is not scaled). A scale factor of 0.0 will collapse the
item to a single point. If you provide a negative scale factor, the
item will be flipped and mirrored (i.e., rotated 180 degrees).
The item is scaled around its transform origin point, which by default
is (0, 0). You can select a different transformation origin by calling
setTransformOriginPoint().
The scale is combined with the item's rotation(), transform() and
transformations() to map the item's coordinate system to the parent item.
\sa scale(), setTransformOriginPoint(), {Transformations}
*/
void QGraphicsItem::setScale(qreal factor)
{
prepareGeometryChange();
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->scale = factor;
d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
if (d_ptr->isObject)
emit static_cast<QGraphicsObject *>(this)->scaleChanged();
}
/*!
\since 4.6
Returns a list of graphics transforms that currently apply to this item.
QGraphicsTransform is for applying and controlling a chain of individual
transformation operations on an item. It's particularily useful in
animations, where each transform operation needs to be interpolated
independently, or differently.
The transformations are combined with the item's rotation(), scale() and
transform() to map the item's coordinate system to the parent item.
\sa scale(), rotation(), transformOriginPoint(), {Transformations}
*/
QList<QGraphicsTransform *> QGraphicsItem::transformations() const
{
if (!d_ptr->transformData)
return QList<QGraphicsTransform *>();
return d_ptr->transformData->graphicsTransforms;
}
/*!
\since 4.6
Sets a list of graphics \a transformations (QGraphicsTransform) that
currently apply to this item.
If all you want is to rotate or scale an item, you should call setRotation()
or setScale() instead. If you want to set an arbitrary transformation on
an item, you can call setTransform().
QGraphicsTransform is for applying and controlling a chain of individual
transformation operations on an item. It's particularily useful in
animations, where each transform operation needs to be interpolated
independently, or differently.
The transformations are combined with the item's rotation(), scale() and
transform() to map the item's coordinate system to the parent item.
\sa scale(), setTransformOriginPoint(), {Transformations}
*/
void QGraphicsItem::setTransformations(const QList<QGraphicsTransform *> &transformations)
{
prepareGeometryChange();
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->graphicsTransforms = transformations;
for (int i = 0; i < transformations.size(); ++i)
transformations.at(i)->d_func()->setItem(this);
d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
/*!
\internal
*/
void QGraphicsItemPrivate::appendGraphicsTransform(QGraphicsTransform *t)
{
if (!transformData)
transformData = new QGraphicsItemPrivate::TransformData;
if (!transformData->graphicsTransforms.contains(t))
transformData->graphicsTransforms.append(t);
Q_Q(QGraphicsItem);
t->d_func()->setItem(q);
transformData->onlyTransform = false;
dirtySceneTransform = 1;
}
/*!
\since 4.6
Returns the origin point for the transformation in item coordinates.
The default is QPointF(0,0).
\sa setTransformOriginPoint(), {Transformations}
*/
QPointF QGraphicsItem::transformOriginPoint() const
{
if (!d_ptr->transformData)
return QPointF(0,0);
return QPointF(d_ptr->transformData->xOrigin, d_ptr->transformData->yOrigin);
}
/*!
\since 4.6
Sets the \a origin point for the transformation in item coordinates.
\sa transformOriginPoint(), {Transformations}
*/
void QGraphicsItem::setTransformOriginPoint(const QPointF &origin)
{
prepareGeometryChange();
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->xOrigin = origin.x();
d_ptr->transformData->yOrigin = origin.y();
d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
/*!
\fn void QGraphicsItem::setTransformOriginPoint(qreal x, qreal y)
\since 4.6
\overload
Sets the origin point for the transformation in item coordinates.
This is equivalent to calling setTransformOriginPoint(QPointF(\a x, \a y)).
\sa setTransformOriginPoint(), {Transformations}
*/
/*!
\obsolete
Use sceneTransform() instead.
\sa transform(), setTransform(), scenePos(), {The Graphics View Coordinate System}
*/
QMatrix QGraphicsItem::sceneMatrix() const
{
d_ptr->ensureSceneTransform();
return d_ptr->sceneTransform.toAffine();
}
/*!
\since 4.3
Returns this item's scene transformation matrix. This matrix can be used
to map coordinates and geometrical shapes from this item's local
coordinate system to the scene's coordinate system. To map coordinates
from the scene, you must first invert the returned matrix.
Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 4
Unlike transform(), which returns only an item's local transformation, this
function includes the item's (and any parents') position, and all the transfomation properties.
\sa transform(), setTransform(), scenePos(), {The Graphics View Coordinate System}, {Transformations}
*/
QTransform QGraphicsItem::sceneTransform() const
{
d_ptr->ensureSceneTransform();
return d_ptr->sceneTransform;
}
/*!
\since 4.3
Returns this item's device transformation matrix, using \a
viewportTransform to map from scene to device coordinates. This matrix can
be used to map coordinates and geometrical shapes from this item's local
coordinate system to the viewport's (or any device's) coordinate
system. To map coordinates from the viewport, you must first invert the
returned matrix.
Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 5
This function is the same as combining this item's scene transform with
the view's viewport transform, but it also understands the
ItemIgnoresTransformations flag. The device transform can be used to do
accurate coordinate mapping (and collision detection) for untransformable
items.
\sa transform(), setTransform(), scenePos(), {The Graphics View Coordinate
System}, itemTransform()
*/
QTransform QGraphicsItem::deviceTransform(const QTransform &viewportTransform) const
{
// Ensure we return the standard transform if we're not untransformable.
if (!d_ptr->itemIsUntransformable()) {
d_ptr->ensureSceneTransform();
return d_ptr->sceneTransform * viewportTransform;
}
// Find the topmost item that ignores view transformations.
const QGraphicsItem *untransformedAncestor = this;
QList<const QGraphicsItem *> parents;
while (untransformedAncestor && ((untransformedAncestor->d_ptr->ancestorFlags
& QGraphicsItemPrivate::AncestorIgnoresTransformations))) {
parents.prepend(untransformedAncestor);
untransformedAncestor = untransformedAncestor->parentItem();
}
if (!untransformedAncestor) {
// Assert in debug mode, continue in release.
Q_ASSERT_X(untransformedAncestor, "QGraphicsItem::deviceTransform",
"Invalid object structure!");
return QTransform();
}
// First translate the base untransformable item.
untransformedAncestor->d_ptr->ensureSceneTransform();
QPointF mappedPoint = (untransformedAncestor->d_ptr->sceneTransform * viewportTransform).map(QPointF(0, 0));
// COMBINE
QTransform matrix = QTransform::fromTranslate(mappedPoint.x(), mappedPoint.y());
if (untransformedAncestor->d_ptr->transformData)
matrix = untransformedAncestor->d_ptr->transformData->computedFullTransform(&matrix);
// Then transform and translate all children.
for (int i = 0; i < parents.size(); ++i) {
const QGraphicsItem *parent = parents.at(i);
parent->d_ptr->combineTransformFromParent(&matrix);
}
return matrix;
}
/*!
\since 4.5
Returns a QTransform that maps coordinates from this item to \a other. If
\a ok is not null, and if there is no such transform, the boolean pointed
to by \a ok will be set to false; otherwise it will be set to true.
This transform provides an alternative to the mapToItem() or mapFromItem()
functions, by returning the appropriate transform so that you can map
shapes and coordinates yourself. It also helps you write more efficient
code when repeatedly mapping between the same two items.
\note In rare circumstances, there is no transform that maps between two
items.
\sa mapToItem(), mapFromItem(), deviceTransform()
*/
QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) const
{
// Catch simple cases first.
if (other == 0) {
qWarning("QGraphicsItem::itemTransform: null pointer passed");
return QTransform();
}
if (other == this) {
if (ok)
*ok = true;
return QTransform();
}
QGraphicsItem *parent = d_ptr->parent;
const QGraphicsItem *otherParent = other->d_ptr->parent;
// This is other's child
if (parent == other) {
if (ok)
*ok = true;
QTransform x;
d_ptr->combineTransformFromParent(&x);
return x;
}
// This is other's parent
if (otherParent == this) {
const QPointF &otherPos = other->d_ptr->pos;
if (other->d_ptr->transformData) {
QTransform otherToParent;
other->d_ptr->combineTransformFromParent(&otherToParent);
return otherToParent.inverted(ok);
}
if (ok)
*ok = true;
return QTransform::fromTranslate(-otherPos.x(), -otherPos.y());
}
// Siblings
if (parent == otherParent) {
// COMBINE
const QPointF &itemPos = d_ptr->pos;
const QPointF &otherPos = other->d_ptr->pos;
if (!d_ptr->transformData && !other->d_ptr->transformData) {
QPointF delta = itemPos - otherPos;
if (ok)
*ok = true;
return QTransform::fromTranslate(delta.x(), delta.y());
}
QTransform itemToParent;
d_ptr->combineTransformFromParent(&itemToParent);
QTransform otherToParent;
other->d_ptr->combineTransformFromParent(&otherToParent);
return itemToParent * otherToParent.inverted(ok);
}
// Find the closest common ancestor. If the two items don't share an
// ancestor, then the only way is to combine their scene transforms.
const QGraphicsItem *commonAncestor = commonAncestorItem(other);
if (!commonAncestor) {
d_ptr->ensureSceneTransform();
other->d_ptr->ensureSceneTransform();
return d_ptr->sceneTransform * other->d_ptr->sceneTransform.inverted(ok);
}
// If the two items are cousins (in sibling branches), map both to the
// common ancestor, and combine the two transforms.
bool cousins = other != commonAncestor && this != commonAncestor;
if (cousins) {
bool good = false;
QTransform thisToScene = itemTransform(commonAncestor, &good);
QTransform otherToScene(Qt::Uninitialized);
if (good)
otherToScene = other->itemTransform(commonAncestor, &good);
if (!good) {
if (ok)
*ok = false;
return QTransform();
}
return thisToScene * otherToScene.inverted(ok);
}
// One is an ancestor of the other; walk the chain.
bool parentOfOther = isAncestorOf(other);
const QGraphicsItem *child = parentOfOther ? other : this;
const QGraphicsItem *root = parentOfOther ? this : other;
QTransform x;
const QGraphicsItem *p = child;
do {
p->d_ptr.data()->combineTransformToParent(&x);
} while ((p = p->d_ptr->parent) && p != root);
if (parentOfOther)
return x.inverted(ok);
if (ok)
*ok = true;
return x;
}
/*!
\obsolete
Sets the item's affine transformation matrix. This is a subset or the
item's full transformation matrix, and might not represent the item's full
transformation.
Use setTransform() instead.
\sa transform(), {The Graphics View Coordinate System}
*/
void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine)
{
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
QTransform newTransform(combine ? QTransform(matrix) * d_ptr->transformData->transform : QTransform(matrix));
if (d_ptr->transformData->transform == newTransform)
return;
// Update and set the new transformation.
if (!(d_ptr->flags & ItemSendsGeometryChanges)) {
d_ptr->setTransformHelper(newTransform);
return;
}
// Notify the item that the transformation matrix is changing.
const QVariant newMatrixVariant = qVariantFromValue<QMatrix>(newTransform.toAffine());
newTransform = QTransform(qVariantValue<QMatrix>(itemChange(ItemMatrixChange, newMatrixVariant)));
if (d_ptr->transformData->transform == newTransform)
return;
// Update and set the new transformation.
d_ptr->setTransformHelper(newTransform);
// Send post-notification.
itemChange(ItemTransformHasChanged, qVariantFromValue<QTransform>(newTransform));
}
/*!
\since 4.3
Sets the item's current transformation matrix to \a matrix.
If \a combine is true, then \a matrix is combined with the current matrix;
otherwise, \a matrix \e replaces the current matrix. \a combine is false
by default.
To simplify interation with items using a transformed view, QGraphicsItem
provides mapTo... and mapFrom... functions that can translate between
items' and the scene's coordinates. For example, you can call mapToScene()
to map an item coordiate to a scene coordinate, or mapFromScene() to map
from scene coordinates to item coordinates.
The transformation matrix is combined with the item's rotation(), scale()
and transformations() into a combined transformation that maps the item's
coordinate system to its parent.
\sa transform(), setRotation(), setScale(), setTransformOriginPoint(), {The Graphics View Coordinate System}, {Transformations}
*/
void QGraphicsItem::setTransform(const QTransform &matrix, bool combine)
{
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
QTransform newTransform(combine ? matrix * d_ptr->transformData->transform : matrix);
if (d_ptr->transformData->transform == newTransform)
return;
// Update and set the new transformation.
if (!(d_ptr->flags & ItemSendsGeometryChanges)) {
d_ptr->setTransformHelper(newTransform);
return;
}
// Notify the item that the transformation matrix is changing.
const QVariant newTransformVariant(itemChange(ItemTransformChange,
qVariantFromValue<QTransform>(newTransform)));
newTransform = qVariantValue<QTransform>(newTransformVariant);
if (d_ptr->transformData->transform == newTransform)
return;
// Update and set the new transformation.
d_ptr->setTransformHelper(newTransform);
// Send post-notification.
itemChange(ItemTransformHasChanged, newTransformVariant);
}
/*!
\obsolete
Use resetTransform() instead.
*/
void QGraphicsItem::resetMatrix()
{
resetTransform();
}
/*!
\since 4.3
Resets this item's transformation matrix to the identity matrix or
all the transformation properties to their default values.
This is equivalent to calling \c setTransform(QTransform()).
\sa setTransform(), transform()
*/
void QGraphicsItem::resetTransform()
{
setTransform(QTransform(), false);
}
/*!
\obsolete
Use
\code
setRotation(rotation() + angle);
\endcode
instead.
Rotates the current item transformation \a angle degrees clockwise around
its origin. To translate around an arbitrary point (x, y), you need to
combine translation and rotation with setTransform().
Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 6
\sa setTransform(), transform(), scale(), shear(), translate()
*/
void QGraphicsItem::rotate(qreal angle)
{
setTransform(QTransform().rotate(angle), true);
}
/*!
\obsolete
Use
\code
setTransform(QTransform::fromScale(sx, sy), true);
\endcode
instead.
Scales the current item transformation by (\a sx, \a sy) around its
origin. To scale from an arbitrary point (x, y), you need to combine
translation and scaling with setTransform().
Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 7
\sa setTransform(), transform()
*/
void QGraphicsItem::scale(qreal sx, qreal sy)
{
setTransform(QTransform::fromScale(sx, sy), true);
}
/*!
\obsolete
Use
\code
setTransform(QTransform().shear(sh, sv), true);
\endcode
instead.
Shears the current item transformation by (\a sh, \a sv).
\sa setTransform(), transform()
*/
void QGraphicsItem::shear(qreal sh, qreal sv)
{
setTransform(QTransform().shear(sh, sv), true);
}
/*!
\obsolete
Use setPos() or setTransformOriginPoint() instead. For identical
behavior, use
\code
setTransform(QTransform::fromTranslate(dx, dy), true);
\endcode
Translates the current item transformation by (\a dx, \a dy).
If all you want is to move an item, you should call moveBy() or
setPos() instead; this function changes the item's translation,
which is conceptually separate from its position.
\sa setTransform(), transform()
*/
void QGraphicsItem::translate(qreal dx, qreal dy)
{
setTransform(QTransform::fromTranslate(dx, dy), true);
}
/*!
This virtual function is called twice for all items by the
QGraphicsScene::advance() slot. In the first phase, all items are called
with \a phase == 0, indicating that items on the scene are about to
advance, and then all items are called with \a phase == 1. Reimplement
this function to update your item if you need simple scene-controlled
animation.
The default implementation does nothing.
For individual item animation, an alternative to this function is to
either use QGraphicsItemAnimation, or to multiple-inherit from QObject and
QGraphicsItem, and animate your item using QObject::startTimer() and
QObject::timerEvent().
\sa QGraphicsItemAnimation, QTimeLine
*/
void QGraphicsItem::advance(int phase)
{
Q_UNUSED(phase);
}
/*!
Returns the Z-value, or the elevation, of the item. The Z-value decides
the stacking order of sibling (neighboring) items.
The default Z-value is 0.
\sa setZValue()
*/
qreal QGraphicsItem::zValue() const
{
return d_ptr->z;
}
/*!
Sets the Z-value, or the elevation, of the item, to \a z. The elevation
decides the stacking order of sibling (neighboring) items. An item of high
Z-value will be drawn on top of an item with a lower Z-value if they share
the same parent item. In addition, children of an item will always be
drawn on top of the parent, regardless of the child's Z-value. Sibling
items that share the same Z-value will be drawn in order of insertion; the
last inserted child is stacked above previous children.
\img graphicsview-zorder.png
Children of different parents are stacked according to the Z-value of
each item's ancestor item which is an immediate child of the two
items' closest common ancestor. For example, a robot item might
define a torso item as the parent of a head item, two arm items,
and two upper-leg items. The upper-leg items would each be parents
of one lower-leg item, and each lower-leg item would be parents of
one foot item. The stacking order of the feet is the same as the
stacking order of each foot's ancestor that is an immediate child
of the two feet's common ancestor (i.e., the torso item); so the
feet are stacked in the same order as the upper-leg items,
regardless of each foot's Z-value.
The Z-value does not affect the item's size in any way.
The default Z-value is 0.
\sa zValue()
*/
void QGraphicsItem::setZValue(qreal z)
{
const QVariant newZVariant(itemChange(ItemZValueChange, z));
qreal newZ = newZVariant.toReal();
if (newZ == d_ptr->z)
return;
if (d_ptr->scene) {
// Z Value has changed, we have to notify the index.
d_ptr->scene->d_func()->index->itemChange(this, ItemZValueChange, newZVariant);
}
d_ptr->z = newZ;
if (d_ptr->parent)
d_ptr->parent->d_ptr->needSortChildren = 1;
else if (d_ptr->scene)
d_ptr->scene->d_func()->needSortTopLevelItems = 1;
if (d_ptr->scene)
d_ptr->scene->d_func()->markDirty(this, QRectF(), /*invalidateChildren=*/true);
itemChange(ItemZValueHasChanged, newZVariant);
if (d_ptr->flags & ItemNegativeZStacksBehindParent)
setFlag(QGraphicsItem::ItemStacksBehindParent, z < qreal(0.0));
if (d_ptr->isObject)
emit static_cast<QGraphicsObject *>(this)->zChanged();
}
/*!
Returns the bounding rect of this item's descendants (i.e., its
children, their children, etc.) in local coordinates. The
rectangle will contain all descendants after they have been mapped
to local coordinates. If the item has no children, this function
returns an empty QRectF.
This does not include this item's own bounding rect; it only returns
its descendants' accumulated bounding rect. If you need to include this
item's bounding rect, you can add boundingRect() to childrenBoundingRect()
using QRectF::operator|().
This function is linear in complexity; it determines the size of the
returned bounding rect by iterating through all descendants.
\sa boundingRect(), sceneBoundingRect()
*/
QRectF QGraphicsItem::childrenBoundingRect() const
{
if (!d_ptr->dirtyChildrenBoundingRect)
return d_ptr->childrenBoundingRect;
d_ptr->childrenBoundingRect = QRectF();
d_ptr->childrenBoundingRectHelper(0, &d_ptr->childrenBoundingRect);
d_ptr->dirtyChildrenBoundingRect = 0;
return d_ptr->childrenBoundingRect;
}
/*!
\fn virtual QRectF QGraphicsItem::boundingRect() const = 0
This pure virtual function defines the outer bounds of the item as
a rectangle; all painting must be restricted to inside an item's
bounding rect. QGraphicsView uses this to determine whether the
item requires redrawing.
Although the item's shape can be arbitrary, the bounding rect is
always rectangular, and it is unaffected by the items'
transformation.
If you want to change the item's bounding rectangle, you must first call
prepareGeometryChange(). This notifies the scene of the imminent change,
so that its can update its item geometry index; otherwise, the scene will
be unaware of the item's new geometry, and the results are undefined
(typically, rendering artifacts are left around in the view).
Reimplement this function to let QGraphicsView determine what
parts of the widget, if any, need to be redrawn.
Note: For shapes that paint an outline / stroke, it is important
to include half the pen width in the bounding rect. It is not
necessary to compensate for antialiasing, though.
Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 8
\sa boundingRegion(), shape(), contains(), {The Graphics View Coordinate
System}, prepareGeometryChange()
*/
/*!
Returns the bounding rect of this item in scene coordinates, by combining
sceneTransform() with boundingRect().
\sa boundingRect(), {The Graphics View Coordinate System}
*/
QRectF QGraphicsItem::sceneBoundingRect() const
{
// Find translate-only offset
// COMBINE
QPointF offset;
const QGraphicsItem *parentItem = this;
const QGraphicsItemPrivate *itemd;
do {
itemd = parentItem->d_ptr.data();
if (itemd->transformData)
break;
offset += itemd->pos;
} while ((parentItem = itemd->parent));
QRectF br = boundingRect();
br.translate(offset);
if (!parentItem)
return br;
if (parentItem->d_ptr->hasTranslateOnlySceneTransform()) {
br.translate(parentItem->d_ptr->sceneTransform.dx(), parentItem->d_ptr->sceneTransform.dy());
return br;
}
return parentItem->d_ptr->sceneTransform.mapRect(br);
}
/*!
Returns the shape of this item as a QPainterPath in local
coordinates. The shape is used for many things, including collision
detection, hit tests, and for the QGraphicsScene::items() functions.
The default implementation calls boundingRect() to return a simple
rectangular shape, but subclasses can reimplement this function to return
a more accurate shape for non-rectangular items. For example, a round item
may choose to return an elliptic shape for better collision detection. For
example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 9
The outline of a shape can vary depending on the width and style of the
pen used when drawing. If you want to include this outline in the item's
shape, you can create a shape from the stroke using QPainterPathStroker.
This function is called by the default implementations of contains() and
collidesWithPath().
\sa boundingRect(), contains(), prepareGeometryChange(), QPainterPathStroker
*/
QPainterPath QGraphicsItem::shape() const
{
QPainterPath path;
path.addRect(boundingRect());
return path;
}
/*!
Returns true if this item is clipped. An item is clipped if it has either
set the \l ItemClipsToShape flag, or if it or any of its ancestors has set
the \l ItemClipsChildrenToShape flag.
Clipping affects the item's appearance (i.e., painting), as well as mouse
and hover event delivery.
\sa clipPath(), shape(), setFlags()
*/
bool QGraphicsItem::isClipped() const
{
Q_D(const QGraphicsItem);
return (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)
|| (d->flags & QGraphicsItem::ItemClipsToShape);
}
/*!
\since 4.5
Returns this item's clip path, or an empty QPainterPath if this item is
not clipped. The clip path constrains the item's appearance and
interaction (i.e., restricts the area the item can draw, and it also
restricts the area that the item receives events).
You can enable clipping by setting the ItemClipsToShape or
ItemClipsChildrenToShape flags. The item's clip path is calculated by
intersecting all clipping ancestors' shapes. If the item sets
ItemClipsToShape, the final clip is intersected with the item's own shape.
\note Clipping introduces a performance penalty for all items involved;
you should generally avoid using clipping if you can (e.g., if your items
always draw inside boundingRect() or shape() boundaries, clipping is not
necessary).
\sa isClipped(), shape(), setFlags()
*/
QPainterPath QGraphicsItem::clipPath() const
{
Q_D(const QGraphicsItem);
if (!d->dirtyClipPath)
return d->emptyClipPath ? QPainterPath() : d->cachedClipPath;
if (!isClipped()) {
d_ptr->setCachedClipPath(QPainterPath());
return d->cachedClipPath;
}
const QRectF thisBoundingRect(boundingRect());
if (thisBoundingRect.isEmpty()) {
if (d_ptr->flags & ItemClipsChildrenToShape)
d_ptr->setEmptyCachedClipPathRecursively();
else
d_ptr->setEmptyCachedClipPath();
return QPainterPath();
}
QPainterPath clip;
// Start with the item's bounding rect.
clip.addRect(thisBoundingRect);
if (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) {
const QGraphicsItem *parent = this;
const QGraphicsItem *lastParent = this;
// Intersect any in-between clips starting at the top and moving downwards.
bool foundValidClipPath = false;
while ((parent = parent->d_ptr->parent)) {
if (parent->d_ptr->flags & ItemClipsChildrenToShape) {
// Map clip to the current parent and intersect with its shape/clipPath
clip = lastParent->itemTransform(parent).map(clip);
if ((foundValidClipPath = !parent->d_ptr->dirtyClipPath && parent->isClipped())) {
if (parent->d_ptr->emptyClipPath) {
if (d_ptr->flags & ItemClipsChildrenToShape)
d_ptr->setEmptyCachedClipPathRecursively();
else
d_ptr->setEmptyCachedClipPath();
return QPainterPath();
}
clip = clip.intersected(parent->d_ptr->cachedClipPath);
if (!(parent->d_ptr->flags & ItemClipsToShape))
clip = clip.intersected(parent->shape());
} else {
clip = clip.intersected(parent->shape());
}
if (clip.isEmpty()) {
if (d_ptr->flags & ItemClipsChildrenToShape)
d_ptr->setEmptyCachedClipPathRecursively();
else
d_ptr->setEmptyCachedClipPath();
return clip;
}
lastParent = parent;
}
if (!(parent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)
|| foundValidClipPath) {
break;
}
}
if (lastParent != this) {
// Map clip back to the item's transform.
// ### what if itemtransform fails
clip = lastParent->itemTransform(this).map(clip);
}
}
if (d->flags & ItemClipsToShape)
clip = clip.intersected(shape());
d_ptr->setCachedClipPath(clip);
return clip;
}
/*!
Returns true if this item contains \a point, which is in local
coordinates; otherwise, false is returned. It is most often called from
QGraphicsView to determine what item is under the cursor, and for that
reason, the implementation of this function should be as light-weight as
possible.
By default, this function calls shape(), but you can reimplement it in a
subclass to provide a (perhaps more efficient) implementation.
\sa shape(), boundingRect(), collidesWithPath()
*/
bool QGraphicsItem::contains(const QPointF &point) const
{
return isClipped() ? clipPath().contains(point) : shape().contains(point);
}
/*!
Returns true if this item collides with \a other; otherwise
returns false.
The \a mode is applied to \a other, and the resulting shape or
bounding rectangle is then compared to this item's shape. The
default value for \a mode is Qt::IntersectsItemShape; \a other
collides with this item if it either intersects, contains, or is
contained by this item's shape (see Qt::ItemSelectionMode for
details).
The default implementation is based on shape intersection, and it calls
shape() on both items. Because the complexity of arbitrary shape-shape
intersection grows with an order of magnitude when the shapes are complex,
this operation can be noticably time consuming. You have the option of
reimplementing this function in a subclass of QGraphicsItem to provide a
custom algorithm. This allows you to make use of natural constraints in
the shapes of your own items, in order to improve the performance of the
collision detection. For instance, two untransformed perfectly circular
items' collision can be determined very efficiently by comparing their
positions and radii.
Keep in mind that when reimplementing this function and calling shape() or
boundingRect() on \a other, the returned coordinates must be mapped to
this item's coordinate system before any intersection can take place.
\sa contains(), shape()
*/
bool QGraphicsItem::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const
{
if (other == this)
return true;
if (!other)
return false;
// The items share the same clip if their closest clipper is the same, or
// if one clips the other.
bool clips = (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren);
bool otherClips = (other->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren);
if (clips || otherClips) {
const QGraphicsItem *closestClipper = isAncestorOf(other) ? this : parentItem();
while (closestClipper && !(closestClipper->flags() & ItemClipsChildrenToShape))
closestClipper = closestClipper->parentItem();
const QGraphicsItem *otherClosestClipper = other->isAncestorOf(this) ? other : other->parentItem();
while (otherClosestClipper && !(otherClosestClipper->flags() & ItemClipsChildrenToShape))
otherClosestClipper = otherClosestClipper->parentItem();
if (closestClipper == otherClosestClipper) {
d_ptr->localCollisionHack = 1;
bool res = collidesWithPath(mapFromItem(other, other->shape()), mode);
d_ptr->localCollisionHack = 0;
return res;
}
}
QPainterPath otherShape = other->isClipped() ? other->clipPath() : other->shape();
return collidesWithPath(mapFromItem(other, otherShape), mode);
}
/*!
Returns true if this item collides with \a path.
The collision is determined by \a mode. The default value for \a mode is
Qt::IntersectsItemShape; \a path collides with this item if it either
intersects, contains, or is contained by this item's shape.
Note that this function checks whether the item's shape or
bounding rectangle (depending on \a mode) is contained within \a
path, and not whether \a path is contained within the items shape
or bounding rectangle.
\sa collidesWithItem(), contains(), shape()
*/
bool QGraphicsItem::collidesWithPath(const QPainterPath &path, Qt::ItemSelectionMode mode) const
{
if (path.isEmpty()) {
// No collision with empty paths.
return false;
}
QRectF rectA(boundingRect());
_q_adjustRect(&rectA);
QRectF rectB(path.controlPointRect());
_q_adjustRect(&rectB);
if (!rectA.intersects(rectB)) {
// This we can determine efficiently. If the two rects neither
// intersect nor contain eachother, then the two items do not collide.
return false;
}
// For further testing, we need this item's shape or bounding rect.
QPainterPath thisShape;
if (mode == Qt::IntersectsItemShape || mode == Qt::ContainsItemShape)
thisShape = (isClipped() && !d_ptr->localCollisionHack) ? clipPath() : shape();
else
thisShape.addRect(rectA);
if (thisShape == QPainterPath()) {
// Empty shape? No collision.
return false;
}
// Use QPainterPath boolean operations to determine the collision, O(N*logN).
if (mode == Qt::IntersectsItemShape || mode == Qt::IntersectsItemBoundingRect)
return path.intersects(thisShape);
return path.contains(thisShape);
}
/*!
Returns a list of all items that collide with this item.
The way collisions are detected is determined by applying \a mode
to items that are compared to this item, i.e., each item's shape
or bounding rectangle is checked against this item's shape. The
default value for \a mode is Qt::IntersectsItemShape.
\sa collidesWithItem()
*/
QList<QGraphicsItem *> QGraphicsItem::collidingItems(Qt::ItemSelectionMode mode) const
{
if (d_ptr->scene)
return d_ptr->scene->collidingItems(this, mode);
return QList<QGraphicsItem *>();
}
/*!
Returns true if this item's bounding rect is completely obscured by the
opaque shape of any of colliding items above it (i.e., with a higher Z
value than this item).
Its implementation is based on calling isObscuredBy(), which you can
reimplement to provide a custom obscurity algorithm.
\sa opaqueArea()
*/
bool QGraphicsItem::isObscured() const
{
return isObscured(QRectF());
}
/*!
\internal
Item obscurity helper function.
Returns true if the subrect \a rect of \a item's bounding rect is obscured
by \a other (i.e., \a other's opaque area covers \a item's \a rect
completely. \a other is assumed to already be "on top of" \a item
wrt. stacking order.
*/
static bool qt_QGraphicsItem_isObscured(const QGraphicsItem *item,
const QGraphicsItem *other,
const QRectF &rect)
{
return other->mapToItem(item, other->opaqueArea()).contains(rect);
}
/*!
\overload
\since 4.3
Returns true if \a rect is completely obscured by the opaque shape of any
of colliding items above it (i.e., with a higher Z value than this item).
Unlike the default isObscured() function, this function does not call
isObscuredBy().
\sa opaqueArea()
*/
bool QGraphicsItem::isObscured(const QRectF &rect) const
{
Q_D(const QGraphicsItem);
if (!d->scene)
return false;
QRectF br = boundingRect();
QRectF testRect = rect.isNull() ? br : rect;
foreach (QGraphicsItem *item, d->scene->items(mapToScene(br), Qt::IntersectsItemBoundingRect)) {
if (item == this)
break;
if (qt_QGraphicsItem_isObscured(this, item, testRect))
return true;
}
return false;
}
/*!
\fn bool QGraphicsItem::isObscured(qreal x, qreal y, qreal w, qreal h) const
\since 4.3
This convenience function is equivalent to calling isObscured(QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
Returns true if this item's bounding rect is completely obscured by the
opaque shape of \a item.
The base implementation maps \a item's opaqueArea() to this item's
coordinate system, and then checks if this item's boundingRect() is fully
contained within the mapped shape.
You can reimplement this function to provide a custom algorithm for
determining whether this item is obscured by \a item.
\sa opaqueArea(), isObscured()
*/
bool QGraphicsItem::isObscuredBy(const QGraphicsItem *item) const
{
if (!item)
return false;
return QGraphicsSceneBspTreeIndexPrivate::closestItemFirst_withoutCache(item, this)
&& qt_QGraphicsItem_isObscured(this, item, boundingRect());
}
/*!
This virtual function returns a shape representing the area where this
item is opaque. An area is opaque if it is filled using an opaque brush or
color (i.e., not transparent).
This function is used by isObscuredBy(), which is called by underlying
items to determine if they are obscured by this item.
The default implementation returns an empty QPainterPath, indicating that
this item is completely transparent and does not obscure any other items.
\sa isObscuredBy(), isObscured(), shape()
*/
QPainterPath QGraphicsItem::opaqueArea() const
{
return QPainterPath();
}
/*!
\since 4.4
Returns the bounding region for this item. The coordinate space of the
returned region depends on \a itemToDeviceTransform. If you pass an
identity QTransform as a parameter, this function will return a local
coordinate region.
The bounding region describes a coarse outline of the item's visual
contents. Although it's expensive to calculate, it's also more precise
than boundingRect(), and it can help to avoid unnecessary repainting when
an item is updated. This is particularily efficient for thin items (e.g.,
lines or simple polygons). You can tune the granularity for the bounding
region by calling setBoundingRegionGranularity(). The default granularity
is 0; in which the item's bounding region is the same as its bounding
rect.
\a itemToDeviceTransform is the transformation from item coordinates to
device coordinates. If you want this function to return a QRegion in scene
coordinates, you can pass sceneTransform() as an argument.
\sa boundingRegionGranularity()
*/
QRegion QGraphicsItem::boundingRegion(const QTransform &itemToDeviceTransform) const
{
// ### Ideally we would have a better way to generate this region,
// preferably something in the lines of QPainterPath::toRegion(QTransform)
// coupled with a way to generate a painter path from a set of painter
// operations (e.g., QPicture::toPainterPath() or so). The current
// approach generates a bitmap with the size of the item's bounding rect
// in device coordinates, scaled by b.r.granularity, then paints the item
// into the bitmap, converts the result to a QRegion and scales the region
// back to device space with inverse granularity.
qreal granularity = boundingRegionGranularity();
QRect deviceRect = itemToDeviceTransform.mapRect(boundingRect()).toRect();
_q_adjustRect(&deviceRect);
if (granularity == 0.0)
return QRegion(deviceRect);
int pad = 1;
QSize bitmapSize(qMax(1, int(deviceRect.width() * granularity) + pad * 2),
qMax(1, int(deviceRect.height() * granularity) + pad * 2));
QImage mask(bitmapSize, QImage::Format_ARGB32_Premultiplied);
mask.fill(0);
QPainter p(&mask);
p.setRenderHints(QPainter::Antialiasing);
// Transform painter (### this code is from QGraphicsScene::drawItemHelper
// and doesn't work properly with perspective transformations).
QPointF viewOrigo = itemToDeviceTransform.map(QPointF(0, 0));
QPointF offset = viewOrigo - deviceRect.topLeft();
p.scale(granularity, granularity);
p.translate(offset);
p.translate(pad, pad);
p.setWorldTransform(itemToDeviceTransform, true);
p.translate(itemToDeviceTransform.inverted().map(QPointF(0, 0)));
// Render
QStyleOptionGraphicsItem option;
const_cast<QGraphicsItem *>(this)->paint(&p, &option, 0);
p.end();
// Transform QRegion back to device space
QTransform unscale = QTransform::fromScale(1 / granularity, 1 / granularity);
QRegion r;
QBitmap colorMask = QBitmap::fromImage(mask.createMaskFromColor(0));
foreach (const QRect &rect, QRegion( colorMask ).rects()) {
QRect xrect = unscale.mapRect(rect).translated(deviceRect.topLeft() - QPoint(pad, pad));
r += xrect.adjusted(-1, -1, 1, 1) & deviceRect;
}
return r;
}
/*!
\since 4.4
Returns the item's bounding region granularity; a value between and
including 0 and 1. The default value is 0 (i.e., the lowest granularity,
where the bounding region corresponds to the item's bounding rectangle).
\omit
### NOTE
\endomit
\sa setBoundingRegionGranularity()
*/
qreal QGraphicsItem::boundingRegionGranularity() const
{
return d_ptr->hasBoundingRegionGranularity
? qVariantValue<qreal>(d_ptr->extra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity))
: 0;
}
/*!
\since 4.4
Sets the bounding region granularity to \a granularity; a value between
and including 0 and 1. The default value is 0 (i.e., the lowest
granularity, where the bounding region corresponds to the item's bounding
rectangle).
The granularity is used by boundingRegion() to calculate how fine the
bounding region of the item should be. The highest achievable granularity
is 1, where boundingRegion() will return the finest outline possible for
the respective device (e.g., for a QGraphicsView viewport, this gives you
a pixel-perfect bounding region). The lowest possible granularity is
0. The value of \a granularity describes the ratio between device
resolution and the resolution of the bounding region (e.g., a value of
0.25 will provide a region where each chunk corresponds to 4x4 device
units / pixels).
\sa boundingRegionGranularity()
*/
void QGraphicsItem::setBoundingRegionGranularity(qreal granularity)
{
if (granularity < 0.0 || granularity > 1.0) {
qWarning("QGraphicsItem::setBoundingRegionGranularity: invalid granularity %g", granularity);
return;
}
if (granularity == 0.0) {
d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity);
d_ptr->hasBoundingRegionGranularity = 0;
return;
}
d_ptr->hasBoundingRegionGranularity = 1;
d_ptr->setExtra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity,
qVariantFromValue<qreal>(granularity));
}
/*!
\fn virtual void QGraphicsItem::paint(QPainter *painter, const
QStyleOptionGraphicsItem *option, QWidget *widget = 0) = 0
This function, which is usually called by QGraphicsView, paints the
contents of an item in local coordinates.
Reimplement this function in a QGraphicsItem subclass to provide the
item's painting implementation, using \a painter. The \a option parameter
provides style options for the item, such as its state, exposed area and
its level-of-detail hints. The \a widget argument is optional. If
provided, it points to the widget that is being painted on; otherwise, it
is 0. For cached painting, \a widget is always 0.
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 10
The painter's pen is 0-width by default, and its pen is initialized to the
QPalette::Text brush from the paint device's palette. The brush is
initialized to QPalette::Window.
Make sure to constrain all painting inside the boundaries of
boundingRect() to avoid rendering artifacts (as QGraphicsView does not
clip the painter for you). In particular, when QPainter renders the
outline of a shape using an assigned QPen, half of the outline will be
drawn outside, and half inside, the shape you're rendering (e.g., with a
pen width of 2 units, you must draw outlines 1 unit inside
boundingRect()). QGraphicsItem does not support use of cosmetic pens with
a non-zero width.
All painting is done in local coordinates.
\sa setCacheMode(), QPen::width(), {Item Coordinates}, ItemUsesExtendedStyleOption
*/
/*!
\internal
Returns true if we can discard an update request; otherwise false.
*/
bool QGraphicsItemPrivate::discardUpdateRequest(bool ignoreClipping, bool ignoreVisibleBit,
bool ignoreDirtyBit, bool ignoreOpacity) const
{
// No scene, or if the scene is updating everything, means we have nothing
// to do. The only exception is if the scene tracks the growing scene rect.
return !scene
|| (!visible && !ignoreVisibleBit && !this->ignoreVisible)
|| (!ignoreDirtyBit && fullUpdatePending)
|| (!ignoreClipping && (childrenClippedToShape() && isClippedAway()))
|| (!ignoreOpacity && !this->ignoreOpacity && childrenCombineOpacity() && isFullyTransparent());
}
/*!
\internal
*/
int QGraphicsItemPrivate::depth() const
{
if (itemDepth == -1)
const_cast<QGraphicsItemPrivate *>(this)->resolveDepth();
return itemDepth;
}
/*!
\internal
*/
void QGraphicsItemPrivate::invalidateDepthRecursively()
{
if (itemDepth == -1)
return;
itemDepth = -1;
for (int i = 0; i < children.size(); ++i)
children.at(i)->d_ptr->invalidateDepthRecursively();
}
/*!
\internal
Resolves the stacking depth of this object and all its ancestors.
*/
void QGraphicsItemPrivate::resolveDepth()
{
if (!parent)
itemDepth = 0;
else {
if (parent->d_ptr->itemDepth == -1)
parent->d_ptr->resolveDepth();
itemDepth = parent->d_ptr->itemDepth + 1;
}
}
/*!
\internal
*/
void QGraphicsItemPrivate::addChild(QGraphicsItem *child)
{
needSortChildren = 1;
child->d_ptr->siblingIndex = children.size();
children.append(child);
}
/*!
\internal
*/
void QGraphicsItemPrivate::removeChild(QGraphicsItem *child)
{
children.removeOne(child);
// NB! Do not use children.removeAt(child->d_ptr->siblingIndex) because
// the child is not guaranteed to be at the index after the list is sorted.
// (see ensureSortedChildren()).
child->d_ptr->siblingIndex = -1;
}
/*!
\internal
*/
QGraphicsItemCache *QGraphicsItemPrivate::maybeExtraItemCache() const
{
return (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData));
}
/*!
\internal
*/
QGraphicsItemCache *QGraphicsItemPrivate::extraItemCache() const
{
QGraphicsItemCache *c = (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData));
if (!c) {
QGraphicsItemPrivate *that = const_cast<QGraphicsItemPrivate *>(this);
c = new QGraphicsItemCache;
that->setExtra(ExtraCacheData, qVariantFromValue<void *>(c));
}
return c;
}
/*!
\internal
*/
void QGraphicsItemPrivate::removeExtraItemCache()
{
QGraphicsItemCache *c = (QGraphicsItemCache *)qVariantValue<void *>(extra(ExtraCacheData));
if (c) {
c->purge();
delete c;
}
unsetExtra(ExtraCacheData);
}
void QGraphicsItemPrivate::setEmptyCachedClipPathRecursively(const QRectF &emptyIfOutsideThisRect)
{
setEmptyCachedClipPath();
const bool checkRect = !emptyIfOutsideThisRect.isNull()
&& !(flags & QGraphicsItem::ItemClipsChildrenToShape);
for (int i = 0; i < children.size(); ++i) {
if (!checkRect) {
children.at(i)->d_ptr->setEmptyCachedClipPathRecursively();
continue;
}
QGraphicsItem *child = children.at(i);
const QRectF rect = child->mapRectFromParent(emptyIfOutsideThisRect);
if (rect.intersects(child->boundingRect()))
child->d_ptr->invalidateCachedClipPathRecursively(false, rect);
else
child->d_ptr->setEmptyCachedClipPathRecursively(rect);
}
}
void QGraphicsItemPrivate::invalidateCachedClipPathRecursively(bool childrenOnly, const QRectF &emptyIfOutsideThisRect)
{
if (!childrenOnly)
invalidateCachedClipPath();
const bool checkRect = !emptyIfOutsideThisRect.isNull();
for (int i = 0; i < children.size(); ++i) {
if (!checkRect) {
children.at(i)->d_ptr->invalidateCachedClipPathRecursively(false);
continue;
}
QGraphicsItem *child = children.at(i);
const QRectF rect = child->mapRectFromParent(emptyIfOutsideThisRect);
if (rect.intersects(child->boundingRect()))
child->d_ptr->invalidateCachedClipPathRecursively(false, rect);
else
child->d_ptr->setEmptyCachedClipPathRecursively(rect);
}
}
void QGraphicsItemPrivate::updateCachedClipPathFromSetPosHelper(const QPointF &newPos)
{
Q_ASSERT(inSetPosHelper);
if (!(ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren))
return; // Not clipped by any ancestor.
// Find closest clip ancestor and transform.
Q_Q(QGraphicsItem);
// COMBINE
QTransform thisToParentTransform = QTransform::fromTranslate(newPos.x(), newPos.y());
if (transformData)
thisToParentTransform = transformData->computedFullTransform(&thisToParentTransform);
QGraphicsItem *clipParent = parent;
while (clipParent && !(clipParent->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape)) {
thisToParentTransform *= clipParent->d_ptr->transformToParent();
clipParent = clipParent->d_ptr->parent;
}
// thisToParentTransform is now the same as q->itemTransform(clipParent), except
// that the new position (which is not yet set on the item) is taken into account.
Q_ASSERT(clipParent);
Q_ASSERT(clipParent->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape);
// From here everything is calculated in clip parent's coordinates.
const QRectF parentBoundingRect(clipParent->boundingRect());
const QRectF thisBoundingRect(thisToParentTransform.mapRect(q->boundingRect()));
if (!parentBoundingRect.intersects(thisBoundingRect)) {
// Item is moved outside the clip parent's bounding rect,
// i.e. it is fully clipped and the clip path is empty.
if (flags & QGraphicsItem::ItemClipsChildrenToShape)
setEmptyCachedClipPathRecursively();
else
setEmptyCachedClipPathRecursively(thisToParentTransform.inverted().mapRect(parentBoundingRect));
return;
}
const QPainterPath parentClip(clipParent->isClipped() ? clipParent->clipPath() : clipParent->shape());
if (parentClip.contains(thisBoundingRect))
return; // Item is inside the clip parent's shape. No update required.
const QRectF parentClipRect(parentClip.controlPointRect());
if (!parentClipRect.intersects(thisBoundingRect)) {
// Item is moved outside the clip parent's shape,
// i.e. it is fully clipped and the clip path is empty.
if (flags & QGraphicsItem::ItemClipsChildrenToShape)
setEmptyCachedClipPathRecursively();
else
setEmptyCachedClipPathRecursively(thisToParentTransform.inverted().mapRect(parentClipRect));
} else {
// Item is partially inside the clip parent's shape,
// i.e. the cached clip path must be invalidated.
invalidateCachedClipPathRecursively(false, thisToParentTransform.inverted().mapRect(parentClipRect));
}
}
// Traverses all the ancestors up to the top-level and updates the pointer to
// always point to the top-most item that has a dirty scene transform.
// It then backtracks to the top-most dirty item and start calculating the
// scene transform by combining the item's transform (+pos) with the parent's
// cached scene transform (which we at this point know for sure is valid).
void QGraphicsItemPrivate::ensureSceneTransformRecursive(QGraphicsItem **topMostDirtyItem)
{
Q_ASSERT(topMostDirtyItem);
if (dirtySceneTransform)
*topMostDirtyItem = q_ptr;
if (parent)
parent->d_ptr->ensureSceneTransformRecursive(topMostDirtyItem);
if (*topMostDirtyItem == q_ptr) {
if (!dirtySceneTransform)
return; // OK, neither my ancestors nor I have dirty scene transforms.
*topMostDirtyItem = 0;
} else if (*topMostDirtyItem) {
return; // Continue backtrack.
}
// COMBINE my transform with the parent's scene transform.
updateSceneTransformFromParent();
Q_ASSERT(!dirtySceneTransform);
}
void QGraphicsItemPrivate::ensureSceneTransform()
{
if (dirtySceneTransform) {
// This item and all its descendants have dirty scene transforms.
// We're about to validate this item's scene transform, so we have to
// invalidate all the children; otherwise there's no way for the descendants
// to detect that the ancestor has changed.
invalidateChildrenSceneTransform();
}
QGraphicsItem *that = q_func();
ensureSceneTransformRecursive(&that);
}
/*!
\internal
*/
void QGraphicsItemPrivate::setSubFocus()
{
// Update focus child chain.
QGraphicsItem *item = q_ptr;
QGraphicsItem *parent = item;
bool hidden = !visible;
do {
parent->d_func()->subFocusItem = item;
} while (!parent->isPanel() && (parent = parent->d_ptr->parent) && (!hidden || !parent->d_func()->visible));
}
/*!
\internal
*/
void QGraphicsItemPrivate::clearSubFocus()
{
// Reset focus child chain.
QGraphicsItem *parent = q_ptr;
do {
if (parent->d_ptr->subFocusItem != q_ptr)
break;
parent->d_ptr->subFocusItem = 0;
} while (!parent->isPanel() && (parent = parent->d_ptr->parent));
}
/*!
\internal
Sets the focusProxy pointer to 0 for all items that have this item as their
focusProxy. ### Qt 5: Use QPointer instead.
*/
void QGraphicsItemPrivate::resetFocusProxy()
{
for (int i = 0; i < focusProxyRefs.size(); ++i)
*focusProxyRefs.at(i) = 0;
focusProxyRefs.clear();
}
/*!
\internal
Tells us if it is a proxy widget
*/
bool QGraphicsItemPrivate::isProxyWidget() const
{
return false;
}
/*!
Schedules a redraw of the area covered by \a rect in this item. You can
call this function whenever your item needs to be redrawn, such as if it
changes appearance or size.
This function does not cause an immediate paint; instead it schedules a
paint request that is processed by QGraphicsView after control reaches the
event loop. The item will only be redrawn if it is visible in any
associated view.
As a side effect of the item being repainted, other items that overlap the
area \a rect may also be repainted.
If the item is invisible (i.e., isVisible() returns false), this function
does nothing.
\sa paint(), boundingRect()
*/
void QGraphicsItem::update(const QRectF &rect)
{
if (rect.isEmpty() && !rect.isNull())
return;
// Make sure we notify effects about invalidated source.
QGraphicsItem *item = this;
do {
if (item->d_ptr->graphicsEffect)
item->d_ptr->notifyInvalidated = 1;
} while ((item = item->d_ptr->parent));
if (CacheMode(d_ptr->cacheMode) != NoCache) {
QGraphicsItemCache *cache = d_ptr->extraItemCache();
if (d_ptr->discardUpdateRequest(/* ignoreVisibleBit = */ false,
/* ignoreClipping = */ false,
/* ignoreDirtyBit = */ true)) {
return;
}
// Invalidate cache.
if (!cache->allExposed) {
if (rect.isNull()) {
cache->allExposed = true;
cache->exposed.clear();
} else {
cache->exposed.append(rect);
}
}
// Only invalidate cache; item is already dirty.
if (d_ptr->fullUpdatePending)
return;
}
if (d_ptr->scene)
d_ptr->scene->d_func()->markDirty(this, rect);
}
/*!
\internal
Scrolls \a rect in \a pix by \a dx, \a dy.
### This can be done much more efficiently by using XCopyArea on X11 with
the same dst and src, and through moving pixels in the raster engine. It
can probably also be done much better on the other paint engines.
*/
void _q_scrollPixmap(QPixmap *pix, const QRect &rect, int dx, int dy)
{
#if 0
QPainter painter(pix);
painter.setClipRect(rect);
painter.drawPixmap(rect.translated(dx, dy), *pix, rect);
painter.end();
#elif defined Q_WS_X11
GC gc = XCreateGC(X11->display, pix->handle(), 0, 0);
XRectangle xrect;
xrect.x = rect.x();
xrect.y = rect.y();
xrect.width = rect.width();
xrect.height = rect.height();
XSetClipRectangles(X11->display, gc, 0, 0, &xrect, 1, YXBanded);
XCopyArea(X11->display, pix->handle(), pix->handle(), gc,
rect.x(), rect.y(), rect.width(), rect.height(),
rect.x()+dx, rect.y()+dy);
XFreeGC(X11->display, gc);
#else
QPixmap newPix = *pix;
QPainter painter(&newPix);
painter.setClipRect(rect);
painter.drawPixmap(rect.translated(dx, dy), *pix, rect);
painter.end();
*pix = newPix;
#endif
}
/*!
\since 4.4
Scrolls the contents of \a rect by \a dx, \a dy. If \a rect is a null rect
(the default), the item's bounding rect is scrolled.
Scrolling provides a fast alternative to simply redrawing when the
contents of the item (or parts of the item) are shifted vertically or
horizontally. Depending on the current transformation and the capabilities
of the paint device (i.e., the viewport), this operation may consist of
simply moving pixels from one location to another using memmove(). In most
cases this is faster than rerendering the entire area.
After scrolling, the item will issue an update for the newly exposed
areas. If scrolling is not supported (e.g., you are rendering to an OpenGL
viewport, which does not benefit from scroll optimizations), this function
is equivalent to calling update(\a rect).
\sa boundingRect()
*/
void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect)
{
Q_D(QGraphicsItem);
if (dx == 0.0 && dy == 0.0)
return;
if (!d->scene)
return;
if (d->cacheMode != NoCache) {
QGraphicsItemCache *c;
bool scrollCache = qFuzzyIsNull(dx - int(dx)) && qFuzzyIsNull(dy - int(dy))
&& (c = (QGraphicsItemCache *)qVariantValue<void *>(d_ptr->extra(QGraphicsItemPrivate::ExtraCacheData)))
&& (d->cacheMode == ItemCoordinateCache && !c->fixedSize.isValid());
if (scrollCache) {
QPixmap pix;
if (QPixmapCache::find(c->key, &pix)) {
// Adjust with 2 pixel margin. Notice the loss of precision
// when converting to QRect.
int adjust = 2;
QRectF br = boundingRect().adjusted(-adjust, -adjust, adjust, adjust);
QRect irect = rect.toRect().translated(-br.x(), -br.y());
_q_scrollPixmap(&pix, irect, dx, dy);
QPixmapCache::replace(c->key, pix);
// Translate the existing expose.
foreach (QRectF exposedRect, c->exposed)
c->exposed += exposedRect.translated(dx, dy) & rect;
// Calculate exposure.
QRegion exposed;
QRect r = rect.toRect();
exposed += r;
exposed -= r.translated(dx, dy);
foreach (QRect rect, exposed.rects())
update(rect);
d->scene->d_func()->markDirty(this);
} else {
update(rect);
}
} else {
// ### This is very slow, and can be done much better. If the cache is
// local and matches the below criteria for rotation and scaling, we
// can easily scroll. And if the cache is in device coordinates, we
// can scroll both the viewport and the cache.
update(rect);
}
return;
}
QRectF scrollRect = !rect.isNull() ? rect : boundingRect();
int couldntScroll = d->scene->views().size();
foreach (QGraphicsView *view, d->scene->views()) {
if (view->viewport()->inherits("QGLWidget")) {
// ### Please replace with a widget attribute; any widget that
// doesn't support partial updates / doesn't support scrolling
// should be skipped in this code. Qt::WA_NoPartialUpdates or so.
continue;
}
static const QLineF up(0, 0, 0, -1);
static const QLineF down(0, 0, 0, 1);
static const QLineF left(0, 0, -1, 0);
static const QLineF right(0, 0, 1, 0);
QTransform deviceTr = deviceTransform(view->viewportTransform());
QRect deviceScrollRect = deviceTr.mapRect(scrollRect).toRect();
QLineF v1 = deviceTr.map(right);
QLineF v2 = deviceTr.map(down);
QLineF u1 = v1.unitVector(); u1.translate(-v1.p1());
QLineF u2 = v2.unitVector(); u2.translate(-v2.p1());
bool noScroll = false;
// Check if the delta resolves to ints in device space.
QPointF deviceDelta = deviceTr.map(QPointF(dx, dy));
if ((deviceDelta.x() - int(deviceDelta.x()))
|| (deviceDelta.y() - int(deviceDelta.y()))) {
noScroll = true;
} else {
// Check if the unit vectors have no fraction in device space.
qreal v1l = v1.length();
if (v1l - int(v1l)) {
noScroll = true;
} else {
dx *= v1.length();
}
qreal v2l = v2.length();
if (v2l - int(v2l)) {
noScroll = true;
} else {
dy *= v2.length();
}
}
if (!noScroll) {
if (u1 == right) {
if (u2 == up) {
// flipped
dy = -dy;
} else if (u2 == down) {
// normal
} else {
noScroll = true;
}
} else if (u1 == left) {
if (u2 == up) {
// mirrored & flipped / rotated 180 degrees
dx = -dx;
dy = -dy;
} else if (u2 == down) {
// mirrored
dx = -dx;
} else {
noScroll = true;
}
} else if (u1 == up) {
if (u2 == left) {
// rotated -90 & mirrored
qreal tmp = dy;
dy = -dx;
dx = -tmp;
} else if (u2 == right) {
// rotated -90
qreal tmp = dy;
dy = -dx;
dx = tmp;
} else {
noScroll = true;
}
} else if (u1 == down) {
if (u2 == left) {
// rotated 90
qreal tmp = dy;
dy = dx;
dx = -tmp;
} else if (u2 == right) {
// rotated 90 & mirrored
qreal tmp = dy;
dy = dx;
dx = tmp;
} else {
noScroll = true;
}
}
}
if (!noScroll) {
view->viewport()->scroll(int(dx), int(dy), deviceScrollRect);
--couldntScroll;
}
}
if (couldntScroll)
update(rect);
}
/*!
\fn void QGraphicsItem::update(qreal x, qreal y, qreal width, qreal height)
\overload
This convenience function is equivalent to calling update(QRectF(\a x, \a
y, \a width, \a height)).
*/
/*!
Maps the point \a point, which is in this item's coordinate system, to \a
item's coordinate system, and returns the mapped coordinate.
If \a item is 0, this function returns the same as mapToScene().
\sa itemTransform(), mapToParent(), mapToScene(), transform(), mapFromItem(), {The Graphics
View Coordinate System}
*/
QPointF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPointF &point) const
{
if (item)
return itemTransform(item).map(point);
return mapToScene(point);
}
/*!
\fn QPointF QGraphicsItem::mapToItem(const QGraphicsItem *item, qreal x, qreal y) const
\overload
This convenience function is equivalent to calling mapToItem(\a item,
QPointF(\a x, \a y)).
*/
/*!
Maps the point \a point, which is in this item's coordinate system, to its
parent's coordinate system, and returns the mapped coordinate. If the item
has no parent, \a point will be mapped to the scene's coordinate system.
\sa mapToItem(), mapToScene(), transform(), mapFromParent(), {The Graphics
View Coordinate System}
*/
QPointF QGraphicsItem::mapToParent(const QPointF &point) const
{
// COMBINE
if (!d_ptr->transformData)
return point + d_ptr->pos;
return d_ptr->transformToParent().map(point);
}
/*!
\fn QPointF QGraphicsItem::mapToParent(qreal x, qreal y) const
\overload
This convenience function is equivalent to calling mapToParent(QPointF(\a
x, \a y)).
*/
/*!
Maps the point \a point, which is in this item's coordinate system, to the
scene's coordinate system, and returns the mapped coordinate.
\sa mapToItem(), mapToParent(), transform(), mapFromScene(), {The Graphics
View Coordinate System}
*/
QPointF QGraphicsItem::mapToScene(const QPointF &point) const
{
if (d_ptr->hasTranslateOnlySceneTransform())
return QPointF(point.x() + d_ptr->sceneTransform.dx(), point.y() + d_ptr->sceneTransform.dy());
return d_ptr->sceneTransform.map(point);
}
/*!
\fn QPointF QGraphicsItem::mapToScene(qreal x, qreal y) const
\overload
This convenience function is equivalent to calling mapToScene(QPointF(\a
x, \a y)).
*/
/*!
Maps the rectangle \a rect, which is in this item's coordinate system, to
\a item's coordinate system, and returns the mapped rectangle as a polygon.
If \a item is 0, this function returns the same as mapToScene().
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
*/
QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QRectF &rect) const
{
if (item)
return itemTransform(item).map(rect);
return mapToScene(rect);
}
/*!
\fn QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
\since 4.3
This convenience function is equivalent to calling mapToItem(item, QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
Maps the rectangle \a rect, which is in this item's coordinate system, to
its parent's coordinate system, and returns the mapped rectangle as a
polygon. If the item has no parent, \a rect will be mapped to the scene's
coordinate system.
\sa mapToScene(), mapToItem(), mapFromParent(), {The Graphics View
Coordinate System}
*/
QPolygonF QGraphicsItem::mapToParent(const QRectF &rect) const
{
// COMBINE
if (!d_ptr->transformData)
return rect.translated(d_ptr->pos);
return d_ptr->transformToParent().map(rect);
}
/*!
\fn QPolygonF QGraphicsItem::mapToParent(qreal x, qreal y, qreal w, qreal h) const
\since 4.3
This convenience function is equivalent to calling mapToParent(QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
Maps the rectangle \a rect, which is in this item's coordinate system, to
the scene's coordinate system, and returns the mapped rectangle as a polygon.
\sa mapToParent(), mapToItem(), mapFromScene(), {The Graphics View
Coordinate System}
*/
QPolygonF QGraphicsItem::mapToScene(const QRectF &rect) const
{
if (d_ptr->hasTranslateOnlySceneTransform())
return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
return d_ptr->sceneTransform.map(rect);
}
/*!
\fn QPolygonF QGraphicsItem::mapToScene(qreal x, qreal y, qreal w, qreal h) const
\since 4.3
This convenience function is equivalent to calling mapToScene(QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
\since 4.5
Maps the rectangle \a rect, which is in this item's coordinate system, to
\a item's coordinate system, and returns the mapped rectangle as a new
rectangle (i.e., the bounding rectangle of the resulting polygon).
If \a item is 0, this function returns the same as mapRectToScene().
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
*/
QRectF QGraphicsItem::mapRectToItem(const QGraphicsItem *item, const QRectF &rect) const
{
if (item)
return itemTransform(item).mapRect(rect);
return mapRectToScene(rect);
}
/*!
\fn QRectF QGraphicsItem::mapRectToItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
\since 4.5
This convenience function is equivalent to calling mapRectToItem(item, QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
\since 4.5
Maps the rectangle \a rect, which is in this item's coordinate system, to
its parent's coordinate system, and returns the mapped rectangle as a new
rectangle (i.e., the bounding rectangle of the resulting polygon).
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
*/
QRectF QGraphicsItem::mapRectToParent(const QRectF &rect) const
{
// COMBINE
if (!d_ptr->transformData)
return rect.translated(d_ptr->pos);
return d_ptr->transformToParent().mapRect(rect);
}
/*!
\fn QRectF QGraphicsItem::mapRectToParent(qreal x, qreal y, qreal w, qreal h) const
\since 4.5
This convenience function is equivalent to calling mapRectToParent(QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
\since 4.5
Maps the rectangle \a rect, which is in this item's coordinate system, to
the scene coordinate system, and returns the mapped rectangle as a new
rectangle (i.e., the bounding rectangle of the resulting polygon).
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
*/
QRectF QGraphicsItem::mapRectToScene(const QRectF &rect) const
{
if (d_ptr->hasTranslateOnlySceneTransform())
return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
return d_ptr->sceneTransform.mapRect(rect);
}
/*!
\fn QRectF QGraphicsItem::mapRectToScene(qreal x, qreal y, qreal w, qreal h) const
\since 4.5
This convenience function is equivalent to calling mapRectToScene(QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
\since 4.5
Maps the rectangle \a rect, which is in \a item's coordinate system, to
this item's coordinate system, and returns the mapped rectangle as a new
rectangle (i.e., the bounding rectangle of the resulting polygon).
If \a item is 0, this function returns the same as mapRectFromScene().
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
*/
QRectF QGraphicsItem::mapRectFromItem(const QGraphicsItem *item, const QRectF &rect) const
{
if (item)
return item->itemTransform(this).mapRect(rect);
return mapRectFromScene(rect);
}
/*!
\fn QRectF QGraphicsItem::mapRectFromItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
\since 4.5
This convenience function is equivalent to calling mapRectFromItem(item, QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
\since 4.5
Maps the rectangle \a rect, which is in this item's parent's coordinate
system, to this item's coordinate system, and returns the mapped rectangle
as a new rectangle (i.e., the bounding rectangle of the resulting
polygon).
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
*/
QRectF QGraphicsItem::mapRectFromParent(const QRectF &rect) const
{
// COMBINE
if (!d_ptr->transformData)
return rect.translated(-d_ptr->pos);
return d_ptr->transformToParent().inverted().mapRect(rect);
}
/*!
\fn QRectF QGraphicsItem::mapRectFromParent(qreal x, qreal y, qreal w, qreal h) const
\since 4.5
This convenience function is equivalent to calling mapRectFromParent(QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
\since 4.5
Maps the rectangle \a rect, which is in scene coordinates, to this item's
coordinate system, and returns the mapped rectangle as a new rectangle
(i.e., the bounding rectangle of the resulting polygon).
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
*/
QRectF QGraphicsItem::mapRectFromScene(const QRectF &rect) const
{
if (d_ptr->hasTranslateOnlySceneTransform())
return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
return d_ptr->sceneTransform.inverted().mapRect(rect);
}
/*!
\fn QRectF QGraphicsItem::mapRectFromScene(qreal x, qreal y, qreal w, qreal h) const
\since 4.5
This convenience function is equivalent to calling mapRectFromScene(QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
Maps the polygon \a polygon, which is in this item's coordinate system, to
\a item's coordinate system, and returns the mapped polygon.
If \a item is 0, this function returns the same as mapToScene().
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
*/
QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPolygonF &polygon) const
{
if (item)
return itemTransform(item).map(polygon);
return mapToScene(polygon);
}
/*!
Maps the polygon \a polygon, which is in this item's coordinate system, to
its parent's coordinate system, and returns the mapped polygon. If the
item has no parent, \a polygon will be mapped to the scene's coordinate
system.
\sa mapToScene(), mapToItem(), mapFromParent(), {The Graphics View
Coordinate System}
*/
QPolygonF QGraphicsItem::mapToParent(const QPolygonF &polygon) const
{
// COMBINE
if (!d_ptr->transformData)
return polygon.translated(d_ptr->pos);
return d_ptr->transformToParent().map(polygon);
}
/*!
Maps the polygon \a polygon, which is in this item's coordinate system, to
the scene's coordinate system, and returns the mapped polygon.
\sa mapToParent(), mapToItem(), mapFromScene(), {The Graphics View
Coordinate System}
*/
QPolygonF QGraphicsItem::mapToScene(const QPolygonF &polygon) const
{
if (d_ptr->hasTranslateOnlySceneTransform())
return polygon.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
return d_ptr->sceneTransform.map(polygon);
}
/*!
Maps the path \a path, which is in this item's coordinate system, to
\a item's coordinate system, and returns the mapped path.
If \a item is 0, this function returns the same as mapToScene().
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
*/
QPainterPath QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPainterPath &path) const
{
if (item)
return itemTransform(item).map(path);
return mapToScene(path);
}
/*!
Maps the path \a path, which is in this item's coordinate system, to
its parent's coordinate system, and returns the mapped path. If the
item has no parent, \a path will be mapped to the scene's coordinate
system.
\sa mapToScene(), mapToItem(), mapFromParent(), {The Graphics View
Coordinate System}
*/
QPainterPath QGraphicsItem::mapToParent(const QPainterPath &path) const
{
// COMBINE
if (!d_ptr->transformData)
return path.translated(d_ptr->pos);
return d_ptr->transformToParent().map(path);
}
/*!
Maps the path \a path, which is in this item's coordinate system, to
the scene's coordinate system, and returns the mapped path.
\sa mapToParent(), mapToItem(), mapFromScene(), {The Graphics View
Coordinate System}
*/
QPainterPath QGraphicsItem::mapToScene(const QPainterPath &path) const
{
if (d_ptr->hasTranslateOnlySceneTransform())
return path.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
return d_ptr->sceneTransform.map(path);
}
/*!
Maps the point \a point, which is in \a item's coordinate system, to this
item's coordinate system, and returns the mapped coordinate.
If \a item is 0, this function returns the same as mapFromScene().
\sa itemTransform(), mapFromParent(), mapFromScene(), transform(), mapToItem(), {The Graphics
View Coordinate System}
*/
QPointF QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QPointF &point) const
{
if (item)
return item->itemTransform(this).map(point);
return mapFromScene(point);
}
/*!
\fn QPointF QGraphicsItem::mapFromItem(const QGraphicsItem *item, qreal x, qreal y) const
\overload
This convenience function is equivalent to calling mapFromItem(\a item,
QPointF(\a x, \a y)).
*/
/*!
Maps the point \a point, which is in this item's parent's coordinate
system, to this item's coordinate system, and returns the mapped
coordinate.
\sa mapFromItem(), mapFromScene(), transform(), mapToParent(), {The Graphics
View Coordinate System}
*/
QPointF QGraphicsItem::mapFromParent(const QPointF &point) const
{
// COMBINE
if (d_ptr->transformData)
return d_ptr->transformToParent().inverted().map(point);
return point - d_ptr->pos;
}
/*!
\fn QPointF QGraphicsItem::mapFromParent(qreal x, qreal y) const
\overload
This convenience function is equivalent to calling
mapFromParent(QPointF(\a x, \a y)).
*/
/*!
Maps the point \a point, which is in this item's scene's coordinate
system, to this item's coordinate system, and returns the mapped
coordinate.
\sa mapFromItem(), mapFromParent(), transform(), mapToScene(), {The Graphics
View Coordinate System}
*/
QPointF QGraphicsItem::mapFromScene(const QPointF &point) const
{
if (d_ptr->hasTranslateOnlySceneTransform())
return QPointF(point.x() - d_ptr->sceneTransform.dx(), point.y() - d_ptr->sceneTransform.dy());
return d_ptr->sceneTransform.inverted().map(point);
}
/*!
\fn QPointF QGraphicsItem::mapFromScene(qreal x, qreal y) const
\overload
This convenience function is equivalent to calling mapFromScene(QPointF(\a
x, \a y)).
*/
/*!
Maps the rectangle \a rect, which is in \a item's coordinate system, to
this item's coordinate system, and returns the mapped rectangle as a
polygon.
If \a item is 0, this function returns the same as mapFromScene()
\sa itemTransform(), mapToItem(), mapFromParent(), transform(), {The Graphics View Coordinate
System}
*/
QPolygonF QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QRectF &rect) const
{
if (item)
return item->itemTransform(this).map(rect);
return mapFromScene(rect);
}
/*!
\fn QPolygonF QGraphicsItem::mapFromItem(const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
\since 4.3
This convenience function is equivalent to calling mapFromItem(item, QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
Maps the rectangle \a rect, which is in this item's parent's coordinate
system, to this item's coordinate system, and returns the mapped rectangle
as a polygon.
\sa mapToParent(), mapFromItem(), transform(), {The Graphics View Coordinate
System}
*/
QPolygonF QGraphicsItem::mapFromParent(const QRectF &rect) const
{
// COMBINE
if (!d_ptr->transformData)
return rect.translated(-d_ptr->pos);
return d_ptr->transformToParent().inverted().map(rect);
}
/*!
\fn QPolygonF QGraphicsItem::mapFromParent(qreal x, qreal y, qreal w, qreal h) const
\since 4.3
This convenience function is equivalent to calling mapFromItem(QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
Maps the rectangle \a rect, which is in this item's scene's coordinate
system, to this item's coordinate system, and returns the mapped rectangle
as a polygon.
\sa mapToScene(), mapFromItem(), transform(), {The Graphics View Coordinate
System}
*/
QPolygonF QGraphicsItem::mapFromScene(const QRectF &rect) const
{
if (d_ptr->hasTranslateOnlySceneTransform())
return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
return d_ptr->sceneTransform.inverted().map(rect);
}
/*!
\fn QPolygonF QGraphicsItem::mapFromScene(qreal x, qreal y, qreal w, qreal h) const
\since 4.3
This convenience function is equivalent to calling mapFromScene(QRectF(\a x, \a y, \a w, \a h)).
*/
/*!
Maps the polygon \a polygon, which is in \a item's coordinate system, to
this item's coordinate system, and returns the mapped polygon.
If \a item is 0, this function returns the same as mapFromScene().
\sa itemTransform(), mapToItem(), mapFromParent(), transform(), {The
Graphics View Coordinate System}
*/
QPolygonF QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QPolygonF &polygon) const
{
if (item)
return item->itemTransform(this).map(polygon);
return mapFromScene(polygon);
}
/*!
Maps the polygon \a polygon, which is in this item's parent's coordinate
system, to this item's coordinate system, and returns the mapped polygon.
\sa mapToParent(), mapToItem(), transform(), {The Graphics View Coordinate
System}
*/
QPolygonF QGraphicsItem::mapFromParent(const QPolygonF &polygon) const
{
// COMBINE
if (!d_ptr->transformData)
return polygon.translated(-d_ptr->pos);
return d_ptr->transformToParent().inverted().map(polygon);
}
/*!
Maps the polygon \a polygon, which is in this item's scene's coordinate
system, to this item's coordinate system, and returns the mapped polygon.
\sa mapToScene(), mapFromParent(), transform(), {The Graphics View Coordinate
System}
*/
QPolygonF QGraphicsItem::mapFromScene(const QPolygonF &polygon) const
{
if (d_ptr->hasTranslateOnlySceneTransform())
return polygon.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
return d_ptr->sceneTransform.inverted().map(polygon);
}
/*!
Maps the path \a path, which is in \a item's coordinate system, to
this item's coordinate system, and returns the mapped path.
If \a item is 0, this function returns the same as mapFromScene().
\sa itemTransform(), mapFromParent(), mapFromScene(), mapToItem(), {The
Graphics View Coordinate System}
*/
QPainterPath QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QPainterPath &path) const
{
if (item)
return item->itemTransform(this).map(path);
return mapFromScene(path);
}
/*!
Maps the path \a path, which is in this item's parent's coordinate
system, to this item's coordinate system, and returns the mapped path.
\sa mapFromScene(), mapFromItem(), mapToParent(), {The Graphics View
Coordinate System}
*/
QPainterPath QGraphicsItem::mapFromParent(const QPainterPath &path) const
{
// COMBINE
if (!d_ptr->transformData)
return path.translated(-d_ptr->pos);
return d_ptr->transformToParent().inverted().map(path);
}
/*!
Maps the path \a path, which is in this item's scene's coordinate
system, to this item's coordinate system, and returns the mapped path.
\sa mapFromParent(), mapFromItem(), mapToScene(), {The Graphics View
Coordinate System}
*/
QPainterPath QGraphicsItem::mapFromScene(const QPainterPath &path) const
{
if (d_ptr->hasTranslateOnlySceneTransform())
return path.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
return d_ptr->sceneTransform.inverted().map(path);
}
/*!
Returns true if this item is an ancestor of \a child (i.e., if this item
is \a child's parent, or one of \a child's parent's ancestors).
\sa parentItem()
*/
bool QGraphicsItem::isAncestorOf(const QGraphicsItem *child) const
{
if (!child || child == this)
return false;
const QGraphicsItem *ancestor = child;
while ((ancestor = ancestor->d_ptr->parent)) {
if (ancestor == this)
return true;
}
return false;
}
/*!
\since 4.4
Returns the closest common ancestor item of this item and \a other, or 0
if either \a other is 0, or there is no common ancestor.
\sa isAncestorOf()
*/
QGraphicsItem *QGraphicsItem::commonAncestorItem(const QGraphicsItem *other) const
{
if (!other)
return 0;
if (other == this)
return const_cast<QGraphicsItem *>(this);
const QGraphicsItem *thisw = this;
const QGraphicsItem *otherw = other;
int thisDepth = d_ptr->depth();
int otherDepth = other->d_ptr->depth();
while (thisDepth > otherDepth) {
thisw = thisw->d_ptr->parent;
--thisDepth;
}
while (otherDepth > thisDepth) {
otherw = otherw->d_ptr->parent;
--otherDepth;
}
while (thisw && thisw != otherw) {
thisw = thisw->d_ptr->parent;
otherw = otherw->d_ptr->parent;
}
return const_cast<QGraphicsItem *>(thisw);
}
/*!
\since 4,4
Returns true if this item is currently under the mouse cursor in one of
the views; otherwise, false is returned.
\sa QGraphicsScene::views(), QCursor::pos()
*/
bool QGraphicsItem::isUnderMouse() const
{
Q_D(const QGraphicsItem);
if (!d->scene)
return false;
QPoint cursorPos = QCursor::pos();
foreach (QGraphicsView *view, d->scene->views()) {
if (contains(mapFromScene(view->mapToScene(view->mapFromGlobal(cursorPos)))))
return true;
}
return false;
}
/*!
Returns this item's custom data for the key \a key as a QVariant.
Custom item data is useful for storing arbitrary properties in any
item. Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 11
Qt does not use this feature for storing data; it is provided solely
for the convenience of the user.
\sa setData()
*/
QVariant QGraphicsItem::data(int key) const
{
QGraphicsItemCustomDataStore *store = qt_dataStore();
if (!store->data.contains(this))
return QVariant();
return store->data.value(this).value(key);
}
/*!
Sets this item's custom data for the key \a key to \a value.
Custom item data is useful for storing arbitrary properties for any
item. Qt does not use this feature for storing data; it is provided solely
for the convenience of the user.
\sa data()
*/
void QGraphicsItem::setData(int key, const QVariant &value)
{
qt_dataStore()->data[this][key] = value;
}
/*!
\fn T qgraphicsitem_cast(QGraphicsItem *item)
\relates QGraphicsItem
\since 4.2
Returns the given \a item cast to type T if \a item is of type T;
otherwise, 0 is returned.
\note To make this function work correctly with custom items, reimplement
the \l{QGraphicsItem::}{type()} function for each custom QGraphicsItem
subclass.
\sa QGraphicsItem::type(), QGraphicsItem::UserType
*/
/*!
Returns the type of an item as an int. All standard graphicsitem classes
are associated with a unique value; see QGraphicsItem::Type. This type
information is used by qgraphicsitem_cast() to distinguish between types.
The default implementation (in QGraphicsItem) returns UserType.
To enable use of qgraphicsitem_cast() with a custom item, reimplement this
function and declare a Type enum value equal to your custom item's type.
Custom items must return a value larger than or equal to UserType (65536).
For example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp QGraphicsItem type
\sa UserType
*/
int QGraphicsItem::type() const
{
return (int)UserType;
}
/*!
Installs an event filter for this item on \a filterItem, causing
all events for this item to first pass through \a filterItem's
sceneEventFilter() function.
To filter another item's events, install this item as an event filter
for the other item. Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 12
An item can only filter events for other items in the same
scene. Also, an item cannot filter its own events; instead, you
can reimplement sceneEvent() directly.
Items must belong to a scene for scene event filters to be installed and
used.
\sa removeSceneEventFilter(), sceneEventFilter(), sceneEvent()
*/
void QGraphicsItem::installSceneEventFilter(QGraphicsItem *filterItem)
{
if (!d_ptr->scene) {
qWarning("QGraphicsItem::installSceneEventFilter: event filters can only be installed"
" on items in a scene.");
return;
}
if (d_ptr->scene != filterItem->scene()) {
qWarning("QGraphicsItem::installSceneEventFilter: event filters can only be installed"
" on items in the same scene.");
return;
}
d_ptr->scene->d_func()->installSceneEventFilter(this, filterItem);
}
/*!
Removes an event filter on this item from \a filterItem.
\sa installSceneEventFilter()
*/
void QGraphicsItem::removeSceneEventFilter(QGraphicsItem *filterItem)
{
if (!d_ptr->scene || d_ptr->scene != filterItem->scene())
return;
d_ptr->scene->d_func()->removeSceneEventFilter(this, filterItem);
}
/*!
Filters events for the item \a watched. \a event is the filtered
event.
Reimplementing this function in a subclass makes it possible
for the item to be used as an event filter for other items,
intercepting all the events send to those items before they are
able to respond.
Reimplementations must return true to prevent further processing of
a given event, ensuring that it will not be delivered to the watched
item, or return false to indicate that the event should be propagated
further by the event system.
\sa installSceneEventFilter()
*/
bool QGraphicsItem::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
{
Q_UNUSED(watched);
Q_UNUSED(event);
return false;
}
/*!
This virtual function receives events to this item. Reimplement
this function to intercept events before they are dispatched to
the specialized event handlers contextMenuEvent(), focusInEvent(),
focusOutEvent(), hoverEnterEvent(), hoverMoveEvent(),
hoverLeaveEvent(), keyPressEvent(), keyReleaseEvent(),
mousePressEvent(), mouseReleaseEvent(), mouseMoveEvent(), and
mouseDoubleClickEvent().
Returns true if the event was recognized and handled; otherwise, (e.g., if
the event type was not recognized,) false is returned.
\a event is the intercepted event.
*/
bool QGraphicsItem::sceneEvent(QEvent *event)
{
if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents) {
if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverLeave
|| event->type() == QEvent::DragEnter || event->type() == QEvent::DragLeave) {
// Hover enter and hover leave events for children are ignored;
// hover move events are forwarded.
return true;
}
QGraphicsItem *handler = this;
do {
handler = handler->d_ptr->parent;
Q_ASSERT(handler);
} while (handler->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents);
// Forward the event to the closest parent that handles child
// events, mapping existing item-local coordinates to its
// coordinate system.
d_ptr->remapItemPos(event, handler);
handler->sceneEvent(event);
return true;
}
if (!d_ptr->visible) {
// Eaten
return true;
}
switch (event->type()) {
case QEvent::FocusIn:
focusInEvent(static_cast<QFocusEvent *>(event));
break;
case QEvent::FocusOut:
focusOutEvent(static_cast<QFocusEvent *>(event));
break;
case QEvent::GraphicsSceneContextMenu:
contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent *>(event));
break;
case QEvent::GraphicsSceneDragEnter:
dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
break;
case QEvent::GraphicsSceneDragMove:
dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
break;
case QEvent::GraphicsSceneDragLeave:
dragLeaveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
break;
case QEvent::GraphicsSceneDrop:
dropEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
break;
case QEvent::GraphicsSceneHoverEnter:
hoverEnterEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
break;
case QEvent::GraphicsSceneHoverMove:
hoverMoveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
break;
case QEvent::GraphicsSceneHoverLeave:
hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
break;
case QEvent::GraphicsSceneMouseMove:
mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
break;
case QEvent::GraphicsSceneMousePress:
mousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
break;
case QEvent::GraphicsSceneMouseRelease:
mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
break;
case QEvent::GraphicsSceneMouseDoubleClick:
mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
break;
case QEvent::GraphicsSceneWheel:
wheelEvent(static_cast<QGraphicsSceneWheelEvent *>(event));
break;
case QEvent::KeyPress: {
QKeyEvent *k = static_cast<QKeyEvent *>(event);
if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
bool res = false;
if (k->key() == Qt::Key_Backtab
|| (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) {
if (d_ptr->isWidget) {
res = static_cast<QGraphicsWidget *>(this)->focusNextPrevChild(false);
} else if (d_ptr->scene) {
res = d_ptr->scene->focusNextPrevChild(false);
}
} else if (k->key() == Qt::Key_Tab) {
if (d_ptr->isWidget) {
res = static_cast<QGraphicsWidget *>(this)->focusNextPrevChild(true);
} else if (d_ptr->scene) {
res = d_ptr->scene->focusNextPrevChild(true);
}
}
if (!res)
event->ignore();
return true;
}
}
keyPressEvent(static_cast<QKeyEvent *>(event));
break;
}
case QEvent::KeyRelease:
keyReleaseEvent(static_cast<QKeyEvent *>(event));
break;
case QEvent::InputMethod:
inputMethodEvent(static_cast<QInputMethodEvent *>(event));
break;
case QEvent::WindowActivate:
case QEvent::WindowDeactivate:
// Propagate panel activation.
if (d_ptr->scene) {
for (int i = 0; i < d_ptr->children.size(); ++i) {
QGraphicsItem *child = d_ptr->children.at(i);
if (!(child->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents))
d_ptr->scene->sendEvent(child, event);
}
}
break;
default:
return false;
}
return true;
}
/*!
This event handler can be reimplemented in a subclass to process context
menu events. The \a event parameter contains details about the event to
be handled.
If you ignore the event, (i.e., by calling QEvent::ignore(),) \a event
will propagate to any item beneath this item. If no items accept the
event, it will be ignored by the scene, and propagate to the view.
It's common to open a QMenu in response to receiving a context menu
event. Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 13
The default implementation ignores the event.
\sa sceneEvent()
*/
void QGraphicsItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
event->ignore();
}
/*!
This event handler, for event \a event, can be reimplemented to receive
drag enter events for this item. Drag enter events are generated as the
cursor enters the item's area.
By accepting the event, (i.e., by calling QEvent::accept(),) the item will
accept drop events, in addition to receiving drag move and drag
leave. Otherwise, the event will be ignored and propagate to the item
beneath. If the event is accepted, the item will receive a drag move event
before control goes back to the event loop.
A common implementation of dragEnterEvent accepts or ignores \a event
depending on the associated mime data in \a event. Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 14
Items do not receive drag and drop events by default; to enable this
feature, call \c setAcceptDrops(true).
The default implementation does nothing.
\sa dropEvent(), dragMoveEvent(), dragLeaveEvent()
*/
void QGraphicsItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
Q_D(QGraphicsItem);
// binary compatibility workaround between 4.4 and 4.5
if (d->isProxyWidget())
static_cast<QGraphicsProxyWidget*>(this)->dragEnterEvent(event);
}
/*!
This event handler, for event \a event, can be reimplemented to receive
drag leave events for this item. Drag leave events are generated as the
cursor leaves the item's area. Most often you will not need to reimplement
this function, but it can be useful for resetting state in your item
(e.g., highlighting).
Calling QEvent::ignore() or QEvent::accept() on \a event has no effect.
Items do not receive drag and drop events by default; to enable this
feature, call \c setAcceptDrops(true).
The default implementation does nothing.
\sa dragEnterEvent(), dropEvent(), dragMoveEvent()
*/
void QGraphicsItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
Q_D(QGraphicsItem);
// binary compatibility workaround between 4.4 and 4.5
if (d->isProxyWidget())
static_cast<QGraphicsProxyWidget*>(this)->dragLeaveEvent(event);
}
/*!
This event handler, for event \a event, can be reimplemented to receive
drag move events for this item. Drag move events are generated as the
cursor moves around inside the item's area. Most often you will not need
to reimplement this function; it is used to indicate that only parts of
the item can accept drops.
Calling QEvent::ignore() or QEvent::accept() on \a event toggles whether
or not the item will accept drops at the position from the event. By
default, \a event is accepted, indicating that the item allows drops at
the specified position.
Items do not receive drag and drop events by default; to enable this
feature, call \c setAcceptDrops(true).
The default implementation does nothing.
\sa dropEvent(), dragEnterEvent(), dragLeaveEvent()
*/
void QGraphicsItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{
Q_D(QGraphicsItem);
// binary compatibility workaround between 4.4 and 4.5
if (d->isProxyWidget())
static_cast<QGraphicsProxyWidget*>(this)->dragMoveEvent(event);
}
/*!
This event handler, for event \a event, can be reimplemented to receive
drop events for this item. Items can only receive drop events if the last
drag move event was accepted.
Calling QEvent::ignore() or QEvent::accept() on \a event has no effect.
Items do not receive drag and drop events by default; to enable this
feature, call \c setAcceptDrops(true).
The default implementation does nothing.
\sa dragEnterEvent(), dragMoveEvent(), dragLeaveEvent()
*/
void QGraphicsItem::dropEvent(QGraphicsSceneDragDropEvent *event)
{
Q_D(QGraphicsItem);
// binary compatibility workaround between 4.4 and 4.5
if (d->isProxyWidget())
static_cast<QGraphicsProxyWidget*>(this)->dropEvent(event);
}
/*!
This event handler, for event \a event, can be reimplemented to receive
focus in events for this item. The default implementation calls
ensureVisible().
\sa focusOutEvent(), sceneEvent(), setFocus()
*/
void QGraphicsItem::focusInEvent(QFocusEvent *event)
{
Q_UNUSED(event);
update();
}
/*!
This event handler, for event \a event, can be reimplemented to receive
focus out events for this item. The default implementation does nothing.
\sa focusInEvent(), sceneEvent(), setFocus()
*/
void QGraphicsItem::focusOutEvent(QFocusEvent *event)
{
Q_UNUSED(event);
update();
}
/*!
This event handler, for event \a event, can be reimplemented to receive
hover enter events for this item. The default implementation calls
update(); otherwise it does nothing.
Calling QEvent::ignore() or QEvent::accept() on \a event has no effect.
\sa hoverMoveEvent(), hoverLeaveEvent(), sceneEvent(), setAcceptHoverEvents()
*/
void QGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
update();
}
/*!
This event handler, for event \a event, can be reimplemented to receive
hover move events for this item. The default implementation does nothing.
Calling QEvent::ignore() or QEvent::accept() on \a event has no effect.
\sa hoverEnterEvent(), hoverLeaveEvent(), sceneEvent(), setAcceptHoverEvents()
*/
void QGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
}
/*!
This event handler, for event \a event, can be reimplemented to receive
hover leave events for this item. The default implementation calls
update(); otherwise it does nothing.
Calling QEvent::ignore() or QEvent::accept() on \a event has no effect.
\sa hoverEnterEvent(), hoverMoveEvent(), sceneEvent(), setAcceptHoverEvents()
*/
void QGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
update();
}
/*!
This event handler, for event \a event, can be reimplemented to
receive key press events for this item. The default implementation
ignores the event. If you reimplement this handler, the event will by
default be accepted.
Note that key events are only received for items that set the
ItemIsFocusable flag, and that have keyboard input focus.
\sa keyReleaseEvent(), setFocus(), QGraphicsScene::setFocusItem(),
sceneEvent()
*/
void QGraphicsItem::keyPressEvent(QKeyEvent *event)
{
event->ignore();
}
/*!
This event handler, for event \a event, can be reimplemented to receive
key release events for this item. The default implementation
ignores the event. If you reimplement this handler, the event will by
default be accepted.
Note that key events are only received for items that set the
ItemIsFocusable flag, and that have keyboard input focus.
\sa keyPressEvent(), setFocus(), QGraphicsScene::setFocusItem(),
sceneEvent()
*/
void QGraphicsItem::keyReleaseEvent(QKeyEvent *event)
{
event->ignore();
}
/*!
This event handler, for event \a event, can be reimplemented to
receive mouse press events for this item. Mouse press events are
only delivered to items that accept the mouse button that is
pressed. By default, an item accepts all mouse buttons, but you
can change this by calling setAcceptedMouseButtons().
The mouse press event decides which item should become the mouse
grabber (see QGraphicsScene::mouseGrabberItem()). If you do not
reimplement this function, the press event will propagate to any
topmost item beneath this item, and no other mouse events will be
delivered to this item.
If you do reimplement this function, \a event will by default be
accepted (see QEvent::accept()), and this item is then the mouse
grabber. This allows the item to receive future move, release and
doubleclick events. If you call QEvent::ignore() on \a event, this
item will lose the mouse grab, and \a event will propagate to any
topmost item beneath. No further mouse events will be delivered to
this item unless a new mouse press event is received.
The default implementation handles basic item interaction, such as
selection and moving. If you want to keep the base implementation
when reimplementing this function, call
QGraphicsItem::mousePressEvent() in your reimplementation.
The event is \l{QEvent::ignore()}d for items that are neither
\l{QGraphicsItem::ItemIsMovable}{movable} nor
\l{QGraphicsItem::ItemIsSelectable}{selectable}.
\sa mouseMoveEvent(), mouseReleaseEvent(),
mouseDoubleClickEvent(), sceneEvent()
*/
void QGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) {
bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0;
if (!multiSelect) {
if (!d_ptr->selected) {
if (QGraphicsScene *scene = d_ptr->scene) {
++scene->d_func()->selectionChanging;
scene->clearSelection();
--scene->d_func()->selectionChanging;
}
setSelected(true);
}
}
} else if (!(flags() & ItemIsMovable)) {
event->ignore();
}
if (d_ptr->isWidget) {
// Qt::Popup closes when you click outside.
QGraphicsWidget *w = static_cast<QGraphicsWidget *>(this);
if (w->windowFlags() & Qt::Popup) {
event->accept();
if (!w->rect().contains(event->pos()))
w->close();
}
}
}
/*!
obsolete
*/
bool _qt_movableAncestorIsSelected(const QGraphicsItem *item)
{
const QGraphicsItem *parent = item->parentItem();
return parent && (((parent->flags() & QGraphicsItem::ItemIsMovable) && parent->isSelected()) || _qt_movableAncestorIsSelected(parent));
}
bool QGraphicsItemPrivate::movableAncestorIsSelected(const QGraphicsItem *item)
{
const QGraphicsItem *parent = item->d_ptr->parent;
return parent && (((parent->flags() & QGraphicsItem::ItemIsMovable) && parent->isSelected()) || _qt_movableAncestorIsSelected(parent));
}
/*!
This event handler, for event \a event, can be reimplemented to
receive mouse move events for this item. If you do receive this
event, you can be certain that this item also received a mouse
press event, and that this item is the current mouse grabber.
Calling QEvent::ignore() or QEvent::accept() on \a event has no
effect.
The default implementation handles basic item interaction, such as
selection and moving. If you want to keep the base implementation
when reimplementing this function, call
QGraphicsItem::mouseMoveEvent() in your reimplementation.
Please note that mousePressEvent() decides which graphics item it
is that receives mouse events. See the mousePressEvent()
description for details.
\sa mousePressEvent(), mouseReleaseEvent(),
mouseDoubleClickEvent(), sceneEvent()
*/
void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable)) {
// Determine the list of items that need to be moved.
QList<QGraphicsItem *> selectedItems;
QMap<QGraphicsItem *, QPointF> initialPositions;
if (d_ptr->scene) {
selectedItems = d_ptr->scene->selectedItems();
initialPositions = d_ptr->scene->d_func()->movingItemsInitialPositions;
if (initialPositions.isEmpty()) {
foreach (QGraphicsItem *item, selectedItems)
initialPositions[item] = item->pos();
initialPositions[this] = pos();
}
d_ptr->scene->d_func()->movingItemsInitialPositions = initialPositions;
}
// Find the active view.
QGraphicsView *view = 0;
if (event->widget())
view = qobject_cast<QGraphicsView *>(event->widget()->parentWidget());
// Move all selected items
int i = 0;
bool movedMe = false;
while (i <= selectedItems.size()) {
QGraphicsItem *item = 0;
if (i < selectedItems.size())
item = selectedItems.at(i);
else
item = this;
if (item == this) {
// Slightly clumsy-looking way to ensure that "this" is part
// of the list of items to move, this is to avoid allocations
// (appending this item to the list of selected items causes a
// detach).
if (movedMe)
break;
movedMe = true;
}
if ((item->flags() & ItemIsMovable) && !QGraphicsItemPrivate::movableAncestorIsSelected(item)) {
QPointF currentParentPos;
QPointF buttonDownParentPos;
if (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorIgnoresTransformations) {
// Items whose ancestors ignore transformations need to
// map screen coordinates to local coordinates, then map
// those to the parent.
QTransform viewToItemTransform = (item->deviceTransform(view->viewportTransform())).inverted();
currentParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->screenPos()))));
buttonDownParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton)))));
} else if (item->flags() & ItemIgnoresTransformations) {
// Root items that ignore transformations need to
// calculate their diff by mapping viewport coordinates
// directly to parent coordinates.
QTransform viewToParentTransform = (item->transform().translate(item->d_ptr->pos.x(), item->d_ptr->pos.y()))
* (item->sceneTransform() * view->viewportTransform()).inverted();
currentParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->screenPos())));
buttonDownParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton))));
} else {
// All other items simply map from the scene.
currentParentPos = item->mapToParent(item->mapFromScene(event->scenePos()));
buttonDownParentPos = item->mapToParent(item->mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
}
item->setPos(initialPositions.value(item) + currentParentPos - buttonDownParentPos);
if (item->flags() & ItemIsSelectable)
item->setSelected(true);
}
++i;
}
} else {
event->ignore();
}
}
/*!
This event handler, for event \a event, can be reimplemented to
receive mouse release events for this item.
Calling QEvent::ignore() or QEvent::accept() on \a event has no
effect.
The default implementation handles basic item interaction, such as
selection and moving. If you want to keep the base implementation
when reimplementing this function, call
QGraphicsItem::mouseReleaseEvent() in your reimplementation.
Please note that mousePressEvent() decides which graphics item it
is that receives mouse events. See the mousePressEvent()
description for details.
\sa mousePressEvent(), mouseMoveEvent(), mouseDoubleClickEvent(),
sceneEvent()
*/
void QGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (flags() & ItemIsSelectable) {
bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0;
if (event->scenePos() == event->buttonDownScenePos(Qt::LeftButton)) {
// The item didn't move
if (multiSelect) {
setSelected(!isSelected());
} else {
bool selectionChanged = false;
if (QGraphicsScene *scene = d_ptr->scene) {
++scene->d_func()->selectionChanging;
// Clear everything but this item. Bypass
// QGraphicsScene::clearSelection()'s default behavior by
// temporarily removing this item from the selection list.
if (d_ptr->selected) {
scene->d_func()->selectedItems.remove(this);
foreach (QGraphicsItem *item, scene->d_func()->selectedItems) {
if (item->isSelected()) {
selectionChanged = true;
break;
}
}
}
scene->clearSelection();
if (d_ptr->selected)
scene->d_func()->selectedItems.insert(this);
--scene->d_func()->selectionChanging;
if (selectionChanged)
emit d_ptr->scene->selectionChanged();
}
setSelected(true);
}
}
}
if (d_ptr->scene && !event->buttons())
d_ptr->scene->d_func()->movingItemsInitialPositions.clear();
}
/*!
This event handler, for event \a event, can be reimplemented to
receive mouse doubleclick events for this item.
When doubleclicking an item, the item will first receive a mouse
press event, followed by a release event (i.e., a click), then a
doubleclick event, and finally a release event.
Calling QEvent::ignore() or QEvent::accept() on \a event has no
effect.
The default implementation calls mousePressEvent(). If you want to
keep the base implementation when reimplementing this function,
call QGraphicsItem::mouseDoubleClickEvent() in your
reimplementation.
Note that an item will not receive double click events if it is
neither \l {QGraphicsItem::ItemIsSelectable}{selectable} nor
\l{QGraphicsItem::ItemIsMovable}{movable} (single mouse clicks are
ignored in this case, and that stops the generation of double
clicks).
\sa mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(), sceneEvent()
*/
void QGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
mousePressEvent(event);
}
/*!
This event handler, for event \a event, can be reimplemented to receive
wheel events for this item. If you reimplement this function, \a event
will be accepted by default.
If you ignore the event, (i.e., by calling QEvent::ignore(),) it will
propagate to any item beneath this item. If no items accept the event, it
will be ignored by the scene, and propagate to the view (e.g., the view's
vertical scroll bar).
The default implementation ignores the event.
\sa sceneEvent()
*/
void QGraphicsItem::wheelEvent(QGraphicsSceneWheelEvent *event)
{
event->ignore();
}
/*!
This event handler, for event \a event, can be reimplemented to receive
input method events for this item. The default implementation ignores the
event.
\sa inputMethodQuery(), sceneEvent()
*/
void QGraphicsItem::inputMethodEvent(QInputMethodEvent *event)
{
event->ignore();
}
/*!
This method is only relevant for input items. It is used by the
input method to query a set of properties of the item to be able
to support complex input method operations, such as support for
surrounding text and reconversions. \a query specifies which
property is queried.
\sa inputMethodEvent(), QInputMethodEvent, QInputContext
*/
QVariant QGraphicsItem::inputMethodQuery(Qt::InputMethodQuery query) const
{
if (isWidget()) {
// ### Qt 5: Remove. The reimplementation in
// QGraphicsProxyWidget solves this problem (but requires a
// recompile to take effect).
return d_ptr->inputMethodQueryHelper(query);
}
Q_UNUSED(query);
return QVariant();
}
/*!
Returns the current input method hints of this item.
Input method hints are only relevant for input items.
The hints are used by the input method to indicate how it should operate.
For example, if the Qt::ImhNumbersOnly flag is set, the input method may change
its visual components to reflect that only numbers can be entered.
The effect may vary between input method implementations.
\since 4.6
\sa setInputMethodHints(), inputMethodQuery(), QInputContext
*/
Qt::InputMethodHints QGraphicsItem::inputMethodHints() const
{
Q_D(const QGraphicsItem);
return d->imHints;
}
/*!
Sets the current input method hints of this item to \a hints.
\since 4.6
\sa inputMethodHints(), inputMethodQuery(), QInputContext
*/
void QGraphicsItem::setInputMethodHints(Qt::InputMethodHints hints)
{
Q_D(QGraphicsItem);
d->imHints = hints;
}
/*!
This virtual function is called by QGraphicsItem to notify custom items
that some part of the item's state changes. By reimplementing this
function, your can react to a change, and in some cases, (depending on \a
change,) adjustments can be made.
\a change is the parameter of the item that is changing. \a value is the
new value; the type of the value depends on \a change.
Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 15
The default implementation does nothing, and returns \a value.
Note: Certain QGraphicsItem functions cannot be called in a
reimplementation of this function; see the GraphicsItemChange
documentation for details.
\sa GraphicsItemChange
*/
QVariant QGraphicsItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
Q_UNUSED(change);
return value;
}
/*!
\internal
Note: This is provided as a hook to avoid future problems related
to adding virtual functions.
*/
bool QGraphicsItem::supportsExtension(Extension extension) const
{
Q_UNUSED(extension);
return false;
}
/*!
\internal
Note: This is provided as a hook to avoid future problems related
to adding virtual functions.
*/
void QGraphicsItem::setExtension(Extension extension, const QVariant &variant)
{
Q_UNUSED(extension);
Q_UNUSED(variant);
}
/*!
\internal
Note: This is provided as a hook to avoid future problems related
to adding virtual functions.
*/
QVariant QGraphicsItem::extension(const QVariant &variant) const
{
Q_UNUSED(variant);
return QVariant();
}
/*!
\internal
Adds this item to the scene's index. Called in conjunction with
removeFromIndex() to ensure the index bookkeeping is correct when
the item's position, transformation or shape changes.
*/
void QGraphicsItem::addToIndex()
{
if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) {
// ### add to child index only if applicable
return;
}
if (d_ptr->scene)
d_ptr->scene->d_func()->index->addItem(this);
}
/*!
\internal
Removes this item from the scene's index. Called in conjunction
with addToIndex() to ensure the index bookkeeping is correct when
the item's position, transformation or shape changes.
*/
void QGraphicsItem::removeFromIndex()
{
if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) {
// ### remove from child index only if applicable
return;
}
if (d_ptr->scene)
d_ptr->scene->d_func()->index->removeItem(this);
}
/*!
Prepares the item for a geometry change. Call this function before
changing the bounding rect of an item to keep QGraphicsScene's index up to
date.
prepareGeometryChange() will call update() if this is necessary.
Example:
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 16
\sa boundingRect()
*/
void QGraphicsItem::prepareGeometryChange()
{
if (d_ptr->scene) {
d_ptr->scene->d_func()->dirtyGrowingItemsBoundingRect = true;
d_ptr->geometryChanged = 1;
d_ptr->paintedViewBoundingRectsNeedRepaint = 1;
d_ptr->notifyBoundingRectChanged = !d_ptr->inSetPosHelper;
QGraphicsScenePrivate *scenePrivate = d_ptr->scene->d_func();
scenePrivate->index->prepareBoundingRectChange(this);
scenePrivate->markDirty(this, QRectF(),
/*invalidateChildren=*/true,
/*maybeDirtyClipPath=*/!d_ptr->inSetPosHelper);
// For compatibility reasons, we have to update the item's old geometry
// if someone is connected to the changed signal or the scene has no views.
// Note that this has to be done *after* markDirty to ensure that
// _q_processDirtyItems is called before _q_emitUpdated.
if (scenePrivate->isSignalConnected(scenePrivate->changedSignalIndex)
|| scenePrivate->views.isEmpty()) {
if (d_ptr->hasTranslateOnlySceneTransform()) {
d_ptr->scene->update(boundingRect().translated(d_ptr->sceneTransform.dx(),
d_ptr->sceneTransform.dy()));
} else {
d_ptr->scene->update(d_ptr->sceneTransform.mapRect(boundingRect()));
}
}
}
QGraphicsItem *parent = this;
while ((parent = parent->d_ptr->parent)) {
parent->d_ptr->dirtyChildrenBoundingRect = 1;
// ### Only do this if the parent's effect applies to the entire subtree.
parent->d_ptr->notifyBoundingRectChanged = 1;
}
if (d_ptr->inSetPosHelper)
return;
if (d_ptr->flags & ItemClipsChildrenToShape)
d_ptr->invalidateCachedClipPathRecursively();
else
d_ptr->invalidateCachedClipPath();
}
/*!
\internal
Highlights \a item as selected.
NOTE: This function is a duplicate of qt_graphicsItem_highlightSelected() in
qgraphicssvgitem.cpp!
*/
static void qt_graphicsItem_highlightSelected(
QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option)
{
const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1));
if (qFuzzyIsNull(qMax(murect.width(), murect.height())))
return;
const QRectF mbrect = painter->transform().mapRect(item->boundingRect());
if (qMin(mbrect.width(), mbrect.height()) < qreal(1.0))
return;
qreal itemPenWidth;
switch (item->type()) {
case QGraphicsEllipseItem::Type:
itemPenWidth = static_cast<QGraphicsEllipseItem *>(item)->pen().widthF();
break;
case QGraphicsPathItem::Type:
itemPenWidth = static_cast<QGraphicsPathItem *>(item)->pen().widthF();
break;
case QGraphicsPolygonItem::Type:
itemPenWidth = static_cast<QGraphicsPolygonItem *>(item)->pen().widthF();
break;
case QGraphicsRectItem::Type:
itemPenWidth = static_cast<QGraphicsRectItem *>(item)->pen().widthF();
break;
case QGraphicsSimpleTextItem::Type:
itemPenWidth = static_cast<QGraphicsSimpleTextItem *>(item)->pen().widthF();
break;
case QGraphicsLineItem::Type:
itemPenWidth = static_cast<QGraphicsLineItem *>(item)->pen().widthF();
break;
default:
itemPenWidth = 1.0;
}
const qreal pad = itemPenWidth / 2;
const qreal penWidth = 0; // cosmetic pen
const QColor fgcolor = option->palette.windowText().color();
const QColor bgcolor( // ensure good contrast against fgcolor
fgcolor.red() > 127 ? 0 : 255,
fgcolor.green() > 127 ? 0 : 255,
fgcolor.blue() > 127 ? 0 : 255);
painter->setPen(QPen(bgcolor, penWidth, Qt::SolidLine));
painter->setBrush(Qt::NoBrush);
painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
painter->setPen(QPen(option->palette.windowText(), 0, Qt::DashLine));
painter->setBrush(Qt::NoBrush);
painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
}
/*!
\class QGraphicsObject
\brief The QGraphicsObject class provides a base class for all graphics items that
require signals, slots and properties.
\since 4.6
\ingroup graphicsview-api
The class extends a QGraphicsItem with QObject's signal/slot and property mechanisms.
It maps many of QGraphicsItem's basic setters and getters to properties and adds notification
signals for many of them.
*/
/*!
Constructs a QGraphicsObject with \a parent.
*/
QGraphicsObject::QGraphicsObject(QGraphicsItem *parent)
: QGraphicsItem(parent)
{
QGraphicsItem::d_ptr->isObject = true;
}
/*!
\internal
*/
QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene)
: QGraphicsItem(dd, parent, scene)
{
QGraphicsItem::d_ptr->isObject = true;
}
/*!
\property QGraphicsObject::parent
\brief the parent of the item
\sa QGraphicsItem::setParentItem(), QGraphicsItem::parentObject()
*/
/*!
\property QGraphicsObject::id
\brief the id of of the item
\sa QGraphicsItem::opacity(), QGraphicsItem::setOpacity()
*/
/*!
\property QGraphicsObject::opacity
\brief the opacity of the item
\sa QGraphicsItem::setOpacity(), QGraphicsItem::opacity()
*/
/*!
\fn QGraphicsObject::opacityChanged()
This signal gets emitted whenever the opacity of the item changes
\sa QGraphicsItem::opacity()
*/
/*!
\fn QGraphicsObject::parentChanged()
This signal gets emitted whenever the parent of the item changes
*/
/*!
\property QGraphicsObject::pos
\brief the position of the item
Describes the items position.
\sa QGraphicsItem::setPos(), QGraphicsItem::pos()
*/
/*!
\property QGraphicsObject::x
\brief the x position of the item
Describes the items x position.
\sa QGraphicsItem::setX(), setPos(), xChanged()
*/
/*!
\fn QGraphicsObject::xChanged()
This signal gets emitted whenever the x position of the item changes
\sa pos()
*/
/*!
\property QGraphicsObject::y
\brief the y position of the item
Describes the items y position.
\sa QGraphicsItem::setY(), setPos(), yChanged()
*/
/*!
\fn QGraphicsObject::yChanged()
This signal gets emitted whenever the y position of the item changes.
\sa pos()
*/
/*!
\property QGraphicsObject::z
\brief the z value of the item
Describes the items z value.
\sa QGraphicsItem::setZValue(), zValue(), zChanged()
*/
/*!
\fn QGraphicsObject::zChanged()
This signal gets emitted whenever the z value of the item changes.
\sa pos()
*/
/*!
\property QGraphicsObject::rotation
This property holds the rotation of the item in degrees.
This specifies how many degrees to rotate the item around its transformOrigin.
The default rotation is 0 degrees (i.e. not rotated at all).
*/
/*!
\fn QGraphicsObject::rotationChanged()
This signal gets emitted whenever the roation of the item changes.
*/
/*!
\property QGraphicsObject::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.
*/
/*!
\fn void QGraphicsObject::scaleChanged()
This signal is emitted when the scale of the item changes.
*/
/*!
\property QGraphicsObject::enabled
\brief whether the item is enabled or not
This property is declared in QGraphicsItem.
By default, this property is true.
\sa QGraphicsItem::isEnabled(), QGraphicsItem::setEnabled()
\sa QGraphicsObject::enabledChanged()
*/
/*!
\fn void QGraphicsObject::enabledChanged()
This signal gets emitted whenever the item get's enabled or disabled.
\sa isEnabled()
*/
/*!
\property QGraphicsObject::visible
\brief whether the item is visible or not
This property is declared in QGraphicsItem.
By default, this property is true.
\sa QGraphicsItem::isVisible(), QGraphicsItem::setVisible(), visibleChanged()
*/
/*!
\fn QGraphicsObject::visibleChanged()
This signal gets emitted whenever the visibility of the item changes
\sa visible
*/
/*!
\fn const QObjectList &QGraphicsObject::children() const
\internal
This function returns the same value as QObject::children(). It's
provided to differentiate between the obsolete member
QGraphicsItem::children() and QObject::children(). QGraphicsItem now
provides childItems() instead.
*/
/*!
\property QGraphicsObject::transformOriginPoint
\brief the transformation origin
This property sets a specific point in the items coordiante system as the
origin for scale and rotation.
\sa scale, rotation, QGraphicsItem::transformOriginPoint()
*/
/*!
\class QAbstractGraphicsShapeItem
\brief The QAbstractGraphicsShapeItem class provides a common base for
all path items.
\since 4.2
\ingroup graphicsview-api
This class does not fully implement an item by itself; in particular, it
does not implement boundingRect() and paint(), which are inherited by
QGraphicsItem.
You can subclass this item to provide a simple base implementation of
accessors for the item's pen and brush.
\sa QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPathItem,
QGraphicsPolygonItem, QGraphicsTextItem, QGraphicsLineItem,
QGraphicsPixmapItem, {The Graphics View Framework}
*/
class QAbstractGraphicsShapeItemPrivate : public QGraphicsItemPrivate
{
Q_DECLARE_PUBLIC(QAbstractGraphicsShapeItem)
public:
QBrush brush;
QPen pen;
// Cached bounding rectangle
mutable QRectF boundingRect;
};
/*!
Constructs a QAbstractGraphicsShapeItem. \a parent is passed to
QGraphicsItem's constructor.
*/
QAbstractGraphicsShapeItem::QAbstractGraphicsShapeItem(QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QGraphicsItem(*new QAbstractGraphicsShapeItemPrivate, parent, scene)
{
}
/*!
\internal
*/
QAbstractGraphicsShapeItem::QAbstractGraphicsShapeItem(QAbstractGraphicsShapeItemPrivate &dd,
QGraphicsItem *parent,
QGraphicsScene *scene)
: QGraphicsItem(dd, parent, scene)
{
}
/*!
Destroys a QAbstractGraphicsShapeItem.
*/
QAbstractGraphicsShapeItem::~QAbstractGraphicsShapeItem()
{
}
/*!
Returns the item's pen. If no pen has been set, this function returns
QPen(), a default black solid line pen with 0 width.
*/
QPen QAbstractGraphicsShapeItem::pen() const
{
Q_D(const QAbstractGraphicsShapeItem);
return d->pen;
}
/*!
Sets the pen for this item to \a pen.
The pen is used to draw the item's outline.
\sa pen()
*/
void QAbstractGraphicsShapeItem::setPen(const QPen &pen)
{
Q_D(QAbstractGraphicsShapeItem);
prepareGeometryChange();
d->pen = pen;
d->boundingRect = QRectF();
update();
}
/*!
Returns the item's brush, or an empty brush if no brush has been set.
\sa setBrush()
*/
QBrush QAbstractGraphicsShapeItem::brush() const
{
Q_D(const QAbstractGraphicsShapeItem);
return d->brush;
}
/*!
Sets the item's brush to \a brush.
The item's brush is used to fill the item.
If you use a brush with a QGradient, the gradient
is relative to the item's coordinate system.
\sa brush()
*/
void QAbstractGraphicsShapeItem::setBrush(const QBrush &brush)
{
Q_D(QAbstractGraphicsShapeItem);
d->brush = brush;
update();
}
/*!
\reimp
*/
bool QAbstractGraphicsShapeItem::isObscuredBy(const QGraphicsItem *item) const
{
return QGraphicsItem::isObscuredBy(item);
}
/*!
\reimp
*/
QPainterPath QAbstractGraphicsShapeItem::opaqueArea() const
{
Q_D(const QAbstractGraphicsShapeItem);
if (d->brush.isOpaque())
return isClipped() ? clipPath() : shape();
return QGraphicsItem::opaqueArea();
}
/*!
\class QGraphicsPathItem
\brief The QGraphicsPathItem class provides a path item that you
can add to a QGraphicsScene.
\since 4.2
\ingroup graphicsview-api
To set the item's path, pass a QPainterPath to QGraphicsPathItem's
constructor, or call the setPath() function. The path() function
returns the current path.
\image graphicsview-pathitem.png
QGraphicsPathItem uses the path to provide a reasonable
implementation of boundingRect(), shape(), and contains(). The
paint() function draws the path using the item's associated pen
and brush, which you can set by calling the setPen() and
setBrush() functions.
\sa QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPolygonItem,
QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, {The Graphics
View Framework}
*/
class QGraphicsPathItemPrivate : public QAbstractGraphicsShapeItemPrivate
{
Q_DECLARE_PUBLIC(QGraphicsPathItem)
public:
QPainterPath path;
};
/*!
Constructs a QGraphicsPath item using \a path as the default path. \a
parent is passed to QAbstractGraphicsShapeItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsPathItem::QGraphicsPathItem(const QPainterPath &path,
QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsPathItemPrivate, parent, scene)
{
if (!path.isEmpty())
setPath(path);
}
/*!
Constructs a QGraphicsPath. \a parent is passed to
QAbstractGraphicsShapeItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsPathItem::QGraphicsPathItem(QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsPathItemPrivate, parent, scene)
{
}
/*!
Destroys the QGraphicsPathItem.
*/
QGraphicsPathItem::~QGraphicsPathItem()
{
}
/*!
Returns the item's path as a QPainterPath. If no item has been set, an
empty QPainterPath is returned.
\sa setPath()
*/
QPainterPath QGraphicsPathItem::path() const
{
Q_D(const QGraphicsPathItem);
return d->path;
}
/*!
Sets the item's path to be the given \a path.
\sa path()
*/
void QGraphicsPathItem::setPath(const QPainterPath &path)
{
Q_D(QGraphicsPathItem);
if (d->path == path)
return;
prepareGeometryChange();
d->path = path;
d->boundingRect = QRectF();
update();
}
/*!
\reimp
*/
QRectF QGraphicsPathItem::boundingRect() const
{
Q_D(const QGraphicsPathItem);
if (d->boundingRect.isNull()) {
qreal pw = pen().widthF();
if (pw == 0.0)
d->boundingRect = d->path.controlPointRect();
else {
d->boundingRect = shape().controlPointRect();
}
}
return d->boundingRect;
}
/*!
\reimp
*/
QPainterPath QGraphicsPathItem::shape() const
{
Q_D(const QGraphicsPathItem);
return qt_graphicsItem_shapeFromPath(d->path, d->pen);
}
/*!
\reimp
*/
bool QGraphicsPathItem::contains(const QPointF &point) const
{
return QAbstractGraphicsShapeItem::contains(point);
}
/*!
\reimp
*/
void QGraphicsPathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_D(QGraphicsPathItem);
Q_UNUSED(widget);
painter->setPen(d->pen);
painter->setBrush(d->brush);
painter->drawPath(d->path);
if (option->state & QStyle::State_Selected)
qt_graphicsItem_highlightSelected(this, painter, option);
}
/*!
\reimp
*/
bool QGraphicsPathItem::isObscuredBy(const QGraphicsItem *item) const
{
return QAbstractGraphicsShapeItem::isObscuredBy(item);
}
/*!
\reimp
*/
QPainterPath QGraphicsPathItem::opaqueArea() const
{
return QAbstractGraphicsShapeItem::opaqueArea();
}
/*!
\reimp
*/
int QGraphicsPathItem::type() const
{
return Type;
}
/*!
\internal
*/
bool QGraphicsPathItem::supportsExtension(Extension extension) const
{
Q_UNUSED(extension);
return false;
}
/*!
\internal
*/
void QGraphicsPathItem::setExtension(Extension extension, const QVariant &variant)
{
Q_UNUSED(extension);
Q_UNUSED(variant);
}
/*!
\internal
*/
QVariant QGraphicsPathItem::extension(const QVariant &variant) const
{
Q_UNUSED(variant);
return QVariant();
}
/*!
\class QGraphicsRectItem
\brief The QGraphicsRectItem class provides a rectangle item that you
can add to a QGraphicsScene.
\since 4.2
\ingroup graphicsview-api
To set the item's rectangle, pass a QRectF to QGraphicsRectItem's
constructor, or call the setRect() function. The rect() function
returns the current rectangle.
\image graphicsview-rectitem.png
QGraphicsRectItem uses the rectangle and the pen width to provide
a reasonable implementation of boundingRect(), shape(), and
contains(). The paint() function draws the rectangle using the
item's associated pen and brush, which you can set by calling the
setPen() and setBrush() functions.
\note The rendering of invalid rectangles, such as those with negative
widths or heights, is undefined. If you cannot be sure that you are
using valid rectangles (for example, if you are creating
rectangles using data from an unreliable source) then you should
use QRectF::normalized() to create normalized rectangles, and use
those instead.
\sa QGraphicsPathItem, QGraphicsEllipseItem, QGraphicsPolygonItem,
QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, {The Graphics
View Framework}
*/
class QGraphicsRectItemPrivate : public QAbstractGraphicsShapeItemPrivate
{
Q_DECLARE_PUBLIC(QGraphicsRectItem)
public:
QRectF rect;
};
/*!
Constructs a QGraphicsRectItem, using \a rect as the default rectangle.
\a parent is passed to QAbstractGraphicsShapeItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsRectItem::QGraphicsRectItem(const QRectF &rect, QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsRectItemPrivate, parent, scene)
{
setRect(rect);
}
/*!
\fn QGraphicsRectItem::QGraphicsRectItem(qreal x, qreal y, qreal width, qreal height,
QGraphicsItem *parent)
Constructs a QGraphicsRectItem with a default rectangle defined
by (\a x, \a y) and the given \a width and \a height.
\a parent is passed to QAbstractGraphicsShapeItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsRectItem::QGraphicsRectItem(qreal x, qreal y, qreal w, qreal h,
QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsRectItemPrivate, parent, scene)
{
setRect(QRectF(x, y, w, h));
}
/*!
Constructs a QGraphicsRectItem. \a parent is passed to
QAbstractGraphicsShapeItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsRectItem::QGraphicsRectItem(QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsRectItemPrivate, parent, scene)
{
}
/*!
Destroys the QGraphicsRectItem.
*/
QGraphicsRectItem::~QGraphicsRectItem()
{
}
/*!
Returns the item's rectangle.
\sa setRect()
*/
QRectF QGraphicsRectItem::rect() const
{
Q_D(const QGraphicsRectItem);
return d->rect;
}
/*!
\fn void QGraphicsRectItem::setRect(const QRectF &rectangle)
Sets the item's rectangle to be the given \a rectangle.
\sa rect()
*/
void QGraphicsRectItem::setRect(const QRectF &rect)
{
Q_D(QGraphicsRectItem);
if (d->rect == rect)
return;
prepareGeometryChange();
d->rect = rect;
d->boundingRect = QRectF();
update();
}
/*!
\fn void QGraphicsRectItem::setRect(qreal x, qreal y, qreal width, qreal height)
\fn void QGraphicsEllipseItem::setRect(qreal x, qreal y, qreal width, qreal height)
Sets the item's rectangle to the rectangle defined by (\a x, \a y)
and the given \a width and \a height.
This convenience function is equivalent to calling \c
{setRect(QRectF(x, y, width, height))}
\sa rect()
*/
/*!
\reimp
*/
QRectF QGraphicsRectItem::boundingRect() const
{
Q_D(const QGraphicsRectItem);
if (d->boundingRect.isNull()) {
qreal halfpw = pen().widthF() / 2;
d->boundingRect = d->rect;
if (halfpw > 0.0)
d->boundingRect.adjust(-halfpw, -halfpw, halfpw, halfpw);
}
return d->boundingRect;
}
/*!
\reimp
*/
QPainterPath QGraphicsRectItem::shape() const
{
Q_D(const QGraphicsRectItem);
QPainterPath path;
path.addRect(d->rect);
return qt_graphicsItem_shapeFromPath(path, d->pen);
}
/*!
\reimp
*/
bool QGraphicsRectItem::contains(const QPointF &point) const
{
return QAbstractGraphicsShapeItem::contains(point);
}
/*!
\reimp
*/
void QGraphicsRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_D(QGraphicsRectItem);
Q_UNUSED(widget);
painter->setPen(d->pen);
painter->setBrush(d->brush);
painter->drawRect(d->rect);
if (option->state & QStyle::State_Selected)
qt_graphicsItem_highlightSelected(this, painter, option);
}
/*!
\reimp
*/
bool QGraphicsRectItem::isObscuredBy(const QGraphicsItem *item) const
{
return QAbstractGraphicsShapeItem::isObscuredBy(item);
}
/*!
\reimp
*/
QPainterPath QGraphicsRectItem::opaqueArea() const
{
return QAbstractGraphicsShapeItem::opaqueArea();
}
/*!
\reimp
*/
int QGraphicsRectItem::type() const
{
return Type;
}
/*!
\internal
*/
bool QGraphicsRectItem::supportsExtension(Extension extension) const
{
Q_UNUSED(extension);
return false;
}
/*!
\internal
*/
void QGraphicsRectItem::setExtension(Extension extension, const QVariant &variant)
{
Q_UNUSED(extension);
Q_UNUSED(variant);
}
/*!
\internal
*/
QVariant QGraphicsRectItem::extension(const QVariant &variant) const
{
Q_UNUSED(variant);
return QVariant();
}
/*!
\class QGraphicsEllipseItem
\brief The QGraphicsEllipseItem class provides an ellipse item that you
can add to a QGraphicsScene.
\since 4.2
\ingroup graphicsview-api
QGraphicsEllipseItem respresents an ellipse with a fill and an outline,
and you can also use it for ellipse segments (see startAngle(),
spanAngle()).
\table
\row
\o \inlineimage graphicsview-ellipseitem.png
\o \inlineimage graphicsview-ellipseitem-pie.png
\endtable
To set the item's ellipse, pass a QRectF to QGraphicsEllipseItem's
constructor, or call setRect(). The rect() function returns the
current ellipse geometry.
QGraphicsEllipseItem uses the rect and the pen width to provide a
reasonable implementation of boundingRect(), shape(), and contains(). The
paint() function draws the ellipse using the item's associated pen and
brush, which you can set by calling setPen() and setBrush().
\sa QGraphicsPathItem, QGraphicsRectItem, QGraphicsPolygonItem,
QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, {The Graphics
View Framework}
*/
class QGraphicsEllipseItemPrivate : public QAbstractGraphicsShapeItemPrivate
{
Q_DECLARE_PUBLIC(QGraphicsEllipseItem)
public:
inline QGraphicsEllipseItemPrivate()
: startAngle(0), spanAngle(360 * 16)
{ }
QRectF rect;
int startAngle;
int spanAngle;
};
/*!
Constructs a QGraphicsEllipseItem using \a rect as the default rectangle.
\a parent is passed to QAbstractGraphicsShapeItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsEllipseItem::QGraphicsEllipseItem(const QRectF &rect, QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent, scene)
{
setRect(rect);
}
/*!
\fn QGraphicsEllipseItem::QGraphicsEllipseItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent)
\since 4.3
Constructs a QGraphicsEllipseItem using the rectangle defined by (\a x, \a
y) and the given \a width and \a height, as the default rectangle. \a
parent is passed to QAbstractGraphicsShapeItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsEllipseItem::QGraphicsEllipseItem(qreal x, qreal y, qreal w, qreal h,
QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent, scene)
{
setRect(x,y,w,h);
}
/*!
Constructs a QGraphicsEllipseItem. \a parent is passed to
QAbstractGraphicsShapeItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsEllipseItem::QGraphicsEllipseItem(QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent, scene)
{
}
/*!
Destroys the QGraphicsEllipseItem.
*/
QGraphicsEllipseItem::~QGraphicsEllipseItem()
{
}
/*!
Returns the item's ellipse geometry as a QRectF.
\sa setRect(), QPainter::drawEllipse()
*/
QRectF QGraphicsEllipseItem::rect() const
{
Q_D(const QGraphicsEllipseItem);
return d->rect;
}
/*!
Sets the item's ellipse geometry to \a rect. The rectangle's left edge
defines the left edge of the ellipse, and the rectangle's top edge
describes the top of the ellipse. The height and width of the rectangle
describe the height and width of the ellipse.
\sa rect(), QPainter::drawEllipse()
*/
void QGraphicsEllipseItem::setRect(const QRectF &rect)
{
Q_D(QGraphicsEllipseItem);
if (d->rect == rect)
return;
prepareGeometryChange();
d->rect = rect;
d->boundingRect = QRectF();
update();
}
/*!
Returns the start angle for an ellipse segment in 16ths of a degree. This
angle is used together with spanAngle() for representing an ellipse
segment (a pie). By default, the start angle is 0.
\sa setStartAngle(), spanAngle()
*/
int QGraphicsEllipseItem::startAngle() const
{
Q_D(const QGraphicsEllipseItem);
return d->startAngle;
}
/*!
Sets the start angle for an ellipse segment to \a angle, which is in 16ths
of a degree. This angle is used together with spanAngle() for representing
an ellipse segment (a pie). By default, the start angle is 0.
\sa startAngle(), setSpanAngle(), QPainter::drawPie()
*/
void QGraphicsEllipseItem::setStartAngle(int angle)
{
Q_D(QGraphicsEllipseItem);
if (angle != d->startAngle) {
prepareGeometryChange();
d->boundingRect = QRectF();
d->startAngle = angle;
update();
}
}
/*!
Returns the span angle of an ellipse segment in 16ths of a degree. This
angle is used together with startAngle() for representing an ellipse
segment (a pie). By default, this function returns 5760 (360 * 16, a full
ellipse).
\sa setSpanAngle(), startAngle()
*/
int QGraphicsEllipseItem::spanAngle() const
{
Q_D(const QGraphicsEllipseItem);
return d->spanAngle;
}
/*!
Sets the span angle for an ellipse segment to \a angle, which is in 16ths
of a degree. This angle is used together with startAngle() to represent an
ellipse segment (a pie). By default, the span angle is 5760 (360 * 16, a
full ellipse).
\sa spanAngle(), setStartAngle(), QPainter::drawPie()
*/
void QGraphicsEllipseItem::setSpanAngle(int angle)
{
Q_D(QGraphicsEllipseItem);
if (angle != d->spanAngle) {
prepareGeometryChange();
d->boundingRect = QRectF();
d->spanAngle = angle;
update();
}
}
/*!
\reimp
*/
QRectF QGraphicsEllipseItem::boundingRect() const
{
Q_D(const QGraphicsEllipseItem);
if (d->boundingRect.isNull()) {
qreal pw = pen().widthF();
if (pw == 0.0 && d->spanAngle == 360 * 16)
d->boundingRect = d->rect;
else
d->boundingRect = shape().controlPointRect();
}
return d->boundingRect;
}
/*!
\reimp
*/
QPainterPath QGraphicsEllipseItem::shape() const
{
Q_D(const QGraphicsEllipseItem);
QPainterPath path;
if (d->rect.isNull())
return path;
if (d->spanAngle != 360 * 16) {
path.moveTo(d->rect.center());
path.arcTo(d->rect, d->startAngle / 16.0, d->spanAngle / 16.0);
} else {
path.addEllipse(d->rect);
}
return qt_graphicsItem_shapeFromPath(path, d->pen);
}
/*!
\reimp
*/
bool QGraphicsEllipseItem::contains(const QPointF &point) const
{
return QAbstractGraphicsShapeItem::contains(point);
}
/*!
\reimp
*/
void QGraphicsEllipseItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_D(QGraphicsEllipseItem);
Q_UNUSED(widget);
painter->setPen(d->pen);
painter->setBrush(d->brush);
if ((d->spanAngle != 0) && (qAbs(d->spanAngle) % (360 * 16) == 0))
painter->drawEllipse(d->rect);
else
painter->drawPie(d->rect, d->startAngle, d->spanAngle);
if (option->state & QStyle::State_Selected)
qt_graphicsItem_highlightSelected(this, painter, option);
}
/*!
\reimp
*/
bool QGraphicsEllipseItem::isObscuredBy(const QGraphicsItem *item) const
{
return QAbstractGraphicsShapeItem::isObscuredBy(item);
}
/*!
\reimp
*/
QPainterPath QGraphicsEllipseItem::opaqueArea() const
{
return QAbstractGraphicsShapeItem::opaqueArea();
}
/*!
\reimp
*/
int QGraphicsEllipseItem::type() const
{
return Type;
}
/*!
\internal
*/
bool QGraphicsEllipseItem::supportsExtension(Extension extension) const
{
Q_UNUSED(extension);
return false;
}
/*!
\internal
*/
void QGraphicsEllipseItem::setExtension(Extension extension, const QVariant &variant)
{
Q_UNUSED(extension);
Q_UNUSED(variant);
}
/*!
\internal
*/
QVariant QGraphicsEllipseItem::extension(const QVariant &variant) const
{
Q_UNUSED(variant);
return QVariant();
}
/*!
\class QGraphicsPolygonItem
\brief The QGraphicsPolygonItem class provides a polygon item that you
can add to a QGraphicsScene.
\since 4.2
\ingroup graphicsview-api
To set the item's polygon, pass a QPolygonF to
QGraphicsPolygonItem's constructor, or call the setPolygon()
function. The polygon() function returns the current polygon.
\image graphicsview-polygonitem.png
QGraphicsPolygonItem uses the polygon and the pen width to provide
a reasonable implementation of boundingRect(), shape(), and
contains(). The paint() function draws the polygon using the
item's associated pen and brush, which you can set by calling the
setPen() and setBrush() functions.
\sa QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem,
QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, {The Graphics
View Framework}
*/
class QGraphicsPolygonItemPrivate : public QAbstractGraphicsShapeItemPrivate
{
Q_DECLARE_PUBLIC(QGraphicsPolygonItem)
public:
inline QGraphicsPolygonItemPrivate()
: fillRule(Qt::OddEvenFill)
{ }
QPolygonF polygon;
Qt::FillRule fillRule;
};
/*!
Constructs a QGraphicsPolygonItem with \a polygon as the default
polygon. \a parent is passed to QAbstractGraphicsShapeItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsPolygonItem::QGraphicsPolygonItem(const QPolygonF &polygon,
QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsPolygonItemPrivate, parent, scene)
{
setPolygon(polygon);
}
/*!
Constructs a QGraphicsPolygonItem. \a parent is passed to
QAbstractGraphicsShapeItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsPolygonItem::QGraphicsPolygonItem(QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsPolygonItemPrivate, parent, scene)
{
}
/*!
Destroys the QGraphicsPolygonItem.
*/
QGraphicsPolygonItem::~QGraphicsPolygonItem()
{
}
/*!
Returns the item's polygon, or an empty polygon if no polygon
has been set.
\sa setPolygon()
*/
QPolygonF QGraphicsPolygonItem::polygon() const
{
Q_D(const QGraphicsPolygonItem);
return d->polygon;
}
/*!
Sets the item's polygon to be the given \a polygon.
\sa polygon()
*/
void QGraphicsPolygonItem::setPolygon(const QPolygonF &polygon)
{
Q_D(QGraphicsPolygonItem);
if (d->polygon == polygon)
return;
prepareGeometryChange();
d->polygon = polygon;
d->boundingRect = QRectF();
update();
}
/*!
Returns the fill rule of the polygon. The default fill rule is
Qt::OddEvenFill.
\sa setFillRule(), QPainterPath::fillRule(), QPainter::drawPolygon()
*/
Qt::FillRule QGraphicsPolygonItem::fillRule() const
{
Q_D(const QGraphicsPolygonItem);
return d->fillRule;
}
/*!
Sets the fill rule of the polygon to \a rule. The default fill rule is
Qt::OddEvenFill.
\sa fillRule(), QPainterPath::fillRule(), QPainter::drawPolygon()
*/
void QGraphicsPolygonItem::setFillRule(Qt::FillRule rule)
{
Q_D(QGraphicsPolygonItem);
if (rule != d->fillRule) {
d->fillRule = rule;
update();
}
}
/*!
\reimp
*/
QRectF QGraphicsPolygonItem::boundingRect() const
{
Q_D(const QGraphicsPolygonItem);
if (d->boundingRect.isNull()) {
qreal pw = pen().widthF();
if (pw == 0.0)
d->boundingRect = d->polygon.boundingRect();
else
d->boundingRect = shape().controlPointRect();
}
return d->boundingRect;
}
/*!
\reimp
*/
QPainterPath QGraphicsPolygonItem::shape() const
{
Q_D(const QGraphicsPolygonItem);
QPainterPath path;
path.addPolygon(d->polygon);
return qt_graphicsItem_shapeFromPath(path, d->pen);
}
/*!
\reimp
*/
bool QGraphicsPolygonItem::contains(const QPointF &point) const
{
return QAbstractGraphicsShapeItem::contains(point);
}
/*!
\reimp
*/
void QGraphicsPolygonItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_D(QGraphicsPolygonItem);
Q_UNUSED(widget);
painter->setPen(d->pen);
painter->setBrush(d->brush);
painter->drawPolygon(d->polygon, d->fillRule);
if (option->state & QStyle::State_Selected)
qt_graphicsItem_highlightSelected(this, painter, option);
}
/*!
\reimp
*/
bool QGraphicsPolygonItem::isObscuredBy(const QGraphicsItem *item) const
{
return QAbstractGraphicsShapeItem::isObscuredBy(item);
}
/*!
\reimp
*/
QPainterPath QGraphicsPolygonItem::opaqueArea() const
{
return QAbstractGraphicsShapeItem::opaqueArea();
}
/*!
\reimp
*/
int QGraphicsPolygonItem::type() const
{
return Type;
}
/*!
\internal
*/
bool QGraphicsPolygonItem::supportsExtension(Extension extension) const
{
Q_UNUSED(extension);
return false;
}
/*!
\internal
*/
void QGraphicsPolygonItem::setExtension(Extension extension, const QVariant &variant)
{
Q_UNUSED(extension);
Q_UNUSED(variant);
}
/*!
\internal
*/
QVariant QGraphicsPolygonItem::extension(const QVariant &variant) const
{
Q_UNUSED(variant);
return QVariant();
}
/*!
\class QGraphicsLineItem
\brief The QGraphicsLineItem class provides a line item that you can add to a
QGraphicsScene.
\since 4.2
\ingroup graphicsview-api
To set the item's line, pass a QLineF to QGraphicsLineItem's
constructor, or call the setLine() function. The line() function
returns the current line. By default the line is black with a
width of 0, but you can change this by calling setPen().
\img graphicsview-lineitem.png
QGraphicsLineItem uses the line and the pen width to provide a reasonable
implementation of boundingRect(), shape(), and contains(). The paint()
function draws the line using the item's associated pen.
\sa QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem,
QGraphicsTextItem, QGraphicsPolygonItem, QGraphicsPixmapItem, {The
Graphics View Framework}
*/
class QGraphicsLineItemPrivate : public QGraphicsItemPrivate
{
Q_DECLARE_PUBLIC(QGraphicsLineItem)
public:
QLineF line;
QPen pen;
};
/*!
Constructs a QGraphicsLineItem, using \a line as the default line. \a
parent is passed to QGraphicsItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsLineItem::QGraphicsLineItem(const QLineF &line, QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QGraphicsItem(*new QGraphicsLineItemPrivate, parent, scene)
{
setLine(line);
}
/*!
Constructs a QGraphicsLineItem, using the line between (\a x1, \a y1) and
(\a x2, \a y2) as the default line. \a parent is passed to
QGraphicsItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsLineItem::QGraphicsLineItem(qreal x1, qreal y1, qreal x2, qreal y2, QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QGraphicsItem(*new QGraphicsLineItemPrivate, parent, scene)
{
setLine(x1, y1, x2, y2);
}
/*!
Constructs a QGraphicsLineItem. \a parent is passed to QGraphicsItem's
constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsLineItem::QGraphicsLineItem(QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QGraphicsItem(*new QGraphicsLineItemPrivate, parent, scene)
{
}
/*!
Destroys the QGraphicsLineItem.
*/
QGraphicsLineItem::~QGraphicsLineItem()
{
}
/*!
Returns the item's pen, or a black solid 0-width pen if no pen has
been set.
\sa setPen()
*/
QPen QGraphicsLineItem::pen() const
{
Q_D(const QGraphicsLineItem);
return d->pen;
}
/*!
Sets the item's pen to \a pen. If no pen is set, the line will be painted
using a black solid 0-width pen.
\sa pen()
*/
void QGraphicsLineItem::setPen(const QPen &pen)
{
Q_D(QGraphicsLineItem);
prepareGeometryChange();
d->pen = pen;
update();
}
/*!
Returns the item's line, or a null line if no line has been set.
\sa setLine()
*/
QLineF QGraphicsLineItem::line() const
{
Q_D(const QGraphicsLineItem);
return d->line;
}
/*!
Sets the item's line to be the given \a line.
\sa line()
*/
void QGraphicsLineItem::setLine(const QLineF &line)
{
Q_D(QGraphicsLineItem);
if (d->line == line)
return;
prepareGeometryChange();
d->line = line;
update();
}
/*!
\fn void QGraphicsLineItem::setLine(qreal x1, qreal y1, qreal x2, qreal y2)
\overload
Sets the item's line to be the line between (\a x1, \a y1) and (\a
x2, \a y2).
This is the same as calling \c {setLine(QLineF(x1, y1, x2, y2))}.
*/
/*!
\reimp
*/
QRectF QGraphicsLineItem::boundingRect() const
{
Q_D(const QGraphicsLineItem);
if (d->pen.widthF() == 0.0) {
const qreal x1 = d->line.p1().x();
const qreal x2 = d->line.p2().x();
const qreal y1 = d->line.p1().y();
const qreal y2 = d->line.p2().y();
qreal lx = qMin(x1, x2);
qreal rx = qMax(x1, x2);
qreal ty = qMin(y1, y2);
qreal by = qMax(y1, y2);
return QRectF(lx, ty, rx - lx, by - ty);
}
return shape().controlPointRect();
}
/*!
\reimp
*/
QPainterPath QGraphicsLineItem::shape() const
{
Q_D(const QGraphicsLineItem);
QPainterPath path;
if (d->line == QLineF())
return path;
path.moveTo(d->line.p1());
path.lineTo(d->line.p2());
return qt_graphicsItem_shapeFromPath(path, d->pen);
}
/*!
\reimp
*/
bool QGraphicsLineItem::contains(const QPointF &point) const
{
return QGraphicsItem::contains(point);
}
/*!
\reimp
*/
void QGraphicsLineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_D(QGraphicsLineItem);
Q_UNUSED(widget);
painter->setPen(d->pen);
painter->drawLine(d->line);
if (option->state & QStyle::State_Selected)
qt_graphicsItem_highlightSelected(this, painter, option);
}
/*!
\reimp
*/
bool QGraphicsLineItem::isObscuredBy(const QGraphicsItem *item) const
{
return QGraphicsItem::isObscuredBy(item);
}
/*!
\reimp
*/
QPainterPath QGraphicsLineItem::opaqueArea() const
{
return QGraphicsItem::opaqueArea();
}
/*!
\reimp
*/
int QGraphicsLineItem::type() const
{
return Type;
}
/*!
\internal
*/
bool QGraphicsLineItem::supportsExtension(Extension extension) const
{
Q_UNUSED(extension);
return false;
}
/*!
\internal
*/
void QGraphicsLineItem::setExtension(Extension extension, const QVariant &variant)
{
Q_UNUSED(extension);
Q_UNUSED(variant);
}
/*!
\internal
*/
QVariant QGraphicsLineItem::extension(const QVariant &variant) const
{
Q_UNUSED(variant);
return QVariant();
}
/*!
\class QGraphicsPixmapItem
\brief The QGraphicsPixmapItem class provides a pixmap item that you can add to
a QGraphicsScene.
\since 4.2
\ingroup graphicsview-api
To set the item's pixmap, pass a QPixmap to QGraphicsPixmapItem's
constructor, or call the setPixmap() function. The pixmap()
function returns the current pixmap.
QGraphicsPixmapItem uses pixmap's optional alpha mask to provide a
reasonable implementation of boundingRect(), shape(), and contains().
\image graphicsview-pixmapitem.png
The pixmap is drawn at the item's (0, 0) coordinate, as returned by
offset(). You can change the drawing offset by calling setOffset().
You can set the pixmap's transformation mode by calling
setTransformationMode(). By default, Qt::FastTransformation is used, which
provides fast, non-smooth scaling. Qt::SmoothTransformation enables
QPainter::SmoothPixmapTransform on the painter, and the quality depends on
the platform and viewport. The result is usually not as good as calling
QPixmap::scale() directly. Call transformationMode() to get the current
transformation mode for the item.
\sa QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem,
QGraphicsTextItem, QGraphicsPolygonItem, QGraphicsLineItem, {The
Graphics View Framework}
*/
/*!
\enum QGraphicsPixmapItem::ShapeMode
This enum describes how QGraphicsPixmapItem calculates its shape and
opaque area.
The default value is MaskShape.
\value MaskShape The shape is determined by calling QPixmap::mask().
This shape includes only the opaque pixels of the pixmap.
Because the shape is more complex, however, it can be slower than the other modes,
and uses more memory.
\value BoundingRectShape The shape is determined by tracing the outline of
the pixmap. This is the fastest shape mode, but it does not take into account
any transparent areas on the pixmap.
\value HeuristicMaskShape The shape is determine by calling
QPixmap::createHeuristicMask(). The performance and memory consumption
is similar to MaskShape.
*/
extern QPainterPath qt_regionToPath(const QRegion ®ion);
class QGraphicsPixmapItemPrivate : public QGraphicsItemPrivate
{
Q_DECLARE_PUBLIC(QGraphicsPixmapItem)
public:
QGraphicsPixmapItemPrivate()
: transformationMode(Qt::FastTransformation),
shapeMode(QGraphicsPixmapItem::MaskShape),
hasShape(false)
{}
QPixmap pixmap;
Qt::TransformationMode transformationMode;
QPointF offset;
QGraphicsPixmapItem::ShapeMode shapeMode;
QPainterPath shape;
bool hasShape;
void updateShape()
{
shape = QPainterPath();
switch (shapeMode) {
case QGraphicsPixmapItem::MaskShape: {
QBitmap mask = pixmap.mask();
if (!mask.isNull()) {
shape = qt_regionToPath(QRegion(mask).translated(offset.toPoint()));
break;
}
// FALL THROUGH
}
case QGraphicsPixmapItem::BoundingRectShape:
shape.addRect(QRectF(offset.x(), offset.y(), pixmap.width(), pixmap.height()));
break;
case QGraphicsPixmapItem::HeuristicMaskShape:
#ifndef QT_NO_IMAGE_HEURISTIC_MASK
shape = qt_regionToPath(QRegion(pixmap.createHeuristicMask()).translated(offset.toPoint()));
#else
shape.addRect(QRectF(offset.x(), offset.y(), pixmap.width(), pixmap.height()));
#endif
break;
}
}
};
/*!
Constructs a QGraphicsPixmapItem, using \a pixmap as the default pixmap.
\a parent is passed to QGraphicsItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsPixmapItem::QGraphicsPixmapItem(const QPixmap &pixmap,
QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QGraphicsItem(*new QGraphicsPixmapItemPrivate, parent, scene)
{
setPixmap(pixmap);
}
/*!
Constructs a QGraphicsPixmapItem. \a parent is passed to QGraphicsItem's
constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsPixmapItem::QGraphicsPixmapItem(QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QGraphicsItem(*new QGraphicsPixmapItemPrivate, parent, scene)
{
}
/*!
Destroys the QGraphicsPixmapItem.
*/
QGraphicsPixmapItem::~QGraphicsPixmapItem()
{
}
/*!
Sets the item's pixmap to \a pixmap.
\sa pixmap()
*/
void QGraphicsPixmapItem::setPixmap(const QPixmap &pixmap)
{
Q_D(QGraphicsPixmapItem);
prepareGeometryChange();
d->pixmap = pixmap;
d->hasShape = false;
update();
}
/*!
Returns the item's pixmap, or an invalid QPixmap if no pixmap has been
set.
\sa setPixmap()
*/
QPixmap QGraphicsPixmapItem::pixmap() const
{
Q_D(const QGraphicsPixmapItem);
return d->pixmap;
}
/*!
Returns the transformation mode of the pixmap. The default mode is
Qt::FastTransformation, which provides quick transformation with no
smoothing.
\sa setTransformationMode()
*/
Qt::TransformationMode QGraphicsPixmapItem::transformationMode() const
{
Q_D(const QGraphicsPixmapItem);
return d->transformationMode;
}
/*!
Sets the pixmap item's transformation mode to \a mode, and toggles an
update of the item. The default mode is Qt::FastTransformation, which
provides quick transformation with no smoothing.
Qt::SmoothTransformation enables QPainter::SmoothPixmapTransform on the
painter, and the quality depends on the platform and viewport. The result
is usually not as good as calling QPixmap::scale() directly.
\sa transformationMode()
*/
void QGraphicsPixmapItem::setTransformationMode(Qt::TransformationMode mode)
{
Q_D(QGraphicsPixmapItem);
if (mode != d->transformationMode) {
d->transformationMode = mode;
update();
}
}
/*!
Returns the pixmap item's \e offset, which defines the point of the
top-left corner of the pixmap, in local coordinates.
\sa setOffset()
*/
QPointF QGraphicsPixmapItem::offset() const
{
Q_D(const QGraphicsPixmapItem);
return d->offset;
}
/*!
Sets the pixmap item's offset to \a offset. QGraphicsPixmapItem will draw
its pixmap using \a offset for its top-left corner.
\sa offset()
*/
void QGraphicsPixmapItem::setOffset(const QPointF &offset)
{
Q_D(QGraphicsPixmapItem);
if (d->offset == offset)
return;
prepareGeometryChange();
d->offset = offset;
d->hasShape = false;
update();
}
/*!
\fn void QGraphicsPixmapItem::setOffset(qreal x, qreal y)
\since 4.3
This convenience function is equivalent to calling setOffset(QPointF(\a x, \a y)).
*/
/*!
\reimp
*/
QRectF QGraphicsPixmapItem::boundingRect() const
{
Q_D(const QGraphicsPixmapItem);
qreal pw = 1.0;
if (d->pixmap.isNull())
return QRectF();
return QRectF(d->offset, d->pixmap.size()).adjusted(-pw/2, -pw/2, pw/2, pw/2);
}
/*!
\reimp
*/
QPainterPath QGraphicsPixmapItem::shape() const
{
Q_D(const QGraphicsPixmapItem);
if (!d->hasShape) {
QGraphicsPixmapItemPrivate *thatD = const_cast<QGraphicsPixmapItemPrivate *>(d);
thatD->updateShape();
thatD->hasShape = true;
}
return d_func()->shape;
}
/*!
\reimp
*/
bool QGraphicsPixmapItem::contains(const QPointF &point) const
{
return QGraphicsItem::contains(point);
}
/*!
\reimp
*/
void QGraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_D(QGraphicsPixmapItem);
Q_UNUSED(widget);
painter->setRenderHint(QPainter::SmoothPixmapTransform,
(d->transformationMode == Qt::SmoothTransformation));
painter->drawPixmap(d->offset, d->pixmap);
if (option->state & QStyle::State_Selected)
qt_graphicsItem_highlightSelected(this, painter, option);
}
/*!
\reimp
*/
bool QGraphicsPixmapItem::isObscuredBy(const QGraphicsItem *item) const
{
return QGraphicsItem::isObscuredBy(item);
}
/*!
\reimp
*/
QPainterPath QGraphicsPixmapItem::opaqueArea() const
{
return shape();
}
/*!
\reimp
*/
int QGraphicsPixmapItem::type() const
{
return Type;
}
/*!
Returns the item's shape mode. The shape mode describes how
QGraphicsPixmapItem calculates its shape. The default mode is MaskShape.
\sa setShapeMode(), ShapeMode
*/
QGraphicsPixmapItem::ShapeMode QGraphicsPixmapItem::shapeMode() const
{
return d_func()->shapeMode;
}
/*!
Sets the item's shape mode to \a mode. The shape mode describes how
QGraphicsPixmapItem calculates its shape. The default mode is MaskShape.
\sa shapeMode(), ShapeMode
*/
void QGraphicsPixmapItem::setShapeMode(ShapeMode mode)
{
Q_D(QGraphicsPixmapItem);
if (d->shapeMode == mode)
return;
d->shapeMode = mode;
d->hasShape = false;
}
/*!
\internal
*/
bool QGraphicsPixmapItem::supportsExtension(Extension extension) const
{
Q_UNUSED(extension);
return false;
}
/*!
\internal
*/
void QGraphicsPixmapItem::setExtension(Extension extension, const QVariant &variant)
{
Q_UNUSED(extension);
Q_UNUSED(variant);
}
/*!
\internal
*/
QVariant QGraphicsPixmapItem::extension(const QVariant &variant) const
{
Q_UNUSED(variant);
return QVariant();
}
/*!
\class QGraphicsTextItem
\brief The QGraphicsTextItem class provides a text item that you can add to
a QGraphicsScene to display formatted text.
\since 4.2
\ingroup graphicsview-api
If you only need to show plain text in an item, consider using QGraphicsSimpleTextItem
instead.
To set the item's text, pass a QString to QGraphicsTextItem's
constructor, or call setHtml()/setPlainText().
QGraphicsTextItem uses the text's formatted size and the associated font
to provide a reasonable implementation of boundingRect(), shape(),
and contains(). You can set the font by calling setFont().
It is possible to make the item editable by setting the Qt::TextEditorInteraction flag
using setTextInteractionFlags().
The item's preferred text width can be set using setTextWidth() and obtained
using textWidth().
\note In order to align HTML text in the center, the item's text width must be set.
\img graphicsview-textitem.png
\note QGraphicsTextItem accepts \l{QGraphicsItem::acceptHoverEvents()}{hover events}
by default. You can change this with \l{QGraphicsItem::}{setAcceptHoverEvents()}.
\sa QGraphicsSimpleTextItem, QGraphicsPathItem, QGraphicsRectItem,
QGraphicsEllipseItem, QGraphicsPixmapItem, QGraphicsPolygonItem,
QGraphicsLineItem, {The Graphics View Framework}
*/
class QGraphicsTextItemPrivate
{
public:
QGraphicsTextItemPrivate()
: control(0), pageNumber(0), useDefaultImpl(false), tabChangesFocus(false), clickCausedFocus(0)
{ }
mutable QTextControl *control;
QTextControl *textControl() const;
inline QPointF controlOffset() const
{ return QPointF(0., pageNumber * control->document()->pageSize().height()); }
inline void sendControlEvent(QEvent *e)
{ if (control) control->processEvent(e, controlOffset()); }
void _q_updateBoundingRect(const QSizeF &);
void _q_update(QRectF);
void _q_ensureVisible(QRectF);
bool _q_mouseOnEdge(QGraphicsSceneMouseEvent *);
QRectF boundingRect;
int pageNumber;
bool useDefaultImpl;
bool tabChangesFocus;
uint clickCausedFocus : 1;
QGraphicsTextItem *qq;
};
/*!
Constructs a QGraphicsTextItem, using \a text as the default plain
text. \a parent is passed to QGraphicsItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsTextItem::QGraphicsTextItem(const QString &text, QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QGraphicsObject(*new QGraphicsItemPrivate, parent, scene), dd(new QGraphicsTextItemPrivate)
{
dd->qq = this;
if (!text.isEmpty())
setPlainText(text);
setAcceptDrops(true);
setAcceptHoverEvents(true);
setFlags(ItemUsesExtendedStyleOption);
}
/*!
Constructs a QGraphicsTextItem. \a parent is passed to QGraphicsItem's
constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsTextItem::QGraphicsTextItem(QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QGraphicsObject(*new QGraphicsItemPrivate, parent, scene), dd(new QGraphicsTextItemPrivate)
{
dd->qq = this;
setAcceptDrops(true);
setAcceptHoverEvents(true);
setFlag(ItemUsesExtendedStyleOption);
}
/*!
Destroys the QGraphicsTextItem.
*/
QGraphicsTextItem::~QGraphicsTextItem()
{
delete dd;
}
/*!
Returns the item's text converted to HTML, or an empty QString if no text has been set.
\sa setHtml()
*/
QString QGraphicsTextItem::toHtml() const
{
#ifndef QT_NO_TEXTHTMLPARSER
if (dd->control)
return dd->control->toHtml();
#endif
return QString();
}
/*!
Sets the item's text to \a text, assuming that text is HTML formatted. If
the item has keyboard input focus, this function will also call
ensureVisible() to ensure that the text is visible in all viewports.
\sa toHtml(), hasFocus(), QGraphicsSimpleTextItem
*/
void QGraphicsTextItem::setHtml(const QString &text)
{
dd->textControl()->setHtml(text);
}
/*!
Returns the item's text converted to plain text, or an empty QString if no text has been set.
\sa setPlainText()
*/
QString QGraphicsTextItem::toPlainText() const
{
if (dd->control)
return dd->control->toPlainText();
return QString();
}
/*!
Sets the item's text to \a text. If the item has keyboard input focus,
this function will also call ensureVisible() to ensure that the text is
visible in all viewports.
\sa toHtml(), hasFocus()
*/
void QGraphicsTextItem::setPlainText(const QString &text)
{
dd->textControl()->setPlainText(text);
}
/*!
Returns the item's font, which is used to render the text.
\sa setFont()
*/
QFont QGraphicsTextItem::font() const
{
if (!dd->control)
return QFont();
return dd->control->document()->defaultFont();
}
/*!
Sets the font used to render the text item to \a font.
\sa font()
*/
void QGraphicsTextItem::setFont(const QFont &font)
{
dd->textControl()->document()->setDefaultFont(font);
}
/*!
Sets the color for unformatted text to \a col.
*/
void QGraphicsTextItem::setDefaultTextColor(const QColor &col)
{
QTextControl *c = dd->textControl();
QPalette pal = c->palette();
pal.setColor(QPalette::Text, col);
c->setPalette(pal);
}
/*!
Returns the default text color that is used to for unformatted text.
*/
QColor QGraphicsTextItem::defaultTextColor() const
{
return dd->textControl()->palette().color(QPalette::Text);
}
/*!
\reimp
*/
QRectF QGraphicsTextItem::boundingRect() const
{
return dd->boundingRect;
}
/*!
\reimp
*/
QPainterPath QGraphicsTextItem::shape() const
{
if (!dd->control)
return QPainterPath();
QPainterPath path;
path.addRect(dd->boundingRect);
return path;
}
/*!
\reimp
*/
bool QGraphicsTextItem::contains(const QPointF &point) const
{
return dd->boundingRect.contains(point);
}
/*!
\reimp
*/
void QGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(widget);
if (dd->control) {
painter->save();
QRectF r = option->exposedRect;
painter->translate(-dd->controlOffset());
r.translate(dd->controlOffset());
QTextDocument *doc = dd->control->document();
QTextDocumentLayout *layout = qobject_cast<QTextDocumentLayout *>(doc->documentLayout());
// the layout might need to expand the root frame to
// the viewport if NoWrap is set
if (layout)
layout->setViewport(dd->boundingRect);
dd->control->drawContents(painter, r);
if (layout)
layout->setViewport(QRect());
painter->restore();
}
if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus))
qt_graphicsItem_highlightSelected(this, painter, option);
}
/*!
\reimp
*/
bool QGraphicsTextItem::isObscuredBy(const QGraphicsItem *item) const
{
return QGraphicsItem::isObscuredBy(item);
}
/*!
\reimp
*/
QPainterPath QGraphicsTextItem::opaqueArea() const
{
return QGraphicsItem::opaqueArea();
}
/*!
\reimp
*/
int QGraphicsTextItem::type() const
{
return Type;
}
/*!
Sets the preferred width for the item's text. If the actual text
is wider than the specified width then it will be broken into
multiple lines.
If \a width is set to -1 then the text will not be broken into
multiple lines unless it is enforced through an explicit line
break or a new paragraph.
The default value is -1.
Note that QGraphicsTextItem keeps a QTextDocument internally,
which is used to calculate the text width.
\sa textWidth(), QTextDocument::setTextWidth()
*/
void QGraphicsTextItem::setTextWidth(qreal width)
{
dd->textControl()->setTextWidth(width);
}
/*!
Returns the text width.
The width is calculated with the QTextDocument that
QGraphicsTextItem keeps internally.
\sa setTextWidth(), QTextDocument::textWidth()
*/
qreal QGraphicsTextItem::textWidth() const
{
if (!dd->control)
return -1;
return dd->control->textWidth();
}
/*!
Adjusts the text item to a reasonable size.
*/
void QGraphicsTextItem::adjustSize()
{
if (dd->control)
dd->control->adjustSize();
}
/*!
Sets the text document \a document on the item.
*/
void QGraphicsTextItem::setDocument(QTextDocument *document)
{
dd->textControl()->setDocument(document);
dd->_q_updateBoundingRect(dd->control->size());
}
/*!
Returns the item's text document.
*/
QTextDocument *QGraphicsTextItem::document() const
{
return dd->textControl()->document();
}
/*!
\reimp
*/
bool QGraphicsTextItem::sceneEvent(QEvent *event)
{
QEvent::Type t = event->type();
if (!dd->tabChangesFocus && (t == QEvent::KeyPress || t == QEvent::KeyRelease)) {
int k = ((QKeyEvent *)event)->key();
if (k == Qt::Key_Tab || k == Qt::Key_Backtab) {
dd->sendControlEvent(event);
return true;
}
}
bool result = QGraphicsItem::sceneEvent(event);
// Ensure input context is updated.
switch (event->type()) {
case QEvent::ContextMenu:
case QEvent::FocusIn:
case QEvent::FocusOut:
case QEvent::GraphicsSceneDragEnter:
case QEvent::GraphicsSceneDragLeave:
case QEvent::GraphicsSceneDragMove:
case QEvent::GraphicsSceneDrop:
case QEvent::GraphicsSceneHoverEnter:
case QEvent::GraphicsSceneHoverLeave:
case QEvent::GraphicsSceneHoverMove:
case QEvent::GraphicsSceneMouseDoubleClick:
case QEvent::GraphicsSceneMousePress:
case QEvent::GraphicsSceneMouseMove:
case QEvent::GraphicsSceneMouseRelease:
case QEvent::KeyPress:
case QEvent::KeyRelease:
// Reset the focus widget's input context, regardless
// of how this item gained or lost focus.
if (QWidget *fw = qApp->focusWidget()) {
if (QInputContext *qic = fw->inputContext()) {
if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut)
qic->reset();
else
qic->update();
}
}
break;
default:
break;
}
return result;
}
/*!
\reimp
*/
void QGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if ((QGraphicsItem::d_ptr->flags & (ItemIsSelectable | ItemIsMovable))
&& (event->buttons() & Qt::LeftButton) && dd->_q_mouseOnEdge(event)) {
// User left-pressed on edge of selectable/movable item, use
// base impl.
dd->useDefaultImpl = true;
} else if (event->buttons() == event->button()
&& dd->control->textInteractionFlags() == Qt::NoTextInteraction) {
// User pressed first button on non-interactive item.
dd->useDefaultImpl = true;
}
if (dd->useDefaultImpl) {
QGraphicsItem::mousePressEvent(event);
if (!event->isAccepted())
dd->useDefaultImpl = false;
return;
}
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (dd->useDefaultImpl) {
QGraphicsItem::mouseMoveEvent(event);
return;
}
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (dd->useDefaultImpl) {
QGraphicsItem::mouseReleaseEvent(event);
if (dd->control->textInteractionFlags() == Qt::NoTextInteraction
&& !event->buttons()) {
// User released last button on non-interactive item.
dd->useDefaultImpl = false;
} else if ((event->buttons() & Qt::LeftButton) == 0) {
// User released the left button on an interactive item.
dd->useDefaultImpl = false;
}
return;
}
QWidget *widget = event->widget();
if (widget) {
qt_widget_private(widget)->handleSoftwareInputPanel(event->button(), dd->clickCausedFocus);
}
dd->clickCausedFocus = 0;
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if (dd->useDefaultImpl) {
QGraphicsItem::mouseDoubleClickEvent(event);
return;
}
if (!hasFocus()) {
QGraphicsItem::mouseDoubleClickEvent(event);
return;
}
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::keyPressEvent(QKeyEvent *event)
{
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::keyReleaseEvent(QKeyEvent *event)
{
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::focusInEvent(QFocusEvent *event)
{
dd->sendControlEvent(event);
if (event->reason() == Qt::MouseFocusReason) {
dd->clickCausedFocus = 1;
}
update();
}
/*!
\reimp
*/
void QGraphicsTextItem::focusOutEvent(QFocusEvent *event)
{
dd->sendControlEvent(event);
update();
}
/*!
\reimp
*/
void QGraphicsTextItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::dropEvent(QGraphicsSceneDragDropEvent *event)
{
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::inputMethodEvent(QInputMethodEvent *event)
{
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
dd->sendControlEvent(event);
}
/*!
\reimp
*/
void QGraphicsTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
dd->sendControlEvent(event);
}
/*!
\reimp
*/
QVariant QGraphicsTextItem::inputMethodQuery(Qt::InputMethodQuery query) const
{
QVariant v;
if (dd->control)
v = dd->control->inputMethodQuery(query);
if (v.type() == QVariant::RectF)
v = v.toRectF().translated(-dd->controlOffset());
else if (v.type() == QVariant::PointF)
v = v.toPointF() - dd->controlOffset();
else if (v.type() == QVariant::Rect)
v = v.toRect().translated(-dd->controlOffset().toPoint());
else if (v.type() == QVariant::Point)
v = v.toPoint() - dd->controlOffset().toPoint();
return v;
}
/*!
\internal
*/
bool QGraphicsTextItem::supportsExtension(Extension extension) const
{
Q_UNUSED(extension);
return false;
}
/*!
\internal
*/
void QGraphicsTextItem::setExtension(Extension extension, const QVariant &variant)
{
Q_UNUSED(extension);
Q_UNUSED(variant);
}
/*!
\internal
*/
QVariant QGraphicsTextItem::extension(const QVariant &variant) const
{
Q_UNUSED(variant);
return QVariant();
}
/*!
\internal
*/
void QGraphicsTextItemPrivate::_q_update(QRectF rect)
{
if (rect.isValid()) {
rect.translate(-controlOffset());
} else {
rect = boundingRect;
}
if (rect.intersects(boundingRect))
qq->update(rect);
}
/*!
\internal
*/
void QGraphicsTextItemPrivate::_q_updateBoundingRect(const QSizeF &size)
{
if (!control) return; // can't happen
const QSizeF pageSize = control->document()->pageSize();
// paged items have a constant (page) size
if (size == boundingRect.size() || pageSize.height() != -1)
return;
qq->prepareGeometryChange();
boundingRect.setSize(size);
qq->update();
}
/*!
\internal
*/
void QGraphicsTextItemPrivate::_q_ensureVisible(QRectF rect)
{
if (qq->hasFocus()) {
rect.translate(-controlOffset());
qq->ensureVisible(rect, /*xmargin=*/0, /*ymargin=*/0);
}
}
QTextControl *QGraphicsTextItemPrivate::textControl() const
{
if (!control) {
QGraphicsTextItem *that = const_cast<QGraphicsTextItem *>(qq);
control = new QTextControl(that);
control->setTextInteractionFlags(Qt::NoTextInteraction);
QObject::connect(control, SIGNAL(updateRequest(QRectF)),
qq, SLOT(_q_update(QRectF)));
QObject::connect(control, SIGNAL(documentSizeChanged(QSizeF)),
qq, SLOT(_q_updateBoundingRect(QSizeF)));
QObject::connect(control, SIGNAL(visibilityRequest(QRectF)),
qq, SLOT(_q_ensureVisible(QRectF)));
QObject::connect(control, SIGNAL(linkActivated(QString)),
qq, SIGNAL(linkActivated(QString)));
QObject::connect(control, SIGNAL(linkHovered(QString)),
qq, SIGNAL(linkHovered(QString)));
const QSizeF pgSize = control->document()->pageSize();
if (pgSize.height() != -1) {
qq->prepareGeometryChange();
that->dd->boundingRect.setSize(pgSize);
qq->update();
} else {
that->dd->_q_updateBoundingRect(control->size());
}
}
return control;
}
/*!
\internal
*/
bool QGraphicsTextItemPrivate::_q_mouseOnEdge(QGraphicsSceneMouseEvent *event)
{
QPainterPath path;
path.addRect(qq->boundingRect());
QPainterPath docPath;
const QTextFrameFormat format = control->document()->rootFrame()->frameFormat();
docPath.addRect(
qq->boundingRect().adjusted(
format.leftMargin(),
format.topMargin(),
-format.rightMargin(),
-format.bottomMargin()));
return path.subtracted(docPath).contains(event->pos());
}
/*!
\fn QGraphicsTextItem::linkActivated(const QString &link)
This signal is emitted when the user clicks on a link on a text item
that enables Qt::LinksAccessibleByMouse or Qt::LinksAccessibleByKeyboard.
\a link is the link that was clicked.
\sa setTextInteractionFlags()
*/
/*!
\fn QGraphicsTextItem::linkHovered(const QString &link)
This signal is emitted when the user hovers over a link on a text item
that enables Qt::LinksAccessibleByMouse. \a link is
the link that was hovered over.
\sa setTextInteractionFlags()
*/
/*!
Sets the flags \a flags to specify how the text item should react to user
input.
The default for a QGraphicsTextItem is Qt::NoTextInteraction. This function
also affects the ItemIsFocusable QGraphicsItem flag by setting it if \a flags
is different from Qt::NoTextInteraction and clearing it otherwise.
By default, the text is read-only. To transform the item into an editor,
set the Qt::TextEditable flag.
*/
void QGraphicsTextItem::setTextInteractionFlags(Qt::TextInteractionFlags flags)
{
if (flags == Qt::NoTextInteraction)
setFlags(this->flags() & ~QGraphicsItem::ItemIsFocusable);
else
setFlags(this->flags() | QGraphicsItem::ItemIsFocusable);
dd->textControl()->setTextInteractionFlags(flags);
}
/*!
Returns the current text interaction flags.
\sa setTextInteractionFlags()
*/
Qt::TextInteractionFlags QGraphicsTextItem::textInteractionFlags() const
{
if (!dd->control)
return Qt::NoTextInteraction;
return dd->control->textInteractionFlags();
}
/*!
\since 4.5
If \a b is true, the \gui Tab key will cause the widget to change focus;
otherwise, the tab key will insert a tab into the document.
In some occasions text edits should not allow the user to input tabulators
or change indentation using the \gui Tab key, as this breaks the focus
chain. The default is false.
\sa tabChangesFocus(), ItemIsFocusable, textInteractionFlags()
*/
void QGraphicsTextItem::setTabChangesFocus(bool b)
{
dd->tabChangesFocus = b;
}
/*!
\since 4.5
Returns true if the \gui Tab key will cause the widget to change focus;
otherwise, false is returned.
By default, this behavior is disabled, and this function will return false.
\sa setTabChangesFocus()
*/
bool QGraphicsTextItem::tabChangesFocus() const
{
return dd->tabChangesFocus;
}
/*!
\property QGraphicsTextItem::openExternalLinks
Specifies whether QGraphicsTextItem should automatically open links using
QDesktopServices::openUrl() instead of emitting the
linkActivated signal.
The default value is false.
*/
void QGraphicsTextItem::setOpenExternalLinks(bool open)
{
dd->textControl()->setOpenExternalLinks(open);
}
bool QGraphicsTextItem::openExternalLinks() const
{
if (!dd->control)
return false;
return dd->control->openExternalLinks();
}
/*!
\property QGraphicsTextItem::textCursor
This property represents the visible text cursor in an editable
text item.
By default, if the item's text has not been set, this property
contains a null text cursor; otherwise it contains a text cursor
placed at the start of the item's document.
*/
void QGraphicsTextItem::setTextCursor(const QTextCursor &cursor)
{
dd->textControl()->setTextCursor(cursor);
}
QTextCursor QGraphicsTextItem::textCursor() const
{
if (!dd->control)
return QTextCursor();
return dd->control->textCursor();
}
class QGraphicsSimpleTextItemPrivate : public QAbstractGraphicsShapeItemPrivate
{
Q_DECLARE_PUBLIC(QGraphicsSimpleTextItem)
public:
inline QGraphicsSimpleTextItemPrivate() {
pen.setStyle(Qt::NoPen);
brush.setStyle(Qt::SolidPattern);
}
QString text;
QFont font;
QRectF boundingRect;
void updateBoundingRect();
};
static QRectF setupTextLayout(QTextLayout *layout)
{
layout->setCacheEnabled(true);
layout->beginLayout();
while (layout->createLine().isValid())
;
layout->endLayout();
qreal maxWidth = 0;
qreal y = 0;
for (int i = 0; i < layout->lineCount(); ++i) {
QTextLine line = layout->lineAt(i);
maxWidth = qMax(maxWidth, line.naturalTextWidth());
line.setPosition(QPointF(0, y));
y += line.height();
}
return QRectF(0, 0, maxWidth, y);
}
void QGraphicsSimpleTextItemPrivate::updateBoundingRect()
{
Q_Q(QGraphicsSimpleTextItem);
QRectF br;
if (text.isEmpty()) {
br = QRectF();
} else {
QString tmp = text;
tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);
QStackTextEngine engine(tmp, font);
QTextLayout layout(&engine);
br = setupTextLayout(&layout);
}
if (br != boundingRect) {
q->prepareGeometryChange();
boundingRect = br;
q->update();
}
}
/*!
\class QGraphicsSimpleTextItem
\brief The QGraphicsSimpleTextItem class provides a simple text path item
that you can add to a QGraphicsScene.
\since 4.2
\ingroup graphicsview-api
To set the item's text, you can either pass a QString to
QGraphicsSimpleTextItem's constructor, or call setText() to change the
text later. To set the text fill color, call setBrush().
The simple text item can have both a fill and an outline; setBrush() will
set the text fill (i.e., text color), and setPen() sets the pen that will
be used to draw the text outline. (The latter can be slow, especially for
complex pens, and items with long text content.) If all you want is to
draw a simple line of text, you should call setBrush() only, and leave the
pen unset; QGraphicsSimpleTextItem's pen is by default Qt::NoPen.
QGraphicsSimpleTextItem uses the text's formatted size and the associated
font to provide a reasonable implementation of boundingRect(), shape(),
and contains(). You can set the font by calling setFont().
QGraphicsSimpleText does not display rich text; instead, you can use
QGraphicsTextItem, which provides full text control capabilities.
\img graphicsview-simpletextitem.png
\sa QGraphicsTextItem, QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem,
QGraphicsPixmapItem, QGraphicsPolygonItem, QGraphicsLineItem, {The
Graphics View Framework}
*/
/*!
Constructs a QGraphicsSimpleTextItem.
\a parent is passed to QGraphicsItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsSimpleTextItem::QGraphicsSimpleTextItem(QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsSimpleTextItemPrivate, parent, scene)
{
}
/*!
Constructs a QGraphicsSimpleTextItem, using \a text as the default plain text.
\a parent is passed to QGraphicsItem's constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsSimpleTextItem::QGraphicsSimpleTextItem(const QString &text, QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QAbstractGraphicsShapeItem(*new QGraphicsSimpleTextItemPrivate, parent, scene)
{
setText(text);
}
/*!
Destroys the QGraphicsSimpleTextItem.
*/
QGraphicsSimpleTextItem::~QGraphicsSimpleTextItem()
{
}
/*!
Sets the item's text to \a text. The text will be displayed as
plain text. Newline characters ('\n') as well as characters of
type QChar::LineSeparator will cause item to break the text into
multiple lines.
*/
void QGraphicsSimpleTextItem::setText(const QString &text)
{
Q_D(QGraphicsSimpleTextItem);
if (d->text == text)
return;
d->text = text;
d->updateBoundingRect();
update();
}
/*!
Returns the item's text.
*/
QString QGraphicsSimpleTextItem::text() const
{
Q_D(const QGraphicsSimpleTextItem);
return d->text;
}
/*!
Sets the font that is used to draw the item's text to \a font.
*/
void QGraphicsSimpleTextItem::setFont(const QFont &font)
{
Q_D(QGraphicsSimpleTextItem);
d->font = font;
d->updateBoundingRect();
}
/*!
Returns the font that is used to draw the item's text.
*/
QFont QGraphicsSimpleTextItem::font() const
{
Q_D(const QGraphicsSimpleTextItem);
return d->font;
}
/*!
\reimp
*/
QRectF QGraphicsSimpleTextItem::boundingRect() const
{
Q_D(const QGraphicsSimpleTextItem);
return d->boundingRect;
}
/*!
\reimp
*/
QPainterPath QGraphicsSimpleTextItem::shape() const
{
Q_D(const QGraphicsSimpleTextItem);
QPainterPath path;
path.addRect(d->boundingRect);
return path;
}
/*!
\reimp
*/
bool QGraphicsSimpleTextItem::contains(const QPointF &point) const
{
Q_D(const QGraphicsSimpleTextItem);
return d->boundingRect.contains(point);
}
/*!
\reimp
*/
void QGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
Q_D(QGraphicsSimpleTextItem);
painter->setFont(d->font);
QString tmp = d->text;
tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);
QStackTextEngine engine(tmp, d->font);
QTextLayout layout(&engine);
setupTextLayout(&layout);
QPen p;
p.setBrush(d->brush);
painter->setPen(p);
if (d->pen.style() == Qt::NoPen && d->brush.style() == Qt::SolidPattern) {
painter->setBrush(Qt::NoBrush);
} else {
QTextLayout::FormatRange range;
range.start = 0;
range.length = layout.text().length();
range.format.setTextOutline(d->pen);
QList<QTextLayout::FormatRange> formats;
formats.append(range);
layout.setAdditionalFormats(formats);
}
layout.draw(painter, QPointF(0, 0));
if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus))
qt_graphicsItem_highlightSelected(this, painter, option);
}
/*!
\reimp
*/
bool QGraphicsSimpleTextItem::isObscuredBy(const QGraphicsItem *item) const
{
return QAbstractGraphicsShapeItem::isObscuredBy(item);
}
/*!
\reimp
*/
QPainterPath QGraphicsSimpleTextItem::opaqueArea() const
{
return QAbstractGraphicsShapeItem::opaqueArea();
}
/*!
\reimp
*/
int QGraphicsSimpleTextItem::type() const
{
return Type;
}
/*!
\internal
*/
bool QGraphicsSimpleTextItem::supportsExtension(Extension extension) const
{
Q_UNUSED(extension);
return false;
}
/*!
\internal
*/
void QGraphicsSimpleTextItem::setExtension(Extension extension, const QVariant &variant)
{
Q_UNUSED(extension);
Q_UNUSED(variant);
}
/*!
\internal
*/
QVariant QGraphicsSimpleTextItem::extension(const QVariant &variant) const
{
Q_UNUSED(variant);
return QVariant();
}
/*!
\class QGraphicsItemGroup
\brief The QGraphicsItemGroup class provides treating a group of items as
one.
\since 4.2
\ingroup graphicsview-api
A QGraphicsItemGroup is a special type of compound item that
treats itself and all its children as one item (i.e., all events
and geometries for all children are merged together). It's common
to use item groups in presentation tools, when the user wants to
group several smaller items into one big item in order to simplify
moving and copying of items.
If all you want is to store items inside other items, you can use
any QGraphicsItem directly by passing a suitable parent to
setParentItem().
The boundingRect() function of QGraphicsItemGroup returns the
bounding rectangle of all items in the item group.
QGraphicsItemGroup ignores the ItemIgnoresTransformations flag on
its children (i.e., with respect to the geometry of the group
item, the children are treated as if they were transformable).
There are two ways to construct an item group. The easiest and
most common approach is to pass a list of items (e.g., all
selected items) to QGraphicsScene::createItemGroup(), which
returns a new QGraphicsItemGroup item. The other approach is to
manually construct a QGraphicsItemGroup item, add it to the scene
calling QGraphicsScene::addItem(), and then add items to the group
manually, one at a time by calling addToGroup(). To dismantle
("ungroup") an item group, you can either call
QGraphicsScene::destroyItemGroup(), or you can manually remove all
items from the group by calling removeFromGroup().
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 17
The operation of adding and removing items preserves the items'
scene-relative position and transformation, as opposed to calling
setParentItem(), where only the child item's parent-relative
position and transformation are kept.
The addtoGroup() function reparents the target item to this item
group, keeping the item's position and transformation intact
relative to the scene. Visually, this means that items added via
addToGroup() will remain completely unchanged as a result of this
operation, regardless of the item or the group's current position
or transformation; although the item's position and matrix are
likely to change.
The removeFromGroup() function has similar semantics to
setParentItem(); it reparents the item to the parent item of the
item group. As with addToGroup(), the item's scene-relative
position and transformation remain intact.
\sa QGraphicsItem, {The Graphics View Framework}
*/
class QGraphicsItemGroupPrivate : public QGraphicsItemPrivate
{
public:
QRectF itemsBoundingRect;
};
/*!
Constructs a QGraphicsItemGroup. \a parent is passed to QGraphicsItem's
constructor.
\sa QGraphicsScene::addItem()
*/
QGraphicsItemGroup::QGraphicsItemGroup(QGraphicsItem *parent
#ifndef Q_QDOC
// obsolete argument
, QGraphicsScene *scene
#endif
)
: QGraphicsItem(*new QGraphicsItemGroupPrivate, parent, scene)
{
setHandlesChildEvents(true);
}
/*!
Destroys the QGraphicsItemGroup.
*/
QGraphicsItemGroup::~QGraphicsItemGroup()
{
}
/*!
Adds the given \a item to this item group. The item will be
reparented to this group, but its position and transformation
relative to the scene will stay intact.
\sa removeFromGroup(), QGraphicsScene::createItemGroup()
*/
void QGraphicsItemGroup::addToGroup(QGraphicsItem *item)
{
Q_D(QGraphicsItemGroup);
if (!item) {
qWarning("QGraphicsItemGroup::addToGroup: cannot add null item");
return;
}
if (item == this) {
qWarning("QGraphicsItemGroup::addToGroup: cannot add a group to itself");
return;
}
// COMBINE
bool ok;
QTransform itemTransform = item->itemTransform(this, &ok);
if (!ok) {
qWarning("QGraphicsItemGroup::addToGroup: could not find a valid transformation from item to group coordinates");
return;
}
QTransform newItemTransform(itemTransform);
item->setPos(mapFromItem(item, 0, 0));
item->setParentItem(this);
// removing position from translation component of the new transform
if (!item->pos().isNull())
newItemTransform *= QTransform::fromTranslate(-item->x(), -item->y());
item->setTransform(newItemTransform);
item->d_func()->setIsMemberOfGroup(true);
prepareGeometryChange();
d->itemsBoundingRect |= itemTransform.mapRect(item->boundingRect() | item->childrenBoundingRect());
update();
}
/*!
Removes the specified \a item from this group. The item will be
reparented to this group's parent item, or to 0 if this group has
no parent. Its position and transformation relative to the scene
will stay intact.
\sa addToGroup(), QGraphicsScene::destroyItemGroup()
*/
void QGraphicsItemGroup::removeFromGroup(QGraphicsItem *item)
{
Q_D(QGraphicsItemGroup);
if (!item) {
qWarning("QGraphicsItemGroup::removeFromGroup: cannot remove null item");
return;
}
QGraphicsItem *newParent = d_ptr->parent;
QPointF oldPos = item->mapToItem(newParent, 0, 0);
item->setParentItem(newParent);
// ### This function should remap the item's matrix to keep the item's
// transformation unchanged relative to the scene.
item->setPos(oldPos);
item->d_func()->setIsMemberOfGroup(item->group() != 0);
// ### Quite expensive. But removeFromGroup() isn't called very often.
prepareGeometryChange();
d->itemsBoundingRect = childrenBoundingRect();
}
/*!
\reimp
Returns the bounding rect of this group item, and all its children.
*/
QRectF QGraphicsItemGroup::boundingRect() const
{
Q_D(const QGraphicsItemGroup);
return d->itemsBoundingRect;
}
/*!
\reimp
*/
void QGraphicsItemGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(widget);
if (option->state & QStyle::State_Selected) {
Q_D(QGraphicsItemGroup);
painter->setBrush(Qt::NoBrush);
painter->drawRect(d->itemsBoundingRect);
}
}
/*!
\reimp
*/
bool QGraphicsItemGroup::isObscuredBy(const QGraphicsItem *item) const
{
return QGraphicsItem::isObscuredBy(item);
}
/*!
\reimp
*/
QPainterPath QGraphicsItemGroup::opaqueArea() const
{
return QGraphicsItem::opaqueArea();
}
/*!
\reimp
*/
int QGraphicsItemGroup::type() const
{
return Type;
}
QRectF QGraphicsItemEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const
{
const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
if (!info && deviceCoordinates) {
// Device coordinates without info not yet supported.
qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context");
return QRectF();
}
QRectF rect = item->boundingRect();
if (!item->d_ptr->children.isEmpty())
rect |= item->childrenBoundingRect();
if (deviceCoordinates) {
Q_ASSERT(info->painter);
rect = info->painter->worldTransform().mapRect(rect);
}
return rect;
}
void QGraphicsItemEffectSourcePrivate::draw(QPainter *painter)
{
if (!info) {
qWarning("QGraphicsEffectSource::draw: Can only begin as a result of QGraphicsEffect::draw");
return;
}
Q_ASSERT(item->d_ptr->scene);
QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();
if (painter == info->painter) {
scened->draw(item, painter, info->viewTransform, info->transformPtr, info->exposedRegion,
info->widget, info->opacity, info->effectTransform, info->wasDirtySceneTransform,
info->drawItem);
} else {
QTransform effectTransform = info->painter->worldTransform().inverted();
effectTransform *= painter->worldTransform();
scened->draw(item, painter, info->viewTransform, info->transformPtr, info->exposedRegion,
info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,
info->drawItem);
}
}
QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset) const
{
const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
if (!info && deviceCoordinates) {
// Device coordinates without info not yet supported.
qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
return QPixmap();
}
if (!item->d_ptr->scene)
return QPixmap();
QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();
const QRectF sourceRect = boundingRect(system);
QRect effectRect = item->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect();
if (offset)
*offset = effectRect.topLeft();
if (deviceCoordinates) {
// Clip to viewport rect.
int left, top, right, bottom;
effectRect.getCoords(&left, &top, &right, &bottom);
if (left < 0) {
if (offset)
offset->rx() += -left;
effectRect.setX(0);
}
if (top < 0) {
if (offset)
offset->ry() += -top;
effectRect.setY(0);
}
// NB! We use +-1 for historical reasons (see QRect documentation).
if (right + 1 > info->widget->width())
effectRect.setRight(info->widget->width() - 1);
if (bottom + 1 > info->widget->height())
effectRect.setBottom(info->widget->height() -1);
}
if (effectRect.isEmpty())
return QPixmap();
QPixmap pixmap(effectRect.size());
pixmap.fill(Qt::transparent);
QPainter pixmapPainter(&pixmap);
pixmapPainter.setRenderHints(info ? info->painter->renderHints() : QPainter::TextAntialiasing);
QTransform effectTransform = QTransform::fromTranslate(-effectRect.x(), -effectRect.y());
if (deviceCoordinates && info->effectTransform)
effectTransform *= *info->effectTransform;
if (!info) {
// Logical coordinates without info.
QTransform sceneTransform = item->sceneTransform();
QTransform newEffectTransform = sceneTransform.inverted();
newEffectTransform *= effectTransform;
scened->draw(item, &pixmapPainter, 0, &sceneTransform, 0, 0, qreal(1.0),
&newEffectTransform, false, true);
} else if (deviceCoordinates) {
// Device coordinates with info.
scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, info->exposedRegion,
info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,
info->drawItem);
} else {
// Item coordinates with info.
QTransform newEffectTransform = info->transformPtr->inverted();
newEffectTransform *= effectTransform;
scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, info->exposedRegion,
info->widget, info->opacity, &newEffectTransform, info->wasDirtySceneTransform,
info->drawItem);
}
pixmapPainter.end();
return pixmap;
}
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, QGraphicsItem *item)
{
if (!item) {
debug << "QGraphicsItem(0)";
return debug;
}
debug << "QGraphicsItem(this =" << ((void*)item)
<< ", parent =" << ((void*)item->parentItem())
<< ", pos =" << item->pos()
<< ", z =" << item->zValue() << ", flags = "
<< item->flags() << ")";
return debug;
}
QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemChange change)
{
const char *str = "UnknownChange";
switch (change) {
case QGraphicsItem::ItemChildAddedChange:
str = "ItemChildAddedChange";
break;
case QGraphicsItem::ItemChildRemovedChange:
str = "ItemChildRemovedChange";
break;
case QGraphicsItem::ItemCursorChange:
str = "ItemCursorChange";
break;
case QGraphicsItem::ItemCursorHasChanged:
str = "ItemCursorHasChanged";
break;
case QGraphicsItem::ItemEnabledChange:
str = "ItemEnabledChange";
break;
case QGraphicsItem::ItemEnabledHasChanged:
str = "ItemEnabledHasChanged";
break;
case QGraphicsItem::ItemFlagsChange:
str = "ItemFlagsChange";
break;
case QGraphicsItem::ItemFlagsHaveChanged:
str = "ItemFlagsHaveChanged";
break;
case QGraphicsItem::ItemMatrixChange:
str = "ItemMatrixChange";
break;
case QGraphicsItem::ItemParentChange:
str = "ItemParentChange";
break;
case QGraphicsItem::ItemParentHasChanged:
str = "ItemParentHasChanged";
break;
case QGraphicsItem::ItemPositionChange:
str = "ItemPositionChange";
break;
case QGraphicsItem::ItemPositionHasChanged:
str = "ItemPositionHasChanged";
break;
case QGraphicsItem::ItemSceneChange:
str = "ItemSceneChange";
break;
case QGraphicsItem::ItemSceneHasChanged:
str = "ItemSceneHasChanged";
break;
case QGraphicsItem::ItemSelectedChange:
str = "ItemSelectedChange";
break;
case QGraphicsItem::ItemSelectedHasChanged:
str = "ItemSelectedHasChanged";
break;
case QGraphicsItem::ItemToolTipChange:
str = "ItemToolTipChange";
break;
case QGraphicsItem::ItemToolTipHasChanged:
str = "ItemToolTipHasChanged";
break;
case QGraphicsItem::ItemTransformChange:
str = "ItemTransformChange";
break;
case QGraphicsItem::ItemTransformHasChanged:
str = "ItemTransformHasChanged";
break;
case QGraphicsItem::ItemVisibleChange:
str = "ItemVisibleChange";
break;
case QGraphicsItem::ItemVisibleHasChanged:
str = "ItemVisibleHasChanged";
break;
case QGraphicsItem::ItemZValueChange:
str = "ItemZValueChange";
break;
case QGraphicsItem::ItemZValueHasChanged:
str = "ItemZValueHasChanged";
break;
case QGraphicsItem::ItemOpacityChange:
str = "ItemOpacityChange";
break;
case QGraphicsItem::ItemOpacityHasChanged:
str = "ItemOpacityHasChanged";
break;
}
debug << str;
return debug;
}
QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag flag)
{
const char *str = "UnknownFlag";
switch (flag) {
case QGraphicsItem::ItemIsMovable:
str = "ItemIsMovable";
break;
case QGraphicsItem::ItemIsSelectable:
str = "ItemIsSelectable";
break;
case QGraphicsItem::ItemIsFocusable:
str = "ItemIsFocusable";
break;
case QGraphicsItem::ItemClipsToShape:
str = "ItemClipsToShape";
break;
case QGraphicsItem::ItemClipsChildrenToShape:
str = "ItemClipsChildrenToShape";
break;
case QGraphicsItem::ItemIgnoresTransformations:
str = "ItemIgnoresTransformations";
break;
case QGraphicsItem::ItemIgnoresParentOpacity:
str = "ItemIgnoresParentOpacity";
break;
case QGraphicsItem::ItemDoesntPropagateOpacityToChildren:
str = "ItemDoesntPropagateOpacityToChildren";
break;
case QGraphicsItem::ItemStacksBehindParent:
str = "ItemStacksBehindParent";
break;
case QGraphicsItem::ItemUsesExtendedStyleOption:
str = "ItemUsesExtendedStyleOption";
break;
case QGraphicsItem::ItemHasNoContents:
str = "ItemHasNoContents";
break;
case QGraphicsItem::ItemSendsGeometryChanges:
str = "ItemSendsGeometryChanges";
break;
case QGraphicsItem::ItemAcceptsInputMethod:
str = "ItemAcceptsInputMethod";
break;
case QGraphicsItem::ItemNegativeZStacksBehindParent:
str = "ItemNegativeZStacksBehindParent";
break;
case QGraphicsItem::ItemAutoDetectsFocusProxy:
str = "ItemAutoDetectsFocusProxy";
break;
case QGraphicsItem::ItemIsPanel:
str = "ItemIsPanel";
break;
}
debug << str;
return debug;
}
QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlags flags)
{
debug << '(';
bool f = false;
for (int i = 0; i < 16; ++i) {
if (flags & (1 << i)) {
if (f)
debug << '|';
f = true;
debug << QGraphicsItem::GraphicsItemFlag(int(flags & (1 << i)));
}
}
debug << ')';
return debug;
}
#endif
QT_END_NAMESPACE
#include "moc_qgraphicsitem.cpp"
#endif // QT_NO_GRAPHICSVIEW
|