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
|
/*
$Id: KDGanttViewSubwidgets.cpp 669475 2007-05-29 13:44:48Z mueller $
KDGantt - a multi-platform charting engine
*/
/****************************************************************************
** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
**
** This file is part of the KDGantt library.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid commercial KDGantt licenses may use this file in
** accordance with the KDGantt Commercial License Agreement provided with
** the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
** information about KDGantt Commercial License Agreements.
**
** Contact info@klaralvdalens-datakonsult.se if any conditions of this
** licensing are not clear to you.
**
** As a special exception, permission is given to link this program
** with any edition of TQt, and distribute the resulting executable,
** without including the source code for TQt in the source distribution.
**
**********************************************************************/
#include "KDGanttViewSubwidgets.h"
#include "KDGanttViewEventItem.h"
#include "KDGanttViewSummaryItem.h"
#include "KDGanttViewTaskItem.h"
#ifndef KDGANTT_MASTER_CVS
#include "KDGanttViewSubwidgets.moc"
#endif
#include <tqlabel.h>
#include <tqheader.h>
#include <tqpainter.h>
#include <tqrect.h>
#include <tqtooltip.h>
#include <tqapplication.h>
#include <tqdrawutil.h>
#include <tqpalette.h>
#include <tqdragobject.h>
#include <tqptrlist.h>
#include <tqpen.h>
#include <tdeglobal.h>
#include <tdelocale.h>
#include <kcalendarsystem.h>
#include <kdebug.h>
KDTimeTableWidget:: KDTimeTableWidget( TQWidget* parent,KDGanttView* myGantt)
: TQCanvas (parent)
{
myGanttView = myGantt;
taskLinksVisible = true;
flag_blockUpdating = false;
int_blockUpdating = 0;
gridPen.setStyle(TQt::DotLine);
gridPen.setColor(TQColor(100,100,100));
maximumComputedGridHeight = 0;
denseLineCount = 0;
denseLineBrush = TQBrush( TQColor ( 240,240,240 ));
noInfoLineBrush = TQBrush( TQColor ( 100,100,100 ), TQt::FDiagPattern );
pendingHeight = 0;
pendingWidth = 0;
retune(256);
resize(1,1);
}
TQPtrList<KDGanttViewTaskLink> KDTimeTableWidget::taskLinks()
{
return myTaskLinkList;
}
void KDTimeTableWidget::clearTaskLinks()
{
// cannot use clear() here, as tasklinks will remove themselves from my list when deleted!
TQPtrListIterator<KDGanttViewTaskLink> it(myTaskLinkList);
while (it.current()) {
delete it.current();
}
}
void KDTimeTableWidget::resetWidth( int wid )
{
if ( wid == width() ) {
if (pendingHeight)
pendingWidth = wid;
else
pendingWidth = 0;
return;
}
if ( ! pendingHeight )
pendingHeight = height();
pendingWidth = wid;
updateMyContent();
}
void KDTimeTableWidget::checkHeight( int hei )
{
if( hei < height() )
return;
if ( pendingHeight < hei+100)
pendingHeight = hei+100;
if ( ! pendingWidth )
pendingWidth = width();
maximumComputedGridHeight = 0; //force recomputing all
updateMyContent();
}
void KDTimeTableWidget::setNoInformationBrush( const TQBrush& brush )
{
noInfoLineBrush = brush;
updateMyContent();
}
TQBrush KDTimeTableWidget::noInformationBrush() const
{
return noInfoLineBrush;
}
void KDTimeTableWidget::removeItemFromTasklinks( KDGanttViewItem* item)
{
TQPtrListIterator<KDGanttViewTaskLink> it((myTaskLinkList));
for ( ; it.current(); ++it ) {
it.current()->removeItemFromList( item );
}
}
void KDTimeTableWidget::expandItem( TQListViewItem * item)
{
item->invalidateHeight () ;
//tqApp->processEvents();
updateMyContent();
}
void KDTimeTableWidget::collapseItem( TQListViewItem * item)
{
item->invalidateHeight () ;
//tqApp->processEvents();
updateMyContent();
}
void KDTimeTableWidget::highlightItem( TQListViewItem * item )
{
static bool itemwashighlighted;
static KDGanttViewItem* highlightedItem = 0;
if (highlightedItem)
highlightedItem->setHighlight(itemwashighlighted);
highlightedItem = ( KDGanttViewItem*)item;
itemwashighlighted = highlightedItem->highlight();
highlightedItem->setHighlight(true);
item->invalidateHeight () ;
myGanttView->myListView->contentsY();
updateMyContent();
}
int KDTimeTableWidget::computeHeight()
{
// compute height of ListView
// show only items shown in ListView
int hei = 0;
KDGanttViewItem* temp;
temp = myGanttView->firstChild();
while (temp) {
hei += temp->computeHeight();
temp = temp->nextSibling();
}
// set hei to 1 to avoid canavs to be a null pixmap
if (hei == 0) {
hei = 1;
}
//tqDebug("COMPUTED HEI %d ", hei);
emit heightComputed( hei );
return hei;
}
void KDTimeTableWidget::computeVerticalGrid()
{
// recompute the vertical grid
// compute the vertical grid
// if we have too much lines, hide them
//tqDebug("computeVerticalGrid() ");
int cw = myGanttView->myTimeHeader->myGridMinorWidth;
int i = 0;
int h ;
if (pendingHeight > height() )
h = pendingHeight;
else
h = height();
int wid;
if ( pendingWidth )
wid = pendingWidth;
else
wid = width();
KDCanvasLine* templine;
KDCanvasRectangle* temprect;
TQColor colcol;
TQPen colPen;
bool colorIterator = true;
if (myGanttView->showMinorTicks()){//minor
colPen.setWidth(cw);
TQPtrListIterator<KDCanvasRectangle> itcol(columnColorList);
TQPtrListIterator<KDCanvasLine> itgrid(verGridList);
for ( ; itgrid.current(); ++itgrid ) {
if (i < wid) {
itgrid.current()->setPoints(i,0,i,h);
itgrid.current()->show();
if (myGanttView->myTimeHeader->getColumnColor(colcol,i,i+cw))
{
colPen.setColor(colcol);
if (colorIterator)
colorIterator = itcol.current();
if (colorIterator)
{/*
itcol.current()->setPen(colPen);
itcol.current()->setPoints(i+(cw/2),0,i+(cw/2),h);
*/
itcol.current()->setPen( TQt::NoPen );
itcol.current()->setBrush( TQBrush( colcol, SolidPattern) );
itcol.current()->setSize(cw ,h );
itcol.current()->move( i, 0 );
itcol.current()->show();
++itcol;
} else {
/*
templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
templine->setPen(colPen);
templine->setPoints(i+(cw/2),0,i+(cw/2),h);
*/
temprect = new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
temprect->setPen( TQt::NoPen );
temprect->setBrush( TQBrush( colcol, SolidPattern) );
temprect->setSize(cw ,h );
temprect->move( i, 0 );
temprect->setZ(-20);
temprect->show();
columnColorList.append(temprect);
}
}
i += cw;
} else {
itgrid.current()->hide();
}
}
// create additional Lines for vertical grid
for ( ;i < wid;i += cw) {
templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
templine->setPen(gridPen);
templine->setPoints(i,0,i,h);
templine->setZ(0);
templine->show();
verGridList.append(templine);
if (myGanttView->myTimeHeader->getColumnColor(colcol,i,i+cw))
{
colPen.setColor(colcol);
if (colorIterator)
colorIterator = itcol.current();
if (colorIterator)
{/*
itcol.current()->setPen(colPen);
itcol.current()->setPoints(i+(cw/2),0,i+(cw/2),h);
*/
itcol.current()->setPen( TQt::NoPen );
itcol.current()->setBrush( TQBrush( colcol, SolidPattern) );
itcol.current()->setSize(cw ,h );
itcol.current()->move( i, 0 );
itcol.current()->show();
++itcol;
} else {
temprect = new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
temprect->setPen( TQt::NoPen );
temprect->setBrush( TQBrush( colcol, SolidPattern) );
temprect->setSize(cw ,h );
temprect->move( i, 0 );
temprect->setZ(-20);
temprect->show();
columnColorList.append(temprect);
/*
templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
templine->setPen(colPen);
templine->setPoints(i+(cw/2),0,i+(cw/2),h);
templine->setZ(-20);
templine->show();
columnColorList.append(templine);
*/
}
}
}
if (colorIterator)
for ( ; itcol.current(); ++itcol )
itcol.current()->hide();
} else {//major
if (myGanttView->showMajorTicks()) {
TQValueList<int>::iterator intIt = myGanttView->myTimeHeader->majorTicks.begin();
TQValueList<int>::iterator intItEnd = myGanttView->myTimeHeader->majorTicks.end();
TQPtrListIterator<KDCanvasRectangle> itcol(columnColorList);
TQPtrListIterator<KDCanvasLine> itgrid(verGridList);
int left = 0;
for ( ; itgrid.current(); ++itgrid ) {
if (intIt != intItEnd) {
left = (*intIt);
++intIt;
itgrid.current()->setPoints(left,0,left,h);
itgrid.current()->show();
//int right = (*intIt);
if ((*intIt))
if (myGanttView->myTimeHeader->getColumnColor(colcol,left,(*intIt) ))
{
int mid = (-left+(*intIt));
colPen.setColor(colcol);
colPen.setWidth((*intIt)-left);
if (colorIterator)
colorIterator = itcol.current();
if (colorIterator)
{/*
itcol.current()->setPen(colPen);
itcol.current()->setPoints(i+mid,0,mid,h);
*/
itcol.current()->setPen( TQt::NoPen );
itcol.current()->setBrush( TQBrush( colcol, SolidPattern) );
itcol.current()->setSize(mid ,h );
itcol.current()->move( left, 0 );
itcol.current()->show();
++itcol;
} else {
temprect = new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
temprect->setPen( TQt::NoPen );
temprect->setBrush( TQBrush( colcol, SolidPattern) );
temprect->setSize(mid,h );
temprect->move( left, 0 );
temprect->setZ(-20);
temprect->show();
columnColorList.append(temprect);
/*
templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
templine->setPen(colPen);
templine->setPoints(mid,0,i+mid,h);
templine->setZ(-20);
templine->show();
columnColorList.append(templine);
*/
}
}
} else {
itgrid.current()->hide();
}
}
KDCanvasLine* templine;
// create additional Lines for vertical grid
for ( ;intIt != intItEnd ;++intIt) {
templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
templine->setPen(gridPen);
templine->setPoints((*intIt),0,(*intIt),h);
templine->setZ(0);
templine->show();
verGridList.append(templine);
if ((*intIt))
if (myGanttView->myTimeHeader->getColumnColor(colcol,left,(*intIt)))
{
int mid = (-left+(*intIt));
colPen.setColor(colcol);
colPen.setWidth((*intIt)-left);
if (colorIterator)
colorIterator = itcol.current();
if (colorIterator)
{/*
itcol.current()->setPen(colPen);
itcol.current()->setPoints(i+mid,0,mid,h);
*/
itcol.current()->setPen( TQt::NoPen );
itcol.current()->setBrush( TQBrush( colcol, SolidPattern) );
itcol.current()->setSize(mid ,h );
itcol.current()->move( left, 0 );
itcol.current()->show();
++itcol;
} else {
temprect = new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
temprect->setPen( TQt::NoPen );
temprect->setBrush( TQBrush( colcol, SolidPattern) );
temprect->setSize(mid ,h );
temprect->move( left, 0 );
temprect->setZ(-20);
temprect->show();
columnColorList.append(temprect);
/*
templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
templine->setPen(colPen);
templine->setPoints(mid,0,i+mid,h);
templine->setZ(-20);
templine->show();
columnColorList.append(templine);
*/
}
}
left = (*intIt);
}
if (colorIterator)
for ( ; itcol.current(); ++itcol ) {
itcol.current()->hide();
}
}
else {
//hideall
TQPtrListIterator<KDCanvasLine> itgrid(verGridList);
for ( ; itgrid.current(); ++itgrid ) {
itgrid.current()->hide();
}
TQPtrListIterator<KDCanvasRectangle> itcol(columnColorList);
for ( ; itcol.current(); ++itcol ) {
itcol.current()->hide();
}
}
}
}
void KDTimeTableWidget::computeHorizontalGrid()
{
// compute horizontal grid
//tqDebug("computeHorizontalGrid() ");
KDGanttViewItem* temp = myGanttView->firstChild();
int wid;
if ( pendingWidth )
wid = pendingWidth;
else
wid = width();
KDCanvasLine* templine;
TQPtrListIterator<KDCanvasLine> ithor(horGridList);
if ( ithor.current() ) {
templine = ithor.current();
++ithor;
} else {
templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
templine->setPen(gridPen);
templine->setZ(0);
horGridList.append(templine);
}
templine->setPoints(0,0,wid,0);
templine->show();
int posY;
while ( temp ) {
posY = temp->itemPos() + temp->height();
if ( ithor.current() ) {
templine = ithor.current();
++ithor;
} else {
//new vertical grid line
templine = new KDCanvasLine(this,0,Type_is_KDGanttGridItem);
templine->setPen(gridPen);
templine->setZ(0);
horGridList.append(templine);
}
if ( templine->endPoint() != TQPoint(wid,posY ))
templine->setPoints(0,posY,wid,posY );
if ( !templine->isVisible() )
templine->show();
//TQString ts = "asGroup";
//if (!temp->displaySubitemsAsGroup() )
// ts = " NOT asGroup";
//tqDebug("temp name %s %s", temp->listViewText(0).latin1(), ts.latin1());
temp = temp->itemBelow ();
}
while ( ithor.current() ) {
if ( ithor.current()->isVisible() )
ithor.current()->hide();
++ithor;
}
}
void KDTimeTableWidget::computeDenseLines()
{
KDGanttViewItem* temp = myGanttView->firstChild();
int wid;
if ( pendingWidth )
wid = pendingWidth;
else
wid = width();
TQPtrListIterator<KDCanvasRectangle> ithordense(horDenseList);
KDCanvasRectangle* denseLine;
int tempDenseLineCount = 0;
while ( temp ) {
if ( temp->isVisible() ) {
++tempDenseLineCount;
if ( tempDenseLineCount == denseLineCount ) {
tempDenseLineCount = 0;
if ( ithordense.current() ) {
denseLine = ithordense.current();
++ithordense;
} else {
denseLine =new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
denseLine->setZ(-2);
horDenseList.append( denseLine );
}
if ( denseLine->rect() != TQRect(0, temp->itemPos(),wid, temp->height()) ) {
denseLine->move( 0, temp->itemPos() );
denseLine->setSize( wid, temp->height());
}
if (denseLine->brush() != denseLineBrush ) {
denseLine->setPen( TQPen( TQt::NoPen ) );
denseLine->setBrush( denseLineBrush);
}
if (!denseLine->isVisible() )
denseLine->show();
} else {
;
}
}
temp = temp->itemBelow ();
}
while ( ithordense.current() ) {
if ( ithordense.current()->isVisible() ) {
ithordense.current()->hide();
}
++ithordense;
}
}
void KDTimeTableWidget::computeShowNoInformation()
{
KDGanttViewItem* temp = myGanttView->firstChild();
int wid;
if ( pendingWidth )
wid = pendingWidth;
else
wid = width();
TQPtrListIterator<KDCanvasRectangle> itnoinfo(showNoInfoList);
KDCanvasRectangle* noInfoLine;
while ( temp ) {
if ( temp->showNoInformation() ) {
if ( itnoinfo.current() ) {
noInfoLine = itnoinfo.current();
++itnoinfo;
} else {
noInfoLine =new KDCanvasRectangle(this,0,Type_is_KDGanttGridItem);
showNoInfoList.append( noInfoLine );
noInfoLine->setZ(-1);
}
noInfoLine->move( 0, temp->itemPos() );
noInfoLine->setSize( wid, temp->height());
noInfoLine->setPen( TQPen( TQt::NoPen ) );
noInfoLine->setBrush( noInfoLineBrush);
noInfoLine->show();
}
temp = temp->itemBelow ();
}
while ( itnoinfo.current() ) {
itnoinfo.current()->hide();
++itnoinfo;
}
}
void KDTimeTableWidget::computeTaskLinks()
{
//compute and show tasklinks
TQPtrListIterator<KDGanttViewTaskLink> it((myTaskLinkList));
for ( ; it.current(); ++it ) {
if (it.current()->isVisible())
it.current()->showMe(true);
else
it.current()->showMe(false);
}
}
// updateMyContent() can be blocked by blockUpdating( true ) or inc_blockUpdating()
// updateMyContent() is blocked, if the GanttView is hidden after startup
void KDTimeTableWidget::updateMyContent()
{
if ( flag_blockUpdating || int_blockUpdating ) {
// tqDebug("KDTimeTableWidget::updateMyContent() blocked! ");
return;
}
//tqDebug("KDTimeTableWidget::updateMyContent() ********************************* ");
/*
// debug output
KDGanttViewItem* temp = myGanttView->firstChild();
while (temp != 0) {
temp->printinfo(" " );
temp = temp->nextSibling();
}
*/
int hei = computeHeight();
minimumHeight = hei;
int viewport_hei = myGanttView->myCanvasView->viewport()->height();
if ( viewport_hei > hei )
hei = viewport_hei + 100;
if ( myGanttView->myTimeHeader->registerStartTime() )
return; // try again via timeheader computeTicks();
if ( myGanttView->myTimeHeader->registerEndTime() )
return; // try again via timeheader computeTicks();
if ( hei > height() ) {
if ( ! pendingWidth )
pendingWidth = width();
if ( pendingHeight < hei )
pendingHeight = hei;
}
if (pendingHeight > hei )
hei = pendingHeight;
if (hei > maximumComputedGridHeight)
{
maximumComputedGridHeight = hei;
// compute the background interval lines
myGanttView->myTimeHeader->computeIntervals( hei );
//compute VerticalGrid and column color
computeVerticalGrid();
}
computeTaskLinks();
computeHorizontalGrid();
computeDenseLines();
computeShowNoInformation();
//setAllChanged();
update();
if (pendingWidth && pendingHeight ) {
resize( pendingWidth, pendingHeight );
pendingWidth = 0;
pendingHeight = 0;
emit heightComputed( 0 );
}
pendingWidth = 0;
pendingHeight = 0;
//tqDebug("KDTimeTableWidget::updateMyContent() -------------------------");
}
// used for blocking recursive methods
// e.g. KDGanttViewItem::setHighlight() and displaySubitemsAsGroup() == true
void KDTimeTableWidget::inc_blockUpdating( )
{
++ int_blockUpdating;
}
// used for blocking recursive methods
void KDTimeTableWidget::dec_blockUpdating( )
{
-- int_blockUpdating;
}
// if false(i.e. unblock), sets int_blockUpdating to 0
void KDTimeTableWidget::setBlockUpdating( bool block )
{
if ( !block )
int_blockUpdating = 0;
flag_blockUpdating = block;
}
bool KDTimeTableWidget::blockUpdating()
{
return flag_blockUpdating;
}
void KDTimeTableWidget::setShowTaskLinks( bool show )
{
taskLinksVisible = show;
updateMyContent();
}
bool KDTimeTableWidget::showTaskLinks()
{
return taskLinksVisible;
}
void KDTimeTableWidget::setHorBackgroundLines( int count, TQBrush brush )
{
denseLineBrush = brush;
denseLineCount = 0;
if ( count > 1 )
denseLineCount = count;
}
int KDTimeTableWidget::horBackgroundLines( TQBrush& brush )
{
brush = denseLineBrush;
return denseLineCount;
}
int KDTimeTableWidget::getCoordX( TQDateTime dt ) {
return myGanttView->myTimeHeader->getCoordX(dt);
}
/* ***************************************************************
KDTimeHeaderWidget:: KDTimeHeaderWidget
***************************************************************** */
KDTimeHeaderWidget:: KDTimeHeaderWidget( TQWidget* parent,KDGanttView* gant )
: TQWidget (parent)
{
myToolTip = new KDTimeHeaderToolTip(this,this);
mySizeHint = 0;
myGanttView = gant;
flagDoNotRecomputeAfterChange = true;
TQDateTime start = (TQDateTime::currentDateTime ()).addSecs(-3600);
setHorizonStart(start);
setHorizonEnd( start.addSecs(3600*2));
flagStartTimeSet = false;
flagEndTimeSet = false;
myCenterDateTime = TQDateTime::currentDateTime ();
setScale(KDGanttView::Auto);
//setScale(KDGanttView::Hour);
myMaxScale = KDGanttView::Month;
myMinScale = KDGanttView::Minute;
myAutoScaleMinorTickcount = 100;
setMajorScaleCount( 1 );
setMinorScaleCount( 1);
setMinimumColumnWidth( 5 );
setYearFormat(KDGanttView::FourDigit );
setHourFormat( KDGanttView::Hour_12 );
myZoomFactor = 1.0;
setWeekendBackgroundColor(TQColor(220,220,220) );
setWeekendDays( 6, 7 );
myGridMinorWidth = 0;
myPopupMenu = new TQPopupMenu(this);
TQPopupMenu * zoomPopupMenu = new TQPopupMenu(this);
myPopupMenu->insertItem (i18n("Zoom"),zoomPopupMenu, 1);
zoomPopupMenu->insertItem( i18n("Zoom to 100%"),this, TQ_SLOT(setSettings(int)),0 ,21,21 );
zoomPopupMenu->insertItem( i18n("Zoom to Fit"),this, TQ_SLOT(setSettings(int)),0 ,20,20 );
zoomPopupMenu->insertItem( i18n("Zoom In (x 2)"),this, TQ_SLOT(setSettings(int)),0 ,22,22 );
zoomPopupMenu->insertItem( i18n("Zoom In (x 6)"),this, TQ_SLOT(setSettings(int)),0 ,24,24 );
zoomPopupMenu->insertItem( i18n("Zoom In (x 12)"),this, TQ_SLOT(setSettings(int)),0 ,26,26 );
zoomPopupMenu->insertItem( i18n("Zoom Out (x 1/2)"),this, TQ_SLOT(setSettings(int)),0 ,23,23 );
zoomPopupMenu->insertItem( i18n("Zoom Out (x 1/6)"),this, TQ_SLOT(setSettings(int)),0 ,25,25 );
zoomPopupMenu->insertItem( i18n("Zoom Out (x 1/12)"),this, TQ_SLOT(setSettings(int)),0 ,27,27 );
scalePopupMenu = new TQPopupMenu(this);
myPopupMenu->insertItem (i18n("Scale"),scalePopupMenu, 2);
scalePopupMenu->insertItem( i18n("Minute"),this, TQ_SLOT(setSettings(int)),0 ,1,1 );
scalePopupMenu->insertItem( i18n("Hour"),this, TQ_SLOT(setSettings(int)),0 ,2,2 );
scalePopupMenu->insertItem( i18n("Day"),this, TQ_SLOT(setSettings(int)),0 ,3,3 );
scalePopupMenu->insertItem( i18n("Week"),this, TQ_SLOT(setSettings(int)),0 ,4,4 );
scalePopupMenu->insertItem( i18n("Month"),this, TQ_SLOT(setSettings(int)),0 ,5,5 );
scalePopupMenu->insertItem( i18n("Auto"),this, TQ_SLOT(setSettings(int)),0 ,6,6 );
scalePopupMenu->setCheckable ( true );
timePopupMenu = new TQPopupMenu(this);
myPopupMenu->insertItem (i18n("Time Format"),timePopupMenu, 3);
timePopupMenu->insertItem( i18n("24 Hour"),this, TQ_SLOT(setSettings(int)),0 ,40,40 );
timePopupMenu->insertItem( i18n("12 PM Hour"),this, TQ_SLOT(setSettings(int)),0 ,41,41 );
timePopupMenu->insertItem( i18n("24:00 Hour"),this, TQ_SLOT(setSettings(int)),0 ,42,42 );
yearPopupMenu = new TQPopupMenu(this);
myPopupMenu->insertItem (i18n("Year Format"),yearPopupMenu, 4);
yearPopupMenu->insertItem( i18n("Four Digit"),this, TQ_SLOT(setSettings(int)),0 ,50,50 );
yearPopupMenu->insertItem( i18n("Two Digit"),this, TQ_SLOT(setSettings(int)),0 ,51,51 );
yearPopupMenu->insertItem( i18n("Two Digit Apostrophe"),this, TQ_SLOT(setSettings(int)),0 ,52,52 );
yearPopupMenu->insertItem( i18n("No Date on Minute/Hour Scale"),this, TQ_SLOT(setSettings(int)),0 ,53,53 );
gridPopupMenu = new TQPopupMenu(this);
myPopupMenu->insertItem (i18n("Grid"),gridPopupMenu,5);
gridPopupMenu->insertItem( i18n("Show Minor Grid"),this, TQ_SLOT(setSettings(int)),0 ,10,10 );
gridPopupMenu->insertItem( i18n("Show Major Grid"),this, TQ_SLOT(setSettings(int)),0 ,11,11 );
gridPopupMenu->insertItem( i18n("Show No Grid"),this, TQ_SLOT(setSettings(int)),0 ,12,12 );
myPopupMenu->insertItem( i18n("Print"),this, TQ_SLOT(setSettings(int)),0 ,30,30 );
connect(myPopupMenu, TQ_SIGNAL ( aboutToShow () ) , this, TQ_SLOT( preparePopupMenu() )) ;
flagZoomToFit = false;
setShowMinorTicks( true );
myRealEnd = myHorizonEnd;
myRealStart = myHorizonStart;
autoComputeTimeLine = true;
flagDoNotRecomputeAfterChange = false;
flagDoNotRepaintAfterChange = false;
setShowPopupMenu(false,false,false,false,false,false,false);
for (int j =1;j<8;++j)
weekdayColor[j] = TQt::white;
myMinimumWidth = 0;
mouseDown = false;
beginMouseDown = 0;
endMouseDown = 0;
}
KDTimeHeaderWidget::~KDTimeHeaderWidget()
{
delete myToolTip;
}
void KDTimeHeaderWidget::preparePopupMenu()
{
myPopupMenu->setItemVisible ( 1, flagShowZoom );
myPopupMenu->setItemVisible ( 2, flagShowScale );
myPopupMenu->setItemVisible ( 3, flagShowTime );
myPopupMenu->setItemVisible ( 4, flagShowYear );
myPopupMenu->setItemVisible ( 5, flagShowGrid);
myPopupMenu->setItemVisible ( 30, flagShowPrint );
if (flagZoomToFit)
myPopupMenu->changeItem( 1, i18n("Zoom (Fit)"));
else
myPopupMenu->changeItem( 1, i18n("Zoom (%1)").arg( TQString::number( zoomFactor(), 'f',3) ) );
int i = 0;
int id;
while ( ( id = scalePopupMenu->idAt( i++ )) >= 0 ) {
scalePopupMenu->setItemChecked ( id, false );
}
scalePopupMenu->setItemChecked ( scalePopupMenu->idAt ( (int)( scale()) ), true );
i = 0;
while ( ( id = timePopupMenu->idAt( i++ )) >= 0 ) {
timePopupMenu->setItemChecked ( id, false );
}
timePopupMenu->setItemChecked ( timePopupMenu->idAt ( (int)( hourFormat()) ), true );
i = 0;
while ( ( id = yearPopupMenu->idAt( i++ )) >= 0 ) {
yearPopupMenu->setItemChecked ( id, false );
}
yearPopupMenu->setItemChecked ( yearPopupMenu->idAt ( (int)( yearFormat()) ), true );
i = 0;
while ( ( id = gridPopupMenu->idAt( i++ )) >= 0 ) {
gridPopupMenu->setItemChecked ( id, false );
}
gridPopupMenu->setItemChecked ( gridPopupMenu->idAt ( 0 ), showMinorTicks() );
gridPopupMenu->setItemChecked ( gridPopupMenu->idAt ( 1 ), showMajorTicks() );
gridPopupMenu->setItemChecked ( gridPopupMenu->idAt ( 2 ),
!(showMajorTicks() || showMinorTicks()) );
}
TQString KDTimeHeaderWidget::getToolTipText(TQPoint p)
{
return TDEGlobal::locale()->formatDateTime(getDateTimeForIndex(p.x()));
}
void KDTimeHeaderWidget::addTickRight( int num )
{
int secs = ((num*getTickTime())-30);
setHorizonEnd(getDateTimeForIndex(width()).addSecs(secs));
//tqApp->processEvents();
}
void KDTimeHeaderWidget::addTickLeft( int num )
{
int secs = ((num*getTickTime())-30);
setHorizonStart(getDateTimeForIndex(0).addSecs(-secs));
//tqApp->processEvents();
}
// the time in secs of one minor grid tick
int KDTimeHeaderWidget::getTickTime()
{
return getDateTimeForIndex(0).secsTo(getDateTimeForIndex(myGridMinorWidth));
}
void KDTimeHeaderWidget::checkWidth( int wid )
{
// we have to set the minimum width one pixel higher than the
// viewport width of the canvas view in order to
// avoid that the horiz. scrollbar of the canvasview is hidden
myMinimumWidth = wid + 1;
if ( myMinimumWidth > width() ||
( myMinimumWidth > mySizeHint &&
myMinimumWidth < (width() - myGridMinorWidth )) )
computeTicks();
// Update (horizontal) scrollbar,
// We probably come from an external resize and then we must
// calculate on basis of myCanvasView.
// (NOTE: we have disconnected the auto TQScrollView scrollbar update)
if (myGanttView && myGanttView->myCanvasView)
myGanttView->myCanvasView->updateScrollBars();
}
bool KDTimeHeaderWidget::registerStartTime()
{
TQListViewItemIterator it( myGanttView->myListView );
if (!flagStartTimeSet) {
TQDateTime temp , time;
KDGanttViewItem* item;
bool setNewTime = false;
item = (KDGanttViewItem*)myGanttView->myListView->firstChild();
if ( item ) {
temp = item->startTime();
time = temp;
// while ( item != 0)
for ( ; it.current(); ++it ) {
item = ( KDGanttViewItem* )it.current();
if (item->isVisibleInGanttView) {
if ( !setNewTime )
temp = item->startTime();
switch( item->type() ) {
case KDGanttViewItem::Event:
time = ((KDGanttViewEventItem*)item)->leadTime();
setNewTime = true;
break;
case KDGanttViewItem::Summary:
case KDGanttViewItem::Task:
time = item->startTime();
setNewTime = true;
break;
default:
time = temp;
}
if ( time < temp) {
temp = time ;
}
}
}
if ( setNewTime )
if ( myHorizonStart != temp) {
myHorizonStart = temp;
computeTicks();
return true;
}
}
}
return false;
}
bool KDTimeHeaderWidget::registerEndTime()
{
if (!flagEndTimeSet) {
TQDateTime temp , time;
KDGanttViewItem* item;
bool setNewTime = false;
item = (KDGanttViewItem*)myGanttView->myListView->firstChild();
if ( item ) {
temp = item->startTime();
time = temp;
TQListViewItemIterator it( myGanttView->myListView );
for ( ; it.current(); ++it ) {
item = ( KDGanttViewItem* )it.current();
if (item->isVisibleInGanttView) {
if ( !setNewTime )
temp = item->startTime();
switch( item->type() ) {
case KDGanttViewItem::Event:
time = ((KDGanttViewEventItem*)item)->startTime();
setNewTime = true;
break;
case KDGanttViewItem::Summary:
time = item->endTime();
if ( time < ((KDGanttViewSummaryItem*)item)->actualEndTime())
time = ((KDGanttViewSummaryItem*)item)->actualEndTime();
setNewTime = true;
break;
case KDGanttViewItem::Task:
time = item->endTime();
setNewTime = true;
break;
default:
time = temp;
}
if ( time > temp)
temp = time ;
}
}
if ( setNewTime )
if (myHorizonEnd != temp ) {
myHorizonEnd = temp;
computeTicks();
return true;
}
}
}
return false;
}
void KDTimeHeaderWidget::setShowPopupMenu( bool show,
bool showZoom,
bool showScale,
bool showTime,
bool showYear,
bool showGrid,
bool showPrint)
{
flagShowPopupMenu = show;
flagShowZoom = showZoom;
flagShowScale = showScale;
flagShowTime = showTime;
flagShowYear = showYear;
flagShowGrid = showGrid;
flagShowPrint = showPrint;
}
bool KDTimeHeaderWidget::showPopupMenu() const
{
return flagShowPopupMenu;
}
void KDTimeHeaderWidget::setSettings(int i)
{
switch (i) {
case 1:
setScale(KDGanttView::Minute );
break;
case 2:
setScale(KDGanttView::Hour );
break;
case 3:
setScale(KDGanttView::Day );
break;
case 4:
setScale(KDGanttView::Week );
break;
case 5:
setScale(KDGanttView::Month );
break;
case 6:
setScale(KDGanttView::Auto );
break;
case 10:
setShowMinorTicks( true );
break;
case 11:
setShowMajorTicks( true );{
}
break;
case 12:
setShowMajorTicks( false );
setShowMinorTicks( false);
break;
case 20:
zoomToFit();
break;
case 21:
zoom(1.0);
break;
case 22:
zoom(2.0,false);
break;
case 23:
zoom(0.5,false);
break;
case 24:
zoom(6.0,false);
break;
case 25:
zoom(0.16666,false);
break;
case 26:
zoom(12.0,false);
break;
case 27:
zoom(0.08333,false);
break;
case 30:
myGanttView->print();
break;
case 40:
case 41:
case 42:
setHourFormat( (KDGanttView::HourFormat) (i - 40) );
break;
case 50:
case 51:
case 52:
case 53:
setYearFormat( (KDGanttView::YearFormat) ( i - 50) );
break;
case 60:
break;
case 61:
break;
case 62:
break;
case 63:
break;
case 64:
break;
}
// myGanttView->myTimeTable->updateMyContent();
}
void KDTimeHeaderWidget::zoomToFit()
{
flagZoomToFit = true;
computeTicks();
// Since we have disconnected autoupdate of scrollbars, we must do it ourselves
if (myGanttView && myGanttView->myCanvasView)
myGanttView->myCanvasView->updateScrollBars();
}
double KDTimeHeaderWidget::zoomFactor()
{
return myZoomFactor;
}
double KDTimeHeaderWidget::secsFromTo( TQDateTime begin, TQDateTime end )
{
TQDateTime temp;
double secs, days;
days = begin.daysTo(end);
temp = begin.addDays((int) days);
secs = temp.secsTo(end);
secs += days * 86400.0;
return secs;
}
void KDTimeHeaderWidget::zoomToSelection( TQDateTime start, TQDateTime end)
{
if (start < myHorizonStart) {
myHorizonStart = start;
flagStartTimeSet = true;
//tqDebug("myHorizonStart reset");
}
if (end > myHorizonEnd) {
myHorizonEnd = end;
flagEndTimeSet = true;
//tqDebug("myHorizonEnd reset ");
}
flagDoNotRepaintAfterChange = true;//avoid flicker
zoom(1.0); // set to 100%
int viewWid = myGanttView->myCanvasView->viewport()->width();
int timeWid = getCoordX(end)-getCoordX(start);
double fac;
fac = ( (double)viewWid)/((double) timeWid );
zoom (fac);
timeWid = getCoordX(end)-getCoordX(start);
int count = 0;
int lastScaleCount = 0;
while (timeWid >viewWid || ( ( myRealMinorScaleCount != lastScaleCount) && timeWid*2 < viewWid ) ) {
lastScaleCount = myRealMinorScaleCount;
fac = (fac * (double)viewWid)/(double)timeWid;
zoom (fac);
timeWid = getCoordX(end)-getCoordX(start);
if ( count++ > 10 ) {
//tqDebug("Exiting while loop in zoomToSelection ");
break;
}
}
flagDoNotRepaintAfterChange = false;
updateTimeTable();
repaint();
moveTimeLineTo((getCoordX(start)-(viewWid-timeWid)/2));
// Since we have disconnected autoupdate of scrollbars, we must do it ourselves
if (myGanttView && myGanttView->myCanvasView)
myGanttView->myCanvasView->updateScrollBars();
}
void KDTimeHeaderWidget::moveTimeLineTo(int X)
{
int Y = myGanttView->myCanvasView->contentsY ();
myGanttView->myCanvasView->setContentsPos (X, Y );
}
void KDTimeHeaderWidget::zoom(double factor, bool absolute)
{
flagZoomToFit = false;
if ( factor < 0.000001 ) {
tqDebug("KDGanttView::zoom() : Zoom factor to low. Nothing zoomed. ");
return;
}
double newZoom;
if (absolute)
newZoom = factor;
else
newZoom = myZoomFactor * factor;
double relativeZoom;
relativeZoom = newZoom / myZoomFactor;
//tqDebug("zooming relative %f ", relativeZoom);
//tqDebug("zooming absolute %f ", newZoom);
int viewWid = myGanttView->myCanvasView->viewport()->width();
if ( width() * relativeZoom < viewWid && ( newZoom > 1.01 || newZoom < 0.99 ) ) {
tqDebug("KDGanttView::zoom() : Zoom factor to low for current horizon. ");
// tqDebug("zooming relative %f, zooming absolute %f, viewWidth %d width %d ", relativeZoom, newZoom, viewWid, width() );
return;
}
myZoomFactor = newZoom;
computeTicks();
// Since we have disconnected autoupdate of scrollbars, we must do it ourselves
if (myGanttView && myGanttView->myCanvasView)
myGanttView->myCanvasView->updateScrollBars();
}
/*!
Sets the start of the horizon of the Gantt chart. If \a start is
null, the horizon start is computed automatically.
\param start the start of the horizon
\sa horizonStart()
*/
void KDTimeHeaderWidget::setHorizonStart( const TQDateTime& start )
{
myHorizonStart = start;
flagStartTimeSet = true;
computeTicks();
}
/*!
Returns the start of the horizon of the Gantt chart.
\return the start of the horizon of the Gantt chart
\sa setHorizonStart()
*/
TQDateTime KDTimeHeaderWidget::horizonStart() const
{
return myHorizonStart;
}
/*!
Sets the end of the horizon of the Gantt chart. If \a end is
null, the horizon end is computed automatically.
\param end the end of the horizon
\sa setHorizonEnd()
*/
void KDTimeHeaderWidget::setHorizonEnd( const TQDateTime& start )
{
myHorizonEnd = start;
flagEndTimeSet = true;
computeTicks();
}
/*!
Returns the end of the horizon of the Gantt chart.
\return the end of the horizon of the Gantt chart
\sa setHorizonEnd()
*/
TQDateTime KDTimeHeaderWidget::horizonEnd() const
{
return myHorizonEnd;
}
/*!
Configures the unit of the lower scale of the header. The higher
unit is computed automatically.
Resets the zoomng factor to 1 (i.e. 100%).
\param unit the unit of the lower scale of the header.
\sa scale()
*/
void KDTimeHeaderWidget::setScale(Scale unit )
{
myScale = unit;
myZoomFactor = 1.0;
computeTicks();
// Since we have disconnected autoupdate of scrollbars, we must do it ourselves
if (myGanttView && myGanttView->myCanvasView)
myGanttView->myCanvasView->updateScrollBars();
}
/*!
Returns the unit of the lower scale of the header.
\return the unit of the lower scale of the header.
\sa setScale()
*/
KDTimeHeaderWidget::Scale KDTimeHeaderWidget::scale() const
{
return myScale;
}
/*!
Sets the maximal allowed time scale of the lower scale of the header.
\param unit the unit of the lower scale of the header.
\sa scale()
*/
void KDTimeHeaderWidget::setMaximumScale( Scale unit )
{
myMaxScale = unit;
computeTicks();
}
/*!
Returns the maximal allowed time scale of the lower scale of the header.
\return the unit of the lower scale of the header.
\sa setScale()
*/
KDTimeHeaderWidget::Scale KDTimeHeaderWidget::maximumScale() const
{
return myMaxScale;
}
/*!
Sets the minimal allowed time scale of the lower scale of the header.
\param unit the unit of the lower scale of the header.
\sa scale()
*/
void KDTimeHeaderWidget::setMinimumScale( Scale unit )
{
myMinScale = unit;
computeTicks();
}
/*!
Returns the minimal allowed time scale of the lower scale of the header.
\return the unit of the lower scale of the header.
\sa setScale()
*/
KDTimeHeaderWidget::Scale KDTimeHeaderWidget::minimumScale() const
{
return myMinScale;
}
/*!
Sets the minimum width a column needs to have. If the size of the
Gantt chart and the scale would make it necessary to go below this
limit otherwise, the chart will automatically be made less exact.
\param width the minimum column width
\sa minimumColumnWidth()
*/
void KDTimeHeaderWidget::setMinimumColumnWidth( int width )
{
myMinimumColumWidth = width;
computeTicks();
}
/*!
Returns the minimum width a column needs to have.
\return the column minimum width
\sa setMinimumColumnWidth()
*/
int KDTimeHeaderWidget::minimumColumnWidth() const
{
return myMinimumColumWidth;
}
/*!
Specifies the format in which to display years. If no years are
shown, this method has no effect.
\param format the year format
\sa yearFormat(), setHourFormat(), hourFormat()
*/
void KDTimeHeaderWidget::setYearFormat( YearFormat format )
{
myYearFormat = format;
computeTicks();
}
/*!
Returns the format in which to display years.
\return the year format
\sa setYearFormat(), setHourFormat(), hourFormat()
*/
KDTimeHeaderWidget::YearFormat KDTimeHeaderWidget::yearFormat() const
{
return myYearFormat;
}
/*!
Specifies the format in which to display hours. If no hours are
shown, this method has no effect.
\param format the hour format
\sa hourFormat(), setYearFormat(), yearFormat()
*/
void KDTimeHeaderWidget::setHourFormat( HourFormat format )
{
myHourFormat = format;
computeTicks();
}
/*!
Returns the format in which to display hours.
\return the hour format
\sa setHourFormat(), setYearFormat(), yearFormat()
*/
KDTimeHeaderWidget::HourFormat KDTimeHeaderWidget::hourFormat() const
{
return myHourFormat;
}
/*!
Specifies whether ticks should be shown on the major scale.
\param show true in order to show ticks, false in order to hide them
\sa showMajorTicks(), setShowMinorTicks(), showMinorTicks()
*/
void KDTimeHeaderWidget::setShowMajorTicks( bool show )
{
flagShowMajorTicks = show;
if (show) {
setShowMinorTicks(false);
}
updateTimeTable();
}
/*!
Returns whether ticks are shown on the major scale.
\return true if ticks are shown on the major scale
\sa setShowMajorTicks(), setShowMinorTicks(), showMinorTicks()
*/
bool KDTimeHeaderWidget::showMajorTicks() const
{
return flagShowMajorTicks;
}
/*!
Specifies whether ticks should be shown on the minor scale.
\param show true in order to show ticks, false in order to hide them
\sa showMinorTicks(), setShowMajorTicks(), showMajorTicks()
*/
void KDTimeHeaderWidget::setShowMinorTicks( bool show )
{
flagShowMinorTicks = show;
if (show)
setShowMajorTicks(false );
//repaintMe();
updateTimeTable();
}
/*!
Returns whether ticks are shown on the minor scale.
\return true if ticks are shown on the minor scale
\sa setShowMinorTicks(), setShowMajorTicks(), showMajorTicks()
*/
bool KDTimeHeaderWidget::showMinorTicks() const
{
return flagShowMinorTicks;
}
/*!
Sets the background color for the column closest to \a column.
\param column the column to set the background color for
\param color the background color
\sa columnBackgroundColor(), setWeekendBackgroundColor(),
weekendBackgroundColor()
*/
void KDTimeHeaderWidget::setColumnBackgroundColor( const TQDateTime& column,
const TQColor& color,
Scale mini, Scale maxi )
{
ColumnColorList::iterator it;
for ( it = ccList.begin(); it != ccList.end(); ++it ) {
if ((*it).datetime == column) {
(*it).color = color;
(*it).minScaleView = mini;
(*it).maxScaleView = maxi;
return;
}
}
DateTimeColor newItem;
newItem.datetime = column;
newItem.color = color;
newItem.minScaleView = mini;
newItem.maxScaleView = maxi;
ccList.append(newItem);
updateTimeTable();
}
void KDTimeHeaderWidget::computeIntervals( int height )
{
IntervalColorList::iterator it;
int left, right;
for ( it = icList.begin(); it != icList.end(); ++it ) {
if ( (*it).minScaleView <= myRealScale && (*it).maxScaleView >= myRealScale ) {
left = getCoordX((*it).datetime);
right = getCoordX((*it).end);
if ( right == left )
++right;
(*it).canvasRect->setPen( TQt::NoPen );
(*it).canvasRect->setBrush( TQBrush( (*it).color, SolidPattern) );
(*it).canvasRect->setSize( right - left ,height );
(*it).canvasRect->move( left,0 );
(*it).canvasRect->show();
} else {
(*it).canvasRect->hide();
/*
(*it).canvasLine->setPen( TQPen( (*it).color, right - left ) );
(*it).canvasLine->setPoints( mid ,0 ,mid ,height );
(*it).canvasLine->show();
} else {
(*it).canvasLine->hide();
*/
}
}
}
bool KDTimeHeaderWidget::changeBackgroundInterval( const TQDateTime& oldstart,
const TQDateTime& oldend,
const TQDateTime& newstart,
const TQDateTime& newend )
{
IntervalColorList::iterator it;
for ( it = icList.begin(); it != icList.end(); ++it ) {
if ((*it).datetime == oldstart && (*it).end == oldend ) {
IntervalColorList::iterator it2;
for ( it2 = icList.begin(); it2 != icList.end(); ++it2 ) {
if ((*it2).datetime == newstart && (*it2).end == newend )
return false;
}
(*it).datetime = newstart;
(*it).end = newend;
updateTimeTable();
return true;
}
}
return false;
}
bool KDTimeHeaderWidget::deleteBackgroundInterval( const TQDateTime& start,
const TQDateTime& end)
{
IntervalColorList::iterator it;
for ( it = icList.begin(); it != icList.end(); ++it ) {
if ((*it).datetime == start && (*it).end == end ) {
//delete (*it).canvasLine;
delete (*it).canvasRect;
icList.remove(it);
updateTimeTable();
return true;
}
}
return false;
}
void KDTimeHeaderWidget::setIntervalBackgroundColor( const TQDateTime& start,
const TQDateTime& end,
const TQColor& color,
Scale mini ,
Scale maxi )
{
IntervalColorList::iterator it;
for ( it = icList.begin(); it != icList.end(); ++it ) {
if ((*it).datetime == start && (*it).end == end ) {
(*it).color = color;
(*it).minScaleView = mini;
(*it).maxScaleView = maxi;
return;
}
}
DateTimeColor newItem;
if ( start <= end ) {
newItem.datetime = start;
newItem.end = end;
} else {
newItem.datetime = end;
newItem.end = start;
}
newItem.color = color;
newItem.minScaleView = mini;
newItem.maxScaleView = maxi;
//newItem.canvasLine = new KDCanvasLine(myGanttView->myTimeTable,0,Type_is_KDGanttGridItem);
newItem.canvasRect = new KDCanvasRectangle(myGanttView->myTimeTable,0,Type_is_KDGanttGridItem);
newItem.canvasRect->setZ(-19);
icList.append(newItem);
updateTimeTable();
}
void KDTimeHeaderWidget::clearBackgroundColor()
{
IntervalColorList::iterator itic;
for ( itic = icList.begin(); itic != icList.end(); ++itic ) {
delete (*itic).canvasRect;
}
ccList.clear();
icList.clear();
updateTimeTable();
}
TQDateTime KDTimeHeaderWidget::getDateTimeForIndex(int X, bool local )
{
int coordX = X;
if ( !local ) {
TQPoint p = TQPoint ( X, 1 );
coordX = myGanttView->myTimeHeaderScroll->viewportToContents(myGanttView->myTimeHeaderScroll->mapFromGlobal( p )).x();
}
double secs = (secsFromTo( myRealStart, myRealEnd ) * ((double)coordX))/(double)width();
double days = secs/86400.0;
secs = secs - ( ((int) days) *86400.0 );
return (myRealStart.addDays ( (int) days )).addSecs( (int) secs);
}
//FIXME: This doesn't work quite intuitively (imho) when scale is day
// and each column containes more than 1 day:
// 1) If a column includes a weekend day, the whole column gets weekend color,
// 2) If a column includes 7 days, either *all* columns get weekend color, or
// *none* get weekend color (haven't figured out why)
// Proposal: Only use weekend color if the whole column is a weekend.
// Alt: Color the area that actually is the weekend.
bool KDTimeHeaderWidget::getColumnColor(TQColor& col,int coordLow, int coordHigh)
{
if (!flagShowMajorTicks && !flagShowMinorTicks)
return false;
TQDateTime start,end;
start = getDateTimeForIndex(coordLow);
end = getDateTimeForIndex(coordHigh).addSecs(-1);
Scale tempScale = myRealScale;
if (flagShowMajorTicks)
switch (myRealScale)
{
case KDGanttView::Minute: tempScale = KDGanttView::Hour; break;
case KDGanttView::Hour: tempScale = KDGanttView::Day ; break;
case KDGanttView::Day: tempScale = KDGanttView::Week ; break;
case KDGanttView::Week: tempScale = KDGanttView::Month ; break;
case KDGanttView::Month: return false ; break;
case KDGanttView::Auto: return false ; break;
}
//check defined column color
ColumnColorList::iterator it;
for ( it = ccList.begin(); it != ccList.end(); ++it ) {
if ((*it).datetime >= start && (*it).datetime <= end) {
if (tempScale >= (*it).minScaleView && tempScale <= (*it).maxScaleView ) {
col = (*it).color;
return true;
}
}
}
if (tempScale > KDGanttView::Day) return false;
start = getDateTimeForIndex((coordLow+coordHigh)/2);
int day = start.date().dayOfWeek ();
//checkweekdaycolor
if (weekdayColor[day] != TQt::white) {
col = weekdayColor[day];
return true;
}
//checkweekendcolor
int endday = myWeekendDaysEnd;
col = myWeekendBackgroundColor;
if (myWeekendDaysStart > myWeekendDaysEnd)
endday +=7;
if (day >= myWeekendDaysStart && day <= endday) {
return true;
} else {
if (day+7 >= myWeekendDaysStart && day+7 <= endday) {
return true;
}
}
return false;
}
/*!
Returns the background color for the column closes to \a column.
\param column the column to query the background color for
\return the background color of the specified column
\sa setColumnBackgroundColor(), setWeekendBackgroundColor(),
weekendBackgroundColor()
*/
TQColor KDTimeHeaderWidget::columnBackgroundColor( const TQDateTime& column ) const
{
TQColor c;
c = white;
ColumnColorList::const_iterator ite;
for ( ite = ccList.begin(); ite != ccList.end(); ++ite ) {
if ((*ite).datetime == column) {
c = (*ite).color;
}
}
return c;
}
/*!
Specifies the background color for weekend days. If no individual
days are visible on the Gantt chart, this method has no visible
effect.
\param color the background color to use for weekend days.
\sa weekendBackgroundColor(), setWeekendDays(), weekendDays()
*/
void KDTimeHeaderWidget::setWeekendBackgroundColor( const TQColor& color )
{
myWeekendBackgroundColor = color ;
updateTimeTable();
}
/*!
Returns the background color for weekend days.
\return the background color for weekend days
\sa setWeekendBackgroundColor(), setWeekendDays(), weekendDays()
*/
TQColor KDTimeHeaderWidget::weekendBackgroundColor() const
{
return myWeekendBackgroundColor;
}
/*!
Specifies the background color for week days. If no individual
days are visible on the Gantt chart, this method has no visible
effect. The days are specified as an interval of integer values
where 1 means Monday and 7 means Sunday.
\param color the background color to use for weekend days.
\param weekday the day of the week (Monday = 1, Sunday = 7)
\sa weekendBackgroundColor(), setWeekendDays(), weekendDays()
*/
void KDTimeHeaderWidget::setWeekdayBackgroundColor( const TQColor& color, int weekday )
{
weekdayColor[weekday] = color;
updateTimeTable();
}
/*!
Returns the background color for weekday days.
\param the day of the week (Monday = 1, Sunday = 7)
\return the background color for weekend days
\sa setWeekendBackgroundColor(), setWeekendDays(), weekendDays()
*/
TQColor KDTimeHeaderWidget::weekdayBackgroundColor(int weekday) const
{
return weekdayColor[weekday];
}
/*!
Defines which days are considered weekends. The days are specified
as an interval of integer values where 1 means Monday and 7 means
Sunday. In order to define a weekend from Sunday to Monday, specify
(7,1).
\param start the first day of the weekend
\param end the last day of the weekend
\sa weekendDays(), setWeekendBackgroundColor(), weekendBackgroundColor()
*/
void KDTimeHeaderWidget::setWeekendDays( int start, int end )
{
myWeekendDaysStart = start;
myWeekendDaysEnd = end;
updateTimeTable();
}
/*!
Returns which days are considered weekends.
\param start in this parameter, the first day of the weekend is returned
\param end in this parameter, the end day of the weekend is returned
\sa setWeekendDays(), setWeekendBackgroundColor(), weekendBackgroundColor()
*/
void KDTimeHeaderWidget::weekendDays( int& start, int& end ) const
{
start = myWeekendDaysStart;
end = myWeekendDaysEnd ;
}
/*!
Sets the number of ticks in the major scale.
\param count the number of ticks in the major scale
\sa majorScaleCount(), setMinorScaleCount(), minorScaleCount()
*/
void KDTimeHeaderWidget::setMajorScaleCount( int count )
{
myMajorScaleCount=count;
computeTicks();
}
/*!
Returns the number of ticks per unit in the major scale.
\return the number of ticks in the major scale
\sa setMajorScaleCount(), setMinorScaleCount(), minorScaleCount()
*/
int KDTimeHeaderWidget::majorScaleCount() const
{
return myMajorScaleCount;
}
/*!
Sets the number of ticks in the minor scale.
\param count the number of ticks in the minor scale
\sa minorScaleCount, setMajorScaleCount, majorScaleCount()
*/
void KDTimeHeaderWidget::setMinorScaleCount( int count )
{
myMinorScaleCount = count;
computeTicks();
}
/*!
Returns the number of ticks per unit in the minor scale.
\return the number of ticks in the minor scale
\sa setMinorScaleCount(), setMajorScaleCount(), majorScaleCount()
*/
int KDTimeHeaderWidget::minorScaleCount() const
{
return myMinorScaleCount ;
}
void KDTimeHeaderWidget::resizeEvent ( TQResizeEvent * )
{
// tqDebug("KDTimeHeaderWidget:: resizeEvent ");
paintPix.resize( 800, height () );
}
void KDTimeHeaderWidget::updateTimeTable()
{
//tqDebug("KDTimeHeaderWidget::updateTimeTable() ");
if (flagDoNotRecomputeAfterChange) return;
// setting the scrolling steps
int scrollLineStep = myGridMinorWidth;
if (showMajorTicks()) {
TQValueList<int>::iterator intIt = majorTicks.begin();
scrollLineStep = 5 * myGridMinorWidth;
if (intIt != majorTicks.end()) {
int left = *intIt;
++intIt;
if (intIt != majorTicks.end()) {
scrollLineStep = *intIt-left;
}
}
}
myGanttView->myCanvasView->horizontalScrollBar()->setLineStep(scrollLineStep);
myGanttView->myTimeTable->maximumComputedGridHeight = 0;
myGanttView->myTimeTable->updateMyContent();
}
void KDTimeHeaderWidget::setAutoScaleMinorTickCount( int count )
{
myAutoScaleMinorTickcount = count;
computeTicks();
}
int KDTimeHeaderWidget::autoScaleMinorTickCount()
{
return myAutoScaleMinorTickcount;
}
void KDTimeHeaderWidget::repaintMe(int left,int paintwid, TQPainter* painter)
{
if (flagDoNotRecomputeAfterChange) return;
TQColorGroup qcg =TQColorGroup( white, black,white, darkGray,black,gray,gray) ;
TQPainter* p;
int offsetLeft = 0;
if ( paintwid > paintPix.width()-100 )
paintPix.resize( paintwid+100, height () );
if ( painter )
p = painter;
else {
p = new TQPainter( &paintPix );
offsetLeft = left-50;
}
if ( mouseDown ) {
p->fillRect( left-offsetLeft, 0, paintwid, height(), TQBrush(paletteBackgroundColor()) );
int start ;
int wid;
if ( beginMouseDown < endMouseDown ) {
start = beginMouseDown ;
wid = endMouseDown - beginMouseDown ;
} else {
start = endMouseDown ;
wid = -endMouseDown + beginMouseDown ;
}
p->fillRect( start-offsetLeft, 0, wid, height(), TQBrush(paletteBackgroundColor().dark()) );
} else {
if (! painter )
p->fillRect( left-offsetLeft, 0, paintwid, height(), TQBrush(paletteBackgroundColor()) );
}
p->setPen(TQColor(40,40,40));
TQFont tempFont = p->font();
tempFont.setWeight(63);
p->setFont(tempFont);
int hei1 = myMajorGridHeight,
hei2 = height(),
wid1 = myGridMinorWidth;
int xCoord;
int lwid = 1;
TQValueList<TQString>::iterator it;
TQValueList<int>::iterator intIt = majorTicks.begin();
for ( it = majorText.begin(); it != majorText.end(); ++it ) {
xCoord = (*intIt++);
if (((*intIt)>= left && xCoord <= left+paintwid)) {
qDrawShadeLine ( p,xCoord-offsetLeft ,hei1+1, xCoord-offsetLeft, -2, qcg, true, lwid, 1 );
p->drawText(xCoord+4-offsetLeft,hei1-4,(*it));
}
}
qDrawShadeLine ( p,left-offsetLeft ,hei1, left+paintwid-offsetLeft, hei1, qcg, true, lwid, 1 );
int i = 0;
for ( it = minorText.begin(); it != minorText.end(); ++it ) {
if (i*wid1 >= left-wid1 && i*wid1 <= left+paintwid) {
qDrawShadeLine ( p,i*wid1-offsetLeft ,hei1-1, i*wid1-offsetLeft, hei2, qcg, true, lwid, 1 );
p->drawText(i*wid1+1-offsetLeft,hei1+1,wid1-1,hei2-hei1,TQt::AlignCenter,(*it));
}
++i;
}
p->setPen(black);
p->drawLine(left-offsetLeft,hei1,left+paintwid-offsetLeft,hei1);
qDrawShadeLine ( p,left-offsetLeft ,hei2-1, left+paintwid-offsetLeft, hei2-1, qcg, true, lwid, 1 );
p->drawLine(left-offsetLeft,hei2-1,left+paintwid-offsetLeft,hei2-1);
if ( !painter ) {
p->end();
delete p;
bitBlt ( this, left, 0, &paintPix, 50, 0, paintwid, height() );
}
}
// cuts the secs in the DateTime if scale is Minute ,
// the minutes and secs if scale is Hour and so on
TQDateTime KDTimeHeaderWidget::getEvenTimeDate(TQDateTime tempdatetime ,Scale sc)
{
TQDate tempdate;
int min, hour;
int tempMinorScaleCount = myRealMinorScaleCount;
switch (sc)
{
case KDGanttView::Month:
tempdate = tempdatetime.date();
while (tempdate.day ()!= 1 )
tempdate = tempdate.addDays(-1);
//while (tempdate.month ()!= 1 )
//tempdate = tempdate.addMonths(-1);
tempdatetime = TQDateTime (tempdate, TQTime (0,0));
break;
case KDGanttView::Week:
tempdate = tempdatetime.date();
while (tempdate.dayOfWeek ()!= TDEGlobal::locale()->weekStartDay())
tempdate = tempdate.addDays(-1);
//tempdate = tempdate.addDays(-7);
tempdatetime = TQDateTime (tempdate, TQTime (0,0));
break;
case KDGanttView::Day:
tempdatetime = TQDateTime (tempdatetime.date(), TQTime ( 0,0 ) );
break;
case KDGanttView::Hour:
hour = tempdatetime.time().hour();
while (24%tempMinorScaleCount > 0 && 24%tempMinorScaleCount < 24)
++tempMinorScaleCount;
hour = ( hour /tempMinorScaleCount)*tempMinorScaleCount;
tempdatetime = TQDateTime (tempdatetime.date(), TQTime (hour, 0 ));
break;
case KDGanttView::Minute:
min = tempdatetime.time().minute();
while (60%tempMinorScaleCount > 0 && 60%tempMinorScaleCount < 60)
++tempMinorScaleCount;
// tqDebug("myMinorScaleCount %d %d %d",myMinorScaleCount, myRealMinorScaleCount, tempMinorScaleCount);
min = (min /tempMinorScaleCount)*tempMinorScaleCount;
tempdatetime = TQDateTime (tempdatetime.date(), TQTime (tempdatetime.time().hour(),min ));
break;
case KDGanttView::Auto:
break;
}
return tempdatetime;
}
void KDTimeHeaderWidget::computeRealScale(TQDateTime start)
{
if (myScale ==KDGanttView::Auto) {
//tqDebug("Autoscale ");
//double secsPerMinor = (((double)start.daysTo(myHorizonEnd))* 86400.00)/((double)myAutoScaleMinorTickcount);
double secsPerMinor = (((double)start.secsTo(myHorizonEnd)))/((double)myAutoScaleMinorTickcount);
secsPerMinor /= myZoomFactor;
if (secsPerMinor <= 1800) {
myRealScale = KDGanttView::Minute;
myRealMinorScaleCount = (int) secsPerMinor/60;
} else {
if (secsPerMinor <= 12*3600) {
myRealScale = KDGanttView::Hour;
myRealMinorScaleCount = (int) secsPerMinor/3600;
} else {
if (secsPerMinor <= 24*3600*3) {
myRealScale = KDGanttView::Day;
myRealMinorScaleCount = (int) secsPerMinor/(3600*24);
} else {
if (secsPerMinor <= 24*3600*14) {
myRealScale = KDGanttView::Week;
myRealMinorScaleCount = (int) secsPerMinor/(3600*24*7);
} else {
myRealScale = KDGanttView::Month;
myRealMinorScaleCount = (int) secsPerMinor/(3600*24*30);
}
}
}
}
if(myRealMinorScaleCount == 0)
myRealMinorScaleCount = 1;
myRealMajorScaleCount = 1;
}
else {
//tqDebug("Fixed scale ");
myRealScale = myScale;
if (myRealScale > myMaxScale)
myRealScale = myMaxScale;
if (myRealScale < myMinScale)
myRealScale = myMinScale;
myRealMinorScaleCount = (int) ( ((double)myMinorScaleCount) /myZoomFactor );
double tempZoom = myZoomFactor;
myRealMajorScaleCount = myMajorScaleCount;
while (myRealMinorScaleCount == 0) {
if (myRealScale == myMinScale) {
myRealMinorScaleCount = 1;
break;
}
switch (myRealScale)
{
case KDGanttView::Minute:
myRealMinorScaleCount = 1;
return;
break;
case KDGanttView::Hour:
myRealScale = KDGanttView::Minute;
tempZoom = tempZoom/60;
break;
case KDGanttView::Day:
myRealScale = KDGanttView::Hour;
tempZoom = tempZoom/24;
break;
case KDGanttView::Week:
myRealScale = KDGanttView::Day;
tempZoom = tempZoom/7;
break;
case KDGanttView::Month:
myRealScale = KDGanttView::Week ;
tempZoom = tempZoom*7/30;
break;
case KDGanttView::Auto:
break;
}
myRealMinorScaleCount = (int) ( myMinorScaleCount /tempZoom );
}
}
}
void KDTimeHeaderWidget::computeTicks(bool doNotComputeRealScale)
{
if (flagDoNotRecomputeAfterChange) return;
bool block = myGanttView->myTimeTable->blockUpdating();
myGanttView->myTimeTable->setBlockUpdating( true );
//tqDebug("computeticks ");
majorTicks.clear();
minorText.clear();
majorText.clear();
if ( !doNotComputeRealScale )
saveCenterDateTime();
if (!doNotComputeRealScale)
computeRealScale(myHorizonStart);
myRealStart = getEvenTimeDate(myHorizonStart ,myRealScale);
if (!doNotComputeRealScale)
computeRealScale(myRealStart);
int tempMinorScaleCount = myRealMinorScaleCount,
tempMajorScaleCount = myRealMajorScaleCount;
int minorItems,minorPerMajor = 1;
minorItems = (int) (secsFromTo( myRealStart, myHorizonEnd)/60.0);
//tqDebug("tempMinorScaleCount %d ", tempMinorScaleCount);
TQPainter p(this);
int Width, Height;
TQString testTextMinor,testTextMajor, tempStr;
TQRect itemRectMinor, itemRectMajor;
TQDate tempDate = myRealStart.date();
myRealEnd = myRealStart;
// preparing the testtext for the differennt scales
switch (myRealScale)
{
// the x in testTextMajor is added to reserve a little bit more space
case KDGanttView::Minute:
testTextMinor = "60";
if (myHourFormat == KDGanttView::Hour_12)
testTextMajor = "Mon Aug 30, 12 AMx";
else
testTextMajor = "Mon Aug 30, 24:00x";
minorPerMajor = 6000;
break;
case KDGanttView::Hour:
minorItems = minorItems/60;
if (myHourFormat == KDGanttView::Hour_24)
testTextMinor = "24x";
else
testTextMinor = "12 AM";
testTextMajor = "Mon Aug 30, x";
if ( yearFormat() != KDGanttView::NoDate )
testTextMajor += getYear(TQDate::currentDate());
minorPerMajor = 2400;
break;
case KDGanttView::Day:
minorItems = minorItems/(60*24);
testTextMinor = "88";
testTextMajor = "Aug 30, x"+getYear(TQDate::currentDate());
minorPerMajor = 700;
break;
case KDGanttView::Week:
minorItems = minorItems/(60*24*7);
testTextMinor = "88";
testTextMajor = "Aug x"+getYear(TQDate::currentDate());
minorPerMajor = 435; // 435 = 365days/12months/7days * 100
break;
case KDGanttView::Month:
minorItems = (minorItems*12)/(60*24*365);
testTextMinor = "M";
testTextMajor = "x"+getYear(TQDate::currentDate());
minorPerMajor = 1200;
break;
case KDGanttView::Auto:
tqDebug("KDGanttView::Internal Error in KDTimeHeaderWidget::computeTicks() ");
tqDebug(" RealScale == Auto : This may not be! ");
break;
}
itemRectMinor = p.boundingRect ( 10, 10, 2, 2, TQt::AlignLeft,testTextMinor);
itemRectMajor = p.boundingRect ( 10, 10, 2, 2, TQt::AlignLeft,testTextMajor);
p.end();
//tqDebug(" tempMinorScaleCount %d ", tempMinorScaleCount);
Height = itemRectMinor.height()+itemRectMajor.height()+11;
Width = (itemRectMinor.width()+5);
if (Width < minimumColumnWidth()) Width = minimumColumnWidth();
// if the desired width is greater than the maximum width of this widget
// increase the minorscalecount
int maxWid = myGanttView->myCanvasView->viewport()->width();
if (!flagZoomToFit)
maxWid = maximumWidth();
while((minorItems/tempMinorScaleCount+1)*Width > maxWid)
++tempMinorScaleCount;
//tqDebug(" tempMinorScaleCount %d ", tempMinorScaleCount);
mySizeHint = (minorItems/tempMinorScaleCount+1)*Width;
switch (myRealScale)
{
case KDGanttView::Minute:
if (tempMinorScaleCount < 60)
while (60%tempMinorScaleCount > 0 && 60%tempMinorScaleCount < 60)
++tempMinorScaleCount;
if (tempMinorScaleCount >= 60) {
myRealScale = KDGanttView::Hour;
myRealMinorScaleCount = tempMinorScaleCount/ 60;
// myRealMinorScaleCount = 1;
myRealMajorScaleCount = 1;
tqDebug("KDGantt::Overzoom:Rescaling from Minute to Hour");
myGanttView->myTimeTable->setBlockUpdating( block );
emit myGanttView->rescaling( KDGanttView::Hour );
computeTicks(true);
return;
}
break;
case KDGanttView::Hour:
while (24%tempMinorScaleCount > 0 && 24%tempMinorScaleCount < 24)
++tempMinorScaleCount;
if (tempMinorScaleCount >= 24) {
myRealScale = KDGanttView::Day;
myRealMinorScaleCount = tempMinorScaleCount/ 24;
//myRealMinorScaleCount = 1;
myRealMajorScaleCount = 1;
tqDebug("KDGantt::Overzoom:Rescaling from Hour to Day");
myGanttView->myTimeTable->setBlockUpdating( block );
emit myGanttView->rescaling( KDGanttView::Day );
computeTicks(true);
return;
}
break;
default:
break;
}
//flagZoomToFit = false;
while((minorItems/tempMinorScaleCount+1)*Width < myMinimumWidth ) {
++minorItems;
}
minorItems = (minorItems/tempMinorScaleCount)+1;
// if not enough space for the text of the major scale, increase majorscalecount
minorPerMajor = (minorPerMajor*tempMajorScaleCount)/tempMinorScaleCount;
// checking, if enough space for majorscale
// if not, increasing MajorScaleCount
while ((minorPerMajor*Width)/100 < itemRectMajor.width()) {
minorPerMajor = minorPerMajor/tempMajorScaleCount;
++tempMajorScaleCount;
minorPerMajor = minorPerMajor*tempMajorScaleCount;
}
// now we have the fixed width of the minorscale computed
myGridMinorWidth = Width;
// the width of this widget is the gridwidth * the amount of items
Width *= minorItems;
// if size changed, reset geometry
if (width() != Width || height() != Height )
{
resize( Width, Height );
emit sizeChanged( Width );
}
myMajorGridHeight = itemRectMajor.height()+5;
TQTime tempTime = myRealStart.time();
TQDateTime tempDateTime;
int i;
const KCalendarSystem * calendar = TDEGlobal::locale()->calendar();
switch (myRealScale)
{
case KDGanttView::Minute:
myRealEnd = myRealEnd.addSecs((minorItems)*tempMinorScaleCount*60);
for ( i = 0; i < minorItems;++i) {
tempStr.setNum(tempTime.minute());
minorText.append(tempStr);
tempTime = tempTime.addSecs(60*tempMinorScaleCount);
}
tempDateTime = myRealStart;
while (tempDateTime.time().minute() != 0)
tempDateTime = tempDateTime.addSecs(60);
while (tempDateTime < myRealEnd) {
majorTicks.append( getCoordX(tempDateTime));
tempStr.setNum(tempDateTime.date().day());
if ( yearFormat() == KDGanttView::NoDate ) {
tempStr = calendar->weekDayName( tempDateTime.date() )+", "
+getHour(tempDateTime.time());
} else {
tempStr = calendar->weekDayName( tempDateTime.date(), true )+" "+
calendar->monthName( tempDateTime.date().month(), tempDateTime.date().year(), true)+ " "+
tempStr+", "+getHour(tempDateTime.time());
}
majorText.append(tempStr);
tempDateTime = tempDateTime.addSecs(3600*tempMajorScaleCount);
}
majorTicks.append( getCoordX(tempDateTime));
break;
case KDGanttView::Hour:
myRealEnd = myRealEnd.addSecs(minorItems*tempMinorScaleCount*60*60);
for ( i = 0; i < minorItems;++i) {
tempStr = getHour(tempTime);
minorText.append(tempStr);
tempTime = tempTime.addSecs(3600*tempMinorScaleCount);
}
tempDateTime = myRealStart;
while (tempDateTime.time().hour() != 0)
tempDateTime = tempDateTime.addSecs(3600);
while (tempDateTime < myRealEnd) {
majorTicks.append( getCoordX(tempDateTime));
tempStr.setNum(tempDateTime.date().day());
if ( yearFormat() == KDGanttView::NoDate ) {
tempStr = calendar->weekDayName( tempDateTime.date() );
} else {
tempStr = calendar->weekDayName( tempDateTime.date(), true )+" "+
calendar->monthName( tempDateTime.date().month(), tempDateTime.date().year(), true)+ " "+
tempStr+", "+getYear(tempDateTime.date());
}
majorText.append(tempStr);
tempDateTime = tempDateTime.addDays(tempMajorScaleCount);
}
majorTicks.append( getCoordX(tempDateTime));
break;
case KDGanttView::Day:
myRealEnd = myRealEnd.addDays(minorItems*tempMinorScaleCount);
for ( i = 0; i < minorItems;++i) {
if (tempMinorScaleCount == 1)
minorText.append((calendar->weekDayName(tempDate, true)).left(1)); //TODO: BIDI
else
minorText.append(TQString::number(tempDate.day()));
tempDate = tempDate.addDays(tempMinorScaleCount);
}
tempDate = myRealStart.date();
while (tempDate.dayOfWeek() != TDEGlobal::locale()->weekStartDay())
tempDate = tempDate.addDays(1);
while (tempDate < myRealEnd.date()) {
majorTicks.append( getCoordX(tempDate));
tempStr.setNum(tempDate.day());
tempStr = calendar->monthName(tempDate.month(), tempDate.year(), true)+ " "+
tempStr+", "+getYear(tempDate);
majorText.append(tempStr);
tempDate = tempDate.addDays(7*tempMajorScaleCount);
}
majorTicks.append( getCoordX(tempDate));
break;
case KDGanttView::Week:
myRealEnd = myRealEnd.addDays(minorItems*tempMinorScaleCount*7);
for ( i = 0; i < minorItems;++i) {
tempStr.setNum(tempDate.day());
minorText.append(tempStr);
tempDate = tempDate.addDays(7*tempMinorScaleCount);
}
tempDate = myRealStart.date();
while (tempDate.day() != TDEGlobal::locale()->weekStartDay())
tempDate = tempDate.addDays(1);
while (tempDate < myRealEnd.date()) {
majorTicks.append( getCoordX(tempDate));
tempStr = calendar->monthName(tempDate.month(), tempDate.year(), true)+ " "+getYear(tempDate);
majorText.append(tempStr);
tempDate = tempDate.addMonths(tempMajorScaleCount);
}
majorTicks.append( getCoordX(tempDate));
break;
case KDGanttView::Month:
myRealEnd = myRealEnd.addMonths(minorItems*tempMinorScaleCount);
for ( i = 0; i < minorItems;++i) {
minorText.append((calendar->monthName(tempDate.month(), tempDate.year(), true)).left(1)); //TODO: BIDI
tempDate = tempDate.addMonths(tempMinorScaleCount);
}
tempDate = myRealStart.date();
while (tempDate.month() != 1)
tempDate = tempDate.addMonths(1);
while (tempDate < myRealEnd.date()) {
majorTicks.append( getCoordX(tempDate));
tempStr = getYear(tempDate);
majorText.append(tempStr);
tempDate = tempDate.addYears(tempMajorScaleCount);
}
majorTicks.append( getCoordX(tempDate));
break;
case KDGanttView::Auto:
break;
}
if (flagDoNotRepaintAfterChange) {
myGanttView->myTimeTable->setBlockUpdating( block );
return;
}
//tqDebug("KDTimeHeaderWidget width %d, viewport width %d ",width (), myGanttView->myCanvasView->viewport()->width());
myGanttView->myTimeTable->setBlockUpdating( block );
updateTimeTable();
centerDateTime(myCenterDateTime);
repaint();
}
void KDTimeHeaderWidget::saveCenterDateTime()
{
double wid = width();
double allsecs = secsFromTo( myRealStart, myRealEnd );
double center = myGanttView->myCanvasView->viewport()->width();
center = center / 2;
center = center + myGanttView->myCanvasView->contentsX();
double secs = (allsecs*center)/wid;
double days = secs/86400.0;
secs = secs - ( (int) days *86400.0 );
myCenterDateTime = (myRealStart.addDays ( (int) days )).addSecs( (int) secs);
}
void KDTimeHeaderWidget::centerDateTime( const TQDateTime& center )
{
moveTimeLineTo(getCoordX( center )-(myGanttView->myCanvasView->viewport()->width() /2));
// tqDebug("centerDateTime %s %d %d", center.toString().latin1(),getCoordX( center ),(myGanttView->myCanvasView->viewport()->width() /2) );
}
void KDTimeHeaderWidget::paintEvent(TQPaintEvent *p)
{
repaintMe(p->rect().x(),p->rect().width());
}
int KDTimeHeaderWidget::getCoordX(TQDate date)
{
int wid = width();
int daysAll = myRealStart.daysTo(myRealEnd);
if (daysAll == 0) return 0;
int days = myRealStart.daysTo(TQDateTime(date));
return (wid *days) /daysAll;
}
int KDTimeHeaderWidget::getCoordX(TQDateTime datetime)
{
double wid = width();
double secsAll = secsFromTo( myRealStart, myRealEnd );
if (secsAll == 0.0) return 0;
double secs = secsFromTo( myRealStart, datetime);
return ((int)((wid *(secs /secsAll))+0.5));
}
TQString KDTimeHeaderWidget::getYear(TQDate date)
{
TQString ret;
ret.setNum(date.year());
switch (yearFormat()) {
case KDGanttView::FourDigit:
// nothing to do
break;
case KDGanttView::TwoDigit:
ret = ret.right(2);
break;
case KDGanttView::TwoDigitApostrophe:
ret = "'"+ret.right(2);
break;
case KDGanttView::NoDate:
// nothing to do
break;
}
return ret;
}
TQString KDTimeHeaderWidget::getHour(TQTime time)
{
TQString ret;
int hour = time.hour();
if (myHourFormat == KDGanttView::Hour_12) {
if (hour >= 12) {
if (hour > 12) hour -=12;
ret.setNum(hour);
ret = ret +" PM";
} else {
if (hour == 0) hour = 12;
ret.setNum(hour);
ret = ret +" AM";
}
} else {
if (myHourFormat == KDGanttView::Hour_24)
ret.setNum(hour);
else {
ret.setNum(hour);
ret += ":00";
}
}
return ret;
}
void KDTimeHeaderWidget::mousePressEvent ( TQMouseEvent * e )
{
mouseDown = false;
switch ( e->button() ) {
case TQt::LeftButton:
mouseDown = true;
beginMouseDown = e->pos().x();
endMouseDown = e->pos().x();
break;
case TQt::RightButton:
if (flagShowPopupMenu)
myPopupMenu->popup(e->globalPos());
break;
case TQt::MidButton:
break;
default:
break;
}
}
void KDTimeHeaderWidget::mouseReleaseEvent ( TQMouseEvent * )
{
if ( mouseDown ) {
mouseDown = false;
// zoom to selection getDateTimeForIndex(
int start, end;
if ( beginMouseDown < endMouseDown ) {
start = beginMouseDown;
end = endMouseDown;
} else {
start = endMouseDown;
end = beginMouseDown;
}
if (start < 0 )
start = 0;
if ( end > width() )
end = width();
//tqDebug("start %s ",getDateTimeForIndex(start).toString().latin1() );
//tqDebug("end %s ",getDateTimeForIndex(end).toString().latin1() );
emit myGanttView->timeIntervalSelected( getDateTimeForIndex(start),getDateTimeForIndex(end) );
emit myGanttView->timeIntervallSelected( getDateTimeForIndex(start),getDateTimeForIndex(end) );
//zoomToSelection( getDateTimeForIndex(start),getDateTimeForIndex(end) );
}
mouseDown = false;
repaint();
}
void KDTimeHeaderWidget::mouseDoubleClickEvent ( TQMouseEvent * )
{
}
void KDTimeHeaderWidget::mouseMoveEvent ( TQMouseEvent * e )
{
if ( mouseDown ) {
if ( e->pos().y() < -height() || e->pos().y() > 2* height() ) {
mouseDown = false;
repaint();
return;
}
endMouseDown = e->pos().x();
//repaint;
int val = -1;
if (endMouseDown < -x() ) {
val = myGanttView->myCanvasView->horizontalScrollBar()->value() -
myGanttView->myCanvasView->horizontalScrollBar()->lineStep();
if ( val < 0 ) {
val = 0;
}
}
if (endMouseDown > -x() +parentWidget()->width() ) {
val = myGanttView->myCanvasView->horizontalScrollBar()->value() +
myGanttView->myCanvasView->horizontalScrollBar()->lineStep();
}
repaintMe(-x(),parentWidget()->width());
if ( val > -1 ) {
if ( val > myGanttView->myCanvasView->horizontalScrollBar()->maxValue() ) {
val = myGanttView->myCanvasView->horizontalScrollBar()->maxValue();
}
myGanttView->myCanvasView->horizontalScrollBar()->setValue( val );
}
//tqDebug("mousemove %d %d %d %d",endMouseDown, -x(),parentWidget()->width() , e->pos().y());
}
}
/* ***************************************************************
KDLegendWidget:: KDLegendWidget
***************************************************************** */
KDLegendWidget:: KDLegendWidget( TQWidget* parent,
KDGanttMinimizeSplitter* legendParent ) :
KDGanttSemiSizingControl ( KDGanttSemiSizingControl::Before,TQt::Vertical,
parent)
{
myLegendParent = legendParent;
dock = 0;
scroll = new TQScrollView( legendParent );
setMaximizedWidget( scroll );
setMinimizedWidget( myLabel = new TQLabel( i18n( " Legend is hidden" ), this) );
setGeometry( 0, 0, 50, 50 );
myLegend = 0;
clearLegend();
showMe ( false );
}
void KDLegendWidget::setAsDoctwindow( bool dockwin )
{
if ( (dock == 0 && !dockwin) || ( dock && dockwin ) )
return;
if ( dockwin )
{
setMaximizedWidget( 0 );
showMe ( false );
if ( dock ) delete dock;
dock = new TQDockWindow(TQDockWindow:: OutsideDock,0 );
dock->resize( 200, 100 );
dock->setHorizontallyStretchable( true );
dock->setVerticallyStretchable( true );
dock->setCaption(i18n("Legend: ") );
dock->setResizeEnabled (true );
delete myLegend;
myLegend = 0;
delete scroll;
scroll = new TQScrollView( dock );
clearLegend();
dock->setWidget(scroll);
setMaximizedWidget( dock );
showMe ( false );
} else {
setMaximizedWidget( 0 );
showMe ( false );
delete myLegend;
myLegend = 0;
delete scroll;
delete dock;
dock = 0;
scroll = new TQScrollView( myLegendParent );
clearLegend();
setMaximizedWidget( scroll );
showMe ( false );
}
}
bool KDLegendWidget::asDoctwindow( )
{
if ( dock )
return true;
return false;
}
TQDockWindow* KDLegendWidget::dockwindow( )
{
return dock;
}
void KDLegendWidget::setFont( TQFont font)
{
myLegend->setFont( font);
myLabel->setFont( font);
TQWidget::setFont( font );
}
void KDLegendWidget::drawToPainter( TQPainter *p )
{
p->drawPixmap( 0, 0, TQPixmap::grabWidget( myLegend ) );
}
TQSize KDLegendWidget::legendSize()
{
return myLegend->size();
}
TQSize KDLegendWidget::legendSizeHint()
{
TQApplication::sendPostedEvents( 0, TQEvent::LayoutHint );
return TQSize( myLegend->sizeHint().width(), myLegend->sizeHint().height()+scroll->horizontalScrollBar()->height());
}
void KDLegendWidget::showMe ( bool show )
{
minimize( !show );
}
void KDLegendWidget::clearLegend ( )
{
if ( myLegend ) delete myLegend;
if ( dock )
myLegend = new TQGroupBox( 1, TQt::Horizontal, scroll->viewport() );
else
myLegend = new TQGroupBox( 1, TQt::Horizontal, i18n( "Legend" ), scroll->viewport() );
myLegend->setBackgroundColor( TQt::white );
myLegend->setFont( font() );
scroll->addChild( myLegend );
scroll->setResizePolicy( TQScrollView::AutoOneFit );
myLegend->layout()->setMargin( 11 );
myLegend->setFrameStyle( TQFrame::NoFrame );
if ( dock )
scroll->setMaximumHeight( 32000 );
else
scroll->setMaximumHeight( legendSizeHint().height() );
}
void KDLegendWidget::addLegendItem( KDGanttViewItem::Shape shape, const TQColor& shapeColor, const TQString& text )
{
TQLabel * temp;
TQPixmap p = KDGanttView::getPixmap( shape, shapeColor, TQt::white, 10);
TQWidget *w = new TQWidget( myLegend );
w->setBackgroundColor( TQt::white );
TQHBoxLayout *lay = new TQHBoxLayout( w ,0, 6);
temp = new TQLabel ( w );
lay->addWidget( temp, 0, TQt:: AlignRight);
temp->setPixmap(p);
temp = new TQLabel ( text, w );
temp->setBackgroundColor( TQt::white );
lay->addWidget( temp, 0, TQt:: AlignLeft);
lay->addStretch();
if ( dock )
scroll->setMaximumHeight( 32000 );
else
scroll->setMaximumHeight( legendSizeHint().height() );
}
bool KDLegendWidget::isShown ( )
{
return !isMinimized();
}
KDListView::KDListView(TQWidget* parent, KDGanttView* gantView):TQListView (parent)
{
myGanttView = gantView;
setAcceptDrops(true);
new KDListViewWhatsThis(viewport(),this);
setRootIsDecorated( true );
setAllColumnsShowFocus( true );
addColumn( i18n( "Task Name" ) );
setSorting( -1 );
//setVScrollBarMode (TQScrollView::AlwaysOn );
setHScrollBarMode (TQScrollView::AlwaysOn );
setDefaultRenameAction(TQListView::Accept);
setColumnWidthMode ( 0,Maximum );
_calendarMode = false;
// TQObject::connect(this, TQ_SIGNAL ( pressed ( TQListViewItem * )) , this, TQ_SLOT( dragItem( TQListViewItem *))) ;
}
void KDListView::dragItem( TQListViewItem * )
{
// tqDebug("drag ");
// startDrag();
}
TQString KDListView::getWhatsThisText(TQPoint p)
{
KDGanttViewItem* item = ( KDGanttViewItem* ) itemAt( p );
if ( item )
return item->whatsThisText();
return i18n( "No item Found" );
}
void KDListView::setCalendarMode( bool mode )
{
_calendarMode = mode;
// setRootIsDecorated ( ! mode );
}
void KDListView::setOpen(TQListViewItem * item, bool open )
{
if (! _calendarMode || ! open ) {
(( KDGanttViewItem*)item)->setCallListViewOnSetOpen( false );
TQListView::setOpen ( item, open );
(( KDGanttViewItem*)item)->setCallListViewOnSetOpen( true );
return;
}
// we are in calendarmode
// in calendarmode only items can be opened which have subitems which have subitems
TQListViewItem* temp;
temp = item->firstChild();
bool openItem = false;
while (temp) {
if ( (( KDGanttViewItem*)temp)->displaySubitemsAsGroup() ) {
temp->setVisible( true );
openItem = true;
}
else {
temp->setVisible( false );
//tqDebug(" temp->setVisible( false );");
}
temp = temp->nextSibling();
}
if ( openItem ) {
(( KDGanttViewItem*)item)->setCallListViewOnSetOpen( false );
TQListView::setOpen ( item, open );
(( KDGanttViewItem*)item)->setCallListViewOnSetOpen( true );
}
}
void KDListView::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
{
TQListView::contentsMouseDoubleClickEvent ( e );
//if ( ! _calendarMode )
// TQListView::contentsMouseDoubleClickEvent ( e );
// else
{
emit myGanttView->lvItemDoubleClicked ( (KDGanttViewItem*) itemAt(e->pos() ) );
emit myGanttView->itemDoubleClicked ( (KDGanttViewItem*) itemAt(e->pos() ) );
}
}
void KDListView::drawToPainter ( TQPainter * p, bool drawHeader )
{
// Draw list
drawAllContents ( p, 0, 0, contentsWidth(), contentsHeight() );
if (!drawHeader) {
return;
}
// Draw headers
TQPen pen = TQPen(TQt::lightGray, 1);
p->save();
TQHeader *h = header();
for (int s = 0; s < h->count(); ++s) {
TQRect r = h->sectionRect(s);
if (s==0) {
p->translate(0, -r.height());
}
//kdDebug()<<s<<": "<<h->label(s)<<" "<<r<<endl;
p->drawText(r.x()+2, r.y(), r.width()-2, r.height(), columnAlignment(s)|TQt::AlignVCenter, h->label(s), -1);
p->save();
p->setPen(pen);
p->drawRect(r.x(), r.y()+1, r.width(), r.height()-2);
p->restore();
}
p->restore();
}
int KDListView::buildDrawables(TQPtrList<KDListView::DrawableItem> &lst, int level, int ypos, TQListViewItem *item, int ymin, int ymax) const {
int y = ypos;
int ih = item->height();
if (y < ymin && y+ih > ymin) {
y = ymin; // include partial item at top
}
if (y >= ymin && y < ymax) { // include partial item at bottom
KDListView::DrawableItem *dr = new KDListView::DrawableItem(level, y, item);
lst.append(dr);
//kdDebug()<<k_funcinfo<<level<<", "<<y<<" : "<<item->text(0)<<endl;
}
y += ih;
if (item->isOpen()) {
TQListViewItem *child = item->firstChild();
for (; child; child = child->nextSibling()) {
y = buildDrawables(lst, level+1, y, child, ymin, ymax);
}
}
return y;
}
// This is a copy of TQListView::drawContentsOffset(), with a few changes
// because drawContentsOffset() only draws *visible* items,
// we want to draw *all* items.
// FIXME: Haven't got paintBraches() to work, atm live without it.
void KDListView::drawAllContents(TQPainter * p, int cx, int cy, int cw, int ch) {
if ( columns() == 0 ) {
paintEmptyArea( p, TQRect( cx, cy, cw, ch ) );
return;
}
//kdDebug()<<k_funcinfo<<TQRect(cx, cy, cw, ch)<<endl;
TQPtrList<KDListView::DrawableItem> drawables;
drawables.setAutoDelete(true);
TQListViewItem *child = firstChild();
int level = 0;
int ypos = 0;
for (; child; child = child->nextSibling()) {
ypos = buildDrawables(drawables, level, ypos, child, cy, cy+ch);
}
p->setFont( font() );
TQPtrListIterator<KDListView::DrawableItem> it(drawables);
TQRect r;
int fx = -1, x, fc = 0, lc = 0;
int tx = -1;
KDListView::DrawableItem * current;
while ( (current = it.current()) != 0 ) {
++it;
int ih = current->i->height();
int ith = current->i->totalHeight();
int c;
int cs;
// need to paint current?
if ( ih > 0 && current->y < cy+ch && current->y+ih > cy ) {
//kdDebug()<<k_funcinfo<<"Paint: "<<current->i->text(0)<<" y="<<current->y<<endl;
if ( fx < 0 ) {
// find first interesting column, once
x = 0;
c = 0;
cs = header()->cellSize( 0 );
while ( x + cs <= cx && c < header()->count() ) {
x += cs;
c++;
if ( c < header()->count() )
cs = header()->cellSize( c );
}
fx = x;
fc = c;
while( x < cx + cw && c < header()->count() ) {
x += cs;
c++;
if ( c < header()->count() )
cs = header()->cellSize( c );
}
lc = c;
}
x = fx;
c = fc;
// draw to last interesting column
const TQColorGroup &cg = ( palette().inactive() );
while ( c < lc && !drawables.isEmpty() ) {
int i = header()->mapToLogical( c );
cs = header()->cellSize( c );
r.setRect( x, current->y-cy, cs, ih );
if ( i == 0 )
r.setLeft( r.left() + current->l * treeStepSize() );
p->save();
// No need to paint if the cell isn't technically visible
if ( !( r.width() == 0 || r.height() == 0 ) ) {
p->translate( r.left(), r.top() );
int ac = header()->mapToLogical( c );
// map to Left currently. This should change once we
// can really reverse the listview.
int align = columnAlignment( ac );
if ( align == AlignAuto ) align = AlignLeft;
bool sel = current->i->isSelected();
if (sel)
current->i->setSelected(false);
current->i->paintCell( p, cg, ac, r.width(), align );
if (sel)
current->i->setSelected(sel);
}
p->restore();
x += cs;
c++;
}
}
const int cell = header()->mapToActual( 0 );
if ( tx < 0 )
tx = header()->cellPos( cell );
// do any children of current need to be painted?
/* FIXME: painting branches doesn't work for some reason...
if ( ih != ith &&
rootIsDecorated() &&
current->y + ith > cy &&
current->y + ih < cy + ch &&
tx + current->l * treeStepSize() < cx + cw &&
tx + (current->l+1) * treeStepSize() > cx ) {
// compute the clip rectangle the safe way
int rtop = current->y + ih;
int rbottom = current->y + ith;
int rleft = tx + current->l*treeStepSize();
int rright = rleft + treeStepSize();
int crtop = TQMAX( rtop, cy );
int crbottom = TQMIN( rbottom, cy+ch );
int crleft = TQMAX( rleft, cx );
int crright = TQMIN( rright, cx+cw );
r.setRect( crleft, crtop,
crright-crleft, crbottom-crtop );
if ( r.isValid() ) {
p->save();
p->translate( rleft, crtop );
//kdDebug()<<k_funcinfo<<"paintBranches: "<<current->i->text(0)<<endl;
current->i->paintBranches( p, colorGroup(), treeStepSize(),
rtop - crtop, r.height() );
p->restore();
}
}*/
}
}
void KDListView::resizeEvent(TQResizeEvent *)
{
triggerUpdate ();
}
void KDListView::dragEnterEvent ( TQDragEnterEvent * e)
{
if ( !myGanttView->dropEnabled() ) {
e->accept( false );
return;
}
myGanttView->lvDragEnterEvent(e);
//e->accept(KDGanttViewItemDrag::canDecode(e) );
}
void KDListView::dragMoveEvent ( TQDragMoveEvent * e)
{
if ( !myGanttView->dropEnabled() ) {
e->accept( false );
return;
}
KDGanttViewItem* draggedItem = 0;
KDGanttViewItem* gItem = (KDGanttViewItem*)itemAt( e->pos()) ;
setCurrentItem( gItem );
if ( e->source() == myGanttView )
draggedItem = myGanttView->myCanvasView->lastClickedItem;
// execute user defined dragMoveEvent handling
if (myGanttView->lvDragMoveEvent ( e , draggedItem, gItem ) )
return;
if ( !KDGanttViewItemDrag::canDecode(e) ) {
e->accept( false );
return;
}
if ( e->source() == myGanttView && gItem ){
// internal drag - do not allow to drag the item to a subitem of itself
KDGanttViewItem* pItem = gItem->parent();
while ( pItem ) {
if ( pItem == myGanttView->myCanvasView->lastClickedItem ) {
e->accept( false );
return;
}
pItem = pItem->parent();
}
if ( gItem == myGanttView->myCanvasView->lastClickedItem ) {
e->accept( false );
return;
}
}
e->accept( true );
}
void KDListView::dragLeaveEvent ( TQDragLeaveEvent * )
{
//tqDebug("contentsDragLeaveEvent ");
}
void KDListView::dropEvent ( TQDropEvent *e )
{
if ( !myGanttView->dropEnabled() ) {
e->accept( false );
return;
}
KDGanttViewItem* gItem = (KDGanttViewItem*)itemAt( e->pos()) ;
KDGanttViewItem* draggedItem = 0;
if ( e->source() == myGanttView )
draggedItem = myGanttView->myCanvasView->lastClickedItem;
if (myGanttView->lvDropEvent ( e, draggedItem, gItem ))
return;
TQString string;
KDGanttViewItemDrag::decode( e, string );
KDGanttViewItem* newItem = 0;
if ( gItem == myGanttView->myCanvasView->lastClickedItem && gItem != 0 ) {
tqDebug("KDGanttView::Possible bug in drag&drop code ");
return;
}
TQDomDocument doc( "GanttView" );
doc.setContent( string );
TQDomElement docRoot = doc.documentElement(); // ChartParams element
TQDomNode node = docRoot.firstChild();
bool enable = myGanttView->myTimeTable->blockUpdating( );
myGanttView->myTimeTable->setBlockUpdating( true );
while( !node.isNull() ) {
TQDomElement element = node.toElement();
if( !element.isNull() ) { // was really an element
TQString tagName = element.tagName();
if( tagName == "Items" ) {
TQDomNode node = element.firstChild();
while( !node.isNull() ) {
TQDomElement element = node.toElement();
if( !element.isNull() ) { // was really an element
TQString tagName = element.tagName();
if( tagName == "Item" ) {
if ( gItem )
newItem = KDGanttViewItem::createFromDomElement( gItem,
element );
else
newItem = KDGanttViewItem::createFromDomElement( myGanttView,
element );
} else {
tqDebug( "Unrecognized tag name: %s", tagName.latin1() );
Q_ASSERT( false );
}
}
//tqDebug("next node1 ");
node = node.nextSibling();
}
}
}
//tqDebug("next node2 ");
node = node.nextSibling();
}
newItem->setDisplaySubitemsAsGroup(myGanttView->displaySubitemsAsGroup());
newItem->resetSubitemVisibility();
myGanttView->slot_lvDropped(e, draggedItem, gItem);
myGanttView->myTimeTable->setBlockUpdating( enable );
myGanttView->myTimeTable->updateMyContent();
return;
}
TQDragObject * KDListView::dragObject ()
{
return TQListView::dragObject ();
}
void KDListView::startDrag ()
{
if ( ! myGanttView->dragEnabled() )
return;
KDGanttViewItem* cItem = (KDGanttViewItem*) currentItem ();
myGanttView->myCanvasView->lastClickedItem = cItem;
myGanttView->lvStartDrag (cItem);
}
KDCanvasText::KDCanvasText( KDTimeTableWidget* canvas,
void* parentItem,
int type ) :
TQCanvasText(canvas)
{
myParentType = type;
myParentItem = parentItem;
}
KDCanvasLine::KDCanvasLine( KDTimeTableWidget* canvas,
void* parentItem,
int type ) :
TQCanvasLine(canvas)
{
myParentType = type;
myParentItem = parentItem;
}
KDCanvasPolygonItem::KDCanvasPolygonItem( KDTimeTableWidget* canvas,
void* parentItem,
int type ) :
TQCanvasPolygonalItem( canvas )
{
myParentType = type;
myParentItem = parentItem;
}
KDCanvasPolygon::KDCanvasPolygon( KDTimeTableWidget* canvas,
void* parentItem,
int type ) :
TQCanvasPolygon( canvas )
{
myParentType = type;
myParentItem = parentItem;
}
KDCanvasEllipse::KDCanvasEllipse( KDTimeTableWidget* canvas,
void* parentItem,
int type ) :
TQCanvasEllipse( canvas )
{
myParentType = type;
myParentItem = parentItem;
}
KDCanvasRectangle::KDCanvasRectangle( KDTimeTableWidget* canvas,
void* parentItem,
int type ) :
TQCanvasRectangle( canvas )
{
myParentType = type;
myParentItem = parentItem;
}
KDGanttCanvasView::KDGanttCanvasView( KDGanttView* sender,TQCanvas* canvas, TQWidget* parent, const
char* name ) : TQCanvasView ( canvas, parent, name ), scrollBarTimer( 0, "scrollBarTimer" )
{
setHScrollBarMode (TQScrollView::AlwaysOn );
setVScrollBarMode( TQScrollView::AlwaysOn );
myToolTip = new KDCanvasToolTip(viewport(),this);
mySignalSender = sender;
currentItem = 0;
currentLink = 0;
cuttedItem = 0;
fromItem = 0;
fromArea = 0;
linkItemsEnabled = false;
linkLine = new TQCanvasLine(canvas);
linkLine->hide();
linkLine->setZ(1000);
//set_Mouse_Tracking(true);
new KDCanvasWhatsThis(viewport(),this);
onItem = new TQPopupMenu( this );
TQPopupMenu * newMenu = new TQPopupMenu( this );
TQPopupMenu * onView = new TQPopupMenu( this );
onView->insertItem( i18n( "Summary" ), this,
TQ_SLOT ( newRootItem( int ) ), 0, 0 );
onView->insertItem( i18n( "Event" ), this,
TQ_SLOT ( newRootItem( int ) ), 0, 1);
onView->insertItem( i18n( "Task" ), this,
TQ_SLOT ( newRootItem( int ) ), 0, 2 );
onItem->insertItem( i18n( "New Root" ), onView );
newMenu->insertItem( i18n( "Summary" ),
this, TQ_SLOT ( newChildItem( int) ), 0, 0 );
newMenu->insertItem( i18n( "Event" ),
this, TQ_SLOT ( newChildItem( int ) ), 0, 1 );
newMenu->insertItem( i18n( "Task" ),
this, TQ_SLOT ( newChildItem( int ) ), 0, 2 );
onItem->insertItem( i18n( "New Child" ), newMenu );
TQPopupMenu * afterMenu = new TQPopupMenu( this );
afterMenu->insertItem( i18n( "Summary" ),
this, TQ_SLOT ( newChildItem( int) ), 0, 0+4 );
afterMenu->insertItem( i18n( "Event" ),
this, TQ_SLOT ( newChildItem( int ) ), 0, 1+4 );
afterMenu->insertItem( i18n( "Task" ),
this, TQ_SLOT ( newChildItem( int ) ), 0, 2+4 );
onItem->insertItem( i18n( "New After" ), afterMenu );
TQPopupMenu *pasteMenu = new TQPopupMenu( this );
pasteMenu->insertItem( i18n( "As Root" ),
this, TQ_SLOT ( pasteItem( int ) ), 0, 0 );
pasteMenu->insertItem( i18n( "As Child" ),
this, TQ_SLOT ( pasteItem( int ) ), 0, 1 );
pasteMenu->insertItem( i18n( "After" ),
this, TQ_SLOT ( pasteItem( int ) ), 0, 2 );
onItem->insertItem( i18n( "Paste" ), pasteMenu, 3 );
onItem->insertItem( i18n( "Cut Item" ), this, TQ_SLOT ( cutItem() ) );
onItem->setItemEnabled( 3, false );
myMyContentsHeight = 0;
_showItemAddPopupMenu = false;
TQObject *scrollViewTimer = child( "scrollview scrollbar timer", "TQTimer", false );
Q_ASSERT( scrollViewTimer );
if ( scrollViewTimer ) {
disconnect( scrollViewTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(updateScrollBars() ) );
}
// If they needed a scrollbar timer in scrollview...
connect( &scrollBarTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(myUpdateScrollBars() ) );
myScrollTimer = new TQTimer( this, "myScrollTimer" );
connect( myScrollTimer, TQ_SIGNAL( timeout() ), TQ_SLOT( slotScrollTimer() ) );
autoScrollEnabled = false;
}
KDGanttCanvasView::~KDGanttCanvasView()
{
delete myToolTip;
}
void KDGanttCanvasView::setShowPopupMenu( bool show )
{
_showItemAddPopupMenu = show;
}
bool KDGanttCanvasView::showPopupMenu()
{
return _showItemAddPopupMenu;
}
void KDGanttCanvasView::moveMyContent( int, int y)
{
setContentsPos(contentsX(), y);
}
void KDGanttCanvasView::resizeEvent ( TQResizeEvent * e )
{
int ho = e->oldSize().height();
int wo = e->oldSize().width();
int hi = height();
int wi = width();
//TQScrollView::blockSignals( true );
verticalScrollBar()->setUpdatesEnabled( false );
TQScrollView::resizeEvent ( e ) ;
if ( ho != hi )
emit heightResized( viewport()->height());
if ( wo != wi )
emit widthResized( viewport()->width() );
//setMyContentsHeight( 0 ); // via timer
//TQScrollView::blockSignals( false );
scrollBarTimer.start(0, true);
}
void KDGanttCanvasView::myUpdateScrollBars()
{
setMyContentsHeight( 0 );
}
void KDGanttCanvasView::setMyContentsHeight( int hei )
{
//tqDebug("setMyContentsHeight %d %d ", hei, myMyContentsHeight);
if ( hei > 0 )
myMyContentsHeight = hei;
verticalScrollBar()->setUpdatesEnabled( true ); // set false in resizeEvent()
if ( viewport()->height() <= myMyContentsHeight )
verticalScrollBar()->setRange( 0, myMyContentsHeight- viewport()->height()+1);
else
verticalScrollBar()->setRange( 0,0 );
// testing for unmatching ScrollBar values of timeheader and timetable
// may happen after external resizing
if ( horizontalScrollBar()->value() != mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->value() ) {
// I am the Boss!
mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->setValue(horizontalScrollBar()->value() );
}
}
// Call after *internal* resizing (like addTickRight())
// Then the new scrollbar maxValue is in myTimeHeader.
void KDGanttCanvasView::updateHorScrollBar() {
//tqDebug("horizontalScrollBar max=%d, myTimeHeaderScroll=%d", horizontalScrollBar()->maxValue(), mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->value());
horizontalScrollBar()->setRange(mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->minValue(), mySignalSender->myTimeHeaderScroll->horizontalScrollBar()->maxValue());
}
void KDGanttCanvasView::cutItem( KDGanttViewItem* item )
{
lastClickedItem = item;
cutItem();
}
void KDGanttCanvasView::insertItemAsRoot( KDGanttViewItem* item )
{
mySignalSender->myListView->insertItem( item );
if ( item == cuttedItem )
cuttedItem = 0;
}
void KDGanttCanvasView::insertItemAsChild( KDGanttViewItem* parent, KDGanttViewItem* item )
{
parent->insertItem( cuttedItem );
if ( item == cuttedItem )
cuttedItem = 0;
}
void KDGanttCanvasView::insertItemAfter( KDGanttViewItem* parent , KDGanttViewItem* item )
{
if ( parent->parent() ) {
parent->parent()->insertItem( item );
}
else
mySignalSender->myListView->insertItem( item );
item->moveItem( parent );
if ( item == cuttedItem )
cuttedItem = 0;
}
void KDGanttCanvasView::cutItem()
{
lastClickedItem->hideSubtree();
//tqDebug("last clicked %d parent %d ", lastClickedItem , lastClickedItem->parent());
if ( lastClickedItem->parent() )
lastClickedItem->parent()->takeItem(lastClickedItem);
else
mySignalSender->myListView->takeItem( lastClickedItem );
mySignalSender->myTimeTable->updateMyContent();
if ( cuttedItem )
delete cuttedItem;
cuttedItem = lastClickedItem;
onItem->setItemEnabled( 3, true );
}
// called from the destructor in KDGanttViewItem or KDGanttView
void KDGanttCanvasView::resetCutPaste( KDGanttViewItem* item )
{
if ( item == 0 && cuttedItem ) {
delete cuttedItem;
cuttedItem = 0;
}
if (item == cuttedItem) {
onItem->setItemEnabled( 3, false );
cuttedItem = 0;
}
}
void KDGanttCanvasView::pasteItem( int type )
{
if ( !cuttedItem )
return;
switch( type ) {
case 0://root
mySignalSender->myListView->insertItem( cuttedItem );
break;
case 1://child
lastClickedItem->insertItem( cuttedItem );
break;
case 2://after
if ( lastClickedItem->parent() ) {
lastClickedItem->parent()->insertItem( cuttedItem );
}
else
mySignalSender->myListView->insertItem( cuttedItem );
cuttedItem->moveItem( lastClickedItem );
break;
default:
;
}
cuttedItem = 0;
onItem->setItemEnabled( 3, false );
mySignalSender->myTimeTable->updateMyContent();
}
void KDGanttCanvasView::newRootItem(int type)
{
KDGanttViewItem* temp = 0;
switch( type ) {
case 1:
temp = new KDGanttViewEventItem( mySignalSender, i18n( "New Event" ) );
break;
case 0:
temp = new KDGanttViewSummaryItem( mySignalSender, i18n( "New Summary" ) );
break;
case 2:
temp = new KDGanttViewTaskItem( mySignalSender, i18n( "New Task" ) );
break;
default:
;
}
if ( temp )
mySignalSender->editItem( temp );
}
void KDGanttCanvasView::newChildItem( int type )
{
KDGanttViewItem* temp = 0;
switch( type ) {
case 1:
temp = new KDGanttViewEventItem( lastClickedItem, i18n( "New Event" ) );
break;
case 0:
temp = new KDGanttViewSummaryItem( lastClickedItem, i18n( "New Summary" ) );
break;
case 2:
temp = new KDGanttViewTaskItem( lastClickedItem, i18n( "New Task" ) );
break;
case 5:
if ( lastClickedItem->parent() )
temp = new KDGanttViewEventItem( lastClickedItem->parent(), lastClickedItem, i18n( "New Event" ) );
else
temp = new KDGanttViewEventItem( mySignalSender, lastClickedItem, i18n( "New Event" ) );
break;
case 4:
if ( lastClickedItem->parent() )
temp = new KDGanttViewSummaryItem( lastClickedItem->parent(), lastClickedItem, i18n( "New Summary" ) );
else
temp = new KDGanttViewSummaryItem( mySignalSender, lastClickedItem, i18n( "New Summary" ) );
break;
case 6:
if ( lastClickedItem->parent() )
temp = new KDGanttViewTaskItem( lastClickedItem->parent(), lastClickedItem, i18n( "New Task" ) );
else
temp = new KDGanttViewTaskItem( mySignalSender, lastClickedItem, i18n( "New Task" ) );
break;
default:
;
}
if ( temp )
mySignalSender->editItem( temp );
}
void KDGanttCanvasView::drawToPainter ( TQPainter * p )
{
drawContents ( p, 0, 0, canvas()->width(), canvas()->height() );
}
TQString KDGanttCanvasView::getToolTipText(TQPoint p)
{
TQCanvasItemList il = canvas()->collisions ( viewportToContents( p ));
TQCanvasItemList::Iterator it;
for ( it = il.begin(); it != il.end(); ++it ) {
switch (getType(*it)) {
case Type_is_KDGanttViewItem:
return (getItem(*it))->tooltipText();
break;
case Type_is_KDGanttTaskLink:
return (getLink(*it))->tooltipText();
break;
default:
break;
}
}
return "";
}
TQString KDGanttCanvasView::getWhatsThisText(TQPoint p)
{
TQCanvasItemList il = canvas() ->collisions (viewportToContents( p ));
TQCanvasItemList::Iterator it;
for ( it = il.begin(); it != il.end(); ++it ) {
switch (getType(*it)) {
case Type_is_KDGanttViewItem:
return (getItem(*it))->whatsThisText();
break;
case Type_is_KDGanttTaskLink:
return (getLink(*it))->whatsThisText();
break;
default:
break;
}
}
return "";
}
/**
Handles the mouseevent if a mousekey is pressed
\param e the mouseevent
*/
void KDGanttCanvasView::contentsMousePressEvent ( TQMouseEvent * e )
{
//tqDebug("mousepress! %d ", this);
//tqDebug("focus %d ",tqApp->focusWidget());
setFocus();
currentLink = 0;
currentItem = 0;
if (e->button() == TQt::RightButton && mySignalSender->editable()) {
lastClickedItem = (KDGanttViewItem*) mySignalSender->myListView->itemAt( TQPoint(2,e->pos().y()));
if ( lastClickedItem ) {
if ( lastClickedItem->displaySubitemsAsGroup() && ! lastClickedItem->isOpen() ) {
// findSub subitem
TQCanvasItemList il = canvas() ->collisions ( e->pos() );
TQCanvasItemList::Iterator it;
for ( it = il.begin(); it != il.end(); ++it ) {
if ( getType(*it) == Type_is_KDGanttViewItem ) {
lastClickedItem = getItem(*it);
}
}
}
if ( _showItemAddPopupMenu )
onItem->popup(e->globalPos());
}
}
TQCanvasItemList il = canvas() ->collisions ( e->pos() );
TQCanvasItemList::Iterator it;
for ( it = il.begin(); it != il.end(); ++it ) {
switch ( e->button() ) {
case TQt::LeftButton:
switch (getType(*it)) {
case Type_is_KDGanttViewItem:
currentItem = getItem(*it);
if (! currentItem->enabled() ) {
currentItem = 0;
} else if (linkItemsEnabled &&
!currentItem->isMyTextCanvas(*it)) {
fromArea = getItemArea(currentItem, e->pos().x());
if (fromArea > 0) {
fromItem = currentItem;
linkLine->setPoints(e->pos().x(), e->pos().y(), e->pos().x(), e->pos().y());
linkLine->show();
}
}
break;
case Type_is_KDGanttTaskLink:
currentLink = getLink(*it);
break;
default:
break;
}
break;
case TQt::RightButton:
switch (getType(*it)) {
case Type_is_KDGanttViewItem:
currentItem = getItem(*it);
if (! currentItem->enabled() )
currentItem = 0;
break;
case Type_is_KDGanttTaskLink:
currentLink = getLink(*it);
break;
}
break;
case TQt::MidButton:
switch (getType(*it)) {
case Type_is_KDGanttViewItem:
currentItem = getItem(*it);
if (! currentItem->enabled() )
currentItem = 0;
break;
case Type_is_KDGanttTaskLink:
currentLink = getLink(*it);
break;
}
break;
default:
break;
}
}
if (e->button() == TQt::RightButton ) {
mySignalSender->gvContextMenuRequested( currentItem, e->globalPos() );
}
if (autoScrollEnabled && e->button() == TQt::LeftButton) {
myScrollTimer->start(50);
}
}
/**
Handles the mouseevent if a mousekey is released
\param e the mouseevent
*/
void KDGanttCanvasView::contentsMouseReleaseEvent ( TQMouseEvent * e )
{
static KDGanttViewItem* lastClicked = 0;
mySignalSender->gvMouseButtonClicked( e->button(), currentItem , e->globalPos() );
//tqDebug("datetime %s ",mySignalSender->getDateTimeForCoordX(e->globalPos().x(), true ).toString().latin1() );
//tqDebug("mousepos %d %d ",e->pos().x(),e->pos().y() );
//tqDebug("mouseup ");
// if ( currentLink || currentItem )
{
switch ( e->button() ) {
case TQt::LeftButton:
myScrollTimer->stop();
{
mySignalSender->itemLeftClicked( currentItem );
mySignalSender->gvItemLeftClicked( currentItem );
}
if ( currentLink )
mySignalSender->taskLinkLeftClicked( currentLink );
if (linkItemsEnabled && fromItem) {
linkLine->hide();
canvas()->update();
TQCanvasItemList il = canvas() ->collisions ( e->pos() );
TQCanvasItemList::Iterator it;
for ( it = il.begin(); it != il.end(); ++it ) {
if (getType(*it) == Type_is_KDGanttViewItem) {
KDGanttViewItem *toItem = getItem(*it);
if (!toItem->isMyTextCanvas(*it)) {
int toArea = getItemArea(toItem, e->pos().x());
if (toArea > 0 && toItem && fromItem != toItem) {
mySignalSender->linkItems(fromItem, toItem, getLinkType(fromArea, toArea));
}
}
break;
}
}
}
fromItem = 0;
break;
case TQt::RightButton:
{
mySignalSender->itemRightClicked( currentItem );
mySignalSender->gvItemRightClicked( currentItem );
}
if ( currentLink )
mySignalSender->taskLinkRightClicked( currentLink );
break;
case TQt::MidButton:
{
mySignalSender->itemMidClicked( currentItem );
mySignalSender->gvItemMidClicked( currentItem );
}
if ( currentLink )
mySignalSender->taskLinkRightClicked( currentLink );
break;
default:
break;
}
}
if ( lastClicked != currentItem )
mySignalSender->gvCurrentChanged( currentItem );
lastClicked = currentItem;
currentLink = 0;
currentItem = 0;
}
/**
Handles the mouseevent if a mousekey is doubleclicked
\param e the mouseevent
*/
void KDGanttCanvasView::contentsMouseDoubleClickEvent ( TQMouseEvent * e )
{
TQCanvasItemList il = canvas() ->collisions ( e->pos() );
TQCanvasItemList::Iterator it;
for ( it = il.begin(); it != il.end(); ++it ) {
switch ( e->button() ) {
case TQt::LeftButton:
switch (getType(*it)) {
case Type_is_KDGanttViewItem:
if ( getItem(*it)->enabled() )
mySignalSender->itemDoubleClicked(getItem(*it));
mySignalSender->gvItemDoubleClicked(getItem(*it));
return;
break;
case Type_is_KDGanttTaskLink:
mySignalSender->taskLinkDoubleClicked(getLink(*it));
return;
break;
default:
break;
}
break;
/*
case RightButton:
switch (getType(*it)) {
case Type_is_KDGanttViewItem:
mySignalSender->itemRightClicked(getItem(*it));
return;
break;
case Type_is_KDGanttTaskLink:
mySignalSender->taskLinkRightClicked(getLink(*it));
return;
break;
}
break;
case MidButton:
switch (getType(*it)) {
case Type_is_KDGanttViewItem:
mySignalSender->itemMidClicked(getItem(*it));
return;
break;
case Type_is_KDGanttTaskLink:
mySignalSender->taskLinkMidClicked(getLink(*it));
return;
break;
}
break;
*/
default:
break;
}
}
}
/**
Handles the mouseevent if a mousekey is pressed an the mouse is moved
\param e the mouseevent
*/
void KDGanttCanvasView::contentsMouseMoveEvent ( TQMouseEvent *e )
{
//tqDebug("mousemove! ");
static int moves = 0;
if ( (currentLink || currentItem) && (moves < 3) ) {
++moves;
} else {
moves = 0;
currentLink = 0;
currentItem = 0;
}
if (autoScrollEnabled)
mousePos = e->pos()- TQPoint(contentsX(),contentsY()); // make mousePos relative 0
if (fromItem) {
//tqDebug("mousemove: linking %s: %d,%d ",fromItem->listViewText().latin1(), e->pos().x(), e->pos().y());
linkLine->setPoints(linkLine->startPoint().x(), linkLine->startPoint().y(), e->pos().x(), e->pos().y());
canvas()->update();
}
// no action implemented
//tqDebug("mousemove ");
//TQToolTip::setGloballyEnabled (false);
//TQToolTip::remove(viewport());
// TQToolTip::add(viewport(), "hello");
// TQToolTip::setGloballyEnabled (true);
/*
TQCanvasItemList il = canvas() ->collisions ( e->pos() );
TQCanvasItemList::Iterator it;
KDGanttItem* mouseover = 0;
for ( it = il.begin(); it != il.end(); ++it ) {
}
*/
}
void KDGanttCanvasView::viewportPaintEvent ( TQPaintEvent * pe )
{
TQCanvasView::viewportPaintEvent ( pe );
}
void KDGanttCanvasView::set_Mouse_Tracking(bool on)
{
viewport()->setMouseTracking(on);
}
int KDGanttCanvasView::getType(TQCanvasItem* it)
{
switch (it->rtti()) {
case TQCanvasItem::Rtti_Line: return ((KDCanvasLine*)it)->myParentType;
case TQCanvasItem::Rtti_Ellipse: return ((KDCanvasEllipse *)it)->myParentType;
case TQCanvasItem::Rtti_Text: return ((KDCanvasText *)it)->myParentType;
case TQCanvasItem::Rtti_Polygon: return ((KDCanvasPolygon *)it)->myParentType;
case TQCanvasItem::Rtti_Rectangle: return ((KDCanvasRectangle *)it)->myParentType;
}
return -1;
}
KDGanttViewItem* KDGanttCanvasView::getItem(TQCanvasItem* it)
{
switch (it->rtti()) {
case TQCanvasItem::Rtti_Line: return (KDGanttViewItem*) ((KDCanvasLine*)it)->myParentItem;
case TQCanvasItem::Rtti_Ellipse: return (KDGanttViewItem*) ((KDCanvasEllipse *)it)->myParentItem;
case TQCanvasItem::Rtti_Text: return (KDGanttViewItem*) ((KDCanvasText *)it)->myParentItem;
case TQCanvasItem::Rtti_Polygon: return (KDGanttViewItem*) ((KDCanvasPolygon *)it)->myParentItem;
case TQCanvasItem::Rtti_Rectangle: return (KDGanttViewItem*) ((KDCanvasRectangle *)it)->myParentItem;
}
return 0;
}
KDGanttViewTaskLink* KDGanttCanvasView::getLink(TQCanvasItem* it)
{
switch (it->rtti()) {
case TQCanvasItem::Rtti_Line: return (KDGanttViewTaskLink*) ((KDCanvasLine*)it)->myParentItem;
case TQCanvasItem::Rtti_Ellipse: return (KDGanttViewTaskLink*) ((KDCanvasEllipse *)it)->myParentItem;
case TQCanvasItem::Rtti_Text: return (KDGanttViewTaskLink*) ((KDCanvasText *)it)->myParentItem;
case TQCanvasItem::Rtti_Polygon: return (KDGanttViewTaskLink*) ((KDCanvasPolygon *)it)->myParentItem;
}
return 0;
}
void KDGanttCanvasView::slotScrollTimer() {
int mx = mousePos.x();
int my = mousePos.y();
int dx = 0;
int dy = 0;
if (mx < 0)
dx = -5;
else if (mx > visibleWidth())
dx = 5;
if (my < 0)
dy = -5;
else if (my > visibleHeight())
dy = TQMIN(5, verticalScrollBar()->maxValue()-verticalScrollBar()->value());
if (dx != 0 || dy != 0)
scrollBy(dx, dy);
}
int KDGanttCanvasView::getItemArea(KDGanttViewItem *item, int x) {
// area can be: no area = 0, Start = 1, Finish = 2
// TODO: middle (move, dnd), front, back (resize)
KDTimeTableWidget *tt = dynamic_cast<KDTimeTableWidget *>(canvas());
if (!tt) {
tqWarning("Cannot cast canvas to KDTimeTableWidget");
return 0;
}
int area = 0;
int start = tt->getCoordX(item->startTime());
int end = start;
if (item->type() == KDGanttViewItem::Event) {
x > start ? area = 2 : area = 1;
} else {
end = tt->getCoordX(item->endTime());
if ((end - start)/2 > (x - start))
area = 1;
else
area = 2;
}
return area;
}
int KDGanttCanvasView::getLinkType(int from, int to) {
// from, to should be Start = 1 or Finish = 2
if ((from == 1) && (to == 1)) {
return KDGanttViewTaskLink::StartStart;
}
if ((from == 1) && (to == 2)) {
return KDGanttViewTaskLink::StartFinish;
}
if ((from == 2) && (to == 1)) {
return KDGanttViewTaskLink::FinishStart;
}
if ((from == 2) && (to == 2)) {
return KDGanttViewTaskLink::FinishFinish;
}
return KDGanttViewTaskLink::None;
}
|