From d5bb8ab9e5f68954168caa067ae8568362f4ff1e Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 31 Aug 2021 16:46:32 +0200 Subject: Fix dynamicscene example to use a QML module Change-Id: I23b87b8ca98721cebc0dc948f0c9bbf741af6cd5 Reviewed-by: Shawn Rutledge (cherry picked from commit be260ba5290f8e51519abb5430b85a142b408258) Reviewed-by: Qt Cherry-pick Bot --- examples/qml/dynamicscene/CMakeLists.txt | 68 +++++++---------- examples/qml/dynamicscene/GenericSceneItem.qml | 59 +++++++++++++++ examples/qml/dynamicscene/PaletteItem.qml | 69 +++++++++++++++++ examples/qml/dynamicscene/PerspectiveItem.qml | 74 ++++++++++++++++++ examples/qml/dynamicscene/Sun.qml | 83 +++++++++++++++++++++ .../qml/dynamicscene/content/GenericSceneItem.qml | 59 --------------- examples/qml/dynamicscene/content/PaletteItem.qml | 69 ----------------- .../qml/dynamicscene/content/PerspectiveItem.qml | 74 ------------------ examples/qml/dynamicscene/content/Sun.qml | 83 --------------------- examples/qml/dynamicscene/content/images/NOTE | 1 - .../qml/dynamicscene/content/images/face-smile.png | Bin 15408 -> 0 bytes examples/qml/dynamicscene/content/images/moon.png | Bin 1757 -> 0 bytes .../dynamicscene/content/images/rabbit_brown.png | Bin 1245 -> 0 bytes .../qml/dynamicscene/content/images/rabbit_bw.png | Bin 1759 -> 0 bytes examples/qml/dynamicscene/content/images/star.png | Bin 259 -> 0 bytes examples/qml/dynamicscene/content/images/sun.png | Bin 8110 -> 0 bytes .../qml/dynamicscene/content/images/tree_s.png | Bin 3406 -> 0 bytes examples/qml/dynamicscene/content/itemCreation.js | 62 --------------- examples/qml/dynamicscene/dynamicscene.qml | 15 ++-- examples/qml/dynamicscene/dynamicscene.qrc | 28 +++---- examples/qml/dynamicscene/images/NOTE | 1 + examples/qml/dynamicscene/images/face-smile.png | Bin 0 -> 15408 bytes examples/qml/dynamicscene/images/moon.png | Bin 0 -> 1757 bytes examples/qml/dynamicscene/images/rabbit_brown.png | Bin 0 -> 1245 bytes examples/qml/dynamicscene/images/rabbit_bw.png | Bin 0 -> 1759 bytes examples/qml/dynamicscene/images/star.png | Bin 0 -> 259 bytes examples/qml/dynamicscene/images/sun.png | Bin 0 -> 8110 bytes examples/qml/dynamicscene/images/tree_s.png | Bin 0 -> 3406 bytes examples/qml/dynamicscene/itemCreation.js | 62 +++++++++++++++ examples/qml/dynamicscene/main.cpp | 2 +- 30 files changed, 395 insertions(+), 414 deletions(-) create mode 100644 examples/qml/dynamicscene/GenericSceneItem.qml create mode 100644 examples/qml/dynamicscene/PaletteItem.qml create mode 100644 examples/qml/dynamicscene/PerspectiveItem.qml create mode 100644 examples/qml/dynamicscene/Sun.qml delete mode 100644 examples/qml/dynamicscene/content/GenericSceneItem.qml delete mode 100644 examples/qml/dynamicscene/content/PaletteItem.qml delete mode 100644 examples/qml/dynamicscene/content/PerspectiveItem.qml delete mode 100644 examples/qml/dynamicscene/content/Sun.qml delete mode 100644 examples/qml/dynamicscene/content/images/NOTE delete mode 100644 examples/qml/dynamicscene/content/images/face-smile.png delete mode 100644 examples/qml/dynamicscene/content/images/moon.png delete mode 100644 examples/qml/dynamicscene/content/images/rabbit_brown.png delete mode 100644 examples/qml/dynamicscene/content/images/rabbit_bw.png delete mode 100644 examples/qml/dynamicscene/content/images/star.png delete mode 100644 examples/qml/dynamicscene/content/images/sun.png delete mode 100644 examples/qml/dynamicscene/content/images/tree_s.png delete mode 100644 examples/qml/dynamicscene/content/itemCreation.js create mode 100644 examples/qml/dynamicscene/images/NOTE create mode 100644 examples/qml/dynamicscene/images/face-smile.png create mode 100644 examples/qml/dynamicscene/images/moon.png create mode 100644 examples/qml/dynamicscene/images/rabbit_brown.png create mode 100644 examples/qml/dynamicscene/images/rabbit_bw.png create mode 100644 examples/qml/dynamicscene/images/star.png create mode 100644 examples/qml/dynamicscene/images/sun.png create mode 100644 examples/qml/dynamicscene/images/tree_s.png create mode 100644 examples/qml/dynamicscene/itemCreation.js (limited to 'examples') diff --git a/examples/qml/dynamicscene/CMakeLists.txt b/examples/qml/dynamicscene/CMakeLists.txt index 9353c35427..623ab1f78b 100644 --- a/examples/qml/dynamicscene/CMakeLists.txt +++ b/examples/qml/dynamicscene/CMakeLists.txt @@ -1,13 +1,8 @@ -# Generated from dynamicscene.pro. - -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(dynamicscene LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) - set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") @@ -15,52 +10,39 @@ endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/dynamicscene") -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Quick) -find_package(Qt6 COMPONENTS Qml) +find_package(Qt6 COMPONENTS Core Gui Quick Qml) -qt_add_executable(dynamicscene - main.cpp -) -set_target_properties(dynamicscene PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(dynamicscene PUBLIC +qt_add_executable(dynamicsceneexample WIN32 MACOSX_BUNDLE main.cpp) + +target_link_libraries(dynamicsceneexample PUBLIC Qt::Core Qt::Gui Qt::Qml Qt::Quick ) - -# Resources: -set(dynamicscene_resource_files - "content/GenericSceneItem.qml" - "content/PaletteItem.qml" - "content/PerspectiveItem.qml" - "content/Sun.qml" - "content/images/NOTE" - "content/images/face-smile.png" - "content/images/moon.png" - "content/images/rabbit_brown.png" - "content/images/rabbit_bw.png" - "content/images/star.png" - "content/images/sun.png" - "content/images/tree_s.png" - "content/itemCreation.js" - "dynamicscene.qml" -) - -qt6_add_resources(dynamicscene "dynamicscene" - PREFIX - "/" - FILES - ${dynamicscene_resource_files} +qt_add_qml_module(dynamicsceneexample + URI dynamicscene + VERSION 1.0 + QML_FILES + "GenericSceneItem.qml" + "PaletteItem.qml" + "PerspectiveItem.qml" + "Sun.qml" + "dynamicscene.qml" + "itemCreation.js" + RESOURCES + "images/NOTE" + "images/face-smile.png" + "images/moon.png" + "images/rabbit_brown.png" + "images/rabbit_bw.png" + "images/star.png" + "images/sun.png" + "images/tree_s.png" ) -install(TARGETS dynamicscene +install(TARGETS dynamicsceneexample RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/qml/dynamicscene/GenericSceneItem.qml b/examples/qml/dynamicscene/GenericSceneItem.qml new file mode 100644 index 0000000000..bc09fd5817 --- /dev/null +++ b/examples/qml/dynamicscene/GenericSceneItem.qml @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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 + +Image { + property bool created: false + property string image + + source: image + +} diff --git a/examples/qml/dynamicscene/PaletteItem.qml b/examples/qml/dynamicscene/PaletteItem.qml new file mode 100644 index 0000000000..d6df4be870 --- /dev/null +++ b/examples/qml/dynamicscene/PaletteItem.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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 +import "itemCreation.js" as Code + +Image { + id: paletteItem + + property string componentFile + property string image + + source: image + + MouseArea { + anchors.fill: parent + + onPressed: (mouse)=> Code.startDrag(mouse); + onPositionChanged: (mouse)=> Code.continueDrag(mouse); + onReleased: (mouse)=> Code.endDrag(mouse); + } +} diff --git a/examples/qml/dynamicscene/PerspectiveItem.qml b/examples/qml/dynamicscene/PerspectiveItem.qml new file mode 100644 index 0000000000..d02a188043 --- /dev/null +++ b/examples/qml/dynamicscene/PerspectiveItem.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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 + +Image { + id: rootItem + + property bool created: false + property string image + + property double scaledBottom: y + (height + height*scale) / 2 + property bool onLand: scaledBottom > (window.height / 2 + window.centerOffset) + + source: image + opacity: onLand ? 1 : 0.25 + scale: Math.max((y + height - 250) * 0.01, 0.3) + + onCreatedChanged: { + if (created && !onLand) + rootItem.destroy(); + else + z = scaledBottom; + } + + onYChanged: z = scaledBottom; +} diff --git a/examples/qml/dynamicscene/Sun.qml b/examples/qml/dynamicscene/Sun.qml new file mode 100644 index 0000000000..062a6065e0 --- /dev/null +++ b/examples/qml/dynamicscene/Sun.qml @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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 + +Image { + id: sun + + property bool created: false + property string image: "images/sun.png" + + source: image + onCreatedChanged: { + if (created) { + sun.z = 1; // above the sky but below the ground layer + window.activeSuns++; + // once item is created, start moving offscreen + dropYAnim.duration = (window.height + window.centerOffset - sun.y) * 16; + dropAnim.running = true; + } else { + window.activeSuns--; + } + } + + SequentialAnimation on y{ + id: dropAnim + running: false + NumberAnimation { + id: dropYAnim + to: (window.height / 2) + window.centerOffset + } + ScriptAction { + script: { sun.created = false; sun.destroy() } + } + } +} diff --git a/examples/qml/dynamicscene/content/GenericSceneItem.qml b/examples/qml/dynamicscene/content/GenericSceneItem.qml deleted file mode 100644 index bc09fd5817..0000000000 --- a/examples/qml/dynamicscene/content/GenericSceneItem.qml +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 - -Image { - property bool created: false - property string image - - source: image - -} diff --git a/examples/qml/dynamicscene/content/PaletteItem.qml b/examples/qml/dynamicscene/content/PaletteItem.qml deleted file mode 100644 index d6df4be870..0000000000 --- a/examples/qml/dynamicscene/content/PaletteItem.qml +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 -import "itemCreation.js" as Code - -Image { - id: paletteItem - - property string componentFile - property string image - - source: image - - MouseArea { - anchors.fill: parent - - onPressed: (mouse)=> Code.startDrag(mouse); - onPositionChanged: (mouse)=> Code.continueDrag(mouse); - onReleased: (mouse)=> Code.endDrag(mouse); - } -} diff --git a/examples/qml/dynamicscene/content/PerspectiveItem.qml b/examples/qml/dynamicscene/content/PerspectiveItem.qml deleted file mode 100644 index d02a188043..0000000000 --- a/examples/qml/dynamicscene/content/PerspectiveItem.qml +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 - -Image { - id: rootItem - - property bool created: false - property string image - - property double scaledBottom: y + (height + height*scale) / 2 - property bool onLand: scaledBottom > (window.height / 2 + window.centerOffset) - - source: image - opacity: onLand ? 1 : 0.25 - scale: Math.max((y + height - 250) * 0.01, 0.3) - - onCreatedChanged: { - if (created && !onLand) - rootItem.destroy(); - else - z = scaledBottom; - } - - onYChanged: z = scaledBottom; -} diff --git a/examples/qml/dynamicscene/content/Sun.qml b/examples/qml/dynamicscene/content/Sun.qml deleted file mode 100644 index 062a6065e0..0000000000 --- a/examples/qml/dynamicscene/content/Sun.qml +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 The Qt Company Ltd 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 - -Image { - id: sun - - property bool created: false - property string image: "images/sun.png" - - source: image - onCreatedChanged: { - if (created) { - sun.z = 1; // above the sky but below the ground layer - window.activeSuns++; - // once item is created, start moving offscreen - dropYAnim.duration = (window.height + window.centerOffset - sun.y) * 16; - dropAnim.running = true; - } else { - window.activeSuns--; - } - } - - SequentialAnimation on y{ - id: dropAnim - running: false - NumberAnimation { - id: dropYAnim - to: (window.height / 2) + window.centerOffset - } - ScriptAction { - script: { sun.created = false; sun.destroy() } - } - } -} diff --git a/examples/qml/dynamicscene/content/images/NOTE b/examples/qml/dynamicscene/content/images/NOTE deleted file mode 100644 index fcd87f9132..0000000000 --- a/examples/qml/dynamicscene/content/images/NOTE +++ /dev/null @@ -1 +0,0 @@ -Images (except star.png) are from the KDE project. diff --git a/examples/qml/dynamicscene/content/images/face-smile.png b/examples/qml/dynamicscene/content/images/face-smile.png deleted file mode 100644 index 3d66d72578..0000000000 Binary files a/examples/qml/dynamicscene/content/images/face-smile.png and /dev/null differ diff --git a/examples/qml/dynamicscene/content/images/moon.png b/examples/qml/dynamicscene/content/images/moon.png deleted file mode 100644 index 1c0d6066a8..0000000000 Binary files a/examples/qml/dynamicscene/content/images/moon.png and /dev/null differ diff --git a/examples/qml/dynamicscene/content/images/rabbit_brown.png b/examples/qml/dynamicscene/content/images/rabbit_brown.png deleted file mode 100644 index ebfdeed332..0000000000 Binary files a/examples/qml/dynamicscene/content/images/rabbit_brown.png and /dev/null differ diff --git a/examples/qml/dynamicscene/content/images/rabbit_bw.png b/examples/qml/dynamicscene/content/images/rabbit_bw.png deleted file mode 100644 index 7bff9b92ca..0000000000 Binary files a/examples/qml/dynamicscene/content/images/rabbit_bw.png and /dev/null differ diff --git a/examples/qml/dynamicscene/content/images/star.png b/examples/qml/dynamicscene/content/images/star.png deleted file mode 100644 index bdcd36909d..0000000000 Binary files a/examples/qml/dynamicscene/content/images/star.png and /dev/null differ diff --git a/examples/qml/dynamicscene/content/images/sun.png b/examples/qml/dynamicscene/content/images/sun.png deleted file mode 100644 index c5fd36ed39..0000000000 Binary files a/examples/qml/dynamicscene/content/images/sun.png and /dev/null differ diff --git a/examples/qml/dynamicscene/content/images/tree_s.png b/examples/qml/dynamicscene/content/images/tree_s.png deleted file mode 100644 index 6eac35a729..0000000000 Binary files a/examples/qml/dynamicscene/content/images/tree_s.png and /dev/null differ diff --git a/examples/qml/dynamicscene/content/itemCreation.js b/examples/qml/dynamicscene/content/itemCreation.js deleted file mode 100644 index 2829a83410..0000000000 --- a/examples/qml/dynamicscene/content/itemCreation.js +++ /dev/null @@ -1,62 +0,0 @@ -var itemComponent = null; -var draggedItem = null; -var startingMouse; -var posnInWindow; - -function startDrag(mouse) -{ - posnInWindow = paletteItem.mapToItem(window, 0, 0); - startingMouse = { x: mouse.x, y: mouse.y } - loadComponent(); -} - -//Creation is split into two functions due to an asynchronous wait while -//possible external files are loaded. - -function loadComponent() { - if (itemComponent != null) { // component has been previously loaded - createItem(); - return; - } - - 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, {"image": paletteItem.image, "x": posnInWindow.x, "y": posnInWindow.y, "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(itemComponent.errorString()); - } -} - -function continueDrag(mouse) -{ - if (draggedItem == null) - return; - - draggedItem.x = mouse.x + posnInWindow.x - startingMouse.x; - draggedItem.y = mouse.y + posnInWindow.y - startingMouse.y; -} - -function endDrag(mouse) -{ - if (draggedItem == null) - return; - - if (draggedItem.y < toolbox.height) { //Don't drop it in the toolbox - draggedItem.destroy(); - draggedItem = null; - } else { - draggedItem.created = true; - draggedItem = null; - } -} - diff --git a/examples/qml/dynamicscene/dynamicscene.qml b/examples/qml/dynamicscene/dynamicscene.qml index 43b4784b13..0775d7593e 100644 --- a/examples/qml/dynamicscene/dynamicscene.qml +++ b/examples/qml/dynamicscene/dynamicscene.qml @@ -51,7 +51,6 @@ import QtQuick import QtQuick.Particles import QtQuick.Controls -import "content" Item { id: window @@ -120,7 +119,7 @@ Item { ImageParticle { id: stars - source: "content/images/star.png" + source: "images/star.png" groups: ["stars"] opacity: .5 } @@ -171,31 +170,31 @@ Item { PaletteItem { anchors.verticalCenter: parent.verticalCenter componentFile: "Sun.qml" - source: "content/images/sun.png" + source: "images/sun.png" image: "images/sun.png" } PaletteItem { anchors.verticalCenter: parent.verticalCenter componentFile: "GenericSceneItem.qml" - source: "content/images/moon.png" + source: "images/moon.png" image: "images/moon.png" } PaletteItem { anchors.verticalCenter: parent.verticalCenter componentFile: "PerspectiveItem.qml" - source: "content/images/tree_s.png" + source: "images/tree_s.png" image: "images/tree_s.png" } PaletteItem { anchors.verticalCenter: parent.verticalCenter componentFile: "PerspectiveItem.qml" - source: "content/images/rabbit_brown.png" + source: "images/rabbit_brown.png" image: "images/rabbit_brown.png" } PaletteItem { anchors.verticalCenter: parent.verticalCenter componentFile: "PerspectiveItem.qml" - source: "content/images/rabbit_bw.png" + source: "images/rabbit_bw.png" image: "images/rabbit_bw.png" } } @@ -258,7 +257,7 @@ Item { selectByMouse: true wrapMode: TextEdit.WordWrap - text: "import QtQuick 2.0\nImage {\n id: smile\n x: 360 * Math.random()\n y: 40 * Math.random() \n source: 'content/images/face-smile.png'\n NumberAnimation on opacity { \n to: 0; duration: 1500\n }\n Component.onCompleted: smile.destroy(1500);\n}" + text: "import QtQuick 2.0\nImage {\n id: smile\n x: 360 * Math.random()\n y: 40 * Math.random() \n source: 'images/face-smile.png'\n NumberAnimation on opacity { \n to: 0; duration: 1500\n }\n Component.onCompleted: smile.destroy(1500);\n}" } } } diff --git a/examples/qml/dynamicscene/dynamicscene.qrc b/examples/qml/dynamicscene/dynamicscene.qrc index ad14d313f4..052b9f8536 100644 --- a/examples/qml/dynamicscene/dynamicscene.qrc +++ b/examples/qml/dynamicscene/dynamicscene.qrc @@ -1,18 +1,18 @@ - + dynamicscene.qml - content/images/face-smile.png - content/images/moon.png - content/images/NOTE - content/images/rabbit_brown.png - content/images/rabbit_bw.png - content/images/star.png - content/images/sun.png - content/images/tree_s.png - content/GenericSceneItem.qml - content/itemCreation.js - content/PaletteItem.qml - content/PerspectiveItem.qml - content/Sun.qml + images/face-smile.png + images/moon.png + images/NOTE + images/rabbit_brown.png + images/rabbit_bw.png + images/star.png + images/sun.png + images/tree_s.png + GenericSceneItem.qml + itemCreation.js + PaletteItem.qml + PerspectiveItem.qml + Sun.qml diff --git a/examples/qml/dynamicscene/images/NOTE b/examples/qml/dynamicscene/images/NOTE new file mode 100644 index 0000000000..fcd87f9132 --- /dev/null +++ b/examples/qml/dynamicscene/images/NOTE @@ -0,0 +1 @@ +Images (except star.png) are from the KDE project. diff --git a/examples/qml/dynamicscene/images/face-smile.png b/examples/qml/dynamicscene/images/face-smile.png new file mode 100644 index 0000000000..3d66d72578 Binary files /dev/null and b/examples/qml/dynamicscene/images/face-smile.png differ diff --git a/examples/qml/dynamicscene/images/moon.png b/examples/qml/dynamicscene/images/moon.png new file mode 100644 index 0000000000..1c0d6066a8 Binary files /dev/null and b/examples/qml/dynamicscene/images/moon.png differ diff --git a/examples/qml/dynamicscene/images/rabbit_brown.png b/examples/qml/dynamicscene/images/rabbit_brown.png new file mode 100644 index 0000000000..ebfdeed332 Binary files /dev/null and b/examples/qml/dynamicscene/images/rabbit_brown.png differ diff --git a/examples/qml/dynamicscene/images/rabbit_bw.png b/examples/qml/dynamicscene/images/rabbit_bw.png new file mode 100644 index 0000000000..7bff9b92ca Binary files /dev/null and b/examples/qml/dynamicscene/images/rabbit_bw.png differ diff --git a/examples/qml/dynamicscene/images/star.png b/examples/qml/dynamicscene/images/star.png new file mode 100644 index 0000000000..bdcd36909d Binary files /dev/null and b/examples/qml/dynamicscene/images/star.png differ diff --git a/examples/qml/dynamicscene/images/sun.png b/examples/qml/dynamicscene/images/sun.png new file mode 100644 index 0000000000..c5fd36ed39 Binary files /dev/null and b/examples/qml/dynamicscene/images/sun.png differ diff --git a/examples/qml/dynamicscene/images/tree_s.png b/examples/qml/dynamicscene/images/tree_s.png new file mode 100644 index 0000000000..6eac35a729 Binary files /dev/null and b/examples/qml/dynamicscene/images/tree_s.png differ diff --git a/examples/qml/dynamicscene/itemCreation.js b/examples/qml/dynamicscene/itemCreation.js new file mode 100644 index 0000000000..2829a83410 --- /dev/null +++ b/examples/qml/dynamicscene/itemCreation.js @@ -0,0 +1,62 @@ +var itemComponent = null; +var draggedItem = null; +var startingMouse; +var posnInWindow; + +function startDrag(mouse) +{ + posnInWindow = paletteItem.mapToItem(window, 0, 0); + startingMouse = { x: mouse.x, y: mouse.y } + loadComponent(); +} + +//Creation is split into two functions due to an asynchronous wait while +//possible external files are loaded. + +function loadComponent() { + if (itemComponent != null) { // component has been previously loaded + createItem(); + return; + } + + 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, {"image": paletteItem.image, "x": posnInWindow.x, "y": posnInWindow.y, "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(itemComponent.errorString()); + } +} + +function continueDrag(mouse) +{ + if (draggedItem == null) + return; + + draggedItem.x = mouse.x + posnInWindow.x - startingMouse.x; + draggedItem.y = mouse.y + posnInWindow.y - startingMouse.y; +} + +function endDrag(mouse) +{ + if (draggedItem == null) + return; + + if (draggedItem.y < toolbox.height) { //Don't drop it in the toolbox + draggedItem.destroy(); + draggedItem = null; + } else { + draggedItem.created = true; + draggedItem = null; + } +} + diff --git a/examples/qml/dynamicscene/main.cpp b/examples/qml/dynamicscene/main.cpp index e28375158d..f6d2ee9a78 100644 --- a/examples/qml/dynamicscene/main.cpp +++ b/examples/qml/dynamicscene/main.cpp @@ -48,4 +48,4 @@ ** ****************************************************************************/ #include "../../quick/shared/shared.h" -DECLARATIVE_EXAMPLE_MAIN(dynamicscene) +DECLARATIVE_EXAMPLE_MAIN(dynamicscene/dynamicscene) -- cgit v1.2.3