summaryrefslogtreecommitdiffstats
path: root/kommander/editor/widgetfactory.cpp
blob: 15f9ad1d2c8fd42ccf07a7e650d1805e6c13893d (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
/**********************************************************************
** Copyright (C) 2000 Trolltech AS.  All rights reserved.
**
** This file is part of TQt Designer.
**
** 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.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/

#include <tdelocale.h>
#include <kommanderfactory.h>

#include "kmdrmainwindow.h"
#include <tqvariant.h> // HP-UX compiler need this here
#include "widgetfactory.h"
#include "widgetdatabase.h"
#include "metadatabase.h"
#include "mainwindow.h"
#include "formwindow.h"
#include "pixmapchooser.h"
#include "tqlayout.h"
#include "listboxeditorimpl.h"
#include "listvieweditorimpl.h"
#include "iconvieweditorimpl.h"
#include "multilineeditorimpl.h"
#ifndef KOMMANDER
#include "widgetinterface.h"
#endif
#ifndef TQT_NO_TABLE
#include "tableeditorimpl.h"
#endif

#include <tqfeatures.h>

#include <tqpixmap.h>
#include <tqgroupbox.h>
#include <tqiconview.h>
#ifndef TQT_NO_TABLE
#include <tqtable.h>
#endif
#ifndef TQT_NO_SQL
#include <tqdatatable.h>
#endif
#include <tqdatetimeedit.h>
#include <tqlineedit.h>
#include <tqspinbox.h>
#include <tqmultilineedit.h>
#include <tqtextedit.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqwidgetstack.h>
#include <tqcombobox.h>
#include <tqtabbar.h>
#include <tqlistbox.h>
#include <tqlistview.h>
#include <tqobjectlist.h>
#include <tqlcdnumber.h>
#include <tqslider.h>
#include <tqdial.h>
#include <tqprogressbar.h>
#include <tqtextview.h>
#include <tqtextbrowser.h>
#include <tqframe.h>
#include <tqmetaobject.h>
#include <tqwizard.h>
#include <tqvaluelist.h>
#include <tqtimer.h>
#include <tqscrollbar.h>
#include <tqmainwindow.h>
#include <tqmenubar.h>
#include <tqapplication.h>
#include <tqsplitter.h>
#ifndef TQT_NO_SQL
#include "database.h"
#endif

//#define NO_STATIC_COLORS
#include "globaldefs.h"

/* KOMMANDER INCLUDES */
#include <lineedit.h>
#include <dialog.h>
#include <execbutton.h>
#include <closebutton.h>
#include <textedit.h>
#include <fileselector.h>
#include <textedit.h>
#include <radiobutton.h>
#include <groupbox.h>
#include <buttongroup.h>
#include <checkbox.h>
#include <combobox.h>
#include <spinboxint.h>
#include <wizard.h>
#include <tabwidget.h>
#include <subdialog.h>
#include <listbox.h>
#include <scriptobject.h>
#include <richtexteditor.h>
#include <treewidget.h>
#include <slider.h>
#include <datepicker.h>
#include <popupmenu.h>
#include "toolbox.h"
#include "fontdialog.h"
#include "aboutdialog.h"

FormWindow *find_formwindow( TQWidget *w )
{
    if ( !w )
	return 0;
    for (;;) {
	if ( w->inherits( "FormWindow" ) )
	    return (FormWindow*)w;
	if ( !w->parentWidget() )
	    return 0;
	w = w->parentWidget();
    }
}

void TQLayoutWidget::paintEvent( TQPaintEvent* )
{
    TQPainter p ( this );
    p.setPen( red );
    p.drawRect( rect() );
}


QDesignerTabWidget::QDesignerTabWidget( TQWidget *parent, const char *name )
    : TQTabWidget( parent, name ), dropIndicator( 0 ), dragPage( 0 ), mousePressed( false )
{
    tabBar()->setAcceptDrops( true );
    tabBar()->installEventFilter( this );
}

int QDesignerTabWidget::currentPage() const
{
    return tabBar()->currentTab();
}

void QDesignerTabWidget::setCurrentPage( int i )
{
    tabBar()->setCurrentTab( i );
}

TQString QDesignerTabWidget::pageTitle() const
{
    return ((TQTabWidget*)this)->tabLabel( TQTabWidget::currentPage() );
}

void QDesignerTabWidget::setPageTitle( const TQString& title )
{
    changeTab( TQTabWidget::currentPage(), title );
}

void QDesignerTabWidget::setPageName( const TQCString& name )
{
    if ( TQTabWidget::currentPage() )
	TQTabWidget::currentPage()->setName( name );
}

TQCString QDesignerTabWidget::pageName() const
{
    if ( !TQTabWidget::currentPage() )
	return 0;
    return TQTabWidget::currentPage()->name();
}

int QDesignerTabWidget::count() const
{
    return tabBar()->count();
}

bool QDesignerTabWidget::eventFilter( TQObject *o, TQEvent *e )
{
    if ( TQT_BASE_OBJECT(o) != TQT_BASE_OBJECT(tabBar()) ) return false;

    switch ( e->type() ) {
    case TQEvent::MouseButtonPress: {
	mousePressed = true;
	TQMouseEvent *me = (TQMouseEvent*)e;
	pressPoint = me->pos();
    }
    break;
    case TQEvent::MouseMove: {
	TQMouseEvent *me = (TQMouseEvent*)e;
	if ( mousePressed && ( pressPoint - me->pos()).manhattanLength() > TQApplication::startDragDistance() ) {
	    TQTextDrag *drg = new TQTextDrag( TQString::number( (long) this ) , this );
	    mousePressed = false;
	    dragPage = TQTabWidget::currentPage();
	    dragLabel = TQTabWidget::tabLabel( dragPage );

	    int index = indexOf( dragPage );

	    removePage( dragPage );
	    if ( !drg->dragMove() ) {
		insertTab( dragPage, dragLabel, index );
		showPage( dragPage );
	    }
	    if ( dropIndicator )
		dropIndicator->hide();
	}
    }
    break;
    case TQEvent::DragLeave:	{
	if ( dropIndicator )
	    dropIndicator->hide();
    }
    break;
    case TQEvent::DragMove: {
	TQDragEnterEvent *de = (TQDragEnterEvent*) e;
	if ( TQTextDrag::canDecode( de ) ) {
	    TQString text;
	    TQTextDrag::decode( de, text );
	    if ( text == TQString::number( (long)this ) )
		de->accept();
	    else
		return false;
	}

	int index = 0;
	TQRect rect;
	for ( ; index < tabBar()->count(); index++ ) {
	    if ( tabBar()->tabAt( index )->rect().contains( de->pos() ) ) {
		rect = tabBar()->tabAt( index )->rect();
		break;
	    }
	}

	if ( index == tabBar()->count() -1 ) {
	    TQRect rect2 = rect;
	    rect2.setLeft( rect2.left() + rect2.width() / 2 );
	    if ( rect2.contains( de->pos() ) )
		index++;
	}

	if ( ! dropIndicator ) {
	    dropIndicator = new TQWidget( this );
	    dropIndicator->setBackgroundColor( red );
	}

	TQPoint pos;
	if ( index == tabBar()->count() )
	    pos = tabBar()->mapToParent( TQPoint( rect.x() + rect.width(), rect.y() ) );
	else
	    pos = tabBar()->mapToParent( TQPoint( rect.x(), rect.y() ) );

	dropIndicator->setGeometry( pos.x(), pos.y() , 3, rect.height() );
	dropIndicator->show();
    }
    break;
    case TQEvent::Drop: {
	TQDragEnterEvent *de = (TQDragEnterEvent*) e;
	if ( TQTextDrag::canDecode( de ) ) {
	    TQString text;
	    TQTextDrag::decode( de, text );
	    if ( text == TQString::number( (long)this ) ) {

		int newIndex = 0;
		for ( ; newIndex < tabBar()->count(); newIndex++ ) {
		    if ( tabBar()->tabAt( newIndex )->rect().contains( de->pos() ) )
			break;
		}

		if ( newIndex == tabBar()->count() -1 ) {
		    TQRect rect2 = tabBar()->tabAt( newIndex )->rect();
		    rect2.setLeft( rect2.left() + rect2.width() / 2 );
		    if ( rect2.contains( de->pos() ) )
			newIndex++;
		}

		int oldIndex = 0;
		for ( ; oldIndex < tabBar()->count(); oldIndex++ ) {
		    if ( tabBar()->tabAt( oldIndex )->rect().contains( pressPoint ) )
			break;
		}

		FormWindow *fw = find_formwindow( this );
		MoveTabPageCommand *cmd =
		    new MoveTabPageCommand( i18n("Move Tab Page" ), fw, this,
					    dragPage, dragLabel, newIndex, oldIndex );
		fw->commandHistory()->addCommand( cmd );
		cmd->execute();
		de->accept();
	    }
	}
    }
    break;
    default:
	break;
    }
    return false;
}

int QDesignerWizard::currentPageNum() const
{
    for ( int i = 0; i < pageCount(); ++i ) {
	if ( page( i ) == currentPage() )
	    return i;
    }
    return 0;
}

void QDesignerWizard::setCurrentPage( int i )
{
    if ( i < currentPageNum() ) {
	while ( i < currentPageNum() ) {
	    if ( currentPageNum() == 0 )
		break;
	    back();
	}

    } else {
	while ( i > currentPageNum() ) {
	    if ( currentPageNum() == pageCount() - 1 )
		break;
	    next();
	}
    }
}

TQString QDesignerWizard::pageTitle() const
{
    return title( currentPage() );
}

void QDesignerWizard::setPageTitle( const TQString& title )
{
    setTitle( currentPage(), title );
}

void QDesignerWizard::setPageName( const TQCString& name )
{
    if ( TQWizard::currentPage() )
	TQWizard::currentPage()->setName( name );
}

TQCString QDesignerWizard::pageName() const
{
    if ( !TQWizard::currentPage() )
	return 0;
    return TQWizard::currentPage()->name();
}

int QDesignerWizard::pageNum( TQWidget *p )
{
    for ( int i = 0; i < pageCount(); ++i ) {
	if ( page( i ) == p )
	    return i;
    }
    return -1;
}

void QDesignerWizard::addPage( TQWidget *p, const TQString &t )
{
    TQWizard::addPage( p, t );
    if ( removedPages.find( p ) )
	removedPages.remove( p );
}

void QDesignerWizard::removePage( TQWidget *p )
{
    TQWizard::removePage( p );
    removedPages.insert( p, p );
}

void QDesignerWizard::insertPage( TQWidget *p, const TQString &t, int index )
{
    TQWizard::insertPage( p, t, index );
    if ( removedPages.find( p ) )
	removedPages.remove( p );
}

TQMap< int, TQMap< TQString, TQVariant> > *defaultProperties = 0;
TQMap< int, TQStringList > *changedProperties = 0;

/*!
  \class WidgetFactory widgetfactory.h
  \brief Set of static functions for creating widgets, layouts and do other stuff

  The widget factory offers functions to create widgets, create and
  delete layouts find out other details - all based on the
  WidgetDatabase's data. So the functions that use ids use the same
  ids as in the WidgetDatabase.
*/


void WidgetFactory::saveDefaultProperties( TQWidget *w, int id )
{
    TQMap< TQString, TQVariant> propMap;
    TQStrList lst = w->metaObject()->propertyNames( true );
    for ( uint i = 0; i < lst.count(); ++i ) {
	TQVariant var = w->property( lst.at( i ) );
	if ( !var.isValid() && qstrcmp( "pixmap", lst.at( i ) ) == 0 )
	    var = TQVariant( TQPixmap() );
	else if ( !var.isValid() && qstrcmp( "iconSet", lst.at( i ) ) == 0 )
	    var = TQVariant( TQIconSet() );
	propMap.replace( lst.at( i ), var );
    }
    defaultProperties->replace( id, propMap );
}

static void saveChangedProperties( TQWidget *w, int id )
{
    TQStringList l = MetaDataBase::changedProperties( TQT_TQOBJECT(w) );
    changedProperties->insert( id, l );
}

EditorTabWidget::EditorTabWidget( TQWidget *parent, const char *name )
    : TabWidget( parent, name ), dropIndicator( 0 ), dragPage( 0 ), mousePressed( false )
{
    tabBar()->setAcceptDrops( true );
    tabBar()->installEventFilter( this );
}

int EditorTabWidget::currentPage() const
{
    return tabBar()->currentTab();
}

void EditorTabWidget::setCurrentPage( int i )
{
    tabBar()->setCurrentTab( i );
}

TQString EditorTabWidget::pageTitle() const
{
    return ((TQTabWidget*)this)->tabLabel( TQTabWidget::currentPage() );
}

void EditorTabWidget::setPageTitle( const TQString& title )
{
    changeTab( TQTabWidget::currentPage(), title );
}

void EditorTabWidget::setPageName( const TQCString& name )
{
    if ( TQTabWidget::currentPage() )
	TQTabWidget::currentPage()->setName( name );
}

TQCString EditorTabWidget::pageName() const
{
    if ( !TQTabWidget::currentPage() )
	return 0;
    return TQTabWidget::currentPage()->name();
}

int EditorTabWidget::count() const
{
    return tabBar()->count();
}

bool EditorTabWidget::eventFilter( TQObject *o, TQEvent *e )
{
    if ( TQT_BASE_OBJECT(o) != TQT_BASE_OBJECT(tabBar()) ) return false;

    switch ( e->type() ) {
    case TQEvent::MouseButtonPress: {
	mousePressed = true;
	TQMouseEvent *me = (TQMouseEvent*)e;
	pressPoint = me->pos();
    }
    break;
    case TQEvent::MouseMove: {
	TQMouseEvent *me = (TQMouseEvent*)e;
	if ( mousePressed && ( pressPoint - me->pos()).manhattanLength() > TQApplication::startDragDistance() ) {
	    TQTextDrag *drg = new TQTextDrag( TQString::number( (long) this ) , this );
	    mousePressed = false;
	    dragPage = TQTabWidget::currentPage();
	    dragLabel = TQTabWidget::tabLabel( dragPage );

	    int index = indexOf( dragPage );

	    removePage( dragPage );
	    if ( !drg->dragMove() ) {
		insertTab( dragPage, dragLabel, index );
		showPage( dragPage );
	    }
	    if ( dropIndicator )
		dropIndicator->hide();
	}
    }
    break;
    case TQEvent::DragLeave:	{
	if ( dropIndicator )
	    dropIndicator->hide();
    }
    break;
    case TQEvent::DragMove: {
	TQDragEnterEvent *de = (TQDragEnterEvent*) e;
	if ( TQTextDrag::canDecode( de ) ) {
	    TQString text;
	    TQTextDrag::decode( de, text );
	    if ( text == TQString::number( (long)this ) )
		de->accept();
	    else
		return false;
	}

	int index = 0;
	TQRect rect;
	for ( ; index < tabBar()->count(); index++ ) {
	    if ( tabBar()->tabAt( index )->rect().contains( de->pos() ) ) {
		rect = tabBar()->tabAt( index )->rect();
		break;
	    }
	}

	if ( index == tabBar()->count() -1 ) {
	    TQRect rect2 = rect;
	    rect2.setLeft( rect2.left() + rect2.width() / 2 );
	    if ( rect2.contains( de->pos() ) )
		index++;
	}

	if ( ! dropIndicator ) {
	    dropIndicator = new TQWidget( this );
	    dropIndicator->setBackgroundColor( red );
	}

	TQPoint pos;
	if ( index == tabBar()->count() )
	    pos = tabBar()->mapToParent( TQPoint( rect.x() + rect.width(), rect.y() ) );
	else
	    pos = tabBar()->mapToParent( TQPoint( rect.x(), rect.y() ) );

	dropIndicator->setGeometry( pos.x(), pos.y() , 3, rect.height() );
	dropIndicator->show();
    }
    break;
    case TQEvent::Drop: {
	TQDragEnterEvent *de = (TQDragEnterEvent*) e;
	if ( TQTextDrag::canDecode( de ) ) {
	    TQString text;
	    TQTextDrag::decode( de, text );
	    if ( text == TQString::number( (long)this ) ) {

		int newIndex = 0;
		for ( ; newIndex < tabBar()->count(); newIndex++ ) {
		    if ( tabBar()->tabAt( newIndex )->rect().contains( de->pos() ) )
			break;
		}

		if ( newIndex == tabBar()->count() -1 ) {
		    TQRect rect2 = tabBar()->tabAt( newIndex )->rect();
		    rect2.setLeft( rect2.left() + rect2.width() / 2 );
		    if ( rect2.contains( de->pos() ) )
			newIndex++;
		}

		int oldIndex = 0;
		for ( ; oldIndex < tabBar()->count(); oldIndex++ ) {
		    if ( tabBar()->tabAt( oldIndex )->rect().contains( pressPoint ) )
			break;
		}

		FormWindow *fw = find_formwindow( this );
		MoveTabPageCommand *cmd =
		    new MoveTabPageCommand( i18n("Move Tab Page" ), fw, this,
					    dragPage, dragLabel, newIndex, oldIndex );
		fw->commandHistory()->addCommand( cmd );
		cmd->execute();
		de->accept();
	    }
	}
    }
    break;
    default:
	break;
    }
    return false;
}


EditorToolBox::EditorToolBox( TQWidget *parent, const char *name )
    : ToolBox( parent, name )
{
    setAcceptDrops( true );
}

int EditorToolBox::currentPage() const
{
    return currentIndex();
}

void EditorToolBox::setCurrentPage( int i )
{
    setCurrentItem( item( i ) );
}

TQString EditorToolBox::pageTitle() const
{
    return itemLabel( currentIndex() );
}

void EditorToolBox::setPageTitle( const TQString& title )
{
    setItemLabel( currentIndex(), title );
}

void EditorToolBox::setPageName( const TQCString& name )
{
    if ( currentItem() )
    currentItem()->setName( name );
}

TQCString EditorToolBox::pageName() const
{
    if ( !currentItem() )
    return 0;
    return currentItem()->name();
}

int EditorToolBox::count() const
{
    return TQToolBox::count();
}



/*!  Creates a widget of the type which is registered as \a id as
  child of \a parent. The \a name is optional. If \a init is true, the
  widget is initialized with some defaults, else the plain widget is
  created.
*/

TQWidget *WidgetFactory::create( int id, TQWidget *parent, const char *name, bool init, const TQRect *r, Qt::Orientation orient )
{
  TQString n = WidgetDatabase::className(id);
  //tqDebug("Trying to create '%s'", n.latin1());
  if (n.isEmpty())
    return 0;

  if (!defaultProperties)
  {
    defaultProperties = new TQMap < int, TQMap < TQString, TQVariant > >();
    changedProperties = new TQMap < int, TQStringList > ();
  }

  TQWidget *w = 0;
  TQString str = WidgetDatabase::createWidgetName(id);
  const char *s = str.latin1();
  w = createWidget(n, parent, name ? name : s, init, r, orient);
  //tqDebug("Trying to create '%s', widget (id=%d) - %s", s, id, w ? "successful" : "failure");
  if (!w && WidgetDatabase::isCustomWidget(id))
    w = createCustomWidget(parent, name ? name : s, MetaDataBase::customWidget(id));
  if (!w)
    return 0;
  MetaDataBase::addEntry(TQT_TQOBJECT(w));

  if (!defaultProperties->contains(id))
    saveDefaultProperties(w, id);
  if (!changedProperties->contains(id))
    saveChangedProperties(w, id);

  return w;
}

/*!  Creates a layout on the widget \a widget of the type \a type
  which can be \c HBox, \c VBox or \c Grid.
*/

TQLayout *WidgetFactory::createLayout( TQWidget *widget, TQLayout *layout, LayoutType type )
{
    int spacing = MainWindow::self->currentLayoutDefaultSpacing();
    int margin = 0;

    if ( widget && !widget->inherits( TQLAYOUTWIDGET_OBJECT_NAME_STRING ) &&
	 ( WidgetDatabase::isContainer( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( TQT_TQOBJECT(widget) ) ) ) ||
	   widget && widget->parentWidget() && widget->parentWidget()->inherits( "FormWindow" ) ) )
	margin = MainWindow::self->currentLayoutDefaultMargin();

    if ( !layout && widget && widget->inherits( TQTABWIDGET_OBJECT_NAME_STRING ) )
	widget = ((TQTabWidget*)widget)->currentPage();

    if ( !layout && widget && widget->inherits( TQTOOLBOX_OBJECT_NAME_STRING ) )
    widget = ((TQToolBox*)widget)->currentItem();

    if ( !layout && widget && widget->inherits( TQWIZARD_OBJECT_NAME_STRING ) )
	widget = ((TQWizard*)widget)->currentPage();

    if ( !layout && widget && widget->inherits( TQMAINWINDOW_OBJECT_NAME_STRING ) )
	widget = ((TQMainWindow*)widget)->centralWidget();

    if ( !layout && widget && widget->inherits( TQWIDGETSTACK_OBJECT_NAME_STRING ) )
	widget = ((TQWidgetStack*)widget)->visibleWidget();

    MetaDataBase::addEntry( TQT_TQOBJECT(widget) );

    if ( !layout && widget && widget->inherits( TQGROUPBOX_OBJECT_NAME_STRING ) ) {
	TQGroupBox *gb = (TQGroupBox*)widget;
	gb->setColumnLayout( 0, Qt::Vertical );
	gb->layout()->setMargin( 0 );
	gb->layout()->setSpacing( 0 );
	TQLayout *l;
	switch ( type ) {
	case HBox:
	    l = new TQHBoxLayout( gb->layout() );
	    MetaDataBase::setMargin( TQT_TQOBJECT(gb), margin );
	    MetaDataBase::setSpacing( TQT_TQOBJECT(gb), spacing );
	    l->setAlignment( AlignTop );
	    MetaDataBase::addEntry( TQT_TQOBJECT(l) );
	    return l;
	case VBox:
	    l = new TQVBoxLayout( gb->layout(), spacing );
	    MetaDataBase::setMargin( TQT_TQOBJECT(gb), margin );
	    MetaDataBase::setSpacing( TQT_TQOBJECT(gb), spacing );
	    l->setAlignment( AlignTop );
	    MetaDataBase::addEntry( TQT_TQOBJECT(l) );
	    return l;
	case Grid:
	    l = new QDesignerGridLayout( gb->layout() );
	    MetaDataBase::setMargin( TQT_TQOBJECT(gb), margin );
	    MetaDataBase::setSpacing( TQT_TQOBJECT(gb), spacing );
	    l->setAlignment( AlignTop );
	    MetaDataBase::addEntry( TQT_TQOBJECT(l) );
	    return l;
	default:
	    return 0;
	}
    } else {
	if ( layout ) {
	    TQLayout *l;
	    switch ( type ) {
	    case HBox:
		l = new TQHBoxLayout( layout );
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		l->setSpacing( spacing );
		l->setMargin( margin );
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		return l;
	    case VBox:
		l = new TQVBoxLayout( layout );
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		l->setSpacing( spacing );
		l->setMargin( margin );
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		return l;
	    case Grid: {
		l = new QDesignerGridLayout( layout );
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		l->setSpacing( spacing );
		l->setMargin( margin );
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		return l;
	    }
	    default:
		return 0;
	    }
	} else {
	    TQLayout *l;
	    switch ( type ) {
	    case HBox:
		l = new TQHBoxLayout( widget );
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		if ( widget ) {
		    MetaDataBase::setMargin( TQT_TQOBJECT(widget), margin );
		    MetaDataBase::setSpacing( TQT_TQOBJECT(widget), spacing );
		} else {
		    l->setMargin( margin );
		    l->setSpacing( margin );
		}
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		return l;
	    case VBox:
		l = new TQVBoxLayout( widget );
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		if ( widget ) {
		    MetaDataBase::setMargin( TQT_TQOBJECT(widget), margin );
		    MetaDataBase::setSpacing( TQT_TQOBJECT(widget), spacing );
		} else {
		    l->setMargin( margin );
		    l->setSpacing( margin );
		}
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		return l;
	    case Grid: {
		l = new QDesignerGridLayout( widget );
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		if ( widget ) {
		    MetaDataBase::setMargin( TQT_TQOBJECT(widget), margin );
		    MetaDataBase::setSpacing( TQT_TQOBJECT(widget), spacing );
		} else {
		    l->setMargin( margin );
		    l->setSpacing( margin );
		}
		MetaDataBase::addEntry( TQT_TQOBJECT(l) );
		return l;
	    }
	    default:
		return 0;
	    }
	}
    }
}

