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
|
/**********************************************************************
This file is based on TQt Designer, Copyright (C) 2000 Trolltech AS. All rights reserved.
This file may be distributed and/or modified under the terms of the
GNU General Public License version 2 as published by the Free Software
Foundation and appearing in the file LICENSE.GPL included in the
packaging of this file.
This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
See http://www.trolltech.com/gpl/ for GPL licensing information.
Modified for Kommander:
(C) 2002-2003 Marc Britton <[email protected]>
(C) 2004 Michal Rudolf <[email protected]>
**********************************************************************/
// TQt includes
#include <tqaccel.h>
#include <tqapplication.h>
#include <tqbitmap.h>
#include <tqevent.h>
#include <tqfeatures.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqmap.h>
#include <tqmetaobject.h>
#include <tqobjectlist.h>
#include <tqpainter.h>
#include <tqpalette.h>
#include <tqpen.h>
#include <tqpixmapcache.h>
#include <tqpopupmenu.h>
#include <tqpushbutton.h>
#include <tqsizegrip.h>
#include <tqspinbox.h>
#include <statusbar.h>
#include <tqtimer.h>
#include <tqtooltip.h>
#include <tqwhatsthis.h>
// KDE includes
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <kstatusbar.h>
// Other includes
#include "formwindow.h"
#include "defs.h"
#include "mainwindow.h"
#include "widgetfactory.h"
#include "sizehandle.h"
#include "metadatabase.h"
#include "resource.h"
#include "tqlayout.h"
#include "connectioneditorimpl.h"
#include "widgetdatabase.h"
#include "pixmapchooser.h"
#include "orderindicator.h"
#include "hierarchyview.h"
#include "globaldefs.h"
#include "formfile.h"
#include <stdlib.h>
static void setCursorToAll(const TQCursor &c, TQWidget *start)
{
start->setCursor(c);
TQObjectList l = start->childrenListObject();
if (!l.isEmpty())
for (TQObject *o = l.first(); o; o = l.next())
{
if (o->isWidgetType() && !o->inherits("SizeHandle"))
setCursorToAll(c, ((TQWidget*)o));
}
}
static void restoreCursors(TQWidget *start, FormWindow *fw)
{
if (fw->widgets()->find(start))
start->setCursor(MetaDataBase::cursor(start));
else
start->setCursor(TQt::ArrowCursor);
TQObjectList l = start->childrenListObject();
if (!l.isEmpty())
for (TQObject *o = l.first(); o; o = l.next())
{
if (o->isWidgetType() && !o->inherits("SizeHandle"))
restoreCursors(((TQWidget*)o), fw);
}
}
/*
The FormWindow is the widget which is used as editor for forms. It
handles inserting, deleting, moving, resizing, etc. of widgets.
Normally multiple formwindows are used at the same time in the
Designer. So each formwindow has its own undo/redo buffer, etc.
Also the formwindow has some signals to inform e.g. about selection
changes which is interesting for the PropertyEditor.
For handling the events of the child widgets (moving, etc.) the
handleMousePress(), etc. functions are called from the application
event filter which is implemented in MainWindow::eventFilter().
*/
FormWindow::FormWindow(FormFile *f, MainWindow *mw, TQWidget *parent, const char *name)
: TQWidget(parent, name, WDestructiveClose), mainwindow(mw),
commands(100), pixInline(true)
{
ff = f;
init();
initSlots();
}
FormWindow::FormWindow(FormFile *f, TQWidget *parent, const char *name)
: TQWidget(parent, name, WDestructiveClose), mainwindow(0),
commands(100), pixInline(true)
{
ff = f;
init();
}
void FormWindow::init()
{
MetaDataBase::addEntry(TQT_TQOBJECT(this));
ff->setFormWindow(this);
propertyWidget = 0;
toolFixed = false;
checkedSelectionsForMove = false;
mContainer = 0;
connectSender = connectReceiver = 0;
currTool = POINTER_TOOL;
unclippedPainter = 0;
widgetPressed = false;
drawRubber = false;
setFocusPolicy(TQ_ClickFocus);
sizePreviewLabel = 0;
checkSelectionsTimer = new TQTimer(this, "checkSelectionsTimer");
connect(checkSelectionsTimer, TQT_SIGNAL(timeout()),
this, TQT_SLOT(invalidCheckedSelections()));
updatePropertiesTimer = new TQTimer(this);
connect(updatePropertiesTimer, TQT_SIGNAL(timeout()),
this, TQT_SLOT(updatePropertiesTimerDone()));
showPropertiesTimer = new TQTimer(this);
connect(showPropertiesTimer, TQT_SIGNAL(timeout()),
this, TQT_SLOT(showPropertiesTimerDone()));
selectionChangedTimer = new TQTimer(this);
connect(selectionChangedTimer, TQT_SIGNAL(timeout()),
this, TQT_SLOT(selectionChangedTimerDone()));
insertParent = 0;
connect(&commands, TQT_SIGNAL(undoRedoChanged(bool, bool, const TQString &, const TQString &)),
this, TQT_SIGNAL(undoRedoChanged(bool, bool, const TQString &, const TQString &)));
propShowBlocked = false;
setIcon(PixmapChooser::loadPixmap("form.xpm", PixmapChooser::Mini));
connect(&commands, TQT_SIGNAL(modificationChanged(bool)),
this, TQT_SLOT(modificationChanged(bool)));
buffer = 0;
TQWidget *w = WidgetFactory::create(WidgetDatabase::idFromClassName("TQFrame"), this);
setMainContainer(w);
propertyWidget = TQT_TQOBJECT(w);
targetContainer = 0;
hadOwnPalette = false;
defSpacing = BOXLAYOUT_DEFAULT_SPACING;
defMargin = BOXLAYOUT_DEFAULT_MARGIN;
}
void FormWindow::setMainWindow(MainWindow *w)
{
mainwindow = w;
MetaDataBase::addEntry(TQT_TQOBJECT(this));
initSlots();
}
void FormWindow::initSlots()
{
}
FormWindow::~FormWindow()
{
if (MainWindow::self->objectHierarchy()->formWindow() == this)
MainWindow::self->objectHierarchy()->setFormWindow(0, 0);
MetaDataBase::clear(TQT_TQOBJECT(this));
if (ff)
ff->setFormWindow(0);
}
void FormWindow::closeEvent(TQCloseEvent *e)
{
if (ff->closeEvent() && mainwindow->unregisterClient(this))
e->accept();
else
e->ignore();
}
void FormWindow::paintGrid(TQWidget *w, TQPaintEvent *e)
{
if (!mainWindow()->showGrid())
return;
TQPixmap grid;
TQString grid_name;
grid_name.sprintf("FormWindowGrid_%d_%d", mainWindow()->grid().x(), mainWindow()->grid().y());
if(!TQPixmapCache::find(grid_name, grid)) {
grid = TQPixmap(350 + (350 % mainWindow()->grid().x()), 350 + (350 % mainWindow()->grid().y()));
grid.fill(colorGroup().color(TQColorGroup::Foreground));
TQBitmap mask(grid.width(), grid.height());
mask.fill(color0);
TQPainter p(&mask);
p.setPen(color1);
for (int y = 0; y < grid.width(); y += mainWindow()->grid().y())
for (int x = 0; x < grid.height(); x += mainWindow()->grid().x())
p.drawPoint(x, y);
grid.setMask(mask);
TQPixmapCache::insert(grid_name, grid);
}
TQPainter p(w);
p.setClipRegion(e->rect());
p.drawTiledPixmap(TQRect(0, 0, width(), height()), grid);
}
/*For operations like drawing a rubber band or drawing the rect
when inserting a new widget, a unclipped painter (which draws also
on child widgets) is needed. This method does all the initialization.
*/
void FormWindow::beginUnclippedPainter(bool doNot)
{
endUnclippedPainter();
bool unclipped = testWFlags(WPaintUnclipped);
setWFlags(WPaintUnclipped);
unclippedPainter = new TQPainter;
unclippedPainter->begin(this);
if (!unclipped)
clearWFlags(WPaintUnclipped);
if (doNot)
{
unclippedPainter->setPen(TQPen(color0, 2));
unclippedPainter->setRasterOp(NotROP);
}
}
void FormWindow::endUnclippedPainter()
{
if (unclippedPainter)
unclippedPainter->end();
delete unclippedPainter;
unclippedPainter = 0;
}
TQPoint FormWindow::gridPoint(const TQPoint &p)
{
return TQPoint((p.x() / grid().x()) * grid().x(),
(p.y() / grid().y()) * grid().y());
}
void FormWindow::drawSizePreview(const TQPoint &pos, const TQString& text)
{
unclippedPainter->save();
unclippedPainter->setPen(TQPen(colorGroup().foreground(), 1 ));
unclippedPainter->setRasterOp(CopyROP);
if (!sizePreviewPixmap.isNull())
unclippedPainter->drawPixmap(sizePreviewPos, sizePreviewPixmap);
if (text.isNull()) {
sizePreviewPixmap = TQPixmap(); // set null again
unclippedPainter->restore();
return;
}
TQRect r = fontMetrics().boundingRect(0, 0, 0, 0, AlignCenter, text);
r = TQRect(pos + TQPoint(10, 10), r.size() + TQSize(5, 5));
checkPreviewGeometry(r);
sizePreviewPos = r.topLeft();
sizePreviewPixmap = TQPixmap::grabWindow(winId(), r.x(), r.y(), r.width(), r.height());
unclippedPainter->setBrush(TQColor(255, 255, 128));
unclippedPainter->drawRect(r);
unclippedPainter->drawText(r, AlignCenter, text);
unclippedPainter->restore();
}
void FormWindow::insertWidget()
{
if (!insertParent || currTool == POINTER_TOOL)
return;
bool useSizeHint = !oldRectValid || (currRect.width() < 2 && currRect.height() < 2);
Qt::Orientation orient =Qt::Horizontal;
TQString n = WidgetDatabase::className(currTool);
if (useSizeHint && (n == "Spacer" || n == "TQSlider" || n == "Line" || n == "TQScrollBar")) {
TQPopupMenu m(mainWindow());
m.insertItem(i18n("&Horizontal"));
int ver = m.insertItem(i18n("&Vertical"));
int r = m.exec(TQCursor::pos());
if (r == ver)
orient =Qt::Vertical;
}
TQWidget *w = WidgetFactory::create(currTool, insertParent, 0, true, &currRect, orient);
if (!w)
return;
if (!savePixmapInline() && currTool == WidgetDatabase::idFromClassName("PixmapLabel"))
((TQLabel*)w)->setPixmap(PixmapChooser::loadPixmap("image.xpm"));
int id = WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(TQT_TQOBJECT(w)));
if (WidgetDatabase::isCustomWidget(id)) {
TQWhatsThis::add(w, i18n("<b>A %1 (custom widget)</b> "
"<p>Click <b>Edit Custom Widgets...</b> in the <b>Tools|Custom</b> "
"menu to add and change custom widgets. You can add "
"properties as well as signals and slots to integrate custom widgets into "
"<i>TQt Designer</i>, and provide a pixmap which will be used to represent "
"the widget on the form.</p>")
.arg(WidgetDatabase::toolTip(id)));
TQToolTip::add(w, i18n("A %1 (custom widget)").arg(WidgetDatabase::toolTip(id)));
}
else
{
TQString tt = WidgetDatabase::toolTip(id);
TQString wt = WidgetDatabase::whatsThis(id);
if (!wt.isEmpty() && !tt.isEmpty())
TQWhatsThis::add(w, i18n("<b>A %1</b><p>%2</p>").arg(tt).arg(wt));
}
TQString s = w->name();
unify(TQT_TQOBJECT(w), s, true);
w->setName(s.utf8());
insertWidget(w);
TQRect r(currRect);
if (!oldRectValid || (currRect.width() < 2 && currRect.height() < 2))
r = TQRect(rectAnchor, TQSize(0, 0));
TQPoint p = r.topLeft();
p = mapToGlobal(p);
p = insertParent->mapFromGlobal(p);
r = TQRect(p, r.size());
if (useSizeHint)
{
r.setWidth(w->sizeHint().width());
r.setHeight(w->sizeHint().height());
}
if (r.width() < 2 * grid().x())
r.setWidth(2 * grid().x());
if (r.height() < 2 * grid().y())
r.setHeight(2 * grid().y());
const TQObjectList l = insertParent->childrenListObject();
TQObjectListIt it(l);
TQWidgetList lst;
if (WidgetDatabase::isContainer(WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(TQT_TQOBJECT(w)))))
for (; it.current();) {
TQObject *o = it.current();
++it;
if (o->isWidgetType() && ((TQWidget*)o)->isVisibleTo(this) &&
insertedWidgets.find((TQWidget*)o) && TQT_BASE_OBJECT(o) != TQT_BASE_OBJECT(w))
{
TQRect r2(((TQWidget*)o)->pos(), ((TQWidget*)o)->size());
if (r.contains(r2))
lst.append((TQWidget*)o);
}
}
if (!lst.isEmpty())
{
TQWidget *pw = WidgetFactory::containerOfWidget(w);
TQValueList<TQPoint> op, np;
for (TQWidget *i = lst.first(); i; i = lst.next())
{
op.append(i->pos());
TQPoint pos = pw->mapFromGlobal(i->mapToGlobal(TQPoint(0, 0)));
pos -= r.topLeft();
np.append(pos);
}
MoveCommand *mv = new MoveCommand(i18n("Reparent Widgets"), this, lst, op, np, insertParent, pw);
if (!toolFixed)
mainwindow->resetTool();
else
setCursorToAll(CrossCursor, w);
InsertCommand *cmd = new InsertCommand(i18n("Insert %1").arg(w->name()), this, w, r);
TQPtrList<Command> commands;
commands.append(mv);
commands.append(cmd);
MacroCommand *mc = new MacroCommand(i18n("Insert %1").arg(w->name()), this, commands);
commandHistory()->addCommand(mc);
mc->execute();
}
else
{
if (!toolFixed)
mainwindow->resetTool();
else
setCursorToAll(CrossCursor, w);
InsertCommand *cmd = new InsertCommand(i18n("Insert %1").arg(w->name()), this, w, r);
commandHistory()->addCommand(cmd);
cmd->execute();
}
}
void FormWindow::insertWidget(TQWidget *w, bool checkName)
{
if (checkName) {
TQString s = w->name();
unify(TQT_TQOBJECT(w), s, true);
w->setName(s.utf8());
}
MetaDataBase::addEntry(TQT_TQOBJECT(w));
int id = WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(TQT_TQOBJECT(w)));
if (WidgetDatabase::isCustomWidget(id))
{
TQWhatsThis::add(w, i18n("<b>A %1 (custom widget)</b> "
"<p>Click <b>Edit Custom Widgets...</b> in the <b>Tools|Custom</b> "
"menu to add and change custom widgets. You can add "
"properties as well as signals and slots to integrate custom widgets into "
"<i>TQt Designer</i>, and provide a pixmap which will be used to represent "
"the widget on the form.</p>")
.arg(WidgetDatabase::toolTip(id)));
TQToolTip::add(w, i18n("A %1 (custom widget)").arg(WidgetDatabase::toolTip(id)));
}
else
{
TQString tt = WidgetDatabase::toolTip(id);
TQString wt = WidgetDatabase::whatsThis(id);
if (!wt.isEmpty() && !tt.isEmpty())
TQWhatsThis::add(w, i18n("<b>A %1</b><p>%2</p>").arg(tt).arg(wt));
}
restoreCursors(w, this);
widgets()->insert(w, w);
w->show();
}
void FormWindow::removeWidget(TQWidget *w)
{
MetaDataBase::removeEntry(TQT_TQOBJECT(w));
widgets()->take(w);
}
void FormWindow::handleContextMenu(TQContextMenuEvent *e, TQWidget *w)
{
switch (currTool) {
case POINTER_TOOL:
if (!isMainContainer(TQT_TQOBJECT(w)) && qstrcmp(w->name(), "central widget"))
{ // press on a child widget
raiseChildSelections(w); // raise selections and select widget
selectWidget(TQT_TQOBJECT(w));
// if widget is laid out, find the first non-laid out super-widget
TQWidget *realWidget = w; // but store the original one
while (w->parentWidget() && (WidgetFactory::layoutType(w->parentWidget()) !=
WidgetFactory::NoLayout || !insertedWidgets.find(w)))
w = w->parentWidget();
if (mainContainer()->inherits("TQMainWindow") &&
((TQMainWindow*)mainContainer())->centralWidget() == realWidget)
{
e->accept();
mainwindow->popupFormWindowMenu(e->globalPos(), this);
}
else
{
e->accept();
mainwindow->popupWidgetMenu(e->globalPos(), this, realWidget);
}
}
else
{
e->accept();
clearSelection();
mainwindow->popupFormWindowMenu(e->globalPos(), this);
}
break;
default:
break;
}
}
void FormWindow::handleMousePress(TQMouseEvent *e, TQWidget *w)
{
checkedSelectionsForMove = false;
checkSelectionsTimer->stop();
if (!sizePreviewLabel) {
sizePreviewLabel = new TQLabel(this);
sizePreviewLabel->hide();
sizePreviewLabel->setBackgroundColor(TQColor(255, 255, 128));
sizePreviewLabel->setFrameStyle(TQFrame::Plain | TQFrame::Box);
}
switch (currTool) {
case POINTER_TOOL:
if (!isMainContainer(TQT_TQOBJECT(w)) && qstrcmp(w->name(), "central widget") != 0)
{ // press on a child widget
// if the clicked widget is not in a layout, raise it
if (!w->parentWidget() || WidgetFactory::layoutType(w->parentWidget()) == WidgetFactory::NoLayout)
w->raise();
if ((e->state() & ControlButton))
{ // with control pressed, always start rubber band selection
drawRubber = true;
currRect = TQRect(0, 0, -1, -1);
startRectDraw(mapFromGlobal(e->globalPos()), e->globalPos(), this, Rubber);
break;
}
bool sel = isWidgetSelected(TQT_TQOBJECT(w));
if (!((e->state() & ControlButton) || (e->state() & ShiftButton)))
{ // control not pressed...
if (!sel) // ...and widget no selectted: unselect all
clearSelection(false);
else
{ // ...widget selected
// only if widget has a layout (it is a layout meta widget or a laid out container!),
// unselect its childs
if (WidgetFactory::layoutType(w) != WidgetFactory::NoLayout)
{
TQObjectList *l = w->queryList("TQWidget");
setPropertyShowingBlocked(true);
for (TQObject *o = l->first(); o; o = l->next())
{
if (!o->isWidgetType())
continue;
if (insertedWidgets.find((TQWidget*)o))
selectWidget(TQT_TQOBJECT(o), false);
}
setPropertyShowingBlocked(false);
delete l;
}
}
tqApp->processEvents();
}
if (((e->state() & ControlButton) || (e->state() & ShiftButton)) &&
sel && e->button() == Qt::LeftButton)
{ // control pressed and selected, unselect widget
selectWidget(TQT_TQOBJECT(w), false);
break;
}
raiseChildSelections(w); // raise selections and select widget
selectWidget(TQT_TQOBJECT(w));
// if widget is laid out, find the first non-laid out super-widget
while (w->parentWidget() &&
(WidgetFactory::layoutType(w->parentWidget()) != WidgetFactory::NoLayout
|| !insertedWidgets.find(w)))
w = w->parentWidget();
if (e->button() == Qt::LeftButton)
{ // left button: store original geometry and more as the widget might start moving
widgetPressed = true;
widgetGeom = TQRect(w->pos(), w->size());
oldPressPos = w->mapFromGlobal(e->globalPos());
origPressPos = oldPressPos;
checkedSelectionsForMove = false;
moving.clear();
if (w->parentWidget() && !isMainContainer(TQT_TQOBJECT(w->parentWidget())) &&
!isCentralWidget(TQT_TQOBJECT(w->parentWidget())))
{
targetContainer = w->parentWidget();
hadOwnPalette = w->parentWidget()->ownPalette();
restorePalette = w->parentWidget()->palette();
}
}
}
else
{ // press was on the formwindow
if (e->button() == Qt::LeftButton)
{ // left button: start rubber selection and show formwindow properties
drawRubber = true;
if (!((e->state() & ControlButton) || (e->state() & ShiftButton)))
{
clearSelection(false);
TQObject *opw = propertyWidget;
propertyWidget = TQT_TQOBJECT(mainContainer());
if (opw->isWidgetType())
repaintSelection((TQWidget*)opw);
}
currRect = TQRect(0, 0, -1, -1);
startRectDraw(mapFromGlobal(e->globalPos()), e->globalPos(), this, Rubber);
}
}
break;
case CONNECT_TOOL:
if (e->button() != Qt::LeftButton)
break;
saveBackground();
mainWindow()->statusBar()->message(i18n("Connect '%1' with...").arg(w->name()));
connectStartPos = mapFromGlobal(e->globalPos());
currentConnectPos = mapFromGlobal(e->globalPos());
connectSender = TQT_TQOBJECT(designerWidget(TQT_TQOBJECT(w)));
connectReceiver = connectableObject(TQT_TQOBJECT(designerWidget(TQT_TQOBJECT(w))), connectReceiver);
beginUnclippedPainter(false);
drawConnectLine();
break;
case ORDER_TOOL:
if (!isMainContainer(TQT_TQOBJECT(w)))
{ // press on a child widget
orderedWidgets.removeRef(w);
orderedWidgets.append(w);
for (TQWidget *wid = orderedWidgets.last(); wid; wid = orderedWidgets.prev())
{
int i = stackedWidgets.findRef(wid);
if (i != -1)
{
stackedWidgets.removeRef(wid);
stackedWidgets.insert(0, wid);
}
}
TQWidgetList oldl = MetaDataBase::tabOrder(this);
TabOrderCommand *cmd = new TabOrderCommand(i18n("Change Tab Order"), this,
oldl, stackedWidgets);
cmd->execute();
commandHistory()->addCommand(cmd, true);
updateOrderIndicators();
}
break;
default: // any insert widget tool
if (e->button() == Qt::LeftButton)
{
insertParent = WidgetFactory::containerOfWidget(mainContainer());
// default parent for new widget is the formwindow
if (!isMainContainer(TQT_TQOBJECT(w)))
{ // press was not on formwindow, check if we can find another parent
TQWidget *wid = w;
for (;;)
{
int id = WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(TQT_TQOBJECT(wid)));
if ((WidgetDatabase::isContainer(id) || wid == mainContainer()) &&
!wid->inherits("TQLayoutWidget") && !wid->inherits("TQSplitter"))
{
insertParent = WidgetFactory::containerOfWidget(wid); // found another parent, store it
break;
}
else
{
wid = wid->parentWidget();
if (!wid)
break;
}
}
}
startRectDraw(w->mapFromGlobal(e->globalPos()), e->globalPos(), w, Insert);
}
break;
}
}
void FormWindow::handleMouseDblClick(TQMouseEvent *, TQWidget *w)
{
switch (currTool) {
case ORDER_TOOL:
if (!isMainContainer(TQT_TQOBJECT(w)))
{ // press on a child widget
orderedWidgets.clear();
orderedWidgets.append(w);
for (TQWidget *wid = orderedWidgets.last(); wid; wid = orderedWidgets.prev())
{
int i = stackedWidgets.findRef(wid);
if (i != -1)
{
stackedWidgets.removeRef(wid);
stackedWidgets.insert(0, wid);
}
}
TQWidgetList oldl = MetaDataBase::tabOrder(this);
TabOrderCommand *cmd = new TabOrderCommand(i18n("Change Tab Order"), this, oldl, stackedWidgets);
cmd->execute();
commandHistory()->addCommand(cmd, true);
updateOrderIndicators();
}
default:
break;
}
}
void FormWindow::handleMouseMove(TQMouseEvent *e, TQWidget *w)
{
if ((e->state() & Qt::LeftButton) != Qt::LeftButton)
return;
TQWidget *newReceiver = (TQWidget*)connectReceiver, *oldReceiver = (TQWidget*)connectReceiver, *wid;
bool drawRecRect;
switch (currTool) {
case POINTER_TOOL:
if (widgetPressed && allowMove(w))
{ // we are prepated for a move
// if widget is laid out, find the first non-laid out super-widget
while (w->parentWidget() && (WidgetFactory::layoutType(w->parentWidget()) !=
WidgetFactory::NoLayout || !insertedWidgets.find(w)))
w = w->parentWidget();
// calc correct position
TQPoint pos = w->mapFromGlobal(e->globalPos());
// calc move distance and store it
TQPoint d = oldPressPos - pos;
if (TQABS(d.x()) < grid().x())
d.setX(0);
if (TQABS(d.y()) < grid().y())
d.setY(0);
if (d.x() == 0)
pos.setX(oldPressPos.x());
if (d.y() == 0)
pos.setY(oldPressPos.y());
oldPressPos = pos;
// snap to grid
int x = widgetGeom.x() - d.x();
widgetGeom.setX(x);
x = (x / grid().x()) * grid().x();
int y = widgetGeom.y() - d.y();
widgetGeom.setY(y);
y = (y / grid().y()) * grid().y();
TQPoint p = w->pos();
if (x - p.x() || y - p.y())
{ // if we actually have to move
if (!checkedSelectionsForMove)
{ // if not checked yet, check if the correct widget are selected...
if (!isWidgetSelected(TQT_TQOBJECT(w)))
{ // and unselect others. Only siblings can be moved at the same time
setPropertyShowingBlocked(true);
selectWidget(TQT_TQOBJECT(w));
setPropertyShowingBlocked(false);
}
checkSelectionsForMove(w);
}
// check whether we would have to reparent the selection and
// highlight the possible new parent container
TQMapConstIterator<ulong, TQPoint> it = moving.begin();
TQWidget* wa = containerAt(e->globalPos(), ((TQWidget*)it.key()));
if (wa && !isMainContainer(TQT_TQOBJECT(wa)) && !isCentralWidget(TQT_TQOBJECT(wa)))
{
wa = WidgetFactory::containerOfWidget(wa);
// ok, looks like we moved onto a container
if (wa != targetContainer)
{
if (targetContainer)
{
if (hadOwnPalette)
targetContainer->setPalette(restorePalette);
else
targetContainer->unsetPalette();
}
targetContainer = wa;
hadOwnPalette = wa->ownPalette();
restorePalette = wa->palette();
wa->setPaletteBackgroundColor(wa->colorGroup().midlight());
}
}
else if (targetContainer)
{
if(hadOwnPalette)
targetContainer->setPalette(restorePalette);
else
targetContainer->unsetPalette();
targetContainer = 0;
}
// finally move the selected widgets and show/update preview label
moveSelectedWidgets(x - p.x(), y - p.y());
sizePreviewLabel->setText(TQString("%1/%2").arg(w->pos().x()).arg(w->pos().y()));
sizePreviewLabel->adjustSize();
TQRect lg(mapFromGlobal(e->globalPos()) + TQPoint(16, 16), sizePreviewLabel->size());
checkPreviewGeometry(lg);
sizePreviewLabel->setGeometry(lg);
sizePreviewLabel->raise();
sizePreviewLabel->show();
}
else
{ // if we don't need to move, do some indication
TQRect lg(mapFromGlobal(e->globalPos()) + TQPoint(16, 16), sizePreviewLabel->size());
checkPreviewGeometry(lg);
sizePreviewLabel->move(lg.x(), lg.y());
}
oldPressPos += (p - w->pos());
}
else if (drawRubber)
// draw rubber if we are in rubber-selection mode
continueRectDraw(mapFromGlobal(e->globalPos()), e->globalPos(), this, Rubber);
break;
case CONNECT_TOOL:
restoreConnectionLine();
wid = tqApp->widgetAt(e->globalPos(), true);
if (wid)
wid = designerWidget(TQT_TQOBJECT(wid));
if (wid && (isMainContainer(TQT_TQOBJECT(wid)) || insertedWidgets.find(wid)) && wid->isVisibleTo(this))
newReceiver = wid;
if (newReceiver && (newReceiver->inherits("TQLayoutWidget")
|| newReceiver->inherits("Spacer")))
newReceiver = (TQWidget*)connectReceiver;
drawRecRect = TQT_BASE_OBJECT(newReceiver) != TQT_BASE_OBJECT(connectReceiver);
currentConnectPos = mapFromGlobal(e->globalPos());
if (newReceiver && (isMainContainer(TQT_TQOBJECT(newReceiver))
|| insertedWidgets.find(newReceiver)) && !isCentralWidget(TQT_TQOBJECT(newReceiver)))
connectReceiver = connectableObject(TQT_TQOBJECT(newReceiver), TQT_TQOBJECT(connectReceiver));
mainWindow()->statusBar()->message(i18n("Connect '%1' to '%2'").arg(connectSender->name()).
arg(connectReceiver->name()));
tqApp->processEvents();
if (drawRecRect)
restoreRect(TQRect(mapToForm(((TQWidget*)oldReceiver)->parentWidget(),
((TQWidget*)oldReceiver)->pos()), ((TQWidget*)oldReceiver)->size()));
drawConnectLine();
break;
case ORDER_TOOL:
break;
default: // we are in an insert-widget tool
if (insertParent) // draw insert rect
continueRectDraw(w->mapFromGlobal(e->globalPos()), e->globalPos(), w, Insert);
break;
}
}
void FormWindow::handleMouseRelease(TQMouseEvent * e, TQWidget * w)
{
if (e->button() != Qt::LeftButton)
return;
switch (currTool)
{
case POINTER_TOOL:
if (widgetPressed && allowMove(w))
{ // we moved the widget
sizePreviewLabel->hide();
if (moving.isEmpty() || w->pos() == *moving.find((ulong) w))
break;
// restore targetContainer
if (targetContainer)
{
if (hadOwnPalette)
targetContainer->setPalette(restorePalette);
else
targetContainer->unsetPalette();
}
// tell property editor to update
if (propertyWidget && propertyWidget->isWidgetType() && !isMainContainer(propertyWidget))
emitUpdateProperties(propertyWidget);
TQMapConstIterator < ulong, TQPoint > it = moving.begin();
TQWidget *oldParent = ((TQWidget *) it.key())->parentWidget();
TQWidget *newParent = oldParent;
// check whether we have to reparent the selection
TQWidget *wa = containerAt(e->globalPos(), ((TQWidget *) it.key()));
if (wa)
{
wa = WidgetFactory::containerOfWidget(wa);
// ok, looks like we moved onto a container
// check whether we really have different parents.
if (wa == ((TQWidget *) it.key())->parentWidget())
goto make_move_command;
// break layout if necessary
if (WidgetFactory::layoutType(wa) != WidgetFactory::NoLayout)
{
if (KMessageBox::questionYesNo(mainWindow(),
i18n("You tried to insert a widget into the "
"layout Container Widget '%1'.\n"
"This is not possible. "
"In order to insert the widget, the layout of '%1'\n"
"must first be broken.\n"
"Break the layout or cancel the operation?").
arg(wa->name()).arg(wa->name()), i18n("Inserting Widget"),
i18n("&Break Layout"), KStdGuiItem::cancel()) == KMessageBox::No)
goto make_move_command; // cancel
breakLayout(wa);
}
// doesn't need to be a command, the MoveCommand does reparenting too
bool emitSelChanged = false;
for (TQMap < ulong, TQPoint >::Iterator it = moving.begin(); it != moving.end(); ++it)
{
TQWidget *i = (TQWidget *) it.key();
if (!emitSelChanged && i->inherits("TQButton"))
{
if (i->parentWidget() && i->parentWidget()->inherits("TQButtonGroup") ||
wa->inherits("TQButtonGroup"))
emitSelChanged = true;
if (!wa->inherits("TQButtonGroup"))
{
MetaDataBase::setPropertyChanged(TQT_TQOBJECT(i), "buttonGroupId", false);
if (i->parentWidget() && i->parentWidget()->inherits("TQButtonGroup"))
((TQButtonGroup *) i->parentWidget())->remove((TQButton *) i);
}
}
TQPoint pos = wa->mapFromGlobal(i->mapToGlobal(TQPoint(0, 0)));
i->reparent(wa, pos, true);
raiseSelection(i);
raiseChildSelections(i);
widgetChanged(TQT_TQOBJECT(i));
mainWindow()->objectHierarchy()->widgetRemoved(i);
mainWindow()->objectHierarchy()->widgetInserted(i);
}
if (emitSelChanged)
{
emit showProperties(TQT_TQOBJECT(wa));
emit showProperties(propertyWidget);
}
newParent = wa;
}
make_move_command:
TQWidgetList widgets; // collect the widgets and its old and new positions which have been moved
TQValueList < TQPoint > oldPos, newPos;
for (it = moving.begin(); it != moving.end(); ++it)
{
widgets.append((TQWidget *) it.key());
oldPos.append(*it);
newPos.append(((TQWidget *) it.key())->pos());
}
// add move command, don't execute it, this is just a summary of the operations we did during the move-event handling
commandHistory()->addCommand(new MoveCommand(i18n("Move"),
this, widgets, oldPos, newPos, oldParent, newParent));
} else if (drawRubber)
{ // we were drawing a rubber selection
endRectDraw(); // get rid of the rectangle
blockSignals(true);
selectWidgets(); // select widgets which intersect the rect
blockSignals(false);
emitSelectionChanged(); // inform about selection changes
if (propertyWidget)
emitShowProperties(propertyWidget);
}
break;
case CONNECT_TOOL:
restoreConnectionLine();
if (connectSender)
restoreRect(TQRect(mapToForm(((TQWidget *) connectSender)->parentWidget(),
((TQWidget *) connectSender)->pos()), ((TQWidget *) connectSender)->size()));
if (connectReceiver)
restoreRect(TQRect(mapToForm(((TQWidget *) connectReceiver)->parentWidget(),
((TQWidget *) connectReceiver)->pos()), ((TQWidget *) connectReceiver)->size()));
endUnclippedPainter();
tqApp->processEvents();
if (connectSender && connectReceiver)
editConnections();
break;
case ORDER_TOOL:
break;
default: // any insert widget tool is active
if (insertParent)
{ // we should insert the new widget now
endRectDraw();
if (WidgetFactory::layoutType(insertParent) != WidgetFactory::NoLayout)
{
if (KMessageBox::questionYesNo(mainWindow(),
i18n("You tried to insert a widget into the "
"layout Container Widget '%1'.\n"
"This is not possible. "
"In order to insert the widget, the layout of '%1'\n"
"must first be broken.\n"
"Break the layout or cancel the operation?").
arg(insertParent->name()).
arg(insertParent->name()), i18n("Inserting Widget"),
i18n("&Break Layout"), KStdGuiItem::cancel()) == KMessageBox::Yes)
{
breakLayout(insertParent);
} else
{
if (!toolFixed)
mainWindow()->resetTool();
break;
}
}
insertWidget(); // so do it
}
break;
}
widgetPressed = false;
drawRubber = false;
insertParent = 0;
delete buffer;
buffer = 0;
}
void FormWindow::handleKeyPress(TQKeyEvent * e, TQWidget * w)
{
e->ignore();
checkSelectionsTimer->stop();
if (!checkedSelectionsForMove &&
(e->key() == Key_Left ||
e->key() == Key_Right ||
e->key() == Key_Up || e->key() == Key_Down) && propertyWidget->isWidgetType())
checkSelectionsForMove((TQWidget *) propertyWidget);
checkSelectionsTimer->start(1000, true);
if (e->key() == Key_Left || e->key() == Key_Right || e->key() == Key_Up || e->key() == Key_Down)
{
TQWidgetList widgets;
TQValueList < TQPoint > oldPos, newPos;
for (WidgetSelection * s = selections.first(); s; s = selections.next())
{
if (s->isUsed())
{
int dx = 0, dy = 0;
bool control = e->state() & ControlButton;
switch (e->key())
{
case Key_Left:
{
e->accept();
if (control)
dx = -1;
else
dx = -grid().x();
}
break;
case Key_Right:
{
e->accept();
if (control)
dx = 1;
else
dx = grid().x();
}
break;
case Key_Up:
{
e->accept();
if (control)
dy = -1;
else
dy = -grid().y();
}
break;
case Key_Down:
{
e->accept();
if (control)
dy = 1;
else
dy = grid().y();
}
break;
default:
break;
}
widgets.append(s->widget());
oldPos.append(s->widget()->pos());
newPos.append(s->widget()->pos() + TQPoint(dx, dy));
}
}
if (!widgets.isEmpty())
{
MoveCommand *cmd = new MoveCommand(i18n("Move"), this,
widgets, oldPos, newPos, 0, 0);
commandHistory()->addCommand(cmd, true);
cmd->execute();
}
}
if (!e->isAccepted())
{
TQObjectList *l = queryList("TQWidget");
if (!l)
return;
if (l->find(TQT_TQOBJECT(w)) != -1)
e->accept();
delete l;
}
}
void FormWindow::handleKeyRelease(TQKeyEvent * e, TQWidget *)
{
e->ignore();
}
void FormWindow::selectWidget(TQObject * o, bool select)
{
if (!o->isWidgetType())
{
// ########### do TQObject stuff
return;
}
TQWidget *w = (TQWidget *) o;
if (isMainContainer(TQT_TQOBJECT(w)))
{
TQObject *opw = propertyWidget;
propertyWidget = TQT_TQOBJECT(mainContainer());
if (opw->isWidgetType())
repaintSelection((TQWidget *) opw);
emitShowProperties(propertyWidget);
return;
}
if (mainContainer()->inherits("TQMainWindow") &&
w == ((TQMainWindow *) mainContainer())->centralWidget())
{
TQObject *opw = propertyWidget;
propertyWidget = TQT_TQOBJECT(mainContainer());
if (opw->isWidgetType())
repaintSelection((TQWidget *) opw);
emitShowProperties(propertyWidget);
return;
}
if (o->inherits("QDesignerToolBar") || o->inherits("QDesignerMenuBar"))
return;
if (select)
{
TQObject *opw = propertyWidget;
propertyWidget = TQT_TQOBJECT(w);
if (opw->isWidgetType())
repaintSelection((TQWidget *) opw);
if (!isPropertyShowingBlocked())
emitShowProperties(propertyWidget);
WidgetSelection *s = usedSelections.find(w);
if (s)
{
s->show();
return;
}
for (WidgetSelection * s2 = selections.first(); s2; s2 = selections.next())
{
if (!s2->isUsed())
{
s = s2;
}
}
if (!s)
{
s = new WidgetSelection(this, &usedSelections);
selections.append(s);
}
s->setWidget(w);
emitSelectionChanged();
} else
{
WidgetSelection *s = usedSelections.find(w);
if (s)
s->setWidget(0);
TQObject *opw = propertyWidget;
if (!usedSelections.isEmpty())
propertyWidget = TQT_TQOBJECT(TQPtrDictIterator < WidgetSelection > (usedSelections).current()->widget());
else
propertyWidget = TQT_TQOBJECT(mainContainer());
if (opw->isWidgetType())
repaintSelection((TQWidget *) opw);
if (!isPropertyShowingBlocked())
emitShowProperties(propertyWidget);
emitSelectionChanged();
}
}
TQPoint FormWindow::grid() const
{
if (!mainWindow()->snapGrid())
return TQPoint(1, 1);
return mainWindow()->grid();
}
void FormWindow::updateSelection(TQWidget * w)
{
WidgetSelection *s = usedSelections.find(w);
if (!w->isVisibleTo(this))
selectWidget(TQT_TQOBJECT(w), false);
else if (s)
s->updateGeometry();
}
void FormWindow::raiseSelection(TQWidget * w)
{
WidgetSelection *s = usedSelections.find(w);
if (s)
s->show();
}
void FormWindow::repaintSelection(TQWidget * w)
{
WidgetSelection *s = usedSelections.find(w);
if (s)
s->update();
}
void FormWindow::clearSelection(bool changePropertyDisplay)
{
TQPtrDictIterator < WidgetSelection > it(usedSelections);
for (; it.current(); ++it)
it.current()->setWidget(0, false);
usedSelections.clear();
if (changePropertyDisplay)
{
TQObject *opw = propertyWidget;
propertyWidget = TQT_TQOBJECT(mainContainer());
if (opw->isWidgetType())
repaintSelection((TQWidget *) opw);
emitShowProperties(propertyWidget);
}
emitSelectionChanged();
}
void FormWindow::startRectDraw(const TQPoint & p, const TQPoint & global, TQWidget *, RectType t)
{
TQPoint pos(p);
pos = mapFromGlobal(global);
oldRectValid = false;
beginUnclippedPainter(true);
if (t == Rubber)
unclippedPainter->setPen(TQPen(color0, 1));
if (t == Insert)
rectAnchor = gridPoint(pos);
else if (t == Rubber)
rectAnchor = pos;
currRect = TQRect(rectAnchor, TQPoint(0, 0));
if (t == Insert)
drawSizePreview(pos, i18n("Use Size Hint"));
}
void FormWindow::continueRectDraw(const TQPoint & p, const TQPoint & global, TQWidget *, RectType t)
{
TQPoint pos = p;
pos = mapFromGlobal(global);
TQPoint p2;
if (t == Insert)
p2 = gridPoint(pos);
else if (t == Rubber)
p2 = pos;
TQRect r(rectAnchor, p2);
r = r.normalize();
if (currRect == r)
{
TQString t("%1/%2");
t = t.arg(r.width() - 1).arg(r.height() - 1);
drawSizePreview(pos, t);
return;
}
if (oldRectValid)
unclippedPainter->drawRect(currRect);
if (r.width() > 1 || r.height() > 1)
{
oldRectValid = true;
currRect = r;
if (t == Insert)
{
TQString t("%1/%2");
t = t.arg(r.width() - 1).arg(r.height() - 1);
drawSizePreview(pos, t);
}
unclippedPainter->setClipRegion(TQRegion(rect()).subtract(TQRect(sizePreviewPos,
sizePreviewPixmap.size())));
unclippedPainter->drawRect(currRect);
unclippedPainter->setClipping(false);
} else
{
oldRectValid = false;
if (t == Insert)
drawSizePreview(pos, i18n("Use Size Hint"));
}
}
void FormWindow::endRectDraw()
{
if (!unclippedPainter)
return;
if (oldRectValid)
unclippedPainter->drawRect(currRect);
drawSizePreview(TQPoint(-1, -1), TQString());
endUnclippedPainter();
}
void FormWindow::selectWidgets()
{
TQObjectList *l = mainContainer()->queryList("TQWidget");
if (l)
{
for (TQObject * o = l->first(); o; o = l->next())
{
if (((TQWidget *) o)->isVisibleTo(this) && insertedWidgets[(void *) o])
{
TQPoint p = ((TQWidget *) o)->mapToGlobal(TQPoint(0, 0));
p = mapFromGlobal(p);
TQRect r(p, ((TQWidget *) o)->size());
if (r.intersects(currRect) && !r.contains(currRect))
selectWidget(TQT_TQOBJECT(o));
}
}
delete l;
}
emitSelectionChanged();
}
bool FormWindow::isWidgetSelected(TQObject * w)
{
if (w->isWidgetType())
return usedSelections.find((TQWidget *) w) != 0;
return false; // #### do stuff for TQObjects
}
void FormWindow::moveSelectedWidgets(int dx, int dy)
{
TQPtrDictIterator < WidgetSelection > it(usedSelections);
for (; it.current(); ++it)
{
WidgetSelection *s = it.current();
TQWidget *w = s->widget();
if (w->parentWidget()
&& WidgetFactory::layoutType(w->parentWidget()) != WidgetFactory::NoLayout)
continue;
w->move(w->x() + dx, w->y() + dy);
s->updateGeometry();
updateChildSelections(w);
}
}
CommandHistory *FormWindow::commandHistory()
{
return &commands;
}
void FormWindow::undo()
{
commandHistory()->undo();
}
void FormWindow::redo()
{
commandHistory()->redo();
}
void FormWindow::raiseChildSelections(TQWidget * w)
{
TQObjectList *l = w->queryList("TQWidget");
if (!l || !l->first())
{
delete l;
return;
}
TQPtrDictIterator < WidgetSelection > it(usedSelections);
for (; it.current(); ++it)
{
if (l->findRef(TQT_TQOBJECT(it.current()->widget())) != -1)
it.current()->show();
}
delete l;
}
void FormWindow::updateChildSelections(TQWidget * w)
{
TQObjectList *l = w->queryList("TQWidget");
if (l)
{
for (TQObject * o = l->first(); o; o = l->next())
{
if (o->isWidgetType() && insertedWidgets.find((TQWidget *) o))
updateSelection((TQWidget *) o);
}
delete l;
}
}
void FormWindow::checkSelectionsForMove(TQWidget * w)
{
checkedSelectionsForMove = true;
TQObjectList *l = w->parentWidget()->queryList("TQWidget", 0, false, false);
moving.clear();
if (l)
{
TQPtrDictIterator < WidgetSelection > it(usedSelections);
WidgetSelection *sel;
while ((sel = it.current()) != 0)
{
if (it.current()->widget() == mainContainer())
continue;
++it;
if (l->find(TQT_TQOBJECT(sel->widget())) == -1)
{
if (WidgetFactory::layoutType(w) == WidgetFactory::NoLayout)
sel->setWidget(0);
} else
{
if (WidgetFactory::layoutType(sel->widget()->parentWidget()) == WidgetFactory::NoLayout)
{
moving.insert((ulong) sel->widget(), sel->widget()->pos());
sel->widget()->raise();
raiseChildSelections(sel->widget());
raiseSelection(sel->widget());
}
}
}
delete l;
}
}
void FormWindow::deleteWidgets()
{
TQWidgetList widgets;
TQPtrDictIterator < WidgetSelection > it(usedSelections);
for (; it.current(); ++it)
{
TQWidget *tb = 0;
if (!(tb = mainWindow()->isAToolBarChild(TQT_TQOBJECT(it.current()->widget()))))
widgets.append(it.current()->widget());
else
((QDesignerToolBar *) tb)->removeWidget(it.current()->widget());
}
if (widgets.isEmpty())
return;
DeleteCommand *cmd = new DeleteCommand(i18n("Delete"), this, widgets);
commandHistory()->addCommand(cmd);
cmd->execute();
}
void FormWindow::editAdjustSize()
{
TQPtrList < Command > commands;
TQWidgetList widgets = selectedWidgets();
if (widgets.isEmpty())
{
TQRect oldr = geometry();
mainContainer()->adjustSize();
resize(mainContainer()->size());
// check whether our own size constraint hit us
if (size() != mainContainer()->size())
mainContainer()->resize(size());
TQRect nr = geometry();
if (oldr != nr)
{
ResizeCommand *cmd = new ResizeCommand(i18n("Adjust Size"), this, this, oldr, nr);
commandHistory()->addCommand(cmd);
}
return;
}
for (TQWidget * w = widgets.first(); w; w = widgets.next())
{
if (w->parentWidget()
&& WidgetFactory::layoutType(w->parentWidget()) != WidgetFactory::NoLayout)
continue;
TQRect oldr = w->geometry();
w->adjustSize();
TQRect nr = w->geometry();
if (oldr != nr)
commands.append(new ResizeCommand(i18n("Adjust Size"), this, w, oldr, nr));
}
if (commands.isEmpty())
return;
for (WidgetSelection * s = selections.first(); s; s = selections.next())
s->updateGeometry();
MacroCommand *cmd = new MacroCommand(i18n("Adjust Size"), this, commands);
commandHistory()->addCommand(cmd);
}
TQWidgetList FormWindow::selectedWidgets() const
{
TQWidgetList widgets;
for (TQPtrDictIterator<WidgetSelection> it(usedSelections); it.current(); ++it)
widgets.append(it.current()->widget());
return widgets;
}
void FormWindow::widgetChanged(TQObject *w)
{
if (w->isWidgetType())
updateSelection((TQWidget*)w);
}
TQLabel *FormWindow::sizePreview() const
{
if (!sizePreviewLabel)
{
((FormWindow*)this)->sizePreviewLabel = new TQLabel((FormWindow*)this);
((FormWindow*)this)->sizePreviewLabel->hide();
((FormWindow*)this)->sizePreviewLabel->setBackgroundColor(TQColor(255, 255, 128));
((FormWindow*)this)->sizePreviewLabel->setFrameStyle(TQFrame::Plain | TQFrame::Box);
}
return sizePreviewLabel;
}
void FormWindow::invalidCheckedSelections()
{
checkedSelectionsForMove = false;
}
void FormWindow::checkPreviewGeometry(TQRect & r)
{
if (TQT_TQRECT_OBJECT(rect()).contains(r))
return;
if (r.left() < rect().left())
r.moveTopLeft(TQPoint(0, r.top()));
if (r.right() > rect().right())
r.moveBottomRight(TQPoint(rect().right(), r.bottom()));
if (r.top() < rect().top())
r.moveTopLeft(TQPoint(r.left(), rect().top()));
if (r.bottom() > rect().bottom())
r.moveBottomRight(TQPoint(r.right(), rect().bottom()));
}
void FormWindow::focusInEvent(TQFocusEvent *)
{
if (mContainer)
{
TQVariant prop = mContainer->property("useInternalParser");
KommanderWidget::useInternalParser = prop.toBool();
}
}
void FormWindow::focusOutEvent(TQFocusEvent *)
{
if (propertyWidget && !isMainContainer(propertyWidget) && !isWidgetSelected(propertyWidget))
{
TQObject *opw = propertyWidget;
propertyWidget = TQT_TQOBJECT(mainContainer());
if (opw->isWidgetType())
repaintSelection((TQWidget *) opw);
}
}
void FormWindow::resizeEvent(TQResizeEvent * e)
{
TQWidget::resizeEvent(e);
if (currTool == ORDER_TOOL)
repositionOrderIndicators();
if (isVisible())
formFile()->setModified(true);
}
TQPtrDict < TQWidget > *FormWindow::widgets()
{
return &insertedWidgets;
}
TQWidget *FormWindow::designerWidget(TQObject * o) const
{
if (!o || !o->isWidgetType())
return 0;
TQWidget *w = (TQWidget *) o;
while (w && !isMainContainer(TQT_TQOBJECT(w)) && !insertedWidgets[(void *) w] || isCentralWidget(TQT_TQOBJECT(w)))
w = (TQWidget *) w->parent();
return w;
}
void FormWindow::emitShowProperties(TQObject * w)
{
if (w)
{
TQObject *opw = propertyWidget;
propertyWidget = w;
if (opw->isWidgetType())
repaintSelection((TQWidget *) opw);
}
showPropertiesTimer->stop();
showPropertiesTimer->start(0, true);
}
void FormWindow::emitUpdateProperties(TQObject * w)
{
if (w == propertyWidget)
{
updatePropertiesTimer->stop();
updatePropertiesTimer->start(0, true);
}
}
void FormWindow::emitSelectionChanged()
{
selectionChangedTimer->stop();
selectionChangedTimer->start(0, true);
}
void FormWindow::updatePropertiesTimerDone()
{
if (propertyWidget && mainWindow()->formWindow() == this)
emit updateProperties(propertyWidget);
}
void FormWindow::showPropertiesTimerDone()
{
if (propertyWidget && mainWindow()->formWindow() == this)
emit showProperties(propertyWidget);
}
void FormWindow::selectionChangedTimerDone()
{
emit selectionChanged();
}
void FormWindow::currentToolChanged()
{
toolFixed = false;
int t = mainwindow->currentTool();
if (currTool == t && t != ORDER_TOOL)
return;
// tool cleanup
switch (currTool)
{
case ORDER_TOOL:
hideOrderIndicators();
break;
case CONNECT_TOOL:
restoreConnectionLine();
if (connectSender)
restoreRect(TQRect(mapToForm(((TQWidget *) connectSender)->parentWidget(),
((TQWidget *) connectSender)->pos()), ((TQWidget *) connectSender)->size()));
if (connectReceiver)
restoreRect(TQRect(mapToForm(((TQWidget *) connectReceiver)->parentWidget(),
((TQWidget *) connectReceiver)->pos()), ((TQWidget *) connectReceiver)->size()));
endUnclippedPainter();
break;
case POINTER_TOOL:
break;
default:
if (insertParent)
endRectDraw();
break;
}
connectSender = connectReceiver = 0;
widgetPressed = false;
drawRubber = false;
insertParent = 0;
delete buffer;
buffer = 0;
currTool = t;
if (hasFocus())
clearSelection(false);
mainWindow()->statusBar()->clear();
// tool setup
switch (currTool)
{
case POINTER_TOOL:
if (propertyWidget && !isMainContainer(propertyWidget) && !isWidgetSelected(propertyWidget))
emitShowProperties(TQT_TQOBJECT(mainContainer()));
restoreCursors(this, this);
break;
case ORDER_TOOL:
if (mainWindow()->formWindow() == this)
{
mainWindow()->statusBar()->message(i18n("Click widgets to change the tab order..."));
orderedWidgets.clear();
showOrderIndicators();
if (mainWindow()->formWindow() == this)
emitShowProperties(TQT_TQOBJECT(mainContainer()));
setCursorToAll(ArrowCursor, this);
}
break;
case CONNECT_TOOL:
mainWindow()->statusBar()->message(i18n("Drag a line to create a connection..."));
setCursorToAll(CrossCursor, this);
if (mainWindow()->formWindow() == this)
emitShowProperties(TQT_TQOBJECT(mainContainer()));
break;
default:
mainWindow()->statusBar()->message(i18n("Click on the form to insert a %1...").
arg(WidgetDatabase::toolTip(currTool).lower()));
setCursorToAll(CrossCursor, this);
if (mainWindow()->formWindow() == this)
emitShowProperties(TQT_TQOBJECT(mainContainer()));
break;
}
}
void FormWindow::showOrderIndicators()
{
hideOrderIndicators();
orderIndicators.setAutoDelete(true);
TQObjectList *l = mainContainer()->queryList("TQWidget");
stackedWidgets = MetaDataBase::tabOrder(this);
if (l)
{
int order = 1;
for (TQObject * o = l->first(); o; o = l->next())
{
TQWidget *w = (TQWidget *) o;
if (w->isVisibleTo(w->parentWidget()) &&
insertedWidgets[(void *) w] && w->focusPolicy() != TQ_NoFocus)
{
OrderIndicator *ind = new OrderIndicator(order++, w, this);
orderIndicators.append(ind);
if (stackedWidgets.findRef(w) == -1)
stackedWidgets.append(w);
}
}
delete l;
}
updateOrderIndicators();
}
void FormWindow::hideOrderIndicators()
{
orderIndicators.clear();
}
void FormWindow::updateOrderIndicators()
{
int order = 1;
for (TQWidget * w = stackedWidgets.first(); w; w = stackedWidgets.next())
{
for (OrderIndicator * i = orderIndicators.first(); i; i = orderIndicators.next())
i->setOrder(order, w);
order++;
}
}
void FormWindow::repositionOrderIndicators()
{
for (OrderIndicator * i = orderIndicators.first(); i; i = orderIndicators.next())
i->reposition();
}
void FormWindow::updateUndoInfo()
{
commandHistory()->emitUndoRedo();
}
bool FormWindow::checkCustomWidgets()
{
TQStringList missingCustomWidgets;
TQPtrDictIterator < TQWidget > it(insertedWidgets);
for (; it.current(); ++it)
{
if (it.current()->isA("CustomWidget"))
{
TQString className = WidgetFactory::classNameOf(TQT_TQOBJECT(it.current()));
if (!MetaDataBase::hasCustomWidget(className))
missingCustomWidgets << className;
}
}
return true;
}
void FormWindow::setPropertyShowingBlocked(bool b)
{
propShowBlocked = b;
}
bool FormWindow::isPropertyShowingBlocked() const
{
return propShowBlocked;
}
int FormWindow::numSelectedWidgets() const
{
return usedSelections.count();
}
TQString FormWindow::copy()
{
Resource resource(mainWindow());
resource.setWidget(this);
return resource.copy();
}
void FormWindow::lowerWidgets()
{
TQWidgetList widgets;
TQPtrDictIterator < WidgetSelection > it(usedSelections);
for (; it.current(); ++it)
widgets.append(it.current()->widget());
LowerCommand *cmd = new LowerCommand(i18n("Lower"), this, widgets);
cmd->execute();
commandHistory()->addCommand(cmd);
}
static void find_accel(const TQString & txt, TQMap < TQChar, TQWidgetList > &accels, TQWidget * w)
{
int i = txt.find("&");
if (i == -1)
return;
TQChar c = txt[i + 1];
if (c.isNull() || c == '&')
return;
c = c.lower();
TQMap < TQChar, TQWidgetList >::Iterator it = accels.find(c);
if (it == accels.end())
{
TQWidgetList wl;
wl.append(w);
accels.insert(c, wl);
} else
{
TQWidgetList *wl = &*it;
wl->append(w);
}
}
void FormWindow::checkAccels()
{
TQMap < TQChar, TQWidgetList > accels;
TQObjectList *l = mainContainer()->queryList("TQWidget");
if (l)
{
for (TQObject * o = l->first(); o; o = l->next())
{
if (((TQWidget *) o)->isVisibleTo(this) && insertedWidgets[(void *) o])
{
TQWidget *w = (TQWidget *) o;
const TQMetaProperty *text =
w->metaObject()->property(w->metaObject()->findProperty("text", true), true);
const TQMetaProperty *title =
w->metaObject()->property(w->metaObject()->findProperty("title", true), true);
const TQMetaProperty *pageTitle =
w->metaObject()->property(w->metaObject()->findProperty("pageTitle", true), true);
if (text)
find_accel(w->property("text").toString(), accels, w);
if (title)
find_accel(w->property("title").toString(), accels, w);
if (pageTitle)
find_accel(w->property("pageTitle").toString(), accels, w);
}
}
delete l;
}
bool ok = true;
TQWidget *wid;
for (TQMap < TQChar, TQWidgetList >::Iterator it = accels.begin(); it != accels.end(); ++it)
{
if ((*it).count() > 1)
{
ok = false;
if (KMessageBox::questionYesNo(mainWindow(),
i18n("Accelerator '%1' is used %2 times.").arg(it.key().upper()).arg((*it).count()),
i18n("Check Accelerators"), i18n("&Select"), KStdGuiItem::cancel()) == KMessageBox::Yes)
{
clearSelection(false);
for (wid = (*it).first(); wid; wid = (*it).next())
selectWidget(TQT_TQOBJECT(wid), true);
}
return;
}
}
if (ok)
KMessageBox::information(mainWindow(), i18n("No accelerator is used more than once."),
i18n("Check Accelerators"));
}
void FormWindow::raiseWidgets()
{
TQWidgetList widgets;
TQPtrDictIterator < WidgetSelection > it(usedSelections);
for (; it.current(); ++it)
widgets.append(it.current()->widget());
RaiseCommand *cmd = new RaiseCommand(i18n("Raise"), this, widgets);
cmd->execute();
commandHistory()->addCommand(cmd);
}
void FormWindow::paste(const TQString & cb, TQWidget * parent)
{
Resource resource(mainWindow());
resource.setWidget(this);
resource.paste(cb, parent);
}
void FormWindow::selectAll()
{
checkedSelectionsForMove = false;
blockSignals(true);
TQObjectList *l = mainContainer()->queryList("TQWidget");
if (l)
{
for (TQObject * o = l->first(); o; o = l->next())
{
if (((TQWidget *) o)->isVisibleTo(this) && insertedWidgets[(void *) o])
{
selectWidget(TQT_TQOBJECT(o));
}
}
delete l;
}
blockSignals(false);
emitSelectionChanged();
if (propertyWidget)
emitShowProperties(propertyWidget);
emitSelectionChanged();
}
void FormWindow::layoutHorizontal()
{
TQWidgetList widgets(selectedWidgets());
LayoutHorizontalCommand *cmd = new LayoutHorizontalCommand(i18n("Lay Out Horizontally"),
this, mainContainer(), 0, widgets);
clearSelection(false);
commandHistory()->addCommand(cmd);
cmd->execute();
}
void FormWindow::layoutVertical()
{
TQWidgetList widgets(selectedWidgets());
LayoutVerticalCommand *cmd = new LayoutVerticalCommand(i18n("Lay Out Vertically"),
this, mainContainer(), 0, widgets);
clearSelection(false);
commandHistory()->addCommand(cmd);
cmd->execute();
}
void FormWindow::layoutHorizontalSplit()
{
TQWidgetList widgets(selectedWidgets());
LayoutHorizontalSplitCommand *cmd =
new LayoutHorizontalSplitCommand(i18n("Lay Out Horizontally (in splitter)"),
this, mainContainer(), 0, widgets);
clearSelection(false);
commandHistory()->addCommand(cmd);
cmd->execute();
}
void FormWindow::layoutVerticalSplit()
{
TQWidgetList widgets(selectedWidgets());
LayoutVerticalSplitCommand *cmd =
new LayoutVerticalSplitCommand(i18n("Lay Out Vertically (in splitter)"),
this, mainContainer(), 0, widgets);
clearSelection(false);
commandHistory()->addCommand(cmd);
cmd->execute();
}
void FormWindow::layoutGrid()
{
int xres = grid().x();
int yres = grid().y();
TQWidgetList widgets(selectedWidgets());
LayoutGridCommand *cmd = new LayoutGridCommand(i18n("Lay Out in a Grid"),
this, mainContainer(), 0, widgets, xres, yres);
clearSelection(false);
commandHistory()->addCommand(cmd);
cmd->execute();
}
void FormWindow::layoutHorizontalContainer(TQWidget * w)
{
if (w == this)
w = mainContainer();
TQObjectList l = WidgetFactory::containerOfWidget(w)->childrenListObject();
if (l.isEmpty())
return;
TQWidgetList widgets;
for (TQObject * o = l.first(); o; o = l.next())
{
if (o->isWidgetType() &&
((TQWidget *) o)->isVisibleTo(this) && insertedWidgets.find((TQWidget *) o))
widgets.append((TQWidget *) o);
}
LayoutHorizontalCommand *cmd = new LayoutHorizontalCommand(i18n("Lay Out Children Horizontally"),
this, mainContainer(), w, widgets);
clearSelection(false);
commandHistory()->addCommand(cmd);
cmd->execute();
}
void FormWindow::layoutVerticalContainer(TQWidget * w)
{
if (w == this)
w = mainContainer();
TQObjectList l = WidgetFactory::containerOfWidget(w)->childrenListObject();
if (l.isEmpty())
return;
TQWidgetList widgets;
for (TQObject * o = l.first(); o; o = l.next())
{
if (o->isWidgetType() &&
((TQWidget *) o)->isVisibleTo(this) && insertedWidgets.find((TQWidget *) o))
widgets.append((TQWidget *) o);
}
LayoutVerticalCommand *cmd = new LayoutVerticalCommand(i18n("Lay Out Children Vertically"),
this, mainContainer(), w, widgets);
clearSelection(false);
commandHistory()->addCommand(cmd);
cmd->execute();
}
void FormWindow::layoutGridContainer(TQWidget * w)
{
if (w == this)
w = mainContainer();
int xres = grid().x();
int yres = grid().y();
TQObjectList l = WidgetFactory::containerOfWidget(w)->childrenListObject();
if (l.isEmpty())
return;
TQWidgetList widgets;
for (TQObject * o = l.first(); o; o = l.next())
{
if (o->isWidgetType() &&
((TQWidget *) o)->isVisibleTo(this) && insertedWidgets.find((TQWidget *) o))
widgets.append((TQWidget *) o);
}
LayoutGridCommand *cmd = new LayoutGridCommand(i18n("Lay Out Children in a Grid"),
this, mainContainer(), w, widgets, xres, yres);
clearSelection(false);
commandHistory()->addCommand(cmd);
cmd->execute();
}
void FormWindow::breakLayout(TQWidget * w)
{
if (w == this)
w = mainContainer();
w = WidgetFactory::containerOfWidget(w);
TQPtrList < Command > commands;
for (;;)
{
if (!w || w == this)
break;
if (WidgetFactory::layoutType(w) != WidgetFactory::NoLayout &&
WidgetDatabase::isContainer(WidgetDatabase::idFromClassName(WidgetFactory::classNameOf(TQT_TQOBJECT(w)))))
{
Command *cmd = breakLayoutCommand(w);
if (cmd)
commands.insert(0, cmd);
if (!w->inherits("TQLayoutWidget") && !w->inherits("TQSplitter"))
break;
}
w = w->parentWidget();
}
if (commands.isEmpty())
return;
clearSelection(false);
MacroCommand *cmd = new MacroCommand(i18n("Break Layout"), this, commands);
commandHistory()->addCommand(cmd);
cmd->execute();
}
BreakLayoutCommand *FormWindow::breakLayoutCommand(TQWidget * w)
{
TQObjectList l = w->childrenListObject();
if (l.isEmpty())
return 0;
TQWidgetList widgets;
for (TQObject * o = l.first(); o; o = l.next())
{
if (o->isWidgetType() &&
!mainWindow()->isAToolBarChild(TQT_TQOBJECT(o)) &&
((TQWidget *) o)->isVisibleTo(this) && insertedWidgets.find((TQWidget *) o))
widgets.append((TQWidget *) o);
}
return new BreakLayoutCommand(i18n("Break Layout"), this,
WidgetFactory::widgetOfContainer(w), widgets);
}
int FormWindow::numVisibleWidgets() const
{
TQPtrDictIterator < TQWidget > it(insertedWidgets);
int visible = 0;
for (; it.current(); ++it)
{
if (it.current()->isVisibleTo((FormWindow *) this))
visible++;
}
return visible;
}
bool FormWindow::hasInsertedChildren(TQWidget *w) const
{
if (!w)
return false;
w = WidgetFactory::containerOfWidget(w);
if (!w)
return false;
TQObjectList *l = w->queryList("TQWidget");
if (!l || !l->first())
{
delete l;
return false;
}
for (TQObject *o = l->first(); o; o = l->next())
if (o->isWidgetType() && ((TQWidget*)o)->isVisibleTo((FormWindow*)this) &&
insertedWidgets.find((TQWidget*)o))
{
delete l;
return true;
}
delete l;
return false;
}
bool FormWindow::allowMove(TQWidget *w)
{
w = w->parentWidget();
while (w)
{
if ((isMainContainer(TQT_TQOBJECT(w)) || insertedWidgets.find(w)) && WidgetFactory::layoutType(w) ==
WidgetFactory::NoLayout)
return true;
w = w->parentWidget();
}
return false;
}
void FormWindow::editConnections()
{
buffer = 0;
if (!connectSender || !connectReceiver)
return;
mainWindow()->statusBar()->clear();
ConnectionEditor editor(mainwindow, connectSender, connectReceiver, this);
mainWindow()->statusBar()->message(i18n("Edit connections..."));
editor.exec();
mainWindow()->statusBar()->clear();
if (!toolFixed)
mainwindow->resetTool();
connectSender = connectReceiver = 0;
}
void FormWindow::saveBackground()
{
delete buffer;
buffer = new TQPixmap(width(), height());
*buffer = TQPixmap::grabWindow(winId());
}
void FormWindow::restoreConnectionLine()
{
if (!unclippedPainter || !buffer)
return;
int a =TQABS(connectStartPos.x() - currentConnectPos.x());
int b = TQABS(connectStartPos.y() - currentConnectPos.y());
TQRect r(connectStartPos, currentConnectPos);
if (a < 32 || b < 32)
{ // special case: vertical or horizontal line
r = r.normalize();
unclippedPainter->drawPixmap(r.x() - 2, r.y() - 2, *buffer,
r.x() - 2, r.y() - 2, r.width() + 4, r.height() + 4);
return;
}
if (a <= 0)
a = 1;
if (b <= 0)
b = 1;
int w, h;
if (b > a)
{
h = 64;
w = (a * h) / b;
}
else
{
w = 64;
h = (b * w) / a;
}
int dx = 2 * w / 3;
int dy = 2 * h / 3;
TQPoint p(connectStartPos);
if (r.x() > r.right())
{
dx = dx * -1;
p.setX(p.x() - 64);
r.moveBy(-64, 0);
}
if (r.y() > r.bottom()) {
dy = dy * -1;
p.setY(p.y() - 64);
r.moveBy(0, -64);
}
w = h = 64;
r = r.normalize();
while (r.contains(p))
{
unclippedPainter->drawPixmap(p, *buffer, TQRect(p, TQSize(w, h)));
unclippedPainter->setPen(red);
p.setX(p.x() + dx);
p.setY(p.y() + dy);
}
unclippedPainter->drawPixmap(connectStartPos.x() - 10, connectStartPos.y() - 10, *buffer,
connectStartPos.x() - 10, connectStartPos.y() - 10, 20, 20);
}
void FormWindow::restoreRect(const TQRect &rect)
{
if (!unclippedPainter)
return;
TQRect r(rect);
r = r.normalize();
r = TQRect(r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4);
unclippedPainter->drawPixmap(r.x() - 2, r.y() - 2, *buffer, r.x() - 2, r.y() - 2, r.width() + 4, 4);
unclippedPainter->drawPixmap(r.x() - 2, r.y() - 2, *buffer, r.x() - 2, r.y() - 2, 4, r.height() + 4);
unclippedPainter->drawPixmap(r.x() - 2, r.y() + r.height() - 3, *buffer, r.x() - 2,
r.y() + r.height() - 3, r.width() + 4, 5);
unclippedPainter->drawPixmap(r.x() + r.width() - 2, r.y(), *buffer, r.x() + r.width() - 2,
r.y(), 4, r.height() + 4);
}
void FormWindow::drawConnectLine()
{
if (!unclippedPainter)
return;
unclippedPainter->setPen(TQPen(white, 2));
unclippedPainter->drawLine(connectStartPos, currentConnectPos);
unclippedPainter->setPen(TQPen(darkCyan, 1));
unclippedPainter->drawLine(connectStartPos, currentConnectPos);
unclippedPainter->setPen(TQPen(magenta, 1));
if (connectSender)
{
TQWidget *w = (TQWidget*)connectSender;
TQPoint p = mapToForm(w, TQPoint(0,0));
unclippedPainter->drawRect(TQRect(p + TQPoint(2, 2), w->size() - TQSize(4, 4)));
}
if (connectReceiver)
{
TQWidget *w = (TQWidget*)connectReceiver;
TQPoint p = mapToForm(w, TQPoint(0,0));
unclippedPainter->drawRect(TQRect(p + TQPoint(2, 2), w->size() - TQSize(4, 4)));
}
}
TQString FormWindow::fileName() const
{
return ff->absFileName();
}
void FormWindow::setFileName(const TQString &fn)
{
ff->setFileName(fn);
emit fileNameChanged(ff->fileName(), this);
}
void FormWindow::modificationChanged(bool m)
{
emit modificationChanged(m, this);
emit modificationChanged(m, ff->fileName());
}
bool FormWindow::unify(TQObject *w, TQString &s, bool changeIt)
{
bool found = !isMainContainer(w) && !qstrcmp(name(), s.latin1());
if (!found)
{
TQString orig = s;
int num = 1;
TQPtrDictIterator<TQWidget> it(insertedWidgets);
for (; it.current();)
if (TQT_BASE_OBJECT(it.current()) != TQT_BASE_OBJECT(w) && !qstrcmp(it.current()->name(), s.latin1()))
{
found = true;
if (!changeIt)
break;
s = orig + "_" + TQString::number(++num);
it.toFirst();
}
else
++it;
if (!found)
{
TQPtrList<TQAction> al;
TQAction *a = 0;
for (a = actions.first(); a; a = actions.next())
{
TQObjectList *l = a->queryList("TQAction");
al.append(a);
for (TQObject *ao = l->first(); ao; ao = l->next())
al.append((TQAction*)ao);
delete l;
}
for (a = al.first(); a; a = al.next())
{
if (a != w && !qstrcmp(a->name(), s.latin1()))
{
found = true;
if (!changeIt)
break;
s = orig + "_" + TQString::number(++num);
a = actions.first();
}
}
}
if (mainContainer()->inherits("TQMainWindow"))
{
if (!found)
{
TQObjectList *l = mainContainer()->queryList("TQDockWindow", 0, true);
for (TQObject *o = l->first(); o; o = l->next())
if (o != w && !qstrcmp(o->name(), s.latin1()))
{
found = true;
if (!changeIt)
break;
s = orig + "_" + TQString::number(++num);
o = l->first();
}
delete l;
}
if (!found)
{
TQObjectList *l = mainContainer()->queryList("QDesignerPopupMenu", 0, true);
for (TQObject *o = l->first(); o; o = l->next())
if (o != w && !qstrcmp(o->name(), s.latin1()))
{
found = true;
if (!changeIt)
break;
s = orig + "_" + TQString::number(++num);
o = l->first();
}
delete l;
}
}
}
if (!found)
return true;
return false;
}
bool FormWindow::isCustomWidgetUsed(MetaDataBase::CustomWidget *w)
{
TQPtrDictIterator<TQWidget> it(insertedWidgets);
for (; it.current(); ++it)
if (it.current()->isA("CustomWidget") && !qstrcmp(WidgetFactory::classNameOf(TQT_TQOBJECT(it.current())),
w->className.utf8()))
return true;
return false;
}
bool FormWindow::isDatabaseWidgetUsed() const
{
#ifndef TQT_NO_SQL
TQStringList dbClasses;
dbClasses << "TQDataTable"; // add more here
TQPtrDictIterator<TQWidget> it(insertedWidgets);
for (; it.current(); ++it)
{
TQString c(it.current()->className());
if (dbClasses.contains(c) > 0)
return true;
}
#endif
return false;
}
bool FormWindow::isDatabaseAware() const
{
#ifndef TQT_NO_SQL
if (TQString(mContainer->className()) == "QDesignerDataBrowser" ||
TQString(mContainer->className()) == "QDesignerDataView")
return true;
return isDatabaseWidgetUsed();
#else
return false;
#endif
}
void FormWindow::visibilityChanged()
{
if (currTool != ORDER_TOOL)
emitUpdateProperties(TQT_TQOBJECT(currentWidget()));
else
{
updateOrderIndicators();
repositionOrderIndicators();
}
}
/*
Maps a pos in a w's coordinates to the form's coordinate system.
This is the equivalent to mapFromGlobal(w->mapToGlobal(pos)) but
avoids the two roundtrips to the X-Server on Unix/X11.
*/
TQPoint FormWindow::mapToForm(const TQWidget* w, const TQPoint& pos) const
{
TQPoint p = pos;
const TQWidget* i = w;
while (i && !i->isTopLevel() && !isMainContainer(TQT_TQOBJECT(const_cast<TQWidget*>(i))))
{
p = i->mapToParent(p);
i = i->parentWidget();
}
return mapFromGlobal(w->mapToGlobal(pos));
}
static int widgetDepth(TQWidget *w)
{
int d = -1;
while (w && !w->isTopLevel())
{
d++;
w = w->parentWidget();
}
return d;
}
static bool isChildOf(TQWidget *c, TQWidget *p)
{
while (c && !c->isTopLevel())
{
if (c == p)
return true;
c = c->parentWidget();
}
return false;
}
TQWidget *FormWindow::containerAt(const TQPoint &pos, TQWidget *notParentOf)
{
TQPtrDictIterator<TQWidget> it(insertedWidgets);
TQWidget *container = 0;
int depth = -1;
TQWidgetList selected = selectedWidgets();
if (TQT_TQRECT_OBJECT(rect()).contains(mapFromGlobal(pos)))
{
container = mainContainer();
depth = widgetDepth(container);
}
for (; it.current(); ++it) {
if (it.current()->inherits("TQLayoutWidget"))
continue;
if (it.current()->inherits("TQSplitter"))
continue;
if (!it.current()->isVisibleTo(this))
continue;
if (selected.find(it.current()) != -1)
continue;
if (!WidgetDatabase::isContainer(WidgetDatabase::idFromClassName(
WidgetFactory::classNameOf(TQT_TQOBJECT(it.current())))) && it.current() != mainContainer())
continue;
// the rectangles of all ancestors of the container must contain the insert position
TQWidget *w = it.current();
while (w && !w->isTopLevel())
{
if (!TQT_TQRECT_OBJECT(w->rect()).contains((w->mapFromGlobal(pos))))
break;
w = w->parentWidget();
}
if (w && !w->isTopLevel()) continue; // we did not get through the full while loop
int wd = widgetDepth(it.current());
if (wd == depth && container && (it.current()->parentWidget()->
childrenListObject()).find(TQT_TQOBJECT(it.current())) >
(container->parentWidget()->childrenListObject()).find(TQT_TQOBJECT(container)))
wd++;
if (wd > depth && !isChildOf(it.current(), notParentOf)) {
depth = wd;
container = it.current();
}
}
return container;
}
bool FormWindow::isMainContainer(TQObject *w) const
{
return w && w->isWidgetType() && (TQT_BASE_OBJECT(w) == this || TQT_BASE_OBJECT(w) == TQT_BASE_OBJECT(mainContainer()));
}
void FormWindow::setMainContainer(TQWidget *w)
{
bool resetPropertyWidget = isMainContainer(propertyWidget);
if (mContainer)
insertedWidgets.remove(mContainer);
if (TQT_BASE_OBJECT(propertyWidget) == TQT_BASE_OBJECT(mContainer))
propertyWidget = 0;
delete mContainer;
mContainer = w;
insertedWidgets.insert(mContainer, mContainer);
delete layout();
TQHBoxLayout *l = new TQHBoxLayout(this);
l->addWidget(w);
if (resetPropertyWidget)
{
TQObject *opw = propertyWidget;
propertyWidget = TQT_TQOBJECT(mContainer);
if (opw && opw->isWidgetType())
repaintSelection((TQWidget*)opw);
}
}
bool FormWindow::savePixmapInline() const
{
return pixInline;
}
TQString FormWindow::pixmapLoaderFunction() const
{
return pixLoader;
}
void FormWindow::setSavePixmapInline(bool b)
{
pixInline = b;
}
void FormWindow::setPixmapLoaderFunction(const TQString &func)
{
pixLoader = func;
}
void FormWindow::setActiveObject(TQObject *o)
{
emitShowProperties(o);
propertyWidget = o;
}
TQAction *FormWindow::findAction(const TQString &name)
{
for (TQAction *a = actionList().first(); a; a = actionList().next())
{
if (TQString(a->name()) == name)
return a;
TQAction *ac = (TQAction*)a->child(name.latin1(), "TQAction");
if (ac)
return ac;
}
return 0;
}
void FormWindow::killAccels(TQObject *top)
{
TQObjectList *l = top->queryList("TQAccel");
if (!l)
return;
for (TQObject *o = l->first(); o; o = l->next())
((TQAccel*)o)->setEnabled(false);
delete l;
}
bool FormWindow::isCentralWidget(TQObject *w) const
{
if (!mainContainer()->inherits("TQMainWindow"))
return false;
return TQT_BASE_OBJECT(w) == TQT_BASE_OBJECT(((TQMainWindow*)mainContainer())->centralWidget());
}
TQObject *FormWindow::connectableObject(TQObject *w, TQObject *)
{
return w;
}
int FormWindow::layoutDefaultSpacing() const
{
return defSpacing;
}
int FormWindow::layoutDefaultMargin() const
{
return defMargin;
}
void FormWindow::setLayoutDefaultSpacing(int s)
{
defSpacing = s;
}
void FormWindow::setLayoutDefaultMargin(int s)
{
defMargin = s;
}
FormFile *FormWindow::formFile() const
{
return ff;
}
void FormWindow::setFormFile(FormFile *f)
{
ff = f;
if (ff)
connect(this, TQT_SIGNAL(modificationChanged(bool, const TQString&)), ff, TQT_SLOT(formWindowChangedSomehow()));
}
#include "formwindow.moc"
|