summaryrefslogtreecommitdiffstats
path: root/experimental/tqtinterface/qt4/src/kernel/tqlayout.cpp
blob: 9c3132a03649dd7757f13ced004552a72b5264cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
/****************************************************************************
**
** Implementation of tqlayout classes
**
** Created : 960416
**
** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
**
** This file is part of the kernel module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file.  Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/

#include "tqlayout.h"

#ifndef TQT_NO_LAYOUT

#include "tqapplication.h"
#include "tqwidget.h"
#include "tqmenubar.h"
#include "tqptrlist.h"
#include "tqsizepolicy.h"

#include "tqlayoutengine_p.h"

#ifdef USE_QT4

int menuBarHeightForWidth( QWidget *menubar_w, int w )
{
#ifndef TQT_NO_MENUBAR
    TQMenuBar *menubar = static_cast<TQMenuBar*>(TQT_TQWIDGET(menubar_w));
    if ( menubar && !menubar->isHidden() && !menubar->isTopLevel() )
	return menubar->heightForWidth( TQMAX(w, menubar->minimumWidth()) );
    else
#endif
	return 0;
}

TQLayout::TQLayout( QWidget *tqparent, int margin, int spacing, const char *name ) : QLayout( tqparent ), autoNewChild(false)
{
	setObjectName(QString::fromAscii(name));
	setMargin(margin);
	if (spacing < 0)
		setSpacing(margin);
	else
		setSpacing(spacing);
	if ( tqparent ) tqparent->installEventFilter( this );
	TQT_TQOBJECT_REQUIRED_INITIALIZATION(tqparent)
}

TQLayout::TQLayout( QLayout *parentLayout, int spacing, const char *name ) : QLayout(), autoNewChild(false)
{
	setObjectName(QString::fromAscii(name));
	setSpacing(spacing);
	if ( parentLayout ) parentLayout->addItem(this);
	if ( parentLayout ) parentLayout->installEventFilter( this );
	TQT_TQOBJECT_REQUIRED_INITIALIZATION(parentLayout)
}

TQLayout::TQLayout( int spacing, const char *name ) : QLayout(), autoNewChild(false)
{
	setObjectName(QString::fromAscii(name));
	setSpacing(spacing);
}

TQ_SPExpandData TQLayout::expandingDirections() const {
	return (Qt::Orientations)TQSizePolicy::BothDirections;
}

TQLayout *TQLayout::tqlayout() {
	return this;
}

TQSize TQLayout::tqsizeHint() const {
	return sizeHint();
}

TQSize TQLayout::tqminimumSize() const {
	return QLayout::minimumSize();
}

TQSize TQLayout::tqmaximumSize() const {
	return QLayout::maximumSize();
}

TQWidget *TQLayout::mainWidget() {
	return TQT_TQWIDGET(parentWidget());
}

void TQLayout::tqinvalidate() {
	QLayout::invalidate();
}

void TQLayout::invalidate() {
	tqinvalidate();
}

TQRect TQLayout::tqgeometry() const {
	return QLayout::geometry();
}

const char *TQLayout::tqname() const {
	if (dynamic_cast<const TQLayout*>(static_cast<const QLayout*>(static_cast<const QObject*>(this)))) {
		static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
		return static_object_name.ascii();
	}
	else {
		printf("[WARNING] Attempted to call TQLayout::tqname() on an object without a constructed TQLayout object or base object.  Returning \"\"\n\r");
		return "";
	}
}

const char *TQLayout::name() const {
	if (dynamic_cast<const TQLayout*>(static_cast<const QLayout*>(static_cast<const QObject*>(this)))) {
		static_object_name = TQT_OBJECT_NAME_HANDLER(objectName());
		return static_object_name.ascii();
	}
	else {
		printf("[WARNING] Attempted to call TQLayout::tqname() on an object without a constructed TQLayout object or base object.  Returning \"\"\n\r");
		return "";
	}
}

int TQLayout::tqalignment() const {
	return alignment();
}

TQWidget *TQLayout::mainWidget() const {
	return TQT_TQWIDGET(parentWidget());
}

void TQLayout::remove(QWidget *w) {
	removeWidget(w);
}

void TQLayout::add(QWidget *w) {
	addWidget(w);
}

void TQLayout::setResizeMode(SizeConstraint s) {
	setSizeConstraint(s);
}

void TQLayout::setResizeMode(ResizeMode s) {
	setResizeMode((SizeConstraint)s);
}

TQLayout::SizeConstraint TQLayout::resizeMode() const {
	return sizeConstraint();
}

TQLayout::ResizeMode TQLayout::tqresizeMode() const {
	return (ResizeMode)sizeConstraint();
}

void TQLayout::setAutoAdd(bool a) {
	autoNewChild = a;
}

bool TQLayout::autoAdd() const {
	return autoNewChild;
}

void TQLayout::tqsetAlignment( int a ) {
	return setAlignment((Qt::Alignment)a);
}

// Qt4 handler interface
bool TQLayout::eventFilter( QObject *q, QEvent *e ) {
	return eventFilter(static_cast<TQObject*>(q), static_cast<TQEvent*>(e));
}

bool TQLayout::event( QEvent *e ) {
	return event(static_cast<TQEvent*>(e));
}

void TQLayout::timerEvent(QTimerEvent *e) {
	timerEvent(static_cast<TQTimerEvent*>(e));
}

void TQLayout::childEvent(QChildEvent *e) {
	TQT_TQOBJECT_CHILDEVENT_CONDITIONAL childEvent(static_cast<TQChildEvent*>(e));
}

void TQLayout::customEvent(QEvent *e) {
	customEvent(static_cast<TQCustomEvent*>(e));
}

bool TQLayout::eventFilter( TQObject *o, TQEvent *e ) {
	TQ_UNUSED(o);

	if (e->type() == TQEvent::Resize) {
		activate();
		TQResizeEvent *r = (TQResizeEvent *)e;
		int mbh = 0;
#ifndef TQT_NO_MENUBAR
		mbh = menuBarHeightForWidth( menuBar(), r->size().width() );
#endif
// 		int b = marginImpl ? 0 : outsideBorder;
		int b = 0;
		setGeometry( TQRect( b, mbh + b, r->size().width() - 2 * b, r->size().height() - mbh - 2 * b ) );
	}

	else if (e->type() == TQEvent::ChildInserted) {
		if (autoNewChild) {
			QChildEvent *c = (QChildEvent *)e;
			if (c->child()->isWidgetType()) {
				QWidget *w = (QWidget *)c->child();
				if (!w->isWindow()) {
// #if !defined(QT_NO_MENUBAR) && !defined(QT_NO_TOOLBAR)
// 					if (qobject_cast<QMenuBar*>(w) && !qobject_cast<QToolBar*>(w->parentWidget())) {
// 						setMenuBar( (QMenuBar *)w );
// 						invalidate();
// 					} else
// #endif
// #ifndef QT_NO_SIZEGRIP
// 					if (qobject_cast<QSizeGrip*>(w) ) {
// 						//SizeGrip is handled by the dialog itself.
// 					} else
// #endif
// 						addItem(QLayoutPrivate::createWidgetItem(this, w));
						addWidget(w);
				}
			}
		}
	}
	else if (e->type() == TQEvent::LayoutHint) {
// 		d->d = false;
// 		if (parent()) {
// 			if (static_cast<QWidget *>(parent())->isVisible()) {
				activate();
// 			}
// 		}
	}
// 	return FALSE;
	return QLayout::eventFilter( o, e );
// 	return TQObject::eventFilter( o, e );
}

TQLayoutIterator TQLayout::iterator() {
	return TQLayoutIterator(this,true);
}

/*!
  \compat

    Sets this layout's parent widget to a fixed size with width \a w
    and height \a h, stopping the user from resizing it, and also
    prevents the layout from resizing it, even if the layout's size
    hint should change. Does nothing if this is not a top-level
    layout (i.e., if parent()->isWidgetType()).

    As a special case, if both \a w and \a h are 0, then the layout's
    current sizeHint() is used.

    Use \c setResizeMode(Fixed) to stop the widget from being resized
    by the user, while still allowing the layout to resize it when
    the sizeHint() changes.

    Use \c setResizeMode(FreeResize) to allow the user to resize the
    widget, while preventing the layout from resizing it.

*/
void TQLayout::freeze(int w, int h)
{
//    if (!isTopLevel())
//        return;
    if (w <= 0 || h <= 0) {
        QSize s = totalSizeHint();
        w = s.width();
        h = s.height();
    }
    setSizeConstraint(SetNoConstraint); // layout will not change min/max size
    QWidget *parent = parentWidget();
    if (parent)
        parent->setFixedSize(w, h);
}

// Use the TQt virtual functions, not the built in Qt ones...
// This requires that the base virtual Qt functions be reimplemented so as to point to the TQt virtual functions instead as shown below.
// This way, when Trinity overrides a TQt virtual function, the calling Qt code will blithely use the overriden TQt function instead.
QLayout *TQLayout::layout() {
	return tqlayout();
}

void TQLayout::setGeometry(const TQRect &r) {
	return QLayout::setGeometry(r);
}

TQRect TQLayout::alignmentRect( const TQRect& qr ) const {
	return TQT_TQRECT_OBJECT(QLayout::alignmentRect(qr));
}

void TQLayout::tqt_handle_qt_destroyed(QObject* obj) {
	emit destroyed(TQT_TQOBJECT(obj));
}

TQLayoutIterator::TQLayoutIterator(QLayout *i) : layout(static_cast<TQLayout*>(i)), index(0) {
}

TQLayoutIterator::TQLayoutIterator(QLayout *i, bool) : layout(static_cast<TQLayout*>(i)), index(0) {
}

TQLayoutItem *TQLayoutIterator::operator++() {
	return static_cast<TQLayoutItem*>(layout->itemAt(++index));
}

TQLayoutItem *TQLayoutIterator::current() {
	return static_cast<TQLayoutItem*>(layout->itemAt(index));
}

TQLayoutItem *TQLayoutIterator::takeCurrent() {
	return static_cast<TQLayoutItem*>(layout->takeAt(index));
}

void TQLayoutIterator::deleteCurrent() {
	delete layout->takeAt(index);
}

TQSpacerItem *TQLayoutItem::tqspacerItem()
{
	return static_cast<TQSpacerItem*>(QLayoutItem::spacerItem());
}

/*!
    This virtual function receives events to an object and should
    return TRUE if the event \a e was recognized and processed.

    The event() function can be reimplemented to customize the
    behavior of an object.

    \sa installEventFilter(), timerEvent(), TQApplication::sendEvent(),
    TQApplication::postEvent(), TQWidget::event()
*/

bool TQLayout::event( TQEvent *e )
{
#if defined(TQT_CHECK_NULL)
    if ( e == 0 )
	qWarning( "TQLayout::event: Null events are not permitted" );
#endif
//     if ( eventFilters ) {			// try filters
// 	if ( activate_filters(e) )		// stopped by a filter
// 	    return TRUE;
//     }
// 
    switch ( e->type() ) {
//     case TQEvent::Timer:
// 	timerEvent( (TQTimerEvent*)e );
// 	return TRUE;
// 
//     case TQEvent::DeferredDelete:
// 	delete this;
// 	return TRUE;
// 
//     default:
// 	if ( e->type() >= TQEvent::User ) {
// 	    customEvent( (TQCustomEvent*) e );
// 	    return TRUE;
// 	}
// 	break;
//     }

    case TQEvent::ChildInserted:
//     case TQEvent::ChildRemoved:		// Causes a recursion loop if uncommented
	childEvent( (TQChildEvent*)e );
	return TRUE;

    default:
	return QLayout::event(e);
    }

    return FALSE;
}

#if 0
void TQGridLayout::tqsetAlignment( int a )
{
	setAlignment((Qt::AlignmentFlag)a);
}
#endif

#if 0

// NOTE
// The following functions are cloned from TQWidget
// They are only required for TQLayout and TQGridLayout becase those classes do not inherit TQObject or TQWidget

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive mouse move events for the widget.

    If mouse tracking is switched off, mouse move events only occur if
    a mouse button is pressed while the mouse is being moved. If mouse
    tracking is switched on, mouse move events occur even if no mouse
    button is pressed.

    TQMouseEvent::pos() reports the position of the mouse cursor,
    relative to this widget. For press and release events, the
    position is usually the same as the position of the last mouse
    move event, but it might be different if the user's hand shakes.
    This is a feature of the underlying window system, not TQt.

    \sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(),
    mouseDoubleClickEvent(), event(), TQMouseEvent
*/

