diff options
author | Oliver Eftevaag <[email protected]> | 2023-06-26 17:50:42 +0200 |
---|---|---|
committer | Shawn Rutledge <[email protected]> | 2023-07-04 06:54:09 +0200 |
commit | 38d6028ad167e4c1f473b4ec400292f68754a843 (patch) | |
tree | c91b8810b233542736fa6fbf0373fade37a8d928 | |
parent | d45f464b05a2ea3d32d23248cdd2a79bed835a0b (diff) |
Merge externaldraganddrop example into the draganddrop example
We have two examples that are both showcasing different drag and drop
features.
Might as well only have one.
Pick-to: 6.6
Change-Id: I9d984f723f42aaf39c5632e58fc376ad0df18acb
Reviewed-by: Shawn Rutledge <[email protected]>
19 files changed, 89 insertions, 216 deletions
diff --git a/examples/quick/CMakeLists.txt b/examples/quick/CMakeLists.txt index 1dd62acdd6..4453239cc8 100644 --- a/examples/quick/CMakeLists.txt +++ b/examples/quick/CMakeLists.txt @@ -4,7 +4,6 @@ qt_internal_add_example(quick-accessibility) qt_internal_add_example(animation) qt_internal_add_example(draganddrop) -qt_internal_add_example(externaldraganddrop) qt_internal_add_example(canvas) qt_internal_add_example(imageelements) qt_internal_add_example(keyinteraction) diff --git a/examples/quick/draganddrop/CMakeLists.txt b/examples/quick/draganddrop/CMakeLists.txt index b24eb4676f..b3d401734a 100644 --- a/examples/quick/draganddrop/CMakeLists.txt +++ b/examples/quick/draganddrop/CMakeLists.txt @@ -31,6 +31,7 @@ qt_add_qml_module(draganddropexample "tiles/tiles.qml" "views/Icon.qml" "views/gridview.qml" + "external/externaldraganddrop.qml" ) target_link_libraries(draganddropexample PRIVATE diff --git a/examples/quick/draganddrop/draganddrop.qml b/examples/quick/draganddrop/draganddrop.qml index 005cd878e2..9e1629e5d4 100644 --- a/examples/quick/draganddrop/draganddrop.qml +++ b/examples/quick/draganddrop/draganddrop.qml @@ -13,6 +13,7 @@ Item { Component.onCompleted: { addExample(qsTr("Tiles"), qsTr("Press and drag tiles to move them into the matching colored boxes"), Qt.resolvedUrl("tiles/tiles.qml")) addExample(qsTr("GridView"), qsTr("Press and drag to re-order items in the grid"), Qt.resolvedUrl("views/gridview.qml")) + addExample(qsTr("External"), qsTr("Drag and drop between this and other applications."), Qt.resolvedUrl("external/externaldraganddrop.qml")) } } } diff --git a/examples/quick/draganddrop/draganddrop.qrc b/examples/quick/draganddrop/draganddrop.qrc index a710562b79..1e6ae00d12 100644 --- a/examples/quick/draganddrop/draganddrop.qrc +++ b/examples/quick/draganddrop/draganddrop.qrc @@ -6,5 +6,6 @@ <file>tiles/tiles.qml</file> <file>views/gridview.qml</file> <file>views/Icon.qml</file> + <file>external/externaldraganddrop.qml</file> </qresource> </RCC> diff --git a/examples/quick/draganddrop/external/externaldraganddrop.qml b/examples/quick/draganddrop/external/externaldraganddrop.qml new file mode 100644 index 0000000000..8156a13f55 --- /dev/null +++ b/examples/quick/draganddrop/external/externaldraganddrop.qml @@ -0,0 +1,84 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +Control { + padding: 8 + contentItem: ColumnLayout { + component DragAndDropArea: Rectangle { + id: item + property string display: qsTr("Drag items to this area, or drag this item to a different drop area.") + property alias dropEnabled: acceptDropCB.checked + color: dropArea.containsDrag ? Qt.darker(palette.base) : palette.base + + ColorAnimation on color { + id: rejectAnimation + from: "#FCC" + to: palette.base + duration: 1000 + } + Label { + anchors.fill: parent + anchors.margins: 10 + text: item.display + wrapMode: Text.WordWrap + } + DropArea { + id: dropArea + anchors.fill: parent + keys: ["text/plain"] + onEntered: (drag) => { + if (!acceptDropCB.checked) { + drag.accepted = false + rejectAnimation.start() + } + } + onDropped: (drop) => { + if (drop.hasText && acceptDropCB.checked) { + if (drop.proposedAction === Qt.MoveAction || drop.proposedAction === Qt.CopyAction) { + item.display = drop.text + drop.acceptProposedAction() + } + } + } + } + MouseArea { + id: mouseArea + anchors.fill: parent + drag.target: draggable + } + Item { + id: draggable + anchors.fill: parent + Drag.active: mouseArea.drag.active + Drag.hotSpot.x: 0 + Drag.hotSpot.y: 0 + Drag.mimeData: { "text/plain": item.display } + Drag.dragType: Drag.Automatic + Drag.onDragFinished: (dropAction) => { + if (dropAction === Qt.MoveAction) + item.display = "" + } + } + CheckBox { + id: acceptDropCB + anchors.bottom: parent.bottom + checked: true + text: qsTr("accept drop") + } + } + + DragAndDropArea { + Layout.fillWidth: true + Layout.fillHeight: true + } + + DragAndDropArea { + Layout.fillWidth: true + Layout.fillHeight: true + } + } +} diff --git a/examples/quick/externaldraganddrop/CMakeLists.txt b/examples/quick/externaldraganddrop/CMakeLists.txt deleted file mode 100644 index 576e848356..0000000000 --- a/examples/quick/externaldraganddrop/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(externaldraganddrop LANGUAGES CXX) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quick/externaldraganddrop") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick) - -qt_standard_project_setup(REQUIRES 6.5) - -qt_add_executable(externaldraganddropexample - WIN32 - MACOSX_BUNDLE - main.cpp -) - -qt_add_qml_module(externaldraganddropexample - URI externaldraganddrop - QML_FILES - "DragAndDropTextItem.qml" - "externaldraganddrop.qml" -) - -target_link_libraries(externaldraganddropexample PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Qml - Qt6::Quick -) - -install(TARGETS externaldraganddropexample - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/quick/externaldraganddrop/DragAndDropTextItem.qml b/examples/quick/externaldraganddrop/DragAndDropTextItem.qml deleted file mode 100644 index 8a53745974..0000000000 --- a/examples/quick/externaldraganddrop/DragAndDropTextItem.qml +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick -import QtQuick.Controls - -Rectangle { - id: item - property string display - property alias dropEnabled: acceptDropCB.checked - color: dropArea.containsDrag ? Qt.darker(palette.base) : palette.base - - ColorAnimation on color { - id: rejectAnimation - from: "#FCC" - to: palette.base - duration: 1000 - } - Label { - anchors.fill: parent - anchors.margins: 10 - text: item.display - wrapMode: Text.WordWrap - } - DropArea { - id: dropArea - anchors.fill: parent - keys: ["text/plain"] - onEntered: (drag) => { - if (!acceptDropCB.checked) { - drag.accepted = false - rejectAnimation.start() - } - } - onDropped: (drop) => { - if (drop.hasText && acceptDropCB.checked) { - if (drop.proposedAction == Qt.MoveAction || drop.proposedAction == Qt.CopyAction) { - item.display = drop.text - drop.acceptProposedAction() - } - } - } - } - MouseArea { - id: mouseArea - anchors.fill: parent - drag.target: draggable - } - Item { - id: draggable - anchors.fill: parent - Drag.active: mouseArea.drag.active - Drag.hotSpot.x: 0 - Drag.hotSpot.y: 0 - Drag.mimeData: { "text/plain": item.display } - Drag.dragType: Drag.Automatic - Drag.onDragFinished: (dropAction) => { - if (dropAction == Qt.MoveAction) - item.display = "" - } - } - CheckBox { - id: acceptDropCB - anchors.bottom: parent.bottom - checked: true - text: "accept drop" - } -} diff --git a/examples/quick/externaldraganddrop/doc/images/qml-dnd2-example.png b/examples/quick/externaldraganddrop/doc/images/qml-dnd2-example.png Binary files differdeleted file mode 100644 index e657d81795..0000000000 --- a/examples/quick/externaldraganddrop/doc/images/qml-dnd2-example.png +++ /dev/null diff --git a/examples/quick/externaldraganddrop/doc/src/externaldraganddrop.qdoc b/examples/quick/externaldraganddrop/doc/src/externaldraganddrop.qdoc deleted file mode 100644 index 974c91a3cc..0000000000 --- a/examples/quick/externaldraganddrop/doc/src/externaldraganddrop.qdoc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only -/*! - \title Qt Quick Examples - externaldraganddrop - \example externaldraganddrop - \brief This is an example of drag-and-drop among QML applications. - \image qml-dnd2-example.png - \ingroup qtquickexamples - - \e externaldraganddrop demonstrates how to perform drag and - drop with \l MouseArea and \l DropArea. - - The example allows you to drag the text to other boxes, out of boxes into - other applications, and from other applications into the boxes. Use the - option or CTRL keys to copy rather than move text when dragging between - boxes. - - \include examples-run.qdocinc - -*/ diff --git a/examples/quick/externaldraganddrop/externaldraganddrop.pro b/examples/quick/externaldraganddrop/externaldraganddrop.pro deleted file mode 100644 index cd456f9b27..0000000000 --- a/examples/quick/externaldraganddrop/externaldraganddrop.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -QT += quick qml -SOURCES += main.cpp -RESOURCES += externaldraganddrop.qrc - -EXAMPLE_FILES = \ - externaldraganddrop.qml \ - DragAndDropTextItem.qml - -target.path = $$[QT_INSTALL_EXAMPLES]/quick/externaldraganddrop -INSTALLS += target diff --git a/examples/quick/externaldraganddrop/externaldraganddrop.qml b/examples/quick/externaldraganddrop/externaldraganddrop.qml deleted file mode 100644 index 22b3f52089..0000000000 --- a/examples/quick/externaldraganddrop/externaldraganddrop.qml +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick -import QtQuick.Controls -import QtQuick.Layouts - -Pane { - id: root - width: 320 - height: 480 - - ColumnLayout { - - anchors.fill: parent - anchors.margins: 8 - - Label { - Layout.fillWidth: true - text: "Drag text into, out of, and between the boxes below." - wrapMode: Text.WordWrap - } - - DragAndDropTextItem { - Layout.fillWidth: true - Layout.fillHeight: true - display: "Sample Text" - } - - DragAndDropTextItem { - Layout.fillWidth: true - Layout.fillHeight: true - display: "Option/ctrl drag to copy instead of move text." - } - - DragAndDropTextItem { - Layout.fillWidth: true - Layout.fillHeight: true - dropEnabled: false - display: "Drag out into other applications." - } - } -} diff --git a/examples/quick/externaldraganddrop/externaldraganddrop.qmlproject b/examples/quick/externaldraganddrop/externaldraganddrop.qmlproject deleted file mode 100644 index 359efae597..0000000000 --- a/examples/quick/externaldraganddrop/externaldraganddrop.qmlproject +++ /dev/null @@ -1,16 +0,0 @@ -import QmlProject 1.1 - -Project { - mainFile: "externaldraganddrop.qml" - - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } -} diff --git a/examples/quick/externaldraganddrop/externaldraganddrop.qrc b/examples/quick/externaldraganddrop/externaldraganddrop.qrc deleted file mode 100644 index 94f7e47e24..0000000000 --- a/examples/quick/externaldraganddrop/externaldraganddrop.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<RCC> - <qresource prefix="/qt/qml/externaldraganddrop"> - <file>externaldraganddrop.qml</file> - <file>DragAndDropTextItem.qml</file> - </qresource> -</RCC> diff --git a/examples/quick/externaldraganddrop/main.cpp b/examples/quick/externaldraganddrop/main.cpp deleted file mode 100644 index cd4831018c..0000000000 --- a/examples/quick/externaldraganddrop/main.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include "../shared/shared.h" -DECLARATIVE_EXAMPLE_MAIN(externaldraganddrop/externaldraganddrop) diff --git a/examples/quick/quick.pro b/examples/quick/quick.pro index 549cea9a5c..b20d92ddb4 100644 --- a/examples/quick/quick.pro +++ b/examples/quick/quick.pro @@ -2,7 +2,6 @@ TEMPLATE = subdirs SUBDIRS = quick-accessibility \ animation \ draganddrop \ - externaldraganddrop \ canvas \ imageelements \ keyinteraction \ diff --git a/src/quick/doc/src/examples.qdoc b/src/quick/doc/src/examples.qdoc index f4d61617c5..1cdb662b73 100644 --- a/src/quick/doc/src/examples.qdoc +++ b/src/quick/doc/src/examples.qdoc @@ -138,7 +138,6 @@ Creator. \b{System and Events} \list \li \l{Qt Quick Examples - Accessibility}{Accessibility} - \li \l{Qt Quick Examples - externaldraganddrop}{External Drag and Drop} \li \l{Qt Quick Examples - Drag and Drop}{Drag and Drop} \li \l{Qt Quick Examples - Item Variable Refresh Rate}{Item Variable Refresh Rate} \endlist diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp index 5fbfb82c6a..dee7616222 100644 --- a/src/quick/items/qquickdrag.cpp +++ b/src/quick/items/qquickdrag.cpp @@ -55,7 +55,7 @@ using namespace Qt::StringLiterals; \l {supportedActions}{drop action} chosen by the recipient of the event, otherwise it will return Qt.IgnoreAction. - \sa {Qt Quick Examples - Drag and Drop}, {Qt Quick Examples - externaldraganddrop} + \sa {Qt Quick Examples - Drag and Drop} */ void QQuickDragAttachedPrivate::itemGeometryChanged(QQuickItem *, QQuickGeometryChange change, diff --git a/src/quick/items/qquickdroparea.cpp b/src/quick/items/qquickdroparea.cpp index 76b6473df1..813ffa46b4 100644 --- a/src/quick/items/qquickdroparea.cpp +++ b/src/quick/items/qquickdroparea.cpp @@ -72,7 +72,7 @@ QQuickDropAreaPrivate::~QQuickDropAreaPrivate() The \l drag.source property is communicated to the source of a drag event as the recipient of a drop on the drag target. - \sa {Qt Quick Examples - Drag and Drop}, {Qt Quick Examples - externaldraganddrop} + \sa {Qt Quick Examples - Drag and Drop} */ QQuickDropArea::QQuickDropArea(QQuickItem *parent) diff --git a/tests/auto/guiapplauncher/examples.txt b/tests/auto/guiapplauncher/examples.txt index f4788f6aa5..88ff180a17 100644 --- a/tests/auto/guiapplauncher/examples.txt +++ b/tests/auto/guiapplauncher/examples.txt @@ -2,7 +2,6 @@ "quick/models/stringlistmodel Example", "examples/quick/models/stringlistmodel", "stringlistmodel", 0, -1 "quick/models/objectlistmodel Example", "examples/quick/models/objectlistmodel", "objectlistmodel", 0, -1 "quick/models/abstractitemmodel Example", "examples/quick/models/abstractitemmodel", "abstractitemmodel", 0, -1 -"quick/externaldraganddrop Example", "examples/quick/externaldraganddrop", "externaldraganddrop", 0, -1 "quick/customitems/maskedmousearea Example", "examples/quick/customitems/maskedmousearea", "maskedmousearea", 0, -1 "quick/imageelements Example", "examples/quick/imageelements", "imageelements", 0, -1 "quick/scenegraph/openglunderqml Example", "examples/quick/scenegraph/openglunderqml", "openglunderqml", 0, -1 |