aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual/itemparticle
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/itemparticle')
-rw-r--r--tests/manual/itemparticle/CMakeLists.txt49
-rw-r--r--tests/manual/itemparticle/delegates.qml58
-rw-r--r--tests/manual/itemparticle/images/rocket.pngbin0 -> 7315 bytes
-rw-r--r--tests/manual/itemparticle/itemparticle.pro10
-rw-r--r--tests/manual/itemparticle/itemparticle.qml262
-rw-r--r--tests/manual/itemparticle/itemparticle.qrc8
-rw-r--r--tests/manual/itemparticle/main.cpp4
-rw-r--r--tests/manual/itemparticle/script.js27
8 files changed, 418 insertions, 0 deletions
diff --git a/tests/manual/itemparticle/CMakeLists.txt b/tests/manual/itemparticle/CMakeLists.txt
new file mode 100644
index 0000000000..8a22a02783
--- /dev/null
+++ b/tests/manual/itemparticle/CMakeLists.txt
@@ -0,0 +1,49 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(itemparticle LANGUAGES CXX)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
+endif()
+
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quick/particles/itemparticle")
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
+
+qt_standard_project_setup(REQUIRES 6.5)
+
+add_subdirectory("../shared" "shared")
+
+qt_add_executable(itemparticleexample WIN32 MACOSX_BUNDLE
+ main.cpp
+)
+
+target_link_libraries(itemparticleexample PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Qml
+ Qt6::Quick
+)
+
+add_dependencies(itemparticleexample itemparticle_shared)
+
+# Resources:
+qt_add_qml_module(itemparticleexample
+ URI itemparticle
+ QML_FILES
+ "itemparticle.qml"
+ "delegates.qml"
+ "script.js"
+ RESOURCES
+ "images/rocket.png"
+)
+
+install(TARGETS itemparticleexample
+ RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
+
+bundle_shared(itemparticleexample)
diff --git a/tests/manual/itemparticle/delegates.qml b/tests/manual/itemparticle/delegates.qml
new file mode 100644
index 0000000000..be5d716168
--- /dev/null
+++ b/tests/manual/itemparticle/delegates.qml
@@ -0,0 +1,58 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQuick
+import QtQuick.Particles
+
+Rectangle {
+ id: root;
+ width: 360
+ height: 600
+ color: "black"
+
+ function newPithySaying() {
+ switch (Math.floor(Math.random()*16)) {
+ case 0: return "Hello World";
+ case 1: return "G'day Mate";
+ case 2: return "Code Less";
+ case 3: return "Create More";
+ case 4: return "Deploy Everywhere";
+ case 5: return "Qt Meta-object Language";
+ case 6: return "Qt Magic Language";
+ case 7: return "Fluid UIs";
+ case 8: return "Touchable";
+ case 9: return "How's it going?";
+ case 10: return "Do you like text?";
+ case 11: return "Enjoy!";
+ case 12: return "ERROR: Out of pith";
+ case 13: return "Punctuation Failure";
+ case 14: return "I can go faster";
+ case 15: return "I can go slower";
+ default: return "OMGWTFBBQ";
+ }
+ }
+
+ ParticleSystem {
+ anchors.fill: parent
+ id: syssy
+ MouseArea {
+ anchors.fill: parent
+ onClicked: syssy.running = !syssy.running
+ }
+ Emitter {
+ anchors.centerIn: parent
+ emitRate: 1
+ lifeSpan: 4800
+ lifeSpanVariation: 1600
+ velocity: AngleDirection {angleVariation: 360; magnitude: 40; magnitudeVariation: 20}
+ }
+ ItemParticle {
+ delegate: Text {
+ text: root.newPithySaying();
+ color: "white"
+ font.pixelSize: 18
+ font.bold: true
+ }
+ }
+ }
+}
diff --git a/tests/manual/itemparticle/images/rocket.png b/tests/manual/itemparticle/images/rocket.png
new file mode 100644
index 0000000000..a171610b03
--- /dev/null
+++ b/tests/manual/itemparticle/images/rocket.png
Binary files differ
diff --git a/tests/manual/itemparticle/itemparticle.pro b/tests/manual/itemparticle/itemparticle.pro
new file mode 100644
index 0000000000..4228852ae0
--- /dev/null
+++ b/tests/manual/itemparticle/itemparticle.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+RESOURCES += \
+ itemparticle.qrc \
+ ../shared/shared.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/particles/itemparticle
+INSTALLS += target
diff --git a/tests/manual/itemparticle/itemparticle.qml b/tests/manual/itemparticle/itemparticle.qml
new file mode 100644
index 0000000000..68f82cf801
--- /dev/null
+++ b/tests/manual/itemparticle/itemparticle.qml
@@ -0,0 +1,262 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQuick
+import QtQuick.Particles
+import shared
+import "script.js" as Script
+
+Item {
+ id: root
+ width: 640
+ height: 480
+ Rectangle {
+ anchors.fill: parent
+ color: "black"
+ z: -1
+ }
+ Item {
+ id: loading
+ Behavior on opacity {NumberAnimation {}}
+ anchors.fill: parent
+ Text {
+ anchors.centerIn: parent
+ text: "Loading"
+ color: "white"
+ }
+ }
+ ParticleSystem {
+ id: sys;
+ running: true
+ }
+ Emitter {
+ id: emitter
+ system: sys
+ height: parent.height - 132/2
+ x: -132/2
+ y: 132/2
+ velocity: PointDirection { x: 32; xVariation: 8 }
+ emitRate: 0.5
+ lifeSpan: Emitter.InfiniteLife
+ group: "photos"
+ }
+ Age {
+ system: sys
+ x: parent.width + 132/2
+ height: parent.height
+ width: 1000
+ }
+ ImageParticle {
+ system: sys
+ groups: ["fireworks"]
+ source: "qrc:///particleresources/star.png"
+ color: "lightsteelblue"
+ alpha: 0
+ colorVariation: 0
+ z: 1000
+ }
+ ItemParticle {
+ id: mp
+ z: 0
+ system: sys
+ fade: false
+ groups: ["photos"]
+ }
+ Component {
+ id: alertDelegate
+ Rectangle {
+ color: "DarkSlateGray"
+ border.width: 1
+ border.color: "LightSteelBlue"
+ width: 144
+ height: 132
+ antialiasing: true
+ radius: 3
+ NumberAnimation on scale {
+ running: true
+ loops: 1
+ from: 0.2
+ to: 1
+ }
+ Image {
+ source: "images/rocket.png"
+ anchors.centerIn: parent
+ }
+ Text {
+ anchors.bottom: parent.bottom
+ anchors.horizontalCenter: parent.horizontalCenter
+ text: "A new ship has arrived!"
+ color: "LightSteelBlue"
+ }
+ }
+ }
+ property Item alertItem;
+ function alert() {
+ force.enabled = true;
+ alertItem = alertDelegate.createObject(root);
+ alertItem.x = root.width/2 - alertItem.width/2
+ alertItem.y = root.height/2 - alertItem.height/2
+ spawnFireworks.pulse(200);
+ stopAlert.start();
+ }
+ focus: true
+ Keys.onSpacePressed: alert();
+ Timer {
+ id: stopAlert
+ running: false
+ repeat: false
+ interval: 800
+ onTriggered: {
+ force.enabled = false;
+ mp.take(root.alertItem, true);
+ centerEmitter.burst(1);
+ }
+ }
+ Attractor {
+ id: force
+ system: sys
+ pointX: root.width/2
+ pointY: root.height/2
+ strength: -10000
+ enabled: false
+ anchors.centerIn: parent
+ width: parent.width/2
+ height: parent.height/2
+ groups:["photos"]
+ affectedParameter: Attractor.Position
+ }
+ Emitter {
+ id: centerEmitter
+ velocity: PointDirection { x: 32; xVariation: 8;}
+ emitRate: 0.5
+ lifeSpan: 12000 //TODO: A -1 or something which does 'infinite'? (but need disable fade first)
+ maximumEmitted: 20
+ group: "photos"
+ system: sys
+ anchors.centerIn: parent
+ enabled: false
+
+ //TODO: Zoom in effect
+ }
+ Emitter {
+ id: spawnFireworks
+ group: "fireworks"
+ system: sys
+ maximumEmitted: 400
+ emitRate: 400
+ lifeSpan: 2800
+ x: parent.width/2
+ y: parent.height/2 - 64
+ width: 8
+ height: 8
+ enabled: false
+ size: 32
+ endSize: 8
+ velocity: AngleDirection { magnitude: 160; magnitudeVariation: 120; angleVariation: 90; angle: 270 }
+ acceleration: PointDirection { y: 160 }
+ }
+ Item { x: -1000; y: -1000 //offscreen
+ Repeater {//Load them here, add to system on completed
+ model: flickrModel
+ delegate: theDelegate
+ }
+ }
+ FlickrRssModel {
+ id: flickrModel
+ tags: "particle,particles"
+ }
+ Component {
+ id: theDelegate
+ Image {
+ required property int index
+ required property string title
+ required property string media
+ required property string thumbnail
+
+ id: image
+ antialiasing: true;
+ source: thumbnail
+ cache: true
+ property real depth: Math.random()
+ property real darken: 0.75
+ z: Math.floor(depth * 100)
+ scale: (depth + 1) / 2
+ sourceSize {
+ width: root.width
+ height: root.height
+ }
+ width: 132
+ height: 132
+ fillMode: Image.PreserveAspectFit
+ Rectangle {
+ // Darken based on depth
+ anchors.centerIn: parent
+ width: parent.paintedWidth + 1
+ height: parent.paintedHeight + 1
+ color: "black"
+ opacity: image.darken * (1 - image.depth)
+ antialiasing: true;
+ }
+ Text {
+ anchors.bottom: parent.bottom
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.bottomMargin: Math.max(parent.paintedWidth, parent.paintedHeight) - Math.min(parent.width, parent.height)
+ width: parent.paintedWidth - 4
+ horizontalAlignment: Text.AlignHCenter
+ elide: Text.ElideRight
+ text: image.title
+ color: "black"
+ }
+ ItemParticle.onDetached: mp.take(image); // respawns
+ onStatusChanged: if (image.status == Image.Ready) {
+ loading.opacity = 0;
+ mp.take(image);
+ }
+ function manage()
+ {
+ if (state == "selected") {
+ console.log("Taking " + index);
+ mp.freeze(image);
+ } else {
+ console.log("Returning " +index);
+ mp.unfreeze(image);
+ }
+ }
+ TapHandler {
+ gesturePolicy: TapHandler.ReleaseWithinBounds
+ onTapped: image.state = (image.state == "" ? "selected" : "")
+ }
+ states: State {
+ name: "selected"
+ ParentChange {
+ target: image
+ parent: root
+ }
+ PropertyChanges {
+ image {
+ source: image.media
+ x: 0
+ y: 0
+ width: root.width
+ height: root.height
+ z: 101
+ opacity: 1
+ rotation: 0
+ darken: 0
+ }
+ }
+ }
+ transitions: Transition {
+ to: "selected"
+ reversible: true
+ SequentialAnimation {
+ ScriptAction { script: image.manage() }
+ ParallelAnimation {
+ ParentAnimation {NumberAnimation { properties: "x,y" }}
+ PropertyAnimation { properties: "width, height, z, rotation, darken"; easing.type: Easing.InOutQuad }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/tests/manual/itemparticle/itemparticle.qrc b/tests/manual/itemparticle/itemparticle.qrc
new file mode 100644
index 0000000000..d345d2a957
--- /dev/null
+++ b/tests/manual/itemparticle/itemparticle.qrc
@@ -0,0 +1,8 @@
+<RCC>
+ <qresource prefix="/qt/qml/itemparticle">
+ <file>itemparticle.qml</file>
+ <file>delegates.qml</file>
+ <file>script.js</file>
+ <file>images/rocket.png</file>
+ </qresource>
+</RCC>
diff --git a/tests/manual/itemparticle/main.cpp b/tests/manual/itemparticle/main.cpp
new file mode 100644
index 0000000000..cc7410f861
--- /dev/null
+++ b/tests/manual/itemparticle/main.cpp
@@ -0,0 +1,4 @@
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+#include "../shared/shared.h"
+DECLARATIVE_EXAMPLE_MAIN(itemparticle/itemparticle)
diff --git a/tests/manual/itemparticle/script.js b/tests/manual/itemparticle/script.js
new file mode 100644
index 0000000000..e8ef93a847
--- /dev/null
+++ b/tests/manual/itemparticle/script.js
@@ -0,0 +1,27 @@
+.pragma library
+
+function getWidth(string) {
+ return (string.match(/width=\"([0-9]+)\"/))[1]
+}
+
+function getHeight(string) {
+ return (string.match(/height=\"([0-9]+)\"/))[1]
+}
+
+function getImagePath(string) {
+ var pattern = /src=\"http:\/\/(\S+)\"/
+ return (string.match(pattern))[1]
+}
+
+function calculateScale(width, height, cellSize) {
+ var widthScale = (cellSize * 1.0) / width
+ var heightScale = (cellSize * 1.0) / height
+ var scale = 0
+
+ if (widthScale <= heightScale) {
+ scale = widthScale;
+ } else if (heightScale < widthScale) {
+ scale = heightScale;
+ }
+ return scale;
+}