void WidgetFactory::deleteLayout( TQWidget *widget )
{
    if ( !widget )
	return;

    if ( widget->inherits( TQTABWIDGET_OBJECT_NAME_STRING ) )
	widget = ((TQTabWidget*)widget)->currentPage();
    if ( widget->inherits( TQWIZARD_OBJECT_NAME_STRING ) )
	widget = ((TQWizard*)widget)->currentPage();
    if ( widget->inherits( TQMAINWINDOW_OBJECT_NAME_STRING ) )
	widget = ((TQMainWindow*)widget)->centralWidget();
    if ( widget->inherits( TQWIDGETSTACK_OBJECT_NAME_STRING ) )
	widget = ((TQWidgetStack*)widget)->visibleWidget();
    delete widget->layout();
}

/*!  Factory functions for creating a widget of the type \a className
  as child of \a parent with the name \a name.

  If \a init is true, some initial default properties are set. This
  has to be in sync with the initChangedProperties() function!
*/

TQWidget *WidgetFactory::createWidget( const TQString &className, TQWidget *parent, const char *name, bool init,
  const TQRect *r, Qt::Orientation orient )
{
  if (className == TQPUSHBUTTON_OBJECT_NAME_STRING)
  {
    TQPushButton *b = 0;
    if (init)
    {
      b = new QDesignerPushButton(parent, name);
      b->setText(TQString::fromLatin1(name));
    } else
    {
      b = new QDesignerPushButton(parent, name);
    }
    TQWidget *w = find_formwindow(b);
    b->setAutoDefault(w && ((FormWindow *) w)->mainContainer()->inherits(TQDIALOG_OBJECT_NAME_STRING));
    return b;
  } else if (className == TQTOOLBUTTON_OBJECT_NAME_STRING)
  {
    if (init)
    {
      QDesignerToolButton *tb = new QDesignerToolButton(parent, name);
      tb->setText("...");
      return tb;
    }
    return new QDesignerToolButton(parent, name);
  } else if (className == TQCHECKBOX_OBJECT_NAME_STRING)
  {
    if (init)
    {
      QDesignerCheckBox *cb = new QDesignerCheckBox(parent, name);
      cb->setText(TQString::fromLatin1(name));
      return cb;
    }
    return new QDesignerCheckBox(parent, name);
  } else if (className == TQRADIOBUTTON_OBJECT_NAME_STRING)
  {
    if (init)
    {
      QDesignerRadioButton *rb = new QDesignerRadioButton(parent, name);
      rb->setText(TQString::fromLatin1(name));
      return rb;
    }
    return new QDesignerRadioButton(parent, name);
  } else if (className == TQGROUPBOX_OBJECT_NAME_STRING)
  {
    if (init)
      return new TQGroupBox(TQString::fromLatin1(name), parent, name);
    return new TQGroupBox(parent, name);
  } else if (className == TQBUTTONGROUP_OBJECT_NAME_STRING)
  {
    if (init)
      return new TQButtonGroup(TQString::fromLatin1(name), parent, name);
    return new TQButtonGroup(parent, name);
  } else if (className == TQICONVIEW_OBJECT_NAME_STRING)
  {
#if !defined(TQT_NO_ICONVIEW)
    TQIconView *iv = new TQIconView(parent, name);
    if (init)
      (void) new TQIconViewItem(iv, i18n("New Item"));
    return iv;
#else
    return 0;
#endif
  } else if (className == TQTABLE_OBJECT_NAME_STRING)
  {
#if !defined(TQT_NO_TABLE)
    if (init)
      return new TQTable(3, 3, parent, name);
    return new TQTable(parent, name);
#else
    return 0;
#endif
#ifndef TQT_NO_SQL
  } else if (className == TQDATATABLE_OBJECT_NAME_STRING)
  {
    return new TQDataTable(parent, name);
#endif //TQT_NO_SQL
  } else if (className == TQDATEEDIT_OBJECT_NAME_STRING)
  {
    return new TQDateEdit(parent, name);
  } else if (className == TQTIMEEDIT_OBJECT_NAME_STRING)
  {
    return new TQTimeEdit(parent, name);
  } else if (className == TQDATETIMEEDIT_OBJECT_NAME_STRING)
  {
    return new TQDateTimeEdit(parent, name);
  } else if (className == TQLISTBOX_OBJECT_NAME_STRING)
  {
    TQListBox *lb = new TQListBox(parent, name);
    if (init)
    {
      lb->insertItem(i18n("New Item"));
      lb->setCurrentItem(0);
    }
    return lb;
  } else if (className == TQLISTVIEW_OBJECT_NAME_STRING)
  {
    TQListView *lv = new TQListView(parent, name);
    lv->setSorting(-1);
    if (init)
    {
      lv->addColumn(i18n("Column 1"));
      lv->setCurrentItem(new TQListViewItem(lv, i18n("New Item")));
    }
    return lv;
  } else if (className == TQLINEEDIT_OBJECT_NAME_STRING)
    return new TQLineEdit(parent, name);
  else if (className == TQSPINBOX_OBJECT_NAME_STRING)
    return new TQSpinBox(parent, name);
  else if (className == TQSPLITTER_OBJECT_NAME_STRING)
    return new TQSplitter(parent, name);
  else if (className == TQMULTILINEEDIT_OBJECT_NAME_STRING)
    return new TQMultiLineEdit(parent, name);
  else if (className == TQTEXTEDIT_OBJECT_NAME_STRING)
    return new TQTextEdit(parent, name);
  else if (className == TQLABEL_OBJECT_NAME_STRING)
  {
    QDesignerLabel *l = new QDesignerLabel(parent, name);
    if (init)
    {
      l->setText(TQString::fromLatin1(name));
      MetaDataBase::addEntry(TQT_TQOBJECT(l));
      MetaDataBase::setPropertyChanged(TQT_TQOBJECT(l), "text", true);
    }
    return l;
  } else if (className == TQLAYOUTWIDGET_OBJECT_NAME_STRING)
    return new TQLayoutWidget(parent, name);
  else if (className == TQTABWIDGET_OBJECT_NAME_STRING)
  {
    TQTabWidget *tw = new QDesignerTabWidget(parent, name);
    if (init)
    {
      FormWindow *fw = find_formwindow(parent);
      TQWidget *w = fw ? new QDesignerWidget(fw, tw, "tab") : new TQWidget(tw, "tab");
      tw->addTab(w, i18n("Tab 1"));
      MetaDataBase::addEntry(TQT_TQOBJECT(w));
      w = fw ? new QDesignerWidget(fw, tw, "tab") : new TQWidget(tw, "tab");
      tw->addTab(w, i18n("Tab 2"));
      MetaDataBase::addEntry(TQT_TQOBJECT(tw));
      MetaDataBase::addEntry(TQT_TQOBJECT(w));
    }
    return tw;
  } else if (className == TQCOMBOBOX_OBJECT_NAME_STRING)
  {
    return new TQComboBox(false, parent, name);
  } else if (className == TQWIDGET_OBJECT_NAME_STRING)
  {
    if (parent &&
        (parent->inherits("FormWindow") || parent->inherits(TQWIZARD_OBJECT_NAME_STRING)
            || parent->inherits(TQTABWIDGET_OBJECT_NAME_STRING) || parent->inherits(TQTOOLBOX_OBJECT_NAME_STRING) || parent->inherits(TQMAINWINDOW_OBJECT_NAME_STRING)))
    {
      FormWindow *fw = find_formwindow(parent);
      if (fw)
      {
        QDesignerWidget *dw = new QDesignerWidget(fw, parent, name);
        MetaDataBase::addEntry(TQT_TQOBJECT(dw));
        return dw;
      }
    }
    return new TQWidget(parent, name);
  } else if (className == TQDIALOG_OBJECT_NAME_STRING)
  {
    TQDialog *dia = 0;
    if (parent && parent->inherits("FormWindow"))
      dia = new QDesignerDialog((FormWindow *) parent, parent, name);
    else
      dia = new TQDialog(parent, name);
    if (parent && !parent->inherits("MainWindow"))
      dia->reparent(parent, TQPoint(0, 0), true);
    return dia;
  } else if (className == TQWIZARD_OBJECT_NAME_STRING)
  {
    TQWizard *wiz = new QDesignerWizard(parent, name);
    if (parent && !parent->inherits("MainWindow"))
    {
      wiz->reparent(parent, TQPoint(0, 0), true);
    }
    if (init && parent && parent->inherits("FormWindow"))
    {
      QDesignerWidget *dw = new QDesignerWidget((FormWindow *) parent, wiz, "page");
      MetaDataBase::addEntry(TQT_TQOBJECT(dw));
      wiz->addPage(dw, i18n("Page"));
      TQTimer::singleShot(0, wiz, TQT_SLOT(next()));
    }
    return wiz;
  } else if (className == "Spacer")
  {
    Spacer *s = new Spacer(parent, name);
    MetaDataBase::addEntry(TQT_TQOBJECT(s));
    MetaDataBase::setPropertyChanged(TQT_TQOBJECT(s), "orientation", true);
    MetaDataBase::setPropertyChanged(TQT_TQOBJECT(s), "sizeType", true);
    if (!r)
      return s;
    if (!r->isValid() || r->width() < 2 && r->height() < 2)
      s->setOrientation(orient);
    else if (r->width() < r->height())
      s->setOrientation(Qt::Vertical);
    else
      s->setOrientation(Qt::Horizontal);
    return s;
  } else if (className == TQLCDNUMBER_OBJECT_NAME_STRING)
    return new TQLCDNumber(parent, name);
  else if (className == TQPROGRESSBAR_OBJECT_NAME_STRING)
    return new TQProgressBar(parent, name);
  else if (className == TQTEXTVIEW_OBJECT_NAME_STRING)
    return new TQTextView(parent, name);
  else if (className == TQTEXTBROWSER_OBJECT_NAME_STRING)
    return new TQTextBrowser(parent, name);
  else if (className == TQDIAL_OBJECT_NAME_STRING)
    return new TQDial(parent, name);
  else if (className == TQSLIDER_OBJECT_NAME_STRING)
  {
    TQSlider *s = new TQSlider(parent, name);
    if (!r)
      return s;
    if (!r->isValid() || r->width() < 2 && r->height() < 2)
      s->setOrientation(orient);
    else if (r->width() > r->height())
      s->setOrientation(Qt::Horizontal);
    MetaDataBase::addEntry(TQT_TQOBJECT(s));
    MetaDataBase::setPropertyChanged(TQT_TQOBJECT(s), "orientation", true);
    return s;
  } else if (className == TQSCROLLBAR_OBJECT_NAME_STRING)
  {
    TQScrollBar *s = new TQScrollBar(parent, name);
    if (!r)
      return s;
    if (!r->isValid() || r->width() < 2 && r->height() < 2)
      s->setOrientation(orient);
    else if (r->width() > r->height())
      s->setOrientation(Qt::Horizontal);
    MetaDataBase::addEntry(TQT_TQOBJECT(s));
    MetaDataBase::setPropertyChanged(TQT_TQOBJECT(s), "orientation", true);
    return s;
  } else if (className == TQFRAME_OBJECT_NAME_STRING)
  {
    if (!init)
      return new TQFrame(parent, name);
    TQFrame *f = new TQFrame(parent, name);
    f->setFrameStyle(TQFrame::StyledPanel | TQFrame::Raised);
    return f;
  } else if (className == "Line")
  {
    Line *l = new Line(parent, name);
    MetaDataBase::addEntry(TQT_TQOBJECT(l));
    MetaDataBase::setPropertyChanged(TQT_TQOBJECT(l), "orientation", true);
    MetaDataBase::setPropertyChanged(TQT_TQOBJECT(l), "frameShadow", true);
    MetaDataBase::setPropertyChanged(TQT_TQOBJECT(l), "frameShape", true);
    if (!r)
      return l;
    if (!r->isValid() || r->width() < 2 && r->height() < 2)
      l->setOrientation(orient);
    else if (r->width() < r->height())
      l->setOrientation(Qt::Vertical);
    return l;
  } else if (className == TQMAINWINDOW_OBJECT_NAME_STRING)
  {
    TQMainWindow *mw = new KmdrMainWindow(parent, name, 0);
    mw->setDockEnabled(TQt::DockMinimized, false);
    QDesignerWidget *dw = new QDesignerWidget((FormWindow *) parent, mw, "central widget");
    mw->setDockMenuEnabled(false);
    MetaDataBase::addEntry(TQT_TQOBJECT(dw));
    mw->setCentralWidget(dw);
    (void) mw->statusBar();
    dw->show();
    return mw;
  }
#ifndef TQT_NO_SQL
  else if (className == TQDATABROWSER_OBJECT_NAME_STRING)
  {
    TQWidget *w = new QDesignerDataBrowser(parent, name);
    if (parent)
      w->reparent(parent, TQPoint(0, 0), true);
    return w;
  } else if (className == TQDATAVIEW_OBJECT_NAME_STRING)
  {
    TQWidget *w = new QDesignerDataView(parent, name);
    if (parent)
      w->reparent(parent, TQPoint(0, 0), true);
    return w;
  }
#endif
#ifdef KOMMANDER

  if (className == "LineEdit")
    return new LineEdit(parent, name);
  else if (className == "ListView")
  {
    TQListView *lv = new TQListView(parent, name);
    lv->setSorting(-1);
    if (init)
    {
      lv->addColumn(i18n("Column 1"));
      lv->setCurrentItem(new TQListViewItem(lv, i18n("New Item")));
    }
    return lv;
  } 
  else if (className == "Dialog")
  {
    TQDialog *dia = 0;
    if (parent && parent->inherits("FormWindow"))
      dia = new EditorDialog((FormWindow *) parent, parent, name);
    else
      dia = new Dialog(parent, name, false);

    if (parent)
      dia->reparent(parent, TQPoint(0, 0), true);
    return dia;
  } 
  else if (className == "Wizard")
  {
    //tqDebug("Creating Wizard...");
    TQWizard *wiz;
    if (parent && parent->inherits("FormWindow"))
      wiz = new QDesignerWizard(parent, name);
    else
      wiz = new Wizard(parent, name);
    if (parent)
      wiz->reparent(parent, TQPoint(0, 0), true);
    if (init && parent && parent->inherits("FormWindow"))
    {
      QDesignerWidget *dw = new QDesignerWidget((FormWindow *) parent, wiz, "page");
      MetaDataBase::addEntry(TQT_TQOBJECT(dw));
      wiz->addPage(dw, i18n("Page 1"));
      wiz->addPage(dw, i18n("Page 2"));
      TQTimer::singleShot(0, wiz, TQT_SLOT(next()));
    }
    return wiz;
  } 
  else if (className == "TabWidget")
  {
    TQTabWidget *tw = new EditorTabWidget(parent, name);
    if (init)
    {
      FormWindow *fw = find_formwindow(parent);
      TQWidget *w = fw ? new QDesignerWidget(fw, tw, "tab") : new TQWidget(tw, "tab");
      tw->addTab(w, i18n("Tab 1"));
      MetaDataBase::addEntry(TQT_TQOBJECT(w));
      w = fw ? new QDesignerWidget(fw, tw, "tab") : new TQWidget(tw, "tab");
      tw->addTab(w, i18n("Tab 2"));
      MetaDataBase::addEntry(TQT_TQOBJECT(tw));
      MetaDataBase::addEntry(TQT_TQOBJECT(w));
    }
    return tw;
  } else if (className == "ToolBox")
  {
    TQToolBox *tw = new EditorToolBox(parent, name);
    if (init)
    {
      FormWindow *fw = find_formwindow(parent);
      TQWidget *w = fw ? new QDesignerWidget(fw, tw, "toolbox") : new TQWidget(tw, "toolbox");
      tw->addItem(w, i18n("Page 1"));
      MetaDataBase::addEntry(TQT_TQOBJECT(w));
      w = fw ? new QDesignerWidget(fw, tw, "toolbox") : new TQWidget(tw, "toolbox");
      tw->addItem(w, i18n("Page 2"));
      MetaDataBase::addEntry(TQT_TQOBJECT(tw));
      MetaDataBase::addEntry(TQT_TQOBJECT(w));
    }
    return tw;
  }
  else if (className == "ExecButton")
    return new ExecButton(parent, name);
  else if (className == "CloseButton")
    return new CloseButton(parent, name);
  else if (className == "SubDialog")
    return new SubDialog(parent, name);
  else if (className == "FileSelector")
    return new FileSelector(parent, name);
  else if (className == "TextEdit")
    return new TextEdit(parent, name);
  else if (className == "RadioButton")
    return new RadioButton(parent, name);
  else if (className == "ButtonGroup")
    return new ButtonGroup(parent, name);
  else if (className == "GroupBox")
    return new GroupBox(parent, name);
  else if (className == "CheckBox")
    return new CheckBox(parent, name);
  else if (className == "ComboBox")
    return new ComboBox(parent, name);
  else if (className == "SpinBoxInt")
    return new SpinBoxInt(parent, name);
  else if (className == "ListBox")
    return new ListBox(parent, name);
  else if (className == "ScriptObject")
    return new ScriptObject(parent, name);
  else if (className == "RichTextEditor")
    return new RichTextEditor(parent, name);
  else if (className == "DatePicker")
    return new DatePicker(parent, name);
  else if (className == "PopupMenu")
    return new PopupMenu(parent, name);
  else if (className == "FontDialog")
    return new FontDialog(parent, name);
  else if (className == "AboutDialog")
    return new AboutDialog(parent, name);
  else if (className == "TreeWidget")
  {
    TQListView *lv = new TreeWidget(parent, name);
    lv->setSorting(-1);
    if (init)
    {
      lv->addColumn(i18n("Column 1"));
      lv->setCurrentItem(new TQListViewItem(lv, i18n("New Item")));
    }
    return lv;
  } else if (className == "Slider")
  {
    Slider *s = new Slider(parent, name);
    if (!r)
      return s;
    if (!r->isValid() || r->width() < 2 && r->height() < 2)
      s->setOrientation(orient);
    else if (r->width() > r->height())
      s->setOrientation(Qt::Horizontal);
    MetaDataBase::addEntry(TQT_TQOBJECT(s));
    MetaDataBase::setPropertyChanged(TQT_TQOBJECT(s), "orientation", true);
    return s;
  }
#endif

  TQWidget *w = KommanderFactory::createWidget(className, parent, name);
  return w;
}



