From c825865cdd88445aa1db94cdf0da89426919acdb Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Mon, 12 Sep 2011 14:17:08 +1000 Subject: Add DropArea item and Drag attached property. Refactors drag API to improve compatibility with traditional drag and drop by reusing events and adding drop actions. Event sending is removed from MouseArea, instead the Drag object can be attached to the item that is dragged and it will send drag events when the position of that item is changed or when its active property changes. The DragTarget item is renamed to DropArea and can now communicate supported and suggested actions. Task-number: QTBUG-19747 Change-Id: I46cb77e68cf1ff32bbcbf0945facb593c9c2243c Reviewed-on: http://codereview.qt-project.org/4638 Sanity-Review: Qt Sanity Bot Reviewed-by: Martin Jones --- .../declarative/draganddrop/dragtarget.qmlproject | 16 ++ .../declarative/draganddrop/tiles/DragTile.qml | 89 +++++++ .../declarative/draganddrop/tiles/DropTile.qml | 68 +++++ examples/declarative/draganddrop/tiles/tiles.qml | 109 ++++++++ .../declarative/draganddrop/views/gridview.qml | 117 ++++++++ .../declarative/dragtarget/dragtarget.qmlproject | 16 -- .../declarative/dragtarget/lists/listmodel.qml | 296 --------------------- .../declarative/dragtarget/lists/lists.qmlproject | 16 -- examples/declarative/dragtarget/text/dragtext.qml | 182 ------------- .../declarative/dragtarget/text/text.qmlproject | 16 -- examples/declarative/dragtarget/tiles/DragTile.qml | 99 ------- examples/declarative/dragtarget/tiles/DropTile.qml | 70 ----- examples/declarative/dragtarget/tiles/tiles.qml | 125 --------- .../modelviews/visualdatamodel/dragselection.qml | 4 +- 14 files changed, 402 insertions(+), 821 deletions(-) create mode 100644 examples/declarative/draganddrop/dragtarget.qmlproject create mode 100644 examples/declarative/draganddrop/tiles/DragTile.qml create mode 100644 examples/declarative/draganddrop/tiles/DropTile.qml create mode 100644 examples/declarative/draganddrop/tiles/tiles.qml create mode 100644 examples/declarative/draganddrop/views/gridview.qml delete mode 100644 examples/declarative/dragtarget/dragtarget.qmlproject delete mode 100644 examples/declarative/dragtarget/lists/listmodel.qml delete mode 100644 examples/declarative/dragtarget/lists/lists.qmlproject delete mode 100644 examples/declarative/dragtarget/text/dragtext.qml delete mode 100644 examples/declarative/dragtarget/text/text.qmlproject delete mode 100644 examples/declarative/dragtarget/tiles/DragTile.qml delete mode 100644 examples/declarative/dragtarget/tiles/DropTile.qml delete mode 100644 examples/declarative/dragtarget/tiles/tiles.qml (limited to 'examples') diff --git a/examples/declarative/draganddrop/dragtarget.qmlproject b/examples/declarative/draganddrop/dragtarget.qmlproject new file mode 100644 index 0000000000..d4909f8685 --- /dev/null +++ b/examples/declarative/draganddrop/dragtarget.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.0 + +Project { + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } + /* List of plugin directories passed to QML runtime */ + // importPaths: [ " ../exampleplugin " ] +} diff --git a/examples/declarative/draganddrop/tiles/DragTile.qml b/examples/declarative/draganddrop/tiles/DragTile.qml new file mode 100644 index 0000000000..d7bc920735 --- /dev/null +++ b/examples/declarative/draganddrop/tiles/DragTile.qml @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: root + property string colorKey + + width: 100; height: 100 + + MouseArea { + id: mouseArea + + width: 100; height: 100 + anchors.centerIn: parent + + drag.target: tile + + onReleased: parent = tile.Drag.target !== null ? tile.Drag.target : root + + Rectangle { + id: tile + + width: 100; height: 100 + + anchors.horizontalCenter: parent.horizontalCenter; anchors.verticalCenter: parent.verticalCenter + color: colorKey + + Drag.keys: [ colorKey ] + Drag.active: mouseArea.drag.active + Drag.hotSpot.x: 50 + Drag.hotSpot.y: 50 + + Text { + anchors.fill: parent + color: "white" + font.pixelSize: 90 + text: modelData + 1 + horizontalAlignment:Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + states: State { + when: mouseArea.drag.active + ParentChange { target: tile; parent: root } + AnchorChanges { target: tile; anchors.verticalCenter: undefined; anchors.horizontalCenter: undefined } + } + } + } +} + diff --git a/examples/declarative/draganddrop/tiles/DropTile.qml b/examples/declarative/draganddrop/tiles/DropTile.qml new file mode 100644 index 0000000000..492706439a --- /dev/null +++ b/examples/declarative/draganddrop/tiles/DropTile.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +DropArea { + id: dragTarget + + property string colorKey + property alias dropProxy: dragTarget + + width: 100; height: 100 + keys: [ colorKey ] + + Rectangle { + id: dropRectangle + + anchors.fill: parent + color: colorKey + + states: [ + State { + when: dragTarget.containsDrag + PropertyChanges { + target: dropRectangle + color: "grey" + } + } + ] + } +} diff --git a/examples/declarative/draganddrop/tiles/tiles.qml b/examples/declarative/draganddrop/tiles/tiles.qml new file mode 100644 index 0000000000..17dcd3b547 --- /dev/null +++ b/examples/declarative/draganddrop/tiles/tiles.qml @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: root + + width: 620 + height: 410 + + color: "black" + + Grid { + id: redDestination + + anchors.left: redSource.right; anchors.top: parent.top; + anchors.margins: 5 + width: 300 + height: 300 + opacity: 0.5 + columns: 3 + + Repeater { + model: 9; + delegate: DropTile { colorKey: "red" } + } + } + + Grid { + anchors.right: blueSource.left; anchors.bottom: parent.bottom; + anchors.margins: 5 + width: 300 + height: 300 + + opacity: 0.5 + + columns: 3 + + Repeater { + model: 9 + delegate: DropTile { colorKey: "blue" } + } + } + + Column { + id: redSource + + anchors.left: parent.left; anchors.top: parent.top; anchors.bottom: parent.bottom + anchors.margins: 5 + width: 100 + spacing: -60 + + Repeater { + model: 9 + delegate: DragTile { colorKey: "red" } + } + } + Column { + id: blueSource + + anchors.right: parent.right; anchors.top: parent.top; anchors.bottom: parent.bottom + anchors.margins: 5 + width: 100 + spacing: -60 + + Repeater { + model: 9 + delegate: DragTile { colorKey: "blue" } + } + } +} diff --git a/examples/declarative/draganddrop/views/gridview.qml b/examples/declarative/draganddrop/views/gridview.qml new file mode 100644 index 0000000000..f16a79c9dc --- /dev/null +++ b/examples/declarative/draganddrop/views/gridview.qml @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +GridView { + id: root + width: 360; height: 360 + cellWidth: 90; cellHeight: 90 + + model: VisualDataModel { + id: visualModel + model: ListModel { + id: colorModel + ListElement { color: "blue" } + ListElement { color: "green" } + ListElement { color: "red" } + ListElement { color: "yellow" } + ListElement { color: "orange" } + ListElement { color: "purple" } + ListElement { color: "cyan" } + ListElement { color: "magenta" } + ListElement { color: "chartreuse" } + ListElement { color: "aquamarine" } + ListElement { color: "indigo" } + ListElement { color: "black" } + ListElement { color: "chartreuse" } + ListElement { color: "violet" } + ListElement { color: "grey" } + ListElement { color: "springgreen" } + } + + delegate: MouseArea { + id: delegateRoot + + property int visualIndex: VisualDataModel.itemsIndex + + width: 90; height: 90 + drag.target: icon + + Rectangle { + id: icon + width: 80; height: 80 + anchors { + horizontalCenter: parent.horizontalCenter; + verticalCenter: parent.verticalCenter + } + color: model.color + radius: 3 + + Drag.active: delegateRoot.pressed + Drag.source: delegateRoot + Drag.hotSpot.x: 40 + Drag.hotSpot.y: 40 + + states: [ + State { + when: icon.Drag.active + ParentChange { + target: icon + parent: root + } + + AnchorChanges { + target: icon; + anchors.horizontalCenter: undefined; + anchors.verticalCenter: undefined + } + } + ] + } + + DropArea { + anchors { fill: parent; margins: 15 } + + onEntered: visualModel.items.move(drag.source.visualIndex, delegateRoot.visualIndex) + } + } + } +} diff --git a/examples/declarative/dragtarget/dragtarget.qmlproject b/examples/declarative/dragtarget/dragtarget.qmlproject deleted file mode 100644 index d4909f8685..0000000000 --- a/examples/declarative/dragtarget/dragtarget.qmlproject +++ /dev/null @@ -1,16 +0,0 @@ -import QmlProject 1.0 - -Project { - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } - /* List of plugin directories passed to QML runtime */ - // importPaths: [ " ../exampleplugin " ] -} diff --git a/examples/declarative/dragtarget/lists/listmodel.qml b/examples/declarative/dragtarget/lists/listmodel.qml deleted file mode 100644 index f153087e7b..0000000000 --- a/examples/declarative/dragtarget/lists/listmodel.qml +++ /dev/null @@ -1,296 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - - -Rectangle { - id: root - color: "grey" - - width: 720 - height: 380 - - Component { - id: draggedText - Text { - x: rootTarget.dragX - 10 - y: rootTarget.dragY - 10 - width: 20 - height: 20 - - text: rootTarget.dragData.display - font.pixelSize: 18 - } - } - - DragTarget { - id: rootTarget - - anchors.fill: parent - } - - Loader { - anchors.fill: parent - sourceComponent: rootTarget.containsDrag ? draggedText : undefined - } - - GridView { - id: gridView - - width: 240 - height: 360 - - anchors.left: parent.left - anchors.verticalCenter: parent.verticalCenter - anchors.margins: 10 - - cellWidth: 60 - cellHeight: 60 - - model: ListModel { - id: gridModel - - ListElement { display: "1" } - ListElement { display: "2" } - ListElement { display: "3" } - ListElement { display: "4" } - ListElement { display: "5" } - ListElement { display: "6" } - ListElement { display: "7" } - ListElement { display: "8" } - ListElement { display: "9" } - ListElement { display: "10" } - ListElement { display: "11" } - ListElement { display: "12" } - ListElement { display: "13" } - ListElement { display: "14" } - ListElement { display: "15" } - ListElement { display: "16" } - ListElement { display: "17" } - ListElement { display: "18" } - ListElement { display: "19" } - ListElement { display: "20" } - ListElement { display: "21" } - ListElement { display: "22" } - ListElement { display: "23" } - ListElement { display: "24" } - } - - delegate: Rectangle { - id: root - - width: 60 - height: 60 - - color: "black" - - Text { - anchors.fill: parent - color: draggable.drag.active ? "gold" : "white" - text: display - font.pixelSize: 16 - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter - } - - MouseArea { - id: draggable - - property int initialIndex - - width: 60 - height: 60 - - drag.data: model - drag.keys: ["grid"] - drag.target: draggable - - states: State { - when: !draggable.drag.active - PropertyChanges { target: draggable; x: 0; y: 0 } - } - } - } - - DragTarget { - anchors.fill: parent - - keys: [ "grid" ] - onPositionChanged: { - var index = gridView.indexAt(drag.x, drag.y) - if (index != -1) - gridModel.move(drag.data.index, index, 1) - } - } - - DragTarget { - property int dragIndex - anchors.fill: parent - - keys: [ "list" ] - onEntered: { - dragIndex = gridView.indexAt(drag.x, drag.y) - if (dragIndex != -1) { - gridModel.insert(dragIndex, { "display": drag.data.display }) - } else { - event.accepted = false - } - } - onPositionChanged: { - var index = gridView.indexAt(drag.x, drag.y); - if (index != -1) { - gridModel.move(dragIndex, index, 1) - dragIndex = index - } - } - onExited: gridModel.remove(dragIndex, 1) - } - } - - ListView { - id: listView - - width: 240 - height: 360 - - anchors.right: parent.right - anchors.verticalCenter: parent.verticalCenter - anchors.margins: 10 - - model: ListModel { - id: listModel - - ListElement { display: "a" } - ListElement { display: "b" } - ListElement { display: "c" } - ListElement { display: "d"} - ListElement { display: "e" } - ListElement { display: "f" } - ListElement { display: "g" } - ListElement { display: "h" } - ListElement { display: "i" } - ListElement { display: "j" } - ListElement { display: "k" } - ListElement { display: "l" } - ListElement { display: "m" } - ListElement { display: "n" } - ListElement { display: "o" } - ListElement { display: "p" } - ListElement { display: "q" } - ListElement { display: "r" } - ListElement { display: "s" } - ListElement { display: "t" } - ListElement { display: "u" } - ListElement { display: "v" } - ListElement { display: "w" } - ListElement { display: "x" } - } - - delegate: Rectangle { - id: root - - width: 240 - height: 15 - - color: "black" - - Text { - anchors.fill: parent - color: draggable.drag.active ? "gold" : "white" - text: display - font.pixelSize: 12 - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter - } - - MouseArea { - id: draggable - - width: 240 - height: 15 - - drag.data: model - drag.keys: ["list"] - drag.target: draggable - - states: State { - when: !draggable.drag.active - PropertyChanges { target: draggable; x: 0; y: 0 } - } - } - } - - DragTarget { - anchors.fill: parent - - keys: [ "list" ] - onPositionChanged: { - var index = listView.indexAt(drag.x, drag.y) - if (index != -1) - listModel.move(drag.data.index, index, 1) - } - } - - DragTarget { - property int dragIndex - anchors.fill: parent - - keys: [ "grid" ] - - onEntered: { - dragIndex = listView.indexAt(drag.x, drag.y) - if (dragIndex != -1) { - listModel.insert(dragIndex, { "display": drag.data.display }) - } else { - event.accepted = false - } - } - onPositionChanged: { - var index = listView.indexAt(drag.x, drag.y); - if (index != -1) { - listModel.move(dragIndex, index, 1) - dragIndex = index - } - } - onExited: listModel.remove(dragIndex, 1) - } - } -} diff --git a/examples/declarative/dragtarget/lists/lists.qmlproject b/examples/declarative/dragtarget/lists/lists.qmlproject deleted file mode 100644 index d4909f8685..0000000000 --- a/examples/declarative/dragtarget/lists/lists.qmlproject +++ /dev/null @@ -1,16 +0,0 @@ -import QmlProject 1.0 - -Project { - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } - /* List of plugin directories passed to QML runtime */ - // importPaths: [ " ../exampleplugin " ] -} diff --git a/examples/declarative/dragtarget/text/dragtext.qml b/examples/declarative/dragtarget/text/dragtext.qml deleted file mode 100644 index 49858d1fc4..0000000000 --- a/examples/declarative/dragtarget/text/dragtext.qml +++ /dev/null @@ -1,182 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Item { - id: root - width: 320; height: 480 - - Rectangle { - id: inputRect - anchors.left: parent.left; anchors.right: parent.right; anchors.top: parent.top - anchors.margins: 2 - height: input.implicitHeight + 4 - - border.width: 1 - - TextInput { - id: input - anchors.fill: parent; anchors.margins: 2 - - text: "the quick brown fox jumped over the lazy dog" - - DragTarget { - id: inputTarget - - anchors.fill: parent - - Component { - id: draggedInputText - Text { - x: inputTarget.dragX - y: inputTarget.dragY - text: inputTarget.dragData - color: "blue" - font: input.font - } - } - - Loader { - sourceComponent: parent.containsDrag ? draggedInputText : undefined - } - } - - - MouseArea { - id: inputDraggable - - anchors.fill: parent - enabled: input.selectionStart != input.selectionEnd - - drag.data: input.selectedText - drag.target: inputDraggable - - drag.onDragged: { - var position = input.positionAt(mouse.x); - mouse.accepted = position >= input.selectionStart && position < input.selectionEnd - } - - MouseArea { - anchors.fill: parent - - onPressed: { - var position = input.positionAt(mouse.x); - if (position < input.selectionStart || position >= input.selectionEnd) { - input.cursorPosition = position - } else { - mouse.accepted = false - } - } - onPositionChanged: input.moveCursorSelection(input.positionAt(mouse.x)) - } - } - } - } - - Rectangle { - id: editRect - anchors.left: parent.left; anchors.right: parent.right; - anchors.top: inputRect.bottom; anchors.bottom: parent.bottom - anchors.margins: 2 - - border.width: 1 - - TextEdit { - id: edit - anchors.fill: parent; anchors.margins: 2 - - text: "the quick brown fox jumped over the lazy dog" - font.pixelSize: 18 - wrapMode: TextEdit.WordWrap - - DragTarget { - id: editTarget - - anchors.fill: parent - - - Component { - id: draggedEditText - Text { - x: editTarget.dragX - y: editTarget.dragY - text: editTarget.dragData - color: "red" - font: edit.font - } - } - - Loader { - sourceComponent: parent.containsDrag ? draggedEditText : undefined - } - } - - MouseArea { - id: editDraggable - - anchors.fill: parent - enabled: edit.selectionStart != edit.selectionEnd - - drag.data: edit.selectedText - drag.target: editDraggable - - drag.onDragged: { - var position = edit.positionAt(mouse.x, mouse.y); - mouse.accepted = position >= edit.selectionStart && position < edit.selectionEnd - } - - MouseArea { - anchors.fill: parent - - onPressed: { - var position = edit.positionAt(mouse.x, mouse.y); - if (position < edit.selectionStart || position >= edit.selectionEnd) { - edit.cursorPosition = position - } else { - mouse.accepted = false - } - } - onPositionChanged: edit.moveCursorSelection(edit.positionAt(mouse.x, mouse.y)) - } - } - } - } -} diff --git a/examples/declarative/dragtarget/text/text.qmlproject b/examples/declarative/dragtarget/text/text.qmlproject deleted file mode 100644 index d4909f8685..0000000000 --- a/examples/declarative/dragtarget/text/text.qmlproject +++ /dev/null @@ -1,16 +0,0 @@ -import QmlProject 1.0 - -Project { - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } - /* List of plugin directories passed to QML runtime */ - // importPaths: [ " ../exampleplugin " ] -} diff --git a/examples/declarative/dragtarget/tiles/DragTile.qml b/examples/declarative/dragtarget/tiles/DragTile.qml deleted file mode 100644 index f1bd79314a..0000000000 --- a/examples/declarative/dragtarget/tiles/DragTile.qml +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Rectangle { - id: dragRectangle - - property Item dropTarget - - property string colorKey - - color: colorKey - - width: 100; height: 100 - - Text { - anchors.fill: parent - color: "white" - font.pixelSize: 90 - text: modelData + 1 - horizontalAlignment:Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - } - - MouseArea { - id: draggable - - anchors.fill: parent - - drag.target: parent - drag.keys: [ colorKey ] - - drag.onDropped: dropTarget = dropItem - - states: [ - State { - when: dragRectangle.dropTarget != undefined && !draggable.drag.active - ParentChange { - target: dragRectangle - parent: dropTarget - x: 0 - y: 0 - } - }, - State { - when: dragRectangle.dropTarget != undefined && draggable.drag.active - ParentChange { - target: dragRectangle - parent: dropTarget - } - }, - State { - when: !draggable.drag.active - AnchorChanges { - target: dragRectangle - anchors.horizontalCenter: parent.horizontalCenter - } - } - ] - } -} diff --git a/examples/declarative/dragtarget/tiles/DropTile.qml b/examples/declarative/dragtarget/tiles/DropTile.qml deleted file mode 100644 index 80aa81f671..0000000000 --- a/examples/declarative/dragtarget/tiles/DropTile.qml +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Rectangle { - id: dropRectangle - - property string colorKey - - color: colorKey - - width: 100; height: 100 - - DragTarget { - id: dragTarget - - anchors.fill: parent - - keys: [ colorKey ] - dropItem: dropRectangle - } - - states: [ - State { - when: dragTarget.containsDrag - PropertyChanges { - target: dropRectangle - color: "grey" - } - } - ] -} diff --git a/examples/declarative/dragtarget/tiles/tiles.qml b/examples/declarative/dragtarget/tiles/tiles.qml deleted file mode 100644 index 1f783e3322..0000000000 --- a/examples/declarative/dragtarget/tiles/tiles.qml +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Rectangle { - id: root - - width: 620 - height: 410 - - color: "black" - - DragTarget { - id: resetTarget - - anchors.fill: parent - } - - Grid { - id: redDestination - - anchors.left: redSource.right; anchors.top: parent.top; - anchors.margins: 5 - width: 300 - height: 300 - - opacity: 0.5 - - columns: 3 - - Repeater { - model: 9 - delegate: DropTile { - colorKey: "red" - } - } - } - - Grid { - id: blueDestination - - anchors.right: blueSource.left; anchors.bottom: parent.bottom; - anchors.margins: 5 - width: 300 - height: 300 - - opacity: 0.5 - - columns: 3 - - Repeater { - model: 9 - delegate: DropTile { - colorKey: "blue" - } - } - } - - Column { - id: redSource - - anchors.left: parent.left; anchors.top: parent.top; anchors.bottom: parent.bottom - anchors.margins: 5 - width: 100 - - Repeater { - model: 9 - delegate: DragTile { - colorKey: "red" - } - } - } - Column { - id: blueSource - - anchors.right: parent.right; anchors.top: parent.top; anchors.bottom: parent.bottom - anchors.margins: 5 - width: 100 - - Repeater { - model: 9 - delegate: DragTile { - colorKey: "blue" - } - } - } -} diff --git a/examples/declarative/modelviews/visualdatamodel/dragselection.qml b/examples/declarative/modelviews/visualdatamodel/dragselection.qml index d4412f9719..afbea1ff94 100644 --- a/examples/declarative/modelviews/visualdatamodel/dragselection.qml +++ b/examples/declarative/modelviews/visualdatamodel/dragselection.qml @@ -69,6 +69,8 @@ Item { width: 64 height: 64 + Drag.active: visibleContainer.drag.active + anchors { horizontalCenter: parent.horizontalCenter; verticalCenter: parent.verticalCenter } states: State { @@ -79,7 +81,7 @@ Item { ParentChange { target: draggable; parent: root } } } - DragTarget { + DropArea { anchors.fill: parent onEntered: visualModel.items.move(selectedItems, 0, packageRoot.VisualDataModel.itemsIndex, selectedItems.count) } -- cgit v1.2.3