From 6c8378eaf1edbbefe6aaa3672b0127816a004fd7 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 23 Nov 2011 15:14:07 +0100 Subject: Say hello to QtQuick module This change moves the QtQuick 2 types and C++ API (including SceneGraph) to a new module (AKA library), QtQuick. 99% of this change is moving files from src/declarative to src/quick, and from tests/auto/declarative to tests/auto/qtquick2. The loading of QtQuick 2 ("import QtQuick 2.0") is now delegated to a plugin, src/imports/qtquick2, just like it's done for QtQuick 1. All tools, examples, and tests that use QtQuick C++ API have gotten "QT += quick" or "QT += quick-private" added to their .pro file. A few additional internal QtDeclarative classes had to be exported (via Q_DECLARATIVE_PRIVATE_EXPORT) since they're needed by the QtQuick 2 implementation. The old header locations (e.g. QtDeclarative/qquickitem.h) will still be supported for some time, but will produce compile-time warnings. (To avoid the QtQuick implementation using the compatibility headers (since QtDeclarative's includepath comes first), a few include statements were modified, e.g. from "#include " to "#include ".) There's a change in qtbase that automatically adds QtQuick to the module list if QtDeclarative is used. Together with the compatibility headers, this should help reduce the migration pain for existing projects. In theory, simply getting an existing QtDeclarative-based project to compile and link shouldn't require any changes for now -- but porting to the new scheme is of course recommended, and will eventually become mandatory. Task-number: QTBUG-22889 Reviewed-by: Lars Knoll Change-Id: Ia52be9373172ba2f37e7623231ecb060316c96a7 Reviewed-by: Kent Hansen Reviewed-by: Sergio Ahumada --- .../debugger/qdeclarativeenginedebugservice_p.h | 2 +- src/declarative/declarative.pro | 7 - src/declarative/designer/designer.pri | 2 - src/declarative/designer/designersupport.cpp | 408 -- src/declarative/designer/designersupport.h | 153 - src/declarative/items/checksync.pl | 108 - src/declarative/items/context2d/context2d.pri | 16 - .../items/context2d/qquickcanvasitem.cpp | 714 --- .../items/context2d/qquickcanvasitem_p.h | 149 - .../items/context2d/qquickcontext2d.cpp | 3540 ------------- .../items/context2d/qquickcontext2d_p.h | 211 - .../context2d/qquickcontext2dcommandbuffer.cpp | 469 -- .../context2d/qquickcontext2dcommandbuffer_p.h | 268 - .../items/context2d/qquickcontext2dnode.cpp | 124 - .../items/context2d/qquickcontext2dnode_p.h | 86 - .../items/context2d/qquickcontext2dtexture.cpp | 778 --- .../items/context2d/qquickcontext2dtexture_p.h | 205 - .../items/context2d/qquickcontext2dtile.cpp | 165 - .../items/context2d/qquickcontext2dtile_p.h | 112 - src/declarative/items/items.pri | 131 - src/declarative/items/qquickanchors.cpp | 1180 ----- src/declarative/items/qquickanchors_p.h | 201 - src/declarative/items/qquickanchors_p_p.h | 176 - src/declarative/items/qquickanimatedimage.cpp | 397 -- src/declarative/items/qquickanimatedimage_p.h | 117 - src/declarative/items/qquickanimatedimage_p_p.h | 88 - src/declarative/items/qquickanimation.cpp | 792 --- src/declarative/items/qquickanimation_p.h | 209 - src/declarative/items/qquickanimation_p_p.h | 153 - src/declarative/items/qquickborderimage.cpp | 600 --- src/declarative/items/qquickborderimage_p.h | 110 - src/declarative/items/qquickborderimage_p_p.h | 103 - src/declarative/items/qquickcanvas.cpp | 2644 ---------- src/declarative/items/qquickcanvas.h | 164 - src/declarative/items/qquickcanvas_p.h | 323 -- src/declarative/items/qquickclipnode.cpp | 120 - src/declarative/items/qquickclipnode_p.h | 71 - src/declarative/items/qquickdrag.cpp | 462 -- src/declarative/items/qquickdrag_p.h | 208 - src/declarative/items/qquickdroparea.cpp | 428 -- src/declarative/items/qquickdroparea_p.h | 167 - src/declarative/items/qquickevents.cpp | 239 - src/declarative/items/qquickevents_p_p.h | 144 - src/declarative/items/qquickflickable.cpp | 2003 -------- src/declarative/items/qquickflickable_p.h | 277 -- src/declarative/items/qquickflickable_p_p.h | 262 - src/declarative/items/qquickflipable.cpp | 308 -- src/declarative/items/qquickflipable_p.h | 104 - src/declarative/items/qquickfocusscope.cpp | 70 - src/declarative/items/qquickfocusscope_p.h | 68 - src/declarative/items/qquickgridview.cpp | 1958 -------- src/declarative/items/qquickgridview_p.h | 146 - src/declarative/items/qquickimage.cpp | 746 --- src/declarative/items/qquickimage_p.h | 122 - src/declarative/items/qquickimage_p_p.h | 85 - src/declarative/items/qquickimagebase.cpp | 290 -- src/declarative/items/qquickimagebase_p.h | 119 - src/declarative/items/qquickimagebase_p_p.h | 93 - src/declarative/items/qquickimplicitsizeitem.cpp | 64 - src/declarative/items/qquickimplicitsizeitem_p.h | 75 - src/declarative/items/qquickimplicitsizeitem_p_p.h | 78 - src/declarative/items/qquickitem.cpp | 5236 ------------------- src/declarative/items/qquickitem.h | 421 -- src/declarative/items/qquickitem_p.h | 752 --- src/declarative/items/qquickitemchangelistener_p.h | 82 - src/declarative/items/qquickitemsmodule.cpp | 241 - src/declarative/items/qquickitemsmodule_p.h | 65 - src/declarative/items/qquickitemview.cpp | 1732 ------- src/declarative/items/qquickitemview_p.h | 296 -- src/declarative/items/qquickitemview_p_p.h | 260 - src/declarative/items/qquicklistview.cpp | 2533 ---------- src/declarative/items/qquicklistview_p.h | 215 - src/declarative/items/qquickloader.cpp | 858 ---- src/declarative/items/qquickloader_p.h | 123 - src/declarative/items/qquickloader_p_p.h | 121 - src/declarative/items/qquickmousearea.cpp | 1168 ----- src/declarative/items/qquickmousearea_p.h | 231 - src/declarative/items/qquickmousearea_p_p.h | 112 - .../items/qquickmultipointtoucharea.cpp | 729 --- .../items/qquickmultipointtoucharea_p.h | 267 - src/declarative/items/qquickninepatchnode.cpp | 302 -- src/declarative/items/qquickninepatchnode_p.h | 98 - src/declarative/items/qquickpainteditem.cpp | 528 -- src/declarative/items/qquickpainteditem.h | 130 - src/declarative/items/qquickpainteditem_p.h | 71 - src/declarative/items/qquickpathview.cpp | 1781 ------- src/declarative/items/qquickpathview_p.h | 259 - src/declarative/items/qquickpathview_p_p.h | 199 - src/declarative/items/qquickpincharea.cpp | 600 --- src/declarative/items/qquickpincharea_p.h | 315 -- src/declarative/items/qquickpincharea_p_p.h | 116 - src/declarative/items/qquickpositioners.cpp | 1532 ------ src/declarative/items/qquickpositioners_p.h | 295 -- src/declarative/items/qquickpositioners_p_p.h | 164 - src/declarative/items/qquickrectangle.cpp | 556 --- src/declarative/items/qquickrectangle_p.h | 189 - src/declarative/items/qquickrectangle_p_p.h | 103 - src/declarative/items/qquickrepeater.cpp | 476 -- src/declarative/items/qquickrepeater_p.h | 112 - src/declarative/items/qquickrepeater_p_p.h | 89 - src/declarative/items/qquickscalegrid.cpp | 214 - src/declarative/items/qquickscalegrid_p_p.h | 134 - src/declarative/items/qquickshadereffect.cpp | 763 --- src/declarative/items/qquickshadereffect_p.h | 158 - src/declarative/items/qquickshadereffectmesh.cpp | 216 - src/declarative/items/qquickshadereffectmesh_p.h | 103 - src/declarative/items/qquickshadereffectnode.cpp | 317 -- src/declarative/items/qquickshadereffectnode_p.h | 151 - src/declarative/items/qquickshadereffectsource.cpp | 921 ---- src/declarative/items/qquickshadereffectsource_p.h | 259 - src/declarative/items/qquicksprite.cpp | 130 - src/declarative/items/qquicksprite_p.h | 136 - src/declarative/items/qquickspriteengine.cpp | 501 -- src/declarative/items/qquickspriteengine_p.h | 323 -- src/declarative/items/qquickspriteimage.cpp | 455 -- src/declarative/items/qquickspriteimage_p.h | 140 - src/declarative/items/qquickstateoperations.cpp | 1346 ----- src/declarative/items/qquickstateoperations_p.h | 275 - src/declarative/items/qquicktext.cpp | 1950 -------- src/declarative/items/qquicktext_p.h | 252 - src/declarative/items/qquicktext_p_p.h | 169 - src/declarative/items/qquicktextedit.cpp | 2091 -------- src/declarative/items/qquicktextedit_p.h | 314 -- src/declarative/items/qquicktextedit_p_p.h | 144 - src/declarative/items/qquicktextinput.cpp | 2007 -------- src/declarative/items/qquicktextinput_p.h | 302 -- src/declarative/items/qquicktextinput_p_p.h | 172 - src/declarative/items/qquicktextnode.cpp | 1344 ----- src/declarative/items/qquicktextnode_p.h | 110 - src/declarative/items/qquicktranslate.cpp | 319 -- src/declarative/items/qquicktranslate_p.h | 162 - src/declarative/items/qquickview.cpp | 539 -- src/declarative/items/qquickview.h | 120 - src/declarative/items/qquickview_p.h | 105 - src/declarative/items/qquickvisualadaptormodel.cpp | 889 ---- src/declarative/items/qquickvisualadaptormodel_p.h | 129 - src/declarative/items/qquickvisualdatamodel.cpp | 2668 ---------- src/declarative/items/qquickvisualdatamodel_p.h | 242 - src/declarative/items/qquickvisualitemmodel.cpp | 235 - src/declarative/items/qquickvisualitemmodel_p.h | 175 - src/declarative/items/qquickwindowmodule.cpp | 55 - src/declarative/items/qquickwindowmodule_p.h | 63 - src/declarative/items/syncexcludes | 11 - .../particles/particleresources/noise.png | Bin 19477 -> 0 bytes src/declarative/particles/particles.pri | 69 - src/declarative/particles/particles.qrc | 5 - src/declarative/particles/qquickage.cpp | 112 - src/declarative/particles/qquickage_p.h | 102 - src/declarative/particles/qquickangledirection.cpp | 116 - src/declarative/particles/qquickangledirection_p.h | 133 - .../particles/qquickcumulativedirection.cpp | 70 - .../particles/qquickcumulativedirection_p.h | 69 - src/declarative/particles/qquickcustomaffector.cpp | 211 - src/declarative/particles/qquickcustomaffector_p.h | 164 - src/declarative/particles/qquickcustomparticle.cpp | 596 --- src/declarative/particles/qquickcustomparticle_p.h | 121 - src/declarative/particles/qquickdirection.cpp | 64 - src/declarative/particles/qquickdirection_p.h | 71 - .../particles/qquickellipseextruder.cpp | 80 - .../particles/qquickellipseextruder_p.h | 86 - src/declarative/particles/qquickfriction.cpp | 111 - src/declarative/particles/qquickfriction_p.h | 104 - src/declarative/particles/qquickgravity.cpp | 97 - src/declarative/particles/qquickgravity_p.h | 118 - src/declarative/particles/qquickgroupgoal.cpp | 112 - src/declarative/particles/qquickgroupgoal_p.h | 102 - src/declarative/particles/qquickimageparticle.cpp | 1803 ------- src/declarative/particles/qquickimageparticle_p.h | 429 -- src/declarative/particles/qquickitemparticle.cpp | 269 - src/declarative/particles/qquickitemparticle_p.h | 138 - src/declarative/particles/qquicklineextruder.cpp | 84 - src/declarative/particles/qquicklineextruder_p.h | 77 - src/declarative/particles/qquickmaskextruder.cpp | 113 - src/declarative/particles/qquickmaskextruder_p.h | 97 - .../particles/qquickparticleaffector.cpp | 279 -- .../particles/qquickparticleaffector_p.h | 201 - .../particles/qquickparticleemitter.cpp | 501 -- .../particles/qquickparticleemitter_p.h | 351 -- .../particles/qquickparticleextruder.cpp | 70 - .../particles/qquickparticleextruder_p.h | 73 - src/declarative/particles/qquickparticlegroup.cpp | 143 - src/declarative/particles/qquickparticlegroup_p.h | 112 - .../particles/qquickparticlepainter.cpp | 150 - .../particles/qquickparticlepainter_p.h | 132 - .../particles/qquickparticlesmodule.cpp | 120 - .../particles/qquickparticlesmodule_p.h | 63 - src/declarative/particles/qquickparticlesystem.cpp | 1106 ----- src/declarative/particles/qquickparticlesystem_p.h | 380 -- src/declarative/particles/qquickpointattractor.cpp | 162 - src/declarative/particles/qquickpointattractor_p.h | 169 - src/declarative/particles/qquickpointdirection.cpp | 85 - src/declarative/particles/qquickpointdirection_p.h | 135 - .../particles/qquickrectangleextruder.cpp | 86 - .../particles/qquickrectangleextruder_p.h | 88 - src/declarative/particles/qquickspritegoal.cpp | 153 - src/declarative/particles/qquickspritegoal_p.h | 125 - .../particles/qquicktargetdirection.cpp | 131 - .../particles/qquicktargetdirection_p.h | 191 - src/declarative/particles/qquicktrailemitter.cpp | 285 -- src/declarative/particles/qquicktrailemitter_p.h | 171 - src/declarative/particles/qquickturbulence.cpp | 205 - src/declarative/particles/qquickturbulence_p.h | 119 - src/declarative/particles/qquickv8particledata.cpp | 503 -- src/declarative/particles/qquickv8particledata_p.h | 69 - src/declarative/particles/qquickwander.cpp | 180 - src/declarative/particles/qquickwander_p.h | 161 - src/declarative/qml/qdeclarativecomponent_p.h | 2 +- src/declarative/qml/qdeclarativeengine.cpp | 6 - src/declarative/qml/qdeclarativeexpression_p.h | 2 +- src/declarative/qml/qdeclarativemetatype.cpp | 1 - src/declarative/qtquick2.cpp | 193 - src/declarative/qtquick2_p.h | 63 - .../scenegraph/coreapi/qsgdefaultrenderer.cpp | 527 -- .../scenegraph/coreapi/qsgdefaultrenderer_p.h | 123 - src/declarative/scenegraph/coreapi/qsggeometry.cpp | 466 -- src/declarative/scenegraph/coreapi/qsggeometry.h | 295 -- src/declarative/scenegraph/coreapi/qsggeometry_p.h | 73 - src/declarative/scenegraph/coreapi/qsgmaterial.cpp | 535 -- src/declarative/scenegraph/coreapi/qsgmaterial.h | 144 - src/declarative/scenegraph/coreapi/qsgnode.cpp | 1264 ----- src/declarative/scenegraph/coreapi/qsgnode.h | 348 -- .../scenegraph/coreapi/qsgnodeupdater.cpp | 287 -- .../scenegraph/coreapi/qsgnodeupdater_p.h | 86 - src/declarative/scenegraph/coreapi/qsgrenderer.cpp | 743 --- src/declarative/scenegraph/coreapi/qsgrenderer_p.h | 234 - src/declarative/scenegraph/qsgadaptationlayer.cpp | 315 -- src/declarative/scenegraph/qsgadaptationlayer_p.h | 257 - src/declarative/scenegraph/qsgcontext.cpp | 512 -- src/declarative/scenegraph/qsgcontext_p.h | 144 - src/declarative/scenegraph/qsgcontextplugin.cpp | 104 - src/declarative/scenegraph/qsgcontextplugin_p.h | 81 - .../qsgdefaultdistancefieldglyphcache.cpp | 324 -- .../qsgdefaultdistancefieldglyphcache_p.h | 165 - src/declarative/scenegraph/qsgdefaultglyphnode.cpp | 95 - .../scenegraph/qsgdefaultglyphnode_p.cpp | 306 -- src/declarative/scenegraph/qsgdefaultglyphnode_p.h | 87 - .../scenegraph/qsgdefaultglyphnode_p_p.h | 96 - src/declarative/scenegraph/qsgdefaultimagenode.cpp | 293 -- src/declarative/scenegraph/qsgdefaultimagenode_p.h | 90 - .../scenegraph/qsgdefaultrectanglenode.cpp | 548 -- .../scenegraph/qsgdefaultrectanglenode_p.h | 108 - .../scenegraph/qsgdistancefieldglyphnode.cpp | 316 -- .../scenegraph/qsgdistancefieldglyphnode_p.cpp | 725 --- .../scenegraph/qsgdistancefieldglyphnode_p.h | 107 - .../scenegraph/qsgdistancefieldglyphnode_p_p.h | 140 - src/declarative/scenegraph/qsgflashnode.cpp | 62 - src/declarative/scenegraph/qsgflashnode_p.h | 69 - src/declarative/scenegraph/qsgpathsimplifier.cpp | 1673 ------- src/declarative/scenegraph/qsgpathsimplifier_p.h | 68 - src/declarative/scenegraph/scenegraph.pri | 86 - .../scenegraph/util/qsgareaallocator.cpp | 290 -- .../scenegraph/util/qsgareaallocator_p.h | 73 - .../scenegraph/util/qsgdistancefieldutil.cpp | 805 --- .../scenegraph/util/qsgdistancefieldutil_p.h | 111 - src/declarative/scenegraph/util/qsgengine.cpp | 115 - src/declarative/scenegraph/util/qsgengine.h | 102 - .../scenegraph/util/qsgflatcolormaterial.cpp | 202 - .../scenegraph/util/qsgflatcolormaterial.h | 74 - src/declarative/scenegraph/util/qsgpainternode.cpp | 464 -- src/declarative/scenegraph/util/qsgpainternode_p.h | 160 - .../scenegraph/util/qsgsimplematerial.h | 222 - .../scenegraph/util/qsgsimplerectnode.cpp | 132 - .../scenegraph/util/qsgsimplerectnode.h | 77 - .../scenegraph/util/qsgsimpletexturenode.cpp | 154 - .../scenegraph/util/qsgsimpletexturenode.h | 82 - src/declarative/scenegraph/util/qsgtexture.cpp | 541 -- src/declarative/scenegraph/util/qsgtexture.h | 133 - src/declarative/scenegraph/util/qsgtexture_p.h | 118 - .../scenegraph/util/qsgtexturematerial.cpp | 410 -- .../scenegraph/util/qsgtexturematerial.h | 102 - .../scenegraph/util/qsgtexturematerial_p.h | 73 - .../scenegraph/util/qsgtextureprovider.cpp | 59 - .../scenegraph/util/qsgtextureprovider_p.h | 68 - .../scenegraph/util/qsgvertexcolormaterial.cpp | 173 - .../scenegraph/util/qsgvertexcolormaterial.h | 69 - src/declarative/util/qdeclarativeanimation.cpp | 2441 --------- src/declarative/util/qdeclarativeanimation_p.h | 458 -- src/declarative/util/qdeclarativeanimation_p_p.h | 366 -- src/declarative/util/qdeclarativebehavior.cpp | 228 - src/declarative/util/qdeclarativebehavior_p.h | 97 - src/declarative/util/qdeclarativebind.cpp | 309 -- src/declarative/util/qdeclarativebind_p.h | 98 - src/declarative/util/qdeclarativechangeset.cpp | 479 -- src/declarative/util/qdeclarativechangeset_p.h | 166 - src/declarative/util/qdeclarativeconnections.cpp | 302 -- src/declarative/util/qdeclarativeconnections_p.h | 102 - src/declarative/util/qdeclarativefontloader.cpp | 335 -- src/declarative/util/qdeclarativefontloader_p.h | 97 - src/declarative/util/qdeclarativelistaccessor.cpp | 138 - src/declarative/util/qdeclarativelistaccessor_p.h | 80 - .../util/qdeclarativelistcompositor.cpp | 1203 ----- .../util/qdeclarativelistcompositor_p.h | 371 -- src/declarative/util/qdeclarativepackage.cpp | 202 - src/declarative/util/qdeclarativepackage_p.h | 98 - src/declarative/util/qdeclarativepath.cpp | 1484 ------ src/declarative/util/qdeclarativepath_p.h | 452 -- src/declarative/util/qdeclarativepath_p_p.h | 88 - .../util/qdeclarativepathinterpolator.cpp | 122 - .../util/qdeclarativepathinterpolator_p.h | 100 - src/declarative/util/qdeclarativepixmapcache.cpp | 1241 ----- src/declarative/util/qdeclarativepixmapcache_p.h | 143 - .../util/qdeclarativepropertychanges.cpp | 796 --- .../util/qdeclarativepropertychanges_p.h | 112 - .../util/qdeclarativesmoothedanimation.cpp | 503 -- .../util/qdeclarativesmoothedanimation_p.h | 103 - .../util/qdeclarativesmoothedanimation_p_p.h | 136 - .../util/qdeclarativespringanimation.cpp | 462 -- .../util/qdeclarativespringanimation_p.h | 111 - src/declarative/util/qdeclarativestate.cpp | 734 --- src/declarative/util/qdeclarativestate_p.h | 210 - src/declarative/util/qdeclarativestate_p_p.h | 264 - src/declarative/util/qdeclarativestategroup.cpp | 516 -- src/declarative/util/qdeclarativestategroup_p.h | 97 - .../util/qdeclarativestateoperations.cpp | 158 - .../util/qdeclarativestateoperations_p.h | 88 - src/declarative/util/qdeclarativestyledtext.cpp | 624 --- src/declarative/util/qdeclarativestyledtext_p.h | 69 - src/declarative/util/qdeclarativesvgparser.cpp | 614 --- src/declarative/util/qdeclarativesvgparser_p.h | 60 - src/declarative/util/qdeclarativesystempalette.cpp | 312 -- src/declarative/util/qdeclarativesystempalette_p.h | 122 - src/declarative/util/qdeclarativetimeline.cpp | 947 ---- src/declarative/util/qdeclarativetimeline_p_p.h | 200 - src/declarative/util/qdeclarativetimer.cpp | 324 -- src/declarative/util/qdeclarativetimer_p.h | 115 - src/declarative/util/qdeclarativetransition.cpp | 392 -- src/declarative/util/qdeclarativetransition_p.h | 111 - .../util/qdeclarativetransitionmanager.cpp | 282 -- .../util/qdeclarativetransitionmanager_p_p.h | 85 - src/declarative/util/qdeclarativeutilmodule.cpp | 98 - src/declarative/util/qdeclarativeutilmodule_p.h | 63 - src/declarative/util/util.pri | 60 +- src/imports/etcprovider/etcprovider.pro | 2 +- src/imports/etcprovider/qetcprovider.h | 2 +- src/imports/imports.pro | 4 +- src/imports/qtquick2/plugin.cpp | 68 + src/imports/qtquick2/qmldir | 1 + src/imports/qtquick2/qtquick2.pro | 19 + src/imports/testlib/main.cpp | 2 +- src/imports/testlib/testlib.pro | 2 +- .../qmltooling/qmldbg_qtquick2/qmldbg_qtquick2.pro | 2 +- .../qmltooling/qmldbg_qtquick2/qtquick2plugin.cpp | 2 +- .../qmltooling/qmldbg_qtquick2/sghighlight.h | 2 +- .../qmltooling/qmldbg_qtquick2/sgselectiontool.cpp | 4 +- .../qmltooling/qmldbg_qtquick2/sgviewinspector.cpp | 6 +- src/qmltest/qmltest.pro | 2 +- src/qmltest/quicktest.cpp | 2 +- src/qmltest/quicktestevent.cpp | 4 +- src/quick/designer/designer.pri | 2 + src/quick/designer/designersupport.cpp | 408 ++ src/quick/designer/designersupport.h | 152 + src/quick/items/checksync.pl | 108 + src/quick/items/context2d/context2d.pri | 16 + src/quick/items/context2d/qquickcanvasitem.cpp | 714 +++ src/quick/items/context2d/qquickcanvasitem_p.h | 148 + src/quick/items/context2d/qquickcontext2d.cpp | 3540 +++++++++++++ src/quick/items/context2d/qquickcontext2d_p.h | 210 + .../context2d/qquickcontext2dcommandbuffer.cpp | 469 ++ .../context2d/qquickcontext2dcommandbuffer_p.h | 266 + src/quick/items/context2d/qquickcontext2dnode.cpp | 124 + src/quick/items/context2d/qquickcontext2dnode_p.h | 84 + .../items/context2d/qquickcontext2dtexture.cpp | 778 +++ .../items/context2d/qquickcontext2dtexture_p.h | 203 + src/quick/items/context2d/qquickcontext2dtile.cpp | 165 + src/quick/items/context2d/qquickcontext2dtile_p.h | 110 + src/quick/items/items.pri | 131 + src/quick/items/qquickanchors.cpp | 1180 +++++ src/quick/items/qquickanchors_p.h | 199 + src/quick/items/qquickanchors_p_p.h | 176 + src/quick/items/qquickanimatedimage.cpp | 397 ++ src/quick/items/qquickanimatedimage_p.h | 115 + src/quick/items/qquickanimatedimage_p_p.h | 88 + src/quick/items/qquickanimation.cpp | 792 +++ src/quick/items/qquickanimation_p.h | 207 + src/quick/items/qquickanimation_p_p.h | 153 + src/quick/items/qquickborderimage.cpp | 600 +++ src/quick/items/qquickborderimage_p.h | 108 + src/quick/items/qquickborderimage_p_p.h | 103 + src/quick/items/qquickcanvas.cpp | 2646 ++++++++++ src/quick/items/qquickcanvas.h | 163 + src/quick/items/qquickcanvas_p.h | 323 ++ src/quick/items/qquickclipnode.cpp | 120 + src/quick/items/qquickclipnode_p.h | 71 + src/quick/items/qquickdrag.cpp | 462 ++ src/quick/items/qquickdrag_p.h | 206 + src/quick/items/qquickdroparea.cpp | 428 ++ src/quick/items/qquickdroparea_p.h | 165 + src/quick/items/qquickevents.cpp | 239 + src/quick/items/qquickevents_p_p.h | 145 + src/quick/items/qquickflickable.cpp | 2003 ++++++++ src/quick/items/qquickflickable_p.h | 275 + src/quick/items/qquickflickable_p_p.h | 262 + src/quick/items/qquickflipable.cpp | 308 ++ src/quick/items/qquickflipable_p.h | 102 + src/quick/items/qquickfocusscope.cpp | 70 + src/quick/items/qquickfocusscope_p.h | 66 + src/quick/items/qquickgridview.cpp | 1958 ++++++++ src/quick/items/qquickgridview_p.h | 145 + src/quick/items/qquickimage.cpp | 746 +++ src/quick/items/qquickimage_p.h | 120 + src/quick/items/qquickimage_p_p.h | 85 + src/quick/items/qquickimagebase.cpp | 290 ++ src/quick/items/qquickimagebase_p.h | 119 + src/quick/items/qquickimagebase_p_p.h | 93 + src/quick/items/qquickimplicitsizeitem.cpp | 64 + src/quick/items/qquickimplicitsizeitem_p.h | 75 + src/quick/items/qquickimplicitsizeitem_p_p.h | 78 + src/quick/items/qquickitem.cpp | 5238 ++++++++++++++++++++ src/quick/items/qquickitem.h | 420 ++ src/quick/items/qquickitem_p.h | 752 +++ src/quick/items/qquickitemchangelistener_p.h | 82 + src/quick/items/qquickitemsmodule.cpp | 241 + src/quick/items/qquickitemsmodule_p.h | 63 + src/quick/items/qquickitemview.cpp | 1732 +++++++ src/quick/items/qquickitemview_p.h | 294 ++ src/quick/items/qquickitemview_p_p.h | 258 + src/quick/items/qquicklistview.cpp | 2533 ++++++++++ src/quick/items/qquicklistview_p.h | 213 + src/quick/items/qquickloader.cpp | 858 ++++ src/quick/items/qquickloader_p.h | 121 + src/quick/items/qquickloader_p_p.h | 121 + src/quick/items/qquickmousearea.cpp | 1168 +++++ src/quick/items/qquickmousearea_p.h | 229 + src/quick/items/qquickmousearea_p_p.h | 112 + src/quick/items/qquickmultipointtoucharea.cpp | 729 +++ src/quick/items/qquickmultipointtoucharea_p.h | 265 + src/quick/items/qquickninepatchnode.cpp | 302 ++ src/quick/items/qquickninepatchnode_p.h | 98 + src/quick/items/qquickpainteditem.cpp | 528 ++ src/quick/items/qquickpainteditem.h | 130 + src/quick/items/qquickpainteditem_p.h | 71 + src/quick/items/qquickpathview.cpp | 1781 +++++++ src/quick/items/qquickpathview_p.h | 257 + src/quick/items/qquickpathview_p_p.h | 199 + src/quick/items/qquickpincharea.cpp | 600 +++ src/quick/items/qquickpincharea_p.h | 313 ++ src/quick/items/qquickpincharea_p_p.h | 116 + src/quick/items/qquickpositioners.cpp | 1532 ++++++ src/quick/items/qquickpositioners_p.h | 293 ++ src/quick/items/qquickpositioners_p_p.h | 164 + src/quick/items/qquickrectangle.cpp | 556 +++ src/quick/items/qquickrectangle_p.h | 188 + src/quick/items/qquickrectangle_p_p.h | 103 + src/quick/items/qquickrepeater.cpp | 476 ++ src/quick/items/qquickrepeater_p.h | 110 + src/quick/items/qquickrepeater_p_p.h | 89 + src/quick/items/qquickscalegrid.cpp | 214 + src/quick/items/qquickscalegrid_p_p.h | 132 + src/quick/items/qquickshadereffect.cpp | 763 +++ src/quick/items/qquickshadereffect_p.h | 156 + src/quick/items/qquickshadereffectmesh.cpp | 216 + src/quick/items/qquickshadereffectmesh_p.h | 102 + src/quick/items/qquickshadereffectnode.cpp | 317 ++ src/quick/items/qquickshadereffectnode_p.h | 149 + src/quick/items/qquickshadereffectsource.cpp | 921 ++++ src/quick/items/qquickshadereffectsource_p.h | 257 + src/quick/items/qquicksprite.cpp | 130 + src/quick/items/qquicksprite_p.h | 133 + src/quick/items/qquickspriteengine.cpp | 501 ++ src/quick/items/qquickspriteengine_p.h | 321 ++ src/quick/items/qquickspriteimage.cpp | 455 ++ src/quick/items/qquickspriteimage_p.h | 138 + src/quick/items/qquickstateoperations.cpp | 1346 +++++ src/quick/items/qquickstateoperations_p.h | 273 + src/quick/items/qquicktext.cpp | 1950 ++++++++ src/quick/items/qquicktext_p.h | 251 + src/quick/items/qquicktext_p_p.h | 169 + src/quick/items/qquicktextedit.cpp | 2091 ++++++++ src/quick/items/qquicktextedit_p.h | 312 ++ src/quick/items/qquicktextedit_p_p.h | 144 + src/quick/items/qquicktextinput.cpp | 2007 ++++++++ src/quick/items/qquicktextinput_p.h | 300 ++ src/quick/items/qquicktextinput_p_p.h | 172 + src/quick/items/qquicktextnode.cpp | 1344 +++++ src/quick/items/qquicktextnode_p.h | 110 + src/quick/items/qquicktranslate.cpp | 319 ++ src/quick/items/qquicktranslate_p.h | 160 + src/quick/items/qquickview.cpp | 541 ++ src/quick/items/qquickview.h | 118 + src/quick/items/qquickview_p.h | 103 + src/quick/items/qquickvisualadaptormodel.cpp | 889 ++++ src/quick/items/qquickvisualadaptormodel_p.h | 129 + src/quick/items/qquickvisualdatamodel.cpp | 2668 ++++++++++ src/quick/items/qquickvisualdatamodel_p.h | 239 + src/quick/items/qquickvisualitemmodel.cpp | 235 + src/quick/items/qquickvisualitemmodel_p.h | 174 + src/quick/items/qquickwindowmodule.cpp | 55 + src/quick/items/qquickwindowmodule_p.h | 63 + src/quick/items/syncexcludes | 11 + src/quick/particles/particleresources/noise.png | Bin 0 -> 19477 bytes src/quick/particles/particles.pri | 69 + src/quick/particles/particles.qrc | 5 + src/quick/particles/qquickage.cpp | 112 + src/quick/particles/qquickage_p.h | 99 + src/quick/particles/qquickangledirection.cpp | 116 + src/quick/particles/qquickangledirection_p.h | 131 + src/quick/particles/qquickcumulativedirection.cpp | 70 + src/quick/particles/qquickcumulativedirection_p.h | 67 + src/quick/particles/qquickcustomaffector.cpp | 211 + src/quick/particles/qquickcustomaffector_p.h | 162 + src/quick/particles/qquickcustomparticle.cpp | 596 +++ src/quick/particles/qquickcustomparticle_p.h | 119 + src/quick/particles/qquickdirection.cpp | 64 + src/quick/particles/qquickdirection_p.h | 68 + src/quick/particles/qquickellipseextruder.cpp | 80 + src/quick/particles/qquickellipseextruder_p.h | 83 + src/quick/particles/qquickfriction.cpp | 111 + src/quick/particles/qquickfriction_p.h | 101 + src/quick/particles/qquickgravity.cpp | 97 + src/quick/particles/qquickgravity_p.h | 115 + src/quick/particles/qquickgroupgoal.cpp | 112 + src/quick/particles/qquickgroupgoal_p.h | 100 + src/quick/particles/qquickimageparticle.cpp | 1804 +++++++ src/quick/particles/qquickimageparticle_p.h | 427 ++ src/quick/particles/qquickitemparticle.cpp | 269 + src/quick/particles/qquickitemparticle_p.h | 137 + src/quick/particles/qquicklineextruder.cpp | 84 + src/quick/particles/qquicklineextruder_p.h | 77 + src/quick/particles/qquickmaskextruder.cpp | 113 + src/quick/particles/qquickmaskextruder_p.h | 95 + src/quick/particles/qquickparticleaffector.cpp | 279 ++ src/quick/particles/qquickparticleaffector_p.h | 199 + src/quick/particles/qquickparticleemitter.cpp | 501 ++ src/quick/particles/qquickparticleemitter_p.h | 349 ++ src/quick/particles/qquickparticleextruder.cpp | 70 + src/quick/particles/qquickparticleextruder_p.h | 71 + src/quick/particles/qquickparticlegroup.cpp | 143 + src/quick/particles/qquickparticlegroup_p.h | 112 + src/quick/particles/qquickparticlepainter.cpp | 150 + src/quick/particles/qquickparticlepainter_p.h | 129 + src/quick/particles/qquickparticlesmodule.cpp | 120 + src/quick/particles/qquickparticlesmodule_p.h | 61 + src/quick/particles/qquickparticlesystem.cpp | 1106 +++++ src/quick/particles/qquickparticlesystem_p.h | 378 ++ src/quick/particles/qquickpointattractor.cpp | 162 + src/quick/particles/qquickpointattractor_p.h | 167 + src/quick/particles/qquickpointdirection.cpp | 85 + src/quick/particles/qquickpointdirection_p.h | 133 + src/quick/particles/qquickrectangleextruder.cpp | 86 + src/quick/particles/qquickrectangleextruder_p.h | 86 + src/quick/particles/qquickspritegoal.cpp | 153 + src/quick/particles/qquickspritegoal_p.h | 123 + src/quick/particles/qquicktargetdirection.cpp | 131 + src/quick/particles/qquicktargetdirection_p.h | 189 + src/quick/particles/qquicktrailemitter.cpp | 285 ++ src/quick/particles/qquicktrailemitter_p.h | 168 + src/quick/particles/qquickturbulence.cpp | 205 + src/quick/particles/qquickturbulence_p.h | 116 + src/quick/particles/qquickv8particledata.cpp | 503 ++ src/quick/particles/qquickv8particledata_p.h | 67 + src/quick/particles/qquickwander.cpp | 180 + src/quick/particles/qquickwander_p.h | 158 + src/quick/qtquick2.cpp | 193 + src/quick/qtquick2_p.h | 61 + src/quick/qtquickglobal.h | 67 + src/quick/qtquickglobal_p.h | 60 + src/quick/quick.pro | 47 + .../scenegraph/coreapi/qsgdefaultrenderer.cpp | 527 ++ .../scenegraph/coreapi/qsgdefaultrenderer_p.h | 119 + src/quick/scenegraph/coreapi/qsggeometry.cpp | 466 ++ src/quick/scenegraph/coreapi/qsggeometry.h | 294 ++ src/quick/scenegraph/coreapi/qsggeometry_p.h | 73 + src/quick/scenegraph/coreapi/qsgmaterial.cpp | 535 ++ src/quick/scenegraph/coreapi/qsgmaterial.h | 143 + src/quick/scenegraph/coreapi/qsgnode.cpp | 1264 +++++ src/quick/scenegraph/coreapi/qsgnode.h | 346 ++ src/quick/scenegraph/coreapi/qsgnodeupdater.cpp | 287 ++ src/quick/scenegraph/coreapi/qsgnodeupdater_p.h | 86 + src/quick/scenegraph/coreapi/qsgrenderer.cpp | 743 +++ src/quick/scenegraph/coreapi/qsgrenderer_p.h | 232 + src/quick/scenegraph/qsgadaptationlayer.cpp | 315 ++ src/quick/scenegraph/qsgadaptationlayer_p.h | 255 + src/quick/scenegraph/qsgcontext.cpp | 513 ++ src/quick/scenegraph/qsgcontext_p.h | 142 + src/quick/scenegraph/qsgcontextplugin.cpp | 104 + src/quick/scenegraph/qsgcontextplugin_p.h | 80 + .../qsgdefaultdistancefieldglyphcache.cpp | 324 ++ .../qsgdefaultdistancefieldglyphcache_p.h | 165 + src/quick/scenegraph/qsgdefaultglyphnode.cpp | 95 + src/quick/scenegraph/qsgdefaultglyphnode_p.cpp | 306 ++ src/quick/scenegraph/qsgdefaultglyphnode_p.h | 85 + src/quick/scenegraph/qsgdefaultglyphnode_p_p.h | 96 + src/quick/scenegraph/qsgdefaultimagenode.cpp | 293 ++ src/quick/scenegraph/qsgdefaultimagenode_p.h | 88 + src/quick/scenegraph/qsgdefaultrectanglenode.cpp | 548 ++ src/quick/scenegraph/qsgdefaultrectanglenode_p.h | 106 + src/quick/scenegraph/qsgdistancefieldglyphnode.cpp | 316 ++ .../scenegraph/qsgdistancefieldglyphnode_p.cpp | 725 +++ src/quick/scenegraph/qsgdistancefieldglyphnode_p.h | 105 + .../scenegraph/qsgdistancefieldglyphnode_p_p.h | 140 + src/quick/scenegraph/qsgflashnode.cpp | 62 + src/quick/scenegraph/qsgflashnode_p.h | 67 + src/quick/scenegraph/qsgpathsimplifier.cpp | 1673 +++++++ src/quick/scenegraph/qsgpathsimplifier_p.h | 68 + src/quick/scenegraph/scenegraph.pri | 86 + src/quick/scenegraph/util/qsgareaallocator.cpp | 290 ++ src/quick/scenegraph/util/qsgareaallocator_p.h | 74 + src/quick/scenegraph/util/qsgdistancefieldutil.cpp | 805 +++ src/quick/scenegraph/util/qsgdistancefieldutil_p.h | 111 + src/quick/scenegraph/util/qsgengine.cpp | 115 + src/quick/scenegraph/util/qsgengine.h | 100 + src/quick/scenegraph/util/qsgflatcolormaterial.cpp | 202 + src/quick/scenegraph/util/qsgflatcolormaterial.h | 72 + src/quick/scenegraph/util/qsgpainternode.cpp | 464 ++ src/quick/scenegraph/util/qsgpainternode_p.h | 158 + src/quick/scenegraph/util/qsgsimplematerial.h | 220 + src/quick/scenegraph/util/qsgsimplerectnode.cpp | 132 + src/quick/scenegraph/util/qsgsimplerectnode.h | 75 + src/quick/scenegraph/util/qsgsimpletexturenode.cpp | 154 + src/quick/scenegraph/util/qsgsimpletexturenode.h | 80 + src/quick/scenegraph/util/qsgtexture.cpp | 541 ++ src/quick/scenegraph/util/qsgtexture.h | 132 + src/quick/scenegraph/util/qsgtexture_p.h | 119 + src/quick/scenegraph/util/qsgtexturematerial.cpp | 410 ++ src/quick/scenegraph/util/qsgtexturematerial.h | 99 + src/quick/scenegraph/util/qsgtexturematerial_p.h | 71 + src/quick/scenegraph/util/qsgtextureprovider.cpp | 59 + src/quick/scenegraph/util/qsgtextureprovider_p.h | 66 + .../scenegraph/util/qsgvertexcolormaterial.cpp | 173 + src/quick/scenegraph/util/qsgvertexcolormaterial.h | 67 + src/quick/util/qdeclarativeanimation.cpp | 2441 +++++++++ src/quick/util/qdeclarativeanimation_p.h | 456 ++ src/quick/util/qdeclarativeanimation_p_p.h | 366 ++ src/quick/util/qdeclarativebehavior.cpp | 228 + src/quick/util/qdeclarativebehavior_p.h | 95 + src/quick/util/qdeclarativebind.cpp | 309 ++ src/quick/util/qdeclarativebind_p.h | 96 + src/quick/util/qdeclarativechangeset.cpp | 479 ++ src/quick/util/qdeclarativechangeset_p.h | 166 + src/quick/util/qdeclarativeconnections.cpp | 302 ++ src/quick/util/qdeclarativeconnections_p.h | 100 + src/quick/util/qdeclarativefontloader.cpp | 335 ++ src/quick/util/qdeclarativefontloader_p.h | 95 + src/quick/util/qdeclarativelistaccessor.cpp | 138 + src/quick/util/qdeclarativelistaccessor_p.h | 78 + src/quick/util/qdeclarativelistcompositor.cpp | 1203 +++++ src/quick/util/qdeclarativelistcompositor_p.h | 371 ++ src/quick/util/qdeclarativepackage.cpp | 202 + src/quick/util/qdeclarativepackage_p.h | 96 + src/quick/util/qdeclarativepath.cpp | 1484 ++++++ src/quick/util/qdeclarativepath_p.h | 450 ++ src/quick/util/qdeclarativepath_p_p.h | 88 + src/quick/util/qdeclarativepathinterpolator.cpp | 122 + src/quick/util/qdeclarativepathinterpolator_p.h | 98 + src/quick/util/qdeclarativepixmapcache.cpp | 1241 +++++ src/quick/util/qdeclarativepixmapcache_p.h | 142 + src/quick/util/qdeclarativepropertychanges.cpp | 796 +++ src/quick/util/qdeclarativepropertychanges_p.h | 110 + src/quick/util/qdeclarativesmoothedanimation.cpp | 503 ++ src/quick/util/qdeclarativesmoothedanimation_p.h | 101 + src/quick/util/qdeclarativesmoothedanimation_p_p.h | 136 + src/quick/util/qdeclarativespringanimation.cpp | 462 ++ src/quick/util/qdeclarativespringanimation_p.h | 109 + src/quick/util/qdeclarativestate.cpp | 734 +++ src/quick/util/qdeclarativestate_p.h | 208 + src/quick/util/qdeclarativestate_p_p.h | 264 + src/quick/util/qdeclarativestategroup.cpp | 516 ++ src/quick/util/qdeclarativestategroup_p.h | 95 + src/quick/util/qdeclarativestateoperations.cpp | 158 + src/quick/util/qdeclarativestateoperations_p.h | 85 + src/quick/util/qdeclarativestyledtext.cpp | 624 +++ src/quick/util/qdeclarativestyledtext_p.h | 69 + src/quick/util/qdeclarativesvgparser.cpp | 614 +++ src/quick/util/qdeclarativesvgparser_p.h | 60 + src/quick/util/qdeclarativesystempalette.cpp | 312 ++ src/quick/util/qdeclarativesystempalette_p.h | 120 + src/quick/util/qdeclarativetimeline.cpp | 947 ++++ src/quick/util/qdeclarativetimeline_p_p.h | 200 + src/quick/util/qdeclarativetimer.cpp | 324 ++ src/quick/util/qdeclarativetimer_p.h | 113 + src/quick/util/qdeclarativetransition.cpp | 392 ++ src/quick/util/qdeclarativetransition_p.h | 109 + src/quick/util/qdeclarativetransitionmanager.cpp | 282 ++ src/quick/util/qdeclarativetransitionmanager_p_p.h | 85 + src/quick/util/qdeclarativeutilmodule.cpp | 98 + src/quick/util/qdeclarativeutilmodule_p.h | 61 + src/quick/util/util.pri | 59 + src/src.pro | 2 +- 678 files changed, 117473 insertions(+), 117454 deletions(-) delete mode 100644 src/declarative/designer/designer.pri delete mode 100644 src/declarative/designer/designersupport.cpp delete mode 100644 src/declarative/designer/designersupport.h delete mode 100755 src/declarative/items/checksync.pl delete mode 100644 src/declarative/items/context2d/context2d.pri delete mode 100644 src/declarative/items/context2d/qquickcanvasitem.cpp delete mode 100644 src/declarative/items/context2d/qquickcanvasitem_p.h delete mode 100644 src/declarative/items/context2d/qquickcontext2d.cpp delete mode 100644 src/declarative/items/context2d/qquickcontext2d_p.h delete mode 100644 src/declarative/items/context2d/qquickcontext2dcommandbuffer.cpp delete mode 100644 src/declarative/items/context2d/qquickcontext2dcommandbuffer_p.h delete mode 100644 src/declarative/items/context2d/qquickcontext2dnode.cpp delete mode 100644 src/declarative/items/context2d/qquickcontext2dnode_p.h delete mode 100644 src/declarative/items/context2d/qquickcontext2dtexture.cpp delete mode 100644 src/declarative/items/context2d/qquickcontext2dtexture_p.h delete mode 100644 src/declarative/items/context2d/qquickcontext2dtile.cpp delete mode 100644 src/declarative/items/context2d/qquickcontext2dtile_p.h delete mode 100644 src/declarative/items/items.pri delete mode 100644 src/declarative/items/qquickanchors.cpp delete mode 100644 src/declarative/items/qquickanchors_p.h delete mode 100644 src/declarative/items/qquickanchors_p_p.h delete mode 100644 src/declarative/items/qquickanimatedimage.cpp delete mode 100644 src/declarative/items/qquickanimatedimage_p.h delete mode 100644 src/declarative/items/qquickanimatedimage_p_p.h delete mode 100644 src/declarative/items/qquickanimation.cpp delete mode 100644 src/declarative/items/qquickanimation_p.h delete mode 100644 src/declarative/items/qquickanimation_p_p.h delete mode 100644 src/declarative/items/qquickborderimage.cpp delete mode 100644 src/declarative/items/qquickborderimage_p.h delete mode 100644 src/declarative/items/qquickborderimage_p_p.h delete mode 100644 src/declarative/items/qquickcanvas.cpp delete mode 100644 src/declarative/items/qquickcanvas.h delete mode 100644 src/declarative/items/qquickcanvas_p.h delete mode 100644 src/declarative/items/qquickclipnode.cpp delete mode 100644 src/declarative/items/qquickclipnode_p.h delete mode 100644 src/declarative/items/qquickdrag.cpp delete mode 100644 src/declarative/items/qquickdrag_p.h delete mode 100644 src/declarative/items/qquickdroparea.cpp delete mode 100644 src/declarative/items/qquickdroparea_p.h delete mode 100644 src/declarative/items/qquickevents.cpp delete mode 100644 src/declarative/items/qquickevents_p_p.h delete mode 100644 src/declarative/items/qquickflickable.cpp delete mode 100644 src/declarative/items/qquickflickable_p.h delete mode 100644 src/declarative/items/qquickflickable_p_p.h delete mode 100644 src/declarative/items/qquickflipable.cpp delete mode 100644 src/declarative/items/qquickflipable_p.h delete mode 100644 src/declarative/items/qquickfocusscope.cpp delete mode 100644 src/declarative/items/qquickfocusscope_p.h delete mode 100644 src/declarative/items/qquickgridview.cpp delete mode 100644 src/declarative/items/qquickgridview_p.h delete mode 100644 src/declarative/items/qquickimage.cpp delete mode 100644 src/declarative/items/qquickimage_p.h delete mode 100644 src/declarative/items/qquickimage_p_p.h delete mode 100644 src/declarative/items/qquickimagebase.cpp delete mode 100644 src/declarative/items/qquickimagebase_p.h delete mode 100644 src/declarative/items/qquickimagebase_p_p.h delete mode 100644 src/declarative/items/qquickimplicitsizeitem.cpp delete mode 100644 src/declarative/items/qquickimplicitsizeitem_p.h delete mode 100644 src/declarative/items/qquickimplicitsizeitem_p_p.h delete mode 100644 src/declarative/items/qquickitem.cpp delete mode 100644 src/declarative/items/qquickitem.h delete mode 100644 src/declarative/items/qquickitem_p.h delete mode 100644 src/declarative/items/qquickitemchangelistener_p.h delete mode 100644 src/declarative/items/qquickitemsmodule.cpp delete mode 100644 src/declarative/items/qquickitemsmodule_p.h delete mode 100644 src/declarative/items/qquickitemview.cpp delete mode 100644 src/declarative/items/qquickitemview_p.h delete mode 100644 src/declarative/items/qquickitemview_p_p.h delete mode 100644 src/declarative/items/qquicklistview.cpp delete mode 100644 src/declarative/items/qquicklistview_p.h delete mode 100644 src/declarative/items/qquickloader.cpp delete mode 100644 src/declarative/items/qquickloader_p.h delete mode 100644 src/declarative/items/qquickloader_p_p.h delete mode 100644 src/declarative/items/qquickmousearea.cpp delete mode 100644 src/declarative/items/qquickmousearea_p.h delete mode 100644 src/declarative/items/qquickmousearea_p_p.h delete mode 100644 src/declarative/items/qquickmultipointtoucharea.cpp delete mode 100644 src/declarative/items/qquickmultipointtoucharea_p.h delete mode 100644 src/declarative/items/qquickninepatchnode.cpp delete mode 100644 src/declarative/items/qquickninepatchnode_p.h delete mode 100644 src/declarative/items/qquickpainteditem.cpp delete mode 100644 src/declarative/items/qquickpainteditem.h delete mode 100644 src/declarative/items/qquickpainteditem_p.h delete mode 100644 src/declarative/items/qquickpathview.cpp delete mode 100644 src/declarative/items/qquickpathview_p.h delete mode 100644 src/declarative/items/qquickpathview_p_p.h delete mode 100644 src/declarative/items/qquickpincharea.cpp delete mode 100644 src/declarative/items/qquickpincharea_p.h delete mode 100644 src/declarative/items/qquickpincharea_p_p.h delete mode 100644 src/declarative/items/qquickpositioners.cpp delete mode 100644 src/declarative/items/qquickpositioners_p.h delete mode 100644 src/declarative/items/qquickpositioners_p_p.h delete mode 100644 src/declarative/items/qquickrectangle.cpp delete mode 100644 src/declarative/items/qquickrectangle_p.h delete mode 100644 src/declarative/items/qquickrectangle_p_p.h delete mode 100644 src/declarative/items/qquickrepeater.cpp delete mode 100644 src/declarative/items/qquickrepeater_p.h delete mode 100644 src/declarative/items/qquickrepeater_p_p.h delete mode 100644 src/declarative/items/qquickscalegrid.cpp delete mode 100644 src/declarative/items/qquickscalegrid_p_p.h delete mode 100644 src/declarative/items/qquickshadereffect.cpp delete mode 100644 src/declarative/items/qquickshadereffect_p.h delete mode 100644 src/declarative/items/qquickshadereffectmesh.cpp delete mode 100644 src/declarative/items/qquickshadereffectmesh_p.h delete mode 100644 src/declarative/items/qquickshadereffectnode.cpp delete mode 100644 src/declarative/items/qquickshadereffectnode_p.h delete mode 100644 src/declarative/items/qquickshadereffectsource.cpp delete mode 100644 src/declarative/items/qquickshadereffectsource_p.h delete mode 100644 src/declarative/items/qquicksprite.cpp delete mode 100644 src/declarative/items/qquicksprite_p.h delete mode 100644 src/declarative/items/qquickspriteengine.cpp delete mode 100644 src/declarative/items/qquickspriteengine_p.h delete mode 100644 src/declarative/items/qquickspriteimage.cpp delete mode 100644 src/declarative/items/qquickspriteimage_p.h delete mode 100644 src/declarative/items/qquickstateoperations.cpp delete mode 100644 src/declarative/items/qquickstateoperations_p.h delete mode 100644 src/declarative/items/qquicktext.cpp delete mode 100644 src/declarative/items/qquicktext_p.h delete mode 100644 src/declarative/items/qquicktext_p_p.h delete mode 100644 src/declarative/items/qquicktextedit.cpp delete mode 100644 src/declarative/items/qquicktextedit_p.h delete mode 100644 src/declarative/items/qquicktextedit_p_p.h delete mode 100644 src/declarative/items/qquicktextinput.cpp delete mode 100644 src/declarative/items/qquicktextinput_p.h delete mode 100644 src/declarative/items/qquicktextinput_p_p.h delete mode 100644 src/declarative/items/qquicktextnode.cpp delete mode 100644 src/declarative/items/qquicktextnode_p.h delete mode 100644 src/declarative/items/qquicktranslate.cpp delete mode 100644 src/declarative/items/qquicktranslate_p.h delete mode 100644 src/declarative/items/qquickview.cpp delete mode 100644 src/declarative/items/qquickview.h delete mode 100644 src/declarative/items/qquickview_p.h delete mode 100644 src/declarative/items/qquickvisualadaptormodel.cpp delete mode 100644 src/declarative/items/qquickvisualadaptormodel_p.h delete mode 100644 src/declarative/items/qquickvisualdatamodel.cpp delete mode 100644 src/declarative/items/qquickvisualdatamodel_p.h delete mode 100644 src/declarative/items/qquickvisualitemmodel.cpp delete mode 100644 src/declarative/items/qquickvisualitemmodel_p.h delete mode 100644 src/declarative/items/qquickwindowmodule.cpp delete mode 100644 src/declarative/items/qquickwindowmodule_p.h delete mode 100644 src/declarative/items/syncexcludes delete mode 100644 src/declarative/particles/particleresources/noise.png delete mode 100644 src/declarative/particles/particles.pri delete mode 100644 src/declarative/particles/particles.qrc delete mode 100644 src/declarative/particles/qquickage.cpp delete mode 100644 src/declarative/particles/qquickage_p.h delete mode 100644 src/declarative/particles/qquickangledirection.cpp delete mode 100644 src/declarative/particles/qquickangledirection_p.h delete mode 100644 src/declarative/particles/qquickcumulativedirection.cpp delete mode 100644 src/declarative/particles/qquickcumulativedirection_p.h delete mode 100644 src/declarative/particles/qquickcustomaffector.cpp delete mode 100644 src/declarative/particles/qquickcustomaffector_p.h delete mode 100644 src/declarative/particles/qquickcustomparticle.cpp delete mode 100644 src/declarative/particles/qquickcustomparticle_p.h delete mode 100644 src/declarative/particles/qquickdirection.cpp delete mode 100644 src/declarative/particles/qquickdirection_p.h delete mode 100644 src/declarative/particles/qquickellipseextruder.cpp delete mode 100644 src/declarative/particles/qquickellipseextruder_p.h delete mode 100644 src/declarative/particles/qquickfriction.cpp delete mode 100644 src/declarative/particles/qquickfriction_p.h delete mode 100644 src/declarative/particles/qquickgravity.cpp delete mode 100644 src/declarative/particles/qquickgravity_p.h delete mode 100644 src/declarative/particles/qquickgroupgoal.cpp delete mode 100644 src/declarative/particles/qquickgroupgoal_p.h delete mode 100644 src/declarative/particles/qquickimageparticle.cpp delete mode 100644 src/declarative/particles/qquickimageparticle_p.h delete mode 100644 src/declarative/particles/qquickitemparticle.cpp delete mode 100644 src/declarative/particles/qquickitemparticle_p.h delete mode 100644 src/declarative/particles/qquicklineextruder.cpp delete mode 100644 src/declarative/particles/qquicklineextruder_p.h delete mode 100644 src/declarative/particles/qquickmaskextruder.cpp delete mode 100644 src/declarative/particles/qquickmaskextruder_p.h delete mode 100644 src/declarative/particles/qquickparticleaffector.cpp delete mode 100644 src/declarative/particles/qquickparticleaffector_p.h delete mode 100644 src/declarative/particles/qquickparticleemitter.cpp delete mode 100644 src/declarative/particles/qquickparticleemitter_p.h delete mode 100644 src/declarative/particles/qquickparticleextruder.cpp delete mode 100644 src/declarative/particles/qquickparticleextruder_p.h delete mode 100644 src/declarative/particles/qquickparticlegroup.cpp delete mode 100644 src/declarative/particles/qquickparticlegroup_p.h delete mode 100644 src/declarative/particles/qquickparticlepainter.cpp delete mode 100644 src/declarative/particles/qquickparticlepainter_p.h delete mode 100644 src/declarative/particles/qquickparticlesmodule.cpp delete mode 100644 src/declarative/particles/qquickparticlesmodule_p.h delete mode 100644 src/declarative/particles/qquickparticlesystem.cpp delete mode 100644 src/declarative/particles/qquickparticlesystem_p.h delete mode 100644 src/declarative/particles/qquickpointattractor.cpp delete mode 100644 src/declarative/particles/qquickpointattractor_p.h delete mode 100644 src/declarative/particles/qquickpointdirection.cpp delete mode 100644 src/declarative/particles/qquickpointdirection_p.h delete mode 100644 src/declarative/particles/qquickrectangleextruder.cpp delete mode 100644 src/declarative/particles/qquickrectangleextruder_p.h delete mode 100644 src/declarative/particles/qquickspritegoal.cpp delete mode 100644 src/declarative/particles/qquickspritegoal_p.h delete mode 100644 src/declarative/particles/qquicktargetdirection.cpp delete mode 100644 src/declarative/particles/qquicktargetdirection_p.h delete mode 100644 src/declarative/particles/qquicktrailemitter.cpp delete mode 100644 src/declarative/particles/qquicktrailemitter_p.h delete mode 100644 src/declarative/particles/qquickturbulence.cpp delete mode 100644 src/declarative/particles/qquickturbulence_p.h delete mode 100644 src/declarative/particles/qquickv8particledata.cpp delete mode 100644 src/declarative/particles/qquickv8particledata_p.h delete mode 100644 src/declarative/particles/qquickwander.cpp delete mode 100644 src/declarative/particles/qquickwander_p.h delete mode 100644 src/declarative/qtquick2.cpp delete mode 100644 src/declarative/qtquick2_p.h delete mode 100644 src/declarative/scenegraph/coreapi/qsgdefaultrenderer.cpp delete mode 100644 src/declarative/scenegraph/coreapi/qsgdefaultrenderer_p.h delete mode 100644 src/declarative/scenegraph/coreapi/qsggeometry.cpp delete mode 100644 src/declarative/scenegraph/coreapi/qsggeometry.h delete mode 100644 src/declarative/scenegraph/coreapi/qsggeometry_p.h delete mode 100644 src/declarative/scenegraph/coreapi/qsgmaterial.cpp delete mode 100644 src/declarative/scenegraph/coreapi/qsgmaterial.h delete mode 100644 src/declarative/scenegraph/coreapi/qsgnode.cpp delete mode 100644 src/declarative/scenegraph/coreapi/qsgnode.h delete mode 100644 src/declarative/scenegraph/coreapi/qsgnodeupdater.cpp delete mode 100644 src/declarative/scenegraph/coreapi/qsgnodeupdater_p.h delete mode 100644 src/declarative/scenegraph/coreapi/qsgrenderer.cpp delete mode 100644 src/declarative/scenegraph/coreapi/qsgrenderer_p.h delete mode 100644 src/declarative/scenegraph/qsgadaptationlayer.cpp delete mode 100644 src/declarative/scenegraph/qsgadaptationlayer_p.h delete mode 100644 src/declarative/scenegraph/qsgcontext.cpp delete mode 100644 src/declarative/scenegraph/qsgcontext_p.h delete mode 100644 src/declarative/scenegraph/qsgcontextplugin.cpp delete mode 100644 src/declarative/scenegraph/qsgcontextplugin_p.h delete mode 100644 src/declarative/scenegraph/qsgdefaultdistancefieldglyphcache.cpp delete mode 100644 src/declarative/scenegraph/qsgdefaultdistancefieldglyphcache_p.h delete mode 100644 src/declarative/scenegraph/qsgdefaultglyphnode.cpp delete mode 100644 src/declarative/scenegraph/qsgdefaultglyphnode_p.cpp delete mode 100644 src/declarative/scenegraph/qsgdefaultglyphnode_p.h delete mode 100644 src/declarative/scenegraph/qsgdefaultglyphnode_p_p.h delete mode 100644 src/declarative/scenegraph/qsgdefaultimagenode.cpp delete mode 100644 src/declarative/scenegraph/qsgdefaultimagenode_p.h delete mode 100644 src/declarative/scenegraph/qsgdefaultrectanglenode.cpp delete mode 100644 src/declarative/scenegraph/qsgdefaultrectanglenode_p.h delete mode 100644 src/declarative/scenegraph/qsgdistancefieldglyphnode.cpp delete mode 100644 src/declarative/scenegraph/qsgdistancefieldglyphnode_p.cpp delete mode 100644 src/declarative/scenegraph/qsgdistancefieldglyphnode_p.h delete mode 100644 src/declarative/scenegraph/qsgdistancefieldglyphnode_p_p.h delete mode 100644 src/declarative/scenegraph/qsgflashnode.cpp delete mode 100644 src/declarative/scenegraph/qsgflashnode_p.h delete mode 100644 src/declarative/scenegraph/qsgpathsimplifier.cpp delete mode 100644 src/declarative/scenegraph/qsgpathsimplifier_p.h delete mode 100644 src/declarative/scenegraph/scenegraph.pri delete mode 100644 src/declarative/scenegraph/util/qsgareaallocator.cpp delete mode 100644 src/declarative/scenegraph/util/qsgareaallocator_p.h delete mode 100644 src/declarative/scenegraph/util/qsgdistancefieldutil.cpp delete mode 100644 src/declarative/scenegraph/util/qsgdistancefieldutil_p.h delete mode 100644 src/declarative/scenegraph/util/qsgengine.cpp delete mode 100644 src/declarative/scenegraph/util/qsgengine.h delete mode 100644 src/declarative/scenegraph/util/qsgflatcolormaterial.cpp delete mode 100644 src/declarative/scenegraph/util/qsgflatcolormaterial.h delete mode 100644 src/declarative/scenegraph/util/qsgpainternode.cpp delete mode 100644 src/declarative/scenegraph/util/qsgpainternode_p.h delete mode 100644 src/declarative/scenegraph/util/qsgsimplematerial.h delete mode 100644 src/declarative/scenegraph/util/qsgsimplerectnode.cpp delete mode 100644 src/declarative/scenegraph/util/qsgsimplerectnode.h delete mode 100644 src/declarative/scenegraph/util/qsgsimpletexturenode.cpp delete mode 100644 src/declarative/scenegraph/util/qsgsimpletexturenode.h delete mode 100644 src/declarative/scenegraph/util/qsgtexture.cpp delete mode 100644 src/declarative/scenegraph/util/qsgtexture.h delete mode 100644 src/declarative/scenegraph/util/qsgtexture_p.h delete mode 100644 src/declarative/scenegraph/util/qsgtexturematerial.cpp delete mode 100644 src/declarative/scenegraph/util/qsgtexturematerial.h delete mode 100644 src/declarative/scenegraph/util/qsgtexturematerial_p.h delete mode 100644 src/declarative/scenegraph/util/qsgtextureprovider.cpp delete mode 100644 src/declarative/scenegraph/util/qsgtextureprovider_p.h delete mode 100644 src/declarative/scenegraph/util/qsgvertexcolormaterial.cpp delete mode 100644 src/declarative/scenegraph/util/qsgvertexcolormaterial.h delete mode 100644 src/declarative/util/qdeclarativeanimation.cpp delete mode 100644 src/declarative/util/qdeclarativeanimation_p.h delete mode 100644 src/declarative/util/qdeclarativeanimation_p_p.h delete mode 100644 src/declarative/util/qdeclarativebehavior.cpp delete mode 100644 src/declarative/util/qdeclarativebehavior_p.h delete mode 100644 src/declarative/util/qdeclarativebind.cpp delete mode 100644 src/declarative/util/qdeclarativebind_p.h delete mode 100644 src/declarative/util/qdeclarativechangeset.cpp delete mode 100644 src/declarative/util/qdeclarativechangeset_p.h delete mode 100644 src/declarative/util/qdeclarativeconnections.cpp delete mode 100644 src/declarative/util/qdeclarativeconnections_p.h delete mode 100644 src/declarative/util/qdeclarativefontloader.cpp delete mode 100644 src/declarative/util/qdeclarativefontloader_p.h delete mode 100644 src/declarative/util/qdeclarativelistaccessor.cpp delete mode 100644 src/declarative/util/qdeclarativelistaccessor_p.h delete mode 100644 src/declarative/util/qdeclarativelistcompositor.cpp delete mode 100644 src/declarative/util/qdeclarativelistcompositor_p.h delete mode 100644 src/declarative/util/qdeclarativepackage.cpp delete mode 100644 src/declarative/util/qdeclarativepackage_p.h delete mode 100644 src/declarative/util/qdeclarativepath.cpp delete mode 100644 src/declarative/util/qdeclarativepath_p.h delete mode 100644 src/declarative/util/qdeclarativepath_p_p.h delete mode 100644 src/declarative/util/qdeclarativepathinterpolator.cpp delete mode 100644 src/declarative/util/qdeclarativepathinterpolator_p.h delete mode 100644 src/declarative/util/qdeclarativepixmapcache.cpp delete mode 100644 src/declarative/util/qdeclarativepixmapcache_p.h delete mode 100644 src/declarative/util/qdeclarativepropertychanges.cpp delete mode 100644 src/declarative/util/qdeclarativepropertychanges_p.h delete mode 100644 src/declarative/util/qdeclarativesmoothedanimation.cpp delete mode 100644 src/declarative/util/qdeclarativesmoothedanimation_p.h delete mode 100644 src/declarative/util/qdeclarativesmoothedanimation_p_p.h delete mode 100644 src/declarative/util/qdeclarativespringanimation.cpp delete mode 100644 src/declarative/util/qdeclarativespringanimation_p.h delete mode 100644 src/declarative/util/qdeclarativestate.cpp delete mode 100644 src/declarative/util/qdeclarativestate_p.h delete mode 100644 src/declarative/util/qdeclarativestate_p_p.h delete mode 100644 src/declarative/util/qdeclarativestategroup.cpp delete mode 100644 src/declarative/util/qdeclarativestategroup_p.h delete mode 100644 src/declarative/util/qdeclarativestateoperations.cpp delete mode 100644 src/declarative/util/qdeclarativestateoperations_p.h delete mode 100644 src/declarative/util/qdeclarativestyledtext.cpp delete mode 100644 src/declarative/util/qdeclarativestyledtext_p.h delete mode 100644 src/declarative/util/qdeclarativesvgparser.cpp delete mode 100644 src/declarative/util/qdeclarativesvgparser_p.h delete mode 100644 src/declarative/util/qdeclarativesystempalette.cpp delete mode 100644 src/declarative/util/qdeclarativesystempalette_p.h delete mode 100644 src/declarative/util/qdeclarativetimeline.cpp delete mode 100644 src/declarative/util/qdeclarativetimeline_p_p.h delete mode 100644 src/declarative/util/qdeclarativetimer.cpp delete mode 100644 src/declarative/util/qdeclarativetimer_p.h delete mode 100644 src/declarative/util/qdeclarativetransition.cpp delete mode 100644 src/declarative/util/qdeclarativetransition_p.h delete mode 100644 src/declarative/util/qdeclarativetransitionmanager.cpp delete mode 100644 src/declarative/util/qdeclarativetransitionmanager_p_p.h delete mode 100644 src/declarative/util/qdeclarativeutilmodule.cpp delete mode 100644 src/declarative/util/qdeclarativeutilmodule_p.h create mode 100644 src/imports/qtquick2/plugin.cpp create mode 100644 src/imports/qtquick2/qmldir create mode 100644 src/imports/qtquick2/qtquick2.pro create mode 100644 src/quick/designer/designer.pri create mode 100644 src/quick/designer/designersupport.cpp create mode 100644 src/quick/designer/designersupport.h create mode 100755 src/quick/items/checksync.pl create mode 100644 src/quick/items/context2d/context2d.pri create mode 100644 src/quick/items/context2d/qquickcanvasitem.cpp create mode 100644 src/quick/items/context2d/qquickcanvasitem_p.h create mode 100644 src/quick/items/context2d/qquickcontext2d.cpp create mode 100644 src/quick/items/context2d/qquickcontext2d_p.h create mode 100644 src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp create mode 100644 src/quick/items/context2d/qquickcontext2dcommandbuffer_p.h create mode 100644 src/quick/items/context2d/qquickcontext2dnode.cpp create mode 100644 src/quick/items/context2d/qquickcontext2dnode_p.h create mode 100644 src/quick/items/context2d/qquickcontext2dtexture.cpp create mode 100644 src/quick/items/context2d/qquickcontext2dtexture_p.h create mode 100644 src/quick/items/context2d/qquickcontext2dtile.cpp create mode 100644 src/quick/items/context2d/qquickcontext2dtile_p.h create mode 100644 src/quick/items/items.pri create mode 100644 src/quick/items/qquickanchors.cpp create mode 100644 src/quick/items/qquickanchors_p.h create mode 100644 src/quick/items/qquickanchors_p_p.h create mode 100644 src/quick/items/qquickanimatedimage.cpp create mode 100644 src/quick/items/qquickanimatedimage_p.h create mode 100644 src/quick/items/qquickanimatedimage_p_p.h create mode 100644 src/quick/items/qquickanimation.cpp create mode 100644 src/quick/items/qquickanimation_p.h create mode 100644 src/quick/items/qquickanimation_p_p.h create mode 100644 src/quick/items/qquickborderimage.cpp create mode 100644 src/quick/items/qquickborderimage_p.h create mode 100644 src/quick/items/qquickborderimage_p_p.h create mode 100644 src/quick/items/qquickcanvas.cpp create mode 100644 src/quick/items/qquickcanvas.h create mode 100644 src/quick/items/qquickcanvas_p.h create mode 100644 src/quick/items/qquickclipnode.cpp create mode 100644 src/quick/items/qquickclipnode_p.h create mode 100644 src/quick/items/qquickdrag.cpp create mode 100644 src/quick/items/qquickdrag_p.h create mode 100644 src/quick/items/qquickdroparea.cpp create mode 100644 src/quick/items/qquickdroparea_p.h create mode 100644 src/quick/items/qquickevents.cpp create mode 100644 src/quick/items/qquickevents_p_p.h create mode 100644 src/quick/items/qquickflickable.cpp create mode 100644 src/quick/items/qquickflickable_p.h create mode 100644 src/quick/items/qquickflickable_p_p.h create mode 100644 src/quick/items/qquickflipable.cpp create mode 100644 src/quick/items/qquickflipable_p.h create mode 100644 src/quick/items/qquickfocusscope.cpp create mode 100644 src/quick/items/qquickfocusscope_p.h create mode 100644 src/quick/items/qquickgridview.cpp create mode 100644 src/quick/items/qquickgridview_p.h create mode 100644 src/quick/items/qquickimage.cpp create mode 100644 src/quick/items/qquickimage_p.h create mode 100644 src/quick/items/qquickimage_p_p.h create mode 100644 src/quick/items/qquickimagebase.cpp create mode 100644 src/quick/items/qquickimagebase_p.h create mode 100644 src/quick/items/qquickimagebase_p_p.h create mode 100644 src/quick/items/qquickimplicitsizeitem.cpp create mode 100644 src/quick/items/qquickimplicitsizeitem_p.h create mode 100644 src/quick/items/qquickimplicitsizeitem_p_p.h create mode 100644 src/quick/items/qquickitem.cpp create mode 100644 src/quick/items/qquickitem.h create mode 100644 src/quick/items/qquickitem_p.h create mode 100644 src/quick/items/qquickitemchangelistener_p.h create mode 100644 src/quick/items/qquickitemsmodule.cpp create mode 100644 src/quick/items/qquickitemsmodule_p.h create mode 100644 src/quick/items/qquickitemview.cpp create mode 100644 src/quick/items/qquickitemview_p.h create mode 100644 src/quick/items/qquickitemview_p_p.h create mode 100644 src/quick/items/qquicklistview.cpp create mode 100644 src/quick/items/qquicklistview_p.h create mode 100644 src/quick/items/qquickloader.cpp create mode 100644 src/quick/items/qquickloader_p.h create mode 100644 src/quick/items/qquickloader_p_p.h create mode 100644 src/quick/items/qquickmousearea.cpp create mode 100644 src/quick/items/qquickmousearea_p.h create mode 100644 src/quick/items/qquickmousearea_p_p.h create mode 100644 src/quick/items/qquickmultipointtoucharea.cpp create mode 100644 src/quick/items/qquickmultipointtoucharea_p.h create mode 100644 src/quick/items/qquickninepatchnode.cpp create mode 100644 src/quick/items/qquickninepatchnode_p.h create mode 100644 src/quick/items/qquickpainteditem.cpp create mode 100644 src/quick/items/qquickpainteditem.h create mode 100644 src/quick/items/qquickpainteditem_p.h create mode 100644 src/quick/items/qquickpathview.cpp create mode 100644 src/quick/items/qquickpathview_p.h create mode 100644 src/quick/items/qquickpathview_p_p.h create mode 100644 src/quick/items/qquickpincharea.cpp create mode 100644 src/quick/items/qquickpincharea_p.h create mode 100644 src/quick/items/qquickpincharea_p_p.h create mode 100644 src/quick/items/qquickpositioners.cpp create mode 100644 src/quick/items/qquickpositioners_p.h create mode 100644 src/quick/items/qquickpositioners_p_p.h create mode 100644 src/quick/items/qquickrectangle.cpp create mode 100644 src/quick/items/qquickrectangle_p.h create mode 100644 src/quick/items/qquickrectangle_p_p.h create mode 100644 src/quick/items/qquickrepeater.cpp create mode 100644 src/quick/items/qquickrepeater_p.h create mode 100644 src/quick/items/qquickrepeater_p_p.h create mode 100644 src/quick/items/qquickscalegrid.cpp create mode 100644 src/quick/items/qquickscalegrid_p_p.h create mode 100644 src/quick/items/qquickshadereffect.cpp create mode 100644 src/quick/items/qquickshadereffect_p.h create mode 100644 src/quick/items/qquickshadereffectmesh.cpp create mode 100644 src/quick/items/qquickshadereffectmesh_p.h create mode 100644 src/quick/items/qquickshadereffectnode.cpp create mode 100644 src/quick/items/qquickshadereffectnode_p.h create mode 100644 src/quick/items/qquickshadereffectsource.cpp create mode 100644 src/quick/items/qquickshadereffectsource_p.h create mode 100644 src/quick/items/qquicksprite.cpp create mode 100644 src/quick/items/qquicksprite_p.h create mode 100644 src/quick/items/qquickspriteengine.cpp create mode 100644 src/quick/items/qquickspriteengine_p.h create mode 100644 src/quick/items/qquickspriteimage.cpp create mode 100644 src/quick/items/qquickspriteimage_p.h create mode 100644 src/quick/items/qquickstateoperations.cpp create mode 100644 src/quick/items/qquickstateoperations_p.h create mode 100644 src/quick/items/qquicktext.cpp create mode 100644 src/quick/items/qquicktext_p.h create mode 100644 src/quick/items/qquicktext_p_p.h create mode 100644 src/quick/items/qquicktextedit.cpp create mode 100644 src/quick/items/qquicktextedit_p.h create mode 100644 src/quick/items/qquicktextedit_p_p.h create mode 100644 src/quick/items/qquicktextinput.cpp create mode 100644 src/quick/items/qquicktextinput_p.h create mode 100644 src/quick/items/qquicktextinput_p_p.h create mode 100644 src/quick/items/qquicktextnode.cpp create mode 100644 src/quick/items/qquicktextnode_p.h create mode 100644 src/quick/items/qquicktranslate.cpp create mode 100644 src/quick/items/qquicktranslate_p.h create mode 100644 src/quick/items/qquickview.cpp create mode 100644 src/quick/items/qquickview.h create mode 100644 src/quick/items/qquickview_p.h create mode 100644 src/quick/items/qquickvisualadaptormodel.cpp create mode 100644 src/quick/items/qquickvisualadaptormodel_p.h create mode 100644 src/quick/items/qquickvisualdatamodel.cpp create mode 100644 src/quick/items/qquickvisualdatamodel_p.h create mode 100644 src/quick/items/qquickvisualitemmodel.cpp create mode 100644 src/quick/items/qquickvisualitemmodel_p.h create mode 100644 src/quick/items/qquickwindowmodule.cpp create mode 100644 src/quick/items/qquickwindowmodule_p.h create mode 100644 src/quick/items/syncexcludes create mode 100644 src/quick/particles/particleresources/noise.png create mode 100644 src/quick/particles/particles.pri create mode 100644 src/quick/particles/particles.qrc create mode 100644 src/quick/particles/qquickage.cpp create mode 100644 src/quick/particles/qquickage_p.h create mode 100644 src/quick/particles/qquickangledirection.cpp create mode 100644 src/quick/particles/qquickangledirection_p.h create mode 100644 src/quick/particles/qquickcumulativedirection.cpp create mode 100644 src/quick/particles/qquickcumulativedirection_p.h create mode 100644 src/quick/particles/qquickcustomaffector.cpp create mode 100644 src/quick/particles/qquickcustomaffector_p.h create mode 100644 src/quick/particles/qquickcustomparticle.cpp create mode 100644 src/quick/particles/qquickcustomparticle_p.h create mode 100644 src/quick/particles/qquickdirection.cpp create mode 100644 src/quick/particles/qquickdirection_p.h create mode 100644 src/quick/particles/qquickellipseextruder.cpp create mode 100644 src/quick/particles/qquickellipseextruder_p.h create mode 100644 src/quick/particles/qquickfriction.cpp create mode 100644 src/quick/particles/qquickfriction_p.h create mode 100644 src/quick/particles/qquickgravity.cpp create mode 100644 src/quick/particles/qquickgravity_p.h create mode 100644 src/quick/particles/qquickgroupgoal.cpp create mode 100644 src/quick/particles/qquickgroupgoal_p.h create mode 100644 src/quick/particles/qquickimageparticle.cpp create mode 100644 src/quick/particles/qquickimageparticle_p.h create mode 100644 src/quick/particles/qquickitemparticle.cpp create mode 100644 src/quick/particles/qquickitemparticle_p.h create mode 100644 src/quick/particles/qquicklineextruder.cpp create mode 100644 src/quick/particles/qquicklineextruder_p.h create mode 100644 src/quick/particles/qquickmaskextruder.cpp create mode 100644 src/quick/particles/qquickmaskextruder_p.h create mode 100644 src/quick/particles/qquickparticleaffector.cpp create mode 100644 src/quick/particles/qquickparticleaffector_p.h create mode 100644 src/quick/particles/qquickparticleemitter.cpp create mode 100644 src/quick/particles/qquickparticleemitter_p.h create mode 100644 src/quick/particles/qquickparticleextruder.cpp create mode 100644 src/quick/particles/qquickparticleextruder_p.h create mode 100644 src/quick/particles/qquickparticlegroup.cpp create mode 100644 src/quick/particles/qquickparticlegroup_p.h create mode 100644 src/quick/particles/qquickparticlepainter.cpp create mode 100644 src/quick/particles/qquickparticlepainter_p.h create mode 100644 src/quick/particles/qquickparticlesmodule.cpp create mode 100644 src/quick/particles/qquickparticlesmodule_p.h create mode 100644 src/quick/particles/qquickparticlesystem.cpp create mode 100644 src/quick/particles/qquickparticlesystem_p.h create mode 100644 src/quick/particles/qquickpointattractor.cpp create mode 100644 src/quick/particles/qquickpointattractor_p.h create mode 100644 src/quick/particles/qquickpointdirection.cpp create mode 100644 src/quick/particles/qquickpointdirection_p.h create mode 100644 src/quick/particles/qquickrectangleextruder.cpp create mode 100644 src/quick/particles/qquickrectangleextruder_p.h create mode 100644 src/quick/particles/qquickspritegoal.cpp create mode 100644 src/quick/particles/qquickspritegoal_p.h create mode 100644 src/quick/particles/qquicktargetdirection.cpp create mode 100644 src/quick/particles/qquicktargetdirection_p.h create mode 100644 src/quick/particles/qquicktrailemitter.cpp create mode 100644 src/quick/particles/qquicktrailemitter_p.h create mode 100644 src/quick/particles/qquickturbulence.cpp create mode 100644 src/quick/particles/qquickturbulence_p.h create mode 100644 src/quick/particles/qquickv8particledata.cpp create mode 100644 src/quick/particles/qquickv8particledata_p.h create mode 100644 src/quick/particles/qquickwander.cpp create mode 100644 src/quick/particles/qquickwander_p.h create mode 100644 src/quick/qtquick2.cpp create mode 100644 src/quick/qtquick2_p.h create mode 100644 src/quick/qtquickglobal.h create mode 100644 src/quick/qtquickglobal_p.h create mode 100644 src/quick/quick.pro create mode 100644 src/quick/scenegraph/coreapi/qsgdefaultrenderer.cpp create mode 100644 src/quick/scenegraph/coreapi/qsgdefaultrenderer_p.h create mode 100644 src/quick/scenegraph/coreapi/qsggeometry.cpp create mode 100644 src/quick/scenegraph/coreapi/qsggeometry.h create mode 100644 src/quick/scenegraph/coreapi/qsggeometry_p.h create mode 100644 src/quick/scenegraph/coreapi/qsgmaterial.cpp create mode 100644 src/quick/scenegraph/coreapi/qsgmaterial.h create mode 100644 src/quick/scenegraph/coreapi/qsgnode.cpp create mode 100644 src/quick/scenegraph/coreapi/qsgnode.h create mode 100644 src/quick/scenegraph/coreapi/qsgnodeupdater.cpp create mode 100644 src/quick/scenegraph/coreapi/qsgnodeupdater_p.h create mode 100644 src/quick/scenegraph/coreapi/qsgrenderer.cpp create mode 100644 src/quick/scenegraph/coreapi/qsgrenderer_p.h create mode 100644 src/quick/scenegraph/qsgadaptationlayer.cpp create mode 100644 src/quick/scenegraph/qsgadaptationlayer_p.h create mode 100644 src/quick/scenegraph/qsgcontext.cpp create mode 100644 src/quick/scenegraph/qsgcontext_p.h create mode 100644 src/quick/scenegraph/qsgcontextplugin.cpp create mode 100644 src/quick/scenegraph/qsgcontextplugin_p.h create mode 100644 src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp create mode 100644 src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h create mode 100644 src/quick/scenegraph/qsgdefaultglyphnode.cpp create mode 100644 src/quick/scenegraph/qsgdefaultglyphnode_p.cpp create mode 100644 src/quick/scenegraph/qsgdefaultglyphnode_p.h create mode 100644 src/quick/scenegraph/qsgdefaultglyphnode_p_p.h create mode 100644 src/quick/scenegraph/qsgdefaultimagenode.cpp create mode 100644 src/quick/scenegraph/qsgdefaultimagenode_p.h create mode 100644 src/quick/scenegraph/qsgdefaultrectanglenode.cpp create mode 100644 src/quick/scenegraph/qsgdefaultrectanglenode_p.h create mode 100644 src/quick/scenegraph/qsgdistancefieldglyphnode.cpp create mode 100644 src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp create mode 100644 src/quick/scenegraph/qsgdistancefieldglyphnode_p.h create mode 100644 src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h create mode 100644 src/quick/scenegraph/qsgflashnode.cpp create mode 100644 src/quick/scenegraph/qsgflashnode_p.h create mode 100644 src/quick/scenegraph/qsgpathsimplifier.cpp create mode 100644 src/quick/scenegraph/qsgpathsimplifier_p.h create mode 100644 src/quick/scenegraph/scenegraph.pri create mode 100644 src/quick/scenegraph/util/qsgareaallocator.cpp create mode 100644 src/quick/scenegraph/util/qsgareaallocator_p.h create mode 100644 src/quick/scenegraph/util/qsgdistancefieldutil.cpp create mode 100644 src/quick/scenegraph/util/qsgdistancefieldutil_p.h create mode 100644 src/quick/scenegraph/util/qsgengine.cpp create mode 100644 src/quick/scenegraph/util/qsgengine.h create mode 100644 src/quick/scenegraph/util/qsgflatcolormaterial.cpp create mode 100644 src/quick/scenegraph/util/qsgflatcolormaterial.h create mode 100644 src/quick/scenegraph/util/qsgpainternode.cpp create mode 100644 src/quick/scenegraph/util/qsgpainternode_p.h create mode 100644 src/quick/scenegraph/util/qsgsimplematerial.h create mode 100644 src/quick/scenegraph/util/qsgsimplerectnode.cpp create mode 100644 src/quick/scenegraph/util/qsgsimplerectnode.h create mode 100644 src/quick/scenegraph/util/qsgsimpletexturenode.cpp create mode 100644 src/quick/scenegraph/util/qsgsimpletexturenode.h create mode 100644 src/quick/scenegraph/util/qsgtexture.cpp create mode 100644 src/quick/scenegraph/util/qsgtexture.h create mode 100644 src/quick/scenegraph/util/qsgtexture_p.h create mode 100644 src/quick/scenegraph/util/qsgtexturematerial.cpp create mode 100644 src/quick/scenegraph/util/qsgtexturematerial.h create mode 100644 src/quick/scenegraph/util/qsgtexturematerial_p.h create mode 100644 src/quick/scenegraph/util/qsgtextureprovider.cpp create mode 100644 src/quick/scenegraph/util/qsgtextureprovider_p.h create mode 100644 src/quick/scenegraph/util/qsgvertexcolormaterial.cpp create mode 100644 src/quick/scenegraph/util/qsgvertexcolormaterial.h create mode 100644 src/quick/util/qdeclarativeanimation.cpp create mode 100644 src/quick/util/qdeclarativeanimation_p.h create mode 100644 src/quick/util/qdeclarativeanimation_p_p.h create mode 100644 src/quick/util/qdeclarativebehavior.cpp create mode 100644 src/quick/util/qdeclarativebehavior_p.h create mode 100644 src/quick/util/qdeclarativebind.cpp create mode 100644 src/quick/util/qdeclarativebind_p.h create mode 100644 src/quick/util/qdeclarativechangeset.cpp create mode 100644 src/quick/util/qdeclarativechangeset_p.h create mode 100644 src/quick/util/qdeclarativeconnections.cpp create mode 100644 src/quick/util/qdeclarativeconnections_p.h create mode 100644 src/quick/util/qdeclarativefontloader.cpp create mode 100644 src/quick/util/qdeclarativefontloader_p.h create mode 100644 src/quick/util/qdeclarativelistaccessor.cpp create mode 100644 src/quick/util/qdeclarativelistaccessor_p.h create mode 100644 src/quick/util/qdeclarativelistcompositor.cpp create mode 100644 src/quick/util/qdeclarativelistcompositor_p.h create mode 100644 src/quick/util/qdeclarativepackage.cpp create mode 100644 src/quick/util/qdeclarativepackage_p.h create mode 100644 src/quick/util/qdeclarativepath.cpp create mode 100644 src/quick/util/qdeclarativepath_p.h create mode 100644 src/quick/util/qdeclarativepath_p_p.h create mode 100644 src/quick/util/qdeclarativepathinterpolator.cpp create mode 100644 src/quick/util/qdeclarativepathinterpolator_p.h create mode 100644 src/quick/util/qdeclarativepixmapcache.cpp create mode 100644 src/quick/util/qdeclarativepixmapcache_p.h create mode 100644 src/quick/util/qdeclarativepropertychanges.cpp create mode 100644 src/quick/util/qdeclarativepropertychanges_p.h create mode 100644 src/quick/util/qdeclarativesmoothedanimation.cpp create mode 100644 src/quick/util/qdeclarativesmoothedanimation_p.h create mode 100644 src/quick/util/qdeclarativesmoothedanimation_p_p.h create mode 100644 src/quick/util/qdeclarativespringanimation.cpp create mode 100644 src/quick/util/qdeclarativespringanimation_p.h create mode 100644 src/quick/util/qdeclarativestate.cpp create mode 100644 src/quick/util/qdeclarativestate_p.h create mode 100644 src/quick/util/qdeclarativestate_p_p.h create mode 100644 src/quick/util/qdeclarativestategroup.cpp create mode 100644 src/quick/util/qdeclarativestategroup_p.h create mode 100644 src/quick/util/qdeclarativestateoperations.cpp create mode 100644 src/quick/util/qdeclarativestateoperations_p.h create mode 100644 src/quick/util/qdeclarativestyledtext.cpp create mode 100644 src/quick/util/qdeclarativestyledtext_p.h create mode 100644 src/quick/util/qdeclarativesvgparser.cpp create mode 100644 src/quick/util/qdeclarativesvgparser_p.h create mode 100644 src/quick/util/qdeclarativesystempalette.cpp create mode 100644 src/quick/util/qdeclarativesystempalette_p.h create mode 100644 src/quick/util/qdeclarativetimeline.cpp create mode 100644 src/quick/util/qdeclarativetimeline_p_p.h create mode 100644 src/quick/util/qdeclarativetimer.cpp create mode 100644 src/quick/util/qdeclarativetimer_p.h create mode 100644 src/quick/util/qdeclarativetransition.cpp create mode 100644 src/quick/util/qdeclarativetransition_p.h create mode 100644 src/quick/util/qdeclarativetransitionmanager.cpp create mode 100644 src/quick/util/qdeclarativetransitionmanager_p_p.h create mode 100644 src/quick/util/qdeclarativeutilmodule.cpp create mode 100644 src/quick/util/qdeclarativeutilmodule_p.h create mode 100644 src/quick/util/util.pri (limited to 'src') diff --git a/src/declarative/debugger/qdeclarativeenginedebugservice_p.h b/src/declarative/debugger/qdeclarativeenginedebugservice_p.h index 7c74c63801..c2ee93b665 100644 --- a/src/declarative/debugger/qdeclarativeenginedebugservice_p.h +++ b/src/declarative/debugger/qdeclarativeenginedebugservice_p.h @@ -66,7 +66,7 @@ class QDeclarativeWatcher; class QDataStream; class QDeclarativeDebugStatesDelegate; -class QDeclarativeEngineDebugService : public QDeclarativeDebugService +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeEngineDebugService : public QDeclarativeDebugService { Q_OBJECT public: diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index 265e4eba33..ca81a4a3d3 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -31,10 +31,3 @@ HEADERS += qtdeclarativeversion.h include(util/util.pri) include(qml/qml.pri) include(debugger/debugger.pri) -include(scenegraph/scenegraph.pri) -include(items/items.pri) -include(particles/particles.pri) -include(designer/designer.pri) - -HEADERS += qtquick2_p.h -SOURCES += qtquick2.cpp diff --git a/src/declarative/designer/designer.pri b/src/declarative/designer/designer.pri deleted file mode 100644 index c523525977..0000000000 --- a/src/declarative/designer/designer.pri +++ /dev/null @@ -1,2 +0,0 @@ -HEADERS += designer/designersupport.h -SOURCES += designer/designersupport.cpp diff --git a/src/declarative/designer/designersupport.cpp b/src/declarative/designer/designersupport.cpp deleted file mode 100644 index 9c565c138c..0000000000 --- a/src/declarative/designer/designersupport.cpp +++ /dev/null @@ -1,408 +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 QtDeclarative module 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 "designersupport.h" -#include - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -DesignerSupport::DesignerSupport() -{ -} - -DesignerSupport::~DesignerSupport() -{ - QHash::iterator iterator; - - for (iterator = m_itemTextureHash.begin(); iterator != m_itemTextureHash.end(); ++iterator) { - QQuickShaderEffectTexture *texture = iterator.value(); - QQuickItem *item = iterator.key(); - QQuickItemPrivate::get(item)->derefFromEffectItem(true); - delete texture; - } -} - -void DesignerSupport::refFromEffectItem(QQuickItem *referencedItem, bool hide) -{ - if (referencedItem == 0) - return; - - QQuickItemPrivate::get(referencedItem)->refFromEffectItem(hide); - QQuickCanvasPrivate::get(referencedItem->canvas())->updateDirtyNode(referencedItem); - - Q_ASSERT(QQuickItemPrivate::get(referencedItem)->rootNode); - - if (!m_itemTextureHash.contains(referencedItem)) { - QQuickShaderEffectTexture *texture = new QQuickShaderEffectTexture(referencedItem); - - texture->setLive(true); - texture->setItem(QQuickItemPrivate::get(referencedItem)->rootNode); - texture->setRect(referencedItem->boundingRect()); - texture->setSize(referencedItem->boundingRect().size().toSize()); - texture->setRecursive(true); -#ifndef QT_OPENGL_ES - texture->setFormat(GL_RGBA8); -#else - texture->setFormat(GL_RGBA); -#endif - texture->setHasMipmaps(false); - - m_itemTextureHash.insert(referencedItem, texture); - } -} - -void DesignerSupport::derefFromEffectItem(QQuickItem *referencedItem, bool unhide) -{ - if (referencedItem == 0) - return; - - delete m_itemTextureHash.take(referencedItem); - QQuickItemPrivate::get(referencedItem)->derefFromEffectItem(unhide); -} - -QImage DesignerSupport::renderImageForItem(QQuickItem *referencedItem, const QRectF &boundingRect, const QSize &imageSize) -{ - if (referencedItem == 0 || referencedItem->parentItem() == 0) { - qDebug() << __FILE__ << __LINE__ << "Warning: Item can be rendered."; - return QImage(); - } - - QQuickShaderEffectTexture *renderTexture = m_itemTextureHash.value(referencedItem); - - Q_ASSERT(renderTexture); - if (renderTexture == 0) - return QImage(); - renderTexture->setRect(boundingRect); - renderTexture->setSize(imageSize); - renderTexture->updateTexture(); - - QImage renderImage = renderTexture->toImage(); - renderImage = renderImage.mirrored(false, true); - - if (renderImage.size().isEmpty()) - qDebug() << __FILE__ << __LINE__ << "Warning: Image is empty."; - - return renderImage; -} - -bool DesignerSupport::isDirty(QQuickItem *referencedItem, DirtyType dirtyType) -{ - if (referencedItem == 0) - return false; - - return QQuickItemPrivate::get(referencedItem)->dirtyAttributes & dirtyType; -} - -void DesignerSupport::resetDirty(QQuickItem *referencedItem) -{ - if (referencedItem == 0) - return; - - QQuickItemPrivate::get(referencedItem)->dirtyAttributes = 0x0; - QQuickItemPrivate::get(referencedItem)->removeFromDirtyList(); -} - -QTransform DesignerSupport::canvasTransform(QQuickItem *referencedItem) -{ - if (referencedItem == 0) - return QTransform(); - - return QQuickItemPrivate::get(referencedItem)->itemToCanvasTransform(); -} - -QTransform DesignerSupport::parentTransform(QQuickItem *referencedItem) -{ - if (referencedItem == 0) - return QTransform(); - - QTransform parentTransform; - - QQuickItemPrivate::get(referencedItem)->itemToParentTransform(parentTransform); - - return parentTransform; -} - -QString propertyNameForAnchorLine(const QQuickAnchorLine::AnchorLine &anchorLine) -{ - switch (anchorLine) { - case QQuickAnchorLine::Left: return QLatin1String("left"); - case QQuickAnchorLine::Right: return QLatin1String("right"); - case QQuickAnchorLine::Top: return QLatin1String("top"); - case QQuickAnchorLine::Bottom: return QLatin1String("bottom"); - case QQuickAnchorLine::HCenter: return QLatin1String("horizontalCenter"); - case QQuickAnchorLine::VCenter: return QLatin1String("verticalCenter"); - case QQuickAnchorLine::Baseline: return QLatin1String("baseline"); - case QQuickAnchorLine::Invalid: - default: return QString(); - } -} - -bool isValidAnchorName(const QString &name) -{ - static QStringList anchorNameList(QStringList() << QLatin1String("anchors.top") - << QLatin1String("anchors.left") - << QLatin1String("anchors.right") - << QLatin1String("anchors.bottom") - << QLatin1String("anchors.verticalCenter") - << QLatin1String("anchors.horizontalCenter") - << QLatin1String("anchors.fill") - << QLatin1String("anchors.centerIn") - << QLatin1String("anchors.baseline")); - - return anchorNameList.contains(name); -} - -bool DesignerSupport::isAnchoredTo(QQuickItem *fromItem, QQuickItem *toItem) -{ - Q_ASSERT(dynamic_cast(QQuickItemPrivate::get(fromItem))); - QQuickItemPrivate *fromItemPrivate = static_cast(QQuickItemPrivate::get(fromItem)); - QQuickAnchors *anchors = fromItemPrivate->anchors(); - return anchors->fill() == toItem - || anchors->centerIn() == toItem - || anchors->bottom().item == toItem - || anchors->top().item == toItem - || anchors->left().item == toItem - || anchors->right().item == toItem - || anchors->verticalCenter().item == toItem - || anchors->horizontalCenter().item == toItem - || anchors->baseline().item == toItem; -} - -bool DesignerSupport::areChildrenAnchoredTo(QQuickItem *fromItem, QQuickItem *toItem) -{ - foreach (QQuickItem *childItem, fromItem->childItems()) { - if (childItem) { - if (isAnchoredTo(childItem, toItem)) - return true; - - if (areChildrenAnchoredTo(childItem, toItem)) - return true; - } - } - - return false; -} - -QQuickAnchors *anchors(QQuickItem *item) -{ - QQuickItemPrivate *itemPrivate = static_cast(QQuickItemPrivate::get(item)); - return itemPrivate->anchors(); -} - -QQuickAnchors::Anchor anchorLineFlagForName(const QString &name) -{ - if (name == QLatin1String("anchors.top")) - return QQuickAnchors::TopAnchor; - - if (name == QLatin1String("anchors.left")) - return QQuickAnchors::LeftAnchor; - - if (name == QLatin1String("anchors.bottom")) - return QQuickAnchors::BottomAnchor; - - if (name == QLatin1String("anchors.right")) - return QQuickAnchors::RightAnchor; - - if (name == QLatin1String("anchors.horizontalCenter")) - return QQuickAnchors::HCenterAnchor; - - if (name == QLatin1String("anchors.verticalCenter")) - return QQuickAnchors::VCenterAnchor; - - if (name == QLatin1String("anchors.baseline")) - return QQuickAnchors::BaselineAnchor; - - - Q_ASSERT_X(false, Q_FUNC_INFO, "wrong anchor name - this should never happen"); - return QQuickAnchors::LeftAnchor; -} - -bool DesignerSupport::hasAnchor(QQuickItem *item, const QString &name) -{ - if (!isValidAnchorName(name)) - return false; - - if (name == QLatin1String("anchors.fill")) - return anchors(item)->fill() != 0; - - if (name == QLatin1String("anchors.centerIn")) - return anchors(item)->centerIn() != 0; - - if (name == QLatin1String("anchors.right")) - return anchors(item)->right().item != 0; - - if (name == QLatin1String("anchors.top")) - return anchors(item)->top().item != 0; - - if (name == QLatin1String("anchors.left")) - return anchors(item)->left().item != 0; - - if (name == QLatin1String("anchors.bottom")) - return anchors(item)->bottom().item != 0; - - if (name == QLatin1String("anchors.horizontalCenter")) - return anchors(item)->horizontalCenter().item != 0; - - if (name == QLatin1String("anchors.verticalCenter")) - return anchors(item)->verticalCenter().item != 0; - - if (name == QLatin1String("anchors.baseline")) - return anchors(item)->baseline().item != 0; - - return anchors(item)->usedAnchors().testFlag(anchorLineFlagForName(name)); -} - -QQuickItem *DesignerSupport::anchorFillTargetItem(QQuickItem *item) -{ - return anchors(item)->fill(); -} - -QQuickItem *DesignerSupport::anchorCenterInTargetItem(QQuickItem *item) -{ - return anchors(item)->centerIn(); -} - - - -QPair DesignerSupport::anchorLineTarget(QQuickItem *item, const QString &name, QDeclarativeContext *context) -{ - QObject *targetObject = 0; - QString targetName; - - if (name == QLatin1String("anchors.fill")) { - targetObject = anchors(item)->fill(); - } else if (name == QLatin1String("anchors.centerIn")) { - targetObject = anchors(item)->centerIn(); - } else { - QDeclarativeProperty metaProperty(item, name, context); - if (!metaProperty.isValid()) - return QPair(); - - QQuickAnchorLine anchorLine = metaProperty.read().value(); - if (anchorLine.anchorLine != QQuickAnchorLine::Invalid) { - targetObject = anchorLine.item; - targetName = propertyNameForAnchorLine(anchorLine.anchorLine); - } - - } - - return QPair(targetName, targetObject); -} - -void DesignerSupport::resetAnchor(QQuickItem *item, const QString &name) -{ - if (name == QLatin1String("anchors.fill")) { - anchors(item)->resetFill(); - } else if (name == QLatin1String("anchors.centerIn")) { - anchors(item)->resetCenterIn(); - } else if (name == QLatin1String("anchors.top")) { - anchors(item)->resetTop(); - } else if (name == QLatin1String("anchors.left")) { - anchors(item)->resetLeft(); - } else if (name == QLatin1String("anchors.right")) { - anchors(item)->resetRight(); - } else if (name == QLatin1String("anchors.bottom")) { - anchors(item)->resetBottom(); - } else if (name == QLatin1String("anchors.horizontalCenter")) { - anchors(item)->resetHorizontalCenter(); - } else if (name == QLatin1String("anchors.verticalCenter")) { - anchors(item)->resetVerticalCenter(); - } else if (name == QLatin1String("anchors.baseline")) { - anchors(item)->resetBaseline(); - } -} - -QList DesignerSupport::statesForItem(QQuickItem *item) -{ - QList objectList; - QList stateList = QQuickItemPrivate::get(item)->_states()->states(); - qCopy(stateList.begin(), stateList.end(), objectList.begin()); - - return objectList; -} - -bool DesignerSupport::isComponentComplete(QQuickItem *item) -{ - return static_cast(QQuickItemPrivate::get(item))->componentComplete; -} - -int DesignerSupport::borderWidth(QQuickItem *item) -{ - QQuickRectangle *rectangle = qobject_cast(item); - if (rectangle) - return rectangle->border()->width(); - - return 0; -} - -void DesignerSupport::refreshExpressions(QDeclarativeContext *context) -{ - QDeclarativeContextPrivate::get(context)->data->refreshExpressions(); -} - -void DesignerSupport::setRootItem(QQuickView *view, QQuickItem *item) -{ - QQuickViewPrivate::get(view)->setRootObject(item); -} - -bool DesignerSupport::isValidWidth(QQuickItem *item) -{ - return QQuickItemPrivate::get(item)->heightValid; -} - -bool DesignerSupport::isValidHeight(QQuickItem *item) -{ - return QQuickItemPrivate::get(item)->widthValid; -} - -void DesignerSupport::updateDirtyNode(QQuickItem *item) -{ - QQuickCanvasPrivate::get(item->canvas())->updateDirtyNode(item); -} - -QT_END_NAMESPACE diff --git a/src/declarative/designer/designersupport.h b/src/declarative/designer/designersupport.h deleted file mode 100644 index 7654363276..0000000000 --- a/src/declarative/designer/designersupport.h +++ /dev/null @@ -1,153 +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 QtDeclarative module 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 DESIGNERSUPPORT_H -#define DESIGNERSUPPORT_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 -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickItem; -class QQuickShaderEffectTexture; -class QImage; -class QTransform; -class QDeclarativeContext; -class QQuickView; - - -class Q_DECLARATIVE_EXPORT DesignerSupport -{ -public: - enum DirtyType { - TransformOrigin = 0x00000001, - Transform = 0x00000002, - BasicTransform = 0x00000004, - Position = 0x00000008, - Size = 0x00000010, - - ZValue = 0x00000020, - Content = 0x00000040, - Smooth = 0x00000080, - OpacityValue = 0x00000100, - ChildrenChanged = 0x00000200, - ChildrenStackingChanged = 0x00000400, - ParentChanged = 0x00000800, - - Clip = 0x00001000, - Canvas = 0x00002000, - - EffectReference = 0x00008000, - Visible = 0x00010000, - HideReference = 0x00020000, - - TransformUpdateMask = TransformOrigin | Transform | BasicTransform | Position | Size | Canvas, - ComplexTransformUpdateMask = Transform | Canvas, - ContentUpdateMask = Size | Content | Smooth | Canvas, - ChildrenUpdateMask = ChildrenChanged | ChildrenStackingChanged | EffectReference | Canvas - }; - - - DesignerSupport(); - ~DesignerSupport(); - - void refFromEffectItem(QQuickItem *referencedItem, bool hide = true); - void derefFromEffectItem(QQuickItem *referencedItem, bool unhide = true); - - QImage renderImageForItem(QQuickItem *referencedItem, const QRectF &boundingRect, const QSize &imageSize); - - static bool isDirty(QQuickItem *referencedItem, DirtyType dirtyType); - static void resetDirty(QQuickItem *referencedItem); - - static QTransform canvasTransform(QQuickItem *referencedItem); - static QTransform parentTransform(QQuickItem *referencedItem); - - static bool isAnchoredTo(QQuickItem *fromItem, QQuickItem *toItem); - static bool areChildrenAnchoredTo(QQuickItem *fromItem, QQuickItem *toItem); - static bool hasAnchor(QQuickItem *item, const QString &name); - static QQuickItem *anchorFillTargetItem(QQuickItem *item); - static QQuickItem *anchorCenterInTargetItem(QQuickItem *item); - static QPair anchorLineTarget(QQuickItem *item, const QString &name, QDeclarativeContext *context); - static void resetAnchor(QQuickItem *item, const QString &name); - - - static QList statesForItem(QQuickItem *item); - - static bool isComponentComplete(QQuickItem *item); - - static int borderWidth(QQuickItem *item); - - static void refreshExpressions(QDeclarativeContext *context); - - static void setRootItem(QQuickView *view, QQuickItem *item); - - static bool isValidWidth(QQuickItem *item); - static bool isValidHeight(QQuickItem *item); - - static void updateDirtyNode(QQuickItem *item); - -private: - QHash m_itemTextureHash; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // DESIGNERSUPPORT_H diff --git a/src/declarative/items/checksync.pl b/src/declarative/items/checksync.pl deleted file mode 100755 index 7dffa72e88..0000000000 --- a/src/declarative/items/checksync.pl +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/perl -############################################################################# -## -## 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$ -## 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$ -## -############################################################################# - -use strict; -use warnings; - -die "Usage: $0 " if (@ARGV != 1); - -my @excludes; -open (SYNCEXCLUDES, "<", "syncexcludes"); -while () { - if (/^([a-zA-Z0-9\._]+)/) { - my $exclude = $1; - push (@excludes, $exclude); - } -} - -my $portdir = "."; -my $qmldir = $ARGV[0]; - -opendir (PORTDIR, $portdir) or die "Cannot open port directory"; -opendir (QMLDIR, $qmldir) or die "Cannot open QML directory"; - -my @portfiles = readdir(PORTDIR); -my @qmlfiles = readdir(QMLDIR); - -closedir(PORTDIR); -closedir(QMLDIR); - -foreach my $qmlfile (@qmlfiles) { - if ($qmlfile =~ /^qdeclarative.*\.cpp$/ or $qmlfile =~ /qdeclarative.*\.h$/) { - - if (grep { $_ eq $qmlfile} @excludes) { - next; - } - - my $portfile = $qmlfile; - $portfile =~ s/^qdeclarative/qsg/; - - if (grep { $_ eq $portfile} @portfiles) { - - open (PORTFILE, "<", "$portdir/$portfile") or die("Cannot open $portdir/$portfile for reading"); - - my $firstline = ; - - close (PORTFILE); - - if ($firstline and $firstline =~ /^\/\/ Commit: ([a-z0-9]+)/) { - my $sha1 = $1; - my $commitSha1 = ""; - - my $output = `cd $qmldir; git log $qmlfile | head -n 1`; - if ($output =~ /commit ([a-z0-9]+)/) { - $commitSha1 = $1; - } - - if ($commitSha1 eq $sha1) { - print ("$portfile: OK\n"); - } else { - print ("$portfile: OUT OF DATE\n"); - } - } else { - print ("$portfile: OUT OF DATE\n"); - } - } else { - print ("$portfile: MISSING\n"); - } - } -} diff --git a/src/declarative/items/context2d/context2d.pri b/src/declarative/items/context2d/context2d.pri deleted file mode 100644 index 60b3e4b0c1..0000000000 --- a/src/declarative/items/context2d/context2d.pri +++ /dev/null @@ -1,16 +0,0 @@ -SOURCES += \ - $$PWD/qquickcanvasitem.cpp \ - $$PWD/qquickcontext2d.cpp \ - $$PWD/qquickcontext2dnode.cpp \ - $$PWD/qquickcontext2dtile.cpp \ - $$PWD/qquickcontext2dtexture.cpp \ - $$PWD/qquickcontext2dcommandbuffer.cpp \ - -HEADERS += \ - $$PWD/qquickcanvasitem_p.h \ - $$PWD/qquickcontext2d_p.h \ - $$PWD/qquickcontext2dnode_p.h \ - $$PWD/qquickcontext2dtile_p.h \ - $$PWD/qquickcontext2dtexture_p.h \ - $$PWD/qquickcontext2dcommandbuffer_p.h \ - diff --git a/src/declarative/items/context2d/qquickcanvasitem.cpp b/src/declarative/items/context2d/qquickcanvasitem.cpp deleted file mode 100644 index 81b7a49722..0000000000 --- a/src/declarative/items/context2d/qquickcanvasitem.cpp +++ /dev/null @@ -1,714 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 -#include "qquickcanvasitem_p.h" -#include -#include "qquickcontext2d_p.h" -#include "qquickcontext2dnode_p.h" -#include "qquickcontext2dtexture_p.h" -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickCanvasItemPrivate : public QQuickItemPrivate -{ -public: - QQuickCanvasItemPrivate(); - ~QQuickCanvasItemPrivate(); - QQuickContext2D* context; - QQuickContext2DTexture* texture; - QSizeF canvasSize; - QSize tileSize; - QRectF canvasWindow; - QRectF dirtyRect; - uint renderInThread : 1; - uint hasCanvasSize :1; - uint hasTileSize :1; - uint hasCanvasWindow :1; - uint componentCompleted :1; - QQuickCanvasItem::RenderTarget renderTarget; - QHash images; - QUrl baseUrl; -}; - -QQuickCanvasItemPrivate::QQuickCanvasItemPrivate() - : QQuickItemPrivate() - , context(0) - , texture(0) - , canvasSize(1, 1) - , tileSize(1, 1) - , renderInThread(false) - , hasCanvasSize(false) - , hasTileSize(false) - , hasCanvasWindow(false) - , componentCompleted(false) - , renderTarget(QQuickCanvasItem::FramebufferObject) -{ -} - -QQuickCanvasItemPrivate::~QQuickCanvasItemPrivate() -{ - qDeleteAll(images); -} - -/*! - \qmlclass Canvas QQuickCanvasItem - \inqmlmodule QtQuick 2 - \since QtQuick 2.0 - \brief The Canvas item provides a 2D canvas element which enables drawing via Javascript. - \inherits Item - \ingroup qml-basic-visual-elements - - The Canvas item allows drawing of straight and curved lines, simple and - complex shapes, graphs, and referenced graphic images. It can also add text, colors, - shadows, gradients, and patterns, and do low level pixel operations. The Canvas - output may be saved as an image file or serialized to a url. - - To define a drawing area in the Canvas item set the \c width and \c height properties. - For example, the following code creates a Canvas item which has a drawing area with a height of 100 - pixels and width of 200 pixels: - \qml - import QtQuick 2.0 - Canvas { - id:mycanvas - width:100 - height:200 - } - \endqml - - Currently the Canvas item only supports the two-dimensional rendering context. - - \section1 Threaded Rendering and Render Target - - The Canvas item supports two render targets: \c Canvas.Image and \c Canvas.FramebufferObject. - - The \c Canvas.Image render target is a \a QImage object. This render target supports background - thread rendering, allowing complex or long running painting to be executed without blocking the UI. - - The Canvas.FramebufferObject render target utilizes OpenGL hardware accelaration rather than rendering into - system memory, which in many cases results in faster rendering. - - The default render target is Canvas.Image and the default renderInThread property is - false. - - \section1 Tiled Canvas - The Canvas item supports tiled rendering by setting \l canvasSize, \l tileSize - and \l canvasWindow properties. - - Tiling allows efficient display of a very large virtual via a smaller canvas - window. The actual memory consumption is in relatation to the canvas window size. The painting - code can draw within the virtual canvas without handling coordinate system transformations. - - The tiles overlapping with the canvas window may be cached eliminating the need to redraw, - which can lead to significantly improved performance in some situations. - - \section1 Pixel Operations - All HTML5 2D context pixel operations are supported. In order to ensure improved - pixel reading/writing performance the \a Canvas.Image render target should be chosen. The - \a Canvas.FramebufferObject render target requires the pixel data to be exchanged between - the system memory and the graphic card, which is significantly more expensive. Rendering - may also be synchronized with the V-sync signal (to avoid {en.wikipedia.org/wiki/Screen_tearing}{screen tearing}) - which will futher impact pixel operations with \c Canvas.FrambufferObject render target. - - \section1 Tips for Porting Existing HTML5 Canvas applications - - Although the Canvas item is provides a HTML5 like API, HTML5 canvas applications - need to be modified to run in the Canvas item: - \list - \o Replace all DOM API calls with QML property bindings or Canvas item methods. - \o Replace all HTML event handlers with the \a MouseArea item. - \o Change setInterval/setTimeout function calls with the \a Timer item. - \o Place painting code into the \a QtQuick2::Canvas::onPaint handler and trigger - painting by calling the \c markDirty or \c requestPaint methods. - \o To draw images, load them by calling the Canvas's loadImage method and then request to paint - them in the onImageLoaded handler. - \endlist - - \sa QtQuick2::Context2D -*/ - -QQuickCanvasItem::QQuickCanvasItem(QQuickItem *parent) - : QQuickItem(*(new QQuickCanvasItemPrivate), parent) -{ - setFlag(ItemHasContents); -} - -QQuickCanvasItem::~QQuickCanvasItem() -{ - Q_D(QQuickCanvasItem); - delete d->context; -} - -/*! - \qmlproperty size QtQuick2::Canvas::canvasSize - Holds the logical canvas size that the context paints on. - - By default, the canvas size is the same size as the current canvas item size. - By setting the canvasSize, tileSize and canvasWindow, the Canvas - item can act as a large virtual canvas with many seperately rendered tile rectangles - Only those tiles within the current canvas window are painted by - the Canvas render engine. - - \sa QtQuick2::Canvas::tileSize QtQuick2::Canvas::canvasWindow -*/ -QSizeF QQuickCanvasItem::canvasSize() const -{ - Q_D(const QQuickCanvasItem); - return d->canvasSize; -} - -void QQuickCanvasItem::setCanvasSize(const QSizeF & size) -{ - Q_D(QQuickCanvasItem); - if (d->canvasSize != size) { - d->hasCanvasSize = true; - d->canvasSize = size; - emit canvasSizeChanged(); - polish(); - update(); - } -} - -/*! - \qmlproperty size QtQuick2::Canvas::tileSize - Holds the canvas rendering tile size. - - The Canvas item enters tiled mode by setting canvasSize, tileSize and - the canvasWindow. This can improve rendering performance - by rendering and caching tiles instead of rendering the whole canvas every time. - - Memory will be consumed only by those tiles within the current visible region. - - By default the tileSize is the same as the canvasSize. - - \sa QtQuick2::Canvas::canvaasSize QtQuick2::Canvas::canvasWindow -*/ -QSize QQuickCanvasItem::tileSize() const -{ - Q_D(const QQuickCanvasItem); - return d->tileSize; -} - -void QQuickCanvasItem::setTileSize(const QSize & size) -{ - Q_D(QQuickCanvasItem); - if (d->tileSize != size) { - d->hasTileSize = true; - d->tileSize = size; - - emit tileSizeChanged(); - polish(); - update(); - } -} - -/*! - \qmlproperty rect QtQuick2::Canvas::canvasWindow - Holds the current canvas visible window. - - By default the canvasWindow size is the same as the Canvas item - size with the topleft point as (0, 0). - - If the canvasSize is different to the Canvas item size, the Canvas - item can display different visible areas by changing the canvas windowSize - and/or position. - - \sa QtQuick2::Canvas::canvasSize QtQuick2::Canvas::tileSize -*/ -QRectF QQuickCanvasItem::canvasWindow() const -{ - Q_D(const QQuickCanvasItem); - return d->canvasWindow; -} - -void QQuickCanvasItem::setCanvasWindow(const QRectF& rect) -{ - Q_D(QQuickCanvasItem); - if (d->canvasWindow != rect) { - d->canvasWindow = rect; - - d->hasCanvasWindow = true; - emit canvasWindowChanged(); - polish(); - update(); - } -} - - -QQuickContext2D* QQuickCanvasItem::context() const -{ - Q_D(const QQuickCanvasItem); - return d->context; -} -/*! - \qmlproperty bool QtQuick2::Canvas::renderInThread - Holds the current canvas rendering mode. - - Set renderInThread to true to render complex and long - running painting in a dedicated background - thread, avoiding blocking the main UI. - - \note: Not all renderTargets support background rendering. If background rendering - is not supported by the current renderTarget, the renderInThread - property is ignored. - - The default value is false. - \sa QtQuick2::Canvas::renderTarget -*/ -bool QQuickCanvasItem::renderInThread() const -{ - Q_D(const QQuickCanvasItem); - return d->renderInThread; -} -/*! - \qmlproperty bool QtQuick2::Canvas::renderTarget - Holds the current canvas render target. - - \list - \o Canvas.Image - render to an in memory image buffer, the render - target supports background rendering. - \o Canvas.FramebufferObject - render to an OpenGL frame buffer, - this render target will ignore the - renderInThread property. The actual - rendering happens in the main QML rendering - process, which may be in a seperate render thread - or in the main GUI thread depending upon the platform. - \endlist - - The default render target is \c Canvas.Image. - \sa QtQuick2::Canvas::renderInThread -*/ -QQuickCanvasItem::RenderTarget QQuickCanvasItem::renderTarget() const -{ - Q_D(const QQuickCanvasItem); - return d->renderTarget; -} - -void QQuickCanvasItem::setRenderTarget(RenderTarget target) -{ - Q_D(QQuickCanvasItem); - if (d->renderTarget != target) { - d->renderTarget = target; - - if (d->componentCompleted) - createTexture(); - emit renderTargetChanged(); - } -} - -void QQuickCanvasItem::_doPainting(const QRectF& region) -{ - Q_D(QQuickCanvasItem); - emit paint(QDeclarativeV8Handle::fromHandle(d->context->v8value()) - , QQuickContext2DTexture::tiledRect(region, d->tileSize)); - if (d->texture) - d->texture->wake(); -} - -void QQuickCanvasItem::setRenderInThread(bool renderInThread) -{ - Q_D(QQuickCanvasItem); - if (d->renderInThread != renderInThread) { - d->renderInThread = renderInThread; - - if (d->componentCompleted) - createTexture(); - - if (d->renderInThread) - connect(this, SIGNAL(painted()), SLOT(update())); - else - disconnect(this, SIGNAL(painted()), this, SLOT(update())); - emit renderInThreadChanged(); - polish(); - update(); - } -} - -void QQuickCanvasItem::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - Q_D(QQuickCanvasItem); - QQuickItem::geometryChanged(newGeometry, oldGeometry); - - const qreal w = newGeometry.width(); - const qreal h = newGeometry.height(); - - if (!d->hasCanvasSize) { - d->canvasSize = QSizeF(w, h); - emit canvasSizeChanged(); - } - - if (!d->hasTileSize) { - d->tileSize = d->canvasSize.toSize(); - emit tileSizeChanged(); - } - - if (!d->hasCanvasWindow) { - d->canvasWindow = newGeometry; - emit canvasWindowChanged(); - } - - polish(); - update(); -} - -void QQuickCanvasItem::componentComplete() -{ - Q_D(QQuickCanvasItem); - QQuickItem::componentComplete(); - - if (!d->context) - createContext(); - createTexture(); - - d->baseUrl = qmlEngine(this)->contextForObject(this)->baseUrl(); - requestPaint(); - updatePolish(); //force update the canvas sizes to texture for the first time - update(); - d->componentCompleted = true; -} - -void QQuickCanvasItem::updatePolish() -{ - Q_D(QQuickCanvasItem); - QQuickItem::updatePolish(); - if (d->texture) { - if (!d->renderInThread && d->dirtyRect.isValid()) - _doPainting(d->dirtyRect); - - d->texture->canvasChanged(d->canvasSize.toSize() - , d->tileSize - , d->canvasWindow.toAlignedRect() - , d->dirtyRect.toAlignedRect() - , d->smooth); - d->dirtyRect = QRectF(); - } -} - -QSGNode *QQuickCanvasItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - Q_D(QQuickCanvasItem); - QQuickContext2DNode *node = static_cast(oldNode); - if (!node) - node = new QQuickContext2DNode(this); - - node->setTexture(d->texture); - node->setSize(d->canvasWindow.size()); - node->update(); - return node; -} - -void QQuickCanvasItem::createTexture() -{ - Q_D(QQuickCanvasItem); - - if (!d->texture - || d->texture->threadRendering() != d->renderInThread - || d->texture->renderTarget() != d->renderTarget) { - if (d->texture) { - d->texture->deleteLater(); - d->texture = 0; - } - - if (d->renderTarget == QQuickCanvasItem::Image) { - d->texture = new QQuickContext2DImageTexture(d->renderInThread); - } else if (d->renderTarget == QQuickCanvasItem::FramebufferObject) { - d->texture = new QQuickContext2DFBOTexture(); - } - - if (d->renderInThread && !d->texture->supportThreadRendering()) { - qWarning("Canvas: render target does not support thread rendering, force to non-thread rendering mode."); - d->renderInThread = false; - emit renderInThreadChanged(); - } - - if (d->renderInThread) - connect(d->texture, SIGNAL(textureChanged()), this, SLOT(update())); - - d->texture->setItem(this); - } -} - -void QQuickCanvasItem::createContext() -{ - Q_D(QQuickCanvasItem); - - delete d->context; - - d->context = new QQuickContext2D(this); - - QV8Engine *e = QDeclarativeEnginePrivate::getV8Engine(qmlEngine(this)); - d->context->setV8Engine(e); -} - -/*! - \qmlmethod object QtQuick2::Canvas::getContext(string contextId) - - Currently, the canvas item only supports the 2D context. If the \a contextId - parameter isn't provided or is "2d", then the QtQuick2::Context2D object is - returned, otherwise returns an invalid value. - */ -QDeclarativeV8Handle QQuickCanvasItem::getContext(const QString &contextId) -{ - Q_D(QQuickCanvasItem); - - if (contextId.toLower() != QLatin1String("2d")) - return QDeclarativeV8Handle::fromHandle(v8::Undefined()); - - if (!d->context) - createContext(); - return QDeclarativeV8Handle::fromHandle(d->context->v8value()); -} - -/*! - \qmlmethod void QtQuick2::Canvas::markDirty(rect region) - - Mark the given \a region as dirty, so that when this region is visible - the canvas renderer will redraw it. This will trigger the "onPaint" signal - handler function. - - \sa QtQuick2::Canvas::paint QtQuick2::Canvas::requestPaint - */ -void QQuickCanvasItem::markDirty(const QRectF& region) -{ - Q_D(QQuickCanvasItem); - d->dirtyRect |= region; - if (d->componentCompleted) - polish(); - update(); -} - - -/*! - \qmlmethod bool QtQuick2::Canvas::save(string filename) - - Save the current canvas content into an image file \a filename. - The saved image format is automatically decided by the \a filename's - suffix. - - Note: calling this method will force painting the whole canvas, not just the - current canvas visible window. - - \sa canvasWindow canvasSize toDataURL - */ -bool QQuickCanvasItem::save(const QString &filename) const -{ - Q_D(const QQuickCanvasItem); - QUrl url = d->baseUrl.resolved(QUrl::fromLocalFile(filename)); - return toImage().save(url.toLocalFile()); -} - -QImage QQuickCanvasItem::loadedImage(const QUrl& url) -{ - Q_D(QQuickCanvasItem); - QUrl fullPathUrl = d->baseUrl.resolved(url); - if (!d->images.contains(fullPathUrl)) { - loadImage(url); - } - QDeclarativePixmap* pix = d->images.value(fullPathUrl); - if (pix->isLoading() || pix->isError()) { - return QImage(); - } - return pix->image(); -} - -/*! - \qmlmethod void QtQuick2::Canvas::loadImage(url image) - Loads the given \c image asynchronously. - - When the image is ready, onImageLoaded will be emitted. - The loaded image can be unloaded by the \a QtQuick2::Canvas::unloadImage method. - - Note: Only loaded images can be painted on the Canvas item. - \sa QtQuick2::Canvas::unloadImage QtQuick2::Canvas::imageLoaded QtQuick2::Canvas::isImageLoaded - \sa QtQuick2::Context2D::createImageData QtQuick2::Context2D::drawImage - */ -void QQuickCanvasItem::loadImage(const QUrl& url) -{ - Q_D(QQuickCanvasItem); - QUrl fullPathUrl = d->baseUrl.resolved(url); - if (!d->images.contains(fullPathUrl)) { - QDeclarativePixmap* pix = new QDeclarativePixmap(); - d->images.insert(fullPathUrl, pix); - - pix->load(qmlEngine(this) - , fullPathUrl - , QDeclarativePixmap::Cache | QDeclarativePixmap::Asynchronous); - pix->connectFinished(this, SIGNAL(imageLoaded())); - } -} -/*! - \qmlmethod void QtQuick2::Canvas::unloadImage(url image) - Unloads the \c image. - - Once an image is unloaded it cannot be painted by the canvas context - unless it is loaded again. - - \sa QtQuick2::Canvas::loadImage QtQuick2::Canvas::imageLoaded QtQuick2::Canvas::isImageLoaded - \sa QtQuick2::Context2D::createImageData QtQuick2::Context2D::drawImage - */ -void QQuickCanvasItem::unloadImage(const QUrl& url) -{ - Q_D(QQuickCanvasItem); - QUrl removeThis = d->baseUrl.resolved(url); - if (d->images.contains(removeThis)) { - delete d->images.value(removeThis); - d->images.remove(removeThis); - } -} - -/*! - \qmlmethod void QtQuick2::Canvas::isImageError(url image) - Returns true if the \a image failed to load. - - \sa QtQuick2::Canvas::loadImage - */ -bool QQuickCanvasItem::isImageError(const QUrl& url) const -{ - Q_D(const QQuickCanvasItem); - QUrl fullPathUrl = d->baseUrl.resolved(url); - return d->images.contains(fullPathUrl) - && d->images.value(fullPathUrl)->isError(); -} - -/*! - \qmlmethod void QtQuick2::Canvas::isImageLoading(url image) - Returns true if the \a image is currently loading. - - \sa QtQuick2::Canvas::loadImage - */ -bool QQuickCanvasItem::isImageLoading(const QUrl& url) const -{ - Q_D(const QQuickCanvasItem); - QUrl fullPathUrl = d->baseUrl.resolved(url); - return d->images.contains(fullPathUrl) - && d->images.value(fullPathUrl)->isLoading(); -} -/*! - \qmlmethod void QtQuick2::Canvas::isImageLoaded(url image) - Returns true if the \a image is sucessfully loaded and ready to use. - - \sa QtQuick2::Canvas::loadImage - */ -bool QQuickCanvasItem::isImageLoaded(const QUrl& url) const -{ - Q_D(const QQuickCanvasItem); - QUrl fullPathUrl = d->baseUrl.resolved(url); - return d->images.contains(fullPathUrl) - && d->images.value(fullPathUrl)->isReady(); -} - -QImage QQuickCanvasItem::toImage(const QRectF& region) const -{ - Q_D(const QQuickCanvasItem); - if (d->texture) { - if (region.isEmpty()) - return d->texture->toImage(canvasWindow()); - else - return d->texture->toImage(region); - } - return QImage(); -} - -/*! - \qmlmethod string QtQuick2::Canvas::toDataURL(string mimeType) - - Returns a data URL for the image in the canvas. - - The default \a mimeType is "image/png". - - \sa QtQuick2::Canvas::save - */ -QString QQuickCanvasItem::toDataURL(const QString& mimeType) const -{ - QImage image = toImage(); - - if (!image.isNull()) { - QByteArray ba; - QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - QString mime = mimeType.toLower(); - QString type; - if (mime == QLatin1Literal("image/png")) { - type = QLatin1Literal("PNG"); - } else if (mime == QLatin1Literal("image/bmp")) - type = QLatin1Literal("BMP"); - else if (mime == QLatin1Literal("image/jpeg")) - type = QLatin1Literal("JPEG"); - else if (mime == QLatin1Literal("image/x-portable-pixmap")) - type = QLatin1Literal("PPM"); - else if (mime == QLatin1Literal("image/tiff")) - type = QLatin1Literal("TIFF"); - else if (mime == QLatin1Literal("image/xpm")) - type = QLatin1Literal("XPM"); - else - return QLatin1Literal("data:,"); - - image.save(&buffer, type.toAscii()); - buffer.close(); - QString dataUrl = QLatin1Literal("data:%1;base64,%2"); - return dataUrl.arg(mime).arg(QLatin1String(ba.toBase64().constData())); - } - return QLatin1Literal("data:,"); -} - -/*! - \qmlsignal QtQuick2::Canvas::onPaint(QtQuick2::Context2D context, rect region) - - This handler is called to render the \a region. - - This signal can be triggered by QtQuick2::Canvas::markdirty, QtQuick2::Canvas::requestPaint - or by changing the current canvas window. -*/ - -/*! - \qmlsignal QtQuick2::Canvas::onPainted() - - This handler is called after all context painting commands are executed and - the Canvas has been rendered. -*/ - -QT_END_NAMESPACE diff --git a/src/declarative/items/context2d/qquickcanvasitem_p.h b/src/declarative/items/context2d/qquickcanvasitem_p.h deleted file mode 100644 index 293434209a..0000000000 --- a/src/declarative/items/context2d/qquickcanvasitem_p.h +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKCANVASITEM_P_H -#define QQUICKCANVASITEM_P_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QQuickContext2D; -class QQuickCanvasItemPrivate; -class Q_DECLARATIVE_EXPORT QQuickCanvasItem : public QQuickItem -{ - Q_OBJECT - Q_ENUMS(RenderTarget) - Q_ENUMS(ImageFilterMode) - - Q_PROPERTY(QSizeF canvasSize READ canvasSize WRITE setCanvasSize NOTIFY canvasSizeChanged) - Q_PROPERTY(QSize tileSize READ tileSize WRITE setTileSize NOTIFY tileSizeChanged) - Q_PROPERTY(QRectF canvasWindow READ canvasWindow WRITE setCanvasWindow NOTIFY canvasWindowChanged) - Q_PROPERTY(bool renderInThread READ renderInThread WRITE setRenderInThread NOTIFY renderInThreadChanged) - Q_PROPERTY(RenderTarget renderTarget READ renderTarget WRITE setRenderTarget NOTIFY renderTargetChanged) -public: - enum RenderTarget { - Image, - FramebufferObject - }; - - enum ImageFilterMode { - Threshold, - Mono, - GrayScale, - Brightness, - Invert, - Blur, - Opaque, - Convolute - }; - - QQuickCanvasItem(QQuickItem *parent = 0); - ~QQuickCanvasItem(); - - QSizeF canvasSize() const; - void setCanvasSize(const QSizeF &); - - QSize tileSize() const; - void setTileSize(const QSize &); - - QRectF canvasWindow() const; - void setCanvasWindow(const QRectF& rect); - - bool renderInThread() const; - void setRenderInThread(bool renderInThread); - - RenderTarget renderTarget() const; - void setRenderTarget(RenderTarget target); - - QQuickContext2D* context() const; - QImage toImage(const QRectF& region = QRectF()) const; - - QImage loadedImage(const QUrl& url); - -Q_SIGNALS: - void paint(QDeclarativeV8Handle context, const QRect ®ion); - void painted(); - void canvasSizeChanged(); - void tileSizeChanged(); - void renderInThreadChanged(); - void textureChanged(); - void canvasWindowChanged(); - void renderTargetChanged(); - void imageLoaded(); -public Q_SLOTS: - QString toDataURL(const QString& type = QLatin1String("image/png")) const; - QDeclarativeV8Handle getContext(const QString & = QLatin1String("2d")); - void markDirty(const QRectF& region); - void requestPaint() {markDirty(canvasWindow());} - // Save current canvas to disk - bool save(const QString& filename) const; - void loadImage(const QUrl& url); - void unloadImage(const QUrl& url); - bool isImageLoaded(const QUrl& url) const; - bool isImageLoading(const QUrl& url) const; - bool isImageError(const QUrl& url) const; -private Q_SLOTS: - void _doPainting(const QRectF& region); -protected: - virtual void componentComplete(); - virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - virtual void updatePolish(); -private: - void createContext(); - void createTexture(); - Q_DECLARE_PRIVATE(QQuickCanvasItem) - friend class QQuickContext2D; - friend class QQuickContext2DTexture; -}; -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickCanvasItem) - -QT_END_HEADER - -#endif //QQUICKCANVASITEM_P_H diff --git a/src/declarative/items/context2d/qquickcontext2d.cpp b/src/declarative/items/context2d/qquickcontext2d.cpp deleted file mode 100644 index 1f7a84baa6..0000000000 --- a/src/declarative/items/context2d/qquickcontext2d.cpp +++ /dev/null @@ -1,3540 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qquickcontext2d_p.h" -#include "qquickcontext2dcommandbuffer_p.h" -#include "qquickcanvasitem_p.h" -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE -/*! - \qmlclass Context2D QQuickContext2D - \inqmlmodule QtQuick 2 - \since QtQuick 2.0 - \brief The Context2D API allows you to draw 2d graphic shapes on the \c Canvas item. - - The Context2D object can be created by \c Canvas item's \c getContext() method: - \code - Canvas { - id:canvas - onPaint:{ - var ctx = canvas.getContext('2d'); - //... - } - } - \endcode - The Context2D API implements the same \l {http://www.w3.org/TR/2dcontext}{W3C Canvas 2D Context API standard} - with some enhanced features. - - The Context2D API provides the rendering \bold{context} which defines the methods and attributes needed to draw - on the \c Canvas item. The following assigns the canvas rendering context to a \c{context} - variable: - \code - var context = mycanvas.getContext("2d") - \endcode - - The Context2D API renders the canvas as a coordinate system whose origin (0,0) is - at the top left corner, as shown in the figure below. Coordinates increase along - the \c{x} axis from left to right and along the \c{y} axis from top to bottom of - the canvas. - \image qml-item-canvas-context.gif -*/ - -Q_CORE_EXPORT double qstrtod(const char *s00, char const **se, bool *ok); - -static const double Q_PI = 3.14159265358979323846; // pi - -#define DEGREES(t) ((t) * 180.0 / Q_PI) - -#define CHECK_CONTEXT(r) if (!r || !r->context || !r->context->buffer()) \ - V8THROW_ERROR("Not a Context2D object"); - -#define CHECK_CONTEXT_SETTER(r) if (!r || !r->context || !r->context->buffer()) \ - V8THROW_ERROR_SETTER("Not a Context2D object"); -#define qClamp(val, min, max) qMin(qMax(val, min), max) -#define CHECK_RGBA(c) (c == '-' || c == '.' || (c >=0 && c <= 9)) -QColor qt_color_from_string(v8::Local name) -{ - v8::String::AsciiValue str(name); - - char *p = *str; - int len = str.length(); - //rgb/hsl color string has at least 7 characters - if (!p || len > 255 || len <= 7) - return QColor(p); - else { - bool isRgb(false), isHsl(false), hasAlpha(false); - Q_UNUSED(isHsl) - - while (isspace(*p)) p++; - if (strncmp(p, "rgb", 3) == 0) - isRgb = true; - else if (strncmp(p, "hsl", 3) == 0) - isHsl = true; - else - return QColor(p); - - p+=3; //skip "rgb" or "hsl" - hasAlpha = (*p == 'a') ? true : false; - - ++p; //skip "(" - - if (hasAlpha) ++p; //skip "a" - - int rh, gs, bl, alpha = 255; - - //red - while (isspace(*p)) p++; - rh = strtol(p, &p, 10); - if (*p == '%') { - rh = qRound(rh/100.0 * 255); - ++p; - } - if (*p++ != ',') return QColor(); - - //green - while (isspace(*p)) p++; - gs = strtol(p, &p, 10); - if (*p == '%') { - gs = qRound(gs/100.0 * 255); - ++p; - } - if (*p++ != ',') return QColor(); - - //blue - while (isspace(*p)) p++; - bl = strtol(p, &p, 10); - if (*p == '%') { - bl = qRound(bl/100.0 * 255); - ++p; - } - - if (hasAlpha) { - if (*p++!= ',') return QColor(); - while (isspace(*p)) p++; - bool ok = false; - alpha = qRound(qstrtod(p, const_cast(&p), &ok) * 255); - } - - if (*p != ')') return QColor(); - if (isRgb) - return QColor::fromRgba(qRgba(qClamp(rh, 0, 255), qClamp(gs, 0, 255), qClamp(bl, 0, 255), qClamp(alpha, 0, 255))); - else - return QColor::fromHsl(qClamp(rh, 0, 255), qClamp(gs, 0, 255), qClamp(bl, 0, 255), qClamp(alpha, 0, 255)); - } - return QColor(); -} - -QFont qt_font_from_string(const QString& fontString) { - QFont font; - // ### this is simplified and incomplete - // ### TODO:get code from Qt webkit - QStringList tokens = fontString.split(QLatin1String(" ")); - foreach (const QString &token, tokens) { - if (token == QLatin1String("italic")) - font.setItalic(true); - else if (token == QLatin1String("bold")) - font.setBold(true); - else if (token.endsWith(QLatin1String("px"))) { - QString number = token; - number.remove(QLatin1String("px")); - //font.setPointSizeF(number.trimmed().toFloat()); - font.setPixelSize(number.trimmed().toInt()); - } else - font.setFamily(token); - } - - return font; -} - - - -class QQuickContext2DEngineData : public QV8Engine::Deletable -{ -public: - QQuickContext2DEngineData(QV8Engine *engine); - ~QQuickContext2DEngineData(); - - v8::Persistent constructorContext; - v8::Persistent constructorGradient; - v8::Persistent constructorPattern; - v8::Persistent constructorPixelArray; - v8::Persistent constructorImageData; -}; - -V8_DEFINE_EXTENSION(QQuickContext2DEngineData, engineData) - -class QV8Context2DResource : public QV8ObjectResource -{ - V8_RESOURCE_TYPE(Context2DType) -public: - QV8Context2DResource(QV8Engine *e) : QV8ObjectResource(e) {} - QQuickContext2D* context; -}; - -class QV8Context2DStyleResource : public QV8ObjectResource -{ - V8_RESOURCE_TYPE(Context2DStyleType) -public: - QV8Context2DStyleResource(QV8Engine *e) - : QV8ObjectResource(e) - , patternRepeatX(false) - , patternRepeatY(false) - {} - QBrush brush; - bool patternRepeatX:1; - bool patternRepeatY:1; -}; - -class QV8Context2DPixelArrayResource : public QV8ObjectResource -{ - V8_RESOURCE_TYPE(Context2DPixelArrayType) -public: - QV8Context2DPixelArrayResource(QV8Engine *e) : QV8ObjectResource(e) {} - - QImage image; -}; - -QImage qt_image_convolute_filter(const QImage& src, const QVector& weights, int radius = 0) -{ - int sides = radius ? radius : qRound(qSqrt(weights.size())); - int half = qFloor(sides/2); - - QImage dst = QImage(src.size(), src.format()); - int w = src.width(); - int h = src.height(); - for (int y = 0; y < dst.height(); ++y) { - QRgb *dr = (QRgb*)dst.scanLine(y); - for (int x = 0; x < dst.width(); ++x) { - unsigned char* dRgb = ((unsigned char*)&dr[x]); - unsigned char red=0, green=0, blue=0, alpha=0; - int sy = y; - int sx = x; - - for (int cy=0; cy= 0 && scy < w && scx >= 0 && scx < h) { - const QRgb *sr = (const QRgb*)(src.constScanLine(scy)); - const unsigned char* sRgb = ((const unsigned char*)&sr[scx]); - qreal wt = radius ? weights[0] : weights[cy*sides+cx]; - red += sRgb[0] * wt; - green += sRgb[1] * wt; - blue += sRgb[2] * wt; - alpha += sRgb[3] * wt; - } - } - } - dRgb[0] = red; - dRgb[1] = green; - dRgb[2] = blue; - dRgb[3] = alpha; - } - } - return dst; -} - -void qt_image_boxblur(QImage& image, int radius, bool quality) -{ - int passes = quality? 3: 1; - for (int i=0; i < passes; i++) { - image = qt_image_convolute_filter(image, QVector() << 1.0/(radius * radius * 1.0), radius); - } -} - -static QPainter::CompositionMode qt_composite_mode_from_string(const QString &compositeOperator) -{ - if (compositeOperator == QLatin1String("source-over")) { - return QPainter::CompositionMode_SourceOver; - } else if (compositeOperator == QLatin1String("source-out")) { - return QPainter::CompositionMode_SourceOut; - } else if (compositeOperator == QLatin1String("source-in")) { - return QPainter::CompositionMode_SourceIn; - } else if (compositeOperator == QLatin1String("source-atop")) { - return QPainter::CompositionMode_SourceAtop; - } else if (compositeOperator == QLatin1String("destination-atop")) { - return QPainter::CompositionMode_DestinationAtop; - } else if (compositeOperator == QLatin1String("destination-in")) { - return QPainter::CompositionMode_DestinationIn; - } else if (compositeOperator == QLatin1String("destination-out")) { - return QPainter::CompositionMode_DestinationOut; - } else if (compositeOperator == QLatin1String("destination-over")) { - return QPainter::CompositionMode_DestinationOver; - } else if (compositeOperator == QLatin1String("lighter")) { - return QPainter::CompositionMode_Lighten; - } else if (compositeOperator == QLatin1String("copy")) { - return QPainter::CompositionMode_Source; - } else if (compositeOperator == QLatin1String("xor")) { - return QPainter::CompositionMode_Xor; - } else if (compositeOperator == QLatin1String("qt-clear")) { - return QPainter::CompositionMode_Clear; - } else if (compositeOperator == QLatin1String("qt-destination")) { - return QPainter::CompositionMode_Destination; - } else if (compositeOperator == QLatin1String("qt-multiply")) { - return QPainter::CompositionMode_Multiply; - } else if (compositeOperator == QLatin1String("qt-screen")) { - return QPainter::CompositionMode_Screen; - } else if (compositeOperator == QLatin1String("qt-overlay")) { - return QPainter::CompositionMode_Overlay; - } else if (compositeOperator == QLatin1String("qt-darken")) { - return QPainter::CompositionMode_Darken; - } else if (compositeOperator == QLatin1String("qt-lighten")) { - return QPainter::CompositionMode_Lighten; - } else if (compositeOperator == QLatin1String("qt-color-dodge")) { - return QPainter::CompositionMode_ColorDodge; - } else if (compositeOperator == QLatin1String("qt-color-burn")) { - return QPainter::CompositionMode_ColorBurn; - } else if (compositeOperator == QLatin1String("qt-hard-light")) { - return QPainter::CompositionMode_HardLight; - } else if (compositeOperator == QLatin1String("qt-soft-light")) { - return QPainter::CompositionMode_SoftLight; - } else if (compositeOperator == QLatin1String("qt-difference")) { - return QPainter::CompositionMode_Difference; - } else if (compositeOperator == QLatin1String("qt-exclusion")) { - return QPainter::CompositionMode_Exclusion; - } - return QPainter::CompositionMode_SourceOver; -} - -static QString qt_composite_mode_to_string(QPainter::CompositionMode op) -{ - switch (op) { - case QPainter::CompositionMode_SourceOver: - return QLatin1String("source-over"); - case QPainter::CompositionMode_DestinationOver: - return QLatin1String("destination-over"); - case QPainter::CompositionMode_Clear: - return QLatin1String("qt-clear"); - case QPainter::CompositionMode_Source: - return QLatin1String("copy"); - case QPainter::CompositionMode_Destination: - return QLatin1String("qt-destination"); - case QPainter::CompositionMode_SourceIn: - return QLatin1String("source-in"); - case QPainter::CompositionMode_DestinationIn: - return QLatin1String("destination-in"); - case QPainter::CompositionMode_SourceOut: - return QLatin1String("source-out"); - case QPainter::CompositionMode_DestinationOut: - return QLatin1String("destination-out"); - case QPainter::CompositionMode_SourceAtop: - return QLatin1String("source-atop"); - case QPainter::CompositionMode_DestinationAtop: - return QLatin1String("destination-atop"); - case QPainter::CompositionMode_Xor: - return QLatin1String("xor"); - case QPainter::CompositionMode_Plus: - return QLatin1String("plus"); - case QPainter::CompositionMode_Multiply: - return QLatin1String("qt-multiply"); - case QPainter::CompositionMode_Screen: - return QLatin1String("qt-screen"); - case QPainter::CompositionMode_Overlay: - return QLatin1String("qt-overlay"); - case QPainter::CompositionMode_Darken: - return QLatin1String("qt-darken"); - case QPainter::CompositionMode_Lighten: - return QLatin1String("lighter"); - case QPainter::CompositionMode_ColorDodge: - return QLatin1String("qt-color-dodge"); - case QPainter::CompositionMode_ColorBurn: - return QLatin1String("qt-color-burn"); - case QPainter::CompositionMode_HardLight: - return QLatin1String("qt-hard-light"); - case QPainter::CompositionMode_SoftLight: - return QLatin1String("qt-soft-light"); - case QPainter::CompositionMode_Difference: - return QLatin1String("qt-difference"); - case QPainter::CompositionMode_Exclusion: - return QLatin1String("qt-exclusion"); - default: - break; - } - return QString(); -} - - -static v8::Local qt_create_image_data(qreal w, qreal h, QV8Engine* engine, const QImage& image) -{ - QQuickContext2DEngineData *ed = engineData(engine); - v8::Local imageData = ed->constructorImageData->NewInstance(); - QV8Context2DPixelArrayResource *r = new QV8Context2DPixelArrayResource(engine); - if (image.isNull()) { - r->image = QImage(w, h, QImage::Format_ARGB32); - r->image.fill(0x00000000); - } else { - Q_ASSERT(image.width() == w && image.height() == h); - r->image = image.format() == QImage::Format_ARGB32 ? image : image.convertToFormat(QImage::Format_ARGB32); - } - v8::Local pixelData = ed->constructorPixelArray->NewInstance(); - pixelData->SetExternalResource(r); - - imageData->SetInternalField(0, pixelData); - return imageData; -} - -//static script functions - -/*! - \qmlproperty QtQuick2::Canvas QtQuick2::Context2D::canvas - Holds the canvas item that the context paints on. - - This property is read only. -*/ -static v8::Handle ctx2d_canvas(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - return engine->newQObject(r->context->canvas()); -} - -/*! - \qmlmethod object QtQuick2::Context2D::restore() - Pops the top state on the stack, restoring the context to that state. - - \sa QtQuick2::Context2D::save() -*/ -static v8::Handle ctx2d_restore(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - r->context->popState(); - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::reset() - Resets the context state and properties to the default values. -*/ -static v8::Handle ctx2d_reset(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - r->context->reset(); - r->context->m_path = QPainterPath(); - r->context->m_path.setFillRule(Qt::WindingFill); - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::save() - Pushes the current state onto the state stack. - - Before changing any state attributes, you should save the current state - for future reference. The context maintains a stack of drawing states. - Each state consists of the current transformation matrix, clipping region, - and values of the following attributes: - \list - \o\a QtQuick2::Context2D::strokeStyle - \o\a QtQuick2::Context2D::fillStyle - \o\a QtQuick2::Context2D::fillRule - \o\a QtQuick2::Context2D::globalAlpha - \o\a QtQuick2::Context2D::lineWidth - \o\a QtQuick2::Context2D::lineCap - \o\a QtQuick2::Context2D::lineJoin - \o\a QtQuick2::Context2D::miterLimit - \o\a QtQuick2::Context2D::shadowOffsetX - \o\a QtQuick2::Context2D::shadowOffsetY - \o\a QtQuick2::Context2D::shadowBlur - \o\a QtQuick2::Context2D::shadowColor - \o\a QtQuick2::Context2D::globalCompositeOperation - \o\a QtQuick2::Context2D::font - \o\a QtQuick2::Context2D::textAlign - \o\a QtQuick2::Context2D::textBaseline - \endlist - - The current path is NOT part of the drawing state. The path can be reset by - invoking the \a QtQuick2::Context2D::beginPath() method. -*/ -static v8::Handle ctx2d_save(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - r->context->pushState(); - - return args.This(); -} - -// transformations -/*! - \qmlmethod object QtQuick2::Context2D::rotate(real angle) - Rotate the canvas around the current origin by \c angle in radians and clockwise direction. - \code - ctx.rotate(Math.PI/2); - \endcode - \image qml-item-canvas-rotate.png - - The rotation transformation matrix is as follows: - - \image qml-item-canvas-math-rotate.png - - where the \c angle of rotation is in radians. - -*/ -static v8::Handle ctx2d_rotate(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - if (args.Length() == 1) { - qreal angle = args[0]->NumberValue(); - if (!qIsFinite(angle)) - return args.This(); - - r->context->state.matrix.rotate(DEGREES(angle)); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::scale(real x, real y) - Increases or decreases the size of each unit in the canvas grid by multiplying the scale factors - to the current tranform matrix. - Where \c x is the scale factor in the horizontal direction and \c y is the scale factor in the - vertical direction. - The following code doubles the horizontal size of an object drawn on the canvas and half its - vertical size: - \code - ctx.scale(2.0, 0.5); - \endcode - \image qml-item-canvas-scale.png - -*/ -static v8::Handle ctx2d_scale(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 2) { - qreal x, y; - x = args[0]->NumberValue(); - y = args[1]->NumberValue(); - if (!qIsFinite(x) || !qIsFinite(y)) - return args.This(); - - r->context->state.matrix.scale(x, y); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::setTransform(real a, real b, real c, real d, real e, real f) - Changes the transformation matrix to the matrix given by the arguments as described below. - - Modifying the transformation matrix directly enables you to perform scaling, - rotating, and translating transformations in a single step. - - Each point on the canvas is multiplied by the matrix before anything is - drawn. The \l{HTML5 Canvas API} defines the transformation matrix as: - - \image qml-item-canvas-math.png - where: - \list - \o \c{a} is the scale factor in the horizontal (x) direction - \image qml-item-canvas-scalex.png - \o \c{c} is the skew factor in the x direction - \image qml-item-canvas-canvas-skewx.png - \o \c{e} is the translation in the x direction - \image qml-item-canvas-canvas-translate.png - \o \c{b} is the skew factor in the y (vertical) direction - \image qml-item-canvas-canvas-skewy.png - \o \c{d} is the scale factor in the y direction - \image qml-item-canvas-canvas-scaley.png - \o \c{f} is the translation in the y direction - \image qml-item-canvas-canvas-translatey.png - \o the last row remains constant - \endlist - The scale factors and skew factors are multiples; \c{e} and \c{f} are - coordinate space units, just like the units in the \a QtQuick2::Context2D::translate(x,y) - method. - - \sa QtQuick2::Context2D::transform() -*/ -static v8::Handle ctx2d_setTransform(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 6) { - qreal a = args[0]->NumberValue(); - qreal b = args[1]->NumberValue(); - qreal c = args[2]->NumberValue(); - qreal d = args[3]->NumberValue(); - qreal e = args[4]->NumberValue(); - qreal f = args[5]->NumberValue(); - - if (!qIsFinite(a) - || !qIsFinite(b) - || !qIsFinite(c) - || !qIsFinite(d) - || !qIsFinite(e) - || !qIsFinite(f)) - return args.This(); - - r->context->state.matrix = QTransform(a, b, c, d, e, f); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::transform(real a, real b, real c, real d, real e, real f) - This method is very similar to \a QtQuick2::Context2D::setTransform(), but instead of replacing the old - tranform matrix, this method applies the given tranform matrix to the current matrix by mulitplying to it. - - The \a setTransform(a, b, c, d, e, f) method actually resets the current transform to the identity matrix, - and then invokes the transform(a, b, c, d, e, f) method with the same arguments. - - \sa QtQuick2::Context2D::setTransform() -*/ -static v8::Handle ctx2d_transform(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 6) { - qreal a = args[0]->NumberValue(); - qreal b = args[1]->NumberValue(); - qreal c = args[2]->NumberValue(); - qreal d = args[3]->NumberValue(); - qreal e = args[4]->NumberValue(); - qreal f = args[5]->NumberValue(); - - if (!qIsFinite(a) - || !qIsFinite(b) - || !qIsFinite(c) - || !qIsFinite(d) - || !qIsFinite(e) - || !qIsFinite(f)) - return args.This(); - - r->context->state.matrix *= QTransform(a, b, c, d, e, f); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::translate(real x, real y) - Translates the origin of the canvas to point (\c x, \c y). - - \c x is the horizontal distance that the origin is translated, in coordinate space units, - \c y is the vertical distance that the origin is translated, in coordinate space units. - Translating the origin enables you to draw patterns of different objects on the canvas - without having to measure the coordinates manually for each shape. -*/ -static v8::Handle ctx2d_translate(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 2) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y)) - return args.This(); - - r->context->state.matrix.translate(x, y); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - - return args.This(); -} - - -/*! - \qmlmethod object QtQuick2::Context2D::resetTransform() - Reset the transformation matrix to default value. - - \sa QtQuick2::Context2D::transform(), QtQuick2::Context2D::setTransform(), QtQuick2::Context2D::reset() -*/ -static v8::Handle ctx2d_resetTransform(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - r->context->state.matrix = QTransform(); - r->context->buffer()->updateMatrix(r->context->state.matrix); - - return args.This(); -} - - -/*! - \qmlmethod object QtQuick2::Context2D::shear(real sh, real sv ) - Shear the transformation matrix with \a sh in horizontal direction and \a sv in vertical direction. -*/ -static v8::Handle ctx2d_shear(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - if (args.Length() == 2) { - qreal sh = args[0]->NumberValue(); - qreal sv = args[1]->NumberValue(); - - if (!qIsFinite(sh) || !qIsFinite(sv)) - return args.This(); - - r->context->state.matrix.shear(sh, sv); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - return args.This(); -} -// compositing - -/*! - \qmlproperty real QtQuick2::Context2D::globalAlpha - Holds the the current alpha value applied to rendering operations. - The value must be in the range from 0.0 (fully transparent) to 1.0 (fully opque). - The default value is 1.0. -*/ -static v8::Handle ctx2d_globalAlpha(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - return v8::Number::New(r->context->state.globalAlpha); -} - -static void ctx2d_globalAlpha_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - qreal globalAlpha = value->NumberValue(); - - if (!qIsFinite(globalAlpha)) - return; - - if (globalAlpha >= 0.0 && globalAlpha <= 1.0 && r->context->state.globalAlpha != globalAlpha) { - r->context->state.globalAlpha = globalAlpha; - r->context->buffer()->setGlobalAlpha(r->context->state.globalAlpha); - } -} - -/*! - \qmlproperty string QtQuick2::Context2D::globalCompositeOperation - Holds the the current the current composition operation, from the list below: - \list - \o source-atop - A atop B. Display the source image wherever both images are opaque. - Display the destination image wherever the destination image is opaque but the source image is transparent. - Display transparency elsewhere. - \o source-in - A in B. Display the source image wherever both the source image and destination image are opaque. - Display transparency elsewhere. - \o source-out - A out B. Display the source image wherever the source image is opaque and the destination image is transparent. - Display transparency elsewhere. - \o source-over - (default) A over B. Display the source image wherever the source image is opaque. - Display the destination image elsewhere. - \o destination-atop - B atop A. Same as source-atop but using the destination image instead of the source image and vice versa. - \o destination-in - B in A. Same as source-in but using the destination image instead of the source image and vice versa. - \o destination-out - B out A. Same as source-out but using the destination image instead of the source image and vice versa. - \o destination-over - B over A. Same as source-over but using the destination image instead of the source image and vice versa. - \o lighter - A plus B. Display the sum of the source image and destination image, with color values approaching 255 (100%) as a limit. - \o copy - A (B is ignored). Display the source image instead of the destination image. - \o xor - A xor B. Exclusive OR of the source image and destination image. - \endlist - - Additionally, this property also accepts the compositon modes listed in \a {QPainter::CompositionMode}. According to the W3C standard, these - extension composition modes are provided as "vendorName-operationName" syntax, for example: \c {QPainter::CompositionMode_Exclusion} is porvided as - "qt-exclusion". -*/ -static v8::Handle ctx2d_globalCompositeOperation(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - return engine->toString(qt_composite_mode_to_string(r->context->state.globalCompositeOperation)); -} - -static void ctx2d_globalCompositeOperation_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - - QString mode = engine->toString(value); - QPainter::CompositionMode cm = qt_composite_mode_from_string(mode); - if (cm == QPainter::CompositionMode_SourceOver && mode != QStringLiteral("source-over")) - return; - - if (cm != r->context->state.globalCompositeOperation) { - r->context->state.globalCompositeOperation = cm; - r->context->buffer()->setGlobalCompositeOperation(cm); - } -} - -// colors and styles -/*! - \qmlproperty variant QtQuick2::Context2D::fillStyle - Holds the current style used for filling shapes. - The style can be either a string containing a CSS color, a CanvasGradient or CanvasPattern object. Invalid values are ignored. - This property accepts several color syntaxes: - \list - \o 'rgb(red, green, blue)' - for example: 'rgb(255, 100, 55)' or 'rgb(100%, 70%, 30%)' - \o 'rgba(red, green, blue, alpha)' - for example: 'rgb(255, 100, 55, 1.0)' or 'rgb(100%, 70%, 30%, 0.5)' - \o 'hsl(hue, saturation, lightness)' - \o 'hsla(hue, saturation, lightness, alpha)' - \o '#RRGGBB' - for example: '#00FFCC' - \o Qt.rgba(red, green, blue, alpha) - for example: Qt.rgba(0.3, 0.7, 1, 1.0) - \endlist - If the \a fillStyle or \a strokeStyle is assigned many times in a loop, the last Qt.rgba() syntax should be chosen, as it has the - best performance, because it's already a valid QColor value, does not need to be parsed everytime. - - The default value is '#000000'. - \sa QtQuick2::Context2D::createLinearGradient - \sa QtQuick2::Context2D::createRadialGradient - \sa QtQuick2::Context2D::createPattern - \sa QtQuick2::Context2D::strokeStyle - */ -static v8::Handle ctx2d_fillStyle(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - QColor color = r->context->state.fillStyle.color(); - if (color.isValid()) { - if (color.alpha() == 255) - return engine->toString(color.name()); - QString alphaString = QString::number(color.alphaF(), 'f'); - while (alphaString.endsWith(QLatin1Char('0'))) - alphaString.chop(1); - if (alphaString.endsWith(QLatin1Char('.'))) - alphaString += QLatin1Char('0'); - return engine->toString(QString::fromLatin1("rgba(%1, %2, %3, %4)").arg(color.red()).arg(color.green()).arg(color.blue()).arg(alphaString)); - } - return r->context->m_fillStyle; -} - -static void ctx2d_fillStyle_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - if (value->IsObject()) { - QColor color = engine->toVariant(value, qMetaTypeId()).value(); - if (color.isValid()) { - r->context->state.fillStyle = color; - r->context->buffer()->setFillStyle(color); - r->context->m_fillStyle = value; - } else { - QV8Context2DStyleResource *style = v8_resource_cast(value->ToObject()); - if (style && style->brush != r->context->state.fillStyle) { - r->context->state.fillStyle = style->brush; - r->context->buffer()->setFillStyle(style->brush, style->patternRepeatX, style->patternRepeatY); - r->context->m_fillStyle = value; - r->context->state.fillPatternRepeatX = style->patternRepeatX; - r->context->state.fillPatternRepeatY = style->patternRepeatY; - } - } - } else if (value->IsString()) { - QColor color = qt_color_from_string(value); - if (color.isValid() && r->context->state.fillStyle != QBrush(color)) { - r->context->state.fillStyle = QBrush(color); - r->context->buffer()->setFillStyle(r->context->state.fillStyle); - r->context->m_fillStyle = value; - } - } -} -/*! - \qmlproperty enumeration QtQuick2::Context2D::fillRule - Holds the current fill rule used for filling shapes. The following fill rules supported: - \list - \o Qt.OddEvenFill - \o Qt.WindingFill - \endlist - Note: Unlike the \a QPainterPath, the Canvas API uses the winding fill as the default fill rule. - The fillRule property is part of the context rendering state. - - \sa QtQuick2::Context2D::fillStyle - */ -static v8::Handle ctx2d_fillRule(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - return engine->fromVariant(r->context->state.fillRule); -} - -static void ctx2d_fillRule_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - if ((value->IsString() && engine->toString(value) == QStringLiteral("WindingFill")) - ||(value->IsNumber() && value->NumberValue() == Qt::WindingFill)) { - r->context->state.fillRule = Qt::WindingFill; - } else if ((value->IsString() && engine->toString(value) == QStringLiteral("OddEvenFill")) - ||(value->IsNumber() && value->NumberValue() == Qt::OddEvenFill)) { - r->context->state.fillRule = Qt::OddEvenFill; - } else { - //error - } - r->context->m_path.setFillRule(r->context->state.fillRule); -} -/*! - \qmlproperty variant QtQuick2::Context2D::strokeStyle - Holds the current color or style to use for the lines around shapes, - The style can be either a string containing a CSS color, a CanvasGradient or CanvasPattern object. - Invalid values are ignored. - - The default value is '#000000'. - - \sa QtQuick2::Context2D::createLinearGradient - \sa QtQuick2::Context2D::createRadialGradient - \sa QtQuick2::Context2D::createPattern - \sa QtQuick2::Context2D::fillStyle - */ -v8::Handle ctx2d_strokeStyle(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - QColor color = r->context->state.strokeStyle.color(); - if (color.isValid()) { - if (color.alpha() == 255) - return engine->toString(color.name()); - QString alphaString = QString::number(color.alphaF(), 'f'); - while (alphaString.endsWith(QLatin1Char('0'))) - alphaString.chop(1); - if (alphaString.endsWith(QLatin1Char('.'))) - alphaString += QLatin1Char('0'); - return engine->toString(QString::fromLatin1("rgba(%1, %2, %3, %4)").arg(color.red()).arg(color.green()).arg(color.blue()).arg(alphaString)); - } - return r->context->m_strokeStyle; -} - -static void ctx2d_strokeStyle_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - if (value->IsObject()) { - QColor color = engine->toVariant(value, qMetaTypeId()).value(); - if (color.isValid()) { - r->context->state.fillStyle = color; - r->context->buffer()->setStrokeStyle(color); - r->context->m_strokeStyle = value; - } else { - QV8Context2DStyleResource *style = v8_resource_cast(value->ToObject()); - if (style && style->brush != r->context->state.strokeStyle) { - r->context->state.strokeStyle = style->brush; - r->context->buffer()->setStrokeStyle(style->brush, style->patternRepeatX, style->patternRepeatY); - r->context->m_strokeStyle = value; - r->context->state.strokePatternRepeatX = style->patternRepeatX; - r->context->state.strokePatternRepeatY = style->patternRepeatY; - - } - } - } else if (value->IsString()) { - QColor color = qt_color_from_string(value); - if (color.isValid() && r->context->state.strokeStyle != QBrush(color)) { - r->context->state.strokeStyle = QBrush(color); - r->context->buffer()->setStrokeStyle(r->context->state.strokeStyle); - r->context->m_strokeStyle = value; - } - } -} - -/*! - \qmlmethod object QtQuick2::Context2D::createLinearGradient(real x0, real y0, real x1, real y1) - Returns a CanvasGradient object that represents a linear gradient that transitions the color along a line between - the start point (\a x0, \a y0) and the end point (\a x1, \a y1). - - A gradient is a smooth transition between colors. There are two types of gradients: linear and radial. - Gradients must have two or more color stops, representing color shifts positioned from 0 to 1 between - to the gradient's starting and end points or circles. - - \sa QtQuick2::Context2D::CanvasGradient::addColorStop - \sa QtQuick2::Context2D::createRadialGradient - \sa QtQuick2::Context2D::ctx2d_createConicalGradient - \sa QtQuick2::Context2D::createPattern - \sa QtQuick2::Context2D::fillStyle - \sa QtQuick2::Context2D::strokeStyle - */ - -static v8::Handle ctx2d_createLinearGradient(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - QV8Engine *engine = V8ENGINE(); - - if (args.Length() == 4) { - QQuickContext2DEngineData *ed = engineData(engine); - v8::Local gradient = ed->constructorGradient->NewInstance(); - QV8Context2DStyleResource *r = new QV8Context2DStyleResource(engine); - qreal x0 = args[0]->NumberValue(); - qreal y0 = args[1]->NumberValue(); - qreal x1 = args[2]->NumberValue(); - qreal y1 = args[3]->NumberValue(); - - if (!qIsFinite(x0) - || !qIsFinite(y0) - || !qIsFinite(x1) - || !qIsFinite(y1)) - V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createLinearGradient(): Incorrect arguments") - - r->brush = QLinearGradient(x0, y0, x1, y1); - gradient->SetExternalResource(r); - return gradient; - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::createRadialGradient(real x0, real y0, real r0, real x1, real y1, real r1) - Returns a CanvasGradient object that represents a radial gradient that paints along the cone given by the start circle with - origin (x0, y0) and radius r0, and the end circle with origin (x1, y1) and radius r1. - - \sa QtQuick2::Context2D::CanvasGradient::addColorStop - \sa QtQuick2::Context2D::createLinearGradient - \sa QtQuick2::Context2D::ctx2d_createConicalGradient - \sa QtQuick2::Context2D::createPattern - \sa QtQuick2::Context2D::fillStyle - \sa QtQuick2::Context2D::strokeStyle - */ - -static v8::Handle ctx2d_createRadialGradient(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - QV8Engine *engine = V8ENGINE(); - - if (args.Length() == 6) { - QQuickContext2DEngineData *ed = engineData(engine); - v8::Local gradient = ed->constructorGradient->NewInstance(); - QV8Context2DStyleResource *r = new QV8Context2DStyleResource(engine); - - qreal x0 = args[0]->NumberValue(); - qreal y0 = args[1]->NumberValue(); - qreal r0 = args[2]->NumberValue(); - qreal x1 = args[3]->NumberValue(); - qreal y1 = args[4]->NumberValue(); - qreal r1 = args[5]->NumberValue(); - - if (!qIsFinite(x0) - || !qIsFinite(y0) - || !qIsFinite(x1) - || !qIsFinite(r0) - || !qIsFinite(r1) - || !qIsFinite(y1)) - V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createRadialGradient(): Incorrect arguments") - - if (r0 < 0 || r1 < 0) - V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createRadialGradient(): Incorrect arguments") - - - r->brush = QRadialGradient(QPointF(x1, y1), r0+r1, QPointF(x0, y0)); - gradient->SetExternalResource(r); - return gradient; - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::createConicalGradient(real x, real y, real angle) - Returns a CanvasGradient object that represents a conical gradient that interpolate colors counter-clockwise around a center point (\c x, \c y) - with start angle \c angle in units of radians. - - \sa QtQuick2::Context2D::CanvasGradient::addColorStop - \sa QtQuick2::Context2D::createLinearGradient - \sa QtQuick2::Context2D::ctx2d_createRadialGradient - \sa QtQuick2::Context2D::createPattern - \sa QtQuick2::Context2D::fillStyle - \sa QtQuick2::Context2D::strokeStyle - */ - -static v8::Handle ctx2d_createConicalGradient(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - QV8Engine *engine = V8ENGINE(); - - if (args.Length() == 6) { - QQuickContext2DEngineData *ed = engineData(engine); - v8::Local gradient = ed->constructorGradient->NewInstance(); - QV8Context2DStyleResource *r = new QV8Context2DStyleResource(engine); - - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - qreal angle = DEGREES(args[2]->NumberValue()); - if (!qIsFinite(x) || !qIsFinite(y)) - V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createConicalGradient(): Incorrect arguments"); - - if (!qIsFinite(angle)) - V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createConicalGradient(): Incorrect arguments"); - - r->brush = QConicalGradient(x, y, angle); - gradient->SetExternalResource(r); - return gradient; - } - - return args.This(); -} -/*! - \qmlmethod variant createPattern(Color color, enumeration patternMode) - This is a overload function. - Returns a CanvasPattern object that uses the given \c color and \c patternMode. - The valid pattern modes are: - \list - \o Qt.SolidPattern - \o Qt.Dense1Pattern - \o Qt.Dense2Pattern - \o Qt.Dense3Pattern - \o Qt.Dense4Pattern - \o Qt.Dense5Pattern - \o Qt.Dense6Pattern - \o Qt.Dense7Pattern - \o Qt.HorPattern - \o Qt.VerPattern - \o Qt.CrossPattern - \o Qt.BDiagPattern - \o Qt.FDiagPattern - \o Qt.DiagCrossPattern -\endlist - \sa Qt::BrushStyle - */ -/*! - \qmlmethod variant createPattern(Image image, string repetition) - Returns a CanvasPattern object that uses the given image and repeats in the direction(s) given by the repetition argument. - - The \a image parameter must be a valid Image item, a valid \a QtQuick2::CanvasImageData object or loaded image url, if there is no image data, throws an INVALID_STATE_ERR exception. - - The allowed values for \a repetition are: - - \list - \o "repeat" - both directions - \o "repeat-x - horizontal only - \o "repeat-y" - vertical only - \o "no-repeat" - neither - \endlist - - If the repetition argument is empty or null, the value "repeat" is used. - - \sa QtQuick2::Context2D::strokeStyle - \sa QtQuick2::Context2D::fillStyle - */ -static v8::Handle ctx2d_createPattern(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - QV8Engine *engine = V8ENGINE(); - - if (args.Length() == 2) { - QQuickContext2DEngineData *ed = engineData(engine); - QV8Context2DStyleResource *styleResouce = new QV8Context2DStyleResource(engine); - - QColor color = engine->toVariant(args[0], qMetaTypeId()).value(); - if (color.isValid()) { - int patternMode = args[1]->IntegerValue(); - Qt::BrushStyle style = Qt::SolidPattern; - if (patternMode >= 0 && patternMode < Qt::LinearGradientPattern) { - style = static_cast(patternMode); - } - styleResouce->brush = QBrush(color, style); - } else { - QImage patternTexture; - - if (args[0]->IsObject()) { - QV8Context2DPixelArrayResource *pixelData = v8_resource_cast(args[0]->ToObject()->Get(v8::String::New("data"))->ToObject()); - if (pixelData) { - patternTexture = pixelData->image; - } - } else { - patternTexture = r->context->createImage(QUrl(engine->toString(args[0]->ToString()))); - } - - if (!patternTexture.isNull()) { - styleResouce->brush.setTextureImage(patternTexture); - - QString repetition = engine->toString(args[1]); - if (repetition == QStringLiteral("repeat") || repetition.isEmpty()) { - styleResouce->patternRepeatX = true; - styleResouce->patternRepeatY = true; - } else if (repetition == QStringLiteral("repeat-x")) { - styleResouce->patternRepeatX = true; - } else if (repetition == QStringLiteral("repeat-y")) { - styleResouce->patternRepeatY = true; - } else if (repetition == QStringLiteral("no-repeat")) { - styleResouce->patternRepeatY = false; - styleResouce->patternRepeatY = false; - } else { - //TODO: exception: SYNTAX_ERR - } - - } - } - - v8::Local pattern = ed->constructorPattern->NewInstance(); - pattern->SetExternalResource(styleResouce); - return pattern; - - } - return v8::Undefined(); -} - -// line styles -/*! - \qmlproperty string QtQuick2::Context2D::lineCap - Holds the the current line cap style. - The possible line cap styles are: - \list - \o butt - the end of each line has a flat edge perpendicular to the direction of the line, this is the default line cap value. - \o round - a semi-circle with the diameter equal to the width of the line must then be added on to the end of the line. - \o square - a rectangle with the length of the line width and the width of half the line width, placed flat against the edge perpendicular to the direction of the line. - \endlist - Other values are ignored. -*/ -v8::Handle ctx2d_lineCap(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - switch (r->context->state.lineCap) { - case Qt::RoundCap: - return engine->toString(QLatin1String("round")); - case Qt::FlatCap: - return engine->toString(QLatin1String("butt")); - case Qt::SquareCap: - return engine->toString(QLatin1String("square")); - default: - break; - } - return engine->toString(QLatin1String("butt"));; -} - -static void ctx2d_lineCap_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - QString lineCap = engine->toString(value); - Qt::PenCapStyle cap; - if (lineCap == QLatin1String("round")) - cap = Qt::RoundCap; - else if (lineCap == QLatin1String("butt")) - cap = Qt::FlatCap; - else if (lineCap == QLatin1String("square")) - cap = Qt::SquareCap; - else - return; - - if (cap != r->context->state.lineCap) { - r->context->state.lineCap = cap; - r->context->buffer()->setLineCap(cap); - } -} - -/*! - \qmlproperty string QtQuick2::Context2D::lineJoin - Holds the the current line join style. A join exists at any point in a subpath - shared by two consecutive lines. When a subpath is closed, then a join also exists - at its first point (equivalent to its last point) connecting the first and last lines in the subpath. - - The possible line join styles are: - \list - \o bevel - this is all that is rendered at joins. - \o round - a filled arc connecting the two aforementioned corners of the join, abutting (and not overlapping) the aforementioned triangle, with the diameter equal to the line width and the origin at the point of the join, must be rendered at joins. - \o miter - a second filled triangle must (if it can given the miter length) be rendered at the join, this is the default line join style. - \endlist - Other values are ignored. -*/ -v8::Handle ctx2d_lineJoin(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - switch (r->context->state.lineJoin) { - case Qt::RoundJoin: - return engine->toString(QLatin1String("round")); - case Qt::BevelJoin: - return engine->toString(QLatin1String("bevel")); - case Qt::MiterJoin: - return engine->toString(QLatin1String("miter")); - default: - break; - } - return engine->toString(QLatin1String("miter")); -} - -static void ctx2d_lineJoin_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - QString lineJoin = engine->toString(value); - Qt::PenJoinStyle join; - if (lineJoin == QLatin1String("round")) - join = Qt::RoundJoin; - else if (lineJoin == QLatin1String("bevel")) - join = Qt::BevelJoin; - else if (lineJoin == QLatin1String("miter")) - join = Qt::MiterJoin; - else - return; - - if (join != r->context->state.lineJoin) { - r->context->state.lineJoin = join; - r->context->buffer()->setLineJoin(join); - } -} - -/*! - \qmlproperty real QtQuick2::Context2D::lineWidth - Holds the the current line width. Values that are not finite values greater than zero are ignored. - */ -v8::Handle ctx2d_lineWidth(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - - return v8::Number::New(r->context->state.lineWidth); -} - -static void ctx2d_lineWidth_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - qreal w = value->NumberValue(); - - if (w > 0 && qIsFinite(w) && w != r->context->state.lineWidth) { - r->context->state.lineWidth = w; - r->context->buffer()->setLineWidth(w); - } -} - -/*! - \qmlproperty real QtQuick2::Context2D::miterLimit - Holds the current miter limit ratio. - The default miter limit value is 10.0. - */ -v8::Handle ctx2d_miterLimit(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - - return v8::Number::New(r->context->state.miterLimit); -} - -static void ctx2d_miterLimit_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - qreal ml = value->NumberValue(); - - if (ml > 0 && qIsFinite(ml) && ml != r->context->state.miterLimit) { - r->context->state.miterLimit = ml; - r->context->buffer()->setMiterLimit(ml); - } -} - -// shadows -/*! - \qmlproperty real QtQuick2::Context2D::shadowBlur - Holds the current level of blur applied to shadows - */ -v8::Handle ctx2d_shadowBlur(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - - return v8::Number::New(r->context->state.shadowBlur); -} - -static void ctx2d_shadowBlur_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - qreal blur = value->NumberValue(); - - if (blur > 0 && qIsFinite(blur) && blur != r->context->state.shadowBlur) { - r->context->state.shadowBlur = blur; - r->context->buffer()->setShadowBlur(blur); - } -} - -/*! - \qmlproperty string QtQuick2::Context2D::shadowColor - Holds the current shadow color. - */ -v8::Handle ctx2d_shadowColor(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - return engine->toString(r->context->state.shadowColor.name()); -} - -static void ctx2d_shadowColor_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - QColor color = qt_color_from_string(value); - - if (color.isValid() && color != r->context->state.shadowColor) { - r->context->state.shadowColor = color; - r->context->buffer()->setShadowColor(color); - } -} - - -/*! - \qmlproperty qreal QtQuick2::Context2D::shadowOffsetX - Holds the current shadow offset in the positive horizontal distance. - - \sa QtQuick2::Context2D::shadowOffsetY - */ -v8::Handle ctx2d_shadowOffsetX(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - - return v8::Number::New(r->context->state.shadowOffsetX); -} - -static void ctx2d_shadowOffsetX_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - qreal offsetX = value->NumberValue(); - if (qIsFinite(offsetX) && offsetX != r->context->state.shadowOffsetX) { - r->context->state.shadowOffsetX = offsetX; - r->context->buffer()->setShadowOffsetX(offsetX); - } -} -/*! - \qmlproperty qreal QtQuick2::Context2D::shadowOffsetY - Holds the current shadow offset in the positive vertical distance. - - \sa QtQuick2::Context2D::shadowOffsetX - */ -v8::Handle ctx2d_shadowOffsetY(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - - return v8::Number::New(r->context->state.shadowOffsetY); -} - -static void ctx2d_shadowOffsetY_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - qreal offsetY = value->NumberValue(); - if (qIsFinite(offsetY) && offsetY != r->context->state.shadowOffsetY) { - r->context->state.shadowOffsetY = offsetY; - r->context->buffer()->setShadowOffsetY(offsetY); - } -} - -v8::Handle ctx2d_path(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - return r->context->m_v8path; -} - -static void ctx2d_path_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - r->context->beginPath(); - if (value->IsObject()) { - QDeclarativePath* path = qobject_cast(engine->toQObject(value)); - if (path) - r->context->m_path = path->path(); - } else { - QString path = engine->toString(value->ToString()); - QDeclarativeSvgParser::parsePathDataFast(path, r->context->m_path); - } - r->context->m_v8path = value; -} - -//rects -/*! - \qmlmethod object QtQuick2::Context2D::clearRect(real x, real y, real w, real h) - Clears all pixels on the canvas in the given rectangle to transparent black. - */ -static v8::Handle ctx2d_clearRect(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 4) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - qreal w = args[2]->NumberValue(); - qreal h = args[3]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) - return args.This(); - - r->context->buffer()->clearRect(x, y, w, h); - } - - return args.This(); -} -/*! - \qmlmethod object QtQuick2::Context2D::fillRect(real x, real y, real w, real h) - Paint the specified rectangular area using the fillStyle. - - \sa QtQuick2::Context2D::fillStyle - */ -static v8::Handle ctx2d_fillRect(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - if (args.Length() == 4) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - qreal w = args[2]->NumberValue(); - qreal h = args[3]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) - return args.This(); - - r->context->buffer()->fillRect(x, y, w, h); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::fillRect(real x, real y, real w, real h) - Stroke the specified rectangle's path using the strokeStyle, lineWidth, lineJoin, - and (if appropriate) miterLimit attributes. - - \sa QtQuick2::Context2D::strokeStyle - \sa QtQuick2::Context2D::lineWidth - \sa QtQuick2::Context2D::lineJoin - \sa QtQuick2::Context2D::miterLimit - */ -static v8::Handle ctx2d_strokeRect(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 4) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - qreal w = args[2]->NumberValue(); - qreal h = args[3]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) - return args.This(); - - r->context->buffer()->strokeRect(x, y, w, h); - } - - return args.This(); -} - -// Complex shapes (paths) API -/*! - \qmlmethod object QtQuick2::Context2D::arc(real x, real y, real radius, real startAngle, real endAngle, bool anticlockwise) - Adds an arc to the current subpath that lies on the circumference of the circle whose center is at the point (\c x,\cy) and whose radius is \c radius. - \image qml-item-canvas-arcTo2.png - \sa QtQuick2::Context2D::arcTo - See {http://www.w3.org/TR/2dcontext/#dom-context-2d-arc}{W3C 2d context standard for arc} - */ -static v8::Handle ctx2d_arc(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - if (args.Length() >= 5) { - bool antiClockwise = false; - - if (args.Length() == 6) - antiClockwise = args[5]->BooleanValue(); - - qreal radius = args[2]->NumberValue(); - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - qreal sa = args[3]->NumberValue(); - qreal ea = args[4]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(sa) || !qIsFinite(ea)) - return args.This(); - - if (radius < 0) - V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "Incorrect argument radius"); - - r->context->arc(args[0]->NumberValue(), - args[1]->NumberValue(), - radius, - args[3]->NumberValue(), - args[4]->NumberValue(), - antiClockwise); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::arcTo(real x1, real y1, real x2, real y2, real radius) - - Adds an arc with the given control points and radius to the current subpath, connected to the previous point by a straight line. - To draw an arc, you begin with the same steps your followed to create a line: - \list - \o Call the context.beginPath() method to set a new path. - \o Call the context.moveTo(\c x, \c y) method to set your starting position on the canvas at the point (\c x,\c y). - \o To draw an arc or circle, call the context.arcTo(\c x1, \c y1, \c x2, \c y2,\c radius) method. - This adds an arc with starting point (\c x1,\c y1), ending point (\c x2, \c y2), and radius \c radius to the current subpath and connects - it to the previous subpath by a straight line. - \endlist - \image qml-item-canvas-arcTo.png - Both startAngle and endAngle are measured from the x axis in units of radians. - - \image qml-item-canvas-startAngle.png - The anticlockwise has the value TRUE for each arc in the figure above because they are all drawn in the counterclockwise direction. - \sa QtQuick2::Context2D::arc - \sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-arcto}{W3C 2d context standard for arcTo} - */ -static v8::Handle ctx2d_arcTo(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - - if (args.Length() == 5) { - qreal x1 = args[0]->NumberValue(); - qreal y1 = args[1]->NumberValue(); - qreal x2 = args[2]->NumberValue(); - qreal y2 = args[3]->NumberValue(); - - if (!qIsFinite(x1) || !qIsFinite(y1) || !qIsFinite(x2) || !qIsFinite(y2)) - return args.This(); - - qreal radius = args[4]->NumberValue(); - if (radius < 0) - V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "Incorrect argument radius"); - r->context->arcTo(args[0]->NumberValue(), - args[1]->NumberValue(), - args[2]->NumberValue(), - args[3]->NumberValue(), - args[4]->NumberValue()); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::beginPath() - - Resets the current path to a new path. - */ -static v8::Handle ctx2d_beginPath(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - r->context->beginPath(); - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::bezierCurveTo(real cp1x, real cp1y, real cp2x, real cp2y, real x, real y) - - Adds a cubic Bezier curve between the current position and the given endPoint using the control points specified by (\c cp1x, cp1y), - and (\c cp2x, \c cp2y). - After the curve is added, the current position is updated to be at the end point (\c x, \c y) of the curve. - The following code produces the path shown below: - \code - ctx.strokeStyle = Qt.rgba(0, 0, 0, 1); - ctx.lineWidth = 1; - ctx.beginPath(); - ctx.moveTo(20, 0);//start point - ctx.bezierCurveTo(-10, 90, 210, 90, 180, 0); - ctx.stroke(); - \endcode - \image qml-item-canvas-bezierCurveTo.png - \sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-beziercurveto}{W3C 2d context standard for bezierCurveTo} - \sa {http://www.openrise.com/lab/FlowerPower/}{The beautiful flower demo by using bezierCurveTo} - */ -static v8::Handle ctx2d_bezierCurveTo(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 6) { - qreal cp1x = args[0]->NumberValue(); - qreal cp1y = args[1]->NumberValue(); - qreal cp2x = args[2]->NumberValue(); - qreal cp2y = args[3]->NumberValue(); - qreal x = args[4]->NumberValue(); - qreal y = args[5]->NumberValue(); - - if (!qIsFinite(cp1x) || !qIsFinite(cp1y) || !qIsFinite(cp2x) || !qIsFinite(cp2y) || !qIsFinite(x) || !qIsFinite(y)) - return args.This(); - - r->context->bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::clip() - - Creates the clipping region from the current path. - Any parts of the shape outside the clipping path are not displayed. - To create a complex shape using the \a clip() method: - - \list 1 - \o Call the \c{context.beginPath()} method to set the clipping path. - \o Define the clipping path by calling any combination of the \c{lineTo}, - \c{arcTo}, \c{arc}, \c{moveTo}, etc and \c{closePath} methods. - \o Call the \c{context.clip()} method. - \endlist - - The new shape displays. The following shows how a clipping path can - modify how an image displays: - - \image qml-canvas-clip-complex.png - \sa QtQuick2::Context2D::beginPath() - \sa QtQuick2::Context2D::closePath() - \sa QtQuick2::Context2D::stroke() - \sa QtQuick2::Context2D::fill() - \sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-clip}{W3C 2d context standard for clip} - */ -static v8::Handle ctx2d_clip(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - QPainterPath clipPath = r->context->m_path; - clipPath.closeSubpath(); - if (!r->context->state.clipPath.isEmpty()) - r->context->state.clipPath = clipPath.intersected(r->context->state.clipPath); - else - r->context->state.clipPath = clipPath; - r->context->buffer()->clip(r->context->state.clipPath); - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::closePath() - Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting a new path. - The current point of the new path is the previous subpath's first point. - - \sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-closepath}{W3C 2d context standard for closePath} - */ -static v8::Handle ctx2d_closePath(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - r->context->closePath(); - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::fill() - - Fills the subpaths with the current fill style. - - \sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-fill}{W3C 2d context standard for fill} - - \sa QtQuick2::Context2D::fillStyle - */ -static v8::Handle ctx2d_fill(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r); - - r->context->buffer()->fill(r->context->m_path); - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::lineTo(real x, real y) - - Draws a line from the current position to the point (x, y). - */ -static v8::Handle ctx2d_lineTo(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 2) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y)) - return args.This(); - - r->context->lineTo(x, y); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::moveTo(real x, real y) - - Creates a new subpath with the given point. - */ -static v8::Handle ctx2d_moveTo(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - if (args.Length() == 2) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y)) - return args.This(); - r->context->moveTo(x, y); - } - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::quadraticCurveTo(real cpx, real cpy, real x, real y) - - Adds a quadratic Bezier curve between the current point and the endpoint (\c x, \c y) with the control point specified by (\c cpx, \c cpy). - - See {http://www.w3.org/TR/2dcontext/#dom-context-2d-quadraticcurveto}{W3C 2d context standard for for quadraticCurveTo} - */ -static v8::Handle ctx2d_quadraticCurveTo(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - if (args.Length() == 4) { - qreal cpx = args[0]->NumberValue(); - qreal cpy = args[1]->NumberValue(); - qreal x = args[2]->NumberValue(); - qreal y = args[3]->NumberValue(); - - if (!qIsFinite(cpx) || !qIsFinite(cpy) || !qIsFinite(x) || !qIsFinite(y)) - return args.This(); - - r->context->quadraticCurveTo(cpx, cpy, x, y); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::rect(real x, real y, real w, real h) - - Adds a rectangle at position (\c x, \c y), with the given width \c w and height \c h, as a closed subpath. - */ -static v8::Handle ctx2d_rect(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 4) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - qreal w = args[2]->NumberValue(); - qreal h = args[3]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) - return args.This(); - - r->context->rect(x, y, w, h); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::roundedRect(real x, real y, real w, real h, real xRadius, real yRadius) - - Adds the given rectangle rect with rounded corners to the path. The \c xRadius and \c yRadius arguments specify the radius of the - ellipses defining the corners of the rounded rectangle. - */ -static v8::Handle ctx2d_roundedRect(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - if (args.Length() == 6) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - qreal w = args[2]->NumberValue(); - qreal h = args[3]->NumberValue(); - qreal xr = args[4]->NumberValue(); - qreal yr = args[5]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) - return args.This(); - - if (!qIsFinite(xr) || !qIsFinite(yr)) - V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "roundedRect(): Invalid arguments"); - - r->context->roundedRect(x, y, w, h, xr, yr); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::ellipse(real x, real y, real w, real h) - - Creates an ellipse within the bounding rectangle defined by its top-left corner at (\a x, \ y), width \a w and height \a h, - and adds it to the path as a closed subpath. - - The ellipse is composed of a clockwise curve, starting and finishing at zero degrees (the 3 o'clock position). - */ -static v8::Handle ctx2d_ellipse(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 4) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - qreal w = args[2]->NumberValue(); - qreal h = args[3]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(h)) - return args.This(); - - - r->context->ellipse(x, y, w, h); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::text(string text, real x, real y) - - Adds the given \c text to the path as a set of closed subpaths created from the current context font supplied. - The subpaths are positioned so that the left end of the text's baseline lies at the point specified by (\c x, \c y). - */ -static v8::Handle ctx2d_text(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE(); - if (args.Length() == 3) { - qreal x = args[1]->NumberValue(); - qreal y = args[2]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y)) - return args.This(); - r->context->text(engine->toString(args[0]), x, y); - } - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::stroke() - - Strokes the subpaths with the current stroke style. - - See {http://www.w3.org/TR/2dcontext/#dom-context-2d-stroke}{W3C 2d context standard for stroke} - - \sa QtQuick2::Context2D::strokeStyle - */ -static v8::Handle ctx2d_stroke(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - - r->context->buffer()->stroke(r->context->m_path); - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::isPointInPath(real x, real y) - - Returns true if the given point is in the current path. - - \sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-ispointinpath}{W3C 2d context standard for isPointInPath} - */ -static v8::Handle ctx2d_isPointInPath(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - bool pointInPath = false; - if (args.Length() == 2) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - if (!qIsFinite(x) || !qIsFinite(y)) - return v8::Boolean::New(false); - pointInPath = r->context->isPointInPath(x, y); - } - return v8::Boolean::New(pointInPath); -} - -static v8::Handle ctx2d_drawFocusRing(const v8::Arguments &args) -{ - V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::drawFocusRing is not supported"); - return args.This(); -} - -static v8::Handle ctx2d_setCaretSelectionRect(const v8::Arguments &args) -{ - V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::setCaretSelectionRect is not supported"); - return args.This(); -} - -static v8::Handle ctx2d_caretBlinkRate(const v8::Arguments &args) -{ - V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::caretBlinkRate is not supported"); - return args.This(); -} -// text -/*! - \qmlproperty string QtQuick2::Context2D::font - Holds the current font settings. - - The default font value is "10px sans-serif". - See {http://www.w3.org/TR/2dcontext/#dom-context-2d-font}{w3C 2d context standard for font} - */ -v8::Handle ctx2d_font(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - return engine->toString(r->context->state.font.toString()); -} - -static void ctx2d_font_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - QString fs = engine->toString(value); - QFont font = qt_font_from_string(fs); - if (font != r->context->state.font) { - r->context->state.font = font; - } -} - -/*! - \qmlproperty string QtQuick2::Context2D::textAlign - - Holds the current text alignment settings. - The possible values are: - \list - \o start - \o end - \o left - \o right - \o center - \endlist - Other values are ignored. The default value is "start". - */ -v8::Handle ctx2d_textAlign(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - QV8Engine *engine = V8ENGINE_ACCESSOR(); - switch (r->context->state.textAlign) { - case QQuickContext2D::Start: - return engine->toString(QLatin1String("start")); - case QQuickContext2D::End: - return engine->toString(QLatin1String("end")); - case QQuickContext2D::Left: - return engine->toString(QLatin1String("left")); - case QQuickContext2D::Right: - return engine->toString(QLatin1String("right")); - case QQuickContext2D::Center: - return engine->toString(QLatin1String("center")); - default: - break; - } - return engine->toString(QLatin1String("start")); -} - -static void ctx2d_textAlign_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - QString textAlign = engine->toString(value); - - QQuickContext2D::TextAlignType ta; - if (textAlign == QLatin1String("start")) - ta = QQuickContext2D::Start; - else if (textAlign == QLatin1String("end")) - ta = QQuickContext2D::End; - else if (textAlign == QLatin1String("left")) - ta = QQuickContext2D::Left; - else if (textAlign == QLatin1String("right")) - ta = QQuickContext2D::Right; - else if (textAlign == QLatin1String("center")) - ta = QQuickContext2D::Center; - else - return; - - if (ta != r->context->state.textAlign) { - r->context->state.textAlign = ta; - } -} - -/*! - \qmlproperty string QtQuick2::Context2D::textBaseline - - Holds the current baseline alignment settings. - The possible values are: - \list - \o top - \o hanging - \o middle - \o alphabetic - \o ideographic - \o bottom - \endlist - Other values are ignored. The default value is "alphabetic". - */ -v8::Handle ctx2d_textBaseline(v8::Local, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - switch (r->context->state.textBaseline) { - case QQuickContext2D::Alphabetic: - return engine->toString(QLatin1String("alphabetic")); - case QQuickContext2D::Hanging: - return engine->toString(QLatin1String("hanging")); - case QQuickContext2D::Top: - return engine->toString(QLatin1String("top")); - case QQuickContext2D::Bottom: - return engine->toString(QLatin1String("bottom")); - case QQuickContext2D::Middle: - return engine->toString(QLatin1String("middle")); - default: - break; - } - return engine->toString(QLatin1String("alphabetic")); -} - -static void ctx2d_textBaseline_set(v8::Local, v8::Local value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast(info.This()); - CHECK_CONTEXT_SETTER(r) - QV8Engine *engine = V8ENGINE_ACCESSOR(); - QString textBaseline = engine->toString(value); - - QQuickContext2D::TextBaseLineType tb; - if (textBaseline == QLatin1String("alphabetic")) - tb = QQuickContext2D::Alphabetic; - else if (textBaseline == QLatin1String("hanging")) - tb = QQuickContext2D::Hanging; - else if (textBaseline == QLatin1String("top")) - tb = QQuickContext2D::Top; - else if (textBaseline == QLatin1String("bottom")) - tb = QQuickContext2D::Bottom; - else if (textBaseline == QLatin1String("middle")) - tb = QQuickContext2D::Middle; - else - return; - - if (tb != r->context->state.textBaseline) { - r->context->state.textBaseline = tb; - } -} - -/*! - \qmlmethod object QtQuick2::Context2D::fillText(text, x, y) - Fills the given text at the given position. - \sa QtQuick2::Context2D::font - \sa QtQuick2::Context2D::textAlign - \sa QtQuick2::Context2D::textBaseline - \sa QtQuick2::Context2D::strokeText - */ -static v8::Handle ctx2d_fillText(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE(); - if (args.Length() == 3) { - qreal x = args[1]->NumberValue(); - qreal y = args[2]->NumberValue(); - if (!qIsFinite(x) || !qIsFinite(y)) - return args.This(); - QPainterPath textPath = r->context->createTextGlyphs(x, y, engine->toString(args[0])); - r->context->buffer()->fill(textPath); - } - return args.This(); -} -/*! - \qmlmethod object QtQuick2::Context2D::strokeText(text, x, y) - Strokes the given text at the given position. - \sa QtQuick2::Context2D::font - \sa QtQuick2::Context2D::textAlign - \sa QtQuick2::Context2D::textBaseline - \sa QtQuick2::Context2D::fillText - */ -static v8::Handle ctx2d_strokeText(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE(); - if (args.Length() == 3) { - qreal x = args[1]->NumberValue(); - qreal y = args[2]->NumberValue(); - if (!qIsFinite(x) || !qIsFinite(y)) - return args.This(); - QPainterPath textPath = r->context->createTextGlyphs(x, y, engine->toString(args[0])); - r->context->buffer()->stroke(textPath); - } - return args.This(); -} -/*! - \qmlclass QtQuick2::TextMetrics - \inqmlmodule QtQuick 2 - \since QtQuick 2.0 - \brief The Context2D TextMetrics interface. - The TextMetrics object can be created by QtQuick2::Context2D::measureText method. - See {http://www.w3.org/TR/2dcontext/#textmetrics}{W3C 2d context TexMetrics} for more details. - - \sa QtQuick2::Context2D::measureText - \sa QtQuick2::TextMetrics::width - */ - -/*! - \qmlproperty int QtQuick2::TextMetrics::width - Holds the advance width of the text that was passed to the QtQuick2::Context2D::measureText() method. - This property is read only. - */ - -/*! - \qmlmethod variant QtQuick2::Context2D::measureText(text) - Returns a TextMetrics object with the metrics of the given text in the current font. - */ -static v8::Handle ctx2d_measureText(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE(); - - if (args.Length() == 1) { - QFontMetrics fm(r->context->state.font); - uint width = fm.width(engine->toString(args[0])); - v8::Local tm = v8::Object::New(); - tm->Set(v8::String::New("width"), v8::Number::New(width)); - return tm; - } - return v8::Undefined(); -} - -// drawing images -/*! - \qmlmethod QtQuick2::Context2D::drawImage(variant image, real dx, real dy) - Draws the given \a image on the canvas at position (\a dx, \a dy). - Note: - The \a image type can be an Image item, an image url or a \a {QtQuick2::CanvasImageData} object. - When given as Image item, if the image isn't fully loaded, this method draws nothing. - When given as url string, the image should be loaded by calling Canvas item's \a QtQuick2::Canvas::loadImage() method first. - This image been drawing is subject to the current context clip path, even the given \c image is a {QtQuick2::CanvasImageData} object. - - \sa QtQuick2::CanvasImageData - \sa QtQuick2::Image - \sa QtQuick2::Canvas::loadImage - \sa QtQuick2::Canvas::isImageLoaded - \sa QtQuick2::Canvas::imageLoaded - - \sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-drawimage}{W3C 2d context standard for drawImage} - */ -/*! - \qmlmethod QtQuick2::Context2D::drawImage(variant image, real dx, real dy, real dw, real dh) - This is an overloaded function. - Draws the given item as \a image onto the canvas at point (\a dx, \a dy) and with width \a dw, - height \a dh. - - Note: - The \a image type can be an Image item, an image url or a \a {QtQuick2::CanvasImageData} object. - When given as Image item, if the image isn't fully loaded, this method draws nothing. - When given as url string, the image should be loaded by calling Canvas item's \a QtQuick2::Canvas::loadImage() method first. - This image been drawing is subject to the current context clip path, even the given \c image is a {QtQuick2::CanvasImageData} object. - - \sa QtQuick2::CanvasImageData - \sa QtQuick2::Image - \sa QtQuick2::Canvas::loadImage - \sa QtQuick2::Canvas::isImageLoaded - \sa QtQuick2::Canvas::imageLoaded - - \sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-drawimage}{W3C 2d context standard for drawImage} - */ -/*! - \qmlmethod QtQuick2::Context2D::drawImage(variant image, real sx, real sy, real sw, sh, real dx, real dy, real dw, dh) - This is an overloaded function. - Draws the given item as \a image from source point (\a sx, \a sy) and source width \sw, source height \sh - onto the canvas at point (\a dx, \a dy) and with width \a dw, height \a dh. - - - Note: - The \a image type can be an Image or Canvas item, an image url or a \a {QtQuick2::CanvasImageData} object. - When given as Image item, if the image isn't fully loaded, this method draws nothing. - When given as url string, the image should be loaded by calling Canvas item's \a QtQuick2::Canvas::loadImage() method first. - This image been drawing is subject to the current context clip path, even the given \c image is a {QtQuick2::CanvasImageData} object. - - \sa QtQuick2::CanvasImageData - \sa QtQuick2::Image - \sa QtQuick2::Canvas::loadImage - \sa QtQuick2::Canvas::isImageLoaded - \sa QtQuick2::Canvas::imageLoaded - - \sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-drawimage}{W3C 2d context standard for drawImage} -*/ -static v8::Handle ctx2d_drawImage(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE(); - qreal sx, sy, sw, sh, dx, dy, dw, dh; - - if (!args.Length()) - return args.This(); - - QImage image; - if (args[0]->IsString()) { - QUrl url(engine->toString(args[0]->ToString())); - if (!url.isValid()) - V8THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch"); - - image = r->context->createImage(url); - } else if (args[0]->IsObject()) { - QQuickImage *imageItem = qobject_cast(engine->toQObject(args[0]->ToObject())); - QQuickCanvasItem *canvas = qobject_cast(engine->toQObject(args[0]->ToObject())); - - QV8Context2DPixelArrayResource *pix = v8_resource_cast(args[0]->ToObject()->GetInternalField(0)->ToObject()); - if (pix) { - image = pix->image; - } else if (imageItem) { - image = imageItem->image(); - } else if (canvas) { - image = canvas->toImage(); - } else { - V8THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch"); - } - } else { - V8THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch"); - } - if (args.Length() == 3) { - dx = args[1]->NumberValue(); - dy = args[2]->NumberValue(); - sx = 0; - sy = 0; - sw = image.width(); - sh = image.height(); - dw = sw; - dh = sh; - } else if (args.Length() == 5) { - sx = 0; - sy = 0; - sw = image.width(); - sh = image.height(); - dx = args[1]->NumberValue(); - dy = args[2]->NumberValue(); - dw = args[3]->NumberValue(); - dh = args[4]->NumberValue(); - } else if (args.Length() == 9) { - sx = args[1]->NumberValue(); - sy = args[2]->NumberValue(); - sw = args[3]->NumberValue(); - sh = args[4]->NumberValue(); - dx = args[5]->NumberValue(); - dy = args[6]->NumberValue(); - dw = args[7]->NumberValue(); - dh = args[8]->NumberValue(); - } else { - return args.This(); - } - - if (!qIsFinite(sx) - || !qIsFinite(sy) - || !qIsFinite(sw) - || !qIsFinite(sh) - || !qIsFinite(dx) - || !qIsFinite(dy) - || !qIsFinite(dw) - || !qIsFinite(dh)) - return args.This(); - - if (!image.isNull()) { - if (sx < 0 || sy < 0 || sw == 0 || sh == 0 - || sx + sw > image.width() || sy + sh > image.height() - || sx + sw < 0 || sy + sh < 0) { - V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "drawImage(), index size error"); - } - - r->context->buffer()->drawImage(image,sx, sy, sw, sh, dx, dy, dw, dh); - } - - return args.This(); -} - -// pixel manipulation -/*! - \qmlclass QtQuick2::CanvasImageData - The \a QtQuick2::CanvasImageData object holds the image pixel data. - - The \a QtQuick2::CanvasImageData object has the actual dimensions of the data stored in - this object and holds the one-dimensional array containing the data in RGBA order, - as integers in the range 0 to 255. - - \sa QtQuick2::CanvasImageData::width - \sa QtQuick2::CanvasImageData::height - \sa QtQuick2::CanvasImageData::data - \sa QtQuick2::Context2D::createImageData - \sa QtQuick2::Context2D::getImageData - \sa QtQuick2::Context2D::putImageData - */ -/*! - \qmlproperty QtQuick2::CanvasImageData::width - Holds the actual width dimension of the data in the ImageData object, in device pixels. - */ -v8::Handle ctx2d_imageData_width(v8::Local, const v8::AccessorInfo &args) -{ - QV8Context2DPixelArrayResource *r = v8_resource_cast(args.This()->GetInternalField(0)->ToObject()); - if (!r) - return v8::Integer::New(0); - return v8::Integer::New(r->image.width()); -} - -/*! - \qmlproperty QtQuick2::CanvasImageData::height - Holds the actual height dimension of the data in the ImageData object, in device pixels. - */ -v8::Handle ctx2d_imageData_height(v8::Local, const v8::AccessorInfo &args) -{ - QV8Context2DPixelArrayResource *r = v8_resource_cast(args.This()->GetInternalField(0)->ToObject()); - if (!r) - return v8::Integer::New(0); - - return v8::Integer::New(r->image.height()); -} - -/*! - \qmlproperty QtQuick2::CanvasImageData::data - Holds the one-dimensional array containing the data in RGBA order, as integers in the range 0 to 255. - */ -v8::Handle ctx2d_imageData_data(v8::Local, const v8::AccessorInfo &args) -{ - return args.This()->GetInternalField(0); -} - -/*! - \qmlmethod void QtQuick2::CanvasImageData::mirrr( bool horizontal = false, bool vertical = true) - Mirrors the image data in place in the \c horizontal and/or the \c vertical direction depending on - whether horizontal and vertical are set to true or false. - The default \c horizontal value is false, the default \c vertical value is true. -*/ -static v8::Handle ctx2d_imageData_mirror(const v8::Arguments &args) -{ - bool horizontal = false, vertical = true; - QV8Context2DPixelArrayResource *r = v8_resource_cast(args.This()->GetInternalField(0)->ToObject()); - - if (!r) { - //error - return v8::Undefined(); - } - - if (args.Length() > 2) { - //error - return v8::Undefined(); - } - - if (args.Length() == 1) { - horizontal = args[0]->BooleanValue(); - } else if (args.Length() == 2) { - horizontal = args[0]->BooleanValue(); - vertical = args[1]->BooleanValue(); - } - r->image = r->image.mirrored(horizontal, vertical); - return args.This(); -} - -/*! - \qmlmethod void QtQuick2::CanvasImageData::filter(enumeration mode, args) - Filters the image data as defined by one of the following modes: - \list - \o Canvas.Threshold - converts the image to black and white pixels depending - if they are above or below the threshold defined by the level parameter. - The level must be between 0.0 (black) and 1.0(white). - If no level is specified, 0.5 is used. - \o Canvas.Mono - converts the image to the 1-bit per pixel format. - \o Canvas.GrayScale - converts any colors in the image to grayscale equivalents. - \o Canvas.Brightness -increase/decrease a fixed \c adjustment value to each pixel's RGB channel value. - \o Canvas.Invert - sets each pixel to its inverse value. - \o Canvas.Blur - executes a box blur with the pixel \c radius parameter specifying the range of the blurring for each pixel. - the default blur \c radius is 3. This filter also accepts another \c quality parameter, if true, the filter will - execute 3-passes box blur to simulate the Guassian blur. The default \c quality value is false. - \o Canvas.Opaque - sets the alpha channel to entirely opaque. - \o Canvas.Convolute - executes a generic {http://en.wikipedia.org/wiki/Convolution}{Convolution} filter, the second - parameter contains the convoluton matrix data as a number array. - \endlist - -*/ -static v8::Handle ctx2d_imageData_filter(const v8::Arguments &args) -{ - QV8Context2DPixelArrayResource *r = v8_resource_cast(args.This()->GetInternalField(0)->ToObject()); - - if (!r) { - //error - return v8::Undefined(); - } - - if (args.Length() >= 1) { - int filterFlag = args[0]->IntegerValue(); - switch (filterFlag) { - case QQuickCanvasItem::Mono : - { - r->image = r->image.convertToFormat(QImage::Format_Mono).convertToFormat(QImage::Format_ARGB32_Premultiplied); - } - break; - case QQuickCanvasItem::GrayScale : - { - for (int y = 0; y < r->image.height(); ++y) { - QRgb *row = (QRgb*)r->image.scanLine(y); - for (int x = 0; x < r->image.width(); ++x) { - unsigned char* rgb = ((unsigned char*)&row[x]); - rgb[0] = rgb[1] = rgb[2] = qGray(rgb[0], rgb[1], rgb[2]); - } - } - } - break; - case QQuickCanvasItem::Threshold : - { - qreal threshold = 0.5; - if (args.Length() > 1) - threshold = args[1]->NumberValue(); - - for (int y = 0; y < r->image.height(); ++y) { - QRgb *row = (QRgb*)r->image.scanLine(y); - for (int x = 0; x < r->image.width(); ++x) { - unsigned char* rgb = ((unsigned char*)&row[x]); - unsigned char v = qGray(rgb[0], rgb[1], rgb[2]) >= threshold*255 ? 255 : 0; - rgb[0] = rgb[1] = rgb[2] = v; - } - } - } - break; - case QQuickCanvasItem::Brightness : - { - int adjustment = 1; - if (args.Length() > 1) - adjustment = args[1]->IntegerValue(); - - for (int y = 0; y < r->image.height(); ++y) { - QRgb *row = (QRgb*)r->image.scanLine(y); - for (int x = 0; x < r->image.width(); ++x) { - ((unsigned char*)&row[x])[0] += adjustment; - ((unsigned char*)&row[x])[1] += adjustment; - ((unsigned char*)&row[x])[2] += adjustment; - } - } - } - break; - case QQuickCanvasItem::Invert : - { - r->image.invertPixels(); - } - break; - case QQuickCanvasItem::Blur : - { - int radius = 3; - bool quality = false; - - if (args.Length() > 1) - radius = args[1]->IntegerValue() / 2; - if (args.Length() > 2) - quality = args[2]->BooleanValue(); - - qt_image_boxblur(r->image, radius, quality); - } - break; - case QQuickCanvasItem::Opaque : - { - for (int y = 0; y < r->image.height(); ++y) { - QRgb *row = (QRgb*)r->image.scanLine(y); - for (int x = 0; x < r->image.width(); ++x) { - ((unsigned char*)&row[x])[3] = 255; - } - } - } - break; - case QQuickCanvasItem::Convolute : - { - if (args.Length() > 1 && args[1]->IsArray()) { - v8::Local array = v8::Local::Cast(args[1]); - QVector weights; - for (uint32_t i = 0; i < array->Length(); ++i) - weights.append(array->Get(i)->NumberValue()); - r->image = qt_image_convolute_filter(r->image, weights); - } else { - //error - } - } - break; - default: - break; - } - } - - return args.This(); -} -/*! - \qmlclass QtQuick2::CanvasPixelArray - The CanvasPixelArray object provides ordered, indexed access to the color components of each pixel of the image data. - The CanvasPixelArray can be accessed as normal Javascript array. - \sa QtQuick2::CanvasImageData - \sa {http://www.w3.org/TR/2dcontext/#canvaspixelarray}{W3C 2d context standard for PixelArray} - */ - -/*! - \qmlproperty QtQuick2::CanvasPixelArray::length - The CanvasPixelArray object represents h×w×4 integers which w and h comes from CanvasImageData. - The length attribute of a CanvasPixelArray object must return this h×w×4 number value. - This property is read only. -*/ -v8::Handle ctx2d_pixelArray_length(v8::Local, const v8::AccessorInfo &args) -{ - QV8Context2DPixelArrayResource *r = v8_resource_cast(args.This()); - if (!r || r->image.isNull()) return v8::Undefined(); - - return v8::Integer::New(r->image.width() * r->image.height() * 4); -} - -v8::Handle ctx2d_pixelArray_indexed(uint32_t index, const v8::AccessorInfo& args) -{ - QV8Context2DPixelArrayResource *r = v8_resource_cast(args.This()); - - if (r && index < static_cast(r->image.width() * r->image.height() * 4)) { - const quint32 w = r->image.width(); - const quint32 row = (index / 4) / w; - const quint32 col = (index / 4) % w; - const QRgb* pixel = reinterpret_cast(r->image.constScanLine(row)); - pixel += col; - switch (index % 4) { - case 0: - return v8::Integer::New(qRed(*pixel)); - case 1: - return v8::Integer::New(qGreen(*pixel)); - case 2: - return v8::Integer::New(qBlue(*pixel)); - case 3: - return v8::Integer::New(qAlpha(*pixel)); - } - } - return v8::Undefined(); -} - -v8::Handle ctx2d_pixelArray_indexed_set(uint32_t index, v8::Local value, const v8::AccessorInfo& info) -{ - QV8Context2DPixelArrayResource *r = v8_resource_cast(info.This()); - - const int v = value->Uint32Value(); - if (r && index < static_cast(r->image.width() * r->image.height() * 4) && v > 0 && v <= 255) { - const quint32 w = r->image.width(); - const quint32 row = (index / 4) / w; - const quint32 col = (index / 4) % w; - - QRgb* pixel = reinterpret_cast(r->image.scanLine(row)); - pixel += col; - switch (index % 4) { - case 0: - *pixel = qRgba(v, qGreen(*pixel), qBlue(*pixel), qAlpha(*pixel)); - break; - case 1: - *pixel = qRgba(qRed(*pixel), v, qBlue(*pixel), qAlpha(*pixel)); - break; - case 2: - *pixel = qRgba(qRed(*pixel), qGreen(*pixel), v, qAlpha(*pixel)); - break; - case 3: - *pixel = qRgba(qRed(*pixel), qGreen(*pixel), qBlue(*pixel), v); - break; - } - } - return v8::Undefined(); -} -/*! - \qmlmethod QtQuick2::CanvasImageData createImageData(real sw, real sh) - Creates a CanvasImageData object with the given dimensions(\a sw, \a sh). - */ -/*! - \qmlmethod QtQuick2::CanvasImageData createImageData(QtQuick2::CanvasImageData imageData) - Creates a CanvasImageData object with the same dimensions as the argument. - */ -/*! - \qmlmethod QtQuick2::CanvasImageData createImageData(Url imageUrl) - Creates a CanvasImageData object with the given image loaded from \a imageUrl. - Note:The \a imageUrl must be already loaded before this function call, if not, an empty - CanvasImageData obect will be returned. - - \sa QtQuick2::Canvas::loadImage, QtQuick2::Canvas::unloadImage, QtQuick2::Canvas::isImageLoaded - */ -static v8::Handle ctx2d_createImageData(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE(); - - if (args.Length() == 1) { - if (args[0]->IsObject()) { - v8::Local imgData = args[0]->ToObject(); - QV8Context2DPixelArrayResource *pa = v8_resource_cast(imgData->GetInternalField(0)->ToObject()); - if (pa) { - qreal w = imgData->Get(v8::String::New("width"))->NumberValue(); - qreal h = imgData->Get(v8::String::New("height"))->NumberValue(); - return qt_create_image_data(w, h, engine, QImage()); - } - } else if (args[0]->IsString()) { - QImage image = r->context->createImage(QUrl(engine->toString(args[0]->ToString()))); - return qt_create_image_data(image.width(), image.height(), engine, image); - } - } else if (args.Length() == 2) { - qreal w = args[0]->NumberValue(); - qreal h = args[1]->NumberValue(); - - if (!qIsFinite(w) || !qIsFinite(h)) - V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createImageData(): invalid arguments"); - - if (w > 0 && h > 0) - return qt_create_image_data(w, h, engine, QImage()); - else - V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createImageData(): invalid arguments"); - } - return v8::Undefined(); -} - -/*! - \qmlmethod QtQuick2::CanvasImageData getImageData(real sx, real sy, real sw, real sh) - Returns an CanvasImageData object containing the image data for the given rectangle of the canvas. - */ -static v8::Handle ctx2d_getImageData(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE(); - if (args.Length() == 4) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - qreal w = args[2]->NumberValue(); - qreal h = args[3]->NumberValue(); - if (!qIsFinite(x) || !qIsFinite(y) || !qIsFinite(w) || !qIsFinite(w)) - V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "getImageData(): Invalid arguments"); - - if (w <= 0 || h <= 0) - V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "getImageData(): Invalid arguments"); - - QImage image = r->context->canvas()->toImage(QRectF(x, y, w, h)); - v8::Local imageData = qt_create_image_data(w, h, engine, image); - - return imageData; - } - return v8::Null(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::putImageData(QtQuick2::CanvasImageData imageData, real dx, real dy, real dirtyX, real dirtyY, real dirtyWidth, real dirtyHeight) - Paints the data from the given ImageData object onto the canvas. If a dirty rectangle (\a dirtyX, \a dirtyY, \a dirtyWidth, \a dirtyHeight) is provided, only the pixels from that rectangle are painted. - */ -static v8::Handle ctx2d_putImageData(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast(args.This()); - CHECK_CONTEXT(r) - if (args.Length() != 3 && args.Length() != 7) - return v8::Undefined(); - - if (args[0]->IsNull() || !args[0]->IsObject()) { - V8THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "Context2D::putImageData, the image data type mismatch"); - } - qreal dx = args[1]->NumberValue(); - qreal dy = args[2]->NumberValue(); - qreal w, h, dirtyX, dirtyY, dirtyWidth, dirtyHeight; - - if (!qIsFinite(dx) || !qIsFinite(dy)) - V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "putImageData() : Invalid arguments"); - - v8::Local imageData = args[0]->ToObject(); - QV8Context2DPixelArrayResource *pixelArray = v8_resource_cast(imageData->Get(v8::String::New("data"))->ToObject()); - if (pixelArray) { - w = imageData->Get(v8::String::New("width"))->NumberValue(); - h = imageData->Get(v8::String::New("height"))->NumberValue(); - - if (args.Length() == 7) { - dirtyX = args[3]->NumberValue(); - dirtyY = args[4]->NumberValue(); - dirtyWidth = args[5]->NumberValue(); - dirtyHeight = args[6]->NumberValue(); - - if (!qIsFinite(dirtyX) || !qIsFinite(dirtyY) || !qIsFinite(dirtyWidth) || !qIsFinite(dirtyHeight)) - V8THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "putImageData() : Invalid arguments"); - - - if (dirtyWidth < 0) { - dirtyX = dirtyX+dirtyWidth; - dirtyWidth = -dirtyWidth; - } - - if (dirtyHeight < 0) { - dirtyY = dirtyY+dirtyHeight; - dirtyHeight = -dirtyHeight; - } - - if (dirtyX < 0) { - dirtyWidth = dirtyWidth+dirtyX; - dirtyX = 0; - } - - if (dirtyY < 0) { - dirtyHeight = dirtyHeight+dirtyY; - dirtyY = 0; - } - - if (dirtyX+dirtyWidth > w) { - dirtyWidth = w - dirtyX; - } - - if (dirtyY+dirtyHeight > h) { - dirtyHeight = h - dirtyY; - } - - if (dirtyWidth <=0 || dirtyHeight <= 0) - return args.This(); - } else { - dirtyX = 0; - dirtyY = 0; - dirtyWidth = w; - dirtyHeight = h; - } - - QImage image = pixelArray->image.copy(dirtyX, dirtyY, dirtyWidth, dirtyHeight); - r->context->buffer()->drawImage(image, dirtyX, dirtyY, dirtyWidth, dirtyHeight, dx, dy, dirtyWidth, dirtyHeight); - } - return args.This(); -} - -/*! - \qmlclass QtQuick2::CanvasGradient - \inqmlmodule QtQuick 2 - \since QtQuick 2.0 - \brief The Context2D opaque CanvasGradient interface. - */ - -/*! - \qmlmethod QtQuick2::CanvasGradient QtQuick2::CanvasGradient::addColorStop(real offsetof, string color) - Adds a color stop with the given color to the gradient at the given offset. - 0.0 is the offset at one end of the gradient, 1.0 is the offset at the other end. - - For example: - \code - var gradient = ctx.createLinearGradient(0, 0, 100, 100); - gradient.addColorStop(0.3, Qt.rgba(1, 0, 0, 1)); - gradient.addColorStop(0.7, 'rgba(0, 255, 255, 1'); - \endcode - */ -static v8::Handle ctx2d_gradient_addColorStop(const v8::Arguments &args) -{ - QV8Context2DStyleResource *style = v8_resource_cast(args.This()); - if (!style) - V8THROW_ERROR("Not a CanvasGradient object"); - - QV8Engine *engine = V8ENGINE(); - - if (args.Length() == 2) { - - if (!style->brush.gradient()) - V8THROW_ERROR("Not a valid CanvasGradient object, can't get the gradient information"); - QGradient gradient = *(style->brush.gradient()); - qreal pos = args[0]->NumberValue(); - QColor color; - - if (args[1]->IsObject()) { - color = engine->toVariant(args[1], qMetaTypeId()).value(); - } else { - color = qt_color_from_string(args[1]); - } - if (pos < 0.0 || pos > 1.0 || !qIsFinite(pos)) { - V8THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "CanvasGradient: parameter offset out of range"); - } - - if (color.isValid()) { - gradient.setColorAt(pos, color); - } else { - V8THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "CanvasGradient: parameter color is not a valid color string"); - } - style->brush = gradient; - } - - return args.This(); -} - - -void QQuickContext2D::beginPath() -{ - m_path = QPainterPath(); - m_path.setFillRule(state.fillRule); -} - -void QQuickContext2D::closePath() -{ - if (m_path.isEmpty()) - return; - - QRectF boundRect = m_path.boundingRect(); - if (boundRect.width() || boundRect.height()) - m_path.closeSubpath(); - //FIXME:QPainterPath set the current point to (0,0) after close subpath - //should be the first point of the previous subpath -} - -void QQuickContext2D::moveTo( qreal x, qreal y) -{ - //FIXME: moveTo should not close the previous subpath - m_path.moveTo(state.matrix.map(QPointF(x, y))); -} - -void QQuickContext2D::lineTo( qreal x, qreal y) -{ - m_path.lineTo(state.matrix.map(QPointF(x, y))); -} - -void QQuickContext2D::quadraticCurveTo(qreal cpx, qreal cpy, - qreal x, qreal y) -{ - m_path.quadTo(state.matrix.map(QPointF(cpx, cpy)), - state.matrix.map(QPointF(x, y))); -} - -void QQuickContext2D::bezierCurveTo(qreal cp1x, qreal cp1y, - qreal cp2x, qreal cp2y, - qreal x, qreal y) -{ - m_path.cubicTo(state.matrix.map(QPointF(cp1x, cp1y)), - state.matrix.map(QPointF(cp2x, cp2y)), - state.matrix.map(QPointF(x, y))); -} - -void QQuickContext2D::addArcTo(const QPointF& p1, const QPointF& p2, float radius) -{ - QPointF p0(m_path.currentPosition()); - - QPointF p1p0((p0.x() - p1.x()), (p0.y() - p1.y())); - QPointF p1p2((p2.x() - p1.x()), (p2.y() - p1.y())); - float p1p0_length = qSqrt(p1p0.x() * p1p0.x() + p1p0.y() * p1p0.y()); - float p1p2_length = qSqrt(p1p2.x() * p1p2.x() + p1p2.y() * p1p2.y()); - - double cos_phi = (p1p0.x() * p1p2.x() + p1p0.y() * p1p2.y()) / (p1p0_length * p1p2_length); - - // The points p0, p1, and p2 are on the same straight line (HTML5, 4.8.11.1.8) - // We could have used areCollinear() here, but since we're reusing - // the variables computed above later on we keep this logic. - if (qFuzzyCompare(qAbs(cos_phi), 1.0)) { - m_path.lineTo(p1); - return; - } - - float tangent = radius / tan(acos(cos_phi) / 2); - float factor_p1p0 = tangent / p1p0_length; - QPointF t_p1p0((p1.x() + factor_p1p0 * p1p0.x()), (p1.y() + factor_p1p0 * p1p0.y())); - - QPointF orth_p1p0(p1p0.y(), -p1p0.x()); - float orth_p1p0_length = sqrt(orth_p1p0.x() * orth_p1p0.x() + orth_p1p0.y() * orth_p1p0.y()); - float factor_ra = radius / orth_p1p0_length; - - // angle between orth_p1p0 and p1p2 to get the right vector orthographic to p1p0 - double cos_alpha = (orth_p1p0.x() * p1p2.x() + orth_p1p0.y() * p1p2.y()) / (orth_p1p0_length * p1p2_length); - if (cos_alpha < 0.f) - orth_p1p0 = QPointF(-orth_p1p0.x(), -orth_p1p0.y()); - - QPointF p((t_p1p0.x() + factor_ra * orth_p1p0.x()), (t_p1p0.y() + factor_ra * orth_p1p0.y())); - - // calculate angles for addArc - orth_p1p0 = QPointF(-orth_p1p0.x(), -orth_p1p0.y()); - float sa = acos(orth_p1p0.x() / orth_p1p0_length); - if (orth_p1p0.y() < 0.f) - sa = 2 * Q_PI - sa; - - // anticlockwise logic - bool anticlockwise = false; - - float factor_p1p2 = tangent / p1p2_length; - QPointF t_p1p2((p1.x() + factor_p1p2 * p1p2.x()), (p1.y() + factor_p1p2 * p1p2.y())); - QPointF orth_p1p2((t_p1p2.x() - p.x()), (t_p1p2.y() - p.y())); - float orth_p1p2_length = sqrtf(orth_p1p2.x() * orth_p1p2.x() + orth_p1p2.y() * orth_p1p2.y()); - float ea = acos(orth_p1p2.x() / orth_p1p2_length); - if (orth_p1p2.y() < 0) - ea = 2 * Q_PI - ea; - if ((sa > ea) && ((sa - ea) < Q_PI)) - anticlockwise = true; - if ((sa < ea) && ((ea - sa) > Q_PI)) - anticlockwise = true; - - arc(p.x(), p.y(), radius, sa, ea, anticlockwise, false); -} - -void QQuickContext2D::arcTo(qreal x1, qreal y1, - qreal x2, qreal y2, - qreal radius) -{ - QPointF st = state.matrix.map(QPointF(x1, y1)); - QPointF end = state.matrix.map(QPointF(x2, y2)); - - if (!m_path.elementCount()) { - m_path.moveTo(st); - } else if (st == m_path.currentPosition() || st == end || !radius) { - m_path.lineTo(st); - } else { - addArcTo(st, end, radius); - } -} - -void QQuickContext2D::rect(qreal x, qreal y, - qreal w, qreal h) -{ - m_path.addPolygon(state.matrix.map(QRectF(x, y, w, h))); -} - -void QQuickContext2D::roundedRect(qreal x, qreal y, - qreal w, qreal h, - qreal xr, qreal yr) -{ - QPainterPath path; - path.addRoundedRect(QRectF(x, y, w, h), xr, yr, Qt::AbsoluteSize); - m_path.addPath(state.matrix.map(path)); -} - -void QQuickContext2D::ellipse(qreal x, qreal y, - qreal w, qreal h) -{ - QPainterPath path; - path.addEllipse(x, y, w, h); - m_path.addPath(state.matrix.map(path)); -} - -void QQuickContext2D::text(const QString& str, qreal x, qreal y) -{ - QPainterPath path; - path.addText(x, y, state.font, str); - m_path.addPath(state.matrix.map(path)); -} - -void QQuickContext2D::arc(qreal xc, - qreal yc, - qreal radius, - qreal sar, - qreal ear, - bool antiClockWise, - bool transform) -{ - - if (transform) { - QPointF point = state.matrix.map(QPointF(xc, yc)); - xc = point.x(); - yc = point.y(); - } - //### HACK - - // In Qt we don't switch the coordinate system for degrees - // and still use the 0,0 as bottom left for degrees so we need - // to switch - sar = -sar; - ear = -ear; - antiClockWise = !antiClockWise; - //end hack - - float sa = DEGREES(sar); - float ea = DEGREES(ear); - - double span = 0; - - double xs = xc - radius; - double ys = yc - radius; - double width = radius*2; - double height = radius*2; - if ((!antiClockWise && (ea - sa >= 360)) || (antiClockWise && (sa - ea >= 360))) - // If the anticlockwise argument is false and endAngle-startAngle is equal to or greater than 2*PI, or, if the - // anticlockwise argument is true and startAngle-endAngle is equal to or greater than 2*PI, then the arc is the whole - // circumference of this circle. - span = 360; - else { - if (!antiClockWise && (ea < sa)) { - span += 360; - } else if (antiClockWise && (sa < ea)) { - span -= 360; - } - //### this is also due to switched coordinate system - // we would end up with a 0 span instead of 360 - if (!(qFuzzyCompare(span + (ea - sa) + 1, 1) && - qFuzzyCompare(qAbs(span), 360))) { - span += ea - sa; - } - if (!m_path.elementCount()) - m_path.moveTo(xs, ys); - } - - - if (transform) { - QPointF currentPos = m_path.currentPosition(); - QPointF startPos = QPointF(xc + radius * qCos(sar), - yc - radius * qSin(sar)); - if (currentPos != startPos) - m_path.lineTo(startPos); - } - - m_path.arcTo(xs, ys, width, height, sa, span); -} - -int baseLineOffset(QQuickContext2D::TextBaseLineType value, const QFontMetrics &metrics) -{ - int offset = 0; - switch (value) { - case QQuickContext2D::Top: - break; - case QQuickContext2D::Alphabetic: - case QQuickContext2D::Middle: - case QQuickContext2D::Hanging: - offset = metrics.ascent(); - break; - case QQuickContext2D::Bottom: - offset = metrics.height(); - break; - } - return offset; -} - -static int textAlignOffset(QQuickContext2D::TextAlignType value, const QFontMetrics &metrics, const QString &text) -{ - int offset = 0; - if (value == QQuickContext2D::Start) - value = QGuiApplication::layoutDirection() == Qt::LeftToRight ? QQuickContext2D::Left : QQuickContext2D::Right; - else if (value == QQuickContext2D::End) - value = QGuiApplication::layoutDirection() == Qt::LeftToRight ? QQuickContext2D::Right: QQuickContext2D::Left; - switch (value) { - case QQuickContext2D::Center: - offset = metrics.width(text)/2; - break; - case QQuickContext2D::Right: - offset = metrics.width(text); - case QQuickContext2D::Left: - default: - break; - } - return offset; -} - - -QImage QQuickContext2D::createImage(const QUrl& url) -{ - return m_canvas->loadedImage(url); -} - -QPainterPath QQuickContext2D::createTextGlyphs(qreal x, qreal y, const QString& text) -{ - const QFontMetrics metrics(state.font); - int yoffset = baseLineOffset(static_cast(state.textBaseline), metrics); - int xoffset = textAlignOffset(static_cast(state.textAlign), metrics, text); - - QPainterPath textPath; - - textPath.addText(x - xoffset, y - yoffset+metrics.ascent(), state.font, text); - textPath = state.matrix.map(textPath); - return textPath; -} - - -bool QQuickContext2D::isPointInPath(qreal x, qreal y) const -{ - return m_path.contains(QPointF(x, y)); -} - -QQuickContext2D::QQuickContext2D(QQuickCanvasItem* item) - : m_canvas(item) - , m_buffer(new QQuickContext2DCommandBuffer) - , m_v8engine(0) -{ - reset(); -} - -QQuickContext2D::~QQuickContext2D() -{ - delete m_buffer; -} - -v8::Handle QQuickContext2D::v8value() const -{ - return m_v8value; -} - -QQuickContext2DEngineData::QQuickContext2DEngineData(QV8Engine *engine) -{ - v8::HandleScope handle_scope; - v8::Context::Scope scope(engine->context()); - - v8::Local ft = v8::FunctionTemplate::New(); - ft->InstanceTemplate()->SetHasExternalResource(true); - ft->PrototypeTemplate()->SetAccessor(v8::String::New("canvas"), ctx2d_canvas, 0, v8::External::Wrap(engine)); - ft->PrototypeTemplate()->Set(v8::String::New("restore"), V8FUNCTION(ctx2d_restore, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("reset"), V8FUNCTION(ctx2d_reset, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("save"), V8FUNCTION(ctx2d_save, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("rotate"), V8FUNCTION(ctx2d_rotate, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("scale"), V8FUNCTION(ctx2d_scale, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("resetTransform"), V8FUNCTION(ctx2d_resetTransform, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("setTransform"), V8FUNCTION(ctx2d_setTransform, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("transform"), V8FUNCTION(ctx2d_transform, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("translate"), V8FUNCTION(ctx2d_translate, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("shear"), V8FUNCTION(ctx2d_shear, engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("globalAlpha"), ctx2d_globalAlpha, ctx2d_globalAlpha_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("globalCompositeOperation"), ctx2d_globalCompositeOperation, ctx2d_globalCompositeOperation_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("fillRule"), ctx2d_fillRule, ctx2d_fillRule_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("fillStyle"), ctx2d_fillStyle, ctx2d_fillStyle_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("strokeStyle"), ctx2d_strokeStyle, ctx2d_strokeStyle_set, v8::External::Wrap(engine)); - ft->PrototypeTemplate()->Set(v8::String::New("createLinearGradient"), V8FUNCTION(ctx2d_createLinearGradient, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("createRadialGradient"), V8FUNCTION(ctx2d_createRadialGradient, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("createConicalGradient"), V8FUNCTION(ctx2d_createConicalGradient, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("createPattern"), V8FUNCTION(ctx2d_createPattern, engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("lineCap"), ctx2d_lineCap, ctx2d_lineCap_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("lineJoin"), ctx2d_lineJoin, ctx2d_lineJoin_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("lineWidth"), ctx2d_lineWidth, ctx2d_lineWidth_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("miterLimit"), ctx2d_miterLimit, ctx2d_miterLimit_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("shadowBlur"), ctx2d_shadowBlur, ctx2d_shadowBlur_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("shadowColor"), ctx2d_shadowColor, ctx2d_shadowColor_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("shadowOffsetX"), ctx2d_shadowOffsetX, ctx2d_shadowOffsetX_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("shadowOffsetY"), ctx2d_shadowOffsetY, ctx2d_shadowOffsetY_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("path"), ctx2d_path, ctx2d_path_set, v8::External::Wrap(engine)); - ft->PrototypeTemplate()->Set(v8::String::New("clearRect"), V8FUNCTION(ctx2d_clearRect, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("fillRect"), V8FUNCTION(ctx2d_fillRect, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("strokeRect"), V8FUNCTION(ctx2d_strokeRect, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("arc"), V8FUNCTION(ctx2d_arc, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("arcTo"), V8FUNCTION(ctx2d_arcTo, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("beginPath"), V8FUNCTION(ctx2d_beginPath, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("bezierCurveTo"), V8FUNCTION(ctx2d_bezierCurveTo, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("clip"), V8FUNCTION(ctx2d_clip, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("closePath"), V8FUNCTION(ctx2d_closePath, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("fill"), V8FUNCTION(ctx2d_fill, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("lineTo"), V8FUNCTION(ctx2d_lineTo, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("moveTo"), V8FUNCTION(ctx2d_moveTo, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("quadraticCurveTo"), V8FUNCTION(ctx2d_quadraticCurveTo, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("rect"), V8FUNCTION(ctx2d_rect, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("roundedRect"), V8FUNCTION(ctx2d_roundedRect, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("text"), V8FUNCTION(ctx2d_text, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("ellipse"), V8FUNCTION(ctx2d_ellipse, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("stroke"), V8FUNCTION(ctx2d_stroke, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("isPointInPath"), V8FUNCTION(ctx2d_isPointInPath, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("drawFocusRing"), V8FUNCTION(ctx2d_drawFocusRing, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("caretBlinkRate"), V8FUNCTION(ctx2d_caretBlinkRate, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("setCaretSelectionRect"), V8FUNCTION(ctx2d_setCaretSelectionRect, engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("font"), ctx2d_font, ctx2d_font_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("textAlign"), ctx2d_textAlign, ctx2d_textAlign_set, v8::External::Wrap(engine)); - ft->InstanceTemplate()->SetAccessor(v8::String::New("textBaseline"), ctx2d_textBaseline, ctx2d_textBaseline_set, v8::External::Wrap(engine)); - ft->PrototypeTemplate()->Set(v8::String::New("fillText"), V8FUNCTION(ctx2d_fillText, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("measureText"), V8FUNCTION(ctx2d_measureText, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("strokeText"), V8FUNCTION(ctx2d_strokeText, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("drawImage"), V8FUNCTION(ctx2d_drawImage, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("createImageData"), V8FUNCTION(ctx2d_createImageData, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("getImageData"), V8FUNCTION(ctx2d_getImageData, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("putImageData"), V8FUNCTION(ctx2d_putImageData, engine)); - - constructorContext = qPersistentNew(ft->GetFunction()); - - v8::Local ftGradient = v8::FunctionTemplate::New(); - ftGradient->InstanceTemplate()->SetHasExternalResource(true); - ftGradient->PrototypeTemplate()->Set(v8::String::New("addColorStop"), V8FUNCTION(ctx2d_gradient_addColorStop, engine)); - constructorGradient = qPersistentNew(ftGradient->GetFunction()); - - v8::Local ftPattern = v8::FunctionTemplate::New(); - ftPattern->InstanceTemplate()->SetHasExternalResource(true); - constructorPattern = qPersistentNew(ftPattern->GetFunction()); - - v8::Local ftPixelArray = v8::FunctionTemplate::New(); - ftPixelArray->InstanceTemplate()->SetHasExternalResource(true); - ftPixelArray->InstanceTemplate()->SetAccessor(v8::String::New("length"), ctx2d_pixelArray_length, 0, v8::External::Wrap(engine)); - ftPixelArray->InstanceTemplate()->SetIndexedPropertyHandler(ctx2d_pixelArray_indexed, ctx2d_pixelArray_indexed_set, 0, 0, 0, v8::External::Wrap(engine)); - constructorPixelArray = qPersistentNew(ftPixelArray->GetFunction()); - - v8::Local ftImageData = v8::FunctionTemplate::New(); - ftImageData->InstanceTemplate()->SetAccessor(v8::String::New("width"), ctx2d_imageData_width, 0, v8::External::Wrap(engine)); - ftImageData->InstanceTemplate()->SetAccessor(v8::String::New("height"), ctx2d_imageData_height, 0, v8::External::Wrap(engine)); - ftImageData->InstanceTemplate()->SetAccessor(v8::String::New("data"), ctx2d_imageData_data, 0, v8::External::Wrap(engine)); - ftImageData->PrototypeTemplate()->Set(v8::String::New("mirror"), V8FUNCTION(ctx2d_imageData_mirror, engine)); - ftImageData->PrototypeTemplate()->Set(v8::String::New("filter"), V8FUNCTION(ctx2d_imageData_filter, engine)); - ftImageData->InstanceTemplate()->SetInternalFieldCount(1); - constructorImageData = qPersistentNew(ftImageData->GetFunction()); -} - -QQuickContext2DEngineData::~QQuickContext2DEngineData() -{ - qPersistentDispose(constructorContext); - qPersistentDispose(constructorGradient); - qPersistentDispose(constructorPattern); - qPersistentDispose(constructorImageData); - qPersistentDispose(constructorPixelArray); -} - -void QQuickContext2D::popState() -{ - if (m_stateStack.isEmpty()) - return; - - QQuickContext2D::State newState = m_stateStack.pop(); - - if (state.matrix != newState.matrix) - buffer()->updateMatrix(newState.matrix); - - if (newState.globalAlpha != state.globalAlpha) - buffer()->setGlobalAlpha(newState.globalAlpha); - - if (newState.globalCompositeOperation != state.globalCompositeOperation) - buffer()->setGlobalCompositeOperation(newState.globalCompositeOperation); - - if (newState.fillStyle != state.fillStyle) - buffer()->setFillStyle(newState.fillStyle); - - if (newState.strokeStyle != state.strokeStyle) - buffer()->setStrokeStyle(newState.strokeStyle); - - if (newState.lineWidth != state.lineWidth) - buffer()->setLineWidth(newState.lineWidth); - - if (newState.lineCap != state.lineCap) - buffer()->setLineCap(newState.lineCap); - - if (newState.lineJoin != state.lineJoin) - buffer()->setLineJoin(newState.lineJoin); - - if (newState.miterLimit != state.miterLimit) - buffer()->setMiterLimit(newState.miterLimit); - - if (newState.clipPath != state.clipPath) { - buffer()->clip(newState.clipPath); - } - - if (newState.shadowBlur != state.shadowBlur) - buffer()->setShadowBlur(newState.shadowBlur); - - if (newState.shadowColor != state.shadowColor) - buffer()->setShadowColor(newState.shadowColor); - - if (newState.shadowOffsetX != state.shadowOffsetX) - buffer()->setShadowOffsetX(newState.shadowOffsetX); - - if (newState.shadowOffsetY != state.shadowOffsetY) - buffer()->setShadowOffsetY(newState.shadowOffsetY); - state = newState; -} -void QQuickContext2D::pushState() -{ - m_stateStack.push(state); -} - -void QQuickContext2D::reset() -{ - QQuickContext2D::State newState; - newState.matrix = QTransform(); - - QPainterPath defaultClipPath; - - QRect r(0, 0, m_canvas->canvasSize().width(), m_canvas->canvasSize().height()); - r = r.united(m_canvas->canvasWindow().toRect()); - defaultClipPath.addRect(r); - newState.clipPath = defaultClipPath; - newState.clipPath.setFillRule(Qt::WindingFill); - - newState.strokeStyle = QColor("#000000"); - newState.fillStyle = QColor("#000000"); - newState.fillPatternRepeatX = false; - newState.fillPatternRepeatY = false; - newState.strokePatternRepeatX = false; - newState.strokePatternRepeatY = false; - newState.fillRule = Qt::WindingFill; - newState.globalAlpha = 1.0; - newState.lineWidth = 1; - newState.lineCap = Qt::FlatCap; - newState.lineJoin = Qt::MiterJoin; - newState.miterLimit = 10; - newState.shadowOffsetX = 0; - newState.shadowOffsetY = 0; - newState.shadowBlur = 0; - newState.shadowColor = qRgba(0, 0, 0, 0); - newState.globalCompositeOperation = QPainter::CompositionMode_SourceOver; - newState.font = QFont(QLatin1String("sans-serif"), 10); - newState.textAlign = QQuickContext2D::Start; - newState.textBaseline = QQuickContext2D::Alphabetic; - - m_stateStack.clear(); - m_stateStack.push(newState); - popState(); - m_buffer->clearRect(0, 0, m_canvas->width(), m_canvas->height()); -} - -void QQuickContext2D::setV8Engine(QV8Engine *engine) -{ - v8::HandleScope handle_scope; - v8::Context::Scope scope(engine->context()); - - if (m_v8engine != engine) { - m_v8engine = engine; - - qPersistentDispose(m_v8value); - - if (m_v8engine == 0) - return; - - QQuickContext2DEngineData *ed = engineData(engine); - m_v8value = qPersistentNew(ed->constructorContext->NewInstance()); - QV8Context2DResource *r = new QV8Context2DResource(engine); - r->context = this; - m_v8value->SetExternalResource(r); - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/context2d/qquickcontext2d_p.h b/src/declarative/items/context2d/qquickcontext2d_p.h deleted file mode 100644 index c5634d2b18..0000000000 --- a/src/declarative/items/context2d/qquickcontext2d_p.h +++ /dev/null @@ -1,211 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKCONTEXT2D_P_H -#define QQUICKCONTEXT2D_P_H - -#include -#include - -#include -#include -#include -#include -#include - - - -#define QQUICKCONTEXT2D_DEBUG //enable this for just DEBUG purpose! - -#ifdef QQUICKCONTEXT2D_DEBUG -#include -#endif - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickCanvasItem; -class QQuickContext2DCommandBuffer; -class QDeclarativePixmap; - -class Q_DECLARATIVE_EXPORT QQuickContext2D -{ -public: - enum TextBaseLineType { Alphabetic=0, Top, Middle, Bottom, Hanging}; - enum TextAlignType { Start=0, End, Left, Right, Center}; - enum PaintCommand { - Invalid = 0, - UpdateMatrix, - ClearRect, - FillRect, - StrokeRect, - Fill, - Stroke, - Clip, - UpdateBrush, - GlobalAlpha, - GlobalCompositeOperation, - StrokeStyle, - FillStyle, - LineWidth, - LineCap, - LineJoin, - MiterLimit, - ShadowOffsetX, - ShadowOffsetY, - ShadowBlur, - ShadowColor, - Font, - TextBaseline, - TextAlign, - FillText, - StrokeText, - DrawImage, - GetImageData - }; - - - struct State { - State() - : strokeStyle(QColor("#000000")) - , fillStyle(QColor("#000000")) - , fillPatternRepeatX(false) - , fillPatternRepeatY(false) - , strokePatternRepeatX(false) - , strokePatternRepeatY(false) - , fillRule(Qt::WindingFill) - , globalAlpha(1.0) - , lineWidth(1) - , lineCap(Qt::FlatCap) - , lineJoin(Qt::MiterJoin) - , miterLimit(10) - , shadowOffsetX(0) - , shadowOffsetY(0) - , shadowBlur(0) - , shadowColor(qRgba(0, 0, 0, 0)) - , globalCompositeOperation(QPainter::CompositionMode_SourceOver) - , font(QFont(QLatin1String("sans-serif"), 10)) - , textAlign(QQuickContext2D::Start) - , textBaseline(QQuickContext2D::Alphabetic) - { - } - - QTransform matrix; - QPainterPath clipPath; - QBrush strokeStyle; - QBrush fillStyle; - bool fillPatternRepeatX:1; - bool fillPatternRepeatY:1; - bool strokePatternRepeatX:1; - bool strokePatternRepeatY:1; - Qt::FillRule fillRule; - qreal globalAlpha; - qreal lineWidth; - Qt::PenCapStyle lineCap; - Qt::PenJoinStyle lineJoin; - qreal miterLimit; - qreal shadowOffsetX; - qreal shadowOffsetY; - qreal shadowBlur; - QColor shadowColor; - QPainter::CompositionMode globalCompositeOperation; - QFont font; - QQuickContext2D::TextAlignType textAlign; - QQuickContext2D::TextBaseLineType textBaseline; - }; - - QQuickContext2D(QQuickCanvasItem* item); - ~QQuickContext2D(); - - inline QQuickCanvasItem* canvas() const {return m_canvas;} - inline QQuickContext2DCommandBuffer* buffer() const {return m_buffer;} - - v8::Handle v8value() const; - void setV8Engine(QV8Engine *eng); - void popState(); - void pushState(); - void reset(); - - // path API - void beginPath(); - void closePath(); - void moveTo(qreal x, qreal y); - void lineTo(qreal x, qreal y); - void quadraticCurveTo(qreal cpx, qreal cpy, qreal x, qreal y); - void bezierCurveTo(qreal cp1x, qreal cp1y, - qreal cp2x, qreal cp2y, qreal x, qreal y); - void arcTo(qreal x1, qreal y1, qreal x2, qreal y2, qreal radius); - void rect(qreal x, qreal y, qreal w, qreal h); - void roundedRect(qreal x, qreal y,qreal w, qreal h, qreal xr, qreal yr); - void ellipse(qreal x, qreal y,qreal w, qreal h); - void text(const QString& str, qreal x, qreal y); - void arc(qreal x, qreal y, qreal radius, - qreal startAngle, qreal endAngle, - bool anticlockwise, bool transform=true); - void addArcTo(const QPointF& p1, const QPointF& p2, float radius); - - bool isPointInPath(qreal x, qreal y) const; - - QPainterPath createTextGlyphs(qreal x, qreal y, const QString& text); - QImage createImage(const QUrl& url); - - State state; - QStack m_stateStack; - QQuickCanvasItem* m_canvas; - QQuickContext2DCommandBuffer* m_buffer; - QPainterPath m_path; - v8::Local m_fillStyle; - v8::Local m_strokeStyle; - v8::Handle m_v8path; - QV8Engine *m_v8engine; - v8::Persistent m_v8value; -}; - - -QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickContext2D) - -QT_END_HEADER - -#endif // QQUICKCONTEXT2D_P_H diff --git a/src/declarative/items/context2d/qquickcontext2dcommandbuffer.cpp b/src/declarative/items/context2d/qquickcontext2dcommandbuffer.cpp deleted file mode 100644 index 476e7e2cf8..0000000000 --- a/src/declarative/items/context2d/qquickcontext2dcommandbuffer.cpp +++ /dev/null @@ -1,469 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qquickcontext2dcommandbuffer_p.h" -#include "qquickcanvasitem_p.h" -#include -#include - -#define HAS_SHADOW(offsetX, offsetY, blur, color) (color.isValid() && color.alpha() && (blur || offsetX || offsetY)) - -QT_BEGIN_NAMESPACE - -void qt_image_boxblur(QImage& image, int radius, bool quality); - -static QImage makeShadowImage(const QImage& image, qreal offsetX, qreal offsetY, qreal blur, const QColor& color) -{ - QImage shadowImg(image.width() + blur + qAbs(offsetX), - image.height() + blur + qAbs(offsetY), - QImage::Format_ARGB32_Premultiplied); - shadowImg.fill(0); - QPainter tmpPainter(&shadowImg); - tmpPainter.setCompositionMode(QPainter::CompositionMode_Source); - qreal shadowX = offsetX > 0? offsetX : 0; - qreal shadowY = offsetY > 0? offsetY : 0; - - tmpPainter.drawImage(shadowX, shadowY, image); - tmpPainter.end(); - - if (blur > 0) - qt_image_boxblur(shadowImg, blur/2, true); - - // blacken the image with shadow color... - tmpPainter.begin(&shadowImg); - tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); - tmpPainter.fillRect(shadowImg.rect(), color); - tmpPainter.end(); - return shadowImg; -} - -static void fillRectShadow(QPainter* p, QRectF shadowRect, qreal offsetX, qreal offsetY, qreal blur, const QColor& color) -{ - QRectF r = shadowRect; - r.moveTo(0, 0); - - QImage shadowImage(r.size().width() + 1, r.size().height() + 1, QImage::Format_ARGB32_Premultiplied); - QPainter tp; - tp.begin(&shadowImage); - tp.fillRect(r, p->brush()); - tp.end(); - shadowImage = makeShadowImage(shadowImage, offsetX, offsetY, blur, color); - - qreal dx = shadowRect.left() + (offsetX < 0? offsetX:0); - qreal dy = shadowRect.top() + (offsetY < 0? offsetY:0); - - p->drawImage(dx, dy, shadowImage); - p->fillRect(shadowRect, p->brush()); -} - -static void fillShadowPath(QPainter* p, const QPainterPath& path, qreal offsetX, qreal offsetY, qreal blur, const QColor& color) -{ - QRectF r = path.boundingRect(); - QImage img(r.size().width() + r.left() + 1, - r.size().height() + r.top() + 1, - QImage::Format_ARGB32_Premultiplied); - img.fill(0); - QPainter tp(&img); - tp.fillPath(path.translated(0, 0), p->brush()); - tp.end(); - - QImage shadowImage = makeShadowImage(img, offsetX, offsetY, blur, color); - qreal dx = r.left() + (offsetX < 0? offsetX:0); - qreal dy = r.top() + (offsetY < 0? offsetY:0); - - p->drawImage(dx, dy, shadowImage); - p->fillPath(path, p->brush()); -} - -static void strokeShadowPath(QPainter* p, const QPainterPath& path, qreal offsetX, qreal offsetY, qreal blur, const QColor& color) -{ - QRectF r = path.boundingRect(); - QImage img(r.size().width() + r.left() + 1, - r.size().height() + r.top() + 1, - QImage::Format_ARGB32_Premultiplied); - img.fill(0); - QPainter tp(&img); - tp.strokePath(path, p->pen()); - tp.end(); - - QImage shadowImage = makeShadowImage(img, offsetX, offsetY, blur, color); - qreal dx = r.left() + (offsetX < 0? offsetX:0); - qreal dy = r.top() + (offsetY < 0? offsetY:0); - p->drawImage(dx, dy, shadowImage); - p->strokePath(path, p->pen()); -} -static inline void drawRepeatPattern(QPainter* p, const QImage& image, const QRectF& rect, const bool repeatX, const bool repeatY) -{ - // Patterns must be painted so that the top left of the first image is anchored at - // the origin of the coordinate space - if (!image.isNull()) { - int w = image.width(); - int h = image.height(); - int startX, startY; - QRect r(static_cast(rect.x()), static_cast(rect.y()), static_cast(rect.width()), static_cast(rect.height())); - - // startX, startY is the coordinate of the first image we need to put on the left-top of the rect - if (repeatX && repeatY) { - // repeat - // startX, startY is at the left top side of the left-top of the rect - startX = r.x() >=0 ? r.x() - (r.x() % w) : r.x() - (w - qAbs(r.x()) % w); - startY = r.y() >=0 ? r.y() - (r.y() % h) : r.y() - (h - qAbs(r.y()) % h); - } else { - if (!repeatX && !repeatY) { - // no-repeat - // only draw the image once at orgin once, check if need to draw - QRect imageRect(0, 0, w, h); - if (imageRect.intersects(r)) { - startX = 0; - startY = 0; - } else - return; - } else if (repeatX && !repeatY) { - // repeat-x - // startY is fixed, but startX change based on the left-top of the rect - QRect imageRect(r.x(), 0, r.width(), h); - if (imageRect.intersects(r)) { - startX = r.x() >=0 ? r.x() - (r.x() % w) : r.x() - (w - qAbs(r.x()) % w); - startY = 0; - } else - return; - } else { - // repeat-y - // startX is fixed, but startY change based on the left-top of the rect - QRect imageRect(0, r.y(), w, r.height()); - if (imageRect.intersects(r)) { - startX = 0; - startY = r.y() >=0 ? r.y() - (r.y() % h) : r.y() - (h - qAbs(r.y()) % h); - } else - return; - } - } - - int x = startX; - int y = startY; - do { - // repeat Y - do { - // repeat X - QRect imageRect(x, y, w, h); - QRect intersectRect = imageRect.intersected(r); - QPoint destStart(intersectRect.x(), intersectRect.y()); - QRect sourceRect(intersectRect.x() - imageRect.x(), intersectRect.y() - imageRect.y(), intersectRect.width(), intersectRect.height()); - - p->drawImage(destStart, image, sourceRect); - x += w; - } while (repeatX && x < r.x() + r.width()); - x = startX; - y += h; - } while (repeatY && y < r.y() + r.height()); - } -} - -QPen QQuickContext2DCommandBuffer::makePen(const QQuickContext2D::State& state) -{ - QPen pen; - pen.setWidthF(state.lineWidth); - pen.setCapStyle(state.lineCap); - pen.setJoinStyle(state.lineJoin); - pen.setMiterLimit(state.miterLimit); - pen.setBrush(state.strokeStyle); - return pen; -} - -void QQuickContext2DCommandBuffer::setPainterState(QPainter* p, const QQuickContext2D::State& state, const QPen& pen) -{ - p->setTransform(state.matrix * p->transform()); - - if (pen != p->pen()) - p->setPen(pen); - - if (state.fillStyle != p->brush()) - p->setBrush(state.fillStyle); - - if (state.font != p->font()) - p->setFont(state.font); - - if (state.globalAlpha != p->opacity()) { - p->setOpacity(state.globalAlpha); - } - - if (state.globalCompositeOperation != p->compositionMode()) - p->setCompositionMode(state.globalCompositeOperation); -} - -void QQuickContext2DCommandBuffer::replay(QPainter* p, QQuickContext2D::State& state) -{ - if (!p) - return; - - reset(); - - QTransform originMatrix = p->transform(); - - QPen pen = makePen(state); - setPainterState(p, state, pen); - - while (hasNext()) { - QQuickContext2D::PaintCommand cmd = takeNextCommand(); - switch (cmd) { - case QQuickContext2D::UpdateMatrix: - { - state.matrix = takeMatrix(); - p->setTransform(state.matrix * originMatrix); - break; - } - case QQuickContext2D::ClearRect: - { - QPainter::CompositionMode cm = p->compositionMode(); - qreal alpha = p->opacity(); - p->setCompositionMode(QPainter::CompositionMode_Source); - p->setOpacity(0); - p->fillRect(takeRect(), QColor(qRgba(0, 0, 0, 0))); - p->setCompositionMode(cm); - p->setOpacity(alpha); - break; - } - case QQuickContext2D::FillRect: - { - QRectF r = takeRect(); - if (HAS_SHADOW(state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor)) - fillRectShadow(p, r, state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); - else - p->fillRect(r, p->brush()); - break; - } - case QQuickContext2D::ShadowColor: - { - state.shadowColor = takeColor(); - break; - } - case QQuickContext2D::ShadowBlur: - { - state.shadowBlur = takeShadowBlur(); - break; - } - case QQuickContext2D::ShadowOffsetX: - { - state.shadowOffsetX = takeShadowOffsetX(); - break; - } - case QQuickContext2D::ShadowOffsetY: - { - state.shadowOffsetY = takeShadowOffsetY(); - break; - } - case QQuickContext2D::FillStyle: - { - state.fillStyle = takeFillStyle(); - state.fillPatternRepeatX = takeBool(); - state.fillPatternRepeatY = takeBool(); - p->setBrush(state.fillStyle); - break; - } - case QQuickContext2D::StrokeStyle: - { - state.strokeStyle = takeStrokeStyle(); - state.strokePatternRepeatX = takeBool(); - state.strokePatternRepeatY = takeBool(); - pen.setBrush(state.strokeStyle); - p->setPen(pen); - break; - } - case QQuickContext2D::LineWidth: - { - state.lineWidth = takeLineWidth(); - pen.setWidth(state.lineWidth); - p->setPen(pen); - break; - } - case QQuickContext2D::LineCap: - { - state.lineCap = takeLineCap(); - pen.setCapStyle(state.lineCap); - p->setPen(pen); - break; - } - case QQuickContext2D::LineJoin: - { - state.lineJoin = takeLineJoin(); - pen.setJoinStyle(state.lineJoin); - p->setPen(pen); - break; - } - case QQuickContext2D::MiterLimit: - { - state.miterLimit = takeMiterLimit(); - pen.setMiterLimit(state.miterLimit); - p->setPen(pen); - break; - } - case QQuickContext2D::TextAlign: - case QQuickContext2D::TextBaseline: - break; - case QQuickContext2D::Fill: - { - QPainterPath path = takePath(); - path.closeSubpath(); - if (HAS_SHADOW(state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor)) - fillShadowPath(p,path, state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); - else - p->fillPath(path, p->brush()); - break; - } - case QQuickContext2D::Stroke: - { - if (HAS_SHADOW(state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor)) - strokeShadowPath(p,takePath(), state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); - else - p->strokePath(takePath(), p->pen()); - break; - } - case QQuickContext2D::Clip: - { - state.clipPath = takePath(); - p->setClipping(true); - p->setClipPath(state.clipPath); - break; - } - case QQuickContext2D::GlobalAlpha: - { - state.globalAlpha = takeGlobalAlpha(); - p->setOpacity(state.globalAlpha); - break; - } - case QQuickContext2D::GlobalCompositeOperation: - { - state.globalCompositeOperation = takeGlobalCompositeOperation(); - p->setCompositionMode(state.globalCompositeOperation); - break; - } - case QQuickContext2D::DrawImage: - { - qreal sx = takeReal(); - qreal sy = takeReal(); - qreal sw = takeReal(); - qreal sh = takeReal(); - qreal dx = takeReal(); - qreal dy = takeReal(); - qreal dw = takeReal(); - qreal dh = takeReal(); - QImage image = takeImage(); - - if (!image.isNull()) { - if (sw == -1 || sh == -1) { - sw = image.width(); - sh = image.height(); - } - if (sx != 0 || sy != 0 || sw != image.width() || sh != image.height()) - image = image.copy(sx, sy, sw, sh); - - image = image.scaled(dw, dh); - - if (HAS_SHADOW(state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor)) { - QImage shadow = makeShadowImage(image, state.shadowOffsetX, state.shadowOffsetY, state.shadowBlur, state.shadowColor); - qreal shadow_dx = dx + (state.shadowOffsetX < 0? state.shadowOffsetY:0); - qreal shadow_dy = dy + (state.shadowOffsetX < 0? state.shadowOffsetY:0); - p->drawImage(shadow_dx, shadow_dy, shadow); - } - p->drawImage(dx, dy, image); - } - break; - } - case QQuickContext2D::GetImageData: - { - //TODO: - break; - } - default: - break; - } - } - - p->end(); -} - -QQuickContext2DCommandBuffer::QQuickContext2DCommandBuffer() - : cmdIdx(0) - , intIdx(0) - , boolIdx(0) - , realIdx(0) - , colorIdx(0) - , matrixIdx(0) - , brushIdx(0) - , pathIdx(0) - , imageIdx(0) -{ -} - - -QQuickContext2DCommandBuffer::~QQuickContext2DCommandBuffer() -{ -} - -void QQuickContext2DCommandBuffer::clear() -{ - commands.clear(); - ints.clear(); - bools.clear(); - reals.clear(); - colors.clear(); - matrixes.clear(); - brushes.clear(); - pathes.clear(); - images.clear(); - reset(); -} - -void QQuickContext2DCommandBuffer::reset() -{ - cmdIdx = 0; - intIdx = 0; - boolIdx = 0; - realIdx = 0; - colorIdx = 0; - matrixIdx = 0; - brushIdx = 0; - pathIdx = 0; - imageIdx = 0; -} - -QT_END_NAMESPACE - diff --git a/src/declarative/items/context2d/qquickcontext2dcommandbuffer_p.h b/src/declarative/items/context2d/qquickcontext2dcommandbuffer_p.h deleted file mode 100644 index 7deb2fbd6e..0000000000 --- a/src/declarative/items/context2d/qquickcontext2dcommandbuffer_p.h +++ /dev/null @@ -1,268 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKCONTEXT2DCOMMANDBUFFER_P_H -#define QQUICKCONTEXT2DCOMMANDBUFFER_P_H - -#include "qquickcontext2d_p.h" -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickCanvasItem; -class QMutex; - -class QQuickContext2DCommandBuffer -{ -public: - QQuickContext2DCommandBuffer(); - ~QQuickContext2DCommandBuffer(); - void reset(); - void clear(); - inline int size() {return commands.size();} - inline bool isEmpty() const {return commands.isEmpty(); } - inline bool hasNext() const {return cmdIdx < commands.size(); } - inline QQuickContext2D::PaintCommand takeNextCommand() { return commands[cmdIdx++]; } - - inline qreal takeGlobalAlpha() { return takeReal(); } - inline QPainter::CompositionMode takeGlobalCompositeOperation(){ return static_cast(takeInt()); } - inline QBrush takeStrokeStyle() { return takeBrush(); } - inline QBrush takeFillStyle() { return takeBrush(); } - - inline qreal takeLineWidth() { return takeReal(); } - inline Qt::PenCapStyle takeLineCap() { return static_cast(takeInt());} - inline Qt::PenJoinStyle takeLineJoin(){ return static_cast(takeInt());} - inline qreal takeMiterLimit() { return takeReal(); } - - inline void setGlobalAlpha( qreal alpha) - { - commands << QQuickContext2D::GlobalAlpha; - reals << alpha; - } - - inline void setGlobalCompositeOperation(QPainter::CompositionMode cm) - { - commands << QQuickContext2D::GlobalCompositeOperation; - ints << cm; - } - - inline void setStrokeStyle(const QBrush &style, bool repeatX = false, bool repeatY = false) - { - commands << QQuickContext2D::StrokeStyle; - brushes << style; - bools << repeatX << repeatY; - } - - inline void drawImage(const QImage& image, qreal sx, qreal sy, qreal sw, qreal sh, qreal dx, qreal dy, qreal dw, qreal dh) - { - commands << QQuickContext2D::DrawImage; - images << image; - reals << sx << sy << sw << sh << dx << dy << dw << dh; - } - - inline qreal takeShadowOffsetX() { return takeReal(); } - inline qreal takeShadowOffsetY() { return takeReal(); } - inline qreal takeShadowBlur() { return takeReal(); } - inline QColor takeShadowColor() { return takeColor(); } - - - inline void updateMatrix(const QTransform& matrix) - { - commands << QQuickContext2D::UpdateMatrix; - matrixes << matrix; - } - - inline void clearRect(qreal x, qreal y, qreal w, qreal h) - { - commands << QQuickContext2D::ClearRect; - reals << x << y << w << h; - } - - inline void fillRect(qreal x, qreal y, qreal w, qreal h) - { - commands << QQuickContext2D::FillRect; - reals << x << y << w << h; - } - - inline void strokeRect(qreal x, qreal y, qreal w, qreal h) - { - QPainterPath p; - p.addRect(x, y, w, h); - - commands << QQuickContext2D::Stroke; - pathes << p; - } - - - inline void fill(const QPainterPath& path) - { - commands << QQuickContext2D::Fill; - pathes << path; - - } - - inline void stroke(const QPainterPath& path) - { - commands << QQuickContext2D::Stroke; - pathes << path; - } - - inline void clip(const QPainterPath& path) - { - commands << QQuickContext2D::Clip; - pathes << path; - } - - - - inline void setFillStyle(const QBrush &style, bool repeatX = false, bool repeatY = false) - { - commands << QQuickContext2D::FillStyle; - brushes << style; - bools << repeatX << repeatY; - } - - - inline void setLineWidth( qreal w) - { - commands << QQuickContext2D::LineWidth; - reals << w; - } - - inline void setLineCap(Qt::PenCapStyle cap) - { - commands << QQuickContext2D::LineCap; - ints << cap; - } - - inline void setLineJoin(Qt::PenJoinStyle join) - { - commands << QQuickContext2D::LineJoin; - ints << join; - } - - inline void setMiterLimit( qreal limit) - { - commands << QQuickContext2D::MiterLimit; - reals << limit; - } - - inline void setShadowOffsetX( qreal x) - { - commands << QQuickContext2D::ShadowOffsetX; - reals << x; - } - - inline void setShadowOffsetY( qreal y) - { - commands << QQuickContext2D::ShadowOffsetY; - reals << y; - } - - inline void setShadowBlur( qreal b) - { - commands << QQuickContext2D::ShadowBlur; - reals << b; - } - - inline void setShadowColor(const QColor &color) - { - commands << QQuickContext2D::ShadowColor; - colors << color; - } - - inline QTransform takeMatrix() { return matrixes[matrixIdx++]; } - - // rects - inline QRectF takeRect() { - qreal x, y, w, h; - x = takeReal(); - y = takeReal(); - w = takeReal(); - h = takeReal(); - return QRectF(x, y, w ,h); - } - - inline QPainterPath takePath() { return pathes[pathIdx++]; } - - inline const QImage& takeImage() { return images[imageIdx++]; } - - inline int takeInt() { return ints[intIdx++]; } - inline bool takeBool() {return bools[boolIdx++]; } - inline qreal takeReal() { return reals[realIdx++]; } - inline QColor takeColor() { return colors[colorIdx++]; } - inline QBrush takeBrush() { return brushes[brushIdx++]; } - - void replay(QPainter* painter, QQuickContext2D::State& state); -private: - QPen makePen(const QQuickContext2D::State& state); - void setPainterState(QPainter* painter, const QQuickContext2D::State& state, const QPen& pen); - int cmdIdx; - int intIdx; - int boolIdx; - int realIdx; - int colorIdx; - int matrixIdx; - int brushIdx; - int pathIdx; - int imageIdx; - QVector commands; - - QVector ints; - QVector bools; - QVector reals; - QVector colors; - QVector matrixes; - QVector brushes; - QVector pathes; - QVector images; -}; - -QT_END_HEADER - -QT_END_NAMESPACE - -#endif // QQUICKCONTEXT2DCOMMANDBUFFER_P_H diff --git a/src/declarative/items/context2d/qquickcontext2dnode.cpp b/src/declarative/items/context2d/qquickcontext2dnode.cpp deleted file mode 100644 index 76b50d9747..0000000000 --- a/src/declarative/items/context2d/qquickcontext2dnode.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qquickcontext2dnode_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - - -QQuickContext2DNode::QQuickContext2DNode(QQuickCanvasItem* item) - : QSGGeometryNode() - , m_item(item) - , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4) - , m_texture(0) - , m_size(1, 1) - , m_dirtyGeometry(false) - , m_dirtyTexture(false) -{ - setMaterial(&m_materialO); - setOpaqueMaterial(&m_material); - setGeometry(&m_geometry); - setFlag(UsePreprocess, true); -} - -QQuickContext2DNode::~QQuickContext2DNode() -{ - delete m_texture; -} - -void QQuickContext2DNode::setSize(const QSizeF& size) -{ - if (m_size != size) { - m_dirtyGeometry = true; - m_size = size; - } -} - -void QQuickContext2DNode::preprocess() -{ - bool doDirty = false; - QSGDynamicTexture *t = qobject_cast(m_material.texture()); - if (t) { - doDirty = t->updateTexture(); - } - if (doDirty) { - m_dirtyTexture = true; - markDirty(DirtyMaterial); - } -} -void QQuickContext2DNode::setTexture(QQuickContext2DTexture* texture) -{ - if (texture != m_texture) { - m_dirtyTexture = true; - m_texture = texture; - } -} - -void QQuickContext2DNode::update() -{ - if (m_dirtyGeometry) - updateGeometry(); - if (m_dirtyTexture) - updateTexture(); - - m_dirtyGeometry = false; - m_dirtyTexture = false; -} - -void QQuickContext2DNode::updateTexture() -{ - m_material.setTexture(m_texture); - m_materialO.setTexture(m_texture); - markDirty(DirtyMaterial); -} - -void QQuickContext2DNode::updateGeometry() -{ - QRectF source = m_texture->textureSubRect(); - QSGGeometry::updateTexturedRectGeometry(&m_geometry, - QRectF(0, 0, m_size.width(), m_size.height()), - source); - markDirty(DirtyGeometry); -} -QT_END_NAMESPACE diff --git a/src/declarative/items/context2d/qquickcontext2dnode_p.h b/src/declarative/items/context2d/qquickcontext2dnode_p.h deleted file mode 100644 index 7403acaf07..0000000000 --- a/src/declarative/items/context2d/qquickcontext2dnode_p.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKCONTEXT2DNODE_P_H -#define QQUICKCONTEXT2DNODE_P_H - -#include -#include - -#include "qquickcanvasitem_p.h" -#include "qquickcontext2dtexture_p.h" -#include "qquickcontext2d_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickContext2DNode : public QSGGeometryNode -{ -public: - QQuickContext2DNode(QQuickCanvasItem* item); - virtual ~QQuickContext2DNode(); - void setTexture(QQuickContext2DTexture* texture); - void update(); - void preprocess(); - void setSize(const QSizeF& size); -private: - void updateTexture(); - void updateGeometry(); - - QQuickCanvasItem* m_item; - QSGOpaqueTextureMaterial m_material; - QSGTextureMaterial m_materialO; - QSGGeometry m_geometry; - QQuickContext2DTexture* m_texture; - QSizeF m_size; - - bool m_dirtyGeometry; - bool m_dirtyTexture; -}; - -QT_END_HEADER - -QT_END_NAMESPACE - -#endif // QQUICKCONTEXT2DNODE_P_H diff --git a/src/declarative/items/context2d/qquickcontext2dtexture.cpp b/src/declarative/items/context2d/qquickcontext2dtexture.cpp deleted file mode 100644 index 1128fa224f..0000000000 --- a/src/declarative/items/context2d/qquickcontext2dtexture.cpp +++ /dev/null @@ -1,778 +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 QtDeclarative module 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 "qquickcontext2dtexture_p.h" -#include "qquickcontext2dtile_p.h" -#include "qquickcanvasitem_p.h" -#include -#include -#include "qquickcontext2dcommandbuffer_p.h" -#include - -#include -#include -#include - -#define QT_MINIMUM_FBO_SIZE 64 - -static inline int qt_next_power_of_two(int v) -{ - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - ++v; - return v; -} - - -Q_GLOBAL_STATIC(QThread, globalCanvasThreadRenderInstance) - - -QQuickContext2DTexture::QQuickContext2DTexture() - : QSGDynamicTexture() - , m_context(0) - , m_item(0) - , m_canvasSize(QSize(1, 1)) - , m_tileSize(QSize(1, 1)) - , m_canvasWindow(QRect(0, 0, 1, 1)) - , m_dirtyCanvas(false) - , m_dirtyTexture(false) - , m_threadRendering(false) - , m_smooth(false) - , m_tiledCanvas(false) - , m_doGrabImage(false) - , m_painting(false) -{ -} - -QQuickContext2DTexture::~QQuickContext2DTexture() -{ - clearTiles(); -} - -QSize QQuickContext2DTexture::textureSize() const -{ - return m_canvasWindow.size(); -} - -void QQuickContext2DTexture::markDirtyTexture() -{ - lock(); - m_dirtyTexture = true; - unlock(); - emit textureChanged(); -} - -bool QQuickContext2DTexture::setCanvasSize(const QSize &size) -{ - if (m_canvasSize != size) { - m_canvasSize = size; - m_dirtyCanvas = true; - return true; - } - return false; -} - -bool QQuickContext2DTexture::setTileSize(const QSize &size) -{ - if (m_tileSize != size) { - m_tileSize = size; - m_dirtyCanvas = true; - return true; - } - return false; -} - -void QQuickContext2DTexture::setSmooth(bool smooth) -{ - m_smooth = smooth; -} - -void QQuickContext2DTexture::setItem(QQuickCanvasItem* item) -{ - if (!item) { - lock(); - m_item = 0; - m_context = 0; - unlock(); - wake(); - } else if (m_item != item) { - lock(); - m_item = item; - m_context = item->context(); - m_state = m_context->state; - unlock(); - connect(this, SIGNAL(textureChanged()), m_item, SIGNAL(painted())); - } -} - -bool QQuickContext2DTexture::setCanvasWindow(const QRect& r) -{ - if (m_canvasWindow != r) { - m_canvasWindow = r; - return true; - } - return false; -} - -bool QQuickContext2DTexture::setDirtyRect(const QRect &r) -{ - bool doDirty = false; - if (m_tiledCanvas) { - foreach (QQuickContext2DTile* t, m_tiles) { - bool dirty = t->rect().intersected(r).isValid(); - t->markDirty(dirty); - if (dirty) - doDirty = true; - } - } else { - doDirty = m_canvasWindow.intersected(r).isValid(); - } - return doDirty; -} - -void QQuickContext2DTexture::canvasChanged(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth) -{ - lock(); - - QSize ts = tileSize; - if (ts.width() > canvasSize.width()) - ts.setWidth(canvasSize.width()); - - if (ts.height() > canvasSize.height()) - ts.setHeight(canvasSize.height()); - - setCanvasSize(canvasSize); - setTileSize(ts); - - if (canvasSize == canvasWindow.size()) { - m_tiledCanvas = false; - m_dirtyCanvas = false; - } else { - m_tiledCanvas = true; - } - - bool doDirty = false; - if (dirtyRect.isValid()) - doDirty = setDirtyRect(dirtyRect); - - bool windowChanged = setCanvasWindow(canvasWindow); - if (windowChanged || doDirty) { - if (m_threadRendering) - QMetaObject::invokeMethod(this, "paint", Qt::QueuedConnection); - else if (supportDirectRendering()) { - QMetaObject::invokeMethod(this, "paint", Qt::DirectConnection); - } - } - - setSmooth(smooth); - unlock(); -} - -void QQuickContext2DTexture::paintWithoutTiles() -{ - QQuickContext2DCommandBuffer* ccb = m_context->buffer(); - - if (ccb->isEmpty() && m_threadRendering && !m_doGrabImage) { - lock(); - if (m_item) - QMetaObject::invokeMethod(m_item, "_doPainting", Qt::QueuedConnection, Q_ARG(QRectF, QRectF(0, 0, m_canvasSize.width(), m_canvasSize.height()))); - wait(); - unlock(); - } - if (ccb->isEmpty()) { - return; - } - - QPaintDevice* device = beginPainting(); - if (!device) { - endPainting(); - return; - } - - QPainter p; - p.begin(device); - if (m_smooth) - p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing - | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); - else - p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing - | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, false); - p.setCompositionMode(QPainter::CompositionMode_SourceOver); - ccb->replay(&p, m_state); - - ccb->clear(); - markDirtyTexture(); - endPainting(); -} - -bool QQuickContext2DTexture::canvasDestroyed() -{ - bool noCanvas = false; - lock(); - noCanvas = m_item == 0; - unlock(); - return noCanvas; -} - -void QQuickContext2DTexture::paint() -{ - if (canvasDestroyed()) - return; - - if (!m_tiledCanvas) { - paintWithoutTiles(); - } else { - lock(); - QRect tiledRegion = createTiles(m_canvasWindow.intersected(QRect(QPoint(0, 0), m_canvasSize))); - unlock(); - - if (!tiledRegion.isEmpty()) { - if (m_threadRendering && !m_doGrabImage) { - QRect dirtyRect; - - lock(); - foreach (QQuickContext2DTile* tile, m_tiles) { - if (tile->dirty()) { - if (dirtyRect.isEmpty()) - dirtyRect = tile->rect(); - else - dirtyRect |= tile->rect(); - } - } - unlock(); - - if (dirtyRect.isValid()) { - lock(); - if (m_item) - QMetaObject::invokeMethod(m_item, "_doPainting", Qt::QueuedConnection, Q_ARG(QRectF, dirtyRect)); - wait(); - unlock(); - } - } - - if (beginPainting()) { - QQuickContext2D::State oldState = m_state; - QQuickContext2DCommandBuffer* ccb = m_context->buffer(); - foreach (QQuickContext2DTile* tile, m_tiles) { - bool dirtyTile = false, dirtyCanvas = false, smooth = false; - - lock(); - dirtyTile = tile->dirty(); - smooth = m_smooth; - dirtyCanvas = m_dirtyCanvas; - unlock(); - - //canvas size or tile size may change during painting tiles - if (dirtyCanvas) { - if (m_threadRendering) - QMetaObject::invokeMethod(this, "paint", Qt::QueuedConnection); - endPainting(); - return; - } else if (dirtyTile) { - ccb->replay(tile->createPainter(smooth), oldState); - tile->drawFinished(); - lock(); - tile->markDirty(false); - unlock(); - } - - compositeTile(tile); - } - ccb->clear(); - endPainting(); - m_state = oldState; - markDirtyTexture(); - } - } - } -} - -QRect QQuickContext2DTexture::tiledRect(const QRectF& window, const QSize& tileSize) -{ - if (window.isEmpty()) - return QRect(); - - const int tw = tileSize.width(); - const int th = tileSize.height(); - const int h1 = window.left() / tw; - const int v1 = window.top() / th; - - const int htiles = ((window.right() - h1 * tw) + tw - 1)/tw; - const int vtiles = ((window.bottom() - v1 * th) + th - 1)/th; - - return QRect(h1 * tw, v1 * th, htiles * tw, vtiles * th); -} - -QRect QQuickContext2DTexture::createTiles(const QRect& window) -{ - QList oldTiles = m_tiles; - m_tiles.clear(); - - if (window.isEmpty()) { - m_dirtyCanvas = false; - return QRect(); - } - - QRect r = tiledRect(window, m_tileSize); - - const int tw = m_tileSize.width(); - const int th = m_tileSize.height(); - const int h1 = window.left() / tw; - const int v1 = window.top() / th; - - - const int htiles = r.width() / tw; - const int vtiles = r.height() / th; - - for (int yy = 0; yy < vtiles; ++yy) { - for (int xx = 0; xx < htiles; ++xx) { - int ht = xx + h1; - int vt = yy + v1; - - QQuickContext2DTile* tile = 0; - - QPoint pos(ht * tw, vt * th); - QRect rect(pos, m_tileSize); - - for (int i = 0; i < oldTiles.size(); i++) { - if (oldTiles[i]->rect() == rect) { - tile = oldTiles.takeAt(i); - break; - } - } - - if (!tile) - tile = createTile(); - - tile->setRect(rect); - m_tiles.append(tile); - } - } - - qDeleteAll(oldTiles); - - m_dirtyCanvas = false; - return r; -} - -void QQuickContext2DTexture::clearTiles() -{ - qDeleteAll(m_tiles); - m_tiles.clear(); -} - -QQuickContext2DFBOTexture::QQuickContext2DFBOTexture() - : QQuickContext2DTexture() - , m_fbo(0) - , m_multisampledFbo(0) - , m_paint_device(0) -{ - m_threadRendering = false; -} - -QQuickContext2DFBOTexture::~QQuickContext2DFBOTexture() -{ - delete m_fbo; - delete m_multisampledFbo; - delete m_paint_device; -} - -bool QQuickContext2DFBOTexture::setCanvasSize(const QSize &size) -{ - QSize s = QSize(qMax(QT_MINIMUM_FBO_SIZE, qt_next_power_of_two(size.width())) - , qMax(QT_MINIMUM_FBO_SIZE, qt_next_power_of_two(size.height()))); - - if (m_canvasSize != s) { - m_canvasSize = s; - m_dirtyCanvas = true; - return true; - } - return false; -} - -bool QQuickContext2DFBOTexture::setTileSize(const QSize &size) -{ - QSize s = QSize(qMax(QT_MINIMUM_FBO_SIZE, qt_next_power_of_two(size.width())) - , qMax(QT_MINIMUM_FBO_SIZE, qt_next_power_of_two(size.height()))); - if (m_tileSize != s) { - m_tileSize = s; - m_dirtyCanvas = true; - return true; - } - return false; -} - -bool QQuickContext2DFBOTexture::setCanvasWindow(const QRect& canvasWindow) -{ - QSize s = QSize(qMax(QT_MINIMUM_FBO_SIZE, qt_next_power_of_two(canvasWindow.size().width())) - , qMax(QT_MINIMUM_FBO_SIZE, qt_next_power_of_two(canvasWindow.size().height()))); - - - bool doChanged = false; - if (m_fboSize != s) { - m_fboSize = s; - doChanged = true; - } - - if (m_canvasWindow != canvasWindow) - m_canvasWindow = canvasWindow; - - return doChanged; -} - -void QQuickContext2DFBOTexture::bind() -{ - glBindTexture(GL_TEXTURE_2D, textureId()); - updateBindOptions(); -} - -QRectF QQuickContext2DFBOTexture::textureSubRect() const -{ - return QRectF(0 - , 0 - , qreal(m_canvasWindow.width()) / m_fboSize.width() - , qreal(m_canvasWindow.height()) / m_fboSize.height()); -} - - -int QQuickContext2DFBOTexture::textureId() const -{ - return m_fbo? m_fbo->texture() : 0; -} - - -bool QQuickContext2DFBOTexture::updateTexture() -{ - if (!m_context->buffer()->isEmpty()) { - paint(); - } - - bool textureUpdated = m_dirtyTexture; - - m_dirtyTexture = false; - - if (m_doGrabImage) { - grabImage(); - m_condition.wakeOne(); - m_doGrabImage = false; - } - return textureUpdated; -} - -QQuickContext2DTile* QQuickContext2DFBOTexture::createTile() const -{ - return new QQuickContext2DFBOTile(); -} - -void QQuickContext2DFBOTexture::grabImage() -{ - if (m_fbo) { - m_grabedImage = m_fbo->toImage(); - } -} - -bool QQuickContext2DFBOTexture::doMultisampling() const -{ - static bool extensionsChecked = false; - static bool multisamplingSupported = false; - - if (!extensionsChecked) { - QList extensions = QByteArray((const char *)glGetString(GL_EXTENSIONS)).split(' '); - multisamplingSupported = extensions.contains("GL_EXT_framebuffer_multisample") - && extensions.contains("GL_EXT_framebuffer_blit"); - extensionsChecked = true; - } - - return multisamplingSupported && m_smooth; -} - -QImage QQuickContext2DFBOTexture::toImage(const QRectF& region) -{ -#define QML_CONTEXT2D_WAIT_MAX 5000 - - m_doGrabImage = true; - if (m_item) - m_item->update(); - - QImage grabbed; - m_mutex.lock(); - bool ok = m_condition.wait(&m_mutex, QML_CONTEXT2D_WAIT_MAX); - - if (!ok) - grabbed = QImage(); - - if (region.isValid()) - grabbed = m_grabedImage.copy(region.toRect()); - else - grabbed = m_grabedImage; - m_grabedImage = QImage(); - return grabbed; -} - -void QQuickContext2DFBOTexture::compositeTile(QQuickContext2DTile* tile) -{ - QQuickContext2DFBOTile* t = static_cast(tile); - QRect target = t->rect().intersect(m_canvasWindow); - if (target.isValid()) { - QRect source = target; - - source.moveTo(source.topLeft() - t->rect().topLeft()); - target.moveTo(target.topLeft() - m_canvasWindow.topLeft()); - - QOpenGLFramebufferObject::blitFramebuffer(m_fbo, target, t->fbo(), source); - } -} -QQuickCanvasItem::RenderTarget QQuickContext2DFBOTexture::renderTarget() const -{ - return QQuickCanvasItem::FramebufferObject; -} -QPaintDevice* QQuickContext2DFBOTexture::beginPainting() -{ - QQuickContext2DTexture::beginPainting(); - - if (m_canvasWindow.size().isEmpty() && !m_threadRendering) { - delete m_fbo; - delete m_multisampledFbo; - m_fbo = 0; - m_multisampledFbo = 0; - return 0; - } else if (!m_fbo || m_fbo->size() != m_fboSize) { - delete m_fbo; - delete m_multisampledFbo; - if (doMultisampling()) { - { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - format.setSamples(8); - m_multisampledFbo = new QOpenGLFramebufferObject(m_fboSize, format); - } - { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::NoAttachment); - m_fbo = new QOpenGLFramebufferObject(m_fboSize, format); - } - } else { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - - m_fbo = new QOpenGLFramebufferObject(m_fboSize, format); - } - } - - if (doMultisampling()) - m_multisampledFbo->bind(); - else - m_fbo->bind(); - - - if (!m_paint_device) { - QOpenGLPaintDevice *gl_device = new QOpenGLPaintDevice(m_fbo->size()); - gl_device->setPaintFlipped(true); - m_paint_device = gl_device; - } - - return m_paint_device; -} - -void QQuickContext2DFBOTexture::endPainting() -{ - QQuickContext2DTexture::endPainting(); - if (m_multisampledFbo) { - QOpenGLFramebufferObject::blitFramebuffer(m_fbo, m_multisampledFbo); - m_multisampledFbo->release(); - } else if (m_fbo) - m_fbo->release(); -} -void qt_quit_context2d_render_thread() -{ - QThread* thread = globalCanvasThreadRenderInstance(); - - if (thread->isRunning()) { - thread->exit(0); - thread->wait(1000); - } -} - -QQuickContext2DImageTexture::QQuickContext2DImageTexture(bool threadRendering) - : QQuickContext2DTexture() - , m_texture(new QSGPlainTexture()) -{ - m_texture->setOwnsTexture(true); - m_texture->setHasMipmaps(false); - - m_threadRendering = threadRendering; - - if (m_threadRendering) { - QThread* thread = globalCanvasThreadRenderInstance(); - moveToThread(thread); - - if (!thread->isRunning()) { - qAddPostRoutine(qt_quit_context2d_render_thread); - thread->start(); - } - } -} - -QQuickContext2DImageTexture::~QQuickContext2DImageTexture() -{ - delete m_texture; -} - -int QQuickContext2DImageTexture::textureId() const -{ - return m_texture->textureId(); -} - -void QQuickContext2DImageTexture::lock() -{ - if (m_threadRendering) - m_mutex.lock(); -} -void QQuickContext2DImageTexture::unlock() -{ - if (m_threadRendering) - m_mutex.unlock(); -} - -void QQuickContext2DImageTexture::wait() -{ - if (m_threadRendering) - m_waitCondition.wait(&m_mutex); -} - -void QQuickContext2DImageTexture::wake() -{ - if (m_threadRendering) - m_waitCondition.wakeOne(); -} - -bool QQuickContext2DImageTexture::supportDirectRendering() const -{ - return !m_threadRendering; -} - -QQuickCanvasItem::RenderTarget QQuickContext2DImageTexture::renderTarget() const -{ - return QQuickCanvasItem::Image; -} - -void QQuickContext2DImageTexture::bind() -{ - m_texture->bind(); -} - -bool QQuickContext2DImageTexture::updateTexture() -{ - lock(); - bool textureUpdated = m_dirtyTexture; - if (m_dirtyTexture) { - m_texture->setImage(m_image); - m_dirtyTexture = false; - } - unlock(); - return textureUpdated; -} - -QQuickContext2DTile* QQuickContext2DImageTexture::createTile() const -{ - return new QQuickContext2DImageTile(); -} - -void QQuickContext2DImageTexture::grabImage(const QRect& r) -{ - m_doGrabImage = true; - paint(); - m_doGrabImage = false; - m_grabedImage = m_image.copy(r); -} - -QImage QQuickContext2DImageTexture::toImage(const QRectF& region) -{ - QRect r = region.isValid() ? region.toRect() : QRect(QPoint(0, 0), m_canvasWindow.size()); - if (threadRendering()) { - wake(); - QMetaObject::invokeMethod(this, "grabImage", Qt::BlockingQueuedConnection, Q_ARG(QRect, r)); - } else { - QMetaObject::invokeMethod(this, "grabImage", Qt::DirectConnection, Q_ARG(QRect, r)); - } - QImage image = m_grabedImage; - m_grabedImage = QImage(); - return image; -} - -QPaintDevice* QQuickContext2DImageTexture::beginPainting() -{ - QQuickContext2DTexture::beginPainting(); - - if (m_canvasWindow.size().isEmpty()) - return 0; - - lock(); - if (m_image.size() != m_canvasWindow.size()) { - m_image = QImage(m_canvasWindow.size(), QImage::Format_ARGB32_Premultiplied); - m_image.fill(0x00000000); - } - unlock(); - return &m_image; -} - -void QQuickContext2DImageTexture::compositeTile(QQuickContext2DTile* tile) -{ - Q_ASSERT(!tile->dirty()); - QQuickContext2DImageTile* t = static_cast(tile); - QRect target = t->rect().intersect(m_canvasWindow); - if (target.isValid()) { - QRect source = target; - source.moveTo(source.topLeft() - t->rect().topLeft()); - target.moveTo(target.topLeft() - m_canvasWindow.topLeft()); - - lock(); - m_painter.begin(&m_image); - m_painter.setCompositionMode(QPainter::CompositionMode_Source); - m_painter.drawImage(target, t->image(), source); - m_painter.end(); - unlock(); - } -} diff --git a/src/declarative/items/context2d/qquickcontext2dtexture_p.h b/src/declarative/items/context2d/qquickcontext2dtexture_p.h deleted file mode 100644 index ed45a09f7c..0000000000 --- a/src/declarative/items/context2d/qquickcontext2dtexture_p.h +++ /dev/null @@ -1,205 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKCONTEXT2DTEXTURE_P_H -#define QQUICKCONTEXT2DTEXTURE_P_H - -#include -#include "qquickcanvasitem_p.h" -#include "qquickcontext2d_p.h" - -#include -#include - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickContext2DTile; -class QQuickContext2DCommandBuffer; - -class QQuickContext2DTexture : public QSGDynamicTexture -{ - Q_OBJECT -public: - QQuickContext2DTexture(); - ~QQuickContext2DTexture(); - - virtual bool hasAlphaChannel() const {return true;} - virtual bool hasMipmaps() const {return false;} - virtual QSize textureSize() const; - virtual void lock() {} - virtual void unlock() {} - virtual void wait() {} - virtual void wake() {} - bool threadRendering() const {return m_threadRendering;} - virtual bool supportThreadRendering() const = 0; - virtual bool supportDirectRendering() const = 0; - virtual QQuickCanvasItem::RenderTarget renderTarget() const = 0; - virtual QImage toImage(const QRectF& region = QRectF()) = 0; - static QRect tiledRect(const QRectF& window, const QSize& tileSize); - - virtual bool setCanvasSize(const QSize &size); - virtual bool setTileSize(const QSize &size); - virtual bool setCanvasWindow(const QRect& canvasWindow); - void setSmooth(bool smooth); - bool setDirtyRect(const QRect &dirtyRect); - virtual void canvasChanged(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth); - bool canvasDestroyed(); -Q_SIGNALS: - void textureChanged(); - -public Q_SLOTS: - void markDirtyTexture(); - void setItem(QQuickCanvasItem* item); - void paint(); - -protected: - void paintWithoutTiles(); - virtual QPaintDevice* beginPainting() {m_painting = true; return 0; } - virtual void endPainting() {m_painting = false;} - virtual QQuickContext2DTile* createTile() const = 0; - virtual void compositeTile(QQuickContext2DTile* tile) = 0; - - void clearTiles(); - QRect createTiles(const QRect& window); - - QList m_tiles; - QQuickContext2D* m_context; - - QQuickContext2D::State m_state; - - QQuickCanvasItem* m_item; - QSize m_canvasSize; - QSize m_tileSize; - QRect m_canvasWindow; - - uint m_dirtyCanvas : 1; - uint m_dirtyTexture : 1; - uint m_threadRendering : 1; - uint m_smooth : 1; - uint m_tiledCanvas : 1; - uint m_doGrabImage : 1; - uint m_painting : 1; -}; - -class QQuickContext2DFBOTexture : public QQuickContext2DTexture -{ - Q_OBJECT - -public: - QQuickContext2DFBOTexture(); - ~QQuickContext2DFBOTexture(); - virtual int textureId() const; - virtual bool updateTexture(); - virtual QQuickContext2DTile* createTile() const; - virtual QImage toImage(const QRectF& region = QRectF()); - virtual QPaintDevice* beginPainting(); - virtual void endPainting(); - QRectF textureSubRect() const; - virtual bool supportThreadRendering() const {return false;} - virtual bool supportDirectRendering() const {return false;} - virtual QQuickCanvasItem::RenderTarget renderTarget() const; - virtual void compositeTile(QQuickContext2DTile* tile); - virtual void bind(); - virtual bool setCanvasSize(const QSize &size); - virtual bool setTileSize(const QSize &size); - virtual bool setCanvasWindow(const QRect& canvasWindow); -private Q_SLOTS: - void grabImage(); - -private: - bool doMultisampling() const; - QImage m_grabedImage; - QOpenGLFramebufferObject *m_fbo; - QOpenGLFramebufferObject *m_multisampledFbo; - QMutex m_mutex; - QWaitCondition m_condition; - QSize m_fboSize; - QPaintDevice *m_paint_device; -}; - -class QSGPlainTexture; -class QQuickContext2DImageTexture : public QQuickContext2DTexture -{ - Q_OBJECT - -public: - QQuickContext2DImageTexture(bool threadRendering = true); - ~QQuickContext2DImageTexture(); - virtual int textureId() const; - virtual void bind(); - virtual bool supportThreadRendering() const {return true;} - virtual bool supportDirectRendering() const; - virtual QQuickCanvasItem::RenderTarget renderTarget() const; - virtual void lock(); - virtual void unlock(); - virtual void wait(); - virtual void wake(); - - virtual bool updateTexture(); - virtual QQuickContext2DTile* createTile() const; - virtual QImage toImage(const QRectF& region = QRectF()); - virtual QPaintDevice* beginPainting(); - virtual void compositeTile(QQuickContext2DTile* tile); - -private Q_SLOTS: - void grabImage(const QRect& r); -private: - QImage m_image; - QImage m_grabedImage; - QMutex m_mutex; - QWaitCondition m_waitCondition; - QPainter m_painter; - QSGPlainTexture* m_texture; -}; - -QT_END_HEADER - -QT_END_NAMESPACE - -#endif // QQUICKCONTEXT2DTEXTURE_P_H diff --git a/src/declarative/items/context2d/qquickcontext2dtile.cpp b/src/declarative/items/context2d/qquickcontext2dtile.cpp deleted file mode 100644 index 6217c66094..0000000000 --- a/src/declarative/items/context2d/qquickcontext2dtile.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qquickcontext2dtile_p.h" - -#include -#include -#include - -QQuickContext2DTile::QQuickContext2DTile() - : m_dirty(true) - , m_rect(QRect(0, 0, 1, 1)) - , m_device(0) -{ -} - -QQuickContext2DTile::~QQuickContext2DTile() -{ - if (m_painter.isActive()) - m_painter.end(); -} - -QPainter* QQuickContext2DTile::createPainter(bool smooth) -{ - if (m_painter.isActive()) - m_painter.end(); - - if (m_device) { - aboutToDraw(); - m_painter.begin(m_device); - m_painter.resetTransform(); - m_painter.setCompositionMode(QPainter::CompositionMode_Source); - -#ifdef QQUICKCONTEXT2D_DEBUG - int v = 100; - int gray = (m_rect.x() / m_rect.width() + m_rect.y() / m_rect.height()) % 2; - if (gray) - v = 150; - m_painter.fillRect(QRect(0, 0, m_rect.width(), m_rect.height()), QColor(v, v, v, 255)); -#endif - if (smooth) - m_painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing - | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); - else - m_painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing - | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, false); - - m_painter.setCompositionMode(QPainter::CompositionMode_SourceOver); - m_painter.translate(-m_rect.left(), -m_rect.top()); - m_painter.setClipRect(m_rect); - m_painter.setClipping(false); - return &m_painter; - } - - return 0; -} - -QQuickContext2DFBOTile::QQuickContext2DFBOTile() - : QQuickContext2DTile() - , m_fbo(0) -{ -} - - -QQuickContext2DFBOTile::~QQuickContext2DFBOTile() -{ - delete m_fbo; -} - -void QQuickContext2DFBOTile::aboutToDraw() -{ - m_fbo->bind(); - if (!m_device) { - QOpenGLPaintDevice *gl_device = new QOpenGLPaintDevice(rect().size()); - m_device = gl_device; - QPainter p(m_device); - p.fillRect(QRectF(0, 0, m_fbo->width(), m_fbo->height()), QColor(qRgba(0, 0, 0, 0))); - p.end(); - } -} - -void QQuickContext2DFBOTile::drawFinished() -{ - m_fbo->release(); -} - -void QQuickContext2DFBOTile::setRect(const QRect& r) -{ - if (m_rect == r) - return; - m_rect = r; - m_dirty = true; - if (!m_fbo || m_fbo->size() != r.size()) { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - format.setInternalTextureFormat(GL_RGBA); - format.setMipmap(false); - - if (m_painter.isActive()) - m_painter.end(); - - delete m_fbo; - m_fbo = new QOpenGLFramebufferObject(r.size(), format); - } -} - - -QQuickContext2DImageTile::QQuickContext2DImageTile() - : QQuickContext2DTile() -{ -} - -QQuickContext2DImageTile::~QQuickContext2DImageTile() -{ -} - -void QQuickContext2DImageTile::setRect(const QRect& r) -{ - if (m_rect == r) - return; - m_rect = r; - m_dirty = true; - if (m_image.size() != r.size()) { - m_image = QImage(r.size(), QImage::Format_ARGB32_Premultiplied); - } - m_device = &m_image; -} diff --git a/src/declarative/items/context2d/qquickcontext2dtile_p.h b/src/declarative/items/context2d/qquickcontext2dtile_p.h deleted file mode 100644 index 92c59efbcf..0000000000 --- a/src/declarative/items/context2d/qquickcontext2dtile_p.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKCONTEXT2DTILE_P_H -#define QQUICKCONTEXT2DTILE_P_H - -#include "qquickcontext2d_p.h" -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickContext2DTexture; -class QQuickContext2DCommandBuffer; - -class QQuickContext2DTile -{ -public: - QQuickContext2DTile(); - ~QQuickContext2DTile(); - - bool dirty() const {return m_dirty;} - void markDirty(bool dirty) {m_dirty = dirty;} - - QRect rect() const {return m_rect;} - - virtual void setRect(const QRect& r) = 0; - virtual QPainter* createPainter(bool smooth = false); - virtual void drawFinished() {} - -protected: - virtual void aboutToDraw() {} - uint m_dirty : 1; - QRect m_rect; - QPaintDevice* m_device; - QPainter m_painter; -}; - - -class QQuickContext2DFBOTile : public QQuickContext2DTile -{ -public: - QQuickContext2DFBOTile(); - ~QQuickContext2DFBOTile(); - virtual void setRect(const QRect& r); - QOpenGLFramebufferObject* fbo() const {return m_fbo;} - void drawFinished(); - -protected: - void aboutToDraw(); -private: - - - QOpenGLFramebufferObject *m_fbo; -}; - -class QQuickContext2DImageTile : public QQuickContext2DTile -{ -public: - QQuickContext2DImageTile(); - ~QQuickContext2DImageTile(); - void setRect(const QRect& r); - const QImage& image() const {return m_image;} -private: - QImage m_image; -}; -QT_END_HEADER - -QT_END_NAMESPACE - -#endif // QQUICKCONTEXT2DTILE_P_H diff --git a/src/declarative/items/items.pri b/src/declarative/items/items.pri deleted file mode 100644 index 308706f0b9..0000000000 --- a/src/declarative/items/items.pri +++ /dev/null @@ -1,131 +0,0 @@ -HEADERS += \ - $$PWD/qquickevents_p_p.h \ - $$PWD/qquickitemchangelistener_p.h \ - $$PWD/qquickanchors_p.h \ - $$PWD/qquickanchors_p_p.h \ - $$PWD/qquickitem.h \ - $$PWD/qquickitem_p.h \ - $$PWD/qquickrectangle_p.h \ - $$PWD/qquickrectangle_p_p.h \ - $$PWD/qquickcanvas.h \ - $$PWD/qquickcanvas_p.h \ - $$PWD/qquickfocusscope_p.h \ - $$PWD/qquickitemsmodule_p.h \ - $$PWD/qquickpainteditem.h \ - $$PWD/qquickpainteditem_p.h \ - $$PWD/qquicktext_p.h \ - $$PWD/qquicktext_p_p.h \ - $$PWD/qquicktextnode_p.h \ - $$PWD/qquicktextinput_p.h \ - $$PWD/qquicktextinput_p_p.h \ - $$PWD/qquicktextedit_p.h \ - $$PWD/qquicktextedit_p_p.h \ - $$PWD/qquickimagebase_p.h \ - $$PWD/qquickimagebase_p_p.h \ - $$PWD/qquickimage_p.h \ - $$PWD/qquickimage_p_p.h \ - $$PWD/qquickborderimage_p.h \ - $$PWD/qquickborderimage_p_p.h \ - $$PWD/qquickninepatchnode_p.h \ - $$PWD/qquickscalegrid_p_p.h \ - $$PWD/qquickmousearea_p.h \ - $$PWD/qquickmousearea_p_p.h \ - $$PWD/qquickpincharea_p.h \ - $$PWD/qquickpincharea_p_p.h \ - $$PWD/qquickflickable_p.h \ - $$PWD/qquickflickable_p_p.h \ - $$PWD/qquicklistview_p.h \ - $$PWD/qquickvisualadaptormodel_p.h \ - $$PWD/qquickvisualdatamodel_p.h \ - $$PWD/qquickvisualitemmodel_p.h \ - $$PWD/qquickrepeater_p.h \ - $$PWD/qquickrepeater_p_p.h \ - $$PWD/qquickgridview_p.h \ - $$PWD/qquickpathview_p.h \ - $$PWD/qquickpathview_p_p.h \ - $$PWD/qquickpositioners_p.h \ - $$PWD/qquickpositioners_p_p.h \ - $$PWD/qquickloader_p.h \ - $$PWD/qquickloader_p_p.h \ - $$PWD/qquickanimatedimage_p.h \ - $$PWD/qquickanimatedimage_p_p.h \ - $$PWD/qquickflipable_p.h \ - $$PWD/qquicktranslate_p.h \ - $$PWD/qquickclipnode_p.h \ - $$PWD/qquickview.h \ - $$PWD/qquickview_p.h \ - $$PWD/qquickanimation_p.h \ - $$PWD/qquickanimation_p_p.h \ - $$PWD/qquickstateoperations_p.h \ - $$PWD/qquickimplicitsizeitem_p.h \ - $$PWD/qquickimplicitsizeitem_p_p.h \ - $$PWD/qquickspriteengine_p.h \ - $$PWD/qquicksprite_p.h \ - $$PWD/qquickspriteimage_p.h \ - $$PWD/qquickdrag_p.h \ - $$PWD/qquickdroparea_p.h \ - $$PWD/qquickmultipointtoucharea_p.h \ - $$PWD/qquickitemview_p.h \ - $$PWD/qquickitemview_p_p.h \ - $$PWD/qquickwindowmodule_p.h - -SOURCES += \ - $$PWD/qquickevents.cpp \ - $$PWD/qquickanchors.cpp \ - $$PWD/qquickitem.cpp \ - $$PWD/qquickrectangle.cpp \ - $$PWD/qquickcanvas.cpp \ - $$PWD/qquickfocusscope.cpp \ - $$PWD/qquickitemsmodule.cpp \ - $$PWD/qquickpainteditem.cpp \ - $$PWD/qquicktext.cpp \ - $$PWD/qquicktextnode.cpp \ - $$PWD/qquicktextinput.cpp \ - $$PWD/qquicktextedit.cpp \ - $$PWD/qquickimagebase.cpp \ - $$PWD/qquickimage.cpp \ - $$PWD/qquickborderimage.cpp \ - $$PWD/qquickninepatchnode.cpp \ - $$PWD/qquickscalegrid.cpp \ - $$PWD/qquickmousearea.cpp \ - $$PWD/qquickpincharea.cpp \ - $$PWD/qquickflickable.cpp \ - $$PWD/qquicklistview.cpp \ - $$PWD/qquickvisualadaptormodel.cpp \ - $$PWD/qquickvisualdatamodel.cpp \ - $$PWD/qquickvisualitemmodel.cpp \ - $$PWD/qquickrepeater.cpp \ - $$PWD/qquickgridview.cpp \ - $$PWD/qquickpathview.cpp \ - $$PWD/qquickpositioners.cpp \ - $$PWD/qquickloader.cpp \ - $$PWD/qquickanimatedimage.cpp \ - $$PWD/qquickflipable.cpp \ - $$PWD/qquicktranslate.cpp \ - $$PWD/qquickclipnode.cpp \ - $$PWD/qquickview.cpp \ - $$PWD/qquickanimation.cpp \ - $$PWD/qquickstateoperations.cpp \ - $$PWD/qquickimplicitsizeitem.cpp \ - $$PWD/qquickspriteengine.cpp \ - $$PWD/qquicksprite.cpp \ - $$PWD/qquickspriteimage.cpp \ - $$PWD/qquickdrag.cpp \ - $$PWD/qquickdroparea.cpp \ - $$PWD/qquickmultipointtoucharea.cpp \ - $$PWD/qquickitemview.cpp \ - $$PWD/qquickwindowmodule.cpp - -SOURCES += \ - $$PWD/qquickshadereffect.cpp \ - $$PWD/qquickshadereffectmesh.cpp \ - $$PWD/qquickshadereffectnode.cpp \ - $$PWD/qquickshadereffectsource.cpp \ - -HEADERS += \ - $$PWD/qquickshadereffect_p.h \ - $$PWD/qquickshadereffectmesh_p.h \ - $$PWD/qquickshadereffectnode_p.h \ - $$PWD/qquickshadereffectsource_p.h \ - -include(context2d/context2d.pri) diff --git a/src/declarative/items/qquickanchors.cpp b/src/declarative/items/qquickanchors.cpp deleted file mode 100644 index 8ebdc374fb..0000000000 --- a/src/declarative/items/qquickanchors.cpp +++ /dev/null @@ -1,1180 +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 QtDeclarative module 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 "qquickanchors_p_p.h" - -#include "qquickitem.h" -#include "qquickitem_p.h" - -#include - -QT_BEGIN_NAMESPACE - -//TODO: should we cache relationships, so we don't have to check each time (parent-child or sibling)? -//TODO: support non-parent, non-sibling (need to find lowest common ancestor) - -static qreal hcenter(QQuickItem *item) -{ - qreal width = item->width(); - int iw = width; - if (iw % 2) - return (width + 1) / 2; - else - return width / 2; -} - -static qreal vcenter(QQuickItem *item) -{ - qreal height = item->height(); - int ih = height; - if (ih % 2) - return (height + 1) / 2; - else - return height / 2; -} - -//### const item? -//local position -static qreal position(QQuickItem *item, QQuickAnchorLine::AnchorLine anchorLine) -{ - qreal ret = 0.0; - switch (anchorLine) { - case QQuickAnchorLine::Left: - ret = item->x(); - break; - case QQuickAnchorLine::Right: - ret = item->x() + item->width(); - break; - case QQuickAnchorLine::Top: - ret = item->y(); - break; - case QQuickAnchorLine::Bottom: - ret = item->y() + item->height(); - break; - case QQuickAnchorLine::HCenter: - ret = item->x() + hcenter(item); - break; - case QQuickAnchorLine::VCenter: - ret = item->y() + vcenter(item); - break; - case QQuickAnchorLine::Baseline: - ret = item->y() + item->baselineOffset(); - break; - default: - break; - } - - return ret; -} - -//position when origin is 0,0 -static qreal adjustedPosition(QQuickItem *item, QQuickAnchorLine::AnchorLine anchorLine) -{ - qreal ret = 0.0; - switch (anchorLine) { - case QQuickAnchorLine::Left: - ret = 0.0; - break; - case QQuickAnchorLine::Right: - ret = item->width(); - break; - case QQuickAnchorLine::Top: - ret = 0.0; - break; - case QQuickAnchorLine::Bottom: - ret = item->height(); - break; - case QQuickAnchorLine::HCenter: - ret = hcenter(item); - break; - case QQuickAnchorLine::VCenter: - ret = vcenter(item); - break; - case QQuickAnchorLine::Baseline: - ret = item->baselineOffset(); - break; - default: - break; - } - - return ret; -} - -QQuickAnchors::QQuickAnchors(QQuickItem *item, QObject *parent) -: QObject(*new QQuickAnchorsPrivate(item), parent) -{ -} - -QQuickAnchors::~QQuickAnchors() -{ - Q_D(QQuickAnchors); - d->inDestructor = true; - d->remDepend(d->fill); - d->remDepend(d->centerIn); - d->remDepend(d->left.item); - d->remDepend(d->right.item); - d->remDepend(d->top.item); - d->remDepend(d->bottom.item); - d->remDepend(d->vCenter.item); - d->remDepend(d->hCenter.item); - d->remDepend(d->baseline.item); -} - -void QQuickAnchorsPrivate::fillChanged() -{ - Q_Q(QQuickAnchors); - if (!fill || !isItemComplete()) - return; - - if (updatingFill < 2) { - ++updatingFill; - - qreal horizontalMargin = q->mirrored() ? rightMargin : leftMargin; - - if (fill == item->parentItem()) { //child-parent - setItemPos(QPointF(horizontalMargin, topMargin)); - } else if (fill->parentItem() == item->parentItem()) { //siblings - setItemPos(QPointF(fill->x()+horizontalMargin, fill->y()+topMargin)); - } - setItemSize(QSizeF(fill->width()-leftMargin-rightMargin, fill->height()-topMargin-bottomMargin)); - - --updatingFill; - } else { - // ### Make this certain :) - qmlInfo(item) << QQuickAnchors::tr("Possible anchor loop detected on fill."); - } - -} - -void QQuickAnchorsPrivate::centerInChanged() -{ - Q_Q(QQuickAnchors); - if (!centerIn || fill || !isItemComplete()) - return; - - if (updatingCenterIn < 2) { - ++updatingCenterIn; - - qreal effectiveHCenterOffset = q->mirrored() ? -hCenterOffset : hCenterOffset; - if (centerIn == item->parentItem()) { - QPointF p(hcenter(item->parentItem()) - hcenter(item) + effectiveHCenterOffset, - vcenter(item->parentItem()) - vcenter(item) + vCenterOffset); - setItemPos(p); - - } else if (centerIn->parentItem() == item->parentItem()) { - QPointF p(centerIn->x() + hcenter(centerIn) - hcenter(item) + effectiveHCenterOffset, - centerIn->y() + vcenter(centerIn) - vcenter(item) + vCenterOffset); - setItemPos(p); - } - - --updatingCenterIn; - } else { - // ### Make this certain :) - qmlInfo(item) << QQuickAnchors::tr("Possible anchor loop detected on centerIn."); - } -} - -void QQuickAnchorsPrivate::clearItem(QQuickItem *item) -{ - if (!item) - return; - if (fill == item) - fill = 0; - if (centerIn == item) - centerIn = 0; - if (left.item == item) { - left.item = 0; - usedAnchors &= ~QQuickAnchors::LeftAnchor; - } - if (right.item == item) { - right.item = 0; - usedAnchors &= ~QQuickAnchors::RightAnchor; - } - if (top.item == item) { - top.item = 0; - usedAnchors &= ~QQuickAnchors::TopAnchor; - } - if (bottom.item == item) { - bottom.item = 0; - usedAnchors &= ~QQuickAnchors::BottomAnchor; - } - if (vCenter.item == item) { - vCenter.item = 0; - usedAnchors &= ~QQuickAnchors::VCenterAnchor; - } - if (hCenter.item == item) { - hCenter.item = 0; - usedAnchors &= ~QQuickAnchors::HCenterAnchor; - } - if (baseline.item == item) { - baseline.item = 0; - usedAnchors &= ~QQuickAnchors::BaselineAnchor; - } -} - -int QQuickAnchorsPrivate::calculateDependency(QQuickItem *controlItem) -{ - QQuickItemPrivate::GeometryChangeTypes dependency = QQuickItemPrivate::NoChange; - - if (!controlItem || inDestructor) - return dependency; - - if (fill == controlItem) { - if ((controlItem == item->parentItem())) - dependency |= QQuickItemPrivate::SizeChange; - else //sibling - dependency |= QQuickItemPrivate::GeometryChange; - return dependency; //exit early - } - - if (centerIn == controlItem) { - if ((controlItem == item->parentItem())) - dependency |= QQuickItemPrivate::SizeChange; - else //sibling - dependency |= QQuickItemPrivate::GeometryChange; - return dependency; //exit early - } - - if ((usedAnchors & QQuickAnchors::LeftAnchor && left.item == controlItem) || - (usedAnchors & QQuickAnchors::RightAnchor && right.item == controlItem) || - (usedAnchors & QQuickAnchors::HCenterAnchor && hCenter.item == controlItem)) { - if ((controlItem == item->parentItem())) - dependency |= QQuickItemPrivate::WidthChange; - else //sibling - dependency |= QFlags(QQuickItemPrivate::XChange | QQuickItemPrivate::WidthChange); - } - - if ((usedAnchors & QQuickAnchors::TopAnchor && top.item == controlItem) || - (usedAnchors & QQuickAnchors::BottomAnchor && bottom.item == controlItem) || - (usedAnchors & QQuickAnchors::VCenterAnchor && vCenter.item == controlItem) || - (usedAnchors & QQuickAnchors::BaselineAnchor && baseline.item == controlItem)) { - if ((controlItem == item->parentItem())) - dependency |= QQuickItemPrivate::HeightChange; - else //sibling - dependency |= QFlags(QQuickItemPrivate::YChange | QQuickItemPrivate::HeightChange); - } - - return dependency; -} - -void QQuickAnchorsPrivate::addDepend(QQuickItem *item) -{ - if (!item || !componentComplete) - return; - - QQuickItemPrivate *p = QQuickItemPrivate::get(item); - p->updateOrAddGeometryChangeListener(this, QFlags(calculateDependency(item))); -} - -void QQuickAnchorsPrivate::remDepend(QQuickItem *item) -{ - if (!item || !componentComplete) - return; - - QQuickItemPrivate *p = QQuickItemPrivate::get(item); - p->updateOrRemoveGeometryChangeListener(this, QFlags(calculateDependency(item))); -} - -bool QQuickAnchors::mirrored() -{ - Q_D(QQuickAnchors); - return QQuickItemPrivate::get(d->item)->effectiveLayoutMirror; -} - -bool QQuickAnchorsPrivate::isItemComplete() const -{ - return componentComplete; -} - -void QQuickAnchors::classBegin() -{ - Q_D(QQuickAnchors); - d->componentComplete = false; -} - -void QQuickAnchors::componentComplete() -{ - Q_D(QQuickAnchors); - d->componentComplete = true; -} - -void QQuickAnchorsPrivate::setItemHeight(qreal v) -{ - updatingMe = true; - item->setHeight(v); - updatingMe = false; -} - -void QQuickAnchorsPrivate::setItemWidth(qreal v) -{ - updatingMe = true; - item->setWidth(v); - updatingMe = false; -} - -void QQuickAnchorsPrivate::setItemX(qreal v) -{ - updatingMe = true; - item->setX(v); - updatingMe = false; -} - -void QQuickAnchorsPrivate::setItemY(qreal v) -{ - updatingMe = true; - item->setY(v); - updatingMe = false; -} - -void QQuickAnchorsPrivate::setItemPos(const QPointF &v) -{ - updatingMe = true; - item->setPos(v); - updatingMe = false; -} - -void QQuickAnchorsPrivate::setItemSize(const QSizeF &v) -{ - updatingMe = true; - item->setSize(v); - updatingMe = false; -} - -void QQuickAnchorsPrivate::updateMe() -{ - if (updatingMe) { - updatingMe = false; - return; - } - - update(); -} - -void QQuickAnchorsPrivate::updateOnComplete() -{ - //optimization to only set initial dependencies once, at completion time - QSet dependencies; - dependencies << fill << centerIn - << left.item << right.item << hCenter.item - << top.item << bottom.item << vCenter.item << baseline.item; - - foreach (QQuickItem *dependency, dependencies) - addDepend(dependency); - - update(); -} - - -void QQuickAnchorsPrivate::update() -{ - fillChanged(); - centerInChanged(); - if (usedAnchors & QQuickAnchorLine::Horizontal_Mask) - updateHorizontalAnchors(); - if (usedAnchors & QQuickAnchorLine::Vertical_Mask) - updateVerticalAnchors(); -} - -void QQuickAnchorsPrivate::itemGeometryChanged(QQuickItem *, const QRectF &newG, const QRectF &oldG) -{ - fillChanged(); - centerInChanged(); - if ((usedAnchors & QQuickAnchorLine::Horizontal_Mask) && (newG.x() != oldG.x() || newG.width() != oldG.width())) - updateHorizontalAnchors(); - if ((usedAnchors & QQuickAnchorLine::Vertical_Mask) && (newG.y() != oldG.y() || newG.height() != oldG.height())) - updateVerticalAnchors(); -} - -QQuickItem *QQuickAnchors::fill() const -{ - Q_D(const QQuickAnchors); - return d->fill; -} - -void QQuickAnchors::setFill(QQuickItem *f) -{ - Q_D(QQuickAnchors); - if (d->fill == f) - return; - - if (!f) { - QQuickItem *oldFill = d->fill; - d->fill = f; - d->remDepend(oldFill); - emit fillChanged(); - return; - } - if (f != d->item->parentItem() && f->parentItem() != d->item->parentItem()){ - qmlInfo(d->item) << tr("Cannot anchor to an item that isn't a parent or sibling."); - return; - } - QQuickItem *oldFill = d->fill; - d->fill = f; - d->remDepend(oldFill); - d->addDepend(d->fill); - emit fillChanged(); - d->fillChanged(); -} - -void QQuickAnchors::resetFill() -{ - setFill(0); -} - -QQuickItem *QQuickAnchors::centerIn() const -{ - Q_D(const QQuickAnchors); - return d->centerIn; -} - -void QQuickAnchors::setCenterIn(QQuickItem* c) -{ - Q_D(QQuickAnchors); - if (d->centerIn == c) - return; - - if (!c) { - QQuickItem *oldCI = d->centerIn; - d->centerIn = c; - d->remDepend(oldCI); - emit centerInChanged(); - return; - } - if (c != d->item->parentItem() && c->parentItem() != d->item->parentItem()){ - qmlInfo(d->item) << tr("Cannot anchor to an item that isn't a parent or sibling."); - return; - } - QQuickItem *oldCI = d->centerIn; - d->centerIn = c; - d->remDepend(oldCI); - d->addDepend(d->centerIn); - emit centerInChanged(); - d->centerInChanged(); -} - -void QQuickAnchors::resetCenterIn() -{ - setCenterIn(0); -} - -bool QQuickAnchorsPrivate::calcStretch(const QQuickAnchorLine &edge1, - const QQuickAnchorLine &edge2, - qreal offset1, - qreal offset2, - QQuickAnchorLine::AnchorLine line, - qreal &stretch) -{ - bool edge1IsParent = (edge1.item == item->parentItem()); - bool edge2IsParent = (edge2.item == item->parentItem()); - bool edge1IsSibling = (edge1.item->parentItem() == item->parentItem()); - bool edge2IsSibling = (edge2.item->parentItem() == item->parentItem()); - - bool invalid = false; - if ((edge2IsParent && edge1IsParent) || (edge2IsSibling && edge1IsSibling)) { - stretch = (position(edge2.item, edge2.anchorLine) + offset2) - - (position(edge1.item, edge1.anchorLine) + offset1); - } else if (edge2IsParent && edge1IsSibling) { - stretch = (position(edge2.item, edge2.anchorLine) + offset2) - - (position(item->parentItem(), line) - + position(edge1.item, edge1.anchorLine) + offset1); - } else if (edge2IsSibling && edge1IsParent) { - stretch = (position(item->parentItem(), line) + position(edge2.item, edge2.anchorLine) + offset2) - - (position(edge1.item, edge1.anchorLine) + offset1); - } else - invalid = true; - - return invalid; -} - -void QQuickAnchorsPrivate::updateVerticalAnchors() -{ - if (fill || centerIn || !isItemComplete()) - return; - - if (updatingVerticalAnchor < 2) { - ++updatingVerticalAnchor; - if (usedAnchors & QQuickAnchors::TopAnchor) { - //Handle stretching - bool invalid = true; - qreal height = 0.0; - if (usedAnchors & QQuickAnchors::BottomAnchor) { - invalid = calcStretch(top, bottom, topMargin, -bottomMargin, QQuickAnchorLine::Top, height); - } else if (usedAnchors & QQuickAnchors::VCenterAnchor) { - invalid = calcStretch(top, vCenter, topMargin, vCenterOffset, QQuickAnchorLine::Top, height); - height *= 2; - } - if (!invalid) - setItemHeight(height); - - //Handle top - if (top.item == item->parentItem()) { - setItemY(adjustedPosition(top.item, top.anchorLine) + topMargin); - } else if (top.item->parentItem() == item->parentItem()) { - setItemY(position(top.item, top.anchorLine) + topMargin); - } - } else if (usedAnchors & QQuickAnchors::BottomAnchor) { - //Handle stretching (top + bottom case is handled above) - if (usedAnchors & QQuickAnchors::VCenterAnchor) { - qreal height = 0.0; - bool invalid = calcStretch(vCenter, bottom, vCenterOffset, -bottomMargin, - QQuickAnchorLine::Top, height); - if (!invalid) - setItemHeight(height*2); - } - - //Handle bottom - if (bottom.item == item->parentItem()) { - setItemY(adjustedPosition(bottom.item, bottom.anchorLine) - item->height() - bottomMargin); - } else if (bottom.item->parentItem() == item->parentItem()) { - setItemY(position(bottom.item, bottom.anchorLine) - item->height() - bottomMargin); - } - } else if (usedAnchors & QQuickAnchors::VCenterAnchor) { - //(stetching handled above) - - //Handle vCenter - if (vCenter.item == item->parentItem()) { - setItemY(adjustedPosition(vCenter.item, vCenter.anchorLine) - - vcenter(item) + vCenterOffset); - } else if (vCenter.item->parentItem() == item->parentItem()) { - setItemY(position(vCenter.item, vCenter.anchorLine) - vcenter(item) + vCenterOffset); - } - } else if (usedAnchors & QQuickAnchors::BaselineAnchor) { - //Handle baseline - if (baseline.item == item->parentItem()) { - setItemY(adjustedPosition(baseline.item, baseline.anchorLine) - item->baselineOffset() + baselineOffset); - } else if (baseline.item->parentItem() == item->parentItem()) { - setItemY(position(baseline.item, baseline.anchorLine) - item->baselineOffset() + baselineOffset); - } - } - --updatingVerticalAnchor; - } else { - // ### Make this certain :) - qmlInfo(item) << QQuickAnchors::tr("Possible anchor loop detected on vertical anchor."); - } -} - -inline QQuickAnchorLine::AnchorLine reverseAnchorLine(QQuickAnchorLine::AnchorLine anchorLine) -{ - if (anchorLine == QQuickAnchorLine::Left) { - return QQuickAnchorLine::Right; - } else if (anchorLine == QQuickAnchorLine::Right) { - return QQuickAnchorLine::Left; - } else { - return anchorLine; - } -} - -void QQuickAnchorsPrivate::updateHorizontalAnchors() -{ - Q_Q(QQuickAnchors); - if (fill || centerIn || !isItemComplete()) - return; - - if (updatingHorizontalAnchor < 3) { - ++updatingHorizontalAnchor; - qreal effectiveRightMargin, effectiveLeftMargin, effectiveHorizontalCenterOffset; - QQuickAnchorLine effectiveLeft, effectiveRight, effectiveHorizontalCenter; - QQuickAnchors::Anchor effectiveLeftAnchor, effectiveRightAnchor; - if (q->mirrored()) { - effectiveLeftAnchor = QQuickAnchors::RightAnchor; - effectiveRightAnchor = QQuickAnchors::LeftAnchor; - effectiveLeft.item = right.item; - effectiveLeft.anchorLine = reverseAnchorLine(right.anchorLine); - effectiveRight.item = left.item; - effectiveRight.anchorLine = reverseAnchorLine(left.anchorLine); - effectiveHorizontalCenter.item = hCenter.item; - effectiveHorizontalCenter.anchorLine = reverseAnchorLine(hCenter.anchorLine); - effectiveLeftMargin = rightMargin; - effectiveRightMargin = leftMargin; - effectiveHorizontalCenterOffset = -hCenterOffset; - } else { - effectiveLeftAnchor = QQuickAnchors::LeftAnchor; - effectiveRightAnchor = QQuickAnchors::RightAnchor; - effectiveLeft = left; - effectiveRight = right; - effectiveHorizontalCenter = hCenter; - effectiveLeftMargin = leftMargin; - effectiveRightMargin = rightMargin; - effectiveHorizontalCenterOffset = hCenterOffset; - } - - if (usedAnchors & effectiveLeftAnchor) { - //Handle stretching - bool invalid = true; - qreal width = 0.0; - if (usedAnchors & effectiveRightAnchor) { - invalid = calcStretch(effectiveLeft, effectiveRight, effectiveLeftMargin, -effectiveRightMargin, QQuickAnchorLine::Left, width); - } else if (usedAnchors & QQuickAnchors::HCenterAnchor) { - invalid = calcStretch(effectiveLeft, effectiveHorizontalCenter, effectiveLeftMargin, effectiveHorizontalCenterOffset, QQuickAnchorLine::Left, width); - width *= 2; - } - if (!invalid) - setItemWidth(width); - - //Handle left - if (effectiveLeft.item == item->parentItem()) { - setItemX(adjustedPosition(effectiveLeft.item, effectiveLeft.anchorLine) + effectiveLeftMargin); - } else if (effectiveLeft.item->parentItem() == item->parentItem()) { - setItemX(position(effectiveLeft.item, effectiveLeft.anchorLine) + effectiveLeftMargin); - } - } else if (usedAnchors & effectiveRightAnchor) { - //Handle stretching (left + right case is handled in updateLeftAnchor) - if (usedAnchors & QQuickAnchors::HCenterAnchor) { - qreal width = 0.0; - bool invalid = calcStretch(effectiveHorizontalCenter, effectiveRight, effectiveHorizontalCenterOffset, -effectiveRightMargin, - QQuickAnchorLine::Left, width); - if (!invalid) - setItemWidth(width*2); - } - - //Handle right - if (effectiveRight.item == item->parentItem()) { - setItemX(adjustedPosition(effectiveRight.item, effectiveRight.anchorLine) - item->width() - effectiveRightMargin); - } else if (effectiveRight.item->parentItem() == item->parentItem()) { - setItemX(position(effectiveRight.item, effectiveRight.anchorLine) - item->width() - effectiveRightMargin); - } - } else if (usedAnchors & QQuickAnchors::HCenterAnchor) { - //Handle hCenter - if (effectiveHorizontalCenter.item == item->parentItem()) { - setItemX(adjustedPosition(effectiveHorizontalCenter.item, effectiveHorizontalCenter.anchorLine) - hcenter(item) + effectiveHorizontalCenterOffset); - } else if (effectiveHorizontalCenter.item->parentItem() == item->parentItem()) { - setItemX(position(effectiveHorizontalCenter.item, effectiveHorizontalCenter.anchorLine) - hcenter(item) + effectiveHorizontalCenterOffset); - } - } - --updatingHorizontalAnchor; - } else { - // ### Make this certain :) - qmlInfo(item) << QQuickAnchors::tr("Possible anchor loop detected on horizontal anchor."); - } -} - -QQuickAnchorLine QQuickAnchors::top() const -{ - Q_D(const QQuickAnchors); - return d->top; -} - -void QQuickAnchors::setTop(const QQuickAnchorLine &edge) -{ - Q_D(QQuickAnchors); - if (!d->checkVAnchorValid(edge) || d->top == edge) - return; - - d->usedAnchors |= TopAnchor; - - if (!d->checkVValid()) { - d->usedAnchors &= ~TopAnchor; - return; - } - - QQuickItem *oldTop = d->top.item; - d->top = edge; - d->remDepend(oldTop); - d->addDepend(d->top.item); - emit topChanged(); - d->updateVerticalAnchors(); -} - -void QQuickAnchors::resetTop() -{ - Q_D(QQuickAnchors); - d->usedAnchors &= ~TopAnchor; - d->remDepend(d->top.item); - d->top = QQuickAnchorLine(); - emit topChanged(); - d->updateVerticalAnchors(); -} - -QQuickAnchorLine QQuickAnchors::bottom() const -{ - Q_D(const QQuickAnchors); - return d->bottom; -} - -void QQuickAnchors::setBottom(const QQuickAnchorLine &edge) -{ - Q_D(QQuickAnchors); - if (!d->checkVAnchorValid(edge) || d->bottom == edge) - return; - - d->usedAnchors |= BottomAnchor; - - if (!d->checkVValid()) { - d->usedAnchors &= ~BottomAnchor; - return; - } - - QQuickItem *oldBottom = d->bottom.item; - d->bottom = edge; - d->remDepend(oldBottom); - d->addDepend(d->bottom.item); - emit bottomChanged(); - d->updateVerticalAnchors(); -} - -void QQuickAnchors::resetBottom() -{ - Q_D(QQuickAnchors); - d->usedAnchors &= ~BottomAnchor; - d->remDepend(d->bottom.item); - d->bottom = QQuickAnchorLine(); - emit bottomChanged(); - d->updateVerticalAnchors(); -} - -QQuickAnchorLine QQuickAnchors::verticalCenter() const -{ - Q_D(const QQuickAnchors); - return d->vCenter; -} - -void QQuickAnchors::setVerticalCenter(const QQuickAnchorLine &edge) -{ - Q_D(QQuickAnchors); - if (!d->checkVAnchorValid(edge) || d->vCenter == edge) - return; - - d->usedAnchors |= VCenterAnchor; - - if (!d->checkVValid()) { - d->usedAnchors &= ~VCenterAnchor; - return; - } - - QQuickItem *oldVCenter = d->vCenter.item; - d->vCenter = edge; - d->remDepend(oldVCenter); - d->addDepend(d->vCenter.item); - emit verticalCenterChanged(); - d->updateVerticalAnchors(); -} - -void QQuickAnchors::resetVerticalCenter() -{ - Q_D(QQuickAnchors); - d->usedAnchors &= ~VCenterAnchor; - d->remDepend(d->vCenter.item); - d->vCenter = QQuickAnchorLine(); - emit verticalCenterChanged(); - d->updateVerticalAnchors(); -} - -QQuickAnchorLine QQuickAnchors::baseline() const -{ - Q_D(const QQuickAnchors); - return d->baseline; -} - -void QQuickAnchors::setBaseline(const QQuickAnchorLine &edge) -{ - Q_D(QQuickAnchors); - if (!d->checkVAnchorValid(edge) || d->baseline == edge) - return; - - d->usedAnchors |= BaselineAnchor; - - if (!d->checkVValid()) { - d->usedAnchors &= ~BaselineAnchor; - return; - } - - QQuickItem *oldBaseline = d->baseline.item; - d->baseline = edge; - d->remDepend(oldBaseline); - d->addDepend(d->baseline.item); - emit baselineChanged(); - d->updateVerticalAnchors(); -} - -void QQuickAnchors::resetBaseline() -{ - Q_D(QQuickAnchors); - d->usedAnchors &= ~BaselineAnchor; - d->remDepend(d->baseline.item); - d->baseline = QQuickAnchorLine(); - emit baselineChanged(); - d->updateVerticalAnchors(); -} - -QQuickAnchorLine QQuickAnchors::left() const -{ - Q_D(const QQuickAnchors); - return d->left; -} - -void QQuickAnchors::setLeft(const QQuickAnchorLine &edge) -{ - Q_D(QQuickAnchors); - if (!d->checkHAnchorValid(edge) || d->left == edge) - return; - - d->usedAnchors |= LeftAnchor; - - if (!d->checkHValid()) { - d->usedAnchors &= ~LeftAnchor; - return; - } - - QQuickItem *oldLeft = d->left.item; - d->left = edge; - d->remDepend(oldLeft); - d->addDepend(d->left.item); - emit leftChanged(); - d->updateHorizontalAnchors(); -} - -void QQuickAnchors::resetLeft() -{ - Q_D(QQuickAnchors); - d->usedAnchors &= ~LeftAnchor; - d->remDepend(d->left.item); - d->left = QQuickAnchorLine(); - emit leftChanged(); - d->updateHorizontalAnchors(); -} - -QQuickAnchorLine QQuickAnchors::right() const -{ - Q_D(const QQuickAnchors); - return d->right; -} - -void QQuickAnchors::setRight(const QQuickAnchorLine &edge) -{ - Q_D(QQuickAnchors); - if (!d->checkHAnchorValid(edge) || d->right == edge) - return; - - d->usedAnchors |= RightAnchor; - - if (!d->checkHValid()) { - d->usedAnchors &= ~RightAnchor; - return; - } - - QQuickItem *oldRight = d->right.item; - d->right = edge; - d->remDepend(oldRight); - d->addDepend(d->right.item); - emit rightChanged(); - d->updateHorizontalAnchors(); -} - -void QQuickAnchors::resetRight() -{ - Q_D(QQuickAnchors); - d->usedAnchors &= ~RightAnchor; - d->remDepend(d->right.item); - d->right = QQuickAnchorLine(); - emit rightChanged(); - d->updateHorizontalAnchors(); -} - -QQuickAnchorLine QQuickAnchors::horizontalCenter() const -{ - Q_D(const QQuickAnchors); - return d->hCenter; -} - -void QQuickAnchors::setHorizontalCenter(const QQuickAnchorLine &edge) -{ - Q_D(QQuickAnchors); - if (!d->checkHAnchorValid(edge) || d->hCenter == edge) - return; - - d->usedAnchors |= HCenterAnchor; - - if (!d->checkHValid()) { - d->usedAnchors &= ~HCenterAnchor; - return; - } - - QQuickItem *oldHCenter = d->hCenter.item; - d->hCenter = edge; - d->remDepend(oldHCenter); - d->addDepend(d->hCenter.item); - emit horizontalCenterChanged(); - d->updateHorizontalAnchors(); -} - -void QQuickAnchors::resetHorizontalCenter() -{ - Q_D(QQuickAnchors); - d->usedAnchors &= ~HCenterAnchor; - d->remDepend(d->hCenter.item); - d->hCenter = QQuickAnchorLine(); - emit horizontalCenterChanged(); - d->updateHorizontalAnchors(); -} - -qreal QQuickAnchors::leftMargin() const -{ - Q_D(const QQuickAnchors); - return d->leftMargin; -} - -void QQuickAnchors::setLeftMargin(qreal offset) -{ - Q_D(QQuickAnchors); - if (d->leftMargin == offset) - return; - d->leftMargin = offset; - if (d->fill) - d->fillChanged(); - else - d->updateHorizontalAnchors(); - emit leftMarginChanged(); -} - -qreal QQuickAnchors::rightMargin() const -{ - Q_D(const QQuickAnchors); - return d->rightMargin; -} - -void QQuickAnchors::setRightMargin(qreal offset) -{ - Q_D(QQuickAnchors); - if (d->rightMargin == offset) - return; - d->rightMargin = offset; - if (d->fill) - d->fillChanged(); - else - d->updateHorizontalAnchors(); - emit rightMarginChanged(); -} - -qreal QQuickAnchors::margins() const -{ - Q_D(const QQuickAnchors); - return d->margins; -} - -void QQuickAnchors::setMargins(qreal offset) -{ - Q_D(QQuickAnchors); - if (d->margins == offset) - return; - //###Is it significantly faster to set them directly so we can call fillChanged only once? - if (!d->rightMargin || d->rightMargin == d->margins) - setRightMargin(offset); - if (!d->leftMargin || d->leftMargin == d->margins) - setLeftMargin(offset); - if (!d->topMargin || d->topMargin == d->margins) - setTopMargin(offset); - if (!d->bottomMargin || d->bottomMargin == d->margins) - setBottomMargin(offset); - d->margins = offset; - emit marginsChanged(); - -} - -qreal QQuickAnchors::horizontalCenterOffset() const -{ - Q_D(const QQuickAnchors); - return d->hCenterOffset; -} - -void QQuickAnchors::setHorizontalCenterOffset(qreal offset) -{ - Q_D(QQuickAnchors); - if (d->hCenterOffset == offset) - return; - d->hCenterOffset = offset; - if (d->centerIn) - d->centerInChanged(); - else - d->updateHorizontalAnchors(); - emit horizontalCenterOffsetChanged(); -} - -qreal QQuickAnchors::topMargin() const -{ - Q_D(const QQuickAnchors); - return d->topMargin; -} - -void QQuickAnchors::setTopMargin(qreal offset) -{ - Q_D(QQuickAnchors); - if (d->topMargin == offset) - return; - d->topMargin = offset; - if (d->fill) - d->fillChanged(); - else - d->updateVerticalAnchors(); - emit topMarginChanged(); -} - -qreal QQuickAnchors::bottomMargin() const -{ - Q_D(const QQuickAnchors); - return d->bottomMargin; -} - -void QQuickAnchors::setBottomMargin(qreal offset) -{ - Q_D(QQuickAnchors); - if (d->bottomMargin == offset) - return; - d->bottomMargin = offset; - if (d->fill) - d->fillChanged(); - else - d->updateVerticalAnchors(); - emit bottomMarginChanged(); -} - -qreal QQuickAnchors::verticalCenterOffset() const -{ - Q_D(const QQuickAnchors); - return d->vCenterOffset; -} - -void QQuickAnchors::setVerticalCenterOffset(qreal offset) -{ - Q_D(QQuickAnchors); - if (d->vCenterOffset == offset) - return; - d->vCenterOffset = offset; - if (d->centerIn) - d->centerInChanged(); - else - d->updateVerticalAnchors(); - emit verticalCenterOffsetChanged(); -} - -qreal QQuickAnchors::baselineOffset() const -{ - Q_D(const QQuickAnchors); - return d->baselineOffset; -} - -void QQuickAnchors::setBaselineOffset(qreal offset) -{ - Q_D(QQuickAnchors); - if (d->baselineOffset == offset) - return; - d->baselineOffset = offset; - d->updateVerticalAnchors(); - emit baselineOffsetChanged(); -} - -QQuickAnchors::Anchors QQuickAnchors::usedAnchors() const -{ - Q_D(const QQuickAnchors); - return d->usedAnchors; -} - -bool QQuickAnchorsPrivate::checkHValid() const -{ - if (usedAnchors & QQuickAnchors::LeftAnchor && - usedAnchors & QQuickAnchors::RightAnchor && - usedAnchors & QQuickAnchors::HCenterAnchor) { - qmlInfo(item) << QQuickAnchors::tr("Cannot specify left, right, and hcenter anchors."); - return false; - } - - return true; -} - -bool QQuickAnchorsPrivate::checkHAnchorValid(QQuickAnchorLine anchor) const -{ - if (!anchor.item) { - qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to a null item."); - return false; - } else if (anchor.anchorLine & QQuickAnchorLine::Vertical_Mask) { - qmlInfo(item) << QQuickAnchors::tr("Cannot anchor a horizontal edge to a vertical edge."); - return false; - } else if (anchor.item != item->parentItem() && anchor.item->parentItem() != item->parentItem()){ - qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to an item that isn't a parent or sibling."); - return false; - } else if (anchor.item == item) { - qmlInfo(item) << QQuickAnchors::tr("Cannot anchor item to self."); - return false; - } - - return true; -} - -bool QQuickAnchorsPrivate::checkVValid() const -{ - if (usedAnchors & QQuickAnchors::TopAnchor && - usedAnchors & QQuickAnchors::BottomAnchor && - usedAnchors & QQuickAnchors::VCenterAnchor) { - qmlInfo(item) << QQuickAnchors::tr("Cannot specify top, bottom, and vcenter anchors."); - return false; - } else if (usedAnchors & QQuickAnchors::BaselineAnchor && - (usedAnchors & QQuickAnchors::TopAnchor || - usedAnchors & QQuickAnchors::BottomAnchor || - usedAnchors & QQuickAnchors::VCenterAnchor)) { - qmlInfo(item) << QQuickAnchors::tr("Baseline anchor cannot be used in conjunction with top, bottom, or vcenter anchors."); - return false; - } - - return true; -} - -bool QQuickAnchorsPrivate::checkVAnchorValid(QQuickAnchorLine anchor) const -{ - if (!anchor.item) { - qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to a null item."); - return false; - } else if (anchor.anchorLine & QQuickAnchorLine::Horizontal_Mask) { - qmlInfo(item) << QQuickAnchors::tr("Cannot anchor a vertical edge to a horizontal edge."); - return false; - } else if (anchor.item != item->parentItem() && anchor.item->parentItem() != item->parentItem()){ - qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to an item that isn't a parent or sibling."); - return false; - } else if (anchor.item == item){ - qmlInfo(item) << QQuickAnchors::tr("Cannot anchor item to self."); - return false; - } - - return true; -} - -QT_END_NAMESPACE - -#include - diff --git a/src/declarative/items/qquickanchors_p.h b/src/declarative/items/qquickanchors_p.h deleted file mode 100644 index 5c66c2e17d..0000000000 --- a/src/declarative/items/qquickanchors_p.h +++ /dev/null @@ -1,201 +0,0 @@ -// Commit: 2c7cab4172f1acc86fd49345a2847417e162f2c3 -/**************************************************************************** -** -** 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$ -** 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 QQUICKANCHORS_P_H -#define QQUICKANCHORS_P_H - -#include - -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickItem; -class QQuickAnchorsPrivate; -class QQuickAnchorLine; -class Q_DECLARATIVE_PRIVATE_EXPORT QQuickAnchors : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QQuickAnchorLine left READ left WRITE setLeft RESET resetLeft NOTIFY leftChanged) - Q_PROPERTY(QQuickAnchorLine right READ right WRITE setRight RESET resetRight NOTIFY rightChanged) - Q_PROPERTY(QQuickAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter NOTIFY horizontalCenterChanged) - Q_PROPERTY(QQuickAnchorLine top READ top WRITE setTop RESET resetTop NOTIFY topChanged) - Q_PROPERTY(QQuickAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom NOTIFY bottomChanged) - Q_PROPERTY(QQuickAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter NOTIFY verticalCenterChanged) - Q_PROPERTY(QQuickAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline NOTIFY baselineChanged) - Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged) - Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) - Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) - Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged) - Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) - Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) - Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged) - Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged) - Q_PROPERTY(QQuickItem *fill READ fill WRITE setFill RESET resetFill NOTIFY fillChanged) - Q_PROPERTY(QQuickItem *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn NOTIFY centerInChanged) - Q_PROPERTY(bool mirrored READ mirrored NOTIFY mirroredChanged) - -public: - QQuickAnchors(QQuickItem *item, QObject *parent=0); - virtual ~QQuickAnchors(); - - enum Anchor { - LeftAnchor = 0x01, - RightAnchor = 0x02, - TopAnchor = 0x04, - BottomAnchor = 0x08, - HCenterAnchor = 0x10, - VCenterAnchor = 0x20, - BaselineAnchor = 0x40, - Horizontal_Mask = LeftAnchor | RightAnchor | HCenterAnchor, - Vertical_Mask = TopAnchor | BottomAnchor | VCenterAnchor | BaselineAnchor - }; - Q_DECLARE_FLAGS(Anchors, Anchor) - - QQuickAnchorLine left() const; - void setLeft(const QQuickAnchorLine &edge); - void resetLeft(); - - QQuickAnchorLine right() const; - void setRight(const QQuickAnchorLine &edge); - void resetRight(); - - QQuickAnchorLine horizontalCenter() const; - void setHorizontalCenter(const QQuickAnchorLine &edge); - void resetHorizontalCenter(); - - QQuickAnchorLine top() const; - void setTop(const QQuickAnchorLine &edge); - void resetTop(); - - QQuickAnchorLine bottom() const; - void setBottom(const QQuickAnchorLine &edge); - void resetBottom(); - - QQuickAnchorLine verticalCenter() const; - void setVerticalCenter(const QQuickAnchorLine &edge); - void resetVerticalCenter(); - - QQuickAnchorLine baseline() const; - void setBaseline(const QQuickAnchorLine &edge); - void resetBaseline(); - - qreal leftMargin() const; - void setLeftMargin(qreal); - - qreal rightMargin() const; - void setRightMargin(qreal); - - qreal horizontalCenterOffset() const; - void setHorizontalCenterOffset(qreal); - - qreal topMargin() const; - void setTopMargin(qreal); - - qreal bottomMargin() const; - void setBottomMargin(qreal); - - qreal margins() const; - void setMargins(qreal); - - qreal verticalCenterOffset() const; - void setVerticalCenterOffset(qreal); - - qreal baselineOffset() const; - void setBaselineOffset(qreal); - - QQuickItem *fill() const; - void setFill(QQuickItem *); - void resetFill(); - - QQuickItem *centerIn() const; - void setCenterIn(QQuickItem *); - void resetCenterIn(); - - Anchors usedAnchors() const; - - bool mirrored(); - - void classBegin(); - void componentComplete(); - -Q_SIGNALS: - void leftChanged(); - void rightChanged(); - void topChanged(); - void bottomChanged(); - void verticalCenterChanged(); - void horizontalCenterChanged(); - void baselineChanged(); - void fillChanged(); - void centerInChanged(); - void leftMarginChanged(); - void rightMarginChanged(); - void topMarginChanged(); - void bottomMarginChanged(); - void marginsChanged(); - void verticalCenterOffsetChanged(); - void horizontalCenterOffsetChanged(); - void baselineOffsetChanged(); - void mirroredChanged(); - -private: - friend class QQuickItemPrivate; - Q_DISABLE_COPY(QQuickAnchors) - Q_DECLARE_PRIVATE(QQuickAnchors) -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickAnchors::Anchors) - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickAnchors) - -QT_END_HEADER - -#endif // QQUICKANCHORS_P_H diff --git a/src/declarative/items/qquickanchors_p_p.h b/src/declarative/items/qquickanchors_p_p.h deleted file mode 100644 index 50d55b081f..0000000000 --- a/src/declarative/items/qquickanchors_p_p.h +++ /dev/null @@ -1,176 +0,0 @@ -// Commit: 2c7cab4172f1acc86fd49345a2847417e162f2c3 -/**************************************************************************** -** -** 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$ -** 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 QQUICKANCHORS_P_P_H -#define QQUICKANCHORS_P_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 "qquickanchors_p.h" -#include "qquickitemchangelistener_p.h" -#include - -QT_BEGIN_NAMESPACE - -class QQuickAnchorLine -{ -public: - QQuickAnchorLine() : item(0), anchorLine(Invalid) {} - - enum AnchorLine { - Invalid = 0x0, - Left = 0x01, - Right = 0x02, - Top = 0x04, - Bottom = 0x08, - HCenter = 0x10, - VCenter = 0x20, - Baseline = 0x40, - Horizontal_Mask = Left | Right | HCenter, - Vertical_Mask = Top | Bottom | VCenter | Baseline - }; - - QQuickItem *item; - AnchorLine anchorLine; -}; - -inline bool operator==(const QQuickAnchorLine& a, const QQuickAnchorLine& b) -{ - return a.item == b.item && a.anchorLine == b.anchorLine; -} - -class QQuickAnchorsPrivate : public QObjectPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickAnchors) -public: - QQuickAnchorsPrivate(QQuickItem *i) - : componentComplete(true), updatingMe(false), inDestructor(false), updatingHorizontalAnchor(0), - updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(i), usedAnchors(0), fill(0), - centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0), - margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0) - { - } - - void clearItem(QQuickItem *); - - int calculateDependency(QQuickItem *); - void addDepend(QQuickItem *); - void remDepend(QQuickItem *); - bool isItemComplete() const; - - bool componentComplete:1; - bool updatingMe:1; - bool inDestructor:1; - uint updatingHorizontalAnchor:2; - uint updatingVerticalAnchor:2; - uint updatingFill:2; - uint updatingCenterIn:2; - - void setItemHeight(qreal); - void setItemWidth(qreal); - void setItemX(qreal); - void setItemY(qreal); - void setItemPos(const QPointF &); - void setItemSize(const QSizeF &); - - void update(); - void updateOnComplete(); - void updateMe(); - - // QQuickItemGeometryListener interface - void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &); - QQuickAnchorsPrivate *anchorPrivate() { return this; } - - bool checkHValid() const; - bool checkVValid() const; - bool checkHAnchorValid(QQuickAnchorLine anchor) const; - bool checkVAnchorValid(QQuickAnchorLine anchor) const; - bool calcStretch(const QQuickAnchorLine &edge1, const QQuickAnchorLine &edge2, qreal offset1, qreal offset2, QQuickAnchorLine::AnchorLine line, qreal &stretch); - - bool isMirrored() const; - void updateHorizontalAnchors(); - void updateVerticalAnchors(); - void fillChanged(); - void centerInChanged(); - - QQuickItem *item; - QQuickAnchors::Anchors usedAnchors; - - QQuickItem *fill; - QQuickItem *centerIn; - - QQuickAnchorLine left; - QQuickAnchorLine right; - QQuickAnchorLine top; - QQuickAnchorLine bottom; - QQuickAnchorLine vCenter; - QQuickAnchorLine hCenter; - QQuickAnchorLine baseline; - - qreal leftMargin; - qreal rightMargin; - qreal topMargin; - qreal bottomMargin; - qreal margins; - qreal vCenterOffset; - qreal hCenterOffset; - qreal baselineOffset; - - static inline QQuickAnchorsPrivate *get(QQuickAnchors *o) { - return static_cast(QObjectPrivate::get(o)); - } -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QQuickAnchorLine) - -#endif diff --git a/src/declarative/items/qquickanimatedimage.cpp b/src/declarative/items/qquickanimatedimage.cpp deleted file mode 100644 index 61447c87e2..0000000000 --- a/src/declarative/items/qquickanimatedimage.cpp +++ /dev/null @@ -1,397 +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 QtDeclarative module 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 "qquickanimatedimage_p.h" -#include "qquickanimatedimage_p_p.h" - -#ifndef QT_NO_MOVIE - -#include -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE -/*! - \qmlclass AnimatedImage QQuickAnimatedImage - \inqmlmodule QtQuick 2 - \inherits Image - \ingroup basic-visual-elements - - The AnimatedImage element extends the features of the \l Image element, providing - a way to play animations stored as images containing a series of frames, - such as those stored in GIF files. - - Information about the current frame and total length of the animation can be - obtained using the \l currentFrame and \l frameCount properties. You can - start, pause and stop the animation by changing the values of the \l playing - and \l paused properties. - - The full list of supported formats can be determined with QMovie::supportedFormats(). - - \section1 Example Usage - - \beginfloatleft - \image animatedimageitem.gif - \endfloat - - The following QML shows how to display an animated image and obtain information - about its state, such as the current frame and total number of frames. - The result is an animated image with a simple progress indicator underneath it. - - \bold Note: Unlike images, animated images are not cached or shared internally. - - \clearfloat - \snippet doc/src/snippets/declarative/animatedimage.qml document - - \sa BorderImage, Image -*/ - -/*! - \qmlproperty url QtQuick2::AnimatedImage::source - - This property holds the URL that refers to the source image. - - AnimatedImage can handle any image format supported by Qt, loaded from any - URL scheme supported by Qt. - - \sa QDeclarativeImageProvider -*/ - -/*! - \qmlproperty bool QtQuick2::AnimatedImage::asynchronous - - Specifies that images on the local filesystem should be loaded - asynchronously in a separate thread. The default value is - false, causing the user interface thread to block while the - image is loaded. Setting \a asynchronous to true is useful where - maintaining a responsive user interface is more desirable - than having images immediately visible. - - Note that this property is only valid for images read from the - local filesystem. Images loaded via a network resource (e.g. HTTP) - are always loaded asynchronously. -*/ - -/*! - \qmlproperty bool QtQuick2::AnimatedImage::mirror - - This property holds whether the image should be horizontally inverted - (effectively displaying a mirrored image). - - The default value is false. -*/ - -QQuickAnimatedImage::QQuickAnimatedImage(QQuickItem *parent) - : QQuickImage(*(new QQuickAnimatedImagePrivate), parent) -{ -} - -QQuickAnimatedImage::~QQuickAnimatedImage() -{ - Q_D(QQuickAnimatedImage); - delete d->_movie; -} - -/*! - \qmlproperty bool QtQuick2::AnimatedImage::paused - This property holds whether the animated image is paused. - - By default, this property is false. Set it to true when you want to pause - the animation. -*/ - -bool QQuickAnimatedImage::isPaused() const -{ - Q_D(const QQuickAnimatedImage); - if (!d->_movie) - return false; - return d->_movie->state()==QMovie::Paused; -} - -void QQuickAnimatedImage::setPaused(bool pause) -{ - Q_D(QQuickAnimatedImage); - if (pause == d->paused) - return; - d->paused = pause; - if (!d->_movie) - return; - d->_movie->setPaused(pause); -} - -/*! - \qmlproperty bool QtQuick2::AnimatedImage::playing - This property holds whether the animated image is playing. - - By default, this property is true, meaning that the animation - will start playing immediately. -*/ - -bool QQuickAnimatedImage::isPlaying() const -{ - Q_D(const QQuickAnimatedImage); - if (!d->_movie) - return false; - return d->_movie->state()!=QMovie::NotRunning; -} - -void QQuickAnimatedImage::setPlaying(bool play) -{ - Q_D(QQuickAnimatedImage); - if (play == d->playing) - return; - d->playing = play; - if (!d->_movie) - return; - if (play) - d->_movie->start(); - else - d->_movie->stop(); -} - -/*! - \qmlproperty int QtQuick2::AnimatedImage::currentFrame - \qmlproperty int QtQuick2::AnimatedImage::frameCount - - currentFrame is the frame that is currently visible. By monitoring this property - for changes, you can animate other items at the same time as the image. - - frameCount is the number of frames in the animation. For some animation formats, - frameCount is unknown and has a value of zero. -*/ -int QQuickAnimatedImage::currentFrame() const -{ - Q_D(const QQuickAnimatedImage); - if (!d->_movie) - return d->preset_currentframe; - return d->_movie->currentFrameNumber(); -} - -void QQuickAnimatedImage::setCurrentFrame(int frame) -{ - Q_D(QQuickAnimatedImage); - if (!d->_movie) { - d->preset_currentframe = frame; - return; - } - d->_movie->jumpToFrame(frame); -} - -int QQuickAnimatedImage::frameCount() const -{ - Q_D(const QQuickAnimatedImage); - if (!d->_movie) - return 0; - return d->_movie->frameCount(); -} - -void QQuickAnimatedImage::setSource(const QUrl &url) -{ - Q_D(QQuickAnimatedImage); - if (url == d->url) - return; - - delete d->_movie; - d->_movie = 0; - - if (d->reply) { - d->reply->deleteLater(); - d->reply = 0; - } - - d->url = url; - emit sourceChanged(d->url); - - if (isComponentComplete()) - load(); -} - -void QQuickAnimatedImage::load() -{ - Q_D(QQuickAnimatedImage); - - QQuickImageBase::Status oldStatus = d->status; - qreal oldProgress = d->progress; - - if (d->url.isEmpty()) { - delete d->_movie; - d->setImage(QImage()); - d->progress = 0; - d->status = Null; - if (d->status != oldStatus) - emit statusChanged(d->status); - if (d->progress != oldProgress) - emit progressChanged(d->progress); - } else { - QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(d->url); - if (!lf.isEmpty()) { - //### should be unified with movieRequestFinished - d->_movie = new QMovie(lf); - if (!d->_movie->isValid()){ - qmlInfo(this) << "Error Reading Animated Image File " << d->url.toString(); - delete d->_movie; - d->_movie = 0; - d->status = Error; - if (d->status != oldStatus) - emit statusChanged(d->status); - return; - } - connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)), - this, SLOT(playingStatusChanged())); - connect(d->_movie, SIGNAL(frameChanged(int)), - this, SLOT(movieUpdate())); - d->_movie->setCacheMode(QMovie::CacheAll); - if (d->playing) - d->_movie->start(); - else - d->_movie->jumpToFrame(0); - if (d->paused) - d->_movie->setPaused(true); - d->setImage(d->_movie->currentPixmap().toImage()); - d->status = Ready; - d->progress = 1.0; - if (d->status != oldStatus) - emit statusChanged(d->status); - if (d->progress != oldProgress) - emit progressChanged(d->progress); - return; - } - - d->status = Loading; - d->progress = 0; - emit statusChanged(d->status); - emit progressChanged(d->progress); - QNetworkRequest req(d->url); - req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); - d->reply = qmlEngine(this)->networkAccessManager()->get(req); - QObject::connect(d->reply, SIGNAL(finished()), - this, SLOT(movieRequestFinished())); - QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), - this, SLOT(requestProgress(qint64,qint64))); - } -} - -#define ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION 16 - -void QQuickAnimatedImage::movieRequestFinished() -{ - Q_D(QQuickAnimatedImage); - - d->redirectCount++; - if (d->redirectCount < ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION) { - QVariant redirect = d->reply->attribute(QNetworkRequest::RedirectionTargetAttribute); - if (redirect.isValid()) { - QUrl url = d->reply->url().resolved(redirect.toUrl()); - d->reply->deleteLater(); - d->reply = 0; - setSource(url); - return; - } - } - d->redirectCount=0; - - d->_movie = new QMovie(d->reply); - if (!d->_movie->isValid()){ -#ifndef QT_NO_DEBUG_STREAM - qmlInfo(this) << "Error Reading Animated Image File " << d->url; -#endif - delete d->_movie; - d->_movie = 0; - d->status = Error; - emit statusChanged(d->status); - return; - } - connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)), - this, SLOT(playingStatusChanged())); - connect(d->_movie, SIGNAL(frameChanged(int)), - this, SLOT(movieUpdate())); - d->_movie->setCacheMode(QMovie::CacheAll); - if (d->playing) - d->_movie->start(); - if (d->paused || !d->playing) { - d->_movie->jumpToFrame(d->preset_currentframe); - d->preset_currentframe = 0; - } - if (d->paused) - d->_movie->setPaused(true); - d->setImage(d->_movie->currentPixmap().toImage()); - d->status = Ready; - emit statusChanged(d->status); -} - -void QQuickAnimatedImage::movieUpdate() -{ - Q_D(QQuickAnimatedImage); - d->setImage(d->_movie->currentPixmap().toImage()); - emit frameChanged(); -} - -void QQuickAnimatedImage::playingStatusChanged() -{ - Q_D(QQuickAnimatedImage); - if ((d->_movie->state() != QMovie::NotRunning) != d->playing) { - d->playing = (d->_movie->state() != QMovie::NotRunning); - emit playingChanged(); - } - if ((d->_movie->state() == QMovie::Paused) != d->paused) { - d->playing = (d->_movie->state() == QMovie::Paused); - emit pausedChanged(); - } -} - -void QQuickAnimatedImage::componentComplete() -{ - Q_D(QQuickAnimatedImage); - QQuickItem::componentComplete(); // NOT QQuickImage - if (d->url.isValid()) - load(); - if (!d->reply) { - setCurrentFrame(d->preset_currentframe); - d->preset_currentframe = 0; - } -} - -QT_END_NAMESPACE - -#endif // QT_NO_MOVIE diff --git a/src/declarative/items/qquickanimatedimage_p.h b/src/declarative/items/qquickanimatedimage_p.h deleted file mode 100644 index ae96e4cc15..0000000000 --- a/src/declarative/items/qquickanimatedimage_p.h +++ /dev/null @@ -1,117 +0,0 @@ -// Commit: 80d0fe9cbd92288a08d5ced8767f1edb651dae37 -/**************************************************************************** -** -** 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$ -** 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 QQUICKANIMATEDIMAGE_P_H -#define QQUICKANIMATEDIMAGE_P_H - -#include "qquickimage_p.h" - -#ifndef QT_NO_MOVIE - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QMovie; -class QQuickAnimatedImagePrivate; - -class Q_AUTOTEST_EXPORT QQuickAnimatedImage : public QQuickImage -{ - Q_OBJECT - - Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) - Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) - Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY frameChanged) - Q_PROPERTY(int frameCount READ frameCount) - - // read-only for AnimatedImage - Q_PROPERTY(QSize sourceSize READ sourceSize NOTIFY sourceSizeChanged) - -public: - QQuickAnimatedImage(QQuickItem *parent=0); - ~QQuickAnimatedImage(); - - bool isPlaying() const; - void setPlaying(bool play); - - bool isPaused() const; - void setPaused(bool pause); - - int currentFrame() const; - void setCurrentFrame(int frame); - - int frameCount() const; - - // Extends QQuickImage's src property*/ - virtual void setSource(const QUrl&); - -Q_SIGNALS: - void playingChanged(); - void pausedChanged(); - void frameChanged(); - void sourceSizeChanged(); - -private Q_SLOTS: - void movieUpdate(); - void movieRequestFinished(); - void playingStatusChanged(); - -protected: - virtual void load(); - void componentComplete(); - -private: - Q_DISABLE_COPY(QQuickAnimatedImage) - Q_DECLARE_PRIVATE(QQuickAnimatedImage) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickAnimatedImage) - -QT_END_HEADER - -#endif // QT_NO_MOVIE - -#endif // QQUICKANIMATEDIMAGE_P_H diff --git a/src/declarative/items/qquickanimatedimage_p_p.h b/src/declarative/items/qquickanimatedimage_p_p.h deleted file mode 100644 index 0d5dd4a3b7..0000000000 --- a/src/declarative/items/qquickanimatedimage_p_p.h +++ /dev/null @@ -1,88 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKANIMATEDIMAGE_P_P_H -#define QQUICKANIMATEDIMAGE_P_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 "qquickimage_p_p.h" - -#ifndef QT_NO_MOVIE - -QT_BEGIN_NAMESPACE - -class QMovie; -class QNetworkReply; - -class QQuickAnimatedImagePrivate : public QQuickImagePrivate -{ - Q_DECLARE_PUBLIC(QQuickAnimatedImage) - -public: - QQuickAnimatedImagePrivate() - : playing(true), paused(false), preset_currentframe(0), _movie(0), reply(0), redirectCount(0) - { - } - - bool playing; - bool paused; - int preset_currentframe; - QMovie *_movie; - QNetworkReply *reply; - int redirectCount; -}; - -QT_END_NAMESPACE - -#endif // QT_NO_MOVIE - -#endif // QQUICKANIMATEDIMAGE_P_P_H diff --git a/src/declarative/items/qquickanimation.cpp b/src/declarative/items/qquickanimation.cpp deleted file mode 100644 index 55eb4e2e13..0000000000 --- a/src/declarative/items/qquickanimation.cpp +++ /dev/null @@ -1,792 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qquickanimation_p.h" -#include "qquickanimation_p_p.h" -#include "qquickstateoperations_p.h" - -#include -#include - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QQuickParentAnimation::QQuickParentAnimation(QObject *parent) - : QDeclarativeAnimationGroup(*(new QQuickParentAnimationPrivate), parent) -{ - Q_D(QQuickParentAnimation); - d->topLevelGroup = new QSequentialAnimationGroup; - QDeclarative_setParent_noEvent(d->topLevelGroup, this); - - d->startAction = new QActionAnimation; - QDeclarative_setParent_noEvent(d->startAction, d->topLevelGroup); - d->topLevelGroup->addAnimation(d->startAction); - - d->ag = new QParallelAnimationGroup; - QDeclarative_setParent_noEvent(d->ag, d->topLevelGroup); - d->topLevelGroup->addAnimation(d->ag); - - d->endAction = new QActionAnimation; - QDeclarative_setParent_noEvent(d->endAction, d->topLevelGroup); - d->topLevelGroup->addAnimation(d->endAction); -} - -QQuickParentAnimation::~QQuickParentAnimation() -{ -} - -QQuickItem *QQuickParentAnimation::target() const -{ - Q_D(const QQuickParentAnimation); - return d->target; -} - -void QQuickParentAnimation::setTarget(QQuickItem *target) -{ - Q_D(QQuickParentAnimation); - if (target == d->target) - return; - - d->target = target; - emit targetChanged(); -} - -QQuickItem *QQuickParentAnimation::newParent() const -{ - Q_D(const QQuickParentAnimation); - return d->newParent; -} - -void QQuickParentAnimation::setNewParent(QQuickItem *newParent) -{ - Q_D(QQuickParentAnimation); - if (newParent == d->newParent) - return; - - d->newParent = newParent; - emit newParentChanged(); -} - -QQuickItem *QQuickParentAnimation::via() const -{ - Q_D(const QQuickParentAnimation); - return d->via; -} - -void QQuickParentAnimation::setVia(QQuickItem *via) -{ - Q_D(QQuickParentAnimation); - if (via == d->via) - return; - - d->via = via; - emit viaChanged(); -} - -//### mirrors same-named function in QQuickItem -QPointF QQuickParentAnimationPrivate::computeTransformOrigin(QQuickItem::TransformOrigin origin, qreal width, qreal height) const -{ - switch (origin) { - default: - case QQuickItem::TopLeft: - return QPointF(0, 0); - case QQuickItem::Top: - return QPointF(width / 2., 0); - case QQuickItem::TopRight: - return QPointF(width, 0); - case QQuickItem::Left: - return QPointF(0, height / 2.); - case QQuickItem::Center: - return QPointF(width / 2., height / 2.); - case QQuickItem::Right: - return QPointF(width, height / 2.); - case QQuickItem::BottomLeft: - return QPointF(0, height); - case QQuickItem::Bottom: - return QPointF(width / 2., height); - case QQuickItem::BottomRight: - return QPointF(width, height); - } -} - -void QQuickParentAnimation::transition(QDeclarativeStateActions &actions, - QDeclarativeProperties &modified, - TransitionDirection direction) -{ - Q_D(QQuickParentAnimation); - - struct QQuickParentAnimationData : public QAbstractAnimationAction - { - QQuickParentAnimationData() {} - ~QQuickParentAnimationData() { qDeleteAll(pc); } - - QDeclarativeStateActions actions; - //### reverse should probably apply on a per-action basis - bool reverse; - QList pc; - virtual void doAction() - { - for (int ii = 0; ii < actions.count(); ++ii) { - const QDeclarativeAction &action = actions.at(ii); - if (reverse) - action.event->reverse(); - else - action.event->execute(); - } - } - }; - - QQuickParentAnimationData *data = new QQuickParentAnimationData; - QQuickParentAnimationData *viaData = new QQuickParentAnimationData; - - bool hasExplicit = false; - if (d->target && d->newParent) { - data->reverse = false; - QDeclarativeAction myAction; - QQuickParentChange *pc = new QQuickParentChange; - pc->setObject(d->target); - pc->setParent(d->newParent); - myAction.event = pc; - data->pc << pc; - data->actions << myAction; - hasExplicit = true; - if (d->via) { - viaData->reverse = false; - QDeclarativeAction myVAction; - QQuickParentChange *vpc = new QQuickParentChange; - vpc->setObject(d->target); - vpc->setParent(d->via); - myVAction.event = vpc; - viaData->pc << vpc; - viaData->actions << myVAction; - } - //### once actions have concept of modified, - // loop to match appropriate ParentChanges and mark as modified - } - - if (!hasExplicit) - for (int i = 0; i < actions.size(); ++i) { - QDeclarativeAction &action = actions[i]; - if (action.event && action.event->typeName() == QLatin1String("ParentChange") - && (!d->target || static_cast(action.event)->object() == d->target)) { - - QQuickParentChange *pc = static_cast(action.event); - QDeclarativeAction myAction = action; - data->reverse = action.reverseEvent; - - //### this logic differs from PropertyAnimation - // (probably a result of modified vs. done) - if (d->newParent) { - QQuickParentChange *epc = new QQuickParentChange; - epc->setObject(static_cast(action.event)->object()); - epc->setParent(d->newParent); - myAction.event = epc; - data->pc << epc; - data->actions << myAction; - pc = epc; - } else { - action.actionDone = true; - data->actions << myAction; - } - - if (d->via) { - viaData->reverse = false; - QDeclarativeAction myAction; - QQuickParentChange *vpc = new QQuickParentChange; - vpc->setObject(pc->object()); - vpc->setParent(d->via); - myAction.event = vpc; - viaData->pc << vpc; - viaData->actions << myAction; - QDeclarativeAction dummyAction; - QDeclarativeAction &xAction = pc->xIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction; - QDeclarativeAction &yAction = pc->yIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction; - QDeclarativeAction &sAction = pc->scaleIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction; - QDeclarativeAction &rAction = pc->rotationIsSet() && i < actions.size()-1 ? actions[++i] : dummyAction; - QQuickItem *target = pc->object(); - QQuickItem *targetParent = action.reverseEvent ? pc->originalParent() : pc->parent(); - - //### this mirrors the logic in QQuickParentChange. - bool ok; - const QTransform &transform = targetParent->itemTransform(d->via, &ok); - if (transform.type() >= QTransform::TxShear || !ok) { - qmlInfo(this) << QQuickParentAnimation::tr("Unable to preserve appearance under complex transform"); - ok = false; - } - - qreal scale = 1; - qreal rotation = 0; - bool isRotate = (transform.type() == QTransform::TxRotate) || (transform.m11() < 0); - if (ok && !isRotate) { - if (transform.m11() == transform.m22()) - scale = transform.m11(); - else { - qmlInfo(this) << QQuickParentAnimation::tr("Unable to preserve appearance under non-uniform scale"); - ok = false; - } - } else if (ok && isRotate) { - if (transform.m11() == transform.m22()) - scale = qSqrt(transform.m11()*transform.m11() + transform.m12()*transform.m12()); - else { - qmlInfo(this) << QQuickParentAnimation::tr("Unable to preserve appearance under non-uniform scale"); - ok = false; - } - - if (scale != 0) - rotation = atan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI; - else { - qmlInfo(this) << QQuickParentAnimation::tr("Unable to preserve appearance under scale of 0"); - ok = false; - } - } - - const QPointF &point = transform.map(QPointF(xAction.toValue.toReal(),yAction.toValue.toReal())); - qreal x = point.x(); - qreal y = point.y(); - if (ok && target->transformOrigin() != QQuickItem::TopLeft) { - qreal w = target->width(); - qreal h = target->height(); - if (pc->widthIsSet() && i < actions.size() - 1) - w = actions[++i].toValue.toReal(); - if (pc->heightIsSet() && i < actions.size() - 1) - h = actions[++i].toValue.toReal(); - const QPointF &transformOrigin - = d->computeTransformOrigin(target->transformOrigin(), w,h); - qreal tempxt = transformOrigin.x(); - qreal tempyt = transformOrigin.y(); - QTransform t; - t.translate(-tempxt, -tempyt); - t.rotate(rotation); - t.scale(scale, scale); - t.translate(tempxt, tempyt); - const QPointF &offset = t.map(QPointF(0,0)); - x += offset.x(); - y += offset.y(); - } - - if (ok) { - //qDebug() << x << y << rotation << scale; - xAction.toValue = x; - yAction.toValue = y; - sAction.toValue = sAction.toValue.toReal() * scale; - rAction.toValue = rAction.toValue.toReal() + rotation; - } - } - } - } - - if (data->actions.count()) { - if (direction == QDeclarativeAbstractAnimation::Forward) { - d->startAction->setAnimAction(d->via ? viaData : data, QActionAnimation::DeleteWhenStopped); - d->endAction->setAnimAction(d->via ? data : 0, QActionAnimation::DeleteWhenStopped); - } else { - d->endAction->setAnimAction(d->via ? viaData : data, QActionAnimation::DeleteWhenStopped); - d->startAction->setAnimAction(d->via ? data : 0, QActionAnimation::DeleteWhenStopped); - } - } else { - delete data; - delete viaData; - } - - //take care of any child animations - bool valid = d->defaultProperty.isValid(); - for (int ii = 0; ii < d->animations.count(); ++ii) { - if (valid) - d->animations.at(ii)->setDefaultTarget(d->defaultProperty); - d->animations.at(ii)->transition(actions, modified, direction); - } - -} - -QAbstractAnimation *QQuickParentAnimation::qtAnimation() -{ - Q_D(QQuickParentAnimation); - return d->topLevelGroup; -} - -QQuickAnchorAnimation::QQuickAnchorAnimation(QObject *parent) -: QDeclarativeAbstractAnimation(*(new QQuickAnchorAnimationPrivate), parent) -{ - Q_D(QQuickAnchorAnimation); - d->va = new QDeclarativeBulkValueAnimator; - QDeclarative_setParent_noEvent(d->va, this); -} - -QQuickAnchorAnimation::~QQuickAnchorAnimation() -{ -} - -QAbstractAnimation *QQuickAnchorAnimation::qtAnimation() -{ - Q_D(QQuickAnchorAnimation); - return d->va; -} - -QDeclarativeListProperty QQuickAnchorAnimation::targets() -{ - Q_D(QQuickAnchorAnimation); - return QDeclarativeListProperty(this, d->targets); -} - -int QQuickAnchorAnimation::duration() const -{ - Q_D(const QQuickAnchorAnimation); - return d->va->duration(); -} - -void QQuickAnchorAnimation::setDuration(int duration) -{ - if (duration < 0) { - qmlInfo(this) << tr("Cannot set a duration of < 0"); - return; - } - - Q_D(QQuickAnchorAnimation); - if (d->va->duration() == duration) - return; - d->va->setDuration(duration); - emit durationChanged(duration); -} - -QEasingCurve QQuickAnchorAnimation::easing() const -{ - Q_D(const QQuickAnchorAnimation); - return d->va->easingCurve(); -} - -void QQuickAnchorAnimation::setEasing(const QEasingCurve &e) -{ - Q_D(QQuickAnchorAnimation); - if (d->va->easingCurve() == e) - return; - - d->va->setEasingCurve(e); - emit easingChanged(e); -} - -void QQuickAnchorAnimation::transition(QDeclarativeStateActions &actions, - QDeclarativeProperties &modified, - TransitionDirection direction) -{ - Q_UNUSED(modified); - Q_D(QQuickAnchorAnimation); - QDeclarativeAnimationPropertyUpdater *data = new QDeclarativeAnimationPropertyUpdater; - data->interpolatorType = QMetaType::QReal; - data->interpolator = d->interpolator; - - data->reverse = direction == Backward ? true : false; - data->fromSourced = false; - data->fromDefined = false; - - for (int ii = 0; ii < actions.count(); ++ii) { - QDeclarativeAction &action = actions[ii]; - if (action.event && action.event->typeName() == QLatin1String("AnchorChanges") - && (d->targets.isEmpty() || d->targets.contains(static_cast(action.event)->object()))) { - data->actions << static_cast(action.event)->additionalActions(); - } - } - - if (data->actions.count()) { - if (!d->rangeIsSet) { - d->va->setStartValue(qreal(0)); - d->va->setEndValue(qreal(1)); - d->rangeIsSet = true; - } - d->va->setAnimValue(data, QAbstractAnimation::DeleteWhenStopped); - d->va->setFromSourcedValue(&data->fromSourced); - } else { - delete data; - } -} - -QQuickPathAnimation::QQuickPathAnimation(QObject *parent) -: QDeclarativeAbstractAnimation(*(new QQuickPathAnimationPrivate), parent) -{ - Q_D(QQuickPathAnimation); - d->pa = new QDeclarativeBulkValueAnimator; - QDeclarative_setParent_noEvent(d->pa, this); -} - -QQuickPathAnimation::~QQuickPathAnimation() -{ -} - -int QQuickPathAnimation::duration() const -{ - Q_D(const QQuickPathAnimation); - return d->pa->duration(); -} - -void QQuickPathAnimation::setDuration(int duration) -{ - if (duration < 0) { - qmlInfo(this) << tr("Cannot set a duration of < 0"); - return; - } - - Q_D(QQuickPathAnimation); - if (d->pa->duration() == duration) - return; - d->pa->setDuration(duration); - emit durationChanged(duration); -} - -QEasingCurve QQuickPathAnimation::easing() const -{ - Q_D(const QQuickPathAnimation); - return d->pa->easingCurve(); -} - -void QQuickPathAnimation::setEasing(const QEasingCurve &e) -{ - Q_D(QQuickPathAnimation); - if (d->pa->easingCurve() == e) - return; - - d->pa->setEasingCurve(e); - emit easingChanged(e); -} - -QDeclarativePath *QQuickPathAnimation::path() const -{ - Q_D(const QQuickPathAnimation); - return d->path; -} - -void QQuickPathAnimation::setPath(QDeclarativePath *path) -{ - Q_D(QQuickPathAnimation); - if (d->path == path) - return; - - d->path = path; - emit pathChanged(); -} - -QQuickItem *QQuickPathAnimation::target() const -{ - Q_D(const QQuickPathAnimation); - return d->target; -} - -void QQuickPathAnimation::setTarget(QQuickItem *target) -{ - Q_D(QQuickPathAnimation); - if (d->target == target) - return; - - d->target = target; - emit targetChanged(); -} - -QQuickPathAnimation::Orientation QQuickPathAnimation::orientation() const -{ - Q_D(const QQuickPathAnimation); - return d->orientation; -} - -void QQuickPathAnimation::setOrientation(Orientation orientation) -{ - Q_D(QQuickPathAnimation); - if (d->orientation == orientation) - return; - - d->orientation = orientation; - emit orientationChanged(d->orientation); -} - -QPointF QQuickPathAnimation::anchorPoint() const -{ - Q_D(const QQuickPathAnimation); - return d->anchorPoint; -} - -void QQuickPathAnimation::setAnchorPoint(const QPointF &point) -{ - Q_D(QQuickPathAnimation); - if (d->anchorPoint == point) - return; - - d->anchorPoint = point; - emit anchorPointChanged(point); -} - -qreal QQuickPathAnimation::orientationEntryInterval() const -{ - Q_D(const QQuickPathAnimation); - return d->entryInterval; -} - -void QQuickPathAnimation::setOrientationEntryInterval(qreal interval) -{ - Q_D(QQuickPathAnimation); - if (d->entryInterval == interval) - return; - d->entryInterval = interval; - emit orientationEntryIntervalChanged(interval); -} - -qreal QQuickPathAnimation::orientationExitInterval() const -{ - Q_D(const QQuickPathAnimation); - return d->exitInterval; -} - -void QQuickPathAnimation::setOrientationExitInterval(qreal interval) -{ - Q_D(QQuickPathAnimation); - if (d->exitInterval == interval) - return; - d->exitInterval = interval; - emit orientationExitIntervalChanged(interval); -} - -qreal QQuickPathAnimation::endRotation() const -{ - Q_D(const QQuickPathAnimation); - return d->endRotation.isNull ? qreal(0) : d->endRotation.value; -} - -void QQuickPathAnimation::setEndRotation(qreal rotation) -{ - Q_D(QQuickPathAnimation); - if (!d->endRotation.isNull && d->endRotation == rotation) - return; - - d->endRotation = rotation; - emit endRotationChanged(d->endRotation); -} - - -QAbstractAnimation *QQuickPathAnimation::qtAnimation() -{ - Q_D(QQuickPathAnimation); - return d->pa; -} - -void QQuickPathAnimation::transition(QDeclarativeStateActions &actions, - QDeclarativeProperties &modified, - TransitionDirection direction) -{ - Q_D(QQuickPathAnimation); - QQuickPathAnimationUpdater *data = new QQuickPathAnimationUpdater; - - data->orientation = d->orientation; - data->anchorPoint = d->anchorPoint; - data->entryInterval = d->entryInterval; - data->exitInterval = d->exitInterval; - data->endRotation = d->endRotation; - data->reverse = direction == Backward ? true : false; - data->fromSourced = false; - data->fromDefined = (d->path && d->path->hasStartX() && d->path->hasStartY()) ? true : false; - data->toDefined = d->path ? d->path->hasEnd() : false; - int origModifiedSize = modified.count(); - - for (int i = 0; i < actions.count(); ++i) { - QDeclarativeAction &action = actions[i]; - if (action.event) - continue; - if (action.specifiedObject == d->target && action.property.name() == QLatin1String("x")) { - data->toX = action.toValue.toReal(); - modified << action.property; - action.fromValue = action.toValue; - } - if (action.specifiedObject == d->target && action.property.name() == QLatin1String("y")) { - data->toY = action.toValue.toReal(); - modified << action.property; - action.fromValue = action.toValue; - } - } - - if (d->target && d->path && - (modified.count() > origModifiedSize || data->toDefined)) { - data->target = d->target; - data->path = d->path; - if (!d->rangeIsSet) { - d->pa->setStartValue(qreal(0)); - d->pa->setEndValue(qreal(1)); - d->rangeIsSet = true; - } - /* - NOTE: The following block relies on the fact that the previous value hasn't - yet been deleted, and has the same target, etc, which may be a bit fragile. - */ - if (d->pa->getAnimValue()) { - QQuickPathAnimationUpdater *prevData = static_cast(d->pa->getAnimValue()); - - // get the original start angle that was used (so we can exactly reverse). - data->startRotation = prevData->startRotation; - - // treat interruptions specially, otherwise we end up with strange paths - if ((data->reverse || prevData->reverse) && prevData->currentV > 0 && prevData->currentV < 1) { - if (!data->fromDefined && !data->toDefined && !prevData->painterPath.isEmpty()) { - QPointF pathPos = QDeclarativePath::sequentialPointAt(prevData->painterPath, prevData->pathLength, prevData->attributePoints, prevData->prevBez, prevData->currentV); - if (!prevData->anchorPoint.isNull()) - pathPos -= prevData->anchorPoint; - if (pathPos == data->target->pos()) { //only treat as interruption if we interrupted ourself - data->painterPath = prevData->painterPath; - data->toDefined = data->fromDefined = data->fromSourced = true; - data->prevBez.isValid = false; - data->interruptStart = prevData->currentV; - data->startRotation = prevData->startRotation; - data->pathLength = prevData->pathLength; - data->attributePoints = prevData->attributePoints; - } - } - } - } - d->pa->setFromSourcedValue(&data->fromSourced); - d->pa->setAnimValue(data, QAbstractAnimation::DeleteWhenStopped); - } else { - d->pa->setFromSourcedValue(0); - d->pa->setAnimValue(0, QAbstractAnimation::DeleteWhenStopped); - delete data; - } -} - -void QQuickPathAnimationUpdater::setValue(qreal v) -{ - if (interruptStart.isValid()) { - if (reverse) - v = 1 - v; - qreal end = reverse ? 0.0 : 1.0; - v = interruptStart + v * (end-interruptStart); - } - currentV = v; - bool atStart = ((reverse && v == 1.0) || (!reverse && v == 0.0)); - if (!fromSourced && (!fromDefined || !toDefined)) { - qreal startX = reverse ? toX + anchorPoint.x() : target->x() + anchorPoint.x(); - qreal startY = reverse ? toY + anchorPoint.y() : target->y() + anchorPoint.y(); - qreal endX = reverse ? target->x() + anchorPoint.x() : toX + anchorPoint.x(); - qreal endY = reverse ? target->y() + anchorPoint.y() : toY + anchorPoint.y(); - - prevBez.isValid = false; - painterPath = path->createPath(QPointF(startX, startY), QPointF(endX, endY), QStringList(), pathLength, attributePoints); - fromSourced = true; - } - - qreal angle; - bool fixed = orientation == QQuickPathAnimation::Fixed; - QPointF currentPos = !painterPath.isEmpty() ? path->sequentialPointAt(painterPath, pathLength, attributePoints, prevBez, v, fixed ? 0 : &angle) : path->sequentialPointAt(v, fixed ? 0 : &angle); - - //adjust position according to anchor point - if (!anchorPoint.isNull()) { - currentPos -= anchorPoint; - if (atStart) { - if (!anchorPoint.isNull() && !fixed) - target->setTransformOriginPoint(anchorPoint); - } - } - - //### could cache properties rather than reconstructing each time - QDeclarativePropertyPrivate::write(QDeclarativeProperty(target, QStringLiteral("x")), currentPos.x(), QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); - QDeclarativePropertyPrivate::write(QDeclarativeProperty(target, QStringLiteral("y")), currentPos.y(), QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); - - //adjust angle according to orientation - if (!fixed) { - switch (orientation) { - case QQuickPathAnimation::RightFirst: - angle = -angle; - break; - case QQuickPathAnimation::TopFirst: - angle = -angle + 90; - break; - case QQuickPathAnimation::LeftFirst: - angle = -angle + 180; - break; - case QQuickPathAnimation::BottomFirst: - angle = -angle + 270; - break; - default: - angle = 0; - break; - } - - if (atStart && !reverse) { - startRotation = target->rotation(); - - //shortest distance to correct orientation - qreal diff = angle - startRotation; - while (diff > 180.0) { - startRotation.value += 360.0; - diff -= 360.0; - } - while (diff < -180.0) { - startRotation.value -= 360.0; - diff += 360.0; - } - } - - //smoothly transition to the desired orientation - if (startRotation.isValid()) { - if (reverse && v == 0.0) - angle = startRotation; - else if (v < entryInterval) - angle = angle * v / entryInterval + startRotation * (entryInterval - v) / entryInterval; - } - if (endRotation.isValid()) { - qreal exitStart = 1 - exitInterval; - if (!reverse && v == 1.0) - angle = endRotation; - else if (v > exitStart) - angle = endRotation * (v - exitStart) / exitInterval + angle * (exitInterval - (v - exitStart)) / exitInterval; - } - QDeclarativePropertyPrivate::write(QDeclarativeProperty(target, QStringLiteral("rotation")), angle, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding); - } - - /* - NOTE: we don't always reset the transform origin, as it can cause a - visual jump if ending on an angle. This means that in some cases - (anchor point and orientation both specified, and ending at an angle) - the transform origin will always be set after running the path animation. - */ - if ((reverse && v == 0.0) || (!reverse && v == 1.0)) { - if (!anchorPoint.isNull() && !fixed && qFuzzyIsNull(angle)) - target->setTransformOriginPoint(QPointF()); - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickanimation_p.h b/src/declarative/items/qquickanimation_p.h deleted file mode 100644 index 2ce72249e2..0000000000 --- a/src/declarative/items/qquickanimation_p.h +++ /dev/null @@ -1,209 +0,0 @@ -// Commit: e39a2e39451bf106a9845f8a60fc571faaa4dde5 -/**************************************************************************** -** -** 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$ -** 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 QQUICKANIMATION_H -#define QQUICKANIMATION_H - -#include "qquickitem.h" - -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickParentAnimationPrivate; -class QQuickParentAnimation : public QDeclarativeAnimationGroup -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QQuickParentAnimation) - - Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged) - Q_PROPERTY(QQuickItem *newParent READ newParent WRITE setNewParent NOTIFY newParentChanged) - Q_PROPERTY(QQuickItem *via READ via WRITE setVia NOTIFY viaChanged) - -public: - QQuickParentAnimation(QObject *parent=0); - virtual ~QQuickParentAnimation(); - - QQuickItem *target() const; - void setTarget(QQuickItem *); - - QQuickItem *newParent() const; - void setNewParent(QQuickItem *); - - QQuickItem *via() const; - void setVia(QQuickItem *); - -Q_SIGNALS: - void targetChanged(); - void newParentChanged(); - void viaChanged(); - -protected: - virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); -}; - -class QQuickAnchorAnimationPrivate; -class QQuickAnchorAnimation : public QDeclarativeAbstractAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QQuickAnchorAnimation) - Q_PROPERTY(QDeclarativeListProperty targets READ targets) - Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) - Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged) - -public: - QQuickAnchorAnimation(QObject *parent=0); - virtual ~QQuickAnchorAnimation(); - - QDeclarativeListProperty targets(); - - int duration() const; - void setDuration(int); - - QEasingCurve easing() const; - void setEasing(const QEasingCurve &); - -Q_SIGNALS: - void durationChanged(int); - void easingChanged(const QEasingCurve&); - -protected: - virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); -}; - -class QQuickItem; -class QDeclarativePath; -class QQuickPathAnimationPrivate; -class Q_AUTOTEST_EXPORT QQuickPathAnimation : public QDeclarativeAbstractAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QQuickPathAnimation) - - Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) - Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged) - Q_PROPERTY(QDeclarativePath *path READ path WRITE setPath NOTIFY pathChanged) - Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged) - Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) - Q_PROPERTY(QPointF anchorPoint READ anchorPoint WRITE setAnchorPoint NOTIFY anchorPointChanged) - Q_PROPERTY(qreal orientationEntryInterval READ orientationEntryInterval WRITE setOrientationEntryInterval NOTIFY orientationEntryIntervalChanged) - Q_PROPERTY(qreal orientationExitInterval READ orientationExitInterval WRITE setOrientationExitInterval NOTIFY orientationExitIntervalChanged) - Q_PROPERTY(qreal endRotation READ endRotation WRITE setEndRotation NOTIFY endRotationChanged) - -public: - QQuickPathAnimation(QObject *parent=0); - virtual ~QQuickPathAnimation(); - - enum Orientation { - Fixed, - RightFirst, - LeftFirst, - BottomFirst, - TopFirst - }; - Q_ENUMS(Orientation) - - int duration() const; - void setDuration(int); - - QEasingCurve easing() const; - void setEasing(const QEasingCurve &); - - QDeclarativePath *path() const; - void setPath(QDeclarativePath *); - - QQuickItem *target() const; - void setTarget(QQuickItem *); - - Orientation orientation() const; - void setOrientation(Orientation orientation); - - QPointF anchorPoint() const; - void setAnchorPoint(const QPointF &point); - - qreal orientationEntryInterval() const; - void setOrientationEntryInterval(qreal); - - qreal orientationExitInterval() const; - void setOrientationExitInterval(qreal); - - qreal endRotation() const; - void setEndRotation(qreal); - -protected: - virtual void transition(QDeclarativeStateActions &actions, - QDeclarativeProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); - -Q_SIGNALS: - void durationChanged(int); - void easingChanged(const QEasingCurve &); - void pathChanged(); - void targetChanged(); - void orientationChanged(Orientation); - void anchorPointChanged(const QPointF &); - void orientationEntryIntervalChanged(qreal); - void orientationExitIntervalChanged(qreal); - void endRotationChanged(qreal); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickParentAnimation) -QML_DECLARE_TYPE(QQuickAnchorAnimation) -QML_DECLARE_TYPE(QQuickPathAnimation) - -QT_END_HEADER - -#endif // QQUICKANIMATION_H diff --git a/src/declarative/items/qquickanimation_p_p.h b/src/declarative/items/qquickanimation_p_p.h deleted file mode 100644 index de2b6d42f9..0000000000 --- a/src/declarative/items/qquickanimation_p_p.h +++ /dev/null @@ -1,153 +0,0 @@ -// Commit: 0ade09152067324f74678f2de4d447b6e0280600 -/**************************************************************************** -** -** 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$ -** 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 QQUICKANIMATION_P_H -#define QQUICKANIMATION_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 "qquickanimation_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickParentAnimationPrivate : public QDeclarativeAnimationGroupPrivate -{ - Q_DECLARE_PUBLIC(QQuickParentAnimation) -public: - QQuickParentAnimationPrivate() - : QDeclarativeAnimationGroupPrivate(), target(0), newParent(0), - via(0), topLevelGroup(0), startAction(0), endAction(0) {} - - QQuickItem *target; - QQuickItem *newParent; - QQuickItem *via; - - QSequentialAnimationGroup *topLevelGroup; - QActionAnimation *startAction; - QActionAnimation *endAction; - - QPointF computeTransformOrigin(QQuickItem::TransformOrigin origin, qreal width, qreal height) const; -}; - -class QQuickAnchorAnimationPrivate : public QDeclarativeAbstractAnimationPrivate -{ - Q_DECLARE_PUBLIC(QQuickAnchorAnimation) -public: - QQuickAnchorAnimationPrivate() : rangeIsSet(false), va(0), - interpolator(QVariantAnimationPrivate::getInterpolator(QMetaType::QReal)) {} - - bool rangeIsSet; - QDeclarativeBulkValueAnimator *va; - QVariantAnimation::Interpolator interpolator; - QList targets; -}; - -class QQuickPathAnimationUpdater : public QDeclarativeBulkValueUpdater -{ -public: - QQuickPathAnimationUpdater() : path(0), target(0), reverse(false), - fromSourced(false), fromDefined(false), toDefined(false), - toX(0), toY(0), currentV(0), orientation(QQuickPathAnimation::Fixed), - entryInterval(0), exitInterval(0) {} - ~QQuickPathAnimationUpdater() {} - - void setValue(qreal v); - - QDeclarativePath *path; - - QPainterPath painterPath; - QDeclarativeCachedBezier prevBez; - qreal pathLength; - QList attributePoints; - - QQuickItem *target; - bool reverse; - bool fromSourced; - bool fromDefined; - bool toDefined; - qreal toX; - qreal toY; - qreal currentV; - QDeclarativeNullableValue interruptStart; - //TODO: bundle below into common struct - QQuickPathAnimation::Orientation orientation; - QPointF anchorPoint; - qreal entryInterval; - qreal exitInterval; - QDeclarativeNullableValue endRotation; - QDeclarativeNullableValue startRotation; -}; - -class QQuickPathAnimationPrivate : public QDeclarativeAbstractAnimationPrivate -{ - Q_DECLARE_PUBLIC(QQuickPathAnimation) -public: - QQuickPathAnimationPrivate() : path(0), target(0), - rangeIsSet(false), orientation(QQuickPathAnimation::Fixed), entryInterval(0), exitInterval(0), pa(0) {} - - QDeclarativePath *path; - QQuickItem *target; - bool rangeIsSet; - QQuickPathAnimation::Orientation orientation; - QPointF anchorPoint; - qreal entryInterval; - qreal exitInterval; - QDeclarativeNullableValue endRotation; - QDeclarativeBulkValueAnimator *pa; -}; - - -QT_END_NAMESPACE - -#endif // QQUICKANIMATION_P_H diff --git a/src/declarative/items/qquickborderimage.cpp b/src/declarative/items/qquickborderimage.cpp deleted file mode 100644 index e0ffd716aa..0000000000 --- a/src/declarative/items/qquickborderimage.cpp +++ /dev/null @@ -1,600 +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 QtDeclarative module 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 "qquickborderimage_p.h" -#include "qquickborderimage_p_p.h" -#include "qquickninepatchnode_p.h" - -#include -#include - -#include - -QT_BEGIN_NAMESPACE - - -/*! - \qmlclass BorderImage QQuickBorderImage - \inqmlmodule QtQuick 2 - \brief The BorderImage element provides an image that can be used as a border. - \inherits Item - \ingroup qml-basic-visual-elements - - The BorderImage element is used to create borders out of images by scaling or tiling - parts of each image. - - A BorderImage element breaks a source image, specified using the \l url property, - into 9 regions, as shown below: - - \image declarative-scalegrid.png - - When the image is scaled, regions of the source image are scaled or tiled to - create the displayed border image in the following way: - - \list - \i The corners (regions 1, 3, 7, and 9) are not scaled at all. - \i Regions 2 and 8 are scaled according to - \l{BorderImage::horizontalTileMode}{horizontalTileMode}. - \i Regions 4 and 6 are scaled according to - \l{BorderImage::verticalTileMode}{verticalTileMode}. - \i The middle (region 5) is scaled according to both - \l{BorderImage::horizontalTileMode}{horizontalTileMode} and - \l{BorderImage::verticalTileMode}{verticalTileMode}. - \endlist - - The regions of the image are defined using the \l border property group, which - describes the distance from each edge of the source image to use as a border. - - \section1 Example Usage - - The following examples show the effects of the different modes on an image. - Guide lines are overlaid onto the image to show the different regions of the - image as described above. - - \beginfloatleft - \image qml-borderimage-normal-image.png - \endfloat - - An unscaled image is displayed using an Image element. The \l border property is - used to determine the parts of the image that will lie inside the unscaled corner - areas and the parts that will be stretched horizontally and vertically. - - \snippet doc/src/snippets/declarative/borderimage/normal-image.qml normal image - - \clearfloat - \beginfloatleft - \image qml-borderimage-scaled.png - \endfloat - - A BorderImage element is used to display the image, and it is given a size that is - larger than the original image. Since the \l horizontalTileMode property is set to - \l{BorderImage::horizontalTileMode}{BorderImage.Stretch}, the parts of image in - regions 2 and 8 are stretched horizontally. Since the \l verticalTileMode property - is set to \l{BorderImage::verticalTileMode}{BorderImage.Stretch}, the parts of image - in regions 4 and 6 are stretched vertically. - - \snippet doc/src/snippets/declarative/borderimage/borderimage-scaled.qml scaled border image - - \clearfloat - \beginfloatleft - \image qml-borderimage-tiled.png - \endfloat - - Again, a large BorderImage element is used to display the image. With the - \l horizontalTileMode property set to \l{BorderImage::horizontalTileMode}{BorderImage.Repeat}, - the parts of image in regions 2 and 8 are tiled so that they fill the space at the - top and bottom of the element. Similarly, the \l verticalTileMode property is set to - \l{BorderImage::verticalTileMode}{BorderImage.Repeat}, the parts of image in regions - 4 and 6 are tiled so that they fill the space at the left and right of the element. - - \snippet doc/src/snippets/declarative/borderimage/borderimage-tiled.qml tiled border image - - \clearfloat - In some situations, the width of regions 2 and 8 may not be an exact multiple of the width - of the corresponding regions in the source image. Similarly, the height of regions 4 and 6 - may not be an exact multiple of the height of the corresponding regions. It can be useful - to use \l{BorderImage::horizontalTileMode}{BorderImage.Round} instead of - \l{BorderImage::horizontalTileMode}{BorderImage.Repeat} in cases like these. - - The \l{declarative/imageelements/borderimage}{BorderImage example} shows how a BorderImage - can be used to simulate a shadow effect on a rectangular item. - - \section1 Quality and Performance - - By default, any scaled regions of the image are rendered without smoothing to improve - rendering speed. Setting the \l smooth property improves rendering quality of scaled - regions, but may slow down rendering. - - The source image may not be loaded instantaneously, depending on its original location. - Loading progress can be monitored with the \l progress property. - - \sa Image, AnimatedImage - */ - -/*! - \qmlproperty bool QtQuick2::BorderImage::asynchronous - - Specifies that images on the local filesystem should be loaded - asynchronously in a separate thread. The default value is - false, causing the user interface thread to block while the - image is loaded. Setting \a asynchronous to true is useful where - maintaining a responsive user interface is more desirable - than having images immediately visible. - - Note that this property is only valid for images read from the - local filesystem. Images loaded via a network resource (e.g. HTTP) - are always loaded asynchronously. -*/ -QQuickBorderImage::QQuickBorderImage(QQuickItem *parent) -: QQuickImageBase(*(new QQuickBorderImagePrivate), parent) -{ -} - -QQuickBorderImage::~QQuickBorderImage() -{ - Q_D(QQuickBorderImage); - if (d->sciReply) - d->sciReply->deleteLater(); -} - -/*! - \qmlproperty enumeration QtQuick2::BorderImage::status - - This property describes the status of image loading. It can be one of: - - \list - \o BorderImage.Null - no image has been set - \o BorderImage.Ready - the image has been loaded - \o BorderImage.Loading - the image is currently being loaded - \o BorderImage.Error - an error occurred while loading the image - \endlist - - \sa progress -*/ - -/*! - \qmlproperty real QtQuick2::BorderImage::progress - - This property holds the progress of image loading, from 0.0 (nothing loaded) - to 1.0 (finished). - - \sa status -*/ - -/*! - \qmlproperty bool QtQuick2::BorderImage::smooth - - Set this property if you want the image to be smoothly filtered when scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If - the image is displayed at its natural size, this property has no visual or - performance effect. - - By default, this property is set to false. - - \note Generally scaling artifacts are only visible if the image is stationary on - the screen. A common pattern when animating an image is to disable smooth - filtering at the beginning of the animation and enable it at the conclusion. -*/ - -/*! - \qmlproperty bool QtQuick2::BorderImage::cache - - Specifies whether the image should be cached. The default value is - true. Setting \a cache to false is useful when dealing with large images, - to make sure that they aren't cached at the expense of small 'ui element' images. -*/ - -/*! - \qmlproperty bool QtQuick2::BorderImage::mirror - - This property holds whether the image should be horizontally inverted - (effectively displaying a mirrored image). - - The default value is false. -*/ - -/*! - \qmlproperty url QtQuick2::BorderImage::source - - This property holds the URL that refers to the source image. - - BorderImage can handle any image format supported by Qt, loaded from any - URL scheme supported by Qt. - - This property can also be used to refer to .sci files, which are - written in a QML-specific, text-based format that specifies the - borders, the image file and the tile rules for a given border image. - - The following .sci file sets the borders to 10 on each side for the - image \c picture.png: - - \code - border.left: 10 - border.top: 10 - border.bottom: 10 - border.right: 10 - source: "picture.png" - \endcode - - The URL may be absolute, or relative to the URL of the component. - - \sa QDeclarativeImageProvider -*/ - -/*! - \qmlproperty QSize QtQuick2::BorderImage::sourceSize - - This property holds the actual width and height of the loaded image. - - In BorderImage, this property is read-only. - - \sa Image::sourceSize -*/ -void QQuickBorderImage::setSource(const QUrl &url) -{ - Q_D(QQuickBorderImage); - //equality is fairly expensive, so we bypass for simple, common case - if ((d->url.isEmpty() == url.isEmpty()) && url == d->url) - return; - - if (d->sciReply) { - d->sciReply->deleteLater(); - d->sciReply = 0; - } - - d->url = url; - d->sciurl = QUrl(); - emit sourceChanged(d->url); - - if (isComponentComplete()) - load(); -} - -void QQuickBorderImage::load() -{ - Q_D(QQuickBorderImage); - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } - - if (d->url.isEmpty()) { - d->pix.clear(this); - d->status = Null; - setImplicitSize(0, 0); - emit statusChanged(d->status); - update(); - } else { - d->status = Loading; - if (d->url.path().endsWith(QLatin1String("sci"))) { - QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(d->url); - if (!lf.isEmpty()) { - QFile file(lf); - file.open(QIODevice::ReadOnly); - setGridScaledImage(QQuickGridScaledImage(&file)); - } else { - QNetworkRequest req(d->url); - d->sciReply = qmlEngine(this)->networkAccessManager()->get(req); - FAST_CONNECT(d->sciReply, SIGNAL(finished()), this, SLOT(sciRequestFinished())) - } - } else { - - QDeclarativePixmap::Options options; - if (d->async) - options |= QDeclarativePixmap::Asynchronous; - if (d->cache) - options |= QDeclarativePixmap::Cache; - d->pix.clear(this); - d->pix.load(qmlEngine(this), d->url, options); - - if (d->pix.isLoading()) { - d->pix.connectFinished(this, SLOT(requestFinished())); - d->pix.connectDownloadProgress(this, SLOT(requestProgress(qint64,qint64))); - } else { - QSize impsize = d->pix.implicitSize(); - setImplicitSize(impsize.width(), impsize.height()); - - if (d->pix.isReady()) { - d->status = Ready; - } else { - d->status = Error; - qmlInfo(this) << d->pix.error(); - } - - d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(d->progress); - update(); - } - } - } - - emit statusChanged(d->status); -} - -/*! - \qmlproperty int QtQuick2::BorderImage::border.left - \qmlproperty int QtQuick2::BorderImage::border.right - \qmlproperty int QtQuick2::BorderImage::border.top - \qmlproperty int QtQuick2::BorderImage::border.bottom - - The 4 border lines (2 horizontal and 2 vertical) break the image into 9 sections, - as shown below: - - \image declarative-scalegrid.png - - Each border line (left, right, top, and bottom) specifies an offset in pixels - from the respective edge of the source image. By default, each border line has - a value of 0. - - For example, the following definition sets the bottom line 10 pixels up from - the bottom of the image: - - \qml - BorderImage { - border.bottom: 10 - // ... - } - \endqml - - The border lines can also be specified using a - \l {BorderImage::source}{.sci file}. -*/ - -QQuickScaleGrid *QQuickBorderImage::border() -{ - Q_D(QQuickBorderImage); - return d->getScaleGrid(); -} - -/*! - \qmlproperty enumeration QtQuick2::BorderImage::horizontalTileMode - \qmlproperty enumeration QtQuick2::BorderImage::verticalTileMode - - This property describes how to repeat or stretch the middle parts of the border image. - - \list - \o BorderImage.Stretch - Scales the image to fit to the available area. - \o BorderImage.Repeat - Tile the image until there is no more space. May crop the last image. - \o BorderImage.Round - Like Repeat, but scales the images down to ensure that the last image is not cropped. - \endlist - - The default tile mode for each property is BorderImage.Stretch. -*/ -QQuickBorderImage::TileMode QQuickBorderImage::horizontalTileMode() const -{ - Q_D(const QQuickBorderImage); - return d->horizontalTileMode; -} - -void QQuickBorderImage::setHorizontalTileMode(TileMode t) -{ - Q_D(QQuickBorderImage); - if (t != d->horizontalTileMode) { - d->horizontalTileMode = t; - emit horizontalTileModeChanged(); - update(); - } -} - -QQuickBorderImage::TileMode QQuickBorderImage::verticalTileMode() const -{ - Q_D(const QQuickBorderImage); - return d->verticalTileMode; -} - -void QQuickBorderImage::setVerticalTileMode(TileMode t) -{ - Q_D(QQuickBorderImage); - if (t != d->verticalTileMode) { - d->verticalTileMode = t; - emit verticalTileModeChanged(); - update(); - } -} - -void QQuickBorderImage::setGridScaledImage(const QQuickGridScaledImage& sci) -{ - Q_D(QQuickBorderImage); - if (!sci.isValid()) { - d->status = Error; - emit statusChanged(d->status); - } else { - QQuickScaleGrid *sg = border(); - sg->setTop(sci.gridTop()); - sg->setBottom(sci.gridBottom()); - sg->setLeft(sci.gridLeft()); - sg->setRight(sci.gridRight()); - d->horizontalTileMode = sci.horizontalTileRule(); - d->verticalTileMode = sci.verticalTileRule(); - - d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); - - QDeclarativePixmap::Options options; - if (d->async) - options |= QDeclarativePixmap::Asynchronous; - if (d->cache) - options |= QDeclarativePixmap::Cache; - d->pix.clear(this); - d->pix.load(qmlEngine(this), d->sciurl, options); - - if (d->pix.isLoading()) { - static int thisRequestProgress = -1; - static int thisRequestFinished = -1; - if (thisRequestProgress == -1) { - thisRequestProgress = - QQuickBorderImage::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); - thisRequestFinished = - QQuickBorderImage::staticMetaObject.indexOfSlot("requestFinished()"); - } - - d->pix.connectFinished(this, thisRequestFinished); - d->pix.connectDownloadProgress(this, thisRequestProgress); - - } else { - - QSize impsize = d->pix.implicitSize(); - setImplicitSize(impsize.width(), impsize.height()); - - if (d->pix.isReady()) { - d->status = Ready; - } else { - d->status = Error; - qmlInfo(this) << d->pix.error(); - } - - d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(1.0); - update(); - - } - } -} - -void QQuickBorderImage::requestFinished() -{ - Q_D(QQuickBorderImage); - - QSize impsize = d->pix.implicitSize(); - if (d->pix.isError()) { - d->status = Error; - qmlInfo(this) << d->pix.error(); - } else { - d->status = Ready; - } - - setImplicitSize(impsize.width(), impsize.height()); - - if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height()) - emit sourceSizeChanged(); - - d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(1.0); - update(); -} - -#define BORDERIMAGE_MAX_REDIRECT 16 - -void QQuickBorderImage::sciRequestFinished() -{ - Q_D(QQuickBorderImage); - - d->redirectCount++; - if (d->redirectCount < BORDERIMAGE_MAX_REDIRECT) { - QVariant redirect = d->sciReply->attribute(QNetworkRequest::RedirectionTargetAttribute); - if (redirect.isValid()) { - QUrl url = d->sciReply->url().resolved(redirect.toUrl()); - setSource(url); - return; - } - } - d->redirectCount=0; - - if (d->sciReply->error() != QNetworkReply::NoError) { - d->status = Error; - d->sciReply->deleteLater(); - d->sciReply = 0; - emit statusChanged(d->status); - } else { - QQuickGridScaledImage sci(d->sciReply); - d->sciReply->deleteLater(); - d->sciReply = 0; - setGridScaledImage(sci); - } -} - -void QQuickBorderImage::doUpdate() -{ - update(); -} - -QSGNode *QQuickBorderImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - Q_D(QQuickBorderImage); - - QSGTexture *texture = d->sceneGraphContext()->textureForFactory(d->pix.textureFactory()); - - if (!texture || width() <= 0 || height() <= 0) { - delete oldNode; - return 0; - } - - QQuickNinePatchNode *node = static_cast(oldNode); - - if (!node) { - node = new QQuickNinePatchNode(); - } - - node->setTexture(texture); - - // Don't implicitly create the scalegrid in the rendering thread... - if (d->border) { - const QQuickScaleGrid *border = d->getScaleGrid(); - node->setInnerRect(QRectF(border->left(), - border->top(), - qMax(1, d->pix.width() - border->right() - border->left()), - qMax(1, d->pix.height() - border->bottom() - border->top()))); - } else { - node->setInnerRect(QRectF(0, 0, d->pix.width(), d->pix.height())); - } - node->setRect(QRectF(0, 0, width(), height())); - node->setFiltering(d->smooth ? QSGTexture::Linear : QSGTexture::Nearest); - node->setHorzontalTileMode(d->horizontalTileMode); - node->setVerticalTileMode(d->verticalTileMode); - node->setMirror(d->mirror); - node->update(); - - return node; -} - -void QQuickBorderImage::pixmapChange() -{ - Q_D(QQuickBorderImage); - - d->pixmapChanged = true; - - // When the pixmap changes, such as being deleted, we need to update the textures - update(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickborderimage_p.h b/src/declarative/items/qquickborderimage_p.h deleted file mode 100644 index 0af6fca55d..0000000000 --- a/src/declarative/items/qquickborderimage_p.h +++ /dev/null @@ -1,110 +0,0 @@ -// Commit: ebd4bc73c46c2962742a682b6a391fb68c482aec -/**************************************************************************** -** -** 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$ -** 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 QQUICKBORDERIMAGE_P_H -#define QQUICKBORDERIMAGE_P_H - -#include "qquickimagebase_p.h" - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickScaleGrid; -class QQuickGridScaledImage; -class QQuickBorderImagePrivate; -class Q_AUTOTEST_EXPORT QQuickBorderImage : public QQuickImageBase -{ - Q_OBJECT - Q_ENUMS(TileMode) - - Q_PROPERTY(QQuickScaleGrid *border READ border CONSTANT) - Q_PROPERTY(TileMode horizontalTileMode READ horizontalTileMode WRITE setHorizontalTileMode NOTIFY horizontalTileModeChanged) - Q_PROPERTY(TileMode verticalTileMode READ verticalTileMode WRITE setVerticalTileMode NOTIFY verticalTileModeChanged) - // read-only for BorderImage - Q_PROPERTY(QSize sourceSize READ sourceSize NOTIFY sourceSizeChanged) - -public: - QQuickBorderImage(QQuickItem *parent=0); - ~QQuickBorderImage(); - - QQuickScaleGrid *border(); - - enum TileMode { Stretch = Qt::StretchTile, Repeat = Qt::RepeatTile, Round = Qt::RoundTile }; - - TileMode horizontalTileMode() const; - void setHorizontalTileMode(TileMode); - - TileMode verticalTileMode() const; - void setVerticalTileMode(TileMode); - - void setSource(const QUrl &url); - -Q_SIGNALS: - void horizontalTileModeChanged(); - void verticalTileModeChanged(); - void sourceSizeChanged(); - -protected: - virtual void load(); - virtual void pixmapChange(); - virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - -private: - void setGridScaledImage(const QQuickGridScaledImage& sci); - -private Q_SLOTS: - void doUpdate(); - void requestFinished(); - void sciRequestFinished(); - -private: - Q_DISABLE_COPY(QQuickBorderImage) - Q_DECLARE_PRIVATE(QQuickBorderImage) -}; - -QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickBorderImage) -QT_END_HEADER - -#endif // QQUICKBORDERIMAGE_P_H diff --git a/src/declarative/items/qquickborderimage_p_p.h b/src/declarative/items/qquickborderimage_p_p.h deleted file mode 100644 index 1875dc082a..0000000000 --- a/src/declarative/items/qquickborderimage_p_p.h +++ /dev/null @@ -1,103 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKBORDERIMAGE_P_P_H -#define QQUICKBORDERIMAGE_P_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 "qquickimagebase_p_p.h" -#include "qquickscalegrid_p_p.h" - -QT_BEGIN_NAMESPACE - -class QNetworkReply; -class QQuickBorderImagePrivate : public QQuickImageBasePrivate -{ - Q_DECLARE_PUBLIC(QQuickBorderImage) - -public: - QQuickBorderImagePrivate() - : border(0), sciReply(0), - horizontalTileMode(QQuickBorderImage::Stretch), - verticalTileMode(QQuickBorderImage::Stretch), - redirectCount(0), pixmapChanged(false) - { - } - - ~QQuickBorderImagePrivate() - { - } - - - QQuickScaleGrid *getScaleGrid() - { - Q_Q(QQuickBorderImage); - if (!border) { - border = new QQuickScaleGrid(q); - FAST_CONNECT(border, SIGNAL(borderChanged()), q, SLOT(doUpdate())) - } - return border; - } - - QQuickScaleGrid *border; - QUrl sciurl; - QNetworkReply *sciReply; - QQuickBorderImage::TileMode horizontalTileMode; - QQuickBorderImage::TileMode verticalTileMode; - int redirectCount; - - bool pixmapChanged : 1; -}; - -QT_END_NAMESPACE - -#endif // QQUICKBORDERIMAGE_P_P_H diff --git a/src/declarative/items/qquickcanvas.cpp b/src/declarative/items/qquickcanvas.cpp deleted file mode 100644 index 8022af98f4..0000000000 --- a/src/declarative/items/qquickcanvas.cpp +++ /dev/null @@ -1,2644 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qquickcanvas.h" -#include "qquickcanvas_p.h" - -#include "qquickitem.h" -#include "qquickitem_p.h" - -#include -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -#define QQUICK_CANVAS_TIMING -#ifdef QQUICK_CANVAS_TIMING -static bool qquick_canvas_timing = !qgetenv("QML_CANVAS_TIMING").isEmpty(); -static QTime threadTimer; -static int syncTime; -static int renderTime; -static int swapTime; -#endif - -DEFINE_BOOL_CONFIG_OPTION(qmlFixedAnimationStep, QML_FIXED_ANIMATION_STEP) -DEFINE_BOOL_CONFIG_OPTION(qmlNoThreadedRenderer, QML_BAD_GUI_RENDER_LOOP) - -extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha); - -void QQuickCanvasPrivate::updateFocusItemTransform() -{ - Q_Q(QQuickCanvas); - QQuickItem *focus = q->activeFocusItem(); - if (focus && qApp->inputPanel()->inputItem() == focus) - qApp->inputPanel()->setInputItemTransform(QQuickItemPrivate::get(focus)->itemToCanvasTransform()); -} - -class QQuickCanvasIncubationController : public QObject, public QDeclarativeIncubationController -{ -public: - QQuickCanvasIncubationController(QQuickCanvasPrivate *canvas) - : m_canvas(canvas), m_eventSent(false) {} - -protected: - virtual bool event(QEvent *e) - { - if (e->type() == QEvent::User) { - Q_ASSERT(m_eventSent); - - bool *amtp = m_canvas->thread->allowMainThreadProcessing(); - while (incubatingObjectCount()) { - if (amtp) - incubateWhile(amtp); - else - incubateFor(5); - QCoreApplication::processEvents(); - } - - m_eventSent = false; - } - return QObject::event(e); - } - - virtual void incubatingObjectCountChanged(int count) - { - if (count && !m_eventSent) { - m_eventSent = true; - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - } - } - -private: - QQuickCanvasPrivate *m_canvas; - bool m_eventSent; -}; - -class QQuickCanvasPlainRenderLoop : public QObject, public QQuickCanvasRenderLoop -{ -public: - QQuickCanvasPlainRenderLoop() - : updatePending(false) - , animationRunning(false) - { - } - - virtual void paint() { - updatePending = false; - if (animationRunning && animationDriver()) - animationDriver()->advance(); - polishItems(); - syncSceneGraph(); - makeCurrent(); - glViewport(0, 0, size.width(), size.height()); - renderSceneGraph(size); - swapBuffers(); - - if (animationRunning) - maybeUpdate(); - } - - virtual QImage grab() { - return qt_gl_read_framebuffer(size, false, false); - } - - virtual void startRendering() { - if (!glContext()) { - createGLContext(); - makeCurrent(); - initializeSceneGraph(); - } else { - makeCurrent(); - } - maybeUpdate(); - } - - virtual void stopRendering() { - cleanupNodesOnShutdown(); - } - - virtual void maybeUpdate() { - if (!updatePending) { - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - updatePending = true; - } - } - - virtual void animationStarted() { - animationRunning = true; - maybeUpdate(); - } - - virtual void animationStopped() { - animationRunning = false; - } - - virtual bool isRunning() const { return glContext(); } // Event loop is always running... - virtual void resize(const QSize &s) { size = s; } - virtual void setWindowSize(const QSize &s) { size = s; } - - bool event(QEvent *e) { - if (e->type() == QEvent::User) { - paint(); - return true; - } - return QObject::event(e); - } - - QSize size; - - uint updatePending : 1; - uint animationRunning : 1; -}; - - - -/* -Focus behavior -============== - -Prior to being added to a valid canvas items can set and clear focus with no -effect. Only once items are added to a canvas (by way of having a parent set that -already belongs to a canvas) do the focus rules apply. Focus goes back to -having no effect if an item is removed from a canvas. - -When an item is moved into a new focus scope (either being added to a canvas -for the first time, or having its parent changed), if the focus scope already has -a scope focused item that takes precedence over the item being added. Otherwise, -the focus of the added tree is used. In the case of of a tree of items being -added to a canvas for the first time, which may have a conflicted focus state (two -or more items in one scope having focus set), the same rule is applied item by item - -thus the first item that has focus will get it (assuming the scope doesn't already -have a scope focused item), and the other items will have their focus cleared. -*/ - -/* - Threaded Rendering - ================== - - The threaded rendering uses a number of different variables to track potential - states used to handle resizing, initial paint, grabbing and driving animations - while ALWAYS keeping the GL context in the rendering thread and keeping the - overhead of normal one-shot paints and vblank driven animations at a minimum. - - Resize, initial show and grab suffer slightly in this model as they are locked - to the rendering in the rendering thread, but this is a necessary evil for - the system to work. - - Variables that are used: - - Private::animationRunning: This is true while the animations are running, and only - written to inside locks. - - RenderThread::isGuiBlocked: This is used to indicate that the GUI thread owns the - lock. This variable is an integer to allow for recursive calls to lockInGui() - without using a recursive mutex. See isGuiBlockPending. - - RenderThread::isPaintComplete: This variable is cleared when rendering starts and - set once rendering is complete. It is monitored in the paintEvent(), - resizeEvent() and grab() functions to force them to wait for rendering to - complete. - - RenderThread::isGuiBlockPending: This variable is set in the render thread just - before the sync event is sent to the GUI thread. It is used to avoid deadlocks - in the case where render thread waits while waiting for GUI to pick up the sync - event and GUI thread gets a resizeEvent, the initial paintEvent or a grab. - When this happens, we use the - exhaustSyncEvent() function to do the sync right there and mark the coming - sync event to be discarded. There can only ever be one sync incoming. - - RenderThread::isRenderBlock: This variable is true when animations are not - running and the render thread has gone to sleep, waiting for more to do. - - RenderThread::isExternalUpdatePending: This variable is set to false when - a new render pass is started and to true in maybeUpdate(). It is an - indication to the render thread that another render pass needs to take - place, rather than the render thread going to sleep after completing its swap. - - RenderThread::doGrab: This variable is set by the grab() function and - tells the renderer to do a grab after rendering is complete and before - swapping happens. - - RenderThread::shouldExit: This variable is used to determine if the render - thread should do a nother pass. It is typically set as a result of show() - and unset as a result of hide() or during shutdown() - - RenderThread::hasExited: Used by the GUI thread to synchronize the shutdown - after shouldExit has been set to true. - */ - -// #define FOCUS_DEBUG -// #define MOUSE_DEBUG -// #define TOUCH_DEBUG -// #define DIRTY_DEBUG -// #define THREAD_DEBUG - -// #define FRAME_TIMING - -#ifdef FRAME_TIMING -static QTime frameTimer; -int sceneGraphRenderTime; -int readbackTime; -#endif - -QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData() -: transformNode(0) -{ -} - -QQuickRootItem::QQuickRootItem() -{ -} - -void QQuickCanvas::exposeEvent(QExposeEvent *) -{ - Q_D(QQuickCanvas); - d->thread->paint(); -} - -void QQuickCanvas::resizeEvent(QResizeEvent *) -{ - Q_D(QQuickCanvas); - d->thread->resize(size()); -} - -void QQuickCanvas::animationStarted() -{ - d_func()->thread->animationStarted(); -} - -void QQuickCanvas::animationStopped() -{ - d_func()->thread->animationStopped(); -} - -void QQuickCanvas::showEvent(QShowEvent *) -{ - Q_D(QQuickCanvas); - if (d->vsyncAnimations) { - if (!d->animationDriver) { - d->animationDriver = d->context->createAnimationDriver(this); - connect(d->animationDriver, SIGNAL(started()), this, SLOT(animationStarted()), Qt::DirectConnection); - connect(d->animationDriver, SIGNAL(stopped()), this, SLOT(animationStopped()), Qt::DirectConnection); - } - d->animationDriver->install(); - } - - if (!d->thread->isRunning()) { - d->thread->setWindowSize(size()); - d->thread->startRendering(); - } -} - -void QQuickCanvas::hideEvent(QHideEvent *) -{ - Q_D(QQuickCanvas); - d->thread->stopRendering(); -} - -void QQuickCanvas::focusOutEvent(QFocusEvent *) -{ - Q_D(QQuickCanvas); - d->rootItem->setFocus(false); -} - -void QQuickCanvas::focusInEvent(QFocusEvent *) -{ - Q_D(QQuickCanvas); - d->rootItem->setFocus(true); -} - - -/*! - Sets weither this canvas should use vsync driven animations. - - This option can only be set on one single QQuickCanvas, and that it's - vsync signal will then be used to drive all animations in the - process. - - This feature is primarily useful for single QQuickCanvas, QML-only - applications. - - \warning Enabling vsync on multiple QQuickCanvas instances has - undefined behavior. - */ -void QQuickCanvas::setVSyncAnimations(bool enabled) -{ - Q_D(QQuickCanvas); - if (visible()) { - qWarning("QQuickCanvas::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 QQuickCanvas::vsyncAnimations() const -{ - Q_D(const QQuickCanvas); - return d->vsyncAnimations; -} - -void QQuickCanvasPrivate::initializeSceneGraph() -{ - if (!context) - context = QSGContext::createDefaultContext(); - - if (context->isReady()) - return; - - QOpenGLContext *glctx = const_cast(QOpenGLContext::currentContext()); - context->initialize(glctx); - - Q_Q(QQuickCanvas); - - if (!QQuickItemPrivate::get(rootItem)->itemNode()->parent()) { - context->rootNode()->appendChildNode(QQuickItemPrivate::get(rootItem)->itemNode()); - } - - engine = new QSGEngine(); - engine->setCanvas(q); - - emit q_func()->sceneGraphInitialized(); -} - -void QQuickCanvasPrivate::polishItems() -{ - while (!itemsToPolish.isEmpty()) { - QSet::Iterator iter = itemsToPolish.begin(); - QQuickItem *item = *iter; - itemsToPolish.erase(iter); - QQuickItemPrivate::get(item)->polishScheduled = false; - item->updatePolish(); - } - updateFocusItemTransform(); -} - - -void QQuickCanvasPrivate::syncSceneGraph() -{ - updateDirtyNodes(); - - // Copy the current state of clearing from canvas into renderer. - context->renderer()->setClearColor(clearColor); - QSGRenderer::ClearMode mode = QSGRenderer::ClearStencilBuffer | QSGRenderer::ClearDepthBuffer; - if (clearBeforeRendering) - mode |= QSGRenderer::ClearColorBuffer; - context->renderer()->setClearMode(mode); -} - - -void QQuickCanvasPrivate::renderSceneGraph(const QSize &size) -{ - Q_Q(QQuickCanvas); - context->renderer()->setDeviceRect(QRect(QPoint(0, 0), size)); - context->renderer()->setViewportRect(QRect(QPoint(0, 0), renderTarget ? renderTarget->size() : size)); - context->renderer()->setProjectionMatrixToDeviceRect(); - - emit q->beforeRendering(); - context->renderNextFrame(renderTarget); - emit q->afterRendering(); - -#ifdef FRAME_TIMING - sceneGraphRenderTime = frameTimer.elapsed(); -#endif - -#ifdef FRAME_TIMING -// int pixel; -// glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel); - readbackTime = frameTimer.elapsed(); -#endif -} - - -QQuickCanvasPrivate::QQuickCanvasPrivate() - : rootItem(0) - , activeFocusItem(0) - , mouseGrabberItem(0) - , dirtyItemList(0) - , context(0) - , clearColor(Qt::white) - , vsyncAnimations(false) - , clearBeforeRendering(true) - , thread(0) - , animationDriver(0) - , renderTarget(0) - , incubationController(0) -{ -} - -QQuickCanvasPrivate::~QQuickCanvasPrivate() -{ -} - -void QQuickCanvasPrivate::init(QQuickCanvas *c) -{ - QUnifiedTimer* ut = QUnifiedTimer::instance(true); - if (qmlFixedAnimationStep()) - ut->setConsistentTiming(true); - - q_ptr = c; - - Q_Q(QQuickCanvas); - - rootItem = new QQuickRootItem; - QQuickItemPrivate *rootItemPrivate = QQuickItemPrivate::get(rootItem); - rootItemPrivate->canvas = q; - rootItemPrivate->flags |= QQuickItem::ItemIsFocusScope; - - // In the absence of a focus in event on some platforms assume the window will - // be activated immediately and set focus on the rootItem - // ### Remove when QTBUG-22415 is resolved. - //It is important that this call happens after the rootItem has a canvas.. - rootItem->setFocus(true); - - bool threaded = !qmlNoThreadedRenderer(); - - if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL)) { - qWarning("QQuickCanvas: platform does not support threaded rendering!"); - threaded = false; - } - - if (threaded) - thread = new QQuickCanvasRenderThread(); - else - thread = new QQuickCanvasPlainRenderLoop(); - - thread->renderer = q; - thread->d = this; - - context = QSGContext::createDefaultContext(); - thread->moveContextToThread(context); - - q->setSurfaceType(QWindow::OpenGLSurface); - q->setFormat(context->defaultSurfaceFormat()); -} - -QDeclarativeListProperty QQuickCanvasPrivate::data() -{ - initRootItem(); - return QQuickItemPrivate::get(rootItem)->data(); -} - -void QQuickCanvasPrivate::initRootItem() -{ - Q_Q(QQuickCanvas); - q->connect(q, SIGNAL(widthChanged(int)), - rootItem, SLOT(setWidth(int))); - q->connect(q, SIGNAL(heightChanged(int)), - rootItem, SLOT(setHeight(int))); - rootItem->setWidth(q->width()); - rootItem->setHeight(q->height()); -} - -void QQuickCanvasPrivate::transformTouchPoints(QList &touchPoints, const QTransform &transform) -{ - for (int i=0; isetWidget(q); // ### refactor... - - QList touchPoints = touchEvent->touchPoints(); - for (int i = 0; i < touchPoints.count(); ++i) { - QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; - - touchPoint.setScreenRect(touchPoint.sceneRect()); - touchPoint.setStartScreenPos(touchPoint.startScenePos()); - touchPoint.setLastScreenPos(touchPoint.lastScenePos()); - - touchPoint.setSceneRect(touchPoint.rect()); - touchPoint.setStartScenePos(touchPoint.startPos()); - touchPoint.setLastScenePos(touchPoint.lastPos()); - - if (touchPoint.isPrimary()) - lastMousePosition = touchPoint.pos().toPoint(); - } - touchEvent->setTouchPoints(touchPoints); -} - -void QQuickCanvasPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions options) -{ - Q_Q(QQuickCanvas); - - Q_ASSERT(item); - Q_ASSERT(scope || item == rootItem); - -#ifdef FOCUS_DEBUG - qWarning() << "QQuickCanvasPrivate::setFocusInScope():"; - qWarning() << " scope:" << (QObject *)scope; - if (scope) - qWarning() << " scopeSubFocusItem:" << (QObject *)QQuickItemPrivate::get(scope)->subFocusItem; - qWarning() << " item:" << (QObject *)item; - qWarning() << " activeFocusItem:" << (QObject *)activeFocusItem; -#endif - - QQuickItemPrivate *scopePrivate = scope ? QQuickItemPrivate::get(scope) : 0; - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - - QQuickItem *oldActiveFocusItem = 0; - QQuickItem *newActiveFocusItem = 0; - - QVarLengthArray changed; - - // Does this change the active focus? - if (item == rootItem || scopePrivate->activeFocus) { - oldActiveFocusItem = activeFocusItem; - newActiveFocusItem = item; - while (newActiveFocusItem->isFocusScope() && newActiveFocusItem->scopedFocusItem()) - newActiveFocusItem = newActiveFocusItem->scopedFocusItem(); - - if (oldActiveFocusItem) { -#ifndef QT_NO_IM - qApp->inputPanel()->commit(); -#endif - - activeFocusItem = 0; - QFocusEvent event(QEvent::FocusOut, Qt::OtherFocusReason); - q->sendEvent(oldActiveFocusItem, &event); - - QQuickItem *afi = oldActiveFocusItem; - while (afi != scope) { - if (QQuickItemPrivate::get(afi)->activeFocus) { - QQuickItemPrivate::get(afi)->activeFocus = false; - changed << afi; - } - afi = afi->parentItem(); - } - } - } - - if (item != rootItem) { - QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem; - // Correct focus chain in scope - if (oldSubFocusItem) { - QQuickItem *sfi = scopePrivate->subFocusItem->parentItem(); - while (sfi != scope) { - QQuickItemPrivate::get(sfi)->subFocusItem = 0; - sfi = sfi->parentItem(); - } - } - { - scopePrivate->subFocusItem = item; - QQuickItem *sfi = scopePrivate->subFocusItem->parentItem(); - while (sfi != scope) { - QQuickItemPrivate::get(sfi)->subFocusItem = item; - sfi = sfi->parentItem(); - } - } - - if (oldSubFocusItem) { - QQuickItemPrivate::get(oldSubFocusItem)->focus = false; - changed << oldSubFocusItem; - } - } - - if (!(options & DontChangeFocusProperty)) { -// if (item != rootItem || QGuiApplication::focusWindow() == q) { // QTBUG-22415 - itemPrivate->focus = true; - changed << item; -// } - } - - if (newActiveFocusItem && rootItem->hasFocus()) { - activeFocusItem = newActiveFocusItem; - - QQuickItemPrivate::get(newActiveFocusItem)->activeFocus = true; - changed << newActiveFocusItem; - - QQuickItem *afi = newActiveFocusItem->parentItem(); - while (afi && afi != scope) { - if (afi->isFocusScope()) { - QQuickItemPrivate::get(afi)->activeFocus = true; - changed << afi; - } - afi = afi->parentItem(); - } - - updateInputMethodData(); - - QFocusEvent event(QEvent::FocusIn, Qt::OtherFocusReason); - q->sendEvent(newActiveFocusItem, &event); - } else { - updateInputMethodData(); - } - - if (!changed.isEmpty()) - notifyFocusChangesRecur(changed.data(), changed.count() - 1); -} - -void QQuickCanvasPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions options) -{ - Q_Q(QQuickCanvas); - - Q_UNUSED(item); - Q_ASSERT(item); - Q_ASSERT(scope || item == rootItem); - -#ifdef FOCUS_DEBUG - qWarning() << "QQuickCanvasPrivate::clearFocusInScope():"; - qWarning() << " scope:" << (QObject *)scope; - qWarning() << " item:" << (QObject *)item; - qWarning() << " activeFocusItem:" << (QObject *)activeFocusItem; -#endif - - QQuickItemPrivate *scopePrivate = scope ? QQuickItemPrivate::get(scope) : 0; - - QQuickItem *oldActiveFocusItem = 0; - QQuickItem *newActiveFocusItem = 0; - - QVarLengthArray changed; - - Q_ASSERT(item == rootItem || item == scopePrivate->subFocusItem); - - // Does this change the active focus? - if (item == rootItem || scopePrivate->activeFocus) { - oldActiveFocusItem = activeFocusItem; - newActiveFocusItem = scope; - - Q_ASSERT(oldActiveFocusItem); - -#ifndef QT_NO_IM - qApp->inputPanel()->commit(); -#endif - - activeFocusItem = 0; - QFocusEvent event(QEvent::FocusOut, Qt::OtherFocusReason); - q->sendEvent(oldActiveFocusItem, &event); - - QQuickItem *afi = oldActiveFocusItem; - while (afi != scope) { - if (QQuickItemPrivate::get(afi)->activeFocus) { - QQuickItemPrivate::get(afi)->activeFocus = false; - changed << afi; - } - afi = afi->parentItem(); - } - } - - if (item != rootItem) { - QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem; - // Correct focus chain in scope - if (oldSubFocusItem) { - QQuickItem *sfi = scopePrivate->subFocusItem->parentItem(); - while (sfi != scope) { - QQuickItemPrivate::get(sfi)->subFocusItem = 0; - sfi = sfi->parentItem(); - } - } - scopePrivate->subFocusItem = 0; - - if (oldSubFocusItem && !(options & DontChangeFocusProperty)) { - QQuickItemPrivate::get(oldSubFocusItem)->focus = false; - changed << oldSubFocusItem; - } - } else if (!(options & DontChangeFocusProperty)) { - QQuickItemPrivate::get(item)->focus = false; - changed << item; - } - - if (newActiveFocusItem) { - Q_ASSERT(newActiveFocusItem == scope); - activeFocusItem = scope; - - updateInputMethodData(); - - QFocusEvent event(QEvent::FocusIn, Qt::OtherFocusReason); - q->sendEvent(newActiveFocusItem, &event); - } else { - updateInputMethodData(); - } - - if (!changed.isEmpty()) - notifyFocusChangesRecur(changed.data(), changed.count() - 1); -} - -void QQuickCanvasPrivate::notifyFocusChangesRecur(QQuickItem **items, int remaining) -{ - QDeclarativeGuard item(*items); - - if (remaining) - notifyFocusChangesRecur(items + 1, remaining - 1); - - if (item) { - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - - if (itemPrivate->notifiedFocus != itemPrivate->focus) { - itemPrivate->notifiedFocus = itemPrivate->focus; - emit item->focusChanged(itemPrivate->focus); - } - - if (item && itemPrivate->notifiedActiveFocus != itemPrivate->activeFocus) { - itemPrivate->notifiedActiveFocus = itemPrivate->activeFocus; - itemPrivate->itemChange(QQuickItem::ItemActiveFocusHasChanged, itemPrivate->activeFocus); - emit item->activeFocusChanged(itemPrivate->activeFocus); - } - } -} - -void QQuickCanvasPrivate::updateInputMethodData() -{ - QQuickItem *inputItem = 0; - if (activeFocusItem && activeFocusItem->flags() & QQuickItem::ItemAcceptsInputMethod) - inputItem = activeFocusItem; - qApp->inputPanel()->setInputItem(inputItem); -} - -void QQuickCanvasPrivate::dirtyItem(QQuickItem *) -{ - Q_Q(QQuickCanvas); - q->maybeUpdate(); -} - -void QQuickCanvasPrivate::cleanup(QSGNode *n) -{ - Q_Q(QQuickCanvas); - - Q_ASSERT(!cleanupNodeList.contains(n)); - cleanupNodeList.append(n); - q->maybeUpdate(); -} - - -/*! - \qmlclass Window QQuickCanvas - \inqmlmodule QtQuick.Window 2 - \brief The Window object creates a new top-level window. - - The Window object creates a new top-level window for a QtQuick scene. It automatically sets up the - window for use with QtQuick 2.0 graphical elements. -*/ -/*! - \class QQuickCanvas - \since QtQuick 2.0 - \brief The QQuickCanvas class provides the canvas for displaying a graphical QML scene - - QQuickCanvas provides the graphical scene management needed to interact with and display - a scene of QQuickItems. - - A QQuickCanvas always has a single invisible root item. To add items to this canvas, - reparent the items to the root item or to an existing item in the scene. - - For easily displaying a scene from a QML file, see \l{QQuickView}. -*/ -QQuickCanvas::QQuickCanvas(QWindow *parent) - : QWindow(*(new QQuickCanvasPrivate), parent) -{ - Q_D(QQuickCanvas); - d->init(this); -} - -QQuickCanvas::QQuickCanvas(QQuickCanvasPrivate &dd, QWindow *parent) - : QWindow(dd, parent) -{ - Q_D(QQuickCanvas); - d->init(this); -} - -QQuickCanvas::~QQuickCanvas() -{ - Q_D(QQuickCanvas); - - if (d->thread->isRunning()) - d->thread->stopRendering(); - - // ### should we change ~QQuickItem to handle this better? - // manually cleanup for the root item (item destructor only handles these when an item is parented) - QQuickItemPrivate *rootItemPrivate = QQuickItemPrivate::get(d->rootItem); - rootItemPrivate->removeFromDirtyList(); - - delete d->incubationController; d->incubationController = 0; - - delete d->rootItem; d->rootItem = 0; - - delete d->thread; d->thread = 0; -} - -/*! - Returns the invisible root item of the scene. - - A QQuickCanvas always has a single invisible root item. To add items to this canvas, - reparent the items to the root item or to an existing item in the scene. -*/ -QQuickItem *QQuickCanvas::rootItem() const -{ - Q_D(const QQuickCanvas); - - return d->rootItem; -} - -/*! - Returns the item which currently has active focus. -*/ -QQuickItem *QQuickCanvas::activeFocusItem() const -{ - Q_D(const QQuickCanvas); - - return d->activeFocusItem; -} - -/*! - Returns the item which currently has the mouse grab. -*/ -QQuickItem *QQuickCanvas::mouseGrabberItem() const -{ - Q_D(const QQuickCanvas); - - return d->mouseGrabberItem; -} - - -/*! - \qmlproperty color QtQuick2.Window::Window::color - - The background color for the window. - - Setting this property is more efficient than using a separate Rectangle. -*/ - -bool QQuickCanvasPrivate::clearHover() -{ - if (hoverItems.isEmpty()) - return false; - - QPointF pos = QCursor::pos(); // ### refactor: q->mapFromGlobal(QCursor::pos()); - - bool accepted = false; - foreach (QQuickItem* item, hoverItems) - accepted = sendHoverEvent(QEvent::HoverLeave, item, pos, pos, QGuiApplication::keyboardModifiers(), true) || accepted; - hoverItems.clear(); - return accepted; -} - - -bool QQuickCanvas::event(QEvent *e) -{ - Q_D(QQuickCanvas); - - switch (e->type()) { - - case QEvent::TouchBegin: - case QEvent::TouchUpdate: - case QEvent::TouchEnd: - { - QTouchEvent *touch = static_cast(e); - d->translateTouchEvent(touch); - d->deliverTouchEvent(touch); - if (!touch->isAccepted()) - return false; - break; - } - case QEvent::Leave: - d->clearHover(); - d->lastMousePosition = QPoint(); - break; - case QEvent::DragEnter: - case QEvent::DragLeave: - case QEvent::DragMove: - case QEvent::Drop: - d->deliverDragEvent(&d->dragGrabber, e); - break; - case QEvent::WindowDeactivate: - rootItem()->windowDeactivateEvent(); - break; - default: - break; - } - - return QWindow::event(e); -} - -void QQuickCanvas::keyPressEvent(QKeyEvent *e) -{ - Q_D(QQuickCanvas); - - if (d->activeFocusItem) - sendEvent(d->activeFocusItem, e); -} - -void QQuickCanvas::keyReleaseEvent(QKeyEvent *e) -{ - Q_D(QQuickCanvas); - - if (d->activeFocusItem) - sendEvent(d->activeFocusItem, e); -} - -bool QQuickCanvasPrivate::deliverInitialMousePressEvent(QQuickItem *item, QMouseEvent *event) -{ - Q_Q(QQuickCanvas); - - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - if (itemPrivate->opacity == 0.0) - return false; - - if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) { - QPointF p = item->mapFromScene(event->windowPos()); - if (!QRectF(0, 0, item->width(), item->height()).contains(p)) - return false; - } - - QList children = itemPrivate->paintOrderChildItems(); - for (int ii = children.count() - 1; ii >= 0; --ii) { - QQuickItem *child = children.at(ii); - if (!child->isVisible() || !child->isEnabled()) - continue; - if (deliverInitialMousePressEvent(child, event)) - return true; - } - - if (itemPrivate->acceptedMouseButtons & event->button()) { - QPointF p = item->mapFromScene(event->windowPos()); - if (QRectF(0, 0, item->width(), item->height()).contains(p)) { - QMouseEvent me(event->type(), p, event->windowPos(), event->screenPos(), - event->button(), event->buttons(), event->modifiers()); - me.accept(); - mouseGrabberItem = item; - q->sendEvent(item, &me); - event->setAccepted(me.isAccepted()); - if (me.isAccepted()) - return true; - mouseGrabberItem->ungrabMouse(); - mouseGrabberItem = 0; - } - } - - return false; -} - -bool QQuickCanvasPrivate::deliverMouseEvent(QMouseEvent *event) -{ - Q_Q(QQuickCanvas); - - lastMousePosition = event->windowPos(); - - if (!mouseGrabberItem && - event->type() == QEvent::MouseButtonPress && - (event->button() & event->buttons()) == event->buttons()) { - return deliverInitialMousePressEvent(rootItem, event); - } - - if (mouseGrabberItem) { - QQuickItemPrivate *mgPrivate = QQuickItemPrivate::get(mouseGrabberItem); - const QTransform &transform = mgPrivate->canvasToItemTransform(); - QMouseEvent me(event->type(), transform.map(event->windowPos()), event->windowPos(), event->screenPos(), - event->button(), event->buttons(), event->modifiers()); - me.accept(); - q->sendEvent(mouseGrabberItem, &me); - event->setAccepted(me.isAccepted()); - if (me.isAccepted()) - return true; - } - - return false; -} - -void QQuickCanvas::mousePressEvent(QMouseEvent *event) -{ - Q_D(QQuickCanvas); - -#ifdef MOUSE_DEBUG - qWarning() << "QQuickCanvas::mousePressEvent()" << event->pos() << event->button() << event->buttons(); -#endif - - d->deliverMouseEvent(event); -} - -void QQuickCanvas::mouseReleaseEvent(QMouseEvent *event) -{ - Q_D(QQuickCanvas); - -#ifdef MOUSE_DEBUG - qWarning() << "QQuickCanvas::mouseReleaseEvent()" << event->pos() << event->button() << event->buttons(); -#endif - - if (!d->mouseGrabberItem) { - QWindow::mouseReleaseEvent(event); - return; - } - - d->deliverMouseEvent(event); - d->mouseGrabberItem = 0; -} - -void QQuickCanvas::mouseDoubleClickEvent(QMouseEvent *event) -{ - Q_D(QQuickCanvas); - -#ifdef MOUSE_DEBUG - qWarning() << "QQuickCanvas::mouseDoubleClickEvent()" << event->pos() << event->button() << event->buttons(); -#endif - - if (!d->mouseGrabberItem && (event->button() & event->buttons()) == event->buttons()) { - if (d->deliverInitialMousePressEvent(d->rootItem, event)) - event->accept(); - else - event->ignore(); - return; - } - - d->deliverMouseEvent(event); -} - -bool QQuickCanvasPrivate::sendHoverEvent(QEvent::Type type, QQuickItem *item, - const QPointF &scenePos, const QPointF &lastScenePos, - Qt::KeyboardModifiers modifiers, bool accepted) -{ - Q_Q(QQuickCanvas); - const QTransform transform = QQuickItemPrivate::get(item)->canvasToItemTransform(); - - //create copy of event - QHoverEvent hoverEvent(type, transform.map(scenePos), transform.map(lastScenePos), modifiers); - hoverEvent.setAccepted(accepted); - - q->sendEvent(item, &hoverEvent); - - return hoverEvent.isAccepted(); -} - -void QQuickCanvas::mouseMoveEvent(QMouseEvent *event) -{ - Q_D(QQuickCanvas); - -#ifdef MOUSE_DEBUG - qWarning() << "QQuickCanvas::mouseMoveEvent()" << event->pos() << event->button() << event->buttons(); -#endif - - if (!d->mouseGrabberItem) { - if (d->lastMousePosition.isNull()) - d->lastMousePosition = event->windowPos(); - QPointF last = d->lastMousePosition; - d->lastMousePosition = event->windowPos(); - - bool accepted = event->isAccepted(); - bool delivered = d->deliverHoverEvent(d->rootItem, event->windowPos(), last, event->modifiers(), accepted); - if (!delivered) { - //take care of any exits - accepted = d->clearHover(); - } - event->setAccepted(accepted); - return; - } - - d->deliverMouseEvent(event); -} - -bool QQuickCanvasPrivate::deliverHoverEvent(QQuickItem *item, const QPointF &scenePos, const QPointF &lastScenePos, - Qt::KeyboardModifiers modifiers, bool &accepted) -{ - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - if (itemPrivate->opacity == 0.0) - return false; - - if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) { - QPointF p = item->mapFromScene(scenePos); - if (!QRectF(0, 0, item->width(), item->height()).contains(p)) - return false; - } - - QList children = itemPrivate->paintOrderChildItems(); - for (int ii = children.count() - 1; ii >= 0; --ii) { - QQuickItem *child = children.at(ii); - if (!child->isVisible() || !child->isEnabled()) - continue; - if (deliverHoverEvent(child, scenePos, lastScenePos, modifiers, accepted)) - return true; - } - - if (itemPrivate->hoverEnabled) { - QPointF p = item->mapFromScene(scenePos); - if (QRectF(0, 0, item->width(), item->height()).contains(p)) { - if (!hoverItems.isEmpty() && hoverItems[0] == item) { - //move - accepted = sendHoverEvent(QEvent::HoverMove, item, scenePos, lastScenePos, modifiers, accepted); - } else { - QList itemsToHover; - QQuickItem* parent = item; - itemsToHover << item; - while ((parent = parent->parentItem())) - itemsToHover << parent; - - // Leaving from previous hovered items until we reach the item or one of its ancestors. - while (!hoverItems.isEmpty() && !itemsToHover.contains(hoverItems[0])) { - sendHoverEvent(QEvent::HoverLeave, hoverItems[0], scenePos, lastScenePos, modifiers, accepted); - hoverItems.removeFirst(); - } - - if (!hoverItems.isEmpty() && hoverItems[0] == item){//Not entering a new Item - // ### Shouldn't we send moves for the parent items as well? - accepted = sendHoverEvent(QEvent::HoverMove, item, scenePos, lastScenePos, modifiers, accepted); - } else { - // Enter items that are not entered yet. - int startIdx = -1; - if (!hoverItems.isEmpty()) - startIdx = itemsToHover.indexOf(hoverItems[0]) - 1; - if (startIdx == -1) - startIdx = itemsToHover.count() - 1; - - for (int i = startIdx; i >= 0; i--) { - QQuickItem *itemToHover = itemsToHover[i]; - if (QQuickItemPrivate::get(itemToHover)->hoverEnabled) { - hoverItems.prepend(itemToHover); - sendHoverEvent(QEvent::HoverEnter, itemToHover, scenePos, lastScenePos, modifiers, accepted); - } - } - } - } - return true; - } - } - - return false; -} - -bool QQuickCanvasPrivate::deliverWheelEvent(QQuickItem *item, QWheelEvent *event) -{ - Q_Q(QQuickCanvas); - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - if (itemPrivate->opacity == 0.0) - return false; - - if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) { - QPointF p = item->mapFromScene(event->posF()); - if (!QRectF(0, 0, item->width(), item->height()).contains(p)) - return false; - } - - QList children = itemPrivate->paintOrderChildItems(); - for (int ii = children.count() - 1; ii >= 0; --ii) { - QQuickItem *child = children.at(ii); - if (!child->isVisible() || !child->isEnabled()) - continue; - if (deliverWheelEvent(child, event)) - return true; - } - - QPointF p = item->mapFromScene(event->posF()); - if (QRectF(0, 0, item->width(), item->height()).contains(p)) { - QWheelEvent wheel(p, event->delta(), event->buttons(), event->modifiers(), event->orientation()); - wheel.accept(); - q->sendEvent(item, &wheel); - if (wheel.isAccepted()) { - event->accept(); - return true; - } - } - - return false; -} - -#ifndef QT_NO_WHEELEVENT -void QQuickCanvas::wheelEvent(QWheelEvent *event) -{ - Q_D(QQuickCanvas); -#ifdef MOUSE_DEBUG - qWarning() << "QQuickCanvas::wheelEvent()" << event->pos() << event->delta() << event->orientation(); -#endif - event->ignore(); - d->deliverWheelEvent(d->rootItem, event); -} -#endif // QT_NO_WHEELEVENT - -bool QQuickCanvasPrivate::deliverTouchEvent(QTouchEvent *event) -{ -#ifdef TOUCH_DEBUG - if (event->type() == QEvent::TouchBegin) - qWarning("touchBeginEvent"); - else if (event->type() == QEvent::TouchUpdate) - qWarning("touchUpdateEvent"); - else if (event->type() == QEvent::TouchEnd) - qWarning("touchEndEvent"); -#endif - - QHash > updatedPoints; - - if (event->type() == QTouchEvent::TouchBegin) { // all points are new touch points - QSet acceptedNewPoints; - deliverTouchPoints(rootItem, event, event->touchPoints(), &acceptedNewPoints, &updatedPoints); - if (acceptedNewPoints.count() > 0) - event->accept(); - return event->isAccepted(); - } - - const QList &touchPoints = event->touchPoints(); - QList newPoints; - QQuickItem *item = 0; - for (int i=0; i 0 || updatedPoints.count() > 0) { - QSet acceptedNewPoints; - int prevCount = updatedPoints.count(); - deliverTouchPoints(rootItem, event, newPoints, &acceptedNewPoints, &updatedPoints); - if (acceptedNewPoints.count() > 0 || updatedPoints.count() != prevCount) - event->accept(); - } - - if (event->touchPointStates() & Qt::TouchPointReleased) { - for (int i=0; iisAccepted(); -} - -bool QQuickCanvasPrivate::deliverTouchPoints(QQuickItem *item, QTouchEvent *event, const QList &newPoints, QSet *acceptedNewPoints, QHash > *updatedPoints) -{ - Q_Q(QQuickCanvas); - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - - if (itemPrivate->opacity == 0.0) - return false; - - if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) { - QRectF bounds(0, 0, item->width(), item->height()); - for (int i=0; imapFromScene(newPoints[i].scenePos()); - if (!bounds.contains(p)) - return false; - } - } - - QList children = itemPrivate->paintOrderChildItems(); - for (int ii = children.count() - 1; ii >= 0; --ii) { - QQuickItem *child = children.at(ii); - if (!child->isEnabled()) - continue; - if (deliverTouchPoints(child, event, newPoints, acceptedNewPoints, updatedPoints)) - return true; - } - - QList matchingPoints; - if (newPoints.count() > 0 && acceptedNewPoints->count() < newPoints.count()) { - QRectF bounds(0, 0, item->width(), item->height()); - for (int i=0; icontains(newPoints[i].id())) - continue; - QPointF p = item->mapFromScene(newPoints[i].scenePos()); - if (bounds.contains(p)) - matchingPoints << newPoints[i]; - } - } - - if (matchingPoints.count() > 0 || (*updatedPoints)[item].count() > 0) { - QList &eventPoints = (*updatedPoints)[item]; - eventPoints.append(matchingPoints); - transformTouchPoints(eventPoints, itemPrivate->canvasToItemTransform()); - - Qt::TouchPointStates eventStates; - for (int i=0; ideviceType()); - touchEvent.setModifiers(event->modifiers()); - touchEvent.setTouchPointStates(eventStates); - touchEvent.setTouchPoints(eventPoints); - touchEvent.setTimestamp(event->timestamp()); - - touchEvent.accept(); - q->sendEvent(item, &touchEvent); - - if (touchEvent.isAccepted()) { - for (int i=0; iinsert(matchingPoints[i].id()); - } - } - } - } - - updatedPoints->remove(item); - if (acceptedNewPoints->count() == newPoints.count() && updatedPoints->isEmpty()) - return true; - - return false; -} - -void QQuickCanvasPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QEvent *event) -{ - Q_Q(QQuickCanvas); - grabber->resetTarget(); - QQuickDragGrabber::iterator grabItem = grabber->begin(); - if (grabItem != grabber->end()) { - Q_ASSERT(event->type() != QEvent::DragEnter); - if (event->type() == QEvent::Drop) { - QDropEvent *e = static_cast(event); - for (e->setAccepted(false); !e->isAccepted() && grabItem != grabber->end(); grabItem = grabber->release(grabItem)) { - QPointF p = (**grabItem)->mapFromScene(e->pos()); - QDropEvent translatedEvent( - p.toPoint(), - e->possibleActions(), - e->mimeData(), - e->mouseButtons(), - e->keyboardModifiers()); - QQuickDropEventEx::copyActions(&translatedEvent, *e); - q->sendEvent(**grabItem, &translatedEvent); - e->setAccepted(translatedEvent.isAccepted()); - e->setDropAction(translatedEvent.dropAction()); - grabber->setTarget(**grabItem); - } - } - if (event->type() != QEvent::DragMove) { // Either an accepted drop or a leave. - QDragLeaveEvent leaveEvent; - for (; grabItem != grabber->end(); grabItem = grabber->release(grabItem)) - q->sendEvent(**grabItem, &leaveEvent); - return; - } else for (; grabItem != grabber->end(); grabItem = grabber->release(grabItem)) { - QDragMoveEvent *moveEvent = static_cast(event); - if (deliverDragEvent(grabber, **grabItem, moveEvent)) { - moveEvent->setAccepted(true); - for (++grabItem; grabItem != grabber->end();) { - QPointF p = (**grabItem)->mapFromScene(moveEvent->pos()); - if (QRectF(0, 0, (**grabItem)->width(), (**grabItem)->height()).contains(p)) { - QDragMoveEvent translatedEvent( - p.toPoint(), - moveEvent->possibleActions(), - moveEvent->mimeData(), - moveEvent->mouseButtons(), - moveEvent->keyboardModifiers()); - QQuickDropEventEx::copyActions(&translatedEvent, *moveEvent); - q->sendEvent(**grabItem, &translatedEvent); - ++grabItem; - } else { - QDragLeaveEvent leaveEvent; - q->sendEvent(**grabItem, &leaveEvent); - grabItem = grabber->release(grabItem); - } - } - return; - } else { - QDragLeaveEvent leaveEvent; - q->sendEvent(**grabItem, &leaveEvent); - } - } - } - if (event->type() == QEvent::DragEnter || event->type() == QEvent::DragMove) { - QDragMoveEvent *e = static_cast(event); - QDragEnterEvent enterEvent( - e->pos(), - e->possibleActions(), - e->mimeData(), - e->mouseButtons(), - e->keyboardModifiers()); - QQuickDropEventEx::copyActions(&enterEvent, *e); - event->setAccepted(deliverDragEvent(grabber, rootItem, &enterEvent)); - } -} - -bool QQuickCanvasPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QQuickItem *item, QDragMoveEvent *event) -{ - Q_Q(QQuickCanvas); - bool accepted = false; - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - if (itemPrivate->opacity == 0.0 || !item->isVisible() || !item->isEnabled()) - return false; - - QPointF p = item->mapFromScene(event->pos()); - if (QRectF(0, 0, item->width(), item->height()).contains(p)) { - if (event->type() == QEvent::DragMove || itemPrivate->flags & QQuickItem::ItemAcceptsDrops) { - QDragMoveEvent translatedEvent( - p.toPoint(), - event->possibleActions(), - event->mimeData(), - event->mouseButtons(), - event->keyboardModifiers(), - event->type()); - QQuickDropEventEx::copyActions(&translatedEvent, *event); - q->sendEvent(item, &translatedEvent); - if (event->type() == QEvent::DragEnter) { - if (translatedEvent.isAccepted()) { - grabber->grab(item); - accepted = true; - } - } else { - accepted = true; - } - } - } else if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) { - return false; - } - - QDragEnterEvent enterEvent( - event->pos(), - event->possibleActions(), - event->mimeData(), - event->mouseButtons(), - event->keyboardModifiers()); - QQuickDropEventEx::copyActions(&enterEvent, *event); - QList children = itemPrivate->paintOrderChildItems(); - for (int ii = children.count() - 1; ii >= 0; --ii) { - if (deliverDragEvent(grabber, children.at(ii), &enterEvent)) - return true; - } - - return accepted; -} - -bool QQuickCanvasPrivate::sendFilteredMouseEvent(QQuickItem *target, QQuickItem *item, QEvent *event) -{ - if (!target) - return false; - - QQuickItemPrivate *targetPrivate = QQuickItemPrivate::get(target); - if (targetPrivate->filtersChildMouseEvents) - if (target->childMouseEventFilter(item, event)) - return true; - - if (sendFilteredMouseEvent(target->parentItem(), item, event)) - return true; - - return false; -} - -/*! - Propagates an event to a QQuickItem on the canvas -*/ -bool QQuickCanvas::sendEvent(QQuickItem *item, QEvent *e) -{ - Q_D(QQuickCanvas); - - if (!item) { - qWarning("QQuickCanvas::sendEvent: Cannot send event to a null item"); - return false; - } - - Q_ASSERT(e); - - switch (e->type()) { - case QEvent::KeyPress: - case QEvent::KeyRelease: - e->accept(); - QQuickItemPrivate::get(item)->deliverKeyEvent(static_cast(e)); - while (!e->isAccepted() && (item = item->parentItem())) { - e->accept(); - QQuickItemPrivate::get(item)->deliverKeyEvent(static_cast(e)); - } - break; - case QEvent::FocusIn: - case QEvent::FocusOut: - QQuickItemPrivate::get(item)->deliverFocusEvent(static_cast(e)); - break; - case QEvent::MouseButtonPress: - case QEvent::MouseButtonRelease: - case QEvent::MouseButtonDblClick: - case QEvent::MouseMove: - // XXX todo - should sendEvent be doing this? how does it relate to forwarded events? - if (!d->sendFilteredMouseEvent(item->parentItem(), item, e)) { - e->accept(); - QQuickItemPrivate::get(item)->deliverMouseEvent(static_cast(e)); - } - break; - case QEvent::Wheel: - QQuickItemPrivate::get(item)->deliverWheelEvent(static_cast(e)); - break; - case QEvent::HoverEnter: - case QEvent::HoverLeave: - case QEvent::HoverMove: - QQuickItemPrivate::get(item)->deliverHoverEvent(static_cast(e)); - break; - case QEvent::TouchBegin: - case QEvent::TouchUpdate: - case QEvent::TouchEnd: - // XXX todo - should sendEvent be doing this? how does it relate to forwarded events? - if (!d->sendFilteredMouseEvent(item->parentItem(), item, e)) { - e->accept(); - QQuickItemPrivate::get(item)->deliverTouchEvent(static_cast(e)); - } - break; - case QEvent::DragEnter: - case QEvent::DragMove: - case QEvent::DragLeave: - case QEvent::Drop: - QQuickItemPrivate::get(item)->deliverDragEvent(e); - break; - default: - break; - } - - return false; -} - -void QQuickCanvasPrivate::cleanupNodes() -{ - for (int ii = 0; ii < cleanupNodeList.count(); ++ii) - delete cleanupNodeList.at(ii); - cleanupNodeList.clear(); -} - -void QQuickCanvasPrivate::cleanupNodesOnShutdown(QQuickItem *item) -{ - QQuickItemPrivate *p = QQuickItemPrivate::get(item); - if (p->itemNodeInstance) { - delete p->itemNodeInstance; - p->itemNodeInstance = 0; - p->opacityNode = 0; - p->clipNode = 0; - p->groupNode = 0; - p->paintNode = 0; - } - - for (int ii = 0; ii < p->childItems.count(); ++ii) - cleanupNodesOnShutdown(p->childItems.at(ii)); -} - -// This must be called from the render thread, with the main thread frozen -void QQuickCanvasPrivate::cleanupNodesOnShutdown() -{ - cleanupNodes(); - - cleanupNodesOnShutdown(rootItem); -} - -void QQuickCanvasPrivate::updateDirtyNodes() -{ -#ifdef DIRTY_DEBUG - qWarning() << "QQuickCanvasPrivate::updateDirtyNodes():"; -#endif - - cleanupNodes(); - - QQuickItem *updateList = dirtyItemList; - dirtyItemList = 0; - if (updateList) QQuickItemPrivate::get(updateList)->prevDirtyItem = &updateList; - - while (updateList) { - QQuickItem *item = updateList; - QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(item); - itemPriv->removeFromDirtyList(); - -#ifdef DIRTY_DEBUG - qWarning() << " QSGNode:" << item << qPrintable(itemPriv->dirtyToString()); -#endif - updateDirtyNode(item); - } -} - -void QQuickCanvasPrivate::updateDirtyNode(QQuickItem *item) -{ -#ifdef QML_RUNTIME_TESTING - bool didFlash = false; -#endif - - QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(item); - quint32 dirty = itemPriv->dirtyAttributes; - itemPriv->dirtyAttributes = 0; - - if ((dirty & QQuickItemPrivate::TransformUpdateMask) || - (dirty & QQuickItemPrivate::Size && itemPriv->origin != QQuickItem::TopLeft && - (itemPriv->scale != 1. || itemPriv->rotation != 0.))) { - - QMatrix4x4 matrix; - - if (itemPriv->x != 0. || itemPriv->y != 0.) - matrix.translate(itemPriv->x, itemPriv->y); - - for (int ii = itemPriv->transforms.count() - 1; ii >= 0; --ii) - itemPriv->transforms.at(ii)->applyTo(&matrix); - - if (itemPriv->scale != 1. || itemPriv->rotation != 0.) { - QPointF origin = item->transformOriginPoint(); - matrix.translate(origin.x(), origin.y()); - if (itemPriv->scale != 1.) - matrix.scale(itemPriv->scale, itemPriv->scale); - if (itemPriv->rotation != 0.) - matrix.rotate(itemPriv->rotation, 0, 0, 1); - matrix.translate(-origin.x(), -origin.y()); - } - - itemPriv->itemNode()->setMatrix(matrix); - } - - bool clipEffectivelyChanged = dirty & QQuickItemPrivate::Clip && - ((item->clip() == false) != (itemPriv->clipNode == 0)); - bool effectRefEffectivelyChanged = dirty & QQuickItemPrivate::EffectReference && - ((itemPriv->effectRefCount == 0) != (itemPriv->rootNode == 0)); - - if (clipEffectivelyChanged) { - QSGNode *parent = itemPriv->opacityNode ? (QSGNode *) itemPriv->opacityNode : (QSGNode *)itemPriv->itemNode(); - QSGNode *child = itemPriv->rootNode ? (QSGNode *)itemPriv->rootNode : (QSGNode *)itemPriv->groupNode; - - if (item->clip()) { - Q_ASSERT(itemPriv->clipNode == 0); - itemPriv->clipNode = new QQuickDefaultClipNode(item->boundingRect()); - itemPriv->clipNode->update(); - - if (child) - parent->removeChildNode(child); - parent->appendChildNode(itemPriv->clipNode); - if (child) - itemPriv->clipNode->appendChildNode(child); - - } else { - Q_ASSERT(itemPriv->clipNode != 0); - parent->removeChildNode(itemPriv->clipNode); - if (child) - itemPriv->clipNode->removeChildNode(child); - delete itemPriv->clipNode; - itemPriv->clipNode = 0; - if (child) - parent->appendChildNode(child); - } - } - - if (dirty & QQuickItemPrivate::ChildrenUpdateMask) - itemPriv->childContainerNode()->removeAllChildNodes(); - - if (effectRefEffectivelyChanged) { - QSGNode *parent = itemPriv->clipNode; - if (!parent) - parent = itemPriv->opacityNode; - if (!parent) - parent = itemPriv->itemNode(); - QSGNode *child = itemPriv->groupNode; - - if (itemPriv->effectRefCount) { - Q_ASSERT(itemPriv->rootNode == 0); - itemPriv->rootNode = new QSGRootNode; - - if (child) - parent->removeChildNode(child); - parent->appendChildNode(itemPriv->rootNode); - if (child) - itemPriv->rootNode->appendChildNode(child); - } else { - Q_ASSERT(itemPriv->rootNode != 0); - parent->removeChildNode(itemPriv->rootNode); - if (child) - itemPriv->rootNode->removeChildNode(child); - delete itemPriv->rootNode; - itemPriv->rootNode = 0; - if (child) - parent->appendChildNode(child); - } - } - - if (dirty & QQuickItemPrivate::ChildrenUpdateMask) { - QSGNode *groupNode = itemPriv->groupNode; - if (groupNode) - groupNode->removeAllChildNodes(); - - QList orderedChildren = itemPriv->paintOrderChildItems(); - int ii = 0; - - for (; ii < orderedChildren.count() && orderedChildren.at(ii)->z() < 0; ++ii) { - QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(orderedChildren.at(ii)); - if (!childPrivate->explicitVisible && !childPrivate->effectRefCount) - continue; - if (childPrivate->itemNode()->parent()) - childPrivate->itemNode()->parent()->removeChildNode(childPrivate->itemNode()); - - itemPriv->childContainerNode()->appendChildNode(childPrivate->itemNode()); - } - itemPriv->beforePaintNode = itemPriv->groupNode ? itemPriv->groupNode->lastChild() : 0; - - if (itemPriv->paintNode) - itemPriv->childContainerNode()->appendChildNode(itemPriv->paintNode); - - for (; ii < orderedChildren.count(); ++ii) { - QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(orderedChildren.at(ii)); - if (!childPrivate->explicitVisible && !childPrivate->effectRefCount) - continue; - if (childPrivate->itemNode()->parent()) - childPrivate->itemNode()->parent()->removeChildNode(childPrivate->itemNode()); - - itemPriv->childContainerNode()->appendChildNode(childPrivate->itemNode()); - } - } - - if ((dirty & QQuickItemPrivate::Size) && itemPriv->clipNode) { - itemPriv->clipNode->setRect(item->boundingRect()); - itemPriv->clipNode->update(); - } - - if (dirty & (QQuickItemPrivate::OpacityValue | QQuickItemPrivate::Visible | QQuickItemPrivate::HideReference)) { - qreal opacity = itemPriv->explicitVisible && itemPriv->hideRefCount == 0 - ? itemPriv->opacity : qreal(0); - - if (opacity != 1 && !itemPriv->opacityNode) { - itemPriv->opacityNode = new QSGOpacityNode; - - QSGNode *parent = itemPriv->itemNode(); - QSGNode *child = itemPriv->clipNode; - if (!child) - child = itemPriv->rootNode; - if (!child) - child = itemPriv->groupNode; - - if (child) - parent->removeChildNode(child); - parent->appendChildNode(itemPriv->opacityNode); - if (child) - itemPriv->opacityNode->appendChildNode(child); - } - if (itemPriv->opacityNode) - itemPriv->opacityNode->setOpacity(opacity); - } - - if (dirty & QQuickItemPrivate::ContentUpdateMask) { - - if (itemPriv->flags & QQuickItem::ItemHasContents) { - updatePaintNodeData.transformNode = itemPriv->itemNode(); - itemPriv->paintNode = item->updatePaintNode(itemPriv->paintNode, &updatePaintNodeData); - - Q_ASSERT(itemPriv->paintNode == 0 || - itemPriv->paintNode->parent() == 0 || - itemPriv->paintNode->parent() == itemPriv->childContainerNode()); - - if (itemPriv->paintNode && itemPriv->paintNode->parent() == 0) { - if (itemPriv->beforePaintNode) - itemPriv->childContainerNode()->insertChildNodeAfter(itemPriv->paintNode, itemPriv->beforePaintNode); - else - itemPriv->childContainerNode()->prependChildNode(itemPriv->paintNode); - } - } else if (itemPriv->paintNode) { - delete itemPriv->paintNode; - itemPriv->paintNode = 0; - } - } - -#ifndef QT_NO_DEBUG - // Check consistency. - const QSGNode *nodeChain[] = { - itemPriv->itemNodeInstance, - itemPriv->opacityNode, - itemPriv->clipNode, - itemPriv->rootNode, - itemPriv->groupNode, - itemPriv->paintNode, - }; - - int ip = 0; - for (;;) { - while (ip < 5 && nodeChain[ip] == 0) - ++ip; - if (ip == 5) - break; - int ic = ip + 1; - while (ic < 5 && nodeChain[ic] == 0) - ++ic; - const QSGNode *parent = nodeChain[ip]; - const QSGNode *child = nodeChain[ic]; - if (child == 0) { - Q_ASSERT(parent == itemPriv->groupNode || parent->childCount() == 0); - } else { - Q_ASSERT(parent == itemPriv->groupNode || parent->childCount() == 1); - Q_ASSERT(child->parent() == parent); - bool containsChild = false; - for (QSGNode *n = parent->firstChild(); n; n = n->nextSibling()) - containsChild |= (n == child); - Q_ASSERT(containsChild); - } - ip = ic; - } -#endif - -#ifdef QML_RUNTIME_TESTING - if (itemPriv->sceneGraphContext()->isFlashModeEnabled()) { - QSGFlashNode *flash = new QSGFlashNode(); - flash->setRect(item->boundingRect()); - itemPriv->childContainerNode()->appendChildNode(flash); - didFlash = true; - } - Q_Q(QQuickCanvas); - if (didFlash) { - q->maybeUpdate(); - } -#endif - -} - -void QQuickCanvas::maybeUpdate() -{ - Q_D(QQuickCanvas); - - if (d->thread && d->thread->isRunning()) - d->thread->maybeUpdate(); -} - -/*! - \fn void QSGEngine::sceneGraphInitialized(); - - This signal is emitted when the scene graph has been initialized. - - This signal will be emitted from the scene graph rendering thread. - */ - -/*! - Returns the QSGEngine used for this scene. - - The engine will only be available once the scene graph has been - initialized. Register for the sceneGraphEngine() signal to get - notification about this. - - \deprecated - */ - -QSGEngine *QQuickCanvas::sceneGraphEngine() const -{ - Q_D(const QQuickCanvas); - qWarning("QQuickCanvas::sceneGraphEngine() is deprecated, use members of QQuickCanvas instead"); - if (d->context && d->context->isReady()) - return d->engine; - return 0; -} - - - -/*! - Sets the render target for this canvas to be \a fbo. - - The specified fbo must be created in the context of the canvas - or one that shares with it. - - \warning - This function can only be called from the thread doing - the rendering. - */ - -void QQuickCanvas::setRenderTarget(QOpenGLFramebufferObject *fbo) -{ - Q_D(QQuickCanvas); - if (d->context && d->context && QThread::currentThread() != d->context->thread()) { - qWarning("QQuickCanvas::setRenderThread: Cannot set render target from outside the rendering thread"); - return; - } - - d->renderTarget = fbo; -} - - - -/*! - Returns the render target for this canvas. - - The default is to render to the surface of the canvas, in which - case the render target is 0. - */ -QOpenGLFramebufferObject *QQuickCanvas::renderTarget() const -{ - Q_D(const QQuickCanvas); - return d->renderTarget; -} - - -/*! - Grabs the contents of the framebuffer and returns it as an image. - - This function might not work if the view is not visible. - - \warning Calling this function will cause performance problems. - - \warning This function can only be called from the GUI thread. - */ -QImage QQuickCanvas::grabFrameBuffer() -{ - Q_D(QQuickCanvas); - return d->thread ? d->thread->grab() : QImage(); -} - -/*! - Returns an incubation controller that splices incubation between frames - for this canvas. QQuickView automatically installs this controller for you, - otherwise you will need to install it yourself using \l{QDeclarativeEngine::setIncubationController} - - The controller is owned by the canvas and will be destroyed when the canvas - is deleted. -*/ -QDeclarativeIncubationController *QQuickCanvas::incubationController() const -{ - Q_D(const QQuickCanvas); - - if (!d->incubationController) - d->incubationController = new QQuickCanvasIncubationController(const_cast(d)); - return d->incubationController; -} - - - -/*! - \enum QQuickCanvas::CreateTextureOption - - The CreateTextureOption enums are used to customize a texture is wrapped. - - \value TextureHasAlphaChannel The texture has an alpha channel and should - be drawn using blending. - - \value TextureHasMipmaps The texture has mipmaps and can be drawn with - mipmapping enabled. - - \value TextureOwnsGLTexture The texture object owns the texture id and - will delete the GL texture when the texture object is deleted. - */ - -/*! - \fn void QQuickCanvas::beforeRendering() - - This signal is emitted before the scene starts rendering. - - Combined with the modes for clearing the background, this option - can be used to paint using raw GL under QML content. - - The GL context used for rendering the scene graph will be bound - at this point. - - Since this signal is emitted from the scene graph rendering thread, the receiver should - be on the scene graph thread or the connection should be Qt::DirectConnection. - -*/ - -/*! - \fn void QQuickCanvas::afterRendering() - - This signal is emitted after the scene has completed rendering, before swapbuffers is called. - - This signal can be used to paint using raw GL on top of QML content, - or to do screen scraping of the current frame buffer. - - The GL context used for rendering the scene graph will be bound at this point. - - Since this signal is emitted from the scene graph rendering thread, the receiver should - be on the scene graph thread or the connection should be Qt::DirectConnection. - */ - - - -/*! - Sets weither the scene graph rendering of QML should clear the color buffer - before it starts rendering to \a enbled. - - By disabling clearing of the color buffer, it is possible to do GL painting - under the scene graph. - - The color buffer is cleared by default. - - \sa beforeRendering() - */ - -void QQuickCanvas::setClearBeforeRendering(bool enabled) -{ - Q_D(QQuickCanvas); - d->clearBeforeRendering = enabled; -} - - - -/*! - Returns weither clearing of the color buffer is done before rendering or not. - */ - -bool QQuickCanvas::clearBeforeRendering() const -{ - Q_D(const QQuickCanvas); - return d->clearBeforeRendering; -} - - - -/*! - Creates a new QSGTexture from the supplied \a image. If the image has an - alpha channel, the corresponding texture will have an alpha channel. - - The caller of the function is responsible for deleting the returned texture. - The actual GL texture will be deleted when the texture object is deleted. - - \warning This function will return 0 if the scene graph has not yet been - initialized. - - This function can be called both from the GUI thread and the rendering thread. - - \sa sceneGraphInitialized() - */ - -QSGTexture *QQuickCanvas::createTextureFromImage(const QImage &image) const -{ - Q_D(const QQuickCanvas); - if (d->context) - return d->context->createTexture(image); - else - return 0; -} - - - -/*! - Creates a new QSGTexture object from an existing GL texture \a id. - - The caller of the function is responsible for deleting the returned texture. - - Use \a options to customize the texture attributes. - - \warning This function will return 0 if the scenegraph has not yet been - initialized. - - \sa sceneGraphInitialized() - */ -QSGTexture *QQuickCanvas::createTextureFromId(uint id, const QSize &size, CreateTextureOptions options) const -{ - Q_D(const QQuickCanvas); - if (d->context) { - QSGPlainTexture *texture = new QSGPlainTexture(); - texture->setTextureId(id); - texture->setHasAlphaChannel(options & TextureHasAlphaChannel); - texture->setHasMipmaps(options & TextureHasMipmaps); - texture->setOwnsTexture(options & TextureOwnsGLTexture); - texture->setTextureSize(size); - return texture; - } - return 0; -} - - -/*! - Sets the color used to clear the opengl context to \a color. - - Setting the clear color has no effect when clearing is disabled. - - \sa setClearBeforeRendering() - */ - -void QQuickCanvas::setClearColor(const QColor &color) -{ - if (color == d_func()->clearColor) - return; - d_func()->clearColor = color; - emit clearColorChanged(color); -} - - - -/*! - Returns the color used to clear the opengl context. - */ - -QColor QQuickCanvas::clearColor() const -{ - return d_func()->clearColor; -} - - - -void QQuickCanvasRenderLoop::createGLContext() -{ - gl = new QOpenGLContext(); - gl->setFormat(renderer->requestedFormat()); - gl->create(); -} - -void QQuickCanvasRenderThread::run() -{ -#ifdef THREAD_DEBUG - qDebug("QML Rendering Thread Started"); -#endif - - if (!glContext()) { - createGLContext(); - makeCurrent(); - initializeSceneGraph(); - } else { - makeCurrent(); - } - - while (!shouldExit) { - lock(); - - bool sizeChanged = false; - isExternalUpdatePending = false; - - if (renderedSize != windowSize) { -#ifdef THREAD_DEBUG - printf(" RenderThread: window has changed size...\n"); -#endif - glViewport(0, 0, windowSize.width(), windowSize.height()); - sizeChanged = true; - } - -#ifdef THREAD_DEBUG - printf(" RenderThread: preparing to sync...\n"); -#endif - - if (!isGuiBlocked) { - isGuiBlockPending = true; - -#ifdef THREAD_DEBUG - printf(" RenderThread: aquired sync lock...\n"); -#endif - allowMainThreadProcessingFlag = false; - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); -#ifdef THREAD_DEBUG - printf(" RenderThread: going to sleep...\n"); -#endif - wait(); - - isGuiBlockPending = false; - } - -#ifdef THREAD_DEBUG - printf(" RenderThread: Doing locked sync\n"); -#endif -#ifdef QQUICK_CANVAS_TIMING - if (qquick_canvas_timing) - threadTimer.start(); -#endif - inSync = true; - syncSceneGraph(); - inSync = false; - - // Wake GUI after sync to let it continue animating and event processing. - allowMainThreadProcessingFlag = true; - wake(); - unlock(); -#ifdef THREAD_DEBUG - printf(" RenderThread: sync done\n"); -#endif -#ifdef QQUICK_CANVAS_TIMING - if (qquick_canvas_timing) - syncTime = threadTimer.elapsed(); -#endif - -#ifdef THREAD_DEBUG - printf(" RenderThread: rendering... %d x %d\n", windowSize.width(), windowSize.height()); -#endif - - renderSceneGraph(windowSize); -#ifdef QQUICK_CANVAS_TIMING - if (qquick_canvas_timing) - renderTime = threadTimer.elapsed() - syncTime; -#endif - - // The content of the target buffer is undefined after swap() so grab needs - // to happen before swap(); - if (doGrab) { -#ifdef THREAD_DEBUG - printf(" RenderThread: doing a grab...\n"); -#endif - grabContent = qt_gl_read_framebuffer(windowSize, false, false); - doGrab = false; - } - -#ifdef THREAD_DEBUG - printf(" RenderThread: wait for swap...\n"); -#endif - - swapBuffers(); -#ifdef THREAD_DEBUG - printf(" RenderThread: swap complete...\n"); -#endif -#ifdef QQUICK_CANVAS_TIMING - if (qquick_canvas_timing) { - swapTime = threadTimer.elapsed() - renderTime; - qDebug() << "- Breakdown of frame time: sync:" << syncTime - << "ms render:" << renderTime << "ms swap:" << swapTime - << "ms total:" << swapTime + renderTime << "ms"; - } -#endif - - lock(); - isPaintCompleted = true; - if (sizeChanged) - renderedSize = windowSize; - - // Wake the GUI thread now that rendering is complete, to signal that painting - // is done, resizing is done or grabbing is completed. For grabbing, we're - // signalling this much later than needed (we could have done it before swap) - // but we don't want to lock an extra time. - wake(); - - if (!animationRunning && !isExternalUpdatePending && !shouldExit && !doGrab) { -#ifdef THREAD_DEBUG - printf(" RenderThread: nothing to do, going to sleep...\n"); -#endif - isRenderBlocked = true; - wait(); - isRenderBlocked = false; - } - - unlock(); - - QCoreApplication::processEvents(); - - // Process any "deleteLater" objects... - QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - } - -#ifdef THREAD_DEBUG - printf(" RenderThread: deleting all outstanding nodes\n"); -#endif - cleanupNodesOnShutdown(); - -#ifdef THREAD_DEBUG - printf(" RenderThread: render loop exited... Good Night!\n"); -#endif - - doneCurrent(); - - lock(); - hasExited = true; -#ifdef THREAD_DEBUG - printf(" RenderThread: waking GUI for final sleep..\n"); -#endif - wake(); - unlock(); - -#ifdef THREAD_DEBUG - printf(" RenderThread: All done...\n"); -#endif -} - - - -bool QQuickCanvasRenderThread::event(QEvent *e) -{ - Q_ASSERT(QThread::currentThread() == qApp->thread()); - - if (e->type() == QEvent::User) { - if (!syncAlreadyHappened) - sync(false); - - syncAlreadyHappened = false; - - if (animationRunning && animationDriver()) { -#ifdef THREAD_DEBUG - qDebug("GUI: Advancing animations...\n"); -#endif - - animationDriver()->advance(); - -#ifdef THREAD_DEBUG - qDebug("GUI: Animations advanced...\n"); -#endif - } - - return true; - } - - return QThread::event(e); -} - - - -void QQuickCanvasRenderThread::exhaustSyncEvent() -{ - if (isGuiBlockPending) { - sync(true); - syncAlreadyHappened = true; - } -} - - - -void QQuickCanvasRenderThread::sync(bool guiAlreadyLocked) -{ -#ifdef THREAD_DEBUG - printf("GUI: sync - %s\n", guiAlreadyLocked ? "outside event" : "inside event"); -#endif - if (!guiAlreadyLocked) - lockInGui(); - - renderThreadAwakened = false; - - polishItems(); - - wake(); - wait(); - - if (!guiAlreadyLocked) - unlockInGui(); -} - - - - -/*! - Acquires the mutex for the GUI thread. The function uses the isGuiBlocked - variable to keep track of how many recursion levels the gui is locked with. - We only actually acquire the mutex for the first level to avoid deadlocking - ourselves. - */ - -void QQuickCanvasRenderThread::lockInGui() -{ - // We must avoid recursive locking in the GUI thread, hence we - // only lock when we are the first one to try to block. - if (!isGuiBlocked) - lock(); - - isGuiBlocked++; - -#ifdef THREAD_DEBUG - printf("GUI: aquired lock... %d\n", isGuiBlocked); -#endif -} - - - -void QQuickCanvasRenderThread::unlockInGui() -{ -#ifdef THREAD_DEBUG - printf("GUI: releasing lock... %d\n", isGuiBlocked); -#endif - --isGuiBlocked; - if (!isGuiBlocked) - unlock(); -} - - - - -void QQuickCanvasRenderThread::animationStarted() -{ -#ifdef THREAD_DEBUG - printf("GUI: animationStarted()\n"); -#endif - - lockInGui(); - - animationRunning = true; - - if (isRenderBlocked) - wake(); - - unlockInGui(); -} - - - -void QQuickCanvasRenderThread::animationStopped() -{ -#ifdef THREAD_DEBUG - printf("GUI: animationStopped()...\n"); -#endif - - lockInGui(); - animationRunning = false; - unlockInGui(); -} - - -void QQuickCanvasRenderThread::paint() -{ -#ifdef THREAD_DEBUG - printf("GUI: paint called..\n"); -#endif - - lockInGui(); - exhaustSyncEvent(); - - isPaintCompleted = false; - while (isRunning() && !isPaintCompleted) { - if (isRenderBlocked) - wake(); - wait(); - } - unlockInGui(); -} - - - -void QQuickCanvasRenderThread::resize(const QSize &size) -{ -#ifdef THREAD_DEBUG - printf("GUI: Resize Event: %dx%d\n", size.width(), size.height()); -#endif - - if (!isRunning()) { - windowSize = size; - return; - } - - lockInGui(); - exhaustSyncEvent(); - - windowSize = size; - - while (isRunning() && renderedSize != windowSize) { - if (isRenderBlocked) - wake(); - wait(); - } - unlockInGui(); -} - - - -void QQuickCanvasRenderThread::startRendering() -{ -#ifdef THREAD_DEBUG - printf("GUI: Starting Render Thread\n"); -#endif - hasExited = false; - shouldExit = false; - isGuiBlocked = 0; - isGuiBlockPending = false; - start(); -} - - - -void QQuickCanvasRenderThread::stopRendering() -{ -#ifdef THREAD_DEBUG - printf("GUI: stopping render thread\n"); -#endif - - lockInGui(); - exhaustSyncEvent(); - shouldExit = true; - - if (isRenderBlocked) { -#ifdef THREAD_DEBUG - printf("GUI: waking up render thread\n"); -#endif - wake(); - } - - while (!hasExited) { -#ifdef THREAD_DEBUG - printf("GUI: waiting for render thread to have exited..\n"); -#endif - wait(); - } - - 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(); - -#ifdef THREAD_DEBUG - printf("GUI: thread has terminated and we're all good..\n"); -#endif - -} - - - -QImage QQuickCanvasRenderThread::grab() -{ - if (!isRunning()) - return QImage(); - - if (QThread::currentThread() != qApp->thread()) { - qWarning("QQuickCanvas::grabFrameBuffer: can only be called from the GUI thread"); - return QImage(); - } - -#ifdef THREAD_DEBUG - printf("GUI: doing a pixelwise grab..\n"); -#endif - - lockInGui(); - exhaustSyncEvent(); - - doGrab = true; - isPaintCompleted = false; - while (isRunning() && !isPaintCompleted) { - if (isRenderBlocked) - wake(); - wait(); - } - - QImage grabbed = grabContent; - grabContent = QImage(); - - unlockInGui(); - - return grabbed; -} - - - -void QQuickCanvasRenderThread::maybeUpdate() -{ - Q_ASSERT_X(QThread::currentThread() == QCoreApplication::instance()->thread() || inSync, - "QQuickCanvas::update", - "Function can only be called from GUI thread or during QQuickItem::updatePaintNode()"); - - if (inSync) { - isExternalUpdatePending = true; - - } else if (!renderThreadAwakened) { -#ifdef THREAD_DEBUG - printf("GUI: doing update...\n"); -#endif - renderThreadAwakened = true; - lockInGui(); - isExternalUpdatePending = true; - if (isRenderBlocked) - wake(); - unlockInGui(); - } -} - - -#include "moc_qquickcanvas.cpp" - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickcanvas.h b/src/declarative/items/qquickcanvas.h deleted file mode 100644 index c27776f234..0000000000 --- a/src/declarative/items/qquickcanvas.h +++ /dev/null @@ -1,164 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKCANVAS_H -#define QQUICKCANVAS_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGEngine; -class QQuickItem; -class QSGTexture; -class QInputMethodEvent; -class QQuickCanvasPrivate; -class QOpenGLFramebufferObject; -class QDeclarativeIncubationController; -class QInputMethodEvent; - -class Q_DECLARATIVE_EXPORT QQuickCanvas : public QWindow -{ - Q_OBJECT - Q_PRIVATE_PROPERTY(QQuickCanvas::d_func(), QDeclarativeListProperty data READ data DESIGNABLE false) - Q_PROPERTY(QColor color READ clearColor WRITE setClearColor NOTIFY clearColorChanged) - Q_CLASSINFO("DefaultProperty", "data") - Q_DECLARE_PRIVATE(QQuickCanvas) -public: - enum CreateTextureOption { - TextureHasAlphaChannel = 0x0001, - TextureHasMipmaps = 0x0002, - TextureOwnsGLTexture = 0x0004 - }; - - Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption) - - QQuickCanvas(QWindow *parent = 0); - - virtual ~QQuickCanvas(); - - QQuickItem *rootItem() const; - QQuickItem *activeFocusItem() const; - - QQuickItem *mouseGrabberItem() const; - - bool sendEvent(QQuickItem *, QEvent *); - - QSGEngine *sceneGraphEngine() const; - - void setVSyncAnimations(bool enabled); - bool vsyncAnimations() const; - - QImage grabFrameBuffer(); - - void setRenderTarget(QOpenGLFramebufferObject *fbo); - QOpenGLFramebufferObject *renderTarget() const; - - QDeclarativeIncubationController *incubationController() const; - - // Scene graph specific functions - QSGTexture *createTextureFromImage(const QImage &image) const; - QSGTexture *createTextureFromId(uint id, const QSize &size, CreateTextureOptions options = CreateTextureOption(0)) const; - - void setClearBeforeRendering(bool enabled); - bool clearBeforeRendering() const; - - void setClearColor(const QColor &color); - QColor clearColor() const; - - QOpenGLContext *openglContext() const; - -Q_SIGNALS: - void frameSwapped(); - void sceneGraphInitialized(); - void beforeRendering(); - void afterRendering(); - void clearColorChanged(const QColor &); - -protected: - QQuickCanvas(QQuickCanvasPrivate &dd, QWindow *parent = 0); - - virtual void exposeEvent(QExposeEvent *); - virtual void resizeEvent(QResizeEvent *); - - virtual void showEvent(QShowEvent *); - virtual void hideEvent(QHideEvent *); - - virtual void focusInEvent(QFocusEvent *); - virtual void focusOutEvent(QFocusEvent *); - - virtual bool event(QEvent *); - virtual void keyPressEvent(QKeyEvent *); - virtual void keyReleaseEvent(QKeyEvent *); - virtual void mousePressEvent(QMouseEvent *); - virtual void mouseReleaseEvent(QMouseEvent *); - virtual void mouseDoubleClickEvent(QMouseEvent *); - virtual void mouseMoveEvent(QMouseEvent *); -#ifndef QT_NO_WHEELEVENT - virtual void wheelEvent(QWheelEvent *); -#endif - -private Q_SLOTS: - void maybeUpdate(); - void animationStarted(); - void animationStopped(); - -private: - friend class QQuickItem; - friend class QQuickCanvasRenderLoop; - Q_DISABLE_COPY(QQuickCanvas) -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QQuickCanvas *) - -QT_END_HEADER - -#endif // QQUICKCANVAS_H - diff --git a/src/declarative/items/qquickcanvas_p.h b/src/declarative/items/qquickcanvas_p.h deleted file mode 100644 index 13ca288cb1..0000000000 --- a/src/declarative/items/qquickcanvas_p.h +++ /dev/null @@ -1,323 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKCANVAS_P_H -#define QQUICKCANVAS_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 "qquickitem.h" -#include "qquickcanvas.h" -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -//Make it easy to identify and customize the root item if needed - -class QQuickRootItem : public QQuickItem -{ - Q_OBJECT -public: - QQuickRootItem(); -public Q_SLOTS: - void setWidth(int w) {QQuickItem::setWidth(qreal(w));} - void setHeight(int h) {QQuickItem::setHeight(qreal(h));} -}; - -class QQuickItemPrivate; -class QQuickCanvasPrivate; - -class QTouchEvent; -class QQuickCanvasRenderLoop; -class QQuickCanvasIncubationController; - -class QQuickCanvasPrivate : public QWindowPrivate -{ -public: - Q_DECLARE_PUBLIC(QQuickCanvas) - - static inline QQuickCanvasPrivate *get(QQuickCanvas *c) { return c->d_func(); } - - QQuickCanvasPrivate(); - virtual ~QQuickCanvasPrivate(); - - void init(QQuickCanvas *); - void initRootItem();//Currently only used if items added in QML - - QQuickRootItem *rootItem; - QDeclarativeListProperty data(); - - QQuickItem *activeFocusItem; - QQuickItem *mouseGrabberItem; - QQuickDragGrabber dragGrabber; - - // Mouse positions are saved in widget coordinates - QPointF lastMousePosition; - void translateTouchEvent(QTouchEvent *touchEvent); - static void transformTouchPoints(QList &touchPoints, const QTransform &transform); - bool deliverInitialMousePressEvent(QQuickItem *, QMouseEvent *); - bool deliverMouseEvent(QMouseEvent *); - bool sendFilteredMouseEvent(QQuickItem *, QQuickItem *, QEvent *); - bool deliverWheelEvent(QQuickItem *, QWheelEvent *); - bool deliverTouchPoints(QQuickItem *, QTouchEvent *, const QList &, QSet *, - QHash > *); - bool deliverTouchEvent(QTouchEvent *); - bool deliverHoverEvent(QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos, Qt::KeyboardModifiers modifiers, bool &accepted); - bool sendHoverEvent(QEvent::Type, QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos, - Qt::KeyboardModifiers modifiers, bool accepted); - bool clearHover(); - void deliverDragEvent(QQuickDragGrabber *, QEvent *); - bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *); - - QList hoverItems; - enum FocusOption { - DontChangeFocusProperty = 0x01, - }; - Q_DECLARE_FLAGS(FocusOptions, FocusOption) - - void setFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions = 0); - void clearFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions = 0); - void notifyFocusChangesRecur(QQuickItem **item, int remaining); - - void updateInputMethodData(); - void updateFocusItemTransform(); - - void dirtyItem(QQuickItem *); - void cleanup(QSGNode *); - - void initializeSceneGraph(); - void polishItems(); - void syncSceneGraph(); - void renderSceneGraph(const QSize &size); - - QQuickItem::UpdatePaintNodeData updatePaintNodeData; - - QQuickItem *dirtyItemList; - QList cleanupNodeList; - - QSet itemsToPolish; - - void updateDirtyNodes(); - void cleanupNodes(); - void cleanupNodesOnShutdown(); - bool updateEffectiveOpacity(QQuickItem *); - void updateEffectiveOpacityRoot(QQuickItem *, qreal); - void updateDirtyNode(QQuickItem *); - - QSGEngine *engine; - QSGContext *context; - QColor clearColor; - - uint vsyncAnimations : 1; - uint clearBeforeRendering : 1; - - QQuickCanvasRenderLoop *thread; - QSize widgetSize; - QSize viewportSize; - - QAnimationDriver *animationDriver; - - QOpenGLFramebufferObject *renderTarget; - - QHash itemForTouchPointId; - - mutable QQuickCanvasIncubationController *incubationController; - -private: - static void cleanupNodesOnShutdown(QQuickItem *); -}; - -class QQuickCanvasRenderLoop -{ -public: - QQuickCanvasRenderLoop() - : d(0) - , renderer(0) - , gl(0) - { - } - virtual ~QQuickCanvasRenderLoop() - { - delete gl; - } - - friend class QQuickCanvasPrivate; - - virtual void paint() = 0; - virtual void resize(const QSize &size) = 0; - virtual void startRendering() = 0; - virtual void stopRendering() = 0; - virtual QImage grab() = 0; - virtual void setWindowSize(const QSize &size) = 0; - virtual void maybeUpdate() = 0; - virtual bool isRunning() const = 0; - virtual void animationStarted() = 0; - virtual void animationStopped() = 0; - virtual void moveContextToThread(QSGContext *) { } - virtual bool *allowMainThreadProcessing() { return 0; } - -protected: - void initializeSceneGraph() { d->initializeSceneGraph(); } - void syncSceneGraph() { d->syncSceneGraph(); } - void cleanupNodesOnShutdown() { d->cleanupNodesOnShutdown(); } - void renderSceneGraph(const QSize &size) { d->renderSceneGraph(size); } - void polishItems() { d->polishItems(); } - QAnimationDriver *animationDriver() const { return d->animationDriver; } - - inline QOpenGLContext *glContext() const { return gl; } - void createGLContext(); - void makeCurrent() { gl->makeCurrent(renderer); } - void doneCurrent() { gl->doneCurrent(); } - void swapBuffers() { - gl->swapBuffers(renderer); - emit renderer->frameSwapped(); - } - -private: - QQuickCanvasPrivate *d; - QQuickCanvas *renderer; - - QOpenGLContext *gl; -}; - -class QQuickCanvasRenderThread : public QThread, public QQuickCanvasRenderLoop -{ - Q_OBJECT -public: - QQuickCanvasRenderThread() - : mutex(QMutex::NonRecursive) - , allowMainThreadProcessingFlag(true) - , animationRunning(false) - , isGuiBlocked(0) - , isPaintCompleted(false) - , isGuiBlockPending(false) - , isRenderBlocked(false) - , isExternalUpdatePending(false) - , syncAlreadyHappened(false) - , inSync(false) - , doGrab(false) - , shouldExit(false) - , hasExited(false) - , renderThreadAwakened(false) - {} - - inline void lock() { mutex.lock(); } - inline void unlock() { mutex.unlock(); } - inline void wait() { condition.wait(&mutex); } - inline void wake() { condition.wakeOne(); } - - void lockInGui(); - void unlockInGui(); - - void paint(); - void resize(const QSize &size); - void startRendering(); - void stopRendering(); - void exhaustSyncEvent(); - void sync(bool guiAlreadyLocked); - bool isRunning() const { return QThread::isRunning(); } - void setWindowSize(const QSize &size) { windowSize = size; } - void maybeUpdate(); - void moveContextToThread(QSGContext *c) { c->moveToThread(this); } - bool *allowMainThreadProcessing() { return &allowMainThreadProcessingFlag; } - - bool event(QEvent *); - - QImage grab(); - -public slots: - void animationStarted(); - void animationStopped(); - -public: - QMutex mutex; - QWaitCondition condition; - - bool allowMainThreadProcessingFlag; - - QSize windowSize; - QSize renderedSize; - - uint animationRunning: 1; - int isGuiBlocked; - uint isPaintCompleted : 1; - uint isGuiBlockPending : 1; - uint isRenderBlocked : 1; - uint isExternalUpdatePending : 1; - uint syncAlreadyHappened : 1; - uint inSync : 1; - uint doGrab : 1; - uint shouldExit : 1; - uint hasExited : 1; - uint renderThreadAwakened : 1; - - QImage grabContent; - - void run(); -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickCanvasPrivate::FocusOptions) - -QT_END_NAMESPACE - -#endif // QQUICKCANVAS_P_H diff --git a/src/declarative/items/qquickclipnode.cpp b/src/declarative/items/qquickclipnode.cpp deleted file mode 100644 index 4aeb2dcf69..0000000000 --- a/src/declarative/items/qquickclipnode.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qquickclipnode_p.h" - -#include -#include - -QQuickDefaultClipNode::QQuickDefaultClipNode(const QRectF &rect) - : m_rect(rect) - , m_radius(0) - , m_dirty_geometry(true) - , m_geometry(QSGGeometry::defaultAttributes_Point2D(), 0) -{ - setGeometry(&m_geometry); - setIsRectangular(true); -} - -void QQuickDefaultClipNode::setRect(const QRectF &rect) -{ - m_rect = rect; - m_dirty_geometry = true; -} - -void QQuickDefaultClipNode::setRadius(qreal radius) -{ - m_radius = radius; - m_dirty_geometry = true; - setIsRectangular(radius == 0); -} - -void QQuickDefaultClipNode::update() -{ - if (m_dirty_geometry) { - updateGeometry(); - m_dirty_geometry = false; - } -} - -void QQuickDefaultClipNode::updateGeometry() -{ - QSGGeometry *g = geometry(); - - if (qFuzzyIsNull(m_radius)) { - g->allocate(4); - QSGGeometry::updateRectGeometry(g, m_rect); - - } else { - int vertexCount = 0; - - // Radius should never exceeds half of the width or half of the height - qreal radius = qMin(qMin(m_rect.width() / 2, m_rect.height() / 2), m_radius); - QRectF rect = m_rect; - rect.adjust(radius, radius, -radius, -radius); - - int segments = qMin(30, qCeil(radius)); // Number of segments per corner. - - g->allocate((segments + 1) * 2); - - QVector2D *vertices = (QVector2D *)g->vertexData(); - - for (int part = 0; part < 2; ++part) { - for (int i = 0; i <= segments; ++i) { - //### Should change to calculate sin/cos only once. - qreal angle = qreal(0.5 * M_PI) * (part + i / qreal(segments)); - qreal s = qFastSin(angle); - qreal c = qFastCos(angle); - qreal y = (part ? rect.bottom() : rect.top()) - radius * c; // current inner y-coordinate. - qreal lx = rect.left() - radius * s; // current inner left x-coordinate. - qreal rx = rect.right() + radius * s; // current inner right x-coordinate. - - vertices[vertexCount++] = QVector2D(rx, y); - vertices[vertexCount++] = QVector2D(lx, y); - } - } - - markDirty(DirtyGeometry); - } - setClipRect(m_rect); -} - diff --git a/src/declarative/items/qquickclipnode_p.h b/src/declarative/items/qquickclipnode_p.h deleted file mode 100644 index 0323c9a24a..0000000000 --- a/src/declarative/items/qquickclipnode_p.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKCLIPNODE_P_H -#define QQUICKCLIPNODE_P_H - -#include - -class QQuickDefaultClipNode : public QSGClipNode -{ -public: - QQuickDefaultClipNode(const QRectF &); - - void setRect(const QRectF &); - QRectF rect() const { return m_rect; } - - void setRadius(qreal radius); - qreal radius() const { return m_radius; } - - virtual void update(); - -private: - void updateGeometry(); - QRectF m_rect; - qreal m_radius; - - uint m_dirty_geometry : 1; - uint m_reserved : 31; - - QSGGeometry m_geometry; -}; - -#endif // QQUICKCLIPNODE_P_H diff --git a/src/declarative/items/qquickdrag.cpp b/src/declarative/items/qquickdrag.cpp deleted file mode 100644 index 9dcc4ac7fe..0000000000 --- a/src/declarative/items/qquickdrag.cpp +++ /dev/null @@ -1,462 +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 QtDeclarative module 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 "qquickdrag_p.h" - -#include -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -class QQuickDragAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickDragAttached) -public: - static QQuickDragAttachedPrivate *get(QQuickDragAttached *attached) { - return static_cast(QObjectPrivate::get(attached)); } - - QQuickDragAttachedPrivate() - : attachedItem(0) - , mimeData(0) - , proposedAction(Qt::MoveAction) - , supportedActions(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction) - , active(false) - , listening(false) - { - } - - void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &); - void start() { start(supportedActions); } - void start(Qt::DropActions supportedActions); - void setTarget(QQuickItem *item); - - QQuickDragGrabber dragGrabber; - - QDeclarativeGuard source; - QDeclarativeGuard target; - QQuickItem *attachedItem; - QQuickDragMimeData *mimeData; - Qt::DropAction proposedAction; - Qt::DropActions supportedActions; - bool active : 1; - bool listening : 1; - QPointF hotSpot; - QStringList keys; -}; - -/*! - \qmlclass Drag QQuickDrag - \inqmlmodule QtQuick 2 - \brief The Drag attached property provides drag and drop events for moved Items. - - Using the Drag attached property any Item can made a source of drag and drop - events within a scene. - - When a drag is \l active on an item any change in that items position will - generate a drag events that will be sent to any DropArea that intersects - the with new position of the item. Other items which implement drag and - drop event handlers can also receive these events. - - The following snippet shows how an item can be dragged with a MouseArea. - However, dragging is not limited to mouse drags, anything that can move an item - can generate drag events, this can include touch events, animations and bindings. - - \snippet doc/src/snippets/declarative/drag.qml 0 - - A drag can be terminated either by canceling it with Drag.cancel() or setting - Drag.active to false, or it can be terminated with a drop event by calling - Drag.drop(). If the drop event is accepted Drag.drop() will return the - \l {supportedActions}{drop action} chosen by the recipient of the event, - otherwise it will return Qt.IgnoreAction. - -*/ - -void QQuickDragAttachedPrivate::itemGeometryChanged(QQuickItem *, const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_Q(QQuickDragAttached); - if (newGeometry.topLeft() == oldGeometry.topLeft() || !active) - return; - - if (QQuickCanvas *canvas = attachedItem->canvas()) { - QPoint scenePos = attachedItem->mapToScene(hotSpot).toPoint(); - QDragMoveEvent event(scenePos, mimeData->m_supportedActions, mimeData, Qt::NoButton, Qt::NoModifier); - QQuickDropEventEx::setProposedAction(&event, proposedAction); - QQuickCanvasPrivate::get(canvas)->deliverDragEvent(&dragGrabber, &event); - if (target != dragGrabber.target()) { - target = dragGrabber.target(); - emit q->targetChanged(); - } - } -} - -QQuickDragAttached::QQuickDragAttached(QObject *parent) - : QObject(*new QQuickDragAttachedPrivate, parent) -{ - Q_D(QQuickDragAttached); - d->attachedItem = qobject_cast(parent); - d->source = d->attachedItem; -} - -QQuickDragAttached::~QQuickDragAttached() -{ - Q_D(QQuickDragAttached); - delete d->mimeData; -} - -/*! - \qmlattachedproperty bool QtQuick2::Drag::active - - This property holds whether a drag event sequence is currently active. - - Setting this property to true will send a QDragEnter event to the scene - with the item's current position. Setting it to false will send a - QDragLeave event. - - While a drag is active any change in an item's position will send a QDragMove - event with item's new position to the scene. -*/ - -bool QQuickDragAttached::isActive() const -{ - Q_D(const QQuickDragAttached); - return d->active; -} - -void QQuickDragAttached::setActive(bool active) -{ - Q_D(QQuickDragAttached); - if (d->active != active) { - if (active) - d->start(d->supportedActions); - else - cancel(); - } -} - -/*! - \qmlattachedproperty Object QtQuick2::Drag::source - - This property holds an object that is identified to recipients of drag events as - the source of the events. By default this is the item Drag property is attached to. - - Changes to source while a Drag is active don't take effect until a new drag is started. -*/ - -QObject *QQuickDragAttached::source() const -{ - Q_D(const QQuickDragAttached); - return d->source; -} - -void QQuickDragAttached::setSource(QObject *item) -{ - Q_D(QQuickDragAttached); - if (d->source != item) { - d->source = item; - emit sourceChanged(); - } -} - -void QQuickDragAttached::resetSource() -{ - Q_D(QQuickDragAttached); - if (d->source != d->attachedItem) { - d->source = d->attachedItem; - emit sourceChanged(); - } -} - -/*! - \qmlattachedproperty Object QtQuick2::Drag::target - - While a drag is active this property holds the last object to accept an - enter event from the dragged item, if the current drag position doesn't - intersect any accepting targets it is null. - - When a drag is not active this property holds the object that accepted - the drop event that ended the drag, if no object accepted the drop or - the drag was canceled the target will then be null. -*/ - -QObject *QQuickDragAttached::target() const -{ - Q_D(const QQuickDragAttached); - return d->target; -} - -/*! - \qmlattachedproperty QPointF QtQuick2::Drag::hotSpot - - This property holds the drag position relative to the top left of the item. - - By default this is (0, 0). - - Changes to hotSpot will take effect when the next event is sent. -*/ - -QPointF QQuickDragAttached::hotSpot() const -{ - Q_D(const QQuickDragAttached); - return d->hotSpot; -} - -void QQuickDragAttached::setHotSpot(const QPointF &hotSpot) -{ - Q_D(QQuickDragAttached); - if (d->hotSpot != hotSpot) { - d->hotSpot = hotSpot; - emit hotSpotChanged(); - // Send a move event if active? - } -} - -/*! - \qmlattachedproperty stringlist QtQuick2::Drag::keys - - This property holds a list of keys that can be used by a DropArea to filter drag events. - - Changes to keys while a Drag is active don't take effect until a new drag is started. -*/ - -QStringList QQuickDragAttached::keys() const -{ - Q_D(const QQuickDragAttached); - return d->keys; -} - -void QQuickDragAttached::setKeys(const QStringList &keys) -{ - Q_D(QQuickDragAttached); - if (d->keys != keys) { - d->keys = keys; - emit keysChanged(); - } -} - -/*! - \qmlattachedproperty flags QtQuick2::Drag::supportedActions - - This property holds return values of Drag.drop() supported by the drag source. - - Changes to supportedActions while a Drag is active don't take effect - until a new drag is started. -*/ - -Qt::DropActions QQuickDragAttached::supportedActions() const -{ - Q_D(const QQuickDragAttached); - return d->supportedActions; -} - -void QQuickDragAttached::setSupportedActions(Qt::DropActions actions) -{ - Q_D(QQuickDragAttached); - if (d->supportedActions != actions) { - d->supportedActions = actions; - emit supportedActionsChanged(); - } -} - -/*! - \qmlattachedproperty enumeration QtQuick2::Drag::proposedAction - - This property holds an action that is recommended by the drag source as a - return value from Drag.drop(). - - Changes to proposedAction will take effect when the next event is sent. -*/ - -Qt::DropAction QQuickDragAttached::proposedAction() const -{ - Q_D(const QQuickDragAttached); - return d->proposedAction; -} - -void QQuickDragAttached::setProposedAction(Qt::DropAction action) -{ - Q_D(QQuickDragAttached); - if (d->proposedAction != action) { - d->proposedAction = action; - emit proposedActionChanged(); - // send a move event with the new default action if active? - } -} - -void QQuickDragAttachedPrivate::start(Qt::DropActions supportedActions) -{ - Q_Q(QQuickDragAttached); - Q_ASSERT(!active); - - if (QQuickCanvas *canvas = attachedItem ? attachedItem->canvas() : 0) { - if (!mimeData) - mimeData = new QQuickDragMimeData; - if (!listening) { - QQuickItemPrivate::get(attachedItem)->addItemChangeListener(this, QQuickItemPrivate::Geometry); - listening = true; - } - - mimeData->m_source = source; - mimeData->m_supportedActions = supportedActions; - mimeData->m_keys = keys; - active = true; - - QPoint scenePos = attachedItem->mapToScene(hotSpot).toPoint(); - QDragEnterEvent event(scenePos, supportedActions, mimeData, Qt::NoButton, Qt::NoModifier); - QQuickDropEventEx::setProposedAction(&event, proposedAction); - QQuickCanvasPrivate::get(canvas)->deliverDragEvent(&dragGrabber, &event); - - emit q->activeChanged(); - if (target != dragGrabber.target()) { - target = dragGrabber.target(); - emit q->targetChanged(); - } - } -} - -/*! - \qmlattachedmethod void QtQuick2::Drag::start(flags supportedActions) - - Starts sending drag events. - - The optional \a supportedActions argument can be used to override the \l supportedActions - property for the started sequence. -*/ - -void QQuickDragAttached::start(QDeclarativeV8Function *args) -{ - Q_D(QQuickDragAttached); - if (d->active) - cancel(); - - Qt::DropActions supportedActions = d->supportedActions; - // check arguments for supportedActions, maybe data? - if (args->Length() >= 1) { - v8::Local v = (*args)[0]; - if (v->IsInt32()) - supportedActions = Qt::DropActions(v->Int32Value()); - } - - d->start(supportedActions); -} - -/*! - \qmlattachedmethod enum QtQuick2::Drag::drop() - - Ends a drag sequence by sending a drop event to the target item. - - Returns the action accepted by the target item. If the target item or a parent doesn't accept - the drop event then Qt.IgnoreAction will be returned. - - The returned drop action may be one of: - - \list - \o Qt.CopyAction Copy the data to the target - \o Qt.MoveAction Move the data from the source to the target - \o Qt.LinkAction Create a link from the source to the target. - \o Qt.IgnoreAction Ignore the action (do nothing with the data). - \endlist - -*/ - -int QQuickDragAttached::drop() -{ - Q_D(QQuickDragAttached); - Qt::DropAction acceptedAction = Qt::IgnoreAction; - - if (!d->active) - return acceptedAction; - - QObject *target = 0; - - if (QQuickCanvas *canvas = d->attachedItem->canvas()) { - QPoint scenePos = d->attachedItem->mapToScene(d->hotSpot).toPoint(); - - QDropEvent event( - scenePos, d->mimeData->m_supportedActions, d->mimeData, Qt::NoButton, Qt::NoModifier); - QQuickDropEventEx::setProposedAction(&event, d->proposedAction); - QQuickCanvasPrivate::get(canvas)->deliverDragEvent(&d->dragGrabber, &event); - - if (event.isAccepted()) { - acceptedAction = event.dropAction(); - target = d->dragGrabber.target(); - } - } - - d->active = false; - if (d->target != target) { - d->target = target; - emit targetChanged(); - } - - emit activeChanged(); - return acceptedAction; -} - -/*! - \qmlattachedmethod void QtQuick2::Drag::cancel() - - Ends a drag sequence. -*/ - -void QQuickDragAttached::cancel() -{ - Q_D(QQuickDragAttached); - if (!d->active) - return; - - if (QQuickCanvas *canvas = d->attachedItem->canvas()) { - QDragLeaveEvent event; - QQuickCanvasPrivate::get(canvas)->deliverDragEvent(&d->dragGrabber, &event); - } - - d->active = false; - if (d->target) { - d->target = 0; - emit targetChanged(); - } - emit activeChanged(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickdrag_p.h b/src/declarative/items/qquickdrag_p.h deleted file mode 100644 index 1d950299d7..0000000000 --- a/src/declarative/items/qquickdrag_p.h +++ /dev/null @@ -1,208 +0,0 @@ -// Commit: c6e6a35aeb8794d68a3ca0c4e27a3a1181c066b5 -/**************************************************************************** -** -** 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$ -** 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 QQUICKDRAG_P_H -#define QQUICKDRAG_P_H - -#include - -#include - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickItem; -class QQuickDrag; -class QQuickDragPrivate; - -class QQuickDragGrabber -{ - class Item : public QDeclarativeGuard - { - public: - Item(QQuickItem *item) : QDeclarativeGuard(item) {} - - QIntrusiveListNode node; - protected: - void objectDestroyed(QQuickItem *) { delete this; } - }; - - typedef QIntrusiveList ItemList; - -public: - QQuickDragGrabber() : m_target(0) {} - ~QQuickDragGrabber() { while (!m_items.isEmpty()) delete m_items.first(); } - - - QObject *target() const - { - if (m_target) - return m_target; - else if (!m_items.isEmpty()) - return *m_items.first(); - else - return 0; - } - void setTarget(QObject *target) { m_target = target; } - void resetTarget() { m_target = 0; } - - typedef ItemList::iterator iterator; - iterator begin() { return m_items.begin(); } - iterator end() { return m_items.end(); } - - void grab(QQuickItem *item) { m_items.insert(new Item(item)); } - iterator release(iterator at) { Item *item = *at; at = at.erase(); delete item; return at; } - -private: - - ItemList m_items; - QObject *m_target; -}; - -class QQuickDropEventEx : public QDropEvent -{ -public: - void setProposedAction(Qt::DropAction action) { default_action = action; drop_action = action; } - - static void setProposedAction(QDropEvent *event, Qt::DropAction action) { - static_cast(event)->setProposedAction(action); - } - - void copyActions(const QDropEvent &from) { - default_action = from.proposedAction(); drop_action = from.dropAction(); } - - static void copyActions(QDropEvent *to, const QDropEvent &from) { - static_cast(to)->copyActions(from); - } -}; - -class QQuickDragMimeData : public QMimeData -{ - Q_OBJECT -public: - QQuickDragMimeData() - : m_source(0) - { - } - - QStringList keys() const { return m_keys; } - QObject *source() const { return m_source; } - -private: - QObject *m_source; - Qt::DropActions m_supportedActions; - QStringList m_keys; - - friend class QQuickDragAttached; - friend class QQuickDragAttachedPrivate; -}; - -class QDeclarativeV8Function; - -class QQuickDragAttachedPrivate; -class QQuickDragAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) - Q_PROPERTY(QObject *source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource) - Q_PROPERTY(QObject *target READ target NOTIFY targetChanged) - Q_PROPERTY(QPointF hotSpot READ hotSpot WRITE setHotSpot NOTIFY hotSpotChanged) - Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged) - Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions WRITE setSupportedActions NOTIFY supportedActionsChanged) - Q_PROPERTY(Qt::DropAction proposedAction READ proposedAction WRITE setProposedAction NOTIFY proposedActionChanged) -public: - QQuickDragAttached(QObject *parent); - ~QQuickDragAttached(); - - bool isActive() const; - void setActive(bool active); - - QObject *source() const; - void setSource(QObject *item); - void resetSource(); - - QObject *target() const; - - QPointF hotSpot() const; - void setHotSpot(const QPointF &hotSpot); - - QStringList keys() const; - void setKeys(const QStringList &keys); - - Qt::DropActions supportedActions() const; - void setSupportedActions(Qt::DropActions actions); - - Qt::DropAction proposedAction() const; - void setProposedAction(Qt::DropAction action); - - Q_INVOKABLE int drop(); - -public Q_SLOTS: - void start(QDeclarativeV8Function *); - void cancel(); - -Q_SIGNALS: - void activeChanged(); - void sourceChanged(); - void targetChanged(); - void hotSpotChanged(); - void keysChanged(); - void supportedActionsChanged(); - void proposedActionChanged(); - -private: - Q_DECLARE_PRIVATE(QQuickDragAttached) -}; - - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/declarative/items/qquickdroparea.cpp b/src/declarative/items/qquickdroparea.cpp deleted file mode 100644 index 6ea1467e41..0000000000 --- a/src/declarative/items/qquickdroparea.cpp +++ /dev/null @@ -1,428 +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 QtDeclarative module 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 "qquickdroparea_p.h" -#include "qquickdrag_p.h" -#include "qquickitem_p.h" -#include "qquickcanvas.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickDropAreaDrag::QQuickDropAreaDrag(QQuickDropAreaPrivate *d, QObject *parent) - : QObject(parent) - , d(d) -{ -} - -QQuickDropAreaDrag::~QQuickDropAreaDrag() -{ -} - -class QQuickDropAreaPrivate : public QQuickItemPrivate -{ - Q_DECLARE_PUBLIC(QQuickDropArea) - -public: - QQuickDropAreaPrivate(); - ~QQuickDropAreaPrivate(); - - bool hasMatchingKey(const QStringList &keys) const; - - QStringList getKeys(const QMimeData *mimeData) const; - - QStringList keys; - QRegExp keyRegExp; - QPointF dragPosition; - QQuickDropAreaDrag *drag; - QDeclarativeGuard source; - QDeclarativeGuard mimeData; -}; - -QQuickDropAreaPrivate::QQuickDropAreaPrivate() - : drag(0) -{ -} - -QQuickDropAreaPrivate::~QQuickDropAreaPrivate() -{ - delete drag; -} - -/*! - \qmlclass DropArea QQuickDropArea - \inqmlmodule QtQuick 2 - \brief The DropArea item provides drag and drop handling. - - A DropArea is an invisible item which receives events when other items are - dragged over it. - - The Drag attached property can be used to notify the DropArea when an Item is - dragged over it. - - 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. -*/ - -QQuickDropArea::QQuickDropArea(QQuickItem *parent) - : QQuickItem(*new QQuickDropAreaPrivate, parent) -{ - setFlags(ItemAcceptsDrops); -} - -QQuickDropArea::~QQuickDropArea() -{ -} - -/*! - \qmlproperty bool QtQuick2::DropArea::containsDrag - - This property identifies whether the DropArea currently contains any - dragged items. -*/ - -bool QQuickDropArea::containsDrag() const -{ - Q_D(const QQuickDropArea); - return d->mimeData; -} - -/*! - \qmlproperty stringlist QtQuick2::DropArea::keys - - This property holds a list of drag keys a DropArea will accept. - - If no keys are listed the DropArea will accept events from any drag source, - otherwise the drag source must have at least one compatible key. - - \sa QtQuick2::Drag::keys -*/ - -QStringList QQuickDropArea::keys() const -{ - Q_D(const QQuickDropArea); - return d->keys; -} - -void QQuickDropArea::setKeys(const QStringList &keys) -{ - Q_D(QQuickDropArea); - 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(); - } -} - -QQuickDropAreaDrag *QQuickDropArea::drag() -{ - Q_D(QQuickDropArea); - if (!d->drag) - d->drag = new QQuickDropAreaDrag(d); - return d->drag; -} - -/*! - \qmlproperty Object QtQuick2::DropArea::drag.source - - This property holds the source of a drag. -*/ - -QObject *QQuickDropAreaDrag::source() const -{ - return d->source; -} - -/*! - \qmlproperty qreal QtQuick2::DropArea::drag.x - \qmlproperty qreal QtQuick2::DropArea::drag.y - - These properties hold the coordinates of the last drag event. -*/ - -qreal QQuickDropAreaDrag::x() const -{ - return d->dragPosition.x(); -} - -qreal QQuickDropAreaDrag::y() const -{ - return d->dragPosition.y(); -} - -/*! - \qmlsignal QtQuick2::DropArea::onPositionChanged(DragEvent drag) - - This handler is called when the position of a drag has changed. -*/ - -void QQuickDropArea::dragMoveEvent(QDragMoveEvent *event) -{ - Q_D(QQuickDropArea); - if (!d->mimeData) - return; - - d->dragPosition = event->pos(); - if (d->drag) - emit d->drag->positionChanged(); - - event->accept(); - QQuickDropEvent dragTargetEvent(d, event); - emit positionChanged(&dragTargetEvent); -} - -bool QQuickDropAreaPrivate::hasMatchingKey(const QStringList &keys) const -{ - if (keyRegExp.isEmpty()) - return true; - - foreach (const QString &key, keys) { - if (keyRegExp.exactMatch(key)) - return true; - } - return false; -} - -QStringList QQuickDropAreaPrivate::getKeys(const QMimeData *mimeData) const -{ - if (const QQuickDragMimeData *dragMime = qobject_cast(mimeData)) - return dragMime->keys(); - return mimeData->formats(); -} - -/*! - \qmlsignal QtQuick2::DropArea::onEntered(DragEvent drag) - - This handler is called when a \a drag enters the bounds of a DropArea. -*/ - -void QQuickDropArea::dragEnterEvent(QDragEnterEvent *event) -{ - Q_D(QQuickDropArea); - const QMimeData *mimeData = event->mimeData(); - if (!d->effectiveEnable || d->mimeData || !mimeData || !d->hasMatchingKey(d->getKeys(mimeData))) - return; - - d->dragPosition = event->pos(); - - event->accept(); - QQuickDropEvent dragTargetEvent(d, event); - emit entered(&dragTargetEvent); - - if (event->isAccepted()) { - d->mimeData = const_cast(mimeData); - if (QQuickDragMimeData *dragMime = qobject_cast(d->mimeData)) - d->source = dragMime->source(); - else - d->source = event->source(); - d->dragPosition = event->pos(); - if (d->drag) { - emit d->drag->positionChanged(); - emit d->drag->sourceChanged(); - } - emit containsDragChanged(); - } -} - -/*! - \qmlsignal QtQuick2::DropArea::onExited() - - This handler is called when a drag exits the bounds of a DropArea. -*/ - -void QQuickDropArea::dragLeaveEvent(QDragLeaveEvent *) -{ - Q_D(QQuickDropArea); - if (!d->mimeData) - return; - - emit exited(); - - d->mimeData = 0; - d->source = 0; - emit containsDragChanged(); - if (d->drag) - emit d->drag->sourceChanged(); -} - -/*! - \qmlsignal QtQuick2::DropArea::onDropped(DragEvent drop) - - This handler is called when a drop event occurs within the bounds of a - a DropArea. -*/ - -void QQuickDropArea::dropEvent(QDropEvent *event) -{ - Q_D(QQuickDropArea); - if (!d->mimeData) - return; - - QQuickDropEvent dragTargetEvent(d, event); - emit dropped(&dragTargetEvent); - - d->mimeData = 0; - d->source = 0; - emit containsDragChanged(); - if (d->drag) - emit d->drag->sourceChanged(); -} - -/*! - \qmlclass DragEvent QQuickDragEvent - \inqmlmodule QtQuick 2 - \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 y - properties, and the \l keys property identifies the drag keys of the event - \l source. -*/ - -/*! - \qmlproperty real QtQuick2::DragEvent::x - - This property holds the x coordinate of a drag event. -*/ - -/*! - \qmlproperty real QtQuick2::DragEvent::y - - This property holds the y coordinate of a drag event. -*/ - -/*! - \qmlproperty Object QtQuick2::DragEvent::drag.source - - This property holds the source of a drag event. -*/ - -QObject *QQuickDropEvent::source() -{ - if (const QQuickDragMimeData *dragMime = qobject_cast(event->mimeData())) - return dragMime->source(); - else - return event->source(); -} - -/*! - \qmlproperty stringlist QtQuick2::DragEvent::keys - - This property holds a list of keys identifying the data type or source of a - drag event. -*/ - -QStringList QQuickDropEvent::keys() const -{ - return d->getKeys(event->mimeData()); -} - -/*! - \qmlproperty enum QtQuick2::DragEvent::action - - This property holds the action that the \l source is to perform on an accepted drop. - - The drop action may be one of: - - \list - \o Qt.CopyAction Copy the data to the target - \o Qt.MoveAction Move the data from the source to the target - \o Qt.LinkAction Create a link from the source to the target. - \o Qt.IgnoreAction Ignore the action (do nothing with the data). - \endlist -*/ - -/*! - \qmlproperty flags QtQuick2::DragEvent::supportedActions - - This property holds the set of \l {action}{actions} supported by the - drag source. -*/ - -/*! - \qmlproperty real QtQuick2::DragEvent::accepted - - This property holds whether the drag event was accepted by a handler. - - The default value is true. -*/ - -/*! - \qmlmethod void QtQuick2::DragEvent::accept() - \qmlmethod void QtQuick2::DragEvent::accept(enum action) - - Accepts the drag event. - - If an \a action is specified it will overwrite the value of the \l action property. -*/ - -void QQuickDropEvent::accept(QDeclarativeV8Function *args) -{ - Qt::DropAction action = event->dropAction(); - - if (args->Length() >= 1) { - v8::Local v = (*args)[0]; - if (v->IsInt32()) - action = Qt::DropAction(v->Int32Value()); - } - // get action from arguments. - event->setDropAction(action); - event->accept(); -} - - -QT_END_NAMESPACE - diff --git a/src/declarative/items/qquickdroparea_p.h b/src/declarative/items/qquickdroparea_p.h deleted file mode 100644 index 31e2bd7813..0000000000 --- a/src/declarative/items/qquickdroparea_p.h +++ /dev/null @@ -1,167 +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 QtDeclarative module 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 QQUICKDROPAREA_P_H -#define QQUICKDROPAREA_P_H - -#include "qquickitem.h" - -#include -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickDropAreaPrivate; -class QQuickDropEvent : public QObject -{ - Q_OBJECT - Q_PROPERTY(qreal x READ x) - Q_PROPERTY(qreal y READ y) - Q_PROPERTY(QObject *source READ source) - Q_PROPERTY(QStringList keys READ keys) - Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions) - Q_PROPERTY(Qt::DropAction action READ action WRITE setAction RESET resetAction) - Q_PROPERTY(bool accepted READ accepted WRITE setAccepted) -public: - QQuickDropEvent(QQuickDropAreaPrivate *d, QDropEvent *event) : d(d), event(event) {} - - qreal x() const { return event->pos().x(); } - qreal y() const { return event->pos().y(); } - - QObject *source(); - - Qt::DropActions supportedActions() const { return event->possibleActions(); } - Qt::DropAction action() const { return event->dropAction(); } - void setAction(Qt::DropAction action) { event->setDropAction(action); } - void resetAction() { event->setDropAction(event->proposedAction()); } - - QStringList keys() const; - - bool accepted() const { return event->isAccepted(); } - void setAccepted(bool accepted) { event->setAccepted(accepted); } - - Q_INVOKABLE void accept(QDeclarativeV8Function *); - -private: - QQuickDropAreaPrivate *d; - QDropEvent *event; -}; - -class QQuickDropAreaDrag : public QObject -{ - Q_OBJECT - Q_PROPERTY(qreal x READ x NOTIFY positionChanged) - Q_PROPERTY(qreal y READ y NOTIFY positionChanged) - Q_PROPERTY(QObject *source READ source NOTIFY sourceChanged) -public: - QQuickDropAreaDrag(QQuickDropAreaPrivate *d, QObject *parent = 0); - ~QQuickDropAreaDrag(); - - qreal x() const; - qreal y() const; - QObject *source() const; - -Q_SIGNALS: - void positionChanged(); - void sourceChanged(); - -private: - QQuickDropAreaPrivate *d; - - friend class QQuickDropArea; - friend class QQuickDropAreaPrivate; -}; - -class QQuickDropAreaPrivate; -class Q_AUTOTEST_EXPORT QQuickDropArea : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(bool containsDrag READ containsDrag NOTIFY containsDragChanged) - Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged) - Q_PROPERTY(QQuickDropAreaDrag *drag READ drag CONSTANT) - -public: - QQuickDropArea(QQuickItem *parent=0); - ~QQuickDropArea(); - - bool containsDrag() const; - void setContainsDrag(bool drag); - - QStringList keys() const; - void setKeys(const QStringList &keys); - - QQuickDropAreaDrag *drag(); - -Q_SIGNALS: - void containsDragChanged(); - void keysChanged(); - void sourceChanged(); - - void entered(QQuickDropEvent *drag); - void exited(); - void positionChanged(QQuickDropEvent *drag); - void dropped(QQuickDropEvent *drop); - -protected: - void dragMoveEvent(QDragMoveEvent *event); - void dragEnterEvent(QDragEnterEvent *event); - void dragLeaveEvent(QDragLeaveEvent *event); - void dropEvent(QDropEvent *event); - -private: - Q_DISABLE_COPY(QQuickDropArea) - Q_DECLARE_PRIVATE(QQuickDropArea) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickDropEvent) -QML_DECLARE_TYPE(QQuickDropArea) - -QT_END_HEADER - -#endif // QQUICKDROPAREA_P_H diff --git a/src/declarative/items/qquickevents.cpp b/src/declarative/items/qquickevents.cpp deleted file mode 100644 index c546dd305a..0000000000 --- a/src/declarative/items/qquickevents.cpp +++ /dev/null @@ -1,239 +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 QtDeclarative module 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 "qquickevents_p_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass KeyEvent QQuickKeyEvent - \inqmlmodule QtQuick 2 - \ingroup qml-event-elements - - \brief The KeyEvent object provides information about a key event. - - For example, the following changes the Item's state property when the Enter - key is pressed: - \qml -Item { - focus: true - Keys.onPressed: { if (event.key == Qt.Key_Enter) state = 'ShowDetails'; } -} - \endqml -*/ - -/*! - \qmlproperty int QtQuick2::KeyEvent::key - - This property holds the code of the key that was pressed or released. - - See \l {Qt::Key}{Qt.Key} for the list of keyboard codes. These codes are - independent of the underlying window system. Note that this - function does not distinguish between capital and non-capital - letters, use the text() function (returning the Unicode text the - key generated) for this purpose. - - A value of either 0 or \l {Qt::Key_unknown}{Qt.Key_Unknown} means that the event is not - the result of a known key; for example, it may be the result of - a compose sequence, a keyboard macro, or due to key event - compression. -*/ - -/*! - \qmlproperty string QtQuick2::KeyEvent::text - - This property holds the Unicode text that the key generated. - The text returned can be an empty string in cases where modifier keys, - such as Shift, Control, Alt, and Meta, are being pressed or released. - In such cases \c key will contain a valid value -*/ - -/*! - \qmlproperty bool QtQuick2::KeyEvent::isAutoRepeat - - This property holds whether this event comes from an auto-repeating key. -*/ - -/*! - \qmlproperty int QtQuick2::KeyEvent::count - - This property holds the number of keys involved in this event. If \l KeyEvent::text - is not empty, this is simply the length of the string. -*/ - -/*! - \qmlproperty bool QtQuick2::KeyEvent::accepted - - Setting \a accepted to true prevents the key event from being - propagated to the item's parent. - - Generally, if the item acts on the key event then it should be accepted - so that ancestor items do not also respond to the same event. -*/ - -/*! - \qmlproperty int QtQuick2::KeyEvent::modifiers - - This property holds the keyboard modifier flags that existed immediately - before the event occurred. - - It contains a bitwise combination of: - \list - \o Qt.NoModifier - No modifier key is pressed. - \o Qt.ShiftModifier - A Shift key on the keyboard is pressed. - \o Qt.ControlModifier - A Ctrl key on the keyboard is pressed. - \o Qt.AltModifier - An Alt key on the keyboard is pressed. - \o Qt.MetaModifier - A Meta key on the keyboard is pressed. - \o Qt.KeypadModifier - A keypad button is pressed. - \endlist - - For example, to react to a Shift key + Enter key combination: - \qml - Item { - focus: true - Keys.onPressed: { - if ((event.key == Qt.Key_Enter) && (event.modifiers & Qt.ShiftModifier)) - doSomething(); - } - } - \endqml -*/ - - -/*! - \qmlclass MouseEvent QQuickMouseEvent - \inqmlmodule QtQuick 2 - \ingroup qml-event-elements - - \brief The MouseEvent object provides information about a mouse event. - - The position of the mouse can be found via the \l x and \l y properties. - The button that caused the event is available via the \l button property. - - \sa MouseArea -*/ - -/*! - \internal - \class QQuickMouseEvent -*/ - -/*! - \qmlproperty int QtQuick2::MouseEvent::x - \qmlproperty int QtQuick2::MouseEvent::y - - These properties hold the coordinates of the position supplied by the mouse event. -*/ - - -/*! - \qmlproperty bool QtQuick2::MouseEvent::accepted - - Setting \a accepted to true prevents the mouse event from being - propagated to items below this item. - - Generally, if the item acts on the mouse event then it should be accepted - so that items lower in the stacking order do not also respond to the same event. -*/ - -/*! - \qmlproperty enumeration QtQuick2::MouseEvent::button - - This property holds the button that caused the event. It can be one of: - \list - \o Qt.LeftButton - \o Qt.RightButton - \o Qt.MiddleButton - \endlist -*/ - -/*! - \qmlproperty bool QtQuick2::MouseEvent::wasHeld - - This property is true if the mouse button has been held pressed longer the - threshold (800ms). -*/ - -/*! - \qmlproperty int QtQuick2::MouseEvent::buttons - - This property holds the mouse buttons pressed when the event was generated. - For mouse move events, this is all buttons that are pressed down. For mouse - press and double click events this includes the button that caused the event. - For mouse release events this excludes the button that caused the event. - - It contains a bitwise combination of: - \list - \o Qt.LeftButton - \o Qt.RightButton - \o Qt.MiddleButton - \endlist -*/ - -/*! - \qmlproperty int QtQuick2::MouseEvent::modifiers - - This property holds the keyboard modifier flags that existed immediately - before the event occurred. - - It contains a bitwise combination of: - \list - \o Qt.NoModifier - No modifier key is pressed. - \o Qt.ShiftModifier - A Shift key on the keyboard is pressed. - \o Qt.ControlModifier - A Ctrl key on the keyboard is pressed. - \o Qt.AltModifier - An Alt key on the keyboard is pressed. - \o Qt.MetaModifier - A Meta key on the keyboard is pressed. - \o Qt.KeypadModifier - A keypad button is pressed. - \endlist - - For example, to react to a Shift key + Left mouse button click: - \qml - MouseArea { - onClicked: { - if ((mouse.button == Qt.LeftButton) && (mouse.modifiers & Qt.ShiftModifier)) - doSomething(); - } - } - \endqml -*/ - - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickevents_p_p.h b/src/declarative/items/qquickevents_p_p.h deleted file mode 100644 index cc5ed4f01e..0000000000 --- a/src/declarative/items/qquickevents_p_p.h +++ /dev/null @@ -1,144 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKEVENTS_P_P_H -#define QQUICKEVENTS_P_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 - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickKeyEvent : public QObject -{ - Q_OBJECT - Q_PROPERTY(int key READ key) - Q_PROPERTY(QString text READ text) - Q_PROPERTY(int modifiers READ modifiers) - Q_PROPERTY(bool isAutoRepeat READ isAutoRepeat) - Q_PROPERTY(int count READ count) - Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) - -public: - QQuickKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text=QString(), bool autorep=false, ushort count=1) - : event(type, key, modifiers, text, autorep, count) { event.setAccepted(false); } - QQuickKeyEvent(const QKeyEvent &ke) - : event(ke) { event.setAccepted(false); } - - int key() const { return event.key(); } - QString text() const { return event.text(); } - int modifiers() const { return event.modifiers(); } - bool isAutoRepeat() const { return event.isAutoRepeat(); } - int count() const { return event.count(); } - - bool isAccepted() { return event.isAccepted(); } - void setAccepted(bool accepted) { event.setAccepted(accepted); } - -private: - QKeyEvent event; -}; - -// used in QtLocation -class Q_DECLARATIVE_EXPORT QQuickMouseEvent : public QObject -{ - Q_OBJECT - Q_PROPERTY(qreal x READ x) - Q_PROPERTY(qreal y READ y) - Q_PROPERTY(int button READ button) - Q_PROPERTY(int buttons READ buttons) - Q_PROPERTY(int modifiers READ modifiers) - Q_PROPERTY(bool wasHeld READ wasHeld) - Q_PROPERTY(bool isClick READ isClick) - Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) - -public: - QQuickMouseEvent(qreal x, qreal y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers - , bool isClick=false, bool wasHeld=false) - : _x(x), _y(y), _button(button), _buttons(buttons), _modifiers(modifiers) - , _wasHeld(wasHeld), _isClick(isClick), _accepted(true) {} - - qreal x() const { return _x; } - qreal y() const { return _y; } - int button() const { return _button; } - int buttons() const { return _buttons; } - int modifiers() const { return _modifiers; } - bool wasHeld() const { return _wasHeld; } - bool isClick() const { return _isClick; } - - // only for internal usage - void setX(qreal x) { _x = x; } - void setY(qreal y) { _y = y; } - void setPosition(const QPointF &point) { _x = point.x(); _y = point.y(); } - - bool isAccepted() { return _accepted; } - void setAccepted(bool accepted) { _accepted = accepted; } - -private: - qreal _x; - qreal _y; - Qt::MouseButton _button; - Qt::MouseButtons _buttons; - Qt::KeyboardModifiers _modifiers; - bool _wasHeld; - bool _isClick; - bool _accepted; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickKeyEvent) -QML_DECLARE_TYPE(QQuickMouseEvent) - -#endif // QQUICKEVENTS_P_P_H diff --git a/src/declarative/items/qquickflickable.cpp b/src/declarative/items/qquickflickable.cpp deleted file mode 100644 index aca3542a92..0000000000 --- a/src/declarative/items/qquickflickable.cpp +++ /dev/null @@ -1,2003 +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 QtDeclarative module 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 "qquickflickable_p.h" -#include "qquickflickable_p_p.h" -#include "qquickcanvas.h" -#include "qquickcanvas_p.h" - -#include -#include -#include -#include -#include "qplatformdefs.h" - -QT_BEGIN_NAMESPACE - -// The maximum number of pixels a flick can overshoot -#ifndef QML_FLICK_OVERSHOOT -#define QML_FLICK_OVERSHOOT 200 -#endif - -// The number of samples to use in calculating the velocity of a flick -#ifndef QML_FLICK_SAMPLEBUFFER -#define QML_FLICK_SAMPLEBUFFER 3 -#endif - -// The number of samples to discard when calculating the flick velocity. -// Touch panels often produce inaccurate results as the finger is lifted. -#ifndef QML_FLICK_DISCARDSAMPLES -#define QML_FLICK_DISCARDSAMPLES 1 -#endif - -// The default maximum velocity of a flick. -#ifndef QML_FLICK_DEFAULTMAXVELOCITY -#define QML_FLICK_DEFAULTMAXVELOCITY 2500 -#endif - -// The default deceleration of a flick. -#ifndef QML_FLICK_DEFAULTDECELERATION -#define QML_FLICK_DEFAULTDECELERATION 1500 -#endif - -// How much faster to decelerate when overshooting -#ifndef QML_FLICK_OVERSHOOTFRICTION -#define QML_FLICK_OVERSHOOTFRICTION 8 -#endif - -// FlickThreshold determines how far the "mouse" must have moved -// before we perform a flick. -static const int FlickThreshold = 20; - -// RetainGrabVelocity is the maxmimum instantaneous velocity that -// will ensure the Flickable retains the grab on consecutive flicks. -static const int RetainGrabVelocity = 15; - -QQuickFlickableVisibleArea::QQuickFlickableVisibleArea(QQuickFlickable *parent) - : QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.) - , m_yPosition(0.), m_heightRatio(0.) -{ -} - -qreal QQuickFlickableVisibleArea::widthRatio() const -{ - return m_widthRatio; -} - -qreal QQuickFlickableVisibleArea::xPosition() const -{ - return m_xPosition; -} - -qreal QQuickFlickableVisibleArea::heightRatio() const -{ - return m_heightRatio; -} - -qreal QQuickFlickableVisibleArea::yPosition() const -{ - return m_yPosition; -} - -void QQuickFlickableVisibleArea::updateVisible() -{ - QQuickFlickablePrivate *p = QQuickFlickablePrivate::get(flickable); - - bool changeX = false; - bool changeY = false; - bool changeWidth = false; - bool changeHeight = false; - - // Vertical - const qreal viewheight = flickable->height(); - const qreal maxyextent = -flickable->maxYExtent() + flickable->minYExtent(); - qreal pagePos = (-p->vData.move.value() + flickable->minYExtent()) / (maxyextent + viewheight); - qreal pageSize = viewheight / (maxyextent + viewheight); - - if (pageSize != m_heightRatio) { - m_heightRatio = pageSize; - changeHeight = true; - } - if (pagePos != m_yPosition) { - m_yPosition = pagePos; - changeY = true; - } - - // Horizontal - const qreal viewwidth = flickable->width(); - const qreal maxxextent = -flickable->maxXExtent() + flickable->minXExtent(); - pagePos = (-p->hData.move.value() + flickable->minXExtent()) / (maxxextent + viewwidth); - pageSize = viewwidth / (maxxextent + viewwidth); - - if (pageSize != m_widthRatio) { - m_widthRatio = pageSize; - changeWidth = true; - } - if (pagePos != m_xPosition) { - m_xPosition = pagePos; - changeX = true; - } - - if (changeX) - emit xPositionChanged(m_xPosition); - if (changeY) - emit yPositionChanged(m_yPosition); - if (changeWidth) - emit widthRatioChanged(m_widthRatio); - if (changeHeight) - emit heightRatioChanged(m_heightRatio); -} - - -QQuickFlickablePrivate::QQuickFlickablePrivate() - : contentItem(new QQuickItem) - , hData(this, &QQuickFlickablePrivate::setViewportX) - , vData(this, &QQuickFlickablePrivate::setViewportY) - , hMoved(false), vMoved(false) - , stealMouse(false), pressed(false), interactive(true), calcVelocity(false) - , pixelAligned(false) - , deceleration(QML_FLICK_DEFAULTDECELERATION) - , maxVelocity(QML_FLICK_DEFAULTMAXVELOCITY), reportedVelocitySmoothing(100) - , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0), fixupDuration(400) - , fixupMode(Normal), vTime(0), visibleArea(0) - , flickableDirection(QQuickFlickable::AutoFlickDirection) - , boundsBehavior(QQuickFlickable::DragAndOvershootBounds) -{ -} - -void QQuickFlickablePrivate::init() -{ - Q_Q(QQuickFlickable); - QDeclarative_setParent_noEvent(contentItem, q); - contentItem->setParentItem(q); - FAST_CONNECT(&timeline, SIGNAL(updated()), q, SLOT(ticked())) - FAST_CONNECT(&timeline, SIGNAL(completed()), q, SLOT(movementEnding())) - q->setAcceptedMouseButtons(Qt::LeftButton); - q->setFiltersChildMouseEvents(true); - QQuickItemPrivate *viewportPrivate = QQuickItemPrivate::get(contentItem); - viewportPrivate->addItemChangeListener(this, QQuickItemPrivate::Geometry); - lastPosTime.invalidate(); -} - -/* - Returns the amount to overshoot by given a velocity. - Will be roughly in range 0 - size/4 -*/ -qreal QQuickFlickablePrivate::overShootDistance(qreal size) -{ - if (maxVelocity <= 0) - return 0.0; - - return qMin(qreal(QML_FLICK_OVERSHOOT), size/3); -} - -void QQuickFlickablePrivate::AxisData::addVelocitySample(qreal v, qreal maxVelocity) -{ - if (v > maxVelocity) - v = maxVelocity; - else if (v < -maxVelocity) - v = -maxVelocity; - velocityBuffer.append(v); - if (velocityBuffer.count() > QML_FLICK_SAMPLEBUFFER) - velocityBuffer.remove(0); -} - -void QQuickFlickablePrivate::AxisData::updateVelocity() -{ - velocity = 0; - if (velocityBuffer.count() > QML_FLICK_DISCARDSAMPLES) { - int count = velocityBuffer.count()-QML_FLICK_DISCARDSAMPLES; - for (int i = 0; i < count; ++i) { - qreal v = velocityBuffer.at(i); - velocity += v; - } - velocity /= count; - } -} - -void QQuickFlickablePrivate::itemGeometryChanged(QQuickItem *item, const QRectF &newGeom, const QRectF &oldGeom) -{ - Q_Q(QQuickFlickable); - if (item == contentItem) { - if (newGeom.x() != oldGeom.x()) - emit q->contentXChanged(); - if (newGeom.y() != oldGeom.y()) - emit q->contentYChanged(); - } -} - -void QQuickFlickablePrivate::flickX(qreal velocity) -{ - Q_Q(QQuickFlickable); - flick(hData, q->minXExtent(), q->maxXExtent(), q->width(), fixupX_callback, velocity); -} - -void QQuickFlickablePrivate::flickY(qreal velocity) -{ - Q_Q(QQuickFlickable); - flick(vData, q->minYExtent(), q->maxYExtent(), q->height(), fixupY_callback, velocity); -} - -void QQuickFlickablePrivate::flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal, - QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity) -{ - Q_Q(QQuickFlickable); - qreal maxDistance = -1; - data.fixingUp = false; - // -ve velocity means list is moving up - if (velocity > 0) { - maxDistance = qAbs(minExtent - data.move.value()); - data.flickTarget = minExtent; - } else { - maxDistance = qAbs(maxExtent - data.move.value()); - data.flickTarget = maxExtent; - } - if (maxDistance > 0) { - qreal v = velocity; - if (maxVelocity != -1 && maxVelocity < qAbs(v)) { - if (v < 0) - v = -maxVelocity; - else - v = maxVelocity; - } - timeline.reset(data.move); - if (boundsBehavior == QQuickFlickable::DragAndOvershootBounds) - timeline.accel(data.move, v, deceleration); - else - timeline.accel(data.move, v, deceleration, maxDistance); - timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this)); - if (!hData.flicking && q->xflick()) { - hData.flicking = true; - emit q->flickingChanged(); - emit q->flickingHorizontallyChanged(); - if (!vData.flicking) - emit q->flickStarted(); - } - if (!vData.flicking && q->yflick()) { - vData.flicking = true; - emit q->flickingChanged(); - emit q->flickingVerticallyChanged(); - if (!hData.flicking) - emit q->flickStarted(); - } - } else { - timeline.reset(data.move); - fixup(data, minExtent, maxExtent); - } -} - -void QQuickFlickablePrivate::fixupY_callback(void *data) -{ - ((QQuickFlickablePrivate *)data)->fixupY(); -} - -void QQuickFlickablePrivate::fixupX_callback(void *data) -{ - ((QQuickFlickablePrivate *)data)->fixupX(); -} - -void QQuickFlickablePrivate::fixupX() -{ - Q_Q(QQuickFlickable); - fixup(hData, q->minXExtent(), q->maxXExtent()); -} - -void QQuickFlickablePrivate::fixupY() -{ - Q_Q(QQuickFlickable); - fixup(vData, q->minYExtent(), q->maxYExtent()); -} - -void QQuickFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent) -{ - if (data.move.value() > minExtent || maxExtent > minExtent) { - timeline.reset(data.move); - if (data.move.value() != minExtent) { - switch (fixupMode) { - case Immediate: - timeline.set(data.move, minExtent); - break; - case ExtentChanged: - // The target has changed. Don't start from the beginning; just complete the - // second half of the animation using the new extent. - timeline.move(data.move, minExtent, QEasingCurve(QEasingCurve::OutExpo), 3*fixupDuration/4); - data.fixingUp = true; - break; - default: { - qreal dist = minExtent - data.move; - timeline.move(data.move, minExtent - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); - timeline.move(data.move, minExtent, QEasingCurve(QEasingCurve::OutExpo), 3*fixupDuration/4); - data.fixingUp = true; - } - } - } - } else if (data.move.value() < maxExtent) { - timeline.reset(data.move); - switch (fixupMode) { - case Immediate: - timeline.set(data.move, maxExtent); - break; - case ExtentChanged: - // The target has changed. Don't start from the beginning; just complete the - // second half of the animation using the new extent. - timeline.move(data.move, maxExtent, QEasingCurve(QEasingCurve::OutExpo), 3*fixupDuration/4); - data.fixingUp = true; - break; - default: { - qreal dist = maxExtent - data.move; - timeline.move(data.move, maxExtent - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); - timeline.move(data.move, maxExtent, QEasingCurve(QEasingCurve::OutExpo), 3*fixupDuration/4); - data.fixingUp = true; - } - } - } - data.inOvershoot = false; - fixupMode = Normal; - vTime = timeline.time(); -} - -void QQuickFlickablePrivate::updateBeginningEnd() -{ - Q_Q(QQuickFlickable); - bool atBoundaryChange = false; - - // Vertical - const int maxyextent = int(-q->maxYExtent()); - const qreal ypos = -vData.move.value(); - bool atBeginning = (ypos <= -q->minYExtent()); - bool atEnd = (maxyextent <= ypos); - - if (atBeginning != vData.atBeginning) { - vData.atBeginning = atBeginning; - atBoundaryChange = true; - } - if (atEnd != vData.atEnd) { - vData.atEnd = atEnd; - atBoundaryChange = true; - } - - // Horizontal - const int maxxextent = int(-q->maxXExtent()); - const qreal xpos = -hData.move.value(); - atBeginning = (xpos <= -q->minXExtent()); - atEnd = (maxxextent <= xpos); - - if (atBeginning != hData.atBeginning) { - hData.atBeginning = atBeginning; - atBoundaryChange = true; - } - if (atEnd != hData.atEnd) { - hData.atEnd = atEnd; - atBoundaryChange = true; - } - - if (vData.extentsChanged) { - vData.extentsChanged = false; - emit q->yOriginChanged(); - } - - if (hData.extentsChanged) { - hData.extentsChanged = false; - emit q->xOriginChanged(); - } - - if (atBoundaryChange) - emit q->isAtBoundaryChanged(); - - if (visibleArea) - visibleArea->updateVisible(); -} - -/* -XXXTODO add docs describing moving, dragging, flicking properties, e.g. - -When the user starts dragging the Flickable, the dragging and moving properties -will be true. - -If the velocity is sufficient when the drag is ended, flicking may begin. - -The moving properties will remain true until all dragging and flicking -is finished. -*/ - -/*! - \qmlsignal QtQuick2::Flickable::onDragStarted() - - This handler is called when the view starts to be dragged due to user - interaction. -*/ - -/*! - \qmlsignal QtQuick2::Flickable::onDragEnded() - - This handler is called when the user stops dragging the view. - - If the velocity of the drag is suffient at the time the - touch/mouse button is released then a flick will start. -*/ - -/*! - \qmlclass Flickable QQuickFlickable - \inqmlmodule QtQuick 2 - \ingroup qml-basic-interaction-elements - - \brief The Flickable item provides a surface that can be "flicked". - \inherits Item - - The Flickable item places its children on a surface that can be dragged - and flicked, causing the view onto the child items to scroll. This - behavior forms the basis of Items that are designed to show large numbers - of child items, such as \l ListView and \l GridView. - - In traditional user interfaces, views can be scrolled using standard - controls, such as scroll bars and arrow buttons. In some situations, it - is also possible to drag the view directly by pressing and holding a - mouse button while moving the cursor. In touch-based user interfaces, - this dragging action is often complemented with a flicking action, where - scrolling continues after the user has stopped touching the view. - - Flickable does not automatically clip its contents. If it is not used as - a full-screen item, you should consider setting the \l{Item::}{clip} property - to true. - - \section1 Example Usage - - \div {class="float-right"} - \inlineimage flickable.gif - \enddiv - - The following example shows a small view onto a large image in which the - user can drag or flick the image in order to view different parts of it. - - \snippet doc/src/snippets/declarative/flickable.qml document - - \clearfloat - - Items declared as children of a Flickable are automatically parented to the - Flickable's \l contentItem. This should be taken into account when - operating on the children of the Flickable; it is usually the children of - \c contentItem that are relevant. For example, the bound of Items added - to the Flickable will be available by \c contentItem.childrenRect - - \section1 Limitations - - \note Due to an implementation detail, items placed inside a Flickable cannot anchor to it by - \c id. Use \c parent instead. -*/ - -/*! - \qmlsignal QtQuick2::Flickable::onMovementStarted() - - This handler is called when the view begins moving due to user - interaction. -*/ - -/*! - \qmlsignal QtQuick2::Flickable::onMovementEnded() - - This handler is called when the view stops moving due to user - interaction. If a flick was generated, this handler will - be triggered once the flick stops. If a flick was not - generated, the handler will be triggered when the - user stops dragging - i.e. a mouse or touch release. -*/ - -/*! - \qmlsignal QtQuick2::Flickable::onFlickStarted() - - This handler is called when the view is flicked. A flick - starts from the point that the mouse or touch is released, - while still in motion. -*/ - -/*! - \qmlsignal QtQuick2::Flickable::onFlickEnded() - - This handler is called when the view stops moving due to a flick. -*/ - -/*! - \qmlproperty real QtQuick2::Flickable::visibleArea.xPosition - \qmlproperty real QtQuick2::Flickable::visibleArea.widthRatio - \qmlproperty real QtQuick2::Flickable::visibleArea.yPosition - \qmlproperty real QtQuick2::Flickable::visibleArea.heightRatio - - These properties describe the position and size of the currently viewed area. - The size is defined as the percentage of the full view currently visible, - scaled to 0.0 - 1.0. The page position is usually in the range 0.0 (beginning) to - 1.0 minus size ratio (end), i.e. \c yPosition is in the range 0.0 to 1.0-\c heightRatio. - However, it is possible for the contents to be dragged outside of the normal - range, resulting in the page positions also being outside the normal range. - - These properties are typically used to draw a scrollbar. For example: - - \snippet doc/src/snippets/declarative/flickableScrollbar.qml 0 - \dots 8 - \snippet doc/src/snippets/declarative/flickableScrollbar.qml 1 - - \sa {declarative/ui-components/scrollbar}{scrollbar example} -*/ -QQuickFlickable::QQuickFlickable(QQuickItem *parent) - : QQuickItem(*(new QQuickFlickablePrivate), parent) -{ - Q_D(QQuickFlickable); - d->init(); -} - -QQuickFlickable::QQuickFlickable(QQuickFlickablePrivate &dd, QQuickItem *parent) - : QQuickItem(dd, parent) -{ - Q_D(QQuickFlickable); - d->init(); -} - -QQuickFlickable::~QQuickFlickable() -{ -} - -/*! - \qmlproperty real QtQuick2::Flickable::contentX - \qmlproperty real QtQuick2::Flickable::contentY - - These properties hold the surface coordinate currently at the top-left - corner of the Flickable. For example, if you flick an image up 100 pixels, - \c contentY will be 100. -*/ -qreal QQuickFlickable::contentX() const -{ - Q_D(const QQuickFlickable); - return -d->contentItem->x(); -} - -void QQuickFlickable::setContentX(qreal pos) -{ - Q_D(QQuickFlickable); - d->hData.explicitValue = true; - d->timeline.reset(d->hData.move); - d->vTime = d->timeline.time(); - movementXEnding(); - if (-pos != d->hData.move.value()) { - d->hData.move.setValue(-pos); - viewportMoved(); - } -} - -qreal QQuickFlickable::contentY() const -{ - Q_D(const QQuickFlickable); - return -d->contentItem->y(); -} - -void QQuickFlickable::setContentY(qreal pos) -{ - Q_D(QQuickFlickable); - d->vData.explicitValue = true; - d->timeline.reset(d->vData.move); - d->vTime = d->timeline.time(); - movementYEnding(); - if (-pos != d->vData.move.value()) { - d->vData.move.setValue(-pos); - viewportMoved(); - } -} - -/*! - \qmlproperty bool QtQuick2::Flickable::interactive - - This property describes whether the user can interact with the Flickable. - A user cannot drag or flick a Flickable that is not interactive. - - By default, this property is true. - - This property is useful for temporarily disabling flicking. This allows - special interaction with Flickable's children; for example, you might want - to freeze a flickable map while scrolling through a pop-up dialog that - is a child of the Flickable. -*/ -bool QQuickFlickable::isInteractive() const -{ - Q_D(const QQuickFlickable); - return d->interactive; -} - -void QQuickFlickable::setInteractive(bool interactive) -{ - Q_D(QQuickFlickable); - if (interactive != d->interactive) { - d->interactive = interactive; - if (!interactive && (d->hData.flicking || d->vData.flicking)) { - d->timeline.clear(); - d->vTime = d->timeline.time(); - d->hData.flicking = false; - d->vData.flicking = false; - emit flickingChanged(); - emit flickingHorizontallyChanged(); - emit flickingVerticallyChanged(); - emit flickEnded(); - } - emit interactiveChanged(); - } -} - -/*! - \qmlproperty real QtQuick2::Flickable::horizontalVelocity - \qmlproperty real QtQuick2::Flickable::verticalVelocity - - The instantaneous velocity of movement along the x and y axes, in pixels/sec. - - The reported velocity is smoothed to avoid erratic output. -*/ -qreal QQuickFlickable::horizontalVelocity() const -{ - Q_D(const QQuickFlickable); - return d->hData.smoothVelocity.value(); -} - -qreal QQuickFlickable::verticalVelocity() const -{ - Q_D(const QQuickFlickable); - return d->vData.smoothVelocity.value(); -} - -/*! - \qmlproperty bool QtQuick2::Flickable::atXBeginning - \qmlproperty bool QtQuick2::Flickable::atXEnd - \qmlproperty bool QtQuick2::Flickable::atYBeginning - \qmlproperty bool QtQuick2::Flickable::atYEnd - - These properties are true if the flickable view is positioned at the beginning, - or end respectively. -*/ -bool QQuickFlickable::isAtXEnd() const -{ - Q_D(const QQuickFlickable); - return d->hData.atEnd; -} - -bool QQuickFlickable::isAtXBeginning() const -{ - Q_D(const QQuickFlickable); - return d->hData.atBeginning; -} - -bool QQuickFlickable::isAtYEnd() const -{ - Q_D(const QQuickFlickable); - return d->vData.atEnd; -} - -bool QQuickFlickable::isAtYBeginning() const -{ - Q_D(const QQuickFlickable); - return d->vData.atBeginning; -} - -void QQuickFlickable::ticked() -{ - viewportMoved(); -} - -/*! - \qmlproperty Item QtQuick2::Flickable::contentItem - - The internal item that contains the Items to be moved in the Flickable. - - Items declared as children of a Flickable are automatically parented to the Flickable's contentItem. - - Items created dynamically need to be explicitly parented to the \e contentItem: - \code - Flickable { - id: myFlickable - function addItem(file) { - var component = Qt.createComponent(file) - component.createObject(myFlickable.contentItem); - } - } - \endcode -*/ -QQuickItem *QQuickFlickable::contentItem() -{ - Q_D(QQuickFlickable); - return d->contentItem; -} - -QQuickFlickableVisibleArea *QQuickFlickable::visibleArea() -{ - Q_D(QQuickFlickable); - if (!d->visibleArea) - d->visibleArea = new QQuickFlickableVisibleArea(this); - return d->visibleArea; -} - -/*! - \qmlproperty enumeration QtQuick2::Flickable::flickableDirection - - This property determines which directions the view can be flicked. - - \list - \o Flickable.AutoFlickDirection (default) - allows flicking vertically if the - \e contentHeight is not equal to the \e height of the Flickable. - Allows flicking horizontally if the \e contentWidth is not equal - to the \e width of the Flickable. - \o Flickable.HorizontalFlick - allows flicking horizontally. - \o Flickable.VerticalFlick - allows flicking vertically. - \o Flickable.HorizontalAndVerticalFlick - allows flicking in both directions. - \endlist -*/ -QQuickFlickable::FlickableDirection QQuickFlickable::flickableDirection() const -{ - Q_D(const QQuickFlickable); - return d->flickableDirection; -} - -void QQuickFlickable::setFlickableDirection(FlickableDirection direction) -{ - Q_D(QQuickFlickable); - if (direction != d->flickableDirection) { - d->flickableDirection = direction; - emit flickableDirectionChanged(); - } -} - -bool QQuickFlickable::pixelAligned() const -{ - Q_D(const QQuickFlickable); - return d->pixelAligned; -} - -void QQuickFlickable::setPixelAligned(bool align) -{ - Q_D(QQuickFlickable); - if (align != d->pixelAligned) { - d->pixelAligned = align; - emit pixelAlignedChanged(); - } -} - -void QQuickFlickablePrivate::handleMousePressEvent(QMouseEvent *event) -{ - Q_Q(QQuickFlickable); - if (interactive && timeline.isActive() - && (qAbs(hData.smoothVelocity.value()) > RetainGrabVelocity - || qAbs(vData.smoothVelocity.value()) > RetainGrabVelocity)) { - stealMouse = true; // If we've been flicked then steal the click. - } else { - stealMouse = false; - } - q->setKeepMouseGrab(stealMouse); - pressed = true; - timeline.clear(); - hData.reset(); - vData.reset(); - hData.dragMinBound = q->minXExtent(); - vData.dragMinBound = q->minYExtent(); - hData.dragMaxBound = q->maxXExtent(); - vData.dragMaxBound = q->maxYExtent(); - fixupMode = Normal; - lastPos = QPointF(); - QQuickItemPrivate::start(lastPosTime); - pressPos = event->localPos(); - hData.pressPos = hData.move.value(); - vData.pressPos = vData.move.value(); - hData.flicking = false; - vData.flicking = false; - QQuickItemPrivate::start(pressTime); - QQuickItemPrivate::start(velocityTime); -} - -void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event) -{ - Q_Q(QQuickFlickable); - if (!interactive || !lastPosTime.isValid()) - return; - bool rejectY = false; - bool rejectX = false; - - bool stealY = stealMouse; - bool stealX = stealMouse; - - if (q->yflick()) { - qreal dy = event->localPos().y() - pressPos.y(); - if (qAbs(dy) > qApp->styleHints()->startDragDistance() || QQuickItemPrivate::elapsed(pressTime) > 200) { - if (!vMoved) - vData.dragStartOffset = dy; - qreal newY = dy + vData.pressPos - vData.dragStartOffset; - const qreal minY = vData.dragMinBound; - const qreal maxY = vData.dragMaxBound; - if (newY > minY) - newY = minY + (newY - minY) / 2; - if (newY < maxY && maxY - minY <= 0) - newY = maxY + (newY - maxY) / 2; - if (boundsBehavior == QQuickFlickable::StopAtBounds && (newY > minY || newY < maxY)) { - rejectY = true; - if (newY < maxY) { - newY = maxY; - rejectY = false; - } - if (newY > minY) { - newY = minY; - rejectY = false; - } - } - if (!rejectY && stealMouse) { - vData.move.setValue(qRound(newY)); - vMoved = true; - } - if (qAbs(dy) > qApp->styleHints()->startDragDistance()) - stealY = true; - } - } - - if (q->xflick()) { - qreal dx = event->localPos().x() - pressPos.x(); - if (qAbs(dx) > qApp->styleHints()->startDragDistance() || QQuickItemPrivate::elapsed(pressTime) > 200) { - if (!hMoved) - hData.dragStartOffset = dx; - qreal newX = dx + hData.pressPos - hData.dragStartOffset; - const qreal minX = hData.dragMinBound; - const qreal maxX = hData.dragMaxBound; - if (newX > minX) - newX = minX + (newX - minX) / 2; - if (newX < maxX && maxX - minX <= 0) - newX = maxX + (newX - maxX) / 2; - if (boundsBehavior == QQuickFlickable::StopAtBounds && (newX > minX || newX < maxX)) { - rejectX = true; - if (newX < maxX) { - newX = maxX; - rejectX = false; - } - if (newX > minX) { - newX = minX; - rejectX = false; - } - } - if (!rejectX && stealMouse) { - hData.move.setValue(qRound(newX)); - hMoved = true; - } - - if (qAbs(dx) > qApp->styleHints()->startDragDistance()) - stealX = true; - } - } - - stealMouse = stealX || stealY; - if (stealMouse) - q->setKeepMouseGrab(true); - - if (rejectY) { - vData.velocityBuffer.clear(); - vData.velocity = 0; - } - if (rejectX) { - hData.velocityBuffer.clear(); - hData.velocity = 0; - } - - if (hMoved || vMoved) { - draggingStarting(); - q->movementStarting(); - q->viewportMoved(); - } - - if (!lastPos.isNull()) { - qreal elapsed = qreal(QQuickItemPrivate::elapsed(lastPosTime)) / 1000.; - if (elapsed <= 0) - return; - QQuickItemPrivate::restart(lastPosTime); - qreal dy = event->localPos().y()-lastPos.y(); - if (q->yflick() && !rejectY) - vData.addVelocitySample(dy/elapsed, maxVelocity); - qreal dx = event->localPos().x()-lastPos.x(); - if (q->xflick() && !rejectX) - hData.addVelocitySample(dx/elapsed, maxVelocity); - } - - lastPos = event->localPos(); -} - -void QQuickFlickablePrivate::handleMouseReleaseEvent(QMouseEvent *event) -{ - Q_Q(QQuickFlickable); - stealMouse = false; - q->setKeepMouseGrab(false); - pressed = false; - - // if we drag then pause before release we should not cause a flick. - qint64 elapsed = QQuickItemPrivate::elapsed(lastPosTime); - - vData.updateVelocity(); - hData.updateVelocity(); - - draggingEnding(); - - if (!lastPosTime.isValid()) - return; - - vTime = timeline.time(); - - qreal velocity = elapsed < 100 ? vData.velocity : 0; - if (vData.atBeginning || vData.atEnd) - velocity /= 2; - if (q->yflick() && qAbs(velocity) > MinimumFlickVelocity && qAbs(event->localPos().y() - pressPos.y()) > FlickThreshold) { - velocityTimeline.reset(vData.smoothVelocity); - vData.smoothVelocity.setValue(-velocity); - flickY(velocity); - } else { - fixupY(); - } - - velocity = elapsed < 100 ? hData.velocity : 0; - if (hData.atBeginning || hData.atEnd) - velocity /= 2; - if (q->xflick() && qAbs(velocity) > MinimumFlickVelocity && qAbs(event->localPos().x() - pressPos.x()) > FlickThreshold) { - velocityTimeline.reset(hData.smoothVelocity); - hData.smoothVelocity.setValue(-velocity); - flickX(velocity); - } else { - fixupX(); - } - - if (!timeline.isActive()) - q->movementEnding(); -} - -void QQuickFlickable::mousePressEvent(QMouseEvent *event) -{ - Q_D(QQuickFlickable); - if (d->interactive) { - if (!d->pressed) - d->handleMousePressEvent(event); - event->accept(); - } else { - QQuickItem::mousePressEvent(event); - } -} - -void QQuickFlickable::mouseMoveEvent(QMouseEvent *event) -{ - Q_D(QQuickFlickable); - if (d->interactive) { - d->handleMouseMoveEvent(event); - event->accept(); - } else { - QQuickItem::mouseMoveEvent(event); - } -} - -void QQuickFlickable::mouseReleaseEvent(QMouseEvent *event) -{ - Q_D(QQuickFlickable); - if (d->interactive) { - d->clearDelayedPress(); - d->handleMouseReleaseEvent(event); - event->accept(); - ungrabMouse(); - } else { - QQuickItem::mouseReleaseEvent(event); - } -} - -void QQuickFlickable::wheelEvent(QWheelEvent *event) -{ - Q_D(QQuickFlickable); - if (!d->interactive) { - QQuickItem::wheelEvent(event); - } else if (yflick() && event->orientation() == Qt::Vertical) { - bool valid = false; - if (event->delta() > 0 && contentY() > -minYExtent()) { - d->vData.velocity = qMax(event->delta()*2 - d->vData.smoothVelocity.value(), qreal(d->maxVelocity/4)); - valid = true; - } else if (event->delta() < 0 && contentY() < -maxYExtent()) { - d->vData.velocity = qMin(event->delta()*2 - d->vData.smoothVelocity.value(), qreal(-d->maxVelocity/4)); - valid = true; - } - if (valid) { - d->vData.flicking = false; - d->flickY(d->vData.velocity); - if (d->vData.flicking) { - d->vMoved = true; - movementStarting(); - } - event->accept(); - } - } else if (xflick() && event->orientation() == Qt::Horizontal) { - bool valid = false; - if (event->delta() > 0 && contentX() > -minXExtent()) { - d->hData.velocity = qMax(event->delta()*2 - d->hData.smoothVelocity.value(), qreal(d->maxVelocity/4)); - valid = true; - } else if (event->delta() < 0 && contentX() < -maxXExtent()) { - d->hData.velocity = qMin(event->delta()*2 - d->hData.smoothVelocity.value(), qreal(-d->maxVelocity/4)); - valid = true; - } - if (valid) { - d->hData.flicking = false; - d->flickX(d->hData.velocity); - if (d->hData.flicking) { - d->hMoved = true; - movementStarting(); - } - event->accept(); - } - } else { - QQuickItem::wheelEvent(event); - } -} - -bool QQuickFlickablePrivate::isOutermostPressDelay() const -{ - Q_Q(const QQuickFlickable); - QQuickItem *item = q->parentItem(); - while (item) { - QQuickFlickable *flick = qobject_cast(item); - if (flick && flick->pressDelay() > 0 && flick->isInteractive()) - return false; - item = item->parentItem(); - } - - return true; -} - -void QQuickFlickablePrivate::captureDelayedPress(QMouseEvent *event) -{ - Q_Q(QQuickFlickable); - if (!q->canvas() || pressDelay <= 0) - return; - if (!isOutermostPressDelay()) - return; - delayedPressTarget = q->canvas()->mouseGrabberItem(); - delayedPressEvent = new QMouseEvent(*event); - delayedPressEvent->setAccepted(false); - delayedPressTimer.start(pressDelay, q); -} - -void QQuickFlickablePrivate::clearDelayedPress() -{ - if (delayedPressEvent) { - delayedPressTimer.stop(); - delete delayedPressEvent; - delayedPressEvent = 0; - } -} - -//XXX pixelAligned ignores the global position of the Flickable, i.e. assumes Flickable itself is pixel aligned. -void QQuickFlickablePrivate::setViewportX(qreal x) -{ - contentItem->setX(pixelAligned ? qRound(x) : x); -} - -void QQuickFlickablePrivate::setViewportY(qreal y) -{ - contentItem->setY(pixelAligned ? qRound(y) : y); -} - -void QQuickFlickable::timerEvent(QTimerEvent *event) -{ - Q_D(QQuickFlickable); - if (event->timerId() == d->delayedPressTimer.timerId()) { - d->delayedPressTimer.stop(); - if (d->delayedPressEvent) { - QQuickItem *grabber = canvas() ? canvas()->mouseGrabberItem() : 0; - if (!grabber || grabber != this) { - // We replay the mouse press but the grabber we had might not be interessted by the event (e.g. overlay) - // so we reset the grabber - if (canvas()->mouseGrabberItem() == d->delayedPressTarget) - d->delayedPressTarget->ungrabMouse(); - // Use the event handler that will take care of finding the proper item to propagate the event - QQuickCanvasPrivate::get(canvas())->deliverMouseEvent(d->delayedPressEvent); - } - delete d->delayedPressEvent; - d->delayedPressEvent = 0; - } - } -} - -qreal QQuickFlickable::minYExtent() const -{ - Q_D(const QQuickFlickable); - return d->vData.startMargin; -} - -qreal QQuickFlickable::minXExtent() const -{ - Q_D(const QQuickFlickable); - return d->hData.startMargin; -} - -/* returns -ve */ -qreal QQuickFlickable::maxXExtent() const -{ - Q_D(const QQuickFlickable); - return width() - vWidth() - d->hData.endMargin; -} -/* returns -ve */ -qreal QQuickFlickable::maxYExtent() const -{ - Q_D(const QQuickFlickable); - return height() - vHeight() - d->vData.endMargin; -} - -void QQuickFlickable::componentComplete() -{ - Q_D(QQuickFlickable); - QQuickItem::componentComplete(); - if (!d->hData.explicitValue && d->hData.startMargin != 0.) - setContentX(-minXExtent()); - if (!d->vData.explicitValue && d->vData.startMargin != 0.) - setContentY(-minYExtent()); -} - -void QQuickFlickable::viewportMoved() -{ - Q_D(QQuickFlickable); - - qreal prevX = d->lastFlickablePosition.x(); - qreal prevY = d->lastFlickablePosition.y(); - if (d->pressed || d->calcVelocity) { - int elapsed = QQuickItemPrivate::restart(d->velocityTime); - if (elapsed > 0) { - qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / elapsed; - if (qAbs(horizontalVelocity) > 0) { - d->velocityTimeline.reset(d->hData.smoothVelocity); - if (d->calcVelocity) - d->velocityTimeline.set(d->hData.smoothVelocity, horizontalVelocity); - else - d->velocityTimeline.move(d->hData.smoothVelocity, horizontalVelocity, d->reportedVelocitySmoothing); - d->velocityTimeline.move(d->hData.smoothVelocity, 0, d->reportedVelocitySmoothing); - } - qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / elapsed; - if (qAbs(verticalVelocity) > 0) { - d->velocityTimeline.reset(d->vData.smoothVelocity); - if (d->calcVelocity) - d->velocityTimeline.set(d->vData.smoothVelocity, verticalVelocity); - else - d->velocityTimeline.move(d->vData.smoothVelocity, verticalVelocity, d->reportedVelocitySmoothing); - d->velocityTimeline.move(d->vData.smoothVelocity, 0, d->reportedVelocitySmoothing); - } - } - } else { - if (d->timeline.time() > d->vTime) { - d->velocityTimeline.clear(); - qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / (d->timeline.time() - d->vTime); - qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / (d->timeline.time() - d->vTime); - d->hData.smoothVelocity.setValue(horizontalVelocity); - d->vData.smoothVelocity.setValue(verticalVelocity); - } - } - - if (!d->vData.inOvershoot && !d->vData.fixingUp && d->vData.flicking - && (d->vData.move.value() > minYExtent() || d->vData.move.value() < maxYExtent()) - && qAbs(d->vData.smoothVelocity.value()) > 100) { - // Increase deceleration if we've passed a bound - d->vData.inOvershoot = true; - qreal maxDistance = d->overShootDistance(height()); - d->timeline.reset(d->vData.move); - d->timeline.accel(d->vData.move, -d->vData.smoothVelocity.value(), d->deceleration*QML_FLICK_OVERSHOOTFRICTION, maxDistance); - d->timeline.callback(QDeclarativeTimeLineCallback(&d->vData.move, d->fixupY_callback, d)); - } - if (!d->hData.inOvershoot && !d->hData.fixingUp && d->hData.flicking - && (d->hData.move.value() > minXExtent() || d->hData.move.value() < maxXExtent()) - && qAbs(d->hData.smoothVelocity.value()) > 100) { - // Increase deceleration if we've passed a bound - d->hData.inOvershoot = true; - qreal maxDistance = d->overShootDistance(width()); - d->timeline.reset(d->hData.move); - d->timeline.accel(d->hData.move, -d->hData.smoothVelocity.value(), d->deceleration*QML_FLICK_OVERSHOOTFRICTION, maxDistance); - d->timeline.callback(QDeclarativeTimeLineCallback(&d->hData.move, d->fixupX_callback, d)); - } - - d->lastFlickablePosition = QPointF(d->hData.move.value(), d->vData.move.value()); - - d->vTime = d->timeline.time(); - d->updateBeginningEnd(); -} - -void QQuickFlickable::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - Q_D(QQuickFlickable); - QQuickItem::geometryChanged(newGeometry, oldGeometry); - - bool changed = false; - if (newGeometry.width() != oldGeometry.width()) { - if (xflick()) - changed = true; - if (d->hData.viewSize < 0) { - d->contentItem->setWidth(width()); - emit contentWidthChanged(); - } - // Make sure that we're entirely in view. - if (!d->pressed && !d->hData.moving && !d->vData.moving) { - d->fixupMode = QQuickFlickablePrivate::Immediate; - d->fixupX(); - } - } - if (newGeometry.height() != oldGeometry.height()) { - if (yflick()) - changed = true; - if (d->vData.viewSize < 0) { - d->contentItem->setHeight(height()); - emit contentHeightChanged(); - } - // Make sure that we're entirely in view. - if (!d->pressed && !d->hData.moving && !d->vData.moving) { - d->fixupMode = QQuickFlickablePrivate::Immediate; - d->fixupY(); - } - } - - if (changed) - d->updateBeginningEnd(); -} - -void QQuickFlickable::cancelFlick() -{ - Q_D(QQuickFlickable); - d->timeline.reset(d->hData.move); - d->timeline.reset(d->vData.move); - movementEnding(); -} - -void QQuickFlickablePrivate::data_append(QDeclarativeListProperty *prop, QObject *o) -{ - QQuickItem *i = qobject_cast(o); - if (i) { - i->setParentItem(static_cast(prop->data)->contentItem); - } else { - o->setParent(prop->object); // XXX todo - do we want this? - } -} - -int QQuickFlickablePrivate::data_count(QDeclarativeListProperty *) -{ - // XXX todo - return 0; -} - -QObject *QQuickFlickablePrivate::data_at(QDeclarativeListProperty *, int) -{ - // XXX todo - return 0; -} - -void QQuickFlickablePrivate::data_clear(QDeclarativeListProperty *) -{ - // XXX todo -} - -QDeclarativeListProperty QQuickFlickable::flickableData() -{ - Q_D(QQuickFlickable); - return QDeclarativeListProperty(this, (void *)d, QQuickFlickablePrivate::data_append, - QQuickFlickablePrivate::data_count, - QQuickFlickablePrivate::data_at, - QQuickFlickablePrivate::data_clear); -} - -QDeclarativeListProperty QQuickFlickable::flickableChildren() -{ - Q_D(QQuickFlickable); - return QQuickItemPrivate::get(d->contentItem)->children(); -} - -/*! - \qmlproperty enumeration QtQuick2::Flickable::boundsBehavior - This property holds whether the surface may be dragged - beyond the Flickable's boundaries, or overshoot the - Flickable's boundaries when flicked. - - This enables the feeling that the edges of the view are soft, - rather than a hard physical boundary. - - The \c boundsBehavior can be one of: - - \list - \o Flickable.StopAtBounds - the contents can not be dragged beyond the boundary - of the flickable, and flicks will not overshoot. - \o Flickable.DragOverBounds - the contents can be dragged beyond the boundary - of the Flickable, but flicks will not overshoot. - \o Flickable.DragAndOvershootBounds (default) - the contents can be dragged - beyond the boundary of the Flickable, and can overshoot the - boundary when flicked. - \endlist -*/ -QQuickFlickable::BoundsBehavior QQuickFlickable::boundsBehavior() const -{ - Q_D(const QQuickFlickable); - return d->boundsBehavior; -} - -void QQuickFlickable::setBoundsBehavior(BoundsBehavior b) -{ - Q_D(QQuickFlickable); - if (b == d->boundsBehavior) - return; - d->boundsBehavior = b; - emit boundsBehaviorChanged(); -} - -/*! - \qmlproperty real QtQuick2::Flickable::contentWidth - \qmlproperty real QtQuick2::Flickable::contentHeight - - The dimensions of the content (the surface controlled by Flickable). - This should typically be set to the combined size of the items placed in the - Flickable. - - The following snippet shows how these properties are used to display - an image that is larger than the Flickable item itself: - - \snippet doc/src/snippets/declarative/flickable.qml document - - In some cases, the the content dimensions can be automatically set - using the \l {Item::childrenRect.width}{childrenRect.width} - and \l {Item::childrenRect.height}{childrenRect.height} properties. -*/ -qreal QQuickFlickable::contentWidth() const -{ - Q_D(const QQuickFlickable); - return d->hData.viewSize; -} - -void QQuickFlickable::setContentWidth(qreal w) -{ - Q_D(QQuickFlickable); - if (d->hData.viewSize == w) - return; - d->hData.viewSize = w; - if (w < 0) - d->contentItem->setWidth(width()); - else - d->contentItem->setWidth(w); - d->hData.markExtentsDirty(); - // Make sure that we're entirely in view. - if (!d->pressed && !d->hData.moving && !d->vData.moving) { - d->fixupMode = QQuickFlickablePrivate::Immediate; - d->fixupX(); - } else if (!d->pressed && d->hData.fixingUp) { - d->fixupMode = QQuickFlickablePrivate::ExtentChanged; - d->fixupX(); - } - emit contentWidthChanged(); - d->updateBeginningEnd(); -} - -qreal QQuickFlickable::contentHeight() const -{ - Q_D(const QQuickFlickable); - return d->vData.viewSize; -} - -void QQuickFlickable::setContentHeight(qreal h) -{ - Q_D(QQuickFlickable); - if (d->vData.viewSize == h) - return; - d->vData.viewSize = h; - if (h < 0) - d->contentItem->setHeight(height()); - else - d->contentItem->setHeight(h); - d->vData.markExtentsDirty(); - // Make sure that we're entirely in view. - if (!d->pressed && !d->hData.moving && !d->vData.moving) { - d->fixupMode = QQuickFlickablePrivate::Immediate; - d->fixupY(); - } else if (!d->pressed && d->vData.fixingUp) { - d->fixupMode = QQuickFlickablePrivate::ExtentChanged; - d->fixupY(); - } - emit contentHeightChanged(); - d->updateBeginningEnd(); -} - -/*! - \qmlproperty real QtQuick2::Flickable::topMargin - \qmlproperty real QtQuick2::Flickable::leftMargin - \qmlproperty real QtQuick2::Flickable::bottomMargin - \qmlproperty real QtQuick2::Flickable::rightMargin - - These properties hold the margins around the content. This space is reserved - in addition to the contentWidth and contentHeight. -*/ - - -qreal QQuickFlickable::topMargin() const -{ - Q_D(const QQuickFlickable); - return d->vData.startMargin; -} - -void QQuickFlickable::setTopMargin(qreal m) -{ - Q_D(QQuickFlickable); - if (d->vData.startMargin == m) - return; - d->vData.startMargin = m; - d->vData.markExtentsDirty(); - if (!d->pressed && !d->hData.moving && !d->vData.moving) { - d->fixupMode = QQuickFlickablePrivate::Immediate; - d->fixupY(); - } - emit topMarginChanged(); - d->updateBeginningEnd(); -} - -qreal QQuickFlickable::bottomMargin() const -{ - Q_D(const QQuickFlickable); - return d->vData.endMargin; -} - -void QQuickFlickable::setBottomMargin(qreal m) -{ - Q_D(QQuickFlickable); - if (d->vData.endMargin == m) - return; - d->vData.endMargin = m; - d->vData.markExtentsDirty(); - if (!d->pressed && !d->hData.moving && !d->vData.moving) { - d->fixupMode = QQuickFlickablePrivate::Immediate; - d->fixupY(); - } - emit bottomMarginChanged(); - d->updateBeginningEnd(); -} - -qreal QQuickFlickable::leftMargin() const -{ - Q_D(const QQuickFlickable); - return d->hData.startMargin; -} - -void QQuickFlickable::setLeftMargin(qreal m) -{ - Q_D(QQuickFlickable); - if (d->hData.startMargin == m) - return; - d->hData.startMargin = m; - d->hData.markExtentsDirty(); - if (!d->pressed && !d->hData.moving && !d->vData.moving) { - d->fixupMode = QQuickFlickablePrivate::Immediate; - d->fixupX(); - } - emit leftMarginChanged(); - d->updateBeginningEnd(); -} - -qreal QQuickFlickable::rightMargin() const -{ - Q_D(const QQuickFlickable); - return d->hData.endMargin; -} - -void QQuickFlickable::setRightMargin(qreal m) -{ - Q_D(QQuickFlickable); - if (d->hData.endMargin == m) - return; - d->hData.endMargin = m; - d->hData.markExtentsDirty(); - if (!d->pressed && !d->hData.moving && !d->vData.moving) { - d->fixupMode = QQuickFlickablePrivate::Immediate; - d->fixupX(); - } - emit rightMarginChanged(); - d->updateBeginningEnd(); -} - -/*! - \qmlproperty real QtQuick2::Flickable::xOrigin - \qmlproperty real QtQuick2::Flickable::yOrigin - - These properties hold the origin of the content. This is usually (0,0), however - ListView and GridView may have an arbitrary origin due to delegate size variation, - or item insertion/removal outside the visible region. -*/ - -qreal QQuickFlickable::yOrigin() const -{ - Q_D(const QQuickFlickable); - return -minYExtent() + d->vData.startMargin; -} - -qreal QQuickFlickable::xOrigin() const -{ - Q_D(const QQuickFlickable); - return -minXExtent() + d->hData.startMargin; -} - - -/*! - \qmlmethod QtQuick2::Flickable::resizeContent(real width, real height, QPointF center) - - Resizes the content to \a width x \a height about \a center. - - This does not scale the contents of the Flickable - it only resizes the \l contentWidth - and \l contentHeight. - - Resizing the content may result in the content being positioned outside - the bounds of the Flickable. Calling \l returnToBounds() will - move the content back within legal bounds. -*/ -void QQuickFlickable::resizeContent(qreal w, qreal h, QPointF center) -{ - Q_D(QQuickFlickable); - if (w != d->hData.viewSize) { - qreal oldSize = d->hData.viewSize; - d->hData.viewSize = w; - d->contentItem->setWidth(w); - emit contentWidthChanged(); - if (center.x() != 0) { - qreal pos = center.x() * w / oldSize; - setContentX(contentX() + pos - center.x()); - } - } - if (h != d->vData.viewSize) { - qreal oldSize = d->vData.viewSize; - d->vData.viewSize = h; - d->contentItem->setHeight(h); - emit contentHeightChanged(); - if (center.y() != 0) { - qreal pos = center.y() * h / oldSize; - setContentY(contentY() + pos - center.y()); - } - } - d->updateBeginningEnd(); -} - -/*! - \qmlmethod QtQuick2::Flickable::returnToBounds() - - Ensures the content is within legal bounds. - - This may be called to ensure that the content is within legal bounds - after manually positioning the content. -*/ -void QQuickFlickable::returnToBounds() -{ - Q_D(QQuickFlickable); - d->fixupX(); - d->fixupY(); -} - -qreal QQuickFlickable::vWidth() const -{ - Q_D(const QQuickFlickable); - if (d->hData.viewSize < 0) - return width(); - else - return d->hData.viewSize; -} - -qreal QQuickFlickable::vHeight() const -{ - Q_D(const QQuickFlickable); - if (d->vData.viewSize < 0) - return height(); - else - return d->vData.viewSize; -} - -bool QQuickFlickable::xflick() const -{ - Q_D(const QQuickFlickable); - if (d->flickableDirection == QQuickFlickable::AutoFlickDirection) - return vWidth() != width(); - return d->flickableDirection & QQuickFlickable::HorizontalFlick; -} - -bool QQuickFlickable::yflick() const -{ - Q_D(const QQuickFlickable); - if (d->flickableDirection == QQuickFlickable::AutoFlickDirection) - return vHeight() != height(); - return d->flickableDirection & QQuickFlickable::VerticalFlick; -} - -void QQuickFlickable::mouseUngrabEvent() -{ - Q_D(QQuickFlickable); - if (d->pressed) { - // if our mouse grab has been removed (probably by another Flickable), - // fix our state - d->pressed = false; - d->draggingEnding(); - d->stealMouse = false; - setKeepMouseGrab(false); - } -} - -bool QQuickFlickable::sendMouseEvent(QMouseEvent *event) -{ - Q_D(QQuickFlickable); - QRectF myRect = mapRectToScene(QRectF(0, 0, width(), height())); - - QQuickCanvas *c = canvas(); - QQuickItem *grabber = c ? c->mouseGrabberItem() : 0; - bool disabledItem = grabber && !grabber->isEnabled(); - bool stealThisEvent = d->stealMouse; - if ((stealThisEvent || myRect.contains(event->windowPos())) && (!grabber || !grabber->keepMouseGrab() || disabledItem)) { - QMouseEvent mouseEvent(event->type(), mapFromScene(event->windowPos()), event->windowPos(), event->screenPos(), - event->button(), event->buttons(), event->modifiers()); - - mouseEvent.setAccepted(false); - - switch (mouseEvent.type()) { - case QEvent::MouseMove: - d->handleMouseMoveEvent(&mouseEvent); - break; - case QEvent::MouseButtonPress: - if (d->pressed) // we are already pressed - this is a delayed replay - return false; - - d->handleMousePressEvent(&mouseEvent); - d->captureDelayedPress(event); - stealThisEvent = d->stealMouse; // Update stealThisEvent in case changed by function call above - break; - case QEvent::MouseButtonRelease: - if (d->delayedPressEvent) { - // We replay the mouse press but the grabber we had might not be interessted by the event (e.g. overlay) - // so we reset the grabber - if (c->mouseGrabberItem() == d->delayedPressTarget) - d->delayedPressTarget->ungrabMouse(); - //Use the event handler that will take care of finding the proper item to propagate the event - QQuickCanvasPrivate::get(canvas())->deliverMouseEvent(d->delayedPressEvent); - d->clearDelayedPress(); - // We send the release - canvas()->sendEvent(c->mouseGrabberItem(), event); - // And the event has been consumed - d->stealMouse = false; - d->pressed = false; - return true; - } - d->handleMouseReleaseEvent(&mouseEvent); - break; - default: - break; - } - grabber = qobject_cast(c->mouseGrabberItem()); - if ((grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) || disabledItem) { - d->clearDelayedPress(); - grabMouse(); - } - - return stealThisEvent || d->delayedPressEvent || disabledItem; - } else if (d->lastPosTime.isValid()) { - d->lastPosTime.invalidate(); - returnToBounds(); - } - if (event->type() == QEvent::MouseButtonRelease) { - d->lastPosTime.invalidate(); - d->clearDelayedPress(); - d->stealMouse = false; - d->pressed = false; - } - return false; -} - - -bool QQuickFlickable::childMouseEventFilter(QQuickItem *i, QEvent *e) -{ - Q_D(QQuickFlickable); - if (!isVisible() || !d->interactive || !isEnabled()) - return QQuickItem::childMouseEventFilter(i, e); - switch (e->type()) { - case QEvent::MouseButtonPress: - case QEvent::MouseMove: - case QEvent::MouseButtonRelease: - return sendMouseEvent(static_cast(e)); - default: - break; - } - - return QQuickItem::childMouseEventFilter(i, e); -} - -/*! - \qmlproperty real QtQuick2::Flickable::maximumFlickVelocity - This property holds the maximum velocity that the user can flick the view in pixels/second. - - The default value is platform dependent. -*/ -qreal QQuickFlickable::maximumFlickVelocity() const -{ - Q_D(const QQuickFlickable); - return d->maxVelocity; -} - -void QQuickFlickable::setMaximumFlickVelocity(qreal v) -{ - Q_D(QQuickFlickable); - if (v == d->maxVelocity) - return; - d->maxVelocity = v; - emit maximumFlickVelocityChanged(); -} - -/*! - \qmlproperty real QtQuick2::Flickable::flickDeceleration - This property holds the rate at which a flick will decelerate. - - The default value is platform dependent. -*/ -qreal QQuickFlickable::flickDeceleration() const -{ - Q_D(const QQuickFlickable); - return d->deceleration; -} - -void QQuickFlickable::setFlickDeceleration(qreal deceleration) -{ - Q_D(QQuickFlickable); - if (deceleration == d->deceleration) - return; - d->deceleration = deceleration; - emit flickDecelerationChanged(); -} - -bool QQuickFlickable::isFlicking() const -{ - Q_D(const QQuickFlickable); - return d->hData.flicking || d->vData.flicking; -} - -/*! - \qmlproperty bool QtQuick2::Flickable::flicking - \qmlproperty bool QtQuick2::Flickable::flickingHorizontally - \qmlproperty bool QtQuick2::Flickable::flickingVertically - - These properties describe whether the view is currently moving horizontally, - vertically or in either direction, due to the user flicking the view. -*/ -bool QQuickFlickable::isFlickingHorizontally() const -{ - Q_D(const QQuickFlickable); - return d->hData.flicking; -} - -bool QQuickFlickable::isFlickingVertically() const -{ - Q_D(const QQuickFlickable); - return d->vData.flicking; -} - -/*! - \qmlproperty bool QtQuick2::Flickable::dragging - \qmlproperty bool QtQuick2::Flickable::draggingHorizontally - \qmlproperty bool QtQuick2::Flickable::draggingVertically - - These properties describe whether the view is currently moving horizontally, - vertically or in either direction, due to the user dragging the view. -*/ -bool QQuickFlickable::isDragging() const -{ - Q_D(const QQuickFlickable); - return d->hData.dragging || d->vData.dragging; -} - -bool QQuickFlickable::isDraggingHorizontally() const -{ - Q_D(const QQuickFlickable); - return d->hData.dragging; -} - -bool QQuickFlickable::isDraggingVertically() const -{ - Q_D(const QQuickFlickable); - return d->vData.dragging; -} - -void QQuickFlickablePrivate::draggingStarting() -{ - Q_Q(QQuickFlickable); - bool wasDragging = hData.dragging || vData.dragging; - if (hMoved && !hData.dragging) { - hData.dragging = true; - emit q->draggingHorizontallyChanged(); - } - if (vMoved && !vData.dragging) { - vData.dragging = true; - emit q->draggingVerticallyChanged(); - } - if (!wasDragging && (hData.dragging || vData.dragging)) { - emit q->draggingChanged(); - emit q->dragStarted(); - } -} - -void QQuickFlickablePrivate::draggingEnding() -{ - Q_Q(QQuickFlickable); - bool wasDragging = hData.dragging || vData.dragging; - if (hData.dragging) { - hData.dragging = false; - emit q->draggingHorizontallyChanged(); - } - if (vData.dragging) { - vData.dragging = false; - emit q->draggingVerticallyChanged(); - } - if (wasDragging && !hData.dragging && !vData.dragging) { - emit q->draggingChanged(); - emit q->dragEnded(); - } -} - -/*! - \qmlproperty int QtQuick2::Flickable::pressDelay - - This property holds the time to delay (ms) delivering a press to - children of the Flickable. This can be useful where reacting - to a press before a flicking action has undesirable effects. - - If the flickable is dragged/flicked before the delay times out - the press event will not be delivered. If the button is released - within the timeout, both the press and release will be delivered. - - Note that for nested Flickables with pressDelay set, the pressDelay of - inner Flickables is overridden by the outermost Flickable. -*/ -int QQuickFlickable::pressDelay() const -{ - Q_D(const QQuickFlickable); - return d->pressDelay; -} - -void QQuickFlickable::setPressDelay(int delay) -{ - Q_D(QQuickFlickable); - if (d->pressDelay == delay) - return; - d->pressDelay = delay; - emit pressDelayChanged(); -} - -/*! - \qmlproperty bool QtQuick2::Flickable::moving - \qmlproperty bool QtQuick2::Flickable::movingHorizontally - \qmlproperty bool QtQuick2::Flickable::movingVertically - - These properties describe whether the view is currently moving horizontally, - vertically or in either direction, due to the user either dragging or - flicking the view. -*/ - -bool QQuickFlickable::isMoving() const -{ - Q_D(const QQuickFlickable); - return d->hData.moving || d->vData.moving; -} - -bool QQuickFlickable::isMovingHorizontally() const -{ - Q_D(const QQuickFlickable); - return d->hData.moving; -} - -bool QQuickFlickable::isMovingVertically() const -{ - Q_D(const QQuickFlickable); - return d->vData.moving; -} - -void QQuickFlickable::movementStarting() -{ - Q_D(QQuickFlickable); - if (d->hMoved && !d->hData.moving) { - d->hData.moving = true; - emit movingChanged(); - emit movingHorizontallyChanged(); - if (!d->vData.moving) - emit movementStarted(); - } - else if (d->vMoved && !d->vData.moving) { - d->vData.moving = true; - emit movingChanged(); - emit movingVerticallyChanged(); - if (!d->hData.moving) - emit movementStarted(); - } -} - -void QQuickFlickable::movementEnding() -{ - Q_D(QQuickFlickable); - movementXEnding(); - movementYEnding(); - d->hData.smoothVelocity.setValue(0); - d->vData.smoothVelocity.setValue(0); -} - -void QQuickFlickable::movementXEnding() -{ - Q_D(QQuickFlickable); - if (d->hData.flicking) { - d->hData.flicking = false; - emit flickingChanged(); - emit flickingHorizontallyChanged(); - if (!d->vData.flicking) - emit flickEnded(); - } - if (!d->pressed && !d->stealMouse) { - if (d->hData.moving) { - d->hData.moving = false; - d->hMoved = false; - emit movingChanged(); - emit movingHorizontallyChanged(); - if (!d->vData.moving) - emit movementEnded(); - } - } - d->hData.fixingUp = false; -} - -void QQuickFlickable::movementYEnding() -{ - Q_D(QQuickFlickable); - if (d->vData.flicking) { - d->vData.flicking = false; - emit flickingChanged(); - emit flickingVerticallyChanged(); - if (!d->hData.flicking) - emit flickEnded(); - } - if (!d->pressed && !d->stealMouse) { - if (d->vData.moving) { - d->vData.moving = false; - d->vMoved = false; - emit movingChanged(); - emit movingVerticallyChanged(); - if (!d->hData.moving) - emit movementEnded(); - } - } - d->vData.fixingUp = false; -} - -void QQuickFlickablePrivate::updateVelocity() -{ - Q_Q(QQuickFlickable); - emit q->horizontalVelocityChanged(); - emit q->verticalVelocityChanged(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickflickable_p.h b/src/declarative/items/qquickflickable_p.h deleted file mode 100644 index 658db94846..0000000000 --- a/src/declarative/items/qquickflickable_p.h +++ /dev/null @@ -1,277 +0,0 @@ -// Commit: 1bcddaaf318fc37c71c5191913f3487c49444ec6 -/**************************************************************************** -** -** 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$ -** 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 QQUICKFLICKABLE_P_H -#define QQUICKFLICKABLE_P_H - -#include "qquickitem.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickFlickablePrivate; -class QQuickFlickableVisibleArea; -class Q_DECLARATIVE_EXPORT QQuickFlickable : public QQuickItem -{ - Q_OBJECT - - Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged) - Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged) - Q_PROPERTY(qreal contentX READ contentX WRITE setContentX NOTIFY contentXChanged) - Q_PROPERTY(qreal contentY READ contentY WRITE setContentY NOTIFY contentYChanged) - Q_PROPERTY(QQuickItem *contentItem READ contentItem CONSTANT) - - Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) - Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) - Q_PROPERTY(qreal yOrigin READ yOrigin NOTIFY yOriginChanged) - - Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) - Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) - Q_PROPERTY(qreal xOrigin READ xOrigin NOTIFY xOriginChanged) - - Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged) - Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged) - - Q_PROPERTY(BoundsBehavior boundsBehavior READ boundsBehavior WRITE setBoundsBehavior NOTIFY boundsBehaviorChanged) - Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity NOTIFY maximumFlickVelocityChanged) - Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged) - Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) - Q_PROPERTY(bool movingHorizontally READ isMovingHorizontally NOTIFY movingHorizontallyChanged) - Q_PROPERTY(bool movingVertically READ isMovingVertically NOTIFY movingVerticallyChanged) - Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) - Q_PROPERTY(bool flickingHorizontally READ isFlickingHorizontally NOTIFY flickingHorizontallyChanged) - Q_PROPERTY(bool flickingVertically READ isFlickingVertically NOTIFY flickingVerticallyChanged) - Q_PROPERTY(bool dragging READ isDragging NOTIFY draggingChanged) - Q_PROPERTY(bool draggingHorizontally READ isDraggingHorizontally NOTIFY draggingHorizontallyChanged) - Q_PROPERTY(bool draggingVertically READ isDraggingVertically NOTIFY draggingVerticallyChanged) - Q_PROPERTY(FlickableDirection flickableDirection READ flickableDirection WRITE setFlickableDirection NOTIFY flickableDirectionChanged) - - Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged) - Q_PROPERTY(int pressDelay READ pressDelay WRITE setPressDelay NOTIFY pressDelayChanged) - - Q_PROPERTY(bool atXEnd READ isAtXEnd NOTIFY isAtBoundaryChanged) - Q_PROPERTY(bool atYEnd READ isAtYEnd NOTIFY isAtBoundaryChanged) - Q_PROPERTY(bool atXBeginning READ isAtXBeginning NOTIFY isAtBoundaryChanged) - Q_PROPERTY(bool atYBeginning READ isAtYBeginning NOTIFY isAtBoundaryChanged) - - Q_PROPERTY(QQuickFlickableVisibleArea *visibleArea READ visibleArea CONSTANT) - - Q_PROPERTY(bool pixelAligned READ pixelAligned WRITE setPixelAligned NOTIFY pixelAlignedChanged) - - Q_PROPERTY(QDeclarativeListProperty flickableData READ flickableData) - Q_PROPERTY(QDeclarativeListProperty flickableChildren READ flickableChildren) - Q_CLASSINFO("DefaultProperty", "flickableData") - - Q_ENUMS(FlickableDirection) - Q_ENUMS(BoundsBehavior) - -public: - QQuickFlickable(QQuickItem *parent=0); - ~QQuickFlickable(); - - QDeclarativeListProperty flickableData(); - QDeclarativeListProperty flickableChildren(); - - enum BoundsBehavior { StopAtBounds, DragOverBounds, DragAndOvershootBounds }; - BoundsBehavior boundsBehavior() const; - void setBoundsBehavior(BoundsBehavior); - - qreal contentWidth() const; - void setContentWidth(qreal); - - qreal contentHeight() const; - void setContentHeight(qreal); - - qreal contentX() const; - virtual void setContentX(qreal pos); - - qreal contentY() const; - virtual void setContentY(qreal pos); - - qreal topMargin() const; - void setTopMargin(qreal m); - - qreal bottomMargin() const; - void setBottomMargin(qreal m); - - qreal leftMargin() const; - void setLeftMargin(qreal m); - - qreal rightMargin() const; - void setRightMargin(qreal m); - - virtual qreal yOrigin() const; - virtual qreal xOrigin() const; - - bool isMoving() const; - bool isMovingHorizontally() const; - bool isMovingVertically() const; - bool isFlicking() const; - bool isFlickingHorizontally() const; - bool isFlickingVertically() const; - bool isDragging() const; - bool isDraggingHorizontally() const; - bool isDraggingVertically() const; - - int pressDelay() const; - void setPressDelay(int delay); - - qreal maximumFlickVelocity() const; - void setMaximumFlickVelocity(qreal); - - qreal flickDeceleration() const; - void setFlickDeceleration(qreal); - - bool isInteractive() const; - void setInteractive(bool); - - qreal horizontalVelocity() const; - qreal verticalVelocity() const; - - bool isAtXEnd() const; - bool isAtXBeginning() const; - bool isAtYEnd() const; - bool isAtYBeginning() const; - - QQuickItem *contentItem(); - - enum FlickableDirection { AutoFlickDirection=0x00, HorizontalFlick=0x01, VerticalFlick=0x02, HorizontalAndVerticalFlick=0x03 }; - FlickableDirection flickableDirection() const; - void setFlickableDirection(FlickableDirection); - - bool pixelAligned() const; - void setPixelAligned(bool align); - - Q_INVOKABLE void resizeContent(qreal w, qreal h, QPointF center); - Q_INVOKABLE void returnToBounds(); - -Q_SIGNALS: - void contentWidthChanged(); - void contentHeightChanged(); - void contentXChanged(); - void contentYChanged(); - void topMarginChanged(); - void bottomMarginChanged(); - void leftMarginChanged(); - void rightMarginChanged(); - void yOriginChanged(); - void xOriginChanged(); - void movingChanged(); - void movingHorizontallyChanged(); - void movingVerticallyChanged(); - void flickingChanged(); - void flickingHorizontallyChanged(); - void flickingVerticallyChanged(); - void draggingChanged(); - void draggingHorizontallyChanged(); - void draggingVerticallyChanged(); - void horizontalVelocityChanged(); - void verticalVelocityChanged(); - void isAtBoundaryChanged(); - void flickableDirectionChanged(); - void interactiveChanged(); - void boundsBehaviorChanged(); - void maximumFlickVelocityChanged(); - void flickDecelerationChanged(); - void pressDelayChanged(); - void movementStarted(); - void movementEnded(); - void flickStarted(); - void flickEnded(); - void dragStarted(); - void dragEnded(); - void pixelAlignedChanged(); - -protected: - virtual bool childMouseEventFilter(QQuickItem *, QEvent *); - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - virtual void wheelEvent(QWheelEvent *event); - virtual void timerEvent(QTimerEvent *event); - - QQuickFlickableVisibleArea *visibleArea(); - -protected Q_SLOTS: - virtual void ticked(); - void movementStarting(); - void movementEnding(); - -protected: - void movementXEnding(); - void movementYEnding(); - virtual qreal minXExtent() const; - virtual qreal minYExtent() const; - virtual qreal maxXExtent() const; - virtual qreal maxYExtent() const; - qreal vWidth() const; - qreal vHeight() const; - virtual void componentComplete(); - virtual void viewportMoved(); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - void mouseUngrabEvent(); - bool sendMouseEvent(QMouseEvent *event); - - bool xflick() const; - bool yflick() const; - void cancelFlick(); - -protected: - QQuickFlickable(QQuickFlickablePrivate &dd, QQuickItem *parent); - -private: - Q_DISABLE_COPY(QQuickFlickable) - Q_DECLARE_PRIVATE(QQuickFlickable) - friend class QQuickFlickableVisibleArea; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickFlickable) - -QT_END_HEADER - -#endif // QQUICKFLICKABLE_P_H diff --git a/src/declarative/items/qquickflickable_p_p.h b/src/declarative/items/qquickflickable_p_p.h deleted file mode 100644 index 8ceea6162f..0000000000 --- a/src/declarative/items/qquickflickable_p_p.h +++ /dev/null @@ -1,262 +0,0 @@ -// Commit: 160f1867868cdea916923652b00484ed11f90aaa -/**************************************************************************** -** -** 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$ -** 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 QQUICKFLICKABLE_P_P_H -#define QQUICKFLICKABLE_P_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 "qquickflickable_p.h" -#include "qquickitem_p.h" -#include "qquickitemchangelistener_p.h" - -#include -#include -#include "qplatformdefs.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -// Really slow flicks can be annoying. -const qreal MinimumFlickVelocity = 75.0; - -class QQuickFlickableVisibleArea; -class QQuickFlickablePrivate : public QQuickItemPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickFlickable) - -public: - static inline QQuickFlickablePrivate *get(QQuickFlickable *o) { return o->d_func(); } - - QQuickFlickablePrivate(); - void init(); - - struct Velocity : public QDeclarativeTimeLineValue - { - Velocity(QQuickFlickablePrivate *p) - : parent(p) {} - virtual void setValue(qreal v) { - if (v != value()) { - QDeclarativeTimeLineValue::setValue(v); - parent->updateVelocity(); - } - } - QQuickFlickablePrivate *parent; - }; - - struct AxisData { - AxisData(QQuickFlickablePrivate *fp, void (QQuickFlickablePrivate::*func)(qreal)) - : move(fp, func), viewSize(-1), startMargin(0), endMargin(0) - , smoothVelocity(fp), atEnd(false), atBeginning(true) - , fixingUp(false), inOvershoot(false), moving(false), flicking(false) - , dragging(false), extentsChanged(false) - , explicitValue(false), minExtentDirty(true), maxExtentDirty(true) - {} - - void reset() { - velocityBuffer.clear(); - dragStartOffset = 0; - fixingUp = false; - inOvershoot = false; - } - - void markExtentsDirty() { - minExtentDirty = true; - maxExtentDirty = true; - extentsChanged = true; - } - - void addVelocitySample(qreal v, qreal maxVelocity); - void updateVelocity(); - - QDeclarativeTimeLineValueProxy move; - qreal viewSize; - qreal pressPos; - qreal dragStartOffset; - qreal dragMinBound; - qreal dragMaxBound; - qreal velocity; - qreal flickTarget; - qreal startMargin; - qreal endMargin; - QQuickFlickablePrivate::Velocity smoothVelocity; - QPODVector velocityBuffer; - bool atEnd : 1; - bool atBeginning : 1; - bool fixingUp : 1; - bool inOvershoot : 1; - bool moving : 1; - bool flicking : 1; - bool dragging : 1; - bool extentsChanged : 1; - bool explicitValue : 1; - mutable bool minExtentDirty : 1; - mutable bool maxExtentDirty : 1; - }; - - void flickX(qreal velocity); - void flickY(qreal velocity); - virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, - QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity); - - void fixupX(); - void fixupY(); - virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent); - - void updateBeginningEnd(); - - bool isOutermostPressDelay() const; - void captureDelayedPress(QMouseEvent *event); - void clearDelayedPress(); - - void setViewportX(qreal x); - void setViewportY(qreal y); - - qreal overShootDistance(qreal size); - - void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &); - - void draggingStarting(); - void draggingEnding(); - -public: - QQuickItem *contentItem; - - AxisData hData; - AxisData vData; - - QDeclarativeTimeLine timeline; - bool hMoved : 1; - bool vMoved : 1; - bool stealMouse : 1; - bool pressed : 1; - bool interactive : 1; - bool calcVelocity : 1; - bool pixelAligned : 1; - QElapsedTimer lastPosTime; - QPointF lastPos; - QPointF pressPos; - QElapsedTimer pressTime; - qreal deceleration; - qreal maxVelocity; - QElapsedTimer velocityTime; - QPointF lastFlickablePosition; - qreal reportedVelocitySmoothing; - QMouseEvent *delayedPressEvent; - QQuickItem *delayedPressTarget; - QBasicTimer delayedPressTimer; - int pressDelay; - int fixupDuration; - - enum FixupMode { Normal, Immediate, ExtentChanged }; - FixupMode fixupMode; - - static void fixupY_callback(void *); - static void fixupX_callback(void *); - - void updateVelocity(); - int vTime; - QDeclarativeTimeLine velocityTimeline; - QQuickFlickableVisibleArea *visibleArea; - QQuickFlickable::FlickableDirection flickableDirection; - QQuickFlickable::BoundsBehavior boundsBehavior; - - void handleMousePressEvent(QMouseEvent *); - void handleMouseMoveEvent(QMouseEvent *); - void handleMouseReleaseEvent(QMouseEvent *); - - // flickableData property - static void data_append(QDeclarativeListProperty *, QObject *); - static int data_count(QDeclarativeListProperty *); - static QObject *data_at(QDeclarativeListProperty *, int); - static void data_clear(QDeclarativeListProperty *); -}; - -class QQuickFlickableVisibleArea : public QObject -{ - Q_OBJECT - - Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged) - Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged) - Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged) - Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged) - -public: - QQuickFlickableVisibleArea(QQuickFlickable *parent=0); - - qreal xPosition() const; - qreal widthRatio() const; - qreal yPosition() const; - qreal heightRatio() const; - - void updateVisible(); - -signals: - void xPositionChanged(qreal xPosition); - void yPositionChanged(qreal yPosition); - void widthRatioChanged(qreal widthRatio); - void heightRatioChanged(qreal heightRatio); - -private: - QQuickFlickable *flickable; - qreal m_xPosition; - qreal m_widthRatio; - qreal m_yPosition; - qreal m_heightRatio; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickFlickableVisibleArea) - -#endif // QQUICKFLICKABLE_P_P_H diff --git a/src/declarative/items/qquickflipable.cpp b/src/declarative/items/qquickflipable.cpp deleted file mode 100644 index ed89f2aaf5..0000000000 --- a/src/declarative/items/qquickflipable.cpp +++ /dev/null @@ -1,308 +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 QtDeclarative module 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 "qquickflipable_p.h" -#include "qquickitem_p.h" - -#include - -#include - -QT_BEGIN_NAMESPACE - -// XXX todo - i think this needs work and a bit of a re-think - -class QQuickLocalTransform : public QQuickTransform -{ - Q_OBJECT -public: - QQuickLocalTransform(QObject *parent) : QQuickTransform(parent) {} - - void setTransform(const QTransform &t) { - transform = t; - update(); - } - virtual void applyTo(QMatrix4x4 *matrix) const { - *matrix *= transform; - } -private: - QTransform transform; -}; - -class QQuickFlipablePrivate : public QQuickItemPrivate -{ - Q_DECLARE_PUBLIC(QQuickFlipable) -public: - QQuickFlipablePrivate() : current(QQuickFlipable::Front), front(0), back(0), sideDirty(false) {} - - virtual void transformChanged(); - void updateSide(); - void setBackTransform(); - - QQuickFlipable::Side current; - QDeclarativeGuard backTransform; - QDeclarativeGuard front; - QDeclarativeGuard back; - - bool sideDirty; - bool wantBackXFlipped; - bool wantBackYFlipped; -}; - -/*! - \qmlclass Flipable QQuickFlipable - \inqmlmodule QtQuick 2 - \ingroup qml-basic-interaction-elements - \brief The Flipable item provides a surface that can be flipped. - \inherits Item - - Flipable is an item that can be visibly "flipped" between its front and - back sides, like a card. It is used together with \l Rotation, \l State - and \l Transition elements to produce a flipping effect. - - The \l front and \l back properties are used to hold the items that are - shown respectively on the front and back sides of the flipable item. - - \section1 Example Usage - - The following example shows a Flipable item that flips whenever it is - clicked, rotating about the y-axis. - - This flipable item has a \c flipped boolean property that is toggled - whenever the MouseArea within the flipable is clicked. When - \c flipped is true, the item changes to the "back" state; in this - state, the \c angle of the \l Rotation item is changed to 180 - degrees to produce the flipping effect. When \c flipped is false, the - item reverts to the default state, in which the \c angle value is 0. - - \snippet doc/src/snippets/declarative/flipable/flipable.qml 0 - - \image flipable.gif - - The \l Transition creates the animation that changes the angle over - four seconds. When the item changes between its "back" and - default states, the NumberAnimation animates the angle between - its old and new values. - - See \l {QML States} for details on state changes and the default - state, and \l {QML Animation and Transitions} for more information on how - animations work within transitions. - - \sa {declarative/ui-components/flipable}{Flipable example} -*/ -QQuickFlipable::QQuickFlipable(QQuickItem *parent) -: QQuickItem(*(new QQuickFlipablePrivate), parent) -{ -} - -QQuickFlipable::~QQuickFlipable() -{ -} - -/*! - \qmlproperty Item QtQuick2::Flipable::front - \qmlproperty Item QtQuick2::Flipable::back - - The front and back sides of the flipable. -*/ - -QQuickItem *QQuickFlipable::front() -{ - Q_D(const QQuickFlipable); - return d->front; -} - -void QQuickFlipable::setFront(QQuickItem *front) -{ - Q_D(QQuickFlipable); - if (d->front) { - qmlInfo(this) << tr("front is a write-once property"); - return; - } - d->front = front; - d->front->setParentItem(this); - if (Back == d->current) - d->front->setOpacity(0.); - emit frontChanged(); -} - -QQuickItem *QQuickFlipable::back() -{ - Q_D(const QQuickFlipable); - return d->back; -} - -void QQuickFlipable::setBack(QQuickItem *back) -{ - Q_D(QQuickFlipable); - if (d->back) { - qmlInfo(this) << tr("back is a write-once property"); - return; - } - if (back == 0) - return; - d->back = back; - d->back->setParentItem(this); - - d->backTransform = new QQuickLocalTransform(d->back); - d->backTransform->prependToItem(d->back); - - if (Front == d->current) - d->back->setOpacity(0.); - connect(back, SIGNAL(widthChanged()), - this, SLOT(retransformBack())); - connect(back, SIGNAL(heightChanged()), - this, SLOT(retransformBack())); - emit backChanged(); -} - -void QQuickFlipable::retransformBack() -{ - Q_D(QQuickFlipable); - if (d->current == QQuickFlipable::Back && d->back) - d->setBackTransform(); -} - -/*! - \qmlproperty enumeration QtQuick2::Flipable::side - - The side of the Flipable currently visible. Possible values are \c - Flipable.Front and \c Flipable.Back. -*/ -QQuickFlipable::Side QQuickFlipable::side() const -{ - Q_D(const QQuickFlipable); - - const_cast(d)->updateSide(); - return d->current; -} - -void QQuickFlipablePrivate::transformChanged() -{ - Q_Q(QQuickFlipable); - - if (!sideDirty) { - sideDirty = true; - q->polish(); - } - - QQuickItemPrivate::transformChanged(); -} - -void QQuickFlipable::updatePolish() -{ - Q_D(QQuickFlipable); - d->updateSide(); -} - -// determination on the currently visible side of the flipable -// has to be done on the complete scene transform to give -// correct results. -void QQuickFlipablePrivate::updateSide() -{ - Q_Q(QQuickFlipable); - - if (!sideDirty) - return; - - sideDirty = false; - - QTransform sceneTransform; - itemToParentTransform(sceneTransform); - - QPointF p1(0, 0); - QPointF p2(1, 0); - QPointF p3(1, 1); - - QPointF scenep1 = sceneTransform.map(p1); - QPointF scenep2 = sceneTransform.map(p2); - QPointF scenep3 = sceneTransform.map(p3); -#if 0 - p1 = q->mapToParent(p1); - p2 = q->mapToParent(p2); - p3 = q->mapToParent(p3); -#endif - - qreal cross = (scenep1.x() - scenep2.x()) * (scenep3.y() - scenep2.y()) - - (scenep1.y() - scenep2.y()) * (scenep3.x() - scenep2.x()); - - wantBackYFlipped = scenep1.x() >= scenep2.x(); - wantBackXFlipped = scenep2.y() >= scenep3.y(); - - QQuickFlipable::Side newSide; - if (cross > 0) { - newSide = QQuickFlipable::Back; - } else { - newSide = QQuickFlipable::Front; - } - - if (newSide != current) { - current = newSide; - if (current == QQuickFlipable::Back && back) - setBackTransform(); - if (front) - front->setOpacity((current==QQuickFlipable::Front)?1.:0.); - if (back) - back->setOpacity((current==QQuickFlipable::Back)?1.:0.); - emit q->sideChanged(); - } -} - -/* Depends on the width/height of the back item, and so needs reevaulating - if those change. -*/ -void QQuickFlipablePrivate::setBackTransform() -{ - QTransform mat; - mat.translate(back->width()/2,back->height()/2); - if (back->width() && wantBackYFlipped) - mat.rotate(180, Qt::YAxis); - if (back->height() && wantBackXFlipped) - mat.rotate(180, Qt::XAxis); - mat.translate(-back->width()/2,-back->height()/2); - - if (backTransform) - backTransform->setTransform(mat); -} - -QT_END_NAMESPACE - -#include "qquickflipable.moc" diff --git a/src/declarative/items/qquickflipable_p.h b/src/declarative/items/qquickflipable_p.h deleted file mode 100644 index 698ec0fcb2..0000000000 --- a/src/declarative/items/qquickflipable_p.h +++ /dev/null @@ -1,104 +0,0 @@ -// Commit: ebd4bc73c46c2962742a682b6a391fb68c482aec -/**************************************************************************** -** -** 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$ -** 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 QQUICKFLIPABLE_P_H -#define QQUICKFLIPABLE_P_H - -#include "qquickitem.h" - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickFlipablePrivate; -class Q_AUTOTEST_EXPORT QQuickFlipable : public QQuickItem -{ - Q_OBJECT - - Q_ENUMS(Side) - Q_PROPERTY(QQuickItem *front READ front WRITE setFront NOTIFY frontChanged) - Q_PROPERTY(QQuickItem *back READ back WRITE setBack NOTIFY backChanged) - Q_PROPERTY(Side side READ side NOTIFY sideChanged) - //### flipAxis - //### flipRotation -public: - QQuickFlipable(QQuickItem *parent=0); - ~QQuickFlipable(); - - QQuickItem *front(); - void setFront(QQuickItem *); - - QQuickItem *back(); - void setBack(QQuickItem *); - - enum Side { Front, Back }; - Side side() const; - -Q_SIGNALS: - void frontChanged(); - void backChanged(); - void sideChanged(); - -protected: - virtual void updatePolish(); - -private Q_SLOTS: - void retransformBack(); - -private: - Q_DISABLE_COPY(QQuickFlipable) - Q_DECLARE_PRIVATE(QQuickFlipable) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickFlipable) - -QT_END_HEADER - -#endif // QQUICKFLIPABLE_P_H diff --git a/src/declarative/items/qquickfocusscope.cpp b/src/declarative/items/qquickfocusscope.cpp deleted file mode 100644 index b807fe58f6..0000000000 --- a/src/declarative/items/qquickfocusscope.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 "qquickfocusscope_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass FocusScope QQuickFocusScope - \inqmlmodule QtQuick 2 - \ingroup qml-basic-interaction-elements - - \brief The FocusScope object explicitly creates a focus scope. - \inherits Item - - Focus scopes assist in keyboard focus handling when building reusable QML - components. All the details are covered in the - \l {qmlfocus}{keyboard focus documentation}. - - \sa {declarative/keyinteraction/focus}{Keyboard focus example} -*/ -QQuickFocusScope::QQuickFocusScope(QQuickItem *parent) -: QQuickItem(parent) -{ - setFlag(ItemIsFocusScope); -} - -QQuickFocusScope::~QQuickFocusScope() -{ -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickfocusscope_p.h b/src/declarative/items/qquickfocusscope_p.h deleted file mode 100644 index ff1a389f62..0000000000 --- a/src/declarative/items/qquickfocusscope_p.h +++ /dev/null @@ -1,68 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKFOCUSSCOPE_P_H -#define QQUICKFOCUSSCOPE_P_H - -#include "qquickitem.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_AUTOTEST_EXPORT QQuickFocusScope : public QQuickItem -{ - Q_OBJECT -public: - QQuickFocusScope(QQuickItem *parent=0); - virtual ~QQuickFocusScope(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickFocusScope) - -QT_END_HEADER - -#endif // QQUICKFOCUSSCOPE_P_H diff --git a/src/declarative/items/qquickgridview.cpp b/src/declarative/items/qquickgridview.cpp deleted file mode 100644 index 44e1f14c6f..0000000000 --- a/src/declarative/items/qquickgridview.cpp +++ /dev/null @@ -1,1958 +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 QtDeclarative module 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 "qquickgridview_p.h" -#include "qquickvisualitemmodel_p.h" -#include "qquickflickable_p_p.h" -#include "qquickitemview_p_p.h" - -#include -#include - -#include -#include -#include -#include -#include "qplatformdefs.h" - -QT_BEGIN_NAMESPACE - -#ifndef QML_FLICK_SNAPONETHRESHOLD -#define QML_FLICK_SNAPONETHRESHOLD 30 -#endif - -//---------------------------------------------------------------------------- - -class FxGridItemSG : public FxViewItem -{ -public: - FxGridItemSG(QQuickItem *i, QQuickGridView *v, bool own) : FxViewItem(i, own), view(v) { - attached = static_cast(qmlAttachedPropertiesObject(item)); - if (attached) - static_cast(attached)->setView(view); - } - - ~FxGridItemSG() {} - - qreal position() const { - return rowPos(); - } - - qreal endPosition() const { - return endRowPos(); - } - - qreal size() const { - return view->flow() == QQuickGridView::LeftToRight ? view->cellHeight() : view->cellWidth(); - } - - qreal sectionSize() const { - return 0.0; - } - - qreal rowPos() const { - if (view->flow() == QQuickGridView::LeftToRight) - return item->y(); - else - return (view->effectiveLayoutDirection() == Qt::RightToLeft ? -view->cellWidth()-item->x() : item->x()); - } - - qreal colPos() const { - if (view->flow() == QQuickGridView::LeftToRight) { - if (view->effectiveLayoutDirection() == Qt::RightToLeft) { - qreal colSize = view->cellWidth(); - int columns = view->width()/colSize; - return colSize * (columns-1) - item->x(); - } else { - return item->x(); - } - } else { - return item->y(); - } - } - qreal endRowPos() const { - if (view->flow() == QQuickGridView::LeftToRight) { - return item->y() + view->cellHeight(); - } else { - if (view->effectiveLayoutDirection() == Qt::RightToLeft) - return -item->x(); - else - return item->x() + view->cellWidth(); - } - } - void setPosition(qreal col, qreal row) { - if (view->effectiveLayoutDirection() == Qt::RightToLeft) { - if (view->flow() == QQuickGridView::LeftToRight) { - int columns = view->width()/view->cellWidth(); - item->setPos(QPointF((view->cellWidth() * (columns-1) - col), row)); - } else { - item->setPos(QPointF(-view->cellWidth()-row, col)); - } - } else { - if (view->flow() == QQuickGridView::LeftToRight) - item->setPos(QPointF(col, row)); - else - item->setPos(QPointF(row, col)); - } - } - bool contains(qreal x, qreal y) const { - return (x >= item->x() && x < item->x() + view->cellWidth() && - y >= item->y() && y < item->y() + view->cellHeight()); - } - - QQuickGridView *view; -}; - -//---------------------------------------------------------------------------- - -class QQuickGridViewPrivate : public QQuickItemViewPrivate -{ - Q_DECLARE_PUBLIC(QQuickGridView) - -public: - virtual Qt::Orientation layoutOrientation() const; - virtual bool isContentFlowReversed() const; - bool isRightToLeftTopToBottom() const; - - virtual qreal positionAt(int index) const; - virtual qreal endPositionAt(int index) const; - virtual qreal originPosition() const; - virtual qreal lastPosition() const; - - qreal rowSize() const; - qreal colSize() const; - qreal colPosAt(int modelIndex) const; - qreal rowPosAt(int modelIndex) const; - qreal snapPosAt(qreal pos) const; - FxViewItem *snapItemAt(qreal pos) const; - int snapIndex() const; - - virtual bool addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer); - virtual bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo); - virtual void visibleItemsChanged(); - - virtual FxViewItem *newViewItem(int index, QQuickItem *item); - virtual void repositionPackageItemAt(QQuickItem *item, int index); - virtual void resetItemPosition(FxViewItem *item, FxViewItem *toItem); - virtual void resetFirstItemPosition(); - virtual void moveItemBy(FxViewItem *item, qreal forwards, qreal backwards); - - virtual void createHighlight(); - virtual void updateHighlight(); - virtual void resetHighlightPosition(); - - virtual void setPosition(qreal pos); - virtual void layoutVisibleItems(); - bool applyInsertionChange(const QDeclarativeChangeSet::Insert &, FxViewItem *, InsertionsResult *); - virtual bool needsRefillForAddedOrRemovedIndex(int index) const; - - virtual qreal headerSize() const; - virtual qreal footerSize() const; - virtual bool showHeaderForIndex(int index) const; - virtual bool showFooterForIndex(int index) const; - virtual void updateHeader(); - virtual void updateFooter(); - - virtual void changedVisibleIndex(int newIndex); - virtual void initializeCurrentItem(); - - virtual void updateViewport(); - virtual void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry); - virtual void fixupPosition(); - virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent); - virtual void flick(QQuickItemViewPrivate::AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, - QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity); - - QQuickGridView::Flow flow; - qreal cellWidth; - qreal cellHeight; - int columns; - QQuickGridView::SnapMode snapMode; - - QSmoothedAnimation *highlightXAnimator; - QSmoothedAnimation *highlightYAnimator; - - QQuickGridViewPrivate() - : flow(QQuickGridView::LeftToRight) - , cellWidth(100), cellHeight(100), columns(1) - , snapMode(QQuickGridView::NoSnap) - , highlightXAnimator(0), highlightYAnimator(0) - {} -}; - -Qt::Orientation QQuickGridViewPrivate::layoutOrientation() const -{ - return flow == QQuickGridView::LeftToRight ? Qt::Vertical : Qt::Horizontal; -} - -bool QQuickGridViewPrivate::isContentFlowReversed() const -{ - return isRightToLeftTopToBottom(); -} - -bool QQuickGridViewPrivate::isRightToLeftTopToBottom() const -{ - Q_Q(const QQuickGridView); - return flow == QQuickGridView::TopToBottom && q->effectiveLayoutDirection() == Qt::RightToLeft; -} - -void QQuickGridViewPrivate::changedVisibleIndex(int newIndex) -{ - visibleIndex = newIndex / columns * columns; -} - -void QQuickGridViewPrivate::setPosition(qreal pos) -{ - Q_Q(QQuickGridView); - if (flow == QQuickGridView::LeftToRight) { - q->QQuickFlickable::setContentY(pos); - q->QQuickFlickable::setContentX(0); - } else { - if (q->effectiveLayoutDirection() == Qt::LeftToRight) - q->QQuickFlickable::setContentX(pos); - else - q->QQuickFlickable::setContentX(-pos-size()); - q->QQuickFlickable::setContentY(0); - } -} - -qreal QQuickGridViewPrivate::originPosition() const -{ - qreal pos = 0; - if (!visibleItems.isEmpty()) - pos = static_cast(visibleItems.first())->rowPos() - visibleIndex / columns * rowSize(); - return pos; -} - -qreal QQuickGridViewPrivate::lastPosition() const -{ - qreal pos = 0; - if (model && model->count()) { - // get end position of last item - pos = (rowPosAt(model->count() - 1) + rowSize()); - } - return pos; -} - -qreal QQuickGridViewPrivate::positionAt(int index) const -{ - return rowPosAt(index); -} - -qreal QQuickGridViewPrivate::endPositionAt(int index) const -{ - return rowPosAt(index) + rowSize(); -} - -qreal QQuickGridViewPrivate::rowSize() const { - return flow == QQuickGridView::LeftToRight ? cellHeight : cellWidth; -} -qreal QQuickGridViewPrivate::colSize() const { - return flow == QQuickGridView::LeftToRight ? cellWidth : cellHeight; -} - -qreal QQuickGridViewPrivate::colPosAt(int modelIndex) const -{ - if (FxViewItem *item = visibleItem(modelIndex)) - return static_cast(item)->colPos(); - if (!visibleItems.isEmpty()) { - if (modelIndex == visibleIndex) { - FxGridItemSG *firstItem = static_cast(visibleItems.first()); - return firstItem->colPos(); - } else if (modelIndex < visibleIndex) { - int count = (visibleIndex - modelIndex) % columns; - int col = static_cast(visibleItems.first())->colPos() / colSize(); - col = (columns - count + col) % columns; - return col * colSize(); - } else { - int count = columns - 1 - (modelIndex - visibleItems.last()->index - 1) % columns; - return static_cast(visibleItems.last())->colPos() - count * colSize(); - } - } - return (modelIndex % columns) * colSize(); -} - -qreal QQuickGridViewPrivate::rowPosAt(int modelIndex) const -{ - if (FxViewItem *item = visibleItem(modelIndex)) - return static_cast(item)->rowPos(); - if (!visibleItems.isEmpty()) { - if (modelIndex == visibleIndex) { - FxGridItemSG *firstItem = static_cast(visibleItems.first()); - return firstItem->rowPos(); - } else if (modelIndex < visibleIndex) { - FxGridItemSG *firstItem = static_cast(visibleItems.first()); - int firstCol = firstItem->colPos() / colSize(); - int col = visibleIndex - modelIndex + (columns - firstCol - 1); - int rows = col / columns; - return firstItem->rowPos() - rows * rowSize(); - } else { - FxGridItemSG *lastItem = static_cast(visibleItems.last()); - int count = modelIndex - lastItem->index; - int col = lastItem->colPos() + count * colSize(); - int rows = col / (columns * colSize()); - return lastItem->rowPos() + rows * rowSize(); - } - } - return (modelIndex / columns) * rowSize(); -} - - -qreal QQuickGridViewPrivate::snapPosAt(qreal pos) const -{ - Q_Q(const QQuickGridView); - qreal snapPos = 0; - if (!visibleItems.isEmpty()) { - qreal highlightStart = highlightRangeStart; - pos += highlightStart; - pos += rowSize()/2; - snapPos = static_cast(visibleItems.first())->rowPos() - visibleIndex / columns * rowSize(); - snapPos = pos - fmodf(pos - snapPos, qreal(rowSize())); - snapPos -= highlightStart; - qreal maxExtent; - qreal minExtent; - if (isRightToLeftTopToBottom()) { - maxExtent = q->minXExtent()-size(); - minExtent = q->maxXExtent()-size(); - } else { - maxExtent = flow == QQuickGridView::LeftToRight ? -q->maxYExtent() : -q->maxXExtent(); - minExtent = flow == QQuickGridView::LeftToRight ? -q->minYExtent() : -q->minXExtent(); - } - if (snapPos > maxExtent) - snapPos = maxExtent; - if (snapPos < minExtent) - snapPos = minExtent; - } - return snapPos; -} - -FxViewItem *QQuickGridViewPrivate::snapItemAt(qreal pos) const -{ - for (int i = 0; i < visibleItems.count(); ++i) { - FxViewItem *item = visibleItems.at(i); - if (item->index == -1) - continue; - qreal itemTop = item->position(); - if (itemTop+rowSize()/2 >= pos && itemTop - rowSize()/2 <= pos) - return item; - } - return 0; -} - -int QQuickGridViewPrivate::snapIndex() const -{ - int index = currentIndex; - for (int i = 0; i < visibleItems.count(); ++i) { - FxGridItemSG *item = static_cast(visibleItems.at(i)); - if (item->index == -1) - continue; - qreal itemTop = item->position(); - FxGridItemSG *hItem = static_cast(highlight); - if (itemTop >= hItem->rowPos()-rowSize()/2 && itemTop < hItem->rowPos()+rowSize()/2) { - index = item->index; - if (item->colPos() >= hItem->colPos()-colSize()/2 && item->colPos() < hItem->colPos()+colSize()/2) - return item->index; - } - } - return index; -} - -FxViewItem *QQuickGridViewPrivate::newViewItem(int modelIndex, QQuickItem *item) -{ - Q_Q(QQuickGridView); - Q_UNUSED(modelIndex); - return new FxGridItemSG(item, q, false); -} - -bool QQuickGridViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer) -{ - qreal colPos = colPosAt(visibleIndex); - qreal rowPos = rowPosAt(visibleIndex); - if (visibleItems.count()) { - FxGridItemSG *lastItem = static_cast(visibleItems.last()); - rowPos = lastItem->rowPos(); - int colNum = qFloor((lastItem->colPos()+colSize()/2) / colSize()); - if (++colNum >= columns) { - colNum = 0; - rowPos += rowSize(); - } - colPos = colNum * colSize(); - } - - int modelIndex = findLastVisibleIndex(); - modelIndex = modelIndex < 0 ? visibleIndex : modelIndex + 1; - - if (visibleItems.count() && (fillFrom > rowPos + rowSize()*2 - || fillTo < rowPosAt(visibleIndex) - rowSize())) { - // We've jumped more than a page. Estimate which items are now - // visible and fill from there. - int count = (fillFrom - (rowPos + rowSize())) / (rowSize()) * columns; - for (int i = 0; i < visibleItems.count(); ++i) - releaseItem(visibleItems.at(i)); - visibleItems.clear(); - modelIndex += count; - if (modelIndex >= model->count()) - modelIndex = model->count() - 1; - else if (modelIndex < 0) - modelIndex = 0; - modelIndex = modelIndex / columns * columns; - visibleIndex = modelIndex; - colPos = colPosAt(visibleIndex); - rowPos = rowPosAt(visibleIndex); - } - - int colNum = qFloor((colPos+colSize()/2) / colSize()); - FxGridItemSG *item = 0; - bool changed = false; - - while (modelIndex < model->count() && rowPos <= fillTo + rowSize()*(columns - colNum)/(columns+1)) { -// qDebug() << "refill: append item" << modelIndex << colPos << rowPos; - if (!(item = static_cast(createItem(modelIndex, doBuffer)))) - break; - item->setPosition(colPos, rowPos); - item->item->setVisible(!doBuffer); - visibleItems.append(item); - if (++colNum >= columns) { - colNum = 0; - rowPos += rowSize(); - } - colPos = colNum * colSize(); - ++modelIndex; - changed = true; - } - - // Find first column - if (visibleItems.count()) { - FxGridItemSG *firstItem = static_cast(visibleItems.first()); - rowPos = firstItem->rowPos(); - colNum = qFloor((firstItem->colPos()+colSize()/2) / colSize()); - if (--colNum < 0) { - colNum = columns - 1; - rowPos -= rowSize(); - } - } else { - colNum = qFloor((colPos+colSize()/2) / colSize()); - } - - // Prepend - colPos = colNum * colSize(); - while (visibleIndex > 0 && rowPos + rowSize() - 1 >= fillFrom - rowSize()*(colNum+1)/(columns+1)){ -// qDebug() << "refill: prepend item" << visibleIndex-1 << "top pos" << rowPos << colPos; - if (!(item = static_cast(createItem(visibleIndex-1, doBuffer)))) - break; - --visibleIndex; - item->setPosition(colPos, rowPos); - item->item->setVisible(!doBuffer); - visibleItems.prepend(item); - if (--colNum < 0) { - colNum = columns-1; - rowPos -= rowSize(); - } - colPos = colNum * colSize(); - changed = true; - } - - return changed; -} - -bool QQuickGridViewPrivate::removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) -{ - Q_Q(QQuickGridView); - FxGridItemSG *item = 0; - bool changed = false; - - while (visibleItems.count() > 1 - && (item = static_cast(visibleItems.first())) - && item->rowPos()+rowSize()-1 < bufferFrom - rowSize()*(item->colPos()/colSize()+1)/(columns+1)) { - if (item->attached->delayRemove()) - break; -// qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endRowPos(); - if (item->index != -1) - visibleIndex++; - visibleItems.removeFirst(); - releaseItem(item); - changed = true; - } - while (visibleItems.count() > 1 - && (item = static_cast(visibleItems.last())) - && item->rowPos() > bufferTo + rowSize()*(columns - item->colPos()/colSize())/(columns+1)) { - if (item->attached->delayRemove()) - break; -// qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1; - visibleItems.removeLast(); - releaseItem(item); - changed = true; - } - - return changed; -} - -void QQuickGridViewPrivate::visibleItemsChanged() -{ - updateHeader(); - updateFooter(); - updateViewport(); -} - -void QQuickGridViewPrivate::updateViewport() -{ - Q_Q(QQuickGridView); - qreal length = flow == QQuickGridView::LeftToRight ? q->width() : q->height(); - columns = (int)qMax((length + colSize()/2) / colSize(), qreal(1.)); - QQuickItemViewPrivate::updateViewport(); -} - -void QQuickGridViewPrivate::layoutVisibleItems() -{ - if (visibleItems.count()) { - FxGridItemSG *firstItem = static_cast(visibleItems.first()); - qreal rowPos = firstItem->rowPos(); - qreal colPos = firstItem->colPos(); - int col = visibleIndex % columns; - if (colPos != col * colSize()) { - colPos = col * colSize(); - firstItem->setPosition(colPos, rowPos); - } - for (int i = 1; i < visibleItems.count(); ++i) { - FxGridItemSG *item = static_cast(visibleItems.at(i)); - if (++col >= columns) { - col = 0; - rowPos += rowSize(); - } - colPos = col * colSize(); - item->setPosition(colPos, rowPos); - } - } -} - -void QQuickGridViewPrivate::repositionPackageItemAt(QQuickItem *item, int index) -{ - Q_Q(QQuickGridView); - qreal pos = position(); - if (flow == QQuickGridView::LeftToRight) { - if (item->y() + item->height() > pos && item->y() < pos + q->height()) - item->setPos(QPointF(colPosAt(index), rowPosAt(index))); - } else { - if (item->x() + item->width() > pos && item->x() < pos + q->width()) { - if (isRightToLeftTopToBottom()) - item->setPos(QPointF(-rowPosAt(index)-item->width(), colPosAt(index))); - else - item->setPos(QPointF(rowPosAt(index), colPosAt(index))); - } - } -} - -void QQuickGridViewPrivate::resetItemPosition(FxViewItem *item, FxViewItem *toItem) -{ - if (item == toItem) - return; - FxGridItemSG *toGridItem = static_cast(toItem); - static_cast(item)->setPosition(toGridItem->colPos(), toGridItem->rowPos()); -} - -void QQuickGridViewPrivate::resetFirstItemPosition() -{ - FxGridItemSG *item = static_cast(visibleItems.first()); - item->setPosition(0, 0); -} - -void QQuickGridViewPrivate::moveItemBy(FxViewItem *item, qreal forwards, qreal backwards) -{ - int moveCount = (forwards / rowSize()) - (backwards / rowSize()); - - FxGridItemSG *gridItem = static_cast(item); - gridItem->setPosition(gridItem->colPos(), gridItem->rowPos() + ((moveCount / columns) * rowSize())); -} - -void QQuickGridViewPrivate::createHighlight() -{ - Q_Q(QQuickGridView); - bool changed = false; - if (highlight) { - if (trackedItem == highlight) - trackedItem = 0; - delete highlight; - highlight = 0; - - delete highlightXAnimator; - delete highlightYAnimator; - highlightXAnimator = 0; - highlightYAnimator = 0; - - changed = true; - } - - if (currentItem) { - QQuickItem *item = createHighlightItem(); - if (item) { - FxGridItemSG *newHighlight = new FxGridItemSG(item, q, true); - if (autoHighlight) - resetHighlightPosition(); - highlightXAnimator = new QSmoothedAnimation(q); - highlightXAnimator->target = QDeclarativeProperty(item, QLatin1String("x")); - highlightXAnimator->userDuration = highlightMoveDuration; - highlightYAnimator = new QSmoothedAnimation(q); - highlightYAnimator->target = QDeclarativeProperty(item, QLatin1String("y")); - highlightYAnimator->userDuration = highlightMoveDuration; - - highlight = newHighlight; - changed = true; - } - } - if (changed) - emit q->highlightItemChanged(); -} - -void QQuickGridViewPrivate::updateHighlight() -{ - applyPendingChanges(); - - if ((!currentItem && highlight) || (currentItem && !highlight)) - createHighlight(); - bool strictHighlight = haveHighlightRange && highlightRange == QQuickGridView::StrictlyEnforceRange; - if (currentItem && autoHighlight && highlight && (!strictHighlight || !pressed)) { - // auto-update highlight - highlightXAnimator->to = currentItem->item->x(); - highlightYAnimator->to = currentItem->item->y(); - highlight->item->setWidth(currentItem->item->width()); - highlight->item->setHeight(currentItem->item->height()); - - highlightXAnimator->restart(); - highlightYAnimator->restart(); - } - updateTrackedItem(); -} - -void QQuickGridViewPrivate::resetHighlightPosition() -{ - if (highlight && currentItem) { - FxGridItemSG *cItem = static_cast(currentItem); - static_cast(highlight)->setPosition(cItem->colPos(), cItem->rowPos()); - } -} - -qreal QQuickGridViewPrivate::headerSize() const -{ - if (!header) - return 0.0; - return flow == QQuickGridView::LeftToRight ? header->item->height() : header->item->width(); -} - -qreal QQuickGridViewPrivate::footerSize() const -{ - if (!footer) - return 0.0; - return flow == QQuickGridView::LeftToRight? footer->item->height() : footer->item->width(); -} - -bool QQuickGridViewPrivate::showHeaderForIndex(int index) const -{ - return index / columns == 0; -} - -bool QQuickGridViewPrivate::showFooterForIndex(int index) const -{ - return index / columns == (model->count()-1) / columns; -} - -void QQuickGridViewPrivate::updateFooter() -{ - Q_Q(QQuickGridView); - bool created = false; - if (!footer) { - QQuickItem *item = createComponentItem(footerComponent, true); - if (!item) - return; - item->setZ(1); - footer = new FxGridItemSG(item, q, true); - created = true; - } - - FxGridItemSG *gridItem = static_cast(footer); - qreal colOffset = 0; - qreal rowOffset = 0; - if (q->effectiveLayoutDirection() == Qt::RightToLeft) { - if (flow == QQuickGridView::TopToBottom) - rowOffset = gridItem->item->width() - cellWidth; - else - colOffset = gridItem->item->width() - cellWidth; - } - if (visibleItems.count()) { - qreal endPos = lastPosition(); - if (findLastVisibleIndex() == model->count()-1) { - gridItem->setPosition(colOffset, endPos + rowOffset); - } else { - qreal visiblePos = isRightToLeftTopToBottom() ? -position() : position() + size(); - if (endPos <= visiblePos || gridItem->endPosition() <= endPos + rowOffset) - gridItem->setPosition(colOffset, endPos + rowOffset); - } - } else { - gridItem->setPosition(colOffset, rowOffset); - } - - if (created) - emit q->footerItemChanged(); -} - -void QQuickGridViewPrivate::updateHeader() -{ - Q_Q(QQuickGridView); - bool created = false; - if (!header) { - QQuickItem *item = createComponentItem(headerComponent, true); - if (!item) - return; - item->setZ(1); - header = new FxGridItemSG(item, q, true); - created = true; - } - - FxGridItemSG *gridItem = static_cast(header); - qreal colOffset = 0; - qreal rowOffset = -headerSize(); - if (q->effectiveLayoutDirection() == Qt::RightToLeft) { - if (flow == QQuickGridView::TopToBottom) - rowOffset += gridItem->item->width()-cellWidth; - else - colOffset = gridItem->item->width()-cellWidth; - } - if (visibleItems.count()) { - qreal startPos = originPosition(); - if (visibleIndex == 0) { - gridItem->setPosition(colOffset, startPos + rowOffset); - } else { - qreal tempPos = isRightToLeftTopToBottom() ? -position()-size() : position(); - qreal headerPos = isRightToLeftTopToBottom() ? gridItem->rowPos() + cellWidth - headerSize() : gridItem->rowPos(); - if (tempPos <= startPos || headerPos > startPos + rowOffset) - gridItem->setPosition(colOffset, startPos + rowOffset); - } - } else { - if (isRightToLeftTopToBottom()) - gridItem->setPosition(colOffset, rowOffset); - else - gridItem->setPosition(colOffset, -headerSize()); - } - - if (created) - emit q->headerItemChanged(); -} - -void QQuickGridViewPrivate::initializeCurrentItem() -{ - if (currentItem && currentIndex >= 0) { - FxGridItemSG *gridItem = static_cast(currentItem); - if (gridItem) - gridItem->setPosition(colPosAt(currentIndex), rowPosAt(currentIndex)); - } -} - -void QQuickGridViewPrivate::itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_Q(QQuickGridView); - QQuickItemViewPrivate::itemGeometryChanged(item, newGeometry, oldGeometry); - if (!q->isComponentComplete()) - return; - if (item == q) { - if (newGeometry.height() != oldGeometry.height() || newGeometry.width() != oldGeometry.width()) { - updateViewport(); - forceLayout = true; - q->polish(); - } - } -} - -void QQuickGridViewPrivate::fixupPosition() -{ - moveReason = Other; - if (flow == QQuickGridView::LeftToRight) - fixupY(); - else - fixupX(); -} - -void QQuickGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent) -{ - if ((flow == QQuickGridView::TopToBottom && &data == &vData) - || (flow == QQuickGridView::LeftToRight && &data == &hData)) - return; - - fixupMode = moveReason == Mouse ? fixupMode : Immediate; - - qreal viewPos = isRightToLeftTopToBottom() ? -position()-size() : position(); - - bool strictHighlightRange = haveHighlightRange && highlightRange == QQuickGridView::StrictlyEnforceRange; - if (snapMode != QQuickGridView::NoSnap) { - qreal tempPosition = isRightToLeftTopToBottom() ? -position()-size() : position(); - if (snapMode == QQuickGridView::SnapOneRow && moveReason == Mouse) { - // if we've been dragged < rowSize()/2 then bias towards the next row - qreal dist = data.move.value() - (data.pressPos - data.dragStartOffset); - qreal bias = 0; - if (data.velocity > 0 && dist > QML_FLICK_SNAPONETHRESHOLD && dist < rowSize()/2) - bias = rowSize()/2; - else if (data.velocity < 0 && dist < -QML_FLICK_SNAPONETHRESHOLD && dist > -rowSize()/2) - bias = -rowSize()/2; - if (isRightToLeftTopToBottom()) - bias = -bias; - tempPosition -= bias; - } - FxViewItem *topItem = snapItemAt(tempPosition+highlightRangeStart); - if (!topItem && strictHighlightRange && currentItem) { - // StrictlyEnforceRange always keeps an item in range - updateHighlight(); - topItem = currentItem; - } - FxViewItem *bottomItem = snapItemAt(tempPosition+highlightRangeEnd); - if (!bottomItem && strictHighlightRange && currentItem) { - // StrictlyEnforceRange always keeps an item in range - updateHighlight(); - bottomItem = currentItem; - } - qreal pos; - bool isInBounds = -position() > maxExtent && -position() <= minExtent; - if (topItem && (isInBounds || strictHighlightRange)) { - qreal headerPos = header ? static_cast(header)->rowPos() : 0; - if (topItem->index == 0 && header && tempPosition+highlightRangeStart < headerPos+headerSize()/2 && !strictHighlightRange) { - pos = isRightToLeftTopToBottom() ? - headerPos + highlightRangeStart - size() : headerPos - highlightRangeStart; - } else { - if (isRightToLeftTopToBottom()) - pos = qMax(qMin(-topItem->position() + highlightRangeStart - size(), -maxExtent), -minExtent); - else - pos = qMax(qMin(topItem->position() - highlightRangeStart, -maxExtent), -minExtent); - } - } else if (bottomItem && isInBounds) { - if (isRightToLeftTopToBottom()) - pos = qMax(qMin(-bottomItem->position() + highlightRangeEnd - size(), -maxExtent), -minExtent); - else - pos = qMax(qMin(bottomItem->position() - highlightRangeEnd, -maxExtent), -minExtent); - } else { - QQuickItemViewPrivate::fixup(data, minExtent, maxExtent); - return; - } - - qreal dist = qAbs(data.move + pos); - if (dist > 0) { - timeline.reset(data.move); - if (fixupMode != Immediate) { - timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - data.fixingUp = true; - } else { - timeline.set(data.move, -pos); - } - vTime = timeline.time(); - } - } else if (haveHighlightRange && highlightRange == QQuickGridView::StrictlyEnforceRange) { - if (currentItem) { - updateHighlight(); - qreal pos = static_cast(currentItem)->rowPos(); - if (viewPos < pos + rowSize() - highlightRangeEnd) - viewPos = pos + rowSize() - highlightRangeEnd; - if (viewPos > pos - highlightRangeStart) - viewPos = pos - highlightRangeStart; - if (isRightToLeftTopToBottom()) - viewPos = -viewPos-size(); - timeline.reset(data.move); - if (viewPos != position()) { - if (fixupMode != Immediate) { - timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - data.fixingUp = true; - } else { - timeline.set(data.move, -viewPos); - } - } - vTime = timeline.time(); - } - } else { - QQuickItemViewPrivate::fixup(data, minExtent, maxExtent); - } - data.inOvershoot = false; - fixupMode = Normal; -} - -void QQuickGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, - QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity) -{ - Q_Q(QQuickGridView); - data.fixingUp = false; - moveReason = Mouse; - if ((!haveHighlightRange || highlightRange != QQuickGridView::StrictlyEnforceRange) - && snapMode == QQuickGridView::NoSnap) { - QQuickItemViewPrivate::flick(data, minExtent, maxExtent, vSize, fixupCallback, velocity); - return; - } - qreal maxDistance = 0; - qreal dataValue = isRightToLeftTopToBottom() ? -data.move.value()+size() : data.move.value(); - // -ve velocity means list is moving up/left - if (velocity > 0) { - if (data.move.value() < minExtent) { - if (snapMode == QQuickGridView::SnapOneRow) { - // if we've been dragged < averageSize/2 then bias towards the next item - qreal dist = data.move.value() - (data.pressPos - data.dragStartOffset); - qreal bias = dist < rowSize()/2 ? rowSize()/2 : 0; - if (isRightToLeftTopToBottom()) - bias = -bias; - data.flickTarget = -snapPosAt(-dataValue - bias); - maxDistance = qAbs(data.flickTarget - data.move.value()); - velocity = maxVelocity; - } else { - maxDistance = qAbs(minExtent - data.move.value()); - } - } - if (snapMode == QQuickGridView::NoSnap && highlightRange != QQuickGridView::StrictlyEnforceRange) - data.flickTarget = minExtent; - } else { - if (data.move.value() > maxExtent) { - if (snapMode == QQuickGridView::SnapOneRow) { - // if we've been dragged < averageSize/2 then bias towards the next item - qreal dist = data.move.value() - (data.pressPos - data.dragStartOffset); - qreal bias = -dist < rowSize()/2 ? rowSize()/2 : 0; - if (isRightToLeftTopToBottom()) - bias = -bias; - data.flickTarget = -snapPosAt(-dataValue + bias); - maxDistance = qAbs(data.flickTarget - data.move.value()); - velocity = -maxVelocity; - } else { - maxDistance = qAbs(maxExtent - data.move.value()); - } - } - if (snapMode == QQuickGridView::NoSnap && highlightRange != QQuickGridView::StrictlyEnforceRange) - data.flickTarget = maxExtent; - } - bool overShoot = boundsBehavior == QQuickFlickable::DragAndOvershootBounds; - if (maxDistance > 0 || overShoot) { - // This mode requires the grid to stop exactly on a row boundary. - qreal v = velocity; - if (maxVelocity != -1 && maxVelocity < qAbs(v)) { - if (v < 0) - v = -maxVelocity; - else - v = maxVelocity; - } - qreal accel = deceleration; - qreal v2 = v * v; - qreal overshootDist = 0.0; - if ((maxDistance > 0.0 && v2 / (2.0f * maxDistance) < accel) || snapMode == QQuickGridView::SnapOneRow) { - // + rowSize()/4 to encourage moving at least one item in the flick direction - qreal dist = v2 / (accel * 2.0) + rowSize()/4; - dist = qMin(dist, maxDistance); - if (v > 0) - dist = -dist; - if (snapMode != QQuickGridView::SnapOneRow) { - qreal distTemp = isRightToLeftTopToBottom() ? -dist : dist; - data.flickTarget = -snapPosAt(-dataValue + distTemp); - } - data.flickTarget = isRightToLeftTopToBottom() ? -data.flickTarget+size() : data.flickTarget; - if (overShoot) { - if (data.flickTarget >= minExtent) { - overshootDist = overShootDistance(vSize); - data.flickTarget += overshootDist; - } else if (data.flickTarget <= maxExtent) { - overshootDist = overShootDistance(vSize); - data.flickTarget -= overshootDist; - } - } - qreal adjDist = -data.flickTarget + data.move.value(); - if (qAbs(adjDist) > qAbs(dist)) { - // Prevent painfully slow flicking - adjust velocity to suit flickDeceleration - qreal adjv2 = accel * 2.0f * qAbs(adjDist); - if (adjv2 > v2) { - v2 = adjv2; - v = qSqrt(v2); - if (dist > 0) - v = -v; - } - } - dist = adjDist; - accel = v2 / (2.0f * qAbs(dist)); - } else { - data.flickTarget = velocity > 0 ? minExtent : maxExtent; - overshootDist = overShoot ? overShootDistance(vSize) : 0; - } - timeline.reset(data.move); - timeline.accel(data.move, v, accel, maxDistance + overshootDist); - timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this)); - if (!hData.flicking && q->xflick()) { - hData.flicking = true; - emit q->flickingChanged(); - emit q->flickingHorizontallyChanged(); - emit q->flickStarted(); - } - if (!vData.flicking && q->yflick()) { - vData.flicking = true; - emit q->flickingChanged(); - emit q->flickingVerticallyChanged(); - emit q->flickStarted(); - } - } else { - timeline.reset(data.move); - fixup(data, minExtent, maxExtent); - } -} - - -//---------------------------------------------------------------------------- -/*! - \qmlclass GridView QQuickGridView - \inqmlmodule QtQuick 2 - \ingroup qml-view-elements - - \inherits Flickable - \brief The GridView item provides a grid view of items provided by a model. - - A GridView displays data from models created from built-in QML elements like ListModel - and XmlListModel, or custom model classes defined in C++ that inherit from - QAbstractListModel. - - A GridView has a \l model, which defines the data to be displayed, and - a \l delegate, which defines how the data should be displayed. Items in a - GridView are laid out horizontally or vertically. Grid views are inherently flickable - as GridView inherits from \l Flickable. - - \section1 Example Usage - - The following example shows the definition of a simple list model defined - in a file called \c ContactModel.qml: - - \snippet doc/src/snippets/declarative/gridview/ContactModel.qml 0 - - \div {class="float-right"} - \inlineimage gridview-simple.png - \enddiv - - This model can be referenced as \c ContactModel in other QML files. See \l{QML Modules} - for more information about creating reusable components like this. - - Another component can display this model data in a GridView, as in the following - example, which creates a \c ContactModel component for its model, and a \l Column element - (containing \l Image and \l Text elements) for its delegate. - - \clearfloat - \snippet doc/src/snippets/declarative/gridview/gridview.qml import - \codeline - \snippet doc/src/snippets/declarative/gridview/gridview.qml classdocs simple - - \div {class="float-right"} - \inlineimage gridview-highlight.png - \enddiv - - The view will create a new delegate for each item in the model. Note that the delegate - is able to access the model's \c name and \c portrait data directly. - - An improved grid view is shown below. The delegate is visually improved and is moved - into a separate \c contactDelegate component. - - \clearfloat - \snippet doc/src/snippets/declarative/gridview/gridview.qml classdocs advanced - - The currently selected item is highlighted with a blue \l Rectangle using the \l highlight property, - and \c focus is set to \c true to enable keyboard navigation for the grid view. - The grid view itself is a focus scope (see \l{qmlfocus#Acquiring Focus and Focus Scopes}{the focus documentation page} for more details). - - Delegates are instantiated as needed and may be destroyed at any time. - State should \e never be stored in a delegate. - - GridView attaches a number of properties to the root item of the delegate, for example - \c {GridView.isCurrentItem}. In the following example, the root delegate item can access - this attached property directly as \c GridView.isCurrentItem, while the child - \c contactInfo object must refer to this property as \c wrapper.GridView.isCurrentItem. - - \snippet doc/src/snippets/declarative/gridview/gridview.qml isCurrentItem - - \note Views do not set the \l{Item::}{clip} property automatically. - If the view is not clipped by another item or the screen, it will be necessary - to set this property to true in order to clip the items that are partially or - fully outside the view. - - \sa {declarative/modelviews/gridview}{GridView example} -*/ - -QQuickGridView::QQuickGridView(QQuickItem *parent) - : QQuickItemView(*(new QQuickGridViewPrivate), parent) -{ -} - -QQuickGridView::~QQuickGridView() -{ -} - -void QQuickGridView::setHighlightFollowsCurrentItem(bool autoHighlight) -{ - Q_D(QQuickGridView); - if (d->autoHighlight != autoHighlight) { - if (!autoHighlight && d->highlightXAnimator) { - d->highlightXAnimator->stop(); - d->highlightYAnimator->stop(); - } - QQuickItemView::setHighlightFollowsCurrentItem(autoHighlight); - } -} - -/*! - \qmlattachedproperty bool QtQuick2::GridView::isCurrentItem - This attached property is true if this delegate is the current item; otherwise false. - - It is attached to each instance of the delegate. -*/ - -/*! - \qmlattachedproperty GridView QtQuick2::GridView::view - This attached property holds the view that manages this delegate instance. - - It is attached to each instance of the delegate. - - \snippet doc/src/snippets/declarative/gridview/gridview.qml isCurrentItem -*/ - -/*! - \qmlattachedproperty bool QtQuick2::GridView::delayRemove - This attached property holds whether the delegate may be destroyed. - - It is attached to each instance of the delegate. - - It is sometimes necessary to delay the destruction of an item - until an animation completes. - - The example below ensures that the animation completes before - the item is removed from the grid. - - \snippet doc/src/snippets/declarative/gridview/gridview.qml delayRemove -*/ - -/*! - \qmlattachedsignal QtQuick2::GridView::onAdd() - This attached handler is called immediately after an item is added to the view. -*/ - -/*! - \qmlattachedsignal QtQuick2::GridView::onRemove() - This attached handler is called immediately before an item is removed from the view. -*/ - - -/*! - \qmlproperty model QtQuick2::GridView::model - This property holds the model providing data for the grid. - - The model provides the set of data that is used to create the items - in the view. Models can be created directly in QML using \l ListModel, \l XmlListModel - or \l VisualItemModel, or provided by C++ model classes. If a C++ model class is - used, it must be a subclass of \l QAbstractItemModel or a simple list. - - \sa {qmlmodels}{Data Models} -*/ - -/*! - \qmlproperty Component QtQuick2::GridView::delegate - - The delegate provides a template defining each item instantiated by the view. - The index is exposed as an accessible \c index property. Properties of the - model are also available depending upon the type of \l {qmlmodels}{Data Model}. - - The number of elements in the delegate has a direct effect on the - flicking performance of the view. If at all possible, place functionality - that is not needed for the normal display of the delegate in a \l Loader which - can load additional elements when needed. - - The GridView will layout the items based on the size of the root item - in the delegate. - - \note Delegates are instantiated as needed and may be destroyed at any time. - State should \e never be stored in a delegate. -*/ - -/*! - \qmlproperty int QtQuick2::GridView::currentIndex - \qmlproperty Item QtQuick2::GridView::currentItem - - The \c currentIndex property holds the index of the current item, and - \c currentItem holds the current item. Setting the currentIndex to -1 - will clear the highlight and set currentItem to null. - - If highlightFollowsCurrentItem is \c true, setting either of these - properties will smoothly scroll the GridView so that the current - item becomes visible. - - Note that the position of the current item - may only be approximate until it becomes visible in the view. -*/ - - -/*! - \qmlproperty Item QtQuick2::GridView::highlightItem - - This holds the highlight item created from the \l highlight component. - - The highlightItem is managed by the view unless - \l highlightFollowsCurrentItem is set to false. - - \sa highlight, highlightFollowsCurrentItem -*/ - - -/*! - \qmlproperty int QtQuick2::GridView::count - This property holds the number of items in the view. -*/ - - -/*! - \qmlproperty Component QtQuick2::GridView::highlight - This property holds the component to use as the highlight. - - An instance of the highlight component is created for each view. - The geometry of the resulting component instance will be managed by the view - so as to stay with the current item, unless the highlightFollowsCurrentItem property is false. - - \sa highlightItem, highlightFollowsCurrentItem -*/ - -/*! - \qmlproperty bool QtQuick2::GridView::highlightFollowsCurrentItem - This property sets whether the highlight is managed by the view. - - If this property is true (the default value), the highlight is moved smoothly - to follow the current item. Otherwise, the - highlight is not moved by the view, and any movement must be implemented - by the highlight. - - Here is a highlight with its motion defined by a \l {SpringAnimation} item: - - \snippet doc/src/snippets/declarative/gridview/gridview.qml highlightFollowsCurrentItem -*/ - - -/*! - \qmlproperty int QtQuick2::GridView::highlightMoveDuration - This property holds the move animation duration of the highlight delegate. - - highlightFollowsCurrentItem must be true for this property - to have effect. - - The default value for the duration is 150ms. - - \sa highlightFollowsCurrentItem -*/ - -/*! - \qmlproperty real QtQuick2::GridView::preferredHighlightBegin - \qmlproperty real QtQuick2::GridView::preferredHighlightEnd - \qmlproperty enumeration QtQuick2::GridView::highlightRangeMode - - These properties define the preferred range of the highlight (for the current item) - within the view. The \c preferredHighlightBegin value must be less than the - \c preferredHighlightEnd value. - - These properties affect the position of the current item when the view is scrolled. - For example, if the currently selected item should stay in the middle of the - view when it is scrolled, set the \c preferredHighlightBegin and - \c preferredHighlightEnd values to the top and bottom coordinates of where the middle - item would be. If the \c currentItem is changed programmatically, the view will - automatically scroll so that the current item is in the middle of the view. - Furthermore, the behavior of the current item index will occur whether or not a - highlight exists. - - Valid values for \c highlightRangeMode are: - - \list - \o GridView.ApplyRange - the view attempts to maintain the highlight within the range. - However, the highlight can move outside of the range at the ends of the view or due - to mouse interaction. - \o GridView.StrictlyEnforceRange - the highlight never moves outside of the range. - The current item changes if a keyboard or mouse action would cause the highlight to move - outside of the range. - \o GridView.NoHighlightRange - this is the default value. - \endlist -*/ - - -/*! - \qmlproperty enumeration QtQuick2::GridView::layoutDirection - This property holds the layout direction of the grid. - - Possible values: - - \list - \o Qt.LeftToRight (default) - Items will be laid out starting in the top, left corner. The flow is - dependent on the \l GridView::flow property. - \o Qt.RightToLeft - Items will be laid out starting in the top, right corner. The flow is dependent - on the \l GridView::flow property. - \endlist - - \bold Note: If GridView::flow is set to GridView.LeftToRight, this is not to be confused if - GridView::layoutDirection is set to Qt.RightToLeft. The GridView.LeftToRight flow value simply - indicates that the flow is horizontal. -*/ - - -/*! - \qmlproperty enumeration QtQuick2::GridView::effectiveLayoutDirection - This property holds the effective layout direction of the grid. - - When using the attached property \l {LayoutMirroring::enabled}{LayoutMirroring::enabled} for locale layouts, - the visual layout direction of the grid will be mirrored. However, the - property \l {GridView::layoutDirection}{layoutDirection} will remain unchanged. - - \sa GridView::layoutDirection, {LayoutMirroring}{LayoutMirroring} -*/ -/*! - \qmlproperty bool QtQuick2::GridView::keyNavigationWraps - This property holds whether the grid wraps key navigation - - If this is true, key navigation that would move the current item selection - past one end of the view instead wraps around and moves the selection to - the other end of the view. - - By default, key navigation is not wrapped. -*/ -/*! - \qmlproperty int QtQuick2::GridView::cacheBuffer - This property determines whether delegates are retained outside the - visible area of the view. - - If non-zero the view may keep as many delegates - instantiated as will fit within the buffer specified. For example, - if in a vertical view the delegate is 20 pixels high, there are 3 - columns and \c cacheBuffer is - set to 40, then up to 6 delegates above and 6 delegates below the visible - area may be created/retained. The buffered delegates are created asynchronously, - allowing creation to occur across multiple frames and reducing the - likelihood of skipping frames. In order to improve painting performance - delegates outside the visible area have their \l visible property set to - false until they are moved into the visible area. - - Note that cacheBuffer is not a pixel buffer - it only maintains additional - instantiated delegates. - - Setting this value can make scrolling the list smoother at the expense - of additional memory usage. It is not a substitute for creating efficient - delegates; the fewer elements in a delegate, the faster a view may be - scrolled. -*/ -void QQuickGridView::setHighlightMoveDuration(int duration) -{ - Q_D(QQuickGridView); - if (d->highlightMoveDuration != duration) { - if (d->highlightYAnimator) { - d->highlightXAnimator->userDuration = duration; - d->highlightYAnimator->userDuration = duration; - } - QQuickItemView::setHighlightMoveDuration(duration); - } -} - -/*! - \qmlproperty enumeration QtQuick2::GridView::flow - This property holds the flow of the grid. - - Possible values: - - \list - \o GridView.LeftToRight (default) - Items are laid out from left to right, and the view scrolls vertically - \o GridView.TopToBottom - Items are laid out from top to bottom, and the view scrolls horizontally - \endlist -*/ -QQuickGridView::Flow QQuickGridView::flow() const -{ - Q_D(const QQuickGridView); - return d->flow; -} - -void QQuickGridView::setFlow(Flow flow) -{ - Q_D(QQuickGridView); - if (d->flow != flow) { - d->flow = flow; - if (d->flow == LeftToRight) { - setContentWidth(-1); - setFlickableDirection(VerticalFlick); - } else { - setContentHeight(-1); - setFlickableDirection(HorizontalFlick); - } - setContentX(0); - setContentY(0); - d->regenerate(); - emit flowChanged(); - } -} - - -/*! - \qmlproperty real QtQuick2::GridView::cellWidth - \qmlproperty real QtQuick2::GridView::cellHeight - - These properties holds the width and height of each cell in the grid. - - The default cell size is 100x100. -*/ -qreal QQuickGridView::cellWidth() const -{ - Q_D(const QQuickGridView); - return d->cellWidth; -} - -void QQuickGridView::setCellWidth(qreal cellWidth) -{ - Q_D(QQuickGridView); - if (cellWidth != d->cellWidth && cellWidth > 0) { - d->cellWidth = qMax(qreal(1), cellWidth); - d->updateViewport(); - emit cellWidthChanged(); - d->forceLayout = true; - d->layout(); - } -} - -qreal QQuickGridView::cellHeight() const -{ - Q_D(const QQuickGridView); - return d->cellHeight; -} - -void QQuickGridView::setCellHeight(qreal cellHeight) -{ - Q_D(QQuickGridView); - if (cellHeight != d->cellHeight && cellHeight > 0) { - d->cellHeight = qMax(qreal(1), cellHeight); - d->updateViewport(); - emit cellHeightChanged(); - d->forceLayout = true; - d->layout(); - } -} -/*! - \qmlproperty enumeration QtQuick2::GridView::snapMode - - This property determines how the view scrolling will settle following a drag or flick. - The possible values are: - - \list - \o GridView.NoSnap (default) - the view stops anywhere within the visible area. - \o GridView.SnapToRow - the view settles with a row (or column for \c GridView.TopToBottom flow) - aligned with the start of the view. - \o GridView.SnapOneRow - the view will settle no more than one row (or column for \c GridView.TopToBottom flow) - away from the first visible row at the time the mouse button is released. - This mode is particularly useful for moving one page at a time. - \endlist - -*/ -QQuickGridView::SnapMode QQuickGridView::snapMode() const -{ - Q_D(const QQuickGridView); - return d->snapMode; -} - -void QQuickGridView::setSnapMode(SnapMode mode) -{ - Q_D(QQuickGridView); - if (d->snapMode != mode) { - d->snapMode = mode; - emit snapModeChanged(); - } -} - - -/*! - \qmlproperty Component QtQuick2::GridView::footer - This property holds the component to use as the footer. - - An instance of the footer component is created for each view. The - footer is positioned at the end of the view, after any items. - - \sa header -*/ -/*! - \qmlproperty Component QtQuick2::GridView::header - This property holds the component to use as the header. - - An instance of the header component is created for each view. The - header is positioned at the beginning of the view, before any items. - - \sa footer -*/ -void QQuickGridView::viewportMoved() -{ - Q_D(QQuickGridView); - QQuickItemView::viewportMoved(); - if (!d->itemCount) - return; - if (d->inViewportMoved) - return; - d->inViewportMoved = true; - - // Set visibility of items to eliminate cost of items outside the visible area. - qreal from = d->isContentFlowReversed() ? -d->position()-d->size() : d->position(); - qreal to = d->isContentFlowReversed() ? -d->position() : d->position()+d->size(); - for (int i = 0; i < d->visibleItems.count(); ++i) { - FxGridItemSG *item = static_cast(d->visibleItems.at(i)); - item->item->setVisible(item->rowPos() + d->rowSize() >= from && item->rowPos() <= to); - } - - if (yflick()) - d->bufferMode = d->vData.smoothVelocity < 0 ? QQuickItemViewPrivate::BufferBefore : QQuickItemViewPrivate::BufferAfter; - else if (d->isRightToLeftTopToBottom()) - d->bufferMode = d->hData.smoothVelocity < 0 ? QQuickItemViewPrivate::BufferAfter : QQuickItemViewPrivate::BufferBefore; - else - d->bufferMode = d->hData.smoothVelocity < 0 ? QQuickItemViewPrivate::BufferBefore : QQuickItemViewPrivate::BufferAfter; - - d->refill(); - if (d->hData.flicking || d->vData.flicking || d->hData.moving || d->vData.moving) - d->moveReason = QQuickGridViewPrivate::Mouse; - if (d->moveReason != QQuickGridViewPrivate::SetIndex) { - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) { - // reposition highlight - qreal pos = d->highlight->position(); - qreal viewPos = d->isRightToLeftTopToBottom() ? -d->position()-d->size() : d->position(); - if (pos > viewPos + d->highlightRangeEnd - d->highlight->size()) - pos = viewPos + d->highlightRangeEnd - d->highlight->size(); - if (pos < viewPos + d->highlightRangeStart) - pos = viewPos + d->highlightRangeStart; - - if (pos != d->highlight->position()) { - d->highlightXAnimator->stop(); - d->highlightYAnimator->stop(); - static_cast(d->highlight)->setPosition(static_cast(d->highlight)->colPos(), pos); - } else { - d->updateHighlight(); - } - - // update current index - int idx = d->snapIndex(); - if (idx >= 0 && idx != d->currentIndex) { - d->updateCurrent(idx); - if (d->currentItem && static_cast(d->currentItem)->colPos() != static_cast(d->highlight)->colPos() && d->autoHighlight) { - if (d->flow == LeftToRight) - d->highlightXAnimator->to = d->currentItem->item->x(); - else - d->highlightYAnimator->to = d->currentItem->item->y(); - } - } - } - } - - d->inViewportMoved = false; -} - -void QQuickGridView::keyPressEvent(QKeyEvent *event) -{ - Q_D(QQuickGridView); - if (d->model && d->model->count() && d->interactive) { - d->moveReason = QQuickGridViewPrivate::SetIndex; - int oldCurrent = currentIndex(); - switch (event->key()) { - case Qt::Key_Up: - moveCurrentIndexUp(); - break; - case Qt::Key_Down: - moveCurrentIndexDown(); - break; - case Qt::Key_Left: - moveCurrentIndexLeft(); - break; - case Qt::Key_Right: - moveCurrentIndexRight(); - break; - default: - break; - } - if (oldCurrent != currentIndex()) { - event->accept(); - return; - } - } - event->ignore(); - QQuickItemView::keyPressEvent(event); -} -/*! - \qmlmethod QtQuick2::GridView::moveCurrentIndexUp() - - Move the currentIndex up one item in the view. - The current index will wrap if keyNavigationWraps is true and it - is currently at the end. This method has no effect if the \l count is zero. - - \bold Note: methods should only be called after the Component has completed. -*/ - - -void QQuickGridView::moveCurrentIndexUp() -{ - Q_D(QQuickGridView); - const int count = d->model ? d->model->count() : 0; - if (!count) - return; - if (d->flow == QQuickGridView::LeftToRight) { - if (currentIndex() >= d->columns || d->wrap) { - int index = currentIndex() - d->columns; - setCurrentIndex((index >= 0 && index < count) ? index : count-1); - } - } else { - if (currentIndex() > 0 || d->wrap) { - int index = currentIndex() - 1; - setCurrentIndex((index >= 0 && index < count) ? index : count-1); - } - } -} - -/*! - \qmlmethod QtQuick2::GridView::moveCurrentIndexDown() - - Move the currentIndex down one item in the view. - The current index will wrap if keyNavigationWraps is true and it - is currently at the end. This method has no effect if the \l count is zero. - - \bold Note: methods should only be called after the Component has completed. -*/ -void QQuickGridView::moveCurrentIndexDown() -{ - Q_D(QQuickGridView); - const int count = d->model ? d->model->count() : 0; - if (!count) - return; - if (d->flow == QQuickGridView::LeftToRight) { - if (currentIndex() < count - d->columns || d->wrap) { - int index = currentIndex()+d->columns; - setCurrentIndex((index >= 0 && index < count) ? index : 0); - } - } else { - if (currentIndex() < count - 1 || d->wrap) { - int index = currentIndex() + 1; - setCurrentIndex((index >= 0 && index < count) ? index : 0); - } - } -} - -/*! - \qmlmethod QtQuick2::GridView::moveCurrentIndexLeft() - - Move the currentIndex left one item in the view. - The current index will wrap if keyNavigationWraps is true and it - is currently at the end. This method has no effect if the \l count is zero. - - \bold Note: methods should only be called after the Component has completed. -*/ -void QQuickGridView::moveCurrentIndexLeft() -{ - Q_D(QQuickGridView); - const int count = d->model ? d->model->count() : 0; - if (!count) - return; - if (effectiveLayoutDirection() == Qt::LeftToRight) { - if (d->flow == QQuickGridView::LeftToRight) { - if (currentIndex() > 0 || d->wrap) { - int index = currentIndex() - 1; - setCurrentIndex((index >= 0 && index < count) ? index : count-1); - } - } else { - if (currentIndex() >= d->columns || d->wrap) { - int index = currentIndex() - d->columns; - setCurrentIndex((index >= 0 && index < count) ? index : count-1); - } - } - } else { - if (d->flow == QQuickGridView::LeftToRight) { - if (currentIndex() < count - 1 || d->wrap) { - int index = currentIndex() + 1; - setCurrentIndex((index >= 0 && index < count) ? index : 0); - } - } else { - if (currentIndex() < count - d->columns || d->wrap) { - int index = currentIndex() + d->columns; - setCurrentIndex((index >= 0 && index < count) ? index : 0); - } - } - } -} - - -/*! - \qmlmethod QtQuick2::GridView::moveCurrentIndexRight() - - Move the currentIndex right one item in the view. - The current index will wrap if keyNavigationWraps is true and it - is currently at the end. This method has no effect if the \l count is zero. - - \bold Note: methods should only be called after the Component has completed. -*/ -void QQuickGridView::moveCurrentIndexRight() -{ - Q_D(QQuickGridView); - const int count = d->model ? d->model->count() : 0; - if (!count) - return; - if (effectiveLayoutDirection() == Qt::LeftToRight) { - if (d->flow == QQuickGridView::LeftToRight) { - if (currentIndex() < count - 1 || d->wrap) { - int index = currentIndex() + 1; - setCurrentIndex((index >= 0 && index < count) ? index : 0); - } - } else { - if (currentIndex() < count - d->columns || d->wrap) { - int index = currentIndex()+d->columns; - setCurrentIndex((index >= 0 && index < count) ? index : 0); - } - } - } else { - if (d->flow == QQuickGridView::LeftToRight) { - if (currentIndex() > 0 || d->wrap) { - int index = currentIndex() - 1; - setCurrentIndex((index >= 0 && index < count) ? index : count-1); - } - } else { - if (currentIndex() >= d->columns || d->wrap) { - int index = currentIndex() - d->columns; - setCurrentIndex((index >= 0 && index < count) ? index : count-1); - } - } - } -} - -bool QQuickGridViewPrivate::applyInsertionChange(const QDeclarativeChangeSet::Insert &change, FxViewItem *firstVisible, InsertionsResult *insertResult) -{ - Q_Q(QQuickGridView); - - int modelIndex = change.index; - int count = change.count; - - int index = visibleItems.count() ? mapFromModel(modelIndex) : 0; - - if (index < 0) { - int i = visibleItems.count() - 1; - while (i > 0 && visibleItems.at(i)->index == -1) - --i; - if (visibleItems.at(i)->index + 1 == modelIndex) { - // Special case of appending an item to the model. - index = visibleItems.count(); - } else { - if (modelIndex <= visibleIndex) { - // Insert before visible items - visibleIndex += count; - for (int i = 0; i < visibleItems.count(); ++i) { - FxViewItem *item = visibleItems.at(i); - if (item->index != -1 && item->index >= modelIndex) - item->index += count; - } - } - return true; - } - } - - qreal tempPos = isRightToLeftTopToBottom() ? -position()-size()+q->width()+1 : position(); - qreal colPos = 0; - qreal rowPos = 0; - int colNum = 0; - if (visibleItems.count()) { - if (index < visibleItems.count()) { - FxGridItemSG *gridItem = static_cast(visibleItems.at(index)); - colPos = gridItem->colPos(); - rowPos = gridItem->rowPos(); - colNum = qFloor((colPos+colSize()/2) / colSize()); - } else { - // appending items to visible list - FxGridItemSG *gridItem = static_cast(visibleItems.at(index-1)); - rowPos = gridItem->rowPos(); - colNum = qFloor((gridItem->colPos()+colSize()/2) / colSize()); - if (++colNum >= columns) { - colNum = 0; - rowPos += rowSize(); - } - colPos = colNum * colSize(); - } - } - - // Update the indexes of the following visible items. - for (int i = 0; i < visibleItems.count(); ++i) { - FxViewItem *item = visibleItems.at(i); - if (item->index != -1 && item->index >= modelIndex) - item->index += count; - } - - int prevAddedCount = insertResult->addedItems.count(); - if (firstVisible && rowPos < firstVisible->position()) { - // Insert items before the visible item. - int insertionIdx = index; - int i = count - 1; - int from = tempPos - buffer; - - while (i >= 0) { - if (rowPos > from && insertionIdx < visibleIndex) { - // item won't be visible, just note the size for repositioning - insertResult->sizeAddedBeforeVisible += rowSize(); - } else { - // item is before first visible e.g. in cache buffer - FxViewItem *item = 0; - if (change.isMove() && (item = currentChanges.removedItems.take(change.moveKey(modelIndex + i)))) { - if (item->index > modelIndex + i) - insertResult->movedBackwards.append(item); - item->index = modelIndex + i; - } - if (!item) - item = createItem(modelIndex + i); - if (!item) - return false; - - item->item->setVisible(true); - visibleItems.insert(insertionIdx, item); - if (!change.isMove()) { - insertResult->addedItems.append(item); - insertResult->sizeAddedBeforeVisible += rowSize(); - } - } - - if (--colNum < 0 ) { - colNum = columns - 1; - rowPos -= rowSize(); - } - colPos = colNum * colSize(); - index++; - i--; - } - } else { - int i = 0; - int to = buffer+tempPos+size()-1; - while (i < count && rowPos <= to + rowSize()*(columns - (colPos/colSize()))/qreal(columns)) { - FxViewItem *item = 0; - if (change.isMove() && (item = currentChanges.removedItems.take(change.moveKey(modelIndex + i)))) { - if (item->index > modelIndex + i) - insertResult->movedBackwards.append(item); - item->index = modelIndex + i; - } - if (!item) - item = createItem(modelIndex + i); - if (!item) - return false; - - item->item->setVisible(true); - visibleItems.insert(index, item); - if (!change.isMove()) - insertResult->addedItems.append(item); - if (++colNum >= columns) { - colNum = 0; - rowPos += rowSize(); - } - colPos = colNum * colSize(); - ++index; - ++i; - } - } - - updateVisibleIndex(); - - return insertResult->addedItems.count() > prevAddedCount; -} - -bool QQuickGridViewPrivate::needsRefillForAddedOrRemovedIndex(int modelIndex) const -{ - // If we add or remove items before visible items, a layout may be - // required to ensure item 0 is in the first column. - return modelIndex < visibleIndex; -} - -/*! - \qmlmethod QtQuick2::GridView::positionViewAtIndex(int index, PositionMode mode) - - Positions the view such that the \a index is at the position specified by - \a mode: - - \list - \o GridView.Beginning - position item at the top (or left for \c GridView.TopToBottom flow) of the view. - \o GridView.Center - position item in the center of the view. - \o GridView.End - position item at bottom (or right for horizontal orientation) of the view. - \o GridView.Visible - if any part of the item is visible then take no action, otherwise - bring the item into view. - \o GridView.Contain - ensure the entire item is visible. If the item is larger than - the view the item is positioned at the top (or left for \c GridView.TopToBottom flow) of the view. - \endlist - - If positioning the view at the index would cause empty space to be displayed at - the beginning or end of the view, the view will be positioned at the boundary. - - It is not recommended to use \l {Flickable::}{contentX} or \l {Flickable::}{contentY} to position the view - at a particular index. This is unreliable since removing items from the start - of the view does not cause all other items to be repositioned. - The correct way to bring an item into view is with \c positionViewAtIndex. - - \bold Note: methods should only be called after the Component has completed. To position - the view at startup, this method should be called by Component.onCompleted. For - example, to position the view at the end: - - \code - Component.onCompleted: positionViewAtIndex(count - 1, GridView.Beginning) - \endcode -*/ - -/*! - \qmlmethod QtQuick2::GridView::positionViewAtBeginning() - \qmlmethod QtQuick2::GridView::positionViewAtEnd() - - Positions the view at the beginning or end, taking into account any header or footer. - - It is not recommended to use \l {Flickable::}{contentX} or \l {Flickable::}{contentY} to position the view - at a particular index. This is unreliable since removing items from the start - of the list does not cause all other items to be repositioned, and because - the actual start of the view can vary based on the size of the delegates. - - \bold Note: methods should only be called after the Component has completed. To position - the view at startup, this method should be called by Component.onCompleted. For - example, to position the view at the end on startup: - - \code - Component.onCompleted: positionViewAtEnd() - \endcode -*/ - -/*! - \qmlmethod int QtQuick2::GridView::indexAt(int x, int y) - - Returns the index of the visible item containing the point \a x, \a y in content - coordinates. If there is no item at the point specified, or the item is - not visible -1 is returned. - - If the item is outside the visible area, -1 is returned, regardless of - whether an item will exist at that point when scrolled into view. - - \bold Note: methods should only be called after the Component has completed. -*/ - -QQuickGridViewAttached *QQuickGridView::qmlAttachedProperties(QObject *obj) -{ - return new QQuickGridViewAttached(obj); -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickgridview_p.h b/src/declarative/items/qquickgridview_p.h deleted file mode 100644 index b02c0a8350..0000000000 --- a/src/declarative/items/qquickgridview_p.h +++ /dev/null @@ -1,146 +0,0 @@ -// Commit: 95814418f9d6adeba365c795462e8afb00138211 -/**************************************************************************** -** -** 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$ -** 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 QQUICKGRIDVIEW_P_H -#define QQUICKGRIDVIEW_P_H - -#include "qquickitemview_p.h" - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QQuickVisualModel; -class QQuickGridViewAttached; -class QQuickGridViewPrivate; -class Q_AUTOTEST_EXPORT QQuickGridView : public QQuickItemView -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QQuickGridView) - - Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) - Q_PROPERTY(qreal cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged) - Q_PROPERTY(qreal cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged) - - Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged) - - Q_ENUMS(SnapMode) - Q_ENUMS(Flow) - Q_CLASSINFO("DefaultProperty", "data") - -public: - QQuickGridView(QQuickItem *parent=0); - ~QQuickGridView(); - - virtual void setHighlightFollowsCurrentItem(bool); - virtual void setHighlightMoveDuration(int); - - enum Flow { LeftToRight, TopToBottom }; - Flow flow() const; - void setFlow(Flow); - - qreal cellWidth() const; - void setCellWidth(qreal); - - qreal cellHeight() const; - void setCellHeight(qreal); - - enum SnapMode { NoSnap, SnapToRow, SnapOneRow }; - SnapMode snapMode() const; - void setSnapMode(SnapMode mode); - - static QQuickGridViewAttached *qmlAttachedProperties(QObject *); - -public Q_SLOTS: - void moveCurrentIndexUp(); - void moveCurrentIndexDown(); - void moveCurrentIndexLeft(); - void moveCurrentIndexRight(); - -Q_SIGNALS: - void cellWidthChanged(); - void cellHeightChanged(); - void highlightMoveDurationChanged(); - void flowChanged(); - void snapModeChanged(); - -protected: - virtual void viewportMoved(); - virtual void keyPressEvent(QKeyEvent *); -}; - -class QQuickGridViewAttached : public QQuickItemViewAttached -{ - Q_OBJECT -public: - QQuickGridViewAttached(QObject *parent) - : QQuickItemViewAttached(parent), m_view(0) {} - ~QQuickGridViewAttached() {} - - Q_PROPERTY(QQuickGridView *view READ view NOTIFY viewChanged) - QQuickGridView *view() { return m_view; } - void setView(QQuickGridView *view) { - if (view != m_view) { - m_view = view; - emit viewChanged(); - } - } - -Q_SIGNALS: - void viewChanged(); - -public: - QDeclarativeGuard m_view; -}; - - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickGridView) -QML_DECLARE_TYPEINFO(QQuickGridView, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif // QQUICKGRIDVIEW_P_H diff --git a/src/declarative/items/qquickimage.cpp b/src/declarative/items/qquickimage.cpp deleted file mode 100644 index 46b8ea0915..0000000000 --- a/src/declarative/items/qquickimage.cpp +++ /dev/null @@ -1,746 +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 QtDeclarative module 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 "qquickimage_p.h" -#include "qquickimage_p_p.h" - -#include - -#include -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickImageTextureProvider : public QSGTextureProvider -{ - Q_OBJECT -public: - QQuickImageTextureProvider() - : m_texture(0) - , m_smooth(false) - { - } - - QSGTexture *texture() const { - - if (m_texture && m_texture->isAtlasTexture()) - const_cast(this)->m_texture = m_texture->removedFromAtlas(); - - if (m_texture) { - m_texture->setFiltering(m_smooth ? QSGTexture::Linear : QSGTexture::Nearest); - m_texture->setMipmapFiltering(QSGTexture::Nearest); - m_texture->setHorizontalWrapMode(QSGTexture::ClampToEdge); - m_texture->setVerticalWrapMode(QSGTexture::ClampToEdge); - } - return m_texture; - } - - friend class QQuickImage; - - QSGTexture *m_texture; - bool m_smooth; -}; - -#include "qquickimage.moc" - -QQuickImagePrivate::QQuickImagePrivate() - : fillMode(QQuickImage::Stretch) - , paintedWidth(0) - , paintedHeight(0) - , pixmapChanged(false) - , hAlign(QQuickImage::AlignHCenter) - , vAlign(QQuickImage::AlignVCenter) - , provider(0) -{ -} - -/*! - \qmlclass Image QQuickImage - \inqmlmodule QtQuick 2 - \ingroup qml-basic-visual-elements - \brief The Image element displays an image in a declarative user interface - \inherits Item - - The Image element is used to display images in a declarative user interface. - - The source of the image is specified as a URL using the \l source property. - Images can be supplied in any of the standard image formats supported by Qt, - including bitmap formats such as PNG and JPEG, and vector graphics formats - such as SVG. If you need to display animated images, use the \l AnimatedImage - element. - - If the \l{Item::width}{width} and \l{Item::height}{height} properties are not - specified, the Image element automatically uses the size of the loaded image. - By default, specifying the width and height of the element causes the image - to be scaled to that size. This behavior can be changed by setting the - \l fillMode property, allowing the image to be stretched and tiled instead. - - \section1 Example Usage - - The following example shows the simplest usage of the Image element. - - \snippet doc/src/snippets/declarative/image.qml document - - \beginfloatleft - \image declarative-qtlogo.png - \endfloat - - \clearfloat - - \section1 Performance - - By default, locally available images are loaded immediately, and the user interface - is blocked until loading is complete. If a large image is to be loaded, it may be - preferable to load the image in a low priority thread, by enabling the \l asynchronous - property. - - If the image is obtained from a network rather than a local resource, it is - automatically loaded asynchronously, and the \l progress and \l status properties - are updated as appropriate. - - Images are cached and shared internally, so if several Image elements have the same \l source, - only one copy of the image will be loaded. - - \bold Note: Images are often the greatest user of memory in QML user interfaces. It is recommended - that images which do not form part of the user interface have their - size bounded via the \l sourceSize property. This is especially important for content - that is loaded from external sources or provided by the user. - - \sa {declarative/imageelements/image}{Image example}, QDeclarativeImageProvider -*/ - -QQuickImage::QQuickImage(QQuickItem *parent) - : QQuickImageBase(*(new QQuickImagePrivate), parent) -{ -} - -QQuickImage::QQuickImage(QQuickImagePrivate &dd, QQuickItem *parent) - : QQuickImageBase(dd, parent) -{ -} - -QQuickImage::~QQuickImage() -{ - Q_D(QQuickImage); - if (d->provider) - d->provider->deleteLater(); -} - -void QQuickImagePrivate::setImage(const QImage &image) -{ - Q_Q(QQuickImage); - pix.setImage(image); - - q->pixmapChange(); - status = pix.isNull() ? QQuickImageBase::Null : QQuickImageBase::Ready; - - q->update(); -} - -/*! - \qmlproperty enumeration QtQuick2::Image::fillMode - - Set this property to define what happens when the source image has a different size - than the item. - - \list - \o Image.Stretch - the image is scaled to fit - \o Image.PreserveAspectFit - the image is scaled uniformly to fit without cropping - \o Image.PreserveAspectCrop - the image is scaled uniformly to fill, cropping if necessary - \o Image.Tile - the image is duplicated horizontally and vertically - \o Image.TileVertically - the image is stretched horizontally and tiled vertically - \o Image.TileHorizontally - the image is stretched vertically and tiled horizontally - \o Image.Pad - the image is not transformed - \endlist - - \table - - \row - \o \image declarative-qtlogo-stretch.png - \o Stretch (default) - \qml - Image { - width: 130; height: 100 - smooth: true - source: "qtlogo.png" - } - \endqml - - \row - \o \image declarative-qtlogo-preserveaspectfit.png - \o PreserveAspectFit - \qml - Image { - width: 130; height: 100 - fillMode: Image.PreserveAspectFit - smooth: true - source: "qtlogo.png" - } - \endqml - - \row - \o \image declarative-qtlogo-preserveaspectcrop.png - \o PreserveAspectCrop - \qml - Image { - width: 130; height: 100 - fillMode: Image.PreserveAspectCrop - smooth: true - source: "qtlogo.png" - clip: true - } - \endqml - - \row - \o \image declarative-qtlogo-tile.png - \o Tile - \qml - Image { - width: 120; height: 120 - fillMode: Image.Tile - source: "qtlogo.png" - } - \endqml - - \row - \o \image declarative-qtlogo-tilevertically.png - \o TileVertically - \qml - Image { - width: 120; height: 120 - fillMode: Image.TileVertically - smooth: true - source: "qtlogo.png" - } - \endqml - - \row - \o \image declarative-qtlogo-tilehorizontally.png - \o TileHorizontally - \qml - Image { - width: 120; height: 120 - fillMode: Image.TileHorizontally - smooth: true - source: "qtlogo.png" - } - \endqml - - \endtable - - Note that \c clip is \c false by default which means that the element might - paint outside its bounding rectangle even if the fillMode is set to \c PreserveAspectCrop. - - \sa {declarative/imageelements/image}{Image example} -*/ -QQuickImage::FillMode QQuickImage::fillMode() const -{ - Q_D(const QQuickImage); - return d->fillMode; -} - -void QQuickImage::setFillMode(FillMode mode) -{ - Q_D(QQuickImage); - if (d->fillMode == mode) - return; - d->fillMode = mode; - update(); - updatePaintedGeometry(); - emit fillModeChanged(); -} - -/*! - - \qmlproperty real QtQuick2::Image::paintedWidth - \qmlproperty real QtQuick2::Image::paintedHeight - - These properties hold the size of the image that is actually painted. - In most cases it is the same as \c width and \c height, but when using a - \c fillMode \c PreserveAspectFit or \c fillMode \c PreserveAspectCrop - \c paintedWidth or \c paintedHeight can be smaller or larger than - \c width and \c height of the Image element. -*/ -qreal QQuickImage::paintedWidth() const -{ - Q_D(const QQuickImage); - return d->paintedWidth; -} - -qreal QQuickImage::paintedHeight() const -{ - Q_D(const QQuickImage); - return d->paintedHeight; -} - -/*! - \qmlproperty enumeration QtQuick2::Image::status - - This property holds the status of image loading. It can be one of: - \list - \o Image.Null - no image has been set - \o Image.Ready - the image has been loaded - \o Image.Loading - the image is currently being loaded - \o Image.Error - an error occurred while loading the image - \endlist - - Use this status to provide an update or respond to the status change in some way. - For example, you could: - - \list - \o Trigger a state change: - \qml - State { name: 'loaded'; when: image.status == Image.Ready } - \endqml - - \o Implement an \c onStatusChanged signal handler: - \qml - Image { - id: image - onStatusChanged: if (image.status == Image.Ready) console.log('Loaded') - } - \endqml - - \o Bind to the status value: - \qml - Text { text: image.status == Image.Ready ? 'Loaded' : 'Not loaded' } - \endqml - \endlist - - \sa progress -*/ - -/*! - \qmlproperty real QtQuick2::Image::progress - - This property holds the progress of image loading, from 0.0 (nothing loaded) - to 1.0 (finished). - - \sa status -*/ - -/*! - \qmlproperty bool QtQuick2::Image::smooth - - Set this property if you want the image to be smoothly filtered when scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If - the image is displayed at its natural size, this property has no visual or - performance effect. - - \note Generally scaling artifacts are only visible if the image is stationary on - the screen. A common pattern when animating an image is to disable smooth - filtering at the beginning of the animation and reenable it at the conclusion. -*/ - -/*! - \qmlproperty QSize QtQuick2::Image::sourceSize - - This property holds the actual width and height of the loaded image. - - Unlike the \l {Item::}{width} and \l {Item::}{height} properties, which scale - the painting of the image, this property sets the actual number of pixels - stored for the loaded image so that large images do not use more - memory than necessary. For example, this ensures the image in memory is no - larger than 1024x1024 pixels, regardless of the Image's \l {Item::}{width} and - \l {Item::}{height} values: - - \code - Rectangle { - width: ... - height: ... - - Image { - anchors.fill: parent - source: "reallyBigImage.jpg" - sourceSize.width: 1024 - sourceSize.height: 1024 - } - } - \endcode - - If the image's actual size is larger than the sourceSize, the image is scaled down. - If only one dimension of the size is set to greater than 0, the - other dimension is set in proportion to preserve the source image's aspect ratio. - (The \l fillMode is independent of this.) - - If the source is an intrinsically scalable image (eg. SVG), this property - determines the size of the loaded image regardless of intrinsic size. - Avoid changing this property dynamically; rendering an SVG is \e slow compared - to an image. - - If the source is a non-scalable image (eg. JPEG), the loaded image will - be no greater than this property specifies. For some formats (currently only JPEG), - the whole image will never actually be loaded into memory. - - Since QtQuick 1.1 the sourceSize can be cleared to the natural size of the image - by setting sourceSize to \c undefined. - - \note \e {Changing this property dynamically causes the image source to be reloaded, - potentially even from the network, if it is not in the disk cache.} -*/ - -/*! - \qmlproperty url QtQuick2::Image::source - - Image can handle any image format supported by Qt, loaded from any URL scheme supported by Qt. - - The URL may be absolute, or relative to the URL of the component. - - \sa QDeclarativeImageProvider -*/ - -/*! - \qmlproperty bool QtQuick2::Image::asynchronous - - Specifies that images on the local filesystem should be loaded - asynchronously in a separate thread. The default value is - false, causing the user interface thread to block while the - image is loaded. Setting \a asynchronous to true is useful where - maintaining a responsive user interface is more desirable - than having images immediately visible. - - Note that this property is only valid for images read from the - local filesystem. Images loaded via a network resource (e.g. HTTP) - are always loaded asynchronously. -*/ - -/*! - \qmlproperty bool QtQuick2::Image::cache - - Specifies whether the image should be cached. The default value is - true. Setting \a cache to false is useful when dealing with large images, - to make sure that they aren't cached at the expense of small 'ui element' images. -*/ - -/*! - \qmlproperty bool QtQuick2::Image::mirror - - This property holds whether the image should be horizontally inverted - (effectively displaying a mirrored image). - - The default value is false. -*/ - -/*! - \qmlproperty enumeration QtQuick2::Image::horizontalAlignment - \qmlproperty enumeration QtQuick2::Image::verticalAlignment - - Sets the horizontal and vertical alignment of the image. By default, the image is top-left aligned. - - The valid values for \c horizontalAlignment are \c Image.AlignLeft, \c Image.AlignRight and \c Image.AlignHCenter. - The valid values for \c verticalAlignment are \c Image.AlignTop, \c Image.AlignBottom - and \c Image.AlignVCenter. -*/ -void QQuickImage::updatePaintedGeometry() -{ - Q_D(QQuickImage); - - if (d->fillMode == PreserveAspectFit) { - if (!d->pix.width() || !d->pix.height()) { - setImplicitSize(0, 0); - return; - } - qreal w = widthValid() ? width() : d->pix.width(); - qreal widthScale = w / qreal(d->pix.width()); - qreal h = heightValid() ? height() : d->pix.height(); - qreal heightScale = h / qreal(d->pix.height()); - if (widthScale <= heightScale) { - d->paintedWidth = w; - d->paintedHeight = widthScale * qreal(d->pix.height()); - } else if (heightScale < widthScale) { - d->paintedWidth = heightScale * qreal(d->pix.width()); - d->paintedHeight = h; - } - qreal iHeight = (widthValid() && !heightValid()) ? d->paintedHeight : d->pix.height(); - qreal iWidth = (heightValid() && !widthValid()) ? d->paintedWidth : d->pix.width(); - setImplicitSize(iWidth, iHeight); - - } else if (d->fillMode == PreserveAspectCrop) { - if (!d->pix.width() || !d->pix.height()) - return; - qreal widthScale = width() / qreal(d->pix.width()); - qreal heightScale = height() / qreal(d->pix.height()); - if (widthScale < heightScale) { - widthScale = heightScale; - } else if (heightScale < widthScale) { - heightScale = widthScale; - } - - d->paintedHeight = heightScale * qreal(d->pix.height()); - d->paintedWidth = widthScale * qreal(d->pix.width()); - } else if (d->fillMode == Pad) { - d->paintedWidth = d->pix.width(); - d->paintedHeight = d->pix.height(); - } else { - d->paintedWidth = width(); - d->paintedHeight = height(); - } - emit paintedGeometryChanged(); -} - -void QQuickImage::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - QQuickImageBase::geometryChanged(newGeometry, oldGeometry); - updatePaintedGeometry(); -} - -QRectF QQuickImage::boundingRect() const -{ - Q_D(const QQuickImage); - return QRectF(0, 0, qMax(width(), d->paintedWidth), qMax(height(), d->paintedHeight)); -} - -QSGTextureProvider *QQuickImage::textureProvider() const -{ - Q_D(const QQuickImage); - if (!d->provider) { - // Make sure it gets thread affinity on the rendering thread so deletion works properly.. - Q_ASSERT_X(d->canvas - && d->sceneGraphContext() - && QThread::currentThread() == d->sceneGraphContext()->thread(), - "QQuickImage::textureProvider", - "Cannot be used outside the GUI thread"); - QQuickImagePrivate *dd = const_cast(d); - dd->provider = new QQuickImageTextureProvider; - dd->provider->m_smooth = d->smooth; - dd->provider->m_texture = d->sceneGraphContext()->textureForFactory(d->pix.textureFactory()); - } - - return d->provider; -} - -QSGNode *QQuickImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - Q_D(QQuickImage); - - QSGTexture *texture = d->sceneGraphContext()->textureForFactory(d->pix.textureFactory()); - - // Copy over the current texture state into the texture provider... - if (d->provider) { - d->provider->m_smooth = d->smooth; - d->provider->m_texture = texture; - } - - if (!texture || width() <= 0 || height() <= 0) { - delete oldNode; - return 0; - } - - QSGImageNode *node = static_cast(oldNode); - if (!node) { - d->pixmapChanged = true; - node = d->sceneGraphContext()->createImageNode(); - node->setTexture(texture); - } - - if (d->pixmapChanged) { - // force update the texture in the node to trigger reconstruction of - // geometry and the likes when a atlas segment has changed. - node->setTexture(0); - node->setTexture(texture); - d->pixmapChanged = false; - } - - QRectF targetRect; - QRectF sourceRect; - QSGTexture::WrapMode hWrap = QSGTexture::ClampToEdge; - QSGTexture::WrapMode vWrap = QSGTexture::ClampToEdge; - - qreal pixWidth = (d->fillMode == PreserveAspectFit) ? d->paintedWidth : d->pix.width(); - qreal pixHeight = (d->fillMode == PreserveAspectFit) ? d->paintedHeight : d->pix.height(); - - int xOffset = 0; - if (d->hAlign == QQuickImage::AlignHCenter) - xOffset = qCeil((width() - pixWidth) / 2.); - else if (d->hAlign == QQuickImage::AlignRight) - xOffset = qCeil(width() - pixWidth); - - int yOffset = 0; - if (d->vAlign == QQuickImage::AlignVCenter) - yOffset = qCeil((height() - pixHeight) / 2.); - else if (d->vAlign == QQuickImage::AlignBottom) - yOffset = qCeil(height() - pixHeight); - - switch (d->fillMode) { - default: - case Stretch: - targetRect = QRectF(0, 0, width(), height()); - sourceRect = d->pix.rect(); - break; - - case PreserveAspectFit: - targetRect = QRectF(xOffset, yOffset, d->paintedWidth, d->paintedHeight); - sourceRect = d->pix.rect(); - break; - - case PreserveAspectCrop: { - targetRect = QRect(0, 0, width(), height()); - qreal wscale = width() / qreal(d->pix.width()); - qreal hscale = height() / qreal(d->pix.height()); - - if (wscale > hscale) { - int src = (hscale / wscale) * qreal(d->pix.height()); - int y = 0; - if (d->vAlign == QQuickImage::AlignVCenter) - y = qCeil((d->pix.height() - src) / 2.); - else if (d->vAlign == QQuickImage::AlignBottom) - y = qCeil(d->pix.height() - src); - sourceRect = QRectF(0, y, d->pix.width(), src); - - } else { - int src = (wscale / hscale) * qreal(d->pix.width()); - int x = 0; - if (d->hAlign == QQuickImage::AlignHCenter) - x = qCeil((d->pix.width() - src) / 2.); - else if (d->hAlign == QQuickImage::AlignRight) - x = qCeil(d->pix.width() - src); - sourceRect = QRectF(x, 0, src, d->pix.height()); - } - } - break; - - case Tile: - targetRect = QRectF(0, 0, width(), height()); - sourceRect = QRectF(-xOffset, -yOffset, width(), height()); - hWrap = QSGTexture::Repeat; - vWrap = QSGTexture::Repeat; - break; - - case TileHorizontally: - targetRect = QRectF(0, 0, width(), height()); - sourceRect = QRectF(-xOffset, 0, width(), d->pix.height()); - hWrap = QSGTexture::Repeat; - break; - - case TileVertically: - targetRect = QRectF(0, 0, width(), height()); - sourceRect = QRectF(0, -yOffset, d->pix.width(), height()); - vWrap = QSGTexture::Repeat; - break; - - case Pad: - qreal w = qMin(qreal(d->pix.width()), width()); - qreal h = qMin(qreal(d->pix.height()), height()); - qreal x = (d->pix.width() > width()) ? -xOffset : 0; - qreal y = (d->pix.height() > height()) ? -yOffset : 0; - targetRect = QRectF(x + xOffset, y + yOffset, w, h); - sourceRect = QRectF(x, y, w, h); - break; - }; - - QRectF nsrect(sourceRect.x() / d->pix.width(), - sourceRect.y() / d->pix.height(), - sourceRect.width() / d->pix.width(), - sourceRect.height() / d->pix.height()); - - if (d->mirror) { - qreal oldLeft = nsrect.left(); - nsrect.setLeft(nsrect.right()); - nsrect.setRight(oldLeft); - } - - node->setHorizontalWrapMode(hWrap); - node->setVerticalWrapMode(vWrap); - node->setFiltering(d->smooth ? QSGTexture::Linear : QSGTexture::Nearest); - - node->setTargetRect(targetRect); - node->setSourceRect(nsrect); - node->update(); - - return node; -} - -void QQuickImage::pixmapChange() -{ - Q_D(QQuickImage); - // PreserveAspectFit calculates the implicit size differently so we - // don't call our superclass pixmapChange(), since that would - // result in the implicit size being set incorrectly, then updated - // in updatePaintedGeometry() - if (d->fillMode != PreserveAspectFit) - QQuickImageBase::pixmapChange(); - updatePaintedGeometry(); - d->pixmapChanged = true; - - // When the pixmap changes, such as being deleted, we need to update the textures - update(); -} - -QQuickImage::VAlignment QQuickImage::verticalAlignment() const -{ - Q_D(const QQuickImage); - return d->vAlign; -} - -void QQuickImage::setVerticalAlignment(VAlignment align) -{ - Q_D(QQuickImage); - if (d->vAlign == align) - return; - - d->vAlign = align; - update(); - updatePaintedGeometry(); - emit verticalAlignmentChanged(align); -} - -QQuickImage::HAlignment QQuickImage::horizontalAlignment() const -{ - Q_D(const QQuickImage); - return d->hAlign; -} - -void QQuickImage::setHorizontalAlignment(HAlignment align) -{ - Q_D(QQuickImage); - if (d->hAlign == align) - return; - - d->hAlign = align; - update(); - updatePaintedGeometry(); - emit horizontalAlignmentChanged(align); -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickimage_p.h b/src/declarative/items/qquickimage_p.h deleted file mode 100644 index 0d1c8dcba3..0000000000 --- a/src/declarative/items/qquickimage_p.h +++ /dev/null @@ -1,122 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKIMAGE_P_H -#define QQUICKIMAGE_P_H - -#include "qquickimagebase_p.h" -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickImagePrivate; -class Q_AUTOTEST_EXPORT QQuickImage : public QQuickImageBase -{ - Q_OBJECT - Q_ENUMS(FillMode) - Q_ENUMS(HAlignment) - Q_ENUMS(VAlignment) - - Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) - Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedGeometryChanged) - Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedGeometryChanged) - Q_PROPERTY(HAlignment horizontalAlignment READ horizontalAlignment WRITE setHorizontalAlignment NOTIFY horizontalAlignmentChanged) - Q_PROPERTY(VAlignment verticalAlignment READ verticalAlignment WRITE setVerticalAlignment NOTIFY verticalAlignmentChanged) - -public: - QQuickImage(QQuickItem *parent=0); - ~QQuickImage(); - - enum HAlignment { AlignLeft = Qt::AlignLeft, - AlignRight = Qt::AlignRight, - AlignHCenter = Qt::AlignHCenter }; - enum VAlignment { AlignTop = Qt::AlignTop, - AlignBottom = Qt::AlignBottom, - AlignVCenter = Qt::AlignVCenter }; - - enum FillMode { Stretch, PreserveAspectFit, PreserveAspectCrop, Tile, TileVertically, TileHorizontally, Pad }; - - FillMode fillMode() const; - void setFillMode(FillMode); - - qreal paintedWidth() const; - qreal paintedHeight() const; - - QRectF boundingRect() const; - - HAlignment horizontalAlignment() const; - void setHorizontalAlignment(HAlignment align); - - VAlignment verticalAlignment() const; - void setVerticalAlignment(VAlignment align); - - bool isTextureProvider() const { return true; } - QSGTextureProvider *textureProvider() const; - -Q_SIGNALS: - void fillModeChanged(); - void paintedGeometryChanged(); - void horizontalAlignmentChanged(HAlignment alignment); - void verticalAlignmentChanged(VAlignment alignment); - -protected: - QQuickImage(QQuickImagePrivate &dd, QQuickItem *parent); - void pixmapChange(); - void updatePaintedGeometry(); - - virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); - virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - -private: - Q_DISABLE_COPY(QQuickImage) - Q_DECLARE_PRIVATE(QQuickImage) -}; - -QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickImage) -QT_END_HEADER - -#endif // QQUICKIMAGE_P_H diff --git a/src/declarative/items/qquickimage_p_p.h b/src/declarative/items/qquickimage_p_p.h deleted file mode 100644 index 2077dfb0b3..0000000000 --- a/src/declarative/items/qquickimage_p_p.h +++ /dev/null @@ -1,85 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKIMAGE_P_P_H -#define QQUICKIMAGE_P_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 "qquickimagebase_p_p.h" -#include "qquickimage_p.h" - -QT_BEGIN_NAMESPACE - -class QQuickImageTextureProvider; - -class QQuickImagePrivate : public QQuickImageBasePrivate -{ - Q_DECLARE_PUBLIC(QQuickImage) - -public: - QQuickImagePrivate(); - - QQuickImage::FillMode fillMode; - qreal paintedWidth; - qreal paintedHeight; - void setImage(const QImage &img); - - bool pixmapChanged : 1; - QQuickImage::HAlignment hAlign; - QQuickImage::VAlignment vAlign; - - QQuickImageTextureProvider *provider; -}; - -QT_END_NAMESPACE - -#endif // QQUICKIMAGE_P_P_H diff --git a/src/declarative/items/qquickimagebase.cpp b/src/declarative/items/qquickimagebase.cpp deleted file mode 100644 index d0e495eff5..0000000000 --- a/src/declarative/items/qquickimagebase.cpp +++ /dev/null @@ -1,290 +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 QtDeclarative module 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 "qquickimagebase_p.h" -#include "qquickimagebase_p_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickImageBase::QQuickImageBase(QQuickItem *parent) -: QQuickImplicitSizeItem(*(new QQuickImageBasePrivate), parent) -{ - setFlag(ItemHasContents); -} - -QQuickImageBase::QQuickImageBase(QQuickImageBasePrivate &dd, QQuickItem *parent) -: QQuickImplicitSizeItem(dd, parent) -{ - setFlag(ItemHasContents); -} - -QQuickImageBase::~QQuickImageBase() -{ -} - -QQuickImageBase::Status QQuickImageBase::status() const -{ - Q_D(const QQuickImageBase); - return d->status; -} - - -qreal QQuickImageBase::progress() const -{ - Q_D(const QQuickImageBase); - return d->progress; -} - - -bool QQuickImageBase::asynchronous() const -{ - Q_D(const QQuickImageBase); - return d->async; -} - -void QQuickImageBase::setAsynchronous(bool async) -{ - Q_D(QQuickImageBase); - if (d->async != async) { - d->async = async; - emit asynchronousChanged(); - } -} - -QUrl QQuickImageBase::source() const -{ - Q_D(const QQuickImageBase); - return d->url; -} - -void QQuickImageBase::setSource(const QUrl &url) -{ - Q_D(QQuickImageBase); - //equality is fairly expensive, so we bypass for simple, common case - if ((d->url.isEmpty() == url.isEmpty()) && url == d->url) - return; - - d->url = url; - emit sourceChanged(d->url); - - if (isComponentComplete()) - load(); -} - -void QQuickImageBase::setSourceSize(const QSize& size) -{ - Q_D(QQuickImageBase); - if (d->sourcesize == size) - return; - - d->sourcesize = size; - d->explicitSourceSize = true; - emit sourceSizeChanged(); - if (isComponentComplete()) - load(); -} - -QSize QQuickImageBase::sourceSize() const -{ - Q_D(const QQuickImageBase); - - int width = d->sourcesize.width(); - int height = d->sourcesize.height(); - return QSize(width != -1 ? width : d->pix.width(), height != -1 ? height : d->pix.height()); -} - -void QQuickImageBase::resetSourceSize() -{ - Q_D(QQuickImageBase); - if (!d->explicitSourceSize) - return; - d->explicitSourceSize = false; - d->sourcesize = QSize(); - emit sourceSizeChanged(); - if (isComponentComplete()) - load(); -} - -bool QQuickImageBase::cache() const -{ - Q_D(const QQuickImageBase); - return d->cache; -} - -void QQuickImageBase::setCache(bool cache) -{ - Q_D(QQuickImageBase); - if (d->cache == cache) - return; - - d->cache = cache; - emit cacheChanged(); - if (isComponentComplete()) - load(); -} - -QImage QQuickImageBase::image() const -{ - Q_D(const QQuickImageBase); - return d->pix.image(); -} - -void QQuickImageBase::setMirror(bool mirror) -{ - Q_D(QQuickImageBase); - if (mirror == d->mirror) - return; - - d->mirror = mirror; - - if (isComponentComplete()) - update(); - - emit mirrorChanged(); -} - -bool QQuickImageBase::mirror() const -{ - Q_D(const QQuickImageBase); - return d->mirror; -} - -void QQuickImageBase::load() -{ - Q_D(QQuickImageBase); - - if (d->url.isEmpty()) { - d->pix.clear(this); - d->status = Null; - d->progress = 0.0; - pixmapChange(); - emit progressChanged(d->progress); - emit statusChanged(d->status); - update(); - } else { - QDeclarativePixmap::Options options; - if (d->async) - options |= QDeclarativePixmap::Asynchronous; - if (d->cache) - options |= QDeclarativePixmap::Cache; - d->pix.clear(this); - pixmapChange(); - d->pix.load(qmlEngine(this), d->url, d->explicitSourceSize ? sourceSize() : QSize(), options); - - if (d->pix.isLoading()) { - d->progress = 0.0; - d->status = Loading; - emit progressChanged(d->progress); - emit statusChanged(d->status); - - static int thisRequestProgress = -1; - static int thisRequestFinished = -1; - if (thisRequestProgress == -1) { - thisRequestProgress = - QQuickImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); - thisRequestFinished = - QQuickImageBase::staticMetaObject.indexOfSlot("requestFinished()"); - } - - d->pix.connectFinished(this, thisRequestFinished); - d->pix.connectDownloadProgress(this, thisRequestProgress); - - } else { - requestFinished(); - } - } -} - -void QQuickImageBase::requestFinished() -{ - Q_D(QQuickImageBase); - - QQuickImageBase::Status oldStatus = d->status; - qreal oldProgress = d->progress; - - if (d->pix.isError()) { - d->status = Error; - qmlInfo(this) << d->pix.error(); - } else { - d->status = Ready; - } - - d->progress = 1.0; - - pixmapChange(); - - if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height()) - emit sourceSizeChanged(); - - if (d->status != oldStatus) - emit statusChanged(d->status); - if (d->progress != oldProgress) - emit progressChanged(d->progress); - - update(); -} - -void QQuickImageBase::requestProgress(qint64 received, qint64 total) -{ - Q_D(QQuickImageBase); - if (d->status == Loading && total > 0) { - d->progress = qreal(received)/total; - emit progressChanged(d->progress); - } -} - -void QQuickImageBase::componentComplete() -{ - Q_D(QQuickImageBase); - QQuickItem::componentComplete(); - if (d->url.isValid()) - load(); -} - -void QQuickImageBase::pixmapChange() -{ - Q_D(QQuickImageBase); - setImplicitSize(d->pix.width(), d->pix.height()); -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickimagebase_p.h b/src/declarative/items/qquickimagebase_p.h deleted file mode 100644 index 51b5f088d4..0000000000 --- a/src/declarative/items/qquickimagebase_p.h +++ /dev/null @@ -1,119 +0,0 @@ -// Commit: af05f64d3edc860c3cf79c7f0bdf2377faae5f40 -/**************************************************************************** -** -** 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$ -** 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 QQUICKIMAGEBASE_P_H -#define QQUICKIMAGEBASE_P_H - -#include "qquickimplicitsizeitem_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QQuickImageBasePrivate; -class Q_AUTOTEST_EXPORT QQuickImageBase : public QQuickImplicitSizeItem -{ - Q_OBJECT - Q_ENUMS(Status) - - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged) - Q_PROPERTY(bool cache READ cache WRITE setCache NOTIFY cacheChanged) - Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize RESET resetSourceSize NOTIFY sourceSizeChanged) - Q_PROPERTY(bool mirror READ mirror WRITE setMirror NOTIFY mirrorChanged) - -public: - QQuickImageBase(QQuickItem *parent=0); - ~QQuickImageBase(); - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - - QUrl source() const; - virtual void setSource(const QUrl &url); - - bool asynchronous() const; - void setAsynchronous(bool); - - bool cache() const; - void setCache(bool); - - QImage image() const; - - virtual void setSourceSize(const QSize&); - QSize sourceSize() const; - void resetSourceSize(); - - virtual void setMirror(bool mirror); - bool mirror() const; - -Q_SIGNALS: - void sourceChanged(const QUrl &); - void sourceSizeChanged(); - void statusChanged(QQuickImageBase::Status); - void progressChanged(qreal progress); - void asynchronousChanged(); - void cacheChanged(); - void mirrorChanged(); - -protected: - virtual void load(); - virtual void componentComplete(); - virtual void pixmapChange(); - QQuickImageBase(QQuickImageBasePrivate &dd, QQuickItem *parent); - -private Q_SLOTS: - virtual void requestFinished(); - void requestProgress(qint64,qint64); - -private: - Q_DISABLE_COPY(QQuickImageBase) - Q_DECLARE_PRIVATE(QQuickImageBase) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QQUICKIMAGEBASE_P_H diff --git a/src/declarative/items/qquickimagebase_p_p.h b/src/declarative/items/qquickimagebase_p_p.h deleted file mode 100644 index 2347a82e92..0000000000 --- a/src/declarative/items/qquickimagebase_p_p.h +++ /dev/null @@ -1,93 +0,0 @@ -// Commit: 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4 -/**************************************************************************** -** -** 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$ -** 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 QQUICKIMAGEBASE_P_P_H -#define QQUICKIMAGEBASE_P_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 "qquickimplicitsizeitem_p_p.h" -#include "qquickimagebase_p.h" - -#include - -QT_BEGIN_NAMESPACE - -class QNetworkReply; -class QQuickImageBasePrivate : public QQuickImplicitSizeItemPrivate -{ - Q_DECLARE_PUBLIC(QQuickImageBase) - -public: - QQuickImageBasePrivate() - : status(QQuickImageBase::Null), - progress(0.0), - explicitSourceSize(false), - async(false), - cache(true), - mirror(false) - { - } - - QDeclarativePixmap pix; - QQuickImageBase::Status status; - QUrl url; - qreal progress; - QSize sourcesize; - bool explicitSourceSize : 1; - bool async : 1; - bool cache : 1; - bool mirror: 1; -}; - -QT_END_NAMESPACE - -#endif // QQUICKIMAGEBASE_P_P_H diff --git a/src/declarative/items/qquickimplicitsizeitem.cpp b/src/declarative/items/qquickimplicitsizeitem.cpp deleted file mode 100644 index b0c5826349..0000000000 --- a/src/declarative/items/qquickimplicitsizeitem.cpp +++ /dev/null @@ -1,64 +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 QtDeclarative module 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 "qquickimplicitsizeitem_p.h" -#include "qquickimplicitsizeitem_p_p.h" - -QT_BEGIN_NAMESPACE - -void QQuickImplicitSizeItemPrivate::implicitWidthChanged() -{ - Q_Q(QQuickImplicitSizeItem); - emit q->implicitWidthChanged(); -} - -void QQuickImplicitSizeItemPrivate::implicitHeightChanged() -{ - Q_Q(QQuickImplicitSizeItem); - emit q->implicitHeightChanged(); -} - -QQuickImplicitSizeItem::QQuickImplicitSizeItem(QQuickImplicitSizeItemPrivate &dd, QQuickItem *parent) - : QQuickItem(dd, parent) -{ -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickimplicitsizeitem_p.h b/src/declarative/items/qquickimplicitsizeitem_p.h deleted file mode 100644 index 9ca98e1d60..0000000000 --- a/src/declarative/items/qquickimplicitsizeitem_p.h +++ /dev/null @@ -1,75 +0,0 @@ -// Commit: 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4 -/**************************************************************************** -** -** 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$ -** 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 QQUICKIMPLICITSIZEITEM_H -#define QQUICKIMPLICITSIZEITEM_H - -#include "qquickpainteditem.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QQuickImplicitSizeItemPrivate; -class Q_AUTOTEST_EXPORT QQuickImplicitSizeItem : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(qreal implicitWidth READ implicitWidth NOTIFY implicitWidthChanged) - Q_PROPERTY(qreal implicitHeight READ implicitHeight NOTIFY implicitHeightChanged) - -protected: - QQuickImplicitSizeItem(QQuickImplicitSizeItemPrivate &dd, QQuickItem *parent); - -Q_SIGNALS: - void implicitWidthChanged(); - void implicitHeightChanged(); - -private: - Q_DISABLE_COPY(QQuickImplicitSizeItem) - Q_DECLARE_PRIVATE(QQuickImplicitSizeItem) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QQUICKIMPLICITSIZEITEM_H diff --git a/src/declarative/items/qquickimplicitsizeitem_p_p.h b/src/declarative/items/qquickimplicitsizeitem_p_p.h deleted file mode 100644 index 17c204d7c3..0000000000 --- a/src/declarative/items/qquickimplicitsizeitem_p_p.h +++ /dev/null @@ -1,78 +0,0 @@ -// Commit: 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4 -/**************************************************************************** -** -** 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$ -** 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 QQUICKIMPLICITSIZEITEM_P_H -#define QQUICKIMPLICITSIZEITEM_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 "qquickitem_p.h" -#include "qquickpainteditem_p.h" -#include "qquickimplicitsizeitem_p.h" - -QT_BEGIN_NAMESPACE - -class QQuickImplicitSizeItemPrivate : public QQuickItemPrivate -{ - Q_DECLARE_PUBLIC(QQuickImplicitSizeItem) - -public: - QQuickImplicitSizeItemPrivate() - { - } - - virtual void implicitWidthChanged(); - virtual void implicitHeightChanged(); -}; - -QT_END_NAMESPACE - -#endif // QQUICKIMPLICITSIZEITEM_P_H diff --git a/src/declarative/items/qquickitem.cpp b/src/declarative/items/qquickitem.cpp deleted file mode 100644 index 9c11196944..0000000000 --- a/src/declarative/items/qquickitem.cpp +++ /dev/null @@ -1,5236 +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 QtDeclarative module 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 "qquickitem.h" - -#include "qquickcanvas.h" -#include -#include "qquickcanvas_p.h" - -#include "qquickevents_p_p.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -// XXX todo Readd parentNotifier for faster parent bindings -// XXX todo Check that elements that create items handle memory correctly after visual ownership change - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass Transform QQuickTransform - \inqmlmodule QtQuick 2 - \ingroup qml-transform-elements - \brief The Transform elements provide a way of building advanced transformations on Items. - - The Transform element is a base type which cannot be instantiated directly. - The following concrete Transform types are available: - - \list - \o \l Rotation - \o \l Scale - \o \l Translate - \endlist - - The Transform elements let you create and control advanced transformations that can be configured - independently using specialized properties. - - You can assign any number of Transform elements to an \l Item. Each Transform is applied in order, - one at a time. -*/ - -/*! - \qmlclass Translate QQuickTranslate - \inqmlmodule QtQuick 2 - \ingroup qml-transform-elements - \brief The Translate object provides a way to move an Item without changing its x or y properties. - - The Translate object provides independent control over position in addition to the Item's x and y properties. - - The following example moves the Y axis of the \l Rectangle elements while still allowing the \l Row element - to lay the items out as if they had not been transformed: - \qml - import QtQuick 1.0 - - Row { - Rectangle { - width: 100; height: 100 - color: "blue" - transform: Translate { y: 20 } - } - Rectangle { - width: 100; height: 100 - color: "red" - transform: Translate { y: -20 } - } - } - \endqml - - \image translate.png -*/ - -/*! - \qmlproperty real QtQuick2::Translate::x - - The translation along the X axis. -*/ - -/*! - \qmlproperty real QtQuick2::Translate::y - - The translation along the Y axis. -*/ - -/*! - \qmlclass Scale QQuickScale - \inqmlmodule QtQuick 2 - \ingroup qml-transform-elements - \brief The Scale element provides a way to scale an Item. - - The Scale element gives more control over scaling than using \l Item's \l{Item::scale}{scale} property. Specifically, - it allows a different scale for the x and y axes, and allows the scale to be relative to an - arbitrary point. - - The following example scales the X axis of the Rectangle, relative to its interior point 25, 25: - \qml - Rectangle { - width: 100; height: 100 - color: "blue" - transform: Scale { origin.x: 25; origin.y: 25; xScale: 3} - } - \endqml - - \sa Rotation, Translate -*/ - -/*! - \qmlproperty real QtQuick2::Scale::origin.x - \qmlproperty real QtQuick2::Scale::origin.y - - The point that the item is scaled from (i.e., the point that stays fixed relative to the parent as - the rest of the item grows). By default the origin is 0, 0. -*/ - -/*! - \qmlproperty real QtQuick2::Scale::xScale - - The scaling factor for the X axis. -*/ - -/*! - \qmlproperty real QtQuick2::Scale::yScale - - The scaling factor for the Y axis. -*/ - -/*! - \qmlclass Rotation QQuickRotation - \inqmlmodule QtQuick 2 - \ingroup qml-transform-elements - \brief The Rotation object provides a way to rotate an Item. - - The Rotation object gives more control over rotation than using \l Item's \l{Item::rotation}{rotation} property. - Specifically, it allows (z axis) rotation to be relative to an arbitrary point. - - The following example rotates a Rectangle around its interior point 25, 25: - \qml - Rectangle { - width: 100; height: 100 - color: "blue" - transform: Rotation { origin.x: 25; origin.y: 25; angle: 45} - } - \endqml - - Rotation also provides a way to specify 3D-like rotations for Items. For these types of - rotations you must specify the axis to rotate around in addition to the origin point. - - The following example shows various 3D-like rotations applied to an \l Image. - \snippet doc/src/snippets/declarative/rotation.qml 0 - - \image axisrotation.png - - \sa {declarative/ui-components/dialcontrol}{Dial Control example}, {declarative/toys/clocks}{Clocks example} -*/ - -/*! - \qmlproperty real QtQuick2::Rotation::origin.x - \qmlproperty real QtQuick2::Rotation::origin.y - - The origin point of the rotation (i.e., the point that stays fixed relative to the parent as - the rest of the item rotates). By default the origin is 0, 0. -*/ - -/*! - \qmlproperty real QtQuick2::Rotation::axis.x - \qmlproperty real QtQuick2::Rotation::axis.y - \qmlproperty real QtQuick2::Rotation::axis.z - - The axis to rotate around. For simple (2D) rotation around a point, you do not need to specify an axis, - as the default axis is the z axis (\c{ axis { x: 0; y: 0; z: 1 } }). - - For a typical 3D-like rotation you will usually specify both the origin and the axis. - - \image 3d-rotation-axis.png -*/ - -/*! - \qmlproperty real QtQuick2::Rotation::angle - - The angle to rotate, in degrees clockwise. -*/ - -QQuickTransformPrivate::QQuickTransformPrivate() -{ -} - -QQuickTransform::QQuickTransform(QObject *parent) -: QObject(*(new QQuickTransformPrivate), parent) -{ -} - -QQuickTransform::QQuickTransform(QQuickTransformPrivate &dd, QObject *parent) -: QObject(dd, parent) -{ -} - -QQuickTransform::~QQuickTransform() -{ - Q_D(QQuickTransform); - for (int ii = 0; ii < d->items.count(); ++ii) { - QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii)); - p->transforms.removeOne(this); - p->dirty(QQuickItemPrivate::Transform); - } -} - -void QQuickTransform::update() -{ - Q_D(QQuickTransform); - for (int ii = 0; ii < d->items.count(); ++ii) { - QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii)); - p->dirty(QQuickItemPrivate::Transform); - } -} - -QQuickContents::QQuickContents(QQuickItem *item) -: m_item(item), m_x(0), m_y(0), m_width(0), m_height(0) -{ -} - -QQuickContents::~QQuickContents() -{ - QList children = m_item->childItems(); - for (int i = 0; i < children.count(); ++i) { - QQuickItem *child = children.at(i); - QQuickItemPrivate::get(child)->removeItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed); - } -} - -bool QQuickContents::calcHeight(QQuickItem *changed) -{ - qreal oldy = m_y; - qreal oldheight = m_height; - - if (changed) { - qreal top = oldy; - qreal bottom = oldy + oldheight; - qreal y = changed->y(); - if (y + changed->height() > bottom) - bottom = y + changed->height(); - if (y < top) - top = y; - m_y = top; - m_height = bottom - top; - } else { - qreal top = FLT_MAX; - qreal bottom = 0; - QList children = m_item->childItems(); - for (int i = 0; i < children.count(); ++i) { - QQuickItem *child = children.at(i); - qreal y = child->y(); - if (y + child->height() > bottom) - bottom = y + child->height(); - if (y < top) - top = y; - } - if (!children.isEmpty()) - m_y = top; - m_height = qMax(bottom - top, qreal(0.0)); - } - - return (m_height != oldheight || m_y != oldy); -} - -bool QQuickContents::calcWidth(QQuickItem *changed) -{ - qreal oldx = m_x; - qreal oldwidth = m_width; - - if (changed) { - qreal left = oldx; - qreal right = oldx + oldwidth; - qreal x = changed->x(); - if (x + changed->width() > right) - right = x + changed->width(); - if (x < left) - left = x; - m_x = left; - m_width = right - left; - } else { - qreal left = FLT_MAX; - qreal right = 0; - QList children = m_item->childItems(); - for (int i = 0; i < children.count(); ++i) { - QQuickItem *child = children.at(i); - qreal x = child->x(); - if (x + child->width() > right) - right = x + child->width(); - if (x < left) - left = x; - } - if (!children.isEmpty()) - m_x = left; - m_width = qMax(right - left, qreal(0.0)); - } - - return (m_width != oldwidth || m_x != oldx); -} - -void QQuickContents::complete() -{ - QQuickItemPrivate::get(m_item)->addItemChangeListener(this, QQuickItemPrivate::Children); - - QList children = m_item->childItems(); - for (int i = 0; i < children.count(); ++i) { - QQuickItem *child = children.at(i); - QQuickItemPrivate::get(child)->addItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed); - //###what about changes to visibility? - } - calcGeometry(); -} - -void QQuickContents::updateRect() -{ - QQuickItemPrivate::get(m_item)->emitChildrenRectChanged(rectF()); -} - -void QQuickContents::itemGeometryChanged(QQuickItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_UNUSED(changed) - bool wChanged = false; - bool hChanged = false; - //### we can only pass changed if the left edge has moved left, or the right edge has moved right - if (newGeometry.width() != oldGeometry.width() || newGeometry.x() != oldGeometry.x()) - wChanged = calcWidth(/*changed*/); - if (newGeometry.height() != oldGeometry.height() || newGeometry.y() != oldGeometry.y()) - hChanged = calcHeight(/*changed*/); - if (wChanged || hChanged) - updateRect(); -} - -void QQuickContents::itemDestroyed(QQuickItem *item) -{ - if (item) - QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed); - calcGeometry(); -} - -void QQuickContents::itemChildRemoved(QQuickItem *, QQuickItem *item) -{ - if (item) - QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed); - calcGeometry(); -} - -void QQuickContents::itemChildAdded(QQuickItem *, QQuickItem *item) -{ - if (item) - QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed); - calcGeometry(item); -} - -QQuickItemKeyFilter::QQuickItemKeyFilter(QQuickItem *item) -: m_processPost(false), m_next(0) -{ - QQuickItemPrivate *p = item?QQuickItemPrivate::get(item):0; - if (p) { - m_next = p->keyHandler; - p->keyHandler = this; - } -} - -QQuickItemKeyFilter::~QQuickItemKeyFilter() -{ -} - -void QQuickItemKeyFilter::keyPressed(QKeyEvent *event, bool post) -{ - if (m_next) m_next->keyPressed(event, post); -} - -void QQuickItemKeyFilter::keyReleased(QKeyEvent *event, bool post) -{ - if (m_next) m_next->keyReleased(event, post); -} - -void QQuickItemKeyFilter::inputMethodEvent(QInputMethodEvent *event, bool post) -{ - if (m_next) - m_next->inputMethodEvent(event, post); - else - event->ignore(); -} - -QVariant QQuickItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query) const -{ - if (m_next) return m_next->inputMethodQuery(query); - return QVariant(); -} - -void QQuickItemKeyFilter::componentComplete() -{ - if (m_next) m_next->componentComplete(); -} -/*! - \qmlclass KeyNavigation QQuickKeyNavigationAttached - \inqmlmodule QtQuick 2 - \ingroup qml-basic-interaction-elements - \brief The KeyNavigation attached property supports key navigation by arrow keys. - - Key-based user interfaces commonly allow the use of arrow keys to navigate between - focusable items. The KeyNavigation attached property enables this behavior by providing a - convenient way to specify the item that should gain focus when an arrow or tab key is pressed. - - The following example provides key navigation for a 2x2 grid of items: - - \snippet doc/src/snippets/declarative/keynavigation.qml 0 - - The top-left item initially receives focus by setting \l {Item::}{focus} to - \c true. When an arrow key is pressed, the focus will move to the - appropriate item, as defined by the value that has been set for - the KeyNavigation \l left, \l right, \l up or \l down properties. - - Note that if a KeyNavigation attached property receives the key press and release - events for a requested arrow or tab key, the event is accepted and does not - propagate any further. - - By default, KeyNavigation receives key events after the item to which it is attached. - If the item accepts the key event, the KeyNavigation attached property will not - receive an event for that key. Setting the \l priority property to - \c KeyNavigation.BeforeItem allows the event to be used for key navigation - before the item, rather than after. - - If item to which the focus is switching is not enabled or visible, an attempt will - be made to skip this item and focus on the next. This is possible if there are - a chain of items with the same KeyNavigation handler. If multiple items in a row are not enabled - or visible, they will also be skipped. - - KeyNavigation will implicitly set the other direction to return focus to this item. So if you set - \l left to another item, \l right will be set on that item's KeyNavigation to set focus back to this - item. However, if that item's KeyNavigation has had right explicitly set then no change will occur. - This means that the above example could have been written, with the same behaviour, without specifing - KeyNavigation.right or KeyNavigation.down for any of the items. - - \sa {Keys}{Keys attached property} -*/ - -/*! - \qmlproperty Item QtQuick2::KeyNavigation::left - \qmlproperty Item QtQuick2::KeyNavigation::right - \qmlproperty Item QtQuick2::KeyNavigation::up - \qmlproperty Item QtQuick2::KeyNavigation::down - \qmlproperty Item QtQuick2::KeyNavigation::tab - \qmlproperty Item QtQuick2::KeyNavigation::backtab - - These properties hold the item to assign focus to - when the left, right, up or down cursor keys, or the - tab key are pressed. -*/ - -/*! - \qmlproperty Item QtQuick2::KeyNavigation::tab - \qmlproperty Item QtQuick2::KeyNavigation::backtab - - These properties hold the item to assign focus to - when the Tab key or Shift+Tab key combination (Backtab) are pressed. -*/ - -QQuickKeyNavigationAttached::QQuickKeyNavigationAttached(QObject *parent) -: QObject(*(new QQuickKeyNavigationAttachedPrivate), parent), - QQuickItemKeyFilter(qobject_cast(parent)) -{ - m_processPost = true; -} - -QQuickKeyNavigationAttached * -QQuickKeyNavigationAttached::qmlAttachedProperties(QObject *obj) -{ - return new QQuickKeyNavigationAttached(obj); -} - -QQuickItem *QQuickKeyNavigationAttached::left() const -{ - Q_D(const QQuickKeyNavigationAttached); - return d->left; -} - -void QQuickKeyNavigationAttached::setLeft(QQuickItem *i) -{ - Q_D(QQuickKeyNavigationAttached); - if (d->left == i) - return; - d->left = i; - d->leftSet = true; - QQuickKeyNavigationAttached* other = - qobject_cast(qmlAttachedPropertiesObject(i)); - if (other && !other->d_func()->rightSet){ - other->d_func()->right = qobject_cast(parent()); - emit other->rightChanged(); - } - emit leftChanged(); -} - -QQuickItem *QQuickKeyNavigationAttached::right() const -{ - Q_D(const QQuickKeyNavigationAttached); - return d->right; -} - -void QQuickKeyNavigationAttached::setRight(QQuickItem *i) -{ - Q_D(QQuickKeyNavigationAttached); - if (d->right == i) - return; - d->right = i; - d->rightSet = true; - QQuickKeyNavigationAttached* other = - qobject_cast(qmlAttachedPropertiesObject(i)); - if (other && !other->d_func()->leftSet){ - other->d_func()->left = qobject_cast(parent()); - emit other->leftChanged(); - } - emit rightChanged(); -} - -QQuickItem *QQuickKeyNavigationAttached::up() const -{ - Q_D(const QQuickKeyNavigationAttached); - return d->up; -} - -void QQuickKeyNavigationAttached::setUp(QQuickItem *i) -{ - Q_D(QQuickKeyNavigationAttached); - if (d->up == i) - return; - d->up = i; - d->upSet = true; - QQuickKeyNavigationAttached* other = - qobject_cast(qmlAttachedPropertiesObject(i)); - if (other && !other->d_func()->downSet){ - other->d_func()->down = qobject_cast(parent()); - emit other->downChanged(); - } - emit upChanged(); -} - -QQuickItem *QQuickKeyNavigationAttached::down() const -{ - Q_D(const QQuickKeyNavigationAttached); - return d->down; -} - -void QQuickKeyNavigationAttached::setDown(QQuickItem *i) -{ - Q_D(QQuickKeyNavigationAttached); - if (d->down == i) - return; - d->down = i; - d->downSet = true; - QQuickKeyNavigationAttached* other = - qobject_cast(qmlAttachedPropertiesObject(i)); - if (other && !other->d_func()->upSet) { - other->d_func()->up = qobject_cast(parent()); - emit other->upChanged(); - } - emit downChanged(); -} - -QQuickItem *QQuickKeyNavigationAttached::tab() const -{ - Q_D(const QQuickKeyNavigationAttached); - return d->tab; -} - -void QQuickKeyNavigationAttached::setTab(QQuickItem *i) -{ - Q_D(QQuickKeyNavigationAttached); - if (d->tab == i) - return; - d->tab = i; - d->tabSet = true; - QQuickKeyNavigationAttached* other = - qobject_cast(qmlAttachedPropertiesObject(i)); - if (other && !other->d_func()->backtabSet) { - other->d_func()->backtab = qobject_cast(parent()); - emit other->backtabChanged(); - } - emit tabChanged(); -} - -QQuickItem *QQuickKeyNavigationAttached::backtab() const -{ - Q_D(const QQuickKeyNavigationAttached); - return d->backtab; -} - -void QQuickKeyNavigationAttached::setBacktab(QQuickItem *i) -{ - Q_D(QQuickKeyNavigationAttached); - if (d->backtab == i) - return; - d->backtab = i; - d->backtabSet = true; - QQuickKeyNavigationAttached* other = - qobject_cast(qmlAttachedPropertiesObject(i)); - if (other && !other->d_func()->tabSet) { - other->d_func()->tab = qobject_cast(parent()); - emit other->tabChanged(); - } - emit backtabChanged(); -} - -/*! - \qmlproperty enumeration QtQuick2::KeyNavigation::priority - - This property determines whether the keys are processed before - or after the attached item's own key handling. - - \list - \o KeyNavigation.BeforeItem - process the key events before normal - item key processing. If the event is used for key navigation, it will be accepted and will not - be passed on to the item. - \o KeyNavigation.AfterItem (default) - process the key events after normal item key - handling. If the item accepts the key event it will not be - handled by the KeyNavigation attached property handler. - \endlist -*/ -QQuickKeyNavigationAttached::Priority QQuickKeyNavigationAttached::priority() const -{ - return m_processPost ? AfterItem : BeforeItem; -} - -void QQuickKeyNavigationAttached::setPriority(Priority order) -{ - bool processPost = order == AfterItem; - if (processPost != m_processPost) { - m_processPost = processPost; - emit priorityChanged(); - } -} - -void QQuickKeyNavigationAttached::keyPressed(QKeyEvent *event, bool post) -{ - Q_D(QQuickKeyNavigationAttached); - event->ignore(); - - if (post != m_processPost) { - QQuickItemKeyFilter::keyPressed(event, post); - return; - } - - bool mirror = false; - switch (event->key()) { - case Qt::Key_Left: { - if (QQuickItem *parentItem = qobject_cast(parent())) - mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror; - QQuickItem* leftItem = mirror ? d->right : d->left; - if (leftItem) { - setFocusNavigation(leftItem, mirror ? "right" : "left"); - event->accept(); - } - break; - } - case Qt::Key_Right: { - if (QQuickItem *parentItem = qobject_cast(parent())) - mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror; - QQuickItem* rightItem = mirror ? d->left : d->right; - if (rightItem) { - setFocusNavigation(rightItem, mirror ? "left" : "right"); - event->accept(); - } - break; - } - case Qt::Key_Up: - if (d->up) { - setFocusNavigation(d->up, "up"); - event->accept(); - } - break; - case Qt::Key_Down: - if (d->down) { - setFocusNavigation(d->down, "down"); - event->accept(); - } - break; - case Qt::Key_Tab: - if (d->tab) { - setFocusNavigation(d->tab, "tab"); - event->accept(); - } - break; - case Qt::Key_Backtab: - if (d->backtab) { - setFocusNavigation(d->backtab, "backtab"); - event->accept(); - } - break; - default: - break; - } - - if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post); -} - -void QQuickKeyNavigationAttached::keyReleased(QKeyEvent *event, bool post) -{ - Q_D(QQuickKeyNavigationAttached); - event->ignore(); - - if (post != m_processPost) { - QQuickItemKeyFilter::keyReleased(event, post); - return; - } - - bool mirror = false; - switch (event->key()) { - case Qt::Key_Left: - if (QQuickItem *parentItem = qobject_cast(parent())) - mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror; - if (mirror ? d->right : d->left) - event->accept(); - break; - case Qt::Key_Right: - if (QQuickItem *parentItem = qobject_cast(parent())) - mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror; - if (mirror ? d->left : d->right) - event->accept(); - break; - case Qt::Key_Up: - if (d->up) { - event->accept(); - } - break; - case Qt::Key_Down: - if (d->down) { - event->accept(); - } - break; - case Qt::Key_Tab: - if (d->tab) { - event->accept(); - } - break; - case Qt::Key_Backtab: - if (d->backtab) { - event->accept(); - } - break; - default: - break; - } - - if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post); -} - -void QQuickKeyNavigationAttached::setFocusNavigation(QQuickItem *currentItem, const char *dir) -{ - QQuickItem *initialItem = currentItem; - bool isNextItem = false; - do { - isNextItem = false; - if (currentItem->isVisible() && currentItem->isEnabled()) { - currentItem->setFocus(true); - } else { - QObject *attached = - qmlAttachedPropertiesObject(currentItem, false); - if (attached) { - QQuickItem *tempItem = qvariant_cast(attached->property(dir)); - if (tempItem) { - currentItem = tempItem; - isNextItem = true; - } - } - } - } - while (currentItem != initialItem && isNextItem); -} - -const QQuickKeysAttached::SigMap QQuickKeysAttached::sigMap[] = { - { Qt::Key_Left, "leftPressed" }, - { Qt::Key_Right, "rightPressed" }, - { Qt::Key_Up, "upPressed" }, - { Qt::Key_Down, "downPressed" }, - { Qt::Key_Tab, "tabPressed" }, - { Qt::Key_Backtab, "backtabPressed" }, - { Qt::Key_Asterisk, "asteriskPressed" }, - { Qt::Key_NumberSign, "numberSignPressed" }, - { Qt::Key_Escape, "escapePressed" }, - { Qt::Key_Return, "returnPressed" }, - { Qt::Key_Enter, "enterPressed" }, - { Qt::Key_Delete, "deletePressed" }, - { Qt::Key_Space, "spacePressed" }, - { Qt::Key_Back, "backPressed" }, - { Qt::Key_Cancel, "cancelPressed" }, - { Qt::Key_Select, "selectPressed" }, - { Qt::Key_Yes, "yesPressed" }, - { Qt::Key_No, "noPressed" }, - { Qt::Key_Context1, "context1Pressed" }, - { Qt::Key_Context2, "context2Pressed" }, - { Qt::Key_Context3, "context3Pressed" }, - { Qt::Key_Context4, "context4Pressed" }, - { Qt::Key_Call, "callPressed" }, - { Qt::Key_Hangup, "hangupPressed" }, - { Qt::Key_Flip, "flipPressed" }, - { Qt::Key_Menu, "menuPressed" }, - { Qt::Key_VolumeUp, "volumeUpPressed" }, - { Qt::Key_VolumeDown, "volumeDownPressed" }, - { 0, 0 } -}; - -bool QQuickKeysAttachedPrivate::isConnected(const char *signalName) -{ - return isSignalConnected(signalIndex(signalName)); -} - -/*! - \qmlclass Keys QQuickKeysAttached - \inqmlmodule QtQuick 2 - \ingroup qml-basic-interaction-elements - \brief The Keys attached property provides key handling to Items. - - All visual primitives support key handling via the Keys - attached property. Keys can be handled via the onPressed - and onReleased signal properties. - - The signal properties have a \l KeyEvent parameter, named - \e event which contains details of the event. If a key is - handled \e event.accepted should be set to true to prevent the - event from propagating up the item hierarchy. - - \section1 Example Usage - - The following example shows how the general onPressed handler can - be used to test for a certain key; in this case, the left cursor - key: - - \snippet doc/src/snippets/declarative/keys/keys-pressed.qml key item - - Some keys may alternatively be handled via specific signal properties, - for example \e onSelectPressed. These handlers automatically set - \e event.accepted to true. - - \snippet doc/src/snippets/declarative/keys/keys-handler.qml key item - - See \l{Qt::Key}{Qt.Key} for the list of keyboard codes. - - \section1 Key Handling Priorities - - The Keys attached property can be configured to handle key events - before or after the item it is attached to. This makes it possible - to intercept events in order to override an item's default behavior, - or act as a fallback for keys not handled by the item. - - If \l priority is Keys.BeforeItem (default) the order of key event processing is: - - \list 1 - \o Items specified in \c forwardTo - \o specific key handlers, e.g. onReturnPressed - \o onKeyPress, onKeyRelease handlers - \o Item specific key handling, e.g. TextInput key handling - \o parent item - \endlist - - If priority is Keys.AfterItem the order of key event processing is: - - \list 1 - \o Item specific key handling, e.g. TextInput key handling - \o Items specified in \c forwardTo - \o specific key handlers, e.g. onReturnPressed - \o onKeyPress, onKeyRelease handlers - \o parent item - \endlist - - If the event is accepted during any of the above steps, key - propagation stops. - - \sa KeyEvent, {KeyNavigation}{KeyNavigation attached property} -*/ - -/*! - \qmlproperty bool QtQuick2::Keys::enabled - - This flags enables key handling if true (default); otherwise - no key handlers will be called. -*/ - -/*! - \qmlproperty enumeration QtQuick2::Keys::priority - - This property determines whether the keys are processed before - or after the attached item's own key handling. - - \list - \o Keys.BeforeItem (default) - process the key events before normal - item key processing. If the event is accepted it will not - be passed on to the item. - \o Keys.AfterItem - process the key events after normal item key - handling. If the item accepts the key event it will not be - handled by the Keys attached property handler. - \endlist -*/ - -/*! - \qmlproperty list QtQuick2::Keys::forwardTo - - This property provides a way to forward key presses, key releases, and keyboard input - coming from input methods to other items. This can be useful when you want - one item to handle some keys (e.g. the up and down arrow keys), and another item to - handle other keys (e.g. the left and right arrow keys). Once an item that has been - forwarded keys accepts the event it is no longer forwarded to items later in the - list. - - This example forwards key events to two lists: - \qml - Item { - ListView { - id: list1 - // ... - } - ListView { - id: list2 - // ... - } - Keys.forwardTo: [list1, list2] - focus: true - } - \endqml -*/ - -/*! - \qmlsignal QtQuick2::Keys::onPressed(KeyEvent event) - - This handler is called when a key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onReleased(KeyEvent event) - - This handler is called when a key has been released. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDigit0Pressed(KeyEvent event) - - This handler is called when the digit '0' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDigit1Pressed(KeyEvent event) - - This handler is called when the digit '1' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDigit2Pressed(KeyEvent event) - - This handler is called when the digit '2' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDigit3Pressed(KeyEvent event) - - This handler is called when the digit '3' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDigit4Pressed(KeyEvent event) - - This handler is called when the digit '4' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDigit5Pressed(KeyEvent event) - - This handler is called when the digit '5' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDigit6Pressed(KeyEvent event) - - This handler is called when the digit '6' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDigit7Pressed(KeyEvent event) - - This handler is called when the digit '7' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDigit8Pressed(KeyEvent event) - - This handler is called when the digit '8' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDigit9Pressed(KeyEvent event) - - This handler is called when the digit '9' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onLeftPressed(KeyEvent event) - - This handler is called when the Left arrow has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onRightPressed(KeyEvent event) - - This handler is called when the Right arrow has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onUpPressed(KeyEvent event) - - This handler is called when the Up arrow has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDownPressed(KeyEvent event) - - This handler is called when the Down arrow has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onTabPressed(KeyEvent event) - - This handler is called when the Tab key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onBacktabPressed(KeyEvent event) - - This handler is called when the Shift+Tab key combination (Backtab) has - been pressed. The \a event parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onAsteriskPressed(KeyEvent event) - - This handler is called when the Asterisk '*' has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onEscapePressed(KeyEvent event) - - This handler is called when the Escape key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onReturnPressed(KeyEvent event) - - This handler is called when the Return key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onEnterPressed(KeyEvent event) - - This handler is called when the Enter key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onDeletePressed(KeyEvent event) - - This handler is called when the Delete key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onSpacePressed(KeyEvent event) - - This handler is called when the Space key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onBackPressed(KeyEvent event) - - This handler is called when the Back key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onCancelPressed(KeyEvent event) - - This handler is called when the Cancel key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onSelectPressed(KeyEvent event) - - This handler is called when the Select key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onYesPressed(KeyEvent event) - - This handler is called when the Yes key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onNoPressed(KeyEvent event) - - This handler is called when the No key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onContext1Pressed(KeyEvent event) - - This handler is called when the Context1 key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onContext2Pressed(KeyEvent event) - - This handler is called when the Context2 key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onContext3Pressed(KeyEvent event) - - This handler is called when the Context3 key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onContext4Pressed(KeyEvent event) - - This handler is called when the Context4 key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onCallPressed(KeyEvent event) - - This handler is called when the Call key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onHangupPressed(KeyEvent event) - - This handler is called when the Hangup key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onFlipPressed(KeyEvent event) - - This handler is called when the Flip key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onMenuPressed(KeyEvent event) - - This handler is called when the Menu key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onVolumeUpPressed(KeyEvent event) - - This handler is called when the VolumeUp key has been pressed. The \a event - parameter provides information about the event. -*/ - -/*! - \qmlsignal QtQuick2::Keys::onVolumeDownPressed(KeyEvent event) - - This handler is called when the VolumeDown key has been pressed. The \a event - parameter provides information about the event. -*/ - -QQuickKeysAttached::QQuickKeysAttached(QObject *parent) -: QObject(*(new QQuickKeysAttachedPrivate), parent), - QQuickItemKeyFilter(qobject_cast(parent)) -{ - Q_D(QQuickKeysAttached); - m_processPost = false; - d->item = qobject_cast(parent); -} - -QQuickKeysAttached::~QQuickKeysAttached() -{ -} - -QQuickKeysAttached::Priority QQuickKeysAttached::priority() const -{ - return m_processPost ? AfterItem : BeforeItem; -} - -void QQuickKeysAttached::setPriority(Priority order) -{ - bool processPost = order == AfterItem; - if (processPost != m_processPost) { - m_processPost = processPost; - emit priorityChanged(); - } -} - -void QQuickKeysAttached::componentComplete() -{ - Q_D(QQuickKeysAttached); - if (d->item) { - for (int ii = 0; ii < d->targets.count(); ++ii) { - QQuickItem *targetItem = d->targets.at(ii); - if (targetItem && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) { - d->item->setFlag(QQuickItem::ItemAcceptsInputMethod); - break; - } - } - } -} - -void QQuickKeysAttached::keyPressed(QKeyEvent *event, bool post) -{ - Q_D(QQuickKeysAttached); - if (post != m_processPost || !d->enabled || d->inPress) { - event->ignore(); - QQuickItemKeyFilter::keyPressed(event, post); - return; - } - - // first process forwards - if (d->item && d->item->canvas()) { - d->inPress = true; - for (int ii = 0; ii < d->targets.count(); ++ii) { - QQuickItem *i = d->targets.at(ii); - if (i && i->isVisible()) { - d->item->canvas()->sendEvent(i, event); - if (event->isAccepted()) { - d->inPress = false; - return; - } - } - } - d->inPress = false; - } - - QQuickKeyEvent ke(*event); - QByteArray keySignal = keyToSignal(event->key()); - if (!keySignal.isEmpty()) { - keySignal += "(QQuickKeyEvent*)"; - if (d->isConnected(keySignal)) { - // If we specifically handle a key then default to accepted - ke.setAccepted(true); - int idx = QQuickKeysAttached::staticMetaObject.indexOfSignal(keySignal); - metaObject()->method(idx).invoke(this, Qt::DirectConnection, Q_ARG(QQuickKeyEvent*, &ke)); - } - } - if (!ke.isAccepted()) - emit pressed(&ke); - event->setAccepted(ke.isAccepted()); - - if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post); -} - -void QQuickKeysAttached::keyReleased(QKeyEvent *event, bool post) -{ - Q_D(QQuickKeysAttached); - if (post != m_processPost || !d->enabled || d->inRelease) { - event->ignore(); - QQuickItemKeyFilter::keyReleased(event, post); - return; - } - - if (d->item && d->item->canvas()) { - d->inRelease = true; - for (int ii = 0; ii < d->targets.count(); ++ii) { - QQuickItem *i = d->targets.at(ii); - if (i && i->isVisible()) { - d->item->canvas()->sendEvent(i, event); - if (event->isAccepted()) { - d->inRelease = false; - return; - } - } - } - d->inRelease = false; - } - - QQuickKeyEvent ke(*event); - emit released(&ke); - event->setAccepted(ke.isAccepted()); - - if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post); -} - -void QQuickKeysAttached::inputMethodEvent(QInputMethodEvent *event, bool post) -{ - Q_D(QQuickKeysAttached); - if (post == m_processPost && d->item && !d->inIM && d->item->canvas()) { - d->inIM = true; - for (int ii = 0; ii < d->targets.count(); ++ii) { - QQuickItem *i = d->targets.at(ii); - if (i && i->isVisible() && (i->flags() & QQuickItem::ItemAcceptsInputMethod)) { - d->item->canvas()->sendEvent(i, event); - if (event->isAccepted()) { - d->imeItem = i; - d->inIM = false; - return; - } - } - } - d->inIM = false; - } - QQuickItemKeyFilter::inputMethodEvent(event, post); -} - -QVariant QQuickKeysAttached::inputMethodQuery(Qt::InputMethodQuery query) const -{ - Q_D(const QQuickKeysAttached); - if (d->item) { - for (int ii = 0; ii < d->targets.count(); ++ii) { - QQuickItem *i = d->targets.at(ii); - if (i && i->isVisible() && (i->flags() & QQuickItem::ItemAcceptsInputMethod) && i == d->imeItem) { - //### how robust is i == d->imeItem check? - QVariant v = i->inputMethodQuery(query); - if (v.userType() == QVariant::RectF) - v = d->item->mapRectFromItem(i, v.toRectF()); //### cost? - return v; - } - } - } - return QQuickItemKeyFilter::inputMethodQuery(query); -} - -QQuickKeysAttached *QQuickKeysAttached::qmlAttachedProperties(QObject *obj) -{ - return new QQuickKeysAttached(obj); -} - -/*! - \qmlclass LayoutMirroring QQuickLayoutMirroringAttached - \inqmlmodule QtQuick 2 - \ingroup qml-utility-elements - \brief The LayoutMirroring attached property is used to mirror layout behavior. - - The LayoutMirroring attached property is used to horizontally mirror \l {anchor-layout}{Item anchors}, - \l{Using QML Positioner and Repeater Items}{positioner} elements (such as \l Row and \l Grid) - and views (such as \l GridView and horizontal \l ListView). Mirroring is a visual change: left - anchors become right anchors, and positioner elements like \l Grid and \l Row reverse the - horizontal layout of child items. - - Mirroring is enabled for an item by setting the \l enabled property to true. By default, this - only affects the item itself; setting the \l childrenInherit property to true propagates the mirroring - behavior to all child elements as well. If the \c LayoutMirroring attached property has not been defined - for an item, mirroring is not enabled. - - The following example shows mirroring in action. The \l Row below is specified as being anchored - to the left of its parent. However, since mirroring has been enabled, the anchor is horizontally - reversed and it is now anchored to the right. Also, since items in a \l Row are positioned - from left to right by default, they are now positioned from right to left instead, as demonstrated - by the numbering and opacity of the items: - - \snippet doc/src/snippets/declarative/layoutmirroring.qml 0 - - \image layoutmirroring.png - - Layout mirroring is useful when it is necessary to support both left-to-right and right-to-left - layout versions of an application to target different language areas. The \l childrenInherit - property allows layout mirroring to be applied without manually setting layout configurations - for every item in an application. Keep in mind, however, that mirroring does not affect any - positioning that is defined by the \l Item \l {Item::}{x} coordinate value, so even with - mirroring enabled, it will often be necessary to apply some layout fixes to support the - desired layout direction. Also, it may be necessary to disable the mirroring of individual - child items (by setting \l {enabled}{LayoutMirroring.enabled} to false for such items) if - mirroring is not the desired behavior, or if the child item already implements mirroring in - some custom way. - - See \l {QML Right-to-left User Interfaces} for further details on using \c LayoutMirroring and - other related features to implement right-to-left support for an application. -*/ - -/*! - \qmlproperty bool QtQuick2::LayoutMirroring::enabled - - This property holds whether the item's layout is mirrored horizontally. Setting this to true - horizontally reverses \l {anchor-layout}{anchor} settings such that left anchors become right, - and right anchors become left. For \l{Using QML Positioner and Repeater Items}{positioner} elements - (such as \l Row and \l Grid) and view elements (such as \l {GridView}{GridView} and \l {ListView}{ListView}) - this also mirrors the horizontal layout direction of the item. - - The default value is false. -*/ - -/*! - \qmlproperty bool QtQuick2::LayoutMirroring::childrenInherit - - This property holds whether the \l {enabled}{LayoutMirroring.enabled} value for this item - is inherited by its children. - - The default value is false. -*/ - - -QQuickLayoutMirroringAttached::QQuickLayoutMirroringAttached(QObject *parent) : QObject(parent), itemPrivate(0) -{ - if (QQuickItem *item = qobject_cast(parent)) { - itemPrivate = QQuickItemPrivate::get(item); - itemPrivate->attachedLayoutDirection = this; - } else - qmlInfo(parent) << tr("LayoutDirection attached property only works with Items"); -} - -QQuickLayoutMirroringAttached * QQuickLayoutMirroringAttached::qmlAttachedProperties(QObject *object) -{ - return new QQuickLayoutMirroringAttached(object); -} - -bool QQuickLayoutMirroringAttached::enabled() const -{ - return itemPrivate ? itemPrivate->effectiveLayoutMirror : false; -} - -void QQuickLayoutMirroringAttached::setEnabled(bool enabled) -{ - if (!itemPrivate) - return; - - itemPrivate->isMirrorImplicit = false; - if (enabled != itemPrivate->effectiveLayoutMirror) { - itemPrivate->setLayoutMirror(enabled); - if (itemPrivate->inheritMirrorFromItem) - itemPrivate->resolveLayoutMirror(); - } -} - -void QQuickLayoutMirroringAttached::resetEnabled() -{ - if (itemPrivate && !itemPrivate->isMirrorImplicit) { - itemPrivate->isMirrorImplicit = true; - itemPrivate->resolveLayoutMirror(); - } -} - -bool QQuickLayoutMirroringAttached::childrenInherit() const -{ - return itemPrivate ? itemPrivate->inheritMirrorFromItem : false; -} - -void QQuickLayoutMirroringAttached::setChildrenInherit(bool childrenInherit) { - if (itemPrivate && childrenInherit != itemPrivate->inheritMirrorFromItem) { - itemPrivate->inheritMirrorFromItem = childrenInherit; - itemPrivate->resolveLayoutMirror(); - childrenInheritChanged(); - } -} - -void QQuickItemPrivate::resolveLayoutMirror() -{ - Q_Q(QQuickItem); - if (QQuickItem *parentItem = q->parentItem()) { - QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parentItem); - setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent); - } else { - setImplicitLayoutMirror(isMirrorImplicit ? false : effectiveLayoutMirror, inheritMirrorFromItem); - } -} - -void QQuickItemPrivate::setImplicitLayoutMirror(bool mirror, bool inherit) -{ - inherit = inherit || inheritMirrorFromItem; - if (!isMirrorImplicit && inheritMirrorFromItem) - mirror = effectiveLayoutMirror; - if (mirror == inheritedLayoutMirror && inherit == inheritMirrorFromParent) - return; - - inheritMirrorFromParent = inherit; - inheritedLayoutMirror = inheritMirrorFromParent ? mirror : false; - - if (isMirrorImplicit) - setLayoutMirror(inherit ? inheritedLayoutMirror : false); - for (int i = 0; i < childItems.count(); ++i) { - if (QQuickItem *child = qobject_cast(childItems.at(i))) { - QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child); - childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent); - } - } -} - -void QQuickItemPrivate::setLayoutMirror(bool mirror) -{ - if (mirror != effectiveLayoutMirror) { - effectiveLayoutMirror = mirror; - if (_anchors) { - QQuickAnchorsPrivate *anchor_d = QQuickAnchorsPrivate::get(_anchors); - anchor_d->fillChanged(); - anchor_d->centerInChanged(); - anchor_d->updateHorizontalAnchors(); - emit _anchors->mirroredChanged(); - } - mirrorChange(); - if (attachedLayoutDirection) { - emit attachedLayoutDirection->enabledChanged(); - } - } -} - -/*! - \class QQuickItem - \brief The QQuickItem class provides the most basic of all visual items in QML. - - All visual items in Qt Declarative inherit from QQuickItem. Although QQuickItem - has no visual appearance, it defines all the properties that are - common across visual items - such as the x and y position, the - width and height, \l {anchor-layout}{anchoring} and key handling. - - You can subclass QQuickItem to provide your own custom visual item that inherits - these features. Note that, because it does not draw anything, QQuickItem sets the - QGraphicsItem::ItemHasNoContents flag. If you subclass QQuickItem to create a visual - item, you will need to unset this flag. - -*/ - -/*! - \qmlclass Item QQuickItem - \inqmlmodule QtQuick 2 - \ingroup qml-basic-visual-elements - \brief The Item is the most basic of all visual items in QML. - - All visual items in Qt Declarative inherit from Item. Although Item - has no visual appearance, it defines all the properties that are - common across visual items - such as the x and y position, the - width and height, \l {anchor-layout}{anchoring} and key handling. - - Item is also useful for grouping items together. - - \qml - Item { - Image { - source: "tile.png" - } - Image { - x: 80 - width: 100 - height: 100 - source: "tile.png" - } - Image { - x: 190 - width: 100 - height: 100 - fillMode: Image.Tile - source: "tile.png" - } - } - \endqml - - - \section1 Key Handling - - Key handling is available to all Item-based visual elements via the \l {Keys}{Keys} - attached property. The \e Keys attached property provides basic handlers such - as \l {Keys::onPressed}{onPressed} and \l {Keys::onReleased}{onReleased}, - as well as handlers for specific keys, such as - \l {Keys::onCancelPressed}{onCancelPressed}. The example below - assigns \l {qmlfocus}{focus} to the item and handles - the Left key via the general \e onPressed handler and the Select key via the - onSelectPressed handler: - - \qml - Item { - focus: true - Keys.onPressed: { - if (event.key == Qt.Key_Left) { - console.log("move left"); - event.accepted = true; - } - } - Keys.onSelectPressed: console.log("Selected"); - } - \endqml - - See the \l {Keys}{Keys} attached property for detailed documentation. - - \section1 Layout Mirroring - - Item layouts can be mirrored using the \l {LayoutMirroring}{LayoutMirroring} attached property. - -*/ - -/*! - \fn void QQuickItem::childrenRectChanged(const QRectF &) - \internal -*/ - -/*! - \fn void QQuickItem::baselineOffsetChanged(qreal) - \internal -*/ - -/*! - \fn void QQuickItem::stateChanged(const QString &state) - \internal -*/ - -/*! - \fn void QQuickItem::parentChanged(QQuickItem *) - \internal -*/ - -/*! - \fn void QQuickItem::smoothChanged(bool) - \internal -*/ - -/*! - \fn void QQuickItem::clipChanged(bool) - \internal -*/ - -/*! \fn void QQuickItem::transformOriginChanged(TransformOrigin) - \internal -*/ - -/*! - \fn void QQuickItem::focusChanged(bool) - \internal -*/ - -/*! - \fn void QQuickItem::activeFocusChanged(bool) - \internal -*/ -/*! - \fn QQuickItem::QQuickItem(QQuickItem *parent) - - Constructs a QQuickItem with the given \a parent. -*/ -QQuickItem::QQuickItem(QQuickItem* parent) -: QObject(*(new QQuickItemPrivate), parent) -{ - Q_D(QQuickItem); - d->init(parent); -} - -/*! \internal -*/ -QQuickItem::QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent) -: QObject(dd, parent) -{ - Q_D(QQuickItem); - d->init(parent); -} - -#ifndef QT_NO_DEBUG -static int qt_item_count = 0; - -static void qt_print_item_count() -{ - qDebug("Number of leaked items: %i", qt_item_count); - qt_item_count = -1; -} -#endif - -/*! - Destroys the QQuickItem. -*/ -QQuickItem::~QQuickItem() -{ -#ifndef QT_NO_DEBUG - --qt_item_count; - if (qt_item_count < 0) - qDebug("Item destroyed after qt_print_item_count() was called."); -#endif - - Q_D(QQuickItem); - - if (d->parentItem) - setParentItem(0); - else if (d->canvas && d->itemNodeInstance) - QQuickCanvasPrivate::get(d->canvas)->cleanup(d->itemNodeInstance); // cleanup root - // XXX todo - optimize - while (!d->childItems.isEmpty()) - d->childItems.first()->setParentItem(0); - - for (int ii = 0; ii < d->changeListeners.count(); ++ii) { - QQuickAnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate(); - if (anchor) - anchor->clearItem(this); - } - - /* - update item anchors that depended on us unless they are our child (and will also be destroyed), - or our sibling, and our parent is also being destroyed. - */ - for (int ii = 0; ii < d->changeListeners.count(); ++ii) { - QQuickAnchorsPrivate *anchor = d->changeListeners.at(ii).listener->anchorPrivate(); - if (anchor && anchor->item && anchor->item->parentItem() && anchor->item->parentItem() != this) - anchor->update(); - } - - for (int ii = 0; ii < d->changeListeners.count(); ++ii) { - const QQuickItemPrivate::ChangeListener &change = d->changeListeners.at(ii); - if (change.types & QQuickItemPrivate::Destroyed) - change.listener->itemDestroyed(this); - } - d->changeListeners.clear(); - delete d->_anchorLines; d->_anchorLines = 0; - delete d->_anchors; d->_anchors = 0; - delete d->_stateGroup; d->_stateGroup = 0; - delete d->_contents; d->_contents = 0; -} - -/*! - \qmlproperty enumeration QtQuick2::Item::transformOrigin - This property holds the origin point around which scale and rotation transform. - - Nine transform origins are available, as shown in the image below. - - \image declarative-transformorigin.png - - This example rotates an image around its bottom-right corner. - \qml - Image { - source: "myimage.png" - transformOrigin: Item.BottomRight - rotation: 45 - } - \endqml - - The default transform origin is \c Item.Center. - - To set an arbitrary transform origin point use the \l Scale or \l Rotation - transform elements. -*/ - -/*! - \qmlproperty Item QtQuick2::Item::parent - This property holds the parent of the item. -*/ - -/*! - \property QQuickItem::parent - This property holds the parent of the item. -*/ -void QQuickItem::setParentItem(QQuickItem *parentItem) -{ - Q_D(QQuickItem); - if (parentItem == d->parentItem) - return; - - d->removeFromDirtyList(); - - QQuickItem *oldParentItem = d->parentItem; - QQuickItem *scopeFocusedItem = 0; - - if (oldParentItem) { - QQuickItemPrivate *op = QQuickItemPrivate::get(oldParentItem); - - QQuickItem *scopeItem = 0; - - if (d->canvas && hasFocus()) { - scopeItem = oldParentItem; - while (!scopeItem->isFocusScope()) scopeItem = scopeItem->parentItem(); - scopeFocusedItem = this; - } else if (d->canvas && !isFocusScope() && d->subFocusItem) { - scopeItem = oldParentItem; - while (!scopeItem->isFocusScope()) scopeItem = scopeItem->parentItem(); - scopeFocusedItem = d->subFocusItem; - } - - if (scopeFocusedItem) - QQuickCanvasPrivate::get(d->canvas)->clearFocusInScope(scopeItem, scopeFocusedItem, - QQuickCanvasPrivate::DontChangeFocusProperty); - - op->removeChild(this); - } - - d->parentItem = parentItem; - - QQuickCanvas *parentCanvas = parentItem?QQuickItemPrivate::get(parentItem)->canvas:0; - if (d->canvas != parentCanvas) { - QQuickItemPrivate::InitializationState initState; - initState.clear(); - d->initCanvas(&initState, parentCanvas); - } - - d->dirty(QQuickItemPrivate::ParentChanged); - - if (d->parentItem) - QQuickItemPrivate::get(d->parentItem)->addChild(this); - - d->setEffectiveVisibleRecur(d->calcEffectiveVisible()); - d->setEffectiveEnableRecur(d->calcEffectiveEnable()); - - if (scopeFocusedItem && d->parentItem && d->canvas) { - // We need to test whether this item becomes scope focused - QQuickItem *scopeItem = 0; - scopeItem = d->parentItem; - while (!scopeItem->isFocusScope()) scopeItem = scopeItem->parentItem(); - - if (scopeItem->scopedFocusItem()) { - QQuickItemPrivate::get(scopeFocusedItem)->focus = false; - emit scopeFocusedItem->focusChanged(false); - } else { - QQuickCanvasPrivate::get(d->canvas)->setFocusInScope(scopeItem, scopeFocusedItem, - QQuickCanvasPrivate::DontChangeFocusProperty); - } - } - - d->resolveLayoutMirror(); - - d->itemChange(ItemParentHasChanged, d->parentItem); - - emit parentChanged(d->parentItem); -} - -void QQuickItem::stackBefore(const QQuickItem *sibling) -{ - Q_D(QQuickItem); - if (!sibling || sibling == this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) { - qWarning("QQuickItem::stackBefore: Cannot stack before %p, which must be a sibling", sibling); - return; - } - - QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem); - - int myIndex = parentPrivate->childItems.indexOf(this); - int siblingIndex = parentPrivate->childItems.indexOf(const_cast(sibling)); - - Q_ASSERT(myIndex != -1 && siblingIndex != -1); - - if (myIndex == siblingIndex - 1) - return; - - parentPrivate->childItems.removeAt(myIndex); - - if (myIndex < siblingIndex) --siblingIndex; - - parentPrivate->childItems.insert(siblingIndex, this); - - parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged); - parentPrivate->markSortedChildrenDirty(this); - - for (int ii = qMin(siblingIndex, myIndex); ii < parentPrivate->childItems.count(); ++ii) - QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged(); -} - -void QQuickItem::stackAfter(const QQuickItem *sibling) -{ - Q_D(QQuickItem); - if (!sibling || sibling == this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) { - qWarning("QQuickItem::stackAfter: Cannot stack after %p, which must be a sibling", sibling); - return; - } - - QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem); - - int myIndex = parentPrivate->childItems.indexOf(this); - int siblingIndex = parentPrivate->childItems.indexOf(const_cast(sibling)); - - Q_ASSERT(myIndex != -1 && siblingIndex != -1); - - if (myIndex == siblingIndex + 1) - return; - - parentPrivate->childItems.removeAt(myIndex); - - if (myIndex < siblingIndex) --siblingIndex; - - parentPrivate->childItems.insert(siblingIndex + 1, this); - - parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged); - parentPrivate->markSortedChildrenDirty(this); - - for (int ii = qMin(myIndex, siblingIndex + 1); ii < parentPrivate->childItems.count(); ++ii) - QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged(); -} - -/*! - Returns the QQuickItem parent of this item. -*/ -QQuickItem *QQuickItem::parentItem() const -{ - Q_D(const QQuickItem); - return d->parentItem; -} - -QSGEngine *QQuickItem::sceneGraphEngine() const -{ - return canvas()->sceneGraphEngine(); -} - -QQuickCanvas *QQuickItem::canvas() const -{ - Q_D(const QQuickItem); - return d->canvas; -} - -static bool itemZOrder_sort(QQuickItem *lhs, QQuickItem *rhs) -{ - return lhs->z() < rhs->z(); -} - -QList QQuickItemPrivate::paintOrderChildItems() const -{ - if (sortedChildItems) - return *sortedChildItems; - - // If none of the items have set Z then the paint order list is the same as - // the childItems list. This is by far the most common case. - bool haveZ = false; - for (int i = 0; i < childItems.count(); ++i) { - if (QQuickItemPrivate::get(childItems.at(i))->z != 0.) { - haveZ = true; - break; - } - } - if (haveZ) { - sortedChildItems = new QList(childItems); - qStableSort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort); - return *sortedChildItems; - } - - sortedChildItems = const_cast*>(&childItems); - - return childItems; -} - -void QQuickItemPrivate::addChild(QQuickItem *child) -{ - Q_Q(QQuickItem); - - Q_ASSERT(!childItems.contains(child)); - - childItems.append(child); - - markSortedChildrenDirty(child); - dirty(QQuickItemPrivate::ChildrenChanged); - - itemChange(QQuickItem::ItemChildAddedChange, child); - - emit q->childrenChanged(); -} - -void QQuickItemPrivate::removeChild(QQuickItem *child) -{ - Q_Q(QQuickItem); - - Q_ASSERT(child); - Q_ASSERT(childItems.contains(child)); - childItems.removeOne(child); - Q_ASSERT(!childItems.contains(child)); - - markSortedChildrenDirty(child); - dirty(QQuickItemPrivate::ChildrenChanged); - - itemChange(QQuickItem::ItemChildRemovedChange, child); - - emit q->childrenChanged(); -} - -void QQuickItemPrivate::InitializationState::clear() -{ - focusScope = 0; -} - -void QQuickItemPrivate::InitializationState::clear(QQuickItem *fs) -{ - focusScope = fs; -} - -QQuickItem *QQuickItemPrivate::InitializationState::getFocusScope(QQuickItem *item) -{ - if (!focusScope) { - QQuickItem *fs = item->parentItem(); - while (!fs->isFocusScope()) - fs = fs->parentItem(); - focusScope = fs; - } - return focusScope; -} - -void QQuickItemPrivate::initCanvas(InitializationState *state, QQuickCanvas *c) -{ - Q_Q(QQuickItem); - - if (canvas) { - removeFromDirtyList(); - QQuickCanvasPrivate *c = QQuickCanvasPrivate::get(canvas); - if (polishScheduled) - c->itemsToPolish.remove(q); - if (c->mouseGrabberItem == q) - c->mouseGrabberItem = 0; - if ( hoverEnabled ) - c->hoverItems.removeAll(q); - if (itemNodeInstance) - c->cleanup(itemNodeInstance); - } - - canvas = c; - - if (canvas && polishScheduled) - QQuickCanvasPrivate::get(canvas)->itemsToPolish.insert(q); - - itemNodeInstance = 0; - opacityNode = 0; - clipNode = 0; - rootNode = 0; - groupNode = 0; - paintNode = 0; - beforePaintNode = 0; - - InitializationState _dummy; - InitializationState *childState = state; - - if (c && q->isFocusScope()) { - _dummy.clear(q); - childState = &_dummy; - } - - for (int ii = 0; ii < childItems.count(); ++ii) { - QQuickItem *child = childItems.at(ii); - QQuickItemPrivate::get(child)->initCanvas(childState, c); - } - - if (c && focus) { - // Fixup - if (state->getFocusScope(q)->scopedFocusItem()) { - focus = false; - emit q->focusChanged(false); - } else { - QQuickCanvasPrivate::get(canvas)->setFocusInScope(state->getFocusScope(q), q); - } - } - - dirty(Canvas); - - itemChange(QQuickItem::ItemSceneChange, c); -} - -/*! -Returns a transform that maps points from canvas space into item space. -*/ -QTransform QQuickItemPrivate::canvasToItemTransform() const -{ - // XXX todo - optimize - return itemToCanvasTransform().inverted(); -} - -/*! -Returns a transform that maps points from item space into canvas space. -*/ -QTransform QQuickItemPrivate::itemToCanvasTransform() const -{ - // XXX todo - QTransform rv = parentItem?QQuickItemPrivate::get(parentItem)->itemToCanvasTransform():QTransform(); - itemToParentTransform(rv); - return rv; -} - -/*! -Motifies \a t with this items local transform relative to its parent. -*/ -void QQuickItemPrivate::itemToParentTransform(QTransform &t) const -{ - if (x || y) - t.translate(x, y); - - if (!transforms.isEmpty()) { - QMatrix4x4 m(t); - for (int ii = transforms.count() - 1; ii >= 0; --ii) - transforms.at(ii)->applyTo(&m); - t = m.toTransform(); - } - - if (scale != 1. || rotation != 0.) { - QPointF tp = computeTransformOrigin(); - t.translate(tp.x(), tp.y()); - t.scale(scale, scale); - t.rotate(rotation); - t.translate(-tp.x(), -tp.y()); - } -} - - -/*! - \qmlproperty real QtQuick2::Item::childrenRect.x - \qmlproperty real QtQuick2::Item::childrenRect.y - \qmlproperty real QtQuick2::Item::childrenRect.width - \qmlproperty real QtQuick2::Item::childrenRect.height - - The childrenRect properties allow an item access to the geometry of its - children. This property is useful if you have an item that needs to be - sized to fit its children. -*/ - - -/*! - \qmlproperty list QtQuick2::Item::children - \qmlproperty list QtQuick2::Item::resources - - The children property contains the list of visual children of this item. - The resources property contains non-visual resources that you want to - reference by name. - - Generally you can rely on Item's default property to handle all this for - you, but it can come in handy in some cases. - - \qml - Item { - children: [ - Text {}, - Rectangle {} - ] - resources: [ - Component { - id: myComponent - Text {} - } - ] - } - \endqml -*/ - -/*! - Returns true if construction of the QML component is complete; otherwise - returns false. - - It is often desirable to delay some processing until the component is - completed. - - \sa componentComplete() -*/ -bool QQuickItem::isComponentComplete() const -{ - Q_D(const QQuickItem); - return d->componentComplete; -} - -QQuickItemPrivate::QQuickItemPrivate() -: _anchors(0), _contents(0), baselineOffset(0), _anchorLines(0), _stateGroup(0), origin(QQuickItem::Center), - - flags(0), widthValid(false), heightValid(false), componentComplete(true), - keepMouse(false), keepTouch(false), hoverEnabled(false), smooth(false), focus(false), activeFocus(false), notifiedFocus(false), - notifiedActiveFocus(false), filtersChildMouseEvents(false), explicitVisible(true), - effectiveVisible(true), explicitEnable(true), effectiveEnable(true), polishScheduled(false), - inheritedLayoutMirror(false), effectiveLayoutMirror(false), isMirrorImplicit(true), - inheritMirrorFromParent(false), inheritMirrorFromItem(false), childrenDoNotOverlap(false), - - canvas(0), parentItem(0), sortedChildItems(&childItems), - - subFocusItem(0), - - x(0), y(0), width(0), height(0), implicitWidth(0), implicitHeight(0), - z(0), scale(1), rotation(0), opacity(1), - - attachedLayoutDirection(0), acceptedMouseButtons(0), - imHints(Qt::ImhMultiLine), - - keyHandler(0), - - dirtyAttributes(0), nextDirtyItem(0), prevDirtyItem(0), - - itemNodeInstance(0), opacityNode(0), clipNode(0), rootNode(0), groupNode(0), paintNode(0) - , beforePaintNode(0), effectRefCount(0), hideRefCount(0) -{ -} - -QQuickItemPrivate::~QQuickItemPrivate() -{ - if (sortedChildItems != &childItems) - delete sortedChildItems; -} - -void QQuickItemPrivate::init(QQuickItem *parent) -{ -#ifndef QT_NO_DEBUG - ++qt_item_count; - static bool atexit_registered = false; - if (!atexit_registered) { - atexit(qt_print_item_count); - atexit_registered = true; - } -#endif - - Q_Q(QQuickItem); - baselineOffset.invalidate(); - - if (parent) { - q->setParentItem(parent); - QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent); - setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent); - } -} - -void QQuickItemPrivate::data_append(QDeclarativeListProperty *prop, QObject *o) -{ - if (!o) - return; - - QQuickItem *that = static_cast(prop->object); - - // This test is measurably (albeit only slightly) faster than qobject_cast<>() - const QMetaObject *mo = o->metaObject(); - while (mo && mo != &QQuickItem::staticMetaObject) { - mo = mo->d.superdata; - } - - if (mo) { - QQuickItem *item = static_cast(o); - item->setParentItem(that); - } else { - if (o->inherits("QGraphicsItem")) - qWarning("Cannot add a QtQuick 1.0 item (%s) into a QtQuick 2.0 scene!", o->metaObject()->className()); - - // XXX todo - do we really want this behavior? - o->setParent(that); - } -} - -/*! - \qmlproperty list QtQuick2::Item::data - \default - - The data property allows you to freely mix visual children and resources - in an item. If you assign a visual item to the data list it becomes - a child and if you assign any other object type, it is added as a resource. - - So you can write: - \qml - Item { - Text {} - Rectangle {} - Timer {} - } - \endqml - - instead of: - \qml - Item { - children: [ - Text {}, - Rectangle {} - ] - resources: [ - Timer {} - ] - } - \endqml - - data is a behind-the-scenes property: you should never need to explicitly - specify it. - */ - -int QQuickItemPrivate::data_count(QDeclarativeListProperty *prop) -{ - Q_UNUSED(prop); - // XXX todo - return 0; -} - -QObject *QQuickItemPrivate::data_at(QDeclarativeListProperty *prop, int i) -{ - Q_UNUSED(prop); - Q_UNUSED(i); - // XXX todo - return 0; -} - -void QQuickItemPrivate::data_clear(QDeclarativeListProperty *prop) -{ - Q_UNUSED(prop); - // XXX todo -} - -QObject *QQuickItemPrivate::resources_at(QDeclarativeListProperty *prop, int index) -{ - const QObjectList children = prop->object->children(); - if (index < children.count()) - return children.at(index); - else - return 0; -} - -void QQuickItemPrivate::resources_append(QDeclarativeListProperty *prop, QObject *o) -{ - // XXX todo - do we really want this behavior? - o->setParent(prop->object); -} - -int QQuickItemPrivate::resources_count(QDeclarativeListProperty *prop) -{ - return prop->object->children().count(); -} - -void QQuickItemPrivate::resources_clear(QDeclarativeListProperty *prop) -{ - // XXX todo - do we really want this behavior? - const QObjectList children = prop->object->children(); - for (int index = 0; index < children.count(); index++) - children.at(index)->setParent(0); -} - -QQuickItem *QQuickItemPrivate::children_at(QDeclarativeListProperty *prop, int index) -{ - QQuickItemPrivate *p = QQuickItemPrivate::get(static_cast(prop->object)); - if (index >= p->childItems.count() || index < 0) - return 0; - else - return p->childItems.at(index); -} - -void QQuickItemPrivate::children_append(QDeclarativeListProperty *prop, QQuickItem *o) -{ - if (!o) - return; - - QQuickItem *that = static_cast(prop->object); - if (o->parentItem() == that) - o->setParentItem(0); - - o->setParentItem(that); -} - -int QQuickItemPrivate::children_count(QDeclarativeListProperty *prop) -{ - QQuickItemPrivate *p = QQuickItemPrivate::get(static_cast(prop->object)); - return p->childItems.count(); -} - -void QQuickItemPrivate::children_clear(QDeclarativeListProperty *prop) -{ - QQuickItem *that = static_cast(prop->object); - QQuickItemPrivate *p = QQuickItemPrivate::get(that); - while (!p->childItems.isEmpty()) - p->childItems.at(0)->setParentItem(0); -} - -int QQuickItemPrivate::transform_count(QDeclarativeListProperty *prop) -{ - QQuickItem *that = static_cast(prop->object); - return QQuickItemPrivate::get(that)->transforms.count(); -} - -void QQuickTransform::appendToItem(QQuickItem *item) -{ - Q_D(QQuickTransform); - if (!item) - return; - - QQuickItemPrivate *p = QQuickItemPrivate::get(item); - - if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(this)) { - p->transforms.removeOne(this); - p->transforms.append(this); - } else { - p->transforms.append(this); - d->items.append(item); - } - - p->dirty(QQuickItemPrivate::Transform); -} - -void QQuickTransform::prependToItem(QQuickItem *item) -{ - Q_D(QQuickTransform); - if (!item) - return; - - QQuickItemPrivate *p = QQuickItemPrivate::get(item); - - if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(this)) { - p->transforms.removeOne(this); - p->transforms.prepend(this); - } else { - p->transforms.prepend(this); - d->items.append(item); - } - - p->dirty(QQuickItemPrivate::Transform); -} - -void QQuickItemPrivate::transform_append(QDeclarativeListProperty *prop, QQuickTransform *transform) -{ - if (!transform) - return; - - QQuickItem *that = static_cast(prop->object); - transform->appendToItem(that); -} - -QQuickTransform *QQuickItemPrivate::transform_at(QDeclarativeListProperty *prop, int idx) -{ - QQuickItem *that = static_cast(prop->object); - QQuickItemPrivate *p = QQuickItemPrivate::get(that); - - if (idx < 0 || idx >= p->transforms.count()) - return 0; - else - return p->transforms.at(idx); -} - -void QQuickItemPrivate::transform_clear(QDeclarativeListProperty *prop) -{ - QQuickItem *that = static_cast(prop->object); - QQuickItemPrivate *p = QQuickItemPrivate::get(that); - - for (int ii = 0; ii < p->transforms.count(); ++ii) { - QQuickTransform *t = p->transforms.at(ii); - QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t); - tp->items.removeOne(that); - } - - p->transforms.clear(); - - p->dirty(QQuickItemPrivate::Transform); -} - -/*! - \property QQuickItem::childrenRect - \brief The geometry of an item's children. - - This property holds the (collective) position and size of the item's children. -*/ - -/*! - \qmlproperty real QtQuick2::Item::x - \qmlproperty real QtQuick2::Item::y - \qmlproperty real QtQuick2::Item::width - \qmlproperty real QtQuick2::Item::height - - Defines the item's position and size relative to its parent. - - \qml - Item { x: 100; y: 100; width: 100; height: 100 } - \endqml - */ - -/*! - \qmlproperty real QtQuick2::Item::z - - Sets the stacking order of sibling items. By default the stacking order is 0. - - Items with a higher stacking value are drawn on top of siblings with a - lower stacking order. Items with the same stacking value are drawn - bottom up in the order they appear. Items with a negative stacking - value are drawn under their parent's content. - - The following example shows the various effects of stacking order. - - \table - \row - \o \image declarative-item_stacking1.png - \o Same \c z - later children above earlier children: - \qml - Item { - Rectangle { - color: "red" - width: 100; height: 100 - } - Rectangle { - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - \endqml - \row - \o \image declarative-item_stacking2.png - \o Higher \c z on top: - \qml - Item { - Rectangle { - z: 1 - color: "red" - width: 100; height: 100 - } - Rectangle { - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - \endqml - \row - \o \image declarative-item_stacking3.png - \o Same \c z - children above parents: - \qml - Item { - Rectangle { - color: "red" - width: 100; height: 100 - Rectangle { - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - } - \endqml - \row - \o \image declarative-item_stacking4.png - \o Lower \c z below: - \qml - Item { - Rectangle { - color: "red" - width: 100; height: 100 - Rectangle { - z: -1 - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - } - \endqml - \endtable - */ - -/*! - \qmlproperty bool QtQuick2::Item::visible - - This property holds whether the item is visible. By default this is true. - - Setting this property directly affects the \c visible value of child - items. When set to \c false, the \c visible values of all child items also - become \c false. When set to \c true, the \c visible values of child items - are returned to \c true, unless they have explicitly been set to \c false. - - (Because of this flow-on behavior, using the \c visible property may not - have the intended effect if a property binding should only respond to - explicit property changes. In such cases it may be better to use the - \l opacity property instead.) - - Setting this property to \c false automatically causes \l focus to be set - to \c false, and this item will longer receive mouse and keyboard events. - (In contrast, setting the \l opacity to 0 does not affect the \l focus - property and the receiving of key events.) - - \note This property's value is only affected by changes to this property or - the parent's \c visible property. It does not change, for example, if this - item moves off-screen, or if the \l opacity changes to 0. -*/ - - -/*! - \qmlproperty AnchorLine QtQuick2::Item::anchors.top - \qmlproperty AnchorLine QtQuick2::Item::anchors.bottom - \qmlproperty AnchorLine QtQuick2::Item::anchors.left - \qmlproperty AnchorLine QtQuick2::Item::anchors.right - \qmlproperty AnchorLine QtQuick2::Item::anchors.horizontalCenter - \qmlproperty AnchorLine QtQuick2::Item::anchors.verticalCenter - \qmlproperty AnchorLine QtQuick2::Item::anchors.baseline - - \qmlproperty Item QtQuick2::Item::anchors.fill - \qmlproperty Item QtQuick2::Item::anchors.centerIn - - \qmlproperty real QtQuick2::Item::anchors.margins - \qmlproperty real QtQuick2::Item::anchors.topMargin - \qmlproperty real QtQuick2::Item::anchors.bottomMargin - \qmlproperty real QtQuick2::Item::anchors.leftMargin - \qmlproperty real QtQuick2::Item::anchors.rightMargin - \qmlproperty real QtQuick2::Item::anchors.horizontalCenterOffset - \qmlproperty real QtQuick2::Item::anchors.verticalCenterOffset - \qmlproperty real QtQuick2::Item::anchors.baselineOffset - - \qmlproperty bool QtQuick2::Item::anchors.mirrored - - Anchors provide a way to position an item by specifying its - relationship with other items. - - Margins apply to top, bottom, left, right, and fill anchors. - The \c anchors.margins property can be used to set all of the various margins at once, to the same value. - Note that margins are anchor-specific and are not applied if an item does not - use anchors. - - Offsets apply for horizontal center, vertical center, and baseline anchors. - - \table - \row - \o \image declarative-anchors_example.png - \o Text anchored to Image, horizontally centered and vertically below, with a margin. - \qml - Item { - Image { - id: pic - // ... - } - Text { - id: label - anchors.horizontalCenter: pic.horizontalCenter - anchors.top: pic.bottom - anchors.topMargin: 5 - // ... - } - } - \endqml - \row - \o \image declarative-anchors_example2.png - \o - Left of Text anchored to right of Image, with a margin. The y - property of both defaults to 0. - - \qml - Item { - Image { - id: pic - // ... - } - Text { - id: label - anchors.left: pic.right - anchors.leftMargin: 5 - // ... - } - } - \endqml - \endtable - - \c anchors.fill provides a convenient way for one item to have the - same geometry as another item, and is equivalent to connecting all - four directional anchors. - - To clear an anchor value, set it to \c undefined. - - \c anchors.mirrored returns true it the layout has been \l {LayoutMirroring}{mirrored}. - - \note You can only anchor an item to siblings or a parent. - - For more information see \l {anchor-layout}{Anchor Layouts}. -*/ - -/*! - \property QQuickItem::baselineOffset - \brief The position of the item's baseline in local coordinates. - - The baseline of a \l Text item is the imaginary line on which the text - sits. Controls containing text usually set their baseline to the - baseline of their text. - - For non-text items, a default baseline offset of 0 is used. -*/ -QQuickAnchors *QQuickItemPrivate::anchors() const -{ - if (!_anchors) { - Q_Q(const QQuickItem); - _anchors = new QQuickAnchors(const_cast(q)); - if (!componentComplete) - _anchors->classBegin(); - } - return _anchors; -} - -QQuickItemPrivate::AnchorLines *QQuickItemPrivate::anchorLines() const -{ - Q_Q(const QQuickItem); - if (!_anchorLines) _anchorLines = - new AnchorLines(const_cast(q)); - return _anchorLines; -} - -void QQuickItemPrivate::siblingOrderChanged() -{ - Q_Q(QQuickItem); - for (int ii = 0; ii < changeListeners.count(); ++ii) { - const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii); - if (change.types & QQuickItemPrivate::SiblingOrder) { - change.listener->itemSiblingOrderChanged(q); - } - } -} - -QDeclarativeListProperty QQuickItemPrivate::data() -{ - return QDeclarativeListProperty(q_func(), 0, QQuickItemPrivate::data_append, - QQuickItemPrivate::data_count, - QQuickItemPrivate::data_at, - QQuickItemPrivate::data_clear); -} - -QRectF QQuickItem::childrenRect() -{ - Q_D(QQuickItem); - if (!d->_contents) { - d->_contents = new QQuickContents(this); - if (d->componentComplete) - d->_contents->complete(); - } - return d->_contents->rectF(); -} - -QList QQuickItem::childItems() const -{ - Q_D(const QQuickItem); - return d->childItems; -} - -bool QQuickItem::clip() const -{ - return flags() & ItemClipsChildrenToShape; -} - -void QQuickItem::setClip(bool c) -{ - if (clip() == c) - return; - - setFlag(ItemClipsChildrenToShape, c); - - emit clipChanged(c); -} - - -/*! - This function is called to handle this item's changes in - geometry from \a oldGeometry to \a newGeometry. If the two - geometries are the same, it doesn't do anything. - */ -void QQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickItem); - - if (d->_anchors) - QQuickAnchorsPrivate::get(d->_anchors)->updateMe(); - - bool xChange = (newGeometry.x() != oldGeometry.x()); - bool yChange = (newGeometry.y() != oldGeometry.y()); - bool widthChange = (newGeometry.width() != oldGeometry.width()); - bool heightChange = (newGeometry.height() != oldGeometry.height()); - - for (int ii = 0; ii < d->changeListeners.count(); ++ii) { - const QQuickItemPrivate::ChangeListener &change = d->changeListeners.at(ii); - if (change.types & QQuickItemPrivate::Geometry) { - if (change.gTypes == QQuickItemPrivate::GeometryChange) { - change.listener->itemGeometryChanged(this, newGeometry, oldGeometry); - } else if ((xChange && (change.gTypes & QQuickItemPrivate::XChange)) || - (yChange && (change.gTypes & QQuickItemPrivate::YChange)) || - (widthChange && (change.gTypes & QQuickItemPrivate::WidthChange)) || - (heightChange && (change.gTypes & QQuickItemPrivate::HeightChange))) { - change.listener->itemGeometryChanged(this, newGeometry, oldGeometry); - } - } - } - - if (xChange) - emit xChanged(); - if (yChange) - emit yChanged(); - if (widthChange) - emit widthChanged(); - if (heightChange) - emit heightChanged(); -} - -/*! - Called by the rendering thread when it is time to sync the state of the QML objects with the - scene graph objects. The function should return the root of the scene graph subtree for - this item. \a oldNode is the node that was returned the last time the function was called. - - The main thread is blocked while this function is executed so it is safe to read - values from the QQuickItem instance and other objects in the main thread. - - \warning This is the only function in which it is allowed to make use of scene graph - objects from the main thread. Use of scene graph objects outside this function will - result in race conditions and potential crashes. - */ - -QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - delete oldNode; - return 0; -} - -QSGTransformNode *QQuickItemPrivate::createTransformNode() -{ - return new QSGTransformNode; -} - -void QQuickItem::updatePolish() -{ -} - -void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types) -{ - ChangeListener change(listener, types); - changeListeners.removeOne(change); -} - -void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types) -{ - ChangeListener change(listener, types); - int index = changeListeners.find(change); - if (index > -1) - changeListeners[index].gTypes = change.gTypes; //we may have different GeometryChangeTypes - else - changeListeners.append(change); -} - -void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types) -{ - ChangeListener change(listener, types); - if (types == NoChange) { - changeListeners.removeOne(change); - } else { - int index = changeListeners.find(change); - if (index > -1) - changeListeners[index].gTypes = change.gTypes; //we may have different GeometryChangeTypes - } -} - -void QQuickItem::keyPressEvent(QKeyEvent *event) -{ - event->ignore(); -} - -void QQuickItem::keyReleaseEvent(QKeyEvent *event) -{ - event->ignore(); -} - -void QQuickItem::inputMethodEvent(QInputMethodEvent *event) -{ - event->ignore(); -} - -void QQuickItem::focusInEvent(QFocusEvent *) -{ -} - -void QQuickItem::focusOutEvent(QFocusEvent *) -{ -} - -void QQuickItem::mousePressEvent(QMouseEvent *event) -{ - event->ignore(); -} - -void QQuickItem::mouseMoveEvent(QMouseEvent *event) -{ - event->ignore(); -} - -void QQuickItem::mouseReleaseEvent(QMouseEvent *event) -{ - event->ignore(); -} - -void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event) -{ - mousePressEvent(event); -} - -void QQuickItem::mouseUngrabEvent() -{ - // XXX todo -} - -void QQuickItem::touchUngrabEvent() -{ - // XXX todo -} - -void QQuickItem::wheelEvent(QWheelEvent *event) -{ - event->ignore(); -} - -void QQuickItem::touchEvent(QTouchEvent *event) -{ - event->ignore(); -} - -void QQuickItem::hoverEnterEvent(QHoverEvent *event) -{ - Q_UNUSED(event); -} - -void QQuickItem::hoverMoveEvent(QHoverEvent *event) -{ - Q_UNUSED(event); -} - -void QQuickItem::hoverLeaveEvent(QHoverEvent *event) -{ - Q_UNUSED(event); -} - -void QQuickItem::dragEnterEvent(QDragEnterEvent *event) -{ - Q_UNUSED(event); -} - -void QQuickItem::dragMoveEvent(QDragMoveEvent *event) -{ - - Q_UNUSED(event); -} - -void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event) -{ - - Q_UNUSED(event); -} - -void QQuickItem::dropEvent(QDropEvent *event) -{ - Q_UNUSED(event); -} - -bool QQuickItem::childMouseEventFilter(QQuickItem *, QEvent *) -{ - return false; -} - -void QQuickItem::windowDeactivateEvent() -{ - foreach (QQuickItem* item, childItems()) { - item->windowDeactivateEvent(); - } -} - -Qt::InputMethodHints QQuickItem::inputMethodHints() const -{ - Q_D(const QQuickItem); - return d->imHints; -} - -void QQuickItem::setInputMethodHints(Qt::InputMethodHints hints) -{ - Q_D(QQuickItem); - d->imHints = hints; - - if (!d->canvas || d->canvas->activeFocusItem() != this) - return; - - QInputPanel *p = qApp->inputPanel(); - if (p->inputItem() == this) - qApp->inputPanel()->update(Qt::ImHints); -} - -void QQuickItem::updateMicroFocus() -{ - QInputPanel *p = qApp->inputPanel(); - if (p->inputItem() == this) - qApp->inputPanel()->update(Qt::ImQueryInput); -} - -QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query) const -{ - Q_D(const QQuickItem); - QVariant v; - - switch (query) { - case Qt::ImEnabled: - v = (bool)(flags() & ItemAcceptsInputMethod); - break; - case Qt::ImHints: - v = (int)inputMethodHints(); - break; - case Qt::ImCursorRectangle: - case Qt::ImFont: - case Qt::ImCursorPosition: - case Qt::ImSurroundingText: - case Qt::ImCurrentSelection: - case Qt::ImMaximumTextLength: - case Qt::ImAnchorPosition: - case Qt::ImPreferredLanguage: - if (d->keyHandler) - v = d->keyHandler->inputMethodQuery(query); - default: - break; - } - - return v; -} - -QQuickAnchorLine QQuickItemPrivate::left() const -{ - return anchorLines()->left; -} - -QQuickAnchorLine QQuickItemPrivate::right() const -{ - return anchorLines()->right; -} - -QQuickAnchorLine QQuickItemPrivate::horizontalCenter() const -{ - return anchorLines()->hCenter; -} - -QQuickAnchorLine QQuickItemPrivate::top() const -{ - return anchorLines()->top; -} - -QQuickAnchorLine QQuickItemPrivate::bottom() const -{ - return anchorLines()->bottom; -} - -QQuickAnchorLine QQuickItemPrivate::verticalCenter() const -{ - return anchorLines()->vCenter; -} - -QQuickAnchorLine QQuickItemPrivate::baseline() const -{ - return anchorLines()->baseline; -} - -qreal QQuickItem::baselineOffset() const -{ - Q_D(const QQuickItem); - if (!d->baselineOffset.isValid()) { - return 0.0; - } else - return d->baselineOffset; -} - -void QQuickItem::setBaselineOffset(qreal offset) -{ - Q_D(QQuickItem); - if (offset == d->baselineOffset) - return; - - d->baselineOffset = offset; - - for (int ii = 0; ii < d->changeListeners.count(); ++ii) { - const QQuickItemPrivate::ChangeListener &change = d->changeListeners.at(ii); - if (change.types & QQuickItemPrivate::Geometry) { - QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate(); - if (anchor) - anchor->updateVerticalAnchors(); - } - } - emit baselineOffsetChanged(offset); -} - -void QQuickItem::update() -{ - Q_D(QQuickItem); - Q_ASSERT(flags() & ItemHasContents); - d->dirty(QQuickItemPrivate::Content); -} - -void QQuickItem::polish() -{ - Q_D(QQuickItem); - if (!d->polishScheduled) { - d->polishScheduled = true; - if (d->canvas) { - QQuickCanvasPrivate *p = QQuickCanvasPrivate::get(d->canvas); - bool maybeupdate = p->itemsToPolish.isEmpty(); - p->itemsToPolish.insert(this); - if (maybeupdate) d->canvas->maybeUpdate(); - } - } -} - -void QQuickItem::mapFromItem(QDeclarativeV8Function *args) const -{ - if (args->Length() != 0) { - v8::Local item = (*args)[0]; - QV8Engine *engine = args->engine(); - - QQuickItem *itemObj = 0; - if (!item->IsNull()) - itemObj = qobject_cast(engine->toQObject(item)); - - if (!itemObj && !item->IsNull()) { - qmlInfo(this) << "mapFromItem() given argument \"" << engine->toString(item->ToString()) - << "\" which is neither null nor an Item"; - return; - } - - v8::Local rv = v8::Object::New(); - args->returnValue(rv); - - qreal x = (args->Length() > 1)?(*args)[1]->NumberValue():0; - qreal y = (args->Length() > 2)?(*args)[2]->NumberValue():0; - - QPointF p = mapFromItem(itemObj, QPointF(x, y)); - - rv->Set(v8::String::New("x"), v8::Number::New(p.x())); - rv->Set(v8::String::New("y"), v8::Number::New(p.y())); - } -} - -QTransform QQuickItem::itemTransform(QQuickItem *other, bool *ok) const -{ - Q_D(const QQuickItem); - - // XXX todo - we need to be able to handle common parents better and detect - // invalid cases - if (ok) *ok = true; - - QTransform t = d->itemToCanvasTransform(); - if (other) t *= QQuickItemPrivate::get(other)->canvasToItemTransform(); - - return t; -} - -void QQuickItem::mapToItem(QDeclarativeV8Function *args) const -{ - if (args->Length() != 0) { - v8::Local item = (*args)[0]; - QV8Engine *engine = args->engine(); - - QQuickItem *itemObj = 0; - if (!item->IsNull()) - itemObj = qobject_cast(engine->toQObject(item)); - - if (!itemObj && !item->IsNull()) { - qmlInfo(this) << "mapToItem() given argument \"" << engine->toString(item->ToString()) - << "\" which is neither null nor an Item"; - return; - } - - v8::Local rv = v8::Object::New(); - args->returnValue(rv); - - qreal x = (args->Length() > 1)?(*args)[1]->NumberValue():0; - qreal y = (args->Length() > 2)?(*args)[2]->NumberValue():0; - - QPointF p = mapToItem(itemObj, QPointF(x, y)); - - rv->Set(v8::String::New("x"), v8::Number::New(p.x())); - rv->Set(v8::String::New("y"), v8::Number::New(p.y())); - } -} - -void QQuickItem::forceActiveFocus() -{ - setFocus(true); - QQuickItem *parent = parentItem(); - while (parent) { - if (parent->flags() & QQuickItem::ItemIsFocusScope) { - parent->setFocus(true); - } - parent = parent->parentItem(); - } -} - -QQuickItem *QQuickItem::childAt(qreal x, qreal y) const -{ - // XXX todo - should this include transform etc.? - const QList children = childItems(); - for (int i = children.count()-1; i >= 0; --i) { - QQuickItem *child = children.at(i); - if (child->isVisible() && child->x() <= x - && child->x() + child->width() >= x - && child->y() <= y - && child->y() + child->height() >= y) - return child; - } - return 0; -} - -QDeclarativeListProperty QQuickItemPrivate::resources() -{ - return QDeclarativeListProperty(q_func(), 0, QQuickItemPrivate::resources_append, - QQuickItemPrivate::resources_count, - QQuickItemPrivate::resources_at, - QQuickItemPrivate::resources_clear); -} - -QDeclarativeListProperty QQuickItemPrivate::children() -{ - return QDeclarativeListProperty(q_func(), 0, QQuickItemPrivate::children_append, - QQuickItemPrivate::children_count, - QQuickItemPrivate::children_at, - QQuickItemPrivate::children_clear); - -} - -QDeclarativeListProperty QQuickItemPrivate::states() -{ - return _states()->statesProperty(); -} - -QDeclarativeListProperty QQuickItemPrivate::transitions() -{ - return _states()->transitionsProperty(); -} - -QString QQuickItemPrivate::state() const -{ - if (!_stateGroup) - return QString(); - else - return _stateGroup->state(); -} - -void QQuickItemPrivate::setState(const QString &state) -{ - _states()->setState(state); -} - -QString QQuickItem::state() const -{ - Q_D(const QQuickItem); - return d->state(); -} - -void QQuickItem::setState(const QString &state) -{ - Q_D(QQuickItem); - d->setState(state); -} - -QDeclarativeListProperty QQuickItem::transform() -{ - return QDeclarativeListProperty(this, 0, QQuickItemPrivate::transform_append, - QQuickItemPrivate::transform_count, - QQuickItemPrivate::transform_at, - QQuickItemPrivate::transform_clear); -} - -void QQuickItem::classBegin() -{ - Q_D(QQuickItem); - d->componentComplete = false; - if (d->_stateGroup) - d->_stateGroup->classBegin(); - if (d->_anchors) - d->_anchors->classBegin(); -} - -void QQuickItem::componentComplete() -{ - Q_D(QQuickItem); - d->componentComplete = true; - if (d->_stateGroup) - d->_stateGroup->componentComplete(); - if (d->_anchors) { - d->_anchors->componentComplete(); - QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete(); - } - if (d->keyHandler) - d->keyHandler->componentComplete(); - if (d->_contents) - d->_contents->complete(); -} - -QDeclarativeStateGroup *QQuickItemPrivate::_states() -{ - Q_Q(QQuickItem); - if (!_stateGroup) { - _stateGroup = new QDeclarativeStateGroup; - if (!componentComplete) - _stateGroup->classBegin(); - FAST_CONNECT(_stateGroup, SIGNAL(stateChanged(QString)), - q, SIGNAL(stateChanged(QString))) - } - - return _stateGroup; -} - -QQuickItemPrivate::AnchorLines::AnchorLines(QQuickItem *q) -{ - left.item = q; - left.anchorLine = QQuickAnchorLine::Left; - right.item = q; - right.anchorLine = QQuickAnchorLine::Right; - hCenter.item = q; - hCenter.anchorLine = QQuickAnchorLine::HCenter; - top.item = q; - top.anchorLine = QQuickAnchorLine::Top; - bottom.item = q; - bottom.anchorLine = QQuickAnchorLine::Bottom; - vCenter.item = q; - vCenter.anchorLine = QQuickAnchorLine::VCenter; - baseline.item = q; - baseline.anchorLine = QQuickAnchorLine::Baseline; -} - -QPointF QQuickItemPrivate::computeTransformOrigin() const -{ - switch (origin) { - default: - case QQuickItem::TopLeft: - return QPointF(0, 0); - case QQuickItem::Top: - return QPointF(width / 2., 0); - case QQuickItem::TopRight: - return QPointF(width, 0); - case QQuickItem::Left: - return QPointF(0, height / 2.); - case QQuickItem::Center: - return QPointF(width / 2., height / 2.); - case QQuickItem::Right: - return QPointF(width, height / 2.); - case QQuickItem::BottomLeft: - return QPointF(0, height); - case QQuickItem::Bottom: - return QPointF(width / 2., height); - case QQuickItem::BottomRight: - return QPointF(width, height); - } -} - -void QQuickItemPrivate::transformChanged() -{ -} - -void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e) -{ - Q_Q(QQuickItem); - - Q_ASSERT(e->isAccepted()); - if (keyHandler) { - if (e->type() == QEvent::KeyPress) - keyHandler->keyPressed(e, false); - else - keyHandler->keyReleased(e, false); - - if (e->isAccepted()) - return; - else - e->accept(); - } - - if (e->type() == QEvent::KeyPress) - q->keyPressEvent(e); - else - q->keyReleaseEvent(e); - - if (e->isAccepted()) - return; - - if (keyHandler) { - e->accept(); - - if (e->type() == QEvent::KeyPress) - keyHandler->keyPressed(e, true); - else - keyHandler->keyReleased(e, true); - } -} - -void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e) -{ - Q_Q(QQuickItem); - - Q_ASSERT(e->isAccepted()); - if (keyHandler) { - keyHandler->inputMethodEvent(e, false); - - if (e->isAccepted()) - return; - else - e->accept(); - } - - q->inputMethodEvent(e); - - if (e->isAccepted()) - return; - - if (keyHandler) { - e->accept(); - - keyHandler->inputMethodEvent(e, true); - } -} - -void QQuickItemPrivate::deliverFocusEvent(QFocusEvent *e) -{ - Q_Q(QQuickItem); - - if (e->type() == QEvent::FocusIn) { - q->focusInEvent(e); - } else { - q->focusOutEvent(e); - } -} - -void QQuickItemPrivate::deliverMouseEvent(QMouseEvent *e) -{ - Q_Q(QQuickItem); - - Q_ASSERT(e->isAccepted()); - - switch (e->type()) { - default: - Q_ASSERT(!"Unknown event type"); - case QEvent::MouseMove: - q->mouseMoveEvent(e); - break; - case QEvent::MouseButtonPress: - q->mousePressEvent(e); - break; - case QEvent::MouseButtonRelease: - q->mouseReleaseEvent(e); - break; - case QEvent::MouseButtonDblClick: - q->mouseDoubleClickEvent(e); - break; - } -} - -void QQuickItemPrivate::deliverWheelEvent(QWheelEvent *e) -{ - Q_Q(QQuickItem); - q->wheelEvent(e); -} - -void QQuickItemPrivate::deliverTouchEvent(QTouchEvent *e) -{ - Q_Q(QQuickItem); - q->touchEvent(e); -} - -void QQuickItemPrivate::deliverHoverEvent(QHoverEvent *e) -{ - Q_Q(QQuickItem); - switch (e->type()) { - default: - Q_ASSERT(!"Unknown event type"); - case QEvent::HoverEnter: - q->hoverEnterEvent(e); - break; - case QEvent::HoverLeave: - q->hoverLeaveEvent(e); - break; - case QEvent::HoverMove: - q->hoverMoveEvent(e); - break; - } -} - -void QQuickItemPrivate::deliverDragEvent(QEvent *e) -{ - Q_Q(QQuickItem); - switch (e->type()) { - default: - Q_ASSERT(!"Unknown event type"); - case QEvent::DragEnter: - q->dragEnterEvent(static_cast(e)); - break; - case QEvent::DragLeave: - q->dragLeaveEvent(static_cast(e)); - break; - case QEvent::DragMove: - q->dragMoveEvent(static_cast(e)); - break; - case QEvent::Drop: - q->dropEvent(static_cast(e)); - break; - } -} - -void QQuickItem::itemChange(ItemChange change, const ItemChangeData &value) -{ - Q_UNUSED(change); - Q_UNUSED(value); -} - -/*! \internal */ -// XXX todo - do we want/need this anymore? -// Note that it's now used for varying clip rect -QRectF QQuickItem::boundingRect() const -{ - Q_D(const QQuickItem); - return QRectF(0, 0, d->width, d->height); -} - -QQuickItem::TransformOrigin QQuickItem::transformOrigin() const -{ - Q_D(const QQuickItem); - return d->origin; -} - -void QQuickItem::setTransformOrigin(TransformOrigin origin) -{ - Q_D(QQuickItem); - if (origin == d->origin) - return; - - d->origin = origin; - d->dirty(QQuickItemPrivate::TransformOrigin); - - emit transformOriginChanged(d->origin); -} - -QPointF QQuickItem::transformOriginPoint() const -{ - Q_D(const QQuickItem); - if (!d->transformOriginPoint.isNull()) - return d->transformOriginPoint; - return d->computeTransformOrigin(); -} - -void QQuickItem::setTransformOriginPoint(const QPointF &point) -{ - Q_D(QQuickItem); - if (d->transformOriginPoint == point) - return; - - d->transformOriginPoint = point; - d->dirty(QQuickItemPrivate::TransformOrigin); -} - -qreal QQuickItem::z() const -{ - Q_D(const QQuickItem); - return d->z; -} - -void QQuickItem::setZ(qreal v) -{ - Q_D(QQuickItem); - if (d->z == v) - return; - - d->z = v; - - d->dirty(QQuickItemPrivate::ZValue); - if (d->parentItem) { - QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged); - QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(this); - } - - emit zChanged(); -} - - -/*! - \qmlproperty real QtQuick2::Item::rotation - This property holds the rotation of the item in degrees clockwise. - - This specifies how many degrees to rotate the item around its transformOrigin. - The default rotation is 0 degrees (i.e. not rotated at all). - - \table - \row - \o \image declarative-rotation.png - \o - \qml - Rectangle { - color: "blue" - width: 100; height: 100 - Rectangle { - color: "red" - x: 25; y: 25; width: 50; height: 50 - rotation: 30 - } - } - \endqml - \endtable - - \sa transform, Rotation -*/ - -/*! - \qmlproperty real QtQuick2::Item::scale - This property holds the scale of the item. - - A scale of less than 1 means the item will be displayed smaller than - normal, and a scale of greater than 1 means the item will be - displayed larger than normal. A negative scale means the item will - be mirrored. - - By default, items are displayed at a scale of 1 (i.e. at their - normal size). - - Scaling is from the item's transformOrigin. - - \table - \row - \o \image declarative-scale.png - \o - \qml - Rectangle { - color: "blue" - width: 100; height: 100 - Rectangle { - color: "green" - width: 25; height: 25 - } - Rectangle { - color: "red" - x: 25; y: 25; width: 50; height: 50 - scale: 1.4 - } - } - \endqml - \endtable - - \sa transform, Scale -*/ - -/*! - \qmlproperty real QtQuick2::Item::opacity - - This property holds the opacity of the item. Opacity is specified as a - number between 0 (fully transparent) and 1 (fully opaque). The default is 1. - - When this property is set, the specified opacity is also applied - individually to child items. In almost all cases this is what you want, - but in some cases it may produce undesired results. For example in the - second set of rectangles below, the red rectangle has specified an opacity - of 0.5, which affects the opacity of its blue child rectangle even though - the child has not specified an opacity. - - \table - \row - \o \image declarative-item_opacity1.png - \o - \qml - Item { - Rectangle { - color: "red" - width: 100; height: 100 - Rectangle { - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - } - \endqml - \row - \o \image declarative-item_opacity2.png - \o - \qml - Item { - Rectangle { - opacity: 0.5 - color: "red" - width: 100; height: 100 - Rectangle { - color: "blue" - x: 50; y: 50; width: 100; height: 100 - } - } - } - \endqml - \endtable - - If an item's opacity is set to 0, the item will no longer receive mouse - events, but will continue to receive key events and will retain the keyboard - \l focus if it has been set. (In contrast, setting the \l visible property - to \c false stops both mouse and keyboard events, and also removes focus - from the item.) -*/ - -/*! - Returns a value indicating whether mouse input should - remain with this item exclusively. - - \sa setKeepMouseGrab() - */ - -qreal QQuickItem::rotation() const -{ - Q_D(const QQuickItem); - return d->rotation; -} - -void QQuickItem::setRotation(qreal r) -{ - Q_D(QQuickItem); - if (d->rotation == r) - return; - - d->rotation = r; - - d->dirty(QQuickItemPrivate::BasicTransform); - - d->itemChange(ItemRotationHasChanged, r); - - emit rotationChanged(); -} - -qreal QQuickItem::scale() const -{ - Q_D(const QQuickItem); - return d->scale; -} - -void QQuickItem::setScale(qreal s) -{ - Q_D(QQuickItem); - if (d->scale == s) - return; - - d->scale = s; - - d->dirty(QQuickItemPrivate::BasicTransform); - - emit scaleChanged(); -} - -qreal QQuickItem::opacity() const -{ - Q_D(const QQuickItem); - return d->opacity; -} - -void QQuickItem::setOpacity(qreal o) -{ - Q_D(QQuickItem); - if (d->opacity == o) - return; - - d->opacity = o; - - d->dirty(QQuickItemPrivate::OpacityValue); - - d->itemChange(ItemOpacityHasChanged, o); - - emit opacityChanged(); -} - -bool QQuickItem::isVisible() const -{ - Q_D(const QQuickItem); - return d->effectiveVisible; -} - -void QQuickItem::setVisible(bool v) -{ - Q_D(QQuickItem); - if (v == d->explicitVisible) - return; - - d->explicitVisible = v; - - d->setEffectiveVisibleRecur(d->calcEffectiveVisible()); -} - -bool QQuickItem::isEnabled() const -{ - Q_D(const QQuickItem); - return d->effectiveEnable; -} - -void QQuickItem::setEnabled(bool e) -{ - Q_D(QQuickItem); - if (e == d->explicitEnable) - return; - - d->explicitEnable = e; - - d->setEffectiveEnableRecur(d->calcEffectiveEnable()); -} - -bool QQuickItemPrivate::calcEffectiveVisible() const -{ - // XXX todo - Should the effective visible of an element with no parent just be the current - // effective visible? This would prevent pointless re-processing in the case of an element - // moving to/from a no-parent situation, but it is different from what graphics view does. - return explicitVisible && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveVisible); -} - -void QQuickItemPrivate::setEffectiveVisibleRecur(bool newEffectiveVisible) -{ - Q_Q(QQuickItem); - - if (newEffectiveVisible && !explicitVisible) { - // This item locally overrides visibility - return; - } - - if (newEffectiveVisible == effectiveVisible) { - // No change necessary - return; - } - - effectiveVisible = newEffectiveVisible; - dirty(Visible); - if (parentItem) QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged); - - if (canvas) { - QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(canvas); - if (canvasPriv->mouseGrabberItem == q) - q->ungrabMouse(); - } - - for (int ii = 0; ii < childItems.count(); ++ii) - QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible); - - for (int ii = 0; ii < changeListeners.count(); ++ii) { - const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii); - if (change.types & QQuickItemPrivate::Visibility) - change.listener->itemVisibilityChanged(q); - } - - emit q->visibleChanged(); -} - -bool QQuickItemPrivate::calcEffectiveEnable() const -{ - // XXX todo - Should the effective enable of an element with no parent just be the current - // effective enable? This would prevent pointless re-processing in the case of an element - // moving to/from a no-parent situation, but it is different from what graphics view does. - return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable); -} - -void QQuickItemPrivate::setEffectiveEnableRecur(bool newEffectiveEnable) -{ - Q_Q(QQuickItem); - - // XXX todo - need to fixup focus - - if (newEffectiveEnable && !explicitEnable) { - // This item locally overrides enable - return; - } - - if (newEffectiveEnable == effectiveEnable) { - // No change necessary - return; - } - - effectiveEnable = newEffectiveEnable; - - if (canvas) { - QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(canvas); - if (canvasPriv->mouseGrabberItem == q) - q->ungrabMouse(); - } - - for (int ii = 0; ii < childItems.count(); ++ii) - QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(newEffectiveEnable); - - emit q->enabledChanged(); -} - -QString QQuickItemPrivate::dirtyToString() const -{ -#define DIRTY_TO_STRING(value) if (dirtyAttributes & value) { \ - if (!rv.isEmpty()) \ - rv.append(QLatin1String("|")); \ - rv.append(QLatin1String(#value)); \ -} - -// QString rv = QLatin1String("0x") + QString::number(dirtyAttributes, 16); - QString rv; - - DIRTY_TO_STRING(TransformOrigin); - DIRTY_TO_STRING(Transform); - DIRTY_TO_STRING(BasicTransform); - DIRTY_TO_STRING(Position); - DIRTY_TO_STRING(Size); - DIRTY_TO_STRING(ZValue); - DIRTY_TO_STRING(Content); - DIRTY_TO_STRING(Smooth); - DIRTY_TO_STRING(OpacityValue); - DIRTY_TO_STRING(ChildrenChanged); - DIRTY_TO_STRING(ChildrenStackingChanged); - DIRTY_TO_STRING(ParentChanged); - DIRTY_TO_STRING(Clip); - DIRTY_TO_STRING(Canvas); - DIRTY_TO_STRING(EffectReference); - DIRTY_TO_STRING(Visible); - DIRTY_TO_STRING(HideReference); - - return rv; -} - -void QQuickItemPrivate::dirty(DirtyType type) -{ - Q_Q(QQuickItem); - if (type & (TransformOrigin | Transform | BasicTransform | Position | Size)) - transformChanged(); - - if (!(dirtyAttributes & type) || (canvas && !prevDirtyItem)) { - dirtyAttributes |= type; - if (canvas) { - addToDirtyList(); - QQuickCanvasPrivate::get(canvas)->dirtyItem(q); - } - } -} - -void QQuickItemPrivate::addToDirtyList() -{ - Q_Q(QQuickItem); - - Q_ASSERT(canvas); - if (!prevDirtyItem) { - Q_ASSERT(!nextDirtyItem); - - QQuickCanvasPrivate *p = QQuickCanvasPrivate::get(canvas); - nextDirtyItem = p->dirtyItemList; - if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem; - prevDirtyItem = &p->dirtyItemList; - p->dirtyItemList = q; - p->dirtyItem(q); - } - Q_ASSERT(prevDirtyItem); -} - -void QQuickItemPrivate::removeFromDirtyList() -{ - if (prevDirtyItem) { - if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem; - *prevDirtyItem = nextDirtyItem; - prevDirtyItem = 0; - nextDirtyItem = 0; - } - Q_ASSERT(!prevDirtyItem); - Q_ASSERT(!nextDirtyItem); -} - -void QQuickItemPrivate::refFromEffectItem(bool hide) -{ - ++effectRefCount; - if (1 == effectRefCount) { - dirty(EffectReference); - if (parentItem) QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged); - } - if (hide) { - if (++hideRefCount == 1) - dirty(HideReference); - } -} - -void QQuickItemPrivate::derefFromEffectItem(bool unhide) -{ - Q_ASSERT(effectRefCount); - --effectRefCount; - if (0 == effectRefCount) { - dirty(EffectReference); - if (parentItem) QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged); - } - if (unhide) { - if (--hideRefCount == 0) - dirty(HideReference); - } -} - -void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) -{ - Q_Q(QQuickItem); - switch (change) { - case QQuickItem::ItemChildAddedChange: - q->itemChange(change, data); - for (int ii = 0; ii < changeListeners.count(); ++ii) { - const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii); - if (change.types & QQuickItemPrivate::Children) { - change.listener->itemChildAdded(q, data.item); - } - } - break; - case QQuickItem::ItemChildRemovedChange: - q->itemChange(change, data); - for (int ii = 0; ii < changeListeners.count(); ++ii) { - const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii); - if (change.types & QQuickItemPrivate::Children) { - change.listener->itemChildRemoved(q, data.item); - } - } - break; - case QQuickItem::ItemSceneChange: - q->itemChange(change, data); - break; - case QQuickItem::ItemVisibleHasChanged: - q->itemChange(change, data); - for (int ii = 0; ii < changeListeners.count(); ++ii) { - const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii); - if (change.types & QQuickItemPrivate::Visibility) { - change.listener->itemVisibilityChanged(q); - } - } - break; - case QQuickItem::ItemParentHasChanged: - q->itemChange(change, data); - for (int ii = 0; ii < changeListeners.count(); ++ii) { - const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii); - if (change.types & QQuickItemPrivate::Parent) { - change.listener->itemParentChanged(q, data.item); - } - } - break; - case QQuickItem::ItemOpacityHasChanged: - q->itemChange(change, data); - for (int ii = 0; ii < changeListeners.count(); ++ii) { - const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii); - if (change.types & QQuickItemPrivate::Opacity) { - change.listener->itemOpacityChanged(q); - } - } - break; - case QQuickItem::ItemActiveFocusHasChanged: - q->itemChange(change, data); - break; - case QQuickItem::ItemRotationHasChanged: - q->itemChange(change, data); - for (int ii = 0; ii < changeListeners.count(); ++ii) { - const QQuickItemPrivate::ChangeListener &change = changeListeners.at(ii); - if (change.types & QQuickItemPrivate::Rotation) { - change.listener->itemRotationChanged(q); - } - } - break; - } -} - -/*! - \property QQuickItem::smooth - \brief whether the item is smoothly transformed. - - This property is provided purely for the purpose of optimization. Turning - smooth transforms off is faster, but looks worse; turning smooth - transformations on is slower, but looks better. - - By default smooth transformations are off. -*/ - -/*! - Returns true if the item should be drawn with antialiasing and - smooth pixmap filtering, false otherwise. - - The default is false. - - \sa setSmooth() -*/ -bool QQuickItem::smooth() const -{ - Q_D(const QQuickItem); - return d->smooth; -} - -/*! - Sets whether the item should be drawn with antialiasing and - smooth pixmap filtering to \a smooth. - - \sa smooth() -*/ -void QQuickItem::setSmooth(bool smooth) -{ - Q_D(QQuickItem); - if (d->smooth == smooth) - return; - - d->smooth = smooth; - d->dirty(QQuickItemPrivate::Smooth); - - emit smoothChanged(smooth); -} - -QQuickItem::Flags QQuickItem::flags() const -{ - Q_D(const QQuickItem); - return (QQuickItem::Flags)d->flags; -} - -void QQuickItem::setFlag(Flag flag, bool enabled) -{ - Q_D(QQuickItem); - if (enabled) - setFlags((Flags)(d->flags | (quint32)flag)); - else - setFlags((Flags)(d->flags & ~(quint32)flag)); -} - -void QQuickItem::setFlags(Flags flags) -{ - Q_D(QQuickItem); - - if ((flags & ItemIsFocusScope) != (d->flags & ItemIsFocusScope)) { - if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->canvas) { - qWarning("QQuickItem: Cannot set FocusScope once item has children and is in a canvas."); - flags &= ~ItemIsFocusScope; - } else if (d->flags & ItemIsFocusScope) { - qWarning("QQuickItem: Cannot unset FocusScope flag."); - flags |= ItemIsFocusScope; - } - } - - if ((flags & ItemClipsChildrenToShape ) != (d->flags & ItemClipsChildrenToShape)) - d->dirty(QQuickItemPrivate::Clip); - - d->flags = flags; -} - -qreal QQuickItem::x() const -{ - Q_D(const QQuickItem); - return d->x; -} - -qreal QQuickItem::y() const -{ - Q_D(const QQuickItem); - return d->y; -} - -QPointF QQuickItem::pos() const -{ - Q_D(const QQuickItem); - return QPointF(d->x, d->y); -} - -void QQuickItem::setX(qreal v) -{ - Q_D(QQuickItem); - if (d->x == v) - return; - - qreal oldx = d->x; - d->x = v; - - d->dirty(QQuickItemPrivate::Position); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(oldx, y(), width(), height())); -} - -void QQuickItem::setY(qreal v) -{ - Q_D(QQuickItem); - if (d->y == v) - return; - - qreal oldy = d->y; - d->y = v; - - d->dirty(QQuickItemPrivate::Position); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), oldy, width(), height())); -} - -void QQuickItem::setPos(const QPointF &pos) -{ - Q_D(QQuickItem); - if (QPointF(d->x, d->y) == pos) - return; - - qreal oldx = d->x; - qreal oldy = d->y; - - d->x = pos.x(); - d->y = pos.y(); - - d->dirty(QQuickItemPrivate::Position); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(oldx, oldy, width(), height())); -} - -qreal QQuickItem::width() const -{ - Q_D(const QQuickItem); - return d->width; -} - -void QQuickItem::setWidth(qreal w) -{ - Q_D(QQuickItem); - if (qIsNaN(w)) - return; - - d->widthValid = true; - if (d->width == w) - return; - - qreal oldWidth = d->width; - d->width = w; - - d->dirty(QQuickItemPrivate::Size); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), oldWidth, height())); -} - -void QQuickItem::resetWidth() -{ - Q_D(QQuickItem); - d->widthValid = false; - setImplicitWidth(implicitWidth()); -} - -void QQuickItemPrivate::implicitWidthChanged() -{ - Q_Q(QQuickItem); - emit q->implicitWidthChanged(); -} - -qreal QQuickItemPrivate::getImplicitWidth() const -{ - return implicitWidth; -} -/*! - Returns the width of the item that is implied by other properties that determine the content. -*/ -qreal QQuickItem::implicitWidth() const -{ - Q_D(const QQuickItem); - return d->getImplicitWidth(); -} - -/*! - \qmlproperty real QtQuick2::Item::implicitWidth - \qmlproperty real QtQuick2::Item::implicitHeight - - Defines the natural width or height of the Item if no \l width or \l height is specified. - - The default implicit size for most items is 0x0, however some elements have an inherent - implicit size which cannot be overridden, e.g. Image, Text. - - Setting the implicit size is useful for defining components that have a preferred size - based on their content, for example: - - \qml - // Label.qml - import QtQuick 1.1 - - Item { - property alias icon: image.source - property alias label: text.text - implicitWidth: text.implicitWidth + image.implicitWidth - implicitHeight: Math.max(text.implicitHeight, image.implicitHeight) - Image { id: image } - Text { - id: text - wrapMode: Text.Wrap - anchors.left: image.right; anchors.right: parent.right - anchors.verticalCenter: parent.verticalCenter - } - } - \endqml - - \bold Note: using implicitWidth of Text or TextEdit and setting the width explicitly - incurs a performance penalty as the text must be laid out twice. -*/ - -/*! - Sets the implied width of the item to \a w. - This is the width implied by other properties that determine the content. -*/ -void QQuickItem::setImplicitWidth(qreal w) -{ - Q_D(QQuickItem); - bool changed = w != d->implicitWidth; - d->implicitWidth = w; - if (d->width == w || widthValid()) { - if (changed) - d->implicitWidthChanged(); - return; - } - - qreal oldWidth = d->width; - d->width = w; - - d->dirty(QQuickItemPrivate::Size); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), oldWidth, height())); - - if (changed) - d->implicitWidthChanged(); -} - -/*! - Returns whether the width property has been set explicitly. -*/ -bool QQuickItem::widthValid() const -{ - Q_D(const QQuickItem); - return d->widthValid; -} - -qreal QQuickItem::height() const -{ - Q_D(const QQuickItem); - return d->height; -} - -void QQuickItem::setHeight(qreal h) -{ - Q_D(QQuickItem); - if (qIsNaN(h)) - return; - - d->heightValid = true; - if (d->height == h) - return; - - qreal oldHeight = d->height; - d->height = h; - - d->dirty(QQuickItemPrivate::Size); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), width(), oldHeight)); -} - -void QQuickItem::resetHeight() -{ - Q_D(QQuickItem); - d->heightValid = false; - setImplicitHeight(implicitHeight()); -} - -void QQuickItemPrivate::implicitHeightChanged() -{ - Q_Q(QQuickItem); - emit q->implicitHeightChanged(); -} - -qreal QQuickItemPrivate::getImplicitHeight() const -{ - return implicitHeight; -} - -/*! - Returns the height of the item that is implied by other properties that determine the content. -*/ -qreal QQuickItem::implicitHeight() const -{ - Q_D(const QQuickItem); - return d->getImplicitHeight(); -} - - -/*! - Sets the implied height of the item to \a h. - This is the height implied by other properties that determine the content. -*/ -void QQuickItem::setImplicitHeight(qreal h) -{ - Q_D(QQuickItem); - bool changed = h != d->implicitHeight; - d->implicitHeight = h; - if (d->height == h || heightValid()) { - if (changed) - d->implicitHeightChanged(); - return; - } - - qreal oldHeight = d->height; - d->height = h; - - d->dirty(QQuickItemPrivate::Size); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), width(), oldHeight)); - - if (changed) - d->implicitHeightChanged(); -} - -void QQuickItem::setImplicitSize(qreal w, qreal h) -{ - Q_D(QQuickItem); - bool wChanged = w != d->implicitWidth; - bool hChanged = h != d->implicitHeight; - - d->implicitWidth = w; - d->implicitHeight = h; - - bool wDone = false; - bool hDone = false; - if (d->width == w || widthValid()) { - if (wChanged) - d->implicitWidthChanged(); - wDone = true; - } - if (d->height == h || heightValid()) { - if (hChanged) - d->implicitHeightChanged(); - hDone = true; - } - if (wDone && hDone) - return; - - qreal oldWidth = d->width; - qreal oldHeight = d->height; - if (!wDone) - d->width = w; - if (!hDone) - d->height = h; - - d->dirty(QQuickItemPrivate::Size); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), oldWidth, oldHeight)); - - if (!wDone && wChanged) - d->implicitWidthChanged(); - if (!hDone && hChanged) - d->implicitHeightChanged(); -} - -/*! - Returns whether the height property has been set explicitly. -*/ -bool QQuickItem::heightValid() const -{ - Q_D(const QQuickItem); - return d->heightValid; -} - -void QQuickItem::setSize(const QSizeF &size) -{ - Q_D(QQuickItem); - d->heightValid = true; - d->widthValid = true; - - if (QSizeF(d->width, d->height) == size) - return; - - qreal oldHeight = d->height; - qreal oldWidth = d->width; - d->height = size.height(); - d->width = size.width(); - - d->dirty(QQuickItemPrivate::Size); - - geometryChanged(QRectF(x(), y(), width(), height()), - QRectF(x(), y(), oldWidth, oldHeight)); -} - -bool QQuickItem::hasActiveFocus() const -{ - Q_D(const QQuickItem); - return d->activeFocus; -} - -bool QQuickItem::hasFocus() const -{ - Q_D(const QQuickItem); - return d->focus; -} - -void QQuickItem::setFocus(bool focus) -{ - Q_D(QQuickItem); - if (d->focus == focus) - return; - - if (d->canvas) { - // Need to find our nearest focus scope - QQuickItem *scope = parentItem(); - while (scope && !scope->isFocusScope()) - scope = scope->parentItem(); - if (focus) - QQuickCanvasPrivate::get(d->canvas)->setFocusInScope(scope, this); - else - QQuickCanvasPrivate::get(d->canvas)->clearFocusInScope(scope, this); - } else { - d->focus = focus; - emit focusChanged(focus); - } -} - -bool QQuickItem::isFocusScope() const -{ - return flags() & ItemIsFocusScope; -} - -QQuickItem *QQuickItem::scopedFocusItem() const -{ - Q_D(const QQuickItem); - if (!isFocusScope()) - return 0; - else - return d->subFocusItem; -} - - -Qt::MouseButtons QQuickItem::acceptedMouseButtons() const -{ - Q_D(const QQuickItem); - return d->acceptedMouseButtons; -} - -void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons) -{ - Q_D(QQuickItem); - d->acceptedMouseButtons = buttons; -} - -bool QQuickItem::filtersChildMouseEvents() const -{ - Q_D(const QQuickItem); - return d->filtersChildMouseEvents; -} - -void QQuickItem::setFiltersChildMouseEvents(bool filter) -{ - Q_D(QQuickItem); - d->filtersChildMouseEvents = filter; -} - -bool QQuickItem::isUnderMouse() const -{ - Q_D(const QQuickItem); - if (!d->canvas) - return false; - - QPoint cursorPos = QCursor::pos(); - if (QRectF(0, 0, width(), height()).contains(mapFromScene(cursorPos))) // ### refactor: d->canvas->mapFromGlobal(cursorPos)))) - return true; - return false; -} - -bool QQuickItem::acceptHoverEvents() const -{ - Q_D(const QQuickItem); - return d->hoverEnabled; -} - -void QQuickItem::setAcceptHoverEvents(bool enabled) -{ - Q_D(QQuickItem); - d->hoverEnabled = enabled; -} - -void QQuickItem::grabMouse() -{ - Q_D(QQuickItem); - if (!d->canvas) - return; - QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(d->canvas); - if (canvasPriv->mouseGrabberItem == this) - return; - - QQuickItem *oldGrabber = canvasPriv->mouseGrabberItem; - canvasPriv->mouseGrabberItem = this; - if (oldGrabber) - oldGrabber->mouseUngrabEvent(); -} - -void QQuickItem::ungrabMouse() -{ - Q_D(QQuickItem); - if (!d->canvas) - return; - QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(d->canvas); - if (canvasPriv->mouseGrabberItem != this) { - qWarning("QQuickItem::ungrabMouse(): Item is not the mouse grabber."); - return; - } - - canvasPriv->mouseGrabberItem = 0; - mouseUngrabEvent(); -} - -bool QQuickItem::keepMouseGrab() const -{ - Q_D(const QQuickItem); - return d->keepMouse; -} - -/*! - The flag indicating whether the mouse should remain - with this item is set to \a keep. - - This is useful for items that wish to grab and keep mouse - interaction following a predefined gesture. For example, - an item that is interested in horizontal mouse movement - may set keepMouseGrab to true once a threshold has been - exceeded. Once keepMouseGrab has been set to true, filtering - items will not react to mouse events. - - If the item does not indicate that it wishes to retain mouse grab, - a filtering item may steal the grab. For example, Flickable may attempt - to steal a mouse grab if it detects that the user has begun to - move the viewport. - - \sa keepMouseGrab() - */ -void QQuickItem::setKeepMouseGrab(bool keep) -{ - Q_D(QQuickItem); - d->keepMouse = keep; -} - -/*! - Grabs the touch points specified by \a ids. - - These touch points will be owned by the item until - they are released. Alternatively, the grab can be stolen - by a filtering item like Flickable. Use setKeepTouchGrab() - to prevent the grab from being stolen. - - \sa ungrabTouchPoints(), setKeepTouchGrab() -*/ -void QQuickItem::grabTouchPoints(const QList &ids) -{ - Q_D(QQuickItem); - if (!d->canvas) - return; - QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(d->canvas); - - QSet ungrab; - for (int i = 0; i < ids.count(); ++i) { - QQuickItem *oldGrabber = canvasPriv->itemForTouchPointId.value(ids.at(i)); - if (oldGrabber == this) - return; - - canvasPriv->itemForTouchPointId[ids.at(i)] = this; - if (oldGrabber) - ungrab.insert(oldGrabber); - } - foreach (QQuickItem *oldGrabber, ungrab) - oldGrabber->touchUngrabEvent(); -} - -/*! - Ungrabs the touch points owned by this item. - - \sa grabTouchPoints() -*/ -void QQuickItem::ungrabTouchPoints() -{ - Q_D(QQuickItem); - if (!d->canvas) - return; - QQuickCanvasPrivate *canvasPriv = QQuickCanvasPrivate::get(d->canvas); - - QMutableHashIterator i(canvasPriv->itemForTouchPointId); - while (i.hasNext()) { - i.next(); - if (i.value() == this) - i.remove(); - } - touchUngrabEvent(); -} - -/*! - Returns a value indicating whether the touch points grabbed by this item - should remain with this item exclusively. - - \sa setKeepTouchGrab(), keepMouseGrab() -*/ -bool QQuickItem::keepTouchGrab() const -{ - Q_D(const QQuickItem); - return d->keepTouch; -} - -/*! - The flag indicating whether the touch points grabbed - by this item should remain with this item is set to \a keep. - - This is useful for items that wish to grab and keep specific touch - points following a predefined gesture. For example, - an item that is interested in horizontal touch point movement - may set setKeepTouchGrab to true once a threshold has been - exceeded. Once setKeepTouchGrab has been set to true, filtering - items will not react to the relevant touch points. - - If the item does not indicate that it wishes to retain touch point grab, - a filtering item may steal the grab. For example, Flickable may attempt - to steal a touch point grab if it detects that the user has begun to - move the viewport. - - \sa keepTouchGrab(), setKeepMouseGrab() - */ -void QQuickItem::setKeepTouchGrab(bool keep) -{ - Q_D(QQuickItem); - d->keepTouch = keep; -} - -/*! - \qmlmethod object QtQuick2::Item::mapFromItem(Item item, real x, real y) - - Maps the point (\a x, \a y), which is in \a item's coordinate system, to - this item's coordinate system, and returns an object with \c x and \c y - properties matching the mapped coordinate. - - If \a item is a \c null value, this maps the point from the coordinate - system of the root QML view. -*/ -/*! - \qmlmethod object QtQuick2::Item::mapToItem(Item item, real x, real y) - - Maps the point (\a x, \a y), which is in this item's coordinate system, to - \a item's coordinate system, and returns an object with \c x and \c y - properties matching the mapped coordinate. - - If \a item is a \c null value, this maps \a x and \a y to the coordinate - system of the root QML view. -*/ -QPointF QQuickItem::mapToItem(const QQuickItem *item, const QPointF &point) const -{ - QPointF p = mapToScene(point); - if (item) - p = item->mapFromScene(p); - return p; -} - -QPointF QQuickItem::mapToScene(const QPointF &point) const -{ - Q_D(const QQuickItem); - return d->itemToCanvasTransform().map(point); -} - -QRectF QQuickItem::mapRectToItem(const QQuickItem *item, const QRectF &rect) const -{ - Q_D(const QQuickItem); - QTransform t = d->itemToCanvasTransform(); - if (item) - t *= QQuickItemPrivate::get(item)->canvasToItemTransform(); - return t.mapRect(rect); -} - -QRectF QQuickItem::mapRectToScene(const QRectF &rect) const -{ - Q_D(const QQuickItem); - return d->itemToCanvasTransform().mapRect(rect); -} - -QPointF QQuickItem::mapFromItem(const QQuickItem *item, const QPointF &point) const -{ - QPointF p = item?item->mapToScene(point):point; - return mapFromScene(p); -} - -QPointF QQuickItem::mapFromScene(const QPointF &point) const -{ - Q_D(const QQuickItem); - return d->canvasToItemTransform().map(point); -} - -QRectF QQuickItem::mapRectFromItem(const QQuickItem *item, const QRectF &rect) const -{ - Q_D(const QQuickItem); - QTransform t = item?QQuickItemPrivate::get(item)->itemToCanvasTransform():QTransform(); - t *= d->canvasToItemTransform(); - return t.mapRect(rect); -} - -QRectF QQuickItem::mapRectFromScene(const QRectF &rect) const -{ - Q_D(const QQuickItem); - return d->canvasToItemTransform().mapRect(rect); -} - - -/*! - \qmlmethod QtQuick2::Item::forceActiveFocus() - - Forces active focus on the item. - - This method sets focus on the item and makes sure that all the focus scopes - higher in the object hierarchy are also given the focus. -*/ - -/*! - Forces active focus on the item. - - This method sets focus on the item and makes sure that all the focus scopes - higher in the object hierarchy are also given the focus. -*/ - -/*! - \qmlmethod QtQuick2::Item::childAt(real x, real y) - - Returns the visible child item at point (\a x, \a y), which is in this - item's coordinate system, or \c null if there is no such item. -*/ - -/*! - Returns the visible child item at point (\a x, \a y), which is in this - item's coordinate system, or 0 if there is no such item. -*/ - -/*! - \qmlproperty list QtQuick2::Item::states - This property holds a list of states defined by the item. - - \qml - Item { - states: [ - State { - // ... - }, - State { - // ... - } - // ... - ] - } - \endqml - - \sa {qmlstate}{States} -*/ -/*! - \qmlproperty list QtQuick2::Item::transitions - This property holds a list of transitions defined by the item. - - \qml - Item { - transitions: [ - Transition { - // ... - }, - Transition { - // ... - } - // ... - ] - } - \endqml - - \sa {QML Animation and Transitions}{Transitions} -*/ -/* - \qmlproperty list QtQuick2::Item::filter - This property holds a list of graphical filters to be applied to the item. - - \l {Filter}{Filters} include things like \l {Blur}{blurring} - the item, or giving it a \l Reflection. Some - filters may not be available on all canvases; if a filter is not - available on a certain canvas, it will simply not be applied for - that canvas (but the QML will still be considered valid). - - \qml - Item { - filter: [ - Blur { - // ... - }, - Reflection { - // ... - } - // ... - ] - } - \endqml -*/ - -/*! - \qmlproperty bool QtQuick2::Item::clip - This property holds whether clipping is enabled. The default clip value is \c false. - - If clipping is enabled, an item will clip its own painting, as well - as the painting of its children, to its bounding rectangle. - - Non-rectangular clipping regions are not supported for performance reasons. -*/ - -/*! - \property QQuickItem::clip - This property holds whether clipping is enabled. The default clip value is \c false. - - If clipping is enabled, an item will clip its own painting, as well - as the painting of its children, to its bounding rectangle. If you set - clipping during an item's paint operation, remember to re-set it to - prevent clipping the rest of your scene. - - Non-rectangular clipping regions are not supported for performance reasons. -*/ - -/*! - \qmlproperty string QtQuick2::Item::state - - This property holds the name of the current state of the item. - - This property is often used in scripts to change between states. For - example: - - \js - function toggle() { - if (button.state == 'On') - button.state = 'Off'; - else - button.state = 'On'; - } - \endjs - - If the item is in its base state (i.e. no explicit state has been - set), \c state will be a blank string. Likewise, you can return an - item to its base state by setting its current state to \c ''. - - \sa {qmlstates}{States} -*/ - -/*! - \qmlproperty list QtQuick2::Item::transform - This property holds the list of transformations to apply. - - For more information see \l Transform. -*/ - -/*! - \enum QQuickItem::TransformOrigin - - Controls the point about which simple transforms like scale apply. - - \value TopLeft The top-left corner of the item. - \value Top The center point of the top of the item. - \value TopRight The top-right corner of the item. - \value Left The left most point of the vertical middle. - \value Center The center of the item. - \value Right The right most point of the vertical middle. - \value BottomLeft The bottom-left corner of the item. - \value Bottom The center point of the bottom of the item. - \value BottomRight The bottom-right corner of the item. -*/ - - -/*! - \qmlproperty bool QtQuick2::Item::activeFocus - - This property indicates whether the item has active focus. - - An item with active focus will receive keyboard input, - or is a FocusScope ancestor of the item that will receive keyboard input. - - Usually, activeFocus is gained by setting focus on an item and its enclosing - FocusScopes. In the following example \c input will have activeFocus. - \qml - Rectangle { - FocusScope { - focus: true - TextInput { - id: input - focus: true - } - } - } - \endqml - - \sa focus, {qmlfocus}{Keyboard Focus} -*/ - -/*! - \qmlproperty bool QtQuick2::Item::focus - This property indicates whether the item has focus within the enclosing focus scope. If true, this item - will gain active focus when the enclosing focus scope gains active focus. - In the following example, \c input will be given active focus when \c scope gains active focus. - \qml - Rectangle { - FocusScope { - id: scope - TextInput { - id: input - focus: true - } - } - } - \endqml - - For the purposes of this property, the scene as a whole is assumed to act like a focus scope. - On a practical level, that means the following QML will give active focus to \c input on startup. - - \qml - Rectangle { - TextInput { - id: input - focus: true - } - } - \endqml - - \sa activeFocus, {qmlfocus}{Keyboard Focus} -*/ - - -/*! - \property QQuickItem::anchors - \internal -*/ - -/*! - \property QQuickItem::left - \internal -*/ - -/*! - \property QQuickItem::right - \internal -*/ - -/*! - \property QQuickItem::horizontalCenter - \internal -*/ - -/*! - \property QQuickItem::top - \internal -*/ - -/*! - \property QQuickItem::bottom - \internal -*/ - -/*! - \property QQuickItem::verticalCenter - \internal -*/ - -/*! - \property QQuickItem::focus - \internal -*/ - -/*! - \property QQuickItem::transform - \internal -*/ - -/*! - \property QQuickItem::transformOrigin - \internal -*/ - -/*! - \property QQuickItem::activeFocus - \internal -*/ - -/*! - \property QQuickItem::baseline - \internal -*/ - -/*! - \property QQuickItem::data - \internal -*/ - -/*! - \property QQuickItem::resources - \internal -*/ - -/*! - \property QQuickItem::state - \internal -*/ - -/*! - \property QQuickItem::states - \internal -*/ - -/*! - \property QQuickItem::transformOriginPoint - \internal -*/ - -/*! - \property QQuickItem::transitions - \internal -*/ - -bool QQuickItem::event(QEvent *ev) -{ -#if 0 - if (ev->type() == QEvent::PolishRequest) { - Q_D(QQuickItem); - d->polishScheduled = false; - updatePolish(); - return true; - } else { - return QObject::event(ev); - } -#endif - if (ev->type() == QEvent::InputMethodQuery) { - QInputMethodQueryEvent *query = static_cast(ev); - Qt::InputMethodQueries queries = query->queries(); - for (uint i = 0; i < 32; ++i) { - Qt::InputMethodQuery q = (Qt::InputMethodQuery)(int)(queries & (1<setValue(q, v); - } - } - query->accept(); - return true; - } else if (ev->type() == QEvent::InputMethod) { - inputMethodEvent(static_cast(ev)); - return true; - } - return QObject::event(ev); -} - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug debug, QQuickItem *item) -{ - if (!item) { - debug << "QQuickItem(0)"; - return debug; - } - - debug << item->metaObject()->className() << "(this =" << ((void*)item) - << ", name=" << item->objectName() - << ", parent =" << ((void*)item->parentItem()) - << ", geometry =" << QRectF(item->pos(), QSizeF(item->width(), item->height())) - << ", z =" << item->z() << ')'; - return debug; -} -#endif - -qint64 QQuickItemPrivate::consistentTime = -1; -void QQuickItemPrivate::setConsistentTime(qint64 t) -{ - consistentTime = t; -} - -class QElapsedTimerConsistentTimeHack -{ -public: - void start() { - t1 = QQuickItemPrivate::consistentTime; - t2 = 0; - } - qint64 elapsed() { - return QQuickItemPrivate::consistentTime - t1; - } - qint64 restart() { - qint64 val = QQuickItemPrivate::consistentTime - t1; - t1 = QQuickItemPrivate::consistentTime; - t2 = 0; - return val; - } - -private: - qint64 t1; - qint64 t2; -}; - -void QQuickItemPrivate::start(QElapsedTimer &t) -{ - if (QQuickItemPrivate::consistentTime == -1) - t.start(); - else - ((QElapsedTimerConsistentTimeHack*)&t)->start(); -} - -qint64 QQuickItemPrivate::elapsed(QElapsedTimer &t) -{ - if (QQuickItemPrivate::consistentTime == -1) - return t.elapsed(); - else - return ((QElapsedTimerConsistentTimeHack*)&t)->elapsed(); -} - -qint64 QQuickItemPrivate::restart(QElapsedTimer &t) -{ - if (QQuickItemPrivate::consistentTime == -1) - return t.restart(); - else - return ((QElapsedTimerConsistentTimeHack*)&t)->restart(); -} - -/*! - \fn bool QQuickItem::isTextureProvider() const - - Returns true if this item is a texture provider. The default - implementation returns false. - - This function can be called from any thread. - */ - -/*! - \fn QSGTextureProvider *QQuickItem::textureProvider() const - - Returns the texture provider for an item. The default implementation - returns 0. - - This function may only be called on the rendering thread. - */ - -QT_END_NAMESPACE - -#include diff --git a/src/declarative/items/qquickitem.h b/src/declarative/items/qquickitem.h deleted file mode 100644 index a3baecb9ea..0000000000 --- a/src/declarative/items/qquickitem.h +++ /dev/null @@ -1,421 +0,0 @@ -// Commit: 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4 -/**************************************************************************** -** -** 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$ -** 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 QQUICKITEM_H -#define QQUICKITEM_H - -#include -#include - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickItem; -class QQuickTransformPrivate; -class QQuickTransform : public QObject -{ - Q_OBJECT -public: - QQuickTransform(QObject *parent = 0); - ~QQuickTransform(); - - void appendToItem(QQuickItem *); - void prependToItem(QQuickItem *); - - virtual void applyTo(QMatrix4x4 *matrix) const = 0; - -protected Q_SLOTS: - void update(); - -protected: - QQuickTransform(QQuickTransformPrivate &dd, QObject *parent); - -private: - Q_DECLARE_PRIVATE(QQuickTransform) -}; - -class QDeclarativeV8Function; -class QDeclarativeState; -class QQuickAnchorLine; -class QDeclarativeTransition; -class QQuickKeyEvent; -class QQuickAnchors; -class QQuickItemPrivate; -class QQuickCanvas; -class QSGEngine; -class QTouchEvent; -class QSGNode; -class QSGTransformNode; -class QSGTextureProvider; - -class Q_DECLARATIVE_EXPORT QQuickItem : public QObject, public QDeclarativeParserStatus -{ - Q_OBJECT - Q_INTERFACES(QDeclarativeParserStatus) - - Q_PROPERTY(QQuickItem *parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty data READ data DESIGNABLE false) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty resources READ resources DESIGNABLE false) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty children READ children NOTIFY childrenChanged DESIGNABLE false) - - Q_PROPERTY(QPointF pos READ pos FINAL) - Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL) - Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL) - Q_PROPERTY(qreal z READ z WRITE setZ NOTIFY zChanged FINAL) - Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL) - Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL) - - Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL) - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL) - - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty states READ states DESIGNABLE false) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty transitions READ transitions DESIGNABLE false) - Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) - Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine left READ left CONSTANT FINAL) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine right READ right CONSTANT FINAL) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine top READ top CONSTANT FINAL) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine bottom READ bottom CONSTANT FINAL) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL) - Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine baseline READ baseline CONSTANT FINAL) - Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged) - - Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged) - - Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL) - Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL) - - Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged) - Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged) - Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged) - Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint) // XXX todo - notify? - Q_PROPERTY(QDeclarativeListProperty transform READ transform DESIGNABLE false FINAL) - - Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) - Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged) - Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged) - - Q_ENUMS(TransformOrigin) - Q_CLASSINFO("DefaultProperty", "data") - -public: - enum Flag { - ItemClipsChildrenToShape = 0x01, - ItemAcceptsInputMethod = 0x02, - ItemIsFocusScope = 0x04, - ItemHasContents = 0x08, - ItemAcceptsDrops = 0x10 - // Remember to increment the size of QQuickItemPrivate::flags - }; - Q_DECLARE_FLAGS(Flags, Flag) - - enum ItemChange { - ItemChildAddedChange, // value.item - ItemChildRemovedChange, // value.item - ItemSceneChange, // value.canvas - ItemVisibleHasChanged, // value.realValue - ItemParentHasChanged, // value.item - ItemOpacityHasChanged, // value.realValue - ItemActiveFocusHasChanged, // value.boolValue - ItemRotationHasChanged // value.realValue - }; - - union ItemChangeData { - ItemChangeData(QQuickItem *v) : item(v) {} - ItemChangeData(QQuickCanvas *v) : canvas(v) {} - ItemChangeData(qreal v) : realValue(v) {} - ItemChangeData(bool v) : boolValue(v) {} - - QQuickItem *item; - QQuickCanvas *canvas; - qreal realValue; - bool boolValue; - }; - - enum TransformOrigin { - TopLeft, Top, TopRight, - Left, Center, Right, - BottomLeft, Bottom, BottomRight - }; - - QQuickItem(QQuickItem *parent = 0); - virtual ~QQuickItem(); - - QSGEngine *sceneGraphEngine() const; - - QQuickCanvas *canvas() const; - QQuickItem *parentItem() const; - void setParentItem(QQuickItem *parent); - void stackBefore(const QQuickItem *); - void stackAfter(const QQuickItem *); - - QRectF childrenRect(); - QList childItems() const; - - bool clip() const; - void setClip(bool); - - QString state() const; - void setState(const QString &); - - qreal baselineOffset() const; - void setBaselineOffset(qreal); - - QDeclarativeListProperty transform(); - - qreal x() const; - qreal y() const; - QPointF pos() const; - void setX(qreal); - void setY(qreal); - void setPos(const QPointF &); - - qreal width() const; - void setWidth(qreal); - void resetWidth(); - qreal implicitWidth() const; - - qreal height() const; - void setHeight(qreal); - void resetHeight(); - qreal implicitHeight() const; - - void setSize(const QSizeF &size); - - TransformOrigin transformOrigin() const; - void setTransformOrigin(TransformOrigin); - QPointF transformOriginPoint() const; - void setTransformOriginPoint(const QPointF &); - - qreal z() const; - void setZ(qreal); - - qreal rotation() const; - void setRotation(qreal); - qreal scale() const; - void setScale(qreal); - - qreal opacity() const; - void setOpacity(qreal); - - bool isVisible() const; - void setVisible(bool); - - bool isEnabled() const; - void setEnabled(bool); - - bool smooth() const; - void setSmooth(bool); - - Flags flags() const; - void setFlag(Flag flag, bool enabled = true); - void setFlags(Flags flags); - - virtual QRectF boundingRect() const; - - bool hasActiveFocus() const; - bool hasFocus() const; - void setFocus(bool); - bool isFocusScope() const; - QQuickItem *scopedFocusItem() const; - - Qt::MouseButtons acceptedMouseButtons() const; - void setAcceptedMouseButtons(Qt::MouseButtons buttons); - bool acceptHoverEvents() const; - void setAcceptHoverEvents(bool enabled); - - bool isUnderMouse() const; - void grabMouse(); - void ungrabMouse(); - bool keepMouseGrab() const; - void setKeepMouseGrab(bool); - bool filtersChildMouseEvents() const; - void setFiltersChildMouseEvents(bool filter); - - void grabTouchPoints(const QList &ids); - void ungrabTouchPoints(); - bool keepTouchGrab() const; - void setKeepTouchGrab(bool); - - QTransform itemTransform(QQuickItem *, bool *) const; - QPointF mapToItem(const QQuickItem *item, const QPointF &point) const; - QPointF mapToScene(const QPointF &point) const; - QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const; - QRectF mapRectToScene(const QRectF &rect) const; - QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const; - QPointF mapFromScene(const QPointF &point) const; - QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const; - QRectF mapRectFromScene(const QRectF &rect) const; - - void polish(); - - Q_INVOKABLE void mapFromItem(QDeclarativeV8Function*) const; - Q_INVOKABLE void mapToItem(QDeclarativeV8Function*) const; - Q_INVOKABLE void forceActiveFocus(); - Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const; - - Qt::InputMethodHints inputMethodHints() const; - void setInputMethodHints(Qt::InputMethodHints hints); - virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - - struct UpdatePaintNodeData { - QSGTransformNode *transformNode; - private: - friend class QQuickCanvasPrivate; - UpdatePaintNodeData(); - }; - - virtual bool isTextureProvider() const { return false; } - virtual QSGTextureProvider *textureProvider() const { return 0; } - -public Q_SLOTS: - void update(); - void updateMicroFocus(); - -Q_SIGNALS: - void childrenRectChanged(const QRectF &); - void baselineOffsetChanged(qreal); - void stateChanged(const QString &); - void focusChanged(bool); - void activeFocusChanged(bool); - void parentChanged(QQuickItem *); - void transformOriginChanged(TransformOrigin); - void smoothChanged(bool); - void clipChanged(bool); - - // XXX todo - void childrenChanged(); - void opacityChanged(); - void enabledChanged(); - void visibleChanged(); - void rotationChanged(); - void scaleChanged(); - - void xChanged(); - void yChanged(); - void widthChanged(); - void heightChanged(); - void zChanged(); - void implicitWidthChanged(); - void implicitHeightChanged(); - -protected: - virtual bool event(QEvent *); - - bool isComponentComplete() const; - virtual void itemChange(ItemChange, const ItemChangeData &); - - void setImplicitWidth(qreal); - bool widthValid() const; // ### better name? - void setImplicitHeight(qreal); - bool heightValid() const; // ### better name? - void setImplicitSize(qreal, qreal); - - virtual void classBegin(); - virtual void componentComplete(); - - virtual void keyPressEvent(QKeyEvent *event); - virtual void keyReleaseEvent(QKeyEvent *event); - virtual void inputMethodEvent(QInputMethodEvent *); - virtual void focusInEvent(QFocusEvent *); - virtual void focusOutEvent(QFocusEvent *); - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - virtual void mouseDoubleClickEvent(QMouseEvent *event); - virtual void mouseUngrabEvent(); // XXX todo - params? - virtual void touchUngrabEvent(); - virtual void wheelEvent(QWheelEvent *event); - virtual void touchEvent(QTouchEvent *event); - virtual void hoverEnterEvent(QHoverEvent *event); - virtual void hoverMoveEvent(QHoverEvent *event); - virtual void hoverLeaveEvent(QHoverEvent *event); - virtual void dragEnterEvent(QDragEnterEvent *); - virtual void dragMoveEvent(QDragMoveEvent *); - virtual void dragLeaveEvent(QDragLeaveEvent *); - virtual void dropEvent(QDropEvent *); - virtual bool childMouseEventFilter(QQuickItem *, QEvent *); - virtual void windowDeactivateEvent(); - - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - - virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - virtual void updatePolish(); - -protected: - QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0); - -private: - friend class QQuickCanvas; - friend class QQuickCanvasPrivate; - friend class QSGRenderer; - Q_DISABLE_COPY(QQuickItem) - Q_DECLARE_PRIVATE(QQuickItem) -}; - -// XXX todo -Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags) - -#ifndef QT_NO_DEBUG_STREAM -QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QQuickItem *item); -#endif - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickItem) -QML_DECLARE_TYPE(QQuickTransform) - -QT_END_HEADER - -#endif // QQUICKITEM_H diff --git a/src/declarative/items/qquickitem_p.h b/src/declarative/items/qquickitem_p.h deleted file mode 100644 index 08ae7fac9b..0000000000 --- a/src/declarative/items/qquickitem_p.h +++ /dev/null @@ -1,752 +0,0 @@ -// Commit: 5c783d0a9a912816813945387903857a314040b5 -/**************************************************************************** -** -** 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$ -** 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 QQUICKITEM_P_H -#define QQUICKITEM_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 "qquickitem.h" - -#include "qquickanchors_p.h" -#include "qquickanchors_p_p.h" -#include "qquickitemchangelistener_p.h" - -#include "qquickcanvas_p.h" - -#include -#include "qquickclipnode_p.h" - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QNetworkReply; -class QQuickItemKeyFilter; -class QQuickLayoutMirroringAttached; - -class QQuickContents : public QQuickItemChangeListener -{ -public: - QQuickContents(QQuickItem *item); - ~QQuickContents(); - - QRectF rectF() const { return QRectF(m_x, m_y, m_width, m_height); } - - inline void calcGeometry(QQuickItem *changed = 0); - void complete(); - -protected: - void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry); - void itemDestroyed(QQuickItem *item); - void itemChildAdded(QQuickItem *, QQuickItem *); - void itemChildRemoved(QQuickItem *, QQuickItem *); - //void itemVisibilityChanged(QQuickItem *item) - -private: - bool calcHeight(QQuickItem *changed = 0); - bool calcWidth(QQuickItem *changed = 0); - void updateRect(); - - QQuickItem *m_item; - qreal m_x; - qreal m_y; - qreal m_width; - qreal m_height; -}; - -void QQuickContents::calcGeometry(QQuickItem *changed) -{ - bool wChanged = calcWidth(changed); - bool hChanged = calcHeight(changed); - if (wChanged || hChanged) - updateRect(); -} - -class QQuickTransformPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QQuickTransform); -public: - static QQuickTransformPrivate* get(QQuickTransform *transform) { return transform->d_func(); } - - QQuickTransformPrivate(); - - QList items; -}; - -class Q_DECLARATIVE_EXPORT QQuickItemPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QQuickItem) - -public: - static QQuickItemPrivate* get(QQuickItem *item) { return item->d_func(); } - static const QQuickItemPrivate* get(const QQuickItem *item) { return item->d_func(); } - - QQuickItemPrivate(); - ~QQuickItemPrivate(); - void init(QQuickItem *parent); - - QDeclarativeListProperty data(); - QDeclarativeListProperty resources(); - QDeclarativeListProperty children(); - - QDeclarativeListProperty states(); - QDeclarativeListProperty transitions(); - - QString state() const; - void setState(const QString &); - - QQuickAnchorLine left() const; - QQuickAnchorLine right() const; - QQuickAnchorLine horizontalCenter() const; - QQuickAnchorLine top() const; - QQuickAnchorLine bottom() const; - QQuickAnchorLine verticalCenter() const; - QQuickAnchorLine baseline() const; - - // data property - static void data_append(QDeclarativeListProperty *, QObject *); - static int data_count(QDeclarativeListProperty *); - static QObject *data_at(QDeclarativeListProperty *, int); - static void data_clear(QDeclarativeListProperty *); - - // resources property - static QObject *resources_at(QDeclarativeListProperty *, int); - static void resources_append(QDeclarativeListProperty *, QObject *); - static int resources_count(QDeclarativeListProperty *); - static void resources_clear(QDeclarativeListProperty *); - - // children property - static void children_append(QDeclarativeListProperty *, QQuickItem *); - static int children_count(QDeclarativeListProperty *); - static QQuickItem *children_at(QDeclarativeListProperty *, int); - static void children_clear(QDeclarativeListProperty *); - - // transform property - static int transform_count(QDeclarativeListProperty *list); - static void transform_append(QDeclarativeListProperty *list, QQuickTransform *); - static QQuickTransform *transform_at(QDeclarativeListProperty *list, int); - static void transform_clear(QDeclarativeListProperty *list); - - QQuickAnchors *anchors() const; - mutable QQuickAnchors *_anchors; - QQuickContents *_contents; - - QDeclarativeNullableValue baselineOffset; - - struct AnchorLines { - AnchorLines(QQuickItem *); - QQuickAnchorLine left; - QQuickAnchorLine right; - QQuickAnchorLine hCenter; - QQuickAnchorLine top; - QQuickAnchorLine bottom; - QQuickAnchorLine vCenter; - QQuickAnchorLine baseline; - }; - mutable AnchorLines *_anchorLines; - AnchorLines *anchorLines() const; - - enum ChangeType { - Geometry = 0x01, - SiblingOrder = 0x02, - Visibility = 0x04, - Opacity = 0x08, - Destroyed = 0x10, - Parent = 0x20, - Children = 0x40, - Rotation = 0x80, - }; - - Q_DECLARE_FLAGS(ChangeTypes, ChangeType) - - enum GeometryChangeType { - NoChange = 0, - XChange = 0x01, - YChange = 0x02, - WidthChange = 0x04, - HeightChange = 0x08, - SizeChange = WidthChange | HeightChange, - GeometryChange = XChange | YChange | SizeChange - }; - - Q_DECLARE_FLAGS(GeometryChangeTypes, GeometryChangeType) - - struct ChangeListener { - ChangeListener(QQuickItemChangeListener *l, QQuickItemPrivate::ChangeTypes t) : listener(l), types(t), gTypes(GeometryChange) {} - ChangeListener(QQuickItemChangeListener *l, QQuickItemPrivate::GeometryChangeTypes gt) : listener(l), types(Geometry), gTypes(gt) {} - QQuickItemChangeListener *listener; - QQuickItemPrivate::ChangeTypes types; - QQuickItemPrivate::GeometryChangeTypes gTypes; //NOTE: not used for == - bool operator==(const ChangeListener &other) const { return listener == other.listener && types == other.types; } - }; - - void addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types) { - changeListeners.append(ChangeListener(listener, types)); - } - void removeItemChangeListener(QQuickItemChangeListener *, ChangeTypes types); - void updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types); - void updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types); - QPODVector changeListeners; - - QDeclarativeStateGroup *_states(); - QDeclarativeStateGroup *_stateGroup; - - QQuickItem::TransformOrigin origin:5; - quint32 flags:5; - bool widthValid:1; - bool heightValid:1; - bool componentComplete:1; - bool keepMouse:1; - bool keepTouch:1; - bool hoverEnabled:1; - bool smooth:1; - bool focus:1; - bool activeFocus:1; - bool notifiedFocus:1; - bool notifiedActiveFocus:1; - bool filtersChildMouseEvents:1; - bool explicitVisible:1; - bool effectiveVisible:1; - bool explicitEnable:1; - bool effectiveEnable:1; - bool polishScheduled:1; - bool inheritedLayoutMirror:1; - bool effectiveLayoutMirror:1; - bool isMirrorImplicit:1; - bool inheritMirrorFromParent:1; - bool inheritMirrorFromItem:1; - bool childrenDoNotOverlap:1; - - QQuickCanvas *canvas; - QSGContext *sceneGraphContext() const { Q_ASSERT(canvas); return static_cast(QObjectPrivate::get(canvas))->context; } - - QQuickItem *parentItem; - QList childItems; - mutable QList *sortedChildItems; - QList paintOrderChildItems() const; - void addChild(QQuickItem *); - void removeChild(QQuickItem *); - void siblingOrderChanged(); - - inline void markSortedChildrenDirty(QQuickItem *child) { - // If sortedChildItems == &childItems then all in childItems have z == 0 - // and we don't need to invalidate if the changed item also has z == 0. - if (child->z() != 0. || sortedChildItems != &childItems) { - if (sortedChildItems != &childItems) - delete sortedChildItems; - sortedChildItems = 0; - } - } - - class InitializationState { - public: - QQuickItem *getFocusScope(QQuickItem *item); - void clear(); - void clear(QQuickItem *focusScope); - private: - QQuickItem *focusScope; - }; - void initCanvas(InitializationState *, QQuickCanvas *); - - QQuickItem *subFocusItem; - - QTransform canvasToItemTransform() const; - QTransform itemToCanvasTransform() const; - void itemToParentTransform(QTransform &) const; - - qreal x; - qreal y; - qreal width; - qreal height; - qreal implicitWidth; - qreal implicitHeight; - - qreal z; - qreal scale; - qreal rotation; - qreal opacity; - - QQuickLayoutMirroringAttached* attachedLayoutDirection; - - Qt::MouseButtons acceptedMouseButtons; - Qt::InputMethodHints imHints; - - QPointF transformOriginPoint; - - virtual qreal getImplicitWidth() const; - virtual qreal getImplicitHeight() const; - virtual void implicitWidthChanged(); - virtual void implicitHeightChanged(); - - void resolveLayoutMirror(); - void setImplicitLayoutMirror(bool mirror, bool inherit); - void setLayoutMirror(bool mirror); - bool isMirrored() const { - return effectiveLayoutMirror; - } - - void emitChildrenRectChanged(const QRectF &rect) { - Q_Q(QQuickItem); - emit q->childrenRectChanged(rect); - } - - QPointF computeTransformOrigin() const; - QList transforms; - virtual void transformChanged(); - - QQuickItemKeyFilter *keyHandler; - void deliverKeyEvent(QKeyEvent *); - void deliverInputMethodEvent(QInputMethodEvent *); - void deliverFocusEvent(QFocusEvent *); - void deliverMouseEvent(QMouseEvent *); - void deliverWheelEvent(QWheelEvent *); - void deliverTouchEvent(QTouchEvent *); - void deliverHoverEvent(QHoverEvent *); - void deliverDragEvent(QEvent *); - - bool calcEffectiveVisible() const; - void setEffectiveVisibleRecur(bool); - bool calcEffectiveEnable() const; - void setEffectiveEnableRecur(bool); - - // XXX todo - enum DirtyType { - TransformOrigin = 0x00000001, - Transform = 0x00000002, - BasicTransform = 0x00000004, - Position = 0x00000008, - Size = 0x00000010, - - ZValue = 0x00000020, - Content = 0x00000040, - Smooth = 0x00000080, - OpacityValue = 0x00000100, - ChildrenChanged = 0x00000200, - ChildrenStackingChanged = 0x00000400, - ParentChanged = 0x00000800, - - Clip = 0x00001000, - Canvas = 0x00002000, - - EffectReference = 0x00008000, - Visible = 0x00010000, - HideReference = 0x00020000, - // When you add an attribute here, don't forget to update - // dirtyToString() - - TransformUpdateMask = TransformOrigin | Transform | BasicTransform | Position | Size | Canvas, - ComplexTransformUpdateMask = Transform | Canvas, - ContentUpdateMask = Size | Content | Smooth | Canvas, - ChildrenUpdateMask = ChildrenChanged | ChildrenStackingChanged | EffectReference | Canvas, - - }; - quint32 dirtyAttributes; - QString dirtyToString() const; - void dirty(DirtyType); - void addToDirtyList(); - void removeFromDirtyList(); - QQuickItem *nextDirtyItem; - QQuickItem**prevDirtyItem; - - inline QSGTransformNode *itemNode(); - inline QSGNode *childContainerNode(); - - /* - QSGNode order is: - - itemNode - - (opacityNode) - - (clipNode) - - (effectNode) - - groupNode - */ - - QSGTransformNode *itemNodeInstance; - QSGOpacityNode *opacityNode; - QQuickDefaultClipNode *clipNode; - QSGRootNode *rootNode; - QSGNode *groupNode; - QSGNode *paintNode; - QSGNode *beforePaintNode; - - virtual QSGTransformNode *createTransformNode(); - - // A reference from an effect item means that this item is used by the effect, so - // it should insert a root node. - void refFromEffectItem(bool hide); - void derefFromEffectItem(bool unhide); - int effectRefCount; - int hideRefCount; - - void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &); - - virtual void mirrorChange() {} - - static qint64 consistentTime; - static void setConsistentTime(qint64 t); - static void start(QElapsedTimer &); - static qint64 elapsed(QElapsedTimer &); - static qint64 restart(QElapsedTimer &); -}; - -/* - Key filters can be installed on a QQuickItem, but not removed. Currently they - are only used by attached objects (which are only destroyed on Item - destruction), so this isn't a problem. If in future this becomes any form - of public API, they will have to support removal too. -*/ -class QQuickItemKeyFilter -{ -public: - QQuickItemKeyFilter(QQuickItem * = 0); - virtual ~QQuickItemKeyFilter(); - - virtual void keyPressed(QKeyEvent *event, bool post); - virtual void keyReleased(QKeyEvent *event, bool post); - virtual void inputMethodEvent(QInputMethodEvent *event, bool post); - virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - virtual void componentComplete(); - - bool m_processPost; - -private: - QQuickItemKeyFilter *m_next; -}; - -class QQuickKeyNavigationAttachedPrivate : public QObjectPrivate -{ -public: - QQuickKeyNavigationAttachedPrivate() - : QObjectPrivate(), - left(0), right(0), up(0), down(0), tab(0), backtab(0), - leftSet(false), rightSet(false), upSet(false), downSet(false), - tabSet(false), backtabSet(false) {} - - QQuickItem *left; - QQuickItem *right; - QQuickItem *up; - QQuickItem *down; - QQuickItem *tab; - QQuickItem *backtab; - bool leftSet : 1; - bool rightSet : 1; - bool upSet : 1; - bool downSet : 1; - bool tabSet : 1; - bool backtabSet : 1; -}; - -class QQuickKeyNavigationAttached : public QObject, public QQuickItemKeyFilter -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QQuickKeyNavigationAttached) - - Q_PROPERTY(QQuickItem *left READ left WRITE setLeft NOTIFY leftChanged) - Q_PROPERTY(QQuickItem *right READ right WRITE setRight NOTIFY rightChanged) - Q_PROPERTY(QQuickItem *up READ up WRITE setUp NOTIFY upChanged) - Q_PROPERTY(QQuickItem *down READ down WRITE setDown NOTIFY downChanged) - Q_PROPERTY(QQuickItem *tab READ tab WRITE setTab NOTIFY tabChanged) - Q_PROPERTY(QQuickItem *backtab READ backtab WRITE setBacktab NOTIFY backtabChanged) - Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged) - - Q_ENUMS(Priority) - -public: - QQuickKeyNavigationAttached(QObject * = 0); - - QQuickItem *left() const; - void setLeft(QQuickItem *); - QQuickItem *right() const; - void setRight(QQuickItem *); - QQuickItem *up() const; - void setUp(QQuickItem *); - QQuickItem *down() const; - void setDown(QQuickItem *); - QQuickItem *tab() const; - void setTab(QQuickItem *); - QQuickItem *backtab() const; - void setBacktab(QQuickItem *); - - enum Priority { BeforeItem, AfterItem }; - Priority priority() const; - void setPriority(Priority); - - static QQuickKeyNavigationAttached *qmlAttachedProperties(QObject *); - -Q_SIGNALS: - void leftChanged(); - void rightChanged(); - void upChanged(); - void downChanged(); - void tabChanged(); - void backtabChanged(); - void priorityChanged(); - -private: - virtual void keyPressed(QKeyEvent *event, bool post); - virtual void keyReleased(QKeyEvent *event, bool post); - void setFocusNavigation(QQuickItem *currentItem, const char *dir); -}; - -class QQuickLayoutMirroringAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled RESET resetEnabled NOTIFY enabledChanged) - Q_PROPERTY(bool childrenInherit READ childrenInherit WRITE setChildrenInherit NOTIFY childrenInheritChanged) - -public: - explicit QQuickLayoutMirroringAttached(QObject *parent = 0); - - bool enabled() const; - void setEnabled(bool); - void resetEnabled(); - - bool childrenInherit() const; - void setChildrenInherit(bool); - - static QQuickLayoutMirroringAttached *qmlAttachedProperties(QObject *); -Q_SIGNALS: - void enabledChanged(); - void childrenInheritChanged(); -private: - friend class QQuickItemPrivate; - QQuickItemPrivate *itemPrivate; -}; - -class QQuickKeysAttachedPrivate : public QObjectPrivate -{ -public: - QQuickKeysAttachedPrivate() - : QObjectPrivate(), inPress(false), inRelease(false) - , inIM(false), enabled(true), imeItem(0), item(0) - {} - - bool isConnected(const char *signalName); - - //loop detection - bool inPress:1; - bool inRelease:1; - bool inIM:1; - - bool enabled : 1; - - QQuickItem *imeItem; - QList targets; - QQuickItem *item; -}; - -class QQuickKeysAttached : public QObject, public QQuickItemKeyFilter -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QQuickKeysAttached) - - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(QDeclarativeListProperty forwardTo READ forwardTo) - Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged) - - Q_ENUMS(Priority) - -public: - QQuickKeysAttached(QObject *parent=0); - ~QQuickKeysAttached(); - - bool enabled() const { Q_D(const QQuickKeysAttached); return d->enabled; } - void setEnabled(bool enabled) { - Q_D(QQuickKeysAttached); - if (enabled != d->enabled) { - d->enabled = enabled; - emit enabledChanged(); - } - } - - enum Priority { BeforeItem, AfterItem}; - Priority priority() const; - void setPriority(Priority); - - QDeclarativeListProperty forwardTo() { - Q_D(QQuickKeysAttached); - return QDeclarativeListProperty(this, d->targets); - } - - virtual void componentComplete(); - - static QQuickKeysAttached *qmlAttachedProperties(QObject *); - -Q_SIGNALS: - void enabledChanged(); - void priorityChanged(); - void pressed(QQuickKeyEvent *event); - void released(QQuickKeyEvent *event); - void digit0Pressed(QQuickKeyEvent *event); - void digit1Pressed(QQuickKeyEvent *event); - void digit2Pressed(QQuickKeyEvent *event); - void digit3Pressed(QQuickKeyEvent *event); - void digit4Pressed(QQuickKeyEvent *event); - void digit5Pressed(QQuickKeyEvent *event); - void digit6Pressed(QQuickKeyEvent *event); - void digit7Pressed(QQuickKeyEvent *event); - void digit8Pressed(QQuickKeyEvent *event); - void digit9Pressed(QQuickKeyEvent *event); - - void leftPressed(QQuickKeyEvent *event); - void rightPressed(QQuickKeyEvent *event); - void upPressed(QQuickKeyEvent *event); - void downPressed(QQuickKeyEvent *event); - void tabPressed(QQuickKeyEvent *event); - void backtabPressed(QQuickKeyEvent *event); - - void asteriskPressed(QQuickKeyEvent *event); - void numberSignPressed(QQuickKeyEvent *event); - void escapePressed(QQuickKeyEvent *event); - void returnPressed(QQuickKeyEvent *event); - void enterPressed(QQuickKeyEvent *event); - void deletePressed(QQuickKeyEvent *event); - void spacePressed(QQuickKeyEvent *event); - void backPressed(QQuickKeyEvent *event); - void cancelPressed(QQuickKeyEvent *event); - void selectPressed(QQuickKeyEvent *event); - void yesPressed(QQuickKeyEvent *event); - void noPressed(QQuickKeyEvent *event); - void context1Pressed(QQuickKeyEvent *event); - void context2Pressed(QQuickKeyEvent *event); - void context3Pressed(QQuickKeyEvent *event); - void context4Pressed(QQuickKeyEvent *event); - void callPressed(QQuickKeyEvent *event); - void hangupPressed(QQuickKeyEvent *event); - void flipPressed(QQuickKeyEvent *event); - void menuPressed(QQuickKeyEvent *event); - void volumeUpPressed(QQuickKeyEvent *event); - void volumeDownPressed(QQuickKeyEvent *event); - -private: - virtual void keyPressed(QKeyEvent *event, bool post); - virtual void keyReleased(QKeyEvent *event, bool post); - virtual void inputMethodEvent(QInputMethodEvent *, bool post); - virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - - const QByteArray keyToSignal(int key) { - QByteArray keySignal; - if (key >= Qt::Key_0 && key <= Qt::Key_9) { - keySignal = "digit0Pressed"; - keySignal[5] = '0' + (key - Qt::Key_0); - } else { - int i = 0; - while (sigMap[i].key && sigMap[i].key != key) - ++i; - keySignal = sigMap[i].sig; - } - return keySignal; - } - - struct SigMap { - int key; - const char *sig; - }; - - static const SigMap sigMap[]; -}; - -QSGTransformNode *QQuickItemPrivate::itemNode() -{ - if (!itemNodeInstance) { - itemNodeInstance = createTransformNode(); - itemNodeInstance->setFlag(QSGNode::OwnedByParent, false); -#ifdef QML_RUNTIME_TESTING - Q_Q(QQuickItem); - itemNodeInstance->description = QString::fromLatin1("QQuickItem(%1)").arg(QString::fromLatin1(q->metaObject()->className())); -#endif - } - return itemNodeInstance; -} - -QSGNode *QQuickItemPrivate::childContainerNode() -{ - if (!groupNode) { - groupNode = new QSGNode(); - if (rootNode) - rootNode->appendChildNode(groupNode); - else if (clipNode) - clipNode->appendChildNode(groupNode); - else if (opacityNode) - opacityNode->appendChildNode(groupNode); - else - itemNode()->appendChildNode(groupNode); - groupNode->setFlag(QSGNode::ChildrenDoNotOverlap, childrenDoNotOverlap); -#ifdef QML_RUNTIME_TESTING - groupNode->description = QLatin1String("group"); -#endif - } - return groupNode; -} - -Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItemPrivate::ChangeTypes); - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickKeysAttached) -QML_DECLARE_TYPEINFO(QQuickKeysAttached, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QQuickKeyNavigationAttached) -QML_DECLARE_TYPEINFO(QQuickKeyNavigationAttached, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QQuickLayoutMirroringAttached) -QML_DECLARE_TYPEINFO(QQuickLayoutMirroringAttached, QML_HAS_ATTACHED_PROPERTIES) - -#endif // QQUICKITEM_P_H diff --git a/src/declarative/items/qquickitemchangelistener_p.h b/src/declarative/items/qquickitemchangelistener_p.h deleted file mode 100644 index a021658f9e..0000000000 --- a/src/declarative/items/qquickitemchangelistener_p.h +++ /dev/null @@ -1,82 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKITEMCHANGELISTENER_P_H -#define QQUICKITEMCHANGELISTENER_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 - -QT_BEGIN_NAMESPACE - -class QRectF; -class QQuickItem; -class QQuickAnchorsPrivate; -class QQuickItemChangeListener -{ -public: - virtual void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &) {} - virtual void itemSiblingOrderChanged(QQuickItem *) {} - virtual void itemVisibilityChanged(QQuickItem *) {} - virtual void itemOpacityChanged(QQuickItem *) {} - virtual void itemDestroyed(QQuickItem *) {} - virtual void itemChildAdded(QQuickItem *, QQuickItem *) {} - virtual void itemChildRemoved(QQuickItem *, QQuickItem *) {} - virtual void itemParentChanged(QQuickItem *, QQuickItem *) {} - virtual void itemRotationChanged(QQuickItem *) {} - - virtual QQuickAnchorsPrivate *anchorPrivate() { return 0; } -}; - -QT_END_NAMESPACE - -#endif // QQUICKITEMCHANGELISTENER_P_H diff --git a/src/declarative/items/qquickitemsmodule.cpp b/src/declarative/items/qquickitemsmodule.cpp deleted file mode 100644 index 060d51e092..0000000000 --- a/src/declarative/items/qquickitemsmodule.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/**************************************************************************** -** -** 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 QtDeclarative module 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 "qquickitemsmodule_p.h" - -#include "qquickitem.h" -#include "qquickitem_p.h" -#include "qquickevents_p_p.h" -#include "qquickrectangle_p.h" -#include "qquickfocusscope_p.h" -#include "qquicktext_p.h" -#include "qquicktextinput_p.h" -#include "qquicktextedit_p.h" -#include "qquickimage_p.h" -#include "qquickborderimage_p.h" -#include "qquickscalegrid_p_p.h" -#include "qquickmousearea_p.h" -#include "qquickpincharea_p.h" -#include "qquickflickable_p.h" -#include "qquickflickable_p_p.h" -#include "qquicklistview_p.h" -#include "qquickvisualitemmodel_p.h" -#include "qquickvisualdatamodel_p.h" -#include "qquickgridview_p.h" -#include "qquickpathview_p.h" -#include -#include -#include "qquickpositioners_p.h" -#include "qquickrepeater_p.h" -#include "qquickloader_p.h" -#include "qquickanimatedimage_p.h" -#include "qquickflipable_p.h" -#include "qquicktranslate_p.h" -#include "qquickstateoperations_p.h" -#include "qquickanimation_p.h" -#include -#include -//#include -#include -#include -#include "qquicksprite_p.h" -#include "qquickspriteimage_p.h" -#include "qquickdrag_p.h" -#include "qquickdroparea_p.h" -#include "qquickmultipointtoucharea_p.h" -#include - -static QDeclarativePrivate::AutoParentResult qquickitem_autoParent(QObject *obj, QObject *parent) -{ - QQuickItem *item = qobject_cast(obj); - if (!item) - return QDeclarativePrivate::IncompatibleObject; - - QQuickItem *parentItem = qobject_cast(parent); - if (!parentItem) - return QDeclarativePrivate::IncompatibleParent; - - item->setParentItem(parentItem); - return QDeclarativePrivate::Parented; -} - -static bool compareQQuickAnchorLines(const void *p1, const void *p2) -{ - const QQuickAnchorLine &l1 = *static_cast(p1); - const QQuickAnchorLine &l2 = *static_cast(p2); - return l1 == l2; -} - -static void qt_quickitems_defineModule(const char *uri, int major, int minor) -{ - QDeclarativePrivate::RegisterAutoParent autoparent = { 0, &qquickitem_autoParent }; - QDeclarativePrivate::qmlregister(QDeclarativePrivate::AutoParentRegistration, &autoparent); - -#ifdef QT_NO_MOVIE - qmlRegisterTypeNotAvailable(uri,major,minor,"AnimatedImage", qApp->translate("QQuickAnimatedImage","Qt was built without support for QMovie")); -#else - qmlRegisterType(uri,major,minor,"AnimatedImage"); -#endif - qmlRegisterType(uri,major,minor,"BorderImage"); - qmlRegisterType(uri,major,minor,"Column"); - qmlRegisterType(uri,major,minor,"Flickable"); - qmlRegisterType(uri,major,minor,"Flipable"); - qmlRegisterType(uri,major,minor,"Flow"); -// qmlRegisterType(uri,major,minor,"FocusPanel"); - qmlRegisterType(uri,major,minor,"FocusScope"); - qmlRegisterType(uri,major,minor,"Gradient"); - qmlRegisterType(uri,major,minor,"GradientStop"); - qmlRegisterType(uri,major,minor,"Grid"); - qmlRegisterType(uri,major,minor,"GridView"); - qmlRegisterType(uri,major,minor,"Image"); - qmlRegisterType(uri,major,minor,"Item"); - qmlRegisterType(uri,major,minor,"ListView"); - qmlRegisterType(uri,major,minor,"Loader"); - qmlRegisterType(uri,major,minor,"MouseArea"); - qmlRegisterType(uri,major,minor,"Path"); - qmlRegisterType(uri,major,minor,"PathAttribute"); - qmlRegisterType(uri,major,minor,"PathCubic"); - qmlRegisterType(uri,major,minor,"PathLine"); - qmlRegisterType(uri,major,minor,"PathPercent"); - qmlRegisterType(uri,major,minor,"PathQuad"); - qmlRegisterType("QtQuick",2,0,"PathCurve"); - qmlRegisterType("QtQuick",2,0,"PathArc"); - qmlRegisterType("QtQuick",2,0,"PathSvg"); - qmlRegisterType(uri,major,minor,"PathView"); - qmlRegisterUncreatableType(uri,major,minor,"Positioner", - QStringLiteral("Positioner is an abstract type that is only available as an attached property.")); -#ifndef QT_NO_VALIDATOR - qmlRegisterType(uri,major,minor,"IntValidator"); - qmlRegisterType(uri,major,minor,"DoubleValidator"); - qmlRegisterType(uri,major,minor,"RegExpValidator"); -#endif - qmlRegisterType(uri,major,minor,"Rectangle"); - qmlRegisterType(uri,major,minor,"Repeater"); - qmlRegisterType(uri,major,minor,"Row"); - qmlRegisterType(uri,major,minor,"Translate"); - qmlRegisterType(uri,major,minor,"Rotation"); - qmlRegisterType(uri,major,minor,"Scale"); - qmlRegisterType(uri,major,minor,"Text"); - qmlRegisterType(uri,major,minor,"TextEdit"); - qmlRegisterType(uri,major,minor,"TextInput"); - qmlRegisterType(uri,major,minor,"ViewSection"); - qmlRegisterType(uri,major,minor,"VisualDataModel"); - qmlRegisterType(uri,major,minor,"VisualDataGroup"); - qmlRegisterType(uri,major,minor,"VisualItemModel"); - - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); -#ifndef QT_NO_VALIDATOR - qmlRegisterType(); -#endif - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterType(); - qRegisterMetaType("QQuickAnchorLine"); - QDeclarativeMetaType::setQQuickAnchorLineCompareFunction(compareQQuickAnchorLines); - - qmlRegisterUncreatableType(uri,major,minor,"KeyNavigation",QQuickKeyNavigationAttached::tr("KeyNavigation is only available via attached properties")); - qmlRegisterUncreatableType(uri,major,minor,"Keys",QQuickKeysAttached::tr("Keys is only available via attached properties")); - qmlRegisterUncreatableType(uri,major,minor,"LayoutMirroring", QQuickLayoutMirroringAttached::tr("LayoutMirroring is only available via attached properties")); - - qmlRegisterType(uri,major,minor,"PinchArea"); - qmlRegisterType(uri,major,minor,"Pinch"); - qmlRegisterType(); - - qmlRegisterType("QtQuick", 2, 0, "ShaderEffect"); - qmlRegisterType("QtQuick", 2, 0, "ShaderEffectSource"); - qmlRegisterUncreatableType("QtQuick", 2, 0, "ShaderEffectMesh", QQuickShaderEffectMesh::tr("Cannot create instance of abstract class ShaderEffectMesh.")); - qmlRegisterType("QtQuick", 2, 0, "GridMesh"); - - qmlRegisterUncreatableType("QtQuick", 2, 0, "PaintedItem", QQuickPaintedItem::tr("Cannot create instance of abstract class PaintedItem")); - - qmlRegisterType("QtQuick", 2, 0, "Canvas"); - - qmlRegisterType("QtQuick", 2, 0, "Sprite"); - qmlRegisterType("QtQuick", 2, 0, "SpriteImage"); - - qmlRegisterType(uri, major, minor,"ParentChange"); - qmlRegisterType(uri, major, minor,"AnchorChanges"); - qmlRegisterType(); - qmlRegisterType(uri, major, minor,"AnchorAnimation"); - qmlRegisterType(uri, major, minor,"ParentAnimation"); - qmlRegisterType("QtQuick",2,0,"PathAnimation"); - qmlRegisterType("QtQuick",2,0,"PathInterpolator"); - - qmlRegisterType("QtQuick", 2, 0, "DropArea"); - qmlRegisterType(); - qmlRegisterType(); - qmlRegisterUncreatableType("QtQuick", 2, 0, "Drag", QQuickDragAttached::tr("Drag is only available via attached properties")); - - qmlRegisterType("QtQuick", 2, 0, "MultiPointTouchArea"); - qmlRegisterType("QtQuick", 2, 0, "TouchPoint"); - qmlRegisterType(); -} - -void QQuickItemsModule::defineModule() -{ - static bool initialized = false; - if (initialized) - return; - initialized = true; - - // XXX todo - Remove before final integration... - QByteArray mode = qgetenv("QMLSCENE_IMPORT_NAME"); - QByteArray name = "QtQuick"; - int majorVersion = 2; - int minorVersion = 0; - if (mode == "quick1") { - majorVersion = 1; - } else if (mode == "qt") { - name = "Qt"; - majorVersion = 4; - minorVersion = 7; - } - - qt_quickitems_defineModule(name, majorVersion, minorVersion); -} - diff --git a/src/declarative/items/qquickitemsmodule_p.h b/src/declarative/items/qquickitemsmodule_p.h deleted file mode 100644 index d3682007d7..0000000000 --- a/src/declarative/items/qquickitemsmodule_p.h +++ /dev/null @@ -1,65 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKITEMSMODULE_P_H -#define QQUICKITEMSMODULE_P_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickItemsModule -{ -public: - static void defineModule(); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QQUICKITEMSMODULE_P_H - diff --git a/src/declarative/items/qquickitemview.cpp b/src/declarative/items/qquickitemview.cpp deleted file mode 100644 index edbe2a5d06..0000000000 --- a/src/declarative/items/qquickitemview.cpp +++ /dev/null @@ -1,1732 +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 QtDeclarative module 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 "qquickitemview_p_p.h" - -QT_BEGIN_NAMESPACE - - -FxViewItem::FxViewItem(QQuickItem *i, bool own) - : item(i), ownItem(own), index(-1) -{ -} - -FxViewItem::~FxViewItem() -{ - if (ownItem && item) { - item->setParentItem(0); - item->deleteLater(); - item = 0; - } -} - - -QQuickItemViewChangeSet::QQuickItemViewChangeSet() - : active(false) -{ - reset(); -} - -bool QQuickItemViewChangeSet::hasPendingChanges() const -{ - return !pendingChanges.isEmpty(); -} - -void QQuickItemViewChangeSet::applyChanges(const QDeclarativeChangeSet &changeSet) -{ - pendingChanges.apply(changeSet); - - int moveId = -1; - int moveOffset; - - foreach (const QDeclarativeChangeSet::Remove &r, changeSet.removes()) { - itemCount -= r.count; - if (moveId == -1 && newCurrentIndex >= r.index + r.count) { - newCurrentIndex -= r.count; - currentChanged = true; - } else if (moveId == -1 && newCurrentIndex >= r.index && newCurrentIndex < r.index + r.count) { - // current item has been removed. - if (r.isMove()) { - moveId = r.moveId; - moveOffset = newCurrentIndex - r.index; - } else { - currentRemoved = true; - newCurrentIndex = -1; - if (itemCount) - newCurrentIndex = qMin(r.index, itemCount - 1); - } - currentChanged = true; - } - } - foreach (const QDeclarativeChangeSet::Insert &i, changeSet.inserts()) { - if (moveId == -1) { - if (itemCount && newCurrentIndex >= i.index) { - newCurrentIndex += i.count; - currentChanged = true; - } else if (newCurrentIndex < 0) { - newCurrentIndex = 0; - currentChanged = true; - } else if (newCurrentIndex == 0 && !itemCount) { - // this is the first item, set the initial current index - currentChanged = true; - } - } else if (moveId == i.moveId) { - newCurrentIndex = i.index + moveOffset; - } - itemCount += i.count; - } -} - -void QQuickItemViewChangeSet::prepare(int currentIndex, int count) -{ - if (active) - return; - reset(); - active = true; - itemCount = count; - newCurrentIndex = currentIndex; -} - -void QQuickItemViewChangeSet::reset() -{ - itemCount = 0; - newCurrentIndex = -1; - pendingChanges.clear(); - removedItems.clear(); - active = false; - currentChanged = false; - currentRemoved = false; -} - - -QQuickItemView::QQuickItemView(QQuickFlickablePrivate &dd, QQuickItem *parent) - : QQuickFlickable(dd, parent) -{ - Q_D(QQuickItemView); - d->init(); -} - -QQuickItemView::~QQuickItemView() -{ - Q_D(QQuickItemView); - d->clear(); - if (d->ownModel) - delete d->model; - delete d->header; - delete d->footer; -} - - -QQuickItem *QQuickItemView::currentItem() const -{ - Q_D(const QQuickItemView); - if (!d->currentItem) - return 0; - const_cast(d)->applyPendingChanges(); - return d->currentItem->item; -} - -QVariant QQuickItemView::model() const -{ - Q_D(const QQuickItemView); - return d->modelVariant; -} - -void QQuickItemView::setModel(const QVariant &model) -{ - Q_D(QQuickItemView); - if (d->modelVariant == model) - return; - if (d->model) { - disconnect(d->model, SIGNAL(modelUpdated(QDeclarativeChangeSet,bool)), - this, SLOT(modelUpdated(QDeclarativeChangeSet,bool))); - disconnect(d->model, SIGNAL(initItem(int,QQuickItem*)), this, SLOT(initItem(int,QQuickItem*))); - disconnect(d->model, SIGNAL(createdItem(int,QQuickItem*)), this, SLOT(createdItem(int,QQuickItem*))); - disconnect(d->model, SIGNAL(destroyingItem(QQuickItem*)), this, SLOT(destroyingItem(QQuickItem*))); - } - - QQuickVisualModel *oldModel = d->model; - - d->clear(); - d->setPosition(d->contentStartPosition()); - d->model = 0; - d->modelVariant = model; - - QObject *object = qvariant_cast(model); - QQuickVisualModel *vim = 0; - if (object && (vim = qobject_cast(object))) { - if (d->ownModel) { - delete oldModel; - d->ownModel = false; - } - d->model = vim; - } else { - if (!d->ownModel) { - d->model = new QQuickVisualDataModel(qmlContext(this), this); - d->ownModel = true; - if (isComponentComplete()) - static_cast(d->model.data())->componentComplete(); - } else { - d->model = oldModel; - } - if (QQuickVisualDataModel *dataModel = qobject_cast(d->model)) - dataModel->setModel(model); - } - - if (d->model) { - d->bufferMode = QQuickItemViewPrivate::BufferBefore | QQuickItemViewPrivate::BufferAfter; - connect(d->model, SIGNAL(createdItem(int,QQuickItem*)), this, SLOT(createdItem(int,QQuickItem*))); - connect(d->model, SIGNAL(initItem(int,QQuickItem*)), this, SLOT(initItem(int,QQuickItem*))); - connect(d->model, SIGNAL(destroyingItem(QQuickItem*)), this, SLOT(destroyingItem(QQuickItem*))); - if (isComponentComplete()) { - updateSections(); - d->refill(); - if ((d->currentIndex >= d->model->count() || d->currentIndex < 0) && !d->currentIndexCleared) { - setCurrentIndex(0); - } else { - d->moveReason = QQuickItemViewPrivate::SetIndex; - d->updateCurrent(d->currentIndex); - if (d->highlight && d->currentItem) { - if (d->autoHighlight) - d->resetHighlightPosition(); - d->updateTrackedItem(); - } - d->moveReason = QQuickItemViewPrivate::Other; - } - d->updateViewport(); - } - connect(d->model, SIGNAL(modelUpdated(QDeclarativeChangeSet,bool)), - this, SLOT(modelUpdated(QDeclarativeChangeSet,bool))); - emit countChanged(); - } - emit modelChanged(); -} - -QDeclarativeComponent *QQuickItemView::delegate() const -{ - Q_D(const QQuickItemView); - if (d->model) { - if (QQuickVisualDataModel *dataModel = qobject_cast(d->model)) - return dataModel->delegate(); - } - - return 0; -} - -void QQuickItemView::setDelegate(QDeclarativeComponent *delegate) -{ - Q_D(QQuickItemView); - if (delegate == this->delegate()) - return; - if (!d->ownModel) { - d->model = new QQuickVisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QQuickVisualDataModel *dataModel = qobject_cast(d->model)) { - int oldCount = dataModel->count(); - dataModel->setDelegate(delegate); - if (isComponentComplete()) { - for (int i = 0; i < d->visibleItems.count(); ++i) - d->releaseItem(d->visibleItems.at(i)); - d->visibleItems.clear(); - d->releaseItem(d->currentItem); - d->currentItem = 0; - updateSections(); - d->refill(); - d->moveReason = QQuickItemViewPrivate::SetIndex; - d->updateCurrent(d->currentIndex); - if (d->highlight && d->currentItem) { - if (d->autoHighlight) - d->resetHighlightPosition(); - d->updateTrackedItem(); - } - d->moveReason = QQuickItemViewPrivate::Other; - d->updateViewport(); - } - if (oldCount != dataModel->count()) - emit countChanged(); - } - emit delegateChanged(); -} - - -int QQuickItemView::count() const -{ - Q_D(const QQuickItemView); - if (!d->model) - return 0; - const_cast(d)->applyPendingChanges(); - return d->model->count(); -} - -int QQuickItemView::currentIndex() const -{ - Q_D(const QQuickItemView); - const_cast(d)->applyPendingChanges(); - return d->currentIndex; -} - -void QQuickItemView::setCurrentIndex(int index) -{ - Q_D(QQuickItemView); - if (d->requestedIndex >= 0 && !d->requestedAsync) // currently creating item - return; - d->currentIndexCleared = (index == -1); - - d->applyPendingChanges(); - if (index == d->currentIndex) - return; - if (isComponentComplete() && d->isValid()) { - d->moveReason = QQuickItemViewPrivate::SetIndex; - d->updateCurrent(index); - } else if (d->currentIndex != index) { - d->currentIndex = index; - emit currentIndexChanged(); - } -} - - -bool QQuickItemView::isWrapEnabled() const -{ - Q_D(const QQuickItemView); - return d->wrap; -} - -void QQuickItemView::setWrapEnabled(bool wrap) -{ - Q_D(QQuickItemView); - if (d->wrap == wrap) - return; - d->wrap = wrap; - emit keyNavigationWrapsChanged(); -} - -int QQuickItemView::cacheBuffer() const -{ - Q_D(const QQuickItemView); - return d->buffer; -} - -void QQuickItemView::setCacheBuffer(int b) -{ - Q_D(QQuickItemView); - if (d->buffer != b) { - d->buffer = b; - if (isComponentComplete()) { - d->bufferMode = QQuickItemViewPrivate::BufferBefore | QQuickItemViewPrivate::BufferAfter; - d->refill(); - } - emit cacheBufferChanged(); - } -} - - -Qt::LayoutDirection QQuickItemView::layoutDirection() const -{ - Q_D(const QQuickItemView); - return d->layoutDirection; -} - -void QQuickItemView::setLayoutDirection(Qt::LayoutDirection layoutDirection) -{ - Q_D(QQuickItemView); - if (d->layoutDirection != layoutDirection) { - d->layoutDirection = layoutDirection; - d->regenerate(); - emit layoutDirectionChanged(); - emit effectiveLayoutDirectionChanged(); - } -} - -Qt::LayoutDirection QQuickItemView::effectiveLayoutDirection() const -{ - Q_D(const QQuickItemView); - if (d->effectiveLayoutMirror) - return d->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft; - else - return d->layoutDirection; -} - - -QDeclarativeComponent *QQuickItemView::header() const -{ - Q_D(const QQuickItemView); - return d->headerComponent; -} - -QQuickItem *QQuickItemView::headerItem() const -{ - Q_D(const QQuickItemView); - const_cast(d)->applyPendingChanges(); - return d->header ? d->header->item : 0; -} - -void QQuickItemView::setHeader(QDeclarativeComponent *headerComponent) -{ - Q_D(QQuickItemView); - if (d->headerComponent != headerComponent) { - d->applyPendingChanges(); - delete d->header; - d->header = 0; - d->headerComponent = headerComponent; - - d->markExtentsDirty(); - - if (isComponentComplete()) { - d->updateHeader(); - d->updateFooter(); - d->updateViewport(); - d->fixupPosition(); - } else { - emit headerItemChanged(); - } - emit headerChanged(); - } -} - -QDeclarativeComponent *QQuickItemView::footer() const -{ - Q_D(const QQuickItemView); - return d->footerComponent; -} - -QQuickItem *QQuickItemView::footerItem() const -{ - Q_D(const QQuickItemView); - const_cast(d)->applyPendingChanges(); - return d->footer ? d->footer->item : 0; -} - -void QQuickItemView::setFooter(QDeclarativeComponent *footerComponent) -{ - Q_D(QQuickItemView); - if (d->footerComponent != footerComponent) { - d->applyPendingChanges(); - delete d->footer; - d->footer = 0; - d->footerComponent = footerComponent; - - if (isComponentComplete()) { - d->updateFooter(); - d->updateViewport(); - d->fixupPosition(); - } else { - emit footerItemChanged(); - } - emit footerChanged(); - } -} - -QDeclarativeComponent *QQuickItemView::highlight() const -{ - Q_D(const QQuickItemView); - const_cast(d)->applyPendingChanges(); - return d->highlightComponent; -} - -void QQuickItemView::setHighlight(QDeclarativeComponent *highlightComponent) -{ - Q_D(QQuickItemView); - if (highlightComponent != d->highlightComponent) { - d->applyPendingChanges(); - d->highlightComponent = highlightComponent; - d->createHighlight(); - if (d->currentItem) - d->updateHighlight(); - emit highlightChanged(); - } -} - -QQuickItem *QQuickItemView::highlightItem() const -{ - Q_D(const QQuickItemView); - const_cast(d)->applyPendingChanges(); - return d->highlight ? d->highlight->item : 0; -} - -bool QQuickItemView::highlightFollowsCurrentItem() const -{ - Q_D(const QQuickItemView); - return d->autoHighlight; -} - -void QQuickItemView::setHighlightFollowsCurrentItem(bool autoHighlight) -{ - Q_D(QQuickItemView); - if (d->autoHighlight != autoHighlight) { - d->autoHighlight = autoHighlight; - if (autoHighlight) - d->updateHighlight(); - emit highlightFollowsCurrentItemChanged(); - } -} - -QQuickItemView::HighlightRangeMode QQuickItemView::highlightRangeMode() const -{ - Q_D(const QQuickItemView); - return static_cast(d->highlightRange); -} - -void QQuickItemView::setHighlightRangeMode(HighlightRangeMode mode) -{ - Q_D(QQuickItemView); - if (d->highlightRange == mode) - return; - d->highlightRange = mode; - d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; - emit highlightRangeModeChanged(); -} - -//###Possibly rename these properties, since they are very useful even without a highlight? -qreal QQuickItemView::preferredHighlightBegin() const -{ - Q_D(const QQuickItemView); - return d->highlightRangeStart; -} - -void QQuickItemView::setPreferredHighlightBegin(qreal start) -{ - Q_D(QQuickItemView); - d->highlightRangeStartValid = true; - if (d->highlightRangeStart == start) - return; - d->highlightRangeStart = start; - d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; - emit preferredHighlightBeginChanged(); -} - -void QQuickItemView::resetPreferredHighlightBegin() -{ - Q_D(QQuickItemView); - d->highlightRangeStartValid = false; - if (d->highlightRangeStart == 0) - return; - d->highlightRangeStart = 0; - emit preferredHighlightBeginChanged(); -} - -qreal QQuickItemView::preferredHighlightEnd() const -{ - Q_D(const QQuickItemView); - return d->highlightRangeEnd; -} - -void QQuickItemView::setPreferredHighlightEnd(qreal end) -{ - Q_D(QQuickItemView); - d->highlightRangeEndValid = true; - if (d->highlightRangeEnd == end) - return; - d->highlightRangeEnd = end; - d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; - emit preferredHighlightEndChanged(); -} - -void QQuickItemView::resetPreferredHighlightEnd() -{ - Q_D(QQuickItemView); - d->highlightRangeEndValid = false; - if (d->highlightRangeEnd == 0) - return; - d->highlightRangeEnd = 0; - emit preferredHighlightEndChanged(); -} - -int QQuickItemView::highlightMoveDuration() const -{ - Q_D(const QQuickItemView); - return d->highlightMoveDuration; -} - -void QQuickItemView::setHighlightMoveDuration(int duration) -{ - Q_D(QQuickItemView); - if (d->highlightMoveDuration != duration) { - d->highlightMoveDuration = duration; - emit highlightMoveDurationChanged(); - } -} - -void QQuickItemViewPrivate::positionViewAtIndex(int index, int mode) -{ - Q_Q(QQuickItemView); - if (!isValid()) - return; - if (mode < QQuickItemView::Beginning || mode > QQuickItemView::Contain) - return; - - applyPendingChanges(); - int idx = qMax(qMin(index, model->count()-1), 0); - - qreal pos = isContentFlowReversed() ? -position() - size() : position(); - FxViewItem *item = visibleItem(idx); - qreal maxExtent; - if (layoutOrientation() == Qt::Vertical) - maxExtent = -q->maxYExtent(); - else - maxExtent = isContentFlowReversed() ? q->minXExtent()-size(): -q->maxXExtent(); - if (!item) { - int itemPos = positionAt(idx); - changedVisibleIndex(idx); - // save the currently visible items in case any of them end up visible again - QList oldVisible = visibleItems; - visibleItems.clear(); - setPosition(qMin(qreal(itemPos), maxExtent)); - // now release the reference to all the old visible items. - for (int i = 0; i < oldVisible.count(); ++i) - releaseItem(oldVisible.at(i)); - item = visibleItem(idx); - } - if (item) { - const qreal itemPos = item->position(); - switch (mode) { - case QQuickItemView::Beginning: - pos = itemPos; - if (index < 0 && header) - pos -= headerSize(); - break; - case QQuickItemView::Center: - pos = itemPos - (size() - item->size())/2; - break; - case QQuickItemView::End: - pos = itemPos - size() + item->size(); - if (index >= model->count() && footer) - pos += footerSize(); - break; - case QQuickItemView::Visible: - if (itemPos > pos + size()) - pos = itemPos - size() + item->size(); - else if (item->endPosition() <= pos) - pos = itemPos; - break; - case QQuickItemView::Contain: - if (item->endPosition() >= pos + size()) - pos = itemPos - size() + item->size(); - if (itemPos < pos) - pos = itemPos; - } - pos = qMin(pos, maxExtent); - qreal minExtent; - if (layoutOrientation() == Qt::Vertical) - minExtent = -q->minYExtent(); - else - minExtent = isContentFlowReversed() ? q->maxXExtent()-size(): -q->minXExtent(); - pos = qMax(pos, minExtent); - moveReason = QQuickItemViewPrivate::Other; - q->cancelFlick(); - setPosition(pos); - - if (highlight) { - if (autoHighlight) - resetHighlightPosition(); - updateHighlight(); - } - } - fixupPosition(); -} - -void QQuickItemView::positionViewAtIndex(int index, int mode) -{ - Q_D(QQuickItemView); - if (!d->isValid() || index < 0 || index >= d->model->count()) - return; - d->positionViewAtIndex(index, mode); -} - - -void QQuickItemView::positionViewAtBeginning() -{ - Q_D(QQuickItemView); - if (!d->isValid()) - return; - d->positionViewAtIndex(-1, Beginning); -} - -void QQuickItemView::positionViewAtEnd() -{ - Q_D(QQuickItemView); - if (!d->isValid()) - return; - d->positionViewAtIndex(d->model->count(), End); -} - -int QQuickItemView::indexAt(qreal x, qreal y) const -{ - Q_D(const QQuickItemView); - for (int i = 0; i < d->visibleItems.count(); ++i) { - const FxViewItem *item = d->visibleItems.at(i); - if (item->contains(x, y)) - return item->index; - } - - return -1; -} - -void QQuickItemViewPrivate::applyPendingChanges() -{ - Q_Q(QQuickItemView); - if (q->isComponentComplete() && currentChanges.hasPendingChanges()) - layout(); -} - -// for debugging only -void QQuickItemViewPrivate::checkVisible() const -{ - int skip = 0; - for (int i = 0; i < visibleItems.count(); ++i) { - FxViewItem *item = visibleItems.at(i); - if (item->index == -1) { - ++skip; - } else if (item->index != visibleIndex + i - skip) { - qFatal("index %d %d %d", visibleIndex, i, item->index); - } - } -} - -void QQuickItemViewPrivate::itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_Q(QQuickItemView); - QQuickFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry); - if (!q->isComponentComplete()) - return; - - if (header && header->item == item) { - updateHeader(); - markExtentsDirty(); - if (!q->isMoving() && !q->isFlicking()) - fixupPosition(); - } else if (footer && footer->item == item) { - updateFooter(); - markExtentsDirty(); - if (!q->isMoving() && !q->isFlicking()) - fixupPosition(); - } - - if (currentItem && currentItem->item == item) - updateHighlight(); - if (trackedItem && trackedItem->item == item) - q->trackedPositionChanged(); -} - -void QQuickItemView::destroyRemoved() -{ - Q_D(QQuickItemView); - for (QList::Iterator it = d->visibleItems.begin(); - it != d->visibleItems.end();) { - FxViewItem *item = *it; - if (item->index == -1 && item->attached->delayRemove() == false) { - d->releaseItem(item); - it = d->visibleItems.erase(it); - } else { - ++it; - } - } - - // Correct the positioning of the items - d->updateSections(); - d->forceLayout = true; - d->layout(); -} - -void QQuickItemView::modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset) -{ - Q_D(QQuickItemView); - if (reset) { - d->moveReason = QQuickItemViewPrivate::SetIndex; - d->regenerate(); - if (d->highlight && d->currentItem) { - if (d->autoHighlight) - d->resetHighlightPosition(); - d->updateTrackedItem(); - } - d->moveReason = QQuickItemViewPrivate::Other; - - emit countChanged(); - } else { - d->currentChanges.prepare(d->currentIndex, d->itemCount); - d->currentChanges.applyChanges(changeSet); - polish(); - } -} - -void QQuickItemView::animStopped() -{ - Q_D(QQuickItemView); - d->bufferMode = QQuickItemViewPrivate::BufferBefore | QQuickItemViewPrivate::BufferAfter; - d->refill(); - if (d->haveHighlightRange && d->highlightRange == QQuickItemView::StrictlyEnforceRange) - d->updateHighlight(); -} - - -void QQuickItemView::trackedPositionChanged() -{ - Q_D(QQuickItemView); - if (!d->trackedItem || !d->currentItem) - return; - if (d->moveReason == QQuickItemViewPrivate::SetIndex) { - qreal trackedPos = d->trackedItem->position(); - qreal trackedSize = d->trackedItem->size(); - if (d->trackedItem != d->currentItem) { - trackedSize += d->currentItem->sectionSize(); - } - qreal viewPos = d->isContentFlowReversed() ? -d->position()-d->size() : d->position(); - qreal pos = viewPos; - if (d->haveHighlightRange) { - if (trackedPos > pos + d->highlightRangeEnd - trackedSize) - pos = trackedPos - d->highlightRangeEnd + trackedSize; - if (trackedPos < pos + d->highlightRangeStart) - pos = trackedPos - d->highlightRangeStart; - if (d->highlightRange != StrictlyEnforceRange) { - if (pos > d->endPosition() - d->size()) - pos = d->endPosition() - d->size(); - if (pos < d->startPosition()) - pos = d->startPosition(); - } - } else { - qreal trackedEndPos = d->trackedItem->endPosition(); - qreal toItemPos = d->currentItem->position(); - qreal toItemEndPos = d->currentItem->endPosition(); - - if (d->header && d->showHeaderForIndex(d->currentIndex)) { - trackedPos -= d->headerSize(); - trackedEndPos -= d->headerSize(); - toItemPos -= d->headerSize(); - toItemEndPos -= d->headerSize(); - } else if (d->footer && d->showFooterForIndex(d->currentIndex)) { - trackedPos += d->footerSize(); - trackedEndPos += d->footerSize(); - toItemPos += d->footerSize(); - toItemEndPos += d->footerSize(); - } - - if (trackedPos < viewPos && toItemPos < viewPos) { - pos = qMax(trackedPos, toItemPos); - } else if (trackedEndPos >= viewPos + d->size() - && toItemEndPos >= viewPos + d->size()) { - if (trackedEndPos <= toItemEndPos) { - pos = trackedEndPos - d->size(); - if (trackedSize > d->size()) - pos = trackedPos; - } else { - pos = toItemEndPos - d->size(); - if (d->currentItem->size() > d->size()) - pos = d->currentItem->position(); - } - } - } - if (viewPos != pos) { - cancelFlick(); - d->calcVelocity = true; - d->setPosition(pos); - d->calcVelocity = false; - } - } -} - -void QQuickItemView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickItemView); - d->markExtentsDirty(); - QQuickFlickable::geometryChanged(newGeometry, oldGeometry); -} - - -qreal QQuickItemView::minYExtent() const -{ - Q_D(const QQuickItemView); - if (d->layoutOrientation() == Qt::Horizontal) - return QQuickFlickable::minYExtent(); - - if (d->vData.minExtentDirty) { - d->minExtent = d->vData.startMargin-d->startPosition(); - if (d->header) - d->minExtent += d->headerSize(); - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { - d->minExtent += d->highlightRangeStart; - if (d->visibleItem(0)) - d->minExtent -= d->visibleItem(0)->sectionSize(); - d->minExtent = qMax(d->minExtent, -(d->endPositionAt(0) - d->highlightRangeEnd)); - } - d->vData.minExtentDirty = false; - } - - return d->minExtent; -} - -qreal QQuickItemView::maxYExtent() const -{ - Q_D(const QQuickItemView); - if (d->layoutOrientation() == Qt::Horizontal) - return height(); - - if (d->vData.maxExtentDirty) { - if (!d->model || !d->model->count()) { - d->maxExtent = d->header ? -d->headerSize() : 0; - d->maxExtent += height(); - } else if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { - d->maxExtent = -(d->positionAt(d->model->count()-1) - d->highlightRangeStart); - if (d->highlightRangeEnd != d->highlightRangeStart) - d->maxExtent = qMin(d->maxExtent, -(d->endPosition() - d->highlightRangeEnd)); - } else { - d->maxExtent = -(d->endPosition() - height()); - } - - if (d->footer) - d->maxExtent -= d->footerSize(); - d->maxExtent -= d->vData.endMargin; - qreal minY = minYExtent(); - if (d->maxExtent > minY) - d->maxExtent = minY; - d->vData.maxExtentDirty = false; - } - return d->maxExtent; -} - -qreal QQuickItemView::minXExtent() const -{ - Q_D(const QQuickItemView); - if (d->layoutOrientation() == Qt::Vertical) - return QQuickFlickable::minXExtent(); - - if (d->hData.minExtentDirty) { - d->minExtent = -d->startPosition(); - qreal highlightStart; - qreal highlightEnd; - qreal endPositionFirstItem = 0; - if (d->isContentFlowReversed()) { - d->minExtent += d->hData.endMargin; - if (d->model && d->model->count()) - endPositionFirstItem = d->positionAt(d->model->count()-1); - else if (d->header) - d->minExtent += d->headerSize(); - highlightStart = d->highlightRangeEndValid ? d->size() - d->highlightRangeEnd : d->size(); - highlightEnd = d->highlightRangeStartValid ? d->size() - d->highlightRangeStart : d->size(); - if (d->footer) - d->minExtent += d->footerSize(); - qreal maxX = maxXExtent(); - if (d->minExtent < maxX) - d->minExtent = maxX; - } else { - d->minExtent += d->hData.startMargin; - endPositionFirstItem = d->endPositionAt(0); - highlightStart = d->highlightRangeStart; - highlightEnd = d->highlightRangeEnd; - if (d->header) - d->minExtent += d->headerSize(); - } - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { - d->minExtent += highlightStart; - d->minExtent = d->isContentFlowReversed() - ? qMin(d->minExtent, endPositionFirstItem + highlightEnd) - : qMax(d->minExtent, -(endPositionFirstItem - highlightEnd)); - } - d->hData.minExtentDirty = false; - } - - return d->minExtent; -} - -qreal QQuickItemView::maxXExtent() const -{ - Q_D(const QQuickItemView); - if (d->layoutOrientation() == Qt::Vertical) - return width(); - - if (d->hData.maxExtentDirty) { - qreal highlightStart; - qreal highlightEnd; - qreal lastItemPosition = 0; - d->maxExtent = 0; - if (d->isContentFlowReversed()) { - highlightStart = d->highlightRangeEndValid ? d->size() - d->highlightRangeEnd : d->size(); - highlightEnd = d->highlightRangeStartValid ? d->size() - d->highlightRangeStart : d->size(); - lastItemPosition = d->endPosition(); - } else { - highlightStart = d->highlightRangeStart; - highlightEnd = d->highlightRangeEnd; - if (d->model && d->model->count()) - lastItemPosition = d->positionAt(d->model->count()-1); - } - if (!d->model || !d->model->count()) { - if (!d->isContentFlowReversed()) - d->maxExtent = d->header ? -d->headerSize() : 0; - d->maxExtent += width(); - } else if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { - d->maxExtent = -(lastItemPosition - highlightStart); - if (highlightEnd != highlightStart) { - d->maxExtent = d->isContentFlowReversed() - ? qMax(d->maxExtent, -(d->endPosition() - highlightEnd)) - : qMin(d->maxExtent, -(d->endPosition() - highlightEnd)); - } - } else { - d->maxExtent = -(d->endPosition() - width()); - } - if (d->isContentFlowReversed()) { - if (d->header) - d->maxExtent -= d->headerSize(); - d->maxExtent -= d->hData.startMargin; - } else { - if (d->footer) - d->maxExtent -= d->footerSize(); - d->maxExtent -= d->hData.endMargin; - qreal minX = minXExtent(); - if (d->maxExtent > minX) - d->maxExtent = minX; - } - d->hData.maxExtentDirty = false; - } - - return d->maxExtent; -} - -void QQuickItemView::setContentX(qreal pos) -{ - Q_D(QQuickItemView); - // Positioning the view manually should override any current movement state - d->moveReason = QQuickItemViewPrivate::Other; - QQuickFlickable::setContentX(pos); -} - -void QQuickItemView::setContentY(qreal pos) -{ - Q_D(QQuickItemView); - // Positioning the view manually should override any current movement state - d->moveReason = QQuickItemViewPrivate::Other; - QQuickFlickable::setContentY(pos); -} - -qreal QQuickItemView::xOrigin() const -{ - Q_D(const QQuickItemView); - if (d->isContentFlowReversed()) - return -maxXExtent() + d->size() - d->hData.startMargin; - else - return -minXExtent() + d->hData.startMargin; -} - -void QQuickItemView::updatePolish() -{ - Q_D(QQuickItemView); - QQuickFlickable::updatePolish(); - d->layout(); -} - -void QQuickItemView::componentComplete() -{ - Q_D(QQuickItemView); - if (d->model && d->ownModel) - static_cast(d->model.data())->componentComplete(); - - QQuickFlickable::componentComplete(); - - updateSections(); - d->updateHeader(); - d->updateFooter(); - d->updateViewport(); - d->setPosition(d->contentStartPosition()); - if (d->isValid()) { - d->refill(); - d->moveReason = QQuickItemViewPrivate::SetIndex; - if (d->currentIndex < 0 && !d->currentIndexCleared) - d->updateCurrent(0); - else - d->updateCurrent(d->currentIndex); - if (d->highlight && d->currentItem) { - if (d->autoHighlight) - d->resetHighlightPosition(); - d->updateTrackedItem(); - } - d->moveReason = QQuickItemViewPrivate::Other; - d->fixupPosition(); - } - if (d->model && d->model->count()) - emit countChanged(); -} - - - -QQuickItemViewPrivate::QQuickItemViewPrivate() - : itemCount(0) - , buffer(0), bufferMode(BufferBefore | BufferAfter) - , layoutDirection(Qt::LeftToRight) - , moveReason(Other) - , visibleIndex(0) - , currentIndex(-1), currentItem(0) - , trackedItem(0), requestedIndex(-1), requestedItem(0) - , highlightComponent(0), highlight(0) - , highlightRange(QQuickItemView::NoHighlightRange) - , highlightRangeStart(0), highlightRangeEnd(0) - , highlightMoveDuration(150) - , headerComponent(0), header(0), footerComponent(0), footer(0) - , minExtent(0), maxExtent(0) - , ownModel(false), wrap(false), deferredRelease(false) - , inApplyModelChanges(false), inViewportMoved(false), forceLayout(false), currentIndexCleared(false) - , haveHighlightRange(false), autoHighlight(true), highlightRangeStartValid(false), highlightRangeEndValid(false) - , fillCacheBuffer(false), inRequest(false), requestedAsync(false) -{ -} - -bool QQuickItemViewPrivate::isValid() const -{ - return model && model->count() && model->isValid(); -} - -qreal QQuickItemViewPrivate::position() const -{ - Q_Q(const QQuickItemView); - return layoutOrientation() == Qt::Vertical ? q->contentY() : q->contentX(); -} - -qreal QQuickItemViewPrivate::size() const -{ - Q_Q(const QQuickItemView); - return layoutOrientation() == Qt::Vertical ? q->height() : q->width(); -} - -qreal QQuickItemViewPrivate::startPosition() const -{ - return isContentFlowReversed() ? -lastPosition() : originPosition(); -} - -qreal QQuickItemViewPrivate::endPosition() const -{ - return isContentFlowReversed() ? -originPosition() : lastPosition(); -} - -qreal QQuickItemViewPrivate::contentStartPosition() const -{ - qreal pos = -headerSize(); - if (layoutOrientation() == Qt::Vertical) - pos -= vData.startMargin; - else if (isContentFlowReversed()) - pos -= hData.endMargin; - else - pos -= hData.startMargin; - - return pos; -} - -int QQuickItemViewPrivate::findLastVisibleIndex(int defaultValue) const -{ - if (visibleItems.count()) { - int i = visibleItems.count() - 1; - while (i > 0 && visibleItems.at(i)->index == -1) - --i; - if (visibleItems.at(i)->index != -1) - return visibleItems.at(i)->index; - } - return defaultValue; -} - -FxViewItem *QQuickItemViewPrivate::visibleItem(int modelIndex) const { - if (modelIndex >= visibleIndex && modelIndex < visibleIndex + visibleItems.count()) { - for (int i = modelIndex - visibleIndex; i < visibleItems.count(); ++i) { - FxViewItem *item = visibleItems.at(i); - if (item->index == modelIndex) - return item; - } - } - return 0; -} - -FxViewItem *QQuickItemViewPrivate::firstVisibleItem() const { - const qreal pos = isContentFlowReversed() ? -position()-size() : position(); - for (int i = 0; i < visibleItems.count(); ++i) { - FxViewItem *item = visibleItems.at(i); - if (item->index != -1 && item->endPosition() > pos) - return item; - } - return visibleItems.count() ? visibleItems.first() : 0; -} - -// Map a model index to visibleItems list index. -// These may differ if removed items are still present in the visible list, -// e.g. doing a removal animation -int QQuickItemViewPrivate::mapFromModel(int modelIndex) const -{ - if (modelIndex < visibleIndex || modelIndex >= visibleIndex + visibleItems.count()) - return -1; - for (int i = 0; i < visibleItems.count(); ++i) { - FxViewItem *item = visibleItems.at(i); - if (item->index == modelIndex) - return i; - if (item->index > modelIndex) - return -1; - } - return -1; // Not in visibleList -} - -void QQuickItemViewPrivate::init() -{ - Q_Q(QQuickItemView); - QQuickItemPrivate::get(contentItem)->childrenDoNotOverlap = true; - q->setFlag(QQuickItem::ItemIsFocusScope); - addItemChangeListener(this, Geometry); - QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped())); - q->setFlickableDirection(QQuickFlickable::VerticalFlick); -} - -void QQuickItemViewPrivate::updateCurrent(int modelIndex) -{ - Q_Q(QQuickItemView); - applyPendingChanges(); - - if (!q->isComponentComplete() || !isValid() || modelIndex < 0 || modelIndex >= model->count()) { - if (currentItem) { - currentItem->attached->setIsCurrentItem(false); - releaseItem(currentItem); - currentItem = 0; - currentIndex = modelIndex; - emit q->currentIndexChanged(); - emit q->currentItemChanged(); - updateHighlight(); - } else if (currentIndex != modelIndex) { - currentIndex = modelIndex; - emit q->currentIndexChanged(); - } - return; - } - - if (currentItem && currentIndex == modelIndex) { - updateHighlight(); - return; - } - - FxViewItem *oldCurrentItem = currentItem; - int oldCurrentIndex = currentIndex; - currentIndex = modelIndex; - currentItem = createItem(modelIndex, false); - if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) - oldCurrentItem->attached->setIsCurrentItem(false); - if (currentItem) { - currentItem->item->setFocus(true); - currentItem->attached->setIsCurrentItem(true); - initializeCurrentItem(); - } - - updateHighlight(); - if (oldCurrentIndex != currentIndex) - emit q->currentIndexChanged(); - if (oldCurrentItem != currentItem) - emit q->currentItemChanged(); - releaseItem(oldCurrentItem); -} - -void QQuickItemViewPrivate::clear() -{ - currentChanges.reset(); - timeline.clear(); - - for (int i = 0; i < visibleItems.count(); ++i) - releaseItem(visibleItems.at(i)); - visibleItems.clear(); - visibleIndex = 0; - - releaseItem(currentItem); - currentItem = 0; - createHighlight(); - trackedItem = 0; - - markExtentsDirty(); - itemCount = 0; -} - - -void QQuickItemViewPrivate::mirrorChange() -{ - Q_Q(QQuickItemView); - regenerate(); - emit q->effectiveLayoutDirectionChanged(); -} - -void QQuickItemViewPrivate::refill() -{ - if (isContentFlowReversed()) - refill(-position()-size(), -position()); - else - refill(position(), position()+size()); -} - -void QQuickItemViewPrivate::refill(qreal from, qreal to, bool doBuffer) -{ - Q_Q(QQuickItemView); - if (!isValid() || !q->isComponentComplete()) - return; - - currentChanges.reset(); - - int prevCount = itemCount; - itemCount = model->count(); - qreal bufferFrom = from - buffer; - qreal bufferTo = to + buffer; - qreal fillFrom = from; - qreal fillTo = to; - if (doBuffer && (bufferMode & BufferAfter)) - fillTo = bufferTo; - if (doBuffer && (bufferMode & BufferBefore)) - fillFrom = bufferFrom; - - // Item creation and release is staggered in order to avoid - // creating/releasing multiple items in one frame - // while flicking (as much as possible). - - bool changed = addVisibleItems(fillFrom, fillTo, doBuffer); - - if (!changed || deferredRelease) { // avoid destroying items in the same frame that we create - if (removeNonVisibleItems(bufferFrom, bufferTo)) - changed = true; - deferredRelease = false; - } else { - deferredRelease = true; - } - - if (changed) { - markExtentsDirty(); - visibleItemsChanged(); - } else if (!doBuffer && buffer && bufferMode != NoBuffer) { - refill(from, to, true); - } - - if (!q->isMoving() && changed) { - fillCacheBuffer = true; - q->polish(); - } - - if (prevCount != itemCount) - emit q->countChanged(); -} - -void QQuickItemViewPrivate::regenerate() -{ - Q_Q(QQuickItemView); - if (q->isComponentComplete()) { - currentChanges.reset(); - delete header; - header = 0; - delete footer; - footer = 0; - updateHeader(); - updateFooter(); - clear(); - updateViewport(); - setPosition(contentStartPosition()); - refill(); - updateCurrent(currentIndex); - } -} - -void QQuickItemViewPrivate::updateViewport() -{ - Q_Q(QQuickItemView); - if (isValid()) { - if (layoutOrientation() == Qt::Vertical) - q->setContentHeight(endPosition() - startPosition()); - else - q->setContentWidth(endPosition() - startPosition()); - } -} - -void QQuickItemViewPrivate::layout() -{ - Q_Q(QQuickItemView); - if (inApplyModelChanges) - return; - - if (!isValid() && !visibleItems.count()) { - clear(); - setPosition(contentStartPosition()); - return; - } - - if (!applyModelChanges() && !forceLayout) { - if (fillCacheBuffer) - refill(); - return; - } - forceLayout = false; - - layoutVisibleItems(); - refill(); - - markExtentsDirty(); - - updateHighlight(); - - if (!q->isMoving() && !q->isFlicking()) { - fixupPosition(); - refill(); - } - - updateHeader(); - updateFooter(); - updateViewport(); - updateUnrequestedPositions(); -} - -bool QQuickItemViewPrivate::applyModelChanges() -{ - Q_Q(QQuickItemView); - if (!q->isComponentComplete() || !currentChanges.hasPendingChanges() || inApplyModelChanges) - return false; - - inApplyModelChanges = true; - - updateUnrequestedIndexes(); - moveReason = QQuickItemViewPrivate::Other; - - int prevCount = itemCount; - bool visibleAffected = false; - bool viewportChanged = !currentChanges.pendingChanges.removes().isEmpty() - || !currentChanges.pendingChanges.inserts().isEmpty(); - - FxViewItem *firstVisible = firstVisibleItem(); - FxViewItem *origVisibleItemsFirst = visibleItems.count() ? visibleItems.first() : 0; - int firstItemIndex = firstVisible ? firstVisible->index : -1; - qreal removedBeforeFirstVisibleBy = 0; - - const QVector &removals = currentChanges.pendingChanges.removes(); - for (int i=0; i::Iterator it = visibleItems.begin(); - while (it != visibleItems.end()) { - FxViewItem *item = *it; - if (item->index == -1 || item->index < removals[i].index) { - // already removed, or before removed items - if (!visibleAffected && item->index < removals[i].index) - visibleAffected = true; - ++it; - } else if (item->index >= removals[i].index + removals[i].count) { - // after removed items - item->index -= removals[i].count; - ++it; - } else { - // removed item - visibleAffected = true; - if (!removals[i].isMove()) - item->attached->emitRemove(); - - if (item->attached->delayRemove() && !removals[i].isMove()) { - item->index = -1; - QObject::connect(item->attached, SIGNAL(delayRemoveChanged()), q, SLOT(destroyRemoved()), Qt::QueuedConnection); - ++it; - } else { - if (firstVisible && item->position() < firstVisible->position() && item != visibleItems.first()) - removedBeforeFirstVisibleBy += item->size(); - if (removals[i].isMove()) { - currentChanges.removedItems.insert(removals[i].moveKey(item->index), item); - } else { - if (item == firstVisible) - firstVisible = 0; - currentChanges.removedItems.insertMulti(QDeclarativeChangeSet::MoveKey(), item); - } - it = visibleItems.erase(it); - } - } - } - if (!visibleAffected && needsRefillForAddedOrRemovedIndex(removals[i].index)) - visibleAffected = true; - } - if (!removals.isEmpty()) - updateVisibleIndex(); - - const QVector &insertions = currentChanges.pendingChanges.inserts(); - InsertionsResult insertResult; - bool allInsertionsBeforeVisible = true; - - for (int i=0; i= visibleIndex) - allInsertionsBeforeVisible = false; - if (wasEmpty && !visibleItems.isEmpty()) - resetFirstItemPosition(); - itemCount += insertions[i].count; - } - for (int i=0; iattached->emitAdd(); - - // if the first visible item has moved, ensure another one takes its place - // so that we avoid shifting all content forwards - // (if an item is removed from before the first visible, the first visible should not move upwards) - bool movedBackToFirstVisible = false; - if (firstVisible && firstItemIndex >= 0) { - for (int i=0; iindex == firstItemIndex) { - // an item has moved backwards up to the first visible's position - resetItemPosition(insertResult.movedBackwards[i], firstVisible); - insertResult.movedBackwards.removeAt(i); - movedBackToFirstVisible = true; - break; - } - } - if (!movedBackToFirstVisible && !allInsertionsBeforeVisible) { - // first visible item has moved forward, another visible item takes its place - FxViewItem *item = visibleItem(firstItemIndex); - if (item) - resetItemPosition(item, firstVisible); - } - } - - // Ensure we don't cause an ugly list scroll - if (firstVisible && visibleItems.count() && visibleItems.first() != firstVisible) { - // ensure first item is placed at correct postion if moving backward - // since it will be used to position all subsequent items - if (insertResult.movedBackwards.count() && origVisibleItemsFirst) - resetItemPosition(visibleItems.first(), origVisibleItemsFirst); - - // correct the first item position (unless it has already been fixed) - if (!movedBackToFirstVisible) { - qreal moveBackwardsBy = insertResult.sizeAddedBeforeVisible; - for (int i=0; isize(); - moveItemBy(visibleItems.first(), removedBeforeFirstVisibleBy, moveBackwardsBy); - } - } - - // Whatever removed/moved items remain are no longer visible items. - for (QHash::Iterator it = currentChanges.removedItems.begin(); - it != currentChanges.removedItems.end(); ++it) { - releaseItem(it.value()); - } - currentChanges.removedItems.clear(); - - if (currentChanges.currentChanged) { - if (currentChanges.currentRemoved && currentItem) { - currentItem->attached->setIsCurrentItem(false); - releaseItem(currentItem); - currentItem = 0; - } - if (!currentIndexCleared) - updateCurrent(currentChanges.newCurrentIndex); - } - currentChanges.reset(); - - updateSections(); - if (prevCount != itemCount) - emit q->countChanged(); - - if (!visibleAffected) - visibleAffected = !currentChanges.pendingChanges.changes().isEmpty(); - if (!visibleAffected && viewportChanged) - updateViewport(); - - inApplyModelChanges = false; - return visibleAffected; -} - -/* - This may return 0 if the item is being created asynchronously. - When the item becomes available, refill() will be called and the item - will be returned on the next call to createItem(). -*/ -FxViewItem *QQuickItemViewPrivate::createItem(int modelIndex, bool asynchronous) -{ - Q_Q(QQuickItemView); - if (requestedIndex == modelIndex && (asynchronous || requestedAsync == asynchronous)) - return 0; - - if (requestedIndex != -1 && requestedIndex != modelIndex) { - delete requestedItem; - requestedItem = 0; - } - - requestedIndex = modelIndex; - requestedAsync = asynchronous; - inRequest = true; - - if (QQuickItem *item = model->item(modelIndex, asynchronous)) { - item->setParentItem(q->contentItem()); - QDeclarative_setParent_noEvent(item, q->contentItem()); - requestedIndex = -1; - fillCacheBuffer = false; - FxViewItem *viewItem = requestedItem; - if (!viewItem) - viewItem = newViewItem(modelIndex, item); // already in cache, so viewItem not initialized in initItem() - if (viewItem) { - viewItem->index = modelIndex; - // do other set up for the new item that should not happen - // until after bindings are evaluated - initializeViewItem(viewItem); - unrequestedItems.remove(item); - } - requestedItem = 0; - inRequest = false; - return viewItem; - } - - inRequest = false; - return 0; -} - -void QQuickItemView::createdItem(int index, QQuickItem *item) -{ - Q_D(QQuickItemView); - if (d->requestedIndex != index) { - item->setParentItem(contentItem()); - d->unrequestedItems.insert(item, index); - item->setVisible(false); - d->repositionPackageItemAt(item, index); - } else { - d->requestedIndex = -1; - if (!d->inRequest) { - if (index == d->currentIndex) - d->updateCurrent(index); - d->refill(); - } else { - d->fillCacheBuffer = true; - polish(); - } - } -} - -void QQuickItemView::initItem(int index, QQuickItem *item) -{ - Q_D(QQuickItemView); - item->setZ(1); - if (d->requestedIndex == index) { - item->setParentItem(contentItem()); - QDeclarative_setParent_noEvent(item, contentItem()); - d->requestedItem = d->newViewItem(index, item); - } -} - -void QQuickItemView::destroyingItem(QQuickItem *item) -{ - Q_D(QQuickItemView); - d->unrequestedItems.remove(item); -} - -void QQuickItemViewPrivate::releaseItem(FxViewItem *item) -{ - Q_Q(QQuickItemView); - if (!item || !model) - return; - if (trackedItem == item) - trackedItem = 0; - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item->item); - itemPrivate->removeItemChangeListener(this, QQuickItemPrivate::Geometry); - if (model->release(item->item) == 0) { - // item was not destroyed, and we no longer reference it. - unrequestedItems.insert(item->item, model->indexOf(item->item, q)); - } - delete item; -} - -QQuickItem *QQuickItemViewPrivate::createHighlightItem() -{ - return createComponentItem(highlightComponent, true, true); -} - -QQuickItem *QQuickItemViewPrivate::createComponentItem(QDeclarativeComponent *component, bool receiveItemGeometryChanges, bool createDefault) -{ - Q_Q(QQuickItemView); - - QQuickItem *item = 0; - if (component) { - QDeclarativeContext *creationContext = component->creationContext(); - QDeclarativeContext *context = new QDeclarativeContext( - creationContext ? creationContext : qmlContext(q)); - QObject *nobj = component->create(context); - if (nobj) { - QDeclarative_setParent_noEvent(context, nobj); - item = qobject_cast(nobj); - if (!item) - delete nobj; - } else { - delete context; - } - } else if (createDefault) { - item = new QQuickItem; - } - if (item) { - QDeclarative_setParent_noEvent(item, q->contentItem()); - item->setParentItem(q->contentItem()); - if (receiveItemGeometryChanges) { - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - itemPrivate->addItemChangeListener(this, QQuickItemPrivate::Geometry); - } - } - return item; -} - -void QQuickItemViewPrivate::updateTrackedItem() -{ - Q_Q(QQuickItemView); - FxViewItem *item = currentItem; - if (highlight) - item = highlight; - trackedItem = item; - - if (trackedItem) - q->trackedPositionChanged(); -} - -void QQuickItemViewPrivate::updateUnrequestedIndexes() -{ - Q_Q(QQuickItemView); - for (QHash::iterator it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) - *it = model->indexOf(it.key(), q); -} - -void QQuickItemViewPrivate::updateUnrequestedPositions() -{ - for (QHash::const_iterator it = unrequestedItems.begin(); it != unrequestedItems.end(); ++it) - repositionPackageItemAt(it.key(), it.value()); -} - -void QQuickItemViewPrivate::updateVisibleIndex() -{ - visibleIndex = 0; - for (QList::Iterator it = visibleItems.begin(); it != visibleItems.end(); ++it) { - if ((*it)->index != -1) { - visibleIndex = (*it)->index; - break; - } - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickitemview_p.h b/src/declarative/items/qquickitemview_p.h deleted file mode 100644 index b8e27e4741..0000000000 --- a/src/declarative/items/qquickitemview_p.h +++ /dev/null @@ -1,296 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module 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 QQUICKITEMVIEW_P_H -#define QQUICKITEMVIEW_P_H - -#include "qquickflickable_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeChangeSet; - -class QQuickItemViewPrivate; - -class Q_AUTOTEST_EXPORT QQuickItemView : public QQuickFlickable -{ - Q_OBJECT - - Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) - Q_PROPERTY(int count READ count NOTIFY countChanged) - - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged) - - Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged) - Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged) - - Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged) - Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged) - - Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged) - Q_PROPERTY(QQuickItem *headerItem READ headerItem NOTIFY headerItemChanged) - Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged) - Q_PROPERTY(QQuickItem *footerItem READ footerItem NOTIFY footerItemChanged) - - Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged) - Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged) - Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged) - Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged) - Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged RESET resetPreferredHighlightBegin) - Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged RESET resetPreferredHighlightEnd) - Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged) - - Q_ENUMS(HighlightRangeMode) - Q_ENUMS(PositionMode) - -public: - QQuickItemView(QQuickFlickablePrivate &dd, QQuickItem *parent = 0); - ~QQuickItemView(); - - QVariant model() const; - void setModel(const QVariant &); - - QDeclarativeComponent *delegate() const; - void setDelegate(QDeclarativeComponent *); - - int count() const; - - int currentIndex() const; - void setCurrentIndex(int idx); - - QQuickItem *currentItem() const; - - bool isWrapEnabled() const; - void setWrapEnabled(bool); - - int cacheBuffer() const; - void setCacheBuffer(int); - - Qt::LayoutDirection layoutDirection() const; - void setLayoutDirection(Qt::LayoutDirection); - Qt::LayoutDirection effectiveLayoutDirection() const; - - QDeclarativeComponent *footer() const; - void setFooter(QDeclarativeComponent *); - QQuickItem *footerItem() const; - - QDeclarativeComponent *header() const; - void setHeader(QDeclarativeComponent *); - QQuickItem *headerItem() const; - - QDeclarativeComponent *highlight() const; - void setHighlight(QDeclarativeComponent *); - - QQuickItem *highlightItem() const; - - bool highlightFollowsCurrentItem() const; - virtual void setHighlightFollowsCurrentItem(bool); - - enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange }; - HighlightRangeMode highlightRangeMode() const; - void setHighlightRangeMode(HighlightRangeMode mode); - - qreal preferredHighlightBegin() const; - void setPreferredHighlightBegin(qreal); - void resetPreferredHighlightBegin(); - - qreal preferredHighlightEnd() const; - void setPreferredHighlightEnd(qreal); - void resetPreferredHighlightEnd(); - - int highlightMoveDuration() const; - virtual void setHighlightMoveDuration(int); - - enum PositionMode { Beginning, Center, End, Visible, Contain }; - - Q_INVOKABLE void positionViewAtIndex(int index, int mode); - Q_INVOKABLE int indexAt(qreal x, qreal y) const; - Q_INVOKABLE void positionViewAtBeginning(); - Q_INVOKABLE void positionViewAtEnd(); - - virtual void setContentX(qreal pos); - virtual void setContentY(qreal pos); - virtual qreal xOrigin() const; - -signals: - void modelChanged(); - void delegateChanged(); - void countChanged(); - void currentIndexChanged(); - void currentItemChanged(); - - void keyNavigationWrapsChanged(); - void cacheBufferChanged(); - - void layoutDirectionChanged(); - void effectiveLayoutDirectionChanged(); - - void headerChanged(); - void footerChanged(); - void headerItemChanged(); - void footerItemChanged(); - - void highlightChanged(); - void highlightItemChanged(); - void highlightFollowsCurrentItemChanged(); - void highlightRangeModeChanged(); - void preferredHighlightBeginChanged(); - void preferredHighlightEndChanged(); - void highlightMoveDurationChanged(); - -protected: - virtual void updatePolish(); - virtual void componentComplete(); - virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); - virtual qreal minYExtent() const; - virtual qreal maxYExtent() const; - virtual qreal minXExtent() const; - virtual qreal maxXExtent() const; - -protected slots: - virtual void updateSections() {} - void destroyRemoved(); - void createdItem(int index, QQuickItem *item); - void initItem(int index, QQuickItem *item); - void modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset); - void destroyingItem(QQuickItem *item); - void animStopped(); - void trackedPositionChanged(); - - - -private: - Q_DECLARE_PRIVATE(QQuickItemView) -}; - - -class Q_AUTOTEST_EXPORT QQuickItemViewAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) - Q_PROPERTY(bool delayRemove READ delayRemove WRITE setDelayRemove NOTIFY delayRemoveChanged) - - Q_PROPERTY(QString section READ section NOTIFY sectionChanged) - Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged) - Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged) - -public: - QQuickItemViewAttached(QObject *parent) - : QObject(parent), m_isCurrent(false), m_delayRemove(false) {} - ~QQuickItemViewAttached() {} - - bool isCurrentItem() const { return m_isCurrent; } - void setIsCurrentItem(bool c) { - if (m_isCurrent != c) { - m_isCurrent = c; - emit currentItemChanged(); - } - } - - bool delayRemove() const { return m_delayRemove; } - void setDelayRemove(bool delay) { - if (m_delayRemove != delay) { - m_delayRemove = delay; - emit delayRemoveChanged(); - } - } - - QString section() const { return m_section; } - void setSection(const QString §) { - if (m_section != sect) { - m_section = sect; - emit sectionChanged(); - } - } - - QString prevSection() const { return m_prevSection; } - void setPrevSection(const QString §) { - if (m_prevSection != sect) { - m_prevSection = sect; - emit prevSectionChanged(); - } - } - - QString nextSection() const { return m_nextSection; } - void setNextSection(const QString §) { - if (m_nextSection != sect) { - m_nextSection = sect; - emit nextSectionChanged(); - } - } - - void emitAdd() { emit add(); } - void emitRemove() { emit remove(); } - -signals: - void currentItemChanged(); - void delayRemoveChanged(); - - void add(); - void remove(); - - void sectionChanged(); - void prevSectionChanged(); - void nextSectionChanged(); - -public: - bool m_isCurrent : 1; - bool m_delayRemove : 1; - - // current only used by list view - mutable QString m_section; - QString m_prevSection; - QString m_nextSection; -}; - - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QQUICKITEMVIEW_P_H - diff --git a/src/declarative/items/qquickitemview_p_p.h b/src/declarative/items/qquickitemview_p_p.h deleted file mode 100644 index 4db274e045..0000000000 --- a/src/declarative/items/qquickitemview_p_p.h +++ /dev/null @@ -1,260 +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 QtDeclarative module 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 QQUICKITEMVIEW_P_P_H -#define QQUICKITEMVIEW_P_P_H - -#include "qquickitemview_p.h" -#include "qquickflickable_p_p.h" -#include "qquickvisualdatamodel_p.h" -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class FxViewItem -{ -public: - FxViewItem(QQuickItem *, bool own); - ~FxViewItem(); - - // these are positions and sizes along the current direction of scrolling/flicking - virtual qreal position() const = 0; - virtual qreal endPosition() const = 0; - virtual qreal size() const = 0; - virtual qreal sectionSize() const = 0; - - virtual bool contains(qreal x, qreal y) const = 0; - - QQuickItem *item; - bool ownItem; - int index; - QQuickItemViewAttached *attached; -}; - -class QQuickItemViewChangeSet -{ -public: - QQuickItemViewChangeSet(); - - bool hasPendingChanges() const; - void prepare(int currentIndex, int count); - void reset(); - - void applyChanges(const QDeclarativeChangeSet &changeSet); - - int itemCount; - int newCurrentIndex; - QDeclarativeChangeSet pendingChanges; - QHash removedItems; - - bool active : 1; - bool currentChanged : 1; - bool currentRemoved : 1; -}; - -class QQuickItemViewPrivate : public QQuickFlickablePrivate -{ - Q_DECLARE_PUBLIC(QQuickItemView) -public: - QQuickItemViewPrivate(); - - struct InsertionsResult { - QList addedItems; - QList movedBackwards; - qreal sizeAddedBeforeVisible; - - InsertionsResult() : sizeAddedBeforeVisible(0) {} - }; - - enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 }; - enum MovementReason { Other, SetIndex, Mouse }; - - bool isValid() const; - qreal position() const; - qreal size() const; - qreal startPosition() const; - qreal endPosition() const; - qreal contentStartPosition() const; - int findLastVisibleIndex(int defaultValue = -1) const; - FxViewItem *visibleItem(int modelIndex) const; - FxViewItem *firstVisibleItem() const; - int mapFromModel(int modelIndex) const; - - virtual void init(); - virtual void clear(); - virtual void updateViewport(); - - void regenerate(); - void layout(); - void refill(); - void refill(qreal from, qreal to, bool doBuffer = false); - void mirrorChange(); - - FxViewItem *createItem(int modelIndex, bool asynchronous = false); - virtual void releaseItem(FxViewItem *item); - - QQuickItem *createHighlightItem(); - QQuickItem *createComponentItem(QDeclarativeComponent *component, bool receiveItemGeometryChanges, bool createDefault = false); - - void updateCurrent(int modelIndex); - void updateTrackedItem(); - void updateUnrequestedIndexes(); - void updateUnrequestedPositions(); - void updateVisibleIndex(); - void positionViewAtIndex(int index, int mode); - void applyPendingChanges(); - bool applyModelChanges(); - - void checkVisible() const; - - void markExtentsDirty() { - if (layoutOrientation() == Qt::Vertical) - vData.markExtentsDirty(); - else - hData.markExtentsDirty(); - } - - QDeclarativeGuard model; - QVariant modelVariant; - int itemCount; - int buffer; - int bufferMode; - Qt::LayoutDirection layoutDirection; - - MovementReason moveReason; - - QList visibleItems; - int visibleIndex; - int currentIndex; - FxViewItem *currentItem; - FxViewItem *trackedItem; - QHash unrequestedItems; - int requestedIndex; - FxViewItem *requestedItem; - QQuickItemViewChangeSet currentChanges; - - // XXX split into struct - QDeclarativeComponent *highlightComponent; - FxViewItem *highlight; - int highlightRange; // enum value - qreal highlightRangeStart; - qreal highlightRangeEnd; - int highlightMoveDuration; - - QDeclarativeComponent *headerComponent; - FxViewItem *header; - QDeclarativeComponent *footerComponent; - FxViewItem *footer; - - mutable qreal minExtent; - mutable qreal maxExtent; - - bool ownModel : 1; - bool wrap : 1; - bool deferredRelease : 1; - bool inApplyModelChanges : 1; - bool inViewportMoved : 1; - bool forceLayout : 1; - bool currentIndexCleared : 1; - bool haveHighlightRange : 1; - bool autoHighlight : 1; - bool highlightRangeStartValid : 1; - bool highlightRangeEndValid : 1; - bool fillCacheBuffer : 1; - bool inRequest : 1; - bool requestedAsync : 1; - -protected: - virtual Qt::Orientation layoutOrientation() const = 0; - virtual bool isContentFlowReversed() const = 0; - - virtual qreal positionAt(int index) const = 0; - virtual qreal endPositionAt(int index) const = 0; - virtual qreal originPosition() const = 0; - virtual qreal lastPosition() const = 0; - - virtual qreal headerSize() const = 0; - virtual qreal footerSize() const = 0; - virtual bool showHeaderForIndex(int index) const = 0; - virtual bool showFooterForIndex(int index) const = 0; - virtual void updateHeader() = 0; - virtual void updateFooter() = 0; - - virtual void createHighlight() = 0; - virtual void updateHighlight() = 0; - virtual void resetHighlightPosition() = 0; - - virtual void setPosition(qreal pos) = 0; - virtual void fixupPosition() = 0; - - virtual bool addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer) = 0; - virtual bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) = 0; - virtual void visibleItemsChanged() = 0; - - virtual FxViewItem *newViewItem(int index, QQuickItem *item) = 0; - virtual void repositionPackageItemAt(QQuickItem *item, int index) = 0; - virtual void resetItemPosition(FxViewItem *item, FxViewItem *toItem) = 0; - virtual void resetFirstItemPosition() = 0; - virtual void moveItemBy(FxViewItem *item, qreal forwards, qreal backwards) = 0; - - virtual void layoutVisibleItems() = 0; - virtual void changedVisibleIndex(int newIndex) = 0; - virtual bool applyInsertionChange(const QDeclarativeChangeSet::Insert &, FxViewItem *, InsertionsResult *) = 0; - virtual bool needsRefillForAddedOrRemovedIndex(int) const { return false; } - - virtual void initializeViewItem(FxViewItem *) {} - virtual void initializeCurrentItem() {} - virtual void updateSections() {} - - virtual void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry); -}; - - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QQUICKITEMVIEW_P_P_H diff --git a/src/declarative/items/qquicklistview.cpp b/src/declarative/items/qquicklistview.cpp deleted file mode 100644 index 86af39075a..0000000000 --- a/src/declarative/items/qquicklistview.cpp +++ /dev/null @@ -1,2533 +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 QtDeclarative module 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 "qquicklistview_p.h" -#include "qquickitemview_p_p.h" -#include "qquickvisualitemmodel_p.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include "qplatformdefs.h" - -QT_BEGIN_NAMESPACE - -#ifndef QML_FLICK_SNAPONETHRESHOLD -#define QML_FLICK_SNAPONETHRESHOLD 30 -#endif - -class FxListItemSG; - -class QQuickListViewPrivate : public QQuickItemViewPrivate -{ - Q_DECLARE_PUBLIC(QQuickListView) -public: - static QQuickListViewPrivate* get(QQuickListView *item) { return item->d_func(); } - - virtual Qt::Orientation layoutOrientation() const; - virtual bool isContentFlowReversed() const; - bool isRightToLeft() const; - - virtual qreal positionAt(int index) const; - virtual qreal endPositionAt(int index) const; - virtual qreal originPosition() const; - virtual qreal lastPosition() const; - - FxViewItem *itemBefore(int modelIndex) const; - QString sectionAt(int modelIndex); - qreal snapPosAt(qreal pos); - FxViewItem *snapItemAt(qreal pos); - - virtual void init(); - virtual void clear(); - - virtual bool addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer); - virtual bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo); - virtual void visibleItemsChanged(); - - virtual FxViewItem *newViewItem(int index, QQuickItem *item); - virtual void initializeViewItem(FxViewItem *item); - virtual void releaseItem(FxViewItem *item); - virtual void repositionPackageItemAt(QQuickItem *item, int index); - virtual void resetItemPosition(FxViewItem *item, FxViewItem *toItem); - virtual void resetFirstItemPosition(); - virtual void moveItemBy(FxViewItem *item, qreal forwards, qreal backwards); - - virtual void createHighlight(); - virtual void updateHighlight(); - virtual void resetHighlightPosition(); - - virtual void setPosition(qreal pos); - virtual void layoutVisibleItems(); - bool applyInsertionChange(const QDeclarativeChangeSet::Insert &, FxViewItem *firstVisible, InsertionsResult *); - - virtual void updateSections(); - QQuickItem *getSectionItem(const QString §ion); - void releaseSectionItem(QQuickItem *item); - void updateInlineSection(FxListItemSG *); - void updateCurrentSection(); - void updateStickySections(); - - virtual qreal headerSize() const; - virtual qreal footerSize() const; - virtual bool showHeaderForIndex(int index) const; - virtual bool showFooterForIndex(int index) const; - virtual void updateHeader(); - virtual void updateFooter(); - - virtual void changedVisibleIndex(int newIndex); - virtual void initializeCurrentItem(); - - void updateAverage(); - - void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry); - virtual void fixupPosition(); - virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent); - virtual void flick(QQuickItemViewPrivate::AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, - QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity); - - QQuickListView::Orientation orient; - qreal visiblePos; - qreal averageSize; - qreal spacing; - QQuickListView::SnapMode snapMode; - - QSmoothedAnimation *highlightPosAnimator; - QSmoothedAnimation *highlightSizeAnimator; - qreal highlightMoveSpeed; - qreal highlightResizeSpeed; - int highlightResizeDuration; - - QQuickViewSection *sectionCriteria; - QString currentSection; - static const int sectionCacheSize = 5; - QQuickItem *sectionCache[sectionCacheSize]; - QQuickItem *currentSectionItem; - QString currentStickySection; - QQuickItem *nextSectionItem; - QString nextStickySection; - QString lastVisibleSection; - QString nextSection; - - qreal overshootDist; - bool correctFlick : 1; - bool inFlickCorrection : 1; - - QQuickListViewPrivate() - : orient(QQuickListView::Vertical) - , visiblePos(0) - , averageSize(100.0), spacing(0.0) - , snapMode(QQuickListView::NoSnap) - , highlightPosAnimator(0), highlightSizeAnimator(0) - , highlightMoveSpeed(400), highlightResizeSpeed(400), highlightResizeDuration(-1) - , sectionCriteria(0), currentSectionItem(0), nextSectionItem(0) - , overshootDist(0.0), correctFlick(false), inFlickCorrection(false) - {} - - friend class QQuickViewSection; -}; - -//---------------------------------------------------------------------------- - -QQuickViewSection::QQuickViewSection(QQuickListView *parent) - : QObject(parent), m_criteria(FullString), m_delegate(0), m_labelPositioning(InlineLabels) - , m_view(parent ? QQuickListViewPrivate::get(parent) : 0) -{ -} - -void QQuickViewSection::setProperty(const QString &property) -{ - if (property != m_property) { - m_property = property; - emit propertyChanged(); - m_view->updateSections(); - } -} - -void QQuickViewSection::setCriteria(QQuickViewSection::SectionCriteria criteria) -{ - if (criteria != m_criteria) { - m_criteria = criteria; - emit criteriaChanged(); - m_view->updateSections(); - } -} - -void QQuickViewSection::setDelegate(QDeclarativeComponent *delegate) -{ - if (delegate != m_delegate) { - m_delegate = delegate; - emit delegateChanged(); - m_view->updateSections(); - } -} - -QString QQuickViewSection::sectionString(const QString &value) -{ - if (m_criteria == FirstCharacter) - return value.isEmpty() ? QString() : value.at(0); - else - return value; -} - -void QQuickViewSection::setLabelPositioning(int l) -{ - if (m_labelPositioning != l) { - m_labelPositioning = l; - emit labelPositioningChanged(); - m_view->updateSections(); - } -} - -//---------------------------------------------------------------------------- - -class FxListItemSG : public FxViewItem -{ -public: - FxListItemSG(QQuickItem *i, QQuickListView *v, bool own) : FxViewItem(i, own), section(0), view(v) { - attached = static_cast(qmlAttachedPropertiesObject(item)); - if (attached) - static_cast(attached)->setView(view); - } - - ~FxListItemSG() {} - - qreal position() const { - if (section) { - if (view->orientation() == QQuickListView::Vertical) - return section->y(); - else - return (view->effectiveLayoutDirection() == Qt::RightToLeft ? -section->width()-section->x() : section->x()); - } else { - return itemPosition(); - } - } - qreal itemPosition() const { - if (view->orientation() == QQuickListView::Vertical) - return item->y(); - else - return (view->effectiveLayoutDirection() == Qt::RightToLeft ? -item->width()-item->x() : item->x()); - } - qreal size() const { - if (section) - return (view->orientation() == QQuickListView::Vertical ? item->height()+section->height() : item->width()+section->width()); - else - return (view->orientation() == QQuickListView::Vertical ? item->height() : item->width()); - } - qreal itemSize() const { - return (view->orientation() == QQuickListView::Vertical ? item->height() : item->width()); - } - qreal sectionSize() const { - if (section) - return (view->orientation() == QQuickListView::Vertical ? section->height() : section->width()); - return 0.0; - } - qreal endPosition() const { - if (view->orientation() == QQuickListView::Vertical) { - return item->y() + item->height(); - } else { - return (view->effectiveLayoutDirection() == Qt::RightToLeft - ? -item->x() - : item->x() + item->width()); - } - } - void setPosition(qreal pos) { - if (view->orientation() == QQuickListView::Vertical) { - if (section) { - section->setY(pos); - pos += section->height(); - } - item->setY(pos); - } else { - if (view->effectiveLayoutDirection() == Qt::RightToLeft) { - if (section) { - section->setX(-section->width()-pos); - pos += section->width(); - } - item->setX(-item->width()-pos); - } else { - if (section) { - section->setX(pos); - pos += section->width(); - } - item->setX(pos); - } - } - } - void setSize(qreal size) { - if (view->orientation() == QQuickListView::Vertical) - item->setHeight(size); - else - item->setWidth(size); - } - bool contains(qreal x, qreal y) const { - return (x >= item->x() && x < item->x() + item->width() && - y >= item->y() && y < item->y() + item->height()); - } - - QQuickItem *section; - QQuickListView *view; -}; - -//---------------------------------------------------------------------------- - -bool QQuickListViewPrivate::isContentFlowReversed() const -{ - return isRightToLeft(); -} - -Qt::Orientation QQuickListViewPrivate::layoutOrientation() const -{ - return static_cast(orient); -} - -bool QQuickListViewPrivate::isRightToLeft() const -{ - Q_Q(const QQuickListView); - return orient == QQuickListView::Horizontal && q->effectiveLayoutDirection() == Qt::RightToLeft; -} - -// Returns the item before modelIndex, if created. -// May return an item marked for removal. -FxViewItem *QQuickListViewPrivate::itemBefore(int modelIndex) const -{ - if (modelIndex < visibleIndex) - return 0; - int idx = 1; - int lastIndex = -1; - while (idx < visibleItems.count()) { - FxViewItem *item = visibleItems.at(idx); - if (item->index != -1) - lastIndex = item->index; - if (item->index == modelIndex) - return visibleItems.at(idx-1); - ++idx; - } - if (lastIndex == modelIndex-1) - return visibleItems.last(); - return 0; -} - -void QQuickListViewPrivate::setPosition(qreal pos) -{ - Q_Q(QQuickListView); - if (orient == QQuickListView::Vertical) { - q->QQuickFlickable::setContentY(pos); - } else { - if (isRightToLeft()) - q->QQuickFlickable::setContentX(-pos-size()); - else - q->QQuickFlickable::setContentX(pos); - } -} - -qreal QQuickListViewPrivate::originPosition() const -{ - qreal pos = 0; - if (!visibleItems.isEmpty()) { - pos = (*visibleItems.constBegin())->position(); - if (visibleIndex > 0) - pos -= visibleIndex * (averageSize + spacing); - } - return pos; -} - -qreal QQuickListViewPrivate::lastPosition() const -{ - qreal pos = 0; - if (!visibleItems.isEmpty()) { - int invisibleCount = visibleItems.count() - visibleIndex; - for (int i = visibleItems.count()-1; i >= 0; --i) { - if (visibleItems.at(i)->index != -1) { - invisibleCount = model->count() - visibleItems.at(i)->index - 1; - break; - } - } - pos = (*(--visibleItems.constEnd()))->endPosition() + invisibleCount * (averageSize + spacing); - } else if (model && model->count()) { - pos = (model->count() * averageSize + (model->count()-1) * spacing); - } - return pos; -} - -qreal QQuickListViewPrivate::positionAt(int modelIndex) const -{ - if (FxViewItem *item = visibleItem(modelIndex)) - return item->position(); - if (!visibleItems.isEmpty()) { - if (modelIndex < visibleIndex) { - int count = visibleIndex - modelIndex; - qreal cs = 0; - if (modelIndex == currentIndex && currentItem) { - cs = currentItem->size() + spacing; - --count; - } - return (*visibleItems.constBegin())->position() - count * (averageSize + spacing) - cs; - } else { - int count = modelIndex - findLastVisibleIndex(visibleIndex) - 1; - return (*(--visibleItems.constEnd()))->endPosition() + spacing + count * (averageSize + spacing); - } - } - return 0; -} - -qreal QQuickListViewPrivate::endPositionAt(int modelIndex) const -{ - if (FxViewItem *item = visibleItem(modelIndex)) - return item->endPosition(); - if (!visibleItems.isEmpty()) { - if (modelIndex < visibleIndex) { - int count = visibleIndex - modelIndex; - return (*visibleItems.constBegin())->position() - (count - 1) * (averageSize + spacing) - spacing; - } else { - int count = modelIndex - findLastVisibleIndex(visibleIndex) - 1; - return (*(--visibleItems.constEnd()))->endPosition() + count * (averageSize + spacing); - } - } - return 0; -} - -QString QQuickListViewPrivate::sectionAt(int modelIndex) -{ - if (FxViewItem *item = visibleItem(modelIndex)) - return item->attached->section(); - - QString section; - if (sectionCriteria) { - QString propValue = model->stringValue(modelIndex, sectionCriteria->property()); - section = sectionCriteria->sectionString(propValue); - } - - return section; -} - -qreal QQuickListViewPrivate::snapPosAt(qreal pos) -{ - if (FxViewItem *snapItem = snapItemAt(pos)) - return snapItem->position(); - if (visibleItems.count()) { - qreal firstPos = (*visibleItems.constBegin())->position(); - qreal endPos = (*(--visibleItems.constEnd()))->position(); - if (pos < firstPos) { - return firstPos - qRound((firstPos - pos) / averageSize) * averageSize; - } else if (pos > endPos) - return endPos + qRound((pos - endPos) / averageSize) * averageSize; - } - return qRound((pos - originPosition()) / averageSize) * averageSize + originPosition(); -} - -FxViewItem *QQuickListViewPrivate::snapItemAt(qreal pos) -{ - FxViewItem *snapItem = 0; - qreal prevItemSize = 0; - for (int i = 0; i < visibleItems.count(); ++i) { - FxViewItem *item = visibleItems.at(i); - if (item->index == -1) - continue; - qreal itemTop = item->position(); - if (highlight && itemTop >= pos && item->endPosition() <= pos + highlight->size()) - return item; - if (itemTop+item->size()/2 >= pos && itemTop-prevItemSize/2 < pos) - snapItem = item; - prevItemSize = item->size(); - } - return snapItem; -} - -void QQuickListViewPrivate::changedVisibleIndex(int newIndex) -{ - visiblePos = positionAt(newIndex); - visibleIndex = newIndex; -} - -void QQuickListViewPrivate::init() -{ - QQuickItemViewPrivate::init(); - ::memset(sectionCache, 0, sizeof(QQuickItem*) * sectionCacheSize); -} - -void QQuickListViewPrivate::clear() -{ - for (int i = 0; i < sectionCacheSize; ++i) { - delete sectionCache[i]; - sectionCache[i] = 0; - } - visiblePos = 0; - currentSectionItem = 0; - nextSectionItem = 0; - lastVisibleSection = QString(); - QQuickItemViewPrivate::clear(); -} - -FxViewItem *QQuickListViewPrivate::newViewItem(int modelIndex, QQuickItem *item) -{ - Q_Q(QQuickListView); - - FxListItemSG *listItem = new FxListItemSG(item, q, false); - listItem->index = modelIndex; - - // initialise attached properties - if (sectionCriteria) { - QString propValue = model->stringValue(modelIndex, sectionCriteria->property()); - listItem->attached->m_section = sectionCriteria->sectionString(propValue); - if (modelIndex > 0) { - if (FxViewItem *item = itemBefore(modelIndex)) - listItem->attached->m_prevSection = item->attached->section(); - else - listItem->attached->m_prevSection = sectionAt(modelIndex-1); - } - if (modelIndex < model->count()-1) { - if (FxViewItem *item = visibleItem(modelIndex+1)) - listItem->attached->m_nextSection = static_cast(item->attached)->section(); - else - listItem->attached->m_nextSection = sectionAt(modelIndex+1); - } - } - - return listItem; -} - -void QQuickListViewPrivate::initializeViewItem(FxViewItem *item) -{ - QQuickItemViewPrivate::initializeViewItem(item); - - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item->item); - itemPrivate->addItemChangeListener(this, QQuickItemPrivate::Geometry); - - if (sectionCriteria && sectionCriteria->delegate()) { - if (item->attached->m_prevSection != item->attached->m_section) - updateInlineSection(static_cast(item)); - } -} - -void QQuickListViewPrivate::releaseItem(FxViewItem *item) -{ - if (item) { - FxListItemSG* listItem = static_cast(item); - if (listItem->section) { - int i = 0; - do { - if (!sectionCache[i]) { - sectionCache[i] = listItem->section; - sectionCache[i]->setVisible(false); - listItem->section = 0; - break; - } - ++i; - } while (i < sectionCacheSize); - delete listItem->section; - } - } - QQuickItemViewPrivate::releaseItem(item); -} - -bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, bool doBuffer) -{ - qreal itemEnd = visiblePos; - if (visibleItems.count()) { - visiblePos = (*visibleItems.constBegin())->position(); - itemEnd = (*(--visibleItems.constEnd()))->endPosition() + spacing; - } - - int modelIndex = findLastVisibleIndex(); - bool haveValidItems = modelIndex >= 0; - modelIndex = modelIndex < 0 ? visibleIndex : modelIndex + 1; - - if (haveValidItems && (fillFrom > itemEnd+averageSize+spacing - || fillTo < visiblePos - averageSize - spacing)) { - // We've jumped more than a page. Estimate which items are now - // visible and fill from there. - int count = (fillFrom - itemEnd) / (averageSize + spacing); - for (int i = 0; i < visibleItems.count(); ++i) - releaseItem(visibleItems.at(i)); - visibleItems.clear(); - modelIndex += count; - if (modelIndex >= model->count()) { - count -= modelIndex - model->count() + 1; - modelIndex = model->count() - 1; - } else if (modelIndex < 0) { - count -= modelIndex; - modelIndex = 0; - } - visibleIndex = modelIndex; - visiblePos = itemEnd + count * (averageSize + spacing); - itemEnd = visiblePos; - } - - bool changed = false; - FxListItemSG *item = 0; - qreal pos = itemEnd; - while (modelIndex < model->count() && pos <= fillTo) { -// qDebug() << "refill: append item" << modelIndex << "pos" << pos; - if (!(item = static_cast(createItem(modelIndex, doBuffer)))) - break; - item->setPosition(pos); - item->item->setVisible(!doBuffer); - pos += item->size() + spacing; - visibleItems.append(item); - ++modelIndex; - changed = true; - } - while (visibleIndex > 0 && visibleIndex <= model->count() && visiblePos > fillFrom) { -// qDebug() << "refill: prepend item" << visibleIndex-1 << "current top pos" << visiblePos; - if (!(item = static_cast(createItem(visibleIndex-1, doBuffer)))) - break; - --visibleIndex; - visiblePos -= item->size() + spacing; - item->setPosition(visiblePos); - item->item->setVisible(!doBuffer); - visibleItems.prepend(item); - changed = true; - } - - return changed; -} - -bool QQuickListViewPrivate::removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) -{ - FxViewItem *item = 0; - bool changed = false; - - // Remove items from the start of the view. - // Zero-sized items shouldn't be removed unless a non-zero-sized item is also being - // removed, otherwise a zero-sized item is infinitely added and removed over and - // over by refill(). - int index = 0; - while (visibleItems.count() > 1 && index < visibleItems.count() - && (item = visibleItems.at(index)) && item->endPosition() < bufferFrom) { - if (item->attached->delayRemove()) - break; - if (item->size() > 0) { -// qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endPosition(); - - // remove this item and all zero-sized items before it - while (item) { - if (item->index != -1) - visibleIndex++; - visibleItems.removeAt(index); - releaseItem(item); - if (index == 0) - break; - item = visibleItems.at(--index); - } - changed = true; - } else { - index++; - } - } - - while (visibleItems.count() > 1 && (item = visibleItems.last()) && item->position() > bufferTo) { - if (item->attached->delayRemove()) - break; -// qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1 << item->position(); - visibleItems.removeLast(); - releaseItem(item); - changed = true; - } - - return changed; -} - -void QQuickListViewPrivate::visibleItemsChanged() -{ - if (visibleItems.count()) - visiblePos = (*visibleItems.constBegin())->position(); - updateAverage(); - if (currentIndex >= 0 && currentItem && !visibleItem(currentIndex)) { - static_cast(currentItem)->setPosition(positionAt(currentIndex)); - updateHighlight(); - } - if (sectionCriteria) - updateCurrentSection(); - updateHeader(); - updateFooter(); - updateViewport(); - updateUnrequestedPositions(); -} - -void QQuickListViewPrivate::layoutVisibleItems() -{ - if (!visibleItems.isEmpty()) { - bool fixedCurrent = currentItem && (*visibleItems.constBegin())->item == currentItem->item; - qreal sum = (*visibleItems.constBegin())->size(); - qreal pos = (*visibleItems.constBegin())->position() + (*visibleItems.constBegin())->size() + spacing; - for (int i=1; i < visibleItems.count(); ++i) { - FxListItemSG *item = static_cast(visibleItems.at(i)); - item->setPosition(pos); - pos += item->size() + spacing; - sum += item->size(); - fixedCurrent = fixedCurrent || (currentItem && item->item == currentItem->item); - } - averageSize = qRound(sum / visibleItems.count()); - - // move current item if it is not a visible item. - if (currentIndex >= 0 && currentItem && !fixedCurrent) { - static_cast(currentItem)->setPosition(positionAt(currentIndex)); - } - } -} - -void QQuickListViewPrivate::repositionPackageItemAt(QQuickItem *item, int index) -{ - Q_Q(QQuickListView); - qreal pos = position(); - if (orient == QQuickListView::Vertical) { - if (item->y() + item->height() > pos && item->y() < pos + q->height()) - item->setY(positionAt(index)); - } else { - if (item->x() + item->width() > pos && item->x() < pos + q->width()) { - if (isRightToLeft()) - item->setX(-positionAt(index)-item->width()); - else - item->setX(positionAt(index)); - } - } -} - -void QQuickListViewPrivate::resetItemPosition(FxViewItem *item, FxViewItem *toItem) -{ - if (item == toItem) - return; - static_cast(item)->setPosition(toItem->position()); -} - -void QQuickListViewPrivate::resetFirstItemPosition() -{ - FxListItemSG *item = static_cast(visibleItems.first()); - item->setPosition(0); -} - -void QQuickListViewPrivate::moveItemBy(FxViewItem *item, qreal forwards, qreal backwards) -{ - qreal diff = forwards - backwards; - static_cast(item)->setPosition(item->position() + diff); -} - -void QQuickListViewPrivate::createHighlight() -{ - Q_Q(QQuickListView); - bool changed = false; - if (highlight) { - if (trackedItem == highlight) - trackedItem = 0; - delete highlight; - highlight = 0; - - delete highlightPosAnimator; - delete highlightSizeAnimator; - highlightPosAnimator = 0; - highlightSizeAnimator = 0; - - changed = true; - } - - if (currentItem) { - QQuickItem *item = createHighlightItem(); - if (item) { - FxListItemSG *newHighlight = new FxListItemSG(item, q, true); - - if (autoHighlight) { - newHighlight->setSize(static_cast(currentItem)->itemSize()); - newHighlight->setPosition(static_cast(currentItem)->itemPosition()); - } - const QLatin1String posProp(orient == QQuickListView::Vertical ? "y" : "x"); - highlightPosAnimator = new QSmoothedAnimation(q); - highlightPosAnimator->target = QDeclarativeProperty(item, posProp); - highlightPosAnimator->velocity = highlightMoveSpeed; - highlightPosAnimator->userDuration = highlightMoveDuration; - - const QLatin1String sizeProp(orient == QQuickListView::Vertical ? "height" : "width"); - highlightSizeAnimator = new QSmoothedAnimation(q); - highlightSizeAnimator->velocity = highlightResizeSpeed; - highlightSizeAnimator->userDuration = highlightResizeDuration; - highlightSizeAnimator->target = QDeclarativeProperty(item, sizeProp); - - highlight = newHighlight; - changed = true; - } - } - if (changed) - emit q->highlightItemChanged(); -} - -void QQuickListViewPrivate::updateHighlight() -{ - applyPendingChanges(); - - if ((!currentItem && highlight) || (currentItem && !highlight)) - createHighlight(); - bool strictHighlight = haveHighlightRange && highlightRange == QQuickListView::StrictlyEnforceRange; - if (currentItem && autoHighlight && highlight && (!strictHighlight || !pressed)) { - // auto-update highlight - FxListItemSG *listItem = static_cast(currentItem); - highlightPosAnimator->to = isRightToLeft() - ? -listItem->itemPosition()-listItem->itemSize() - : listItem->itemPosition(); - highlightSizeAnimator->to = listItem->itemSize(); - if (orient == QQuickListView::Vertical) { - if (highlight->item->width() == 0) - highlight->item->setWidth(currentItem->item->width()); - } else { - if (highlight->item->height() == 0) - highlight->item->setHeight(currentItem->item->height()); - } - - highlightPosAnimator->restart(); - highlightSizeAnimator->restart(); - } - updateTrackedItem(); -} - -void QQuickListViewPrivate::resetHighlightPosition() -{ - if (highlight && currentItem) - static_cast(highlight)->setPosition(static_cast(currentItem)->itemPosition()); -} - -QQuickItem * QQuickListViewPrivate::getSectionItem(const QString §ion) -{ - Q_Q(QQuickListView); - QQuickItem *sectionItem = 0; - int i = sectionCacheSize-1; - while (i >= 0 && !sectionCache[i]) - --i; - if (i >= 0) { - sectionItem = sectionCache[i]; - sectionCache[i] = 0; - sectionItem->setVisible(true); - QDeclarativeContext *context = QDeclarativeEngine::contextForObject(sectionItem)->parentContext(); - context->setContextProperty(QLatin1String("section"), section); - } else { - QDeclarativeContext *creationContext = sectionCriteria->delegate()->creationContext(); - QDeclarativeContext *context = new QDeclarativeContext( - creationContext ? creationContext : qmlContext(q)); - context->setContextProperty(QLatin1String("section"), section); - QObject *nobj = sectionCriteria->delegate()->beginCreate(context); - if (nobj) { - QDeclarative_setParent_noEvent(context, nobj); - sectionItem = qobject_cast(nobj); - if (!sectionItem) { - delete nobj; - } else { - sectionItem->setZ(2); - QDeclarative_setParent_noEvent(sectionItem, contentItem); - sectionItem->setParentItem(contentItem); - } - } else { - delete context; - } - sectionCriteria->delegate()->completeCreate(); - } - - return sectionItem; -} - -void QQuickListViewPrivate::releaseSectionItem(QQuickItem *item) -{ - int i = 0; - do { - if (!sectionCache[i]) { - sectionCache[i] = item; - sectionCache[i]->setVisible(false); - return; - } - ++i; - } while (i < sectionCacheSize); - delete item; -} - -void QQuickListViewPrivate::updateInlineSection(FxListItemSG *listItem) -{ - if (!sectionCriteria || !sectionCriteria->delegate()) - return; - if (listItem->attached->m_prevSection != listItem->attached->m_section - && (sectionCriteria->labelPositioning() & QQuickViewSection::InlineLabels - || (listItem->index == 0 && sectionCriteria->labelPositioning() & QQuickViewSection::CurrentLabelAtStart))) { - if (!listItem->section) { - qreal pos = listItem->position(); - listItem->section = getSectionItem(listItem->attached->m_section); - listItem->setPosition(pos); - } else { - QDeclarativeContext *context = QDeclarativeEngine::contextForObject(listItem->section)->parentContext(); - context->setContextProperty(QLatin1String("section"), listItem->attached->m_section); - } - } else if (listItem->section) { - qreal pos = listItem->position(); - releaseSectionItem(listItem->section); - listItem->section = 0; - listItem->setPosition(pos); - } -} - -void QQuickListViewPrivate::updateStickySections() -{ - if (!sectionCriteria || visibleItems.isEmpty() - || (!sectionCriteria->labelPositioning() && !currentSectionItem && !nextSectionItem)) - return; - - bool isRtl = isRightToLeft(); - qreal viewPos = isRightToLeft() ? -position()-size() : position(); - QQuickItem *sectionItem = 0; - QQuickItem *lastSectionItem = 0; - int index = 0; - while (index < visibleItems.count()) { - if (QQuickItem *section = static_cast(visibleItems.at(index))->section) { - // Find the current section header and last visible section header - // and hide them if they will overlap a static section header. - qreal sectionPos = orient == QQuickListView::Vertical ? section->y() : section->x(); - qreal sectionSize = orient == QQuickListView::Vertical ? section->height() : section->width(); - bool visTop = true; - if (sectionCriteria->labelPositioning() & QQuickViewSection::CurrentLabelAtStart) - visTop = isRtl ? -sectionPos-sectionSize >= viewPos : sectionPos >= viewPos; - bool visBot = true; - if (sectionCriteria->labelPositioning() & QQuickViewSection::NextLabelAtEnd) - visBot = isRtl ? -sectionPos <= viewPos + size() : sectionPos + sectionSize < viewPos + size(); - section->setVisible(visBot && visTop); - if (visTop && !sectionItem) - sectionItem = section; - if (isRtl) { - if (-sectionPos <= viewPos + size()) - lastSectionItem = section; - } else { - if (sectionPos + sectionSize < viewPos + size()) - lastSectionItem = section; - } - } - ++index; - } - - // Current section header - if (sectionCriteria->labelPositioning() & QQuickViewSection::CurrentLabelAtStart) { - if (!currentSectionItem) { - currentSectionItem = getSectionItem(currentSection); - } else if (currentStickySection != currentSection) { - QDeclarativeContext *context = QDeclarativeEngine::contextForObject(currentSectionItem)->parentContext(); - context->setContextProperty(QLatin1String("section"), currentSection); - } - currentStickySection = currentSection; - if (!currentSectionItem) - return; - - qreal sectionSize = orient == QQuickListView::Vertical ? currentSectionItem->height() : currentSectionItem->width(); - bool atBeginning = orient == QQuickListView::Vertical ? vData.atBeginning : (isRightToLeft() ? hData.atEnd : hData.atBeginning); - currentSectionItem->setVisible(!atBeginning && (!header || header->endPosition() < viewPos)); - qreal pos = isRtl ? position() + size() - sectionSize : viewPos; - if (sectionItem) { - qreal sectionPos = orient == QQuickListView::Vertical ? sectionItem->y() : sectionItem->x(); - pos = isRtl ? qMax(pos, sectionPos + sectionSize) : qMin(pos, sectionPos - sectionSize); - } - if (header) - pos = isRtl ? qMin(header->endPosition(), pos) : qMax(header->endPosition(), pos); - if (footer) - pos = isRtl ? qMax(-footer->position(), pos) : qMin(footer->position() - sectionSize, pos); - if (orient == QQuickListView::Vertical) - currentSectionItem->setY(pos); - else - currentSectionItem->setX(pos); - } else if (currentSectionItem) { - releaseSectionItem(currentSectionItem); - currentSectionItem = 0; - } - - // Next section footer - if (sectionCriteria->labelPositioning() & QQuickViewSection::NextLabelAtEnd) { - if (!nextSectionItem) { - nextSectionItem = getSectionItem(nextSection); - } else if (nextStickySection != nextSection) { - QDeclarativeContext *context = QDeclarativeEngine::contextForObject(nextSectionItem)->parentContext(); - context->setContextProperty(QLatin1String("section"), nextSection); - } - nextStickySection = nextSection; - if (!nextSectionItem) - return; - - qreal sectionSize = orient == QQuickListView::Vertical ? nextSectionItem->height() : nextSectionItem->width(); - nextSectionItem->setVisible(!nextSection.isEmpty()); - qreal pos = isRtl ? position() : viewPos + size() - sectionSize; - if (lastSectionItem) { - qreal sectionPos = orient == QQuickListView::Vertical ? lastSectionItem->y() : lastSectionItem->x(); - pos = isRtl ? qMin(pos, sectionPos - sectionSize) : qMax(pos, sectionPos + sectionSize); - } - if (header) - pos = isRtl ? qMin(header->endPosition() - sectionSize, pos) : qMax(header->endPosition(), pos); - if (orient == QQuickListView::Vertical) - nextSectionItem->setY(pos); - else - nextSectionItem->setX(pos); - } else if (nextSectionItem) { - releaseSectionItem(nextSectionItem); - nextSectionItem = 0; - } -} - -void QQuickListViewPrivate::updateSections() -{ - Q_Q(QQuickListView); - if (!q->isComponentComplete()) - return; - - QQuickItemViewPrivate::updateSections(); - - if (sectionCriteria && !visibleItems.isEmpty()) { - QString prevSection; - if (visibleIndex > 0) - prevSection = sectionAt(visibleIndex-1); - QQuickListViewAttached *prevAtt = 0; - int idx = -1; - for (int i = 0; i < visibleItems.count(); ++i) { - QQuickListViewAttached *attached = static_cast(visibleItems.at(i)->attached); - attached->setPrevSection(prevSection); - if (visibleItems.at(i)->index != -1) { - QString propValue = model->stringValue(visibleItems.at(i)->index, sectionCriteria->property()); - attached->setSection(sectionCriteria->sectionString(propValue)); - idx = visibleItems.at(i)->index; - } - updateInlineSection(static_cast(visibleItems.at(i))); - if (prevAtt) - prevAtt->setNextSection(attached->section()); - prevSection = attached->section(); - prevAtt = attached; - } - if (prevAtt) { - if (idx > 0 && idx < model->count()-1) - prevAtt->setNextSection(sectionAt(idx+1)); - else - prevAtt->setNextSection(QString()); - } - } - - lastVisibleSection = QString(); - updateCurrentSection(); - updateStickySections(); -} - -void QQuickListViewPrivate::updateCurrentSection() -{ - Q_Q(QQuickListView); - if (!sectionCriteria || visibleItems.isEmpty()) { - if (!currentSection.isEmpty()) { - currentSection.clear(); - emit q->currentSectionChanged(); - } - return; - } - bool inlineSections = sectionCriteria->labelPositioning() & QQuickViewSection::InlineLabels; - qreal sectionThreshold = position(); - if (currentSectionItem && !inlineSections) - sectionThreshold += orient == QQuickListView::Vertical ? currentSectionItem->height() : currentSectionItem->width(); - int index = 0; - int modelIndex = visibleIndex; - while (index < visibleItems.count() && visibleItems.at(index)->endPosition() <= sectionThreshold) { - if (visibleItems.at(index)->index != -1) - modelIndex = visibleItems.at(index)->index; - ++index; - } - - QString newSection = currentSection; - if (index < visibleItems.count()) - newSection = visibleItems.at(index)->attached->section(); - else - newSection = (*visibleItems.constBegin())->attached->section(); - if (newSection != currentSection) { - currentSection = newSection; - updateStickySections(); - emit q->currentSectionChanged(); - } - - if (sectionCriteria->labelPositioning() & QQuickViewSection::NextLabelAtEnd) { - // Don't want to scan for next section on every movement, so remember - // the last section in the visible area and only scan for the next - // section when that changes. Clearing lastVisibleSection will also - // force searching. - QString lastSection = currentSection; - qreal endPos = isRightToLeft() ? -position() : position() + size(); - if (nextSectionItem && !inlineSections) - endPos -= orient == QQuickListView::Vertical ? nextSectionItem->height() : nextSectionItem->width(); - while (index < visibleItems.count() && static_cast(visibleItems.at(index))->itemPosition() < endPos) { - if (visibleItems.at(index)->index != -1) - modelIndex = visibleItems.at(index)->index; - lastSection = visibleItems.at(index)->attached->section(); - ++index; - } - - if (lastVisibleSection != lastSection) { - nextSection = QString(); - lastVisibleSection = lastSection; - for (int i = modelIndex; i < itemCount; ++i) { - QString section = sectionAt(i); - if (section != lastSection) { - nextSection = section; - updateStickySections(); - break; - } - } - } - } -} - -void QQuickListViewPrivate::initializeCurrentItem() -{ - QQuickItemViewPrivate::initializeCurrentItem(); - - if (currentItem) { - FxListItemSG *listItem = static_cast(currentItem); - - if (currentIndex == visibleIndex - 1 && visibleItems.count()) { - // We can calculate exact postion in this case - listItem->setPosition(visibleItems.first()->position() - currentItem->size() - spacing); - } else { - // Create current item now and position as best we can. - // Its position will be corrected when it becomes visible. - listItem->setPosition(positionAt(currentIndex)); - } - - // Avoid showing section delegate twice. We still need the section heading so that - // currentItem positioning works correctly. - // This is slightly sub-optimal, but section heading caching minimizes the impact. - if (listItem->section) - listItem->section->setVisible(false); - - if (visibleItems.isEmpty()) - averageSize = listItem->size(); - } -} - -void QQuickListViewPrivate::updateAverage() -{ - if (!visibleItems.count()) - return; - qreal sum = 0.0; - for (int i = 0; i < visibleItems.count(); ++i) - sum += visibleItems.at(i)->size(); - averageSize = qRound(sum / visibleItems.count()); -} - -qreal QQuickListViewPrivate::headerSize() const -{ - return header ? header->size() : 0.0; -} - -qreal QQuickListViewPrivate::footerSize() const -{ - return footer ? footer->size() : 0.0; -} - -bool QQuickListViewPrivate::showHeaderForIndex(int index) const -{ - return index == 0; -} - -bool QQuickListViewPrivate::showFooterForIndex(int index) const -{ - return index == model->count()-1; -} - -void QQuickListViewPrivate::updateFooter() -{ - Q_Q(QQuickListView); - bool created = false; - if (!footer) { - QQuickItem *item = createComponentItem(footerComponent, true); - if (!item) - return; - item->setZ(1); - footer = new FxListItemSG(item, q, true); - created = true; - } - - FxListItemSG *listItem = static_cast(footer); - if (visibleItems.count()) { - qreal endPos = lastPosition(); - if (findLastVisibleIndex() == model->count()-1) { - listItem->setPosition(endPos); - } else { - qreal visiblePos = position() + q->height(); - if (endPos <= visiblePos || listItem->position() < endPos) - listItem->setPosition(endPos); - } - } else { - listItem->setPosition(visiblePos); - } - - if (created) - emit q->footerItemChanged(); -} - -void QQuickListViewPrivate::updateHeader() -{ - Q_Q(QQuickListView); - bool created = false; - if (!header) { - QQuickItem *item = createComponentItem(headerComponent, true); - if (!item) - return; - item->setZ(1); - header = new FxListItemSG(item, q, true); - created = true; - } - - FxListItemSG *listItem = static_cast(header); - if (listItem) { - if (visibleItems.count()) { - qreal startPos = originPosition(); - if (visibleIndex == 0) { - listItem->setPosition(startPos - headerSize()); - } else { - if (position() <= startPos || listItem->position() > startPos - headerSize()) - listItem->setPosition(startPos - headerSize()); - } - } else { - listItem->setPosition(-headerSize()); - } - } - - if (created) - emit q->headerItemChanged(); -} - -void QQuickListViewPrivate::itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_Q(QQuickListView); - QQuickItemViewPrivate::itemGeometryChanged(item, newGeometry, oldGeometry); - if (!q->isComponentComplete()) - return; - if (item != contentItem && (!highlight || item != highlight->item)) { - if ((orient == QQuickListView::Vertical && newGeometry.height() != oldGeometry.height()) - || (orient == QQuickListView::Horizontal && newGeometry.width() != oldGeometry.width())) { - forceLayout = true; - q->polish(); - } - } -} - -void QQuickListViewPrivate::fixupPosition() -{ - if ((haveHighlightRange && highlightRange == QQuickListView::StrictlyEnforceRange) - || snapMode != QQuickListView::NoSnap) - moveReason = Other; - if (orient == QQuickListView::Vertical) - fixupY(); - else - fixupX(); -} - -void QQuickListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent) -{ - if ((orient == QQuickListView::Horizontal && &data == &vData) - || (orient == QQuickListView::Vertical && &data == &hData)) - return; - - correctFlick = false; - fixupMode = moveReason == Mouse ? fixupMode : Immediate; - bool strictHighlightRange = haveHighlightRange && highlightRange == QQuickListView::StrictlyEnforceRange; - - qreal viewPos = isRightToLeft() ? -position()-size() : position(); - - if (snapMode != QQuickListView::NoSnap && moveReason != QQuickListViewPrivate::SetIndex) { - qreal tempPosition = isRightToLeft() ? -position()-size() : position(); - if (snapMode == QQuickListView::SnapOneItem && moveReason == Mouse) { - // if we've been dragged < averageSize/2 then bias towards the next item - qreal dist = data.move.value() - (data.pressPos - data.dragStartOffset); - qreal bias = 0; - if (data.velocity > 0 && dist > QML_FLICK_SNAPONETHRESHOLD && dist < averageSize/2) - bias = averageSize/2; - else if (data.velocity < 0 && dist < -QML_FLICK_SNAPONETHRESHOLD && dist > -averageSize/2) - bias = -averageSize/2; - if (isRightToLeft()) - bias = -bias; - tempPosition -= bias; - } - FxViewItem *topItem = snapItemAt(tempPosition+highlightRangeStart); - if (!topItem && strictHighlightRange && currentItem) { - // StrictlyEnforceRange always keeps an item in range - updateHighlight(); - topItem = currentItem; - } - FxViewItem *bottomItem = snapItemAt(tempPosition+highlightRangeEnd); - if (!bottomItem && strictHighlightRange && currentItem) { - // StrictlyEnforceRange always keeps an item in range - updateHighlight(); - bottomItem = currentItem; - } - qreal pos; - bool isInBounds = -position() > maxExtent && -position() <= minExtent; - if (topItem && (isInBounds || strictHighlightRange)) { - if (topItem->index == 0 && header && tempPosition+highlightRangeStart < header->position()+header->size()/2 && !strictHighlightRange) { - pos = isRightToLeft() ? - header->position() + highlightRangeStart - size() : header->position() - highlightRangeStart; - } else { - if (isRightToLeft()) - pos = qMax(qMin(-topItem->position() + highlightRangeStart - size(), -maxExtent), -minExtent); - else - pos = qMax(qMin(topItem->position() - highlightRangeStart, -maxExtent), -minExtent); - } - } else if (bottomItem && isInBounds) { - if (isRightToLeft()) - pos = qMax(qMin(-bottomItem->position() + highlightRangeEnd - size(), -maxExtent), -minExtent); - else - pos = qMax(qMin(bottomItem->position() - highlightRangeEnd, -maxExtent), -minExtent); - } else { - QQuickItemViewPrivate::fixup(data, minExtent, maxExtent); - return; - } - - qreal dist = qAbs(data.move + pos); - if (dist > 0) { - timeline.reset(data.move); - if (fixupMode != Immediate) { - timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - data.fixingUp = true; - } else { - timeline.set(data.move, -pos); - } - vTime = timeline.time(); - } - } else if (currentItem && strictHighlightRange && moveReason != QQuickListViewPrivate::SetIndex) { - updateHighlight(); - qreal pos = static_cast(currentItem)->itemPosition(); - if (viewPos < pos + static_cast(currentItem)->itemSize() - highlightRangeEnd) - viewPos = pos + static_cast(currentItem)->itemSize() - highlightRangeEnd; - if (viewPos > pos - highlightRangeStart) - viewPos = pos - highlightRangeStart; - if (isRightToLeft()) - viewPos = -viewPos-size(); - - timeline.reset(data.move); - if (viewPos != position()) { - if (fixupMode != Immediate) { - timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - data.fixingUp = true; - } else { - timeline.set(data.move, -viewPos); - } - } - vTime = timeline.time(); - } else { - QQuickItemViewPrivate::fixup(data, minExtent, maxExtent); - } - data.inOvershoot = false; - fixupMode = Normal; -} - -void QQuickListViewPrivate::flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, - QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity) -{ - Q_Q(QQuickListView); - - data.fixingUp = false; - moveReason = Mouse; - if ((!haveHighlightRange || highlightRange != QQuickListView::StrictlyEnforceRange) && snapMode == QQuickListView::NoSnap) { - correctFlick = true; - QQuickItemViewPrivate::flick(data, minExtent, maxExtent, vSize, fixupCallback, velocity); - return; - } - qreal maxDistance = 0; - qreal dataValue = isRightToLeft() ? -data.move.value()+size() : data.move.value(); - - // -ve velocity means list is moving up/left - if (velocity > 0) { - if (data.move.value() < minExtent) { - if (snapMode == QQuickListView::SnapOneItem && !hData.flicking && !vData.flicking) { - // if we've been dragged < averageSize/2 then bias towards the next item - qreal dist = data.move.value() - (data.pressPos - data.dragStartOffset); - qreal bias = dist < averageSize/2 ? averageSize/2 : 0; - if (isRightToLeft()) - bias = -bias; - data.flickTarget = -snapPosAt(-(dataValue - highlightRangeStart) - bias) + highlightRangeStart; - maxDistance = qAbs(data.flickTarget - data.move.value()); - velocity = maxVelocity; - } else { - maxDistance = qAbs(minExtent - data.move.value()); - } - } - if (snapMode == QQuickListView::NoSnap && highlightRange != QQuickListView::StrictlyEnforceRange) - data.flickTarget = minExtent; - } else { - if (data.move.value() > maxExtent) { - if (snapMode == QQuickListView::SnapOneItem && !hData.flicking && !vData.flicking) { - // if we've been dragged < averageSize/2 then bias towards the next item - qreal dist = data.move.value() - (data.pressPos - data.dragStartOffset); - qreal bias = -dist < averageSize/2 ? averageSize/2 : 0; - if (isRightToLeft()) - bias = -bias; - data.flickTarget = -snapPosAt(-(dataValue - highlightRangeStart) + bias) + highlightRangeStart; - maxDistance = qAbs(data.flickTarget - data.move.value()); - velocity = -maxVelocity; - } else { - maxDistance = qAbs(maxExtent - data.move.value()); - } - } - if (snapMode == QQuickListView::NoSnap && highlightRange != QQuickListView::StrictlyEnforceRange) - data.flickTarget = maxExtent; - } - bool overShoot = boundsBehavior == QQuickFlickable::DragAndOvershootBounds; - if (maxDistance > 0 || overShoot) { - // These modes require the list to stop exactly on an item boundary. - // The initial flick will estimate the boundary to stop on. - // Since list items can have variable sizes, the boundary will be - // reevaluated and adjusted as we approach the boundary. - qreal v = velocity; - if (maxVelocity != -1 && maxVelocity < qAbs(v)) { - if (v < 0) - v = -maxVelocity; - else - v = maxVelocity; - } - if (!hData.flicking && !vData.flicking) { - // the initial flick - estimate boundary - qreal accel = deceleration; - qreal v2 = v * v; - overshootDist = 0.0; - // + averageSize/4 to encourage moving at least one item in the flick direction - qreal dist = v2 / (accel * 2.0) + averageSize/4; - if (maxDistance > 0) - dist = qMin(dist, maxDistance); - if (v > 0) - dist = -dist; - if ((maxDistance > 0.0 && v2 / (2.0f * maxDistance) < accel) || snapMode == QQuickListView::SnapOneItem) { - if (snapMode != QQuickListView::SnapOneItem) { - qreal distTemp = isRightToLeft() ? -dist : dist; - data.flickTarget = -snapPosAt(-(dataValue - highlightRangeStart) + distTemp) + highlightRangeStart; - } - data.flickTarget = isRightToLeft() ? -data.flickTarget+size() : data.flickTarget; - if (overShoot) { - if (data.flickTarget >= minExtent) { - overshootDist = overShootDistance(vSize); - data.flickTarget += overshootDist; - } else if (data.flickTarget <= maxExtent) { - overshootDist = overShootDistance(vSize); - data.flickTarget -= overshootDist; - } - } - qreal adjDist = -data.flickTarget + data.move.value(); - if (qAbs(adjDist) > qAbs(dist)) { - // Prevent painfully slow flicking - adjust velocity to suit flickDeceleration - qreal adjv2 = accel * 2.0f * qAbs(adjDist); - if (adjv2 > v2) { - v2 = adjv2; - v = qSqrt(v2); - if (dist > 0) - v = -v; - } - } - dist = adjDist; - accel = v2 / (2.0f * qAbs(dist)); - } else if (overShoot) { - data.flickTarget = data.move.value() - dist; - if (data.flickTarget >= minExtent) { - overshootDist = overShootDistance(vSize); - data.flickTarget += overshootDist; - } else if (data.flickTarget <= maxExtent) { - overshootDist = overShootDistance(vSize); - data.flickTarget -= overshootDist; - } - } - timeline.reset(data.move); - timeline.accel(data.move, v, accel, maxDistance + overshootDist); - timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this)); - if (!hData.flicking && q->xflick()) { - hData.flicking = true; - emit q->flickingChanged(); - emit q->flickingHorizontallyChanged(); - emit q->flickStarted(); - } - if (!vData.flicking && q->yflick()) { - vData.flicking = true; - emit q->flickingChanged(); - emit q->flickingVerticallyChanged(); - emit q->flickStarted(); - } - correctFlick = true; - } else { - // reevaluate the target boundary. - qreal newtarget = data.flickTarget; - if (snapMode != QQuickListView::NoSnap || highlightRange == QQuickListView::StrictlyEnforceRange) { - qreal tempFlickTarget = isRightToLeft() ? -data.flickTarget+size() : data.flickTarget; - newtarget = -snapPosAt(-(tempFlickTarget - highlightRangeStart)) + highlightRangeStart; - newtarget = isRightToLeft() ? -newtarget+size() : newtarget; - } - if (velocity < 0 && newtarget <= maxExtent) - newtarget = maxExtent - overshootDist; - else if (velocity > 0 && newtarget >= minExtent) - newtarget = minExtent + overshootDist; - if (newtarget == data.flickTarget) { // boundary unchanged - nothing to do - if (qAbs(velocity) < MinimumFlickVelocity) - correctFlick = false; - return; - } - data.flickTarget = newtarget; - qreal dist = -newtarget + data.move.value(); - if ((v < 0 && dist < 0) || (v > 0 && dist > 0)) { - correctFlick = false; - timeline.reset(data.move); - fixup(data, minExtent, maxExtent); - return; - } - timeline.reset(data.move); - timeline.accelDistance(data.move, v, -dist); - timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this)); - } - } else { - correctFlick = false; - timeline.reset(data.move); - fixup(data, minExtent, maxExtent); - } -} - -//---------------------------------------------------------------------------- - -/*! - \qmlclass ListView QQuickListView - \inqmlmodule QtQuick 2 - \ingroup qml-view-elements - \inherits Flickable - \brief The ListView item provides a list view of items provided by a model. - - A ListView displays data from models created from built-in QML elements like ListModel - and XmlListModel, or custom model classes defined in C++ that inherit from - QAbstractListModel. - - A ListView has a \l model, which defines the data to be displayed, and - a \l delegate, which defines how the data should be displayed. Items in a - ListView are laid out horizontally or vertically. List views are inherently - flickable because ListView inherits from \l Flickable. - - \section1 Example Usage - - The following example shows the definition of a simple list model defined - in a file called \c ContactModel.qml: - - \snippet doc/src/snippets/declarative/listview/ContactModel.qml 0 - - Another component can display this model data in a ListView, like this: - - \snippet doc/src/snippets/declarative/listview/listview.qml import - \codeline - \snippet doc/src/snippets/declarative/listview/listview.qml classdocs simple - - \image listview-simple.png - - Here, the ListView creates a \c ContactModel component for its model, and a \l Text element - for its delegate. The view will create a new \l Text component for each item in the model. Notice - the delegate is able to access the model's \c name and \c number data directly. - - An improved list view is shown below. The delegate is visually improved and is moved - into a separate \c contactDelegate component. - - \snippet doc/src/snippets/declarative/listview/listview.qml classdocs advanced - \image listview-highlight.png - - The currently selected item is highlighted with a blue \l Rectangle using the \l highlight property, - and \c focus is set to \c true to enable keyboard navigation for the list view. - The list view itself is a focus scope (see \l{qmlfocus#Acquiring Focus and Focus Scopes}{the focus documentation page} for more details). - - Delegates are instantiated as needed and may be destroyed at any time. - State should \e never be stored in a delegate. - - ListView attaches a number of properties to the root item of the delegate, for example - \c {ListView.isCurrentItem}. In the following example, the root delegate item can access - this attached property directly as \c ListView.isCurrentItem, while the child - \c contactInfo object must refer to this property as \c wrapper.ListView.isCurrentItem. - - \snippet doc/src/snippets/declarative/listview/listview.qml isCurrentItem - - \note Views do not enable \e clip automatically. If the view - is not clipped by another item or the screen, it will be necessary - to set \e {clip: true} in order to have the out of view items clipped - nicely. - - \sa {QML Data Models}, GridView, {declarative/modelviews/listview}{ListView examples} -*/ -QQuickListView::QQuickListView(QQuickItem *parent) - : QQuickItemView(*(new QQuickListViewPrivate), parent) -{ -} - -QQuickListView::~QQuickListView() -{ -} - -/*! - \qmlattachedproperty bool QtQuick2::ListView::isCurrentItem - This attached property is true if this delegate is the current item; otherwise false. - - It is attached to each instance of the delegate. - - This property may be used to adjust the appearance of the current item, for example: - - \snippet doc/src/snippets/declarative/listview/listview.qml isCurrentItem -*/ - -/*! - \qmlattachedproperty ListView QtQuick2::ListView::view - This attached property holds the view that manages this delegate instance. - - It is attached to each instance of the delegate. -*/ - -/*! - \qmlattachedproperty string QtQuick2::ListView::previousSection - This attached property holds the section of the previous element. - - It is attached to each instance of the delegate. - - The section is evaluated using the \l {ListView::section.property}{section} properties. -*/ - -/*! - \qmlattachedproperty string QtQuick2::ListView::nextSection - This attached property holds the section of the next element. - - It is attached to each instance of the delegate. - - The section is evaluated using the \l {ListView::section.property}{section} properties. -*/ - -/*! - \qmlattachedproperty string QtQuick2::ListView::section - This attached property holds the section of this element. - - It is attached to each instance of the delegate. - - The section is evaluated using the \l {ListView::section.property}{section} properties. -*/ - -/*! - \qmlattachedproperty bool QtQuick2::ListView::delayRemove - This attached property holds whether the delegate may be destroyed. - - It is attached to each instance of the delegate. - - It is sometimes necessary to delay the destruction of an item - until an animation completes. - - The example delegate below ensures that the animation completes before - the item is removed from the list. - - \snippet doc/src/snippets/declarative/listview/listview.qml delayRemove -*/ - -/*! - \qmlattachedsignal QtQuick2::ListView::onAdd() - This attached handler is called immediately after an item is added to the view. -*/ - -/*! - \qmlattachedsignal QtQuick2::ListView::onRemove() - This attached handler is called immediately before an item is removed from the view. -*/ - -/*! - \qmlproperty model QtQuick2::ListView::model - This property holds the model providing data for the list. - - The model provides the set of data that is used to create the items - in the view. Models can be created directly in QML using \l ListModel, \l XmlListModel - or \l VisualItemModel, or provided by C++ model classes. If a C++ model class is - used, it must be a subclass of \l QAbstractItemModel or a simple list. - - \sa {qmlmodels}{Data Models} -*/ - -/*! - \qmlproperty Component QtQuick2::ListView::delegate - - The delegate provides a template defining each item instantiated by the view. - The index is exposed as an accessible \c index property. Properties of the - model are also available depending upon the type of \l {qmlmodels}{Data Model}. - - The number of elements in the delegate has a direct effect on the - flicking performance of the view. If at all possible, place functionality - that is not needed for the normal display of the delegate in a \l Loader which - can load additional elements when needed. - - The ListView will lay out the items based on the size of the root item - in the delegate. - - It is recommended that the delegate's size be a whole number to avoid sub-pixel - alignment of items. - - \note Delegates are instantiated as needed and may be destroyed at any time. - State should \e never be stored in a delegate. -*/ -/*! - \qmlproperty int QtQuick2::ListView::currentIndex - \qmlproperty Item QtQuick2::ListView::currentItem - - The \c currentIndex property holds the index of the current item, and - \c currentItem holds the current item. Setting the currentIndex to -1 - will clear the highlight and set currentItem to null. - - If highlightFollowsCurrentItem is \c true, setting either of these - properties will smoothly scroll the ListView so that the current - item becomes visible. - - Note that the position of the current item - may only be approximate until it becomes visible in the view. -*/ - -/*! - \qmlproperty Item QtQuick2::ListView::highlightItem - - This holds the highlight item created from the \l highlight component. - - The \c highlightItem is managed by the view unless - \l highlightFollowsCurrentItem is set to false. - - \sa highlight, highlightFollowsCurrentItem -*/ - -/*! - \qmlproperty int QtQuick2::ListView::count - This property holds the number of items in the view. -*/ - -/*! - \qmlproperty Component QtQuick2::ListView::highlight - This property holds the component to use as the highlight. - - An instance of the highlight component is created for each list. - The geometry of the resulting component instance is managed by the list - so as to stay with the current item, unless the highlightFollowsCurrentItem - property is false. - - \sa highlightItem, highlightFollowsCurrentItem, {declarative/modelviews/listview}{ListView examples} -*/ - -/*! - \qmlproperty bool QtQuick2::ListView::highlightFollowsCurrentItem - This property holds whether the highlight is managed by the view. - - If this property is true (the default value), the highlight is moved smoothly - to follow the current item. Otherwise, the - highlight is not moved by the view, and any movement must be implemented - by the highlight. - - Here is a highlight with its motion defined by a \l {SpringAnimation} item: - - \snippet doc/src/snippets/declarative/listview/listview.qml highlightFollowsCurrentItem - - Note that the highlight animation also affects the way that the view - is scrolled. This is because the view moves to maintain the - highlight within the preferred highlight range (or visible viewport). - - \sa highlight, highlightMoveSpeed -*/ -//###Possibly rename these properties, since they are very useful even without a highlight? -/*! - \qmlproperty real QtQuick2::ListView::preferredHighlightBegin - \qmlproperty real QtQuick2::ListView::preferredHighlightEnd - \qmlproperty enumeration QtQuick2::ListView::highlightRangeMode - - These properties define the preferred range of the highlight (for the current item) - within the view. The \c preferredHighlightBegin value must be less than the - \c preferredHighlightEnd value. - - These properties affect the position of the current item when the list is scrolled. - For example, if the currently selected item should stay in the middle of the - list when the view is scrolled, set the \c preferredHighlightBegin and - \c preferredHighlightEnd values to the top and bottom coordinates of where the middle - item would be. If the \c currentItem is changed programmatically, the list will - automatically scroll so that the current item is in the middle of the view. - Furthermore, the behavior of the current item index will occur whether or not a - highlight exists. - - Valid values for \c highlightRangeMode are: - - \list - \o ListView.ApplyRange - the view attempts to maintain the highlight within the range. - However, the highlight can move outside of the range at the ends of the list or due - to mouse interaction. - \o ListView.StrictlyEnforceRange - the highlight never moves outside of the range. - The current item changes if a keyboard or mouse action would cause the highlight to move - outside of the range. - \o ListView.NoHighlightRange - this is the default value. - \endlist -*/ -void QQuickListView::setHighlightFollowsCurrentItem(bool autoHighlight) -{ - Q_D(QQuickListView); - if (d->autoHighlight != autoHighlight) { - if (!autoHighlight) { - if (d->highlightPosAnimator) - d->highlightPosAnimator->stop(); - if (d->highlightSizeAnimator) - d->highlightSizeAnimator->stop(); - } - QQuickItemView::setHighlightFollowsCurrentItem(autoHighlight); - } -} - -/*! - \qmlproperty real QtQuick2::ListView::spacing - - This property holds the spacing between items. - - The default value is 0. -*/ -qreal QQuickListView::spacing() const -{ - Q_D(const QQuickListView); - return d->spacing; -} - -void QQuickListView::setSpacing(qreal spacing) -{ - Q_D(QQuickListView); - if (spacing != d->spacing) { - d->spacing = spacing; - d->forceLayout = true; - d->layout(); - emit spacingChanged(); - } -} - -/*! - \qmlproperty enumeration QtQuick2::ListView::orientation - This property holds the orientation of the list. - - Possible values: - - \list - \o ListView.Horizontal - Items are laid out horizontally - \o ListView.Vertical (default) - Items are laid out vertically - \endlist - - \table - \row - \o Horizontal orientation: - \image ListViewHorizontal.png - - \row - \o Vertical orientation: - \image listview-highlight.png - \endtable -*/ -QQuickListView::Orientation QQuickListView::orientation() const -{ - Q_D(const QQuickListView); - return d->orient; -} - -void QQuickListView::setOrientation(QQuickListView::Orientation orientation) -{ - Q_D(QQuickListView); - if (d->orient != orientation) { - d->orient = orientation; - if (d->orient == Vertical) { - setContentWidth(-1); - setFlickableDirection(VerticalFlick); - setContentX(0); - } else { - setContentHeight(-1); - setFlickableDirection(HorizontalFlick); - setContentY(0); - } - d->regenerate(); - emit orientationChanged(); - } -} - -/*! - \qmlproperty enumeration QtQuick2::ListView::layoutDirection - This property holds the layout direction of the horizontal list. - - Possible values: - - \list - \o Qt.LeftToRight (default) - Items will be laid out from left to right. - \o Qt.RightToLeft - Items will be laid out from right to let. - \endlist - - \sa ListView::effectiveLayoutDirection -*/ - - -/*! - \qmlproperty enumeration QtQuick2::ListView::effectiveLayoutDirection - This property holds the effective layout direction of the horizontal list. - - When using the attached property \l {LayoutMirroring::enabled}{LayoutMirroring::enabled} for locale layouts, - the visual layout direction of the horizontal list will be mirrored. However, the - property \l {ListView::layoutDirection}{layoutDirection} will remain unchanged. - - \sa ListView::layoutDirection, {LayoutMirroring}{LayoutMirroring} -*/ - -/*! - \qmlproperty bool QtQuick2::ListView::keyNavigationWraps - This property holds whether the list wraps key navigation. - - If this is true, key navigation that would move the current item selection - past the end of the list instead wraps around and moves the selection to - the start of the list, and vice-versa. - - By default, key navigation is not wrapped. -*/ - - -/*! - \qmlproperty int QtQuick2::ListView::cacheBuffer - This property determines whether delegates are retained outside the - visible area of the view. - - If this value is non-zero, the view may keep as many delegates - instantiated as it can fit within the buffer specified. For example, - if in a vertical view the delegate is 20 pixels high and \c cacheBuffer is - set to 40, then up to 2 delegates above and 2 delegates below the visible - area may be created/retained. The buffered delegates are created asynchronously, - allowing creation to occur across multiple frames and reducing the - likelihood of skipping frames. In order to improve painting performance - delegates outside the visible area have their \l visible property set to - false until they are moved into the visible area. - - Note that cacheBuffer is not a pixel buffer - it only maintains additional - instantiated delegates. - - Setting this value can improve the smoothness of scrolling behavior at the expense - of additional memory usage. It is not a substitute for creating efficient - delegates; the fewer elements in a delegate, the faster a view can be - scrolled. -*/ - - -/*! - \qmlproperty string QtQuick2::ListView::section.property - \qmlproperty enumeration QtQuick2::ListView::section.criteria - \qmlproperty Component QtQuick2::ListView::section.delegate - \qmlproperty enumeration QtQuick2::ListView::section.labelPositioning - - These properties determine the expression to be evaluated and appearance - of the section labels. - - \c section.property holds the name of the property that is the basis - of each section. - - \c section.criteria holds the criteria for forming each section based on - \c section.property. This value can be one of: - - \list - \o ViewSection.FullString (default) - sections are created based on the - \c section.property value. - \o ViewSection.FirstCharacter - sections are created based on the first - character of the \c section.property value (for example, 'A', 'B', 'C' - sections, etc. for an address book) - \endlist - - \c section.delegate holds the delegate component for each section. - - \c section.labelPositioning determines whether the current and/or - next section labels stick to the start/end of the view, and whether - the labels are shown inline. This value can be a combination of: - - \list - \o ViewSection.InlineLabels - section labels are shown inline between - the item delegates separating sections (default). - \o ViewSection.CurrentLabelAtStart - the current section label sticks to the - start of the view as it is moved. - \o ViewSection.NextLabelAtEnd - the next section label (beyond all visible - sections) sticks to the end of the view as it is moved. \note Enabling - \c ViewSection.NextLabelAtEnd requires the view to scan ahead for the next - section, which has performance implications, especially for slower models. - \endlist - - Each item in the list has attached properties named \c ListView.section, - \c ListView.previousSection and \c ListView.nextSection. - - For example, here is a ListView that displays a list of animals, separated - into sections. Each item in the ListView is placed in a different section - depending on the "size" property of the model item. The \c sectionHeading - delegate component provides the light blue bar that marks the beginning of - each section. - - - \snippet examples/declarative/modelviews/listview/sections.qml 0 - - \image qml-listview-sections-example.png - - \note Adding sections to a ListView does not automatically re-order the - list items by the section criteria. - If the model is not ordered by section, then it is possible that - the sections created will not be unique; each boundary between - differing sections will result in a section header being created - even if that section exists elsewhere. - - \sa {declarative/modelviews/listview}{ListView examples} -*/ -QQuickViewSection *QQuickListView::sectionCriteria() -{ - Q_D(QQuickListView); - if (!d->sectionCriteria) { - d->sectionCriteria = new QQuickViewSection(this); - connect(d->sectionCriteria, SIGNAL(propertyChanged()), this, SLOT(updateSections())); - } - return d->sectionCriteria; -} - -/*! - \qmlproperty string QtQuick2::ListView::currentSection - This property holds the section that is currently at the beginning of the view. -*/ -QString QQuickListView::currentSection() const -{ - Q_D(const QQuickListView); - return d->currentSection; -} - -/*! - \qmlproperty real QtQuick2::ListView::highlightMoveSpeed - \qmlproperty int QtQuick2::ListView::highlightMoveDuration - \qmlproperty real QtQuick2::ListView::highlightResizeSpeed - \qmlproperty int QtQuick2::ListView::highlightResizeDuration - - These properties hold the move and resize animation speed of the highlight delegate. - - \l highlightFollowsCurrentItem must be true for these properties - to have effect. - - The default value for the speed properties is 400 pixels/second. - The default value for the duration properties is -1, i.e. the - highlight will take as much time as necessary to move at the set speed. - - These properties have the same characteristics as a SmoothedAnimation. - - \sa highlightFollowsCurrentItem -*/ -qreal QQuickListView::highlightMoveSpeed() const -{ - Q_D(const QQuickListView); - return d->highlightMoveSpeed; -} - -void QQuickListView::setHighlightMoveSpeed(qreal speed) -{ - Q_D(QQuickListView); - if (d->highlightMoveSpeed != speed) { - d->highlightMoveSpeed = speed; - if (d->highlightPosAnimator) - d->highlightPosAnimator->velocity = d->highlightMoveSpeed; - emit highlightMoveSpeedChanged(); - } -} - -void QQuickListView::setHighlightMoveDuration(int duration) -{ - Q_D(QQuickListView); - if (d->highlightMoveDuration != duration) { - if (d->highlightPosAnimator) - d->highlightPosAnimator->userDuration = duration; - QQuickItemView::setHighlightMoveDuration(duration); - } -} - -qreal QQuickListView::highlightResizeSpeed() const -{ - Q_D(const QQuickListView); - return d->highlightResizeSpeed; -} - -void QQuickListView::setHighlightResizeSpeed(qreal speed) -{ - Q_D(QQuickListView); - if (d->highlightResizeSpeed != speed) { - d->highlightResizeSpeed = speed; - if (d->highlightSizeAnimator) - d->highlightSizeAnimator->velocity = d->highlightResizeSpeed; - emit highlightResizeSpeedChanged(); - } -} - -int QQuickListView::highlightResizeDuration() const -{ - Q_D(const QQuickListView); - return d->highlightResizeDuration; -} - -void QQuickListView::setHighlightResizeDuration(int duration) -{ - Q_D(QQuickListView); - if (d->highlightResizeDuration != duration) { - d->highlightResizeDuration = duration; - if (d->highlightSizeAnimator) - d->highlightSizeAnimator->userDuration = d->highlightResizeDuration; - emit highlightResizeDurationChanged(); - } -} - -/*! - \qmlproperty enumeration QtQuick2::ListView::snapMode - - This property determines how the view scrolling will settle following a drag or flick. - The possible values are: - - \list - \o ListView.NoSnap (default) - the view stops anywhere within the visible area. - \o ListView.SnapToItem - the view settles with an item aligned with the start of - the view. - \o ListView.SnapOneItem - the view settles no more than one item away from the first - visible item at the time the mouse button is released. This mode is particularly - useful for moving one page at a time. - \endlist - - \c snapMode does not affect the \l currentIndex. To update the - \l currentIndex as the list is moved, set \l highlightRangeMode - to \c ListView.StrictlyEnforceRange. - - \sa highlightRangeMode -*/ -QQuickListView::SnapMode QQuickListView::snapMode() const -{ - Q_D(const QQuickListView); - return d->snapMode; -} - -void QQuickListView::setSnapMode(SnapMode mode) -{ - Q_D(QQuickListView); - if (d->snapMode != mode) { - d->snapMode = mode; - emit snapModeChanged(); - } -} - - -/*! - \qmlproperty Component QtQuick2::ListView::footer - This property holds the component to use as the footer. - - An instance of the footer component is created for each view. The - footer is positioned at the end of the view, after any items. - - \sa header -*/ - - -/*! - \qmlproperty Component QtQuick2::ListView::header - This property holds the component to use as the header. - - An instance of the header component is created for each view. The - header is positioned at the beginning of the view, before any items. - - \sa footer -*/ - -void QQuickListView::viewportMoved() -{ - Q_D(QQuickListView); - QQuickItemView::viewportMoved(); - if (!d->itemCount) - return; - // Recursion can occur due to refill changing the content size. - if (d->inViewportMoved) - return; - d->inViewportMoved = true; - - // Set visibility of items to eliminate cost of items outside the visible area. - qreal from = d->isContentFlowReversed() ? -d->position()-d->size() : d->position(); - qreal to = d->isContentFlowReversed() ? -d->position() : d->position()+d->size(); - for (int i = 0; i < d->visibleItems.count(); ++i) { - FxViewItem *item = static_cast(d->visibleItems.at(i)); - item->item->setVisible(item->endPosition() >= from && item->position() <= to); - } - - if (yflick()) - d->bufferMode = d->vData.smoothVelocity < 0 ? QQuickListViewPrivate::BufferBefore : QQuickListViewPrivate::BufferAfter; - else if (d->isRightToLeft()) - d->bufferMode = d->hData.smoothVelocity < 0 ? QQuickListViewPrivate::BufferAfter : QQuickListViewPrivate::BufferBefore; - else - d->bufferMode = d->hData.smoothVelocity < 0 ? QQuickListViewPrivate::BufferBefore : QQuickListViewPrivate::BufferAfter; - - d->refill(); - if (d->hData.flicking || d->vData.flicking || d->hData.moving || d->vData.moving) - d->moveReason = QQuickListViewPrivate::Mouse; - if (d->moveReason != QQuickListViewPrivate::SetIndex) { - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) { - // reposition highlight - qreal pos = d->highlight->position(); - qreal viewPos = d->isRightToLeft() ? -d->position()-d->size() : d->position(); - if (pos > viewPos + d->highlightRangeEnd - d->highlight->size()) - pos = viewPos + d->highlightRangeEnd - d->highlight->size(); - if (pos < viewPos + d->highlightRangeStart) - pos = viewPos + d->highlightRangeStart; - if (pos != d->highlight->position()) { - d->highlightPosAnimator->stop(); - static_cast(d->highlight)->setPosition(pos); - } else { - d->updateHighlight(); - } - - // update current index - if (FxViewItem *snapItem = d->snapItemAt(d->highlight->position())) { - if (snapItem->index >= 0 && snapItem->index != d->currentIndex) - d->updateCurrent(snapItem->index); - } - } - } - - if ((d->hData.flicking || d->vData.flicking) && d->correctFlick && !d->inFlickCorrection) { - d->inFlickCorrection = true; - // Near an end and it seems that the extent has changed? - // Recalculate the flick so that we don't end up in an odd position. - if (yflick() && !d->vData.inOvershoot) { - if (d->vData.velocity > 0) { - const qreal minY = minYExtent(); - if ((minY - d->vData.move.value() < height()/2 || d->vData.flickTarget - d->vData.move.value() < height()/2) - && minY != d->vData.flickTarget) - d->flickY(-d->vData.smoothVelocity.value()); - } else if (d->vData.velocity < 0) { - const qreal maxY = maxYExtent(); - if ((d->vData.move.value() - maxY < height()/2 || d->vData.move.value() - d->vData.flickTarget < height()/2) - && maxY != d->vData.flickTarget) - d->flickY(-d->vData.smoothVelocity.value()); - } - } - - if (xflick() && !d->hData.inOvershoot) { - if (d->hData.velocity > 0) { - const qreal minX = minXExtent(); - if ((minX - d->hData.move.value() < width()/2 || d->hData.flickTarget - d->hData.move.value() < width()/2) - && minX != d->hData.flickTarget) - d->flickX(-d->hData.smoothVelocity.value()); - } else if (d->hData.velocity < 0) { - const qreal maxX = maxXExtent(); - if ((d->hData.move.value() - maxX < width()/2 || d->hData.move.value() - d->hData.flickTarget < width()/2) - && maxX != d->hData.flickTarget) - d->flickX(-d->hData.smoothVelocity.value()); - } - } - d->inFlickCorrection = false; - } - if (d->sectionCriteria) { - d->updateCurrentSection(); - d->updateStickySections(); - } - d->inViewportMoved = false; -} - -void QQuickListView::keyPressEvent(QKeyEvent *event) -{ - Q_D(QQuickListView); - if (d->model && d->model->count() && d->interactive) { - if ((d->orient == QQuickListView::Horizontal && !d->isRightToLeft() && event->key() == Qt::Key_Left) - || (d->orient == QQuickListView::Horizontal && d->isRightToLeft() && event->key() == Qt::Key_Right) - || (d->orient == QQuickListView::Vertical && event->key() == Qt::Key_Up)) { - if (currentIndex() > 0 || (d->wrap && !event->isAutoRepeat())) { - decrementCurrentIndex(); - event->accept(); - return; - } else if (d->wrap) { - event->accept(); - return; - } - } else if ((d->orient == QQuickListView::Horizontal && !d->isRightToLeft() && event->key() == Qt::Key_Right) - || (d->orient == QQuickListView::Horizontal && d->isRightToLeft() && event->key() == Qt::Key_Left) - || (d->orient == QQuickListView::Vertical && event->key() == Qt::Key_Down)) { - if (currentIndex() < d->model->count() - 1 || (d->wrap && !event->isAutoRepeat())) { - incrementCurrentIndex(); - event->accept(); - return; - } else if (d->wrap) { - event->accept(); - return; - } - } - } - event->ignore(); - QQuickItemView::keyPressEvent(event); -} - -void QQuickListView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickListView); - if (d->isRightToLeft() && d->orient == QQuickListView::Horizontal) { - // maintain position relative to the right edge - int dx = newGeometry.width() - oldGeometry.width(); - setContentX(contentX() - dx); - } - QQuickItemView::geometryChanged(newGeometry, oldGeometry); -} - - -/*! - \qmlmethod QtQuick2::ListView::incrementCurrentIndex() - - Increments the current index. The current index will wrap - if keyNavigationWraps is true and it is currently at the end. - This method has no effect if the \l count is zero. - - \bold Note: methods should only be called after the Component has completed. -*/ -void QQuickListView::incrementCurrentIndex() -{ - Q_D(QQuickListView); - int count = d->model ? d->model->count() : 0; - if (count && (currentIndex() < count - 1 || d->wrap)) { - d->moveReason = QQuickListViewPrivate::SetIndex; - int index = currentIndex()+1; - setCurrentIndex((index >= 0 && index < count) ? index : 0); - } -} - -/*! - \qmlmethod QtQuick2::ListView::decrementCurrentIndex() - - Decrements the current index. The current index will wrap - if keyNavigationWraps is true and it is currently at the beginning. - This method has no effect if the \l count is zero. - - \bold Note: methods should only be called after the Component has completed. -*/ -void QQuickListView::decrementCurrentIndex() -{ - Q_D(QQuickListView); - int count = d->model ? d->model->count() : 0; - if (count && (currentIndex() > 0 || d->wrap)) { - d->moveReason = QQuickListViewPrivate::SetIndex; - int index = currentIndex()-1; - setCurrentIndex((index >= 0 && index < count) ? index : count-1); - } -} - -void QQuickListView::updateSections() -{ - Q_D(QQuickListView); - if (isComponentComplete() && d->model) { - QList roles; - if (d->sectionCriteria && !d->sectionCriteria->property().isEmpty()) - roles << d->sectionCriteria->property().toUtf8(); - d->model->setWatchedRoles(roles); - d->updateSections(); - if (d->itemCount) { - d->forceLayout = true; - d->layout(); - } - } -} - -bool QQuickListViewPrivate::applyInsertionChange(const QDeclarativeChangeSet::Insert &change, FxViewItem *firstVisible, InsertionsResult *insertResult) -{ - int modelIndex = change.index; - int count = change.count; - - - qreal tempPos = isRightToLeft() ? -position()-size() : position(); - int index = visibleItems.count() ? mapFromModel(modelIndex) : 0; - - if (index < 0) { - int i = visibleItems.count() - 1; - while (i > 0 && visibleItems.at(i)->index == -1) - --i; - if (i == 0 && visibleItems.first()->index == -1) { - // there are no visible items except items marked for removal - index = visibleItems.count(); - } else if (visibleItems.at(i)->index + 1 == modelIndex - && visibleItems.at(i)->endPosition() <= buffer+tempPos+size()) { - // Special case of appending an item to the model. - index = visibleItems.count(); - } else { - if (modelIndex < visibleIndex) { - // Insert before visible items - visibleIndex += count; - for (int i = 0; i < visibleItems.count(); ++i) { - FxViewItem *item = visibleItems.at(i); - if (item->index != -1 && item->index >= modelIndex) - item->index += count; - } - } - return true; - } - } - - // index can be the next item past the end of the visible items list (i.e. appended) - int pos = 0; - if (visibleItems.count()) { - pos = index < visibleItems.count() ? visibleItems.at(index)->position() - : visibleItems.last()->endPosition()+spacing; - } - - int prevAddedCount = insertResult->addedItems.count(); - if (firstVisible && pos < firstVisible->position()) { - // Insert items before the visible item. - int insertionIdx = index; - int i = 0; - int from = tempPos - buffer; - - for (i = count-1; i >= 0; --i) { - if (pos > from && insertionIdx < visibleIndex) { - // item won't be visible, just note the size for repositioning - insertResult->sizeAddedBeforeVisible += averageSize + spacing; - pos -= averageSize + spacing; - } else { - // item is before first visible e.g. in cache buffer - FxViewItem *item = 0; - if (change.isMove() && (item = currentChanges.removedItems.take(change.moveKey(modelIndex + i)))) { - if (item->index > modelIndex + i) - insertResult->movedBackwards.append(item); - item->index = modelIndex + i; - } - if (!item) - item = createItem(modelIndex + i); - if (!item) - return false; - - visibleItems.insert(insertionIdx, item); - if (!change.isMove()) { - insertResult->addedItems.append(item); - insertResult->sizeAddedBeforeVisible += item->size(); - } - pos -= item->size() + spacing; - } - index++; - } - } else { - int i = 0; - int to = buffer+tempPos+size(); - for (i = 0; i < count && pos <= to; ++i) { - FxViewItem *item = 0; - if (change.isMove() && (item = currentChanges.removedItems.take(change.moveKey(modelIndex + i)))) { - if (item->index > modelIndex + i) - insertResult->movedBackwards.append(item); - item->index = modelIndex + i; - } - if (!item) - item = createItem(modelIndex + i); - if (!item) - return false; - - visibleItems.insert(index, item); - if (!change.isMove()) - insertResult->addedItems.append(item); - pos += item->size() + spacing; - ++index; - } - } - - for (; index < visibleItems.count(); ++index) { - FxViewItem *item = visibleItems.at(index); - if (item->index != -1) - item->index += count; - } - - updateVisibleIndex(); - - return insertResult->addedItems.count() > prevAddedCount; -} - - -/*! - \qmlmethod QtQuick2::ListView::positionViewAtIndex(int index, PositionMode mode) - - Positions the view such that the \a index is at the position specified by - \a mode: - - \list - \o ListView.Beginning - position item at the top (or left for horizontal orientation) of the view. - \o ListView.Center - position item in the center of the view. - \o ListView.End - position item at bottom (or right for horizontal orientation) of the view. - \o ListView.Visible - if any part of the item is visible then take no action, otherwise - bring the item into view. - \o ListView.Contain - ensure the entire item is visible. If the item is larger than - the view the item is positioned at the top (or left for horizontal orientation) of the view. - \endlist - - If positioning the view at \a index would cause empty space to be displayed at - the beginning or end of the view, the view will be positioned at the boundary. - - It is not recommended to use \l {Flickable::}{contentX} or \l {Flickable::}{contentY} to position the view - at a particular index. This is unreliable since removing items from the start - of the list does not cause all other items to be repositioned, and because - the actual start of the view can vary based on the size of the delegates. - The correct way to bring an item into view is with \c positionViewAtIndex. - - \bold Note: methods should only be called after the Component has completed. To position - the view at startup, this method should be called by Component.onCompleted. For - example, to position the view at the end: - - \code - Component.onCompleted: positionViewAtIndex(count - 1, ListView.Beginning) - \endcode -*/ - -/*! - \qmlmethod QtQuick2::ListView::positionViewAtBeginning() - \qmlmethod QtQuick2::ListView::positionViewAtEnd() - - Positions the view at the beginning or end, taking into account any header or footer. - - It is not recommended to use \l {Flickable::}{contentX} or \l {Flickable::}{contentY} to position the view - at a particular index. This is unreliable since removing items from the start - of the list does not cause all other items to be repositioned, and because - the actual start of the view can vary based on the size of the delegates. - - \bold Note: methods should only be called after the Component has completed. To position - the view at startup, this method should be called by Component.onCompleted. For - example, to position the view at the end on startup: - - \code - Component.onCompleted: positionViewAtEnd() - \endcode -*/ - -/*! - \qmlmethod int QtQuick2::ListView::indexAt(int x, int y) - - Returns the index of the visible item containing the point \a x, \a y in content - coordinates. If there is no item at the point specified, or the item is - not visible -1 is returned. - - If the item is outside the visible area, -1 is returned, regardless of - whether an item will exist at that point when scrolled into view. - - \bold Note: methods should only be called after the Component has completed. -*/ - -QQuickListViewAttached *QQuickListView::qmlAttachedProperties(QObject *obj) -{ - return new QQuickListViewAttached(obj); -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquicklistview_p.h b/src/declarative/items/qquicklistview_p.h deleted file mode 100644 index 0266e23cd5..0000000000 --- a/src/declarative/items/qquicklistview_p.h +++ /dev/null @@ -1,215 +0,0 @@ -// Commit: 95814418f9d6adeba365c795462e8afb00138211 -/**************************************************************************** -** -** 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$ -** 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 QQUICKLISTVIEW_P_H -#define QQUICKLISTVIEW_P_H - -#include "qquickitemview_p.h" - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickListView; -class QQuickListViewPrivate; -class Q_AUTOTEST_EXPORT QQuickViewSection : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged) - Q_PROPERTY(SectionCriteria criteria READ criteria WRITE setCriteria NOTIFY criteriaChanged) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) - Q_PROPERTY(int labelPositioning READ labelPositioning WRITE setLabelPositioning NOTIFY labelPositioningChanged) - Q_ENUMS(SectionCriteria) - Q_ENUMS(LabelPositioning) -public: - QQuickViewSection(QQuickListView *parent=0); - - QString property() const { return m_property; } - void setProperty(const QString &); - - enum SectionCriteria { FullString, FirstCharacter }; - SectionCriteria criteria() const { return m_criteria; } - void setCriteria(SectionCriteria); - - QDeclarativeComponent *delegate() const { return m_delegate; } - void setDelegate(QDeclarativeComponent *delegate); - - QString sectionString(const QString &value); - - enum LabelPositioning { InlineLabels = 0x01, CurrentLabelAtStart = 0x02, NextLabelAtEnd = 0x04 }; - int labelPositioning() { return m_labelPositioning; } - void setLabelPositioning(int pos); - -Q_SIGNALS: - void propertyChanged(); - void criteriaChanged(); - void delegateChanged(); - void labelPositioningChanged(); - -private: - QString m_property; - SectionCriteria m_criteria; - QDeclarativeComponent *m_delegate; - int m_labelPositioning; - QQuickListViewPrivate *m_view; -}; - - -class QQuickVisualModel; -class QQuickListViewAttached; -class Q_AUTOTEST_EXPORT QQuickListView : public QQuickItemView -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QQuickListView) - - // XXX deprecate these two properties (only duration should be necessary) - Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) - Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) - - Q_PROPERTY(int highlightResizeDuration READ highlightResizeDuration WRITE setHighlightResizeDuration NOTIFY highlightResizeDurationChanged) - - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) - Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) - - Q_PROPERTY(QQuickViewSection *section READ sectionCriteria CONSTANT) - Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) - - Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged) - - Q_ENUMS(Orientation) - Q_ENUMS(SnapMode) - Q_CLASSINFO("DefaultProperty", "data") - -public: - QQuickListView(QQuickItem *parent=0); - ~QQuickListView(); - - qreal spacing() const; - void setSpacing(qreal spacing); - - enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical }; - Orientation orientation() const; - void setOrientation(Orientation); - - QQuickViewSection *sectionCriteria(); - QString currentSection() const; - - virtual void setHighlightFollowsCurrentItem(bool); - - qreal highlightMoveSpeed() const; - void setHighlightMoveSpeed(qreal); - - qreal highlightResizeSpeed() const; - void setHighlightResizeSpeed(qreal); - - int highlightResizeDuration() const; - void setHighlightResizeDuration(int); - - virtual void setHighlightMoveDuration(int); - - enum SnapMode { NoSnap, SnapToItem, SnapOneItem }; - SnapMode snapMode() const; - void setSnapMode(SnapMode mode); - - static QQuickListViewAttached *qmlAttachedProperties(QObject *); - -public Q_SLOTS: - void incrementCurrentIndex(); - void decrementCurrentIndex(); - -Q_SIGNALS: - void spacingChanged(); - void orientationChanged(); - void currentSectionChanged(); - void highlightMoveSpeedChanged(); - void highlightResizeSpeedChanged(); - void highlightResizeDurationChanged(); - void snapModeChanged(); - -protected: - virtual void viewportMoved(); - virtual void keyPressEvent(QKeyEvent *); - virtual void geometryChanged(const QRectF &newGeometry,const QRectF &oldGeometry); - -protected Q_SLOTS: - void updateSections(); -}; - -class QQuickListViewAttached : public QQuickItemViewAttached -{ - Q_OBJECT - -public: - QQuickListViewAttached(QObject *parent) - : QQuickItemViewAttached(parent), m_view(0) {} - ~QQuickListViewAttached() {} - - Q_PROPERTY(QQuickListView *view READ view NOTIFY viewChanged) - QQuickListView *view() { return m_view; } - void setView(QQuickListView *view) { - if (view != m_view) { - m_view = view; - emit viewChanged(); - } - } - -Q_SIGNALS: - void viewChanged(); - -public: - QDeclarativeGuard m_view; -}; - - -QT_END_NAMESPACE - -QML_DECLARE_TYPEINFO(QQuickListView, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QQuickListView) -QML_DECLARE_TYPE(QQuickViewSection) - -QT_END_HEADER - -#endif // QQUICKLISTVIEW_P_H diff --git a/src/declarative/items/qquickloader.cpp b/src/declarative/items/qquickloader.cpp deleted file mode 100644 index f9fd9148ee..0000000000 --- a/src/declarative/items/qquickloader.cpp +++ /dev/null @@ -1,858 +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 QtDeclarative module 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 "qquickloader_p_p.h" - -#include - -#include -#include - -#include - -#include - -QT_BEGIN_NAMESPACE - -QQuickLoaderPrivate::QQuickLoaderPrivate() - : item(0), component(0), itemContext(0), incubator(0), updatingSize(false), - itemWidthValid(false), itemHeightValid(false), - active(true), loadingFromSource(false), asynchronous(false) -{ -} - -QQuickLoaderPrivate::~QQuickLoaderPrivate() -{ - delete incubator; - disposeInitialPropertyValues(); -} - -void QQuickLoaderPrivate::itemGeometryChanged(QQuickItem *resizeItem, const QRectF &newGeometry, const QRectF &oldGeometry) -{ - if (resizeItem == item) { - if (!updatingSize && newGeometry.width() != oldGeometry.width()) - itemWidthValid = true; - if (!updatingSize && newGeometry.height() != oldGeometry.height()) - itemHeightValid = true; - _q_updateSize(false); - } - QQuickItemChangeListener::itemGeometryChanged(resizeItem, newGeometry, oldGeometry); -} - -void QQuickLoaderPrivate::clear() -{ - disposeInitialPropertyValues(); - - if (incubator) - incubator->clear(); - - if (loadingFromSource && component) { - component->deleteLater(); - component = 0; - } - source = QUrl(); - - if (item) { - QQuickItemPrivate *p = QQuickItemPrivate::get(item); - p->removeItemChangeListener(this, QQuickItemPrivate::Geometry); - - // We can't delete immediately because our item may have triggered - // the Loader to load a different item. - item->setParentItem(0); - item->setVisible(false); - item->deleteLater(); - item = 0; - } -} - -void QQuickLoaderPrivate::initResize() -{ - QQuickItemPrivate *p = QQuickItemPrivate::get(item); - p->addItemChangeListener(this, QQuickItemPrivate::Geometry); - // We may override the item's size, so we need to remember - // whether the item provided its own valid size. - itemWidthValid = p->widthValid; - itemHeightValid = p->heightValid; - _q_updateSize(); -} - -/*! - \qmlclass Loader QQuickLoader - \inqmlmodule QtQuick 2 - \ingroup qml-utility-elements - \inherits Item - - \brief The Loader item allows dynamically loading an Item-based - subtree from a URL or Component. - - Loader is used to dynamically load visual QML components. It can load a - QML file (using the \l source property) or a \l Component object (using - the \l sourceComponent property). It is useful for delaying the creation - of a component until it is required: for example, when a component should - be created on demand, or when a component should not be created - unnecessarily for performance reasons. - - Here is a Loader that loads "Page1.qml" as a component when the - \l MouseArea is clicked: - - \snippet doc/src/snippets/declarative/loader/simple.qml 0 - - The loaded item can be accessed using the \l item property. - - If the \l source or \l sourceComponent changes, any previously instantiated - items are destroyed. Setting \l source to an empty string or setting - \l sourceComponent to \c undefined destroys the currently loaded item, - freeing resources and leaving the Loader empty. - - \section2 Loader sizing behavior - - Loader is like any other visual item and must be positioned and sized - accordingly to become visible. - - \list - \o If an explicit size is not specified for the Loader, the Loader - is automatically resized to the size of the loaded item once the - component is loaded. - \o If the size of the Loader is specified explicitly by setting - the width, height or by anchoring, the loaded item will be resized - to the size of the Loader. - \endlist - - In both scenarios the size of the item and the Loader are identical. - This ensures that anchoring to the Loader is equivalent to anchoring - to the loaded item. - - \table - \row - \o sizeloader.qml - \o sizeitem.qml - \row - \o \snippet doc/src/snippets/declarative/loader/sizeloader.qml 0 - \o \snippet doc/src/snippets/declarative/loader/sizeitem.qml 0 - \row - \o The red rectangle will be sized to the size of the root item. - \o The red rectangle will be 50x50, centered in the root item. - \endtable - - - \section2 Receiving signals from loaded items - - Any signals emitted from the loaded item can be received using the - \l Connections element. For example, the following \c application.qml - loads \c MyItem.qml, and is able to receive the \c message signal from - the loaded item through a \l Connections object: - - \table - \row - \o application.qml - \o MyItem.qml - \row - \o \snippet doc/src/snippets/declarative/loader/connections.qml 0 - \o \snippet doc/src/snippets/declarative/loader/MyItem.qml 0 - \endtable - - Alternatively, since \c MyItem.qml is loaded within the scope of the - Loader, it could also directly call any function defined in the Loader or - its parent \l Item. - - - \section2 Focus and key events - - Loader is a focus scope. Its \l {Item::}{focus} property must be set to - \c true for any of its children to get the \e {active focus}. (See - \l{qmlfocus#Acquiring Focus and Focus Scopes}{the focus documentation page} - for more details.) Any key events received in the loaded item should likely - also be \l {KeyEvent::}{accepted} so they are not propagated to the Loader. - - For example, the following \c application.qml loads \c KeyReader.qml when - the \l MouseArea is clicked. Notice the \l {Item::}{focus} property is - set to \c true for the Loader as well as the \l Item in the dynamically - loaded object: - - \table - \row - \o application.qml - \o KeyReader.qml - \row - \o \snippet doc/src/snippets/declarative/loader/focus.qml 0 - \o \snippet doc/src/snippets/declarative/loader/KeyReader.qml 0 - \endtable - - Once \c KeyReader.qml is loaded, it accepts key events and sets - \c event.accepted to \c true so that the event is not propagated to the - parent \l Rectangle. - - \sa {dynamic-object-creation}{Dynamic Object Creation} -*/ - -QQuickLoader::QQuickLoader(QQuickItem *parent) - : QQuickImplicitSizeItem(*(new QQuickLoaderPrivate), parent) -{ - setFlag(ItemIsFocusScope); -} - -QQuickLoader::~QQuickLoader() -{ - Q_D(QQuickLoader); - if (d->item) { - QQuickItemPrivate *p = QQuickItemPrivate::get(d->item); - p->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - } -} - -/*! - \qmlproperty bool QtQuick2::Loader::active - This property is \c true if the Loader is currently active. - The default value for the \l active property is \c true. - - If the Loader is inactive, changing the \l source or \l sourceComponent - will not cause the item to be instantiated until the Loader is made active. - - Setting the value to inactive will cause any \l item loaded by the loader - to be released, but will not affect the \l source or \l sourceComponent. - - The \l status of an inactive loader is always \c Null. - - \sa source, sourceComponent - */ -bool QQuickLoader::active() const -{ - Q_D(const QQuickLoader); - return d->active; -} - -void QQuickLoader::setActive(bool newVal) -{ - Q_D(QQuickLoader); - if (d->active != newVal) { - d->active = newVal; - if (newVal == true) { - if (d->loadingFromSource) { - loadFromSource(); - } else { - loadFromSourceComponent(); - } - } else { - if (d->item) { - QQuickItemPrivate *p = QQuickItemPrivate::get(d->item); - p->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - - // We can't delete immediately because our item may have triggered - // the Loader to load a different item. - d->item->setParentItem(0); - d->item->setVisible(false); - d->item->deleteLater(); - d->item = 0; - emit itemChanged(); - } - emit statusChanged(); - } - emit activeChanged(); - } -} - - -/*! - \qmlproperty url QtQuick2::Loader::source - This property holds the URL of the QML component to instantiate. - - Note the QML component must be an \l{Item}-based component. The loader - cannot load non-visual components. - - To unload the currently loaded item, set this property to an empty string, - or set \l sourceComponent to \c undefined. Setting \c source to a - new URL will also cause the item created by the previous URL to be unloaded. - - \sa sourceComponent, status, progress -*/ -QUrl QQuickLoader::source() const -{ - Q_D(const QQuickLoader); - return d->source; -} - -void QQuickLoader::setSource(const QUrl &url) -{ - setSource(url, true); // clear previous values -} - -void QQuickLoader::setSource(const QUrl &url, bool needsClear) -{ - Q_D(QQuickLoader); - if (d->source == url) - return; - - if (needsClear) - d->clear(); - - d->source = url; - d->loadingFromSource = true; - - if (d->active) - loadFromSource(); - else - emit sourceChanged(); -} - -void QQuickLoader::loadFromSource() -{ - Q_D(QQuickLoader); - if (d->source.isEmpty()) { - emit sourceChanged(); - emit statusChanged(); - emit progressChanged(); - emit itemChanged(); - return; - } - - if (isComponentComplete()) { - d->component = new QDeclarativeComponent(qmlEngine(this), d->source, this); - d->load(); - } -} - -/*! - \qmlproperty Component QtQuick2::Loader::sourceComponent - This property holds the \l{Component} to instantiate. - - \qml - Item { - Component { - id: redSquare - Rectangle { color: "red"; width: 10; height: 10 } - } - - Loader { sourceComponent: redSquare } - Loader { sourceComponent: redSquare; x: 10 } - } - \endqml - - To unload the currently loaded item, set this property to an empty string - or \c undefined. - - \sa source, progress -*/ - -QDeclarativeComponent *QQuickLoader::sourceComponent() const -{ - Q_D(const QQuickLoader); - return d->component; -} - -void QQuickLoader::setSourceComponent(QDeclarativeComponent *comp) -{ - Q_D(QQuickLoader); - if (comp == d->component) - return; - - d->clear(); - - d->component = comp; - d->loadingFromSource = false; - - if (d->active) - loadFromSourceComponent(); - else - emit sourceComponentChanged(); -} - -void QQuickLoader::resetSourceComponent() -{ - setSourceComponent(0); -} - -void QQuickLoader::loadFromSourceComponent() -{ - Q_D(QQuickLoader); - if (!d->component) { - emit sourceComponentChanged(); - emit statusChanged(); - emit progressChanged(); - emit itemChanged(); - return; - } - - if (isComponentComplete()) - d->load(); -} - -/*! - \qmlmethod object QtQuick2::Loader::setSource(url source, object properties) - - Creates an object instance of the given \a source component that will have - the given \a properties. The \a properties argument is optional. The instance - will be accessible via the \l item property once loading and instantiation - is complete. - - If the \l active property is \c false at the time when this function is called, - the given \a source component will not be loaded but the \a source and initial - \a properties will be cached. When the loader is made \l active, an instance of - the \a source component will be created with the initial \a properties set. - - Setting the initial property values of an instance of a component in this manner - will \bold{not} trigger any associated \l{Behavior}s. - - Note that the cached \a properties will be cleared if the \l source or \l sourceComponent - is changed after calling this function but prior to setting the loader \l active. - - Example: - \table - \row - \o - \qml - // ExampleComponent.qml - import QtQuick 2.0 - Rectangle { - id: rect - color: "red" - width: 10 - height: 10 - - Behavior on color { - NumberAnimation { - target: rect - property: "width" - to: (rect.width + 20) - duration: 0 - } - } - } - \endqml - \o - \qml - // example.qml - import QtQuick 2.0 - Item { - Loader { - id: squareLoader - onLoaded: console.log(squareLoader.item.width); // prints [10], not [30] - } - - Component.onCompleted: { - squareLoader.setSource("ExampleComponent.qml", { "color": "blue" }); - // will trigger the onLoaded code when complete. - } - } - \endqml - \endtable - - \sa source, active -*/ -void QQuickLoader::setSource(QDeclarativeV8Function *args) -{ - Q_ASSERT(args); - Q_D(QQuickLoader); - - bool ipvError = false; - args->returnValue(v8::Undefined()); - v8::Handle ipv = d->extractInitialPropertyValues(args, this, &ipvError); - if (ipvError) - return; - - d->clear(); - QUrl sourceUrl = d->resolveSourceUrl(args); - if (!ipv.IsEmpty()) { - d->disposeInitialPropertyValues(); - d->initialPropertyValues = qPersistentNew(ipv); - d->qmlGlobalForIpv = qPersistentNew(args->qmlGlobal()); - } - - setSource(sourceUrl, false); // already cleared and set ipv above. -} - -void QQuickLoaderPrivate::disposeInitialPropertyValues() -{ - if (!initialPropertyValues.IsEmpty()) - qPersistentDispose(initialPropertyValues); - if (!qmlGlobalForIpv.IsEmpty()) - qPersistentDispose(qmlGlobalForIpv); -} - -void QQuickLoaderPrivate::load() -{ - Q_Q(QQuickLoader); - - if (!q->isComponentComplete() || !component) - return; - - if (!component->isLoading()) { - _q_sourceLoaded(); - } else { - QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), - q, SLOT(_q_sourceLoaded())); - QObject::connect(component, SIGNAL(progressChanged(qreal)), - q, SIGNAL(progressChanged())); - emit q->statusChanged(); - emit q->progressChanged(); - if (loadingFromSource) - emit q->sourceChanged(); - else - emit q->sourceComponentChanged(); - emit q->itemChanged(); - } -} - -void QQuickLoaderIncubator::setInitialState(QObject *o) -{ - loader->setInitialState(o); -} - -void QQuickLoaderPrivate::setInitialState(QObject *obj) -{ - Q_Q(QQuickLoader); - - QQuickItem *item = qobject_cast(obj); - if (item) { - QDeclarative_setParent_noEvent(itemContext, obj); - QDeclarative_setParent_noEvent(item, q); - item->setParentItem(q); - } - - if (initialPropertyValues.IsEmpty()) - return; - - QDeclarativeComponentPrivate *d = QDeclarativeComponentPrivate::get(component); - Q_ASSERT(d && d->engine); - d->initializeObjectWithInitialProperties(qmlGlobalForIpv, initialPropertyValues, obj); -} - -void QQuickLoaderIncubator::statusChanged(Status status) -{ - loader->incubatorStateChanged(status); -} - -void QQuickLoaderPrivate::incubatorStateChanged(QDeclarativeIncubator::Status status) -{ - Q_Q(QQuickLoader); - if (status == QDeclarativeIncubator::Loading || status == QDeclarativeIncubator::Null) - return; - - if (status == QDeclarativeIncubator::Ready) { - QObject *obj = incubator->object(); - item = qobject_cast(obj); - if (item) { - initResize(); - } else { - qmlInfo(q) << QQuickLoader::tr("Loader does not support loading non-visual elements."); - delete itemContext; - itemContext = 0; - delete obj; - } - incubator->clear(); - } else if (status == QDeclarativeIncubator::Error) { - if (!incubator->errors().isEmpty()) - QDeclarativeEnginePrivate::warning(qmlEngine(q), incubator->errors()); - delete itemContext; - itemContext = 0; - delete incubator->object(); - source = QUrl(); - } - if (loadingFromSource) - emit q->sourceChanged(); - else - emit q->sourceComponentChanged(); - emit q->statusChanged(); - emit q->progressChanged(); - emit q->itemChanged(); - emit q->loaded(); - disposeInitialPropertyValues(); // cleanup -} - -void QQuickLoaderPrivate::_q_sourceLoaded() -{ - Q_Q(QQuickLoader); - if (!component || !component->errors().isEmpty()) { - if (component) - QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors()); - if (loadingFromSource) - emit q->sourceChanged(); - else - emit q->sourceComponentChanged(); - emit q->statusChanged(); - emit q->progressChanged(); - disposeInitialPropertyValues(); // cleanup - return; - } - - QDeclarativeContext *creationContext = component->creationContext(); - if (!creationContext) creationContext = qmlContext(q); - itemContext = new QDeclarativeContext(creationContext); - itemContext->setContextObject(q); - - delete incubator; - incubator = new QQuickLoaderIncubator(this, asynchronous ? QDeclarativeIncubator::Asynchronous : QDeclarativeIncubator::AsynchronousIfNested); - - component->create(*incubator, itemContext); - - if (incubator && incubator->status() == QDeclarativeIncubator::Loading) - emit q->statusChanged(); -} - -/*! - \qmlproperty enumeration QtQuick2::Loader::status - - This property holds the status of QML loading. It can be one of: - \list - \o Loader.Null - the loader is inactive or no QML source has been set - \o Loader.Ready - the QML source has been loaded - \o Loader.Loading - the QML source is currently being loaded - \o Loader.Error - an error occurred while loading the QML source - \endlist - - Use this status to provide an update or respond to the status change in some way. - For example, you could: - - \list - \o Trigger a state change: - \qml - State { name: 'loaded'; when: loader.status == Loader.Ready } - \endqml - - \o Implement an \c onStatusChanged signal handler: - \qml - Loader { - id: loader - onStatusChanged: if (loader.status == Loader.Ready) console.log('Loaded') - } - \endqml - - \o Bind to the status value: - \qml - Text { text: loader.status == Loader.Ready ? 'Loaded' : 'Not loaded' } - \endqml - \endlist - - Note that if the source is a local file, the status will initially be Ready (or Error). While - there will be no onStatusChanged signal in that case, the onLoaded will still be invoked. - - \sa progress -*/ - -QQuickLoader::Status QQuickLoader::status() const -{ - Q_D(const QQuickLoader); - - if (!d->active) - return Null; - - if (d->component) { - switch (d->component->status()) { - case QDeclarativeComponent::Loading: - return Loading; - case QDeclarativeComponent::Error: - return Error; - case QDeclarativeComponent::Null: - return Null; - default: - break; - } - } - - if (d->incubator) { - switch (d->incubator->status()) { - case QDeclarativeIncubator::Loading: - return Loading; - case QDeclarativeIncubator::Error: - return Error; - default: - break; - } - } - - if (d->item) - return Ready; - - return d->source.isEmpty() ? Null : Error; -} - -void QQuickLoader::componentComplete() -{ - Q_D(QQuickLoader); - QQuickItem::componentComplete(); - if (active()) { - if (d->loadingFromSource) { - d->component = new QDeclarativeComponent(qmlEngine(this), d->source, this); - } - d->load(); - } -} - -/*! - \qmlsignal QtQuick2::Loader::onLoaded() - - This handler is called when the \l status becomes \c Loader.Ready, or on successful - initial load. -*/ - - -/*! -\qmlproperty real QtQuick2::Loader::progress - -This property holds the progress of loading QML data from the network, from -0.0 (nothing loaded) to 1.0 (finished). Most QML files are quite small, so -this value will rapidly change from 0 to 1. - -\sa status -*/ -qreal QQuickLoader::progress() const -{ - Q_D(const QQuickLoader); - - if (d->item) - return 1.0; - - if (d->component) - return d->component->progress(); - - return 0.0; -} - -/*! -\qmlproperty bool QtQuick2::Loader::asynchronous - -This property holds whether the component will be instantiated asynchronously. - -Loading asynchronously creates the objects declared by the component -across multiple frames, and reduces the -likelihood of glitches in animation. When loading asynchronously the status -will change to Loader.Loading. Once the entire component has been created, the -\l item will be available and the status will change to Loader.Ready. - -To avoid seeing the items loading progressively set \c visible appropriately, e.g. - -\code -Loader { - source: "mycomponent.qml" - asynchronous: true - visible: status == Loader.Ready -} -\endcode - -Note that this property affects object instantiation only; it is unrelated to -loading a component asynchronously via a network. -*/ -bool QQuickLoader::asynchronous() const -{ - Q_D(const QQuickLoader); - return d->asynchronous; -} - -void QQuickLoader::setAsynchronous(bool a) -{ - Q_D(QQuickLoader); - if (d->asynchronous == a) - return; - - d->asynchronous = a; - emit asynchronousChanged(); -} - -void QQuickLoaderPrivate::_q_updateSize(bool loaderGeometryChanged) -{ - Q_Q(QQuickLoader); - if (!item || updatingSize) - return; - - updatingSize = true; - - qreal iWidth = !itemWidthValid ? item->implicitWidth() : item->width(); - qreal iHeight = !itemHeightValid ? item->implicitHeight() : item->height(); - q->setImplicitSize(iWidth, iHeight); - - if (loaderGeometryChanged && q->widthValid()) - item->setWidth(q->width()); - if (loaderGeometryChanged && q->heightValid()) - item->setHeight(q->height()); - - updatingSize = false; -} - -/*! - \qmlproperty Item QtQuick2::Loader::item - This property holds the top-level item that is currently loaded. -*/ -QQuickItem *QQuickLoader::item() const -{ - Q_D(const QQuickLoader); - return d->item; -} - -void QQuickLoader::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickLoader); - if (newGeometry != oldGeometry) { - d->_q_updateSize(); - } - QQuickItem::geometryChanged(newGeometry, oldGeometry); -} - -QUrl QQuickLoaderPrivate::resolveSourceUrl(QDeclarativeV8Function *args) -{ - QV8Engine *v8engine = args->engine(); - QString arg = v8engine->toString((*args)[0]->ToString()); - if (arg.isEmpty()) - return QUrl(); - - QDeclarativeContextData *context = args->context(); - Q_ASSERT(context); - return context->resolvedUrl(QUrl(arg)); -} - -v8::Handle QQuickLoaderPrivate::extractInitialPropertyValues(QDeclarativeV8Function *args, QObject *loader, bool *error) -{ - v8::Local valuemap; - if (args->Length() >= 2) { - v8::Local v = (*args)[1]; - if (!v->IsObject() || v->IsArray()) { - *error = true; - qmlInfo(loader) << loader->tr("setSource: value is not an object"); - } else { - *error = false; - valuemap = v8::Local::Cast(v); - } - } - - return valuemap; -} - -#include - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickloader_p.h b/src/declarative/items/qquickloader_p.h deleted file mode 100644 index 3dcab4c654..0000000000 --- a/src/declarative/items/qquickloader_p.h +++ /dev/null @@ -1,123 +0,0 @@ -// Commit: 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4 -/**************************************************************************** -** -** 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$ -** 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 QQUICKLOADER_P_H -#define QQUICKLOADER_P_H - -#include "qquickimplicitsizeitem_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickLoaderPrivate; -class Q_AUTOTEST_EXPORT QQuickLoader : public QQuickImplicitSizeItem -{ - Q_OBJECT - Q_ENUMS(Status) - - Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(QDeclarativeComponent *sourceComponent READ sourceComponent WRITE setSourceComponent RESET resetSourceComponent NOTIFY sourceComponentChanged) - Q_PROPERTY(QQuickItem *item READ item NOTIFY itemChanged) - Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) - Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged) - -public: - QQuickLoader(QQuickItem *parent = 0); - virtual ~QQuickLoader(); - - bool active() const; - void setActive(bool newVal); - - Q_INVOKABLE void setSource(QDeclarativeV8Function *); - - QUrl source() const; - void setSource(const QUrl &); - - QDeclarativeComponent *sourceComponent() const; - void setSourceComponent(QDeclarativeComponent *); - void resetSourceComponent(); - - enum Status { Null, Ready, Loading, Error }; - Status status() const; - qreal progress() const; - - bool asynchronous() const; - void setAsynchronous(bool a); - - QQuickItem *item() const; - -Q_SIGNALS: - void itemChanged(); - void activeChanged(); - void sourceChanged(); - void sourceComponentChanged(); - void statusChanged(); - void progressChanged(); - void loaded(); - void asynchronousChanged(); - -protected: - void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); - void componentComplete(); - -private: - void setSource(const QUrl &sourceUrl, bool needsClear); - void loadFromSource(); - void loadFromSourceComponent(); - Q_DISABLE_COPY(QQuickLoader) - Q_DECLARE_PRIVATE(QQuickLoader) - Q_PRIVATE_SLOT(d_func(), void _q_sourceLoaded()) - Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickLoader) - -QT_END_HEADER - -#endif // QQUICKLOADER_P_H diff --git a/src/declarative/items/qquickloader_p_p.h b/src/declarative/items/qquickloader_p_p.h deleted file mode 100644 index 63d73e8da2..0000000000 --- a/src/declarative/items/qquickloader_p_p.h +++ /dev/null @@ -1,121 +0,0 @@ -// Commit: 5d2817cd668a705729df1727de49adf00713ac97 -/**************************************************************************** -** -** 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$ -** 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 QQUICKLOADER_P_P_H -#define QQUICKLOADER_P_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 "qquickloader_p.h" -#include "qquickimplicitsizeitem_p_p.h" -#include "qquickitemchangelistener_p.h" -#include - -#include - -QT_BEGIN_NAMESPACE - - -class QQuickLoaderPrivate; -class QQuickLoaderIncubator : public QDeclarativeIncubator -{ -public: - QQuickLoaderIncubator(QQuickLoaderPrivate *l, IncubationMode mode) : QDeclarativeIncubator(mode), loader(l) {} - -protected: - virtual void statusChanged(Status); - virtual void setInitialState(QObject *); - -private: - QQuickLoaderPrivate *loader; -}; - -class QDeclarativeContext; -class QQuickLoaderPrivate : public QQuickImplicitSizeItemPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickLoader) - -public: - QQuickLoaderPrivate(); - ~QQuickLoaderPrivate(); - - void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry); - void clear(); - void initResize(); - void load(); - - void incubatorStateChanged(QDeclarativeIncubator::Status status); - void setInitialState(QObject *o); - void disposeInitialPropertyValues(); - QUrl resolveSourceUrl(QDeclarativeV8Function *args); - v8::Handle extractInitialPropertyValues(QDeclarativeV8Function *args, QObject *loader, bool *error); - - QUrl source; - QQuickItem *item; - QDeclarativeComponent *component; - QDeclarativeContext *itemContext; - QQuickLoaderIncubator *incubator; - v8::Persistent initialPropertyValues; - v8::Persistent qmlGlobalForIpv; - bool updatingSize: 1; - bool itemWidthValid : 1; - bool itemHeightValid : 1; - bool active : 1; - bool loadingFromSource : 1; - bool asynchronous : 1; - - void _q_sourceLoaded(); - void _q_updateSize(bool loaderGeometryChanged = true); -}; - -QT_END_NAMESPACE - -#endif // QQUICKLOADER_P_P_H diff --git a/src/declarative/items/qquickmousearea.cpp b/src/declarative/items/qquickmousearea.cpp deleted file mode 100644 index 8d4f3e86b0..0000000000 --- a/src/declarative/items/qquickmousearea.cpp +++ /dev/null @@ -1,1168 +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 QtDeclarative module 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 "qquickmousearea_p.h" -#include "qquickmousearea_p_p.h" -#include "qquickcanvas.h" -#include "qquickevents_p_p.h" -#include "qquickdrag_p.h" - -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE -static const int PressAndHoldDelay = 800; - -QQuickDrag::QQuickDrag(QObject *parent) -: QObject(parent), _target(0), _axis(XandYAxis), _xmin(-FLT_MAX), -_xmax(FLT_MAX), _ymin(-FLT_MAX), _ymax(FLT_MAX), _active(false), _filterChildren(false) -{ -} - -QQuickDrag::~QQuickDrag() -{ -} - -QQuickItem *QQuickDrag::target() const -{ - return _target; -} - -void QQuickDrag::setTarget(QQuickItem *t) -{ - if (_target == t) - return; - _target = t; - emit targetChanged(); -} - -void QQuickDrag::resetTarget() -{ - if (_target == 0) - return; - _target = 0; - emit targetChanged(); -} - -QQuickDrag::Axis QQuickDrag::axis() const -{ - return _axis; -} - -void QQuickDrag::setAxis(QQuickDrag::Axis a) -{ - if (_axis == a) - return; - _axis = a; - emit axisChanged(); -} - -qreal QQuickDrag::xmin() const -{ - return _xmin; -} - -void QQuickDrag::setXmin(qreal m) -{ - if (_xmin == m) - return; - _xmin = m; - emit minimumXChanged(); -} - -qreal QQuickDrag::xmax() const -{ - return _xmax; -} - -void QQuickDrag::setXmax(qreal m) -{ - if (_xmax == m) - return; - _xmax = m; - emit maximumXChanged(); -} - -qreal QQuickDrag::ymin() const -{ - return _ymin; -} - -void QQuickDrag::setYmin(qreal m) -{ - if (_ymin == m) - return; - _ymin = m; - emit minimumYChanged(); -} - -qreal QQuickDrag::ymax() const -{ - return _ymax; -} - -void QQuickDrag::setYmax(qreal m) -{ - if (_ymax == m) - return; - _ymax = m; - emit maximumYChanged(); -} - -bool QQuickDrag::active() const -{ - return _active; -} - -void QQuickDrag::setActive(bool drag) -{ - if (_active == drag) - return; - _active = drag; - emit activeChanged(); -} - -bool QQuickDrag::filterChildren() const -{ - return _filterChildren; -} - -void QQuickDrag::setFilterChildren(bool filter) -{ - if (_filterChildren == filter) - return; - _filterChildren = filter; - emit filterChildrenChanged(); -} - -QQuickDragAttached *QQuickDrag::qmlAttachedProperties(QObject *obj) -{ - return new QQuickDragAttached(obj); -} - -QQuickMouseAreaPrivate::QQuickMouseAreaPrivate() -: absorb(true), hovered(false), pressed(false), longPress(false), - moved(false), stealMouse(false), doubleClick(false), preventStealing(false), - propagateComposedEvents(false), drag(0) -{ -} - -QQuickMouseAreaPrivate::~QQuickMouseAreaPrivate() -{ - delete drag; -} - -void QQuickMouseAreaPrivate::init() -{ - Q_Q(QQuickMouseArea); - q->setAcceptedMouseButtons(Qt::LeftButton); - q->setFiltersChildMouseEvents(true); -} - -void QQuickMouseAreaPrivate::saveEvent(QMouseEvent *event) -{ - lastPos = event->localPos(); - lastScenePos = event->windowPos(); - lastButton = event->button(); - lastButtons = event->buttons(); - lastModifiers = event->modifiers(); -} - -bool QQuickMouseAreaPrivate::isPressAndHoldConnected() -{ - Q_Q(QQuickMouseArea); - static int idx = QObjectPrivate::get(q)->signalIndex("pressAndHold(QQuickMouseEvent*)"); - return QObjectPrivate::get(q)->isSignalConnected(idx); -} - -bool QQuickMouseAreaPrivate::isDoubleClickConnected() -{ - Q_Q(QQuickMouseArea); - static int idx = QObjectPrivate::get(q)->signalIndex("doubleClicked(QQuickMouseEvent*)"); - return QObjectPrivate::get(q)->isSignalConnected(idx); -} - -bool QQuickMouseAreaPrivate::isClickConnected() -{ - Q_Q(QQuickMouseArea); - static int idx = QObjectPrivate::get(q)->signalIndex("clicked(QQuickMouseEvent*)"); - return QObjectPrivate::get(q)->isSignalConnected(idx); -} - -void QQuickMouseAreaPrivate::propagate(QQuickMouseEvent* event, PropagateType t) -{ - Q_Q(QQuickMouseArea); - if (!propagateComposedEvents) - return; - QPointF scenePos = q->mapToScene(QPointF(event->x(), event->y())); - propagateHelper(event, canvas->rootItem(), scenePos, t); -} - -bool QQuickMouseAreaPrivate::propagateHelper(QQuickMouseEvent *ev, QQuickItem *item,const QPointF &sp, PropagateType sig) -{ - //Based off of QQuickCanvas::deliverInitialMousePressEvent - //But specific to MouseArea, so doesn't belong in canvas - Q_Q(const QQuickMouseArea); - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - if (itemPrivate->opacity == 0.0) - return false; - - if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) { - QPointF p = item->mapFromScene(sp); - if (!QRectF(0, 0, item->width(), item->height()).contains(p)) - return false; - } - - QList children = itemPrivate->paintOrderChildItems(); - for (int ii = children.count() - 1; ii >= 0; --ii) { - QQuickItem *child = children.at(ii); - if (!child->isVisible() || !child->isEnabled()) - continue; - if (propagateHelper(ev, child, sp, sig)) - return true; - } - - QQuickMouseArea* ma = qobject_cast(item); - if (ma && ma != q && itemPrivate->acceptedMouseButtons & ev->button()) { - switch (sig) { - case Click: - if (!ma->d_func()->isClickConnected()) - return false; - break; - case DoubleClick: - if (!ma->d_func()->isDoubleClickConnected()) - return false; - break; - case PressAndHold: - if (!ma->d_func()->isPressAndHoldConnected()) - return false; - break; - } - QPointF p = item->mapFromScene(sp); - if (QRectF(0, 0, item->width(), item->height()).contains(p)) { - ev->setX(p.x()); - ev->setY(p.y()); - ev->setAccepted(true);//It is connected, they have to explicitly ignore to let it slide - switch (sig) { - case Click: emit ma->clicked(ev); break; - case DoubleClick: emit ma->doubleClicked(ev); break; - case PressAndHold: emit ma->pressAndHold(ev); break; - } - if (ev->isAccepted()) - return true; - } - } - return false; - -} - -/*! - \qmlclass MouseArea QQuickMouseArea - \inqmlmodule QtQuick 2 - \ingroup qml-basic-interaction-elements - \brief The MouseArea item enables simple mouse handling. - \inherits Item - - A MouseArea is an invisible item that is typically used in conjunction with - a visible item in order to provide mouse handling for that item. - By effectively acting as a proxy, the logic for mouse handling can be - contained within a MouseArea item. - - For basic key handling, see the \l{Keys}{Keys attached property}. - - The \l enabled property is used to enable and disable mouse handling for - the proxied item. When disabled, the mouse area becomes transparent to - mouse events. - - The \l pressed read-only property indicates whether or not the user is - holding down a mouse button over the mouse area. This property is often - used in bindings between properties in a user interface. The containsMouse - read-only property indicates the presence of the mouse cursor over the - mouse area but, by default, only when a mouse button is held down; see below - for further details. - - Information about the mouse position and button clicks are provided via - signals for which event handler properties are defined. The most commonly - used involved handling mouse presses and clicks: onClicked, onDoubleClicked, - onPressed, onReleased and onPressAndHold. - - By default, MouseArea items only report mouse clicks and not changes to the - position of the mouse cursor. Setting the hoverEnabled property ensures that - handlers defined for onPositionChanged, onEntered and onExited are used and - that the containsMouse property is updated even when no mouse buttons are - pressed. - - \section1 Example Usage - - \div {class="float-right"} - \inlineimage qml-mousearea-snippet.png - \enddiv - - The following example uses a MouseArea in a \l Rectangle that changes - the \l Rectangle color to red when clicked: - - \snippet doc/src/snippets/declarative/mousearea/mousearea.qml import - \codeline - \snippet doc/src/snippets/declarative/mousearea/mousearea.qml intro - - \clearfloat - Many MouseArea signals pass a \l{MouseEvent}{mouse} parameter that contains - additional information about the mouse event, such as the position, button, - and any key modifiers. - - Here is an extension of the previous example that produces a different - color when the area is right clicked: - - \snippet doc/src/snippets/declarative/mousearea/mousearea.qml intro-extended - - Behavioral Change in QtQuick 2.0 - - From QtQuick 2.0, the signals clicked, doubleClicked and pressAndHold have a different interaction - model with regards to the delivery of events to multiple overlapping MouseAreas. These signals can now propagate - to all MouseAreas in the area, in painting order, until accepted by one of them. A signal is accepted by - default if there is a signal handler for it, use mouse.accepted = false; to ignore. This propagation - can send the signal to MouseAreas other than the one which accepted the press event, although that MouseArea - will receive the signal first. This behavior can be enabled by setting propagateComposedEvents to true. - - \sa MouseEvent, {declarative/touchinteraction/mousearea}{MouseArea example} -*/ - -/*! - \qmlsignal QtQuick2::MouseArea::onEntered() - - This handler is called when the mouse enters the mouse area. - - By default the onEntered handler is only called while a button is - pressed. Setting hoverEnabled to true enables handling of - onEntered when no mouse button is pressed. - - \sa hoverEnabled -*/ - -/*! - \qmlsignal QtQuick2::MouseArea::onExited() - - This handler is called when the mouse exits the mouse area. - - By default the onExited handler is only called while a button is - pressed. Setting hoverEnabled to true enables handling of - onExited when no mouse button is pressed. - - The example below shows a fairly typical relationship between - two MouseAreas, with \c mouseArea2 on top of \c mouseArea1. Moving the - mouse into \c mouseArea2 from \c mouseArea1 will cause \c onExited - to be called for \c mouseArea1. - \qml - Rectangle { - width: 400; height: 400 - MouseArea { - id: mouseArea1 - anchors.fill: parent - hoverEnabled: true - } - MouseArea { - id: mouseArea2 - width: 100; height: 100 - anchors.centerIn: parent - hoverEnabled: true - } - } - \endqml - - If instead you give the two mouseAreas a parent-child relationship, - moving the mouse into \c mouseArea2 from \c mouseArea1 will \b not - cause \c onExited to be called for \c mouseArea1. Instead, they will - both be considered to be simultaneously hovered. - - \sa hoverEnabled -*/ - -/*! - \qmlsignal QtQuick2::MouseArea::onPositionChanged(MouseEvent mouse) - - This handler is called when the mouse position changes. - - The \l {MouseEvent}{mouse} parameter provides information about the mouse, including the x and y - position, and any buttons currently pressed. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. - - By default the onPositionChanged handler is only called while a button is - pressed. Setting hoverEnabled to true enables handling of - onPositionChanged when no mouse button is pressed. -*/ - -/*! - \qmlsignal QtQuick2::MouseArea::onClicked(MouseEvent mouse) - - This handler is called when there is a click. A click is defined as a press followed by a release, - both inside the MouseArea (pressing, moving outside the MouseArea, and then moving back inside and - releasing is also considered a click). - - The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y - position of the release of the click, and whether the click was held. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. -*/ - -/*! - \qmlsignal QtQuick2::MouseArea::onPressed(MouseEvent mouse) - - This handler is called when there is a press. - The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y - position and which button was pressed. - - The \e accepted property of the MouseEvent parameter determines whether this MouseArea - will handle the press and all future mouse events until release. The default is to accept - the event and not allow other MouseArea beneath this one to handle the event. If \e accepted - is set to false, no further events will be sent to this MouseArea until the button is next - pressed. -*/ - -/*! - \qmlsignal QtQuick2::MouseArea::onReleased(MouseEvent mouse) - - This handler is called when there is a release. - The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y - position of the release of the click, and whether the click was held. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. - - \sa onCanceled -*/ - -/*! - \qmlsignal QtQuick2::MouseArea::onPressAndHold(MouseEvent mouse) - - This handler is called when there is a long press (currently 800ms). - The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y - position of the press, and which button is pressed. - - The \e accepted property of the MouseEvent parameter is ignored in this handler. -*/ - -/*! - \qmlsignal QtQuick2::MouseArea::onDoubleClicked(MouseEvent mouse) - - This handler is called when there is a double-click (a press followed by a release followed by a press). - The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y - position of the release of the click, and whether the click was held. - - If the \e accepted property of the \l {MouseEvent}{mouse} parameter is set to false - in the handler, the onPressed/onReleased/onClicked handlers will be called for the second - click; otherwise they are suppressed. The accepted property defaults to true. -*/ - -/*! - \qmlsignal QtQuick2::MouseArea::onCanceled() - - This handler is called when mouse events have been canceled, either because an event was not accepted, or - because another element stole the mouse event handling. - - This signal is for advanced use: it is useful when there is more than one MouseArea - that is handling input, or when there is a MouseArea inside a \l Flickable. In the latter - case, if you execute some logic on the pressed signal and then start dragging, the - \l Flickable will steal the mouse handling from the MouseArea. In these cases, to reset - the logic when the MouseArea has lost the mouse handling to the \l Flickable, - \c onCanceled should be used in addition to onReleased. -*/ -QQuickMouseArea::QQuickMouseArea(QQuickItem *parent) - : QQuickItem(*(new QQuickMouseAreaPrivate), parent) -{ - Q_D(QQuickMouseArea); - d->init(); -} - -QQuickMouseArea::~QQuickMouseArea() -{ -} - -/*! - \qmlproperty real QtQuick2::MouseArea::mouseX - \qmlproperty real QtQuick2::MouseArea::mouseY - These properties hold the coordinates of the mouse cursor. - - If the hoverEnabled property is false then these properties will only be valid - while a button is pressed, and will remain valid as long as the button is held - down even if the mouse is moved outside the area. - - By default, this property is false. - - If hoverEnabled is true then these properties will be valid when: - \list - \i no button is pressed, but the mouse is within the MouseArea (containsMouse is true). - \i a button is pressed and held, even if it has since moved out of the area. - \endlist - - The coordinates are relative to the MouseArea. -*/ -qreal QQuickMouseArea::mouseX() const -{ - Q_D(const QQuickMouseArea); - return d->lastPos.x(); -} - -qreal QQuickMouseArea::mouseY() const -{ - Q_D(const QQuickMouseArea); - return d->lastPos.y(); -} - -/*! - \qmlproperty bool QtQuick2::MouseArea::enabled - This property holds whether the item accepts mouse events. - - By default, this property is true. -*/ -bool QQuickMouseArea::isEnabled() const -{ - Q_D(const QQuickMouseArea); - return d->absorb; -} - -void QQuickMouseArea::setEnabled(bool a) -{ - Q_D(QQuickMouseArea); - if (a != d->absorb) { - d->absorb = a; - emit enabledChanged(); - } -} - -/*! - \qmlproperty bool QtQuick2::MouseArea::preventStealing - This property holds whether the mouse events may be stolen from this - MouseArea. - - If a MouseArea is placed within an item that filters child mouse - events, such as Flickable, the mouse - events may be stolen from the MouseArea if a gesture is recognized - by the parent element, e.g. a flick gesture. If preventStealing is - set to true, no element will steal the mouse events. - - Note that setting preventStealing to true once an element has started - stealing events will have no effect until the next press event. - - By default this property is false. -*/ -bool QQuickMouseArea::preventStealing() const -{ - Q_D(const QQuickMouseArea); - return d->preventStealing; -} - -void QQuickMouseArea::setPreventStealing(bool prevent) -{ - Q_D(QQuickMouseArea); - if (prevent != d->preventStealing) { - d->preventStealing = prevent; - setKeepMouseGrab(d->preventStealing && d->absorb); - emit preventStealingChanged(); - } -} - - -/*! - \qmlproperty bool QtQuick2::MouseArea::propagateComposedEvents - This property holds whether composed mouse events will automatically propagate to - other MouseAreas. - - MouseArea contains several composed events, clicked, doubleClicked, - and pressAndHold. These can propagate via a separate mechanism to basic - mouse events, like pressed, which they are composed of. - - If propagateComposedEvents is set to true, then composed events will be automatically - propagated to other MouseAreas in the same location in the scene. They are propagated - in painting order until an item accepts them. Unlike pressed handling, events will - not be automatically accepted if no handler is present. - - This property greatly simplifies the usecase of when you want to have overlapping MouseAreas - handling the composed events together. For example: if you want one MouseArea to handle click - signals and the other to handle pressAndHold, or if you want one MouseArea to handle click most - of the time, but pass it through when certain conditions are met. - - By default this property is false. -*/ -bool QQuickMouseArea::propagateComposedEvents() const -{ - Q_D(const QQuickMouseArea); - return d->propagateComposedEvents; -} - -void QQuickMouseArea::setPropagateComposedEvents(bool prevent) -{ - Q_D(QQuickMouseArea); - if (prevent != d->propagateComposedEvents) { - d->propagateComposedEvents = prevent; - setKeepMouseGrab(d->propagateComposedEvents && d->absorb); - emit propagateComposedEventsChanged(); - } -} - -/*! - \qmlproperty MouseButtons QtQuick2::MouseArea::pressedButtons - This property holds the mouse buttons currently pressed. - - It contains a bitwise combination of: - \list - \o Qt.LeftButton - \o Qt.RightButton - \o Qt.MiddleButton - \endlist - - The code below displays "right" when the right mouse buttons is pressed: - - \snippet doc/src/snippets/declarative/mousearea/mousearea.qml mousebuttons - - \sa acceptedButtons -*/ -Qt::MouseButtons QQuickMouseArea::pressedButtons() const -{ - Q_D(const QQuickMouseArea); - return d->lastButtons; -} - -void QQuickMouseArea::mousePressEvent(QMouseEvent *event) -{ - Q_D(QQuickMouseArea); - d->moved = false; - d->stealMouse = d->preventStealing; - if (!d->absorb) - QQuickItem::mousePressEvent(event); - else { - d->longPress = false; - d->saveEvent(event); - if (d->drag) { - d->dragX = drag()->axis() & QQuickDrag::XAxis; - d->dragY = drag()->axis() & QQuickDrag::YAxis; - } - if (d->drag) - d->drag->setActive(false); - setHovered(true); - d->startScene = event->windowPos(); - d->pressAndHoldTimer.start(PressAndHoldDelay, this); - setKeepMouseGrab(d->stealMouse); - event->setAccepted(setPressed(true)); - - } -} - -void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event) -{ - Q_D(QQuickMouseArea); - if (!d->absorb) { - QQuickItem::mouseMoveEvent(event); - return; - } - - d->saveEvent(event); - - // ### we should skip this if these signals aren't used - // ### can GV handle this for us? - bool contains = boundingRect().contains(d->lastPos); - if (d->hovered && !contains) - setHovered(false); - else if (!d->hovered && contains) - setHovered(true); - - if (d->drag && d->drag->target()) { - if (!d->moved) { - d->targetStartPos = d->drag->target()->parentItem() - ? d->drag->target()->parentItem()->mapToScene(d->drag->target()->pos()) - : d->drag->target()->pos(); - } - - QPointF startLocalPos; - QPointF curLocalPos; - if (drag()->target()->parentItem()) { - startLocalPos = drag()->target()->parentItem()->mapFromScene(d->startScene); - curLocalPos = drag()->target()->parentItem()->mapFromScene(event->windowPos()); - } else { - startLocalPos = d->startScene; - curLocalPos = event->windowPos(); - } - - const int dragThreshold = qApp->styleHints()->startDragDistance(); - qreal dx = qAbs(curLocalPos.x() - startLocalPos.x()); - qreal dy = qAbs(curLocalPos.y() - startLocalPos.y()); - - if (keepMouseGrab() && d->stealMouse && !d->drag->active()) - d->drag->setActive(true); - - QPointF startPos = d->drag->target()->parentItem() - ? d->drag->target()->parentItem()->mapFromScene(d->targetStartPos) - : d->targetStartPos; - - QPointF dragPos = d->drag->target()->pos(); - - if (d->dragX && d->drag->active()) { - qreal x = (curLocalPos.x() - startLocalPos.x()) + startPos.x(); - if (x < drag()->xmin()) - x = drag()->xmin(); - else if (x > drag()->xmax()) - x = drag()->xmax(); - dragPos.setX(x); - } - if (d->dragY && d->drag->active()) { - qreal y = (curLocalPos.y() - startLocalPos.y()) + startPos.y(); - if (y < drag()->ymin()) - y = drag()->ymin(); - else if (y > drag()->ymax()) - y = drag()->ymax(); - dragPos.setY(y); - } - d->drag->target()->setPos(dragPos); - - if (!keepMouseGrab()) { - if ((!d->dragY && dy < dragThreshold && d->dragX && dx > dragThreshold) - || (!d->dragX && dx < dragThreshold && d->dragY && dy > dragThreshold) - || (d->dragX && d->dragY && (dx > dragThreshold || dy > dragThreshold))) { - setKeepMouseGrab(true); - d->stealMouse = true; - } - } - - d->moved = true; - } - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); - emit mouseXChanged(&me); - me.setPosition(d->lastPos); - emit mouseYChanged(&me); - me.setPosition(d->lastPos); - emit positionChanged(&me); -} - -void QQuickMouseArea::mouseReleaseEvent(QMouseEvent *event) -{ - Q_D(QQuickMouseArea); - d->stealMouse = false; - if (!d->absorb) { - QQuickItem::mouseReleaseEvent(event); - } else { - d->saveEvent(event); - setPressed(false); - if (d->drag) - d->drag->setActive(false); - // If we don't accept hover, we need to reset containsMouse. - if (!acceptHoverEvents()) - setHovered(false); - QQuickCanvas *c = canvas(); - if (c && c->mouseGrabberItem() == this) - ungrabMouse(); - setKeepMouseGrab(false); - - } - d->doubleClick = false; -} - -void QQuickMouseArea::mouseDoubleClickEvent(QMouseEvent *event) -{ - Q_D(QQuickMouseArea); - if (d->absorb) { - d->saveEvent(event); - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); - me.setAccepted(d->isDoubleClickConnected()); - emit this->doubleClicked(&me); - if (!me.isAccepted()) - d->propagate(&me, QQuickMouseAreaPrivate::DoubleClick); - d->doubleClick = d->isDoubleClickConnected() || me.isAccepted(); - } - QQuickItem::mouseDoubleClickEvent(event); -} - -void QQuickMouseArea::hoverEnterEvent(QHoverEvent *event) -{ - Q_D(QQuickMouseArea); - if (!d->absorb) { - QQuickItem::hoverEnterEvent(event); - } else { - d->lastPos = event->posF(); - d->lastModifiers = event->modifiers(); - setHovered(true); - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, Qt::NoButton, d->lastModifiers, false, false); - emit mouseXChanged(&me); - me.setPosition(d->lastPos); - emit mouseYChanged(&me); - me.setPosition(d->lastPos); - } -} - -void QQuickMouseArea::hoverMoveEvent(QHoverEvent *event) -{ - Q_D(QQuickMouseArea); - if (!d->absorb) { - QQuickItem::hoverMoveEvent(event); - } else { - d->lastPos = event->posF(); - d->lastModifiers = event->modifiers(); - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, Qt::NoButton, d->lastModifiers, false, false); - emit mouseXChanged(&me); - me.setPosition(d->lastPos); - emit mouseYChanged(&me); - me.setPosition(d->lastPos); - emit positionChanged(&me); - } -} - -void QQuickMouseArea::hoverLeaveEvent(QHoverEvent *event) -{ - Q_D(QQuickMouseArea); - if (!d->absorb) - QQuickItem::hoverLeaveEvent(event); - else - setHovered(false); -} - -void QQuickMouseArea::ungrabMouse() -{ - Q_D(QQuickMouseArea); - if (d->pressed) { - // if our mouse grab has been removed (probably by Flickable), fix our - // state - d->pressed = false; - d->stealMouse = false; - setKeepMouseGrab(false); - emit canceled(); - emit pressedChanged(); - if (d->hovered) { - d->hovered = false; - emit hoveredChanged(); - } - } -} - -void QQuickMouseArea::mouseUngrabEvent() -{ - ungrabMouse(); -} - -bool QQuickMouseArea::sendMouseEvent(QMouseEvent *event) -{ - Q_D(QQuickMouseArea); - QRectF myRect = mapRectToScene(QRectF(0, 0, width(), height())); - - QQuickCanvas *c = canvas(); - QQuickItem *grabber = c ? c->mouseGrabberItem() : 0; - bool stealThisEvent = d->stealMouse; - if ((stealThisEvent || myRect.contains(event->windowPos())) && (!grabber || !grabber->keepMouseGrab())) { - QMouseEvent mouseEvent(event->type(), mapFromScene(event->windowPos()), event->windowPos(), event->screenPos(), - event->button(), event->buttons(), event->modifiers()); - mouseEvent.setAccepted(false); - - switch (event->type()) { - case QEvent::MouseMove: - mouseMoveEvent(&mouseEvent); - break; - case QEvent::MouseButtonPress: - mousePressEvent(&mouseEvent); - break; - case QEvent::MouseButtonRelease: - mouseReleaseEvent(&mouseEvent); - break; - default: - break; - } - grabber = c->mouseGrabberItem(); - if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) - grabMouse(); - - return stealThisEvent; - } - if (event->type() == QEvent::MouseButtonRelease) { - if (d->pressed) { - d->pressed = false; - d->stealMouse = false; - if (c && c->mouseGrabberItem() == this) - ungrabMouse(); - emit canceled(); - emit pressedChanged(); - if (d->hovered) { - d->hovered = false; - emit hoveredChanged(); - } - } - } - return false; -} - -bool QQuickMouseArea::childMouseEventFilter(QQuickItem *i, QEvent *e) -{ - Q_D(QQuickMouseArea); - if (!d->absorb || !isVisible() || !d->drag || !d->drag->filterChildren()) - return QQuickItem::childMouseEventFilter(i, e); - switch (e->type()) { - case QEvent::MouseButtonPress: - case QEvent::MouseMove: - case QEvent::MouseButtonRelease: - return sendMouseEvent(static_cast(e)); - default: - break; - } - - return QQuickItem::childMouseEventFilter(i, e); -} - -void QQuickMouseArea::timerEvent(QTimerEvent *event) -{ - Q_D(QQuickMouseArea); - if (event->timerId() == d->pressAndHoldTimer.timerId()) { - d->pressAndHoldTimer.stop(); - bool dragged = d->drag && d->drag->active(); - if (d->pressed && dragged == false && d->hovered == true) { - d->longPress = true; - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); - me.setAccepted(d->isPressAndHoldConnected()); - emit pressAndHold(&me); - if (!me.isAccepted()) - d->propagate(&me, QQuickMouseAreaPrivate::PressAndHold); - if (!me.isAccepted()) // no one handled the long press - allow click - d->longPress = false; - } - } -} - -void QQuickMouseArea::windowDeactivateEvent() -{ - ungrabMouse(); - QQuickItem::windowDeactivateEvent(); -} - -void QQuickMouseArea::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - Q_D(QQuickMouseArea); - QQuickItem::geometryChanged(newGeometry, oldGeometry); - - if (d->lastScenePos.isNull) - d->lastScenePos = mapToScene(d->lastPos); - else if (newGeometry.x() != oldGeometry.x() || newGeometry.y() != oldGeometry.y()) - d->lastPos = mapFromScene(d->lastScenePos); -} - -void QQuickMouseArea::itemChange(ItemChange change, const ItemChangeData &value) -{ - Q_D(QQuickMouseArea); - switch (change) { - case ItemVisibleHasChanged: - if (acceptHoverEvents() && d->hovered != (isVisible() && isUnderMouse())) - setHovered(!d->hovered); - break; - default: - break; - } - - QQuickItem::itemChange(change, value); -} - -/*! - \qmlproperty bool QtQuick2::MouseArea::hoverEnabled - This property holds whether hover events are handled. - - By default, mouse events are only handled in response to a button event, or when a button is - pressed. Hover enables handling of all mouse events even when no mouse button is - pressed. - - This property affects the containsMouse property and the onEntered, onExited and - onPositionChanged signals. -*/ -bool QQuickMouseArea::hoverEnabled() const -{ - return acceptHoverEvents(); -} - -void QQuickMouseArea::setHoverEnabled(bool h) -{ - if (h == acceptHoverEvents()) - return; - - setAcceptHoverEvents(h); - emit hoverEnabledChanged(); -} - - -/*! - \qmlproperty bool QtQuick2::MouseArea::containsMouse - This property holds whether the mouse is currently inside the mouse area. - - \warning This property is not updated if the area moves under the mouse: \e containsMouse will not change. - In addition, if hoverEnabled is false, containsMouse will only be valid when the mouse is pressed. -*/ -bool QQuickMouseArea::hovered() const -{ - Q_D(const QQuickMouseArea); - return d->hovered; -} - -/*! - \qmlproperty bool QtQuick2::MouseArea::pressed - This property holds whether the mouse area is currently pressed. -*/ -bool QQuickMouseArea::pressed() const -{ - Q_D(const QQuickMouseArea); - return d->pressed; -} - -void QQuickMouseArea::setHovered(bool h) -{ - Q_D(QQuickMouseArea); - if (d->hovered != h) { - d->hovered = h; - emit hoveredChanged(); - d->hovered ? emit entered() : emit exited(); - } -} -/*! - \qmlproperty QtQuick2::Qt::MouseButtons MouseArea::acceptedButtons - This property holds the mouse buttons that the mouse area reacts to. - - The available buttons are: - \list - \o Qt.LeftButton - \o Qt.RightButton - \o Qt.MiddleButton - \endlist - - To accept more than one button the flags can be combined with the - "|" (or) operator: - - \code - MouseArea { acceptedButtons: Qt.LeftButton | Qt.RightButton } - \endcode - - The default value is \c Qt.LeftButton. -*/ -Qt::MouseButtons QQuickMouseArea::acceptedButtons() const -{ - return acceptedMouseButtons(); -} - -void QQuickMouseArea::setAcceptedButtons(Qt::MouseButtons buttons) -{ - if (buttons != acceptedMouseButtons()) { - setAcceptedMouseButtons(buttons); - emit acceptedButtonsChanged(); - } -} - -bool QQuickMouseArea::setPressed(bool p) -{ - Q_D(QQuickMouseArea); - bool dragged = d->drag && d->drag->active(); - bool isclick = d->pressed == true && p == false && dragged == false && d->hovered == true; - - if (d->pressed != p) { - d->pressed = p; - QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); - if (d->pressed) { - if (!d->doubleClick) - emit pressed(&me); - me.setPosition(d->lastPos); - emit mouseXChanged(&me); - me.setPosition(d->lastPos); - emit mouseYChanged(&me); - emit pressedChanged(); - } else { - emit released(&me); - me.setPosition(d->lastPos); - emit pressedChanged(); - if (isclick && !d->longPress && !d->doubleClick){ - me.setAccepted(d->isClickConnected()); - emit clicked(&me); - if (!me.isAccepted()) - d->propagate(&me, QQuickMouseAreaPrivate::Click); - } - } - - return me.isAccepted(); - } - return false; -} - -/*! - \qmlproperty Item QtQuick2::MouseArea::drag.target - \qmlproperty bool QtQuick2::MouseArea::drag.active - \qmlproperty enumeration QtQuick2::MouseArea::drag.axis - \qmlproperty real QtQuick2::MouseArea::drag.minimumX - \qmlproperty real QtQuick2::MouseArea::drag.maximumX - \qmlproperty real QtQuick2::MouseArea::drag.minimumY - \qmlproperty real QtQuick2::MouseArea::drag.maximumY - \qmlproperty bool QtQuick2::MouseArea::drag.filterChildren - - \c drag provides a convenient way to make an item draggable. - - \list - \i \c drag.target specifies the id of the item to drag. - \i \c drag.active specifies if the target item is currently being dragged. - \i \c drag.axis specifies whether dragging can be done horizontally (\c Drag.XAxis), vertically (\c Drag.YAxis), or both (\c Drag.XandYAxis) - \i \c drag.minimum and \c drag.maximum limit how far the target can be dragged along the corresponding axes. - \endlist - - The following example displays a \l Rectangle that can be dragged along the X-axis. The opacity - of the rectangle is reduced when it is dragged to the right. - - \snippet doc/src/snippets/declarative/mousearea/mousearea.qml drag - - \note Items cannot be dragged if they are anchored for the requested - \c drag.axis. For example, if \c anchors.left or \c anchors.right was set - for \c rect in the above example, it cannot be dragged along the X-axis. - This can be avoided by settng the anchor value to \c undefined in - an \l onPressed handler. - - If \c drag.filterChildren is set to true, a drag can override descendant MouseAreas. This - enables a parent MouseArea to handle drags, for example, while descendants handle clicks: - - \snippet doc/src/snippets/declarative/mousearea/mouseareadragfilter.qml dragfilter - -*/ - -QQuickDrag *QQuickMouseArea::drag() -{ - Q_D(QQuickMouseArea); - if (!d->drag) - d->drag = new QQuickDrag; - return d->drag; -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickmousearea_p.h b/src/declarative/items/qquickmousearea_p.h deleted file mode 100644 index b8fa7d5ce8..0000000000 --- a/src/declarative/items/qquickmousearea_p.h +++ /dev/null @@ -1,231 +0,0 @@ -// Commit: c6e6a35aeb8794d68a3ca0c4e27a3a1181c066b5 -/**************************************************************************** -** -** 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$ -** 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 QQUICKMOUSEAREA_P_H -#define QQUICKMOUSEAREA_P_H - -#include "qquickitem.h" - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickDragAttached; -class QQuickMouseEvent; -class Q_AUTOTEST_EXPORT QQuickDrag : public QObject -{ - Q_OBJECT - - Q_ENUMS(Axis) - Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget) - 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) - Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged) - 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) - //### consider drag and drop - -public: - QQuickDrag(QObject *parent=0); - ~QQuickDrag(); - - QQuickItem *target() const; - void setTarget(QQuickItem *target); - void resetTarget(); - - enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 }; - Axis axis() const; - void setAxis(Axis); - - qreal xmin() const; - void setXmin(qreal); - qreal xmax() const; - void setXmax(qreal); - qreal ymin() const; - void setYmin(qreal); - qreal ymax() const; - void setYmax(qreal); - - bool active() const; - void setActive(bool); - - bool filterChildren() const; - void setFilterChildren(bool); - - static QQuickDragAttached *qmlAttachedProperties(QObject *obj); - -Q_SIGNALS: - void targetChanged(); - void axisChanged(); - void minimumXChanged(); - void maximumXChanged(); - void minimumYChanged(); - void maximumYChanged(); - void activeChanged(); - void filterChildrenChanged(); - -private: - QQuickItem *_target; - Axis _axis; - qreal _xmin; - qreal _xmax; - qreal _ymin; - qreal _ymax; - bool _active : 1; - bool _filterChildren: 1; - Q_DISABLE_COPY(QQuickDrag) -}; - -class QQuickMouseAreaPrivate; -// used in QtLocation -class Q_DECLARATIVE_EXPORT QQuickMouseArea : public QQuickItem -{ - Q_OBJECT - - Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mouseXChanged) - Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mouseYChanged) - Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) - Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged) - Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) - Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged) - Q_PROPERTY(QQuickDrag *drag READ drag CONSTANT) //### add flicking to QQuickDrag or add a QDeclarativeFlick ??? - Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged) - Q_PROPERTY(bool propagateComposedEvents READ propagateComposedEvents WRITE setPropagateComposedEvents NOTIFY propagateComposedEventsChanged) - -public: - QQuickMouseArea(QQuickItem *parent=0); - ~QQuickMouseArea(); - - qreal mouseX() const; - qreal mouseY() const; - - bool isEnabled() const; - void setEnabled(bool); - - bool hovered() const; - bool pressed() const; - - Qt::MouseButtons pressedButtons() const; - - Qt::MouseButtons acceptedButtons() const; - void setAcceptedButtons(Qt::MouseButtons buttons); - - bool hoverEnabled() const; - void setHoverEnabled(bool h); - - QQuickDrag *drag(); - - bool preventStealing() const; - void setPreventStealing(bool prevent); - - bool propagateComposedEvents() const; - void setPropagateComposedEvents(bool propagate); - -Q_SIGNALS: - void hoveredChanged(); - void pressedChanged(); - void enabledChanged(); - void acceptedButtonsChanged(); - void hoverEnabledChanged(); - void positionChanged(QQuickMouseEvent *mouse); - void mouseXChanged(QQuickMouseEvent *mouse); - void mouseYChanged(QQuickMouseEvent *mouse); - void preventStealingChanged(); - void propagateComposedEventsChanged(); - - void pressed(QQuickMouseEvent *mouse); - void pressAndHold(QQuickMouseEvent *mouse); - void released(QQuickMouseEvent *mouse); - void clicked(QQuickMouseEvent *mouse); - void doubleClicked(QQuickMouseEvent *mouse); - void entered(); - void exited(); - void canceled(); - -protected: - void setHovered(bool); - bool setPressed(bool); - bool sendMouseEvent(QMouseEvent *event); - - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - virtual void mouseDoubleClickEvent(QMouseEvent *event); - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void mouseUngrabEvent(); - virtual void hoverEnterEvent(QHoverEvent *event); - virtual void hoverMoveEvent(QHoverEvent *event); - virtual void hoverLeaveEvent(QHoverEvent *event); - virtual bool childMouseEventFilter(QQuickItem *i, QEvent *e); - virtual void timerEvent(QTimerEvent *event); - virtual void windowDeactivateEvent(); - - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - virtual void itemChange(ItemChange change, const ItemChangeData& value); - -private: - void handlePress(); - void handleRelease(); - void ungrabMouse(); - -private: - Q_DISABLE_COPY(QQuickMouseArea) - Q_DECLARE_PRIVATE(QQuickMouseArea) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickDrag) -QML_DECLARE_TYPEINFO(QQuickDrag, QML_HAS_ATTACHED_PROPERTIES) -QML_DECLARE_TYPE(QQuickMouseArea) - -QT_END_HEADER - -#endif // QQUICKMOUSEAREA_P_H diff --git a/src/declarative/items/qquickmousearea_p_p.h b/src/declarative/items/qquickmousearea_p_p.h deleted file mode 100644 index c1c53c4302..0000000000 --- a/src/declarative/items/qquickmousearea_p_p.h +++ /dev/null @@ -1,112 +0,0 @@ -// Commit: c6e6a35aeb8794d68a3ca0c4e27a3a1181c066b5 -/**************************************************************************** -** -** 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$ -** 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 QQUICKMOUSEAREA_P_P_H -#define QQUICKMOUSEAREA_P_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 "qquickitem_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickMouseEvent; -class QQuickMouseArea; -class QQuickMouseAreaPrivate : public QQuickItemPrivate -{ - Q_DECLARE_PUBLIC(QQuickMouseArea) - -public: - QQuickMouseAreaPrivate(); - ~QQuickMouseAreaPrivate(); - void init(); - - void saveEvent(QMouseEvent *event); - enum PropagateType{ - Click, - DoubleClick, - PressAndHold - }; - void propagate(QQuickMouseEvent* event, PropagateType); - bool propagateHelper(QQuickMouseEvent*, QQuickItem*,const QPointF &, PropagateType); - - bool isPressAndHoldConnected(); - bool isDoubleClickConnected(); - bool isClickConnected(); - - bool absorb : 1; - bool hovered : 1; - bool pressed : 1; - bool longPress : 1; - bool moved : 1; - bool dragX : 1; - bool dragY : 1; - bool stealMouse : 1; - bool doubleClick : 1; - bool preventStealing : 1; - bool propagateComposedEvents : 1; - QQuickDrag *drag; - QPointF startScene; - QPointF targetStartPos; - QPointF lastPos; - QDeclarativeNullableValue lastScenePos; - Qt::MouseButton lastButton; - Qt::MouseButtons lastButtons; - Qt::KeyboardModifiers lastModifiers; - QBasicTimer pressAndHoldTimer; -}; - -QT_END_NAMESPACE - -#endif // QQUICKMOUSEAREA_P_P_H diff --git a/src/declarative/items/qquickmultipointtoucharea.cpp b/src/declarative/items/qquickmultipointtoucharea.cpp deleted file mode 100644 index f7fdf97fb7..0000000000 --- a/src/declarative/items/qquickmultipointtoucharea.cpp +++ /dev/null @@ -1,729 +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 QtDeclarative module 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 "qquickmultipointtoucharea_p.h" -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass TouchPoint QQuickTouchPoint - \inqmlmodule QtQuick 2 - \ingroup qml-event-elements - \brief The TouchPoint element describes a touch point in a MultiPointTouchArea. - - The TouchPoint element contains information about a touch point, such as the current - position, pressure, and area. -*/ - -/*! - \qmlproperty int QtQuick2::TouchPoint::pointId - - This property holds the point id of the touch point. - - Each touch point within a MultiPointTouchArea will have a unique id. -*/ -void QQuickTouchPoint::setPointId(int id) -{ - if (_id == id) - return; - _id = id; - emit pointIdChanged(); -} - -/*! - \qmlproperty real QtQuick2::TouchPoint::x - \qmlproperty real QtQuick2::TouchPoint::y - - These properties hold the current position of the touch point. -*/ - -void QQuickTouchPoint::setX(qreal x) -{ - if (_x == x) - return; - _x = x; - emit xChanged(); -} - -void QQuickTouchPoint::setY(qreal y) -{ - if (_y == y) - return; - _y = y; - emit yChanged(); -} - -/*! - \qmlproperty real QtQuick2::TouchPoint::pressure - \qmlproperty rectangle QtQuick2::TouchPoint::area - - These properties hold additional information about the current state of the touch point. - - \list - \i \c pressure is a value in the range of 0.0 to 1.0. - \i \c area is a rectangle covering the area of the touch point, centered on the current position of the touch point. - \endlist -*/ -void QQuickTouchPoint::setPressure(qreal pressure) -{ - if (_pressure == pressure) - return; - _pressure = pressure; - emit pressureChanged(); -} - -void QQuickTouchPoint::setArea(const QRectF &area) -{ - if (_area == area) - return; - _area = area; - emit areaChanged(); -} - -/*! - \qmlproperty bool QtQuick2::TouchPoint::valid - - This property holds whether the touch point is valid. - - An invalid touch point is one that has not yet been pressed, - or has already been released. -*/ -void QQuickTouchPoint::setValid(bool valid) -{ - if (_valid == valid) - return; - _valid = valid; - emit validityChanged(); -} - -/*! - \qmlproperty real QtQuick2::TouchPoint::startX - \qmlproperty real QtQuick2::TouchPoint::startY - - These properties hold the starting position of the touch point. -*/ - -void QQuickTouchPoint::setStartX(qreal startX) -{ - if (_startX == startX) - return; - _startX = startX; - emit startXChanged(); -} - -void QQuickTouchPoint::setStartY(qreal startY) -{ - if (_startY == startY) - return; - _startY = startY; - emit startYChanged(); -} - -/*! - \qmlproperty real QtQuick2::TouchPoint::previousX - \qmlproperty real QtQuick2::TouchPoint::previousY - - These properties hold the previous position of the touch point. -*/ -void QQuickTouchPoint::setPreviousX(qreal previousX) -{ - if (_previousX == previousX) - return; - _previousX = previousX; - emit previousXChanged(); -} - -void QQuickTouchPoint::setPreviousY(qreal previousY) -{ - if (_previousY == previousY) - return; - _previousY = previousY; - emit previousYChanged(); -} - -/*! - \qmlproperty real QtQuick2::TouchPoint::sceneX - \qmlproperty real QtQuick2::TouchPoint::sceneY - - These properties hold the current position of the touch point in scene coordinates. -*/ - -void QQuickTouchPoint::setSceneX(qreal sceneX) -{ - if (_sceneX == sceneX) - return; - _sceneX = sceneX; - emit sceneXChanged(); -} - -void QQuickTouchPoint::setSceneY(qreal sceneY) -{ - if (_sceneY == sceneY) - return; - _sceneY = sceneY; - emit sceneYChanged(); -} - -/*! - \qmlclass MultiPointTouchArea QQuickMultiPointTouchArea - \inqmlmodule QtQuick 2 - \brief The MultiPointTouchArea item enables handling of multiple touch points. - \inherits Item - - A MultiPointTouchArea is an invisible item that is used to track multiple touch points. - - The \l enabled property is used to enable and disable touch handling. When disabled, - the touch area becomes transparent to mouse/touch events. - - MultiPointTouchArea can be used in two ways: - - \list - \o setting \c touchPoints to provide touch point objects with properties that can be bound to - \o using the onTouchUpdated or onTouchPointsPressed, onTouchPointsUpdated and onTouchPointsReleased handlers - \endlist - - While a MultiPointTouchArea \i can take exclusive ownership of certain touch points, it is also possible to have - multiple MultiPointTouchAreas active at the same time, each operating on a different set of touch points. - - \sa TouchPoint -*/ - -/*! - \qmlsignal QtQuick2::MultiPointTouchArea::touchPointsPressed(list touchPoints) - - This handler is called when new touch points are added. \a touchPoints is a list of these new points. - - If minimumTouchPoints is set to a value greater than one, this handler will not be called until the minimum number - of required touch points has been reached. At that point, touchPointsPressed will be called with all the current touch points. -*/ - -/*! - \qmlsignal QtQuick2::MultiPointTouchArea::touchPointsUpdated(list touchPoints) - - This handler is called when existing touch points are updated. \a touchPoints is a list of these updated points. -*/ - -/*! - \qmlsignal QtQuick2::MultiPointTouchArea::touchPointsReleased(list touchPoints) - - This handler is called when existing touch points are removed. \a touchPoints is a list of these removed points. -*/ - -/*! - \qmlsignal QtQuick2::MultiPointTouchArea::touchPointsCanceled(list touchPoints) - - This handler is called when new touch events have been canceled because another element stole the touch event handling. - - This signal is for advanced use: it is useful when there is more than one MultiPointTouchArea - that is handling input, or when there is a MultiPointTouchArea inside a \l Flickable. In the latter - case, if you execute some logic on the touchPointsPressed signal and then start dragging, the - \l Flickable may steal the touch handling from the MultiPointTouchArea. In these cases, to reset - the logic when the MultiPointTouchArea has lost the touch handling to the \l Flickable, - \c onTouchPointsCanceled should be used in addition to onTouchPointsReleased. - - \a touchPoints is the list of canceled points. -*/ - -/*! - \qmlsignal QtQuick2::MultiPointTouchArea::gestureStarted(GestureEvent gesture) - - This handler is called when the global drag threshold has been reached. - - This function is typically used when a MultiPointTouchAreas has been nested in a Flickable or another MultiPointTouchArea. - Wnen the threshold has been reached, and the handler called, you can determine whether or not the touch - area should grab the current touch points. By default they will not be grabbed; to grab them call \c gesture.grab(). If the - gesture is not grabbed, the nesting Flickable, for example, would also have an opportunity to grab. - - The gesture object also includes information on the current set of \c touchPoints and the \c dragThreshold. -*/ - -/*! - \qmlsignal QtQuick2::MultiPointTouchArea::touchUpdated(list touchPoints) - - This handler is called when the touch points handled by the MultiPointTouchArea change. This includes adding new touch points, - removing previous touch points, as well as updating current touch point data. \a touchPoints is the list of all current touch - points. -*/ - -/*! - \qmlproperty list QtQuick2::MultiPointTouchArea::touchPoints - - This property holds a set of user-defined touch point objects that can be bound to. - - In the following example, we have two small rectangles that follow our touch points. - - \snippet doc/src/snippets/declarative/multipointtoucharea/multipointtoucharea.qml 0 - - By default this property holds an empty list. - - \sa TouchPoint -*/ - -QQuickMultiPointTouchArea::QQuickMultiPointTouchArea(QQuickItem *parent) - : QQuickItem(parent), - _minimumTouchPoints(0), - _maximumTouchPoints(INT_MAX), - _stealMouse(false) -{ - setAcceptedMouseButtons(Qt::LeftButton); - setFiltersChildMouseEvents(true); -} - -QQuickMultiPointTouchArea::~QQuickMultiPointTouchArea() -{ - clearTouchLists(); - foreach (QObject *obj, _touchPoints) { - QQuickTouchPoint *dtp = static_cast(obj); - if (!dtp->isQmlDefined()) - delete dtp; - } -} - -/*! - \qmlproperty int QtQuick2::MultiPointTouchArea::minimumTouchPoints - \qmlproperty int QtQuick2::MultiPointTouchArea::maximumTouchPoints - - These properties hold the range of touch points to be handled by the touch area. - - These are convenience that allow you to, for example, have nested MultiPointTouchAreas, - one handling two finger touches, and another handling three finger touches. - - By default, all touch points within the touch area are handled. -*/ - -int QQuickMultiPointTouchArea::minimumTouchPoints() const -{ - return _minimumTouchPoints; -} - -void QQuickMultiPointTouchArea::setMinimumTouchPoints(int num) -{ - if (_minimumTouchPoints == num) - return; - _minimumTouchPoints = num; - emit minimumTouchPointsChanged(); -} - -int QQuickMultiPointTouchArea::maximumTouchPoints() const -{ - return _maximumTouchPoints; -} - -void QQuickMultiPointTouchArea::setMaximumTouchPoints(int num) -{ - if (_maximumTouchPoints == num) - return; - _maximumTouchPoints = num; - emit maximumTouchPointsChanged(); -} - -void QQuickMultiPointTouchArea::touchEvent(QTouchEvent *event) -{ - switch (event->type()) { - case QEvent::TouchBegin: - case QEvent::TouchUpdate: - case QEvent::TouchEnd: { - //if e.g. a parent Flickable has the mouse grab, don't process the touch events - QQuickCanvas *c = canvas(); - QQuickItem *grabber = c ? c->mouseGrabberItem() : 0; - if (grabber && grabber != this && grabber->keepMouseGrab() && grabber->isEnabled()) { - QQuickItem *item = this; - while ((item = item->parentItem())) { - if (item == grabber) - return; - } - } - updateTouchData(event); - if (event->type() == QEvent::TouchEnd) { - //TODO: move to canvas - _stealMouse = false; - setKeepMouseGrab(false); - QQuickCanvas *c = canvas(); - if (c && c->mouseGrabberItem() == this) - ungrabMouse(); - setKeepTouchGrab(false); - ungrabTouchPoints(); - } - break; - } - default: - QQuickItem::touchEvent(event); - break; - } -} - -void QQuickMultiPointTouchArea::grabGesture() -{ - _stealMouse = true; - - grabMouse(); - setKeepMouseGrab(true); - - grabTouchPoints(_touchPoints.keys()); - setKeepTouchGrab(true); -} - -void QQuickMultiPointTouchArea::updateTouchData(QEvent *event) -{ - bool ended = false; - bool moved = false; - bool started = false; - - clearTouchLists(); - QTouchEvent *e = static_cast(event); - QList touchPoints = e->touchPoints(); - int numTouchPoints = touchPoints.count(); - //always remove released touches, and make sure we handle all releases before adds. - foreach (QTouchEvent::TouchPoint p, touchPoints) { - Qt::TouchPointState touchPointState = p.state(); - int id = p.id(); - if (touchPointState & Qt::TouchPointReleased) { - QQuickTouchPoint* dtp = static_cast(_touchPoints.value(id)); - if (!dtp) - continue; - _releasedTouchPoints.append(dtp); - _touchPoints.remove(id); - ended = true; - } - } - if (numTouchPoints >= _minimumTouchPoints && numTouchPoints <= _maximumTouchPoints) { - foreach (QTouchEvent::TouchPoint p, touchPoints) { - Qt::TouchPointState touchPointState = p.state(); - int id = p.id(); - if (touchPointState & Qt::TouchPointReleased) { - //handled above - } else if (!_touchPoints.contains(id)) { //could be pressed, moved, or stationary - addTouchPoint(&p); - started = true; - } else if (touchPointState & Qt::TouchPointMoved) { - QQuickTouchPoint* dtp = static_cast(_touchPoints[id]); - Q_ASSERT(dtp); - _movedTouchPoints.append(dtp); - updateTouchPoint(dtp,&p); - moved = true; - } else { - QQuickTouchPoint* dtp = static_cast(_touchPoints[id]); - Q_ASSERT(dtp); - updateTouchPoint(dtp,&p); - } - } - - //see if we should be grabbing the gesture - if (!_stealMouse /* !ignoring gesture*/) { - bool offerGrab = false; - const int dragThreshold = qApp->styleHints()->startDragDistance(); - foreach (const QTouchEvent::TouchPoint &p, touchPoints) { - if (p.state() == Qt::TouchPointReleased) - continue; - const QPointF ¤tPos = p.scenePos(); - const QPointF &startPos = p.startScenePos(); - if (qAbs(currentPos.x() - startPos.x()) > dragThreshold) - offerGrab = true; - else if (qAbs(currentPos.y() - startPos.y()) > dragThreshold) - offerGrab = true; - if (offerGrab) - break; - } - - if (offerGrab) { - QQuickGrabGestureEvent event; - event._touchPoints = _touchPoints.values(); - emit gestureStarted(&event); - if (event.wantsGrab()) - grabGesture(); - } - } - - if (ended) emit(touchPointsReleased(_releasedTouchPoints)); - if (moved) emit(touchPointsUpdated(_movedTouchPoints)); - if (started) emit(touchPointsPressed(_pressedTouchPoints)); - if (!_touchPoints.isEmpty()) emit touchUpdated(_touchPoints.values()); - } -} - -void QQuickMultiPointTouchArea::clearTouchLists() -{ - foreach (QObject *obj, _releasedTouchPoints) { - QQuickTouchPoint *dtp = static_cast(obj); - if (!dtp->isQmlDefined()) - delete dtp; - else - dtp->setValid(false); - } - _releasedTouchPoints.clear(); - _pressedTouchPoints.clear(); - _movedTouchPoints.clear(); -} - -void QQuickMultiPointTouchArea::addTouchPoint(const QTouchEvent::TouchPoint *p) -{ - QQuickTouchPoint *dtp = 0; - foreach (QQuickTouchPoint* tp, _touchPrototypes) { - if (!tp->isValid()) { - tp->setValid(true); - dtp = tp; - break; - } - } - - if (dtp == 0) - dtp = new QQuickTouchPoint(false); - dtp->setPointId(p->id()); - updateTouchPoint(dtp,p); - _touchPoints.insert(p->id(),dtp); - //we may have just obtained enough points to start tracking them -- in that case moved or stationary count as newly pressed - if (p->state() & Qt::TouchPointPressed || p->state() & Qt::TouchPointMoved || p->state() & Qt::TouchPointStationary) - _pressedTouchPoints.append(dtp); -} - -void QQuickMultiPointTouchArea::addTouchPrototype(QQuickTouchPoint *prototype) -{ - int id = _touchPrototypes.count(); - prototype->setPointId(id); - _touchPrototypes.insert(id, prototype); -} - -void QQuickMultiPointTouchArea::updateTouchPoint(QQuickTouchPoint *dtp, const QTouchEvent::TouchPoint *p) -{ - //TODO: if !qmlDefined, could bypass setters. - // also, should only emit signals after all values have been set - dtp->setX(p->pos().x()); - dtp->setY(p->pos().y()); - dtp->setPressure(p->pressure()); - dtp->setArea(p->rect()); - dtp->setStartX(p->startPos().x()); - dtp->setStartY(p->startPos().y()); - dtp->setPreviousX(p->lastPos().x()); - dtp->setPreviousY(p->lastPos().y()); - dtp->setSceneX(p->scenePos().x()); - dtp->setSceneY(p->scenePos().y()); -} - -void QQuickMultiPointTouchArea::mousePressEvent(QMouseEvent *event) -{ - if (!isEnabled()) { - QQuickItem::mousePressEvent(event); - return; - } - - _stealMouse = false; - setKeepMouseGrab(false); - event->setAccepted(true); -} - -void QQuickMultiPointTouchArea::mouseMoveEvent(QMouseEvent *event) -{ - if (!isEnabled()) { - QQuickItem::mouseMoveEvent(event); - return; - } - - //do nothing -} - -void QQuickMultiPointTouchArea::mouseReleaseEvent(QMouseEvent *event) -{ - _stealMouse = false; - if (!isEnabled()) { - QQuickItem::mouseReleaseEvent(event); - return; - } - QQuickCanvas *c = canvas(); - if (c && c->mouseGrabberItem() == this) - ungrabMouse(); - setKeepMouseGrab(false); -} - -void QQuickMultiPointTouchArea::ungrab() -{ - if (_touchPoints.count()) { - QQuickCanvas *c = canvas(); - if (c && c->mouseGrabberItem() == this) { - _stealMouse = false; - setKeepMouseGrab(false); - } - setKeepTouchGrab(false); - emit touchPointsCanceled(_touchPoints.values()); - clearTouchLists(); - foreach (QObject *obj, _touchPoints) { - QQuickTouchPoint *dtp = static_cast(obj); - if (!dtp->isQmlDefined()) - delete dtp; - else - dtp->setValid(false); - } - _touchPoints.clear(); - } -} - -void QQuickMultiPointTouchArea::mouseUngrabEvent() -{ - ungrab(); -} - -void QQuickMultiPointTouchArea::touchUngrabEvent() -{ - ungrab(); -} - -bool QQuickMultiPointTouchArea::sendMouseEvent(QMouseEvent *event) -{ - QRectF myRect = mapRectToScene(QRectF(0, 0, width(), height())); - - QQuickCanvas *c = canvas(); - QQuickItem *grabber = c ? c->mouseGrabberItem() : 0; - bool stealThisEvent = _stealMouse; - if ((stealThisEvent || myRect.contains(event->windowPos())) && (!grabber || !grabber->keepMouseGrab())) { - QMouseEvent mouseEvent(event->type(), mapFromScene(event->windowPos()), event->windowPos(), event->screenPos(), - event->button(), event->buttons(), event->modifiers()); - mouseEvent.setAccepted(false); - - switch (mouseEvent.type()) { - case QEvent::MouseMove: - mouseMoveEvent(&mouseEvent); - break; - case QEvent::MouseButtonPress: - mousePressEvent(&mouseEvent); - break; - case QEvent::MouseButtonRelease: - mouseReleaseEvent(&mouseEvent); - break; - default: - break; - } - grabber = c->mouseGrabberItem(); - if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) - grabMouse(); - - return stealThisEvent; - } - if (event->type() == QEvent::MouseButtonRelease) { - _stealMouse = false; - if (c && c->mouseGrabberItem() == this) - ungrabMouse(); - setKeepMouseGrab(false); - } - return false; -} - -bool QQuickMultiPointTouchArea::childMouseEventFilter(QQuickItem *i, QEvent *event) -{ - if (!isEnabled() || !isVisible()) - return QQuickItem::childMouseEventFilter(i, event); - switch (event->type()) { - case QEvent::MouseButtonPress: - case QEvent::MouseMove: - case QEvent::MouseButtonRelease: - return sendMouseEvent(static_cast(event)); - break; - case QEvent::TouchBegin: - case QEvent::TouchUpdate: - if (!shouldFilter(event)) - return false; - updateTouchData(event); - return _stealMouse; - case QEvent::TouchEnd: { - if (!shouldFilter(event)) - return false; - updateTouchData(event); - //TODO: verify this behavior - _stealMouse = false; - setKeepMouseGrab(false); - QQuickCanvas *c = canvas(); - if (c && c->mouseGrabberItem() == this) - ungrabMouse(); - setKeepTouchGrab(false); - ungrabTouchPoints(); - } - break; - default: - break; - } - return QQuickItem::childMouseEventFilter(i, event); -} - -bool QQuickMultiPointTouchArea::shouldFilter(QEvent *event) -{ - QQuickCanvas *c = canvas(); - QQuickItem *grabber = c ? c->mouseGrabberItem() : 0; - bool disabledItem = grabber && !grabber->isEnabled(); - bool stealThisEvent = _stealMouse; - bool contains = false; - if (!stealThisEvent) { - switch (event->type()) { - case QEvent::MouseButtonPress: - case QEvent::MouseMove: - case QEvent::MouseButtonRelease: { - QMouseEvent *me = static_cast(event); - QRectF myRect = mapRectToScene(QRectF(0, 0, width(), height())); - contains = myRect.contains(me->windowPos()); - } - break; - case QEvent::TouchBegin: - case QEvent::TouchUpdate: - case QEvent::TouchEnd: { - QTouchEvent *te = static_cast(event); - QRectF myRect = mapRectToScene(QRectF(0, 0, width(), height())); - foreach (const QTouchEvent::TouchPoint &point, te->touchPoints()) { - if (myRect.contains(point.scenePos())) { - contains = true; - break; - } - } - } - break; - default: - break; - } - } - if ((stealThisEvent || contains) && (!grabber || !grabber->keepMouseGrab() || disabledItem)) { - return true; - } - ungrab(); - return false; -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickmultipointtoucharea_p.h b/src/declarative/items/qquickmultipointtoucharea_p.h deleted file mode 100644 index dac70453c5..0000000000 --- a/src/declarative/items/qquickmultipointtoucharea_p.h +++ /dev/null @@ -1,267 +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 QtDeclarative module 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 QQUICKMULTIPOINTTOUCHAREA_H -#define QQUICKMULTIPOINTTOUCHAREA_H - -#include "qquickitem.h" -#include "qevent.h" - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickMultiPointTouchArea; -class Q_AUTOTEST_EXPORT QQuickTouchPoint : public QObject -{ - Q_OBJECT - Q_PROPERTY(bool valid READ isValid NOTIFY validityChanged) - Q_PROPERTY(int pointId READ pointId NOTIFY pointIdChanged) - Q_PROPERTY(qreal x READ x NOTIFY xChanged) - Q_PROPERTY(qreal y READ y NOTIFY yChanged) - Q_PROPERTY(qreal pressure READ pressure NOTIFY pressureChanged) - Q_PROPERTY(QRectF area READ area NOTIFY areaChanged) - - Q_PROPERTY(qreal startX READ startX NOTIFY startXChanged) - Q_PROPERTY(qreal startY READ startY NOTIFY startYChanged) - Q_PROPERTY(qreal previousX READ previousX NOTIFY previousXChanged) - Q_PROPERTY(qreal previousY READ previousY NOTIFY previousYChanged) - Q_PROPERTY(qreal sceneX READ sceneX NOTIFY sceneXChanged) - Q_PROPERTY(qreal sceneY READ sceneY NOTIFY sceneYChanged) - -public: - QQuickTouchPoint(bool qmlDefined = true) - : _id(0), - _x(0.0), _y(0.0), - _pressure(0.0), - _qmlDefined(qmlDefined), - _valid(!qmlDefined), - _previousX(0.0), _previousY(0.0), - _sceneX(0.0), _sceneY(0.0) - {} - - int pointId() const { return _id; } - void setPointId(int id); - - qreal x() const { return _x; } - void setX(qreal x); - - qreal y() const { return _y; } - void setY(qreal y); - - qreal pressure() const { return _pressure; } - void setPressure(qreal pressure); - - QRectF area() const { return _area; } - void setArea(const QRectF &area); - - bool isQmlDefined() { return _qmlDefined; } - - bool isValid() { return _valid; } - void setValid(bool valid); - - qreal startX() const { return _startX; } - void setStartX(qreal startX); - - qreal startY() const { return _startY; } - void setStartY(qreal startY); - - qreal previousX() const { return _previousX; } - void setPreviousX(qreal previousX); - - qreal previousY() const { return _previousY; } - void setPreviousY(qreal previousY); - - qreal sceneX() const { return _sceneX; } - void setSceneX(qreal sceneX); - - qreal sceneY() const { return _sceneY; } - void setSceneY(qreal sceneY); - - -Q_SIGNALS: - void pointIdChanged(); - void xChanged(); - void yChanged(); - void pressureChanged(); - void areaChanged(); - void validityChanged(); - void startXChanged(); - void startYChanged(); - void previousXChanged(); - void previousYChanged(); - void sceneXChanged(); - void sceneYChanged(); - -private: - friend class QQuickMultiPointTouchArea; - int _id; - qreal _x; - qreal _y; - qreal _pressure; - QRectF _area; - bool _qmlDefined; - bool _valid; - qreal _startX; - qreal _startY; - qreal _previousX; - qreal _previousY; - qreal _sceneX; - qreal _sceneY; -}; - -class QQuickGrabGestureEvent : public QObject -{ - Q_OBJECT - Q_PROPERTY(QDeclarativeListProperty touchPoints READ touchPoints) - Q_PROPERTY(qreal dragThreshold READ dragThreshold) -public: - QQuickGrabGestureEvent() : _grab(false), _dragThreshold(qApp->styleHints()->startDragDistance()) {} - - Q_INVOKABLE void grab() { _grab = true; } - bool wantsGrab() const { return _grab; } - - QDeclarativeListProperty touchPoints() { - return QDeclarativeListProperty(this, _touchPoints); - } - qreal dragThreshold() const { return _dragThreshold; } - -private: - friend class QQuickMultiPointTouchArea; - bool _grab; - qreal _dragThreshold; - QList _touchPoints; -}; - -class Q_AUTOTEST_EXPORT QQuickMultiPointTouchArea : public QQuickItem -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeListProperty touchPoints READ touchPoints) - Q_PROPERTY(int minimumTouchPoints READ minimumTouchPoints WRITE setMinimumTouchPoints NOTIFY minimumTouchPointsChanged) - Q_PROPERTY(int maximumTouchPoints READ maximumTouchPoints WRITE setMaximumTouchPoints NOTIFY maximumTouchPointsChanged) - -public: - QQuickMultiPointTouchArea(QQuickItem *parent=0); - ~QQuickMultiPointTouchArea(); - - int minimumTouchPoints() const; - void setMinimumTouchPoints(int num); - int maximumTouchPoints() const; - void setMaximumTouchPoints(int num); - - QDeclarativeListProperty touchPoints() { - return QDeclarativeListProperty(this, 0, QQuickMultiPointTouchArea::touchPoint_append, QQuickMultiPointTouchArea::touchPoint_count, QQuickMultiPointTouchArea::touchPoint_at, 0); - } - - static void touchPoint_append(QDeclarativeListProperty *list, QQuickTouchPoint* touch) { - QQuickMultiPointTouchArea *q = static_cast(list->object); - q->addTouchPrototype(touch); - } - - static int touchPoint_count(QDeclarativeListProperty *list) { - QQuickMultiPointTouchArea *q = static_cast(list->object); - return q->_touchPrototypes.count(); - } - - static QQuickTouchPoint* touchPoint_at(QDeclarativeListProperty *list, int index) { - QQuickMultiPointTouchArea *q = static_cast(list->object); - return q->_touchPrototypes[index]; - } - -Q_SIGNALS: - void touchPointsPressed(const QList &touchPoints); - void touchPointsUpdated(const QList &touchPoints); - void touchPointsReleased(const QList &touchPoints); - void touchPointsCanceled(const QList &touchPoints); - void gestureStarted(QQuickGrabGestureEvent *gesture); - void touchUpdated(const QList &touchPoints); - void minimumTouchPointsChanged(); - void maximumTouchPointsChanged(); - -protected: - void touchEvent(QTouchEvent *); - bool childMouseEventFilter(QQuickItem *i, QEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseUngrabEvent(); - void touchUngrabEvent(); - - void addTouchPrototype(QQuickTouchPoint* prototype); - void addTouchPoint(const QTouchEvent::TouchPoint *p); - void clearTouchLists(); - - void updateTouchPoint(QQuickTouchPoint*, const QTouchEvent::TouchPoint*); - void updateTouchData(QEvent*); - - bool sendMouseEvent(QMouseEvent *event); - bool shouldFilter(QEvent *event); - void grabGesture(); - -private: - void ungrab(); - QMap _touchPrototypes; //TouchPoints defined in QML - QMap _touchPoints; //All current touch points - QList _releasedTouchPoints; - QList _pressedTouchPoints; - QList _movedTouchPoints; - int _minimumTouchPoints; - int _maximumTouchPoints; - bool _stealMouse; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickTouchPoint) -QML_DECLARE_TYPE(QQuickGrabGestureEvent) -QML_DECLARE_TYPE(QQuickMultiPointTouchArea) - -QT_END_HEADER - -#endif // QQUICKMULTIPOINTTOUCHAREA_H diff --git a/src/declarative/items/qquickninepatchnode.cpp b/src/declarative/items/qquickninepatchnode.cpp deleted file mode 100644 index 2974725348..0000000000 --- a/src/declarative/items/qquickninepatchnode.cpp +++ /dev/null @@ -1,302 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qquickninepatchnode_p.h" -#include -#include - -QQuickNinePatchNode::QQuickNinePatchNode() - : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0) - , m_horizontalTileMode(QQuickBorderImage::Stretch) - , m_verticalTileMode(QQuickBorderImage::Stretch) - , m_dirtyGeometry(false) - , m_mirror(false) -{ - setOpaqueMaterial(&m_material); - setMaterial(&m_materialO); - setGeometry(&m_geometry); - m_geometry.setDrawingMode(GL_TRIANGLES); -#ifdef QML_RUNTIME_TESTING - description = QLatin1String("borderimage"); -#endif -} - -void QQuickNinePatchNode::setInnerRect(const QRectF &rect) -{ - if (m_innerRect == rect) - return; - m_innerRect = rect; - m_dirtyGeometry = true; -} - -void QQuickNinePatchNode::setRect(const QRectF &rect) -{ - if (m_targetRect == rect) - return; - m_targetRect = rect; - m_dirtyGeometry = true; -} - -void QQuickNinePatchNode::setHorzontalTileMode(QQuickBorderImage::TileMode mode) -{ - if (mode == QQuickBorderImage::TileMode(m_horizontalTileMode)) - return; - m_horizontalTileMode = mode; - m_dirtyGeometry = true; -} - - -void QQuickNinePatchNode::setVerticalTileMode(QQuickBorderImage::TileMode mode) -{ - if (mode == QQuickBorderImage::TileMode(m_verticalTileMode)) - return; - m_verticalTileMode = mode; - m_dirtyGeometry = true; -} - - -void QQuickNinePatchNode::setFiltering(QSGTexture::Filtering filtering) -{ - if (m_material.filtering() == filtering) - return; - - m_material.setFiltering(filtering); - m_materialO.setFiltering(filtering); - markDirty(DirtyMaterial); -} - -QSGTexture::Filtering QQuickNinePatchNode::filtering() const -{ - return m_material.filtering(); -} - -void QQuickNinePatchNode::setTexture(QSGTexture *texture) -{ - if (texture == m_material.texture()) - return; - m_material.setTexture(texture); - m_materialO.setTexture(texture); - markDirty(DirtyMaterial); -} - -QSGTexture *QQuickNinePatchNode::texture() const -{ - return m_material.texture(); -} - -void QQuickNinePatchNode::setMirror(bool m) -{ - if (m_mirror == m) - return; - m_mirror = m; - m_dirtyGeometry = true; -} - - -void QQuickNinePatchNode::update() -{ - if (!m_dirtyGeometry) - return; - - // For stretch this algorithm could be simplified to use less vertices - // as more vertices could be reused then, but I doubt its where our main - // problem will lie. This way, we at least share the algorithm between all - - Q_ASSERT(m_material.texture()); - - float tw = m_material.texture()->textureSize().width(); - float th = m_material.texture()->textureSize().height(); - - QRectF textureSubRect = m_material.texture()->textureSubRect(); - QSize textureSize = m_material.texture()->textureSize(); - - float rightBorder = tw - m_innerRect.right(); - float bottomBorder = th - m_innerRect.bottom(); - -// qDebug() << m_innerRect << m_targetRect << m_horizontalTileMode << m_verticalTileMode; - - int xChunkCount = 0; // Number of chunks - float xChunkSize = 0; // Size of chunk in pixels - float xTexSize = m_innerRect.width(); // Size of the texture to stretch/tile - float xSize = m_targetRect.width() - m_innerRect.left() - rightBorder; // Size of area to fill with chunks - - if (m_horizontalTileMode == QQuickBorderImage::Repeat) { - xChunkCount = qCeil(xSize / xTexSize); - xChunkSize = xTexSize; - } else if (m_horizontalTileMode == QQuickBorderImage::Round) { - xChunkCount = qCeil(xSize / xTexSize); - qreal fullWidth = xChunkCount * xTexSize; - xChunkSize = xTexSize * xSize / fullWidth; - } else { - xChunkCount = 1; - xChunkSize = xSize; - } - - int yChunkCount = 0; - float yChunkSize = 0; // Relative to target rect. - float yTexSize = m_innerRect.height(); // Size of the texture to stretch/tile - float ySize = m_targetRect.height() - m_innerRect.top() - bottomBorder; - - if (m_verticalTileMode == QQuickBorderImage::Repeat) { - yChunkCount = qCeil(ySize / yTexSize); - yChunkSize = yTexSize; - } else if (m_verticalTileMode == QQuickBorderImage::Round) { - yChunkCount = qCeil(ySize / yTexSize); - qreal fullHeight = yChunkCount * yTexSize; - yChunkSize = yTexSize * ySize / fullHeight; - } else { - yChunkCount = 1; - yChunkSize = ySize; - } - - int xTotalChunkCount = xChunkCount + 2; - int yTotalChunkCount = yChunkCount + 2; - - int totalChunkCount = xTotalChunkCount * yTotalChunkCount; - int vertexCount = totalChunkCount * 4; - int indexCount = totalChunkCount * 6; - - if (vertexCount != m_geometry.vertexCount() || indexCount != m_geometry.indexCount()) - m_geometry.allocate(vertexCount, indexCount); - - QSGGeometry::TexturedPoint2D *v = m_geometry.vertexDataAsTexturedPoint2D(); - - - // Fill in the vertices.. The loop below is pretty much an exact replica - // of the one inside fillRow. - float yTexChunk1 = m_innerRect.top() / th; - float yTexChunk2 = m_innerRect.bottom() / th; - - fillRow(v, 0, 0, xChunkCount, xChunkSize, textureSubRect, textureSize); - fillRow(v, m_innerRect.y(), yTexChunk1, xChunkCount, xChunkSize, textureSubRect, textureSize); - - for (int yc=0; ycx = m_targetRect.width() - v->x; - ++v; - } - } - -// v = m_geometry.vertexDataAsTexturedPoint2D(); -// for (int i=0; ix, v->y, v->tx, v->ty); -// ++v; -// } - - quint16 *i = m_geometry.indexDataAsUShort(); - int row = xTotalChunkCount * 2; - for (int r=0; rset(0, y, tsr.left(), ty); - v++->set(m_innerRect.x(), y, xTexChunk1, ty); - - for (int xc=0; xcset(xx, y, xTexChunk1, ty); - - // Special case the last one - if (xc == xChunkCount - 1) { - float t = m_horizontalTileMode == QQuickBorderImage::Repeat - ? xTexChunk1 + (xTexChunk2 - xTexChunk1) * (m_targetRect.width() - rightBorder - xx) / xChunkSize - : xTexChunk2; - v->set(m_targetRect.width() - rightBorder, y, t, ty); - } else { - v->set(xx + xChunkSize, y, xTexChunk2, ty); - } - ++v; - } - - v++->set(m_targetRect.width() - rightBorder, y, xTexChunk2, ty); - v++->set(m_targetRect.width(), y, tsr.right(), ty); -} diff --git a/src/declarative/items/qquickninepatchnode_p.h b/src/declarative/items/qquickninepatchnode_p.h deleted file mode 100644 index cdb0fd8e70..0000000000 --- a/src/declarative/items/qquickninepatchnode_p.h +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKNINEPATCHNODE_H -#define QQUICKNINEPATCHNODE_H - -#include "qsgnode.h" -#include "qsgtexturematerial.h" -#include "qquickborderimage_p.h" - -class TextureReference; - -class QQuickNinePatchNode : public QSGGeometryNode -{ -public: - QQuickNinePatchNode(); - - void setTexture(QSGTexture *texture); - QSGTexture *texture() const; - - void setRect(const QRectF &rect); - QRectF rect() const { return m_targetRect; } - - void setInnerRect(const QRectF &rect); - QRectF innerRect() const { return m_innerRect; } - - void setFiltering(QSGTexture::Filtering filtering); - QSGTexture::Filtering filtering() const; - - void setHorzontalTileMode(QQuickBorderImage::TileMode mode); - QQuickBorderImage::TileMode horizontalTileMode() const { - return (QQuickBorderImage::TileMode) m_horizontalTileMode; - } - - void setVerticalTileMode(QQuickBorderImage::TileMode mode); - QQuickBorderImage::TileMode verticalTileMode() const { - return (QQuickBorderImage::TileMode) m_verticalTileMode; - } - - void setMirror(bool m); - bool mirror() const { return m_mirror; } - - void update(); - -private: - void fillRow(QSGGeometry::TexturedPoint2D *&v, float y, float ty, int xChunkCount, float xChunkSize, const QRectF &tsr, const QSize &ts); - QRectF m_targetRect; - QRectF m_innerRect; - QSGOpaqueTextureMaterial m_material; - QSGTextureMaterial m_materialO; - QSGGeometry m_geometry; - - uint m_horizontalTileMode : 2; - uint m_verticalTileMode : 2; - - uint m_dirtyGeometry : 1; - uint m_mirror : 1; -}; - -#endif // QQUICKNINEPATCHNODE_H diff --git a/src/declarative/items/qquickpainteditem.cpp b/src/declarative/items/qquickpainteditem.cpp deleted file mode 100644 index 4d96da2e1a..0000000000 --- a/src/declarative/items/qquickpainteditem.cpp +++ /dev/null @@ -1,528 +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 QtDeclarative module 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 "qquickpainteditem.h" -#include - -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -/*! - \class QQuickPaintedItem - \brief The QQuickPaintedItem class provides a way to use the QPainter API in the - QML Scene Graph. - - \inmodule QtDeclarative - - The QQuickPaintedItem makes it possible to use the QPainter API with the QML Scene Graph. - It sets up a textured rectangle in the Scene Graph and uses a QPainter to paint - onto the texture. The render target can be either a QImage or a QOpenGLFramebufferObject. - When the render target is a QImage, QPainter first renders into the image then - the content is uploaded to the texture. - When a QOpenGLFramebufferObject is used, QPainter paints directly onto the texture. - Call update() to trigger a repaint. - - To enable QPainter to do anti-aliased rendering, use setAntialiasing(). - - QQuickPaintedItem is meant to make it easier to port old code that is using the - QPainter API to the QML Scene Graph API and it should be used only for that purpose. - - To write your own painted item, you first create a subclass of QQuickPaintedItem, and then - start by implementing its only pure virtual public function: paint(), which implements - the actual painting. To get the size of the area painted by the item, use - contentsBoundingRect(). -*/ - -/*! - \enum QQuickPaintedItem::RenderTarget - - This enum describes QQuickPaintedItem's render targets. The render target is the - surface QPainter paints onto before the item is rendered on screen. - - \value Image The default; QPainter paints into a QImage using the raster paint engine. - The image's content needs to be uploaded to graphics memory afterward, this operation - can potentially be slow if the item is large. This render target allows high quality - anti-aliasing and fast item resizing. - - \value FramebufferObject QPainter paints into a QOpenGLFramebufferObject using the GL - paint engine. Painting can be faster as no texture upload is required, but anti-aliasing - quality is not as good as if using an image. This render target allows faster rendering - in some cases, but you should avoid using it if the item is resized often. - - \value InvertedYFramebufferObject Exactly as for FramebufferObject above, except once - the painting is done, prior to rendering the painted image is flipped about the - x-axis so that the top-most pixels are now at the bottom. Since this is done with the - OpenGL texture coordinates it is a much faster way to achieve this effect than using a - painter transform. - - \sa setRenderTarget() -*/ - -/*! - \enum QQuickPaintedItem::PerformanceHint - - This enum describes flags that you can enable to improve rendering - performance in QQuickPaintedItem. By default, none of these flags are set. - - \value FastFBOResizing If your item gets resized often and you are using the - QQuickPaintedItem::FramebufferObject render target, set this flag to true to reduce the - item resizing time at the cost of using more graphics memory. Resizing a Framebuffer object - is a costly operation, by enabling this property the Framebuffer Object will use a texture - larger than the actual size of the item to avoid as much as possible resizing it. -*/ - -/*! - \internal -*/ -QQuickPaintedItemPrivate::QQuickPaintedItemPrivate() - : QQuickItemPrivate() - , contentsScale(1.0) - , fillColor(Qt::transparent) - , renderTarget(QQuickPaintedItem::Image) - , performanceHints(0) - , opaquePainting(false) - , antialiasing(false) - , mipmap(false) -{ -} - -/*! - Constructs a QQuickPaintedItem with the given \a parent item. - */ -QQuickPaintedItem::QQuickPaintedItem(QQuickItem *parent) - : QQuickItem(*(new QQuickPaintedItemPrivate), parent) -{ - setFlag(ItemHasContents); -} - -/*! - \internal -*/ -QQuickPaintedItem::QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *parent) - : QQuickItem(dd, parent) -{ - setFlag(ItemHasContents); -} - -/*! - Destroys the QQuickPaintedItem. -*/ -QQuickPaintedItem::~QQuickPaintedItem() -{ -} - -/*! - Schedules a redraw of the area covered by \a rect in this item. You can call this function - whenever your item needs to be redrawn, such as if it changes appearance or size. - - This function does not cause an immediate paint; instead it schedules a paint request that - is processed by the QML Scene Graph when the next frame is rendered. The item will only be - redrawn if it is visible. - - Note that calling this function will trigger a repaint of the whole scene. - - \sa paint() -*/ -void QQuickPaintedItem::update(const QRect &rect) -{ - Q_D(QQuickPaintedItem); - - if (rect.isNull() && !d->dirtyRect.isNull()) - d->dirtyRect = contentsBoundingRect().toAlignedRect(); - else - d->dirtyRect |= (contentsBoundingRect() & rect).toAlignedRect(); - QQuickItem::update(); -} - -/*! - Returns true if this item is opaque; otherwise, false is returned. - - By default, painted items are not opaque. - - \sa setOpaquePainting() -*/ -bool QQuickPaintedItem::opaquePainting() const -{ - Q_D(const QQuickPaintedItem); - return d->opaquePainting; -} - -/*! - If \a opaque is true, the item is opaque; otherwise, it is considered as translucent. - - Opaque items are not blended with the rest of the scene, you should set this to true - if the content of the item is opaque to speed up rendering. - - By default, painted items are not opaque. - - \sa opaquePainting() -*/ -void QQuickPaintedItem::setOpaquePainting(bool opaque) -{ - Q_D(QQuickPaintedItem); - - if (d->opaquePainting == opaque) - return; - - d->opaquePainting = opaque; - QQuickItem::update(); -} - -/*! - Returns true if antialiased painting is enabled; otherwise, false is returned. - - By default, antialiasing is not enabled. - - \sa setAntialiasing() -*/ -bool QQuickPaintedItem::antialiasing() const -{ - Q_D(const QQuickPaintedItem); - return d->antialiasing; -} - -/*! - If \a enable is true, antialiased painting is enabled. - - By default, antialiasing is not enabled. - - \sa antialiasing() -*/ -void QQuickPaintedItem::setAntialiasing(bool enable) -{ - Q_D(QQuickPaintedItem); - - if (d->antialiasing == enable) - return; - - d->antialiasing = enable; - update(); -} - -/*! - Returns true if mipmaps are enabled; otherwise, false is returned. - - By default, mipmapping is not enabled. - - \sa setMipmap() -*/ -bool QQuickPaintedItem::mipmap() const -{ - Q_D(const QQuickPaintedItem); - return d->mipmap; -} - -/*! - If \a enable is true, mipmapping is enabled on the associated texture. - - Mipmapping increases rendering speed and reduces aliasing artifacts when the item is - scaled down. - - By default, mipmapping is not enabled. - - \sa mipmap() -*/ -void QQuickPaintedItem::setMipmap(bool enable) -{ - Q_D(QQuickPaintedItem); - - if (d->mipmap == enable) - return; - - d->mipmap = enable; - update(); -} - -/*! - Returns the performance hints. - - By default, no performance hint is enabled/ - - \sa setPerformanceHint(), setPerformanceHints() -*/ -QQuickPaintedItem::PerformanceHints QQuickPaintedItem::performanceHints() const -{ - Q_D(const QQuickPaintedItem); - return d->performanceHints; -} - -/*! - Sets the given performance \a hint on the item if \a enabled is true; - otherwise clears the performance hint. - - By default, no performance hint is enabled/ - - \sa setPerformanceHints(), performanceHints() -*/ -void QQuickPaintedItem::setPerformanceHint(QQuickPaintedItem::PerformanceHint hint, bool enabled) -{ - Q_D(QQuickPaintedItem); - PerformanceHints oldHints = d->performanceHints; - if (enabled) - d->performanceHints |= hint; - else - d->performanceHints &= ~hint; - if (oldHints != d->performanceHints) - update(); -} - -/*! - Sets the performance hints to \a hints - - By default, no performance hint is enabled/ - - \sa setPerformanceHint(), performanceHints() -*/ -void QQuickPaintedItem::setPerformanceHints(QQuickPaintedItem::PerformanceHints hints) -{ - Q_D(QQuickPaintedItem); - if (d->performanceHints == hints) - return; - d->performanceHints = hints; - update(); -} - -/*! - This function returns the outer bounds of the item as a rectangle; all painting must be - restricted to inside an item's bounding rect. - - If the contents size has not been set it reflects the size of the item; otherwise - it reflects the contents size scaled by the contents scale. - - Use this function to know the area painted by the item. - - \sa QQuickItem::width(), QQuickItem::height(), contentsSize(), contentsScale() -*/ -QRectF QQuickPaintedItem::contentsBoundingRect() const -{ - Q_D(const QQuickPaintedItem); - - qreal w = d->width; - QSizeF sz = d->contentsSize * d->contentsScale; - if (w < sz.width()) - w = sz.width(); - qreal h = d->height; - if (h < sz.height()) - h = sz.height(); - - return QRectF(0, 0, w, h); -} - -/*! - \property QQuickPaintedItem::contentsSize - \brief The size of the contents - - The contents size is the size of the item in regards to how it is painted - using the paint() function. This is distinct from the size of the - item in regards to height() and width(). -*/ -QSize QQuickPaintedItem::contentsSize() const -{ - Q_D(const QQuickPaintedItem); - return d->contentsSize; -} - -void QQuickPaintedItem::setContentsSize(const QSize &size) -{ - Q_D(QQuickPaintedItem); - - if (d->contentsSize == size) - return; - - d->contentsSize = size; - update(); -} - -/*! - This convenience function is equivalent to calling setContentsSize(QSize()). -*/ -void QQuickPaintedItem::resetContentsSize() -{ - setContentsSize(QSize()); -} - -/*! - \property QQuickPaintedItem::contentsScale - \brief The scale of the contents - - All painting happening in paint() is scaled by the contents scale. This is distinct - from the scale of the item in regards to scale(). - - The default value is 1. -*/ -qreal QQuickPaintedItem::contentsScale() const -{ - Q_D(const QQuickPaintedItem); - return d->contentsScale; -} - -void QQuickPaintedItem::setContentsScale(qreal scale) -{ - Q_D(QQuickPaintedItem); - - if (d->contentsScale == scale) - return; - - d->contentsScale = scale; - update(); -} - -/*! - \property QQuickPaintedItem::fillColor - \brief The item's background fill color. - - By default, the fill color is set to Qt::transparent. -*/ -QColor QQuickPaintedItem::fillColor() const -{ - Q_D(const QQuickPaintedItem); - return d->fillColor; -} - -void QQuickPaintedItem::setFillColor(const QColor &c) -{ - Q_D(QQuickPaintedItem); - - if (d->fillColor == c) - return; - - d->fillColor = c; - update(); - - emit fillColorChanged(); -} - -/*! - \property QQuickPaintedItem::renderTarget - \brief The item's render target. - - This property defines which render target the QPainter renders into, it can be either - QSGPaintedItem::Image, QSGPaintedItem::FramebufferObject or QSGPaintedItem::InvertedYFramebufferObject. - - Each has certain benefits, typically performance versus quality. Using a framebuffer - object avoids a costly upload of the image contents to the texture in graphics memory, - while using an image enables high quality anti-aliasing. - - \warning Resizing a framebuffer object is a costly operation, avoid using - the QQuickPaintedItem::FramebufferObject render target if the item gets resized often. - - By default, the render target is QQuickPaintedItem::Image. -*/ -QQuickPaintedItem::RenderTarget QQuickPaintedItem::renderTarget() const -{ - Q_D(const QQuickPaintedItem); - return d->renderTarget; -} - -void QQuickPaintedItem::setRenderTarget(RenderTarget target) -{ - Q_D(QQuickPaintedItem); - - if (d->renderTarget == target) - return; - - d->renderTarget = target; - update(); - - emit renderTargetChanged(); -} - -/*! - \fn virtual void QQuickPaintedItem::paint(QPainter *painter) = 0 - - This function, which is usually called by the QML Scene Graph, paints the - contents of an item in local coordinates. - - The function is called after the item has been filled with the fillColor. - - Reimplement this function in a QQuickPaintedItem subclass to provide the - item's painting implementation, using \a painter. - - \note The QML Scene Graph uses two separate threads, the main thread does things such as - processing events or updating animations while a second thread does the actual OpenGL rendering. - As a consequence, paint() is not called from the main GUI thread but from the GL enabled - renderer thread. At the moment paint() is called, the GUI thread is blocked and this is - therefore thread-safe. -*/ - -/*! - This function is called when the Scene Graph node associated to the item needs to - be updated. -*/ -QSGNode *QQuickPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) -{ - Q_UNUSED(data); - Q_D(QQuickPaintedItem); - - if (width() <= 0 || height() <= 0) { - delete oldNode; - return 0; - } - - QSGPainterNode *node = static_cast(oldNode); - if (!node) - node = new QSGPainterNode(this); - - QRectF br = contentsBoundingRect(); - - node->setPreferredRenderTarget(d->renderTarget); - node->setFastFBOResizing(d->performanceHints & FastFBOResizing); - node->setSize(QSize(qRound(br.width()), qRound(br.height()))); - node->setSmoothPainting(d->antialiasing); - node->setLinearFiltering(d->smooth); - node->setMipmapping(d->mipmap); - node->setOpaquePainting(d->opaquePainting); - node->setFillColor(d->fillColor); - node->setContentsScale(d->contentsScale); - node->setDirty(d->dirtyRect); - node->update(); - - d->dirtyRect = QRect(); - - return node; -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickpainteditem.h b/src/declarative/items/qquickpainteditem.h deleted file mode 100644 index b2da9e6c7a..0000000000 --- a/src/declarative/items/qquickpainteditem.h +++ /dev/null @@ -1,130 +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 QtDeclarative module 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 QQUICKPAINTEDITEM_P_H -#define QQUICKPAINTEDITEM_P_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QQuickPaintedItemPrivate; -class Q_DECLARATIVE_EXPORT QQuickPaintedItem : public QQuickItem -{ - Q_OBJECT - Q_ENUMS(RenderTarget) - - Q_PROPERTY(QSize contentsSize READ contentsSize WRITE setContentsSize NOTIFY contentsSizeChanged) - Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged) - Q_PROPERTY(qreal contentsScale READ contentsScale WRITE setContentsScale NOTIFY contentsScaleChanged) - Q_PROPERTY(RenderTarget renderTarget READ renderTarget WRITE setRenderTarget NOTIFY renderTargetChanged) -public: - QQuickPaintedItem(QQuickItem *parent = 0); - virtual ~QQuickPaintedItem(); - - enum RenderTarget { - Image, - FramebufferObject, - InvertedYFramebufferObject - }; - - enum PerformanceHint { - FastFBOResizing = 0x1 - }; - Q_DECLARE_FLAGS(PerformanceHints, PerformanceHint) - - void update(const QRect &rect = QRect()); - - bool opaquePainting() const; - void setOpaquePainting(bool opaque); - - bool antialiasing() const; - void setAntialiasing(bool enable); - - bool mipmap() const; - void setMipmap(bool enable); - - PerformanceHints performanceHints() const; - void setPerformanceHint(PerformanceHint hint, bool enabled = true); - void setPerformanceHints(PerformanceHints hints); - - QRectF contentsBoundingRect() const; - - QSize contentsSize() const; - void setContentsSize(const QSize &); - void resetContentsSize(); - - qreal contentsScale() const; - void setContentsScale(qreal); - - QColor fillColor() const; - void setFillColor(const QColor&); - - RenderTarget renderTarget() const; - void setRenderTarget(RenderTarget target); - - virtual void paint(QPainter *painter) = 0; - -Q_SIGNALS: - void fillColorChanged(); - void contentsSizeChanged(); - void contentsScaleChanged(); - void renderTargetChanged(); - -protected: - QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *parent = 0); - virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - -private: - Q_DISABLE_COPY(QQuickPaintedItem) - Q_DECLARE_PRIVATE(QQuickPaintedItem) -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPaintedItem::PerformanceHints) - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QQUICKPAINTEDITEM_P_H diff --git a/src/declarative/items/qquickpainteditem_p.h b/src/declarative/items/qquickpainteditem_p.h deleted file mode 100644 index b847b0a4ef..0000000000 --- a/src/declarative/items/qquickpainteditem_p.h +++ /dev/null @@ -1,71 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKPAINTEDITEM_P_P_H -#define QQUICKPAINTEDITEM_P_P_H - -#include "qquickitem_p.h" -#include - -QT_BEGIN_NAMESPACE - -class QQuickPaintedItemPrivate : public QQuickItemPrivate -{ -public: - QQuickPaintedItemPrivate(); - - QSize contentsSize; - qreal contentsScale; - QColor fillColor; - QQuickPaintedItem::RenderTarget renderTarget; - QQuickPaintedItem::PerformanceHints performanceHints; - - QRect dirtyRect; - - bool opaquePainting: 1; - bool antialiasing: 1; - bool mipmap: 1; -}; - -QT_END_NAMESPACE - -#endif // QQUICKPAINTEDITEM_P_P_H diff --git a/src/declarative/items/qquickpathview.cpp b/src/declarative/items/qquickpathview.cpp deleted file mode 100644 index f262562edf..0000000000 --- a/src/declarative/items/qquickpathview.cpp +++ /dev/null @@ -1,1781 +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 QtDeclarative module 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 "qquickpathview_p.h" -#include "qquickpathview_p_p.h" -#include "qquickcanvas.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -inline qreal qmlMod(qreal x, qreal y) -{ -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return fmodf(float(x), float(y)); - else -#endif - return fmod(x, y); -} - -static QDeclarativeOpenMetaObjectType *qPathViewAttachedType = 0; - -QQuickPathViewAttached::QQuickPathViewAttached(QObject *parent) -: QObject(parent), m_percent(-1), m_view(0), m_onPath(false), m_isCurrent(false) -{ - if (qPathViewAttachedType) { - m_metaobject = new QDeclarativeOpenMetaObject(this, qPathViewAttachedType); - m_metaobject->setCached(true); - } else { - m_metaobject = new QDeclarativeOpenMetaObject(this); - } -} - -QQuickPathViewAttached::~QQuickPathViewAttached() -{ -} - -QVariant QQuickPathViewAttached::value(const QByteArray &name) const -{ - return m_metaobject->value(name); -} -void QQuickPathViewAttached::setValue(const QByteArray &name, const QVariant &val) -{ - m_metaobject->setValue(name, val); -} - - -void QQuickPathViewPrivate::init() -{ - Q_Q(QQuickPathView); - offset = 0; - q->setAcceptedMouseButtons(Qt::LeftButton); - q->setFlag(QQuickItem::ItemIsFocusScope); - q->setFiltersChildMouseEvents(true); - FAST_CONNECT(&tl, SIGNAL(updated()), q, SLOT(ticked())) - lastPosTime.invalidate(); - FAST_CONNECT(&tl, SIGNAL(completed()), q, SLOT(movementEnding())) -} - -QQuickItem *QQuickPathViewPrivate::getItem(int modelIndex, qreal z, bool onPath) -{ - Q_Q(QQuickPathView); - requestedIndex = modelIndex; - requestedOnPath = onPath; - requestedZ = z; - inRequest = true; - QQuickItem *item = model->item(modelIndex, false); - if (item) { - QDeclarative_setParent_noEvent(item, q); - item->setParentItem(q); - requestedIndex = -1; - qPathViewAttachedType = attType; - QQuickPathViewAttached *att = static_cast(qmlAttachedPropertiesObject(item)); - qPathViewAttachedType = 0; - if (att) - att->setOnPath(onPath); - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - itemPrivate->addItemChangeListener(this, QQuickItemPrivate::Geometry); - } - inRequest = false; - return item; -} - -void QQuickPathView::createdItem(int index, QQuickItem *item) -{ - Q_D(QQuickPathView); - if (d->requestedIndex != index) { - qPathViewAttachedType = d->attachedType(); - QQuickPathViewAttached *att = static_cast(qmlAttachedPropertiesObject(item)); - qPathViewAttachedType = 0; - if (att) { - att->m_view = this; - att->setOnPath(false); - } - item->setParentItem(this); - QDeclarative_setParent_noEvent(item, this); - d->updateItem(item, index < d->firstIndex ? 0.0 : 1.0); - } else { - d->requestedIndex = -1; - if (!d->inRequest) - refill(); - } -} - -void QQuickPathView::initItem(int index, QQuickItem *item) -{ - Q_D(QQuickPathView); - if (d->requestedIndex == index) { - item->setParentItem(this); - qPathViewAttachedType = d->attachedType(); - QQuickPathViewAttached *att = static_cast(qmlAttachedPropertiesObject(item)); - qPathViewAttachedType = 0; - if (att) { - att->m_view = this; - qreal percent = d->positionOfIndex(index); - foreach (const QString &attr, d->path->attributes()) - att->setValue(attr.toUtf8(), d->path->attributeAt(attr, percent)); - item->setZ(d->requestedZ); - if (att) - att->setOnPath(d->requestedOnPath); - } - } -} - -void QQuickPathViewPrivate::releaseItem(QQuickItem *item) -{ - if (!item || !model) - return; - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - itemPrivate->removeItemChangeListener(this, QQuickItemPrivate::Geometry); - if (model->release(item) == 0) { - // item was not destroyed, and we no longer reference it. - if (QQuickPathViewAttached *att = attached(item)) - att->setOnPath(false); - } -} - -QQuickPathViewAttached *QQuickPathViewPrivate::attached(QQuickItem *item) -{ - return static_cast(qmlAttachedPropertiesObject(item, false)); -} - -QDeclarativeOpenMetaObjectType *QQuickPathViewPrivate::attachedType() -{ - Q_Q(QQuickPathView); - if (!attType) { - // pre-create one metatype to share with all attached objects - attType = new QDeclarativeOpenMetaObjectType(&QQuickPathViewAttached::staticMetaObject, qmlEngine(q)); - foreach (const QString &attr, path->attributes()) - attType->createProperty(attr.toUtf8()); - } - - return attType; -} - -void QQuickPathViewPrivate::clear() -{ - if (currentItem) { - releaseItem(currentItem); - currentItem = 0; - } - for (int i=0; i= 0 && index < modelCount) { - qreal start = 0.0; - if (haveHighlightRange && highlightRangeMode != QQuickPathView::NoHighlightRange) - start = highlightRangeStart; - qreal globalPos = index + offset; - globalPos = qmlMod(globalPos, qreal(modelCount)) / modelCount; - if (pathItems != -1 && pathItems < modelCount) { - globalPos += start * mappedRange; - globalPos = qmlMod(globalPos, 1.0); - if (globalPos < mappedRange) - pos = globalPos / mappedRange; - } else { - pos = qmlMod(globalPos + start, 1.0); - } - } - - return pos; -} - -void QQuickPathViewPrivate::createHighlight() -{ - Q_Q(QQuickPathView); - if (!q->isComponentComplete()) - return; - - bool changed = false; - if (highlightItem) { - highlightItem->setParentItem(0); - highlightItem->deleteLater(); - highlightItem = 0; - changed = true; - } - - QQuickItem *item = 0; - if (highlightComponent) { - QDeclarativeContext *creationContext = highlightComponent->creationContext(); - QDeclarativeContext *highlightContext = new QDeclarativeContext( - creationContext ? creationContext : qmlContext(q)); - QObject *nobj = highlightComponent->create(highlightContext); - if (nobj) { - QDeclarative_setParent_noEvent(highlightContext, nobj); - item = qobject_cast(nobj); - if (!item) - delete nobj; - } else { - delete highlightContext; - } - } else { - item = new QQuickItem; - } - if (item) { - QDeclarative_setParent_noEvent(item, q); - item->setParentItem(q); - highlightItem = item; - changed = true; - } - if (changed) - emit q->highlightItemChanged(); -} - -void QQuickPathViewPrivate::updateHighlight() -{ - Q_Q(QQuickPathView); - if (!q->isComponentComplete() || !isValid()) - return; - if (highlightItem) { - if (haveHighlightRange && highlightRangeMode == QQuickPathView::StrictlyEnforceRange) { - updateItem(highlightItem, highlightRangeStart); - } else { - qreal target = currentIndex; - - offsetAdj = 0.0; - tl.reset(moveHighlight); - moveHighlight.setValue(highlightPosition); - - const int duration = highlightMoveDuration; - - if (target - highlightPosition > modelCount/2) { - highlightUp = false; - qreal distance = modelCount - target + highlightPosition; - tl.move(moveHighlight, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * highlightPosition / distance)); - tl.set(moveHighlight, modelCount-0.01); - tl.move(moveHighlight, target, QEasingCurve(QEasingCurve::OutQuad), int(duration * (modelCount-target) / distance)); - } else if (target - highlightPosition <= -modelCount/2) { - highlightUp = true; - qreal distance = modelCount - highlightPosition + target; - tl.move(moveHighlight, modelCount-0.01, QEasingCurve(QEasingCurve::InQuad), int(duration * (modelCount-highlightPosition) / distance)); - tl.set(moveHighlight, 0.0); - tl.move(moveHighlight, target, QEasingCurve(QEasingCurve::OutQuad), int(duration * target / distance)); - } else { - highlightUp = highlightPosition - target < 0; - tl.move(moveHighlight, target, QEasingCurve(QEasingCurve::InOutQuad), duration); - } - } - } -} - -void QQuickPathViewPrivate::setHighlightPosition(qreal pos) -{ - if (pos != highlightPosition) { - qreal start = 0.0; - qreal end = 1.0; - if (haveHighlightRange && highlightRangeMode != QQuickPathView::NoHighlightRange) { - start = highlightRangeStart; - end = highlightRangeEnd; - } - - qreal range = qreal(modelCount); - // calc normalized position of highlight relative to offset - qreal relativeHighlight = qmlMod(pos + offset, range) / range; - - if (!highlightUp && relativeHighlight > end * mappedRange) { - qreal diff = 1.0 - relativeHighlight; - setOffset(offset + diff * range); - } else if (highlightUp && relativeHighlight >= (end - start) * mappedRange) { - qreal diff = relativeHighlight - (end - start) * mappedRange; - setOffset(offset - diff * range - 0.00001); - } - - highlightPosition = pos; - qreal pathPos = positionOfIndex(pos); - updateItem(highlightItem, pathPos); - if (QQuickPathViewAttached *att = attached(highlightItem)) - att->setOnPath(pathPos != -1.0); - } -} - -void QQuickPathView::pathUpdated() -{ - Q_D(QQuickPathView); - QList::iterator it = d->items.begin(); - while (it != d->items.end()) { - QQuickItem *item = *it; - if (QQuickPathViewAttached *att = d->attached(item)) - att->m_percent = -1; - ++it; - } - refill(); -} - -void QQuickPathViewPrivate::updateItem(QQuickItem *item, qreal percent) -{ - if (QQuickPathViewAttached *att = attached(item)) { - if (qFuzzyCompare(att->m_percent, percent)) - return; - att->m_percent = percent; - foreach (const QString &attr, path->attributes()) - att->setValue(attr.toUtf8(), path->attributeAt(attr, percent)); - } - QPointF pf = path->pointAt(percent); - item->setX(qRound(pf.x() - item->width()/2)); - item->setY(qRound(pf.y() - item->height()/2)); -} - -void QQuickPathViewPrivate::regenerate() -{ - Q_Q(QQuickPathView); - if (!q->isComponentComplete()) - return; - - clear(); - - if (!isValid()) - return; - - firstIndex = -1; - updateMappedRange(); - q->refill(); -} - -/*! - \qmlclass PathView QQuickPathView - \inqmlmodule QtQuick 2 - \ingroup qml-view-elements - \brief The PathView element lays out model-provided items on a path. - \inherits Item - - A PathView displays data from models created from built-in QML elements like ListModel - and XmlListModel, or custom model classes defined in C++ that inherit from - QAbstractListModel. - - The view has a \l model, which defines the data to be displayed, and - a \l delegate, which defines how the data should be displayed. - The \l delegate is instantiated for each item on the \l path. - The items may be flicked to move them along the path. - - For example, if there is a simple list model defined in a file \c ContactModel.qml like this: - - \snippet doc/src/snippets/declarative/pathview/ContactModel.qml 0 - - This data can be represented as a PathView, like this: - - \snippet doc/src/snippets/declarative/pathview/pathview.qml 0 - - \image pathview.gif - - (Note the above example uses PathAttribute to scale and modify the - opacity of the items as they rotate. This additional code can be seen in the - PathAttribute documentation.) - - PathView does not automatically handle keyboard navigation. This is because - the keys to use for navigation will depend upon the shape of the path. Navigation - can be added quite simply by setting \c focus to \c true and calling - \l decrementCurrentIndex() or \l incrementCurrentIndex(), for example to navigate - using the left and right arrow keys: - - \qml - PathView { - // ... - focus: true - Keys.onLeftPressed: decrementCurrentIndex() - Keys.onRightPressed: incrementCurrentIndex() - } - \endqml - - The path view itself is a focus scope (see \l{qmlfocus#Acquiring Focus and Focus Scopes}{the focus documentation page} for more details). - - Delegates are instantiated as needed and may be destroyed at any time. - State should \e never be stored in a delegate. - - PathView attaches a number of properties to the root item of the delegate, for example - \c {PathView.isCurrentItem}. In the following example, the root delegate item can access - this attached property directly as \c PathView.isCurrentItem, while the child - \c nameText object must refer to this property as \c wrapper.PathView.isCurrentItem. - - \snippet doc/src/snippets/declarative/pathview/pathview.qml 1 - - \bold Note that views do not enable \e clip automatically. If the view - is not clipped by another item or the screen, it will be necessary - to set \e {clip: true} in order to have the out of view items clipped - nicely. - - \sa Path, {declarative/modelviews/pathview}{PathView example} -*/ - -QQuickPathView::QQuickPathView(QQuickItem *parent) - : QQuickItem(*(new QQuickPathViewPrivate), parent) -{ - Q_D(QQuickPathView); - d->init(); -} - -QQuickPathView::~QQuickPathView() -{ - Q_D(QQuickPathView); - d->clear(); - if (d->attType) - d->attType->release(); - if (d->ownModel) - delete d->model; -} - -/*! - \qmlattachedproperty PathView QtQuick2::PathView::view - This attached property holds the view that manages this delegate instance. - - It is attached to each instance of the delegate. -*/ - -/*! - \qmlattachedproperty bool QtQuick2::PathView::onPath - This attached property holds whether the item is currently on the path. - - If a pathItemCount has been set, it is possible that some items may - be instantiated, but not considered to be currently on the path. - Usually, these items would be set invisible, for example: - - \qml - Component { - Rectangle { - visible: PathView.onPath - // ... - } - } - \endqml - - It is attached to each instance of the delegate. -*/ - -/*! - \qmlattachedproperty bool QtQuick2::PathView::isCurrentItem - This attached property is true if this delegate is the current item; otherwise false. - - It is attached to each instance of the delegate. - - This property may be used to adjust the appearance of the current item. - - \snippet doc/src/snippets/declarative/pathview/pathview.qml 1 -*/ - -/*! - \qmlproperty model QtQuick2::PathView::model - This property holds the model providing data for the view. - - The model provides a set of data that is used to create the items for the view. - For large or dynamic datasets the model is usually provided by a C++ model object. - Models can also be created directly in QML, using the ListModel element. - - \sa {qmlmodels}{Data Models} -*/ -QVariant QQuickPathView::model() const -{ - Q_D(const QQuickPathView); - return d->modelVariant; -} - -void QQuickPathView::setModel(const QVariant &model) -{ - Q_D(QQuickPathView); - if (d->modelVariant == model) - return; - - if (d->model) { - disconnect(d->model, SIGNAL(modelUpdated(QDeclarativeChangeSet,bool)), - this, SLOT(modelUpdated(QDeclarativeChangeSet,bool))); - disconnect(d->model, SIGNAL(createdItem(int,QQuickItem*)), this, SLOT(createdItem(int,QQuickItem*))); - disconnect(d->model, SIGNAL(initItem(int,QQuickItem*)), this, SLOT(initItem(int,QQuickItem*))); - for (int i=0; iitems.count(); i++){ - QQuickItem *p = d->items[i]; - d->releaseItem(p); - } - d->items.clear(); - } - - d->modelVariant = model; - QObject *object = qvariant_cast(model); - QQuickVisualModel *vim = 0; - if (object && (vim = qobject_cast(object))) { - if (d->ownModel) { - delete d->model; - d->ownModel = false; - } - d->model = vim; - } else { - if (!d->ownModel) { - d->model = new QQuickVisualDataModel(qmlContext(this)); - d->ownModel = true; - if (isComponentComplete()) - static_cast(d->model.data())->componentComplete(); - } - if (QQuickVisualDataModel *dataModel = qobject_cast(d->model)) - dataModel->setModel(model); - } - d->modelCount = 0; - if (d->model) { - connect(d->model, SIGNAL(modelUpdated(QDeclarativeChangeSet,bool)), - this, SLOT(modelUpdated(QDeclarativeChangeSet,bool))); - connect(d->model, SIGNAL(createdItem(int,QQuickItem*)), this, SLOT(createdItem(int,QQuickItem*))); - connect(d->model, SIGNAL(initItem(int,QQuickItem*)), this, SLOT(initItem(int,QQuickItem*))); - d->modelCount = d->model->count(); - if (d->model->count()) - d->offset = qmlMod(d->offset, qreal(d->model->count())); - if (d->offset < 0) - d->offset = d->model->count() + d->offset; -} - d->regenerate(); - if (d->currentIndex < d->modelCount) - setOffset(qmlMod(d->modelCount - d->currentIndex, d->modelCount)); - else - d->fixOffset(); - emit countChanged(); - emit modelChanged(); -} - -/*! - \qmlproperty int QtQuick2::PathView::count - This property holds the number of items in the model. -*/ -int QQuickPathView::count() const -{ - Q_D(const QQuickPathView); - return d->model ? d->modelCount : 0; -} - -/*! - \qmlproperty Path QtQuick2::PathView::path - This property holds the path used to lay out the items. - For more information see the \l Path documentation. -*/ -QDeclarativePath *QQuickPathView::path() const -{ - Q_D(const QQuickPathView); - return d->path; -} - -void QQuickPathView::setPath(QDeclarativePath *path) -{ - Q_D(QQuickPathView); - if (d->path == path) - return; - if (d->path) - disconnect(d->path, SIGNAL(changed()), this, SLOT(pathUpdated())); - d->path = path; - connect(d->path, SIGNAL(changed()), this, SLOT(pathUpdated())); - if (d->isValid() && isComponentComplete()) { - d->clear(); - if (d->attType) { - d->attType->release(); - d->attType = 0; - } - d->regenerate(); - } - emit pathChanged(); -} - -/*! - \qmlproperty int QtQuick2::PathView::currentIndex - This property holds the index of the current item. -*/ -int QQuickPathView::currentIndex() const -{ - Q_D(const QQuickPathView); - return d->currentIndex; -} - -void QQuickPathView::setCurrentIndex(int idx) -{ - Q_D(QQuickPathView); - if (d->model && d->modelCount) - idx = qAbs(idx % d->modelCount); - if (d->model && (idx != d->currentIndex || !d->currentItem)) { - if (d->currentItem) { - if (QQuickPathViewAttached *att = d->attached(d->currentItem)) - att->setIsCurrentItem(false); - d->releaseItem(d->currentItem); - } - int oldCurrentIdx = d->currentIndex; - QQuickItem *oldCurrentItem = d->currentItem; - d->currentItem = 0; - d->moveReason = QQuickPathViewPrivate::SetIndex; - d->currentIndex = idx; - if (d->modelCount) { - d->createCurrentItem(); - if (d->haveHighlightRange && d->highlightRangeMode == QQuickPathView::StrictlyEnforceRange) - d->snapToCurrent(); - d->currentItemOffset = d->positionOfIndex(d->currentIndex); - d->updateHighlight(); - } - if (oldCurrentIdx != d->currentIndex) - emit currentIndexChanged(); - if (oldCurrentItem != d->currentItem) - emit currentItemChanged(); - } -} - -QQuickItem *QQuickPathView::currentItem() const -{ - Q_D(const QQuickPathView); - return d->currentItem; -} - -/*! - \qmlmethod QtQuick2::PathView::incrementCurrentIndex() - - Increments the current index. - - \bold Note: methods should only be called after the Component has completed. -*/ -void QQuickPathView::incrementCurrentIndex() -{ - Q_D(QQuickPathView); - d->moveDirection = QQuickPathViewPrivate::Positive; - setCurrentIndex(currentIndex()+1); -} - -/*! - \qmlmethod QtQuick2::PathView::decrementCurrentIndex() - - Decrements the current index. - - \bold Note: methods should only be called after the Component has completed. -*/ -void QQuickPathView::decrementCurrentIndex() -{ - Q_D(QQuickPathView); - if (d->model && d->modelCount) { - int idx = currentIndex()-1; - if (idx < 0) - idx = d->modelCount - 1; - d->moveDirection = QQuickPathViewPrivate::Negative; - setCurrentIndex(idx); - } -} - -/*! - \qmlproperty real QtQuick2::PathView::offset - - The offset specifies how far along the path the items are from their initial positions. - This is a real number that ranges from 0.0 to the count of items in the model. -*/ -qreal QQuickPathView::offset() const -{ - Q_D(const QQuickPathView); - return d->offset; -} - -void QQuickPathView::setOffset(qreal offset) -{ - Q_D(QQuickPathView); - d->setOffset(offset); - d->updateCurrent(); -} - -void QQuickPathViewPrivate::setOffset(qreal o) -{ - Q_Q(QQuickPathView); - if (offset != o) { - if (isValid() && q->isComponentComplete()) { - offset = qmlMod(o, qreal(modelCount)); - if (offset < 0) - offset += qreal(modelCount); - q->refill(); - } else { - offset = o; - } - emit q->offsetChanged(); - } -} - -void QQuickPathViewPrivate::setAdjustedOffset(qreal o) -{ - setOffset(o+offsetAdj); -} - -/*! - \qmlproperty Component QtQuick2::PathView::highlight - This property holds the component to use as the highlight. - - An instance of the highlight component will be created for each view. - The geometry of the resultant component instance will be managed by the view - so as to stay with the current item. - - The below example demonstrates how to make a simple highlight. Note the use - of the \l{PathView::onPath}{PathView.onPath} attached property to ensure that - the highlight is hidden when flicked away from the path. - - \qml - Component { - Rectangle { - visible: PathView.onPath - // ... - } - } - \endqml - - \sa highlightItem, highlightRangeMode -*/ - -QDeclarativeComponent *QQuickPathView::highlight() const -{ - Q_D(const QQuickPathView); - return d->highlightComponent; -} - -void QQuickPathView::setHighlight(QDeclarativeComponent *highlight) -{ - Q_D(QQuickPathView); - if (highlight != d->highlightComponent) { - d->highlightComponent = highlight; - d->createHighlight(); - d->updateHighlight(); - emit highlightChanged(); - } -} - -/*! - \qmlproperty Item QtQuick2::PathView::highlightItem - - \c highlightItem holds the highlight item, which was created - from the \l highlight component. - - \sa highlight -*/ -QQuickItem *QQuickPathView::highlightItem() -{ - Q_D(const QQuickPathView); - return d->highlightItem; -} -/*! - \qmlproperty real QtQuick2::PathView::preferredHighlightBegin - \qmlproperty real QtQuick2::PathView::preferredHighlightEnd - \qmlproperty enumeration QtQuick2::PathView::highlightRangeMode - - These properties set the preferred range of the highlight (current item) - within the view. The preferred values must be in the range 0.0-1.0. - - If highlightRangeMode is set to \e PathView.NoHighlightRange - - If highlightRangeMode is set to \e PathView.ApplyRange the view will - attempt to maintain the highlight within the range, however - the highlight can move outside of the range at the ends of the path - or due to a mouse interaction. - - If highlightRangeMode is set to \e PathView.StrictlyEnforceRange the highlight will never - move outside of the range. This means that the current item will change - if a keyboard or mouse action would cause the highlight to move - outside of the range. - - Note that this is the correct way to influence where the - current item ends up when the view moves. For example, if you want the - currently selected item to be in the middle of the path, then set the - highlight range to be 0.5,0.5 and highlightRangeMode to PathView.StrictlyEnforceRange. - Then, when the path scrolls, - the currently selected item will be the item at that position. This also applies to - when the currently selected item changes - it will scroll to within the preferred - highlight range. Furthermore, the behaviour of the current item index will occur - whether or not a highlight exists. - - The default value is \e PathView.StrictlyEnforceRange. - - Note that a valid range requires preferredHighlightEnd to be greater - than or equal to preferredHighlightBegin. -*/ -qreal QQuickPathView::preferredHighlightBegin() const -{ - Q_D(const QQuickPathView); - return d->highlightRangeStart; -} - -void QQuickPathView::setPreferredHighlightBegin(qreal start) -{ - Q_D(QQuickPathView); - if (d->highlightRangeStart == start || start < 0 || start > 1.0) - return; - d->highlightRangeStart = start; - d->haveHighlightRange = d->highlightRangeMode != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; - refill(); - emit preferredHighlightBeginChanged(); -} - -qreal QQuickPathView::preferredHighlightEnd() const -{ - Q_D(const QQuickPathView); - return d->highlightRangeEnd; -} - -void QQuickPathView::setPreferredHighlightEnd(qreal end) -{ - Q_D(QQuickPathView); - if (d->highlightRangeEnd == end || end < 0 || end > 1.0) - return; - d->highlightRangeEnd = end; - d->haveHighlightRange = d->highlightRangeMode != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; - refill(); - emit preferredHighlightEndChanged(); -} - -QQuickPathView::HighlightRangeMode QQuickPathView::highlightRangeMode() const -{ - Q_D(const QQuickPathView); - return d->highlightRangeMode; -} - -void QQuickPathView::setHighlightRangeMode(HighlightRangeMode mode) -{ - Q_D(QQuickPathView); - if (d->highlightRangeMode == mode) - return; - d->highlightRangeMode = mode; - d->haveHighlightRange = d->highlightRangeMode != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; - if (d->haveHighlightRange) { - d->regenerate(); - d->snapToCurrent(); - } - emit highlightRangeModeChanged(); -} - -/*! - \qmlproperty int QtQuick2::PathView::highlightMoveDuration - This property holds the move animation duration of the highlight delegate. - - If the highlightRangeMode is StrictlyEnforceRange then this property - determines the speed that the items move along the path. - - The default value for the duration is 300ms. -*/ -int QQuickPathView::highlightMoveDuration() const -{ - Q_D(const QQuickPathView); - return d->highlightMoveDuration; -} - -void QQuickPathView::setHighlightMoveDuration(int duration) -{ - Q_D(QQuickPathView); - if (d->highlightMoveDuration == duration) - return; - d->highlightMoveDuration = duration; - emit highlightMoveDurationChanged(); -} - -/*! - \qmlproperty real QtQuick2::PathView::dragMargin - This property holds the maximum distance from the path that initiate mouse dragging. - - By default the path can only be dragged by clicking on an item. If - dragMargin is greater than zero, a drag can be initiated by clicking - within dragMargin pixels of the path. -*/ -qreal QQuickPathView::dragMargin() const -{ - Q_D(const QQuickPathView); - return d->dragMargin; -} - -void QQuickPathView::setDragMargin(qreal dragMargin) -{ - Q_D(QQuickPathView); - if (d->dragMargin == dragMargin) - return; - d->dragMargin = dragMargin; - emit dragMarginChanged(); -} - -/*! - \qmlproperty real QtQuick2::PathView::flickDeceleration - This property holds the rate at which a flick will decelerate. - - The default is 100. -*/ -qreal QQuickPathView::flickDeceleration() const -{ - Q_D(const QQuickPathView); - return d->deceleration; -} - -void QQuickPathView::setFlickDeceleration(qreal dec) -{ - Q_D(QQuickPathView); - if (d->deceleration == dec) - return; - d->deceleration = dec; - emit flickDecelerationChanged(); -} - -/*! - \qmlproperty bool QtQuick2::PathView::interactive - - A user cannot drag or flick a PathView that is not interactive. - - This property is useful for temporarily disabling flicking. This allows - special interaction with PathView's children. -*/ -bool QQuickPathView::isInteractive() const -{ - Q_D(const QQuickPathView); - return d->interactive; -} - -void QQuickPathView::setInteractive(bool interactive) -{ - Q_D(QQuickPathView); - if (interactive != d->interactive) { - d->interactive = interactive; - if (!interactive) - d->tl.clear(); - emit interactiveChanged(); - } -} - -/*! - \qmlproperty bool QtQuick2::PathView::moving - - This property holds whether the view is currently moving - due to the user either dragging or flicking the view. -*/ -bool QQuickPathView::isMoving() const -{ - Q_D(const QQuickPathView); - return d->moving; -} - -/*! - \qmlproperty bool QtQuick2::PathView::flicking - - This property holds whether the view is currently moving - due to the user flicking the view. -*/ -bool QQuickPathView::isFlicking() const -{ - Q_D(const QQuickPathView); - return d->flicking; -} - -/*! - \qmlsignal QtQuick2::PathView::onMovementStarted() - - This handler is called when the view begins moving due to user - interaction. -*/ - -/*! - \qmlsignal QtQuick2::PathView::onMovementEnded() - - This handler is called when the view stops moving due to user - interaction. If a flick was generated, this handler will - be triggered once the flick stops. If a flick was not - generated, the handler will be triggered when the - user stops dragging - i.e. a mouse or touch release. -*/ - -/*! - \qmlsignal QtQuick2::PathView::onFlickStarted() - - This handler is called when the view is flicked. A flick - starts from the point that the mouse or touch is released, - while still in motion. -*/ - -/*! - \qmlsignal QtQuick2::PathView::onFlickEnded() - - This handler is called when the view stops moving due to a flick. -*/ - -/*! - \qmlproperty Component QtQuick2::PathView::delegate - - The delegate provides a template defining each item instantiated by the view. - The index is exposed as an accessible \c index property. Properties of the - model are also available depending upon the type of \l {qmlmodels}{Data Model}. - - The number of elements in the delegate has a direct effect on the - flicking performance of the view when pathItemCount is specified. If at all possible, place functionality - that is not needed for the normal display of the delegate in a \l Loader which - can load additional elements when needed. - - Note that the PathView will layout the items based on the size of the root - item in the delegate. - - Here is an example delegate: - \snippet doc/src/snippets/declarative/pathview/pathview.qml 1 -*/ -QDeclarativeComponent *QQuickPathView::delegate() const -{ - Q_D(const QQuickPathView); - if (d->model) { - if (QQuickVisualDataModel *dataModel = qobject_cast(d->model)) - return dataModel->delegate(); - } - - return 0; -} - -void QQuickPathView::setDelegate(QDeclarativeComponent *delegate) -{ - Q_D(QQuickPathView); - if (delegate == this->delegate()) - return; - if (!d->ownModel) { - d->model = new QQuickVisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QQuickVisualDataModel *dataModel = qobject_cast(d->model)) { - int oldCount = dataModel->count(); - dataModel->setDelegate(delegate); - d->modelCount = dataModel->count(); - d->regenerate(); - if (oldCount != dataModel->count()) - emit countChanged(); - emit delegateChanged(); - } -} - -/*! - \qmlproperty int QtQuick2::PathView::pathItemCount - This property holds the number of items visible on the path at any one time. -*/ -int QQuickPathView::pathItemCount() const -{ - Q_D(const QQuickPathView); - return d->pathItems; -} - -void QQuickPathView::setPathItemCount(int i) -{ - Q_D(QQuickPathView); - if (i == d->pathItems) - return; - if (i < 1) - i = 1; - d->pathItems = i; - d->updateMappedRange(); - if (d->isValid() && isComponentComplete()) { - d->regenerate(); - } - emit pathItemCountChanged(); -} - -QPointF QQuickPathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const -{ - //XXX maybe do recursively at increasing resolution. - qreal mindist = 1e10; // big number - QPointF nearPoint = path->pointAt(0); - qreal nearPc = 0; - for (qreal i=1; i < 1000; i++) { - QPointF pt = path->pointAt(i/1000.0); - QPointF diff = pt - point; - qreal dist = diff.x()*diff.x() + diff.y()*diff.y(); - if (dist < mindist) { - nearPoint = pt; - nearPc = i; - mindist = dist; - } - } - - if (nearPercent) - *nearPercent = nearPc / 1000.0; - - return nearPoint; -} - -void QQuickPathView::mousePressEvent(QMouseEvent *event) -{ - Q_D(QQuickPathView); - if (d->interactive) { - d->handleMousePressEvent(event); - event->accept(); - } else { - QQuickItem::mousePressEvent(event); - } -} - -void QQuickPathViewPrivate::handleMousePressEvent(QMouseEvent *event) -{ - Q_Q(QQuickPathView); - if (!interactive || !items.count()) - return; - QPointF scenePoint = q->mapToScene(event->localPos()); - int idx = 0; - for (; idx < items.count(); ++idx) { - QRectF rect = items.at(idx)->boundingRect(); - rect = items.at(idx)->mapRectToScene(rect); - if (rect.contains(scenePoint)) - break; - } - if (idx == items.count() && dragMargin == 0.) // didn't click on an item - return; - - startPoint = pointNear(event->localPos(), &startPc); - if (idx == items.count()) { - qreal distance = qAbs(event->localPos().x() - startPoint.x()) + qAbs(event->localPos().y() - startPoint.y()); - if (distance > dragMargin) - return; - } - - if (tl.isActive() && flicking) - stealMouse = true; // If we've been flicked then steal the click. - else - stealMouse = false; - - lastElapsed = 0; - lastDist = 0; - QQuickItemPrivate::start(lastPosTime); - tl.clear(); -} - -void QQuickPathView::mouseMoveEvent(QMouseEvent *event) -{ - Q_D(QQuickPathView); - if (d->interactive) { - d->handleMouseMoveEvent(event); - if (d->stealMouse) - setKeepMouseGrab(true); - event->accept(); - } else { - QQuickItem::mouseMoveEvent(event); - } -} - -void QQuickPathViewPrivate::handleMouseMoveEvent(QMouseEvent *event) -{ - Q_Q(QQuickPathView); - if (!interactive || !lastPosTime.isValid()) - return; - - qreal newPc; - QPointF pathPoint = pointNear(event->localPos(), &newPc); - if (!stealMouse) { - QPointF delta = pathPoint - startPoint; - if (qAbs(delta.x()) > qApp->styleHints()->startDragDistance() || qAbs(delta.y()) > qApp->styleHints()->startDragDistance()) { - stealMouse = true; - startPc = newPc; - } - } - - if (stealMouse) { - moveReason = QQuickPathViewPrivate::Mouse; - qreal diff = (newPc - startPc)*modelCount*mappedRange; - if (diff) { - q->setOffset(offset + diff); - - if (diff > modelCount/2) - diff -= modelCount; - else if (diff < -modelCount/2) - diff += modelCount; - - lastElapsed = QQuickItemPrivate::restart(lastPosTime); - lastDist = diff; - startPc = newPc; - } - if (!moving) { - moving = true; - emit q->movingChanged(); - emit q->movementStarted(); - } - } -} - -void QQuickPathView::mouseReleaseEvent(QMouseEvent *event) -{ - Q_D(QQuickPathView); - if (d->interactive) { - d->handleMouseReleaseEvent(event); - event->accept(); - ungrabMouse(); - } else { - QQuickItem::mouseReleaseEvent(event); - } -} - -void QQuickPathViewPrivate::handleMouseReleaseEvent(QMouseEvent *) -{ - Q_Q(QQuickPathView); - stealMouse = false; - q->setKeepMouseGrab(false); - if (!interactive || !lastPosTime.isValid()) - return; - - qreal elapsed = qreal(lastElapsed + QQuickItemPrivate::elapsed(lastPosTime)) / 1000.; - qreal velocity = elapsed > 0. ? lastDist / elapsed : 0; - if (model && modelCount && qAbs(velocity) > 1.) { - qreal count = pathItems == -1 ? modelCount : pathItems; - if (qAbs(velocity) > count * 2) // limit velocity - velocity = (velocity > 0 ? count : -count) * 2; - // Calculate the distance to be travelled - qreal v2 = velocity*velocity; - qreal accel = deceleration/10; - // + 0.25 to encourage moving at least one item in the flick direction - qreal dist = qMin(qreal(modelCount-1), qreal(v2 / (accel * 2.0) + 0.25)); - if (haveHighlightRange && highlightRangeMode == QQuickPathView::StrictlyEnforceRange) { - // round to nearest item. - if (velocity > 0.) - dist = qRound(dist + offset) - offset; - else - dist = qRound(dist - offset) + offset; - // Calculate accel required to stop on item boundary - if (dist <= 0.) { - dist = 0.; - accel = 0.; - } else { - accel = v2 / (2.0f * qAbs(dist)); - } - } - offsetAdj = 0.0; - moveOffset.setValue(offset); - tl.accel(moveOffset, velocity, accel, dist); - tl.callback(QDeclarativeTimeLineCallback(&moveOffset, fixOffsetCallback, this)); - if (!flicking) { - flicking = true; - emit q->flickingChanged(); - emit q->flickStarted(); - } - } else { - fixOffset(); - } - - lastPosTime.invalidate(); - if (!tl.isActive()) - q->movementEnding(); -} - -bool QQuickPathView::sendMouseEvent(QMouseEvent *event) -{ - Q_D(QQuickPathView); - QRectF myRect = mapRectToScene(QRectF(0, 0, width(), height())); - QQuickCanvas *c = canvas(); - QQuickItem *grabber = c ? c->mouseGrabberItem() : 0; - bool stealThisEvent = d->stealMouse; - if ((stealThisEvent || myRect.contains(event->windowPos())) && (!grabber || !grabber->keepMouseGrab())) { - QMouseEvent mouseEvent(event->type(), mapFromScene(event->windowPos()), event->windowPos(), event->screenPos(), - event->button(), event->buttons(), event->modifiers()); - mouseEvent.setAccepted(false); - - switch (mouseEvent.type()) { - case QEvent::MouseMove: - d->handleMouseMoveEvent(&mouseEvent); - break; - case QEvent::MouseButtonPress: - d->handleMousePressEvent(&mouseEvent); - stealThisEvent = d->stealMouse; // Update stealThisEvent in case changed by function call above - break; - case QEvent::MouseButtonRelease: - d->handleMouseReleaseEvent(&mouseEvent); - break; - default: - break; - } - grabber = c->mouseGrabberItem(); - if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) - grabMouse(); - - return d->stealMouse; - } else if (d->lastPosTime.isValid()) { - d->lastPosTime.invalidate(); - d->fixOffset(); - } - if (event->type() == QEvent::MouseButtonRelease) - d->stealMouse = false; - return false; -} - -bool QQuickPathView::childMouseEventFilter(QQuickItem *i, QEvent *e) -{ - Q_D(QQuickPathView); - if (!isVisible() || !d->interactive) - return QQuickItem::childMouseEventFilter(i, e); - - switch (e->type()) { - case QEvent::MouseButtonPress: - case QEvent::MouseMove: - case QEvent::MouseButtonRelease: - return sendMouseEvent(static_cast(e)); - default: - break; - } - - return QQuickItem::childMouseEventFilter(i, e); -} - -void QQuickPathView::mouseUngrabEvent() -{ - Q_D(QQuickPathView); - if (d->stealMouse) { - // if our mouse grab has been removed (probably by a Flickable), - // fix our state - d->stealMouse = false; - setKeepMouseGrab(false); - d->lastPosTime.invalidate(); - } -} - -void QQuickPathView::updatePolish() -{ - QQuickItem::updatePolish(); - refill(); -} - -void QQuickPathView::componentComplete() -{ - Q_D(QQuickPathView); - if (d->model && d->ownModel) - static_cast(d->model.data())->componentComplete(); - - QQuickItem::componentComplete(); - - d->createHighlight(); - // It is possible that a refill has already happended to to Path - // bindings being handled in the componentComplete(). If so - // don't do it again. - if (d->items.count() == 0 && d->model) { - d->modelCount = d->model->count(); - d->regenerate(); - } - d->updateHighlight(); - - if (d->modelCount) - emit countChanged(); -} - -void QQuickPathView::refill() -{ - Q_D(QQuickPathView); - if (!d->isValid() || !isComponentComplete()) - return; - - d->layoutScheduled = false; - bool currentVisible = false; - - // first move existing items and remove items off path - int idx = d->firstIndex; - QList::iterator it = d->items.begin(); - while (it != d->items.end()) { - qreal pos = d->positionOfIndex(idx); - QQuickItem *item = *it; - if (pos >= 0.0) { - d->updateItem(item, pos); - if (idx == d->currentIndex) { - currentVisible = true; - d->currentItemOffset = pos; - } - ++it; - } else { - // qDebug() << "release"; - d->updateItem(item, 1.0); - d->releaseItem(item); - if (it == d->items.begin()) { - if (++d->firstIndex >= d->modelCount) - d->firstIndex = 0; - } - it = d->items.erase(it); - } - ++idx; - if (idx >= d->modelCount) - idx = 0; - } - if (!d->items.count()) - d->firstIndex = -1; - - bool waiting = false; - if (d->modelCount) { - // add items to beginning and end - int count = d->pathItems == -1 ? d->modelCount : qMin(d->pathItems, d->modelCount); - if (d->items.count() < count) { - int idx = qRound(d->modelCount - d->offset) % d->modelCount; - qreal startPos = 0.0; - if (d->haveHighlightRange && d->highlightRangeMode != QQuickPathView::NoHighlightRange) - startPos = d->highlightRangeStart; - if (d->firstIndex >= 0) { - startPos = d->positionOfIndex(d->firstIndex); - idx = (d->firstIndex + d->items.count()) % d->modelCount; - } - qreal pos = d->positionOfIndex(idx); - while ((pos > startPos || !d->items.count()) && d->items.count() < count) { -// qDebug() << "append" << idx; - QQuickItem *item = d->getItem(idx, idx+1); - if (!item) { - waiting = true; - break; - } - if (d->currentIndex == idx) { - currentVisible = true; - d->currentItemOffset = pos; - } - if (d->items.count() == 0) - d->firstIndex = idx; - d->items.append(item); - d->updateItem(item, pos); - ++idx; - if (idx >= d->modelCount) - idx = 0; - pos = d->positionOfIndex(idx); - } - - idx = d->firstIndex - 1; - if (idx < 0) - idx = d->modelCount - 1; - pos = d->positionOfIndex(idx); - while (!waiting && (pos >= 0.0 && pos < startPos) && d->items.count() < count) { -// qDebug() << "prepend" << idx; - QQuickItem *item = d->getItem(idx, idx+1); - if (!item) { - waiting = true; - break; - } - if (d->currentIndex == idx) { - currentVisible = true; - d->currentItemOffset = pos; - } - d->items.prepend(item); - d->updateItem(item, pos); - d->firstIndex = idx; - idx = d->firstIndex - 1; - if (idx < 0) - idx = d->modelCount - 1; - pos = d->positionOfIndex(idx); - } - } - } - - if (!currentVisible) { - d->currentItemOffset = 1.0; - if (d->currentItem) { - if (QQuickPathViewAttached *att = d->attached(d->currentItem)) - att->setOnPath(false); - } else if (!waiting && d->currentIndex >= 0 && d->currentIndex < d->modelCount) { - if (d->currentItem = d->getItem(d->currentIndex, d->currentIndex, false)) { - d->updateItem(d->currentItem, d->currentIndex < d->firstIndex ? 0.0 : 1.0); - if (QQuickPathViewAttached *att = d->attached(d->currentItem)) - att->setIsCurrentItem(true); - } - } - } else if (!waiting && !d->currentItem) { - if (d->currentItem = d->getItem(d->currentIndex, d->currentIndex, true)) { - d->currentItem->setFocus(true); - if (QQuickPathViewAttached *att = d->attached(d->currentItem)) - att->setIsCurrentItem(true); - } - } - - if (d->highlightItem && d->haveHighlightRange && d->highlightRangeMode == QQuickPathView::StrictlyEnforceRange) { - d->updateItem(d->highlightItem, d->highlightRangeStart); - if (QQuickPathViewAttached *att = d->attached(d->highlightItem)) - att->setOnPath(true); - } else if (d->highlightItem && d->moveReason != QQuickPathViewPrivate::SetIndex) { - d->updateItem(d->highlightItem, d->currentItemOffset); - if (QQuickPathViewAttached *att = d->attached(d->highlightItem)) - att->setOnPath(currentVisible); - } - while (d->itemCache.count()) - d->releaseItem(d->itemCache.takeLast()); -} - -void QQuickPathView::modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset) -{ - Q_D(QQuickPathView); - if (!d->model || !d->model->isValid() || !d->path || !isComponentComplete()) - return; - - if (reset) { - d->modelCount = d->model->count(); - d->regenerate(); - emit countChanged(); - return; - } - - if (changeSet.removes().isEmpty() && changeSet.inserts().isEmpty()) - return; - - const int modelCount = d->modelCount; - int moveId = -1; - int moveOffset; - bool currentChanged = false; - bool changedOffset = false; - foreach (const QDeclarativeChangeSet::Remove &r, changeSet.removes()) { - if (moveId == -1 && d->currentIndex >= r.index + r.count) { - d->currentIndex -= r.count; - currentChanged = true; - } else if (moveId == -1 && d->currentIndex >= r.index && d->currentIndex < r.index + r.count) { - // current item has been removed. - d->currentIndex = qMin(r.index, d->modelCount - r.count - 1); - if (r.isMove()) { - moveId = r.moveId; - moveOffset = d->currentIndex - r.index; - } else if (d->currentItem) { - if (QQuickPathViewAttached *att = d->attached(d->currentItem)) - att->setIsCurrentItem(true); - d->releaseItem(d->currentItem); - d->currentItem = 0; - } - currentChanged = true; - } - - if (r.index > d->currentIndex) { - changedOffset = true; - d->offset -= r.count; - d->offsetAdj -= r.count; - } - d->modelCount -= r.count; - } - foreach (const QDeclarativeChangeSet::Insert &i, changeSet.inserts()) { - if (d->modelCount) { - if (moveId == -1 && i.index <= d->currentIndex) { - d->currentIndex += i.count; - currentChanged = true; - } else { - if (moveId != -1 && moveId == i.moveId) { - d->currentIndex = i.index + moveOffset; - currentChanged = true; - } - if (i.index > d->currentIndex) { - d->offset += i.count; - d->offsetAdj += i.count; - changedOffset = true; - } - } - } - d->modelCount += i.count; - } - - d->offset = qmlMod(d->offset, d->modelCount); - if (d->offset < 0) - d->offset += d->modelCount; - - d->itemCache += d->items; - d->items.clear(); - - if (!d->modelCount) { - while (d->itemCache.count()) - d->releaseItem(d->itemCache.takeLast()); - d->offset = 0; - changedOffset = true; - d->tl.reset(d->moveOffset); - } else { - if (!d->flicking && !d->moving && d->haveHighlightRange && d->highlightRangeMode == QQuickPathView::StrictlyEnforceRange) { - d->offset = qmlMod(d->modelCount - d->currentIndex, d->modelCount); - changedOffset = true; - } - d->firstIndex = -1; - d->updateMappedRange(); - d->scheduleLayout(); - } - if (changedOffset) - emit offsetChanged(); - if (currentChanged) - emit currentIndexChanged(); - if (d->modelCount != modelCount) - emit countChanged(); -} - -void QQuickPathView::destroyingItem(QQuickItem *item) -{ - Q_UNUSED(item); -} - -void QQuickPathView::ticked() -{ - Q_D(QQuickPathView); - d->updateCurrent(); -} - -void QQuickPathView::movementEnding() -{ - Q_D(QQuickPathView); - if (d->flicking) { - d->flicking = false; - emit flickingChanged(); - emit flickEnded(); - } - if (d->moving && !d->stealMouse) { - d->moving = false; - emit movingChanged(); - emit movementEnded(); - } -} - -// find the item closest to the snap position -int QQuickPathViewPrivate::calcCurrentIndex() -{ - int current = -1; - if (modelCount && model && items.count()) { - offset = qmlMod(offset, modelCount); - if (offset < 0) - offset += modelCount; - current = qRound(qAbs(qmlMod(modelCount - offset, modelCount))); - current = current % modelCount; - } - - return current; -} - -void QQuickPathViewPrivate::createCurrentItem() -{ - if (requestedIndex != -1) - return; - int itemIndex = (currentIndex - firstIndex + modelCount) % modelCount; - if (itemIndex < items.count()) { - if (currentItem = getItem(currentIndex, currentIndex, true)) { - currentItem->setFocus(true); - if (QQuickPathViewAttached *att = attached(currentItem)) - att->setIsCurrentItem(true); - } - } else if (currentIndex >= 0 && currentIndex < modelCount) { - if (currentItem = getItem(currentIndex, currentIndex, false)) { - updateItem(currentItem, currentIndex < firstIndex ? 0.0 : 1.0); - if (QQuickPathViewAttached *att = attached(currentItem)) - att->setIsCurrentItem(true); - } - } -} - -void QQuickPathViewPrivate::updateCurrent() -{ - Q_Q(QQuickPathView); - if (moveReason != Mouse) - return; - if (!modelCount || !haveHighlightRange || highlightRangeMode != QQuickPathView::StrictlyEnforceRange) - return; - - int idx = calcCurrentIndex(); - if (model && idx != currentIndex) { - if (currentItem) { - if (QQuickPathViewAttached *att = attached(currentItem)) - att->setIsCurrentItem(false); - releaseItem(currentItem); - } - currentIndex = idx; - currentItem = 0; - createCurrentItem(); - emit q->currentIndexChanged(); - } -} - -void QQuickPathViewPrivate::fixOffsetCallback(void *d) -{ - ((QQuickPathViewPrivate *)d)->fixOffset(); -} - -void QQuickPathViewPrivate::fixOffset() -{ - Q_Q(QQuickPathView); - if (model && items.count()) { - if (haveHighlightRange && highlightRangeMode == QQuickPathView::StrictlyEnforceRange) { - int curr = calcCurrentIndex(); - if (curr != currentIndex) - q->setCurrentIndex(curr); - else - snapToCurrent(); - } - } -} - -void QQuickPathViewPrivate::snapToCurrent() -{ - if (!model || modelCount <= 0) - return; - - qreal targetOffset = qmlMod(modelCount - currentIndex, modelCount); - - if (offset == targetOffset) - return; - - moveReason = Other; - offsetAdj = 0.0; - tl.reset(moveOffset); - moveOffset.setValue(offset); - - const int duration = highlightMoveDuration; - - if (!duration) { - tl.set(moveOffset, targetOffset); - } else if (moveDirection == Positive || (moveDirection == Shortest && targetOffset - offset > modelCount/2)) { - qreal distance = modelCount - targetOffset + offset; - if (targetOffset > moveOffset) { - tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * offset / distance)); - tl.set(moveOffset, modelCount); - tl.move(moveOffset, targetOffset, QEasingCurve(offset == 0.0 ? QEasingCurve::InOutQuad : QEasingCurve::OutQuad), int(duration * (modelCount-targetOffset) / distance)); - } else { - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration); - } - } else if (moveDirection == Negative || targetOffset - offset <= -modelCount/2) { - qreal distance = modelCount - offset + targetOffset; - if (targetOffset < moveOffset) { - tl.move(moveOffset, modelCount, QEasingCurve(targetOffset == 0 ? QEasingCurve::InOutQuad : QEasingCurve::InQuad), int(duration * (modelCount-offset) / distance)); - tl.set(moveOffset, 0.0); - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * targetOffset / distance)); - } else { - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration); - } - } else { - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration); - } - moveDirection = Shortest; -} - -QQuickPathViewAttached *QQuickPathView::qmlAttachedProperties(QObject *obj) -{ - return new QQuickPathViewAttached(obj); -} - -QT_END_NAMESPACE - diff --git a/src/declarative/items/qquickpathview_p.h b/src/declarative/items/qquickpathview_p.h deleted file mode 100644 index ebc1587b09..0000000000 --- a/src/declarative/items/qquickpathview_p.h +++ /dev/null @@ -1,259 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKPATHVIEW_P_H -#define QQUICKPATHVIEW_P_H - -#include "qquickitem.h" - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeChangeSet; - -class QQuickPathViewPrivate; -class QQuickPathViewAttached; -class Q_AUTOTEST_EXPORT QQuickPathView : public QQuickItem -{ - Q_OBJECT - - Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) - Q_PROPERTY(QDeclarativePath *path READ path WRITE setPath NOTIFY pathChanged) - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged) - Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged) - - Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged) - Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged) - - Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged) - Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged) - Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged) - Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged) - - Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin NOTIFY dragMarginChanged) - Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged) - Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged) - - Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) - Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) - - Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) - Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount NOTIFY pathItemCountChanged) - - Q_ENUMS(HighlightRangeMode) - -public: - QQuickPathView(QQuickItem *parent=0); - virtual ~QQuickPathView(); - - QVariant model() const; - void setModel(const QVariant &); - - QDeclarativePath *path() const; - void setPath(QDeclarativePath *); - - int currentIndex() const; - void setCurrentIndex(int idx); - - QQuickItem *currentItem() const; - - qreal offset() const; - void setOffset(qreal offset); - - QDeclarativeComponent *highlight() const; - void setHighlight(QDeclarativeComponent *highlight); - QQuickItem *highlightItem(); - - enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange }; - HighlightRangeMode highlightRangeMode() const; - void setHighlightRangeMode(HighlightRangeMode mode); - - qreal preferredHighlightBegin() const; - void setPreferredHighlightBegin(qreal); - - qreal preferredHighlightEnd() const; - void setPreferredHighlightEnd(qreal); - - int highlightMoveDuration() const; - void setHighlightMoveDuration(int); - - qreal dragMargin() const; - void setDragMargin(qreal margin); - - qreal flickDeceleration() const; - void setFlickDeceleration(qreal dec); - - bool isInteractive() const; - void setInteractive(bool); - - bool isMoving() const; - bool isFlicking() const; - - int count() const; - - QDeclarativeComponent *delegate() const; - void setDelegate(QDeclarativeComponent *); - - int pathItemCount() const; - void setPathItemCount(int); - - static QQuickPathViewAttached *qmlAttachedProperties(QObject *); - -public Q_SLOTS: - void incrementCurrentIndex(); - void decrementCurrentIndex(); - -Q_SIGNALS: - void currentIndexChanged(); - void currentItemChanged(); - void offsetChanged(); - void modelChanged(); - void countChanged(); - void pathChanged(); - void preferredHighlightBeginChanged(); - void preferredHighlightEndChanged(); - void highlightRangeModeChanged(); - void dragMarginChanged(); - void snapPositionChanged(); - void delegateChanged(); - void pathItemCountChanged(); - void flickDecelerationChanged(); - void interactiveChanged(); - void movingChanged(); - void flickingChanged(); - void highlightChanged(); - void highlightItemChanged(); - void highlightMoveDurationChanged(); - void movementStarted(); - void movementEnded(); - void flickStarted(); - void flickEnded(); - -protected: - virtual void updatePolish(); - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *); - bool sendMouseEvent(QMouseEvent *event); - bool childMouseEventFilter(QQuickItem *, QEvent *); - void mouseUngrabEvent(); - void componentComplete(); - -private Q_SLOTS: - void refill(); - void ticked(); - void movementEnding(); - void modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset); - void createdItem(int index, QQuickItem *item); - void initItem(int index, QQuickItem *item); - void destroyingItem(QQuickItem *item); - void pathUpdated(); - -private: - friend class QQuickPathViewAttached; - Q_DISABLE_COPY(QQuickPathView) - Q_DECLARE_PRIVATE(QQuickPathView) -}; - -class QDeclarativeOpenMetaObject; -class QQuickPathViewAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QQuickPathView *view READ view CONSTANT) - Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) - Q_PROPERTY(bool onPath READ isOnPath NOTIFY pathChanged) - -public: - QQuickPathViewAttached(QObject *parent); - ~QQuickPathViewAttached(); - - QQuickPathView *view() { return m_view; } - - bool isCurrentItem() const { return m_isCurrent; } - void setIsCurrentItem(bool c) { - if (m_isCurrent != c) { - m_isCurrent = c; - emit currentItemChanged(); - } - } - - QVariant value(const QByteArray &name) const; - void setValue(const QByteArray &name, const QVariant &val); - - bool isOnPath() const { return m_onPath; } - void setOnPath(bool on) { - if (on != m_onPath) { - m_onPath = on; - emit pathChanged(); - } - } - qreal m_percent; - -Q_SIGNALS: - void currentItemChanged(); - void pathChanged(); - -private: - friend class QQuickPathViewPrivate; - friend class QQuickPathView; - QQuickPathView *m_view; - QDeclarativeOpenMetaObject *m_metaobject; - bool m_onPath : 1; - bool m_isCurrent : 1; -}; - - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickPathView) -QML_DECLARE_TYPEINFO(QQuickPathView, QML_HAS_ATTACHED_PROPERTIES) -QT_END_HEADER - -#endif // QQUICKPATHVIEW_P_H diff --git a/src/declarative/items/qquickpathview_p_p.h b/src/declarative/items/qquickpathview_p_p.h deleted file mode 100644 index 9bf329dab5..0000000000 --- a/src/declarative/items/qquickpathview_p_p.h +++ /dev/null @@ -1,199 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKPATHVIEW_P_P_H -#define QQUICKPATHVIEW_P_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 "qquickpathview_p.h" -#include "qquickitem_p.h" -#include "qquickvisualdatamodel_p.h" - -#include -#include -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QDeclarativeOpenMetaObjectType; -class QQuickPathViewAttached; -class QQuickPathViewPrivate : public QQuickItemPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickPathView) - -public: - QQuickPathViewPrivate() - : path(0), currentIndex(0), currentItemOffset(0.0), startPc(0), lastDist(0) - , lastElapsed(0), offset(0.0), offsetAdj(0.0), mappedRange(1.0) - , stealMouse(false), ownModel(false), interactive(true), haveHighlightRange(true) - , autoHighlight(true), highlightUp(false), layoutScheduled(false) - , moving(false), flicking(false), requestedOnPath(false), inRequest(false) - , dragMargin(0), deceleration(100) - , moveOffset(this, &QQuickPathViewPrivate::setAdjustedOffset) - , firstIndex(-1), pathItems(-1), requestedIndex(-1), requestedZ(0) - , moveReason(Other), moveDirection(Shortest), attType(0), highlightComponent(0), highlightItem(0) - , moveHighlight(this, &QQuickPathViewPrivate::setHighlightPosition) - , highlightPosition(0) - , highlightRangeStart(0), highlightRangeEnd(0) - , highlightRangeMode(QQuickPathView::StrictlyEnforceRange) - , highlightMoveDuration(300), modelCount(0) - { - } - - void init(); - - void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) { - if ((newGeometry.size() != oldGeometry.size()) - && (!highlightItem || item != highlightItem)) { - if (QQuickPathViewAttached *att = attached(item)) - att->m_percent = -1; - scheduleLayout(); - } - } - - void scheduleLayout() { - Q_Q(QQuickPathView); - if (!layoutScheduled) { - layoutScheduled = true; - q->polish(); - } - } - - QQuickItem *getItem(int modelIndex, qreal z = 0, bool onPath=true); - void releaseItem(QQuickItem *item); - QQuickPathViewAttached *attached(QQuickItem *item); - QDeclarativeOpenMetaObjectType *attachedType(); - void clear(); - void updateMappedRange(); - qreal positionOfIndex(qreal index) const; - void createHighlight(); - void updateHighlight(); - void setHighlightPosition(qreal pos); - bool isValid() const { - return model && model->count() > 0 && model->isValid() && path; - } - - void handleMousePressEvent(QMouseEvent *event); - void handleMouseMoveEvent(QMouseEvent *event); - void handleMouseReleaseEvent(QMouseEvent *); - - int calcCurrentIndex(); - void createCurrentItem(); - void updateCurrent(); - static void fixOffsetCallback(void*); - void fixOffset(); - void setOffset(qreal offset); - void setAdjustedOffset(qreal offset); - void regenerate(); - void updateItem(QQuickItem *, qreal); - void snapToCurrent(); - QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const; - - QDeclarativePath *path; - int currentIndex; - QDeclarativeGuard currentItem; - qreal currentItemOffset; - qreal startPc; - QPointF startPoint; - qreal lastDist; - int lastElapsed; - qreal offset; - qreal offsetAdj; - qreal mappedRange; - bool stealMouse : 1; - bool ownModel : 1; - bool interactive : 1; - bool haveHighlightRange : 1; - bool autoHighlight : 1; - bool highlightUp : 1; - bool layoutScheduled : 1; - bool moving : 1; - bool flicking : 1; - bool requestedOnPath : 1; - bool inRequest : 1; - QElapsedTimer lastPosTime; - QPointF lastPos; - qreal dragMargin; - qreal deceleration; - QDeclarativeTimeLine tl; - QDeclarativeTimeLineValueProxy moveOffset; - int firstIndex; - int pathItems; - int requestedIndex; - qreal requestedZ; - QList items; - QList itemCache; - QDeclarativeGuard model; - QVariant modelVariant; - enum MovementReason { Other, SetIndex, Mouse }; - MovementReason moveReason; - enum MovementDirection { Shortest, Negative, Positive }; - MovementDirection moveDirection; - QDeclarativeOpenMetaObjectType *attType; - QDeclarativeComponent *highlightComponent; - QQuickItem *highlightItem; - QDeclarativeTimeLineValueProxy moveHighlight; - qreal highlightPosition; - qreal highlightRangeStart; - qreal highlightRangeEnd; - QQuickPathView::HighlightRangeMode highlightRangeMode; - int highlightMoveDuration; - int modelCount; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/declarative/items/qquickpincharea.cpp b/src/declarative/items/qquickpincharea.cpp deleted file mode 100644 index beacbe32bf..0000000000 --- a/src/declarative/items/qquickpincharea.cpp +++ /dev/null @@ -1,600 +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 QtSG module 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 "qquickpincharea_p_p.h" -#include "qquickcanvas.h" - -#include -#include -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass PinchEvent QQuickPinchEvent - \inqmlmodule QtQuick 2 - \ingroup qml-event-elements - \brief The PinchEvent object provides information about a pinch event. - - \bold {The PinchEvent element was added in QtQuick 1.1} - - The \c center, \c startCenter, \c previousCenter properties provide the center position between the two touch points. - - The \c scale and \c previousScale properties provide the scale factor. - - The \c angle, \c previousAngle and \c rotation properties provide the angle between the two points and the amount of rotation. - - The \c point1, \c point2, \c startPoint1, \c startPoint2 properties provide the positions of the touch points. - - The \c accepted property may be set to false in the \c onPinchStarted handler if the gesture should not - be handled. - - \sa PinchArea -*/ - -/*! - \qmlproperty QPointF QtQuick2::PinchEvent::center - \qmlproperty QPointF QtQuick2::PinchEvent::startCenter - \qmlproperty QPointF QtQuick2::PinchEvent::previousCenter - - These properties hold the position of the center point between the two touch points. - - \list - \o \c center is the current center point - \o \c previousCenter is the center point of the previous event. - \o \c startCenter is the center point when the gesture began - \endlist -*/ - -/*! - \qmlproperty real QtQuick2::PinchEvent::scale - \qmlproperty real QtQuick2::PinchEvent::previousScale - - These properties hold the scale factor determined by the change in distance between the two touch points. - - \list - \o \c scale is the current scale factor. - \o \c previousScale is the scale factor of the previous event. - \endlist - - When a pinch gesture is started, the scale is 1.0. -*/ - -/*! - \qmlproperty real QtQuick2::PinchEvent::angle - \qmlproperty real QtQuick2::PinchEvent::previousAngle - \qmlproperty real QtQuick2::PinchEvent::rotation - - These properties hold the angle between the two touch points. - - \list - \o \c angle is the current angle between the two points in the range -180 to 180. - \o \c previousAngle is the angle of the previous event. - \o \c rotation is the total rotation since the pinch gesture started. - \endlist - - When a pinch gesture is started, the rotation is 0.0. -*/ - -/*! - \qmlproperty QPointF QtQuick2::PinchEvent::point1 - \qmlproperty QPointF QtQuick2::PinchEvent::startPoint1 - \qmlproperty QPointF QtQuick2::PinchEvent::point2 - \qmlproperty QPointF QtQuick2::PinchEvent::startPoint2 - - These properties provide the actual touch points generating the pinch. - - \list - \o \c point1 and \c point2 hold the current positions of the points. - \o \c startPoint1 and \c startPoint2 hold the positions of the points when the second point was touched. - \endlist -*/ - -/*! - \qmlproperty bool QtQuick2::PinchEvent::accepted - - Setting this property to false in the \c PinchArea::onPinchStarted handler - will result in no further pinch events being generated, and the gesture - ignored. -*/ - -/*! - \qmlproperty int QtQuick2::PinchEvent::pointCount - - Holds the number of points currently touched. The PinchArea will not react - until two touch points have initited a gesture, but will remain active until - all touch points have been released. -*/ - -QQuickPinch::QQuickPinch() - : m_target(0), m_minScale(1.0), m_maxScale(1.0) - , m_minRotation(0.0), m_maxRotation(0.0) - , m_axis(NoDrag), m_xmin(-FLT_MAX), m_xmax(FLT_MAX) - , m_ymin(-FLT_MAX), m_ymax(FLT_MAX), m_active(false) -{ -} - -QQuickPinchAreaPrivate::~QQuickPinchAreaPrivate() -{ - delete pinch; -} - -/*! - \qmlclass PinchArea QQuickPinchArea - \inqmlmodule QtQuick 2 - \brief The PinchArea item enables simple pinch gesture handling. - \inherits Item - - \bold {The PinchArea element was added in QtQuick 1.1} - - A PinchArea is an invisible item that is typically used in conjunction with - a visible item in order to provide pinch gesture handling for that item. - - The \l enabled property is used to enable and disable pinch handling for - the proxied item. When disabled, the pinch area becomes transparent to - mouse/touch events. - - PinchArea can be used in two ways: - - \list - \o setting a \c pinch.target to provide automatic interaction with an element - \o using the onPinchStarted, onPinchUpdated and onPinchFinished handlers - \endlist - - \sa PinchEvent -*/ - -/*! - \qmlsignal QtQuick2::PinchArea::onPinchStarted() - - This handler is called when the pinch area detects that a pinch gesture has started. - - The \l {PinchEvent}{pinch} parameter provides information about the pinch gesture, - including the scale, center and angle of the pinch. - - To ignore this gesture set the \c pinch.accepted property to false. The gesture - will be canceled and no further events will be sent. -*/ - -/*! - \qmlsignal QtQuick2::PinchArea::onPinchUpdated() - - This handler is called when the pinch area detects that a pinch gesture has changed. - - The \l {PinchEvent}{pinch} parameter provides information about the pinch gesture, - including the scale, center and angle of the pinch. -*/ - -/*! - \qmlsignal QtQuick2::PinchArea::onPinchFinished() - - This handler is called when the pinch area detects that a pinch gesture has finished. - - The \l {PinchEvent}{pinch} parameter provides information about the pinch gesture, - including the scale, center and angle of the pinch. -*/ - - -/*! - \qmlproperty Item QtQuick2::PinchArea::pinch.target - \qmlproperty bool QtQuick2::PinchArea::pinch.active - \qmlproperty real QtQuick2::PinchArea::pinch.minimumScale - \qmlproperty real QtQuick2::PinchArea::pinch.maximumScale - \qmlproperty real QtQuick2::PinchArea::pinch.minimumRotation - \qmlproperty real QtQuick2::PinchArea::pinch.maximumRotation - \qmlproperty enumeration QtQuick2::PinchArea::pinch.dragAxis - \qmlproperty real QtQuick2::PinchArea::pinch.minimumX - \qmlproperty real QtQuick2::PinchArea::pinch.maximumX - \qmlproperty real QtQuick2::PinchArea::pinch.minimumY - \qmlproperty real QtQuick2::PinchArea::pinch.maximumY - - \c pinch provides a convenient way to make an item react to pinch gestures. - - \list - \i \c pinch.target specifies the id of the item to drag. - \i \c pinch.active specifies if the target item is currently being dragged. - \i \c pinch.minimumScale and \c pinch.maximumScale limit the range of the Item::scale property. - \i \c pinch.minimumRotation and \c pinch.maximumRotation limit the range of the Item::rotation property. - \i \c pinch.dragAxis specifies whether dragging in not allowed (\c Pinch.NoDrag), can be done horizontally (\c Pinch.XAxis), vertically (\c Pinch.YAxis), or both (\c Pinch.XandYAxis) - \i \c pinch.minimum and \c pinch.maximum limit how far the target can be dragged along the corresponding axes. - \endlist -*/ - -QQuickPinchArea::QQuickPinchArea(QQuickItem *parent) - : QQuickItem(*(new QQuickPinchAreaPrivate), parent) -{ - Q_D(QQuickPinchArea); - d->init(); -} - -QQuickPinchArea::~QQuickPinchArea() -{ -} -/*! - \qmlproperty bool QtQuick2::PinchArea::enabled - This property holds whether the item accepts pinch gestures. - - This property defaults to true. -*/ -bool QQuickPinchArea::isEnabled() const -{ - Q_D(const QQuickPinchArea); - return d->absorb; -} - -void QQuickPinchArea::setEnabled(bool a) -{ - Q_D(QQuickPinchArea); - if (a != d->absorb) { - d->absorb = a; - emit enabledChanged(); - } -} - -void QQuickPinchArea::touchEvent(QTouchEvent *event) -{ - Q_D(QQuickPinchArea); - if (!d->absorb || !isVisible()) { - QQuickItem::event(event); - return; - } - - switch (event->type()) { - case QEvent::TouchBegin: - case QEvent::TouchUpdate: - d->touchPoints.clear(); - for (int i = 0; i < event->touchPoints().count(); ++i) { - if (!(event->touchPoints().at(i).state() & Qt::TouchPointReleased)) { - d->touchPoints << event->touchPoints().at(i); - } - } - updatePinch(); - break; - case QEvent::TouchEnd: - d->touchPoints.clear(); - updatePinch(); - break; - default: - QQuickItem::event(event); - } -} - -void QQuickPinchArea::updatePinch() -{ - Q_D(QQuickPinchArea); - if (d->touchPoints.count() == 0) { - if (d->inPinch) { - d->inPinch = false; - QPointF pinchCenter = mapFromScene(d->sceneLastCenter); - QQuickPinchEvent pe(pinchCenter, d->pinchLastScale, d->pinchLastAngle, d->pinchRotation); - pe.setStartCenter(d->pinchStartCenter); - pe.setPreviousCenter(pinchCenter); - pe.setPreviousAngle(d->pinchLastAngle); - pe.setPreviousScale(d->pinchLastScale); - pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); - pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); - pe.setPoint1(mapFromScene(d->lastPoint1)); - pe.setPoint2(mapFromScene(d->lastPoint2)); - emit pinchFinished(&pe); - d->pinchStartDist = 0; - d->pinchActivated = false; - if (d->pinch && d->pinch->target()) - d->pinch->setActive(false); - } - d->initPinch = false; - d->pinchRejected = false; - d->stealMouse = false; - setKeepMouseGrab(false); - QQuickCanvas *c = canvas(); - if (c && c->mouseGrabberItem() == this) - ungrabMouse(); - return; - } - QTouchEvent::TouchPoint touchPoint1 = d->touchPoints.at(0); - QTouchEvent::TouchPoint touchPoint2 = d->touchPoints.at(d->touchPoints. count() >= 2 ? 1 : 0); - if (d->touchPoints.count() == 2 - && (touchPoint1.state() & Qt::TouchPointPressed || touchPoint2.state() & Qt::TouchPointPressed)) { - d->id1 = touchPoint1.id(); - d->sceneStartPoint1 = touchPoint1.scenePos(); - d->sceneStartPoint2 = touchPoint2.scenePos(); - d->pinchActivated = true; - d->initPinch = true; - } - if (d->pinchActivated && !d->pinchRejected){ - const int dragThreshold = qApp->styleHints()->startDragDistance(); - QPointF p1 = touchPoint1.scenePos(); - QPointF p2 = touchPoint2.scenePos(); - qreal dx = p1.x() - p2.x(); - qreal dy = p1.y() - p2.y(); - qreal dist = sqrt(dx*dx + dy*dy); - QPointF sceneCenter = (p1 + p2)/2; - qreal angle = QLineF(p1, p2).angle(); - if (d->touchPoints.count() == 1) { - // If we only have one point then just move the center - if (d->id1 == touchPoint1.id()) - sceneCenter = d->sceneLastCenter + touchPoint1.scenePos() - d->lastPoint1; - else - sceneCenter = d->sceneLastCenter + touchPoint2.scenePos() - d->lastPoint2; - angle = d->pinchLastAngle; - } - d->id1 = touchPoint1.id(); - if (angle > 180) - angle -= 360; - if (!d->inPinch || d->initPinch) { - if (d->touchPoints.count() >= 2 - && (qAbs(p1.x()-d->sceneStartPoint1.x()) > dragThreshold - || qAbs(p1.y()-d->sceneStartPoint1.y()) > dragThreshold - || qAbs(p2.x()-d->sceneStartPoint2.x()) > dragThreshold - || qAbs(p2.y()-d->sceneStartPoint2.y()) > dragThreshold)) { - d->initPinch = false; - d->sceneStartCenter = sceneCenter; - d->sceneLastCenter = sceneCenter; - d->pinchStartCenter = mapFromScene(sceneCenter); - d->pinchStartDist = dist; - d->pinchStartAngle = angle; - d->pinchLastScale = 1.0; - d->pinchLastAngle = angle; - d->pinchRotation = 0.0; - d->lastPoint1 = p1; - d->lastPoint2 = p2; - QQuickPinchEvent pe(d->pinchStartCenter, 1.0, angle, 0.0); - pe.setStartCenter(d->pinchStartCenter); - pe.setPreviousCenter(d->pinchStartCenter); - pe.setPreviousAngle(d->pinchLastAngle); - pe.setPreviousScale(d->pinchLastScale); - pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); - pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); - pe.setPoint1(mapFromScene(d->lastPoint1)); - pe.setPoint2(mapFromScene(d->lastPoint2)); - pe.setPointCount(d->touchPoints.count()); - emit pinchStarted(&pe); - if (pe.accepted()) { - d->inPinch = true; - d->stealMouse = true; - QQuickCanvas *c = canvas(); - if (c && c->mouseGrabberItem() != this) - grabMouse(); - setKeepMouseGrab(true); - if (d->pinch && d->pinch->target()) { - d->pinchStartPos = pinch()->target()->pos(); - d->pinchStartScale = d->pinch->target()->scale(); - d->pinchStartRotation = d->pinch->target()->rotation(); - d->pinch->setActive(true); - } - } else { - d->pinchRejected = true; - } - } - } else if (d->pinchStartDist > 0) { - qreal scale = dist ? dist / d->pinchStartDist : d->pinchLastScale; - qreal da = d->pinchLastAngle - angle; - if (da > 180) - da -= 360; - else if (da < -180) - da += 360; - d->pinchRotation += da; - QPointF pinchCenter = mapFromScene(sceneCenter); - QQuickPinchEvent pe(pinchCenter, scale, angle, d->pinchRotation); - pe.setStartCenter(d->pinchStartCenter); - pe.setPreviousCenter(mapFromScene(d->sceneLastCenter)); - pe.setPreviousAngle(d->pinchLastAngle); - pe.setPreviousScale(d->pinchLastScale); - pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); - pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); - pe.setPoint1(touchPoint1.pos()); - pe.setPoint2(touchPoint2.pos()); - pe.setPointCount(d->touchPoints.count()); - d->pinchLastScale = scale; - d->sceneLastCenter = sceneCenter; - d->pinchLastAngle = angle; - d->lastPoint1 = touchPoint1.scenePos(); - d->lastPoint2 = touchPoint2.scenePos(); - emit pinchUpdated(&pe); - if (d->pinch && d->pinch->target()) { - qreal s = d->pinchStartScale * scale; - s = qMin(qMax(pinch()->minimumScale(),s), pinch()->maximumScale()); - pinch()->target()->setScale(s); - QPointF pos = sceneCenter - d->sceneStartCenter + d->pinchStartPos; - if (pinch()->axis() & QQuickPinch::XAxis) { - qreal x = pos.x(); - if (x < pinch()->xmin()) - x = pinch()->xmin(); - else if (x > pinch()->xmax()) - x = pinch()->xmax(); - pinch()->target()->setX(x); - } - if (pinch()->axis() & QQuickPinch::YAxis) { - qreal y = pos.y(); - if (y < pinch()->ymin()) - y = pinch()->ymin(); - else if (y > pinch()->ymax()) - y = pinch()->ymax(); - pinch()->target()->setY(y); - } - if (d->pinchStartRotation >= pinch()->minimumRotation() - && d->pinchStartRotation <= pinch()->maximumRotation()) { - qreal r = d->pinchRotation + d->pinchStartRotation; - r = qMin(qMax(pinch()->minimumRotation(),r), pinch()->maximumRotation()); - pinch()->target()->setRotation(r); - } - } - } - } -} - -void QQuickPinchArea::mousePressEvent(QMouseEvent *event) -{ - Q_D(QQuickPinchArea); - d->stealMouse = false; - if (!d->absorb) - QQuickItem::mousePressEvent(event); - else { - setKeepMouseGrab(false); - event->setAccepted(true); - } -} - -void QQuickPinchArea::mouseMoveEvent(QMouseEvent *event) -{ - Q_D(QQuickPinchArea); - if (!d->absorb) { - QQuickItem::mouseMoveEvent(event); - return; - } -} - -void QQuickPinchArea::mouseReleaseEvent(QMouseEvent *event) -{ - Q_D(QQuickPinchArea); - d->stealMouse = false; - if (!d->absorb) { - QQuickItem::mouseReleaseEvent(event); - } else { - QQuickCanvas *c = canvas(); - if (c && c->mouseGrabberItem() == this) - ungrabMouse(); - setKeepMouseGrab(false); - } -} - -void QQuickPinchArea::mouseUngrabEvent() -{ - setKeepMouseGrab(false); -} - -bool QQuickPinchArea::sendMouseEvent(QMouseEvent *event) -{ - Q_D(QQuickPinchArea); - QRectF myRect = mapRectToScene(QRectF(0, 0, width(), height())); - - QQuickCanvas *c = canvas(); - QQuickItem *grabber = c ? c->mouseGrabberItem() : 0; - bool stealThisEvent = d->stealMouse; - if ((stealThisEvent || myRect.contains(event->windowPos())) && (!grabber || !grabber->keepMouseGrab())) { - QMouseEvent mouseEvent(event->type(), mapFromScene(event->windowPos()), event->windowPos(), event->screenPos(), - event->button(), event->buttons(), event->modifiers()); - mouseEvent.setAccepted(false); - - switch (mouseEvent.type()) { - case QEvent::MouseMove: - mouseMoveEvent(&mouseEvent); - break; - case QEvent::MouseButtonPress: - mousePressEvent(&mouseEvent); - break; - case QEvent::MouseButtonRelease: - mouseReleaseEvent(&mouseEvent); - break; - default: - break; - } - grabber = c->mouseGrabberItem(); - if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) - grabMouse(); - - return stealThisEvent; - } - if (event->type() == QEvent::MouseButtonRelease) { - d->stealMouse = false; - if (c && c->mouseGrabberItem() == this) - ungrabMouse(); - setKeepMouseGrab(false); - } - return false; -} - -bool QQuickPinchArea::childMouseEventFilter(QQuickItem *i, QEvent *e) -{ - Q_D(QQuickPinchArea); - if (!d->absorb || !isVisible()) - return QQuickItem::childMouseEventFilter(i, e); - switch (e->type()) { - case QEvent::MouseButtonPress: - case QEvent::MouseMove: - case QEvent::MouseButtonRelease: - return sendMouseEvent(static_cast(e)); - break; - case QEvent::TouchBegin: - case QEvent::TouchUpdate: { - QTouchEvent *touch = static_cast(e); - d->touchPoints.clear(); - for (int i = 0; i < touch->touchPoints().count(); ++i) - if (!(touch->touchPoints().at(i).state() & Qt::TouchPointReleased)) - d->touchPoints << touch->touchPoints().at(i); - updatePinch(); - } - return d->inPinch; - case QEvent::TouchEnd: - d->touchPoints.clear(); - updatePinch(); - break; - default: - break; - } - - return QQuickItem::childMouseEventFilter(i, e); -} - -void QQuickPinchArea::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - QQuickItem::geometryChanged(newGeometry, oldGeometry); -} - -void QQuickPinchArea::itemChange(ItemChange change, const ItemChangeData &value) -{ - QQuickItem::itemChange(change, value); -} - -QQuickPinch *QQuickPinchArea::pinch() -{ - Q_D(QQuickPinchArea); - if (!d->pinch) - d->pinch = new QQuickPinch; - return d->pinch; -} - - -QT_END_NAMESPACE - diff --git a/src/declarative/items/qquickpincharea_p.h b/src/declarative/items/qquickpincharea_p.h deleted file mode 100644 index c98a1fdd9e..0000000000 --- a/src/declarative/items/qquickpincharea_p.h +++ /dev/null @@ -1,315 +0,0 @@ -// Commit: f707672eb4c51ea82fbd98e1da16ece61a74c690 -/**************************************************************************** -** -** 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 QtSG module 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 QQUICKPINCHAREA_H -#define QQUICKPINCHAREA_H - -#include "qquickitem.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_AUTOTEST_EXPORT QQuickPinch : public QObject -{ - Q_OBJECT - - Q_ENUMS(Axis) - Q_PROPERTY(QQuickItem *target READ target WRITE setTarget RESET resetTarget) - Q_PROPERTY(qreal minimumScale READ minimumScale WRITE setMinimumScale NOTIFY minimumScaleChanged) - Q_PROPERTY(qreal maximumScale READ maximumScale WRITE setMaximumScale NOTIFY maximumScaleChanged) - Q_PROPERTY(qreal minimumRotation READ minimumRotation WRITE setMinimumRotation NOTIFY minimumRotationChanged) - Q_PROPERTY(qreal maximumRotation READ maximumRotation WRITE setMaximumRotation NOTIFY maximumRotationChanged) - Q_PROPERTY(Axis dragAxis READ axis WRITE setAxis NOTIFY dragAxisChanged) - Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged) - Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged) - Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged) - Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged) - Q_PROPERTY(bool active READ active NOTIFY activeChanged) - -public: - QQuickPinch(); - - QQuickItem *target() const { return m_target; } - void setTarget(QQuickItem *target) { - if (target == m_target) - return; - m_target = target; - emit targetChanged(); - } - void resetTarget() { - if (!m_target) - return; - m_target = 0; - emit targetChanged(); - } - - qreal minimumScale() const { return m_minScale; } - void setMinimumScale(qreal s) { - if (s == m_minScale) - return; - m_minScale = s; - emit minimumScaleChanged(); - } - qreal maximumScale() const { return m_maxScale; } - void setMaximumScale(qreal s) { - if (s == m_maxScale) - return; - m_maxScale = s; - emit maximumScaleChanged(); - } - - qreal minimumRotation() const { return m_minRotation; } - void setMinimumRotation(qreal r) { - if (r == m_minRotation) - return; - m_minRotation = r; - emit minimumRotationChanged(); - } - qreal maximumRotation() const { return m_maxRotation; } - void setMaximumRotation(qreal r) { - if (r == m_maxRotation) - return; - m_maxRotation = r; - emit maximumRotationChanged(); - } - - enum Axis { NoDrag=0x00, XAxis=0x01, YAxis=0x02, XandYAxis=0x03 }; - Axis axis() const { return m_axis; } - void setAxis(Axis a) { - if (a == m_axis) - return; - m_axis = a; - emit dragAxisChanged(); - } - - qreal xmin() const { return m_xmin; } - void setXmin(qreal x) { - if (x == m_xmin) - return; - m_xmin = x; - emit minimumXChanged(); - } - qreal xmax() const { return m_xmax; } - void setXmax(qreal x) { - if (x == m_xmax) - return; - m_xmax = x; - emit maximumXChanged(); - } - qreal ymin() const { return m_ymin; } - void setYmin(qreal y) { - if (y == m_ymin) - return; - m_ymin = y; - emit minimumYChanged(); - } - qreal ymax() const { return m_ymax; } - void setYmax(qreal y) { - if (y == m_ymax) - return; - m_ymax = y; - emit maximumYChanged(); - } - - bool active() const { return m_active; } - void setActive(bool a) { - if (a == m_active) - return; - m_active = a; - emit activeChanged(); - } - -signals: - void targetChanged(); - void minimumScaleChanged(); - void maximumScaleChanged(); - void minimumRotationChanged(); - void maximumRotationChanged(); - void dragAxisChanged(); - void minimumXChanged(); - void maximumXChanged(); - void minimumYChanged(); - void maximumYChanged(); - void activeChanged(); - -private: - QQuickItem *m_target; - qreal m_minScale; - qreal m_maxScale; - qreal m_minRotation; - qreal m_maxRotation; - Axis m_axis; - qreal m_xmin; - qreal m_xmax; - qreal m_ymin; - qreal m_ymax; - bool m_active; -}; - -class Q_AUTOTEST_EXPORT QQuickPinchEvent : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QPointF center READ center) - Q_PROPERTY(QPointF startCenter READ startCenter) - Q_PROPERTY(QPointF previousCenter READ previousCenter) - Q_PROPERTY(qreal scale READ scale) - Q_PROPERTY(qreal previousScale READ previousScale) - Q_PROPERTY(qreal angle READ angle) - Q_PROPERTY(qreal previousAngle READ previousAngle) - Q_PROPERTY(qreal rotation READ rotation) - Q_PROPERTY(QPointF point1 READ point1) - Q_PROPERTY(QPointF startPoint1 READ startPoint1) - Q_PROPERTY(QPointF point2 READ point2) - Q_PROPERTY(QPointF startPoint2 READ startPoint2) - Q_PROPERTY(int pointCount READ pointCount) - Q_PROPERTY(bool accepted READ accepted WRITE setAccepted) - -public: - QQuickPinchEvent(QPointF c, qreal s, qreal a, qreal r) - : QObject(), m_center(c), m_scale(s), m_angle(a), m_rotation(r) - , m_pointCount(0), m_accepted(true) {} - - QPointF center() const { return m_center; } - QPointF startCenter() const { return m_startCenter; } - void setStartCenter(QPointF c) { m_startCenter = c; } - QPointF previousCenter() const { return m_lastCenter; } - void setPreviousCenter(QPointF c) { m_lastCenter = c; } - qreal scale() const { return m_scale; } - qreal previousScale() const { return m_lastScale; } - void setPreviousScale(qreal s) { m_lastScale = s; } - qreal angle() const { return m_angle; } - qreal previousAngle() const { return m_lastAngle; } - void setPreviousAngle(qreal a) { m_lastAngle = a; } - qreal rotation() const { return m_rotation; } - QPointF point1() const { return m_point1; } - void setPoint1(QPointF p) { m_point1 = p; } - QPointF startPoint1() const { return m_startPoint1; } - void setStartPoint1(QPointF p) { m_startPoint1 = p; } - QPointF point2() const { return m_point2; } - void setPoint2(QPointF p) { m_point2 = p; } - QPointF startPoint2() const { return m_startPoint2; } - void setStartPoint2(QPointF p) { m_startPoint2 = p; } - int pointCount() const { return m_pointCount; } - void setPointCount(int count) { m_pointCount = count; } - - bool accepted() const { return m_accepted; } - void setAccepted(bool a) { m_accepted = a; } - -private: - QPointF m_center; - QPointF m_startCenter; - QPointF m_lastCenter; - qreal m_scale; - qreal m_lastScale; - qreal m_angle; - qreal m_lastAngle; - qreal m_rotation; - QPointF m_point1; - QPointF m_point2; - QPointF m_startPoint1; - QPointF m_startPoint2; - int m_pointCount; - bool m_accepted; -}; - - -class QQuickMouseEvent; -class QQuickPinchAreaPrivate; -class Q_AUTOTEST_EXPORT QQuickPinchArea : public QQuickItem -{ - Q_OBJECT - - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(QQuickPinch *pinch READ pinch CONSTANT) - -public: - QQuickPinchArea(QQuickItem *parent=0); - ~QQuickPinchArea(); - - bool isEnabled() const; - void setEnabled(bool); - - QQuickPinch *pinch(); - -Q_SIGNALS: - void enabledChanged(); - void pinchStarted(QQuickPinchEvent *pinch); - void pinchUpdated(QQuickPinchEvent *pinch); - void pinchFinished(QQuickPinchEvent *pinch); - -protected: - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void mouseUngrabEvent(); - virtual bool sendMouseEvent(QMouseEvent *event); - virtual bool childMouseEventFilter(QQuickItem *i, QEvent *e); - virtual void touchEvent(QTouchEvent *event); - - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - virtual void itemChange(ItemChange change, const ItemChangeData& value); - -private: - void updatePinch(); - void handlePress(); - void handleRelease(); - -private: - Q_DISABLE_COPY(QQuickPinchArea) - Q_DECLARE_PRIVATE(QQuickPinchArea) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickPinch) -QML_DECLARE_TYPE(QQuickPinchEvent) -QML_DECLARE_TYPE(QQuickPinchArea) - -QT_END_HEADER - -#endif // QQUICKPINCHAREA_H - diff --git a/src/declarative/items/qquickpincharea_p_p.h b/src/declarative/items/qquickpincharea_p_p.h deleted file mode 100644 index 1c9d5c5ba4..0000000000 --- a/src/declarative/items/qquickpincharea_p_p.h +++ /dev/null @@ -1,116 +0,0 @@ -// Commit: f707672eb4c51ea82fbd98e1da16ece61a74c690 -/**************************************************************************** -** -** 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 QtSG module 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 QQUICKPINCHAREA_P_H -#define QQUICKPINCHAREA_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 - -#include "qquickitem_p.h" -#include "qquickpincharea_p.h" - -QT_BEGIN_NAMESPACE - -class QQuickPinch; -class QQuickPinchAreaPrivate : public QQuickItemPrivate -{ - Q_DECLARE_PUBLIC(QQuickPinchArea) -public: - QQuickPinchAreaPrivate() - : absorb(true), stealMouse(false), inPinch(false) - , pinchRejected(false), pinchActivated(false), initPinch(false) - , pinch(0), pinchStartDist(0), pinchStartScale(1.0) - , pinchLastScale(1.0), pinchStartRotation(0.0), pinchStartAngle(0.0) - , pinchLastAngle(0.0), pinchRotation(0.0) - { - } - - ~QQuickPinchAreaPrivate(); - - void init() - { - Q_Q(QQuickPinchArea); - q->setAcceptedMouseButtons(Qt::LeftButton); - q->setFiltersChildMouseEvents(true); - } - - bool absorb : 1; - bool stealMouse : 1; - bool inPinch : 1; - bool pinchRejected : 1; - bool pinchActivated : 1; - bool initPinch : 1; - QQuickPinch *pinch; - QPointF sceneStartPoint1; - QPointF sceneStartPoint2; - QPointF lastPoint1; - QPointF lastPoint2; - qreal pinchStartDist; - qreal pinchStartScale; - qreal pinchLastScale; - qreal pinchStartRotation; - qreal pinchStartAngle; - qreal pinchLastAngle; - qreal pinchRotation; - QPointF sceneStartCenter; - QPointF pinchStartCenter; - QPointF sceneLastCenter; - QPointF pinchStartPos; - QList touchPoints; - int id1; -}; - -QT_END_NAMESPACE - -#endif // QQUICKPINCHAREA_P_H - diff --git a/src/declarative/items/qquickpositioners.cpp b/src/declarative/items/qquickpositioners.cpp deleted file mode 100644 index 08fa4b1724..0000000000 --- a/src/declarative/items/qquickpositioners.cpp +++ /dev/null @@ -1,1532 +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 QtDeclarative module 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 "qquickpositioners_p.h" -#include "qquickpositioners_p_p.h" - -#include -#include -#include -#include - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const QQuickItemPrivate::ChangeTypes watchedChanges - = QQuickItemPrivate::Geometry - | QQuickItemPrivate::SiblingOrder - | QQuickItemPrivate::Visibility - | QQuickItemPrivate::Destroyed; - -void QQuickBasePositionerPrivate::watchChanges(QQuickItem *other) -{ - QQuickItemPrivate *otherPrivate = QQuickItemPrivate::get(other); - otherPrivate->addItemChangeListener(this, watchedChanges); -} - -void QQuickBasePositionerPrivate::unwatchChanges(QQuickItem* other) -{ - QQuickItemPrivate *otherPrivate = QQuickItemPrivate::get(other); - otherPrivate->removeItemChangeListener(this, watchedChanges); -} - -QQuickBasePositioner::QQuickBasePositioner(PositionerType at, QQuickItem *parent) - : QQuickImplicitSizeItem(*(new QQuickBasePositionerPrivate), parent) -{ - Q_D(QQuickBasePositioner); - d->init(at); -} -/*! - \internal - \class QQuickBasePositioner - \brief The QQuickBasePositioner class provides a base for QQuickGraphics layouts. - - To create a QQuickGraphics Positioner, simply subclass QQuickBasePositioner and implement - doLayout(), which is automatically called when the layout might need - updating. In doLayout() use the setX and setY functions from QQuickBasePositioner, and the - base class will apply the positions along with the appropriate transitions. The items to - position are provided in order as the protected member positionedItems. - - You also need to set a PositionerType, to declare whether you are positioning the x, y or both - for the child items. Depending on the chosen type, only x or y changes will be applied. - - Note that the subclass is responsible for adding the spacing in between items. - - Positioning is usually delayed until before a frame is rendered, to batch multiple repositioning - changes into one calculation. -*/ - -QQuickBasePositioner::QQuickBasePositioner(QQuickBasePositionerPrivate &dd, PositionerType at, QQuickItem *parent) - : QQuickImplicitSizeItem(dd, parent) -{ - Q_D(QQuickBasePositioner); - d->init(at); -} - -QQuickBasePositioner::~QQuickBasePositioner() -{ - Q_D(QQuickBasePositioner); - for (int i = 0; i < positionedItems.count(); ++i) - d->unwatchChanges(positionedItems.at(i).item); - positionedItems.clear(); -} - -void QQuickBasePositioner::updatePolish() -{ - Q_D(QQuickBasePositioner); - if (d->positioningDirty) - prePositioning(); -} - -int QQuickBasePositioner::spacing() const -{ - Q_D(const QQuickBasePositioner); - return d->spacing; -} - -void QQuickBasePositioner::setSpacing(int s) -{ - Q_D(QQuickBasePositioner); - if (s==d->spacing) - return; - d->spacing = s; - d->setPositioningDirty(); - emit spacingChanged(); -} - -QDeclarativeTransition *QQuickBasePositioner::move() const -{ - Q_D(const QQuickBasePositioner); - return d->moveTransition; -} - -void QQuickBasePositioner::setMove(QDeclarativeTransition *mt) -{ - Q_D(QQuickBasePositioner); - if (mt == d->moveTransition) - return; - d->moveTransition = mt; - emit moveChanged(); -} - -QDeclarativeTransition *QQuickBasePositioner::add() const -{ - Q_D(const QQuickBasePositioner); - return d->addTransition; -} - -void QQuickBasePositioner::setAdd(QDeclarativeTransition *add) -{ - Q_D(QQuickBasePositioner); - if (add == d->addTransition) - return; - - d->addTransition = add; - emit addChanged(); -} - -void QQuickBasePositioner::componentComplete() -{ - QQuickItem::componentComplete(); - positionedItems.reserve(childItems().count()); - prePositioning(); - reportConflictingAnchors(); -} - -void QQuickBasePositioner::itemChange(ItemChange change, const ItemChangeData &value) -{ - Q_D(QQuickBasePositioner); - if (change == ItemChildAddedChange){ - d->setPositioningDirty(); - } else if (change == ItemChildRemovedChange) { - QQuickItem *child = value.item; - QQuickBasePositioner::PositionedItem posItem(child); - int idx = positionedItems.find(posItem); - if (idx >= 0) { - d->unwatchChanges(child); - positionedItems.remove(idx); - } - d->setPositioningDirty(); - } - - QQuickItem::itemChange(change, value); -} - -void QQuickBasePositioner::prePositioning() -{ - Q_D(QQuickBasePositioner); - if (!isComponentComplete()) - return; - - if (d->doingPositioning) - return; - - d->positioningDirty = false; - d->doingPositioning = true; - //Need to order children by creation order modified by stacking order - QList children = childItems(); - - QPODVector oldItems; - positionedItems.copyAndClear(oldItems); - for (int ii = 0; ii < children.count(); ++ii) { - QQuickItem *child = children.at(ii); - QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child); - PositionedItem *item = 0; - PositionedItem posItem(child); - int wIdx = oldItems.find(posItem); - if (wIdx < 0) { - d->watchChanges(child); - positionedItems.append(posItem); - item = &positionedItems[positionedItems.count()-1]; - item->isNew = true; - if (!childPrivate->explicitVisible || !child->width() || !child->height()) - item->isVisible = false; - } else { - item = &oldItems[wIdx]; - // Items are only omitted from positioning if they are explicitly hidden - // i.e. their positioning is not affected if an ancestor is hidden. - if (!childPrivate->explicitVisible || !child->width() || !child->height()) { - item->isVisible = false; - } else if (!item->isVisible) { - item->isVisible = true; - item->isNew = true; - } else { - item->isNew = false; - } - positionedItems.append(*item); - } - } - QSizeF contentSize(0,0); - doPositioning(&contentSize); - updateAttachedProperties(); - if (!d->addActions.isEmpty() || !d->moveActions.isEmpty()) - finishApplyTransitions(); - d->doingPositioning = false; - //Set implicit size to the size of its children - setImplicitSize(contentSize.width(), contentSize.height()); -} - -void QQuickBasePositioner::positionX(int x, const PositionedItem &target) -{ - Q_D(QQuickBasePositioner); - if (d->type == Horizontal || d->type == Both) { - if (target.isNew) { - if (!d->addTransition || !d->addTransition->enabled()) - target.item->setX(x); - else - d->addActions << QDeclarativeAction(target.item, QLatin1String("x"), QVariant(x)); - } else if (x != target.item->x()) { - if (!d->moveTransition || !d->moveTransition->enabled()) - target.item->setX(x); - else - d->moveActions << QDeclarativeAction(target.item, QLatin1String("x"), QVariant(x)); - } - } -} - -void QQuickBasePositioner::positionY(int y, const PositionedItem &target) -{ - Q_D(QQuickBasePositioner); - if (d->type == Vertical || d->type == Both) { - if (target.isNew) { - if (!d->addTransition || !d->addTransition->enabled()) - target.item->setY(y); - else - d->addActions << QDeclarativeAction(target.item, QLatin1String("y"), QVariant(y)); - } else if (y != target.item->y()) { - if (!d->moveTransition || !d->moveTransition->enabled()) - target.item->setY(y); - else - d->moveActions << QDeclarativeAction(target.item, QLatin1String("y"), QVariant(y)); - } - } -} - -void QQuickBasePositioner::finishApplyTransitions() -{ - Q_D(QQuickBasePositioner); - // Note that if a transition is not set the transition manager will - // apply the changes directly, in the case add/move aren't set - d->addTransitionManager.transition(d->addActions, d->addTransition); - d->moveTransitionManager.transition(d->moveActions, d->moveTransition); - d->addActions.clear(); - d->moveActions.clear(); -} - -QQuickPositionerAttached *QQuickBasePositioner::qmlAttachedProperties(QObject *obj) -{ - return new QQuickPositionerAttached(obj); -} - -void QQuickBasePositioner::updateAttachedProperties(QQuickPositionerAttached *specificProperty, QQuickItem *specificPropertyOwner) const -{ - // If this function is deemed too expensive or shows up in profiles, it could - // be changed to run only when there are attached properties present. This - // could be a flag in the positioner that is set by the attached property - // constructor. - QQuickPositionerAttached *prevLastProperty = 0; - QQuickPositionerAttached *lastProperty = 0; - - int visibleItemIndex = 0; - for (int ii = 0; ii < positionedItems.count(); ++ii) { - const PositionedItem &child = positionedItems.at(ii); - if (!child.item) - continue; - - QQuickPositionerAttached *property = 0; - - if (specificProperty) { - if (specificPropertyOwner == child.item) { - property = specificProperty; - } - } else { - property = static_cast(qmlAttachedPropertiesObject(child.item, false)); - } - - if (child.isVisible) { - if (property) { - property->setIndex(visibleItemIndex); - property->setIsFirstItem(visibleItemIndex == 0); - - if (property->isLastItem()) - prevLastProperty = property; - } - - lastProperty = property; - ++visibleItemIndex; - } else if (property) { - property->setIndex(-1); - property->setIsFirstItem(false); - property->setIsLastItem(false); - } - } - - if (prevLastProperty && prevLastProperty != lastProperty) - prevLastProperty->setIsLastItem(false); - if (lastProperty) - lastProperty->setIsLastItem(true); -} - -/*! - \qmlclass Positioner QQuickPositionerAttached - \inqmlmodule QtQuick 2 - \ingroup qml-positioning-elements - \brief The Positioner type provides attached properties that contain details on where an item exists in a positioner. - - Positioner items (such as Column, Row, Flow and Grid) provide automatic layout - for child items. Attaching this property allows a child item to determine - where it exists within the positioner. -*/ - -QQuickPositionerAttached::QQuickPositionerAttached(QObject *parent) : QObject(parent), m_index(-1), m_isFirstItem(false), m_isLastItem(false) -{ - QQuickItem *attachedItem = qobject_cast(parent); - if (attachedItem) { - QQuickBasePositioner *positioner = qobject_cast(attachedItem->parent()); - if (positioner) { - positioner->updateAttachedProperties(this, attachedItem); - } - } -} - -/*! - \qmlattachedproperty Item QtQuick2::Positioner::index - - This property allows the item to determine - its index within the positioner. -*/ -void QQuickPositionerAttached::setIndex(int index) -{ - if (m_index == index) - return; - m_index = index; - emit indexChanged(); -} - -/*! - \qmlattachedproperty Item QtQuick2::Positioner::isFirstItem - \qmlattachedproperty Item QtQuick2::Positioner::isLastItem - - These properties allow the item to determine if it - is the first or last item in the positioner, respectively. -*/ -void QQuickPositionerAttached::setIsFirstItem(bool isFirstItem) -{ - if (m_isFirstItem == isFirstItem) - return; - m_isFirstItem = isFirstItem; - emit isFirstItemChanged(); -} - -void QQuickPositionerAttached::setIsLastItem(bool isLastItem) -{ - if (m_isLastItem == isLastItem) - return; - m_isLastItem = isLastItem; - emit isLastItemChanged(); -} - -/*! - \qmlclass Column QQuickColumn - \inqmlmodule QtQuick 2 - \ingroup qml-positioning-elements - \brief The Column item arranges its children vertically. - \inherits Item - - The Column item positions its child items so that they are vertically - aligned and not overlapping. - - Spacing between items can be added using the \l spacing property. - Transitions can be used for cases where items managed by a Column are - added or moved. These are stored in the \l add and \l move properties - respectively. - - See \l{Using QML Positioner and Repeater Items} for more details about this item and other - related items. - - \section1 Example Usage - - The following example positions differently shaped rectangles using a Column - item. - - \image verticalpositioner_example.png - - \snippet doc/src/snippets/declarative/column/vertical-positioner.qml document - - \section1 Using Transitions - - Transitions can be used to animate items that are added to, moved within, - or removed from a Column item. The \l add and \l move properties can be set to - the transitions that will be applied when items are added to, removed from, - or re-positioned within a Column item. - - The use of transitions with positioners is described in more detail in the - \l{Using QML Positioner and Repeater Items#Using Transitions}{Using QML - Positioner and Repeater Items} document. - - \image verticalpositioner_transition.gif - - \qml - Column { - spacing: 2 - add: Transition { - // Define an animation for adding a new item... - } - move: Transition { - // Define an animation for moving items within the column... - } - // ... - } - \endqml - - \section1 Limitations - - Note that the positioner assumes that the x and y positions of its children - will not change. If you manually change the x or y properties in script, bind - the x or y properties, use anchors on a child of a positioner, or have the - height of a child depend on the position of a child, then the - positioner may exhibit strange behavior. If you need to perform any of these - actions, consider positioning the items without the use of a Column. - - Items with a width or height of 0 will not be positioned. - - Positioning is batched and syncronized with painting to reduce the number of - calculations needed. This means that positioners may not reposition items immediately - when changes occur, but it will have moved by the next frame. - - \sa Row, Grid, Flow, Positioner, {declarative/positioners}{Positioners example} -*/ -/*! - \qmlproperty Transition QtQuick2::Column::add - - This property holds the transition to be applied when adding an - item to the positioner. The transition will only be applied to the - added item(s). Positioner transitions will only affect the - position (x, y) of items. - - For a positioner, adding an item can mean that either the object - has been created or reparented, and thus is now a child or the - positioner, or that the object has had its opacity increased from - zero, and thus is now visible. - - \sa move -*/ -/*! - \qmlproperty Transition QtQuick2::Column::move - - This property holds the transition to apply when moving an item - within the positioner. Positioner transitions will only affect - the position (x, y) of items. - - This transition can be performed when other items are added or removed - from the positioner, or when items resize themselves. - - \image positioner-move.gif - - \qml - Column { - move: Transition { - NumberAnimation { - properties: "y" - duration: 1000 - } - } - } - \endqml - - \sa add, {declarative/positioners}{Positioners example} -*/ -/*! - \qmlproperty int QtQuick2::Column::spacing - - The spacing is the amount in pixels left empty between adjacent - items. The default spacing is 0. - - \sa Grid::spacing -*/ -QQuickColumn::QQuickColumn(QQuickItem *parent) -: QQuickBasePositioner(Vertical, parent) -{ -} - -void QQuickColumn::doPositioning(QSizeF *contentSize) -{ - int voffset = 0; - - for (int ii = 0; ii < positionedItems.count(); ++ii) { - const PositionedItem &child = positionedItems.at(ii); - if (!child.item || !child.isVisible) - continue; - - if (child.item->y() != voffset) - positionY(voffset, child); - - contentSize->setWidth(qMax(contentSize->width(), child.item->width())); - - voffset += child.item->height(); - voffset += spacing(); - } - - if (voffset != 0)//If we positioned any items, undo the spacing from the last item - voffset -= spacing(); - contentSize->setHeight(voffset); -} - -void QQuickColumn::reportConflictingAnchors() -{ - QQuickBasePositionerPrivate *d = static_cast(QQuickBasePositionerPrivate::get(this)); - for (int ii = 0; ii < positionedItems.count(); ++ii) { - const PositionedItem &child = positionedItems.at(ii); - if (child.item) { - QQuickAnchors *anchors = QQuickItemPrivate::get(static_cast(child.item))->_anchors; - if (anchors) { - QQuickAnchors::Anchors usedAnchors = anchors->usedAnchors(); - if (usedAnchors & QQuickAnchors::TopAnchor || - usedAnchors & QQuickAnchors::BottomAnchor || - usedAnchors & QQuickAnchors::VCenterAnchor || - anchors->fill() || anchors->centerIn()) { - d->anchorConflict = true; - break; - } - } - } - } - if (d->anchorConflict) { - qmlInfo(this) << "Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"; - } -} -/*! - \qmlclass Row QQuickRow - \inqmlmodule QtQuick 2 - \ingroup qml-positioning-elements - \brief The Row item arranges its children horizontally. - \inherits Item - - The Row item positions its child items so that they are horizontally - aligned and not overlapping. - - Use \l spacing to set the spacing between items in a Row, and use the - \l add and \l move properties to set the transitions that should be applied - when items are added to, removed from, or re-positioned within the Row. - - See \l{Using QML Positioner and Repeater Items} for more details about this item and other - related items. - - \section1 Example Usage - - The following example lays out differently shaped rectangles using a Row. - - \image horizontalpositioner_example.png - - \snippet doc/src/snippets/declarative/row/row.qml document - - \section1 Using Transitions - - Transitions can be used to animate items that are added to, moved within, - or removed from a Grid item. The \l add and \l move properties can be set to - the transitions that will be applied when items are added to, removed from, - or re-positioned within a Row item. - - \section1 Limitations - - Note that the positioner assumes that the x and y positions of its children - will not change. If you manually change the x or y properties in script, bind - the x or y properties, use anchors on a child of a positioner, or have the - width of a child depend on the position of a child, then the - positioner may exhibit strange behavior. If you need to perform any of these - actions, consider positioning the items without the use of a Row. - - Items with a width or height of 0 will not be positioned. - - Positioning is batched and syncronized with painting to reduce the number of - calculations needed. This means that positioners may not reposition items immediately - when changes occur, but it will have moved by the next frame. - - \sa Column, Grid, Flow, Positioner, {declarative/positioners}{Positioners example} -*/ -/*! - \qmlproperty Transition QtQuick2::Row::add - - This property holds the transition to be applied when adding an - item to the positioner. The transition will only be applied to the - added item(s). Positioner transitions will only affect the - position (x, y) of items. - - For a positioner, adding an item can mean that either the object - has been created or reparented, and thus is now a child or the - positioner, or that the object has had its opacity increased from - zero, and thus is now visible. - - \sa move -*/ -/*! - \qmlproperty Transition QtQuick2::Row::move - - This property holds the transition to be applied when moving an - item within the positioner. Positioner transitions will only affect - the position (x, y) of items. - - This transition can be performed when other items are added or removed - from the positioner, or when items resize themselves. - - \qml - Row { - id: positioner - move: Transition { - NumberAnimation { - properties: "x" - duration: 1000 - } - } - } - \endqml - - \sa add, {declarative/positioners}{Positioners example} -*/ -/*! - \qmlproperty int QtQuick2::Row::spacing - - The spacing is the amount in pixels left empty between adjacent - items. The default spacing is 0. - - \sa Grid::spacing -*/ - -QQuickRow::QQuickRow(QQuickItem *parent) -: QQuickBasePositioner(Horizontal, parent) -{ -} -/*! - \qmlproperty enumeration QtQuick2::Row::layoutDirection - - This property holds the layoutDirection of the row. - - Possible values: - - \list - \o Qt.LeftToRight (default) - Items are laid out from left to right. If the width of the row is explicitly set, - the left anchor remains to the left of the row. - \o Qt.RightToLeft - Items are laid out from right to left. If the width of the row is explicitly set, - the right anchor remains to the right of the row. - \endlist - - \sa Grid::layoutDirection, Flow::layoutDirection, {declarative/righttoleft/layoutdirection}{Layout directions example} -*/ - -Qt::LayoutDirection QQuickRow::layoutDirection() const -{ - return QQuickBasePositionerPrivate::getLayoutDirection(this); -} - -void QQuickRow::setLayoutDirection(Qt::LayoutDirection layoutDirection) -{ - QQuickBasePositionerPrivate *d = static_cast(QQuickBasePositionerPrivate::get(this)); - if (d->layoutDirection != layoutDirection) { - d->layoutDirection = layoutDirection; - // For RTL layout the positioning changes when the width changes. - if (d->layoutDirection == Qt::RightToLeft) - d->addItemChangeListener(d, QQuickItemPrivate::Geometry); - else - d->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - prePositioning(); - emit layoutDirectionChanged(); - emit effectiveLayoutDirectionChanged(); - } -} -/*! - \qmlproperty enumeration QtQuick2::Row::effectiveLayoutDirection - This property holds the effective layout direction of the row positioner. - - When using the attached property \l {LayoutMirroring::enabled}{LayoutMirroring::enabled} for locale layouts, - the visual layout direction of the row positioner will be mirrored. However, the - property \l {Row::layoutDirection}{layoutDirection} will remain unchanged. - - \sa Row::layoutDirection, {LayoutMirroring}{LayoutMirroring} -*/ - -Qt::LayoutDirection QQuickRow::effectiveLayoutDirection() const -{ - return QQuickBasePositionerPrivate::getEffectiveLayoutDirection(this); -} - -void QQuickRow::doPositioning(QSizeF *contentSize) -{ - QQuickBasePositionerPrivate *d = static_cast(QQuickBasePositionerPrivate::get(this)); - int hoffset = 0; - - QList hoffsets; - for (int ii = 0; ii < positionedItems.count(); ++ii) { - const PositionedItem &child = positionedItems.at(ii); - if (!child.item || !child.isVisible) - continue; - - if (d->isLeftToRight()) { - if (child.item->x() != hoffset) - positionX(hoffset, child); - } else { - hoffsets << hoffset; - } - - contentSize->setHeight(qMax(contentSize->height(), child.item->height())); - - hoffset += child.item->width(); - hoffset += spacing(); - } - - if (hoffset != 0)//If we positioned any items, undo the extra spacing from the last item - hoffset -= spacing(); - contentSize->setWidth(hoffset); - - if (d->isLeftToRight()) - return; - - //Right to Left layout - int end = 0; - if (!widthValid()) - end = contentSize->width(); - else - end = width(); - - int acc = 0; - for (int ii = 0; ii < positionedItems.count(); ++ii) { - const PositionedItem &child = positionedItems.at(ii); - if (!child.item || !child.isVisible) - continue; - hoffset = end - hoffsets[acc++] - child.item->width(); - if (child.item->x() != hoffset) - positionX(hoffset, child); - } -} - -void QQuickRow::reportConflictingAnchors() -{ - QQuickBasePositionerPrivate *d = static_cast(QQuickBasePositionerPrivate::get(this)); - for (int ii = 0; ii < positionedItems.count(); ++ii) { - const PositionedItem &child = positionedItems.at(ii); - if (child.item) { - QQuickAnchors *anchors = QQuickItemPrivate::get(static_cast(child.item))->_anchors; - if (anchors) { - QQuickAnchors::Anchors usedAnchors = anchors->usedAnchors(); - if (usedAnchors & QQuickAnchors::LeftAnchor || - usedAnchors & QQuickAnchors::RightAnchor || - usedAnchors & QQuickAnchors::HCenterAnchor || - anchors->fill() || anchors->centerIn()) { - d->anchorConflict = true; - break; - } - } - } - } - if (d->anchorConflict) - qmlInfo(this) << "Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"; -} - -/*! - \qmlclass Grid QQuickGrid - \inqmlmodule QtQuick 2 - \ingroup qml-positioning-elements - \brief The Grid item positions its children in a grid. - \inherits Item - - The Grid item positions its child items so that they are - aligned in a grid and are not overlapping. - - The grid positioner calculates a grid of rectangular cells of sufficient - size to hold all items, placing the items in the cells, from left to right - and top to bottom. Each item is positioned in the top-left corner of its - cell with position (0, 0). - - A Grid defaults to four columns, and as many rows as are necessary to - fit all child items. The number of rows and columns can be constrained - by setting the \l rows and \l columns properties. - - Spacing can be added between child items by setting the \l spacing - property. The amount of spacing applied will be the same in the - horizontal and vertical directions. - - See \l{Using QML Positioner and Repeater Items} for more details about this item and other - related items. - - \section1 Example Usage - - The following example demonstrates this. - - \image gridLayout_example.png - - \snippet doc/src/snippets/declarative/grid/grid.qml document - - \section1 Using Transitions - - Transitions can be used to animate items that are added to, moved within, - or removed from a Grid item. The \l add and \l move properties can be set to - the transitions that will be applied when items are added to, removed from, - or re-positioned within a Grid item. - - \section1 Limitations - - Note that the positioner assumes that the x and y positions of its children - will not change. If you manually change the x or y properties in script, bind - the x or y properties, use anchors on a child of a positioner, or have the - width or height of a child depend on the position of a child, then the - positioner may exhibit strange behavior. If you need to perform any of these - actions, consider positioning the items without the use of a Grid. - - Items with a width or height of 0 will not be positioned. - - Positioning is batched and syncronized with painting to reduce the number of - calculations needed. This means that positioners may not reposition items immediately - when changes occur, but it will have moved by the next frame. - - \sa Flow, Row, Column, Positioner, {declarative/positioners}{Positioners example} -*/ -/*! - \qmlproperty Transition QtQuick2::Grid::add - - This property holds the transition to be applied when adding an - item to the positioner. The transition will only be applied to the - added item(s). Positioner transitions will only affect the - position (x, y) of items. - - For a positioner, adding an item can mean that either the object - has been created or reparented, and thus is now a child or the - positioner, or that the object has had its opacity increased from - zero, and thus is now visible. - - \sa move -*/ -/*! - \qmlproperty Transition QtQuick2::Grid::move - - This property holds the transition to be applied when moving an - item within the positioner. Positioner transitions will only affect - the position (x, y) of items. - - This transition can be performed when other items are added or removed - from the positioner, or when items resize themselves. - - \qml - Grid { - move: Transition { - NumberAnimation { - properties: "x,y" - duration: 1000 - } - } - } - \endqml - - \sa add, {declarative/positioners}{Positioners example} -*/ -/*! - \qmlproperty int QtQuick2::Grid::spacing - - The spacing is the amount in pixels left empty between adjacent - items. The default spacing is 0. - - The below example places a Grid containing a red, a blue and a - green rectangle on a gray background. The area the grid positioner - occupies is colored white. The positioner on the left has the - no spacing (the default), and the positioner on the right has - a spacing of 6. - - \inlineimage qml-grid-no-spacing.png - \inlineimage qml-grid-spacing.png - - \sa rows, columns -*/ -QQuickGrid::QQuickGrid(QQuickItem *parent) : - QQuickBasePositioner(Both, parent), m_rows(-1), m_columns(-1), m_rowSpacing(-1), m_columnSpacing(-1), m_flow(LeftToRight) -{ -} - -/*! - \qmlproperty int QtQuick2::Grid::columns - - This property holds the number of columns in the grid. The default - number of columns is 4. - - If the grid does not have enough items to fill the specified - number of columns, some columns will be of zero width. -*/ - -/*! - \qmlproperty int QtQuick2::Grid::rows - This property holds the number of rows in the grid. - - If the grid does not have enough items to fill the specified - number of rows, some rows will be of zero width. -*/ - -void QQuickGrid::setColumns(const int columns) -{ - if (columns == m_columns) - return; - m_columns = columns; - prePositioning(); - emit columnsChanged(); -} - -void QQuickGrid::setRows(const int rows) -{ - if (rows == m_rows) - return; - m_rows = rows; - prePositioning(); - emit rowsChanged(); -} - -/*! - \qmlproperty enumeration QtQuick2::Grid::flow - This property holds the flow of the layout. - - Possible values are: - - \list - \o Grid.LeftToRight (default) - Items are positioned next to - each other in the \l layoutDirection, then wrapped to the next line. - \o Grid.TopToBottom - Items are positioned next to each - other from top to bottom, then wrapped to the next column. - \endlist -*/ -QQuickGrid::Flow QQuickGrid::flow() const -{ - return m_flow; -} - -void QQuickGrid::setFlow(Flow flow) -{ - if (m_flow != flow) { - m_flow = flow; - prePositioning(); - emit flowChanged(); - } -} - -/*! - \qmlproperty int QtQuick2::Grid::rowSpacing - - This property holds the spacing in pixels between rows. - - \sa columnSpacing - \since QtQuick2.0 -*/ -void QQuickGrid::setRowSpacing(const int rowSpacing) -{ - if (rowSpacing == m_rowSpacing) - return; - m_rowSpacing = rowSpacing; - prePositioning(); - emit rowSpacingChanged(); -} - -/*! - \qmlproperty int QtQuick2::Grid::columnSpacing - - This property holds the spacing in pixels between columns. - - \sa rowSpacing - \since QtQuick2.0 -*/ -void QQuickGrid::setColumnSpacing(const int columnSpacing) -{ - if (columnSpacing == m_columnSpacing) - return; - m_columnSpacing = columnSpacing; - prePositioning(); - emit columnSpacingChanged(); -} - -/*! - \qmlproperty enumeration QtQuick2::Grid::layoutDirection - - This property holds the layout direction of the layout. - - Possible values are: - - \list - \o Qt.LeftToRight (default) - Items are positioned from the top to bottom, - and left to right. The flow direction is dependent on the - \l Grid::flow property. - \o Qt.RightToLeft - Items are positioned from the top to bottom, - and right to left. The flow direction is dependent on the - \l Grid::flow property. - \endlist - - \sa Flow::layoutDirection, Row::layoutDirection, {declarative/righttoleft/layoutdirection}{Layout directions example} -*/ -Qt::LayoutDirection QQuickGrid::layoutDirection() const -{ - return QQuickBasePositionerPrivate::getLayoutDirection(this); -} - -void QQuickGrid::setLayoutDirection(Qt::LayoutDirection layoutDirection) -{ - QQuickBasePositionerPrivate *d = static_cast(QQuickBasePositionerPrivate::get(this)); - if (d->layoutDirection != layoutDirection) { - d->layoutDirection = layoutDirection; - // For RTL layout the positioning changes when the width changes. - if (d->layoutDirection == Qt::RightToLeft) - d->addItemChangeListener(d, QQuickItemPrivate::Geometry); - else - d->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - prePositioning(); - emit layoutDirectionChanged(); - emit effectiveLayoutDirectionChanged(); - } -} - -/*! - \qmlproperty enumeration QtQuick2::Grid::effectiveLayoutDirection - This property holds the effective layout direction of the grid positioner. - - When using the attached property \l {LayoutMirroring::enabled}{LayoutMirroring::enabled} for locale layouts, - the visual layout direction of the grid positioner will be mirrored. However, the - property \l {Grid::layoutDirection}{layoutDirection} will remain unchanged. - - \sa Grid::layoutDirection, {LayoutMirroring}{LayoutMirroring} -*/ -Qt::LayoutDirection QQuickGrid::effectiveLayoutDirection() const -{ - return QQuickBasePositionerPrivate::getEffectiveLayoutDirection(this); -} - -void QQuickGrid::doPositioning(QSizeF *contentSize) -{ - QQuickBasePositionerPrivate *d = static_cast(QQuickBasePositionerPrivate::get(this)); - int c = m_columns; - int r = m_rows; - //Is allocating the extra QPODVector too much overhead? - QPODVector visibleItems;//we aren't concerned with invisible items - visibleItems.reserve(positionedItems.count()); - for (int i=0; i maxColWidth; - QList maxRowHeight; - int childIndex =0; - if (m_flow == LeftToRight) { - for (int i=0; i < r; i++){ - for (int j=0; j < c; j++){ - if (j==0) - maxRowHeight << 0; - if (i==0) - maxColWidth << 0; - - if (childIndex == visibleItems.count()) - break; - - const PositionedItem &child = visibleItems.at(childIndex++); - if (child.item->width() > maxColWidth[j]) - maxColWidth[j] = child.item->width(); - if (child.item->height() > maxRowHeight[i]) - maxRowHeight[i] = child.item->height(); - } - } - } else { - for (int j=0; j < c; j++){ - for (int i=0; i < r; i++){ - if (j==0) - maxRowHeight << 0; - if (i==0) - maxColWidth << 0; - - if (childIndex == visibleItems.count()) - break; - - const PositionedItem &child = visibleItems.at(childIndex++); - if (child.item->width() > maxColWidth[j]) - maxColWidth[j] = child.item->width(); - if (child.item->height() > maxRowHeight[i]) - maxRowHeight[i] = child.item->height(); - } - } - } - - int columnSpacing = m_columnSpacing; - if (columnSpacing == -1) - columnSpacing = spacing(); - - int rowSpacing = m_rowSpacing; - if (rowSpacing == -1) - rowSpacing = spacing(); - - int widthSum = 0; - for (int j=0; j < maxColWidth.size(); j++){ - if (j) - widthSum += columnSpacing; - widthSum += maxColWidth[j]; - } - - int heightSum = 0; - for (int i=0; i < maxRowHeight.size(); i++){ - if (i) - heightSum += rowSpacing; - heightSum += maxRowHeight[i]; - } - - contentSize->setHeight(heightSum); - contentSize->setWidth(widthSum); - - int end = 0; - if (widthValid()) - end = width(); - else - end = widthSum; - - int xoffset=0; - if (!d->isLeftToRight()) - xoffset = end; - int yoffset=0; - int curRow =0; - int curCol =0; - for (int i = 0; i < visibleItems.count(); ++i) { - const PositionedItem &child = visibleItems.at(i); - int childXOffset = xoffset; - if (!d->isLeftToRight()) - childXOffset -= child.item->width(); - if ((child.item->x() != childXOffset) || (child.item->y() != yoffset)){ - positionX(childXOffset, child); - positionY(yoffset, child); - } - - if (m_flow == LeftToRight) { - if (d->isLeftToRight()) - xoffset += maxColWidth[curCol]+columnSpacing; - else - xoffset -= maxColWidth[curCol]+columnSpacing; - curCol++; - curCol%=c; - if (!curCol){ - yoffset += maxRowHeight[curRow]+rowSpacing; - if (d->isLeftToRight()) - xoffset = 0; - else - xoffset = end; - curRow++; - if (curRow>=r) - break; - } - } else { - yoffset+=maxRowHeight[curRow]+rowSpacing; - curRow++; - curRow%=r; - if (!curRow){ - if (d->isLeftToRight()) - xoffset += maxColWidth[curCol]+columnSpacing; - else - xoffset -= maxColWidth[curCol]+columnSpacing; - yoffset=0; - curCol++; - if (curCol>=c) - break; - } - } - } -} - -void QQuickGrid::reportConflictingAnchors() -{ - QQuickBasePositionerPrivate *d = static_cast(QQuickBasePositionerPrivate::get(this)); - for (int ii = 0; ii < positionedItems.count(); ++ii) { - const PositionedItem &child = positionedItems.at(ii); - if (child.item) { - QQuickAnchors *anchors = QQuickItemPrivate::get(static_cast(child.item))->_anchors; - if (anchors && (anchors->usedAnchors() || anchors->fill() || anchors->centerIn())) { - d->anchorConflict = true; - break; - } - } - } - if (d->anchorConflict) - qmlInfo(this) << "Cannot specify anchors for items inside Grid"; -} - -/*! - \qmlclass Flow QQuickFlow - \inqmlmodule QtQuick 2 - \ingroup qml-positioning-elements - \brief The Flow item arranges its children side by side, wrapping as necessary. - \inherits Item - - The Flow item positions its child items like words on a page, wrapping them - to create rows or columns of items that do not overlap. - - Spacing between items can be added using the \l spacing property. - Transitions can be used for cases where items managed by a Column are - added or moved. These are stored in the \l add and \l move properties - respectively. - - See \l{Using QML Positioner and Repeater Items} for more details about this item and other - related items. - - \section1 Example Usage - - The following example positions \l Text items within a parent item using - a Flow item. - - \image qml-flow-snippet.png - - \snippet doc/src/snippets/declarative/flow.qml flow item - - \section1 Using Transitions - - Transitions can be used to animate items that are added to, moved within, - or removed from a Flow item. The \l add and \l move properties can be set to - the transitions that will be applied when items are added to, removed from, - or re-positioned within a Flow item. - - The use of transitions with positioners is described in more detail in the - \l{Using QML Positioner and Repeater Items#Using Transitions}{Using QML - Positioner and Repeater Items} document. - - \section1 Limitations - - Note that the positioner assumes that the x and y positions of its children - will not change. If you manually change the x or y properties in script, bind - the x or y properties, use anchors on a child of a positioner, or have the - width or height of a child depend on the position of a child, then the - positioner may exhibit strange behavior. If you need to perform any of these - actions, consider positioning the items without the use of a Flow. - - Items with a width or height of 0 will not be positioned. - - Positioning is batched and syncronized with painting to reduce the number of - calculations needed. This means that positioners may not reposition items immediately - when changes occur, but it will have moved by the next frame. - - \sa Column, Row, Grid, Positioner, {declarative/positioners}{Positioners example} -*/ -/*! - \qmlproperty Transition QtQuick2::Flow::add - - This property holds the transition to be applied when adding an - item to the positioner. The transition will only be applied to the - added item(s). Positioner transitions will only affect the - position (x, y) of items. - - For a positioner, adding an item can mean that either the object - has been created or reparented, and thus is now a child or the - positioner, or that the object has had its opacity increased from - zero, and thus is now visible. - - \sa move -*/ -/*! - \qmlproperty Transition QtQuick2::Flow::move - - This property holds the transition to be applied when moving an - item within the positioner. Positioner transitions will only affect - the position (x, y) of items. - - This transition can be performed when other items are added or removed - from the positioner, or when items resize themselves. - - \qml - Flow { - id: positioner - move: Transition { - NumberAnimation { - properties: "x,y" - ease: "easeOutBounce" - } - } - } - \endqml - - \sa add, {declarative/positioners}{Positioners example} -*/ -/*! - \qmlproperty int QtQuick2::Flow::spacing - - spacing is the amount in pixels left empty between each adjacent - item, and defaults to 0. - - \sa Grid::spacing -*/ - -class QQuickFlowPrivate : public QQuickBasePositionerPrivate -{ - Q_DECLARE_PUBLIC(QQuickFlow) - -public: - QQuickFlowPrivate() - : QQuickBasePositionerPrivate(), flow(QQuickFlow::LeftToRight) - {} - - QQuickFlow::Flow flow; -}; - -QQuickFlow::QQuickFlow(QQuickItem *parent) -: QQuickBasePositioner(*(new QQuickFlowPrivate), Both, parent) -{ - Q_D(QQuickFlow); - // Flow layout requires relayout if its own size changes too. - d->addItemChangeListener(d, QQuickItemPrivate::Geometry); -} - -/*! - \qmlproperty enumeration QtQuick2::Flow::flow - This property holds the flow of the layout. - - Possible values are: - - \list - \o Flow.LeftToRight (default) - Items are positioned next to - to each other according to the \l layoutDirection until the width of the Flow - is exceeded, then wrapped to the next line. - \o Flow.TopToBottom - Items are positioned next to each - other from top to bottom until the height of the Flow is exceeded, - then wrapped to the next column. - \endlist -*/ -QQuickFlow::Flow QQuickFlow::flow() const -{ - Q_D(const QQuickFlow); - return d->flow; -} - -void QQuickFlow::setFlow(Flow flow) -{ - Q_D(QQuickFlow); - if (d->flow != flow) { - d->flow = flow; - prePositioning(); - emit flowChanged(); - } -} - -/*! - \qmlproperty enumeration QtQuick2::Flow::layoutDirection - - This property holds the layout direction of the layout. - - Possible values are: - - \list - \o Qt.LeftToRight (default) - Items are positioned from the top to bottom, - and left to right. The flow direction is dependent on the - \l Flow::flow property. - \o Qt.RightToLeft - Items are positioned from the top to bottom, - and right to left. The flow direction is dependent on the - \l Flow::flow property. - \endlist - - \sa Grid::layoutDirection, Row::layoutDirection, {declarative/righttoleft/layoutdirection}{Layout directions example} -*/ - -Qt::LayoutDirection QQuickFlow::layoutDirection() const -{ - Q_D(const QQuickFlow); - return d->layoutDirection; -} - -void QQuickFlow::setLayoutDirection(Qt::LayoutDirection layoutDirection) -{ - Q_D(QQuickFlow); - if (d->layoutDirection != layoutDirection) { - d->layoutDirection = layoutDirection; - prePositioning(); - emit layoutDirectionChanged(); - emit effectiveLayoutDirectionChanged(); - } -} - -/*! - \qmlproperty enumeration QtQuick2::Flow::effectiveLayoutDirection - This property holds the effective layout direction of the flow positioner. - - When using the attached property \l {LayoutMirroring::enabled}{LayoutMirroring::enabled} for locale layouts, - the visual layout direction of the grid positioner will be mirrored. However, the - property \l {Flow::layoutDirection}{layoutDirection} will remain unchanged. - - \sa Flow::layoutDirection, {LayoutMirroring}{LayoutMirroring} -*/ - -Qt::LayoutDirection QQuickFlow::effectiveLayoutDirection() const -{ - return QQuickBasePositionerPrivate::getEffectiveLayoutDirection(this); -} - -void QQuickFlow::doPositioning(QSizeF *contentSize) -{ - Q_D(QQuickFlow); - - int hoffset = 0; - int voffset = 0; - int linemax = 0; - QList hoffsets; - - for (int i = 0; i < positionedItems.count(); ++i) { - const PositionedItem &child = positionedItems.at(i); - if (!child.item || !child.isVisible) - continue; - - if (d->flow == LeftToRight) { - if (widthValid() && hoffset && hoffset + child.item->width() > width()) { - hoffset = 0; - voffset += linemax + spacing(); - linemax = 0; - } - } else { - if (heightValid() && voffset && voffset + child.item->height() > height()) { - voffset = 0; - hoffset += linemax + spacing(); - linemax = 0; - } - } - - if (d->isLeftToRight()) { - if (child.item->x() != hoffset) - positionX(hoffset, child); - } else { - hoffsets << hoffset; - } - if (child.item->y() != voffset) - positionY(voffset, child); - - contentSize->setWidth(qMax(contentSize->width(), hoffset + child.item->width())); - contentSize->setHeight(qMax(contentSize->height(), voffset + child.item->height())); - - if (d->flow == LeftToRight) { - hoffset += child.item->width(); - hoffset += spacing(); - linemax = qMax(linemax, qCeil(child.item->height())); - } else { - voffset += child.item->height(); - voffset += spacing(); - linemax = qMax(linemax, qCeil(child.item->width())); - } - } - if (d->isLeftToRight()) - return; - - int end; - if (widthValid()) - end = width(); - else - end = contentSize->width(); - int acc = 0; - for (int i = 0; i < positionedItems.count(); ++i) { - const PositionedItem &child = positionedItems.at(i); - if (!child.item || !child.isVisible) - continue; - hoffset = end - hoffsets[acc++] - child.item->width(); - if (child.item->x() != hoffset) - positionX(hoffset, child); - } -} - -void QQuickFlow::reportConflictingAnchors() -{ - Q_D(QQuickFlow); - for (int ii = 0; ii < positionedItems.count(); ++ii) { - const PositionedItem &child = positionedItems.at(ii); - if (child.item) { - QQuickAnchors *anchors = QQuickItemPrivate::get(static_cast(child.item))->_anchors; - if (anchors && (anchors->usedAnchors() || anchors->fill() || anchors->centerIn())) { - d->anchorConflict = true; - break; - } - } - } - if (d->anchorConflict) - qmlInfo(this) << "Cannot specify anchors for items inside Flow"; -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickpositioners_p.h b/src/declarative/items/qquickpositioners_p.h deleted file mode 100644 index b8e8879205..0000000000 --- a/src/declarative/items/qquickpositioners_p.h +++ /dev/null @@ -1,295 +0,0 @@ -// Commit: 2c7cab4172f1acc86fd49345a2847417e162f2c3 -/**************************************************************************** -** -** 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$ -** 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 QQUICKPOSITIONERS_P_H -#define QQUICKPOSITIONERS_P_H - -#include "qquickimplicitsizeitem_p.h" - -#include -#include - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickBasePositionerPrivate; - -class QQuickPositionerAttached : public QObject -{ - Q_OBJECT - -public: - QQuickPositionerAttached(QObject *parent); - - Q_PROPERTY(int index READ index NOTIFY indexChanged) - Q_PROPERTY(bool isFirstItem READ isFirstItem NOTIFY isFirstItemChanged) - Q_PROPERTY(bool isLastItem READ isLastItem NOTIFY isLastItemChanged) - - int index() const { return m_index; } - void setIndex(int index); - - bool isFirstItem() const { return m_isFirstItem; } - void setIsFirstItem(bool isFirstItem); - - bool isLastItem() const { return m_isLastItem; } - void setIsLastItem(bool isLastItem); - -Q_SIGNALS: - void indexChanged(); - void isFirstItemChanged(); - void isLastItemChanged(); - -private: - int m_index; - bool m_isFirstItem; - bool m_isLastItem; -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QQuickBasePositioner : public QQuickImplicitSizeItem -{ - Q_OBJECT - - Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) - Q_PROPERTY(QDeclarativeTransition *move READ move WRITE setMove NOTIFY moveChanged) - Q_PROPERTY(QDeclarativeTransition *add READ add WRITE setAdd NOTIFY addChanged) -public: - enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 }; - QQuickBasePositioner(PositionerType, QQuickItem *parent); - ~QQuickBasePositioner(); - - int spacing() const; - void setSpacing(int); - - QDeclarativeTransition *move() const; - void setMove(QDeclarativeTransition *); - - QDeclarativeTransition *add() const; - void setAdd(QDeclarativeTransition *); - - static QQuickPositionerAttached *qmlAttachedProperties(QObject *obj); - - void updateAttachedProperties(QQuickPositionerAttached *specificProperty = 0, QQuickItem *specificPropertyOwner = 0) const; - -protected: - QQuickBasePositioner(QQuickBasePositionerPrivate &dd, PositionerType at, QQuickItem *parent); - virtual void componentComplete(); - virtual void itemChange(ItemChange, const ItemChangeData &); - void finishApplyTransitions(); - - virtual void updatePolish(); - -Q_SIGNALS: - void spacingChanged(); - void moveChanged(); - void addChanged(); - -protected Q_SLOTS: - void prePositioning(); - -protected: - virtual void doPositioning(QSizeF *contentSize)=0; - virtual void reportConflictingAnchors()=0; - class PositionedItem { - public : - PositionedItem(QQuickItem *i) : item(i), isNew(false), isVisible(true) {} - bool operator==(const PositionedItem &other) const { return other.item == item; } - QQuickItem *item; - bool isNew; - bool isVisible; - }; - - QPODVector positionedItems; - void positionX(int,const PositionedItem &target); - void positionY(int,const PositionedItem &target); - -private: - Q_DISABLE_COPY(QQuickBasePositioner) - Q_DECLARE_PRIVATE(QQuickBasePositioner) -}; - -class Q_AUTOTEST_EXPORT QQuickColumn : public QQuickBasePositioner -{ - Q_OBJECT -public: - QQuickColumn(QQuickItem *parent=0); - -protected: - virtual void doPositioning(QSizeF *contentSize); - virtual void reportConflictingAnchors(); -private: - Q_DISABLE_COPY(QQuickColumn) -}; - -class Q_AUTOTEST_EXPORT QQuickRow: public QQuickBasePositioner -{ - Q_OBJECT - Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged) - Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged) -public: - QQuickRow(QQuickItem *parent=0); - - Qt::LayoutDirection layoutDirection() const; - void setLayoutDirection (Qt::LayoutDirection); - Qt::LayoutDirection effectiveLayoutDirection() const; - -Q_SIGNALS: - void layoutDirectionChanged(); - void effectiveLayoutDirectionChanged(); - -protected: - virtual void doPositioning(QSizeF *contentSize); - virtual void reportConflictingAnchors(); -private: - Q_DISABLE_COPY(QQuickRow) -}; - -class Q_AUTOTEST_EXPORT QQuickGrid : public QQuickBasePositioner -{ - Q_OBJECT - Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged) - Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged) - Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged) - Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged) - Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) - Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged) - Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged) - -public: - QQuickGrid(QQuickItem *parent=0); - - int rows() const {return m_rows;} - void setRows(const int rows); - - int columns() const {return m_columns;} - void setColumns(const int columns); - - int rowSpacing() const { return m_rowSpacing; } - void setRowSpacing(int); - - int columnSpacing() const { return m_columnSpacing; } - void setColumnSpacing(int); - - Q_ENUMS(Flow) - enum Flow { LeftToRight, TopToBottom }; - Flow flow() const; - void setFlow(Flow); - - Qt::LayoutDirection layoutDirection() const; - void setLayoutDirection (Qt::LayoutDirection); - Qt::LayoutDirection effectiveLayoutDirection() const; - -Q_SIGNALS: - void rowsChanged(); - void columnsChanged(); - void flowChanged(); - void layoutDirectionChanged(); - void effectiveLayoutDirectionChanged(); - void rowSpacingChanged(); - void columnSpacingChanged(); - -protected: - virtual void doPositioning(QSizeF *contentSize); - virtual void reportConflictingAnchors(); - -private: - int m_rows; - int m_columns; - int m_rowSpacing; - int m_columnSpacing; - Flow m_flow; - Q_DISABLE_COPY(QQuickGrid) -}; - -class QQuickFlowPrivate; -class Q_AUTOTEST_EXPORT QQuickFlow: public QQuickBasePositioner -{ - Q_OBJECT - Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) - Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged) - Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged) -public: - QQuickFlow(QQuickItem *parent=0); - - Q_ENUMS(Flow) - enum Flow { LeftToRight, TopToBottom }; - Flow flow() const; - void setFlow(Flow); - - Qt::LayoutDirection layoutDirection() const; - void setLayoutDirection (Qt::LayoutDirection); - Qt::LayoutDirection effectiveLayoutDirection() const; - -Q_SIGNALS: - void flowChanged(); - void layoutDirectionChanged(); - void effectiveLayoutDirectionChanged(); - -protected: - virtual void doPositioning(QSizeF *contentSize); - virtual void reportConflictingAnchors(); -protected: - QQuickFlow(QQuickFlowPrivate &dd, QQuickItem *parent); -private: - Q_DISABLE_COPY(QQuickFlow) - Q_DECLARE_PRIVATE(QQuickFlow) -}; - - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickColumn) -QML_DECLARE_TYPE(QQuickRow) -QML_DECLARE_TYPE(QQuickGrid) -QML_DECLARE_TYPE(QQuickFlow) - -QML_DECLARE_TYPE(QQuickBasePositioner) -QML_DECLARE_TYPEINFO(QQuickBasePositioner, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER - -#endif // QQUICKPOSITIONERS_P_H diff --git a/src/declarative/items/qquickpositioners_p_p.h b/src/declarative/items/qquickpositioners_p_p.h deleted file mode 100644 index 86c6c74ba6..0000000000 --- a/src/declarative/items/qquickpositioners_p_p.h +++ /dev/null @@ -1,164 +0,0 @@ -// Commit: 2c7cab4172f1acc86fd49345a2847417e162f2c3 -/**************************************************************************** -** -** 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$ -** 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 QQUICKPOSITIONERS_P_P_H -#define QQUICKPOSITIONERS_P_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 "qquickpositioners_p.h" -#include "qquickimplicitsizeitem_p_p.h" - -#include -#include -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickBasePositionerPrivate : public QQuickImplicitSizeItemPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickBasePositioner) - -public: - QQuickBasePositionerPrivate() - : spacing(0), type(QQuickBasePositioner::None) - , moveTransition(0), addTransition(0), positioningDirty(false) - , doingPositioning(false), anchorConflict(false), layoutDirection(Qt::LeftToRight) - { - } - - void init(QQuickBasePositioner::PositionerType at) - { - type = at; - childrenDoNotOverlap = true; - } - - int spacing; - - QQuickBasePositioner::PositionerType type; - QDeclarativeTransition *moveTransition; - QDeclarativeTransition *addTransition; - QDeclarativeStateOperation::ActionList addActions; - QDeclarativeStateOperation::ActionList moveActions; - QDeclarativeTransitionManager addTransitionManager; - QDeclarativeTransitionManager moveTransitionManager; - - void watchChanges(QQuickItem *other); - void unwatchChanges(QQuickItem* other); - void setPositioningDirty() { - Q_Q(QQuickBasePositioner); - if (!positioningDirty) { - positioningDirty = true; - q->polish(); - } - } - - bool positioningDirty : 1; - bool doingPositioning : 1; - bool anchorConflict : 1; - - Qt::LayoutDirection layoutDirection; - - void mirrorChange() { - if (type != QQuickBasePositioner::Vertical) - setPositioningDirty(); - } - bool isLeftToRight() const { - if (type == QQuickBasePositioner::Vertical) - return true; - else - return effectiveLayoutMirror ? layoutDirection == Qt::RightToLeft : layoutDirection == Qt::LeftToRight; - } - - virtual void itemSiblingOrderChanged(QQuickItem* other) - { - Q_UNUSED(other); - setPositioningDirty(); - } - - void itemGeometryChanged(QQuickItem *, const QRectF &newGeometry, const QRectF &oldGeometry) - { - if (newGeometry.size() != oldGeometry.size()) - setPositioningDirty(); - } - - virtual void itemVisibilityChanged(QQuickItem *) - { - setPositioningDirty(); - } - - void itemDestroyed(QQuickItem *item) - { - Q_Q(QQuickBasePositioner); - q->positionedItems.removeOne(QQuickBasePositioner::PositionedItem(item)); - } - - static Qt::LayoutDirection getLayoutDirection(const QQuickBasePositioner *positioner) - { - return positioner->d_func()->layoutDirection; - } - - static Qt::LayoutDirection getEffectiveLayoutDirection(const QQuickBasePositioner *positioner) - { - if (positioner->d_func()->effectiveLayoutMirror) - return positioner->d_func()->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft; - else - return positioner->d_func()->layoutDirection; - } -}; - -QT_END_NAMESPACE - -#endif // QQUICKPOSITIONERS_P_P_H diff --git a/src/declarative/items/qquickrectangle.cpp b/src/declarative/items/qquickrectangle.cpp deleted file mode 100644 index c3cbaaa00e..0000000000 --- a/src/declarative/items/qquickrectangle.cpp +++ /dev/null @@ -1,556 +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 QtDeclarative module 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 "qquickrectangle_p.h" -#include "qquickrectangle_p_p.h" - -#include -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -// XXX todo - should we change rectangle to draw entirely within its width/height? -/*! - \internal - \class QQuickPen - \brief The QQuickPen class provides a pen used for drawing rectangle borders on a QQuickView. - - By default, the pen is invalid and nothing is drawn. You must either set a color (then the default - width is 1) or a width (then the default color is black). - - A width of 1 indicates is a single-pixel line on the border of the item being painted. - - Example: - \qml - Rectangle { - border.width: 2 - border.color: "red" - } - \endqml -*/ - -QQuickPen::QQuickPen(QObject *parent) - : QObject(parent) - , m_width(1) - , m_color("#000000") - , m_aligned(true) - , m_valid(false) -{ -} - -qreal QQuickPen::width() const -{ - return m_width; -} - -void QQuickPen::setWidth(qreal w) -{ - if (m_width == w && m_valid) - return; - - m_width = w; - m_valid = m_color.alpha() && (qRound(m_width) >= 1 || (!m_aligned && m_width > 0)); - emit penChanged(); -} - -QColor QQuickPen::color() const -{ - return m_color; -} - -void QQuickPen::setColor(const QColor &c) -{ - m_color = c; - m_valid = m_color.alpha() && (qRound(m_width) >= 1 || (!m_aligned && m_width > 0)); - emit penChanged(); -} - -bool QQuickPen::aligned() const -{ - return m_aligned; -} - -void QQuickPen::setAligned(bool aligned) -{ - if (aligned == m_aligned) - return; - m_aligned = aligned; - m_valid = m_color.alpha() && (qRound(m_width) >= 1 || (!m_aligned && m_width > 0)); - emit penChanged(); -} - -bool QQuickPen::isValid() const -{ - return m_valid; -} - -/*! - \qmlclass GradientStop QQuickGradientStop - \inqmlmodule QtQuick 2 - \ingroup qml-basic-visual-elements - \brief The GradientStop item defines the color at a position in a Gradient. - - \sa Gradient -*/ - -/*! - \qmlproperty real QtQuick2::GradientStop::position - \qmlproperty color QtQuick2::GradientStop::color - - The position and color properties describe the color used at a given - position in a gradient, as represented by a gradient stop. - - The default position is 0.0; the default color is black. - - \sa Gradient -*/ -QQuickGradientStop::QQuickGradientStop(QObject *parent) - : QObject(parent) -{ -} - -qreal QQuickGradientStop::position() const -{ - return m_position; -} - -void QQuickGradientStop::setPosition(qreal position) -{ - m_position = position; updateGradient(); -} - -QColor QQuickGradientStop::color() const -{ - return m_color; -} - -void QQuickGradientStop::setColor(const QColor &color) -{ - m_color = color; updateGradient(); -} - -void QQuickGradientStop::updateGradient() -{ - if (QQuickGradient *grad = qobject_cast(parent())) - grad->doUpdate(); -} - -/*! - \qmlclass Gradient QQuickGradient - \inqmlmodule QtQuick 2 - \ingroup qml-basic-visual-elements - \brief The Gradient item defines a gradient fill. - - A gradient is defined by two or more colors, which will be blended seamlessly. - - The colors are specified as a set of GradientStop child items, each of - which defines a position on the gradient from 0.0 to 1.0 and a color. - The position of each GradientStop is defined by setting its - \l{GradientStop::}{position} property; its color is defined using its - \l{GradientStop::}{color} property. - - A gradient without any gradient stops is rendered as a solid white fill. - - Note that this item is not a visual representation of a gradient. To display a - gradient, use a visual element (like \l Rectangle) which supports the use - of gradients. - - \section1 Example Usage - - \div {class="float-right"} - \inlineimage qml-gradient.png - \enddiv - - The following example declares a \l Rectangle item with a gradient starting - with red, blending to yellow at one third of the height of the rectangle, - and ending with green: - - \snippet doc/src/snippets/declarative/gradient.qml code - - \clearfloat - \section1 Performance and Limitations - - Calculating gradients can be computationally expensive compared to the use - of solid color fills or images. Consider using gradients for static items - in a user interface. - - In Qt 4.7, only vertical, linear gradients can be applied to items. If you - need to apply different orientations of gradients, a combination of rotation - and clipping will need to be applied to the relevant items. This can - introduce additional performance requirements for your application. - - The use of animations involving gradient stops may not give the desired - result. An alternative way to animate gradients is to use pre-generated - images or SVG drawings containing gradients. - - \sa GradientStop -*/ - -/*! - \qmlproperty list QtQuick2::Gradient::stops - \default - - This property holds the gradient stops describing the gradient. - - By default, this property contains an empty list. - - To set the gradient stops, define them as children of the Gradient element. -*/ -QQuickGradient::QQuickGradient(QObject *parent) -: QObject(parent), m_gradient(0) -{ -} - -QQuickGradient::~QQuickGradient() -{ - delete m_gradient; -} - -QDeclarativeListProperty QQuickGradient::stops() -{ - return QDeclarativeListProperty(this, m_stops); -} - -const QGradient *QQuickGradient::gradient() const -{ - if (!m_gradient && !m_stops.isEmpty()) { - m_gradient = new QLinearGradient(0,0,0,1.0); - for (int i = 0; i < m_stops.count(); ++i) { - const QQuickGradientStop *stop = m_stops.at(i); - m_gradient->setCoordinateMode(QGradient::ObjectBoundingMode); - m_gradient->setColorAt(stop->position(), stop->color()); - } - } - - return m_gradient; -} - -void QQuickGradient::doUpdate() -{ - delete m_gradient; - m_gradient = 0; - emit updated(); -} - -int QQuickRectanglePrivate::doUpdateSlotIdx = -1; - -/*! - \qmlclass Rectangle QQuickRectangle - \inqmlmodule QtQuick 2 - \ingroup qml-basic-visual-elements - \brief The Rectangle item provides a filled rectangle with an optional border. - \inherits Item - - Rectangle items are used to fill areas with solid color or gradients, and are - often used to hold other items. - - \section1 Appearance - - Each Rectangle item is painted using either a solid fill color, specified using - the \l color property, or a gradient, defined using a Gradient element and set - using the \l gradient property. If both a color and a gradient are specified, - the gradient is used. - - You can add an optional border to a rectangle with its own color and thickness - by setting the \l border.color and \l border.width properties. - - You can also create rounded rectangles using the \l radius property. Since this - introduces curved edges to the corners of a rectangle, it may be appropriate to - set the \l smooth property to improve its appearance. - - \section1 Example Usage - - \div {class="float-right"} - \inlineimage declarative-rect.png - \enddiv - - The following example shows the effects of some of the common properties on a - Rectangle item, which in this case is used to create a square: - - \snippet doc/src/snippets/declarative/rectangle/rectangle.qml document - - \clearfloat - \section1 Performance - - Using the \l smooth property improves the appearance of a rounded rectangle at - the cost of rendering performance. You should consider unsetting this property - for rectangles in motion, and only set it when they are stationary. - - \sa Image -*/ - -QQuickRectangle::QQuickRectangle(QQuickItem *parent) -: QQuickItem(*(new QQuickRectanglePrivate), parent) -{ - setFlag(ItemHasContents); -} - -void QQuickRectangle::doUpdate() -{ - Q_D(QQuickRectangle); - qreal penMargin = 0; - qreal penOffset = 0; - if (d->pen && d->pen->isValid()) { - if (d->pen->aligned()) { - const int pw = qRound(d->pen->width()); - penMargin = qreal(0.5) * pw; - penOffset = (pw & 1) * qreal(0.5); - } else { - penMargin = qreal(0.5) * d->pen->width(); - } - } - if (penMargin != d->penMargin || penOffset != d->penOffset) { - d->penMargin = penMargin; - d->penOffset = penOffset; - d->dirty(QQuickItemPrivate::Size); // update clip - } - update(); -} - -/*! - \qmlproperty int QtQuick2::Rectangle::border.width - \qmlproperty color QtQuick2::Rectangle::border.color - - The width and color used to draw the border of the rectangle. - - A width of 1 creates a thin line. For no line, use a width of 0 or a transparent color. - - \note The width of the rectangle's border does not affect the geometry of the - rectangle itself or its position relative to other items if anchors are used. - - If \c border.width is an odd number, the rectangle is painted at a half-pixel offset to retain - border smoothness. Also, the border is rendered evenly on either side of the - rectangle's boundaries, and the spare pixel is rendered to the right and below the - rectangle (as documented for QRect rendering). This can cause unintended effects if - \c border.width is 1 and the rectangle is \l{Item::clip}{clipped} by a parent item: - - \div {class="float-right"} - \inlineimage rect-border-width.png - \enddiv - - \snippet doc/src/snippets/declarative/rectangle/rect-border-width.qml 0 - - \clearfloat - Here, the innermost rectangle's border is clipped on the bottom and right edges by its - parent. To avoid this, the border width can be set to two instead of one. -*/ -QQuickPen *QQuickRectangle::border() -{ - Q_D(QQuickRectangle); - return d->getPen(); -} - -/*! - \qmlproperty Gradient QtQuick2::Rectangle::gradient - - The gradient to use to fill the rectangle. - - This property allows for the construction of simple vertical gradients. - Other gradients may by formed by adding rotation to the rectangle. - - \div {class="float-left"} - \inlineimage declarative-rect_gradient.png - \enddiv - - \snippet doc/src/snippets/declarative/rectangle/rectangle-gradient.qml rectangles - \clearfloat - - If both a gradient and a color are specified, the gradient will be used. - - \sa Gradient, color -*/ -QQuickGradient *QQuickRectangle::gradient() const -{ - Q_D(const QQuickRectangle); - return d->gradient; -} - -void QQuickRectangle::setGradient(QQuickGradient *gradient) -{ - Q_D(QQuickRectangle); - if (d->gradient == gradient) - return; - static int updatedSignalIdx = -1; - if (updatedSignalIdx < 0) - updatedSignalIdx = QQuickGradient::staticMetaObject.indexOfSignal("updated()"); - if (d->doUpdateSlotIdx < 0) - d->doUpdateSlotIdx = QQuickRectangle::staticMetaObject.indexOfSlot("doUpdate()"); - if (d->gradient) - QMetaObject::disconnect(d->gradient, updatedSignalIdx, this, d->doUpdateSlotIdx); - d->gradient = gradient; - if (d->gradient) - QMetaObject::connect(d->gradient, updatedSignalIdx, this, d->doUpdateSlotIdx); - update(); -} - -/*! - \qmlproperty real QtQuick2::Rectangle::radius - This property holds the corner radius used to draw a rounded rectangle. - - If radius is non-zero, the rectangle will be painted as a rounded rectangle, otherwise it will be - painted as a normal rectangle. The same radius is used by all 4 corners; there is currently - no way to specify different radii for different corners. -*/ -qreal QQuickRectangle::radius() const -{ - Q_D(const QQuickRectangle); - return d->radius; -} - -void QQuickRectangle::setRadius(qreal radius) -{ - Q_D(QQuickRectangle); - if (d->radius == radius) - return; - - d->radius = radius; - update(); - emit radiusChanged(); -} - -/*! - \qmlproperty color QtQuick2::Rectangle::color - This property holds the color used to fill the rectangle. - - The default color is white. - - \div {class="float-right"} - \inlineimage rect-color.png - \enddiv - - The following example shows rectangles with colors specified - using hexadecimal and named color notation: - - \snippet doc/src/snippets/declarative/rectangle/rectangle-colors.qml rectangles - - \clearfloat - If both a gradient and a color are specified, the gradient will be used. - - \sa gradient -*/ -QColor QQuickRectangle::color() const -{ - Q_D(const QQuickRectangle); - return d->color; -} - -void QQuickRectangle::setColor(const QColor &c) -{ - Q_D(QQuickRectangle); - if (d->color == c) - return; - - d->color = c; - update(); - emit colorChanged(); -} - -QSGNode *QQuickRectangle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) -{ - Q_UNUSED(data); - Q_D(QQuickRectangle); - - if (width() <= 0 || height() <= 0 - || (d->color.alpha() == 0 && (!d->pen || d->pen->width() == 0 || d->pen->color().alpha() == 0))) { - delete oldNode; - return 0; - } - - QSGRectangleNode *rectangle = static_cast(oldNode); - if (!rectangle) rectangle = d->sceneGraphContext()->createRectangleNode(); - - rectangle->setRect(QRectF(0, 0, width(), height())); - rectangle->setColor(d->color); - - if (d->pen && d->pen->isValid()) { - rectangle->setPenColor(d->pen->color()); - rectangle->setPenWidth(d->pen->width()); - rectangle->setAligned(d->pen->aligned()); - } else { - rectangle->setPenWidth(0); - } - - rectangle->setRadius(d->radius); - - QGradientStops stops; - if (d->gradient) { - QList qxstops = d->gradient->m_stops; - for (int i = 0; i < qxstops.size(); ++i){ - int j = 0; - while (j < stops.size() && stops.at(j).first < qxstops[i]->position()) - j++; - stops.insert(j, QGradientStop(qxstops.at(i)->position(), qxstops.at(i)->color())); - } - } - rectangle->setGradientStops(stops); - - rectangle->update(); - - return rectangle; -} -/*! - \qmlproperty bool QtQuick2::Rectangle::smooth - - Set this property if you want the item to be smoothly scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If - the item is displayed at its natural size, this property has no visual or - performance effect. - - \note Generally scaling artifacts are only visible if the item is stationary on - the screen. A common pattern when animating an item is to disable smooth - filtering at the beginning of the animation and reenable it at the conclusion. - - \image rect-smooth.png - On this image, smooth is turned off for the top half and on for the bottom half. -*/ - -QRectF QQuickRectangle::boundingRect() const -{ - Q_D(const QQuickRectangle); - return QRectF(d->penOffset - d->penMargin, d->penOffset - d->penMargin, - d->width + 2 * d->penMargin, d->height + 2 * d->penMargin); -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickrectangle_p.h b/src/declarative/items/qquickrectangle_p.h deleted file mode 100644 index 838b944c62..0000000000 --- a/src/declarative/items/qquickrectangle_p.h +++ /dev/null @@ -1,189 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKRECTANGLE_P_H -#define QQUICKRECTANGLE_P_H - -#include "qquickitem.h" - -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class Q_DECLARATIVE_PRIVATE_EXPORT QQuickPen : public QObject -{ - Q_OBJECT - - Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY penChanged) - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged) - Q_PROPERTY(bool aligned READ aligned WRITE setAligned NOTIFY penChanged) -public: - QQuickPen(QObject *parent=0); - - qreal width() const; - void setWidth(qreal w); - - QColor color() const; - void setColor(const QColor &c); - - bool aligned() const; - void setAligned(bool aligned); - - bool isValid() const; - -Q_SIGNALS: - void penChanged(); - -private: - qreal m_width; - QColor m_color; - bool m_aligned : 1; - bool m_valid : 1; -}; - -class Q_AUTOTEST_EXPORT QQuickGradientStop : public QObject -{ - Q_OBJECT - - Q_PROPERTY(qreal position READ position WRITE setPosition) - Q_PROPERTY(QColor color READ color WRITE setColor) - -public: - QQuickGradientStop(QObject *parent=0); - - qreal position() const; - void setPosition(qreal position); - - QColor color() const; - void setColor(const QColor &color); - -private: - void updateGradient(); - -private: - qreal m_position; - QColor m_color; -}; - -class Q_AUTOTEST_EXPORT QQuickGradient : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeListProperty stops READ stops) - Q_CLASSINFO("DefaultProperty", "stops") - -public: - QQuickGradient(QObject *parent=0); - ~QQuickGradient(); - - QDeclarativeListProperty stops(); - - const QGradient *gradient() const; - -Q_SIGNALS: - void updated(); - -private: - void doUpdate(); - -private: - QList m_stops; - mutable QGradient *m_gradient; - friend class QQuickRectangle; - friend class QQuickGradientStop; -}; - -class QQuickRectanglePrivate; -class Q_DECLARATIVE_PRIVATE_EXPORT QQuickRectangle : public QQuickItem -{ - Q_OBJECT - - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) - Q_PROPERTY(QQuickGradient *gradient READ gradient WRITE setGradient) - Q_PROPERTY(QQuickPen * border READ border CONSTANT) - Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) -public: - QQuickRectangle(QQuickItem *parent=0); - - QColor color() const; - void setColor(const QColor &); - - QQuickPen *border(); - - QQuickGradient *gradient() const; - void setGradient(QQuickGradient *gradient); - - qreal radius() const; - void setRadius(qreal radius); - - virtual QRectF boundingRect() const; - -Q_SIGNALS: - void colorChanged(); - void radiusChanged(); - -protected: - virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - -private Q_SLOTS: - void doUpdate(); - -private: - Q_DISABLE_COPY(QQuickRectangle) - Q_DECLARE_PRIVATE(QQuickRectangle) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickPen) -QML_DECLARE_TYPE(QQuickGradientStop) -QML_DECLARE_TYPE(QQuickGradient) -QML_DECLARE_TYPE(QQuickRectangle) - -QT_END_HEADER - -#endif // QQUICKRECTANGLE_P_H diff --git a/src/declarative/items/qquickrectangle_p_p.h b/src/declarative/items/qquickrectangle_p_p.h deleted file mode 100644 index 93140ce75a..0000000000 --- a/src/declarative/items/qquickrectangle_p_p.h +++ /dev/null @@ -1,103 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKRECTANGLE_P_P_H -#define QQUICKRECTANGLE_P_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 "qquickitem_p.h" - -QT_BEGIN_NAMESPACE - -class QQuickGradient; -class QQuickRectangle; -class QQuickRectanglePrivate : public QQuickItemPrivate -{ - Q_DECLARE_PUBLIC(QQuickRectangle) - -public: - QQuickRectanglePrivate() : - color(Qt::white), gradient(0), pen(0), radius(0), penMargin(0), penOffset(0) - { - } - - ~QQuickRectanglePrivate() - { - delete pen; - } - - QColor color; - QQuickGradient *gradient; - QQuickPen *pen; - qreal radius; - qreal penMargin; - qreal penOffset; - static int doUpdateSlotIdx; - - QQuickPen *getPen() { - if (!pen) { - Q_Q(QQuickRectangle); - pen = new QQuickPen; - static int penChangedSignalIdx = -1; - if (penChangedSignalIdx < 0) - penChangedSignalIdx = QQuickPen::staticMetaObject.indexOfSignal("penChanged()"); - if (doUpdateSlotIdx < 0) - doUpdateSlotIdx = QQuickRectangle::staticMetaObject.indexOfSlot("doUpdate()"); - QMetaObject::connect(pen, penChangedSignalIdx, q, doUpdateSlotIdx); - } - return pen; - } -}; - -QT_END_NAMESPACE - -#endif // QQUICKRECTANGLE_P_P_H diff --git a/src/declarative/items/qquickrepeater.cpp b/src/declarative/items/qquickrepeater.cpp deleted file mode 100644 index efa83eec38..0000000000 --- a/src/declarative/items/qquickrepeater.cpp +++ /dev/null @@ -1,476 +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 QtDeclarative module 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 "qquickrepeater_p.h" -#include "qquickrepeater_p_p.h" -#include "qquickvisualdatamodel_p.h" - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QQuickRepeaterPrivate::QQuickRepeaterPrivate() - : model(0), ownModel(false), inRequest(false), itemCount(0), createFrom(-1) -{ -} - -QQuickRepeaterPrivate::~QQuickRepeaterPrivate() -{ - if (ownModel) - delete model; -} - -/*! - \qmlclass Repeater QQuickRepeater - \inqmlmodule QtQuick 2 - \ingroup qml-utility-elements - \inherits Item - - \brief The Repeater element allows you to repeat an Item-based component using a model. - - The Repeater element is used to create a large number of - similar items. Like other view elements, a Repeater has a \l model and a \l delegate: - for each entry in the model, the delegate is instantiated - in a context seeded with data from the model. A Repeater item is usually - enclosed in a positioner element such as \l Row or \l Column to visually - position the multiple delegate items created by the Repeater. - - The following Repeater creates three instances of a \l Rectangle item within - a \l Row: - - \snippet doc/src/snippets/declarative/repeaters/repeater.qml import - \codeline - \snippet doc/src/snippets/declarative/repeaters/repeater.qml simple - - \image repeater-simple.png - - A Repeater's \l model can be any of the supported \l {qmlmodels}{data models}. - Additionally, like delegates for other views, a Repeater delegate can access - its index within the repeater, as well as the model data relevant to the - delegate. See the \l delegate property documentation for details. - - Items instantiated by the Repeater are inserted, in order, as - children of the Repeater's parent. The insertion starts immediately after - the repeater's position in its parent stacking list. This allows - a Repeater to be used inside a layout. For example, the following Repeater's - items are stacked between a red rectangle and a blue rectangle: - - \snippet doc/src/snippets/declarative/repeaters/repeater.qml layout - - \image repeater.png - - - \note A Repeater item owns all items it instantiates. Removing or dynamically destroying - an item created by a Repeater results in unpredictable behavior. - - - \section2 Considerations when using Repeater - - The Repeater element creates all of its delegate items when the repeater is first - created. This can be inefficient if there are a large number of delegate items and - not all of the items are required to be visible at the same time. If this is the case, - consider using other view elements like ListView (which only creates delegate items - when they are scrolled into view) or use the \l {Dynamic Object Creation} methods to - create items as they are required. - - Also, note that Repeater is \l {Item}-based, and can only repeat \l {Item}-derived objects. - For example, it cannot be used to repeat QtObjects: - \badcode - Item { - //XXX does not work! Can't repeat QtObject as it doesn't derive from Item. - Repeater { - model: 10 - QtObject {} - } - } - \endcode - */ - -/*! - \qmlsignal QtQuick2::Repeater::onItemAdded(int index, Item item) - - This handler is called when an item is added to the repeater. The \a index - parameter holds the index at which the item has been inserted within the - repeater, and the \a item parameter holds the \l Item that has been added. -*/ - -/*! - \qmlsignal QtQuick2::Repeater::onItemRemoved(int index, Item item) - - This handler is called when an item is removed from the repeater. The \a index - parameter holds the index at which the item was removed from the repeater, - and the \a item parameter holds the \l Item that was removed. - - Do not keep a reference to \a item if it was created by this repeater, as - in these cases it will be deleted shortly after the handler is called. -*/ -QQuickRepeater::QQuickRepeater(QQuickItem *parent) - : QQuickItem(*(new QQuickRepeaterPrivate), parent) -{ -} - -QQuickRepeater::~QQuickRepeater() -{ -} - -/*! - \qmlproperty any QtQuick2::Repeater::model - - The model providing data for the repeater. - - This property can be set to any of the supported \l {qmlmodels}{data models}: - - \list - \o A number that indicates the number of delegates to be created by the repeater - \o A model (e.g. a ListModel item, or a QAbstractItemModel subclass) - \o A string list - \o An object list - \endlist - - The type of model affects the properties that are exposed to the \l delegate. - - \sa {qmlmodels}{Data Models} -*/ -QVariant QQuickRepeater::model() const -{ - Q_D(const QQuickRepeater); - return d->dataSource; -} - -void QQuickRepeater::setModel(const QVariant &model) -{ - Q_D(QQuickRepeater); - if (d->dataSource == model) - return; - - clear(); - if (d->model) { - disconnect(d->model, SIGNAL(modelUpdated(QDeclarativeChangeSet,bool)), - this, SLOT(modelUpdated(QDeclarativeChangeSet,bool))); - disconnect(d->model, SIGNAL(createdItem(int,QQuickItem*)), this, SLOT(createdItem(int,QQuickItem*))); - disconnect(d->model, SIGNAL(initItem(int,QQuickItem*)), this, SLOT(initItem(int,QQuickItem*))); -// disconnect(d->model, SIGNAL(destroyingItem(QQuickItem*)), this, SLOT(destroyingItem(QQuickItem*))); - } - d->dataSource = model; - QObject *object = qvariant_cast(model); - QQuickVisualModel *vim = 0; - if (object && (vim = qobject_cast(object))) { - if (d->ownModel) { - delete d->model; - d->ownModel = false; - } - d->model = vim; - } else { - if (!d->ownModel) { - d->model = new QQuickVisualDataModel(qmlContext(this)); - d->ownModel = true; - if (isComponentComplete()) - static_cast(d->model)->componentComplete(); - } - if (QQuickVisualDataModel *dataModel = qobject_cast(d->model)) - dataModel->setModel(model); - } - if (d->model) { - connect(d->model, SIGNAL(modelUpdated(QDeclarativeChangeSet,bool)), - this, SLOT(modelUpdated(QDeclarativeChangeSet,bool))); - connect(d->model, SIGNAL(createdItem(int,QQuickItem*)), this, SLOT(createdItem(int,QQuickItem*))); - connect(d->model, SIGNAL(initItem(int,QQuickItem*)), this, SLOT(initItem(int,QQuickItem*))); -// connect(d->model, SIGNAL(destroyingItem(QQuickItem*)), this, SLOT(destroyingItem(QQuickItem*))); - regenerate(); - } - emit modelChanged(); - emit countChanged(); -} - -/*! - \qmlproperty Component QtQuick2::Repeater::delegate - \default - - The delegate provides a template defining each item instantiated by the repeater. - - Delegates are exposed to a read-only \c index property that indicates the index - of the delegate within the repeater. For example, the following \l Text delegate - displays the index of each repeated item: - - \table - \row - \o \snippet doc/src/snippets/declarative/repeaters/repeater.qml index - \o \image repeater-index.png - \endtable - - If the \l model is a \l{QStringList-based model}{string list} or - \l{QObjectList-based model}{object list}, the delegate is also exposed to - a read-only \c modelData property that holds the string or object data. For - example: - - \table - \row - \o \snippet doc/src/snippets/declarative/repeaters/repeater.qml modeldata - \o \image repeater-modeldata.png - \endtable - - If the \l model is a model object (such as a \l ListModel) the delegate - can access all model roles as named properties, in the same way that delegates - do for view classes like ListView. - - \sa {QML Data Models} - */ -QDeclarativeComponent *QQuickRepeater::delegate() const -{ - Q_D(const QQuickRepeater); - if (d->model) { - if (QQuickVisualDataModel *dataModel = qobject_cast(d->model)) - return dataModel->delegate(); - } - - return 0; -} - -void QQuickRepeater::setDelegate(QDeclarativeComponent *delegate) -{ - Q_D(QQuickRepeater); - if (QQuickVisualDataModel *dataModel = qobject_cast(d->model)) - if (delegate == dataModel->delegate()) - return; - - if (!d->ownModel) { - d->model = new QQuickVisualDataModel(qmlContext(this)); - d->ownModel = true; - } - if (QQuickVisualDataModel *dataModel = qobject_cast(d->model)) { - dataModel->setDelegate(delegate); - regenerate(); - emit delegateChanged(); - } -} - -/*! - \qmlproperty int QtQuick2::Repeater::count - - This property holds the number of items in the repeater. -*/ -int QQuickRepeater::count() const -{ - Q_D(const QQuickRepeater); - if (d->model) - return d->model->count(); - return 0; -} - -/*! - \qmlmethod Item QtQuick2::Repeater::itemAt(index) - - Returns the \l Item that has been created at the given \a index, or \c null - if no item exists at \a index. -*/ -QQuickItem *QQuickRepeater::itemAt(int index) const -{ - Q_D(const QQuickRepeater); - if (index >= 0 && index < d->deletables.count()) - return d->deletables[index]; - return 0; -} - -void QQuickRepeater::componentComplete() -{ - Q_D(QQuickRepeater); - if (d->model && d->ownModel) - static_cast(d->model)->componentComplete(); - QQuickItem::componentComplete(); - regenerate(); - if (d->model && d->model->count()) - emit countChanged(); -} - -void QQuickRepeater::itemChange(ItemChange change, const ItemChangeData &value) -{ - QQuickItem::itemChange(change, value); - if (change == ItemParentHasChanged) { - regenerate(); - } -} - -void QQuickRepeater::clear() -{ - Q_D(QQuickRepeater); - bool complete = isComponentComplete(); - - if (d->model) { - for (int i = 0; i < d->deletables.count(); ++i) { - QQuickItem *item = d->deletables.at(i); - if (complete) - emit itemRemoved(i, item); - d->model->release(item); - } - } - d->deletables.clear(); - d->itemCount = 0; -} - -void QQuickRepeater::regenerate() -{ - Q_D(QQuickRepeater); - if (!isComponentComplete()) - return; - - clear(); - - if (!d->model || !d->model->count() || !d->model->isValid() || !parentItem() || !isComponentComplete()) - return; - - d->itemCount = count(); - d->deletables.resize(d->itemCount); - d->createFrom = 0; - d->createItems(); -} - -void QQuickRepeaterPrivate::createItems() -{ - Q_Q(QQuickRepeater); - if (createFrom == -1) - return; - inRequest = true; - for (int ii = createFrom; ii < itemCount; ++ii) { - if (!deletables.at(ii)) { - QQuickItem *item = model->item(ii, false); - if (!item) { - createFrom = ii; - break; - } - deletables[ii] = item; - QDeclarative_setParent_noEvent(item, q->parentItem()); - item->setParentItem(q->parentItem()); - if (ii > 0 && deletables.at(ii-1)) { - item->stackAfter(deletables.at(ii-1)); - } else { - QQuickItem *after = q; - for (int si = ii+1; si < itemCount; ++si) { - if (deletables.at(si)) { - after = deletables.at(si); - break; - } - } - item->stackBefore(after); - } - emit q->itemAdded(ii, item); - } - } - inRequest = false; -} - -void QQuickRepeater::createdItem(int, QQuickItem *) -{ - Q_D(QQuickRepeater); - if (!d->inRequest) - d->createItems(); -} - -void QQuickRepeater::initItem(int, QQuickItem *item) -{ - QDeclarative_setParent_noEvent(item, parentItem()); - item->setParentItem(parentItem()); -} - -void QQuickRepeater::modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset) -{ - Q_D(QQuickRepeater); - - if (!isComponentComplete()) - return; - - if (reset) { - regenerate(); - emit countChanged(); - } - - int difference = 0; - QHash > > moved; - foreach (const QDeclarativeChangeSet::Remove &remove, changeSet.removes()) { - int index = qMin(remove.index, d->deletables.count()); - int count = qMin(remove.index + remove.count, d->deletables.count()) - index; - if (remove.isMove()) { - moved.insert(remove.moveId, d->deletables.mid(index, count)); - d->deletables.erase( - d->deletables.begin() + index, - d->deletables.begin() + index + count); - } else while (count--) { - QQuickItem *item = d->deletables.at(index); - d->deletables.remove(index); - emit itemRemoved(index, item); - if (item) - d->model->release(item); - --d->itemCount; - } - - difference -= remove.count; - } - - d->createFrom = -1; - foreach (const QDeclarativeChangeSet::Insert &insert, changeSet.inserts()) { - int index = qMin(insert.index, d->deletables.count()); - if (insert.isMove()) { - QVector > items = moved.value(insert.moveId); - d->deletables = d->deletables.mid(0, index) + items + d->deletables.mid(index); - QQuickItem *stackBefore = index + items.count() < d->deletables.count() - ? d->deletables.at(index + items.count()) - : this; - for (int i = index; i < index + items.count(); ++i) - d->deletables.at(i)->stackBefore(stackBefore); - } else for (int i = 0; i < insert.count; ++i) { - int modelIndex = index + i; - ++d->itemCount; - d->deletables.insert(modelIndex, 0); - if (d->createFrom == -1) - d->createFrom = modelIndex; - } - difference += insert.count; - } - - d->createItems(); - - if (difference != 0) - emit countChanged(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickrepeater_p.h b/src/declarative/items/qquickrepeater_p.h deleted file mode 100644 index 5b90d74e65..0000000000 --- a/src/declarative/items/qquickrepeater_p.h +++ /dev/null @@ -1,112 +0,0 @@ -// Commit: ebd4bc73c46c2962742a682b6a391fb68c482aec -/**************************************************************************** -** -** 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$ -** 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 QQUICKREPEATER_P_H -#define QQUICKREPEATER_P_H - -#include "qquickitem.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeChangeSet; - -class QQuickRepeaterPrivate; -class Q_AUTOTEST_EXPORT QQuickRepeater : public QQuickItem -{ - Q_OBJECT - - Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) - Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_CLASSINFO("DefaultProperty", "delegate") - -public: - QQuickRepeater(QQuickItem *parent=0); - virtual ~QQuickRepeater(); - - QVariant model() const; - void setModel(const QVariant &); - - QDeclarativeComponent *delegate() const; - void setDelegate(QDeclarativeComponent *); - - int count() const; - - Q_INVOKABLE QQuickItem *itemAt(int index) const; - -Q_SIGNALS: - void modelChanged(); - void delegateChanged(); - void countChanged(); - - void itemAdded(int index, QQuickItem *item); - void itemRemoved(int index, QQuickItem *item); - -private: - void clear(); - void regenerate(); - -protected: - virtual void componentComplete(); - void itemChange(ItemChange change, const ItemChangeData &value); - -private Q_SLOTS: - void createdItem(int index, QQuickItem *item); - void initItem(int, QQuickItem *item); - void modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset); - -private: - Q_DISABLE_COPY(QQuickRepeater) - Q_DECLARE_PRIVATE(QQuickRepeater) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickRepeater) - -QT_END_HEADER - -#endif // QQUICKREPEATER_P_H diff --git a/src/declarative/items/qquickrepeater_p_p.h b/src/declarative/items/qquickrepeater_p_p.h deleted file mode 100644 index 962d177494..0000000000 --- a/src/declarative/items/qquickrepeater_p_p.h +++ /dev/null @@ -1,89 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKREPEATER_P_P_H -#define QQUICKREPEATER_P_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 "qquickrepeater_p.h" -#include "qquickitem_p.h" - -#include - -QT_BEGIN_NAMESPACE - -class QDeclarativeContext; -class QQuickVisualModel; -class QQuickRepeaterPrivate : public QQuickItemPrivate -{ - Q_DECLARE_PUBLIC(QQuickRepeater) - -public: - QQuickRepeaterPrivate(); - ~QQuickRepeaterPrivate(); - -private: - void createItems(); - - QQuickVisualModel *model; - QVariant dataSource; - bool ownModel : 1; - bool inRequest : 1; - int itemCount; - int createFrom; - - QVector > deletables; -}; - -QT_END_NAMESPACE - -#endif // QQUICKREPEATER_P_P_H diff --git a/src/declarative/items/qquickscalegrid.cpp b/src/declarative/items/qquickscalegrid.cpp deleted file mode 100644 index 9a8f652a9b..0000000000 --- a/src/declarative/items/qquickscalegrid.cpp +++ /dev/null @@ -1,214 +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 QtDeclarative module 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 "qquickscalegrid_p_p.h" - -#include - -QT_BEGIN_NAMESPACE - -/*! - \internal - \class QQuickScaleGrid - \brief The QQuickScaleGrid class allows you to specify a 3x3 grid to use in scaling an image. -*/ - -QQuickScaleGrid::QQuickScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0) -{ -} - -QQuickScaleGrid::~QQuickScaleGrid() -{ -} - -bool QQuickScaleGrid::isNull() const -{ - return !_left && !_top && !_right && !_bottom; -} - -void QQuickScaleGrid::setLeft(int pos) -{ - if (_left != pos) { - _left = pos; - emit borderChanged(); - } -} - -void QQuickScaleGrid::setTop(int pos) -{ - if (_top != pos) { - _top = pos; - emit borderChanged(); - } -} - -void QQuickScaleGrid::setRight(int pos) -{ - if (_right != pos) { - _right = pos; - emit borderChanged(); - } -} - -void QQuickScaleGrid::setBottom(int pos) -{ - if (_bottom != pos) { - _bottom = pos; - emit borderChanged(); - } -} - -QQuickGridScaledImage::QQuickGridScaledImage() -: _l(-1), _r(-1), _t(-1), _b(-1), - _h(QQuickBorderImage::Stretch), _v(QQuickBorderImage::Stretch) -{ -} - -QQuickGridScaledImage::QQuickGridScaledImage(const QQuickGridScaledImage &o) -: _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix) -{ -} - -QQuickGridScaledImage &QQuickGridScaledImage::operator=(const QQuickGridScaledImage &o) -{ - _l = o._l; - _r = o._r; - _t = o._t; - _b = o._b; - _h = o._h; - _v = o._v; - _pix = o._pix; - return *this; -} - -QQuickGridScaledImage::QQuickGridScaledImage(QIODevice *data) -: _l(-1), _r(-1), _t(-1), _b(-1), _h(QQuickBorderImage::Stretch), _v(QQuickBorderImage::Stretch) -{ - int l = -1; - int r = -1; - int t = -1; - int b = -1; - QString imgFile; - - QByteArray raw; - while (raw = data->readLine(), !raw.isEmpty()) { - QString line = QString::fromUtf8(raw.trimmed()); - if (line.isEmpty() || line.startsWith(QLatin1Char('#'))) - continue; - - int colonId = line.indexOf(QLatin1Char(':')); - if (colonId <= 0) - return; - - QStringList list; - list.append(line.left(colonId).trimmed()); - list.append(line.mid(colonId+1).trimmed()); - - if (list[0] == QLatin1String("border.left")) - l = list[1].toInt(); - else if (list[0] == QLatin1String("border.right")) - r = list[1].toInt(); - else if (list[0] == QLatin1String("border.top")) - t = list[1].toInt(); - else if (list[0] == QLatin1String("border.bottom")) - b = list[1].toInt(); - else if (list[0] == QLatin1String("source")) - imgFile = list[1]; - else if (list[0] == QLatin1String("horizontalTileRule")) - _h = stringToRule(list[1]); - else if (list[0] == QLatin1String("verticalTileRule")) - _v = stringToRule(list[1]); - } - - if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty()) - return; - - _l = l; _r = r; _t = t; _b = b; - - _pix = imgFile; - if (_pix.startsWith(QLatin1Char('"')) && _pix.endsWith(QLatin1Char('"'))) - _pix = _pix.mid(1, _pix.size() - 2); // remove leading/trailing quotes. -} - -QQuickBorderImage::TileMode QQuickGridScaledImage::stringToRule(const QString &s) -{ - if (s == QLatin1String("Stretch")) - return QQuickBorderImage::Stretch; - if (s == QLatin1String("Repeat")) - return QQuickBorderImage::Repeat; - if (s == QLatin1String("Round")) - return QQuickBorderImage::Round; - - qWarning("QQuickGridScaledImage: Invalid tile rule specified. Using Stretch."); - return QQuickBorderImage::Stretch; -} - -bool QQuickGridScaledImage::isValid() const -{ - return _l >= 0; -} - -int QQuickGridScaledImage::gridLeft() const -{ - return _l; -} - -int QQuickGridScaledImage::gridRight() const -{ - return _r; -} - -int QQuickGridScaledImage::gridTop() const -{ - return _t; -} - -int QQuickGridScaledImage::gridBottom() const -{ - return _b; -} - -QString QQuickGridScaledImage::pixmapUrl() const -{ - return _pix; -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickscalegrid_p_p.h b/src/declarative/items/qquickscalegrid_p_p.h deleted file mode 100644 index 8d93c3b1c9..0000000000 --- a/src/declarative/items/qquickscalegrid_p_p.h +++ /dev/null @@ -1,134 +0,0 @@ -// Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350 -/**************************************************************************** -** -** 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$ -** 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 QQUICKSCALEGRID_P_P_H -#define QQUICKSCALEGRID_P_P_H - -#include "qquickborderimage_p.h" - -#include -#include - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class Q_DECLARATIVE_PRIVATE_EXPORT QQuickScaleGrid : public QObject -{ - Q_OBJECT - Q_ENUMS(TileRule) - - Q_PROPERTY(int left READ left WRITE setLeft NOTIFY borderChanged) - Q_PROPERTY(int top READ top WRITE setTop NOTIFY borderChanged) - Q_PROPERTY(int right READ right WRITE setRight NOTIFY borderChanged) - Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY borderChanged) - -public: - QQuickScaleGrid(QObject *parent=0); - ~QQuickScaleGrid(); - - bool isNull() const; - - int left() const { return _left; } - void setLeft(int); - - int top() const { return _top; } - void setTop(int); - - int right() const { return _right; } - void setRight(int); - - int bottom() const { return _bottom; } - void setBottom(int); - -Q_SIGNALS: - void borderChanged(); - -private: - int _left; - int _top; - int _right; - int _bottom; -}; - -class Q_DECLARATIVE_PRIVATE_EXPORT QQuickGridScaledImage -{ -public: - QQuickGridScaledImage(); - QQuickGridScaledImage(const QQuickGridScaledImage &); - QQuickGridScaledImage(QIODevice*); - QQuickGridScaledImage &operator=(const QQuickGridScaledImage &); - bool isValid() const; - int gridLeft() const; - int gridRight() const; - int gridTop() const; - int gridBottom() const; - QQuickBorderImage::TileMode horizontalTileRule() const { return _h; } - QQuickBorderImage::TileMode verticalTileRule() const { return _v; } - - QString pixmapUrl() const; - -private: - static QQuickBorderImage::TileMode stringToRule(const QString &); - -private: - int _l; - int _r; - int _t; - int _b; - QQuickBorderImage::TileMode _h; - QQuickBorderImage::TileMode _v; - QString _pix; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickScaleGrid) - -QT_END_HEADER - -#endif // QQUICKSCALEGRID_P_P_H diff --git a/src/declarative/items/qquickshadereffect.cpp b/src/declarative/items/qquickshadereffect.cpp deleted file mode 100644 index bdef980440..0000000000 --- a/src/declarative/items/qquickshadereffect.cpp +++ /dev/null @@ -1,763 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 -#include - -#include "qsgmaterial.h" -#include "qquickitem_p.h" - -#include -#include -#include "qquickcanvas.h" - -#include "qquickimage_p.h" -#include "qquickshadereffectsource_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -static const char qt_default_vertex_code[] = - "uniform highp mat4 qt_Matrix; \n" - "attribute highp vec4 qt_Vertex; \n" - "attribute highp vec2 qt_MultiTexCoord0; \n" - "varying highp vec2 qt_TexCoord0; \n" - "void main() { \n" - " qt_TexCoord0 = qt_MultiTexCoord0; \n" - " gl_Position = qt_Matrix * qt_Vertex; \n" - "}"; - -static const char qt_default_fragment_code[] = - "varying highp vec2 qt_TexCoord0; \n" - "uniform sampler2D source; \n" - "uniform lowp float qt_Opacity; \n" - "void main() { \n" - " gl_FragColor = texture2D(source, qt_TexCoord0) * qt_Opacity; \n" - "}"; - -static const char qt_position_attribute_name[] = "qt_Vertex"; -static const char qt_texcoord_attribute_name[] = "qt_MultiTexCoord0"; - -const char *qtPositionAttributeName() -{ - return qt_position_attribute_name; -} - -const char *qtTexCoordAttributeName() -{ - return qt_texcoord_attribute_name; -} - -/*! - \qmlclass ShaderEffect QQuickShaderEffect - \inqmlmodule QtQuick 2 - \ingroup qml-basic-visual-elements - \brief The ShaderEffect element applies custom shaders to a rectangle. - \inherits Item - - The ShaderEffect element applies a custom OpenGL - \l{vertexShader}{vertex} and \l{fragmentShader}{fragment} shader to a - rectangle. It allows you to write effects such as drop shadow, blur, - colorize and page curl directly in QML. - - There are two types of input to the \l vertexShader: - uniform variables and attributes. Some are predefined: - \list - \o uniform mat4 qt_Matrix - combined transformation - matrix, the product of the matrices from the root item to this - ShaderEffect, and an orthogonal projection. - \o uniform float qt_Opacity - combined opacity, the product of the - opacities from the root item to this ShaderEffect. - \o attribute vec4 qt_Vertex - vertex position, the top-left vertex has - position (0, 0), the bottom-right (\l{Item::width}{width}, - \l{Item::height}{height}). - \o attribute vec2 qt_MultiTexCoord0 - texture coordinate, the top-left - coordinate is (0, 0), the bottom-right (1, 1). - \endlist - - In addition, any property that can be mapped to an OpenGL Shading Language - (GLSL) type is available as a uniform variable. The following list shows - how properties are mapped to GLSL uniform variables: - \list - \o bool, int, qreal -> bool, int, float - If the type in the shader is not - the same as in QML, the value is converted automatically. - \o QColor -> vec4 - When colors are passed to the shader, they are first - premultiplied. Thus Qt.rgba(0.2, 0.6, 1.0, 0.5) becomes - vec4(0.1, 0.3, 0.5, 0.5) in the shader, for example. - \o QRect, QRectF -> vec4 - Qt.rect(x, y, w, h) becomes vec4(x, y, w, h) in - the shader. - \o QPoint, QPointF, QSize, QSizeF -> vec2 - \o QVector3D -> vec3 - \o QTransform -> mat4 - \o \l Image, \l ShaderEffectSource -> sampler2D - Origin is in the top-left - corner, and the color values are premultiplied. - \endlist - - The output from the \l fragmentShader should be premultiplied. If - \l blending is enabled, source-over blending is used. However, additive - blending can be achieved by outputting zero in the alpha channel. - - \row - \o \image declarative-shadereffectitem.png - \o \qml - import QtQuick 2.0 - - Rectangle { - width: 200; height: 100 - Row { - Image { id: img; sourceSize { width: 100; height: 100 } source: "qt-logo.png" } - ShaderEffect { - width: 100; height: 100 - property variant src: img - vertexShader: " - uniform highp mat4 qt_Matrix; - attribute highp vec4 qt_Vertex; - attribute highp vec2 qt_MultiTexCoord0; - varying highp vec2 coord; - void main() { - coord = qt_MultiTexCoord0; - gl_Position = qt_Matrix * qt_Vertex; - }" - fragmentShader: " - varying highp vec2 coord; - uniform sampler2D src; - uniform lowp float qt_Opacity; - void main() { - lowp vec4 tex = texture2D(src, coord); - gl_FragColor = vec4(vec3(dot(tex.rgb, vec3(0.344, 0.5, 0.156))), tex.a) * qt_Opacity; - }" - } - } - } - \endqml - \endrow - - By default, the ShaderEffect consists of four vertices, one for each - corner. For non-linear vertex transformations, like page curl, you can - specify a fine grid of vertices by specifying a \l mesh resolution. - - \note Scene Graph textures have origin in the top-left corner rather than - bottom-left which is common in OpenGL. -*/ - -QQuickShaderEffect::QQuickShaderEffect(QQuickItem *parent) - : QQuickItem(parent) - , m_meshResolution(1, 1) - , m_mesh(0) - , m_cullMode(NoCulling) - , m_blending(true) - , m_dirtyData(true) - , m_programDirty(true) - , m_dirtyMesh(true) - , m_dirtyGeometry(true) -{ - setFlag(QQuickItem::ItemHasContents); -} - -QQuickShaderEffect::~QQuickShaderEffect() -{ - reset(); -} - -void QQuickShaderEffect::componentComplete() -{ - updateProperties(); - QQuickItem::componentComplete(); -} - -/*! - \qmlproperty string QtQuick2::ShaderEffect::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 QQuickShaderEffect::setFragmentShader(const QByteArray &code) -{ - if (m_source.fragmentCode.constData() == code.constData()) - return; - m_source.fragmentCode = code; - if (isComponentComplete()) { - reset(); - updateProperties(); - update(); - } - emit fragmentShaderChanged(); -} - -/*! - \qmlproperty string QtQuick2::ShaderEffect::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 QQuickShaderEffect::setVertexShader(const QByteArray &code) -{ - if (m_source.vertexCode.constData() == code.constData()) - return; - m_source.vertexCode = code; - if (isComponentComplete()) { - reset(); - updateProperties(); - update(); - } - emit vertexShaderChanged(); -} - -/*! - \qmlproperty bool QtQuick2::ShaderEffect::blending - - If this property is true, the output from the \l fragmentShader is blended - with the background using source-over blend mode. If false, the background - is disregarded. Blending decreases the performance, so you should set this - property to false when blending is not needed. The default value is true. -*/ - -void QQuickShaderEffect::setBlending(bool enable) -{ - if (blending() == enable) - return; - - m_blending = enable; - update(); - - emit blendingChanged(); -} - -/*! - \qmlproperty variant QtQuick2::ShaderEffect::mesh - - This property defines the mesh used to draw the ShaderEffect. It can hold - any mesh object deriving from \l QQuickShaderEffectMesh, such as \l GridMesh. - If a size value is assigned to this property, the ShaderEffect implicitly - uses a \l GridMesh with the value as - \l{GridMesh::resolution}{mesh resolution}. By default, this property is - the size 1x1. - - \sa GridMesh -*/ - -QVariant QQuickShaderEffect::mesh() const -{ - return m_mesh ? qVariantFromValue(static_cast(m_mesh)) - : qVariantFromValue(m_meshResolution); -} - -void QQuickShaderEffect::setMesh(const QVariant &mesh) -{ - QQuickShaderEffectMesh *newMesh = qobject_cast(qVariantValue(mesh)); - if (newMesh && newMesh == m_mesh) - return; - if (m_mesh) - disconnect(m_mesh, SIGNAL(geometryChanged()), this, 0); - m_mesh = newMesh; - if (m_mesh) { - connect(m_mesh, SIGNAL(geometryChanged()), this, SLOT(updateGeometry())); - } else { - if (qVariantCanConvert(mesh)) { - m_meshResolution = mesh.toSize(); - } else { - QList res = mesh.toByteArray().split('x'); - bool ok = res.size() == 2; - if (ok) { - int w = res.at(0).toInt(&ok); - if (ok) { - int h = res.at(1).toInt(&ok); - if (ok) - m_meshResolution = QSize(w, h); - } - } - if (!ok) - qWarning("ShaderEffect: mesh property must be size or object deriving from QQuickShaderEffectMesh."); - } - m_defaultMesh.setResolution(m_meshResolution); - } - - m_dirtyMesh = true; - update(); - emit meshChanged(); -} - -/*! - \qmlproperty enumeration QtQuick2::ShaderEffect::cullMode - - This property defines which sides of the element should be visible. - - \list - \o ShaderEffect.NoCulling - Both sides are visible - \o ShaderEffect.BackFaceCulling - only front side is visible - \o ShaderEffect.FrontFaceCulling - only back side is visible - \endlist - - The default is NoCulling. -*/ - -void QQuickShaderEffect::setCullMode(CullMode face) -{ - if (face == m_cullMode) - return; - m_cullMode = face; - update(); - emit cullModeChanged(); -} - -void QQuickShaderEffect::changeSource(int index) -{ - Q_ASSERT(index >= 0 && index < m_sources.size()); - QVariant v = property(m_sources.at(index).name.constData()); - setSource(v, index); -} - -void QQuickShaderEffect::updateData() -{ - m_dirtyData = true; - update(); -} - -void QQuickShaderEffect::updateGeometry() -{ - m_dirtyGeometry = true; - update(); -} - -void QQuickShaderEffect::setSource(const QVariant &var, int index) -{ - Q_ASSERT(index >= 0 && index < m_sources.size()); - - SourceData &source = m_sources[index]; - - source.sourceObject = 0; - if (var.isNull()) { - return; - } else if (!qVariantCanConvert(var)) { - qWarning("Could not assign source of type '%s' to property '%s'.", var.typeName(), source.name.constData()); - return; - } - - QObject *obj = qVariantValue(var); - QQuickItem *item = qobject_cast(obj); - if (!item || !item->isTextureProvider()) { - qWarning("ShaderEffect: source uniform [%s] is not assigned a valid texture provider: %s [%s]", - source.name.constData(), qPrintable(obj->objectName()), obj->metaObject()->className()); - return; - } - - source.sourceObject = item; - - - // TODO: Find better solution. - // '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 (item && item->parentItem() == 0) { - item->setParentItem(this); - item->setVisible(false); - } -} - -void QQuickShaderEffect::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 QQuickShaderEffect::connectPropertySignals() -{ - QSet::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("QQuickShaderEffect: 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("QQuickShaderEffect: '%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("QQuickShaderEffect: '%s' does not have a matching source!", source.name.constData()); - } - } -} - -void QQuickShaderEffect::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; - QQuickItem *item = qobject_cast(source.sourceObject); - if (item && item->parentItem() == this) - item->setParentItem(0); - } - m_sources.clear(); - - m_programDirty = true; - m_dirtyMesh = true; -} - -void QQuickShaderEffect::updateProperties() -{ - if (m_source.vertexCode.isEmpty()) { - m_source.attributeNames.append(QByteArray(qt_position_attribute_name)); - m_source.attributeNames.append(QByteArray(qt_texcoord_attribute_name)); - m_source.respectsMatrix = true; - } else { - lookThroughShaderCode(m_source.vertexCode); - } - if (m_source.fragmentCode.isEmpty()) { - m_source.respectsOpacity = true; - QByteArray name("source"); - m_source.uniformNames.insert(name); - SourceData d; - d.mapper = new QSignalMapper; - d.name = name; - d.sourceObject = 0; - m_sources.append(d); - } else { - lookThroughShaderCode(m_source.fragmentCode); - } - - if (!m_mesh && !m_source.attributeNames.contains(qt_position_attribute_name)) - qWarning("QQuickShaderEffect: Missing reference to \'%s\'.", qt_position_attribute_name); - if (!m_mesh && !m_source.attributeNames.contains(qt_texcoord_attribute_name)) - qWarning("QQuickShaderEffect: Missing reference to \'%s\'.", qt_texcoord_attribute_name); - if (!m_source.respectsMatrix) - qWarning("QQuickShaderEffect: Missing reference to \'qt_Matrix\'."); - if (!m_source.respectsOpacity) - qWarning("QQuickShaderEffect: 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(); -} - -namespace { - - enum VariableQualifier { - AttributeQualifier, - UniformQualifier - }; - - inline bool qt_isalpha(char c) - { - char ch = c | 0x20; - return (ch >= 'a' && ch <= 'z') || c == '_'; - } - - inline bool qt_isalnum(char c) - { - return qt_isalpha(c) || (c >= '0' && c <= '9'); - } - - inline bool qt_isspace(char c) - { - return c == ' ' || (c >= 0x09 && c <= 0x0d); - } - - // Returns -1 if not found, returns index to first character after the name if found. - int qt_search_for_variable(const char *s, int length, int index, VariableQualifier &decl, - int &typeIndex, int &typeLength, - int &nameIndex, int &nameLength) - { - enum Identifier { - QualifierIdentifier, // Base state - PrecisionIdentifier, - TypeIdentifier, - NameIdentifier - }; - Identifier expected = QualifierIdentifier; - bool compilerDirectiveExpected = index == 0; - - while (index < length) { - // Skip whitespace. - while (qt_isspace(s[index])) { - compilerDirectiveExpected |= s[index] == '\n'; - ++index; - } - - if (qt_isalpha(s[index])) { - // Read identifier. - int idIndex = index; - ++index; - while (qt_isalnum(s[index])) - ++index; - int idLength = index - idIndex; - - const int attrLen = sizeof("attribute") - 1; - const int uniLen = sizeof("uniform") - 1; - const int loLen = sizeof("lowp") - 1; - const int medLen = sizeof("mediump") - 1; - const int hiLen = sizeof("highp") - 1; - - switch (expected) { - case QualifierIdentifier: - if (idLength == attrLen && qstrncmp("attribute", s + idIndex, attrLen) == 0) { - decl = AttributeQualifier; - expected = PrecisionIdentifier; - } else if (idLength == uniLen && qstrncmp("uniform", s + idIndex, uniLen) == 0) { - decl = UniformQualifier; - expected = PrecisionIdentifier; - } - break; - case PrecisionIdentifier: - if ((idLength == loLen && qstrncmp("lowp", s + idIndex, loLen) == 0) - || (idLength == medLen && qstrncmp("mediump", s + idIndex, medLen) == 0) - || (idLength == hiLen && qstrncmp("highp", s + idIndex, hiLen) == 0)) - { - expected = TypeIdentifier; - break; - } - // Fall through. - case TypeIdentifier: - typeIndex = idIndex; - typeLength = idLength; - expected = NameIdentifier; - break; - case NameIdentifier: - nameIndex = idIndex; - nameLength = idLength; - return index; // Attribute or uniform declaration found. Return result. - default: - break; - } - } else if (s[index] == '#' && compilerDirectiveExpected) { - // Skip compiler directives. - ++index; - while (index < length && (s[index] != '\n' || s[index - 1] == '\\')) - ++index; - } else if (s[index] == '/' && s[index + 1] == '/') { - // Skip comments. - index += 2; - while (index < length && s[index] != '\n') - ++index; - } else if (s[index] == '/' && s[index + 1] == '*') { - // Skip comments. - index += 2; - while (index < length && (s[index] != '*' || s[index + 1] != '/')) - ++index; - if (index < length) - index += 2; // Skip star-slash. - } else { - expected = QualifierIdentifier; - ++index; - } - compilerDirectiveExpected = false; - } - return -1; - } -} - -void QQuickShaderEffect::lookThroughShaderCode(const QByteArray &code) -{ - int index = 0; - int typeIndex, typeLength, nameIndex, nameLength; - const char *s = code.constData(); - VariableQualifier decl; - while ((index = qt_search_for_variable(s, code.size(), index, decl, typeIndex, typeLength, - nameIndex, nameLength)) != -1) - { - if (decl == AttributeQualifier) { - m_source.attributeNames.append(QByteArray(s + nameIndex, nameLength)); - } else { - Q_ASSERT(decl == UniformQualifier); - - const int matLen = sizeof("qt_Matrix") - 1; - const int opLen = sizeof("qt_Opacity") - 1; - const int sampLen = sizeof("sampler2D") - 1; - - if (nameLength == matLen && qstrncmp("qt_Matrix", s + nameIndex, matLen) == 0) { - m_source.respectsMatrix = true; - } else if (nameLength == opLen && qstrncmp("qt_Opacity", s + nameIndex, opLen) == 0) { - m_source.respectsOpacity = true; - } else { - QByteArray name(s + nameIndex, nameLength); - m_source.uniformNames.insert(name); - if (typeLength == sampLen && qstrncmp("sampler2D", s + typeIndex, sampLen) == 0) { - SourceData d; - d.mapper = new QSignalMapper; - d.name = name; - d.sourceObject = 0; - m_sources.append(d); - } - } - } - } -} - -void QQuickShaderEffect::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - m_dirtyGeometry = true; - QQuickItem::geometryChanged(newGeometry, oldGeometry); -} - -QSGNode *QQuickShaderEffect::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - QQuickShaderEffectNode *node = static_cast(oldNode); - - // In the case of a bad vertex shader, don't try to create a node... - if (m_source.attributeNames.isEmpty()) { - if (node) - delete node; - return 0; - } - - if (!node) { - node = new QQuickShaderEffectNode; - m_programDirty = true; - m_dirtyData = true; - m_dirtyGeometry = true; - } - - QQuickShaderEffectMaterial *material = node->shaderMaterial(); - - if (m_dirtyMesh) { - node->setGeometry(0); - m_dirtyMesh = false; - m_dirtyGeometry = true; - } - - if (m_dirtyGeometry) { - node->setFlag(QSGNode::OwnsGeometry, false); - QSGGeometry *geometry = node->geometry(); - QRectF rect(0, 0, width(), height()); - QQuickShaderEffectMesh *mesh = m_mesh ? m_mesh : &m_defaultMesh; - - geometry = mesh->updateGeometry(geometry, m_source.attributeNames, rect); - if (!geometry) { - delete node; - return 0; - } - - node->setGeometry(geometry); - node->setFlag(QSGNode::OwnsGeometry, true); - - m_dirtyGeometry = false; - } - - if (m_programDirty) { - QQuickShaderEffectProgram s = m_source; - if (s.fragmentCode.isEmpty()) - s.fragmentCode = qt_default_fragment_code; - if (s.vertexCode.isEmpty()) - s.vertexCode = qt_default_vertex_code; - s.className = metaObject()->className(); - - material->setProgramSource(s); - node->markDirty(QSGNode::DirtyMaterial); - m_programDirty = false; - } - - // Update blending - if (bool(material->flags() & QSGMaterial::Blending) != m_blending) { - material->setFlag(QSGMaterial::Blending, m_blending); - node->markDirty(QSGNode::DirtyMaterial); - } - - if (int(material->cullMode()) != int(m_cullMode)) { - material->setCullMode(QQuickShaderEffectMaterial::CullMode(m_cullMode)); - node->markDirty(QSGNode::DirtyMaterial); - } - - if (m_dirtyData) { - QVector > values; - QVector > textures; - const QVector > &oldTextures = material->textureProviders(); - - for (QSet::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 *t = oldTextures.at(i).second; - if (t) - disconnect(t, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture())); - } - for (int i = 0; i < m_sources.size(); ++i) { - const SourceData &source = m_sources.at(i); - QSGTextureProvider *t = source.sourceObject ? source.sourceObject->textureProvider() : 0; - textures.append(qMakePair(source.name, t)); - if (t) - connect(t, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture()), Qt::DirectConnection); - } - material->setUniforms(values); - material->setTextureProviders(textures); - node->markDirty(QSGNode::DirtyMaterial); - m_dirtyData = false; - } - - return node; -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickshadereffect_p.h b/src/declarative/items/qquickshadereffect_p.h deleted file mode 100644 index 1910f43195..0000000000 --- a/src/declarative/items/qquickshadereffect_p.h +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKSHADEREFFECT_P_H -#define QQUICKSHADEREFFECT_P_H - -#include "qquickitem.h" - -#include "qsgmaterial.h" -#include -#include -#include "qquickshadereffectmesh_p.h" - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -const char *qtPositionAttributeName(); -const char *qtTexCoordAttributeName(); - -class QSGContext; -class QSignalMapper; -class QQuickCustomMaterialShader; - -class Q_AUTOTEST_EXPORT QQuickShaderEffect : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QByteArray fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged) - Q_PROPERTY(QByteArray vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged) - Q_PROPERTY(bool blending READ blending WRITE setBlending NOTIFY blendingChanged) - Q_PROPERTY(QVariant mesh READ mesh WRITE setMesh NOTIFY meshChanged) - Q_PROPERTY(CullMode culling READ cullMode WRITE setCullMode NOTIFY cullModeChanged) - Q_ENUMS(CullMode) - -public: - enum CullMode - { - NoCulling = QQuickShaderEffectMaterial::NoCulling, - BackFaceCulling = QQuickShaderEffectMaterial::BackFaceCulling, - FrontFaceCulling = QQuickShaderEffectMaterial::FrontFaceCulling - }; - - QQuickShaderEffect(QQuickItem *parent = 0); - ~QQuickShaderEffect(); - - virtual void componentComplete(); - - QByteArray fragmentShader() const { return m_source.fragmentCode; } - void setFragmentShader(const QByteArray &code); - - QByteArray vertexShader() const { return m_source.vertexCode; } - void setVertexShader(const QByteArray &code); - - bool blending() const { return m_blending; } - void setBlending(bool enable); - - QVariant mesh() const; - void setMesh(const QVariant &mesh); - - CullMode cullMode() const { return m_cullMode; } - void setCullMode(CullMode face); - -Q_SIGNALS: - void fragmentShaderChanged(); - void vertexShaderChanged(); - void blendingChanged(); - void meshChanged(); - void cullModeChanged(); - -protected: - virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); - virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - -private Q_SLOTS: - void changeSource(int index); - void updateData(); - void updateGeometry(); - -private: - friend class QQuickCustomMaterialShader; - friend class QQuickShaderEffectNode; - - void setSource(const QVariant &var, int index); - void disconnectPropertySignals(); - void connectPropertySignals(); - void reset(); - void updateProperties(); - void lookThroughShaderCode(const QByteArray &code); - - QQuickShaderEffectProgram m_source; - QSize m_meshResolution; - QQuickShaderEffectMesh *m_mesh; - QQuickGridMesh m_defaultMesh; - CullMode m_cullMode; - - struct SourceData - { - QSignalMapper *mapper; - QPointer sourceObject; - QByteArray name; - }; - QVector m_sources; - - uint m_blending : 1; - uint m_dirtyData : 1; - - uint m_programDirty : 1; - uint m_dirtyMesh : 1; - uint m_dirtyGeometry : 1; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QQUICKSHADEREFFECT_P_H diff --git a/src/declarative/items/qquickshadereffectmesh.cpp b/src/declarative/items/qquickshadereffectmesh.cpp deleted file mode 100644 index 7709bed614..0000000000 --- a/src/declarative/items/qquickshadereffectmesh.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qquickshadereffectmesh_p.h" -#include "qsggeometry.h" -#include "qquickshadereffect_p.h" - -QT_BEGIN_NAMESPACE - -QQuickShaderEffectMesh::QQuickShaderEffectMesh(QObject *parent) - : QObject(parent) -{ -} - -/*! - \qmlclass GridMesh QQuickGridMesh - \inqmlmodule QtQuick 2 - \ingroup qml-utility-elements - \brief GridMesh defines a mesh with vertices arranged in a grid. - - GridMesh defines a rectangular mesh consisting of vertices arranged in an - evenly spaced grid. It is used to generate \l{QSGGeometry}{geometry}. - The grid resolution is specified with the \l resolution property. -*/ - -QQuickGridMesh::QQuickGridMesh(QObject *parent) - : QQuickShaderEffectMesh(parent) - , m_resolution(1, 1) -{ - connect(this, SIGNAL(resolutionChanged()), this, SIGNAL(geometryChanged())); -} - -QSGGeometry *QQuickGridMesh::updateGeometry(QSGGeometry *geometry, const QVector &attributes, const QRectF &dstRect) const -{ - int vmesh = m_resolution.height(); - int hmesh = m_resolution.width(); - int attrCount = attributes.count(); - - if (!geometry) { - bool error = true; - Q_UNUSED(error) - switch (attrCount) { - case 0: - qWarning("QQuickGridMesh:: No attributes specified."); - break; - case 1: - if (attributes.at(0) == qtPositionAttributeName()) { - error = false; - break; - } - qWarning("QQuickGridMesh:: Missing \'%s\' attribute.", - qtPositionAttributeName()); - break; - case 2: - if (attributes.contains(qtPositionAttributeName()) - && attributes.contains(qtTexCoordAttributeName())) - { - error = false; - break; - } - qWarning("QQuickGridMesh:: Missing \'%s\' or \'%s\' attribute.", - qtPositionAttributeName(), qtTexCoordAttributeName()); - break; - default: - qWarning("QQuickGridMesh:: Too many attributes specified."); - break; - } - - geometry = new QSGGeometry(attrCount == 1 - ? QSGGeometry::defaultAttributes_Point2D() - : QSGGeometry::defaultAttributes_TexturedPoint2D(), - (vmesh + 1) * (hmesh + 1), vmesh * 2 * (hmesh + 2), - GL_UNSIGNED_SHORT); - - } else { - geometry->allocate((vmesh + 1) * (hmesh + 1), vmesh * 2 * (hmesh + 2)); - } - - QSGGeometry::Point2D *vdata = static_cast(geometry->vertexData()); - - bool positionFirst = attributes.at(0) == qtPositionAttributeName(); - - QRectF srcRect(0, 0, 1, 1); - for (int iy = 0; iy <= vmesh; ++iy) { - float fy = iy / float(vmesh); - float y = float(dstRect.top()) + fy * float(dstRect.height()); - float ty = float(srcRect.top()) + fy * float(srcRect.height()); - for (int ix = 0; ix <= hmesh; ++ix) { - float fx = ix / float(hmesh); - for (int ia = 0; ia < attrCount; ++ia) { - if (positionFirst == (ia == 0)) { - vdata->x = float(dstRect.left()) + fx * float(dstRect.width()); - vdata->y = y; - ++vdata; - } else { - vdata->x = float(srcRect.left()) + fx * float(srcRect.width()); - vdata->y = ty; - ++vdata; - } - } - } - } - - quint16 *indices = (quint16 *)geometry->indexDataAsUShort(); - int i = 0; - for (int iy = 0; iy < vmesh; ++iy) { - *(indices++) = i + hmesh + 1; - for (int ix = 0; ix <= hmesh; ++ix, ++i) { - *(indices++) = i + hmesh + 1; - *(indices++) = i; - } - *(indices++) = i - 1; - } - - return geometry; -} - -/*! - \qmlproperty size QtQuick2::GridMesh::resolution - - This property holds the grid resolution. The resolution's width and height - specify the number of cells or spacings between vertices horizontally and - vertically respectively. The minimum and default is 1x1, which corresponds - to four vertices in total, one in each corner. - For non-linear vertex transformations, you probably want to set the - resolution higher. - - \row - \o \image declarative-gridmesh.png - \o \qml - import QtQuick 2.0 - - ShaderEffect { - width: 200 - height: 200 - mesh: GridMesh { - resolution: Qt.size(20, 20) - } - property variant source: Image { - source: "qt-logo.png" - sourceSize { width: 200; height: 200 } - smooth: true - } - vertexShader: " - uniform highp mat4 qt_Matrix; - attribute highp vec4 qt_Vertex; - attribute highp vec2 qt_MultiTexCoord0; - varying highp vec2 qt_TexCoord0; - uniform highp float width; - void main() { - highp vec4 pos = qt_Vertex; - highp float d = .5 * smoothstep(0., 1., qt_MultiTexCoord0.y); - pos.x = width * mix(d, 1.0 - d, qt_MultiTexCoord0.x); - gl_Position = qt_Matrix * pos; - qt_TexCoord0 = qt_MultiTexCoord0; - }" - } - \endqml - \endrow -*/ - -void QQuickGridMesh::setResolution(const QSize &res) -{ - if (res == m_resolution) - return; - if (res.width() < 1 || res.height() < 1) { - return; - } - m_resolution = res; - emit resolutionChanged(); -} - -QSize QQuickGridMesh::resolution() const -{ - return m_resolution; -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickshadereffectmesh_p.h b/src/declarative/items/qquickshadereffectmesh_p.h deleted file mode 100644 index 40549f73a8..0000000000 --- a/src/declarative/items/qquickshadereffectmesh_p.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qdeclarativeparserstatus.h" - -#include -#include -#include -#include -#include - -#ifndef QQUICKSHADEREFFECTMESH_P_H -#define QQUICKSHADEREFFECTMESH_P_H - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGGeometry; -class QRectF; - -class Q_DECLARATIVE_EXPORT QQuickShaderEffectMesh : public QObject -{ - Q_OBJECT -public: - QQuickShaderEffectMesh(QObject *parent = 0); - // If 'geometry' != 0, 'attributes' is the same as last time the function was called. - virtual QSGGeometry *updateGeometry(QSGGeometry *geometry, const QVector &attributes, const QRectF &rect) const = 0; - -Q_SIGNALS: - // Emitted when the geometry needs to be updated. - void geometryChanged(); -}; - -class QQuickGridMesh : public QQuickShaderEffectMesh -{ - Q_OBJECT - Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged) -public: - QQuickGridMesh(QObject *parent = 0); - virtual QSGGeometry *updateGeometry(QSGGeometry *geometry, const QVector &attributes, const QRectF &rect) const; - - void setResolution(const QSize &res); - QSize resolution() const; - -Q_SIGNALS: - void resolutionChanged(); - -private: - QSize m_resolution; -}; - -inline QColor qt_premultiply_color(const QColor &c) -{ - return QColor::fromRgbF(c.redF() * c.alphaF(), c.greenF() * c.alphaF(), c.blueF() * c.alphaF(), c.alphaF()); -} - - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QQUICKSHADEREFFECTMESH_P_H diff --git a/src/declarative/items/qquickshadereffectnode.cpp b/src/declarative/items/qquickshadereffectnode.cpp deleted file mode 100644 index 43c891e497..0000000000 --- a/src/declarative/items/qquickshadereffectnode.cpp +++ /dev/null @@ -1,317 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 - -#include "qquickshadereffectmesh_p.h" -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickCustomMaterialShader : public QSGMaterialShader -{ -public: - QQuickCustomMaterialShader(const QQuickShaderEffectMaterialKey &key, const QVector &attributes); - virtual void deactivate(); - virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect); - virtual char const *const *attributeNames() const; - -protected: - friend class QQuickShaderEffectNode; - - virtual void initialize(); - virtual const char *vertexShader() const; - virtual const char *fragmentShader() const; - - const QQuickShaderEffectMaterialKey m_key; - QVector m_attributeNames; - const QVector m_attributes; - - QVector m_uniformLocs; - int m_opacityLoc; - int m_matrixLoc; - uint m_textureIndicesSet; -}; - -QQuickCustomMaterialShader::QQuickCustomMaterialShader(const QQuickShaderEffectMaterialKey &key, const QVector &attributes) - : m_key(key) - , m_attributes(attributes) - , m_textureIndicesSet(false) -{ - for (int i = 0; i < attributes.count(); ++i) - m_attributeNames.append(attributes.at(i).constData()); - m_attributeNames.append(0); -} - -void QQuickCustomMaterialShader::deactivate() -{ - QSGMaterialShader::deactivate(); - glDisable(GL_CULL_FACE); -} - -void QQuickCustomMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - Q_ASSERT(newEffect != 0); - - const QQuickShaderEffectMaterial *material = static_cast(newEffect); - - if (!m_textureIndicesSet) { - for (int i = 0; i < material->m_textures.size(); ++i) - program()->setUniformValue(material->m_textures.at(i).first.constData(), i); - m_textureIndicesSet = true; - } - - if (m_uniformLocs.size() != material->m_uniformValues.size()) { - m_uniformLocs.reserve(material->m_uniformValues.size()); - for (int i = 0; i < material->m_uniformValues.size(); ++i) { - const QByteArray &name = material->m_uniformValues.at(i).first; - m_uniformLocs.append(program()->uniformLocation(name.constData())); - } - } - - QOpenGLFunctions *functions = state.context()->functions(); - for (int i = material->m_textures.size() - 1; i >= 0; --i) { - functions->glActiveTexture(GL_TEXTURE0 + i); - if (QSGTextureProvider *provider = material->m_textures.at(i).second) { - if (QSGTexture *texture = provider->texture()) { - texture->bind(); - continue; - } - } - qWarning("ShaderEffect: source or provider missing when binding textures"); - glBindTexture(GL_TEXTURE_2D, 0); - } - - if (material->m_source.respectsOpacity) - program()->setUniformValue(m_opacityLoc, state.opacity()); - - for (int i = 0; i < material->m_uniformValues.count(); ++i) { - const QVariant &v = material->m_uniformValues.at(i).second; - - switch (v.type()) { - case QVariant::Color: - program()->setUniformValue(m_uniformLocs.at(i), qt_premultiply_color(qvariant_cast(v))); - break; - case QVariant::Double: - program()->setUniformValue(m_uniformLocs.at(i), (float) qvariant_cast(v)); - break; - case QVariant::Transform: - program()->setUniformValue(m_uniformLocs.at(i), qvariant_cast(v)); - break; - case QVariant::Int: - program()->setUniformValue(m_uniformLocs.at(i), v.toInt()); - break; - case QVariant::Bool: - program()->setUniformValue(m_uniformLocs.at(i), GLint(v.toBool())); - break; - case QVariant::Size: - case QVariant::SizeF: - program()->setUniformValue(m_uniformLocs.at(i), v.toSizeF()); - break; - case QVariant::Point: - case QVariant::PointF: - program()->setUniformValue(m_uniformLocs.at(i), v.toPointF()); - break; - case QVariant::Rect: - case QVariant::RectF: - { - QRectF r = v.toRectF(); - program()->setUniformValue(m_uniformLocs.at(i), r.x(), r.y(), r.width(), r.height()); - } - break; - case QVariant::Vector3D: - program()->setUniformValue(m_uniformLocs.at(i), qvariant_cast(v)); - break; - default: - break; - } - } - - const QQuickShaderEffectMaterial *oldMaterial = static_cast(oldEffect); - if (oldEffect == 0 || material->cullMode() != oldMaterial->cullMode()) { - switch (material->cullMode()) { - case QQuickShaderEffectMaterial::FrontFaceCulling: - glEnable(GL_CULL_FACE); - glCullFace(GL_FRONT); - break; - case QQuickShaderEffectMaterial::BackFaceCulling: - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); - break; - default: - glDisable(GL_CULL_FACE); - break; - } - } - - if ((state.isMatrixDirty()) && material->m_source.respectsMatrix) - program()->setUniformValue(m_matrixLoc, state.combinedMatrix()); -} - -char const *const *QQuickCustomMaterialShader::attributeNames() const -{ - return m_attributeNames.constData(); -} - -void QQuickCustomMaterialShader::initialize() -{ - m_opacityLoc = program()->uniformLocation("qt_Opacity"); - m_matrixLoc = program()->uniformLocation("qt_Matrix"); -} - -const char *QQuickCustomMaterialShader::vertexShader() const -{ - return m_key.vertexCode.constData(); -} - -const char *QQuickCustomMaterialShader::fragmentShader() const -{ - return m_key.fragmentCode.constData(); -} - - -bool QQuickShaderEffectMaterialKey::operator == (const QQuickShaderEffectMaterialKey &other) const -{ - return vertexCode == other.vertexCode && fragmentCode == other.fragmentCode && className == other.className; -} - -uint qHash(const QQuickShaderEffectMaterialKey &key) -{ - return qHash(qMakePair(qMakePair(key.vertexCode, key.fragmentCode), key.className)); -} - - -QHash > QQuickShaderEffectMaterial::materialMap; - -QQuickShaderEffectMaterial::QQuickShaderEffectMaterial() - : m_cullMode(NoCulling) -{ - setFlag(Blending, true); -} - -QSGMaterialType *QQuickShaderEffectMaterial::type() const -{ - return m_type.data(); -} - -QSGMaterialShader *QQuickShaderEffectMaterial::createShader() const -{ - return new QQuickCustomMaterialShader(m_source, m_source.attributeNames); -} - -int QQuickShaderEffectMaterial::compare(const QSGMaterial *other) const -{ - return this - static_cast(other); -} - -void QQuickShaderEffectMaterial::setCullMode(QQuickShaderEffectMaterial::CullMode face) -{ - m_cullMode = face; -} - -QQuickShaderEffectMaterial::CullMode QQuickShaderEffectMaterial::cullMode() const -{ - return m_cullMode; -} - -void QQuickShaderEffectMaterial::setProgramSource(const QQuickShaderEffectProgram &source) -{ - m_source = source; - m_type = materialMap.value(m_source); - if (m_type.isNull()) { - m_type = QSharedPointer(new QSGMaterialType); - materialMap.insert(m_source, m_type); - } -} - -void QQuickShaderEffectMaterial::setUniforms(const QVector > &uniformValues) -{ - m_uniformValues = uniformValues; -} - -void QQuickShaderEffectMaterial::setTextureProviders(const QVector > &textures) -{ - m_textures = textures; -} - -const QVector > &QQuickShaderEffectMaterial::textureProviders() const -{ - return m_textures; -} - -void QQuickShaderEffectMaterial::updateTextures() const -{ - for (int i = 0; i < m_textures.size(); ++i) { - if (QSGTextureProvider *provider = m_textures.at(i).second) { - if (QSGDynamicTexture *texture = qobject_cast(provider->texture())) - texture->updateTexture(); - } - } -} - - -QQuickShaderEffectNode::QQuickShaderEffectNode() -{ - QSGNode::setFlag(UsePreprocess, true); - setMaterial(&m_material); - -#ifdef QML_RUNTIME_TESTING - description = QLatin1String("shadereffect"); -#endif -} - -QQuickShaderEffectNode::~QQuickShaderEffectNode() -{ -} - -void QQuickShaderEffectNode::markDirtyTexture() -{ - markDirty(DirtyMaterial); -} - -void QQuickShaderEffectNode::preprocess() -{ - Q_ASSERT(material()); - static_cast(material())->updateTextures(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickshadereffectnode_p.h b/src/declarative/items/qquickshadereffectnode_p.h deleted file mode 100644 index 50213ff396..0000000000 --- a/src/declarative/items/qquickshadereffectnode_p.h +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKSHADEREFFECTNODE_P_H -#define QQUICKSHADEREFFECTNODE_P_H - -#include "qsgnode.h" -#include "qsgmaterial.h" -#include -#include - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -struct QQuickShaderEffectMaterialKey { - QByteArray vertexCode; - QByteArray fragmentCode; - const char *className; - - bool operator == (const QQuickShaderEffectMaterialKey &other) const; -}; - -uint qHash(const QQuickShaderEffectMaterialKey &key); - -// TODO: Implement support for multisampling. -struct QQuickShaderEffectProgram : public QQuickShaderEffectMaterialKey -{ - QQuickShaderEffectProgram() : respectsOpacity(false), respectsMatrix(false) {} - - QVector attributeNames; - QSet uniformNames; - - uint respectsOpacity : 1; - uint respectsMatrix : 1; -}; - - -class QQuickCustomMaterialShader; -class QQuickShaderEffectMaterial : public QSGMaterial -{ -public: - enum CullMode - { - NoCulling, - BackFaceCulling, - FrontFaceCulling - }; - - QQuickShaderEffectMaterial(); - virtual QSGMaterialType *type() const; - virtual QSGMaterialShader *createShader() const; - virtual int compare(const QSGMaterial *other) const; - - void setCullMode(CullMode face); - CullMode cullMode() const; - - void setProgramSource(const QQuickShaderEffectProgram &); - void setUniforms(const QVector > &uniformValues); - void setTextureProviders(const QVector > &textures); - const QVector > &textureProviders() const; - void updateTextures() const; - -protected: - friend class QQuickCustomMaterialShader; - - // The type pointer needs to be unique. It is not safe to let the type object be part of the - // QQuickShaderEffectMaterial, since it can be deleted and a new one constructed on top of the old - // one. The new QQuickShaderEffectMaterial would then get the same type pointer as the old one, and - // CustomMaterialShaders based on the old one would incorrectly be used together with the new - // one. To guarantee that the type pointer is unique, the type object must live as long as - // there are any CustomMaterialShaders of that type. - QSharedPointer m_type; - - QQuickShaderEffectProgram m_source; - QVector > m_uniformValues; - QVector > m_textures; - CullMode m_cullMode; - - static QHash > materialMap; -}; - - -class QSGShaderEffectMesh; - -class QQuickShaderEffectNode : public QObject, public QSGGeometryNode -{ - Q_OBJECT -public: - QQuickShaderEffectNode(); - virtual ~QQuickShaderEffectNode(); - - virtual void preprocess(); - - QQuickShaderEffectMaterial *shaderMaterial() { return &m_material; } - -private Q_SLOTS: - void markDirtyTexture(); - -private: - QQuickShaderEffectMaterial m_material; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QQUICKSHADEREFFECTNODE_P_H diff --git a/src/declarative/items/qquickshadereffectsource.cpp b/src/declarative/items/qquickshadereffectsource.cpp deleted file mode 100644 index 952f240cd3..0000000000 --- a/src/declarative/items/qquickshadereffectsource.cpp +++ /dev/null @@ -1,921 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qquickshadereffectsource_p.h" - -#include "qquickitem_p.h" -#include "qquickcanvas_p.h" -#include -#include - -#include "qopenglframebufferobject.h" -#include "qmath.h" -#include - -QT_BEGIN_NAMESPACE - -DEFINE_BOOL_CONFIG_OPTION(qmlFboOverlay, QML_FBO_OVERLAY) - -class QQuickShaderEffectSourceTextureProvider : public QSGTextureProvider -{ - Q_OBJECT -public: - QQuickShaderEffectSourceTextureProvider() - : sourceTexture(0) - { - } - - QSGTexture *texture() const { - sourceTexture->setMipmapFiltering(mipmapFiltering); - sourceTexture->setFiltering(filtering); - sourceTexture->setHorizontalWrapMode(horizontalWrap); - sourceTexture->setVerticalWrapMode(verticalWrap); - return sourceTexture; - } - - QQuickShaderEffectTexture *sourceTexture; - - QSGTexture::Filtering mipmapFiltering; - QSGTexture::Filtering filtering; - QSGTexture::WrapMode horizontalWrap; - QSGTexture::WrapMode verticalWrap; -}; -#include "qquickshadereffectsource.moc" - - -QQuickShaderEffectSourceNode::QQuickShaderEffectSourceNode() -{ - setFlag(UsePreprocess, true); -} - -void QQuickShaderEffectSourceNode::markDirtyTexture() -{ - markDirty(DirtyMaterial); -} - - -QQuickShaderEffectTexture::QQuickShaderEffectTexture(QQuickItem *shaderSource) - : QSGDynamicTexture() - , m_item(0) - , m_format(GL_RGBA) - , m_shaderSource(shaderSource) - , m_renderer(0) - , m_fbo(0) - , m_secondaryFbo(0) -#ifdef QSG_DEBUG_FBO_OVERLAY - , m_debugOverlay(0) -#endif - , m_context(QQuickItemPrivate::get(shaderSource)->sceneGraphContext()) - , m_mipmap(false) - , m_live(true) - , m_recursive(false) - , m_dirtyTexture(true) - , m_multisamplingSupportChecked(false) - , m_multisampling(false) - , m_grab(false) -{ -} - -QQuickShaderEffectTexture::~QQuickShaderEffectTexture() -{ - if (m_renderer) - disconnect(m_renderer, SIGNAL(sceneGraphChanged()), this, SLOT(markDirtyTexture())); - delete m_renderer; - delete m_fbo; - delete m_secondaryFbo; -#ifdef QSG_DEBUG_FBO_OVERLAY - delete m_debugOverlay; -#endif -} - -int QQuickShaderEffectTexture::textureId() const -{ - return m_fbo ? m_fbo->texture() : 0; -} - -bool QQuickShaderEffectTexture::hasAlphaChannel() const -{ - return m_format != GL_RGB; -} - -bool QQuickShaderEffectTexture::hasMipmaps() const -{ - return m_mipmap; -} - - -void QQuickShaderEffectTexture::bind() -{ -#ifndef QT_NO_DEBUG - if (!m_recursive && m_fbo && ((m_multisampling && m_secondaryFbo->isBound()) || m_fbo->isBound())) - qWarning("ShaderEffectSource: \'recursive\' must be set to true when rendering recursively."); -#endif - glBindTexture(GL_TEXTURE_2D, m_fbo ? m_fbo->texture() : 0); - updateBindOptions(); -} - -bool QQuickShaderEffectTexture::updateTexture() -{ - if ((m_live || m_grab) && m_dirtyTexture) { - grab(); - m_grab = false; - return true; - } - return false; -} - -void QQuickShaderEffectTexture::setHasMipmaps(bool mipmap) -{ - if (mipmap == m_mipmap) - return; - m_mipmap = mipmap; - if (m_mipmap && m_fbo && !m_fbo->format().mipmap()) - markDirtyTexture(); -} - - -void QQuickShaderEffectTexture::setItem(QSGNode *item) -{ - if (item == m_item) - return; - m_item = item; - markDirtyTexture(); -} - -void QQuickShaderEffectTexture::setRect(const QRectF &rect) -{ - if (rect == m_rect) - return; - m_rect = rect; - markDirtyTexture(); -} - -void QQuickShaderEffectTexture::setSize(const QSize &size) -{ - if (size == m_size) - return; - m_size = size; - markDirtyTexture(); -} - -void QQuickShaderEffectTexture::setFormat(GLenum format) -{ - if (format == m_format) - return; - m_format = format; - markDirtyTexture(); -} - -void QQuickShaderEffectTexture::setLive(bool live) -{ - if (live == m_live) - return; - m_live = live; - markDirtyTexture(); -} - -void QQuickShaderEffectTexture::scheduleUpdate() -{ - if (m_grab) - return; - m_grab = true; - if (m_dirtyTexture) - emit updateRequested(); -} - -void QQuickShaderEffectTexture::setRecursive(bool recursive) -{ - m_recursive = recursive; -} - -void QQuickShaderEffectTexture::markDirtyTexture() -{ - m_dirtyTexture = true; - if (m_live || m_grab) - emit updateRequested(); -} - -void QQuickShaderEffectTexture::grab() -{ - if (!m_item || m_size.isNull()) { - delete m_fbo; - delete m_secondaryFbo; - m_fbo = m_secondaryFbo = 0; - m_dirtyTexture = false; - if (m_grab) - emit scheduledUpdateCompleted(); - return; - } - QSGNode *root = m_item; - while (root->firstChild() && root->type() != QSGNode::RootNodeType) - root = root->firstChild(); - if (root->type() != QSGNode::RootNodeType) - return; - - if (!m_renderer) { - m_renderer = m_context->createRenderer(); - connect(m_renderer, SIGNAL(sceneGraphChanged()), this, SLOT(markDirtyTexture())); - } - m_renderer->setRootNode(static_cast(root)); - - bool deleteFboLater = false; - if (!m_fbo || m_fbo->size() != m_size || m_fbo->format().internalTextureFormat() != m_format - || (!m_fbo->format().mipmap() && m_mipmap)) - { - if (!m_multisamplingSupportChecked) { - QList 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 (m_multisampling) { - // Don't delete the FBO right away in case it is used recursively. - deleteFboLater = true; - delete m_secondaryFbo; - QOpenGLFramebufferObjectFormat format; - - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - format.setInternalTextureFormat(m_format); - format.setSamples(8); - m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format); - } else { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - format.setInternalTextureFormat(m_format); - format.setMipmap(m_mipmap); - if (m_recursive) { - deleteFboLater = true; - delete m_secondaryFbo; - m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format); - glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture()); - updateBindOptions(true); - } else { - delete m_fbo; - delete m_secondaryFbo; - m_fbo = new QOpenGLFramebufferObject(m_size, format); - m_secondaryFbo = 0; - glBindTexture(GL_TEXTURE_2D, m_fbo->texture()); - updateBindOptions(true); - } - } - } - - if (m_recursive && !m_secondaryFbo) { - // m_fbo already created, m_recursive was just set. - Q_ASSERT(m_fbo); - Q_ASSERT(!m_multisampling); - - m_secondaryFbo = new QOpenGLFramebufferObject(m_size, m_fbo->format()); - glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture()); - updateBindOptions(true); - } - - // Render texture. - root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip and opacity update. - m_renderer->nodeChanged(root, QSGNode::DirtyForceUpdate); // Force render list update. - -#ifdef QSG_DEBUG_FBO_OVERLAY - if (qmlFboOverlay()) { - if (!m_debugOverlay) - m_debugOverlay = m_context->createRectangleNode(); - m_debugOverlay->setRect(QRectF(0, 0, m_size.width(), m_size.height())); - m_debugOverlay->setColor(QColor(0xff, 0x00, 0x80, 0x40)); - m_debugOverlay->setPenColor(QColor()); - m_debugOverlay->setPenWidth(0); - m_debugOverlay->setRadius(0); - m_debugOverlay->update(); - root->appendChildNode(m_debugOverlay); - } -#endif - - m_dirtyTexture = false; - - QOpenGLContext *ctx = m_context->glContext(); - m_renderer->setDeviceRect(m_size); - m_renderer->setViewportRect(m_size); - QRectF mirrored(m_rect.left(), m_rect.bottom(), m_rect.width(), -m_rect.height()); - m_renderer->setProjectionMatrixToRect(mirrored); - m_renderer->setClearColor(Qt::transparent); - - if (m_multisampling) { - m_renderer->renderScene(QSGBindableFbo(m_secondaryFbo)); - - if (deleteFboLater) { - delete m_fbo; - QOpenGLFramebufferObjectFormat format; - format.setInternalTextureFormat(m_format); - format.setAttachment(QOpenGLFramebufferObject::NoAttachment); - format.setMipmap(m_mipmap); - format.setSamples(0); - m_fbo = new QOpenGLFramebufferObject(m_size, format); - glBindTexture(GL_TEXTURE_2D, m_fbo->texture()); - updateBindOptions(true); - } - - QRect r(QPoint(), m_size); - QOpenGLFramebufferObject::blitFramebuffer(m_fbo, r, m_secondaryFbo, r); - } else { - if (m_recursive) { - m_renderer->renderScene(QSGBindableFbo(m_secondaryFbo)); - - if (deleteFboLater) { - delete m_fbo; - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - format.setInternalTextureFormat(m_format); - format.setMipmap(m_mipmap); - m_fbo = new QOpenGLFramebufferObject(m_size, format); - glBindTexture(GL_TEXTURE_2D, m_fbo->texture()); - updateBindOptions(true); - } - qSwap(m_fbo, m_secondaryFbo); - } else { - m_renderer->renderScene(QSGBindableFbo(m_fbo)); - } - } - - if (m_mipmap) { - glBindTexture(GL_TEXTURE_2D, textureId()); - ctx->functions()->glGenerateMipmap(GL_TEXTURE_2D); - } - - root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip, opacity and render list update. - -#ifdef QSG_DEBUG_FBO_OVERLAY - if (qmlFboOverlay()) - root->removeChildNode(m_debugOverlay); -#endif - if (m_recursive) - markDirtyTexture(); // Continuously update if 'live' and 'recursive'. - - if (m_grab) - emit scheduledUpdateCompleted(); -} - -QImage QQuickShaderEffectTexture::toImage() const -{ - if (m_fbo) - return m_fbo->toImage(); - - return QImage(); -} - -/*! - \qmlclass ShaderEffectSource QQuickShaderEffectSource - \since 5.0 - \ingroup qml-basic-visual-elements - \brief The ShaderEffectSource element renders a QML element into a texture - and displays it. - \inherits Item - - The ShaderEffectSource element renders \l sourceItem into a texture and - displays it in the scene. \l sourceItem is drawn into the texture as though - it was a fully opaque root element. Thus \l sourceItem itself can be - invisible, but still appear in the texture. - - ShaderEffectSource can be used as: - \list - \o a texture source in a \l ShaderEffect. - This allows you to apply custom shader effects to any QML element. - \o a cache for a complex element. - The complex element can be rendered once into the texture, which can - then be animated freely without the need to render the complex element - again every frame. - \o an opacity layer. - ShaderEffectSource allows you to apply an opacity to elements as a group - rather than each element individually. - \endlist - - \table - \row - \o \image declarative-shadereffectsource.png - \o \qml - import QtQuick 2.0 - - Rectangle { - width: 200 - height: 100 - gradient: Gradient { - GradientStop { position: 0; color: "white" } - GradientStop { position: 1; color: "black" } - } - Row { - opacity: 0.5 - Item { - id: foo - width: 100; height: 100 - Rectangle { x: 5; y: 5; width: 60; height: 60; color: "red" } - Rectangle { x: 20; y: 20; width: 60; height: 60; color: "orange" } - Rectangle { x: 35; y: 35; width: 60; height: 60; color: "yellow" } - } - ShaderEffectSource { - width: 100; height: 100 - sourceItem: foo - } - } - } - \endqml - \endrow - \endtable - - The ShaderEffectSource element does not redirect any mouse or keyboard - input to \l sourceItem. If you hide the \l sourceItem by setting - \l{Item::visible}{visible} to false or \l{Item::opacity}{opacity} to zero, - it will no longer react to input. In cases where the ShaderEffectSource is - meant to replace the \l sourceItem, you typically want to hide the - \l sourceItem while still handling input. For this, you can use - the \l hideSource property. - - \note If \l sourceItem is a \l Rectangle with border, by default half the - border width falls outside the texture. To get the whole border, you can - extend the \l sourceRect. - - \warning In most cases, using a ShaderEffectSource will decrease - performance, and in all cases, it will increase video memory usage. - Rendering through a ShaderEffectSource might also lead to lower quality - since some OpenGL implementations support multisampled backbuffer, - but not multisampled framebuffer objects. -*/ - -QQuickShaderEffectSource::QQuickShaderEffectSource(QQuickItem *parent) - : QQuickItem(parent) - , m_provider(0) - , m_texture(0) - , m_wrapMode(ClampToEdge) - , m_sourceItem(0) - , m_textureSize(0, 0) - , m_format(RGBA) - , m_live(true) - , m_hideSource(false) - , m_mipmap(false) - , m_recursive(false) - , m_grab(true) -{ - setFlag(ItemHasContents); -} - -QQuickShaderEffectSource::~QQuickShaderEffectSource() -{ - if (m_texture) - m_texture->deleteLater(); - - if (m_provider) - m_provider->deleteLater(); - - if (m_sourceItem) { - QQuickItemPrivate *sd = QQuickItemPrivate::get(m_sourceItem); - sd->removeItemChangeListener(this, QQuickItemPrivate::Geometry); - sd->derefFromEffectItem(m_hideSource); - } -} - -void QQuickShaderEffectSource::ensureTexture() -{ - if (m_texture) - return; - - Q_ASSERT_X(QQuickItemPrivate::get(this)->canvas - && QQuickItemPrivate::get(this)->sceneGraphContext() - && QThread::currentThread() == QQuickItemPrivate::get(this)->sceneGraphContext()->thread(), - "QQuickShaderEffectSource::ensureTexture", - "Cannot be used outside the rendering thread"); - - m_texture = new QQuickShaderEffectTexture(this); - connect(m_texture, SIGNAL(updateRequested()), this, SLOT(update())); - connect(m_texture, SIGNAL(scheduledUpdateCompleted()), this, SIGNAL(scheduledUpdateCompleted())); -} - -QSGTextureProvider *QQuickShaderEffectSource::textureProvider() const -{ - if (!m_provider) { - // Make sure it gets thread affinity on the rendering thread so deletion works properly.. - Q_ASSERT_X(QQuickItemPrivate::get(this)->canvas - && QQuickItemPrivate::get(this)->sceneGraphContext() - && QThread::currentThread() == QQuickItemPrivate::get(this)->sceneGraphContext()->thread(), - "QQuickShaderEffectSource::textureProvider", - "Cannot be used outside the rendering thread"); - const_cast(this)->m_provider = new QQuickShaderEffectSourceTextureProvider(); - const_cast(this)->ensureTexture(); - connect(m_texture, SIGNAL(updateRequested()), m_provider, SIGNAL(textureChanged())); - m_provider->sourceTexture = m_texture; - } - return m_provider; -} - -/*! - \qmlproperty enumeration ShaderEffectSource::wrapMode - - This property defines the OpenGL wrap modes associated with the texture. - Modifying this property makes most sense when the element is used as a - source texture of a \l ShaderEffect. - - \list - \o ShaderEffectSource.ClampToEdge - GL_CLAMP_TO_EDGE both horizontally and vertically - \o ShaderEffectSource.RepeatHorizontally - GL_REPEAT horizontally, GL_CLAMP_TO_EDGE vertically - \o ShaderEffectSource.RepeatVertically - GL_CLAMP_TO_EDGE horizontally, GL_REPEAT vertically - \o ShaderEffectSource.Repeat - GL_REPEAT both horizontally and vertically - \endlist - - \note Some OpenGL ES 2 implementations do not support the GL_REPEAT - wrap mode with non-power-of-two textures. -*/ - -QQuickShaderEffectSource::WrapMode QQuickShaderEffectSource::wrapMode() const -{ - return m_wrapMode; -} - -void QQuickShaderEffectSource::setWrapMode(WrapMode mode) -{ - if (mode == m_wrapMode) - return; - m_wrapMode = mode; - update(); - emit wrapModeChanged(); -} - -/*! - \qmlproperty Item ShaderEffectSource::sourceItem - - This property holds the element to be rendered into the texture. -*/ - -QQuickItem *QQuickShaderEffectSource::sourceItem() const -{ - return m_sourceItem; -} - -void QQuickShaderEffectSource::itemGeometryChanged(QQuickItem *item, const QRectF &newRect, const QRectF &oldRect) -{ - Q_ASSERT(item == m_sourceItem); - Q_UNUSED(item); - if (newRect.size() != oldRect.size()) - update(); -} - -void QQuickShaderEffectSource::setSourceItem(QQuickItem *item) -{ - if (item == m_sourceItem) - return; - if (m_sourceItem) { - QQuickItemPrivate *d = QQuickItemPrivate::get(m_sourceItem); - d->derefFromEffectItem(m_hideSource); - d->removeItemChangeListener(this, QQuickItemPrivate::Geometry); - } - m_sourceItem = item; - if (m_sourceItem) { - // TODO: Find better solution. - // 'm_sourceItem' 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 (m_sourceItem->parentItem() == 0) { - m_sourceItem->setParentItem(this); - m_sourceItem->setVisible(false); - } - QQuickItemPrivate *d = QQuickItemPrivate::get(m_sourceItem); - d->refFromEffectItem(m_hideSource); - d->addItemChangeListener(this, QQuickItemPrivate::Geometry); - } - update(); - emit sourceItemChanged(); -} - -/*! - \qmlproperty rect ShaderEffectSource::sourceRect - - This property defines which rectangular area of the \l sourceItem to - render into the texture. The source rectangle can be larger than - \l sourceItem itself. If the rectangle is null, which is the default, - the whole \l sourceItem is rendered to texture. -*/ - -QRectF QQuickShaderEffectSource::sourceRect() const -{ - return m_sourceRect; -} - -void QQuickShaderEffectSource::setSourceRect(const QRectF &rect) -{ - if (rect == m_sourceRect) - return; - m_sourceRect = rect; - update(); - emit sourceRectChanged(); -} - -/*! - \qmlproperty size ShaderEffectSource::textureSize - - This property holds the requested size of the texture. If it is empty, - which is the default, the size of the source rectangle is used. - - \note Some platforms have a limit on how small framebuffer objects can be, - which means the actual texture size might be larger than the requested - size. -*/ - -QSize QQuickShaderEffectSource::textureSize() const -{ - return m_textureSize; -} - -void QQuickShaderEffectSource::setTextureSize(const QSize &size) -{ - if (size == m_textureSize) - return; - m_textureSize = size; - update(); - emit textureSizeChanged(); -} - -/*! - \qmlproperty enumeration ShaderEffectSource::format - - This property defines the internal OpenGL format of the texture. - Modifying this property makes most sense when the element is used as a - source texture of a \l ShaderEffect. Depending on the OpenGL - implementation, this property might allow you to save some texture memory. - - \list - \o ShaderEffectSource.Alpha - GL_ALPHA - \o ShaderEffectSource.RGB - GL_RGB - \o ShaderEffectSource.RGBA - GL_RGBA - \endlist - - \note Some OpenGL implementations do not support the GL_ALPHA format. -*/ - -QQuickShaderEffectSource::Format QQuickShaderEffectSource::format() const -{ - return m_format; -} - -void QQuickShaderEffectSource::setFormat(QQuickShaderEffectSource::Format format) -{ - if (format == m_format) - return; - m_format = format; - update(); - emit formatChanged(); -} - -/*! - \qmlproperty bool ShaderEffectSource::live - - If this property is true, the texture is updated whenever the - \l sourceItem changes. Otherwise, it will be a frozen image of the - \l sourceItem. The property is true by default. -*/ - -bool QQuickShaderEffectSource::live() const -{ - return m_live; -} - -void QQuickShaderEffectSource::setLive(bool live) -{ - if (live == m_live) - return; - m_live = live; - update(); - emit liveChanged(); -} - -/*! - \qmlproperty bool ShaderEffectSource::hideSource - - If this property is true, the \l sourceItem is hidden, though it will still - be rendered into the texture. As opposed to hiding the \l sourceItem by - setting \l{Item::visible}{visible} to false, setting this property to true - will not prevent mouse or keyboard input from reaching \l sourceItem. - The property is useful when the ShaderEffectSource is anchored on top of, - and meant to replace the \l sourceItem. -*/ - -bool QQuickShaderEffectSource::hideSource() const -{ - return m_hideSource; -} - -void QQuickShaderEffectSource::setHideSource(bool hide) -{ - if (hide == m_hideSource) - return; - if (m_sourceItem) { - QQuickItemPrivate::get(m_sourceItem)->refFromEffectItem(hide); - QQuickItemPrivate::get(m_sourceItem)->derefFromEffectItem(m_hideSource); - } - m_hideSource = hide; - update(); - emit hideSourceChanged(); -} - -/*! - \qmlproperty bool ShaderEffectSource::mipmap - - If this property is true, mipmaps are generated for the texture. - - \note Some OpenGL ES 2 implementations do not support mipmapping of - non-power-of-two textures. -*/ - -bool QQuickShaderEffectSource::mipmap() const -{ - return m_mipmap; -} - -void QQuickShaderEffectSource::setMipmap(bool enabled) -{ - if (enabled == m_mipmap) - return; - m_mipmap = enabled; - update(); - emit mipmapChanged(); -} - -/*! - \qmlproperty bool ShaderEffectSource::recursive - - Set this property to true if the ShaderEffectSource has a dependency on - itself. ShaderEffectSources form a dependency chain, where one - ShaderEffectSource can be part of the \l sourceItem of another. - If there is a loop in this chain, a ShaderEffectSource could end up trying - to render into the same texture it is using as source, which is not allowed - by OpenGL. When this property is set to true, an extra texture is allocated - so that ShaderEffectSource can keep a copy of the texture from the previous - frame. It can then render into one texture and use the texture from the - previous frame as source. - - Setting both this property and \l live to true will cause the scene graph - to render continuously. Since the ShaderEffectSource depends on itself, - updating it means that it immediately becomes dirty again. -*/ - -bool QQuickShaderEffectSource::recursive() const -{ - return m_recursive; -} - -void QQuickShaderEffectSource::setRecursive(bool enabled) -{ - if (enabled == m_recursive) - return; - m_recursive = enabled; - emit recursiveChanged(); -} - -/*! - \qmlmethod ShaderEffectSource::scheduleUpdate() - - Schedules a re-rendering of the texture for the next frame. - Use this to update the texture when \l live is false. -*/ - -void QQuickShaderEffectSource::scheduleUpdate() -{ - if (m_grab) - return; - m_grab = true; - update(); -} - -static void get_wrap_mode(QQuickShaderEffectSource::WrapMode mode, QSGTexture::WrapMode *hWrap, QSGTexture::WrapMode *vWrap) -{ - switch (mode) { - case QQuickShaderEffectSource::RepeatHorizontally: - *hWrap = QSGTexture::Repeat; - *vWrap = QSGTexture::ClampToEdge; - break; - case QQuickShaderEffectSource::RepeatVertically: - *vWrap = QSGTexture::Repeat; - *hWrap = QSGTexture::ClampToEdge; - break; - case QQuickShaderEffectSource::Repeat: - *hWrap = *vWrap = QSGTexture::Repeat; - break; - default: - // QQuickShaderEffectSource::ClampToEdge - *hWrap = *vWrap = QSGTexture::ClampToEdge; - break; - } -} - - -QSGNode *QQuickShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - if (!m_sourceItem || m_sourceItem->width() == 0 || m_sourceItem->height() == 0) { - delete oldNode; - return 0; - } - - ensureTexture(); - - QQuickShaderEffectTexture *tex = qobject_cast(m_texture); - tex->setLive(m_live); - tex->setItem(QQuickItemPrivate::get(m_sourceItem)->itemNode()); - QRectF sourceRect = m_sourceRect.width() == 0 || m_sourceRect.height() == 0 - ? QRectF(0, 0, m_sourceItem->width(), m_sourceItem->height()) - : m_sourceRect; - tex->setRect(sourceRect); - QSize textureSize = m_textureSize.isEmpty() - ? QSize(qCeil(qAbs(sourceRect.width())), qCeil(qAbs(sourceRect.height()))) - : m_textureSize; - Q_ASSERT(!textureSize.isEmpty()); - QQuickItemPrivate *d = static_cast(QObjectPrivate::get(this)); - const QSize minTextureSize = d->sceneGraphContext()->minimumFBOSize(); - // Keep power-of-two by doubling the size. - while (textureSize.width() < minTextureSize.width()) - textureSize.rwidth() *= 2; - while (textureSize.height() < minTextureSize.height()) - textureSize.rheight() *= 2; - - tex->setSize(textureSize); - tex->setRecursive(m_recursive); - tex->setFormat(GLenum(m_format)); - tex->setHasMipmaps(m_mipmap); - - if (m_grab) - tex->scheduleUpdate(); - m_grab = false; - - QSGTexture::Filtering filtering = QQuickItemPrivate::get(this)->smooth - ? QSGTexture::Linear - : QSGTexture::Nearest; - QSGTexture::Filtering mmFiltering = m_mipmap ? filtering : QSGTexture::None; - QSGTexture::WrapMode hWrap, vWrap; - get_wrap_mode(m_wrapMode, &hWrap, &vWrap); - - if (m_provider) { - m_provider->mipmapFiltering = mmFiltering; - m_provider->filtering = filtering; - m_provider->horizontalWrap = hWrap; - m_provider->verticalWrap = vWrap; - } - - // Don't create the paint node if we're not spanning any area - if (width() == 0 || height() == 0) { - delete oldNode; - return 0; - } - - QQuickShaderEffectSourceNode *node = static_cast(oldNode); - if (!node) { - node = new QQuickShaderEffectSourceNode; - node->setTexture(m_texture); - connect(m_texture, SIGNAL(updateRequested()), node, SLOT(markDirtyTexture())); - } - - // If live and recursive, update continuously. - if (m_live && m_recursive) - node->markDirty(QSGNode::DirtyMaterial); - - node->setMipmapFiltering(mmFiltering); - node->setFiltering(filtering); - node->setHorizontalWrapMode(hWrap); - node->setVerticalWrapMode(vWrap); - node->setTargetRect(QRectF(0, 0, width(), height())); - node->setSourceRect(QRectF(0, 0, 1, 1)); - node->update(); - - return node; -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickshadereffectsource_p.h b/src/declarative/items/qquickshadereffectsource_p.h deleted file mode 100644 index fee361c27c..0000000000 --- a/src/declarative/items/qquickshadereffectsource_p.h +++ /dev/null @@ -1,259 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 QQUICKSHADEREFFECTSOURCE_P_H -#define QQUICKSHADEREFFECTSOURCE_P_H - -#include "qquickitem.h" -#include -#include -#include -#include -#include - -#include "qpointer.h" -#include "qsize.h" -#include "qrect.h" - -#define QSG_DEBUG_FBO_OVERLAY - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGNode; -class UpdatePaintNodeData; -class QOpenGLFramebufferObject; - -class QQuickShaderEffectSourceTextureProvider; - -class QQuickShaderEffectSourceNode : public QObject, public QSGDefaultImageNode -{ - Q_OBJECT - -public: - QQuickShaderEffectSourceNode(); - -private Q_SLOTS: - void markDirtyTexture(); -}; - -class Q_DECLARATIVE_EXPORT QQuickShaderEffectTexture : public QSGDynamicTexture -{ - Q_OBJECT -public: - QQuickShaderEffectTexture(QQuickItem *shaderSource); - ~QQuickShaderEffectTexture(); - - virtual bool updateTexture(); - - // The item's "paint node", not effect node. - QSGNode *item() const { return m_item; } - void setItem(QSGNode *item); - - QRectF rect() const { return m_rect; } - void setRect(const QRectF &rect); - - QSize size() const { return m_size; } - void setSize(const QSize &size); - - void setHasMipmaps(bool mipmap); - - void bind(); - - bool hasAlphaChannel() const; - bool hasMipmaps() const; - int textureId() const; - QSize textureSize() const { return m_size; } - - GLenum format() const { return m_format; } - void setFormat(GLenum format); - - bool live() const { return bool(m_live); } - void setLive(bool live); - - bool recursive() const { return bool(m_recursive); } - void setRecursive(bool recursive); - - void scheduleUpdate(); - - QImage toImage() const; - -Q_SIGNALS: - void updateRequested(); - void scheduledUpdateCompleted(); - -public Q_SLOTS: - void markDirtyTexture(); - -private: - void grab(); - - QSGNode *m_item; - QRectF m_rect; - QSize m_size; - GLenum m_format; - - QQuickItem *m_shaderSource; - QSGRenderer *m_renderer; - QOpenGLFramebufferObject *m_fbo; - QOpenGLFramebufferObject *m_secondaryFbo; - -#ifdef QSG_DEBUG_FBO_OVERLAY - QSGRectangleNode *m_debugOverlay; -#endif - - QSGContext *m_context; - - uint m_mipmap : 1; - uint m_live : 1; - uint m_recursive : 1; - uint m_dirtyTexture : 1; - uint m_multisamplingSupportChecked : 1; - uint m_multisampling : 1; - uint m_grab : 1; -}; - -class Q_DECLARATIVE_EXPORT QQuickShaderEffectSource : public QQuickItem, public QQuickItemChangeListener -{ - Q_OBJECT - Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged) - Q_PROPERTY(QQuickItem *sourceItem READ sourceItem WRITE setSourceItem NOTIFY sourceItemChanged) - Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged) - Q_PROPERTY(QSize textureSize READ textureSize WRITE setTextureSize NOTIFY textureSizeChanged) - Q_PROPERTY(Format format READ format WRITE setFormat NOTIFY formatChanged) - Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged) - Q_PROPERTY(bool hideSource READ hideSource WRITE setHideSource NOTIFY hideSourceChanged) - Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged) - Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged) - - Q_ENUMS(Format WrapMode) -public: - enum WrapMode { - ClampToEdge, - RepeatHorizontally, - RepeatVertically, - Repeat - }; - - enum Format { - Alpha = GL_ALPHA, - RGB = GL_RGB, - RGBA = GL_RGBA - }; - - QQuickShaderEffectSource(QQuickItem *parent = 0); - ~QQuickShaderEffectSource(); - - WrapMode wrapMode() const; - void setWrapMode(WrapMode mode); - - QQuickItem *sourceItem() const; - void setSourceItem(QQuickItem *item); - - QRectF sourceRect() const; - void setSourceRect(const QRectF &rect); - - QSize textureSize() const; - void setTextureSize(const QSize &size); - - Format format() const; - void setFormat(Format format); - - bool live() const; - void setLive(bool live); - - bool hideSource() const; - void setHideSource(bool hide); - - bool mipmap() const; - void setMipmap(bool enabled); - - bool recursive() const; - void setRecursive(bool enabled); - - bool isTextureProvider() const { return true; } - QSGTextureProvider *textureProvider() const; - - Q_INVOKABLE void scheduleUpdate(); - -Q_SIGNALS: - void wrapModeChanged(); - void sourceItemChanged(); - void sourceRectChanged(); - void textureSizeChanged(); - void formatChanged(); - void liveChanged(); - void hideSourceChanged(); - void mipmapChanged(); - void recursiveChanged(); - - void scheduledUpdateCompleted(); - -protected: - virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - - virtual void itemGeometryChanged(QQuickItem *item, const QRectF &newRect, const QRectF &oldRect); - -private: - void ensureTexture(); - - QQuickShaderEffectSourceTextureProvider *m_provider; - QQuickShaderEffectTexture *m_texture; - WrapMode m_wrapMode; - QPointer m_sourceItem; - QRectF m_sourceRect; - QSize m_textureSize; - Format m_format; - uint m_live : 1; - uint m_hideSource : 1; - uint m_mipmap : 1; - uint m_recursive : 1; - uint m_grab : 1; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QQUICKSHADEREFFECTSOURCE_P_H diff --git a/src/declarative/items/qquicksprite.cpp b/src/declarative/items/qquicksprite.cpp deleted file mode 100644 index b476905269..0000000000 --- a/src/declarative/items/qquicksprite.cpp +++ /dev/null @@ -1,130 +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$ -** 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 "qquicksprite_p.h" -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass Sprite QQuickSprite - \inqmlmodule QtQuick 2 - \brief The Sprite element represents a sprite animation - -*/ -/*! - \qmlproperty int QtQuick2::Sprite::duration - - Time between frames. -*/ -/*! - \qmlproperty int QtQuick2::Sprite::durationVariation - - The time between frames can vary by up to this amount. - - Default is 0. -*/ - -/*! - \qmlproperty string QtQuick2::Sprite::name - - The name of this sprite, for use in the to property of other sprites. -*/ -/*! - \qmlproperty QVariantMap QtQuick2::Sprite::to - - A list of other sprites and weighted transitions to them, - for example {"a":1, "b":2, "c":0} would specify that one-third should - transition to sprite "a" when this sprite is done, and two-thirds should - transition to sprite "b" when this sprite is done. As the transitions are - chosen randomly, these proportions will not be exact. With "c":0 in the list, - no sprites will randomly transition to "c", but it wll be a valid path if a sprite - goal is set. - - If no list is specified, or the sum of weights in the list is zero, then the sprite - will repeat itself after completing. -*/ -/*! - \qmlproperty int QtQuick2::Sprite::frames - - Number of frames in this sprite. -*/ -/*! - \qmlproperty int QtQuick2::Sprite::frameHeight - - Height of a single frame in this sprite. -*/ -/*! - \qmlproperty int QtQuick2::Sprite::frameWidth - - Width of a single frame in this sprite. -*/ -/*! - \qmlproperty url QtQuick2::Sprite::source - - The image source for the animation. - - If frameHeight and frameWidth are not specified, it is assumed to be a single long row of square frames. - Otherwise, it can be multiple contiguous rows or rectangluar frames, when one row runs out the next will be used. -*/ - Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) - Q_PROPERTY(int durationVariation READ durationVariance WRITE setDurationVariance NOTIFY durationVarianceChanged) - Q_PROPERTY(QVariantMap to READ to WRITE setTo NOTIFY toChanged) - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - Q_PROPERTY(qreal speedModifiesDuration READ speedModifer WRITE setSpeedModifier NOTIFY speedModifierChanged) - Q_PROPERTY(int frames READ frames WRITE setFrames NOTIFY framesChanged) - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - //If frame height or width is not specified, it is assumed to be a single long row of square frames. - //Otherwise, it can be multiple contiguous rows, when one row runs out the next will be used. - Q_PROPERTY(int frameHeight READ frameHeight WRITE setFrameHeight NOTIFY frameHeightChanged) - Q_PROPERTY(int frameWidth READ frameWidth WRITE setFrameWidth NOTIFY frameWidthChanged) - -QQuickSprite::QQuickSprite(QObject *parent) : - QQuickStochasticState(parent) - , m_generatedCount(0) - , m_framesPerRow(0) - , m_frameHeight(0) - , m_frameWidth(0) - , m_rowY(0) -{ -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquicksprite_p.h b/src/declarative/items/qquicksprite_p.h deleted file mode 100644 index e7f3bbce80..0000000000 --- a/src/declarative/items/qquicksprite_p.h +++ /dev/null @@ -1,136 +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$ -** 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 QQUICKSPRITE_P_H -#define QQUICKSPRITE_P_H - -#include -#include -#include -#include -#include "qquickspriteengine_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QQuickSprite : public QQuickStochasticState -{ - Q_OBJECT - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - //If frame height or width is not specified, it is assumed to be a single long row of square frames. - //Otherwise, it can be multiple contiguous rows, when one row runs out the next will be used. - Q_PROPERTY(int frameHeight READ frameHeight WRITE setFrameHeight NOTIFY frameHeightChanged) - Q_PROPERTY(int frameWidth READ frameWidth WRITE setFrameWidth NOTIFY frameWidthChanged) - -public: - explicit QQuickSprite(QObject *parent = 0); - - QUrl source() const - { - return m_source; - } - - int frameHeight() const - { - return m_frameHeight; - } - - int frameWidth() const - { - return m_frameWidth; - } - - -signals: - - void sourceChanged(QUrl arg); - - void frameHeightChanged(int arg); - - void frameWidthChanged(int arg); - -public slots: - - void setSource(QUrl arg) - { - if (m_source != arg) { - m_source = arg; - emit sourceChanged(arg); - } - } - - void setFrameHeight(int arg) - { - if (m_frameHeight != arg) { - m_frameHeight = arg; - emit frameHeightChanged(arg); - } - } - - void setFrameWidth(int arg) - { - if (m_frameWidth != arg) { - m_frameWidth = arg; - emit frameWidthChanged(arg); - } - } - - -private: - friend class QSGImageParticle; - friend class QQuickSpriteEngine; - friend class QQuickStochasticEngine; - int m_generatedCount; - int m_framesPerRow; - QUrl m_source; - int m_frameHeight; - int m_frameWidth; - int m_rowY; - -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // QQUICKSPRITE_P_H diff --git a/src/declarative/items/qquickspriteengine.cpp b/src/declarative/items/qquickspriteengine.cpp deleted file mode 100644 index c25ccf3487..0000000000 --- a/src/declarative/items/qquickspriteengine.cpp +++ /dev/null @@ -1,501 +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$ -** 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 "qquickspriteengine_p.h" -#include "qquicksprite_p.h" -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/* TODO: - make sharable? - solve the state data initialization/transfer issue so as to not need to make friends -*/ - -QQuickStochasticEngine::QQuickStochasticEngine(QObject *parent) : - QObject(parent), m_timeOffset(0) -{ - //Default size 1 - setCount(1); - m_advanceTime.start(); -} - -QQuickStochasticEngine::QQuickStochasticEngine(QList states, QObject *parent) : - QObject(parent), m_states(states), m_timeOffset(0) -{ - //Default size 1 - setCount(1); - m_advanceTime.start(); -} - -QQuickStochasticEngine::~QQuickStochasticEngine() -{ -} - -QQuickSpriteEngine::QQuickSpriteEngine(QObject *parent) - : QQuickStochasticEngine(parent) -{ -} - -QQuickSpriteEngine::QQuickSpriteEngine(QList sprites, QObject *parent) - : QQuickStochasticEngine(parent) -{ - foreach (QQuickSprite* sprite, sprites) - m_states << (QQuickStochasticState*)sprite; -} - -QQuickSpriteEngine::~QQuickSpriteEngine() -{ -} - - -int QQuickSpriteEngine::maxFrames() -{ - return m_maxFrames; -} - -/* States too large to fit in one row are split into multiple rows - This is more efficient for the implementation, but should remain an implementation detail (invisible from QML) - Therefore the below functions abstract sprite from the viewpoint of classes that pass the details onto shaders - 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 -TODO: Above idea needs to have the varying duration offset added to it -*/ -int QQuickSpriteEngine::spriteState(int sprite) -{ - int state = m_things[sprite]; - if (!m_sprites[state]->m_generatedCount) - return state; - int rowDuration = m_duration[sprite] * m_sprites[state]->m_framesPerRow; - int extra = (m_timeOffset - m_startTimes[sprite])/rowDuration; - return state + extra; -} - -int QQuickSpriteEngine::spriteStart(int sprite) -{ - int state = m_things[sprite]; - if (!m_sprites[state]->m_generatedCount) - return m_startTimes[sprite]; - int rowDuration = m_duration[sprite] * m_sprites[state]->m_framesPerRow; - int extra = (m_timeOffset - m_startTimes[sprite])/rowDuration; - return state + extra*rowDuration; -} - -int QQuickSpriteEngine::spriteFrames(int sprite) -{ - int state = m_things[sprite]; - if (!m_sprites[state]->m_generatedCount) - return m_sprites[state]->frames(); - int rowDuration = m_duration[sprite] * m_sprites[state]->m_framesPerRow; - int extra = (m_timeOffset - m_startTimes[sprite])/rowDuration; - if (extra == m_sprites[state]->m_generatedCount - 1)//last state - return m_sprites[state]->frames() % m_sprites[state]->m_framesPerRow; - else - return m_sprites[state]->m_framesPerRow; -} - -int QQuickSpriteEngine::spriteDuration(int sprite) -{ - int state = m_things[sprite]; - if (!m_sprites[state]->m_generatedCount) - return m_duration[sprite]; - int rowDuration = m_duration[sprite] * m_sprites[state]->m_framesPerRow; - int extra = (m_timeOffset - m_startTimes[sprite])/rowDuration; - if (extra == m_sprites[state]->m_generatedCount - 1)//last state - return (m_duration[sprite] * m_sprites[state]->frames()) % rowDuration; - else - return rowDuration; -} - -int QQuickSpriteEngine::spriteY(int sprite) -{ - int state = m_things[sprite]; - if (!m_sprites[state]->m_generatedCount) - return m_sprites[state]->m_rowY; - int rowDuration = m_duration[sprite] * m_sprites[state]->m_framesPerRow; - int extra = (m_timeOffset - m_startTimes[sprite])/rowDuration; - return m_sprites[state]->m_rowY + m_sprites[state]->m_frameHeight * extra; -} - -int QQuickSpriteEngine::spriteWidth(int sprite) -{ - int state = m_things[sprite]; - return m_sprites[state]->m_frameWidth; -} - -int QQuickSpriteEngine::spriteHeight(int sprite) -{ - int state = m_things[sprite]; - return m_sprites[state]->m_frameHeight; -} - -int QQuickSpriteEngine::spriteCount()//TODO: Actually image state count, need to rename these things to make sense together -{ - return m_imageStateCount; -} - -void QQuickStochasticEngine::setGoal(int state, int sprite, bool jump) -{ - if (sprite >= m_things.count() || state >= m_states.count() - || sprite < 0 || state < 0) - return; - if (!jump){ - m_goals[sprite] = state; - return; - } - - if (m_things[sprite] == state) - return;//Already there - m_things[sprite] = state; - m_duration[sprite] = m_states[state]->variedDuration(); - m_goals[sprite] = -1; - restart(sprite); - emit stateChanged(sprite); - emit m_states[state]->entered(); - return; -} - -QImage QQuickSpriteEngine::assembledImage() -{ - int h = 0; - int w = 0; - m_maxFrames = 0; - m_imageStateCount = 0; - int maxSize = 0; - - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize); - foreach (QQuickStochasticState* s, m_states){ - QQuickSprite* sprite = qobject_cast(s); - if (sprite) - m_sprites << sprite; - else - qDebug() << "Error: Non-sprite in QQuickSpriteEngine"; - } - - foreach (QQuickSprite* state, m_sprites){ - if (state->frames() > m_maxFrames) - m_maxFrames = state->frames(); - - QImage img(state->source().toLocalFile()); - if (img.isNull()) { - qWarning() << "SpriteEngine: loading image failed..." << state->source().toLocalFile(); - return QImage(); - } - - //Check that the frame sizes are the same within one engine - if (!state->m_frameWidth) - state->m_frameWidth = img.width() / state->frames(); - - if (!state->m_frameHeight) - state->m_frameHeight = img.height(); - - if (state->frames() * state->frameWidth() > maxSize){ - struct helper{ - static int divRoundUp(int a, int b){return (a+b-1)/b;} - }; - int rowsNeeded = helper::divRoundUp(state->frames(), helper::divRoundUp(maxSize, state->frameWidth())); - if (rowsNeeded * state->frameHeight() > maxSize){ - qWarning() << "SpriteEngine: Animation too large to fit in one texture..." << state->source().toLocalFile(); - qWarning() << "SpriteEngine: Your texture max size today is " << maxSize; - } - state->m_generatedCount = rowsNeeded; - h += state->frameHeight() * rowsNeeded; - w = qMax(w, helper::divRoundUp(maxSize, state->frameWidth())); - m_imageStateCount += rowsNeeded; - }else{ - h += state->frameHeight(); - w = qMax(w, state->frameWidth() * state->frames()); - m_imageStateCount++; - } - } - - //maxFrames is max number in a line of the texture - QImage image(w, h, QImage::Format_ARGB32); - image.fill(0); - QPainter p(&image); - int y = 0; - foreach (QQuickSprite* state, m_sprites){ - QImage img(state->source().toLocalFile()); - int frameWidth = state->m_frameWidth; - int frameHeight = state->m_frameHeight; - if (img.height() == frameHeight && img.width() < maxSize){//Simple case - p.drawImage(0,y,img); - state->m_rowY = y; - y += frameHeight; - }else{//Chopping up image case - state->m_framesPerRow = image.width()/frameWidth; - state->m_rowY = y; - int x = 0; - int curX = 0; - int curY = 0; - int framesLeft = state->frames(); - while (framesLeft > 0){ - if (image.width() - x + curX <= img.width()){//finish a row in image (dest) - int copied = image.width() - x; - Q_ASSERT(!(copied % frameWidth));//XXX: Just checking - framesLeft -= copied/frameWidth; - p.drawImage(x,y,img.copy(curX,curY,copied,frameHeight)); - y += frameHeight; - curX += copied; - x = 0; - if (curX == img.width()){ - curX = 0; - curY += frameHeight; - } - }else{//finish a row in img (src) - int copied = img.width() - curX; - Q_ASSERT(!(copied % frameWidth));//XXX: Just checking - framesLeft -= copied/frameWidth; - p.drawImage(x,y,img.copy(curX,curY,copied,frameHeight)); - curY += frameHeight; - x += copied; - curX = 0; - } - } - if (x) - y += frameHeight; - } - } - - if (image.height() > maxSize){ - qWarning() << "SpriteEngine: Too many animations to fit in one texture..."; - qWarning() << "SpriteEngine: Your texture max size today is " << maxSize; - return QImage(); - } - return image; -} - -void QQuickStochasticEngine::setCount(int c) -{ - m_things.resize(c); - m_goals.resize(c); - m_duration.resize(c); - m_startTimes.resize(c); -} - -void QQuickStochasticEngine::start(int index, int state) -{ - if (index >= m_things.count()) - return; - m_things[index] = state; - m_duration[index] = m_states[state]->variedDuration(); - m_goals[index] = -1; - restart(index); -} - -void QQuickStochasticEngine::stop(int index) -{ - if (index >= m_things.count()) - return; - //Will never change until start is called again with a new state - this is not a 'pause' - for (int i=0; iframes() + m_startTimes[index]; - for (int i=0; i changedIndexes; - while (!m_stateUpdates.isEmpty() && time >= m_stateUpdates.first().first){ - foreach (int idx, m_stateUpdates.first().second){ - if (idx >= m_things.count()) - continue;//TODO: Proper fix(because this does happen and I'm just ignoring it) - int stateIdx = m_things[idx]; - int nextIdx = -1; - int goalPath = goalSeek(stateIdx, idx); - if (goalPath == -1){//Random - qreal r =(qreal) qrand() / (qreal) RAND_MAX; - qreal total = 0.0; - for (QVariantMap::const_iterator iter=m_states[stateIdx]->m_to.constBegin(); - iter!=m_states[stateIdx]->m_to.constEnd(); iter++) - total += (*iter).toReal(); - r*=total; - for (QVariantMap::const_iterator iter= m_states[stateIdx]->m_to.constBegin(); - iter!=m_states[stateIdx]->m_to.constEnd(); iter++){ - if (r < (*iter).toReal()){ - bool superBreak = false; - for (int i=0; iname() == iter.key()){ - nextIdx = i; - superBreak = true; - break; - } - } - if (superBreak) - break; - } - r -= (*iter).toReal(); - } - }else{//Random out of shortest paths to goal - nextIdx = goalPath; - } - if (nextIdx == -1)//No to states means stay here - nextIdx = stateIdx; - - m_things[idx] = nextIdx; - m_duration[idx] = m_states[nextIdx]->variedDuration(); - m_startTimes[idx] = time; - if (nextIdx != stateIdx){ - changedIndexes << idx; - emit m_states[nextIdx]->entered(); - } - addToUpdateList((m_duration[idx] * m_states[nextIdx]->frames()) + time, idx); - } - m_stateUpdates.pop_front(); - } - - m_timeOffset = time; - m_advanceTime.start(); - //TODO: emit this when a psuedostate changes too - foreach (int idx, changedIndexes){//Batched so that update list doesn't change midway - emit stateChanged(idx); - } - if (m_stateUpdates.isEmpty()) - return -1; - return m_stateUpdates.first().first; -} - -int QQuickStochasticEngine::goalSeek(int curIdx, int spriteIdx, int dist) -{ - QString goalName; - if (m_goals[spriteIdx] != -1) - goalName = m_states[m_goals[spriteIdx]]->name(); - else - goalName = m_globalGoal; - if (goalName.isEmpty()) - return -1; - //TODO: caching instead of excessively redoing iterative deepening (which was chosen arbitarily anyways) - // Paraphrased - implement in an *efficient* manner - for (int i=0; iname() == goalName) - return curIdx; - if (dist < 0) - dist = m_states.count(); - QQuickStochasticState* curState = m_states[curIdx]; - for (QVariantMap::const_iterator iter = curState->m_to.constBegin(); - iter!=curState->m_to.constEnd(); iter++){ - if (iter.key() == goalName) - for (int i=0; iname() == goalName) - return i; - } - QSet options; - for (int i=1; im_to.constBegin(); - iter!=curState->m_to.constEnd(); iter++){ - int option = -1; - for (int j=0; jname() == iter.key()) - if (goalSeek(j, spriteIdx, i) != -1) - option = j; - if (option != -1) - options << option; - } - if (!options.isEmpty()){ - if (options.count()==1) - return *(options.begin()); - int option = -1; - qreal r =(qreal) qrand() / (qreal) RAND_MAX; - qreal total = 0; - for (QSet::const_iterator iter=options.constBegin(); - iter!=options.constEnd(); iter++) - total += curState->m_to.value(m_states[(*iter)]->name()).toReal(); - r *= total; - for (QVariantMap::const_iterator iter = curState->m_to.constBegin(); - iter!=curState->m_to.constEnd(); iter++){ - bool superContinue = true; - for (int j=0; jname() == iter.key()) - if (options.contains(j)) - superContinue = false; - if (superContinue) - continue; - if (r < (*iter).toReal()){ - bool superBreak = false; - for (int j=0; jname() == iter.key()){ - option = j; - superBreak = true; - break; - } - } - if (superBreak) - break; - } - r-=(*iter).toReal(); - } - return option; - } - } - return -1; -} - -void QQuickStochasticEngine::addToUpdateList(uint t, int idx) -{ - for (int i=0; i t){ - QList tmpList; - tmpList << idx; - m_stateUpdates.insert(i, qMakePair(t, tmpList)); - return; - } - } - QList tmpList; - tmpList << idx; - m_stateUpdates << qMakePair(t, tmpList); -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickspriteengine_p.h b/src/declarative/items/qquickspriteengine_p.h deleted file mode 100644 index 1040140a28..0000000000 --- a/src/declarative/items/qquickspriteengine_p.h +++ /dev/null @@ -1,323 +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$ -** 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 QQUICKSPRITEENGINE_P_H -#define QQUICKSPRITEENGINE_P_H - -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickSprite; -class Q_AUTOTEST_EXPORT QQuickStochasticState : public QObject //For internal use -{ - Q_OBJECT - Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) - Q_PROPERTY(int durationVariation READ durationVariance WRITE setDurationVariance NOTIFY durationVarianceChanged) - Q_PROPERTY(QVariantMap to READ to WRITE setTo NOTIFY toChanged) - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - Q_PROPERTY(qreal speedModifiesDuration READ speedModifer WRITE setSpeedModifier NOTIFY speedModifierChanged) - Q_PROPERTY(int frames READ frames WRITE setFrames NOTIFY framesChanged) - -public: - QQuickStochasticState(QObject* parent = 0) - : QObject(parent) - , m_frames(1) - , m_duration(1000) - { - } - - int duration() const - { - return m_duration; - } - - QString name() const - { - return m_name; - } - - QVariantMap to() const - { - return m_to; - } - - qreal speedModifer() const - { - return m_speedModifier; - } - - int durationVariance() const - { - return m_durationVariance; - } - - - int variedDuration() const - { - return m_duration - + (m_durationVariance * ((qreal)qrand()/RAND_MAX) * 2) - - m_durationVariance; - } - - int frames() const - { - return m_frames; - } - -signals: - void durationChanged(int arg); - - void nameChanged(QString arg); - - void toChanged(QVariantMap arg); - - void speedModifierChanged(qreal arg); - - void durationVarianceChanged(int arg); - - void entered();//### Just playing around - don't expect full state API - void framesChanged(int arg); - -public slots: - void setDuration(int arg) - { - if (m_duration != arg) { - m_duration = arg; - emit durationChanged(arg); - } - } - - void setName(QString arg) - { - if (m_name != arg) { - m_name = arg; - emit nameChanged(arg); - } - } - - void setTo(QVariantMap arg) - { - if (m_to != arg) { - m_to = arg; - emit toChanged(arg); - } - } - - void setSpeedModifier(qreal arg) - { - if (m_speedModifier != arg) { - m_speedModifier = arg; - emit speedModifierChanged(arg); - } - } - - void setDurationVariance(int arg) - { - if (m_durationVariance != arg) { - m_durationVariance = arg; - emit durationVarianceChanged(arg); - } - } - - void setFrames(int arg) - { - if (m_frames != arg) { - m_frames = arg; - emit framesChanged(arg); - } - } - -private: - QString m_name; - int m_frames; - QVariantMap m_to; - int m_duration; - qreal m_speedModifier; - int m_durationVariance; - - friend class QQuickStochasticEngine; -}; - -class Q_AUTOTEST_EXPORT QQuickStochasticEngine : public QObject -{ - Q_OBJECT - //TODO: Optimize single state case? - Q_PROPERTY(QString globalGoal READ globalGoal WRITE setGlobalGoal NOTIFY globalGoalChanged) - Q_PROPERTY(QDeclarativeListProperty states READ states) -public: - explicit QQuickStochasticEngine(QObject *parent = 0); - QQuickStochasticEngine(QList states, QObject *parent=0); - ~QQuickStochasticEngine(); - - QDeclarativeListProperty states() - { - return QDeclarativeListProperty(this, m_states); - } - - QString globalGoal() const - { - return m_globalGoal; - } - - int count() const {return m_things.count();} - void setCount(int c); - - void setGoal(int state, int sprite=0, bool jump=false); - void start(int index=0, int state=0); - void stop(int index=0); - int curState(int index=0) {return m_things[index];} - - QQuickStochasticState* state(int idx){return m_states[idx];} - int stateIndex(QQuickStochasticState* s){return m_states.indexOf(s);} - int stateIndex(const QString& s) { - for (int i=0; iname() == s) - return i; - return -1; - } - - int stateCount() {return m_states.count();} -private: -signals: - - void globalGoalChanged(QString arg); - void stateChanged(int idx); - -public slots: - void setGlobalGoal(QString arg) - { - if (m_globalGoal != arg) { - m_globalGoal = arg; - emit globalGoalChanged(arg); - } - } - - uint updateSprites(uint time); - -protected: - friend class QQuickParticleSystem; - void restart(int index); - void addToUpdateList(uint t, int idx); - int goalSeek(int curState, int idx, int dist=-1); - QList m_states; - //### Consider struct or class for the four data variables? - QVector m_things;//int is the index in m_states of the current state - QVector m_goals; - QVector m_duration; - QVector m_startTimes; - QList > > m_stateUpdates;//### This could be done faster - priority queue? - - QTime m_advanceTime; - uint m_timeOffset; - QString m_globalGoal; - int m_maxFrames; - int m_imageStateCount; -}; - -class QQuickSpriteEngine : public QQuickStochasticEngine -{ - Q_OBJECT - Q_PROPERTY(QDeclarativeListProperty sprites READ sprites) -public: - explicit QQuickSpriteEngine(QObject *parent = 0); - QQuickSpriteEngine(QList sprites, QObject *parent=0); - ~QQuickSpriteEngine(); - QDeclarativeListProperty sprites() - { - return QDeclarativeListProperty(this, m_sprites); - } - - - int spriteState(int sprite=0); - int spriteStart(int sprite=0); - int spriteFrames(int sprite=0); - int spriteDuration(int sprite=0); - int spriteX(int /* sprite */ = 0) { return 0; }//Currently all rows are 0 aligned, if we get more space efficient we might change this - int spriteY(int sprite=0); - int spriteWidth(int sprite=0); - int spriteHeight(int sprite=0); - int spriteCount();//Like state count, but for the image states - int maxFrames(); - QImage assembledImage(); -private: - QList m_sprites; -}; - -//Common use is to have your own list property which is transparently an engine -inline void spriteAppend(QDeclarativeListProperty *p, QQuickSprite* s) -{ - reinterpret_cast *>(p->data)->append(s); - p->object->metaObject()->invokeMethod(p->object, "createEngine"); -} - -inline QQuickSprite* spriteAt(QDeclarativeListProperty *p, int idx) -{ - return reinterpret_cast *>(p->data)->at(idx); -} - -inline void spriteClear(QDeclarativeListProperty *p) -{ - reinterpret_cast *>(p->data)->clear(); - p->object->metaObject()->invokeMethod(p->object, "createEngine"); -} - -inline int spriteCount(QDeclarativeListProperty *p) -{ - return reinterpret_cast *>(p->data)->count(); -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QQUICKSPRITEENGINE_P_H diff --git a/src/declarative/items/qquickspriteimage.cpp b/src/declarative/items/qquickspriteimage.cpp deleted file mode 100644 index a18d0f95c7..0000000000 --- a/src/declarative/items/qquickspriteimage.cpp +++ /dev/null @@ -1,455 +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$ -** 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 "qquickspriteimage_p.h" -#include "qquicksprite_p.h" -#include "qquickspriteengine_p.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const char vertexShaderCode[] = - "attribute highp vec2 vTex;\n" - "uniform highp vec4 animData;// interpolate(bool), duration, frameCount (this anim), timestamp (this anim)\n" - "uniform highp vec4 animPos;//sheet x,y, width/height of this anim\n" - "uniform highp vec4 animSheetSize; //width/height of whole sheet, width/height of element\n" - "\n" - "uniform highp mat4 qt_Matrix;\n" - "uniform highp float timestamp;\n" - "\n" - "varying highp vec4 fTexS;\n" - "varying lowp float progress;\n" - "\n" - "\n" - "void main() {\n" - " //Calculate frame location in texture\n" - " highp float frameIndex = mod((((timestamp - animData.w)*1000.)/animData.y),animData.z);\n" - " progress = mod((timestamp - animData.w)*1000., animData.y) / animData.y;\n" - "\n" - " frameIndex = floor(frameIndex);\n" - " fTexS.xy = vec2(((frameIndex + vTex.x) * animPos.z / animSheetSize.x), ((animPos.y + vTex.y * animPos.w) / animSheetSize.y));\n" - "\n" - " //Next frame is also passed, for interpolation\n" - " //### Should the next anim be precalculated to allow for interpolation there?\n" - " if (animData.x == 1.0 && frameIndex != animData.z - 1.)//Can't do it for the last frame though, this anim may not loop\n" - " frameIndex = mod(frameIndex+1., animData.z);\n" - " fTexS.zw = vec2(((frameIndex + vTex.x) * animPos.z / animSheetSize.x), ((animPos.y + vTex.y * animPos.w) / animSheetSize.y));\n" - "\n" - " gl_Position = qt_Matrix * vec4(animSheetSize.z * vTex.x, animSheetSize.w * vTex.y, 0, 1);\n" - "}\n"; - -static const char fragmentShaderCode[] = - "uniform sampler2D texture;\n" - "uniform lowp float qt_Opacity;\n" - "\n" - "varying highp vec4 fTexS;\n" - "varying lowp float progress;\n" - "\n" - "void main() {\n" - " gl_FragColor = mix(texture2D(texture, fTexS.xy), texture2D(texture, fTexS.zw), progress) * qt_Opacity;\n" - "}\n"; - -class QQuickSpriteMaterial : public QSGMaterial -{ -public: - QQuickSpriteMaterial(); - virtual ~QQuickSpriteMaterial(); - virtual QSGMaterialType *type() const { static QSGMaterialType type; return &type; } - virtual QSGMaterialShader *createShader() const; - virtual int compare(const QSGMaterial *other) const - { - return this - static_cast(other); - } - - QSGTexture *texture; - - qreal timestamp; - float interpolate; - float frameDuration; - float frameCount; - float animT; - float animX; - float animY; - float animWidth; - float animHeight; - float sheetWidth; - float sheetHeight; - float elementWidth; - float elementHeight; -}; - -QQuickSpriteMaterial::QQuickSpriteMaterial() - : timestamp(0) - , interpolate(1.0f) - , frameDuration(1.0f) - , frameCount(1.0f) - , animT(0.0f) - , animX(0.0f) - , animY(0.0f) - , animWidth(1.0f) - , animHeight(1.0f) - , sheetWidth(1.0f) - , sheetHeight(1.0f) - , elementWidth(1.0f) - , elementHeight(1.0f) -{ - setFlag(Blending, true); -} - -QQuickSpriteMaterial::~QQuickSpriteMaterial() -{ - delete texture; -} - -class SpriteMaterialData : public QSGMaterialShader -{ -public: - SpriteMaterialData(const char * /* vertexFile */ = 0, const char * /* fragmentFile */ = 0) - { - } - - 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 *) - { - QQuickSpriteMaterial *m = static_cast(newEffect); - m->texture->bind(); - - program()->setUniformValue(m_opacity_id, state.opacity()); - program()->setUniformValue(m_timestamp_id, (float) m->timestamp); - program()->setUniformValue(m_animData_id, m->interpolate, m->frameDuration, m->frameCount, m->animT); - program()->setUniformValue(m_animPos_id, m->animX, m->animY, m->animWidth, m->animHeight); - program()->setUniformValue(m_animSheetSize_id, m->sheetWidth, m->sheetHeight, m->elementWidth, m->elementHeight); - - if (state.isMatrixDirty()) - program()->setUniformValue(m_matrix_id, state.combinedMatrix()); - } - - virtual void initialize() { - m_matrix_id = program()->uniformLocation("qt_Matrix"); - m_opacity_id = program()->uniformLocation("qt_Opacity"); - m_timestamp_id = program()->uniformLocation("timestamp"); - m_animData_id = program()->uniformLocation("animData"); - m_animPos_id = program()->uniformLocation("animPos"); - m_animSheetSize_id = program()->uniformLocation("animSheetSize"); - } - - virtual const char *vertexShader() const { return vertexShaderCode; } - virtual const char *fragmentShader() const { return fragmentShaderCode; } - - virtual char const *const *attributeNames() const { - static const char *attr[] = { - "vTex", - 0 - }; - return attr; - } - - int m_matrix_id; - int m_opacity_id; - int m_timestamp_id; - int m_animData_id; - int m_animPos_id; - int m_animSheetSize_id; - - static float chunkOfBytes[1024]; -}; - -float SpriteMaterialData::chunkOfBytes[1024]; - -QSGMaterialShader *QQuickSpriteMaterial::createShader() const -{ - return new SpriteMaterialData; -} - -struct SpriteVertex { - float tx; - float ty; -}; - -struct SpriteVertices { - SpriteVertex v1; - SpriteVertex v2; - SpriteVertex v3; - SpriteVertex v4; -}; - -/*! - \qmlclass SpriteImage QQuickSpriteImage - \inqmlmodule QtQuick 2 - \inherits Item - \brief The SpriteImage element draws a sprite animation - -*/ -/*! - \qmlproperty bool QtQuick2::SpriteImage::running - - Whether the sprite is animating or not. - - Default is true -*/ -/*! - \qmlproperty bool QtQuick2::SpriteImage::interpolate - - If true, interpolation will occur between sprite frames to make the - animation appear smoother. - - Default is true. -*/ -/*! - \qmlproperty string QtQuick2::SpriteImage::goalState - - The name of the Sprite which the animation should move to. - - Sprite states have defined durations and transitions between them, setting goalState - will cause it to disregard any path weightings (including 0) and head down the path - which will reach the goalState quickest (fewest animations). It will pass through - intermediate states on that path, and animate them for their duration. - - If it is possible to return to the goalState from the starting point of the goalState - it will continue to do so until goalState is set to "" or an unreachable state. -*/ -/*! \qmlmethod void QtQuick2::SpriteImage::jumpTo(string sprite) - - This function causes the sprite to jump to the specified state immediately, intermediate - states are not played. -*/ -/*! - \qmlproperty list QtQuick2::SpriteImage::sprites - - The sprite or sprites to draw. Sprites will be scaled to the size of this element. -*/ - -//TODO: Implicitly size element to size of first sprite? -QQuickSpriteImage::QQuickSpriteImage(QQuickItem *parent) : - QQuickItem(parent) - , m_node(0) - , m_material(0) - , m_spriteEngine(0) - , m_pleaseReset(false) - , m_running(true) - , m_interpolate(true) -{ - setFlag(ItemHasContents); - connect(this, SIGNAL(runningChanged(bool)), - this, SLOT(update())); -} - -void QQuickSpriteImage::jumpTo(const QString &sprite) -{ - if (!m_spriteEngine) - return; - m_spriteEngine->setGoal(m_spriteEngine->stateIndex(sprite), 0, true); -} - -void QQuickSpriteImage::setGoalState(const QString &sprite) -{ - if (m_goalState != sprite){ - m_goalState = sprite; - emit goalStateChanged(sprite); - m_spriteEngine->setGoal(m_spriteEngine->stateIndex(sprite)); - } -} - -QDeclarativeListProperty QQuickSpriteImage::sprites() -{ - return QDeclarativeListProperty(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear); -} - -void QQuickSpriteImage::createEngine() -{ - //TODO: delay until component complete - if (m_spriteEngine) - delete m_spriteEngine; - if (m_sprites.count()) - m_spriteEngine = new QQuickSpriteEngine(m_sprites, this); - else - m_spriteEngine = 0; - reset(); -} - -static QSGGeometry::Attribute SpriteImage_Attributes[] = { - QSGGeometry::Attribute::create(0, 2, GL_FLOAT), // tex -}; - -static QSGGeometry::AttributeSet SpriteImage_AttributeSet = -{ - 1, // Attribute Count - 2 * sizeof(float), - SpriteImage_Attributes -}; - -QSGGeometryNode* QQuickSpriteImage::buildNode() -{ - if (!m_spriteEngine) { - qWarning() << "SpriteImage: No sprite engine..."; - return 0; - } - - m_material = new QQuickSpriteMaterial(); - - QImage image = m_spriteEngine->assembledImage(); - if (image.isNull()) - return 0; - m_material->texture = canvas()->createTextureFromImage(image); - m_material->texture->setFiltering(QSGTexture::Linear); - m_spriteEngine->start(0); - m_material->interpolate = m_interpolate ? 1.0 : 0.0; - m_material->frameCount = m_spriteEngine->spriteFrames(); - m_material->frameDuration = m_spriteEngine->spriteDuration(); - m_material->animT = 0; - m_material->animX = m_spriteEngine->spriteX(); - m_material->animY = m_spriteEngine->spriteY(); - m_material->animWidth = m_spriteEngine->spriteWidth(); - m_material->animHeight = m_spriteEngine->spriteHeight(); - m_material->sheetWidth = image.width(); - m_material->sheetHeight = image.height(); - m_material->elementWidth = width(); - m_material->elementHeight = height(); - - int vCount = 4; - int iCount = 6; - QSGGeometry *g = new QSGGeometry(SpriteImage_AttributeSet, vCount, iCount); - g->setDrawingMode(GL_TRIANGLES); - - SpriteVertices *p = (SpriteVertices *) g->vertexData(); - - p->v1.tx = 0; - p->v1.ty = 0; - - p->v2.tx = 1.0; - p->v2.ty = 0; - - p->v3.tx = 0; - p->v3.ty = 1.0; - - p->v4.tx = 1.0; - p->v4.ty = 1.0; - - quint16 *indices = g->indexDataAsUShort(); - indices[0] = 0; - indices[1] = 1; - indices[2] = 2; - indices[3] = 1; - indices[4] = 3; - indices[5] = 2; - - - m_timestamp.start(); - m_node = new QSGGeometryNode(); - m_node->setGeometry(g); - m_node->setMaterial(m_material); - m_node->setFlag(QSGGeometryNode::OwnsMaterial); - return m_node; -} - -void QQuickSpriteImage::reset() -{ - m_pleaseReset = true; -} - -QSGNode *QQuickSpriteImage::updatePaintNode(QSGNode *, UpdatePaintNodeData *) -{ - if (m_pleaseReset) { - delete m_node; - delete m_material; - - m_node = 0; - m_material = 0; - m_pleaseReset = false; - } - - prepareNextFrame(); - - if (m_running) { - update(); - if (m_node) - m_node->markDirty(QSGNode::DirtyMaterial); - } - - return m_node; -} - -void QQuickSpriteImage::prepareNextFrame() -{ - if (m_node == 0) - m_node = buildNode(); - if (m_node == 0) //error creating node - return; - - uint timeInt = m_timestamp.elapsed(); - qreal time = timeInt / 1000.; - m_material->timestamp = time; - m_material->elementHeight = height(); - m_material->elementWidth = width(); - m_material->interpolate = m_interpolate; - - //Advance State - m_spriteEngine->updateSprites(timeInt); - int curY = m_spriteEngine->spriteY(); - if (curY != m_material->animY){ - m_material->animT = m_spriteEngine->spriteStart()/1000.0; - m_material->frameCount = m_spriteEngine->spriteFrames(); - m_material->frameDuration = m_spriteEngine->spriteDuration(); - m_material->animX = m_spriteEngine->spriteX(); - m_material->animY = m_spriteEngine->spriteY(); - m_material->animWidth = m_spriteEngine->spriteWidth(); - m_material->animHeight = m_spriteEngine->spriteHeight(); - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/items/qquickspriteimage_p.h b/src/declarative/items/qquickspriteimage_p.h deleted file mode 100644 index 39384cedca..0000000000 --- a/src/declarative/items/qquickspriteimage_p.h +++ /dev/null @@ -1,140 +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$ -** 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 QQUICKSPRITEIMAGE_P_H -#define QQUICKSPRITEIMAGE_P_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGContext; -class QQuickSprite; -class QQuickSpriteEngine; -class QSGGeometryNode; -class QQuickSpriteMaterial; -class Q_AUTOTEST_EXPORT QQuickSpriteImage : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged) - Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate NOTIFY interpolateChanged) - Q_PROPERTY(QString goalState READ goalState WRITE setGoalState NOTIFY goalStateChanged) - //###try to share similar spriteEngines for less overhead? - Q_PROPERTY(QDeclarativeListProperty sprites READ sprites) - Q_CLASSINFO("DefaultProperty", "sprites") - -public: - explicit QQuickSpriteImage(QQuickItem *parent = 0); - - QDeclarativeListProperty sprites(); - - bool running() const - { - return m_running; - } - - bool interpolate() const - { - return m_interpolate; - } - - QString goalState() const - { - return m_goalState; - } - -signals: - - void runningChanged(bool arg); - void interpolateChanged(bool arg); - void goalStateChanged(QString arg); - -public slots: - - void jumpTo(const QString &sprite); - void setGoalState(const QString &sprite); - - void setRunning(bool arg) - { - if (m_running != arg) { - m_running = arg; - emit runningChanged(arg); - } - } - - void setInterpolate(bool arg) - { - if (m_interpolate != arg) { - m_interpolate = arg; - emit interpolateChanged(arg); - } - } - -private slots: - void createEngine(); -protected: - void reset(); - QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); -private: - void prepareNextFrame(); - QSGGeometryNode* buildNode(); - QSGGeometryNode *m_node; - QQuickSpriteMaterial *m_material; - QList m_sprites; - QQuickSpriteEngine* m_spriteEngine; - QTime m_timestamp; - int m_maxFrames; - bool m_pleaseReset; - bool m_running; - bool m_interpolate; - QString m_goalState; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QQUICKSPRITEIMAGE_P_H diff --git a/src/declarative/items/qquickstateoperations.cpp b/src/declarative/items/qquickstateoperations.cpp deleted file mode 100644 index 8c53e0a63f..0000000000 --- a/src/declarative/items/qquickstateoperations.cpp +++ /dev/null @@ -1,1346 +0,0 @@ -/**************************************************************************** -** -** 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$ -** 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 "qquickstateoperations_p.h" -#include "qquickitem_p.h" - -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickParentChangePrivate : public QDeclarativeStateOperationPrivate -{ - Q_DECLARE_PUBLIC(QQuickParentChange) -public: - QQuickParentChangePrivate() : target(0), parent(0), origParent(0), origStackBefore(0), - rewindParent(0), rewindStackBefore(0) {} - - QQuickItem *target; - QDeclarativeGuard parent; - QDeclarativeGuard origParent; - QDeclarativeGuard origStackBefore; - QQuickItem *rewindParent; - QQuickItem *rewindStackBefore; - - QDeclarativeNullableValue xString; - QDeclarativeNullableValue yString; - QDeclarativeNullableValue widthString; - QDeclarativeNullableValue heightString; - QDeclarativeNullableValue scaleString; - QDeclarativeNullableValue rotationString; - - void doChange(QQuickItem *targetParent, QQuickItem *stackBefore = 0); -}; - -void QQuickParentChangePrivate::doChange(QQuickItem *targetParent, QQuickItem *stackBefore) -{ - if (targetParent && target && target->parentItem()) { - Q_Q(QQuickParentChange); - bool ok; - const QTransform &transform = target->parentItem()->itemTransform(targetParent, &ok); - if (transform.type() >= QTransform::TxShear || !ok) { - qmlInfo(q) << QQuickParentChange::tr("Unable to preserve appearance under complex transform"); - ok = false; - } - - qreal scale = 1; - qreal rotation = 0; - bool isRotate = (transform.type() == QTransform::TxRotate) || (transform.m11() < 0); - if (ok && !isRotate) { - if (transform.m11() == transform.m22()) - scale = transform.m11(); - else { - qmlInfo(q) << QQuickParentChange::tr("Unable to preserve appearance under non-uniform scale"); - ok = false; - } - } else if (ok && isRotate) { - if (transform.m11() == transform.m22()) - scale = qSqrt(transform.m11()*transform.m11() + transform.m12()*transform.m12()); - else { - qmlInfo(q) << QQuickParentChange::tr("Unable to preserve appearance under non-uniform scale"); - ok = false; - } - - if (scale != 0) - rotation = atan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI; - else { - qmlInfo(q) << QQuickParentChange::tr("Unable to preserve appearance under scale of 0"); - ok = false; - } - } - - const QPointF &point = transform.map(QPointF(target->x(),target->y())); - qreal x = point.x(); - qreal y = point.y(); - - // setParentItem will update the transformOriginPoint if needed - target->setParentItem(targetParent); - - if (ok && target->transformOrigin() != QQuickItem::TopLeft) { - qreal tempxt = target->transformOriginPoint().x(); - qreal tempyt = target->transformOriginPoint().y(); - QTransform t; - t.translate(-tempxt, -tempyt); - t.rotate(rotation); - t.scale(scale, scale); - t.translate(tempxt, tempyt); - const QPointF &offset = t.map(QPointF(0,0)); - x += offset.x(); - y += offset.y(); - } - - if (ok) { - //qDebug() << x << y << rotation << scale; - target->setX(x); - target->setY(y); - target->setRotation(target->rotation() + rotation); - target->setScale(target->scale() * scale); - } - } else if (target) { - target->setParentItem(targetParent); - } - - //restore the original stack position. - //### if stackBefore has also been reparented this won't work - if (stackBefore) - target->stackBefore(stackBefore); -} - -QQuickParentChange::QQuickParentChange(QObject *parent) - : QDeclarativeStateOperation(*(new QQuickParentChangePrivate), parent) -{ -} - -QQuickParentChange::~QQuickParentChange() -{ -} - -QDeclarativeScriptString QQuickParentChange::x() const -{ - Q_D(const QQuickParentChange); - return d->xString.value; -} - -void QQuickParentChange::setX(QDeclarativeScriptString x) -{ - Q_D(QQuickParentChange); - d->xString = x; -} - -bool QQuickParentChange::xIsSet() const -{ - Q_D(const QQuickParentChange); - return d->xString.isValid(); -} - -QDeclarativeScriptString QQuickParentChange::y() const -{ - Q_D(const QQuickParentChange); - return d->yString.value; -} - -void QQuickParentChange::setY(QDeclarativeScriptString y) -{ - Q_D(QQuickParentChange); - d->yString = y; -} - -bool QQuickParentChange::yIsSet() const -{ - Q_D(const QQuickParentChange); - return d->yString.isValid(); -} - -QDeclarativeScriptString QQuickParentChange::width() const -{ - Q_D(const QQuickParentChange); - return d->widthString.value; -} - -void QQuickParentChange::setWidth(QDeclarativeScriptString width) -{ - Q_D(QQuickParentChange); - d->widthString = width; -} - -bool QQuickParentChange::widthIsSet() const -{ - Q_D(const QQuickParentChange); - return d->widthString.isValid(); -} - -QDeclarativeScriptString QQuickParentChange::height() const -{ - Q_D(const QQuickParentChange); - return d->heightString.value; -} - -void QQuickParentChange::setHeight(QDeclarativeScriptString height) -{ - Q_D(QQuickParentChange); - d->heightString = height; -} - -bool QQuickParentChange::heightIsSet() const -{ - Q_D(const QQuickParentChange); - return d->heightString.isValid(); -} - -QDeclarativeScriptString QQuickParentChange::scale() const -{ - Q_D(const QQuickParentChange); - return d->scaleString.value; -} - -void QQuickParentChange::setScale(QDeclarativeScriptString scale) -{ - Q_D(QQuickParentChange); - d->scaleString = scale; -} - -bool QQuickParentChange::scaleIsSet() const -{ - Q_D(const QQuickParentChange); - return d->scaleString.isValid(); -} - -QDeclarativeScriptString QQuickParentChange::rotation() const -{ - Q_D(const QQuickParentChange); - return d->rotationString.value; -} - -void QQuickParentChange::setRotation(QDeclarativeScriptString rotation) -{ - Q_D(QQuickParentChange); - d->rotationString = rotation; -} - -bool QQuickParentChange::rotationIsSet() const -{ - Q_D(const QQuickParentChange); - return d->rotationString.isValid(); -} - -QQuickItem *QQuickParentChange::originalParent() const -{ - Q_D(const QQuickParentChange); - return d->origParent; -} - -QQuickItem *QQuickParentChange::object() const -{ - Q_D(const QQuickParentChange); - return d->target; -} - -void QQuickParentChange::setObject(QQuickItem *target) -{ - Q_D(QQuickParentChange); - d->target = target; -} - -QQuickItem *QQuickParentChange::parent() const -{ - Q_D(const QQuickParentChange); - return d->parent; -} - -void QQuickParentChange::setParent(QQuickItem *parent) -{ - Q_D(QQuickParentChange); - d->parent = parent; -} - -QDeclarativeStateOperation::ActionList QQuickParentChange::actions() -{ - Q_D(QQuickParentChange); - if (!d->target || !d->parent) - return ActionList(); - - ActionList actions; - - QDeclarativeAction a; - a.event = this; - actions << a; - - if (d->xString.isValid()) { - bool ok = false; - QString script = d->xString.value.script(); - qreal x = script.toFloat(&ok); - if (ok) { - QDeclarativeAction xa(d->target, QLatin1String("x"), x); - actions << xa; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("x"))); - QDeclarativeAction xa; - xa.property = newBinding->property(); - xa.toBinding = newBinding; - xa.fromValue = xa.property.read(); - xa.deletableToBinding = true; - actions << xa; - } - } - - if (d->yString.isValid()) { - bool ok = false; - QString script = d->yString.value.script(); - qreal y = script.toFloat(&ok); - if (ok) { - QDeclarativeAction ya(d->target, QLatin1String("y"), y); - actions << ya; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("y"))); - QDeclarativeAction ya; - ya.property = newBinding->property(); - ya.toBinding = newBinding; - ya.fromValue = ya.property.read(); - ya.deletableToBinding = true; - actions << ya; - } - } - - if (d->scaleString.isValid()) { - bool ok = false; - QString script = d->scaleString.value.script(); - qreal scale = script.toFloat(&ok); - if (ok) { - QDeclarativeAction sa(d->target, QLatin1String("scale"), scale); - actions << sa; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("scale"))); - QDeclarativeAction sa; - sa.property = newBinding->property(); - sa.toBinding = newBinding; - sa.fromValue = sa.property.read(); - sa.deletableToBinding = true; - actions << sa; - } - } - - if (d->rotationString.isValid()) { - bool ok = false; - QString script = d->rotationString.value.script(); - qreal rotation = script.toFloat(&ok); - if (ok) { - QDeclarativeAction ra(d->target, QLatin1String("rotation"), rotation); - actions << ra; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("rotation"))); - QDeclarativeAction ra; - ra.property = newBinding->property(); - ra.toBinding = newBinding; - ra.fromValue = ra.property.read(); - ra.deletableToBinding = true; - actions << ra; - } - } - - if (d->widthString.isValid()) { - bool ok = false; - QString script = d->widthString.value.script(); - qreal width = script.toFloat(&ok); - if (ok) { - QDeclarativeAction wa(d->target, QLatin1String("width"), width); - actions << wa; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("width"))); - QDeclarativeAction wa; - wa.property = newBinding->property(); - wa.toBinding = newBinding; - wa.fromValue = wa.property.read(); - wa.deletableToBinding = true; - actions << wa; - } - } - - if (d->heightString.isValid()) { - bool ok = false; - QString script = d->heightString.value.script(); - qreal height = script.toFloat(&ok); - if (ok) { - QDeclarativeAction ha(d->target, QLatin1String("height"), height); - actions << ha; - } else { - QDeclarativeBinding *newBinding = new QDeclarativeBinding(script, d->target, qmlContext(this)); - newBinding->setTarget(QDeclarativeProperty(d->target, QLatin1String("height"))); - QDeclarativeAction ha; - ha.property = newBinding->property(); - ha.toBinding = newBinding; - ha.fromValue = ha.property.read(); - ha.deletableToBinding = true; - actions << ha; - } - } - - return actions; -} - -void QQuickParentChange::saveOriginals() -{ - Q_D(QQuickParentChange); - saveCurrentValues(); - d->origParent = d->rewindParent; - d->origStackBefore = d->rewindStackBefore; -} - -/*void QQuickParentChange::copyOriginals(QDeclarativeActionEvent *other) -{ - Q_D(QQuickParentChange); - QQuickParentChange *pc = static_cast(other); - - d->origParent = pc->d_func()->rewindParent; - d->origStackBefore = pc->d_func()->rewindStackBefore; - - saveCurrentValues(); -}*/ - -void QQuickParentChange::execute(Reason) -{ - Q_D(QQuickParentChange); - d->doChange(d->parent); -} - -bool QQuickParentChange::isReversable() -{ - return true; -} - -void QQuickParentChange::reverse(Reason) -{ - Q_D(QQuickParentChange); - d->doChange(d->origParent, d->origStackBefore); -} - -QString QQuickParentChange::typeName() const -{ - return QLatin1String("ParentChange"); -} - -bool QQuickParentChange::override(QDeclarativeActionEvent*other) -{ - Q_D(QQuickParentChange); - if (other->typeName() != QLatin1String("ParentChange")) - return false; - if (QQuickParentChange *otherPC = static_cast(other)) - return (d->target == otherPC->object()); - return false; -} - -void QQuickParentChange::saveCurrentValues() -{ - Q_D(QQuickParentChange); - if (!d->target) { - d->rewindParent = 0; - d->rewindStackBefore = 0; - return; - } - - d->rewindParent = d->target->parentItem(); - d->rewindStackBefore = 0; - - if (!d->rewindParent) - return; - - QList children = d->rewindParent->childItems(); - for (int ii = 0; ii < children.count() - 1; ++ii) { - if (children.at(ii) == d->target) { - d->rewindStackBefore = children.at(ii + 1); - break; - } - } -} - -void QQuickParentChange::rewind() -{ - Q_D(QQuickParentChange); - d->doChange(d->rewindParent, d->rewindStackBefore); -} - -class QQuickAnchorSetPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QQuickAnchorSet) -public: - QQuickAnchorSetPrivate() - : usedAnchors(0), resetAnchors(0), fill(0), - centerIn(0)/*, leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0), - margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)*/ - { - } - - QQuickAnchors::Anchors usedAnchors; - QQuickAnchors::Anchors resetAnchors; - - QQuickItem *fill; - QQuickItem *centerIn; - - QDeclarativeScriptString leftScript; - QDeclarativeScriptString rightScript; - QDeclarativeScriptString topScript; - QDeclarativeScriptString bottomScript; - QDeclarativeScriptString hCenterScript; - QDeclarativeScriptString vCenterScript; - QDeclarativeScriptString baselineScript; - - /*qreal leftMargin; - qreal rightMargin; - qreal topMargin; - qreal bottomMargin; - qreal margins; - qreal vCenterOffset; - qreal hCenterOffset; - qreal baselineOffset;*/ -}; - -QQuickAnchorSet::QQuickAnchorSet(QObject *parent) - : QObject(*new QQuickAnchorSetPrivate, parent) -{ -} - -QQuickAnchorSet::~QQuickAnchorSet() -{ -} - -QDeclarativeScriptString QQuickAnchorSet::top() const -{ - Q_D(const QQuickAnchorSet); - return d->topScript; -} - -void QQuickAnchorSet::setTop(const QDeclarativeScriptString &edge) -{ - Q_D(QQuickAnchorSet); - d->usedAnchors |= QQuickAnchors::TopAnchor; - d->topScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetTop(); -} - -void QQuickAnchorSet::resetTop() -{ - Q_D(QQuickAnchorSet); - d->usedAnchors &= ~QQuickAnchors::TopAnchor; - d->topScript = QDeclarativeScriptString(); - d->resetAnchors |= QQuickAnchors::TopAnchor; -} - -QDeclarativeScriptString QQuickAnchorSet::bottom() const -{ - Q_D(const QQuickAnchorSet); - return d->bottomScript; -} - -void QQuickAnchorSet::setBottom(const QDeclarativeScriptString &edge) -{ - Q_D(QQuickAnchorSet); - d->usedAnchors |= QQuickAnchors::BottomAnchor; - d->bottomScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetBottom(); -} - -void QQuickAnchorSet::resetBottom() -{ - Q_D(QQuickAnchorSet); - d->usedAnchors &= ~QQuickAnchors::BottomAnchor; - d->bottomScript = QDeclarativeScriptString(); - d->resetAnchors |= QQuickAnchors::BottomAnchor; -} - -QDeclarativeScriptString QQuickAnchorSet::verticalCenter() const -{ - Q_D(const QQuickAnchorSet); - return d->vCenterScript; -} - -void QQuickAnchorSet::setVerticalCenter(const QDeclarativeScriptString &edge) -{ - Q_D(QQuickAnchorSet); - d->usedAnchors |= QQuickAnchors::VCenterAnchor; - d->vCenterScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetVerticalCenter(); -} - -void QQuickAnchorSet::resetVerticalCenter() -{ - Q_D(QQuickAnchorSet); - d->usedAnchors &= ~QQuickAnchors::VCenterAnchor; - d->vCenterScript = QDeclarativeScriptString(); - d->resetAnchors |= QQuickAnchors::VCenterAnchor; -} - -QDeclarativeScriptString QQuickAnchorSet::baseline() const -{ - Q_D(const QQuickAnchorSet); - return d->baselineScript; -} - -void QQuickAnchorSet::setBaseline(const QDeclarativeScriptString &edge) -{ - Q_D(QQuickAnchorSet); - d->usedAnchors |= QQuickAnchors::BaselineAnchor; - d->baselineScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetBaseline(); -} - -void QQuickAnchorSet::resetBaseline() -{ - Q_D(QQuickAnchorSet); - d->usedAnchors &= ~QQuickAnchors::BaselineAnchor; - d->baselineScript = QDeclarativeScriptString(); - d->resetAnchors |= QQuickAnchors::BaselineAnchor; -} - -QDeclarativeScriptString QQuickAnchorSet::left() const -{ - Q_D(const QQuickAnchorSet); - return d->leftScript; -} - -void QQuickAnchorSet::setLeft(const QDeclarativeScriptString &edge) -{ - Q_D(QQuickAnchorSet); - d->usedAnchors |= QQuickAnchors::LeftAnchor; - d->leftScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetLeft(); -} - -void QQuickAnchorSet::resetLeft() -{ - Q_D(QQuickAnchorSet); - d->usedAnchors &= ~QQuickAnchors::LeftAnchor; - d->leftScript = QDeclarativeScriptString(); - d->resetAnchors |= QQuickAnchors::LeftAnchor; -} - -QDeclarativeScriptString QQuickAnchorSet::right() const -{ - Q_D(const QQuickAnchorSet); - return d->rightScript; -} - -void QQuickAnchorSet::setRight(const QDeclarativeScriptString &edge) -{ - Q_D(QQuickAnchorSet); - d->usedAnchors |= QQuickAnchors::RightAnchor; - d->rightScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetRight(); -} - -void QQuickAnchorSet::resetRight() -{ - Q_D(QQuickAnchorSet); - d->usedAnchors &= ~QQuickAnchors::RightAnchor; - d->rightScript = QDeclarativeScriptString(); - d->resetAnchors |= QQuickAnchors::RightAnchor; -} - -QDeclarativeScriptString QQuickAnchorSet::horizontalCenter() const -{ - Q_D(const QQuickAnchorSet); - return d->hCenterScript; -} - -void QQuickAnchorSet::setHorizontalCenter(const QDeclarativeScriptString &edge) -{ - Q_D(QQuickAnchorSet); - d->usedAnchors |= QQuickAnchors::HCenterAnchor; - d->hCenterScript = edge; - if (edge.script() == QLatin1String("undefined")) - resetHorizontalCenter(); -} - -void QQuickAnchorSet::resetHorizontalCenter() -{ - Q_D(QQuickAnchorSet); - d->usedAnchors &= ~QQuickAnchors::HCenterAnchor; - d->hCenterScript = QDeclarativeScriptString(); - d->resetAnchors |= QQuickAnchors::HCenterAnchor; -} - -QQuickItem *QQuickAnchorSet::fill() const -{ - Q_D(const QQuickAnchorSet); - return d->fill; -} - -void QQuickAnchorSet::setFill(QQuickItem *f) -{ - Q_D(QQuickAnchorSet); - d->fill = f; -} - -void QQuickAnchorSet::resetFill() -{ - setFill(0); -} - -QQuickItem *QQuickAnchorSet::centerIn() const -{ - Q_D(const QQuickAnchorSet); - return d->centerIn; -} - -void QQuickAnchorSet::setCenterIn(QQuickItem* c) -{ - Q_D(QQuickAnchorSet); - d->centerIn = c; -} - -void QQuickAnchorSet::resetCenterIn() -{ - setCenterIn(0); -} - - -class QQuickAnchorChangesPrivate : public QDeclarativeStateOperationPrivate -{ -public: - QQuickAnchorChangesPrivate() - : target(0), anchorSet(new QQuickAnchorSet), - leftBinding(0), rightBinding(0), hCenterBinding(0), - topBinding(0), bottomBinding(0), vCenterBinding(0), baselineBinding(0), - origLeftBinding(0), origRightBinding(0), origHCenterBinding(0), - origTopBinding(0), origBottomBinding(0), origVCenterBinding(0), - origBaselineBinding(0) - { - - } - ~QQuickAnchorChangesPrivate() { delete anchorSet; } - - QQuickItem *target; - QQuickAnchorSet *anchorSet; - - QDeclarativeBinding *leftBinding; - QDeclarativeBinding *rightBinding; - QDeclarativeBinding *hCenterBinding; - QDeclarativeBinding *topBinding; - QDeclarativeBinding *bottomBinding; - QDeclarativeBinding *vCenterBinding; - QDeclarativeBinding *baselineBinding; - - QDeclarativeAbstractBinding *origLeftBinding; - QDeclarativeAbstractBinding *origRightBinding; - QDeclarativeAbstractBinding *origHCenterBinding; - QDeclarativeAbstractBinding *origTopBinding; - QDeclarativeAbstractBinding *origBottomBinding; - QDeclarativeAbstractBinding *origVCenterBinding; - QDeclarativeAbstractBinding *origBaselineBinding; - - QQuickAnchorLine rewindLeft; - QQuickAnchorLine rewindRight; - QQuickAnchorLine rewindHCenter; - QQuickAnchorLine rewindTop; - QQuickAnchorLine rewindBottom; - QQuickAnchorLine rewindVCenter; - QQuickAnchorLine rewindBaseline; - - qreal fromX; - qreal fromY; - qreal fromWidth; - qreal fromHeight; - - qreal toX; - qreal toY; - qreal toWidth; - qreal toHeight; - - qreal rewindX; - qreal rewindY; - qreal rewindWidth; - qreal rewindHeight; - - bool applyOrigLeft; - bool applyOrigRight; - bool applyOrigHCenter; - bool applyOrigTop; - bool applyOrigBottom; - bool applyOrigVCenter; - bool applyOrigBaseline; - - QDeclarativeNullableValue origWidth; - QDeclarativeNullableValue origHeight; - qreal origX; - qreal origY; - - QList oldBindings; - - QDeclarativeProperty leftProp; - QDeclarativeProperty rightProp; - QDeclarativeProperty hCenterProp; - QDeclarativeProperty topProp; - QDeclarativeProperty bottomProp; - QDeclarativeProperty vCenterProp; - QDeclarativeProperty baselineProp; -}; - -QQuickAnchorChanges::QQuickAnchorChanges(QObject *parent) - : QDeclarativeStateOperation(*(new QQuickAnchorChangesPrivate), parent) -{ -} - -QQuickAnchorChanges::~QQuickAnchorChanges() -{ -} - -QQuickAnchorChanges::ActionList QQuickAnchorChanges::actions() -{ - Q_D(QQuickAnchorChanges); - d->leftBinding = d->rightBinding = d->hCenterBinding = d->topBinding - = d->bottomBinding = d->vCenterBinding = d->baselineBinding = 0; - - d->leftProp = QDeclarativeProperty(d->target, QLatin1String("anchors.left")); - d->rightProp = QDeclarativeProperty(d->target, QLatin1String("anchors.right")); - d->hCenterProp = QDeclarativeProperty(d->target, QLatin1String("anchors.horizontalCenter")); - d->topProp = QDeclarativeProperty(d->target, QLatin1String("anchors.top")); - d->bottomProp = QDeclarativeProperty(d->target, QLatin1String("anchors.bottom")); - d->vCenterProp = QDeclarativeProperty(d->target, QLatin1String("anchors.verticalCenter")); - d->baselineProp = QDeclarativeProperty(d->target, QLatin1String("anchors.baseline")); - - if (d->anchorSet->d_func()->usedAnchors & QQuickAnchors::LeftAnchor) { - d->leftBinding = new QDeclarativeBinding(d->anchorSet->d_func()->leftScript.script(), d->target, qmlContext(this)); - d->leftBinding->setTarget(d->leftProp); - } - if (d->anchorSet->d_func()->usedAnchors & QQuickAnchors::RightAnchor) { - d->rightBinding = new QDeclarativeBinding(d->anchorSet->d_func()->rightScript.script(), d->target, qmlContext(this)); - d->rightBinding->setTarget(d->rightProp); - } - if (d->anchorSet->d_func()->usedAnchors & QQuickAnchors::HCenterAnchor) { - d->hCenterBinding = new QDeclarativeBinding(d->anchorSet->d_func()->hCenterScript.script(), d->target, qmlContext(this)); - d->hCenterBinding->setTarget(d->hCenterProp); - } - if (d->anchorSet->d_func()->usedAnchors & QQuickAnchors::TopAnchor) { - d->topBinding = new QDeclarativeBinding(d->anchorSet->d_func()->topScript.script(), d->target, qmlContext(this)); - d->topBinding->setTarget(d->topProp); - } - if (d->anchorSet->d_func()->usedAnchors & QQuickAnchors::BottomAnchor) { - d->bottomBinding = new QDeclarativeBinding(d->anchorSet->d_func()->bottomScript.script(), d->target, qmlContext(this)); - d->bottomBinding->setTarget(d->bottomProp); - } - if (d->anchorSet->d_func()->usedAnchors & QQuickAnchors::VCenterAnchor) { - d->vCenterBinding = new QDeclarativeBinding(d->anchorSet->d_func()->vCenterScript.script(), d->target, qmlContext(this)); - d->vCenterBinding->setTarget(d->vCenterProp); - } - if (d->anchorSet->d_func()->usedAnchors & QQuickAnchors::BaselineAnchor) { - d->baselineBinding = new QDeclarativeBinding(d->anchorSet->d_func()->baselineScript.script(), d->target, qmlContext(this)); - d->baselineBinding->setTarget(d->baselineProp); - } - - QDeclarativeAction a; - a.event = this; - return ActionList() << a; -} - -QQuickAnchorSet *QQuickAnchorChanges::anchors() -{ - Q_D(QQuickAnchorChanges); - return d->anchorSet; -} - -QQuickItem *QQuickAnchorChanges::object() const -{ - Q_D(const QQuickAnchorChanges); - return d->target; -} - -void QQuickAnchorChanges::setObject(QQuickItem *target) -{ - Q_D(QQuickAnchorChanges); - d->target = target; -} - -void QQuickAnchorChanges::execute(Reason reason) -{ - Q_D(QQuickAnchorChanges); - if (!d->target) - return; - - QQuickItemPrivate *targetPrivate = QQuickItemPrivate::get(d->target); - //incorporate any needed "reverts" - if (d->applyOrigLeft) { - if (!d->origLeftBinding) - targetPrivate->anchors()->resetLeft(); - QDeclarativePropertyPrivate::setBinding(d->leftProp, d->origLeftBinding); - } - if (d->applyOrigRight) { - if (!d->origRightBinding) - targetPrivate->anchors()->resetRight(); - QDeclarativePropertyPrivate::setBinding(d->rightProp, d->origRightBinding); - } - if (d->applyOrigHCenter) { - if (!d->origHCenterBinding) - targetPrivate->anchors()->resetHorizontalCenter(); - QDeclarativePropertyPrivate::setBinding(d->hCenterProp, d->origHCenterBinding); - } - if (d->applyOrigTop) { - if (!d->origTopBinding) - targetPrivate->anchors()->resetTop(); - QDeclarativePropertyPrivate::setBinding(d->topProp, d->origTopBinding); - } - if (d->applyOrigBottom) { - if (!d->origBottomBinding) - targetPrivate->anchors()->resetBottom(); - QDeclarativePropertyPrivate::setBinding(d->bottomProp, d->origBottomBinding); - } - if (d->applyOrigVCenter) { - if (!d->origVCenterBinding) - targetPrivate->anchors()->resetVerticalCenter(); - QDeclarativePropertyPrivate::setBinding(d->vCenterProp, d->origVCenterBinding); - } - if (d->applyOrigBaseline) { - if (!d->origBaselineBinding) - targetPrivate->anchors()->resetBaseline(); - QDeclarativePropertyPrivate::setBinding(d->baselineProp, d->origBaselineBinding); - } - - //destroy old bindings - if (reason == ActualChange) { - for (int i = 0; i < d->oldBindings.size(); ++i) { - QDeclarativeAbstractBinding *binding = d->oldBindings.at(i); - if (binding) - binding->destroy(); - } - d->oldBindings.clear(); - } - - //reset any anchors that have been specified as "undefined" - if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::LeftAnchor) { - targetPrivate->anchors()->resetLeft(); - QDeclarativePropertyPrivate::setBinding(d->leftProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::RightAnchor) { - targetPrivate->anchors()->resetRight(); - QDeclarativePropertyPrivate::setBinding(d->rightProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::HCenterAnchor) { - targetPrivate->anchors()->resetHorizontalCenter(); - QDeclarativePropertyPrivate::setBinding(d->hCenterProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::TopAnchor) { - targetPrivate->anchors()->resetTop(); - QDeclarativePropertyPrivate::setBinding(d->topProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::BottomAnchor) { - targetPrivate->anchors()->resetBottom(); - QDeclarativePropertyPrivate::setBinding(d->bottomProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::VCenterAnchor) { - targetPrivate->anchors()->resetVerticalCenter(); - QDeclarativePropertyPrivate::setBinding(d->vCenterProp, 0); - } - if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::BaselineAnchor) { - targetPrivate->anchors()->resetBaseline(); - QDeclarativePropertyPrivate::setBinding(d->baselineProp, 0); - } - - //set any anchors that have been specified - if (d->leftBinding) - QDeclarativePropertyPrivate::setBinding(d->leftBinding->property(), d->leftBinding); - if (d->rightBinding) - QDeclarativePropertyPrivate::setBinding(d->rightBinding->property(), d->rightBinding); - if (d->hCenterBinding) - QDeclarativePropertyPrivate::setBinding(d->hCenterBinding->property(), d->hCenterBinding); - if (d->topBinding) - QDeclarativePropertyPrivate::setBinding(d->topBinding->property(), d->topBinding); - if (d->bottomBinding) - QDeclarativePropertyPrivate::setBinding(d->bottomBinding->property(), d->bottomBinding); - if (d->vCenterBinding) - QDeclarativePropertyPrivate::setBinding(d->vCenterBinding->property(), d->vCenterBinding); - if (d->baselineBinding) - QDeclarativePropertyPrivate::setBinding(d->baselineBinding->property(), d->baselineBinding); -} - -bool QQuickAnchorChanges::isReversable() -{ - return true; -} - -void QQuickAnchorChanges::reverse(Reason reason) -{ - Q_D(QQuickAnchorChanges); - if (!d->target) - return; - - QQuickItemPrivate *targetPrivate = QQuickItemPrivate::get(d->target); - //reset any anchors set by the state - if (d->leftBinding) { - targetPrivate->anchors()->resetLeft(); - QDeclarativePropertyPrivate::setBinding(d->leftBinding->property(), 0); - if (reason == ActualChange) { - d->leftBinding->destroy(); d->leftBinding = 0; - } - } - if (d->rightBinding) { - targetPrivate->anchors()->resetRight(); - QDeclarativePropertyPrivate::setBinding(d->rightBinding->property(), 0); - if (reason == ActualChange) { - d->rightBinding->destroy(); d->rightBinding = 0; - } - } - if (d->hCenterBinding) { - targetPrivate->anchors()->resetHorizontalCenter(); - QDeclarativePropertyPrivate::setBinding(d->hCenterBinding->property(), 0); - if (reason == ActualChange) { - d->hCenterBinding->destroy(); d->hCenterBinding = 0; - } - } - if (d->topBinding) { - targetPrivate->anchors()->resetTop(); - QDeclarativePropertyPrivate::setBinding(d->topBinding->property(), 0); - if (reason == ActualChange) { - d->topBinding->destroy(); d->topBinding = 0; - } - } - if (d->bottomBinding) { - targetPrivate->anchors()->resetBottom(); - QDeclarativePropertyPrivate::setBinding(d->bottomBinding->property(), 0); - if (reason == ActualChange) { - d->bottomBinding->destroy(); d->bottomBinding = 0; - } - } - if (d->vCenterBinding) { - targetPrivate->anchors()->resetVerticalCenter(); - QDeclarativePropertyPrivate::setBinding(d->vCenterBinding->property(), 0); - if (reason == ActualChange) { - d->vCenterBinding->destroy(); d->vCenterBinding = 0; - } - } - if (d->baselineBinding) { - targetPrivate->anchors()->resetBaseline(); - QDeclarativePropertyPrivate::setBinding(d->baselineBinding->property(), 0); - if (reason == ActualChange) { - d->baselineBinding->destroy(); d->baselineBinding = 0; - } - } - - //restore previous anchors - if (d->origLeftBinding) - QDeclarativePropertyPrivate::setBinding(d->leftProp, d->origLeftBinding); - if (d->origRightBinding) - QDeclarativePropertyPrivate::setBinding(d->rightProp, d->origRightBinding); - if (d->origHCenterBinding) - QDeclarativePropertyPrivate::setBinding(d->hCenterProp, d->origHCenterBinding); - if (d->origTopBinding) - QDeclarativePropertyPrivate::setBinding(d->topProp, d->origTopBinding); - if (d->origBottomBinding) - QDeclarativePropertyPrivate::setBinding(d->bottomProp, d->origBottomBinding); - if (d->origVCenterBinding) - QDeclarativePropertyPrivate::setBinding(d->vCenterProp, d->origVCenterBinding); - if (d->origBaselineBinding) - QDeclarativePropertyPrivate::setBinding(d->baselineProp, d->origBaselineBinding); - - //restore any absolute geometry changed by the state's anchors - QQuickAnchors::Anchors stateVAnchors = d->anchorSet->d_func()->usedAnchors & QQuickAnchors::Vertical_Mask; - QQuickAnchors::Anchors origVAnchors = targetPrivate->anchors()->usedAnchors() & QQuickAnchors::Vertical_Mask; - QQuickAnchors::Anchors stateHAnchors = d->anchorSet->d_func()->usedAnchors & QQuickAnchors::Horizontal_Mask; - QQuickAnchors::Anchors origHAnchors = targetPrivate->anchors()->usedAnchors() & QQuickAnchors::Horizontal_Mask; - - bool stateSetWidth = (stateHAnchors && - stateHAnchors != QQuickAnchors::LeftAnchor && - stateHAnchors != QQuickAnchors::RightAnchor && - stateHAnchors != QQuickAnchors::HCenterAnchor); - bool origSetWidth = (origHAnchors && - origHAnchors != QQuickAnchors::LeftAnchor && - origHAnchors != QQuickAnchors::RightAnchor && - origHAnchors != QQuickAnchors::HCenterAnchor); - if (d->origWidth.isValid() && stateSetWidth && !origSetWidth) - d->target->setWidth(d->origWidth.value); - - bool stateSetHeight = (stateVAnchors && - stateVAnchors != QQuickAnchors::TopAnchor && - stateVAnchors != QQuickAnchors::BottomAnchor && - stateVAnchors != QQuickAnchors::VCenterAnchor && - stateVAnchors != QQuickAnchors::BaselineAnchor); - bool origSetHeight = (origVAnchors && - origVAnchors != QQuickAnchors::TopAnchor && - origVAnchors != QQuickAnchors::BottomAnchor && - origVAnchors != QQuickAnchors::VCenterAnchor && - origVAnchors != QQuickAnchors::BaselineAnchor); - if (d->origHeight.isValid() && stateSetHeight && !origSetHeight) - d->target->setHeight(d->origHeight.value); - - if (stateHAnchors && !origHAnchors) - d->target->setX(d->origX); - - if (stateVAnchors && !origVAnchors) - d->target->setY(d->origY); -} - -QString QQuickAnchorChanges::typeName() const -{ - return QLatin1String("AnchorChanges"); -} - -QList QQuickAnchorChanges::additionalActions() -{ - Q_D(QQuickAnchorChanges); - QList extra; - - QQuickAnchors::Anchors combined = d->anchorSet->d_func()->usedAnchors | d->anchorSet->d_func()->resetAnchors; - bool hChange = combined & QQuickAnchors::Horizontal_Mask; - bool vChange = combined & QQuickAnchors::Vertical_Mask; - - if (d->target) { - QDeclarativeAction a; - if (hChange && d->fromX != d->toX) { - a.property = QDeclarativeProperty(d->target, QLatin1String("x")); - a.toValue = d->toX; - extra << a; - } - if (vChange && d->fromY != d->toY) { - a.property = QDeclarativeProperty(d->target, QLatin1String("y")); - a.toValue = d->toY; - extra << a; - } - if (hChange && d->fromWidth != d->toWidth) { - a.property = QDeclarativeProperty(d->target, QLatin1String("width")); - a.toValue = d->toWidth; - extra << a; - } - if (vChange && d->fromHeight != d->toHeight) { - a.property = QDeclarativeProperty(d->target, QLatin1String("height")); - a.toValue = d->toHeight; - extra << a; - } - } - - return extra; -} - -bool QQuickAnchorChanges::changesBindings() -{ - return true; -} - -void QQuickAnchorChanges::saveOriginals() -{ - Q_D(QQuickAnchorChanges); - if (!d->target) - return; - - d->origLeftBinding = QDeclarativePropertyPrivate::binding(d->leftProp); - d->origRightBinding = QDeclarativePropertyPrivate::binding(d->rightProp); - d->origHCenterBinding = QDeclarativePropertyPrivate::binding(d->hCenterProp); - d->origTopBinding = QDeclarativePropertyPrivate::binding(d->topProp); - d->origBottomBinding = QDeclarativePropertyPrivate::binding(d->bottomProp); - d->origVCenterBinding = QDeclarativePropertyPrivate::binding(d->vCenterProp); - d->origBaselineBinding = QDeclarativePropertyPrivate::binding(d->baselineProp); - - QQuickItemPrivate *targetPrivate = QQuickItemPrivate::get(d->target); - if (targetPrivate->widthValid) - d->origWidth = d->target->width(); - if (targetPrivate->heightValid) - d->origHeight = d->target->height(); - d->origX = d->target->x(); - d->origY = d->target->y(); - - d->applyOrigLeft = d->applyOrigRight = d->applyOrigHCenter = d->applyOrigTop - = d->applyOrigBottom = d->applyOrigVCenter = d->applyOrigBaseline = false; - - saveCurrentValues(); -} - -void QQuickAnchorChanges::copyOriginals(QDeclarativeActionEvent *other) -{ - Q_D(QQuickAnchorChanges); - QQuickAnchorChanges *ac = static_cast(other); - QQuickAnchorChangesPrivate *acp = ac->d_func(); - - QQuickAnchors::Anchors combined = acp->anchorSet->d_func()->usedAnchors | - acp->anchorSet->d_func()->resetAnchors; - - //probably also need to revert some things - d->applyOrigLeft = (combined & QQuickAnchors::LeftAnchor); - d->applyOrigRight = (combined & QQuickAnchors::RightAnchor); - d->applyOrigHCenter = (combined & QQuickAnchors::HCenterAnchor); - d->applyOrigTop = (combined & QQuickAnchors::TopAnchor); - d->applyOrigBottom = (combined & QQuickAnchors::BottomAnchor); - d->applyOrigVCenter = (combined & QQuickAnchors::VCenterAnchor); - d->applyOrigBaseline = (combined & QQuickAnchors::BaselineAnchor); - - d->origLeftBinding = acp->origLeftBinding; - d->origRightBinding = acp->origRightBinding; - d->origHCenterBinding = acp->origHCenterBinding; - d->origTopBinding = acp->origTopBinding; - d->origBottomBinding = acp->origBottomBinding; - d->origVCenterBinding = acp->origVCenterBinding; - d->origBaselineBinding = acp->origBaselineBinding; - - d->origWidth = acp->origWidth; - d->origHeight = acp->origHeight; - d->origX = acp->origX; - d->origY = acp->origY; - - d->oldBindings.clear(); - d->oldBindings << acp->leftBinding << acp->rightBinding << acp->hCenterBinding - << acp->topBinding << acp->bottomBinding << acp->baselineBinding; - - saveCurrentValues(); -} - -void QQuickAnchorChanges::clearBindings() -{ - Q_D(QQuickAnchorChanges); - if (!d->target) - return; - - //### should this (saving "from" values) be moved to saveCurrentValues()? - d->fromX = d->target->x(); - d->fromY = d->target->y(); - d->fromWidth = d->target->width(); - d->fromHeight = d->target->height(); - - QQuickItemPrivate *targetPrivate = QQuickItemPrivate::get(d->target); - //reset any anchors with corresponding reverts - //reset any anchors that have been specified as "undefined" - //reset any anchors that we'll be setting in the state - QQuickAnchors::Anchors combined = d->anchorSet->d_func()->resetAnchors | - d->anchorSet->d_func()->usedAnchors; - if (d->applyOrigLeft || (combined & QQuickAnchors::LeftAnchor)) { - targetPrivate->anchors()->resetLeft(); - QDeclarativePropertyPrivate::setBinding(d->leftProp, 0); - } - if (d->applyOrigRight || (combined & QQuickAnchors::RightAnchor)) { - targetPrivate->anchors()->resetRight(); - QDeclarativePropertyPrivate::setBinding(d->rightProp, 0); - } - if (d->applyOrigHCenter || (combined & QQuickAnchors::HCenterAnchor)) { - targetPrivate->anchors()->resetHorizontalCenter(); - QDeclarativePropertyPrivate::setBinding(d->hCenterProp, 0); - } - if (d->applyOrigTop || (combined & QQuickAnchors::TopAnchor)) { - targetPrivate->anchors()->resetTop(); - QDeclarativePropertyPrivate::setBinding(d->topProp, 0); - } - if (d->applyOrigBottom || (combined & QQuickAnchors::BottomAnchor)) { - targetPrivate->anchors()->resetBottom(); - QDeclarativePropertyPrivate::setBinding(d->bottomProp, 0); - } - if (d->applyOrigVCenter || (combined & QQuickAnchors::VCenterAnchor)) { - targetPrivate->anchors()->resetVerticalCenter(); - QDeclarativePropertyPrivate::setBinding(d->vCenterProp, 0); - } - if (d->applyOrigBaseline || (combined & QQuickAnchors::BaselineAnchor)) { - targetPrivate->anchors()->resetBaseline(); - QDeclarativePropertyPrivate::setBinding(d->baselineProp, 0); - } -} - -bool QQuickAnchorChanges::override(QDeclarativeActionEvent*other) -{ - if (other->typeName() != QLatin1String("AnchorChanges")) - return false; - if (static_cast(this) == other) - return true; - if (static_cast(other)->object() == object()) - return true; - return false; -} - -void QQuickAnchorChanges::rewind() -{ - Q_D(QQuickAnchorChanges); - if (!d->target) - return; - - QQuickItemPrivate *targetPrivate = QQuickItemPrivate::get(d->target); - - //restore previous values (but not previous bindings, i.e. anchors) - d->target->setX(d->rewindX); - d->target->setY(d->rewindY); - if (targetPrivate->widthValid) { - d->target->setWidth(d->rewindWidth); - } - if (targetPrivate->heightValid) { - d->target->setHeight(d->rewindHeight); - } -} - -void QQuickAnchorChanges::saveCurrentValues() -{ - Q_D(QQuickAnchorChanges); - if (!d->target) - return; - - QQuickItemPrivate *targetPrivate = QQuickItemPrivate::get(d->target); - d->rewindLeft = targetPrivate->anchors()->left(); - d->rewindRight = targetPrivate->anchors()->right(); - d->rewindHCenter = targetPrivate->anchors()->horizontalCenter(); - d->rewindTop = targetPrivate->anchors()->top(); - d->rewindBottom = targetPrivate->anchors()->bottom(); - d->rewindVCenter = targetPrivate->anchors()->verticalCenter(); - d->rewindBaseline = targetPrivate->anchors()->baseline(); - - d->rewindX = d->target->x(); - d->rewindY = d->target->y(); - d->rewindWidth = d->target->width(); - d->rewindHeight = d->target->height(); -} - -void QQuickAnchorChanges::saveTargetValues() -{ - Q_D(QQuickAnchorChanges); - if (!d->target) - return; - - d->toX = d->target->x(); - d->toY = d->target->y(); - d->toWidth = d->target->width(); - d->toHeight = d->target->height(); -} - -#include - -QT_END_NAMESPACE - diff --git a/src/declarative/items/qquickstateoperations_p.h b/src/declarative/items/qquickstateoperations_p.h deleted file mode 100644 index 7844c6d7dd..0000000000 --- a/src/declarative/items/qquickstateoperations_p.h +++ /dev/null @@ -1,275 +0,0 @@ -// Commit: 84c47bbb133304d7ef35642fa1fbb17619d4a43d -/**************************************************************************** -** -** 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$ -** 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 QQUICKSTATEOPERATIONS_P_H -#define QQUICKSTATEOPERATIONS_P_H - -#include "qquickitem.h" -#include "qquickanchors_p.h" - -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickParentChangePrivate; -class Q_AUTOTEST_EXPORT QQuickParentChange : public QDeclarativeStateOperation, public QDeclarativeActionEvent -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QQuickParentChange) - - Q_PROPERTY(QQuickItem *target READ object WRITE setObject) - Q_PROPERTY(QQuickItem *parent READ parent WRITE setParent) - Q_PROPERTY(QDeclarativeScriptString x READ x WRITE setX) - Q_PROPERTY(QDeclarativeScriptString y READ y WRITE setY) - Q_PROPERTY(QDeclarativeScriptString width READ width WRITE setWidth) - Q_PROPERTY(QDeclarativeScriptString height READ height WRITE setHeight) - Q_PROPERTY(QDeclarativeScriptString scale READ scale WRITE setScale) - Q_PROPERTY(QDeclarativeScriptString rotation READ rotation WRITE setRotation) -public: - QQuickParentChange(QObject *parent=0); - ~QQuickParentChange(); - - QQuickItem *object() const; - void setObject(QQuickItem *); - - QQuickItem *parent() const; - void setParent(QQuickItem *); - - QQuickItem *originalParent() const; - - QDeclarativeScriptString x() const; - void setX(QDeclarativeScriptString x); - bool xIsSet() const; - - QDeclarativeScriptString y() const; - void setY(QDeclarativeScriptString y); - bool yIsSet() const; - - QDeclarativeScriptString width() const; - void setWidth(QDeclarativeScriptString width); - bool widthIsSet() const; - - QDeclarativeScriptString height() const; - void setHeight(QDeclarativeScriptString height); - bool heightIsSet() const; - - QDeclarativeScriptString scale() const; - void setScale(QDeclarativeScriptString scale); - bool scaleIsSet() const; - - QDeclarativeScriptString rotation() const; - void setRotation(QDeclarativeScriptString rotation); - bool rotationIsSet() const; - - virtual ActionList actions(); - - virtual void saveOriginals(); - //virtual void copyOriginals(QDeclarativeActionEvent*); - virtual void execute(Reason reason = ActualChange); - virtual bool isReversable(); - virtual void reverse(Reason reason = ActualChange); - virtual QString typeName() const; - virtual bool override(QDeclarativeActionEvent*other); - virtual void rewind(); - virtual void saveCurrentValues(); -}; - -class QQuickAnchorChanges; -class QQuickAnchorSetPrivate; -class Q_AUTOTEST_EXPORT QQuickAnchorSet : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QDeclarativeScriptString left READ left WRITE setLeft RESET resetLeft) - Q_PROPERTY(QDeclarativeScriptString right READ right WRITE setRight RESET resetRight) - Q_PROPERTY(QDeclarativeScriptString horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter) - Q_PROPERTY(QDeclarativeScriptString top READ top WRITE setTop RESET resetTop) - Q_PROPERTY(QDeclarativeScriptString bottom READ bottom WRITE setBottom RESET resetBottom) - Q_PROPERTY(QDeclarativeScriptString verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter) - Q_PROPERTY(QDeclarativeScriptString baseline READ baseline WRITE setBaseline RESET resetBaseline) - //Q_PROPERTY(QQuickItem *fill READ fill WRITE setFill RESET resetFill) - //Q_PROPERTY(QQuickItem *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn) - - /*Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged) - Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) - Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) - Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged()) - Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) - Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) - Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged()) - Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged())*/ - -public: - QQuickAnchorSet(QObject *parent=0); - virtual ~QQuickAnchorSet(); - - QDeclarativeScriptString left() const; - void setLeft(const QDeclarativeScriptString &edge); - void resetLeft(); - - QDeclarativeScriptString right() const; - void setRight(const QDeclarativeScriptString &edge); - void resetRight(); - - QDeclarativeScriptString horizontalCenter() const; - void setHorizontalCenter(const QDeclarativeScriptString &edge); - void resetHorizontalCenter(); - - QDeclarativeScriptString top() const; - void setTop(const QDeclarativeScriptString &edge); - void resetTop(); - - QDeclarativeScriptString bottom() const; - void setBottom(const QDeclarativeScriptString &edge); - void resetBottom(); - - QDeclarativeScriptString verticalCenter() const; - void setVerticalCenter(const QDeclarativeScriptString &edge); - void resetVerticalCenter(); - - QDeclarativeScriptString baseline() const; - void setBaseline(const QDeclarativeScriptString &edge); - void resetBaseline(); - - QQuickItem *fill() const; - void setFill(QQuickItem *); - void resetFill(); - - QQuickItem *centerIn() const; - void setCenterIn(QQuickItem *); - void resetCenterIn(); - - /*qreal leftMargin() const; - void setLeftMargin(qreal); - - qreal rightMargin() const; - void setRightMargin(qreal); - - qreal horizontalCenterOffset() const; - void setHorizontalCenterOffset(qreal); - - qreal topMargin() const; - void setTopMargin(qreal); - - qreal bottomMargin() const; - void setBottomMargin(qreal); - - qreal margins() const; - void setMargins(qreal); - - qreal verticalCenterOffset() const; - void setVerticalCenterOffset(qreal); - - qreal baselineOffset() const; - void setBaselineOffset(qreal);*/ - - QQuickAnchors::Anchors usedAnchors() const; - -/*Q_SIGNALS: - void leftMarginChanged(); - void rightMarginChanged(); - void topMarginChanged(); - void bottomMarginChanged(); - void marginsChanged(); - void verticalCenterOffsetChanged(); - void horizontalCenterOffsetChanged(); - void baselineOffsetChanged();*/ - -private: - friend class QQuickAnchorChanges; - Q_DISABLE_COPY(QQuickAnchorSet) - Q_DECLARE_PRIVATE(QQuickAnchorSet) -}; - -class QQuickAnchorChangesPrivate; -class Q_AUTOTEST_EXPORT QQuickAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QQuickAnchorChanges) - - Q_PROPERTY(QQuickItem *target READ object WRITE setObject) - Q_PROPERTY(QQuickAnchorSet *anchors READ anchors CONSTANT) - -public: - QQuickAnchorChanges(QObject *parent=0); - ~QQuickAnchorChanges(); - - virtual ActionList actions(); - - QQuickAnchorSet *anchors(); - - QQuickItem *object() const; - void setObject(QQuickItem *); - - virtual void execute(Reason reason = ActualChange); - virtual bool isReversable(); - virtual void reverse(Reason reason = ActualChange); - virtual QString typeName() const; - virtual bool override(QDeclarativeActionEvent*other); - virtual bool changesBindings(); - virtual void saveOriginals(); - virtual bool needsCopy() { return true; } - virtual void copyOriginals(QDeclarativeActionEvent*); - virtual void clearBindings(); - virtual void rewind(); - virtual void saveCurrentValues(); - - QList additionalActions(); - virtual void saveTargetValues(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickParentChange) -QML_DECLARE_TYPE(QQuickAnchorSet) -QML_DECLARE_TYPE(QQuickAnchorChanges) - -QT_END_HEADER - -#endif // QQUICKSTATEOPERATIONS_P_H - diff --git a/src/declarative/items/qquicktext.cpp b/src/declarative/items/qquicktext.cpp deleted file mode 100644 index 630b466d80..0000000000 --- a/src/declarative/items/qquicktext.cpp +++ /dev/null @@ -1,1950 +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 QtDeclarative module 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 "qquicktext_p.h" -#include "qquicktext_p_p.h" - -#include -#include -#include "qquicktextnode_p.h" -#include "qquickimage_p_p.h" -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -extern Q_GUI_EXPORT bool qt_applefontsmoothing_enabled; - -class QQuickTextDocumentWithImageResources : public QTextDocument { - Q_OBJECT - -public: - QQuickTextDocumentWithImageResources(QQuickText *parent); - virtual ~QQuickTextDocumentWithImageResources(); - - void setText(const QString &); - int resourcesLoading() const { return outstanding; } - -protected: - QVariant loadResource(int type, const QUrl &name); - -private slots: - void requestFinished(); - -private: - QHash m_resources; - - int outstanding; - static QSet errors; -}; - -DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD) -DEFINE_BOOL_CONFIG_OPTION(enableImageCache, QML_ENABLE_TEXT_IMAGE_CACHE); - -QString QQuickTextPrivate::elideChar = QString(0x2026); - -QQuickTextPrivate::QQuickTextPrivate() -: color((QRgb)0), style(QQuickText::Normal), hAlign(QQuickText::AlignLeft), - vAlign(QQuickText::AlignTop), elideMode(QQuickText::ElideNone), - format(QQuickText::AutoText), wrapMode(QQuickText::NoWrap), lineHeight(1), - lineHeightMode(QQuickText::ProportionalHeight), lineCount(1), maximumLineCount(INT_MAX), - maximumLineCountValid(false), - texture(0), - imageCacheDirty(false), updateOnComponentComplete(true), - richText(false), styledText(false), singleline(false), cacheAllTextAsImage(true), internalWidthUpdate(false), - requireImplicitWidth(false), truncated(false), hAlignImplicit(true), rightToLeftText(false), - layoutTextElided(false), richTextAsImage(false), textureImageCacheDirty(false), textHasChanged(true), - naturalWidth(0), doc(0), elipsisLayout(0), textLine(0), nodeType(NodeIsNull) - -#if defined(Q_OS_MAC) -, layoutThread(0), paintingThread(0) -#endif - -{ - cacheAllTextAsImage = enableImageCache(); -} - -void QQuickTextPrivate::init() -{ - Q_Q(QQuickText); - q->setAcceptedMouseButtons(Qt::LeftButton); - q->setFlag(QQuickItem::ItemHasContents); -} - -QQuickTextDocumentWithImageResources::QQuickTextDocumentWithImageResources(QQuickText *parent) -: QTextDocument(parent), outstanding(0) -{ - setUndoRedoEnabled(false); -} - -QQuickTextDocumentWithImageResources::~QQuickTextDocumentWithImageResources() -{ - if (!m_resources.isEmpty()) - qDeleteAll(m_resources); -} - -QVariant QQuickTextDocumentWithImageResources::loadResource(int type, const QUrl &name) -{ - QDeclarativeContext *context = qmlContext(parent()); - QUrl url = context->resolvedUrl(name); - - if (type == QTextDocument::ImageResource) { - QHash::Iterator iter = m_resources.find(url); - - if (iter == m_resources.end()) { - QDeclarativePixmap *p = new QDeclarativePixmap(context->engine(), url); - iter = m_resources.insert(url, p); - - if (p->isLoading()) { - p->connectFinished(this, SLOT(requestFinished())); - outstanding++; - } - } - - QDeclarativePixmap *p = *iter; - if (p->isReady()) { - return p->image(); - } else if (p->isError()) { - if (!errors.contains(url)) { - errors.insert(url); - qmlInfo(parent()) << p->error(); - } - } - } - - return QTextDocument::loadResource(type,url); // The *resolved* URL -} - -void QQuickTextDocumentWithImageResources::requestFinished() -{ - outstanding--; - if (outstanding == 0) { - QQuickText *textItem = static_cast(parent()); - QString text = textItem->text(); -#ifndef QT_NO_TEXTHTMLPARSER - setHtml(text); -#else - setPlainText(text); -#endif - QQuickTextPrivate *d = QQuickTextPrivate::get(textItem); - d->updateLayout(); - } -} - -void QQuickTextDocumentWithImageResources::setText(const QString &text) -{ - if (!m_resources.isEmpty()) { - qDeleteAll(m_resources); - m_resources.clear(); - outstanding = 0; - } - -#ifndef QT_NO_TEXTHTMLPARSER - setHtml(text); -#else - setPlainText(text); -#endif -} - -QSet QQuickTextDocumentWithImageResources::errors; - -QQuickTextPrivate::~QQuickTextPrivate() -{ - delete elipsisLayout; - delete textLine; textLine = 0; -} - -qreal QQuickTextPrivate::getImplicitWidth() const -{ - if (!requireImplicitWidth) { - // We don't calculate implicitWidth unless it is required. - // We need to force a size update now to ensure implicitWidth is calculated - QQuickTextPrivate *me = const_cast(this); - me->requireImplicitWidth = true; - me->updateSize(); - } - return implicitWidth; -} - -void QQuickTextPrivate::updateLayout() -{ - Q_Q(QQuickText); - if (!q->isComponentComplete()) { - updateOnComponentComplete = true; - return; - } - updateOnComponentComplete = false; - layoutTextElided = false; - // Setup instance of QTextLayout for all cases other than richtext - if (!richText) { - if (elipsisLayout) { - delete elipsisLayout; - elipsisLayout = 0; - } - layout.clearLayout(); - layout.setFont(font); - if (!styledText) { - QString tmp = text; - tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); - singleline = !tmp.contains(QChar::LineSeparator); - if (singleline && !maximumLineCountValid && elideMode != QQuickText::ElideNone && q->widthValid() && wrapMode == QQuickText::NoWrap) { - QFontMetrics fm(font); - tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); - if (tmp != text) { - layoutTextElided = true; - if (!truncated) { - truncated = true; - emit q->truncatedChanged(); - } - } - } - layout.setText(tmp); - } else { - singleline = false; - if (textHasChanged) { - QDeclarativeStyledText::parse(text, layout); - textHasChanged = false; - } - } - } else { - ensureDoc(); - QTextBlockFormat::LineHeightTypes type; - type = lineHeightMode == QQuickText::FixedHeight ? QTextBlockFormat::FixedHeight : QTextBlockFormat::ProportionalHeight; - QTextBlockFormat blockFormat; - blockFormat.setLineHeight((lineHeightMode == QQuickText::FixedHeight ? lineHeight : lineHeight * 100), type); - for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next()) { - QTextCursor cursor(it); - cursor.mergeBlockFormat(blockFormat); - } - } - - updateSize(); -} - -void QQuickTextPrivate::updateSize() -{ - Q_Q(QQuickText); - - if (!q->isComponentComplete()) { - updateOnComponentComplete = true; - return; - } - - if (!requireImplicitWidth) { - emit q->implicitWidthChanged(); - // if the implicitWidth is used, then updateSize() has already been called (recursively) - if (requireImplicitWidth) - return; - } - - invalidateImageCache(); - - QFontMetrics fm(font); - if (text.isEmpty()) { - q->setImplicitSize(0, fm.height()); - paintedSize = QSize(0, fm.height()); - emit q->paintedSizeChanged(); - q->update(); - return; - } - - int dy = q->height(); - QSize size(0, 0); - -#if defined(Q_OS_MAC) - layoutThread = QThread::currentThread(); -#endif - - //setup instance of QTextLayout for all cases other than richtext - if (!richText) { - QRect textRect = setupTextLayout(); - layedOutTextRect = textRect; - size = textRect.size(); - dy -= size.height(); - } else { - singleline = false; // richtext can't elide or be optimized for single-line case - ensureDoc(); - doc->setDefaultFont(font); - QQuickText::HAlignment horizontalAlignment = q->effectiveHAlign(); - if (rightToLeftText) { - if (horizontalAlignment == QQuickText::AlignLeft) - horizontalAlignment = QQuickText::AlignRight; - else if (horizontalAlignment == QQuickText::AlignRight) - horizontalAlignment = QQuickText::AlignLeft; - } - QTextOption option; - option.setAlignment((Qt::Alignment)int(horizontalAlignment | vAlign)); - option.setWrapMode(QTextOption::WrapMode(wrapMode)); - if (!cacheAllTextAsImage && !richTextAsImage && !qmlDisableDistanceField()) - option.setUseDesignMetrics(true); - doc->setDefaultTextOption(option); - if (requireImplicitWidth && q->widthValid()) { - doc->setTextWidth(-1); - naturalWidth = doc->idealWidth(); - } - if (wrapMode != QQuickText::NoWrap && q->widthValid()) - doc->setTextWidth(q->width()); - else - doc->setTextWidth(doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug) - dy -= (int)doc->size().height(); - QSize dsize = doc->size().toSize(); - layedOutTextRect = QRect(QPoint(0,0), dsize); - size = QSize(int(doc->idealWidth()),dsize.height()); - } - int yoff = 0; - - if (q->heightValid()) { - if (vAlign == QQuickText::AlignBottom) - yoff = dy; - else if (vAlign == QQuickText::AlignVCenter) - yoff = dy/2; - } - q->setBaselineOffset(fm.ascent() + yoff); - - //### need to comfirm cost of always setting these for richText - internalWidthUpdate = true; - qreal iWidth = -1; - if (!q->widthValid()) - iWidth = size.width(); - else if (requireImplicitWidth) - iWidth = naturalWidth; - if (iWidth > -1) - q->setImplicitSize(iWidth, size.height()); - internalWidthUpdate = false; - - if (iWidth == -1) - q->setImplicitHeight(size.height()); - if (paintedSize != size) { - paintedSize = size; - emit q->paintedSizeChanged(); - } - q->update(); -} - -QQuickTextLine::QQuickTextLine() - : QObject(), m_line(0), m_height(0) -{ -} - -void QQuickTextLine::setLine(QTextLine *line) -{ - m_line = line; -} - -int QQuickTextLine::number() const -{ - if (m_line) - return m_line->lineNumber(); - return 0; -} - -qreal QQuickTextLine::width() const -{ - if (m_line) - return m_line->width(); - return 0; -} - -void QQuickTextLine::setWidth(qreal width) -{ - if (m_line) - m_line->setLineWidth(width); -} - -qreal QQuickTextLine::height() const -{ - if (m_height) - return m_height; - if (m_line) - return m_line->height(); - return 0; -} - -void QQuickTextLine::setHeight(qreal height) -{ - if (m_line) - m_line->setPosition(QPointF(m_line->x(), m_line->y() - m_line->height() + height)); - m_height = height; -} - -qreal QQuickTextLine::x() const -{ - if (m_line) - return m_line->x(); - return 0; -} - -void QQuickTextLine::setX(qreal x) -{ - if (m_line) - m_line->setPosition(QPointF(x, m_line->y())); -} - -qreal QQuickTextLine::y() const -{ - if (m_line) - return m_line->y(); - return 0; -} - -void QQuickTextLine::setY(qreal y) -{ - if (m_line) - m_line->setPosition(QPointF(m_line->x(), y)); -} - -void QQuickText::doLayout() -{ - Q_D(QQuickText); - d->updateSize(); -} - -bool QQuickTextPrivate::isLineLaidOutConnected() -{ - static int idx = this->signalIndex("lineLaidOut(QQuickTextLine*)"); - return this->isSignalConnected(idx); -} - -void QQuickTextPrivate::setupCustomLineGeometry(QTextLine &line, qreal &height, qreal elideWidth = 0) -{ - Q_Q(QQuickText); - -#if defined(Q_OS_MAC) - if (QThread::currentThread() != paintingThread) { -#endif - if (!line.lineNumber()) - linesRects.clear(); - - if (!textLine) - textLine = new QQuickTextLine; - textLine->setLine(&line); - textLine->setY(height); - textLine->setHeight(0); - - // use the text item's width by default if it has one and wrap is on - if (q->widthValid() && q->wrapMode() != QQuickText::NoWrap) - textLine->setWidth(q->width() - elideWidth); - else - textLine->setWidth(INT_MAX); - if (lineHeight != 1.0) - textLine->setHeight((lineHeightMode == QQuickText::FixedHeight) ? lineHeight : line.height() * lineHeight); - - emit q->lineLaidOut(textLine); - - linesRects << QRectF(textLine->x(), textLine->y(), textLine->width(), textLine->height()); - height += textLine->height(); - -#if defined(Q_OS_MAC) - } else { - if (line.lineNumber() < linesRects.count()) { - QRectF r = linesRects.at(line.lineNumber()); - line.setLineWidth(r.width()); - line.setPosition(r.topLeft()); - } - } -#endif -} - -/*! - Lays out the QQuickTextPrivate::layout QTextLayout in the constraints of the QQuickText. - - Returns the size of the final text. This can be used to position the text vertically (the text is - already absolutely positioned horizontally). -*/ -QRect QQuickTextPrivate::setupTextLayout() -{ - // ### text layout handling should be profiled and optimized as needed - // what about QStackTextEngine engine(tmp, d->font.font()); QTextLayout textLayout(&engine); - Q_Q(QQuickText); - layout.setCacheEnabled(true); - - qreal lineWidth = 0; - int visibleCount = 0; - - //set manual width - if (q->widthValid()) - lineWidth = q->width(); - - QTextOption textOption = layout.textOption(); - textOption.setAlignment(Qt::Alignment(q->effectiveHAlign())); - textOption.setWrapMode(QTextOption::WrapMode(wrapMode)); - if (!cacheAllTextAsImage && !richTextAsImage && !qmlDisableDistanceField()) - textOption.setUseDesignMetrics(true); - layout.setTextOption(textOption); - - QFontMetrics fm(layout.font()); - elidePos = QPointF(); - - if (requireImplicitWidth && q->widthValid()) { - // requires an extra layout - QString elidedText; - if (layoutTextElided) { - // We have provided elided text to the layout, but we must calculate unelided width. - elidedText = layout.text(); - layout.setText(text); - } - layout.beginLayout(); - forever { - QTextLine line = layout.createLine(); - if (!line.isValid()) - break; - } - layout.endLayout(); - QRectF br; - for (int i = 0; i < layout.lineCount(); ++i) { - QTextLine line = layout.lineAt(i); - br = br.united(line.naturalTextRect()); - } - naturalWidth = br.width(); - if (layoutTextElided) - layout.setText(elidedText); - } - - qreal height = 0; - QRectF br; - - bool truncate = false; - bool customLayout = isLineLaidOutConnected(); - bool elideEnabled = elideMode == QQuickText::ElideRight && q->widthValid(); - - layout.beginLayout(); - if (!lineWidth) - lineWidth = INT_MAX; - int linesLeft = maximumLineCount; - int visibleTextLength = 0; - forever { - QTextLine line = layout.createLine(); - if (!line.isValid()) - break; - - visibleCount++; - - qreal preLayoutHeight = height; - if (customLayout) { - setupCustomLineGeometry(line, height); - } else if (lineWidth) { - line.setLineWidth(lineWidth); - line.setPosition(QPointF(line.position().x(), height)); - height += (lineHeightMode == QQuickText::FixedHeight) ? lineHeight : line.height() * lineHeight; - } - - bool elide = false; - if (elideEnabled && q->heightValid() && height > q->height()) { - // This line does not fit in the remaining area. - elide = true; - if (visibleCount > 1) { - --visibleCount; - height = preLayoutHeight; - line.setLineWidth(0.0); - line.setPosition(QPointF(FLT_MAX,FLT_MAX)); - line = layout.lineAt(visibleCount-1); - } - } else { - visibleTextLength += line.textLength(); - } - - if (elide || (maximumLineCountValid && --linesLeft == 0)) { - if (visibleTextLength < text.length()) { - truncate = true; - if (elideEnabled) { - qreal elideWidth = fm.width(elideChar); - // Need to correct for alignment - if (customLayout) - setupCustomLineGeometry(line, height, elideWidth); - else - line.setLineWidth(lineWidth - elideWidth); - if (layout.text().mid(line.textStart(), line.textLength()).isRightToLeft()) { - line.setPosition(QPointF(line.position().x() + elideWidth, line.position().y())); - elidePos.setX(line.naturalTextRect().left() - elideWidth); - } else { - elidePos.setX(line.naturalTextRect().right()); - } - elidePos.setY(line.position().y()); - if (!elipsisLayout) - elipsisLayout = new QTextLayout(elideChar, layout.font()); - elipsisLayout->beginLayout(); - QTextLine el = elipsisLayout->createLine(); - el.setPosition(elidePos); - elipsisLayout->endLayout(); - br = br.united(el.naturalTextRect()); - } - br = br.united(line.naturalTextRect()); - break; - } - } - br = br.united(line.naturalTextRect()); - } - layout.endLayout(); - - //Update truncated - if (truncated != truncate) { - truncated = truncate; - emit q->truncatedChanged(); - } - - if (!customLayout) - br.setHeight(height); - - if (!q->widthValid()) - naturalWidth = br.width(); - - //Update the number of visible lines - if (lineCount != visibleCount) { - lineCount = visibleCount; - emit q->lineCountChanged(); - } - - return QRect(qRound(br.x()), qRound(br.y()), qCeil(br.width()), qCeil(br.height())); -} - -/*! - Returns a painted version of the QQuickTextPrivate::layout QTextLayout. - If \a drawStyle is true, the style color overrides all colors in the document. -*/ -QPixmap QQuickTextPrivate::textLayoutImage(bool drawStyle) -{ - QSize size = layedOutTextRect.size(); - - //paint text - QPixmap img(size); - if (!size.isEmpty()) { - img.fill(Qt::transparent); -/*#ifdef Q_OS_MAC // Fails on CocoaX64 - bool oldSmooth = qt_applefontsmoothing_enabled; - qt_applefontsmoothing_enabled = false; -#endif*/ - QPainter p(&img); -/*#ifdef Q_OS_MAC // Fails on CocoaX64 - qt_applefontsmoothing_enabled = oldSmooth; -#endif*/ - drawTextLayout(&p, QPointF(-layedOutTextRect.x(),0), drawStyle); - } - return img; -} - -/*! - Paints the QQuickTextPrivate::layout QTextLayout into \a painter at \a pos. If - \a drawStyle is true, the style color overrides all colors in the document. -*/ -void QQuickTextPrivate::drawTextLayout(QPainter *painter, const QPointF &pos, bool drawStyle) -{ - if (drawStyle) - painter->setPen(styleColor); - else - painter->setPen(color); - painter->setFont(font); - layout.draw(painter, pos); - if (!elidePos.isNull()) - painter->drawText(pos + elidePos, elideChar); -} - -/*! - Returns a painted version of the QQuickTextPrivate::doc QTextDocument. - If \a drawStyle is true, the style color overrides all colors in the document. -*/ -QPixmap QQuickTextPrivate::textDocumentImage(bool drawStyle) -{ - QSize size = doc->size().toSize(); - - //paint text - QPixmap img(size); - img.fill(Qt::transparent); -/*#ifdef Q_OS_MAC // Fails on CocoaX64 - bool oldSmooth = qt_applefontsmoothing_enabled; - qt_applefontsmoothing_enabled = false; -#endif*/ - QPainter p(&img); -/*#ifdef Q_OS_MAC // Fails on CocoaX64 - qt_applefontsmoothing_enabled = oldSmooth; -#endif*/ - - QAbstractTextDocumentLayout::PaintContext context; - - QTextOption oldOption(doc->defaultTextOption()); - if (drawStyle) { - context.palette.setColor(QPalette::Text, styleColor); - QTextOption colorOption(doc->defaultTextOption()); - colorOption.setFlags(QTextOption::SuppressColors); - doc->setDefaultTextOption(colorOption); - } else { - context.palette.setColor(QPalette::Text, color); - } - doc->documentLayout()->draw(&p, context); - if (drawStyle) - doc->setDefaultTextOption(oldOption); - return img; -} - -/*! - Mark the image cache as dirty. -*/ -void QQuickTextPrivate::invalidateImageCache() -{ - Q_Q(QQuickText); - - if (richTextAsImage || cacheAllTextAsImage || (qmlDisableDistanceField() && style != QQuickText::Normal)) { // If actually using the image cache - if (imageCacheDirty) - return; - - imageCacheDirty = true; - - if (q->isComponentComplete()) - QCoreApplication::postEvent(q, new QEvent(QEvent::User)); - } else if (q->isComponentComplete()) - q->update(); -} - -/*! - Tests if the image cache is dirty, and repaints it if it is. -*/ -void QQuickTextPrivate::checkImageCache() -{ - Q_Q(QQuickText); - - if (!imageCacheDirty) - return; - - if (text.isEmpty()) { - - imageCache = QPixmap(); - - } else { - - QPixmap textImage; - QPixmap styledImage; - - if (richText) { - textImage = textDocumentImage(false); - if (style != QQuickText::Normal) - styledImage = textDocumentImage(true); //### should use styleColor - } else { - textImage = textLayoutImage(false); - if (style != QQuickText::Normal) - styledImage = textLayoutImage(true); //### should use styleColor - } - - switch (style) { - case QQuickText::Outline: - imageCache = drawOutline(textImage, styledImage); - break; - case QQuickText::Sunken: - imageCache = drawOutline(textImage, styledImage, -1); - break; - case QQuickText::Raised: - imageCache = drawOutline(textImage, styledImage, 1); - break; - default: - imageCache = textImage; - break; - } - - } - - imageCacheDirty = false; - textureImageCacheDirty = true; - q->update(); -} - -/*! - Ensures the QQuickTextPrivate::doc variable is set to a valid text document -*/ -void QQuickTextPrivate::ensureDoc() -{ - if (!doc) { - Q_Q(QQuickText); - doc = new QQuickTextDocumentWithImageResources(q); - doc->setDocumentMargin(0); - } -} - -/*! - Draw \a styleSource as an outline around \a source and return the new image. -*/ -QPixmap QQuickTextPrivate::drawOutline(const QPixmap &source, const QPixmap &styleSource) -{ - QPixmap img = QPixmap(styleSource.width() + 2, styleSource.height() + 2); - img.fill(Qt::transparent); - - QPainter ppm(&img); - - QPoint pos(0, 0); - pos += QPoint(-1, 0); - ppm.drawPixmap(pos, styleSource); - pos += QPoint(2, 0); - ppm.drawPixmap(pos, styleSource); - pos += QPoint(-1, -1); - ppm.drawPixmap(pos, styleSource); - pos += QPoint(0, 2); - ppm.drawPixmap(pos, styleSource); - - pos += QPoint(0, -1); - ppm.drawPixmap(pos, source); - ppm.end(); - - return img; -} - -/*! - Draw \a styleSource below \a source at \a yOffset and return the new image. -*/ -QPixmap QQuickTextPrivate::drawOutline(const QPixmap &source, const QPixmap &styleSource, int yOffset) -{ - QPixmap img = QPixmap(styleSource.width() + 2, styleSource.height() + 2); - img.fill(Qt::transparent); - - QPainter ppm(&img); - - ppm.drawPixmap(QPoint(0, yOffset), styleSource); - ppm.drawPixmap(0, 0, source); - - ppm.end(); - - return img; -} - -/*! - \qmlclass Text QQuickText - \inqmlmodule QtQuick 2 - \ingroup qml-basic-visual-elements - \brief The Text item allows you to add formatted text to a scene. - \inherits Item - - Text items can display both plain and rich text. For example, red text with - a specific font and size can be defined like this: - - \qml - Text { - text: "Hello World!" - font.family: "Helvetica" - font.pointSize: 24 - color: "red" - } - \endqml - - Rich text is defined using HTML-style markup: - - \qml - Text { - text: "Hello World!" - } - \endqml - - \image declarative-text.png - - If height and width are not explicitly set, Text will attempt to determine how - much room is needed and set it accordingly. Unless \l wrapMode is set, it will always - prefer width to height (all text will be placed on a single line). - - The \l elide property can alternatively be used to fit a single line of - plain text to a set width. - - Note that the \l{Supported HTML Subset} is limited. Also, if the text contains - HTML img tags that load remote images, the text is reloaded. - - Text provides read-only text. For editable text, see \l TextEdit. - - \sa {declarative/text/fonts}{Fonts example} -*/ -QQuickText::QQuickText(QQuickItem *parent) -: QQuickImplicitSizeItem(*(new QQuickTextPrivate), parent) -{ - Q_D(QQuickText); - d->init(); -} - -QQuickText::~QQuickText() -{ -} - -/*! - \qmlproperty bool QtQuick2::Text::clip - This property holds whether the text is clipped. - - Note that if the text does not fit in the bounding rectangle it will be abruptly chopped. - - If you want to display potentially long text in a limited space, you probably want to use \c elide instead. -*/ - -/*! - \qmlproperty bool QtQuick2::Text::smooth - - This property holds whether the text is smoothly scaled or transformed. - - Smooth filtering gives better visual quality, but is slower. If - the item is displayed at its natural size, this property has no visual or - performance effect. - - \note Generally scaling artifacts are only visible if the item is stationary on - the screen. A common pattern when animating an item is to disable smooth - filtering at the beginning of the animation and reenable it at the conclusion. -*/ - -/*! - \qmlsignal QtQuick2::Text::onLineLaidOut(line) - - This handler is called for every line during the layout process. - This gives the opportunity to position and resize a line as it is being laid out. - It can for example be used to create columns or lay out text around objects. - - The properties of a line are: - \list - \o number (read-only) - \o x - \o y - \o width - \o height - \endlist - - For example, this will move the first 5 lines of a text element by 100 pixels to the right: - \code - onLineLaidOut: { - if (line.number < 5) { - line.x = line.x + 100 - line.width = line.width - 100 - } - } - \endcode -*/ - -/*! - \qmlsignal QtQuick2::Text::onLinkActivated(string link) - - This handler is called when the user clicks on a link embedded in the text. - The link must be in rich text or HTML format and the - \a link string provides access to the particular link. - - \snippet doc/src/snippets/declarative/text/onLinkActivated.qml 0 - - The example code will display the text - "The main website is at \l{http://qt.nokia.com}{Nokia Qt DF}." - - Clicking on the highlighted link will output - \tt{http://qt.nokia.com link activated} to the console. -*/ - -/*! - \qmlproperty string QtQuick2::Text::font.family - - Sets the family name of the font. - - The family name is case insensitive and may optionally include a foundry name, e.g. "Helvetica [Cronyx]". - If the family is available from more than one foundry and the foundry isn't specified, an arbitrary foundry is chosen. - If the family isn't available a family will be set using the font matching algorithm. -*/ - -/*! - \qmlproperty bool QtQuick2::Text::font.bold - - Sets whether the font weight is bold. -*/ - -/*! - \qmlproperty enumeration QtQuick2::Text::font.weight - - Sets the font's weight. - - The weight can be one of: - \list - \o Font.Light - \o Font.Normal - the default - \o Font.DemiBold - \o Font.Bold - \o Font.Black - \endlist - - \qml - Text { text: "Hello"; font.weight: Font.DemiBold } - \endqml -*/ - -/*! - \qmlproperty bool QtQuick2::Text::font.italic - - Sets whether the font has an italic style. -*/ - -/*! - \qmlproperty bool QtQuick2::Text::font.underline - - Sets whether the text is underlined. -*/ - -/*! - \qmlproperty bool QtQuick2::Text::font.strikeout - - Sets whether the font has a strikeout style. -*/ - -/*! - \qmlproperty real QtQuick2::Text::font.pointSize - - Sets the font size in points. The point size must be greater than zero. -*/ - -/*! - \qmlproperty int QtQuick2::Text::font.pixelSize - - Sets the font size in pixels. - - Using this function makes the font device dependent. - Use \c pointSize to set the size of the font in a device independent manner. -*/ - -/*! - \qmlproperty real QtQuick2::Text::font.letterSpacing - - Sets the letter spacing for the font. - - Letter spacing changes the default spacing between individual letters in the font. - A positive value increases the letter spacing by the corresponding pixels; a negative value decreases the spacing. -*/ - -/*! - \qmlproperty real QtQuick2::Text::font.wordSpacing - - Sets the word spacing for the font. - - Word spacing changes the default spacing between individual words. - A positive value increases the word spacing by a corresponding amount of pixels, - while a negative value decreases the inter-word spacing accordingly. -*/ - -/*! - \qmlproperty enumeration QtQuick2::Text::font.capitalization - - Sets the capitalization for the text. - - \list - \o Font.MixedCase - This is the normal text rendering option where no capitalization change is applied. - \o Font.AllUppercase - This alters the text to be rendered in all uppercase type. - \o Font.AllLowercase - This alters the text to be rendered in all lowercase type. - \o Font.SmallCaps - This alters the text to be rendered in small-caps type. - \o Font.Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character. - \endlist - - \qml - Text { text: "Hello"; font.capitalization: Font.AllLowercase } - \endqml -*/ -QFont QQuickText::font() const -{ - Q_D(const QQuickText); - return d->sourceFont; -} - -void QQuickText::setFont(const QFont &font) -{ - Q_D(QQuickText); - if (d->sourceFont == font) - return; - - d->sourceFont = font; - QFont oldFont = d->font; - d->font = font; - - if (d->font.pointSizeF() != -1) { - // 0.5pt resolution - qreal size = qRound(d->font.pointSizeF()*2.0); - d->font.setPointSizeF(size/2.0); - } - - if (oldFont != d->font) - d->updateLayout(); - - emit fontChanged(d->sourceFont); -} - -/*! - \qmlproperty string QtQuick2::Text::text - - The text to display. Text supports both plain and rich text strings. - - The item will try to automatically determine whether the text should - be treated as styled text. This determination is made using Qt::mightBeRichText(). -*/ -QString QQuickText::text() const -{ - Q_D(const QQuickText); - return d->text; -} - -void QQuickText::setText(const QString &n) -{ - Q_D(QQuickText); - if (d->text == n) - return; - - d->richText = d->format == RichText; - d->styledText = d->format == StyledText || (d->format == AutoText && Qt::mightBeRichText(n)); - d->text = n; - if (isComponentComplete()) { - if (d->richText) { - d->ensureDoc(); - d->doc->setText(n); - d->rightToLeftText = d->doc->toPlainText().isRightToLeft(); - d->richTextAsImage = enableImageCache(); - } else { - d->rightToLeftText = d->text.isRightToLeft(); - } - d->determineHorizontalAlignment(); - } - d->textHasChanged = true; - d->updateLayout(); - emit textChanged(d->text); -} - -/*! - \qmlproperty color QtQuick2::Text::color - - The text color. - - An example of green text defined using hexadecimal notation: - \qml - Text { - color: "#00FF00" - text: "green text" - } - \endqml - - An example of steel blue text defined using an SVG color name: - \qml - Text { - color: "steelblue" - text: "blue text" - } - \endqml -*/ -QColor QQuickText::color() const -{ - Q_D(const QQuickText); - return d->color; -} - -void QQuickText::setColor(const QColor &color) -{ - Q_D(QQuickText); - if (d->color == color) - return; - - d->color = color; - d->invalidateImageCache(); - emit colorChanged(d->color); -} -/*! - \qmlproperty enumeration QtQuick2::Text::style - - Set an additional text style. - - Supported text styles are: - \list - \o Text.Normal - the default - \o Text.Outline - \o Text.Raised - \o Text.Sunken - \endlist - - \qml - Row { - Text { font.pointSize: 24; text: "Normal" } - Text { font.pointSize: 24; text: "Raised"; style: Text.Raised; styleColor: "#AAAAAA" } - Text { font.pointSize: 24; text: "Outline";style: Text.Outline; styleColor: "red" } - Text { font.pointSize: 24; text: "Sunken"; style: Text.Sunken; styleColor: "#AAAAAA" } - } - \endqml - - \image declarative-textstyle.png -*/ -QQuickText::TextStyle QQuickText::style() const -{ - Q_D(const QQuickText); - return d->style; -} - -void QQuickText::setStyle(QQuickText::TextStyle style) -{ - Q_D(QQuickText); - if (d->style == style) - return; - - // changing to/from Normal requires the boundingRect() to change - if (isComponentComplete() && (d->style == Normal || style == Normal)) - update(); - d->style = style; - d->invalidateImageCache(); - emit styleChanged(d->style); -} - -/*! - \qmlproperty color QtQuick2::Text::styleColor - - Defines the secondary color used by text styles. - - \c styleColor is used as the outline color for outlined text, and as the - shadow color for raised or sunken text. If no style has been set, it is not - used at all. - - \qml - Text { font.pointSize: 18; text: "hello"; style: Text.Raised; styleColor: "gray" } - \endqml - - \sa style - */ -QColor QQuickText::styleColor() const -{ - Q_D(const QQuickText); - return d->styleColor; -} - -void QQuickText::setStyleColor(const QColor &color) -{ - Q_D(QQuickText); - if (d->styleColor == color) - return; - - d->styleColor = color; - d->invalidateImageCache(); - emit styleColorChanged(d->styleColor); -} - -/*! - \qmlproperty enumeration QtQuick2::Text::horizontalAlignment - \qmlproperty enumeration QtQuick2::Text::verticalAlignment - \qmlproperty enumeration QtQuick2::Text::effectiveHorizontalAlignment - - Sets the horizontal and vertical alignment of the text within the Text items - width and height. By default, the text is vertically aligned to the top. Horizontal - alignment follows the natural alignment of the text, for example text that is read - from left to right will be aligned to the left. - - The valid values for \c horizontalAlignment are \c Text.AlignLeft, \c Text.AlignRight, \c Text.AlignHCenter and - \c Text.AlignJustify. The valid values for \c verticalAlignment are \c Text.AlignTop, \c Text.AlignBottom - and \c Text.AlignVCenter. - - Note that for a single line of text, the size of the text is the area of the text. In this common case, - all alignments are equivalent. If you want the text to be, say, centered in its parent, then you will - need to either modify the Item::anchors, or set horizontalAlignment to Text.AlignHCenter and bind the width to - that of the parent. - - When using the attached property LayoutMirroring::enabled to mirror application - layouts, the horizontal alignment of text will also be mirrored. However, the property - \c horizontalAlignment will remain unchanged. To query the effective horizontal alignment - of Text, use the read-only property \c effectiveHorizontalAlignment. -*/ -QQuickText::HAlignment QQuickText::hAlign() const -{ - Q_D(const QQuickText); - return d->hAlign; -} - -void QQuickText::setHAlign(HAlignment align) -{ - Q_D(QQuickText); - bool forceAlign = d->hAlignImplicit && d->effectiveLayoutMirror; - d->hAlignImplicit = false; - if (d->setHAlign(align, forceAlign) && isComponentComplete()) - d->updateLayout(); -} - -void QQuickText::resetHAlign() -{ - Q_D(QQuickText); - d->hAlignImplicit = true; - if (isComponentComplete() && d->determineHorizontalAlignment()) - d->updateLayout(); -} - -QQuickText::HAlignment QQuickText::effectiveHAlign() const -{ - Q_D(const QQuickText); - QQuickText::HAlignment effectiveAlignment = d->hAlign; - if (!d->hAlignImplicit && d->effectiveLayoutMirror) { - switch (d->hAlign) { - case QQuickText::AlignLeft: - effectiveAlignment = QQuickText::AlignRight; - break; - case QQuickText::AlignRight: - effectiveAlignment = QQuickText::AlignLeft; - break; - default: - break; - } - } - return effectiveAlignment; -} - -bool QQuickTextPrivate::setHAlign(QQuickText::HAlignment alignment, bool forceAlign) -{ - Q_Q(QQuickText); - if (hAlign != alignment || forceAlign) { - QQuickText::HAlignment oldEffectiveHAlign = q->effectiveHAlign(); - hAlign = alignment; - - emit q->horizontalAlignmentChanged(hAlign); - if (oldEffectiveHAlign != q->effectiveHAlign()) - emit q->effectiveHorizontalAlignmentChanged(); - return true; - } - return false; -} - -bool QQuickTextPrivate::determineHorizontalAlignment() -{ - if (hAlignImplicit) { - bool alignToRight = text.isEmpty() ? QGuiApplication::keyboardInputDirection() == Qt::RightToLeft : rightToLeftText; - return setHAlign(alignToRight ? QQuickText::AlignRight : QQuickText::AlignLeft); - } - return false; -} - -void QQuickTextPrivate::mirrorChange() -{ - Q_Q(QQuickText); - if (q->isComponentComplete()) { - if (!hAlignImplicit && (hAlign == QQuickText::AlignRight || hAlign == QQuickText::AlignLeft)) { - updateLayout(); - emit q->effectiveHorizontalAlignmentChanged(); - } - } -} - -QTextDocument *QQuickTextPrivate::textDocument() -{ - return doc; -} - -QQuickText::VAlignment QQuickText::vAlign() const -{ - Q_D(const QQuickText); - return d->vAlign; -} - -void QQuickText::setVAlign(VAlignment align) -{ - Q_D(QQuickText); - if (d->vAlign == align) - return; - - d->vAlign = align; - emit verticalAlignmentChanged(align); -} - -/*! - \qmlproperty enumeration QtQuick2::Text::wrapMode - - Set this property to wrap the text to the Text item's width. The text will only - wrap if an explicit width has been set. wrapMode can be one of: - - \list - \o Text.NoWrap (default) - no wrapping will be performed. If the text contains insufficient newlines, then \l paintedWidth will exceed a set width. - \o Text.WordWrap - wrapping is done on word boundaries only. If a word is too long, \l paintedWidth will exceed a set width. - \o Text.WrapAnywhere - wrapping is done at any point on a line, even if it occurs in the middle of a word. - \o Text.Wrap - if possible, wrapping occurs at a word boundary; otherwise it will occur at the appropriate point on the line, even in the middle of a word. - \endlist -*/ -QQuickText::WrapMode QQuickText::wrapMode() const -{ - Q_D(const QQuickText); - return d->wrapMode; -} - -void QQuickText::setWrapMode(WrapMode mode) -{ - Q_D(QQuickText); - if (mode == d->wrapMode) - return; - - d->wrapMode = mode; - d->updateLayout(); - - emit wrapModeChanged(); -} - -/*! - \qmlproperty int QtQuick2::Text::lineCount - - Returns the number of lines visible in the text item. - - This property is not supported for rich text. - - \sa maximumLineCount -*/ -int QQuickText::lineCount() const -{ - Q_D(const QQuickText); - return d->lineCount; -} - -/*! - \qmlproperty bool QtQuick2::Text::truncated - - Returns true if the text has been truncated due to \l maximumLineCount - or \l elide. - - This property is not supported for rich text. - - \sa maximumLineCount, elide -*/ -bool QQuickText::truncated() const -{ - Q_D(const QQuickText); - return d->truncated; -} - -/*! - \qmlproperty int QtQuick2::Text::maximumLineCount - - Set this property to limit the number of lines that the text item will show. - If elide is set to Text.ElideRight, the text will be elided appropriately. - By default, this is the value of the largest possible integer. - - This property is not supported for rich text. - - \sa lineCount, elide -*/ -int QQuickText::maximumLineCount() const -{ - Q_D(const QQuickText); - return d->maximumLineCount; -} - -void QQuickText::setMaximumLineCount(int lines) -{ - Q_D(QQuickText); - - d->maximumLineCountValid = lines==INT_MAX ? false : true; - if (d->maximumLineCount != lines) { - d->maximumLineCount = lines; - d->updateLayout(); - emit maximumLineCountChanged(); - } -} - -void QQuickText::resetMaximumLineCount() -{ - Q_D(QQuickText); - setMaximumLineCount(INT_MAX); - d->elidePos = QPointF(); - if (d->truncated != false) { - d->truncated = false; - emit truncatedChanged(); - } -} - -/*! - \qmlproperty enumeration QtQuick2::Text::textFormat - - The way the text property should be displayed. - - Supported text formats are: - - \list - \o Text.AutoText (default) - \o Text.PlainText - \o Text.StyledText - \o Text.RichText - \endlist - - If the text format is \c Text.AutoText the text element - will automatically determine whether the text should be treated as - styled text. This determination is made using Qt::mightBeRichText(). - - Text.StyledText is an optimized format supporting some basic text - styling markup, in the style of html 3.2: - - \code - - bold - - italic -
- new line -

- paragraph - - underlined text - -

to
- headers - - anchor -
    ,