/*!  Find out which type the layout of the widget is. Returns \c HBox,
  \c VBox, \c Grid or \c NoLayout.  \a layout points to this
  TQWidget::layout() of \a w or to 0 after the function call.
*/

WidgetFactory::LayoutType WidgetFactory::layoutType( TQWidget *w, TQLayout *&layout )
{
    layout = 0;

    if ( w && w->inherits( TQTABWIDGET_OBJECT_NAME_STRING ) )
	w = ((TQTabWidget*)w)->currentPage();
    if ( w->inherits( TQTOOLBOX_OBJECT_NAME_STRING ) )
    w = ((TQToolBox*)w)->currentItem();
    if ( w && w->inherits( TQWIZARD_OBJECT_NAME_STRING ) )
	w = ((TQWizard*)w)->currentPage();
    if ( w && w->inherits( TQMAINWINDOW_OBJECT_NAME_STRING ) )
	w = ((TQMainWindow*)w)->centralWidget();
    if ( w && w->inherits( TQWIDGETSTACK_OBJECT_NAME_STRING ) )
	w = ((TQWidgetStack*)w)->visibleWidget();

    if ( w && w->inherits( TQSPLITTER_OBJECT_NAME_STRING ) )
	return ( (TQSplitter*)w )->orientation() ==Qt::Horizontal ? HBox : VBox;

    if ( !w || !w->layout() )
	return NoLayout;
    TQLayout *lay = w->layout();

    if ( w->inherits( TQGROUPBOX_OBJECT_NAME_STRING ) ) {
	TQObjectList *l = TQT_TQOBJECT(lay)->queryList( TQLAYOUT_OBJECT_NAME_STRING );
	if ( l && l->first() )
	    lay = (TQLayout*)l->first();
	delete l;
    }
    layout = lay;

    if ( lay->inherits( TQHBOXLAYOUT_OBJECT_NAME_STRING ) )
	return HBox;
    else if ( lay->inherits( TQVBOXLAYOUT_OBJECT_NAME_STRING ) )
	return VBox;
    else if ( lay->inherits( TQGRIDLAYOUT_OBJECT_NAME_STRING ) )
	return Grid;
    return NoLayout;
}

