summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/designer/rbuic/form.cpp
blob: eb9d6ee78c8944d28a84b624c678ab547803ded9 (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
/**********************************************************************
** Copyright (C) 2000 Trolltech AS.  All rights reserved.
** Copyright (c) 2002 Germain Garand <germain@ebooksfrance.com>
**
** This file is part of Qt 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.
**
**********************************************************************/
/*
** 06/2002 : Initial release of puic, the PerlQt User Interface Compiler,
**           a work derivated from uic (the Qt User Interface Compiler)
**           and pyuic (the PyQt User Interface Compiler).
**
**           G.Garand
**
**********************************************************************/

#include "uic.h"
#include "parser.h"
#include "widgetdatabase.h"
#include "domtool.h"

#include <tqstringlist.h>
#include <tqregexp.h>
#include <tqfile.h>
#include <tqfileinfo.h>

#define NO_STATIC_COLORS
#include <globaldefs.h>

#include <zlib.h>

static TTQByteArray unzipXPM( TTQString data, ulong& length )
{
    const int lengthOffset = 4;
    int baSize = data.length() / 2 + lengthOffset;
    uchar *ba = new uchar[ baSize ];
    for ( int i = lengthOffset; i < baSize; ++i ) {
        char h = data[ 2 * (i-lengthOffset) ].latin1();
        char l = data[ 2 * (i-lengthOffset) + 1 ].latin1();
	uchar r = 0;
	if ( h <= '9' )
	    r += h - '0';
	else
	    r += h - 'a' + 10;
	r = r << 4;
	if ( l <= '9' )
	    r += l - '0';
	else
	    r += l - 'a' + 10;
	ba[ i ] = r;
    }
    // qUncompress() expects the first 4 bytes to be the expected length of the
    // uncompressed data 
    ba[0] = ( length & 0xff000000 ) >> 24;
    ba[1] = ( length & 0x00ff0000 ) >> 16;
    ba[2] = ( length & 0x0000ff00 ) >> 8;
    ba[3] = ( length & 0x000000ff );
    TTQByteArray baunzip = qUncompress( ba, baSize );
    delete[] ba;
    return baunzip;
}

static TTQString imageDataName(TTQString name) {
	TTQString result = name + "_data";
	result.replace("@", "@@");
	return result;
}

/*!
  Creates an implementation ( cpp-file ) for the form given in \a e

  \sa createFormDecl(), createObjectImpl()
 */
void Uic::createFormImpl( const TTQDomElement &e )
{
    TTQDomElement n;
    TTQDomNodeList nl;
    int i;
    TTQString objClass = getClassName( e );
    if ( objClass.isEmpty() )
	return;
    TTQString objName = getObjectName( e );
	
	if (hasKDEwidget) {
    	out << indent << "retquire 'Korundum'" << endl << endl;
	} else {
    	out << indent << "retquire 'Qt'" << endl << endl;
	}

    // generate local and local includes retquired
    TTQStringList globalIncludes, localIncludes;
    TTQStringList::Iterator it;
    TTQStringList sqlClasses;

    TTQMap<TTQString, CustomInclude> customWidgetIncludes;
    TTQMap<TTQString, TTQString> functionImpls;

    // find additional slots
    TTQStringList extraSlots;
    TTQStringList extraSlotTypes;
    nl = e.parentNode().toElement().elementsByTagName( "slot" );
    for ( i = 0; i < (int) nl.length(); i++ ) {
	n = nl.item(i).toElement();
	if ( n.parentNode().toElement().tagName() != "slots"
	     && n.parentNode().toElement().tagName() != "connections" )
	    continue;
	if ( n.attribute( "language", "C++" ) != "C++" )
	    continue;
	TTQString slotName = n.firstChild().toText().data().stripWhiteSpace();
	if ( slotName.endsWith( ";" ) )
	    slotName = slotName.left( slotName.length() - 1 );

	extraSlots += Parser::cleanArgs(slotName);
	extraSlotTypes += n.attribute( "returnType", "void" );
    }

    // find signals
    TTQStringList extraSignals;
    nl = e.parentNode().toElement().elementsByTagName( "signal" );
    for ( i = 0; i < (int) nl.length(); i++ ) {
	n = nl.item(i).toElement();
	if ( n.parentNode().toElement().tagName() != "signals"
	     && n.parentNode().toElement().tagName() != "connections" )
	    continue;
	if ( n.attribute( "language", "C++" ) != "C++" )
	    continue;
	TTQString sigName = n.firstChild().toText().data().stripWhiteSpace();
	if ( sigName.endsWith( ";" ) )
	    sigName = sigName.left( sigName.length() - 1 );
	extraSignals += sigName;
    }

    //find additional functions
    TTQStringList extraFunctions;
    for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {
        if ( n.tagName() == "functions" ) { // compatibility
            for ( TTQDomElement n2 = n.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) {
                if ( n2.tagName() == "function" ) {
                    TTQString fname;
                    if( !n2.attribute("name").isNull() )
                    {
                        fname = n2.attribute( "name" );
                        fname = Parser::cleanArgs( fname );
                        functionImpls.insert( fname, n2.firstChild().toText().data() );
                    }
                    else
                    {
                        fname = n2.text();
                        fname = Parser::cleanArgs( fname );
                    }
                    extraFunctions += fname;
                }
            }
        } else if ( n.tagName() == "customwidgets" ) {
	    TTQDomElement n2 = n.firstChild().toElement();
	    while ( !n2.isNull() ) {
		if ( n2.tagName() == "customwidget" ) {
		    TTQDomElement n3 = n2.firstChild().toElement();
		    TTQString cl, header;
		    WidgetDatabaseRecord *r = new WidgetDatabaseRecord;
		    while ( !n3.isNull() ) {
			if ( n3.tagName() == "class" ) {
			    cl = n3.firstChild().toText().data();
			    r->name = cl;
			} else if ( n3.tagName() == "header" ) {
			    CustomInclude ci;
			    ci.header = n3.firstChild().toText().data();
			    ci.location = n3.attribute( "location", "global" );
			    r->includeFile = ci.header;
			    header = ci.header;
			    customWidgetIncludes.insert( cl, ci );
			}
			WidgetDatabase::append( r );
			n3 = n3.nextSibling().toElement();
		    }

		    if (cl.isEmpty())
			cl = "UnnamedCustomClass";

		    int ext = header.findRev('.');

		    if (ext >= 0)
			header.truncate(ext);

		    if (header.isEmpty())
			header = cl.lower();

//		    if (!nofwd)
//		    	out << "use " << cl << ";" << endl; // FIXME: what about header ?
		}
		n2 = n2.nextSibling().toElement();
	    }
	}
    }

    out << "class " << nameOfClass << " < " << objClass << endl << endl;

    // QtRuby sig/slot declaration
	
    ++indent;
    
	if ( !extraSlots.isEmpty() ) {
		out << indent << "slots 'languageChange()'";
    	for ( it = extraSlots.begin(); it != extraSlots.end(); ++it ) {
			if (it == extraSlots.begin()) {
				out << "," << endl;
			}
	    	rubySlot( it );
	    	out << ( ((*it) == extraSlots.last()) ? "":",") << endl;
		}
		out << endl;
     }

    // create signals
    if ( !extraSignals.isEmpty() ) {
		out << indent << "signals ";
		--indent;
		for ( it = extraSignals.begin(); it != extraSignals.end(); ++it ) {
	    	rubySlot( it );
			if (it == extraSignals.begin()) {
				++indent;
			}
	    	out << ( ((*it) == extraSignals.last()) ? "":",") << endl;
		}
		out << endl;
    }


    // children
    if( !objectNames.isEmpty() )
    	qWarning("WARNING : objectNames should be empty at "__FILE__" line %d\n", __LINE__);
    nl = e.parentNode().toElement().elementsByTagName( "widget" );
    for ( i = 1; i < (int) nl.length(); i++ )
    { // start at 1, 0 is the toplevel widget
	n = nl.item(i).toElement();
	createAttrDecl( n );
    }
    objectNames.clear();
	
    ++indent;

    // additional attributes (from Designer)
    TTQStringList publicVars, protectedVars, privateVars;
    nl = e.parentNode().toElement().elementsByTagName( "variable" );
    for ( i = 0; i < (int)nl.length(); i++ ) {
        n = nl.item( i ).toElement();
        // Because of compatibility the next lines have to be commented out.
        // Someday it should be uncommented.
        //if ( n.parentNode().toElement().tagName() != "variables" )
        //    continue;
        TTQString access = n.attribute( "access", "protected" );
        TTQString var = n.firstChild().toText().data().stripWhiteSpace();
        if ( var.endsWith( ";" ) )
            var.truncate(var.length() - 1);
        if ( access == "public" )
            publicVars += var;
        else if ( access == "private" )
            privateVars += var;
        else
            protectedVars += var;
    }

    // Databases Connection holders

    registerDatabases( e );
    dbConnections = unique( dbConnections );
    for ( it = dbConnections.begin(); it != dbConnections.end(); ++it ) {
	if ( !(*it).isEmpty() && (*it) != "(default)") {
	    out << indent << (*it) << "Connection" << endl;
	}
    }

    --indent;

    // additional includes (local or global ) and forward declaractions
    nl = e.parentNode().toElement().elementsByTagName( "include" );
    for ( i = 0; i < (int) nl.length(); i++ ) {
	TTQDomElement n2 = nl.item(i).toElement();
	TTQString s = n2.firstChild().toText().data();
	if ( n2.attribute( "location" ) != "local" ) {
	    if ( s.right( 5 ) == ".ui.h" && !TTQFile::exists( s ) )
		continue;
	    if ( n2.attribute( "impldecl", "in implementation" ) != "in implementation" )
		continue;
	    globalIncludes += s;
	}
    }

    // do the local includes afterwards, since global includes have priority on clashes
    for ( i = 0; i < (int) nl.length(); i++ ) {
	TTQDomElement n2 = nl.item(i).toElement();
	TTQString s = n2.firstChild().toText().data();
	if ( n2.attribute( "location" ) == "local" &&!globalIncludes.contains( s ) ) {
	    if ( s.right( 5 ) == ".ui.h" && !TTQFile::exists( s ) )
		continue;
	    if ( n2.attribute( "impldecl", "in implementation" ) != "in implementation" )
		continue;
	    localIncludes += s;
	}
    }

    // additional custom widget headers
    nl = e.parentNode().toElement().elementsByTagName( "header" );
    for ( i = 0; i < (int) nl.length(); i++ ) {
	TTQDomElement n2 = nl.item(i).toElement();
	TTQString s = n2.firstChild().toText().data();
	if ( n2.attribute( "location" ) != "local" )
	    globalIncludes += s;
	else
	    localIncludes += s;
    }


    // grab slots/funcs defined in ui.h files
    for(TTQStringList::Iterator it = localIncludes.begin(); it != localIncludes.end(); ++it)
    {
        if((*it).right( 5 ) == ".ui.h")
        {
            TTQFile f((*it));
            if( f.open( IO_ReadOnly ) )
            {
                TTQRegExp re("^def\\s+([a-zA-Z0-9_]+)\\s.*$");
                TTQRegExp re2("^end\\s*$");
                TTQTextStream t( &f );
                TTQString s, s2, s3;
                while ( !t.eof() )
                {
                    s = t.readLine();
                    int pos = re.search(s);
                    if(pos == -1)
                        continue;
                    s2 = re.cap(1);
					s2 += "()";
//                    s2 = Parser::cleanArgs(s2);
                    s3 = "{";
                    while( !t.eof() )
                    {
                        s = t.readLine();
                         if(re2.search(s) != -1)
                            break;
                       s3 += s + "\n";
                    }
					s3 += "}";
                    functionImpls.insert( s2, s3 );
                    if( t.eof() ) break;
                }
                f.close();
             }
        }
    }

    // includes for child widgets
    for ( it = tags.begin(); it != tags.end(); ++it ) {
	nl = e.parentNode().toElement().elementsByTagName( *it );
	for ( i = 1; i < (int) nl.length(); i++ ) { // start at 1, 0 is the toplevel widget
	    TTQString name = getClassName( nl.item(i).toElement() );
	    if ( name == "Spacer" ) {
		globalIncludes += "tqlayout.h";
		globalIncludes += "tqapplication.h";
		continue;
	    }
	    if ( name.mid( 4 ) == "ListView" )
		globalIncludes += "tqheader.h";
	    if ( name != objClass ) {
		int wid = WidgetDatabase::idFromClassName( name.replace( TTQRegExp("^TQt::"), "Q" ) );
		TTQMap<TTQString, CustomInclude>::Iterator it = customWidgetIncludes.find( name );
		if ( it == customWidgetIncludes.end() )
		    globalIncludes += WidgetDatabase::includeFile( wid );
	    }
	}
    }

    dbConnections = unique( dbConnections );
    if ( dbConnections.count() )
	sqlClasses += "TQt::SqlDatabase";
    if ( dbCursors.count() )
	sqlClasses += "TQt::SqlCursor";
    bool dbForm = false;
    if ( dbForms[ "(default)" ].count() )
	dbForm = true;
    bool subDbForms = false;
    for ( it = dbConnections.begin(); it != dbConnections.end(); ++it ) {
	if ( !(*it).isEmpty()  && (*it) != "(default)" ) {
	    if ( dbForms[ (*it) ].count() ) {
		subDbForms = true;
		break;
	    }
	}
    }
    if ( dbForm || subDbForms ) {
	sqlClasses += "TQt::SqlForm";
	sqlClasses += "TQt::SqlRecord";
    }

    if (globalIncludes.findIndex("tqdatatable.h") >= 0)
        sqlClasses += "TQt::DataTable";

    if (globalIncludes.findIndex("qtableview.h") >= 0)
        sqlClasses += "TQt::TableView";

    if (globalIncludes.findIndex("tqdatabrowser.h") >= 0)
        sqlClasses += "TQt::DataBrowser";

    out << endl;

    // find out what images are retquired
    TTQStringList retquiredImages;
    static const char *imgTags[] = { "pixmap", "iconset", 0 };
    for ( i = 0; imgTags[i] != 0; i++ ) {
       nl = e.parentNode().toElement().elementsByTagName( imgTags[i] );
       for ( int j = 0; j < (int) nl.length(); j++ ) {
           TTQString img = "@";
           retquiredImages += (img + nl.item(j).firstChild().toText().data());
		}
    }

    // register the object and unify its name
	TTQString loadFunction(objName);
    objName = registerObject( objName );

    TTQStringList images;
    TTQStringList xpmImages;
    if ( pixmapLoaderFunction.isEmpty() && !externPixmaps )
    {
	// create images
	for ( n = e; !n.isNull(); n = n.nextSibling().toElement() )
        {
	    if ( n.tagName()  == "images" )
            {
		nl = n.elementsByTagName( "image" );
		for ( i = 0; i < (int) nl.length(); i++ )
                {
		    TTQString img = registerObject(  nl.item(i).toElement().attribute( "name" ) );
		    if ( !retquiredImages.contains( img ) )
			continue;
		    TTQDomElement tmp = nl.item(i).firstChild().toElement();
		    if ( tmp.tagName() != "data" )
			continue;
		    TTQString format = tmp.attribute("format", "PNG" );
		    TTQString data = tmp.firstChild().toText().data();
		    if ( format == "XPM.GZ" )
                    {
			xpmImages += img;
			ulong length = tmp.attribute("length").toULong();
			TTQByteArray baunzip = unzipXPM( data, length );
			// shouldn't we test the initial `length' against the
			// resulting `length' to catch corrupt UIC files?
			int a = 0;
            out << indent << imageDataName(img) << " =\n[";
 
			while ( baunzip[a] != '\"' )
			    a++;
			for ( ; a < (int) length; a++ )
			{
			    char ch;

			    if ((ch = baunzip[a]) == '}')
			    {
				out << "]\n" << endl;

				break;
			    }

			    out << ch;
			}
		    }
                    else
                    {
			images += img;
                        out << indent << imageDataName(img) << " = [ " << endl;
			++indent;
 			int a ;
			for ( a = 0; a < (int) (data.length()/2)-1; a++ ) {
			    out << "0x" << TTQString(data[2*a]) << TTQString(data[2*a+1]) << ",";
			    if ( a % 12 == 11 )
				out << endl << "    ";
			    else
				out << " ";
			}
			out << "0x" << TTQString(data[2*a]) << TTQString(data[2*a+1]) << " ].pack \"C*\"" << endl;
			--indent;
                        out << endl;
		    }
		}
	    }
	}
	out << endl;
    }
    else if ( externPixmaps )
    {
	/*
	out << indent << "def uic_load_pixmap_" << loadFunction << "( data )" << endl;
	++indent;
	out << indent << "pix = TQt::Pixmap.new()" << endl;
	out << indent << "m = TQt::MimeSourceFactory.defaultFactory().data(data)" << endl;
	out << endl;
	out << indent << "if ! m.nil?" << endl;
	++indent;
	out << indent << "TQt::ImageDrag.decode(m, pix)" << endl;
	--indent;
	out << indent << "end" << endl;
	out << endl;
	out << indent << "return pix" << endl;
	--indent;
	out << indent << "end" << endl;
	out << endl;
	out << endl;
	pixmapLoaderFunction = "uic_load_pixmap_" + loadFunction;
	*/
	pixmapLoaderFunction = "TQt::Pixmap.fromMimeSource";
    }


    // constructor(s)
    if ( objClass == "TQt::Dialog" || objClass == "TQt::Wizard" ) {
    out << indent << "def initialize(parent = nil, name = nil, modal = false, fl = 0)" << endl;
    ++indent;
	out << indent << "super" << endl;
    } else if ( objClass == "TQt::Widget")  {
    out << indent << "def initialize(parent = nil, name = nil, fl = 0)" << endl;
    ++indent;
	out << indent << "super" << endl;
    } else if ( objClass == "TQt::MainWindow" ) {
    out << indent << "def initialize(parent = nil, name = nil, fl = WType_TopLevel)" << endl;
    ++indent;
	out << indent << "super" << endl;
	isMainWindow = true;
    } else {
    out << indent << "def initialize(parent = nil, name = nil)" << endl;
    ++indent;
	out << indent << "super" << endl;
    }

    out << endl;

    // create pixmaps for all images
    if ( !images.isEmpty() ) {
	TTQStringList::Iterator it;
	for ( it = images.begin(); it != images.end(); ++it ) {
	    out << indent << (*it) << " = TQt::Pixmap.new()" << endl;
	    out << indent << (*it) << ".loadFromData(" << imageDataName(*it) << ", " << imageDataName(*it) << ".length, \"PNG\")" << endl;
	}
        out << endl;
    }
    // create pixmaps for all images
    if ( !xpmImages.isEmpty() ) {
	for ( it = xpmImages.begin(); it != xpmImages.end(); ++it ) {
	    out << indent << (*it) << " = TQt::Pixmap.new(" << imageDataName(*it) << ")" << endl;
	}
	out << endl;
    }

    if ( isMainWindow )
	out << indent << "statusBar()" << endl;

    // set the properties
   TTQSize geometry( 0, 0 );
    
	for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
	if ( n.tagName() == "property" ) {
	    bool stdset = stdsetdef;
	    if ( n.hasAttribute( "stdset" ) )
		stdset = toBool( n.attribute( "stdset" ) );
	    TTQString prop = n.attribute("name");
	    TTQDomElement n2 = n.firstChild().toElement();
	    TTQString value = setObjectProperty( objClass, TTQString::null, prop, n2, stdset );
	    if ( value.isEmpty() )
		continue;
		
	    if ( prop == "geometry" && n2.tagName() == "rect") {
		TTQDomElement n3 = n2.firstChild().toElement();
		while ( !n3.isNull() ) {
		    if ( n3.tagName() == "width" )
			geometry.setWidth( n3.firstChild().toText().data().toInt() );
		    else if ( n3.tagName() == "height" )
			geometry.setHeight( n3.firstChild().toText().data().toInt() );
		    n3 = n3.nextSibling().toElement();
		}
	    } else {
		TTQString call;
		if ( stdset ) {
		    call = mkStdSet( prop ) + "(" + value + ")";
		} else {
		    call = "setProperty(\"" + prop + "\", TQt::Variant.new(" + value + "))";
	    }

		if ( n2.tagName() == "string" ) {
		    trout << indent << call << endl;
		} else if ( prop == "name" ) {
		    out << indent << "if name.nil?" << endl;
		    out << indent << "\t" << call << endl;
		    out << indent << "end" << endl;
		} else {
		    out << indent << call << endl;
		}
	    }
	}
    }

    out << endl;

    // create all children, some forms have special retquirements

    if ( objClass == "TQt::Wizard" )
    {
	for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )
        {
	    if ( tags.contains( n.tagName()  ) )
            {
		TTQString page = createObjectImpl( n, objClass, "self" );
		TTQString comment;
		TTQString label = DomTool::readAttribute( n, "title", "", comment ).toString();
		out << indent << "addPage(" << page << ", "<< trcall( label ) << ")" << endl;
		trout << indent << "setTitle( " << page << ", " << trcall( label, comment ) << " )" << endl;
		TTQVariant def( false, 0 );
		if ( DomTool::hasAttribute( n, "backEnabled" ) )
		    out << indent << "setBackEnabled(" << page << "," << mkBool( DomTool::readAttribute( n, "backEnabled", def).toBool() ) << ");" << endl;
		if ( DomTool::hasAttribute( n, "nextEnabled" ) )
		    out << indent << "setNextEnabled(" << page << "," << mkBool( DomTool::readAttribute( n, "nextEnabled", def).toBool() ) << ");" << endl;
		if ( DomTool::hasAttribute( n, "finishEnabled" ) )
		    out << indent << "setFinishEnabled(" << page << "," << mkBool( DomTool::readAttribute( n, "finishEnabled", def).toBool() ) << ");" << endl;
		if ( DomTool::hasAttribute( n, "helpEnabled" ) )
		    out << indent << "setHelpEnabled(" << page << "," << mkBool( DomTool::readAttribute( n, "helpEnabled", def).toBool() ) << ");" << endl;
		if ( DomTool::hasAttribute( n, "finish" ) )
		    out << indent << "setFinish( " << page << "," << mkBool( DomTool::readAttribute( n, "finish", def).toBool() ) << ");" << endl;
	    }
	}
    }
    else
    { // standard widgets
	for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() )
        {
	    if ( tags.contains( n.tagName()  ) )
		createObjectImpl( n, objName, "self" );
	}
    }

    // database support
    dbConnections = unique( dbConnections );
    if ( dbConnections.count() )
	out << endl;
    for ( it = dbConnections.begin(); it != dbConnections.end(); ++it ) {
	if ( !(*it).isEmpty() && (*it) != "(default)") {
	    out << indent << (*it) << "Connection = TQt::SqlDatabase.database(\"" <<(*it) << "\");" << endl;
	}
    }

    nl = e.parentNode().toElement().elementsByTagName( "widget" );
    for ( i = 1; i < (int) nl.length(); i++ ) { // start at 1, 0 is the toplevel widget
	n = nl.item(i).toElement();
	TTQString s = getClassName( n );
	if ( s == "TQt::DataBrowser" || s == "TQt::DataView" ) {
	    TTQString objName = getObjectName( n );
	    TTQString tab = getDatabaseInfo( n, "table" );
	    TTQString con = getDatabaseInfo( n, "connection" );
	    out << indent << objName << "Form = TQt::SqlForm.new(self, \"" << objName << "Form\")" << endl;
	    TTQDomElement n2;
	    for ( n2 = n.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() )
		createFormImpl( n2, objName, con, tab );
	    out << indent << objName << ".setForm(" << objName << "Form)" << endl;
	}
    }

    // actions, toolbars, menubar
    bool needEndl = false;
    for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {
	if ( n.tagName()  == "actions" ) {
	    if ( !needEndl )
		out << endl;
	    createActionImpl( n.firstChild().toElement(), "self" );
	    needEndl = true;
	}
    }
    if ( needEndl )
	out << endl;
    needEndl = false;
    for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {
	if ( n.tagName() == "toolbars" ) {
	    if ( !needEndl )
		out << endl;
	    createToolbarImpl( n, objClass, objName );
	    needEndl = true;
	}
    }
    if ( needEndl )
	out << endl;
    needEndl = false;
    for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {
	if ( n.tagName() == "menubar" ) {
	    if ( !needEndl )
		out << endl;
	    createMenuBarImpl( n, objClass, objName );
	    needEndl = true;
	}
    }
    if ( needEndl )
	out << endl;

    out << indent << "languageChange()" << endl;
    
    // take minimumSizeHint() into account, for height-for-width widgets
    if ( !geometry.isNull() ) {
	out << indent << "resize( TQt::Size.new(" << geometry.width() << ", "
	    << geometry.height() << ").expandedTo(minimumSizeHint()) )" << endl;
	out << indent << "clearWState( WState_Polished )" << endl;
    }
	
	for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {
	if ( n.tagName()  == "connections" ) {
	    // setup signals and slots connections
	    out << endl;
	    nl = n.elementsByTagName( "connection" );
	    for ( i = 0; i < (int) nl.length(); i++ ) {
		TTQString sender, receiver, signal, slot;
		for ( TTQDomElement n2 = nl.item(i).firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) {
		    if ( n2.tagName() == "sender" )
			sender = n2.firstChild().toText().data();
		    else if ( n2.tagName() == "receiver" )
			receiver = n2.firstChild().toText().data();
		    else if ( n2.tagName() == "signal" )
			signal = n2.firstChild().toText().data();
		    else if ( n2.tagName() == "slot" )
			slot = n2.firstChild().toText().data();
		}
		if ( sender.isEmpty() || receiver.isEmpty() || signal.isEmpty() || slot.isEmpty() )
		    continue;
                else if ( sender[0] == '<' ||
                    receiver[0] == '<' ||
                    signal[0] == '<' ||
                    slot[0] == '<' )
                    continue;
		sender = registeredName( sender );
		receiver = registeredName( receiver );

		if ( sender == objName )
		    sender = "self";
		if ( receiver == objName )
		    receiver = "self";

		out << indent << "TQt::Object.connect(" << sender
		    << ", TQT_SIGNAL(\"" << signal << "\"), "<< receiver << ", TQT_SLOT(\"" << slot << "\") )" << endl;
	    }
	} else if ( n.tagName()  == "tabstops" ) {
	    // setup tab order
	    out << endl;
	    TTQString lastName;
	    TTQDomElement n2 = n.firstChild().toElement();
	    while ( !n2.isNull() ) {
		if ( n2.tagName() == "tabstop" ) {
		    TTQString name = n2.firstChild().toText().data();
		    name = registeredName( name );
		    if ( !lastName.isEmpty() )
			out << indent << "setTabOrder(" << lastName << ", " << name << ")" << endl;
		    lastName = name;
		}
		n2 = n2.nextSibling().toElement();
	    }
	}
    }