void TQLayout::mouseMoveEvent( TQMouseEvent * e)
{
    e->ignore();
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive mouse press events for the widget.

    If you create new widgets in the mousePressEvent() the
    mouseReleaseEvent() may not end up where you expect, depending on
    the underlying window system (or X11 window manager), the widgets'
    location and maybe more.

    The default implementation implements the closing of popup widgets
    when you click outside the window. For other widget types it does
    nothing.

    \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
    mouseMoveEvent(), event(), TQMouseEvent
*/

void TQLayout::mousePressEvent( TQMouseEvent * )
{
// 	TQT_TQWIDGET_CONST(this)->mousePressEvent(e);
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive mouse release events for the widget.

    \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
    mouseMoveEvent(), event(),  TQMouseEvent
*/

void TQLayout::mouseReleaseEvent( TQMouseEvent * e )
{
    e->ignore();
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive mouse double click events for the widget.

    The default implementation generates a normal mouse press event.

    Note that the widgets gets a mousePressEvent() and a
    mouseReleaseEvent() before the mouseDoubleClickEvent().

    \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
    event(), TQMouseEvent
*/

void TQLayout::mouseDoubleClickEvent( TQMouseEvent *e )
{
    mousePressEvent( e );			// try mouse press event
}

#ifndef TQT_NO_WHEELEVENT
/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive wheel events for the widget.

    If you reimplement this handler, it is very important that you
    \link TQWheelEvent ignore()\endlink the event if you do not handle
    it, so that the widget's tqparent can interpret it.

    The default implementation ignores the event.

    \sa TQWheelEvent::ignore(), TQWheelEvent::accept(), event(),
    TQWheelEvent
*/

void TQLayout::wheelEvent( TQWheelEvent *e )
{
    e->ignore();
}
#endif

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive tablet events for the widget.

    If you reimplement this handler, it is very important that you
    \link TQTabletEvent ignore()\endlink the event if you do not handle
    it, so that the widget's tqparent can interpret it.

    The default implementation ignores the event.

    \sa TQTabletEvent::ignore(), TQTabletEvent::accept(), event(),
    TQTabletEvent
*/

void TQLayout::tabletEvent( TQTabletEvent *e )
{
    e->ignore();
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive key press events for the widget.

    A widget must call setFocusPolicy() to accept focus initially and
    have focus in order to receive a key press event.

    If you reimplement this handler, it is very important that you
    explicitly \link TQKeyEvent::ignore() ignore\endlink the event
    if you do not understand it, so that the widget's tqparent can
    interpret it; otherwise, the event will be implicitly accepted.
    Although top-level widgets are able to choose whether to accept
    or ignore unknown events because they have no tqparent widgets that
    could otherwise handle them, it is good practice to explicitly
    ignore events to make widgets as reusable as possible.

    The default implementation closes popup widgets if the user
    presses <b>Esc</b>. Otherwise the event is ignored.

    \sa keyReleaseEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
    focusInEvent(), focusOutEvent(), event(), TQKeyEvent
*/

void TQLayout::keyPressEvent( TQKeyEvent * )
{
// 	TQT_TQWIDGET_CONST(this)->keyPressEvent(e);
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive key release events for the widget.

    A widget must \link setFocusPolicy() accept focus\endlink
    initially and \link hasFocus() have focus\endlink in order to
    receive a key release event.

    If you reimplement this handler, it is very important that you
    \link TQKeyEvent ignore()\endlink the release if you do not
    understand it, so that the widget's tqparent can interpret it.

    The default implementation ignores the event.

    \sa keyPressEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
    focusInEvent(), focusOutEvent(), event(), TQKeyEvent
*/

void TQLayout::keyReleaseEvent( TQKeyEvent *e )
{
    e->ignore();
}

/*!
    This event handler can be reimplemented in a subclass to receive
    keyboard focus events (focus received) for the widget.

    A widget normally must setFocusPolicy() to something other than
    \c NoFocus in order to receive focus events. (Note that the
    application programmer can call setFocus() on any widget, even
    those that do not normally accept focus.)

    The default implementation updates the widget (except for toplevel
    widgets that do not specify a focusPolicy() ). It also calls
    setMicroFocusHint(), hinting any system-specific input tools about
    the focus of the user's attention.

    \sa focusOutEvent(), setFocusPolicy(), keyPressEvent(),
    keyReleaseEvent(), event(), TQFocusEvent
*/

void TQLayout::focusInEvent( TQFocusEvent * )
{
// 	TQT_TQWIDGET_CONST(this)->focusInEvent(e);
}

/*!
    This event handler can be reimplemented in a subclass to receive
    keyboard focus events (focus lost) for the widget.

    A widget normally must setFocusPolicy() to something other than
    \c NoFocus in order to receive focus events. (Note that the
    application programmer can call setFocus() on any widget, even
    those that do not normally accept focus.)

    The default implementation updates the widget (except for toplevel
    widgets that do not specify a focusPolicy() ). It also calls
    setMicroFocusHint(), hinting any system-specific input tools about
    the focus of the user's attention.

    \sa focusInEvent(), setFocusPolicy(), keyPressEvent(),
    keyReleaseEvent(), event(), TQFocusEvent
*/

void TQLayout::focusOutEvent( TQFocusEvent * )
{
// 	TQT_TQWIDGET_CONST(this)->focusOutEvent(e);
}

/*!
    This event handler can be reimplemented in a subclass to receive
    widget enter events.

    An event is sent to the widget when the mouse cursor enters the
    widget.

    \sa leaveEvent(), mouseMoveEvent(), event()
*/

void TQLayout::enterEvent( TQEvent * )
{
}

/*!
    This event handler can be reimplemented in a subclass to receive
    widget leave events.

    A leave event is sent to the widget when the mouse cursor leaves
    the widget.

    \sa enterEvent(), mouseMoveEvent(), event()
*/

void TQLayout::leaveEvent( TQEvent * )
{
}

/*!
    This event handler can be reimplemented in a subclass to receive
    paint events.

    A paint event is a request to tqrepaint all or part of the widget.
    It can happen as a result of tqrepaint() or update(), or because the
    widget was obscured and has now been uncovered, or for many other
    reasons.

    Many widgets can simply tqrepaint their entire surface when asked
    to, but some slow widgets need to optimize by painting only the
    requested region: TQPaintEvent::region(). This speed optimization
    does not change the result, as painting is clipped to that region
    during event processing. TQListView and TQCanvas do this, for
    example.

    TQt also tries to speed up painting by merging multiple paint
    events into one. When update() is called several times or the
    window system sends several paint events, TQt merges these events
    into one event with a larger region (see TQRegion::unite()).
    tqrepaint() does not permit this optimization, so we suggest using
    update() when possible.

    When the paint event occurs, the update region has normally been
    erased, so that you're painting on the widget's background. There
    are a couple of exceptions and TQPaintEvent::erased() tells you
    whether the widget has been erased or not.

    The background can be set using setBackgroundMode(),
    setPaletteBackgroundColor() or setBackgroundPixmap(). The
    documentation for setBackgroundMode() elaborates on the
    background; we recommend reading it.

    \sa event(), tqrepaint(), update(), TQPainter, TQPixmap, TQPaintEvent
*/

void TQLayout::paintEvent( TQPaintEvent *e )
{
}


/*!
    This event handler can be reimplemented in a subclass to receive
    widget move events. When the widget receives this event, it is
    already at the new position.

    The old position is accessible through TQMoveEvent::oldPos().

    \sa resizeEvent(), event(), move(), TQMoveEvent
*/

void TQLayout::moveEvent( TQMoveEvent * )
{
}


/*!
    This event handler can be reimplemented in a subclass to receive
    widget resize events. When resizeEvent() is called, the widget
    already has its new tqgeometry. The old size is accessible through
    TQResizeEvent::oldSize().

    The widget will be erased and receive a paint event immediately
    after processing the resize event. No drawing need be (or should
    be) done inside this handler.

    Widgets that have been created with the \c WNoAutoErase flag
    will not be erased. Nevertheless, they will receive a paint event
    for their entire area afterwards. Again, no drawing needs to be
    done inside this handler.

    The default implementation calls updateMask() if the widget has
    \link TQLayout::setAutoMask() automatic masking\endlink enabled.

    \sa moveEvent(), event(), resize(), TQResizeEvent, paintEvent()
*/

void TQLayout::resizeEvent( TQResizeEvent * )
{
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive widget close events.

    The default implementation calls e->accept(), which hides this
    widget. See the \l TQCloseEvent documentation for more details.

    \sa event(), hide(), close(), TQCloseEvent
*/

void TQLayout::closeEvent( TQCloseEvent *e )
{
    e->accept();
}


/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive widget context menu events.

    The default implementation calls e->ignore(), which rejects the
    context event. See the \l TQContextMenuEvent documentation for
    more details.

    \sa event(), TQContextMenuEvent
*/

void TQLayout::contextMenuEvent( TQContextMenuEvent *e )
{
    e->ignore();
}


/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive Input Method composition events. This handler
    is called when the user begins entering text using an Input Method.

    The default implementation calls e->ignore(), which rejects the
    Input Method event. See the \l TQIMEvent documentation for more
    details.

    \sa event(), TQIMEvent
*/
void TQLayout::imStartEvent( TQIMEvent *e )
{
    e->ignore();
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive Input Method composition events. This handler
    is called when the user has entered some text using an Input Method.

    The default implementation calls e->ignore(), which rejects the
    Input Method event. See the \l TQIMEvent documentation for more
    details.

    \sa event(), TQIMEvent
*/
void TQLayout::imComposeEvent( TQIMEvent *e )
{
    e->ignore();
}


/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive Input Method composition events. This handler
    is called when the user has finished inputting text via an Input
    Method.

    The default implementation calls e->ignore(), which rejects the
    Input Method event. See the \l TQIMEvent documentation for more
    details.

    \sa event(), TQIMEvent
*/
void TQLayout::imEndEvent( TQIMEvent *e )
{
    e->ignore();
}


#ifndef TQT_NO_DRAGANDDROP

/*!
    This event handler is called when a drag is in progress and the
    mouse enters this widget.

    See the \link dnd.html Drag-and-drop documentation\endlink for an
    overview of how to provide drag-and-drop in your application.

    \sa TQTextDrag, TQImageDrag, TQDragEnterEvent
*/
void TQLayout::dragEnterEvent( TQDragEnterEvent * )
{
}

/*!
    This event handler is called when a drag is in progress and the
    mouse enters this widget, and whenever it moves within the widget.

    See the \link dnd.html Drag-and-drop documentation\endlink for an
    overview of how to provide drag-and-drop in your application.

    \sa TQTextDrag, TQImageDrag, TQDragMoveEvent
*/
void TQLayout::dragMoveEvent( TQDragMoveEvent * )
{
}

/*!
    This event handler is called when a drag is in progress and the
    mouse leaves this widget.

    See the \link dnd.html Drag-and-drop documentation\endlink for an
    overview of how to provide drag-and-drop in your application.

    \sa TQTextDrag, TQImageDrag, TQDragLeaveEvent
*/
void TQLayout::dragLeaveEvent( TQDragLeaveEvent * )
{
}

/*!
    This event handler is called when the drag is dropped on this
    widget.

    See the \link dnd.html Drag-and-drop documentation\endlink for an
    overview of how to provide drag-and-drop in your application.

    \sa TQTextDrag, TQImageDrag, TQDropEvent
*/
void TQLayout::dropEvent( TQDropEvent * )
{
}

#endif // TQT_NO_DRAGANDDROP

/*!
    This event handler can be reimplemented in a subclass to receive
    widget show events.

    Non-spontaneous show events are sent to widgets immediately before
    they are shown. The spontaneous show events of top-level widgets
    are delivered afterwards.

    \sa event(), TQShowEvent
*/
void TQLayout::showEvent( TQShowEvent * )
{
}

/*!
    This event handler can be reimplemented in a subclass to receive
    widget hide events.

    Hide events are sent to widgets immediately after they have been
    hidden.

    \sa event(), TQHideEvent
*/
void TQLayout::hideEvent( TQHideEvent * )
{
}

#endif

void TQLayout::timerEvent( TQTimerEvent * )
{
}

void TQLayout::childEvent( TQChildEvent * )
{
}

void TQLayout::customEvent( TQCustomEvent * )
{
}

#if 0

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive mouse move events for the widget.

    If mouse tracking is switched off, mouse move events only occur if
    a mouse button is pressed while the mouse is being moved. If mouse
    tracking is switched on, mouse move events occur even if no mouse
    button is pressed.

    TQMouseEvent::pos() reports the position of the mouse cursor,
    relative to this widget. For press and release events, the
    position is usually the same as the position of the last mouse
    move event, but it might be different if the user's hand shakes.
    This is a feature of the underlying window system, not TQt.

    \sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(),
    mouseDoubleClickEvent(), event(), TQMouseEvent
*/

void TQGridLayout::mouseMoveEvent( TQMouseEvent * e)
{
    e->ignore();
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive mouse press events for the widget.

    If you create new widgets in the mousePressEvent() the
    mouseReleaseEvent() may not end up where you expect, depending on
    the underlying window system (or X11 window manager), the widgets'
    location and maybe more.

    The default implementation implements the closing of popup widgets
    when you click outside the window. For other widget types it does
    nothing.

    \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
    mouseMoveEvent(), event(), TQMouseEvent
*/

void TQGridLayout::mousePressEvent( TQMouseEvent * )
{
// 	TQT_TQLAYOUT_CONST(this)->mousePressEvent(e);
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive mouse release events for the widget.

    \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
    mouseMoveEvent(), event(),  TQMouseEvent
*/

void TQGridLayout::mouseReleaseEvent( TQMouseEvent * e )
{
    e->ignore();
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive mouse double click events for the widget.

    The default implementation generates a normal mouse press event.

    Note that the widgets gets a mousePressEvent() and a
    mouseReleaseEvent() before the mouseDoubleClickEvent().

    \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
    event(), TQMouseEvent
*/

void TQGridLayout::mouseDoubleClickEvent( TQMouseEvent *e )
{
    mousePressEvent( e );			// try mouse press event
}

#ifndef TQT_NO_WHEELEVENT
/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive wheel events for the widget.

    If you reimplement this handler, it is very important that you
    \link TQWheelEvent ignore()\endlink the event if you do not handle
    it, so that the widget's tqparent can interpret it.

    The default implementation ignores the event.

    \sa TQWheelEvent::ignore(), TQWheelEvent::accept(), event(),
    TQWheelEvent
*/

void TQGridLayout::wheelEvent( TQWheelEvent *e )
{
    e->ignore();
}
#endif

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive tablet events for the widget.

    If you reimplement this handler, it is very important that you
    \link TQTabletEvent ignore()\endlink the event if you do not handle
    it, so that the widget's tqparent can interpret it.

    The default implementation ignores the event.

    \sa TQTabletEvent::ignore(), TQTabletEvent::accept(), event(),
    TQTabletEvent
*/

void TQGridLayout::tabletEvent( TQTabletEvent *e )
{
    e->ignore();
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive key press events for the widget.

    A widget must call setFocusPolicy() to accept focus initially and
    have focus in order to receive a key press event.

    If you reimplement this handler, it is very important that you
    explicitly \link TQKeyEvent::ignore() ignore\endlink the event
    if you do not understand it, so that the widget's tqparent can
    interpret it; otherwise, the event will be implicitly accepted.
    Although top-level widgets are able to choose whether to accept
    or ignore unknown events because they have no tqparent widgets that
    could otherwise handle them, it is good practice to explicitly
    ignore events to make widgets as reusable as possible.

    The default implementation closes popup widgets if the user
    presses <b>Esc</b>. Otherwise the event is ignored.

    \sa keyReleaseEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
    focusInEvent(), focusOutEvent(), event(), TQKeyEvent
*/

void TQGridLayout::keyPressEvent( TQKeyEvent * )
{
// 	TQT_TQLAYOUT_CONST(this)->keyPressEvent(e);
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive key release events for the widget.

    A widget must \link setFocusPolicy() accept focus\endlink
    initially and \link hasFocus() have focus\endlink in order to
    receive a key release event.

    If you reimplement this handler, it is very important that you
    \link TQKeyEvent ignore()\endlink the release if you do not
    understand it, so that the widget's tqparent can interpret it.

    The default implementation ignores the event.

    \sa keyPressEvent(), TQKeyEvent::ignore(), setFocusPolicy(),
    focusInEvent(), focusOutEvent(), event(), TQKeyEvent
*/

void TQGridLayout::keyReleaseEvent( TQKeyEvent *e )
{
    e->ignore();
}

/*!
    This event handler can be reimplemented in a subclass to receive
    keyboard focus events (focus received) for the widget.

    A widget normally must setFocusPolicy() to something other than
    \c NoFocus in order to receive focus events. (Note that the
    application programmer can call setFocus() on any widget, even
    those that do not normally accept focus.)

    The default implementation updates the widget (except for toplevel
    widgets that do not specify a focusPolicy() ). It also calls
    setMicroFocusHint(), hinting any system-specific input tools about
    the focus of the user's attention.

    \sa focusOutEvent(), setFocusPolicy(), keyPressEvent(),
    keyReleaseEvent(), event(), TQFocusEvent
*/

void TQGridLayout::focusInEvent( TQFocusEvent * )
{
// 	TQT_TQLAYOUT_CONST(this)->focusInEvent(e);
}

/*!
    This event handler can be reimplemented in a subclass to receive
    keyboard focus events (focus lost) for the widget.

    A widget normally must setFocusPolicy() to something other than
    \c NoFocus in order to receive focus events. (Note that the
    application programmer can call setFocus() on any widget, even
    those that do not normally accept focus.)

    The default implementation updates the widget (except for toplevel
    widgets that do not specify a focusPolicy() ). It also calls
    setMicroFocusHint(), hinting any system-specific input tools about
    the focus of the user's attention.

    \sa focusInEvent(), setFocusPolicy(), keyPressEvent(),
    keyReleaseEvent(), event(), TQFocusEvent
*/

void TQGridLayout::focusOutEvent( TQFocusEvent * )
{
// 	TQT_TQLAYOUT_CONST(this)->focusOutEvent(e);
}

/*!
    This event handler can be reimplemented in a subclass to receive
    widget enter events.

    An event is sent to the widget when the mouse cursor enters the
    widget.

    \sa leaveEvent(), mouseMoveEvent(), event()
*/

void TQGridLayout::enterEvent( TQEvent * )
{
}

/*!
    This event handler can be reimplemented in a subclass to receive
    widget leave events.

    A leave event is sent to the widget when the mouse cursor leaves
    the widget.

    \sa enterEvent(), mouseMoveEvent(), event()
*/

void TQGridLayout::leaveEvent( TQEvent * )
{
}

/*!
    This event handler can be reimplemented in a subclass to receive
    paint events.

    A paint event is a request to tqrepaint all or part of the widget.
    It can happen as a result of tqrepaint() or update(), or because the
    widget was obscured and has now been uncovered, or for many other
    reasons.

    Many widgets can simply tqrepaint their entire surface when asked
    to, but some slow widgets need to optimize by painting only the
    requested region: TQPaintEvent::region(). This speed optimization
    does not change the result, as painting is clipped to that region
    during event processing. TQListView and TQCanvas do this, for
    example.

    TQt also tries to speed up painting by merging multiple paint
    events into one. When update() is called several times or the
    window system sends several paint events, TQt merges these events
    into one event with a larger region (see TQRegion::unite()).
    tqrepaint() does not permit this optimization, so we suggest using
    update() when possible.

    When the paint event occurs, the update region has normally been
    erased, so that you're painting on the widget's background. There
    are a couple of exceptions and TQPaintEvent::erased() tells you
    whether the widget has been erased or not.

    The background can be set using setBackgroundMode(),
    setPaletteBackgroundColor() or setBackgroundPixmap(). The
    documentation for setBackgroundMode() elaborates on the
    background; we recommend reading it.

    \sa event(), tqrepaint(), update(), TQPainter, TQPixmap, TQPaintEvent
*/

void TQGridLayout::paintEvent( TQPaintEvent *e )
{
// 	// At least let Qt4 get a shot at painting it
// 	QWidget::paintEvent(e);
}


/*!
    This event handler can be reimplemented in a subclass to receive
    widget move events. When the widget receives this event, it is
    already at the new position.

    The old position is accessible through TQMoveEvent::oldPos().

    \sa resizeEvent(), event(), move(), TQMoveEvent
*/

void TQGridLayout::moveEvent( TQMoveEvent * )
{
}


/*!
    This event handler can be reimplemented in a subclass to receive
    widget resize events. When resizeEvent() is called, the widget
    already has its new tqgeometry. The old size is accessible through
    TQResizeEvent::oldSize().

    The widget will be erased and receive a paint event immediately
    after processing the resize event. No drawing need be (or should
    be) done inside this handler.

    Widgets that have been created with the \c WNoAutoErase flag
    will not be erased. Nevertheless, they will receive a paint event
    for their entire area afterwards. Again, no drawing needs to be
    done inside this handler.

    The default implementation calls updateMask() if the widget has
    \link TQGridLayout::setAutoMask() automatic masking\endlink enabled.

    \sa moveEvent(), event(), resize(), TQResizeEvent, paintEvent()
*/

void TQGridLayout::resizeEvent( TQResizeEvent * )
{
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive widget close events.

    The default implementation calls e->accept(), which hides this
    widget. See the \l TQCloseEvent documentation for more details.

    \sa event(), hide(), close(), TQCloseEvent
*/

void TQGridLayout::closeEvent( TQCloseEvent *e )
{
    e->accept();
}


/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive widget context menu events.

    The default implementation calls e->ignore(), which rejects the
    context event. See the \l TQContextMenuEvent documentation for
    more details.

    \sa event(), TQContextMenuEvent
*/

void TQGridLayout::contextMenuEvent( TQContextMenuEvent *e )
{
    e->ignore();
}


/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive Input Method composition events. This handler
    is called when the user begins entering text using an Input Method.

    The default implementation calls e->ignore(), which rejects the
    Input Method event. See the \l TQIMEvent documentation for more
    details.

    \sa event(), TQIMEvent
*/
void TQGridLayout::imStartEvent( TQIMEvent *e )
{
    e->ignore();
}

/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive Input Method composition events. This handler
    is called when the user has entered some text using an Input Method.

    The default implementation calls e->ignore(), which rejects the
    Input Method event. See the \l TQIMEvent documentation for more
    details.

    \sa event(), TQIMEvent
*/
void TQGridLayout::imComposeEvent( TQIMEvent *e )
{
    e->ignore();
}


/*!
    This event handler, for event \a e, can be reimplemented in a
    subclass to receive Input Method composition events. This handler
    is called when the user has finished inputting text via an Input
    Method.

    The default implementation calls e->ignore(), which rejects the
    Input Method event. See the \l TQIMEvent documentation for more
    details.

    \sa event(), TQIMEvent
*/
void TQGridLayout::imEndEvent( TQIMEvent *e )
{
    e->ignore();
}


#ifndef TQT_NO_DRAGANDDROP

/*!
    This event handler is called when a drag is in progress and the
    mouse enters this widget.

    See the \link dnd.html Drag-and-drop documentation\endlink for an
    overview of how to provide drag-and-drop in your application.

    \sa TQTextDrag, TQImageDrag, TQDragEnterEvent
*/
void TQGridLayout::dragEnterEvent( TQDragEnterEvent * )
{
}

/*!
    This event handler is called when a drag is in progress and the
    mouse enters this widget, and whenever it moves within the widget.

    See the \link dnd.html Drag-and-drop documentation\endlink for an
    overview of how to provide drag-and-drop in your application.

    \sa TQTextDrag, TQImageDrag, TQDragMoveEvent
*/
void TQGridLayout::dragMoveEvent( TQDragMoveEvent * )
{
}

/*!
    This event handler is called when a drag is in progress and the
    mouse leaves this widget.

    See the \link dnd.html Drag-and-drop documentation\endlink for an
    overview of how to provide drag-and-drop in your application.

    \sa TQTextDrag, TQImageDrag, TQDragLeaveEvent
*/
void TQGridLayout::dragLeaveEvent( TQDragLeaveEvent * )
{
}

/*!
    This event handler is called when the drag is dropped on this
    widget.

    See the \link dnd.html Drag-and-drop documentation\endlink for an
    overview of how to provide drag-and-drop in your application.

    \sa TQTextDrag, TQImageDrag, TQDropEvent
*/
void TQGridLayout::dropEvent( TQDropEvent * )
{
}

#endif // TQT_NO_DRAGANDDROP

/*!
    This event handler can be reimplemented in a subclass to receive
    widget show events.

    Non-spontaneous show events are sent to widgets immediately before
    they are shown. The spontaneous show events of top-level widgets
    are delivered afterwards.

    \sa event(), TQShowEvent
*/
void TQGridLayout::showEvent( TQShowEvent * )
{
}

/*!
    This event handler can be reimplemented in a subclass to receive
    widget hide events.

    Hide events are sent to widgets immediately after they have been
    hidden.

    \sa event(), TQHideEvent
*/
void TQGridLayout::hideEvent( TQHideEvent * )
{
}

void TQGridLayout::timerEvent( TQTimerEvent * )
{
}

void TQGridLayout::childEvent( TQChildEvent * )
{
}

void TQGridLayout::customEvent( TQCustomEvent * )
{
}

#endif

TQMetaObject *TQLayout::tqmetaObject() const {
	return TQT_TQOBJECT_CONST(this)->tqmetaObject();
}

#else // USE_QT4

#endif // USE_QT4

/*
  Three internal classes related to TQGridLayout: (1) TQGridBox is a
  TQLayoutItem with (row, column) information; (2) TQGridMultiBox is a
  TQGridBox with (torow, tocolumn) information; (3) TQGridLayoutData is
  the internal representation of a TQGridLayout.
*/

class TQGridBox
{
public:
    TQGridBox( TQLayoutItem *lit ) { item_ = lit; }

    TQGridBox( TQWidget *wid ) { item_ = new TQWidgetItem( wid ); }
    TQGridBox( int w, int h, TQSizePolicy::SizeType hData = TQSizePolicy::Minimum,
	      TQSizePolicy::SizeType vData = TQSizePolicy::Minimum )
    { item_ = TQT_TQLAYOUTITEM(new TQSpacerItem( w, h, hData, vData )); }
    ~TQGridBox() { delete item_; }

    QSize tqsizeHint() const { return item_->sizeHint(); }
    QSize tqminimumSize() const { return item_->minimumSize(); }
    QSize tqmaximumSize() const { return item_->maximumSize(); }
    TQ_SPExpandData expandingDirections() const { return item_->expandingDirections(); }
    bool isEmpty() const { return item_->isEmpty(); }

    bool hasHeightForWidth() const { return item_->hasHeightForWidth(); }
    int heightForWidth( int w ) const { return item_->heightForWidth(w); }

    void tqsetAlignment( int a ) { item_->tqsetAlignment( a ); }
    void setGeometry( const TQRect &r ) { item_->setGeometry( r ); }
    int tqalignment() const { return item_->tqalignment(); }
    TQLayoutItem *item() { return item_; }
    TQLayoutItem *takeItem() { TQLayoutItem *i = item_; item_ = 0; return i; }

    int hStretch() { return item_->widget() ?
			 TQT_TQSIZEPOLICY_OBJECT(item_->widget()->sizePolicy()).horStretch() : 0; }
    int vStretch() { return item_->widget() ?
			 TQT_TQSIZEPOLICY_OBJECT(item_->widget()->sizePolicy()).verStretch() : 0; }

private:
    friend class TQGridLayoutData;
    friend class TQGridLayoutDataIterator;

    TQLayoutItem *item_;
    int row, col;
};

class TQGridMultiBox
{
public:
    TQGridMultiBox( TQGridBox *box, int toRow, int toCol )
	: box_( box ), torow( toRow ), tocol( toCol ) { }
    ~TQGridMultiBox() { delete box_; }
    TQGridBox *box() { return box_; }
    TQLayoutItem *takeItem() { return box_->takeItem(); }

private:
    friend class TQGridLayoutData;
    friend class TQGridLayoutDataIterator;

    TQGridBox *box_;
    int torow, tocol;
};

class TQGridLayoutData
{
public:
    TQGridLayoutData();
    TQGridLayoutData( int nRows, int nCols );
    ~TQGridLayoutData();

    void add( TQGridBox*, int row, int col );
    void add( TQGridBox*, int row1, int row2, int col1, int col2 );
    QSize tqsizeHint( int ) const;
    QSize tqminimumSize( int ) const;
    QSize tqmaximumSize( int ) const;

    TQ_SPExpandData expanding( int spacing );

    void distribute( TQRect, int );
    inline int numRows() const { return rr; }
    inline int numCols() const { return cc; }
    inline void expand( int rows, int cols )
    { setSize( TQMAX(rows, rr), TQMAX(cols, cc) ); }
    inline void setRowStretch( int r, int s )
    { expand( r + 1, 0 ); rStretch[r] = s; setDirty(); }
    inline void setColStretch( int c, int s )
    { expand( 0, c + 1 ); cStretch[c] = s; setDirty(); }
    inline int rowStretch( int r ) const { return rStretch[r]; }
    inline int colStretch( int c ) const { return cStretch[c]; }
    inline void setRowSpacing( int r, int s )
    { expand( r + 1, 0 ); rSpacing[r] = s; setDirty(); }
    inline void setColSpacing( int c, int s )
    { expand( 0, c + 1 ); cSpacing[c] = s; setDirty(); }
    inline int rowSpacing( int r ) const { return rSpacing[r]; }
    inline int colSpacing( int c ) const { return cSpacing[c]; }

    inline void setReversed( bool r, bool c ) { hReversed = c; vReversed = r; }
    inline bool horReversed() const { return hReversed; }
    inline bool verReversed() const { return vReversed; }
    inline void setDirty() { needRecalc = TRUE; hfw_width = -1; }
    inline bool isDirty() const { return needRecalc; }
    bool hasHeightForWidth( int space );
    int heightForWidth( int, int, int );
    int minimumHeightForWidth( int, int, int );

    bool findWidget( TQWidget* w, int *row, int *col );

    inline void getNextPos( int &row, int &col ) { row = nextR; col = nextC; }
    inline uint count() const
    { return things.count() + ( multi ? multi->count() : 0 ); }
    TQRect cellGeometry( int row, int col ) const;

private:
    void setNextPosAfter( int r, int c );
    void recalcHFW( int w, int s );
    void addHfwData ( TQGridBox *box, int width );
    void init();
    TQSize findSize( TQCOORD TQLayoutStruct::*, int ) const;
    void addData( TQGridBox *b, bool r = TRUE, bool c = TRUE );
    void setSize( int rows, int cols );
    void setupLayoutData( int space );
    void setupHfwLayoutData( int space );

    int rr;
    int cc;
    TQMemArray<TQLayoutStruct> rowData;
    TQMemArray<TQLayoutStruct> colData;
    TQMemArray<TQLayoutStruct> *hfwData;
    TQMemArray<int> rStretch;
    TQMemArray<int> cStretch;
    TQMemArray<int> rSpacing;
    TQMemArray<int> cSpacing;
    TQPtrList<TQGridBox> things;
    TQPtrList<TQGridMultiBox> *multi;

    int hfw_width;
    int hfw_height;
    int hfw_minheight;
    int nextR;
    int nextC;

    uint hReversed	: 1;
    uint vReversed	: 1;
    uint needRecalc	: 1;
    uint has_hfw	: 1;
    uint addVertical	: 1;

    friend class TQGridLayoutDataIterator;
};

TQGridLayoutData::TQGridLayoutData()
{
    init();
}

TQGridLayoutData::TQGridLayoutData( int nRows, int nCols )
    : rowData( 0 ), colData( 0 )
{
    init();
    if ( nRows  < 0 ) {
	nRows = 1;
	addVertical = FALSE;
    }
    if ( nCols  < 0 ) {
	nCols = 1;
	addVertical = TRUE;
    }
    setSize( nRows, nCols );
}

TQGridLayoutData::~TQGridLayoutData()
{
    // must be cleared while the data is still in a stable state
    things.clear();

    delete multi;
    delete hfwData;
}

void TQGridLayoutData::init()
{
    addVertical = FALSE;
    setDirty();
    multi = 0;
    rr = cc = 0;
    nextR = nextC = 0;
    hfwData = 0;
    things.setAutoDelete( TRUE );
    hReversed = FALSE;
    vReversed = FALSE;
}

bool TQGridLayoutData::hasHeightForWidth( int spacing )
{
    setupLayoutData( spacing );
    return has_hfw;
}

/*
  Assumes that setupLayoutData() has been called, and that
  qGeomCalc() has filled in colData with appropriate values.
*/
void TQGridLayoutData::recalcHFW( int w, int spacing )
{
    /*
      Go through all tqchildren, using colData and heightForWidth()
      and put the results in hfw_rowData.
    */
    if ( !hfwData )
	hfwData = new TQMemArray<TQLayoutStruct>( rr );
    setupHfwLayoutData( spacing );
    TQMemArray<TQLayoutStruct> &rData = *hfwData;

    int h = 0;
    int mh = 0;
    int n = 0;
    for ( int r = 0; r < rr; r++ ) {
	h += rData[r].tqsizeHint;
	mh += rData[r].tqminimumSize;
	if ( !rData[r].empty )
	    n++;
    }
    if ( n ) {
	h += ( n - 1 ) * spacing;
	mh += ( n - 1 ) * spacing;
    }

    hfw_width = w;
    hfw_height = TQMIN( TQLAYOUTSIZE_MAX, h );
    hfw_minheight = TQMIN( TQLAYOUTSIZE_MAX, mh );
}

int TQGridLayoutData::heightForWidth( int w, int margin, int spacing )
{
    setupLayoutData( spacing );
    if ( !has_hfw )
	return -1;
    if ( w + 2*margin != hfw_width ) {
	qGeomCalc( colData, 0, cc, 0, w+2*margin, spacing );
	recalcHFW( w+2*margin, spacing );
    }
    return hfw_height + 2*margin;
}

int TQGridLayoutData::minimumHeightForWidth( int w, int margin, int spacing )
{
    (void) heightForWidth( w, margin, spacing );
    return has_hfw ? (hfw_minheight + 2*margin) : -1;
}

bool TQGridLayoutData::findWidget( TQWidget* w, int *row, int *col )
{
    TQPtrListIterator<TQGridBox> it( things );
    TQGridBox * box;
    while ( (box = it.current()) != 0 ) {
	++it;
	if ( box->item()->widget() == w ) {
	    if ( row )
		*row = box->row;
	    if ( col )
		*col = box->col;
	    return TRUE;
	}
    }
    if ( multi ) {
	TQPtrListIterator<TQGridMultiBox> it( *multi );
	TQGridMultiBox * mbox;
	while ( (mbox = it.current()) != 0 ) {
	    ++it;
	    box = mbox->box();
	    if ( box->item()->widget() == w ) {
		if ( row )
		    *row = box->row;
		if ( col )
		    *col = box->col;
		return TRUE;
	    }

	}
    }
    return FALSE;
}

TQSize TQGridLayoutData::findSize( TQCOORD TQLayoutStruct::*size, int spacer ) const
{
    TQGridLayoutData *that = (TQGridLayoutData *)this;
    that->setupLayoutData( spacer );

    int w = 0;
    int h = 0;
    int n = 0;
    for ( int r = 0; r < rr; r++ ) {
	h = h + rowData[r].*size;
	if ( !rowData[r].empty )
	    n++;
    }
    if ( n )
	h += ( n - 1 ) * spacer;
    n = 0;
    for ( int c = 0; c < cc; c++ ) {
	w = w + colData[c].*size;
	if ( !colData[c].empty )
	    n++;
    }
    if ( n )
	w += ( n - 1 ) * spacer;
    w = TQMIN( TQLAYOUTSIZE_MAX, w );
    h = TQMIN( TQLAYOUTSIZE_MAX, h );

    return TQSize( w, h );
}

TQ_SPExpandData TQGridLayoutData::expanding( int spacing )
{
    setupLayoutData( spacing );
    int ret = 0;

    for ( int r = 0; r < rr; r++ ) {
	if ( rowData[r].expansive ) {
	    ret |= (int) TQSizePolicy::Vertically;
	    break;
	}
    }
    for ( int c = 0; c < cc; c++ ) {
	if ( colData[c].expansive ) {
	    ret |= (int) TQSizePolicy::Horizontally;
	    break;
	}
    }
    return (TQ_SPExpandData) ret;
}

QSize TQGridLayoutData::tqsizeHint( int spacer ) const
{
    return findSize( &TQLayoutStruct::tqsizeHint, spacer );
}

QSize TQGridLayoutData::tqmaximumSize( int spacer ) const
{
    return findSize( &TQLayoutStruct::tqmaximumSize, spacer );
}

QSize TQGridLayoutData::tqminimumSize( int spacer ) const
{
    return findSize( &TQLayoutStruct::tqminimumSize, spacer );
}

void TQGridLayoutData::setSize( int r, int c )
{
    if ( (int)rowData.size() < r ) {
	int newR = TQMAX( r, rr * 2 );
	rowData.resize( newR );
	rStretch.resize( newR );
	rSpacing.resize( newR );
	for ( int i = rr; i < newR; i++ ) {
	    rowData[i].init();
	    rStretch[i] = 0;
	    rSpacing[i] = 0;
	}
    }
    if ( (int)colData.size() < c ) {
	int newC = TQMAX( c, cc * 2 );
	colData.resize( newC );
	cStretch.resize( newC );
	cSpacing.resize( newC );
	for ( int i = cc; i < newC; i++ ) {
	    colData[i].init();
	    cStretch[i] = 0;
	    cSpacing[i] = 0;
	}
    }

    if ( hfwData && (int)hfwData->size() < r ) {
	delete hfwData;
	hfwData = 0;
	hfw_width = -1;
    }
    rr = r;
    cc = c;
}

void TQGridLayoutData::setNextPosAfter( int row, int col )
{
    if ( addVertical ) {
	if ( col > nextC || (col == nextC && row >= nextR) ) {
	    nextR = row + 1;
	    nextC = col;
	    if ( nextR >= rr ) {
		nextR = 0;
		nextC++;
	    }
	}
    } else {
	if ( row > nextR || (row == nextR && col >= nextC) ) {
	    nextR = row;
	    nextC = col + 1;
	    if ( nextC >= cc ) {
		nextC = 0;
		nextR++;
	    }
	}
    }
}

void TQGridLayoutData::add( TQGridBox *box, int row, int col )
{
    expand( row+1, col+1 );
    box->row = row;
    box->col = col;
    things.append( box );
    setDirty();
    setNextPosAfter( row, col );
}

void TQGridLayoutData::add( TQGridBox *box, int row1, int row2, int col1,
			   int col2  )
{
#ifdef TQT_CHECK_RANGE
    if ( row2 >= 0 && row2 < row1 )
	qWarning( "TQGridLayout: Multi-cell fromRow greater than toRow" );
    if ( col2 >= 0 && col2 < col1 )
	qWarning( "TQGridLayout: Multi-cell fromCol greater than toCol" );
#endif
    if ( row1 == row2 && col1 == col2 ) {
	add( box, row1, col1 );
	return;
    }
    expand( row2+1, col2+1 );
    box->row = row1;
    box->col = col1;
    TQGridMultiBox *mbox = new TQGridMultiBox( box, row2, col2 );
    if ( !multi ) {
	multi = new TQPtrList<TQGridMultiBox>;
	multi->setAutoDelete( TRUE );
    }
    multi->append( mbox );
    setDirty();
    if ( col2 < 0 )
	col2 = cc - 1;

    setNextPosAfter( row2, col2 );
}

void TQGridLayoutData::addData( TQGridBox *box, bool r, bool c )
{
    TQSize hint = box->tqsizeHint();
    TQSize minS = box->tqminimumSize();
    TQSize maxS = box->tqmaximumSize();

    if ( c ) {
	if ( !cStretch[box->col] )
	    colData[box->col].stretch = TQMAX( colData[box->col].stretch,
					      box->hStretch() );
	colData[box->col].tqsizeHint = TQMAX( hint.width(),
					   colData[box->col].tqsizeHint );
	colData[box->col].tqminimumSize = TQMAX( minS.width(),
					      colData[box->col].tqminimumSize );

	qMaxExpCalc( colData[box->col].tqmaximumSize, colData[box->col].expansive,
		     maxS.width(),
		     box->expandingDirections() & TQSizePolicy::Horizontally );
    }
    if ( r ) {
	if ( !rStretch[box->row] )
	    rowData[box->row].stretch = TQMAX( rowData[box->row].stretch,
					      box->vStretch() );
	rowData[box->row].tqsizeHint = TQMAX( hint.height(),
					   rowData[box->row].tqsizeHint );
	rowData[box->row].tqminimumSize = TQMAX( minS.height(),
					      rowData[box->row].tqminimumSize );

	qMaxExpCalc( rowData[box->row].tqmaximumSize, rowData[box->row].expansive,
		     maxS.height(),
		     box->expandingDirections() & TQSizePolicy::Vertically );
    }
    if ( box->isEmpty() ) {
	if ( box->item()->widget() != 0 ) {
	    /*
	      Hidden widgets should behave exactly the same as if
	      there were no widgets at all in the cell. We could have
	      TQWidgetItem::tqmaximumSize() to return
	      TQSize(TQLAYOUTSIZE_MAX, TQLAYOUTSIZE_MAX). However, that
	      value is not suitable for TQBoxLayouts. So let's fix it
	      here.
	    */
	    if ( c )
		colData[box->col].tqmaximumSize = TQLAYOUTSIZE_MAX;
	    if ( r )
		rowData[box->row].tqmaximumSize = TQLAYOUTSIZE_MAX;
	}
    } else {
	// Empty boxes (i.e. spacers) do not get borders. This is
	// hacky, but compatible.
	if ( c )
	    colData[box->col].empty = FALSE;
	if ( r )
	    rowData[box->row].empty = FALSE;
    }
}

static void distributeMultiBox( TQMemArray<TQLayoutStruct> &chain, int spacing,
				int start, int end,
				int minSize, int tqsizeHint,
				TQMemArray<int> &stretchArray, int stretch )
{
    int i;
    int w = 0;
    int wh = 0;
    int max = 0;
    for ( i = start; i <= end; i++ ) {
	w += chain[i].tqminimumSize;
	wh += chain[i].tqsizeHint;
	max += chain[i].tqmaximumSize;
	chain[i].empty = FALSE;
	if ( stretchArray[i] == 0 )
	    chain[i].stretch = TQMAX(chain[i].stretch,stretch);
    }
    w += spacing * ( end - start );
    wh += spacing * ( end - start );
    max += spacing * ( end - start );

    if ( max < minSize ) { // implies w < minSize
	/*
	  We must increase the maximum size of at least one of the
	  items. qGeomCalc() will put the extra space in between the
	  items. We must recover that extra space and put it
	  somewhere. It does not really matter where, since the user
	  can always specify stretch factors and avoid this code.
	*/
	qGeomCalc( chain, start, end - start + 1, 0, minSize, spacing );
	int pos = 0;
	for ( i = start; i <= end; i++ ) {
	    int nextPos = ( i == end ) ? minSize - 1 : chain[i + 1].pos;
	    int realSize = nextPos - pos;
	    if ( i != end )
		realSize -= spacing;
	    if ( chain[i].tqminimumSize < realSize )
		chain[i].tqminimumSize = realSize;
	    if ( chain[i].tqmaximumSize < chain[i].tqminimumSize )
		chain[i].tqmaximumSize = chain[i].tqminimumSize;
	    pos = nextPos;
	}
    } else if ( w < minSize ) {
	qGeomCalc( chain, start, end - start + 1, 0, minSize, spacing );
	for ( i = start; i <= end; i++ ) {
	    if ( chain[i].tqminimumSize < chain[i].size )
		chain[i].tqminimumSize = chain[i].size;
	}
    }

    if ( wh < tqsizeHint ) {
	qGeomCalc( chain, start, end - start + 1, 0, tqsizeHint, spacing );
	for ( i = start; i <= end; i++ ) {
	    if ( chain[i].tqsizeHint < chain[i].size )
		chain[i].tqsizeHint = chain[i].size;
	}
    }
}

//#define TQT_LAYOUT_DISABLE_CACHING

void TQGridLayoutData::setupLayoutData( int spacing )
{
#ifndef TQT_LAYOUT_DISABLE_CACHING
    if ( !needRecalc )
	return;
#endif
    has_hfw = FALSE;
    int i;

    for ( i = 0; i < rr; i++ )
	rowData[i].init( rStretch[i], rSpacing[i] );
    for ( i = 0; i < cc; i++ )
	colData[i].init( cStretch[i], cSpacing[i] );

    TQPtrListIterator<TQGridBox> it( things );
    TQGridBox * box;
    while ( (box = it.current()) != 0 ) {
	++it;
	addData( box );
	has_hfw = has_hfw || box->item()->hasHeightForWidth();
    }

    if ( multi ) {
	TQPtrListIterator<TQGridMultiBox> it( *multi );
	TQGridMultiBox * mbox;
	while ( (mbox = it.current()) != 0 ) {
	    ++it;
	    TQGridBox *box = mbox->box();
	    int r1 = box->row;
	    int c1 = box->col;
	    int r2 = mbox->torow;
	    int c2 = mbox->tocol;
	    if ( r2 < 0 )
		r2 = rr - 1;
	    if ( c2 < 0 )
		c2 = cc - 1;

	    TQSize hint = box->tqsizeHint();
	    TQSize min = box->tqminimumSize();
	    if ( box->hasHeightForWidth() )
		has_hfw = TRUE;

	    if ( r1 == r2 ) {
		addData( box, TRUE, FALSE );
	    } else {
		distributeMultiBox( rowData, spacing, r1, r2,
				    min.height(), hint.height(),
				    rStretch, box->vStretch() );
	    }
	    if ( c1 == c2 ) {
		addData( box, FALSE, TRUE );
	    } else {
		distributeMultiBox( colData, spacing, c1, c2,
				    min.width(), hint.width(),
				    cStretch, box->hStretch() );
	    }
	}
    }
    for ( i = 0; i < rr; i++ )
	rowData[i].expansive = rowData[i].expansive || rowData[i].stretch > 0;
    for ( i = 0; i < cc; i++ )
	colData[i].expansive = colData[i].expansive || colData[i].stretch > 0;

    needRecalc = FALSE;
}

void TQGridLayoutData::addHfwData( TQGridBox *box, int width )
{
    TQMemArray<TQLayoutStruct> &rData = *hfwData;
    if ( box->hasHeightForWidth() ) {
	int hint = box->heightForWidth( width );
	rData[box->row].tqsizeHint = TQMAX( hint, rData[box->row].tqsizeHint );
	rData[box->row].tqminimumSize = TQMAX( hint, rData[box->row].tqminimumSize );
    } else {
	TQSize hint = box->tqsizeHint();
	TQSize minS = box->tqminimumSize();
	rData[box->row].tqsizeHint = TQMAX( hint.height(),
					 rData[box->row].tqsizeHint );
	rData[box->row].tqminimumSize = TQMAX( minS.height(),
					    rData[box->row].tqminimumSize );
    }
}

/*
  Similar to setupLayoutData(), but uses heightForWidth(colData)
  instead of tqsizeHint(). Assumes that setupLayoutData() and
  qGeomCalc(colData) has been called.
*/
void TQGridLayoutData::setupHfwLayoutData( int spacing )
{
    TQMemArray<TQLayoutStruct> &rData = *hfwData;
    int i;
    for ( i = 0; i < rr; i++ ) {
	rData[i] = rowData[i];
	rData[i].tqminimumSize = rData[i].tqsizeHint = 0;
    }
    TQPtrListIterator<TQGridBox> it( things );
    TQGridBox * box;
    while ( (box=it.current()) != 0 ) {
	++it;
	addHfwData( box, colData[box->col].size );
    }
    if ( multi ) {
	TQPtrListIterator<TQGridMultiBox> it( *multi );
	TQGridMultiBox * mbox;
	while ( (mbox=it.current()) != 0 ) {
	    ++it;
	    TQGridBox *box = mbox->box();
	    int r1 = box->row;
	    int c1 = box->col;
	    int r2 = mbox->torow;
	    int c2 = mbox->tocol;
	    if ( r2 < 0 )
		r2 = rr-1;
	    if ( c2 < 0 )
		c2 = cc-1;
	    int w = colData[c2].pos + colData[c2].size - colData[c1].pos;
	    if ( r1 == r2 ) {
		addHfwData( box, w );
	    } else {
		TQSize hint = box->tqsizeHint();
		TQSize min = box->tqminimumSize();
		if ( box->hasHeightForWidth() ) {
		    int hfwh = box->heightForWidth( w );
		    if ( hfwh > hint.height() )
			hint.setHeight( hfwh );
		    if ( hfwh > min.height() )
			min.setHeight( hfwh );
		}
		distributeMultiBox( rData, spacing, r1, r2,
				    min.height(), hint.height(),
				    rStretch, box->vStretch() );
	    }
	}
    }
    for ( i = 0; i < rr; i++ )
	rData[i].expansive = rData[i].expansive || rData[i].stretch > 0;
}

void TQGridLayoutData::distribute( TQRect r, int spacing )
{
    bool visualHReversed = hReversed;
    if ( TQApplication::reverseLayout() )
	visualHReversed = !visualHReversed;

    setupLayoutData( spacing );

    qGeomCalc( colData, 0, cc, r.x(), r.width(), spacing );
    TQMemArray<TQLayoutStruct> *rDataPtr;
    if ( has_hfw ) {
	recalcHFW( r.width(), spacing );
	qGeomCalc( *hfwData, 0, rr, r.y(), r.height(), spacing );
	rDataPtr = hfwData;
    } else {
	qGeomCalc( rowData, 0, rr, r.y(), r.height(), spacing );
	rDataPtr = &rowData;
    }
    TQMemArray<TQLayoutStruct> &rData = *rDataPtr;

    TQPtrListIterator<TQGridBox> it( things );
    TQGridBox * box;
    while ( (box=it.current()) != 0 ) {
	++it;
	int x = colData[box->col].pos;
	int y = rData[box->row].pos;
	int w = colData[box->col].size;
	int h = rData[box->row].size;
	if ( visualHReversed )
	    x = r.left() + r.right() - x - w + 1;
	if ( vReversed )
	    y = r.top() + r.bottom() - y - h + 1;
	box->setGeometry( TQRect( x, y, w, h ) );
    }
    if ( multi ) {
	TQPtrListIterator<TQGridMultiBox> it( *multi );
	TQGridMultiBox * mbox;
	while ( (mbox=it.current()) != 0 ) {
	    ++it;
	    TQGridBox *box = mbox->box();
	    int r2 = mbox->torow;
	    int c2 = mbox->tocol;
	    if ( r2 < 0 )
		r2 = rr-1;
	    if ( c2 < 0 )
		c2 = cc-1;

	    int x = colData[box->col].pos;
	    int y = rData[box->row].pos;
	    int x2p = colData[c2].pos + colData[c2].size; // x2+1
	    int y2p = rData[r2].pos + rData[r2].size;    // y2+1
	    int w = x2p - x;
	    int h = y2p - y;
	    // this code is copied from above:
	    if ( visualHReversed )
		x = r.left() + r.right() - x - w + 1;
	    if ( vReversed )
		y = r.top() + r.bottom() - y - h + 1;
	    box->setGeometry( TQRect( x, y, w, h ) );
	}
    }
}

TQRect TQGridLayoutData::cellGeometry( int row, int col ) const
{
    if ( row < 0 || row >= rr || col < 0 || col >= cc )
	return TQRect();

    const TQMemArray<TQLayoutStruct> *rDataPtr;
    if ( has_hfw )
	rDataPtr = hfwData;
    else
	rDataPtr = &rowData;
    return TQRect( colData[col].pos, (*rDataPtr)[row].pos,
		  colData[col].size, (*rDataPtr)[row].size );
}

class TQGridLayoutDataIterator : public TQGLayoutIterator
{
public:
    TQGridLayoutDataIterator( TQGridLayoutData *d );
    uint count() const { return data->count(); }
    TQLayoutItem *current() {
	if ( multi ) {
	    if ( !data->multi || idx >= (int)data->multi->count() )
		return 0;
	    return data->multi->at( idx )->box()->item();
	} else {
	    if ( idx >= (int)data->things.count() )
		return 0;
	    return data->things.at( idx )->item();
	}
    }
    void toFirst() {
	multi = data->things.isEmpty();
	idx = 0;
    }
    TQLayoutItem *next() {
	idx++;
	if ( !multi && idx >= (int)data->things.count() ) {
	    multi = TRUE;
	    idx = 0;
	}
	return current();
    }
    TQLayoutItem *takeCurrent() {
	TQLayoutItem *item = 0;
	if ( multi ) {
	     if ( !data->multi || idx >= (int)data->multi->count() )
		return 0;
	    TQGridMultiBox *b = data->multi->take( idx );
	    item = b->takeItem();
	    delete b;
	} else {
	    if ( idx >= (int)data->things.count() )
		return 0;
	    TQGridBox *b = data->things.take( idx );
	    item = b->takeItem();
	    delete b;
	}
	return item;
    }

private:
    TQGridLayoutData *data;
    bool multi;
    int idx;
};

inline TQGridLayoutDataIterator::TQGridLayoutDataIterator( TQGridLayoutData *d )
    : data( d )
{
    toFirst();
}

/*!
    \class TQGridLayout

    \brief The TQGridLayout class lays out widgets in a grid.

    \ingroup geomanagement
    \ingroup appearance
    \mainclass

    TQGridLayout takes the space made available to it (by its tqparent
    tqlayout or by the mainWidget()), divides it up into rows and
    columns, and puts each widget it manages into the correct cell.

    Columns and rows behave identically; we will discuss columns, but
    there are equivalent functions for rows.

    Each column has a minimum width and a stretch factor. The minimum
    width is the greatest of that set using addColSpacing() and the
    minimum width of each widget in that column. The stretch factor is
    set using setColStretch() and determines how much of the available
    space the column will get over and above its necessary minimum.

    Normally, each managed widget or tqlayout is put into a cell of its
    own using addWidget(), addLayout() or by the \link
    TQLayout::setAutoAdd() auto-add facility\endlink. It is also
    possible for a widget to occupy multiple cells using
    addMultiCellWidget(). If you do this, TQGridLayout will guess how
    to distribute the size over the columns/rows (based on the stretch
    factors).

    To remove a widget from a tqlayout, call remove(). Calling
    TQWidget::hide() on a widget also effectively removes the widget
    from the tqlayout until TQWidget::show() is called.

    This illustration shows a fragment of a dialog with a five-column,
    three-row grid (the grid is shown overlaid in magenta):

    \img gridtqlayout.png

    Columns 0, 2 and 4 in this dialog fragment are made up of a
    TQLabel, a TQLineEdit, and a TQListBox. Columns 1 and 3 are
    placeholders made with addColSpacing(). Row 0 consists of three
    TQLabel objects, row 1 of three TQLineEdit objects and row 2 of
    three TQListBox objects. We used placeholder columns (1 and 3) to
    get the right amount of space between the columns.

    Note that the columns and rows are not equally wide or tall. If
    you want two columns to have the same width, you must set their
    minimum widths and stretch factors to be the same yourself. You do
    this using addColSpacing() and setColStretch().

    If the TQGridLayout is not the top-level tqlayout (i.e. does not
    manage all of the widget's area and tqchildren), you must add it to
    its tqparent tqlayout when you create it, but before you do anything
    with it. The normal way to add a tqlayout is by calling
    parentLayout-\>addLayout().

    Once you have added your tqlayout you can start putting widgets and
    other layouts into the cells of your grid tqlayout using
    addWidget(), addLayout() and addMultiCellWidget().

    TQGridLayout also includes two margin widths: the border and the
    spacing. The border is the width of the reserved space along each
    of the TQGridLayout's four sides. The spacing is the width of the
    automatically allocated spacing between neighboring boxes.

    Both the border and the spacing are parameters of the constructor
    and default to 0.

    \sa TQGrid, \link tqlayout.html Layout Overview \endlink
*/

/*
  Returns TRUE if the widget \a w can be added to the tqlayout \a l;
  otherwise returns FALSE.
*/
static bool checkWidget( TQLayout *l, TQWidget *w )
{
    if ( !w ) {
#if defined(TQT_CHECK_STATE)
	qWarning( "TQLayout: Cannot add null widget to %s/%s", l->className(),
		  l->name() );
#endif
	return FALSE;
    }
    if ( w->parentWidget() != l->mainWidget() && l->mainWidget() ) {
#if defined(TQT_CHECK_STATE)
	if ( w->parentWidget() )
	    qWarning( "TQLayout: Adding %s/%s (child of %s/%s) to tqlayout for "
		      "%s/%s", w->className(), w->name(),
		      w->parentWidget()->className(), w->parentWidget()->name(),
		      l->mainWidget()->className(), l->mainWidget()->name() );
	else
	    qWarning( "TQLayout: Adding %s/%s (top-level widget) to tqlayout for"
		      " %s/%s", w->className(), w->name(),
		      l->mainWidget()->className(), l->mainWidget()->name() );
#endif
	return FALSE;
    }
    return TRUE;
}

// #ifdef USE_QT4
// 
// #else // USE_QT4

/*!
    \enum TQGridLayout::Corner

    This enum identifies which corner is the origin (0, 0) of the
    tqlayout.

    \value TopLeft the top-left corner
    \value TopRight the top-right corner
    \value BottomLeft the bottom-left corner
    \value BottomRight the bottom-right corner
*/

/*!
    Constructs a new TQGridLayout with \a nRows rows, \a nCols columns
    and tqparent widget, \a  tqparent. \a tqparent may not be 0. The grid
    tqlayout is called \a name.

    \a margin is the number of pixels between the edge of the widget
    and its managed tqchildren. \a space is the default number of pixels
    between cells. If \a space is -1, the value of \a margin is used.
*/
TQGridLayout::TQGridLayout( TQWidget *tqparent, int nRows, int nCols, int margin,
			  int space, const char *name )
    : TQLayout( tqparent, margin, space, name )
{
    init( nRows, nCols );
}

/*!
    Constructs a new grid that is placed inside \a parentLayout with
    \a nRows rows and \a nCols columns. If \a spacing is -1, this
    TQGridLayout inherits its tqparent's spacing(); otherwise \a spacing
    is used. The grid tqlayout is called \a name.

    This grid is placed according to \a parentLayout's default
    placement rules.
*/
TQGridLayout::TQGridLayout( TQLayout *parentLayout, int nRows, int nCols,
			  int spacing, const char *name )
    : TQLayout( parentLayout, spacing, name )
{
    init( nRows, nCols );
}

/*!
    Constructs a new grid with \a nRows rows and \a nCols columns. If
    \a spacing is -1, this TQGridLayout inherits its tqparent's
    spacing(); otherwise \a spacing is used. The grid tqlayout is called
    \a name.

    You must insert this grid into another tqlayout. You can insert
    widgets and layouts into this tqlayout at any time, but laying out
    will not be performed before this is inserted into another tqlayout.
*/
TQGridLayout::TQGridLayout( int nRows, int nCols,
			  int spacing, const char *name )
     : TQLayout( spacing, name )
{
    init( nRows, nCols );
}

/*!
    Destroys the grid tqlayout. Geometry management is terminated if
    this is a top-level grid.

    The tqlayout's widgets aren't destroyed.
*/
TQGridLayout::~TQGridLayout()
{
    delete data;
}

/*!
    Returns the number of rows in this grid.
*/
int TQGridLayout::numRows() const
{
    return data->numRows();
}

/*!
    Returns the number of columns in this grid.
*/
int TQGridLayout::numCols() const
{
    return data->numCols();
}

/*!
    Returns the preferred size of this grid.
*/
TQSize TQGridLayout::tqsizeHint() const
{
    return data->tqsizeHint( spacing() ) + TQSize( 2 * margin(), 2 * margin() );
}

/*!
    Returns the minimum size needed by this grid.
*/
TQSize TQGridLayout::tqminimumSize() const
{
    return data->tqminimumSize( spacing() ) + TQSize( 2 * margin(), 2 * margin() );
}

/*!
    Returns the maximum size needed by this grid.
*/
TQSize TQGridLayout::tqmaximumSize() const
{
    TQSize s = data->tqmaximumSize( spacing() ) +
	      TQSize( 2 * margin(), 2 * margin() );
    s = s.boundedTo( TQSize(TQLAYOUTSIZE_MAX, TQLAYOUTSIZE_MAX) );
    if ( tqalignment() & TQt::AlignHorizontal_Mask )
	s.setWidth( TQLAYOUTSIZE_MAX );
    if ( tqalignment() & TQt::AlignVertical_Mask )
	s.setHeight( TQLAYOUTSIZE_MAX );
    return s;
}

/*!
    Returns TRUE if this tqlayout's preferred height depends on its
    width; otherwise returns FALSE.
*/
bool TQGridLayout::hasHeightForWidth() const
{
    return ((TQGridLayout*)this)->data->hasHeightForWidth( spacing() );
}

/*!
    Returns the tqlayout's preferred height when it is \a w pixels wide.
*/
int TQGridLayout::heightForWidth( int w ) const
{
    TQGridLayout *that = (TQGridLayout*)this;
    return that->data->heightForWidth( w, margin(), spacing() );
}

/*! \internal */
int TQGridLayout::minimumHeightForWidth( int w ) const
{
    TQGridLayout *that = (TQGridLayout*)this;
    return that->data->minimumHeightForWidth( w, margin(), spacing() );
}

/*!
    Searches for widget \a w in this tqlayout (not including child
    layouts). If \a w is found, it sets \c \a row and \c \a col to
    the row and column and returns TRUE; otherwise returns FALSE.

    Note: if a widget spans multiple rows/columns, the top-left cell
    is returned.
*/
bool TQGridLayout::findWidget( TQWidget* w, int *row, int *col )
{
    return data->findWidget( w, row, col );
}

/*!
    Resizes managed widgets within the rectangle \a r.
*/
void TQGridLayout::setGeometry( const TQRect &r )
{
    if ( data->isDirty() || r != tqgeometry() ) {
	TQLayout::setGeometry( r );
	TQRect cr = tqalignment() ? alignmentRect( r ) : r;
	TQRect s( cr.x() + margin(), cr.y() + margin(),
		 cr.width() - 2 * margin(), cr.height() - 2 * margin() );
	data->distribute( s, spacing() );
    }
}

/*!
    Returns the tqgeometry of the cell with row \a row and column \a col
    in the grid. Returns an invalid rectangle if \a row or \a col is
    outside the grid.

    \warning in the current version of TQt this function does not
    return valid results until setGeometry() has been called, i.e.
    after the mainWidget() is visible.
*/
TQRect TQGridLayout::cellGeometry( int row, int col ) const
{
    return data->cellGeometry( row, col );
}

/*!
    Expands this grid so that it will have \a nRows rows and \a nCols
    columns. Will not shrink the grid. You should not need to call
    this function because TQGridLayout expands automatically as new
    items are inserted.
*/
void TQGridLayout::expand( int nRows, int nCols )
{
    data->expand( nRows, nCols );
}

/*!
    Sets up the grid.
*/
void TQGridLayout::init( int nRows, int nCols )
{
    setSupportsMargin( TRUE );
    data = new TQGridLayoutData( nRows, nCols );
}

/*!
    \overload

    Adds \a item to the next free position of this tqlayout.
*/
void TQGridLayout::addItem( QLayoutItem *item )
{
    int r, c;
    data->getNextPos( r, c );
    add( TQT_TQLAYOUTITEM(item), r, c );
}

/*!
    Adds \a item at position \a row, \a col. The tqlayout takes
    ownership of the \a item.
*/
void TQGridLayout::addItem( QLayoutItem *item, int row, int col )
{
    add( TQT_TQLAYOUTITEM(item), row, col );
}

/*!
    Adds \a item at position \a row, \a col. The tqlayout takes
    ownership of the \a item.
*/
void TQGridLayout::add( TQLayoutItem *item, int row, int col )
{
    TQGridBox *box = new TQGridBox( item );
    data->add( box, row, col );
}

/*!
    Adds the \a item to the cell grid, spanning multiple rows/columns.

    The cell will span from \a fromRow, \a fromCol to \a toRow, \a
    toCol. Alignment is specified by \a tqalignment, which is a bitwise
    OR of \l TQt::AlignmentFlags values. The default tqalignment is 0,
    which means that the widget fills the entire cell.
*/
void TQGridLayout::addMultiCell( QLayoutItem *item, int fromRow, int toRow,
				int fromCol, int toCol, int tqalignment )
{
    TQGridBox *b = new TQGridBox( TQT_TQLAYOUTITEM(item) );
    b->tqsetAlignment( tqalignment );
    data->add( b, fromRow, toRow, fromCol, toCol );
}

/*!
    Adds the widget \a w to the cell grid at \a row, \a col. The
    top-left position is (0, 0) by default.

    Alignment is specified by \a tqalignment, which is a bitwise OR of
    \l TQt::AlignmentFlags values. The default tqalignment is 0, which
    means that the widget fills the entire cell.

    \list
    \i You should not call this if you have enabled the
    \link TQLayout::setAutoAdd() auto-add facility of the tqlayout\endlink.

    \i From TQt 3.0, the \a tqalignment parameter is interpreted more
    aggressively than in previous versions of TQt. A non-default
    tqalignment now indicates that the widget should not grow to fill
    the available space, but should be sized according to tqsizeHint().
    \endlist

    \sa addMultiCellWidget()
*/
void TQGridLayout::addWidget( TQWidget *w, int row, int col, int tqalignment )
{
    if ( !checkWidget( this, w ) )
	return;
    if ( row < 0 || col < 0 ) {
#if defined(TQT_CHECK_STATE)
	qWarning( "TQGridLayout: Cannot add %s/%s to %s/%s at row %d col %d",
		  w->className(), w->name(), className(), name(), row, col );
#endif
	return;
    }
    TQWidgetItem *b = new TQWidgetItem( w );
    b->tqsetAlignment( tqalignment );
    add( b, row, col );
}

/*!
    Adds the widget \a w to the cell grid, spanning multiple
    rows/columns. The cell will span from \a fromRow, \a fromCol to \a
    toRow, \a toCol.

    Alignment is specified by \a tqalignment, which is a bitwise OR of
    \l TQt::AlignmentFlags values. The default tqalignment is 0, which
    means that the widget fills the entire cell.

    A non-zero tqalignment indicates that the widget should not grow to
    fill the available space but should be sized according to
    tqsizeHint().

    \sa addWidget()
*/
void TQGridLayout::addMultiCellWidget( TQWidget *w, int fromRow, int toRow,
				      int fromCol, int toCol, int tqalignment )
{
    TQGridBox *b = new TQGridBox( w );
    b->tqsetAlignment( tqalignment );
    data->add( b, fromRow, toRow, fromCol, toCol );
}

/*!
    Places the \a tqlayout at position (\a row, \a col) in the grid. The
    top-left position is (0, 0).

    \a tqlayout becomes a child of the grid tqlayout.

    When a tqlayout is constructed with another tqlayout as its tqparent,
    you don't need to call addLayout(); the child tqlayout is
    automatically added to the tqparent tqlayout as it is constructed.

    \sa addMultiCellLayout()
*/
void TQGridLayout::addLayout( TQLayout *tqlayout, int row, int col )
{
    addChildLayout( tqlayout );
    add( TQT_TQLAYOUTITEM(tqlayout), row, col );
}

/*!
    Adds the tqlayout \a tqlayout to the cell grid, spanning multiple
    rows/columns. The cell will span from \a fromRow, \a fromCol to \a
    toRow, \a toCol.

    Alignment is specified by \a tqalignment, which is a bitwise OR of
    \l TQt::AlignmentFlags values. The default tqalignment is 0, which
    means that the widget fills the entire cell.

    A non-zero tqalignment indicates that the tqlayout should not grow to
    fill the available space but should be sized according to
    tqsizeHint().

    \a tqlayout becomes a child of the grid tqlayout.

    \sa addLayout()
*/
void TQGridLayout::addMultiCellLayout( TQLayout *tqlayout, int fromRow, int toRow,
				      int fromCol, int toCol, int tqalignment )
{
    addChildLayout( tqlayout );
    TQGridBox *b = new TQGridBox( TQT_TQLAYOUTITEM(tqlayout) );
    b->tqsetAlignment( tqalignment );
    data->add( b, fromRow, toRow, fromCol, toCol );
}

/*!
    Sets the stretch factor of row \a row to \a stretch. The first row
    is number 0.

    The stretch factor is relative to the other rows in this grid.
    Rows with a higher stretch factor take more of the available
    space.

    The default stretch factor is 0. If the stretch factor is 0 and no
    other row in this table can grow at all, the row may still grow.

    \sa rowStretch(), setRowSpacing(), setColStretch()
*/
void TQGridLayout::setRowStretch( int row, int stretch )
{
    data->setRowStretch( row, stretch );
}

/*!
    Returns the stretch factor for row \a row.

    \sa setRowStretch()
*/
int TQGridLayout::rowStretch( int row ) const
{
    return data->rowStretch( row );
}

/*!
    Returns the stretch factor for column \a col.

    \sa setColStretch()
*/
int TQGridLayout::colStretch( int col ) const
{
    return data->colStretch( col );
}

/*!
    Sets the stretch factor of column \a col to \a stretch. The first
    column is number 0.

    The stretch factor is relative to the other columns in this grid.
    Columns with a higher stretch factor take more of the available
    space.

    The default stretch factor is 0. If the stretch factor is 0 and no
    other column in this table can grow at all, the column may still
    grow.

    \sa colStretch(), addColSpacing(), setRowStretch()
*/
void TQGridLayout::setColStretch( int col, int stretch )
{
    data->setColStretch( col, stretch );
}

#if TQT_VERSION >= 0x040000
#error "Make add{Row,Col}Spacing() inline TQT_NO_COMPAT functions defined in terms of set{Row,Col}Spacing()"
#endif

/*!
    \obsolete

    Sets the minimum height of row \a row to \a minsize pixels.

    Use setRowSpacing() instead.
*/
void TQGridLayout::addRowSpacing( int row, int minsize )
{
    TQLayoutItem *b = TQT_TQLAYOUTITEM(new TQSpacerItem( 0, minsize ));
    add( b, row, 0 );
}

/*!
    \obsolete

    Sets the minimum width of column \a col to \a minsize pixels.

    Use setColSpacing() instead.
*/
void TQGridLayout::addColSpacing( int col, int minsize )
{
    TQLayoutItem *b = TQT_TQLAYOUTITEM(new TQSpacerItem( minsize, 0 ));
    add( b, 0, col );
}

/*!
    Sets the minimum height of row \a row to \a minSize pixels.

    \sa rowSpacing(), setColSpacing()
*/
void TQGridLayout::setRowSpacing( int row, int minSize )
{
    data->setRowSpacing( row, minSize );
}

/*!
    Returns the row spacing for row \a row.

    \sa setRowSpacing()
*/
int TQGridLayout::rowSpacing( int row ) const
{
    return data->rowSpacing( row );
}

/*!
    Sets the minimum width of column \a col to \a minSize pixels.

    \sa colSpacing(), setRowSpacing()
*/
void TQGridLayout::setColSpacing( int col, int minSize )
{
    data->setColSpacing( col, minSize );
}

/*!
    Returns the column spacing for column \a col.

    \sa setColSpacing()
*/
int TQGridLayout::colSpacing( int col ) const
{
    return data->colSpacing( col );
}

/*!
    Returns whether this tqlayout can make use of more space than
    tqsizeHint(). A value of \c Vertical or \c Horizontal means that it wants
    to grow in only one dimension, whereas \c BothDirections means that
    it wants to grow in both dimensions.
*/
TQ_SPExpandData TQGridLayout::expandingDirections() const
{
    return data->expanding( spacing() );
}

/*!
    Sets the grid's origin corner, i.e. position (0, 0), to \a c.
*/
void TQGridLayout::setOrigin( Corner c )
{
    data->setReversed( c == BottomLeft || c == BottomRight,
		       c == TopRight || c == BottomRight );
}

/*!
    Returns the corner that's used for the grid's origin, i.e. for
    position (0, 0).
*/
TQGridLayout::Corner TQGridLayout::origin() const
{
    if ( data->horReversed() ) {
	return data->verReversed() ? BottomRight : TopRight;
    } else {
	return data->verReversed() ? BottomLeft : TopLeft;
    }
}

/*!
    Resets cached information.
*/
void TQGridLayout::tqinvalidate()
{
    TQLayout::tqinvalidate();
    TQLayout::setGeometry( TQRect() ); // for binary compatibility (?)
    data->setDirty();
}

/*! \reimp */
// TQLayoutIterator TQGridLayout::iterator()
// {
//     return TQLayoutIterator( new TQGridLayoutDataIterator(data) );
// }

#ifdef USE_QT4

/*!
    \reimp
*/
int TQGridLayout::count() const {
	return data->count();
}

/*!
    \reimp
*/
TQLayoutItem* TQGridLayout::itemAt(int index) const {
	TQGridLayoutDataIterator tqgli = TQGridLayoutDataIterator(data);
	for (int i=0; i<index; i++) { tqgli.next(); }
	return index >= 0 && index < data->count() ? tqgli.current() : 0;
}

/*!
    \reimp
*/
TQLayoutItem* TQGridLayout::takeAt(int index) {
	if (index < 0 || index >= data->count())
		return 0;
	TQGridLayoutDataIterator tqgli = TQGridLayoutDataIterator(data);
	for (int i=0; i<index; i++) { tqgli.next(); }
	return tqgli.takeCurrent();
}

#endif // USE_QT4

// #endif // USE_QT4

struct TQBoxLayoutItem
{
    TQBoxLayoutItem( TQLayoutItem *it, int stretch_ = 0 )
	: item( it ), stretch( stretch_ ), magic( FALSE ) { }
    ~TQBoxLayoutItem() { delete item; }

    int hfw( int w ) {
	if ( item->hasHeightForWidth() ) {
	    return item->heightForWidth( w );
	} else {
	    return item->sizeHint().height();
	}
    }
    int mhfw( int w ) {
	if ( item->hasHeightForWidth() ) {
	    return item->heightForWidth( w );
	} else {
	    return item->minimumSize().height();
	}
    }
    int hStretch() {
	if ( stretch == 0 && item->widget() ) {
	    return TQT_TQSIZEPOLICY_OBJECT(item->widget()->sizePolicy()).horStretch();
	} else {
	    return stretch;
	}
    }
    int vStretch() {
	if ( stretch == 0 && item->widget() ) {
	    return TQT_TQSIZEPOLICY_OBJECT(item->widget()->sizePolicy()).verStretch();
	} else {
	    return stretch;
	}
    }

    TQLayoutItem *item;
    int stretch;
    bool magic;
};

class TQBoxLayoutData
{
public:
    TQBoxLayoutData() : geomArray( 0 ), hfwWidth( -1 ), dirty( TRUE )
    { list.setAutoDelete( TRUE ); }

    ~TQBoxLayoutData() { delete geomArray; }
    void setDirty() {
	delete geomArray;
	geomArray = 0;
	hfwWidth = -1;
	hfwHeight = -1;
	dirty = TRUE;
    }

    TQPtrList<TQBoxLayoutItem> list;
    TQMemArray<TQLayoutStruct> *geomArray;
    int hfwWidth;
    int hfwHeight;
    int hfwMinHeight;
    TQSize tqsizeHint;
    TQSize minSize;
    TQSize maxSize;
    TQ_SPExpandData expanding;
    uint hasHfw : 1;
    uint dirty : 1;
};

class TQBoxLayoutIterator : public TQGLayoutIterator
{
public:
    TQBoxLayoutIterator( TQBoxLayoutData *d ) : data( d ), idx( 0 ) {}
    TQLayoutItem *current() {
	if ( idx >= int(data->list.count()) )
	    return 0;
	return data->list.at(idx)->item;
    }
    TQLayoutItem *next() {
	idx++;
	return current();
    }
    TQLayoutItem *takeCurrent() {
	TQLayoutItem *item = 0;

	TQBoxLayoutItem *b = data->list.take( idx );
	if ( b ) {
	    item = b->item;
	    b->item = 0;
	    delete b;
	}
	data->setDirty();
	return item;
    }

private:
    TQBoxLayoutData *data;
    int idx;
};

/*!
    \class TQBoxLayout

    \brief The TQBoxLayout class lines up child widgets horizontally or
    vertically.

    \ingroup geomanagement
    \ingroup appearance

    TQBoxLayout takes the space it gets (from its tqparent tqlayout or from
    the mainWidget()), divides it up into a row of boxes, and makes
    each managed widget fill one box.

    \img qhbox-m.png Horizontal box with five child widgets

    If the TQBoxLayout's orientation is \c Horizontal the boxes are
    placed in a row, with suitable sizes. Each widget (or other box)
    will get at least its minimum size and at most its maximum size.
    Any excess space is shared according to the stretch factors (more
    about that below).

    \img qvbox-m.png Vertical box with five child widgets

    If the TQBoxLayout's orientation is \c Vertical, the boxes are
    placed in a column, again with suitable sizes.

    The easiest way to create a TQBoxLayout is to use one of the
    convenience classes, e.g. TQHBoxLayout (for \c Horizontal boxes) or
    TQVBoxLayout (for \c Vertical boxes). You can also use the
    TQBoxLayout constructor directly, specifying its direction as \c
    LeftToRight, \c Down, \c RightToLeft or \c Up.

    If the TQBoxLayout is not the top-level tqlayout (i.e. it is not
    managing all of the widget's area and tqchildren), you must add it
    to its tqparent tqlayout before you can do anything with it. The
    normal way to add a tqlayout is by calling
    parentLayout-\>addLayout().

    Once you have done this, you can add boxes to the TQBoxLayout using
    one of four functions:

    \list
    \i addWidget() to add a widget to the TQBoxLayout and set the
    widget's stretch factor. (The stretch factor is along the row of
    boxes.)

    \i addSpacing() to create an empty box; this is one of the
    functions you use to create nice and spacious dialogs. See below
    for ways to set margins.

    \i addStretch() to create an empty, stretchable box.

    \i addLayout() to add a box containing another TQLayout to the row
    and set that tqlayout's stretch factor.
    \endlist

    Use insertWidget(), insertSpacing(), insertStretch() or
    insertLayout() to insert a box at a specified position in the
    tqlayout.

    TQBoxLayout also includes two margin widths:

    \list
    \i setMargin() sets the width of the outer border. This is the width
       of the reserved space along each of the TQBoxLayout's four sides.
    \i setSpacing() sets the width between neighboring boxes. (You
       can use addSpacing() to get more space at a particular spot.)
    \endlist

    The margin defaults to 0. The spacing defaults to the same as the
    margin width for a top-level tqlayout, or to the same as the tqparent
    tqlayout. Both are parameters to the constructor.

    To remove a widget from a tqlayout, call remove(). Calling
    TQWidget::hide() on a widget also effectively removes the widget
    from the tqlayout until TQWidget::show() is called.

    You will almost always want to use TQVBoxLayout and TQHBoxLayout
    rather than TQBoxLayout because of their convenient constructors.

    \sa TQGrid \link tqlayout.html Layout Overview \endlink
*/

/*!
    \enum TQBoxLayout::Direction

    This type is used to determine the direction of a box tqlayout.

    \value LeftToRight  Horizontal, from left to right
    \value RightToLeft  Horizontal, from right to left
    \value TopToBottom  Vertical, from top to bottom
    \value Down  The same as \c TopToBottom
    \value BottomToTop  Vertical, from bottom to top
    \value Up  The same as \c BottomToTop
*/

static inline bool horz( TQBoxLayout::Direction dir )
{
    return dir == TQBoxLayout::RightToLeft || dir == TQBoxLayout::LeftToRight;
}

/*!
    Constructs a new TQBoxLayout with direction \a d and main widget \a
    tqparent. \a tqparent may not be 0.

    The \a margin is the number of pixels between the edge of the
    widget and its managed tqchildren. The \a spacing is the default
    number of pixels between neighboring tqchildren. If \a spacing is -1
    the value of \a margin is used for \a spacing.

    \a name is the internal object name.

    \sa direction()
*/
TQBoxLayout::TQBoxLayout( TQWidget *tqparent, Direction d,
			int margin, int spacing, const char *name )
    : TQLayout( tqparent, margin, spacing, name )
{
    data = new TQBoxLayoutData;
    dir = d;
    setSupportsMargin( TRUE );
}

/*!
    Constructs a new TQBoxLayout called \a name, with direction \a d,
    and inserts it into \a parentLayout.

    The \a spacing is the default number of pixels between neighboring
    tqchildren. If \a spacing is -1, the tqlayout will inherit its
    tqparent's spacing().
*/
TQBoxLayout::TQBoxLayout( TQLayout *parentLayout, Direction d, int spacing,
			const char *name )
    : TQLayout( parentLayout, spacing, name )
{
    data = new TQBoxLayoutData;
    dir = d;
    setSupportsMargin( TRUE );
}

/*!
    Constructs a new TQBoxLayout called \a name, with direction \a d.

    If \a spacing is -1, the tqlayout will inherit its tqparent's
    spacing(); otherwise \a spacing is used.

    You must insert this box into another tqlayout.
*/
TQBoxLayout::TQBoxLayout( Direction d, int spacing, const char *name )
    : TQLayout( spacing, name )
{
    data = new TQBoxLayoutData;
    dir = d;
    setSupportsMargin( TRUE );
}

/*!
    Destroys this box tqlayout.

    The tqlayout's widgets aren't destroyed.
*/
TQBoxLayout::~TQBoxLayout()
{
    delete data;
}

/*!
    Returns the preferred size of this box tqlayout.
*/
TQSize TQBoxLayout::tqsizeHint() const
{
    if ( data->dirty ) {
	TQBoxLayout *that = (TQBoxLayout*)this;
	that->setupGeom();
    }
    return data->tqsizeHint + TQSize( 2 * margin(), 2 * margin() );
}

/*!
    Returns the minimum size needed by this box tqlayout.
*/
TQSize TQBoxLayout::tqminimumSize() const
{
    if ( data->dirty ) {
	TQBoxLayout *that = (TQBoxLayout*)this;
	that->setupGeom();
    }
    return data->minSize + TQSize( 2 * margin(), 2 * margin() );
}

/*!
    Returns the maximum size needed by this box tqlayout.
*/
TQSize TQBoxLayout::tqmaximumSize() const
{
    if ( data->dirty ) {
	TQBoxLayout *that = (TQBoxLayout*)this;
	that->setupGeom();
    }
    TQSize s = ( data->maxSize + TQSize(2 * margin(), 2 * margin()) )
	      .boundedTo(TQSize(TQLAYOUTSIZE_MAX, TQLAYOUTSIZE_MAX));
    if ( tqalignment() & TQt::AlignHorizontal_Mask )
	s.setWidth( TQLAYOUTSIZE_MAX );
    if ( tqalignment() & TQt::AlignVertical_Mask )
	s.setHeight( TQLAYOUTSIZE_MAX );
    return s;
}

/*!
  Returns TRUE if this tqlayout's preferred height depends on its width;
  otherwise returns FALSE.
*/
bool TQBoxLayout::hasHeightForWidth() const
{
    if ( data->dirty ) {
	TQBoxLayout *that = (TQBoxLayout*)this;
	that->setupGeom();
    }
    return data->hasHfw;
}

/*!
    Returns the tqlayout's preferred height when it is \a w pixels wide.
*/
int TQBoxLayout::heightForWidth( int w ) const
{
    if ( !hasHeightForWidth() )
	return -1;
    w -= 2 * margin();
    if ( w != data->hfwWidth ) {
	TQBoxLayout *that = (TQBoxLayout*)this;
	that->calcHfw( w );
    }
    return data->hfwHeight + 2 * margin();
}

/*! \internal */
int TQBoxLayout::minimumHeightForWidth( int w ) const
{
    (void) heightForWidth( w );
    return data->hasHfw ? (data->hfwMinHeight + 2 * margin() ) : -1;
}

/*!
    Resets cached information.
*/
void TQBoxLayout::tqinvalidate()
{
    TQLayout::tqinvalidate();
    data->setDirty();
}

/*!
    \reimp
*/
int TQBoxLayout::count() const {
	return data->list.count();
}

/*!
    \reimp
*/
TQLayoutItem* TQBoxLayout::itemAt(int index) const {
	return index >= 0 && index < data->list.count() ? data->list.at(index)->item : 0;
}

/*!
    \reimp
*/
TQLayoutItem* TQBoxLayout::takeAt(int index) {
	if (index < 0 || index >= data->list.count())
		return 0;
	TQBoxLayoutItem *b = data->list.take(index);
	TQLayoutItem *item = b->item;
	b->item = 0;
	delete b;

	invalidate();
	return item;
}

/*!
    \reimp
*/
// TQLayoutIterator TQBoxLayout::iterator()
// {
//     return TQLayoutIterator( new TQBoxLayoutIterator(data) );
// }

/*!
    Returns whether this tqlayout can make use of more space than
    tqsizeHint(). A value of \c Vertical or \c Horizontal means that it wants
    to grow in only one dimension, whereas \c BothDirections means that
    it wants to grow in both dimensions.
*/
TQ_SPExpandData TQBoxLayout::expandingDirections() const
{
    if ( data->dirty ) {
	TQBoxLayout *that = (TQBoxLayout*)this;
	that->setupGeom();
    }
    return data->expanding;
}

/*!
    Resizes managed widgets within the rectangle \a r.
*/
void TQBoxLayout::setGeometry( const TQRect &r )
{
    if ( !data->geomArray || r != tqgeometry() ) {
	TQLayout::setGeometry( r );
	if ( !data->geomArray )
	    setupGeom();
	TQRect cr = tqalignment() ? alignmentRect( r ) : r;
	TQRect s( cr.x() + margin(), cr.y() + margin(),
		 cr.width() - 2 * margin(), cr.height() - 2 * margin() );

	TQMemArray<TQLayoutStruct> a = *data->geomArray;
	int pos = horz( dir ) ? s.x() : s.y();
	int space = horz( dir ) ? s.width() : s.height();
	int n = a.count();
	if ( data->hasHfw && !horz(dir) ) {
	    for ( int i = 0; i < n; i++ ) {
		TQBoxLayoutItem *box = data->list.at( i );
		if ( box->item->hasHeightForWidth() )
		    a[i].tqsizeHint = a[i].tqminimumSize =
				    box->item->heightForWidth( s.width() );
	    }
	}

	Direction visualDir = dir;
	if ( TQApplication::reverseLayout() ) {
	    if ( dir == LeftToRight )
		visualDir = RightToLeft;
	    else if ( dir == RightToLeft )
		visualDir = LeftToRight;
	}

	qGeomCalc( a, 0, n, pos, space, spacing() );
	for ( int i = 0; i < n; i++ ) {
	    TQBoxLayoutItem *box = data->list.at( i );

	    switch ( visualDir ) {
	    case LeftToRight:
		box->item->setGeometry( TQRect(a[i].pos, s.y(),
					      a[i].size, s.height()) );
		break;
	    case RightToLeft:
		box->item->setGeometry( TQRect(s.left() + s.right()
					      - a[i].pos - a[i].size + 1, s.y(),
					      a[i].size, s.height()) );
		break;
	    case TopToBottom:
		box->item->setGeometry( TQRect(s.x(), a[i].pos,
					      s.width(), a[i].size) );
		break;
	    case BottomToTop:
		box->item->setGeometry( TQRect(s.x(), s.top() + s.bottom()
					      - a[i].pos - a[i].size + 1,
					      s.width(), a[i].size) );
	    }
	}
    }
}

/*!
    Adds \a item to the end of this box tqlayout.
*/
void TQBoxLayout::addItem( QLayoutItem *item )
{
    TQBoxLayoutItem *it = new TQBoxLayoutItem( static_cast<TQLayoutItem*>(item) );
    data->list.append( it );
    tqinvalidate();
}

/*!
    Inserts \a item into this box tqlayout at position \a index. If \a
    index is negative, the item is added at the end.

    \warning Does not call TQLayout::insertChildLayout() if \a item is
    a TQLayout.

    \sa addItem(), findWidget()
*/
void TQBoxLayout::insertItem( int index, TQLayoutItem *item )
{
    if ( index < 0 )				// append
	index = data->list.count();

    TQBoxLayoutItem *it = new TQBoxLayoutItem( item );
    data->list.insert( index, it );
    tqinvalidate();
}

/*!
    Inserts a non-stretchable space at position \a index, with size \a
    size. If \a index is negative the space is added at the end.

    The box tqlayout has default margin and spacing. This function adds
    additional space.

    \sa insertStretch()
*/
void TQBoxLayout::insertSpacing( int index, int size )
{
    if ( index < 0 )				// append
	index = data->list.count();

    // hack in TQGridLayoutData: spacers do not get insideSpacing
    TQLayoutItem *b;
    if ( horz( dir ) )
	b = TQT_TQLAYOUTITEM(new TQSpacerItem( size, 0, TQSizePolicy::Fixed,
			     TQSizePolicy::Minimum ));
    else
	b = TQT_TQLAYOUTITEM(new TQSpacerItem( 0, size, TQSizePolicy::Minimum,
			     TQSizePolicy::Fixed ));

    TQBoxLayoutItem *it = new TQBoxLayoutItem( b );
    it->magic = TRUE;
    data->list.insert( index, it );
    tqinvalidate();
}

/*!
    Inserts a stretchable space at position \a index, with zero
    minimum size and stretch factor \a stretch. If \a index is
    negative the space is added at the end.

    \sa insertSpacing()
*/
void TQBoxLayout::insertStretch( int index, int stretch )
{
    if ( index < 0 )				// append
	index = data->list.count();

    // hack in TQGridLayoutData: spacers do not get insideSpacing
    TQLayoutItem *b;
    if ( horz( dir ) )
	b = TQT_TQLAYOUTITEM(new TQSpacerItem( 0, 0, TQSizePolicy::Expanding,
			     TQSizePolicy::Minimum ));
    else
	b = TQT_TQLAYOUTITEM(new TQSpacerItem( 0, 0,  TQSizePolicy::Minimum,
			     TQSizePolicy::Expanding ));

    TQBoxLayoutItem *it = new TQBoxLayoutItem( b, stretch );
    it->magic = TRUE;
    data->list.insert( index, it );
    tqinvalidate();
}

/*!
    Inserts \a tqlayout at position \a index, with stretch factor \a
    stretch. If \a index is negative, the tqlayout is added at the end.

    \a tqlayout becomes a child of the box tqlayout.

    \sa setAutoAdd(), insertWidget(), insertSpacing()
*/
void TQBoxLayout::insertLayout( int index, TQLayout *tqlayout, int stretch )
{
    if ( index < 0 )				// append
	index = data->list.count();

    addChildLayout( tqlayout );
    TQBoxLayoutItem *it = new TQBoxLayoutItem( TQT_TQLAYOUTITEM(tqlayout), stretch );
    data->list.insert( index, it );
    tqinvalidate();
}

/*!
    Inserts \a widget at position \a index, with stretch factor \a
    stretch and tqalignment \a tqalignment. If \a index is negative, the
    widget is added at the end.

    The stretch factor applies only in the \link direction() direction
    \endlink of the TQBoxLayout, and is relative to the other boxes and
    widgets in this TQBoxLayout. Widgets and boxes with higher stretch
    factors grow more.

    If the stretch factor is 0 and nothing else in the TQBoxLayout has
    a stretch factor greater than zero, the space is distributed
    according to the TQWidget:sizePolicy() of each widget that's
    involved.

    Alignment is specified by \a tqalignment, which is a bitwise OR of
    \l TQt::AlignmentFlags values. The default tqalignment is 0, which
    means that the widget fills the entire cell.

    From TQt 3.0, the \a tqalignment parameter is interpreted more
    aggressively than in previous versions of TQt. A non-default
    tqalignment now indicates that the widget should not grow to fill
    the available space, but should be sized according to tqsizeHint().

    \sa setAutoAdd(), insertLayout(), insertSpacing()
*/
void TQBoxLayout::insertWidget( int index, TQWidget *widget, int stretch,
			       int tqalignment )
{
    if ( !checkWidget(this, widget) )
	 return;

    if ( index < 0 )				// append
	index = data->list.count();

    TQWidgetItem *b = new TQWidgetItem( widget );
    b->tqsetAlignment( tqalignment );
    TQBoxLayoutItem *it = new TQBoxLayoutItem( b, stretch );
    data->list.insert( index, it );
    tqinvalidate();
}

/*!
    Adds a non-stretchable space with size \a size to the end of this
    box tqlayout. TQBoxLayout provides default margin and spacing. This
    function adds additional space.

    \sa insertSpacing(), addStretch()
*/
void TQBoxLayout::addSpacing( int size )
{
    insertSpacing( -1, size );
}

/*!
    Adds a stretchable space with zero minimum size and stretch factor
    \a stretch to the end of this box tqlayout.

    \sa addSpacing()
*/
void TQBoxLayout::addStretch( int stretch )
{
    insertStretch( -1, stretch );
}

/*!
    Adds \a widget to the end of this box tqlayout, with a stretch
    factor of \a stretch and tqalignment \a tqalignment.

    The stretch factor applies only in the \link direction() direction
    \endlink of the TQBoxLayout, and is relative to the other boxes and
    widgets in this TQBoxLayout. Widgets and boxes with higher stretch
    factors grow more.

    If the stretch factor is 0 and nothing else in the TQBoxLayout has
    a stretch factor greater than zero, the space is distributed
    according to the TQWidget:sizePolicy() of each widget that's
    involved.

    Alignment is specified by \a tqalignment which is a bitwise OR of \l
    TQt::AlignmentFlags values. The default tqalignment is 0, which means
    that the widget fills the entire cell.

    From TQt 3.0, the \a tqalignment parameter is interpreted more
    aggressively than in previous versions of TQt. A non-default
    tqalignment now indicates that the widget should not grow to fill
    the available space, but should be sized according to tqsizeHint().

    \sa insertWidget(), setAutoAdd(), addLayout(), addSpacing()
*/
void TQBoxLayout::addWidget( TQWidget *widget, int stretch,
			    int tqalignment )
{
    insertWidget( -1, widget, stretch, tqalignment );
}

/*!
    Adds \a tqlayout to the end of the box, with serial stretch factor
    \a stretch.

    When a tqlayout is constructed with another tqlayout as its tqparent,
    you don't need to call addLayout(); the child tqlayout is
    automatically added to the tqparent tqlayout as it is constructed.

    \sa insertLayout(), setAutoAdd(), addWidget(), addSpacing()
*/
void TQBoxLayout::addLayout( TQLayout *tqlayout, int stretch )
{
    insertLayout( -1, tqlayout, stretch );
}

/*!
    Limits the perpendicular dimension of the box (e.g. height if the
    box is LeftToRight) to a minimum of \a size. Other constraints may
    increase the limit.
*/
void TQBoxLayout::addStrut( int size )
{
    TQLayoutItem *b;
    if ( horz( dir ) )
	b = TQT_TQLAYOUTITEM(new TQSpacerItem( 0, size, TQSizePolicy::Fixed,
			     TQSizePolicy::Minimum ));
    else
	b = TQT_TQLAYOUTITEM(new TQSpacerItem( size, 0, TQSizePolicy::Minimum,
			     TQSizePolicy::Fixed ));

    TQBoxLayoutItem *it = new TQBoxLayoutItem( b );
    it->magic = TRUE;
    data->list.append( it );
    tqinvalidate();
}

/*!
    Searches for widget \a w in this tqlayout (not including child
    layouts).

    Returns the index of \a w, or -1 if \a w is not found.
*/
int TQBoxLayout::findWidget( TQWidget* w )
{
    const int n = data->list.count();
    for ( int i = 0; i < n; i++ ) {
	if ( data->list.at(i)->item->widget() == w )
	    return i;
    }
    return -1;
}

/*!
    Sets the stretch factor for widget \a w to \a stretch and returns
    TRUE if \a w is found in this tqlayout (not including child
    layouts); otherwise returns FALSE.
*/
bool TQBoxLayout::setStretchFactor( TQWidget *w, int stretch )
{
    TQPtrListIterator<TQBoxLayoutItem> it( data->list );
    TQBoxLayoutItem *box;
    while ( (box=it.current()) != 0 ) {
	++it;
	if ( box->item->widget() == w ) {
	    box->stretch = stretch;
	    tqinvalidate();
	    return TRUE;
	}
    }
    return FALSE;
}

/*!
  \overload

  Sets the stretch factor for the tqlayout \a l to \a stretch and
  returns TRUE if \a l is found in this tqlayout (not including child
  layouts); otherwise returns FALSE.
*/
bool TQBoxLayout::setStretchFactor( TQLayout *l, int stretch )
{
    TQPtrListIterator<TQBoxLayoutItem> it( data->list );
    TQBoxLayoutItem *box;
    while ( (box=it.current()) != 0 ) {
	++it;
	if ( box->item->tqlayout() == l ) {
	    box->stretch = stretch;
	    tqinvalidate();
	    return TRUE;
	}
    }
    return FALSE;
}

/*!
    Sets the direction of this tqlayout to \a direction.
*/
void TQBoxLayout::setDirection( Direction direction )
{
    if ( dir == direction )
	return;
    if ( horz(dir) != horz(direction) ) {
	//swap around the spacers (the "magic" bits)
	//#### a bit yucky, knows too much.
	//#### probably best to add access functions to tqspacerItem
	//#### or even a TQSpacerItem::flip()
	TQPtrListIterator<TQBoxLayoutItem> it( data->list );
	TQBoxLayoutItem *box;
	while ( (box=it.current()) != 0 ) {
	    ++it;
	    if ( box->magic ) {
		TQSpacerItem *sp = box->item->tqspacerItem();
		if ( sp ) {
		    if ( sp->expandingDirections() == TQSizePolicy::NoDirection ) {
			//spacing or strut
			TQSize s = sp->tqsizeHint();
			sp->changeSize( s.height(), s.width(),
			    horz(direction) ? TQSizePolicy::Fixed:TQSizePolicy::Minimum,
			    horz(direction) ? TQSizePolicy::Minimum:TQSizePolicy::Fixed );

		    } else {
			//stretch
			if ( horz(direction) )
			    sp->changeSize( 0, 0, TQSizePolicy::Expanding,
					    TQSizePolicy::Minimum );
			else
			    sp->changeSize( 0, 0, TQSizePolicy::Minimum,
					    TQSizePolicy::Expanding );
		    }
		}
	    }
	}
    }
    dir = direction;
    tqinvalidate();
    if ( mainWidget() ) {
	TQEvent *lh = new TQEvent( TQEvent::LayoutHint );
	TQApplication::postEvent( mainWidget(), lh );
    }

}

/*
    Initializes the data structure needed by qGeomCalc and
    recalculates max/min and size hint.
*/
void TQBoxLayout::setupGeom()
{
    if ( !data->dirty )
	return;

    int maxw = horz( dir ) ? 0 : TQLAYOUTSIZE_MAX;
    int maxh = horz( dir ) ? TQLAYOUTSIZE_MAX : 0;
    int minw = 0;
    int minh = 0;
    int hintw = 0;
    int hinth = 0;

    bool horexp = FALSE;
    bool verexp = FALSE;

    data->hasHfw = FALSE;

    delete data->geomArray;
    int n = data->list.count();
    data->geomArray = new TQMemArray<TQLayoutStruct>( n );
    TQMemArray<TQLayoutStruct>& a = *data->geomArray;

    bool first = TRUE;
    for ( int i = 0; i < n; i++ ) {
	TQBoxLayoutItem *box = data->list.at( i );
	TQSize max = box->item->maximumSize();
	TQSize min = box->item->minimumSize();
	TQSize hint = box->item->sizeHint();

	TQ_SPExpandData exp = box->item->expandingDirections();
	bool empty = box->item->isEmpty();
	// space before non-empties, except the first:
	int space = ( empty || first ) ? 0 : spacing();
	bool ignore = empty && box->item->widget(); // ignore hidden widgets

	if ( horz(dir) ) {
	    bool expand = exp & TQSizePolicy::Horizontally || box->stretch > 0;
	    horexp = horexp || expand;
	    maxw += max.width() + space;
	    minw += min.width() + space;
	    hintw += hint.width() + space;
	    if ( !ignore )
		qMaxExpCalc( maxh, verexp,
			     max.height(), exp & TQSizePolicy::Vertically );
	    minh = TQMAX( minh, min.height() );
	    hinth = TQMAX( hinth, hint.height() );

	    a[i].tqsizeHint = hint.width();
	    a[i].tqmaximumSize = max.width();
	    a[i].tqminimumSize = min.width();
	    a[i].expansive = expand;
	    a[i].stretch = box->stretch ? box->stretch : box->hStretch();
	} else {
	    bool expand = ( exp & TQSizePolicy::Vertically || box->stretch > 0 );
	    verexp = verexp || expand;
	    maxh += max.height() + space;
	    minh += min.height() + space;
	    hinth += hint.height() + space;
	    if ( !ignore )
		qMaxExpCalc( maxw, horexp,
			     max.width(), exp & TQSizePolicy::Horizontally );
	    minw = TQMAX( minw, min.width() );
	    hintw = TQMAX( hintw, hint.width() );

	    a[i].tqsizeHint = hint.height();
	    a[i].tqmaximumSize = max.height();
	    a[i].tqminimumSize = min.height();
	    a[i].expansive = expand;
	    a[i].stretch = box->stretch ? box->stretch : box->vStretch();
	}

	a[i].empty = empty;
	data->hasHfw = data->hasHfw || box->item->hasHeightForWidth();
	first = first && empty;
    }

    data->minSize = TQSize( minw, minh );
    data->maxSize = TQSize( maxw, maxh ).expandedTo( data->minSize );

    data->expanding = (TQ_SPExpandData)
		       ( (horexp ? TQSizePolicy::Horizontally : 0)
			 | (verexp ? TQSizePolicy::Vertically : 0) );

    data->tqsizeHint = TQSize( hintw, hinth )
		     .expandedTo( data->minSize )
		     .boundedTo( data->maxSize );

    data->dirty = FALSE;
}

/*
  Calculates and stores the preferred height given the width \a w.
*/
void TQBoxLayout::calcHfw( int w )
{
    int h = 0;
    int mh = 0;

    if ( horz(dir) ) {
	TQMemArray<TQLayoutStruct> &a = *data->geomArray;
	int n = a.count();
	qGeomCalc( a, 0, n, 0, w, spacing() );
	for ( int i = 0; i < n; i++ ) {
	    TQBoxLayoutItem *box = data->list.at(i);
	    h = TQMAX( h, box->hfw(a[i].size) );
	    mh = TQMAX( mh, box->mhfw(a[i].size) );
	}
    } else {
	TQPtrListIterator<TQBoxLayoutItem> it( data->list );
	TQBoxLayoutItem *box;
	bool first = TRUE;
	while ( (box = it.current()) != 0 ) {
	    ++it;
	    bool empty = box->item->isEmpty();
	    h += box->hfw( w );
	    mh += box->mhfw( w );
	    if ( !first && !empty ) {
		h += spacing();
		mh += spacing();
	    }
	    first = first && empty;
	}
    }
    data->hfwWidth = w;
    data->hfwHeight = h;
    data->hfwMinHeight = mh;
}

/*!
    \fn TQBoxLayout::Direction TQBoxLayout::direction() const

    Returns the direction of the box. addWidget() and addSpacing()
    work in this direction; the stretch stretches in this direction.

    \sa TQBoxLayout::Direction addWidget() addSpacing()
*/

/*!
    \class TQHBoxLayout
    \brief The TQHBoxLayout class lines up widgets horizontally.

    \ingroup geomanagement
    \ingroup appearance
    \mainclass

    This class is used to construct horizontal box tqlayout objects. See
    \l TQBoxLayout for more details.

    The simplest use of the class is like this:
    \code
	TQBoxLayout * l = new TQHBoxLayout( widget );
	l->setAutoAdd( TRUE );
	new TQSomeWidget( widget );
	new TQSomeOtherWidget( widget );
	new TQAnotherWidget( widget );
    \endcode

    or like this:
    \code
	TQBoxLayout * l = new TQHBoxLayout( widget );
	l->addWidget( existingChildOfWidget );
	l->addWidget( anotherChildOfWidget );
    \endcode

    \img qhboxtqlayout.png TQHBox

    \sa TQVBoxLayout TQGridLayout
	\link tqlayout.html the Layout overview \endlink
*/

/*!
    Constructs a new top-level horizontal box called \a name, with
    tqparent \a tqparent.

    The \a margin is the number of pixels between the edge of the
    widget and its managed tqchildren. The \a spacing is the default
    number of pixels between neighboring tqchildren. If \a spacing is -1
    the value of \a margin is used for \a spacing.
*/
TQHBoxLayout::TQHBoxLayout( TQWidget *tqparent, int margin,
			  int spacing, const char *name )
    : TQBoxLayout( tqparent, LeftToRight, margin, spacing, name )
{
}

/*!
    Constructs a new horizontal box called name \a name and adds it to
    \a parentLayout.

    The \a spacing is the default number of pixels between neighboring
    tqchildren. If \a spacing is -1, this TQHBoxLayout will inherit its
    tqparent's spacing().
*/
TQHBoxLayout::TQHBoxLayout( TQLayout *parentLayout, int spacing,
			  const char *name )
    : TQBoxLayout( parentLayout, LeftToRight, spacing, name )
{
}

/*!
    Constructs a new horizontal box called name \a name. You must add
    it to another tqlayout.

    The \a spacing is the default number of pixels between neighboring
    tqchildren. If \a spacing is -1, this TQHBoxLayout will inherit its
    tqparent's spacing().
*/
TQHBoxLayout::TQHBoxLayout( int spacing, const char *name )
    : TQBoxLayout( LeftToRight, spacing, name )
{
}

/*!
    Destroys this box tqlayout.

    The tqlayout's widgets aren't destroyed.
*/
TQHBoxLayout::~TQHBoxLayout()
{
}

/*!
    \class TQVBoxLayout

    \brief The TQVBoxLayout class lines up widgets vertically.

    \ingroup geomanagement
    \ingroup appearance
    \mainclass

    This class is used to construct vertical box tqlayout objects. See
    TQBoxLayout for more details.

    The simplest use of the class is like this:
    \code
	TQBoxLayout * l = new TQVBoxLayout( widget );
	l->addWidget( aWidget );
	l->addWidget( anotherWidget );
    \endcode

    \img qvboxtqlayout.png TQVBox

    \sa TQHBoxLayout TQGridLayout \link tqlayout.html the Layout overview \endlink
*/

/*!
    Constructs a new top-level vertical box called \a name, with
    tqparent \a tqparent.

    The \a margin is the number of pixels between the edge of the
    widget and its managed tqchildren. The \a spacing is the default
    number of pixels between neighboring tqchildren. If \a spacing is -1
    the value of \a margin is used for \a spacing.
*/
TQVBoxLayout::TQVBoxLayout( TQWidget *tqparent, int margin, int spacing,
			  const char *name )
    : TQBoxLayout( tqparent, TopToBottom, margin, spacing, name )
{

}

/*!
    Constructs a new vertical box called name \a name and adds it to
    \a parentLayout.

    The \a spacing is the default number of pixels between neighboring
    tqchildren. If \a spacing is -1, this TQVBoxLayout will inherit its
    tqparent's spacing().
*/
TQVBoxLayout::TQVBoxLayout( TQLayout *parentLayout, int spacing,
			  const char *name )
    : TQBoxLayout( parentLayout, TopToBottom, spacing, name )
{
}

/*!
    Constructs a new vertical box called name \a name. You must add
    it to another tqlayout.

    The \a spacing is the default number of pixels between neighboring
    tqchildren. If \a spacing is -1, this TQVBoxLayout will inherit its
    tqparent's spacing().
*/
TQVBoxLayout::TQVBoxLayout( int spacing, const char *name )
    : TQBoxLayout( TopToBottom, spacing, name )
{
}

/*!
    Destroys this box tqlayout.

    The tqlayout's widgets aren't destroyed.
*/
TQVBoxLayout::~TQVBoxLayout()
{
}

TQBoxLayout *TQBoxLayout::createTmpCopy()
{
    TQBoxLayout *bl = new TQBoxLayout( direction() );
    delete bl->data;
    bl->data = data;
    return bl;
}

#endif // TQT_NO_LAYOUT