diff options
Diffstat (limited to 'examples/declarative/dynamic/qml')
-rw-r--r-- | examples/declarative/dynamic/qml/Button.qml | 36 | ||||
-rw-r--r-- | examples/declarative/dynamic/qml/GenericItem.qml | 13 | ||||
-rw-r--r-- | examples/declarative/dynamic/qml/PaletteItem.qml | 16 | ||||
-rw-r--r-- | examples/declarative/dynamic/qml/PerspectiveItem.qml | 29 | ||||
-rw-r--r-- | examples/declarative/dynamic/qml/Sun.qml | 32 | ||||
-rw-r--r-- | examples/declarative/dynamic/qml/itemCreation.js | 65 |
6 files changed, 103 insertions, 88 deletions
diff --git a/examples/declarative/dynamic/qml/Button.qml b/examples/declarative/dynamic/qml/Button.qml index 53588bb..963a850 100644 --- a/examples/declarative/dynamic/qml/Button.qml +++ b/examples/declarative/dynamic/qml/Button.qml @@ -6,19 +6,35 @@ Rectangle { property variant text signal clicked - SystemPalette { id: activePalette } - height: text.height + 10 - width: text.width + 20 + height: text.height + 10; width: text.width + 20 border.width: 1 - radius: 4; smooth: true + radius: 4 + smooth: true + gradient: Gradient { - GradientStop { position: 0.0; - color: if(!mr.pressed){activePalette.light;}else{activePalette.button;} + GradientStop { + position: 0.0 + color: !mouseArea.pressed ? activePalette.light : activePalette.button } - GradientStop { position: 1.0; - color: if(!mr.pressed){activePalette.button;}else{activePalette.dark;} + GradientStop { + position: 1.0 + color: !mouseArea.pressed ? activePalette.button : activePalette.dark } } - MouseArea { id:mr; anchors.fill: parent; onClicked: container.clicked() } - Text { id: text; anchors.centerIn:parent; font.pointSize: 10; text: parent.text; color: activePalette.buttonText } + + SystemPalette { id: activePalette } + + MouseArea { + id: mouseArea + 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 deleted file mode 100644 index faac06d..0000000 --- a/examples/declarative/dynamic/qml/GenericItem.qml +++ /dev/null @@ -1,13 +0,0 @@ -import Qt 4.7 - -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 index e8f2ed4..dcb5cc3 100644 --- a/examples/declarative/dynamic/qml/PaletteItem.qml +++ b/examples/declarative/dynamic/qml/PaletteItem.qml @@ -1,13 +1,19 @@ import Qt 4.7 import "itemCreation.js" as Code -GenericItem { - id: itemButton - property string file +Image { + id: paletteItem + + property string componentFile + property string image + + source: image + MouseArea { - anchors.fill: parent; + anchors.fill: parent + onPressed: Code.startDrag(mouse); - onPositionChanged: Code.moveDrag(mouse); + onPositionChanged: Code.continueDrag(mouse); onReleased: Code.endDrag(mouse); } } diff --git a/examples/declarative/dynamic/qml/PerspectiveItem.qml b/examples/declarative/dynamic/qml/PerspectiveItem.qml index 3cbe64a..c04d3dc 100644 --- a/examples/declarative/dynamic/qml/PerspectiveItem.qml +++ b/examples/declarative/dynamic/qml/PerspectiveItem.qml @@ -1,16 +1,25 @@ import Qt 4.7 Image { - id: tree + id: rootItem + property bool created: false - property double scaleFactor: Math.max((y+height-250)*0.01, 0.3) - property double scaledBottom: y + (height+height*scaleFactor)/2 - property bool onLand: scaledBottom > window.height/2 - property string image //Needed for compatibility with GenericItem + property string image + + property double scaledBottom: y + (height + height*scale) / 2 + property bool onLand: scaledBottom > window.height / 2 + + source: image opacity: onLand ? 1 : 0.25 - onCreatedChanged: if (created && !onLand) { tree.destroy() } else { z = scaledBottom } - scale: scaleFactor - transformOrigin: "Center" - source: image; smooth: true - onYChanged: z = scaledBottom + scale: Math.max((y + height - 250) * 0.01, 0.3) + smooth: true + + onCreatedChanged: { + if (created && !onLand) + rootItem.destroy(); + else + z = scaledBottom; + } + + onYChanged: z = scaledBottom; } diff --git a/examples/declarative/dynamic/qml/Sun.qml b/examples/declarative/dynamic/qml/Sun.qml index 3627964..43dcb9a 100644 --- a/examples/declarative/dynamic/qml/Sun.qml +++ b/examples/declarative/dynamic/qml/Sun.qml @@ -2,23 +2,37 @@ import Qt 4.7 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 + source: image - //x and y get set when instantiated - //head offscreen + // once item is created, start moving offscreen NumberAnimation on y { - to: window.height / 2; + to: window.height / 2 running: created - onRunningChanged: if (running) duration = (window.height - sun.y) * 10; else state = "OffScreen"; + onRunningChanged: { + if (running) + duration = (window.height - sun.y) * 10; + else + state = "OffScreen" + } } states: State { - name: "OffScreen"; - StateChangeScript { script: { sun.created = false; sun.destroy() } } + name: "OffScreen" + StateChangeScript { + script: { sun.created = false; sun.destroy() } + } + } + + onCreatedChanged: { + if (created) { + sun.z = 1; // above the sky but below the ground layer + window.activeSuns++; + } else { + window.activeSuns--; + } } } diff --git a/examples/declarative/dynamic/qml/itemCreation.js b/examples/declarative/dynamic/qml/itemCreation.js index 98d48a8..59750f3 100644 --- a/examples/declarative/dynamic/qml/itemCreation.js +++ b/examples/declarative/dynamic/qml/itemCreation.js @@ -1,80 +1,63 @@ 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; - } -} +var posnInWindow; function startDrag(mouse) { - setSceneOffset(); + posnInWindow = paletteItem.mapToItem(null, 0, 0); startingMouse = { x: mouse.x, y: mouse.y } loadComponent(); } -//Creation is split into two functions due to an asyncronous wait while +//Creation is split into two functions due to an asynchronous wait while //possible external files are loaded. function loadComponent() { - if (itemComponent != null) //Already loaded the component + if (itemComponent != null) { // component has been previously loaded createItem(); + return; + } - itemComponent = Qt.createComponent(itemButton.file); - //console.log(itemButton.file) - if(itemComponent.isLoading){ - component.statusChanged.connect(finishCreation); - }else{//Depending on the content, it can be ready or error immediately + itemComponent = Qt.createComponent(paletteItem.componentFile); + if (itemComponent.status == Component.Loading) //Depending on the content, it can be ready or error immediately + component.statusChanged.connect(createItem); + else 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) { + if (itemComponent.status == Component.Ready && draggedItem == null) { + draggedItem = itemComponent.createObject(window); + draggedItem.image = paletteItem.image; + draggedItem.x = posnInWindow.x; + draggedItem.y = posnInWindow.y; + draggedItem.z = 3; // make sure created item is above the ground layer + } else if (itemComponent.status == Component.Error) { draggedItem = null; console.log("error creating component"); console.log(component.errorsString()); } } -function moveDrag(mouse) +function continueDrag(mouse) { - if(draggedItem == null) + if (draggedItem == null) return; - draggedItem.x = mouse.x + xOffset - startingMouse.x; - draggedItem.y = mouse.y + yOffset - startingMouse.y; + draggedItem.x = mouse.x + posnInWindow.x - startingMouse.x; + draggedItem.y = mouse.y + posnInWindow.y - startingMouse.y; } function endDrag(mouse) { - if(draggedItem == null) + if (draggedItem == null) return; - if(draggedItem.x + draggedItem.width > toolbox.x){ //Don't drop it in the toolbox + if (draggedItem.x + draggedItem.width > toolbox.x) { //Don't drop it in the toolbox draggedItem.destroy(); draggedItem = null; - }else{ - draggedItem.z = startingZ; + } else { draggedItem.created = true; draggedItem = null; } |