// QtRuby - FIXME: what the heck is this ?
    // buddies
    bool firstBuddy = true;
    for ( TTQValueList<Buddy>::Iterator buddy = buddies.begin(); buddy != buddies.end(); ++buddy ) {
	if ( isObjectRegistered( (*buddy).buddy ) ) {
	    if ( firstBuddy ) {
		out << endl;
	    }
	    out << indent << (*buddy).key << ".setBuddy(" << registeredName( (*buddy).buddy ) << ")" << endl;
	    firstBuddy = false;
	}

    }
    if ( extraSlots.find( "init()" ) != extraSlots.end() ||
         extraFunctions.find( "init()" ) != extraFunctions.end())
        out << endl << indent << "init()" << endl;

    // end of constructor
    --indent;
    out << indent << "end" << endl;
    out << endl;



    // handle application events if retquired
    bool needFontEventHandler = false;
    bool needSqlTableEventHandler = false;
    bool needSqlDataBrowserEventHandler = false;
    nl = e.elementsByTagName( "widget" );
    for ( i = 0; i < (int) nl.length(); i++ ) {
	if ( !DomTool::propertiesOfType( nl.item(i).toElement() , "font" ).isEmpty() )
	    needFontEventHandler = true;
	TTQString s = getClassName( nl.item(i).toElement() );
	if ( s == "TQt::DataTable" || s == "TQt::DataBrowser" ) {
	    if ( !isFrameworkCodeGenerated( nl.item(i).toElement() ) )
		 continue;
	    if ( s == "TQt::DataTable" )
		needSqlTableEventHandler = true;
	    if ( s == "TQt::DataBrowser" )
		needSqlDataBrowserEventHandler = true;
	}
	if ( needFontEventHandler && needSqlTableEventHandler && needSqlDataBrowserEventHandler )
	    break;
    }

