aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/declarative/flickr/content/ImageDetails.qml184
-rw-r--r--demos/declarative/flickr/content/Progress.qml22
-rw-r--r--demos/declarative/flickr/content/StreamView.qml34
-rw-r--r--demos/declarative/flickr/content/UnifiedDelegate.qml2
-rw-r--r--demos/declarative/flickr/content/images/noise.pngbin0 -> 25447 bytes
-rw-r--r--demos/declarative/flickr/flickr.qml30
-rw-r--r--demos/declarative/plasmapatrol/content/BlasterHardpoint.qml34
-rw-r--r--demos/declarative/plasmapatrol/content/CannonHardpoint.qml24
-rw-r--r--demos/declarative/plasmapatrol/content/ChoiceBox.qml2
-rw-r--r--demos/declarative/plasmapatrol/content/Cruiser.qml32
-rw-r--r--demos/declarative/plasmapatrol/content/Frigate.qml26
-rw-r--r--demos/declarative/plasmapatrol/content/Hardpoint.qml2
-rw-r--r--demos/declarative/plasmapatrol/content/HelpScreens.qml2
-rw-r--r--demos/declarative/plasmapatrol/content/LaserHardpoint.qml34
-rw-r--r--demos/declarative/plasmapatrol/content/PlasmaPatrolParticles.qml60
-rw-r--r--demos/declarative/plasmapatrol/content/Ship.qml2
-rw-r--r--demos/declarative/plasmapatrol/content/Sloop.qml20
-rw-r--r--demos/declarative/plasmapatrol/plasmapatrol.qml18
-rw-r--r--demos/declarative/samegame/SamegameCore/BoomBlock.qml18
-rw-r--r--demos/declarative/samegame/samegame.qml14
-rw-r--r--examples/declarative/cppextensions/imageprovider/imageprovider-example.qml4
-rw-r--r--examples/declarative/dragtarget/dragtarget.qmlproject16
-rw-r--r--examples/declarative/dragtarget/lists/listmodel.qml256
-rw-r--r--examples/declarative/dragtarget/lists/lists.qmlproject16
-rw-r--r--examples/declarative/dragtarget/text/dragtext.qml142
-rw-r--r--examples/declarative/dragtarget/text/text.qmlproject16
-rw-r--r--examples/declarative/dragtarget/tiles/DragTile.qml59
-rw-r--r--examples/declarative/dragtarget/tiles/DropTile.qml30
-rw-r--r--examples/declarative/dragtarget/tiles/tiles.qml85
-rw-r--r--examples/declarative/particles/allsmiles/plain.qml26
-rw-r--r--examples/declarative/particles/allsmiles/smile.qml100
-rw-r--r--examples/declarative/particles/allsmiles/smilefactory.qml42
-rw-r--r--examples/declarative/particles/allsmiles/spriteparticles.qml32
-rw-r--r--examples/declarative/particles/allsmiles/spritestateparticles.qml18
-rw-r--r--examples/declarative/particles/allsmiles/spritevariedparticles.qml18
-rw-r--r--examples/declarative/particles/allsmiles/ultraparticles.qml16
-rw-r--r--examples/declarative/particles/asteroid/asteroid.qml56
-rw-r--r--examples/declarative/particles/asteroid/blackhole.qml69
-rw-r--r--examples/declarative/particles/custom/blurparticles.qml165
-rw-r--r--examples/declarative/particles/custom/content/particle.pngbin0 -> 861 bytes
-rw-r--r--examples/declarative/particles/custom/content/smile.pngbin0 -> 15408 bytes
-rw-r--r--examples/declarative/particles/custom/fireworks.qml (renamed from examples/declarative/particles/snow/snow3.qml)86
-rw-r--r--examples/declarative/particles/custom/shader.qml84
-rw-r--r--examples/declarative/particles/exampleslauncher.qml116
-rw-r--r--examples/declarative/particles/launcherContent/Button.qml (renamed from examples/declarative/particles/trails/swarm.qml)61
-rw-r--r--examples/declarative/particles/launcherContent/Shell.qml (renamed from examples/declarative/particles/snow/snow2.qml)58
-rw-r--r--examples/declarative/particles/launcherContent/icons/asteroid.pngbin0 -> 35579 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/blackhole.pngbin0 -> 31296 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/blurparticles.pngbin0 -> 7793 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/close.pngbin0 -> 2144 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/dynamicemitters.pngbin0 -> 9347 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/fireballs.pngbin0 -> 5371 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/flickr.pngbin0 -> 10542 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/gridsplosion.pngbin0 -> 8154 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/layered.pngbin0 -> 8572 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/list.pngbin0 -> 32912 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/overburst.pngbin0 -> 1019 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/package.pngbin0 -> 3163 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/plain.pngbin0 -> 4705 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/plasmapatrol.pngbin0 -> 9839 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/portal.pngbin0 -> 11359 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/rainbow.pngbin0 -> 6538 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/remove.pngbin0 -> 2144 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/samegame.pngbin0 -> 8647 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/shimmer.pngbin0 -> 13670 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/smile.pngbin0 -> 12784 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/smilefactory.pngbin0 -> 2863 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/snow.pngbin0 -> 5858 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/spaceexplorer.pngbin0 -> 9152 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/spriteparticles.pngbin0 -> 6963 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/spritestateparticles.pngbin0 -> 2565 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/spritevariedparticles.pngbin0 -> 2569 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/stream.pngbin0 -> 26560 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/trails.pngbin0 -> 23168 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/turbulence.pngbin0 -> 9684 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/ultraparticles.pngbin0 -> 9590 bytes
-rw-r--r--examples/declarative/particles/launcherContent/icons/velocityfrommotion.pngbin0 -> 36360 bytes
-rw-r--r--examples/declarative/particles/launcherContent/launcher.js8
-rw-r--r--examples/declarative/particles/modelparticles/bubbles.qml17
-rw-r--r--examples/declarative/particles/modelparticles/gridsplosion.qml24
-rw-r--r--examples/declarative/particles/modelparticles/package.qml12
-rw-r--r--examples/declarative/particles/modelparticles/stream.qml54
-rw-r--r--examples/declarative/particles/snow/snow.qml43
-rw-r--r--examples/declarative/particles/spaceexplorer/spaceexplorer.qml93
-rw-r--r--examples/declarative/particles/trails/dynamicemitters.qml34
-rw-r--r--examples/declarative/particles/trails/fireballs.qml90
-rw-r--r--examples/declarative/particles/trails/layered.qml28
-rw-r--r--examples/declarative/particles/trails/list.qml16
-rw-r--r--examples/declarative/particles/trails/overburst.qml22
-rw-r--r--examples/declarative/particles/trails/portal.qml40
-rw-r--r--examples/declarative/particles/trails/rainbow.qml22
-rw-r--r--examples/declarative/particles/trails/shimmer.qml16
-rw-r--r--examples/declarative/particles/trails/trails.qml34
-rw-r--r--examples/declarative/particles/trails/turbulence.qml56
-rw-r--r--examples/declarative/particles/trails/velocityfrommotion.qml74
-rw-r--r--examples/declarative/toys/dynamicscene/dynamicscene.qml10
-rw-r--r--examples/declarative/toys/dynamicscene/qml/Sun.qml2
-rw-r--r--examples/declarative/ui-components/flipable/content/Card.qml2
-rw-r--r--examples/declarative/ui-components/flipable/flipable.qml4
-rw-r--r--src/declarative/debugger/qjsdebuggeragent.cpp13
-rw-r--r--src/declarative/debugger/qjsdebuggeragent_p.h2
-rw-r--r--src/declarative/debugger/qjsdebugservice.cpp10
-rw-r--r--src/declarative/debugger/qpacketprotocol.cpp2
-rw-r--r--src/declarative/declarative.pro1
-rw-r--r--src/declarative/items/items.pri9
-rw-r--r--src/declarative/items/qsgcanvas.cpp229
-rw-r--r--src/declarative/items/qsgcanvas.h3
-rw-r--r--src/declarative/items/qsgcanvas_p.h7
-rw-r--r--src/declarative/items/qsgcanvasitem.cpp290
-rw-r--r--src/declarative/items/qsgcanvasitem_p.h3
-rw-r--r--src/declarative/items/qsgcontext2d.cpp619
-rw-r--r--src/declarative/items/qsgcontext2d_p.h34
-rw-r--r--src/declarative/items/qsgdragtarget.cpp361
-rw-r--r--src/declarative/items/qsgdragtarget_p.h137
-rw-r--r--src/declarative/items/qsgevent.h137
-rw-r--r--src/declarative/items/qsgitem.cpp42
-rw-r--r--src/declarative/items/qsgitem.h5
-rw-r--r--src/declarative/items/qsgitem_p.h1
-rw-r--r--src/declarative/items/qsgitemsmodule.cpp8
-rw-r--r--src/declarative/items/qsgmousearea.cpp153
-rw-r--r--src/declarative/items/qsgmousearea_p.h32
-rw-r--r--src/declarative/items/qsgmousearea_p_p.h4
-rw-r--r--src/declarative/items/qsgshadereffectitem.cpp1
-rw-r--r--src/declarative/items/qsgshadereffectmesh.cpp6
-rw-r--r--src/declarative/items/qsgshadereffectnode.cpp1
-rw-r--r--src/declarative/items/qsgsprite.cpp (renamed from src/imports/particles/spritestate.cpp)4
-rw-r--r--src/declarative/items/qsgsprite_p.h (renamed from src/imports/particles/spritestate.h)8
-rw-r--r--src/declarative/items/qsgspriteengine.cpp (renamed from src/imports/particles/spriteengine.cpp)44
-rw-r--r--src/declarative/items/qsgspriteengine_p.h (renamed from src/imports/particles/spriteengine.h)40
-rw-r--r--src/declarative/items/qsgspriteimage.cpp (renamed from src/imports/particles/spriteimage.cpp)46
-rw-r--r--src/declarative/items/qsgspriteimage_p.h (renamed from src/imports/particles/spriteimage.h)20
-rw-r--r--src/declarative/items/qsgtext.cpp50
-rw-r--r--src/declarative/items/qsgtext_p.h1
-rw-r--r--src/declarative/items/qsgtext_p_p.h4
-rw-r--r--src/declarative/items/qsgtextnode.cpp44
-rw-r--r--src/declarative/items/qsgtextnode_p.h3
-rw-r--r--src/declarative/particles/defaultshaders/ctfragment.shader (renamed from src/imports/particles/resources/ctfragment.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/ctvertex.shader (renamed from src/imports/particles/resources/ctvertex.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/defaultFadeInOut.png (renamed from src/imports/particles/resources/defaultFadeInOut.png)bin286 -> 286 bytes
-rw-r--r--src/declarative/particles/defaultshaders/deformablefragment.shader (renamed from src/imports/particles/resources/deformablefragment.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/deformablevertex.shader (renamed from src/imports/particles/resources/deformablevertex.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/identitytable.png (renamed from src/imports/particles/resources/identitytable.png)bin90 -> 90 bytes
-rw-r--r--src/declarative/particles/defaultshaders/simplefragment.shader (renamed from src/imports/particles/resources/simplefragment.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/simplevertex.shader (renamed from src/imports/particles/resources/simplevertex.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/spritefragment.shader (renamed from src/imports/particles/resources/spritefragment.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/spriteimagefragment.shader (renamed from src/imports/particles/resources/spriteimagefragment.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/spriteimagevertex.shader (renamed from src/imports/particles/resources/spriteimagevertex.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/spritevertex.shader (renamed from src/imports/particles/resources/spritevertex.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/superfragment.shader (renamed from src/imports/particles/resources/superfragment.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/supervertex.shader (renamed from src/imports/particles/resources/supervertex.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/trailsfragment.shader (renamed from src/imports/particles/resources/trailsfragment.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/trailsvertex.shader (renamed from src/imports/particles/resources/trailsvertex.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/ultrafragment.shader (renamed from src/imports/particles/resources/ultrafragment.shader)0
-rw-r--r--src/declarative/particles/defaultshaders/ultravertex.shader (renamed from src/imports/particles/resources/ultravertex.shader)0
-rw-r--r--src/declarative/particles/particles.pri60
-rw-r--r--src/declarative/particles/particles.qrc22
-rw-r--r--src/declarative/particles/qsgangleddirection.cpp (renamed from src/imports/particles/angledvector.cpp)8
-rw-r--r--src/declarative/particles/qsgangleddirection_p.h (renamed from src/imports/particles/angledvector.h)12
-rw-r--r--src/declarative/particles/qsgcustomparticle.cpp518
-rw-r--r--src/declarative/particles/qsgcustomparticle_p.h118
-rw-r--r--src/declarative/particles/qsgellipseextruder.cpp (renamed from src/imports/particles/ellipseextruder.cpp)10
-rw-r--r--src/declarative/particles/qsgellipseextruder_p.h (renamed from src/imports/particles/ellipseextruder.h)6
-rw-r--r--src/declarative/particles/qsgemitter.cpp (renamed from src/imports/particles/trailsemitter.cpp)39
-rw-r--r--src/declarative/particles/qsgemitter_p.h (renamed from src/imports/particles/trailsemitter.h)9
-rw-r--r--src/declarative/particles/qsgfollowemitter.cpp (renamed from src/imports/particles/followemitter.cpp)69
-rw-r--r--src/declarative/particles/qsgfollowemitter_p.h (renamed from src/imports/particles/followemitter.h)28
-rw-r--r--src/declarative/particles/qsgfriction.cpp (renamed from src/imports/particles/frictionaffector.cpp)8
-rw-r--r--src/declarative/particles/qsgfriction_p.h (renamed from src/imports/particles/frictionaffector.h)8
-rw-r--r--src/declarative/particles/qsggravity.cpp (renamed from src/imports/particles/gravityaffector.cpp)14
-rw-r--r--src/declarative/particles/qsggravity_p.h (renamed from src/imports/particles/gravityaffector.h)8
-rw-r--r--src/declarative/particles/qsgimageparticle.cpp (renamed from src/imports/particles/ultraparticle.cpp)381
-rw-r--r--src/declarative/particles/qsgimageparticle_p.h (renamed from src/imports/particles/ultraparticle.h)70
-rw-r--r--src/declarative/particles/qsgitemparticle.cpp (renamed from src/imports/particles/itemparticle.cpp)147
-rw-r--r--src/declarative/particles/qsgitemparticle_p.h (renamed from src/imports/particles/itemparticle.h)57
-rw-r--r--src/declarative/particles/qsgkill.cpp (renamed from src/imports/particles/killaffector.cpp)12
-rw-r--r--src/declarative/particles/qsgkill_p.h (renamed from src/imports/particles/killaffector.h)8
-rw-r--r--src/declarative/particles/qsglineextruder.cpp (renamed from src/imports/particles/lineextruder.cpp)8
-rw-r--r--src/declarative/particles/qsglineextruder_p.h (renamed from src/imports/particles/lineextruder.h)6
-rw-r--r--src/declarative/particles/qsgmaskextruder.cpp (renamed from src/imports/particles/maskextruder.cpp)23
-rw-r--r--src/declarative/particles/qsgmaskextruder_p.h (renamed from src/imports/particles/maskextruder.h)6
-rw-r--r--src/declarative/particles/qsgmodelparticle.cpp (renamed from src/imports/particles/dataparticle.cpp)151
-rw-r--r--src/declarative/particles/qsgmodelparticle_p.h (renamed from src/imports/particles/dataparticle.h)38
-rw-r--r--src/declarative/particles/qsgparticleaffector.cpp (renamed from src/imports/particles/particleaffector.cpp)54
-rw-r--r--src/declarative/particles/qsgparticleaffector_p.h (renamed from src/imports/particles/particleaffector.h)39
-rw-r--r--src/declarative/particles/qsgparticleemitter.cpp (renamed from src/imports/particles/particleemitter.cpp)33
-rw-r--r--src/declarative/particles/qsgparticleemitter_p.h (renamed from src/imports/particles/particleemitter.h)73
-rw-r--r--src/declarative/particles/qsgparticleextruder.cpp (renamed from src/imports/particles/particleextruder.cpp)8
-rw-r--r--src/declarative/particles/qsgparticleextruder_p.h (renamed from src/imports/particles/particleextruder.h)4
-rw-r--r--src/declarative/particles/qsgparticlepainter.cpp188
-rw-r--r--src/declarative/particles/qsgparticlepainter_p.h (renamed from src/imports/particles/particle.h)70
-rw-r--r--src/declarative/particles/qsgparticlesmodule.cpp111
-rw-r--r--src/declarative/particles/qsgparticlesmodule_p.h (renamed from src/imports/particles/burstemitter.cpp)28
-rw-r--r--src/declarative/particles/qsgparticlesystem.cpp447
-rw-r--r--src/declarative/particles/qsgparticlesystem_p.h (renamed from src/imports/particles/particlesystem.h)116
-rw-r--r--src/declarative/particles/qsgpointattractor.cpp (renamed from src/imports/particles/attractoraffector.cpp)40
-rw-r--r--src/declarative/particles/qsgpointattractor_p.h (renamed from src/imports/particles/attractoraffector.h)56
-rw-r--r--src/declarative/particles/qsgpointdirection.cpp (renamed from src/imports/particles/pointvector.cpp)8
-rw-r--r--src/declarative/particles/qsgpointdirection_p.h (renamed from src/imports/particles/pointvector.h)6
-rw-r--r--src/declarative/particles/qsgspritegoal.cpp (renamed from src/imports/particles/spritegoalaffector.cpp)30
-rw-r--r--src/declarative/particles/qsgspritegoal_p.h (renamed from src/imports/particles/spritegoalaffector.h)14
-rw-r--r--src/declarative/particles/qsgstochasticdirection.cpp (renamed from src/imports/particles/varyingvector.cpp)6
-rw-r--r--src/declarative/particles/qsgstochasticdirection_p.h (renamed from src/imports/particles/varyingvector.h)4
-rw-r--r--src/declarative/particles/qsgtargeteddirection.cpp (renamed from src/imports/particles/directedvector.cpp)12
-rw-r--r--src/declarative/particles/qsgtargeteddirection_p.h (renamed from src/imports/particles/directedvector.h)6
-rw-r--r--src/declarative/particles/qsgturbulence.cpp (renamed from src/imports/particles/turbulenceaffector.cpp)68
-rw-r--r--src/declarative/particles/qsgturbulence_p.h (renamed from src/imports/particles/turbulenceaffector.h)10
-rw-r--r--src/declarative/particles/qsgwander.cpp (renamed from src/imports/particles/wanderaffector.cpp)50
-rw-r--r--src/declarative/particles/qsgwander_p.h (renamed from src/imports/particles/wanderaffector.h)41
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp6
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp2
-rw-r--r--src/declarative/qml/qdeclarativevme.cpp1
-rw-r--r--src/declarative/qml/qdeclarativexmlhttprequest.cpp9
-rw-r--r--src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp14
-rw-r--r--src/declarative/scenegraph/coreapi/qsgdefaultrenderer_p.h4
-rw-r--r--src/declarative/scenegraph/coreapi/qsgnode.cpp22
-rw-r--r--src/declarative/scenegraph/coreapi/qsgnode.h13
-rw-r--r--src/declarative/scenegraph/coreapi/qsgrenderer.cpp23
-rw-r--r--src/declarative/scenegraph/qsgcontext.cpp2
-rw-r--r--src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp7
-rw-r--r--src/declarative/scenegraph/qsgdistancefieldglyphnode.cpp58
-rw-r--r--src/declarative/util/qdeclarativechangeset.cpp440
-rw-r--r--src/declarative/util/qdeclarativechangeset_p.h160
-rw-r--r--src/declarative/util/qdeclarativepixmapcache.cpp5
-rw-r--r--src/declarative/util/util.pri2
-rw-r--r--src/imports/particles/burstemitter.h67
-rw-r--r--src/imports/particles/coloredparticle.cpp540
-rw-r--r--src/imports/particles/coloredparticle.h254
-rw-r--r--src/imports/particles/deformableparticle.cpp438
-rw-r--r--src/imports/particles/deformableparticle.h235
-rw-r--r--src/imports/particles/driftaffector.cpp67
-rw-r--r--src/imports/particles/driftaffector.h104
-rw-r--r--src/imports/particles/eternalaffector.cpp60
-rw-r--r--src/imports/particles/eternalaffector.h88
-rw-r--r--src/imports/particles/gravitationalsingularityaffector.cpp179
-rw-r--r--src/imports/particles/gravitationalsingularityaffector.h121
-rw-r--r--src/imports/particles/main.cpp160
-rw-r--r--src/imports/particles/meanderaffector.cpp65
-rw-r--r--src/imports/particles/meanderaffector.h103
-rw-r--r--src/imports/particles/particle.cpp135
-rw-r--r--src/imports/particles/particles.cpp (renamed from src/imports/particles/speedlimitaffector.h)52
-rw-r--r--src/imports/particles/particles.pro109
-rw-r--r--src/imports/particles/particlesystem.cpp396
-rw-r--r--src/imports/particles/pictureaffector.cpp118
-rw-r--r--src/imports/particles/pictureaffector.h99
-rw-r--r--src/imports/particles/pluginmain.h65
-rw-r--r--src/imports/particles/resetaffector.cpp78
-rw-r--r--src/imports/particles/resetaffector.h75
-rw-r--r--src/imports/particles/speedlimitaffector.cpp77
-rw-r--r--src/imports/particles/spriteparticle.cpp449
-rw-r--r--src/imports/particles/spriteparticle.h99
-rw-r--r--src/imports/particles/spriteparticles.qrc22
-rw-r--r--src/imports/particles/superparticle.cpp511
-rw-r--r--src/imports/particles/superparticle.h389
-rw-r--r--src/imports/particles/swarmaffector.cpp114
-rw-r--r--src/imports/particles/swarmaffector.h116
-rw-r--r--src/imports/particles/toggleaffector.cpp59
-rw-r--r--src/imports/particles/toggleaffector.h102
-rw-r--r--src/imports/particles/zoneaffector.cpp68
-rw-r--r--src/imports/particles/zoneaffector.h159
-rw-r--r--tests/auto/declarative/declarative.pro1
-rw-r--r--tests/auto/declarative/node/tst_nodestest.cpp4
-rw-r--r--tests/auto/declarative/qdeclarativechangeset/qdeclarativechangeset.pro17
-rw-r--r--tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp614
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/importScope.1.js1
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/importScope.2.js3
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/importScope.qml7
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp14
-rw-r--r--tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp1
-rw-r--r--tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp1
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/NestedComponentRoot.qml6
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/nestedComponentRoots.qml4
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp7
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData.qml2
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_DELETE.expect7
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_HEAD.expect (renamed from tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_PUT.expect)0
-rw-r--r--tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp23
-rw-r--r--tests/auto/declarative/qsglistview/tst_qsglistview.cpp2
-rw-r--r--tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp6
-rw-r--r--tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp22
-rw-r--r--tests/benchmarks/declarative/binding/tst_binding.cpp3
-rw-r--r--tests/benchmarks/declarative/declarative.pro1
-rw-r--r--tests/benchmarks/declarative/javascript/data/NestedIdObject.qml9
-rw-r--r--tests/benchmarks/declarative/javascript/data/intQObjectProperty.qml13
-rw-r--r--tests/benchmarks/declarative/javascript/data/localId.qml13
-rw-r--r--tests/benchmarks/declarative/javascript/data/nestedId.qml13
-rw-r--r--tests/benchmarks/declarative/javascript/data/stringQObjectProperty.qml14
-rw-r--r--tests/benchmarks/declarative/javascript/javascript.pro11
-rw-r--r--tests/benchmarks/declarative/javascript/testtypes.cpp48
-rw-r--r--tests/benchmarks/declarative/javascript/testtypes.h65
-rw-r--r--tests/benchmarks/declarative/javascript/tst_javascript.cpp123
-rw-r--r--tools/qmlscene/main.cpp6
291 files changed, 8152 insertions, 8022 deletions
diff --git a/demos/declarative/flickr/content/ImageDetails.qml b/demos/declarative/flickr/content/ImageDetails.qml
index 62c3397f08..74346466e3 100644
--- a/demos/declarative/flickr/content/ImageDetails.qml
+++ b/demos/declarative/flickr/content/ImageDetails.qml
@@ -40,7 +40,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Flipable {
id: container
@@ -57,6 +57,8 @@ Flipable {
property int rating: 2
property variant prevScale: 1.0
+ property int flipDuration: 1600
+
signal closed
transform: Rotation {
@@ -137,95 +139,173 @@ Flipable {
slider.value = prevScale;
}
if (inBackState && bigImage.status == Image.Ready)
- particleBox.imageInAnim();
+ effectBox.imageInAnim();
}
property bool inBackState: false
onInBackStateChanged:{
if(inBackState && bigImage.status == Image.Ready)
- particleBox.imageInAnim();
+ effectBox.imageInAnim();
else if (!inBackState && bigImage.status == Image.Ready)
- particleBox.imageOutAnim();
+ effectBox.imageOutAnim();
}
}
+ ShaderEffectSource{
+ id: pictureSource
+ sourceItem: bigImage
+ smooth: true
+ //Workaround: Doesn't work below lines
+ width: bigImage.width
+ height: bigImage.width
+ visible: false
+ }
+ Turbulence{//only fill visible rect
+ id: turbulence
+ system: imageSystem
+ anchors.fill: parent
+ frequency: 100
+ strength: 250
+ active: false
+ }
Item{
- id: particleBox
+ id: effectBox
width: bigImage.width * bigImage.scale
height: bigImage.height * bigImage.scale
anchors.centerIn: parent
-
function imageInAnim(){
- cp.visible = true;
- pixAffect.onceOff = false;
bigImage.visible = false;
+ noiseIn.visible = true;
endEffectTimer.start();
- pixelEmitter.pulse(1);
}
function imageOutAnim(){
- cp.visible = true;
- pixAffect.onceOff = true;
bigImage.visible = false;
+ noiseIn.visible = false;
turbulence.active = true;
endEffectTimer.start();
pixelEmitter.burst(2048);
}
Timer{
id: endEffectTimer
- interval: 1000
+ interval: flipDuration
repeat: false
running: false
onTriggered:{
- bigImage.visible = true;
turbulence.active = false;
- cp.visible = false;
+ noiseIn.visible = false;
+ bigImage.visible = true;
}
}
- ParticleSystem{
- id: imageSystem
- }
- ColoredParticle{
- id: cp
- system: imageSystem
- color: "gray"
- alpha: 1
- image: "images/squareParticle.png"
- colorVariation: 0
- }
- Picture{
- id: pixAffect
- system: imageSystem
+ ShaderEffectItem{
+ id: noiseIn
anchors.fill: parent
- image: container.photoUrl;
- onceOff: true
+ property real t: 0
+ visible: false
+ onVisibleChanged: tAnim.start()
+ NumberAnimation{
+ id: tAnim
+ target: noiseIn
+ property: "t"
+ from: 0.0
+ to: 1.0
+ duration: flipDuration
+ }
+ property variant source: pictureSource
+ property variant noise: ShaderEffectSource{
+ sourceItem:Image{
+ source: "images/noise.png"
+ }
+ hideSource: true
+ smooth: false
+ }
+ fragmentShader:"
+ uniform sampler2D noise;
+ uniform sampler2D source;
+ uniform highp float t;
+ uniform lowp float qt_Opacity;
+ varying highp vec2 qt_TexCoord0;
+ void main(){
+ //Want to use noise2, but it always returns (0,0)?
+ if(texture2D(noise, qt_TexCoord0).w <= t)
+ gl_FragColor = texture2D(source, qt_TexCoord0) * qt_Opacity;
+ else
+ gl_FragColor = vec4(0.,0.,0.,0.);
+ }
+ "
}
- Turbulence{
- id: turbulence
- system: imageSystem
- anchors.fill: parent
- frequency: 100
- strength: 250
- active: false
+ ParticleSystem{
+ id: imageSystem
}
- TrailEmitter{
- id: pixelEmitter0
+ Emitter{
+ id: pixelEmitter
system: imageSystem
- height: parent.height
- particleSize: 4
- particleDuration: 1000
- particlesPerSecond: 4096
- speed: PointVector{x: 360; xVariation: 8; yVariation: 4}
+ //anchors.fill: parent
+ width: Math.min(bigImage.width * bigImage.scale, flickable.width);
+ height: Math.min(bigImage.height * bigImage.scale, flickable.height);
+ anchors.centerIn: parent
+ size: 4
+ lifeSpan: flipDuration
+ emitRate: 2048
emitting: false
}
- TrailEmitter{
- id: pixelEmitter
+ CustomParticle{
+ id: blowOut
system: imageSystem
- anchors.fill: parent
- particleSize: 4
- particleDuration: 1000
- particlesPerSecond: 2048
- emitting: false
+ property real maxWidth: effectBox.width
+ property real maxHeight: effectBox.height
+ vertexShader:"
+ attribute highp vec2 vPos;
+ attribute highp vec2 vTex;
+ attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize
+ attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
+ attribute highp float r;
+
+ uniform highp float maxWidth;
+ uniform highp float maxHeight;
+
+ uniform highp mat4 qt_ModelViewProjectionMatrix;
+ uniform highp float timestamp;
+ uniform lowp float qt_Opacity;
+
+ varying highp vec2 fTex2;
+ varying lowp float fFade;
+
+ void main() {
+ fTex2 = vec2(vPos.x / maxWidth, vPos.y / maxHeight);
+ highp float size = vData.z;
+ highp float endSize = vData.w;
+
+ highp float t = (timestamp - vData.x) / vData.y;
+
+ highp float currentSize = mix(size, endSize, t * t);
+
+ if (t < 0. || t > 1.)
+ currentSize = 0.;
+
+ highp vec2 pos = vPos
+ - currentSize / 2. + currentSize * vTex // adjust size
+ + vVec.xy * t * vData.y // apply speed vector..
+ + 0.5 * vVec.zw * pow(t * vData.y, 2.);
+
+ gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1);
+
+ highp float fadeIn = min(t * 10., 1.);
+ highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
+
+ fFade = 1.0;//fadeIn * fadeOut * qt_Opacity;
+ }
+ "
+ property variant pictureTexture: pictureSource
+ fragmentShader: "
+ uniform sampler2D pictureTexture;
+ varying highp vec2 fTex2;
+ varying highp float fFade;
+ void main() {
+ gl_FragColor = texture2D(pictureTexture, fTex2) * fFade;
+ }"
}
+
+
}
}
}
@@ -268,7 +348,7 @@ Flipable {
transitions: Transition {
SequentialAnimation {
PropertyAction { target: bigImage; property: "smooth"; value: false }
- NumberAnimation { easing.type: Easing.InOutQuad; properties: "angle"; duration: 1000 }
+ NumberAnimation { easing.type: Easing.InOutQuad; properties: "angle"; duration: flipDuration }
PropertyAction { target: bigImage; property: "smooth"; value: !flickable.movingVertically }
}
}
diff --git a/demos/declarative/flickr/content/Progress.qml b/demos/declarative/flickr/content/Progress.qml
index d403feebd1..73a91a4aa9 100644
--- a/demos/declarative/flickr/content/Progress.qml
+++ b/demos/declarative/flickr/content/Progress.qml
@@ -40,7 +40,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item{
id: container
@@ -59,24 +59,24 @@ Item{
running: container.visible
id: barSys
}
- ColoredParticle{
+ ImageParticle{
color: "lightsteelblue"
alpha: 0.1
colorVariation: 0.05
- image: "images/particle.png"
+ source: "images/particle.png"
system: barSys
}
- TrailEmitter{
+ Emitter{
y: 2; height: parent.height-4;
x: 2; width: Math.max(parent.width * progress - 4, 0);
- speed: AngleVector{ angleVariation: 180; magnitudeVariation: 12 }
+ speed: AngledDirection{ angleVariation: 180; magnitudeVariation: 12 }
system: barSys
- particlesPerSecond: width;
- particleDuration: 1000
- particleSize: 20
- particleSizeVariation: 4
- particleEndSize: 12
- maxParticles: parent.width;
+ emitRate: width;
+ lifeSpan: 1000
+ size: 20
+ sizeVariation: 4
+ endSize: 12
+ emitCap: parent.width;
}
Text {
diff --git a/demos/declarative/flickr/content/StreamView.qml b/demos/declarative/flickr/content/StreamView.qml
index 26a3f35e63..d7b608a391 100644
--- a/demos/declarative/flickr/content/StreamView.qml
+++ b/demos/declarative/flickr/content/StreamView.qml
@@ -40,7 +40,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item{
id: container
@@ -52,7 +52,7 @@ Item{
anchors.fill:parent
overwrite: false
}
- DataParticle{
+ ModelParticle{
id: mp
fade: false
system: sys
@@ -66,38 +66,38 @@ Item{
}
}
property real emitterSpacing: parent.width/3
- TrailEmitter{
+ Emitter{
system: sys
width: emitterSpacing - 64
x: emitterSpacing*0 + 32
y: -128
height: 32
- speed: PointVector{ y: (container.height + 128)/12 }
- particlesPerSecond: 0.4
- particleDuration: 1000000//eventually -1 should mean a million seconds for neatness
- maxParticles: 15
+ speed: PointDirection{ y: (container.height + 128)/12 }
+ emitRate: 0.4
+ lifeSpan: 1000000//eventually -1 should mean a million seconds for neatness
+ emitCap: 15
}
- TrailEmitter{
+ Emitter{
system: sys
width: emitterSpacing - 64
x: emitterSpacing*1 + 32
y: -128
height: 32
- speed: PointVector{ y: (container.height + 128)/12 }
- particlesPerSecond: 0.4
- particleDuration: 1000000//eventually -1 should mean a million seconds for neatness
- maxParticles: 15
+ speed: PointDirection{ y: (container.height + 128)/12 }
+ emitRate: 0.4
+ lifeSpan: 1000000//eventually -1 should mean a million seconds for neatness
+ emitCap: 15
}
- TrailEmitter{
+ Emitter{
system: sys
width: emitterSpacing - 64
x: emitterSpacing*2 + 32
y: -128
height: 32
- speed: PointVector{ y: (container.height + 128)/12 }
- particlesPerSecond: 0.4
- particleDuration: 1000000//eventually -1 should mean a million seconds for neatness
- maxParticles: 15
+ speed: PointDirection{ y: (container.height + 128)/12 }
+ emitRate: 0.4
+ lifeSpan: 1000000//eventually -1 should mean a million seconds for neatness
+ emitCap: 15
}
Kill{
system: sys
diff --git a/demos/declarative/flickr/content/UnifiedDelegate.qml b/demos/declarative/flickr/content/UnifiedDelegate.qml
index aaf4ccbd7a..f4c926763f 100644
--- a/demos/declarative/flickr/content/UnifiedDelegate.qml
+++ b/demos/declarative/flickr/content/UnifiedDelegate.qml
@@ -40,7 +40,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Package {
function photoClicked() {
diff --git a/demos/declarative/flickr/content/images/noise.png b/demos/declarative/flickr/content/images/noise.png
new file mode 100644
index 0000000000..c5a5ba0053
--- /dev/null
+++ b/demos/declarative/flickr/content/images/noise.png
Binary files differ
diff --git a/demos/declarative/flickr/flickr.qml b/demos/declarative/flickr/flickr.qml
index 40e1bae683..a222b41341 100644
--- a/demos/declarative/flickr/flickr.qml
+++ b/demos/declarative/flickr/flickr.qml
@@ -40,7 +40,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
import "content"
Item {
@@ -56,21 +56,21 @@ Item {
id: bgParticles
startTime: 16000
}
- ColoredParticle {
+ ImageParticle {
particles: ["trail"]
- image: "content/images/particle.png"
+ source: "content/images/particle.png"
color: "#1A1A6F"
alpha: 0.1
colorVariation: 0.01
blueVariation: 0.8
system: bgParticles
}
- TrailEmitter {
+ Emitter {
particle: "drops"
width: parent.width
- particlesPerSecond: 0.5
- particleDuration: 20000
- speed: PointVector{
+ emitRate: 0.5
+ lifeSpan: 20000
+ speed: PointDirection{
y: {screen.height/18}
}
system: bgParticles
@@ -78,16 +78,16 @@ Item {
FollowEmitter {
follow: "drops"
particle: "trail"
- particlesPerParticlePerSecond: 18
- particleSize: 32
- particleEndSize: 0
- particleSizeVariation: 4
- particleDuration: 1200
+ emitRatePerParticle: 18
+ size: 32
+ endSize: 0
+ sizeVariation: 4
+ lifeSpan: 1200
system: bgParticles
anchors.fill: parent
- emissionWidth: 16
- emissionHeight: 16
- emissionShape: Ellipse{}
+ emitWidth: 16
+ emitHeight: 16
+ emitShape: EllipseShape{}
}
VisualDataModel{
diff --git a/demos/declarative/plasmapatrol/content/BlasterHardpoint.qml b/demos/declarative/plasmapatrol/content/BlasterHardpoint.qml
index 8d36cdfb13..1242a85149 100644
--- a/demos/declarative/plasmapatrol/content/BlasterHardpoint.qml
+++ b/demos/declarative/plasmapatrol/content/BlasterHardpoint.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item {
id: container
@@ -53,20 +53,20 @@ Item {
width: 24
height: 24
- TrailEmitter{
+ Emitter{
id: visualization
particle: "blaster"
system: container.system
emitting: show
anchors.fill: parent
- shape: Ellipse{}
- speed: DirectedVector{ targetX: width/2; targetY: width/2; magnitude: -1; proportionalMagnitude: true}
- particleDuration: 1000
- particlesPerSecond: 64
+ shape: EllipseShape{}
+ speed: TargetedDirection{ targetX: width/2; targetY: width/2; magnitude: -1; proportionalMagnitude: true}
+ lifeSpan: 1000
+ emitRate: 64
- particleSize: 24
- particleSizeVariation: 24
- particleEndSize: 0
+ size: 24
+ sizeVariation: 24
+ endSize: 0
}
property int blastsLeft: 0
@@ -112,20 +112,20 @@ Item {
rofTimer.repeat = false;
}
}
- TrailEmitter{
+ Emitter{
id: emitter
particle: "blaster"
emitting: false
system: container.system
anchors.centerIn: parent
- particleDuration: 1000
- particlesPerSecond: 16
- maxParticles: blasts
- particleSize: 24
- particleEndSize:16
- particleSizeVariation: 8
- speed: DirectedVector{
+ lifeSpan: 1000
+ emitRate: 16
+ emitCap: blasts
+ size: 24
+ endSize:16
+ sizeVariation: 8
+ speed: TargetedDirection{
id: blastVector
targetX: target.x; targetY: target.y; magnitude: 1.1; proportionalMagnitude: true
}
diff --git a/demos/declarative/plasmapatrol/content/CannonHardpoint.qml b/demos/declarative/plasmapatrol/content/CannonHardpoint.qml
index d9a307cc64..b7572ef5c4 100644
--- a/demos/declarative/plasmapatrol/content/CannonHardpoint.qml
+++ b/demos/declarative/plasmapatrol/content/CannonHardpoint.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item {
id: container
@@ -49,17 +49,17 @@ Item {
width: 24
height: 24
- TrailEmitter{
+ Emitter{
id: visualization
particle: "cannon"
emitting: container.show
system: container.system
anchors.centerIn: parent
- particleDuration: 2000
- particlesPerSecond: 1
+ lifeSpan: 2000
+ emitRate: 1
- particleSize: 4
- particleEndSize: 0
+ size: 4
+ endSize: 0
}
function fireAt(targetArg, hardpoint){
@@ -78,18 +78,18 @@ Item {
}
emitter.burst(1);
}
- TrailEmitter{
+ Emitter{
id: emitter
particle: "cannon"
emitting: false
system: container.system
anchors.centerIn: parent
- particleDuration: 1000
- particlesPerSecond: 1
- particleSize: 8
- particleEndSize: 4
- speed: DirectedVector{
+ lifeSpan: 1000
+ emitRate: 1
+ size: 8
+ endSize: 4
+ speed: TargetedDirection{
id: blastVector
targetX: target.x; targetY: target.y; magnitude: 1.1; proportionalMagnitude: true
}
diff --git a/demos/declarative/plasmapatrol/content/ChoiceBox.qml b/demos/declarative/plasmapatrol/content/ChoiceBox.qml
index 6bdc4288ee..1e64a76225 100644
--- a/demos/declarative/plasmapatrol/content/ChoiceBox.qml
+++ b/demos/declarative/plasmapatrol/content/ChoiceBox.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item{
id: container
diff --git a/demos/declarative/plasmapatrol/content/Cruiser.qml b/demos/declarative/plasmapatrol/content/Cruiser.qml
index 8b8073328e..a844fa1bb8 100644
--- a/demos/declarative/plasmapatrol/content/Cruiser.qml
+++ b/demos/declarative/plasmapatrol/content/Cruiser.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item {
id: container
@@ -54,7 +54,7 @@ Item {
property int gunType: 0
width: 128
height: 128
- TrailEmitter{
+ Emitter{
//TODO: Cooler would be an 'orbiting' affector
//TODO: On the subject, opacity and size should be grouped type 'overLife' if we can cram that in the particles
system: container.system
@@ -62,30 +62,30 @@ Item {
anchors.centerIn: parent
width: 64
height: 64
- shape: Ellipse{}
+ shape: EllipseShape{}
- particlesPerSecond: hp > 0 ? hp * 1 + 20 : 0
- particleDuration: 2400
- maxParticles: (maxHP * 1 + 20)*2.4
+ emitRate: hp > 0 ? hp * 1 + 20 : 0
+ lifeSpan: 2400
+ emitCap: (maxHP * 1 + 20)*2.4
- particleSize: 48
- particleSizeVariation: 16
- particleEndSize: 16
+ size: 48
+ sizeVariation: 16
+ endSize: 16
- speed: AngleVector{angleVariation:360; magnitudeVariation: 32}
+ speed: AngledDirection{angleVariation:360; magnitudeVariation: 32}
}
- TrailEmitter{
+ Emitter{
system: container.system
particle: "cruiserArmor"
anchors.fill: parent
- shape: Ellipse{ fill: false }
+ shape: EllipseShape{ fill: false }
emitting: hp>0
- particlesPerSecond: 16
- particleDuration: 2000
+ emitRate: 16
+ lifeSpan: 2000
- particleSize: 48
- particleSizeVariation: 24
+ size: 48
+ sizeVariation: 24
SpriteGoal{
id: destructor
diff --git a/demos/declarative/plasmapatrol/content/Frigate.qml b/demos/declarative/plasmapatrol/content/Frigate.qml
index 54f629268f..d31405250e 100644
--- a/demos/declarative/plasmapatrol/content/Frigate.qml
+++ b/demos/declarative/plasmapatrol/content/Frigate.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item {
id: container
@@ -54,29 +54,29 @@ Item {
property int gunType: 0
width: 128
height: 128
- TrailEmitter{
+ Emitter{
system: container.system
particle: "frigateShield"
anchors.centerIn: parent
- particleSize: 92
- particlesPerSecond: 1
- particleDuration: 4800
+ size: 92
+ emitRate: 1
+ lifeSpan: 4800
emitting: hp > 0
}
- TrailEmitter{
+ Emitter{
system: container.system
particle: container.shipParticle
anchors.centerIn: parent
width: 64
height: 16
- shape: Ellipse{}
+ shape: EllipseShape{}
- particleSize: 16
- particleSizeVariation: 8
- particleEndSize: 8
- particlesPerSecond: hp > 0 ? hp * 1 + 20 : 0
- particleDuration: 1200
- maxParticles: (maxHP * 1 + 20)*2
+ size: 16
+ sizeVariation: 8
+ endSize: 8
+ emitRate: hp > 0 ? hp * 1 + 20 : 0
+ lifeSpan: 1200
+ emitCap: (maxHP * 1 + 20)*2
}
Timer{
id: fireControl
diff --git a/demos/declarative/plasmapatrol/content/Hardpoint.qml b/demos/declarative/plasmapatrol/content/Hardpoint.qml
index 184c750a79..3d4edb38f8 100644
--- a/demos/declarative/plasmapatrol/content/Hardpoint.qml
+++ b/demos/declarative/plasmapatrol/content/Hardpoint.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item {
id: container
diff --git a/demos/declarative/plasmapatrol/content/HelpScreens.qml b/demos/declarative/plasmapatrol/content/HelpScreens.qml
index 8896aeee4a..7e4fb9f1c9 100644
--- a/demos/declarative/plasmapatrol/content/HelpScreens.qml
+++ b/demos/declarative/plasmapatrol/content/HelpScreens.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
SequentialLoader {
id: hLdr
diff --git a/demos/declarative/plasmapatrol/content/LaserHardpoint.qml b/demos/declarative/plasmapatrol/content/LaserHardpoint.qml
index d6d470a15b..e99424856c 100644
--- a/demos/declarative/plasmapatrol/content/LaserHardpoint.qml
+++ b/demos/declarative/plasmapatrol/content/LaserHardpoint.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item {
id: container
@@ -49,20 +49,20 @@ Item {
width: 24
height: 24
- TrailEmitter{
+ Emitter{
id: visualization
particle: "laser"
system: container.system
anchors.fill: parent
emitting: container.show
- shape: Ellipse{}
- speed: DirectedVector{ targetX: width/2; targetY: width/2; magnitude: -1; proportionalMagnitude: true }
- particleDuration: 1000
- particlesPerSecond: 64
+ shape: EllipseShape{}
+ speed: TargetedDirection{ targetX: width/2; targetY: width/2; magnitude: -1; proportionalMagnitude: true }
+ lifeSpan: 1000
+ emitRate: 64
- particleSize: 24
- particleSizeVariation: 8
- particleEndSize: 8
+ size: 24
+ sizeVariation: 8
+ endSize: 8
}
function fireAt(targetArg, hardpoint){
@@ -84,7 +84,7 @@ Item {
emitter.pulse(0.10);
// console.log("Fire box: " + Math.min(container.width/2, target.x) + "," + Math.min(container.height/2, target.y) + " " + (Math.max(container.width/2, target.x) - Math.min(container.width/2, target.x)) + "," + (Math.max(container.height/2, target.y) - Math.min(container.height/2, target.y)));
}
- TrailEmitter{
+ Emitter{
id: emitter
particle: "laser"
emitting: false
@@ -93,16 +93,16 @@ Item {
width: Math.max(container.width/2, target.x) - x;
y: Math.min(container.height/2, target.y);
height: Math.max(container.height/2, target.y) - y;
- shape: Line{
+ shape: LineShape{
mirrored: (emitter.y < 0 || emitter.x < 0) && !(emitter.y < 0 && emitter.x < 0 )//I just want XOR
}
- particleDuration: 1000
- particlesPerSecond: 8000
- maxParticles: 800
- particleSize: 16
- particleEndSize: 0
+ lifeSpan: 1000
+ emitRate: 8000
+ emitCap: 800
+ size: 16
+ endSize: 0
- speed: PointVector{xVariation: 4; yVariation: 4}
+ speed: PointDirection{xVariation: 4; yVariation: 4}
}
}
diff --git a/demos/declarative/plasmapatrol/content/PlasmaPatrolParticles.qml b/demos/declarative/plasmapatrol/content/PlasmaPatrolParticles.qml
index 7a6fcb96d0..b65686e59e 100644
--- a/demos/declarative/plasmapatrol/content/PlasmaPatrolParticles.qml
+++ b/demos/declarative/plasmapatrol/content/PlasmaPatrolParticles.qml
@@ -39,87 +39,87 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item{
property ParticleSystem sys
- ColoredParticle{
+ ImageParticle{
system: sys
particles: ["default"]
- image: "pics/blur-circle3.png"
+ source: "pics/blur-circle3.png"
color: "#003A3A3A"
colorVariation: 0.1
z: 0
}
- ColoredParticle{
+ ImageParticle{
system: sys
particles: ["redTeam"]
- image: "pics/blur-circle3.png"
+ source: "pics/blur-circle3.png"
color: "#0028060A"
colorVariation: 0.1
z: 0
}
- ColoredParticle{
+ ImageParticle{
system: sys
particles: ["greenTeam"]
- image: "pics/blur-circle3.png"
+ source: "pics/blur-circle3.png"
color: "#0006280A"
colorVariation: 0.1
z: 0
}
- ColoredParticle{
+ ImageParticle{
system: sys
particles: ["blaster"]
- image: "pics/star2.png"
+ source: "pics/star2.png"
//color: "#0F282406"
color: "#0F484416"
colorVariation: 0.2
z: 2
}
- ColoredParticle{
+ ImageParticle{
system: sys
particles: ["laser"]
- image: "pics/star3.png"
+ source: "pics/star3.png"
//color: "#00123F68"
color: "#00428FF8"
colorVariation: 0.2
z: 2
}
- ColoredParticle{
+ ImageParticle{
system: sys
particles: ["cannon"]
- image: "pics/particle.png"
+ source: "pics/particle.png"
color: "#80FFAAFF"
colorVariation: 0.1
z: 2
}
- ColoredParticle{
+ ImageParticle{
system: sys
particles: ["cannonCore"]
- image: "pics/particle.png"
+ source: "pics/particle.png"
color: "#00666666"
colorVariation: 0.8
z: 1
}
- ColoredParticle{
+ ImageParticle{
system: sys
particles: ["cannonWake"]
- image: "pics/star.png"
+ source: "pics/star.png"
color: "#00CCCCCC"
colorVariation: 0.2
z: 1
}
- ColoredParticle{
+ ImageParticle{
system: sys
particles: ["frigateShield"]
- image: "pics/blur-circle2.png"
+ source: "pics/blur-circle2.png"
color: "#00000000"
colorVariation: 0.05
blueVariation: 0.5
greenVariation: 0.1
z: 3
}
- SpriteParticle{
+ ImageParticle{
system: sys
particles: ["cruiserArmor"]
z: 1
@@ -148,12 +148,12 @@ Item{
system: sys
particle: "cannonWake"
follow: "cannon"
- particlesPerParticlePerSecond: 64
- particleDuration: 600
- speed: AngleVector{ angleVariation: 360; magnitude: 48}
- particleSize: 16
- particleEndSize: 8
- particleSizeVariation: 2
+ emitRatePerParticle: 64
+ lifeSpan: 600
+ speed: AngledDirection{ angleVariation: 360; magnitude: 48}
+ size: 16
+ endSize: 8
+ sizeVariation: 2
emitting: true
width: 1000//XXX: Terrible hack
height: 1000
@@ -162,10 +162,10 @@ Item{
system: sys
particle: "cannonCore"
follow: "cannon"
- particlesPerParticlePerSecond: 256
- particleDuration: 128
- particleSize: 24
- particleEndSize: 8
+ emitRatePerParticle: 256
+ lifeSpan: 128
+ size: 24
+ endSize: 8
emitting: true
width: 1000//XXX: Terrible hack
height: 1000
diff --git a/demos/declarative/plasmapatrol/content/Ship.qml b/demos/declarative/plasmapatrol/content/Ship.qml
index 0ccea94221..ce8fb6073f 100644
--- a/demos/declarative/plasmapatrol/content/Ship.qml
+++ b/demos/declarative/plasmapatrol/content/Ship.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item {
id: me
diff --git a/demos/declarative/plasmapatrol/content/Sloop.qml b/demos/declarative/plasmapatrol/content/Sloop.qml
index 1b9bce7333..1a6f3a9620 100644
--- a/demos/declarative/plasmapatrol/content/Sloop.qml
+++ b/demos/declarative/plasmapatrol/content/Sloop.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item {
id: container
@@ -55,23 +55,23 @@ Item {
property int gunType: 0
width: 128
height: 128
- TrailEmitter{
+ Emitter{
id: emitter
//TODO: Cooler would be an 'orbiting' affector
//TODO: On the subject, opacity and size should be grouped type 'overLife' if we can cram that in the particles
system: container.system
particle: container.shipParticle
- shape: Ellipse{}
+ shape: EllipseShape{}
- particlesPerSecond: hp > 0 ? hp + 20 : 0
- particleDuration: blinkInterval
- maxParticles: (maxHP + 20)
+ emitRate: hp > 0 ? hp + 20 : 0
+ lifeSpan: blinkInterval
+ emitCap: (maxHP + 20)
- acceleration: AngleVector{angleVariation: 360; magnitude: 8}
+ acceleration: AngledDirection{angleVariation: 360; magnitude: 8}
- particleSize: 24
- particleEndSize: 4
- particleSizeVariation: 8
+ size: 24
+ endSize: 4
+ sizeVariation: 8
width: 16
height: 16
x: 64
diff --git a/demos/declarative/plasmapatrol/plasmapatrol.qml b/demos/declarative/plasmapatrol/plasmapatrol.qml
index 3a7b217618..dfc36ded01 100644
--- a/demos/declarative/plasmapatrol/plasmapatrol.qml
+++ b/demos/declarative/plasmapatrol/plasmapatrol.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
import "content"
Rectangle {
@@ -93,18 +93,18 @@ Rectangle {
id: title
width: root.width
height: 240
- TrailEmitter{
+ Emitter{
anchors.fill: parent
system: particles
emitting: true
particle: "default"
- particlesPerSecond: 1200
- particleDuration: 1200
- shape: Mask{source:"content/pics/TitleText.png"}
- particleSize: 16
- particleEndSize: 0
- particleSizeVariation: 8
- speed: AngleVector{angleVariation:360; magnitudeVariation: 6}
+ emitRate: 1200
+ lifeSpan: 1200
+ shape: MaskShape{source:"content/pics/TitleText.png"}
+ size: 16
+ endSize: 0
+ sizeVariation: 8
+ speed: AngledDirection{angleVariation:360; magnitudeVariation: 6}
}
}
Button{
diff --git a/demos/declarative/samegame/SamegameCore/BoomBlock.qml b/demos/declarative/samegame/SamegameCore/BoomBlock.qml
index 67e67b893a..2d8fdba2c9 100644
--- a/demos/declarative/samegame/SamegameCore/BoomBlock.qml
+++ b/demos/declarative/samegame/SamegameCore/BoomBlock.qml
@@ -40,7 +40,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Item {
id: block
@@ -71,7 +71,7 @@ Item {
Behavior on opacity { NumberAnimation { duration: 200 } }
anchors.fill: parent
}
- TrailEmitter {
+ Emitter {
id: particles
system: particleSystem
particle: {
@@ -85,14 +85,14 @@ Item {
}
anchors.fill: parent
- speed: DirectedVector{targetX: block.width/2; targetY: block.height/2; magnitude: -60; magnitudeVariation: 60}
- shape: Ellipse{fill:true}
+ speed: TargetedDirection{targetX: block.width/2; targetY: block.height/2; magnitude: -60; magnitudeVariation: 60}
+ shape: EllipseShape{fill:true}
emitting: false;
- particleDuration: 700; particleDurationVariation: 100
- particlesPerSecond: 1000
- maxParticles: 100 //only fires 0.1s bursts (still 2x old number, ColoredParticle wants less than 16000 max though)
- particleSize: 28
- particleEndSize: 14
+ lifeSpan: 700; lifeSpanVariation: 100
+ emitRate: 1000
+ emitCap: 100 //only fires 0.1s bursts (still 2x old number, ImageParticle wants less than 16000 max though)
+ size: 28
+ endSize: 14
}
states: [
diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml
index 202eb40401..0daf72de58 100644
--- a/demos/declarative/samegame/samegame.qml
+++ b/demos/declarative/samegame/samegame.qml
@@ -40,7 +40,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
import "SamegameCore"
import "SamegameCore/samegame.js" as Logic
@@ -77,27 +77,27 @@ Rectangle {
}
Item{
ParticleSystem{ id: particleSystem; }
- ColoredParticle {
+ ImageParticle {
system: particleSystem
particles: ["red"]
color: Qt.darker("red");//Actually want desaturated...
- image: "SamegameCore/pics/particle.png"
+ source: "SamegameCore/pics/particle.png"
colorVariation: 0.4
alpha: 0.1
}
- ColoredParticle {
+ ImageParticle {
system: particleSystem
particles: ["green"]
color: Qt.darker("green");//Actually want desaturated...
- image: "SamegameCore/pics/particle.png"
+ source: "SamegameCore/pics/particle.png"
colorVariation: 0.4
alpha: 0.1
}
- ColoredParticle {
+ ImageParticle {
system: particleSystem
particles: ["blue"]
color: Qt.darker("blue");//Actually want desaturated...
- image: "SamegameCore/pics/particle.png"
+ source: "SamegameCore/pics/particle.png"
colorVariation: 0.4
alpha: 0.1
}
diff --git a/examples/declarative/cppextensions/imageprovider/imageprovider-example.qml b/examples/declarative/cppextensions/imageprovider/imageprovider-example.qml
index e25b420025..f8f7b0ee55 100644
--- a/examples/declarative/cppextensions/imageprovider/imageprovider-example.qml
+++ b/examples/declarative/cppextensions/imageprovider/imageprovider-example.qml
@@ -42,8 +42,8 @@ import "ImageProviderCore" // import the plugin that registers the color image p
//![0]
Column {
- Image { source: "image://colors/yellow" }
- Image { source: "image://colors/red" }
+ Image { source: "source://colors/yellow" }
+ Image { source: "source://colors/red" }
}
//![0]
diff --git a/examples/declarative/dragtarget/dragtarget.qmlproject b/examples/declarative/dragtarget/dragtarget.qmlproject
new file mode 100644
index 0000000000..d4909f8685
--- /dev/null
+++ b/examples/declarative/dragtarget/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/dragtarget/lists/listmodel.qml b/examples/declarative/dragtarget/lists/listmodel.qml
new file mode 100644
index 0000000000..50b1d397c7
--- /dev/null
+++ b/examples/declarative/dragtarget/lists/listmodel.qml
@@ -0,0 +1,256 @@
+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
new file mode 100644
index 0000000000..d4909f8685
--- /dev/null
+++ b/examples/declarative/dragtarget/lists/lists.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/dragtarget/text/dragtext.qml b/examples/declarative/dragtarget/text/dragtext.qml
new file mode 100644
index 0000000000..c4a4f24f74
--- /dev/null
+++ b/examples/declarative/dragtarget/text/dragtext.qml
@@ -0,0 +1,142 @@
+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
new file mode 100644
index 0000000000..d4909f8685
--- /dev/null
+++ b/examples/declarative/dragtarget/text/text.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/dragtarget/tiles/DragTile.qml b/examples/declarative/dragtarget/tiles/DragTile.qml
new file mode 100644
index 0000000000..213373a392
--- /dev/null
+++ b/examples/declarative/dragtarget/tiles/DragTile.qml
@@ -0,0 +1,59 @@
+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
new file mode 100644
index 0000000000..9d968753db
--- /dev/null
+++ b/examples/declarative/dragtarget/tiles/DropTile.qml
@@ -0,0 +1,30 @@
+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
new file mode 100644
index 0000000000..d8bcb39bd2
--- /dev/null
+++ b/examples/declarative/dragtarget/tiles/tiles.qml
@@ -0,0 +1,85 @@
+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/particles/allsmiles/plain.qml b/examples/declarative/particles/allsmiles/plain.qml
new file mode 100644
index 0000000000..890a5782d1
--- /dev/null
+++ b/examples/declarative/particles/allsmiles/plain.qml
@@ -0,0 +1,26 @@
+import QtQuick 2.0
+import QtQuick.Particles 2.0
+
+Rectangle{
+ color: "goldenrod"
+ width: 2000
+ height: 2000
+ ParticleSystem{id: sys}
+ ImageParticle{
+ id: up
+ system: sys
+ source: "content/singlesmile.png"
+ }
+ Emitter{
+ anchors.centerIn: parent
+ system: sys
+ emitRate: 1000
+ size: 20
+ lifeSpan: 10000
+ speed: AngledDirection{angleVariation: 360; magnitudeVariation: 100;}
+ }
+ MouseArea{
+ anchors.fill: parent
+ onClicked: up.autoRotation = !up.autoRotation
+ }
+}
diff --git a/examples/declarative/particles/allsmiles/smile.qml b/examples/declarative/particles/allsmiles/smile.qml
index e37e8fa98e..6b122e7be5 100644
--- a/examples/declarative/particles/allsmiles/smile.qml
+++ b/examples/declarative/particles/allsmiles/smile.qml
@@ -39,35 +39,101 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
+ id: root
color: "white"
width: 310
height: 300
ParticleSystem{ id: sys }
- Picture{
+ CustomParticle{
system: sys
- anchors.fill: parent
- image: "content/singlesmile.png"
- onceOff: true
- }
- ColoredParticle{
- system: sys
- image: "content/particle.png"
- color: "black"
- alpha: 0.4
- sizeTable: "content/sizeInOut.png"
+ property real maxWidth: root.width
+ property real maxHeight: root.height
+ ShaderEffectSource{
+ id: pictureSource
+ sourceItem: picture
+ hideSource: true
+ }
+ Image{
+ id: picture
+ source: "content/singlesmile.png"
+ }
+ ShaderEffectSource{
+ id: particleSource
+ sourceItem: particle
+ hideSource: true
+ }
+ Image{
+ id: particle
+ source: "content/particle.png"
+ }
+ vertexShader:"
+ attribute highp vec2 vPos;
+ attribute highp vec2 vTex;
+ attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize
+ attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
+ attribute highp float r;
+
+ uniform highp float maxWidth;
+ uniform highp float maxHeight;
+
+ uniform highp mat4 qt_ModelViewProjectionMatrix;
+ uniform highp float timestamp;
+ uniform lowp float qt_Opacity;
+
+ varying highp vec2 fTex;
+ varying highp vec2 fTex2;
+ varying lowp float fFade;
+
+ void main() {
+ fTex = vTex;
+ fTex2 = vec2(vPos.x / maxWidth, vPos.y / maxHeight);
+ highp float size = vData.z;
+ highp float endSize = vData.w;
+
+ highp float t = (timestamp - vData.x) / vData.y;
+
+ highp float currentSize = mix(size, endSize, t * t);
+
+ if (t < 0. || t > 1.)
+ currentSize = 0.;
+
+ highp vec2 pos = vPos
+ - currentSize / 2. + currentSize * vTex // adjust size
+ + vVec.xy * t * vData.y // apply speed vector..
+ + 0.5 * vVec.zw * pow(t * vData.y, 2.);
+
+ gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1);
+
+ highp float fadeIn = min(t * 10., 1.);
+ highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
+
+ fFade = fadeIn * fadeOut * qt_Opacity;
+ }
+ "
+ property variant particleTexture: particleSource
+ property variant pictureTexture: pictureSource
+ fragmentShader: "
+ uniform sampler2D particleTexture;
+ uniform sampler2D pictureTexture;
+ varying highp vec2 fTex;
+ varying highp vec2 fTex2;
+ varying highp float fFade;
+ void main() {
+ gl_FragColor = texture2D(pictureTexture, fTex2) * texture2D(particleTexture, fTex).w * fFade;
+ }"
}
- TrailEmitter{
+ Emitter{
id: emitter
system: sys
emitting: false
- particleDuration: 4000
- maxParticles: 1200
+ lifeSpan: 4000
+ emitCap: 1200
anchors.fill: parent
- particleSize: 32
- speed: PointVector{ xVariation: 12; yVariation: 12 }
+ size: 32
+ speed: PointDirection{ xVariation: 12; yVariation: 12 }
}
MouseArea{
anchors.fill: parent
diff --git a/examples/declarative/particles/allsmiles/smilefactory.qml b/examples/declarative/particles/allsmiles/smilefactory.qml
index 47becb50fe..5b36eee3cd 100644
--- a/examples/declarative/particles/allsmiles/smilefactory.qml
+++ b/examples/declarative/particles/allsmiles/smilefactory.qml
@@ -39,27 +39,27 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
color: "goldenrod"
width: 400
height: 400
ParticleSystem{id:sys}
- DeformableParticle{
+ ImageParticle{
system: sys
particles: ["goingLeft", "goingRight"]
- image: "content/singlesmile.png"
+ source: "content/singlesmile.png"
rotation: 90
rotationSpeed: 90
autoRotation: true
}
- DeformableParticle{
+ ImageParticle{
system: sys
particles: ["goingDown"]
- image: "content/squarefacespriteXX.png"
+ source: "content/squarefacespriteXX.png"
rotation: 180
- yVector: PointVector{ y: 0.5; yVariation: 0.25; xVariation: 0.25; }
+ yVector: PointDirection{ y: 0.5; yVariation: 0.25; xVariation: 0.25; }
}
Timer{
running: true
@@ -79,40 +79,40 @@ Rectangle{
interval: 8400
onTriggered: emitC.emitting = true;
}
- TrailEmitter{
+ Emitter{
id: emitA
x: 0
y: 120
system: sys
emitting: false
particle: "goingRight"
- speed: PointVector{ x: 100 }
- particleDuration: 4000
- particlesPerSecond: 2
- particleSize: 32
+ speed: PointDirection{ x: 100 }
+ lifeSpan: 4000
+ emitRate: 2
+ size: 32
}
- TrailEmitter{
+ Emitter{
id: emitB
x: 400
y: 240
system: sys
emitting: false
particle: "goingLeft"
- speed: PointVector{ x: -100 }
- particleDuration: 4000
- particlesPerSecond: 2
- particleSize: 32
+ speed: PointDirection{ x: -100 }
+ lifeSpan: 4000
+ emitRate: 2
+ size: 32
}
- TrailEmitter{
+ Emitter{
id: emitC
x: 0
y: 360
system: sys
emitting: false
particle: "goingDown"
- speed: PointVector{ x: 100 }
- particleDuration: 4000
- particlesPerSecond: 2
- particleSize: 32
+ speed: PointDirection{ x: 100 }
+ lifeSpan: 4000
+ emitRate: 2
+ size: 32
}
}
diff --git a/examples/declarative/particles/allsmiles/spriteparticles.qml b/examples/declarative/particles/allsmiles/spriteparticles.qml
index 4bcb7081b8..f5479f1570 100644
--- a/examples/declarative/particles/allsmiles/spriteparticles.qml
+++ b/examples/declarative/particles/allsmiles/spriteparticles.qml
@@ -39,60 +39,60 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
color: "goldenrod"
width: 400
height: 400
- ColoredParticle{
+ ImageParticle{
id: test
particles: ["Test"]
- image: "content/particle.png"
+ source: "content/particle.png"
system: sys
z: 2
anchors.fill: parent
color: "#336666CC"
colorVariation: 0.0
}
- SpriteParticle{
+ ImageParticle{
id: single
particles: ["Face"]
system: sys
z: 2
anchors.fill: parent
- Sprite{
+ sprites: Sprite{
source: "content/squarefacesprite.png"
frames: 6
duration: 120
}
}
- Mask{
+ MaskShape{
id: mask
source: "content/smileMask.png"
}
- TrailEmitter{
+ Emitter{
system: sys
particle: "Test"
anchors.fill: parent
id: particles2
- particlesPerSecond: 6000
- particleDuration: 720
+ emitRate: 6000
+ lifeSpan: 720
emitting: true
- particleSize: 10
+ size: 10
shape: mask
}
- TrailEmitter{
+ Emitter{
system: sys
particle: "Face"
anchors.fill: parent
id: particles
- particlesPerSecond: 60
- particleDuration: 1440
+ emitRate: 60
+ lifeSpan: 1440
emitting: true
- speed: PointVector{xVariation: 10; yVariation: 10;}
- particleSize: 30
- particleSizeVariation: 10
+ speed: PointDirection{xVariation: 10; yVariation: 10;}
+ size: 30
+ sizeVariation: 10
shape: mask
}
ParticleSystem{
diff --git a/examples/declarative/particles/allsmiles/spritestateparticles.qml b/examples/declarative/particles/allsmiles/spritestateparticles.qml
index 6a61487a89..a599c69a63 100644
--- a/examples/declarative/particles/allsmiles/spritestateparticles.qml
+++ b/examples/declarative/particles/allsmiles/spritestateparticles.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
color: "goldenrod"
@@ -109,7 +109,7 @@ Rectangle{
z:4
}
ParticleSystem{ id: sys }
- SpriteParticle{
+ ImageParticle{
anchors.fill: parent
id: particles
system: sys
@@ -168,15 +168,15 @@ Rectangle{
duration: 10000
}]
}
- TrailEmitter{
+ Emitter{
system: sys
- particlesPerSecond: 16
- particleDuration: 10000
+ emitRate: 16
+ lifeSpan: 10000
emitting: true
- speed: AngleVector{angle: 90; magnitude: 60; angleVariation: 5}
- acceleration: PointVector{ y: 10 }
- particleSize: 30
- particleSizeVariation: 10
+ speed: AngledDirection{angle: 90; magnitude: 60; angleVariation: 5}
+ acceleration: PointDirection{ y: 10 }
+ size: 30
+ sizeVariation: 10
width: parent.width
height: 100
}
diff --git a/examples/declarative/particles/allsmiles/spritevariedparticles.qml b/examples/declarative/particles/allsmiles/spritevariedparticles.qml
index c1b773093f..d6e13727ff 100644
--- a/examples/declarative/particles/allsmiles/spritevariedparticles.qml
+++ b/examples/declarative/particles/allsmiles/spritevariedparticles.qml
@@ -39,14 +39,14 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
color: "goldenrod"
width: 800
height: 800
ParticleSystem{ id: sys }
- SpriteParticle{
+ ImageParticle{
system: sys
anchors.fill: parent
sprites: [Sprite{
@@ -92,17 +92,17 @@ Rectangle{
duration: 120
}]
}
- TrailEmitter{
+ Emitter{
id: particleEmitter
system: sys
width: parent.width
- particlesPerSecond: 16
- particleDuration: 8000
+ emitRate: 16
+ lifeSpan: 8000
emitting: true
- speed: AngleVector{angle: 90; magnitude: 300; magnitudeVariation: 100; angleVariation: 5}
- acceleration: PointVector{ y: 10 }
- particleSize: 30
- particleSizeVariation: 10
+ speed: AngledDirection{angle: 90; magnitude: 300; magnitudeVariation: 100; angleVariation: 5}
+ acceleration: PointDirection{ y: 10 }
+ size: 30
+ sizeVariation: 10
}
Binding{
target: particleEmitter
diff --git a/examples/declarative/particles/allsmiles/ultraparticles.qml b/examples/declarative/particles/allsmiles/ultraparticles.qml
index 85bbdbacd8..0ea095deb6 100644
--- a/examples/declarative/particles/allsmiles/ultraparticles.qml
+++ b/examples/declarative/particles/allsmiles/ultraparticles.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
color: "white"
@@ -48,7 +48,7 @@ Rectangle{
ParticleSystem{
id: sys
}
- UltraParticle{
+ ImageParticle{
sprites: [
Sprite{
name: "licking"
@@ -80,16 +80,16 @@ Rectangle{
factor: 0.1
system: sys
}
- TrailEmitter{
+ Emitter{
system: sys
anchors.centerIn: parent
id: particles
- particlesPerSecond: 200
- particleDuration: 6000
+ emitRate: 200
+ lifeSpan: 6000
emitting: true
- speed: AngleVector{angleVariation: 360; magnitude: 80; magnitudeVariation: 40}
- particleSize: 40
- particleEndSize: 80
+ speed: AngledDirection{angleVariation: 360; magnitude: 80; magnitudeVariation: 40}
+ size: 40
+ endSize: 80
}
Text{
x: 16
diff --git a/examples/declarative/particles/asteroid/asteroid.qml b/examples/declarative/particles/asteroid/asteroid.qml
index b5b4f672c2..2ecfc42a98 100644
--- a/examples/declarative/particles/asteroid/asteroid.qml
+++ b/examples/declarative/particles/asteroid/asteroid.qml
@@ -38,8 +38,8 @@
**
****************************************************************************/
-import Qt.labs.particles 2.0
-import Qt.labs.particles 2.0 as Qlp
+import QtQuick.Particles 2.0
+import QtQuick.Particles 2.0 as Qlp
import QtQuick 2.0
Item {
@@ -65,42 +65,42 @@ Item {
}
}
- ColoredParticle {
+ ImageParticle {
system: sys
particles: ["starfield"]
- image: "content/star.png"
+ source: "content/star.png"
colorVariation: 0.3
color: "white"
}
- TrailEmitter {
+ Emitter {
id: starField
system: sys
particle: "starfield"
- particlesPerSecond: 80
- particleDuration: 2500
+ emitRate: 80
+ lifeSpan: 2500
anchors.centerIn: parent
- //acceleration: AngleVector{angleVariation: 360; magnitude: 200}//Is this a better effect, more consistent speed?
- acceleration: PointVector{ xVariation: 200; yVariation: 200; }
+ //acceleration: AngledDirection{angleVariation: 360; magnitude: 200}//Is this a better effect, more consistent speed?
+ acceleration: PointDirection{ xVariation: 200; yVariation: 200; }
- particleSize: 0
- particleEndSize: 80
- particleSizeVariation: 10
+ size: 0
+ endSize: 80
+ sizeVariation: 10
}
- TrailEmitter{
+ Emitter{
system: sys
particle: "meteor"
- particlesPerSecond: 12
- particleDuration: 5000
+ emitRate: 12
+ lifeSpan: 5000
emitting: true
- acceleration: PointVector{ xVariation: 80; yVariation: 80; }
- particleSize: 15
- particleEndSize: 300
+ acceleration: PointDirection{ xVariation: 80; yVariation: 80; }
+ size: 15
+ endSize: 300
anchors.centerIn: parent
}
- SpriteParticle{
+ ImageParticle{
system: sys
particles: ["meteor"]
sprites:[Sprite{
@@ -168,11 +168,11 @@ Item {
}
}
- ColoredParticle{
+ ImageParticle{
z:0
system: sys
particles: ["exhaust"]
- image: "content/particle4.png"
+ source: "content/particle4.png"
color: "orange"
SequentialAnimation on color {
@@ -191,23 +191,23 @@ Item {
colorVariation: 0.2
}
- TrailEmitter{
+ Emitter{
id: trailsNormal2
system: sys
particle: "exhaust"
- particlesPerSecond: 300
- particleDuration: 500
+ emitRate: 300
+ lifeSpan: 500
y: holder.y
x: holder.x
- speed: PointVector{ xVariation: 40; yVariation: 40; }
+ speed: PointDirection{ xVariation: 40; yVariation: 40; }
speedFromMovement: 16
- acceleration: PointVector{ xVariation: 10; yVariation: 10; }
+ acceleration: PointDirection{ xVariation: 10; yVariation: 10; }
- particleSize: 4
- particleSizeVariation: 4
+ size: 4
+ sizeVariation: 4
}
}
diff --git a/examples/declarative/particles/asteroid/blackhole.qml b/examples/declarative/particles/asteroid/blackhole.qml
index 68d5835880..4a7ce02538 100644
--- a/examples/declarative/particles/asteroid/blackhole.qml
+++ b/examples/declarative/particles/asteroid/blackhole.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
id: root
@@ -65,41 +65,42 @@ Rectangle{
}
}
- TrailEmitter{
+ Emitter{
particle: "stars"
system: particles
- particlesPerSecond: 40
- particleDuration: 4000
+ emitRate: 40
+ lifeSpan: 4000
emitting: true
- particleSize: 30
- particleSizeVariation: 10
- speed: PointVector{ x: 220; xVariation: 40 }
+ size: 30
+ sizeVariation: 10
+ speed: PointDirection{ x: 220; xVariation: 40 }
height: parent.height
}
- TrailEmitter{
+ Emitter{
particle: "roids"
system: particles
- particlesPerSecond: 10
- particleDuration: 4000
+ emitRate: 10
+ lifeSpan: 4000
emitting: true
- particleSize: 30
- particleSizeVariation: 10
- speed: PointVector{ x: 220; xVariation: 40 }
+ size: 30
+ sizeVariation: 10
+ speed: PointDirection{ x: 220; xVariation: 40 }
height: parent.height
}
ParticleSystem{
id: particles
anchors.fill: parent
}
- ColoredParticle{
+ ImageParticle{
id: stars
particles: ["stars"]
system: particles
- image: "content/star.png"
+ source: "content/star.png"
color: "white"
colorVariation: 0.1
+ alpha: 0
}
- SpriteParticle{
+ ImageParticle{
id: roids
particles: ["roids"]
system: particles
@@ -112,20 +113,20 @@ Rectangle{
speedModifiesDuration: -0.1
}
}
- ColoredParticle{
+ ImageParticle{
id: shot
particles: ["shot"]
system: particles
- image: "content/star.png"
+ source: "content/star.png"
color: "#0FF06600"
colorVariation: 0.3
}
- ColoredParticle{
+ ImageParticle{
id: engine
particles: ["engine"]
system: particles
- image: "content/particle4.png"
+ source: "content/particle4.png"
color: "orange"
SequentialAnimation on color {
@@ -144,9 +145,11 @@ Rectangle{
colorVariation: 0.2
}
- GravitationalSingularity{
+ PointAttractor{
id: gs; x: root.width/2; y: root.height/2; strength: 4000000;
system: particles
+ physics: PointAttractor.Acceleration
+ proportionalToDistance: PointAttractor.Quadratic
}
Kill{
system: particles
@@ -166,27 +169,27 @@ Rectangle{
drag.axis: Drag.XandYAxis
drag.target: ship
}
- TrailEmitter{
+ Emitter{
particle: "engine"
system: particles
- particlesPerSecond: 200
- particleDuration: 1000
+ emitRate: 200
+ lifeSpan: 1000
emitting: true
- particleSize: 10
- particleEndSize: 4
- particleSizeVariation: 4
- speed: PointVector{ x: -128; xVariation: 32 }
+ size: 10
+ endSize: 4
+ sizeVariation: 4
+ speed: PointDirection{ x: -128; xVariation: 32 }
height: parent.height
width: 20
}
- TrailEmitter{
+ Emitter{
particle: "shot"
system: particles
- particlesPerSecond: 32
- particleDuration: 2000
+ emitRate: 32
+ lifeSpan: 2000
emitting: spacePressed
- particleSize: 40
- speed: PointVector{ x: 256; }
+ size: 40
+ speed: PointDirection{ x: 256; }
x: parent.width
y: parent.height/2
}
diff --git a/examples/declarative/particles/custom/blurparticles.qml b/examples/declarative/particles/custom/blurparticles.qml
new file mode 100644
index 0000000000..15da9ba9db
--- /dev/null
+++ b/examples/declarative/particles/custom/blurparticles.qml
@@ -0,0 +1,165 @@
+/****************************************************************************
+**
+** 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
+import QtQuick.Particles 2.0
+
+Rectangle{
+ color: "white"
+ width: 240
+ height: 360
+ ParticleSystem{
+ id: sys
+ }
+ Emitter{
+ system:sys
+ height: parent.height
+ emitRate: 1
+ lifeSpan: 12000
+ speed: PointDirection{x:20;}
+ size: 64
+ }
+ ShaderEffectSource{
+ id: theSource
+ sourceItem: theItem
+ hideSource: true
+ }
+ Image{
+ id: theItem
+ source: "content/smile.png"
+ }
+
+ CustomParticle{
+ system: sys
+ //TODO: Someway that you don't have to rewrite the basics for a simple addition
+ vertexShader:"
+ attribute highp vec2 vPos;
+ attribute highp vec2 vTex;
+ attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize
+ attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
+ attribute highp float r;
+
+ uniform highp mat4 qt_ModelViewProjectionMatrix;
+ uniform highp float timestamp;
+ uniform lowp float qt_Opacity;
+
+ varying highp vec2 fTex;
+ varying lowp float fFade;
+ varying lowp float fBlur;
+
+ void main() {
+ fTex = vTex;
+ highp float size = vData.z;
+ highp float endSize = vData.w;
+
+ highp float t = (timestamp - vData.x) / vData.y;
+
+ highp float currentSize = mix(size, endSize, t * t);
+
+ if (t < 0. || t > 1.)
+ currentSize = 0.;
+
+ highp vec2 pos = vPos
+ - currentSize / 2. + currentSize * vTex // adjust size
+ + vVec.xy * t * vData.y // apply speed vector..
+ + 0.5 * vVec.zw * pow(t * vData.y, 2.);
+
+ gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1);
+
+ highp float fadeIn = min(t * 10., 1.);
+ highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
+
+ fFade = fadeIn * fadeOut * qt_Opacity;
+ fBlur = max(0.2 * t, t * r);
+ }
+ "
+ property variant source: theSource
+ property variant blurred: ShaderEffectSource {
+ smooth: true
+ sourceItem: ShaderEffectItem {
+ width: theItem.width
+ height: theItem.height
+ property variant delta: Qt.size(0.0, 1.0 / height)
+ property variant source: ShaderEffectSource {
+ smooth: true
+ sourceItem: ShaderEffectItem {
+ width: theItem.width
+ height: theItem.height
+ property variant delta: Qt.size(1.0 / width, 0.0)
+ property variant source: theSource
+ fragmentShader: "
+ uniform sampler2D source;
+ uniform highp vec2 delta;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = 0.0538 * texture2D(source, qt_TexCoord0 - 3.182 * delta)
+ + 0.3229 * texture2D(source, qt_TexCoord0 - 1.364 * delta)
+ + 0.2466 * texture2D(source, qt_TexCoord0)
+ + 0.3229 * texture2D(source, qt_TexCoord0 + 1.364 * delta)
+ + 0.0538 * texture2D(source, qt_TexCoord0 + 3.182 * delta);
+ }"
+ }
+ }
+ fragmentShader: "
+ uniform sampler2D source;
+ uniform highp vec2 delta;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = 0.0538 * texture2D(source, qt_TexCoord0 - 3.182 * delta)
+ + 0.3229 * texture2D(source, qt_TexCoord0 - 1.364 * delta)
+ + 0.2466 * texture2D(source, qt_TexCoord0)
+ + 0.3229 * texture2D(source, qt_TexCoord0 + 1.364 * delta)
+ + 0.0538 * texture2D(source, qt_TexCoord0 + 3.182 * delta);
+ }"
+ }
+ }
+ fragmentShader: "
+ uniform sampler2D source;
+ uniform sampler2D blurred;
+ varying highp vec2 fTex;
+ varying highp float fBlur;
+ varying highp float fFade;
+ void main() {
+ gl_FragColor = mix(texture2D(source, fTex), texture2D(blurred, fTex), min(1.0,fBlur*3.0)) * fFade;
+ }"
+
+ }
+}
+
diff --git a/examples/declarative/particles/custom/content/particle.png b/examples/declarative/particles/custom/content/particle.png
new file mode 100644
index 0000000000..5c83896d22
--- /dev/null
+++ b/examples/declarative/particles/custom/content/particle.png
Binary files differ
diff --git a/examples/declarative/particles/custom/content/smile.png b/examples/declarative/particles/custom/content/smile.png
new file mode 100644
index 0000000000..3d66d72578
--- /dev/null
+++ b/examples/declarative/particles/custom/content/smile.png
Binary files differ
diff --git a/examples/declarative/particles/snow/snow3.qml b/examples/declarative/particles/custom/fireworks.qml
index 080bc4d1af..b73a5e234f 100644
--- a/examples/declarative/particles/snow/snow3.qml
+++ b/examples/declarative/particles/custom/fireworks.qml
@@ -39,42 +39,66 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
width: 360
- height: 540
- id: root
- ParticleSystem{ id: particles }
- SpriteParticle{
- system: particles
- sprites: Sprite{
- name: "snow"
- source: "content/flake-01.png"
- frames: 51
- duration: 40
+ height: 600
+ color: "black"
+ Component{
+ id: firework
+ Item{
+ id: container
+ width: 48
+ height: 48
+ Image{
+ width: 48
+ height: 48
+ id: img
+ source: "content/particle.png"
+ }
+ Timer{
+ interval: 1000 + 4000*Math.random()
+ running: true
+ repeat: false
+ onTriggered: {
+ img.visible = false;
+ emitter.burst(100);
+ }
+ }
+ Emitter{
+ anchors.centerIn: parent
+ id: emitter
+ system: syssy
+ particle: "works"
+ emitting: false
+ emitRate: 100
+ lifeSpan: 1000
+ //speed: AngledDirection{angle: 270; angleVariation:60; magnitudeVariation: 60; magnitude: 20}
+ speed: PointDirection{y:-60; yVariation: 80; xVariation: 80}
+ acceleration: PointDirection{y:100; yVariation: 20}
+ }
}
}
- Drift{
- system: particles
+ ParticleSystem{
anchors.fill: parent
- xDrift: 200
- }
- SpeedLimit{
- system: particles
- anchors.fill: parent
- speedLimit: 100
- }
- TrailEmitter{
- system: particles
- particlesPerSecond: 20
- particleDuration: 7000
- emitting: true
- speed: PointVector{ y:80; yVariation: 40; }
- acceleration: PointVector{ y: 4 }
- particleSize: 20
- particleSizeVariation: 10
- width: parent.width
- height: 40
+ id: syssy
+ Emitter{
+ particle: "fire"
+ width: parent.width
+ y: parent.height
+ emitRate: 2
+ lifeSpan: 6000
+ speed: PointDirection{y:-100}
+ }
+ ItemParticle{
+ particles: ["fire"]
+ delegate: firework
+ }
+ ImageParticle{
+ particles: ["works"]
+ source: "content/particle.png"
+ }
}
}
+
diff --git a/examples/declarative/particles/custom/shader.qml b/examples/declarative/particles/custom/shader.qml
new file mode 100644
index 0000000000..d83e7864c4
--- /dev/null
+++ b/examples/declarative/particles/custom/shader.qml
@@ -0,0 +1,84 @@
+import QtQuick 2.0
+import QtQuick.Particles 2.0
+
+ParticleSystem{
+ id: root
+ width: 1024
+ height: 768
+ Rectangle{
+ z: -1
+ anchors.fill: parent
+ color: "black"
+ Text{
+ anchors.bottom: parent.bottom
+ anchors.horizontalCenter: parent.horizontalCenter
+ font.pixelSize: 36
+ color: "white"
+ text: "It's all in the fragment shader."
+ }
+ }
+ Emitter{
+ emitRate: 400
+ lifeSpan: 8000
+ size: 24
+ sizeVariation: 16
+ speed: PointDirection{x: root.width/10; y: root.height/10;}
+ //acceleration: AngledDirection{angle:225; magnitude: root.width/36; angleVariation: 45; magnitudeVariation: 80}
+ acceleration: PointDirection{x: -root.width/40; y: -root.height/40; xVariation: -root.width/20; yVariation: -root.width/20}
+ }
+ CustomParticle{
+ //TODO: Someway that you don't have to rewrite the basics for a simple addition
+ vertexShader:"
+ attribute highp vec2 vPos;
+ attribute highp vec2 vTex;
+ attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize
+ attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
+ attribute highp float r;
+
+ uniform highp mat4 qt_ModelViewProjectionMatrix;
+ uniform highp float timestamp;
+ uniform lowp float qt_Opacity;
+
+ varying highp vec2 fTex;
+ varying lowp float fFade;
+ varying highp vec2 fPos;
+
+ void main() {
+ fTex = vTex;
+ highp float size = vData.z;
+ highp float endSize = vData.w;
+
+ highp float t = (timestamp - vData.x) / vData.y;
+
+ highp float currentSize = mix(size, endSize, t * t);
+
+ if (t < 0. || t > 1.)
+ currentSize = 0.;
+
+ highp vec2 pos = vPos
+ - currentSize / 2. + currentSize * vTex // adjust size
+ + vVec.xy * t * vData.y // apply speed vector..
+ + 0.5 * vVec.zw * pow(t * vData.y, 2.);
+
+ gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1);
+
+ highp float fadeIn = min(t * 20., 1.);
+ highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
+
+ fFade = fadeIn * fadeOut * qt_Opacity;
+ fPos = vec2(pos.x/1024., pos.y/768.);
+ }
+ "
+ fragmentShader: "
+ varying highp vec2 fPos;
+ varying lowp float fFade;
+ varying highp vec2 fTex;
+ void main() {//*2 because this generates dark colors mostly
+ highp vec2 circlePos = fTex*2.0 - vec2(1.0,1.0);
+ highp float dist = length(circlePos);
+ highp float circleFactor = max(min(1.0 - dist, 1.0), 0.0);
+ gl_FragColor = vec4(fPos.x*2.0 - fPos.y, fPos.y*2.0 - fPos.x, fPos.x*fPos.y*2.0, 0.0) * circleFactor * fFade;
+ }"
+
+ }
+}
diff --git a/examples/declarative/particles/exampleslauncher.qml b/examples/declarative/particles/exampleslauncher.qml
new file mode 100644
index 0000000000..354bcdf65a
--- /dev/null
+++ b/examples/declarative/particles/exampleslauncher.qml
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** 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
+import QtQuick.Particles 2.0
+import "launcherContent/launcher.js" as Util
+import "launcherContent"
+
+Rectangle{
+ color: "black"
+ width: 360
+ height: 600
+ Shell{
+ z: 1
+ id: shell
+ anchors.fill: parent
+ }
+ VisualDataModel{//TODO: Transitions between modes
+ id: vdm
+ model: [
+ "../spaceexplorer/spaceexplorer.qml",
+ "../snow/snow.qml",
+ "../asteroid/asteroid.qml",
+ "../asteroid/blackhole.qml",
+ "../custom/blurparticles.qml",
+ "../modelparticles/bubbles.qml",
+ "../modelparticles/gridsplosion.qml",
+ "../modelparticles/package.qml",
+ "../modelparticles/stream.qml",
+ "../allsmiles/plain.qml",
+ "../allsmiles/smile.qml",
+ "../allsmiles/smilefactory.qml",
+ "../allsmiles/ultraparticles.qml",
+ "../allsmiles/spriteparticles.qml",
+ "../allsmiles/spritestateparticles.qml",
+ "../allsmiles/spritevariedparticles.qml",
+ "../trails/velocityfrommotion.qml",
+ "../trails/fireballs.qml",
+ "../trails/list.qml",
+ "../trails/portal.qml",
+ "../trails/rainbow.qml",
+ "../trails/dynamicemitters.qml",
+ "../trails/overburst.qml",
+ "../trails/layered.qml",
+ "../trails/shimmer.qml",
+ "../trails/turbulence.qml",
+ "../../../../demos/declarative/samegame/samegame.qml",
+ "../../../../demos/declarative/plasmapatrol/plasmapatrol.qml",
+ "../../../../demos/declarative/flickr/flickr.qml"
+ ]
+ delegate: Rectangle{
+ color: "white"
+ width: 96
+ height: 96
+ Image{
+ width: 72
+ height: 72
+ anchors.centerIn: parent
+ source: Util.iconFromPath(modelData)
+ }
+ Text{
+ text: Util.nameFromPath(modelData)
+ anchors.bottom: parent.bottom
+ anchors.horizontalCenter: parent.horizontalCenter
+ font.pixelSize: 8
+ }
+ MouseArea{
+ anchors.fill: parent
+ onClicked: shell.setDemo(modelData)
+ }
+ }
+ }
+ GridView{
+ anchors.fill: parent
+ cellWidth: 120
+ cellHeight: 120
+ model: vdm
+ }
+}
diff --git a/examples/declarative/particles/trails/swarm.qml b/examples/declarative/particles/launcherContent/Button.qml
index 083f9e816d..a937b3bede 100644
--- a/examples/declarative/particles/trails/swarm.qml
+++ b/examples/declarative/particles/launcherContent/Button.qml
@@ -39,40 +39,35 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0 as QLP
-Rectangle{
- width: 200
- height: 200
- color: "black"
- QLP.ParticleSystem{ id: ps }
- QLP.ColoredParticle{
- system: ps
- particles: ["star1","star2"]
- anchors.fill: parent
- clip: true
- image: "content/star.png"
- }
- QLP.Swarm{
- system: ps
- leaders: ["star2"];
- anchors.fill: parent
- strength: 128
- }
- QLP.TrailEmitter{
- anchors.fill: parent
- system: ps
- particle: "star1"
- particlesPerSecond: 100
- particleDuration: 2000
+Rectangle {
+ id: container
+
+ property string text: "Button"
+ signal clicked
+
+ width: buttonLabel.width + 20; height: buttonLabel.height + 20
+ smooth: true
+ property color myCol: "#999999"
+ border { width: 1; color: Qt.darker(myCol) }
+ radius: 8
+
+ gradient: Gradient {
+ GradientStop {
+ position: 0.0
+ color: {
+ if (mouseArea.pressed)
+ return Qt.darker(myCol)
+ else
+ return Qt.lighter(myCol)
+ }
+ }
+ GradientStop { position: 1.0; color: myCol }
}
- QLP.TrailEmitter{
- anchors.fill: parent
- system: ps
- particle: "star2"
- particlesPerSecond: 0.4
- particleDuration: 10000
- particleSize: 64
- particleEndSize: 32
+
+ MouseArea { id: mouseArea; anchors.fill: parent; onClicked: container.clicked() }
+
+ Text {
+ id: buttonLabel; text: container.text; anchors.centerIn: container; color: "black"; font.pixelSize: 24
}
}
diff --git a/examples/declarative/particles/snow/snow2.qml b/examples/declarative/particles/launcherContent/Shell.qml
index c016ba2934..32b0cd624c 100644
--- a/examples/declarative/particles/snow/snow2.qml
+++ b/examples/declarative/particles/launcherContent/Shell.qml
@@ -39,36 +39,40 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
-Rectangle{
- width: 360
- height: 540
- ParticleSystem{ id: particles }
- SpriteParticle{
- system: particles
- Sprite{
- name: "snow"
- source: "content/flake-01.png"
- frames: 51
- duration: 40
+Loader{
+ id: ldr
+ visible: false
+ focus: visible
+ onVisibleChanged: source = ""
+ opacity: visible?1:0
+ Behavior on opacity{NumberAnimation{}}
+
+ function setDemo(str){
+ visible = true;
+ source = str;
+ }
+ Image{//TODO: Augment with PARTICLES
+ z: 1
+ source: "icons/close.png"
+ MouseArea{
+ anchors.fill: parent
+ onClicked: ldr.visible = false;
}
}
- Drift{
- system: particles
+ Rectangle{
+ z: -1
anchors.fill: parent
- xDrift: 400;
- }
- TrailEmitter{
- system: particles
- particlesPerSecond: 20
- particleDuration: 7000
- emitting: true
- speed: PointVector{ y:80; yVariation: 40; }
- acceleration: PointVector{ y: 4 }
- particleSize: 20
- particleSizeVariation: 10
- width: parent.width
- height: 100
+ color:"black"
+ Text{
+ color: "white"
+ anchors.centerIn: parent
+ text: ldr.Status == Loader.Error ? "Error :(" : "Loading..."
+ }
+ MouseArea{
+ id: graball
+ anchors.fill: parent
+ onClicked:;
+ }
}
}
diff --git a/examples/declarative/particles/launcherContent/icons/asteroid.png b/examples/declarative/particles/launcherContent/icons/asteroid.png
new file mode 100644
index 0000000000..77480c6f09
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/asteroid.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/blackhole.png b/examples/declarative/particles/launcherContent/icons/blackhole.png
new file mode 100644
index 0000000000..4bd8040c3b
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/blackhole.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/blurparticles.png b/examples/declarative/particles/launcherContent/icons/blurparticles.png
new file mode 100644
index 0000000000..7a247ae46e
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/blurparticles.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/close.png b/examples/declarative/particles/launcherContent/icons/close.png
new file mode 100644
index 0000000000..c37714ee8f
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/close.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/dynamicemitters.png b/examples/declarative/particles/launcherContent/icons/dynamicemitters.png
new file mode 100644
index 0000000000..0cdef9d21e
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/dynamicemitters.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/fireballs.png b/examples/declarative/particles/launcherContent/icons/fireballs.png
new file mode 100644
index 0000000000..39acf8b40d
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/fireballs.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/flickr.png b/examples/declarative/particles/launcherContent/icons/flickr.png
new file mode 100644
index 0000000000..4de2650280
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/flickr.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/gridsplosion.png b/examples/declarative/particles/launcherContent/icons/gridsplosion.png
new file mode 100644
index 0000000000..ec75453df6
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/gridsplosion.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/layered.png b/examples/declarative/particles/launcherContent/icons/layered.png
new file mode 100644
index 0000000000..a28e3c4f02
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/layered.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/list.png b/examples/declarative/particles/launcherContent/icons/list.png
new file mode 100644
index 0000000000..bc13263cff
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/list.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/overburst.png b/examples/declarative/particles/launcherContent/icons/overburst.png
new file mode 100644
index 0000000000..4ef0435991
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/overburst.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/package.png b/examples/declarative/particles/launcherContent/icons/package.png
new file mode 100644
index 0000000000..eba8951c26
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/package.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/plain.png b/examples/declarative/particles/launcherContent/icons/plain.png
new file mode 100644
index 0000000000..dd51498514
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/plain.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/plasmapatrol.png b/examples/declarative/particles/launcherContent/icons/plasmapatrol.png
new file mode 100644
index 0000000000..fda852b420
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/plasmapatrol.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/portal.png b/examples/declarative/particles/launcherContent/icons/portal.png
new file mode 100644
index 0000000000..9c1f910d0c
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/portal.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/rainbow.png b/examples/declarative/particles/launcherContent/icons/rainbow.png
new file mode 100644
index 0000000000..8841ea30f9
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/rainbow.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/remove.png b/examples/declarative/particles/launcherContent/icons/remove.png
new file mode 100644
index 0000000000..c37714ee8f
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/remove.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/samegame.png b/examples/declarative/particles/launcherContent/icons/samegame.png
new file mode 100644
index 0000000000..d00698264b
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/samegame.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/shimmer.png b/examples/declarative/particles/launcherContent/icons/shimmer.png
new file mode 100644
index 0000000000..0ff53196a6
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/shimmer.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/smile.png b/examples/declarative/particles/launcherContent/icons/smile.png
new file mode 100644
index 0000000000..f990e6c03e
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/smile.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/smilefactory.png b/examples/declarative/particles/launcherContent/icons/smilefactory.png
new file mode 100644
index 0000000000..78ea52790f
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/smilefactory.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/snow.png b/examples/declarative/particles/launcherContent/icons/snow.png
new file mode 100644
index 0000000000..d98e14b8ae
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/snow.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/spaceexplorer.png b/examples/declarative/particles/launcherContent/icons/spaceexplorer.png
new file mode 100644
index 0000000000..770584a0fa
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/spaceexplorer.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/spriteparticles.png b/examples/declarative/particles/launcherContent/icons/spriteparticles.png
new file mode 100644
index 0000000000..5603964939
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/spriteparticles.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/spritestateparticles.png b/examples/declarative/particles/launcherContent/icons/spritestateparticles.png
new file mode 100644
index 0000000000..dd01518ac4
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/spritestateparticles.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/spritevariedparticles.png b/examples/declarative/particles/launcherContent/icons/spritevariedparticles.png
new file mode 100644
index 0000000000..495bb6beee
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/spritevariedparticles.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/stream.png b/examples/declarative/particles/launcherContent/icons/stream.png
new file mode 100644
index 0000000000..a74f9a0340
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/stream.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/trails.png b/examples/declarative/particles/launcherContent/icons/trails.png
new file mode 100644
index 0000000000..0337ebcfd8
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/trails.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/turbulence.png b/examples/declarative/particles/launcherContent/icons/turbulence.png
new file mode 100644
index 0000000000..2b9446ea90
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/turbulence.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/ultraparticles.png b/examples/declarative/particles/launcherContent/icons/ultraparticles.png
new file mode 100644
index 0000000000..0d87eea427
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/ultraparticles.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/icons/velocityfrommotion.png b/examples/declarative/particles/launcherContent/icons/velocityfrommotion.png
new file mode 100644
index 0000000000..79baa08293
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/icons/velocityfrommotion.png
Binary files differ
diff --git a/examples/declarative/particles/launcherContent/launcher.js b/examples/declarative/particles/launcherContent/launcher.js
new file mode 100644
index 0000000000..e4fedd30d7
--- /dev/null
+++ b/examples/declarative/particles/launcherContent/launcher.js
@@ -0,0 +1,8 @@
+function nameFromPath(path){
+ var ret = path.split('/');
+ return ret[ret.length-1].split('.')[0];
+}
+function iconFromPath(path){
+ var ret = path.split('/');
+ return "launcherContent/icons/" + ret[ret.length-1].split('.')[0] + ".png";
+}
diff --git a/examples/declarative/particles/modelparticles/bubbles.qml b/examples/declarative/particles/modelparticles/bubbles.qml
index 80d03a9ea7..23f0b82d01 100644
--- a/examples/declarative/particles/modelparticles/bubbles.qml
+++ b/examples/declarative/particles/modelparticles/bubbles.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
import "../../modelviews/listview/content" as OtherDemo
import "content/script.js" as Script
import "content"
@@ -56,21 +56,22 @@ Item{
ParticleSystem{
id: sys;
}
- TrailEmitter{
+ Emitter{
system: sys
particle: "A"
width: parent.width/2
x: parent.width/4
y:parent.height
- speed: PointVector{ y: -64; yVariation: 16 }
- particlesPerSecond: 1
- particleDuration: 8000
+ speed: PointDirection{ y: -64; yVariation: 16 }
+ emitRate: 1
+ lifeSpan: 8000
}
- Drift{
+ Wander{
system: sys
- xDrift: 200
+ xVariance: 400
+ pace: 200
}
- DataParticle{
+ ModelParticle{
id: mp
z: 0
system: sys
diff --git a/examples/declarative/particles/modelparticles/gridsplosion.qml b/examples/declarative/particles/modelparticles/gridsplosion.qml
index d45ef392e0..db860125e5 100644
--- a/examples/declarative/particles/modelparticles/gridsplosion.qml
+++ b/examples/declarative/particles/modelparticles/gridsplosion.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
import "content"
Item{
@@ -48,13 +48,14 @@ Item{
height: 240
property bool inGrid: false
ParticleSystem{ id: sys }
- TrailEmitter{
+ Emitter{
system: sys
id: burster;
emitting: false
- particlesPerSecond: 1000
- particleDuration: 500
- speed: PointVector{xVariation: 400; yVariation: 400}
+ emitRate: 1000
+ lifeSpan: 50000
+ emitCap: 100;
+ speed: PointDirection{xVariation: 400; yVariation: 400}
anchors.centerIn: parent
Timer{
interval: 1000
@@ -69,9 +70,9 @@ Item{
onTriggered: {inGrid = true;}// sys.running = false;}
}
}
- ColoredParticle{
+ ImageParticle{
system: sys
- image: "../trails/content/particle.png"
+ source: "../trails/content/particle.png"
color: "black"
colorVariation: 0.0
}
@@ -80,17 +81,14 @@ Item{
width: 120
height: 120
}
- DataParticle{
+ ModelParticle{
system: sys
model: theModel.parts.particles
+ fade: false
}
Friction{
system: sys
- factor: 1
- }
- Stasis{
- system: sys
- targetLife: 400
+ factor: 5
}
VisualDataModel{
id: theModel
diff --git a/examples/declarative/particles/modelparticles/package.qml b/examples/declarative/particles/modelparticles/package.qml
index d5c104b480..0aa8903270 100644
--- a/examples/declarative/particles/modelparticles/package.qml
+++ b/examples/declarative/particles/modelparticles/package.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
import "content"
Rectangle {
@@ -69,7 +69,7 @@ Rectangle {
width: 200; height:200
model: visualModel.parts.list
}
- DataParticle{
+ ModelParticle{
x: 200; width: 200; height:200
model: visualModel.parts.grid
system: sys
@@ -80,12 +80,12 @@ Rectangle {
id: sys
anchors.fill: parent
}
- TrailEmitter{
+ Emitter{
system: sys
width: 100
x: 50
- speed: PointVector{ y: 40 }
- particleDuration: 5000
- particlesPerSecond: 1.6
+ speed: PointDirection{ y: 40 }
+ lifeSpan: 5000
+ emitRate: 1.6
}
}
diff --git a/examples/declarative/particles/modelparticles/stream.qml b/examples/declarative/particles/modelparticles/stream.qml
index 0ad807bc7b..5c7a6f7fc4 100644
--- a/examples/declarative/particles/modelparticles/stream.qml
+++ b/examples/declarative/particles/modelparticles/stream.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
import "content/script.js" as Script
import "content"
@@ -68,15 +68,15 @@ Item{
overwrite: false
startTime: 12000//Doesn't actually work with the loading time though...
}
- TrailEmitter{
+ Emitter{
id: emitter
system: sys
height: parent.height - 132/2
x: -132/2
y: 132/2
- speed: PointVector{ x: 32; xVariation: 8 }
- particlesPerSecond: 0.5
- particleDuration: 120000 //TODO: A -1 or something which does 'infinite'? (but need disable fade first)
+ speed: PointDirection{ x: 32; xVariation: 8 }
+ emitRate: 0.5
+ lifeSpan: 120000 //TODO: A -1 or something which does 'infinite'? (but need disable fade first)
particle: "photos"
}
Kill{
@@ -85,10 +85,10 @@ Item{
height: parent.height
width: 1000
}
- ColoredParticle{
+ ImageParticle{
system: sys
particles: ["fireworks"]
- image: "../trails/content/star.png"
+ source: "../trails/content/star.png"
color: "lightsteelblue"
alpha: 0
colorVariation: 0
@@ -125,7 +125,7 @@ Item{
}
property Item alertItem;
function alert(){
- resetter.active = false
+ //resetter.active = false
force.active = true;
alertItem = alertDelegate.createObject(root);
alertItem.x = root.width/2 - alertItem.width/2
@@ -142,34 +142,30 @@ Item{
interval: 800
onTriggered: {
force.active = false
- resetter.active = true;
+ //resetter.active = true;
mp.take(alertItem, true);
centerEmitter.burst(1);
}
}
- Attractor{
+ PointAttractor{
id: force
system: sys
x: root.width/2
y: root.height/2
- strength: -30000
+ strength: -10000
active: false
anchors.centerIn: parent
width: parent.width/2
height: parent.height/2
particles:["photos"]
+ physics: PointAttractor.Position
}
- Reset{
- id: resetter
- system: sys
- particles:["photos"]
- }
- TrailEmitter{
+ Emitter{
id: centerEmitter
- speed: PointVector{ x: 32; xVariation: 8;}
- particlesPerSecond: 0.5
- particleDuration: 12000 //TODO: A -1 or something which does 'infinite'? (but need disable fade first)
- maxParticles: 20
+ speed: PointDirection{ x: 32; xVariation: 8;}
+ emitRate: 0.5
+ lifeSpan: 12000 //TODO: A -1 or something which does 'infinite'? (but need disable fade first)
+ emitCap: 20
particle: "photos"
system: sys
anchors.centerIn: parent
@@ -177,22 +173,22 @@ Item{
//TODO: Zoom in effect
}
- TrailEmitter{
+ Emitter{
id: spawnFireworks
particle: "fireworks"
system: sys
- maxParticles: 400
- particlesPerSecond: 400
- particleDuration: 2800
+ emitCap: 400
+ emitRate: 400
+ lifeSpan: 2800
x: parent.width/2
y: parent.height/2 - 64
width: 8
height: 8
emitting: false
- particleSize: 32
- particleEndSize: 8
- speed: AngleVector{ magnitude: 160; magnitudeVariation: 120; angleVariation: 90; angle: 270 }
- acceleration: PointVector{ y: 160 }
+ size: 32
+ endSize: 8
+ speed: AngledDirection{ 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
diff --git a/examples/declarative/particles/snow/snow.qml b/examples/declarative/particles/snow/snow.qml
index 25d2e1468b..ea2de17046 100644
--- a/examples/declarative/particles/snow/snow.qml
+++ b/examples/declarative/particles/snow/snow.qml
@@ -39,15 +39,17 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
+import "content"
+import "../launcherContent" as UI
Rectangle{
width: 360
height: 540
ParticleSystem { id: particles }
- SpriteParticle {
+ ImageParticle {
system: particles
- Sprite{
+ sprites: Sprite{
name: "snow"
source: "content/flake-01.png"
frames: 51
@@ -55,21 +57,38 @@ Rectangle{
}
}
Wander {
+ id: wanderer
system: particles
anchors.fill: parent
- xVariance: 40;
- pace: 40;
+ xVariance: 360/(wanderer.physics+1);
+ pace: 100*(wanderer.physics+1);
}
- TrailEmitter {
+ Emitter {
system: particles
- particlesPerSecond: 20
- particleDuration: 7000
+ emitRate: 20
+ lifeSpan: 7000
emitting: true
- speed: PointVector{ y:80; yVariation: 40; }
- acceleration: PointVector{ y: 4 }
- particleSize: 20
- particleSizeVariation: 10
+ speed: PointDirection{ y:80; yVariation: 40; }
+ acceleration: PointDirection{ y: 4 }
+ size: 20
+ sizeVariation: 10
width: parent.width
height: 100
}
+ Row{
+ anchors.bottom: parent.bottom
+ anchors.horizontalCenter: parent.horizontalCenter
+ UI.Button{
+ text:"dx/dt"
+ onClicked: wanderer.physics = Wander.Position;
+ }
+ UI.Button{
+ text:"dv/dt"
+ onClicked: wanderer.physics = Wander.Velocity;
+ }
+ UI.Button{
+ text:"da/dt"
+ onClicked: wanderer.physics = Wander.Acceleration;
+ }
+ }
}
diff --git a/examples/declarative/particles/spaceexplorer/spaceexplorer.qml b/examples/declarative/particles/spaceexplorer/spaceexplorer.qml
index 091ca0a8b5..1bb3cdae02 100644
--- a/examples/declarative/particles/spaceexplorer/spaceexplorer.qml
+++ b/examples/declarative/particles/spaceexplorer/spaceexplorer.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
import "content/helpers.js" as Helpers
Rectangle{
@@ -75,22 +75,22 @@ Rectangle{
property bool fakeMoving: false
property real fakeMovementDir: 0
- TrailEmitter{
+ Emitter{
particle: "stars2"
system: background
- particlesPerSecond: 60
- particleDuration: 4000
+ emitRate: 60
+ lifeSpan: 4000
emitting: true
- particleSize: 10
- particleSizeVariation: 10
+ size: 10
+ sizeVariation: 10
anchors.fill: parent
}
ParticleSystem{ id: background }
- ColoredParticle{
+ ImageParticle{
particles: ["stars2"]
system: background
anchors.fill: parent
- image: "content/star.png"
+ source: "content/star.png"
color: "white"
colorVariation: 0.1
}
@@ -197,29 +197,29 @@ Rectangle{
ParticleSystem{ id: foreground }
- ColoredParticle{
+ ImageParticle{
particles: ["stars"]
anchors.fill: parent
system: foreground
- image: "content/star.png"
+ source: "content/star.png"
color: "white"
colorVariation: 0.1
}
- ColoredParticle{
+ ImageParticle{
particles: ["shot"]
anchors.fill: parent
system: foreground
- image: "content/star.png"
+ source: "content/star.png"
color: "orange"
colorVariation: 0.3
}
- ColoredParticle{
+ ImageParticle{
id: engine
particles: ["engine"]
anchors.fill: parent
system: foreground
- image: "content/particle4.png"
+ source: "content/particle4.png"
color: "orange"
SequentialAnimation on color {
@@ -238,30 +238,31 @@ Rectangle{
colorVariation: 0.2
}
- SpriteParticle{
+ ImageParticle{
particles: ["powerups"]
anchors.fill: parent
system: foreground
- Sprite{
+ sprites:[Sprite{
name: "norm"
source: "content/powerupScore.png"
frames: 35
duration: 40
to: {"norm":1, "got":0}
- }
+ },
Sprite{
name: "got"
source: "content/powerupScore_got.png"
frames: 22
duration: 40
to: {"null":1}
- }
+ },
Sprite{
name: "null"
source: "content/powerupScore_gone.png"
frames: 1
duration: 1000
}
+ ]
}
SpriteGoal{
x: rocket.x - 30
@@ -273,8 +274,9 @@ Rectangle{
onAffected: if(!gameOver) score += 1000
system: foreground
}
- GravitationalSingularity{
+ PointAttractor{
id: gs1; x: vorteX; y: vorteY; strength: 800000;
+ proportionalToDistance: PointAttractor.Quadratic;
system: foreground
}
Kill{
@@ -285,8 +287,9 @@ Rectangle{
system: foreground
}
- GravitationalSingularity{
+ PointAttractor{
id: gs2; x: vorteX2; y: vorteY2; strength: 800000;
+ proportionalToDistance: PointAttractor.Quadratic;
system: foreground
}
Kill{
@@ -297,8 +300,9 @@ Rectangle{
system: foreground
}
- GravitationalSingularity{
+ PointAttractor{
id: gs3; x: vorteX3; y: vorteY3; strength: 800000;
+ proportionalToDistance: PointAttractor.Quadratic;
system: foreground
}
Kill{
@@ -308,8 +312,9 @@ Rectangle{
height: holeSize * 2
system: foreground
}
- GravitationalSingularity{
+ PointAttractor{
id: gs4; x: vorteX4; y: vorteY4; strength: 800000;
+ proportionalToDistance: PointAttractor.Quadratic;
system: foreground
}
Kill{
@@ -319,24 +324,24 @@ Rectangle{
height: holeSize * 2
system: foreground
}
- TrailEmitter{
+ Emitter{
particle: "powerups"
system: foreground
- particlesPerSecond: 1
- particleDuration: 6000
+ emitRate: 1
+ lifeSpan: 6000
emitting: !gameOver
- particleSize: 60
- particleSizeVariation: 10
+ size: 60
+ sizeVariation: 10
anchors.fill: parent
}
- TrailEmitter{
+ Emitter{
particle: "stars"
system: foreground
- particlesPerSecond: 40
- particleDuration: 4000
+ emitRate: 40
+ lifeSpan: 4000
emitting: !gameOver
- particleSize: 30
- particleSizeVariation: 10
+ size: 30
+ sizeVariation: 10
anchors.fill: parent
}
SpriteImage{
@@ -374,16 +379,16 @@ Rectangle{
drag.axis: Drag.XandYAxis
drag.target: rocket
},
- TrailEmitter{
+ Emitter{
system: foreground
particle: "engine"
- particlesPerSecond: 100
- particleDuration: 1000
+ emitRate: 100
+ lifeSpan: 1000
emitting: !gameOver
- particleSize: 10
- particleEndSize: 4
- particleSizeVariation: 4
- speed: PointVector{
+ size: 10
+ endSize: 4
+ sizeVariation: 4
+ speed: PointDirection{
x: -128 * Math.cos(rocket.rotation * (Math.PI / 180))
y: -128 * Math.sin(rocket.rotation * (Math.PI / 180))
}
@@ -392,14 +397,14 @@ Rectangle{
width: 4
},
- TrailEmitter{
+ Emitter{
system: foreground
particle: "shot"
- particlesPerSecond: 16
- particleDuration: 1600
+ emitRate: 16
+ lifeSpan: 1600
emitting: !gameOver && shoot
- particleSize: 40
- speed: PointVector{
+ size: 40
+ speed: PointDirection{
x: 256 * Math.cos(rocket.rotation * (Math.PI / 180))
y: 256 * Math.sin(rocket.rotation * (Math.PI / 180))
}
diff --git a/examples/declarative/particles/trails/dynamicemitters.qml b/examples/declarative/particles/trails/dynamicemitters.qml
index 8ea0272d94..f338c204db 100644
--- a/examples/declarative/particles/trails/dynamicemitters.qml
+++ b/examples/declarative/particles/trails/dynamicemitters.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
id: root
@@ -49,26 +49,26 @@ Rectangle{
ParticleSystem{
id: sys
}
- ColoredParticle{
+ ImageParticle{
system: sys
- image: "content/particle.png"
+ source: "content/particle.png"
color: "white"
colorVariation: 1.0
alpha: 0.1
}
Component{
id: emitterComp
- TrailEmitter{
+ Emitter{
id: container
- TrailEmitter{
+ Emitter{
id: emitMore
system: sys
emitting: true
- particlesPerSecond: 128
- particleDuration: 600
- particleSize: 16
- particleEndSize: 8
- speed: AngleVector{angleVariation:360; magnitude: 60}
+ emitRate: 128
+ lifeSpan: 600
+ size: 16
+ endSize: 8
+ speed: AngledDirection{angleVariation:360; magnitude: 60}
}
property int life: 2600
@@ -81,10 +81,10 @@ Rectangle{
}
system: sys
emitting: true
- particlesPerSecond: 64
- particleDuration: 600
- particleSize: 24
- particleEndSize: 8
+ emitRate: 32
+ lifeSpan: 600
+ size: 24
+ endSize: 8
NumberAnimation on x{
id: xAnim;
to: targetX
@@ -107,12 +107,12 @@ Rectangle{
MouseArea{
anchors.fill: parent
onClicked:{
- for(var i=0; i<16; i++){
+ for(var i=0; i<8; i++){
var obj = emitterComp.createObject(root);
obj.x = mouse.x
obj.y = mouse.y
- obj.targetX = Math.random() * 640
- obj.targetY = Math.random() * 480
+ obj.targetX = Math.random() * 240 - 120 + obj.x
+ obj.targetY = Math.random() * 240 - 120 + obj.y
obj.life = Math.round(Math.random() * 2400) + 200
obj.go();
}
diff --git a/examples/declarative/particles/trails/fireballs.qml b/examples/declarative/particles/trails/fireballs.qml
index 116a2334dc..4cc2eacc25 100644
--- a/examples/declarative/particles/trails/fireballs.qml
+++ b/examples/declarative/particles/trails/fireballs.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle {
id: root
@@ -52,35 +52,35 @@ Rectangle {
}
/*
- ColoredParticle{
+ ImageParticle{
id: fireball
anchors.fill: parent
particles: ["E"]
system: particles
- image: "content/particleA.png"
+ source: "content/particleA.png"
colorVariation: 0.2
color: "#00ff400f"
}
*/
- ColoredParticle{
+ ImageParticle{
id: smoke
system: particles
anchors.fill: parent
particles: ["A", "B"]
- image: "content/particle.png"
+ source: "content/particle.png"
colorVariation: 0
color: "#00111111"
}
- ColoredParticle{
+ ImageParticle{
id: flame
anchors.fill: parent
system: particles
particles: ["C", "D"]
- image: "content/particle.png"
+ source: "content/particle.png"
colorVariation: 0.1
color: "#00ff400f"
}
- TrailEmitter{
+ Emitter{
id: fire
system: particles
particle: "C"
@@ -88,15 +88,15 @@ Rectangle {
y: parent.height
width: parent.width
- particlesPerSecond: 350
- particleDuration: 3500
+ emitRate: 350
+ lifeSpan: 3500
- acceleration: PointVector{ y: -17; xVariation: 3 }
- speed: PointVector{xVariation: 3}
+ acceleration: PointDirection{ y: -17; xVariation: 3 }
+ speed: PointDirection{xVariation: 3}
- particleSize: 24
- particleSizeVariation: 8
- particleEndSize: 4
+ size: 24
+ sizeVariation: 8
+ endSize: 4
}
FollowEmitter{
id: fireSmoke
@@ -106,15 +106,15 @@ Rectangle {
width: root.width
height: root.height - 68
- particlesPerParticlePerSecond: 1
- particleDuration: 2000
+ emitRatePerParticle: 1
+ lifeSpan: 2000
- speed: PointVector{y:-17*6; yVariation: -17; xVariation: 3}
- acceleration: PointVector{xVariation: 3}
+ speed: PointDirection{y:-17*6; yVariation: -17; xVariation: 3}
+ acceleration: PointDirection{xVariation: 3}
- particleSize: 36
- particleSizeVariation: 8
- particleEndSize: 16
+ size: 36
+ sizeVariation: 8
+ endSize: 16
}
FollowEmitter{
id: fireballFlame
@@ -123,14 +123,14 @@ Rectangle {
particle: "D"
follow: "E"
- particlesPerParticlePerSecond: 120
- particleDuration: 180
- emissionWidth: 8
- emissionHeight: 8
+ emitRatePerParticle: 120
+ lifeSpan: 180
+ emitWidth: 8
+ emitHeight: 8
- particleSize: 16
- particleSizeVariation: 4
- particleEndSize: 4
+ size: 16
+ sizeVariation: 4
+ endSize: 4
}
FollowEmitter{
@@ -140,19 +140,19 @@ Rectangle {
particle: "A"
follow: "E"
- particlesPerParticlePerSecond: 128
- particleDuration: 2400
- emissionWidth: 16
- emissionHeight: 16
+ emitRatePerParticle: 128
+ lifeSpan: 2400
+ emitWidth: 16
+ emitHeight: 16
- speed: PointVector{yVariation: 16; xVariation: 16}
- acceleration: PointVector{y: -16}
+ speed: PointDirection{yVariation: 16; xVariation: 16}
+ acceleration: PointDirection{y: -16}
- particleSize: 24
- particleSizeVariation: 8
- particleEndSize: 8
+ size: 24
+ sizeVariation: 8
+ endSize: 8
}
- TrailEmitter{
+ Emitter{
id: balls
system: particles
particle: "E"
@@ -160,14 +160,14 @@ Rectangle {
y: parent.height
width: parent.width
- particlesPerSecond: 2
- particleDuration: 7000
+ emitRate: 2
+ lifeSpan: 7000
- speed: PointVector{y:-17*4*2; xVariation: 6*6}
- acceleration: PointVector{y: 17*2; xVariation: 6*6}
+ speed: PointDirection{y:-17*4*2; xVariation: 6*6}
+ acceleration: PointDirection{y: 17*2; xVariation: 6*6}
- particleSize: 12
- particleSizeVariation: 4
+ size: 12
+ sizeVariation: 4
}
}
diff --git a/examples/declarative/particles/trails/layered.qml b/examples/declarative/particles/trails/layered.qml
index 38eb8e67dc..d4a823b556 100644
--- a/examples/declarative/particles/trails/layered.qml
+++ b/examples/declarative/particles/trails/layered.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
id: root
@@ -55,30 +55,26 @@ Rectangle{
id: sys
startTime: 4000
}
- TrailEmitter{
+ Emitter{
system: sys
y:root.height + 20
width: root.width
- particlesPerSecond: 200
- particleDuration: 4000
- speed: PointVector{ y: -120; }
+ emitRate: 200
+ lifeSpan: 4000
+ speed: PointDirection{ y: -120; }
}
- SpriteParticle{
+ ImageParticle{
system: sys
visible: !cloneMode
- Sprite{
- source: "content/particle2.png"
- }
+ source: "content/particle2.png"
}
- SpriteParticle{
+ ImageParticle{
system: sys
visible: cloneMode
z: 0
- Sprite{
- source: "content/particle3.png"
- }
+ source: "content/particle3.png"
}
- SpriteParticle{
+ ImageParticle{
system: sys
clip: true
visible: cloneMode
@@ -86,8 +82,6 @@ Rectangle{
height: 240
width: root.width
z: 1
- Sprite{
- source: "content/particle.png"
- }
+ source: "content/particle.png"
}
}
diff --git a/examples/declarative/particles/trails/list.qml b/examples/declarative/particles/trails/list.qml
index 2ab579f126..7e8fb44003 100644
--- a/examples/declarative/particles/trails/list.qml
+++ b/examples/declarative/particles/trails/list.qml
@@ -43,18 +43,18 @@
// highlight bar is moved between items. + Particles.
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
import "content"
Rectangle {
width: 200; height: 300
color: "black"
ParticleSystem{ id: particles }
- ColoredParticle{
+ ImageParticle{
anchors.fill: parent
system: particles
z: 10
- image: "content/star.png"
+ source: "content/star.png"
color: "white"
colorVariation: 0.0
}
@@ -92,14 +92,14 @@ Rectangle {
y: listView.currentItem.y;
//Behavior on y { SpringAnimation { spring: 2; damping: 0.1 } }
Behavior on y { NumberAnimation {id: anim} }
- TrailEmitter{
+ Emitter{
anchors.fill: parent
system: particles;
emitting: anim.running
- particlesPerSecond: 600
- particleDuration: 600
- particleSize: 16
- particleEndSize: 8
+ emitRate: 600
+ lifeSpan: 600
+ size: 16
+ endSize: 8
}
}
}
diff --git a/examples/declarative/particles/trails/overburst.qml b/examples/declarative/particles/trails/overburst.qml
index 6ca15972a4..c3129a1d72 100644
--- a/examples/declarative/particles/trails/overburst.qml
+++ b/examples/declarative/particles/trails/overburst.qml
@@ -39,34 +39,34 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
color: "black"
width: 360
height: 540
ParticleSystem{ id: sys }
- ColoredParticle{
+ ImageParticle{
system: sys
id: cp
- image: "content/particle.png"
+ source: "content/particle.png"
colorVariation: 0.4
color: "#000000FF"
}
- TrailEmitter{
+ Emitter{
//burst on click
id: bursty
system: sys
emitting: ma.pressed
x: ma.mouseX
y: ma.mouseY
- particlesPerSecond: 16000
- particleDuration: 1000
- maxParticles: 4000
- acceleration: AngleVector{angleVariation: 360; magnitude: 360; }
- particleSize: 8
- particleEndSize: 16
- particleSizeVariation: 4
+ emitRate: 16000
+ lifeSpan: 1000
+ emitCap: 4000
+ acceleration: AngledDirection{angleVariation: 360; magnitude: 360; }
+ size: 8
+ endSize: 16
+ sizeVariation: 4
}
MouseArea{
anchors.fill: parent
diff --git a/examples/declarative/particles/trails/portal.qml b/examples/declarative/particles/trails/portal.qml
index dba2e59513..8cf323b0f5 100644
--- a/examples/declarative/particles/trails/portal.qml
+++ b/examples/declarative/particles/trails/portal.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
id: root
@@ -54,51 +54,51 @@ Rectangle{
id: particles
startTime: 2000
}
- ColoredParticle{
+ ImageParticle{
particles: ["center","edge"]
anchors.fill: parent
system: particles
- image: "content/particle.png"
+ source: "content/particle.png"
colorVariation: 0.1
color: "#009999FF"
}
- TrailEmitter{
+ Emitter{
anchors.fill: parent
particle: "center"
system: particles
- particlesPerSecond: 200
- particleDuration: 2000
+ emitRate: 200
+ lifeSpan: 2000
emitting: true
- particleSize: 20
- particleSizeVariation: 2
- particleEndSize: 0
- shape: Ellipse{fill: false}
- speed: DirectedVector{
+ size: 20
+ sizeVariation: 2
+ endSize: 0
+ shape: EllipseShape{fill: false}
+ speed: TargetedDirection{
targetX: root.width/2
targetY: root.height/2
proportionalMagnitude: true
magnitude: 0.5
}
}
- TrailEmitter{
+ Emitter{
anchors.fill: parent
particle: "edge"
system: particles
- particlesPerSecond: 4000
- particleDuration: 2000
+ emitRate: 4000
+ lifeSpan: 2000
emitting: true
- particleSize: 20
- particleSizeVariation: 2
- particleEndSize: 0
- shape: Ellipse{fill: false}
- speed: DirectedVector{
+ size: 20
+ sizeVariation: 2
+ endSize: 0
+ shape: EllipseShape{fill: false}
+ speed: TargetedDirection{
targetX: root.width/2
targetY: root.height/2
proportionalMagnitude: true
magnitude: 0.1
magnitudeVariation: 0.1
}
- acceleration: DirectedVector{
+ acceleration: TargetedDirection{
targetX: root.width/2
targetY: root.height/2
targetVariation: 200
diff --git a/examples/declarative/particles/trails/rainbow.qml b/examples/declarative/particles/trails/rainbow.qml
index 6c64929668..c0b61bf89e 100644
--- a/examples/declarative/particles/trails/rainbow.qml
+++ b/examples/declarative/particles/trails/rainbow.qml
@@ -38,7 +38,7 @@
**
****************************************************************************/
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
import QtQuick 2.0
Rectangle {
@@ -48,19 +48,19 @@ Rectangle {
color: "black"
ParticleSystem{ id: particles }
- ColoredParticle{
+ ImageParticle{
system: particles
colorVariation: 0.5
alpha: 0
- image: "content/particle.png"
+ source: "content/particle.png"
colorTable: "content/colortable.png"
sizeTable: "content/colortable.png"
}
- TrailEmitter{
+ Emitter{
system: particles
- particlesPerSecond: 500
- particleDuration: 2000
+ emitRate: 500
+ lifeSpan: 2000
y: root.height / 2 + Math.sin(t * 2) * root.height * 0.3
x: root.width / 2 + Math.cos(t) * root.width * 0.3
@@ -72,11 +72,11 @@ Rectangle {
speedFromMovement: 20
- speed: PointVector{ xVariation: 5; yVariation: 5;}
- acceleration: PointVector{ xVariation: 5; yVariation: 5;}
+ speed: PointDirection{ xVariation: 5; yVariation: 5;}
+ acceleration: PointDirection{ xVariation: 5; yVariation: 5;}
- particleSize: 16
- //particleEndSize: 8
- //particleSizeVariation: 8
+ size: 16
+ //endSize: 8
+ //sizeVariation: 8
}
}
diff --git a/examples/declarative/particles/trails/shimmer.qml b/examples/declarative/particles/trails/shimmer.qml
index 06f599d97a..2bd4f6980f 100644
--- a/examples/declarative/particles/trails/shimmer.qml
+++ b/examples/declarative/particles/trails/shimmer.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
width: 360
@@ -53,21 +53,21 @@ Rectangle{
id: particles
running: false
}
- ColoredParticle{
+ ImageParticle{
anchors.fill: parent
system: particles
- image: "content/star.png"
+ source: "content/star.png"
sizeTable: "content/sparkleSize.png"
alpha: 0
colorVariation: 0.6
}
- TrailEmitter{
+ Emitter{
anchors.fill: parent
system: particles
- particlesPerSecond: 2000
- particleDuration: 2000
+ emitRate: 2000
+ lifeSpan: 2000
emitting: true
- particleSize: 30
- particleSizeVariation: 10
+ size: 30
+ sizeVariation: 10
}
}
diff --git a/examples/declarative/particles/trails/trails.qml b/examples/declarative/particles/trails/trails.qml
index 58d369c8d5..689de4eb41 100644
--- a/examples/declarative/particles/trails/trails.qml
+++ b/examples/declarative/particles/trails/trails.qml
@@ -39,44 +39,44 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
color: "black"
width: 360
height: 540
ParticleSystem{ id: sys }
- ColoredParticle{
+ ImageParticle{
system: sys
id: cp
- image: "content/particle.png"
+ source: "content/particle.png"
color: "#00FFFFFF"
colorVariation: 0.4
}
- TrailEmitter{
+ Emitter{
//burst on click
id: bursty
system: sys
emitting: false
- particlesPerSecond: 2000
- particleDuration: 500
- acceleration: AngleVector{ angle: 90; angleVariation: 360; magnitude: 640; }
- particleSize: 8
- particleEndSize: 16
- particleSizeVariation: 4
+ emitRate: 2000
+ lifeSpan: 500
+ acceleration: AngledDirection{ angle: 90; angleVariation: 360; magnitude: 640; }
+ size: 8
+ endSize: 16
+ sizeVariation: 4
}
- TrailEmitter{
+ Emitter{
system: sys
speedFromMovement: 4.0
emitting: ma.pressed
x: ma.mouseX
y: ma.mouseY
- particlesPerSecond: 400
- particleDuration: 2000
- acceleration: AngleVector{ angle: 90; angleVariation: 22; magnitude: 32; }
- particleSize: 8
- particleEndSize: 16
- particleSizeVariation: 8
+ emitRate: 400
+ lifeSpan: 2000
+ acceleration: AngledDirection{ angle: 90; angleVariation: 22; magnitude: 32; }
+ size: 8
+ endSize: 16
+ sizeVariation: 8
}
MouseArea{
id: ma
diff --git a/examples/declarative/particles/trails/turbulence.qml b/examples/declarative/particles/trails/turbulence.qml
index 7da50464c2..6159b3e9c9 100644
--- a/examples/declarative/particles/trails/turbulence.qml
+++ b/examples/declarative/particles/trails/turbulence.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle{
width: 360
@@ -66,32 +66,32 @@ Rectangle{
frequency: 64
gridSize: 16
}
- ColoredParticle{
+ ImageParticle{
particles: ["smoke"]
system: ps
- image: "content/particle.png"
+ source: "content/particle.png"
color: "#11111111"
colorVariation: 0
}
- ColoredParticle{
+ ImageParticle{
particles: ["flame"]
system: ps
- image: "content/particle.png"
+ source: "content/particle.png"
color: "#11ff400f"
colorVariation: 0.1
}
- TrailEmitter{
+ Emitter{
anchors.centerIn: parent
system: ps
particle: "flame"
- particlesPerSecond: 120
- particleDuration: 1200
- particleSize: 20
- particleEndSize: 10
- particleSizeVariation: 10
- acceleration: PointVector{ y: -40 }
- speed: AngleVector{ angle: 270; magnitude: 20; angleVariation: 22; magnitudeVariation: 5 }
+ emitRate: 120
+ lifeSpan: 1200
+ size: 20
+ endSize: 10
+ sizeVariation: 10
+ acceleration: PointDirection{ y: -40 }
+ speed: AngledDirection{ angle: 270; magnitude: 20; angleVariation: 22; magnitudeVariation: 5 }
}
FollowEmitter{
id: smoke1
@@ -101,14 +101,14 @@ Rectangle{
particle: "smoke"
follow: "flame"
- particlesPerParticlePerSecond: 4
- particleDuration: 2400
- particleDurationVariation: 400
- particleSize: 16
- particleEndSize: 8
- particleSizeVariation: 8
- acceleration: PointVector{ y: -40 }
- speed: AngleVector{ angle: 270; magnitude: 40; angleVariation: 22; magnitudeVariation: 5 }
+ emitRatePerParticle: 4
+ lifeSpan: 2400
+ lifeSpanVariation: 400
+ size: 16
+ endSize: 8
+ sizeVariation: 8
+ acceleration: PointDirection{ y: -40 }
+ speed: AngledDirection{ angle: 270; magnitude: 40; angleVariation: 22; magnitudeVariation: 5 }
}
FollowEmitter{
id: smoke2
@@ -118,12 +118,12 @@ Rectangle{
particle: "smoke"
follow: "flame"
- particlesPerParticlePerSecond: 1
- particleDuration: 2400
- particleSize: 36
- particleEndSize: 24
- particleSizeVariation: 8
- acceleration: PointVector{ y: -40 }
- speed: AngleVector{ angle: 270; magnitude: 40; angleVariation: 22; magnitudeVariation: 5 }
+ emitRatePerParticle: 1
+ lifeSpan: 2400
+ size: 36
+ endSize: 24
+ sizeVariation: 8
+ acceleration: PointDirection{ y: -40 }
+ speed: AngledDirection{ angle: 270; magnitude: 40; angleVariation: 22; magnitudeVariation: 5 }
}
}
diff --git a/examples/declarative/particles/trails/velocityfrommotion.qml b/examples/declarative/particles/trails/velocityfrommotion.qml
index 3692410853..d361c99f89 100644
--- a/examples/declarative/particles/trails/velocityfrommotion.qml
+++ b/examples/declarative/particles/trails/velocityfrommotion.qml
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import Qt.labs.particles 2.0
+import QtQuick.Particles 2.0
Rectangle {
@@ -75,9 +75,9 @@ Rectangle {
}
ParticleSystem{ id: sys1 }
- ColoredParticle{
+ ImageParticle{
system: sys1
- image: "content/particle.png"
+ source: "content/particle.png"
color: "cyan"
alpha: 0
SequentialAnimation on color {
@@ -105,26 +105,26 @@ Rectangle {
}
colorVariation: 0.3
}
- TrailEmitter{
+ Emitter{
id: trailsNormal
system: sys1
- particlesPerSecond: 500
- particleDuration: 2000
+ emitRate: 500
+ lifeSpan: 2000
y: mouseArea.pressed ? mouseArea.mouseY : circle.cy
x: mouseArea.pressed ? mouseArea.mouseX : circle.cx
- speed: PointVector{xVariation: 4; yVariation: 4;}
- acceleration: PointVector{xVariation: 10; yVariation: 10;}
+ speed: PointDirection{xVariation: 4; yVariation: 4;}
+ acceleration: PointDirection{xVariation: 10; yVariation: 10;}
speedFromMovement: 8
- particleSize: 8
- particleSizeVariation: 4
+ size: 8
+ sizeVariation: 4
}
ParticleSystem { id: sys2 }
- ColoredParticle{
+ ImageParticle{
color: "cyan"
system: sys2
alpha: 0
@@ -142,29 +142,29 @@ Rectangle {
}
}
colorVariation: 0.5
- image: "content/star.png"
+ source: "content/star.png"
}
- TrailEmitter{
+ Emitter{
id: trailsStars
system: sys2
- particlesPerSecond: 100
- particleDuration: 2200
+ emitRate: 100
+ lifeSpan: 2200
y: mouseArea.pressed ? mouseArea.mouseY : circle.cy
x: mouseArea.pressed ? mouseArea.mouseX : circle.cx
- speed: PointVector{xVariation: 4; yVariation: 4;}
- acceleration: PointVector{xVariation: 10; yVariation: 10;}
+ speed: PointDirection{xVariation: 4; yVariation: 4;}
+ acceleration: PointDirection{xVariation: 10; yVariation: 10;}
speedFromMovement: 8
- particleSize: 22
- particleSizeVariation: 4
+ size: 22
+ sizeVariation: 4
}
ParticleSystem { id: sys3; }
- ColoredParticle{
- image: "content/particle.png"
+ ImageParticle{
+ source: "content/particle.png"
system: sys3
color: "orange"
alpha: 0
@@ -185,28 +185,28 @@ Rectangle {
colorVariation: 0.2
}
- TrailEmitter{
+ Emitter{
id: trailsNormal2
system: sys3
- particlesPerSecond: 300
- particleDuration: 2000
+ emitRate: 300
+ lifeSpan: 2000
y: mouseArea.pressed ? mouseArea.mouseY : circle2.cy
x: mouseArea.pressed ? mouseArea.mouseX : circle2.cx
speedFromMovement: 16
- speed: PointVector{xVariation: 4; yVariation: 4;}
- acceleration: PointVector{xVariation: 10; yVariation: 10;}
+ speed: PointDirection{xVariation: 4; yVariation: 4;}
+ acceleration: PointDirection{xVariation: 10; yVariation: 10;}
- particleSize: 12
- particleSizeVariation: 4
+ size: 12
+ sizeVariation: 4
}
ParticleSystem { id: sys4; }
- ColoredParticle{
+ ImageParticle{
system: sys4
- image: "content/star.png"
+ source: "content/star.png"
color: "green"
alpha: 0
SequentialAnimation on color {
@@ -225,23 +225,23 @@ Rectangle {
colorVariation: 0.5
}
- TrailEmitter{
+ Emitter{
id: trailsStars2
system: sys4
- particlesPerSecond: 50
- particleDuration: 2200
+ emitRate: 50
+ lifeSpan: 2200
y: mouseArea.pressed ? mouseArea.mouseY : circle2.cy
x: mouseArea.pressed ? mouseArea.mouseX : circle2.cx
speedFromMovement: 16
- speed: PointVector{xVariation: 2; yVariation: 2;}
- acceleration: PointVector{xVariation: 10; yVariation: 10;}
+ speed: PointDirection{xVariation: 2; yVariation: 2;}
+ acceleration: PointDirection{xVariation: 10; yVariation: 10;}
- particleSize: 22
- particleSizeVariation: 4
+ size: 22
+ sizeVariation: 4
}
diff --git a/examples/declarative/toys/dynamicscene/dynamicscene.qml b/examples/declarative/toys/dynamicscene/dynamicscene.qml
index a436b41b88..174204768a 100644
--- a/examples/declarative/toys/dynamicscene/dynamicscene.qml
+++ b/examples/declarative/toys/dynamicscene/dynamicscene.qml
@@ -147,27 +147,27 @@ Item {
PaletteItem {
anchors.verticalCenter: parent.verticalCenter
componentFile: "Sun.qml"
- image: "../images/sun.png"
+ source: "../images/sun.png"
}
PaletteItem {
anchors.verticalCenter: parent.verticalCenter
componentFile: "GenericSceneItem.qml"
- image: "../images/moon.png"
+ source: "../images/moon.png"
}
PaletteItem {
anchors.verticalCenter: parent.verticalCenter
componentFile: "PerspectiveItem.qml"
- image: "../images/tree_s.png"
+ source: "../images/tree_s.png"
}
PaletteItem {
anchors.verticalCenter: parent.verticalCenter
componentFile: "PerspectiveItem.qml"
- image: "../images/rabbit_brown.png"
+ source: "../images/rabbit_brown.png"
}
PaletteItem {
anchors.verticalCenter: parent.verticalCenter
componentFile: "PerspectiveItem.qml"
- image: "../images/rabbit_bw.png"
+ source: "../images/rabbit_bw.png"
}
}
}
diff --git a/examples/declarative/toys/dynamicscene/qml/Sun.qml b/examples/declarative/toys/dynamicscene/qml/Sun.qml
index d632461262..df3246d356 100644
--- a/examples/declarative/toys/dynamicscene/qml/Sun.qml
+++ b/examples/declarative/toys/dynamicscene/qml/Sun.qml
@@ -44,7 +44,7 @@ Image {
id: sun
property bool created: false
- property string image: "../images/sun.png"
+ property string source: "../images/sun.png"
source: image
diff --git a/examples/declarative/ui-components/flipable/content/Card.qml b/examples/declarative/ui-components/flipable/content/Card.qml
index 6374dd8eda..6574733abb 100644
--- a/examples/declarative/ui-components/flipable/content/Card.qml
+++ b/examples/declarative/ui-components/flipable/content/Card.qml
@@ -43,7 +43,7 @@ import QtQuick 1.0
Flipable {
id: container
- property alias image: frontImage.source
+ property alias source: frontImage.source
property bool flipped: true
property int xAxis: 0
property int yAxis: 0
diff --git a/examples/declarative/ui-components/flipable/flipable.qml b/examples/declarative/ui-components/flipable/flipable.qml
index 6d0235ecb4..3b23aa0d69 100644
--- a/examples/declarative/ui-components/flipable/flipable.qml
+++ b/examples/declarative/ui-components/flipable/flipable.qml
@@ -49,7 +49,7 @@ Rectangle {
Row {
anchors.centerIn: parent; spacing: 30
- Card { image: "content/9_club.png"; angle: 180; yAxis: 1 }
- Card { image: "content/5_heart.png"; angle: 540; xAxis: 1 }
+ Card { source: "content/9_club.png"; angle: 180; yAxis: 1 }
+ Card { source: "content/5_heart.png"; angle: 540; xAxis: 1 }
}
}
diff --git a/src/declarative/debugger/qjsdebuggeragent.cpp b/src/declarative/debugger/qjsdebuggeragent.cpp
index 9b76592c48..dff637b7da 100644
--- a/src/declarative/debugger/qjsdebuggeragent.cpp
+++ b/src/declarative/debugger/qjsdebuggeragent.cpp
@@ -56,7 +56,7 @@ class QJSDebuggerAgentPrivate
{
public:
QJSDebuggerAgentPrivate(QJSDebuggerAgent *q)
- : q(q), state(NoState)
+ : q(q), state(NoState), isInitialized(false)
{}
void continueExec();
@@ -79,6 +79,7 @@ public:
QHash<QString, JSAgentBreakpointData> fileNameToBreakpoints;
QStringList watchExpressions;
QSet<qint64> knownObjectIds;
+ bool isInitialized;
};
namespace {
@@ -252,6 +253,14 @@ QJSDebuggerAgent::~QJSDebuggerAgent()
delete d;
}
+/*!
+ Indicates whether the agent got the list of breakpoints.
+ */
+bool QJSDebuggerAgent::isInitialized() const
+{
+ return d->isInitialized;
+}
+
void QJSDebuggerAgent::setBreakpoints(const JSAgentBreakpoints &breakpoints)
{
d->breakpoints = breakpoints;
@@ -259,6 +268,8 @@ void QJSDebuggerAgent::setBreakpoints(const JSAgentBreakpoints &breakpoints)
d->fileNameToBreakpoints.clear();
foreach (const JSAgentBreakpointData &bp, breakpoints)
d->fileNameToBreakpoints.insertMulti(fileName(QString::fromUtf8(bp.fileUrl)), bp);
+
+ d->isInitialized = true;
}
void QJSDebuggerAgent::setWatchExpressions(const QStringList &watchExpressions)
diff --git a/src/declarative/debugger/qjsdebuggeragent_p.h b/src/declarative/debugger/qjsdebuggeragent_p.h
index 5aa3c9ccbc..309588eb2f 100644
--- a/src/declarative/debugger/qjsdebuggeragent_p.h
+++ b/src/declarative/debugger/qjsdebuggeragent_p.h
@@ -145,6 +145,8 @@ public:
QJSDebuggerAgent(QDeclarativeEngine *engine, QObject *parent = 0);
~QJSDebuggerAgent();
+ bool isInitialized() const;
+
void setBreakpoints(const JSAgentBreakpoints &);
void setWatchExpressions(const QStringList &);
diff --git a/src/declarative/debugger/qjsdebugservice.cpp b/src/declarative/debugger/qjsdebugservice.cpp
index 4ce2c906bc..ad84f656f7 100644
--- a/src/declarative/debugger/qjsdebugservice.cpp
+++ b/src/declarative/debugger/qjsdebugservice.cpp
@@ -71,6 +71,16 @@ void QJSDebugService::addEngine(QDeclarativeEngine *engine)
Q_ASSERT(!m_engines.contains(engine));
m_engines.append(engine);
+
+ if (status() == Enabled && !m_engines.isEmpty() && !m_agent) {
+ m_agent = new QJSDebuggerAgent(engine, engine);
+ connect(m_agent, SIGNAL(stopped(bool,QString)),
+ this, SLOT(executionStopped(bool,QString)));
+
+ while (!m_agent->isInitialized()) {
+ waitForMessage();
+ }
+ }
}
void QJSDebugService::removeEngine(QDeclarativeEngine *engine)
diff --git a/src/declarative/debugger/qpacketprotocol.cpp b/src/declarative/debugger/qpacketprotocol.cpp
index a40a9ab8a6..9caaa79011 100644
--- a/src/declarative/debugger/qpacketprotocol.cpp
+++ b/src/declarative/debugger/qpacketprotocol.cpp
@@ -198,6 +198,8 @@ public Q_SLOTS:
packets.append(inProgress);
inProgressSize = -1;
inProgress.clear();
+
+ waitingForPacket = false;
emit readyRead();
} else
return;
diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro
index cbd7d24753..1f79a9a017 100644
--- a/src/declarative/declarative.pro
+++ b/src/declarative/declarative.pro
@@ -33,6 +33,7 @@ include(qml/qml.pri)
include(debugger/debugger.pri)
include(scenegraph/scenegraph.pri)
include(items/items.pri)
+include(particles/particles.pri)
symbian: {
TARGET.UID3=0x2001E623
diff --git a/src/declarative/items/items.pri b/src/declarative/items/items.pri
index d6942973cd..bf92025b75 100644
--- a/src/declarative/items/items.pri
+++ b/src/declarative/items/items.pri
@@ -61,6 +61,11 @@ HEADERS += \
$$PWD/qsgcanvasitem_p.h \
$$PWD/qsgcontext2d_p.h \
$$PWD/qsgcontext2d_p_p.h \
+ $$PWD/qsgspriteengine_p.h \
+ $$PWD/qsgsprite_p.h \
+ $$PWD/qsgspriteimage_p.h \
+ $$PWD/qsgevent.h \
+ $$PWD/qsgdragtarget_p.h \
SOURCES += \
$$PWD/qsgevents.cpp \
@@ -100,6 +105,10 @@ SOURCES += \
$$PWD/qsgimplicitsizeitem.cpp \
$$PWD/qsgcanvasitem.cpp \
$$PWD/qsgcontext2d.cpp \
+ $$PWD/qsgspriteengine.cpp \
+ $$PWD/qsgsprite.cpp \
+ $$PWD/qsgspriteimage.cpp \
+ $$PWD/qsgdragtarget.cpp \
SOURCES += \
$$PWD/qsgshadereffectitem.cpp \
diff --git a/src/declarative/items/qsgcanvas.cpp b/src/declarative/items/qsgcanvas.cpp
index f12f936b4e..97d643dae6 100644
--- a/src/declarative/items/qsgcanvas.cpp
+++ b/src/declarative/items/qsgcanvas.cpp
@@ -45,6 +45,8 @@
#include "qsgitem.h"
#include "qsgitem_p.h"
+#include "qsgevent.h"
+
#include <private/qsgrenderer_p.h>
#include <private/qsgflashnode_p.h>
@@ -172,7 +174,7 @@ void QSGCanvas::paintEvent(QPaintEvent *)
int lastFrame = frameTimer.restart();
#endif
- if (d->animationDriver->isRunning())
+ if (d->animationDriver && d->animationDriver->isRunning())
d->animationDriver->advance();
#ifdef FRAME_TIMING
@@ -220,7 +222,7 @@ void QSGCanvas::paintEvent(QPaintEvent *)
QDeclarativeDebugTrace::endRange(QDeclarativeDebugTrace::Painting);
- if (d->animationDriver->isRunning())
+ if (d->animationDriver && d->animationDriver->isRunning())
update();
} else {
if (updatesEnabled()) {
@@ -248,25 +250,32 @@ void QSGCanvas::showEvent(QShowEvent *e)
QGLWidget::showEvent(e);
- if (d->threadedRendering) {
- if (!d->animationDriver) {
- d->animationDriver = d->context->createAnimationDriver(this);
- connect(d->animationDriver, SIGNAL(started()), d->thread, SLOT(animationStarted()), Qt::DirectConnection);
- connect(d->animationDriver, SIGNAL(stopped()), d->thread, SLOT(animationStopped()), Qt::DirectConnection);
- }
- d->animationDriver->install();
- d->thread->startRenderThread();
- setUpdatesEnabled(true);
- } else {
- makeCurrent();
+ if (!d->contextFailed) {
+ if (d->threadedRendering) {
+ if (d->vsyncAnimations) {
+ if (!d->animationDriver) {
+ d->animationDriver = d->context->createAnimationDriver(this);
+ connect(d->animationDriver, SIGNAL(started()), d->thread, SLOT(animationStarted()), Qt::DirectConnection);
+ connect(d->animationDriver, SIGNAL(stopped()), d->thread, SLOT(animationStopped()), Qt::DirectConnection);
+ }
+ d->animationDriver->install();
+ }
+ d->thread->startRenderThread();
+ setUpdatesEnabled(true);
+ } else {
+ makeCurrent();
- if (!d->context || !d->context->isReady()) {
- d->initializeSceneGraph();
- d->animationDriver = d->context->createAnimationDriver(this);
- connect(d->animationDriver, SIGNAL(started()), this, SLOT(update()));
- }
+ if (!d->context || !d->context->isReady()) {
+ d->initializeSceneGraph();
+ if (d->vsyncAnimations) {
+ d->animationDriver = d->context->createAnimationDriver(this);
+ connect(d->animationDriver, SIGNAL(started()), this, SLOT(update()));
+ }
+ }
- d->animationDriver->install();
+ if (d->animationDriver)
+ d->animationDriver->install();
+ }
}
}
@@ -274,15 +283,57 @@ void QSGCanvas::hideEvent(QHideEvent *e)
{
Q_D(QSGCanvas);
- if (d->threadedRendering) {
- d->thread->stopRenderThread();
- }
+ if (!d->contextFailed) {
+ if (d->threadedRendering) {
+ d->thread->stopRenderThread();
+ }
- d->animationDriver->uninstall();
+ if (d->animationDriver)
+ d->animationDriver->uninstall();
+ }
QGLWidget::hideEvent(e);
}
+
+
+/*!
+ Sets weither this canvas should use vsync driven animations.
+
+ This option can only be set on one single QSGCanvas, and that it's
+ vsync signal will then be used to drive all animations in the
+ process.
+
+ This feature is primarily useful for single QSGCanvas, QML-only
+ applications.
+
+ \warning Enabling vsync on multiple QSGCanvas instances has
+ undefined behavior.
+ */
+void QSGCanvas::setVSyncAnimations(bool enabled)
+{
+ Q_D(QSGCanvas);
+ if (isVisible()) {
+ qWarning("QSGCanvas::setVSyncAnimations: Cannot be changed when widget is shown");
+ return;
+ }
+ d->vsyncAnimations = enabled;
+}
+
+
+
+/*!
+ Returns true if this canvas should use vsync driven animations;
+ otherwise returns false.
+ */
+bool QSGCanvas::vsyncAnimations() const
+{
+ Q_D(const QSGCanvas);
+ return d->vsyncAnimations;
+}
+
+
+
void QSGCanvas::focusOutEvent(QFocusEvent *event)
{
Q_D(QSGCanvas);
@@ -374,9 +425,11 @@ QSGCanvasPrivate::QSGCanvasPrivate()
, hoverItem(0)
, dirtyItemList(0)
, context(0)
+ , contextFailed(false)
, threadedRendering(false)
, animationRunning(false)
, renderThreadAwakened(false)
+ , vsyncAnimations(false)
, thread(0)
, animationDriver(0)
{
@@ -391,6 +444,11 @@ void QSGCanvasPrivate::init(QSGCanvas *c)
{
QUnifiedTimer::instance(true)->setConsistentTiming(qmlFixedAnimationStep());
+ if (!c->context() || !c->context()->isValid()) {
+ contextFailed = true;
+ qWarning("QSGCanvas: Couldn't acquire a GL context.");
+ }
+
q_ptr = c;
Q_Q(QSGCanvas);
@@ -877,18 +935,20 @@ QSGCanvas::~QSGCanvas()
d->cleanupNodes();
- // We need to remove all references to textures pointing to "our" QSGContext
- // from the QDeclarativePixmapCache. Call into the cache to remove the GL / Scene Graph
- // part of those cache entries.
- // To "play nice" with other GL apps that are potentially running in the GUI thread,
- // We get the current context and only temporarily make our own current
- QGLContext *currentContext = const_cast<QGLContext *>(QGLContext::currentContext());
- makeCurrent();
- extern void qt_declarative_pixmapstore_clean(QSGContext *context);
- qt_declarative_pixmapstore_clean(d->context);
- delete d->context;
- if (currentContext)
- currentContext->makeCurrent();
+ if (!d->contextFailed) {
+ // We need to remove all references to textures pointing to "our" QSGContext
+ // from the QDeclarativePixmapCache. Call into the cache to remove the GL / Scene Graph
+ // part of those cache entries.
+ // To "play nice" with other GL apps that are potentially running in the GUI thread,
+ // We get the current context and only temporarily make our own current
+ QGLContext *currentContext = const_cast<QGLContext *>(QGLContext::currentContext());
+ makeCurrent();
+ extern void qt_declarative_pixmapstore_clean(QSGContext *context);
+ qt_declarative_pixmapstore_clean(d->context);
+ delete d->context;
+ if (currentContext)
+ currentContext->makeCurrent();
+ }
}
QSGItem *QSGCanvas::rootItem() const
@@ -944,7 +1004,7 @@ bool QSGCanvas::event(QEvent *e)
d->thread->syncAlreadyHappened = false;
- if (d->animationRunning) {
+ if (d->animationRunning && d->animationDriver) {
#ifdef THREAD_DEBUG
qDebug("GUI: Advancing animations...\n");
#endif
@@ -975,6 +1035,12 @@ bool QSGCanvas::event(QEvent *e)
d->clearHover();
d->lastMousePosition = QPoint();
break;
+ case QSGEvent::SGDragEnter:
+ case QSGEvent::SGDragExit:
+ case QSGEvent::SGDragMove:
+ case QSGEvent::SGDragDrop:
+ d->deliverDragEvent(static_cast<QSGDragEvent *>(e));
+ break;
default:
break;
}
@@ -1434,6 +1500,78 @@ bool QSGCanvasPrivate::deliverTouchPoints(QSGItem *item, QTouchEvent *event, con
return false;
}
+void QSGCanvasPrivate::deliverDragEvent(QSGDragEvent *event)
+{
+ Q_Q(QSGCanvas);
+ if (event->type() == QSGEvent::SGDragExit || event->type() == QSGEvent::SGDragDrop) {
+ if (QSGItem *grabItem = event->grabItem()) {
+ event->setPosition(grabItem->mapFromScene(event->scenePosition()));
+ q->sendEvent(grabItem, event);
+ }
+ } else if (!deliverDragEvent(rootItem, event)) {
+ if (QSGItem *grabItem = event->grabItem()) {
+ QSGDragEvent exitEvent(QSGEvent::SGDragExit, *event);
+ exitEvent.setPosition(grabItem->mapFromScene(event->scenePosition()));
+ q->sendEvent(grabItem, &exitEvent);
+ event->setDropItem(0);
+ event->setGrabItem(0);
+ }
+ event->setAccepted(false);
+ }
+}
+
+bool QSGCanvasPrivate::deliverDragEvent(QSGItem *item, QSGDragEvent *event)
+{
+ Q_Q(QSGCanvas);
+ QSGItemPrivate *itemPrivate = QSGItemPrivate::get(item);
+ if (itemPrivate->opacity == 0.0)
+ return false;
+
+ if (itemPrivate->flags & QSGItem::ItemClipsChildrenToShape) {
+ QPointF p = item->mapFromScene(event->scenePosition());
+ if (!QRectF(0, 0, item->width(), item->height()).contains(p))
+ return false;
+ }
+
+ QList<QSGItem *> children = itemPrivate->paintOrderChildItems();
+ for (int ii = children.count() - 1; ii >= 0; --ii) {
+ QSGItem *child = children.at(ii);
+ if (!child->isVisible() || !child->isEnabled())
+ continue;
+ if (deliverDragEvent(child, event))
+ return true;
+ }
+
+ QPointF p = item->mapFromScene(event->scenePosition());
+ if (QRectF(0, 0, item->width(), item->height()).contains(p)) {
+ event->setPosition(p);
+
+ if (event->type() == QSGEvent::SGDragMove && item != event->grabItem()) {
+ QSGDragEvent enterEvent(QSGEvent::SGDragEnter, *event);
+ q->sendEvent(item, &enterEvent);
+ if (enterEvent.isAccepted()) {
+ if (QSGItem *grabItem = event->grabItem()) {
+ QSGDragEvent exitEvent(QSGEvent::SGDragExit, *event);
+ q->sendEvent(grabItem, &exitEvent);
+ }
+ event->setDropItem(enterEvent.dropItem());
+ event->setGrabItem(item);
+ } else {
+ return false;
+ }
+ }
+
+ q->sendEvent(item, event);
+ if (event->isAccepted()) {
+ event->setGrabItem(item);
+ return true;
+ }
+ event->setAccepted(true);
+ }
+
+ return false;
+}
+
bool QSGCanvasPrivate::sendFilteredMouseEvent(QSGItem *target, QSGItem *item, QGraphicsSceneMouseEvent *event)
{
if (!target)
@@ -1509,6 +1647,12 @@ bool QSGCanvas::sendEvent(QSGItem *item, QEvent *e)
case QEvent::TouchEnd:
QSGItemPrivate::get(item)->deliverTouchEvent(static_cast<QTouchEvent *>(e));
break;
+ case QSGEvent::SGDragEnter:
+ case QSGEvent::SGDragExit:
+ case QSGEvent::SGDragMove:
+ case QSGEvent::SGDragDrop:
+ QSGItemPrivate::get(item)->deliverDragEvent(static_cast<QSGDragEvent *>(e));
+ break;
default:
break;
}
@@ -1857,7 +2001,9 @@ QImage QSGCanvas::grabFrameBuffer()
void QSGCanvasRenderThread::run()
{
+#ifdef THREAD_DEBUG
qDebug("QML Rendering Thread Started");
+#endif
renderer->makeCurrent();
@@ -1950,7 +2096,7 @@ void QSGCanvasRenderThread::run()
// but we don't want to lock an extra time.
wake();
- if (!d->animationRunning && !isExternalUpdatePending) {
+ if (!d->animationRunning && !isExternalUpdatePending && !shouldExit && !doGrab) {
#ifdef THREAD_DEBUG
printf(" RenderThread: nothing to do, going to sleep...\n");
#endif
@@ -2170,6 +2316,13 @@ void QSGCanvasRenderThread::stopRenderThread()
}
unlockInGui();
+
+#ifdef THREAD_DEBUG
+ printf("GUI: waiting for render thread to terminate..\n");
+#endif
+ // Actually wait for the thread to terminate. Otherwise we can delete it
+ // too early and crash.
+ QThread::wait();
}
@@ -2189,7 +2342,7 @@ QImage QSGCanvasRenderThread::grab()
doGrab = true;
isPaintCompleted = false;
while (isRunning() && !isPaintCompleted) {
- if (!isRenderBlocked)
+ if (isRenderBlocked)
wake();
wait();
}
diff --git a/src/declarative/items/qsgcanvas.h b/src/declarative/items/qsgcanvas.h
index d0d0c79d5e..8913e41b86 100644
--- a/src/declarative/items/qsgcanvas.h
+++ b/src/declarative/items/qsgcanvas.h
@@ -75,6 +75,9 @@ public:
QSGEngine *sceneGraphEngine() const;
+ void setVSyncAnimations(bool enabled);
+ bool vsyncAnimations() const;
+
QImage grabFrameBuffer();
Q_SIGNALS:
diff --git a/src/declarative/items/qsgcanvas_p.h b/src/declarative/items/qsgcanvas_p.h
index 7538b3d7c1..7f7182ee52 100644
--- a/src/declarative/items/qsgcanvas_p.h
+++ b/src/declarative/items/qsgcanvas_p.h
@@ -55,6 +55,7 @@
#include "qsgitem.h"
#include "qsgcanvas.h"
+#include "qsgevent.h"
#include <private/qdeclarativeguard_p.h>
#include <private/qsgcontext_p.h>
@@ -116,6 +117,8 @@ public:
bool deliverHoverEvent(QSGItem *, QGraphicsSceneHoverEvent *);
void sendHoverEvent(QEvent::Type, QSGItem *, QGraphicsSceneHoverEvent *);
void clearHover();
+ void deliverDragEvent(QSGDragEvent *);
+ bool deliverDragEvent(QSGItem *item, QSGDragEvent *);
QDeclarativeGuard<QSGItem> hoverItem;
enum FocusOption {
@@ -152,11 +155,13 @@ public:
QSGContext *context;
- uint contextInThread : 1;
+ uint contextFailed : 1;
uint threadedRendering : 1;
uint animationRunning: 1;
uint renderThreadAwakened : 1;
+ uint vsyncAnimations : 1;
+
QSGCanvasRenderThread *thread;
QSize widgetSize;
QSize viewportSize;
diff --git a/src/declarative/items/qsgcanvasitem.cpp b/src/declarative/items/qsgcanvasitem.cpp
index fa99c9be6f..264752eddd 100644
--- a/src/declarative/items/qsgcanvasitem.cpp
+++ b/src/declarative/items/qsgcanvasitem.cpp
@@ -56,6 +56,7 @@ class QSGCanvasItemPrivate : public QSGPaintedItemPrivate
{
public:
QSGCanvasItemPrivate();
+ ~QSGCanvasItemPrivate();
QSGContext2D* context;
};
@@ -69,6 +70,10 @@ QSGCanvasItemPrivate::QSGCanvasItemPrivate()
{
}
+QSGCanvasItemPrivate::~QSGCanvasItemPrivate()
+{
+}
+
/*!
Constructs a QSGCanvasItem with the given \a parent item.
*/
@@ -94,24 +99,24 @@ void QSGCanvasItem::paint(QPainter *painter)
}
}
-
-QSGContext2D* QSGCanvasItem::getContext(const QString &contextId)
+QScriptValue QSGCanvasItem::getContext(const QString &contextId)
{
Q_D(QSGCanvasItem);
+ QScriptEngine* e = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this));
if (contextId == QLatin1String("2d")) {
if (!d->context) {
d->context = new QSGContext2D(this);
+ d->context->setScriptEngine(e);
connect(d->context, SIGNAL(changed()), this, SLOT(requestPaint()));
}
- return d->context;
+ return d->context->scriptValue();
}
qDebug("Canvas:requesting unsupported context");
- return 0;
+ return e->undefinedValue();
}
void QSGCanvasItem::requestPaint()
{
- // Q_D(QSGCanvasItem);
//TODO:update(d->context->dirtyRect());
update();
}
@@ -162,280 +167,5 @@ QString QSGCanvasItem::toDataURL(const QString& mimeType) const
}
return QLatin1String("data:,");
}
-//CanvasItemTextureProvider::CanvasItemTextureProvider(QObject *parent)
-// : QSGTextureProvider(parent)
-// , m_ctx2d(0)
-// , m_fbo(0)
-// , m_multisampledFbo(0)
-// , m_dirtyTexture(true)
-// , m_multisamplingSupportChecked(false)
-// , m_multisampling(false)
-//{
-//}
-
-//CanvasItemTextureProvider::~CanvasItemTextureProvider()
-//{
-// delete m_fbo;
-// delete m_multisampledFbo;
-//}
-
-//void CanvasItemTextureProvider::updateTexture()
-//{
-// if (m_dirtyTexture) {
-// if (!m_ctx2d->isDirty())
-// return;
-// if (m_size.isEmpty()) {
-// m_texture = QSGTextureRef();
-// delete m_fbo;
-// delete m_multisampledFbo;
-// m_multisampledFbo = m_fbo = 0;
-// return;
-// }
-
-//#ifndef QSGCANVASITEM_PAINTING_ON_IMAGE
-// //create texture
-// if (!m_fbo || m_fbo->size() != m_size )
-// {
-// const QGLContext *ctx = QSGContext::current->glContext();
-// if (!m_multisamplingSupportChecked) {
-// QList<QByteArray> extensions = QByteArray((const char *)glGetString(GL_EXTENSIONS)).split(' ');
-// m_multisampling = extensions.contains("GL_EXT_framebuffer_multisample")
-// && extensions.contains("GL_EXT_framebuffer_blit");
-// m_multisamplingSupportChecked = true;
-// }
-
-// if (ctx->format().sampleBuffers() && m_multisampling) {
-// delete m_fbo;
-// delete m_multisampledFbo;
-// QGLFramebufferObjectFormat format;
-
-// format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
-// format.setSamples(ctx->format().samples());
-// m_multisampledFbo = new QGLFramebufferObject(m_size, format);
-// {
-// QGLFramebufferObjectFormat format;
-// format.setAttachment(QGLFramebufferObject::NoAttachment);
-// m_fbo = new QGLFramebufferObject(m_size, format);
-// }
-
-// QSGPlainTexture *tex = new QSGPlainTexture;
-// tex->setTextureId(m_fbo->texture());
-// tex->setOwnsTexture(false);
-// tex->setHasAlphaChannel(true);
-// setOpaque(!tex->hasAlphaChannel());
-// m_texture = QSGTextureRef(tex);
-// } else {
-// delete m_fbo;
-// QGLFramebufferObjectFormat format;
-// format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
-// m_fbo = new QGLFramebufferObject(m_size, format);
-// QSGPlainTexture *tex = new QSGPlainTexture;
-// tex->setTextureId(m_fbo->texture());
-// tex->setOwnsTexture(false);
-// tex->setHasAlphaChannel(true);
-// setOpaque(!tex->hasAlphaChannel());
-// m_texture = QSGTextureRef(tex);
-// }
-// }
-//#endif
-
-//#ifdef QSGCANVASITEM_DEBUG
-// qDebug() << "painting interval:" << m_elapsedTimer.nsecsElapsed();
-// m_elapsedTimer.restart();
-//#endif
-// //paint 2d
-// if (m_ctx2d) {
-// QPainter p;
-//#ifndef QSGCANVASITEM_PAINTING_ON_IMAGE
-// if (m_multisampledFbo)
-// p.begin(m_multisampledFbo);
-// else if (m_fbo)
-// p.begin(m_fbo);
-// else
-// return;
-// // move the origin of coordinates to the down left corner and
-// // scale coordinates and turn y-axis up
-// QSize size = m_ctx2d->size();
-// p.translate( 0, size.height());
-// p.scale(1, -1);
-
-// m_ctx2d->paint(&p);
-
-// p.end();
-
-// if (m_multisampledFbo) {
-// QRect r(0, 0, m_fbo->width(), m_fbo->height());
-// QGLFramebufferObject::blitFramebuffer(m_fbo, r, m_multisampledFbo, r);
-// }
-
-// if (m_ctx2d->requireCachedImage())
-// m_ctx2d->setCachedImage(m_fbo->toImage());
-
-//#else
-// m_painter.begin(m_ctx2d->paintDevice());
-// m_ctx2d->paint(&m_painter);
-// m_painter.end();
-
-// if (m_texture.isNull()) {
-// m_texture = QSGContext::current->createTexture(m_ctx2d->toImage());
-// } else {
-// QSGPlainTexture* t =static_cast<QSGPlainTexture*>(m_texture.texture());
-// t->setImage(m_ctx2d->toImage());
-// }
-// m_ctx2d->setCachedImage(m_ctx2d->toImage());
-
-//#endif
-
-//#ifdef QSGCANVASITEM_DEBUG
-// qDebug() << "painting time:" << m_elapsedTimer.nsecsElapsed();
-// m_elapsedTimer.restart();
-//#endif
-// emit painted();
-// }
-// }
-//}
-
-//QSGTextureRef CanvasItemTextureProvider::texture()
-//{
-// return m_texture;
-//}
-//void CanvasItemTextureProvider::setContext2D(QSGContext2D *ctx2d)
-//{
-// if (ctx2d && m_ctx2d != ctx2d) {
-// m_ctx2d = ctx2d;
-// connect(this, SIGNAL(painted()), m_ctx2d, SIGNAL(painted()));
-// }
-//}
-//void CanvasItemTextureProvider::setRect(const QRectF &rect)
-//{
-// if (rect == m_rect)
-// return;
-// m_rect = rect;
-// markDirtyTexture();
-//}
-
-//void CanvasItemTextureProvider::setSize(const QSize &size)
-//{
-// if (size == m_size)
-// return;
-// m_size = size;
-// markDirtyTexture();
-//}
-
-//void CanvasItemTextureProvider::markDirtyTexture()
-//{
-// m_dirtyTexture = true;
-// emit textureChanged();
-//}
-//QSGCanvasItem::QSGCanvasItem(QSGItem *parent)
-// : TextureItem(parent)
-// , m_textureProvider(0)
-// , m_context2dChanged(false)
-// , m_context2d( new QSGContext2D(this))
-// , m_fillMode(QSGCanvasItem::Stretch)
-// , m_color(Qt::white)
-//{
-// m_textureProvider = new CanvasItemTextureProvider(this);
-// m_textureProvider->setContext2D(m_context2d);
-// setTextureProvider(m_textureProvider, true);
-// setFlag(QSGItem::ItemHasContents, true);
-//}
-
-//QSGCanvasItem::~QSGCanvasItem()
-//{
-//}
-
-//void QSGCanvasItem::componentComplete()
-//{
-// m_context2d->setSize(width(), height());
-// qDebug() << "m_context2d.size:" << m_context2d->size();
-// connect(m_context2d, SIGNAL(changed()), this, SLOT(requestPaint()));
-// QScriptEngine* scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this));
-// if (scriptEngine != m_context2d->scriptEngine())
-// m_context2d->setScriptEngine(scriptEngine);
-// QSGItem::componentComplete();
-//}
-
-
-//void QSGCanvasItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
-//{
-// if (width() == 0 && height()
-// && newGeometry.width() > 0 && newGeometry.height() > 0) {
-// m_context2d->setSize(width(), height());
-// }
-// TextureItem::geometryChanged(newGeometry, oldGeometry);
-//}
-
-//void QSGCanvasItem::setFillMode(FillMode mode)
-//{
-// if (m_fillMode == mode)
-// return;
-
-// m_fillMode = mode;
-// update();
-// emit fillModeChanged();
-//}
-
-//QColor QSGCanvasItem::color()
-//{
-// return m_color;
-//}
-
-//void QSGCanvasItem::setColor(const QColor &color)
-//{
-// if (m_color !=color) {
-// m_color = color;
-// colorChanged();
-// }
-//}
-
-//QSGCanvasItem::FillMode QSGCanvasItem::fillMode() const
-//{
-// return m_fillMode;
-//}
-
-
-
-//Node *QSGCanvasItem::updatePaintNode(Node *oldNode, UpdatePaintNodeData *data)
-//{
-// if (width() <= 0 || height() <= 0) {
-// delete oldNode;
-// return 0;
-// }
-
-// TextureNodeInterface *node = static_cast<TextureNodeInterface *>(oldNode);
-
-// if (node && m_context2d->isDirty()) {
-// QRectF bounds = boundingRect();
-
-// if (m_textureProvider) {
-// m_textureProvider->setRect(QRectF(bounds.x(), bounds.y(), width(), height()));
-
-// m_textureProvider->setSize(QSize(width(), height()));
-// //m_textureProvider->setOpaque(true);
-// m_textureProvider->setHorizontalWrapMode(QSGTextureProvider::ClampToEdge);
-// m_textureProvider->setVerticalWrapMode(QSGTextureProvider::ClampToEdge);
-// node->setTargetRect(bounds);
-// node->setSourceRect(QRectF(0, 0, 1, 1));
-// // node->setTargetRect(image.rect());
-//// node->setSourceRect(QRectF(0, 0, 1, 1));
-//// d->textureProvider->setHorizontalWrapMode(QSGTextureProvider::ClampToEdge);
-//// d->textureProvider->setVerticalWrapMode(QSGTextureProvider::ClampToEdge);
-//// d->textureProvider->setFiltering(d->smooth ? QSGTextureProvider::Linear : QSGTextureProvider::Nearest);
-// }
-
-// if (m_context2dChanged) {
-// //force textnode update the content
-// node->setTexture(0);
-// node->setTexture(m_textureProvider);
-// m_context2dChanged = false;
-// }
-// } else {
-// if (m_context2d->requireCachedImage())
-// m_context2d->setCachedImage(QImage(width(), height(), QImage::Format_ARGB32_Premultiplied));
-// }
-
-// return TextureItem::updatePaintNode(oldNode, data);
-//}
QT_END_NAMESPACE
diff --git a/src/declarative/items/qsgcanvasitem_p.h b/src/declarative/items/qsgcanvasitem_p.h
index a358c353ea..b501901569 100644
--- a/src/declarative/items/qsgcanvasitem_p.h
+++ b/src/declarative/items/qsgcanvasitem_p.h
@@ -55,6 +55,7 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
+class QScriptValue;
class QSGContext2D;
class QSGCanvasItemPrivate;
class QSGCanvasItem : public QSGPaintedItem
@@ -68,7 +69,7 @@ signals:
void canvasUpdated();
public Q_SLOTS:
QString toDataURL(const QString& type = QLatin1String("image/png")) const;
- QSGContext2D* getContext(const QString & = QLatin1String("2d"));
+ QScriptValue getContext(const QString & = QLatin1String("2d"));
void requestPaint();
// Save current canvas to disk
diff --git a/src/declarative/items/qsgcontext2d.cpp b/src/declarative/items/qsgcontext2d.cpp
index 6f7121ac30..9dddc99557 100644
--- a/src/declarative/items/qsgcontext2d.cpp
+++ b/src/declarative/items/qsgcontext2d.cpp
@@ -366,6 +366,547 @@ static QString compositeOperatorToString(QPainter::CompositionMode op)
return QString();
}
+
+ #include <QScriptEngine>
+
+//static QtScript functions
+static QScriptValue ctx2d_sync(QScriptContext *c, QScriptEngine* e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ ctx2d->sync();
+ return e->nullValue();
+}
+
+
+// back-reference to the canvas, getter
+static QScriptValue ctx2d_canvas(QScriptContext *c, QScriptEngine* e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ return e->newQObject(ctx2d->canvas());
+}
+
+// state
+static QScriptValue ctx2d_restore(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ ctx2d->restore();
+ return e->nullValue();
+}
+
+static QScriptValue ctx2d_save(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ ctx2d->save();
+ return e->nullValue();
+}
+
+// transformations
+static QScriptValue ctx2d_rotate(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {
+ ctx2d->rotate(c->argument(0).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_scale(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 2) {
+ ctx2d->scale(c->argument(0).toNumber(), c->argument(1).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_setTransform(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 6) {
+ ctx2d->setTransform(c->argument(0).toNumber()
+ , c->argument(1).toNumber()
+ , c->argument(2).toNumber()
+ , c->argument(3).toNumber()
+ , c->argument(4).toNumber()
+ , c->argument(5).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_transform(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 6) {
+ ctx2d->transform(c->argument(0).toNumber()
+ , c->argument(1).toNumber()
+ , c->argument(2).toNumber()
+ , c->argument(3).toNumber()
+ , c->argument(4).toNumber()
+ , c->argument(5).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_translate(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 2) {
+ ctx2d->translate(c->argument(0).toNumber()
+ , c->argument(1).toNumber());
+ }
+ return e->nullValue();
+}
+
+// compositing
+// float getter/setter default 1.0
+static QScriptValue ctx2d_globalAlpha(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setGlobalAlpha(c->argument(0).toNumber());
+ }
+ return e->toScriptValue(ctx2d->globalAlpha());
+}
+
+// string getter/setter default "source-over"
+static QScriptValue ctx2d_globalCompositeOperation(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (ctx2d) {
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setGlobalCompositeOperation(c->argument(0).toString());
+ }
+ return e->toScriptValue(ctx2d->globalCompositeOperation());
+ }
+ return e->nullValue();
+}
+
+// colors and styles
+// getter/setter
+static QScriptValue ctx2d_fillStyle(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setFillStyle(c->argument(0).toVariant());
+ }
+ return e->toScriptValue(ctx2d->fillStyle());
+}
+
+// colors and styles
+// getter/setter
+static QScriptValue ctx2d_fillColor(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setFillColor(c->argument(0).toVariant().value<QColor>());
+ }
+ return e->toScriptValue(ctx2d->fillColor());
+}
+
+
+//getter/setter
+static QScriptValue ctx2d_strokeStyle(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setStrokeStyle(c->argument(0).toVariant());
+ }
+ return e->toScriptValue(ctx2d->strokeStyle());
+}
+
+// colors and styles
+// getter/setter
+static QScriptValue ctx2d_strokeColor(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setStrokeColor(c->argument(0).toVariant().value<QColor>());
+ }
+ return e->toScriptValue(ctx2d->strokeColor());
+}
+
+static QScriptValue ctx2d_createLinearGradient(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 4) {
+ QObject* gradient = ctx2d->createLinearGradient( c->argument(0).toNumber()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber());
+ return e->toScriptValue(gradient);
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_createRadialGradient(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 6) {
+ QObject* gradient = ctx2d->createRadialGradient( c->argument(0).toNumber()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber()
+ ,c->argument(4).toNumber()
+ ,c->argument(5).toNumber());
+ return e->toScriptValue(gradient);
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_createPattern(QScriptContext *c, QScriptEngine *e)
+{
+ //TODO
+ return e->nullValue();
+}
+
+// line styles
+// string getter/setter
+static QScriptValue ctx2d_lineCap(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setLineCap(c->argument(0).toString());
+ }
+ return e->toScriptValue(ctx2d->lineCap());
+}
+
+// string getter/setter
+static QScriptValue ctx2d_lineJoin(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setLineJoin(c->argument(0).toString());
+ }
+ return e->toScriptValue(ctx2d->lineJoin());
+}
+// float getter/setter
+static QScriptValue ctx2d_lineWidth(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setLineWidth(c->argument(0).toNumber());
+ }
+ return e->toScriptValue(ctx2d->lineWidth());
+}
+// float getter/setter
+static QScriptValue ctx2d_miterLimit(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setMiterLimit(c->argument(0).toNumber());
+ }
+ return e->toScriptValue(ctx2d->miterLimit());
+}
+
+// shadows
+// float getter/setter
+static QScriptValue ctx2d_shadowBlur(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setShadowBlur(c->argument(0).toNumber());
+ }
+ return e->toScriptValue(ctx2d->shadowBlur());
+}
+static QScriptValue ctx2d_shadowColor(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setShadowColor(c->argument(0).toString());
+ }
+ return e->toScriptValue(ctx2d->shadowColor());
+}
+static QScriptValue ctx2d_shadowOffsetX(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setShadowOffsetX(c->argument(0).toNumber());
+ }
+ return e->toScriptValue(ctx2d->shadowOffsetX());
+}
+
+static QScriptValue ctx2d_shadowOffsetY(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 1) {//setter
+ ctx2d->setShadowOffsetY(c->argument(0).toNumber());
+ }
+ return e->toScriptValue(ctx2d->shadowOffsetY());
+}
+
+//rects
+static QScriptValue ctx2d_clearRect(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 4) {
+ ctx2d->clearRect(c->argument(0).toNumber()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_fillRect(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 4) {
+ ctx2d->fillRect(c->argument(0).toNumber()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_strokeRect(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 4) {
+ ctx2d->strokeRect(c->argument(0).toNumber()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber());
+ }
+ return e->nullValue();
+}
+
+// Complex shapes (paths) API
+static QScriptValue ctx2d_arc(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 6) {
+ ctx2d->arc(c->argument(0).toNumber()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber()
+ ,c->argument(4).toNumber()
+ ,c->argument(5).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_arcTo(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 5) {
+ ctx2d->arcTo(c->argument(0).toNumber()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber()
+ ,c->argument(4).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_beginPath(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ ctx2d->beginPath();
+ return e->nullValue();
+}
+static QScriptValue ctx2d_bezierCurveTo(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 5) {
+ ctx2d->bezierCurveTo(c->argument(0).toNumber()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber()
+ ,c->argument(4).toNumber()
+ ,c->argument(5).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_clip(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ ctx2d->clip();
+ return e->nullValue();
+}
+static QScriptValue ctx2d_closePath(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ ctx2d->closePath();
+ return e->nullValue();
+}
+static QScriptValue ctx2d_fill(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ ctx2d->fill();
+ return e->nullValue();
+}
+static QScriptValue ctx2d_lineTo(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 2) {
+ ctx2d->lineTo(c->argument(0).toNumber()
+ ,c->argument(1).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_moveTo(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 2) {
+ ctx2d->moveTo(c->argument(0).toNumber()
+ ,c->argument(1).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_quadraticCurveTo(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 4) {
+ ctx2d->quadraticCurveTo(c->argument(0).toNumber()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_rect(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 4) {
+ ctx2d->rect(c->argument(0).toNumber()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_stroke(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ ctx2d->stroke();
+ return e->nullValue();
+}
+static QScriptValue ctx2d_isPointInPath(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ bool pointInPath = false;
+ if (c->argumentCount() == 2) {
+ pointInPath = ctx2d->isPointInPath(c->argument(0).toNumber()
+ ,c->argument(1).toNumber());
+ }
+ return e->toScriptValue(pointInPath);
+}
+
+// text
+static QScriptValue ctx2d_font(QScriptContext *c, QScriptEngine *e)
+{
+ return QScriptValue();
+}
+static QScriptValue ctx2d_textAlign(QScriptContext *c, QScriptEngine *e)
+{
+ return QScriptValue();
+}
+static QScriptValue ctx2d_textBaseline(QScriptContext *c, QScriptEngine *e)
+{
+ return QScriptValue();
+}
+static QScriptValue ctx2d_fillText(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 3) {
+ ctx2d->fillText(c->argument(0).toString()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber());
+ }
+ return e->nullValue();
+}
+static QScriptValue ctx2d_strokeText(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 3) {
+ ctx2d->strokeText(c->argument(0).toString()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber());
+ }
+ return e->nullValue();
+}
+
+// drawing images
+static QScriptValue ctx2d_drawImage(QScriptContext *c, QScriptEngine *e)
+{
+ QSGContext2D* ctx2d = qscriptvalue_cast<QSGContext2D*>(c->thisObject().data());
+ if (c->argumentCount() == 3) {
+ ctx2d->drawImage(c->argument(0).toString()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber());
+ } else if (c->argumentCount() == 5) {
+ ctx2d->drawImage(c->argument(0).toString()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber()
+ ,c->argument(4).toNumber());
+ } else if (c->argumentCount() == 9) {
+ ctx2d->drawImage(c->argument(0).toString()
+ ,c->argument(1).toNumber()
+ ,c->argument(2).toNumber()
+ ,c->argument(3).toNumber()
+ ,c->argument(4).toNumber()
+ ,c->argument(5).toNumber()
+ ,c->argument(6).toNumber()
+ ,c->argument(7).toNumber()
+ ,c->argument(8).toNumber());
+ }
+ return e->nullValue();
+}
+
+// pixel manipulation
+static QScriptValue ctx2d_createImageData(QScriptContext *c, QScriptEngine *e)
+{
+ //#TODO
+ return QScriptValue();
+}
+static QScriptValue ctx2d_getImageData(QScriptContext *c, QScriptEngine *e)
+{
+ //#TODO
+ return QScriptValue();
+}
+static QScriptValue ctx2d_putImageData(QScriptContext *c, QScriptEngine *e)
+{
+ //#TODO
+ return QScriptValue();
+}
+
+//Image Data Interface
+static QScriptValue ctx2d_imageData_data(QScriptContext *c, QScriptEngine *e)
+{
+ //#TODO
+ return QScriptValue();
+}
+static QScriptValue ctx2d_imageData_height(QScriptContext *c, QScriptEngine *e)
+{
+ //#TODO
+ return QScriptValue();
+}
+static QScriptValue ctx2d_imageData_width(QScriptContext *c, QScriptEngine *e)
+{
+ //#TODO
+ return QScriptValue();
+}
+
+//CanvasPixelArray interface
+static QScriptValue ctx2d_pixelArray_length(QScriptContext *c, QScriptEngine *e)
+{
+ //#TODO
+ return QScriptValue();
+}
+//getter/setter by index how to?
+static QScriptValue ctx2d_pixelArray(QScriptContext *c, QScriptEngine *e)
+{
+ //#TODO
+ return QScriptValue();
+}
+
+//CanvasGradient interface
+static QScriptValue ctx2d_gradient_addColorStop(QScriptContext *c, QScriptEngine *e)
+{
+ //#TODO
+ return QScriptValue();
+}
+
+//TextMetrics
+static QScriptValue ctx2d_textMetrics_width(QScriptContext *c, QScriptEngine *e)
+{
+ //#TODO
+ return QScriptValue();
+}
+
+
bool QSGContext2DPrivate::hasShadow() const
{
return state.shadowColor.isValid()
@@ -1623,6 +2164,11 @@ QSGContext2D::QSGContext2D(QSGContext2D *orig, QSGContext2DWorkerAgent* agentDat
d->canvas = qobject_cast<QSGCanvasItem*>(orig);
}
+QSGCanvasItem* QSGContext2D::canvas() const
+{
+ Q_D(const QSGContext2D);
+ return d->canvas;
+}
QSGContext2D::~QSGContext2D()
{
Q_D(QSGContext2D);
@@ -1649,24 +2195,60 @@ void QSGContext2D::setScriptEngine(QScriptEngine *eng)
Q_D(QSGContext2D);
if (d->scriptEngine != eng) {
d->scriptEngine = eng;
-// QScriptValue agent = d->scriptEngine->globalObject().property(QLatin1String("Context2DAgent"));
-// if (!agent.isValid()) {
-// d->scriptEngine->evaluate(QLatin1String(
-// "(function CanvasImageData(w, h, d) {"
-// " this.widht = w;"
-// " this.height = h;"
-// " this.data = d;"
-// " })"));
-// d->scriptEngine->evaluate(agentScript());
-// agent = d->scriptEngine->globalObject().property(QLatin1String("Context2DAgent"));
-// if (!agent.isValid()) {
-// qWarning() << "QSGContext2D:error when evaluating context2d script value!";
-// d->scriptValue = QScriptValue();
-// return;
-// }
-// }
-// QScriptValue o = d->scriptEngine->newQObject(this);
-// d->scriptValue = agent.construct(QScriptValueList() << o);
+ d->scriptValue = eng->newObject();
+ d->scriptValue.setData(eng->toScriptValue(this));
+ d->scriptValue.setProperty(QLatin1String("sync"), eng->newFunction(ctx2d_sync));
+ d->scriptValue.setProperty(QLatin1String("canvas"), eng->newFunction(ctx2d_canvas),QScriptValue::PropertyGetter);
+ d->scriptValue.setProperty(QLatin1String("restore"), eng->newFunction(ctx2d_restore));
+ d->scriptValue.setProperty(QLatin1String("save"), eng->newFunction(ctx2d_save));
+ d->scriptValue.setProperty(QLatin1String("rotate"), eng->newFunction(ctx2d_rotate, 1));
+ d->scriptValue.setProperty(QLatin1String("scale"), eng->newFunction(ctx2d_scale, 2));
+ d->scriptValue.setProperty(QLatin1String("setTransform"), eng->newFunction(ctx2d_setTransform, 6));
+ d->scriptValue.setProperty(QLatin1String("transform"), eng->newFunction(ctx2d_transform, 6));
+ d->scriptValue.setProperty(QLatin1String("translate"), eng->newFunction(ctx2d_translate, 2));
+ d->scriptValue.setProperty(QLatin1String("globalAlpha"), eng->newFunction(ctx2d_globalAlpha), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("globalCompositeOperation"), eng->newFunction(ctx2d_globalCompositeOperation), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("fillStyle"), eng->newFunction(ctx2d_fillStyle), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("strokeStyle"), eng->newFunction(ctx2d_strokeStyle), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("fillColor"), eng->newFunction(ctx2d_fillColor), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("strokeColor"), eng->newFunction(ctx2d_strokeColor), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("createLinearGradient"), eng->newFunction(ctx2d_createLinearGradient, 4));
+ d->scriptValue.setProperty(QLatin1String("createRadialGradient"), eng->newFunction(ctx2d_createRadialGradient, 6));
+ d->scriptValue.setProperty(QLatin1String("createPattern"), eng->newFunction(ctx2d_createPattern, 2));
+ d->scriptValue.setProperty(QLatin1String("lineCap"), eng->newFunction(ctx2d_lineCap), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("lineJoin"), eng->newFunction(ctx2d_lineJoin), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("lineWidth"), eng->newFunction(ctx2d_lineWidth), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("miterLimit"), eng->newFunction(ctx2d_miterLimit), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("shadowBlur"), eng->newFunction(ctx2d_shadowBlur), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("shadowColor"), eng->newFunction(ctx2d_shadowColor), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("shadowOffsetX"), eng->newFunction(ctx2d_shadowOffsetX), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("shadowOffsetY"), eng->newFunction(ctx2d_shadowOffsetY), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("clearRect"), eng->newFunction(ctx2d_clearRect, 4));
+ d->scriptValue.setProperty(QLatin1String("fillRect"), eng->newFunction(ctx2d_fillRect, 4));
+ d->scriptValue.setProperty(QLatin1String("strokeRect"), eng->newFunction(ctx2d_strokeRect, 4));
+ d->scriptValue.setProperty(QLatin1String("arc"), eng->newFunction(ctx2d_arc, 6));
+ d->scriptValue.setProperty(QLatin1String("arcTo"), eng->newFunction(ctx2d_arcTo, 5));
+ d->scriptValue.setProperty(QLatin1String("beginPath"), eng->newFunction(ctx2d_beginPath));
+ d->scriptValue.setProperty(QLatin1String("bezierCurveTo"), eng->newFunction(ctx2d_bezierCurveTo, 6));
+ d->scriptValue.setProperty(QLatin1String("clip"), eng->newFunction(ctx2d_clip));
+ d->scriptValue.setProperty(QLatin1String("closePath"), eng->newFunction(ctx2d_closePath));
+ d->scriptValue.setProperty(QLatin1String("fill"), eng->newFunction(ctx2d_fill));
+ d->scriptValue.setProperty(QLatin1String("lineTo"), eng->newFunction(ctx2d_lineTo, 2));
+ d->scriptValue.setProperty(QLatin1String("moveTo"), eng->newFunction(ctx2d_moveTo, 2));
+ d->scriptValue.setProperty(QLatin1String("quadraticCurveTo"), eng->newFunction(ctx2d_quadraticCurveTo, 4));
+ d->scriptValue.setProperty(QLatin1String("rect"), eng->newFunction(ctx2d_rect, 4));
+ d->scriptValue.setProperty(QLatin1String("stroke"), eng->newFunction(ctx2d_stroke));
+ d->scriptValue.setProperty(QLatin1String("isPointInPath"), eng->newFunction(ctx2d_isPointInPath, 2));
+ d->scriptValue.setProperty(QLatin1String("font"), eng->newFunction(ctx2d_font), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("textAlign"), eng->newFunction(ctx2d_textAlign), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("textBaseline"), eng->newFunction(ctx2d_textBaseline), QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ d->scriptValue.setProperty(QLatin1String("fillText"), eng->newFunction(ctx2d_fillText, 4));
+ //d->scriptValue.setProperty(QLatin1String("measureText"), eng->newFunction(ctx2d_measureText, 1));
+ d->scriptValue.setProperty(QLatin1String("strokeText"), eng->newFunction(ctx2d_strokeText, 4));
+ d->scriptValue.setProperty(QLatin1String("drawImage"), eng->newFunction(ctx2d_drawImage, 9));
+ d->scriptValue.setProperty(QLatin1String("createImageData"), eng->newFunction(ctx2d_createImageData, 2));
+ d->scriptValue.setProperty(QLatin1String("getImageData"), eng->newFunction(ctx2d_getImageData, 4));
+ d->scriptValue.setProperty(QLatin1String("putImageData"), eng->newFunction(ctx2d_putImageData, 7));
}
}
@@ -2380,6 +2962,7 @@ void QSGContext2D::paint(QPainter* p)
qreal y = d->reals[real_idx++];
qreal w = d->reals[real_idx++];
qreal h = d->reals[real_idx++];
+// qDebug() << "fillRect(" << x << y << w << h << ")";
if (d->hasShadow())
d->fillRectShadow(p, QRectF(x, y, w, h));
else
diff --git a/src/declarative/items/qsgcontext2d_p.h b/src/declarative/items/qsgcontext2d_p.h
index 1a900100de..335f71b7e0 100644
--- a/src/declarative/items/qsgcontext2d_p.h
+++ b/src/declarative/items/qsgcontext2d_p.h
@@ -85,38 +85,9 @@ public:
Q_DECLARE_METATYPE(QSGCanvasGradient*)
-//class QSGCanvasImage: public QObject
-//{
-// Q_OBJECT
-// Q_PROPERTY(QString src READ src WRITE setSrc NOTIFY sourceChanged)
-//public:
-// QSGCanvasImage() {}
-// QSGCanvasImage(const QString &url) : m_image(url), m_src(url) {
-// }
-// QSGCanvasImage(const QImage &img) {m_image = img;}
-
-//public slots:
-// QImage &value() { return m_image; }
-// const QImage &value() const{ return m_image; }
-// QString src() { return m_src; }
-// void setSrc(const QString &src) { m_src = src; m_image.load(src); emit sourceChanged();}
-//signals:
-// void sourceChanged();
-
-//private:
-// QSGImage* img;
-// QString src;
-//};
-
-//Q_DECLARE_METATYPE(QSGCanvasImage*)
-
-
-/*
-
- */
-
class QSGContext2DWorkerAgent;
class QSGContext2DPrivate;
+class QSGCanvasItem;
class QSGContext2D : public QObject
{
Q_OBJECT
@@ -215,6 +186,9 @@ public:
QSGContext2D(QObject *parent = 0);
QSGContext2D(QSGContext2D *ctx2d, QSGContext2DWorkerAgent* agentData);
~QSGContext2D();
+
+ QSGCanvasItem* canvas() const;
+
void setSize(int width, int height);
void setSize(const QSize &size);
QSize size() const;
diff --git a/src/declarative/items/qsgdragtarget.cpp b/src/declarative/items/qsgdragtarget.cpp
new file mode 100644
index 0000000000..c1ed167ee6
--- /dev/null
+++ b/src/declarative/items/qsgdragtarget.cpp
@@ -0,0 +1,361 @@
+/****************************************************************************
+**
+** 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 QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgdragtarget_p.h"
+#include "qsgitem_p.h"
+#include "qsgcanvas.h"
+
+/*!
+ \qmlclass DragEvent QSGDragEvent
+ \brief The DragEvent object provides information about a drag event.
+
+ The position of the drag event can be obtained from the \l x and \l
+ properties, the \l keys property identifies the drag keys of the event
+ source and the \l data property contains the payload of the drag event.
+*/
+
+/*!
+ \qmlproperty real DragEvent::x
+
+ This property holds the x coordinate of a drag event.
+*/
+
+/*!
+ \qmlproperty real DragEvent::y
+
+ This property holds the y coordinate of a drag event.
+*/
+
+/*!
+ \qmlproperty stringlist DragEvent::keys
+
+ This property holds a list of keys identifying the data type or source of a
+ drag event.
+*/
+
+/*!
+ \qmlproperty variant DragEvent::data
+
+ This property holds data payload of a drag event.
+*/
+
+/*!
+ \qmlproperty real DragEvent::accepted
+
+ This property holds whether the drag event was accepted by a handler.
+
+ The default value is true.
+*/
+
+class QSGDragTargetPrivate : public QSGItemPrivate
+{
+ Q_DECLARE_PUBLIC(QSGDragTarget)
+
+public:
+ QSGDragTargetPrivate();
+ ~QSGDragTargetPrivate();
+
+ bool hasMatchingKey(const QStringList &keys) const;
+
+ QStringList keys;
+ QRegExp keyRegExp;
+ QVariant dragData;
+ QPointF dragPosition;
+ QSGItem *dropItem;
+ bool containsDrag : 1;
+};
+
+QSGDragTargetPrivate::QSGDragTargetPrivate()
+ : dropItem(0)
+ , containsDrag(false)
+{
+}
+
+QSGDragTargetPrivate::~QSGDragTargetPrivate()
+{
+}
+
+/*!
+ \qmlclass DragTarget QSGDragTarget
+ \brief The DragTarget item provides drag and drop handling.
+
+ A DragTarget is an invisible item which receives events when another item
+ is dragged over it.
+
+ A MouseArea item can be used to drag items.
+
+ The \l keys property can be used to filter drag events which don't include
+ a matching key.
+
+ The \l dropItem property is communicated to the source of a drag event as
+ the recipient of a drop on the drag target.
+
+ The \l delegate property provides a means to specify a component to be
+ instantiated for each active drag over a drag target.
+*/
+
+QSGDragTarget::QSGDragTarget(QSGItem *parent)
+ : QSGItem(*new QSGDragTargetPrivate, parent)
+{
+}
+
+QSGDragTarget::~QSGDragTarget()
+{
+}
+
+/*!
+ \qmlproperty bool DragTarget::containsDrag
+
+ This property identifies whether the DragTarget currently contains any
+ dragged items.
+*/
+
+bool QSGDragTarget::containsDrag() const
+{
+ Q_D(const QSGDragTarget);
+ return d->containsDrag;
+}
+
+/*!
+ \qmlproperty stringlist DragTarget::keys
+
+ This property holds a list of drag keys a DragTarget will accept.
+*/
+
+QStringList QSGDragTarget::keys() const
+{
+ Q_D(const QSGDragTarget);
+ return d->keys;
+}
+
+void QSGDragTarget::setKeys(const QStringList &keys)
+{
+ Q_D(QSGDragTarget);
+ if (d->keys != keys) {
+ d->keys = keys;
+
+ if (keys.isEmpty()) {
+ d->keyRegExp = QRegExp();
+ } else {
+ QString pattern = QLatin1Char('(') + QRegExp::escape(keys.first());
+ for (int i = 1; i < keys.count(); ++i)
+ pattern += QLatin1Char('|') + QRegExp::escape(keys.at(i));
+ pattern += QLatin1Char(')');
+ d->keyRegExp = QRegExp(pattern.replace(QLatin1String("\\*"), QLatin1String(".+")));
+ }
+ emit keysChanged();
+ }
+}
+
+/*!
+ \qmlproperty Item DragTarget::dropItem
+
+ This property identifies an item as the recipient of a drop event within
+ a DragTarget.
+
+ \sa MouseArea::drag.dropItem
+*/
+
+QSGItem *QSGDragTarget::dropItem() const
+{
+ Q_D(const QSGDragTarget);
+ return d->dropItem;
+}
+
+void QSGDragTarget::setDropItem(QSGItem *item)
+{
+ Q_D(QSGDragTarget);
+ if (d->dropItem != item) {
+ d->dropItem = item;
+ emit dropItemChanged();
+ }
+}
+
+void QSGDragTarget::resetDropItem()
+{
+ Q_D(QSGDragTarget);
+ if (d->dropItem) {
+ d->dropItem = 0;
+ emit dropItemChanged();
+ }
+}
+
+qreal QSGDragTarget::dragX() const
+{
+ Q_D(const QSGDragTarget);
+ return d->dragPosition.x();
+}
+
+qreal QSGDragTarget::dragY() const
+{
+ Q_D(const QSGDragTarget);
+ return d->dragPosition.y();
+}
+
+QVariant QSGDragTarget::dragData() const
+{
+ Q_D(const QSGDragTarget);
+ return d->dragData;
+}
+
+/*!
+ \qmlsignal DragTarget::onPositionChanged(DragEvent drag)
+ \qmlattachedsignal DragTarget::onPositionChanged(DragEvent drag)
+
+ This handler is called when the position of a drag has changed.
+*/
+
+void QSGDragTarget::dragMoveEvent(QSGDragEvent *event)
+{
+ Q_D(QSGDragTarget);
+ if (!d->containsDrag) {
+ event->setAccepted(false);
+ return;
+ }
+
+ event->setDropItem(d->dropItem);
+
+ d->dragPosition = event->position();
+ emit dragPositionChanged();
+
+ QSGDragTargetEvent dragTargetEvent(event);
+ emit positionChanged(&dragTargetEvent);
+}
+
+bool QSGDragTargetPrivate::hasMatchingKey(const QStringList &keys) const
+{
+ if (keyRegExp.isEmpty())
+ return true;
+
+ foreach (const QString &key, keys) {
+ if (keyRegExp.exactMatch(key))
+ return true;
+ }
+ return false;
+}
+
+/*!
+ \qmlsignal DragTarget::onEntered(DragEvent drag)
+ \qmlattachedsignal DragTarget::onEntered(DragEvent drag)
+
+ This handler is called when a drag enters the bounds of a DragTarget.
+*/
+
+void QSGDragTarget::dragEnterEvent(QSGDragEvent *event)
+{
+ Q_D(QSGDragTarget);
+ if (!d->effectiveEnable || !d->hasMatchingKey(event->keys()) || d->containsDrag) {
+ event->setAccepted(false);
+ return;
+ }
+
+ event->setDropItem(d->dropItem);
+
+ QSGDragTargetEvent dragTargetEvent(event);
+ emit entered(&dragTargetEvent);
+
+ if (event->isAccepted()) {
+
+ d->dragData = event->data();
+ d->containsDrag = true;
+ if (!d->dragData.isNull())
+ emit dragDataChanged();
+ emit containsDragChanged();
+ }
+}
+
+/*!
+ \qmlsignal DragTarget::onExited(DragEvent drag)
+ \qmlattachedsignal DragTarget::onExited(DragEvent drag)
+
+ This handler is called when a drag exits the bounds of a DragTarget.
+*/
+
+void QSGDragTarget::dragExitEvent(QSGDragEvent *event)
+{
+ Q_D(QSGDragTarget);
+ if (!d->containsDrag) {
+ event->setAccepted(false);
+ return;
+ }
+
+ QSGDragTargetEvent dragTargetEvent(event);
+ emit exited(&dragTargetEvent);
+
+ d->containsDrag = false;
+ emit containsDragChanged();
+ if (!d->dragData.isNull()) {
+ d->dragData = QVariant();
+ emit dragDataChanged();
+ }
+}
+
+/*!
+ \qmlsignal DragTarget::onDropped(DragEvent drag)
+ \qmlattachedsignal DragTarget::onDropped(DragEvent drag)
+
+ This handler is called when a drop event occurs within the bounds of a
+ a DragTarget.
+*/
+
+void QSGDragTarget::dragDropEvent(QSGDragEvent *event)
+{
+ Q_D(QSGDragTarget);
+ if (!d->containsDrag) {
+ event->setAccepted(false);
+ return;
+ }
+
+ event->setDropItem(d->dropItem);
+
+ QSGDragTargetEvent dragTargetEvent(event);
+ emit dropped(&dragTargetEvent);
+
+ d->containsDrag = false;
+ emit containsDragChanged();
+ if (!d->dragData.isNull()) {
+ d->dragData = QVariant();
+ emit dragDataChanged();
+ }
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/declarative/items/qsgdragtarget_p.h b/src/declarative/items/qsgdragtarget_p.h
new file mode 100644
index 0000000000..ad13e11854
--- /dev/null
+++ b/src/declarative/items/qsgdragtarget_p.h
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** 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 QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGDRAGTARGET_P_H
+#define QSGDRAGTARGET_P_H
+
+#include "qsgitem.h"
+#include "qsgevent.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QSGDragTargetEvent : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal x READ x)
+ Q_PROPERTY(qreal y READ y)
+ Q_PROPERTY(QVariant data READ data)
+ Q_PROPERTY(QStringList keys READ keys)
+ Q_PROPERTY(bool accepted READ accepted WRITE setAccepted)
+public:
+ QSGDragTargetEvent(QSGDragEvent *event) : _event(event) {}
+
+ qreal x() const { return _event->x(); }
+ qreal y() const { return _event->y(); }
+
+ QVariant data() const { return _event->data(); }
+ QStringList keys() const { return _event->keys(); }
+
+ bool accepted() const { return _event->isAccepted(); }
+ void setAccepted(bool accepted) { _event->setAccepted(accepted); }
+
+private:
+ QSGDragEvent *_event;
+};
+
+class QSGDragTargetPrivate;
+class Q_AUTOTEST_EXPORT QSGDragTarget : public QSGItem
+{
+ Q_OBJECT
+ Q_PROPERTY(bool containsDrag READ containsDrag NOTIFY containsDragChanged)
+ Q_PROPERTY(QSGItem *dropItem READ dropItem WRITE setDropItem NOTIFY dropItemChanged RESET resetDropItem)
+ Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged)
+ Q_PROPERTY(qreal dragX READ dragX NOTIFY dragPositionChanged)
+ Q_PROPERTY(qreal dragY READ dragY NOTIFY dragPositionChanged)
+ Q_PROPERTY(QVariant dragData READ dragData NOTIFY dragDataChanged)
+
+public:
+ QSGDragTarget(QSGItem *parent=0);
+ ~QSGDragTarget();
+
+ bool containsDrag() const;
+ void setContainsDrag(bool drag);
+
+ QStringList keys() const;
+ void setKeys(const QStringList &keys);
+
+ QSGItem *dropItem() const;
+ void setDropItem(QSGItem *item);
+ void resetDropItem();
+
+ qreal dragX() const;
+ qreal dragY() const;
+ QVariant dragData() const;
+
+Q_SIGNALS:
+ void containsDragChanged();
+ void keysChanged();
+ void dropItemChanged();
+ void dragPositionChanged();
+ void dragDataChanged();
+
+ void entered(QSGDragTargetEvent *drag);
+ void exited(QSGDragTargetEvent *drag);
+ void positionChanged(QSGDragTargetEvent *drag);
+ void dropped(QSGDragTargetEvent *drag);
+
+protected:
+ void dragMoveEvent(QSGDragEvent *event);
+ void dragEnterEvent(QSGDragEvent *event);
+ void dragExitEvent(QSGDragEvent *event);
+ void dragDropEvent(QSGDragEvent *event);
+
+private:
+ Q_DISABLE_COPY(QSGDragTarget)
+ Q_DECLARE_PRIVATE(QSGDragTarget)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QSGDragTargetEvent)
+QML_DECLARE_TYPE(QSGDragTarget)
+
+QT_END_HEADER
+
+#endif // QSGDRAGTARGET_P_H
diff --git a/src/declarative/items/qsgevent.h b/src/declarative/items/qsgevent.h
new file mode 100644
index 0000000000..93b53d1312
--- /dev/null
+++ b/src/declarative/items/qsgevent.h
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDRAGEVENT_H
+#define QDRAGEVENT_H
+
+#include <QtCore/qcoreevent.h>
+#include <QtCore/qnamespace.h>
+#include <QtCore/qpoint.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qvariant.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QSGItem;
+
+class Q_DECLARATIVE_EXPORT QSGEvent : public QEvent
+{
+public:
+ // XXX: Merge types into QEvent or formally reserve a suitable range.
+ // Alternatively start from QEvent::User and add a SGUser value for use by items.
+ enum SGType
+ {
+ SGDragEnter = 600,
+ SGDragExit,
+ SGDragMove,
+ SGDragDrop
+ };
+
+ QSGEvent(QSGEvent::SGType type) : QEvent(Type(type)) {}
+
+ SGType type() const { return SGType(QEvent::type()); }
+};
+
+class Q_DECLARATIVE_EXPORT QSGDragEvent : public QSGEvent
+{
+public:
+ QSGDragEvent(
+ SGType type,
+ const QPointF &scenePosition,
+ const QVariant &data,
+ const QStringList &keys,
+ QSGItem *grabItem = 0)
+ : QSGEvent(type)
+ , _scenePosition(scenePosition),
+ _data(data)
+ , _keys(keys)
+ , _dropItem(0)
+ , _grabItem(grabItem)
+ {
+ }
+ QSGDragEvent(SGType type, const QSGDragEvent &event)
+ : QSGEvent(type)
+ , _scenePosition(event._scenePosition)
+ , _position(event._position)
+ , _data(event._data)
+ , _keys(event._keys)
+ , _dropItem(event._dropItem)
+ , _grabItem(event._grabItem)
+ {
+ }
+
+ QVariant data() const { return _data; }
+
+ qreal x() const { return _position.x(); }
+ qreal y() const { return _position.y(); }
+ QPointF position() const { return _position; }
+ void setPosition(const QPointF &position) { _position = position; }
+
+ QPointF scenePosition() const { return _scenePosition; }
+
+ QStringList keys() const { return _keys; }
+
+ QSGItem *dropItem() const { return _dropItem; }
+ void setDropItem(QSGItem *dropItem) { _dropItem = dropItem; }
+
+ QSGItem *grabItem() const { return _grabItem; }
+ void setGrabItem(QSGItem *item) { _grabItem = item; }
+
+private:
+ QPointF _scenePosition;
+ QPointF _position;
+ QVariant _data;
+ QStringList _keys;
+ QSGItem *_dropItem;
+ QSGItem *_grabItem;
+};
+
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
+
diff --git a/src/declarative/items/qsgitem.cpp b/src/declarative/items/qsgitem.cpp
index aa8fec7061..9bbed05dd5 100644
--- a/src/declarative/items/qsgitem.cpp
+++ b/src/declarative/items/qsgitem.cpp
@@ -44,6 +44,7 @@
#include "qsgcanvas.h"
#include <QtScript/qscriptengine.h>
#include "qsgcanvas_p.h"
+#include "qsgevent.h"
#include "qsgevents_p_p.h"
@@ -1688,6 +1689,26 @@ void QSGItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Q_UNUSED(event);
}
+void QSGItem::dragMoveEvent(QSGDragEvent *event)
+{
+ event->setAccepted(false);
+}
+
+void QSGItem::dragEnterEvent(QSGDragEvent *event)
+{
+ event->setAccepted(false);
+}
+
+void QSGItem::dragExitEvent(QSGDragEvent *event)
+{
+ event->setAccepted(false);
+}
+
+void QSGItem::dragDropEvent(QSGDragEvent *event)
+{
+ event->setAccepted(false);
+}
+
bool QSGItem::childMouseEventFilter(QSGItem *, QEvent *)
{
return false;
@@ -2149,6 +2170,27 @@ void QSGItemPrivate::deliverHoverEvent(QGraphicsSceneHoverEvent *e)
}
}
+void QSGItemPrivate::deliverDragEvent(QSGDragEvent *e)
+{
+ Q_Q(QSGItem);
+ switch (e->type()) {
+ default:
+ Q_ASSERT(!"Unknown event type");
+ case QSGEvent::SGDragEnter:
+ q->dragEnterEvent(e);
+ break;
+ case QSGEvent::SGDragExit:
+ q->dragExitEvent(e);
+ break;
+ case QSGEvent::SGDragMove:
+ q->dragMoveEvent(e);
+ break;
+ case QSGEvent::SGDragDrop:
+ q->dragDropEvent(e);
+ break;
+ }
+}
+
void QSGItem::itemChange(ItemChange change, const ItemChangeData &value)
{
Q_UNUSED(change);
diff --git a/src/declarative/items/qsgitem.h b/src/declarative/items/qsgitem.h
index 564d819000..995b5cbcd1 100644
--- a/src/declarative/items/qsgitem.h
+++ b/src/declarative/items/qsgitem.h
@@ -89,6 +89,7 @@ class QSGKeyEvent;
class QSGAnchors;
class QSGItemPrivate;
class QSGCanvas;
+class QSGDragEvent;
class QSGEngine;
class QTouchEvent;
class QSGNode;
@@ -363,6 +364,10 @@ protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+ virtual void dragMoveEvent(QSGDragEvent *event);
+ virtual void dragEnterEvent(QSGDragEvent *event);
+ virtual void dragExitEvent(QSGDragEvent *event);
+ virtual void dragDropEvent(QSGDragEvent *event);
virtual bool childMouseEventFilter(QSGItem *, QEvent *);
virtual void geometryChanged(const QRectF &newGeometry,
diff --git a/src/declarative/items/qsgitem_p.h b/src/declarative/items/qsgitem_p.h
index c955c44fe6..0b3348d7fc 100644
--- a/src/declarative/items/qsgitem_p.h
+++ b/src/declarative/items/qsgitem_p.h
@@ -324,6 +324,7 @@ public:
void deliverWheelEvent(QGraphicsSceneWheelEvent *);
void deliverTouchEvent(QTouchEvent *);
void deliverHoverEvent(QGraphicsSceneHoverEvent *);
+ void deliverDragEvent(QSGDragEvent *);
bool calcEffectiveVisible() const;
void setEffectiveVisibleRecur(bool);
diff --git a/src/declarative/items/qsgitemsmodule.cpp b/src/declarative/items/qsgitemsmodule.cpp
index e5fcfeed6f..a3752fcec8 100644
--- a/src/declarative/items/qsgitemsmodule.cpp
+++ b/src/declarative/items/qsgitemsmodule.cpp
@@ -74,6 +74,9 @@
//#include "private/qsgpincharea_p.h"
#include "qsgcanvasitem_p.h"
#include "qsgcontext2d_p.h"
+#include "qsgsprite_p.h"
+#include "qsgspriteimage_p.h"
+#include "qsgdragtarget_p.h"
static QDeclarativePrivate::AutoParentResult qsgitem_autoParent(QObject *obj, QObject *parent)
{
@@ -178,12 +181,17 @@ static void qt_sgitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QSGContext2D>();
qmlRegisterType<QSGCanvasGradient>();
+ qmlRegisterType<QSGSprite>("QtQuick", 2, 0, "Sprite");
+ qmlRegisterType<QSGSpriteImage>("QtQuick", 2, 0, "SpriteImage");
qmlRegisterType<QSGParentChange>(uri, major, minor,"ParentChange");
qmlRegisterType<QSGAnchorChanges>(uri, major, minor,"AnchorChanges");
qmlRegisterType<QSGAnchorSet>();
qmlRegisterType<QSGAnchorAnimation>(uri, major, minor,"AnchorAnimation");
qmlRegisterType<QSGParentAnimation>(uri, major, minor,"ParentAnimation");
+
+ qmlRegisterType<QSGDragTarget>("QtQuick", 2, 0, "DragTarget");
+ qmlRegisterType<QSGDragTargetEvent>();
}
void QSGItemsModule::defineModule()
diff --git a/src/declarative/items/qsgmousearea.cpp b/src/declarative/items/qsgmousearea.cpp
index 62b149567a..6886ccca35 100644
--- a/src/declarative/items/qsgmousearea.cpp
+++ b/src/declarative/items/qsgmousearea.cpp
@@ -42,6 +42,7 @@
#include "qsgmousearea_p.h"
#include "qsgmousearea_p_p.h"
#include "qsgcanvas.h"
+#include "qsgevent.h"
#include "qsgevents_p_p.h"
#include <QtGui/qgraphicssceneevent.h>
@@ -53,8 +54,8 @@ QT_BEGIN_NAMESPACE
static const int PressAndHoldDelay = 800;
QSGDrag::QSGDrag(QObject *parent)
-: QObject(parent), _target(0), _axis(XandYAxis), _xmin(-FLT_MAX), _xmax(FLT_MAX), _ymin(-FLT_MAX), _ymax(FLT_MAX),
-_active(false), _filterChildren(false)
+: QObject(parent), _target(0), _dropItem(0), _grabItem(0), _axis(XandYAxis), _xmin(-FLT_MAX),
+_xmax(FLT_MAX), _ymin(-FLT_MAX), _ymax(FLT_MAX), _active(false), _filterChildren(false)
{
}
@@ -77,12 +78,70 @@ void QSGDrag::setTarget(QSGItem *t)
void QSGDrag::resetTarget()
{
- if (!_target)
+ if (_target == 0)
return;
_target = 0;
emit targetChanged();
}
+/*!
+ \qmlproperty Item MouseArea::drag.dropItem
+
+ This property holds the item an active drag will be dropped on if released
+ at the current position.
+*/
+
+QSGItem *QSGDrag::dropItem() const
+{
+ return _dropItem;
+}
+
+void QSGDrag::setDropItem(QSGItem *item)
+{
+ if (_dropItem != item) {
+ _dropItem = item;
+ emit dropItemChanged();
+ }
+}
+
+QSGItem *QSGDrag::grabItem() const
+{
+ return _grabItem;
+}
+
+void QSGDrag::setGrabItem(QSGItem *item)
+{
+ _grabItem = item;
+}
+
+/*!
+ \qmlproperty variant MouseArea::drag.data
+
+ This property holds the data sent to recipients of drag events generated
+ by a MouseArea.
+*/
+
+QVariant QSGDrag::data() const
+{
+ return _data;
+}
+
+void QSGDrag::setData(const QVariant &data)
+{
+ if (_data != data) {
+ _data = data;
+ emit dataChanged();
+ }
+}
+
+void QSGDrag::resetData()
+{
+ if (!_data.isNull()) {
+ _data = QVariant();
+ emit dataChanged();
+ }
+}
+
QSGDrag::Axis QSGDrag::axis() const
{
return _axis;
@@ -174,9 +233,30 @@ void QSGDrag::setFilterChildren(bool filter)
emit filterChildrenChanged();
}
+/*!
+ \qmlproperty stringlist MouseArea::drag.keys
+
+ This property holds a list of keys drag recipients can use to identify the
+ source or data type of a drag event.
+*/
+
+QStringList QSGDrag::keys() const
+{
+ return _keys;
+}
+
+void QSGDrag::setKeys(const QStringList &keys)
+{
+ if (_keys != keys) {
+ _keys = keys;
+ emit keysChanged();
+ }
+}
+
QSGMouseAreaPrivate::QSGMouseAreaPrivate()
: absorb(true), hovered(false), pressed(false), longPress(false),
- moved(false), stealMouse(false), doubleClick(false), preventStealing(false), drag(0)
+ moved(false), stealMouse(false), doubleClick(false), preventStealing(false), dragRejected(false),
+ drag(0)
{
Q_Q(QSGMouseArea);
forwardTo = QDeclarativeListProperty<QSGItem>(q, forwardToList);
@@ -383,6 +463,7 @@ void QSGMouseArea::mousePressEvent(QGraphicsSceneMouseEvent *event)
QSGItem::mousePressEvent(event);
else {
d->longPress = false;
+ d->dragRejected = false;
d->saveEvent(event);
if (d->drag) {
d->dragX = drag()->axis() & QSGDrag::XAxis;
@@ -420,9 +501,11 @@ void QSGMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
setHovered(true);
if (d->drag && d->drag->target()) {
+
if (!d->moved) {
- d->startX = drag()->target()->x();
- d->startY = drag()->target()->y();
+ d->targetStartPos = d->drag->target()->parentItem()
+ ? d->drag->target()->parentItem()->mapToScene(d->drag->target()->pos())
+ : d->drag->target()->pos();
}
QPointF startLocalPos;
@@ -439,11 +522,31 @@ void QSGMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
qreal dx = qAbs(curLocalPos.x() - startLocalPos.x());
qreal dy = qAbs(curLocalPos.y() - startLocalPos.y());
- if (keepMouseGrab() && d->stealMouse)
- d->drag->setActive(true);
+ if (keepMouseGrab() && d->stealMouse && !d->dragRejected && !d->drag->active()) {
+ QSGMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress);
+ d->drag->emitDragged(&me);
+ if (me.isAccepted()) {
+ d->drag->setActive(true);
+ QSGDragEvent dragEvent(
+ QSGEvent::SGDragEnter,
+ d->startScene,
+ d->drag->data(),
+ d->drag->keys());
+ QCoreApplication::sendEvent(canvas(), &dragEvent);
+
+ d->drag->setGrabItem(dragEvent.grabItem());
+ d->drag->setDropItem(dragEvent.dropItem());
+ } else {
+ d->dragRejected = true;
+ }
+ }
+
+ QPointF startPos = d->drag->target()->parentItem()
+ ? d->drag->target()->parentItem()->mapFromScene(d->targetStartPos)
+ : d->targetStartPos;
if (d->dragX && d->drag->active()) {
- qreal x = (curLocalPos.x() - startLocalPos.x()) + d->startX;
+ qreal x = (curLocalPos.x() - startLocalPos.x()) + startPos.x();
if (x < drag()->xmin())
x = drag()->xmin();
else if (x > drag()->xmax())
@@ -451,7 +554,7 @@ void QSGMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
drag()->target()->setX(x);
}
if (d->dragY && d->drag->active()) {
- qreal y = (curLocalPos.y() - startLocalPos.y()) + d->startY;
+ qreal y = (curLocalPos.y() - startLocalPos.y()) + startPos.y();
if (y < drag()->ymin())
y = drag()->ymin();
else if (y > drag()->ymax())
@@ -469,6 +572,18 @@ void QSGMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
d->moved = true;
+
+ if (d->drag->active()) {
+ QSGDragEvent dragEvent(
+ QSGEvent::SGDragMove,
+ event->scenePos(),
+ d->drag->data(),
+ d->drag->keys(),
+ d->drag->grabItem());
+ QCoreApplication::sendEvent(canvas(), &dragEvent);
+ d->drag->setGrabItem(dragEvent.grabItem());
+ d->drag->setDropItem(dragEvent.dropItem());
+ }
}
QSGMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress);
emit mousePositionChanged(&me);
@@ -489,8 +604,24 @@ void QSGMouseArea::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
} else {
d->saveEvent(event);
setPressed(false);
- if (d->drag)
+ if (d->drag && d->drag->active()) {
+ QSGDragEvent dragEvent(
+ QSGEvent::SGDragDrop,
+ event->scenePos(),
+ d->drag->data(),
+ d->drag->keys(),
+ d->drag->grabItem());
+ QCoreApplication::sendEvent(canvas(), &dragEvent);
+ d->drag->setGrabItem(0);
+ if (dragEvent.isAccepted()) {
+ d->drag->setDropItem(dragEvent.dropItem());
+ d->drag->emitDropped(dragEvent.dropItem());
+ } else {
+ d->drag->emitCanceled();
+ }
+ d->drag->setDropItem(0);
d->drag->setActive(false);
+ }
// If we don't accept hover, we need to reset containsMouse.
if (!acceptHoverEvents())
setHovered(false);
diff --git a/src/declarative/items/qsgmousearea_p.h b/src/declarative/items/qsgmousearea_p.h
index 469b9f7168..d7248bca37 100644
--- a/src/declarative/items/qsgmousearea_p.h
+++ b/src/declarative/items/qsgmousearea_p.h
@@ -51,12 +51,15 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
+class QSGMouseEvent;
class Q_AUTOTEST_EXPORT QSGDrag : public QObject
{
Q_OBJECT
Q_ENUMS(Axis)
Q_PROPERTY(QSGItem *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget)
+ Q_PROPERTY(QSGItem *dropItem READ dropItem NOTIFY dropItemChanged)
+ Q_PROPERTY(QVariant data READ data WRITE setData NOTIFY dataChanged RESET resetData)
Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged)
Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged)
Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged)
@@ -64,6 +67,7 @@ class Q_AUTOTEST_EXPORT QSGDrag : public QObject
Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged)
Q_PROPERTY(bool active READ active NOTIFY activeChanged)
Q_PROPERTY(bool filterChildren READ filterChildren WRITE setFilterChildren NOTIFY filterChildrenChanged)
+ Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged)
//### consider drag and drop
public:
@@ -74,6 +78,16 @@ public:
void setTarget(QSGItem *);
void resetTarget();
+ QSGItem *dropItem() const;
+ void setDropItem(QSGItem *item);
+
+ QSGItem *grabItem() const;
+ void setGrabItem(QSGItem *grabItem);
+
+ QVariant data() const;
+ void setData(const QVariant &data);
+ void resetData();
+
enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 };
Axis axis() const;
void setAxis(Axis);
@@ -93,8 +107,17 @@ public:
bool filterChildren() const;
void setFilterChildren(bool);
+ QStringList keys() const;
+ void setKeys(const QStringList &keys);
+
+ void emitDragged(QSGMouseEvent *event) { emit dragged(event); }
+ void emitDropped(QSGItem *dropItem) { emit dropped(dropItem); }
+ void emitCanceled() { emit canceled(); }
+
Q_SIGNALS:
void targetChanged();
+ void dropItemChanged();
+ void dataChanged();
void axisChanged();
void minimumXChanged();
void maximumXChanged();
@@ -102,9 +125,17 @@ Q_SIGNALS:
void maximumYChanged();
void activeChanged();
void filterChildrenChanged();
+ void keysChanged();
+ void dragged(QSGMouseEvent *mouse);
+ void dropped(QSGItem *dropItem);
+ void canceled();
private:
+ QStringList _keys;
+ QVariant _data;
QSGItem *_target;
+ QSGItem *_dropItem;
+ QSGItem *_grabItem;
Axis _axis;
qreal _xmin;
qreal _xmax;
@@ -115,7 +146,6 @@ private:
Q_DISABLE_COPY(QSGDrag)
};
-class QSGMouseEvent;
class QSGMouseAreaPrivate;
class Q_AUTOTEST_EXPORT QSGMouseArea : public QSGItem
{
diff --git a/src/declarative/items/qsgmousearea_p_p.h b/src/declarative/items/qsgmousearea_p_p.h
index e736c059a2..0eb0444224 100644
--- a/src/declarative/items/qsgmousearea_p_p.h
+++ b/src/declarative/items/qsgmousearea_p_p.h
@@ -96,10 +96,10 @@ public:
bool stealMouse : 1;
bool doubleClick : 1;
bool preventStealing : 1;
+ bool dragRejected : 1;
QSGDrag *drag;
QPointF startScene;
- qreal startX;
- qreal startY;
+ QPointF targetStartPos;
QPointF lastPos;
QDeclarativeNullableValue<QPointF> lastScenePos;
Qt::MouseButton lastButton;
diff --git a/src/declarative/items/qsgshadereffectitem.cpp b/src/declarative/items/qsgshadereffectitem.cpp
index 44e075c6f7..3fae0f15fd 100644
--- a/src/declarative/items/qsgshadereffectitem.cpp
+++ b/src/declarative/items/qsgshadereffectitem.cpp
@@ -540,6 +540,7 @@ QSGNode *QSGShaderEffectItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeD
s.fragmentCode = qt_default_fragment_code;
if (s.vertexCode.isEmpty())
s.vertexCode = qt_default_vertex_code;
+ s.className = metaObject()->className();
m_material.setProgramSource(s);
node->markDirty(QSGNode::DirtyMaterial);
diff --git a/src/declarative/items/qsgshadereffectmesh.cpp b/src/declarative/items/qsgshadereffectmesh.cpp
index 4900755e46..05131285df 100644
--- a/src/declarative/items/qsgshadereffectmesh.cpp
+++ b/src/declarative/items/qsgshadereffectmesh.cpp
@@ -135,11 +135,6 @@ QSGGeometry *QSGGridMesh::updateGeometry(QSGGeometry *geometry, const QVector<QB
break;
}
- if (error) {
- delete geometry;
- return 0;
- }
-
geometry = new QSGGeometry(attrCount == 1
? QSGGeometry::defaultAttributes_Point2D()
: QSGGeometry::defaultAttributes_TexturedPoint2D(),
@@ -203,7 +198,6 @@ void QSGGridMesh::setResolution(const QSize &res)
if (res == m_resolution)
return;
if (res.width() < 1 || res.height() < 1) {
- qWarning("QSGGridMesh: Resolution must be at least 1x1");
return;
}
m_resolution = res;
diff --git a/src/declarative/items/qsgshadereffectnode.cpp b/src/declarative/items/qsgshadereffectnode.cpp
index 74cd995d0d..5d3efb934c 100644
--- a/src/declarative/items/qsgshadereffectnode.cpp
+++ b/src/declarative/items/qsgshadereffectnode.cpp
@@ -84,6 +84,7 @@ QSGCustomMaterialShader::QSGCustomMaterialShader(const QSGShaderEffectMaterialKe
void QSGCustomMaterialShader::deactivate()
{
+ QSGMaterialShader::deactivate();
glDisable(GL_CULL_FACE);
}
diff --git a/src/imports/particles/spritestate.cpp b/src/declarative/items/qsgsprite.cpp
index 72535c0e73..694976a540 100644
--- a/src/imports/particles/spritestate.cpp
+++ b/src/declarative/items/qsgsprite.cpp
@@ -39,11 +39,11 @@
**
****************************************************************************/
-#include "spritestate.h"
+#include "qsgsprite_p.h"
QT_BEGIN_NAMESPACE
-SpriteState::SpriteState(QObject *parent) :
+QSGSprite::QSGSprite(QObject *parent) :
QObject(parent)
, m_generatedCount(0)
, m_framesPerRow(0)
diff --git a/src/imports/particles/spritestate.h b/src/declarative/items/qsgsprite_p.h
index 5157a8bb31..652a4cd482 100644
--- a/src/imports/particles/spritestate.h
+++ b/src/declarative/items/qsgsprite_p.h
@@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class SpriteState : public QObject
+class QSGSprite : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
@@ -69,7 +69,7 @@ class SpriteState : public QObject
Q_PROPERTY(QVariantMap to READ to WRITE setTo NOTIFY toChanged)
public:
- explicit SpriteState(QObject *parent = 0);
+ explicit QSGSprite(QObject *parent = 0);
QUrl source() const
{
@@ -211,8 +211,8 @@ public slots:
}
private:
- friend class SpriteParticle;
- friend class SpriteEngine;
+ friend class QSGImageParticle;
+ friend class QSGSpriteEngine;
int m_generatedCount;
int m_framesPerRow;
QUrl m_source;
diff --git a/src/imports/particles/spriteengine.cpp b/src/declarative/items/qsgspriteengine.cpp
index 7676d9ed46..27de0d94f6 100644
--- a/src/imports/particles/spriteengine.cpp
+++ b/src/declarative/items/qsgspriteengine.cpp
@@ -39,8 +39,8 @@
**
****************************************************************************/
-#include "spriteengine.h"
-#include "spritestate.h"
+#include "qsgspriteengine_p.h"
+#include "qsgsprite_p.h"
#include <QDebug>
#include <QPainter>
#include <QSet>
@@ -48,7 +48,7 @@
QT_BEGIN_NAMESPACE
-SpriteEngine::SpriteEngine(QObject *parent) :
+QSGSpriteEngine::QSGSpriteEngine(QObject *parent) :
QObject(parent), m_timeOffset(0)
{
//Default size 1
@@ -56,7 +56,7 @@ SpriteEngine::SpriteEngine(QObject *parent) :
m_advanceTime.start();
}
-SpriteEngine::SpriteEngine(QList<SpriteState*> states, QObject *parent) :
+QSGSpriteEngine::QSGSpriteEngine(QList<QSGSprite*> states, QObject *parent) :
QObject(parent), m_states(states), m_timeOffset(0)
{
//Default size 1
@@ -64,11 +64,11 @@ SpriteEngine::SpriteEngine(QList<SpriteState*> states, QObject *parent) :
m_advanceTime.start();
}
-SpriteEngine::~SpriteEngine()
+QSGSpriteEngine::~QSGSpriteEngine()
{
}
-int SpriteEngine::maxFrames()
+int QSGSpriteEngine::maxFrames()
{
return m_maxFrames;
}
@@ -79,7 +79,7 @@ int SpriteEngine::maxFrames()
But States maintain their listed index for internal structures
TODO: All these calculations should be pre-calculated and cached during initialization for a significant performance boost
*/
-int SpriteEngine::spriteState(int sprite)
+int QSGSpriteEngine::spriteState(int sprite)
{
int state = m_sprites[sprite];
if(!m_states[state]->m_generatedCount)
@@ -89,7 +89,7 @@ int SpriteEngine::spriteState(int sprite)
return state + extra;
}
-int SpriteEngine::spriteStart(int sprite)
+int QSGSpriteEngine::spriteStart(int sprite)
{
int state = m_sprites[sprite];
if(!m_states[state]->m_generatedCount)
@@ -99,7 +99,7 @@ int SpriteEngine::spriteStart(int sprite)
return state + extra*rowDuration;
}
-int SpriteEngine::spriteFrames(int sprite)
+int QSGSpriteEngine::spriteFrames(int sprite)
{
int state = m_sprites[sprite];
if(!m_states[state]->m_generatedCount)
@@ -112,7 +112,7 @@ int SpriteEngine::spriteFrames(int sprite)
return m_states[state]->m_framesPerRow;
}
-int SpriteEngine::spriteDuration(int sprite)
+int QSGSpriteEngine::spriteDuration(int sprite)
{
int state = m_sprites[sprite];
if(!m_states[state]->m_generatedCount)
@@ -125,12 +125,12 @@ int SpriteEngine::spriteDuration(int sprite)
return rowDuration;
}
-int SpriteEngine::spriteCount()//TODO: Actually image state count, need to rename these things to make sense together
+int QSGSpriteEngine::spriteCount()//TODO: Actually image state count, need to rename these things to make sense together
{
return m_imageStateCount;
}
-void SpriteEngine::setGoal(int state, int sprite, bool jump)
+void QSGSpriteEngine::setGoal(int state, int sprite, bool jump)
{
if(sprite >= m_sprites.count() || state >= m_states.count())
return;
@@ -147,7 +147,7 @@ void SpriteEngine::setGoal(int state, int sprite, bool jump)
return;
}
-QImage SpriteEngine::assembledImage()
+QImage QSGSpriteEngine::assembledImage()
{
int frameHeight = 0;
int frameWidth = 0;
@@ -157,7 +157,7 @@ QImage SpriteEngine::assembledImage()
int maxSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
- foreach(SpriteState* state, m_states){
+ foreach(QSGSprite* state, m_states){
if(state->frames() > m_maxFrames)
m_maxFrames = state->frames();
@@ -215,7 +215,7 @@ QImage SpriteEngine::assembledImage()
image.fill(0);
QPainter p(&image);
int y = 0;
- foreach(SpriteState* state, m_states){
+ foreach(QSGSprite* state, m_states){
QImage img(state->source().toLocalFile());
if(img.height() == frameHeight && img.width() < maxSize){//Simple case
p.drawImage(0,y,img);
@@ -262,14 +262,14 @@ QImage SpriteEngine::assembledImage()
return image;
}
-void SpriteEngine::setCount(int c)
+void QSGSpriteEngine::setCount(int c)
{
m_sprites.resize(c);
m_goals.resize(c);
m_startTimes.resize(c);
}
-void SpriteEngine::startSprite(int index)
+void QSGSpriteEngine::startSprite(int index)
{
if(index >= m_sprites.count())
return;
@@ -278,7 +278,7 @@ void SpriteEngine::startSprite(int index)
restartSprite(index);
}
-void SpriteEngine::restartSprite(int index)
+void QSGSpriteEngine::restartSprite(int index)
{
m_startTimes[index] = m_timeOffset + m_advanceTime.elapsed();
int time = m_states[m_sprites[index]]->duration() * m_states[m_sprites[index]]->frames() + m_startTimes[index];
@@ -287,7 +287,7 @@ void SpriteEngine::restartSprite(int index)
addToUpdateList(time, index);
}
-uint SpriteEngine::updateSprites(uint time)
+uint QSGSpriteEngine::updateSprites(uint time)
{
//Sprite State Update;
while(!m_stateUpdates.isEmpty() && time >= m_stateUpdates.first().first){
@@ -341,7 +341,7 @@ uint SpriteEngine::updateSprites(uint time)
return m_stateUpdates.first().first;
}
-int SpriteEngine::goalSeek(int curIdx, int spriteIdx, int dist)
+int QSGSpriteEngine::goalSeek(int curIdx, int spriteIdx, int dist)
{
QString goalName;
if(m_goals[spriteIdx] != -1)
@@ -357,7 +357,7 @@ int SpriteEngine::goalSeek(int curIdx, int spriteIdx, int dist)
return curIdx;
if(dist < 0)
dist = m_states.count();
- SpriteState* curState = m_states[curIdx];
+ QSGSprite* curState = m_states[curIdx];
for(QVariantMap::const_iterator iter = curState->m_to.constBegin();
iter!=curState->m_to.constEnd(); iter++){
if(iter.key() == goalName)
@@ -416,7 +416,7 @@ int SpriteEngine::goalSeek(int curIdx, int spriteIdx, int dist)
return -1;
}
-void SpriteEngine::addToUpdateList(uint t, int idx)
+void QSGSpriteEngine::addToUpdateList(uint t, int idx)
{
for(int i=0; i<m_stateUpdates.count(); i++){
if(m_stateUpdates[i].first==t){
diff --git a/src/imports/particles/spriteengine.h b/src/declarative/items/qsgspriteengine_p.h
index 0180245685..8ab6e3a30a 100644
--- a/src/imports/particles/spriteengine.h
+++ b/src/declarative/items/qsgspriteengine_p.h
@@ -57,22 +57,22 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class SpriteState;
+class QSGSprite;
-class SpriteEngine : public QObject
+class QSGSpriteEngine : public QObject
{
Q_OBJECT
//TODO: Optimize single sprite case
- Q_PROPERTY(QDeclarativeListProperty<SpriteState> sprites READ sprites)
+ Q_PROPERTY(QDeclarativeListProperty<QSGSprite> sprites READ sprites)
Q_PROPERTY(QString globalGoal READ globalGoal WRITE setGlobalGoal NOTIFY globalGoalChanged)
public:
- explicit SpriteEngine(QObject *parent = 0);
- SpriteEngine(QList<SpriteState*> sprites, QObject *parent=0);
- ~SpriteEngine();
+ explicit QSGSpriteEngine(QObject *parent = 0);
+ QSGSpriteEngine(QList<QSGSprite*> sprites, QObject *parent=0);
+ ~QSGSpriteEngine();
- QDeclarativeListProperty<SpriteState> sprites()
+ QDeclarativeListProperty<QSGSprite> sprites()
{
- return QDeclarativeListProperty<SpriteState>(this, m_states);
+ return QDeclarativeListProperty<QSGSprite>(this, m_states);
}
QString globalGoal() const
{
@@ -95,10 +95,10 @@ public:
void startSprite(int index=0);
private://Nothing outside should use this?
- friend class SpriteGoalAffector;//XXX: Fix interface
+ friend class QSGSpriteGoalAffector;//XXX: Fix interface
int stateCount() {return m_states.count();}
- int stateIndex(SpriteState* s){return m_states.indexOf(s);}//TODO: Does this need to be hidden?
- SpriteState* state(int idx){return m_states[idx];}//Used by spritegoal affector
+ int stateIndex(QSGSprite* s){return m_states.indexOf(s);}//TODO: Does this need to be hidden?
+ QSGSprite* state(int idx){return m_states[idx];}//Used by spritegoal affector
signals:
void globalGoalChanged(QString arg);
@@ -118,7 +118,7 @@ private:
void restartSprite(int sprite);
void addToUpdateList(uint t, int idx);
int goalSeek(int curState, int spriteIdx, int dist=-1);
- QList<SpriteState*> m_states;
+ QList<QSGSprite*> m_states;
QVector<int> m_sprites;//int is the index in m_states of the current state
QVector<int> m_goals;
QVector<int> m_startTimes;
@@ -132,26 +132,26 @@ private:
};
//Common use is to have your own list property which is transparently an engine
-inline void spriteAppend(QDeclarativeListProperty<SpriteState> *p, SpriteState* s)
+inline void spriteAppend(QDeclarativeListProperty<QSGSprite> *p, QSGSprite* s)
{
- reinterpret_cast<QList<SpriteState *> *>(p->data)->append(s);
+ reinterpret_cast<QList<QSGSprite *> *>(p->data)->append(s);
p->object->metaObject()->invokeMethod(p->object, "createEngine");
}
-inline SpriteState* spriteAt(QDeclarativeListProperty<SpriteState> *p, int idx)
+inline QSGSprite* spriteAt(QDeclarativeListProperty<QSGSprite> *p, int idx)
{
- return reinterpret_cast<QList<SpriteState *> *>(p->data)->at(idx);
+ return reinterpret_cast<QList<QSGSprite *> *>(p->data)->at(idx);
}
-inline void spriteClear(QDeclarativeListProperty<SpriteState> *p)
+inline void spriteClear(QDeclarativeListProperty<QSGSprite> *p)
{
- reinterpret_cast<QList<SpriteState *> *>(p->data)->clear();
+ reinterpret_cast<QList<QSGSprite *> *>(p->data)->clear();
p->object->metaObject()->invokeMethod(p->object, "createEngine");
}
-inline int spriteCount(QDeclarativeListProperty<SpriteState> *p)
+inline int spriteCount(QDeclarativeListProperty<QSGSprite> *p)
{
- return reinterpret_cast<QList<SpriteState *> *>(p->data)->count();
+ return reinterpret_cast<QList<QSGSprite *> *>(p->data)->count();
}
QT_END_NAMESPACE
diff --git a/src/imports/particles/spriteimage.cpp b/src/declarative/items/qsgspriteimage.cpp
index ea08ae4ea0..8cc0dc5b76 100644
--- a/src/imports/particles/spriteimage.cpp
+++ b/src/declarative/items/qsgspriteimage.cpp
@@ -39,9 +39,9 @@
**
****************************************************************************/
-#include "spriteimage.h"
-#include "spritestate.h"
-#include "spriteengine.h"
+#include "qsgspriteimage_p.h"
+#include "qsgsprite_p.h"
+#include "qsgspriteengine_p.h"
#include <private/qsgcontext_p.h>
#include <private/qsgadaptationlayer_p.h>
#include <qsgnode.h>
@@ -55,16 +55,16 @@
QT_BEGIN_NAMESPACE
-class SpriteMaterial : public QSGMaterial
+class QSGSpriteMaterial : public QSGMaterial
{
public:
- SpriteMaterial();
- virtual ~SpriteMaterial();
+ QSGSpriteMaterial();
+ virtual ~QSGSpriteMaterial();
virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
virtual QSGMaterialShader *createShader() const;
virtual int compare(const QSGMaterial *other) const
{
- return this - static_cast<const SpriteMaterial *>(other);
+ return this - static_cast<const QSGSpriteMaterial *>(other);
}
QSGTexture *texture;
@@ -77,7 +77,7 @@ public:
int height;
};
-SpriteMaterial::SpriteMaterial()
+QSGSpriteMaterial::QSGSpriteMaterial()
: timestamp(0)
, timelength(1)
, framecount(1)
@@ -88,7 +88,7 @@ SpriteMaterial::SpriteMaterial()
setFlag(Blending, true);
}
-SpriteMaterial::~SpriteMaterial()
+QSGSpriteMaterial::~QSGSpriteMaterial()
{
delete texture;
}
@@ -98,11 +98,11 @@ class SpriteMaterialData : public QSGMaterialShader
public:
SpriteMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
{
- QFile vf(vertexFile ? vertexFile : ":resources/spriteimagevertex.shader");
+ QFile vf(vertexFile ? vertexFile : ":defaultshaders/spriteimagevertex.shader");
vf.open(QFile::ReadOnly);
m_vertex_code = vf.readAll();
- QFile ff(fragmentFile ? fragmentFile : ":resources/spriteimagefragment.shader");
+ QFile ff(fragmentFile ? fragmentFile : ":defaultshaders/spriteimagefragment.shader");
ff.open(QFile::ReadOnly);
m_fragment_code = ff.readAll();
@@ -120,7 +120,7 @@ public:
virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
{
- SpriteMaterial *m = static_cast<SpriteMaterial *>(newEffect);
+ QSGSpriteMaterial *m = static_cast<QSGSpriteMaterial *>(newEffect);
m->texture->bind();
program()->setUniformValue(m_opacity_id, state.opacity());
@@ -173,7 +173,7 @@ public:
};
float SpriteMaterialData::chunkOfBytes[1024];
-QSGMaterialShader *SpriteMaterial::createShader() const
+QSGMaterialShader *QSGSpriteMaterial::createShader() const
{
return new SpriteMaterialData;
}
@@ -194,7 +194,7 @@ struct SpriteVertices {
SpriteVertex v4;
};
-SpriteImage::SpriteImage(QSGItem *parent) :
+QSGSpriteImage::QSGSpriteImage(QSGItem *parent) :
QSGItem(parent)
, m_node(0)
, m_material(0)
@@ -207,18 +207,18 @@ SpriteImage::SpriteImage(QSGItem *parent) :
this, SLOT(update()));
}
-QDeclarativeListProperty<SpriteState> SpriteImage::sprites()
+QDeclarativeListProperty<QSGSprite> QSGSpriteImage::sprites()
{
- return QDeclarativeListProperty<SpriteState>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
+ return QDeclarativeListProperty<QSGSprite>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
}
-void SpriteImage::createEngine()
+void QSGSpriteImage::createEngine()
{
//TODO: delay until component complete
if(m_spriteEngine)
delete m_spriteEngine;
if(m_sprites.count())
- m_spriteEngine = new SpriteEngine(m_sprites, this);
+ m_spriteEngine = new QSGSpriteEngine(m_sprites, this);
else
m_spriteEngine = 0;
reset();
@@ -236,7 +236,7 @@ static QSGGeometry::AttributeSet SpriteImage_AttributeSet =
SpriteImage_Attributes
};
-QSGGeometryNode* SpriteImage::buildNode()
+QSGGeometryNode* QSGSpriteImage::buildNode()
{
if (!m_spriteEngine) {
qWarning() << "SpriteImage: No sprite engine...";
@@ -248,7 +248,7 @@ QSGGeometryNode* SpriteImage::buildNode()
m_material = 0;
}
- m_material = new SpriteMaterial();
+ m_material = new QSGSpriteMaterial();
QImage image = m_spriteEngine->assembledImage();
if(image.isNull())
@@ -297,12 +297,12 @@ QSGGeometryNode* SpriteImage::buildNode()
return m_node;
}
-void SpriteImage::reset()
+void QSGSpriteImage::reset()
{
m_pleaseReset = true;
}
-QSGNode *SpriteImage::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
+QSGNode *QSGSpriteImage::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
{
if(m_pleaseReset){
delete m_node;
@@ -324,7 +324,7 @@ QSGNode *SpriteImage::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
return m_node;
}
-void SpriteImage::prepareNextFrame()
+void QSGSpriteImage::prepareNextFrame()
{
if (m_node == 0)
m_node = buildNode();
diff --git a/src/imports/particles/spriteimage.h b/src/declarative/items/qsgspriteimage_p.h
index cd73c97333..f03fd869f0 100644
--- a/src/imports/particles/spriteimage.h
+++ b/src/declarative/items/qsgspriteimage_p.h
@@ -52,22 +52,22 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QSGContext;
-class SpriteState;
-class SpriteEngine;
+class QSGSprite;
+class QSGSpriteEngine;
class QSGGeometryNode;
-class SpriteMaterial;
-class SpriteImage : public QSGItem
+class QSGSpriteMaterial;
+class QSGSpriteImage : public QSGItem
{
Q_OBJECT
Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
//###try to share similar spriteEngines for less overhead?
- Q_PROPERTY(QDeclarativeListProperty<SpriteState> sprites READ sprites)
+ Q_PROPERTY(QDeclarativeListProperty<QSGSprite> sprites READ sprites)
Q_CLASSINFO("DefaultProperty", "sprites")
public:
- explicit SpriteImage(QSGItem *parent = 0);
+ explicit QSGSpriteImage(QSGItem *parent = 0);
- QDeclarativeListProperty<SpriteState> sprites();
+ QDeclarativeListProperty<QSGSprite> sprites();
bool running() const
{
@@ -98,9 +98,9 @@ private:
void prepareNextFrame();
QSGGeometryNode* buildNode();
QSGGeometryNode *m_node;
- SpriteMaterial *m_material;
- QList<SpriteState*> m_sprites;
- SpriteEngine* m_spriteEngine;
+ QSGSpriteMaterial *m_material;
+ QList<QSGSprite*> m_sprites;
+ QSGSpriteEngine* m_spriteEngine;
QTime m_timestamp;
int m_maxFrames;
bool m_pleaseReset;
diff --git a/src/declarative/items/qsgtext.cpp b/src/declarative/items/qsgtext.cpp
index b99e929a84..3398824f69 100644
--- a/src/declarative/items/qsgtext.cpp
+++ b/src/declarative/items/qsgtext.cpp
@@ -102,10 +102,11 @@ QSGTextPrivate::QSGTextPrivate()
lineHeightMode(QSGText::ProportionalHeight), lineCount(1), maximumLineCount(INT_MAX),
maximumLineCountValid(false),
texture(0),
- imageCacheDirty(true), updateOnComponentComplete(true),
+ imageCacheDirty(false), updateOnComponentComplete(true),
richText(false), singleline(false), cacheAllTextAsImage(true), internalWidthUpdate(false),
requireImplicitWidth(false), truncated(false), hAlignImplicit(true), rightToLeftText(false),
- layoutTextElided(false), naturalWidth(0), doc(0), layoutThread(0), nodeType(NodeIsNull)
+ layoutTextElided(false), richTextAsImage(false), textureImageCacheDirty(false), naturalWidth(0),
+ doc(0), layoutThread(0), nodeType(NodeIsNull)
{
cacheAllTextAsImage = enableImageCache();
}
@@ -289,6 +290,8 @@ void QSGTextPrivate::updateSize()
int dy = q->height();
QSize size(0, 0);
+ layoutThread = QThread::currentThread();
+
//setup instance of QTextLayout for all cases other than richtext
if (!richText) {
QRect textRect = setupTextLayout();
@@ -377,8 +380,6 @@ QRect QSGTextPrivate::setupTextLayout()
bool elideText = false;
bool truncate = false;
- layoutThread = QThread::currentThread();
-
QFontMetrics fm(layout.font());
elidePos = QPointF();
@@ -573,14 +574,15 @@ void QSGTextPrivate::invalidateImageCache()
{
Q_Q(QSGText);
- if(cacheAllTextAsImage || (!QSGDistanceFieldGlyphCache::distanceFieldEnabled() && style != QSGText::Normal)){//If actually using the image cache
+ if(richTextAsImage || cacheAllTextAsImage || (!QSGDistanceFieldGlyphCache::distanceFieldEnabled() && style != QSGText::Normal)){//If actually using the image cache
if (imageCacheDirty)
return;
imageCacheDirty = true;
- imageCache = QPixmap();
- }
- if (q->isComponentComplete())
+
+ if (q->isComponentComplete())
+ QCoreApplication::postEvent(q, new QEvent(QEvent::User));
+ } else if (q->isComponentComplete())
q->update();
}
@@ -589,6 +591,8 @@ void QSGTextPrivate::invalidateImageCache()
*/
void QSGTextPrivate::checkImageCache()
{
+ Q_Q(QSGText);
+
if (!imageCacheDirty)
return;
@@ -629,6 +633,8 @@ void QSGTextPrivate::checkImageCache()
}
imageCacheDirty = false;
+ textureImageCacheDirty = true;
+ q->update();
}
/*!
@@ -748,6 +754,7 @@ void QSGText::setText(const QString &n)
d->ensureDoc();
d->doc->setText(n);
d->rightToLeftText = d->doc->toPlainText().isRightToLeft();
+ d->richTextAsImage = QSGTextNode::isComplexRichText(d->doc);
} else {
d->rightToLeftText = d->text.isRightToLeft();
}
@@ -987,6 +994,7 @@ void QSGText::setTextFormat(TextFormat format)
if (!wasRich && d->richText && isComponentComplete()) {
d->ensureDoc();
d->doc->setText(d->text);
+ d->richTextAsImage = QSGTextNode::isComplexRichText(d->doc);
}
d->updateLayout();
@@ -1063,10 +1071,9 @@ QSGNode *QSGText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
Q_UNUSED(data);
Q_D(QSGText);
- bool richTextAsImage = false;
- if (d->richText) {
- d->ensureDoc();
- richTextAsImage = QSGTextNode::isComplexRichText(d->doc);
+ if (d->text.isEmpty()) {
+ delete oldNode;
+ return 0;
}
QRectF bounds = boundingRect();
@@ -1076,10 +1083,9 @@ QSGNode *QSGText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
d->updateLayout();
// XXX todo - some styled text can be done by the QSGTextNode
- if (richTextAsImage || d->cacheAllTextAsImage || (!QSGDistanceFieldGlyphCache::distanceFieldEnabled() && d->style != Normal)) {
- bool wasDirty = d->imageCacheDirty;
-
- d->checkImageCache();
+ if (d->richTextAsImage || d->cacheAllTextAsImage || (!QSGDistanceFieldGlyphCache::distanceFieldEnabled() && d->style != Normal)) {
+ bool wasDirty = d->textureImageCacheDirty;
+ d->textureImageCacheDirty = false;
if (d->imageCache.isNull()) {
delete oldNode;
@@ -1139,6 +1145,17 @@ QSGNode *QSGText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
}
}
+bool QSGText::event(QEvent *e)
+{
+ Q_D(QSGText);
+ if (e->type() == QEvent::User) {
+ d->checkImageCache();
+ return true;
+ } else {
+ return QSGImplicitSizeItem::event(e);
+ }
+}
+
qreal QSGText::paintedWidth() const
{
Q_D(const QSGText);
@@ -1207,6 +1224,7 @@ void QSGText::componentComplete()
d->ensureDoc();
d->doc->setText(d->text);
d->rightToLeftText = d->doc->toPlainText().isRightToLeft();
+ d->richTextAsImage = QSGTextNode::isComplexRichText(d->doc);
} else {
d->rightToLeftText = d->text.isRightToLeft();
}
diff --git a/src/declarative/items/qsgtext_p.h b/src/declarative/items/qsgtext_p.h
index 090a2b0e67..a5b61bcb2e 100644
--- a/src/declarative/items/qsgtext_p.h
+++ b/src/declarative/items/qsgtext_p.h
@@ -199,6 +199,7 @@ protected:
virtual void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry);
virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
+ virtual bool event(QEvent *);
private:
Q_DISABLE_COPY(QSGText)
diff --git a/src/declarative/items/qsgtext_p_p.h b/src/declarative/items/qsgtext_p_p.h
index a3836a19f8..6e98d30594 100644
--- a/src/declarative/items/qsgtext_p_p.h
+++ b/src/declarative/items/qsgtext_p_p.h
@@ -120,12 +120,14 @@ public:
bool hAlignImplicit:1;
bool rightToLeftText:1;
bool layoutTextElided:1;
+ bool richTextAsImage:1;
+ bool textureImageCacheDirty:1;
QRect layedOutTextRect;
QSize paintedSize;
qreal naturalWidth;
virtual qreal getImplicitWidth() const;
-
+
void ensureDoc();
QPixmap textDocumentImage(bool drawStyle);
QSGTextDocumentWithImageResources *doc;
diff --git a/src/declarative/items/qsgtextnode.cpp b/src/declarative/items/qsgtextnode.cpp
index bbfb258759..3120d7e4eb 100644
--- a/src/declarative/items/qsgtextnode.cpp
+++ b/src/declarative/items/qsgtextnode.cpp
@@ -152,18 +152,32 @@ void QSGTextNode::addTextDecorations(const QPointF &position, const QRawFont &fo
}
QSGGlyphNode *QSGTextNode::addGlyphs(const QPointF &position, const QGlyphRun &glyphs, const QColor &color,
- QSGText::TextStyle style, const QColor &styleColor)
+ QSGText::TextStyle style, const QColor &styleColor, QSGGlyphNode *prevNode)
{
- QSGGlyphNode *node = m_context->createGlyphNode();
- if (QSGDistanceFieldGlyphCache::distanceFieldEnabled()) {
- QSGDistanceFieldGlyphNode *dfNode = static_cast<QSGDistanceFieldGlyphNode *>(node);
- dfNode->setStyle(style);
- dfNode->setStyleColor(styleColor);
- }
+ QSGGlyphNode *node = prevNode;
+
+ if (!node)
+ node = m_context->createGlyphNode();
+
node->setGlyphs(position, glyphs);
- node->setColor(color);
- appendChildNode(node);
+ if (node != prevNode) {
+ if (QSGDistanceFieldGlyphCache::distanceFieldEnabled()) {
+ QSGDistanceFieldGlyphNode *dfNode = static_cast<QSGDistanceFieldGlyphNode *>(node);
+ dfNode->setStyle(style);
+ dfNode->setStyleColor(styleColor);
+ }
+ node->setColor(color);
+ appendChildNode(node);
+ }
+
+
+ if (glyphs.overline() || glyphs.strikeOut() || glyphs.underline()) {
+ QPointF baseLine = node->baseLine();
+ qreal width = node->boundingRect().width();
+ addTextDecorations(baseLine, glyphs.rawFont(), color, width,
+ glyphs.overline(), glyphs.strikeOut(), glyphs.underline());
+ }
return node;
}
@@ -186,6 +200,9 @@ void QSGTextNode::addTextLayout(const QPointF &position, QTextLayout *textLayout
QSGText::TextStyle style, const QColor &styleColor)
{
QList<QGlyphRun> glyphsList(textLayout->glyphRuns());
+
+ QSGGlyphNode *prevNode = 0;
+
for (int i=0; i<glyphsList.size(); ++i) {
QGlyphRun glyphs = glyphsList.at(i);
QRawFont font = glyphs.rawFont();
@@ -359,13 +376,8 @@ void QSGTextNode::addTextBlock(const QPointF &position, QTextDocument *textDocum
for (int i=0; i<glyphsList.size(); ++i) {
QGlyphRun glyphs = glyphsList.at(i);
QRawFont font = glyphs.rawFont();
- QSGGlyphNode *glyphNode = addGlyphs(position + blockPosition + QPointF(0, font.ascent()),
- glyphs, color, style, styleColor);
-
- QPointF baseLine = glyphNode->baseLine();
- qreal width = glyphNode->boundingRect().width();
- addTextDecorations(baseLine, font, color, width,
- glyphs.overline(), glyphs.strikeOut(), glyphs.underline());
+ addGlyphs(position + blockPosition + QPointF(0, font.ascent()),
+ glyphs, color, style, styleColor);
}
}
diff --git a/src/declarative/items/qsgtextnode_p.h b/src/declarative/items/qsgtextnode_p.h
index 7a49f51dbe..e442b4cff2 100644
--- a/src/declarative/items/qsgtextnode_p.h
+++ b/src/declarative/items/qsgtextnode_p.h
@@ -73,7 +73,8 @@ private:
void addTextBlock(const QPointF &position, QTextDocument *textDocument, const QTextBlock &block,
const QColor &overrideColor, QSGText::TextStyle style = QSGText::Normal, const QColor &styleColor = QColor());
QSGGlyphNode *addGlyphs(const QPointF &position, const QGlyphRun &glyphs, const QColor &color,
- QSGText::TextStyle style = QSGText::Normal, const QColor &styleColor = QColor());
+ QSGText::TextStyle style = QSGText::Normal, const QColor &styleColor = QColor(),
+ QSGGlyphNode *node = 0);
void addTextDecorations(const QPointF &position, const QRawFont &font, const QColor &color,
qreal width, bool hasOverline, bool hasStrikeOut, bool hasUnderline);
QSGContext *m_context;
diff --git a/src/imports/particles/resources/ctfragment.shader b/src/declarative/particles/defaultshaders/ctfragment.shader
index a17f5841ca..a17f5841ca 100644
--- a/src/imports/particles/resources/ctfragment.shader
+++ b/src/declarative/particles/defaultshaders/ctfragment.shader
diff --git a/src/imports/particles/resources/ctvertex.shader b/src/declarative/particles/defaultshaders/ctvertex.shader
index b20676cc49..b20676cc49 100644
--- a/src/imports/particles/resources/ctvertex.shader
+++ b/src/declarative/particles/defaultshaders/ctvertex.shader
diff --git a/src/imports/particles/resources/defaultFadeInOut.png b/src/declarative/particles/defaultshaders/defaultFadeInOut.png
index 89c04eaefe..89c04eaefe 100644
--- a/src/imports/particles/resources/defaultFadeInOut.png
+++ b/src/declarative/particles/defaultshaders/defaultFadeInOut.png
Binary files differ
diff --git a/src/imports/particles/resources/deformablefragment.shader b/src/declarative/particles/defaultshaders/deformablefragment.shader
index 494053e319..494053e319 100644
--- a/src/imports/particles/resources/deformablefragment.shader
+++ b/src/declarative/particles/defaultshaders/deformablefragment.shader
diff --git a/src/imports/particles/resources/deformablevertex.shader b/src/declarative/particles/defaultshaders/deformablevertex.shader
index 01570950b1..01570950b1 100644
--- a/src/imports/particles/resources/deformablevertex.shader
+++ b/src/declarative/particles/defaultshaders/deformablevertex.shader
diff --git a/src/imports/particles/resources/identitytable.png b/src/declarative/particles/defaultshaders/identitytable.png
index 2cada1bfad..2cada1bfad 100644
--- a/src/imports/particles/resources/identitytable.png
+++ b/src/declarative/particles/defaultshaders/identitytable.png
Binary files differ
diff --git a/src/imports/particles/resources/simplefragment.shader b/src/declarative/particles/defaultshaders/simplefragment.shader
index 494053e319..494053e319 100644
--- a/src/imports/particles/resources/simplefragment.shader
+++ b/src/declarative/particles/defaultshaders/simplefragment.shader
diff --git a/src/imports/particles/resources/simplevertex.shader b/src/declarative/particles/defaultshaders/simplevertex.shader
index f185ef0700..f185ef0700 100644
--- a/src/imports/particles/resources/simplevertex.shader
+++ b/src/declarative/particles/defaultshaders/simplevertex.shader
diff --git a/src/imports/particles/resources/spritefragment.shader b/src/declarative/particles/defaultshaders/spritefragment.shader
index 4d89d69c6a..4d89d69c6a 100644
--- a/src/imports/particles/resources/spritefragment.shader
+++ b/src/declarative/particles/defaultshaders/spritefragment.shader
diff --git a/src/imports/particles/resources/spriteimagefragment.shader b/src/declarative/particles/defaultshaders/spriteimagefragment.shader
index ecd62cf390..ecd62cf390 100644
--- a/src/imports/particles/resources/spriteimagefragment.shader
+++ b/src/declarative/particles/defaultshaders/spriteimagefragment.shader
diff --git a/src/imports/particles/resources/spriteimagevertex.shader b/src/declarative/particles/defaultshaders/spriteimagevertex.shader
index 27de2ada6a..27de2ada6a 100644
--- a/src/imports/particles/resources/spriteimagevertex.shader
+++ b/src/declarative/particles/defaultshaders/spriteimagevertex.shader
diff --git a/src/imports/particles/resources/spritevertex.shader b/src/declarative/particles/defaultshaders/spritevertex.shader
index 78b8e36b3b..78b8e36b3b 100644
--- a/src/imports/particles/resources/spritevertex.shader
+++ b/src/declarative/particles/defaultshaders/spritevertex.shader
diff --git a/src/imports/particles/resources/superfragment.shader b/src/declarative/particles/defaultshaders/superfragment.shader
index a17f5841ca..a17f5841ca 100644
--- a/src/imports/particles/resources/superfragment.shader
+++ b/src/declarative/particles/defaultshaders/superfragment.shader
diff --git a/src/imports/particles/resources/supervertex.shader b/src/declarative/particles/defaultshaders/supervertex.shader
index 432a23ce05..432a23ce05 100644
--- a/src/imports/particles/resources/supervertex.shader
+++ b/src/declarative/particles/defaultshaders/supervertex.shader
diff --git a/src/imports/particles/resources/trailsfragment.shader b/src/declarative/particles/defaultshaders/trailsfragment.shader
index d3db87fa30..d3db87fa30 100644
--- a/src/imports/particles/resources/trailsfragment.shader
+++ b/src/declarative/particles/defaultshaders/trailsfragment.shader
diff --git a/src/imports/particles/resources/trailsvertex.shader b/src/declarative/particles/defaultshaders/trailsvertex.shader
index 7bc1d66b71..7bc1d66b71 100644
--- a/src/imports/particles/resources/trailsvertex.shader
+++ b/src/declarative/particles/defaultshaders/trailsvertex.shader
diff --git a/src/imports/particles/resources/ultrafragment.shader b/src/declarative/particles/defaultshaders/ultrafragment.shader
index 0627d0f1e8..0627d0f1e8 100644
--- a/src/imports/particles/resources/ultrafragment.shader
+++ b/src/declarative/particles/defaultshaders/ultrafragment.shader
diff --git a/src/imports/particles/resources/ultravertex.shader b/src/declarative/particles/defaultshaders/ultravertex.shader
index 65a1a3077a..65a1a3077a 100644
--- a/src/imports/particles/resources/ultravertex.shader
+++ b/src/declarative/particles/defaultshaders/ultravertex.shader
diff --git a/src/declarative/particles/particles.pri b/src/declarative/particles/particles.pri
new file mode 100644
index 0000000000..04200a380e
--- /dev/null
+++ b/src/declarative/particles/particles.pri
@@ -0,0 +1,60 @@
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ $$PWD/qsgangleddirection_p.h \
+ $$PWD/qsgcustomparticle_p.h \
+ $$PWD/qsgellipseextruder_p.h \
+ $$PWD/qsgemitter_p.h \
+ $$PWD/qsgfollowemitter_p.h \
+ $$PWD/qsgfriction_p.h \
+ $$PWD/qsggravity_p.h \
+ $$PWD/qsgimageparticle_p.h \
+ $$PWD/qsgitemparticle_p.h \
+ $$PWD/qsgkill_p.h \
+ $$PWD/qsglineextruder_p.h \
+ $$PWD/qsgmaskextruder_p.h \
+ $$PWD/qsgmodelparticle_p.h \
+ $$PWD/qsgparticleaffector_p.h \
+ $$PWD/qsgparticleemitter_p.h \
+ $$PWD/qsgparticleextruder_p.h \
+ $$PWD/qsgparticlepainter_p.h \
+ $$PWD/qsgparticlesmodule_p.h \
+ $$PWD/qsgparticlesystem_p.h \
+ $$PWD/qsgpointattractor_p.h \
+ $$PWD/qsgpointdirection_p.h \
+ $$PWD/qsgspritegoal_p.h \
+ $$PWD/qsgstochasticdirection_p.h \
+ $$PWD/qsgtargeteddirection_p.h \
+ $$PWD/qsgturbulence_p.h \
+ $$PWD/qsgwander_p.h
+
+SOURCES += \
+ $$PWD/qsgangleddirection.cpp \
+ $$PWD/qsgcustomparticle.cpp \
+ $$PWD/qsgellipseextruder.cpp \
+ $$PWD/qsgemitter.cpp \
+ $$PWD/qsgfollowemitter.cpp \
+ $$PWD/qsgfriction.cpp \
+ $$PWD/qsggravity.cpp \
+ $$PWD/qsgimageparticle.cpp \
+ $$PWD/qsgitemparticle.cpp \
+ $$PWD/qsgkill.cpp \
+ $$PWD/qsglineextruder.cpp \
+ $$PWD/qsgmaskextruder.cpp \
+ $$PWD/qsgmodelparticle.cpp \
+ $$PWD/qsgparticleaffector.cpp \
+ $$PWD/qsgparticleemitter.cpp \
+ $$PWD/qsgparticleextruder.cpp \
+ $$PWD/qsgparticlepainter.cpp \
+ $$PWD/qsgparticlesmodule.cpp \
+ $$PWD/qsgparticlesystem.cpp \
+ $$PWD/qsgpointattractor.cpp \
+ $$PWD/qsgpointdirection.cpp \
+ $$PWD/qsgspritegoal.cpp \
+ $$PWD/qsgstochasticdirection.cpp \
+ $$PWD/qsgtargeteddirection.cpp \
+ $$PWD/qsgturbulence.cpp \
+ $$PWD/qsgwander.cpp
+
+RESOURCES += \
+ $$PWD/particles.qrc
diff --git a/src/declarative/particles/particles.qrc b/src/declarative/particles/particles.qrc
new file mode 100644
index 0000000000..85931ec9ce
--- /dev/null
+++ b/src/declarative/particles/particles.qrc
@@ -0,0 +1,22 @@
+<RCC>
+ <qresource prefix="/">
+ <file>defaultshaders/spritefragment.shader</file>
+ <file>defaultshaders/spritevertex.shader</file>
+ <file>defaultshaders/ctfragment.shader</file>
+ <file>defaultshaders/ctvertex.shader</file>
+ <file>defaultshaders/trailsfragment.shader</file>
+ <file>defaultshaders/trailsvertex.shader</file>
+ <file>defaultshaders/spriteimagefragment.shader</file>
+ <file>defaultshaders/spriteimagevertex.shader</file>
+ <file>defaultshaders/identitytable.png</file>
+ <file>defaultshaders/defaultFadeInOut.png</file>
+ <file>defaultshaders/deformablefragment.shader</file>
+ <file>defaultshaders/deformablevertex.shader</file>
+ <file>defaultshaders/ultravertex.shader</file>
+ <file>defaultshaders/ultrafragment.shader</file>
+ <file>defaultshaders/supervertex.shader</file>
+ <file>defaultshaders/superfragment.shader</file>
+ <file>defaultshaders/simplevertex.shader</file>
+ <file>defaultshaders/simplefragment.shader</file>
+ </qresource>
+</RCC>
diff --git a/src/imports/particles/angledvector.cpp b/src/declarative/particles/qsgangleddirection.cpp
index 85b5ed7472..5c32b53e3e 100644
--- a/src/imports/particles/angledvector.cpp
+++ b/src/declarative/particles/qsgangleddirection.cpp
@@ -39,12 +39,12 @@
**
****************************************************************************/
-#include "angledvector.h"
+#include "qsgangleddirection_p.h"
#include <cmath>
QT_BEGIN_NAMESPACE
const qreal CONV = 0.017453292519943295;
-AngledVector::AngledVector(QObject *parent) :
- VaryingVector(parent)
+QSGAngledDirection::QSGAngledDirection(QObject *parent) :
+ QSGStochasticDirection(parent)
, m_angle(0)
, m_magnitude(0)
, m_angleVariation(0)
@@ -53,7 +53,7 @@ AngledVector::AngledVector(QObject *parent) :
}
-const QPointF &AngledVector::sample(const QPointF &from)
+const QPointF &QSGAngledDirection::sample(const QPointF &from)
{
//TODO: Faster
qreal theta = m_angle*CONV - m_angleVariation*CONV + rand()/float(RAND_MAX) * m_angleVariation*CONV * 2;
diff --git a/src/imports/particles/angledvector.h b/src/declarative/particles/qsgangleddirection_p.h
index ac78059e43..76262453a9 100644
--- a/src/imports/particles/angledvector.h
+++ b/src/declarative/particles/qsgangleddirection_p.h
@@ -39,16 +39,16 @@
**
****************************************************************************/
-#ifndef ANGLEDVECTOR_H
-#define ANGLEDVECTOR_H
-#include "varyingvector.h"
+#ifndef QSGANGLEDDIRECTION_H
+#define QSGANGLEDDIRECTION_H
+#include "qsgstochasticdirection_p.h"
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class AngledVector : public VaryingVector
+class QSGAngledDirection : public QSGStochasticDirection
{
Q_OBJECT
Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
@@ -56,7 +56,7 @@ class AngledVector : public VaryingVector
Q_PROPERTY(qreal angleVariation READ angleVariation WRITE setAngleVariation NOTIFY angleVariationChanged)
Q_PROPERTY(qreal magnitudeVariation READ magnitudeVariation WRITE setMagnitudeVariation NOTIFY magnitudeVariationChanged)
public:
- explicit AngledVector(QObject *parent = 0);
+ explicit QSGAngledDirection(QObject *parent = 0);
const QPointF &sample(const QPointF &from);
qreal angle() const
{
@@ -130,4 +130,4 @@ qreal m_magnitudeVariation;
QT_END_NAMESPACE
QT_END_HEADER
-#endif // ANGLEDVECTOR_H
+#endif // QSGANGLEDDIRECTION_H
diff --git a/src/declarative/particles/qsgcustomparticle.cpp b/src/declarative/particles/qsgcustomparticle.cpp
new file mode 100644
index 0000000000..46f160ddf4
--- /dev/null
+++ b/src/declarative/particles/qsgcustomparticle.cpp
@@ -0,0 +1,518 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgcustomparticle_p.h"
+#include <private/qsgshadereffectmesh_p.h>
+#include <cstdlib>
+
+QT_BEGIN_NAMESPACE
+
+//TODO: Can we make the code such that you don't have to copy the whole vertex shader just to add one little calculation?
+//Includes comments because the code isn't self explanatory
+static const char qt_particles_default_vertex_code[] =
+ "attribute highp vec2 vPos; \n"
+ "attribute highp vec2 vTex; \n"
+ "attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize \n"
+ "attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration \n"
+ "uniform highp mat4 qt_ModelViewProjectionMatrix; \n"
+ "uniform highp float timestamp; \n"
+ "varying highp vec2 fTex; \n"
+ "void main() { \n"
+ " fTex = vTex; \n"
+ " highp float size = vData.z; \n"
+ " highp float endSize = vData.w; \n"
+ " highp float t = (timestamp - vData.x) / vData.y; \n"
+ " highp float currentSize = mix(size, endSize, t * t); \n"
+ " if (t < 0. || t > 1.) \n"
+ " currentSize = 0.; \n"
+ " highp vec2 pos = vPos \n"
+ " - currentSize / 2. + currentSize * vTex // adjust size \n"
+ " + vVec.xy * t * vData.y // apply speed vector.. \n"
+ " + 0.5 * vVec.zw * pow(t * vData.y, 2.); \n"
+ " gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1); \n"
+ "}";
+
+static const char qt_particles_default_fragment_code[] =//TODO: Default frag requires source?
+ "uniform sampler2D source; \n"
+ "varying highp vec2 fTex; \n"
+ "uniform lowp float qt_Opacity; \n"
+ "void main() { \n"
+ " gl_FragColor = texture2D(source, fTex) * qt_Opacity; \n"
+ "}";
+
+static const char qt_position_attribute_name[] = "qt_Vertex";
+static const char qt_texcoord_attribute_name[] = "qt_MultiTexCoord0";
+
+static QSGGeometry::Attribute PlainParticle_Attributes[] = {
+ { 0, 2, GL_FLOAT }, // Position
+ { 1, 2, GL_FLOAT }, // TexCoord
+ { 2, 4, GL_FLOAT }, // Data
+ { 3, 4, GL_FLOAT }, // Vectors
+ { 4, 1, GL_FLOAT } // r
+};
+
+static QSGGeometry::AttributeSet PlainParticle_AttributeSet =
+{
+ 5, // Attribute Count
+ (2 + 2 + 4 + 4 + 1) * sizeof(float),
+ PlainParticle_Attributes
+};
+
+struct PlainVertex {
+ float x;
+ float y;
+ float tx;
+ float ty;
+ float t;
+ float lifeSpan;
+ float size;
+ float endSize;
+ float sx;
+ float sy;
+ float ax;
+ float ay;
+ float r;
+};
+
+struct PlainVertices {
+ PlainVertex v1;
+ PlainVertex v2;
+ PlainVertex v3;
+ PlainVertex v4;
+};
+
+QSGCustomParticle::QSGCustomParticle(QSGItem* parent)
+ : QSGParticlePainter(parent)
+ , m_pleaseReset(true)
+ , m_dirtyData(true)
+{
+ setFlag(QSGItem::ItemHasContents);
+}
+
+void QSGCustomParticle::componentComplete()
+{
+ reset();
+ QSGParticlePainter::componentComplete();
+}
+
+
+//Trying to keep the shader conventions the same as in qsgshadereffectitem
+/*!
+ \qmlproperty string CustomParticle::fragmentShader
+
+ This property holds the fragment shader's GLSL source code.
+ The default shader passes the texture coordinate along to the fragment
+ shader as "varying highp vec2 qt_TexCoord0".
+*/
+
+void QSGCustomParticle::setFragmentShader(const QByteArray &code)
+{
+ if (m_source.fragmentCode.constData() == code.constData())
+ return;
+ m_source.fragmentCode = code;
+ if (isComponentComplete()) {
+ reset();
+ }
+ emit fragmentShaderChanged();
+}
+
+/*!
+ \qmlproperty string CustomParticle::vertexShader
+
+ This property holds the vertex shader's GLSL source code.
+ The default shader expects the texture coordinate to be passed from the
+ vertex shader as "varying highp vec2 qt_TexCoord0", and it samples from a
+ sampler2D named "source".
+*/
+
+void QSGCustomParticle::setVertexShader(const QByteArray &code)
+{
+ if (m_source.vertexCode.constData() == code.constData())
+ return;
+ m_source.vertexCode = code;
+ if (isComponentComplete()) {
+ reset();
+ }
+ emit vertexShaderChanged();
+}
+
+void QSGCustomParticle::reset()
+{
+ disconnectPropertySignals();
+
+ m_source.attributeNames.clear();
+ m_source.uniformNames.clear();
+ m_source.respectsOpacity = false;
+ m_source.respectsMatrix = false;
+ m_source.className = metaObject()->className();
+
+ for (int i = 0; i < m_sources.size(); ++i) {
+ const SourceData &source = m_sources.at(i);
+ delete source.mapper;
+ if (source.item && source.item->parentItem() == this)
+ source.item->setParentItem(0);
+ }
+ m_sources.clear();
+
+ QSGParticlePainter::reset();
+ m_pleaseReset = true;
+}
+
+
+void QSGCustomParticle::changeSource(int index)
+{
+ Q_ASSERT(index >= 0 && index < m_sources.size());
+ QVariant v = property(m_sources.at(index).name.constData());
+ setSource(v, index);
+}
+
+void QSGCustomParticle::updateData()
+{
+ m_dirtyData = true;
+ update();
+}
+
+void QSGCustomParticle::setSource(const QVariant &var, int index)
+{
+ Q_ASSERT(index >= 0 && index < m_sources.size());
+
+ SourceData &source = m_sources[index];
+
+ source.item = 0;
+ if (var.isNull()) {
+ return;
+ } else if (!qVariantCanConvert<QObject *>(var)) {
+ qWarning("Could not assign source of type '%s' to property '%s'.", var.typeName(), source.name.constData());
+ return;
+ }
+
+ QObject *obj = qVariantValue<QObject *>(var);
+
+ QSGTextureProvider *int3rface = QSGTextureProvider::from(obj);
+ if (!int3rface) {
+ qWarning("Could not assign property '%s', did not implement QSGTextureProvider.", source.name.constData());
+ }
+
+ source.item = qobject_cast<QSGItem *>(obj);
+
+ // TODO: Copy better solution in QSGShaderEffectItem when they find it.
+ // 'source.item' needs a canvas to get a scenegraph node.
+ // The easiest way to make sure it gets a canvas is to
+ // make it a part of the same item tree as 'this'.
+ if (source.item && source.item->parentItem() == 0) {
+ source.item->setParentItem(this);
+ source.item->setVisible(false);
+ }
+}
+
+void QSGCustomParticle::disconnectPropertySignals()
+{
+ disconnect(this, 0, this, SLOT(updateData()));
+ for (int i = 0; i < m_sources.size(); ++i) {
+ SourceData &source = m_sources[i];
+ disconnect(this, 0, source.mapper, 0);
+ disconnect(source.mapper, 0, this, 0);
+ }
+}
+
+void QSGCustomParticle::connectPropertySignals()
+{
+ QSet<QByteArray>::const_iterator it;
+ for (it = m_source.uniformNames.begin(); it != m_source.uniformNames.end(); ++it) {
+ int pi = metaObject()->indexOfProperty(it->constData());
+ if (pi >= 0) {
+ QMetaProperty mp = metaObject()->property(pi);
+ if (!mp.hasNotifySignal())
+ qWarning("QSGShaderEffectItem: property '%s' does not have notification method!", it->constData());
+ QByteArray signalName("2");
+ signalName.append(mp.notifySignal().signature());
+ connect(this, signalName, this, SLOT(updateData()));
+ } else {
+ qWarning("QSGShaderEffectItem: '%s' does not have a matching property!", it->constData());
+ }
+ }
+ for (int i = 0; i < m_sources.size(); ++i) {
+ SourceData &source = m_sources[i];
+ int pi = metaObject()->indexOfProperty(source.name.constData());
+ if (pi >= 0) {
+ QMetaProperty mp = metaObject()->property(pi);
+ QByteArray signalName("2");
+ signalName.append(mp.notifySignal().signature());
+ connect(this, signalName, source.mapper, SLOT(map()));
+ source.mapper->setMapping(this, i);
+ connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int)));
+ } else {
+ qWarning("QSGShaderEffectItem: '%s' does not have a matching source!", source.name.constData());
+ }
+ }
+}
+
+void QSGCustomParticle::updateProperties()
+{
+ QByteArray vertexCode = m_source.vertexCode;
+ QByteArray fragmentCode = m_source.fragmentCode;
+ if (vertexCode.isEmpty())
+ vertexCode = qt_particles_default_vertex_code;
+ if (fragmentCode.isEmpty())
+ fragmentCode = qt_particles_default_fragment_code;
+
+ m_source.attributeNames.clear();
+ m_source.attributeNames << "vPos" << "vTex" << "vData" << "vVec" << "r";
+
+ lookThroughShaderCode(vertexCode);
+ lookThroughShaderCode(fragmentCode);
+
+ if (!m_source.attributeNames.contains(qt_position_attribute_name))
+ qWarning("QSGShaderEffectItem: Missing reference to \'%s\'.", qt_position_attribute_name);
+ if (!m_source.attributeNames.contains(qt_texcoord_attribute_name))
+ qWarning("QSGShaderEffectItem: Missing reference to \'%s\'.", qt_texcoord_attribute_name);
+ if (!m_source.respectsMatrix)
+ qWarning("QSGShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
+ if (!m_source.respectsOpacity)
+ qWarning("QSGShaderEffectItem: Missing reference to \'qt_Opacity\'.");
+
+ for (int i = 0; i < m_sources.size(); ++i) {
+ QVariant v = property(m_sources.at(i).name);
+ setSource(v, i);
+ }
+
+ connectPropertySignals();
+}
+
+void QSGCustomParticle::lookThroughShaderCode(const QByteArray &code)
+{
+ // Regexp for matching attributes and uniforms.
+ // In human readable form: attribute|uniform [lowp|mediump|highp] <type> <name>
+ static QRegExp re(QLatin1String("\\b(attribute|uniform)\\b\\s*\\b(?:lowp|mediump|highp)?\\b\\s*\\b(\\w+)\\b\\s*\\b(\\w+)"));
+ Q_ASSERT(re.isValid());
+
+ int pos = -1;
+
+ QString wideCode = QString::fromLatin1(code.constData(), code.size());
+
+ while ((pos = re.indexIn(wideCode, pos + 1)) != -1) {
+ QByteArray decl = re.cap(1).toLatin1(); // uniform or attribute
+ QByteArray type = re.cap(2).toLatin1(); // type
+ QByteArray name = re.cap(3).toLatin1(); // variable name
+
+ if (decl == "attribute") {
+ if(!m_source.attributeNames.contains(name))//TODO: Can they add custom attributes?
+ qWarning() << "Custom Particle: Unknown attribute " << name;
+ } else {
+ Q_ASSERT(decl == "uniform");//TODO: Shouldn't assert
+
+ if (name == "qt_ModelViewProjectionMatrix") {
+ m_source.respectsMatrix = true;
+ } else if (name == "qt_Opacity") {
+ m_source.respectsOpacity = true;
+ } else if (name == "timestamp") {
+ //TODO: Copy the whole thing just because I have one more uniform?
+ } else {
+ m_source.uniformNames.insert(name);
+ if (type == "sampler2D") {
+ SourceData d;
+ d.mapper = new QSignalMapper;
+ d.name = name;
+ d.item = 0;
+ m_sources.append(d);
+ }
+ }
+ }
+ }
+}
+
+QSGNode *QSGCustomParticle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
+{
+ if(m_pleaseReset){
+ if(m_node)
+ delete m_node;
+ //delete m_material;//Shader effect item doesn't regen material?
+
+ m_node = 0;
+ m_pleaseReset = false;
+ m_dirtyData = false;
+ }
+
+ if(m_system && m_system->isRunning())
+ prepareNextFrame();
+ if (m_node){
+ if(oldNode)
+ Q_ASSERT(oldNode == m_node);
+ update();
+ m_node->markDirty(QSGNode::DirtyMaterial); //done in buildData?
+ }
+
+ return m_node;
+}
+
+void QSGCustomParticle::prepareNextFrame(){
+ if(!m_node)
+ m_node = buildCustomNode();
+ if(!m_node)
+ return;
+
+ m_lastTime = m_system->systemSync(this) / 1000.;
+ if(m_dirtyData || true)//Currently this is how we update timestamp... potentially over expensive.
+ buildData();
+}
+
+QSGShaderEffectNode* QSGCustomParticle::buildCustomNode()
+{
+ if (m_count * 4 > 0xffff) {
+ printf("CustomParticle: Too many particles... \n");//####Why is this here?
+ return 0;
+ }
+
+ if(m_count <= 0) {
+ printf("CustomParticle: Too few particles... \n");
+ return 0;
+ }
+
+ //Create Particle Geometry
+ int vCount = m_count * 4;
+ int iCount = m_count * 6;
+ QSGGeometry *g = new QSGGeometry(PlainParticle_AttributeSet, vCount, iCount);
+ g->setDrawingMode(GL_TRIANGLES);
+ PlainVertex *vertices = (PlainVertex *) g->vertexData();
+ for (int p=0; p<m_count; ++p) {
+ reload(p);
+ vertices[0].tx = 0;
+ vertices[0].ty = 0;
+
+ vertices[1].tx = 1;
+ vertices[1].ty = 0;
+
+ vertices[2].tx = 0;
+ vertices[2].ty = 1;
+
+ vertices[3].tx = 1;
+ vertices[3].ty = 1;
+ vertices += 4;
+ }
+ quint16 *indices = g->indexDataAsUShort();
+ for (int i=0; i<m_count; ++i) {
+ int o = i * 4;
+ indices[0] = o;
+ indices[1] = o + 1;
+ indices[2] = o + 2;
+ indices[3] = o + 1;
+ indices[4] = o + 3;
+ indices[5] = o + 2;
+ indices += 6;
+ }
+
+ updateProperties();
+ QSGShaderEffectNode* node = new QSGShaderEffectNode();
+
+
+ node->setGeometry(g);
+ node->setMaterial(&m_material);
+
+ QSGShaderEffectProgram s = m_source;
+ if (s.fragmentCode.isEmpty())
+ s.fragmentCode = qt_particles_default_fragment_code;
+ if (s.vertexCode.isEmpty())
+ s.vertexCode = qt_particles_default_vertex_code;
+ m_material.setProgramSource(s);
+ return node;
+}
+
+static const QByteArray timestampName("timestamp");
+
+void QSGCustomParticle::buildData()
+{
+ if(!m_node)//Operates on m_node
+ return;
+ QVector<QPair<QByteArray, QVariant> > values;
+ QVector<QPair<QByteArray, QPointer<QSGItem> > > textures;
+ const QVector<QPair<QByteArray, QPointer<QSGItem> > > &oldTextures = m_material.textureProviders();
+
+ for (QSet<QByteArray>::const_iterator it = m_source.uniformNames.begin();
+ it != m_source.uniformNames.end(); ++it) {
+ values.append(qMakePair(*it, property(*it)));
+ }
+ for (int i = 0; i < oldTextures.size(); ++i) {
+ QSGTextureProvider *oldSource = QSGTextureProvider::from(oldTextures.at(i).second);
+ if (oldSource && oldSource->textureChangedSignal())
+ disconnect(oldTextures.at(i).second, oldSource->textureChangedSignal(), m_node, SLOT(markDirtyTexture()));
+ }
+ for (int i = 0; i < m_sources.size(); ++i) {
+ const SourceData &source = m_sources.at(i);
+ textures.append(qMakePair(source.name, source.item));
+ QSGTextureProvider *t = QSGTextureProvider::from(source.item);
+ if (t && t->textureChangedSignal())
+ connect(source.item, t->textureChangedSignal(), m_node, SLOT(markDirtyTexture()), Qt::DirectConnection);
+ }
+ values.append(qMakePair(timestampName, QVariant(m_lastTime)));
+ m_material.setUniforms(values);
+ m_material.setTextureProviders(textures);
+ m_node->markDirty(QSGNode::DirtyMaterial);
+ m_dirtyData = false;
+}
+
+void QSGCustomParticle::initialize(int idx)
+{
+ m_data[idx]->r = rand()/(qreal)RAND_MAX;
+}
+
+void QSGCustomParticle::reload(int idx)
+{
+ if (m_node == 0)
+ return;
+
+ PlainVertices *particles = (PlainVertices *) m_node->geometry()->vertexData();
+ PlainVertex *vertices = (PlainVertex *)&particles[idx];
+ for (int i=0; i<4; ++i) {
+ vertices[i].x = m_data[idx]->x - m_systemOffset.x();
+ vertices[i].y = m_data[idx]->y - m_systemOffset.y();
+ vertices[i].t = m_data[idx]->t;
+ vertices[i].lifeSpan = m_data[idx]->lifeSpan;
+ vertices[i].size = m_data[idx]->size;
+ vertices[i].endSize = m_data[idx]->endSize;
+ vertices[i].sx = m_data[idx]->sx;
+ vertices[i].sy = m_data[idx]->sy;
+ vertices[i].ax = m_data[idx]->ax;
+ vertices[i].ay = m_data[idx]->ay;
+ vertices[i].r = m_data[idx]->r;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/particles/qsgcustomparticle_p.h b/src/declarative/particles/qsgcustomparticle_p.h
new file mode 100644
index 0000000000..50ff37a2a0
--- /dev/null
+++ b/src/declarative/particles/qsgcustomparticle_p.h
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CUSTOM_PARTICLE_H
+#define CUSTOM_PARTICLE_H
+#include "qsgparticlepainter_p.h"
+#include <QtDeclarative/private/qsgshadereffectnode_p.h>
+#include <QSignalMapper>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QSGNode;
+struct PlainVertices;
+//Genealogy: Hybrid of UltraParticle and ShaderEffectItem
+class QSGCustomParticle : public QSGParticlePainter
+{
+ Q_OBJECT
+ Q_PROPERTY(QByteArray fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged)
+ Q_PROPERTY(QByteArray vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged)
+
+public:
+ explicit QSGCustomParticle(QSGItem* parent=0);
+
+ QByteArray fragmentShader() const { return m_source.fragmentCode; }
+ void setFragmentShader(const QByteArray &code);
+
+ QByteArray vertexShader() const { return m_source.vertexCode; }
+ void setVertexShader(const QByteArray &code);
+public Q_SLOTS:
+ void updateData();
+ void changeSource(int);
+Q_SIGNALS:
+ void fragmentShaderChanged();
+ void vertexShaderChanged();
+protected:
+ virtual void initialize(int idx);
+ virtual void reload(int idx);
+
+ QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
+ void prepareNextFrame();
+ void setSource(const QVariant &var, int index);
+ void disconnectPropertySignals();
+ void connectPropertySignals();
+ void reset();
+ void resize(int oldCount, int newCount);
+ void updateProperties();
+ void lookThroughShaderCode(const QByteArray &code);
+ virtual void componentComplete();
+ QSGShaderEffectNode *buildCustomNode();
+ void performPendingResize();
+
+private:
+ void buildData();
+
+
+ bool m_pleaseReset;
+ bool m_dirtyData;
+ QSGShaderEffectProgram m_source;
+ struct SourceData
+ {
+ QSignalMapper *mapper;
+ QPointer<QSGItem> item;
+ QByteArray name;
+ };
+ QVector<SourceData> m_sources;
+ QSGShaderEffectMaterial m_material;
+ QSGShaderEffectNode* m_node;
+ qreal m_lastTime;
+
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif //HEADER_GUARD
diff --git a/src/imports/particles/ellipseextruder.cpp b/src/declarative/particles/qsgellipseextruder.cpp
index 1a0d70594b..76925895b9 100644
--- a/src/imports/particles/ellipseextruder.cpp
+++ b/src/declarative/particles/qsgellipseextruder.cpp
@@ -39,16 +39,16 @@
**
****************************************************************************/
-#include "ellipseextruder.h"
+#include "qsgellipseextruder_p.h"
#include <cmath>
QT_BEGIN_NAMESPACE
-EllipseExtruder::EllipseExtruder(QObject *parent) :
- ParticleExtruder(parent)
+QSGEllipseExtruder::QSGEllipseExtruder(QObject *parent) :
+ QSGParticleExtruder(parent)
, m_fill(true)
{
}
-QPointF EllipseExtruder::extrude(const QRectF & r)
+QPointF QSGEllipseExtruder::extrude(const QRectF & r)
{
qreal theta = ((qreal)rand()/RAND_MAX) * 6.2831853071795862;
qreal mag = m_fill ? ((qreal)rand()/RAND_MAX) : 1;
@@ -56,7 +56,7 @@ QPointF EllipseExtruder::extrude(const QRectF & r)
r.y() + r.height()/2 + mag * (r.height()/2) * sin(theta));
}
-bool EllipseExtruder::contains(const QRectF &bounds, const QPointF &point)
+bool QSGEllipseExtruder::contains(const QRectF &bounds, const QPointF &point)
{
return bounds.contains(point);//TODO: Ellipse
}
diff --git a/src/imports/particles/ellipseextruder.h b/src/declarative/particles/qsgellipseextruder_p.h
index 25cc9bc16a..9f770a7ee6 100644
--- a/src/imports/particles/ellipseextruder.h
+++ b/src/declarative/particles/qsgellipseextruder_p.h
@@ -41,7 +41,7 @@
#ifndef ELLIPSEEXTRUDER_H
#define ELLIPSEEXTRUDER_H
-#include "particleextruder.h"
+#include "qsgparticleextruder_p.h"
QT_BEGIN_HEADER
@@ -50,12 +50,12 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class EllipseExtruder : public ParticleExtruder
+class QSGEllipseExtruder : public QSGParticleExtruder
{
Q_OBJECT
Q_PROPERTY(bool fill READ fill WRITE setFill NOTIFY fillChanged)//###Use base class? If it's still box
public:
- explicit EllipseExtruder(QObject *parent = 0);
+ explicit QSGEllipseExtruder(QObject *parent = 0);
virtual QPointF extrude(const QRectF &);
virtual bool contains(const QRectF &bounds, const QPointF &point);
diff --git a/src/imports/particles/trailsemitter.cpp b/src/declarative/particles/qsgemitter.cpp
index 41635a4299..c3ec3ffc9e 100644
--- a/src/imports/particles/trailsemitter.cpp
+++ b/src/declarative/particles/qsgemitter.cpp
@@ -39,13 +39,13 @@
**
****************************************************************************/
-#include "trailsemitter.h"
-#include "particlesystem.h"
-#include "particle.h"
+#include "qsgemitter_p.h"
+#include "qsgparticlesystem_p.h"
+#include "qsgparticlepainter_p.h"//TODO: What was this for again?
QT_BEGIN_NAMESPACE
-TrailsEmitter::TrailsEmitter(QSGItem* parent)
- : ParticleEmitter(parent)
+QSGBasicEmitter::QSGBasicEmitter(QSGItem* parent)
+ : QSGParticleEmitter(parent)
, m_speed_from_movement(0)
, m_particle_count(0)
, m_reset_last(true)
@@ -55,7 +55,7 @@ TrailsEmitter::TrailsEmitter(QSGItem* parent)
// setFlag(ItemHasContents);
}
-void TrailsEmitter::setSpeedFromMovement(qreal t)
+void QSGBasicEmitter::setSpeedFromMovement(qreal t)
{
if (t == m_speed_from_movement)
return;
@@ -63,12 +63,12 @@ void TrailsEmitter::setSpeedFromMovement(qreal t)
emit speedFromMovementChanged();
}
-void TrailsEmitter::reset()
+void QSGBasicEmitter::reset()
{
m_reset_last = true;
}
-void TrailsEmitter::emitWindow(int timeStamp)
+void QSGBasicEmitter::emitWindow(int timeStamp)
{
if (m_system == 0)
return;
@@ -121,10 +121,9 @@ void TrailsEmitter::emitWindow(int timeStamp)
pt = time;
while (pt < time || !m_burstQueue.isEmpty()) {
//int pos = m_last_particle % m_particle_count;
- ParticleData* datum = m_system->newDatum(m_system->m_groupIds[m_particle]);
+ QSGParticleData* datum = m_system->newDatum(m_system->m_groupIds[m_particle]);
if(datum){//actually emit(otherwise we've been asked to skip this one)
datum->e = this;//###useful?
- ParticleVertex &p = datum->pv;
qreal t = 1 - (pt - opt) / dt;
qreal vx =
- 2 * ax * (1 - t)
@@ -137,8 +136,8 @@ void TrailsEmitter::emitWindow(int timeStamp)
// Particle timestamp
- p.t = pt;
- p.lifeSpan = //TODO:Promote to base class?
+ datum->t = pt;
+ datum->lifeSpan = //TODO:Promote to base class?
(m_particleDuration
+ ((rand() % ((m_particleDurationVariation*2) + 1)) - m_particleDurationVariation))
/ 1000.0;
@@ -153,20 +152,20 @@ void TrailsEmitter::emitWindow(int timeStamp)
, width(), height());
}
QPointF newPos = effectiveExtruder()->extrude(boundsRect);
- p.x = newPos.x();
- p.y = newPos.y();
+ datum->x = newPos.x();
+ datum->y = newPos.y();
// Particle speed
const QPointF &speed = m_speed->sample(newPos);
- p.sx = speed.x()
+ datum->sx = speed.x()
+ m_speed_from_movement * vx;
- p.sy = speed.y()
+ datum->sy = speed.y()
+ m_speed_from_movement * vy;
// Particle acceleration
const QPointF &accel = m_acceleration->sample(newPos);
- p.ax = accel.x();
- p.ay = accel.y();
+ datum->ax = accel.x();
+ datum->ay = accel.y();
// Particle size
float sizeVariation = -m_particleSizeVariation
@@ -175,8 +174,8 @@ void TrailsEmitter::emitWindow(int timeStamp)
float size = qMax((qreal)0.0 , m_particleSize + sizeVariation);
float endSize = qMax((qreal)0.0 , sizeAtEnd + sizeVariation);
- p.size = size;// * float(m_emitting);
- p.endSize = endSize;// * float(m_emitting);
+ datum->size = size;// * float(m_emitting);
+ datum->endSize = endSize;// * float(m_emitting);
m_system->emitParticle(datum);
}
diff --git a/src/imports/particles/trailsemitter.h b/src/declarative/particles/qsgemitter_p.h
index 1ae150c0d2..3988c71cdf 100644
--- a/src/imports/particles/trailsemitter.h
+++ b/src/declarative/particles/qsgemitter_p.h
@@ -45,7 +45,7 @@
#include <QtCore>
#include <QtGui>
-#include "particleemitter.h"
+#include "qsgparticleemitter_p.h"
QT_BEGIN_HEADER
@@ -54,18 +54,17 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class ParticleTrailsMaterial;
class QSGGeometryNode;
-class TrailsEmitter : public ParticleEmitter
+class QSGBasicEmitter : public QSGParticleEmitter
{
Q_OBJECT
Q_PROPERTY(qreal speedFromMovement READ speedFromMovement WRITE setSpeedFromMovement NOTIFY speedFromMovementChanged)
public:
- explicit TrailsEmitter(QSGItem* parent=0);
- virtual ~TrailsEmitter(){}
+ explicit QSGBasicEmitter(QSGItem* parent=0);
+ virtual ~QSGBasicEmitter(){}
virtual void emitWindow(int timeStamp);
diff --git a/src/imports/particles/followemitter.cpp b/src/declarative/particles/qsgfollowemitter.cpp
index 17a544f62d..ba31e8f834 100644
--- a/src/imports/particles/followemitter.cpp
+++ b/src/declarative/particles/qsgfollowemitter.cpp
@@ -39,21 +39,22 @@
**
****************************************************************************/
-#include "followemitter.h"
-#include "particle.h"
+#include "qsgfollowemitter_p.h"
+#include "qsgparticlepainter_p.h"//TODO: What was this for again?
#include <cmath>
QT_BEGIN_NAMESPACE
-FollowEmitter::FollowEmitter(QSGItem *parent) :
- ParticleEmitter(parent)
+QSGFollowEmitter::QSGFollowEmitter(QSGItem *parent) :
+ QSGParticleEmitter(parent)
, m_particlesPerParticlePerSecond(0)
, m_lastTimeStamp(0)
, m_emitterXVariation(0)
, m_emitterYVariation(0)
, m_followCount(0)
, m_emissionExtruder(0)
- , m_defaultEmissionExtruder(new ParticleExtruder(this))
+ , m_defaultEmissionExtruder(new QSGParticleExtruder(this))
{
+ //TODO: If followed increased their size
connect(this, SIGNAL(followChanged(QString)),
this, SLOT(recalcParticlesPerSecond()));
connect(this, SIGNAL(particleDurationChanged(int)),
@@ -62,12 +63,12 @@ FollowEmitter::FollowEmitter(QSGItem *parent) :
this, SLOT(recalcParticlesPerSecond()));
}
-void FollowEmitter::recalcParticlesPerSecond(){
+void QSGFollowEmitter::recalcParticlesPerSecond(){
if(!m_system)
return;
m_followCount = m_system->m_groupData[m_system->m_groupIds[m_follow]]->size;
if(!m_followCount){
- setParticlesPerSecond(1000);//XXX: Fix this horrendous hack, needed so they aren't turned off from start (causes crashes - test that when gone you don't crash with 0 PPPS)
+ setParticlesPerSecond(1);//XXX: Fix this horrendous hack, needed so they aren't turned off from start (causes crashes - test that when gone you don't crash with 0 PPPS)
}else{
setParticlesPerSecond(m_particlesPerParticlePerSecond * m_followCount);
m_lastEmission.resize(m_followCount);
@@ -75,12 +76,12 @@ void FollowEmitter::recalcParticlesPerSecond(){
}
}
-void FollowEmitter::reset()
+void QSGFollowEmitter::reset()
{
m_followCount = 0;
}
-void FollowEmitter::emitWindow(int timeStamp)
+void QSGFollowEmitter::emitWindow(int timeStamp)
{
if (m_system == 0)
return;
@@ -111,61 +112,59 @@ void FollowEmitter::emitWindow(int timeStamp)
int gId = m_system->m_groupIds[m_follow];
int gId2 = m_system->m_groupIds[m_particle];
- for(int i=0; i<m_system->m_groupData[gId]->size; i++){
- pt = m_lastEmission[i];
- ParticleData* d = m_system->m_data[i + m_system->m_groupData[gId]->start];
+ foreach(QSGParticleData *d, m_system->m_groupData[gId]->data){
if(!d || !d->stillAlive())
continue;
- if(pt < d->pv.t)
- pt = d->pv.t;
+ pt = m_lastEmission[d->index];
+ if(pt < d->t)
+ pt = d->t;
if(!effectiveExtruder()->contains(QRectF(offset.x(), offset.y(), width(), height()),QPointF(d->curX(), d->curY()))){
- m_lastEmission[i] = time;//jump over this time period without emitting, because it's outside
+ m_lastEmission[d->index] = time;//jump over this time period without emitting, because it's outside
continue;
}
while(pt < time || !m_burstQueue.isEmpty()){
- ParticleData* datum = m_system->newDatum(gId2);
+ QSGParticleData* datum = m_system->newDatum(gId2);
if(datum){//else, skip this emission
datum->e = this;//###useful?
- ParticleVertex &p = datum->pv;
// Particle timestamp
- p.t = pt;
- p.lifeSpan =
+ datum->t = pt;
+ datum->lifeSpan =
(m_particleDuration
+ ((rand() % ((m_particleDurationVariation*2) + 1)) - m_particleDurationVariation))
/ 1000.0;
// Particle position
// Note that burst location doesn't get used for follow emitter
- qreal followT = pt - d->pv.t;
+ qreal followT = pt - d->t;
qreal followT2 = followT * followT * 0.5;
- qreal sizeOffset = d->pv.size/2;//TODO: Current size? As an option
+ qreal sizeOffset = d->size/2;//TODO: Current size? As an option
//TODO: Set variations
//Subtract offset, because PS expects this in emitter coordinates
- QRectF boundsRect(d->pv.x - offset.x() + d->pv.sx * followT + d->pv.ax * followT2 - m_emitterXVariation/2,
- d->pv.y - offset.y() + d->pv.sy * followT + d->pv.ay * followT2 - m_emitterYVariation/2,
+ QRectF boundsRect(d->x - offset.x() + d->sx * followT + d->ax * followT2 - m_emitterXVariation/2,
+ d->y - offset.y() + d->sy * followT + d->ay * followT2 - m_emitterYVariation/2,
m_emitterXVariation,
m_emitterYVariation);
- // QRectF boundsRect(d->pv.x + d->pv.sx * followT + d->pv.ax * followT2 + offset.x() - sizeOffset,
- // d->pv.y + d->pv.sy * followT + d->pv.ay * followT2 + offset.y() - sizeOffset,
+ // QRectF boundsRect(d->x + d->sx * followT + d->ax * followT2 + offset.x() - sizeOffset,
+ // d->y + d->sy * followT + d->ay * followT2 + offset.y() - sizeOffset,
// sizeOffset*2,
// sizeOffset*2);
- ParticleExtruder* effectiveEmissionExtruder = m_emissionExtruder ? m_emissionExtruder : m_defaultEmissionExtruder;
+ QSGParticleExtruder* effectiveEmissionExtruder = m_emissionExtruder ? m_emissionExtruder : m_defaultEmissionExtruder;
const QPointF &newPos = effectiveEmissionExtruder->extrude(boundsRect);
- p.x = newPos.x();
- p.y = newPos.y();
+ datum->x = newPos.x();
+ datum->y = newPos.y();
// Particle speed
const QPointF &speed = m_speed->sample(newPos);
- p.sx = speed.x();
- p.sy = speed.y();
+ datum->sx = speed.x();
+ datum->sy = speed.y();
// Particle acceleration
const QPointF &accel = m_acceleration->sample(newPos);
- p.ax = accel.x();
- p.ay = accel.y();
+ datum->ax = accel.x();
+ datum->ay = accel.y();
// Particle size
float sizeVariation = -m_particleSizeVariation
@@ -174,8 +173,8 @@ void FollowEmitter::emitWindow(int timeStamp)
float size = qMax((qreal)0.0, m_particleSize + sizeVariation);
float endSize = qMax((qreal)0.0, sizeAtEnd + sizeVariation);
- p.size = size * float(m_emitting);
- p.endSize = endSize * float(m_emitting);
+ datum->size = size * float(m_emitting);
+ datum->endSize = endSize * float(m_emitting);
m_system->emitParticle(datum);
}
@@ -187,7 +186,7 @@ void FollowEmitter::emitWindow(int timeStamp)
pt += particleRatio;
}
}
- m_lastEmission[i] = pt;
+ m_lastEmission[d->index] = pt;
}
m_lastTimeStamp = time;
diff --git a/src/imports/particles/followemitter.h b/src/declarative/particles/qsgfollowemitter_p.h
index 6df293e2e1..bf5d2fe8ef 100644
--- a/src/imports/particles/followemitter.h
+++ b/src/declarative/particles/qsgfollowemitter_p.h
@@ -41,8 +41,8 @@
#ifndef FOLLOWEMITTER_H
#define FOLLOWEMITTER_H
-#include "particleemitter.h"
-#include "particleaffector.h"
+#include "qsgparticleemitter_p.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
@@ -51,21 +51,21 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class FollowEmitter : public ParticleEmitter
+class QSGFollowEmitter : public QSGParticleEmitter
{
Q_OBJECT
Q_PROPERTY(QString follow READ follow WRITE setFollow NOTIFY followChanged)
//### Remove, and just document that particles per second is per particle? But has count issues
- Q_PROPERTY(int particlesPerParticlePerSecond READ particlesPerParticlePerSecond WRITE setParticlesPerParticlePerSecond NOTIFY particlesPerParticlePerSecondChanged)
+ Q_PROPERTY(int emitRatePerParticle READ particlesPerParticlePerSecond WRITE setParticlesPerParticlePerSecond NOTIFY particlesPerParticlePerSecondChanged)
//TODO: Document that FollowEmitter's box is where it follows. It emits in a rect centered on the followed particle
//TODO: A set of properties that can involve the particle size of the followed
- Q_PROPERTY(ParticleExtruder* emissionShape READ emissonShape WRITE setEmissionShape NOTIFY emissionShapeChanged)
- Q_PROPERTY(qreal emissionHeight READ emitterYVariation WRITE setEmitterYVariation NOTIFY emitterYVariationChanged)
- Q_PROPERTY(qreal emissionWidth READ emitterXVariation WRITE setEmitterXVariation NOTIFY emitterXVariationChanged)
+ Q_PROPERTY(QSGParticleExtruder* emitShape READ emissonShape WRITE setEmissionShape NOTIFY emissionShapeChanged)
+ Q_PROPERTY(qreal emitHeight READ emitterYVariation WRITE setEmitterYVariation NOTIFY emitterYVariationChanged)
+ Q_PROPERTY(qreal emitWidth READ emitterXVariation WRITE setEmitterXVariation NOTIFY emitterXVariationChanged)
public:
- explicit FollowEmitter(QSGItem *parent = 0);
+ explicit QSGFollowEmitter(QSGItem *parent = 0);
virtual void emitWindow(int timeStamp);
virtual void reset();
@@ -89,7 +89,7 @@ public:
return m_follow;
}
- ParticleExtruder* emissonShape() const
+ QSGParticleExtruder* emissonShape() const
{
return m_emissionExtruder;
}
@@ -104,7 +104,7 @@ signals:
void followChanged(QString arg);
- void emissionShapeChanged(ParticleExtruder* arg);
+ void emissionShapeChanged(QSGParticleExtruder* arg);
public slots:
@@ -139,7 +139,7 @@ public slots:
}
}
- void setEmissionShape(ParticleExtruder* arg)
+ void setEmissionShape(QSGParticleExtruder* arg)
{
if (m_emissionExtruder != arg) {
m_emissionExtruder = arg;
@@ -151,7 +151,7 @@ private slots:
void recalcParticlesPerSecond();
private:
- QSet<ParticleData*> m_pending;
+ QSet<QSGParticleData*> m_pending;
QVector<qreal> m_lastEmission;
int m_particlesPerParticlePerSecond;
qreal m_lastTimeStamp;
@@ -159,8 +159,8 @@ private:
qreal m_emitterYVariation;
QString m_follow;
int m_followCount;
- ParticleExtruder* m_emissionExtruder;
- ParticleExtruder* m_defaultEmissionExtruder;
+ QSGParticleExtruder* m_emissionExtruder;
+ QSGParticleExtruder* m_defaultEmissionExtruder;
};
QT_END_NAMESPACE
diff --git a/src/imports/particles/frictionaffector.cpp b/src/declarative/particles/qsgfriction.cpp
index 057bb20958..828d20556d 100644
--- a/src/imports/particles/frictionaffector.cpp
+++ b/src/declarative/particles/qsgfriction.cpp
@@ -39,14 +39,14 @@
**
****************************************************************************/
-#include "frictionaffector.h"
+#include "qsgfriction_p.h"
QT_BEGIN_NAMESPACE
-FrictionAffector::FrictionAffector(QSGItem *parent) :
- ParticleAffector(parent), m_factor(0.0)
+QSGFrictionAffector::QSGFrictionAffector(QSGItem *parent) :
+ QSGParticleAffector(parent), m_factor(0.0)
{
}
-bool FrictionAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGFrictionAffector::affectParticle(QSGParticleData *d, qreal dt)
{
if(!m_factor)
return false;
diff --git a/src/imports/particles/frictionaffector.h b/src/declarative/particles/qsgfriction_p.h
index 67b5f1029c..6b5a86f3f2 100644
--- a/src/imports/particles/frictionaffector.h
+++ b/src/declarative/particles/qsgfriction_p.h
@@ -41,7 +41,7 @@
#ifndef FRICTIONAFFECTOR_H
#define FRICTIONAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
@@ -50,19 +50,19 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class FrictionAffector : public ParticleAffector
+class QSGFrictionAffector : public QSGParticleAffector
{
Q_OBJECT
Q_PROPERTY(qreal factor READ factor WRITE setFactor NOTIFY factorChanged)
public:
- explicit FrictionAffector(QSGItem *parent = 0);
+ explicit QSGFrictionAffector(QSGItem *parent = 0);
qreal factor() const
{
return m_factor;
}
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
signals:
void factorChanged(qreal arg);
diff --git a/src/imports/particles/gravityaffector.cpp b/src/declarative/particles/qsggravity.cpp
index 02edbacd68..b1cf3e9481 100644
--- a/src/imports/particles/gravityaffector.cpp
+++ b/src/declarative/particles/qsggravity.cpp
@@ -39,12 +39,12 @@
**
****************************************************************************/
-#include "gravityaffector.h"
+#include "qsggravity_p.h"
#include <cmath>
QT_BEGIN_NAMESPACE
const qreal CONV = 0.017453292520444443;
-GravityAffector::GravityAffector(QSGItem *parent) :
- ParticleAffector(parent), m_acceleration(-10), m_angle(90), m_xAcc(0), m_yAcc(0)
+QSGGravityAffector::QSGGravityAffector(QSGItem *parent) :
+ QSGParticleAffector(parent), m_acceleration(-10), m_angle(90), m_xAcc(0), m_yAcc(0)
{
connect(this, SIGNAL(accelerationChanged(qreal)),
this, SLOT(recalc()));
@@ -53,22 +53,22 @@ GravityAffector::GravityAffector(QSGItem *parent) :
recalc();
}
-void GravityAffector::recalc()
+void QSGGravityAffector::recalc()
{
qreal theta = m_angle * CONV;
m_xAcc = m_acceleration * cos(theta);
m_yAcc = m_acceleration * sin(theta);
}
-bool GravityAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGGravityAffector::affectParticle(QSGParticleData *d, qreal dt)
{
Q_UNUSED(dt);
bool changed = false;
- if(d->pv.ax != m_xAcc){
+ if(d->ax != m_xAcc){
d->setInstantaneousAX(m_xAcc);
changed = true;
}
- if(d->pv.ay != m_yAcc){
+ if(d->ay != m_yAcc){
d->setInstantaneousAY(m_yAcc);
changed = true;
}
diff --git a/src/imports/particles/gravityaffector.h b/src/declarative/particles/qsggravity_p.h
index 004b59e182..57b2511911 100644
--- a/src/imports/particles/gravityaffector.h
+++ b/src/declarative/particles/qsggravity_p.h
@@ -41,7 +41,7 @@
#ifndef GRAVITYAFFECTOR_H
#define GRAVITYAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
@@ -50,13 +50,13 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class GravityAffector : public ParticleAffector
+class QSGGravityAffector : public QSGParticleAffector
{
Q_OBJECT
Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
public:
- explicit GravityAffector(QSGItem *parent = 0);
+ explicit QSGGravityAffector(QSGItem *parent = 0);
qreal acceleration() const
{
return m_acceleration;
@@ -67,7 +67,7 @@ public:
return m_angle;
}
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
signals:
void accelerationChanged(qreal arg);
diff --git a/src/imports/particles/ultraparticle.cpp b/src/declarative/particles/qsgimageparticle.cpp
index fd49523aff..836236c13e 100644
--- a/src/imports/particles/ultraparticle.cpp
+++ b/src/declarative/particles/qsgimageparticle.cpp
@@ -45,10 +45,10 @@
#include <qsgtexturematerial.h>
#include <qsgtexture.h>
#include <QFile>
-#include "ultraparticle.h"
-#include "particleemitter.h"
-#include "spritestate.h"
-#include "spriteengine.h"
+#include "qsgimageparticle_p.h"
+#include "qsgparticleemitter_p.h"
+#include "qsgsprite_p.h"
+#include "qsgspriteengine_p.h"
#include <QGLFunctions>
#include <qsgengine.h>
@@ -97,11 +97,11 @@ class UltraMaterialData : public QSGMaterialShader
public:
UltraMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
{
- QFile vf(vertexFile ? vertexFile : ":resources/ultravertex.shader");
+ QFile vf(vertexFile ? vertexFile : ":defaultshaders/ultravertex.shader");
vf.open(QFile::ReadOnly);
m_vertex_code = vf.readAll();
- QFile ff(fragmentFile ? fragmentFile : ":resources/ultrafragment.shader");
+ QFile ff(fragmentFile ? fragmentFile : ":defaultshaders/ultrafragment.shader");
ff.open(QFile::ReadOnly);
m_fragment_code = ff.readAll();
@@ -211,11 +211,11 @@ class SimpleMaterialData : public QSGMaterialShader
public:
SimpleMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
{
- QFile vf(vertexFile ? vertexFile : ":resources/simplevertex.shader");
+ QFile vf(vertexFile ? vertexFile : ":defaultshaders/simplevertex.shader");
vf.open(QFile::ReadOnly);
m_vertex_code = vf.readAll();
- QFile ff(fragmentFile ? fragmentFile : ":resources/simplefragment.shader");
+ QFile ff(fragmentFile ? fragmentFile : ":defaultshaders/simplefragment.shader");
ff.open(QFile::ReadOnly);
m_fragment_code = ff.readAll();
@@ -281,8 +281,8 @@ QSGMaterialShader *SimpleMaterial::createShader() const {
return new SimpleMaterialData;
}
-UltraParticle::UltraParticle(QSGItem* parent)
- : ParticleType(parent)
+QSGImageParticle::QSGImageParticle(QSGItem* parent)
+ : QSGParticlePainter(parent)
, m_do_reset(false)
, m_color_variation(0.0)
, m_node(0)
@@ -307,12 +307,12 @@ UltraParticle::UltraParticle(QSGItem* parent)
setFlag(ItemHasContents);
}
-QDeclarativeListProperty<SpriteState> UltraParticle::sprites()
+QDeclarativeListProperty<QSGSprite> QSGImageParticle::sprites()
{
- return QDeclarativeListProperty<SpriteState>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
+ return QDeclarativeListProperty<QSGSprite>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
}
-void UltraParticle::setImage(const QUrl &image)
+void QSGImageParticle::setImage(const QUrl &image)
{
if (image == m_image_name)
return;
@@ -322,7 +322,7 @@ void UltraParticle::setImage(const QUrl &image)
}
-void UltraParticle::setColortable(const QUrl &table)
+void QSGImageParticle::setColortable(const QUrl &table)
{
if (table == m_colortable_name)
return;
@@ -331,7 +331,7 @@ void UltraParticle::setColortable(const QUrl &table)
reset();
}
-void UltraParticle::setSizetable(const QUrl &table)
+void QSGImageParticle::setSizetable(const QUrl &table)
{
if (table == m_sizetable_name)
return;
@@ -340,7 +340,7 @@ void UltraParticle::setSizetable(const QUrl &table)
reset();
}
-void UltraParticle::setOpacitytable(const QUrl &table)
+void QSGImageParticle::setOpacitytable(const QUrl &table)
{
if (table == m_opacitytable_name)
return;
@@ -349,77 +349,77 @@ void UltraParticle::setOpacitytable(const QUrl &table)
reset();
}
-void UltraParticle::setColor(const QColor &color)
+void QSGImageParticle::setColor(const QColor &color)
{
if (color == m_color)
return;
m_color = color;
emit colorChanged();
- if(perfLevel < Coloured)
+ if(perfLevel < Colored)
reset();
}
-void UltraParticle::setColorVariation(qreal var)
+void QSGImageParticle::setColorVariation(qreal var)
{
if (var == m_color_variation)
return;
m_color_variation = var;
emit colorVariationChanged();
- if(perfLevel < Coloured)
+ if(perfLevel < Colored)
reset();
}
-void UltraParticle::setAlphaVariation(qreal arg)
+void QSGImageParticle::setAlphaVariation(qreal arg)
{
if (m_alphaVariation != arg) {
m_alphaVariation = arg;
emit alphaVariationChanged(arg);
}
- if(perfLevel < Coloured)
+ if(perfLevel < Colored)
reset();
}
-void UltraParticle::setAlpha(qreal arg)
+void QSGImageParticle::setAlpha(qreal arg)
{
if (m_alpha != arg) {
m_alpha = arg;
emit alphaChanged(arg);
}
- if(perfLevel < Coloured)
+ if(perfLevel < Colored)
reset();
}
-void UltraParticle::setRedVariation(qreal arg)
+void QSGImageParticle::setRedVariation(qreal arg)
{
if (m_redVariation != arg) {
m_redVariation = arg;
emit redVariationChanged(arg);
}
- if(perfLevel < Coloured)
+ if(perfLevel < Colored)
reset();
}
-void UltraParticle::setGreenVariation(qreal arg)
+void QSGImageParticle::setGreenVariation(qreal arg)
{
if (m_greenVariation != arg) {
m_greenVariation = arg;
emit greenVariationChanged(arg);
}
- if(perfLevel < Coloured)
+ if(perfLevel < Colored)
reset();
}
-void UltraParticle::setBlueVariation(qreal arg)
+void QSGImageParticle::setBlueVariation(qreal arg)
{
if (m_blueVariation != arg) {
m_blueVariation = arg;
emit blueVariationChanged(arg);
}
- if(perfLevel < Coloured)
+ if(perfLevel < Colored)
reset();
}
-void UltraParticle::setRotation(qreal arg)
+void QSGImageParticle::setRotation(qreal arg)
{
if (m_rotation != arg) {
m_rotation = arg;
@@ -429,7 +429,7 @@ void UltraParticle::setRotation(qreal arg)
reset();
}
-void UltraParticle::setRotationVariation(qreal arg)
+void QSGImageParticle::setRotationVariation(qreal arg)
{
if (m_rotationVariation != arg) {
m_rotationVariation = arg;
@@ -439,7 +439,7 @@ void UltraParticle::setRotationVariation(qreal arg)
reset();
}
-void UltraParticle::setRotationSpeed(qreal arg)
+void QSGImageParticle::setRotationSpeed(qreal arg)
{
if (m_rotationSpeed != arg) {
m_rotationSpeed = arg;
@@ -449,7 +449,7 @@ void UltraParticle::setRotationSpeed(qreal arg)
reset();
}
-void UltraParticle::setRotationSpeedVariation(qreal arg)
+void QSGImageParticle::setRotationSpeedVariation(qreal arg)
{
if (m_rotationSpeedVariation != arg) {
m_rotationSpeedVariation = arg;
@@ -459,7 +459,7 @@ void UltraParticle::setRotationSpeedVariation(qreal arg)
reset();
}
-void UltraParticle::setAutoRotation(bool arg)
+void QSGImageParticle::setAutoRotation(bool arg)
{
if (m_autoRotation != arg) {
m_autoRotation = arg;
@@ -469,7 +469,7 @@ void UltraParticle::setAutoRotation(bool arg)
reset();
}
-void UltraParticle::setXVector(VaryingVector* arg)
+void QSGImageParticle::setXVector(QSGStochasticDirection* arg)
{
if (m_xVector != arg) {
m_xVector = arg;
@@ -479,7 +479,7 @@ void UltraParticle::setXVector(VaryingVector* arg)
reset();
}
-void UltraParticle::setYVector(VaryingVector* arg)
+void QSGImageParticle::setYVector(QSGStochasticDirection* arg)
{
if (m_yVector != arg) {
m_yVector = arg;
@@ -489,7 +489,7 @@ void UltraParticle::setYVector(VaryingVector* arg)
reset();
}
-void UltraParticle::setBloat(bool arg)
+void QSGImageParticle::setBloat(bool arg)
{
if (m_bloat != arg) {
m_bloat = arg;
@@ -498,24 +498,19 @@ void UltraParticle::setBloat(bool arg)
if(perfLevel < 9999)
reset();
}
-void UltraParticle::setCount(int c)
-{
- ParticleType::setCount(c);
- m_pleaseReset = true;
-}
-void UltraParticle::reset()
+void QSGImageParticle::reset()
{
- ParticleType::reset();
+ QSGParticlePainter::reset();
m_pleaseReset = true;
}
-void UltraParticle::createEngine()
+void QSGImageParticle::createEngine()
{
if(m_spriteEngine)
delete m_spriteEngine;
if(m_sprites.count())
- m_spriteEngine = new SpriteEngine(m_sprites, this);
+ m_spriteEngine = new QSGSpriteEngine(m_sprites, this);
else
m_spriteEngine = 0;
reset();
@@ -553,7 +548,7 @@ static QSGGeometry::AttributeSet UltraParticle_AttributeSet =
UltraParticle_Attributes
};
-QSGGeometryNode* UltraParticle::buildSimpleParticleNode()
+QSGGeometryNode* QSGImageParticle::buildSimpleParticleNode()
{
perfLevel = Simple;//TODO: Intermediate levels
QImage image = QImage(m_image_name.toLocalFile());
@@ -569,20 +564,19 @@ QSGGeometryNode* UltraParticle::buildSimpleParticleNode()
g->setDrawingMode(GL_TRIANGLES);
SimpleVertex *vertices = (SimpleVertex *) g->vertexData();
- for (int p=0; p<m_count; ++p) {
- for (int i=0; i<4; ++i) {
- vertices[i].x = 0;
- vertices[i].y = 0;
- vertices[i].t = -1;
- vertices[i].lifeSpan = 0;
- vertices[i].size = 0;
- vertices[i].endSize = 0;
- vertices[i].sx = 0;
- vertices[i].sy = 0;
- vertices[i].ax = 0;
- vertices[i].ay = 0;
+ for (int p=0; p<m_count; ++p){
+ for(int i=0; i<4; i++){
+ vertices[i].x = m_data[p]->x;
+ vertices[i].y = m_data[p]->y;
+ vertices[i].t = m_data[p]->t;
+ vertices[i].size = m_data[p]->size;
+ vertices[i].endSize = m_data[p]->endSize;
+ vertices[i].sx = m_data[p]->sx;
+ vertices[i].sy = m_data[p]->sy;
+ vertices[i].ax = m_data[p]->ax;
+ vertices[i].ay = m_data[p]->ay;
}
-
+ //reload(p);
vertices[0].tx = 0;
vertices[0].ty = 0;
@@ -610,6 +604,9 @@ QSGGeometryNode* UltraParticle::buildSimpleParticleNode()
indices += 6;
}
+ m_node = new QSGGeometryNode();
+ m_node->setGeometry(g);
+
if (m_material) {
delete m_material;
m_material = 0;
@@ -619,24 +616,21 @@ QSGGeometryNode* UltraParticle::buildSimpleParticleNode()
m_material->texture = sceneGraphEngine()->createTextureFromImage(image);
m_material->texture->setFiltering(QSGTexture::Linear);
m_material->framecount = 1;
- m_node = new QSGGeometryNode();
- m_node->setGeometry(g);
m_node->setMaterial(m_material);
m_last_particle = 0;
-
return m_node;
}
-QSGGeometryNode* UltraParticle::buildParticleNode()
+QSGGeometryNode* QSGImageParticle::buildParticleNode()
{
if (m_count * 4 > 0xffff) {
- printf("UltraParticle: Too many particles... \n");//####Why is this here?
+ printf("UltraParticle: Too many particles... \n");//### Why is this here?
return 0;
}
if(m_count <= 0) {
- printf("UltraParticle: Too few particles... \n");
+ qDebug() << "UltraParticle: Too few particles... \n";//XXX: Is now a vaild intermediate state...
return 0;
}
@@ -679,70 +673,12 @@ QSGGeometryNode* UltraParticle::buildParticleNode()
QSGGeometry *g = new QSGGeometry(UltraParticle_AttributeSet, vCount, iCount);
g->setDrawingMode(GL_TRIANGLES);
+ m_node = new QSGGeometryNode();
+ m_node->setGeometry(g);
UltraVertex *vertices = (UltraVertex *) g->vertexData();
- SimpleVertex *oldSimple = (SimpleVertex *) m_lastData;//TODO: Other levels
- if(m_lastLevel == 1)
- qDebug() << "Theta" << m_lastLevel << oldSimple[0].x << oldSimple[0].y << oldSimple[0].t;
for (int p=0; p<m_count; ++p) {
-
- if (m_lastLevel == 1) {//Transplant/IntermediateVertices?
- for (int i=0; i<4; ++i) {
- vertices[i].x = oldSimple[i].x;
- vertices[i].y = oldSimple[i].y;
- vertices[i].t = oldSimple[i].t;
- vertices[i].lifeSpan = oldSimple[i].lifeSpan;
- vertices[i].size = oldSimple[i].size;
- vertices[i].endSize = oldSimple[i].endSize;
- vertices[i].sx = oldSimple[i].sx;
- vertices[i].sy = oldSimple[i].sy;
- vertices[i].ax = oldSimple[i].ax;
- vertices[i].ay = oldSimple[i].ay;
- vertices[i].xx = 1;
- vertices[i].xy = 0;
- vertices[i].yx = 0;
- vertices[i].yy = 1;
- vertices[i].rotation = 0;
- vertices[i].rotationSpeed = 0;
- vertices[i].autoRotate = 0;
- vertices[i].animIdx = 0;
- vertices[i].frameDuration = oldSimple[i].lifeSpan;
- vertices[i].frameCount = 1;
- vertices[i].animT = oldSimple[i].t;
- vertices[i].color.r = 255;
- vertices[i].color.g = 255;
- vertices[i].color.b = 255;
- vertices[i].color.a = 255;
- }
- } else {
- for (int i=0; i<4; ++i) {
- vertices[i].x = 0;
- vertices[i].y = 0;
- vertices[i].t = -1;
- vertices[i].lifeSpan = 0;
- vertices[i].size = 0;
- vertices[i].endSize = 0;
- vertices[i].sx = 0;
- vertices[i].sy = 0;
- vertices[i].ax = 0;
- vertices[i].ay = 0;
- vertices[i].xx = 1;
- vertices[i].xy = 0;
- vertices[i].yx = 0;
- vertices[i].yy = 1;
- vertices[i].rotation = 0;
- vertices[i].rotationSpeed = 0;
- vertices[i].autoRotate = 0;
- vertices[i].animIdx = -1;
- vertices[i].frameDuration = 1;
- vertices[i].frameCount = 0;
- vertices[i].animT = -1;
- vertices[i].color.r = 0;//TODO:Some things never get used uninitialized. Consider dropping them here?
- vertices[i].color.g = 0;
- vertices[i].color.b = 0;
- vertices[i].color.a = 0;
- }
- }
+ reload(p);//reload gets geometry from node
vertices[0].tx = 0;
vertices[0].ty = 0;
@@ -757,10 +693,9 @@ QSGGeometryNode* UltraParticle::buildParticleNode()
vertices[3].ty = 1;
vertices += 4;
- oldSimple += 4;
}
- quint16 *indices = g->indexDataAsUShort();//TODO: Speed gains by copying this over if count unchanged?
+ quint16 *indices = g->indexDataAsUShort();
for (int i=0; i<m_count; ++i) {
int o = i * 4;
indices[0] = o;
@@ -783,11 +718,11 @@ QSGGeometryNode* UltraParticle::buildParticleNode()
QImage opacitytable(m_opacitytable_name.toLocalFile());
m_material = new UltraMaterial();
if(colortable.isNull())
- colortable = QImage(":resources/identitytable.png");
+ colortable = QImage(":defaultshaders/identitytable.png");
if(sizetable.isNull())
- sizetable = QImage(":resources/identitytable.png");
+ sizetable = QImage(":defaultshaders/identitytable.png");
if(opacitytable.isNull())
- opacitytable = QImage(":resources/defaultFadeInOut.png");
+ opacitytable = QImage(":defaultshaders/defaultFadeInOut.png");
Q_ASSERT(!colortable.isNull());
Q_ASSERT(!sizetable.isNull());
Q_ASSERT(!opacitytable.isNull());
@@ -804,8 +739,6 @@ QSGGeometryNode* UltraParticle::buildParticleNode()
m_spriteEngine->setCount(m_count);
}
- m_node = new QSGGeometryNode();
- m_node->setGeometry(g);
m_node->setMaterial(m_material);
m_last_particle = 0;
@@ -813,14 +746,14 @@ QSGGeometryNode* UltraParticle::buildParticleNode()
return m_node;
}
-QSGNode *UltraParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
+QSGNode *QSGImageParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
{
if(m_pleaseReset){
if(m_node){
if(perfLevel == 1){
- qDebug() << "Beta";
- m_lastData = qMalloc(m_count*sizeof(SimpleVertices));//TODO: Account for count_changed possibility
- memcpy(m_lastData, m_node->geometry()->vertexData(), m_count * sizeof(SimpleVertices));//TODO: Multiple levels
+ m_lastCount = m_node->geometry()->vertexCount() / 4;
+ m_lastData = qMalloc(m_lastCount*sizeof(SimpleVertices));
+ memcpy(m_lastData, m_node->geometry()->vertexData(), m_lastCount * sizeof(SimpleVertices));//TODO: Multiple levels
}
m_lastLevel = perfLevel;
delete m_node;
@@ -843,9 +776,9 @@ QSGNode *UltraParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
return m_node;
}
-void UltraParticle::prepareNextFrame()
+void QSGImageParticle::prepareNextFrame()
{
- if (m_node == 0){ //TODO: Staggered loading (as emitted)
+ if (m_node == 0){//TODO: Staggered loading (as emitted)
m_node = buildParticleNode();
if(m_node == 0)
return;
@@ -876,67 +809,14 @@ void UltraParticle::prepareNextFrame()
}
}
-template <typename VT>
-IntermediateVertices* transplant(IntermediateVertices* iv, VT &v)
-{//Deliberate typemangling cast
- iv->v1 = (UltraVertex*)&(v.v1);
- iv->v2 = (UltraVertex*)&(v.v2);
- iv->v3 = (UltraVertex*)&(v.v3);
- iv->v4 = (UltraVertex*)&(v.v4);
- return iv;
-}
-
-IntermediateVertices* UltraParticle::fetchIntermediateVertices(int pos)
+void QSGImageParticle::reloadColor(const Color4ub &c, QSGParticleData* d)
{
- //Note that this class ruins typesafety for you. Maybe even thread safety.
- //TODO: Something better, possibly with templates or inheritance
- static IntermediateVertices iv;
- SimpleVertices *sv;
- UltraVertices *uv;
- switch(perfLevel){
- case Simple:
- sv = (SimpleVertices *) m_node->geometry()->vertexData();
- return transplant(&iv, sv[pos]);
- case Coloured:
- case Deformable:
- case Tabled:
- case Sprites:
- default:
- uv = (UltraVertices *) m_node->geometry()->vertexData();
- return transplant(&iv,uv[pos]);
- }
-}
-
-void UltraParticle::reloadColor(const Color4ub &c, ParticleData* d)
-{
- UltraVertices *particles = (UltraVertices *) m_node->geometry()->vertexData();
- int pos = particleTypeIndex(d);
- UltraVertices &p = particles[pos];
- p.v1.color = p.v2.color = p.v3.color = p.v4.color = c;
-}
-
-void UltraParticle::reload(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- int pos = particleTypeIndex(d);
- IntermediateVertices* p = fetchIntermediateVertices(pos);
-
- //Perhaps we could be more efficient?
- vertexCopy(*p->v1, d->pv);
- vertexCopy(*p->v2, d->pv);
- vertexCopy(*p->v3, d->pv);
- vertexCopy(*p->v4, d->pv);
+ d->color = c;
+ //TODO: get index for reload - or make function take an index
}
-void UltraParticle::load(ParticleData *d)
+void QSGImageParticle::initialize(int idx)
{
- if (m_node == 0)
- return;
-
- int pos = particleTypeIndex(d);
- IntermediateVertices* p = fetchIntermediateVertices(pos);//Remember this removes typesafety!
Color4ub color;
qreal redVariation = m_color_variation + m_redVariation;
qreal greenVariation = m_color_variation + m_greenVariation;
@@ -944,50 +824,111 @@ void UltraParticle::load(ParticleData *d)
switch(perfLevel){//Fall-through is intended on all of them
case Sprites:
// Initial Sprite State
- p->v1->animT = p->v2->animT = p->v3->animT = p->v4->animT = p->v1->t;
- p->v1->animIdx = p->v2->animIdx = p->v3->animIdx = p->v4->animIdx = 0;
+ m_data[idx]->animT = m_data[idx]->t;
+ m_data[idx]->animIdx = 0;
if(m_spriteEngine){
- m_spriteEngine->startSprite(pos);
- p->v1->frameCount = p->v2->frameCount = p->v3->frameCount = p->v4->frameCount = m_spriteEngine->spriteFrames(pos);
- p->v1->frameDuration = p->v2->frameDuration = p->v3->frameDuration = p->v4->frameDuration = m_spriteEngine->spriteDuration(pos);
+ m_spriteEngine->startSprite(idx);
+ m_data[idx]->frameCount = m_spriteEngine->spriteFrames(idx);
+ m_data[idx]->frameDuration = m_spriteEngine->spriteDuration(idx);
}else{
- p->v1->frameCount = p->v2->frameCount = p->v3->frameCount = p->v4->frameCount = 1;
- p->v1->frameDuration = p->v2->frameDuration = p->v3->frameDuration = p->v4->frameDuration = 9999;
+ m_data[idx]->frameCount = 1;
+ m_data[idx]->frameDuration = 9999;
}
case Tabled:
case Deformable:
//Initial Rotation
if(m_xVector){
- const QPointF &ret = m_xVector->sample(QPointF(d->pv.x, d->pv.y));
- p->v1->xx = p->v2->xx = p->v3->xx = p->v4->xx = ret.x();
- p->v1->xy = p->v2->xy = p->v3->xy = p->v4->xy = ret.y();
+ const QPointF &ret = m_xVector->sample(QPointF(m_data[idx]->x, m_data[idx]->y));
+ m_data[idx]->xx = ret.x();
+ m_data[idx]->xy = ret.y();
}
if(m_yVector){
- const QPointF &ret = m_yVector->sample(QPointF(d->pv.x, d->pv.y));
- p->v1->yx = p->v2->yx = p->v3->yx = p->v4->yx = ret.x();
- p->v1->yy = p->v2->yy = p->v3->yy = p->v4->yy = ret.y();
+ const QPointF &ret = m_yVector->sample(QPointF(m_data[idx]->x, m_data[idx]->y));
+ m_data[idx]->yx = ret.x();
+ m_data[idx]->yy = ret.y();
}
- p->v1->rotation = p->v2->rotation = p->v3->rotation = p->v4->rotation =
+ m_data[idx]->rotation =
(m_rotation + (m_rotationVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationVariation) ) * CONV;
- p->v1->rotationSpeed = p->v2->rotationSpeed = p->v3->rotationSpeed = p->v4->rotationSpeed =
+ m_data[idx]->rotationSpeed =
(m_rotationSpeed + (m_rotationSpeedVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationSpeedVariation) ) * CONV;
- p->v1->autoRotate = p->v2->autoRotate = p->v3->autoRotate = p->v4->autoRotate = m_autoRotation?1.0:0.0;
- case Coloured:
+ m_data[idx]->autoRotate = m_autoRotation?1.0:0.0;
+ case Colored:
//Color initialization
// Particle color
color.r = m_color.red() * (1 - redVariation) + rand() % 256 * redVariation;
color.g = m_color.green() * (1 - greenVariation) + rand() % 256 * greenVariation;
color.b = m_color.blue() * (1 - blueVariation) + rand() % 256 * blueVariation;
color.a = m_alpha * m_color.alpha() * (1 - m_alphaVariation) + rand() % 256 * m_alphaVariation;
- p->v1->color = p->v2->color = p->v3->color = p->v4->color = color;
+ m_data[idx]->color = color;
default:
break;
}
+}
+
+void QSGImageParticle::reload(int idx)
+{
+ if(!m_node)
+ return;
+
+ m_node->setFlag(QSGNode::OwnsGeometry, false);
+ UltraVertex *ultraVertices = (UltraVertex *) m_node->geometry()->vertexData();
+ SimpleVertex *simpleVertices = (SimpleVertex *) m_node->geometry()->vertexData();
+ switch(perfLevel){
+ case Sprites:
+ ultraVertices += idx*4;
+ for(int i=0; i<4; i++){
+ ultraVertices[i].x = m_data[idx]->x - m_systemOffset.x();
+ ultraVertices[i].y = m_data[idx]->y - m_systemOffset.y();
+ ultraVertices[i].t = m_data[idx]->t;
+ ultraVertices[i].lifeSpan = m_data[idx]->lifeSpan;
+ ultraVertices[i].size = m_data[idx]->size;
+ ultraVertices[i].endSize = m_data[idx]->endSize;
+ ultraVertices[i].sx = m_data[idx]->sx;
+ ultraVertices[i].sy = m_data[idx]->sy;
+ ultraVertices[i].ax = m_data[idx]->ax;
+ ultraVertices[i].ay = m_data[idx]->ay;
+ ultraVertices[i].xx = m_data[idx]->xx;
+ ultraVertices[i].xy = m_data[idx]->xy;
+ ultraVertices[i].yx = m_data[idx]->yx;
+ ultraVertices[i].yy = m_data[idx]->yy;
+ ultraVertices[i].rotation = m_data[idx]->rotation;
+ ultraVertices[i].rotationSpeed = m_data[idx]->rotationSpeed;
+ ultraVertices[i].autoRotate = m_data[idx]->autoRotate;
+ ultraVertices[i].animIdx = m_data[idx]->animIdx;
+ ultraVertices[i].frameDuration = m_data[idx]->frameDuration;
+ ultraVertices[i].frameCount = m_data[idx]->frameCount;
+ ultraVertices[i].animT = m_data[idx]->animT;
+ ultraVertices[i].color.r = m_data[idx]->color.r;
+ ultraVertices[i].color.g = m_data[idx]->color.g;
+ ultraVertices[i].color.b = m_data[idx]->color.b;
+ ultraVertices[i].color.a = m_data[idx]->color.a;
+ }
+ break;
+ case Tabled://TODO: Us
+ case Deformable:
+ case Colored:
+ case Simple:
+ simpleVertices += idx*4;
+ for(int i=0; i<4; i++){
+ simpleVertices[i].x = m_data[idx]->x - m_systemOffset.x();
+ simpleVertices[i].y = m_data[idx]->y - m_systemOffset.y();
+ simpleVertices[i].t = m_data[idx]->t;
+ simpleVertices[i].lifeSpan = m_data[idx]->lifeSpan;
+ simpleVertices[i].size = m_data[idx]->size;
+ simpleVertices[i].endSize = m_data[idx]->endSize;
+ simpleVertices[i].sx = m_data[idx]->sx;
+ simpleVertices[i].sy = m_data[idx]->sy;
+ simpleVertices[i].ax = m_data[idx]->ax;
+ simpleVertices[i].ay = m_data[idx]->ay;
+ }
+ break;
+ default:
+ break;
+ }
- vertexCopy(*p->v1, d->pv);
- vertexCopy(*p->v2, d->pv);
- vertexCopy(*p->v3, d->pv);
- vertexCopy(*p->v4, d->pv);
+ m_node->setFlag(QSGNode::OwnsGeometry, true);
}
+
+
QT_END_NAMESPACE
diff --git a/src/imports/particles/ultraparticle.h b/src/declarative/particles/qsgimageparticle_p.h
index cb120f9273..dc79c5910e 100644
--- a/src/imports/particles/ultraparticle.h
+++ b/src/declarative/particles/qsgimageparticle_p.h
@@ -41,12 +41,10 @@
#ifndef ULTRAPARTICLE_H
#define ULTRAPARTICLE_H
-#include "particle.h"
-#include "varyingvector.h"
+#include "qsgparticlepainter_p.h"
+#include "qsgstochasticdirection_p.h"
#include <QDeclarativeListProperty>
-#include "coloredparticle.h"
-
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -56,15 +54,8 @@ QT_MODULE(Declarative)
class UltraMaterial;
class QSGGeometryNode;
-class SpriteState;
-class SpriteEngine;
-
-/*struct Color4ub {//in coloredparticle
- uchar r;
- uchar g;
- uchar b;
- uchar a;
-};*/
+class QSGSprite;
+class QSGSpriteEngine;
struct SimpleVertex {
float x;
@@ -129,10 +120,10 @@ struct IntermediateVertices {
UltraVertex* v4;
};
-class UltraParticle : public ParticleType
+class QSGImageParticle : public QSGParticlePainter
{
Q_OBJECT
- Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
+ Q_PROPERTY(QUrl source READ image WRITE setImage NOTIFY imageChanged)
Q_PROPERTY(QUrl colorTable READ colortable WRITE setColortable NOTIFY colortableChanged)
Q_PROPERTY(QUrl sizeTable READ sizetable WRITE setSizetable NOTIFY sizetableChanged)
Q_PROPERTY(QUrl opacityTable READ opacitytable WRITE setOpacitytable NOTIFY opacitytableChanged)
@@ -158,26 +149,23 @@ class UltraParticle : public ParticleType
//###Call i/j? Makes more sense to those with vector calculus experience, and I could even add the cirumflex in QML?
//xVector is the vector from the top-left point to the top-right point, and is multiplied by current size
- Q_PROPERTY(VaryingVector* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged)
+ Q_PROPERTY(QSGStochasticDirection* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged)
//yVector is the same, but top-left to bottom-left. The particle is always a parallelogram.
- Q_PROPERTY(VaryingVector* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged)
- Q_PROPERTY(QDeclarativeListProperty<SpriteState> sprites READ sprites)
+ Q_PROPERTY(QSGStochasticDirection* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged)
+ Q_PROPERTY(QDeclarativeListProperty<QSGSprite> sprites READ sprites)
Q_PROPERTY(bool bloat READ bloat WRITE setBloat NOTIFY bloatChanged)//Just a debugging property to bypass optimizations
public:
- explicit UltraParticle(QSGItem *parent = 0);
- virtual ~UltraParticle(){}
+ explicit QSGImageParticle(QSGItem *parent = 0);
+ virtual ~QSGImageParticle(){}
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
- QDeclarativeListProperty<SpriteState> sprites();
- SpriteEngine* spriteEngine() {return m_spriteEngine;}
+ QDeclarativeListProperty<QSGSprite> sprites();
+ QSGSpriteEngine* spriteEngine() {return m_spriteEngine;}
enum PerformanceLevel{//TODO: Expose?
Unknown = 0,
Simple,
- Coloured,
+ Colored,
Deformable,
Tabled,
Sprites
@@ -223,9 +211,9 @@ public:
bool autoRotation() const { return m_autoRotation; }
- VaryingVector* xVector() const { return m_xVector; }
+ QSGStochasticDirection* xVector() const { return m_xVector; }
- VaryingVector* yVector() const { return m_yVector; }
+ QSGStochasticDirection* yVector() const { return m_yVector; }
bool bloat() const { return m_bloat; }
@@ -260,14 +248,14 @@ signals:
void autoRotationChanged(bool arg);
- void xVectorChanged(VaryingVector* arg);
+ void xVectorChanged(QSGStochasticDirection* arg);
- void yVectorChanged(VaryingVector* arg);
+ void yVectorChanged(QSGStochasticDirection* arg);
void bloatChanged(bool arg);
public slots:
- void reloadColor(const Color4ub &c, ParticleData* d);
+ void reloadColor(const Color4ub &c, QSGParticleData* d);
void setAlphaVariation(qreal arg);
void setAlpha(qreal arg);
@@ -288,15 +276,18 @@ public slots:
void setAutoRotation(bool arg);
- void setXVector(VaryingVector* arg);
+ void setXVector(QSGStochasticDirection* arg);
- void setYVector(VaryingVector* arg);
+ void setYVector(QSGStochasticDirection* arg);
void setBloat(bool arg);
protected:
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
void reset();
+ virtual void initialize(int idx);
+ virtual void reload(int idx);
+
+ QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
void prepareNextFrame();
QSGGeometryNode* buildParticleNode();
QSGGeometryNode* buildSimpleParticleNode();
@@ -305,8 +296,6 @@ private slots:
void createEngine(); //### method invoked by sprite list changing (in engine.h) - pretty nasty
private:
- //void vertexCopy(UltraVertex &b,const ParticleVertex& a);
- IntermediateVertices* fetchIntermediateVertices(int pos);
bool m_do_reset;
QUrl m_image_name;
@@ -336,17 +325,18 @@ private:
qreal m_rotationSpeed;
qreal m_rotationSpeedVariation;
bool m_autoRotation;
- VaryingVector* m_xVector;
- VaryingVector* m_yVector;
+ QSGStochasticDirection* m_xVector;
+ QSGStochasticDirection* m_yVector;
- QList<SpriteState*> m_sprites;
- SpriteEngine* m_spriteEngine;
+ QList<QSGSprite*> m_sprites;
+ QSGSpriteEngine* m_spriteEngine;
bool m_bloat;
PerformanceLevel perfLevel;
PerformanceLevel m_lastLevel;
void* m_lastData;
+ int m_lastCount;
};
QT_END_NAMESPACE
diff --git a/src/imports/particles/itemparticle.cpp b/src/declarative/particles/qsgitemparticle.cpp
index e31309cf21..5e324cd43d 100644
--- a/src/imports/particles/itemparticle.cpp
+++ b/src/declarative/particles/qsgitemparticle.cpp
@@ -39,32 +39,40 @@
**
****************************************************************************/
-#include "itemparticle.h"
+#include "qsgitemparticle_p.h"
#include <QtDeclarative/private/qsgvisualitemmodel_p.h>
#include <qsgnode.h>
+#include <QTimer>
+#include <QDeclarativeComponent>
#include <QDebug>
QT_BEGIN_NAMESPACE
-ItemParticle::ItemParticle(QSGItem *parent) :
- ParticleType(parent), m_fade(true)
+QSGItemParticle::QSGItemParticle(QSGItem *parent) :
+ QSGParticlePainter(parent), m_fade(true), m_delegate(0)
{
setFlag(QSGItem::ItemHasContents);
+ QTimer* manageDelegates = new QTimer(this);//TODO: don't leak
+ connect(manageDelegates, SIGNAL(timeout()),
+ this, SLOT(tick()));
+ manageDelegates->setInterval(16);
+ manageDelegates->setSingleShot(false);
+ manageDelegates->start();
}
-void ItemParticle::freeze(QSGItem* item)
+void QSGItemParticle::freeze(QSGItem* item)
{
m_stasis << item;
}
-void ItemParticle::unfreeze(QSGItem* item)
+void QSGItemParticle::unfreeze(QSGItem* item)
{
m_stasis.remove(item);
}
-void ItemParticle::take(QSGItem *item, bool prioritize)
+void QSGItemParticle::take(QSGItem *item, bool prioritize)
{
if(prioritize)
m_pendingItems.push_front(item);
@@ -72,72 +80,75 @@ void ItemParticle::take(QSGItem *item, bool prioritize)
m_pendingItems.push_back(item);
}
-void ItemParticle::give(QSGItem *item)
+void QSGItemParticle::give(QSGItem *item)
{
//TODO: This
}
-void ItemParticle::load(ParticleData* d)
+void QSGItemParticle::initialize(int idx)
{
- if(m_pendingItems.isEmpty())
- return;
- int pos = particleTypeIndex(d);
- if(m_items[pos]){
- if(m_stasis.contains(m_items[pos]))
- qWarning() << "Current model particles prefers overwrite:false";
- //remove old item from the particle that is dying to make room for this one
- m_items[pos]->setOpacity(0.);
- ItemParticleAttached* mpa;
- if((mpa = qobject_cast<ItemParticleAttached*>(qmlAttachedPropertiesObject<ItemParticle>(m_items[pos], false))))
- mpa->detach();//reparent as well?
- m_items[pos] = 0;
- m_data[pos] = 0;
- m_activeCount--;
- }
- m_items[pos] = m_pendingItems.front();
- m_pendingItems.pop_front();
- m_items[pos]->setX(d->curX() - m_items[pos]->width()/2);
- m_items[pos]->setY(d->curY() - m_items[pos]->height()/2);
- ItemParticleAttached* mpa = qobject_cast<ItemParticleAttached*>(qmlAttachedPropertiesObject<ItemParticle>(m_items[pos]));
- if(mpa){
- mpa->m_mp = this;
- mpa->attach();
- }
- m_items[pos]->setParentItem(this);
- m_data[pos] = d;
- m_activeCount++;
+ m_loadables << idx;//defer to other thread
}
-void ItemParticle::reload(ParticleData* d)
+void QSGItemParticle::reload(int idx)
{
- //No-op unless we start copying the data.
}
-void ItemParticle::setCount(int c)
+void QSGItemParticle::tick()
{
- ParticleType::setCount(c);//###Do we need our own?
- m_particleCount = c;
- reset();
-}
+ foreach(QSGItem* item, m_deletables){
+ if(m_fade)
+ item->setOpacity(0.);
+ QSGItemParticleAttached* mpa;
+ if((mpa = qobject_cast<QSGItemParticleAttached*>(qmlAttachedPropertiesObject<QSGItemParticle>(item))))
+ mpa->detach();//reparent as well?
+ //TODO: Delete iff we created it
+ m_activeCount--;
+ }
+ m_deletables.clear();
-int ItemParticle::count()
-{
- return m_particleCount;
+ foreach(int pos, m_loadables){
+ if(m_stasis.contains(m_data[pos]->delegate))
+ qWarning() << "Current model particles prefers overwrite:false";
+ //remove old item from the particle that is dying to make room for this one
+ if(m_data[pos]->delegate){
+ m_deletables << m_data[pos]->delegate;
+ m_activeCount--;
+ }
+ m_data[pos]->delegate = 0;
+ if(!m_pendingItems.isEmpty()){
+ m_data[pos]->delegate = m_pendingItems.front();
+ m_pendingItems.pop_front();
+ }else if(m_delegate){
+ m_data[pos]->delegate = qobject_cast<QSGItem*>(m_delegate->create(qmlContext(this)));
+ }
+ if(m_data[pos]->delegate && m_data[pos]){//###Data can be zero if creating an item leads to a reset - this screws things up.
+ m_data[pos]->delegate->setX(m_data[pos]->curX() - m_data[pos]->delegate->width()/2);//TODO: adjust for system?
+ m_data[pos]->delegate->setY(m_data[pos]->curY() - m_data[pos]->delegate->height()/2);
+ QSGItemParticleAttached* mpa = qobject_cast<QSGItemParticleAttached*>(qmlAttachedPropertiesObject<QSGItemParticle>(m_data[pos]->delegate));
+ if(mpa){
+ mpa->m_mp = this;
+ mpa->attach();
+ }
+ m_data[pos]->delegate->setParentItem(this);
+ if(m_fade)
+ m_data[pos]->delegate->setOpacity(0.);
+ m_activeCount++;
+ }
+ }
+ m_loadables.clear();
}
-void ItemParticle::reset()
+void QSGItemParticle::reset()
{
- ParticleType::reset();
+ QSGParticlePainter::reset();
//TODO: Cleanup items?
- m_items.resize(m_particleCount);
- m_data.resize(m_particleCount);
- m_items.fill(0);
- m_data.fill(0);
- //m_pendingItems.clear();//TODO: Should this be done? If so, Emit signal?
+ m_loadables.clear();
+ //deletables?
}
-QSGNode* ItemParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d)
+QSGNode* QSGItemParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d)
{
//Dummy update just to get painting tick
if(m_pleaseReset){
@@ -152,7 +163,7 @@ QSGNode* ItemParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d)
return QSGItem::updatePaintNode(n,d);
}
-void ItemParticle::prepareNextFrame()
+void QSGItemParticle::prepareNextFrame()
{
qint64 timeStamp = m_system->systemSync(this);
qreal curT = timeStamp/1000.0;
@@ -162,23 +173,19 @@ void ItemParticle::prepareNextFrame()
return;
//TODO: Size, better fade?
- for(int i=0; i<m_particleCount; i++){
- QSGItem* item = m_items[i];
- ParticleData* data = m_data[i];
- if(!item || !data)
+ for(int i=0; i<count(); i++){
+ QSGParticleData* data = m_data[i];
+ QSGItem* item = data->delegate;
+ if(!item)
continue;
- qreal t = ((timeStamp/1000.0) - data->pv.t) / data->pv.lifeSpan;
+ qreal t = ((timeStamp/1000.0) - data->t) / data->lifeSpan;
if(m_stasis.contains(item)) {
- m_data[i]->pv.t += dt;//Stasis effect
+ m_data[i]->t += dt;//Stasis effect
continue;
}
if(t >= 1.0){//Usually happens from load
- item->setOpacity(0.);
- ItemParticleAttached* mpa;
- if((mpa = qobject_cast<ItemParticleAttached*>(qmlAttachedPropertiesObject<ItemParticle>(m_items[i]))))
- mpa->detach();//reparent as well?
- m_items[i] = 0;
- m_data[i] = 0;
+ m_deletables << item;
+ m_data[i]->delegate = 0;
m_activeCount--;
}else{//Fade
if(m_fade){
@@ -192,14 +199,14 @@ void ItemParticle::prepareNextFrame()
item->setOpacity(1.);//###Without fade, it's just a binary toggle - if we turn it off we have to turn it back on
}
}
- item->setX(data->curX() - item->width()/2);
- item->setY(data->curY() - item->height()/2);
+ item->setX(data->curX() - item->width()/2 - m_systemOffset.x());
+ item->setY(data->curY() - item->height()/2 - m_systemOffset.y());
}
}
-ItemParticleAttached *ItemParticle::qmlAttachedProperties(QObject *object)
+QSGItemParticleAttached *QSGItemParticle::qmlAttachedProperties(QObject *object)
{
- return new ItemParticleAttached(object);
+ return new QSGItemParticleAttached(object);
}
QT_END_NAMESPACE
diff --git a/src/imports/particles/itemparticle.h b/src/declarative/particles/qsgitemparticle_p.h
index 50414c77b6..24bbcf97d8 100644
--- a/src/imports/particles/itemparticle.h
+++ b/src/declarative/particles/qsgitemparticle_p.h
@@ -41,7 +41,7 @@
#ifndef ITEMPARTICLE_H
#define ITEMPARTICLE_H
-#include "particle.h"
+#include "qsgparticlepainter_p.h"
#include <QPointer>
#include <QSet>
QT_BEGIN_HEADER
@@ -50,28 +50,31 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QSGVisualDataModel;
-class ItemParticleAttached;
+class QSGItemParticleAttached;
-class ItemParticle : public ParticleType
+class QSGItemParticle : public QSGParticlePainter
{
Q_OBJECT
-
Q_PROPERTY(bool fade READ fade WRITE setFade NOTIFY fadeChanged)
+ Q_PROPERTY(QDeclarativeComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
public:
- explicit ItemParticle(QSGItem *parent = 0);
+ explicit QSGItemParticle(QSGItem *parent = 0);
bool fade() const { return m_fade; }
virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
- virtual int count();
- static ItemParticleAttached *qmlAttachedProperties(QObject *object);
+ static QSGItemParticleAttached *qmlAttachedProperties(QObject *object);
+ QDeclarativeComponent* delegate() const
+ {
+ return m_delegate;
+ }
+
signals:
void fadeChanged();
+ void delegateChanged(QDeclarativeComponent* arg);
+
public slots:
//TODO: Add a follow mode, where moving the delegate causes the logical particle to go with it?
void freeze(QSGItem* item);
@@ -80,38 +83,48 @@ public slots:
void give(QSGItem* item);//give from modelparticle
void setFade(bool arg){if(arg == m_fade) return; m_fade = arg; emit fadeChanged();}
+ void setDelegate(QDeclarativeComponent* arg)
+ {
+ if (m_delegate != arg) {
+ m_delegate = arg;
+ emit delegateChanged(arg);
+ }
+ }
+
protected:
virtual void reset();
+ virtual void reload(int idx);
+ virtual void initialize(int idx);
void prepareNextFrame();
+private slots:
+ void tick();
private:
- QList<QPointer<QSGItem> > m_deletables;
- int m_particleCount;
+ QList<QSGItem* > m_deletables;
+ QList< int > m_loadables;
bool m_fade;
QList<QSGItem*> m_pendingItems;
- QVector<QSGItem*> m_items;
- QVector<ParticleData*> m_data;
- QVector<int> m_idx;
QList<int> m_available;
QSet<QSGItem*> m_stasis;
qreal m_lastT;
int m_activeCount;
+ QDeclarativeComponent* m_delegate;
};
-class ItemParticleAttached : public QObject
+class QSGItemParticleAttached : public QObject
{
Q_OBJECT
- Q_PROPERTY(ItemParticle* particle READ particle CONSTANT);
+ Q_PROPERTY(QSGItemParticle* particle READ particle CONSTANT);
public:
- ItemParticleAttached(QObject* parent)
+ QSGItemParticleAttached(QObject* parent)
: QObject(parent), m_mp(0)
{;}
- ItemParticle* particle() {return m_mp;}
+ QSGItemParticle* particle() {return m_mp;}
void detach(){emit detached();}
void attach(){emit attached();}
private:
- ItemParticle* m_mp;
- friend class ItemParticle;
+ QSGItemParticle* m_mp;
+ friend class QSGItemParticle;
Q_SIGNALS:
void detached();
void attached();
@@ -119,7 +132,7 @@ Q_SIGNALS:
QT_END_NAMESPACE
-QML_DECLARE_TYPEINFO(ItemParticle, QML_HAS_ATTACHED_PROPERTIES)
+QML_DECLARE_TYPEINFO(QSGItemParticle, QML_HAS_ATTACHED_PROPERTIES)
QT_END_HEADER
#endif // ITEMPARTICLE_H
diff --git a/src/imports/particles/killaffector.cpp b/src/declarative/particles/qsgkill.cpp
index c98a2f44e2..eb3a55d402 100644
--- a/src/imports/particles/killaffector.cpp
+++ b/src/declarative/particles/qsgkill.cpp
@@ -39,20 +39,20 @@
**
****************************************************************************/
-#include "killaffector.h"
-#include "particleemitter.h"
+#include "qsgkill_p.h"
+#include "qsgparticleemitter_p.h"
QT_BEGIN_NAMESPACE
-KillAffector::KillAffector(QSGItem *parent) :
- ParticleAffector(parent)
+QSGKillAffector::QSGKillAffector(QSGItem *parent) :
+ QSGParticleAffector(parent)
{
}
-bool KillAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGKillAffector::affectParticle(QSGParticleData *d, qreal dt)
{
Q_UNUSED(dt);
if(d->stillAlive()){
- d->pv.t -= d->pv.lifeSpan + 1;
+ d->t -= d->lifeSpan + 1;
return true;
}
}
diff --git a/src/imports/particles/killaffector.h b/src/declarative/particles/qsgkill_p.h
index 937ef321a3..1b24b2fb40 100644
--- a/src/imports/particles/killaffector.h
+++ b/src/declarative/particles/qsgkill_p.h
@@ -41,7 +41,7 @@
#ifndef KILLAFFECTOR_H
#define KILLAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
@@ -50,13 +50,13 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class KillAffector : public ParticleAffector
+class QSGKillAffector : public QSGParticleAffector
{
Q_OBJECT
public:
- explicit KillAffector(QSGItem *parent = 0);
+ explicit QSGKillAffector(QSGItem *parent = 0);
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
signals:
public slots:
diff --git a/src/imports/particles/lineextruder.cpp b/src/declarative/particles/qsglineextruder.cpp
index 399bdae046..f32b01402a 100644
--- a/src/imports/particles/lineextruder.cpp
+++ b/src/declarative/particles/qsglineextruder.cpp
@@ -38,15 +38,15 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "lineextruder.h"
+#include "qsglineextruder_p.h"
#include <cmath>
-LineExtruder::LineExtruder(QObject *parent) :
- ParticleExtruder(parent), m_mirrored(false)
+QSGLineExtruder::QSGLineExtruder(QObject *parent) :
+ QSGParticleExtruder(parent), m_mirrored(false)
{
}
-QPointF LineExtruder::extrude(const QRectF &r)
+QPointF QSGLineExtruder::extrude(const QRectF &r)
{
qreal x,y;
if(!r.height()){
diff --git a/src/imports/particles/lineextruder.h b/src/declarative/particles/qsglineextruder_p.h
index 925f1b3361..f356ca332a 100644
--- a/src/imports/particles/lineextruder.h
+++ b/src/declarative/particles/qsglineextruder_p.h
@@ -41,16 +41,16 @@
#ifndef LINEEXTRUDER_H
#define LINEEXTRUDER_H
-#include "particleextruder.h"
+#include "qsgparticleextruder_p.h"
-class LineExtruder : public ParticleExtruder
+class QSGLineExtruder : public QSGParticleExtruder
{
Q_OBJECT
//Default is topleft to bottom right. Flipped makes it topright to bottom left
Q_PROPERTY(bool mirrored READ mirrored WRITE setmirrored NOTIFY mirroredChanged)
public:
- explicit LineExtruder(QObject *parent = 0);
+ explicit QSGLineExtruder(QObject *parent = 0);
virtual QPointF extrude(const QRectF &);
bool mirrored() const
{
diff --git a/src/imports/particles/maskextruder.cpp b/src/declarative/particles/qsgmaskextruder.cpp
index 53dacf4214..d9a463910d 100644
--- a/src/imports/particles/maskextruder.cpp
+++ b/src/declarative/particles/qsgmaskextruder.cpp
@@ -39,45 +39,52 @@
**
****************************************************************************/
-#include "maskextruder.h"
+#include "qsgmaskextruder_p.h"
#include <QImage>
#include <QDebug>
QT_BEGIN_NAMESPACE
-MaskExtruder::MaskExtruder(QObject *parent) :
- ParticleExtruder(parent)
+QSGMaskExtruder::QSGMaskExtruder(QObject *parent) :
+ QSGParticleExtruder(parent)
, m_lastWidth(-1)
, m_lastHeight(-1)
{
}
-QPointF MaskExtruder::extrude(const QRectF &r)
+QPointF QSGMaskExtruder::extrude(const QRectF &r)
{
ensureInitialized(r);
- if(!m_mask.count())
+ if(!m_mask.count() || m_img.isNull())
return r.topLeft();
const QPointF p = m_mask[rand() % m_mask.count()];
//### Should random sub-pixel positioning be added?
return p + r.topLeft();
}
-bool MaskExtruder::contains(const QRectF &bounds, const QPointF &point)
+bool QSGMaskExtruder::contains(const QRectF &bounds, const QPointF &point)
{
ensureInitialized(bounds);//###Current usage patterns WILL lead to different bounds/r calls. Separate list?
+ if(m_img.isNull())
+ return false;
QPoint p = point.toPoint() - bounds.topLeft().toPoint();
return m_img.rect().contains(p) && (bool)m_img.pixelIndex(p);
}
-void MaskExtruder::ensureInitialized(const QRectF &r)
+void QSGMaskExtruder::ensureInitialized(const QRectF &r)
{
if(m_lastWidth == r.width() && m_lastHeight == r.height())
- return;
+ return;//Same as before
m_lastWidth = r.width();
m_lastHeight = r.height();
+ m_img = QImage();
m_mask.clear();
if(m_source.isEmpty())
return;
m_img = QImage(m_source.toLocalFile());
+ if(m_img.isNull()){
+ qWarning() << "MaskShape: Cannot load" << qPrintable(m_source.toLocalFile());
+ return;
+ }
m_img = m_img.createAlphaMask();
m_img = m_img.convertToFormat(QImage::Format_Mono);//Else LSB, but I think that's easier
m_img = m_img.scaled(r.size().toSize());//TODO: Do they need aspect ratio stuff? Or tiling?
diff --git a/src/imports/particles/maskextruder.h b/src/declarative/particles/qsgmaskextruder_p.h
index 6aaa79a0f9..b564efa6dc 100644
--- a/src/imports/particles/maskextruder.h
+++ b/src/declarative/particles/qsgmaskextruder_p.h
@@ -41,7 +41,7 @@
#ifndef MASKEXTRUDER_H
#define MASKEXTRUDER_H
-#include "particleextruder.h"
+#include "qsgparticleextruder_p.h"
#include <QUrl>
#include <QImage>
@@ -51,12 +51,12 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class MaskExtruder : public ParticleExtruder
+class QSGMaskExtruder : public QSGParticleExtruder
{
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
public:
- explicit MaskExtruder(QObject *parent = 0);
+ explicit QSGMaskExtruder(QObject *parent = 0);
virtual QPointF extrude(const QRectF &);
virtual bool contains(const QRectF &bounds, const QPointF &point);
diff --git a/src/imports/particles/dataparticle.cpp b/src/declarative/particles/qsgmodelparticle.cpp
index a2965e8c71..47b8844ad5 100644
--- a/src/imports/particles/dataparticle.cpp
+++ b/src/declarative/particles/qsgmodelparticle.cpp
@@ -39,25 +39,32 @@
**
****************************************************************************/
-#include "dataparticle.h"
+#include "qsgmodelparticle_p.h"
#include <QtDeclarative/private/qsgvisualitemmodel_p.h>
#include <qsgnode.h>
+#include <QTimer>
#include <QDebug>
QT_BEGIN_NAMESPACE
-DataParticle::DataParticle(QSGItem *parent) :
- ParticleType(parent), m_ownModel(false), m_comp(0), m_model(0), m_fade(true), m_modelCount(0)
+QSGModelParticle::QSGModelParticle(QSGItem *parent) :
+ QSGParticlePainter(parent), m_ownModel(false), m_comp(0), m_model(0), m_fade(true), m_modelCount(0)
{
setFlag(QSGItem::ItemHasContents);
+ QTimer* manageDelegates = new QTimer(this);//TODO: don't leak
+ connect(manageDelegates, SIGNAL(timeout()),
+ this, SLOT(processPending()));
+ manageDelegates->setInterval(16);
+ manageDelegates->setSingleShot(false);
+ manageDelegates->start();
}
-QVariant DataParticle::model() const
+QVariant QSGModelParticle::model() const
{
return m_dataSource;
}
-void DataParticle::setModel(const QVariant &arg)
+void QSGModelParticle::setModel(const QVariant &arg)
{
if(arg == m_dataSource)
return;
@@ -84,7 +91,7 @@ void DataParticle::setModel(const QVariant &arg)
updateCount();
}
-void DataParticle::updateCount()
+void QSGModelParticle::updateCount()
{
int newCount = 0;
if(m_model)
@@ -105,14 +112,14 @@ void DataParticle::updateCount()
m_modelCount = newCount;
}
-QDeclarativeComponent *DataParticle::delegate() const
+QDeclarativeComponent *QSGModelParticle::delegate() const
{
if(m_model)
return m_model->delegate();
return 0;
}
-void DataParticle::setDelegate(QDeclarativeComponent *comp)
+void QSGModelParticle::setDelegate(QDeclarativeComponent *comp)
{
if (QSGVisualDataModel *dataModel = qobject_cast<QSGVisualDataModel*>(m_model))
if (comp == dataModel->delegate())
@@ -123,90 +130,86 @@ void DataParticle::setDelegate(QDeclarativeComponent *comp)
emit delegateChanged();
}
-int DataParticle::modelCount() const
+int QSGModelParticle::modelCount() const
{
if(m_model)
- const_cast<DataParticle*>(this)->updateCount();//TODO: Investigate why this doesn't get called properly
+ const_cast<QSGModelParticle*>(this)->updateCount();//TODO: Investigate why this doesn't get called properly
return m_modelCount;
}
-void DataParticle::freeze(QSGItem* item)
+void QSGModelParticle::freeze(QSGItem* item)
{
m_stasis << item;
}
-void DataParticle::unfreeze(QSGItem* item)
+void QSGModelParticle::unfreeze(QSGItem* item)
{
m_stasis.remove(item);
}
-void DataParticle::load(ParticleData* d)
+void QSGModelParticle::initialize(int idx)
{
if(!m_model || !m_model->count())
return;
- int pos = particleTypeIndex(d);
if(m_available.isEmpty())
return;
- if(m_items[pos]){
- if(m_stasis.contains(m_items[pos]))
- qWarning() << "Current model particles prefers overwrite:false";
- //remove old item from the particle that is dying to make room for this one
- m_items[pos]->setOpacity(0.);
- m_available << m_idx[pos];
- m_model->release(m_items[pos]);
- m_idx[pos] = -1;
- m_items[pos] = 0;
- m_data[pos] = 0;
- m_activeCount--;
- }
- m_items[pos] = m_model->item(m_available.first());
- m_idx[pos] = m_available.first();
- m_available.pop_front();
- DataParticleAttached* mpa = qobject_cast<DataParticleAttached*>(qmlAttachedPropertiesObject<DataParticle>(m_items[pos]));
- if(mpa){
- mpa->m_mp = this;
- mpa->attach();
- }
- m_items[pos]->setParentItem(this);
- m_data[pos] = d;
+ m_requests << idx;
m_activeCount++;
}
-void DataParticle::reload(ParticleData* d)
-{
- //No-op unless we start copying the data.
-}
+void QSGModelParticle::processPending()
+{//can't create/delete arbitrary items in the render thread
+ foreach(QSGItem* item, m_deletables){
+ item->setOpacity(0.);
+ m_model->release(item);
+ }
+ m_deletables.clear();
-void DataParticle::setCount(int c)
-{
- ParticleType::setCount(c);//###Do we need our own?
- m_particleCount = c;
- reset();
+ foreach(int pos, m_requests){
+ if(m_data[pos]->delegate){
+ if(m_stasis.contains(m_data[pos]->delegate))
+ qWarning() << "Current model particles prefers overwrite:false";
+ //remove old item from the particle that is dying to make room for this one
+ m_deletables << m_data[pos]->delegate;
+ m_available << m_data[pos]->modelIndex;
+ m_data[pos]->modelIndex = -1;
+ m_data[pos]->delegate = 0;
+ m_data[pos] = 0;
+ m_activeCount--;
+ }
+
+ if(!m_available.isEmpty()){
+ m_data[pos]->delegate = m_model->item(m_available.first());
+ m_data[pos]->modelIndex = m_available.first();
+ m_available.pop_front();
+ QSGModelParticleAttached* mpa = qobject_cast<QSGModelParticleAttached*>(qmlAttachedPropertiesObject<QSGModelParticle>(m_data[pos]->delegate));
+ if(mpa){
+ mpa->m_mp = this;
+ mpa->attach();
+ }
+ m_data[pos]->delegate->setParentItem(this);
+ }
+ }
+ m_requests.clear();
}
-int DataParticle::count()
+void QSGModelParticle::reload(int idx)
{
- return m_particleCount;
+ //No-op unless we start copying the data.
}
-void DataParticle::reset()
+void QSGModelParticle::reset()
{
- ParticleType::reset();
+ QSGParticlePainter::reset();
//TODO: Cleanup items?
- m_items.resize(m_particleCount);
- m_data.resize(m_particleCount);
- m_idx.resize(m_particleCount);
- m_items.fill(0);
- m_data.fill(0);
- m_idx.fill(-1);
//m_available.clear();//Should this be reset too?
//m_pendingItems.clear();//TODO: Should this be done? If so, Emit signal?
}
-QSGNode* DataParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d)
+QSGNode* QSGModelParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d)
{
//Dummy update just to get painting tick
if(m_pleaseReset){
@@ -221,7 +224,7 @@ QSGNode* DataParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d)
return QSGItem::updatePaintNode(n,d);
}
-void DataParticle::prepareNextFrame()
+void QSGModelParticle::prepareNextFrame()
{
qint64 timeStamp = m_system->systemSync(this);
qreal curT = timeStamp/1000.0;
@@ -231,22 +234,20 @@ void DataParticle::prepareNextFrame()
return;
//TODO: Size, better fade?
- for(int i=0; i<m_particleCount; i++){
- QSGItem* item = m_items[i];
- ParticleData* data = m_data[i];
- if(!item || !data)
+ for(int i=0; i<count(); i++){
+ QSGParticleData* data = m_data[i];
+ if(!data->delegate)
continue;
- qreal t = ((timeStamp/1000.0) - data->pv.t) / data->pv.lifeSpan;
- if(m_stasis.contains(item)) {
- m_data[i]->pv.t += dt;//Stasis effect
+ qreal t = ((timeStamp/1000.0) - data->t) / data->lifeSpan;
+ if(m_stasis.contains(m_data[i]->delegate)) {
+ m_data[i]->t += dt;//Stasis effect
continue;
}
if(t >= 1.0){//Usually happens from load
- item->setOpacity(0.);
- m_available << m_idx[i];
- m_model->release(m_items[i]);
- m_idx[i] = -1;
- m_items[i] = 0;
+ m_available << m_data[i]->modelIndex;
+ m_deletables << m_data[i]->delegate;
+ m_data[i]->modelIndex = -1;
+ m_data[i]->delegate = 0;
m_data[i] = 0;
m_activeCount--;
}else{//Fade
@@ -256,19 +257,19 @@ void DataParticle::prepareNextFrame()
o = t*5;
if(t>0.8)
o = (1-t)*5;
- item->setOpacity(o);
+ m_data[i]->delegate->setOpacity(o);
}else{
- item->setOpacity(1.);//###Without fade, it's just a binary toggle - if we turn it off we have to turn it back on
+ m_data[i]->delegate->setOpacity(1.);//###Without fade, it's just a binary toggle - if we turn it off we have to turn it back on
}
}
- item->setX(data->curX() - item->width()/2);
- item->setY(data->curY() - item->height()/2);
+ m_data[i]->delegate->setX(data->curX() - m_data[i]->delegate->width()/2 - m_systemOffset.x());
+ m_data[i]->delegate->setY(data->curY() - m_data[i]->delegate->height()/2 - m_systemOffset.y());
}
}
-DataParticleAttached *DataParticle::qmlAttachedProperties(QObject *object)
+QSGModelParticleAttached *QSGModelParticle::qmlAttachedProperties(QObject *object)
{
- return new DataParticleAttached(object);
+ return new QSGModelParticleAttached(object);
}
QT_END_NAMESPACE
diff --git a/src/imports/particles/dataparticle.h b/src/declarative/particles/qsgmodelparticle_p.h
index 84422e70c3..31e4025bb4 100644
--- a/src/imports/particles/dataparticle.h
+++ b/src/declarative/particles/qsgmodelparticle_p.h
@@ -41,7 +41,7 @@
#ifndef DATAPARTICLE_H
#define DATAPARTICLE_H
-#include "particle.h"
+#include "qsgparticlepainter_p.h"
#include <QPointer>
#include <QSet>
QT_BEGIN_HEADER
@@ -50,9 +50,9 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QSGVisualDataModel;
-class DataParticleAttached;
+class QSGModelParticleAttached;
-class DataParticle : public ParticleType
+class QSGModelParticle : public QSGParticlePainter
{
Q_OBJECT
@@ -62,7 +62,7 @@ class DataParticle : public ParticleType
Q_PROPERTY(bool fade READ fade WRITE setFade NOTIFY fadeChanged)
Q_CLASSINFO("DefaultProperty", "delegate")
public:
- explicit DataParticle(QSGItem *parent = 0);
+ explicit QSGModelParticle(QSGItem *parent = 0);
QVariant model() const;
void setModel(const QVariant &);
@@ -74,12 +74,8 @@ public:
bool fade() const { return m_fade; }
virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
- virtual int count();
- static DataParticleAttached *qmlAttachedProperties(QObject *object);
+ static QSGModelParticleAttached *qmlAttachedProperties(QObject *object);
signals:
void modelChanged();
void delegateChanged();
@@ -93,22 +89,22 @@ public slots:
void setFade(bool arg){if(arg == m_fade) return; m_fade = arg; emit fadeChanged();}
protected:
virtual void reset();
+ virtual void reload(int idx);
+ virtual void initialize(int idx);
void prepareNextFrame();
private slots:
void updateCount();
+ void processPending();
private:
bool m_ownModel;
QDeclarativeComponent* m_comp;
QSGVisualDataModel *m_model;
QVariant m_dataSource;
- QList<QPointer<QSGItem> > m_deletables;
- int m_particleCount;
+ QList<QSGItem*> m_deletables;
+ QList< int > m_requests;
bool m_fade;
QList<QSGItem*> m_pendingItems;
- QVector<QSGItem*> m_items;
- QVector<ParticleData*> m_data;
- QVector<int> m_idx;
QList<int> m_available;
QSet<QSGItem*> m_stasis;
qreal m_lastT;
@@ -116,20 +112,20 @@ private:
int m_modelCount;
};
-class DataParticleAttached : public QObject
+class QSGModelParticleAttached : public QObject
{
Q_OBJECT
- Q_PROPERTY(DataParticle* particle READ particle CONSTANT);
+ Q_PROPERTY(QSGModelParticle* particle READ particle CONSTANT);
public:
- DataParticleAttached(QObject* parent)
+ QSGModelParticleAttached(QObject* parent)
: QObject(parent), m_mp(0)
{;}
- DataParticle* particle() {return m_mp;}
+ QSGModelParticle* particle() {return m_mp;}
void detach(){emit detached();}
void attach(){emit attached();}
private:
- DataParticle* m_mp;
- friend class DataParticle;
+ QSGModelParticle* m_mp;
+ friend class QSGModelParticle;
Q_SIGNALS:
void detached();
void attached();
@@ -137,7 +133,7 @@ Q_SIGNALS:
QT_END_NAMESPACE
-QML_DECLARE_TYPEINFO(DataParticle, QML_HAS_ATTACHED_PROPERTIES)
+QML_DECLARE_TYPEINFO(QSGModelParticle, QML_HAS_ATTACHED_PROPERTIES)
QT_END_HEADER
#endif // DATAPARTICLE_H
diff --git a/src/imports/particles/particleaffector.cpp b/src/declarative/particles/qsgparticleaffector.cpp
index 73564a940a..5b0936cc40 100644
--- a/src/imports/particles/particleaffector.cpp
+++ b/src/declarative/particles/qsgparticleaffector.cpp
@@ -39,14 +39,14 @@
**
****************************************************************************/
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
#include <QDebug>
QT_BEGIN_NAMESPACE
-ParticleAffector::ParticleAffector(QSGItem *parent) :
+QSGParticleAffector::QSGParticleAffector(QSGItem *parent) :
QSGItem(parent), m_needsReset(false), m_system(0), m_active(true)
- , m_updateIntSet(false), m_shape(new ParticleExtruder(this)), m_signal(false)
+ , m_updateIntSet(false), m_shape(new QSGParticleExtruder(this)), m_signal(false)
{
- connect(this, SIGNAL(systemChanged(ParticleSystem*)),
+ connect(this, SIGNAL(systemChanged(QSGParticleSystem*)),
this, SLOT(updateOffsets()));
connect(this, SIGNAL(xChanged()),
this, SLOT(updateOffsets()));
@@ -54,14 +54,16 @@ ParticleAffector::ParticleAffector(QSGItem *parent) :
this, SLOT(updateOffsets()));//TODO: in componentComplete and all relevant signals
}
-void ParticleAffector::componentComplete()
+void QSGParticleAffector::componentComplete()
{
+ if(!m_system && qobject_cast<QSGParticleSystem*>(parentItem()))
+ setSystem(qobject_cast<QSGParticleSystem*>(parentItem()));
if(!m_system)
qWarning() << "Affector created without a particle system specified";//TODO: useful QML warnings, like line number?
QSGItem::componentComplete();
}
-void ParticleAffector::affectSystem(qreal dt)
+void QSGParticleAffector::affectSystem(qreal dt)
{
if(!m_active)
return;
@@ -77,42 +79,42 @@ void ParticleAffector::affectSystem(qreal dt)
m_groups << m_system->m_groupIds[p];//###Can this occur before group ids are properly assigned?
m_updateIntSet = false;
}
- //foreach(ParticleData* d, m_system->m_data){
- for(int i=0; i<m_system->m_particle_count; i++){
- ParticleData* d = m_system->m_data[i];
- if(!d || (m_onceOff && m_onceOffed.contains(d->systemIndex)))
- continue;
- if(m_groups.isEmpty() || m_groups.contains(d->group)){
- //Need to have previous location for affected. if signal || shape might be faster?
- QPointF curPos = QPointF(d->curX(), d->curY());
- if(width() == 0 || height() == 0
- || m_shape->contains(QRectF(m_offset.x(), m_offset.y(), width(), height()),curPos)){
- if(affectParticle(d, dt)){
- m_system->m_needsReset << d;
- if(m_onceOff)
- m_onceOffed << d->systemIndex;
- if(m_signal)
- emit affected(curPos.x(), curPos.y());
+ foreach(QSGParticleGroupData* gd, m_system->m_groupData){
+ foreach(QSGParticleData* d, gd->data){
+ if(!d || (m_onceOff && m_onceOffed.contains(qMakePair(d->group, d->index))))
+ continue;
+ if(m_groups.isEmpty() || m_groups.contains(d->group)){
+ //Need to have previous location for affected. if signal || shape might be faster?
+ QPointF curPos = QPointF(d->curX(), d->curY());
+ if(width() == 0 || height() == 0
+ || m_shape->contains(QRectF(m_offset.x(), m_offset.y(), width(), height()),curPos)){
+ if(affectParticle(d, dt)){
+ m_system->m_needsReset << d;
+ if(m_onceOff)
+ m_onceOffed << qMakePair(d->group, d->index);
+ if(m_signal)
+ emit affected(curPos.x(), curPos.y());
+ }
}
}
}
}
}
-bool ParticleAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGParticleAffector::affectParticle(QSGParticleData *d, qreal dt)
{
Q_UNUSED(d);
Q_UNUSED(dt);
return false;
}
-void ParticleAffector::reset(int idx)
+void QSGParticleAffector::reset(QSGParticleData* pd)
{//TODO: This, among other ones, should be restructured so they don't all need to remember to call the superclass
if(m_onceOff)
- m_onceOffed.remove(idx);
+ m_onceOffed.remove(qMakePair(pd->group, pd->index));
}
-void ParticleAffector::updateOffsets()
+void QSGParticleAffector::updateOffsets()
{
if(m_system)
m_offset = m_system->mapFromItem(this, QPointF(0, 0));
diff --git a/src/imports/particles/particleaffector.h b/src/declarative/particles/qsgparticleaffector_p.h
index 3a92263092..7418760941 100644
--- a/src/imports/particles/particleaffector.h
+++ b/src/declarative/particles/qsgparticleaffector_p.h
@@ -43,8 +43,8 @@
#define PARTICLEAFFECTOR_H
#include <QObject>
-#include "particlesystem.h"
-#include "particleextruder.h"
+#include "qsgparticlesystem_p.h"
+#include "qsgparticleextruder_p.h"
QT_BEGIN_HEADER
@@ -52,22 +52,21 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-
-class ParticleAffector : public QSGItem
+class QSGParticleAffector : public QSGItem
{
Q_OBJECT
- Q_PROPERTY(ParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
+ Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
Q_PROPERTY(QStringList particles READ particles WRITE setParticles NOTIFY particlesChanged)
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
Q_PROPERTY(bool onceOff READ onceOff WRITE setOnceOff NOTIFY onceOffChanged)
- Q_PROPERTY(ParticleExtruder* shape READ shape WRITE setShape NOTIFY shapeChanged)
+ Q_PROPERTY(QSGParticleExtruder* shape READ shape WRITE setShape NOTIFY shapeChanged)
Q_PROPERTY(bool signal READ signal WRITE setSignal NOTIFY signalChanged)
public:
- explicit ParticleAffector(QSGItem *parent = 0);
+ explicit QSGParticleAffector(QSGItem *parent = 0);
virtual void affectSystem(qreal dt);
- virtual void reset(int systemIdx);//As some store their own data per idx?
- ParticleSystem* system() const
+ virtual void reset(QSGParticleData*);//As some store their own data per particle?
+ QSGParticleSystem* system() const
{
return m_system;
}
@@ -87,7 +86,7 @@ public:
return m_onceOff;
}
- ParticleExtruder* shape() const
+ QSGParticleExtruder* shape() const
{
return m_shape;
}
@@ -99,7 +98,7 @@ public:
signals:
- void systemChanged(ParticleSystem* arg);
+ void systemChanged(QSGParticleSystem* arg);
void particlesChanged(QStringList arg);
@@ -107,13 +106,13 @@ signals:
void onceOffChanged(bool arg);
- void shapeChanged(ParticleExtruder* arg);
+ void shapeChanged(QSGParticleExtruder* arg);
- void affected(qreal x, qreal y);//###Idx too?
+ void affected(qreal x, qreal y);
void signalChanged(bool arg);
public slots:
-void setSystem(ParticleSystem* arg)
+void setSystem(QSGParticleSystem* arg)
{
if (m_system != arg) {
m_system = arg;
@@ -147,7 +146,7 @@ void setOnceOff(bool arg)
}
}
-void setShape(ParticleExtruder* arg)
+void setShape(QSGParticleExtruder* arg)
{
if (m_shape != arg) {
m_shape = arg;
@@ -164,10 +163,10 @@ void setSignal(bool arg)
}
protected:
- friend class ParticleSystem;
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ friend class QSGParticleSystem;
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
bool m_needsReset;//### What is this really saving?
- ParticleSystem* m_system;
+ QSGParticleSystem* m_system;
QStringList m_particles;
bool activeGroup(int g) {return m_groups.isEmpty() || m_groups.contains(g);}
bool m_active;
@@ -175,12 +174,12 @@ protected:
QPointF m_offset;
private:
QSet<int> m_groups;
- QSet<int> m_onceOffed;
+ QSet<QPair<int, int> > m_onceOffed;
bool m_updateIntSet;
bool m_onceOff;
- ParticleExtruder* m_shape;
+ QSGParticleExtruder* m_shape;
bool m_signal;
diff --git a/src/imports/particles/particleemitter.cpp b/src/declarative/particles/qsgparticleemitter.cpp
index dd7d73749b..143338f798 100644
--- a/src/imports/particles/particleemitter.cpp
+++ b/src/declarative/particles/qsgparticleemitter.cpp
@@ -39,9 +39,9 @@
**
****************************************************************************/
-#include "particleemitter.h"
+#include "qsgparticleemitter_p.h"
QT_BEGIN_NAMESPACE
-ParticleEmitter::ParticleEmitter(QSGItem *parent) :
+QSGParticleEmitter::QSGParticleEmitter(QSGItem *parent) :
QSGItem(parent)
, m_particlesPerSecond(10)
, m_particleDuration(1000)
@@ -68,25 +68,27 @@ ParticleEmitter::ParticleEmitter(QSGItem *parent) :
this, SIGNAL(particleCountChanged()));
}
-ParticleEmitter::~ParticleEmitter()
+QSGParticleEmitter::~QSGParticleEmitter()
{
if(m_defaultExtruder)
delete m_defaultExtruder;
}
-void ParticleEmitter::componentComplete()
+void QSGParticleEmitter::componentComplete()
{
+ if(!m_system && qobject_cast<QSGParticleSystem*>(parentItem()))
+ setSystem(qobject_cast<QSGParticleSystem*>(parentItem()));
if(!m_system)
qWarning() << "Emitter created without a particle system specified";//TODO: useful QML warnings, like line number?
QSGItem::componentComplete();
}
-void ParticleEmitter::emitWindow(int timeStamp)
+void QSGParticleEmitter::emitWindow(int timeStamp)
{
Q_UNUSED(timeStamp);
}
-void ParticleEmitter::setEmitting(bool arg)
+void QSGParticleEmitter::setEmitting(bool arg)
{
if (m_emitting != arg) {
m_emitting = arg;
@@ -95,16 +97,16 @@ void ParticleEmitter::setEmitting(bool arg)
}
-ParticleExtruder* ParticleEmitter::effectiveExtruder()
+QSGParticleExtruder* QSGParticleEmitter::effectiveExtruder()
{
if(m_extruder)
return m_extruder;
if(!m_defaultExtruder)
- m_defaultExtruder = new ParticleExtruder;
+ m_defaultExtruder = new QSGParticleExtruder;
return m_defaultExtruder;
}
-void ParticleEmitter::pulse(qreal seconds)
+void QSGParticleEmitter::pulse(qreal seconds)
{
if(!particleCount())
qWarning() << "pulse called on an emitter with a particle count of zero";
@@ -112,14 +114,21 @@ void ParticleEmitter::pulse(qreal seconds)
m_burstLeft = seconds*1000.0;//TODO: Change name to match
}
-void ParticleEmitter::burst(int num)
+void QSGParticleEmitter::burst(int num)
{
if(!particleCount())
qWarning() << "burst called on an emitter with a particle count of zero";
m_burstQueue << qMakePair(num, QPointF(x(), y()));
}
-void ParticleEmitter::setMaxParticleCount(int arg)
+void QSGParticleEmitter::burst(int num, qreal x, qreal y)
+{
+ if(!particleCount())
+ qWarning() << "burst called on an emitter with a particle count of zero";
+ m_burstQueue << qMakePair(num, QPointF(x, y));
+}
+
+void QSGParticleEmitter::setMaxParticleCount(int arg)
{
if (m_maxParticleCount != arg) {
if(arg < 0 && m_maxParticleCount >= 0){
@@ -138,7 +147,7 @@ void ParticleEmitter::setMaxParticleCount(int arg)
}
}
-int ParticleEmitter::particleCount() const
+int QSGParticleEmitter::particleCount() const
{
if(m_maxParticleCount >= 0)
return m_maxParticleCount;
diff --git a/src/imports/particles/particleemitter.h b/src/declarative/particles/qsgparticleemitter_p.h
index e272ae51ab..65aca0c83e 100644
--- a/src/imports/particles/particleemitter.h
+++ b/src/declarative/particles/qsgparticleemitter_p.h
@@ -44,9 +44,9 @@
#include <QSGItem>
#include <QDebug>
-#include "particlesystem.h"
-#include "particleextruder.h"
-#include "varyingvector.h"
+#include "qsgparticlesystem_p.h"
+#include "qsgparticleextruder_p.h"
+#include "qsgstochasticdirection_p.h"
#include <QList>
#include <QPair>
@@ -57,29 +57,29 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class ParticleEmitter : public QSGItem
+class QSGParticleEmitter : public QSGItem
{
Q_OBJECT
//###currently goes in emitters OR sets system. Pick one?
- Q_PROPERTY(ParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
+ Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
Q_PROPERTY(QString particle READ particle WRITE setParticle NOTIFY particleChanged)
- Q_PROPERTY(ParticleExtruder* shape READ extruder WRITE setExtruder NOTIFY extruderChanged)
+ Q_PROPERTY(QSGParticleExtruder* shape READ extruder WRITE setExtruder NOTIFY extruderChanged)
Q_PROPERTY(bool emitting READ emitting WRITE setEmitting NOTIFY emittingChanged)
- Q_PROPERTY(qreal particlesPerSecond READ particlesPerSecond WRITE setParticlesPerSecond NOTIFY particlesPerSecondChanged)
- Q_PROPERTY(int particleDuration READ particleDuration WRITE setParticleDuration NOTIFY particleDurationChanged)
- Q_PROPERTY(int particleDurationVariation READ particleDurationVariation WRITE setParticleDurationVariation NOTIFY particleDurationVariationChanged)
- Q_PROPERTY(int maxParticles READ maxParticleCount WRITE setMaxParticleCount NOTIFY maxParticleCountChanged)
+ Q_PROPERTY(qreal emitRate READ particlesPerSecond WRITE setParticlesPerSecond NOTIFY particlesPerSecondChanged)
+ Q_PROPERTY(int lifeSpan READ particleDuration WRITE setParticleDuration NOTIFY particleDurationChanged)
+ Q_PROPERTY(int lifeSpanVariation READ particleDurationVariation WRITE setParticleDurationVariation NOTIFY particleDurationVariationChanged)
+ Q_PROPERTY(int emitCap READ maxParticleCount WRITE setMaxParticleCount NOTIFY maxParticleCountChanged)
- Q_PROPERTY(qreal particleSize READ particleSize WRITE setParticleSize NOTIFY particleSizeChanged)
- Q_PROPERTY(qreal particleEndSize READ particleEndSize WRITE setParticleEndSize NOTIFY particleEndSizeChanged)
- Q_PROPERTY(qreal particleSizeVariation READ particleSizeVariation WRITE setParticleSizeVariation NOTIFY particleSizeVariationChanged)
+ Q_PROPERTY(qreal size READ particleSize WRITE setParticleSize NOTIFY particleSizeChanged)
+ Q_PROPERTY(qreal endSize READ particleEndSize WRITE setParticleEndSize NOTIFY particleEndSizeChanged)
+ Q_PROPERTY(qreal sizeVariation READ particleSizeVariation WRITE setParticleSizeVariation NOTIFY particleSizeVariationChanged)
- Q_PROPERTY(VaryingVector *speed READ speed WRITE setSpeed NOTIFY speedChanged)
- Q_PROPERTY(VaryingVector *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
+ Q_PROPERTY(QSGStochasticDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged)
+ Q_PROPERTY(QSGStochasticDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
public:
- explicit ParticleEmitter(QSGItem *parent = 0);
- virtual ~ParticleEmitter();
+ explicit QSGParticleEmitter(QSGItem *parent = 0);
+ virtual ~QSGParticleEmitter();
virtual void emitWindow(int timeStamp);
bool emitting() const
@@ -97,7 +97,7 @@ public:
return m_particleDuration;
}
- ParticleSystem* system() const
+ QSGParticleSystem* system() const
{
return m_system;
}
@@ -118,13 +118,13 @@ signals:
void particleDurationChanged(int);
void emittingChanged(bool);
- void systemChanged(ParticleSystem* arg);
+ void systemChanged(QSGParticleSystem* arg);
void particleChanged(QString arg);
void particleDurationVariationChanged(int arg);
- void extruderChanged(ParticleExtruder* arg);
+ void extruderChanged(QSGParticleExtruder* arg);
void particleSizeChanged(qreal arg);
@@ -132,9 +132,9 @@ signals:
void particleSizeVariationChanged(qreal arg);
- void speedChanged(VaryingVector * arg);
+ void speedChanged(QSGStochasticDirection * arg);
- void accelerationChanged(VaryingVector * arg);
+ void accelerationChanged(QSGStochasticDirection * arg);
void maxParticleCountChanged(int arg);
void particleCountChanged();
@@ -142,6 +142,7 @@ signals:
public slots:
void pulse(qreal seconds);
void burst(int num);
+ void burst(int num, qreal x, qreal y);
void setEmitting(bool arg);
@@ -161,7 +162,7 @@ public slots:
}
}
- void setSystem(ParticleSystem* arg)
+ void setSystem(QSGParticleSystem* arg)
{
if (m_system != arg) {
m_system = arg;
@@ -185,7 +186,7 @@ public slots:
emit particleDurationVariationChanged(arg);
}
}
- void setExtruder(ParticleExtruder* arg)
+ void setExtruder(QSGParticleExtruder* arg)
{
if (m_extruder != arg) {
m_extruder = arg;
@@ -217,7 +218,7 @@ public slots:
}
}
- void setSpeed(VaryingVector * arg)
+ void setSpeed(QSGStochasticDirection * arg)
{
if (m_speed != arg) {
m_speed = arg;
@@ -225,7 +226,7 @@ public slots:
}
}
- void setAcceleration(VaryingVector * arg)
+ void setAcceleration(QSGStochasticDirection * arg)
{
if (m_acceleration != arg) {
m_acceleration = arg;
@@ -239,7 +240,7 @@ public:
int particleCount() const;
virtual void reset(){;}
- ParticleExtruder* extruder() const
+ QSGParticleExtruder* extruder() const
{
return m_extruder;
}
@@ -259,12 +260,12 @@ public:
return m_particleSizeVariation;
}
- VaryingVector * speed() const
+ QSGStochasticDirection * speed() const
{
return m_speed;
}
- VaryingVector * acceleration() const
+ QSGStochasticDirection * acceleration() const
{
return m_acceleration;
}
@@ -279,13 +280,13 @@ protected:
int m_particleDuration;
int m_particleDurationVariation;
bool m_emitting;
- ParticleSystem* m_system;
+ QSGParticleSystem* m_system;
QString m_particle;
- ParticleExtruder* m_extruder;
- ParticleExtruder* m_defaultExtruder;
- ParticleExtruder* effectiveExtruder();
- VaryingVector * m_speed;
- VaryingVector * m_acceleration;
+ QSGParticleExtruder* m_extruder;
+ QSGParticleExtruder* m_defaultExtruder;
+ QSGParticleExtruder* effectiveExtruder();
+ QSGStochasticDirection * m_speed;
+ QSGStochasticDirection * m_acceleration;
qreal m_particleSize;
qreal m_particleEndSize;
qreal m_particleSizeVariation;
@@ -294,7 +295,7 @@ protected:
QList<QPair<int, QPointF > > m_burstQueue;
int m_maxParticleCount;
private:
- VaryingVector m_nullVector;
+ QSGStochasticDirection m_nullVector;
};
QT_END_NAMESPACE
diff --git a/src/imports/particles/particleextruder.cpp b/src/declarative/particles/qsgparticleextruder.cpp
index 3ff5abf996..91b968c8af 100644
--- a/src/imports/particles/particleextruder.cpp
+++ b/src/declarative/particles/qsgparticleextruder.cpp
@@ -39,16 +39,16 @@
**
****************************************************************************/
-#include "particleextruder.h"
+#include "qsgparticleextruder_p.h"
QT_BEGIN_NAMESPACE
-ParticleExtruder::ParticleExtruder(QObject *parent) :
+QSGParticleExtruder::QSGParticleExtruder(QObject *parent) :
QObject(parent), m_fill(true)
{
}
-QPointF ParticleExtruder::extrude(const QRectF &rect)
+QPointF QSGParticleExtruder::extrude(const QRectF &rect)
{
if(m_fill)
return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(),
@@ -70,7 +70,7 @@ QPointF ParticleExtruder::extrude(const QRectF &rect)
}
}
-bool ParticleExtruder::contains(const QRectF &bounds, const QPointF &point)
+bool QSGParticleExtruder::contains(const QRectF &bounds, const QPointF &point)
{
return bounds.contains(point);
}
diff --git a/src/imports/particles/particleextruder.h b/src/declarative/particles/qsgparticleextruder_p.h
index 2c417d3f92..41e27eb2fa 100644
--- a/src/imports/particles/particleextruder.h
+++ b/src/declarative/particles/qsgparticleextruder_p.h
@@ -52,13 +52,13 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class ParticleExtruder : public QObject
+class QSGParticleExtruder : public QObject
{
Q_OBJECT
Q_PROPERTY(bool fill READ fill WRITE setFill NOTIFY fillChanged)//###Should this be base class, or a BoxExtruder?
public:
- explicit ParticleExtruder(QObject *parent = 0);
+ explicit QSGParticleExtruder(QObject *parent = 0);
virtual QPointF extrude(const QRectF &);
virtual bool contains(const QRectF &bounds, const QPointF &point);//###Needed for follow emitter, but does it belong? Only marginally conceptually valid, and that's from user's perspective
bool fill() const
diff --git a/src/declarative/particles/qsgparticlepainter.cpp b/src/declarative/particles/qsgparticlepainter.cpp
new file mode 100644
index 0000000000..cf1d3c2894
--- /dev/null
+++ b/src/declarative/particles/qsgparticlepainter.cpp
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** 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 Declarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgparticlepainter_p.h"
+#include <QDebug>
+QT_BEGIN_NAMESPACE
+QSGParticlePainter::QSGParticlePainter(QSGItem *parent) :
+ QSGItem(parent),
+ m_system(0), m_count(0), m_lastStart(0), m_sentinel(new QSGParticleData)
+{
+ connect(this, SIGNAL(xChanged()),
+ this, SLOT(calcSystemOffset()));
+ connect(this, SIGNAL(yChanged()),
+ this, SLOT(calcSystemOffset()));
+}
+
+void QSGParticlePainter::componentComplete()
+{
+ if(!m_system && qobject_cast<QSGParticleSystem*>(parentItem()))
+ setSystem(qobject_cast<QSGParticleSystem*>(parentItem()));
+ if(!m_system)
+ qWarning() << "ParticlePainter created without a particle system specified";//TODO: useful QML warnings, like line number?
+ QSGItem::componentComplete();
+}
+
+
+void QSGParticlePainter::setSystem(QSGParticleSystem *arg)
+{
+ if (m_system != arg) {
+ m_system = arg;
+ if(m_system){
+ m_system->registerParticlePainter(this);
+ connect(m_system, SIGNAL(xChanged()),
+ this, SLOT(calcSystemOffset()));
+ connect(m_system, SIGNAL(yChanged()),
+ this, SLOT(calcSystemOffset()));
+ calcSystemOffset();
+ }
+ emit systemChanged(arg);
+ }
+}
+
+void QSGParticlePainter::load(QSGParticleData* d)
+{
+ int idx = particleTypeIndex(d);
+ m_data[idx] = d;
+ initialize(idx);
+ reload(idx);
+}
+
+void QSGParticlePainter::reload(QSGParticleData* d)
+{
+ reload(particleTypeIndex(d));
+}
+
+void QSGParticlePainter::reset()
+{
+ //Have to every time because what it's emitting may have changed and that affects particleTypeIndex
+ if(m_system && !m_inResize)
+ resize(0,1);//###Fix this by making resize take sensible arguments
+ //###This also means double resets. Make reset not virtual?
+}
+
+void QSGParticlePainter::resize(int oldSize, int newSize)
+{
+ if(newSize == oldSize)//TODO: What if particles switched so indices change but total count is the same?
+ return;
+
+ QHash<int, QPair<int, int> > oldStarts(m_particleStarts);
+ //Update particle starts datastore
+ m_particleStarts.clear();
+ m_lastStart = 0;
+ QList<int> particleList;
+ if(m_particles.isEmpty())
+ particleList << 0;
+ foreach(const QString &s, m_particles)
+ particleList << m_system->m_groupIds[s];
+ foreach(int gIdx, particleList){
+ QSGParticleGroupData *gd = m_system->m_groupData[gIdx];
+ m_particleStarts.insert(gIdx, qMakePair<int, int>(gd->size, m_lastStart));
+ m_lastStart += gd->size;
+ }
+
+ //Shuffle stuff around
+ //TODO: In place shuffling because it's faster
+ QVector<QSGParticleData*> oldData(m_data);
+ QVector<QObject*> oldAttached(m_attachedData);
+ m_data.clear();
+ m_data.resize(m_count);
+ m_attachedData.resize(m_count);
+ foreach(int gIdx, particleList){
+ QSGParticleGroupData *gd = m_system->m_groupData[gIdx];
+ for(int i=0; i<gd->data.size(); i++){//TODO: When group didn't exist before
+ int newIdx = m_particleStarts[gIdx].second + i;
+ int oldIdx = oldStarts[gIdx].second + i;
+ if(i >= oldStarts[gIdx].first || oldData.size() <= oldIdx){
+ m_data[newIdx] = m_sentinel;
+ }else{
+ m_data[newIdx] = oldData[oldIdx];
+ m_attachedData[newIdx] = oldAttached[oldIdx];
+ }
+ }
+ }
+ m_inResize = true;
+ reset();
+ m_inResize = false;
+}
+
+
+void QSGParticlePainter::setCount(int c)
+{
+ Q_ASSERT(c >= 0); //XXX
+ if(c == m_count)
+ return;
+ int lastCount = m_count;
+ m_count = c;
+ resize(lastCount, m_count);
+ emit countChanged();
+}
+
+int QSGParticlePainter::count()
+{
+ return m_count;
+}
+
+int QSGParticlePainter::particleTypeIndex(QSGParticleData* d)
+{
+ Q_ASSERT(d && m_particleStarts.contains(d->group));//XXX
+ int ret = m_particleStarts[d->group].second + d->index;
+ Q_ASSERT(ret >=0 && ret < m_count);//XXX:shouldn't assert, but bugs here were hard to find in the past
+ return ret;
+}
+
+
+void QSGParticlePainter::calcSystemOffset()
+{
+ if(!m_system)
+ return;
+ QPointF lastOffset = m_systemOffset;
+ m_systemOffset = -1 * this->mapFromItem(m_system, QPointF());
+ if(lastOffset != m_systemOffset){
+ //Reload all particles//TODO: Necessary?
+ foreach(const QString &g, m_particles){
+ int gId = m_system->m_groupIds[g];
+ foreach(QSGParticleData* d, m_system->m_groupData[gId]->data)
+ reload(d);
+ }
+ }
+}
+QT_END_NAMESPACE
diff --git a/src/imports/particles/particle.h b/src/declarative/particles/qsgparticlepainter_p.h
index fbb9665a64..e506018f53 100644
--- a/src/imports/particles/particle.h
+++ b/src/declarative/particles/qsgparticlepainter_p.h
@@ -44,7 +44,7 @@
#include <QObject>
#include <QDebug>
-#include "particlesystem.h"
+#include "qsgparticlesystem_p.h"
QT_BEGIN_HEADER
@@ -53,19 +53,20 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class ParticleType : public QSGItem
+class QSGParticlePainter : public QSGItem
{
Q_OBJECT
- Q_PROPERTY(ParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
+ Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
Q_PROPERTY(QStringList particles READ particles WRITE setParticles NOTIFY particlesChanged)
public:
- explicit ParticleType(QSGItem *parent = 0);
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
- virtual int count();
- ParticleSystem* system() const
+ explicit QSGParticlePainter(QSGItem *parent = 0);
+ //Data Interface to system
+ void load(QSGParticleData*);
+ void reload(QSGParticleData*);
+ void setCount(int c);
+ int count();
+ QSGParticleSystem* system() const
{
return m_system;
}
@@ -76,16 +77,14 @@ public:
return m_particles;
}
- int particleTypeIndex(ParticleData*);
- virtual void componentComplete();
signals:
void countChanged();
- void systemChanged(ParticleSystem* arg);
+ void systemChanged(QSGParticleSystem* arg);
void particlesChanged(QStringList arg);
public slots:
-void setSystem(ParticleSystem* arg);
+void setSystem(QSGParticleSystem* arg);
void setParticles(QStringList arg)
{
@@ -96,39 +95,38 @@ void setParticles(QStringList arg)
}
private slots:
void calcSystemOffset();
+
protected:
+ /* Reset resets all your internal data structures. But anything attached to a particle should
+ be in attached data. So reset + reloads should have no visible effect.
+ ###Hunt down all cases where we do a complete reset for convenience and be more targeted
+ */
virtual void reset();
-// virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *){
-// qDebug() << "Shouldn't be here..." << this;
-// return 0;
-// }
-
- ParticleSystem* m_system;
- friend class ParticleSystem;
+ virtual void componentComplete();
+ //Data interface to painters
+ QVector<QSGParticleData*> m_data; //Actually stored in arbitrary order,
+ QVector<QObject*> m_attachedData; //This data will be moved along with m_data in resizes (but you own it)
+ virtual void initialize(int){}
+ virtual void reload(int){}//If you need to do something on size changed, check m_data size in this? Or we reset you every time?
+
+ QSGParticleSystem* m_system;
+ friend class QSGParticleSystem;
int m_count;
bool m_pleaseReset;
QStringList m_particles;
- QHash<int,int> m_particleStarts;
- int m_lastStart;
QPointF m_systemOffset;
- template <typename VertexStruct>
- void vertexCopy(VertexStruct &b, const ParticleVertex& a)
- {
- b.x = a.x - m_systemOffset.x();
- b.y = a.y - m_systemOffset.y();
- b.t = a.t;
- b.lifeSpan = a.lifeSpan;
- b.size = a.size;
- b.endSize = a.endSize;
- b.sx = a.sx;
- b.sy = a.sy;
- b.ax = a.ax;
- b.ay = a.ay;
- }
private:
+ int m_lastStart;
+ QHash<int, QPair<int, int> > m_particleStarts;
+ int particleTypeIndex(QSGParticleData* d);//Now private
+ void resize(int, int);
+
+ QSGParticleData* m_sentinel;
+ //QVector<QSGParticleData*> m_shadowData;//For when we implement overwrite: false
+ bool m_inResize;
};
QT_END_NAMESPACE
diff --git a/src/declarative/particles/qsgparticlesmodule.cpp b/src/declarative/particles/qsgparticlesmodule.cpp
new file mode 100644
index 0000000000..a7a9a9253f
--- /dev/null
+++ b/src/declarative/particles/qsgparticlesmodule.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** 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 Declarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgangleddirection_p.h"
+#include "qsgcustomparticle_p.h"
+#include "qsgellipseextruder_p.h"
+#include "qsgemitter_p.h"
+#include "qsgfollowemitter_p.h"
+#include "qsgfriction_p.h"
+#include "qsggravity_p.h"
+#include "qsgimageparticle_p.h"
+#include "qsgitemparticle_p.h"
+#include "qsgkill_p.h"
+#include "qsglineextruder_p.h"
+#include "qsgmaskextruder_p.h"
+#include "qsgmodelparticle_p.h"
+#include "qsgparticleaffector_p.h"
+#include "qsgparticleemitter_p.h"
+#include "qsgparticleextruder_p.h"
+#include "qsgparticlepainter_p.h"
+#include "qsgparticlesmodule_p.h"
+#include "qsgparticlesystem_p.h"
+#include "qsgpointattractor_p.h"
+#include "qsgpointdirection_p.h"
+#include "qsgspritegoal_p.h"
+#include "qsgstochasticdirection_p.h"
+#include "qsgtargeteddirection_p.h"
+#include "qsgturbulence_p.h"
+#include "qsgwander_p.h"
+
+QT_BEGIN_NAMESPACE
+
+void QSGParticlesModule::defineModule()
+{
+ const char* uri = "QtQuick.Particles";
+ //Debugging only exposition
+ qmlRegisterType<QSGParticlePainter>(uri, 2, 0, "ParticlePainter");
+ qmlRegisterType<QSGParticleEmitter>(uri, 2, 0, "ParticleEmitter");
+ qmlRegisterType<QSGParticleExtruder>(uri, 2, 0, "ParticleExtruder");
+ qmlRegisterType<QSGStochasticDirection>(uri, 2, 0, "NullVector");
+ //Probably should be nocreate types
+
+ qmlRegisterType<QSGParticleSystem>(uri, 2, 0, "ParticleSystem");
+
+ qmlRegisterType<QSGImageParticle>(uri, 2, 0, "ImageParticle");
+ qmlRegisterType<QSGCustomParticle>(uri, 2, 0, "CustomParticle");
+ qmlRegisterType<QSGItemParticle>(uri, 2, 0, "ItemParticle");
+ qmlRegisterType<QSGModelParticle>(uri, 2, 0, "ModelParticle");
+
+ qmlRegisterType<QSGBasicEmitter>(uri, 2, 0, "Emitter");
+ qmlRegisterType<QSGFollowEmitter>(uri, 2, 0, "FollowEmitter");
+
+ qmlRegisterType<QSGEllipseExtruder>(uri, 2, 0, "EllipseShape");
+ qmlRegisterType<QSGLineExtruder>(uri, 2, 0, "LineShape");
+ qmlRegisterType<QSGMaskExtruder>(uri, 2, 0, "MaskShape");
+
+ qmlRegisterType<QSGPointDirection>(uri, 2, 0, "PointDirection");
+ qmlRegisterType<QSGAngledDirection>(uri, 2, 0, "AngledDirection");
+ qmlRegisterType<QSGTargetedDirection>(uri, 2, 0, "TargetedDirection");
+
+ qmlRegisterType<QSGParticleAffector>(uri, 2, 0, "ParticleAffector");//if it has a triggered signal, it's useful
+ qmlRegisterType<QSGWanderAffector>(uri, 2, 0, "Wander");
+ qmlRegisterType<QSGFrictionAffector>(uri, 2, 0, "Friction");
+ qmlRegisterType<QSGPointAttractorAffector>(uri, 2, 0, "PointAttractor");
+ qmlRegisterType<QSGGravityAffector>(uri, 2, 0, "Gravity");
+ qmlRegisterType<QSGKillAffector>(uri, 2, 0, "Kill");
+ qmlRegisterType<QSGSpriteGoalAffector>(uri, 2, 0, "SpriteGoal");
+ qmlRegisterType<QSGTurbulenceAffector>(uri, 2, 0 , "Turbulence");
+}
+
+QT_END_NAMESPACE
+
+//Q_EXPORT_PLUGIN2(Particles, QT_PREPEND_NAMESPACE(ParticlesModule))
diff --git a/src/imports/particles/burstemitter.cpp b/src/declarative/particles/qsgparticlesmodule_p.h
index a817172486..1afe0654f6 100644
--- a/src/imports/particles/burstemitter.cpp
+++ b/src/declarative/particles/qsgparticlesmodule_p.h
@@ -38,18 +38,26 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "burstemitter.h"
+
+#ifndef QSGPARTICLESMODULE_H
+#define QSGPARTICLESMODULE_H
+
+#include <qdeclarative.h>
+
+QT_BEGIN_HEADER
+
QT_BEGIN_NAMESPACE
-void BurstEmitter::burst(int count, qreal x, qreal y)
+QT_MODULE(Declarative)
+
+class QSGParticlesModule
{
- qreal oldX = QSGItem::x();
- qreal oldY = QSGItem::y();
- setX(x);
- setY(y);
- TrailsEmitter::burst(count);
- setX(oldX);
- setY(oldY);
-}
+public:
+ static void defineModule();
+};
QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QSGPARTICLESMODULE_H
diff --git a/src/declarative/particles/qsgparticlesystem.cpp b/src/declarative/particles/qsgparticlesystem.cpp
new file mode 100644
index 0000000000..2dc21299cf
--- /dev/null
+++ b/src/declarative/particles/qsgparticlesystem.cpp
@@ -0,0 +1,447 @@
+/****************************************************************************
+**
+** 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 Declarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgparticlesystem_p.h"
+#include <qsgnode.h>
+#include "qsgparticleemitter_p.h"
+#include "qsgparticleaffector_p.h"
+#include "qsgparticlepainter_p.h"
+#include <cmath>
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+QSGParticleData::QSGParticleData()
+ : group(0)
+ , e(0)
+ , index(0)
+{
+ x = 0;
+ y = 0;
+ t = -1;
+ size = 0;
+ endSize = 0;
+ sx = 0;
+ sy = 0;
+ ax = 0;
+ ay = 0;
+ xx = 1;
+ xy = 0;
+ yx = 0;
+ yy = 1;
+ rotation = 0;
+ rotationSpeed = 0;
+ autoRotate = 0;
+ animIdx = -1;
+ frameDuration = 1;
+ frameCount = 0;
+ animT = -1;
+ color.r = 255;
+ color.g = 255;
+ color.b = 255;
+ color.a = 255;
+ r = 0;
+ delegate = 0;
+ modelIndex = -1;
+}
+
+QSGParticleSystem::QSGParticleSystem(QSGItem *parent) :
+ QSGItem(parent), m_particle_count(0), m_running(true)
+ , m_startTime(0), m_overwrite(false)
+ , m_componentComplete(false)
+{
+ QSGParticleGroupData* gd = new QSGParticleGroupData;//Default group
+ m_groupData.insert(0,gd);
+ m_groupIds.insert("",0);
+ m_nextGroupId = 1;
+
+ connect(&m_painterMapper, SIGNAL(mapped(QObject*)),
+ this, SLOT(loadPainter(QObject*)));
+}
+
+void QSGParticleSystem::registerParticlePainter(QSGParticlePainter* p)
+{
+ //TODO: a way to Unregister emitters, painters and affectors
+ m_particlePainters << QPointer<QSGParticlePainter>(p);//###Set or uniqueness checking?
+ connect(p, SIGNAL(particlesChanged(QStringList)),
+ &m_painterMapper, SLOT(map()));
+ loadPainter(p);
+ p->update();//###Initial update here?
+}
+
+void QSGParticleSystem::registerParticleEmitter(QSGParticleEmitter* e)
+{
+ m_emitters << QPointer<QSGParticleEmitter>(e);//###How to get them out?
+ connect(e, SIGNAL(particleCountChanged()),
+ this, SLOT(emittersChanged()));
+ connect(e, SIGNAL(particleChanged(QString)),
+ this, SLOT(emittersChanged()));
+ emittersChanged();
+ e->reset();//Start, so that starttime factors appropriately
+}
+
+void QSGParticleSystem::registerParticleAffector(QSGParticleAffector* a)
+{
+ m_affectors << QPointer<QSGParticleAffector>(a);
+}
+
+void QSGParticleSystem::loadPainter(QObject *p)
+{
+ if(!m_componentComplete)
+ return;
+
+ QSGParticlePainter* painter = qobject_cast<QSGParticlePainter*>(p);
+ Q_ASSERT(painter);//XXX
+ foreach(QSGParticleGroupData* sg, m_groupData)
+ sg->painters.remove(painter);
+ int particleCount = 0;
+ if(painter->particles().isEmpty()){//Uses default particle
+ particleCount += m_groupData[0]->size;
+ m_groupData[0]->painters << painter;
+ }else{
+ foreach(const QString &group, painter->particles()){
+ particleCount += m_groupData[m_groupIds[group]]->size;
+ m_groupData[m_groupIds[group]]->painters << painter;
+ }
+ }
+ painter->setCount(particleCount);
+ painter->update();//###Initial update here?
+ return;
+}
+
+void QSGParticleSystem::emittersChanged()
+{
+ if(!m_componentComplete)
+ return;
+
+ m_emitters.removeAll(0);
+
+ //Recalculate all counts, as emitter 'particle' may have changed as well
+ //### Worth tracking previous 'particle' per emitter to do partial recalculations?
+ m_particle_count = 0;
+
+ int previousGroups = m_nextGroupId;
+ QVector<int> previousSizes;
+ previousSizes.resize(previousGroups);
+ for(int i=0; i<previousGroups; i++)
+ previousSizes[i] = m_groupData[i]->size;
+ for(int i=0; i<previousGroups; i++)
+ m_groupData[i]->size = 0;
+
+ foreach(QSGParticleEmitter* e, m_emitters){//Populate groups and set sizes.
+ if(!m_groupIds.contains(e->particle())
+ || (!e->particle().isEmpty() && !m_groupIds[e->particle()])){//or it was accidentally inserted by a failed lookup earlier
+ QSGParticleGroupData* gd = new QSGParticleGroupData;
+ int id = m_nextGroupId++;
+ m_groupIds.insert(e->particle(), id);
+ m_groupData.insert(id, gd);
+ }
+ m_groupData[m_groupIds[e->particle()]]->size += e->particleCount();
+ m_particle_count += e->particleCount();
+ //###: Cull emptied groups?
+ }
+
+ foreach(QSGParticleGroupData* gd, m_groupData){//resize groups and update painters
+ int id = m_groupData.key(gd);
+
+ //TODO: Shrink back down! (but it has the problem of trying to remove the dead particles while maintaining integrity)
+ gd->size = qMax(gd->size, id < previousGroups?previousSizes[id]:0);
+
+ gd->data.resize(gd->size);
+ if(id < previousGroups){
+ for(int i=previousSizes[id]; i<gd->size; i++)
+ gd->data[i] = 0;
+ /*TODO:Consider salvaging partial updates, but have to batch changes to a single painter
+ int delta = 0;
+ delta = gd->size - previousSizes[id];
+ foreach(QSGParticlePainter* painter, gd->painters){
+ if(!painter->count() && delta){
+ painter->reset();
+ painter->update();
+ }
+ qDebug() << "Phi" << painter << painter->count() << delta;
+ painter->setCount(painter->count() + delta);
+ }
+ */
+ }
+ }
+ foreach(QSGParticlePainter *p, m_particlePainters)
+ loadPainter(p);
+
+ if(m_particle_count > 16000)//###Investigate if these limits are worth warning about?
+ qWarning() << "Particle system arbitarily believes it has a vast number of particles (>16000). Expect poor performance";
+}
+
+void QSGParticleSystem::setRunning(bool arg)
+{
+ if (m_running != arg) {
+ m_running = arg;
+ emit runningChanged(arg);
+ reset();
+ }
+}
+
+void QSGParticleSystem::componentComplete()
+{
+ QSGItem::componentComplete();
+ m_componentComplete = true;
+ //if(!m_emitters.isEmpty() && !m_particlePainters.isEmpty())
+ reset();
+}
+
+void QSGParticleSystem::reset()//TODO: Needed?
+{
+ if(!m_componentComplete)
+ return;
+
+ //Clear guarded pointers which have been deleted
+ int cleared = 0;
+ cleared += m_emitters.removeAll(0);
+ cleared += m_particlePainters.removeAll(0);
+ cleared += m_affectors.removeAll(0);
+ //qDebug() << "Reset" << m_emitters.count() << m_particles.count() << "Cleared" << cleared;
+
+ emittersChanged();
+
+ //TODO: Reset data
+// foreach(QSGParticlePainter* p, m_particlePainters)
+// p->reset();
+// foreach(QSGParticleEmitter* e, m_emitters)
+// e->reset();
+ //### Do affectors need reset too?
+
+ if(!m_running)
+ return;
+
+ foreach(QSGParticlePainter *p, m_particlePainters){
+ loadPainter(p);
+ p->reset();
+ }
+
+ m_timestamp.start();//TODO: Better placement
+ m_initialized = true;
+}
+
+QSGParticleData* QSGParticleSystem::newDatum(int groupId)
+{
+
+ Q_ASSERT(groupId < m_groupData.count());//XXX shouldn't really be an assert
+ Q_ASSERT(m_groupData[groupId]->size);
+
+ if( m_groupData[groupId]->nextIdx >= m_groupData[groupId]->size)
+ m_groupData[groupId]->nextIdx = 0;
+ int nextIdx = m_groupData[groupId]->nextIdx++;
+
+ Q_ASSERT(nextIdx < m_groupData[groupId]->size);
+ QSGParticleData* ret;
+ if(m_groupData[groupId]->data[nextIdx]){//Recycle, it's faster.
+ ret = m_groupData[groupId]->data[nextIdx];
+ if(!m_overwrite && ret->stillAlive()){
+ return 0;//Artificial longevity (or too fast emission) means this guy hasn't died. To maintain count, don't emit a new one
+ }//###Reset?
+ }else{
+ ret = new QSGParticleData;
+ m_groupData[groupId]->data[nextIdx] = ret;
+ }
+
+ ret->system = this;
+ ret->index = nextIdx;
+ ret->group = groupId;
+ return ret;
+}
+
+void QSGParticleSystem::emitParticle(QSGParticleData* pd)
+{// called from prepareNextFrame()->emitWindow - enforce?
+ //Account for relative emitter position
+ QPointF offset = this->mapFromItem(pd->e, QPointF(0, 0));
+ if(!offset.isNull()){
+ pd->x += offset.x();
+ pd->y += offset.y();
+ }
+
+ foreach(QSGParticleAffector *a, m_affectors)
+ if(a && a->m_needsReset)
+ a->reset(pd);
+ foreach(QSGParticlePainter* p, m_groupData[pd->group]->painters)
+ if(p)
+ p->load(pd);
+}
+
+
+
+qint64 QSGParticleSystem::systemSync(QSGParticlePainter* p)
+{
+ if (!m_running)
+ return 0;
+ if (!m_initialized)
+ return 0;//error in initialization
+
+ if(m_syncList.isEmpty() || m_syncList.contains(p)){//Need to advance the simulation
+ m_syncList.clear();
+
+ //### Elapsed time never shrinks - may cause problems if left emitting for weeks at a time.
+ qreal dt = m_timeInt / 1000.;
+ m_timeInt = m_timestamp.elapsed() + m_startTime;
+ qreal time = m_timeInt / 1000.;
+ dt = time - dt;
+ m_needsReset.clear();
+ foreach(QSGParticleEmitter* emitter, m_emitters)
+ if(emitter)
+ emitter->emitWindow(m_timeInt);
+ foreach(QSGParticleAffector* a, m_affectors)
+ if(a)
+ a->affectSystem(dt);
+ foreach(QSGParticleData* d, m_needsReset)
+ foreach(QSGParticlePainter* p, m_groupData[d->group]->painters)
+ if(p && d)
+ p->reload(d);
+ }
+ m_syncList << p;
+ return m_timeInt;
+}
+
+//sets the x accleration without affecting the instantaneous x velocity or position
+void QSGParticleData::setInstantaneousAX(qreal ax)
+{
+ qreal t = (system->m_timeInt / 1000.0) - this->t;
+ qreal sx = (this->sx + t*this->ax) - t*ax;
+ qreal ex = this->x + this->sx * t + 0.5 * this->ax * t * t;
+ qreal x = ex - t*sx - 0.5 * t*t*ax;
+
+ this->ax = ax;
+ this->sx = sx;
+ this->x = x;
+}
+
+//sets the x velocity without affecting the instantaneous x postion
+void QSGParticleData::setInstantaneousSX(qreal vx)
+{
+ qreal t = (system->m_timeInt / 1000.0) - this->t;
+ qreal sx = vx - t*this->ax;
+ qreal ex = this->x + this->sx * t + 0.5 * this->ax * t * t;
+ qreal x = ex - t*sx - 0.5 * t*t*this->ax;
+
+ this->sx = sx;
+ this->x = x;
+}
+
+//sets the instantaneous x postion
+void QSGParticleData::setInstantaneousX(qreal x)
+{
+ qreal t = (system->m_timeInt / 1000.0) - this->t;
+ this->x = x - t*this->sx - 0.5 * t*t*this->ax;
+}
+
+//sets the y accleration without affecting the instantaneous y velocity or position
+void QSGParticleData::setInstantaneousAY(qreal ay)
+{
+ qreal t = (system->m_timeInt / 1000.0) - this->t;
+ qreal sy = (this->sy + t*this->ay) - t*ay;
+ qreal ey = this->y + this->sy * t + 0.5 * this->ay * t * t;
+ qreal y = ey - t*sy - 0.5 * t*t*ay;
+
+ this->ay = ay;
+ this->sy = sy;
+ this->y = y;
+}
+
+//sets the y velocity without affecting the instantaneous y position
+void QSGParticleData::setInstantaneousSY(qreal vy)
+{
+ qreal t = (system->m_timeInt / 1000.0) - this->t;
+ //qDebug() << t << (system->m_timeInt/1000.0) << this->x << this->sx << this->ax << this->x + this->sx * t + 0.5 * this->ax * t * t;
+ qreal sy = vy - t*this->ay;
+ qreal ey = this->y + this->sy * t + 0.5 * this->ay * t * t;
+ qreal y = ey - t*sy - 0.5 * t*t*this->ay;
+
+ this->sy = sy;
+ this->y = y;
+}
+
+//sets the instantaneous Y position
+void QSGParticleData::setInstantaneousY(qreal y)
+{
+ qreal t = (system->m_timeInt / 1000.0) - this->t;
+ this->y = y - t*this->sy - 0.5 * t*t*this->ay;
+}
+
+qreal QSGParticleData::curX() const
+{
+ qreal t = (system->m_timeInt / 1000.0) - this->t;
+ return this->x + this->sx * t + 0.5 * this->ax * t * t;
+}
+
+qreal QSGParticleData::curSX() const
+{
+ qreal t = (system->m_timeInt / 1000.0) - this->t;
+ return this->sx + t*this->ax;
+}
+
+qreal QSGParticleData::curY() const
+{
+ qreal t = (system->m_timeInt / 1000.0) - this->t;
+ return y + sy * t + 0.5 * ay * t * t;
+}
+
+qreal QSGParticleData::curSY() const
+{
+ qreal t = (system->m_timeInt / 1000.0) - this->t;
+ return sy + t*ay;
+}
+
+void QSGParticleData::debugDump()
+{
+ qDebug() << "Particle" << group
+ << "Pos: " << x << "," << y
+ << "Vel: " << sx << "," << sy
+ << "Acc: " << ax << "," << ay
+ << "Size: " << size << "," << endSize
+ << "Time: " << t << "," <<lifeSpan;
+}
+
+bool QSGParticleData::stillAlive()
+{
+ if(!system)
+ return false;
+ return (t + lifeSpan) > (system->m_timeInt/1000.0);
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/particles/particlesystem.h b/src/declarative/particles/qsgparticlesystem_p.h
index fbb0e7424f..45b4e164f1 100644
--- a/src/imports/particles/particlesystem.h
+++ b/src/declarative/particles/qsgparticlesystem_p.h
@@ -47,6 +47,7 @@
#include <QVector>
#include <QHash>
#include <QPointer>
+#include <QSignalMapper>
QT_BEGIN_HEADER
@@ -55,20 +56,23 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class ParticleAffector;
-class ParticleEmitter;
-class ParticleType;
-class ParticleData;
+class QSGParticleAffector;
+class QSGParticleEmitter;
+class QSGParticlePainter;
+class QSGParticleData;
-struct GroupData{
+class QSGParticleGroupData{
+public:
+ QSGParticleGroupData():size(0),nextIdx(0)
+ {}
int size;
- int start;
int nextIdx;
- QList<ParticleType*> types;
+ QSet<QSGParticlePainter*> painters;
+ QVector<QSGParticleData*> data;
};
-class ParticleSystem : public QSGItem
+class QSGParticleSystem : public QSGItem
{
Q_OBJECT
Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
@@ -80,7 +84,7 @@ class ParticleSystem : public QSGItem
*/
public:
- explicit ParticleSystem(QSGItem *parent = 0);
+ explicit QSGParticleSystem(QSGItem *parent = 0);
bool isRunning() const
{
@@ -131,22 +135,22 @@ protected:
void componentComplete();
private slots:
- void countChanged();
+ void emittersChanged();
+ void loadPainter(QObject* p);
public://but only really for related class usage. Perhaps we should all be friends?
- void emitParticle(ParticleData* p);
- ParticleData* newDatum(int groupId);
- qint64 systemSync(ParticleType* p);
+ void emitParticle(QSGParticleData* p);
+ QSGParticleData* newDatum(int groupId);
+ qint64 systemSync(QSGParticlePainter* p);
QElapsedTimer m_timestamp;
- QVector<ParticleData*> m_data;
- QSet<ParticleData*> m_needsReset;
+ QSet<QSGParticleData*> m_needsReset;
QHash<QString, int> m_groupIds;
- QHash<int, GroupData*> m_groupData;//id, size, start
+ QHash<int, QSGParticleGroupData*> m_groupData;
qint64 m_timeInt;
bool m_initialized;
- void registerParticleType(ParticleType* p);
- void registerParticleEmitter(ParticleEmitter* e);
- void registerParticleAffector(ParticleAffector* a);
+ void registerParticlePainter(QSGParticlePainter* p);
+ void registerParticleEmitter(QSGParticleEmitter* e);
+ void registerParticleAffector(QSGParticleAffector* a);
bool overwrite() const
{
return m_overwrite;
@@ -156,36 +160,30 @@ public://but only really for related class usage. Perhaps we should all be frien
private:
void initializeSystem();
bool m_running;
- QList<QPointer<ParticleEmitter> > m_emitters;
- QList<QPointer<ParticleAffector> > m_affectors;
- QList<QPointer<ParticleType> > m_particles;
- QList<QPointer<ParticleType> > m_syncList;
+ QList<QPointer<QSGParticleEmitter> > m_emitters;
+ QList<QPointer<QSGParticleAffector> > m_affectors;
+ QList<QPointer<QSGParticlePainter> > m_particlePainters;
+ QList<QPointer<QSGParticlePainter> > m_syncList;
qint64 m_startTime;
int m_nextGroupId;
bool m_overwrite;
-};
+ bool m_componentComplete;
-//TODO: Clean up all this into ParticleData
+ QSignalMapper m_painterMapper;
+ QSignalMapper m_emitterMapper;
+};
-struct ParticleVertex {
- float x;
- float y;
- float t;
- float lifeSpan;
- float size;
- float endSize;
- float sx;
- float sy;
- float ax;
- float ay;
- //TODO: Need opacity over life control. More variable size over life?
+struct Color4ub {
+ uchar r;
+ uchar g;
+ uchar b;
+ uchar a;
};
-class ParticleData{
+class QSGParticleData{
public:
- ParticleData();
-
- ParticleVertex pv;
+ //TODO: QObject like memory management (without the cost, just attached to system)
+ QSGParticleData();
//Convenience functions for working backwards, because parameters are from the start of particle life
//If setting multiple parameters at once, doing the conversion yourself will be faster.
@@ -210,10 +208,38 @@ public:
qreal curSY() const;
int group;
- ParticleEmitter* e;
- ParticleSystem* system;
- int particleIndex;
- int systemIndex;
+ QSGParticleEmitter* e;//### Needed?
+ QSGParticleSystem* system;
+ int index;
+
+ //General Position Stuff
+ float x;
+ float y;
+ float t;
+ float lifeSpan;
+ float size;
+ float endSize;
+ float sx;
+ float sy;
+ float ax;
+ float ay;
+
+ //Other stuff, now universally shared
+ Color4ub color;
+ float xx;
+ float xy;
+ float yx;
+ float yy;
+ float rotation;
+ float rotationSpeed;
+ float autoRotate;//Assume that GPUs prefer floats to bools
+ float animIdx;
+ float frameDuration;
+ float frameCount;
+ float animT;
+ float r;
+ QSGItem* delegate;
+ int modelIndex;
void debugDump();
bool stillAlive();
diff --git a/src/imports/particles/attractoraffector.cpp b/src/declarative/particles/qsgpointattractor.cpp
index 847cb2c471..6f57ecaa36 100644
--- a/src/imports/particles/attractoraffector.cpp
+++ b/src/declarative/particles/qsgpointattractor.cpp
@@ -39,28 +39,50 @@
**
****************************************************************************/
-#include "attractoraffector.h"
+#include "qsgpointattractor_p.h"
#include <cmath>
#include <QDebug>
QT_BEGIN_NAMESPACE
-AttractorAffector::AttractorAffector(QSGItem *parent) :
- ParticleAffector(parent), m_strength(0.0), m_x(0), m_y(0)
+QSGPointAttractorAffector::QSGPointAttractorAffector(QSGItem *parent) :
+ QSGParticleAffector(parent), m_strength(0.0), m_x(0), m_y(0)
+ , m_physics(Velocity), m_proportionalToDistance(Linear)
{
}
-bool AttractorAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGPointAttractorAffector::affectParticle(QSGParticleData *d, qreal dt)
{
if(m_strength == 0.0)
return false;
- qreal dx = m_x - d->curX();
- qreal dy = m_y - d->curY();
+ qreal dx = m_y - d->curX();
+ qreal dy = m_x - d->curY();
qreal r = sqrt((dx*dx) + (dy*dy));
qreal theta = atan2(dy,dx);
- qreal ds = (m_strength / r) * dt;
+ qreal ds = 0;
+ switch(m_proportionalToDistance){
+ case Quadratic:
+ ds = (m_strength / qMax<qreal>(1.,r*r)) * dt;
+ break;
+ case Linear://also default
+ default:
+ ds = (m_strength / qMax<qreal>(1.,r)) * dt;
+ }
dx = ds * cos(theta);
dy = ds * sin(theta);
- d->setInstantaneousSX(d->pv.sx + dx);
- d->setInstantaneousSY(d->pv.sy + dy);
+ switch(m_physics){
+ case Position:
+ d->x = (d->x + dx);
+ d->y = (d->y + dy);
+ break;
+ case Acceleration:
+ d->setInstantaneousAX(d->ax + dx);
+ d->setInstantaneousAY(d->ay + dy);
+ break;
+ case Velocity: //also default
+ default:
+ d->setInstantaneousSX(d->sx + dx);
+ d->setInstantaneousSY(d->sy + dy);
+ }
+
return true;
}
QT_END_NAMESPACE
diff --git a/src/imports/particles/attractoraffector.h b/src/declarative/particles/qsgpointattractor_p.h
index f41e9ad5e4..3ca29dfa96 100644
--- a/src/imports/particles/attractoraffector.h
+++ b/src/declarative/particles/qsgpointattractor_p.h
@@ -41,7 +41,7 @@
#ifndef ATTRACTORAFFECTOR_H
#define ATTRACTORAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
@@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class AttractorAffector : public ParticleAffector
+class QSGPointAttractorAffector : public QSGParticleAffector
{
Q_OBJECT
//Like Gravitational singularity, but linear to distance instead of quadratic
@@ -57,8 +57,24 @@ class AttractorAffector : public ParticleAffector
Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
+ Q_PROPERTY(PhysicsAffects physics READ physics WRITE setPhysics NOTIFY physicsChanged)
+ Q_PROPERTY(Proportion proportionalToDistance READ proportionalToDistance WRITE setProportionalToDistance NOTIFY proportionalToDistanceChanged)
+ Q_ENUMS(PhysicsAffects)
+ Q_ENUMS(Proportion)
+
public:
- explicit AttractorAffector(QSGItem *parent = 0);
+ enum Proportion{
+ Linear,
+ Quadratic
+ };
+
+ enum PhysicsAffects {
+ Position,
+ Velocity,
+ Acceleration
+ };
+
+ explicit QSGPointAttractorAffector(QSGItem *parent = 0);
qreal strength() const
{
@@ -75,6 +91,16 @@ public:
return m_y;
}
+ PhysicsAffects physics() const
+ {
+ return m_physics;
+ }
+
+ Proportion proportionalToDistance() const
+ {
+ return m_proportionalToDistance;
+ }
+
signals:
void strengthChanged(qreal arg);
@@ -83,6 +109,10 @@ signals:
void yChanged(qreal arg);
+ void physicsChanged(PhysicsAffects arg);
+
+ void proportionalToDistanceChanged(Proportion arg);
+
public slots:
void setStrength(qreal arg)
{
@@ -107,12 +137,30 @@ void setY(qreal arg)
emit yChanged(arg);
}
}
+void setPhysics(PhysicsAffects arg)
+{
+ if (m_physics != arg) {
+ m_physics = arg;
+ emit physicsChanged(arg);
+ }
+}
+
+void setProportionalToDistance(Proportion arg)
+{
+ if (m_proportionalToDistance != arg) {
+ m_proportionalToDistance = arg;
+ emit proportionalToDistanceChanged(arg);
+ }
+}
+
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
private:
qreal m_strength;
qreal m_x;
qreal m_y;
+PhysicsAffects m_physics;
+Proportion m_proportionalToDistance;
};
QT_END_NAMESPACE
diff --git a/src/imports/particles/pointvector.cpp b/src/declarative/particles/qsgpointdirection.cpp
index e222965943..c3c4f1c5de 100644
--- a/src/imports/particles/pointvector.cpp
+++ b/src/declarative/particles/qsgpointdirection.cpp
@@ -39,12 +39,12 @@
**
****************************************************************************/
-#include "pointvector.h"
+#include "qsgpointdirection_p.h"
QT_BEGIN_NAMESPACE
-PointVector::PointVector(QObject *parent) :
- VaryingVector(parent)
+QSGPointDirection::QSGPointDirection(QObject *parent) :
+ QSGStochasticDirection(parent)
, m_x(0)
, m_y(0)
, m_xVariation(0)
@@ -52,7 +52,7 @@ PointVector::PointVector(QObject *parent) :
{
}
-const QPointF &PointVector::sample(const QPointF &)
+const QPointF &QSGPointDirection::sample(const QPointF &)
{
m_ret.setX(m_x - m_xVariation + rand() / float(RAND_MAX) * m_xVariation * 2);
m_ret.setY(m_y - m_yVariation + rand() / float(RAND_MAX) * m_yVariation * 2);
diff --git a/src/imports/particles/pointvector.h b/src/declarative/particles/qsgpointdirection_p.h
index 5ffa896680..5e5b052744 100644
--- a/src/imports/particles/pointvector.h
+++ b/src/declarative/particles/qsgpointdirection_p.h
@@ -41,7 +41,7 @@
#ifndef POINTVECTOR_H
#define POINTVECTOR_H
-#include "varyingvector.h"
+#include "qsgstochasticdirection_p.h"
QT_BEGIN_HEADER
@@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class PointVector : public VaryingVector
+class QSGPointDirection : public QSGStochasticDirection
{
Q_OBJECT
Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
@@ -57,7 +57,7 @@ class PointVector : public VaryingVector
Q_PROPERTY(qreal xVariation READ xVariation WRITE setXVariation NOTIFY xVariationChanged)
Q_PROPERTY(qreal yVariation READ yVariation WRITE setYVariation NOTIFY yVariationChanged)
public:
- explicit PointVector(QObject *parent = 0);
+ explicit QSGPointDirection(QObject *parent = 0);
virtual const QPointF &sample(const QPointF &from);
qreal x() const
{
diff --git a/src/imports/particles/spritegoalaffector.cpp b/src/declarative/particles/qsgspritegoal.cpp
index 2bd56c4a07..c97bfd1f26 100644
--- a/src/imports/particles/spritegoalaffector.cpp
+++ b/src/declarative/particles/qsgspritegoal.cpp
@@ -39,20 +39,20 @@
**
****************************************************************************/
-#include "spritegoalaffector.h"
-#include "spriteparticle.h"
-#include "spriteengine.h"
-#include "spritestate.h"
+#include "qsgspritegoal_p.h"
+#include "private/qsgspriteengine_p.h"
+#include "private/qsgsprite_p.h"
+#include "qsgimageparticle_p.h"
#include <QDebug>
QT_BEGIN_NAMESPACE
-SpriteGoalAffector::SpriteGoalAffector(QSGItem *parent) :
- ParticleAffector(parent), m_goalIdx(-1), m_jump(false)
+QSGSpriteGoalAffector::QSGSpriteGoalAffector(QSGItem *parent) :
+ QSGParticleAffector(parent), m_goalIdx(-1), m_jump(false)
{
}
-void SpriteGoalAffector::updateStateIndex(SpriteEngine* e)
+void QSGSpriteGoalAffector::updateStateIndex(QSGSpriteEngine* e)
{
m_lastEngine = e;
for(int i=0; i<e->stateCount(); i++){
@@ -64,7 +64,7 @@ void SpriteGoalAffector::updateStateIndex(SpriteEngine* e)
m_goalIdx = -1;//Can't find it
}
-void SpriteGoalAffector::setGoalState(QString arg)
+void QSGSpriteGoalAffector::setGoalState(QString arg)
{
if (m_goalState != arg) {
m_goalState = arg;
@@ -76,21 +76,21 @@ void SpriteGoalAffector::setGoalState(QString arg)
}
}
-bool SpriteGoalAffector::affectParticle(ParticleData *d, qreal dt)
+bool QSGSpriteGoalAffector::affectParticle(QSGParticleData *d, qreal dt)
{
Q_UNUSED(dt);
//TODO: Affect all engines
- SpriteEngine *engine = 0;
- foreach(ParticleType *p, m_system->m_groupData[d->group]->types)
- if(qobject_cast<SpriteParticle*>(p))
- engine = qobject_cast<SpriteParticle*>(p)->spriteEngine();
+ QSGSpriteEngine *engine = 0;
+ foreach(QSGParticlePainter *p, m_system->m_groupData[d->group]->painters)
+ if(qobject_cast<QSGImageParticle*>(p))
+ engine = qobject_cast<QSGImageParticle*>(p)->spriteEngine();
if(!engine)
return false;
if(m_goalIdx == -2 || engine != m_lastEngine)
updateStateIndex(engine);
- if(engine->spriteState(d->particleIndex) != m_goalIdx){
- engine->setGoal(m_goalIdx, d->particleIndex, m_jump);
+ if(engine->spriteState(d->index) != m_goalIdx){
+ engine->setGoal(m_goalIdx, d->index, m_jump);
emit affected(QPointF(d->curX(), d->curY()));//###Expensive if unconnected? Move to Affector?
return true; //Doesn't affect particle data, but necessary for onceOff
}
diff --git a/src/imports/particles/spritegoalaffector.h b/src/declarative/particles/qsgspritegoal_p.h
index 3a51562be2..28fb2939e6 100644
--- a/src/imports/particles/spritegoalaffector.h
+++ b/src/declarative/particles/qsgspritegoal_p.h
@@ -41,7 +41,7 @@
#ifndef SPRITEGOALAFFECTOR_H
#define SPRITEGOALAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
@@ -49,15 +49,15 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class SpriteEngine;
+class QSGSpriteEngine;
-class SpriteGoalAffector : public ParticleAffector
+class QSGSpriteGoalAffector : public QSGParticleAffector
{
Q_OBJECT
Q_PROPERTY(QString goalState READ goalState WRITE setGoalState NOTIFY goalStateChanged)
Q_PROPERTY(bool jump READ jump WRITE setJump NOTIFY jumpChanged)
public:
- explicit SpriteGoalAffector(QSGItem *parent = 0);
+ explicit QSGSpriteGoalAffector(QSGItem *parent = 0);
QString goalState() const
{
@@ -69,7 +69,7 @@ public:
return m_jump;
}
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
signals:
void goalStateChanged(QString arg);
@@ -90,10 +90,10 @@ void setJump(bool arg)
}
private:
- void updateStateIndex(SpriteEngine* e);
+ void updateStateIndex(QSGSpriteEngine* e);
QString m_goalState;
int m_goalIdx;
- SpriteEngine* m_lastEngine;
+ QSGSpriteEngine* m_lastEngine;
bool m_jump;
};
diff --git a/src/imports/particles/varyingvector.cpp b/src/declarative/particles/qsgstochasticdirection.cpp
index ab09f47f79..3673b9c7a7 100644
--- a/src/imports/particles/varyingvector.cpp
+++ b/src/declarative/particles/qsgstochasticdirection.cpp
@@ -39,16 +39,16 @@
**
****************************************************************************/
-#include "varyingvector.h"
+#include "qsgstochasticdirection_p.h"
QT_BEGIN_NAMESPACE
-VaryingVector::VaryingVector(QObject *parent) :
+QSGStochasticDirection::QSGStochasticDirection(QObject *parent) :
QObject(parent)
{
}
-const QPointF &VaryingVector::sample(const QPointF &from)
+const QPointF &QSGStochasticDirection::sample(const QPointF &from)
{
return m_ret;
}
diff --git a/src/imports/particles/varyingvector.h b/src/declarative/particles/qsgstochasticdirection_p.h
index 9f80366d2e..da3a4302b1 100644
--- a/src/imports/particles/varyingvector.h
+++ b/src/declarative/particles/qsgstochasticdirection_p.h
@@ -52,11 +52,11 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class VaryingVector : public QObject
+class QSGStochasticDirection : public QObject
{
Q_OBJECT
public:
- explicit VaryingVector(QObject *parent = 0);
+ explicit QSGStochasticDirection(QObject *parent = 0);
virtual const QPointF &sample(const QPointF &from);
signals:
diff --git a/src/imports/particles/directedvector.cpp b/src/declarative/particles/qsgtargeteddirection.cpp
index c1aeba3ad2..9f1a868512 100644
--- a/src/imports/particles/directedvector.cpp
+++ b/src/declarative/particles/qsgtargeteddirection.cpp
@@ -39,14 +39,14 @@
**
****************************************************************************/
-#include "directedvector.h"
-#include "particleemitter.h"
+#include "qsgtargeteddirection_p.h"
+#include "qsgparticleemitter_p.h"
#include <cmath>
#include <QDebug>
QT_BEGIN_NAMESPACE
-DirectedVector::DirectedVector(QObject *parent) :
- VaryingVector(parent)
+QSGTargetedDirection::QSGTargetedDirection(QObject *parent) :
+ QSGStochasticDirection(parent)
, m_targetX(0)
, m_targetY(0)
, m_targetVariation(0)
@@ -57,13 +57,13 @@ DirectedVector::DirectedVector(QObject *parent) :
{
}
-const QPointF &DirectedVector::sample(const QPointF &from)
+const QPointF &QSGTargetedDirection::sample(const QPointF &from)
{
//###This approach loses interpolating the last position of the target (like we could with the emitter) is it worthwhile?
qreal targetX;
qreal targetY;
if(m_targetItem){
- ParticleEmitter* parentEmitter = qobject_cast<ParticleEmitter*>(parent());
+ QSGParticleEmitter* parentEmitter = qobject_cast<QSGParticleEmitter*>(parent());
targetX = m_targetItem->width()/2;
targetY = m_targetItem->height()/2;
if(!parentEmitter){
diff --git a/src/imports/particles/directedvector.h b/src/declarative/particles/qsgtargeteddirection_p.h
index f1d0919bc3..4010505858 100644
--- a/src/imports/particles/directedvector.h
+++ b/src/declarative/particles/qsgtargeteddirection_p.h
@@ -41,7 +41,7 @@
#ifndef DIRECTEDVECTOR_H
#define DIRECTEDVECTOR_H
-#include "varyingvector.h"
+#include "qsgstochasticdirection_p.h"
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QSGItem;
-class DirectedVector : public VaryingVector
+class QSGTargetedDirection : public QSGStochasticDirection
{
Q_OBJECT
Q_PROPERTY(qreal targetX READ targetX WRITE setTargetX NOTIFY targetXChanged)
@@ -64,7 +64,7 @@ class DirectedVector : public VaryingVector
Q_PROPERTY(qreal magnitudeVariation READ magnitudeVariation WRITE setMagnitudeVariation NOTIFY magnitudeVariationChanged)
public:
- explicit DirectedVector(QObject *parent = 0);
+ explicit QSGTargetedDirection(QObject *parent = 0);
virtual const QPointF &sample(const QPointF &from);
qreal targetX() const
diff --git a/src/imports/particles/turbulenceaffector.cpp b/src/declarative/particles/qsgturbulence.cpp
index d29f09d974..bb46b99f0d 100644
--- a/src/imports/particles/turbulenceaffector.cpp
+++ b/src/declarative/particles/qsgturbulence.cpp
@@ -39,21 +39,21 @@
**
****************************************************************************/
-#include "turbulenceaffector.h"
-#include "particle.h"
+#include "qsgturbulence_p.h"
+#include "qsgparticlepainter_p.h"//TODO: Why was this needed again?
#include <cmath>
#include <cstdlib>
#include <QDebug>
QT_BEGIN_NAMESPACE
-TurbulenceAffector::TurbulenceAffector(QSGItem *parent) :
- ParticleAffector(parent),
+QSGTurbulenceAffector::QSGTurbulenceAffector(QSGItem *parent) :
+ QSGParticleAffector(parent),
m_strength(10), m_lastT(0), m_frequency(64), m_gridSize(10), m_field(0), m_inited(false)
{
//TODO: Update grid on size change
}
-TurbulenceAffector::~TurbulenceAffector()
+QSGTurbulenceAffector::~QSGTurbulenceAffector()
{
if (m_field) {
for(int i=0; i<m_gridSize; i++)
@@ -67,7 +67,7 @@ static qreal magnitude(qreal x, qreal y)
return sqrt(x*x + y*y);
}
-void TurbulenceAffector::setSize(int arg)
+void QSGTurbulenceAffector::setSize(int arg)
{
if (m_gridSize != arg) {
if(m_field){ //deallocate and then reallocate grid
@@ -81,7 +81,7 @@ void TurbulenceAffector::setSize(int arg)
}
}
-void TurbulenceAffector::ensureInit()
+void QSGTurbulenceAffector::ensureInit()
{
if(m_inited)
return;
@@ -96,7 +96,7 @@ void TurbulenceAffector::ensureInit()
m_magSum = magnitude(m_spacing.x(), m_spacing.y())*2;
}
-void TurbulenceAffector::mapUpdate()
+void QSGTurbulenceAffector::mapUpdate()
{
QPoint pos(rand() % m_gridSize, rand() % m_gridSize);
QPointF vector(m_strength - (((qreal)rand() / RAND_MAX) * m_strength*2),
@@ -116,7 +116,7 @@ void TurbulenceAffector::mapUpdate()
}
-void TurbulenceAffector::affectSystem(qreal dt)
+void QSGTurbulenceAffector::affectSystem(qreal dt)
{
if(!m_system || !m_active)
return;
@@ -128,30 +128,34 @@ void TurbulenceAffector::affectSystem(qreal dt)
m_lastT += period;
}
- foreach(ParticleData *d, m_system->m_data){
- if(!d || !activeGroup(d->group))
+ foreach(QSGParticleGroupData *gd, m_system->m_groupData){
+ if(!activeGroup(m_system->m_groupData.key(gd)))//TODO: Surely this can be done better
return;
- qreal fx = 0.0;
- qreal fy = 0.0;
- QPointF pos = QPointF(d->curX() - x(), d->curY() - y());//TODO: Offset
- QPointF nodePos = QPointF(pos.x() / m_spacing.x(), pos.y() / m_spacing.y());
- QSet<QPair<int, int> > nodes;
- nodes << qMakePair((int)ceil(nodePos.x()), (int)ceil(nodePos.y()));
- nodes << qMakePair((int)ceil(nodePos.x()), (int)floor(nodePos.y()));
- nodes << qMakePair((int)floor(nodePos.x()), (int)ceil(nodePos.y()));
- nodes << qMakePair((int)floor(nodePos.x()), (int)floor(nodePos.y()));
- typedef QPair<int, int> intPair;
- foreach(const intPair &p, nodes){
- if(!QRect(0,0,m_gridSize-1,m_gridSize-1).contains(QPoint(p.first, p.second)))
- continue;
- qreal dist = magnitude(pos.x() - p.first*m_spacing.x(), pos.y() - p.second*m_spacing.y());//TODO: Mathematically valid
- fx += m_field[p.first][p.second].x() * ((m_magSum - dist)/m_magSum);//Proportionally weight nodes
- fy += m_field[p.first][p.second].y() * ((m_magSum - dist)/m_magSum);
- }
- if(fx || fy){
- d->setInstantaneousSX(d->curSX()+ fx * dt);
- d->setInstantaneousSY(d->curSY()+ fy * dt);
- m_system->m_needsReset << d;
+ foreach(QSGParticleData *d, gd->data){
+ if(!d || !activeGroup(d->group))
+ return;
+ qreal fx = 0.0;
+ qreal fy = 0.0;
+ QPointF pos = QPointF(d->curX() - x(), d->curY() - y());//TODO: Offset
+ QPointF nodePos = QPointF(pos.x() / m_spacing.x(), pos.y() / m_spacing.y());
+ QSet<QPair<int, int> > nodes;
+ nodes << qMakePair((int)ceil(nodePos.x()), (int)ceil(nodePos.y()));
+ nodes << qMakePair((int)ceil(nodePos.x()), (int)floor(nodePos.y()));
+ nodes << qMakePair((int)floor(nodePos.x()), (int)ceil(nodePos.y()));
+ nodes << qMakePair((int)floor(nodePos.x()), (int)floor(nodePos.y()));
+ typedef QPair<int, int> intPair;
+ foreach(const intPair &p, nodes){
+ if(!QRect(0,0,m_gridSize-1,m_gridSize-1).contains(QPoint(p.first, p.second)))
+ continue;
+ qreal dist = magnitude(pos.x() - p.first*m_spacing.x(), pos.y() - p.second*m_spacing.y());//TODO: Mathematically valid
+ fx += m_field[p.first][p.second].x() * ((m_magSum - dist)/m_magSum);//Proportionally weight nodes
+ fy += m_field[p.first][p.second].y() * ((m_magSum - dist)/m_magSum);
+ }
+ if(fx || fy){
+ d->setInstantaneousSX(d->curSX()+ fx * dt);
+ d->setInstantaneousSY(d->curSY()+ fy * dt);
+ m_system->m_needsReset << d;
+ }
}
}
}
diff --git a/src/imports/particles/turbulenceaffector.h b/src/declarative/particles/qsgturbulence_p.h
index 2dc2ddcdfd..29483fbc70 100644
--- a/src/imports/particles/turbulenceaffector.h
+++ b/src/declarative/particles/qsgturbulence_p.h
@@ -41,7 +41,7 @@
#ifndef TURBULENCEAFFECTOR_H
#define TURBULENCEAFFECTOR_H
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
#include <QDeclarativeListProperty>
QT_BEGIN_HEADER
@@ -51,17 +51,17 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class ParticleType;
+class QSGParticlePainter;
-class TurbulenceAffector : public ParticleAffector
+class QSGTurbulenceAffector : public QSGParticleAffector
{
Q_OBJECT
Q_PROPERTY(int strength READ strength WRITE setStrength NOTIFY strengthChanged)
Q_PROPERTY(int frequency READ frequency WRITE setFrequency NOTIFY frequencyChanged)
Q_PROPERTY(int gridSize READ size WRITE setSize NOTIFY sizeChanged)
public:
- explicit TurbulenceAffector(QSGItem *parent = 0);
- ~TurbulenceAffector();
+ explicit QSGTurbulenceAffector(QSGItem *parent = 0);
+ ~QSGTurbulenceAffector();
virtual void affectSystem(qreal dt);
int strength() const
diff --git a/src/imports/particles/wanderaffector.cpp b/src/declarative/particles/qsgwander.cpp
index 4d3ba5f7ce..26bea4ee04 100644
--- a/src/imports/particles/wanderaffector.cpp
+++ b/src/declarative/particles/qsgwander.cpp
@@ -39,24 +39,25 @@
**
****************************************************************************/
-#include "wanderaffector.h"
-#include "particlesystem.h"//for ParticlesVertices
+#include "qsgwander_p.h"
+#include "qsgparticlesystem_p.h"//for ParticlesVertices
QT_BEGIN_NAMESPACE
-WanderAffector::WanderAffector(QSGItem *parent) :
- ParticleAffector(parent)
+QSGWanderAffector::QSGWanderAffector(QSGItem *parent) :
+ QSGParticleAffector(parent), m_xVariance(0), m_yVariance(0), m_pace(0)
+ , m_physics(Velocity)
{
m_needsReset = true;
}
-WanderAffector::~WanderAffector()
+QSGWanderAffector::~QSGWanderAffector()
{
for(QHash<int, WanderData*>::const_iterator iter=m_wanderData.constBegin();
iter != m_wanderData.constEnd(); iter++)
delete (*iter);
}
-WanderData* WanderAffector::getData(int idx)
+WanderData* QSGWanderAffector::getData(int idx)
{
if(m_wanderData.contains(idx))
return m_wanderData[idx];
@@ -72,15 +73,16 @@ WanderData* WanderAffector::getData(int idx)
return d;
}
-void WanderAffector::reset(int systemIdx)
+void QSGWanderAffector::reset(int systemIdx)
{
if(m_wanderData.contains(systemIdx))
delete m_wanderData[systemIdx];
m_wanderData.remove(systemIdx);
}
-bool WanderAffector::affectParticle(ParticleData* data, qreal dt)
+bool QSGWanderAffector::affectParticle(QSGParticleData* data, qreal dt)
{
+ /*TODO: Add a mode which does basically this - picking a direction, going in it (random speed) and then going back
WanderData* d = getData(data->systemIndex);
if (m_xVariance != 0.) {
if ((d->x_vel > d->x_peak && d->x_var > 0.0) || (d->x_vel < -d->x_peak && d->x_var < 0.0)) {
@@ -106,5 +108,37 @@ bool WanderAffector::affectParticle(ParticleData* data, qreal dt)
p->y += dy;
return true;
+ */
+ qreal dx = dt * m_pace * (2 * qreal(qrand())/RAND_MAX - 1);
+ qreal dy = dt * m_pace * (2 * qreal(qrand())/RAND_MAX - 1);
+ qreal newX, newY;
+ switch(m_physics){
+ case Position:
+ newX = data->curX() + dx;
+ if(m_xVariance > qAbs(newX) )
+ data->x += dx;
+ newY = data->curY() + dy;
+ if(m_yVariance > qAbs(newY) )
+ data->y += dy;
+ break;
+ default:
+ case Velocity:
+ newX = data->curSX() + dx;
+ if(m_xVariance > qAbs(newX) )
+ data->setInstantaneousSX(newX);
+ newY = data->curSY() + dy;
+ if(m_yVariance > qAbs(newY) )
+ data->setInstantaneousSY(newY);
+ break;
+ case Acceleration:
+ newX = data->ax + dx;
+ if(m_xVariance > qAbs(newX) )
+ data->setInstantaneousAX(newX);
+ newY = data->ay + dy;
+ if(m_yVariance > qAbs(newY) )
+ data->setInstantaneousAY(newY);
+ break;
+ }
+ return true;
}
QT_END_NAMESPACE
diff --git a/src/imports/particles/wanderaffector.h b/src/declarative/particles/qsgwander_p.h
index 612872830b..783efc8636 100644
--- a/src/imports/particles/wanderaffector.h
+++ b/src/declarative/particles/qsgwander_p.h
@@ -42,7 +42,7 @@
#ifndef WANDERAFFECTOR_H
#define WANDERAFFECTOR_H
#include <QHash>
-#include "particleaffector.h"
+#include "qsgparticleaffector_p.h"
QT_BEGIN_HEADER
@@ -51,8 +51,6 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class SpriteEmitter;
-
struct WanderData{
qreal x_vel;
qreal y_vel;
@@ -62,16 +60,24 @@ struct WanderData{
qreal y_var;
};
-class WanderAffector : public ParticleAffector
+class QSGWanderAffector : public QSGParticleAffector
{
Q_OBJECT
+ Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged)
Q_PROPERTY(qreal xVariance READ xVariance WRITE setXVariance NOTIFY xVarianceChanged)
Q_PROPERTY(qreal yVariance READ yVariance WRITE setYVariance NOTIFY yVarianceChanged)
- Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged)
+ Q_PROPERTY(PhysicsAffects physics READ physics WRITE setPhysics NOTIFY physicsChanged)
+ Q_ENUMS(PhysicsAffects)
public:
- explicit WanderAffector(QSGItem *parent = 0);
- ~WanderAffector();
+ enum PhysicsAffects {
+ Position,
+ Velocity,
+ Acceleration
+ };
+
+ explicit QSGWanderAffector(QSGItem *parent = 0);
+ ~QSGWanderAffector();
virtual void reset(int systemIdx);
qreal xVariance() const
@@ -88,8 +94,14 @@ public:
{
return m_pace;
}
+
+ PhysicsAffects physics() const
+ {
+ return m_physics;
+ }
+
protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
signals:
void xVarianceChanged(qreal arg);
@@ -98,6 +110,9 @@ signals:
void paceChanged(qreal arg);
+
+ void physicsChanged(PhysicsAffects arg);
+
public slots:
void setXVariance(qreal arg)
{
@@ -123,12 +138,22 @@ void setPace(qreal arg)
}
}
+
+void setPhysics(PhysicsAffects arg)
+{
+ if (m_physics != arg) {
+ m_physics = arg;
+ emit physicsChanged(arg);
+ }
+}
+
private:
WanderData* getData(int idx);
QHash<int, WanderData*> m_wanderData;
qreal m_xVariance;
qreal m_yVariance;
qreal m_pace;
+ PhysicsAffects m_physics;
};
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index 72010c0ef2..43bb58c88a 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -650,6 +650,7 @@ bool QDeclarativeCompiler::compile(QDeclarativeEngine *engine,
out->dumpInstructions();
if (compilerStatDump())
dumpStats();
+ Q_ASSERT(out->rootPropertyCache);
} else {
reset(out);
}
@@ -1230,6 +1231,11 @@ void QDeclarativeCompiler::genComponent(QDeclarativeParser::Object *obj)
id.setId.index = obj->idIndex;
output->addInstruction(id);
}
+
+ if (obj == unitRoot) {
+ output->rootPropertyCache = output->types[obj->type].createPropertyCache(engine);
+ output->rootPropertyCache->addref();
+ }
}
bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj,
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 4f9e6e3af8..906af83778 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -106,6 +106,7 @@
#include <private/qdeclarativeitemsmodule_p.h>
#include <private/qdeclarativeutilmodule_p.h>
#include <private/qsgitemsmodule_p.h>
+#include <private/qsgparticlesmodule_p.h>
#include <qsgtexture.h>
#ifdef Q_OS_WIN // for %APPDATA%
@@ -362,6 +363,7 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e)
QDeclarativeUtilModule::defineModule();
QDeclarativeEnginePrivate::defineModule();
QSGItemsModule::defineModule();
+ QSGParticlesModule::defineModule();
QDeclarativeValueTypeFactory::registerValueTypes();
}
globalClass = new QDeclarativeGlobalScriptClass(&scriptEngine);
diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp
index a9b303c94f..8959f1775f 100644
--- a/src/declarative/qml/qdeclarativevme.cpp
+++ b/src/declarative/qml/qdeclarativevme.cpp
@@ -988,6 +988,7 @@ QScriptValue QDeclarativeVME::run(QDeclarativeContextData *parentCtxt, QDeclarat
ctxt->imports = script->importCache;
} else {
ctxt->imports = parentCtxt->imports;
+ ctxt->importedScripts = parentCtxt->importedScripts;
}
if (ctxt->imports) {
diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
index 83b7d170a4..f74995ba0a 100644
--- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp
+++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
@@ -1163,10 +1163,12 @@ void QDeclarativeXMLHttpRequest::requestFromUrl(const QUrl &url)
m_network = networkAccessManager()->get(request);
else if (m_method == QLatin1String("HEAD"))
m_network = networkAccessManager()->head(request);
- else if(m_method == QLatin1String("POST"))
+ else if (m_method == QLatin1String("POST"))
m_network = networkAccessManager()->post(request, m_data);
- else if(m_method == QLatin1String("PUT"))
+ else if (m_method == QLatin1String("PUT"))
m_network = networkAccessManager()->put(request, m_data);
+ else if (m_method == QLatin1String("DELETE"))
+ m_network = networkAccessManager()->deleteResource(request);
QObject::connect(m_network, SIGNAL(downloadProgress(qint64,qint64)),
this, SLOT(downloadProgress(qint64)));
@@ -1447,7 +1449,8 @@ static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngin
if (method != QLatin1String("GET") &&
method != QLatin1String("PUT") &&
method != QLatin1String("HEAD") &&
- method != QLatin1String("POST"))
+ method != QLatin1String("POST") &&
+ method != QLatin1String("DELETE"))
THROW_DOM(SYNTAX_ERR, "Unsupported HTTP method type");
diff --git a/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp b/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp
index 1e6b6919cb..7279ff0216 100644
--- a/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp
+++ b/src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp
@@ -158,7 +158,7 @@ IndexGeometryNodePair IndexGeometryNodePairHeap::pop()
}
-QMLRenderer::QMLRenderer(QSGContext *context)
+QSGDefaultRenderer::QSGDefaultRenderer(QSGContext *context)
: QSGRenderer(context)
, m_opaqueNodes(64)
, m_transparentNodes(64)
@@ -175,7 +175,7 @@ QMLRenderer::QMLRenderer(QSGContext *context)
#endif
}
-void QMLRenderer::nodeChanged(QSGNode *node, QSGNode::DirtyFlags flags)
+void QSGDefaultRenderer::nodeChanged(QSGNode *node, QSGNode::DirtyFlags flags)
{
QSGRenderer::nodeChanged(node, flags);
@@ -190,7 +190,7 @@ void QMLRenderer::nodeChanged(QSGNode *node, QSGNode::DirtyFlags flags)
m_needs_sorting = true;
}
-void QMLRenderer::render()
+void QSGDefaultRenderer::render()
{
#if defined (QML_RUNTIME_TESTING)
static bool dumpTree = qApp->arguments().contains(QLatin1String("--dump-tree"));
@@ -336,18 +336,18 @@ void QMLRenderer::render()
}
-void QMLRenderer::setSortFrontToBackEnabled(bool sort)
+void QSGDefaultRenderer::setSortFrontToBackEnabled(bool sort)
{
printf("setting sorting to... %d\n", sort);
m_sort_front_to_back = sort;
}
-bool QMLRenderer::isSortFrontToBackEnabled() const
+bool QSGDefaultRenderer::isSortFrontToBackEnabled() const
{
return m_sort_front_to_back;
}
-void QMLRenderer::buildLists(QSGNode *node)
+void QSGDefaultRenderer::buildLists(QSGNode *node)
{
if (node->isSubtreeBlocked())
return;
@@ -420,7 +420,7 @@ void QMLRenderer::buildLists(QSGNode *node)
}
}
-void QMLRenderer::renderNodes(const QDataBuffer<QSGGeometryNode *> &list)
+void QSGDefaultRenderer::renderNodes(const QDataBuffer<QSGGeometryNode *> &list)
{
const float scale = 1.0f / m_currentRenderOrder;
int count = list.size();
diff --git a/src/declarative/scenegraph/coreapi/qsgdefaultrenderer_p.h b/src/declarative/scenegraph/coreapi/qsgdefaultrenderer_p.h
index dc2d089391..f2adb00391 100644
--- a/src/declarative/scenegraph/coreapi/qsgdefaultrenderer_p.h
+++ b/src/declarative/scenegraph/coreapi/qsgdefaultrenderer_p.h
@@ -77,11 +77,11 @@ private:
};
-class QMLRenderer : public QSGRenderer
+class QSGDefaultRenderer : public QSGRenderer
{
Q_OBJECT
public:
- QMLRenderer(QSGContext *context);
+ QSGDefaultRenderer(QSGContext *context);
void render();
diff --git a/src/declarative/scenegraph/coreapi/qsgnode.cpp b/src/declarative/scenegraph/coreapi/qsgnode.cpp
index fa720a3b72..b295d25b70 100644
--- a/src/declarative/scenegraph/coreapi/qsgnode.cpp
+++ b/src/declarative/scenegraph/coreapi/qsgnode.cpp
@@ -174,6 +174,17 @@ bool QSGNode::isSubtreeBlocked() const
return m_subtreeGeometryCount == 0;
}
+/*!
+ \internal
+ Detaches the node from the scene graph and deletes any children it owns.
+
+ This function is called from QSGNode's and QSGRootNode's destructor. It
+ should not be called explicitly in user code. QSGRootNode needs to call
+ destroy() because destroy() calls removeChildNode() which in turn calls
+ markDirty() which type-casts the node to QSGRootNode. This type-cast is not
+ valid at the time QSGNode's destructor is called because the node will
+ already be partially destroyed at that point.
+*/
void QSGNode::destroy()
{
@@ -447,9 +458,9 @@ void QSGNode::markDirty(DirtyFlags flags)
int geometryCountDiff = 0;
if (flags & DirtyNodeAdded)
- geometryCountDiff = m_subtreeGeometryCount;
+ geometryCountDiff += m_subtreeGeometryCount;
if (flags & DirtyNodeRemoved)
- geometryCountDiff = -m_subtreeGeometryCount;
+ geometryCountDiff -= m_subtreeGeometryCount;
QSGNode *p = m_parent;
while (p) {
@@ -493,7 +504,6 @@ QSGBasicGeometryNode::QSGBasicGeometryNode(NodeType type)
QSGBasicGeometryNode::~QSGBasicGeometryNode()
{
- destroy();
if (flags() & OwnsGeometry)
delete m_geometry;
}
@@ -569,7 +579,6 @@ QSGGeometryNode::QSGGeometryNode()
QSGGeometryNode::~QSGGeometryNode()
{
- destroy();
if (flags() & OwnsMaterial)
delete m_material;
if (flags() & OwnsOpaqueMaterial)
@@ -731,7 +740,6 @@ QSGClipNode::QSGClipNode()
QSGClipNode::~QSGClipNode()
{
- destroy();
}
@@ -807,7 +815,6 @@ QSGTransformNode::QSGTransformNode()
QSGTransformNode::~QSGTransformNode()
{
- destroy();
}
@@ -881,7 +888,7 @@ QSGRootNode::~QSGRootNode()
{
while (!m_renderers.isEmpty())
m_renderers.last()->setRootNode(0);
- destroy();
+ destroy(); // Must call destroy() here because markDirty() casts this to QSGRootNode.
}
@@ -940,7 +947,6 @@ QSGOpacityNode::QSGOpacityNode()
QSGOpacityNode::~QSGOpacityNode()
{
- destroy();
}
diff --git a/src/declarative/scenegraph/coreapi/qsgnode.h b/src/declarative/scenegraph/coreapi/qsgnode.h
index 2705958e04..80def63f21 100644
--- a/src/declarative/scenegraph/coreapi/qsgnode.h
+++ b/src/declarative/scenegraph/coreapi/qsgnode.h
@@ -82,11 +82,9 @@ public:
DirtyNodeAdded = 0x0004,
DirtyNodeRemoved = 0x0008,
DirtyGeometry = 0x0010,
- DirtyRenderOrder = 0x0020,
DirtyMaterial = 0x0040,
DirtyOpacity = 0x0080,
DirtyForceUpdate = 0x0100,
- DirtyAll = 0xffff,
DirtyPropagationMask = DirtyMatrix
| DirtyClipList
@@ -152,16 +150,11 @@ public:
protected:
QSGNode(NodeType type);
- // When a node is destroyed, it will detach from the scene graph and the renderer will be
- // notified about the change. If the node is detached in the base node's destructor, the
- // renderer can't safely cast the node to its original type, since at this point it has been
- // partly destroyed already. To solve this problem, all the node destructors must call a common
- // destroy method.
-
- void destroy();
-
private:
+ friend class QSGRootNode;
+
void init();
+ void destroy();
QSGNode *m_parent;
NodeType m_type;
diff --git a/src/declarative/scenegraph/coreapi/qsgrenderer.cpp b/src/declarative/scenegraph/coreapi/qsgrenderer.cpp
index c6afb3154b..48c34d39dd 100644
--- a/src/declarative/scenegraph/coreapi/qsgrenderer.cpp
+++ b/src/declarative/scenegraph/coreapi/qsgrenderer.cpp
@@ -229,6 +229,21 @@ void QSGRenderer::renderScene(const Bindable &bindable)
int bindTime = frameTimer.elapsed();
#endif
+#ifndef QT_NO_DEBUG
+ // Sanity check that attribute registers are disabled
+ {
+ GLint count;
+ glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &count);
+ GLint enabled;
+ for (int i=0; i<count; ++i) {
+ glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled);
+ if (enabled) {
+ qWarning("QSGRenderer: attribute %d is enabled, this can lead to memory corruption and crashes.", i);
+ }
+ }
+ }
+#endif
+
render();
#ifdef QSG_RENDERER_TIMING
int renderTime = frameTimer.elapsed();
@@ -278,6 +293,14 @@ void QSGRenderer::setClearColor(const QColor &color)
m_clear_color = color;
}
+/*!
+ Updates internal data structures and emits the sceneGraphChanged() signal.
+
+ If \a flags contains the QSGNode::DirtyNodeRemoved flag, the node might be
+ in the process of being destroyed. It is then not safe to downcast the node
+ pointer.
+*/
+
void QSGRenderer::nodeChanged(QSGNode *node, QSGNode::DirtyFlags flags)
{
Q_UNUSED(node);
diff --git a/src/declarative/scenegraph/qsgcontext.cpp b/src/declarative/scenegraph/qsgcontext.cpp
index 616474748d..682b514b9c 100644
--- a/src/declarative/scenegraph/qsgcontext.cpp
+++ b/src/declarative/scenegraph/qsgcontext.cpp
@@ -307,7 +307,7 @@ QSGRenderer *QSGContext::createRenderer()
{
// ### Do something with this before release...
static bool doFrontToBack = qApp->arguments().contains(QLatin1String("--opaque-front-to-back"));
- QMLRenderer *renderer = new QMLRenderer(this);
+ QSGDefaultRenderer *renderer = new QSGDefaultRenderer(this);
if (doFrontToBack) {
printf("QSGContext: Sorting opaque nodes front to back...\n");
renderer->setSortFrontToBackEnabled(true);
diff --git a/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp b/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp
index 0011492053..c63ff9d4cc 100644
--- a/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp
+++ b/src/declarative/scenegraph/qsgdistancefieldglyphcache.cpp
@@ -912,8 +912,9 @@ void QSGDistanceFieldGlyphCache::updateCache()
if (m_textureData->pendingGlyphs.isEmpty())
return;
- int requiredWidth = m_textureData->currY == 0 ? m_textureData->currX : maxTextureSize();
- int requiredHeight = qMin(maxTextureSize(), m_textureData->currY + QT_DISTANCEFIELD_TILESIZE);
+ int requiredWidth = maxTextureSize();
+ int rows = 128 / (requiredWidth / QT_DISTANCEFIELD_TILESIZE); // Enough rows to fill the latin1 set by default..
+ int requiredHeight = qMin(maxTextureSize(), qMax(m_textureData->currY + QT_DISTANCEFIELD_TILESIZE, QT_DISTANCEFIELD_TILESIZE * rows));
resizeTexture((requiredWidth), (requiredHeight));
glBindTexture(GL_TEXTURE_2D, m_textureData->texture);
@@ -941,7 +942,7 @@ void QSGDistanceFieldGlyphCache::updateCache()
QFile file(key);
if (file.open(QFile::ReadOnly)) {
int fileSize = file.size();
- int dim = sqrt(fileSize);
+ int dim = sqrt(float(fileSize));
QByteArray blob = file.readAll();
glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, dim, dim, GL_ALPHA, GL_UNSIGNED_BYTE, blob.constData());
continue;
diff --git a/src/declarative/scenegraph/qsgdistancefieldglyphnode.cpp b/src/declarative/scenegraph/qsgdistancefieldglyphnode.cpp
index d826f7f1e7..4686067bd7 100644
--- a/src/declarative/scenegraph/qsgdistancefieldglyphnode.cpp
+++ b/src/declarative/scenegraph/qsgdistancefieldglyphnode.cpp
@@ -124,9 +124,32 @@ void QSGDistanceFieldGlyphNode::updateGeometry()
m_glyph_cache->populate(glyphIndexes.count(), glyphIndexes.constData());
Q_ASSERT(g->indexType() == GL_UNSIGNED_SHORT);
- g->allocate(glyphIndexes.size() * 4, glyphIndexes.size() * 6);
- QVector4D *vp = (QVector4D *)g->vertexData();
- ushort *ip = g->indexDataAsUShort();
+
+ int oldVertexCount = g->vertexCount();
+ int oldIndexCount = g->indexCount();
+
+ // We could potentially move the realloc part into the QSGGeometry object as a
+ // grow() function...
+
+ void *data = 0;
+ if (oldVertexCount && oldIndexCount) {
+ int byteSize = oldVertexCount * sizeof(QSGGeometry::TexturedPoint2D)
+ + oldIndexCount * sizeof(quint16);
+ data = qMalloc(byteSize);
+ memcpy(data, g->vertexData(), byteSize);
+ }
+
+ g->allocate(oldVertexCount + glyphIndexes.size() * 4, oldIndexCount + glyphIndexes.size() * 6);
+
+ if (data) {
+ memcpy(g->vertexData(), data, oldVertexCount * sizeof(QSGGeometry::TexturedPoint2D));
+ memcpy(g->indexData(), ((char *) data) + oldVertexCount * sizeof(QSGGeometry::TexturedPoint2D),
+ oldIndexCount * sizeof(quint16));
+ qFree(data);
+ }
+
+ QSGGeometry::TexturedPoint2D *vp = g->vertexDataAsTexturedPoint2D() + oldVertexCount;
+ ushort *ip = g->indexDataAsUShort() + oldIndexCount;
QPointF margins(2, 2);
QPointF texMargins = margins / m_glyph_cache->fontScale();
@@ -167,12 +190,12 @@ void QSGDistanceFieldGlyphNode::updateGeometry()
m_baseLine = glyphPosition;
int vi = i & 1 ? (glyphIndexes.size() + 1) / 2 + i / 2 : i / 2;
- vp[4 * vi + 0] = QVector4D(cx1, cy1, tx1, ty1);
- vp[4 * vi + 1] = QVector4D(cx2, cy1, tx2, ty1);
- vp[4 * vi + 2] = QVector4D(cx1, cy2, tx1, ty2);
- vp[4 * vi + 3] = QVector4D(cx2, cy2, tx2, ty2);
+ vp[4 * vi + 0].set(cx1, cy1, tx1, ty1);
+ vp[4 * vi + 1].set(cx2, cy1, tx2, ty1);
+ vp[4 * vi + 2].set(cx1, cy2, tx1, ty2);
+ vp[4 * vi + 3].set(cx2, cy2, tx2, ty2);
- int o = i * 4;
+ int o = i * 4 + oldVertexCount;
ip[6 * i + 0] = o + 0;
ip[6 * i + 1] = o + 2;
ip[6 * i + 2] = o + 3;
@@ -181,6 +204,25 @@ void QSGDistanceFieldGlyphNode::updateGeometry()
ip[6 * i + 5] = o + 0;
}
+// printf("Vertices:\n");
+// for (int v=0; v<g->vertexCount(); ++v) {
+// QSGGeometry::TexturedPoint2D *t = g->vertexDataAsTexturedPoint2D() + v;
+// printf(" - %d -- %f %f -- %.3f %.3f\n", v, t->x, t->y, t->tx, t->ty);
+// }
+
+// printf("Indices:\n");
+// for (int i=0; i<g->indexCount();) {
+
+// printf(" - %[ ", i);
+// printf("%d, ", g->indexDataAsUShort()[i++]);
+// printf("%d, ", g->indexDataAsUShort()[i++]);
+// printf("%d, ", g->indexDataAsUShort()[i++]);
+// printf("%d, ", g->indexDataAsUShort()[i++]);
+// printf("%d, ", g->indexDataAsUShort()[i++]);
+// printf("%d", g->indexDataAsUShort()[i++]);
+// printf(" ]\n");
+// }
+
setBoundingRect(boundingRect);
markDirty(DirtyGeometry);
}
diff --git a/src/declarative/util/qdeclarativechangeset.cpp b/src/declarative/util/qdeclarativechangeset.cpp
new file mode 100644
index 0000000000..d9a508ba13
--- /dev/null
+++ b/src/declarative/util/qdeclarativechangeset.cpp
@@ -0,0 +1,440 @@
+/****************************************************************************
+**
+** 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 QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativechangeset_p.h"
+
+void QDeclarativeChangeSet::insertInsert(int start, int end)
+{
+ const int count = end - start;
+
+ // Moved signals.
+ QVector<Move>::iterator move = m_moves.begin();
+ for (; move != m_moves.end() && start >= move->maximum(); ++move) {}
+ for (; move != m_moves.end() && end >= move->minimum(); ++move) {
+ if (start <= move->tstart) {
+ move->tstart += count;
+ move->tend += count;
+ } else if (start < move->tend) {
+ int relativeStart = start - move->tstart;
+
+ move = m_moves.insert(move, Move(
+ move->fstart + count, move->fstart + count + relativeStart, move->tstart));
+ ++move;
+ move->fstart += relativeStart;
+ move->tstart += count + relativeStart;
+ move->tend += count;
+
+ start -= relativeStart;
+ end -= relativeStart;
+ } else {
+ start -= move->count();
+ end -= move->count();
+ }
+
+ if (start <= move->fstart) {
+ move->fstart += count;
+ move->fend += count;
+ } else if (start < move->tstart) {
+ start += move->count();
+ end += move->count();
+ }
+
+ }
+ for (; move != m_moves.end(); ++move) {
+ move->fstart += count;
+ move->fend += count;
+ move->tstart += count;
+ move->tend += count;
+ }
+
+ // Inserted signals.
+ QVector<Insert>::iterator insert = m_inserts.begin();
+ for (; insert != m_inserts.end(); ++insert) {
+ if (start < insert->start) {
+ insert = m_inserts.insert(insert, Insert(start, end));
+ break;
+ } else if (start <= insert->end) {
+ insert->end += count;
+ break;
+ }
+ }
+ if (insert == m_inserts.end()) {
+ m_inserts.append(Insert(start, end));
+ } else for (++insert; insert != m_inserts.end(); ++insert) {
+ insert->start += count;
+ insert->end += count;
+ }
+
+
+ // Changed signals.
+ QVector<Change>::iterator change = m_changes.begin();
+ for (; change != m_changes.end() && start != change->start && start < change->end; ++change) {
+ if (start > change->start) {
+ int relativeStart = start - change->start;
+ change = m_changes.insert(change, Change(change->start, change->start + relativeStart));
+ ++change;
+ change->start += count + relativeStart;
+ change->end += count - relativeStart;
+ break;
+ }
+ }
+ for (; change != m_changes.end(); ++change) {
+ change->start += count;
+ change->end += count;
+ }
+}
+
+void QDeclarativeChangeSet::insertRemove(int start, int end)
+{
+ // Changed Signals.
+ QVector<Change>::iterator change = m_changes.begin();
+ for (; change != m_changes.end() && start >= change->end; ++change) {}
+ for (; change != m_changes.end() && end < change->start; ++change) {
+ const int removeCount = qMin(change->end, end) - qMax(change->start, start);
+ change->end -= removeCount;
+ if (change->start == change->end) {
+ change = m_changes.erase(change);
+ } else if (start < change->start) {
+ change->start = start;
+ }
+ }
+ const int count = end - start;
+ for (; change != m_changes.end(); ++change) {
+ change->start -= count;
+ change->end -= count;
+ }
+
+ QVector<Remove> removeChanges;
+
+ // Moved signals.
+ QVector<Move>::iterator move = m_moves.begin();
+ for (; move != m_moves.end() && start >= move->maximum(); ++move) {}
+ for (; move != m_moves.end() && end >= move->minimum(); ++move) {
+ if (move->fstart < move->tstart) {
+ if (start < move->fstart) {
+ const int difference = move->fstart - start;
+ move->fend -= difference;
+ move->fstart = start;
+ move->tstart -= difference;
+ move->tend -= difference;
+
+ removeChanges.append(Remove(start, start + difference));
+ end -= difference;
+ }
+ if (end < move->tstart) {
+ move->tstart -= end - start;
+ move->tend -= end - start;
+ } else if (start < move->tend) {
+ const int difference = qMin(move->tend, end) - move->tstart;
+ removeChanges.append(Remove(
+ move->fstart , move->fstart + difference));
+ end -= difference;
+
+ move->fend -= difference;
+ move->tstart -= end - start;
+ move->tend -= end - start + difference;
+ }
+ start += move->count();
+ end += move->count();
+ } else {
+ if (start < move->tend) {
+ const int offset = qMax(0, start - move->tstart);
+ const int difference = qMin(move->tend, end) - qMax(move->tstart, start);
+
+ removeChanges.append(Remove(
+ move->fstart + offset, move->fstart + offset + difference));
+ start -= offset;
+ end -= offset + difference;
+
+ move->fend -= difference;
+ move->tstart = start;
+ move->tend = start + move->fend - move->fstart;
+ } else {
+ start -= move->count();
+ end -= move->count();
+ }
+
+ move->fstart -= end - start;
+ move->fend -= end - start;
+
+ if (start > move->fstart) {
+ const int offset = start - move->fstart;
+ const int difference = qMin(move->fend, end) - start;
+ removeChanges.append(Remove(
+ move->fstart + end - start + offset + difference ,
+ move->fend + end - start + offset));
+ end -= offset;
+ move->fstart += offset;
+ move->fend += offset;
+ }
+ }
+
+ if (move->tstart == move->tend || move->fstart == move->tstart) {
+ move = m_moves.erase(move);
+ --move;
+ }
+ }
+ for (; move != m_moves.end(); ++move) {
+ move->fstart -= count;
+ move->fend -= count;
+ move->tstart -= count;
+ move->tend -= count;
+ }
+
+ if (start != end)
+ removeChanges.append(Remove(start, end));
+
+ foreach (const Remove &r, removeChanges) {
+ int start = r.start;
+ int end = r.end;
+
+ QVector<Insert>::iterator insert = m_inserts.end() - 1;
+ for (const int count = end - start; insert != m_inserts.begin() - 1 && insert->start >= end; --insert) {
+ insert->start -= count;
+ insert->end -= count;
+ }
+ for (; insert != m_inserts.begin() - 1 && insert->end > start; --insert) {
+ const int removeCount = qMin(insert->end, end) - qMax(insert->start, start);
+ insert->end -= removeCount;
+ if (insert->start == insert->end) {
+ insert = m_inserts.erase(insert);
+ } else if (start < insert->start) {
+ insert->end -= insert->start - start;
+ insert->start = start;
+ } else {
+ start -= insert->count();
+ end -= insert->count();
+ }
+ end -= removeCount;
+ if (start == end)
+ return;
+ }
+ // Adjust the index to compensate for any inserts prior to the remove position..
+ for (; insert != m_inserts.begin() - 1; --insert) {
+ start -= insert->count();
+ end -= insert->count();
+ }
+
+ // Removed signals.
+ QVector<Remove>::iterator remove = m_removes.begin();
+ for (; remove != m_removes.end(); ++remove) {
+ if (end < remove->start) {
+ remove = m_removes.insert(remove, Remove(start, end));
+ break;
+ } else if (start <= remove->start) {
+ remove->end += end - remove->start;
+ remove->start = start;
+
+ QVector<Remove>::iterator rbegin = remove;
+ QVector<Remove>::iterator rend = ++rbegin;
+ for (; rend != m_removes.end() && rend->start <= remove->end; ++rend)
+ remove->end += rend->count();
+ if (rbegin != rend) {
+ remove = m_removes.erase(rbegin, rend);
+ }
+ break;
+ }
+ }
+ if (remove != m_removes.end()) {
+ const int count = end - start;
+ for (++remove; remove != m_removes.end(); ++remove) {
+ remove->start -= count;
+ remove->end -= count;
+ }
+ } else {
+ m_removes.append(Remove(start, end));
+ }
+ }
+}
+
+void QDeclarativeChangeSet::insertMove(int start, int end, int to)
+{
+ QVector<Insert> insertChanges;
+ QVector<Move> moveChanges;
+
+ int fStart = start;
+ int fTo = to;
+ int fEnd = end;
+ int &bStart = fTo;
+ int bEnd = to + end - start;
+
+ if (start > to) {
+ qSwap(fStart, bStart);
+ qSwap(fEnd, bEnd);
+ }
+
+ // Inserted signals.
+ QVector<Insert>::iterator insert = m_inserts.begin();
+ if (start < to) {
+ for (; insert != m_inserts.end() && fStart >= insert->end; ++insert) {}
+ for (; insert != m_inserts.end() && fEnd > insert->start; ++insert) {
+ const int removeCount = qMin(insert->end, fEnd) - qMax(insert->start, fStart);
+ const int relativeStart = fStart - insert->start;
+ const int relativeEnd = qMax(0, fEnd - insert->end);
+
+ insert->end -= removeCount;
+ if (insert->start == insert->end) {
+ insert = m_inserts.erase(insert);
+ --insert;
+ }
+
+ if (relativeStart < 0) {
+ moveChanges.append(Move(fStart, fStart - relativeStart, fTo + relativeEnd));
+ fTo -= relativeStart;
+ }
+
+ fTo += removeCount;
+ insertChanges.append(Insert(bEnd - removeCount, bEnd));
+ }
+ } else {
+ for (; insert != m_inserts.end() && bStart >= insert->end; ++insert) {}
+ for (; insert != m_inserts.end() && bEnd > insert->start; ++insert) {
+ const int removeCount = qMin(insert->end, bEnd) - qMax(insert->start, bStart);
+ const int relativeStart = bStart - insert->start;
+
+ insert->start += removeCount;
+ if (insert->start == insert->end) {
+ insert->start = fStart;
+ insert->end = insert->start + removeCount;
+ } else {
+ insert = m_inserts.insert(insert, Insert(fStart, fStart + removeCount));
+ ++insert;
+ }
+ if (relativeStart < 0) {
+ moveChanges.append(Move(fStart, fStart - relativeStart, fTo + removeCount));
+ fStart -= relativeStart;
+ fTo -= relativeStart;
+ }
+ fStart += removeCount;
+ fTo += removeCount;
+ }
+ }
+
+ if (fTo != bEnd)
+ moveChanges.append(Move(fStart, fStart + bEnd - fTo, fTo));
+
+ QVector<Insert>::iterator it = insertChanges.begin();
+ for (insert = m_inserts.begin(); it != insertChanges.end() && insert != m_inserts.end();++insert) {
+ if (it->start < insert->start) {
+ insert = m_inserts.insert(insert, *it);
+ ++it;
+ } else if (it->start <= insert->end) {
+ insert->end += it->count();
+ ++it;
+ }
+ }
+ for (; it != insertChanges.end(); ++it)
+ m_inserts.append(*it);
+
+ // Insert queued moved signals ordered by destination position.
+ QVector<Move>::iterator move = m_moves.begin();
+ if (start > to) {
+ for (QVector<Move>::iterator it = moveChanges.begin(); it != moveChanges.end(); ++it) {
+ it->fend += it->tstart - it->fstart;
+ it->tend -=it->tstart - it->fstart;
+ qSwap(it->fstart, it->tstart);
+ for (; move != m_moves.end() && it->to >= qMin(move->fstart, move->tstart); ++move) {}
+ move = m_moves.insert(move, *it);
+ }
+ } else {
+ for (QVector<Move>::iterator it = moveChanges.begin(); it != moveChanges.end(); ++it) {
+ for (; move != m_moves.end() && it->start >= qMin(move->fstart, move->tstart); ++move) {}
+ move = m_moves.insert(move, *it);
+ }
+ }
+}
+
+void QDeclarativeChangeSet::insertChange(int start, int end)
+{
+ QVector<Change> filteredChanges;
+
+ // Inserted signals (don't emit change signals on new items).
+ QVector<Insert>::iterator insert = m_inserts.begin();
+ for (; insert != m_inserts.end() && start >= insert->end; ++insert) {}
+ for (; insert != m_inserts.end() && end > insert->start; ++insert) {
+ if (start < insert->start)
+ filteredChanges.append(Change(start, insert->start));
+ start = insert->end;
+ }
+ if (start < end)
+ filteredChanges.append(Change(start, end));
+
+ // Find the union of the existing and filtered sets of change signals.
+ QVector<Change>::iterator change = m_changes.begin();
+ for (QVector<Change>::iterator it = filteredChanges.begin(); it != filteredChanges.end(); ++it) {
+ for (; change != m_changes.end() && change->end < it->start; ++change) {}
+ if (change == m_changes.end() || change->start > it->end) {
+ change = m_changes.insert(change, *it);
+ } else {
+ if (it->start < change->start)
+ change->start = it->start;
+
+ if (it->end > change->end) {
+ change->end = it->end;
+ QVector<Change>::iterator rbegin = change;
+ QVector<Change>::iterator rend = ++rbegin;
+ for (; rend != m_changes.end() && rend->start <= change->end; ++rend) {
+ if (rend->end > change->end)
+ change->end = rend->end;
+ }
+ if (rbegin != rend) {
+ change = m_changes.erase(rbegin, rend);
+ --change;
+ }
+ }
+ }
+ }
+
+}
+
+QDebug operator <<(QDebug debug, const QDeclarativeChangeSet &set)
+{
+ foreach (const QDeclarativeChangeSet::Remove &remove, set.removes())
+ debug.nospace() << "QDeclarativeChangeSet::Remove(" << remove.start << "," << remove.end << ")";
+ foreach (const QDeclarativeChangeSet::Insert &insert, set.inserts())
+ debug.nospace() << "QDeclarativeChangeSet::Insert(" << insert.start << "," << insert.end << ")";
+ foreach (const QDeclarativeChangeSet::Move &move, set.moves())
+ debug.nospace() << "QDeclarativeChangeSet::Move(" << move.start << "," << move.end << "," << move.to << ")";
+ foreach (const QDeclarativeChangeSet::Change &change, set.changes())
+ debug.nospace() << "QDeclarativeChangeSet::Change(" << change.start << "," << change.end << ")";
+ return debug;
+}
+
diff --git a/src/declarative/util/qdeclarativechangeset_p.h b/src/declarative/util/qdeclarativechangeset_p.h
new file mode 100644
index 0000000000..f911e658ea
--- /dev/null
+++ b/src/declarative/util/qdeclarativechangeset_p.h
@@ -0,0 +1,160 @@
+/****************************************************************************
+**
+** 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 QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVECHANGESET_P_H
+#define QDECLARATIVECHANGESET_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qdebug.h>
+#include <QtCore/qvector.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_AUTOTEST_EXPORT QDeclarativeChangeSet
+{
+public:
+ struct Insert
+ {
+ Insert() {}
+ Insert(int start, int end) : start(start), end(end) {}
+
+ int count() const { return end - start; }
+
+ int start;
+ int end;
+ };
+
+ struct Remove
+ {
+ Remove() {}
+ Remove(int start, int end) : start(start), end(end) {}
+
+ int count() const { return end - start; }
+
+ int start;
+ int end;
+ };
+
+ struct Move
+ {
+ Move() {}
+ Move(int start, int end, int to) : fstart(start), fend(end), tstart(to), tend(to + end - start) {}
+
+ int minimum() const { return qMin(fstart, tstart); }
+ int maximum() const { return qMax(fend, tend); }
+ int count() const { return fend - fstart; }
+
+ union {
+ int start;
+ int fstart;
+ };
+ union {
+ int end;
+ int fend;
+ };
+ union {
+ int to;
+ int tstart;
+ };
+ int tend;
+ };
+
+ struct Change
+ {
+ Change() {}
+ Change(int start, int end) : start(start), end(end) {}
+
+ int count() const { return end - start; }
+
+ int start;
+ int end;
+ };
+
+ const QVector<Remove> &removes() const { return m_removes; }
+ const QVector<Insert> &inserts() const { return m_inserts; }
+ const QVector<Move> &moves() const { return m_moves; }
+ const QVector<Change> &changes() const {return m_changes; }
+
+ void insertInsert(int start, int end);
+ void insertRemove(int start, int end);
+ void insertMove(int start, int end, int to);
+ void insertChange(int start, int end);
+
+ void appendInsert(int start, int end) { m_inserts.append(Insert(start, end)); }
+ void appendRemove(int start, int end) { m_removes.append(Remove(start, end)); }
+ void appendMove(int start, int end, int to) { m_moves.append(Move(start, end, to)); }
+ void appendChange(int start, int end) { m_changes.append(Change(start, end)); }
+
+ void append(const QVector<Insert> &inserts) { m_inserts += inserts; }
+ void append(const QVector<Remove> &removes) { m_removes += removes; }
+ void append(const QVector<Move> &moves) { m_moves += moves; }
+ void append(const QVector<Change> &changes) { m_changes += changes; }
+
+ void clear()
+ {
+ m_removes.clear();
+ m_inserts.clear();
+ m_moves.clear();
+ m_changes.clear();
+ }
+
+private:
+ QVector<Remove> m_removes;
+ QVector<Insert> m_inserts;
+ QVector<Move> m_moves;
+ QVector<Change> m_changes;
+};
+
+Q_AUTOTEST_EXPORT QDebug operator <<(QDebug debug, const QDeclarativeChangeSet &change);
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp
index 194dc70e10..108d2579ac 100644
--- a/src/declarative/util/qdeclarativepixmapcache.cpp
+++ b/src/declarative/util/qdeclarativepixmapcache.cpp
@@ -855,8 +855,8 @@ bool QDeclarativePixmapReply::event(QEvent *event)
if (de->texture) {
data->texture = de->texture;
data->context = de->context;
- } else
- data->pixmap = QPixmap::fromImage(de->image);
+ }
+ data->pixmap = QPixmap::fromImage(de->image);
data->implicitSize = de->implicitSize;
} else {
data->errorString = de->errorString;
@@ -1119,6 +1119,7 @@ QSGTexture *QDeclarativePixmap::texture(QSGContext *context) const
return d->texture;
else if (d->pixmapStatus == Ready) {
d->texture = context->createTexture(d->pixmap.toImage());
+ d->context = context;
return d->texture;
}
}
diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri
index 5bc8b117c0..4bd1f1bb1b 100644
--- a/src/declarative/util/util.pri
+++ b/src/declarative/util/util.pri
@@ -28,6 +28,7 @@ SOURCES += \
$$PWD/qdeclarativefontloader.cpp \
$$PWD/qdeclarativestyledtext.cpp \
$$PWD/qdeclarativelistmodelworkeragent.cpp \
+ $$PWD/qdeclarativechangeset.cpp \
$$PWD/qlistmodelinterface.cpp
HEADERS += \
@@ -63,6 +64,7 @@ HEADERS += \
$$PWD/qdeclarativefontloader_p.h \
$$PWD/qdeclarativestyledtext_p.h \
$$PWD/qdeclarativelistmodelworkeragent_p.h \
+ $$PWD/qdeclarativechangeset_p.h \
$$PWD/qlistmodelinterface_p.h
contains(QT_CONFIG, xmlpatterns) {
diff --git a/src/imports/particles/burstemitter.h b/src/imports/particles/burstemitter.h
deleted file mode 100644
index cffa7911af..0000000000
--- a/src/imports/particles/burstemitter.h
+++ /dev/null
@@ -1,67 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef BURSTEMITTER_H
-#define BURSTEMITTER_H
-
-#include "trailsemitter.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-//Convenience Class - can't do function overloads in QML?
-class BurstEmitter : public TrailsEmitter
-{
- Q_OBJECT
-public:
- explicit BurstEmitter(QSGItem* parent = 0):TrailsEmitter(parent){}
-public slots:
- void burst(int count, qreal x, qreal y);
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif
diff --git a/src/imports/particles/coloredparticle.cpp b/src/imports/particles/coloredparticle.cpp
deleted file mode 100644
index 22ef2d2eba..0000000000
--- a/src/imports/particles/coloredparticle.cpp
+++ /dev/null
@@ -1,540 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <private/qsgcontext_p.h>
-#include <private/qsgadaptationlayer_p.h>
-#include <qsgnode.h>
-#include <qsgtexturematerial.h>
-#include <qsgtexture.h>
-#include <QFile>
-#include "coloredparticle.h"
-#include "particleemitter.h"
-#include <QGLFunctions>
-#include <qsgengine.h>
-
-QT_BEGIN_NAMESPACE
-
-class ParticleTrailsMaterial : public QSGMaterial
-{
-public:
- ParticleTrailsMaterial()
- : timestamp(0)
- {
- setFlag(Blending, true);
- }
-
- ~ParticleTrailsMaterial()
- {
- delete texture;
- }
-
- virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const
- {
- return this - static_cast<const ParticleTrailsMaterial *>(other);
- }
-
- QSGTexture *texture;
-
- qreal timestamp;
-};
-
-
-class ParticleTrailsMaterialData : public QSGMaterialShader
-{
-public:
- ParticleTrailsMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
- {
- QFile vf(vertexFile ? vertexFile : ":resources/trailsvertex.shader");
- vf.open(QFile::ReadOnly);
- m_vertex_code = vf.readAll();
-
- QFile ff(fragmentFile ? fragmentFile : ":resources/trailsfragment.shader");
- ff.open(QFile::ReadOnly);
- m_fragment_code = ff.readAll();
-
- Q_ASSERT(!m_vertex_code.isNull());
- Q_ASSERT(!m_fragment_code.isNull());
- }
-
- void deactivate() {
- QSGMaterialShader::deactivate();
-
- for (int i=0; i<8; ++i) {
- program()->setAttributeArray(i, GL_FLOAT, chunkOfBytes, 1, 0);
- }
- }
-
- virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
- {
- ParticleTrailsMaterial *m = static_cast<ParticleTrailsMaterial *>(newEffect);
- state.context()->functions()->glActiveTexture(GL_TEXTURE0);
- m->texture->bind();
-
- program()->setUniformValue(m_opacity_id, state.opacity());
- program()->setUniformValue(m_timestamp_id, (float) m->timestamp);
-
- if (state.isMatrixDirty())
- program()->setUniformValue(m_matrix_id, state.combinedMatrix());
- }
-
- virtual void initialize() {
- m_matrix_id = program()->uniformLocation("matrix");
- m_opacity_id = program()->uniformLocation("opacity");
- m_timestamp_id = program()->uniformLocation("timestamp");
- }
-
- virtual const char *vertexShader() const { return m_vertex_code.constData(); }
- virtual const char *fragmentShader() const { return m_fragment_code.constData(); }
-
- virtual char const *const *attributeNames() const {
- static const char *attr[] = {
- "vPos",
- "vTex",
- "vData",
- "vVec",
- "vColor",
- 0
- };
- return attr;
- }
-
- virtual bool isColorTable() const { return false; }
-
- int m_matrix_id;
- int m_opacity_id;
- int m_timestamp_id;
-
- QByteArray m_vertex_code;
- QByteArray m_fragment_code;
-
- static float chunkOfBytes[1024];
-};
-float ParticleTrailsMaterialData::chunkOfBytes[1024];
-
-
-QSGMaterialShader *ParticleTrailsMaterial::createShader() const
-{
- return new ParticleTrailsMaterialData;
-}
-
-
-class ParticleTrailsMaterialCT : public ParticleTrailsMaterial
-{
-public:
- ParticleTrailsMaterialCT()
- {
- }
-
- ~ParticleTrailsMaterialCT()
- {
- delete colortable;
- delete sizetable;
- delete opacitytable;
- }
-
- virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
- virtual QSGMaterialShader *createShader() const;
-
- QSGTexture *colortable;
- QSGTexture *sizetable;
- QSGTexture *opacitytable;
-};
-
-
-class ParticleTrailsMaterialDataCT : public ParticleTrailsMaterialData
-{
-public:
- ParticleTrailsMaterialDataCT()
- : ParticleTrailsMaterialData(":resources/ctvertex.shader", ":resources/ctfragment.shader")
- {
- }
-
- bool isColorTable() const { return true; }
-
- virtual void initialize() {
- ParticleTrailsMaterialData::initialize();
- m_colortable_id = program()->uniformLocation("colortable");
- m_sizetable_id = program()->uniformLocation("sizetable");
- m_opacitytable_id = program()->uniformLocation("opacitytable");
- }
-
- virtual void updateState(const RenderState &state, QSGMaterial *current, QSGMaterial *old)
- {
- // Bind the texture to unit 1 before calling the base class, so that the
- // base class can set active texture back to 0.
- ParticleTrailsMaterialCT *m = static_cast<ParticleTrailsMaterialCT *>(current);
- state.context()->functions()->glActiveTexture(GL_TEXTURE1);
- m->colortable->bind();
- program()->setUniformValue(m_colortable_id, 1);
-
- state.context()->functions()->glActiveTexture(GL_TEXTURE2);
- m->sizetable->bind();
- program()->setUniformValue(m_sizetable_id, 2);
-
- state.context()->functions()->glActiveTexture(GL_TEXTURE3);
- m->opacitytable->bind();
- program()->setUniformValue(m_opacitytable_id, 3);
-
- ParticleTrailsMaterialData::updateState(state, current, old);
- }
-
- int m_colortable_id;
- int m_sizetable_id;
- int m_opacitytable_id;
-};
-
-
-QSGMaterialShader *ParticleTrailsMaterialCT::createShader() const
-{
- return new ParticleTrailsMaterialDataCT;
-}
-
-ColoredParticle::ColoredParticle(QSGItem* parent)
- : ParticleType(parent)
- , m_do_reset(false)
- , m_color(Qt::white)
- , m_color_variation(0.5)
- , m_node(0)
- , m_material(0)
- , m_alphaVariation(0.0)
- , m_alpha(1.0)
- , m_redVariation(0.0)
- , m_greenVariation(0.0)
- , m_blueVariation(0.0)
-{
- setFlag(ItemHasContents);
-}
-
-void ColoredParticle::setImage(const QUrl &image)
-{
- if (image == m_image_name)
- return;
- m_image_name = image;
- emit imageChanged();
- reset();
-}
-
-
-void ColoredParticle::setColortable(const QUrl &table)
-{
- if (table == m_colortable_name)
- return;
- m_colortable_name = table;
- emit colortableChanged();
- reset();
-}
-
-void ColoredParticle::setSizetable(const QUrl &table)
-{
- if (table == m_sizetable_name)
- return;
- m_sizetable_name = table;
- emit sizetableChanged();
- reset();
-}
-
-void ColoredParticle::setOpacitytable(const QUrl &table)
-{
- if (table == m_opacitytable_name)
- return;
- m_opacitytable_name = table;
- emit opacitytableChanged();
- reset();
-}
-
-void ColoredParticle::setColor(const QColor &color)
-{
- if (color == m_color)
- return;
- m_color = color;
- emit colorChanged();
- //m_system->pleaseReset();//XXX
-}
-
-void ColoredParticle::setColorVariation(qreal var)
-{
- if (var == m_color_variation)
- return;
- m_color_variation = var;
- emit colorVariationChanged();
- //m_system->pleaseReset();//XXX
-}
-
-void ColoredParticle::setCount(int c)
-{
- ParticleType::setCount(c);
- m_pleaseReset = true;
-}
-
-void ColoredParticle::reset()
-{
- ParticleType::reset();
- m_pleaseReset = true;
-}
-
-static QSGGeometry::Attribute ColoredParticle_Attributes[] = {
- { 0, 2, GL_FLOAT }, // Position
- { 1, 2, GL_FLOAT }, // TexCoord
- { 2, 4, GL_FLOAT }, // Data
- { 3, 4, GL_FLOAT }, // Vectors
- { 4, 4, GL_UNSIGNED_BYTE } // Colors
-};
-
-static QSGGeometry::AttributeSet ColoredParticle_AttributeSet =
-{
- 5, // Attribute Count
- (2 + 2 + 4 + 4) * sizeof(float) + 4 * sizeof(uchar),
- ColoredParticle_Attributes
-};
-
-QSGGeometryNode* ColoredParticle::buildParticleNode()
-{
- if (m_count * 4 > 0xffff) {
- printf("ColoredParticle: Too many particles... \n");
- return 0;
- }
-
- if(m_count <= 0) {
- printf("ColoredParticle: Too few particles... \n");
- return 0;
- }
-
- QImage image(m_image_name.toLocalFile());
- if (image.isNull()) {
- printf("ParticleTrails: loading image failed... '%s'\n", qPrintable(m_image_name.toLocalFile()));
- return 0;
- }
-
- int vCount = m_count * 4;
- int iCount = m_count * 6;
-
- QSGGeometry *g = new QSGGeometry(ColoredParticle_AttributeSet, vCount, iCount);
- g->setDrawingMode(GL_TRIANGLES);
-
- ColoredParticleVertex *vertices = (ColoredParticleVertex *) g->vertexData();
- for (int p=0; p<m_count; ++p) {
-
- for (int i=0; i<4; ++i) {
- vertices[i].x = 0;
- vertices[i].y = 0;
- vertices[i].t = -1;
- vertices[i].lifeSpan = 0;
- vertices[i].size = 0;
- vertices[i].endSize = 0;
- vertices[i].sx = 0;
- vertices[i].sy = 0;
- vertices[i].ax = 0;
- vertices[i].ay = 0;
- }
-
- vertices[0].tx = 0;
- vertices[0].ty = 0;
-
- vertices[1].tx = 1;
- vertices[1].ty = 0;
-
- vertices[2].tx = 0;
- vertices[2].ty = 1;
-
- vertices[3].tx = 1;
- vertices[3].ty = 1;
-
- vertices += 4;
- }
-
- quint16 *indices = g->indexDataAsUShort();
- for (int i=0; i<m_count; ++i) {
- int o = i * 4;
- indices[0] = o;
- indices[1] = o + 1;
- indices[2] = o + 2;
- indices[3] = o + 1;
- indices[4] = o + 3;
- indices[5] = o + 2;
- indices += 6;
- }
-
- if (m_material) {
- delete m_material;
- m_material = 0;
- }
-
- QImage colortable(m_colortable_name.toLocalFile());
- QImage sizetable(m_sizetable_name.toLocalFile());
- QImage opacitytable(m_opacitytable_name.toLocalFile());
- if(!colortable.isNull() || !sizetable.isNull() || !opacitytable.isNull()){
- //using tabled shaders
- m_material = new ParticleTrailsMaterialCT();
- if(colortable.isNull())
- colortable = QImage(":resources/identitytable.png");
- if(sizetable.isNull())
- sizetable = QImage(":resources/identitytable.png");
- if(opacitytable.isNull())
- opacitytable = QImage(":resources/defaultFadeInOut.png");
- Q_ASSERT(!colortable.isNull());
- Q_ASSERT(!sizetable.isNull());
- Q_ASSERT(!opacitytable.isNull());
- ParticleTrailsMaterialCT* ct_material = static_cast<ParticleTrailsMaterialCT *>(m_material);
- ct_material->colortable = sceneGraphEngine()->createTextureFromImage(colortable);
- ct_material->sizetable = sceneGraphEngine()->createTextureFromImage(sizetable);
- ct_material->opacitytable = sceneGraphEngine()->createTextureFromImage(opacitytable);
- }
-
- if (!m_material)
- m_material = new ParticleTrailsMaterial();
-
-
- m_material->texture = sceneGraphEngine()->createTextureFromImage(image);
- m_material->texture->setFiltering(QSGTexture::Linear);
-
- m_node = new QSGGeometryNode();
- m_node->setGeometry(g);
- m_node->setMaterial(m_material);
-
- m_last_particle = 0;
-
- return m_node;
-}
-
-QSGNode *ColoredParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
-{
- if(m_pleaseReset){
- if(m_node)
- delete m_node;
- if(m_material)
- delete m_material;
-
- m_node = 0;
- m_material = 0;
- m_pleaseReset = false;
- }
-
- if(m_system && m_system->isRunning())
- prepareNextFrame();
- if (m_node){
- update();
- m_node->markDirty(QSGNode::DirtyMaterial);
- }
-
- return m_node;
-}
-
-void ColoredParticle::prepareNextFrame()
-{
- if (m_node == 0){ //TODO: Staggered loading (as emitted)
- m_node = buildParticleNode();
- if(m_node == 0)
- return;
- }
- qint64 timeStamp = m_system->systemSync(this);
-
- qreal time = timeStamp / 1000.;
- m_material->timestamp = time;
-}
-
-void ColoredParticle::reloadColor(const Color4ub &c, ParticleData* d)
-{
- ColoredParticleVertices *particles = (ColoredParticleVertices *) m_node->geometry()->vertexData();
- int pos = particleTypeIndex(d);
- ColoredParticleVertices &p = particles[pos];
- p.v1.color = p.v2.color = p.v3.color = p.v4.color = c;
-}
-
-void ColoredParticle::vertexCopy(ColoredParticleVertex &b,const ParticleVertex& a)
-{
- b.x = a.x - m_systemOffset.x();
- b.y = a.y - m_systemOffset.y();
- b.t = a.t;
- b.lifeSpan = a.lifeSpan;
- b.size = a.size;
- b.endSize = a.endSize;
- b.sx = a.sx;
- b.sy = a.sy;
- b.ax = a.ax;
- b.ay = a.ay;
-}
-
-void ColoredParticle::reload(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- ColoredParticleVertices *particles = (ColoredParticleVertices *) m_node->geometry()->vertexData();
-
- int pos = particleTypeIndex(d);
-
- ColoredParticleVertices &p = particles[pos];
-
- //Perhaps we could be more efficient?
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-void ColoredParticle::load(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- //Color initialization
- // Particle color
- Color4ub color;
- qreal redVariation = m_color_variation + m_redVariation;
- qreal greenVariation = m_color_variation + m_greenVariation;
- qreal blueVariation = m_color_variation + m_blueVariation;
- color.r = m_color.red() * (1 - redVariation) + rand() % 256 * redVariation;
- color.g = m_color.green() * (1 - greenVariation) + rand() % 256 * greenVariation;
- color.b = m_color.blue() * (1 - blueVariation) + rand() % 256 * blueVariation;
- color.a = m_alpha * m_color.alpha() * (1 - m_alphaVariation) + rand() % 256 * m_alphaVariation;
- ColoredParticleVertices *particles = (ColoredParticleVertices *) m_node->geometry()->vertexData();
- ColoredParticleVertices &p = particles[particleTypeIndex(d)];
- p.v1.color = p.v2.color = p.v3.color = p.v4.color = color;
-
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/particles/coloredparticle.h b/src/imports/particles/coloredparticle.h
deleted file mode 100644
index 446b764941..0000000000
--- a/src/imports/particles/coloredparticle.h
+++ /dev/null
@@ -1,254 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef COLOREDPARTICLE_H
-#define COLOREDPARTICLE_H
-#include "particle.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class ParticleTrailsMaterial;
-class QSGGeometryNode;
-
-struct Color4ub {
- uchar r;
- uchar g;
- uchar b;
- uchar a;
-};
-
-struct ColoredParticleVertex {
- float x;
- float y;
- float tx;
- float ty;
- float t;
- float lifeSpan;
- float size;
- float endSize;
- float sx;
- float sy;
- float ax;
- float ay;
- Color4ub color;
-};
-
-struct ColoredParticleVertices {
- ColoredParticleVertex v1;
- ColoredParticleVertex v2;
- ColoredParticleVertex v3;
- ColoredParticleVertex v4;
-};
-
-class ColoredParticle : public ParticleType
-{
- Q_OBJECT
- Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
- Q_PROPERTY(QUrl colorTable READ colortable WRITE setColortable NOTIFY colortableChanged)
- Q_PROPERTY(QUrl sizeTable READ sizetable WRITE setSizetable NOTIFY sizetableChanged)
- Q_PROPERTY(QUrl opacityTable READ opacitytable WRITE setOpacitytable NOTIFY opacitytableChanged)
-
- Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
- //Stacks (added) with individual colorVariations
- Q_PROPERTY(qreal colorVariation READ colorVariation WRITE setColorVariation NOTIFY colorVariationChanged)
- Q_PROPERTY(qreal redVariation READ redVariation WRITE setRedVariation NOTIFY redVariationChanged)
- Q_PROPERTY(qreal greenVariation READ greenVariation WRITE setGreenVariation NOTIFY greenVariationChanged)
- Q_PROPERTY(qreal blueVariation READ blueVariation WRITE setBlueVariation NOTIFY blueVariationChanged)
- //Stacks (multiplies) with the Alpha in the color, mostly here so you can use svg color names (which have full alpha)
- Q_PROPERTY(qreal alpha READ alpha WRITE setAlpha NOTIFY alphaChanged)
- Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged)
-
-public:
- explicit ColoredParticle(QSGItem *parent = 0);
- virtual ~ColoredParticle(){}
-
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
-
- QUrl image() const { return m_image_name; }
- void setImage(const QUrl &image);
-
- QUrl colortable() const { return m_colortable_name; }
- void setColortable(const QUrl &table);
-
- QUrl sizetable() const { return m_sizetable_name; }
- void setSizetable (const QUrl &table);
-
- QUrl opacitytable() const { return m_opacitytable_name; }
- void setOpacitytable(const QUrl &table);
-
- QColor color() const { return m_color; }
- void setColor(const QColor &color);
-
- qreal colorVariation() const { return m_color_variation; }
- void setColorVariation(qreal var);
-
- qreal renderOpacity() const { return m_render_opacity; }
-
- qreal alphaVariation() const
- {
- return m_alphaVariation;
- }
-
- qreal alpha() const
- {
- return m_alpha;
- }
-
- qreal redVariation() const
- {
- return m_redVariation;
- }
-
- qreal greenVariation() const
- {
- return m_greenVariation;
- }
-
- qreal blueVariation() const
- {
- return m_blueVariation;
- }
-
-signals:
-
- void imageChanged();
- void colortableChanged();
- void sizetableChanged();
- void opacitytableChanged();
-
- void colorChanged();
- void colorVariationChanged();
-
- void particleDurationChanged();
- void alphaVariationChanged(qreal arg);
-
- void alphaChanged(qreal arg);
-
- void redVariationChanged(qreal arg);
-
- void greenVariationChanged(qreal arg);
-
- void blueVariationChanged(qreal arg);
-
-public slots:
- void setAlphaVariation(qreal arg)
- {
- if (m_alphaVariation != arg) {
- m_alphaVariation = arg;
- emit alphaVariationChanged(arg);
- }
- }
-
- void setAlpha(qreal arg)
- {
- if (m_alpha != arg) {
- m_alpha = arg;
- emit alphaChanged(arg);
- }
- }
-
- void setRedVariation(qreal arg)
- {
- if (m_redVariation != arg) {
- m_redVariation = arg;
- emit redVariationChanged(arg);
- }
- }
-
- void setGreenVariation(qreal arg)
- {
- if (m_greenVariation != arg) {
- m_greenVariation = arg;
- emit greenVariationChanged(arg);
- }
- }
-
- void setBlueVariation(qreal arg)
- {
- if (m_blueVariation != arg) {
- m_blueVariation = arg;
- emit blueVariationChanged(arg);
- }
- }
-
- void reloadColor(const Color4ub &c, ParticleData* d);
-protected:
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- void reset();
- void prepareNextFrame();
- QSGGeometryNode* buildParticleNode();
-private:
- void vertexCopy(ColoredParticleVertex &b,const ParticleVertex& a);
- bool m_do_reset;
-
- QUrl m_image_name;
- QUrl m_colortable_name;
- QUrl m_sizetable_name;
- QUrl m_opacitytable_name;
-
-
- QColor m_color;
- qreal m_color_variation;
- qreal m_particleDuration;
-
- QSGGeometryNode *m_node;
- ParticleTrailsMaterial *m_material;
-
- // derived values...
- int m_last_particle;
-
- qreal m_render_opacity;
- qreal m_alphaVariation;
- qreal m_alpha;
- qreal m_redVariation;
- qreal m_greenVariation;
- qreal m_blueVariation;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // COLOREDPARTICLE_H
diff --git a/src/imports/particles/deformableparticle.cpp b/src/imports/particles/deformableparticle.cpp
deleted file mode 100644
index 768e4eb4b5..0000000000
--- a/src/imports/particles/deformableparticle.cpp
+++ /dev/null
@@ -1,438 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <private/qsgcontext_p.h>
-#include <private/qsgadaptationlayer_p.h>
-#include <qsgnode.h>
-#include <qsgtexturematerial.h>
-#include <qsgtexture.h>
-#include <QFile>
-#include "deformableparticle.h"
-#include <QGLFunctions>
-#include <qsgengine.h>
-
-QT_BEGIN_NAMESPACE
-
-const float CONV = 0.017453292519943295;
-class DeformableParticleMaterial : public QSGMaterial
-{
-public:
- DeformableParticleMaterial()
- : timestamp(0)
- {
- setFlag(Blending, true);
- }
-
- ~DeformableParticleMaterial()
- {
- delete texture;
- }
-
- virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const
- {
- return this - static_cast<const DeformableParticleMaterial *>(other);
- }
-
- QSGTexture *texture;
-
- qreal timestamp;
-};
-
-
-class DeformableParticleMaterialData : public QSGMaterialShader
-{
-public:
- DeformableParticleMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
- {
- QFile vf(vertexFile ? vertexFile : ":resources/deformablevertex.shader");
- vf.open(QFile::ReadOnly);
- m_vertex_code = vf.readAll();
-
- QFile ff(fragmentFile ? fragmentFile : ":resources/deformablefragment.shader");
- ff.open(QFile::ReadOnly);
- m_fragment_code = ff.readAll();
-
- Q_ASSERT(!m_vertex_code.isNull());
- Q_ASSERT(!m_fragment_code.isNull());
- }
-
- void deactivate() {
- QSGMaterialShader::deactivate();
-
- for (int i=0; i<8; ++i) {
- program()->setAttributeArray(i, GL_FLOAT, chunkOfBytes, 1, 0);
- }
- }
-
- virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
- {
- DeformableParticleMaterial *m = static_cast<DeformableParticleMaterial *>(newEffect);
- state.context()->functions()->glActiveTexture(GL_TEXTURE0);
- m->texture->bind();
-
- program()->setUniformValue(m_opacity_id, state.opacity());
- program()->setUniformValue(m_timestamp_id, (float) m->timestamp);
-
- if (state.isMatrixDirty())
- program()->setUniformValue(m_matrix_id, state.combinedMatrix());
- }
-
- virtual void initialize() {
- m_matrix_id = program()->uniformLocation("matrix");
- m_opacity_id = program()->uniformLocation("opacity");
- m_timestamp_id = program()->uniformLocation("timestamp");
- }
-
- virtual const char *vertexShader() const { return m_vertex_code.constData(); }
- virtual const char *fragmentShader() const { return m_fragment_code.constData(); }
-
- virtual char const *const *attributeNames() const {
- static const char *attr[] = {
- "vPos",
- "vTex",
- "vData",
- "vVec",
- "vDeformVec",
- "vRotation",
- 0
- };
- return attr;
- }
-
- virtual bool isColorTable() const { return false; }
-
- int m_matrix_id;
- int m_opacity_id;
- int m_timestamp_id;
-
- QByteArray m_vertex_code;
- QByteArray m_fragment_code;
-
- static float chunkOfBytes[1024];
-};
-float DeformableParticleMaterialData::chunkOfBytes[1024];
-
-
-QSGMaterialShader *DeformableParticleMaterial::createShader() const
-{
- return new DeformableParticleMaterialData;
-}
-
-struct DeformableParticleVertex {
- float x;
- float y;
- float tx;
- float ty;
- float t;
- float lifeSpan;
- float size;
- float endSize;
- float sx;
- float sy;
- float ax;
- float ay;
- float xx;
- float xy;
- float yx;
- float yy;
- float rotation;
- float rotationSpeed;
- float autoRotate;//Assume that GPUs prefer floats to bools
-};
-
-struct DeformableParticleVertices {
- DeformableParticleVertex v1;
- DeformableParticleVertex v2;
- DeformableParticleVertex v3;
- DeformableParticleVertex v4;
-};
-
-
-DeformableParticle::DeformableParticle(QSGItem* parent)
- : ParticleType(parent)
- , m_do_reset(false)
- , m_rotation(0)
- , m_autoRotation(false)
- , m_xVector(0)
- , m_yVector(0)
- , m_rotationVariation(0)
- , m_rotationSpeed(0)
- , m_rotationSpeedVariation(0)
-{
- setFlag(ItemHasContents);
-}
-
-void DeformableParticle::setImage(const QUrl &image)
-{
- if (image == m_image)
- return;
- m_image = image;
- emit imageChanged();
- reset();
-}
-
-void DeformableParticle::setCount(int c)
-{
- ParticleType::setCount(c);
- m_pleaseReset = true;
-}
-
-void DeformableParticle::reset()
-{
- ParticleType::reset();
- m_pleaseReset = true;
-}
-
-static QSGGeometry::Attribute DeformableParticle_Attributes[] = {
- { 0, 2, GL_FLOAT }, // Position
- { 1, 2, GL_FLOAT }, // TexCoord
- { 2, 4, GL_FLOAT }, // Data
- { 3, 4, GL_FLOAT }, // Vectors
- { 4, 4, GL_FLOAT }, // DeformationVectors
- { 5, 3, GL_FLOAT } // Rotation
-};
-
-static QSGGeometry::AttributeSet DeformableParticle_AttributeSet =
-{
- 6, // Attribute Count
- (2 + 2 + 4 + 4 + 4 + 3) * sizeof(float),
- DeformableParticle_Attributes
-};
-
-QSGGeometryNode* DeformableParticle::buildParticleNode()
-{
- if (m_count * 4 > 0xffff) {
- printf("DeformableParticle: Too many particles... \n");
- return 0;
- }
-
- if(m_count <= 0) {
- printf("DeformableParticle: Too few particles... \n");
- return 0;
- }
-
- QImage image(m_image.toLocalFile());
- if (image.isNull()) {
- printf("DeformableParticle: loading image failed... '%s'\n", qPrintable(m_image.toLocalFile()));
- return 0;
- }
-
- int vCount = m_count * 4;
- int iCount = m_count * 6;
-
- QSGGeometry *g = new QSGGeometry(DeformableParticle_AttributeSet, vCount, iCount);
- g->setDrawingMode(GL_TRIANGLES);
-
- DeformableParticleVertex *vertices = (DeformableParticleVertex *) g->vertexData();
- for (int p=0; p<m_count; ++p) {
-
- for (int i=0; i<4; ++i) {
- vertices[i].x = 0;
- vertices[i].y = 0;
- vertices[i].t = -1;
- vertices[i].lifeSpan = 0;
- vertices[i].size = 0;
- vertices[i].endSize = 0;
- vertices[i].sx = 0;
- vertices[i].sy = 0;
- vertices[i].ax = 0;
- vertices[i].ay = 0;
- vertices[i].xx = 1;
- vertices[i].xy = 0;
- vertices[i].yx = 0;
- vertices[i].yy = 1;
- vertices[i].rotation = 0;
- vertices[i].rotationSpeed = 0;
- vertices[i].autoRotate = 0;
- }
-
- vertices[0].tx = 0;
- vertices[0].ty = 0;
-
- vertices[1].tx = 1;
- vertices[1].ty = 0;
-
- vertices[2].tx = 0;
- vertices[2].ty = 1;
-
- vertices[3].tx = 1;
- vertices[3].ty = 1;
-
- vertices += 4;
- }
-
- quint16 *indices = g->indexDataAsUShort();
- for (int i=0; i<m_count; ++i) {
- int o = i * 4;
- indices[0] = o;
- indices[1] = o + 1;
- indices[2] = o + 2;
- indices[3] = o + 1;
- indices[4] = o + 3;
- indices[5] = o + 2;
- indices += 6;
- }
-
- if (m_material) {
- delete m_material;
- m_material = 0;
- }
-
- if (!m_material)
- m_material = new DeformableParticleMaterial();
-
-
- m_material->texture = sceneGraphEngine()->createTextureFromImage(image);
- m_material->texture->setFiltering(QSGTexture::Linear);
-
- m_node = new QSGGeometryNode();
- m_node->setGeometry(g);
- m_node->setMaterial(m_material);
-
- m_last_particle = 0;
-
- return m_node;
-}
-
-QSGNode *DeformableParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
-{
- if(m_pleaseReset){
- if(m_node)
- delete m_node;
- if(m_material)
- delete m_material;
-
- m_node = 0;
- m_material = 0;
- m_pleaseReset = false;
- }
-
- if(m_system && m_system->isRunning())
- prepareNextFrame();
- if (m_node){
- update();
- m_node->markDirty(QSGNode::DirtyMaterial);
- }
-
- return m_node;
-}
-
-void DeformableParticle::prepareNextFrame()
-{
- if (m_node == 0){ //TODO: Staggered loading (as emitted)
- m_node = buildParticleNode();
- if(m_node == 0)
- return;
- }
- qint64 timeStamp = m_system->systemSync(this);
-
- qreal time = timeStamp / 1000.;
- m_material->timestamp = time;
-
-}
-
-
-void DeformableParticle::vertexCopy(DeformableParticleVertex &b,const ParticleVertex& a)
-{
- b.x = a.x - m_systemOffset.x();
- b.y = a.y - m_systemOffset.y();
- b.t = a.t;
- b.lifeSpan = a.lifeSpan;
- b.size = a.size;
- b.endSize = a.endSize;
- b.sx = a.sx;
- b.sy = a.sy;
- b.ax = a.ax;
- b.ay = a.ay;
-}
-
-void DeformableParticle::reload(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- DeformableParticleVertices *particles = (DeformableParticleVertices *) m_node->geometry()->vertexData();
-
- int pos = particleTypeIndex(d);
-
- DeformableParticleVertices &p = particles[pos];
-
- //Perhaps we could be more efficient?
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
- //TODO: Allow for change of deformation data?
-}
-
-void DeformableParticle::load(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- //Deformation Initialization
- DeformableParticleVertices *particles = (DeformableParticleVertices *) m_node->geometry()->vertexData();
- DeformableParticleVertices &p = particles[particleTypeIndex(d)];
- if(m_xVector){
- const QPointF &ret = m_xVector->sample(QPointF(d->pv.x, d->pv.y));
- p.v1.xx = p.v2.xx = p.v3.xx = p.v4.xx = ret.x();
- p.v1.xy = p.v2.xy = p.v3.xy = p.v4.xy = ret.y();
- }
- if(m_yVector){
- const QPointF &ret = m_yVector->sample(QPointF(d->pv.x, d->pv.y));
- p.v1.yx = p.v2.yx = p.v3.yx = p.v4.yx = ret.x();
- p.v1.yy = p.v2.yy = p.v3.yy = p.v4.yy = ret.y();
- }
- p.v1.rotation = p.v2.rotation = p.v3.rotation = p.v4.rotation =
- (m_rotation + (m_rotationVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationVariation) ) * CONV;
- p.v1.rotationSpeed = p.v2.rotationSpeed = p.v3.rotationSpeed = p.v4.rotationSpeed =
- (m_rotationSpeed + (m_rotationSpeedVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationSpeedVariation) ) * CONV;
- p.v1.autoRotate = p.v2.autoRotate = p.v3.autoRotate = p.v4.autoRotate = m_autoRotation?1.0:0.0;
-
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/particles/deformableparticle.h b/src/imports/particles/deformableparticle.h
deleted file mode 100644
index 0de6d8228a..0000000000
--- a/src/imports/particles/deformableparticle.h
+++ /dev/null
@@ -1,235 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DEFORMABLEPARTICLE_H
-#define DEFORMABLEPARTICLE_H
-#include "particle.h"
-#include "varyingvector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class DeformableParticleMaterial;
-class QSGGeometryNode;
-struct DeformableParticleVertex;
-
-class DeformableParticle : public ParticleType
-{
- Q_OBJECT
- //Note that the particle centering can be less accurate with this one
- Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
-
- Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
- Q_PROPERTY(qreal rotationVariation READ rotationVariation WRITE setRotationVariation NOTIFY rotationVariationChanged)
- Q_PROPERTY(qreal rotationSpeed READ rotationSpeed WRITE setRotationSpeed NOTIFY rotationSpeedChanged)
- Q_PROPERTY(qreal rotationSpeedVariation READ rotationSpeedVariation WRITE setRotationSpeedVariation NOTIFY rotationSpeedVariationChanged)
- //If true, then will face the direction of motion. Stacks with rotation, e.g. setting rotation
- //to 180 will lead to facing away from the direction of motion
- Q_PROPERTY(bool autoRotation READ autoRotation WRITE autoRotation NOTIFY autoRotationChanged)
-
- //###Call i/j? Makes more sense to those with vector calculus experience, and I could even add the cirumflex in QML?
- //xVector is the vector from the top-left point to the top-right point, and is multiplied by current size
- Q_PROPERTY(VaryingVector* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged)
- //yVector is the same, but top-left to bottom-left. The particle is always a parallelogram.
- Q_PROPERTY(VaryingVector* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged)
-
- //Do we want to add the tables?
- //Q_PROPERTY(QUrl colorTable READ colortable WRITE setColortable NOTIFY colortableChanged)
- //Q_PROPERTY(QUrl sizeTable READ sizetable WRITE setSizetable NOTIFY sizetableChanged)
- //Q_PROPERTY(QUrl opacityTable READ opacitytable WRITE setOpacitytable NOTIFY opacitytableChanged)
-
- //Does it need alpha? For convenience only, as images probably don't have it
- //Q_PROPERTY(qreal alpha READ alpha WRITE setAlpha NOTIFY alphaChanged)
- //Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged)
-
-public:
- explicit DeformableParticle(QSGItem *parent = 0);
- virtual ~DeformableParticle(){}
-
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
-
- QUrl image() const { return m_image; }
- void setImage(const QUrl &image);
-
- qreal rotation() const
- {
- return m_rotation;
- }
-
- bool autoRotation() const
- {
- return m_autoRotation;
- }
-
- VaryingVector* xVector() const
- {
- return m_xVector;
- }
-
- VaryingVector* yVector() const
- {
- return m_yVector;
- }
-
- qreal rotationVariation() const
- {
- return m_rotationVariation;
- }
-
- qreal rotationSpeed() const
- {
- return m_rotationSpeed;
- }
-
- qreal rotationSpeedVariation() const
- {
- return m_rotationSpeedVariation;
- }
-
-signals:
-
- void imageChanged();
- void rotationChanged(qreal arg);
-
- void autoRotationChanged(bool arg);
-
- void xVectorChanged(VaryingVector* arg);
-
- void yVectorChanged(VaryingVector* arg);
-
- void rotationVariationChanged(qreal arg);
-
- void rotationSpeedChanged(qreal arg);
-
- void rotationSpeedVariationChanged(qreal arg);
-
-public slots:
-void setRotation(qreal arg)
-{
- if (m_rotation != arg) {
- m_rotation = arg;
- emit rotationChanged(arg);
- }
-}
-
-void autoRotation(bool arg)
-{
- if (m_autoRotation != arg) {
- m_autoRotation = arg;
- emit autoRotationChanged(arg);
- }
-}
-
-void setXVector(VaryingVector* arg)
-{
- if (m_xVector != arg) {
- m_xVector = arg;
- emit xVectorChanged(arg);
- }
-}
-
-void setYVector(VaryingVector* arg)
-{
- if (m_yVector != arg) {
- m_yVector = arg;
- emit yVectorChanged(arg);
- }
-}
-
-void setRotationVariation(qreal arg)
-{
- if (m_rotationVariation != arg) {
- m_rotationVariation = arg;
- emit rotationVariationChanged(arg);
- }
-}
-
-void setRotationSpeed(qreal arg)
-{
- if (m_rotationSpeed != arg) {
- m_rotationSpeed = arg;
- emit rotationSpeedChanged(arg);
- }
-}
-
-void setRotationSpeedVariation(qreal arg)
-{
- if (m_rotationSpeedVariation != arg) {
- m_rotationSpeedVariation = arg;
- emit rotationSpeedVariationChanged(arg);
- }
-}
-
-protected:
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- void reset();
- void prepareNextFrame();
- QSGGeometryNode* buildParticleNode();
-private:
- void vertexCopy(DeformableParticleVertex &b,const ParticleVertex& a);
- bool m_do_reset;
-
- QUrl m_image;
- QSGGeometryNode *m_node;
- DeformableParticleMaterial *m_material;
-
- // derived values...
- int m_last_particle;
-
- qreal m_render_opacity;
- // generated vars
- qreal m_rotation;
- bool m_autoRotation;
- VaryingVector* m_xVector;
- VaryingVector* m_yVector;
- qreal m_rotationVariation;
- qreal m_rotationSpeed;
- qreal m_rotationSpeedVariation;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // DEFORMABLEPARTICLE_H
diff --git a/src/imports/particles/driftaffector.cpp b/src/imports/particles/driftaffector.cpp
deleted file mode 100644
index f88e29936a..0000000000
--- a/src/imports/particles/driftaffector.cpp
+++ /dev/null
@@ -1,67 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "driftaffector.h"
-#include "particlesystem.h"
-QT_BEGIN_NAMESPACE
-DriftAffector::DriftAffector(QSGItem *parent) :
- ParticleAffector(parent)
-{
-}
-
-DriftAffector::~DriftAffector()
-{
-}
-
-bool DriftAffector::affectParticle(ParticleData *data, qreal dt)
-{
- if(!m_xDrift && !m_yDrift)
- return false;
- qreal dx = (((qreal)qrand() / (qreal)RAND_MAX) - 0.5) * 2 * m_xDrift * dt;
- qreal dy = (((qreal)qrand() / (qreal)RAND_MAX) - 0.5) * 2 * m_yDrift * dt;
- if(dx)
- data->setInstantaneousSX(data->curSX() + dx);
- if(dy)
- data->setInstantaneousSY(data->curSY() + dy);
-
- return true;
-}
-QT_END_NAMESPACE
diff --git a/src/imports/particles/driftaffector.h b/src/imports/particles/driftaffector.h
deleted file mode 100644
index 91ef0fbd34..0000000000
--- a/src/imports/particles/driftaffector.h
+++ /dev/null
@@ -1,104 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DRIFTAFFECTOR_H
-#define DRIFTAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-
-class DriftAffector : public ParticleAffector
-{
- Q_OBJECT
- Q_PROPERTY(qreal xDrift READ xDrift WRITE setXDrift NOTIFY xDriftChanged)
- Q_PROPERTY(qreal yDrift READ yDrift WRITE setYDrift NOTIFY yDriftChanged)
-public:
- explicit DriftAffector(QSGItem *parent = 0);
- ~DriftAffector();
- qreal yDrift() const
- {
- return m_yDrift;
- }
-
- qreal xDrift() const
- {
- return m_xDrift;
- }
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
-
-signals:
-
- void yDriftChanged(qreal arg);
-
- void xDriftChanged(qreal arg);
-
-public slots:
-
-void setYDrift(qreal arg)
-{
- if (m_yDrift != arg) {
- m_yDrift = arg;
- emit yDriftChanged(arg);
- }
-}
-
-void setXDrift(qreal arg)
-{
- if (m_xDrift != arg) {
- m_xDrift = arg;
- emit xDriftChanged(arg);
- }
-}
-
-private:
- qreal m_yDrift;
- qreal m_xDrift;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // DRIFTAFFECTOR_H
diff --git a/src/imports/particles/eternalaffector.cpp b/src/imports/particles/eternalaffector.cpp
deleted file mode 100644
index c946709170..0000000000
--- a/src/imports/particles/eternalaffector.cpp
+++ /dev/null
@@ -1,60 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "eternalaffector.h"
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-EternalAffector::EternalAffector(QSGItem *parent) :
- ParticleAffector(parent)
-{
-}
-
-bool EternalAffector::affectParticle(ParticleData *d, qreal dt)
-{
- qreal target = (m_system->m_timeInt - m_targetLife)/1000.0;
- if(d->pv.t < target)
- d->pv.t = target;
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/particles/eternalaffector.h b/src/imports/particles/eternalaffector.h
deleted file mode 100644
index 834106b53d..0000000000
--- a/src/imports/particles/eternalaffector.h
+++ /dev/null
@@ -1,88 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ETERNALAFFECTOR_H
-#define ETERNALAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class EternalAffector : public ParticleAffector
-{
- Q_OBJECT
- Q_PROPERTY(int targetLife READ targetLife WRITE setTargetLife NOTIFY targetLifeChanged)
-
-public:
- explicit EternalAffector(QSGItem *parent = 0);
- int targetLife() const
- {
- return m_targetLife;
- }
-
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
-
-signals:
-
- void targetLifeChanged(int arg);
-
-public slots:
-
- void setTargetLife(int arg)
- {
- if (m_targetLife != arg) {
- m_targetLife = arg;
- emit targetLifeChanged(arg);
- }
- }
-private:
- int m_targetLife;
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // ETERNALAFFECTOR_H
diff --git a/src/imports/particles/gravitationalsingularityaffector.cpp b/src/imports/particles/gravitationalsingularityaffector.cpp
deleted file mode 100644
index 4dd7d94b7b..0000000000
--- a/src/imports/particles/gravitationalsingularityaffector.cpp
+++ /dev/null
@@ -1,179 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "gravitationalsingularityaffector.h"
-#include <cmath>
-#include <QDebug>
-QT_BEGIN_NAMESPACE
-GravitationalSingularityAffector::GravitationalSingularityAffector(QSGItem *parent) :
- ParticleAffector(parent), m_strength(0.0), m_x(0), m_y(0)
-{
-}
-
-const qreal LIMIT = 200;
-qreal limit(qreal val){
- if(qAbs(val) > LIMIT){
- return val < 0 ? LIMIT * -1 : LIMIT;
- }else{
- return val;
- }
-}
-
-bool GravitationalSingularityAffector::affectParticle(ParticleData *d, qreal dt)
-{
- if(!m_strength)
- return false;
- qreal dx = m_x - d->curX();
- qreal dy = m_y - d->curY();
- qreal r = sqrt((dx*dx) + (dy*dy));
- if(r < 0.1 ){//Simulated event horizion - It's right on top of it, and will never escape again. just stick it here.
- d->pv.ax = 0;
- d->pv.ay = 0;
- d->pv.sx = 0;
- d->pv.sy = 0;
- d->pv.x = m_x;
- d->pv.y = m_y;
- return true;
- }else if(r < 50.0){//Too close, typical dt values are far too coarse for simulation. This may kill perf though
- int parts = floor(100.0/r);
- ParticleData* f = new ParticleData;//Fake, where it's all in real time for convenience
- f->pv.x = d->curX();
- f->pv.y = d->curY();
- f->pv.sx = limit(d->curSX());
- f->pv.sy = limit(d->curSY());
- f->pv.ax = d->pv.ax;
- f->pv.ay = d->pv.ay;
- subaffect(f, dt/parts, true);
- for(int i=1; i<parts; i++)
- subaffect(f, dt/parts, false);
-
- //Copy values from f, and turn into 'from start' values
- qreal t = (m_system->m_timeInt/1000.) - d->pv.t;
- qreal sy = limit(f->pv.sy) - t*f->pv.ay;
- qreal y = f->pv.y - t*sy - 0.5 * t*t*f->pv.ay;
- qreal sx = limit(f->pv.sx) - t*f->pv.ax;
- qreal x = f->pv.x - t*sx - 0.5 * t*t*f->pv.ax;
-
- d->pv.ay = f->pv.ay;
- d->pv.sy = sy;
- d->pv.y = y;
- d->pv.ax = f->pv.ax;
- d->pv.sx = sx;
- d->pv.x = x;
- return true;
- }
- qreal theta = atan2(dy,dx);
- qreal ds = (m_strength / (r*r)) * dt;
- dx = ds * cos(theta);
- dy = ds * sin(theta);
- d->setInstantaneousSX(limit(d->pv.sx + dx));
- d->setInstantaneousSY(limit(d->pv.sy + dy));
- return true;
-}
-
-const qreal EPSILON = 0.1;
-bool fuzzyCompare(qreal a, qreal b)
-{
- //Not using qFuzzyCompare because I want control of epsilon
- return (a >= b - EPSILON && a <= b + EPSILON);
-}
-
-bool fuzzyLess(qreal a, qreal b)
-{
- //Not using qFuzzyCompare because I want control of epsilon
- return a <= b + EPSILON;
-}
-
-bool fuzzyMore(qreal a, qreal b)
-{
- //Not using qFuzzyCompare because I want control of epsilon
- return a >= b - EPSILON;
-}
-
-bool lineIntersect(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3)
-{
- if(x3 < qMin(x1,x2) || x3 > qMax(x1,x2) || y3 < qMin(y1,y2) || y3 > qMax(y1,y2))
- return false;
- qreal m,c;
- m = (y2-y1) / (x2-x1);
- c = y1 - m*x1;
- return (fuzzyCompare(y3, m*x3 + c));
-}
-
-void GravitationalSingularityAffector::subaffect(ParticleData *d, qreal dt, bool first)
-{
- if(!first){
- qreal nextX = d->pv.x + d->pv.sx * dt + d->pv.ax * dt * dt * 0.5;
- qreal nextY = d->pv.y + d->pv.sy * dt + d->pv.ay * dt * dt * 0.5;
- if(lineIntersect(d->pv.x, d->pv.y, nextX, nextY, m_x, m_y)){
- d->pv.ax = 0;
- d->pv.ay = 0;
- d->pv.sx = 0;
- d->pv.sy = 0;
- d->pv.x = m_x;
- d->pv.y = m_y;
- return;
- //Passed center - the near infinite forces cancel out
-// d->pv.x = m_x + m_x - d->pv.x;
-// d->pv.y = m_y + m_y - d->pv.y;
-// d->pv.sx *= -1;
-// d->pv.sy *= -1;
-// return;
- }
- //Simulate advancing a dt
- d->pv.x = nextX;
- d->pv.y = nextY;
- d->pv.sx += d->pv.ax * dt;
- d->pv.sy += d->pv.ay * dt;
- }
- qreal dx = m_x - d->pv.x;
- qreal dy = m_y - d->pv.y;
- qreal r = sqrt((dx*dx) + (dy*dy));
- if(!r)
- return;
- qreal theta = atan2(dy,dx);
- qreal ds = (m_strength / (r*r)) * dt;
- dx = ds * cos(theta);
- dy = ds * sin(theta);
- d->pv.sx = d->pv.sx + dx;
- d->pv.sy = d->pv.sy + dy;
-}
-QT_END_NAMESPACE
diff --git a/src/imports/particles/gravitationalsingularityaffector.h b/src/imports/particles/gravitationalsingularityaffector.h
deleted file mode 100644
index 7ac5e93e0e..0000000000
--- a/src/imports/particles/gravitationalsingularityaffector.h
+++ /dev/null
@@ -1,121 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef GRAVITATIONALSINGULARITYAFFECTOR_H
-#define GRAVITATIONALSINGULARITYAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-
-class GravitationalSingularityAffector : public ParticleAffector
-{
- Q_OBJECT
- Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
- Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
- Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
-public:
- explicit GravitationalSingularityAffector(QSGItem *parent = 0);
-
- qreal strength() const
- {
- return m_strength;
- }
-
- qreal x() const
- {
- return m_x;
- }
-
- qreal y() const
- {
- return m_y;
- }
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
- void subaffect(ParticleData *d, qreal dt, bool first);
-signals:
-
- void strengthChanged(qreal arg);
-
- void xChanged(qreal arg);
-
- void yChanged(qreal arg);
-
-public slots:
-
-void setStrength(qreal arg)
-{
- if (m_strength != arg) {
- m_strength = arg;
- emit strengthChanged(arg);
- }
-}
-
-void setX(qreal arg)
-{
- if (m_x != arg) {
- m_x = arg;
- emit xChanged(arg);
- }
-}
-
-void setY(qreal arg)
-{
- if (m_y != arg) {
- m_y = arg;
- emit yChanged(arg);
- }
-}
-
-private:
-qreal m_strength;
-qreal m_x;
-qreal m_y;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // GRAVITATIONALSINGULARITYAFFECTOR_H
diff --git a/src/imports/particles/main.cpp b/src/imports/particles/main.cpp
deleted file mode 100644
index 072025d6bc..0000000000
--- a/src/imports/particles/main.cpp
+++ /dev/null
@@ -1,160 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "V1/qdeclarativeparticles_p.h"
-#include "pluginmain.h"
-#include "spritestate.h"
-#include "spriteengine.h"
-#include "particleaffector.h"
-#include "wanderaffector.h"
-//#include "rockingaffector.h"
-//#include "scalingaffector.h"
-#include "resetaffector.h"
-#include "gravityaffector.h"
-#include "driftaffector.h"
-#include "gravitationalsingularityaffector.h"
-#include "frictionaffector.h"
-#include "meanderaffector.h"
-#include "attractoraffector.h"
-#include "speedlimitaffector.h"
-#include "killaffector.h"
-//#include "zoneaffector.h"
-//#include "toggleaffector.h"
-#include "spritegoalaffector.h"
-#include "swarmaffector.h"
-#include "turbulenceaffector.h"
-#include "eternalaffector.h"
-#include "particlesystem.h"
-#include "particleemitter.h"
-//#include "spriteemitter.h"
-#include "trailsemitter.h"
-#include "burstemitter.h"
-#include "particle.h"
-#include "coloredparticle.h"
-#include "spriteparticle.h"
-//#include "modelparticle.h"
-#include "dataparticle.h"
-#include "itemparticle.h"
-#include "superparticle.h"
-#include "ultraparticle.h"
-//#include "pairedparticle.h"
-#include "spriteimage.h"
-#include "followemitter.h"
-#include "particleextruder.h"
-#include "ellipseextruder.h"
-#include "lineextruder.h"
-#include "maskextruder.h"
-#include "varyingvector.h"
-#include "pointvector.h"
-#include "angledvector.h"
-#include "directedvector.h"
-//#include "followaffector.h"
-#include "deformableparticle.h"
-#include "pictureaffector.h"
-
-QT_BEGIN_NAMESPACE
-
-void ParticlesPlugin::registerTypes(const char *uri)
-{
- Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.particles"));
-
- qmlRegisterType<QDeclarativeParticles>(uri, 1, 0, "Particles");
- qmlRegisterType<QDeclarativeParticleMotion>(uri,1,0,"ParticleMotion");
- qmlRegisterType<QDeclarativeParticleMotionGravity>(uri,1,0,"ParticleMotionGravity");
- qmlRegisterType<QDeclarativeParticleMotionLinear>(uri,1,0,"ParticleMotionLinear");
- qmlRegisterType<QDeclarativeParticleMotionWander>(uri,1,0,"ParticleMotionWander");
- qmlRegisterType<SpriteState>(uri, 2, 0, "Sprite");
- qmlRegisterType<SpriteEngine>(uri, 2, 0, "SpriteEngine");
- qmlRegisterType<SpriteImage>(uri, 2, 0, "SpriteImage");
-
- qmlRegisterType<ParticleSystem>(uri, 2, 0, "ParticleSystem");
-
- qmlRegisterType<ParticleType>(uri, 2, 0, "Particle");
- qmlRegisterType<ColoredParticle>(uri, 2, 0, "ColoredParticle");
- qmlRegisterType<SpriteParticle>(uri, 2, 0, "SpriteParticle");
- //qmlRegisterType<ModelParticle>(uri, 2, 0, "ModelParticle");
- qmlRegisterType<DataParticle>(uri, 2, 0, "DataParticle");
- qmlRegisterType<ItemParticle>(uri, 2, 0, "ItemParticle");
- //qmlRegisterType<PairedParticle>(uri, 2, 0, "PairedParticle");
- qmlRegisterType<DeformableParticle>(uri, 2, 0, "DeformableParticle");
- qmlRegisterType<SuperParticle>(uri, 2, 0, "SuperParticle");
- qmlRegisterType<UltraParticle>(uri, 2, 0, "UltraParticle");
-
- qmlRegisterType<ParticleEmitter>(uri, 2, 0, "ParticleEmitter");
- qmlRegisterType<TrailsEmitter>(uri, 2, 0, "TrailEmitter");
- qmlRegisterType<TrailsEmitter>(uri, 2, 0, "BurstEmitter");
-
- qmlRegisterType<FollowEmitter>(uri, 2, 0, "FollowEmitter");
- qmlRegisterType<ParticleExtruder>(uri, 2, 0, "Box");
- qmlRegisterType<EllipseExtruder>(uri, 2, 0, "Ellipse");
- qmlRegisterType<LineExtruder>(uri, 2, 0, "Line");
- qmlRegisterType<MaskExtruder>(uri, 2, 0, "Mask");
-
- qmlRegisterType<VaryingVector>(uri, 2, 0, "NullVector");
- qmlRegisterType<PointVector>(uri, 2, 0, "PointVector");
- qmlRegisterType<AngledVector>(uri, 2, 0, "AngleVector");
- qmlRegisterType<DirectedVector>(uri, 2, 0, "DirectedVector");
-
- qmlRegisterType<ParticleAffector>(uri, 2, 0, "ParticleAffector");
- qmlRegisterType<WanderAffector>(uri, 2, 0, "Wander");
- //qmlRegisterType<ScalingAffector>(uri, 2, 0, "Scale");
- //qmlRegisterType<RockingAffector>(uri, 2, 0, "Rocking");
- qmlRegisterType<DriftAffector>(uri, 2, 0, "Drift");
- qmlRegisterType<FrictionAffector>(uri, 2, 0, "Friction");
- qmlRegisterType<GravitationalSingularityAffector>(uri, 2, 0, "GravitationalSingularity");
- qmlRegisterType<AttractorAffector>(uri, 2, 0, "Attractor");
- qmlRegisterType<MeanderAffector>(uri, 2, 0, "Meander");
- qmlRegisterType<SpeedLimitAffector>(uri, 2, 0, "SpeedLimit");
- qmlRegisterType<GravityAffector>(uri, 2, 0, "Gravity");
- qmlRegisterType<EternalAffector>(uri, 2, 0, "Stasis");
- qmlRegisterType<ResetAffector>(uri, 2, 0, "Reset");
- //qmlRegisterType<ZoneAffector>(uri, 2, 0, "Zone");
- //qmlRegisterType<ToggleAffector>(uri, 2, 0, "Toggle");
- qmlRegisterType<KillAffector>(uri, 2, 0, "Kill");
- qmlRegisterType<SpriteGoalAffector>(uri, 2, 0, "SpriteGoal");
- qmlRegisterType<SwarmAffector>(uri, 2, 0 , "Swarm");
- qmlRegisterType<TurbulenceAffector>(uri, 2, 0 , "Turbulence");
- qmlRegisterType<PictureAffector>(uri, 2, 0, "Picture");
-}
-
-QT_END_NAMESPACE
-
-Q_EXPORT_PLUGIN2(Particles, QT_PREPEND_NAMESPACE(ParticlesPlugin))
diff --git a/src/imports/particles/meanderaffector.cpp b/src/imports/particles/meanderaffector.cpp
deleted file mode 100644
index 8e03cd07fb..0000000000
--- a/src/imports/particles/meanderaffector.cpp
+++ /dev/null
@@ -1,65 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "meanderaffector.h"
-
-QT_BEGIN_NAMESPACE
-
-MeanderAffector::MeanderAffector(QSGItem *parent) :
- ParticleAffector(parent)
-{
-}
-
-bool MeanderAffector::affectParticle(ParticleData *data, qreal dt)
-{
- if(!m_xDrift && !m_yDrift)
- return false;
- qreal dx = (((qreal)qrand() / (qreal)RAND_MAX) - 0.5) * 2 * m_xDrift * dt;
- qreal dy = (((qreal)qrand() / (qreal)RAND_MAX) - 0.5) * 2 * m_yDrift * dt;
- if(dx)
- data->setInstantaneousAX(data->pv.ax + dx);
- if(dy)
- data->setInstantaneousAY(data->pv.ay + dy);
-
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/particles/meanderaffector.h b/src/imports/particles/meanderaffector.h
deleted file mode 100644
index 203d20430d..0000000000
--- a/src/imports/particles/meanderaffector.h
+++ /dev/null
@@ -1,103 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef MEANDERAFFECTOR_H
-#define MEANDERAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-
-class MeanderAffector : public ParticleAffector
-{
- Q_OBJECT
- //Like drift, but affects da/dt instead of ds/dt
- Q_PROPERTY(qreal xDrift READ xDrift WRITE setXDrift NOTIFY xDriftChanged)
- Q_PROPERTY(qreal yDrift READ yDrift WRITE setYDrift NOTIFY yDriftChanged)
-public:
- explicit MeanderAffector(QSGItem *parent = 0);
-
- qreal xDrift() const
- {
- return m_xDrift;
- }
-
- qreal yDrift() const
- {
- return m_yDrift;
- }
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
-signals:
-
- void xDriftChanged(qreal arg);
-
- void yDriftChanged(qreal arg);
-
-public slots:
-
- void setXDrift(qreal arg)
- {
- if (m_xDrift != arg) {
- m_xDrift = arg;
- emit xDriftChanged(arg);
- }
- }
- void setYDrift(qreal arg)
- {
- if (m_yDrift != arg) {
- m_yDrift = arg;
- emit yDriftChanged(arg);
- }
- }
-
-private:
- qreal m_xDrift;
- qreal m_yDrift;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // MEANDERAFFECTOR_H
diff --git a/src/imports/particles/particle.cpp b/src/imports/particles/particle.cpp
deleted file mode 100644
index 8f4ecbf733..0000000000
--- a/src/imports/particles/particle.cpp
+++ /dev/null
@@ -1,135 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "particle.h"
-#include <QDebug>
-QT_BEGIN_NAMESPACE
-ParticleType::ParticleType(QSGItem *parent) :
- QSGItem(parent),
- m_system(0)
-{
- connect(this, SIGNAL(xChanged()),
- this, SLOT(calcSystemOffset()));
- connect(this, SIGNAL(yChanged()),
- this, SLOT(calcSystemOffset()));
-}
-
-void ParticleType::componentComplete()
-{
- if(!m_system)
- qWarning() << "Particle created without a particle system specified";//TODO: useful QML warnings, like line number?
- QSGItem::componentComplete();
-}
-
-
-void ParticleType::setSystem(ParticleSystem *arg)
-{
- if (m_system != arg) {
- m_system = arg;
- if(m_system){
- m_system->registerParticleType(this);
- connect(m_system, SIGNAL(xChanged()),
- this, SLOT(calcSystemOffset()));
- connect(m_system, SIGNAL(yChanged()),
- this, SLOT(calcSystemOffset()));
- calcSystemOffset();
- }
- emit systemChanged(arg);
- }
-}
-
-void ParticleType::load(ParticleData*)
-{
-}
-
-void ParticleType::reload(ParticleData*)
-{
-}
-
-void ParticleType::reset()
-{
- //Have to every time because what it's emitting may have changed and that affects particleTypeIndex
- m_particleStarts.clear();
- m_lastStart = 0;
-}
-
-void ParticleType::setCount(int c)
-{
- if(c == m_count)
- return;
- m_count = c;
- emit countChanged();
-}
-
-int ParticleType::count()
-{
- return m_count;
-}
-
-
-int ParticleType::particleTypeIndex(ParticleData* d)
-{
- if(!m_particleStarts.contains(d->group)){
- m_particleStarts.insert(d->group, m_lastStart);
- m_lastStart += m_system->m_groupData[d->group]->size;
- }
- int ret = m_particleStarts[d->group] + d->particleIndex;
- Q_ASSERT(ret >=0 && ret < m_count);//XXX: Possibly shouldn't assert, but bugs here were hard to find in the past
- return ret;
-}
-
-
-void ParticleType::calcSystemOffset()
-{
- if(!m_system)
- return;
- QPointF lastOffset = m_systemOffset;
- m_systemOffset = this->mapFromItem(m_system, QPointF());
- if(lastOffset != m_systemOffset){
- //Reload all particles
- foreach(const QString &g, m_particles){
- int gId = m_system->m_groupIds[g];
- for(int i=0; i<m_system->m_groupData[gId]->size; i++)
- reload(m_system->m_data[m_system->m_groupData[gId]->start + i]);
- }
- }
-}
-QT_END_NAMESPACE
diff --git a/src/imports/particles/speedlimitaffector.h b/src/imports/particles/particles.cpp
index b3858a2a9d..b30beb5c74 100644
--- a/src/imports/particles/speedlimitaffector.h
+++ b/src/imports/particles/particles.cpp
@@ -1,10 +1,10 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
-** This file is part of the Declarative module of the Qt Toolkit.
+** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
@@ -39,51 +39,31 @@
**
****************************************************************************/
-#ifndef SPEEDLIMITAFFECTOR_H
-#define SPEEDLIMITAFFECTOR_H
-#include "particleaffector.h"
+#include <QtDeclarative/qdeclarativeextensionplugin.h>
+#include <QtDeclarative/qdeclarative.h>
-QT_BEGIN_HEADER
+#include "V1/qdeclarativeparticles_p.h"
QT_BEGIN_NAMESPACE
-QT_MODULE(Declarative)
-
-class SpeedLimitAffector : public ParticleAffector
+class QParticlesQmlModule : public QDeclarativeExtensionPlugin
{
Q_OBJECT
- Q_PROPERTY(qreal speedLimit READ speedLimit WRITE setSpeedLimit NOTIFY speedLimitChanged)
-
-
public:
- explicit SpeedLimitAffector(QSGItem *parent = 0);
-
- qreal speedLimit() const
+ virtual void registerTypes(const char *uri)
{
- return m_speedLimit;
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.particles"));
+ qmlRegisterType<QDeclarativeParticleMotion>(uri,1,0,"ParticleMotion");
+ qmlRegisterType<QDeclarativeParticleMotionGravity>(uri,1,0,"ParticleMotionGravity");
+ qmlRegisterType<QDeclarativeParticleMotionLinear>(uri,1,0,"ParticleMotionLinear");
+ qmlRegisterType<QDeclarativeParticleMotionWander>(uri,1,0,"ParticleMotionWander");
+ qmlRegisterType<QDeclarativeParticles>(uri,1,0,"Particles");
}
-
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
-signals:
-
- void speedLimitChanged(qreal arg);
-
-public slots:
-void setSpeedLimit(qreal arg)
-{
- if (m_speedLimit != arg) {
- m_speedLimit = arg;
- emit speedLimitChanged(arg);
- }
-}
-
-private:
-qreal m_speedLimit;
};
QT_END_NAMESPACE
-QT_END_HEADER
+#include "particles.moc"
+
+Q_EXPORT_PLUGIN2(qmlparticlesplugin, QT_PREPEND_NAMESPACE(QParticlesQmlModule));
-#endif // SPEEDLIMITAFFECTOR_H
diff --git a/src/imports/particles/particles.pro b/src/imports/particles/particles.pro
index a6930fe95c..56f663f328 100644
--- a/src/imports/particles/particles.pro
+++ b/src/imports/particles/particles.pro
@@ -3,118 +3,17 @@ TARGETPATH = Qt/labs/particles
include(../qimportbase.pri)
HEADERS += \
- V1/qdeclarativeparticles_p.h \
- spritestate.h \
- pluginmain.h \
- particleaffector.h \
- wanderaffector.h \
- #rockingaffector.h \
- #scalingaffector.h \
- driftaffector.h \
- particleemitter.h \
- particlesystem.h \
- trailsemitter.h \
- #spriteemitter.h \
- particle.h \
- coloredparticle.h \
- spriteparticle.h \
- spritegoalaffector.h \
- #zoneaffector.h \
- frictionaffector.h \
- gravitationalsingularityaffector.h \
- killaffector.h \
- speedlimitaffector.h \
- spriteengine.h \
- gravityaffector.h \
- attractoraffector.h \
- meanderaffector.h \
- #toggleaffector.h \
- spriteimage.h \
- #pairedparticle.h \
- followemitter.h \
- swarmaffector.h \
- turbulenceaffector.h \
- particleextruder.h \
- ellipseextruder.h \
- maskextruder.h \
- varyingvector.h \
- pointvector.h \
- angledvector.h \
- directedvector.h \
- #modelparticle.h \
- eternalaffector.h \
- lineextruder.h \
- resetaffector.h \
- deformableparticle.h \
- pictureaffector.h \
- superparticle.h \
- ultraparticle.h \
- burstemitter.h \
- dataparticle.h \
- itemparticle.h
+ V1/qdeclarativeparticles_p.h
SOURCES += \
- V1/qdeclarativeparticles.cpp \
- spritestate.cpp \
- main.cpp \
- particleaffector.cpp \
- wanderaffector.cpp \
- #rockingaffector.cpp \
- #scalingaffector.cpp \
- driftaffector.cpp \
- particleemitter.cpp \
- particlesystem.cpp \
- trailsemitter.cpp \
- #spriteemitter.cpp \
- particle.cpp \
- coloredparticle.cpp \
- spriteparticle.cpp \
- spritegoalaffector.cpp \
- #zoneaffector.cpp \
- frictionaffector.cpp \
- gravitationalsingularityaffector.cpp \
- killaffector.cpp \
- speedlimitaffector.cpp \
- spriteengine.cpp \
- gravityaffector.cpp \
- attractoraffector.cpp \
- meanderaffector.cpp \
- #toggleaffector.cpp \
- spriteimage.cpp \
- #pairedparticle.cpp \
- followemitter.cpp \
- swarmaffector.cpp \
- turbulenceaffector.cpp \
- particleextruder.cpp \
- ellipseextruder.cpp \
- maskextruder.cpp \
- varyingvector.cpp \
- pointvector.cpp \
- angledvector.cpp \
- directedvector.cpp \
- #modelparticle.cpp \
- eternalaffector.cpp \
- lineextruder.cpp \
- resetaffector.cpp \
- deformableparticle.cpp \
- pictureaffector.cpp \
- superparticle.cpp \
- ultraparticle.cpp \
- burstemitter.cpp \
- dataparticle.cpp \
- itemparticle.cpp
-
-QT += declarative opengl
-#Because we use QDeclarativePixmapCache once...
-QT += core-private gui-private declarative-private script-private
+ particles.cpp \
+ V1/qdeclarativeparticles.cpp
+QT += declarative opengl core gui declarative-private core-private gui-private
OTHER_FILES += \
qmldir
-RESOURCES += \
- spriteparticles.qrc
-
DESTDIR = $$QT.declarative.imports/$$TARGETPATH
target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
diff --git a/src/imports/particles/particlesystem.cpp b/src/imports/particles/particlesystem.cpp
deleted file mode 100644
index 0c9180c2d8..0000000000
--- a/src/imports/particles/particlesystem.cpp
+++ /dev/null
@@ -1,396 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "particlesystem.h"
-#include <qsgnode.h>
-#include "particleemitter.h"
-#include "particleaffector.h"
-#include "particle.h"
-#include <cmath>
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-ParticleData::ParticleData()
- : group(0)
- , e(0)
- , particleIndex(0)
- , systemIndex(0)
-{
- pv.x = 0;
- pv.y = 0;
- pv.t = -1;
- pv.size = 0;
- pv.endSize = 0;
- pv.sx = 0;
- pv.sy = 0;
- pv.ax = 0;
- pv.ay = 0;
-}
-
-ParticleSystem::ParticleSystem(QSGItem *parent) :
- QSGItem(parent), m_particle_count(0), m_running(true) , m_startTime(0), m_overwrite(false)
-{
- m_groupIds = QHash<QString, int>();
-}
-
-void ParticleSystem::registerParticleType(ParticleType* p)
-{
- m_particles << QPointer<ParticleType>(p);//###Set or uniqueness checking?
- reset();
-}
-
-void ParticleSystem::registerParticleEmitter(ParticleEmitter* e)
-{
- m_emitters << QPointer<ParticleEmitter>(e);//###How to get them out?
- connect(e, SIGNAL(particleCountChanged()),
- this, SLOT(countChanged()));
- connect(e, SIGNAL(particleChanged(QString)),
- this, SLOT(countChanged()));
- reset();
-}
-
-void ParticleSystem::registerParticleAffector(ParticleAffector* a)
-{
- m_affectors << QPointer<ParticleAffector>(a);
- //reset();//TODO: Slim down the huge batch of resets at the start
-}
-
-void ParticleSystem::countChanged()
-{
- reset();//Need to give Particles new Count
-}
-
-void ParticleSystem::setRunning(bool arg)
-{
- if (m_running != arg) {
- m_running = arg;
- emit runningChanged(arg);
- reset();
- }
-}
-
-void ParticleSystem::componentComplete()
-{
- QSGItem::componentComplete();
- reset();
-}
-
-void ParticleSystem::initializeSystem()
-{
- int oldCount = m_particle_count;
- m_particle_count = 0;//TODO: Only when changed?
-
- //### Reset the data too?
- for(int i=0; i<oldCount; i++){
- if(m_data[i]){
- delete m_data[i];
- m_data[i] = 0;
- }
- }
-
- for(QHash<int, GroupData*>::iterator iter = m_groupData.begin(); iter != m_groupData.end(); iter++)
- delete (*iter);
- m_groupData.clear();
- m_groupIds.clear();
-
- GroupData* gd = new GroupData;//Default group
- gd->size = 0;
- gd->start = -1;
- gd->nextIdx = 0;
- m_groupData.insert(0,gd);
- m_groupIds.insert("",0);
- m_nextGroupId = 1;
-
- if(!m_emitters.count() || !m_particles.count())
- return;
-
- foreach(ParticleEmitter* e, m_emitters){
- if(!m_groupIds.contains(e->particle())
- || (!e->particle().isEmpty() && !m_groupIds[e->particle()])){//or it was accidentally inserted by a failed lookup earlier
- GroupData* gd = new GroupData;
- gd->size = 0;
- gd->start = -1;
- gd->nextIdx = 0;
- int id = m_nextGroupId++;
- m_groupIds.insert(e->particle(), id);
- m_groupData.insert(id, gd);
- }
- m_groupData[m_groupIds[e->particle()]]->size += e->particleCount();
- }
-
- for(QHash<int, GroupData*>::iterator iter = m_groupData.begin(); iter != m_groupData.end(); iter++){
- (*iter)->start = m_particle_count;
- m_particle_count += (*iter)->size;
- }
- m_data.resize(m_particle_count);
- for(int i=oldCount; i<m_particle_count; i++)
- m_data[i] = 0;//setup new ones
-
- if(m_particle_count > 16000)
- qWarning() << "Particle system contains a vast number of particles (>16000). Expect poor performance";
-
- foreach(ParticleType* particle, m_particles){
- int particleCount = 0;
- if(particle->particles().isEmpty()){//Uses default particle
- particleCount += m_groupData[0]->size;
- m_groupData[0]->types << particle;
- }else{
- foreach(const QString &group, particle->particles()){
- particleCount += m_groupData[m_groupIds[group]]->size;
- m_groupData[m_groupIds[group]]->types << particle;
- }
- }
- particle->setCount(particleCount);
- particle->m_pleaseReset = true;
- }
-
- m_timestamp.start();
- m_initialized = true;
- emit systemInitialized();
- qDebug() << "System Initialized. Size:" << m_particle_count;
-}
-
-void ParticleSystem::reset()
-{
- //Clear guarded pointers which have been deleted
- int cleared = 0;
- cleared += m_emitters.removeAll(0);
- cleared += m_particles.removeAll(0);
- cleared += m_affectors.removeAll(0);
- //qDebug() << "Reset" << m_emitters.count() << m_particles.count() << "Cleared" << cleared;
- foreach(ParticleType* p, m_particles)
- p->reset();
- foreach(ParticleEmitter* e, m_emitters)
- e->reset();
- if(!m_running)
- return;
- initializeSystem();
- foreach(ParticleType* p, m_particles)
- p->update();
- foreach(ParticleEmitter* e, m_emitters)
- e->emitWindow(0);//Start, so that starttime factors appropriately
-}
-
-ParticleData* ParticleSystem::newDatum(int groupId)
-{
- Q_ASSERT(groupId < m_groupData.count());//XXX shouldn't really be an assert
- Q_ASSERT(m_groupData[groupId]->size);
- int nextIdx = m_groupData[groupId]->start + m_groupData[groupId]->nextIdx++;
- if( m_groupData[groupId]->nextIdx >= m_groupData[groupId]->size)
- m_groupData[groupId]->nextIdx = 0;
-
- Q_ASSERT(nextIdx < m_data.size());
- ParticleData* ret;
- if(m_data[nextIdx]){//Recycle, it's faster.
- ret = m_data[nextIdx];
- if(!m_overwrite && ret->stillAlive()){
- return 0;//Artificial longevity (or too fast emission) means this guy hasn't died. To maintain count, don't emit a new one
- }//###Reset?
- }else{
- ret = new ParticleData;
- m_data[nextIdx] = ret;
- }
-
- ret->system = this;
- ret->systemIndex = nextIdx;
- ret->particleIndex = nextIdx - m_groupData[groupId]->start;
- ret->group = groupId;
- return ret;
-}
-
-void ParticleSystem::emitParticle(ParticleData* pd)
-{// called from prepareNextFrame()->emitWindow - enforce?
- //Account for relative emitter position
- QPointF offset = this->mapFromItem(pd->e, QPointF(0, 0));
- if(!offset.isNull()){
- pd->pv.x += offset.x();
- pd->pv.y += offset.y();
- }
-
- foreach(ParticleAffector *a, m_affectors)
- if(a && a->m_needsReset)
- a->reset(pd->systemIndex);
- foreach(ParticleType* p, m_groupData[pd->group]->types)
- if(p)
- p->load(pd);
-}
-
-
-
-qint64 ParticleSystem::systemSync(ParticleType* p)
-{
- if (!m_running)
- return 0;
- if (!m_initialized)
- return 0;//error in initialization
-
- if(m_syncList.isEmpty() || m_syncList.contains(p)){//Need to advance the simulation
- m_syncList.clear();
-
- //### Elapsed time never shrinks - may cause problems if left emitting for weeks at a time.
- qreal dt = m_timeInt / 1000.;
- m_timeInt = m_timestamp.elapsed() + m_startTime;
- qreal time = m_timeInt / 1000.;
- dt = time - dt;
- m_needsReset.clear();
- foreach(ParticleEmitter* emitter, m_emitters)
- if(emitter)
- emitter->emitWindow(m_timeInt);
- foreach(ParticleAffector* a, m_affectors)
- if(a)
- a->affectSystem(dt);
- foreach(ParticleData* d, m_needsReset)
- foreach(ParticleType* p, m_groupData[d->group]->types)
- if(p && d)
- p->reload(d);
- }
- m_syncList << p;
- return m_timeInt;
-}
-
-//sets the x accleration without affecting the instantaneous x velocity or position
-void ParticleData::setInstantaneousAX(qreal ax)
-{
- qreal t = (system->m_timeInt / 1000.0) - pv.t;
- qreal sx = (pv.sx + t*pv.ax) - t*ax;
- qreal ex = pv.x + pv.sx * t + 0.5 * pv.ax * t * t;
- qreal x = ex - t*sx - 0.5 * t*t*ax;
-
- pv.ax = ax;
- pv.sx = sx;
- pv.x = x;
-}
-
-//sets the x velocity without affecting the instantaneous x postion
-void ParticleData::setInstantaneousSX(qreal vx)
-{
- qreal t = (system->m_timeInt / 1000.0) - pv.t;
- qreal sx = vx - t*pv.ax;
- qreal ex = pv.x + pv.sx * t + 0.5 * pv.ax * t * t;
- qreal x = ex - t*sx - 0.5 * t*t*pv.ax;
-
- pv.sx = sx;
- pv.x = x;
-}
-
-//sets the instantaneous x postion
-void ParticleData::setInstantaneousX(qreal x)
-{
- qreal t = (system->m_timeInt / 1000.0) - pv.t;
- pv.x = x - t*pv.sx - 0.5 * t*t*pv.ax;
-}
-
-//sets the y accleration without affecting the instantaneous y velocity or position
-void ParticleData::setInstantaneousAY(qreal ay)
-{
- qreal t = (system->m_timeInt / 1000.0) - pv.t;
- qreal sy = (pv.sy + t*pv.ay) - t*ay;
- qreal ey = pv.y + pv.sy * t + 0.5 * pv.ay * t * t;
- qreal y = ey - t*sy - 0.5 * t*t*ay;
-
- pv.ay = ay;
- pv.sy = sy;
- pv.y = y;
-}
-
-//sets the y velocity without affecting the instantaneous y position
-void ParticleData::setInstantaneousSY(qreal vy)
-{
- qreal t = (system->m_timeInt / 1000.0) - pv.t;
- //qDebug() << t << (system->m_timeInt/1000.0) << pv.x << pv.sx << pv.ax << pv.x + pv.sx * t + 0.5 * pv.ax * t * t;
- qreal sy = vy - t*pv.ay;
- qreal ey = pv.y + pv.sy * t + 0.5 * pv.ay * t * t;
- qreal y = ey - t*sy - 0.5 * t*t*pv.ay;
-
- pv.sy = sy;
- pv.y = y;
-}
-
-//sets the instantaneous Y position
-void ParticleData::setInstantaneousY(qreal y)
-{
- qreal t = (system->m_timeInt / 1000.0) - pv.t;
- pv.y = y - t*pv.sy - 0.5 * t*t*pv.ay;
-}
-
-qreal ParticleData::curX() const
-{
- qreal t = (system->m_timeInt / 1000.0) - pv.t;
- return pv.x + pv.sx * t + 0.5 * pv.ax * t * t;
-}
-
-qreal ParticleData::curSX() const
-{
- qreal t = (system->m_timeInt / 1000.0) - pv.t;
- return pv.sx + t*pv.ax;
-}
-
-qreal ParticleData::curY() const
-{
- qreal t = (system->m_timeInt / 1000.0) - pv.t;
- return pv.y + pv.sy * t + 0.5 * pv.ay * t * t;
-}
-
-qreal ParticleData::curSY() const
-{
- qreal t = (system->m_timeInt / 1000.0) - pv.t;
- return pv.sy + t*pv.ay;
-}
-
-void ParticleData::debugDump()
-{
- qDebug() << "Particle" << group
- << "Pos: " << pv.x << "," << pv.y
- << "Vel: " << pv.sx << "," << pv.sy
- << "Acc: " << pv.ax << "," << pv.ay
- << "Size: " << pv.size << "," << pv.endSize
- << "Time: " << pv.t << "," <<pv.lifeSpan;
-}
-
-bool ParticleData::stillAlive()
-{
- if(!system)
- return false;
- return (pv.t + pv.lifeSpan) > (system->m_timeInt/1000.0);
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/particles/pictureaffector.cpp b/src/imports/particles/pictureaffector.cpp
deleted file mode 100644
index 636e26b830..0000000000
--- a/src/imports/particles/pictureaffector.cpp
+++ /dev/null
@@ -1,118 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "pictureaffector.h"
-#include "coloredparticle.h"
-#include <QDebug>
-#include <private/qsgtexture_p.h>
-#include <private/qdeclarativepixmapcache_p.h>
-
-QT_BEGIN_NAMESPACE
-
-PictureAffector::PictureAffector(QSGItem *parent) :
- ParticleAffector(parent), m_pix(0)
-{
- m_needsReset = true;
-}
-
-void PictureAffector::reset(int systemIdx)
-{
- ParticleAffector::reset(systemIdx);
-}
-
-void PictureAffector::startLoadImage()
-{
- if(m_pix)
- m_pix->clear();
- else
- m_pix = new QDeclarativePixmap();
- m_pix->load(qmlEngine(this), m_image, QDeclarativePixmap::Cache);
- if(m_pix->isReady())
- loadImage();
- else
- m_pix->connectFinished(this, SLOT(loadImage()));
-}
-void PictureAffector::loadImage()
-{
- m_loadedImage = m_pix->pixmap().toImage();
- if(m_loadedImage.isNull())
- qWarning() << "PictureAffector could not load picture " << m_image;
-}
-
-bool PictureAffector::affectParticle(ParticleData *d, qreal dt)
-{
- Q_UNUSED(dt);
- if(!width() || !height()){
- qWarning() << "PictureAffector needs a size";
- return false;
- }
-
- if(m_loadedImage.isNull())
- return false;
-
- if(m_loadedImage.size()!=QSize(width(), height()))
- m_loadedImage = m_loadedImage.scaled(width(), height());//TODO: Aspect Ratio Control?
-
- bool affected = false;
- QPoint pos = QPoint(d->curX() - m_offset.x(), d->curY() - m_offset.y());
- if(!QRect(0,0,width(),height()).contains(pos)){
- //XXX: Just a debugging helper, as I don't think it can get here.
- qWarning() << "PictureAffector gives up.";
- return false;
- }
- Color4ub c;
- QRgb col = m_loadedImage.pixel(pos);
- c.a = qAlpha(col);
- c.b = qBlue(col);
- c.g = qGreen(col);
- c.r = qRed(col);
- foreach(ParticleType *p, m_system->m_groupData[d->group]->types){
- if(qobject_cast<ColoredParticle*>(p)){
- ColoredParticle* cp = qobject_cast<ColoredParticle*>(p);
- cp->reloadColor(c, d);
- affected = true;
- }
- }
-
- return affected;//Doesn't affect particle data, but necessary for onceOff
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/particles/pictureaffector.h b/src/imports/particles/pictureaffector.h
deleted file mode 100644
index 4e0141d00a..0000000000
--- a/src/imports/particles/pictureaffector.h
+++ /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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef PICTUREAFFECTOR_H
-#define PICTUREAFFECTOR_H
-#include "particleaffector.h"
-#include <QDebug>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class QDeclarativePixmap;
-class PictureAffector : public ParticleAffector
-{
- Q_OBJECT
- //Usually want to use "particles" to target just colored stuff, and save performance
- //Use onceOff (inherited) to determine if this is an emitter modification or a more constant enforcer
- Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
- //TODO: Bool smooth, where it interpolates
-public:
- explicit PictureAffector(QSGItem *parent = 0);
-
- QUrl image() const
- {
- return m_image;
- }
-
-protected:
- virtual void reset(int systemIdx);
- virtual bool affectParticle(ParticleData *d, qreal dt);
-signals:
-
- void imageChanged(QUrl arg);
-
-public slots:
- void setImage(QUrl arg)
- {
- if (m_image != arg) {
- m_image = arg;
- startLoadImage();
- emit imageChanged(arg);
- }
- }
-
-private slots:
- void loadImage();
-private:
- void startLoadImage();
- QUrl m_image;
- QDeclarativePixmap* m_pix;
- QImage m_loadedImage;
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // PICTUREAFFECTOR_H
diff --git a/src/imports/particles/pluginmain.h b/src/imports/particles/pluginmain.h
deleted file mode 100644
index cd8760d1a0..0000000000
--- a/src/imports/particles/pluginmain.h
+++ /dev/null
@@ -1,65 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef PLUGINMAIN_H
-#define PLUGINMAIN_H
-
-#include <QtDeclarative>
-#include <QtDeclarative/QDeclarativeExtensionPlugin>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class ParticlesPlugin : public QDeclarativeExtensionPlugin
-{
- Q_OBJECT
-public:
- virtual void registerTypes(const char *uri);
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // PLUGINMAIN_H
diff --git a/src/imports/particles/resetaffector.cpp b/src/imports/particles/resetaffector.cpp
deleted file mode 100644
index 0598298f27..0000000000
--- a/src/imports/particles/resetaffector.cpp
+++ /dev/null
@@ -1,78 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "resetaffector.h"
-#include <cmath>
-QT_BEGIN_NAMESPACE
-ResetAffector::ResetAffector(QSGItem *parent) :
- ParticleAffector(parent)
-{
-}
-
-void ResetAffector::reset(int idx)
-{
- ParticleAffector::reset(idx);
- if(m_data[idx])
- delete m_data[idx];
- m_data.insert(idx, 0);//TODO: Either load with data now, or get data next tick whether active or not
-}
-
-bool ResetAffector::affectParticle(ParticleData *d, qreal dt)
-{
- TrajectoryData* trajectory;
- if(m_data[d->systemIndex]){
- trajectory = m_data[d->systemIndex];
- //TODO: Faster to calculate once (not 4 times)
- d->setInstantaneousSX(trajectory->sx);
- d->setInstantaneousSY(trajectory->sy);
- d->setInstantaneousAX(trajectory->ax);
- d->setInstantaneousAY(trajectory->ay);
- }else{
- trajectory = new TrajectoryData;
- }
- trajectory->sx = d->pv.sx;
- trajectory->sy = d->pv.sy;
- trajectory->ax = d->pv.ax;
- trajectory->ay = d->pv.ay;
- m_data.insert(d->systemIndex, trajectory);//overwrites
- return true;
-}
-QT_END_NAMESPACE
diff --git a/src/imports/particles/resetaffector.h b/src/imports/particles/resetaffector.h
deleted file mode 100644
index 6a4e2b7983..0000000000
--- a/src/imports/particles/resetaffector.h
+++ /dev/null
@@ -1,75 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef RESETAFFECTOR_H
-#define RESETAFFECTOR_H
-#include "particleaffector.h"
-#include <QHash>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-struct TrajectoryData{
- qreal sx,sy,ax,ay;
-};
-
-class ResetAffector : public ParticleAffector
-{
- Q_OBJECT
-public:
- explicit ResetAffector(QSGItem *parent = 0);
- virtual void reset(int systemIdx);
-
-signals:
-
-public slots:
-protected:
- virtual bool affectParticle(ParticleData *d, qreal dt);
-private:
- QHash<int, TrajectoryData*> m_data;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // RESETAFFECTOR_H
diff --git a/src/imports/particles/speedlimitaffector.cpp b/src/imports/particles/speedlimitaffector.cpp
deleted file mode 100644
index c226404b01..0000000000
--- a/src/imports/particles/speedlimitaffector.cpp
+++ /dev/null
@@ -1,77 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "speedlimitaffector.h"
-#include <cmath>
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-SpeedLimitAffector::SpeedLimitAffector(QSGItem *parent) :
- ParticleAffector(parent), m_speedLimit(-1)
-{
-}
-
-bool SpeedLimitAffector::affectParticle(ParticleData *d, qreal dt){
- Q_UNUSED(dt);
- if(m_speedLimit <= 0)
- return false;
-
- qreal x = d->curSX();
- qreal y = d->curSY();
- qreal s = sqrt(x*x + y*y);
- if(s <= m_speedLimit)
- return false;
-
-
- if(s >= m_speedLimit*1.01){
- qreal theta = atan2(y,x);
- d->setInstantaneousSX(m_speedLimit * cos(theta));
- d->setInstantaneousSY(m_speedLimit * sin(theta));
- }
-
- d->setInstantaneousAY(0);
- d->setInstantaneousAX(0);
-
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/particles/spriteparticle.cpp b/src/imports/particles/spriteparticle.cpp
deleted file mode 100644
index 6039d2819b..0000000000
--- a/src/imports/particles/spriteparticle.cpp
+++ /dev/null
@@ -1,449 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "spriteparticle.h"
-#include "spritestate.h"
-#include "spriteengine.h"
-#include "particleemitter.h"
-#include <private/qsgcontext_p.h>
-#include <private/qsgadaptationlayer_p.h>
-#include <qsgnode.h>
-#include <qsgtexturematerial.h>
-#include <qsgengine.h>
-#include <qsgtexture.h>
-#include <QFile>
-#include <cmath>
-#include <qmath.h>
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-class SpriteParticlesMaterial : public QSGMaterial
-{
-public:
- SpriteParticlesMaterial();
- virtual ~SpriteParticlesMaterial();
- virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const
- {
- return this - static_cast<const SpriteParticlesMaterial *>(other);
- }
-
- QSGTexture *texture;
-
- qreal timestamp;
- int framecount;
- int animcount;
-};
-
-SpriteParticlesMaterial::SpriteParticlesMaterial()
- : timestamp(0)
- , framecount(1)
- , animcount(1)
-{
- setFlag(Blending, true);
-}
-
-SpriteParticlesMaterial::~SpriteParticlesMaterial()
-{
- delete texture;
-}
-
-class SpriteParticlesMaterialData : public QSGMaterialShader
-{
-public:
- SpriteParticlesMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
- {
- QFile vf(vertexFile ? vertexFile : ":resources/spritevertex.shader");
- vf.open(QFile::ReadOnly);
- m_vertex_code = vf.readAll();
-
- QFile ff(fragmentFile ? fragmentFile : ":resources/spritefragment.shader");
- ff.open(QFile::ReadOnly);
- m_fragment_code = ff.readAll();
-
- Q_ASSERT(!m_vertex_code.isNull());
- Q_ASSERT(!m_fragment_code.isNull());
- }
-
- void deactivate() {
- QSGMaterialShader::deactivate();
-
- for (int i=0; i<8; ++i) {
- program()->setAttributeArray(i, GL_FLOAT, chunkOfBytes, 1, 0);
- }
- }
-
- virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
- {
- SpriteParticlesMaterial *m = static_cast<SpriteParticlesMaterial *>(newEffect);
- m->texture->bind();
-
- program()->setUniformValue(m_opacity_id, state.opacity());
- program()->setUniformValue(m_timestamp_id, (float) m->timestamp);
- program()->setUniformValue(m_framecount_id, (float) m->framecount);
- program()->setUniformValue(m_animcount_id, (float) m->animcount);
-
- if (state.isMatrixDirty())
- program()->setUniformValue(m_matrix_id, state.combinedMatrix());
- }
-
- virtual void initialize() {
- m_matrix_id = program()->uniformLocation("matrix");
- m_opacity_id = program()->uniformLocation("opacity");
- m_timestamp_id = program()->uniformLocation("timestamp");
- m_framecount_id = program()->uniformLocation("framecount");
- m_animcount_id = program()->uniformLocation("animcount");
- }
-
- virtual const char *vertexShader() const { return m_vertex_code.constData(); }
- virtual const char *fragmentShader() const { return m_fragment_code.constData(); }
-
- virtual char const *const *attributeNames() const {
- static const char *attr[] = {
- "vPos",
- "vTex",
- "vData",
- "vVec",
- "vAnimData",
- 0
- };
- return attr;
- }
-
- virtual bool isColorTable() const { return false; }
-
- int m_matrix_id;
- int m_opacity_id;
- int m_timestamp_id;
- int m_framecount_id;
- int m_animcount_id;
-
- QByteArray m_vertex_code;
- QByteArray m_fragment_code;
-
- static float chunkOfBytes[1024];
-};
-float SpriteParticlesMaterialData::chunkOfBytes[1024];
-
-QSGMaterialShader *SpriteParticlesMaterial::createShader() const
-{
- return new SpriteParticlesMaterialData;
-}
-
-struct SpriteParticleVertex {
- float x;
- float y;
- float tx;
- float ty;
- float t;
- float lifeSpan;
- float size;
- float endSize;
- float sx;
- float sy;
- float ax;
- float ay;
- float animIdx;
- float frameDuration;
- float frameCount;
- float animT;
-};
-
-struct SpriteParticleVertices {
- SpriteParticleVertex v1;
- SpriteParticleVertex v2;
- SpriteParticleVertex v3;
- SpriteParticleVertex v4;
-};
-
-SpriteParticle::SpriteParticle(QSGItem *parent) :
- ParticleType(parent)
- , m_node(0)
- , m_material(0)
- , m_spriteEngine(0)
-{
- setFlag(ItemHasContents);
- }
-QDeclarativeListProperty<SpriteState> SpriteParticle::sprites()
-{
- return QDeclarativeListProperty<SpriteState>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
-}
-
-void SpriteParticle::createEngine()
-{
- if(m_spriteEngine)
- delete m_spriteEngine;
- if(m_sprites.count())
- m_spriteEngine = new SpriteEngine(m_sprites, this);
- else
- m_spriteEngine = 0;
- reset();//###this is probably out of updatePaintNode and shouldn't be
-}
-
-void SpriteParticle::setCount(int c)
-{
- ParticleType::setCount(c);
- m_pleaseReset = true;
-}
-
-static QSGGeometry::Attribute SpriteParticle_Attributes[] = {
- { 0, 2, GL_FLOAT }, // Position
- { 1, 2, GL_FLOAT }, // TexCoord
- { 2, 4, GL_FLOAT }, // Data
- { 3, 4, GL_FLOAT }, // Vectors
- { 4, 4, GL_FLOAT } // Colors
-};
-
-static QSGGeometry::AttributeSet SpriteParticle_AttributeSet =
-{
- 5, // Attribute Count
- (2 + 2 + 4 + 4 + 4) * sizeof(float),
- SpriteParticle_Attributes
-};
-
-
-
-QSGGeometryNode* SpriteParticle::buildParticleNode()
-{
- if (m_count * 4 > 0xffff) {
- qWarning() << "SpriteParticle: too many particles...";
- return 0;
- }
-
- if (m_count * 4 == 0) {
- qWarning() << "SpriteParticle: No particles...";
- return 0;
- }
-
- if (!m_spriteEngine) {
- qWarning() << "SpriteParticle: No sprite engine...";
- return 0;
- }
-
- if (m_material) {
- delete m_material;
- m_material = 0;
- }
-
- m_material = new SpriteParticlesMaterial();
-
- QImage image = m_spriteEngine->assembledImage();
- if(image.isNull())
- return 0;
- m_material->texture = sceneGraphEngine()->createTextureFromImage(image);
- m_material->texture->setFiltering(QSGTexture::Linear);
- m_material->framecount = m_spriteEngine->maxFrames();
- m_spriteEngine->setCount(m_count);
-
- int vCount = m_count * 4;
- int iCount = m_count * 6;
- QSGGeometry *g = new QSGGeometry(SpriteParticle_AttributeSet, vCount, iCount);
- g->setDrawingMode(GL_TRIANGLES);
-
- SpriteParticleVertex *vertices = (SpriteParticleVertex *) g->vertexData();
- for (int p=0; p<m_count; ++p) {
-
- for (int i=0; i<4; ++i) {
- vertices[i].x = 0;
- vertices[i].y = 0;
- vertices[i].t = -1;
- vertices[i].lifeSpan = -1;
- vertices[i].size = 0;
- vertices[i].endSize = 0;
- vertices[i].sx = 0;
- vertices[i].sy = 0;
- vertices[i].ax = 0;
- vertices[i].ay = 0;
- vertices[i].animIdx = 0;
- vertices[i].frameDuration = 1;
- vertices[i].frameCount = 1;
- vertices[i].animT = -1;
-
- }
-
- vertices[0].tx = 0;
- vertices[0].ty = 0;
-
- vertices[1].tx = 1.0;
- vertices[1].ty = 0;
-
- vertices[2].tx = 0;
- vertices[2].ty = 1.0;
-
- vertices[3].tx = 1.0;
- vertices[3].ty = 1.0;
-
- vertices += 4;
- }
-
- quint16 *indices = g->indexDataAsUShort();
- for (int i=0; i<m_count; ++i) {
- int o = i * 4;
- indices[0] = o;
- indices[1] = o + 1;
- indices[2] = o + 2;
- indices[3] = o + 1;
- indices[4] = o + 3;
- indices[5] = o + 2;
- indices += 6;
- }
-
-
- m_node = new QSGGeometryNode();
- m_node->setGeometry(g);
- m_node->setMaterial(m_material);
- m_last_particle = 0;
- return m_node;
-}
-
-void SpriteParticle::vertexCopy(SpriteParticleVertex &b,const ParticleVertex& a)
-{
- b.x = a.x + m_systemOffset.x();
- b.y = a.y + m_systemOffset.y();
- b.t = a.t;
- b.lifeSpan = a.lifeSpan;
- b.size = a.size;
- b.endSize = a.endSize;
- b.sx = a.sx;
- b.sy = a.sy;
- b.ax = a.ax;
- b.ay = a.ay;
-}
-
-void SpriteParticle::load(ParticleData *d)
-{
- if (m_node == 0) //error creating node
- return;
-
- SpriteParticleVertices *particles = (SpriteParticleVertices *) m_node->geometry()->vertexData();
- int pos = particleTypeIndex(d);
- SpriteParticleVertices &p = particles[pos];
-
- // Initial Sprite State
- m_spriteEngine->startSprite(pos);
- p.v1.animT = p.v2.animT = p.v3.animT = p.v4.animT = p.v1.t;
- p.v1.animIdx = p.v2.animIdx = p.v3.animIdx = p.v4.animIdx = 0;
- p.v1.frameCount = p.v2.frameCount = p.v3.frameCount = p.v4.frameCount = m_spriteEngine->spriteFrames(pos);
- p.v1.frameDuration = p.v2.frameDuration = p.v3.frameDuration = p.v4.frameDuration = m_spriteEngine->spriteDuration(pos);
-
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-
-}
-
-void SpriteParticle::reload(ParticleData *d)
-{
- if (m_node == 0) //error creating node
- return;
-
- SpriteParticleVertices *particles = (SpriteParticleVertices *) m_node->geometry()->vertexData();
- int pos = particleTypeIndex(d);
- SpriteParticleVertices &p = particles[pos];
-
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-
-QSGNode *SpriteParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
-{
- if(m_pleaseReset){
- if(m_node)
- delete m_node;
- if(m_material)
- delete m_material;
-
- m_node = 0;
- m_material = 0;
- m_pleaseReset = false;
- }
- if(m_system&& m_system->isRunning())
- prepareNextFrame();
- if (m_node){
- update();
- m_node->markDirty(QSGNode::DirtyMaterial);
- }
-
- return m_node;
-}
-
-void SpriteParticle::prepareNextFrame()
-{
- if (m_node == 0){ //TODO: Staggered loading (as emitted) (is it just moving this check to load()?)
- m_node = buildParticleNode();
- if(m_node == 0)
- return;
- }
- qint64 timeStamp = m_system->systemSync(this);
-
-
- qreal time = timeStamp / 1000.;
- m_material->timestamp = time;
- m_material->animcount = m_spriteEngine->spriteCount();
-
- //Advance State
- SpriteParticleVertices *particles = (SpriteParticleVertices *) m_node->geometry()->vertexData();
- m_spriteEngine->updateSprites(timeStamp);
- for(int i=0; i<m_count; i++){
- SpriteParticleVertices &p = particles[i];
- int curIdx = m_spriteEngine->spriteState(i);
- if(curIdx != p.v1.animIdx){
- p.v1.animIdx = p.v2.animIdx = p.v3.animIdx = p.v4.animIdx = curIdx;
- p.v1.animT = p.v2.animT = p.v3.animT = p.v4.animT = m_spriteEngine->spriteStart(i)/1000.0;
- p.v1.frameCount = p.v2.frameCount = p.v3.frameCount = p.v4.frameCount = m_spriteEngine->spriteFrames(i);
- p.v1.frameDuration = p.v2.frameDuration = p.v3.frameDuration = p.v4.frameDuration = m_spriteEngine->spriteDuration(i);
- }
- }
-}
-
-void SpriteParticle::reset()
-{
- ParticleType::reset();
- m_pleaseReset = true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/particles/spriteparticle.h b/src/imports/particles/spriteparticle.h
deleted file mode 100644
index f28d198600..0000000000
--- a/src/imports/particles/spriteparticle.h
+++ /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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef SPRITEPARTICLE_H
-#define SPRITEPARTICLE_H
-#include "particle.h"
-#include <QDeclarativeListProperty>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class SpriteState;
-class SpriteEngine;
-class QSGGeometryNode;
-class SpriteParticlesMaterial;
-class SpriteParticleVertex;
-
-class SpriteParticle : public ParticleType
-{
- Q_OBJECT
- Q_PROPERTY(QDeclarativeListProperty<SpriteState> sprites READ sprites)
- Q_CLASSINFO("DefaultProperty", "sprites")
-public:
- explicit SpriteParticle(QSGItem *parent = 0);
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
-
- QDeclarativeListProperty<SpriteState> sprites();
- SpriteEngine* spriteEngine() {return m_spriteEngine;}
-signals:
-
-public slots:
-protected:
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- void reset();
- void prepareNextFrame();
- QSGGeometryNode* buildParticleNode();
-private slots:
- void createEngine();
-private:
- QSGGeometryNode *m_node;
- SpriteParticlesMaterial *m_material;
-
- int m_particle_duration;
- int m_last_particle;
-
- QList<SpriteState*> m_sprites;
- SpriteEngine* m_spriteEngine;
-
- void vertexCopy(SpriteParticleVertex &b,const ParticleVertex& a);
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // SPRITEPARTICLE_H
diff --git a/src/imports/particles/spriteparticles.qrc b/src/imports/particles/spriteparticles.qrc
deleted file mode 100644
index 0232c3c9f9..0000000000
--- a/src/imports/particles/spriteparticles.qrc
+++ /dev/null
@@ -1,22 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>resources/spritefragment.shader</file>
- <file>resources/spritevertex.shader</file>
- <file>resources/ctfragment.shader</file>
- <file>resources/ctvertex.shader</file>
- <file>resources/trailsfragment.shader</file>
- <file>resources/trailsvertex.shader</file>
- <file>resources/spriteimagefragment.shader</file>
- <file>resources/spriteimagevertex.shader</file>
- <file>resources/identitytable.png</file>
- <file>resources/defaultFadeInOut.png</file>
- <file>resources/deformablefragment.shader</file>
- <file>resources/deformablevertex.shader</file>
- <file>resources/ultravertex.shader</file>
- <file>resources/ultrafragment.shader</file>
- <file>resources/supervertex.shader</file>
- <file>resources/superfragment.shader</file>
- <file>resources/simplevertex.shader</file>
- <file>resources/simplefragment.shader</file>
- </qresource>
-</RCC>
diff --git a/src/imports/particles/superparticle.cpp b/src/imports/particles/superparticle.cpp
deleted file mode 100644
index 811b6a4ba8..0000000000
--- a/src/imports/particles/superparticle.cpp
+++ /dev/null
@@ -1,511 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <private/qsgcontext_p.h>
-#include <private/qsgadaptationlayer_p.h>
-#include <qsgnode.h>
-#include <qsgtexturematerial.h>
-#include <qsgtexture.h>
-#include <QFile>
-#include "superparticle.h"
-#include "particleemitter.h"
-#include <QGLFunctions>
-#include <qsgengine.h>
-
-QT_BEGIN_NAMESPACE
-
-const float CONV = 0.017453292519943295;
-class SuperMaterial : public QSGMaterial
-{
-public:
- SuperMaterial()
- : timestamp(0)
- {
- setFlag(Blending, true);
- }
-
- ~SuperMaterial()
- {
- delete texture;
- delete colortable;
- delete sizetable;
- delete opacitytable;
- }
-
- virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const
- {
- return this - static_cast<const SuperMaterial *>(other);
- }
-
- QSGTexture *texture;
- QSGTexture *colortable;
- QSGTexture *sizetable;
- QSGTexture *opacitytable;
-
- qreal timestamp;
-};
-
-
-class SuperMaterialData : public QSGMaterialShader
-{
-public:
- SuperMaterialData(const char *vertexFile = 0, const char *fragmentFile = 0)
- {
- QFile vf(vertexFile ? vertexFile : ":resources/supervertex.shader");
- vf.open(QFile::ReadOnly);
- m_vertex_code = vf.readAll();
-
- QFile ff(fragmentFile ? fragmentFile : ":resources/superfragment.shader");
- ff.open(QFile::ReadOnly);
- m_fragment_code = ff.readAll();
-
- Q_ASSERT(!m_vertex_code.isNull());
- Q_ASSERT(!m_fragment_code.isNull());
- }
-
- void deactivate() {
- QSGMaterialShader::deactivate();
-
- for (int i=0; i<8; ++i) {
- program()->setAttributeArray(i, GL_FLOAT, chunkOfBytes, 1, 0);
- }
- }
-
- virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
- {
- SuperMaterial *m = static_cast<SuperMaterial *>(newEffect);
- state.context()->functions()->glActiveTexture(GL_TEXTURE0);
- m->texture->bind();
-
- state.context()->functions()->glActiveTexture(GL_TEXTURE1);
- m->colortable->bind();
- program()->setUniformValue(m_colortable_id, 1);
-
- state.context()->functions()->glActiveTexture(GL_TEXTURE2);
- m->sizetable->bind();
- program()->setUniformValue(m_sizetable_id, 2);
-
- state.context()->functions()->glActiveTexture(GL_TEXTURE3);
- m->opacitytable->bind();
- program()->setUniformValue(m_opacitytable_id, 3);
-
- program()->setUniformValue(m_opacity_id, state.opacity());
- program()->setUniformValue(m_timestamp_id, (float) m->timestamp);
-
- if (state.isMatrixDirty())
- program()->setUniformValue(m_matrix_id, state.combinedMatrix());
- }
-
- virtual void initialize() {
- m_colortable_id = program()->uniformLocation("colortable");
- m_sizetable_id = program()->uniformLocation("sizetable");
- m_opacitytable_id = program()->uniformLocation("opacitytable");
- m_matrix_id = program()->uniformLocation("matrix");
- m_opacity_id = program()->uniformLocation("opacity");
- m_timestamp_id = program()->uniformLocation("timestamp");
- }
-
- virtual const char *vertexShader() const { return m_vertex_code.constData(); }
- virtual const char *fragmentShader() const { return m_fragment_code.constData(); }
-
- virtual char const *const *attributeNames() const {
- static const char *attr[] = {
- "vPos",
- "vTex",
- "vData",
- "vVec",
- "vColor",
- "vDeformVec",
- "vRotation",
- 0
- };
- return attr;
- }
-
- virtual bool isColorTable() const { return false; }
-
- int m_matrix_id;
- int m_opacity_id;
- int m_timestamp_id;
- int m_colortable_id;
- int m_sizetable_id;
- int m_opacitytable_id;
-
- QByteArray m_vertex_code;
- QByteArray m_fragment_code;
-
- static float chunkOfBytes[1024];
-};
-float SuperMaterialData::chunkOfBytes[1024];
-
-
-QSGMaterialShader *SuperMaterial::createShader() const
-{
- return new SuperMaterialData;
-}
-
-SuperParticle::SuperParticle(QSGItem* parent)
- : ParticleType(parent)
- , m_do_reset(false)
- , m_color(Qt::white)
- , m_color_variation(0.5)
- , m_node(0)
- , m_material(0)
- , m_alphaVariation(0.0)
- , m_alpha(1.0)
- , m_redVariation(0.0)
- , m_greenVariation(0.0)
- , m_blueVariation(0.0)
-{
- setFlag(ItemHasContents);
-}
-
-void SuperParticle::setImage(const QUrl &image)
-{
- if (image == m_image_name)
- return;
- m_image_name = image;
- emit imageChanged();
- reset();
-}
-
-
-void SuperParticle::setColortable(const QUrl &table)
-{
- if (table == m_colortable_name)
- return;
- m_colortable_name = table;
- emit colortableChanged();
- reset();
-}
-
-void SuperParticle::setSizetable(const QUrl &table)
-{
- if (table == m_sizetable_name)
- return;
- m_sizetable_name = table;
- emit sizetableChanged();
- reset();
-}
-
-void SuperParticle::setOpacitytable(const QUrl &table)
-{
- if (table == m_opacitytable_name)
- return;
- m_opacitytable_name = table;
- emit opacitytableChanged();
- reset();
-}
-
-void SuperParticle::setColor(const QColor &color)
-{
- if (color == m_color)
- return;
- m_color = color;
- emit colorChanged();
- //m_system->pleaseReset();//XXX
-}
-
-void SuperParticle::setColorVariation(qreal var)
-{
- if (var == m_color_variation)
- return;
- m_color_variation = var;
- emit colorVariationChanged();
- //m_system->pleaseReset();//XXX
-}
-
-void SuperParticle::setCount(int c)
-{
- ParticleType::setCount(c);
- m_pleaseReset = true;
-}
-
-void SuperParticle::reset()
-{
- ParticleType::reset();
- m_pleaseReset = true;
-}
-
-static QSGGeometry::Attribute SuperParticle_Attributes[] = {
- { 0, 2, GL_FLOAT }, // Position
- { 1, 2, GL_FLOAT }, // TexCoord
- { 2, 4, GL_FLOAT }, // Data
- { 3, 4, GL_FLOAT }, // Vectors
- { 4, 4, GL_UNSIGNED_BYTE }, // Colors
- { 5, 4, GL_FLOAT }, // DeformationVectors
- { 6, 3, GL_FLOAT } // Rotation
-};
-
-static QSGGeometry::AttributeSet SuperParticle_AttributeSet =
-{
- 7, // Attribute Count
- (2 + 2 + 4 + 4 + 4 + 3) * sizeof(float) + 4 * sizeof(uchar),
- SuperParticle_Attributes
-};
-
-QSGGeometryNode* SuperParticle::buildParticleNode()
-{
- if (m_count * 4 > 0xffff) {
- printf("SuperParticle: Too many particles... \n");
- return 0;
- }
-
- if(m_count <= 0) {
- printf("SuperParticle: Too few particles... \n");
- return 0;
- }
-
- QImage image(m_image_name.toLocalFile());
- if (image.isNull()) {
- printf("SuperParticle: loading image failed... '%s'\n", qPrintable(m_image_name.toLocalFile()));
- return 0;
- }
-
- int vCount = m_count * 4;
- int iCount = m_count * 6;
-
- QSGGeometry *g = new QSGGeometry(SuperParticle_AttributeSet, vCount, iCount);
- g->setDrawingMode(GL_TRIANGLES);
-
- SuperVertex *vertices = (SuperVertex *) g->vertexData();
- for (int p=0; p<m_count; ++p) {
-
- for (int i=0; i<4; ++i) {
- vertices[i].x = 0;
- vertices[i].y = 0;
- vertices[i].t = -1;
- vertices[i].lifeSpan = 0;
- vertices[i].size = 0;
- vertices[i].endSize = 0;
- vertices[i].sx = 0;
- vertices[i].sy = 0;
- vertices[i].ax = 0;
- vertices[i].ay = 0;
- vertices[i].xx = 1;
- vertices[i].xy = 0;
- vertices[i].yx = 0;
- vertices[i].yy = 1;
- vertices[i].rotation = 0;
- vertices[i].rotationSpeed = 0;
- vertices[i].autoRotate = 0;
- }
-
- vertices[0].tx = 0;
- vertices[0].ty = 0;
-
- vertices[1].tx = 1;
- vertices[1].ty = 0;
-
- vertices[2].tx = 0;
- vertices[2].ty = 1;
-
- vertices[3].tx = 1;
- vertices[3].ty = 1;
-
- vertices += 4;
- }
-
- quint16 *indices = g->indexDataAsUShort();
- for (int i=0; i<m_count; ++i) {
- int o = i * 4;
- indices[0] = o;
- indices[1] = o + 1;
- indices[2] = o + 2;
- indices[3] = o + 1;
- indices[4] = o + 3;
- indices[5] = o + 2;
- indices += 6;
- }
-
- if (m_material) {
- delete m_material;
- m_material = 0;
- }
-
- QImage colortable(m_colortable_name.toLocalFile());
- QImage sizetable(m_sizetable_name.toLocalFile());
- QImage opacitytable(m_opacitytable_name.toLocalFile());
- m_material = new SuperMaterial();
- if(colortable.isNull())
- colortable = QImage(":resources/identitytable.png");
- if(sizetable.isNull())
- sizetable = QImage(":resources/identitytable.png");
- if(opacitytable.isNull())
- opacitytable = QImage(":resources/defaultFadeInOut.png");
- Q_ASSERT(!colortable.isNull());
- Q_ASSERT(!sizetable.isNull());
- Q_ASSERT(!opacitytable.isNull());
- m_material->colortable = sceneGraphEngine()->createTextureFromImage(colortable);
- m_material->sizetable = sceneGraphEngine()->createTextureFromImage(sizetable);
- m_material->opacitytable = sceneGraphEngine()->createTextureFromImage(opacitytable);
-
- m_material->texture = sceneGraphEngine()->createTextureFromImage(image);
- m_material->texture->setFiltering(QSGTexture::Linear);
-
- m_node = new QSGGeometryNode();
- m_node->setGeometry(g);
- m_node->setMaterial(m_material);
-
- m_last_particle = 0;
-
- return m_node;
-}
-
-QSGNode *SuperParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
-{
- if(m_pleaseReset){
- if(m_node)
- delete m_node;
- if(m_material)
- delete m_material;
-
- m_node = 0;
- m_material = 0;
- m_pleaseReset = false;
- }
-
- if(m_system && m_system->isRunning())
- prepareNextFrame();
- if (m_node){
- update();
- m_node->markDirty(QSGNode::DirtyMaterial);
- }
-
- return m_node;
-}
-
-void SuperParticle::prepareNextFrame()
-{
- if (m_node == 0){ //TODO: Staggered loading (as emitted)
- m_node = buildParticleNode();
- if(m_node == 0)
- return;
- }
- qint64 timeStamp = m_system->systemSync(this);
-
- qreal time = timeStamp / 1000.;
- m_material->timestamp = time;
-}
-
-void SuperParticle::reloadColor(const Color4ub &c, ParticleData* d)
-{
- SuperVertices *particles = (SuperVertices *) m_node->geometry()->vertexData();
- int pos = particleTypeIndex(d);
- SuperVertices &p = particles[pos];
- p.v1.color = p.v2.color = p.v3.color = p.v4.color = c;
-}
-
-void SuperParticle::vertexCopy(SuperVertex &b,const ParticleVertex& a)
-{
- b.x = a.x - m_systemOffset.x();
- b.y = a.y - m_systemOffset.y();
- b.t = a.t;
- b.lifeSpan = a.lifeSpan;
- b.size = a.size;
- b.endSize = a.endSize;
- b.sx = a.sx;
- b.sy = a.sy;
- b.ax = a.ax;
- b.ay = a.ay;
-}
-
-void SuperParticle::reload(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- SuperVertices *particles = (SuperVertices *) m_node->geometry()->vertexData();
-
- int pos = particleTypeIndex(d);
-
- SuperVertices &p = particles[pos];
-
- //Perhaps we could be more efficient?
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-void SuperParticle::load(ParticleData *d)
-{
- if (m_node == 0)
- return;
-
- //Color initialization
- // Particle color
- Color4ub color;
- qreal redVariation = m_color_variation + m_redVariation;
- qreal greenVariation = m_color_variation + m_greenVariation;
- qreal blueVariation = m_color_variation + m_blueVariation;
- color.r = m_color.red() * (1 - redVariation) + rand() % 256 * redVariation;
- color.g = m_color.green() * (1 - greenVariation) + rand() % 256 * greenVariation;
- color.b = m_color.blue() * (1 - blueVariation) + rand() % 256 * blueVariation;
- color.a = m_alpha * m_color.alpha() * (1 - m_alphaVariation) + rand() % 256 * m_alphaVariation;
- SuperVertices *particles = (SuperVertices *) m_node->geometry()->vertexData();
- SuperVertices &p = particles[particleTypeIndex(d)];
- p.v1.color = p.v2.color = p.v3.color = p.v4.color = color;
- if(m_xVector){
- const QPointF &ret = m_xVector->sample(QPointF(d->pv.x, d->pv.y));
- p.v1.xx = p.v2.xx = p.v3.xx = p.v4.xx = ret.x();
- p.v1.xy = p.v2.xy = p.v3.xy = p.v4.xy = ret.y();
- }
- if(m_yVector){
- const QPointF &ret = m_yVector->sample(QPointF(d->pv.x, d->pv.y));
- p.v1.yx = p.v2.yx = p.v3.yx = p.v4.yx = ret.x();
- p.v1.yy = p.v2.yy = p.v3.yy = p.v4.yy = ret.y();
- }
- p.v1.rotation = p.v2.rotation = p.v3.rotation = p.v4.rotation =
- (m_rotation + (m_rotationVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationVariation) ) * CONV;
- p.v1.rotationSpeed = p.v2.rotationSpeed = p.v3.rotationSpeed = p.v4.rotationSpeed =
- (m_rotationSpeed + (m_rotationSpeedVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationSpeedVariation) ) * CONV;
- p.v1.autoRotate = p.v2.autoRotate = p.v3.autoRotate = p.v4.autoRotate = m_autoRotation?1.0:0.0;
-
- vertexCopy(p.v1, d->pv);
- vertexCopy(p.v2, d->pv);
- vertexCopy(p.v3, d->pv);
- vertexCopy(p.v4, d->pv);
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/particles/superparticle.h b/src/imports/particles/superparticle.h
deleted file mode 100644
index ac2f9860ef..0000000000
--- a/src/imports/particles/superparticle.h
+++ /dev/null
@@ -1,389 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef SUPERPARTICLE_H
-#define SUPERPARTICLE_H
-#include "particle.h"
-#include "varyingvector.h"
-
-#include "coloredparticle.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class SuperMaterial;
-class QSGGeometryNode;
-
-/*struct Color4ub {//in coloredparticle
- uchar r;
- uchar g;
- uchar b;
- uchar a;
-};*/
-
-struct SuperVertex {
- float x;
- float y;
- float tx;
- float ty;
- float t;
- float lifeSpan;
- float size;
- float endSize;
- float sx;
- float sy;
- float ax;
- float ay;
- Color4ub color;
- float xx;
- float xy;
- float yx;
- float yy;
- float rotation;
- float rotationSpeed;
- float autoRotate;//Assume that GPUs prefer floats to bools
-};
-
-struct SuperVertices {
- SuperVertex v1;
- SuperVertex v2;
- SuperVertex v3;
- SuperVertex v4;
-};
-
-class SuperParticle : public ParticleType
-{
- Q_OBJECT
- Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
- Q_PROPERTY(QUrl colorTable READ colortable WRITE setColortable NOTIFY colortableChanged)
- Q_PROPERTY(QUrl sizeTable READ sizetable WRITE setSizetable NOTIFY sizetableChanged)
- Q_PROPERTY(QUrl opacityTable READ opacitytable WRITE setOpacitytable NOTIFY opacitytableChanged)
-
- Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
- //Stacks (added) with individual colorVariations
- Q_PROPERTY(qreal colorVariation READ colorVariation WRITE setColorVariation NOTIFY colorVariationChanged)
- Q_PROPERTY(qreal redVariation READ redVariation WRITE setRedVariation NOTIFY redVariationChanged)
- Q_PROPERTY(qreal greenVariation READ greenVariation WRITE setGreenVariation NOTIFY greenVariationChanged)
- Q_PROPERTY(qreal blueVariation READ blueVariation WRITE setBlueVariation NOTIFY blueVariationChanged)
- //Stacks (multiplies) with the Alpha in the color, mostly here so you can use svg color names (which have full alpha)
- Q_PROPERTY(qreal alpha READ alpha WRITE setAlpha NOTIFY alphaChanged)
- Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged)
-
- Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
- Q_PROPERTY(qreal rotationVariation READ rotationVariation WRITE setRotationVariation NOTIFY rotationVariationChanged)
- Q_PROPERTY(qreal rotationSpeed READ rotationSpeed WRITE setRotationSpeed NOTIFY rotationSpeedChanged)
- Q_PROPERTY(qreal rotationSpeedVariation READ rotationSpeedVariation WRITE setRotationSpeedVariation NOTIFY rotationSpeedVariationChanged)
- //If true, then will face the direction of motion. Stacks with rotation, e.g. setting rotation
- //to 180 will lead to facing away from the direction of motion
- Q_PROPERTY(bool autoRotation READ autoRotation WRITE autoRotation NOTIFY autoRotationChanged)
-
- //###Call i/j? Makes more sense to those with vector calculus experience, and I could even add the cirumflex in QML?
- //xVector is the vector from the top-left point to the top-right point, and is multiplied by current size
- Q_PROPERTY(VaryingVector* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged)
- //yVector is the same, but top-left to bottom-left. The particle is always a parallelogram.
- Q_PROPERTY(VaryingVector* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged)
-public:
- explicit SuperParticle(QSGItem *parent = 0);
- virtual ~SuperParticle(){}
-
- virtual void load(ParticleData*);
- virtual void reload(ParticleData*);
- virtual void setCount(int c);
-
- QUrl image() const { return m_image_name; }
- void setImage(const QUrl &image);
-
- QUrl colortable() const { return m_colortable_name; }
- void setColortable(const QUrl &table);
-
- QUrl sizetable() const { return m_sizetable_name; }
- void setSizetable (const QUrl &table);
-
- QUrl opacitytable() const { return m_opacitytable_name; }
- void setOpacitytable(const QUrl &table);
-
- QColor color() const { return m_color; }
- void setColor(const QColor &color);
-
- qreal colorVariation() const { return m_color_variation; }
- void setColorVariation(qreal var);
-
- qreal renderOpacity() const { return m_render_opacity; }
-
- qreal alphaVariation() const
- {
- return m_alphaVariation;
- }
-
- qreal alpha() const
- {
- return m_alpha;
- }
-
- qreal redVariation() const
- {
- return m_redVariation;
- }
-
- qreal greenVariation() const
- {
- return m_greenVariation;
- }
-
- qreal blueVariation() const
- {
- return m_blueVariation;
- }
-
- qreal rotation() const
- {
- return m_rotation;
- }
-
- qreal rotationVariation() const
- {
- return m_rotationVariation;
- }
-
- qreal rotationSpeed() const
- {
- return m_rotationSpeed;
- }
-
- qreal rotationSpeedVariation() const
- {
- return m_rotationSpeedVariation;
- }
-
- bool autoRotation() const
- {
- return m_autoRotation;
- }
-
- VaryingVector* xVector() const
- {
- return m_xVector;
- }
-
- VaryingVector* yVector() const
- {
- return m_yVector;
- }
-
-signals:
-
- void imageChanged();
- void colortableChanged();
- void sizetableChanged();
- void opacitytableChanged();
-
- void colorChanged();
- void colorVariationChanged();
-
- void particleDurationChanged();
- void alphaVariationChanged(qreal arg);
-
- void alphaChanged(qreal arg);
-
- void redVariationChanged(qreal arg);
-
- void greenVariationChanged(qreal arg);
-
- void blueVariationChanged(qreal arg);
-
- void rotationChanged(qreal arg);
-
- void rotationVariationChanged(qreal arg);
-
- void rotationSpeedChanged(qreal arg);
-
- void rotationSpeedVariationChanged(qreal arg);
-
- void autoRotationChanged(bool arg);
-
- void xVectorChanged(VaryingVector* arg);
-
- void yVectorChanged(VaryingVector* arg);
-
-public slots:
- void setAlphaVariation(qreal arg)
- {
- if (m_alphaVariation != arg) {
- m_alphaVariation = arg;
- emit alphaVariationChanged(arg);
- }
- }
-
- void setAlpha(qreal arg)
- {
- if (m_alpha != arg) {
- m_alpha = arg;
- emit alphaChanged(arg);
- }
- }
-
- void setRedVariation(qreal arg)
- {
- if (m_redVariation != arg) {
- m_redVariation = arg;
- emit redVariationChanged(arg);
- }
- }
-
- void setGreenVariation(qreal arg)
- {
- if (m_greenVariation != arg) {
- m_greenVariation = arg;
- emit greenVariationChanged(arg);
- }
- }
-
- void setBlueVariation(qreal arg)
- {
- if (m_blueVariation != arg) {
- m_blueVariation = arg;
- emit blueVariationChanged(arg);
- }
- }
-
- void reloadColor(const Color4ub &c, ParticleData* d);
- void setRotation(qreal arg)
- {
- if (m_rotation != arg) {
- m_rotation = arg;
- emit rotationChanged(arg);
- }
- }
-
- void setRotationVariation(qreal arg)
- {
- if (m_rotationVariation != arg) {
- m_rotationVariation = arg;
- emit rotationVariationChanged(arg);
- }
- }
-
- void setRotationSpeed(qreal arg)
- {
- if (m_rotationSpeed != arg) {
- m_rotationSpeed = arg;
- emit rotationSpeedChanged(arg);
- }
- }
-
- void setRotationSpeedVariation(qreal arg)
- {
- if (m_rotationSpeedVariation != arg) {
- m_rotationSpeedVariation = arg;
- emit rotationSpeedVariationChanged(arg);
- }
- }
-
- void autoRotation(bool arg)
- {
- if (m_autoRotation != arg) {
- m_autoRotation = arg;
- emit autoRotationChanged(arg);
- }
- }
-
- void setXVector(VaryingVector* arg)
- {
- if (m_xVector != arg) {
- m_xVector = arg;
- emit xVectorChanged(arg);
- }
- }
-
- void setYVector(VaryingVector* arg)
- {
- if (m_yVector != arg) {
- m_yVector = arg;
- emit yVectorChanged(arg);
- }
- }
-
-protected:
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
- void reset();
- void prepareNextFrame();
- QSGGeometryNode* buildParticleNode();
-private:
- void vertexCopy(SuperVertex &b,const ParticleVertex& a);
- bool m_do_reset;
-
- QUrl m_image_name;
- QUrl m_colortable_name;
- QUrl m_sizetable_name;
- QUrl m_opacitytable_name;
-
-
- QColor m_color;
- qreal m_color_variation;
- qreal m_particleDuration;
-
- QSGGeometryNode *m_node;
- SuperMaterial *m_material;
-
- // derived values...
- int m_last_particle;
-
- qreal m_render_opacity;
- qreal m_alphaVariation;
- qreal m_alpha;
- qreal m_redVariation;
- qreal m_greenVariation;
- qreal m_blueVariation;
- qreal m_rotation;
- qreal m_rotationVariation;
- qreal m_rotationSpeed;
- qreal m_rotationSpeedVariation;
- bool m_autoRotation;
- VaryingVector* m_xVector;
- VaryingVector* m_yVector;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // SUPERPARTICLE_H
diff --git a/src/imports/particles/swarmaffector.cpp b/src/imports/particles/swarmaffector.cpp
deleted file mode 100644
index 513e8a17a7..0000000000
--- a/src/imports/particles/swarmaffector.cpp
+++ /dev/null
@@ -1,114 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "swarmaffector.h"
-#include "particle.h"
-#include <cmath>
-#include <QDebug>
-QT_BEGIN_NAMESPACE
-
-SwarmAffector::SwarmAffector(QSGItem *parent) :
- ParticleAffector(parent), m_strength(1), m_inited(false)
-{
- connect(this, SIGNAL(leadersChanged(QStringList)),
- this, SLOT(updateGroupList()));
-}
-
-void SwarmAffector::ensureInit()
-{
- if(m_inited)
- return;
- m_inited = true;
- updateGroupList();
- m_lastPos.resize(m_system->count());
-}
-
-const qreal epsilon = 0.0000001;
-bool SwarmAffector::affectParticle(ParticleData *d, qreal dt)
-{
- ensureInit();
- QPointF curPos(d->curX(), d->curY());
- if(m_leaders.isEmpty() || m_leadGroups.contains(d->group)){
- m_lastPos[d->systemIndex] = curPos;
- if(m_leadGroups.contains(d->group))
- return false;
- }
-
- qreal fx = 0.0;
- qreal fy = 0.0;
- for(int i=0; i < m_lastPos.count(); i++){
- if(m_lastPos[i].isNull())
- continue;
- QPointF diff = m_lastPos[i] - curPos;
- qreal r = sqrt(diff.x() * diff.x() + diff.y() * diff.y());
- if(r == 0.0)
- continue;
- qreal f = m_strength * (1/r);
- if(f < epsilon)
- continue;
- qreal theta = atan2(diff.y(), diff.x());
- fx += cos(theta) * f;
- fy += sin(theta) * f;
- }
- if(!fx && !fy)
- return false;
- d->setInstantaneousSX(d->curSX()+fx * dt);
- d->setInstantaneousSY(d->curSY()+fy * dt);
- return true;
-}
-
-void SwarmAffector::reset(int systemIdx)
-{
- if(!m_system)
- return;
- if(!m_lastPos[systemIdx].isNull())
- m_lastPos[systemIdx] = QPointF();
-}
-
-void SwarmAffector::updateGroupList()
-{
- if(!m_system || !m_system->m_initialized)
- return;
- m_leadGroups.clear();
- foreach(const QString &s, m_leaders)
- m_leadGroups << m_system->m_groupIds[s];
-}
-QT_END_NAMESPACE
diff --git a/src/imports/particles/swarmaffector.h b/src/imports/particles/swarmaffector.h
deleted file mode 100644
index 63f77c9294..0000000000
--- a/src/imports/particles/swarmaffector.h
+++ /dev/null
@@ -1,116 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef SWARMAFFECTOR_H
-#define SWARMAFFECTOR_H
-#include "particleaffector.h"
-#include <QDeclarativeListProperty>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-
-class ParticleType;
-
-class SwarmAffector : public ParticleAffector
-{
- Q_OBJECT
- Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
- Q_PROPERTY(QStringList leaders READ leaders WRITE setLeaders NOTIFY leadersChanged)
-public:
- explicit SwarmAffector(QSGItem *parent = 0);
- virtual bool affectParticle(ParticleData *d, qreal dt);
- virtual void reset(int systemIdx);
-
- qreal strength() const
- {
- return m_strength;
- }
-
- QStringList leaders() const
- {
- return m_leaders;
- }
-
-signals:
-
- void strengthChanged(qreal arg);
-
- void leadersChanged(QStringList arg);
-
-public slots:
-
-void setStrength(qreal arg)
-{
- if (m_strength != arg) {
- m_strength = arg;
- emit strengthChanged(arg);
- }
-}
-
-void setLeaders(QStringList arg)
-{
- if (m_leaders != arg) {
- m_leaders = arg;
- emit leadersChanged(arg);
- }
-}
-
-private:
- void ensureInit();
- void mapUpdate(int idx, qreal strength);
- QVector<QPointF> m_lastPos;
- qreal m_strength;
- bool m_inited;
- QStringList m_leaders;
- QSet<int> m_leadGroups;
-private slots:
- void updateGroupList();
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // SWARMAFFECTOR_H
diff --git a/src/imports/particles/toggleaffector.cpp b/src/imports/particles/toggleaffector.cpp
deleted file mode 100644
index 5e03b17684..0000000000
--- a/src/imports/particles/toggleaffector.cpp
+++ /dev/null
@@ -1,59 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "toggleaffector.h"
-
-QT_BEGIN_NAMESPACE
-
-ToggleAffector::ToggleAffector(QObject *parent) :
- ParticleAffector(parent)
-{
-}
-
-bool ToggleAffector::affect(ParticleData *d, qreal dt)
-{
- if(m_affecting)
- return m_affector->affect(d, dt);
- else
- return false;
-}
-
-QT_END_NAMESPACE
diff --git a/src/imports/particles/toggleaffector.h b/src/imports/particles/toggleaffector.h
deleted file mode 100644
index 08e7c0e2eb..0000000000
--- a/src/imports/particles/toggleaffector.h
+++ /dev/null
@@ -1,102 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef TOGGLEAFFECTOR_H
-#define TOGGLEAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class ToggleAffector : public ParticleAffector
-{
- Q_OBJECT
- Q_PROPERTY(bool affecting READ affecting WRITE setAffecting NOTIFY affectingChanged)
- Q_PROPERTY(ParticleAffector* affector READ affector WRITE affector NOTIFY affectorChanged)
- Q_CLASSINFO("DefaultProperty", "affector")
-
-public:
- explicit ToggleAffector(QObject *parent = 0);
- virtual bool affect(ParticleData *d, qreal dt);
- bool affecting() const
- {
- return m_affecting;
- }
-
- ParticleAffector* affector() const
- {
- return m_affector;
- }
-
-signals:
-
- void affectingChanged(bool arg);
-
- void affectorChanged(ParticleAffector* arg);
-
-public slots:
-void setAffecting(bool arg)
-{
- if (m_affecting != arg) {
- m_affecting = arg;
- emit affectingChanged(arg);
- }
-}
-
-void affector(ParticleAffector* arg)
-{
- if (m_affector != arg) {
- m_affector = arg;
- emit affectorChanged(arg);
- }
-}
-
-private:
-bool m_affecting;
-ParticleAffector* m_affector;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // TOGGLEAFFECTOR_H
diff --git a/src/imports/particles/zoneaffector.cpp b/src/imports/particles/zoneaffector.cpp
deleted file mode 100644
index cb7adca795..0000000000
--- a/src/imports/particles/zoneaffector.cpp
+++ /dev/null
@@ -1,68 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "zoneaffector.h"
-#include <QDebug>
-
-QT_BEGIN_NAMESPACE
-
-ZoneAffector::ZoneAffector(QObject *parent) :
- ParticleAffector(parent), m_x(0), m_y(0), m_width(0), m_height(0), m_affector(0)
-{
-}
-
-bool ZoneAffector::affect(ParticleData *d, qreal dt)
-{
- if(!m_affector)
- return false;
- qreal x = d->curX();
- qreal y = d->curY();
- if(x >= m_x && x <= m_x+m_width && y >= m_y && y <= m_y+m_height)
- return m_affector->affect(d, dt);
- return false;
-}
-
-void ZoneAffector::reset(int systemIdx)
-{
- if(m_affector)
- m_affector->reset(systemIdx);
-}
-QT_END_NAMESPACE
diff --git a/src/imports/particles/zoneaffector.h b/src/imports/particles/zoneaffector.h
deleted file mode 100644
index 8c17cedba2..0000000000
--- a/src/imports/particles/zoneaffector.h
+++ /dev/null
@@ -1,159 +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 Declarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ZONEAFFECTOR_H
-#define ZONEAFFECTOR_H
-#include "particleaffector.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class ZoneAffector : public ParticleAffector
-{
- Q_OBJECT
- //TODO: Can we get anchors in here? consider becoming an un-parented QSGItem?
- Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged);
- Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged);
- Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged);
- Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged);
- Q_PROPERTY(ParticleAffector* affector READ affector WRITE affector NOTIFY affectorChanged)
- Q_CLASSINFO("DefaultProperty", "affector")
-public:
- explicit ZoneAffector(QObject *parent = 0);
-
- virtual bool affect(ParticleData *d, qreal dt);
- virtual void reset(int systemIdx);
-
- ParticleAffector* affector() const
- {
- return m_affector;
- }
-
- qreal x() const
- {
- return m_x;
- }
-
- qreal y() const
- {
- return m_y;
- }
-
- qreal width() const
- {
- return m_width;
- }
-
- qreal height() const
- {
- return m_height;
- }
-
-signals:
-
-
- void affectorChanged(ParticleAffector* arg);
-
- void xChanged(qreal arg);
-
- void yChanged(qreal arg);
-
- void widthChanged(qreal arg);
-
- void heightChanged(qreal arg);
-
-public slots:
-
-
-void affector(ParticleAffector* arg)
-{
- if (m_affector != arg) {
- m_affector = arg;
- emit affectorChanged(arg);
- }
-}
-
-void setX(qreal arg)
-{
- if (m_x != arg) {
- m_x = arg;
- emit xChanged(arg);
- }
-}
-
-void setY(qreal arg)
-{
- if (m_y != arg) {
- m_y = arg;
- emit yChanged(arg);
- }
-}
-
-void setWidth(qreal arg)
-{
- if (m_width != arg) {
- m_width = arg;
- emit widthChanged(arg);
- }
-}
-
-void setHeight(qreal arg)
-{
- if (m_height != arg) {
- m_height = arg;
- emit heightChanged(arg);
- }
-}
-
-private:
-qreal m_x;
-qreal m_y;
-qreal m_width;
-qreal m_height;
-ParticleAffector* m_affector;
-};
-
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif // ZONEAFFECTOR_H
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro
index 20fa8548fd..9ef9ce8a16 100644
--- a/tests/auto/declarative/declarative.pro
+++ b/tests/auto/declarative/declarative.pro
@@ -34,6 +34,7 @@ contains(QT_CONFIG, private_tests) {
qdeclarativebehaviors \
qdeclarativebinding \
qdeclarativeborderimage \
+ qdeclarativechangeset \
qdeclarativeconnection \
qdeclarativedebug \
qdeclarativedebugclient \
diff --git a/tests/auto/declarative/node/tst_nodestest.cpp b/tests/auto/declarative/node/tst_nodestest.cpp
index a1b0a6ac91..fc159b98e9 100644
--- a/tests/auto/declarative/node/tst_nodestest.cpp
+++ b/tests/auto/declarative/node/tst_nodestest.cpp
@@ -196,14 +196,14 @@ public:
if (renderer->rootNode()->parent()) {
// Mark the root dirty to build a clean state from the root and down
- renderer->rootNode()->markDirty(QSGNode::DirtyAll);
+ renderer->rootNode()->markDirty(QSGNode::DirtyForceUpdate);
}
renderer->renderScene();
if (renderer->rootNode()->parent()) {
// Mark the parent of the root dirty to force the root and down to be updated.
- renderer->rootNode()->parent()->markDirty(QSGNode::DirtyAll);
+ renderer->rootNode()->parent()->markDirty(QSGNode::DirtyForceUpdate);
}
}
diff --git a/tests/auto/declarative/qdeclarativechangeset/qdeclarativechangeset.pro b/tests/auto/declarative/qdeclarativechangeset/qdeclarativechangeset.pro
new file mode 100644
index 0000000000..1c9a3c00f9
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativechangeset/qdeclarativechangeset.pro
@@ -0,0 +1,17 @@
+load(qttest_p4)
+contains(QT_CONFIG,declarative): QT += declarative gui
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qdeclarativechangeset.cpp
+
+symbian: {
+ importFiles.files = data
+ importFiles.path = .
+ DEPLOYMENT += importFiles
+} else {
+ DEFINES += SRCDIR=\\\"$$PWD\\\"
+}
+
+CONFIG += parallel_test
+
+QT += core-private gui-private declarative-private
diff --git a/tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp b/tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp
new file mode 100644
index 0000000000..018711ac64
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp
@@ -0,0 +1,614 @@
+/****************************************************************************
+**
+** 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 test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qtest.h>
+#include <private/qdeclarativechangeset_p.h>
+
+#define VERIFY_EXPECTED_OUTPUT
+
+
+
+class tst_qdeclarativemodelchange : public QObject
+{
+ Q_OBJECT
+public:
+ struct Signal
+ {
+ int start;
+ int end;
+ int to;
+
+ bool isInsert() const { return to == -1; }
+ bool isRemove() const { return to == -2; }
+ bool isMove() const { return to >= 0; }
+ bool isChange() const { return to == -3; }
+ };
+
+ static Signal Insert(int start, int end) { Signal signal = { start, end, -1 }; return signal; }
+ static Signal Remove(int start, int end) { Signal signal = { start, end, -2 }; return signal; }
+ static Signal Move(int start, int end, int to) { Signal signal = { start, end, to }; return signal; }
+ static Signal Change(int start, int end) { Signal signal = { start, end, -3 }; return signal; }
+
+ typedef QVector<Signal> SignalList;
+
+
+#ifdef VERIFY_EXPECTED_OUTPUT
+
+ template<typename T>
+ void move(int from, int to, int n, T *items)
+ {
+ if (from > to) {
+ // Only move forwards - flip if backwards moving
+ int tfrom = from;
+ int tto = to;
+ from = tto;
+ to = tto+n;
+ n = tfrom-tto;
+ }
+
+ T replaced;
+ int i=0;
+ typename T::ConstIterator it=items->begin(); it += from+n;
+ for (; i<to-from; ++i,++it)
+ replaced.append(*it);
+ i=0;
+ it=items->begin(); it += from;
+ for (; i<n; ++i,++it)
+ replaced.append(*it);
+ typename T::ConstIterator f=replaced.begin();
+ typename T::Iterator t=items->begin(); t += from;
+ for (; f != replaced.end(); ++f, ++t)
+ *t = *f;
+ }
+
+ QVector<int> applyChanges(const QVector<int> &list, const QVector<Signal> &changes)
+ {
+ QVector<int> alteredList = list;
+ foreach (const Signal &signal, changes) {
+ if (signal.isInsert()) {
+ alteredList.insert(signal.start, signal.end - signal.start, 100);
+ } else if (signal.isRemove()) {
+ alteredList.erase(alteredList.begin() + signal.start, alteredList.begin() + signal.end);
+ } else if (signal.isMove()) {
+ move(signal.start, signal.to, signal.end - signal.start, &alteredList);
+ } else if (signal.isChange()) {
+ for (int i = signal.start; i < signal.end; ++i) {
+ if (alteredList[i] < 100)
+ alteredList[i] = 100;
+ }
+ }
+ }
+ return alteredList;
+ }
+
+#endif
+
+private slots:
+ void sequence_data();
+ void sequence();
+};
+
+bool operator ==(const tst_qdeclarativemodelchange::Signal &left, const tst_qdeclarativemodelchange::Signal &right) {
+ return left.start == right.start && left.end == right.end && left.to == right.to; }
+
+
+QDebug operator <<(QDebug debug, const tst_qdeclarativemodelchange::Signal &signal)
+{
+ if (signal.isInsert())
+ debug.nospace() << "Insert(" << signal.start << "," << signal.end << ")";
+ else if (signal.isRemove())
+ debug.nospace() << "Remove(" << signal.start << "," << signal.end << ")";
+ else if (signal.isMove())
+ debug.nospace() << "Move(" << signal.start << "," << signal.end << "," << signal.to << ")";
+ else if (signal.isChange())
+ debug.nospace() << "Change(" << signal.start << "," << signal.end << ")";
+ return debug;
+}
+
+Q_DECLARE_METATYPE(tst_qdeclarativemodelchange::SignalList)
+
+void tst_qdeclarativemodelchange::sequence_data()
+{
+ QTest::addColumn<SignalList>("input");
+ QTest::addColumn<SignalList>("output");
+
+ // Insert
+ QTest::newRow("i(12-17)")
+ << (SignalList() << Insert(12, 17))
+ << (SignalList() << Insert(12, 17));
+ QTest::newRow("i(2-5),i(12-17)")
+ << (SignalList() << Insert(2, 5) << Insert(12, 17))
+ << (SignalList() << Insert(2, 5) << Insert(12, 17));
+ QTest::newRow("i(12-17),i(2-5)")
+ << (SignalList() << Insert(12, 17) << Insert(2, 5))
+ << (SignalList() << Insert(2, 5) << Insert(15, 20));
+ QTest::newRow("i(12-17),i(12-15)")
+ << (SignalList() << Insert(12, 17) << Insert(12, 15))
+ << (SignalList() << Insert(12, 20));
+ QTest::newRow("i(12-17),i(17-20)")
+ << (SignalList() << Insert(12, 17) << Insert(17, 20))
+ << (SignalList() << Insert(12, 20));
+ QTest::newRow("i(12-17),i(15-18)")
+ << (SignalList() << Insert(12, 17) << Insert(15, 18))
+ << (SignalList() << Insert(12, 20));
+
+ // Remove
+ QTest::newRow("r(3-12)")
+ << (SignalList() << Remove(3, 12))
+ << (SignalList() << Remove(3, 12));
+ QTest::newRow("r(3-7),r(3-5)")
+ << (SignalList() << Remove(3, 7) << Remove(3, 5))
+ << (SignalList() << Remove(3, 9));
+ QTest::newRow("r(4-3),r(14-19)")
+ << (SignalList() << Remove(4, 7) << Remove(14, 19))
+ << (SignalList() << Remove(4, 7) << Remove(14, 19));
+ QTest::newRow("r(14-19),r(4-7)")
+ << (SignalList() << Remove(14, 19) << Remove(4, 7))
+ << (SignalList() << Remove(4, 7) << Remove(11, 16));
+ QTest::newRow("r(4-7),r(2-11)")
+ << (SignalList() << Remove(4, 7) << Remove(2, 11))
+ << (SignalList() << Remove(2, 14));
+
+ // Move
+ QTest::newRow("m(8-10,10)")
+ << (SignalList() << Move(8, 10, 10))
+ << (SignalList() << Move(8, 10, 10));
+ // No merging of moves yet.
+// QTest::newRow("m(5-7,13),m(5-8,12)")
+// << (SignalList() << Move(5, 7, 13) << Move(5, 8, 12))
+// << (SignalList() << Move(5, 10, 10));
+
+ // Change
+ QTest::newRow("c(4-9)")
+ << (SignalList() << Change(4, 9))
+ << (SignalList() << Change(4, 9));
+ QTest::newRow("c(4-9),c(12-14)")
+ << (SignalList() << Change(4, 9) << Change(12, 14))
+ << (SignalList() << Change(4, 9) << Change(12, 14));
+ QTest::newRow("c(12-14),c(4-9)")
+ << (SignalList() << Change(12, 14) << Change(4, 9))
+ << (SignalList() << Change(4, 9) << Change(12, 14));
+ QTest::newRow("c(4-9),c(2-4)")
+ << (SignalList() << Change(4, 9) << Change(2, 4))
+ << (SignalList() << Change(2, 9));
+ QTest::newRow("c(4-9),c(9-11)")
+ << (SignalList() << Change(4, 9) << Change(9, 11))
+ << (SignalList() << Change(4, 11));
+ QTest::newRow("c(4-9),c(3-5)")
+ << (SignalList() << Change(4, 9) << Change(3, 5))
+ << (SignalList() << Change(3, 9));
+ QTest::newRow("c(4-9),c(8-10)")
+ << (SignalList() << Change(4, 9) << Change(8, 10))
+ << (SignalList() << Change(4, 10));
+ QTest::newRow("c(4-9),c(3-5)")
+ << (SignalList() << Change(4, 9) << Change(3, 5))
+ << (SignalList() << Change(3, 9));
+ QTest::newRow("c(4-9),c(2,11)")
+ << (SignalList() << Change(4, 9) << Change(2, 11))
+ << (SignalList() << Change(2, 11));
+ QTest::newRow("c(4-9),c(12-15),c(8-14)")
+ << (SignalList() << Change(4, 9) << Change(12, 15) << Change(8, 14))
+ << (SignalList() << Change(4, 15));
+
+ // Insert, then remove.
+ QTest::newRow("i(12-18),r(12-18)")
+ << (SignalList() << Insert(12, 18) << Remove(12, 18))
+ << (SignalList());
+ QTest::newRow("i(12-18),r(10-14)")
+ << (SignalList() << Insert(12, 18) << Remove(10, 14))
+ << (SignalList() << Remove(10, 12) << Insert(10, 14));
+ QTest::newRow("i(12-18),r(16-20)")
+ << (SignalList() << Insert(12, 18) << Remove(16, 20))
+ << (SignalList() << Remove(12, 14) << Insert(12, 16));
+ QTest::newRow("i(12-18),r(13-17)")
+ << (SignalList() << Insert(12, 18) << Remove(13, 17))
+ << (SignalList() << Insert(12, 14));
+ QTest::newRow("i(12-18),r(14,18)")
+ << (SignalList() << Insert(12, 18) << Remove(14, 18))
+ << (SignalList() << Insert(12, 14));
+ QTest::newRow("i(12-18),r(12-16)")
+ << (SignalList() << Insert(12, 18) << Remove(12, 16))
+ << (SignalList() << Insert(12, 14));
+ QTest::newRow("i(12-18),r(11-19)")
+ << (SignalList() << Insert(12, 18) << Remove(11, 19))
+ << (SignalList() << Remove(11, 13));
+ QTest::newRow("i(12-18),r(8-12)")
+ << (SignalList() << Insert(12, 18) << Remove(8, 12))
+ << (SignalList() << Remove(8, 12) << Insert(8, 14));
+ QTest::newRow("i(12-18),r(2-6)")
+ << (SignalList() << Insert(12, 18) << Remove(2, 6))
+ << (SignalList() << Remove(2, 6) << Insert(8, 14));
+ QTest::newRow("i(12-18),r(18-22)")
+ << (SignalList() << Insert(12, 18) << Remove(18, 22))
+ << (SignalList() << Remove(12, 16) << Insert(12, 18));
+ QTest::newRow("i(12-18),r(20-24)")
+ << (SignalList() << Insert(12, 18) << Remove(20, 24))
+ << (SignalList() << Remove(14, 18) << Insert(12, 18));
+
+ // Insert, then move
+ QTest::newRow("i(12-18),m(12-18,5)")
+ << (SignalList() << Insert(12, 18) << Move(12, 18, 5))
+ << (SignalList() << Insert(5, 11));
+ QTest::newRow("i(12-18),m(10-14,5)")
+ << (SignalList() << Insert(12, 18) << Move(10, 14, 5))
+ << (SignalList() << Insert(5, 7) << Insert(14, 18) << Move(12, 14, 5));
+ QTest::newRow("i(12-18),m(16-20,5)")
+ << (SignalList() << Insert(12, 18) << Move(16, 20, 5))
+ << (SignalList() << Insert(5, 7) << Insert(14, 18) << Move(18, 20, 7));
+ QTest::newRow("i(12-18),m(13-17,5)")
+ << (SignalList() << Insert(12, 18) << Move(13, 17, 5))
+ << (SignalList() << Insert(5, 9) << Insert(16, 18));
+ QTest::newRow("i(12-18),m(14-18,5)")
+ << (SignalList() << Insert(12, 18) << Move(14, 18, 5))
+ << (SignalList() << Insert(5, 9) << Insert(16, 18));
+ QTest::newRow("i(12-18),m(12-16,5)")
+ << (SignalList() << Insert(12, 18) << Move(12, 16, 5))
+ << (SignalList() << Insert(5, 9) << Insert(16, 18));
+ QTest::newRow("i(12-18),m(11-19,5)")
+ << (SignalList() << Insert(12, 18) << Move(11, 19, 5))
+ << (SignalList() << Insert(5, 11) << Move(17, 18, 5) << Move(18, 19, 12));
+ QTest::newRow("i(12-18),m(8-12,5)")
+ << (SignalList() << Insert(12, 18) << Move(8, 12, 5))
+ << (SignalList() << Insert(12, 18) << Move(8, 12, 5));
+ QTest::newRow("i(12-18),m(2-6,5)")
+ << (SignalList() << Insert(12, 18) << Move(2, 6, 5))
+ << (SignalList() << Insert(12, 18) << Move(2, 6, 5));
+ QTest::newRow("i(12-18),m(18-22,5)")
+ << (SignalList() << Insert(12, 18) << Move(18, 22, 5))
+ << (SignalList() << Insert(12, 18) << Move(18, 22, 5));
+ QTest::newRow("i(12-18),m(20-24,5)")
+ << (SignalList() << Insert(12, 18) << Move(20, 24, 5))
+ << (SignalList() << Insert(12, 18) << Move(20, 24, 5));
+
+ QTest::newRow("i(12-18),m(5-13,11)")
+ << (SignalList() << Insert(12, 18) << Move(5, 13, 11))
+ << (SignalList() << Insert(12, 17) << Insert(18, 19) << Move(5, 12, 11));
+
+ QTest::newRow("i(12-18),m(12-18,23)")
+ << (SignalList() << Insert(12, 18) << Move(12, 18, 23))
+ << (SignalList() << Insert(23, 29));
+ QTest::newRow("i(12-18),m(10-14,23)")
+ << (SignalList() << Insert(12, 18) << Move(10, 14, 23))
+ << (SignalList() << Insert(12, 16) << Insert(25, 27) << Move(10, 12, 23));
+ QTest::newRow("i(12-18),m(16-20,23)")
+ << (SignalList() << Insert(12, 18) << Move(16, 20, 23))
+ << (SignalList() << Insert(12, 16) << Insert(25, 27) << Move(16, 18, 25));
+ QTest::newRow("i(12-18),m(13-17,23)")
+ << (SignalList() << Insert(12, 18) << Move(13, 17, 23))
+ << (SignalList() << Insert(12, 14) << Insert(23, 27));
+ QTest::newRow("i(12-18),m(14-18,23)")
+ << (SignalList() << Insert(12, 18) << Move(14, 18, 23))
+ << (SignalList() << Insert(12, 14) << Insert(23, 27));
+ QTest::newRow("i(12-18),m(12-16,23)")
+ << (SignalList() << Insert(12, 18) << Move(12, 16, 23))
+ << (SignalList() << Insert(12, 14) << Insert(23, 27));
+ QTest::newRow("i(12-18),m(11-19,23)")
+ << (SignalList() << Insert(12, 18) << Move(11, 19, 23))
+ << (SignalList() << Insert(25, 31) << Move(11, 12, 24) << Move(11, 12, 30));
+ QTest::newRow("i(12-18),m(8-12,23)")
+ << (SignalList() << Insert(12, 18) << Move(8, 12, 23))
+ << (SignalList() << Insert(12, 18) << Move(8, 12, 23));
+ QTest::newRow("i(12-18),m(2-6,23)")
+ << (SignalList() << Insert(12, 18) << Move(2, 6, 23))
+ << (SignalList() << Insert(12, 18) << Move(2, 6, 23));
+ QTest::newRow("i(12-18),m(18-22,23)")
+ << (SignalList() << Insert(12, 18) << Move(18, 22, 23))
+ << (SignalList() << Insert(12, 18) << Move(18, 22, 23));
+ QTest::newRow("i(12-18),m(20-24,23)")
+ << (SignalList() << Insert(12, 18) << Move(20, 24, 23))
+ << (SignalList() << Insert(12, 18) << Move(20, 24, 23));
+
+ QTest::newRow("i(12-18),m(11-21,23)")
+ << (SignalList() << Insert(12, 18) << Move(11, 21, 23))
+ << (SignalList() << Insert(27, 33) << Move(11, 12, 26) << Move(11, 14, 30));
+
+ // Insert, then change
+ QTest::newRow("i(12-18),c(12-16)")
+ << (SignalList() << Insert(12, 18) << Change(12, 6))
+ << (SignalList() << Insert(12, 18));
+ QTest::newRow("i(12-18),c(10-14)")
+ << (SignalList() << Insert(12, 18) << Change(10, 16))
+ << (SignalList() << Insert(12, 18) << Change(10, 12));
+ QTest::newRow("i(12-18),c(16-20)")
+ << (SignalList() << Insert(12, 18) << Change(16, 20))
+ << (SignalList() << Insert(12, 18) << Change(18, 20));
+ QTest::newRow("i(12-18),c(13-17)")
+ << (SignalList() << Insert(12, 18) << Change(13, 17))
+ << (SignalList() << Insert(12, 18));
+ QTest::newRow("i(12-18),c(14-18)")
+ << (SignalList() << Insert(12, 18) << Change(14, 18))
+ << (SignalList() << Insert(12, 18));
+ QTest::newRow("i(12-18),c(12-16)")
+ << (SignalList() << Insert(12, 18) << Change(12, 16))
+ << (SignalList() << Insert(12, 18));
+ QTest::newRow("i(12-18),c(11-19)")
+ << (SignalList() << Insert(12, 18) << Change(11, 19))
+ << (SignalList() << Insert(12, 18) << Change(11, 12) << Change(18, 19));
+ QTest::newRow("i(12-18),c(8-12)")
+ << (SignalList() << Insert(12, 18) << Change(8, 12))
+ << (SignalList() << Insert(12, 18) << Change(8, 12));
+ QTest::newRow("i(12-18),c(2-6)")
+ << (SignalList() << Insert(12, 18) << Change(2, 6))
+ << (SignalList() << Insert(12, 18) << Change(2, 6));
+ QTest::newRow("i(12-18),c(18-22)")
+ << (SignalList() << Insert(12, 18) << Change(18, 22))
+ << (SignalList() << Insert(12, 18) << Change(18, 22));
+ QTest::newRow("i(12-18),c(20-24)")
+ << (SignalList() << Insert(12, 18) << Change(20, 24))
+ << (SignalList() << Insert(12, 18) << Change(20, 24));
+
+ // Remove, then insert
+ QTest::newRow("r(12-18),i(12-18)")
+ << (SignalList() << Remove(12, 18) << Insert(12, 18))
+ << (SignalList() << Remove(12, 18) << Insert(12, 18));
+ QTest::newRow("r(12-18),i(10-14)")
+ << (SignalList() << Remove(12, 18) << Insert(10, 14))
+ << (SignalList() << Remove(12, 18) << Insert(10, 14));
+ QTest::newRow("r(12-18),i(16-20)")
+ << (SignalList() << Remove(12, 18) << Insert(16, 20))
+ << (SignalList() << Remove(12, 18) << Insert(16, 20));
+ QTest::newRow("r(12-18),i(13-17)")
+ << (SignalList() << Remove(12, 18) << Insert(13, 17))
+ << (SignalList() << Remove(12, 18) << Insert(13, 17));
+ QTest::newRow("r(12-18),i(14-18)")
+ << (SignalList() << Remove(12, 18) << Insert(14, 18))
+ << (SignalList() << Remove(12, 18) << Insert(14, 18));
+ QTest::newRow("r(12-18),i(12-16)")
+ << (SignalList() << Remove(12, 18) << Insert(12, 16))
+ << (SignalList() << Remove(12, 18) << Insert(12, 16));
+ QTest::newRow("r(12-18),i(11-19)")
+ << (SignalList() << Remove(12, 18) << Insert(11, 19))
+ << (SignalList() << Remove(12, 18) << Insert(11, 19));
+ QTest::newRow("i(12-18),r(8-12)")
+ << (SignalList() << Remove(12, 18) << Insert(8, 12))
+ << (SignalList() << Remove(12, 18) << Insert(8, 12));
+ QTest::newRow("i(12-18),r(2-6)")
+ << (SignalList() << Remove(12, 18) << Insert(2, 6))
+ << (SignalList() << Remove(12, 18) << Insert(2, 6));
+ QTest::newRow("i(12-18),r(18-22)")
+ << (SignalList() << Remove(12, 18) << Insert(18, 22))
+ << (SignalList() << Remove(12, 18) << Insert(18, 22));
+ QTest::newRow("i(12-18),r(20-24)")
+ << (SignalList() << Remove(12, 18) << Insert(20, 24))
+ << (SignalList() << Remove(12, 18) << Insert(20, 24));
+
+ // Move, then insert
+ QTest::newRow("m(12-18,5),i(12-18)")
+ << (SignalList() << Move(12, 18, 5) << Insert(12, 18))
+ << (SignalList() << Insert(6, 12) << Move(18, 24, 5));
+ QTest::newRow("m(12-18,5),i(10-14)")
+ << (SignalList() << Move(12, 18, 5) << Insert(10, 14))
+ << (SignalList() << Insert(5, 9) << Move(16, 21, 5) << Move(21, 22, 14));
+ QTest::newRow("m(12-18,5),i(16-20)")
+ << (SignalList() << Move(12, 18, 5) << Insert(16, 20))
+ << (SignalList() << Insert(10, 14) << Move(16, 22, 5));
+ QTest::newRow("m(12-18,5),i(13-17)")
+ << (SignalList() << Move(12, 18, 5) << Insert(13, 17))
+ << (SignalList() << Insert(7, 11) << Move(16, 22, 5));
+ QTest::newRow("m(12-18,5),i(14-18)")
+ << (SignalList() << Move(12, 18, 5) << Insert(14, 18))
+ << (SignalList() << Insert(8, 12) << Move(16, 22, 5));
+ QTest::newRow("m(12-18,5),i(12-16)")
+ << (SignalList() << Move(12, 18, 5) << Insert(12, 16))
+ << (SignalList() << Insert(6, 10) << Move(16, 22, 5));
+ QTest::newRow("m(12-18,5),i(11-19)")
+ << (SignalList() << Move(12, 18, 5) << Insert(11, 19))
+ << (SignalList() << Insert(5, 13) << Move(20, 26, 5));
+ QTest::newRow("m(12-18,5),i(8-12)")
+ << (SignalList() << Move(12, 18, 5) << Insert(8, 12))
+ << (SignalList() << Insert(5, 9) << Move(16, 19, 5) << Move(19, 22, 12));
+ QTest::newRow("m(12-18,5),i(2-6)")
+ << (SignalList() << Move(12, 18, 5) << Insert(2, 6))
+ << (SignalList() << Insert(2, 6) << Move(16, 22, 9));
+ QTest::newRow("m(12-18,5),i(18-22)")
+ << (SignalList() << Move(12, 18, 5) << Insert(18, 22))
+ << (SignalList() << Insert(18, 22) << Move(12, 18, 5));
+ QTest::newRow("m(12-18,5),i(20-24)")
+ << (SignalList() << Move(12, 18, 5) << Insert(20, 24))
+ << (SignalList() << Insert(20, 24) << Move(12, 18, 5));
+
+ QTest::newRow("m(12-18,23),i(12-18)")
+ << (SignalList() << Move(12, 18, 23) << Insert(12, 18))
+ << (SignalList() << Insert(12, 18) << Move(18, 24, 29));
+ QTest::newRow("m(12-18,23),i(10-14)")
+ << (SignalList() << Move(12, 18, 23) << Insert(10, 14))
+ << (SignalList() << Insert(10, 14) << Move(16, 22, 27));
+ QTest::newRow("m(12-18,23),i(16-20)")
+ << (SignalList() << Move(12, 18, 23) << Insert(16, 20))
+ << (SignalList() << Insert(22, 26) << Move(12, 18, 27));
+ QTest::newRow("m(12-18,23),i(13-17)")
+ << (SignalList() << Move(12, 18, 23) << Insert(13, 17))
+ << (SignalList() << Insert(19, 23) << Move(12, 18, 27));
+ QTest::newRow("m(12-18,23),i(14-18)")
+ << (SignalList() << Move(12, 18, 23) << Insert(14, 18))
+ << (SignalList() << Insert(20, 24) << Move(12, 18, 27));
+ QTest::newRow("m(12-18,23),i(12-16)")
+ << (SignalList() << Move(12, 18, 23) << Insert(12, 16))
+ << (SignalList() << Insert(12, 16) << Move(16, 22, 27));
+ QTest::newRow("m(12-18,23),i(11-19)")
+ << (SignalList() << Move(12, 18, 23) << Insert(11, 19))
+ << (SignalList() << Insert(11, 19) << Move(20, 26, 31));
+ QTest::newRow("m(12-18,23),i(8-12)")
+ << (SignalList() << Move(12, 18, 23) << Insert(8, 12))
+ << (SignalList() << Insert(8, 12) << Move(16, 22, 27));
+ QTest::newRow("m(12-18,23),i(2-6)")
+ << (SignalList() << Move(12, 18, 23) << Insert(2, 6))
+ << (SignalList() << Insert(2, 6) << Move(16, 22, 27));
+ QTest::newRow("m(12-18,23),i(18-22)")
+ << (SignalList() << Move(12, 18, 23) << Insert(18, 22))
+ << (SignalList() << Insert(24, 28) << Move(12, 18, 27));
+ QTest::newRow("m(12-18,23),i(20-24)")
+ << (SignalList() << Move(12, 18, 23) << Insert(20, 24))
+ << (SignalList() << Insert(26, 30) << Move(12, 18, 27));
+
+ // Move, then remove
+ QTest::newRow("m(12-18,5),r(12-18)")
+ << (SignalList() << Move(12, 18, 5) << Remove(12, 18))
+ << (SignalList() << Remove(6, 12) << Move(6, 12, 5));
+ QTest::newRow("m(12-18,5),r(10-14)")
+ << (SignalList() << Move(12, 18, 5) << Remove(10, 14))
+ << (SignalList() << Remove(5, 8) << Remove(14, 15) << Move(9, 14, 5));
+ QTest::newRow("m(12-18,5),r(16-20)")
+ << (SignalList() << Move(12, 18, 5) << Remove(16, 20))
+ << (SignalList() << Remove(10, 12) << Remove(16, 18) << Move(10, 16, 5));
+ QTest::newRow("m(12-18,5),r(13-17)")
+ << (SignalList() << Move(12, 18, 5) << Remove(13, 17))
+ << (SignalList() << Remove(7, 11) << Move(8, 14, 5));
+ QTest::newRow("m(12-18,5),r(14-18)")
+ << (SignalList() << Move(12, 18, 5) << Remove(14, 18))
+ << (SignalList() << Remove(8, 12) << Move(8, 14, 5));
+ QTest::newRow("m(12-18,5),r(12-16)")
+ << (SignalList() << Move(12, 18, 5) << Remove(12, 16))
+ << (SignalList() << Remove(6, 10) << Move(8, 14, 5));
+ QTest::newRow("m(12-18,5),r(11-19)")
+ << (SignalList() << Move(12, 18, 5) << Remove(11, 19))
+ << (SignalList() << Remove(5, 12) << Remove(11, 12));
+ QTest::newRow("m(12-18,5),r(8-12)")
+ << (SignalList() << Move(12, 18, 5) << Remove(8, 12))
+ << (SignalList() << Remove(5, 6) << Remove(14, 17) << Move(11, 14, 5));
+ QTest::newRow("m(12-18,5),r(2-6)")
+ << (SignalList() << Move(12, 18, 5) << Remove(2, 6))
+ << (SignalList() << Remove(2, 5) << Remove(9, 10) << Move(9, 14, 2));
+ QTest::newRow("m(12-18,5),r(6-10)")
+ << (SignalList() << Move(12, 18, 5) << Remove(6, 10))
+ << (SignalList() << Remove(13, 17) << Move(12, 14, 5));
+ QTest::newRow("m(12-18,5),r(18-22)")
+ << (SignalList() << Move(12, 18, 5) << Remove(18, 22))
+ << (SignalList() << Remove(18, 22) << Move(12, 18, 5));
+ QTest::newRow("m(12-18,5),r(20-24)")
+ << (SignalList() << Move(12, 18, 5) << Remove(20, 24))
+ << (SignalList() << Remove(20, 24) << Move(12, 18, 5));
+
+ QTest::newRow("m(12-18,23),r(12-18)")
+ << (SignalList() << Move(12, 18, 23) << Remove(12, 18))
+ << (SignalList() << Remove(18, 24) << Move(12, 18, 17));
+ QTest::newRow("m(12-18,23),r(10-14)")
+ << (SignalList() << Move(12, 18, 23) << Remove(10, 14))
+ << (SignalList() << Remove(10, 12) << Remove(16, 18) << Move(10, 16, 19));
+ QTest::newRow("m(12-18,23),r(16-20)")
+ << (SignalList() << Move(12, 18, 23) << Remove(16, 20))
+ << (SignalList() << Remove(22, 26) << Move(12, 18, 19));
+ QTest::newRow("m(12-18,23),r(13-17)")
+ << (SignalList() << Move(12, 18, 23) << Remove(13, 17))
+ << (SignalList() << Remove(19, 23) << Move(12, 18, 19));
+ QTest::newRow("m(12-18,23),r(14-18)")
+ << (SignalList() << Move(12, 18, 23) << Remove(14, 18))
+ << (SignalList() << Remove(20, 24) << Move(12, 18, 19));
+ QTest::newRow("m(12-18,23),r(12-16)")
+ << (SignalList() << Move(12, 18, 23) << Remove(12, 16))
+ << (SignalList() << Remove(18, 22) << Move(12, 18, 19));
+ QTest::newRow("m(12-18,23),r(11-19)")
+ << (SignalList() << Move(12, 18, 23) << Remove(11, 19))
+ << (SignalList() << Remove(11, 12) << Remove(17, 24) << Move(11, 17, 15));
+ QTest::newRow("m(12-18,23),r(8-12)")
+ << (SignalList() << Move(12, 18, 23) << Remove(8, 12))
+ << (SignalList() << Remove(8, 12) << Move(8, 14, 19));
+ QTest::newRow("m(12-18,23),r(2-6)")
+ << (SignalList() << Move(12, 18, 23) << Remove(2, 6))
+ << (SignalList() << Remove(2, 6) << Move(8, 14, 19));
+ QTest::newRow("m(12-18,23),r(18-22)")
+ << (SignalList() << Move(12, 18, 23) << Remove(18, 22))
+ << (SignalList() << Remove(24, 28) << Move(12, 18, 19));
+ QTest::newRow("m(12-18,23),r(20-24)")
+ << (SignalList() << Move(12, 18, 23) << Remove(20, 24))
+ << (SignalList() << Remove(12, 13) << Remove(25, 28) << Move(12, 17, 20));
+}
+
+void tst_qdeclarativemodelchange::sequence()
+{
+ QFETCH(SignalList, input);
+ QFETCH(SignalList, output);
+
+ QDeclarativeChangeSet set;
+
+ foreach (const Signal &signal, input) {
+ if (signal.isRemove())
+ set.insertRemove(signal.start, signal.end);
+ else if (signal.isInsert())
+ set.insertInsert(signal.start, signal.end);
+ else if (signal.isMove())
+ set.insertMove(signal.start, signal.end, signal.to);
+ else if (signal.isChange())
+ set.insertChange(signal.start, signal.end);
+ }
+
+ SignalList changes;
+ foreach (const QDeclarativeChangeSet::Remove &remove, set.removes())
+ changes << Remove(remove.start, remove.end);
+ foreach (const QDeclarativeChangeSet::Insert &insert, set.inserts())
+ changes << Insert(insert.start, insert.end);
+ foreach (const QDeclarativeChangeSet::Move &move, set.moves())
+ changes << Move(move.start, move.end, move.to);
+ foreach (const QDeclarativeChangeSet::Change &change, set.changes())
+ changes << Change(change.start, change.end);
+
+#ifdef VERIFY_EXPECTED_OUTPUT
+ QVector<int> list;
+ for (int i = 0; i < 40; ++i)
+ list.append(i);
+ QVector<int> inputList = applyChanges(list, input);
+ QVector<int> outputList = applyChanges(list, output);
+ if (outputList != inputList /* || changes != output*/) {
+ qDebug() << input;
+ qDebug() << output;
+ qDebug() << changes;
+ qDebug() << inputList;
+ qDebug() << outputList;
+ } else if (changes != output) {
+ qDebug() << output;
+ qDebug() << changes;
+ }
+ QCOMPARE(outputList, inputList);
+#else
+
+ if (changes != output) {
+ qDebug() << output;
+ qDebug() << changes;
+ }
+
+#endif
+
+ QCOMPARE(changes, output);
+}
+
+
+QTEST_MAIN(tst_qdeclarativemodelchange)
+
+#include "tst_qdeclarativechangeset.moc"
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/importScope.1.js b/tests/auto/declarative/qdeclarativeecmascript/data/importScope.1.js
new file mode 100644
index 0000000000..4c556f9e96
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/importScope.1.js
@@ -0,0 +1 @@
+var value = 240
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/importScope.2.js b/tests/auto/declarative/qdeclarativeecmascript/data/importScope.2.js
new file mode 100644
index 0000000000..291fb9d2cc
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/importScope.2.js
@@ -0,0 +1,3 @@
+function getValue() {
+ return ImportScope1.value
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/importScope.qml b/tests/auto/declarative/qdeclarativeecmascript/data/importScope.qml
new file mode 100644
index 0000000000..a72847f0d7
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/importScope.qml
@@ -0,0 +1,7 @@
+import QtQuick 1.0
+import "importScope.1.js" as ImportScope1
+import "importScope.2.js" as ImportScope2
+
+QtObject {
+ property int test: ImportScope2.getValue()
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index cabaddeeb7..3c4c336822 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -108,6 +108,7 @@ private slots:
void aliasPropertyAndBinding();
void nonExistentAttachedObject();
void scope();
+ void importScope();
void signalParameterTypes();
void objectsCompareAsEqual();
void dynamicCreation_data();
@@ -959,6 +960,19 @@ void tst_qdeclarativeecmascript::scope()
}
}
+// In 4.7, non-library javascript files that had no imports shared the imports of their
+// importing context
+void tst_qdeclarativeecmascript::importScope()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("importScope.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+
+ QCOMPARE(o->property("test").toInt(), 240);
+
+ delete o;
+}
+
/*
Tests that "any" type passes through a synthesized signal parameter. This
is essentially a test of QDeclarativeMetaType::copy()
diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
index 8044b8097a..b5aaa007e9 100644
--- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
+++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
@@ -328,7 +328,6 @@ void tst_qdeclarativeimage::mirror()
p_e.drawPixmap(QRect(0, 0, width, height), srcPixmap, QRect(0, 0, srcPixmap.width(), srcPixmap.height()));
break;
case QDeclarativeImage::PreserveAspectFit:
- QEXPECT_FAIL("", "QTBUG-19538", Continue);
p_e.drawPixmap(QRect(25, 0, width / (width/height), height), srcPixmap, QRect(0, 0, srcPixmap.width(), srcPixmap.height()));
break;
case QDeclarativeImage::PreserveAspectCrop:
diff --git a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
index c9e8cdfae3..1aa9a5d5b1 100644
--- a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
+++ b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
@@ -332,6 +332,7 @@ void tst_qdeclarativeinstruction::dump()
i.storeScriptString.propertyIndex = 24;
i.storeScriptString.value = 3;
i.storeScriptString.scope = 1;
+ i.storeScriptString.bindingId = 3;
data->addInstruction(i);
}
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/NestedComponentRoot.qml b/tests/auto/declarative/qdeclarativelanguage/data/NestedComponentRoot.qml
new file mode 100644
index 0000000000..785a27dd79
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/NestedComponentRoot.qml
@@ -0,0 +1,6 @@
+import QtQuick 1.0
+
+Component {
+ Item {
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/nestedComponentRoots.qml b/tests/auto/declarative/qdeclarativelanguage/data/nestedComponentRoots.qml
new file mode 100644
index 0000000000..361bcbcb56
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/nestedComponentRoots.qml
@@ -0,0 +1,4 @@
+import QtQuick 1.0
+
+NestedComponentRoot {
+}
diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
index 132c947d93..3c6ce9da6d 100644
--- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
+++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
@@ -135,6 +135,7 @@ private slots:
void reservedWords_data();
void reservedWords();
void inlineAssignmentsOverrideBindings();
+ void nestedComponentRoots();
void basicRemote_data();
void basicRemote();
@@ -1428,6 +1429,12 @@ void tst_qdeclarativelanguage::inlineAssignmentsOverrideBindings()
delete o;
}
+// QTBUG-19354
+void tst_qdeclarativelanguage::nestedComponentRoots()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("nestedComponentRoots.qml"));
+}
+
// Import tests (QT-558)
void tst_qdeclarativelanguage::importsBuiltin_data()
{
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData.qml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData.qml
index c98555cd2f..442932be26 100644
--- a/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData.qml
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData.qml
@@ -14,7 +14,7 @@ QtObject {
// Test to the end
x.onreadystatechange = function() {
if (x.readyState == XMLHttpRequest.DONE) {
- if (reqType == "HEAD")
+ if (reqType == "HEAD" || reqType == "DELETE")
dataOK = (x.responseText == "");
else
dataOK = (x.responseText == "QML Rocks!\n");
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_DELETE.expect b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_DELETE.expect
new file mode 100644
index 0000000000..b2d177aa20
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_DELETE.expect
@@ -0,0 +1,7 @@
+DELETE /testdocument.html HTTP/1.1
+ACCEPT-LANGUAGE: en-US
+Connection: Keep-Alive
+Accept-Encoding: gzip
+User-Agent: Mozilla/5.0
+Host: 127.0.0.1:14445
+
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_PUT.expect b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_HEAD.expect
index 74a979817d..74a979817d 100644
--- a/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_PUT.expect
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/send_ignoreData_HEAD.expect
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
index de16cf41f5..aad68c5926 100644
--- a/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/tst_qdeclarativexmlhttprequest.cpp
@@ -497,7 +497,7 @@ void tst_qdeclarativexmlhttprequest::send_alreadySent()
delete object;
}
-// Test that send for a GET or HEAD ignores data
+// Test that sends for GET, HEAD and DELETE ignore data
void tst_qdeclarativexmlhttprequest::send_ignoreData()
{
{
@@ -522,7 +522,7 @@ void tst_qdeclarativexmlhttprequest::send_ignoreData()
{
TestHTTPServer server(SERVER_PORT);
QVERIFY(server.isValid());
- QVERIFY(server.wait(TEST_FILE("send_ignoreData_PUT.expect"),
+ QVERIFY(server.wait(TEST_FILE("send_ignoreData_HEAD.expect"),
TEST_FILE("send_ignoreData.reply"),
QUrl()));
@@ -537,6 +537,25 @@ void tst_qdeclarativexmlhttprequest::send_ignoreData()
delete object;
}
+
+ {
+ TestHTTPServer server(SERVER_PORT);
+ QVERIFY(server.isValid());
+ QVERIFY(server.wait(TEST_FILE("send_ignoreData_DELETE.expect"),
+ TEST_FILE("send_ignoreData.reply"),
+ QUrl()));
+
+ QDeclarativeComponent component(&engine, TEST_FILE("send_ignoreData.qml"));
+ QObject *object = component.beginCreate(engine.rootContext());
+ QVERIFY(object != 0);
+ object->setProperty("reqType", "DELETE");
+ object->setProperty("url", "http://127.0.0.1:14445/testdocument.html");
+ component.completeCreate();
+
+ QTRY_VERIFY(object->property("dataOK").toBool() == true);
+
+ delete object;
+ }
}
// Test that send()'ing data works
diff --git a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
index e32353ad53..c2bcf6dd40 100644
--- a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
+++ b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
@@ -1186,6 +1186,8 @@ void tst_QSGListView::sectionsDelegate()
void tst_QSGListView::currentIndex()
{
+ QSKIP("QTBUG-20020", SkipAll);
+
TestModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), QString::number(i));
diff --git a/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp b/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp
index 7d74c0add8..ea9260772e 100644
--- a/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp
+++ b/tests/auto/declarative/qsgtextedit/tst_qsgtextedit.cpp
@@ -408,10 +408,7 @@ void tst_qsgtextedit::alignments()
ob->setProperty("horizontalAlignment",hAlign);
ob->setProperty("verticalAlignment",vAlign);
QTRY_COMPARE(ob->property("running").toBool(),false);
- QImage actual(canvas.width(), canvas.height(), QImage::Format_RGB32);
- actual.fill(qRgb(255,255,255));
- QPainter p(&actual);
- canvas.render(&p);
+ QImage actual = canvas.grabFrameBuffer();
expectfile = createExpectedFileIfNotFound(expectfile, actual);
@@ -458,6 +455,7 @@ void tst_qsgtextedit::hAlign()
void tst_qsgtextedit::hAlign_RightToLeft()
{
+ QSKIP("QTBUG-20017", SkipAll);
QSGView canvas(QUrl::fromLocalFile(SRCDIR "/data/horizontalAlignment_RightToLeft.qml"));
QSGTextEdit *textEdit = canvas.rootObject()->findChild<QSGTextEdit*>("text");
QVERIFY(textEdit != 0);
diff --git a/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp b/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp
index cbe14a5563..77427253a6 100644
--- a/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp
+++ b/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp
@@ -1037,12 +1037,7 @@ void tst_qsgtextinput::horizontalAlignment()
QObject *ob = canvas.rootObject();
QVERIFY(ob != 0);
ob->setProperty("horizontalAlignment",hAlign);
- QImage actual(canvas.width(), canvas.height(), QImage::Format_RGB32);
- actual.fill(qRgb(255,255,255));
- {
- QPainter p(&actual);
- canvas.render(&p);
- }
+ QImage actual = canvas.grabFrameBuffer();
expectfile = createExpectedFileIfNotFound(expectfile, actual);
@@ -1053,6 +1048,7 @@ void tst_qsgtextinput::horizontalAlignment()
void tst_qsgtextinput::horizontalAlignment_RightToLeft()
{
+ QSKIP("QTBUG-20017", SkipAll);
QSGView canvas(QUrl::fromLocalFile(SRCDIR "/data/horizontalAlignment_RightToLeft.qml"));
QSGTextInput *textInput = canvas.rootObject()->findChild<QSGTextInput*>("text");
QVERIFY(textInput != 0);
@@ -1446,6 +1442,7 @@ void tst_qsgtextinput::navigation()
void tst_qsgtextinput::navigation_RTL()
{
+ QSKIP("QTBUG-20017", SkipAll);
QSGView canvas(QUrl::fromLocalFile(SRCDIR "/data/navigation.qml"));
canvas.show();
canvas.setFocus();
@@ -1734,7 +1731,7 @@ void tst_qsgtextinput::cursorRectangle()
// Check the cursor rectangle remains within the input bounding rect when auto scrolling.
QVERIFY(r.left() < input.boundingRect().width());
- QVERIFY(r.right() >= input.width());
+ QVERIFY(r.right() >= input.width() - error);
for (int i = 6; i < text.length(); ++i) {
input.setCursorPosition(i);
@@ -2219,18 +2216,25 @@ void tst_qsgtextinput::preeditAutoScroll()
QCOMPARE(input->positionAt(0), 0);
QCOMPARE(input->positionAt(input->width()), 5);
+ // some tolerance for different fonts.
+#ifdef Q_OS_LINUX
+ const int error = 2;
+#else
+ const int error = 5;
+#endif
+
// test if the preedit is larger than the text input that the
// character preceding the cursor is still visible.
qreal x = input->positionToRectangle(0).x();
for (int i = 0; i < 3; ++i) {
ic.sendPreeditText(preeditText, i + 1);
- QVERIFY(input->cursorRectangle().right() >= fm.width(preeditText.at(i)));
+ QVERIFY(input->cursorRectangle().right() >= fm.width(preeditText.at(i)) - error);
QVERIFY(input->positionToRectangle(0).x() < x);
x = input->positionToRectangle(0).x();
}
for (int i = 1; i >= 0; --i) {
ic.sendPreeditText(preeditText, i + 1);
- QVERIFY(input->cursorRectangle().right() >= fm.width(preeditText.at(i)));
+ QVERIFY(input->cursorRectangle().right() >= fm.width(preeditText.at(i)) - error);
QVERIFY(input->positionToRectangle(0).x() > x);
x = input->positionToRectangle(0).x();
}
diff --git a/tests/benchmarks/declarative/binding/tst_binding.cpp b/tests/benchmarks/declarative/binding/tst_binding.cpp
index 5dce36d31d..70796f682a 100644
--- a/tests/benchmarks/declarative/binding/tst_binding.cpp
+++ b/tests/benchmarks/declarative/binding/tst_binding.cpp
@@ -186,7 +186,8 @@ void tst_binding::creation()
COMPONENT(file, binding);
QBENCHMARK {
- c.create();
+ QObject *o = c.create();
+ delete o;
}
}
diff --git a/tests/benchmarks/declarative/declarative.pro b/tests/benchmarks/declarative/declarative.pro
index a827978d63..f2dfdf971a 100644
--- a/tests/benchmarks/declarative/declarative.pro
+++ b/tests/benchmarks/declarative/declarative.pro
@@ -3,6 +3,7 @@ TEMPLATE = subdirs
SUBDIRS += \
binding \
creation \
+ javascript \
holistic \
pointers \
qdeclarativecomponent \
diff --git a/tests/benchmarks/declarative/javascript/data/NestedIdObject.qml b/tests/benchmarks/declarative/javascript/data/NestedIdObject.qml
new file mode 100644
index 0000000000..410ee00ddc
--- /dev/null
+++ b/tests/benchmarks/declarative/javascript/data/NestedIdObject.qml
@@ -0,0 +1,9 @@
+import QtQuick 1.0
+
+QtObject {
+ function runtest() {
+ for (var ii = 0; ii < 5000000; ++ii) {
+ root
+ }
+ }
+}
diff --git a/tests/benchmarks/declarative/javascript/data/intQObjectProperty.qml b/tests/benchmarks/declarative/javascript/data/intQObjectProperty.qml
new file mode 100644
index 0000000000..c3e6ebc16a
--- /dev/null
+++ b/tests/benchmarks/declarative/javascript/data/intQObjectProperty.qml
@@ -0,0 +1,13 @@
+import Qt.test 1.0
+
+TestObject {
+ id: root
+
+ function runtest() {
+ var r = root;
+
+ for (var ii = 0; ii < 5000000; ++ii) {
+ r.intValue
+ }
+ }
+}
diff --git a/tests/benchmarks/declarative/javascript/data/localId.qml b/tests/benchmarks/declarative/javascript/data/localId.qml
new file mode 100644
index 0000000000..474d0760a3
--- /dev/null
+++ b/tests/benchmarks/declarative/javascript/data/localId.qml
@@ -0,0 +1,13 @@
+// Benchmarks the cost of accessing an id in the same file as the script.
+
+import QtQuick 1.0
+
+QtObject {
+ id: root
+
+ function runtest() {
+ for (var ii = 0; ii < 5000000; ++ii) {
+ root
+ }
+ }
+}
diff --git a/tests/benchmarks/declarative/javascript/data/nestedId.qml b/tests/benchmarks/declarative/javascript/data/nestedId.qml
new file mode 100644
index 0000000000..49c4e3ca43
--- /dev/null
+++ b/tests/benchmarks/declarative/javascript/data/nestedId.qml
@@ -0,0 +1,13 @@
+// Benchmarks the cost of accessing an id in a parent context of the script.
+
+import QtQuick 1.0
+
+QtObject {
+ id: root
+
+ property variant object: NestedIdObject {}
+ function runtest() {
+ object.runtest();
+ }
+}
+
diff --git a/tests/benchmarks/declarative/javascript/data/stringQObjectProperty.qml b/tests/benchmarks/declarative/javascript/data/stringQObjectProperty.qml
new file mode 100644
index 0000000000..ccd8a791b6
--- /dev/null
+++ b/tests/benchmarks/declarative/javascript/data/stringQObjectProperty.qml
@@ -0,0 +1,14 @@
+import Qt.test 1.0
+
+TestObject {
+ id: root
+
+ function runtest() {
+ var r = root;
+
+ for (var ii = 0; ii < 5000000; ++ii) {
+ r.stringValue
+ }
+ }
+}
+
diff --git a/tests/benchmarks/declarative/javascript/javascript.pro b/tests/benchmarks/declarative/javascript/javascript.pro
new file mode 100644
index 0000000000..7395cef07e
--- /dev/null
+++ b/tests/benchmarks/declarative/javascript/javascript.pro
@@ -0,0 +1,11 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_javascript
+QT += declarative
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_javascript.cpp testtypes.cpp
+HEADERS += testtypes.h
+
+# Define SRCDIR equal to test's source directory
+DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/benchmarks/declarative/javascript/testtypes.cpp b/tests/benchmarks/declarative/javascript/testtypes.cpp
new file mode 100644
index 0000000000..f490b770fd
--- /dev/null
+++ b/tests/benchmarks/declarative/javascript/testtypes.cpp
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** 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 test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "testtypes.h"
+#include <QtDeclarative/qdeclarative.h>
+
+void registerTypes()
+{
+ qmlRegisterType<TestObject>("Qt.test", 1,0, "TestObject");
+}
diff --git a/tests/benchmarks/declarative/javascript/testtypes.h b/tests/benchmarks/declarative/javascript/testtypes.h
new file mode 100644
index 0000000000..c89f10757b
--- /dev/null
+++ b/tests/benchmarks/declarative/javascript/testtypes.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** 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 test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TESTTYPES_H
+#define TESTTYPES_H
+
+#include <QtCore/qobject.h>
+
+class TestObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int intValue READ intValue);
+ Q_PROPERTY(QString stringValue READ stringValue);
+
+public:
+ TestObject() : m_string("Hello world!") {}
+
+ int intValue() const { return 13; }
+ QString stringValue() const { return m_string; }
+
+private:
+ QString m_string;
+};
+
+void registerTypes();
+
+#endif // TESTTYPES_H
diff --git a/tests/benchmarks/declarative/javascript/tst_javascript.cpp b/tests/benchmarks/declarative/javascript/tst_javascript.cpp
new file mode 100644
index 0000000000..73c1d7c7ad
--- /dev/null
+++ b/tests/benchmarks/declarative/javascript/tst_javascript.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** 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 test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDir>
+#include <QDebug>
+#include <qtest.h>
+#include <QDeclarativeEngine>
+#include <QDeclarativeComponent>
+
+#include "testtypes.h"
+
+class tst_javascript : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_javascript();
+ virtual ~tst_javascript();
+
+private slots:
+ void run_data();
+ void run();
+
+private:
+ QDeclarativeEngine engine;
+};
+
+tst_javascript::tst_javascript()
+{
+ registerTypes();
+}
+
+tst_javascript::~tst_javascript()
+{
+}
+
+void tst_javascript::run_data()
+{
+ QTest::addColumn<QString>("file");
+
+ QDir dir(SRCDIR "/data");
+
+ QStringList files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
+
+ for (int ii = 0; ii < files.count(); ++ii) {
+ QString file = files.at(ii);
+ if (file.endsWith(".qml") && file.at(0).isLower()) {
+
+ QString testName = file.left(file.length() - 4 /* strlen(".qml") */);
+ QString fileName = QLatin1String(SRCDIR) + QLatin1String("/data/") + file;
+
+
+ QTest::newRow(qPrintable(testName)) << fileName;
+
+ }
+ }
+}
+
+void tst_javascript::run()
+{
+ QFETCH(QString, file);
+
+ QDeclarativeComponent c(&engine, file);
+
+ if (c.isError()) {
+ qWarning() << c.errors();
+ }
+
+ QVERIFY(!c.isError());
+
+ QObject *o = c.create();
+ QVERIFY(o != 0);
+
+ QMetaMethod method = o->metaObject()->method(o->metaObject()->indexOfMethod("runtest()"));
+
+ QBENCHMARK {
+ method.invoke(o);
+ }
+
+ delete o;
+}
+
+QTEST_MAIN(tst_javascript)
+
+#include "tst_javascript.moc"
diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp
index 765a9dc2fb..d351b27e7e 100644
--- a/tools/qmlscene/main.cpp
+++ b/tools/qmlscene/main.cpp
@@ -252,6 +252,7 @@ struct Options
, scenegraphOnGraphicsview(false)
, clip(false)
, versionDetection(true)
+ , vsync(true)
{
}
@@ -263,6 +264,7 @@ struct Options
bool scenegraphOnGraphicsview;
bool clip;
bool versionDetection;
+ bool vsync;
};
#if defined(QMLSCENE_BUNDLE)
@@ -440,6 +442,7 @@ static void usage()
qWarning(" --sg-on-gv [--clip] ....................... Scenegraph on graphicsview (and clip to item)");
#endif
qWarning(" --no-version-detection .................... Do not try to detect the version of the .qml file");
+ qWarning(" --no-vsync-animations ..................... Do not use vsync based animations");
qWarning(" ");
exit(1);
@@ -474,6 +477,8 @@ int main(int argc, char ** argv)
options.versionDetection = false;
else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("-i") && i + 1 < argc)
imports.append(QString::fromLatin1(argv[++i]));
+ else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--no-vsync-animations"))
+ options.vsync = false;
else if (QString::fromLatin1(argv[i]).toLower() == QLatin1String("--help")
|| QString::fromLatin1(argv[i]).toLower() == QLatin1String("-help")
|| QString::fromLatin1(argv[i]).toLower() == QLatin1String("--h")
@@ -520,6 +525,7 @@ int main(int argc, char ** argv)
if (options.versionDetection)
checkAndAdaptVersion(options.file);
QSGView *qxView = new MyQSGView();
+ qxView->setVSyncAnimations(options.vsync);
engine = qxView->engine();
for (int i = 0; i < imports.size(); ++i)
engine->addImportPath(imports.at(i));