summaryrefslogtreecommitdiffstats
path: root/kjsembed/docs/examples/kjsuic/kjsuic.js
blob: fcea8bb0eeb85227f7070ac00e29e52fa58f490c (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
/*
* To use this fuction provide the ui file name, the parent
* that will handle the slots of the form, and the parent
* widget that will handle the UI portion.
*
* var form = kjsuic("EnvelopeMakerUI.ui", this, this);
* println(dump(form));
*
* This will then return you a widget object that has properties
* that are the main child widgets in the UI file.  So if you have
* a KLineEdit called "myLineEdit" in the UI file then there would
* be a member of the form called myLineEdit.  (ex: form.myLineEdit )
*
* If there are container widgets present then the children will show
* up as properties of those widgets.  So if you have a groupbox called
* "Group" and a KLineEdit inside of it called "editor" you would address
* this as "Group.editor".
*
* An important note:   Take care when using UI files with this that have
* widget names that do not conflict with current Qt properties as the Qt
* properties will take precident over the added widgets.
*/

function kjsuic(uifile, slotParent, parent)
{
        var widget = Factory.loadui(uifile, slotParent, parent);
        var lst = widget.children();
        addChildren( widget )
        return widget;
}

function addChildren( widget )
{
	var lst = widget.children();
        for( var idx = 0; idx < lst.length; ++idx)
        {
                var str = "widget." + lst[idx] + " = widget.child('" + lst[idx] + "');";
                eval(str);
		var typeName = widget.child(lst[idx]).className();

		if( typeName == "TQGroupBox" || typeName == "TQButtonGroup" || typeName == "TQFrame")
		{
			eval("addChildren( widget." + lst[idx] + ");");
		}
        }
}