// PerlQt - TODO: is this needed ?
// Seems not.. let's ifzero for now...

    if ( 0 && needFontEventHandler) {
	//	indent = "\t"; // increase indentation for if-clause below
	out << endl;
	out << "#  Main event handler. Reimplemented to handle" << endl;
	out << "#  application font changes" << endl;
	out << endl;
	out << "def event( ev )" << endl;
	out << "    ret = super( ev ) " << endl;
	if ( needFontEventHandler ) {
	    ++indent;
	    out << "    if ev.type() == TQt::Event::ApplicationFontChange " << endl;
	    for ( i = 0; i < (int) nl.length(); i++ ) {
		n = nl.item(i).toElement();
		TTQStringList list = DomTool::propertiesOfType( n, "font" );
		for ( it = list.begin(); it != list.end(); ++it )
		    createExclusiveProperty( n, *it );
	    }
	    out << "    end" << endl;
	    --indent;
	}
	out << "end" << endl;
	out << endl;
    }

    if ( needSqlTableEventHandler || needSqlDataBrowserEventHandler ) {
	out << endl;
	out << indent << "# Widget polish.  Reimplemented to handle default data" << endl;
	if ( needSqlTableEventHandler )
	    out << indent << "# table initialization." << endl;
	if ( needSqlDataBrowserEventHandler )
	    out << indent << "# browser initialization." << endl;
	out << indent << "def polish" << endl;
	++indent;
	if ( needSqlTableEventHandler ) {
	    for ( i = 0; i < (int) nl.length(); i++ ) {
		TTQString s = getClassName( nl.item(i).toElement() );
		if ( s == "TQt::DataTable" ) {
		    n = nl.item(i).toElement();
		    TTQString c = TTQString("@") + getObjectName( n );
		    TTQString conn = getDatabaseInfo( n, "connection" );
		    TTQString tab = getDatabaseInfo( n, "table" );
		    if ( !( conn.isEmpty() || tab.isEmpty() ) ) {
			out << indent << "if " << "!" << c << ".nil?" << endl;
			++indent;
			out << indent << "cursor = " << c << ".sqlCursor()" << endl;
			out << endl;
			out << indent << "if !cursor.nil?" << endl;
			++indent;
			if ( conn == "(default)" )
			    out << indent << "cursor = TQt::SqlCursor.new(\"" << tab << "\")" << endl;
			else
			    out << indent << "cursor = TQt::SqlCursor.new(\"" << tab << "\", true, " << conn << "Connection)" << endl;
			out << indent << "if " << c << ".readOnly? " << endl;
			++indent;
			out << indent << "cursor.mode = TQt::SqlCursor::ReadOnly" << endl;
			--indent;
			out << indent << "end " << endl;
			out << indent << c << ".setSqlCursor(cursor, false, true)" << endl;
			--indent;
			out << endl;
			out << indent << "end" << endl;
			out << indent << "if !cursor.active?" << endl;
			++indent;
			out << indent << c << ".refresh(TQt::DataTable::RefreshAll)" << endl;
			--indent;
			out << indent << "end" << endl;
			--indent;
			out << indent << "end" << endl;
		    }
		}
	    }
	}
	if ( needSqlDataBrowserEventHandler ) {
	    nl = e.elementsByTagName( "widget" );
	    for ( i = 0; i < (int) nl.length(); i++ ) {
		TTQString s = getClassName( nl.item(i).toElement() );
		if ( s == "TQt::DataBrowser" ) {
		    TTQString obj = getObjectName( nl.item(i).toElement() );
		    TTQString tab = getDatabaseInfo( nl.item(i).toElement(),
						   "table" );
		    TTQString conn = getDatabaseInfo( nl.item(i).toElement(),
						    "connection" );
		    if ( !(tab).isEmpty() ) {
			out << indent << "if " << obj << endl;
			++indent;
			out << indent << "if !" << obj << ".sqlCursor()" << endl;
			++indent;
			if ( conn == "(default)" )
			    out << indent << "cursor = TQt::SqlCursor.new(\"" << tab << "\")" << endl;
			else
			    out << indent << "cursor = TQt::SqlCursor.new(\"" << tab << "\", true, " << conn << "Connection)" << endl;
			out << indent << obj << ".setSqlCursor(cursor, true)" << endl;
			out << indent << obj << ".refresh()" << endl;
			out << indent << obj << ".first()" << endl;
			--indent;
			out << indent << "end" << endl;
			--indent;
			out << indent << "end" << endl;
		    }
		}
	    }
	}
	out << indent << "super()" << endl;
	--indent;
	out << indent << "end" << endl;
    }
	
    out << indent << "#" << endl;
    out << indent << "#  Sets the strings of the subwidgets using the current" << endl;
    out << indent << "#  language." << endl;
    out << indent << "#" << endl;
    out << indent << "def " << "languageChange()" << endl;
    out << languageChangeBody;
    out << indent << "end" << endl;
	out << indent << "protected :languageChange" << endl;
    out << endl;
    
	if ( !extraSlots.isEmpty() && writeSlotImpl ) {
	for ( it = extraSlots.begin(); it != extraSlots.end(); ++it ) {
	    out << endl;
	    int astart = (*it).find('(');
	    out << indent << "def " << (*it).left(astart) << "(*k)" << endl;
	    bool createWarning = true;
	    TTQString fname = Parser::cleanArgs( *it );
	    TTQMap<TTQString, TTQString>::Iterator fit = functionImpls.find( fname );
	    if ( fit != functionImpls.end() ) {
		int begin = (*fit).find( "{" );
		TTQString body = (*fit).mid( begin + 1, (*fit).findRev( "}" ) - begin - 1 );
		createWarning = body.simplifyWhiteSpace().isEmpty();
		if ( !createWarning )
		    out << body << endl;
	    }
	    if ( createWarning ) {
		++indent;
		if ( *it != "init()" && *it != "destroy()" )
		    out << indent << "print(\"" << nameOfClass << "." << (*it) << ": Not implemented yet.\\n\")" << endl;
		--indent;
	    }
	    out << indent << "end" << endl;

	}
    }

    if ( !extraFunctions.isEmpty() ) {
	for ( it = extraFunctions.begin(); it != extraFunctions.end(); ++it ) {
	    out << endl;
	    int astart = (*it).find('(');
	    out << indent << "def " << (*it).left(astart) << "(*k)" << endl;
	    TTQString fname = Parser::cleanArgs( *it );
	    TTQMap<TTQString, TTQString>::Iterator fit = functionImpls.find( fname );
	    if ( fit != functionImpls.end() ) {
		int begin = (*fit).find( "{" );
		TTQString body = (*fit).mid( begin + 1, (*fit).findRev( "}" ) - begin - 1 );
		body.simplifyWhiteSpace().isEmpty();
		out << body << endl;
	    }
	    out << indent << "end" << endl;

	}
    }


    out << endl;
    out << "end" << endl;
}


/*! Creates form support implementation code for the widgets given
  in \a e.

  Traverses recursively over all children.
 */

void Uic::createFormImpl( const TTQDomElement& e, const TTQString& form, const TTQString& connection, const TTQString& table )
{
    if ( e.tagName() == "widget" &&
	 e.attribute( "class" ) != "TQt::DataTable" ) {
	TTQString field = getDatabaseInfo( e, "field" );
	if ( !field.isEmpty() ) {
	    if ( isWidgetInTable( e, connection, table ) )
		out << indent << form << "Form.insert(" << getObjectName( e ) << ", " << fixString( field ) << ")" << endl;
	}
    }
    TTQDomElement n;
    for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
	createFormImpl( n, form, connection, table );
    }
}


// Generate a QtRuby signal/slot definition.

void Uic::rubySlot(TTQStringList::Iterator &it)
{
    out << indent << "'" << (*it) << "'";
}