/*!
  \overload
*/
WidgetFactory::LayoutType WidgetFactory::layoutType( TQLayout *layout )
{
    if ( layout->inherits( TQHBOXLAYOUT_OBJECT_NAME_STRING ) )
	return HBox;
    else if ( layout->inherits( TQVBOXLAYOUT_OBJECT_NAME_STRING ) )
	return VBox;
    else if ( layout->inherits( TQGRIDLAYOUT_OBJECT_NAME_STRING ) )
	return Grid;
    return NoLayout;
}

/*!
  \overload
*/
WidgetFactory::LayoutType WidgetFactory::layoutType( TQWidget *w )
{
    TQLayout *l = 0;
    return layoutType( w, l );
}


TQWidget *WidgetFactory::layoutParent( TQLayout *layout )
{
    TQObject *o = TQT_TQOBJECT(layout);
    while ( o ) {
	if ( o->isWidgetType() )
	    return (TQWidget*)o;
	o = o->parent();
    }
    return 0;
}

/*!  Returns the widget into which children should be inserted when \a
  w is a container known to the designer.

  Usually that is \a w itself, sometimes it is different (e.g. a
  tabwidget is known to the designer as a container but the child
  widgets should be inserted into the current page of the
  tabwidget. So in this case this function returns the current page of
  the tabwidget.)
 */
