diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2009-10-30 03:36:19 (GMT) |
---|---|---|
committer | Yann Bodson <yann.bodson@nokia.com> | 2009-10-30 03:36:19 (GMT) |
commit | f37e9d787bd418d8f75997a8d46c1c42e842c673 (patch) | |
tree | 8e11076675fa02740d5d5ca490b5dc09adc16bdf /examples/declarative/dynamic/qml | |
parent | 72932c6683729071c1acb3f4832c5dc53a561bdd (diff) | |
download | Qt-f37e9d787bd418d8f75997a8d46c1c42e842c673.zip Qt-f37e9d787bd418d8f75997a8d46c1c42e842c673.tar.gz Qt-f37e9d787bd418d8f75997a8d46c1c42e842c673.tar.bz2 |
cleanup
Diffstat (limited to 'examples/declarative/dynamic/qml')
-rw-r--r-- | examples/declarative/dynamic/qml/Button.qml | 24 | ||||
-rw-r--r-- | examples/declarative/dynamic/qml/GenericItem.qml | 13 | ||||
-rw-r--r-- | examples/declarative/dynamic/qml/PaletteItem.qml | 13 | ||||
-rw-r--r-- | examples/declarative/dynamic/qml/PerspectiveItem.qml | 12 | ||||
-rw-r--r-- | examples/declarative/dynamic/qml/Sun.qml | 24 | ||||
-rw-r--r-- | examples/declarative/dynamic/qml/itemCreation.js | 82 |
6 files changed, 168 insertions, 0 deletions
diff --git a/examples/declarative/dynamic/qml/Button.qml b/examples/declarative/dynamic/qml/Button.qml new file mode 100644 index 0000000..2769cd8 --- /dev/null +++ b/examples/declarative/dynamic/qml/Button.qml @@ -0,0 +1,24 @@ +import Qt 4.6 + +Rectangle { + id: container + + property var text + signal clicked + + SystemPalette { id: activePalette; colorGroup: Qt.Active } + height: text.height + 10 + width: text.width + 20 + border.width: 1 + radius: 4; smooth: true + gradient: Gradient { + GradientStop { position: 0.0; + color: if(!mr.pressed){activePalette.light;}else{activePalette.button;} + } + GradientStop { position: 1.0; + color: if(!mr.pressed){activePalette.button;}else{activePalette.dark;} + } + } + MouseRegion { id:mr; anchors.fill: parent; onClicked: container.clicked() } + Text { id: text; anchors.centerIn:parent; font.pointSize: 10; text: parent.text; color: activePalette.buttonText } +} diff --git a/examples/declarative/dynamic/qml/GenericItem.qml b/examples/declarative/dynamic/qml/GenericItem.qml new file mode 100644 index 0000000..10e3dba --- /dev/null +++ b/examples/declarative/dynamic/qml/GenericItem.qml @@ -0,0 +1,13 @@ +import Qt 4.6 + +Item{ + property bool created: false + property string image + width: imageItem.width + height: imageItem.height + z: 2 + Image{ + id: imageItem + source: image; + } +} diff --git a/examples/declarative/dynamic/qml/PaletteItem.qml b/examples/declarative/dynamic/qml/PaletteItem.qml new file mode 100644 index 0000000..bb6036d --- /dev/null +++ b/examples/declarative/dynamic/qml/PaletteItem.qml @@ -0,0 +1,13 @@ +import Qt 4.6 + +GenericItem { + id: itemButton + property string file + Script { source: "itemCreation.js" } + MouseRegion { + anchors.fill: parent; + onPressed: startDrag(mouse); + onPositionChanged: moveDrag(mouse); + onReleased: endDrag(mouse); + } +} diff --git a/examples/declarative/dynamic/qml/PerspectiveItem.qml b/examples/declarative/dynamic/qml/PerspectiveItem.qml new file mode 100644 index 0000000..9e09dd2 --- /dev/null +++ b/examples/declarative/dynamic/qml/PerspectiveItem.qml @@ -0,0 +1,12 @@ +import Qt 4.6 + +Image { + id: tree + property bool created: false + opacity: y+height > window.height/2 ? 1 : 0.25 + onCreatedChanged: if (created && y+height<=window.height/2) { tree.destroy() } + scale: y+height > window.height/2 ? (y+height-250)*0.01 : 1 + transformOrigin: "Center" + source: image; + z: y +} diff --git a/examples/declarative/dynamic/qml/Sun.qml b/examples/declarative/dynamic/qml/Sun.qml new file mode 100644 index 0000000..796a370 --- /dev/null +++ b/examples/declarative/dynamic/qml/Sun.qml @@ -0,0 +1,24 @@ +import Qt 4.6 + +Image { + id: sun + property bool created: false + property string image: "../images/sun.png" + onCreatedChanged: if(created){window.activeSuns++;}else{window.activeSuns--;} + + source: image; + z: 1 + + //x and y get set when instantiated + //head offscreen + y: NumberAnimation { + to: parent.height; + duration: 10000; + running: created + } + + states: State { + name: "OffScreen"; when: created && y > window.height / 2;//Below the ground + StateChangeScript { script: { sun.created = false; sun.destroy() } } + } +} diff --git a/examples/declarative/dynamic/qml/itemCreation.js b/examples/declarative/dynamic/qml/itemCreation.js new file mode 100644 index 0000000..b3e8ba5 --- /dev/null +++ b/examples/declarative/dynamic/qml/itemCreation.js @@ -0,0 +1,82 @@ +var itemComponent = null; +var draggedItem = null; +var startingMouse; +var startingZ; +//Until QT-2385 is resolved we need to convert to scene coordinates manually +var xOffset; +var yOffset; +function setSceneOffset() +{ + xOffset = 0; + yOffset = 0; + var p = itemButton; + while(p != window){ + xOffset += p.x; + yOffset += p.y; + p = p.parent; + } +} + +function startDrag(mouse) +{ + setSceneOffset(); + startingMouse = { x: mouse.x, y: mouse.y } + loadComponent(); +} + +//Creation is split into two functions due to an asyncronous wait while +//possible external files are loaded. + +function loadComponent() { + if (itemComponent != null) //Already loaded the component + createItem(); + + itemComponent = createComponent(itemButton.file); + print(itemButton.file) + if(itemComponent.isLoading){ + component.statusChanged.connect(finishCreation); + }else{//Depending on the content, it can be ready or error immediately + createItem(); + } +} + +function createItem() { + if (itemComponent.isReady && draggedItem == null) { + draggedItem = itemComponent.createObject(); + draggedItem.parent = window; + draggedItem.image = itemButton.image; + draggedItem.x = xOffset; + draggedItem.y = yOffset; + startingZ = draggedItem.z; + draggedItem.z = 4;//On top + } else if (itemComponent.isError) { + draggedItem = null; + print("error creating component"); + print(component.errorsString()); + } +} + +function moveDrag(mouse) +{ + if(draggedItem == null) + return; + + draggedItem.x = mouse.x + xOffset - startingMouse.x; + draggedItem.y = mouse.y + yOffset - startingMouse.y; +} + +function endDrag(mouse) +{ + if(draggedItem == null) + return; + + if(draggedItem.x + draggedItem.width > toolbox.x){ //Don't drop it in the toolbox + draggedItem.destroy(); + draggedItem = null; + }else{ + draggedItem.z = startingZ; + draggedItem.created = true; + draggedItem = null; + } +} + |