summaryrefslogtreecommitdiffstats
path: root/examples/declarative/dynamic/qml/itemCreation.js
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2010-05-07 09:15:32 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2010-05-07 09:15:32 (GMT)
commit695ddc4a13233c8e6f626fa205336f90f8c5a565 (patch)
tree88da8a1d80219e5788db3f4e138d1d281bb3d816 /examples/declarative/dynamic/qml/itemCreation.js
parent1824eb63f6b2f8baa26b20c57fc50db84eefaa30 (diff)
parent67bf465253db71c0eddbc6ffcb811dd65c00b207 (diff)
downloadQt-695ddc4a13233c8e6f626fa205336f90f8c5a565.zip
Qt-695ddc4a13233c8e6f626fa205336f90f8c5a565.tar.gz
Qt-695ddc4a13233c8e6f626fa205336f90f8c5a565.tar.bz2
Merge branch '4.7' of git@scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Conflicts: examples/declarative/dynamic/qml/itemCreation.js
Diffstat (limited to 'examples/declarative/dynamic/qml/itemCreation.js')
-rw-r--r--examples/declarative/dynamic/qml/itemCreation.js58
1 files changed, 21 insertions, 37 deletions
diff --git a/examples/declarative/dynamic/qml/itemCreation.js b/examples/declarative/dynamic/qml/itemCreation.js
index 08f5320..59750f3 100644
--- a/examples/declarative/dynamic/qml/itemCreation.js
+++ b/examples/declarative/dynamic/qml/itemCreation.js
@@ -1,53 +1,38 @@
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.status == Component.Loading){
- 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.status == Component.Ready && draggedItem == null) {
draggedItem = itemComponent.createObject(window);
- draggedItem.image = itemButton.image;
- draggedItem.x = xOffset;
- draggedItem.y = yOffset;
- startingZ = draggedItem.z;
- draggedItem.z = 4;//On top
+ 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");
@@ -55,25 +40,24 @@ function createItem() {
}
}
-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;
}