TQWidget* WidgetFactory::containerOfWidget( TQWidget *w )
{
    if ( !w )
	return w;
    if ( w->inherits( TQTABWIDGET_OBJECT_NAME_STRING ) )
	return ((TQTabWidget*)w)->currentPage();
    if ( w->inherits( TQTOOLBOX_OBJECT_NAME_STRING ) )
    return ((TQToolBox*)w)->currentItem();
    if ( w->inherits( TQWIZARD_OBJECT_NAME_STRING ) )
	return ((TQWizard*)w)->currentPage();
    if ( w->inherits( TQWIDGETSTACK_OBJECT_NAME_STRING ) )
	return ((TQWidgetStack*)w)->visibleWidget();
    if ( w->inherits( TQMAINWINDOW_OBJECT_NAME_STRING ) )
	return ((TQMainWindow*)w)->centralWidget();
    return w;
}

/*!  Returns the actual designer widget of the container \a w. This is
  normally \a w itself, but might be a parent or grand parent of \a w
  (e.g. when working with a tabwidget and \a w is the container which
  contains and layouts childs, but the actual widget known to the
  designer is the tabwidget which is the parent of \a w. So this
  function returns the tabwidget then.)
*/

TQWidget* WidgetFactory::widgetOfContainer( TQWidget *w )
{
    if ( w->parentWidget() && w->parentWidget()->inherits( TQWIDGETSTACK_OBJECT_NAME_STRING ) )
	w = w->parentWidget();
    while ( w ) {
	if ( WidgetDatabase::isContainer( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( TQT_TQOBJECT(w) ) ) ) ||
	     w && w->parentWidget() && w->parentWidget()->inherits( "FormWindow" ) )
	    return w;
	w = w->parentWidget();
    }
    return w;
}

