diff options
author | Bea Lam <bea.lam@nokia.com> | 2009-10-08 05:08:40 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2009-10-08 05:08:40 (GMT) |
commit | f149107f3281fd537c98aaac5cba5934d55aa78a (patch) | |
tree | 57bd2008434dbaeb857b29e4ec3f1c99c45139d3 /examples/declarative/dynamic | |
parent | e79cf93c8b724c8eac042e68ba8dee0b9f2feee3 (diff) | |
download | Qt-f149107f3281fd537c98aaac5cba5934d55aa78a.zip Qt-f149107f3281fd537c98aaac5cba5934d55aa78a.tar.gz Qt-f149107f3281fd537c98aaac5cba5934d55aa78a.tar.bz2 |
Clean up
Diffstat (limited to 'examples/declarative/dynamic')
-rw-r--r-- | examples/declarative/dynamic/dynamic.js | 26 | ||||
-rw-r--r-- | examples/declarative/dynamic/dynamic.qml | 66 |
2 files changed, 68 insertions, 24 deletions
diff --git a/examples/declarative/dynamic/dynamic.js b/examples/declarative/dynamic/dynamic.js index 8f1e138..8bfdba3 100644 --- a/examples/declarative/dynamic/dynamic.js +++ b/examples/declarative/dynamic/dynamic.js @@ -2,54 +2,56 @@ var dynamicObject = null; var fourthBox = null; var component = null; var started = false; + function createQml(p) { - return createQmlObject('DynRect {}',p,'DynPart.qml'); + return createQmlObject('DynRect {}', p, 'DynPart.qml'); } function destroyDynamicObject() { - if(!(dynamicObject==null)){ + if (!(dynamicObject == null)) { dynamicObject.destroy(); dynamicObject = null; } } function instantCreateWithComponent() {//Like create, but assumes instant readyness - if(dynamicObject!=null)//Already made + if (dynamicObject != null)//Already made return null; component = createComponent("dynamic.qml"); dynamicObject = component.createObject(); - if(dynamicObject == null){ + + if (dynamicObject == null) { print("error creating component"); - }else{ + } else { dynamicObject.parent = targetItem; return dynamicObject; } return null; } -function finishCreation(){ - if(component.isReady && dynamicObject == null){ +function finishCreation() { + if (component.isReady && dynamicObject == null) { dynamicObject = component.createObject(); dynamicObject.parent = targetItem; - }else if(component.isError){ + } else if (component.isError) { dynamicObject = null; print("error creating component"); print(component.errorsString()); } } -function createWithComponent(){ - if(component!=null){ +function createWithComponent() { + if (component != null) { return finishCreation(); } - if(started!=false){ + if (started != false) { finishCreation();//Remakes if destroyed return dynamicObject; } started = true; component = createComponent("dynamic.qml"); finishCreation(); - if(dynamicObject != null){ + if (dynamicObject != null) { return dynamicObject; } component.statusChanged.connect(finishCreation); diff --git a/examples/declarative/dynamic/dynamic.qml b/examples/declarative/dynamic/dynamic.qml index 6ea7ab8..66fdf87 100644 --- a/examples/declarative/dynamic/dynamic.qml +++ b/examples/declarative/dynamic/dynamic.qml @@ -1,22 +1,55 @@ import Qt 4.6 -Rectangle { id: page; width: 800; height: 800; color:"black" +Rectangle { + id: page + width: 800 + height: 800 + color: "black" Script { source: "dynamic.js" } - property bool extendStars: false; + + property bool extendStars: false + Item { id: targetItem; x: 100; y: 100; } Item { id: targetItem2; x: 0; y: 300; } - Rectangle { width: 100; height: 100; color: "green"; id: rect - MouseRegion { anchors.fill:parent; onClicked: {a = createWithComponent();}} + + Rectangle { + id: rect + width: 100 + height: 100 + color: "green" + + MouseRegion { + anchors.fill: parent + onClicked: { a = createWithComponent(); } + } } - Rectangle { width: 100; height: 100; color: "red"; id: rect2; y:100; - MouseRegion { anchors.fill:parent; onClicked: {destroyDynamicObject();}} + + Rectangle { + id: rect2 + width: 100 + height: 100 + y: 100 + color: "red" + + MouseRegion { + anchors.fill:parent + onClicked: { destroyDynamicObject(); } + } } - Rectangle { width: 100; height: 100; color: "blue"; id: rect3; y:200; - MouseRegion { anchors.fill:parent; onClicked: - { - if(fourthBox == null) { + + Rectangle { + id: rect3 + width: 100 + height: 100 + y: 200 + color: "blue" + + MouseRegion { + anchors.fill: parent + onClicked: { + if (fourthBox == null) { a = createQml(targetItem2); - if(a!=null) { + if (a != null) { a.parent = targetItem2;//BUG: this should happen automatically fourthBox = a; print(a.toStr()); @@ -31,5 +64,14 @@ Rectangle { id: page; width: 800; height: 800; color:"black" } } } - Particles { x:0; y:0; count:20; lifeSpan:500; width:100; height: if(extendStars){400;}else{300;} source:"star.png"} + + Particles { + x: 0 + y: 0 + count: 20 + lifeSpan: 500 + width: 100 + height: if (extendStars) { 400; } else { 300; } + source: "star.png" + } } |