/*!
  Returns whether \a o is a passive interactor or not.
 */
bool WidgetFactory::isPassiveInteractor( TQObject* o )
{
    if ( TQApplication::activePopupWidget() ) // if a popup is open, we have to make sure that this one is closed, else X might do funny things
	return true;

    if ( o->inherits( TQTABBAR_OBJECT_NAME_STRING ) || ::tqqt_cast<TQToolBox*>(o->parent()) )
	return true;
    else if ( o->inherits( TQSIZEGRIP_OBJECT_NAME_STRING ) )
	return true;
    else if ( o->inherits( TQTOOLBUTTON_OBJECT_NAME_STRING ) && o->parent() && o->parent()->inherits( TQTABBAR_OBJECT_NAME_STRING ) )
	return true;
    else if ( o->parent() && o->parent()->inherits( TQWIZARD_OBJECT_NAME_STRING ) && o->inherits( TQPUSHBUTTON_OBJECT_NAME_STRING ) )
	return true;
    else if ( o->parent() && o->parent()->inherits( TQMAINWINDOW_OBJECT_NAME_STRING ) && o->inherits( TQMENUBAR_OBJECT_NAME_STRING ) )
	return true;
    else if ( o->inherits( TQDOCKWINDOWHANDLE_OBJECT_NAME_STRING ) )
	return true;
    else if ( o->inherits( TQHIDEDOCK_OBJECT_NAME_STRING ) )
	return true;

    return false;
}


/*!
  Returns the class name of object \a o that should be used for externally (i.e. for saving)
 */
const char* WidgetFactory::classNameOf( TQObject* o )
{
  if (o->inherits("QDesignerTabWidget"))
    return TQTABWIDGET_OBJECT_NAME_STRING;
#ifdef KOMMANDER
  else if (o->inherits("EditorTabWidget"))
    return "TabWidget";
  else if (o->inherits("EditorToolBox"))
    return "ToolBox";
#endif
  else if (o->inherits("QDesignerDialog"))
    return TQDIALOG_OBJECT_NAME_STRING;
  else if (o->inherits("QDesignerWidget"))
    return TQWIDGET_OBJECT_NAME_STRING;
  else if (o->inherits("CustomWidget"))
    return ((CustomWidget *) o)->realClassName().latin1();
  else if (o->inherits("QDesignerLabel"))
    return TQLABEL_OBJECT_NAME_STRING;
  else if (o->inherits("QDesignerWizard"))
    return TQWIZARD_OBJECT_NAME_STRING;
  else if (o->inherits("EditorWizard"))
    return "Wizard";
  else if (o->inherits("QDesignerPushButton"))
    return TQPUSHBUTTON_OBJECT_NAME_STRING;
  else if (o->inherits("QDesignerToolButton"))
    return TQTOOLBUTTON_OBJECT_NAME_STRING;
  else if (o->inherits("QDesignerRadioButton"))
    return TQRADIOBUTTON_OBJECT_NAME_STRING;
  else if (o->inherits("QDesignerCheckBox"))
    return TQCHECKBOX_OBJECT_NAME_STRING;
  else if (o->inherits("QDesignerMenuBar"))
    return TQMENUBAR_OBJECT_NAME_STRING;
  else if (o->inherits("QDesignerToolBar"))
    return TQTOOLBAR_OBJECT_NAME_STRING;
#ifndef TQT_NO_SQL
  else if (o->inherits("QDesignerDataBrowser"))
    return TQDATABROWSER_OBJECT_NAME_STRING;
  else if (o->inherits("QDesignerDataView"))
    return TQDATAVIEW_OBJECT_NAME_STRING;
#endif
  else if (o->inherits("EditorDialog"))
    return "Dialog";
  return o->className();
}

/*!  As some properties are set by default when creating a widget this
  functions markes this properties as changed. Has to be in sync with
  createWidget()!
*/

void WidgetFactory::initChangedProperties( TQObject *o )
{
    MetaDataBase::setPropertyChanged( o, "name", true );
    if ( !o->inherits( "QDesignerToolBar" ) && !o->inherits( "QDesignerMenuBar" ) )
	MetaDataBase::setPropertyChanged( o, "geometry", true );

    if ( o->inherits( TQPUSHBUTTON_OBJECT_NAME_STRING ) || o->inherits(TQRADIOBUTTON_OBJECT_NAME_STRING) || o->inherits( TQCHECKBOX_OBJECT_NAME_STRING ) || o->inherits( TQTOOLBUTTON_OBJECT_NAME_STRING ) )
	MetaDataBase::setPropertyChanged( o, "text", true );
    else if (::tqqt_cast<TQToolButton*>(o) && ::tqqt_cast<TQToolBox*>(widgetOfContainer((TQWidget*)o->parent()))) {
        MetaDataBase::setPropertyChanged( o, "usesTextLabel", TRUE );
        MetaDataBase::setPropertyChanged( o, "textLabel", TRUE );
        MetaDataBase::setPropertyChanged( o, "autoRaise", TRUE );
        MetaDataBase::setPropertyChanged( o, "textPosition", TRUE );
    }    else if ( o->inherits( TQGROUPBOX_OBJECT_NAME_STRING ) )
	MetaDataBase::setPropertyChanged( o, "title", true );
    else if ( o->isA( TQFRAME_OBJECT_NAME_STRING ) ) {
	MetaDataBase::setPropertyChanged( o, "frameShadow", true );
	MetaDataBase::setPropertyChanged( o, "frameShape", true );
    } else if ( o->inherits( TQTABWIDGET_OBJECT_NAME_STRING ) || o->inherits( TQWIZARD_OBJECT_NAME_STRING ) ) {
	MetaDataBase::setPropertyChanged( o, "pageTitle", true );
	MetaDataBase::setPropertyChanged( o, "pageName", true );
#ifndef TQT_NO_TABLE
    } else if ( o->inherits( TQTABLE_OBJECT_NAME_STRING ) && !o->inherits( TQDATATABLE_OBJECT_NAME_STRING ) ) {
	MetaDataBase::setPropertyChanged( o, "numRows", true );
	MetaDataBase::setPropertyChanged( o, "numCols", true );
	TQTable *t = (TQTable*)o;
	for ( int i = 0; i < 3; ++i ) {
	    t->horizontalHeader()->setLabel( i, TQString::number( i + 1 ) );
	    t->verticalHeader()->setLabel( i, TQString::number( i + 1 ) );
	}
#endif
    } else if ( ::tqqt_cast<TQToolBox*>(o) ) {
        MetaDataBase::setPropertyChanged( o, "currentIndex", true );
        MetaDataBase::setPropertyChanged( o, "itemName", true );
        MetaDataBase::setPropertyChanged( o, "itemLabel", true );
        MetaDataBase::setPropertyChanged( o, "itemIconSet", true );
        MetaDataBase::setPropertyChanged( o, "itemToolTip", true );
        MetaDataBase::setPropertyChanged( o, "itemBackgroundMode", true );
    } else if ( o->inherits( TQSPLITTER_OBJECT_NAME_STRING )  ) {
	MetaDataBase::setPropertyChanged( o, "orientation", true );
    } else if ( o->inherits( "QDesignerToolBar" )  ) {
	MetaDataBase::setPropertyChanged( o, "label", true );
    } else if ( o->inherits( "QDesignerMenuBar" )  ) {
	MetaDataBase::setPropertyChanged( o, "itemName", true );
	MetaDataBase::setPropertyChanged( o, "itemNumber", true );
	MetaDataBase::setPropertyChanged( o, "itemText", true );
    }
}

bool WidgetFactory::hasSpecialEditor( int id )
{
  TQString className = WidgetDatabase::className(id);

  if (className == "TextEdit" || className == "ComboBox" || className == "ListBox" || className ==
      "TreeWidget" || className == "TextBrowser")
    return true;

  if (className.mid(1) == "ListBox")
    return true;
  if (className.mid(1) == "ComboBox")
    return true;
  if (className.mid(1) == "ListView")
    return true;
  if (className.mid(1) == "IconView")
    return true;
  if (className == TQTEXTEDIT_OBJECT_NAME_STRING || className == TQMULTILINEEDIT_OBJECT_NAME_STRING)
    return true;
  if (className.contains("Table"))
    return true;

  return false;
}

bool WidgetFactory::hasItems( int id )
{
  TQString className = WidgetDatabase::className(id);

  if (className == "ComboBox" || className == "ListBox" || className == "TreeWidget")
    return true;
  if (className.mid(1) == "ListBox" || className.mid(1) == "ListView" ||
      className.mid(1) == "IconView" || className.mid(1) == "ComboBox" ||
      className.contains("Table"))
    return true;

  return false;
}

void WidgetFactory::editWidget( int id, TQWidget *parent, TQWidget *editWidget, FormWindow *fw )
{
  TQString className = WidgetDatabase::className(id);

#ifdef KOMMANDER
  if (className == "ComboBox")
  {
    if (!editWidget->inherits(TQCOMBOBOX_OBJECT_NAME_STRING))
      return;

    TQComboBox *cb = (TQComboBox *) editWidget;

    ListBoxEditor *e = new ListBoxEditor(parent, cb->listBox(), fw);
    e->exec();
    delete e;

    cb->update();

    return;
  }
  if (className == "TextEdit" || className == "TextBrowser")
  {
    MultiLineEditor *e = new MultiLineEditor(parent, editWidget, fw);
    e->exec();
    delete e;
    return;
  }
  if (className == "TreeWidget")
  {
    if (!editWidget->inherits(TQLISTVIEW_OBJECT_NAME_STRING))
      return;
    TQListView *lv = (TQListView *) editWidget;
    ListViewEditor *e = new ListViewEditor(parent, lv, fw);
    e->exec();
    delete e;
    return;
  }
  if (className == "ListBox")
  {
    if (!editWidget->inherits(TQLISTBOX_OBJECT_NAME_STRING))
      return;
    ListBoxEditor *e = new ListBoxEditor(parent, editWidget, fw);
    e->exec();
    delete e;
    return;
  }
#endif
  if (className.mid(1) == "ListBox")
  {
    if (!editWidget->inherits(TQLISTBOX_OBJECT_NAME_STRING))
      return;
    ListBoxEditor *e = new ListBoxEditor(parent, editWidget, fw);
    e->exec();
    delete e;
    return;
  }

  if (className.mid(1) == "ComboBox")
  {
    if (!editWidget->inherits(TQCOMBOBOX_OBJECT_NAME_STRING))
      return;
    TQComboBox *cb = (TQComboBox *) editWidget;
    ListBoxEditor *e = new ListBoxEditor(parent, cb->listBox(), fw);
    e->exec();
    delete e;
    cb->update();
    return;
  }

  if (className.mid(1) == "ListView")
  {
    if (!editWidget->inherits(TQLISTVIEW_OBJECT_NAME_STRING))
      return;
    TQListView *lv = (TQListView *) editWidget;
    ListViewEditor *e = new ListViewEditor(parent, lv, fw);
    e->exec();
    delete e;
    return;
  }

  if (className.mid(1) == "IconView")
  {
    if (!editWidget->inherits(TQICONVIEW_OBJECT_NAME_STRING))
      return;
    IconViewEditor *e = new IconViewEditor(parent, editWidget, fw);
    e->exec();
    delete e;
    return;
  }

  if (className == TQMULTILINEEDIT_OBJECT_NAME_STRING || className == TQTEXTEDIT_OBJECT_NAME_STRING)
  {
    MultiLineEditor *e = new MultiLineEditor(parent, editWidget, fw);
    e->exec();
    delete e;
    return;
  }
#ifndef TQT_NO_TABLE
  if (className.contains("Table"))
  {
    TableEditor *e = new TableEditor(parent, editWidget, fw);
    e->exec();
    delete e;
    return;
  }
#endif
}

bool WidgetFactory::canResetProperty( TQObject *w, const TQString &propName )
{
    if ( propName == "name" || propName == "geometry" )
	return false;
    TQStringList l = *changedProperties->find( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ) );
    return l.findIndex( propName ) == -1;
}

bool WidgetFactory::resetProperty( TQObject *w, const TQString &propName )
{
    const TQMetaProperty *p = w->metaObject()->property( w->metaObject()->
							findProperty( propName, true ), true );
    if (!p )
	return false;
    return p->reset( w );
}

TQVariant WidgetFactory::defaultValue( TQObject *w, const TQString &propName )
{
    if ( propName == "wordwrap" ) {
	int v = defaultValue( w, "alignment" ).toInt();
	return TQVariant( ( v & WordBreak ) == WordBreak, 0 );
    } else if ( propName == "toolTip" || propName == "whatsThis" ) {
	return TQVariant( TQString::fromLatin1( "" ) );
    } else if ( w->inherits( "CustomWidget" ) ) {
	return TQVariant();
    } else if ( propName == "frameworkCode" ) {
	return TQVariant( true, 0 );
    } else if ( propName == "layoutMargin" ) {
	if ( w->inherits( TQLAYOUTWIDGET_OBJECT_NAME_STRING ) )
	    return TQVariant( 0 );
	else if ( MainWindow::self->formWindow() )
	    return TQVariant( MainWindow::self->formWindow()->layoutDefaultMargin() );
    } else if ( propName == "layoutSpacing" ) {
	if ( MainWindow::self->formWindow() )
	    return TQVariant( MainWindow::self->formWindow()->layoutDefaultSpacing() );
    }

    return *( *defaultProperties->find( WidgetDatabase::idFromClassName( classNameOf( w ) ) ) ).find( propName );
}

TQString WidgetFactory::defaultCurrentItem( TQObject *w, const TQString &propName )
{
    const TQMetaProperty *p = w->metaObject()->
			     property( w->metaObject()->findProperty( propName, true ), true );
    if ( !p ) {
	int v = defaultValue( w, "alignment" ).toInt();
	if ( propName == "hAlign" ) {
	    if ( ( v & AlignAuto ) == AlignAuto )
		return "AlignAuto";
	    if ( ( v & AlignLeft ) == AlignLeft )
		return "AlignLeft";
	    if ( ( v & AlignCenter ) == AlignCenter || ( v & AlignHCenter ) == AlignHCenter )
		return "AlignHCenter";
	    if ( ( v & AlignRight ) == AlignRight )
		return "AlignRight";
	    if ( ( v & AlignJustify ) == AlignJustify )
		return "AlignJustify";
	} else if ( propName == "vAlign" ) {
	    if ( ( v & AlignTop ) == AlignTop )
		return "AlignTop";
	    if ( ( v & AlignCenter ) == AlignCenter || ( v & AlignVCenter ) == AlignVCenter )
		return "AlignVCenter";
	    if ( ( v & AlignBottom ) == AlignBottom )
		return "AlignBottom";
	}
	return TQString();

    }
    return p->valueToKey( defaultValue( w, propName ).toInt() );
}

TQWidget *WidgetFactory::createCustomWidget( TQWidget *parent, const char *name, MetaDataBase::CustomWidget *w )
{
    if ( !w )
	return 0;
    return new CustomWidget( parent, name, w );
}

TQVariant WidgetFactory::property( TQObject *w, const char *name )
{
    TQVariant v = w->property( name );
    if ( v.isValid() )
	return v;
    return MetaDataBase::fakeProperty( w, name );
}

void QDesignerLabel::updateBuddy()
{

    if ( myBuddy.isEmpty() )
	return;

    TQObjectList *l = topLevelWidget()->queryList( TQWIDGET_OBJECT_NAME_STRING, myBuddy, false, true );
    if ( !l || !l->first() ) {
	delete l;
	return;
    }

    TQLabel::setBuddy( (TQWidget*)l->first() );
    delete l;
}

void QDesignerWidget::paintEvent( TQPaintEvent *e )
{
    formwindow->paintGrid( this, e );
}

void QDesignerDialog::paintEvent( TQPaintEvent *e )
{
    formwindow->paintGrid( this, e );
}

void EditorDialog::paintEvent( TQPaintEvent *e )
{
    formwindow->paintGrid( this, e );
}

TQSizePolicy TQLayoutWidget::sizePolicy() const
{
    return sp;
}

bool TQLayoutWidget::event( TQEvent *e )
{
    if ( e && ( e->type() == TQEvent::ChildInserted ||
		e->type() == TQEvent::ChildRemoved ||
		e->type() == TQEvent::LayoutHint ||
		e->type() == TQEvent::Reparent ) )
	updateSizePolicy();
    return TQWidget::event( e );
}

/*
  This function must be called on TQLayoutWidget creation and whenever
  the TQLayoutWidget's parent layout changes (e.g., from a TQHBoxLayout
  to a TQVBoxLayout), because of the (illogical) way layouting works.
*/
void TQLayoutWidget::updateSizePolicy()
{
    TQObjectList clo = childrenListObject();
    if ( clo.isEmpty() || clo.count() == 0 ) {
	sp = TQWidget::sizePolicy();
	return;
    }

    /*
      TQSizePolicy::MayShrink & friends are private. Here we assume the
      following:

	  Fixed = 0
	  Maximum = MayShrink
	  Minimum = MayGrow
	  Preferred = MayShrink | MayGrow
    */

    int ht = (int) TQSizePolicy::Preferred;
    int vt = (int) TQSizePolicy::Preferred;

    if ( layout() ) {
	/*
	  parentLayout is set to the parent layout if there is one and if it is
	  top level, in which case layouting is illogical.
	*/
	TQLayout *parentLayout = 0;
	if ( parent() && parent()->isWidgetType() ) {
	    parentLayout = ((TQWidget *)parent())->layout();
	    if ( parentLayout && parentLayout->mainWidget()->inherits(TQLAYOUTWIDGET_OBJECT_NAME_STRING) )
		parentLayout = 0;
	}

	TQObjectListIt it( childrenListObject() );
	TQObject *o;

	if ( layout()->inherits(TQVBOXLAYOUT_OBJECT_NAME_STRING) ) {
	    if ( parentLayout && parentLayout->inherits(TQHBOXLAYOUT_OBJECT_NAME_STRING) )
		vt = TQSizePolicy::Minimum;
	    else
		vt = TQSizePolicy::Fixed;

	    while ( ( o = it.current() ) ) {
		++it;
		if ( !o->isWidgetType() || ( (TQWidget*)o )->testWState( WState_ForceHide ) )
		    continue;
		TQWidget *w = (TQWidget*)o;

		if ( !w->sizePolicy().mayGrowHorizontally() )
		    ht &= ~TQSizePolicy::Minimum;
		if ( !w->sizePolicy().mayShrinkHorizontally() )
		    ht &= ~TQSizePolicy::Maximum;
		if ( w->sizePolicy().mayGrowVertically() )
		    vt |= TQSizePolicy::Minimum;
		if ( w->sizePolicy().mayShrinkVertically() )
		    vt |= TQSizePolicy::Maximum;
	    }
	} else if ( layout()->inherits(TQHBOXLAYOUT_OBJECT_NAME_STRING) ) {
	    if ( parentLayout && parentLayout->inherits(TQVBOXLAYOUT_OBJECT_NAME_STRING) )
		ht = TQSizePolicy::Minimum;
	    else
		ht = TQSizePolicy::Fixed;

	    while ( ( o = it.current() ) ) {
		++it;
		if ( !o->isWidgetType() || ( (TQWidget*)o )->testWState( WState_ForceHide ) )
		    continue;
		TQWidget *w = (TQWidget*)o;

		if ( w->sizePolicy().mayGrowHorizontally() )
		    ht |= TQSizePolicy::Minimum;
		if ( w->sizePolicy().mayShrinkHorizontally() )
		    ht |= TQSizePolicy::Maximum;
		if ( !w->sizePolicy().mayGrowVertically() )
		    vt &= ~TQSizePolicy::Minimum;
		if ( !w->sizePolicy().mayShrinkVertically() )
		    vt &= ~TQSizePolicy::Maximum;
	    }
	} else if ( layout()->inherits(TQGRIDLAYOUT_OBJECT_NAME_STRING) ) {
	    ht = TQSizePolicy::Fixed;
	    vt = TQSizePolicy::Fixed;
	    if ( parentLayout ) {
		if ( parentLayout->inherits(TQVBOXLAYOUT_OBJECT_NAME_STRING) )
		    ht = TQSizePolicy::Minimum;
		else if ( parentLayout->inherits(TQHBOXLAYOUT_OBJECT_NAME_STRING) )
		    vt = TQSizePolicy::Minimum;
	    }

	    while ( ( o = it.current() ) ) {
		++it;
		if ( !o->isWidgetType() || ( (TQWidget*)o )->testWState( WState_ForceHide ) )
		    continue;
		TQWidget *w = (TQWidget*)o;

		if ( w->sizePolicy().mayGrowHorizontally() )
		    ht |= TQSizePolicy::Minimum;
		if ( w->sizePolicy().mayShrinkHorizontally() )
		    ht |= TQSizePolicy::Maximum;
		if ( w->sizePolicy().mayGrowVertically() )
		    vt |= TQSizePolicy::Minimum;
		if ( w->sizePolicy().mayShrinkVertically() )
		    vt |= TQSizePolicy::Maximum;
	    }
	}
#ifdef USE_QT4
	if ( layout()->expanding() & TQSizePolicy::Horizontally )
	    ht = TQSizePolicy::Expanding;
	if ( layout()->expanding() & TQSizePolicy::Vertically )
	    vt = TQSizePolicy::Expanding;
#else // USE_QT4
	if ( layout()->expanding() & TQSizePolicy::Horizontally )
	    ht = TQSizePolicy::Expanding;
	if ( layout()->expanding() & TQSizePolicy::Vertically )
	    vt = TQSizePolicy::Expanding;
#endif // USE_QT4

	layout()->invalidate();
    }

    sp = TQSizePolicy( (TQSizePolicy::SizeType) ht, (TQSizePolicy::SizeType) vt );
    updateGeometry();
}

void CustomWidget::paintEvent( TQPaintEvent *e )
{
    if ( parentWidget() && parentWidget()->inherits( "FormWindow" ) ) {
	( (FormWindow*)parentWidget() )->paintGrid( this, e );
    } else {
	TQPainter p( this );
	p.fillRect( rect(), colorGroup().dark() );
	p.drawPixmap( ( width() - cusw->pixmap->width() ) / 2,
		      ( height() - cusw->pixmap->height() ) / 2,
		      *cusw->pixmap );
    }
}


#include "widgetfactory.moc"