summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-05-26 07:41:06 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-05-26 07:41:06 (GMT)
commit12ebfedc3de64e99082ca573351bdd24b1d42370 (patch)
tree0290b22723ae07fb4b11e6f5008e5bae2050a12b
parent7ffe42d376b574239480b38b8f6430339b806daa (diff)
parentbaec0ecd314c6e9563bd56cf19571ca71d7d11cd (diff)
downloadQt-12ebfedc3de64e99082ca573351bdd24b1d42370.zip
Qt-12ebfedc3de64e99082ca573351bdd24b1d42370.tar.gz
Qt-12ebfedc3de64e99082ca573351bdd24b1d42370.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Conflicts: src/corelib/kernel/qcoreevent.h src/gui/graphicsview/qgraphicsitem_p.h
-rwxr-xr-xconfigure4
-rw-r--r--demos/boxes/boxes.pro5
-rw-r--r--demos/boxes/glbuffers.cpp26
-rw-r--r--demos/boxes/glbuffers.h8
-rw-r--r--demos/boxes/glextensions.cpp37
-rw-r--r--demos/boxes/glextensions.h85
-rw-r--r--demos/boxes/glshaders.cpp266
-rw-r--r--demos/boxes/qtbox.cpp33
-rw-r--r--demos/boxes/qtbox.h8
-rw-r--r--demos/boxes/roundedbox.cpp21
-rw-r--r--demos/boxes/roundedbox.h9
-rw-r--r--demos/boxes/scene.cpp152
-rw-r--r--demos/boxes/scene.h17
-rw-r--r--demos/boxes/trackball.cpp50
-rw-r--r--demos/boxes/trackball.h17
-rw-r--r--demos/boxes/vector.h602
-rw-r--r--demos/qtdemo/xml/examples.xml15
-rw-r--r--dist/changes-4.5.24
-rw-r--r--doc/src/animation.qdoc368
-rw-r--r--doc/src/diagrams/animations-architecture.svg351
-rw-r--r--doc/src/diagrams/programs/easingcurve/easingcurve.pro13
-rw-r--r--doc/src/diagrams/programs/easingcurve/main.cpp90
-rw-r--r--doc/src/examples-overview.qdoc8
-rw-r--r--doc/src/examples.qdoc17
-rw-r--r--doc/src/examples/eventtransitions.qdoc86
-rw-r--r--doc/src/examples/factorial.qdoc102
-rw-r--r--doc/src/examples/pingpong.qdoc107
-rw-r--r--doc/src/examples/stickman.qdoc115
-rw-r--r--doc/src/examples/tankgame.qdoc117
-rw-r--r--doc/src/examples/trafficlight.qdoc99
-rw-r--r--doc/src/examples/twowaybutton.qdoc82
-rw-r--r--doc/src/external-resources.qdoc10
-rw-r--r--doc/src/groups.qdoc23
-rw-r--r--doc/src/images/animations-architecture.pngbin0 -> 27619 bytes
-rw-r--r--doc/src/images/factorial-example.pngbin0 -> 4032 bytes
-rw-r--r--doc/src/images/inputdialogs.pngbin4244 -> 30369 bytes
-rw-r--r--doc/src/images/pingpong-example.pngbin0 -> 7843 bytes
-rw-r--r--doc/src/images/qeasingcurve-cosinecurve.pngbin0 -> 2544 bytes
-rw-r--r--doc/src/images/qeasingcurve-inback.pngbin0 -> 2225 bytes
-rw-r--r--doc/src/images/qeasingcurve-inbounce.pngbin0 -> 2378 bytes
-rw-r--r--doc/src/images/qeasingcurve-incirc.pngbin0 -> 2138 bytes
-rw-r--r--doc/src/images/qeasingcurve-incubic.pngbin0 -> 2230 bytes
-rw-r--r--doc/src/images/qeasingcurve-incurve.pngbin0 -> 2325 bytes
-rw-r--r--doc/src/images/qeasingcurve-inelastic.pngbin0 -> 2314 bytes
-rw-r--r--doc/src/images/qeasingcurve-inexpo.pngbin0 -> 2183 bytes
-rw-r--r--doc/src/images/qeasingcurve-inoutback.pngbin0 -> 2460 bytes
-rw-r--r--doc/src/images/qeasingcurve-inoutbounce.pngbin0 -> 2522 bytes
-rw-r--r--doc/src/images/qeasingcurve-inoutcirc.pngbin0 -> 2352 bytes
-rw-r--r--doc/src/images/qeasingcurve-inoutcubic.pngbin0 -> 2410 bytes
-rw-r--r--doc/src/images/qeasingcurve-inoutelastic.pngbin0 -> 2485 bytes
-rw-r--r--doc/src/images/qeasingcurve-inoutexpo.pngbin0 -> 2383 bytes
-rw-r--r--doc/src/images/qeasingcurve-inoutquad.pngbin0 -> 2392 bytes
-rw-r--r--doc/src/images/qeasingcurve-inoutquart.pngbin0 -> 2331 bytes
-rw-r--r--doc/src/images/qeasingcurve-inoutquint.pngbin0 -> 2244 bytes
-rw-r--r--doc/src/images/qeasingcurve-inoutsine.pngbin0 -> 2405 bytes
-rw-r--r--doc/src/images/qeasingcurve-inquad.pngbin0 -> 2283 bytes
-rw-r--r--doc/src/images/qeasingcurve-inquart.pngbin0 -> 2261 bytes
-rw-r--r--doc/src/images/qeasingcurve-inquint.pngbin0 -> 2178 bytes
-rw-r--r--doc/src/images/qeasingcurve-insine.pngbin0 -> 2167 bytes
-rw-r--r--doc/src/images/qeasingcurve-linear.pngbin0 -> 2165 bytes
-rw-r--r--doc/src/images/qeasingcurve-outback.pngbin0 -> 2371 bytes
-rw-r--r--doc/src/images/qeasingcurve-outbounce.pngbin0 -> 2481 bytes
-rw-r--r--doc/src/images/qeasingcurve-outcirc.pngbin0 -> 2269 bytes
-rw-r--r--doc/src/images/qeasingcurve-outcubic.pngbin0 -> 2336 bytes
-rw-r--r--doc/src/images/qeasingcurve-outcurve.pngbin0 -> 2389 bytes
-rw-r--r--doc/src/images/qeasingcurve-outelastic.pngbin0 -> 2402 bytes
-rw-r--r--doc/src/images/qeasingcurve-outexpo.pngbin0 -> 2299 bytes
-rw-r--r--doc/src/images/qeasingcurve-outinback.pngbin0 -> 2400 bytes
-rw-r--r--doc/src/images/qeasingcurve-outinbounce.pngbin0 -> 2568 bytes
-rw-r--r--doc/src/images/qeasingcurve-outincirc.pngbin0 -> 2339 bytes
-rw-r--r--doc/src/images/qeasingcurve-outincubic.pngbin0 -> 2393 bytes
-rw-r--r--doc/src/images/qeasingcurve-outinelastic.pngbin0 -> 2517 bytes
-rw-r--r--doc/src/images/qeasingcurve-outinexpo.pngbin0 -> 2377 bytes
-rw-r--r--doc/src/images/qeasingcurve-outinquad.pngbin0 -> 2380 bytes
-rw-r--r--doc/src/images/qeasingcurve-outinquart.pngbin0 -> 2319 bytes
-rw-r--r--doc/src/images/qeasingcurve-outinquint.pngbin0 -> 2248 bytes
-rw-r--r--doc/src/images/qeasingcurve-outinsine.pngbin0 -> 2388 bytes
-rw-r--r--doc/src/images/qeasingcurve-outquad.pngbin0 -> 2324 bytes
-rw-r--r--doc/src/images/qeasingcurve-outquart.pngbin0 -> 2304 bytes
-rw-r--r--doc/src/images/qeasingcurve-outquint.pngbin0 -> 2242 bytes
-rw-r--r--doc/src/images/qeasingcurve-outsine.pngbin0 -> 2364 bytes
-rw-r--r--doc/src/images/qeasingcurve-sinecurve.pngbin0 -> 2470 bytes
-rw-r--r--doc/src/images/statemachine-button-history.pngbin0 -> 8493 bytes
-rw-r--r--doc/src/images/statemachine-button-nested.pngbin0 -> 7051 bytes
-rw-r--r--doc/src/images/statemachine-button.pngbin0 -> 4233 bytes
-rw-r--r--doc/src/images/statemachine-customevents.pngbin0 -> 2544 bytes
-rw-r--r--doc/src/images/statemachine-customevents2.pngbin0 -> 6713 bytes
-rw-r--r--doc/src/images/statemachine-finished.pngbin0 -> 5518 bytes
-rw-r--r--doc/src/images/statemachine-nonparallel.pngbin0 -> 5350 bytes
-rw-r--r--doc/src/images/statemachine-parallel.pngbin0 -> 8631 bytes
-rw-r--r--doc/src/images/stickman-example.pngbin0 -> 18867 bytes
-rw-r--r--doc/src/images/stickman-example1.pngbin0 -> 64543 bytes
-rw-r--r--doc/src/images/stickman-example2.pngbin0 -> 37412 bytes
-rw-r--r--doc/src/images/stickman-example3.pngbin0 -> 23591 bytes
-rw-r--r--doc/src/images/tankgame-example.pngbin0 -> 16089 bytes
-rw-r--r--doc/src/images/trafficlight-example.pngbin0 -> 5325 bytes
-rw-r--r--doc/src/images/trafficlight-example1.pngbin0 -> 3694 bytes
-rw-r--r--doc/src/images/trafficlight-example2.pngbin0 -> 7257 bytes
-rw-r--r--doc/src/snippets/animation/sequential/icons.qrc6
-rw-r--r--doc/src/snippets/animation/sequential/icons/left.pngbin0 -> 413 bytes
-rw-r--r--doc/src/snippets/animation/sequential/icons/right.pngbin0 -> 414 bytes
-rw-r--r--doc/src/snippets/animation/sequential/main.cpp50
-rw-r--r--doc/src/snippets/animation/sequential/sequential.pro4
-rw-r--r--doc/src/snippets/animation/sequential/tracer.cpp25
-rw-r--r--doc/src/snippets/animation/sequential/tracer.h23
-rw-r--r--doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp4
-rw-r--r--doc/src/statemachine.qdoc645
-rw-r--r--examples/animation/README38
-rw-r--r--examples/animation/animatedtiles/animatedtiles.pro8
-rw-r--r--examples/animation/animatedtiles/animatedtiles.qrc11
-rw-r--r--examples/animation/animatedtiles/images/Time-For-Lunch-2.jpgbin0 -> 32471 bytes
-rw-r--r--examples/animation/animatedtiles/images/centered.pngbin0 -> 892 bytes
-rw-r--r--examples/animation/animatedtiles/images/ellipse.pngbin0 -> 10767 bytes
-rw-r--r--examples/animation/animatedtiles/images/figure8.pngbin0 -> 14050 bytes
-rw-r--r--examples/animation/animatedtiles/images/kinetic.pngbin0 -> 6776 bytes
-rw-r--r--examples/animation/animatedtiles/images/random.pngbin0 -> 14969 bytes
-rw-r--r--examples/animation/animatedtiles/images/tile.pngbin0 -> 16337 bytes
-rw-r--r--examples/animation/animatedtiles/main.cpp280
-rw-r--r--examples/animation/animation.pro16
-rw-r--r--examples/animation/appchooser/accessories-dictionary.pngbin0 -> 5396 bytes
-rw-r--r--examples/animation/appchooser/akregator.pngbin0 -> 4873 bytes
-rw-r--r--examples/animation/appchooser/appchooser.pro8
-rw-r--r--examples/animation/appchooser/appchooser.qrc8
-rw-r--r--examples/animation/appchooser/digikam.pngbin0 -> 3334 bytes
-rw-r--r--examples/animation/appchooser/k3b.pngbin0 -> 8220 bytes
-rw-r--r--examples/animation/appchooser/main.cpp158
-rw-r--r--examples/animation/easing/animation.h101
-rw-r--r--examples/animation/easing/easing.pro14
-rw-r--r--examples/animation/easing/easing.qrc5
-rw-r--r--examples/animation/easing/form.ui201
-rw-r--r--examples/animation/easing/images/qt-logo.pngbin0 -> 5149 bytes
-rw-r--r--examples/animation/easing/main.cpp53
-rw-r--r--examples/animation/easing/window.cpp163
-rw-r--r--examples/animation/easing/window.h79
-rw-r--r--examples/animation/moveblocks/main.cpp295
-rw-r--r--examples/animation/moveblocks/moveblocks.pro7
-rw-r--r--examples/animation/states/accessories-dictionary.pngbin0 -> 5396 bytes
-rw-r--r--examples/animation/states/akregator.pngbin0 -> 4873 bytes
-rw-r--r--examples/animation/states/digikam.pngbin0 -> 3334 bytes
-rw-r--r--examples/animation/states/help-browser.pngbin0 -> 6984 bytes
-rw-r--r--examples/animation/states/k3b.pngbin0 -> 8220 bytes
-rw-r--r--examples/animation/states/kchart.pngbin0 -> 4887 bytes
-rw-r--r--examples/animation/states/main.cpp284
-rw-r--r--examples/animation/states/states.pro8
-rw-r--r--examples/animation/states/states.qrc10
-rw-r--r--examples/animation/stickman/animation.cpp193
-rw-r--r--examples/animation/stickman/animation.h83
-rw-r--r--examples/animation/stickman/animations/chillingbin0 -> 6508 bytes
-rw-r--r--examples/animation/stickman/animations/dancingbin0 -> 2348 bytes
-rw-r--r--examples/animation/stickman/animations/deadbin0 -> 268 bytes
-rw-r--r--examples/animation/stickman/animations/jumpingbin0 -> 1308 bytes
-rw-r--r--examples/animation/stickman/editor/animationdialog.cpp192
-rw-r--r--examples/animation/stickman/editor/animationdialog.h84
-rw-r--r--examples/animation/stickman/editor/editor.pri2
-rw-r--r--examples/animation/stickman/editor/mainwindow.cpp76
-rw-r--r--examples/animation/stickman/editor/mainwindow.h58
-rw-r--r--examples/animation/stickman/graphicsview.cpp81
-rw-r--r--examples/animation/stickman/graphicsview.h64
-rw-r--r--examples/animation/stickman/lifecycle.cpp212
-rw-r--r--examples/animation/stickman/lifecycle.h80
-rw-r--r--examples/animation/stickman/main.cpp97
-rw-r--r--examples/animation/stickman/node.cpp92
-rw-r--r--examples/animation/stickman/node.h72
-rw-r--r--examples/animation/stickman/stickman.cpp343
-rw-r--r--examples/animation/stickman/stickman.h103
-rw-r--r--examples/animation/stickman/stickman.pro21
-rw-r--r--examples/animation/sub-attaq/animationmanager.cpp93
-rw-r--r--examples/animation/sub-attaq/animationmanager.h70
-rw-r--r--examples/animation/sub-attaq/boat.cpp318
-rw-r--r--examples/animation/sub-attaq/boat.h102
-rw-r--r--examples/animation/sub-attaq/boat_p.h256
-rw-r--r--examples/animation/sub-attaq/bomb.cpp124
-rw-r--r--examples/animation/sub-attaq/bomb.h76
-rw-r--r--examples/animation/sub-attaq/custompropertyanimation.cpp108
-rw-r--r--examples/animation/sub-attaq/custompropertyanimation.h114
-rw-r--r--examples/animation/sub-attaq/data.xml15
-rw-r--r--examples/animation/sub-attaq/graphicsscene.cpp374
-rw-r--r--examples/animation/sub-attaq/graphicsscene.h131
-rw-r--r--examples/animation/sub-attaq/main.cpp57
-rw-r--r--examples/animation/sub-attaq/mainwindow.cpp92
-rw-r--r--examples/animation/sub-attaq/mainwindow.h64
-rw-r--r--examples/animation/sub-attaq/pics/big/background.pngbin0 -> 48858 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/boat.pngbin0 -> 5198 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/bomb.pngbin0 -> 760 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/explosion/boat/step1.pngbin0 -> 5760 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/explosion/boat/step2.pngbin0 -> 9976 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/explosion/boat/step3.pngbin0 -> 12411 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/explosion/boat/step4.pngbin0 -> 15438 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/explosion/submarine/step1.pngbin0 -> 3354 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/explosion/submarine/step2.pngbin0 -> 6205 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/explosion/submarine/step3.pngbin0 -> 6678 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/explosion/submarine/step4.pngbin0 -> 6666 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/submarine.pngbin0 -> 3202 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/surface.pngbin0 -> 575 bytes
-rw-r--r--examples/animation/sub-attaq/pics/big/torpedo.pngbin0 -> 951 bytes
-rw-r--r--examples/animation/sub-attaq/pics/scalable/background-n810.svg171
-rw-r--r--examples/animation/sub-attaq/pics/scalable/background.svg171
-rw-r--r--examples/animation/sub-attaq/pics/scalable/boat.svg279
-rw-r--r--examples/animation/sub-attaq/pics/scalable/bomb.svg138
-rw-r--r--examples/animation/sub-attaq/pics/scalable/sand.svg103
-rw-r--r--examples/animation/sub-attaq/pics/scalable/see.svg44
-rw-r--r--examples/animation/sub-attaq/pics/scalable/sky.svg45
-rw-r--r--examples/animation/sub-attaq/pics/scalable/sub-attaq.svg1473
-rw-r--r--examples/animation/sub-attaq/pics/scalable/submarine.svg214
-rw-r--r--examples/animation/sub-attaq/pics/scalable/surface.svg49
-rw-r--r--examples/animation/sub-attaq/pics/scalable/torpedo.svg127
-rw-r--r--examples/animation/sub-attaq/pics/small/background.pngbin0 -> 34634 bytes
-rw-r--r--examples/animation/sub-attaq/pics/small/boat.pngbin0 -> 2394 bytes
-rw-r--r--examples/animation/sub-attaq/pics/small/bomb.pngbin0 -> 760 bytes
-rw-r--r--examples/animation/sub-attaq/pics/small/submarine.pngbin0 -> 1338 bytes
-rw-r--r--examples/animation/sub-attaq/pics/small/surface.pngbin0 -> 502 bytes
-rw-r--r--examples/animation/sub-attaq/pics/small/torpedo.pngbin0 -> 951 bytes
-rw-r--r--examples/animation/sub-attaq/pics/welcome/logo-a.pngbin0 -> 5972 bytes
-rw-r--r--examples/animation/sub-attaq/pics/welcome/logo-a2.pngbin0 -> 5969 bytes
-rw-r--r--examples/animation/sub-attaq/pics/welcome/logo-b.pngbin0 -> 6869 bytes
-rw-r--r--examples/animation/sub-attaq/pics/welcome/logo-dash.pngbin0 -> 2255 bytes
-rw-r--r--examples/animation/sub-attaq/pics/welcome/logo-excl.pngbin0 -> 2740 bytes
-rw-r--r--examples/animation/sub-attaq/pics/welcome/logo-q.pngbin0 -> 7016 bytes
-rw-r--r--examples/animation/sub-attaq/pics/welcome/logo-s.pngbin0 -> 5817 bytes
-rw-r--r--examples/animation/sub-attaq/pics/welcome/logo-t.pngbin0 -> 3717 bytes
-rw-r--r--examples/animation/sub-attaq/pics/welcome/logo-t2.pngbin0 -> 3688 bytes
-rw-r--r--examples/animation/sub-attaq/pics/welcome/logo-u.pngbin0 -> 5374 bytes
-rw-r--r--examples/animation/sub-attaq/pixmapitem.cpp59
-rw-r--r--examples/animation/sub-attaq/pixmapitem.h63
-rw-r--r--examples/animation/sub-attaq/progressitem.cpp67
-rw-r--r--examples/animation/sub-attaq/progressitem.h61
-rw-r--r--examples/animation/sub-attaq/qanimationstate.cpp150
-rw-r--r--examples/animation/sub-attaq/qanimationstate.h92
-rw-r--r--examples/animation/sub-attaq/states.cpp325
-rw-r--r--examples/animation/sub-attaq/states.h180
-rw-r--r--examples/animation/sub-attaq/sub-attaq.pro36
-rw-r--r--examples/animation/sub-attaq/subattaq.qrc38
-rw-r--r--examples/animation/sub-attaq/submarine.cpp211
-rw-r--r--examples/animation/sub-attaq/submarine.h92
-rw-r--r--examples/animation/sub-attaq/submarine_p.h139
-rw-r--r--examples/animation/sub-attaq/torpedo.cpp120
-rw-r--r--examples/animation/sub-attaq/torpedo.h76
-rw-r--r--examples/examples.pro2
-rw-r--r--examples/opengl/framebufferobject/glwidget.cpp28
-rw-r--r--examples/opengl/framebufferobject/glwidget.h3
-rw-r--r--examples/opengl/hellogl_es2/glwidget.cpp391
-rw-r--r--examples/opengl/hellogl_es2/glwidget.h31
-rw-r--r--examples/statemachine/README36
-rw-r--r--examples/statemachine/eventtransitions/eventtransitions.pro7
-rw-r--r--examples/statemachine/eventtransitions/main.cpp116
-rw-r--r--examples/statemachine/factorial/factorial.pro11
-rw-r--r--examples/statemachine/factorial/main.cpp182
-rw-r--r--examples/statemachine/pingpong/main.cpp145
-rw-r--r--examples/statemachine/pingpong/pingpong.pro11
-rw-r--r--examples/statemachine/statemachine.pro15
-rw-r--r--examples/statemachine/tankgame/gameitem.cpp129
-rw-r--r--examples/statemachine/tankgame/gameitem.h66
-rw-r--r--examples/statemachine/tankgame/gameovertransition.cpp80
-rw-r--r--examples/statemachine/tankgame/gameovertransition.h63
-rw-r--r--examples/statemachine/tankgame/main.cpp53
-rw-r--r--examples/statemachine/tankgame/mainwindow.cpp342
-rw-r--r--examples/statemachine/tankgame/mainwindow.h93
-rw-r--r--examples/statemachine/tankgame/plugin.h62
-rw-r--r--examples/statemachine/tankgame/rocketitem.cpp101
-rw-r--r--examples/statemachine/tankgame/rocketitem.h66
-rw-r--r--examples/statemachine/tankgame/tankgame.pro19
-rw-r--r--examples/statemachine/tankgame/tankitem.cpp302
-rw-r--r--examples/statemachine/tankgame/tankitem.h109
-rw-r--r--examples/statemachine/tankgameplugins/random_ai/random_ai.pro13
-rw-r--r--examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp79
-rw-r--r--examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h105
-rw-r--r--examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp89
-rw-r--r--examples/statemachine/tankgameplugins/seek_ai/seek_ai.h249
-rw-r--r--examples/statemachine/tankgameplugins/seek_ai/seek_ai.pro13
-rw-r--r--examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp70
-rw-r--r--examples/statemachine/tankgameplugins/spin_ai/spin_ai.h (renamed from demos/boxes/glshaders.h)88
-rw-r--r--examples/statemachine/tankgameplugins/spin_ai/spin_ai.pro13
-rw-r--r--examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp70
-rw-r--r--examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h92
-rw-r--r--examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.pro13
-rw-r--r--examples/statemachine/tankgameplugins/tankgameplugins.pro11
-rw-r--r--examples/statemachine/trafficlight/main.cpp190
-rw-r--r--examples/statemachine/trafficlight/trafficlight.pro7
-rw-r--r--examples/statemachine/twowaybutton/main.cpp86
-rw-r--r--examples/statemachine/twowaybutton/twowaybutton.pro7
-rw-r--r--mkspecs/win32-icc/qmake.conf2
-rw-r--r--src/3rdparty/easing/easing.cpp670
-rw-r--r--src/3rdparty/easing/legal.qdoc35
-rw-r--r--src/3rdparty/webkit/VERSION2
-rw-r--r--src/3rdparty/webkit/WebCore/ChangeLog39
-rw-r--r--src/3rdparty/webkit/WebCore/platform/network/qt/QNetworkReplyHandler.cpp1
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/qt/PluginPackageQt.cpp4
-rw-r--r--src/3rdparty/webkit/WebCore/plugins/qt/PluginViewQt.cpp8
-rw-r--r--src/3rdparty/webkit/WebKit/qt/ChangeLog14
-rw-r--r--src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp8
-rw-r--r--src/corelib/animation/animation.pri25
-rw-r--r--src/corelib/animation/qabstractanimation.cpp733
-rw-r--r--src/corelib/animation/qabstractanimation.h137
-rw-r--r--src/corelib/animation/qabstractanimation_p.h150
-rw-r--r--src/corelib/animation/qanimationgroup.cpp309
-rw-r--r--src/corelib/animation/qanimationgroup.h88
-rw-r--r--src/corelib/animation/qanimationgroup_p.h79
-rw-r--r--src/corelib/animation/qparallelanimationgroup.cpp316
-rw-r--r--src/corelib/animation/qparallelanimationgroup.h86
-rw-r--r--src/corelib/animation/qparallelanimationgroup_p.h85
-rw-r--r--src/corelib/animation/qpauseanimation.cpp154
-rw-r--r--src/corelib/animation/qpauseanimation.h84
-rw-r--r--src/corelib/animation/qpropertyanimation.cpp316
-rw-r--r--src/corelib/animation/qpropertyanimation.h90
-rw-r--r--src/corelib/animation/qpropertyanimation_p.h89
-rw-r--r--src/corelib/animation/qsequentialanimationgroup.cpp594
-rw-r--r--src/corelib/animation/qsequentialanimationgroup.h96
-rw-r--r--src/corelib/animation/qsequentialanimationgroup_p.h111
-rw-r--r--src/corelib/animation/qvariantanimation.cpp653
-rw-r--r--src/corelib/animation/qvariantanimation.h130
-rw-r--r--src/corelib/animation/qvariantanimation_p.h130
-rw-r--r--src/corelib/concurrent/qfuturewatcher_p.h4
-rw-r--r--src/corelib/corelib.pro2
-rw-r--r--src/corelib/global/qfeatures.txt8
-rw-r--r--src/corelib/global/qglobal.cpp4
-rw-r--r--src/corelib/io/qdebug.h28
-rw-r--r--src/corelib/io/qdir.cpp10
-rw-r--r--src/corelib/io/qfile.cpp29
-rw-r--r--src/corelib/io/qfsfileengine.cpp122
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp9
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp95
-rw-r--r--src/corelib/io/qiodevice.cpp2
-rw-r--r--src/corelib/io/qnoncontiguousbytedevice.cpp4
-rw-r--r--src/corelib/io/qprocess.cpp2
-rw-r--r--src/corelib/io/qprocess_unix.cpp48
-rw-r--r--src/corelib/io/qprocess_win.cpp20
-rw-r--r--src/corelib/io/qresource.cpp8
-rw-r--r--src/corelib/io/qsettings_win.cpp2
-rw-r--r--src/corelib/io/qtemporaryfile.cpp98
-rw-r--r--src/corelib/io/qtextstream.cpp2
-rw-r--r--src/corelib/io/qurl.cpp6
-rw-r--r--src/corelib/io/qurl.h2
-rw-r--r--src/corelib/kernel/kernel.pri8
-rw-r--r--src/corelib/kernel/qabstractitemmodel.cpp12
-rw-r--r--src/corelib/kernel/qabstractitemmodel_p.h2
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp4
-rw-r--r--src/corelib/kernel/qcoreapplication_win.cpp35
-rw-r--r--src/corelib/kernel/qcoreevent.cpp2
-rw-r--r--src/corelib/kernel/qcoreevent.h22
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix_p.h4
-rw-r--r--src/corelib/kernel/qeventdispatcher_win.cpp7
-rw-r--r--src/corelib/kernel/qobject.cpp9
-rw-r--r--src/corelib/kernel/qsharedmemory_unix.cpp5
-rw-r--r--src/corelib/kernel/qsystemsemaphore_p.h4
-rw-r--r--src/corelib/kernel/qtranslator.cpp4
-rw-r--r--src/corelib/statemachine/qabstractstate.cpp202
-rw-r--r--src/corelib/statemachine/qabstractstate.h90
-rw-r--r--src/corelib/statemachine/qabstractstate_p.h83
-rw-r--r--src/corelib/statemachine/qabstracttransition.cpp342
-rw-r--r--src/corelib/statemachine/qabstracttransition.h111
-rw-r--r--src/corelib/statemachine/qabstracttransition_p.h91
-rw-r--r--src/corelib/statemachine/qeventtransition.cpp285
-rw-r--r--src/corelib/statemachine/qeventtransition.h96
-rw-r--r--src/corelib/statemachine/qeventtransition_p.h79
-rw-r--r--src/corelib/statemachine/qfinalstate.cpp134
-rw-r--r--src/corelib/statemachine/qfinalstate.h76
-rw-r--r--src/corelib/statemachine/qhistorystate.cpp223
-rw-r--r--src/corelib/statemachine/qhistorystate.h91
-rw-r--r--src/corelib/statemachine/qhistorystate_p.h79
-rw-r--r--src/corelib/statemachine/qsignalevent.h77
-rw-r--r--src/corelib/statemachine/qsignaleventgenerator_p.h78
-rw-r--r--src/corelib/statemachine/qsignaltransition.cpp260
-rw-r--r--src/corelib/statemachine/qsignaltransition.h89
-rw-r--r--src/corelib/statemachine/qsignaltransition_p.h79
-rw-r--r--src/corelib/statemachine/qstate.cpp483
-rw-r--r--src/corelib/statemachine/qstate.h113
-rw-r--r--src/corelib/statemachine/qstate_p.h108
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp2221
-rw-r--r--src/corelib/statemachine/qstatemachine.h166
-rw-r--r--src/corelib/statemachine/qstatemachine_p.h216
-rw-r--r--src/corelib/statemachine/qwrappedevent.h76
-rw-r--r--src/corelib/statemachine/statemachine.pri30
-rw-r--r--src/corelib/thread/qmutexpool.cpp20
-rw-r--r--src/corelib/thread/qmutexpool_p.h7
-rw-r--r--src/corelib/tools/qbytearray.cpp2
-rw-r--r--src/corelib/tools/qcontiguouscache.cpp4
-rw-r--r--src/corelib/tools/qcontiguouscache.h8
-rw-r--r--src/corelib/tools/qdatetime.cpp6
-rw-r--r--src/corelib/tools/qeasingcurve.cpp846
-rw-r--r--src/corelib/tools/qeasingcurve.h114
-rw-r--r--src/corelib/tools/qline.cpp4
-rw-r--r--src/corelib/tools/qlocale.cpp8
-rw-r--r--src/corelib/tools/qpoint.cpp2
-rw-r--r--src/corelib/tools/qstring.cpp78
-rw-r--r--src/corelib/tools/qtimeline.cpp114
-rw-r--r--src/corelib/tools/qtimeline.h5
-rw-r--r--src/corelib/tools/tools.pri2
-rw-r--r--src/gui/animation/animation.pri3
-rw-r--r--src/gui/animation/qguivariantanimation.cpp75
-rw-r--r--src/gui/dialogs/qfiledialog.cpp10
-rw-r--r--src/gui/dialogs/qfiledialog_win.cpp18
-rw-r--r--src/gui/dialogs/qfilesystemmodel.cpp2
-rw-r--r--src/gui/dialogs/qmessagebox.cpp2
-rw-r--r--src/gui/dialogs/qmessagebox.h2
-rw-r--r--src/gui/dialogs/qprintpreviewdialog.cpp2
-rw-r--r--src/gui/embedded/qscreen_qws.cpp5
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp442
-rw-r--r--src/gui/graphicsview/qgraphicsitem.h41
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h89
-rw-r--r--src/gui/graphicsview/qgraphicsproxywidget.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicsproxywidget.h2
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp5
-rw-r--r--src/gui/graphicsview/qgraphicsview.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicswidget.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicswidget.h9
-rw-r--r--src/gui/graphicsview/qgridlayoutengine.cpp6
-rw-r--r--src/gui/gui.pro2
-rw-r--r--src/gui/image/qpixmapcache.cpp34
-rw-r--r--src/gui/image/qpixmapcache_p.h2
-rw-r--r--src/gui/image/qxpmhandler.cpp6
-rw-r--r--src/gui/itemviews/qfileiconprovider.cpp3
-rw-r--r--src/gui/itemviews/qitemdelegate.cpp3
-rw-r--r--src/gui/itemviews/qitemselectionmodel.cpp2
-rw-r--r--src/gui/itemviews/qstyleditemdelegate.cpp3
-rw-r--r--src/gui/itemviews/qtableview.cpp2
-rw-r--r--src/gui/kernel/qapplication.cpp6
-rw-r--r--src/gui/kernel/qapplication_win.cpp42
-rw-r--r--src/gui/kernel/qevent.cpp6
-rw-r--r--src/gui/kernel/qlayoutengine.cpp2
-rw-r--r--src/gui/kernel/qmime_win.cpp2
-rw-r--r--src/gui/kernel/qshortcutmap.cpp4
-rw-r--r--src/gui/kernel/qwidget.cpp4
-rw-r--r--src/gui/kernel/qwindowdefs_win.h2
-rw-r--r--src/gui/painting/qcolor.cpp6
-rw-r--r--src/gui/painting/qdrawhelper.cpp8
-rw-r--r--src/gui/painting/qdrawhelper_p.h3
-rw-r--r--src/gui/painting/qmatrix.cpp2
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp233
-rw-r--r--src/gui/painting/qpaintengine_raster_p.h1
-rw-r--r--src/gui/painting/qpaintengineex.cpp4
-rw-r--r--src/gui/painting/qpainterpath.cpp2
-rw-r--r--src/gui/painting/qpdf.cpp26
-rw-r--r--src/gui/painting/qpen.cpp2
-rw-r--r--src/gui/painting/qprintengine_pdf.cpp4
-rw-r--r--src/gui/painting/qprintengine_ps.cpp24
-rw-r--r--src/gui/painting/qregion.cpp6
-rw-r--r--src/gui/painting/qtessellator.cpp12
-rw-r--r--src/gui/painting/qtransform.cpp2
-rw-r--r--src/gui/painting/qtransform.h14
-rw-r--r--src/gui/statemachine/qbasickeyeventtransition.cpp203
-rw-r--r--src/gui/statemachine/qbasickeyeventtransition_p.h93
-rw-r--r--src/gui/statemachine/qbasicmouseeventtransition.cpp208
-rw-r--r--src/gui/statemachine/qbasicmouseeventtransition_p.h98
-rw-r--r--src/gui/statemachine/qguistatemachine.cpp559
-rw-r--r--src/gui/statemachine/qkeyeventtransition.cpp186
-rw-r--r--src/gui/statemachine/qkeyeventtransition.h87
-rw-r--r--src/gui/statemachine/qmouseeventtransition.cpp216
-rw-r--r--src/gui/statemachine/qmouseeventtransition.h92
-rw-r--r--src/gui/statemachine/statemachine.pri13
-rw-r--r--src/gui/styles/gtksymbols.cpp27
-rw-r--r--src/gui/styles/qcleanlooksstyle.cpp6
-rw-r--r--src/gui/styles/qcommonstyle.cpp6
-rw-r--r--src/gui/styles/qgtkstyle.cpp13
-rw-r--r--src/gui/styles/qplastiquestyle.cpp9
-rw-r--r--src/gui/styles/qstyle.cpp2
-rw-r--r--src/gui/styles/qstyleoption.cpp8
-rw-r--r--src/gui/styles/qstylesheetstyle.cpp2
-rw-r--r--src/gui/text/qcssparser.cpp4
-rw-r--r--src/gui/text/qfontdatabase.cpp4
-rw-r--r--src/gui/text/qfontengine.cpp2
-rw-r--r--src/gui/text/qfontengine_mac.mm4
-rw-r--r--src/gui/text/qfontsubset.cpp30
-rw-r--r--src/gui/text/qtextcontrol.cpp2
-rw-r--r--src/gui/text/qtextdocument.cpp2
-rw-r--r--src/gui/text/qtextengine.cpp42
-rw-r--r--src/gui/util/qcompleter.cpp2
-rw-r--r--src/gui/util/qsystemtrayicon_win.cpp2
-rw-r--r--src/gui/widgets/qabstractspinbox.cpp4
-rw-r--r--src/gui/widgets/qcalendarwidget.cpp14
-rw-r--r--src/gui/widgets/qlabel.cpp2
-rw-r--r--src/gui/widgets/qlineedit.cpp2
-rw-r--r--src/gui/widgets/qspinbox.cpp6
-rw-r--r--src/network/access/qhttp.cpp4
-rw-r--r--src/network/kernel/qhostinfo_win.cpp15
-rw-r--r--src/network/kernel/qnetworkproxy.cpp4
-rw-r--r--src/network/kernel/qurlinfo.cpp4
-rw-r--r--src/network/socket/qhttpsocketengine.cpp4
-rw-r--r--src/network/socket/qnativesocketengine_p.h37
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp61
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp35
-rw-r--r--src/opengl/gl2paintengineex/glgc_shader_source.h289
-rw-r--r--src/opengl/gl2paintengineex/qgl2pexvertexarray.cpp6
-rw-r--r--src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h5
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager.cpp465
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager_p.h385
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadersource_p.h383
-rw-r--r--src/opengl/gl2paintengineex/qglgradientcache.cpp27
-rw-r--r--src/opengl/gl2paintengineex/qglgradientcache_p.h4
-rw-r--r--src/opengl/gl2paintengineex/qglpexshadermanager.cpp450
-rw-r--r--src/opengl/gl2paintengineex/qglpexshadermanager_p.h156
-rw-r--r--src/opengl/gl2paintengineex/qglshader.cpp605
-rw-r--r--src/opengl/gl2paintengineex/qglshader_p.h260
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp644
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h23
-rw-r--r--src/opengl/opengl.pro40
-rw-r--r--src/opengl/qegl.cpp67
-rw-r--r--src/opengl/qgl.cpp315
-rw-r--r--src/opengl/qgl.h2
-rw-r--r--src/opengl/qgl_egl.cpp8
-rw-r--r--src/opengl/qgl_p.h71
-rw-r--r--src/opengl/qgl_x11egl.cpp156
-rw-r--r--src/opengl/qglextensions.cpp297
-rw-r--r--src/opengl/qglextensions_p.h454
-rw-r--r--src/opengl/qglframebufferobject.cpp555
-rw-r--r--src/opengl/qglframebufferobject.h49
-rw-r--r--src/opengl/qglpixelbuffer.cpp38
-rw-r--r--src/opengl/qglpixmapfilter.cpp174
-rw-r--r--src/opengl/qglpixmapfilter_p.h29
-rw-r--r--src/opengl/qglshaderprogram.cpp2992
-rw-r--r--src/opengl/qglshaderprogram.h297
-rw-r--r--src/opengl/qpaintengine_opengl.cpp217
-rw-r--r--src/opengl/qpixmapdata_gl.cpp274
-rw-r--r--src/opengl/qpixmapdata_gl_p.h25
-rw-r--r--src/opengl/qwindowsurface_gl.cpp269
-rw-r--r--src/opengl/qwindowsurface_gl_p.h1
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp2
-rw-r--r--src/scripttools/debugging/qscriptenginedebugger.cpp13
-rw-r--r--src/sql/drivers/mysql/qsql_mysql.cpp3
-rw-r--r--src/sql/drivers/oci/qsql_oci.cpp12
-rw-r--r--src/xml/dom/qdom.cpp5
-rw-r--r--tests/auto/_networkselftest/_networkselftest.pro6
-rw-r--r--tests/auto/_networkselftest/tst_networkselftest.cpp592
-rw-r--r--tests/auto/auto.pro10
-rw-r--r--tests/auto/qanimationgroup/qanimationgroup.pro5
-rw-r--r--tests/auto/qanimationgroup/tst_qanimationgroup.cpp413
-rw-r--r--tests/auto/qeasingcurve/qeasingcurve.pro3
-rw-r--r--tests/auto/qeasingcurve/tst_qeasingcurve.cpp665
-rw-r--r--tests/auto/qfile/copy-fallback.qrc5
-rw-r--r--tests/auto/qfile/test/test.pro2
-rw-r--r--tests/auto/qfile/tst_qfile.cpp37
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp126
-rw-r--r--tests/auto/qitemdelegate/tst_qitemdelegate.cpp78
-rw-r--r--tests/auto/qmake/testdata/bundle-spaces/some-file6
-rw-r--r--tests/auto/qparallelanimationgroup/qparallelanimationgroup.pro5
-rw-r--r--tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp834
-rw-r--r--tests/auto/qpropertyanimation/qpropertyanimation.pro5
-rw-r--r--tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp919
-rw-r--r--tests/auto/qsequentialanimationgroup/qsequentialanimationgroup.pro5
-rw-r--r--tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp1649
-rw-r--r--tests/auto/qstate/qstate.pro5
-rw-r--r--tests/auto/qstate/tst_qstate.cpp340
-rw-r--r--tests/auto/qstatemachine/qstatemachine.pro4
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp3730
-rw-r--r--tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp38
-rw-r--r--tests/benchmarks/benchmarks.pro1
-rw-r--r--tests/benchmarks/qanimation/dummyanimation.cpp20
-rw-r--r--tests/benchmarks/qanimation/dummyanimation.h19
-rw-r--r--tests/benchmarks/qanimation/dummyobject.cpp25
-rw-r--r--tests/benchmarks/qanimation/dummyobject.h23
-rw-r--r--tests/benchmarks/qanimation/main.cpp150
-rw-r--r--tests/benchmarks/qanimation/qanimation.pro18
-rw-r--r--tests/benchmarks/qanimation/rectanimation.cpp58
-rw-r--r--tests/benchmarks/qanimation/rectanimation.h30
-rw-r--r--tests/benchmarks/qgraphicsitem/qgraphicsitem.pro6
-rw-r--r--tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp170
-rw-r--r--tests/benchmarks/qstring/main.cpp123
-rw-r--r--tests/benchmarks/qstring/qstring.pro4
-rw-r--r--tests/benchmarks/qvariant/qvariant.pro1
-rw-r--r--tests/benchmarks/qvariant/tst_qvariant.cpp115
-rw-r--r--tools/designer/src/components/formeditor/qdesigner_resource.cpp121
-rw-r--r--tools/designer/src/lib/shared/newformwidget.cpp5
-rw-r--r--tools/designer/src/lib/shared/qdesigner_formbuilder.cpp14
-rw-r--r--tools/designer/src/lib/shared/qdesigner_formbuilder_p.h17
-rw-r--r--tools/designer/src/lib/shared/qdesigner_toolbar.cpp16
-rw-r--r--tools/designer/src/lib/shared/qsimpleresource.cpp133
-rw-r--r--tools/designer/src/lib/shared/qsimpleresource_p.h17
-rw-r--r--tools/linguist/lconvert/main.cpp24
-rw-r--r--tools/linguist/lupdate/java.cpp13
-rw-r--r--tools/linguist/shared/translator.cpp20
-rw-r--r--tools/linguist/shared/translator.h3
-rw-r--r--tools/qdoc3/htmlgenerator.cpp2
-rw-r--r--tools/qdoc3/test/classic.css4
572 files changed, 48973 insertions, 5573 deletions
diff --git a/configure b/configure
index 740f95a..b57e8cb 100755
--- a/configure
+++ b/configure
@@ -202,7 +202,7 @@ earlyArgParse()
VAL=$1
fi
;;
- h|help|--help|-help)
+ -h|help|--help|-help)
if [ "$VAL" = "yes" ]; then
OPT_HELP="$VAL"
COMMERCIAL_USER="no" #doesn't matter we will display the help
@@ -2718,7 +2718,7 @@ if [ "$PLATFORM_MAC" = "yes" ]; then
# Build commmand line arguments we can pass to the compiler during configure tests
# by prefixing each arch with "-arch".
CFG_MAC_ARCHS_GCC_FORMAT="${CFG_MAC_ARCHS/x86/i386}"
- CFG_MAC_ARCHS_GCC_FORMAT="${CFG_MAC_ARCHS/i386_64/x86_64}"
+ CFG_MAC_ARCHS_GCC_FORMAT="${CFG_MAC_ARCHS_GCC_FORMAT/i386_64/x86_64}"
for ARCH in $CFG_MAC_ARCHS_GCC_FORMAT; do
MAC_ARCHS_COMMANDLINE="$MAC_ARCHS_COMMANDLINE -arch $ARCH"
done
diff --git a/demos/boxes/boxes.pro b/demos/boxes/boxes.pro
index 6c1a331..33f1f14 100644
--- a/demos/boxes/boxes.pro
+++ b/demos/boxes/boxes.pro
@@ -11,17 +11,14 @@ INCLUDEPATH += .
HEADERS += 3rdparty/fbm.h \
glbuffers.h \
glextensions.h \
- glshaders.h \
gltrianglemesh.h \
qtbox.h \
roundedbox.h \
scene.h \
- trackball.h \
- vector.h
+ trackball.h
SOURCES += 3rdparty/fbm.c \
glbuffers.cpp \
glextensions.cpp \
- glshaders.cpp \
main.cpp \
qtbox.cpp \
roundedbox.cpp \
diff --git a/demos/boxes/glbuffers.cpp b/demos/boxes/glbuffers.cpp
index b2a594e..a25a425 100644
--- a/demos/boxes/glbuffers.cpp
+++ b/demos/boxes/glbuffers.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "glbuffers.h"
+#include <QtGui/qmatrix4x4.h>
//============================================================================//
// GLTexture //
@@ -346,7 +347,7 @@ void GLRenderTargetCube::end()
m_fbo.setAsRenderTarget(false);
}
-void GLRenderTargetCube::getViewMatrix(gfx::Matrix4x4f& mat, int face)
+void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
{
if (face < 0 || face >= 6) {
qWarning("GLRenderTargetCube::getViewMatrix: 'face' must be in the range [0, 6). (face == %d)", face);
@@ -371,20 +372,21 @@ void GLRenderTargetCube::getViewMatrix(gfx::Matrix4x4f& mat, int face)
{-1.0f, -1.0f, +1.0f},
};
- memset(mat.bits(), 0, sizeof(float) * 16);
+ memset(mat.data(), 0, sizeof(float) * 16);
for (int i = 0; i < 3; ++i)
- mat(perm[face][i], i) = signs[face][i];
+ mat(i, perm[face][i]) = signs[face][i];
mat(3, 3) = 1.0f;
}
-void GLRenderTargetCube::getProjectionMatrix(gfx::Matrix4x4f& mat, float nearZ, float farZ)
+void GLRenderTargetCube::getProjectionMatrix(QMatrix4x4& mat, float nearZ, float farZ)
{
- float proj[] = {
- 1.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, (nearZ+farZ)/(nearZ-farZ), -1.0f,
- 0.0f, 0.0f, 2.0f*nearZ*farZ/(nearZ-farZ), 0.0f,
- };
-
- memcpy(mat.bits(), proj, sizeof(float) * 16);
+ static const QMatrix4x4 reference(
+ 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, -1.0f, 0.0f);
+
+ mat = reference;
+ mat(2, 2) = (nearZ+farZ)/(nearZ-farZ);
+ mat(2, 3) = 2.0f*nearZ*farZ/(nearZ-farZ);
}
diff --git a/demos/boxes/glbuffers.h b/demos/boxes/glbuffers.h
index 88de4e8..392924e 100644
--- a/demos/boxes/glbuffers.h
+++ b/demos/boxes/glbuffers.h
@@ -48,8 +48,6 @@
#include <QtGui>
#include <QtOpenGL>
-#include "vector.h"
-
#define BUFFER_OFFSET(i) ((char*)0 + (i))
#define SIZE_OF_MEMBER(cls, member) sizeof(static_cast<cls *>(0)->member)
@@ -60,6 +58,8 @@ if (m_failed || !(assertion)) {
returnStatement; \
}
+class QMatrix4x4;
+
class GLTexture
{
public:
@@ -135,8 +135,8 @@ public:
void end();
virtual bool failed() {return m_failed || m_fbo.failed();}
- static void getViewMatrix(gfx::Matrix4x4f& mat, int face);
- static void getProjectionMatrix(gfx::Matrix4x4f& mat, float nearZ, float farZ);
+ static void getViewMatrix(QMatrix4x4& mat, int face);
+ static void getProjectionMatrix(QMatrix4x4& mat, float nearZ, float farZ);
private:
GLFrameBufferObject m_fbo;
};
diff --git a/demos/boxes/glextensions.cpp b/demos/boxes/glextensions.cpp
index 59256a8..5f168b6 100644
--- a/demos/boxes/glextensions.cpp
+++ b/demos/boxes/glextensions.cpp
@@ -47,23 +47,6 @@ bool GLExtensionFunctions::resolve(const QGLContext *context)
{
bool ok = true;
- RESOLVE_GL_FUNC(CreateShaderObjectARB)
- RESOLVE_GL_FUNC(ShaderSourceARB)
- RESOLVE_GL_FUNC(CompileShaderARB)
- RESOLVE_GL_FUNC(GetObjectParameterivARB)
- RESOLVE_GL_FUNC(DeleteObjectARB)
- RESOLVE_GL_FUNC(GetInfoLogARB)
- RESOLVE_GL_FUNC(CreateProgramObjectARB)
- RESOLVE_GL_FUNC(AttachObjectARB)
- RESOLVE_GL_FUNC(DetachObjectARB)
- RESOLVE_GL_FUNC(LinkProgramARB)
- RESOLVE_GL_FUNC(UseProgramObjectARB)
- RESOLVE_GL_FUNC(GetUniformLocationARB)
- RESOLVE_GL_FUNC(Uniform1iARB)
- RESOLVE_GL_FUNC(Uniform1fARB)
- RESOLVE_GL_FUNC(Uniform4fARB)
- RESOLVE_GL_FUNC(UniformMatrix4fvARB)
-
RESOLVE_GL_FUNC(GenFramebuffersEXT)
RESOLVE_GL_FUNC(GenRenderbuffersEXT)
RESOLVE_GL_FUNC(BindRenderbufferEXT)
@@ -88,26 +71,6 @@ bool GLExtensionFunctions::resolve(const QGLContext *context)
return ok;
}
-bool GLExtensionFunctions::glslSupported() {
- return CreateShaderObjectARB
- && CreateShaderObjectARB
- && ShaderSourceARB
- && CompileShaderARB
- && GetObjectParameterivARB
- && DeleteObjectARB
- && GetInfoLogARB
- && CreateProgramObjectARB
- && AttachObjectARB
- && DetachObjectARB
- && LinkProgramARB
- && UseProgramObjectARB
- && GetUniformLocationARB
- && Uniform1iARB
- && Uniform1fARB
- && Uniform4fARB
- && UniformMatrix4fvARB;
-}
-
bool GLExtensionFunctions::fboSupported() {
return GenFramebuffersEXT
&& GenRenderbuffersEXT
diff --git a/demos/boxes/glextensions.h b/demos/boxes/glextensions.h
index 7ba3b32..af36e29 100644
--- a/demos/boxes/glextensions.h
+++ b/demos/boxes/glextensions.h
@@ -47,23 +47,6 @@
/*
Functions resolved:
-glCreateShaderObjectARB
-glShaderSourceARB
-glCompileShaderARB
-glGetObjectParameterivARB
-glDeleteObjectARB
-glGetInfoLogARB
-glCreateProgramObjectARB
-glAttachObjectARB
-glDetachObjectARB
-glLinkProgramARB
-glUseProgramObjectARB
-glGetUniformLocationARB
-glUniform1iARB
-glUniform1fARB
-glUniform4fARB
-glUniformMatrix4fvARB
-
glGenFramebuffersEXT
glGenRenderbuffersEXT
glBindRenderbufferEXT
@@ -139,39 +122,6 @@ typedef ptrdiff_t GLsizeiptrARB;
#define GL_DEPTH_ATTACHMENT_EXT 0x8D00
#endif
-#ifndef GL_ARB_vertex_shader
-#define GL_VERTEX_SHADER_ARB 0x8B31
-#endif
-
-#ifndef GL_ARB_fragment_shader
-#define GL_FRAGMENT_SHADER_ARB 0x8B30
-#endif
-
-#ifndef GL_ARB_shader_objects
-typedef char GLcharARB;
-typedef unsigned int GLhandleARB;
-#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81
-#define GL_OBJECT_LINK_STATUS_ARB 0x8B82
-#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84
-#endif
-
-typedef GLhandleARB (APIENTRY *_glCreateShaderObjectARB) (GLenum);
-typedef void (APIENTRY *_glShaderSourceARB) (GLhandleARB, GLuint, const GLcharARB**, GLint *);
-typedef void (APIENTRY *_glCompileShaderARB) (GLhandleARB);
-typedef void (APIENTRY *_glGetObjectParameterivARB) (GLhandleARB, GLenum, int *);
-typedef void (APIENTRY *_glDeleteObjectARB) (GLhandleARB);
-typedef void (APIENTRY *_glGetInfoLogARB) (GLhandleARB, GLsizei, GLsizei *, GLcharARB *);
-typedef GLhandleARB (APIENTRY *_glCreateProgramObjectARB) ();
-typedef void (APIENTRY *_glAttachObjectARB) (GLhandleARB, GLhandleARB);
-typedef void (APIENTRY *_glDetachObjectARB) (GLhandleARB, GLhandleARB);
-typedef void (APIENTRY *_glLinkProgramARB) (GLhandleARB);
-typedef void (APIENTRY *_glUseProgramObjectARB) (GLhandleARB);
-typedef GLint (APIENTRY *_glGetUniformLocationARB) (GLhandleARB, const GLcharARB *);
-typedef void (APIENTRY *_glUniform1iARB) (GLint, GLint);
-typedef void (APIENTRY *_glUniform1fARB) (GLint, GLfloat);
-typedef void (APIENTRY *_glUniform4fARB) (GLint, GLfloat, GLfloat, GLfloat, GLfloat);
-typedef void (APIENTRY *_glUniformMatrix4fvARB) (GLint, GLuint, GLboolean, const GLfloat *);
-
typedef void (APIENTRY *_glGenFramebuffersEXT) (GLsizei, GLuint *);
typedef void (APIENTRY *_glGenRenderbuffersEXT) (GLsizei, GLuint *);
typedef void (APIENTRY *_glBindRenderbufferEXT) (GLenum, GLuint);
@@ -197,27 +147,9 @@ struct GLExtensionFunctions
{
bool resolve(const QGLContext *context);
- bool glslSupported();
bool fboSupported();
bool openGL15Supported(); // the rest: multi-texture, 3D-texture, vertex buffer objects
- _glCreateShaderObjectARB CreateShaderObjectARB;
- _glShaderSourceARB ShaderSourceARB;
- _glCompileShaderARB CompileShaderARB;
- _glGetObjectParameterivARB GetObjectParameterivARB;
- _glDeleteObjectARB DeleteObjectARB;
- _glGetInfoLogARB GetInfoLogARB;
- _glCreateProgramObjectARB CreateProgramObjectARB;
- _glAttachObjectARB AttachObjectARB;
- _glDetachObjectARB DetachObjectARB;
- _glLinkProgramARB LinkProgramARB;
- _glUseProgramObjectARB UseProgramObjectARB;
- _glGetUniformLocationARB GetUniformLocationARB;
- _glUniform1iARB Uniform1iARB;
- _glUniform1fARB Uniform1fARB;
- _glUniform4fARB Uniform4fARB;
- _glUniformMatrix4fvARB UniformMatrix4fvARB;
-
_glGenFramebuffersEXT GenFramebuffersEXT;
_glGenRenderbuffersEXT GenRenderbuffersEXT;
_glBindRenderbufferEXT BindRenderbufferEXT;
@@ -246,23 +178,6 @@ inline GLExtensionFunctions &getGLExtensionFunctions()
return funcs;
}
-#define glCreateShaderObjectARB getGLExtensionFunctions().CreateShaderObjectARB
-#define glShaderSourceARB getGLExtensionFunctions().ShaderSourceARB
-#define glCompileShaderARB getGLExtensionFunctions().CompileShaderARB
-#define glGetObjectParameterivARB getGLExtensionFunctions().GetObjectParameterivARB
-#define glDeleteObjectARB getGLExtensionFunctions().DeleteObjectARB
-#define glGetInfoLogARB getGLExtensionFunctions().GetInfoLogARB
-#define glCreateProgramObjectARB getGLExtensionFunctions().CreateProgramObjectARB
-#define glAttachObjectARB getGLExtensionFunctions().AttachObjectARB
-#define glDetachObjectARB getGLExtensionFunctions().DetachObjectARB
-#define glLinkProgramARB getGLExtensionFunctions().LinkProgramARB
-#define glUseProgramObjectARB getGLExtensionFunctions().UseProgramObjectARB
-#define glGetUniformLocationARB getGLExtensionFunctions().GetUniformLocationARB
-#define glUniform1iARB getGLExtensionFunctions().Uniform1iARB
-#define glUniform1fARB getGLExtensionFunctions().Uniform1fARB
-#define glUniform4fARB getGLExtensionFunctions().Uniform4fARB
-#define glUniformMatrix4fvARB getGLExtensionFunctions().UniformMatrix4fvARB
-
#define glGenFramebuffersEXT getGLExtensionFunctions().GenFramebuffersEXT
#define glGenRenderbuffersEXT getGLExtensionFunctions().GenRenderbuffersEXT
#define glBindRenderbufferEXT getGLExtensionFunctions().BindRenderbufferEXT
diff --git a/demos/boxes/glshaders.cpp b/demos/boxes/glshaders.cpp
deleted file mode 100644
index b6999a8..0000000
--- a/demos/boxes/glshaders.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the demonstration applications of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "glshaders.h"
-
-#define GLSHADERS_ASSERT_OPENGL(prefix, assertion, returnStatement) \
-if (m_failed || !(assertion)) { \
- if (!m_failed) qCritical(prefix ": The necessary OpenGL functions are not available."); \
- m_failed = true; \
- returnStatement; \
-}
-
-
-GLShader::GLShader(const char *data, int size, GLenum shaderType)
-: m_compileError(false), m_failed(false)
-{
- GLSHADERS_ASSERT_OPENGL("GLShader::GLShader",
- glCreateShaderObjectARB && glShaderSourceARB && glCompileShaderARB && glGetObjectParameterivARB, return)
-
- m_shader = glCreateShaderObjectARB(shaderType);
-
- GLint glSize = size;
- glShaderSourceARB(m_shader, 1, &data, &glSize);
- glCompileShaderARB(m_shader);
- int status;
- glGetObjectParameterivARB(m_shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
- m_compileError = (status != 1);
-}
-
-GLShader::GLShader(const QString& fileName, GLenum shaderType)
- : m_compileError(false), m_failed(false)
-{
- GLSHADERS_ASSERT_OPENGL("GLShader::GLShader",
- glCreateShaderObjectARB && glShaderSourceARB && glCompileShaderARB && glGetObjectParameterivARB, return)
-
- m_shader = glCreateShaderObjectARB(shaderType);
-
- QFile file(fileName);
- if (file.open(QIODevice::ReadOnly)) {
- QByteArray bytes = file.readAll();
- GLint size = file.size();
- const char *p = bytes.data();
- file.close();
- glShaderSourceARB(m_shader, 1, &p, &size);
- glCompileShaderARB(m_shader);
- int status;
- glGetObjectParameterivARB(m_shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
- m_compileError = (status != 1);
- } else {
- m_compileError = true;
- }
-}
-
-GLShader::~GLShader()
-{
- GLSHADERS_ASSERT_OPENGL("GLShader::~GLShader", glDeleteObjectARB, return)
-
- glDeleteObjectARB(m_shader);
-}
-
-QString GLShader::log()
-{
- GLSHADERS_ASSERT_OPENGL("GLShader::log", glGetObjectParameterivARB
- && glGetInfoLogARB, return QLatin1String("GLSL not supported."))
-
- int length;
- glGetObjectParameterivARB(m_shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
- char *log = new char[length + 1];
- GLsizei glLength = length;
- glGetInfoLogARB(m_shader, glLength, &glLength, log);
- log[glLength] = '\0';
- QString result(log);
- delete log;
- return result;
-}
-
-GLVertexShader::GLVertexShader(const char *data, int size) : GLShader(data, size, GL_VERTEX_SHADER_ARB)
-{
-}
-
-GLVertexShader::GLVertexShader(const QString& fileName) : GLShader(fileName, GL_VERTEX_SHADER_ARB)
-{
-}
-
-GLFragmentShader::GLFragmentShader(const char *data, int size) : GLShader(data, size, GL_FRAGMENT_SHADER_ARB)
-{
-}
-
-GLFragmentShader::GLFragmentShader(const QString& fileName) : GLShader(fileName, GL_FRAGMENT_SHADER_ARB)
-{
-}
-
-GLProgram::GLProgram() : m_linked(false), m_linkError(false), m_failed(false)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::GLProgram", glCreateProgramObjectARB, return)
-
- m_program = glCreateProgramObjectARB();
-}
-
-GLProgram::~GLProgram()
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::~GLProgram", glDeleteObjectARB, return)
-
- glDeleteObjectARB(m_program);
-}
-
-void GLProgram::attach(const GLShader &shader)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::attach", glAttachObjectARB, return)
-
- glAttachObjectARB(m_program, shader.m_shader);
- m_linked = m_linkError = false;
-}
-
-void GLProgram::detach(const GLShader &shader)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::detach", glDetachObjectARB, return)
-
- glDetachObjectARB(m_program, shader.m_shader);
- m_linked = m_linkError = false;
-}
-
-bool GLProgram::failed()
-{
- if (m_failed || m_linkError)
- return true;
-
- if (m_linked)
- return false;
-
- GLSHADERS_ASSERT_OPENGL("GLProgram::failed", glLinkProgramARB && glGetObjectParameterivARB, return true)
-
- glLinkProgramARB(m_program);
- int status;
- glGetObjectParameterivARB(m_program, GL_OBJECT_LINK_STATUS_ARB, &status);
- m_linkError = !(m_linked = (status == 1));
- return m_linkError;
-}
-
-QString GLProgram::log()
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::log", glGetObjectParameterivARB && glGetInfoLogARB,
- return QLatin1String("Failed."))
-
- int length;
- glGetObjectParameterivARB(m_program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
- char *log = new char[length + 1];
- GLsizei glLength = length;
- glGetInfoLogARB(m_program, glLength, &glLength, log);
- log[glLength] = '\0';
- QString result(log);
- delete log;
- return result;
-}
-
-void GLProgram::bind()
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::bind", glUseProgramObjectARB, return)
-
- if (!failed())
- glUseProgramObjectARB(m_program);
-}
-
-void GLProgram::unbind()
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::bind", glUseProgramObjectARB, return)
-
- glUseProgramObjectARB(0);
-}
-
-bool GLProgram::hasParameter(const QString& name)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::hasParameter", glGetUniformLocationARB, return false)
-
- if (!failed()) {
- QByteArray asciiName = name.toAscii();
- return -1 != glGetUniformLocationARB(m_program, asciiName.data());
- }
- return false;
-}
-
-void GLProgram::setInt(const QString& name, int value)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::setInt", glGetUniformLocationARB && glUniform1iARB, return)
-
- if (!failed()) {
- QByteArray asciiName = name.toAscii();
- int loc = glGetUniformLocationARB(m_program, asciiName.data());
- glUniform1iARB(loc, value);
- }
-}
-
-void GLProgram::setFloat(const QString& name, float value)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::setFloat", glGetUniformLocationARB && glUniform1fARB, return)
-
- if (!failed()) {
- QByteArray asciiName = name.toAscii();
- int loc = glGetUniformLocationARB(m_program, asciiName.data());
- glUniform1fARB(loc, value);
- }
-}
-
-void GLProgram::setColor(const QString& name, QRgb value)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::setColor", glGetUniformLocationARB && glUniform4fARB, return)
-
- //qDebug() << "Setting color" << name;
- if (!failed()) {
- QByteArray asciiName = name.toAscii();
- int loc = glGetUniformLocationARB(m_program, asciiName.data());
- //qDebug() << "Location of" << name << "is" << loc;
- QColor color(value);
- glUniform4fARB(loc, color.redF(), color.greenF(), color.blueF(), color.alphaF());
- }
-}
-
-void GLProgram::setMatrix(const QString& name, const gfx::Matrix4x4f &mat)
-{
- GLSHADERS_ASSERT_OPENGL("GLProgram::setMatrix", glGetUniformLocationARB && glUniformMatrix4fvARB, return)
-
- if (!failed()) {
- QByteArray asciiName = name.toAscii();
- int loc = glGetUniformLocationARB(m_program, asciiName.data());
- //qDebug() << "Location of" << name << "is" << loc;
- glUniformMatrix4fvARB(loc, 1, GL_FALSE, mat.bits());
- }
-} \ No newline at end of file
diff --git a/demos/boxes/qtbox.cpp b/demos/boxes/qtbox.cpp
index 0607698..ba9f95d 100644
--- a/demos/boxes/qtbox.cpp
+++ b/demos/boxes/qtbox.cpp
@@ -269,19 +269,20 @@ bool ItemBase::isInResizeArea(const QPointF &pos)
QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0)
{
for (int i = 0; i < 8; ++i) {
- m_vertices[i][0] = (i & 1 ? 0.5f : -0.5f);
- m_vertices[i][1] = (i & 2 ? 0.5f : -0.5f);
- m_vertices[i][2] = (i & 4 ? 0.5f : -0.5f);
+ m_vertices[i].setX(i & 1 ? 0.5f : -0.5f);
+ m_vertices[i].setY(i & 2 ? 0.5f : -0.5f);
+ m_vertices[i].setZ(i & 4 ? 0.5f : -0.5f);
}
for (int i = 0; i < 4; ++i) {
- m_texCoords[i][0] = (i & 1 ? 1.0f : 0.0f);
- m_texCoords[i][1] = (i & 2 ? 1.0f : 0.0f);
- }
- memset(m_normals, 0, sizeof(m_normals));
- for (int i = 0; i < 3; ++i) {
- m_normals[2 * i + 0][i] = -1.0f;
- m_normals[2 * i + 1][i] = 1.0f;
+ m_texCoords[i].setX(i & 1 ? 1.0f : 0.0f);
+ m_texCoords[i].setY(i & 2 ? 1.0f : 0.0f);
}
+ m_normals[0] = QVector3D(-1.0f, 0.0f, 0.0f);
+ m_normals[1] = QVector3D(1.0f, 0.0f, 0.0f);
+ m_normals[2] = QVector3D(0.0f, -1.0f, 0.0f);
+ m_normals[3] = QVector3D(0.0f, 1.0f, 0.0f);
+ m_normals[4] = QVector3D(0.0f, 0.0f, -1.0f);
+ m_normals[5] = QVector3D(0.0f, 0.0f, 1.0f);
}
QtBox::~QtBox()
@@ -351,21 +352,21 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
glColor4f(1.0f, 1.0f, 1.0f, 1.0);
glBegin(GL_TRIANGLE_STRIP);
- glNormal3fv(m_normals[2 * dir + 0].bits());
+ glNormal3fv(reinterpret_cast<float *>(&m_normals[2 * dir + 0]));
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
- glTexCoord2fv(m_texCoords[(j << 1) | i].bits());
- glVertex3fv(m_vertices[(i << ((dir + 2) % 3)) | (j << ((dir + 1) % 3))].bits());
+ glTexCoord2fv(reinterpret_cast<float *>(&m_texCoords[(j << 1) | i]));
+ glVertex3fv(reinterpret_cast<float *>(&m_vertices[(i << ((dir + 2) % 3)) | (j << ((dir + 1) % 3))]));
}
}
glEnd();
glBegin(GL_TRIANGLE_STRIP);
- glNormal3fv(m_normals[2 * dir + 1].bits());
+ glNormal3fv(reinterpret_cast<float *>(&m_normals[2 * dir + 1]));
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
- glTexCoord2fv(m_texCoords[(j << 1) | i].bits());
- glVertex3fv(m_vertices[(1 << dir) | (i << ((dir + 1) % 3)) | (j << ((dir + 2) % 3))].bits());
+ glTexCoord2fv(reinterpret_cast<float *>(&m_texCoords[(j << 1) | i]));
+ glVertex3fv(reinterpret_cast<float *>(&m_vertices[(1 << dir) | (i << ((dir + 1) % 3)) | (j << ((dir + 2) % 3))]));
}
}
glEnd();
diff --git a/demos/boxes/qtbox.h b/demos/boxes/qtbox.h
index aae8256..5042077 100644
--- a/demos/boxes/qtbox.h
+++ b/demos/boxes/qtbox.h
@@ -44,7 +44,7 @@
#include <QtGui>
-#include "vector.h"
+#include <QtGui/qvector3d.h>
#include "glbuffers.h"
class ItemBase : public QObject, public QGraphicsItem
@@ -85,9 +85,9 @@ public:
protected:
virtual ItemBase *createNew(int size, int x, int y);
private:
- gfx::Vector3f m_vertices[8];
- gfx::Vector2f m_texCoords[4];
- gfx::Vector3f m_normals[6];
+ QVector3D m_vertices[8];
+ QVector3D m_texCoords[4];
+ QVector3D m_normals[6];
GLTexture *m_texture;
};
diff --git a/demos/boxes/roundedbox.cpp b/demos/boxes/roundedbox.cpp
index f238da2..93ebce7 100644
--- a/demos/boxes/roundedbox.cpp
+++ b/demos/boxes/roundedbox.cpp
@@ -46,9 +46,10 @@
//============================================================================//
VertexDescription P3T2N3Vertex::description[] = {
- {VertexDescription::Position, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, position) / sizeof(float), offsetof(P3T2N3Vertex, position), 0},
- {VertexDescription::TexCoord, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, texCoord) / sizeof(float), offsetof(P3T2N3Vertex, texCoord), 0},
- {VertexDescription::Normal, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, normal) / sizeof(float), offsetof(P3T2N3Vertex, normal), 0},
+ {VertexDescription::Position, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, position) / sizeof(float), 0, 0},
+ {VertexDescription::TexCoord, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, texCoord) / sizeof(float), sizeof(QVector3D), 0},
+ {VertexDescription::Normal, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, normal) / sizeof(float), sizeof(QVector3D) + sizeof(QVector2D), 0},
+
{VertexDescription::Null, 0, 0, 0, 0},
};
@@ -78,10 +79,9 @@ GLRoundedBox::GLRoundedBox(float r, float scale, int n)
}
for (int corner = 0; corner < 8; ++corner) {
- gfx::Vector3f centre;
- centre[0] = (corner & 1 ? 1.0f : -1.0f);
- centre[1] = (corner & 2 ? 1.0f : -1.0f);
- centre[2] = (corner & 4 ? 1.0f : -1.0f);
+ QVector3D centre(corner & 1 ? 1.0f : -1.0f,
+ corner & 2 ? 1.0f : -1.0f,
+ corner & 4 ? 1.0f : -1.0f);
int winding = (corner & 1) ^ ((corner >> 1) & 1) ^ (corner >> 2);
int offsX = ((corner ^ 1) - corner) * vertexCountPerCorner;
int offsY = ((corner ^ 2) - corner) * vertexCountPerCorner;
@@ -129,12 +129,13 @@ GLRoundedBox::GLRoundedBox(float r, float scale, int n)
}
for (int j = 0; j <= i; ++j) {
- gfx::Vector3f normal = gfx::Vector3f::vector(i - j, j, n + 1 - i).normalized();
- gfx::Vector3f pos = centre * (0.5f - r + r * normal);
+ QVector3D normal = QVector3D(i - j, j, n + 1 - i).normalized();
+ QVector3D offset(0.5f - r, 0.5f - r, 0.5f - r);
+ QVector3D pos = centre * (offset + r * normal);
vp[vidx].position = scale * pos;
vp[vidx].normal = centre * normal;
- vp[vidx].texCoord = gfx::Vector2f::vector(pos[0], pos[1]) + 0.5f;
+ vp[vidx].texCoord = QVector2D(pos.x() + 0.5f, pos.y() + 0.5f);
// Corner polygons
if (i < n + 1) {
diff --git a/demos/boxes/roundedbox.h b/demos/boxes/roundedbox.h
index b934ade..65b545e 100644
--- a/demos/boxes/roundedbox.h
+++ b/demos/boxes/roundedbox.h
@@ -49,14 +49,15 @@
#include <QtOpenGL>
#include "gltrianglemesh.h"
-#include "vector.h"
+#include <QtGui/qvector3d.h>
+#include <QtGui/qvector2d.h>
#include "glbuffers.h"
struct P3T2N3Vertex
{
- gfx::Vector3f position;
- gfx::Vector2f texCoord;
- gfx::Vector3f normal;
+ QVector3D position;
+ QVector2D texCoord;
+ QVector3D normal;
static VertexDescription description[];
};
diff --git a/demos/boxes/scene.cpp b/demos/boxes/scene.cpp
index 1040e17..e2aa16b 100644
--- a/demos/boxes/scene.cpp
+++ b/demos/boxes/scene.cpp
@@ -39,7 +39,10 @@
**
****************************************************************************/
+#include <QDebug>
#include "scene.h"
+#include <QtGui/qmatrix4x4.h>
+#include <QtGui/qvector3d.h>
#include "3rdparty/fbm.h"
@@ -484,9 +487,9 @@ Scene::Scene(int width, int height, int maxTextureSize)
{
setSceneRect(0, 0, width, height);
- m_trackBalls[0] = TrackBall(0.0005f, gfx::Vector3f::vector(0, 1, 0), TrackBall::Sphere);
- m_trackBalls[1] = TrackBall(0.0001f, gfx::Vector3f::vector(0, 0, 1), TrackBall::Sphere);
- m_trackBalls[2] = TrackBall(0.0f, gfx::Vector3f::vector(0, 1, 0), TrackBall::Plane);
+ m_trackBalls[0] = TrackBall(0.05f, QVector3D(0, 1, 0), TrackBall::Sphere);
+ m_trackBalls[1] = TrackBall(0.005f, QVector3D(0, 0, 1), TrackBall::Sphere);
+ m_trackBalls[2] = TrackBall(0.0f, QVector3D(0, 1, 0), TrackBall::Plane);
m_renderOptions = new RenderOptionsDialog;
m_renderOptions->move(20, 120);
@@ -531,11 +534,11 @@ Scene::~Scene()
if (texture) delete texture;
if (m_mainCubemap)
delete m_mainCubemap;
- foreach (GLProgram *program, m_programs)
+ foreach (QGLShaderProgram *program, m_programs)
if (program) delete program;
if (m_vertexShader)
delete m_vertexShader;
- foreach (GLFragmentShader *shader, m_fragmentShaders)
+ foreach (QGLShader *shader, m_fragmentShaders)
if (shader) delete shader;
foreach (GLRenderTargetCube *rt, m_cubemaps)
if (rt) delete rt;
@@ -549,16 +552,18 @@ void Scene::initGL()
{
m_box = new GLRoundedBox(0.25f, 1.0f, 10);
- m_vertexShader = new GLVertexShader(":/res/boxes/basic.vsh");
+ m_vertexShader = new QGLShader(":/res/boxes/basic.vsh", QGLShader::VertexShader);
QStringList list;
list << ":/res/boxes/cubemap_posx.jpg" << ":/res/boxes/cubemap_negx.jpg" << ":/res/boxes/cubemap_posy.jpg"
<< ":/res/boxes/cubemap_negy.jpg" << ":/res/boxes/cubemap_posz.jpg" << ":/res/boxes/cubemap_negz.jpg";
m_environment = new GLTextureCube(list, qMin(1024, m_maxTextureSize));
- m_environmentShader = new GLFragmentShader(environmentShaderText, strlen(environmentShaderText));
- m_environmentProgram = new GLProgram;
- m_environmentProgram->attach(*m_vertexShader);
- m_environmentProgram->attach(*m_environmentShader);
+ m_environmentShader = new QGLShader(QGLShader::FragmentShader);
+ m_environmentShader->setSourceCode(environmentShaderText);
+ m_environmentProgram = new QGLShaderProgram;
+ m_environmentProgram->addShader(m_vertexShader);
+ m_environmentProgram->addShader(m_environmentShader);
+ m_environmentProgram->link();
const int NOISE_SIZE = 128; // for a different size, B and BM in fbm.c must also be changed
m_noise = new GLTexture3D(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE);
@@ -610,12 +615,12 @@ void Scene::initGL()
filter = QStringList("*.fsh");
files = QDir(":/res/boxes/").entryInfoList(filter, QDir::Files | QDir::Readable);
foreach (QFileInfo file, files) {
- GLProgram *program = new GLProgram;
- GLFragmentShader* shader = new GLFragmentShader(file.absoluteFilePath());
+ QGLShaderProgram *program = new QGLShaderProgram;
+ QGLShader* shader = new QGLShader(file.absoluteFilePath(), QGLShader::FragmentShader);
// The program does not take ownership over the shaders, so store them in a vector so they can be deleted afterwards.
- program->attach(*m_vertexShader);
- program->attach(*shader);
- if (program->failed()) {
+ program->addShader(m_vertexShader);
+ program->addShader(shader);
+ if (!program->link()) {
qWarning("Failed to compile and link shader program");
qWarning("Vertex shader log:");
qWarning() << m_vertexShader->log();
@@ -633,22 +638,22 @@ void Scene::initGL()
m_programs << program;
m_renderOptions->addShader(file.baseName());
- program->bind();
- m_cubemaps << (program->hasParameter("env") ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0);
- program->unbind();
+ program->enable();
+ m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0);
+ program->disable();
}
if (m_programs.size() == 0)
- m_programs << new GLProgram;
+ m_programs << new QGLShaderProgram;
m_renderOptions->emitParameterChanged();
}
// If one of the boxes should not be rendered, set excludeBox to its index.
// If the main box should not be rendered, set excludeBox to -1.
-void Scene::renderBoxes(const gfx::Matrix4x4f &view, int excludeBox)
+void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox)
{
- gfx::Matrix4x4f invView = view.inverse();
+ QMatrix4x4 invView = view.inverted();
// If multi-texturing is supported, use three saplers.
if (glActiveTexture) {
@@ -664,26 +669,26 @@ void Scene::renderBoxes(const gfx::Matrix4x4f &view, int excludeBox)
glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
- gfx::Matrix4x4f viewRotation(view);
+ QMatrix4x4 viewRotation(view);
viewRotation(3, 0) = viewRotation(3, 1) = viewRotation(3, 2) = 0.0f;
viewRotation(0, 3) = viewRotation(1, 3) = viewRotation(2, 3) = 0.0f;
viewRotation(3, 3) = 1.0f;
- glLoadMatrixf(viewRotation.bits());
+ glLoadMatrixf(viewRotation.data());
glScalef(20.0f, 20.0f, 20.0f);
// Don't render the environment if the environment texture can't be set for the correct sampler.
if (glActiveTexture) {
m_environment->bind();
- m_environmentProgram->bind();
- m_environmentProgram->setInt("tex", 0);
- m_environmentProgram->setInt("env", 1);
- m_environmentProgram->setInt("noise", 2);
+ m_environmentProgram->enable();
+ m_environmentProgram->setUniformValue("tex", GLint(0));
+ m_environmentProgram->setUniformValue("env", GLint(1));
+ m_environmentProgram->setUniformValue("noise", GLint(2));
m_box->draw();
- m_environmentProgram->unbind();
+ m_environmentProgram->disable();
m_environment->unbind();
}
- glLoadMatrixf(view.bits());
+ glLoadMatrixf(view.data());
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
@@ -693,9 +698,11 @@ void Scene::renderBoxes(const gfx::Matrix4x4f &view, int excludeBox)
continue;
glPushMatrix();
- gfx::Matrix4x4f m;
- m_trackBalls[1].rotation().matrix(m);
- glMultMatrixf(m.bits());
+ QMatrix4x4 m;
+ m.rotate(m_trackBalls[1].rotation());
+ m = m.transposed();
+
+ glMultMatrixf(m.data());
glRotatef(360.0f * i / m_programs.size(), 0.0f, 0.0f, 1.0f);
glTranslatef(2.0f, 0.0f, 0.0f);
@@ -707,14 +714,14 @@ void Scene::renderBoxes(const gfx::Matrix4x4f &view, int excludeBox)
else
m_environment->bind();
}
- m_programs[i]->bind();
- m_programs[i]->setInt("tex", 0);
- m_programs[i]->setInt("env", 1);
- m_programs[i]->setInt("noise", 2);
- m_programs[i]->setMatrix("view", view);
- m_programs[i]->setMatrix("invView", invView);
+ m_programs[i]->enable();
+ m_programs[i]->setUniformValue("tex", GLint(0));
+ m_programs[i]->setUniformValue("env", GLint(1));
+ m_programs[i]->setUniformValue("noise", GLint(2));
+ m_programs[i]->setUniformValue("view", view);
+ m_programs[i]->setUniformValue("invView", invView);
m_box->draw();
- m_programs[i]->unbind();
+ m_programs[i]->disable();
if (glActiveTexture) {
if (m_dynamicCubemap && m_cubemaps[i])
@@ -726,9 +733,10 @@ void Scene::renderBoxes(const gfx::Matrix4x4f &view, int excludeBox)
}
if (-1 != excludeBox) {
- gfx::Matrix4x4f m;
- m_trackBalls[0].rotation().matrix(m);
- glMultMatrixf(m.bits());
+ QMatrix4x4 m;
+ m.rotate(m_trackBalls[0].rotation());
+ m = m.transposed();
+ glMultMatrixf(m.data());
if (glActiveTexture) {
if (m_dynamicCubemap)
@@ -737,14 +745,14 @@ void Scene::renderBoxes(const gfx::Matrix4x4f &view, int excludeBox)
m_environment->bind();
}
- m_programs[m_currentShader]->bind();
- m_programs[m_currentShader]->setInt("tex", 0);
- m_programs[m_currentShader]->setInt("env", 1);
- m_programs[m_currentShader]->setInt("noise", 2);
- m_programs[m_currentShader]->setMatrix("view", view);
- m_programs[m_currentShader]->setMatrix("invView", invView);
+ m_programs[m_currentShader]->enable();
+ m_programs[m_currentShader]->setUniformValue("tex", GLint(0));
+ m_programs[m_currentShader]->setUniformValue("env", GLint(1));
+ m_programs[m_currentShader]->setUniformValue("noise", GLint(2));
+ m_programs[m_currentShader]->setUniformValue("view", view);
+ m_programs[m_currentShader]->setUniformValue("invView", invView);
m_box->draw();
- m_programs[m_currentShader]->unbind();
+ m_programs[m_currentShader]->disable();
if (glActiveTexture) {
if (m_dynamicCubemap)
@@ -829,31 +837,32 @@ void Scene::renderCubemaps()
// To speed things up, only update the cubemaps for the small cubes every N frames.
const int N = (m_updateAllCubemaps ? 1 : 3);
- gfx::Matrix4x4f mat;
+ QMatrix4x4 mat;
GLRenderTargetCube::getProjectionMatrix(mat, 0.1f, 100.0f);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
- glLoadMatrixf(mat.bits());
+ glLoadMatrixf(mat.data());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
- gfx::Vector3f center;
+ QVector3D center;
for (int i = m_frame % N; i < m_cubemaps.size(); i += N) {
if (0 == m_cubemaps[i])
continue;
float angle = 2.0f * PI * i / m_cubemaps.size();
- center = m_trackBalls[1].rotation().transform(gfx::Vector3f::vector(cos(angle), sin(angle), 0));
+
+ center = m_trackBalls[1].rotation().rotateVector(QVector3D(cos(angle), sin(angle), 0.0f));
for (int face = 0; face < 6; ++face) {
m_cubemaps[i]->begin(face);
GLRenderTargetCube::getViewMatrix(mat, face);
- gfx::Vector4f v = gfx::Vector4f::vector(-center[0], -center[1], -center[2], 1.0);
- mat[3] = v * mat;
+ QVector4D v = QVector4D(-center.x(), -center.y(), -center.z(), 1.0);
+ mat.setColumn(3, v * mat);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderBoxes(mat, i);
@@ -897,12 +906,9 @@ void Scene::drawBackground(QPainter *painter, const QRectF &)
glMatrixMode(GL_MODELVIEW);
- //gfx::Matrix4x4f view = gfx::Matrix4x4f::identity();
- //view(3, 2) -= 2.0f * exp(m_distExp / 1200.0f);
-
- gfx::Matrix4x4f view;
- m_trackBalls[2].rotation().matrix(view);
- view(3, 2) -= 2.0f * exp(m_distExp / 1200.0f);
+ QMatrix4x4 view;
+ view.rotate(m_trackBalls[2].rotation());
+ view(2, 3) -= 2.0f * exp(m_distExp / 1200.0f);
renderBoxes(view);
defaultStates();
@@ -936,10 +942,10 @@ void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
if (event->buttons() & Qt::MidButton) {
- m_trackBalls[2].move(pixelPosToViewPos(event->scenePos()), gfx::Quaternionf::identity());
+ m_trackBalls[2].move(pixelPosToViewPos(event->scenePos()), QQuaternion());
event->accept();
} else {
- m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), gfx::Quaternionf::identity());
+ m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), QQuaternion());
}
}
@@ -960,7 +966,7 @@ void Scene::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
if (event->buttons() & Qt::MidButton) {
- m_trackBalls[2].push(pixelPosToViewPos(event->scenePos()), gfx::Quaternionf::identity());
+ m_trackBalls[2].push(pixelPosToViewPos(event->scenePos()), QQuaternion());
event->accept();
}
}
@@ -982,7 +988,7 @@ void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
}
if (event->button() == Qt::MidButton) {
- m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), gfx::Quaternionf::identity());
+ m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), QQuaternion());
event->accept();
}
}
@@ -1021,20 +1027,20 @@ void Scene::toggleDynamicCubemap(int state)
void Scene::setColorParameter(const QString &name, QRgb color)
{
// set the color in all programs
- foreach (GLProgram *program, m_programs) {
- program->bind();
- program->setColor(name, color);
- program->unbind();
+ foreach (QGLShaderProgram *program, m_programs) {
+ program->enable();
+ program->setUniformValue(program->uniformLocation(name), QColor(color));
+ program->disable();
}
}
void Scene::setFloatParameter(const QString &name, float value)
{
// set the color in all programs
- foreach (GLProgram *program, m_programs) {
- program->bind();
- program->setFloat(name, value);
- program->unbind();
+ foreach (QGLShaderProgram *program, m_programs) {
+ program->enable();
+ program->setUniformValue(program->uniformLocation(name), value);
+ program->disable();
}
}
diff --git a/demos/boxes/scene.h b/demos/boxes/scene.h
index 2db9317..48ecaba 100644
--- a/demos/boxes/scene.h
+++ b/demos/boxes/scene.h
@@ -50,14 +50,13 @@
#include "roundedbox.h"
#include "gltrianglemesh.h"
-#include "vector.h"
#include "trackball.h"
#include "glbuffers.h"
-#include "glshaders.h"
#include "qtbox.h"
#define PI 3.14159265358979
+class QMatrix4x4;
class ParameterEdit : public QWidget
{
public:
@@ -195,7 +194,7 @@ public slots:
void setFloatParameter(const QString &name, float value);
void newItem(ItemDialog::ItemType type);
protected:
- void renderBoxes(const gfx::Matrix4x4f &view, int excludeBox = -2);
+ void renderBoxes(const QMatrix4x4 &view, int excludeBox = -2);
void setStates();
void setLights();
void defaultStates();
@@ -231,13 +230,11 @@ private:
GLTexture3D *m_noise;
GLRenderTargetCube *m_mainCubemap;
QVector<GLRenderTargetCube *> m_cubemaps;
- QVector<GLProgram *> m_programs;
- GLVertexShader *m_vertexShader;
- QVector<GLFragmentShader *> m_fragmentShaders;
- GLFragmentShader *m_environmentShader;
- GLProgram *m_environmentProgram;
+ QVector<QGLShaderProgram *> m_programs;
+ QGLShader *m_vertexShader;
+ QVector<QGLShader *> m_fragmentShaders;
+ QGLShader *m_environmentShader;
+ QGLShaderProgram *m_environmentProgram;
};
-
-
#endif
diff --git a/demos/boxes/trackball.cpp b/demos/boxes/trackball.cpp
index 980f6ed..a8bfe44 100644
--- a/demos/boxes/trackball.cpp
+++ b/demos/boxes/trackball.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "trackball.h"
+#include "scene.h"
//============================================================================//
// TrackBall //
@@ -51,23 +52,23 @@ TrackBall::TrackBall(TrackMode mode)
, m_pressed(false)
, m_mode(mode)
{
- m_axis = gfx::Vector3f::vector(0, 1, 0);
- m_rotation = gfx::Quaternionf::quaternion(1.0f, 0.0f, 0.0f, 0.0f);
+ m_axis = QVector3D(0, 1, 0);
+ m_rotation = QQuaternion();
m_lastTime = QTime::currentTime();
}
-TrackBall::TrackBall(float angularVelocity, const gfx::Vector3f& axis, TrackMode mode)
+TrackBall::TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode)
: m_axis(axis)
, m_angularVelocity(angularVelocity)
, m_paused(false)
, m_pressed(false)
, m_mode(mode)
{
- m_rotation = gfx::Quaternionf::quaternion(1.0f, 0.0f, 0.0f, 0.0f);
+ m_rotation = QQuaternion();
m_lastTime = QTime::currentTime();
}
-void TrackBall::push(const QPointF& p, const gfx::Quaternionf &)
+void TrackBall::push(const QPointF& p, const QQuaternion &)
{
m_rotation = rotation();
m_pressed = true;
@@ -76,7 +77,7 @@ void TrackBall::push(const QPointF& p, const gfx::Quaternionf &)
m_angularVelocity = 0.0f;
}
-void TrackBall::move(const QPointF& p, const gfx::Quaternionf &transformation)
+void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
{
if (!m_pressed)
return;
@@ -90,44 +91,45 @@ void TrackBall::move(const QPointF& p, const gfx::Quaternionf &transformation)
case Plane:
{
QLineF delta(m_lastPos, p);
- m_angularVelocity = delta.length() / msecs;
- m_axis = gfx::Vector3f::vector(delta.dy(), -delta.dx(), 0.0f).normalized();
- m_axis = transformation.transform(m_axis);
- m_rotation *= gfx::Quaternionf::rotation(delta.length(), m_axis);
+ m_angularVelocity = 180*delta.length() / (PI*msecs);
+ m_axis = QVector3D(delta.dy(), -delta.dx(), 0.0f).normalized();
+ m_axis = transformation.rotateVector(m_axis);
+ m_rotation *= QQuaternion::fromAxisAndAngle(m_axis, delta.length());
}
break;
case Sphere:
{
- gfx::Vector3f lastPos3D = gfx::Vector3f::vector(m_lastPos.x(), m_lastPos.y(), 0);
- float sqrZ = 1 - lastPos3D.sqrNorm();
+ QVector3D lastPos3D = QVector3D(m_lastPos.x(), m_lastPos.y(), 0.0f);
+ float sqrZ = 1 - QVector3D::dotProduct(lastPos3D, lastPos3D);
if (sqrZ > 0)
- lastPos3D[2] = sqrt(sqrZ);
+ lastPos3D.setZ(sqrt(sqrZ));
else
lastPos3D.normalize();
- gfx::Vector3f currentPos3D = gfx::Vector3f::vector(p.x(), p.y(), 0);
- sqrZ = 1 - currentPos3D.sqrNorm();
+ QVector3D currentPos3D = QVector3D(p.x(), p.y(), 0.0f);
+ sqrZ = 1 - QVector3D::dotProduct(currentPos3D, currentPos3D);
if (sqrZ > 0)
- currentPos3D[2] = sqrt(sqrZ);
+ currentPos3D.setZ(sqrt(sqrZ));
else
currentPos3D.normalize();
- m_axis = gfx::Vector3f::cross(currentPos3D, lastPos3D);
- float angle = asin(sqrt(m_axis.sqrNorm()));
+ m_axis = QVector3D::crossProduct(currentPos3D, lastPos3D);
+ float angle = asin(sqrt(QVector3D::dotProduct(m_axis, m_axis)));
- m_angularVelocity = angle / msecs;
+ m_angularVelocity = 180*angle / (PI*msecs);
m_axis.normalize();
- m_axis = transformation.transform(m_axis);
- m_rotation *= gfx::Quaternionf::rotation(angle, m_axis);
+ m_axis = transformation.rotateVector(m_axis);
+ m_rotation *= QQuaternion::fromAxisAndAngle(m_axis, angle);
}
break;
}
+
m_lastPos = p;
m_lastTime = currentTime;
}
-void TrackBall::release(const QPointF& p, const gfx::Quaternionf &transformation)
+void TrackBall::release(const QPointF& p, const QQuaternion &transformation)
{
// Calling move() caused the rotation to stop if the framerate was too low.
move(p, transformation);
@@ -146,13 +148,13 @@ void TrackBall::stop()
m_paused = true;
}
-gfx::Quaternionf TrackBall::rotation() const
+QQuaternion TrackBall::rotation() const
{
if (m_paused || m_pressed)
return m_rotation;
QTime currentTime = QTime::currentTime();
float angle = m_angularVelocity * m_lastTime.msecsTo(currentTime);
- return m_rotation * gfx::Quaternionf::rotation(angle, m_axis);
+ return m_rotation * QQuaternion::fromAxisAndAngle(m_axis, angle);
}
diff --git a/demos/boxes/trackball.h b/demos/boxes/trackball.h
index 5e3f40c..66e9b68 100644
--- a/demos/boxes/trackball.h
+++ b/demos/boxes/trackball.h
@@ -44,7 +44,8 @@
#include <QtGui>
-#include "vector.h"
+#include <QtGui/qvector3d.h>
+#include <QtGui/qquaternion.h>
class TrackBall
{
@@ -55,17 +56,17 @@ public:
Sphere,
};
TrackBall(TrackMode mode = Sphere);
- TrackBall(float angularVelocity, const gfx::Vector3f& axis, TrackMode mode = Sphere);
+ TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode = Sphere);
// coordinates in [-1,1]x[-1,1]
- void push(const QPointF& p, const gfx::Quaternionf &transformation);
- void move(const QPointF& p, const gfx::Quaternionf &transformation);
- void release(const QPointF& p, const gfx::Quaternionf &transformation);
+ void push(const QPointF& p, const QQuaternion &transformation);
+ void move(const QPointF& p, const QQuaternion &transformation);
+ void release(const QPointF& p, const QQuaternion &transformation);
void start(); // starts clock
void stop(); // stops clock
- gfx::Quaternionf rotation() const;
+ QQuaternion rotation() const;
private:
- gfx::Quaternionf m_rotation;
- gfx::Vector3f m_axis;
+ QQuaternion m_rotation;
+ QVector3D m_axis;
float m_angularVelocity;
QPointF m_lastPos;
diff --git a/demos/boxes/vector.h b/demos/boxes/vector.h
deleted file mode 100644
index bb24531..0000000
--- a/demos/boxes/vector.h
+++ /dev/null
@@ -1,602 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the demonstration applications of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef VECTOR_H
-#define VECTOR_H
-
-#include <cassert>
-#include <cmath>
-#include <iostream>
-
-namespace gfx
-{
-
-template<class T, int n>
-struct Vector
-{
- // Keep the Vector struct a plain old data (POD) struct by avoiding constructors
-
- static Vector vector(T x)
- {
- Vector result;
- for (int i = 0; i < n; ++i)
- result.v[i] = x;
- return result;
- }
-
- // Use only for 2D vectors
- static Vector vector(T x, T y)
- {
- assert(n == 2);
- Vector result;
- result.v[0] = x;
- result.v[1] = y;
- return result;
- }
-
- // Use only for 3D vectors
- static Vector vector(T x, T y, T z)
- {
- assert(n == 3);
- Vector result;
- result.v[0] = x;
- result.v[1] = y;
- result.v[2] = z;
- return result;
- }
-
- // Use only for 4D vectors
- static Vector vector(T x, T y, T z, T w)
- {
- assert(n == 4);
- Vector result;
- result.v[0] = x;
- result.v[1] = y;
- result.v[2] = z;
- result.v[3] = w;
- return result;
- }
-
- // Pass 'n' arguments to this function.
- static Vector vector(T *v)
- {
- Vector result;
- for (int i = 0; i < n; ++i)
- result.v[i] = v[i];
- return result;
- }
-
- T &operator [] (int i) {return v[i];}
- T operator [] (int i) const {return v[i];}
-
-#define VECTOR_BINARY_OP(op, arg, rhs) \
- Vector operator op (arg) const \
- { \
- Vector result; \
- for (int i = 0; i < n; ++i) \
- result.v[i] = v[i] op rhs; \
- return result; \
- }
-
- VECTOR_BINARY_OP(+, const Vector &u, u.v[i])
- VECTOR_BINARY_OP(-, const Vector &u, u.v[i])
- VECTOR_BINARY_OP(*, const Vector &u, u.v[i])
- VECTOR_BINARY_OP(/, const Vector &u, u.v[i])
- VECTOR_BINARY_OP(+, T s, s)
- VECTOR_BINARY_OP(-, T s, s)
- VECTOR_BINARY_OP(*, T s, s)
- VECTOR_BINARY_OP(/, T s, s)
-#undef VECTOR_BINARY_OP
-
- Vector operator - () const
- {
- Vector result;
- for (int i = 0; i < n; ++i)
- result.v[i] = -v[i];
- return result;
- }
-
-#define VECTOR_ASSIGN_OP(op, arg, rhs) \
- Vector &operator op (arg) \
- { \
- for (int i = 0; i < n; ++i) \
- v[i] op rhs; \
- return *this; \
- }
-
- VECTOR_ASSIGN_OP(+=, const Vector &u, u.v[i])
- VECTOR_ASSIGN_OP(-=, const Vector &u, u.v[i])
- VECTOR_ASSIGN_OP(=, T s, s)
- VECTOR_ASSIGN_OP(*=, T s, s)
- VECTOR_ASSIGN_OP(/=, T s, s)
-#undef VECTOR_ASSIGN_OP
-
- static T dot(const Vector &u, const Vector &v)
- {
- T sum(0);
- for (int i = 0; i < n; ++i)
- sum += u.v[i] * v.v[i];
- return sum;
- }
-
- static Vector cross(const Vector &u, const Vector &v)
- {
- assert(n == 3);
- return vector(u.v[1] * v.v[2] - u.v[2] * v.v[1],
- u.v[2] * v.v[0] - u.v[0] * v.v[2],
- u.v[0] * v.v[1] - u.v[1] * v.v[0]);
- }
-
- T sqrNorm() const
- {
- return dot(*this, *this);
- }
-
- // requires floating point type T
- void normalize()
- {
- T s = sqrNorm();
- if (s != 0)
- *this /= sqrt(s);
- }
-
- // requires floating point type T
- Vector normalized() const
- {
- T s = sqrNorm();
- if (s == 0)
- return *this;
- return *this / sqrt(s);
- }
-
- T *bits() {return v;}
- const T *bits() const {return v;}
-
- T v[n];
-};
-
-#define SCALAR_VECTOR_BINARY_OP(op) \
-template<class T, int n> \
-Vector<T, n> operator op (T s, const Vector<T, n>& u) \
-{ \
- Vector<T, n> result; \
- for (int i = 0; i < n; ++i) \
- result[i] = s op u[i]; \
- return result; \
-}
-
-SCALAR_VECTOR_BINARY_OP(+)
-SCALAR_VECTOR_BINARY_OP(-)
-SCALAR_VECTOR_BINARY_OP(*)
-SCALAR_VECTOR_BINARY_OP(/)
-#undef SCALAR_VECTOR_BINARY_OP
-
-template<class T, int n>
-std::ostream &operator << (std::ostream &os, const Vector<T, n> &v)
-{
- assert(n > 0);
- os << "[" << v[0];
- for (int i = 1; i < n; ++i)
- os << ", " << v[i];
- os << "]";
- return os;
-}
-
-typedef Vector<float, 2> Vector2f;
-typedef Vector<float, 3> Vector3f;
-typedef Vector<float, 4> Vector4f;
-
-template<class T, int rows, int cols>
-struct Matrix
-{
- // Keep the Matrix struct a plain old data (POD) struct by avoiding constructors
-
- static Matrix matrix(T x)
- {
- Matrix result;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j)
- result.v[i][j] = x;
- }
- return result;
- }
-
- static Matrix matrix(T *m)
- {
- Matrix result;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- result.v[i][j] = *m;
- ++m;
- }
- }
- return result;
- }
-
- T &operator () (int i, int j) {return v[i][j];}
- T operator () (int i, int j) const {return v[i][j];}
- Vector<T, cols> &operator [] (int i) {return v[i];}
- const Vector<T, cols> &operator [] (int i) const {return v[i];}
-
- // TODO: operators, methods
-
- Vector<T, rows> operator * (const Vector<T, cols> &u) const
- {
- Vector<T, rows> result;
- for (int i = 0; i < rows; ++i)
- result[i] = Vector<T, cols>::dot(v[i], u);
- return result;
- }
-
- template<int k>
- Matrix<T, rows, k> operator * (const Matrix<T, cols, k> &m)
- {
- Matrix<T, rows, k> result;
- for (int i = 0; i < rows; ++i)
- result[i] = v[i] * m;
- return result;
- }
-
- T* bits() {return reinterpret_cast<T *>(this);}
- const T* bits() const {return reinterpret_cast<const T *>(this);}
-
- // Simple Gauss elimination.
- // TODO: Optimize and improve stability.
- Matrix inverse(bool *ok = 0) const
- {
- assert(rows == cols);
- Matrix rhs = identity();
- Matrix lhs(*this);
- T temp;
- // Down
- for (int i = 0; i < rows; ++i) {
- // Pivoting
- int pivot = i;
- for (int j = i; j < rows; ++j) {
- if (qAbs(lhs(j, i)) > lhs(pivot, i))
- pivot = j;
- }
- // TODO: fuzzy compare.
- if (lhs(pivot, i) == T(0)) {
- if (ok)
- *ok = false;
- return rhs;
- }
- if (pivot != i) {
- for (int j = i; j < cols; ++j) {
- temp = lhs(pivot, j);
- lhs(pivot, j) = lhs(i, j);
- lhs(i, j) = temp;
- }
- for (int j = 0; j < cols; ++j) {
- temp = rhs(pivot, j);
- rhs(pivot, j) = rhs(i, j);
- rhs(i, j) = temp;
- }
- }
-
- // Normalize i-th row
- rhs[i] /= lhs(i, i);
- for (int j = cols - 1; j > i; --j)
- lhs(i, j) /= lhs(i, i);
-
- // Eliminate non-zeros in i-th column below the i-th row.
- for (int j = i + 1; j < rows; ++j) {
- rhs[j] -= lhs(j, i) * rhs[i];
- for (int k = i + 1; k < cols; ++k)
- lhs(j, k) -= lhs(j, i) * lhs(i, k);
- }
- }
- // Up
- for (int i = rows - 1; i > 0; --i) {
- for (int j = i - 1; j >= 0; --j)
- rhs[j] -= lhs(j, i) * rhs[i];
- }
- if (ok)
- *ok = true;
- return rhs;
- }
-
- Matrix<T, cols, rows> transpose() const
- {
- Matrix<T, cols, rows> result;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j)
- result.v[j][i] = v[i][j];
- }
- return result;
- }
-
- static Matrix identity()
- {
- Matrix result = matrix(T(0));
- for (int i = 0; i < rows && i < cols; ++i)
- result.v[i][i] = T(1);
- return result;
- }
-
- Vector<T, cols> v[rows];
-};
-
-template<class T, int rows, int cols>
-Vector<T, cols> operator * (const Vector<T, rows> &u, const Matrix<T, rows, cols> &m)
-{
- Vector<T, cols> result = Vector<T, cols>::vector(T(0));
- for (int i = 0; i < rows; ++i)
- result += m[i] * u[i];
- return result;
-}
-
-template<class T, int rows, int cols>
-std::ostream &operator << (std::ostream &os, const Matrix<T, rows, cols> &m)
-{
- assert(rows > 0);
- os << "[" << m[0];
- for (int i = 1; i < rows; ++i)
- os << ", " << m[i];
- os << "]";
- return os;
-}
-
-
-typedef Matrix<float, 2, 2> Matrix2x2f;
-typedef Matrix<float, 3, 3> Matrix3x3f;
-typedef Matrix<float, 4, 4> Matrix4x4f;
-
-template<class T>
-struct Quaternion
-{
- // Keep the Quaternion struct a plain old data (POD) struct by avoiding constructors
-
- static Quaternion quaternion(T s, T x, T y, T z)
- {
- Quaternion result;
- result.scalar = s;
- result.vector[0] = x;
- result.vector[1] = y;
- result.vector[2] = z;
- return result;
- }
-
- static Quaternion quaternion(T s, const Vector<T, 3> &v)
- {
- Quaternion result;
- result.scalar = s;
- result.vector = v;
- return result;
- }
-
- static Quaternion identity()
- {
- return quaternion(T(1), T(0), T(0), T(0));
- }
-
- // assumes that all the elements are packed tightly
- T& operator [] (int i) {return reinterpret_cast<T *>(this)[i];}
- T operator [] (int i) const {return reinterpret_cast<const T *>(this)[i];}
-
-#define QUATERNION_BINARY_OP(op, arg, rhs) \
- Quaternion operator op (arg) const \
- { \
- Quaternion result; \
- for (int i = 0; i < 4; ++i) \
- result[i] = (*this)[i] op rhs; \
- return result; \
- }
-
- QUATERNION_BINARY_OP(+, const Quaternion &q, q[i])
- QUATERNION_BINARY_OP(-, const Quaternion &q, q[i])
- QUATERNION_BINARY_OP(*, T s, s)
- QUATERNION_BINARY_OP(/, T s, s)
-#undef QUATERNION_BINARY_OP
-
- Quaternion operator - () const
- {
- return Quaternion(-scalar, -vector);
- }
-
- Quaternion operator * (const Quaternion &q) const
- {
- Quaternion result;
- result.scalar = scalar * q.scalar - Vector<T, 3>::dot(vector, q.vector);
- result.vector = scalar * q.vector + vector * q.scalar + Vector<T, 3>::cross(vector, q.vector);
- return result;
- }
-
- Quaternion operator * (const Vector<T, 3> &v) const
- {
- Quaternion result;
- result.scalar = -Vector<T, 3>::dot(vector, v);
- result.vector = scalar * v + Vector<T, 3>::cross(vector, v);
- return result;
- }
-
- friend Quaternion operator * (const Vector<T, 3> &v, const Quaternion &q)
- {
- Quaternion result;
- result.scalar = -Vector<T, 3>::dot(v, q.vector);
- result.vector = v * q.scalar + Vector<T, 3>::cross(v, q.vector);
- return result;
- }
-
-#define QUATERNION_ASSIGN_OP(op, arg, rhs) \
- Quaternion &operator op (arg) \
- { \
- for (int i = 0; i < 4; ++i) \
- (*this)[i] op rhs; \
- return *this; \
- }
-
- QUATERNION_ASSIGN_OP(+=, const Quaternion &q, q[i])
- QUATERNION_ASSIGN_OP(-=, const Quaternion &q, q[i])
- QUATERNION_ASSIGN_OP(=, T s, s)
- QUATERNION_ASSIGN_OP(*=, T s, s)
- QUATERNION_ASSIGN_OP(/=, T s, s)
-#undef QUATERNION_ASSIGN_OP
-
- Quaternion& operator *= (const Quaternion &q)
- {
- Quaternion result;
- result.scalar = scalar * q.scalar - Vector<T, 3>::dot(vector, q.vector);
- result.vector = scalar * q.vector + vector * q.scalar + Vector<T, 3>::cross(vector, q.vector);
- return (*this = result);
- }
-
- Quaternion& operator *= (const Vector<T, 3> &v)
- {
- Quaternion result;
- result.scalar = -Vector<T, 3>::dot(vector, v);
- result.vector = scalar * v + Vector<T, 3>::cross(vector, v);
- return (*this = result);
- }
-
- Quaternion conjugate() const
- {
- return quaternion(scalar, -vector);
- }
-
- T sqrNorm() const
- {
- return scalar * scalar + vector.sqrNorm();
- }
-
- Quaternion inverse() const
- {
- return conjugate() / sqrNorm();
- }
-
- // requires floating point type T
- Quaternion normalized() const
- {
- T s = sqrNorm();
- if (s == 0)
- return *this;
- return *this / sqrt(s);
- }
-
- void matrix(Matrix<T, 3, 3>& m) const
- {
- T bb = vector[0] * vector[0];
- T cc = vector[1] * vector[1];
- T dd = vector[2] * vector[2];
- T diag = scalar * scalar - bb - cc - dd;
- T ab = scalar * vector[0];
- T ac = scalar * vector[1];
- T ad = scalar * vector[2];
- T bc = vector[0] * vector[1];
- T cd = vector[1] * vector[2];
- T bd = vector[2] * vector[0];
- m(0, 0) = diag + 2 * bb;
- m(0, 1) = 2 * (bc - ad);
- m(0, 2) = 2 * (ac + bd);
- m(1, 0) = 2 * (ad + bc);
- m(1, 1) = diag + 2 * cc;
- m(1, 2) = 2 * (cd - ab);
- m(2, 0) = 2 * (bd - ac);
- m(2, 1) = 2 * (ab + cd);
- m(2, 2) = diag + 2 * dd;
- }
-
- void matrix(Matrix<T, 4, 4>& m) const
- {
- T bb = vector[0] * vector[0];
- T cc = vector[1] * vector[1];
- T dd = vector[2] * vector[2];
- T diag = scalar * scalar - bb - cc - dd;
- T ab = scalar * vector[0];
- T ac = scalar * vector[1];
- T ad = scalar * vector[2];
- T bc = vector[0] * vector[1];
- T cd = vector[1] * vector[2];
- T bd = vector[2] * vector[0];
- m(0, 0) = diag + 2 * bb;
- m(0, 1) = 2 * (bc - ad);
- m(0, 2) = 2 * (ac + bd);
- m(0, 3) = 0;
- m(1, 0) = 2 * (ad + bc);
- m(1, 1) = diag + 2 * cc;
- m(1, 2) = 2 * (cd - ab);
- m(1, 3) = 0;
- m(2, 0) = 2 * (bd - ac);
- m(2, 1) = 2 * (ab + cd);
- m(2, 2) = diag + 2 * dd;
- m(2, 3) = 0;
- m(3, 0) = 0;
- m(3, 1) = 0;
- m(3, 2) = 0;
- m(3, 3) = 1;
- }
-
- // assumes that 'this' is normalized
- Vector<T, 3> transform(const Vector<T, 3> &v) const
- {
- Matrix<T, 3, 3> m;
- matrix(m);
- return v * m;
- }
-
- // assumes that all the elements are packed tightly
- T* bits() {return reinterpret_cast<T *>(this);}
- const T* bits() const {return reinterpret_cast<const T *>(this);}
-
- // requires floating point type T
- static Quaternion rotation(T angle, const Vector<T, 3> &unitAxis)
- {
- T s = sin(angle / 2);
- T c = cos(angle / 2);
- return quaternion(c, unitAxis * s);
- }
-
- T scalar;
- Vector<T, 3> vector;
-};
-
-template<class T>
-Quaternion<T> operator * (T s, const Quaternion<T>& q)
-{
- return Quaternion<T>::quaternion(s * q.scalar, s * q.vector);
-}
-
-typedef Quaternion<float> Quaternionf;
-
-} // end namespace gfx
-
-#endif
diff --git a/demos/qtdemo/xml/examples.xml b/demos/qtdemo/xml/examples.xml
index 96a3e80..2560848 100644
--- a/demos/qtdemo/xml/examples.xml
+++ b/demos/qtdemo/xml/examples.xml
@@ -19,6 +19,15 @@
<example filename="mediaplayer" name="Media Player" />
<example filename="boxes" name="Boxes" />
</demos>
+ <category dirname="animation" name="Animation Framework">
+ <example filename="animatedtiles" name="Animated Tiles" />
+ <example filename="appchooser" name="Appchooser" />
+ <example filename="easing" name="Easing Curves" />
+ <example filename="moveblocks" name="Moving Blocks" />
+ <example filename="states" name="UI States" />
+ <example filename="stickman" name="Stickman" />
+ <example filename="sub-attaq" name="Sub-attaq" />
+ </category>
<category dirname="qtconcurrent" name="Concurrent Programming">
<example filename="map" name="Map" executable="false" />
<example filename="progressdialog" name="Progress Dialog" />
@@ -167,6 +176,12 @@
<example filename="masterdetail" name="Music Archive" />
<example filename="sqlwidgetmapper" name="SQL Widget Mapper" />
</category>
+ <category dirname="statemachine" name="State Machine">
+ <example filename="eventtransitions" name="Event Transitions" />
+ <example filename="tankgame" name="Tank Game" />
+ <example filename="trafficlight" name="Traffic Light" />
+ <example filename="twowaybutton" name="Two-way Button" />
+ </category>
<category dirname="threads" name="Threading">
<example filename="mandelbrot" name="Mandelbrot" />
</category>
diff --git a/dist/changes-4.5.2 b/dist/changes-4.5.2
index b3e808f..1e00208 100644
--- a/dist/changes-4.5.2
+++ b/dist/changes-4.5.2
@@ -42,8 +42,8 @@ Third party components
Memory (r41527, r43764, r43828, r43830)
JavaScript (r39882, r40086, r40131, r40133)
Rendering (r41285, r41296, r41659, r42887)
- Network (r41664, r42516)
- Plugins (r41346, r43550)
+ Network (r41664, r42516, r42747)
+ Plugins (r41346, r43550, r43915, r43917, r43923)
Clipboard (r41360)
****************************************************************************
diff --git a/doc/src/animation.qdoc b/doc/src/animation.qdoc
new file mode 100644
index 0000000..b4e603c
--- /dev/null
+++ b/doc/src/animation.qdoc
@@ -0,0 +1,368 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \page animation-overview.html
+ \title The Animation Framework
+ \ingroup architecture
+ \ingroup animation
+ \brief An overview of the Animation Framework
+
+ \keyword Animation
+
+ The animation framework is part of the Kinetic project, and aims
+ to provide an easy way for creating animated and smooth GUI's. By
+ animating Qt properties, the framework provides great freedom for
+ animating widgets and other \l{QObject}s. The framework can also
+ be used with the Graphics View framework.
+
+ In this overview, we explain the basics of its architecture. We
+ also show examples of the most common techniques that the
+ framework allows for animating QObjects and graphics items.
+
+ \tableofcontents
+
+ \section1 The Animation Architecture
+
+ We will in this section take a high-level look at the animation
+ framework's architecture and how it is used to animate Qt
+ properties. The following diagram shows the most important classes
+ in the animation framework.
+
+ \image animations-architecture.png
+
+ The animation framework foundation consists of the base class
+ QAbstractAnimation, and its two subclasses QVariantAnimation and
+ QAnimationGroup. QAbstractAnimation is the ancestor of all
+ animations. It represents basic properties that are common for all
+ animations in the framework; notably, the ability to start, stop,
+ and pause an animation. It is also receives the time change
+ notifications.
+
+ The animation framework further provides the QPropertyAnimation
+ class, which inherits QVariantAnimation and performs animation of
+ a Qt property, which is part of Qt's \l{Meta-Object
+ System}{meta-object system}. The class performs an interpolation
+ over the property using an easing curve. So when you want to
+ animate a value, you can declare it as a property and make your
+ class a QObject. Note that this gives us great freedom in
+ animating already existing widgets and other \l{QObject}s.
+
+ Complex animations can be constructed by building a tree structure
+ of \l{QAbstractAnimation}s. The tree is built by using
+ \l{QAnimationGroup}s, which function as containers for other
+ animations. Note also that the groups are subclasses of
+ QAbstractAnimation, so groups can themselves contain other groups.
+
+ The animation framework can be used on its own, but is also
+ designed to be part of the state machine framework (See the
+ \l{The State Machine Framework}{state machine framework} for an
+ introduction to the Qt state machine). The state machine provides
+ a special state that can play an animation. A QState can also set
+ properties when the state is entered or exited, and this special
+ animation state will interpolate between these values when given a
+ QPropertyAnimation. We will look more closely at this later.
+
+ Behind the scenes, the animations are controlled by a global
+ timer, which sends \l{QAbstractAnimation::updateCurrentTime()}{updates} to
+ all animations that are playing.
+
+ For detailed descriptions of the classes' function and roles in
+ the framework, please look up their class descriptions.
+
+ \section1 Animating Qt Properties
+
+ As mentioned in the previous section, the QPropertyAnimation class
+ can interpolate over Qt properties. It is this class that should
+ be used for animation of values; in fact, its superclass,
+ QVariantAnimation, is an abstract class, and cannot be used
+ directly.
+
+ A major reason we chose to animate Qt properties is that it
+ presents us with freedom to animate already existing classes in
+ the Qt API. Notably, the QWidget class (which we can also embed in
+ a QGraphicsView) has properties for its bounds, colors, etc.
+ Let's look at a small example:
+
+ \code
+ QPushButton button("Animated Button");
+ button.show();
+
+ QPropertyAnimation animation(&button, "geometry");
+ animation.setDuration(10000);
+ animation.setStartValue(QRect(0, 0, 100, 30));
+ animation.setEndValue(QRect(250, 250, 100, 30));
+
+ animation.start();
+ \endcode
+
+ This code will move \c button from the top left corner of the
+ screen to the position (250, 250) in 10 seconds (10000 milliseconds).
+
+ The example above will do a linear interpolation between the
+ start and end value. It is also possible to set values
+ situated between the start and end value. The interpolation
+ will then go by these points.
+
+ \code
+ QPushButton button("Animated Button");
+ button.show();
+
+ QPropertyAnimation animation(&button, "geometry");
+ animation.setDuration(10000);
+
+ animation.setKeyValueAt(0, QRect(0, 0, 100, 30));
+ animation.setKeyValueAt(0.8, QRect(250, 250, 100, 30));
+ animation.setKeyValueAt(1, QRect(0, 0, 100, 30));
+
+ animation.start();
+ \endcode
+
+ In this example, the animation will take the button to (250, 250)
+ in 8 seconds, and then move it back to its original position in
+ the remaining 2 seconds. The movement will be linearly
+ interpolated between these points.
+
+ You also have the possibility to animate values of a QObject
+ that is not declared as a Qt property. The only requirement is
+ that this value has a setter. You can then subclass the class
+ containing the value and declare a property that uses this setter.
+ Note that each Qt property requires a getter, so you will need to
+ provide a getter yourself if this is not defined.
+
+ \code
+ class MyGraphicsRectItem : public QObject, public QGraphicsRectItem
+ {
+ Q_OBJECT
+ Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
+ };
+ \endcode
+
+ In the above code example, we subclass QGraphicsRectItem and
+ define a geometry property. We can now animate the widgets
+ geometry even if QGraphicsRectItem does not provide the geometry
+ property.
+
+ For a general introduction to the Qt property system, see its
+ \l{Qt's Property System}{overview}.
+
+ \section1 Animations and the Graphics View Framework
+
+ When you want to animate \l{QGraphicsItem}s, you also use
+ QPropertyAnimation. However, QGraphicsItem does not inherit QObject.
+ A good solution is to subclass the graphics item you wish to animate.
+ This class will then also inherit QObject.
+ This way, QPropertyAnimation can be used for \l{QGraphicsItem}s.
+ The example below shows how this is done. Another possibility is
+ to inherit QGraphicsWidget, which already is a QObject.
+
+ \code
+ class Pixmap : public QObject, public QGraphicsPixmapItem
+ {
+ Q_OBJECT
+ Q_PROPERTY(QPointF pos READ pos WRITE setPos)
+ ...
+ \endcode
+
+ As described in the previous section, we need to define
+ properties that we wish to animate.
+
+ Note that QObject must be the first class inherited as the
+ meta-object system demands this.
+
+ \warning The QItemAnimation class, which was initially intended
+ for animating \l{QGraphicsItem}s may be deprecated or removed from
+ the animation framework.
+
+ \omit (need something about the list of animations). \endomit
+
+ \section1 Easing Curves
+
+ As mentioned, QPropertyAnimation performs an interpolation between
+ the start and end property value. In addition to adding more key
+ values to the animation, you can also use an easing curve. Easing
+ curves describe a function that controls how the speed of the
+ interpolation between 0 and 1 should be, and are useful if you
+ want to control the speed of an animation without changing the
+ path of the interpolation.
+
+ \code
+ QPushButton button("Animated Button");
+ button.show();
+
+ QPropertyAnimation animation(&button, "geometry");
+ animation.setDuration(3000);
+ animation.setStartValue(QRect(0, 0, 100, 30));
+ animation.setEndValue(QRect(250, 250, 100, 30));
+
+ animation.setEasingCurve(QEasingCurve::OutBounce);
+
+ animation.start();
+ \endcode
+
+ Here the animation will follow a curve that makes it bounce like a
+ ball as if it was dropped from the start to the end position.
+ QEasingCurve has a large collection of curves for you to choose
+ from. These are defined by the QEasingCurve::Type enum. If you are
+ in need of another curve, you can also implement one yourself, and
+ register it with QEasingCurve.
+
+ \omit Drop this for the first Lab release
+ (Example of custom easing curve (without the actual impl of
+ the function I expect)
+ \endomit
+
+ \section1 Putting Animations Together
+
+ An application will often contain more than one animation. For
+ instance, you might want to move more than one graphics item
+ simultaneously or move them in sequence after each other.
+
+ The subclasses of QAnimationGroup (QSequentialAnimationGroup and
+ QParallelAnimationGroup) are containers for other animations so
+ that these animations can be animated either in sequence or
+ parallel. The QAnimationGroup is an example of an animation that
+ does not animate properties, but it gets notified of time changes
+ periodically. This enables it to forward those time changes to its
+ contained animations, and thereby controlling when its animations
+ are played.
+
+ Let's look at code examples that use both
+ QSequentialAnimationGroup and QParallelAnimationGroup, starting
+ off with the latter.
+
+ \code
+ QPushButton *bonnie = new QPushButton("Bonnie");
+ bonnie->show();
+
+ QPushButton *clyde = new QPushButton("Clyde");
+ clyde->show();
+
+ QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "geometry");
+ // Set up anim1
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "geometry");
+ // Set up anim2
+
+ QParallelAnimationGroup *group = new QParallelAnimationGroup;
+ group->addAnimation(anim1);
+ group->addAnimation(anim2);
+
+ group->start();
+ \endcode
+
+ A parallel group plays more than one animation at the same time.
+ Calling its \l{QAbstractAnimation::}{start()} function will start
+ all animations it governs.
+
+ \code
+ QPushButton button("Animated Button");
+ button.show();
+
+ QPropertyAnimation anim1(&button, "geometry");
+ anim1.setDuration(3000);
+ anim1.setStartValue(QRect(0, 0, 100, 30));
+ anim1.setEndValue(QRect(500, 500, 100, 30));
+
+ QPropertyAnimation anim2(&button, "geometry");
+ anim2.setDuration(3000);
+ anim2.setStartValue(QRect(500, 500, 100, 30));
+ anim2.setEndValue(QRect(1000, 500, 100, 30));
+
+ QSequentialAnimationGroup group;
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ group.start();
+ \endcode
+
+ As you no doubt have guessed, QSequentialAnimationGroup plays
+ its animations in sequence. It starts the next animation in
+ the list after the previous is finished.
+
+ Since an animation group is an animation itself, you can add
+ it to another group. This way, you can build a tree structure
+ of animations which specifies when the animations are played
+ in relation to each other.
+
+ \section1 Animations and States
+
+ When using a \l{The State Machine Framework}{state machine}, we
+ have a special state, QAnimationState, that will play one or more
+ animations.
+
+ The QState::addAnimatedTransition() convenience function lets you
+ associate an animation to a state transition. The function will
+ create the QAnimationState for you, and insert it into the state
+ machine. We also have the possibility to associate properties with
+ the states rather than setting the start and end values ourselves.
+ Below is a complete code example that animates the geometry of a
+ QPushButton.
+
+ \code
+ QPushButton *button = new QPushButton("Animated Button");
+ button->show();
+
+ QStateMachine *machine = new QStateMachine;
+
+ QState *state1 = new QState(machine->rootState());
+ state1->setPropertyOnEntry(button, "geometry",
+ QRect(0, 0, 100, 30));
+ machine->setInitialState(state1);
+
+ QState *state2 = new QState(machine->rootState());
+ state2->setPropertyOnEntry(button, "geometry",
+ QRect(250, 250, 100, 30));
+
+ state1->addAnimatedTransition(button, SIGNAL(clicked()), state2,
+ new QPropertyAnimation(button, "geometry"));
+ state2->addAnimatedTransition(button, SIGNAL(clicked()), state1,
+ new QPropertyAnimation(button, "geometry"));
+
+ machine->start();
+ \endcode
+
+ For a more comprehensive example of how to use the state machine
+ framework for animations, see the states example (it lives in the
+ \c{examples/animation/states} directory).
+*/
+
diff --git a/doc/src/diagrams/animations-architecture.svg b/doc/src/diagrams/animations-architecture.svg
new file mode 100644
index 0000000..0246510
--- /dev/null
+++ b/doc/src/diagrams/animations-architecture.svg
@@ -0,0 +1,351 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="950.00006"
+ height="365.28983"
+ id="svg2"
+ sodipodi:version="0.32"
+ inkscape:version="0.46"
+ sodipodi:docname="animations-architecture.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape"
+ version="1.0">
+ <defs
+ id="defs4">
+ <marker
+ inkscape:stockid="Arrow2Mend"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="Arrow2Mend"
+ style="overflow:visible">
+ <path
+ id="path3736"
+ style="font-size:12px;fill-rule:evenodd;stroke-width:0.625;stroke-linejoin:round"
+ d="M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.97309,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z"
+ transform="scale(-0.6,-0.6)" />
+ </marker>
+ <marker
+ inkscape:stockid="Arrow2Lend"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="Arrow2Lend"
+ style="overflow:visible">
+ <path
+ id="path3730"
+ style="font-size:12px;fill-rule:evenodd;stroke-width:0.625;stroke-linejoin:round"
+ d="M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.97309,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z"
+ transform="matrix(-1.1,0,0,-1.1,-1.1,0)" />
+ </marker>
+ <marker
+ inkscape:stockid="Arrow1Lend"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="Arrow1Lend"
+ style="overflow:visible">
+ <path
+ id="path3712"
+ d="M 0,0 L 5,-5 L -12.5,0 L 5,5 L 0,0 z"
+ style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;marker-start:none"
+ transform="matrix(-0.8,0,0,-0.8,-10,0)" />
+ </marker>
+ <marker
+ inkscape:stockid="TriangleOutL"
+ orient="auto"
+ refY="0"
+ refX="0"
+ id="TriangleOutL"
+ style="overflow:visible">
+ <path
+ id="path3852"
+ d="M 5.77,0 L -2.88,5 L -2.88,-5 L 5.77,0 z"
+ style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;marker-start:none"
+ transform="scale(0.8,0.8)" />
+ </marker>
+ <linearGradient
+ id="linearGradient3165">
+ <stop
+ style="stop-color:#c8c8dc;stop-opacity:1;"
+ offset="0"
+ id="stop3167" />
+ <stop
+ style="stop-color:#b4b4c8;stop-opacity:0;"
+ offset="1"
+ id="stop3169" />
+ </linearGradient>
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 526.18109 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="744.09448 : 526.18109 : 1"
+ inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+ id="perspective10" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3165"
+ id="linearGradient3171"
+ x1="249.25"
+ y1="89.862183"
+ x2="475.75"
+ y2="89.862183"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.2195969,0,0,3.7006494,-257.93754,-842.42203)" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3165"
+ id="linearGradient3183"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.2195969,0,0,3.7006494,-383.02298,-676.69717)"
+ x1="249.25"
+ y1="89.862183"
+ x2="475.75"
+ y2="89.862183" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3165"
+ id="linearGradient3191"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.2195969,0,0,3.7006494,-382.93759,-1004.922)"
+ x1="249.25"
+ y1="89.862183"
+ x2="475.75"
+ y2="89.862183" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3165"
+ id="linearGradient7165"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.2195969,0,0,3.7006494,-483.69907,-593.77419)"
+ x1="249.25"
+ y1="89.862183"
+ x2="475.75"
+ y2="89.862183" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3165"
+ id="linearGradient7195"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.2195969,0,0,3.7006494,-571.87523,-1167.422)"
+ x1="249.25"
+ y1="89.862183"
+ x2="475.75"
+ y2="89.862183" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3165"
+ id="linearGradient7203"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.2195969,0,0,3.7006494,-572.46592,-841.2256)"
+ x1="249.25"
+ y1="89.862183"
+ x2="475.75"
+ y2="89.862183" />
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ gridtolerance="10000"
+ guidetolerance="10"
+ objecttolerance="10"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="0.98994949"
+ inkscape:cx="276.75951"
+ inkscape:cy="155.06417"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:snap-bbox="true"
+ inkscape:window-width="1592"
+ inkscape:window-height="1124"
+ inkscape:window-x="0"
+ inkscape:window-y="0">
+ <inkscape:grid
+ type="xygrid"
+ id="grid2383"
+ visible="true"
+ enabled="true"
+ units="pt"
+ spacingx="2pt"
+ spacingy="2pt" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(-121.77519,-152.95286)">
+ <rect
+ style="opacity:1;fill:url(#linearGradient3171);fill-opacity:1;stroke:#202020;stroke-width:1.35220754;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="rect2385"
+ width="49.409317"
+ height="277.54871"
+ x="-203.03828"
+ y="-648.64777"
+ ry="12.582828"
+ rx="10.562523"
+ transform="matrix(0,-1,-1,0,0,0)" />
+ <text
+ xml:space="preserve"
+ style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:100%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:DejaVu Sans Mono;-inkscape-font-specification:DejaVu Sans Mono"
+ x="380.311"
+ y="185.86879"
+ id="text3173"
+ sodipodi:linespacing="100%"><tspan
+ sodipodi:role="line"
+ id="tspan3175"
+ x="380.311"
+ y="185.86879">QAbstractAnimation</tspan></text>
+ <rect
+ style="opacity:1;fill:url(#linearGradient3183);fill-opacity:1;stroke:#202020;stroke-width:1.35220754;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="rect3177"
+ width="49.409317"
+ height="277.54871"
+ x="-328.12369"
+ y="-482.92297"
+ ry="12.582828"
+ rx="10.562523"
+ transform="matrix(0,-1,-1,0,0,0)" />
+ <text
+ xml:space="preserve"
+ style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:100%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:DejaVu Sans Mono;-inkscape-font-specification:DejaVu Sans Mono"
+ x="221.80489"
+ y="310.95419"
+ id="text3179"
+ sodipodi:linespacing="100%"><tspan
+ sodipodi:role="line"
+ id="tspan3181"
+ x="221.80489"
+ y="310.95419">QVariantAnimation</tspan></text>
+ <rect
+ style="opacity:1;fill:url(#linearGradient3191);fill-opacity:1;stroke:#202020;stroke-width:1.35220754;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="rect3185"
+ width="49.409317"
+ height="277.54871"
+ x="-328.03827"
+ y="-811.14777"
+ ry="12.582828"
+ rx="10.562523"
+ transform="matrix(0,-1,-1,0,0,0)" />
+ <text
+ xml:space="preserve"
+ style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:100%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:DejaVu Sans Mono;-inkscape-font-specification:DejaVu Sans Mono"
+ x="564.13324"
+ y="310.86877"
+ id="text3187"
+ sodipodi:linespacing="100%"><tspan
+ sodipodi:role="line"
+ id="tspan3189"
+ x="564.13324"
+ y="310.86877">QAnimationGroup</tspan></text>
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#000000;stroke-width:1.875;stroke-linecap:butt;stroke-linejoin:miter;marker-mid:none;marker-end:url(#Arrow2Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 346.77519,279.39048 L 346.77519,241.89048 L 509.27519,241.89048 L 509.27519,204.39048"
+ id="path3195"
+ sodipodi:nodetypes="cccc" />
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#000000;stroke-width:1.875;stroke-linecap:butt;stroke-linejoin:miter;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 671.77519,279.39048 L 671.77519,241.89048 L 509.27519,241.89048"
+ id="path7137"
+ sodipodi:nodetypes="ccc" />
+ <rect
+ style="opacity:1;fill:url(#linearGradient7165);fill-opacity:1;stroke:#202020;stroke-width:1.35220754;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="rect7159"
+ width="49.409317"
+ height="277.54871"
+ x="-428.7998"
+ y="-400"
+ ry="12.582828"
+ rx="10.562523"
+ transform="matrix(0,-1,-1,0,0,0)" />
+ <text
+ xml:space="preserve"
+ style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:100%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:DejaVu Sans Mono;-inkscape-font-specification:DejaVu Sans Mono"
+ x="131.66315"
+ y="411.63031"
+ id="text7161"
+ sodipodi:linespacing="100%"><tspan
+ sodipodi:role="line"
+ id="tspan7163"
+ x="131.66315"
+ y="411.63031">QPropertyAnimation</tspan></text>
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#000000;stroke-width:1.875;stroke-linecap:butt;stroke-linejoin:miter;marker-mid:none;marker-end:url(#Arrow2Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 309.27519,379.39048 L 309.27519,329.39048"
+ id="path7167"
+ sodipodi:nodetypes="cc" />
+ <rect
+ style="opacity:1;fill:url(#linearGradient7195);fill-opacity:1;stroke:#202020;stroke-width:1.35220754;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="rect7189"
+ width="49.409317"
+ height="375"
+ x="-516.97589"
+ y="-1071.0991"
+ ry="12.582828"
+ rx="10.562523"
+ transform="matrix(0,-1,-1,0,0,0)" />
+ <text
+ xml:space="preserve"
+ style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:100%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:DejaVu Sans Mono;-inkscape-font-specification:DejaVu Sans Mono"
+ x="703.17139"
+ y="499.8064"
+ id="text7191"
+ sodipodi:linespacing="100%"><tspan
+ sodipodi:role="line"
+ id="tspan7193"
+ x="703.17139"
+ y="499.8064">QSequentialAnimationGroup</tspan></text>
+ <rect
+ style="opacity:1;fill:url(#linearGradient7203);fill-opacity:1;stroke:#202020;stroke-width:1.35220754;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="rect7197"
+ width="50"
+ height="350"
+ x="-517.56659"
+ y="-647.45129"
+ ry="12.582828"
+ rx="10.562523"
+ transform="matrix(0,-1,-1,0,0,0)" />
+ <text
+ xml:space="preserve"
+ style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:100%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:DejaVu Sans Mono;-inkscape-font-specification:DejaVu Sans Mono"
+ x="306.46109"
+ y="500.39709"
+ id="text7199"
+ sodipodi:linespacing="100%"><tspan
+ sodipodi:role="line"
+ id="tspan7201"
+ x="306.46109"
+ y="500.39709">QParallelAnimationGroup</tspan></text>
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#000000;stroke-width:1.875;stroke-linecap:butt;stroke-linejoin:miter;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 859.27519,466.89048 L 859.27519,391.89048 L 671.77519,391.89048"
+ id="path7205"
+ sodipodi:nodetypes="ccc" />
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#000000;stroke-width:1.875;stroke-linecap:butt;stroke-linejoin:miter;marker-mid:none;marker-end:url(#Arrow2Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 496.77519,466.89048 L 496.77519,391.89048 L 671.77519,391.89048 L 671.77519,329.39048"
+ id="path7207"
+ sodipodi:nodetypes="cccc" />
+ </g>
+</svg>
diff --git a/doc/src/diagrams/programs/easingcurve/easingcurve.pro b/doc/src/diagrams/programs/easingcurve/easingcurve.pro
new file mode 100644
index 0000000..0b80127
--- /dev/null
+++ b/doc/src/diagrams/programs/easingcurve/easingcurve.pro
@@ -0,0 +1,13 @@
+######################################################################
+# Automatically generated by qmake (2.01a) fr 13. feb 13:26:38 2009
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp
+
+CONFIG += console \ No newline at end of file
diff --git a/doc/src/diagrams/programs/easingcurve/main.cpp b/doc/src/diagrams/programs/easingcurve/main.cpp
new file mode 100644
index 0000000..98e9d37
--- /dev/null
+++ b/doc/src/diagrams/programs/easingcurve/main.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $TROLLTECH_DUAL_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+void createCurveIcons();
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ createCurveIcons();
+ return app.exit();
+}
+
+void createCurveIcons()
+{
+ QDir dir(QDir::current());
+ if (dir.dirName() == QLatin1String("debug") || dir.dirName() == QLatin1String("release")) {
+ dir.cdUp();
+ }
+ dir.cdUp();
+ dir.cdUp();
+ dir.cdUp();
+ QSize iconSize(128, 128);
+ QPixmap pix(iconSize);
+ QPainter painter(&pix);
+ QLinearGradient gradient(0,0, 0, iconSize.height());
+ gradient.setColorAt(0.0, QColor(240, 240, 240));
+ gradient.setColorAt(1.0, QColor(224, 224, 224));
+ QBrush brush(gradient);
+ const QMetaObject &mo = QEasingCurve::staticMetaObject;
+ QMetaEnum metaEnum = mo.enumerator(mo.indexOfEnumerator("Type"));
+ QFont oldFont = painter.font();
+ // Skip QEasingCurve::Custom
+ QString output(QString::fromAscii("%1/images").arg(dir.absolutePath()));
+ printf("Generating images to %s\n", qPrintable(output));
+ for (int i = 0; i < QEasingCurve::NCurveTypes - 1; ++i) {
+ painter.setFont(oldFont);
+ QString name(QLatin1String(metaEnum.key(i)));
+ painter.fillRect(QRect(QPoint(0, 0), iconSize), brush);
+ QEasingCurve curve((QEasingCurve::Type)i);
+ painter.setPen(QColor(0, 0, 255, 64));
+ qreal xAxis = iconSize.height()/1.5;
+ qreal yAxis = iconSize.width()/3;
+ painter.drawLine(0, xAxis, iconSize.width(), xAxis); // hor
+ painter.drawLine(yAxis, 0, yAxis, iconSize.height()); // ver
+
+ qreal curveScale = iconSize.height()/2;
+
+ painter.drawLine(yAxis - 2, xAxis - curveScale, yAxis + 2, xAxis - curveScale); // hor
+ painter.drawLine(yAxis + curveScale, xAxis + 2, yAxis + curveScale, xAxis - 2); // ver
+ painter.drawText(yAxis + curveScale - 8, xAxis - curveScale - 4, QLatin1String("(1,1)"));
+
+ painter.drawText(yAxis + 42, xAxis + 10, QLatin1String("progress"));
+ painter.drawText(15, xAxis - curveScale - 10, QLatin1String("ease"));
+
+ painter.setPen(QPen(Qt::red, 1, Qt::DotLine));
+ painter.drawLine(yAxis, xAxis - curveScale, yAxis + curveScale, xAxis - curveScale); // hor
+ painter.drawLine(yAxis + curveScale, xAxis, yAxis + curveScale, xAxis - curveScale); // ver
+
+ QPoint currentPos(yAxis, xAxis);
+
+ painter.setPen(Qt::black);
+ QFont font = oldFont;
+ font.setPixelSize(oldFont.pixelSize() + 15);
+ painter.setFont(font);
+ painter.drawText(0, iconSize.height() - 20, iconSize.width(), 20, Qt::AlignHCenter, name);
+
+ for (qreal t = 0; t < 1.0; t+=1.0/curveScale) {
+ QPoint to;
+ to.setX(yAxis + curveScale * t);
+ to.setY(xAxis - curveScale * curve.valueForProgress(t));
+ painter.drawLine(currentPos, to);
+ currentPos = to;
+ }
+ QString fileName(QString::fromAscii("qeasingcurve-%1.png").arg(name.toLower()));
+ printf("%s\n", qPrintable(fileName));
+ pix.save(QString::fromAscii("%1/%2").arg(output).arg(fileName), "PNG");
+ }
+}
+
+
diff --git a/doc/src/examples-overview.qdoc b/doc/src/examples-overview.qdoc
index 549574d..92ccd4e 100644
--- a/doc/src/examples-overview.qdoc
+++ b/doc/src/examples-overview.qdoc
@@ -319,6 +319,14 @@
from displaying Web pages within a Qt user interface to an implementation of
a basic function Web browser.
+ \section1 \l{Qt Examples#State Machine}{State Machine}
+
+ Qt provides a powerful hierchical finite state machine through the Qt State
+ Machine classes.
+
+ These examples demonstrate the fundamental aspects of implementing
+ Statecharts with Qt.
+
\section1 \l{Qt Examples#Qt for Embedded Linux}{Qt for Embedded Linux}
\l{Qt Examples#Qt for Embedded Linux}{\inlineimage qt-embedded-examples.png
diff --git a/doc/src/examples.qdoc b/doc/src/examples.qdoc
index 29c6c0b..c55d29f 100644
--- a/doc/src/examples.qdoc
+++ b/doc/src/examples.qdoc
@@ -86,6 +86,12 @@
\o \l{activeqt/webbrowser}{Web Browser}\raisedaster
\o \l{activeqt/wrapper}{Wrapper}\raisedaster
\endlist
+
+ \section1 Animation
+
+ \list
+ \o \l{animation/stickman}{Stick man}\raisedaster
+ \endlist
\section1 Concurrent Programming
@@ -308,6 +314,17 @@
\o \l{sql/sqlwidgetmapper}{SQL Widget Mapper}\raisedaster
\endlist
+ \section1 State Machine
+
+ \list
+ \o \l{statemachine/eventtransitions}{Event Transitions}\raisedaster
+ \o \l{statemachine/factorial}{Factorial States}\raisedaster
+ \o \l{statemachine/pingpong}{Ping Pong States}\raisedaster
+ \o \l{statemachine/trafficlight}{Traffic Light}\raisedaster
+ \o \l{statemachine/twowaybutton}{Two-way Button}\raisedaster
+ \o \l{statemachine/tankgame}{Tank Game}\raisedaster
+ \endlist
+
\section1 Threads
\list
diff --git a/doc/src/examples/eventtransitions.qdoc b/doc/src/examples/eventtransitions.qdoc
new file mode 100644
index 0000000..3b956bb
--- /dev/null
+++ b/doc/src/examples/eventtransitions.qdoc
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example statemachine/eventtransitions
+ \title Event Transitions Example
+
+ The Event Transitions example shows how to use event transitions, a
+ feature of \l{The State Machine Framework}.
+
+ \snippet examples/statemachine/eventtransitions/main.cpp 0
+
+ The \c Window class's constructors begins by creating a button.
+
+ \snippet examples/statemachine/eventtransitions/main.cpp 1
+
+ Two states, \c s1 and \c s2, are created; upon entry they will assign
+ "Outside" and "Inside" to the button's text, respectively.
+
+ \snippet examples/statemachine/eventtransitions/main.cpp 2
+
+ When the button receives an event of type QEvent::Enter and the state
+ machine is in state \c s1, the machine will transition to state \c s2.
+
+ \snippet examples/statemachine/eventtransitions/main.cpp 3
+
+ When the button receives an event of type QEvent::Leave and the state
+ machine is in state \c s2, the machine will transition back to state \c
+ s1.
+
+ \snippet examples/statemachine/eventtransitions/main.cpp 4
+
+ Next, the state \c s3 is created. \c s3 will be entered when the button
+ receives an event of type QEvent::MouseButtonPress and the state machine
+ is in state \c s2. When the button receives an event of type
+ QEvent::MouseButtonRelease and the state machine is in state \c s3, the
+ machine will transition back to state \c s2.
+
+ \snippet examples/statemachine/eventtransitions/main.cpp 5
+
+ Finally, the states are added to the machine as top-level states, the
+ initial state is set to be \c s1 ("Outside"), and the machine is started.
+
+ \snippet examples/statemachine/eventtransitions/main.cpp 6
+
+ The main() function constructs a Window object and shows it.
+
+*/
diff --git a/doc/src/examples/factorial.qdoc b/doc/src/examples/factorial.qdoc
new file mode 100644
index 0000000..2a72e0a
--- /dev/null
+++ b/doc/src/examples/factorial.qdoc
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example statemachine/factorial
+ \title Factorial States Example
+
+ The Factorial States example shows how to use \l{The State Machine
+ Framework} to calculate the factorial of an integer.
+
+ The statechart for calculating the factorial looks as follows:
+
+ \img factorial-example.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ In other words, the state machine calculates the factorial of 6 and prints
+ the result.
+
+ \snippet examples/statemachine/factorial/main.cpp 0
+
+ The Factorial class is used to hold the data of the computation, \c x and
+ \c fac. It also provides a signal that's emitted whenever the value of \c
+ x changes.
+
+ \snippet examples/statemachine/factorial/main.cpp 1
+
+ The FactorialLoopTransition class implements the guard (\c x > 1) and
+ calculations (\c fac = \c x * \c fac; \c x = \c x - 1) of the factorial
+ loop.
+
+ \snippet examples/statemachine/factorial/main.cpp 2
+
+ The FactorialDoneTransition class implements the guard (\c x <= 1) that
+ terminates the factorial computation. It also prints the final result to
+ standard output.
+
+ \snippet examples/statemachine/factorial/main.cpp 3
+
+ The application's main() function first creates the application object, a
+ Factorial object and a state machine.
+
+ \snippet examples/statemachine/factorial/main.cpp 4
+
+ The \c compute state is created, and the initial values of \c x and \c fac
+ are defined. A FactorialLoopTransition object is created and added to the
+ state.
+
+ \snippet examples/statemachine/factorial/main.cpp 5
+
+ A final state, \c done, is created, and a FactorialDoneTransition object
+ is created with \c done as its target state. The transition is then added
+ to the \c compute state.
+
+ \snippet examples/statemachine/factorial/main.cpp 6
+
+ The machine's initial state is set to be the \c compute state. We connect
+ the QStateMachine::finished() signal to the QCoreApplication::quit() slot,
+ so the application will quit when the state machine's work is
+ done. Finally, the state machine is started, and the application's event
+ loop is entered.
+
+ */
diff --git a/doc/src/examples/pingpong.qdoc b/doc/src/examples/pingpong.qdoc
new file mode 100644
index 0000000..040e429
--- /dev/null
+++ b/doc/src/examples/pingpong.qdoc
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example statemachine/pingpong
+ \title Ping Pong States Example
+
+ The Ping Pong States example shows how to use parallel states together
+ with custom events and transitions in \l{The State Machine Framework}.
+
+ This example implements a statechart where two states communicate by
+ posting events to the state machine. The state chart looks as follows:
+
+ \img pingpong-example.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ The \c pinger and \c ponger states are parallel states, i.e. they are
+ entered simultaneously and will take transitions independently of
+ eachother.
+
+ The \c pinger state will post the first \c ping event upon entry; the \c
+ ponger state will respond by posting a \c pong event; this will cause the
+ \c pinger state to post a new \c ping event; and so on.
+
+ \snippet examples/statemachine/pingpong/main.cpp 0
+
+ Two custom events are defined, \c PingEvent and \c PongEvent.
+
+ \snippet examples/statemachine/pingpong/main.cpp 1
+
+ The \c Pinger class defines a state that posts a \c PingEvent to the state
+ machine when the state is entered.
+
+ \snippet examples/statemachine/pingpong/main.cpp 2
+
+ The \c PingTransition class defines a transition that is triggered by
+ events of type \c PingEvent, and that posts a \c PongEvent (with a delay
+ of 500 milliseconds) to the state machine when the transition is
+ triggered.
+
+ \snippet examples/statemachine/pingpong/main.cpp 3
+
+ The \c PongTransition class defines a transition that is triggered by
+ events of type \c PongEvent, and that posts a \c PingEvent (with a delay
+ of 500 milliseconds) to the state machine when the transition is
+ triggered.
+
+ \snippet examples/statemachine/pingpong/main.cpp 4
+
+ The main() function begins by creating a state machine and a parallel
+ state group.
+
+ \snippet examples/statemachine/pingpong/main.cpp 5
+
+ Next, the \c pinger and \c ponger states are created, with the parallel
+ state group as their parent state. Note that the transitions are \e
+ targetless. When such a transition is triggered, the source state won't be
+ exited and re-entered; only the transition's onTransition() function will
+ be called, and the state machine's configuration will remain the same,
+ which is precisely what we want in this case.
+
+ \snippet examples/statemachine/pingpong/main.cpp 6
+
+ Finally, the group is added to the state machine, the machine is started,
+ and the application event loop is entered.
+
+ */
diff --git a/doc/src/examples/stickman.qdoc b/doc/src/examples/stickman.qdoc
new file mode 100644
index 0000000..49f4953
--- /dev/null
+++ b/doc/src/examples/stickman.qdoc
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example animation/stickman
+ \title Stickman Example
+
+ The Stickman example shows how to animate transitions in a state machine to implement key frame
+ animations.
+
+ \image stickman-example.png
+
+ In this example, we will write a small application which animates the joints in a skeleton and
+ projects a stickman figure on top. The stickman can be either "alive" or "dead", and when in the
+ "alive" state, he can be performing different actions defined by key frame animations.
+
+ Animations are implemented as composite states. Each child state of the animation state
+ represents a frame in the animation by setting the position of each joint in the stickman's
+ skeleton to the positions defined for the particular frame. The frames are then bound together
+ with animated transitions that trigger on the source state's polished() signal. Thus, the
+ machine will enter the state representing the next frame in the animation immediately after it
+ has finished animating into the previous frame.
+
+ \image stickman-example1.png
+
+ The states for an animation is constructed by reading a custom animation file format and
+ creating states that assign values to the the "position" properties of each of the nodes in the
+ skeleton graph.
+
+ \snippet examples/animation/stickman/lifecycle.cpp 1
+
+ The states are then bound together with signal transitions that listen to the polished() signal.
+
+ \snippet examples/animation/stickman/lifecycle.cpp 2
+
+ The last frame state is given a transition to the first one, so that the animation will loop
+ until it is interrupted when a transition out from the animation state is taken. To get smooth
+ animations between the different key frames, we set a default animation on the state machine.
+ This is a parallel animation group which contains animations for all the "position" properties
+ and will be selected by default when taking any transition that leads into a state that assigns
+ values to these properties.
+
+ \snippet examples/animation/stickman/lifecycle.cpp 3
+
+ Several such animation states are constructed, and are placed together as children of a top
+ level "alive" state which represents the stickman life cycle. Transitions go from the parent
+ state to the child state to ensure that each of the child states inherit them.
+
+ \image stickman-example2.png
+
+ This saves us the effort of connect every state to every state with identical transitions. The
+ state machine makes sure that transitions between the key frame animations are also smooth by
+ applying the default animation when interrupting one and starting another.
+
+ Finally, there is a transition out from the "alive" state and into the "dead" state. This is
+ a custom transition type called LightningSrikesTransition which samples every second and
+ triggers at random (one out of fifty times on average.)
+
+ \snippet examples/animation/stickman/lifecycle.cpp 4
+
+ When it triggers, the machine will first enter a "lightningBlink" state which uses a timer to
+ pause for a brief period of time while the background color of the scene is white. This gives us
+ a flash effect when the lightning strikes.
+
+ \snippet examples/animation/stickman/lifecycle.cpp 5
+
+ We start and stop a QTimer object when entering and exiting the state. Then we transition into
+ the "dead" state when the timer times out.
+
+ \snippet examples/animation/stickman/lifecycle.cpp 0
+
+ When the machine is in the "dead" state, it will be unresponsive. This is because the "dead"
+ state has no transitions leading out.
+
+ \image stickman-example3.png
+
+*/
diff --git a/doc/src/examples/tankgame.qdoc b/doc/src/examples/tankgame.qdoc
new file mode 100644
index 0000000..ab3e0f4
--- /dev/null
+++ b/doc/src/examples/tankgame.qdoc
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example statemachine/tankgame
+ \title Tank Game Example
+
+ The Tank Game example is part of the in \l{The State Machine Framework}. It shows how to use
+ parallel states to implement artificial intelligence controllers that run in parallel, and error
+ states to handle run-time errors in parts of the state graph created by external plugins.
+
+ \image tankgame-example.png
+
+ In this example we write a simple game. The application runs a state machine with two main
+ states: A "stopped" state and a "running" state. The user can load plugins from the disk by
+ selecting the "Add tank" menu item.
+
+ When the "Add tank" menu item is selected, the "plugins" subdirectory in the example's
+ directory is searched for compatible plugins. If any are found, they will be listed in a
+ dialog box created using QInputDialog::getItem().
+
+ \snippet examples/statemachine/tankgame/mainwindow.cpp 1
+
+ If the user selects a plugin, the application will construct a TankItem object, which inherits
+ from QGraphicsItem and QObject, and which implements an agreed-upon interface using the
+ meta-object mechanism.
+
+ \snippet examples/statemachine/tankgame/tankitem.h 0
+
+ The tank item will be passed to the plugin's create() function. This will in turn return a
+ QState object which is expected to implement an artificial intelligence which controls the
+ tank and attempts to destroy other tanks it detects.
+
+ \snippet examples/statemachine/tankgame/mainwindow.cpp 2
+
+ Each returned QState object becomes a descendant of a \c region in the "running" state, which is
+ defined as a parallel state. This means that entering the "running" state will cause each of the
+ plugged-in QState objects to be entered simultaneously, allowing the tanks to run independently
+ of each other.
+
+ \snippet examples/statemachine/tankgame/mainwindow.cpp 0
+
+ The maximum number of tanks on the map is four, and when this number is reached, the
+ "Add tank" menu item should be disabled. This is implemented by giving the "stopped" state two
+ children which define whether the map is full or not.
+
+ \snippet examples/statemachine/tankgame/mainwindow.cpp 5
+
+ To make sure that we go into the correct child state when returning from the "running" state
+ (if the "Stop game" menu item is selected while the game is running) we also give the "stopped"
+ state a history state which we make the initial state of "stopped" state.
+
+ \snippet examples/statemachine/tankgame/mainwindow.cpp 3
+
+ Since part of the state graph is defined by external plugins, we have no way of controlling
+ whether they contain errors. By default, run-time errors are handled in the state machine by
+ entering a top level state which prints out an error message and never exits. If we were to
+ use this default behavior, a run-time error in any of the plugins would cause the "running"
+ state to exit, and thus all the other tanks to stop running as well. A better solution would
+ be if the broken plugin was disabled and the rest of the tanks allowed to continue as before.
+
+ This is done by setting the error state of the plugin's top-most state to a special error state
+ defined specifically for the plugin in question.
+
+ \snippet examples/statemachine/tankgame/mainwindow.cpp 4
+
+ If a run-time error occurs in \c pluginState or any of its descendants, the state machine will
+ search the hierarchy of ancestors until it finds a state whose error state is different from
+ \c null. (Note that if we are worried that a plugin could inadvertedly be overriding our
+ error state, we could search the descendants of \c pluginState and verify that their error
+ states are set to \c null before accepting the plugin.)
+
+ The specialized \c errorState sets the "enabled" property of the tank item in question to false,
+ causing it to be painted with a red cross over it to indicate that it is no longer running.
+ Since the error state is a child of the same region in the parallel "running" state as
+ \c pluginState, it will not exit the "running" state, and the other tanks will continue running
+ without disruption.
+
+*/
diff --git a/doc/src/examples/trafficlight.qdoc b/doc/src/examples/trafficlight.qdoc
new file mode 100644
index 0000000..ae62127
--- /dev/null
+++ b/doc/src/examples/trafficlight.qdoc
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example statemachine/trafficlight
+ \title Traffic Light Example
+
+ The Traffic Light example shows how to use \l{The State Machine Framework}
+ to implement the control flow of a traffic light.
+
+ \image trafficlight-example.png
+
+ In this example we write a TrafficLightWidget class. The traffic light has
+ three lights: Red, yellow and green. The traffic light transitions from
+ one light to another (red to yellow to green to yellow to red again) at
+ certain intervals.
+
+ \snippet examples/statemachine/trafficlight/main.cpp 0
+
+ The LightWidget class represents a single light of the traffic light. It
+ provides an \c on property and two slots, turnOn() and turnOff(), to turn
+ the light on and off, respectively. The widget paints itself in the color
+ that's passed to the constructor.
+
+ \snippet examples/statemachine/trafficlight/main.cpp 1
+
+ The TrafficLightWidget class represents the visual part of the traffic
+ light; it's a widget that contains three lights arranged vertically, and
+ provides accessor functions for these.
+
+ \snippet examples/statemachine/trafficlight/main.cpp 2
+
+ The createLightState() function creates a state that turns a light on when
+ the state is entered, and off when the state is exited. The state uses a
+ timer, and as we shall see the timeout is used to transition from one
+ LightState to another. Here is the statechart for the light state:
+
+ \img trafficlight-example1.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ \snippet examples/statemachine/trafficlight/main.cpp 3
+
+ The TrafficLight class combines the TrafficLightWidget with a state
+ machine. The state graph has four states: red-to-yellow, yellow-to-green,
+ green-to-yellow and yellow-to-red. The initial state is red-to-yellow;
+ when the state's timer times out, the state machine transitions to
+ yellow-to-green. The same process repeats through the other states.
+ This is what the statechart looks like:
+
+ \img trafficlight-example2.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ \snippet examples/statemachine/trafficlight/main.cpp 4
+
+ The main() function constructs a TrafficLight and shows it.
+
+*/
diff --git a/doc/src/examples/twowaybutton.qdoc b/doc/src/examples/twowaybutton.qdoc
new file mode 100644
index 0000000..87de2e8
--- /dev/null
+++ b/doc/src/examples/twowaybutton.qdoc
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example statemachine/twowaybutton
+ \title Two-way Button Example
+
+ The Two-way button example shows how to use \l{The State Machine
+ Framework} to implement a simple state machine that toggles the current
+ state when a button is clicked.
+
+ \snippet examples/statemachine/twowaybutton/main.cpp 0
+
+ The application's main() function begins by constructing the application
+ object, a button and a state machine.
+
+ \snippet examples/statemachine/twowaybutton/main.cpp 1
+
+ The state machine has two states; \c on and \c off. When either state is
+ entered, the text of the button will be set accordingly.
+
+ \snippet examples/statemachine/twowaybutton/main.cpp 2
+
+ When the state machine is in the \c off state and the button is clicked,
+ it will transition to the \c on state; when the state machine is in the \c
+ on state and the button is clicked, it will transition to the \c off
+ state.
+
+ \snippet examples/statemachine/twowaybutton/main.cpp 3
+
+ The states are added to the state machine; they become top-level (sibling)
+ states.
+
+ \snippet examples/statemachine/twowaybutton/main.cpp 4
+
+ The initial state is \c off; this is the state the state machine will
+ immediately transition to once the state machine is started.
+
+ \snippet examples/statemachine/twowaybutton/main.cpp 5
+
+ Finally, the button is resized and made visible, and the application event
+ loop is entered.
+
+*/
diff --git a/doc/src/external-resources.qdoc b/doc/src/external-resources.qdoc
index f48c3d7..3bfb5af 100644
--- a/doc/src/external-resources.qdoc
+++ b/doc/src/external-resources.qdoc
@@ -334,6 +334,16 @@
*/
/*!
+ \externalpage http://www.w3.org/TR/scxml/
+ \title State Chart XML: State Machine Notation for Control Abstraction
+*/
+
+/*!
+ \externalpage http://www.wisdom.weizmann.ac.il/~dharel/SCANNED.PAPERS/Statecharts.pdf
+ \title Statecharts: A visual formalism for complex systems
+*/
+
+/*!
\externalpage http://www.gnu.org/licenses/gpl.html
\title GNU General Public License
*/
diff --git a/doc/src/groups.qdoc b/doc/src/groups.qdoc
index c9cedc4..3c4da53 100644
--- a/doc/src/groups.qdoc
+++ b/doc/src/groups.qdoc
@@ -69,6 +69,18 @@
*/
/*!
+ \group animation
+ \ingroup groups
+
+ \title Animation Framework
+ \brief Classes for animations, states and transitions.
+
+ These classes provide a framework for creating both simple and complex
+ animations. \l{The Animation Framework} also provides states and animated
+ transitions, making it easy to create animated stateful forms.
+*/
+
+/*!
\group abstractwidgets
\title Abstract Widget Classes
\ingroup groups
@@ -597,3 +609,14 @@
These classes are relevant to developers who are working with Qt Script's
debugging features.
*/
+
+/*!
+ \group statemachine
+ \ingroup groups
+
+ \title State Machine Classes
+ \brief Classes for constructing and executing state graphs.
+
+ These classes are provided by \l{The State Machine Framework} for creating
+ event-driven state machines.
+*/
diff --git a/doc/src/images/animations-architecture.png b/doc/src/images/animations-architecture.png
new file mode 100644
index 0000000..9b581af
--- /dev/null
+++ b/doc/src/images/animations-architecture.png
Binary files differ
diff --git a/doc/src/images/factorial-example.png b/doc/src/images/factorial-example.png
new file mode 100644
index 0000000..8fb1cc6
--- /dev/null
+++ b/doc/src/images/factorial-example.png
Binary files differ
diff --git a/doc/src/images/inputdialogs.png b/doc/src/images/inputdialogs.png
index 135c2f6..8bda185 100644
--- a/doc/src/images/inputdialogs.png
+++ b/doc/src/images/inputdialogs.png
Binary files differ
diff --git a/doc/src/images/pingpong-example.png b/doc/src/images/pingpong-example.png
new file mode 100644
index 0000000..af707e4
--- /dev/null
+++ b/doc/src/images/pingpong-example.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-cosinecurve.png b/doc/src/images/qeasingcurve-cosinecurve.png
new file mode 100644
index 0000000..b27e763
--- /dev/null
+++ b/doc/src/images/qeasingcurve-cosinecurve.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inback.png b/doc/src/images/qeasingcurve-inback.png
new file mode 100644
index 0000000..8506c0f
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inback.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inbounce.png b/doc/src/images/qeasingcurve-inbounce.png
new file mode 100644
index 0000000..275b38c
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inbounce.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-incirc.png b/doc/src/images/qeasingcurve-incirc.png
new file mode 100644
index 0000000..b985e9c
--- /dev/null
+++ b/doc/src/images/qeasingcurve-incirc.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-incubic.png b/doc/src/images/qeasingcurve-incubic.png
new file mode 100644
index 0000000..e417ee1
--- /dev/null
+++ b/doc/src/images/qeasingcurve-incubic.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-incurve.png b/doc/src/images/qeasingcurve-incurve.png
new file mode 100644
index 0000000..d9a9340
--- /dev/null
+++ b/doc/src/images/qeasingcurve-incurve.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inelastic.png b/doc/src/images/qeasingcurve-inelastic.png
new file mode 100644
index 0000000..b242fd3
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inelastic.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inexpo.png b/doc/src/images/qeasingcurve-inexpo.png
new file mode 100644
index 0000000..f06316c
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inexpo.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inoutback.png b/doc/src/images/qeasingcurve-inoutback.png
new file mode 100644
index 0000000..9fd1446
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inoutback.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inoutbounce.png b/doc/src/images/qeasingcurve-inoutbounce.png
new file mode 100644
index 0000000..fb65f31
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inoutbounce.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inoutcirc.png b/doc/src/images/qeasingcurve-inoutcirc.png
new file mode 100644
index 0000000..123cc54
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inoutcirc.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inoutcubic.png b/doc/src/images/qeasingcurve-inoutcubic.png
new file mode 100644
index 0000000..b07695c
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inoutcubic.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inoutelastic.png b/doc/src/images/qeasingcurve-inoutelastic.png
new file mode 100644
index 0000000..65851e1
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inoutelastic.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inoutexpo.png b/doc/src/images/qeasingcurve-inoutexpo.png
new file mode 100644
index 0000000..7cbfb13
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inoutexpo.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inoutquad.png b/doc/src/images/qeasingcurve-inoutquad.png
new file mode 100644
index 0000000..c5eed06
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inoutquad.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inoutquart.png b/doc/src/images/qeasingcurve-inoutquart.png
new file mode 100644
index 0000000..3b66c0d
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inoutquart.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inoutquint.png b/doc/src/images/qeasingcurve-inoutquint.png
new file mode 100644
index 0000000..c74efe9
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inoutquint.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inoutsine.png b/doc/src/images/qeasingcurve-inoutsine.png
new file mode 100644
index 0000000..5964f31
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inoutsine.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inquad.png b/doc/src/images/qeasingcurve-inquad.png
new file mode 100644
index 0000000..3373310
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inquad.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inquart.png b/doc/src/images/qeasingcurve-inquart.png
new file mode 100644
index 0000000..28086d8
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inquart.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-inquint.png b/doc/src/images/qeasingcurve-inquint.png
new file mode 100644
index 0000000..330aa85
--- /dev/null
+++ b/doc/src/images/qeasingcurve-inquint.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-insine.png b/doc/src/images/qeasingcurve-insine.png
new file mode 100644
index 0000000..63d9238
--- /dev/null
+++ b/doc/src/images/qeasingcurve-insine.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-linear.png b/doc/src/images/qeasingcurve-linear.png
new file mode 100644
index 0000000..2a05885
--- /dev/null
+++ b/doc/src/images/qeasingcurve-linear.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outback.png b/doc/src/images/qeasingcurve-outback.png
new file mode 100644
index 0000000..7cb34c6
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outback.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outbounce.png b/doc/src/images/qeasingcurve-outbounce.png
new file mode 100644
index 0000000..932fc16
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outbounce.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outcirc.png b/doc/src/images/qeasingcurve-outcirc.png
new file mode 100644
index 0000000..a1a6cb6
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outcirc.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outcubic.png b/doc/src/images/qeasingcurve-outcubic.png
new file mode 100644
index 0000000..aa1d604
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outcubic.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outcurve.png b/doc/src/images/qeasingcurve-outcurve.png
new file mode 100644
index 0000000..a949ae4
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outcurve.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outelastic.png b/doc/src/images/qeasingcurve-outelastic.png
new file mode 100644
index 0000000..2a9ba39
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outelastic.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outexpo.png b/doc/src/images/qeasingcurve-outexpo.png
new file mode 100644
index 0000000..e771c2e
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outexpo.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outinback.png b/doc/src/images/qeasingcurve-outinback.png
new file mode 100644
index 0000000..7523727
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outinback.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outinbounce.png b/doc/src/images/qeasingcurve-outinbounce.png
new file mode 100644
index 0000000..ab73d02
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outinbounce.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outincirc.png b/doc/src/images/qeasingcurve-outincirc.png
new file mode 100644
index 0000000..ec4b8d3
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outincirc.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outincubic.png b/doc/src/images/qeasingcurve-outincubic.png
new file mode 100644
index 0000000..8b8ae68
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outincubic.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outinelastic.png b/doc/src/images/qeasingcurve-outinelastic.png
new file mode 100644
index 0000000..89dde2c
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outinelastic.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outinexpo.png b/doc/src/images/qeasingcurve-outinexpo.png
new file mode 100644
index 0000000..5909901
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outinexpo.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outinquad.png b/doc/src/images/qeasingcurve-outinquad.png
new file mode 100644
index 0000000..7ddefee
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outinquad.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outinquart.png b/doc/src/images/qeasingcurve-outinquart.png
new file mode 100644
index 0000000..00ef597
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outinquart.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outinquint.png b/doc/src/images/qeasingcurve-outinquint.png
new file mode 100644
index 0000000..361bfaa4
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outinquint.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outinsine.png b/doc/src/images/qeasingcurve-outinsine.png
new file mode 100644
index 0000000..1737041
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outinsine.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outquad.png b/doc/src/images/qeasingcurve-outquad.png
new file mode 100644
index 0000000..6f27cbd
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outquad.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outquart.png b/doc/src/images/qeasingcurve-outquart.png
new file mode 100644
index 0000000..d45a0b8
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outquart.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outquint.png b/doc/src/images/qeasingcurve-outquint.png
new file mode 100644
index 0000000..6e7df0e
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outquint.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-outsine.png b/doc/src/images/qeasingcurve-outsine.png
new file mode 100644
index 0000000..7546a0d
--- /dev/null
+++ b/doc/src/images/qeasingcurve-outsine.png
Binary files differ
diff --git a/doc/src/images/qeasingcurve-sinecurve.png b/doc/src/images/qeasingcurve-sinecurve.png
new file mode 100644
index 0000000..ca67d44
--- /dev/null
+++ b/doc/src/images/qeasingcurve-sinecurve.png
Binary files differ
diff --git a/doc/src/images/statemachine-button-history.png b/doc/src/images/statemachine-button-history.png
new file mode 100644
index 0000000..7f51cae
--- /dev/null
+++ b/doc/src/images/statemachine-button-history.png
Binary files differ
diff --git a/doc/src/images/statemachine-button-nested.png b/doc/src/images/statemachine-button-nested.png
new file mode 100644
index 0000000..762ac14
--- /dev/null
+++ b/doc/src/images/statemachine-button-nested.png
Binary files differ
diff --git a/doc/src/images/statemachine-button.png b/doc/src/images/statemachine-button.png
new file mode 100644
index 0000000..10102bd
--- /dev/null
+++ b/doc/src/images/statemachine-button.png
Binary files differ
diff --git a/doc/src/images/statemachine-customevents.png b/doc/src/images/statemachine-customevents.png
new file mode 100644
index 0000000..62a4222
--- /dev/null
+++ b/doc/src/images/statemachine-customevents.png
Binary files differ
diff --git a/doc/src/images/statemachine-customevents2.png b/doc/src/images/statemachine-customevents2.png
new file mode 100644
index 0000000..57b37ef
--- /dev/null
+++ b/doc/src/images/statemachine-customevents2.png
Binary files differ
diff --git a/doc/src/images/statemachine-finished.png b/doc/src/images/statemachine-finished.png
new file mode 100644
index 0000000..0ac081d
--- /dev/null
+++ b/doc/src/images/statemachine-finished.png
Binary files differ
diff --git a/doc/src/images/statemachine-nonparallel.png b/doc/src/images/statemachine-nonparallel.png
new file mode 100644
index 0000000..f9850a7
--- /dev/null
+++ b/doc/src/images/statemachine-nonparallel.png
Binary files differ
diff --git a/doc/src/images/statemachine-parallel.png b/doc/src/images/statemachine-parallel.png
new file mode 100644
index 0000000..a65c297
--- /dev/null
+++ b/doc/src/images/statemachine-parallel.png
Binary files differ
diff --git a/doc/src/images/stickman-example.png b/doc/src/images/stickman-example.png
new file mode 100644
index 0000000..a40f37b
--- /dev/null
+++ b/doc/src/images/stickman-example.png
Binary files differ
diff --git a/doc/src/images/stickman-example1.png b/doc/src/images/stickman-example1.png
new file mode 100644
index 0000000..1596a68
--- /dev/null
+++ b/doc/src/images/stickman-example1.png
Binary files differ
diff --git a/doc/src/images/stickman-example2.png b/doc/src/images/stickman-example2.png
new file mode 100644
index 0000000..980276a
--- /dev/null
+++ b/doc/src/images/stickman-example2.png
Binary files differ
diff --git a/doc/src/images/stickman-example3.png b/doc/src/images/stickman-example3.png
new file mode 100644
index 0000000..3635ff7
--- /dev/null
+++ b/doc/src/images/stickman-example3.png
Binary files differ
diff --git a/doc/src/images/tankgame-example.png b/doc/src/images/tankgame-example.png
new file mode 100644
index 0000000..9e17e30
--- /dev/null
+++ b/doc/src/images/tankgame-example.png
Binary files differ
diff --git a/doc/src/images/trafficlight-example.png b/doc/src/images/trafficlight-example.png
new file mode 100644
index 0000000..3431542
--- /dev/null
+++ b/doc/src/images/trafficlight-example.png
Binary files differ
diff --git a/doc/src/images/trafficlight-example1.png b/doc/src/images/trafficlight-example1.png
new file mode 100644
index 0000000..ec8c7ff
--- /dev/null
+++ b/doc/src/images/trafficlight-example1.png
Binary files differ
diff --git a/doc/src/images/trafficlight-example2.png b/doc/src/images/trafficlight-example2.png
new file mode 100644
index 0000000..a12e4db
--- /dev/null
+++ b/doc/src/images/trafficlight-example2.png
Binary files differ
diff --git a/doc/src/snippets/animation/sequential/icons.qrc b/doc/src/snippets/animation/sequential/icons.qrc
new file mode 100644
index 0000000..d55f797
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/icons.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>icons/left.png</file>
+ <file>icons/right.png</file>
+ </qresource>
+</RCC>
diff --git a/doc/src/snippets/animation/sequential/icons/left.png b/doc/src/snippets/animation/sequential/icons/left.png
new file mode 100644
index 0000000..5dd8da0
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/icons/left.png
Binary files differ
diff --git a/doc/src/snippets/animation/sequential/icons/right.png b/doc/src/snippets/animation/sequential/icons/right.png
new file mode 100644
index 0000000..ac61326
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/icons/right.png
Binary files differ
diff --git a/doc/src/snippets/animation/sequential/main.cpp b/doc/src/snippets/animation/sequential/main.cpp
new file mode 100644
index 0000000..aff8f29
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/main.cpp
@@ -0,0 +1,50 @@
+#include <QApplication>
+#include <QLabel>
+#include <QPropertyAnimation>
+#include <QSequentialAnimationGroup>
+#include "tracer.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QWidget window;
+ window.resize(720, 96);
+ window.show();
+
+ QLabel *label1 = new QLabel(&window);
+ label1->setPixmap(QPixmap(":/icons/left.png"));
+ label1->move(16, 16);
+ label1->show();
+
+ QLabel *label2 = new QLabel(&window);
+ label2->setPixmap(QPixmap(":/icons/right.png"));
+ label2->move(320, 16);
+ label2->show();
+
+ QPropertyAnimation *anim1 = new QPropertyAnimation(label1, "pos");
+ anim1->setDuration(2500);
+ anim1->setStartValue(QPoint(16, 16));
+ anim1->setEndValue(QPoint(320, 16));
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(label2, "pos");
+ anim2->setDuration(2500);
+ anim2->setStartValue(QPoint(320, 16));
+ anim2->setEndValue(QPoint(640, 16));
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(anim1);
+ group.addAnimation(anim2);
+
+ Tracer tracer(&window);
+
+ QObject::connect(anim1, SIGNAL(valueChanged(QVariant)),
+ &tracer, SLOT(recordValue(QVariant)));
+ QObject::connect(anim2, SIGNAL(valueChanged(QVariant)),
+ &tracer, SLOT(recordValue(QVariant)));
+ QObject::connect(anim1, SIGNAL(finished()), &tracer, SLOT(checkValue()));
+ QObject::connect(anim2, SIGNAL(finished()), &tracer, SLOT(checkValue()));
+
+ group.start();
+ return app.exec();
+}
diff --git a/doc/src/snippets/animation/sequential/sequential.pro b/doc/src/snippets/animation/sequential/sequential.pro
new file mode 100644
index 0000000..fcf017f
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/sequential.pro
@@ -0,0 +1,4 @@
+HEADERS = tracer.h
+RESOURCES = icons.qrc
+SOURCES = main.cpp \
+ tracer.cpp
diff --git a/doc/src/snippets/animation/sequential/tracer.cpp b/doc/src/snippets/animation/sequential/tracer.cpp
new file mode 100644
index 0000000..49bd51e
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/tracer.cpp
@@ -0,0 +1,25 @@
+#include <QAbstractAnimation>
+#include <QDebug>
+#include <QPoint>
+#include "tracer.h"
+
+Tracer::Tracer(QObject *parent)
+ : QObject(parent)
+{
+}
+
+void Tracer::checkValue()
+{
+ QAbstractAnimation *animation = static_cast<QAbstractAnimation *>(sender());
+ if (time != animation->duration()) {
+ qDebug() << "Animation's last recorded time" << time;
+ qDebug() << "Expected" << animation->duration();
+ }
+}
+
+void Tracer::recordValue(const QVariant &value)
+{
+ QAbstractAnimation *animation = static_cast<QAbstractAnimation *>(sender());
+ this->value = value;
+ time = animation->currentTime();
+}
diff --git a/doc/src/snippets/animation/sequential/tracer.h b/doc/src/snippets/animation/sequential/tracer.h
new file mode 100644
index 0000000..1adb018
--- /dev/null
+++ b/doc/src/snippets/animation/sequential/tracer.h
@@ -0,0 +1,23 @@
+#ifndef TRACER_H
+#define TRACER_H
+
+#include <QObject>
+#include <QVariant>
+
+class Tracer : public QObject
+{
+ Q_OBJECT
+
+public:
+ Tracer(QObject *parent = 0);
+
+public slots:
+ void checkValue();
+ void recordValue(const QVariant &value);
+
+private:
+ QVariant value;
+ int time;
+};
+
+#endif
diff --git a/doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp b/doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp
new file mode 100644
index 0000000..65358ea
--- /dev/null
+++ b/doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp
@@ -0,0 +1,4 @@
+//! [0]
+qreal myEasingFunction(qreal progress);
+//! [0]
+
diff --git a/doc/src/statemachine.qdoc b/doc/src/statemachine.qdoc
new file mode 100644
index 0000000..5a89f4d
--- /dev/null
+++ b/doc/src/statemachine.qdoc
@@ -0,0 +1,645 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \page statemachine-api.html
+ \title The State Machine Framework
+ \brief An overview of the State Machine framework for constructing and executing state graphs.
+ \ingroup architecture
+
+ \tableofcontents
+
+ The State Machine framework provides classes for creating and executing
+ state graphs. The concepts and notation are based on those from Harel's
+ \l{Statecharts: A visual formalism for complex systems}{Statecharts}, which
+ is also the basis of UML state diagrams. The semantics of state machine
+ execution are based on \l{State Chart XML: State Machine Notation for
+ Control Abstraction}{State Chart XML (SCXML)}.
+
+ Statecharts provide a graphical way of modeling how a system reacts to
+ stimuli. This is done by defining the possible \e states that the system can
+ be in, and how the system can move from one state to another (\e transitions
+ between states). A key characteristic of event-driven systems (such as Qt
+ applications) is that behavior often depends not only on the last or current
+ event, but also the events that preceded it. With statecharts, this
+ information is easy to express.
+
+ The State Machine framework provides an API and execution model that can be
+ used to effectively embed the elements and semantics of statecharts in Qt
+ applications. The framework integrates tightly with Qt's meta-object system;
+ for example, transitions between states can be triggered by signals, and
+ states can be configured to set properties and invoke methods on QObjects.
+ Qt's event system is used to drive the state machines.
+
+ \section1 A Simple State Machine
+
+ To demonstrate the core functionality of the State Machine API, let's look
+ at a small example: A state machine with three states, \c s1, \c s2 and \c
+ s3. The state machine is controlled by a single QPushButton; when the button
+ is clicked, the machine transitions to another state. Initially, the state
+ machine is in state \c s1. The statechart for this machine is as follows:
+
+ \img statemachine-button.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ The following snippet shows the code needed to create such a state machine.
+ First, we create the state machine and states:
+
+ \code
+ QStateMachine machine;
+ QState *s1 = new QState();
+ QState *s2 = new QState();
+ QState *s3 = new QState();
+ \endcode
+
+ Then, we create the transitions by using the QState::addTransition()
+ function:
+
+ \code
+ s1->addTransition(button, SIGNAL(clicked()), s2);
+ s2->addTransition(button, SIGNAL(clicked()), s3);
+ s3->addTransition(button, SIGNAL(clicked()), s1);
+ \endcode
+
+ Next, we add the states to the machine and set the machine's initial state:
+
+ \code
+ machine.addState(s1);
+ machine.addState(s2);
+ machine.addState(s3);
+ machine.setInitialState(s1);
+ \endcode
+
+ Finally, we start the state machine:
+
+ \code
+ machine.start();
+ \endcode
+
+ The state machine executes asynchronously, i.e. it becomes part of your
+ application's event loop.
+
+ \section1 Doing Useful Work on State Entry and Exit
+
+ The above state machine merely transitions from one state to another, it
+ doesn't perform any operations. The QState::assignProperty() function can be
+ used to have a state set a property of a QObject when the state is
+ entered. In the following snippet, the value that should be assigned to a
+ QLabel's text property is specified for each state:
+
+ \code
+ s1->assignProperty(label, "text", "In state s1");
+ s2->assignProperty(label, "text", "In state s2");
+ s3->assignProperty(label, "text", "In state s3");
+ \endcode
+
+ When any of the states is entered, the label's text will be changed
+ accordingly.
+
+ The QState::entered() signal is emitted when the state is entered, and the
+ QState::exited() signal is emitted when the state is exited. In the
+ following snippet, the button's showMaximized() slot will be called when
+ state \c s3 is entered, and the button's showMinimized() slot will be called
+ when \c s3 is exited:
+
+ \code
+ QObject::connect(s3, SIGNAL(entered()), button, SLOT(showMaximized()));
+ QObject::connect(s3, SIGNAL(exited()), button, SLOT(showMinimized()));
+ \endcode
+
+ Custom states can reimplement QAbstractState::onEntry() and
+ QAbstractState::onExit().
+
+ \section1 State Machines That Finish
+
+ The state machine defined in the previous section never finishes. In order
+ for a state machine to be able to finish, it needs to have a top-level \e
+ final state (QFinalState object). When the state machine enters a top-level
+ final state, the machine will emit the QStateMachine::finished() signal and
+ halt.
+
+ All you need to do to introduce a final state in the graph is create a
+ QFinalState object and use it as the target of one or more transitions.
+
+ \section1 Sharing Transitions By Grouping States
+
+ Assume we wanted the user to be able to quit the application at any time by
+ clicking a Quit button. In order to achieve this, we need to create a final
+ state and make it the target of a transition associated with the Quit
+ button's clicked() signal. We could add a transition from each of \c s1, \c
+ s2 and \c s3; however, this seems redundant, and one would also have to
+ remember to add such a transition from every new state that is added in the
+ future.
+
+ We can achieve the same behavior (namely that clicking the Quit button quits
+ the state machine, regardless of which state the state machine is in) by
+ grouping states \c s1, \c s2 and \c s3. This is done by creating a new
+ top-level state and making the three original states children of the new
+ state. The following diagram shows the new state machine.
+
+ \img statemachine-button-nested.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ The three original states have been renamed \c s11, \c s12 and \c s13 to
+ reflect that they are now children of the new top-level state, \c s1. Child
+ states implicitly inherit the transitions of their parent state. This means
+ it is now sufficient to add a single transition from \c s1 to the final
+ state \c s2. New states added to \c s1 will also automatically inherit this
+ transition.
+
+ All that's needed to group states is to specify the proper parent when the
+ state is created. You also need to specify which of the child states is the
+ initial one (i.e. which child state the state machine should enter when the
+ parent state is the target of a transition).
+
+ \code
+ QState *s1 = new QState();
+ QState *s11 = new QState(s1);
+ QState *s12 = new QState(s1);
+ QState *s13 = new QState(s1);
+ s1->setInitialState(s11);
+ machine.addState(s1);
+ \endcode
+
+ \code
+ QFinalState *s2 = new QFinalState();
+ s1->addTransition(quitButton, SIGNAL(clicked()), s2);
+ machine.addState(s2);
+
+ QObject::connect(&machine, SIGNAL(finished()), QApplication::instance(), SLOT(quit()));
+ \endcode
+
+ In this case we want the application to quit when the state machine is
+ finished, so the machine's finished() signal is connected to the
+ application's quit() slot.
+
+ A child state can override an inherited transition. For example, the
+ following code adds a transition that effectively causes the Quit button to
+ be ignored when the state machine is in state \c s12.
+
+ \code
+ s12>addTransition(quitButton, SIGNAL(clicked()), s12);
+ \endcode
+
+ A transition can have any state as its target, i.e. the target state does
+ not have to be on the same level in the state hierarchy as the source state.
+
+ \section1 Using History States to Save and Restore the Current State
+
+ Imagine that we wanted to add an "interrupt" mechanism to the example
+ discussed in the previous section; the user should be able to click a button
+ to have the state machine perform some non-related task, after which the
+ state machine should resume whatever it was doing before (i.e. return to the
+ old state, which is one of \c s11, \c s12 and \c s13 in this case).
+
+ Such behavior can easily be modeled using \e{history states}. A history
+ state (QHistoryState object) is a pseudo-state that represents the child
+ state that the parent state was in the last time the parent state was
+ exited.
+
+ A history state is created as a child of the state for which we wish to
+ record the current child state; when the state machine detects the presence
+ of such a state at runtime, it automatically records the current (real)
+ child state when the parent state is exited. A transition to the history
+ state is in fact a transition to the child state that the state machine had
+ previously saved; the state machine automatically "forwards" the transition
+ to the real child state.
+
+ The following diagram shows the state machine after the interrupt mechanism
+ has been added.
+
+ \img statemachine-button-history.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ The following code shows how it can be implemented; in this example we
+ simply display a message box when \c s3 is entered, then immediately return
+ to the previous child state of \c s1 via the history state.
+
+ \code
+ QHistoryState *s1h = s1->addHistoryState();
+
+ QState *s3 = new QState();
+ s3->assignProperty(label, "text", "In s3");
+ QMessageBox mbox;
+ mbox.addButton(QMessageBox::Ok);
+ mbox.setText("Interrupted!");
+ mbox.setIcon(QMessageBox::Information);
+ QObject::connect(s3, SIGNAL(entered()), &mbox, SLOT(exec()));
+ s3->addTransition(s1h);
+ machine.addState(s3);
+
+ s1->addTransition(interruptButton, SIGNAL(clicked()), s3);
+ \endcode
+
+ \section1 Using Parallel States to Avoid a Combinatorial Explosion of States
+
+ Assume that you wanted to model a set of mutually exclusive properties of a
+ car in a single state machine. Let's say the properties we are interested in
+ are Clean vs Dirty, and Moving vs Not moving. It would take four mutually
+ exclusive states and eight transitions to be able to represent and freely
+ move between all possible combinations.
+
+ \img statemachine-nonparallel.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ If we added a third property (say, Red vs Blue), the total number of states
+ would double, to eight; and if we added a fourth property (say, Enclosed vs
+ Convertible), the total number of states would double again, to 16.
+
+ Using parallel states, the total number of states and transitions grows
+ linearly as we add more properties, instead of exponentially. Furthermore,
+ states can be added to or removed from the parallel state without affecting
+ any of their sibling states.
+
+ \img statemachine-parallel.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ To create a parallel state group, pass QState::ParallelStates to the QState
+ constructor.
+
+ \code
+ QState *s1 = new QState(QState::ParallelStates);
+ // s11 and s12 will be entered in parallel
+ QState *s11 = new QState(s1);
+ QState *s12 = new QState(s1);
+ \endcode
+
+ When a parallel state group is entered, all its child states will be
+ simultaneously entered. Transitions within the individual child states
+ operate normally. However, any of the child states may take a transition
+ outside the parent state. When this happens, the parent state and all of its
+ child states are exited.
+
+ \section1 Detecting that a Composite State has Finished
+
+ A child state can be final (a QFinalState object); when a final child state
+ is entered, the parent state emits the QState::finished() signal. The
+ following diagram shows a composite state \c s1 which does some processing
+ before entering a final state:
+
+ \img statemachine-finished.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ When \c s1 's final state is entered, \c s1 will automatically emit
+ finished(). We use a signal transition to cause this event to trigger a
+ state change:
+
+ \code
+ s1->addTransition(s1, SIGNAL(finished()), s2);
+ \endcode
+
+ Using final states in composite states is useful when you want to hide the
+ internal details of a composite state; i.e. the only thing the outside world
+ should be able to do is enter the state, and get a notification when the
+ state has completed its work. This is a very powerful abstraction and
+ encapsulation mechanism when building complex (deeply nested) state
+ machines. (In the above example, you could of course create a transition
+ directly from \c s1 's \c done state rather than relying on \c s1 's
+ finished() signal, but with the consequence that implementation details of
+ \c s1 are exposed and depended on).
+
+ For parallel state groups, the QState::finished() signal is emitted when \e
+ all the child states have entered final states.
+
+ \section1 Events, Transitions and Guards
+
+ A QStateMachine runs its own event loop. For signal transitions
+ (QSignalTransition objects), QStateMachine automatically posts a
+ QSignalEvent to itself when it intercepts the corresponding signal;
+ similarly, for QObject event transitions (QEventTransition objects) a
+ QWrappedEvent is posted.
+
+ You can post your own events to the state machine using
+ QStateMachine::postEvent().
+
+ When posting a custom event to the state machine, you typically also have
+ one or more custom transitions that can be triggered from events of that
+ type. To create such a transition, you subclass QAbstractTransition and
+ reimplement QAbstractTransition::eventTest(), where you check if an event
+ matches your event type (and optionally other criteria, e.g. attributes of
+ the event object).
+
+ Here we define our own custom event type, \c StringEvent, for posting
+ strings to the state machine:
+
+ \code
+ struct StringEvent : public QEvent
+ {
+ StringEvent(const QString &val)
+ : QEvent(QEvent::Type(QEvent::User+1)),
+ value(val) {}
+
+ QString value;
+ };
+ \endcode
+
+ Next, we define a transition that only triggers when the event's string
+ matches a particular string (a \e guarded transition):
+
+ \code
+ class StringTransition : public QAbstractTransition
+ {
+ public:
+ StringTransition(const QString &value)
+ : m_value(value) {}
+
+ protected:
+ virtual bool eventTest(QEvent *e) const
+ {
+ if (e->type() != QEvent::Type(QEvent::User+1)) // StringEvent
+ return false;
+ StringEvent *se = static_cast<StringEvent*>(e);
+ return (m_value == se->value);
+ }
+
+ virtual void onTransition(QEvent *) {}
+
+ private:
+ QString m_value;
+ };
+ \endcode
+
+ In the eventTest() reimplementation, we first check if the event type is the
+ desired one; if so, we cast the event to a StringEvent and perform the
+ string comparison.
+
+ The following is a statechart that uses the custom event and transition:
+
+ \img statemachine-customevents.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ Here's what the implementation of the statechart looks like:
+
+ \code
+ QStateMachine machine;
+ QState *s1 = new QState();
+ QState *s2 = new QState();
+ QFinalState *done = new QFinalState();
+
+ StringTransition *t1 = new StringTransition("Hello");
+ t1->setTargetState(s2);
+ s1->addTransition(t1);
+ StringTransition *t2 = new StringTransition("world");
+ t2->setTargetState(done);
+ s2->addTransition(t2);
+
+ machine.addState(s1);
+ machine.addState(s2);
+ machine.addState(done);
+ machine.setInitialState(s1);
+ \endcode
+
+ Once the machine is started, we can post events to it.
+
+ \code
+ machine.postEvent(new StringEvent("Hello"));
+ machine.postEvent(new StringEvent("world"));
+ \endcode
+
+ An event that is not handled by any relevant transition will be silently
+ consumed by the state machine. It can be useful to group states and provide
+ a default handling of such events; for example, as illustrated in the
+ following statechart:
+
+ \img statemachine-customevents2.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ For deeply nested statecharts, you can add such "fallback" transitions at
+ the level of granularity that's most appropriate.
+
+ \section1 Using Restore Policy To Automatically Restore Properties
+
+ In some state machines it can be useful to focus the attention on assigning properties in states,
+ not on restoring them when the state is no longer active. If you know that a property should
+ always be restored to its initial value when the machine enters a state that does not explicitly
+ give the property a value, you can set the global restore policy to
+ QStateMachine::RestoreProperties.
+
+ \code
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+ \endcode
+
+ When this restore policy is set, the machine will automatically restore all properties. If it
+ enters a state where a given property is not set, it will first search the hierarchy of ancestors
+ to see if the property is defined there. If it is, the property will be restored to the value
+ defined by the closest ancestor. If not, it will be restored to its initial value (i.e. the
+ value of the property before any property assignments in states were executed.)
+
+ Take the following code:
+ \code
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QState *s1 = new QState();
+ s1->assignProperty(object, "fooBar", 1.0);
+ machine.addState(s1);
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState();
+ machine.addState(s2);
+ \endcode
+
+ Lets say the property \c fooBar is 0.0 when the machine starts. When the machine is in state
+ \c s1, the property will be 1.0, since the state explicitly assigns this value to it. When the
+ machine is in state \c s2, no value is explicitly defined for the property, so it will implicitly
+ be restored to 0.0.
+
+ If we are using nested states, the parent defines a value for the property which is inherited by
+ all descendants that do not explicitly assign a value to the property.
+ \code
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QState *s1 = new QState();
+ s1->assignProperty(object, "fooBar", 1.0);
+ machine.addState(s1);
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(s1);
+ s2->assignProperty(object, "fooBar", 2.0);
+ s1->setInitialState(s2);
+
+ QState *s3 = new QState(s1);
+ \endcode
+
+ Here \c s1 has two children: \c s2 and \c s3. When \c s2 is entered, the property \c fooBar
+ will have the value 2.0, since this is explicitly defined for the state. When the machine is in
+ state \c s3, no value is defined for the state, but \c s1 defines the property to be 1.0, so this
+ is the value that will be assigned to \c fooBar.
+
+ \section1 Animating Property Assignments
+
+ The State Machine API connects with the Animation API in Qt to allow automatically animating
+ properties as they are assigned in states.
+
+ Say we have the following code:
+ \code
+ QState *s1 = new QState();
+ QState *s2 = new QState();
+
+ s1->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
+ s2->assignProperty(button, "geometry", QRectF(0, 0, 100, 100));
+
+ s1->addTransition(button, SIGNAL(clicked()), s2);
+ \endcode
+
+ Here we define two states of a user interface. In \c s1 the \c button is small, and in \c s2
+ it is bigger. If we click the button to transition from \c s1 to \c s2, the geometry of the button
+ will be set immediately when a given state has been entered. If we want the transition to be
+ smooth, however, all we need to do is make a QPropertyAnimation and add this to the transition
+ object.
+
+ \code
+ QState *s1 = new QState();
+ QState *s2 = new QState();
+
+ s1->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
+ s2->assignProperty(button, "geometry", QRectF(0, 0, 100, 100));
+
+ QSignalTransition *transition = s1->addTransition(button, SIGNAL(clicked()), s2);
+ transition->addAnimation(new QPropertyAnimation(button, "geometry"));
+ \endcode
+
+ Adding an animation for the property in question means that the property assignment will no
+ longer take immediate effect when the state has been entered. Instead, the animation will start
+ playing when the state has been entered and smoothly animate the property assignment. Since we
+ do not set the start value or end value of the animation, these will be set implicitly. The
+ start value of the animation will be the property's current value when the animation starts, and
+ the end value will be set based on the property assignments defined for the state.
+
+ If the global restore policy of the state machine is set to QStateMachine::RestoreProperties,
+ it is possible to also add animations for the property restorations.
+
+ \section1 Detecting That All Properties Have Been Set In A State
+
+ When animations are used to assign properties, a state no longer defines the exact values that a
+ property will have when the machine is in the given state. While the animation is running, the
+ property can potentially have any value, depending on the animation.
+
+ In some cases, it can be useful to be able to detect when the property has actually been assigned
+ the value defined by a state. For this, we can use the state's polished() signal.
+ \code
+ QState *s1 = new QState();
+ s1->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
+
+ QState *s2 = new QState();
+
+ s1->addTransition(s1, SIGNAL(polished()), s2);
+ \endcode
+
+ The machine will be in state \c s1 until the \c geometry property has been set. Then it will
+ immediately transition into \c s2. If the transition into \c s1 has an animation for the \c
+ geometry property, then the machine will stay in \c s1 until the animation has finished. If there
+ is no animation, it will simply set the property and immediately enter state \c s2.
+
+ Either way, when the machine is in state \c s2, the property \c geometry has been assigned the
+ defined value.
+
+ If the global restore policy is set to QStateMachine::RestoreProperties, the state will not emit
+ the polished() signal until these have been executed as well.
+
+ \section1 What happens if a state is exited before the animation has finished
+
+ If a state has property assignments, and the transition into the state has animations for the
+ properties, the state can potentially be exited before the properties have been assigned to the
+ values defines by the state. This is true in particular when there are transitions out from the
+ state that do not depend on the state being polished, as described in the previous section.
+
+ The State Machine API guarantees that a property assigned by the state machine either:
+ \list
+ \o Has a value explicitly assigned to the property.
+ \o Is currently being animated into a value explicitly assigned to the property.
+ \endlist
+
+ When a state is exited prior to the animation finishing, the behavior of the state machine depends
+ on the target state of the transition. If the target state explicitly assigns a value to the
+ property, no additional action will be taken. The property will be assigned the value defined by
+ the target state.
+
+ If the target state does not assign any value to the property, there are two
+ options: By default, the property will be assigned the value defined by the state it is leaving
+ (the value it would have been assigned if the animation had been permitted to finish playing.) If
+ a global restore policy is set, however, this will take precedence, and the property will be
+ restored as usual.
+
+ \section1 Default Animations
+
+ As described earlier, you can add animations to transitions to make sure property assignments
+ in the target state are animated. If you want a specific animation to be used for a given property
+ regardless of which transition is taken, you can add it as a default animation to the state
+ machine. This is in particular useful when the properties assigned (or restored) by specific
+ states is not known when the machine is constructed.
+
+ \code
+ QState *s1 = new QState();
+ QState *s2 = new QState();
+
+ s2->assignProperty(object, "fooBar", 2.0);
+ s1->addTransition(s2);
+
+ QStateMachine machine;
+ machine.setInitialState(s1);
+ machine.addDefaultAnimation(new QPropertyAnimation(object, "fooBar"));
+ \endcode
+
+ When the machine is in state \c s2, the machine will play the default animation for the
+ property \c fooBar since this property is assigned by \c s2.
+
+ Note that animations explicitly set on transitions will take precedence over any default
+ animation for the given property.
+*/
diff --git a/examples/animation/README b/examples/animation/README
new file mode 100644
index 0000000..6a892f8
--- /dev/null
+++ b/examples/animation/README
@@ -0,0 +1,38 @@
+The animation framework aims to provide an easy way for creating animated and
+smooth GUI's. By animating Qt properties, the framework provides great freedom
+for animating widgets and other QObjects. The framework can also be used with
+the Graphics View framework.
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/animation/animatedtiles/animatedtiles.pro b/examples/animation/animatedtiles/animatedtiles.pro
new file mode 100644
index 0000000..1840b17
--- /dev/null
+++ b/examples/animation/animatedtiles/animatedtiles.pro
@@ -0,0 +1,8 @@
+SOURCES = main.cpp
+RESOURCES = animatedtiles.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/animation/animatedtiles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS animatedtiles.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/animation/animatedtiles
+INSTALLS += target sources
diff --git a/examples/animation/animatedtiles/animatedtiles.qrc b/examples/animation/animatedtiles/animatedtiles.qrc
new file mode 100644
index 0000000..c43a979
--- /dev/null
+++ b/examples/animation/animatedtiles/animatedtiles.qrc
@@ -0,0 +1,11 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/Time-For-Lunch-2.jpg</file>
+ <file>images/centered.png</file>
+ <file>images/ellipse.png</file>
+ <file>images/figure8.png</file>
+ <file>images/kinetic.png</file>
+ <file>images/random.png</file>
+ <file>images/tile.png</file>
+</qresource>
+</RCC>
diff --git a/examples/animation/animatedtiles/images/Time-For-Lunch-2.jpg b/examples/animation/animatedtiles/images/Time-For-Lunch-2.jpg
new file mode 100644
index 0000000..c57a555
--- /dev/null
+++ b/examples/animation/animatedtiles/images/Time-For-Lunch-2.jpg
Binary files differ
diff --git a/examples/animation/animatedtiles/images/centered.png b/examples/animation/animatedtiles/images/centered.png
new file mode 100644
index 0000000..e416156
--- /dev/null
+++ b/examples/animation/animatedtiles/images/centered.png
Binary files differ
diff --git a/examples/animation/animatedtiles/images/ellipse.png b/examples/animation/animatedtiles/images/ellipse.png
new file mode 100644
index 0000000..2c3ba88
--- /dev/null
+++ b/examples/animation/animatedtiles/images/ellipse.png
Binary files differ
diff --git a/examples/animation/animatedtiles/images/figure8.png b/examples/animation/animatedtiles/images/figure8.png
new file mode 100644
index 0000000..6b05804
--- /dev/null
+++ b/examples/animation/animatedtiles/images/figure8.png
Binary files differ
diff --git a/examples/animation/animatedtiles/images/kinetic.png b/examples/animation/animatedtiles/images/kinetic.png
new file mode 100644
index 0000000..55cfa55
--- /dev/null
+++ b/examples/animation/animatedtiles/images/kinetic.png
Binary files differ
diff --git a/examples/animation/animatedtiles/images/random.png b/examples/animation/animatedtiles/images/random.png
new file mode 100644
index 0000000..415d96f
--- /dev/null
+++ b/examples/animation/animatedtiles/images/random.png
Binary files differ
diff --git a/examples/animation/animatedtiles/images/tile.png b/examples/animation/animatedtiles/images/tile.png
new file mode 100644
index 0000000..c8f39d8
--- /dev/null
+++ b/examples/animation/animatedtiles/images/tile.png
Binary files differ
diff --git a/examples/animation/animatedtiles/main.cpp b/examples/animation/animatedtiles/main.cpp
new file mode 100644
index 0000000..4b1d99d
--- /dev/null
+++ b/examples/animation/animatedtiles/main.cpp
@@ -0,0 +1,280 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtCore/qstate.h>
+
+class Pixmap : public QObject, public QGraphicsPixmapItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QPointF pos READ pos WRITE setPos)
+public:
+ Pixmap(const QPixmap &pix)
+ : QObject(), QGraphicsPixmapItem(pix)
+ {
+ setCacheMode(DeviceCoordinateCache);
+ }
+};
+
+class Button : public QGraphicsWidget
+{
+ Q_OBJECT
+public:
+ Button(const QPixmap &pixmap, QGraphicsItem *parent = 0)
+ : QGraphicsWidget(parent), _pix(pixmap)
+ {
+ setAcceptHoverEvents(true);
+ setCacheMode(DeviceCoordinateCache);
+ }
+
+ QRectF boundingRect() const
+ {
+ return QRectF(-65, -65, 130, 130);
+ }
+
+ QPainterPath shape() const
+ {
+ QPainterPath path;
+ path.addEllipse(boundingRect());
+ return path;
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
+ {
+ bool down = option->state & QStyle::State_Sunken;
+ QRectF r = boundingRect();
+ QLinearGradient grad(r.topLeft(), r.bottomRight());
+ grad.setColorAt(down ? 1 : 0, option->state & QStyle::State_MouseOver ? Qt::white : Qt::lightGray);
+ grad.setColorAt(down ? 0 : 1, Qt::darkGray);
+ painter->setPen(Qt::darkGray);
+ painter->setBrush(grad);
+ painter->drawEllipse(r);
+ QLinearGradient grad2(r.topLeft(), r.bottomRight());
+ grad.setColorAt(down ? 1 : 0, Qt::darkGray);
+ grad.setColorAt(down ? 0 : 1, Qt::lightGray);
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(grad);
+ if (down)
+ painter->translate(2, 2);
+ painter->drawEllipse(r.adjusted(5, 5, -5, -5));
+ painter->drawPixmap(-_pix.width()/2, -_pix.height()/2, _pix);
+ }
+
+signals:
+ void pressed();
+
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *)
+ {
+ emit pressed();
+ update();
+ }
+
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *)
+ {
+ update();
+ }
+
+private:
+ QPixmap _pix;
+};
+
+class View : public QGraphicsView
+{
+public:
+ View(QGraphicsScene *scene) : QGraphicsView(scene) { }
+
+protected:
+ void resizeEvent(QResizeEvent *event)
+ {
+ QGraphicsView::resizeEvent(event);
+ fitInView(sceneRect(), Qt::KeepAspectRatio);
+ }
+};
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(animatedtiles);
+
+ QApplication app(argc, argv);
+
+ QPixmap kineticPix(":/images/kinetic.png");
+ QPixmap bgPix(":/images/Time-For-Lunch-2.jpg");
+
+ QGraphicsScene scene(-350, -350, 700, 700);
+
+ QList<Pixmap *> items;
+ for (int i = 0; i < 64; ++i) {
+ Pixmap *item = new Pixmap(kineticPix);
+ item->setOffset(-kineticPix.width()/2, -kineticPix.height()/2);
+ item->setZValue(i);
+ items << item;
+ scene.addItem(item);
+ }
+
+ // Buttons
+ QGraphicsItem *buttonParent = new QGraphicsRectItem;
+ Button *ellipseButton = new Button(QPixmap(":/images/ellipse.png"), buttonParent);
+ Button *figure8Button = new Button(QPixmap(":/images/figure8.png"), buttonParent);
+ Button *randomButton = new Button(QPixmap(":/images/random.png"), buttonParent);
+ Button *tiledButton = new Button(QPixmap(":/images/tile.png"), buttonParent);
+ Button *centeredButton = new Button(QPixmap(":/images/centered.png"), buttonParent);
+
+ ellipseButton->setPos(-100, -100);
+ figure8Button->setPos(100, -100);
+ randomButton->setPos(0, 0);
+ tiledButton->setPos(-100, 100);
+ centeredButton->setPos(100, 100);
+
+ scene.addItem(buttonParent);
+ buttonParent->scale(0.75, 0.75);
+ buttonParent->setPos(200, 200);
+ buttonParent->setZValue(65);
+
+ // States
+ QState *rootState = new QState;
+ QState *ellipseState = new QState(rootState);
+ QState *figure8State = new QState(rootState);
+ QState *randomState = new QState(rootState);
+ QState *tiledState = new QState(rootState);
+ QState *centeredState = new QState(rootState);
+
+ // Values
+ for (int i = 0; i < 64; ++i) {
+ Pixmap *item = items.at(i);
+ // Ellipse
+ ellipseState->assignProperty(item, "pos",
+ QPointF(cos((i / 63.0) * 6.28) * 250,
+ sin((i / 63.0) * 6.28) * 250));
+
+ // Figure 8
+ figure8State->assignProperty(item, "pos",
+ QPointF(sin((i / 63.0) * 6.28) * 250,
+ sin(((i * 2)/63.0) * 6.28) * 250));
+
+ // Random
+ randomState->assignProperty(item, "pos",
+ QPointF(-250 + qrand() % 500,
+ -250 + qrand() % 500));
+
+ // Tiled
+ tiledState->assignProperty(item, "pos",
+ QPointF(((i % 8) - 4) * kineticPix.width() + kineticPix.width() / 2,
+ ((i / 8) - 4) * kineticPix.height() + kineticPix.height() / 2));
+
+ // Centered
+ centeredState->assignProperty(item, "pos", QPointF());
+ }
+
+ // Ui
+ View *view = new View(&scene);
+ view->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Animated Tiles"));
+ view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
+ view->setBackgroundBrush(bgPix);
+ view->setCacheMode(QGraphicsView::CacheBackground);
+ view->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
+ view->show();
+
+ QStateMachine states;
+ states.addState(rootState);
+ states.setInitialState(rootState);
+ rootState->setInitialState(centeredState);
+
+ QParallelAnimationGroup *group = new QParallelAnimationGroup;
+ for (int i = 0; i < 64; ++i) {
+ QPropertyAnimation *anim = new QPropertyAnimation(items[i], "pos");
+ anim->setDuration(750 + i * 25);
+ anim->setEasingCurve(QEasingCurve::InOutBack);
+ group->addAnimation(anim);
+ }
+ QAbstractTransition *trans = rootState->addTransition(ellipseButton, SIGNAL(pressed()), ellipseState);
+ trans->addAnimation(group);
+
+ group = new QParallelAnimationGroup;
+ for (int i = 0; i < 64; ++i) {
+ QPropertyAnimation *anim = new QPropertyAnimation(items[i], "pos");
+ anim->setDuration(750 + i * 25);
+ anim->setEasingCurve(QEasingCurve::InOutBack);
+ group->addAnimation(anim);
+ }
+ trans = rootState->addTransition(figure8Button, SIGNAL(pressed()), figure8State);
+ trans->addAnimation(group);
+
+ group = new QParallelAnimationGroup;
+ for (int i = 0; i < 64; ++i) {
+ QPropertyAnimation *anim = new QPropertyAnimation(items[i], "pos");
+ anim->setDuration(750 + i * 25);
+ anim->setEasingCurve(QEasingCurve::InOutBack);
+ group->addAnimation(anim);
+ }
+ trans = rootState->addTransition(randomButton, SIGNAL(pressed()), randomState);
+ trans->addAnimation(group);
+
+ group = new QParallelAnimationGroup;
+ for (int i = 0; i < 64; ++i) {
+ QPropertyAnimation *anim = new QPropertyAnimation(items[i], "pos");
+ anim->setDuration(750 + i * 25);
+ anim->setEasingCurve(QEasingCurve::InOutBack);
+ group->addAnimation(anim);
+ }
+ trans = rootState->addTransition(tiledButton, SIGNAL(pressed()), tiledState);
+ trans->addAnimation(group);
+
+ group = new QParallelAnimationGroup;
+ for (int i = 0; i < 64; ++i) {
+ QPropertyAnimation *anim = new QPropertyAnimation(items[i], "pos");
+ anim->setDuration(750 + i * 25);
+ anim->setEasingCurve(QEasingCurve::InOutBack);
+ group->addAnimation(anim);
+ }
+ trans = rootState->addTransition(centeredButton, SIGNAL(pressed()), centeredState);
+ trans->addAnimation(group);
+
+ states.start();
+ QTimer timer;
+ timer.start(125);
+ timer.setSingleShot(true);
+ rootState->addTransition(&timer, SIGNAL(timeout()), ellipseState);
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/animation/animation.pro b/examples/animation/animation.pro
new file mode 100644
index 0000000..9a2874b
--- /dev/null
+++ b/examples/animation/animation.pro
@@ -0,0 +1,16 @@
+TEMPLATE = \
+ subdirs
+SUBDIRS += \
+ animatedtiles \
+ appchooser \
+ easing \
+ moveblocks \
+ states \
+ stickman \
+ sub-attaq
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/animation
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS animation.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/animation
+INSTALLS += target sources
diff --git a/examples/animation/appchooser/accessories-dictionary.png b/examples/animation/appchooser/accessories-dictionary.png
new file mode 100644
index 0000000..e9bd55d
--- /dev/null
+++ b/examples/animation/appchooser/accessories-dictionary.png
Binary files differ
diff --git a/examples/animation/appchooser/akregator.png b/examples/animation/appchooser/akregator.png
new file mode 100644
index 0000000..a086f45
--- /dev/null
+++ b/examples/animation/appchooser/akregator.png
Binary files differ
diff --git a/examples/animation/appchooser/appchooser.pro b/examples/animation/appchooser/appchooser.pro
new file mode 100644
index 0000000..847b60a
--- /dev/null
+++ b/examples/animation/appchooser/appchooser.pro
@@ -0,0 +1,8 @@
+SOURCES = main.cpp
+RESOURCES = appchooser.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/animation/appchooser
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS appchooser.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/animation/appchooser
+INSTALLS += target sources
diff --git a/examples/animation/appchooser/appchooser.qrc b/examples/animation/appchooser/appchooser.qrc
new file mode 100644
index 0000000..28a3e1c
--- /dev/null
+++ b/examples/animation/appchooser/appchooser.qrc
@@ -0,0 +1,8 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>accessories-dictionary.png</file>
+ <file>akregator.png</file>
+ <file>digikam.png</file>
+ <file>k3b.png</file>
+</qresource>
+</RCC>
diff --git a/examples/animation/appchooser/digikam.png b/examples/animation/appchooser/digikam.png
new file mode 100644
index 0000000..9de9fb2
--- /dev/null
+++ b/examples/animation/appchooser/digikam.png
Binary files differ
diff --git a/examples/animation/appchooser/k3b.png b/examples/animation/appchooser/k3b.png
new file mode 100644
index 0000000..bbcafcf
--- /dev/null
+++ b/examples/animation/appchooser/k3b.png
Binary files differ
diff --git a/examples/animation/appchooser/main.cpp b/examples/animation/appchooser/main.cpp
new file mode 100644
index 0000000..44457f7
--- /dev/null
+++ b/examples/animation/appchooser/main.cpp
@@ -0,0 +1,158 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <QtGui>
+
+
+class Pixmap : public QGraphicsWidget
+{
+ Q_OBJECT
+
+public:
+ Pixmap(const QPixmap &pix, QGraphicsItem *parent = 0)
+ : QGraphicsWidget(parent), orig(pix), p(pix)
+ {
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ {
+ painter->drawPixmap(QPointF(), p);
+ }
+
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent * )
+ {
+ emit clicked();
+ }
+
+ virtual void setGeometry(const QRectF &rect)
+ {
+ QGraphicsWidget::setGeometry(rect);
+
+ if (rect.size().width() > orig.size().width())
+ p = orig.scaled(rect.size().toSize());
+ else
+ p = orig;
+ }
+
+Q_SIGNALS:
+ void clicked();
+
+private:
+ QPixmap orig;
+ QPixmap p;
+};
+
+void createStates(const QObjectList &objects,
+ const QRect &selectedRect, QState *parent)
+{
+ for (int i = 0; i < objects.size(); ++i) {
+ QState *state = new QState(parent);
+ state->assignProperty(objects.at(i), "geometry", selectedRect);
+ parent->addTransition(objects.at(i), SIGNAL(clicked()), state);
+ }
+}
+
+void createAnimations(const QObjectList &objects, QStateMachine *machine)
+{
+ for (int i=0; i<objects.size(); ++i)
+ machine->addDefaultAnimation(new QPropertyAnimation(objects.at(i), "geometry"));
+}
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(appchooser);
+
+ QApplication app(argc, argv);
+
+ Pixmap *p1 = new Pixmap(QPixmap(":/digikam.png"));
+ Pixmap *p2 = new Pixmap(QPixmap(":/akregator.png"));
+ Pixmap *p3 = new Pixmap(QPixmap(":/accessories-dictionary.png"));
+ Pixmap *p4 = new Pixmap(QPixmap(":/k3b.png"));
+
+ p1->setObjectName("p1");
+ p2->setObjectName("p2");
+ p3->setObjectName("p3");
+ p4->setObjectName("p4");
+
+ p1->setGeometry(QRectF(0.0, 0.0, 64.0, 64.0));
+ p2->setGeometry(QRectF(236.0, 0.0, 64.0, 64.0));
+ p3->setGeometry(QRectF(236.0, 236.0, 64.0, 64.0));
+ p4->setGeometry(QRectF(0.0, 236.0, 64.0, 64.0));
+
+ QGraphicsScene scene(0, 0, 300, 300);
+ scene.setBackgroundBrush(Qt::white);
+ scene.addItem(p1);
+ scene.addItem(p2);
+ scene.addItem(p3);
+ scene.addItem(p4);
+
+ QGraphicsView window(&scene);
+ window.setFrameStyle(0);
+ window.setAlignment(Qt::AlignLeft | Qt::AlignTop);
+ window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QState *group = new QState(machine.rootState());
+ group->setObjectName("group");
+ QRect selectedRect(86, 86, 128, 128);
+
+ QState *idleState = new QState(group);
+ group->setInitialState(idleState);
+
+ QObjectList objects;
+ objects << p1 << p2 << p3 << p4;
+ createStates(objects, selectedRect, group);
+ createAnimations(objects, &machine);
+
+ machine.setInitialState(group);
+ machine.start();
+
+ window.resize(300, 300);
+ window.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/animation/easing/animation.h b/examples/animation/easing/animation.h
new file mode 100644
index 0000000..d4d699d
--- /dev/null
+++ b/examples/animation/easing/animation.h
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANIMATION_H
+#define ANIMATION_H
+
+#include <QtGui>
+
+#include <QtCore/qpropertyanimation.h>
+
+class Animation : public QPropertyAnimation {
+public:
+ enum PathType {
+ LinearPath,
+ CirclePath,
+ NPathTypes
+ };
+ Animation(QObject *target, const QByteArray &prop)
+ : QPropertyAnimation(target, prop)
+ {
+ setPathType(LinearPath);
+ }
+
+ void setPathType(PathType pathType)
+ {
+ if (pathType >= NPathTypes)
+ qWarning("Unknown pathType %d", pathType);
+
+ m_pathType = pathType;
+ m_path = QPainterPath();
+ }
+
+ void updateCurrentTime(int msecs)
+ {
+ if (m_pathType == CirclePath) {
+ if (m_path.isEmpty()) {
+ QPointF to = endValue().toPointF();
+ QPointF from = startValue().toPointF();
+ m_path.moveTo(from);
+ m_path.addEllipse(QRectF(from, to));
+ }
+ int dura = duration();
+ const qreal progress = ((dura == 0) ? 1 : ((((currentTime() - 1) % dura) + 1) / qreal(dura)));
+
+ qreal easedProgress = easingCurve().valueForProgress(progress);
+ if (easedProgress > 1.0) {
+ easedProgress -= 1.0;
+ } else if (easedProgress < 0) {
+ easedProgress += 1.0;
+ }
+ QPointF pt = m_path.pointAtPercent(easedProgress);
+ updateCurrentValue(pt);
+ emit valueChanged(pt);
+ } else {
+ QPropertyAnimation::updateCurrentTime(msecs);
+ }
+ }
+
+ QPainterPath m_path;
+ PathType m_pathType;
+};
+
+#endif // ANIMATION_H
diff --git a/examples/animation/easing/easing.pro b/examples/animation/easing/easing.pro
new file mode 100644
index 0000000..8e8a35f
--- /dev/null
+++ b/examples/animation/easing/easing.pro
@@ -0,0 +1,14 @@
+HEADERS = window.h \
+ animation.h
+SOURCES = main.cpp \
+ window.cpp
+
+FORMS = form.ui
+
+RESOURCES = easing.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/animation/easing
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS easing.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/animation/easing
+INSTALLS += target sources
diff --git a/examples/animation/easing/easing.qrc b/examples/animation/easing/easing.qrc
new file mode 100644
index 0000000..7e112d3
--- /dev/null
+++ b/examples/animation/easing/easing.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>images/qt-logo.png</file>
+ </qresource>
+ </RCC> \ No newline at end of file
diff --git a/examples/animation/easing/form.ui b/examples/animation/easing/form.ui
new file mode 100644
index 0000000..b60ade8
--- /dev/null
+++ b/examples/animation/easing/form.ui
@@ -0,0 +1,201 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>545</width>
+ <height>471</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Easing curves</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" colspan="2">
+ <widget class="QListWidget" name="easingCurvePicker">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>120</height>
+ </size>
+ </property>
+ <property name="verticalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="movement">
+ <enum>QListView::Static</enum>
+ </property>
+ <property name="isWrapping" stdset="0">
+ <bool>false</bool>
+ </property>
+ <property name="viewMode">
+ <enum>QListView::IconMode</enum>
+ </property>
+ <property name="selectionRectVisible">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="title">
+ <string>Path type</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QRadioButton" name="lineRadio">
+ <property name="text">
+ <string>Line</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="circleRadio">
+ <property name="text">
+ <string>Circle</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Properties</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Period</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QDoubleSpinBox" name="periodSpinBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimum">
+ <double>-1.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.100000000000000</double>
+ </property>
+ <property name="value">
+ <double>-1.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Amplitude</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QDoubleSpinBox" name="amplitudeSpinBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimum">
+ <double>-1.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.100000000000000</double>
+ </property>
+ <property name="value">
+ <double>-1.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Overshoot</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QDoubleSpinBox" name="overshootSpinBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimum">
+ <double>-1.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.100000000000000</double>
+ </property>
+ <property name="value">
+ <double>-1.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="1">
+ <widget class="QGraphicsView" name="graphicsView">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+ <buttongroups>
+ <buttongroup name="buttonGroup"/>
+ </buttongroups>
+</ui>
diff --git a/examples/animation/easing/images/qt-logo.png b/examples/animation/easing/images/qt-logo.png
new file mode 100644
index 0000000..14ddf2a
--- /dev/null
+++ b/examples/animation/easing/images/qt-logo.png
Binary files differ
diff --git a/examples/animation/easing/main.cpp b/examples/animation/easing/main.cpp
new file mode 100644
index 0000000..bd10df2
--- /dev/null
+++ b/examples/animation/easing/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "window.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(easing);
+ QApplication app(argc, argv);
+ Window w;
+ w.resize(400, 400);
+ w.show();
+ return app.exec();
+}
diff --git a/examples/animation/easing/window.cpp b/examples/animation/easing/window.cpp
new file mode 100644
index 0000000..cf4be15
--- /dev/null
+++ b/examples/animation/easing/window.cpp
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "window.h"
+
+Window::Window(QWidget *parent)
+ : QWidget(parent), m_iconSize(64, 64)
+{
+ m_ui.setupUi(this);
+ QButtonGroup *buttonGroup = qFindChild<QButtonGroup *>(this); // ### workaround for uic in 4.4
+ m_ui.easingCurvePicker->setIconSize(m_iconSize);
+ m_ui.easingCurvePicker->setMinimumHeight(m_iconSize.height() + 50);
+ buttonGroup->setId(m_ui.lineRadio, 0);
+ buttonGroup->setId(m_ui.circleRadio, 1);
+
+ QEasingCurve dummy;
+ m_ui.periodSpinBox->setValue(dummy.period());
+ m_ui.amplitudeSpinBox->setValue(dummy.amplitude());
+ m_ui.overshootSpinBox->setValue(dummy.overshoot());
+
+ connect(m_ui.easingCurvePicker, SIGNAL(currentRowChanged(int)), this, SLOT(curveChanged(int)));
+ connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(pathChanged(int)));
+ connect(m_ui.periodSpinBox, SIGNAL(valueChanged(double)), this, SLOT(periodChanged(double)));
+ connect(m_ui.amplitudeSpinBox, SIGNAL(valueChanged(double)), this, SLOT(amplitudeChanged(double)));
+ connect(m_ui.overshootSpinBox, SIGNAL(valueChanged(double)), this, SLOT(overshootChanged(double)));
+ createCurveIcons();
+
+ QPixmap pix(QLatin1String(":/images/qt-logo.png"));
+ m_item = new PixmapItem(pix);
+ m_scene.addItem(m_item);
+ m_ui.graphicsView->setScene(&m_scene);
+
+ m_anim = new Animation(m_item, "pos");
+ m_anim->setEasingCurve(QEasingCurve::OutBounce);
+ m_ui.easingCurvePicker->setCurrentRow(int(QEasingCurve::OutBounce));
+
+ startAnimation();
+}
+
+void Window::createCurveIcons()
+{
+ QPixmap pix(m_iconSize);
+ QPainter painter(&pix);
+ QLinearGradient gradient(0,0, 0, m_iconSize.height());
+ gradient.setColorAt(0.0, QColor(240, 240, 240));
+ gradient.setColorAt(1.0, QColor(224, 224, 224));
+ QBrush brush(gradient);
+ const QMetaObject &mo = QEasingCurve::staticMetaObject;
+ QMetaEnum metaEnum = mo.enumerator(mo.indexOfEnumerator("Type"));
+ // Skip QEasingCurve::Custom
+ for (int i = 0; i < QEasingCurve::NCurveTypes - 1; ++i) {
+ painter.fillRect(QRect(QPoint(0, 0), m_iconSize), brush);
+ QEasingCurve curve((QEasingCurve::Type)i);
+ painter.setPen(QColor(0, 0, 255, 64));
+ qreal xAxis = m_iconSize.height()/1.5;
+ qreal yAxis = m_iconSize.width()/3;
+ painter.drawLine(0, xAxis, m_iconSize.width(), xAxis);
+ painter.drawLine(yAxis, 0, yAxis, m_iconSize.height());
+ painter.setPen(Qt::black);
+
+ qreal curveScale = m_iconSize.height()/2;
+ QPoint currentPos(yAxis, xAxis);
+
+ for (qreal t = 0; t < 1.0; t+=1.0/curveScale) {
+ QPoint to;
+ to.setX(yAxis + curveScale * t);
+ to.setY(xAxis - curveScale * curve.valueForProgress(t));
+ painter.drawLine(currentPos, to);
+ currentPos = to;
+ }
+ QListWidgetItem *item = new QListWidgetItem;
+ item->setIcon(QIcon(pix));
+ item->setText(metaEnum.key(i));
+ m_ui.easingCurvePicker->addItem(item);
+ }
+}
+
+void Window::startAnimation()
+{
+ m_anim->setStartValue(QPointF(0, 0));
+ m_anim->setEndValue(QPointF(100, 100));
+ m_anim->setDuration(2000);
+ m_anim->setLoopCount(-1); // forever
+ m_anim->start();
+}
+
+void Window::curveChanged(int row)
+{
+ QEasingCurve::Type curveType = (QEasingCurve::Type)row;
+ m_anim->setEasingCurve(curveType);
+ m_anim->setCurrentTime(0);
+
+ bool isElastic = curveType >= QEasingCurve::InElastic && curveType <= QEasingCurve::OutInElastic;
+ bool isBounce = curveType >= QEasingCurve::InBounce && curveType <= QEasingCurve::OutInBounce;
+ m_ui.periodSpinBox->setEnabled(isElastic);
+ m_ui.amplitudeSpinBox->setEnabled(isElastic || isBounce);
+ m_ui.overshootSpinBox->setEnabled(curveType >= QEasingCurve::InBack && curveType <= QEasingCurve::OutInBack);
+}
+
+void Window::pathChanged(int index)
+{
+ m_anim->setPathType((Animation::PathType)index);
+}
+
+void Window::periodChanged(double value)
+{
+ QEasingCurve curve = m_anim->easingCurve();
+ curve.setPeriod(value);
+ m_anim->setEasingCurve(curve);
+}
+
+void Window::amplitudeChanged(double value)
+{
+ QEasingCurve curve = m_anim->easingCurve();
+ curve.setAmplitude(value);
+ m_anim->setEasingCurve(curve);
+}
+
+void Window::overshootChanged(double value)
+{
+ QEasingCurve curve = m_anim->easingCurve();
+ curve.setOvershoot(value);
+ m_anim->setEasingCurve(curve);
+}
+
diff --git a/examples/animation/easing/window.h b/examples/animation/easing/window.h
new file mode 100644
index 0000000..f3a8cb3
--- /dev/null
+++ b/examples/animation/easing/window.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "ui_form.h"
+#include "animation.h"
+
+class PixmapItem : public QObject, public QGraphicsPixmapItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QPointF pos READ pos WRITE setPos)
+public:
+ PixmapItem(const QPixmap &pix) : QGraphicsPixmapItem(pix)
+ {
+ }
+};
+
+class Window : public QWidget {
+ Q_OBJECT
+public:
+ Window(QWidget *parent = 0);
+private slots:
+ void curveChanged(int row);
+ void pathChanged(int index);
+ void periodChanged(double);
+ void amplitudeChanged(double);
+ void overshootChanged(double);
+
+private:
+ void createCurveIcons();
+ void startAnimation();
+
+ Ui::Form m_ui;
+ QGraphicsScene m_scene;
+ PixmapItem *m_item;
+ Animation *m_anim;
+ QSize m_iconSize;
+
+
+};
diff --git a/examples/animation/moveblocks/main.cpp b/examples/animation/moveblocks/main.cpp
new file mode 100644
index 0000000..d315112
--- /dev/null
+++ b/examples/animation/moveblocks/main.cpp
@@ -0,0 +1,295 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <QtGui>
+
+class StateSwitchEvent: public QEvent
+{
+public:
+ StateSwitchEvent()
+ : QEvent(Type(StateSwitchType))
+ {
+ }
+
+ StateSwitchEvent(int rand)
+ : QEvent(Type(StateSwitchType)),
+ m_rand(rand)
+ {
+ }
+
+ enum { StateSwitchType = QEvent::User + 256 };
+
+ int rand() const { return m_rand; }
+
+private:
+ int m_rand;
+};
+
+
+class QGraphicsRectWidget : public QGraphicsWidget
+{
+public:
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *,
+ QWidget *)
+ {
+ painter->fillRect(rect(), Qt::blue);
+ }
+};
+
+class StateSwitchTransition: public QAbstractTransition
+{
+public:
+ StateSwitchTransition(int rand)
+ : QAbstractTransition(),
+ m_rand(rand)
+ {
+ }
+
+protected:
+ virtual bool eventTest(QEvent *event)
+ {
+ return (event->type() == QEvent::Type(StateSwitchEvent::StateSwitchType))
+ && (static_cast<StateSwitchEvent *>(event)->rand() == m_rand);
+ }
+
+ virtual void onTransition(QEvent *) {}
+
+private:
+ int m_rand;
+};
+
+class StateSwitcher : public QState
+{
+ Q_OBJECT
+public:
+ StateSwitcher(QStateMachine *machine)
+ : QState(machine->rootState()), m_machine(machine),
+ m_stateCount(0), m_lastIndex(0)
+ { }
+
+ virtual void onEntry(QEvent *)
+ {
+ int n;
+ while ((n = (qrand() % m_stateCount + 1)) == m_lastIndex)
+ { }
+ m_lastIndex = n;
+ m_machine->postEvent(new StateSwitchEvent(n));
+ }
+ virtual void onExit(QEvent *) {}
+
+ void addState(QState *state, QAbstractAnimation *animation) {
+ StateSwitchTransition *trans = new StateSwitchTransition(++m_stateCount);
+ trans->setTargetState(state);
+ addTransition(trans);
+ trans->addAnimation(animation);
+ }
+
+
+private:
+ QStateMachine *m_machine;
+ int m_stateCount;
+ int m_lastIndex;
+};
+
+QState *createGeometryState(QObject *w1, const QRect &rect1,
+ QObject *w2, const QRect &rect2,
+ QObject *w3, const QRect &rect3,
+ QObject *w4, const QRect &rect4,
+ QState *parent)
+{
+ QState *result = new QState(parent);
+ result->assignProperty(w1, "geometry", rect1);
+ result->assignProperty(w1, "geometry", rect1);
+ result->assignProperty(w2, "geometry", rect2);
+ result->assignProperty(w3, "geometry", rect3);
+ result->assignProperty(w4, "geometry", rect4);
+
+ return result;
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+#if 0
+ QWidget window;
+ QPalette palette;
+ palette.setBrush(QPalette::Window, Qt::black);
+ window.setPalette(palette);
+ QPushButton *button1 = new QPushButton("A", &window);
+ QPushButton *button2 = new QPushButton("B", &window);
+ QPushButton *button3 = new QPushButton("C", &window);
+ QPushButton *button4 = new QPushButton("D", &window);
+
+ button1->setObjectName("button1");
+ button2->setObjectName("button2");
+ button3->setObjectName("button3");
+ button4->setObjectName("button4");
+#else
+ QGraphicsRectWidget *button1 = new QGraphicsRectWidget;
+ QGraphicsRectWidget *button2 = new QGraphicsRectWidget;
+ QGraphicsRectWidget *button3 = new QGraphicsRectWidget;
+ QGraphicsRectWidget *button4 = new QGraphicsRectWidget;
+ button2->setZValue(1);
+ button3->setZValue(2);
+ button4->setZValue(3);
+ QGraphicsScene scene(0, 0, 300, 300);
+ scene.setBackgroundBrush(Qt::black);
+ scene.addItem(button1);
+ scene.addItem(button2);
+ scene.addItem(button3);
+ scene.addItem(button4);
+
+ QGraphicsView window(&scene);
+ window.setFrameStyle(0);
+ window.setAlignment(Qt::AlignLeft | Qt::AlignTop);
+ window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+#endif
+ QStateMachine machine;
+
+ QState *group = new QState();
+ group->setObjectName("group");
+ QTimer timer;
+ timer.setInterval(1250);
+ timer.setSingleShot(true);
+ QObject::connect(group, SIGNAL(entered()), &timer, SLOT(start()));
+
+ QState *state1;
+ QState *state2;
+ QState *state3;
+ QState *state4;
+ QState *state5;
+ QState *state6;
+ QState *state7;
+
+ state1 = createGeometryState(button1, QRect(100, 0, 50, 50),
+ button2, QRect(150, 0, 50, 50),
+ button3, QRect(200, 0, 50, 50),
+ button4, QRect(250, 0, 50, 50),
+ group);
+ state2 = createGeometryState(button1, QRect(250, 100, 50, 50),
+ button2, QRect(250, 150, 50, 50),
+ button3, QRect(250, 200, 50, 50),
+ button4, QRect(250, 250, 50, 50),
+ group);
+ state3 = createGeometryState(button1, QRect(150, 250, 50, 50),
+ button2, QRect(100, 250, 50, 50),
+ button3, QRect(50, 250, 50, 50),
+ button4, QRect(0, 250, 50, 50),
+ group);
+ state4 = createGeometryState(button1, QRect(0, 150, 50, 50),
+ button2, QRect(0, 100, 50, 50),
+ button3, QRect(0, 50, 50, 50),
+ button4, QRect(0, 0, 50, 50),
+ group);
+ state5 = createGeometryState(button1, QRect(100, 100, 50, 50),
+ button2, QRect(150, 100, 50, 50),
+ button3, QRect(100, 150, 50, 50),
+ button4, QRect(150, 150, 50, 50),
+ group);
+ state6 = createGeometryState(button1, QRect(50, 50, 50, 50),
+ button2, QRect(200, 50, 50, 50),
+ button3, QRect(50, 200, 50, 50),
+ button4, QRect(200, 200, 50, 50),
+ group);
+ state7 = createGeometryState(button1, QRect(0, 0, 50, 50),
+ button2, QRect(250, 0, 50, 50),
+ button3, QRect(0, 250, 50, 50),
+ button4, QRect(250, 250, 50, 50),
+ group);
+ group->setInitialState(state1);
+
+ QParallelAnimationGroup animationGroup;
+ QSequentialAnimationGroup *subGroup;
+
+ QPropertyAnimation *anim = new QPropertyAnimation(button4, "geometry");
+ anim->setDuration(1000);
+ anim->setEasingCurve(QEasingCurve::OutElastic);
+ animationGroup.addAnimation(anim);
+
+ subGroup = new QSequentialAnimationGroup(&animationGroup);
+ subGroup->addPause(100);
+ anim = new QPropertyAnimation(button3, "geometry");
+ anim->setDuration(1000);
+ anim->setEasingCurve(QEasingCurve::OutElastic);
+ subGroup->addAnimation(anim);
+
+ subGroup = new QSequentialAnimationGroup(&animationGroup);
+ subGroup->addPause(150);
+ anim = new QPropertyAnimation(button2, "geometry");
+ anim->setDuration(1000);
+ anim->setEasingCurve(QEasingCurve::OutElastic);
+ subGroup->addAnimation(anim);
+
+ subGroup = new QSequentialAnimationGroup(&animationGroup);
+ subGroup->addPause(200);
+ anim = new QPropertyAnimation(button1, "geometry");
+ anim->setDuration(1000);
+ anim->setEasingCurve(QEasingCurve::OutElastic);
+ subGroup->addAnimation(anim);
+
+ StateSwitcher *stateSwitcher = new StateSwitcher(&machine);
+ stateSwitcher->setObjectName("stateSwitcher");
+ group->addTransition(&timer, SIGNAL(timeout()), stateSwitcher);
+ stateSwitcher->addState(state1, &animationGroup);
+ stateSwitcher->addState(state2, &animationGroup);
+ stateSwitcher->addState(state3, &animationGroup);
+ stateSwitcher->addState(state4, &animationGroup);
+ stateSwitcher->addState(state5, &animationGroup);
+ stateSwitcher->addState(state6, &animationGroup);
+ stateSwitcher->addState(state7, &animationGroup);
+
+ machine.addState(group);
+ machine.setInitialState(group);
+ machine.start();
+
+
+ window.resize(300, 300);
+ window.show();
+
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/animation/moveblocks/moveblocks.pro b/examples/animation/moveblocks/moveblocks.pro
new file mode 100644
index 0000000..b8e88b2
--- /dev/null
+++ b/examples/animation/moveblocks/moveblocks.pro
@@ -0,0 +1,7 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/animation/moveblocks
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS moveblocks.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/animation/moveblocks
+INSTALLS += target sources
diff --git a/examples/animation/states/accessories-dictionary.png b/examples/animation/states/accessories-dictionary.png
new file mode 100644
index 0000000..e9bd55d
--- /dev/null
+++ b/examples/animation/states/accessories-dictionary.png
Binary files differ
diff --git a/examples/animation/states/akregator.png b/examples/animation/states/akregator.png
new file mode 100644
index 0000000..a086f45
--- /dev/null
+++ b/examples/animation/states/akregator.png
Binary files differ
diff --git a/examples/animation/states/digikam.png b/examples/animation/states/digikam.png
new file mode 100644
index 0000000..9de9fb2
--- /dev/null
+++ b/examples/animation/states/digikam.png
Binary files differ
diff --git a/examples/animation/states/help-browser.png b/examples/animation/states/help-browser.png
new file mode 100644
index 0000000..db92faa
--- /dev/null
+++ b/examples/animation/states/help-browser.png
Binary files differ
diff --git a/examples/animation/states/k3b.png b/examples/animation/states/k3b.png
new file mode 100644
index 0000000..bbcafcf
--- /dev/null
+++ b/examples/animation/states/k3b.png
Binary files differ
diff --git a/examples/animation/states/kchart.png b/examples/animation/states/kchart.png
new file mode 100644
index 0000000..1dd115b
--- /dev/null
+++ b/examples/animation/states/kchart.png
Binary files differ
diff --git a/examples/animation/states/main.cpp b/examples/animation/states/main.cpp
new file mode 100644
index 0000000..17a7a8e
--- /dev/null
+++ b/examples/animation/states/main.cpp
@@ -0,0 +1,284 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+class Pixmap : public QGraphicsWidget
+{
+ Q_OBJECT
+public:
+ Pixmap(const QPixmap &pix) : QGraphicsWidget(), p(pix)
+ {
+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ {
+ painter->drawPixmap(QPointF(), p);
+ }
+
+protected:
+ QSizeF sizeHint(Qt::SizeHint, const QSizeF & = QSizeF())
+ {
+ return QSizeF(p.width(), p.height());
+ }
+
+private:
+ QPixmap p;
+};
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(states);
+
+ QApplication app(argc, argv);
+
+ // Text edit and button
+ QTextEdit *edit = new QTextEdit;
+ edit->setText("asdf lkjha yuoiqwe asd iuaysd u iasyd uiy "
+ "asdf lkjha yuoiqwe asd iuaysd u iasyd uiy "
+ "asdf lkjha yuoiqwe asd iuaysd u iasyd uiy "
+ "asdf lkjha yuoiqwe asd iuaysd u iasyd uiy!");
+
+ QPushButton *button = new QPushButton;
+ QGraphicsProxyWidget *buttonProxy = new QGraphicsProxyWidget;
+ buttonProxy->setWidget(button);
+ QGraphicsProxyWidget *editProxy = new QGraphicsProxyWidget;
+ editProxy->setWidget(edit);
+
+ QGroupBox *box = new QGroupBox;
+ box->setFlat(true);
+ box->setTitle("Options");
+
+ QVBoxLayout *layout2 = new QVBoxLayout;
+ box->setLayout(layout2);
+ layout2->addWidget(new QRadioButton("Herring"));
+ layout2->addWidget(new QRadioButton("Blue Parrot"));
+ layout2->addWidget(new QRadioButton("Petunias"));
+ layout2->addStretch();
+
+ QGraphicsProxyWidget *boxProxy = new QGraphicsProxyWidget;
+ boxProxy->setWidget(box);
+
+ // Parent widget
+ QGraphicsWidget *widget = new QGraphicsWidget;
+ QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, widget);
+ layout->addItem(editProxy);
+ layout->addItem(buttonProxy);
+ widget->setLayout(layout);
+
+ Pixmap *p1 = new Pixmap(QPixmap(":/digikam.png"));
+ Pixmap *p2 = new Pixmap(QPixmap(":/akregator.png"));
+ Pixmap *p3 = new Pixmap(QPixmap(":/accessories-dictionary.png"));
+ Pixmap *p4 = new Pixmap(QPixmap(":/k3b.png"));
+ Pixmap *p5 = new Pixmap(QPixmap(":/help-browser.png"));
+ Pixmap *p6 = new Pixmap(QPixmap(":/kchart.png"));
+
+ QGraphicsScene scene(0, 0, 400, 300);
+ scene.setBackgroundBrush(scene.palette().window());
+ scene.addItem(widget);
+ scene.addItem(boxProxy);
+ scene.addItem(p1);
+ scene.addItem(p2);
+ scene.addItem(p3);
+ scene.addItem(p4);
+ scene.addItem(p5);
+ scene.addItem(p6);
+
+ QStateMachine machine;
+ QState *root = machine.rootState();
+ QState *state1 = new QState(root);
+ QState *state2 = new QState(root);
+ QState *state3 = new QState(root);
+ machine.setInitialState(state1);
+
+ // State 1
+ state1->assignProperty(button, "text", "Switch to state 2");
+ state1->assignProperty(widget, "geometry", QRectF(0, 0, 400, 150));
+ state1->assignProperty(box, "geometry", QRect(-200, 150, 200, 150));
+ state1->assignProperty(p1, "geometry", QRectF(68, 185, 64, 64));
+ state1->assignProperty(p2, "geometry", QRectF(168, 185, 64, 64));
+ state1->assignProperty(p3, "geometry", QRectF(268, 185, 64, 64));
+ state1->assignProperty(p4, "geometry", QRectF(68-150, 48-150, 64, 64));
+ state1->assignProperty(p5, "geometry", QRectF(168, 48-150, 64, 64));
+ state1->assignProperty(p6, "geometry", QRectF(268+150, 48-150, 64, 64));
+ state1->assignProperty(p1, "zRotation", qreal(0));
+ state1->assignProperty(p2, "zRotation", qreal(0));
+ state1->assignProperty(p3, "zRotation", qreal(0));
+ state1->assignProperty(p4, "zRotation", qreal(-270));
+ state1->assignProperty(p5, "zRotation", qreal(-90));
+ state1->assignProperty(p6, "zRotation", qreal(270));
+ state1->assignProperty(boxProxy, "opacity", qreal(0));
+ state1->assignProperty(p1, "opacity", qreal(1));
+ state1->assignProperty(p2, "opacity", qreal(1));
+ state1->assignProperty(p3, "opacity", qreal(1));
+ state1->assignProperty(p4, "opacity", qreal(0));
+ state1->assignProperty(p5, "opacity", qreal(0));
+ state1->assignProperty(p6, "opacity", qreal(0));
+
+ // State 2
+ state2->assignProperty(button, "text", "Switch to state 3");
+ state2->assignProperty(widget, "geometry", QRectF(200, 150, 200, 150));
+ state2->assignProperty(box, "geometry", QRect(9, 150, 190, 150));
+ state2->assignProperty(p1, "geometry", QRectF(68-150, 185+150, 64, 64));
+ state2->assignProperty(p2, "geometry", QRectF(168, 185+150, 64, 64));
+ state2->assignProperty(p3, "geometry", QRectF(268+150, 185+150, 64, 64));
+ state2->assignProperty(p4, "geometry", QRectF(64, 48, 64, 64));
+ state2->assignProperty(p5, "geometry", QRectF(168, 48, 64, 64));
+ state2->assignProperty(p6, "geometry", QRectF(268, 48, 64, 64));
+ state2->assignProperty(p1, "zRotation", qreal(-270));
+ state2->assignProperty(p2, "zRotation", qreal(90));
+ state2->assignProperty(p3, "zRotation", qreal(270));
+ state2->assignProperty(p4, "zRotation", qreal(0));
+ state2->assignProperty(p5, "zRotation", qreal(0));
+ state2->assignProperty(p6, "zRotation", qreal(0));
+ state2->assignProperty(boxProxy, "opacity", qreal(1));
+ state2->assignProperty(p1, "opacity", qreal(0));
+ state2->assignProperty(p2, "opacity", qreal(0));
+ state2->assignProperty(p3, "opacity", qreal(0));
+ state2->assignProperty(p4, "opacity", qreal(1));
+ state2->assignProperty(p5, "opacity", qreal(1));
+ state2->assignProperty(p6, "opacity", qreal(1));
+
+ // State 3
+ state3->assignProperty(button, "text", "Switch to state 1");
+ state3->assignProperty(p1, "geometry", QRectF(5, 5, 64, 64));
+ state3->assignProperty(p2, "geometry", QRectF(5, 5 + 64 + 5, 64, 64));
+ state3->assignProperty(p3, "geometry", QRectF(5, 5 + (64 + 5) + 64, 64, 64));
+ state3->assignProperty(p4, "geometry", QRectF(5 + 64 + 5, 5, 64, 64));
+ state3->assignProperty(p5, "geometry", QRectF(5 + 64 + 5, 5 + 64 + 5, 64, 64));
+ state3->assignProperty(p6, "geometry", QRectF(5 + 64 + 5, 5 + (64 + 5) + 64, 64, 64));
+ state3->assignProperty(widget, "geometry", QRectF(138, 5, 400 - 138, 200));
+ state3->assignProperty(box, "geometry", QRect(5, 205, 400, 90));
+ state3->assignProperty(p1, "opacity", qreal(1));
+ state3->assignProperty(p2, "opacity", qreal(1));
+ state3->assignProperty(p3, "opacity", qreal(1));
+ state3->assignProperty(p4, "opacity", qreal(1));
+ state3->assignProperty(p5, "opacity", qreal(1));
+ state3->assignProperty(p6, "opacity", qreal(1));
+
+ QParallelAnimationGroup animation1;
+
+ QSequentialAnimationGroup *animation1SubGroup;
+ animation1SubGroup = new QSequentialAnimationGroup(&animation1);
+ animation1SubGroup->addPause(250);
+ animation1SubGroup->addAnimation(new QPropertyAnimation(box, "geometry"));
+
+ animation1.addAnimation(new QPropertyAnimation(widget, "geometry"));
+ animation1.addAnimation(new QPropertyAnimation(p1, "geometry"));
+ animation1.addAnimation(new QPropertyAnimation(p2, "geometry"));
+ animation1.addAnimation(new QPropertyAnimation(p3, "geometry"));
+ animation1.addAnimation(new QPropertyAnimation(p4, "geometry"));
+ animation1.addAnimation(new QPropertyAnimation(p5, "geometry"));
+ animation1.addAnimation(new QPropertyAnimation(p6, "geometry"));
+ animation1.addAnimation(new QPropertyAnimation(p1, "zRotation"));
+ animation1.addAnimation(new QPropertyAnimation(p2, "zRotation"));
+ animation1.addAnimation(new QPropertyAnimation(p3, "zRotation"));
+ animation1.addAnimation(new QPropertyAnimation(p4, "zRotation"));
+ animation1.addAnimation(new QPropertyAnimation(p5, "zRotation"));
+ animation1.addAnimation(new QPropertyAnimation(p6, "zRotation"));
+ animation1.addAnimation(new QPropertyAnimation(p1, "opacity"));
+ animation1.addAnimation(new QPropertyAnimation(p2, "opacity"));
+ animation1.addAnimation(new QPropertyAnimation(p3, "opacity"));
+ animation1.addAnimation(new QPropertyAnimation(p4, "opacity"));
+ animation1.addAnimation(new QPropertyAnimation(p5, "opacity"));
+ animation1.addAnimation(new QPropertyAnimation(p6, "opacity"));
+
+ QParallelAnimationGroup animation2;
+ animation2.addAnimation(new QPropertyAnimation(box, "geometry"));
+ animation2.addAnimation(new QPropertyAnimation(widget, "geometry"));
+ animation2.addAnimation(new QPropertyAnimation(p1, "geometry"));
+ animation2.addAnimation(new QPropertyAnimation(p2, "geometry"));
+ animation2.addAnimation(new QPropertyAnimation(p3, "geometry"));
+ animation2.addAnimation(new QPropertyAnimation(p4, "geometry"));
+ animation2.addAnimation(new QPropertyAnimation(p5, "geometry"));
+ animation2.addAnimation(new QPropertyAnimation(p6, "geometry"));
+ animation2.addAnimation(new QPropertyAnimation(p1, "zRotation"));
+ animation2.addAnimation(new QPropertyAnimation(p2, "zRotation"));
+ animation2.addAnimation(new QPropertyAnimation(p3, "zRotation"));
+ animation2.addAnimation(new QPropertyAnimation(p4, "zRotation"));
+ animation2.addAnimation(new QPropertyAnimation(p5, "zRotation"));
+ animation2.addAnimation(new QPropertyAnimation(p6, "zRotation"));
+ animation2.addAnimation(new QPropertyAnimation(p1, "opacity"));
+ animation2.addAnimation(new QPropertyAnimation(p2, "opacity"));
+ animation2.addAnimation(new QPropertyAnimation(p3, "opacity"));
+ animation2.addAnimation(new QPropertyAnimation(p4, "opacity"));
+ animation2.addAnimation(new QPropertyAnimation(p5, "opacity"));
+ animation2.addAnimation(new QPropertyAnimation(p6, "opacity"));
+
+ QParallelAnimationGroup animation3;
+ animation3.addAnimation(new QPropertyAnimation(box, "geometry"));
+ animation3.addAnimation(new QPropertyAnimation(widget, "geometry"));
+ animation3.addAnimation(new QPropertyAnimation(p1, "geometry"));
+ animation3.addAnimation(new QPropertyAnimation(p2, "geometry"));
+ animation3.addAnimation(new QPropertyAnimation(p3, "geometry"));
+ animation3.addAnimation(new QPropertyAnimation(p4, "geometry"));
+ animation3.addAnimation(new QPropertyAnimation(p5, "geometry"));
+ animation3.addAnimation(new QPropertyAnimation(p6, "geometry"));
+ animation3.addAnimation(new QPropertyAnimation(p1, "zRotation"));
+ animation3.addAnimation(new QPropertyAnimation(p2, "zRotation"));
+ animation3.addAnimation(new QPropertyAnimation(p3, "zRotation"));
+ animation3.addAnimation(new QPropertyAnimation(p4, "zRotation"));
+ animation3.addAnimation(new QPropertyAnimation(p5, "zRotation"));
+ animation3.addAnimation(new QPropertyAnimation(p6, "zRotation"));
+ animation3.addAnimation(new QPropertyAnimation(p1, "opacity"));
+ animation3.addAnimation(new QPropertyAnimation(p2, "opacity"));
+ animation3.addAnimation(new QPropertyAnimation(p3, "opacity"));
+ animation3.addAnimation(new QPropertyAnimation(p4, "opacity"));
+ animation3.addAnimation(new QPropertyAnimation(p5, "opacity"));
+ animation3.addAnimation(new QPropertyAnimation(p6, "opacity"));
+
+ QAbstractTransition *t1 = state1->addTransition(button, SIGNAL(clicked()), state2);
+ t1->addAnimation(&animation1);
+ QAbstractTransition *t2 = state2->addTransition(button, SIGNAL(clicked()), state3);
+ t2->addAnimation(&animation2);
+ QAbstractTransition *t3 = state3->addTransition(button, SIGNAL(clicked()), state1);
+ t3->addAnimation(&animation3);
+
+ machine.start();
+
+ QGraphicsView view(&scene);
+ view.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/animation/states/states.pro b/examples/animation/states/states.pro
new file mode 100644
index 0000000..f4d1e0b
--- /dev/null
+++ b/examples/animation/states/states.pro
@@ -0,0 +1,8 @@
+SOURCES += main.cpp
+RESOURCES += states.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/animation/states
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS states.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/animation/states
+INSTALLS += target sources
diff --git a/examples/animation/states/states.qrc b/examples/animation/states/states.qrc
new file mode 100644
index 0000000..60ab3f7
--- /dev/null
+++ b/examples/animation/states/states.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>accessories-dictionary.png</file>
+ <file>akregator.png</file>
+ <file>digikam.png</file>
+ <file>help-browser.png</file>
+ <file>k3b.png</file>
+ <file>kchart.png</file>
+</qresource>
+</RCC>
diff --git a/examples/animation/stickman/animation.cpp b/examples/animation/stickman/animation.cpp
new file mode 100644
index 0000000..c2c6bd1
--- /dev/null
+++ b/examples/animation/stickman/animation.cpp
@@ -0,0 +1,193 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "animation.h"
+
+#include <QPointF>
+#include <QIODevice>
+#include <QDataStream>
+
+class Frame
+{
+public:
+ Frame() {
+ }
+
+ int nodeCount() const
+ {
+ return m_nodePositions.size();
+ }
+
+ void setNodeCount(int nodeCount)
+ {
+ while (nodeCount > m_nodePositions.size())
+ m_nodePositions.append(QPointF());
+
+ while (nodeCount < m_nodePositions.size())
+ m_nodePositions.removeLast();
+ }
+
+ QPointF nodePos(int idx) const
+ {
+ return m_nodePositions.at(idx);
+ }
+
+ void setNodePos(int idx, const QPointF &pos)
+ {
+ m_nodePositions[idx] = pos;
+ }
+
+private:
+ QList<QPointF> m_nodePositions;
+};
+
+Animation::Animation()
+{
+ m_currentFrame = 0;
+ m_frames.append(new Frame);
+}
+
+Animation::~Animation()
+{
+ qDeleteAll(m_frames);
+}
+
+void Animation::setTotalFrames(int totalFrames)
+{
+ while (m_frames.size() < totalFrames)
+ m_frames.append(new Frame);
+
+ while (totalFrames < m_frames.size())
+ delete m_frames.takeLast();
+}
+
+int Animation::totalFrames() const
+{
+ return m_frames.size();
+}
+
+void Animation::setCurrentFrame(int currentFrame)
+{
+ m_currentFrame = qMax(qMin(currentFrame, totalFrames()-1), 0);
+}
+
+int Animation::currentFrame() const
+{
+ return m_currentFrame;
+}
+
+void Animation::setNodeCount(int nodeCount)
+{
+ Frame *frame = m_frames.at(m_currentFrame);
+ frame->setNodeCount(nodeCount);
+}
+
+int Animation::nodeCount() const
+{
+ Frame *frame = m_frames.at(m_currentFrame);
+ return frame->nodeCount();
+}
+
+void Animation::setNodePos(int idx, const QPointF &pos)
+{
+ Frame *frame = m_frames.at(m_currentFrame);
+ frame->setNodePos(idx, pos);
+}
+
+QPointF Animation::nodePos(int idx) const
+{
+ Frame *frame = m_frames.at(m_currentFrame);
+ return frame->nodePos(idx);
+}
+
+QString Animation::name() const
+{
+ return m_name;
+}
+
+void Animation::setName(const QString &name)
+{
+ m_name = name;
+}
+
+void Animation::save(QIODevice *device) const
+{
+ QDataStream stream(device);
+ stream << m_name;
+ stream << m_frames.size();
+ foreach (Frame *frame, m_frames) {
+ stream << frame->nodeCount();
+ for (int i=0; i<frame->nodeCount(); ++i)
+ stream << frame->nodePos(i);
+ }
+}
+
+void Animation::load(QIODevice *device)
+{
+ if (!m_frames.isEmpty())
+ qDeleteAll(m_frames);
+
+ m_frames.clear();
+
+ QDataStream stream(device);
+ stream >> m_name;
+
+ int frameCount;
+ stream >> frameCount;
+
+ for (int i=0; i<frameCount; ++i) {
+
+ int nodeCount;
+ stream >> nodeCount;
+
+ Frame *frame = new Frame;
+ frame->setNodeCount(nodeCount);
+
+ for (int j=0; j<nodeCount; ++j) {
+ QPointF pos;
+ stream >> pos;
+
+ frame->setNodePos(j, pos);
+ }
+
+ m_frames.append(frame);
+ }
+}
diff --git a/examples/animation/stickman/animation.h b/examples/animation/stickman/animation.h
new file mode 100644
index 0000000..b0b39c9
--- /dev/null
+++ b/examples/animation/stickman/animation.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANIMATION_H
+#define ANIMATION_H
+
+#include <QPointF>
+#include <QList>
+#include <QString>
+
+class Frame;
+QT_BEGIN_NAMESPACE
+class QIODevice;
+QT_END_NAMESPACE
+class Animation
+{
+public:
+ Animation();
+ ~Animation();
+
+ void setTotalFrames(int totalFrames);
+ int totalFrames() const;
+
+ void setCurrentFrame(int currentFrame);
+ int currentFrame() const;
+
+ void setNodeCount(int nodeCount);
+ int nodeCount() const;
+
+ void setNodePos(int idx, const QPointF &pos);
+ QPointF nodePos(int idx) const;
+
+ QString name() const;
+ void setName(const QString &name);
+
+ void save(QIODevice *device) const;
+ void load(QIODevice *device);
+
+private:
+ QString m_name;
+ QList<Frame *> m_frames;
+ int m_currentFrame;
+};
+
+#endif
diff --git a/examples/animation/stickman/animations/chilling b/examples/animation/stickman/animations/chilling
new file mode 100644
index 0000000..a81fc7a
--- /dev/null
+++ b/examples/animation/stickman/animations/chilling
Binary files differ
diff --git a/examples/animation/stickman/animations/dancing b/examples/animation/stickman/animations/dancing
new file mode 100644
index 0000000..462f66f
--- /dev/null
+++ b/examples/animation/stickman/animations/dancing
Binary files differ
diff --git a/examples/animation/stickman/animations/dead b/examples/animation/stickman/animations/dead
new file mode 100644
index 0000000..9859b4b
--- /dev/null
+++ b/examples/animation/stickman/animations/dead
Binary files differ
diff --git a/examples/animation/stickman/animations/jumping b/examples/animation/stickman/animations/jumping
new file mode 100644
index 0000000..12661a1
--- /dev/null
+++ b/examples/animation/stickman/animations/jumping
Binary files differ
diff --git a/examples/animation/stickman/editor/animationdialog.cpp b/examples/animation/stickman/editor/animationdialog.cpp
new file mode 100644
index 0000000..441517d
--- /dev/null
+++ b/examples/animation/stickman/editor/animationdialog.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "animationdialog.h"
+#include "stickman.h"
+#include "animation.h"
+#include "node.h"
+
+#include <QHBoxLayout>
+#include <QStackedWidget>
+#include <QSpinBox>
+#include <QPushButton>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMessageBox>
+#include <QFileDialog>
+
+AnimationDialog::AnimationDialog(StickMan *stickman, QWidget *parent)
+ : QDialog(parent), m_animation(0), m_stickman(stickman)
+{
+ initUi();
+}
+
+AnimationDialog::~AnimationDialog()
+{
+ delete m_animation;
+}
+
+void AnimationDialog::initUi()
+{
+ setWindowTitle("Animation");
+ setEnabled(false);
+
+ // Second page
+ m_currentFrame = new QSpinBox();
+ m_totalFrames = new QSpinBox();
+ m_name = new QLineEdit();
+
+ connect(m_currentFrame, SIGNAL(valueChanged(int)), this, SLOT(currentFrameChanged(int)));
+ connect(m_totalFrames, SIGNAL(valueChanged(int)), this, SLOT(totalFramesChanged(int)));
+ connect(m_name, SIGNAL(textChanged(QString)), this, SLOT(setCurrentAnimationName(QString)));
+
+ QGridLayout *gridLayout = new QGridLayout(this);
+ gridLayout->addWidget(new QLabel("Name:"), 0, 0, 1, 2);
+ gridLayout->addWidget(m_name, 0, 2, 1, 2);
+ gridLayout->addWidget(new QLabel("Frame:"), 1, 0);
+ gridLayout->addWidget(m_currentFrame, 1, 1);
+ gridLayout->addWidget(new QLabel("of total # of frames: "), 1, 2);
+ gridLayout->addWidget(m_totalFrames, 1, 3);
+}
+
+void AnimationDialog::initFromAnimation()
+{
+ m_currentFrame->setRange(0, m_animation->totalFrames()-1);
+ m_currentFrame->setValue(m_animation->currentFrame());
+
+ m_totalFrames->setRange(1, 1000);
+ m_totalFrames->setValue(m_animation->totalFrames());
+
+ m_name->setText(m_animation->name());
+}
+
+void AnimationDialog::saveAnimation()
+{
+ saveCurrentFrame();
+
+ QString fileName = QFileDialog::getSaveFileName(this, "Save animation");
+
+ QFile file(fileName);
+ if (file.open(QIODevice::WriteOnly))
+ m_animation->save(&file);
+}
+
+void AnimationDialog::loadAnimation()
+{
+ if (maybeSave() != QMessageBox::Cancel) {
+ QString fileName = QFileDialog::getOpenFileName(this, "Open animation");
+
+ QFile file(fileName);
+ if (file.open(QIODevice::ReadOnly)) {
+ if (m_animation == 0)
+ newAnimation();
+
+ m_animation->load(&file);
+ stickManFromCurrentFrame();
+ initFromAnimation();
+ }
+ }
+}
+
+QMessageBox::StandardButton AnimationDialog::maybeSave()
+{
+ if (m_animation == 0)
+ return QMessageBox::No;
+
+ QMessageBox::StandardButton button = QMessageBox::question(this, "Save?", "Do you want to save your changes?",
+ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+ if (button == QMessageBox::Save)
+ saveAnimation();
+
+ return button;
+}
+
+void AnimationDialog::newAnimation()
+{
+ if (maybeSave() != QMessageBox::Cancel) {
+ setEnabled(true);
+ delete m_animation;
+ m_animation = new Animation();
+ initFromAnimation();
+ }
+}
+
+// Gets the data from the stickman and stores it in current frame
+void AnimationDialog::saveCurrentFrame()
+{
+ int count = m_stickman->nodeCount();
+ m_animation->setNodeCount(count);
+ for (int i=0; i<count; ++i) {
+ QGraphicsItem *node = m_stickman->node(i);
+ m_animation->setNodePos(i, node->pos());
+ }
+}
+
+// Gets the data from the current frame and sets the stickman
+void AnimationDialog::stickManFromCurrentFrame()
+{
+ int count = m_animation->nodeCount();
+ for (int i=0;i<count;++i) {
+ QGraphicsItem *node = m_stickman->node(i);
+ node->setPos(m_animation->nodePos(i));
+ }
+}
+
+void AnimationDialog::currentFrameChanged(int currentFrame)
+{
+ saveCurrentFrame();
+ qDebug("currentFrame: %d", currentFrame);
+ m_animation->setCurrentFrame(currentFrame);
+ stickManFromCurrentFrame();
+ initFromAnimation();
+}
+
+void AnimationDialog::totalFramesChanged(int totalFrames)
+{
+ m_animation->setTotalFrames(totalFrames);
+ stickManFromCurrentFrame();
+ initFromAnimation();
+}
+
+void AnimationDialog::setCurrentAnimationName(const QString &name)
+{
+ m_animation->setName(name);
+}
diff --git a/examples/animation/stickman/editor/animationdialog.h b/examples/animation/stickman/editor/animationdialog.h
new file mode 100644
index 0000000..6025088
--- /dev/null
+++ b/examples/animation/stickman/editor/animationdialog.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANIMATIONDIALOG_H
+#define ANIMATIONDIALOG_H
+
+#include <QDialog>
+#include <QMessageBox>
+
+QT_BEGIN_NAMESPACE
+class QSpinBox;
+class QLineEdit;
+QT_END_NAMESPACE
+class StickMan;
+class Animation;
+class AnimationDialog: public QDialog
+{
+ Q_OBJECT
+public:
+ AnimationDialog(StickMan *stickMan, QWidget *parent = 0);
+ ~AnimationDialog();
+
+public slots:
+ void currentFrameChanged(int currentFrame);
+ void totalFramesChanged(int totalFrames);
+ void setCurrentAnimationName(const QString &name);
+
+ void newAnimation();
+ void saveAnimation();
+ void loadAnimation();
+
+private:
+ void saveCurrentFrame();
+ void stickManFromCurrentFrame();
+ void initFromAnimation();
+ void initUi();
+ QMessageBox::StandardButton maybeSave();
+
+ QSpinBox *m_currentFrame;
+ QSpinBox *m_totalFrames;
+ QLineEdit *m_name;
+ Animation *m_animation;
+ StickMan *m_stickman;
+};
+
+#endif
diff --git a/examples/animation/stickman/editor/editor.pri b/examples/animation/stickman/editor/editor.pri
new file mode 100644
index 0000000..7ad9edb
--- /dev/null
+++ b/examples/animation/stickman/editor/editor.pri
@@ -0,0 +1,2 @@
+SOURCES += $$PWD/animationdialog.cpp $$PWD/mainwindow.cpp
+HEADERS += $$PWD/animationdialog.h $$PWD/mainwindow.h
diff --git a/examples/animation/stickman/editor/mainwindow.cpp b/examples/animation/stickman/editor/mainwindow.cpp
new file mode 100644
index 0000000..c6464c6
--- /dev/null
+++ b/examples/animation/stickman/editor/mainwindow.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "animationdialog.h"
+#include "stickman.h"
+
+#include <QMenuBar>
+#include <QApplication>
+
+MainWindow::MainWindow(StickMan *stickMan)
+{
+ initActions(stickMan);
+}
+
+MainWindow::~MainWindow()
+{
+}
+
+void MainWindow::initActions(StickMan *stickMan)
+{
+ AnimationDialog *dialog = new AnimationDialog(stickMan, this);
+ dialog->show();
+
+ QMenu *fileMenu = menuBar()->addMenu("&File");
+ QAction *loadAction = fileMenu->addAction("&Open");
+ QAction *saveAction = fileMenu->addAction("&Save");
+ QAction *exitAction = fileMenu->addAction("E&xit");
+
+ QMenu *animationMenu = menuBar()->addMenu("&Animation");
+ QAction *newAnimationAction = animationMenu->addAction("&New animation");
+
+ connect(loadAction, SIGNAL(triggered()), dialog, SLOT(loadAnimation()));
+ connect(saveAction, SIGNAL(triggered()), dialog, SLOT(saveAnimation()));
+ connect(exitAction, SIGNAL(triggered()), QApplication::instance(), SLOT(quit()));
+ connect(newAnimationAction, SIGNAL(triggered()), dialog, SLOT(newAnimation()));
+
+}
diff --git a/examples/animation/stickman/editor/mainwindow.h b/examples/animation/stickman/editor/mainwindow.h
new file mode 100644
index 0000000..4c2b949
--- /dev/null
+++ b/examples/animation/stickman/editor/mainwindow.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+class StickMan;
+class MainWindow: public QMainWindow
+{
+public:
+ MainWindow(StickMan *stickMan);
+ ~MainWindow();
+
+private:
+ void initActions(StickMan *stickMan);
+};
+
+#endif
diff --git a/examples/animation/stickman/graphicsview.cpp b/examples/animation/stickman/graphicsview.cpp
new file mode 100644
index 0000000..754f3bc
--- /dev/null
+++ b/examples/animation/stickman/graphicsview.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "graphicsview.h"
+#include "editor/mainwindow.h"
+#include "stickman.h"
+
+#include <QtGui/QKeyEvent>
+#include <QtGui/QGraphicsScene>
+#include <QtGui/QGraphicsView>
+
+GraphicsView::GraphicsView(QWidget *parent) : QGraphicsView(parent), m_editor(0) {}
+
+void GraphicsView::keyPressEvent(QKeyEvent *e)
+{
+ if (e->key() == Qt::Key_Escape)
+ close();
+
+#if 0
+ if (e->key() == Qt::Key_F1) {
+ if (m_editor == 0) {
+ QGraphicsScene *scene = new QGraphicsScene;
+ StickMan *stickMan = new StickMan;
+ stickMan->setDrawSticks(true);
+ scene->addItem(stickMan);
+
+ QGraphicsView *view = new QGraphicsView;
+ view->setBackgroundBrush(Qt::black);
+ view->setRenderHints(QPainter::Antialiasing);
+ view->setScene(scene);
+
+ m_editor = new MainWindow(stickMan);
+ m_editor->setCentralWidget(view);
+ }
+
+ m_editor->showMaximized();
+ }
+#endif
+
+ emit keyPressed(Qt::Key(e->key()));
+}
+
+
diff --git a/examples/animation/stickman/graphicsview.h b/examples/animation/stickman/graphicsview.h
new file mode 100644
index 0000000..2515418
--- /dev/null
+++ b/examples/animation/stickman/graphicsview.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GRAPHICSVIEW_H
+#define GRAPHICSVIEW
+
+#include <QtGui/QGraphicsView>
+
+class MainWindow;
+class GraphicsView: public QGraphicsView
+{
+ Q_OBJECT
+public:
+ GraphicsView(QWidget *parent = 0);
+
+protected:
+ void keyPressEvent(QKeyEvent *);
+
+signals:
+ void keyPressed(int key);
+
+private:
+ MainWindow *m_editor;
+};
+
+#endif
diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp
new file mode 100644
index 0000000..eb4ed11
--- /dev/null
+++ b/examples/animation/stickman/lifecycle.cpp
@@ -0,0 +1,212 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "lifecycle.h"
+#include "stickman.h"
+#include "node.h"
+#include "animation.h"
+#include "graphicsview.h"
+
+#include <QtCore>
+#include <QtGui>
+
+class KeyPressTransition: public QSignalTransition
+{
+public:
+ KeyPressTransition(GraphicsView *receiver, Qt::Key key)
+ : QSignalTransition(receiver, SIGNAL(keyPressed(int))), m_key(key)
+ {
+ }
+ KeyPressTransition(GraphicsView *receiver, Qt::Key key, QAbstractState *target)
+ : QSignalTransition(receiver, SIGNAL(keyPressed(int)), QList<QAbstractState*>() << target), m_key(key)
+ {
+ }
+
+ virtual bool eventTest(QEvent *e)
+ {
+ if (QSignalTransition::eventTest(e)) {
+ QVariant key = static_cast<QSignalEvent*>(e)->arguments().at(0);
+ return (key.toInt() == int(m_key));
+ }
+
+ return false;
+ }
+private:
+ Qt::Key m_key;
+};
+
+//! [4]
+class LightningStrikesTransition: public QEventTransition
+{
+public:
+ LightningStrikesTransition(QAbstractState *target)
+ : QEventTransition(this, QEvent::Timer, QList<QAbstractState*>() << target)
+ {
+ qsrand((uint)QDateTime::currentDateTime().toTime_t());
+ startTimer(1000);
+ }
+
+ virtual bool eventTest(QEvent *e)
+ {
+ return QEventTransition::eventTest(e) && ((qrand() % 50) == 0);
+ }
+};
+//! [4]
+
+LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
+ : m_stickMan(stickMan), m_keyReceiver(keyReceiver)
+{
+ // Create animation group to be used for all transitions
+ m_animationGroup = new QParallelAnimationGroup();
+ const int stickManNodeCount = m_stickMan->nodeCount();
+ for (int i=0; i<stickManNodeCount; ++i) {
+ QPropertyAnimation *pa = new QPropertyAnimation(m_stickMan->node(i), "position");
+ m_animationGroup->addAnimation(pa);
+ }
+
+ // Set up intial state graph
+//! [3]
+ m_machine = new QStateMachine();
+ m_machine->addDefaultAnimation(m_animationGroup);
+//! [3]
+
+ m_alive = new QState(m_machine->rootState());
+ m_alive->setObjectName("alive");
+
+ // Make it blink when lightning strikes before entering dead animation
+ QState *lightningBlink = new QState(m_machine->rootState());
+ lightningBlink->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::white);
+ lightningBlink->assignProperty(m_stickMan, "penColor", Qt::black);
+ lightningBlink->assignProperty(m_stickMan, "fillColor", Qt::white);
+ lightningBlink->assignProperty(m_stickMan, "isDead", true);
+
+//! [5]
+ QTimer *timer = new QTimer(lightningBlink);
+ timer->setSingleShot(true);
+ timer->setInterval(100);
+ QObject::connect(lightningBlink, SIGNAL(entered()), timer, SLOT(start()));
+ QObject::connect(lightningBlink, SIGNAL(exited()), timer, SLOT(stop()));
+//! [5]
+
+ m_dead = new QState(m_machine->rootState());
+ m_dead->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::black);
+ m_dead->assignProperty(m_stickMan, "penColor", Qt::white);
+ m_dead->assignProperty(m_stickMan, "fillColor", Qt::black);
+ m_dead->setObjectName("dead");
+
+ // Idle state (sets no properties)
+ m_idle = new QState(m_alive);
+ m_idle->setObjectName("idle");
+
+ m_alive->setInitialState(m_idle);
+
+ // Lightning strikes at random
+ m_alive->addTransition(new LightningStrikesTransition(lightningBlink));
+//! [0]
+ lightningBlink->addTransition(timer, SIGNAL(timeout()), m_dead);
+//! [0]
+
+ m_machine->setInitialState(m_alive);
+}
+
+void LifeCycle::setDeathAnimation(const QString &fileName)
+{
+ QState *deathAnimation = makeState(m_dead, fileName);
+ m_dead->setInitialState(deathAnimation);
+}
+
+void LifeCycle::start()
+{
+ m_machine->start();
+}
+
+void LifeCycle::addActivity(const QString &fileName, Qt::Key key)
+{
+ QState *state = makeState(m_alive, fileName);
+ m_alive->addTransition(new KeyPressTransition(m_keyReceiver, key, state));
+}
+
+QState *LifeCycle::makeState(QState *parentState, const QString &animationFileName)
+{
+ QState *topLevel = new QState(parentState);
+
+ Animation animation;
+ {
+ QFile file(animationFileName);
+ if (file.open(QIODevice::ReadOnly))
+ animation.load(&file);
+ }
+
+ const int frameCount = animation.totalFrames();
+ QState *previousState = 0;
+ for (int i=0; i<frameCount; ++i) {
+ animation.setCurrentFrame(i);
+
+//! [1]
+ QState *frameState = new QState(topLevel);
+ const int nodeCount = animation.nodeCount();
+ for (int j=0; j<nodeCount; ++j)
+ frameState->assignProperty(m_stickMan->node(j), "position", animation.nodePos(j));
+//! [1]
+
+ frameState->setObjectName(QString::fromLatin1("frame %0").arg(i));
+ if (previousState == 0)
+ topLevel->setInitialState(frameState);
+ else
+//! [2]
+ previousState->addTransition(previousState, SIGNAL(polished()), frameState);
+//! [2]
+
+ previousState = frameState;
+ }
+
+ // Loop
+ previousState->addTransition(previousState, SIGNAL(polished()), topLevel->initialState());
+
+ return topLevel;
+
+}
+
+LifeCycle::~LifeCycle()
+{
+ delete m_machine;
+ delete m_animationGroup;
+}
diff --git a/examples/animation/stickman/lifecycle.h b/examples/animation/stickman/lifecycle.h
new file mode 100644
index 0000000..2be4762
--- /dev/null
+++ b/examples/animation/stickman/lifecycle.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LIFECYCLE_H
+#define LIFECYCLE_H
+
+#include <Qt>
+
+class StickMan;
+QT_BEGIN_NAMESPACE
+class QStateMachine;
+class QAnimationGroup;
+class QState;
+class QAbstractState;
+class QAbstractTransition;
+QT_END_NAMESPACE
+class GraphicsView;
+class LifeCycle
+{
+public:
+ LifeCycle(StickMan *stickMan, GraphicsView *keyEventReceiver);
+ ~LifeCycle();
+
+ void setDeathAnimation(const QString &fileName);
+ void addActivity(const QString &fileName, Qt::Key key);
+
+ void start();
+
+private:
+ QState *makeState(QState *parentState, const QString &animationFileName);
+
+ StickMan *m_stickMan;
+ QStateMachine *m_machine;
+ QAnimationGroup *m_animationGroup;
+ GraphicsView *m_keyReceiver;
+
+ QState *m_alive;
+ QState *m_dead;
+ QState *m_idle;
+};
+
+#endif
diff --git a/examples/animation/stickman/main.cpp b/examples/animation/stickman/main.cpp
new file mode 100644
index 0000000..62d8252
--- /dev/null
+++ b/examples/animation/stickman/main.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "animation.h"
+#include "node.h"
+#include "lifecycle.h"
+#include "stickman.h"
+#include "graphicsview.h"
+
+#include <QtCore>
+#include <QtGui>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ StickMan *stickMan = new StickMan;
+ stickMan->setDrawSticks(false);
+
+ QGraphicsTextItem *textItem = new QGraphicsTextItem();
+ textItem->setHtml("<font color=\"white\"><b>Stickman</b>"
+ "<p>"
+ "Tell the stickman what to do!"
+ "</p>"
+ "<p><i>"
+ "<li>Press <font color=\"purple\">J</font> to make the stickman jump.</li>"
+ "<li>Press <font color=\"purple\">D</font> to make the stickman dance.</li>"
+ "<li>Press <font color=\"purple\">C</font> to make him chill out.</li>"
+ "<li>When you are done, press <font color=\"purple\">Escape</font>.</li>"
+ "</i></p>"
+ "<p>If he is unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again."
+ "</p></font>");
+ qreal w = textItem->boundingRect().width();
+ QRectF stickManBoundingRect = stickMan->mapToScene(stickMan->boundingRect()).boundingRect();
+ textItem->setPos(-w / 2.0, stickManBoundingRect.bottom() + 25.0);
+
+ QGraphicsScene *scene = new QGraphicsScene();
+ scene->addItem(stickMan);
+ scene->addItem(textItem);
+ scene->setBackgroundBrush(Qt::black);
+
+ GraphicsView *view = new GraphicsView();
+ view->setRenderHints(QPainter::Antialiasing);
+ view->setTransformationAnchor(QGraphicsView::NoAnchor);
+ view->setScene(scene);
+ view->showFullScreen();
+ view->setFocus();
+ view->setSceneRect(scene->sceneRect());
+
+ LifeCycle *cycle = new LifeCycle(stickMan, view);
+ cycle->setDeathAnimation("animations/dead");
+
+ cycle->addActivity("animations/jumping", Qt::Key_J);
+ cycle->addActivity("animations/dancing", Qt::Key_D);
+ cycle->addActivity("animations/chilling", Qt::Key_C);
+ cycle->start();
+
+ return app.exec();
+}
diff --git a/examples/animation/stickman/node.cpp b/examples/animation/stickman/node.cpp
new file mode 100644
index 0000000..9c485d9
--- /dev/null
+++ b/examples/animation/stickman/node.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "node.h"
+#include "stickman.h"
+
+#include <QRectF>
+#include <QPainter>
+#include <QGraphicsSceneMouseEvent>
+
+Node::Node(const QPointF &pos, QGraphicsItem *parent)
+ : QGraphicsItem(parent), m_dragging(false)
+{
+ setPos(pos);
+}
+
+Node::~Node()
+{
+}
+
+QRectF Node::boundingRect() const
+{
+ return QRectF(-6.0, -6.0, 12.0, 12.0);
+}
+
+void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ painter->setPen(Qt::white);
+ painter->drawEllipse(QPointF(0.0, 0.0), 5.0, 5.0);
+}
+
+QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
+{
+ if (change == QGraphicsItem::ItemPositionChange)
+ emit positionChanged();
+
+ return QGraphicsItem::itemChange(change, value);
+}
+
+void Node::mousePressEvent(QGraphicsSceneMouseEvent *)
+{
+ m_dragging = true;
+}
+
+void Node::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (m_dragging)
+ setPos(mapToParent(event->pos()));
+}
+
+void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
+{
+ m_dragging = false;
+}
diff --git a/examples/animation/stickman/node.h b/examples/animation/stickman/node.h
new file mode 100644
index 0000000..72eae87
--- /dev/null
+++ b/examples/animation/stickman/node.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef NODE_H
+#define NODE_H
+
+#include <QGraphicsItem>
+
+class Node: public QObject, public QGraphicsItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QPointF position READ pos WRITE setPos);
+public:
+ Node(const QPointF &pos, QGraphicsItem *parent = 0);
+ ~Node();
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+signals:
+ void positionChanged();
+
+protected:
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+
+ void mousePressEvent(QGraphicsSceneMouseEvent *);
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *);
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
+
+private:
+ bool m_dragging;
+};
+
+#endif
diff --git a/examples/animation/stickman/stickman.cpp b/examples/animation/stickman/stickman.cpp
new file mode 100644
index 0000000..a3b200c
--- /dev/null
+++ b/examples/animation/stickman/stickman.cpp
@@ -0,0 +1,343 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "stickman.h"
+#include "node.h"
+
+#include <QPainter>
+#include <QTimer>
+
+#define _USE_MATH_DEFINES
+#include <math.h>
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+static const int NodeCount = 16;
+static const qreal Coords[NodeCount * 2] = {
+ 0.0, -150.0, // head, #0
+
+ 0.0, -100.0, // body pentagon, top->bottom, left->right, #1 - 5
+ -50.0, -50.0,
+ 50.0, -50.0,
+ -25.0, 50.0,
+ 25.0, 50.0,
+
+ -100.0, 0.0, // right arm, #6 - 7
+ -125.0, 50.0,
+
+ 100.0, 0.0, // left arm, #8 - 9
+ 125.0, 50.0,
+
+ -35.0, 75.0, // lower body, #10 - 11
+ 35.0, 75.0,
+
+ -25.0, 200.0, // right leg, #12 - 13
+ -30.0, 300.0,
+
+ 25.0, 200.0, // left leg, #14 - 15
+ 30.0, 300.0
+
+};
+
+static const int BoneCount = 24;
+static const int Bones[BoneCount * 2] = {
+ 0, 1, // neck
+
+ 1, 2, // body
+ 1, 3,
+ 1, 4,
+ 1, 5,
+ 2, 3,
+ 2, 4,
+ 2, 5,
+ 3, 4,
+ 3, 5,
+ 4, 5,
+
+ 2, 6, // right arm
+ 6, 7,
+
+ 3, 8, // left arm
+ 8, 9,
+
+ 4, 10, // lower body
+ 4, 11,
+ 5, 10,
+ 5, 11,
+ 10, 11,
+
+ 10, 12, // right leg
+ 12, 13,
+
+ 11, 14, // left leg
+ 14, 15
+
+};
+
+StickMan::StickMan()
+{
+ m_nodes = new Node*[NodeCount];
+ m_sticks = true;
+ m_isDead = false;
+ m_pixmap = QPixmap("images/head.png");
+ m_penColor = Qt::white;
+ m_fillColor = Qt::black;
+
+ // Set up start position of limbs
+ for (int i=0; i<NodeCount; ++i) {
+ m_nodes[i] = new Node(QPointF(Coords[i * 2], Coords[i * 2 + 1]), this);
+ connect(m_nodes[i], SIGNAL(positionChanged()), this, SLOT(childPositionChanged()));
+ }
+
+ m_perfectBoneLengths = new qreal[BoneCount];
+ for (int i=0; i<BoneCount; ++i) {
+ int n1 = Bones[i * 2];
+ int n2 = Bones[i * 2 + 1];
+
+ Node *node1 = m_nodes[n1];
+ Node *node2 = m_nodes[n2];
+
+ QPointF dist = node1->pos() - node2->pos();
+ m_perfectBoneLengths[i] = sqrt(pow(dist.x(),2) + pow(dist.y(),2));
+ }
+
+ startTimer(10);
+}
+
+StickMan::~StickMan()
+{
+ delete m_nodes;
+}
+
+void StickMan::childPositionChanged()
+{
+ prepareGeometryChange();
+}
+
+void StickMan::setDrawSticks(bool on)
+{
+ m_sticks = on;
+ for (int i=0;i<nodeCount();++i) {
+ Node *node = m_nodes[i];
+ node->setVisible(on);
+ }
+}
+
+QRectF StickMan::boundingRect() const
+{
+ // account for head radius=50.0 plus pen which is 5.0
+ return childrenBoundingRect().adjusted(-55.0, -55.0, 55.0, 55.0);
+}
+
+int StickMan::nodeCount() const
+{
+ return NodeCount;
+}
+
+Node *StickMan::node(int idx) const
+{
+ if (idx >= 0 && idx < NodeCount)
+ return m_nodes[idx];
+ else
+ return 0;
+}
+
+void StickMan::timerEvent(QTimerEvent *)
+{
+ update();
+}
+
+void StickMan::stabilize()
+{
+ static const qreal threshold = 0.001;
+
+ for (int i=0; i<BoneCount; ++i) {
+ int n1 = Bones[i * 2];
+ int n2 = Bones[i * 2 + 1];
+
+ Node *node1 = m_nodes[n1];
+ Node *node2 = m_nodes[n2];
+
+ QPointF pos1 = node1->pos();
+ QPointF pos2 = node2->pos();
+
+ QPointF dist = pos1 - pos2;
+ qreal length = sqrt(pow(dist.x(),2) + pow(dist.y(),2));
+ qreal diff = (length - m_perfectBoneLengths[i]) / length;
+
+ QPointF p = dist * (0.5 * diff);
+ if (p.x() > threshold && p.y() > threshold) {
+ pos1 -= p;
+ pos2 += p;
+
+ node1->setPos(pos1);
+ node2->setPos(pos2);
+ }
+ }
+}
+
+QPointF StickMan::posFor(int idx) const
+{
+ return m_nodes[idx]->pos();
+}
+
+//#include <QTime>
+void StickMan::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ /* static int frames = 0;
+ static QTime time;
+ if (frames++ % 100 == 0) {
+ frames = 1;
+ time.restart();
+ }
+
+ if (time.elapsed() > 0) {
+ painter->setPen(Qt::white);
+ painter->drawText(0, 0, QString::number(frames / (time.elapsed() / 1000.0)));
+ }*/
+
+ stabilize();
+ if (m_sticks) {
+ painter->setPen(Qt::white);
+ for (int i=0; i<BoneCount; ++i) {
+ int n1 = Bones[i * 2];
+ int n2 = Bones[i * 2 + 1];
+
+ Node *node1 = m_nodes[n1];
+ Node *node2 = m_nodes[n2];
+
+ painter->drawLine(node1->pos(), node2->pos());
+ }
+ } else {
+ // first bone is neck and will be used for head
+
+ QPainterPath path;
+ path.moveTo(posFor(0));
+ path.lineTo(posFor(1));
+
+ // right arm
+ path.lineTo(posFor(2));
+ path.lineTo(posFor(6));
+ path.lineTo(posFor(7));
+
+ // left arm
+ path.moveTo(posFor(3));
+ path.lineTo(posFor(8));
+ path.lineTo(posFor(9));
+
+ // body
+ path.moveTo(posFor(2));
+ path.lineTo(posFor(4));
+ path.lineTo(posFor(10));
+ path.lineTo(posFor(11));
+ path.lineTo(posFor(5));
+ path.lineTo(posFor(3));
+ path.lineTo(posFor(1));
+
+ // right leg
+ path.moveTo(posFor(10));
+ path.lineTo(posFor(12));
+ path.lineTo(posFor(13));
+
+ // left leg
+ path.moveTo(posFor(11));
+ path.lineTo(posFor(14));
+ path.lineTo(posFor(15));
+
+ painter->setPen(QPen(m_penColor, 5.0, Qt::SolidLine, Qt::RoundCap));
+ painter->drawPath(path);
+
+ {
+ int n1 = Bones[0];
+ int n2 = Bones[1];
+ Node *node1 = m_nodes[n1];
+ Node *node2 = m_nodes[n2];
+
+ QPointF dist = node2->pos() - node1->pos();
+
+ qreal sinAngle = dist.x() / sqrt(pow(dist.x(), 2) + pow(dist.y(), 2));
+ qreal angle = asin(sinAngle) * 180.0 / M_PI;
+
+ QPointF headPos = node1->pos();
+ painter->translate(headPos);
+ painter->rotate(-angle);
+
+ painter->setBrush(m_fillColor);
+ painter->drawEllipse(QPointF(0,0), 50.0, 50.0);
+
+ painter->setBrush(m_penColor);
+ painter->setPen(QPen(m_penColor, 2.5, Qt::SolidLine, Qt::RoundCap));
+
+ // eyes
+ if (m_isDead) {
+ painter->drawLine(-30.0, -30.0, -20.0, -20.0);
+ painter->drawLine(-20.0, -30.0, -30.0, -20.0);
+
+ painter->drawLine(20.0, -30.0, 30.0, -20.0);
+ painter->drawLine(30.0, -30.0, 20.0, -20.0);
+ } else {
+ painter->drawChord(QRectF(-30.0, -30.0, 25.0, 70.0), 30.0*16, 120.0*16);
+ painter->drawChord(QRectF(5.0, -30.0, 25.0, 70.0), 30.0*16, 120.0*16);
+ }
+
+ // mouth
+ if (m_isDead) {
+ painter->drawLine(-28.0, 2.0, 29.0, 2.0);
+ } else {
+ painter->setBrush(QColor(128, 0, 64 ));
+ painter->drawChord(QRectF(-28.0, 2.0-55.0/2.0, 57.0, 55.0), 0.0, -180.0*16);
+ }
+
+ // pupils
+ if (!m_isDead) {
+ painter->setPen(QPen(m_fillColor, 1.0, Qt::SolidLine, Qt::RoundCap));
+ painter->setBrush(m_fillColor);
+ painter->drawEllipse(QPointF(-12.0, -25.0), 5.0, 5.0);
+ painter->drawEllipse(QPointF(22.0, -25.0), 5.0, 5.0);
+ }
+ }
+ }
+}
+
+
+
diff --git a/examples/animation/stickman/stickman.h b/examples/animation/stickman/stickman.h
new file mode 100644
index 0000000..6395272
--- /dev/null
+++ b/examples/animation/stickman/stickman.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STICKMAN_H
+#define STICKMAN_H
+
+#include <QGraphicsItem>
+
+const int LimbCount = 16;
+
+class Node;
+QT_BEGIN_NAMESPACE
+class QTimer;
+QT_END_NAMESPACE
+class StickMan: public QObject, public QGraphicsItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QColor penColor WRITE setPenColor READ penColor)
+ Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor)
+ Q_PROPERTY(bool isDead WRITE setIsDead READ isDead)
+public:
+ StickMan();
+ ~StickMan();
+
+ virtual QRectF boundingRect() const;
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+ int nodeCount() const;
+ Node *node(int idx) const;
+
+ void setDrawSticks(bool on);
+ bool drawSticks() const { return m_sticks; }
+
+ QColor penColor() const { return m_penColor; }
+ void setPenColor(const QColor &color) { m_penColor = color; }
+
+ QColor fillColor() const { return m_fillColor; }
+ void setFillColor(const QColor &color) { m_fillColor = color; }
+
+ bool isDead() const { return m_isDead; }
+ void setIsDead(bool isDead) { m_isDead = isDead; }
+
+public slots:
+ void stabilize();
+ void childPositionChanged();
+
+protected:
+ void timerEvent(QTimerEvent *e);
+
+private:
+ QPointF posFor(int idx) const;
+
+ Node **m_nodes;
+ qreal *m_perfectBoneLengths;
+
+ uint m_sticks : 1;
+ uint m_isDead : 1;
+ uint m_reserved : 30;
+
+ QPixmap m_pixmap;
+ QColor m_penColor;
+ QColor m_fillColor;
+};
+
+#endif // STICKMAN_H
diff --git a/examples/animation/stickman/stickman.pro b/examples/animation/stickman/stickman.pro
new file mode 100644
index 0000000..1dbbce9
--- /dev/null
+++ b/examples/animation/stickman/stickman.pro
@@ -0,0 +1,21 @@
+HEADERS += stickman.h \
+ animation.h \
+ node.h \
+ lifecycle.h \
+ graphicsview.h
+SOURCES += main.cpp \
+ stickman.cpp \
+ animation.cpp \
+ node.cpp \
+ lifecycle.cpp \
+ graphicsview.cpp
+
+INCLUDEPATH += $$PWD
+
+include(editor/editor.pri)
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/animation/stickman
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS stickman.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/animation/stickman
+INSTALLS += target sources
diff --git a/examples/animation/sub-attaq/animationmanager.cpp b/examples/animation/sub-attaq/animationmanager.cpp
new file mode 100644
index 0000000..477d3bd
--- /dev/null
+++ b/examples/animation/sub-attaq/animationmanager.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "animationmanager.h"
+
+//Qt
+#include <QtCore/QAbstractAnimation>
+#include <QtCore/QDebug>
+
+// the universe's only animation manager
+AnimationManager *AnimationManager::instance = 0;
+
+AnimationManager::AnimationManager()
+{
+}
+
+AnimationManager *AnimationManager::self()
+{
+ if (!instance)
+ instance = new AnimationManager;
+ return instance;
+}
+
+void AnimationManager::registerAnimation(QAbstractAnimation *anim)
+{
+ animations.append(anim);
+}
+
+void AnimationManager::unregisterAnimation(QAbstractAnimation *anim)
+{
+ animations.removeAll(anim);
+}
+
+void AnimationManager::unregisterAllAnimations()
+{
+ animations.clear();
+}
+
+void AnimationManager::pauseAll()
+{
+ foreach (QAbstractAnimation* animation, animations)
+ {
+ if (animation->state() == QAbstractAnimation::Running)
+ animation->pause();
+ }
+}
+void AnimationManager::resumeAll()
+{
+ foreach (QAbstractAnimation* animation, animations)
+ {
+ if (animation->state() == QAbstractAnimation::Paused)
+ animation->resume();
+ }
+}
diff --git a/examples/animation/sub-attaq/animationmanager.h b/examples/animation/sub-attaq/animationmanager.h
new file mode 100644
index 0000000..a563c96
--- /dev/null
+++ b/examples/animation/sub-attaq/animationmanager.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANIMATIONMANAGER_H
+#define ANIMATIONMANAGER_H
+
+#include <QtCore/QObject>
+
+QT_BEGIN_NAMESPACE
+class QAbstractAnimation;
+QT_END_NAMESPACE
+
+class AnimationManager : public QObject
+{
+Q_OBJECT
+public:
+ AnimationManager();
+ void registerAnimation(QAbstractAnimation *anim);
+ void unregisterAnimation(QAbstractAnimation *anim);
+ void unregisterAllAnimations();
+ static AnimationManager *self();
+
+public slots:
+ void pauseAll();
+ void resumeAll();
+
+private:
+ static AnimationManager *instance;
+ QList<QAbstractAnimation *> animations;
+};
+
+#endif // ANIMATIONMANAGER_H
diff --git a/examples/animation/sub-attaq/boat.cpp b/examples/animation/sub-attaq/boat.cpp
new file mode 100644
index 0000000..63d12bb
--- /dev/null
+++ b/examples/animation/sub-attaq/boat.cpp
@@ -0,0 +1,318 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "boat.h"
+#include "boat_p.h"
+#include "bomb.h"
+#include "pixmapitem.h"
+#include "graphicsscene.h"
+#include "animationmanager.h"
+#include "custompropertyanimation.h"
+#include "qanimationstate.h"
+
+//Qt
+#include <QtCore/QPropertyAnimation>
+#include <QtCore/QStateMachine>
+#include <QtCore/QHistoryState>
+#include <QtCore/QFinalState>
+#include <QtCore/QState>
+#include <QtCore/QSequentialAnimationGroup>
+
+static QAbstractAnimation *setupDestroyAnimation(Boat *boat)
+{
+ QSequentialAnimationGroup *group = new QSequentialAnimationGroup(boat);
+#if QT_VERSION >=0x040500
+ PixmapItem *step1 = new PixmapItem(QString("explosion/boat/step1"),GraphicsScene::Big, boat);
+ step1->setZValue(6);
+ PixmapItem *step2 = new PixmapItem(QString("explosion/boat/step2"),GraphicsScene::Big, boat);
+ step2->setZValue(6);
+ PixmapItem *step3 = new PixmapItem(QString("explosion/boat/step3"),GraphicsScene::Big, boat);
+ step3->setZValue(6);
+ PixmapItem *step4 = new PixmapItem(QString("explosion/boat/step4"),GraphicsScene::Big, boat);
+ step4->setZValue(6);
+ step1->setOpacity(0);
+ step2->setOpacity(0);
+ step3->setOpacity(0);
+ step4->setOpacity(0);
+ CustomPropertyAnimation *anim1 = new CustomPropertyAnimation(boat);
+ anim1->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim1->setDuration(100);
+ anim1->setEndValue(1);
+ CustomPropertyAnimation *anim2 = new CustomPropertyAnimation(boat);
+ anim2->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim2->setDuration(100);
+ anim2->setEndValue(1);
+ CustomPropertyAnimation *anim3 = new CustomPropertyAnimation(boat);
+ anim3->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim3->setDuration(100);
+ anim3->setEndValue(1);
+ CustomPropertyAnimation *anim4 = new CustomPropertyAnimation(boat);
+ anim4->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim4->setDuration(100);
+ anim4->setEndValue(1);
+ CustomPropertyAnimation *anim5 = new CustomPropertyAnimation(boat);
+ anim5->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim5->setDuration(100);
+ anim5->setEndValue(0);
+ CustomPropertyAnimation *anim6 = new CustomPropertyAnimation(boat);
+ anim6->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim6->setDuration(100);
+ anim6->setEndValue(0);
+ CustomPropertyAnimation *anim7 = new CustomPropertyAnimation(boat);
+ anim7->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim7->setDuration(100);
+ anim7->setEndValue(0);
+ CustomPropertyAnimation *anim8 = new CustomPropertyAnimation(boat);
+ anim8->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim8->setDuration(100);
+ anim8->setEndValue(0);
+ group->addAnimation(anim1);
+ group->addAnimation(anim2);
+ group->addAnimation(anim3);
+ group->addAnimation(anim4);
+ group->addAnimation(anim5);
+ group->addAnimation(anim6);
+ group->addAnimation(anim7);
+ group->addAnimation(anim8);
+#else
+ // work around for a bug where we don't transition if the duration is zero.
+ QtPauseAnimation *anim = new QtPauseAnimation(group);
+ anim->setDuration(1);
+ group->addAnimation(anim);
+#endif
+ AnimationManager::self()->registerAnimation(group);
+ return group;
+}
+
+
+
+Boat::Boat(QGraphicsItem * parent, Qt::WindowFlags wFlags)
+ : QGraphicsWidget(parent,wFlags), speed(0), bombsAlreadyLaunched(0), direction(Boat::None), movementAnimation(0)
+{
+ pixmapItem = new PixmapItem(QString("boat"),GraphicsScene::Big, this);
+ setZValue(4);
+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsFocusable);
+ resize(pixmapItem->boundingRect().size());
+
+ //The movement animation used to animate the boat
+ movementAnimation = new QPropertyAnimation(this, "pos");
+
+ //The movement animation used to animate the boat
+ destroyAnimation = setupDestroyAnimation(this);
+
+ //We setup the state machien of the boat
+ machine = new QStateMachine(this);
+ QState *moving = new QState(machine->rootState());
+ StopState *stopState = new StopState(this, moving);
+ machine->setInitialState(moving);
+ moving->setInitialState(stopState);
+ MoveStateRight *moveStateRight = new MoveStateRight(this, moving);
+ MoveStateLeft *moveStateLeft = new MoveStateLeft(this, moving);
+ LaunchStateRight *launchStateRight = new LaunchStateRight(this, machine->rootState());
+ LaunchStateLeft *launchStateLeft = new LaunchStateLeft(this, machine->rootState());
+
+ //then setup the transitions for the rightMove state
+ KeyStopTransition *leftStopRight = new KeyStopTransition(this, QEvent::KeyPress, Qt::Key_Left);
+ leftStopRight->setTargetState(stopState);
+ KeyMoveTransition *leftMoveRight = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Left);
+ leftMoveRight->setTargetState(moveStateRight);
+ KeyMoveTransition *rightMoveRight = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right);
+ rightMoveRight->setTargetState(moveStateRight);
+ KeyMoveTransition *rightMoveStop = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right);
+ rightMoveStop->setTargetState(moveStateRight);
+
+ //then setup the transitions for the leftMove state
+ KeyStopTransition *rightStopLeft = new KeyStopTransition(this, QEvent::KeyPress, Qt::Key_Right);
+ rightStopLeft->setTargetState(stopState);
+ KeyMoveTransition *rightMoveLeft = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right);
+ rightMoveLeft->setTargetState(moveStateLeft);
+ KeyMoveTransition *leftMoveLeft = new KeyMoveTransition(this, QEvent::KeyPress,Qt::Key_Left);
+ leftMoveLeft->setTargetState(moveStateLeft);
+ KeyMoveTransition *leftMoveStop = new KeyMoveTransition(this, QEvent::KeyPress,Qt::Key_Left);
+ leftMoveStop->setTargetState(moveStateLeft);
+
+ //We set up the right move state
+ moveStateRight->addTransition(leftStopRight);
+ moveStateRight->addTransition(leftMoveRight);
+ moveStateRight->addTransition(rightMoveRight);
+ stopState->addTransition(rightMoveStop);
+
+ //We set up the left move state
+ moveStateLeft->addTransition(rightStopLeft);
+ moveStateLeft->addTransition(leftMoveLeft);
+ moveStateLeft->addTransition(rightMoveLeft);
+ stopState->addTransition(leftMoveStop);
+
+ //The animation is finished, it means we reached the border of the screen, the boat is stopped so we move to the stop state
+ moveStateLeft->addTransition(movementAnimation, SIGNAL(finished()), stopState);
+ moveStateRight->addTransition(movementAnimation, SIGNAL(finished()), stopState);
+
+ //We set up the keys for dropping bombs
+ KeyLaunchTransition *upFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up);
+ upFireLeft->setTargetState(launchStateRight);
+ KeyLaunchTransition *upFireRight = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up);
+ upFireRight->setTargetState(launchStateRight);
+ KeyLaunchTransition *upFireStop = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up);
+ upFireStop->setTargetState(launchStateRight);
+ KeyLaunchTransition *downFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down);
+ downFireLeft->setTargetState(launchStateLeft);
+ KeyLaunchTransition *downFireRight = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down);
+ downFireRight->setTargetState(launchStateLeft);
+ KeyLaunchTransition *downFireMove = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down);
+ downFireMove->setTargetState(launchStateLeft);
+
+ //We set up transitions for fire up
+ moveStateRight->addTransition(upFireRight);
+ moveStateLeft->addTransition(upFireLeft);
+ stopState->addTransition(upFireStop);
+
+ //We set up transitions for fire down
+ moveStateRight->addTransition(downFireRight);
+ moveStateLeft->addTransition(downFireLeft);
+ stopState->addTransition(downFireMove);
+
+ //Finally the launch state should come back to its original state
+ QHistoryState *historyState = new QHistoryState(moving);
+ launchStateLeft->addTransition(historyState);
+ launchStateRight->addTransition(historyState);
+
+ QFinalState *final = new QFinalState(machine->rootState());
+
+ //This state play the destroyed animation
+ QAnimationState *destroyedState = new QAnimationState(machine->rootState());
+ destroyedState->setAnimation(destroyAnimation);
+
+ //Play a nice animation when the boat is destroyed
+ moving->addTransition(this, SIGNAL(boatDestroyed()),destroyedState);
+
+ //Transition to final state when the destroyed animation is finished
+ destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final);
+
+ //The machine has finished to be executed, then the boat is dead
+ connect(machine,SIGNAL(finished()),this, SIGNAL(boatExecutionFinished()));
+
+}
+
+void Boat::run()
+{
+ //We register animations
+ AnimationManager::self()->registerAnimation(movementAnimation);
+ AnimationManager::self()->registerAnimation(destroyAnimation);
+ machine->start();
+}
+
+void Boat::stop()
+{
+ movementAnimation->stop();
+ machine->stop();
+}
+
+void Boat::updateBoatMovement()
+{
+ if (speed == 0 || direction == Boat::None) {
+ movementAnimation->stop();
+ return;
+ }
+
+ movementAnimation->stop();
+ movementAnimation->setStartValue(pos());
+
+ if (direction == Boat::Left) {
+ movementAnimation->setEndValue(QPointF(0,y()));
+ movementAnimation->setDuration(x()/speed*15);
+ }
+ else /*if (direction == Boat::Right)*/ {
+ movementAnimation->setEndValue(QPointF(scene()->width()-size().width(),y()));
+ movementAnimation->setDuration((scene()->width()-size().width()-x())/speed*15);
+ }
+ movementAnimation->start();
+}
+
+void Boat::destroy()
+{
+ movementAnimation->stop();
+ emit boatDestroyed();
+}
+
+int Boat::bombsLaunched() const
+{
+ return bombsAlreadyLaunched;
+}
+
+void Boat::setBombsLaunched(int number)
+{
+ if (number > MAX_BOMB) {
+ qWarning("Boat::setBombsLaunched : It impossible to launch that number of bombs");
+ return;
+ }
+ bombsAlreadyLaunched = number;
+}
+
+int Boat::currentSpeed() const
+{
+ return speed;
+}
+
+void Boat::setCurrentSpeed(int speed)
+{
+ if (speed > 3 || speed < 0) {
+ qWarning("Boat::setCurrentSpeed: The boat can't run on that speed");
+ return;
+ }
+ this->speed = speed;
+}
+
+enum Boat::Movement Boat::currentDirection() const
+{
+ return direction;
+}
+
+void Boat::setCurrentDirection(Movement direction)
+{
+ this->direction = direction;
+}
+
+int Boat::type() const
+{
+ return Type;
+}
diff --git a/examples/animation/sub-attaq/boat.h b/examples/animation/sub-attaq/boat.h
new file mode 100644
index 0000000..08a9fa2
--- /dev/null
+++ b/examples/animation/sub-attaq/boat.h
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __BOAT__H__
+#define __BOAT__H__
+
+//Qt
+#include <QtCore/QObject>
+#include <QtGui/QKeyEvent>
+
+#include <QtGui/QGraphicsWidget>
+
+class PixmapItem;
+class Bomb;
+QT_BEGIN_NAMESPACE
+class QVariantAnimation;
+class QAbstractAnimation;
+class QStateMachine;
+QT_END_NAMESPACE
+
+class Boat : public QGraphicsWidget
+{
+Q_OBJECT
+Q_PROPERTY(QPointF pos READ pos WRITE setPos)
+public:
+ enum Movement {
+ None = 0,
+ Left,
+ Right
+ };
+ enum { Type = UserType + 2 };
+ Boat(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
+ void destroy();
+ void run();
+ void stop();
+
+ int bombsLaunched() const;
+ void setBombsLaunched(int number);
+
+ int currentSpeed() const;
+ void setCurrentSpeed(int speed);
+
+ enum Movement currentDirection() const;
+ void setCurrentDirection(Movement direction);
+
+ void updateBoatMovement();
+
+ virtual int type() const;
+
+Q_SIGNALS:
+ void boatDestroyed();
+ void boatExecutionFinished();
+
+private:
+ int speed;
+ int bombsAlreadyLaunched;
+ Movement direction;
+ QVariantAnimation *movementAnimation;
+ QAbstractAnimation *destroyAnimation;
+ QStateMachine *machine;
+ PixmapItem *pixmapItem;
+};
+
+#endif //__BOAT__H__
diff --git a/examples/animation/sub-attaq/boat_p.h b/examples/animation/sub-attaq/boat_p.h
new file mode 100644
index 0000000..a8a24a6
--- /dev/null
+++ b/examples/animation/sub-attaq/boat_p.h
@@ -0,0 +1,256 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BOAT_P_H
+#define BOAT_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.
+//
+
+//Own
+#include "bomb.h"
+#include "graphicsscene.h"
+
+// Qt
+#include <QtGui/QKeyEventTransition>
+
+static const int MAX_BOMB = 5;
+
+
+//These transtion test if we have to stop the boat (i.e current speed is 1)
+class KeyStopTransition : public QKeyEventTransition
+{
+public:
+ KeyStopTransition(Boat *boat, QEvent::Type type, int key)
+ : QKeyEventTransition(boat, type, key)
+ {
+ this->boat = boat;
+ this->key = key;
+ }
+protected:
+ virtual bool eventTest(QEvent *event)
+ {
+ Q_UNUSED(event);
+ if (!QKeyEventTransition::eventTest(event))
+ return false;
+ if (boat->currentSpeed() == 1)
+ return true;
+ else
+ return false;
+ }
+private:
+ Boat * boat;
+ int key;
+};
+
+//These transtion test if we have to move the boat (i.e current speed was 0 or another value)
+ class KeyMoveTransition : public QKeyEventTransition
+{
+public:
+ KeyMoveTransition(Boat *boat, QEvent::Type type, int key)
+ : QKeyEventTransition(boat, type, key)
+ {
+ this->boat = boat;
+ this->key = key;
+ }
+protected:
+ virtual bool eventTest(QEvent *event)
+ {
+ Q_UNUSED(event);
+ if (!QKeyEventTransition::eventTest(event))
+ return false;
+ if (boat->currentSpeed() >= 0)
+ return true;
+ else
+ return false;
+
+ }
+ void onTransition(QEvent *)
+ {
+ //We decrease the speed if needed
+ if (key == Qt::Key_Left && boat->currentDirection() == Boat::Right)
+ boat->setCurrentSpeed(boat->currentSpeed() - 1);
+ else if (key == Qt::Key_Right && boat->currentDirection() == Boat::Left)
+ boat->setCurrentSpeed(boat->currentSpeed() - 1);
+ else if (boat->currentSpeed() < 3)
+ boat->setCurrentSpeed(boat->currentSpeed() + 1);
+ boat->updateBoatMovement();
+ }
+private:
+ Boat * boat;
+ int key;
+};
+
+//This transition trigger the bombs launch
+ class KeyLaunchTransition : public QKeyEventTransition
+{
+public:
+ KeyLaunchTransition(Boat *boat, QEvent::Type type, int key)
+ : QKeyEventTransition(boat, type, key)
+ {
+ this->boat = boat;
+ this->key = key;
+ }
+protected:
+ virtual bool eventTest(QEvent *event)
+ {
+ Q_UNUSED(event);
+ if (!QKeyEventTransition::eventTest(event))
+ return false;
+ //We have enough bomb?
+ if (boat->bombsLaunched() < MAX_BOMB)
+ return true;
+ else
+ return false;
+ }
+private:
+ Boat * boat;
+ int key;
+};
+
+//This state is describing when the boat is moving right
+class MoveStateRight : public QState
+{
+public:
+ MoveStateRight(Boat *boat,QState *parent = 0) : QState(parent)
+ {
+ this->boat = boat;
+ }
+protected:
+ void onEntry(QEvent *)
+ {
+ boat->setCurrentDirection(Boat::Right);
+ boat->updateBoatMovement();
+ }
+private:
+ Boat * boat;
+};
+
+ //This state is describing when the boat is moving left
+class MoveStateLeft : public QState
+{
+public:
+ MoveStateLeft(Boat *boat,QState *parent = 0) : QState(parent)
+ {
+ this->boat = boat;
+ }
+protected:
+ void onEntry(QEvent *)
+ {
+ boat->setCurrentDirection(Boat::Left);
+ boat->updateBoatMovement();
+ }
+private:
+ Boat * boat;
+};
+
+//This state is describing when the boat is in a stand by position
+class StopState : public QState
+{
+public:
+ StopState(Boat *boat,QState *parent = 0) : QState(parent)
+ {
+ this->boat = boat;
+ }
+protected:
+ void onEntry(QEvent *)
+ {
+ boat->setCurrentSpeed(0);
+ boat->setCurrentDirection(Boat::None);
+ boat->updateBoatMovement();
+ }
+private:
+ Boat * boat;
+};
+
+//This state is describing the launch of the torpedo on the right
+class LaunchStateRight : public QState
+{
+public:
+ LaunchStateRight(Boat *boat,QState *parent = 0) : QState(parent)
+ {
+ this->boat = boat;
+ }
+protected:
+ void onEntry(QEvent *)
+ {
+ Bomb *b = new Bomb();
+ b->setPos(boat->x()+boat->size().width(),boat->y());
+ GraphicsScene *scene = static_cast<GraphicsScene *>(boat->scene());
+ scene->addItem(b);
+ b->launch(Bomb::Right);
+ boat->setBombsLaunched(boat->bombsLaunched() + 1);
+ }
+private:
+ Boat * boat;
+};
+
+//This state is describing the launch of the torpedo on the left
+class LaunchStateLeft : public QState
+{
+public:
+ LaunchStateLeft(Boat *boat,QState *parent = 0) : QState(parent)
+ {
+ this->boat = boat;
+ }
+protected:
+ void onEntry(QEvent *)
+ {
+ Bomb *b = new Bomb();
+ b->setPos(boat->x() - b->size().width(), boat->y());
+ GraphicsScene *scene = static_cast<GraphicsScene *>(boat->scene());
+ scene->addItem(b);
+ b->launch(Bomb::Left);
+ boat->setBombsLaunched(boat->bombsLaunched() + 1);
+ }
+private:
+ Boat * boat;
+};
+
+#endif // BOAT_P_H
diff --git a/examples/animation/sub-attaq/bomb.cpp b/examples/animation/sub-attaq/bomb.cpp
new file mode 100644
index 0000000..f1f5324
--- /dev/null
+++ b/examples/animation/sub-attaq/bomb.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "bomb.h"
+#include "submarine.h"
+#include "pixmapitem.h"
+#include "animationmanager.h"
+#include "qanimationstate.h"
+
+//Qt
+#include <QtCore/QSequentialAnimationGroup>
+#include <QtCore/QPropertyAnimation>
+#include <QtCore/QStateMachine>
+#include <QtCore/QFinalState>
+
+Bomb::Bomb(QGraphicsItem * parent, Qt::WindowFlags wFlags)
+ : QGraphicsWidget(parent,wFlags), launchAnimation(0)
+{
+ pixmapItem = new PixmapItem(QString("bomb"),GraphicsScene::Big, this);
+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ setFlags(QGraphicsItem::ItemIsMovable);
+ setZValue(2);
+ resize(pixmapItem->boundingRect().size());
+}
+
+void Bomb::launch(Bomb::Direction direction)
+{
+ launchAnimation = new QSequentialAnimationGroup();
+ AnimationManager::self()->registerAnimation(launchAnimation);
+ qreal delta = direction == Right ? 20 : - 20;
+ QPropertyAnimation *anim = new QPropertyAnimation(this, "pos");
+ anim->setEndValue(QPointF(x() + delta,y() - 20));
+ anim->setDuration(150);
+ launchAnimation->addAnimation(anim);
+ anim = new QPropertyAnimation(this, "pos");
+ anim->setEndValue(QPointF(x() + delta*2, y() ));
+ anim->setDuration(150);
+ launchAnimation->addAnimation(anim);
+ anim = new QPropertyAnimation(this, "pos");
+ anim->setEndValue(QPointF(x() + delta*2,scene()->height()));
+ anim->setDuration(y()/2*60);
+ launchAnimation->addAnimation(anim);
+ connect(anim,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationLaunchValueChanged(const QVariant &)));
+
+ //We setup the state machine of the bomb
+ QStateMachine *machine = new QStateMachine(this);
+
+ //This state is when the launch animation is playing
+ QAnimationState *launched = new QAnimationState(machine->rootState());
+ launched->setAnimation(launchAnimation);
+
+ //End
+ QFinalState *final = new QFinalState(machine->rootState());
+
+ machine->setInitialState(launched);
+
+ //### Add a nice animation when the bomb is destroyed
+ launched->addTransition(this, SIGNAL(bombExplosed()),final);
+
+ //If the animation is finished, then we move to the final state
+ launched->addTransition(launched, SIGNAL(animationFinished()), final);
+
+ //The machine has finished to be executed, then the boat is dead
+ connect(machine,SIGNAL(finished()),this, SIGNAL(bombExecutionFinished()));
+
+ machine->start();
+
+}
+
+void Bomb::onAnimationLaunchValueChanged(const QVariant &)
+{
+ foreach (QGraphicsItem * item , collidingItems(Qt::IntersectsItemBoundingRect)) {
+ if (item->type() == SubMarine::Type) {
+ SubMarine *s = static_cast<SubMarine *>(item);
+ destroy();
+ s->destroy();
+ }
+ }
+}
+
+void Bomb::destroy()
+{
+ launchAnimation->stop();
+ emit bombExplosed();
+}
diff --git a/examples/animation/sub-attaq/bomb.h b/examples/animation/sub-attaq/bomb.h
new file mode 100644
index 0000000..226d056
--- /dev/null
+++ b/examples/animation/sub-attaq/bomb.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __BOMB__H__
+#define __BOMB__H__
+
+//Qt
+#include <QtGui/QGraphicsWidget>
+#include <QtCore/QAnimationGroup>
+
+class PixmapItem;
+
+class Bomb : public QGraphicsWidget
+{
+Q_OBJECT
+Q_PROPERTY(QPointF pos READ pos WRITE setPos)
+public:
+ enum Direction {
+ Left = 0,
+ Right
+ };
+ Bomb(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0);
+ void launch(Direction direction);
+ void destroy();
+
+Q_SIGNALS:
+ void bombExplosed();
+ void bombExecutionFinished();
+
+private slots:
+ void onAnimationLaunchValueChanged(const QVariant &);
+
+private:
+ QAnimationGroup *launchAnimation;
+ PixmapItem *pixmapItem;
+};
+
+#endif //__BOMB__H__
diff --git a/examples/animation/sub-attaq/custompropertyanimation.cpp b/examples/animation/sub-attaq/custompropertyanimation.cpp
new file mode 100644
index 0000000..8226cca
--- /dev/null
+++ b/examples/animation/sub-attaq/custompropertyanimation.cpp
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "custompropertyanimation.h"
+
+// Qt
+#include <QtCore/qdebug.h>
+
+CustomPropertyAnimation::CustomPropertyAnimation(QObject *parent) :
+ QVariantAnimation(parent), animProp(0)
+{
+}
+
+CustomPropertyAnimation::~CustomPropertyAnimation()
+{
+}
+
+void CustomPropertyAnimation::setProperty(AbstractProperty *_animProp)
+{
+ if (animProp == _animProp)
+ return;
+ delete animProp;
+ animProp = _animProp;
+}
+
+/*!
+ \reimp
+ */
+void CustomPropertyAnimation::updateCurrentValue(const QVariant &value)
+{
+ if (!animProp || state() == QAbstractAnimation::Stopped)
+ return;
+
+ animProp->write(value);
+}
+
+
+/*!
+ \reimp
+*/
+void CustomPropertyAnimation::updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState)
+{
+ // Initialize start value
+ if (oldState == QAbstractAnimation::Stopped) {
+ if (!animProp)
+ return;
+ QVariant def = animProp->read();
+ if (def.isValid()) {
+ const int t = def.userType();
+ KeyValues values = keyValues();
+ //this ensures that all the keyValues are of type t
+ for (int i = 0; i < values.count(); ++i) {
+ QVariantAnimation::KeyValue &pair = values[i];
+ if (pair.second.userType() != t)
+ pair.second.convert(static_cast<QVariant::Type>(t));
+ }
+ //let's now update the key values
+ setKeyValues(values);
+ }
+
+ if (animProp && !startValue().isValid() && currentTime() == 0
+ || (currentTime() == duration() && currentLoop() == (loopCount() - 1))) {
+ setStartValue(def);
+ }
+ }
+
+ QVariantAnimation::updateState(oldState, newState);
+}
+
+#include "moc_custompropertyanimation.cpp"
diff --git a/examples/animation/sub-attaq/custompropertyanimation.h b/examples/animation/sub-attaq/custompropertyanimation.h
new file mode 100644
index 0000000..8654aeb
--- /dev/null
+++ b/examples/animation/sub-attaq/custompropertyanimation.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CUSTOMPROPERTYANIMATION_H
+#define CUSTOMPROPERTYANIMATION_H
+
+#include <QtCore/qvariantanimation.h>
+
+QT_BEGIN_NAMESPACE
+class QGraphicsItem;
+QT_END_NAMESPACE
+
+struct AbstractProperty
+{
+ virtual QVariant read() const = 0;
+ virtual void write(const QVariant &value) = 0;
+};
+
+
+class CustomPropertyAnimation : public QVariantAnimation
+{
+ Q_OBJECT
+
+ template <typename Target, typename T, typename T2 = T>
+ class MemberFunctionProperty : public AbstractProperty
+ {
+ public:
+ typedef T (Target::*Getter)(void) const;
+ typedef void (Target::*Setter)(T2);
+
+ MemberFunctionProperty(Target* target, Getter getter, Setter setter)
+ : m_target(target), m_getter(getter), m_setter(setter) {}
+
+ virtual void write(const QVariant &value)
+ {
+ if (m_setter) (m_target->*m_setter)(qVariantValue<T>(value));
+ }
+
+ virtual QVariant read() const
+ {
+ if (m_getter) return qVariantFromValue<T>((m_target->*m_getter)());
+ return QVariant();
+ }
+
+ private:
+ Target *m_target;
+ Getter m_getter;
+ Setter m_setter;
+ };
+
+public:
+ CustomPropertyAnimation(QObject *parent = 0);
+ ~CustomPropertyAnimation();
+
+ template<class Target, typename T>
+ void setMemberFunctions(Target* target, T (Target::*getter)() const, void (Target::*setter)(const T& ))
+ {
+ setProperty(new MemberFunctionProperty<Target, T, const T&>(target, getter, setter));
+ }
+
+ template<class Target, typename T>
+ void setMemberFunctions(Target* target, T (Target::*getter)() const, void (Target::*setter)(T))
+ {
+ setProperty(new MemberFunctionProperty<Target, T>(target, getter, setter));
+ }
+
+ void updateCurrentValue(const QVariant &value);
+ void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState);
+ void setProperty(AbstractProperty *animProp);
+
+private:
+ Q_DISABLE_COPY(CustomPropertyAnimation);
+ AbstractProperty *animProp;
+};
+
+#endif // CUSTOMPROPERTYANIMATION_H
diff --git a/examples/animation/sub-attaq/data.xml b/examples/animation/sub-attaq/data.xml
new file mode 100644
index 0000000..41d4754
--- /dev/null
+++ b/examples/animation/sub-attaq/data.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<subattaq>
+ <submarines>
+ <submarine type="0" points="10" name="Q1" />
+ <submarine type="1" points="20" name="Q2" />
+ </submarines>
+ <levels>
+ <level id="0" name="Seaman recruit">
+ <subinstance type="0" nb="2"/>
+ </level>
+ <level id="1" name="Seaman apprentice">
+ <subinstance type="0" nb="4"/>
+ </level>
+ </levels>
+</subattaq>
diff --git a/examples/animation/sub-attaq/graphicsscene.cpp b/examples/animation/sub-attaq/graphicsscene.cpp
new file mode 100644
index 0000000..f2d41bc
--- /dev/null
+++ b/examples/animation/sub-attaq/graphicsscene.cpp
@@ -0,0 +1,374 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "graphicsscene.h"
+#include "states.h"
+#include "boat.h"
+#include "submarine.h"
+#include "torpedo.h"
+#include "bomb.h"
+#include "pixmapitem.h"
+#include "custompropertyanimation.h"
+#include "animationmanager.h"
+#include "qanimationstate.h"
+#include "progressitem.h"
+
+//Qt
+#include <QtCore/QPropertyAnimation>
+#include <QtCore/QSequentialAnimationGroup>
+#include <QtCore/QParallelAnimationGroup>
+#include <QtCore/QStateMachine>
+#include <QtCore/QFinalState>
+#include <QtCore/QPauseAnimation>
+#include <QtGui/QAction>
+#include <QtCore/QDir>
+#include <QtGui/QApplication>
+#include <QtGui/QMessageBox>
+#include <QtGui/QGraphicsView>
+#include <QtGui/QGraphicsSceneMouseEvent>
+#include <QtCore/QXmlStreamReader>
+
+//helper function that creates an animation for position and inserts it into group
+static CustomPropertyAnimation *addGraphicsItemPosAnimation(QSequentialAnimationGroup *group,
+ QGraphicsItem *item, const QPointF &endPos)
+{
+ CustomPropertyAnimation *ret = new CustomPropertyAnimation(group);
+ ret->setMemberFunctions(item, &QGraphicsItem::pos, &QGraphicsItem::setPos);
+ ret->setEndValue(endPos);
+ ret->setDuration(200);
+ ret->setEasingCurve(QEasingCurve::OutElastic);
+ group->addPause(50);
+ return ret;
+}
+
+//helper function that creates an animation for opacity and inserts it into group
+static void addGraphicsItemFadeoutAnimation(QAnimationGroup *group, QGraphicsItem *item)
+{
+#if QT_VERSION >=0x040500
+ CustomPropertyAnimation *anim = new CustomPropertyAnimation(group);
+ anim->setMemberFunctions(item, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim->setDuration(800);
+ anim->setEndValue(0);
+ anim->setEasingCurve(QEasingCurve::OutQuad);
+#else
+ // work around for a bug where we don't transition if the duration is zero.
+ QtPauseAnimation *anim = new QtPauseAnimation(group);
+ anim->setDuration(1);
+#endif
+}
+
+GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode)
+ : QGraphicsScene(x,y,width,height), mode(mode), newAction(0), quitAction(0), boat(0)
+{
+ backgroundItem = new PixmapItem(QString("background"),mode);
+ backgroundItem->setZValue(1);
+ backgroundItem->setPos(0,0);
+ addItem(backgroundItem);
+
+ PixmapItem *surfaceItem = new PixmapItem(QString("surface"),mode);
+ surfaceItem->setZValue(3);
+ surfaceItem->setPos(0,sealLevel() - surfaceItem->boundingRect().height()/2);
+ addItem(surfaceItem);
+
+ //The item that display score and level
+ progressItem = new ProgressItem(backgroundItem);
+
+ //We create the boat
+ boat = new Boat();
+ addItem(boat);
+ boat->setPos(this->width()/2, sealLevel() - boat->size().height());
+ boat->hide();
+
+ //parse the xml that contain all data of the game
+ QXmlStreamReader reader;
+ QFile file(QDir::currentPath() + "/data.xml");
+ file.open(QIODevice::ReadOnly);
+ reader.setDevice(&file);
+ LevelDescription currentLevel;
+ while (!reader.atEnd()) {
+ reader.readNext();
+ if (reader.tokenType() == QXmlStreamReader::StartElement) {
+ if (reader.name() == "submarine")
+ {
+ SubmarineDescription desc;
+ desc.name = reader.attributes().value("name").toString();
+ desc.points = reader.attributes().value("points").toString().toInt();
+ desc.type = reader.attributes().value("type").toString().toInt();
+ submarinesData.append(desc);
+ }
+ if (reader.name() == "level")
+ {
+ currentLevel.id = reader.attributes().value("id").toString().toInt();
+ currentLevel.name = reader.attributes().value("name").toString();
+ }
+ if (reader.name() == "subinstance")
+ {
+ currentLevel.submarines.append(qMakePair(reader.attributes().value("type").toString().toInt(),reader.attributes().value("nb").toString().toInt()));
+ }
+ }
+ if (reader.tokenType() == QXmlStreamReader::EndElement) {
+ if (reader.name() == "level")
+ {
+ levelsData.insert(currentLevel.id,currentLevel);
+ currentLevel.submarines.clear();
+ }
+ }
+ }
+}
+
+qreal GraphicsScene::sealLevel() const
+{
+ if (mode == Big)
+ return 220;
+ else
+ return 160;
+}
+
+void GraphicsScene::setupScene(const QList<QAction *> &actions)
+{
+ newAction = actions.at(0);
+ quitAction = actions.at(1);
+
+ QGraphicsItem *logo_s = addWelcomeItem(QPixmap(":/logo-s"));
+ QGraphicsItem *logo_u = addWelcomeItem(QPixmap(":/logo-u"));
+ QGraphicsItem *logo_b = addWelcomeItem(QPixmap(":/logo-b"));
+ QGraphicsItem *logo_dash = addWelcomeItem(QPixmap(":/logo-dash"));
+ QGraphicsItem *logo_a = addWelcomeItem(QPixmap(":/logo-a"));
+ QGraphicsItem *logo_t = addWelcomeItem(QPixmap(":/logo-t"));
+ QGraphicsItem *logo_t2 = addWelcomeItem(QPixmap(":/logo-t2"));
+ QGraphicsItem *logo_a2 = addWelcomeItem(QPixmap(":/logo-a2"));
+ QGraphicsItem *logo_q = addWelcomeItem(QPixmap(":/logo-q"));
+ QGraphicsItem *logo_excl = addWelcomeItem(QPixmap(":/logo-excl"));
+ logo_s->setZValue(3);
+ logo_u->setZValue(4);
+ logo_b->setZValue(5);
+ logo_dash->setZValue(6);
+ logo_a->setZValue(7);
+ logo_t->setZValue(8);
+ logo_t2->setZValue(9);
+ logo_a2->setZValue(10);
+ logo_q->setZValue(11);
+ logo_excl->setZValue(12);
+ logo_s->setPos(QPointF(-1000, -1000));
+ logo_u->setPos(QPointF(-800, -1000));
+ logo_b->setPos(QPointF(-600, -1000));
+ logo_dash->setPos(QPointF(-400, -1000));
+ logo_a->setPos(QPointF(1000, 2000));
+ logo_t->setPos(QPointF(800, 2000));
+ logo_t2->setPos(QPointF(600, 2000));
+ logo_a2->setPos(QPointF(400, 2000));
+ logo_q->setPos(QPointF(200, 2000));
+ logo_excl->setPos(QPointF(0, 2000));
+
+ QSequentialAnimationGroup * lettersGroupMoving = new QSequentialAnimationGroup(this);
+ QParallelAnimationGroup * lettersGroupFading = new QParallelAnimationGroup(this);
+
+ //creation of the animations for moving letters
+ addGraphicsItemPosAnimation(lettersGroupMoving, logo_s, QPointF(300, 150));
+ addGraphicsItemPosAnimation(lettersGroupMoving, logo_u, QPointF(350, 150));
+ addGraphicsItemPosAnimation(lettersGroupMoving, logo_b, QPointF(400, 120));
+ addGraphicsItemPosAnimation(lettersGroupMoving, logo_dash, QPointF(460, 150));
+ addGraphicsItemPosAnimation(lettersGroupMoving, logo_a, QPointF(350, 250));
+ addGraphicsItemPosAnimation(lettersGroupMoving, logo_t, QPointF(400, 250));
+ addGraphicsItemPosAnimation(lettersGroupMoving, logo_t2, QPointF(430, 250));
+ addGraphicsItemPosAnimation(lettersGroupMoving, logo_a2, QPointF(465, 250));
+ addGraphicsItemPosAnimation(lettersGroupMoving, logo_q, QPointF(510, 250));
+ addGraphicsItemPosAnimation(lettersGroupMoving, logo_excl, QPointF(570, 220));
+
+ //creation of the animations for fading out the letters
+ addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_s);
+ addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_u);
+ addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_b);
+ addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_dash);
+ addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_a);
+ addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_t);
+ addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_t2);
+ addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_a2);
+ addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_q);
+ addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_excl);
+ connect(lettersGroupFading, SIGNAL(finished()), this, SLOT(onIntroAnimationFinished()));
+
+ QStateMachine *machine = new QStateMachine(this);
+
+ //This state is when the player is playing
+ PlayState *gameState = new PlayState(this,machine->rootState());
+
+ //Final state
+ QFinalState *final = new QFinalState(machine->rootState());
+
+ //Animation when the player enter in the game
+ QAnimationState *lettersMovingState = new QAnimationState(machine->rootState());
+ lettersMovingState->setAnimation(lettersGroupMoving);
+
+ //Animation when the welcome screen disappear
+ QAnimationState *lettersFadingState = new QAnimationState(machine->rootState());
+ lettersFadingState->setAnimation(lettersGroupFading);
+
+ //if new game then we fade out the welcome screen and start playing
+ lettersMovingState->addTransition(newAction, SIGNAL(triggered()),lettersFadingState);
+ lettersFadingState->addTransition(lettersFadingState, SIGNAL(animationFinished()),gameState);
+
+ //New Game is triggered then player start playing
+ gameState->addTransition(newAction, SIGNAL(triggered()),gameState);
+
+ //Wanna quit, then connect to CTRL+Q
+ gameState->addTransition(quitAction, SIGNAL(triggered()),final);
+ lettersMovingState->addTransition(quitAction, SIGNAL(triggered()),final);
+
+ //Welcome screen is the initial state
+ machine->setInitialState(lettersMovingState);
+
+ machine->start();
+
+ //We reach the final state, then we quit
+ connect(machine,SIGNAL(finished()),this, SLOT(onQuitGameTriggered()));
+}
+
+void GraphicsScene::addItem(Bomb *bomb)
+{
+ bombs.insert(bomb);
+ connect(bomb,SIGNAL(bombExecutionFinished()),this, SLOT(onBombExecutionFinished()));
+ QGraphicsScene::addItem(bomb);
+}
+
+void GraphicsScene::addItem(Torpedo *torpedo)
+{
+ torpedos.insert(torpedo);
+ connect(torpedo,SIGNAL(torpedoExecutionFinished()),this, SLOT(onTorpedoExecutionFinished()));
+ QGraphicsScene::addItem(torpedo);
+}
+
+void GraphicsScene::addItem(SubMarine *submarine)
+{
+ submarines.insert(submarine);
+ connect(submarine,SIGNAL(subMarineExecutionFinished()),this, SLOT(onSubMarineExecutionFinished()));
+ QGraphicsScene::addItem(submarine);
+}
+
+void GraphicsScene::addItem(QGraphicsItem *item)
+{
+ QGraphicsScene::addItem(item);
+}
+
+void GraphicsScene::mousePressEvent (QGraphicsSceneMouseEvent * event)
+{
+ event->ignore();
+}
+
+void GraphicsScene::onQuitGameTriggered()
+{
+ qApp->closeAllWindows();
+}
+
+void GraphicsScene::onBombExecutionFinished()
+{
+ Bomb *bomb = qobject_cast<Bomb *>(sender());
+ bombs.remove(bomb);
+ bomb->deleteLater();
+ if (boat)
+ boat->setBombsLaunched(boat->bombsLaunched() - 1);
+}
+
+void GraphicsScene::onTorpedoExecutionFinished()
+{
+ Torpedo *torpedo = qobject_cast<Torpedo *>(sender());
+ torpedos.remove(torpedo);
+ torpedo->deleteLater();
+}
+
+void GraphicsScene::onSubMarineExecutionFinished()
+{
+ SubMarine *submarine = qobject_cast<SubMarine *>(sender());
+ submarines.remove(submarine);
+ if (submarines.count() == 0) {
+ emit allSubMarineDestroyed(submarine->points());
+ } else {
+ emit subMarineDestroyed(submarine->points());
+ }
+ submarine->deleteLater();
+}
+
+int GraphicsScene::remainingSubMarines() const
+{
+ return submarines.count();
+}
+
+void GraphicsScene::clearScene()
+{
+ foreach (SubMarine *sub,submarines) {
+ sub->destroy();
+ sub->deleteLater();
+ }
+
+ foreach (Torpedo *torpedo,torpedos) {
+ torpedo->destroy();
+ torpedo->deleteLater();
+ }
+
+ foreach (Bomb *bomb,bombs) {
+ bomb->destroy();
+ bomb->deleteLater();
+ }
+
+ submarines.clear();
+ bombs.clear();
+ torpedos.clear();
+
+ AnimationManager::self()->unregisterAllAnimations();
+
+ boat->stop();
+ boat->hide();
+}
+
+QGraphicsPixmapItem *GraphicsScene::addWelcomeItem(const QPixmap &pm)
+{
+ QGraphicsPixmapItem *item = addPixmap(pm);
+ welcomeItems << item;
+ return item;
+}
+
+void GraphicsScene::onIntroAnimationFinished()
+{
+ qDeleteAll(welcomeItems);
+ welcomeItems.clear();
+}
+
diff --git a/examples/animation/sub-attaq/graphicsscene.h b/examples/animation/sub-attaq/graphicsscene.h
new file mode 100644
index 0000000..8b0ea96
--- /dev/null
+++ b/examples/animation/sub-attaq/graphicsscene.h
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __GRAPHICSSCENE__H__
+#define __GRAPHICSSCENE__H__
+
+//Qt
+#include <QtGui/QGraphicsScene>
+#include <QtCore/QSet>
+#include <QtCore/QState>
+
+
+class Boat;
+class SubMarine;
+class Torpedo;
+class Bomb;
+class PixmapItem;
+class ProgressItem;
+QT_BEGIN_NAMESPACE
+class QAction;
+QT_END_NAMESPACE
+
+class GraphicsScene : public QGraphicsScene
+{
+Q_OBJECT
+public:
+ enum Mode {
+ Big = 0,
+ Small
+ };
+
+ struct SubmarineDescription {
+ int type;
+ int points;
+ QString name;
+ };
+
+ struct LevelDescription {
+ int id;
+ QString name;
+ QList<QPair<int,int> > submarines;
+ };
+
+ GraphicsScene(int x, int y, int width, int height, Mode mode = Big);
+ qreal sealLevel() const;
+ void setupScene(const QList<QAction *> &actions);
+ void addItem(Bomb *bomb);
+ void addItem(Torpedo *torpedo);
+ void addItem(SubMarine *submarine);
+ void addItem(QGraphicsItem *item);
+ int remainingSubMarines() const;
+ void clearScene();
+ QGraphicsPixmapItem *addWelcomeItem(const QPixmap &pm);
+
+Q_SIGNALS:
+ void subMarineDestroyed(int);
+ void allSubMarineDestroyed(int);
+
+protected:
+ void mousePressEvent (QGraphicsSceneMouseEvent * event);
+
+private slots:
+ void onQuitGameTriggered();
+ void onBombExecutionFinished();
+ void onTorpedoExecutionFinished();
+ void onSubMarineExecutionFinished();
+ void onIntroAnimationFinished();
+
+private:
+ Mode mode;
+ PixmapItem *backgroundItem;
+ ProgressItem *progressItem;
+ QAction * newAction;
+ QAction * quitAction;
+ Boat *boat;
+ QSet<SubMarine *> submarines;
+ QSet<Bomb *> bombs;
+ QSet<Torpedo *> torpedos;
+ QVector<QGraphicsPixmapItem *> welcomeItems;
+ QVector<SubmarineDescription> submarinesData;
+ QHash<int, LevelDescription> levelsData;
+
+ friend class PauseState;
+ friend class PlayState;
+ friend class LevelState;
+ friend class LostState;
+ friend class WinState;
+ friend class WinTransition;
+ friend class UpdateScoreTransition;
+};
+
+#endif //__GRAPHICSSCENE__H__
+
diff --git a/examples/animation/sub-attaq/main.cpp b/examples/animation/sub-attaq/main.cpp
new file mode 100644
index 0000000..ffaa86f
--- /dev/null
+++ b/examples/animation/sub-attaq/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Q_INIT_RESOURCE(subattaq);
+
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ MainWindow w;
+ w.show();
+
+ return app.exec();
+}
diff --git a/examples/animation/sub-attaq/mainwindow.cpp b/examples/animation/sub-attaq/mainwindow.cpp
new file mode 100644
index 0000000..a166241
--- /dev/null
+++ b/examples/animation/sub-attaq/mainwindow.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "mainwindow.h"
+#include "graphicsscene.h"
+
+#ifndef QT_NO_OPENGL
+ #include <QtOpenGL/QtOpenGL>
+#endif
+//Qt
+#include <QtGui/QGraphicsView>
+
+MainWindow::MainWindow() : QMainWindow(0)
+{
+ QMenuBar *menuBar = new QMenuBar;
+ QMenu *file = new QMenu(tr("&File"),menuBar);
+
+ QAction *newAction = new QAction(tr("New Game"),file);
+ newAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N));
+ file->addAction(newAction);
+ QAction *quitAction = new QAction(tr("Quit"),file);
+ quitAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
+ file->addAction(quitAction);
+
+ menuBar->addMenu(file);
+ setMenuBar(menuBar);
+
+ QStringList list = QApplication::arguments();
+ if (list.contains("-fullscreen")) {
+ scene = new GraphicsScene(0, 0, 750, 400,GraphicsScene::Small);
+ setWindowState(Qt::WindowFullScreen);
+ } else {
+ scene = new GraphicsScene(0, 0, 880, 630);
+ layout()->setSizeConstraint(QLayout::SetFixedSize);
+ }
+
+ view = new QGraphicsView(scene,this);
+ view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
+ QList<QAction *> actions;
+ actions << newAction << quitAction;
+ scene->setupScene(actions);
+#ifndef QT_NO_OPENGL
+ view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
+#endif
+
+ setCentralWidget(view);
+
+}
+
+MainWindow::~MainWindow()
+{
+}
+
diff --git a/examples/animation/sub-attaq/mainwindow.h b/examples/animation/sub-attaq/mainwindow.h
new file mode 100644
index 0000000..87f194a
--- /dev/null
+++ b/examples/animation/sub-attaq/mainwindow.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __MAINWINDOW__H__
+#define __MAINWINDOW__H__
+
+//Qt
+#include <QtGui/QMainWindow>
+class GraphicsScene;
+QT_BEGIN_NAMESPACE
+class QGraphicsView;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+Q_OBJECT
+public:
+ MainWindow();
+ ~MainWindow();
+
+private:
+ GraphicsScene *scene;
+ QGraphicsView *view;
+};
+
+#endif //__MAINWINDOW__H__
diff --git a/examples/animation/sub-attaq/pics/big/background.png b/examples/animation/sub-attaq/pics/big/background.png
new file mode 100644
index 0000000..9f58157
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/background.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/boat.png b/examples/animation/sub-attaq/pics/big/boat.png
new file mode 100644
index 0000000..be82dff
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/boat.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/bomb.png b/examples/animation/sub-attaq/pics/big/bomb.png
new file mode 100644
index 0000000..3af5f2f
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/bomb.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step1.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step1.png
new file mode 100644
index 0000000..c9fd8b0
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/explosion/boat/step1.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step2.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step2.png
new file mode 100644
index 0000000..7528f2d
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/explosion/boat/step2.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step3.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step3.png
new file mode 100644
index 0000000..aae9c9c
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/explosion/boat/step3.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step4.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step4.png
new file mode 100644
index 0000000..d697c1b
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/explosion/boat/step4.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step1.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step1.png
new file mode 100644
index 0000000..88ca514
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/explosion/submarine/step1.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step2.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step2.png
new file mode 100644
index 0000000..524f589
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/explosion/submarine/step2.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step3.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step3.png
new file mode 100644
index 0000000..2cca1e8
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/explosion/submarine/step3.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step4.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step4.png
new file mode 100644
index 0000000..82100a8
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/explosion/submarine/step4.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/submarine.png b/examples/animation/sub-attaq/pics/big/submarine.png
new file mode 100644
index 0000000..df435dc
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/submarine.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/surface.png b/examples/animation/sub-attaq/pics/big/surface.png
new file mode 100644
index 0000000..4eba29e
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/surface.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/big/torpedo.png b/examples/animation/sub-attaq/pics/big/torpedo.png
new file mode 100644
index 0000000..f9c2687
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/big/torpedo.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/scalable/background-n810.svg b/examples/animation/sub-attaq/pics/scalable/background-n810.svg
new file mode 100644
index 0000000..ece9f7a
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/scalable/background-n810.svg
@@ -0,0 +1,171 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ version="1.0"
+ width="744.09448"
+ height="1052.3622"
+ id="svg2588"
+ sodipodi:version="0.32"
+ inkscape:version="0.46"
+ sodipodi:docname="background-n810.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape">
+ <metadata
+ id="metadata28">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <sodipodi:namedview
+ inkscape:window-height="1141"
+ inkscape:window-width="1920"
+ inkscape:pageshadow="2"
+ inkscape:pageopacity="0.0"
+ guidetolerance="10.0"
+ gridtolerance="10.0"
+ objecttolerance="10.0"
+ borderopacity="1.0"
+ bordercolor="#666666"
+ pagecolor="#ffffff"
+ id="base"
+ showgrid="false"
+ inkscape:zoom="1.2399902"
+ inkscape:cx="375"
+ inkscape:cy="461.074"
+ inkscape:window-x="0"
+ inkscape:window-y="0"
+ inkscape:current-layer="layer1" />
+ <defs
+ id="defs2590">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 526.18109 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="744.09448 : 526.18109 : 1"
+ inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+ id="perspective30" />
+ <linearGradient
+ id="linearGradient3746">
+ <stop
+ id="stop3748"
+ style="stop-color:#ffffff;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3750"
+ style="stop-color:#0074b7;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <radialGradient
+ cx="82.966125"
+ cy="-178.42453"
+ r="526.79456"
+ fx="82.966125"
+ fy="-178.42453"
+ id="radialGradient3880"
+ xlink:href="#linearGradient3746"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1.4952094,0.2388475,-0.1040669,0.3734391,-208.61982,418.216)" />
+ <linearGradient
+ id="linearGradient3624">
+ <stop
+ id="stop3626"
+ style="stop-color:#3a8daf;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3636"
+ style="stop-color:#252525;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="552.98486"
+ y1="390.56842"
+ x2="549.39465"
+ y2="702.3479"
+ id="linearGradient3630"
+ xlink:href="#linearGradient3624"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(2.3373776,0,0,1.186038,-986.88716,67.776416)" />
+ <linearGradient
+ id="linearGradient3816">
+ <stop
+ id="stop3818"
+ style="stop-color:#ad8b00;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3820"
+ style="stop-color:#ad8b00;stop-opacity:0"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="573"
+ y1="755.46222"
+ x2="573"
+ y2="700.13464"
+ id="linearGradient3826"
+ xlink:href="#linearGradient3816"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1,0,0,1.2561681,-151.5,-34.518664)" />
+ <linearGradient
+ id="linearGradient5097">
+ <stop
+ id="stop5099"
+ style="stop-color:#19a2db;stop-opacity:0"
+ offset="0" />
+ <stop
+ id="stop5109"
+ style="stop-color:#1379a7;stop-opacity:0.49803922"
+ offset="0.30000001" />
+ <stop
+ id="stop5101"
+ style="stop-color:#0e5173;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="590.84674"
+ y1="274.57559"
+ x2="590.84674"
+ y2="334.01376"
+ id="linearGradient5103"
+ xlink:href="#linearGradient5097"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(-151.5,156.75229)"
+ spreadMethod="pad" />
+ </defs>
+ <g
+ id="layer1">
+ <rect
+ width="1053.5891"
+ height="206.64989"
+ x="-151.79456"
+ y="330.16019"
+ id="rect3638"
+ style="opacity:1;fill:url(#radialGradient3880);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.1880002;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ width="1054.4708"
+ height="364.81519"
+ x="-152.23541"
+ y="533.48895"
+ id="rect3622"
+ style="opacity:1;fill:url(#linearGradient3630);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.13464069;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M -152.5,877.11847 C 120.5,865.81296 -202.86309,769.3663 109.5,871.29717 C 172.96247,892.00636 243.5,872.55334 297.5,871.29717 C 351.5,870.041 311.5,859.80335 358.5,876.13354 C 405.5,892.46372 553.5,861.09903 598.5,854.8182 C 643.5,848.53736 756.5,841.79698 795.5,853.10249 C 834.5,864.408 904.5,866.2725 904.5,866.2725 L 901.5,903.95754 L -154.5,902.70137 L -152.5,877.11847 z"
+ id="path3814"
+ style="fill:url(#linearGradient3826);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ d="M 902.20121,894.16261 C 632.01828,889.43035 756.73005,860.2801 614.20403,894.1311 C 596.58819,898.315 408.23621,883.21212 400.43291,894.1311 C 376.86263,927.11261 75.265447,868.1243 34.250926,886.79082 C 31.281885,888.14209 12.514878,884.22134 -12.264082,889.72008 C -48.555335,897.77353 -64.717178,885.62471 -103.31472,890.35697 C -141.91229,895.08922 -145.87102,891.93439 -145.87102,891.93439 L -152.79879,903.10131 L 892.3044,902.5755 L 902.20121,894.16261 z"
+ id="path3828"
+ style="fill:#ad8b00;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ </g>
+</svg>
diff --git a/examples/animation/sub-attaq/pics/scalable/background.svg b/examples/animation/sub-attaq/pics/scalable/background.svg
new file mode 100644
index 0000000..0be2680
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/scalable/background.svg
@@ -0,0 +1,171 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ version="1.0"
+ width="744.09448"
+ height="1052.3622"
+ id="svg2588"
+ sodipodi:version="0.32"
+ inkscape:version="0.46"
+ sodipodi:docname="background.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape">
+ <metadata
+ id="metadata28">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <sodipodi:namedview
+ inkscape:window-height="1141"
+ inkscape:window-width="1920"
+ inkscape:pageshadow="2"
+ inkscape:pageopacity="0.0"
+ guidetolerance="10.0"
+ gridtolerance="10.0"
+ objecttolerance="10.0"
+ borderopacity="1.0"
+ bordercolor="#666666"
+ pagecolor="#ffffff"
+ id="base"
+ showgrid="false"
+ inkscape:zoom="0.93884027"
+ inkscape:cx="473.72605"
+ inkscape:cy="538.63678"
+ inkscape:window-x="0"
+ inkscape:window-y="0"
+ inkscape:current-layer="layer1" />
+ <defs
+ id="defs2590">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 526.18109 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="744.09448 : 526.18109 : 1"
+ inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+ id="perspective30" />
+ <linearGradient
+ id="linearGradient3746">
+ <stop
+ id="stop3748"
+ style="stop-color:#ffffff;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3750"
+ style="stop-color:#0074b7;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <radialGradient
+ cx="82.966125"
+ cy="-178.42453"
+ r="526.79456"
+ fx="82.966125"
+ fy="-178.42453"
+ id="radialGradient3880"
+ xlink:href="#linearGradient3746"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1.4952094,0.3367191,-0.1040669,0.5264617,-208.61982,282.52272)" />
+ <linearGradient
+ id="linearGradient3624">
+ <stop
+ id="stop3626"
+ style="stop-color:#3a8daf;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3636"
+ style="stop-color:#252525;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="552.98486"
+ y1="390.56842"
+ x2="549.39465"
+ y2="702.3479"
+ id="linearGradient3630"
+ xlink:href="#linearGradient3624"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(2.3373776,0,0,1.5004634,-986.88716,-154.07447)" />
+ <linearGradient
+ id="linearGradient3816">
+ <stop
+ id="stop3818"
+ style="stop-color:#ad8b00;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3820"
+ style="stop-color:#ad8b00;stop-opacity:0"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="573"
+ y1="755.46222"
+ x2="573"
+ y2="700.13464"
+ id="linearGradient3826"
+ xlink:href="#linearGradient3816"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1,0,0,1.6033628,-151.5,-294.0167)" />
+ <linearGradient
+ id="linearGradient5097">
+ <stop
+ id="stop5099"
+ style="stop-color:#19a2db;stop-opacity:0"
+ offset="0" />
+ <stop
+ id="stop5109"
+ style="stop-color:#1379a7;stop-opacity:0.49803922"
+ offset="0.30000001" />
+ <stop
+ id="stop5101"
+ style="stop-color:#0e5173;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="590.84674"
+ y1="274.57559"
+ x2="590.84674"
+ y2="334.01376"
+ id="linearGradient5103"
+ xlink:href="#linearGradient5097"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(-151.5,156.75229)"
+ spreadMethod="pad" />
+ </defs>
+ <g
+ id="layer1">
+ <rect
+ width="1053.5891"
+ height="291.32797"
+ x="-151.79456"
+ y="158.38464"
+ id="rect3638"
+ style="opacity:1;fill:url(#radialGradient3880);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.1880002;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ width="1054.4708"
+ height="461.52972"
+ x="-152.23541"
+ y="435.10107"
+ id="rect3622"
+ style="opacity:1;fill:url(#linearGradient3630);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.13464069;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M -152.5,869.5896 C 120.5,855.15934 -202.86309,732.0556 109.5,862.15934 C 172.96247,888.59238 243.5,863.7627 297.5,862.15934 C 351.5,860.55598 311.5,847.48872 358.5,868.33244 C 405.5,889.17615 553.5,849.14252 598.5,841.12571 C 643.5,833.1089 756.5,824.50553 795.5,838.9358 C 834.5,853.36606 904.5,855.74589 904.5,855.74589 L 901.5,903.84677 L -154.5,902.24341 L -152.5,869.5896 z"
+ id="path3814"
+ style="fill:url(#linearGradient3826);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ d="M 902.20121,891.3446 C 632.01828,885.30439 756.73005,848.09724 614.20403,891.30439 C 596.58819,896.64468 408.23621,877.36748 400.43291,891.30439 C 376.86263,933.40172 75.265447,858.10952 34.250926,881.93531 C 31.281885,883.66006 12.514878,878.65564 -12.264082,885.67419 C -48.555335,895.95355 -64.717178,880.4469 -103.31472,886.48711 C -141.91229,892.52732 -145.87102,888.50052 -145.87102,888.50052 L -152.79879,902.75389 L 892.3044,902.08275 L 902.20121,891.3446 z"
+ id="path3828"
+ style="fill:#ad8b00;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ </g>
+</svg>
diff --git a/examples/animation/sub-attaq/pics/scalable/boat.svg b/examples/animation/sub-attaq/pics/scalable/boat.svg
new file mode 100644
index 0000000..5298821b
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/scalable/boat.svg
@@ -0,0 +1,279 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ version="1.0"
+ width="744.09448"
+ height="1052.3622"
+ id="svg2584">
+ <defs
+ id="defs2666">
+ <linearGradient
+ x1="542.5"
+ y1="222.59448"
+ x2="559"
+ y2="222.59448"
+ id="linearGradient3387"
+ xlink:href="#linearGradient3746"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(-110.6791,190.19124)" />
+ <linearGradient
+ id="linearGradient3167">
+ <stop
+ id="stop3169"
+ style="stop-color:#464646;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3345"
+ style="stop-color:#848788;stop-opacity:1"
+ offset="0.44021741" />
+ <stop
+ id="stop3347"
+ style="stop-color:#9ca0a2;stop-opacity:1"
+ offset="0.56799388" />
+ <stop
+ id="stop3171"
+ style="stop-color:#b5babd;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="474.23065"
+ y1="229.92336"
+ x2="474.1944"
+ y2="218.27365"
+ id="linearGradient3416"
+ xlink:href="#linearGradient3167"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(-125.98032,185.95625)" />
+ <linearGradient
+ id="linearGradient3692">
+ <stop
+ id="stop3694"
+ style="stop-color:#ffffff;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3696"
+ style="stop-color:#b6b6b6;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="573.5"
+ y1="244.2056"
+ x2="578.25"
+ y2="216.9556"
+ id="linearGradient3972"
+ xlink:href="#linearGradient3692"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(-126.5541,188.56624)" />
+ <linearGradient
+ id="linearGradient3438">
+ <stop
+ id="stop3440"
+ style="stop-color:#939393;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3444"
+ style="stop-color:#d6d6d6;stop-opacity:1"
+ offset="0.12354442" />
+ <stop
+ id="stop3446"
+ style="stop-color:#dadada;stop-opacity:1"
+ offset="0.74055624" />
+ <stop
+ id="stop3442"
+ style="stop-color:#ffffff;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="660.29303"
+ y1="256.53284"
+ x2="444.79303"
+ y2="255.62085"
+ id="linearGradient3948"
+ xlink:href="#linearGradient3438"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(-126.5541,185.56624)" />
+ <linearGradient
+ x1="542.5"
+ y1="222.59448"
+ x2="559"
+ y2="222.59448"
+ id="linearGradient3990"
+ xlink:href="#linearGradient3746"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(-132.8041,190.19124)" />
+ <linearGradient
+ id="linearGradient3746">
+ <stop
+ id="stop3748"
+ style="stop-color:#ffffff;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3750"
+ style="stop-color:#0074b7;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="542.5"
+ y1="222.59448"
+ x2="559"
+ y2="222.59448"
+ id="linearGradient3994"
+ xlink:href="#linearGradient3746"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(-88.054101,190.19124)" />
+ <linearGradient
+ id="linearGradient3428">
+ <stop
+ id="stop3430"
+ style="stop-color:#464646;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3432"
+ style="stop-color:#848788;stop-opacity:1"
+ offset="0.18306103" />
+ <stop
+ id="stop3434"
+ style="stop-color:#9ca0a2;stop-opacity:1"
+ offset="0.66368055" />
+ <stop
+ id="stop3436"
+ style="stop-color:#b5babd;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="592.92798"
+ y1="199.43727"
+ x2="557.05743"
+ y2="196.5448"
+ id="linearGradient3426"
+ xlink:href="#linearGradient3428"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(-102.5217,149.09845)" />
+ </defs>
+ <g
+ id="layer1">
+ <g
+ id="boat">
+ <path
+ d="M 296.669,434.15623 C 376.12538,436.50959 448.282,436.46711 542.42304,434.15623 C 542.42304,434.15623 544.22253,425.03531 542.42304,422.57953 C 432.90655,403.86953 296.669,418.12547 296.669,422.57953 L 296.669,434.15623 z"
+ id="path3469"
+ style="fill:#a9a9a9;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3.4975698;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" />
+ <rect
+ width="3.4280596"
+ height="29.611124"
+ x="647.59613"
+ y="173.91156"
+ transform="matrix(0.9327494,0.3605254,-0.3633626,0.9316478,0,0)"
+ id="rect3408"
+ style="opacity:1;fill:#333333;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ width="48.499989"
+ height="8.5"
+ x="318.48221"
+ y="405.82172"
+ transform="matrix(0.9999952,3.0887777e-3,-3.0887777e-3,0.9999952,0,0)"
+ id="rect3376"
+ style="opacity:1;fill:url(#linearGradient3416);fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:2.99999928;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 382.4459,430.66072 C 382.4459,430.66072 420.85999,388.74829 397.4459,385.66072 L 488.4459,397.66072 L 488.4459,432.66072 L 382.4459,430.66072 z"
+ id="path3952"
+ style="fill:url(#linearGradient3972);fill-opacity:1;fill-rule:evenodd;stroke:#323232;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 301.4459,429.66072 C 301.4459,429.66072 330.46329,468.66072 343.4459,468.66072 C 355.42851,471.91072 507.57644,473.70653 525.4459,465.91072 C 534.58031,461.59104 537.90602,455.58662 539.4459,429.66072 C 473.70193,439.43306 371.2651,439.78219 301.4459,429.66072 z"
+ id="path3938"
+ style="fill:url(#linearGradient3948);fill-opacity:1;fill-rule:evenodd;stroke:#545454;stroke-width:3.0999999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 339.44863,416.12222 L 357.69854,416.17859 L 368.1622,427.96097 L 339.41234,427.87217 L 339.44863,416.12222 z"
+ id="rect3378"
+ style="fill:#dedede;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" />
+ <rect
+ width="13.5"
+ height="17"
+ x="411.19589"
+ y="404.28574"
+ id="rect3974"
+ style="opacity:1;fill:url(#linearGradient3990);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ width="13.5"
+ height="17"
+ x="455.94589"
+ y="404.28574"
+ id="rect3992"
+ style="opacity:1;fill:url(#linearGradient3994);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 295.6959,421.91072 C 360.77923,430.41072 446.61257,432.91072 541.9459,421.91072 C 541.9459,421.91072 543.74902,428.6076 541.9459,430.41072 C 432.20839,444.14823 295.6959,433.68104 295.6959,430.41072 L 295.6959,421.91072 z"
+ id="rect2558"
+ style="fill:#dedede;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" />
+ <rect
+ width="94.427879"
+ height="7.236649"
+ x="437.10614"
+ y="342.2645"
+ transform="matrix(0.9947793,0.1020501,-0.1079723,0.9941539,0,0)"
+ id="rect2569"
+ style="opacity:1;fill:#c1c1c1;fill-opacity:1;fill-rule:nonzero;stroke:#404040;stroke-width:3.0365274;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ width="13.5"
+ height="17"
+ x="433.32089"
+ y="404.28574"
+ id="rect3385"
+ style="opacity:1;fill:url(#linearGradient3387);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 402.86916,380.21847 L 489.80407,388.85485 L 491.52271,394.54919 L 397.58781,384.91281 L 402.86916,380.21847 z"
+ id="rect3466"
+ style="fill:#dcdcdc;fill-opacity:1;fill-rule:nonzero;stroke:#404040;stroke-width:3.03650045;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" />
+ <rect
+ width="34.5"
+ height="14.5"
+ x="456.4783"
+ y="336.94293"
+ transform="matrix(0.997157,7.5351915e-2,-7.5351915e-2,0.997157,0,0)"
+ id="rect3418"
+ style="opacity:1;fill:url(#linearGradient3426);fill-opacity:1;fill-rule:nonzero;stroke:#494949;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <g
+ transform="matrix(0.9246214,0.3808874,-0.3808874,0.9246214,-13.252851,-40.129692)"
+ id="flag">
+ <rect
+ width="19.75"
+ height="27.75"
+ x="193.34448"
+ y="-709"
+ transform="matrix(0,1,-1,0,0,0)"
+ id="rect3389"
+ style="opacity:1;fill:#b20000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ width="27.25"
+ height="5.75"
+ x="681.5"
+ y="200.59448"
+ id="rect3393"
+ style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ width="5.75"
+ height="19.5"
+ x="691.25"
+ y="193.59448"
+ id="rect3395"
+ style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ width="27.75"
+ height="2.5"
+ x="681.5"
+ y="202.34448"
+ id="rect3397"
+ style="opacity:1;fill:#000080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ width="3"
+ height="19.25"
+ x="692.5"
+ y="193.59448"
+ id="rect3399"
+ style="opacity:1;fill:#000080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ </g>
+ </g>
+ </g>
+</svg>
diff --git a/examples/animation/sub-attaq/pics/scalable/bomb.svg b/examples/animation/sub-attaq/pics/scalable/bomb.svg
new file mode 100644
index 0000000..294771a
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/scalable/bomb.svg
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ version="1.0"
+ width="744.09448"
+ height="1052.3622"
+ id="svg3121">
+ <defs
+ id="defs3123">
+ <radialGradient
+ cx="-135.625"
+ cy="148.71948"
+ r="7.625"
+ fx="-135.625"
+ fy="148.71948"
+ id="radialGradient3439"
+ xlink:href="#linearGradient3366"
+ gradientUnits="userSpaceOnUse" />
+ <linearGradient
+ x1="-132.85063"
+ y1="173.6969"
+ x2="-145.3662"
+ y2="177.59828"
+ id="linearGradient3418"
+ xlink:href="#linearGradient3366"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(-0.2134297,-0.5943658,0.6658882,-0.2391126,-274.53441,123.00067)" />
+ <linearGradient
+ x1="-141.85466"
+ y1="181.49153"
+ x2="-144.95044"
+ y2="175.90179"
+ id="linearGradient3414"
+ xlink:href="#linearGradient3366"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.2134297,-0.5943658,-0.6658882,-0.2391126,-15.893355,122.67824)" />
+ <linearGradient
+ x1="-149.5"
+ y1="177.59448"
+ x2="-145.7928"
+ y2="180.05936"
+ id="linearGradient3410"
+ xlink:href="#linearGradient3366"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(-0.6315243,0,0,0.7075182,-227.03781,54.321514)" />
+ <linearGradient
+ x1="-140.46242"
+ y1="177.40488"
+ x2="-147.04802"
+ y2="172.66473"
+ id="linearGradient3406"
+ xlink:href="#linearGradient3366"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(-0.6315243,0,0,-0.7075182,-226.40365,274.91611)" />
+ <linearGradient
+ x1="-147.2406"
+ y1="180.95567"
+ x2="-140.01878"
+ y2="175.57777"
+ id="linearGradient3402"
+ xlink:href="#linearGradient3366"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.6315243,0,0,-0.7075182,-64.045217,275.07466)" />
+ <linearGradient
+ x1="-146.98956"
+ y1="174.00922"
+ x2="-142.60332"
+ y2="179.38712"
+ id="linearGradient3398"
+ xlink:href="#linearGradient3366"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.6315243,0,0,0.7075182,-62.683611,54.187362)" />
+ <linearGradient
+ id="linearGradient3366">
+ <stop
+ id="stop3368"
+ style="stop-color:#bcbcbc;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3370"
+ style="stop-color:#191b1c;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <radialGradient
+ cx="-208.95004"
+ cy="173.10576"
+ r="31.667252"
+ fx="-208.95004"
+ fy="173.10576"
+ id="radialGradient3364"
+ xlink:href="#linearGradient3366"
+ gradientUnits="userSpaceOnUse" />
+ </defs>
+ <g
+ id="layer1">
+ <g
+ transform="translate(419.4996,488.13454)"
+ id="mine">
+ <path
+ d="M -167.5843,186.54079 A 31.466251,31.466251 0 1 1 -230.5168,186.54079 A 31.466251,31.466251 0 1 1 -167.5843,186.54079 z"
+ transform="matrix(0.6341613,0,0,0.6341613,-18.521242,45.718192)"
+ id="path2586"
+ style="opacity:1;fill:url(#radialGradient3364);fill-opacity:1;stroke:#131313;stroke-width:3.54799318;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M -155.20193,175.4167 C -157.60085,176.6451 -156.78074,184.26068 -156.78074,184.26068 C -156.78074,184.26068 -148.33787,181.58301 -148.57092,178.60053 C -148.74283,176.40051 -153.23774,174.41092 -155.20193,175.4167 z"
+ id="path3382"
+ style="fill:url(#linearGradient3398);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M -156.56354,153.84532 C -158.96246,152.61693 -158.14235,145.00135 -158.14235,145.00135 C -158.14235,145.00135 -149.69948,147.67902 -149.93253,150.66149 C -150.10444,152.86151 -154.59935,154.85111 -156.56354,153.84532 z"
+ id="path3400"
+ style="fill:url(#linearGradient3402);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M -133.88532,153.68678 C -131.48641,152.45838 -132.30652,144.8428 -132.30652,144.8428 C -132.30652,144.8428 -140.74938,147.52047 -140.51633,150.50295 C -140.34442,152.70297 -135.84951,154.69256 -133.88532,153.68678 z"
+ id="path3404"
+ style="fill:url(#linearGradient3406);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M -134.51948,175.55085 C -132.12057,176.77925 -132.94068,184.39483 -132.94068,184.39483 C -132.94068,184.39483 -141.38355,181.71716 -141.15049,178.73469 C -140.97858,176.53467 -136.48367,174.54507 -134.51948,175.55085 z"
+ id="path3408"
+ style="fill:url(#linearGradient3410);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M -161.25709,168.78221 C -163.22395,170.62484 -170.11427,165.85236 -170.11427,165.85236 C -170.11427,165.85236 -164.7408,160.23808 -162.01257,161.46538 C -160.00011,162.37068 -159.64667,167.27352 -161.25709,168.78221 z"
+ id="path3412"
+ style="fill:url(#linearGradient3414);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M -129.17068,169.10464 C -127.20382,170.94727 -120.3135,166.17478 -120.3135,166.17478 C -120.3135,166.17478 -125.68697,160.5605 -128.41519,161.7878 C -130.42766,162.69311 -130.7811,167.59595 -129.17068,169.10464 z"
+ id="path3416"
+ style="fill:url(#linearGradient3418);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M -126,151.21948 A 6.625,6.625 0 1 1 -139.25,151.21948 A 6.625,6.625 0 1 1 -126,151.21948 z"
+ transform="matrix(0.6341613,0,0,0.6341613,-61.039517,68.324922)"
+ id="path3426"
+ style="opacity:1;fill:url(#radialGradient3439);fill-opacity:1;stroke:#131313;stroke-width:3.54799318;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ </g>
+ </g>
+</svg>
diff --git a/examples/animation/sub-attaq/pics/scalable/sand.svg b/examples/animation/sub-attaq/pics/scalable/sand.svg
new file mode 100644
index 0000000..8af11b7
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/scalable/sand.svg
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ version="1.0"
+ width="744.09448"
+ height="1052.3622"
+ id="svg2596">
+ <defs
+ id="defs2598">
+ <linearGradient
+ id="linearGradient3708">
+ <stop
+ id="stop3710"
+ style="stop-color:#202020;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3712"
+ style="stop-color:#ffffff;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="518.26996"
+ y1="497.31476"
+ x2="533.02924"
+ y2="497.31476"
+ id="linearGradient3794"
+ xlink:href="#linearGradient3708"
+ gradientUnits="userSpaceOnUse" />
+ <linearGradient
+ id="linearGradient3718">
+ <stop
+ id="stop3720"
+ style="stop-color:#bcbcbc;stop-opacity:0.28169015"
+ offset="0" />
+ <stop
+ id="stop3722"
+ style="stop-color:#bcbcbc;stop-opacity:0"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="516.89508"
+ y1="503.50137"
+ x2="516.89508"
+ y2="543.80646"
+ id="linearGradient3792"
+ xlink:href="#linearGradient3718"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.9947644,0,0,1.3346457,2.7877039,-166.60153)" />
+ <linearGradient
+ id="linearGradient3692">
+ <stop
+ id="stop3694"
+ style="stop-color:#ffffff;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3696"
+ style="stop-color:#b6b6b6;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="506.95975"
+ y1="469.73706"
+ x2="525.41608"
+ y2="469.73706"
+ id="linearGradient3790"
+ xlink:href="#linearGradient3692"
+ gradientUnits="userSpaceOnUse" />
+ <linearGradient
+ id="linearGradient3816">
+ <stop
+ id="stop3818"
+ style="stop-color:#ad8b00;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3820"
+ style="stop-color:#ad8b00;stop-opacity:0"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="573"
+ y1="755.46222"
+ x2="573"
+ y2="700.13464"
+ id="linearGradient3826"
+ xlink:href="#linearGradient3816"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1,0,0,1.6033628,-150.63569,-350.3846)" />
+ </defs>
+ <g
+ id="layer1">
+ <path
+ d="M -151.63569,813.2217 C 121.3643,798.79144 -201.99878,675.6877 110.3643,805.79144 C 173.82677,832.22448 244.3643,807.3948 298.3643,805.79144 C 352.3643,804.18808 312.3643,791.12082 359.3643,811.96454 C 406.3643,832.80825 554.3643,792.77462 599.3643,784.75781 C 644.3643,776.741 757.36426,768.13763 796.36426,782.5679 C 835.36426,796.99816 905.36426,799.37799 905.36426,799.37799 L 902.36426,847.47887 L -153.63569,845.87551 L -151.63569,813.2217 z"
+ id="path3814"
+ style="fill:url(#linearGradient3826);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ d="M 908.86426,836.95812 C 635.8643,830.91791 761.87636,793.71076 617.8643,836.91791 C 600.0648,842.2582 409.74894,822.981 401.8643,836.91791 C 378.04825,879.01524 73.306465,803.72304 31.864305,827.54883 C 28.864305,829.27358 9.9016246,824.26916 -15.135695,831.28771 C -51.805335,841.56707 -68.135695,826.06042 -107.1357,832.10063 C -146.1357,838.14084 -150.13569,834.11404 -150.13569,834.11404 L -157.13569,848.36741 L 898.86426,847.69627 L 908.86426,836.95812 z"
+ id="path3828"
+ style="fill:#ad8b00;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ </g>
+</svg>
diff --git a/examples/animation/sub-attaq/pics/scalable/see.svg b/examples/animation/sub-attaq/pics/scalable/see.svg
new file mode 100644
index 0000000..0666691
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/scalable/see.svg
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ version="1.0"
+ width="744.09448"
+ height="1052.3622"
+ id="svg2650">
+ <defs
+ id="defs2652">
+ <linearGradient
+ id="linearGradient3624">
+ <stop
+ id="stop3626"
+ style="stop-color:#3a8daf;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3636"
+ style="stop-color:#252525;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="552.98486"
+ y1="390.56842"
+ x2="549.39465"
+ y2="702.3479"
+ id="linearGradient3630"
+ xlink:href="#linearGradient3624"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(2.3373776,0,0,1.5004634,-996.17287,-279.00679)" />
+ </defs>
+ <g
+ id="layer1">
+ <rect
+ width="1054.4708"
+ height="461.52972"
+ x="-161.52115"
+ y="310.16876"
+ id="rect3622"
+ style="opacity:1;fill:url(#linearGradient3630);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.13464069;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ </g>
+</svg>
diff --git a/examples/animation/sub-attaq/pics/scalable/sky.svg b/examples/animation/sub-attaq/pics/scalable/sky.svg
new file mode 100644
index 0000000..1546c08
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/scalable/sky.svg
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ version="1.0"
+ width="744.09448"
+ height="1052.3622"
+ id="svg2721">
+ <defs
+ id="defs2723">
+ <linearGradient
+ id="linearGradient3746">
+ <stop
+ id="stop3748"
+ style="stop-color:#ffffff;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3750"
+ style="stop-color:#0074b7;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <radialGradient
+ cx="82.966125"
+ cy="-178.42453"
+ r="526.79456"
+ fx="82.966125"
+ fy="-178.42453"
+ id="radialGradient3880"
+ xlink:href="#linearGradient3746"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1.4952094,0.3367191,-0.1040669,0.5264617,-235.04839,425.12197)" />
+ </defs>
+ <g
+ id="layer1">
+ <rect
+ width="1053.5891"
+ height="291.32797"
+ x="-178.22313"
+ y="300.98392"
+ id="rect3638"
+ style="opacity:1;fill:url(#radialGradient3880);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.1880002;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ </g>
+</svg>
diff --git a/examples/animation/sub-attaq/pics/scalable/sub-attaq.svg b/examples/animation/sub-attaq/pics/scalable/sub-attaq.svg
new file mode 100644
index 0000000..b075179
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/scalable/sub-attaq.svg
@@ -0,0 +1,1473 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="1052.3622"
+ height="744.09448"
+ id="svg2"
+ sodipodi:version="0.32"
+ inkscape:version="0.46"
+ version="1.0"
+ sodipodi:docname="sub-attaq.svg"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape">
+ <defs
+ id="defs4">
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3366"
+ id="radialGradient3439"
+ cx="-135.625"
+ cy="148.71948"
+ fx="-135.625"
+ fy="148.71948"
+ r="7.625"
+ gradientUnits="userSpaceOnUse" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3366"
+ id="linearGradient3418"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(-0.2134297,-0.5943658,0.6658882,-0.2391126,-274.53441,123.00067)"
+ x1="-132.85063"
+ y1="173.6969"
+ x2="-145.3662"
+ y2="177.59828" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3366"
+ id="linearGradient3414"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.2134297,-0.5943658,-0.6658882,-0.2391126,-15.893355,122.67824)"
+ x1="-141.85466"
+ y1="181.49153"
+ x2="-144.95044"
+ y2="175.90179" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3366"
+ id="linearGradient3410"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(-0.6315243,0,0,0.7075182,-227.03781,54.321514)"
+ x1="-149.5"
+ y1="177.59448"
+ x2="-145.7928"
+ y2="180.05936" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3366"
+ id="linearGradient3406"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(-0.6315243,0,0,-0.7075182,-226.40365,274.91611)"
+ x1="-140.46242"
+ y1="177.40488"
+ x2="-147.04802"
+ y2="172.66473" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3366"
+ id="linearGradient3402"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.6315243,0,0,-0.7075182,-64.045217,275.07466)"
+ x1="-147.2406"
+ y1="180.95567"
+ x2="-140.01878"
+ y2="175.57777" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3366"
+ id="linearGradient3398"
+ x1="-146.98956"
+ y1="174.00922"
+ x2="-142.60332"
+ y2="179.38712"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.6315243,0,0,0.7075182,-62.683611,54.187362)" />
+ <linearGradient
+ id="linearGradient3366">
+ <stop
+ id="stop3368"
+ offset="0"
+ style="stop-color:#bcbcbc;stop-opacity:1;" />
+ <stop
+ id="stop3370"
+ offset="1"
+ style="stop-color:#191b1c;stop-opacity:1;" />
+ </linearGradient>
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3366"
+ id="radialGradient3364"
+ cx="-208.95004"
+ cy="173.10576"
+ fx="-208.95004"
+ fy="173.10576"
+ r="31.667252"
+ gradientUnits="userSpaceOnUse" />
+ <linearGradient
+ id="linearGradient5097">
+ <stop
+ style="stop-color:#19a2db;stop-opacity:0;"
+ offset="0"
+ id="stop5099" />
+ <stop
+ id="stop5109"
+ offset="0.30000001"
+ style="stop-color:#1379a7;stop-opacity:0.49803922;" />
+ <stop
+ style="stop-color:#0e5173;stop-opacity:1;"
+ offset="1"
+ id="stop5101" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3523"
+ inkscape:collect="always">
+ <stop
+ id="stop3525"
+ offset="0"
+ style="stop-color:#b9b9b9;stop-opacity:1" />
+ <stop
+ id="stop3527"
+ offset="1"
+ style="stop-color:#444444;stop-opacity:0;" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3438">
+ <stop
+ style="stop-color:#939393;stop-opacity:1;"
+ offset="0"
+ id="stop3440" />
+ <stop
+ id="stop3444"
+ offset="0.12354442"
+ style="stop-color:#d6d6d6;stop-opacity:1;" />
+ <stop
+ style="stop-color:#dadada;stop-opacity:1;"
+ offset="0.74055624"
+ id="stop3446" />
+ <stop
+ style="stop-color:#ffffff;stop-opacity:1;"
+ offset="1"
+ id="stop3442" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3428">
+ <stop
+ id="stop3430"
+ offset="0"
+ style="stop-color:#464646;stop-opacity:1;" />
+ <stop
+ style="stop-color:#848788;stop-opacity:1;"
+ offset="0.18306103"
+ id="stop3432" />
+ <stop
+ id="stop3434"
+ offset="0.66368055"
+ style="stop-color:#9ca0a2;stop-opacity:1;" />
+ <stop
+ id="stop3436"
+ offset="1"
+ style="stop-color:#b5babd;stop-opacity:1;" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient4034">
+ <stop
+ id="stop4036"
+ offset="0"
+ style="stop-color:#ffffff;stop-opacity:1;" />
+ <stop
+ style="stop-color:#ffffff;stop-opacity:0.49803922;"
+ offset="0.5"
+ id="stop4038" />
+ <stop
+ id="stop4040"
+ offset="0.63705367"
+ style="stop-color:#ffffff;stop-opacity:0.24705882;" />
+ <stop
+ style="stop-color:#ffffff;stop-opacity:0.12156863;"
+ offset="0.79425853"
+ id="stop4042" />
+ <stop
+ id="stop4044"
+ offset="1"
+ style="stop-color:#a0a0a0;stop-opacity:1;" />
+ </linearGradient>
+ <linearGradient
+ inkscape:collect="always"
+ id="linearGradient4016">
+ <stop
+ style="stop-color:#283e6a;stop-opacity:1;"
+ offset="0"
+ id="stop4018" />
+ <stop
+ style="stop-color:#283e6a;stop-opacity:0;"
+ offset="1"
+ id="stop4020" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient4004">
+ <stop
+ style="stop-color:#dbdbdb;stop-opacity:1;"
+ offset="0"
+ id="stop4010" />
+ <stop
+ style="stop-color:#c4c9cb;stop-opacity:1;"
+ offset="1"
+ id="stop4012" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3998">
+ <stop
+ id="stop4000"
+ offset="0"
+ style="stop-color:#adadad;stop-opacity:1;" />
+ <stop
+ id="stop4002"
+ offset="1"
+ style="stop-color:#ffffff;stop-opacity:1;" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3864">
+ <stop
+ style="stop-color:#ffffff;stop-opacity:1;"
+ offset="0"
+ id="stop3866" />
+ <stop
+ id="stop4028"
+ offset="0.5"
+ style="stop-color:#ffffff;stop-opacity:0.49803922;" />
+ <stop
+ style="stop-color:#ffffff;stop-opacity:0.24705882;"
+ offset="0.75"
+ id="stop4030" />
+ <stop
+ id="stop4032"
+ offset="0.875"
+ style="stop-color:#ffffff;stop-opacity:0.12156863;" />
+ <stop
+ style="stop-color:#a0a0a0;stop-opacity:1;"
+ offset="1"
+ id="stop3868" />
+ </linearGradient>
+ <linearGradient
+ inkscape:collect="always"
+ id="linearGradient3816">
+ <stop
+ style="stop-color:#ad8b00;stop-opacity:1;"
+ offset="0"
+ id="stop3818" />
+ <stop
+ style="stop-color:#ad8b00;stop-opacity:0;"
+ offset="1"
+ id="stop3820" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3746">
+ <stop
+ style="stop-color:#ffffff;stop-opacity:1;"
+ offset="0"
+ id="stop3748" />
+ <stop
+ style="stop-color:#0074b7;stop-opacity:1;"
+ offset="1"
+ id="stop3750" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3718">
+ <stop
+ style="stop-color:#bcbcbc;stop-opacity:0.28169015;"
+ offset="0"
+ id="stop3720" />
+ <stop
+ style="stop-color:#bcbcbc;stop-opacity:0;"
+ offset="1"
+ id="stop3722" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3708">
+ <stop
+ style="stop-color:#202020;stop-opacity:1;"
+ offset="0"
+ id="stop3710" />
+ <stop
+ style="stop-color:#ffffff;stop-opacity:1;"
+ offset="1"
+ id="stop3712" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3692">
+ <stop
+ style="stop-color:#ffffff;stop-opacity:1;"
+ offset="0"
+ id="stop3694" />
+ <stop
+ style="stop-color:#b6b6b6;stop-opacity:1;"
+ offset="1"
+ id="stop3696" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3656">
+ <stop
+ style="stop-color:#ffffff;stop-opacity:1;"
+ offset="0"
+ id="stop3658" />
+ <stop
+ style="stop-color:#ffffff;stop-opacity:0;"
+ offset="1"
+ id="stop3660" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3624">
+ <stop
+ style="stop-color:#3a8daf;stop-opacity:1;"
+ offset="0"
+ id="stop3626" />
+ <stop
+ id="stop3636"
+ offset="1"
+ style="stop-color:#252525;stop-opacity:1;" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3532">
+ <stop
+ id="stop3534"
+ offset="0"
+ style="stop-color:#545454;stop-opacity:1;" />
+ <stop
+ style="stop-color:#848788;stop-opacity:1;"
+ offset="0.44021741"
+ id="stop3536" />
+ <stop
+ id="stop3538"
+ offset="0.56799388"
+ style="stop-color:#9ca0a2;stop-opacity:1;" />
+ <stop
+ id="stop3540"
+ offset="1"
+ style="stop-color:#565d60;stop-opacity:1" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3345">
+ <stop
+ id="stop3348"
+ offset="0"
+ style="stop-color:#898989;stop-opacity:1;" />
+ <stop
+ style="stop-color:#9ea1a2;stop-opacity:1;"
+ offset="0.44021741"
+ id="stop3350" />
+ <stop
+ id="stop3352"
+ offset="0.56799388"
+ style="stop-color:#bbbdbf;stop-opacity:1;" />
+ <stop
+ id="stop3354"
+ offset="1"
+ style="stop-color:#f0f1f2;stop-opacity:1;" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3227">
+ <stop
+ style="stop-color:#444444;stop-opacity:1;"
+ offset="0"
+ id="stop3229" />
+ <stop
+ style="stop-color:#b0b0b0;stop-opacity:1;"
+ offset="1"
+ id="stop3232" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3435">
+ <stop
+ style="stop-color:#ffffff;stop-opacity:1;"
+ offset="0"
+ id="stop3437" />
+ <stop
+ style="stop-color:#c0c0c0;stop-opacity:0;"
+ offset="1"
+ id="stop3439" />
+ </linearGradient>
+ <linearGradient
+ inkscape:collect="always"
+ id="linearGradient3421">
+ <stop
+ style="stop-color:#444444;stop-opacity:1;"
+ offset="0"
+ id="stop3423" />
+ <stop
+ style="stop-color:#444444;stop-opacity:0;"
+ offset="1"
+ id="stop3425" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3293">
+ <stop
+ style="stop-color:#c4b434;stop-opacity:1;"
+ offset="0"
+ id="stop3295" />
+ <stop
+ style="stop-color:#9b5500;stop-opacity:1;"
+ offset="1"
+ id="stop3297" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3229">
+ <stop
+ style="stop-color:#125a7a;stop-opacity:1;"
+ offset="0"
+ id="stop3231" />
+ <stop
+ style="stop-color:#308fc0;stop-opacity:1;"
+ offset="1"
+ id="stop3233" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3219">
+ <stop
+ id="stop3221"
+ offset="0"
+ style="stop-color:#a55b00;stop-opacity:1;" />
+ <stop
+ id="stop3223"
+ offset="1"
+ style="stop-color:#f4e45e;stop-opacity:1;" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3189">
+ <stop
+ style="stop-color:#000000;stop-opacity:1;"
+ offset="0"
+ id="stop3191" />
+ <stop
+ style="stop-color:#000000;stop-opacity:0;"
+ offset="1"
+ id="stop3193" />
+ </linearGradient>
+ <linearGradient
+ id="linearGradient3167">
+ <stop
+ style="stop-color:#464646;stop-opacity:1;"
+ offset="0"
+ id="stop3169" />
+ <stop
+ id="stop3345"
+ offset="0.44021741"
+ style="stop-color:#848788;stop-opacity:1;" />
+ <stop
+ style="stop-color:#9ca0a2;stop-opacity:1;"
+ offset="0.56799388"
+ id="stop3347" />
+ <stop
+ style="stop-color:#b5babd;stop-opacity:1;"
+ offset="1"
+ id="stop3171" />
+ </linearGradient>
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 526.18109 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="744.09448 : 526.18109 : 1"
+ inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+ id="perspective10" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3167"
+ id="linearGradient3175"
+ x1="443.95602"
+ y1="315.31854"
+ x2="443.95602"
+ y2="247.85609"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.4908502,0,0,0.4579593,350.98557,542.12189)" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3219"
+ id="linearGradient3253"
+ gradientUnits="userSpaceOnUse"
+ x1="325.57214"
+ y1="280.13632"
+ x2="312.84424"
+ y2="257.60013" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3229"
+ id="linearGradient3255"
+ gradientUnits="userSpaceOnUse"
+ x1="310.01578"
+ y1="255.47881"
+ x2="325.92572"
+ y2="280.13632" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3219"
+ id="linearGradient3321"
+ gradientUnits="userSpaceOnUse"
+ x1="325.57214"
+ y1="280.13632"
+ x2="312.84424"
+ y2="257.60013" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3229"
+ id="linearGradient3323"
+ gradientUnits="userSpaceOnUse"
+ x1="310.01578"
+ y1="255.47881"
+ x2="325.92572"
+ y2="280.13632" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3219"
+ id="linearGradient3331"
+ gradientUnits="userSpaceOnUse"
+ x1="325.57214"
+ y1="280.13632"
+ x2="312.84424"
+ y2="257.60013" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3229"
+ id="linearGradient3333"
+ gradientUnits="userSpaceOnUse"
+ x1="310.01578"
+ y1="255.47881"
+ x2="325.92572"
+ y2="280.13632" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3293"
+ id="linearGradient3343"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1.3292883,0,0,1.10796,1.5038593,-24.232315)"
+ x1="359.5589"
+ y1="258.84247"
+ x2="370.88239"
+ y2="258.84247" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3219"
+ id="linearGradient3365"
+ gradientUnits="userSpaceOnUse"
+ x1="325.57214"
+ y1="280.13632"
+ x2="312.84424"
+ y2="257.60013" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3229"
+ id="linearGradient3367"
+ gradientUnits="userSpaceOnUse"
+ x1="310.01578"
+ y1="255.47881"
+ x2="325.92572"
+ y2="280.13632" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3219"
+ id="linearGradient3369"
+ gradientUnits="userSpaceOnUse"
+ x1="325.57214"
+ y1="280.13632"
+ x2="312.84424"
+ y2="257.60013" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3229"
+ id="linearGradient3371"
+ gradientUnits="userSpaceOnUse"
+ x1="310.01578"
+ y1="255.47881"
+ x2="325.92572"
+ y2="280.13632" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3219"
+ id="linearGradient3379"
+ gradientUnits="userSpaceOnUse"
+ x1="325.57214"
+ y1="280.13632"
+ x2="312.84424"
+ y2="257.60013" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3229"
+ id="linearGradient3381"
+ gradientUnits="userSpaceOnUse"
+ x1="310.01578"
+ y1="255.47881"
+ x2="325.92572"
+ y2="280.13632" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3293"
+ id="linearGradient3385"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1.3267302,0,0,1.1332782,-1.5786343,-29.194748)"
+ x1="371.79858"
+ y1="258.84247"
+ x2="364.49646"
+ y2="258.84247" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3293"
+ id="linearGradient3401"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1.9807835,0,0,1.1280701,-361.45126,-28.553769)"
+ x1="371.79858"
+ y1="258.84247"
+ x2="364.49646"
+ y2="258.84247" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3421"
+ id="radialGradient3431"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1.1862613,0,0,0.3638703,-186.86143,179.02055)"
+ cx="432.3343"
+ cy="233.80295"
+ fx="432.3343"
+ fy="233.80295"
+ r="59.056834" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3435"
+ id="radialGradient3441"
+ cx="290.5"
+ cy="244.34448"
+ fx="290.5"
+ fy="244.34448"
+ r="37.5"
+ gradientTransform="matrix(0.8202102,0.8202102,-0.7960458,0.7960458,246.73838,-189.686)"
+ gradientUnits="userSpaceOnUse" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3345"
+ id="linearGradient3311"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.466978,0,0,0.4500435,352.00841,540.25044)"
+ x1="510.99884"
+ y1="161.99408"
+ x2="396.48914"
+ y2="161.99408" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3421"
+ id="radialGradient3339"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.4181493,0,0,0.1282619,386.09461,620.15777)"
+ cx="432.3343"
+ cy="233.80295"
+ fx="432.3343"
+ fy="233.80295"
+ r="59.056834" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3219"
+ id="linearGradient3434"
+ gradientUnits="userSpaceOnUse"
+ x1="325.57214"
+ y1="280.13632"
+ x2="312.84424"
+ y2="257.60013" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3229"
+ id="linearGradient3436"
+ gradientUnits="userSpaceOnUse"
+ x1="310.01578"
+ y1="255.47881"
+ x2="325.92572"
+ y2="280.13632" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3532"
+ id="linearGradient3520"
+ x1="525"
+ y1="371.09448"
+ x2="525"
+ y2="395.09448"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.5865192,0,0,0.2518015,339.73218,572.99479)" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3624"
+ id="linearGradient3630"
+ x1="552.98486"
+ y1="390.56842"
+ x2="549.39465"
+ y2="702.3479"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(2.3373776,0,0,1.5004634,-835.38716,-310.82676)" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3656"
+ id="radialGradient3662"
+ cx="656.19507"
+ cy="534.45917"
+ fx="656.19507"
+ fy="534.45917"
+ r="13.227922"
+ gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)"
+ gradientUnits="userSpaceOnUse" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3656"
+ id="radialGradient3668"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)"
+ cx="656.19507"
+ cy="534.45917"
+ fx="656.19507"
+ fy="534.45917"
+ r="13.227922" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3656"
+ id="radialGradient3672"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)"
+ cx="656.19507"
+ cy="534.45917"
+ fx="656.19507"
+ fy="534.45917"
+ r="13.227922" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3656"
+ id="radialGradient3676"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)"
+ cx="656.19507"
+ cy="534.45917"
+ fx="656.19507"
+ fy="534.45917"
+ r="13.227922" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3692"
+ id="linearGradient3772"
+ gradientUnits="userSpaceOnUse"
+ x1="506.95975"
+ y1="469.73706"
+ x2="525.41608"
+ y2="469.73706" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3718"
+ id="linearGradient3774"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.9947644,0,0,1.3346457,2.7877039,-166.60153)"
+ x1="516.89508"
+ y1="503.50137"
+ x2="516.89508"
+ y2="543.80646" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3708"
+ id="linearGradient3776"
+ gradientUnits="userSpaceOnUse"
+ x1="518.26993"
+ y1="497.31477"
+ x2="533.02923"
+ y2="497.31477" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3692"
+ id="linearGradient3790"
+ gradientUnits="userSpaceOnUse"
+ x1="506.95975"
+ y1="469.73706"
+ x2="525.41608"
+ y2="469.73706" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3718"
+ id="linearGradient3792"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.9947644,0,0,1.3346457,2.7877039,-166.60153)"
+ x1="516.89508"
+ y1="503.50137"
+ x2="516.89508"
+ y2="543.80646" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3708"
+ id="linearGradient3794"
+ gradientUnits="userSpaceOnUse"
+ x1="518.26993"
+ y1="497.31477"
+ x2="533.02923"
+ y2="497.31477" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3656"
+ id="radialGradient3804"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)"
+ cx="656.19507"
+ cy="534.45917"
+ fx="656.19507"
+ fy="534.45917"
+ r="13.227922" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3656"
+ id="radialGradient3808"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)"
+ cx="656.19507"
+ cy="534.45917"
+ fx="656.19507"
+ fy="534.45917"
+ r="13.227922" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3227"
+ id="linearGradient3812"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1.1223608,0,0,0.3849769,-17.516054,565.40983)"
+ x1="543.5"
+ y1="205.19257"
+ x2="587.52001"
+ y2="205.19257" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3816"
+ id="linearGradient3826"
+ x1="573"
+ y1="755.46222"
+ x2="573"
+ y2="700.13464"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1,0,0,1.6033628,0,-450.76899)" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3864"
+ id="radialGradient3874"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(2.9674693,0.8647541,-0.8726553,1.0212484,-15.308759,-74.232772)"
+ cx="94.273849"
+ cy="89.893486"
+ fx="94.273849"
+ fy="89.893486"
+ r="74.397521" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3746"
+ id="radialGradient3880"
+ cx="82.966125"
+ cy="-178.42453"
+ fx="82.966125"
+ fy="-178.42453"
+ r="526.79456"
+ gradientTransform="matrix(1.4952094,0.3367191,-0.1040669,0.5264617,-57.119818,125.77043)"
+ gradientUnits="userSpaceOnUse" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3438"
+ id="linearGradient3948"
+ x1="660.29303"
+ y1="256.53284"
+ x2="444.79303"
+ y2="255.62085"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(0,32.526912)" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3692"
+ id="linearGradient3972"
+ x1="573.5"
+ y1="244.2056"
+ x2="578.25"
+ y2="216.9556"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(0,35.526912)" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3746"
+ id="linearGradient3990"
+ x1="542.5"
+ y1="222.59448"
+ x2="559"
+ y2="222.59448"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(-6.25,37.151912)" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3746"
+ id="linearGradient3994"
+ gradientUnits="userSpaceOnUse"
+ x1="542.5"
+ y1="222.59448"
+ x2="559"
+ y2="222.59448"
+ gradientTransform="translate(38.5,37.151912)" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient4016"
+ id="linearGradient4022"
+ x1="639"
+ y1="262.09448"
+ x2="667"
+ y2="262.09448"
+ gradientUnits="userSpaceOnUse" />
+ <inkscape:perspective
+ id="perspective2578"
+ inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+ inkscape:vp_z="744.09448 : 526.18109 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_x="0 : 526.18109 : 1"
+ sodipodi:type="inkscape:persp3d" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3746"
+ id="linearGradient3387"
+ gradientUnits="userSpaceOnUse"
+ x1="542.5"
+ y1="222.59448"
+ x2="559"
+ y2="222.59448"
+ gradientTransform="translate(15.875,37.151912)" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3167"
+ id="linearGradient3416"
+ x1="474.23065"
+ y1="229.92336"
+ x2="474.1944"
+ y2="218.27365"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(0.1004684,32.526757)" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3428"
+ id="linearGradient3426"
+ x1="592.92798"
+ y1="199.43727"
+ x2="557.05743"
+ y2="196.5448"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(12.140805,-13.041887)" />
+ <filter
+ inkscape:collect="always"
+ id="filter3507">
+ <feGaussianBlur
+ inkscape:collect="always"
+ stdDeviation="3.0523171"
+ id="feGaussianBlur3509" />
+ </filter>
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3523"
+ id="linearGradient3521"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1,0,0,-0.7291751,0,521.83983)"
+ x1="562.55634"
+ y1="285.89896"
+ x2="562.55634"
+ y2="244.09448" />
+ <linearGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient5097"
+ id="linearGradient5103"
+ x1="590.84674"
+ y1="274.57559"
+ x2="590.84674"
+ y2="334.01376"
+ gradientUnits="userSpaceOnUse"
+ spreadMethod="pad" />
+ <radialGradient
+ inkscape:collect="always"
+ xlink:href="#linearGradient3864"
+ id="radialGradient5107"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(2.9674693,0.8647541,-0.8726553,1.0212484,-15.308759,-74.232772)"
+ cx="94.273849"
+ cy="89.893486"
+ fx="94.273849"
+ fy="89.893486"
+ r="74.397521" />
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ gridtolerance="10000"
+ guidetolerance="10"
+ objecttolerance="10"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="0.70710678"
+ inkscape:cx="532.91407"
+ inkscape:cy="457.84365"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="false"
+ inkscape:window-width="1674"
+ inkscape:window-height="1000"
+ inkscape:window-x="2"
+ inkscape:window-y="14"
+ showguides="false" />
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1">
+ <rect
+ style="opacity:1;fill:url(#radialGradient3880);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.1880002;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect3638"
+ width="1053.5891"
+ height="291.32797"
+ x="-0.29455566"
+ y="1.6323624" />
+ <path
+ style="fill:url(#radialGradient3874);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;filter:url(#filter3507)"
+ d="M 158.37853,75.817898 C 130.95894,49.483192 82.14552,74.615971 85.85382,95.15981 C 49.691853,94.8009 50.214842,139.36083 83.29101,132.16343 C 144.66465,163.16454 159.26268,129.80212 164.6863,136.51386 C 225.60448,157.97672 246.34362,130.65438 265.24417,127.0714 C 294.43981,137.91859 337.16986,121.78798 297.03636,102.77604 C 331.73096,64.597047 277.96882,60.229366 253.07028,70.400868 C 191.09597,33.610112 168.89234,63.292037 158.37853,75.817898 z"
+ id="path3872"
+ sodipodi:nodetypes="cccccccc"
+ transform="matrix(1.5062893,0,0,1.1720951,618.04001,132.36768)" />
+ <rect
+ style="opacity:1;fill:url(#linearGradient3630);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.13464069;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect3622"
+ width="1054.4708"
+ height="461.52972"
+ x="-0.7354126"
+ y="278.34879" />
+ <path
+ style="fill:url(#linearGradient3826);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M -0.99999999,712.83731 C 272,698.40705 -51.363087,575.30331 261,705.40705 C 324.46247,731.84009 395,707.01041 449,705.40705 C 503,703.80369 463,690.73643 510,711.58015 C 557,732.42386 705,692.39023 750,684.37342 C 795,676.35661 908,667.75324 947,682.18351 C 986,696.61377 1056,698.9936 1056,698.9936 L 1053,747.09448 L -3,745.49112 L -0.99999999,712.83731 z"
+ id="path3814"
+ sodipodi:nodetypes="cssssscccc" />
+ <rect
+ style="opacity:1;fill:url(#linearGradient3520);fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:0.56879884;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect3512"
+ width="10.557344"
+ height="6.0432386"
+ x="642.3761"
+ y="666.43695" />
+ <use
+ x="0"
+ y="0"
+ xlink:href="#path2455"
+ id="use3258"
+ transform="matrix(0.869168,0,0,-0.869168,81.98751,1246.5374)"
+ width="1052.3622"
+ height="744.09448" />
+ <path
+ style="fill:url(#linearGradient3812);fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.77744257;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 593.04822,651.68104 C 593.04822,651.68104 653.65569,615.49321 639.065,637.05192 C 624.47431,658.61061 624.47431,658.61061 624.47431,658.61061 L 593.04822,651.68104 z"
+ id="path2455" />
+ <path
+ style="fill:url(#linearGradient3175);fill-opacity:1;fill-rule:evenodd;stroke:#393939;stroke-width:1.90693891;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 485.26939,643.71814 C 443.15507,651.66437 458.5319,680.53556 502.21486,686.27814 C 551.68229,692.78115 568.45042,691.0115 605.34827,686.27814 C 657.60843,679.57406 657.68143,651.78445 605.34827,643.25553 C 553.98131,634.88408 516.10913,637.89923 485.26939,643.71814 z"
+ id="path2385"
+ sodipodi:nodetypes="cssss" />
+ <path
+ style="fill:url(#radialGradient3339);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 542.18031,648.1112 C 548.56327,665.42741 608.42397,656.72745 586.93551,642.57104 C 586.93551,642.57104 543.33293,648.61096 542.18031,648.1112 z"
+ id="path3403"
+ sodipodi:nodetypes="ccc" />
+ <path
+ style="fill:url(#linearGradient3311);fill-opacity:1;fill-rule:evenodd;stroke:#2d2d2d;stroke-width:2.07042313;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 537.39402,641.90906 C 537.39402,656.7605 583.62247,656.30589 583.62247,641.45445 L 583.62247,636.06071 C 583.62247,621.21003 537.39402,613.87461 537.39402,628.72529 L 537.39402,641.90906 z"
+ id="path3291"
+ sodipodi:nodetypes="cssss" />
+ <g
+ id="g3235"
+ transform="matrix(1.4016868,0,0,1.1319742,112.22001,-99.678822)" />
+ <path
+ sodipodi:type="arc"
+ style="opacity:1;fill:url(#radialGradient3441);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.227;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3433"
+ sodipodi:cx="303.5"
+ sodipodi:cy="263.09448"
+ sodipodi:rx="37.5"
+ sodipodi:ry="40"
+ d="M 341,263.09448 A 37.5,40 0 1 1 266,263.09448 A 37.5,40 0 1 1 341,263.09448 z"
+ transform="matrix(0.692163,0,1.4106583e-2,0.289185,275.31394,582.37251)" />
+ <path
+ sodipodi:type="arc"
+ style="opacity:1;fill:#444444;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.06500006;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3458"
+ sodipodi:cx="369.5"
+ sodipodi:cy="316.09448"
+ sodipodi:rx="27.5"
+ sodipodi:ry="7"
+ d="M 397,316.09448 A 27.5,7 0 1 1 342,316.09448 A 27.5,7 0 1 1 397,316.09448 z"
+ transform="matrix(0.5642633,0,0,0.5642633,348.03095,450.47113)" />
+ <path
+ sodipodi:type="arc"
+ style="opacity:1;fill:#444444;fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:4.23126984;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3510"
+ sodipodi:cx="369.5"
+ sodipodi:cy="316.09448"
+ sodipodi:rx="27.5"
+ sodipodi:ry="7"
+ d="M 397,316.09448 A 27.5,7 0 1 1 342,316.09448 A 27.5,7 0 1 1 397,316.09448 z"
+ transform="matrix(0,0.30778,-0.5642633,0,828.66499,563.5944)" />
+ <use
+ x="0"
+ y="0"
+ xlink:href="#path3510"
+ id="use3544"
+ transform="translate(0.5000005,-17.23511)"
+ width="1052.3622"
+ height="744.09448" />
+ <path
+ sodipodi:type="arc"
+ style="opacity:1;fill:#787878;fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:2.38492584;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3584"
+ sodipodi:cx="237.5"
+ sodipodi:cy="366.09448"
+ sodipodi:rx="8.5"
+ sodipodi:ry="8"
+ d="M 246,366.09448 A 8.5,8 0 1 1 229,366.09448 A 8.5,8 0 1 1 246,366.09448 z"
+ transform="matrix(1.7798114,-4.2997512e-2,1.3318941e-2,0.5513151,196.65666,476.1443)" />
+ <path
+ style="fill:#a9a9a9;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3.49756980000000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
+ d="M 423.2231,281.1169 C 502.67948,283.47026 574.8361,283.42778 668.97714,281.1169 C 668.97714,281.1169 670.77663,271.99598 668.97714,269.5402 C 559.46065,250.8302 423.2231,265.08614 423.2231,269.5402 L 423.2231,281.1169 z"
+ id="path3469"
+ sodipodi:nodetypes="cccsc" />
+ <rect
+ style="opacity:1;fill:#333333;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect3408"
+ width="3.4280596"
+ height="29.611124"
+ x="709.89148"
+ y="-14.462622"
+ transform="matrix(0.9327494,0.3605254,-0.3633626,0.9316478,0,0)" />
+ <rect
+ style="opacity:1;fill:url(#linearGradient3416);fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:2.99999928;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect3376"
+ width="48.499989"
+ height="8.5"
+ x="444.56302"
+ y="252.39224"
+ transform="matrix(0.9999952,3.0887776e-3,-3.0887776e-3,0.9999952,0,0)" />
+ <path
+ style="fill:url(#linearGradient3972);fill-opacity:1;fill-rule:evenodd;stroke:#323232;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 509,277.62139 C 509,277.62139 547.41409,235.70896 524,232.62139 L 615,244.62139 L 615,279.62139 L 509,277.62139 z"
+ id="path3952"
+ sodipodi:nodetypes="csccc" />
+ <path
+ sodipodi:type="arc"
+ style="opacity:1;fill:url(#radialGradient3662);fill-opacity:1;fill-rule:nonzero;stroke:#41526b;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3654"
+ sodipodi:cx="656.19507"
+ sodipodi:cy="541.15485"
+ sodipodi:rx="12.727922"
+ sodipodi:ry="16.263456"
+ d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z"
+ transform="matrix(0.5187874,0,0,0.3968421,374.8524,387.30025)" />
+ <path
+ sodipodi:type="arc"
+ style="opacity:1;fill:url(#radialGradient3668);fill-opacity:1;fill-rule:nonzero;stroke:#41526b;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3666"
+ sodipodi:cx="656.19507"
+ sodipodi:cy="541.15485"
+ sodipodi:rx="12.727922"
+ sodipodi:ry="16.263456"
+ d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z"
+ transform="matrix(0.5734968,0,0,0.4386917,316.52295,315.62837)" />
+ <path
+ transform="matrix(0.8598866,0,0,0.5637407,192.52282,220.77351)"
+ d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z"
+ sodipodi:ry="16.263456"
+ sodipodi:rx="12.727922"
+ sodipodi:cy="541.15485"
+ sodipodi:cx="656.19507"
+ id="path3670"
+ style="opacity:1;fill:url(#radialGradient3672);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.90000010000000020;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ sodipodi:type="arc" />
+ <path
+ sodipodi:type="arc"
+ style="opacity:1;fill:url(#radialGradient3676);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.90000010000000020;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3674"
+ sodipodi:cx="656.19507"
+ sodipodi:cy="541.15485"
+ sodipodi:rx="12.727922"
+ sodipodi:ry="16.263456"
+ d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z"
+ transform="matrix(0.7435991,0,0,0.6264519,225.8301,127.83701)" />
+ <g
+ id="g3759"
+ transform="matrix(0.8830571,0,0,0.8830571,104.83144,103.2985)">
+ <path
+ d="M 523.9661,469.73706 A 7.7781744,34.648232 0 1 1 508.40975,469.73706 A 7.7781744,34.648232 0 1 1 523.9661,469.73706 z"
+ sodipodi:ry="34.648232"
+ sodipodi:rx="7.7781744"
+ sodipodi:cy="469.73706"
+ sodipodi:cx="516.18793"
+ id="path3682"
+ style="opacity:1;fill:url(#linearGradient3772);fill-opacity:1;fill-rule:nonzero;stroke:#272727;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ sodipodi:type="arc" />
+ <g
+ id="g3754">
+ <rect
+ style="opacity:1;fill:url(#linearGradient3774);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.20000005;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect3716"
+ width="33.58757"
+ height="59.927299"
+ x="498.86386"
+ y="497.84454" />
+ <path
+ style="fill:url(#linearGradient3776);fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 523.35045,482.89424 C 523.35045,482.89424 532.31256,488.20203 532.02344,500.14638 C 531.73431,512.09072 531.73431,511.73417 531.73431,511.73417 C 531.73431,511.73417 520.70627,493.83104 519.26887,499.77636 L 523.35045,482.89424 z"
+ id="path3704"
+ sodipodi:nodetypes="cscsc" />
+ <path
+ sodipodi:nodetypes="cscsc"
+ id="path3706"
+ d="M 508.50327,482.89424 C 508.50327,482.89424 499.54116,488.20203 499.83028,500.14638 C 500.11941,512.09072 500.11941,511.73417 500.11941,511.73417 C 500.11941,511.73417 511.14745,493.83104 512.58485,499.77636 L 508.50327,482.89424 z"
+ style="fill:#bcbcbc;fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ </g>
+ </g>
+ <g
+ transform="matrix(0.8830571,0,0,0.8830571,192.45885,-66.370546)"
+ id="g3778">
+ <path
+ sodipodi:type="arc"
+ style="opacity:1;fill:url(#linearGradient3790);fill-opacity:1;fill-rule:nonzero;stroke:#272727;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3780"
+ sodipodi:cx="516.18793"
+ sodipodi:cy="469.73706"
+ sodipodi:rx="7.7781744"
+ sodipodi:ry="34.648232"
+ d="M 523.9661,469.73706 A 7.7781744,34.648232 0 1 1 508.40975,469.73706 A 7.7781744,34.648232 0 1 1 523.9661,469.73706 z" />
+ <g
+ id="g3782">
+ <rect
+ y="497.84454"
+ x="498.86386"
+ height="59.927299"
+ width="33.58757"
+ id="rect3784"
+ style="opacity:1;fill:url(#linearGradient3792);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.20000005;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="cscsc"
+ id="path3786"
+ d="M 523.35045,482.89424 C 523.35045,482.89424 532.31256,488.20203 532.02344,500.14638 C 531.73431,512.09072 531.73431,511.73417 531.73431,511.73417 C 531.73431,511.73417 520.70627,493.83104 519.26887,499.77636 L 523.35045,482.89424 z"
+ style="fill:url(#linearGradient3794);fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ style="fill:#bcbcbc;fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 508.50327,482.89424 C 508.50327,482.89424 499.54116,488.20203 499.83028,500.14638 C 500.11941,512.09072 500.11941,511.73417 500.11941,511.73417 C 500.11941,511.73417 511.14745,493.83104 512.58485,499.77636 L 508.50327,482.89424 z"
+ id="path3788"
+ sodipodi:nodetypes="cscsc" />
+ </g>
+ </g>
+ <path
+ transform="matrix(0.4292897,0,0,0.3283816,384.32775,481.20689)"
+ d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z"
+ sodipodi:ry="16.263456"
+ sodipodi:rx="12.727922"
+ sodipodi:cy="541.15485"
+ sodipodi:cx="656.19507"
+ id="path3802"
+ style="opacity:1;fill:url(#radialGradient3804);fill-opacity:1;fill-rule:nonzero;stroke:#41526b;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ sodipodi:type="arc" />
+ <path
+ sodipodi:type="arc"
+ style="opacity:1;fill:url(#radialGradient3808);fill-opacity:1;fill-rule:nonzero;stroke:#41526b;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path3806"
+ sodipodi:cx="656.19507"
+ sodipodi:cy="541.15485"
+ sodipodi:rx="12.727922"
+ sodipodi:ry="16.263456"
+ d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z"
+ transform="matrix(0.5842998,0,0,0.4469553,299.7804,369.91514)" />
+ <path
+ style="fill:#ad8b00;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 1059.5,736.57373 C 786.5,730.53352 912.51207,693.32637 768.5,736.53352 C 750.7005,741.87381 560.38464,722.59661 552.5,736.53352 C 528.68395,778.63085 223.94216,703.33865 182.5,727.16444 C 179.5,728.88919 160.53732,723.88477 135.5,730.90332 C 98.830356,741.18268 82.5,725.67603 43.5,731.71624 C 4.5,737.75645 0.5,733.72965 0.5,733.72965 L -6.5,747.98302 L 1049.5,747.31188 L 1059.5,736.57373 z"
+ id="path3828"
+ sodipodi:nodetypes="cssssscccc" />
+ <rect
+ style="opacity:1;fill:url(#linearGradient5103);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect3448"
+ width="1053.5891"
+ height="67.882248"
+ x="-0.29455566"
+ y="274.57559" />
+ <path
+ sodipodi:nodetypes="ccccc"
+ id="path3519"
+ d="M 428,343.85222 C 428,343.85222 457.01739,315.41439 470,315.41439 C 481.98261,313.04457 634.13054,311.73511 652,317.41962 C 661.13441,320.56943 664.46012,324.9477 666,343.85222 C 600.25603,336.72647 497.8192,336.4719 428,343.85222 z"
+ style="opacity:0.43933058;fill:url(#linearGradient3521);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:3.0999999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ style="fill:url(#linearGradient3948);fill-opacity:1;fill-rule:evenodd;stroke:#545454;stroke-width:3.0999999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 428,276.62139 C 428,276.62139 457.01739,315.62139 470,315.62139 C 481.98261,318.87139 634.13054,320.6672 652,312.87139 C 661.13441,308.55171 664.46012,302.54729 666,276.62139 C 600.25603,286.39373 497.8192,286.74286 428,276.62139 z"
+ id="path3938"
+ sodipodi:nodetypes="ccccc" />
+ <path
+ style="fill:#dedede;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
+ d="M 466.00273,263.08289 L 484.25264,263.13926 L 494.7163,274.92164 L 465.96644,274.83284 L 466.00273,263.08289 z"
+ id="rect3378"
+ sodipodi:nodetypes="ccccc" />
+ <rect
+ style="opacity:1;fill:url(#linearGradient3990);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect3974"
+ width="13.5"
+ height="17"
+ x="537.75"
+ y="251.2464"
+ inkscape:transform-center-x="30" />
+ <rect
+ inkscape:transform-center-x="30"
+ y="251.2464"
+ x="582.5"
+ height="17"
+ width="13.5"
+ id="rect3992"
+ style="opacity:1;fill:url(#linearGradient3994);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ style="fill:#dedede;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
+ d="M 422.25,268.87139 C 487.33333,277.37139 573.16667,279.87139 668.5,268.87139 C 668.5,268.87139 670.30312,275.56827 668.5,277.37139 C 558.76249,291.1089 422.25,280.64171 422.25,277.37139 L 422.25,268.87139 z"
+ id="rect2558"
+ sodipodi:nodetypes="cccsc" />
+ <rect
+ style="opacity:1;fill:#c1c1c1;fill-opacity:1;fill-rule:nonzero;stroke:#404040;stroke-width:3.0365274;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect2569"
+ width="94.427879"
+ height="7.236649"
+ x="546.39832"
+ y="177.10637"
+ transform="matrix(0.9947793,0.1020501,-0.1079723,0.9941539,0,0)" />
+ <rect
+ inkscape:transform-center-x="30"
+ y="251.2464"
+ x="559.875"
+ height="17"
+ width="13.5"
+ id="rect3385"
+ style="opacity:1;fill:url(#linearGradient3387);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <g
+ id="g3401"
+ transform="matrix(0.9246214,0.3808874,-0.3808874,0.9246214,113.30125,-193.16902)"
+ inkscape:transform-center-x="17.590385"
+ inkscape:transform-center-y="-15.415449">
+ <rect
+ inkscape:transform-center-y="-43.888889"
+ transform="matrix(0,1,-1,0,0,0)"
+ style="opacity:1;fill:#b20000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect3389"
+ width="19.75"
+ height="27.75"
+ x="193.34448"
+ y="-709" />
+ <rect
+ y="200.59448"
+ x="681.5"
+ height="5.75"
+ width="27.25"
+ id="rect3393"
+ style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ y="193.59448"
+ x="691.25"
+ height="19.5"
+ width="5.75"
+ id="rect3395"
+ style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ y="202.34448"
+ x="681.5"
+ height="2.5"
+ width="27.75"
+ id="rect3397"
+ style="opacity:1;fill:#000080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <rect
+ y="193.59448"
+ x="692.5"
+ height="19.25"
+ width="3"
+ id="rect3399"
+ style="opacity:1;fill:#000080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ </g>
+ <path
+ style="fill:#dcdcdc;fill-opacity:1;fill-rule:nonzero;stroke:#404040;stroke-width:3.03650045;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
+ d="M 529.42326,227.17914 L 616.35817,235.81552 L 618.07681,241.50986 L 524.14191,231.87348 L 529.42326,227.17914 z"
+ id="rect3466"
+ sodipodi:nodetypes="ccccc" />
+ <rect
+ style="opacity:1;fill:url(#linearGradient3426);fill-opacity:1;fill-rule:nonzero;stroke:#494949;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect3418"
+ width="34.5"
+ height="14.5"
+ x="571.14081"
+ y="174.8026"
+ transform="matrix(0.997157,7.5351915e-2,-7.5351915e-2,0.997157,0,0)"
+ inkscape:transform-center-x="-8"
+ inkscape:transform-center-y="2" />
+ <g
+ id="mine"
+ transform="translate(971.11461,237.62715)"
+ inkscape:label="#g3441">
+ <path
+ transform="matrix(0.6341613,0,0,0.6341613,-18.521242,45.718192)"
+ d="M -167.5843,186.54079 A 31.466251,31.466251 0 1 1 -230.5168,186.54079 A 31.466251,31.466251 0 1 1 -167.5843,186.54079 z"
+ sodipodi:ry="31.466251"
+ sodipodi:rx="31.466251"
+ sodipodi:cy="186.54079"
+ sodipodi:cx="-199.05055"
+ id="path2586"
+ style="opacity:1;fill:url(#radialGradient3364);fill-opacity:1;stroke:#131313;stroke-width:3.54799318;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ sodipodi:type="arc" />
+ <path
+ sodipodi:nodetypes="ccss"
+ id="path3382"
+ d="M -155.20193,175.4167 C -157.60085,176.6451 -156.78074,184.26068 -156.78074,184.26068 C -156.78074,184.26068 -148.33787,181.58301 -148.57092,178.60053 C -148.74283,176.40051 -153.23774,174.41092 -155.20193,175.4167 z"
+ style="fill:url(#linearGradient3398);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="ccss"
+ id="path3400"
+ d="M -156.56354,153.84532 C -158.96246,152.61693 -158.14235,145.00135 -158.14235,145.00135 C -158.14235,145.00135 -149.69948,147.67902 -149.93253,150.66149 C -150.10444,152.86151 -154.59935,154.85111 -156.56354,153.84532 z"
+ style="fill:url(#linearGradient3402);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="ccss"
+ id="path3404"
+ d="M -133.88532,153.68678 C -131.48641,152.45838 -132.30652,144.8428 -132.30652,144.8428 C -132.30652,144.8428 -140.74938,147.52047 -140.51633,150.50295 C -140.34442,152.70297 -135.84951,154.69256 -133.88532,153.68678 z"
+ style="fill:url(#linearGradient3406);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="ccss"
+ id="path3408"
+ d="M -134.51948,175.55085 C -132.12057,176.77925 -132.94068,184.39483 -132.94068,184.39483 C -132.94068,184.39483 -141.38355,181.71716 -141.15049,178.73469 C -140.97858,176.53467 -136.48367,174.54507 -134.51948,175.55085 z"
+ style="fill:url(#linearGradient3410);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="ccss"
+ id="path3412"
+ d="M -161.25709,168.78221 C -163.22395,170.62484 -170.11427,165.85236 -170.11427,165.85236 C -170.11427,165.85236 -164.7408,160.23808 -162.01257,161.46538 C -160.00011,162.37068 -159.64667,167.27352 -161.25709,168.78221 z"
+ style="fill:url(#linearGradient3414);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ sodipodi:nodetypes="ccss"
+ id="path3416"
+ d="M -129.17068,169.10464 C -127.20382,170.94727 -120.3135,166.17478 -120.3135,166.17478 C -120.3135,166.17478 -125.68697,160.5605 -128.41519,161.7878 C -130.42766,162.69311 -130.7811,167.59595 -129.17068,169.10464 z"
+ style="fill:url(#linearGradient3418);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ transform="matrix(0.6341613,0,0,0.6341613,-61.039517,68.324922)"
+ d="M -126,151.21948 A 6.625,6.625 0 1 1 -139.25,151.21948 A 6.625,6.625 0 1 1 -126,151.21948 z"
+ sodipodi:ry="6.625"
+ sodipodi:rx="6.625"
+ sodipodi:cy="151.21948"
+ sodipodi:cx="-132.625"
+ id="path3426"
+ style="opacity:1;fill:url(#radialGradient3439);fill-opacity:1;stroke:#131313;stroke-width:3.54799318;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ sodipodi:type="arc" />
+ </g>
+ </g>
+</svg>
diff --git a/examples/animation/sub-attaq/pics/scalable/submarine.svg b/examples/animation/sub-attaq/pics/scalable/submarine.svg
new file mode 100644
index 0000000..8a0ffdd
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/scalable/submarine.svg
@@ -0,0 +1,214 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ version="1.0"
+ width="744.09448"
+ height="1052.3622"
+ id="svg2594">
+ <defs
+ id="defs2596">
+ <linearGradient
+ id="linearGradient3345">
+ <stop
+ id="stop3348"
+ style="stop-color:#898989;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3350"
+ style="stop-color:#9ea1a2;stop-opacity:1"
+ offset="0.44021741" />
+ <stop
+ id="stop3352"
+ style="stop-color:#bbbdbf;stop-opacity:1"
+ offset="0.56799388" />
+ <stop
+ id="stop3354"
+ style="stop-color:#f0f1f2;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="510.99884"
+ y1="161.99408"
+ x2="396.48914"
+ y2="161.99408"
+ id="linearGradient3311"
+ xlink:href="#linearGradient3345"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.466978,0,0,0.4500435,231.58508,159.95135)" />
+ <linearGradient
+ id="linearGradient3532">
+ <stop
+ id="stop3534"
+ style="stop-color:#545454;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3536"
+ style="stop-color:#848788;stop-opacity:1"
+ offset="0.44021741" />
+ <stop
+ id="stop3538"
+ style="stop-color:#9ca0a2;stop-opacity:1"
+ offset="0.56799388" />
+ <stop
+ id="stop3540"
+ style="stop-color:#565d60;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="525"
+ y1="371.09448"
+ x2="525"
+ y2="395.09448"
+ id="linearGradient3520"
+ xlink:href="#linearGradient3532"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.5865192,0,0,0.2518015,219.30885,192.6957)" />
+ <linearGradient
+ id="linearGradient3227">
+ <stop
+ id="stop3229"
+ style="stop-color:#444444;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3232"
+ style="stop-color:#b0b0b0;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="543.5"
+ y1="205.19257"
+ x2="587.52002"
+ y2="205.19257"
+ id="linearGradient3812"
+ xlink:href="#linearGradient3227"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(1.1223608,0,0,0.3849769,-137.93938,185.11074)" />
+ <linearGradient
+ id="linearGradient3167">
+ <stop
+ id="stop3169"
+ style="stop-color:#464646;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3345"
+ style="stop-color:#848788;stop-opacity:1"
+ offset="0.44021741" />
+ <stop
+ id="stop3347"
+ style="stop-color:#9ca0a2;stop-opacity:1"
+ offset="0.56799388" />
+ <stop
+ id="stop3171"
+ style="stop-color:#b5babd;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="443.95602"
+ y1="315.31854"
+ x2="443.95602"
+ y2="247.85609"
+ id="linearGradient3175"
+ xlink:href="#linearGradient3167"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.4908502,0,0,0.4579593,230.56224,161.8228)" />
+ <linearGradient
+ id="linearGradient3421">
+ <stop
+ id="stop3423"
+ style="stop-color:#444444;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3425"
+ style="stop-color:#444444;stop-opacity:0"
+ offset="1" />
+ </linearGradient>
+ <radialGradient
+ cx="432.33429"
+ cy="233.80295"
+ r="59.056835"
+ fx="432.33429"
+ fy="233.80295"
+ id="radialGradient3339"
+ xlink:href="#linearGradient3421"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.4181493,0,0,0.1282619,265.67128,239.85868)" />
+ <linearGradient
+ id="linearGradient3435">
+ <stop
+ id="stop3437"
+ style="stop-color:#ffffff;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3439"
+ style="stop-color:#c0c0c0;stop-opacity:0"
+ offset="1" />
+ </linearGradient>
+ <radialGradient
+ cx="290.5"
+ cy="244.34448"
+ r="37.5"
+ fx="290.5"
+ fy="244.34448"
+ id="radialGradient3441"
+ xlink:href="#linearGradient3435"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.8202102,0.8202102,-0.7960458,0.7960458,246.73838,-189.686)" />
+ </defs>
+ <g
+ id="submarine">
+ <rect
+ width="10.557344"
+ height="6.0432386"
+ x="521.95276"
+ y="286.13785"
+ id="rect3512"
+ style="opacity:1;fill:url(#linearGradient3520);fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:0.56879884;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 472.62489,271.38195 C 472.62489,271.38195 533.23236,235.19412 518.64167,256.75283 C 504.05098,278.31152 504.05098,278.31152 504.05098,278.31152 L 472.62489,271.38195 z"
+ id="path2455"
+ style="fill:url(#linearGradient3812);fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.77744257;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 364.84606,263.41905 C 322.73174,271.36528 338.10857,300.23647 381.79153,305.97905 C 431.25896,312.48206 448.02709,310.71241 484.92494,305.97905 C 537.1851,299.27497 537.2581,271.48536 484.92494,262.95644 C 433.55798,254.58499 395.6858,257.60014 364.84606,263.41905 z"
+ id="path2385"
+ style="fill:url(#linearGradient3175);fill-opacity:1;fill-rule:evenodd;stroke:#393939;stroke-width:1.90693891;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 421.75698,267.81211 C 428.13994,285.12832 488.00064,276.42836 466.51218,262.27195 C 466.51218,262.27195 422.9096,268.31187 421.75698,267.81211 z"
+ id="path3403"
+ style="fill:url(#radialGradient3339);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+ <path
+ d="M 416.97069,261.60997 C 416.97069,276.46141 463.19914,276.0068 463.19914,261.15536 L 463.19914,255.76162 C 463.19914,240.91094 416.97069,233.57552 416.97069,248.4262 L 416.97069,261.60997 z"
+ id="path3291"
+ style="fill:url(#linearGradient3311);fill-opacity:1;fill-rule:evenodd;stroke:#2d2d2d;stroke-width:2.07042313;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 341,263.09448 A 37.5,40 0 1 1 266,263.09448 A 37.5,40 0 1 1 341,263.09448 z"
+ transform="matrix(0.692163,0,1.4106583e-2,0.289185,154.89061,202.07342)"
+ id="path3433"
+ style="opacity:1;fill:url(#radialGradient3441);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.227;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 397,316.09448 A 27.5,7 0 1 1 342,316.09448 A 27.5,7 0 1 1 397,316.09448 z"
+ transform="matrix(0.5642633,0,0,0.5642633,227.60762,70.172035)"
+ id="path3458"
+ style="opacity:1;fill:#444444;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.06500006;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 397,316.09448 A 27.5,7 0 1 1 342,316.09448 A 27.5,7 0 1 1 397,316.09448 z"
+ transform="matrix(0,0.30778,-0.5642633,0,708.24166,183.29531)"
+ id="path3510"
+ style="opacity:1;fill:#444444;fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:4.23126984;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <use
+ transform="translate(0.5000044,-17.235115)"
+ id="use3544"
+ x="0"
+ y="0"
+ width="1052.3622"
+ height="744.09448"
+ xlink:href="#path3510" />
+ <path
+ d="M 246,366.09448 A 8.5,8 0 1 1 229,366.09448 A 8.5,8 0 1 1 246,366.09448 z"
+ transform="matrix(1.7798114,-4.2997512e-2,1.3318941e-2,0.5513151,76.233334,95.845205)"
+ id="path3584"
+ style="opacity:1;fill:#787878;fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:2.38492584;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ </g>
+</svg>
diff --git a/examples/animation/sub-attaq/pics/scalable/surface.svg b/examples/animation/sub-attaq/pics/scalable/surface.svg
new file mode 100644
index 0000000..40ed239
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/scalable/surface.svg
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ version="1.0"
+ width="744.09448"
+ height="1052.3622"
+ id="svg2685">
+ <defs
+ id="defs2687">
+ <linearGradient
+ id="linearGradient5097">
+ <stop
+ id="stop5099"
+ style="stop-color:#19a2db;stop-opacity:0"
+ offset="0" />
+ <stop
+ id="stop5109"
+ style="stop-color:#1379a7;stop-opacity:0.49803922"
+ offset="0.30000001" />
+ <stop
+ id="stop5101"
+ style="stop-color:#0e5173;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="590.84674"
+ y1="274.57559"
+ x2="590.84674"
+ y2="334.01376"
+ id="linearGradient5103"
+ xlink:href="#linearGradient5097"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="translate(-172.21428,209.55976)"
+ spreadMethod="pad" />
+ </defs>
+ <g
+ id="layer1">
+ <rect
+ width="1053.5891"
+ height="67.882248"
+ x="-172.50883"
+ y="484.13535"
+ id="rect3448"
+ style="opacity:1;fill:url(#linearGradient5103);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ </g>
+</svg>
diff --git a/examples/animation/sub-attaq/pics/scalable/torpedo.svg b/examples/animation/sub-attaq/pics/scalable/torpedo.svg
new file mode 100644
index 0000000..48e429d
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/scalable/torpedo.svg
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ version="1.0"
+ width="744.09448"
+ height="1052.3622"
+ id="svg2584">
+ <defs
+ id="defs2586">
+ <linearGradient
+ id="linearGradient3708">
+ <stop
+ id="stop3710"
+ style="stop-color:#202020;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3712"
+ style="stop-color:#ffffff;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="518.26996"
+ y1="497.31476"
+ x2="533.02924"
+ y2="497.31476"
+ id="linearGradient3776"
+ xlink:href="#linearGradient3708"
+ gradientUnits="userSpaceOnUse" />
+ <linearGradient
+ id="linearGradient3718">
+ <stop
+ id="stop3720"
+ style="stop-color:#bcbcbc;stop-opacity:0.28169015"
+ offset="0" />
+ <stop
+ id="stop3722"
+ style="stop-color:#bcbcbc;stop-opacity:0"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="516.89508"
+ y1="503.50137"
+ x2="516.89508"
+ y2="543.80646"
+ id="linearGradient3774"
+ xlink:href="#linearGradient3718"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.9947644,0,0,1.3346457,2.7877039,-166.60153)" />
+ <linearGradient
+ id="linearGradient3692">
+ <stop
+ id="stop3694"
+ style="stop-color:#ffffff;stop-opacity:1"
+ offset="0" />
+ <stop
+ id="stop3696"
+ style="stop-color:#b6b6b6;stop-opacity:1"
+ offset="1" />
+ </linearGradient>
+ <linearGradient
+ x1="506.95975"
+ y1="469.73706"
+ x2="525.41608"
+ y2="469.73706"
+ id="linearGradient3772"
+ xlink:href="#linearGradient3692"
+ gradientUnits="userSpaceOnUse" />
+ <linearGradient
+ x1="506.95975"
+ y1="469.73706"
+ x2="525.41608"
+ y2="469.73706"
+ id="linearGradient2403"
+ xlink:href="#linearGradient3692"
+ gradientUnits="userSpaceOnUse" />
+ <linearGradient
+ x1="516.89508"
+ y1="503.50137"
+ x2="516.89508"
+ y2="543.80646"
+ id="linearGradient2405"
+ xlink:href="#linearGradient3718"
+ gradientUnits="userSpaceOnUse"
+ gradientTransform="matrix(0.9947644,0,0,1.3346457,2.7877039,-166.60153)" />
+ <linearGradient
+ x1="518.26996"
+ y1="497.31476"
+ x2="533.02924"
+ y2="497.31476"
+ id="linearGradient2407"
+ xlink:href="#linearGradient3708"
+ gradientUnits="userSpaceOnUse" />
+ </defs>
+ <g
+ transform="translate(-128.69958,6.6568748)"
+ id="torpedo">
+ <g
+ transform="matrix(0.8830571,0,0,0.8830571,-119.78327,177.67947)"
+ id="g3525">
+ <path
+ d="M 523.9661,469.73706 A 7.7781744,34.648232 0 1 1 508.40975,469.73706 A 7.7781744,34.648232 0 1 1 523.9661,469.73706 z"
+ id="path3682"
+ style="opacity:1;fill:url(#linearGradient2403);fill-opacity:1;fill-rule:nonzero;stroke:#272727;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <g
+ id="g3754">
+ <rect
+ width="33.58757"
+ height="59.927299"
+ x="498.86386"
+ y="497.84454"
+ id="rect3716"
+ style="opacity:1;fill:url(#linearGradient2405);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.20000005;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 523.35045,482.89424 C 523.35045,482.89424 532.31256,488.20203 532.02344,500.14638 C 531.73431,512.09072 531.73431,511.73417 531.73431,511.73417 C 531.73431,511.73417 520.70627,493.83104 519.26887,499.77636 L 523.35045,482.89424 z"
+ id="path3704"
+ style="fill:url(#linearGradient2407);fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ d="M 508.50327,482.89424 C 508.50327,482.89424 499.54116,488.20203 499.83028,500.14638 C 500.11941,512.09072 500.11941,511.73417 500.11941,511.73417 C 500.11941,511.73417 511.14745,493.83104 512.58485,499.77636 L 508.50327,482.89424 z"
+ id="path3706"
+ style="fill:#bcbcbc;fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ </g>
+ </g>
+ </g>
+</svg>
diff --git a/examples/animation/sub-attaq/pics/small/background.png b/examples/animation/sub-attaq/pics/small/background.png
new file mode 100644
index 0000000..5ad3db6
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/small/background.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/small/boat.png b/examples/animation/sub-attaq/pics/small/boat.png
new file mode 100644
index 0000000..114ccc3
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/small/boat.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/small/bomb.png b/examples/animation/sub-attaq/pics/small/bomb.png
new file mode 100644
index 0000000..3af5f2f
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/small/bomb.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/small/submarine.png b/examples/animation/sub-attaq/pics/small/submarine.png
new file mode 100644
index 0000000..0c0c350
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/small/submarine.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/small/surface.png b/examples/animation/sub-attaq/pics/small/surface.png
new file mode 100644
index 0000000..06d0e47
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/small/surface.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/small/torpedo.png b/examples/animation/sub-attaq/pics/small/torpedo.png
new file mode 100644
index 0000000..f9c2687
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/small/torpedo.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/welcome/logo-a.png b/examples/animation/sub-attaq/pics/welcome/logo-a.png
new file mode 100644
index 0000000..67dd76d
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/welcome/logo-a.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/welcome/logo-a2.png b/examples/animation/sub-attaq/pics/welcome/logo-a2.png
new file mode 100644
index 0000000..17668b0
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/welcome/logo-a2.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/welcome/logo-b.png b/examples/animation/sub-attaq/pics/welcome/logo-b.png
new file mode 100644
index 0000000..cf6c045
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/welcome/logo-b.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/welcome/logo-dash.png b/examples/animation/sub-attaq/pics/welcome/logo-dash.png
new file mode 100644
index 0000000..219233c
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/welcome/logo-dash.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/welcome/logo-excl.png b/examples/animation/sub-attaq/pics/welcome/logo-excl.png
new file mode 100644
index 0000000..8dd0a2e
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/welcome/logo-excl.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/welcome/logo-q.png b/examples/animation/sub-attaq/pics/welcome/logo-q.png
new file mode 100644
index 0000000..86e588d
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/welcome/logo-q.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/welcome/logo-s.png b/examples/animation/sub-attaq/pics/welcome/logo-s.png
new file mode 100644
index 0000000..7b6a36e
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/welcome/logo-s.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/welcome/logo-t.png b/examples/animation/sub-attaq/pics/welcome/logo-t.png
new file mode 100644
index 0000000..b2e3526
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/welcome/logo-t.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/welcome/logo-t2.png b/examples/animation/sub-attaq/pics/welcome/logo-t2.png
new file mode 100644
index 0000000..b11a778
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/welcome/logo-t2.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pics/welcome/logo-u.png b/examples/animation/sub-attaq/pics/welcome/logo-u.png
new file mode 100644
index 0000000..24eede8
--- /dev/null
+++ b/examples/animation/sub-attaq/pics/welcome/logo-u.png
Binary files differ
diff --git a/examples/animation/sub-attaq/pixmapitem.cpp b/examples/animation/sub-attaq/pixmapitem.cpp
new file mode 100644
index 0000000..22a363f
--- /dev/null
+++ b/examples/animation/sub-attaq/pixmapitem.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "pixmapitem.h"
+
+//Qt
+#include <QtCore/QDir>
+
+PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphicsItem * parent) : QGraphicsPixmapItem(parent),name(fileName)
+{
+ loadPixmap(mode);
+}
+
+void PixmapItem::loadPixmap(GraphicsScene::Mode mode)
+{
+ if (mode == GraphicsScene::Big)
+ setPixmap(":/big/" + name);
+ else
+ setPixmap(":/small/" + name);
+}
diff --git a/examples/animation/sub-attaq/pixmapitem.h b/examples/animation/sub-attaq/pixmapitem.h
new file mode 100644
index 0000000..31022c1
--- /dev/null
+++ b/examples/animation/sub-attaq/pixmapitem.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __PIXMAPITEM__H__
+#define __PIXMAPITEM__H__
+
+//Own
+#include "graphicsscene.h"
+
+//Qt
+#include <QtGui/QGraphicsPixmapItem>
+
+class PixmapItem : public QGraphicsPixmapItem
+{
+public:
+ PixmapItem(const QString &fileName, GraphicsScene::Mode mode, QGraphicsItem * parent = 0);
+
+private:
+ void loadPixmap(GraphicsScene::Mode mode);
+
+ QString name;
+ QPixmap pixmap;
+};
+
+#endif //__PIXMAPITEM__H__
diff --git a/examples/animation/sub-attaq/progressitem.cpp b/examples/animation/sub-attaq/progressitem.cpp
new file mode 100644
index 0000000..59ccb9a
--- /dev/null
+++ b/examples/animation/sub-attaq/progressitem.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "progressitem.h"
+#include "pixmapitem.h"
+
+ProgressItem::ProgressItem (QGraphicsItem * parent)
+ : QGraphicsTextItem(parent), currentLevel(1), currentScore(0)
+{
+ setFont(QFont("Comic Sans MS"));
+ setPos(parentItem()->boundingRect().topRight() - QPointF(180, -5));
+}
+
+void ProgressItem::setLevel(int level)
+{
+ currentLevel = level;
+ updateProgress();
+}
+
+void ProgressItem::setScore(int score)
+{
+ currentScore = score;
+ updateProgress();
+}
+
+void ProgressItem::updateProgress()
+{
+ setHtml(QString("Level : %1 Score : %2").arg(currentLevel).arg(currentScore));
+}
diff --git a/examples/animation/sub-attaq/progressitem.h b/examples/animation/sub-attaq/progressitem.h
new file mode 100644
index 0000000..7b8db4d
--- /dev/null
+++ b/examples/animation/sub-attaq/progressitem.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PROGRESSITEM_H
+#define PROGRESSITEM_H
+
+//Qt
+#include <QtGui/QGraphicsTextItem>
+
+class ProgressItem : public QGraphicsTextItem
+{
+public:
+ ProgressItem(QGraphicsItem * parent = 0);
+ void setLevel(int level);
+ void setScore(int score);
+
+private:
+ void updateProgress();
+ int currentLevel;
+ int currentScore;
+};
+
+#endif // PROGRESSITEM_H
diff --git a/examples/animation/sub-attaq/qanimationstate.cpp b/examples/animation/sub-attaq/qanimationstate.cpp
new file mode 100644
index 0000000..d4d109c
--- /dev/null
+++ b/examples/animation/sub-attaq/qanimationstate.cpp
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qanimationstate.h"
+
+#include <QtCore/qstate.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+\class QAnimationState
+
+\brief The QAnimationState class provides state that handle an animation and emit
+a signal when this animation is finished.
+
+\ingroup statemachine
+
+QAnimationState provides a state that handle an animation. It will start this animation
+when the state is entered and stop it when it is leaved. When the animation has finished the
+state emit animationFinished signal.
+QAnimationState is part of \l{The State Machine Framework}.
+
+\code
+QStateMachine machine;
+QAnimationState *s = new QAnimationState(machine->rootState());
+QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
+s->setAnimation(animation);
+QState *s2 = new QState(machine->rootState());
+s->addTransition(s, SIGNAL(animationFinished()), s2);
+machine.start();
+\endcode
+
+\sa QState, {The Animation Framework}
+*/
+
+
+#ifndef QT_NO_ANIMATION
+
+/*!
+ Constructs a new state with the given \a parent state.
+*/
+QAnimationState::QAnimationState(QState *parent)
+ : QState(parent), m_animation(0)
+{
+}
+
+/*!
+ Destroys the animation state.
+*/
+QAnimationState::~QAnimationState()
+{
+}
+
+/*!
+ Set an \a animation for this QAnimationState. If an animation was previously handle by this
+ state then it won't emit animationFinished for the old animation. The QAnimationState doesn't
+ take the ownership of the animation.
+*/
+void QAnimationState::setAnimation(QAbstractAnimation *animation)
+{
+ if (animation == m_animation)
+ return;
+
+ //Disconnect from the previous animation if exist
+ if(m_animation)
+ disconnect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished()));
+
+ m_animation = animation;
+
+ if (m_animation) {
+ //connect the new animation
+ connect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished()));
+ }
+}
+
+/*!
+ Returns the animation handle by this animation state, or 0 if there is no animation.
+*/
+QAbstractAnimation* QAnimationState::animation() const
+{
+ return m_animation;
+}
+
+/*!
+ \reimp
+*/
+void QAnimationState::onEntry(QEvent *)
+{
+ if (m_animation)
+ m_animation->start();
+}
+
+/*!
+ \reimp
+*/
+void QAnimationState::onExit(QEvent *)
+{
+ if (m_animation)
+ m_animation->stop();
+}
+
+/*!
+ \reimp
+*/
+bool QAnimationState::event(QEvent *e)
+{
+ return QState::event(e);
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/examples/animation/sub-attaq/qanimationstate.h b/examples/animation/sub-attaq/qanimationstate.h
new file mode 100644
index 0000000..e5322ad
--- /dev/null
+++ b/examples/animation/sub-attaq/qanimationstate.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QANIMATIONSTATE_H
+#define QANIMATIONSTATE_H
+
+#ifndef QT_STATEMACHINE_SOLUTION
+# include <QtCore/qstate.h>
+# include <QtCore/qabstractanimation.h>
+#else
+# include "qstate.h"
+# include "qabstractanimation.h"
+#endif
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_ANIMATION
+
+class QAbstractAnimation;
+
+class QAnimationState : public QState
+{
+ Q_OBJECT
+public:
+ QAnimationState(QState *parent = 0);
+ ~QAnimationState();
+
+ void setAnimation(QAbstractAnimation *animation);
+ QAbstractAnimation* animation() const;
+
+Q_SIGNALS:
+ void animationFinished();
+
+protected:
+ void onEntry(QEvent *);
+ void onExit(QEvent *);
+ bool event(QEvent *e);
+
+private:
+ Q_DISABLE_COPY(QAnimationState)
+ QAbstractAnimation *m_animation;
+};
+
+#endif
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QANIMATIONSTATE_H
diff --git a/examples/animation/sub-attaq/states.cpp b/examples/animation/sub-attaq/states.cpp
new file mode 100644
index 0000000..adc8bd0
--- /dev/null
+++ b/examples/animation/sub-attaq/states.cpp
@@ -0,0 +1,325 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "states.h"
+#include "graphicsscene.h"
+#include "boat.h"
+#include "submarine.h"
+#include "torpedo.h"
+#include "animationmanager.h"
+#include "progressitem.h"
+
+//Qt
+#include <QtGui/QMessageBox>
+#include <QtGui/QGraphicsView>
+#include <QtCore/QStateMachine>
+#include <QtGui/QKeyEventTransition>
+#include <QtCore/QSignalEvent>
+#include <QtCore/QFinalState>
+
+PlayState::PlayState(GraphicsScene *scene, QState *parent)
+ : QState(parent),
+ scene(scene),
+ machine(0),
+ currentLevel(0),
+ score(0)
+{
+}
+
+PlayState::~PlayState()
+{
+}
+
+void PlayState::onEntry(QEvent *)
+{
+ //We are now playing?
+ if (machine) {
+ machine->stop();
+ scene->clearScene();
+ currentLevel = 0;
+ score = 0;
+ delete machine;
+ }
+
+ machine = new QStateMachine(this);
+
+ //This state is when player is playing
+ LevelState *levelState = new LevelState(scene, this, machine->rootState());
+
+ //This state is when the player is actually playing but the game is not paused
+ QState *playingState = new QState(levelState);
+ levelState->setInitialState(playingState);
+
+ //This state is when the game is paused
+ PauseState *pauseState = new PauseState(scene, levelState);
+
+ //We have one view, it receive the key press event
+ QKeyEventTransition *pressPplay = new QKeyEventTransition(scene->views().at(0), QEvent::KeyPress, Qt::Key_P);
+ pressPplay->setTargetState(pauseState);
+ QKeyEventTransition *pressPpause = new QKeyEventTransition(scene->views().at(0), QEvent::KeyPress, Qt::Key_P);
+ pressPpause->setTargetState(playingState);
+
+ //Pause "P" is triggered, the player pause the game
+ playingState->addTransition(pressPplay);
+
+ //To get back playing when the game has been paused
+ pauseState->addTransition(pressPpause);
+
+ //This state is when player have lost
+ LostState *lostState = new LostState(scene, this, machine->rootState());
+
+ //This state is when player have won
+ WinState *winState = new WinState(scene, this, machine->rootState());
+
+ //The boat has been destroyed then the game is finished
+ levelState->addTransition(scene->boat, SIGNAL(boatExecutionFinished()),lostState);
+
+ //This transition check if we won or not
+ WinTransition *winTransition = new WinTransition(scene, this, winState);
+
+ //The boat has been destroyed then the game is finished
+ levelState->addTransition(winTransition);
+
+ //This state is an animation when the score changed
+ UpdateScoreState *scoreState = new UpdateScoreState(this, levelState);
+
+ //This transition update the score when a submarine die
+ UpdateScoreTransition *scoreTransition = new UpdateScoreTransition(scene, this, levelState);
+ scoreTransition->setTargetState(scoreState);
+
+ //The boat has been destroyed then the game is finished
+ playingState->addTransition(scoreTransition);
+
+ //We go back to play state
+ scoreState->addTransition(playingState);
+
+ //We start playing!!!
+ machine->setInitialState(levelState);
+
+ //Final state
+ QFinalState *final = new QFinalState(machine->rootState());
+
+ //This transition is triggered when the player press space after completing a level
+ CustomSpaceTransition *spaceTransition = new CustomSpaceTransition(scene->views().at(0), this, QEvent::KeyPress, Qt::Key_Space);
+ spaceTransition->setTargetState(levelState);
+ winState->addTransition(spaceTransition);
+
+ //We lost we should reach the final state
+ lostState->addTransition(lostState, SIGNAL(finished()), final);
+
+ machine->start();
+}
+
+LevelState::LevelState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game)
+{
+}
+void LevelState::onEntry(QEvent *)
+{
+ initializeLevel();
+}
+
+void LevelState::initializeLevel()
+{
+ //we re-init the boat
+ scene->boat->setPos(scene->width()/2, scene->sealLevel() - scene->boat->size().height());
+ scene->boat->setCurrentSpeed(0);
+ scene->boat->setCurrentDirection(Boat::None);
+ scene->boat->setBombsLaunched(0);
+ scene->boat->show();
+ scene->setFocusItem(scene->boat,Qt::OtherFocusReason);
+ scene->boat->run();
+
+ scene->progressItem->setScore(game->score);
+ scene->progressItem->setLevel(game->currentLevel + 1);
+
+ GraphicsScene::LevelDescription currentLevelDescription = scene->levelsData.value(game->currentLevel);
+
+ for (int i = 0; i < currentLevelDescription.submarines.size(); ++i ) {
+
+ QPair<int,int> subContent = currentLevelDescription.submarines.at(i);
+ GraphicsScene::SubmarineDescription submarineDesc = scene->submarinesData.at(subContent.first);
+
+ for (int j = 0; j < subContent.second; ++j ) {
+ SubMarine *sub = new SubMarine(submarineDesc.type, submarineDesc.name, submarineDesc.points);
+ scene->addItem(sub);
+ int random = (qrand() % 15 + 1);
+ qreal x = random == 13 || random == 5 ? 0 : scene->width() - sub->size().width();
+ qreal y = scene->height() -(qrand() % 150 + 1) - sub->size().height();
+ sub->setPos(x,y);
+ sub->setCurrentDirection(x == 0 ? SubMarine::Right : SubMarine::Left);
+ sub->setCurrentSpeed(qrand() % 3 + 1);
+ }
+ }
+}
+
+/** Pause State */
+PauseState::PauseState(GraphicsScene *scene, QState *parent) : QState(parent),scene(scene)
+{
+}
+void PauseState::onEntry(QEvent *)
+{
+ AnimationManager::self()->pauseAll();
+ scene->boat->setEnabled(false);
+}
+void PauseState::onExit(QEvent *)
+{
+ AnimationManager::self()->resumeAll();
+ scene->boat->setEnabled(true);
+ scene->boat->setFocus();
+}
+
+/** Lost State */
+LostState::LostState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game)
+{
+}
+
+void LostState::onEntry(QEvent *)
+{
+ //The message to display
+ QString message = QString("You lose on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score);
+
+ //We set the level back to 0
+ game->currentLevel = 0;
+
+ //We set the score back to 0
+ game->score = 0;
+
+ //We clear the scene
+ scene->clearScene();
+
+ //we have only one view
+ QMessageBox::information(scene->views().at(0),"You lose",message);
+}
+
+/** Win State */
+WinState::WinState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game)
+{
+}
+
+void WinState::onEntry(QEvent *)
+{
+ //We clear the scene
+ scene->clearScene();
+
+ QString message;
+ if (scene->levelsData.size() - 1 != game->currentLevel) {
+ message = QString("You win the level %1. Your score is %2.\nPress Space to continue after closing this dialog.").arg(game->currentLevel+1).arg(game->score);
+ //We increment the level number
+ game->currentLevel++;
+ } else {
+ message = QString("You finish the game on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score);
+ //We set the level back to 0
+ game->currentLevel = 0;
+ //We set the score back to 0
+ game->score = 0;
+ }
+
+ //we have only one view
+ QMessageBox::information(scene->views().at(0),"You win",message);
+}
+
+/** UpdateScore State */
+UpdateScoreState::UpdateScoreState(PlayState *game, QState *parent) : QState(parent)
+{
+ this->game = game;
+}
+void UpdateScoreState::onEntry(QEvent *e)
+{
+ QState::onEntry(e);
+}
+
+/** Win transition */
+UpdateScoreTransition::UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target)
+ : QSignalTransition(scene,SIGNAL(subMarineDestroyed(int)), QList<QAbstractState*>() << target),
+ game(game), scene(scene)
+{
+}
+
+bool UpdateScoreTransition::eventTest(QEvent *event)
+{
+ if (!QSignalTransition::eventTest(event))
+ return false;
+ else {
+ QSignalEvent *se = static_cast<QSignalEvent*>(event);
+ game->score += se->arguments().at(0).toInt();
+ scene->progressItem->setScore(game->score);
+ return true;
+ }
+}
+
+/** Win transition */
+WinTransition::WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target)
+ : QSignalTransition(scene,SIGNAL(allSubMarineDestroyed(int)), QList<QAbstractState*>() << target),
+ game(game), scene(scene)
+{
+}
+
+bool WinTransition::eventTest(QEvent *event)
+{
+ if (!QSignalTransition::eventTest(event))
+ return false;
+ else {
+ QSignalEvent *se = static_cast<QSignalEvent*>(event);
+ game->score += se->arguments().at(0).toInt();
+ scene->progressItem->setScore(game->score);
+ return true;
+ }
+}
+
+/** Space transition */
+CustomSpaceTransition::CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key)
+ : QKeyEventTransition(widget, type, key),
+ game(game)
+{
+}
+
+bool CustomSpaceTransition::eventTest(QEvent *event)
+{
+ Q_UNUSED(event);
+ if (!QKeyEventTransition::eventTest(event))
+ return false;
+ if (game->currentLevel != 0)
+ return true;
+ else
+ return false;
+
+}
diff --git a/examples/animation/sub-attaq/states.h b/examples/animation/sub-attaq/states.h
new file mode 100644
index 0000000..71375e0
--- /dev/null
+++ b/examples/animation/sub-attaq/states.h
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STATES_H
+#define STATES_H
+
+//Qt
+#include <QtCore/QState>
+#include <QtCore/QSignalTransition>
+#include <QtCore/QPropertyAnimation>
+#include <QtGui/QKeyEventTransition>
+#include <QtCore/QSet>
+
+class GraphicsScene;
+class Boat;
+class SubMarine;
+QT_BEGIN_NAMESPACE
+class QStateMachine;
+QT_END_NAMESPACE
+
+class PlayState : public QState
+{
+public:
+ PlayState(GraphicsScene *scene, QState *parent = 0);
+ ~PlayState();
+
+ protected:
+ void onEntry(QEvent *);
+
+private :
+ GraphicsScene *scene;
+ QStateMachine *machine;
+ int currentLevel;
+ int score;
+ QState *parallelChild;
+
+ friend class UpdateScoreState;
+ friend class UpdateScoreTransition;
+ friend class WinTransition;
+ friend class CustomSpaceTransition;
+ friend class WinState;
+ friend class LostState;
+ friend class LevelState;
+};
+
+class LevelState : public QState
+{
+public:
+ LevelState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
+protected:
+ void onEntry(QEvent *);
+private :
+ void initializeLevel();
+ GraphicsScene *scene;
+ PlayState *game;
+};
+
+class PauseState : public QState
+{
+public:
+ PauseState(GraphicsScene *scene, QState *parent = 0);
+
+protected:
+ void onEntry(QEvent *);
+ void onExit(QEvent *);
+private :
+ GraphicsScene *scene;
+ Boat *boat;
+};
+
+class LostState : public QState
+{
+public:
+ LostState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
+
+protected:
+ void onEntry(QEvent *);
+private :
+ GraphicsScene *scene;
+ PlayState *game;
+};
+
+class WinState : public QState
+{
+public:
+ WinState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
+
+protected:
+ void onEntry(QEvent *);
+private :
+ GraphicsScene *scene;
+ PlayState *game;
+};
+
+class UpdateScoreState : public QState
+{
+public:
+ UpdateScoreState(PlayState *game, QState *parent);
+protected:
+ void onEntry(QEvent *);
+private:
+ QPropertyAnimation *scoreAnimation;
+ PlayState *game;
+};
+
+//These transtion is used to update the score
+class UpdateScoreTransition : public QSignalTransition
+{
+public:
+ UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target);
+protected:
+ virtual bool eventTest(QEvent *event);
+private:
+ PlayState * game;
+ GraphicsScene *scene;
+};
+
+//These transtion test if we have won the game
+class WinTransition : public QSignalTransition
+{
+public:
+ WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target);
+protected:
+ virtual bool eventTest(QEvent *event);
+private:
+ PlayState * game;
+ GraphicsScene *scene;
+};
+
+//These transtion is true if one level has been completed and the player want to continue
+ class CustomSpaceTransition : public QKeyEventTransition
+{
+public:
+ CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key);
+protected:
+ virtual bool eventTest(QEvent *event);
+private:
+ PlayState *game;
+ int key;
+};
+
+#endif // STATES_H
diff --git a/examples/animation/sub-attaq/sub-attaq.pro b/examples/animation/sub-attaq/sub-attaq.pro
new file mode 100644
index 0000000..d13a099
--- /dev/null
+++ b/examples/animation/sub-attaq/sub-attaq.pro
@@ -0,0 +1,36 @@
+contains(QT_CONFIG, opengl):QT += opengl
+
+HEADERS += boat.h \
+ bomb.h \
+ mainwindow.h \
+ submarine.h \
+ torpedo.h \
+ pixmapitem.h \
+ graphicsscene.h \
+ animationmanager.h \
+ states.h \
+ boat_p.h \
+ submarine_p.h \
+ custompropertyanimation.h \
+ qanimationstate.h \
+ progressitem.h
+SOURCES += boat.cpp \
+ bomb.cpp \
+ main.cpp \
+ mainwindow.cpp \
+ submarine.cpp \
+ torpedo.cpp \
+ pixmapitem.cpp \
+ graphicsscene.cpp \
+ animationmanager.cpp \
+ states.cpp \
+ custompropertyanimation.cpp \
+ qanimationstate.cpp \
+ progressitem.cpp
+RESOURCES += subattaq.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/animation/sub-attaq
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS sub-attaq.pro pics
+sources.path = $$[QT_INSTALL_EXAMPLES]/animation/sub-attaq
+INSTALLS += target sources
diff --git a/examples/animation/sub-attaq/subattaq.qrc b/examples/animation/sub-attaq/subattaq.qrc
new file mode 100644
index 0000000..c76f8ef
--- /dev/null
+++ b/examples/animation/sub-attaq/subattaq.qrc
@@ -0,0 +1,38 @@
+<RCC>
+ <qresource prefix="/" >
+ <file alias="all" >pics/scalable/sub-attaq.svg</file>
+ <file alias="submarine" >pics/scalable/submarine.svg</file>
+ <file alias="boat" >pics/scalable/boat.svg</file>
+ <file alias="torpedo" >pics/scalable/torpedo.svg</file>
+ <file alias="logo-s" >pics/welcome/logo-s.png</file>
+ <file alias="logo-u" >pics/welcome/logo-u.png</file>
+ <file alias="logo-b" >pics/welcome/logo-b.png</file>
+ <file alias="logo-dash" >pics/welcome/logo-dash.png</file>
+ <file alias="logo-a" >pics/welcome/logo-a.png</file>
+ <file alias="logo-t" >pics/welcome/logo-t.png</file>
+ <file alias="logo-t2" >pics/welcome/logo-t2.png</file>
+ <file alias="logo-a2" >pics/welcome/logo-a2.png</file>
+ <file alias="logo-q" >pics/welcome/logo-q.png</file>
+ <file alias="logo-excl" >pics/welcome/logo-excl.png</file>
+ <file alias="big/background" >pics/big/background.png</file>
+ <file alias="big/boat" >pics/big/boat.png</file>
+ <file alias="big/bomb" >pics/big/bomb.png</file>
+ <file alias="big/submarine" >pics/big/submarine.png</file>
+ <file alias="big/surface" >pics/big/surface.png</file>
+ <file alias="big/torpedo" >pics/big/torpedo.png</file>
+ <file alias="small/background" >pics/small/background.png</file>
+ <file alias="small/boat" >pics/small/boat.png</file>
+ <file alias="small/bomb" >pics/small/bomb.png</file>
+ <file alias="small/submarine" >pics/small/submarine.png</file>
+ <file alias="small/surface" >pics/small/surface.png</file>
+ <file alias="small/torpedo" >pics/small/torpedo.png</file>
+ <file alias="big/explosion/boat/step1" >pics/big/explosion/boat/step1.png</file>
+ <file alias="big/explosion/boat/step2" >pics/big/explosion/boat/step2.png</file>
+ <file alias="big/explosion/boat/step3" >pics/big/explosion/boat/step3.png</file>
+ <file alias="big/explosion/boat/step4" >pics/big/explosion/boat/step4.png</file>
+ <file alias="big/explosion/submarine/step1" >pics/big/explosion/submarine/step1.png</file>
+ <file alias="big/explosion/submarine/step2" >pics/big/explosion/submarine/step2.png</file>
+ <file alias="big/explosion/submarine/step3" >pics/big/explosion/submarine/step3.png</file>
+ <file alias="big/explosion/submarine/step4" >pics/big/explosion/submarine/step4.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/animation/sub-attaq/submarine.cpp b/examples/animation/sub-attaq/submarine.cpp
new file mode 100644
index 0000000..d8cf1da
--- /dev/null
+++ b/examples/animation/sub-attaq/submarine.cpp
@@ -0,0 +1,211 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "submarine.h"
+#include "submarine_p.h"
+#include "torpedo.h"
+#include "pixmapitem.h"
+#include "graphicsscene.h"
+#include "animationmanager.h"
+#include "custompropertyanimation.h"
+#include "qanimationstate.h"
+
+#include <QtCore/QPropertyAnimation>
+#include <QtCore/QStateMachine>
+#include <QtCore/QFinalState>
+#include <QtCore/QSequentialAnimationGroup>
+
+static QAbstractAnimation *setupDestroyAnimation(SubMarine *sub)
+{
+ QSequentialAnimationGroup *group = new QSequentialAnimationGroup(sub);
+#if QT_VERSION >=0x040500
+ PixmapItem *step1 = new PixmapItem(QString("explosion/submarine/step1"),GraphicsScene::Big, sub);
+ step1->setZValue(6);
+ PixmapItem *step2 = new PixmapItem(QString("explosion/submarine/step2"),GraphicsScene::Big, sub);
+ step2->setZValue(6);
+ PixmapItem *step3 = new PixmapItem(QString("explosion/submarine/step3"),GraphicsScene::Big, sub);
+ step3->setZValue(6);
+ PixmapItem *step4 = new PixmapItem(QString("explosion/submarine/step4"),GraphicsScene::Big, sub);
+ step4->setZValue(6);
+ step1->setOpacity(0);
+ step2->setOpacity(0);
+ step3->setOpacity(0);
+ step4->setOpacity(0);
+ CustomPropertyAnimation *anim1 = new CustomPropertyAnimation(sub);
+ anim1->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim1->setDuration(100);
+ anim1->setEndValue(1);
+ CustomPropertyAnimation *anim2 = new CustomPropertyAnimation(sub);
+ anim2->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim2->setDuration(100);
+ anim2->setEndValue(1);
+ CustomPropertyAnimation *anim3 = new CustomPropertyAnimation(sub);
+ anim3->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim3->setDuration(100);
+ anim3->setEndValue(1);
+ CustomPropertyAnimation *anim4 = new CustomPropertyAnimation(sub);
+ anim4->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim4->setDuration(100);
+ anim4->setEndValue(1);
+ group->addAnimation(anim1);
+ group->addAnimation(anim2);
+ group->addAnimation(anim3);
+ group->addAnimation(anim4);
+#else
+ // work around for a bug where we don't transition if the duration is zero.
+ QtPauseAnimation *anim = new QtPauseAnimation(group);
+ anim->setDuration(1);
+ group->addAnimation(anim);
+#endif
+ AnimationManager::self()->registerAnimation(group);
+ return group;
+}
+
+
+SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem * parent, Qt::WindowFlags wFlags)
+ : QGraphicsWidget(parent,wFlags), subType(type), subName(name), subPoints(points), speed(0), direction(SubMarine::None)
+{
+ pixmapItem = new PixmapItem(QString("submarine"),GraphicsScene::Big, this);
+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ setZValue(5);
+ setFlags(QGraphicsItem::ItemIsMovable);
+ resize(pixmapItem->boundingRect().width(),pixmapItem->boundingRect().height());
+ setTransformOrigin(boundingRect().center());
+
+ //We setup the state machine of the submarine
+ QStateMachine *machine = new QStateMachine(this);
+
+ //This state is when the boat is moving/rotating
+ QState *moving = new QState(machine->rootState());
+
+ //This state is when the boat is moving from left to right
+ MovementState *movement = new MovementState(this, moving);
+
+ //This state is when the boat is moving from left to right
+ ReturnState *rotation = new ReturnState(this, moving);
+
+ //This is the initial state of the moving root state
+ moving->setInitialState(movement);
+
+ movement->addTransition(this, SIGNAL(subMarineStateChanged()), moving);
+
+ //This is the initial state of the machine
+ machine->setInitialState(moving);
+
+ //End
+ QFinalState *final = new QFinalState(machine->rootState());
+
+ //If the moving animation is finished we move to the return state
+ movement->addTransition(movement, SIGNAL(animationFinished()), rotation);
+
+ //If the return animation is finished we move to the moving state
+ rotation->addTransition(rotation, SIGNAL(animationFinished()), movement);
+
+ //This state play the destroyed animation
+ QAnimationState *destroyedState = new QAnimationState(machine->rootState());
+ destroyedState->setAnimation(setupDestroyAnimation(this));
+
+ //Play a nice animation when the submarine is destroyed
+ moving->addTransition(this, SIGNAL(subMarineDestroyed()), destroyedState);
+
+ //Transition to final state when the destroyed animation is finished
+ destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final);
+
+ //The machine has finished to be executed, then the submarine is dead
+ connect(machine,SIGNAL(finished()),this, SIGNAL(subMarineExecutionFinished()));
+
+ machine->start();
+}
+
+int SubMarine::points()
+{
+ return subPoints;
+}
+
+void SubMarine::setCurrentDirection(SubMarine::Movement direction)
+{
+ if (this->direction == direction)
+ return;
+ if (direction == SubMarine::Right && this->direction == SubMarine::None) {
+ setYRotation(180);
+ }
+ this->direction = direction;
+}
+
+enum SubMarine::Movement SubMarine::currentDirection() const
+{
+ return direction;
+}
+
+void SubMarine::setCurrentSpeed(int speed)
+{
+ if (speed < 0 || speed > 3) {
+ qWarning("SubMarine::setCurrentSpeed : The speed is invalid");
+ }
+ this->speed = speed;
+ emit subMarineStateChanged();
+}
+
+int SubMarine::currentSpeed() const
+{
+ return speed;
+}
+
+void SubMarine::launchTorpedo(int speed)
+{
+ Torpedo * torp = new Torpedo();
+ GraphicsScene *scene = static_cast<GraphicsScene *>(this->scene());
+ scene->addItem(torp);
+ torp->setPos(x(), y());
+ torp->setCurrentSpeed(speed);
+ torp->launch();
+}
+
+void SubMarine::destroy()
+{
+ emit subMarineDestroyed();
+}
+
+int SubMarine::type() const
+{
+ return Type;
+}
diff --git a/examples/animation/sub-attaq/submarine.h b/examples/animation/sub-attaq/submarine.h
new file mode 100644
index 0000000..4001603
--- /dev/null
+++ b/examples/animation/sub-attaq/submarine.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __SUBMARINE__H__
+#define __SUBMARINE__H__
+
+//Qt
+#include <QtCore/QVariantAnimation>
+#include <QtGui/QGraphicsWidget>
+
+class PixmapItem;
+
+class Torpedo;
+
+class SubMarine : public QGraphicsWidget
+{
+Q_OBJECT
+public:
+ enum Movement {
+ None = 0,
+ Left,
+ Right
+ };
+ enum { Type = UserType + 1 };
+ SubMarine(int type, const QString &name, int points, QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0);
+
+ int points();
+
+ void setCurrentDirection(Movement direction);
+ enum Movement currentDirection() const;
+
+ void setCurrentSpeed(int speed);
+ int currentSpeed() const;
+
+ void launchTorpedo(int speed);
+ void destroy();
+
+ virtual int type() const;
+
+Q_SIGNALS:
+ void subMarineDestroyed();
+ void subMarineExecutionFinished();
+ void subMarineStateChanged();
+
+private:
+ int subType;
+ QString subName;
+ int subPoints;
+ int speed;
+ Movement direction;
+ PixmapItem *pixmapItem;
+};
+
+#endif //__SUBMARINE__H__
diff --git a/examples/animation/sub-attaq/submarine_p.h b/examples/animation/sub-attaq/submarine_p.h
new file mode 100644
index 0000000..8c31eb7
--- /dev/null
+++ b/examples/animation/sub-attaq/submarine_p.h
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SUBMARINE_P_H
+#define SUBMARINE_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.
+//
+
+//Own
+#include "animationmanager.h"
+#include "submarine.h"
+#include "qanimationstate.h"
+
+//Qt
+#include <QtCore/QPropertyAnimation>
+#include <QtGui/QGraphicsScene>
+
+//This state is describing when the boat is moving right
+class MovementState : public QAnimationState
+{
+Q_OBJECT
+public:
+ MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
+ {
+ movementAnimation = new QPropertyAnimation(submarine, "pos");
+ connect(movementAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationMovementValueChanged(const QVariant &)));
+ setAnimation(movementAnimation);
+ AnimationManager::self()->registerAnimation(movementAnimation);
+ this->submarine = submarine;
+ }
+
+protected slots:
+ void onAnimationMovementValueChanged(const QVariant &)
+ {
+ if (qrand() % 200 + 1 == 3)
+ submarine->launchTorpedo(qrand() % 3 + 1);
+ }
+
+protected:
+ void onEntry(QEvent *e)
+ {
+ if (submarine->currentDirection() == SubMarine::Left) {
+ movementAnimation->setEndValue(QPointF(0,submarine->y()));
+ movementAnimation->setDuration(submarine->x()/submarine->currentSpeed()*12);
+ }
+ else /*if (submarine->currentDirection() == SubMarine::Right)*/ {
+ movementAnimation->setEndValue(QPointF(submarine->scene()->width()-submarine->size().width(),submarine->y()));
+ movementAnimation->setDuration((submarine->scene()->width()-submarine->size().width()-submarine->x())/submarine->currentSpeed()*12);
+ }
+ movementAnimation->setStartValue(submarine->pos());
+ QAnimationState::onEntry(e);
+ }
+
+private:
+ SubMarine *submarine;
+ QPropertyAnimation *movementAnimation;
+};
+
+//This state is describing when the boat is moving right
+class ReturnState : public QAnimationState
+{
+public:
+ ReturnState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
+ {
+ returnAnimation = new QPropertyAnimation(submarine, "yRotation");
+ AnimationManager::self()->registerAnimation(returnAnimation);
+ setAnimation(returnAnimation);
+ this->submarine = submarine;
+ }
+
+protected:
+ void onEntry(QEvent *e)
+ {
+ returnAnimation->stop();
+ returnAnimation->setStartValue(submarine->yRotation());
+ returnAnimation->setEndValue(submarine->currentDirection() == SubMarine::Right ? 360. : 180.);
+ returnAnimation->setDuration(500);
+ QAnimationState::onEntry(e);
+ }
+
+ void onExit(QEvent *e)
+ {
+ submarine->currentDirection() == SubMarine::Right ? submarine->setCurrentDirection(SubMarine::Left) : submarine->setCurrentDirection(SubMarine::Right);
+ QAnimationState::onExit(e);
+ }
+
+private:
+ SubMarine *submarine;
+ QPropertyAnimation *returnAnimation;
+};
+
+#endif // SUBMARINE_P_H
diff --git a/examples/animation/sub-attaq/torpedo.cpp b/examples/animation/sub-attaq/torpedo.cpp
new file mode 100644
index 0000000..02a54fc
--- /dev/null
+++ b/examples/animation/sub-attaq/torpedo.cpp
@@ -0,0 +1,120 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "torpedo.h"
+#include "pixmapitem.h"
+#include "boat.h"
+#include "graphicsscene.h"
+#include "animationmanager.h"
+#include "qanimationstate.h"
+
+#include <QtCore/QPropertyAnimation>
+#include <QtCore/QStateMachine>
+#include <QtCore/QFinalState>
+
+Torpedo::Torpedo(QGraphicsItem * parent, Qt::WindowFlags wFlags)
+ : QGraphicsWidget(parent,wFlags), currentSpeed(0), launchAnimation(0)
+{
+ pixmapItem = new PixmapItem(QString::fromLatin1("torpedo"),GraphicsScene::Big, this);
+ setZValue(2);
+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ setFlags(QGraphicsItem::ItemIsMovable);
+ resize(pixmapItem->boundingRect().size());
+}
+
+void Torpedo::launch()
+{
+ launchAnimation = new QPropertyAnimation(this, "pos");
+ AnimationManager::self()->registerAnimation(launchAnimation);
+ launchAnimation->setEndValue(QPointF(x(),qobject_cast<GraphicsScene *>(scene())->sealLevel() - 15));
+ launchAnimation->setEasingCurve(QEasingCurve::InQuad);
+ launchAnimation->setDuration(y()/currentSpeed*10);
+ connect(launchAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationLaunchValueChanged(const QVariant &)));
+
+ //We setup the state machine of the torpedo
+ QStateMachine *machine = new QStateMachine(this);
+
+ //This state is when the launch animation is playing
+ QAnimationState *launched = new QAnimationState(machine->rootState());
+ launched->setAnimation(launchAnimation);
+
+ //End
+ QFinalState *final = new QFinalState(machine->rootState());
+
+ machine->setInitialState(launched);
+
+ //### Add a nice animation when the torpedo is destroyed
+ launched->addTransition(this, SIGNAL(torpedoExplosed()),final);
+
+ //If the animation is finished, then we move to the final state
+ launched->addTransition(launched, SIGNAL(animationFinished()), final);
+
+ //The machine has finished to be executed, then the boat is dead
+ connect(machine,SIGNAL(finished()),this, SIGNAL(torpedoExecutionFinished()));
+
+ machine->start();
+}
+
+void Torpedo::setCurrentSpeed(int speed)
+{
+ if (speed < 0) {
+ qWarning("Torpedo::setCurrentSpeed : The speed is invalid");
+ return;
+ }
+ currentSpeed = speed;
+}
+
+void Torpedo::onAnimationLaunchValueChanged(const QVariant &)
+{
+ foreach (QGraphicsItem *item , collidingItems(Qt::IntersectsItemBoundingRect)) {
+ if (item->type() == Boat::Type) {
+ Boat *b = static_cast<Boat *>(item);
+ b->destroy();
+ }
+ }
+}
+
+void Torpedo::destroy()
+{
+ launchAnimation->stop();
+ emit torpedoExplosed();
+}
diff --git a/examples/animation/sub-attaq/torpedo.h b/examples/animation/sub-attaq/torpedo.h
new file mode 100644
index 0000000..4a0f457
--- /dev/null
+++ b/examples/animation/sub-attaq/torpedo.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __TORPEDO__H__
+#define __TORPEDO__H__
+
+//Qt
+#include <QtCore/QObject>
+
+#include <QtCore/QVariantAnimation>
+#include <QtGui/QGraphicsWidget>
+
+class PixmapItem;
+
+class Torpedo : public QGraphicsWidget
+{
+Q_OBJECT
+Q_PROPERTY(QPointF pos READ pos WRITE setPos)
+public:
+ Torpedo(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0);
+ void launch();
+ void setCurrentSpeed(int speed);
+ void destroy();
+
+Q_SIGNALS:
+ void torpedoExplosed();
+ void torpedoExecutionFinished();
+
+private slots:
+ void onAnimationLaunchValueChanged(const QVariant &);
+
+private:
+ int currentSpeed;
+ PixmapItem *pixmapItem;
+ QVariantAnimation *launchAnimation;
+};
+
+#endif //__TORPEDO__H__
diff --git a/examples/examples.pro b/examples/examples.pro
index 2d49103..d537b8f 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -1,5 +1,6 @@
TEMPLATE = subdirs
SUBDIRS = \
+ animation \
desktop \
dialogs \
draganddrop \
@@ -14,6 +15,7 @@ SUBDIRS = \
qtconcurrent \
richtext \
sql \
+ statemachine \
threads \
tools \
tutorials \
diff --git a/examples/opengl/framebufferobject/glwidget.cpp b/examples/opengl/framebufferobject/glwidget.cpp
index d3591d6..3cb3929 100644
--- a/examples/opengl/framebufferobject/glwidget.cpp
+++ b/examples/opengl/framebufferobject/glwidget.cpp
@@ -53,7 +53,18 @@ GLWidget::GLWidget(QWidget *parent)
{
setWindowTitle(tr("OpenGL framebuffer objects"));
makeCurrent();
- fbo = new QGLFramebufferObject(1024, 1024);
+
+ if (QGLFramebufferObject::hasOpenGLFramebufferBlit()) {
+ QGLFramebufferObjectFormat format;
+ format.setSamples(4);
+
+ render_fbo = new QGLFramebufferObject(512, 512, format);
+ texture_fbo = new QGLFramebufferObject(512, 512);
+ } else {
+ render_fbo = new QGLFramebufferObject(1024, 1024);
+ texture_fbo = render_fbo;
+ }
+
rot_x = rot_y = rot_z = 0.0f;
scale = 0.1f;
anim = new QTimeLine(750, this);
@@ -113,7 +124,9 @@ GLWidget::~GLWidget()
{
delete[] wave;
glDeleteLists(tile_list, 1);
- delete fbo;
+ delete texture_fbo;
+ if (render_fbo != texture_fbo)
+ delete render_fbo;
}
void GLWidget::paintEvent(QPaintEvent *)
@@ -129,10 +142,16 @@ void GLWidget::draw()
saveGLState();
// render the 'bubbles.svg' file into our framebuffer object
- QPainter fbo_painter(fbo);
+ QPainter fbo_painter(render_fbo);
svg_renderer->render(&fbo_painter);
fbo_painter.end();
+ if (render_fbo != texture_fbo) {
+ QRect rect(0, 0, render_fbo->width(), render_fbo->height());
+ QGLFramebufferObject::blitFramebuffer(texture_fbo, rect,
+ render_fbo, rect);
+ }
+
// draw into the GL widget
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
@@ -145,8 +164,9 @@ void GLWidget::draw()
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glBindTexture(GL_TEXTURE_2D, fbo->texture());
+ glBindTexture(GL_TEXTURE_2D, texture_fbo->texture());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glEnable(GL_TEXTURE_2D);
glEnable(GL_MULTISAMPLE);
glEnable(GL_CULL_FACE);
diff --git a/examples/opengl/framebufferobject/glwidget.h b/examples/opengl/framebufferobject/glwidget.h
index b64cfa8..d97ef78 100644
--- a/examples/opengl/framebufferobject/glwidget.h
+++ b/examples/opengl/framebufferobject/glwidget.h
@@ -77,6 +77,7 @@ private:
QImage logo;
QTimeLine *anim;
QSvgRenderer *svg_renderer;
- QGLFramebufferObject *fbo;
+ QGLFramebufferObject *render_fbo;
+ QGLFramebufferObject *texture_fbo;
};
diff --git a/examples/opengl/hellogl_es2/glwidget.cpp b/examples/opengl/hellogl_es2/glwidget.cpp
index 213c5b2..ee50670 100644
--- a/examples/opengl/hellogl_es2/glwidget.cpp
+++ b/examples/opengl/hellogl_es2/glwidget.cpp
@@ -48,124 +48,10 @@
const int bubbleNum = 8;
-inline void CrossProduct(qreal &xOut, qreal &yOut, qreal &zOut, qreal x1, qreal y1, qreal z1, qreal x2, qreal y2, qreal z2)
-{
- xOut = y1 * z2 - z1 * y2;
- yOut = z1 * x2 - x1 * z2;
- zOut = x1 * y2 - y1 * x2;
-}
-
-inline void Normalize(qreal &x, qreal &y, qreal &z)
-{
- qreal l = sqrt(x*x + y*y + z*z);
- x = x / l;
- y = y / l;
- z = z / l;
-}
-
-inline void IdentityMatrix(GLfloat *m)
-{
- m[0 * 4 + 0] = 1.0f;
- m[1 * 4 + 0] = 0.0f;
- m[2 * 4 + 0] = 0.0f;
- m[3 * 4 + 0] = 0.0f;
- m[0 * 4 + 1] = 0.0f;
- m[1 * 4 + 1] = 1.0f;
- m[2 * 4 + 1] = 0.0f;
- m[3 * 4 + 1] = 0.0f;
- m[0 * 4 + 2] = 0.0f;
- m[1 * 4 + 2] = 0.0f;
- m[2 * 4 + 2] = 1.0f;
- m[3 * 4 + 2] = 0.0f;
- m[0 * 4 + 3] = 0.0f;
- m[1 * 4 + 3] = 0.0f;
- m[2 * 4 + 3] = 0.0f;
- m[3 * 4 + 3] = 1.0f;
-}
-
-// Adjust a 4x4 matrix to apply a scale.
-inline void ScaleMatrix(GLfloat *m, GLfloat scalex, GLfloat scaley, GLfloat scalez)
-{
- m[0 * 4 + 0] *= scalex;
- m[0 * 4 + 1] *= scalex;
- m[0 * 4 + 2] *= scalex;
- m[0 * 4 + 3] *= scalex;
- m[1 * 4 + 0] *= scaley;
- m[1 * 4 + 1] *= scaley;
- m[1 * 4 + 2] *= scaley;
- m[1 * 4 + 3] *= scaley;
- m[2 * 4 + 0] *= scalez;
- m[2 * 4 + 1] *= scalez;
- m[2 * 4 + 2] *= scalez;
- m[2 * 4 + 3] *= scalez;
-}
-
-// Adjust a 4x4 matrix to apply a translation.
-inline void TranslateMatrix(GLfloat *m, GLfloat translatex, GLfloat translatey, GLfloat translatez)
-{
- m[3 * 4 + 0] += m[0 * 4 + 0] * translatex + m[1 * 4 + 0] * translatey + m[2 * 4 + 0] * translatez;
- m[3 * 4 + 1] += m[0 * 4 + 1] * translatex + m[1 * 4 + 1] * translatey + m[2 * 4 + 1] * translatez;
- m[3 * 4 + 2] += m[0 * 4 + 2] * translatex + m[1 * 4 + 2] * translatey + m[2 * 4 + 2] * translatez;
- m[3 * 4 + 3] += m[0 * 4 + 3] * translatex + m[1 * 4 + 3] * translatey + m[2 * 4 + 3] * translatez;
-}
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-// Adjust a 4x4 matrix to apply a rotation.
-inline void RotateMatrix(GLfloat *m, GLfloat angle, GLfloat vx, GLfloat vy, GLfloat vz)
-{
- GLfloat len = sqrt(vx * vx + vy * vy + vz * vz);
- if (len != 0) {
- vx /= len;
- vy /= len;
- vz /= len;
- }
-
- GLfloat c, s, ic;
- c = cos(angle * M_PI / 180.0);
- s = sin(angle * M_PI / 180.0);
- ic = 1.0f - c;
-
- GLfloat rot[16];
- rot[0 * 4 + 0] = vx * vx * ic + c;
- rot[1 * 4 + 0] = vx * vy * ic - vz * s;
- rot[2 * 4 + 0] = vx * vz * ic + vy * s;
- rot[3 * 4 + 0] = 0.0f;
- rot[0 * 4 + 1] = vy * vx * ic + vz * s;
- rot[1 * 4 + 1] = vy * vy * ic + c;
- rot[2 * 4 + 1] = vy * vz * ic - vx * s;
- rot[3 * 4 + 1] = 0.0f;
- rot[0 * 4 + 2] = vx * vz * ic - vy * s;
- rot[1 * 4 + 2] = vy * vz * ic + vx * s;
- rot[2 * 4 + 2] = vz * vz * ic + c;
- rot[3 * 4 + 2] = 0.0f;
- rot[0 * 4 + 3] = 0.0f;
- rot[1 * 4 + 3] = 0.0f;
- rot[2 * 4 + 3] = 0.0f;
- rot[3 * 4 + 3] = 1.0f;
-
- GLfloat temp[16];
- for (int i = 0; i < 4; ++i) {
- for (int j = 0; j < 4; ++j) {
- temp[j * 4 + i] = 0.0f;
- for (int k = 0; k < 4; ++k) {
- temp[j * 4 + i] += m[k * 4 + i] * rot[j * 4 + k];
- }
- }
- }
-
- qMemCopy(m, temp, sizeof(temp));
-}
-
GLWidget::GLWidget(QWidget *parent)
: QGLWidget(parent)
{
qtLogo = true;
- createdVertices = 0;
- createdNormals = 0;
- m_vertexNumber = 0;
frames = 0;
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
@@ -178,10 +64,6 @@ GLWidget::GLWidget(QWidget *parent)
GLWidget::~GLWidget()
{
- if (createdVertices)
- delete[] createdVertices;
- if (createdNormals)
- delete[] createdNormals;
}
void GLWidget::setScaling(int scale) {
@@ -210,13 +92,11 @@ void GLWidget::showBubbles(bool bubbles)
void GLWidget::paintQtLogo()
{
glDisable(GL_TEXTURE_2D);
- glVertexAttribPointer(vertexAttr1, 3, GL_FLOAT, GL_FALSE, 0, createdVertices);
- glEnableVertexAttribArray(vertexAttr1);
- glVertexAttribPointer(normalAttr1, 3, GL_FLOAT, GL_FALSE, 0, createdNormals);
- glEnableVertexAttribArray(normalAttr1);
- glDrawArrays(GL_TRIANGLES, 0, m_vertexNumber / 3);
- glDisableVertexAttribArray(normalAttr1);
- glDisableVertexAttribArray(vertexAttr1);
+ program1.setAttributeArray(vertexAttr1, vertices.constData());
+ program1.setAttributeArray(normalAttr1, normals.constData());
+ glDrawArrays(GL_TRIANGLES, 0, vertices.size());
+ program1.disableAttributeArray(normalAttr1);
+ program1.disableAttributeArray(vertexAttr1);
}
void GLWidget::paintTexturedCube()
@@ -239,8 +119,7 @@ void GLWidget::paintTexturedCube()
-0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5,
0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5
};
- glVertexAttribPointer(vertexAttr2, 3, GL_FLOAT, GL_FALSE, 0, afVertices);
- glEnableVertexAttribArray(vertexAttr2);
+ program2.setAttributeArray(vertexAttr2, afVertices, 3);
GLfloat afTexCoord[] = {
0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f,
@@ -258,8 +137,7 @@ void GLWidget::paintTexturedCube()
1.0f,0.0f, 1.0f,1.0f, 0.0f,0.0f,
0.0f,1.0f, 0.0f,0.0f, 1.0f,1.0f
};
- glVertexAttribPointer(texCoordAttr2, 2, GL_FLOAT, GL_FALSE, 0, afTexCoord);
- glEnableVertexAttribArray(texCoordAttr2);
+ program2.setAttributeArray(texCoordAttr2, afTexCoord, 2);
GLfloat afNormals[] = {
@@ -278,50 +156,15 @@ void GLWidget::paintTexturedCube()
0,1,0, 0,1,0, 0,1,0,
0,1,0, 0,1,0, 0,1,0
};
- glVertexAttribPointer(normalAttr2, 3, GL_FLOAT, GL_FALSE, 0, afNormals);
- glEnableVertexAttribArray(normalAttr2);
+ program2.setAttributeArray(normalAttr2, afNormals, 3);
- glUniform1i(textureUniform2, 0); // use texture unit 0
+ program2.setUniformValue(textureUniform2, 0); // use texture unit 0
glDrawArrays(GL_TRIANGLES, 0, 36);
- glDisableVertexAttribArray(vertexAttr2);
- glDisableVertexAttribArray(normalAttr2);
- glDisableVertexAttribArray(texCoordAttr2);
-}
-
-static void reportCompileErrors(GLuint shader, const char *src)
-{
- GLint value = 0;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &value);
- bool compiled = (value != 0);
- value = 0;
- glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &value);
- if (!compiled && value > 1) {
- char *log = new char [value];
- GLint len;
- glGetShaderInfoLog(shader, value, &len, log);
- qWarning("%s\n", log);
- qWarning("when compiling:\n%s\n", src);
- delete [] log;
- }
-}
-
-static void reportLinkErrors(GLuint program, const char *vsrc, const char *fsrc)
-{
- GLint value = 0;
- glGetProgramiv(program, GL_LINK_STATUS, &value);
- bool linked = (value != 0);
- value = 0;
- glGetProgramiv(program, GL_INFO_LOG_LENGTH, &value);
- if (!linked && value > 1) {
- char *log = new char [value];
- GLint len;
- glGetProgramInfoLog(program, value, &len, log);
- qWarning("%s\n", log);
- qWarning("when linking:\n%s\nwith:\n%s\n", vsrc, fsrc);
- delete [] log;
- }
+ program2.disableAttributeArray(vertexAttr2);
+ program2.disableAttributeArray(normalAttr2);
+ program2.disableAttributeArray(texCoordAttr2);
}
void GLWidget::initializeGL ()
@@ -332,8 +175,8 @@ void GLWidget::initializeGL ()
glGenTextures(1, &m_uiTexture);
m_uiTexture = bindTexture(QImage(":/qt.png"));
- GLuint vshader1 = glCreateShader(GL_VERTEX_SHADER);
- const char *vsrc1[1] = {
+ QGLShader *vshader1 = new QGLShader(QGLShader::VertexShader, this);
+ const char *vsrc1 =
"attribute highp vec4 vertex;\n"
"attribute mediump vec3 normal;\n"
"uniform mediump mat4 matrix;\n"
@@ -346,36 +189,28 @@ void GLWidget::initializeGL ()
" color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);\n"
" color = clamp(color, 0.0, 1.0);\n"
" gl_Position = matrix * vertex;\n"
- "}\n"
- };
- glShaderSource(vshader1, 1, vsrc1, 0);
- glCompileShader(vshader1);
- reportCompileErrors(vshader1, vsrc1[0]);
+ "}\n";
+ vshader1->setSourceCode(vsrc1);
- GLuint fshader1 = glCreateShader(GL_FRAGMENT_SHADER);
- const char *fsrc1[1] = {
+ QGLShader *fshader1 = new QGLShader(QGLShader::FragmentShader, this);
+ const char *fsrc1 =
"varying mediump vec4 color;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = color;\n"
- "}\n"
- };
- glShaderSource(fshader1, 1, fsrc1, 0);
- glCompileShader(fshader1);
- reportCompileErrors(fshader1, fsrc1[0]);
-
- program1 = glCreateProgram();
- glAttachShader(program1, vshader1);
- glAttachShader(program1, fshader1);
- glLinkProgram(program1);
- reportLinkErrors(program1, vsrc1[0], fsrc1[0]);
-
- vertexAttr1 = glGetAttribLocation(program1, "vertex");
- normalAttr1 = glGetAttribLocation(program1, "normal");
- matrixUniform1 = glGetUniformLocation(program1, "matrix");
-
- GLuint vshader2 = glCreateShader(GL_VERTEX_SHADER);
- const char *vsrc2[1] = {
+ "}\n";
+ fshader1->setSourceCode(fsrc1);
+
+ program1.addShader(vshader1);
+ program1.addShader(fshader1);
+ program1.link();
+
+ vertexAttr1 = program1.attributeLocation("vertex");
+ normalAttr1 = program1.attributeLocation("normal");
+ matrixUniform1 = program1.uniformLocation("matrix");
+
+ QGLShader *vshader2 = new QGLShader(QGLShader::VertexShader);
+ const char *vsrc2 =
"attribute highp vec4 vertex;\n"
"attribute highp vec4 texCoord;\n"
"attribute mediump vec3 normal;\n"
@@ -388,14 +223,11 @@ void GLWidget::initializeGL ()
" angle = max(dot(normal, toLight), 0.0);\n"
" gl_Position = matrix * vertex;\n"
" texc = texCoord;\n"
- "}\n"
- };
- glShaderSource(vshader2, 1, vsrc2, 0);
- glCompileShader(vshader2);
- reportCompileErrors(vshader2, vsrc2[0]);
+ "}\n";
+ vshader2->setSourceCode(vsrc2);
- GLuint fshader2 = glCreateShader(GL_FRAGMENT_SHADER);
- const char *fsrc2[1] = {
+ QGLShader *fshader2 = new QGLShader(QGLShader::FragmentShader);
+ const char *fsrc2 =
"varying highp vec4 texc;\n"
"uniform sampler2D tex;\n"
"varying mediump float angle;\n"
@@ -404,23 +236,18 @@ void GLWidget::initializeGL ()
" highp vec3 color = texture2D(tex, texc.st).rgb;\n"
" color = color * 0.2 + color * 0.8 * angle;\n"
" gl_FragColor = vec4(clamp(color, 0.0, 1.0), 1.0);\n"
- "}\n"
- };
- glShaderSource(fshader2, 1, fsrc2, 0);
- glCompileShader(fshader2);
- reportCompileErrors(fshader2, fsrc2[0]);
-
- program2 = glCreateProgram();
- glAttachShader(program2, vshader2);
- glAttachShader(program2, fshader2);
- glLinkProgram(program2);
- reportLinkErrors(program2, vsrc2[0], fsrc2[0]);
-
- vertexAttr2 = glGetAttribLocation(program2, "vertex");
- normalAttr2 = glGetAttribLocation(program2, "normal");
- texCoordAttr2 = glGetAttribLocation(program2, "texCoord");
- matrixUniform2 = glGetUniformLocation(program2, "matrix");
- textureUniform2 = glGetUniformLocation(program2, "tex");
+ "}\n";
+ fshader2->setSourceCode(fsrc2);
+
+ program2.addShader(vshader2);
+ program2.addShader(fshader2);
+ program2.link();
+
+ vertexAttr2 = program2.attributeLocation("vertex");
+ normalAttr2 = program2.attributeLocation("normal");
+ texCoordAttr2 = program2.attributeLocation("texCoord");
+ matrixUniform2 = program2.uniformLocation("matrix");
+ textureUniform2 = program2.uniformLocation("tex");
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
@@ -450,24 +277,23 @@ void GLWidget::paintGL()
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
- GLfloat modelview[16];
- IdentityMatrix(modelview);
- RotateMatrix(modelview, m_fAngle, 0.0, 1.0, 0.0);
- RotateMatrix(modelview, m_fAngle, 1.0, 0.0, 0.0);
- RotateMatrix(modelview, m_fAngle, 0.0, 0.0, 1.0);
- ScaleMatrix(modelview, m_fScale, m_fScale, m_fScale);
- TranslateMatrix(modelview, 0, -0.2, 0);
+ QMatrix4x4 modelview;
+ modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
+ modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
+ modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
+ modelview.scale(m_fScale);
+ modelview.translate(0.0f, -0.2f, 0.0f);
if (qtLogo) {
- glUseProgram(program1);
- glUniformMatrix4fv(matrixUniform1, 1, GL_FALSE, modelview);
+ program1.enable();
+ program1.setUniformValue(matrixUniform1, modelview);
paintQtLogo();
- glUseProgram(0);
+ program1.disable();
} else {
- glUseProgram(program2);
- glUniformMatrix4fv(matrixUniform2, 1, GL_FALSE, modelview);
+ program2.enable();
+ program1.setUniformValue(matrixUniform2, modelview);
paintTexturedCube();
- glUseProgram(0);
+ program2.disable();
}
glDisable(GL_DEPTH_TEST);
@@ -563,80 +389,69 @@ void GLWidget::createGeometry()
extrude(x8, y8, x5, y5);
}
- m_vertexNumber = vertices.size();
- createdVertices = new GLfloat[m_vertexNumber];
- createdNormals = new GLfloat[m_vertexNumber];
- for (int i = 0;i < m_vertexNumber;i++) {
- createdVertices[i] = vertices.at(i) * 2;
- createdNormals[i] = normals.at(i);
- }
- vertices.clear();
- normals.clear();
+ for (int i = 0;i < vertices.size();i++)
+ vertices[i] *= 2.0f;
}
void GLWidget::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4)
{
- qreal nx, ny, nz;
+ vertices << QVector3D(x1, y1, -0.05f);
+ vertices << QVector3D(x2, y2, -0.05f);
+ vertices << QVector3D(x4, y4, -0.05f);
- vertices << x1 << y1 << -0.05f;
- vertices << x2 << y2 << -0.05f;
- vertices << x4 << y4 << -0.05f;
+ vertices << QVector3D(x3, y3, -0.05f);
+ vertices << QVector3D(x4, y4, -0.05f);
+ vertices << QVector3D(x2, y2, -0.05f);
- vertices << x3 << y3 << -0.05f;
- vertices << x4 << y4 << -0.05f;
- vertices << x2 << y2 << -0.05f;
+ QVector3D n = QVector3D::normal
+ (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(x4 - x1, y4 - y1, 0.0f));
- CrossProduct(nx, ny, nz, x2 - x1, y2 - y1, 0, x4 - x1, y4 - y1, 0);
- Normalize(nx, ny, nz);
+ normals << n;
+ normals << n;
+ normals << n;
- normals << nx << ny << nz;
- normals << nx << ny << nz;
- normals << nx << ny << nz;
+ normals << n;
+ normals << n;
+ normals << n;
- normals << nx << ny << nz;
- normals << nx << ny << nz;
- normals << nx << ny << nz;
+ vertices << QVector3D(x4, y4, 0.05f);
+ vertices << QVector3D(x2, y2, 0.05f);
+ vertices << QVector3D(x1, y1, 0.05f);
- vertices << x4 << y4 << 0.05f;
- vertices << x2 << y2 << 0.05f;
- vertices << x1 << y1 << 0.05f;
+ vertices << QVector3D(x2, y2, 0.05f);
+ vertices << QVector3D(x4, y4, 0.05f);
+ vertices << QVector3D(x3, y3, 0.05f);
- vertices << x2 << y2 << 0.05f;
- vertices << x4 << y4 << 0.05f;
- vertices << x3 << y3 << 0.05f;
+ n = QVector3D::normal
+ (QVector3D(x2 - x4, y2 - y4, 0.0f), QVector3D(x1 - x4, y1 - y4, 0.0f));
- CrossProduct(nx, ny, nz, x2 - x4, y2 - y4, 0, x1 - x4, y1 - y4, 0);
- Normalize(nx, ny, nz);
+ normals << n;
+ normals << n;
+ normals << n;
- normals << nx << ny << nz;
- normals << nx << ny << nz;
- normals << nx << ny << nz;
-
- normals << nx << ny << nz;
- normals << nx << ny << nz;
- normals << nx << ny << nz;
+ normals << n;
+ normals << n;
+ normals << n;
}
void GLWidget::extrude(qreal x1, qreal y1, qreal x2, qreal y2)
{
- qreal nx, ny, nz;
-
- vertices << x1 << y1 << +0.05f;
- vertices << x2 << y2 << +0.05f;
- vertices << x1 << y1 << -0.05f;
+ vertices << QVector3D(x1, y1, +0.05f);
+ vertices << QVector3D(x2, y2, +0.05f);
+ vertices << QVector3D(x1, y1, -0.05f);
- vertices << x2 << y2 << -0.05f;
- vertices << x1 << y1 << -0.05f;
- vertices << x2 << y2 << +0.05f;
+ vertices << QVector3D(x2, y2, -0.05f);
+ vertices << QVector3D(x1, y1, -0.05f);
+ vertices << QVector3D(x2, y2, +0.05f);
- CrossProduct(nx, ny, nz, x2 - x1, y2 - y1, 0.0f, 0.0f, 0.0f, -0.1f);
- Normalize(nx, ny, nz);
+ QVector3D n = QVector3D::normal
+ (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(0.0f, 0.0f, -0.1f));
- normals << nx << ny << nz;
- normals << nx << ny << nz;
- normals << nx << ny << nz;
+ normals << n;
+ normals << n;
+ normals << n;
- normals << nx << ny << nz;
- normals << nx << ny << nz;
- normals << nx << ny << nz;
+ normals << n;
+ normals << n;
+ normals << n;
}
diff --git a/examples/opengl/hellogl_es2/glwidget.h b/examples/opengl/hellogl_es2/glwidget.h
index 9a7823a..596e1cc 100644
--- a/examples/opengl/hellogl_es2/glwidget.h
+++ b/examples/opengl/hellogl_es2/glwidget.h
@@ -43,7 +43,11 @@
#define GLWIDGET_H
#include <QGLWidget>
+#include <QtGui/qvector3d.h>
+#include <QtGui/qmatrix4x4.h>
+#include <QtOpenGL/qglshaderprogram.h>
#include <QTime>
+#include <QVector>
class Bubble;
class GLWidget : public QGLWidget {
@@ -71,24 +75,21 @@ private:
void createBubbles(int number);
void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
- QList<qreal> vertices;
- QList<qreal> normals;
- GLfloat *createdVertices;
- GLfloat *createdNormals;
- int m_vertexNumber;
+ QVector<QVector3D> vertices;
+ QVector<QVector3D> normals;
bool qtLogo;
QList<Bubble*> bubbles;
int frames;
QTime time;
- GLuint program1;
- GLuint program2;
- GLuint vertexAttr1;
- GLuint normalAttr1;
- GLuint matrixUniform1;
- GLuint vertexAttr2;
- GLuint normalAttr2;
- GLuint texCoordAttr2;
- GLuint matrixUniform2;
- GLuint textureUniform2;
+ QGLShaderProgram program1;
+ QGLShaderProgram program2;
+ int vertexAttr1;
+ int normalAttr1;
+ int matrixUniform1;
+ int vertexAttr2;
+ int normalAttr2;
+ int texCoordAttr2;
+ int matrixUniform2;
+ int textureUniform2;
};
#endif
diff --git a/examples/statemachine/README b/examples/statemachine/README
new file mode 100644
index 0000000..2879e67
--- /dev/null
+++ b/examples/statemachine/README
@@ -0,0 +1,36 @@
+Qt is provided with a powerful hierchical finite state machine through
+the Qt State Machine classes.
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/statemachine/eventtransitions/eventtransitions.pro b/examples/statemachine/eventtransitions/eventtransitions.pro
new file mode 100644
index 0000000..7e92cf2
--- /dev/null
+++ b/examples/statemachine/eventtransitions/eventtransitions.pro
@@ -0,0 +1,7 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/eventtransitions
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS eventtransitions.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/eventtransitions
+INSTALLS += target sources
diff --git a/examples/statemachine/eventtransitions/main.cpp b/examples/statemachine/eventtransitions/main.cpp
new file mode 100644
index 0000000..aba0c73
--- /dev/null
+++ b/examples/statemachine/eventtransitions/main.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#ifdef QT_STATEMACHINE_SOLUTION
+#include <qstatemachine.h>
+#include <qstate.h>
+#include <qeventtransition.h>
+#endif
+
+//! [0]
+class Window : public QWidget
+{
+public:
+ Window(QWidget *parent = 0)
+ : QWidget(parent)
+ {
+ QPushButton *button = new QPushButton(this);
+ button->setGeometry(QRect(100, 100, 100, 100));
+//! [0]
+
+//! [1]
+ QStateMachine *machine = new QStateMachine(this);
+
+ QState *s1 = new QState();
+ s1->assignProperty(button, "text", "Outside");
+
+ QState *s2 = new QState();
+ s2->assignProperty(button, "text", "Inside");
+//! [1]
+
+//! [2]
+ QEventTransition *enterTransition = new QEventTransition(button, QEvent::Enter);
+ enterTransition->setTargetState(s2);
+ s1->addTransition(enterTransition);
+//! [2]
+
+//! [3]
+ QEventTransition *leaveTransition = new QEventTransition(button, QEvent::Leave);
+ leaveTransition->setTargetState(s1);
+ s2->addTransition(leaveTransition);
+//! [3]
+
+//! [4]
+ QState *s3 = new QState();
+ s3->assignProperty(button, "text", "Pressing...");
+
+ QEventTransition *pressTransition = new QEventTransition(button, QEvent::MouseButtonPress);
+ pressTransition->setTargetState(s3);
+ s2->addTransition(pressTransition);
+
+ QEventTransition *releaseTransition = new QEventTransition(button, QEvent::MouseButtonRelease);
+ releaseTransition->setTargetState(s2);
+ s3->addTransition(releaseTransition);
+//! [4]
+
+//! [5]
+ machine->addState(s1);
+ machine->addState(s2);
+ machine->addState(s3);
+
+ machine->setInitialState(s1);
+ machine->start();
+ }
+};
+//! [5]
+
+//! [6]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.resize(300, 300);
+ window.show();
+
+ return app.exec();
+}
+//! [6]
diff --git a/examples/statemachine/factorial/factorial.pro b/examples/statemachine/factorial/factorial.pro
new file mode 100644
index 0000000..14a6833
--- /dev/null
+++ b/examples/statemachine/factorial/factorial.pro
@@ -0,0 +1,11 @@
+QT = core
+win32: CONFIG += console
+mac:CONFIG -= app_bundle
+
+SOURCES += main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/factorial
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS factorial.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/factorial
+INSTALLS += target sources
diff --git a/examples/statemachine/factorial/main.cpp b/examples/statemachine/factorial/main.cpp
new file mode 100644
index 0000000..1065eb8
--- /dev/null
+++ b/examples/statemachine/factorial/main.cpp
@@ -0,0 +1,182 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <stdio.h>
+#ifdef QT_STATEMACHINE_SOLUTION
+#include <qstatemachine.h>
+#include <qstate.h>
+#include <qsignaltransition.h>
+#include <qfinalstate.h>
+#endif
+
+//! [0]
+class Factorial : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int x READ x WRITE setX)
+ Q_PROPERTY(int fac READ fac WRITE setFac)
+public:
+ Factorial(QObject *parent = 0)
+ : QObject(parent), m_x(-1), m_fac(1)
+ {
+ }
+
+ int x() const
+ {
+ return m_x;
+ }
+
+ void setX(int x)
+ {
+ if (x == m_x)
+ return;
+ m_x = x;
+ emit xChanged(x);
+ }
+
+ int fac() const
+ {
+ return m_fac;
+ }
+
+ void setFac(int fac)
+ {
+ m_fac = fac;
+ }
+
+Q_SIGNALS:
+ void xChanged(int value);
+
+private:
+ int m_x;
+ int m_fac;
+};
+//! [0]
+
+//! [1]
+class FactorialLoopTransition : public QSignalTransition
+{
+public:
+ FactorialLoopTransition(Factorial *fact)
+ : QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact)
+ {}
+
+ virtual bool eventTest(QEvent *e)
+ {
+ if (!QSignalTransition::eventTest(e))
+ return false;
+ QSignalEvent *se = static_cast<QSignalEvent*>(e);
+ return se->arguments().at(0).toInt() > 1;
+ }
+
+ virtual void onTransition(QEvent *e)
+ {
+ QSignalEvent *se = static_cast<QSignalEvent*>(e);
+ int x = se->arguments().at(0).toInt();
+ int fac = m_fact->property("fac").toInt();
+ m_fact->setProperty("fac", x * fac);
+ m_fact->setProperty("x", x - 1);
+ }
+
+private:
+ Factorial *m_fact;
+};
+//! [1]
+
+//! [2]
+class FactorialDoneTransition : public QSignalTransition
+{
+public:
+ FactorialDoneTransition(Factorial *fact)
+ : QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact)
+ {}
+
+ virtual bool eventTest(QEvent *e)
+ {
+ if (!QSignalTransition::eventTest(e))
+ return false;
+ QSignalEvent *se = static_cast<QSignalEvent*>(e);
+ return se->arguments().at(0).toInt() <= 1;
+ }
+
+ virtual void onTransition(QEvent *)
+ {
+ fprintf(stdout, "%d\n", m_fact->property("fac").toInt());
+ }
+
+private:
+ Factorial *m_fact;
+};
+//! [2]
+
+//! [3]
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+ Factorial factorial;
+ QStateMachine machine;
+//! [3]
+
+//! [4]
+ QState *compute = new QState(machine.rootState());
+ compute->assignProperty(&factorial, "fac", 1);
+ compute->assignProperty(&factorial, "x", 6);
+ compute->addTransition(new FactorialLoopTransition(&factorial));
+//! [4]
+
+//! [5]
+ QFinalState *done = new QFinalState(machine.rootState());
+ FactorialDoneTransition *doneTransition = new FactorialDoneTransition(&factorial);
+ doneTransition->setTargetState(done);
+ compute->addTransition(doneTransition);
+//! [5]
+
+//! [6]
+ machine.setInitialState(compute);
+ QObject::connect(&machine, SIGNAL(finished()), &app, SLOT(quit()));
+ machine.start();
+
+ return app.exec();
+}
+//! [6]
+
+#include "main.moc"
diff --git a/examples/statemachine/pingpong/main.cpp b/examples/statemachine/pingpong/main.cpp
new file mode 100644
index 0000000..331627e
--- /dev/null
+++ b/examples/statemachine/pingpong/main.cpp
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <stdio.h>
+#ifdef QT_STATEMACHINE_SOLUTION
+#include <qstate.h>
+#include <qstatemachine.h>
+#include <qabstracttransition.h>
+#endif
+
+//! [0]
+class PingEvent : public QEvent
+{
+public:
+ PingEvent() : QEvent(QEvent::Type(QEvent::User+2))
+ {}
+};
+
+class PongEvent : public QEvent
+{
+public:
+ PongEvent() : QEvent(QEvent::Type(QEvent::User+3))
+ {}
+};
+//! [0]
+
+//! [1]
+class Pinger : public QState
+{
+public:
+ Pinger(QState *parent)
+ : QState(parent) {}
+
+protected:
+ virtual void onEntry(QEvent *)
+ {
+ machine()->postEvent(new PingEvent());
+ fprintf(stdout, "ping?\n");
+ }
+};
+//! [1]
+
+//! [3]
+class PongTransition : public QAbstractTransition
+{
+public:
+ PongTransition() {}
+
+protected:
+ virtual bool eventTest(QEvent *e) {
+ return (e->type() == QEvent::User+3);
+ }
+ virtual void onTransition(QEvent *)
+ {
+ machine()->postEvent(new PingEvent(), 500);
+ fprintf(stdout, "ping?\n");
+ }
+};
+//! [3]
+
+//! [2]
+class PingTransition : public QAbstractTransition
+{
+public:
+ PingTransition() {}
+
+protected:
+ virtual bool eventTest(QEvent *e) {
+ return (e->type() == QEvent::User+2);
+ }
+ virtual void onTransition(QEvent *)
+ {
+ machine()->postEvent(new PongEvent(), 500);
+ fprintf(stdout, "pong!\n");
+ }
+};
+//! [2]
+
+//! [4]
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QStateMachine machine;
+ QState *group = new QState(QState::ParallelStates);
+ group->setObjectName("group");
+//! [4]
+
+//! [5]
+ Pinger *pinger = new Pinger(group);
+ pinger->setObjectName("pinger");
+ pinger->addTransition(new PongTransition());
+
+ QState *ponger = new QState(group);
+ ponger->setObjectName("ponger");
+ ponger->addTransition(new PingTransition());
+//! [5]
+
+//! [6]
+ machine.addState(group);
+ machine.setInitialState(group);
+ machine.start();
+
+ return app.exec();
+}
+//! [6]
diff --git a/examples/statemachine/pingpong/pingpong.pro b/examples/statemachine/pingpong/pingpong.pro
new file mode 100644
index 0000000..42eab6c
--- /dev/null
+++ b/examples/statemachine/pingpong/pingpong.pro
@@ -0,0 +1,11 @@
+QT = core
+win32: CONFIG += console
+mac:CONFIG -= app_bundle
+
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/pingpong
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS pingpong.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/pingpong
+INSTALLS += target sources
diff --git a/examples/statemachine/statemachine.pro b/examples/statemachine/statemachine.pro
new file mode 100644
index 0000000..5074a3c
--- /dev/null
+++ b/examples/statemachine/statemachine.pro
@@ -0,0 +1,15 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ eventtransitions \
+ factorial \
+ pingpong \
+ trafficlight \
+ twowaybutton \
+ tankgame \
+ tankgameplugins
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS statemachine.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine
+INSTALLS += target sources
diff --git a/examples/statemachine/tankgame/gameitem.cpp b/examples/statemachine/tankgame/gameitem.cpp
new file mode 100644
index 0000000..ad8b37c
--- /dev/null
+++ b/examples/statemachine/tankgame/gameitem.cpp
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "gameitem.h"
+
+#include <QGraphicsScene>
+#include <QDebug>
+
+GameItem::GameItem(QObject *parent) : QObject(parent)
+{
+}
+
+QPointF GameItem::tryMove(const QPointF &requestedPosition, QLineF *collidedLine,
+ QGraphicsItem **collidedItem) const
+{
+ QLineF movementPath(pos(), requestedPosition);
+
+ qreal cannonLength = 0.0;
+ {
+ QPointF p1 = boundingRect().center();
+ QPointF p2 = QPointF(boundingRect().right() + 10.0, p1.y());
+
+ cannonLength = QLineF(mapToScene(p1), mapToScene(p2)).length();
+ }
+
+ movementPath.setLength(movementPath.length() + cannonLength);
+
+ QRectF boundingRectPath(QPointF(qMin(movementPath.x1(), movementPath.x2()), qMin(movementPath.y1(), movementPath.y2())),
+ QPointF(qMax(movementPath.x1(), movementPath.x2()), qMax(movementPath.y1(), movementPath.y2())));
+
+ QList<QGraphicsItem *> itemsInRect = scene()->items(boundingRectPath, Qt::IntersectsItemBoundingRect);
+
+ QPointF nextPoint = requestedPosition;
+ QRectF sceneRect = scene()->sceneRect();
+
+ foreach (QGraphicsItem *item, itemsInRect) {
+ if (item == static_cast<const QGraphicsItem *>(this))
+ continue;
+
+ QPolygonF mappedBoundingRect = item->mapToScene(item->boundingRect());
+ for (int i=0; i<mappedBoundingRect.size(); ++i) {
+ QPointF p1 = mappedBoundingRect.at(i == 0 ? mappedBoundingRect.size()-1 : i-1);
+ QPointF p2 = mappedBoundingRect.at(i);
+
+ QLineF rectLine(p1, p2);
+ QPointF intersectionPoint;
+ QLineF::IntersectType intersectType = movementPath.intersect(rectLine, &intersectionPoint);
+
+ if (intersectType == QLineF::BoundedIntersection) {
+ movementPath.setP2(intersectionPoint);
+ movementPath.setLength(movementPath.length() - cannonLength);
+ nextPoint = movementPath.p2();
+
+ if (collidedLine != 0)
+ *collidedLine = rectLine;
+
+ if (collidedItem != 0)
+ *collidedItem = item;
+ }
+ }
+ }
+
+
+ // Don't go outside of map
+ if (nextPoint.x() < sceneRect.left()) {
+ nextPoint.rx() = sceneRect.left();
+ if (collidedLine != 0)
+ *collidedLine = QLineF(scene()->sceneRect().topLeft(), scene()->sceneRect().bottomLeft());
+ }
+
+ if (nextPoint.x() > sceneRect.right()) {
+ nextPoint.rx() = sceneRect.right();
+ if (collidedLine != 0)
+ *collidedLine = QLineF(scene()->sceneRect().topRight(), scene()->sceneRect().bottomRight());
+ }
+
+ if (nextPoint.y() < sceneRect.top()) {
+ nextPoint.ry() = sceneRect.top();
+ if (collidedLine != 0)
+ *collidedLine = QLineF(scene()->sceneRect().topLeft(), scene()->sceneRect().topRight());
+ }
+
+ if (nextPoint.y() > sceneRect.bottom()) {
+ nextPoint.ry() = sceneRect.bottom();
+ if (collidedLine != 0)
+ *collidedLine = QLineF(scene()->sceneRect().bottomLeft(), scene()->sceneRect().bottomRight());
+ }
+
+ return nextPoint;
+}
+
diff --git a/examples/statemachine/tankgame/gameitem.h b/examples/statemachine/tankgame/gameitem.h
new file mode 100644
index 0000000..90b0a6c
--- /dev/null
+++ b/examples/statemachine/tankgame/gameitem.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GAMEITEM_H
+#define GAMEITEM_H
+
+#include <QGraphicsItem>
+
+QT_BEGIN_NAMESPACE
+class QLineF;
+QT_END_NAMESPACE
+class GameItem: public QObject, public QGraphicsItem
+{
+ Q_OBJECT
+public:
+ enum { Type = UserType + 1 };
+ int type() const { return Type; }
+
+ GameItem(QObject *parent = 0);
+
+ virtual void idle(qreal elapsed) = 0;
+
+protected:
+ QPointF tryMove(const QPointF &requestedPosition, QLineF *collidedLine = 0,
+ QGraphicsItem **collidedItem = 0) const;
+};
+
+#endif
diff --git a/examples/statemachine/tankgame/gameovertransition.cpp b/examples/statemachine/tankgame/gameovertransition.cpp
new file mode 100644
index 0000000..360e902
--- /dev/null
+++ b/examples/statemachine/tankgame/gameovertransition.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "gameovertransition.h"
+#include "tankitem.h"
+
+#include <QSignalEvent>
+#include <QSignalMapper>
+
+GameOverTransition::GameOverTransition(QAbstractState *targetState)
+ : QSignalTransition(new QSignalMapper(), SIGNAL(mapped(QObject*)))
+{
+ setTargetState(targetState);
+
+ QSignalMapper *mapper = qobject_cast<QSignalMapper *>(senderObject());
+ mapper->setParent(this);
+}
+
+void GameOverTransition::addTankItem(TankItem *tankItem)
+{
+ m_tankItems.append(tankItem);
+
+ QSignalMapper *mapper = qobject_cast<QSignalMapper *>(senderObject());
+ mapper->setMapping(tankItem, tankItem);
+ connect(tankItem, SIGNAL(aboutToBeDestroyed()), mapper, SLOT(map()));
+}
+
+bool GameOverTransition::eventTest(QEvent *e)
+{
+ bool ret = QSignalTransition::eventTest(e);
+
+ if (ret) {
+ QSignalEvent *signalEvent = static_cast<QSignalEvent *>(e);
+ QObject *sender = qvariant_cast<QObject *>(signalEvent->arguments().at(0));
+ TankItem *tankItem = qobject_cast<TankItem *>(sender);
+ m_tankItems.removeAll(tankItem);
+
+ return m_tankItems.size() <= 1;
+ } else {
+ return false;
+ }
+}
diff --git a/examples/statemachine/tankgame/gameovertransition.h b/examples/statemachine/tankgame/gameovertransition.h
new file mode 100644
index 0000000..5e99a75
--- /dev/null
+++ b/examples/statemachine/tankgame/gameovertransition.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GAMEOVERTRANSITION_H
+#define GAMEOVERTRANSITION_H
+
+#include <QSignalTransition>
+
+class TankItem;
+class GameOverTransition: public QSignalTransition
+{
+ Q_OBJECT
+public:
+ GameOverTransition(QAbstractState *targetState);
+
+ void addTankItem(TankItem *tankItem);
+
+protected:
+ bool eventTest(QEvent *event);
+
+private:
+ QList<TankItem *> m_tankItems;
+};
+
+#endif
diff --git a/examples/statemachine/tankgame/main.cpp b/examples/statemachine/tankgame/main.cpp
new file mode 100644
index 0000000..185ad68
--- /dev/null
+++ b/examples/statemachine/tankgame/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ MainWindow mainWindow;
+ mainWindow.show();
+
+ return app.exec();
+}
diff --git a/examples/statemachine/tankgame/mainwindow.cpp b/examples/statemachine/tankgame/mainwindow.cpp
new file mode 100644
index 0000000..46e0db3
--- /dev/null
+++ b/examples/statemachine/tankgame/mainwindow.cpp
@@ -0,0 +1,342 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "tankitem.h"
+#include "rocketitem.h"
+#include "plugin.h"
+#include "gameovertransition.h"
+
+#include <QStateMachine>
+#include <QGraphicsView>
+#include <QAction>
+#include <QMenuBar>
+#include <QState>
+#include <QHistoryState>
+#include <QTimer>
+#include <QFileDialog>
+#include <QPluginLoader>
+#include <QApplication>
+#include <QInputDialog>
+#include <QMessageBox>
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), m_scene(0), m_machine(0), m_runningState(0), m_started(false)
+{
+ init();
+}
+
+MainWindow::~MainWindow()
+{
+}
+
+void MainWindow::addWall(const QRectF &wall)
+{
+ QGraphicsRectItem *item = new QGraphicsRectItem;
+ item->setRect(wall);
+ item->setBrush(Qt::darkGreen);
+ item->setPen(QPen(Qt::black, 0));
+
+ m_scene->addItem(item);
+}
+
+void MainWindow::init()
+{
+ setWindowTitle("Pluggable Tank Game");
+
+ QGraphicsView *view = new QGraphicsView(this);
+ view->setRenderHints(QPainter::Antialiasing);
+ setCentralWidget(view);
+
+ m_scene = new QGraphicsScene(this);
+ view->setScene(m_scene);
+
+ QRectF sceneRect = QRectF(-200.0, -200.0, 400.0, 400.0);
+ m_scene->setSceneRect(sceneRect);
+
+ {
+ TankItem *item = new TankItem(this);
+
+ item->setPos(m_scene->sceneRect().topLeft() + QPointF(30.0, 30.0));
+ item->setDirection(45.0);
+ item->setColor(Qt::red);
+
+ m_spawns.append(item);
+ }
+
+ {
+ TankItem *item = new TankItem(this);
+
+ item->setPos(m_scene->sceneRect().topRight() + QPointF(-30.0, 30.0));
+ item->setDirection(135.0);
+ item->setColor(Qt::green);
+
+ m_spawns.append(item);
+ }
+
+ {
+ TankItem *item = new TankItem(this);
+
+ item->setPos(m_scene->sceneRect().bottomRight() + QPointF(-30.0, -30.0));
+ item->setDirection(225.0);
+ item->setColor(Qt::blue);
+
+ m_spawns.append(item);
+ }
+
+ {
+ TankItem *item = new TankItem(this);
+
+ item->setPos(m_scene->sceneRect().bottomLeft() + QPointF(30.0, -30.0));
+ item->setDirection(315.0);
+ item->setColor(Qt::yellow);
+
+ m_spawns.append(item);
+ }
+
+ QPointF centerOfMap = sceneRect.center();
+
+ addWall(QRectF(centerOfMap + QPointF(-50.0, -60.0), centerOfMap + QPointF(50.0, -50.0)));
+ addWall(QRectF(centerOfMap - QPointF(-50.0, -60.0), centerOfMap - QPointF(50.0, -50.0)));
+ addWall(QRectF(centerOfMap + QPointF(-50.0, -50.0), centerOfMap + QPointF(-40.0, 50.0)));
+ addWall(QRectF(centerOfMap - QPointF(-50.0, -50.0), centerOfMap - QPointF(-40.0, 50.0)));
+
+ addWall(QRectF(sceneRect.topLeft() + QPointF(sceneRect.width() / 2.0 - 5.0, -10.0),
+ sceneRect.topLeft() + QPointF(sceneRect.width() / 2.0 + 5.0, 100.0)));
+ addWall(QRectF(sceneRect.bottomLeft() + QPointF(sceneRect.width() / 2.0 - 5.0, 10.0),
+ sceneRect.bottomLeft() + QPointF(sceneRect.width() / 2.0 + 5.0, -100.0)));
+ addWall(QRectF(sceneRect.topLeft() + QPointF(-10.0, sceneRect.height() / 2.0 - 5.0),
+ sceneRect.topLeft() + QPointF(100.0, sceneRect.height() / 2.0 + 5.0)));
+ addWall(QRectF(sceneRect.topRight() + QPointF(10.0, sceneRect.height() / 2.0 - 5.0),
+ sceneRect.topRight() + QPointF(-100.0, sceneRect.height() / 2.0 + 5.0)));
+
+
+ QAction *addTankAction = menuBar()->addAction("&Add tank");
+ QAction *runGameAction = menuBar()->addAction("&Run game");
+ runGameAction->setObjectName("runGameAction");
+ QAction *stopGameAction = menuBar()->addAction("&Stop game");
+ menuBar()->addSeparator();
+ QAction *quitAction = menuBar()->addAction("&Quit");
+
+ connect(addTankAction, SIGNAL(triggered()), this, SLOT(addTank()));
+ connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
+
+ m_machine = new QStateMachine(this);
+ QState *stoppedState = new QState(m_machine->rootState());
+ stoppedState->setObjectName("stoppedState");
+ stoppedState->assignProperty(runGameAction, "enabled", true);
+ stoppedState->assignProperty(stopGameAction, "enabled", false);
+ stoppedState->assignProperty(this, "started", false);
+ m_machine->setInitialState(stoppedState);
+
+//! [5]
+ QState *spawnsAvailable = new QState(stoppedState);
+ spawnsAvailable->assignProperty(addTankAction, "enabled", true);
+
+ QState *noSpawnsAvailable = new QState(stoppedState);
+ noSpawnsAvailable->assignProperty(addTankAction, "enabled", false);
+//! [5]
+ spawnsAvailable->setObjectName("spawnsAvailable");
+ noSpawnsAvailable->setObjectName("noSpawnsAvailable");
+
+ spawnsAvailable->addTransition(this, SIGNAL(mapFull()), noSpawnsAvailable);
+
+//! [3]
+ QHistoryState *hs = new QHistoryState(stoppedState);
+ hs->setDefaultState(spawnsAvailable);
+//! [3]
+ hs->setObjectName("hs");
+
+ stoppedState->setInitialState(hs);
+
+//! [0]
+ m_runningState = new QState(QState::ParallelStates, m_machine->rootState());
+//! [0]
+ m_runningState->setObjectName("runningState");
+ m_runningState->assignProperty(addTankAction, "enabled", false);
+ m_runningState->assignProperty(runGameAction, "enabled", false);
+ m_runningState->assignProperty(stopGameAction, "enabled", true);
+
+ QState *gameOverState = new QState(m_machine->rootState());
+ gameOverState->setObjectName("gameOverState");
+ gameOverState->assignProperty(stopGameAction, "enabled", false);
+ connect(gameOverState, SIGNAL(entered()), this, SLOT(gameOver()));
+
+ stoppedState->addTransition(runGameAction, SIGNAL(triggered()), m_runningState);
+ m_runningState->addTransition(stopGameAction, SIGNAL(triggered()), stoppedState);
+
+ m_gameOverTransition = new GameOverTransition(gameOverState);
+ m_runningState->addTransition(m_gameOverTransition);
+
+ QTimer *timer = new QTimer(this);
+ timer->setInterval(100);
+ connect(timer, SIGNAL(timeout()), this, SLOT(runStep()));
+ connect(m_runningState, SIGNAL(entered()), timer, SLOT(start()));
+ connect(m_runningState, SIGNAL(exited()), timer, SLOT(stop()));
+
+ m_machine->start();
+ m_time.start();
+}
+
+void MainWindow::runStep()
+{
+ if (!m_started) {
+ m_time.restart();
+ m_started = true;
+ } else {
+ int elapsed = m_time.elapsed();
+ if (elapsed > 0) {
+ m_time.restart();
+ qreal elapsedSecs = elapsed / 1000.0;
+ QList<QGraphicsItem *> items = m_scene->items();
+ foreach (QGraphicsItem *item, items) {
+ if (GameItem *gameItem = qgraphicsitem_cast<GameItem *>(item))
+ gameItem->idle(elapsedSecs);
+ }
+ }
+ }
+}
+
+void MainWindow::gameOver()
+{
+ QList<QGraphicsItem *> items = m_scene->items();
+
+ TankItem *lastTankStanding = 0;
+ foreach (QGraphicsItem *item, items) {
+ if (GameItem *gameItem = qgraphicsitem_cast<GameItem *>(item)) {
+ if ((lastTankStanding = qobject_cast<TankItem *>(gameItem)) != 0)
+ break;
+ }
+ }
+
+ QMessageBox::information(this, "Game over!",
+ QString::fromLatin1("The tank played by '%1' has won!").arg(lastTankStanding->objectName()));
+}
+
+void MainWindow::addRocket()
+{
+ TankItem *tankItem = qobject_cast<TankItem *>(sender());
+ if (tankItem != 0) {
+ RocketItem *rocketItem = new RocketItem;
+
+ QPointF s = tankItem->mapToScene(QPointF(tankItem->boundingRect().right() + 10.0,
+ tankItem->boundingRect().center().y()));
+ rocketItem->setPos(s);
+ rocketItem->setDirection(tankItem->direction());
+ m_scene->addItem(rocketItem);
+ }
+}
+
+void MainWindow::addTank()
+{
+ Q_ASSERT(!m_spawns.isEmpty());
+
+ QDir pluginsDir(qApp->applicationDirPath());
+#if defined(Q_OS_WIN)
+ if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
+ pluginsDir.cdUp();
+#elif defined(Q_OS_MAC)
+ if (pluginsDir.dirName() == "MacOS") {
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ }
+#endif
+
+ pluginsDir.cd("plugins");
+
+ QStringList itemNames;
+ QList<Plugin *> items;
+ foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
+ QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
+ QObject *possiblePlugin = loader.instance();
+ if (Plugin *plugin = qobject_cast<Plugin *>(possiblePlugin)) {
+ QString objectName = possiblePlugin->objectName();
+ if (objectName.isEmpty())
+ objectName = fileName;
+
+ itemNames.append(objectName);
+ items.append(plugin);
+ }
+ }
+
+ if (items.isEmpty()) {
+ QMessageBox::information(this, "No tank types found", "Please build the errorstateplugins directory");
+ return;
+ }
+
+ bool ok;
+//! [1]
+ QString selectedName = QInputDialog::getItem(this, "Select a tank type", "Tank types",
+ itemNames, 0, false, &ok);
+//! [1]
+
+ if (ok && !selectedName.isEmpty()) {
+ int idx = itemNames.indexOf(selectedName);
+ if (Plugin *plugin = idx >= 0 ? items.at(idx) : 0) {
+ TankItem *tankItem = m_spawns.takeLast();
+ tankItem->setObjectName(selectedName);
+ tankItem->setToolTip(selectedName);
+ m_scene->addItem(tankItem);
+ connect(tankItem, SIGNAL(cannonFired()), this, SLOT(addRocket()));
+ if (m_spawns.isEmpty())
+ emit mapFull();
+
+ m_gameOverTransition->addTankItem(tankItem);
+
+ QState *region = new QState(m_runningState);
+ region->setObjectName(QString::fromLatin1("region%1").arg(m_spawns.size()));
+//! [2]
+ QState *pluginState = plugin->create(region, tankItem);
+//! [2]
+ region->setInitialState(pluginState);
+
+ // If the plugin has an error it is disabled
+//! [4]
+ QState *errorState = new QState(region);
+ errorState->setObjectName(QString::fromLatin1("errorState%1").arg(m_spawns.size()));
+ errorState->assignProperty(tankItem, "enabled", false);
+ pluginState->setErrorState(errorState);
+//! [4]
+ }
+ }
+}
+
diff --git a/examples/statemachine/tankgame/mainwindow.h b/examples/statemachine/tankgame/mainwindow.h
new file mode 100644
index 0000000..4ae8f7a
--- /dev/null
+++ b/examples/statemachine/tankgame/mainwindow.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QTime>
+
+QT_BEGIN_NAMESPACE
+class QGraphicsScene;
+class QStateMachine;
+class QState;
+QT_END_NAMESPACE
+class GameOverTransition;
+class TankItem;
+
+class MainWindow: public QMainWindow
+{
+ Q_OBJECT
+ Q_PROPERTY(bool started READ started WRITE setStarted)
+public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+ void setStarted(bool b) { m_started = b; }
+ bool started() const { return m_started; }
+
+public slots:
+ void addTank();
+ void addRocket();
+ void runStep();
+ void gameOver();
+
+signals:
+ void mapFull();
+
+private:
+ void init();
+ void addWall(const QRectF &wall);
+
+ QGraphicsScene *m_scene;
+
+ QStateMachine *m_machine;
+ QState *m_runningState;
+ GameOverTransition *m_gameOverTransition;
+
+ QList<TankItem *> m_spawns;
+ QTime m_time;
+
+ bool m_started : 1;
+};
+
+#endif
+
diff --git a/examples/statemachine/tankgame/plugin.h b/examples/statemachine/tankgame/plugin.h
new file mode 100644
index 0000000..ddd10b7
--- /dev/null
+++ b/examples/statemachine/tankgame/plugin.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PLUGIN_H
+#define PLUGIN_H
+
+#include <QtPlugin>
+
+QT_BEGIN_NAMESPACE
+class QState;
+QT_END_NAMESPACE
+class Plugin
+{
+public:
+ virtual ~Plugin() {}
+
+ virtual QState *create(QState *parentState, QObject *tank) = 0;
+};
+
+QT_BEGIN_NAMESPACE
+Q_DECLARE_INTERFACE(Plugin, "TankPlugin")
+QT_END_NAMESPACE
+
+#endif
diff --git a/examples/statemachine/tankgame/rocketitem.cpp b/examples/statemachine/tankgame/rocketitem.cpp
new file mode 100644
index 0000000..3ace8e8
--- /dev/null
+++ b/examples/statemachine/tankgame/rocketitem.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "rocketitem.h"
+#include "tankitem.h"
+
+#include <QPainter>
+#include <QGraphicsScene>
+
+#include <math.h>
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+RocketItem::RocketItem(QObject *parent)
+ : GameItem(parent), m_direction(0.0), m_distance(300.0)
+{
+}
+
+QRectF RocketItem::boundingRect() const
+{
+ return QRectF(-1.0, -1.0, 2.0, 2.0);
+}
+
+void RocketItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ painter->setBrush(Qt::black);
+ painter->drawEllipse(boundingRect());
+}
+
+void RocketItem::idle(qreal elapsed)
+{
+ qreal dist = elapsed * speed();
+
+ m_distance -= dist;
+ if (m_distance < 0.0) {
+ scene()->removeItem(this);
+ delete this;
+ return;
+ }
+
+ qreal a = m_direction * M_PI / 180.0;
+
+ qreal yd = dist * sin(a);
+ qreal xd = dist * sin(M_PI / 2.0 - a);
+
+ QPointF requestedPosition = pos() + QPointF(xd, yd);
+ QGraphicsItem *collidedItem = 0;
+ QPointF nextPosition = tryMove(requestedPosition, 0, &collidedItem);
+ if (requestedPosition == nextPosition) {
+ setPos(nextPosition);
+ } else {
+ if (GameItem *gameItem = qgraphicsitem_cast<GameItem *>(collidedItem)) {
+ TankItem *tankItem = qobject_cast<TankItem *>(gameItem);
+ if (tankItem != 0)
+ tankItem->hitByRocket();
+ }
+
+ scene()->removeItem(this);
+ delete this;
+ }
+}
diff --git a/examples/statemachine/tankgame/rocketitem.h b/examples/statemachine/tankgame/rocketitem.h
new file mode 100644
index 0000000..31146a6
--- /dev/null
+++ b/examples/statemachine/tankgame/rocketitem.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ROCKETITEM_H
+#define ROCKETITEM_H
+
+#include "gameitem.h"
+
+class RocketItem: public GameItem
+{
+ Q_OBJECT
+public:
+ RocketItem(QObject *parent = 0);
+
+ virtual void idle(qreal elapsed);
+ qreal speed() const { return 100.0; }
+ void setDirection(qreal direction) { m_direction = direction; }
+
+protected:
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ QRectF boundingRect() const;
+
+private:
+ qreal m_direction;
+ qreal m_distance;
+};
+
+#endif
diff --git a/examples/statemachine/tankgame/tankgame.pro b/examples/statemachine/tankgame/tankgame.pro
new file mode 100644
index 0000000..59415be
--- /dev/null
+++ b/examples/statemachine/tankgame/tankgame.pro
@@ -0,0 +1,19 @@
+HEADERS += mainwindow.h \
+ plugin.h \
+ tankitem.h \
+ rocketitem.h \
+ gameitem.h \
+ gameovertransition.h
+SOURCES += main.cpp \
+ mainwindow.cpp \
+ tankitem.cpp \
+ rocketitem.cpp \
+ gameitem.cpp \
+ gameovertransition.cpp
+CONFIG += console
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tankgame.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame
+INSTALLS += target sources
diff --git a/examples/statemachine/tankgame/tankitem.cpp b/examples/statemachine/tankgame/tankitem.cpp
new file mode 100644
index 0000000..393d65f
--- /dev/null
+++ b/examples/statemachine/tankgame/tankitem.cpp
@@ -0,0 +1,302 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tankitem.h"
+
+#include <QPainter>
+#include <QGraphicsScene>
+#include <QDebug>
+
+#include <math.h>
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+class Action
+{
+public:
+ Action(TankItem *item) : m_item(item)
+ {
+ }
+
+ TankItem *item() const { return m_item; }
+ void setItem(TankItem *item) { m_item = item; }
+
+ virtual bool apply(qreal timeDelta) = 0;
+
+private:
+ TankItem *m_item;
+};
+
+class MoveAction: public Action
+{
+public:
+ MoveAction(TankItem *item, qreal distance)
+ : Action(item), m_distance(distance)
+ {
+ m_reverse = m_distance < 0.0;
+ }
+
+ bool apply(qreal timeDelta)
+ {
+ qreal dist = timeDelta * item()->speed() * (m_reverse ? -1.0 : 1.0);
+
+ bool done = false;
+ if (qAbs(m_distance) < qAbs(dist)) {
+ done = true;
+ dist = m_distance;
+ }
+ m_distance -= dist;
+
+ qreal a = item()->direction() * M_PI / 180.0;
+
+ qreal yd = dist * sin(a);
+ qreal xd = dist * sin(M_PI / 2.0 - a);
+
+ item()->setPos(item()->pos() + QPointF(xd, yd));
+ return !done;
+ }
+
+private:
+ qreal m_distance;
+ bool m_reverse;
+};
+
+class TurnAction: public Action
+{
+public:
+ TurnAction(TankItem *item, qreal distance)
+ : Action(item), m_distance(distance)
+ {
+ m_reverse = m_distance < 0.0;
+ }
+
+ bool apply(qreal timeDelta)
+ {
+ qreal dist = timeDelta * item()->angularSpeed() * (m_reverse ? -1.0 : 1.0);
+ bool done = false;
+ if (qAbs(m_distance) < qAbs(dist)) {
+ done = true;
+ dist = m_distance;
+ }
+ m_distance -= dist;
+
+ item()->setDirection(item()->direction() + dist);
+ return !done;
+ }
+
+private:
+ qreal m_distance;
+ bool m_reverse;
+};
+
+TankItem::TankItem(QObject *parent)
+ : GameItem(parent), m_currentAction(0), m_currentDirection(0.0), m_enabled(true)
+{
+ connect(this, SIGNAL(cannonFired()), this, SIGNAL(actionCompleted()));
+}
+
+void TankItem::idle(qreal elapsed)
+{
+ if (m_enabled) {
+ if (m_currentAction != 0) {
+ if (!m_currentAction->apply(elapsed)) {
+ setAction(0);
+ emit actionCompleted();
+ }
+
+ QGraphicsItem *item = 0;
+ qreal distance = distanceToObstacle(&item);
+ if (TankItem *tankItem = qgraphicsitem_cast<TankItem *>(item))
+ emit tankSpotted(tankItem->direction(), distance);
+ }
+ }
+}
+
+void TankItem::hitByRocket()
+{
+ emit aboutToBeDestroyed();
+ deleteLater();
+}
+
+void TankItem::setAction(Action *newAction)
+{
+ if (m_currentAction != 0)
+ delete m_currentAction;
+
+ m_currentAction = newAction;
+}
+
+void TankItem::fireCannon()
+{
+ emit cannonFired();
+}
+
+void TankItem::moveForwards(qreal length)
+{
+ setAction(new MoveAction(this, length));
+}
+
+void TankItem::moveBackwards(qreal length)
+{
+ setAction(new MoveAction(this, -length));
+}
+
+void TankItem::turn(qreal degrees)
+{
+ setAction(new TurnAction(this, degrees));
+}
+
+void TankItem::turnTo(qreal degrees)
+{
+ setAction(new TurnAction(this, degrees - direction()));
+}
+
+void TankItem::stop()
+{
+ setAction(0);
+}
+
+QVariant TankItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
+{
+ if (change == ItemPositionChange && scene()) {
+ QPointF requestedPosition = value.toPointF();
+ QLineF collidedLine;
+ QPointF nextPoint = tryMove(requestedPosition, &collidedLine);
+ if (nextPoint != requestedPosition)
+ emit collision(collidedLine);
+ return nextPoint;
+ } else {
+ return QGraphicsItem::itemChange(change, value);
+ }
+}
+
+
+void TankItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QRectF brect = boundingRect();
+
+ painter->setBrush(m_color);
+ painter->setPen(Qt::black);
+
+ // body
+ painter->drawRect(brect.adjusted(0.0, 4.0, -2.0, -4.0));
+
+ // cannon
+ QRectF cannonBase = brect.adjusted(10.0, 6.0, -12.0, -6.0);
+ painter->drawEllipse(cannonBase);
+
+ painter->drawRect(QRectF(QPointF(cannonBase.center().x(), cannonBase.center().y() - 2.0),
+ QPointF(brect.right(), cannonBase.center().y() + 2.0)));
+
+ // left track
+ painter->setBrush(QBrush(Qt::black, Qt::VerPattern));
+ QRectF leftTrackRect = QRectF(brect.topLeft(), QPointF(brect.right() - 2.0, brect.top() + 4.0));
+ painter->fillRect(leftTrackRect, Qt::darkYellow);
+ painter->drawRect(leftTrackRect);
+
+ // right track
+ QRectF rightTrackRect = QRectF(QPointF(brect.left(), brect.bottom() - 4.0),
+ QPointF(brect.right() - 2.0, brect.bottom()));
+ painter->fillRect(rightTrackRect, Qt::darkYellow);
+ painter->drawRect(rightTrackRect);
+
+ if (!m_enabled) {
+ painter->setPen(QPen(Qt::red, 5));
+
+ painter->drawEllipse(brect);
+
+ QPainterPath path;
+ path.addEllipse(brect);
+ painter->setClipPath(path);
+ painter->drawLine(brect.topRight(), brect.bottomLeft());
+ }
+}
+
+QRectF TankItem::boundingRect() const
+{
+ return QRectF(-20.0, -10.0, 40.0, 20.0);
+}
+
+qreal TankItem::direction() const
+{
+ return m_currentDirection;
+}
+
+void TankItem::setDirection(qreal newDirection)
+{
+ int fullRotations = int(newDirection) / 360;
+ newDirection -= fullRotations * 360.0;
+
+ qreal diff = newDirection - m_currentDirection;
+ m_currentDirection = newDirection;
+ rotate(diff);
+}
+
+qreal TankItem::distanceToObstacle(QGraphicsItem **obstacle) const
+{
+ qreal dist = sqrt(pow(scene()->sceneRect().width(), 2) + pow(scene()->sceneRect().height(), 2));
+
+ qreal a = m_currentDirection * M_PI / 180.0;
+
+ qreal yd = dist * sin(a);
+ qreal xd = dist * sin(M_PI / 2.0 - a);
+
+ QPointF requestedPosition = pos() + QPointF(xd, yd);
+ QGraphicsItem *collidedItem = 0;
+ QPointF nextPosition = tryMove(requestedPosition, 0, &collidedItem);
+ if (collidedItem != 0) {
+ if (obstacle != 0)
+ *obstacle = collidedItem;
+
+ QPointF d = nextPosition - pos();
+ return sqrt(pow(d.x(), 2) + pow(d.y(), 2));
+ } else {
+ return 0.0;
+ }
+}
+
+qreal TankItem::distanceToObstacle() const
+{
+ return distanceToObstacle(0);
+}
+
diff --git a/examples/statemachine/tankgame/tankitem.h b/examples/statemachine/tankgame/tankitem.h
new file mode 100644
index 0000000..942fca8
--- /dev/null
+++ b/examples/statemachine/tankgame/tankitem.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TANKITEM_H
+#define TANKITEM_H
+
+#include "gameitem.h"
+
+#include <QColor>
+
+class Action;
+class TankItem: public GameItem
+{
+ Q_OBJECT
+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled)
+ Q_PROPERTY(qreal direction READ direction WRITE turnTo)
+ Q_PROPERTY(qreal distanceToObstacle READ distanceToObstacle)
+public:
+ TankItem(QObject *parent = 0);
+
+ void setColor(const QColor &color) { m_color = color; }
+ QColor color() const { return m_color; }
+
+ void idle(qreal elapsed);
+ void setDirection(qreal newDirection);
+
+ qreal speed() const { return 90.0; }
+ qreal angularSpeed() const { return 90.0; }
+
+ QRectF boundingRect() const;
+
+ void hitByRocket();
+
+ void setEnabled(bool b) { m_enabled = b; }
+ bool enabled() const { return m_enabled; }
+
+ qreal direction() const;
+ qreal distanceToObstacle() const;
+ qreal distanceToObstacle(QGraphicsItem **item) const;
+
+//! [0]
+signals:
+ void tankSpotted(qreal direction, qreal distance);
+ void collision(const QLineF &collidedLine);
+ void actionCompleted();
+ void cannonFired();
+ void aboutToBeDestroyed();
+
+public slots:
+ void moveForwards(qreal length = 10.0);
+ void moveBackwards(qreal length = 10.0);
+ void turn(qreal degrees = 30.0);
+ void turnTo(qreal degrees = 0.0);
+ void stop();
+ void fireCannon();
+//! [0]
+
+protected:
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
+
+private:
+ void setAction(Action *newAction);
+
+ Action *m_currentAction;
+ qreal m_currentDirection;
+ QColor m_color;
+ bool m_enabled;
+};
+
+#endif
diff --git a/examples/statemachine/tankgameplugins/random_ai/random_ai.pro b/examples/statemachine/tankgameplugins/random_ai/random_ai.pro
new file mode 100644
index 0000000..5bc0b26
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/random_ai/random_ai.pro
@@ -0,0 +1,13 @@
+TEMPLATE = lib
+CONFIG += plugin
+INCLUDEPATH += ../..
+HEADERS = random_ai_plugin.h
+SOURCES = random_ai_plugin.cpp
+TARGET = $$qtLibraryTarget(random_ai)
+DESTDIR = ../../tankgame/plugins
+
+#! [0]
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS random_ai.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/random_ai \ No newline at end of file
diff --git a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp
new file mode 100644
index 0000000..d360de9
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "random_ai_plugin.h"
+
+#include <QState>
+#include <QtPlugin>
+
+#include <time.h>
+
+QState *RandomAiPlugin::create(QState *parentState, QObject *tank)
+{
+ qsrand(uint(time(NULL)));
+
+ QState *topLevel = new QState(parentState);
+
+ QState *selectNextActionState = new SelectActionState(topLevel);
+ topLevel->setInitialState(selectNextActionState);
+
+ QState *fireState = new RandomDistanceState(topLevel);
+ connect(fireState, SIGNAL(distanceComputed(qreal)), tank, SLOT(fireCannon()));
+ selectNextActionState->addTransition(selectNextActionState, SIGNAL(fireSelected()), fireState);
+
+ QState *moveForwardsState = new RandomDistanceState(topLevel);
+ connect(moveForwardsState, SIGNAL(distanceComputed(qreal)), tank, SLOT(moveForwards(qreal)));
+ selectNextActionState->addTransition(selectNextActionState, SIGNAL(moveForwardsSelected()), moveForwardsState);
+
+ QState *moveBackwardsState = new RandomDistanceState(topLevel);
+ connect(moveBackwardsState, SIGNAL(distanceComputed(qreal)), tank, SLOT(moveBackwards(qreal)));
+ selectNextActionState->addTransition(selectNextActionState, SIGNAL(moveBackwardsSelected()), moveBackwardsState);
+
+ QState *turnState = new RandomDistanceState(topLevel);
+ connect(turnState, SIGNAL(distanceComputed(qreal)), tank, SLOT(turn(qreal)));
+ selectNextActionState->addTransition(selectNextActionState, SIGNAL(turnSelected()), turnState);
+
+ topLevel->addTransition(tank, SIGNAL(actionCompleted()), selectNextActionState);
+
+ return topLevel;
+}
+
+Q_EXPORT_PLUGIN2(random_ai, RandomAiPlugin)
diff --git a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h
new file mode 100644
index 0000000..9faeeac
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RANDOM_AI_PLUGIN_H
+#define RANDOM_AI_PLUGIN_H
+
+#include <QObject>
+#include <QState>
+
+#include <tankgame/plugin.h>
+
+class SelectActionState: public QState
+{
+ Q_OBJECT
+public:
+ SelectActionState(QState *parent = 0) : QState(parent)
+ {
+ }
+
+signals:
+ void fireSelected();
+ void moveForwardsSelected();
+ void moveBackwardsSelected();
+ void turnSelected();
+
+protected:
+ void onEntry(QEvent *)
+ {
+ int rand = qrand() % 4;
+ switch (rand) {
+ case 0: emit fireSelected(); break;
+ case 1: emit moveForwardsSelected(); break;
+ case 2: emit moveBackwardsSelected(); break;
+ case 3: emit turnSelected(); break;
+ };
+ }
+};
+
+class RandomDistanceState: public QState
+{
+ Q_OBJECT
+public:
+ RandomDistanceState(QState *parent = 0) : QState(parent)
+ {
+ }
+
+signals:
+ void distanceComputed(qreal distance);
+
+protected:
+ void onEntry(QEvent *)
+ {
+ emit distanceComputed(qreal(qrand() % 180));
+ }
+};
+
+class RandomAiPlugin: public QObject, public Plugin
+{
+ Q_OBJECT
+ Q_INTERFACES(Plugin)
+public:
+ RandomAiPlugin() { setObjectName("Random"); }
+
+ virtual QState *create(QState *parentState, QObject *tank);
+};
+
+#endif // RANDOM_AI_PLUGIN_H
diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp
new file mode 100644
index 0000000..6aae015
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "seek_ai.h"
+
+QState *SeekAi::create(QState *parentState, QObject *tank)
+{
+ QState *topLevel = new QState(parentState);
+ topLevel->setObjectName("topLevel");
+
+ QState *seek = new QState(topLevel);
+ seek->setObjectName("seek");
+ topLevel->setInitialState(seek);
+
+ QState *lookForNearestWall = new SearchState(tank, seek);
+ lookForNearestWall->setObjectName("lookForNearestWall");
+ seek->setInitialState(lookForNearestWall);
+
+ QState *driveToFirstObstacle = new QState(seek);
+ driveToFirstObstacle->setObjectName("driveToFirstObstacle");
+ lookForNearestWall->addTransition(lookForNearestWall, SIGNAL(nearestObstacleStraightAhead()),
+ driveToFirstObstacle);
+
+ QState *drive = new QState(driveToFirstObstacle);
+ drive->setObjectName("drive");
+ driveToFirstObstacle->setInitialState(drive);
+ connect(drive, SIGNAL(entered()), tank, SLOT(moveForwards()));
+ connect(drive, SIGNAL(exited()), tank, SLOT(stop()));
+
+ // Go in loop
+ QState *finishedDriving = new QState(driveToFirstObstacle);
+ finishedDriving->setObjectName("finishedDriving");
+ drive->addTransition(tank, SIGNAL(actionCompleted()), finishedDriving);
+ finishedDriving->addTransition(drive);
+
+ QState *turnTo = new QState(seek);
+ turnTo->setObjectName("turnTo");
+ driveToFirstObstacle->addTransition(new CollisionTransition(tank, turnTo));
+
+ turnTo->addTransition(tank, SIGNAL(actionCompleted()), driveToFirstObstacle);
+
+ ChaseState *chase = new ChaseState(tank, topLevel);
+ chase->setObjectName("chase");
+ seek->addTransition(new TankSpottedTransition(tank, chase));
+ chase->addTransition(chase, SIGNAL(finished()), driveToFirstObstacle);
+ chase->addTransition(new TankSpottedTransition(tank, chase));
+
+ return topLevel;
+}
+
+Q_EXPORT_PLUGIN2(seek_ai, SeekAi)
diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h
new file mode 100644
index 0000000..e44ad07
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h
@@ -0,0 +1,249 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SEEK_AI_H
+#define SEEK_AI_H
+
+#include <tankgame/plugin.h>
+
+#include <QState>
+#include <QFinalState>
+#include <QSignalTransition>
+#include <QSignalEvent>
+#include <QVariant>
+#include <QLineF>
+#include <QDebug>
+
+class SearchState: public QState
+{
+ Q_OBJECT
+public:
+ SearchState(QObject *tank, QState *parentState = 0)
+ : QState(parentState),
+ m_tank(tank),
+ m_distanceToTurn(360.0),
+ m_nearestDistance(-1.0),
+ m_directionOfNearestObstacle(0.0)
+ {
+ }
+
+public slots:
+ void turnAlittle()
+ {
+ qreal dist = m_tank->property("distanceToObstacle").toDouble();
+
+ if (m_nearestDistance < 0.0 || dist < m_nearestDistance) {
+ m_nearestDistance = dist;
+ m_directionOfNearestObstacle = m_tank->property("direction").toDouble();
+ }
+
+ m_distanceToTurn -= 10.0;
+ if (m_distanceToTurn < 0.0) {
+ disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle()));
+ connect(m_tank, SIGNAL(actionCompleted()), this, SIGNAL(nearestObstacleStraightAhead()));
+ m_tank->setProperty("direction", m_directionOfNearestObstacle);
+ }
+
+ qreal currentDirection = m_tank->property("direction").toDouble();
+ m_tank->setProperty("direction", currentDirection + 10.0);
+ }
+
+signals:
+ void nearestObstacleStraightAhead();
+
+protected:
+ void onEntry(QEvent *)
+ {
+ connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle()));
+ turnAlittle();
+ }
+
+ void onExit(QEvent *)
+ {
+ disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle()));
+ disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(nearestObstacleStraightAhead()));
+ }
+
+private:
+ QObject *m_tank;
+
+ qreal m_distanceToTurn;
+ qreal m_nearestDistance;
+ qreal m_directionOfNearestObstacle;
+};
+
+class CollisionTransition: public QSignalTransition
+{
+public:
+ CollisionTransition(QObject *tank, QState *turnTo)
+ : QSignalTransition(tank, SIGNAL(collision(QLineF))),
+ m_tank(tank),
+ m_turnTo(turnTo)
+ {
+ setTargetState(turnTo);
+ }
+
+protected:
+ bool eventTest(QEvent *event)
+ {
+ bool b = QSignalTransition::eventTest(event);
+ if (b) {
+ QSignalEvent *se = static_cast<QSignalEvent *>(event);
+ m_lastLine = se->arguments().at(0).toLineF();
+ }
+ return b;
+ }
+
+ void onTransition(QEvent *)
+ {
+ qreal angleOfWall = m_lastLine.angle();
+
+ qreal newDirection;
+ if (qrand() % 2 == 0)
+ newDirection = angleOfWall;
+ else
+ newDirection = angleOfWall - 180.0;
+
+ m_turnTo->assignProperty(m_tank, "direction", newDirection);
+ }
+
+private:
+ QLineF m_lastLine;
+ QObject *m_tank;
+ QState *m_turnTo;
+};
+
+class ChaseState: public QState
+{
+ class GoToLocationState: public QState
+ {
+ public:
+ GoToLocationState(QObject *tank, QState *parentState = 0)
+ : QState(parentState), m_tank(tank), m_distance(0.0)
+ {
+ }
+
+ void setDistance(qreal distance) { m_distance = distance; }
+
+ protected:
+ void onEntry()
+ {
+ QMetaObject::invokeMethod(m_tank, "moveForwards", Q_ARG(qreal, m_distance));
+ }
+
+ private:
+ QObject *m_tank;
+ qreal m_distance;
+ };
+
+public:
+ ChaseState(QObject *tank, QState *parentState = 0) : QState(parentState), m_tank(tank)
+ {
+ QState *fireCannon = new QState(this);
+ fireCannon->setObjectName("fireCannon");
+ connect(fireCannon, SIGNAL(entered()), tank, SLOT(fireCannon()));
+ setInitialState(fireCannon);
+
+ m_goToLocation = new GoToLocationState(tank, this);
+ m_goToLocation->setObjectName("goToLocation");
+ fireCannon->addTransition(tank, SIGNAL(actionCompleted()), m_goToLocation);
+
+ m_turnToDirection = new QState(this);
+ m_turnToDirection->setObjectName("turnToDirection");
+ m_goToLocation->addTransition(tank, SIGNAL(actionCompleted()), m_turnToDirection);
+
+ QFinalState *finalState = new QFinalState(this);
+ finalState->setObjectName("finalState");
+ m_turnToDirection->addTransition(tank, SIGNAL(actionCompleted()), finalState);
+ }
+
+ void setDirection(qreal direction)
+ {
+ m_turnToDirection->assignProperty(m_tank, "direction", direction);
+ }
+
+ void setDistance(qreal distance)
+ {
+ m_goToLocation->setDistance(distance);
+ }
+
+private:
+ QObject *m_tank;
+ GoToLocationState *m_goToLocation;
+ QState *m_turnToDirection;
+
+};
+
+class TankSpottedTransition: public QSignalTransition
+{
+public:
+ TankSpottedTransition(QObject *tank, ChaseState *target) : QSignalTransition(tank, SIGNAL(tankSpotted(qreal,qreal))), m_chase(target)
+ {
+ setTargetState(target);
+ }
+
+protected:
+ bool eventTest(QEvent *event)
+ {
+ bool b = QSignalTransition::eventTest(event);
+ if (b) {
+ QSignalEvent *se = static_cast<QSignalEvent *>(event);
+ m_chase->setDirection(se->arguments().at(0).toDouble());
+ m_chase->setDistance(se->arguments().at(1).toDouble());
+ }
+ return b;
+ }
+
+private:
+ ChaseState *m_chase;
+};
+
+class SeekAi: public QObject, public Plugin
+{
+ Q_OBJECT
+ Q_INTERFACES(Plugin)
+public:
+ SeekAi() { setObjectName("Seek and destroy"); }
+
+ virtual QState *create(QState *parentState, QObject *tank);
+};
+
+#endif
diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.pro b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.pro
new file mode 100644
index 0000000..0d8bf2e
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.pro
@@ -0,0 +1,13 @@
+TEMPLATE = lib
+CONFIG += plugin
+INCLUDEPATH += ../..
+HEADERS = seek_ai.h
+SOURCES = seek_ai.cpp
+TARGET = $$qtLibraryTarget(seek_ai)
+DESTDIR = ../../tankgame/plugins
+
+#! [0]
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS seek_ai.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/seek_ai \ No newline at end of file
diff --git a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp
new file mode 100644
index 0000000..581a6b2
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "spin_ai.h"
+
+#include <QtPlugin>
+
+QState *SpinAi::create(QState *parentState, QObject *tank)
+{
+ QState *topLevel = new QState(parentState);
+ QState *spinState = new SpinState(tank, topLevel);
+ topLevel->setInitialState(spinState);
+
+ // When tank is spotted, fire two times and go back to spin state
+ QState *fireState = new QState(topLevel);
+
+ QState *fireOnce = new QState(fireState);
+ fireState->setInitialState(fireOnce);
+ connect(fireOnce, SIGNAL(entered()), tank, SLOT(fireCannon()));
+
+ QState *fireTwice = new QState(fireState);
+ connect(fireTwice, SIGNAL(entered()), tank, SLOT(fireCannon()));
+
+ fireOnce->addTransition(tank, SIGNAL(actionCompleted()), fireTwice);
+ fireTwice->addTransition(tank, SIGNAL(actionCompleted()), spinState);
+
+ spinState->addTransition(tank, SIGNAL(tankSpotted(qreal,qreal)), fireState);
+
+ return topLevel;
+}
+
+Q_EXPORT_PLUGIN2(spin_ai, SpinAi)
diff --git a/demos/boxes/glshaders.h b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h
index 2b6209a..652e8b8 100644
--- a/demos/boxes/glshaders.h
+++ b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h
@@ -3,7 +3,7 @@
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
-** This file is part of the demonstration applications of the Qt Toolkit.
+** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
@@ -39,70 +39,54 @@
**
****************************************************************************/
-#ifndef GLSHADERS_H
-#define GLSHADERS_H
+#ifndef SPIN_AI_H
+#define SPIN_AI_H
-//#include <GL/glew.h>
-#include "glextensions.h"
+#include <tankgame/plugin.h>
-#include <QtGui>
-#include <QtOpenGL>
+#include <QObject>
+#include <QState>
+#include <QVariant>
-#include "vector.h"
-
-class GLShader
+class SpinState: public QState
{
+ Q_OBJECT
public:
- friend class GLProgram;
- virtual ~GLShader();
- bool failed() const {return m_failed;}
- QString log();
+ SpinState(QObject *tank, QState *parent) : QState(parent), m_tank(tank)
+ {
+ }
+
+public slots:
+ void spin()
+ {
+ m_tank->setProperty("direction", m_tank->property("direction").toDouble() + 90.0);
+ }
+
protected:
- GLShader(const char *data, int size, GLenum shaderType);
- GLShader(const QString& fileName, GLenum shaderType);
+ void onEntry(QEvent *)
+ {
+ connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin()));
+ spin();
+ }
- GLhandleARB m_shader;
- bool m_compileError;
- bool m_failed;
-};
+ void onExit(QEvent *)
+ {
+ disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin()));
+ }
-class GLVertexShader : public GLShader
-{
-public:
- GLVertexShader(const char *data, int size);
- GLVertexShader(const QString& fileName);
-};
+private:
+ QObject *m_tank;
-class GLFragmentShader : public GLShader
-{
-public:
- GLFragmentShader(const char *data, int size);
- GLFragmentShader(const QString& fileName);
};
-class GLProgram
+class SpinAi: public QObject, public Plugin
{
+ Q_OBJECT
+ Q_INTERFACES(Plugin)
public:
- GLProgram();
- ~GLProgram();
- void attach(const GLShader &shader);
- void detach(const GLShader &shader);
- void bind();
- void unbind();
- bool failed();
- QString log();
- bool hasParameter(const QString& name);
- // use program before setting values
- void setInt(const QString& name, int value);
- void setFloat(const QString& name, float value);
- void setColor(const QString& name, QRgb value);
- void setMatrix(const QString& name, const gfx::Matrix4x4f &mat);
- // TODO: add a bunch of set-functions for different types.
-private:
- GLhandleARB m_program;
- bool m_linked;
- bool m_linkError;
- bool m_failed;
+ SpinAi() { setObjectName("Spin and destroy"); }
+
+ virtual QState *create(QState *parentState, QObject *tank);
};
#endif
diff --git a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.pro b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.pro
new file mode 100644
index 0000000..8ab4da0
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.pro
@@ -0,0 +1,13 @@
+TEMPLATE = lib
+CONFIG += plugin
+INCLUDEPATH += ../..
+HEADERS = spin_ai.h
+SOURCES = spin_ai.cpp
+TARGET = $$qtLibraryTarget(spin_ai)
+DESTDIR = ../../tankgame/plugins
+
+#! [0]
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS spin_ai.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/spin_ai \ No newline at end of file
diff --git a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp
new file mode 100644
index 0000000..19137b2
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "spin_ai_with_error.h"
+
+#include <QtPlugin>
+
+QState *SpinAiWithError::create(QState *parentState, QObject *tank)
+{
+ QState *topLevel = new QState(parentState);
+ QState *spinState = new SpinState(tank, topLevel);
+ topLevel->setInitialState(spinState);
+
+ // When tank is spotted, fire two times and go back to spin state
+ // (no initial state set for fireState will lead to run-time error in machine)
+ QState *fireState = new QState(topLevel);
+
+ QState *fireOnce = new QState(fireState);
+ connect(fireOnce, SIGNAL(entered()), tank, SLOT(fireCannon()));
+
+ QState *fireTwice = new QState(fireState);
+ connect(fireTwice, SIGNAL(entered()), tank, SLOT(fireCannon()));
+
+ fireOnce->addTransition(tank, SIGNAL(actionCompleted()), fireTwice);
+ fireTwice->addTransition(tank, SIGNAL(actionCompleted()), spinState);
+
+ spinState->addTransition(tank, SIGNAL(tankSpotted(qreal,qreal)), fireState);
+
+ return topLevel;
+}
+
+Q_EXPORT_PLUGIN2(spin_ai_with_error, SpinAiWithError)
diff --git a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h
new file mode 100644
index 0000000..e040bf2
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SPIN_AI_WITH_ERROR_H
+#define SPIN_AI_WITH_ERROR_H
+
+#include <tankgame/plugin.h>
+
+#include <QObject>
+#include <QState>
+#include <QVariant>
+
+class SpinState: public QState
+{
+ Q_OBJECT
+public:
+ SpinState(QObject *tank, QState *parent) : QState(parent), m_tank(tank)
+ {
+ }
+
+public slots:
+ void spin()
+ {
+ m_tank->setProperty("direction", m_tank->property("direction").toDouble() + 90.0);
+ }
+
+protected:
+ void onEntry(QEvent *)
+ {
+ connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin()));
+ spin();
+ }
+
+ void onExit(QEvent *)
+ {
+ disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin()));
+ }
+
+private:
+ QObject *m_tank;
+
+};
+
+class SpinAiWithError: public QObject, public Plugin
+{
+ Q_OBJECT
+ Q_INTERFACES(Plugin)
+public:
+ SpinAiWithError() { setObjectName("Spin and destroy with runtime error in state machine"); }
+
+ virtual QState *create(QState *parentState, QObject *tank);
+};
+
+#endif
diff --git a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.pro b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.pro
new file mode 100644
index 0000000..124cf98
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.pro
@@ -0,0 +1,13 @@
+TEMPLATE = lib
+CONFIG += plugin
+INCLUDEPATH += ../..
+HEADERS = spin_ai_with_error.h
+SOURCES = spin_ai_with_error.cpp
+TARGET = $$qtLibraryTarget(spin_ai_with_error)
+DESTDIR = ../../tankgame/plugins
+
+#! [0]
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS spin_ai_with_error.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/spin_ai_with_error \ No newline at end of file
diff --git a/examples/statemachine/tankgameplugins/tankgameplugins.pro b/examples/statemachine/tankgameplugins/tankgameplugins.pro
new file mode 100644
index 0000000..a098e03
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/tankgameplugins.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+SUBDIRS = random_ai \
+ spin_ai_with_error \
+ spin_ai \
+ seek_ai
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tankgameplugins.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins
+INSTALLS += target sources
diff --git a/examples/statemachine/trafficlight/main.cpp b/examples/statemachine/trafficlight/main.cpp
new file mode 100644
index 0000000..8a46fff
--- /dev/null
+++ b/examples/statemachine/trafficlight/main.cpp
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#ifdef QT_STATEMACHINE_SOLUTION
+#include <qstate.h>
+#include <qstatemachine.h>
+#include <qfinalstate.h>
+#endif
+
+//! [0]
+class LightWidget : public QWidget
+{
+ Q_OBJECT
+ Q_PROPERTY(bool on READ isOn WRITE setOn)
+public:
+ LightWidget(const QColor &color, QWidget *parent = 0)
+ : QWidget(parent), m_color(color), m_on(false) {}
+
+ bool isOn() const
+ { return m_on; }
+ void setOn(bool on)
+ {
+ if (on == m_on)
+ return;
+ m_on = on;
+ update();
+ }
+
+public slots:
+ void turnOff() { setOn(false); }
+ void turnOn() { setOn(true); }
+
+protected:
+ virtual void paintEvent(QPaintEvent *)
+ {
+ if (!m_on)
+ return;
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setBrush(m_color);
+ painter.drawEllipse(0, 0, width(), height());
+ }
+
+private:
+ QColor m_color;
+ bool m_on;
+};
+//! [0]
+
+//! [1]
+class TrafficLightWidget : public QWidget
+{
+public:
+ TrafficLightWidget(QWidget *parent = 0)
+ : QWidget(parent)
+ {
+ QVBoxLayout *vbox = new QVBoxLayout(this);
+ m_red = new LightWidget(Qt::red);
+ vbox->addWidget(m_red);
+ m_yellow = new LightWidget(Qt::yellow);
+ vbox->addWidget(m_yellow);
+ m_green = new LightWidget(Qt::green);
+ vbox->addWidget(m_green);
+ QPalette pal = palette();
+ pal.setColor(QPalette::Background, Qt::black);
+ setPalette(pal);
+ setAutoFillBackground(true);
+ }
+
+ LightWidget *redLight() const
+ { return m_red; }
+ LightWidget *yellowLight() const
+ { return m_yellow; }
+ LightWidget *greenLight() const
+ { return m_green; }
+
+private:
+ LightWidget *m_red;
+ LightWidget *m_yellow;
+ LightWidget *m_green;
+};
+//! [1]
+
+//! [2]
+QState *createLightState(LightWidget *light, int duration, QState *parent = 0)
+{
+ QState *lightState = new QState(parent);
+ QTimer *timer = new QTimer(lightState);
+ timer->setInterval(duration);
+ timer->setSingleShot(true);
+ QState *timing = new QState(lightState);
+ QObject::connect(timing, SIGNAL(entered()), light, SLOT(turnOn()));
+ QObject::connect(timing, SIGNAL(entered()), timer, SLOT(start()));
+ QObject::connect(timing, SIGNAL(exited()), light, SLOT(turnOff()));
+ QFinalState *done = new QFinalState(lightState);
+ timing->addTransition(timer, SIGNAL(timeout()), done);
+ lightState->setInitialState(timing);
+ return lightState;
+}
+//! [2]
+
+//! [3]
+class TrafficLight : public QWidget
+{
+public:
+ TrafficLight(QWidget *parent = 0)
+ : QWidget(parent)
+ {
+ QVBoxLayout *vbox = new QVBoxLayout(this);
+ TrafficLightWidget *widget = new TrafficLightWidget();
+ vbox->addWidget(widget);
+ vbox->setMargin(0);
+
+ QStateMachine *machine = new QStateMachine(this);
+ QState *redGoingYellow = createLightState(widget->redLight(), 3000);
+ redGoingYellow->setObjectName("redGoingYellow");
+ QState *yellowGoingGreen = createLightState(widget->yellowLight(), 1000);
+ yellowGoingGreen->setObjectName("yellowGoingGreen");
+ redGoingYellow->addTransition(redGoingYellow, SIGNAL(finished()), yellowGoingGreen);
+ QState *greenGoingYellow = createLightState(widget->greenLight(), 3000);
+ greenGoingYellow->setObjectName("greenGoingYellow");
+ yellowGoingGreen->addTransition(yellowGoingGreen, SIGNAL(finished()), greenGoingYellow);
+ QState *yellowGoingRed = createLightState(widget->yellowLight(), 1000);
+ yellowGoingRed->setObjectName("yellowGoingRed");
+ greenGoingYellow->addTransition(greenGoingYellow, SIGNAL(finished()), yellowGoingRed);
+ yellowGoingRed->addTransition(yellowGoingRed, SIGNAL(finished()), redGoingYellow);
+
+ machine->addState(redGoingYellow);
+ machine->addState(yellowGoingGreen);
+ machine->addState(greenGoingYellow);
+ machine->addState(yellowGoingRed);
+ machine->setInitialState(redGoingYellow);
+ machine->start();
+ }
+};
+//! [3]
+
+//! [4]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ TrafficLight widget;
+ widget.resize(110, 300);
+ widget.show();
+
+ return app.exec();
+}
+//! [4]
+
+#include "main.moc"
diff --git a/examples/statemachine/trafficlight/trafficlight.pro b/examples/statemachine/trafficlight/trafficlight.pro
new file mode 100644
index 0000000..684575a
--- /dev/null
+++ b/examples/statemachine/trafficlight/trafficlight.pro
@@ -0,0 +1,7 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/trafficlight
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS trafficlight.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/trafficlight
+INSTALLS += target sources
diff --git a/examples/statemachine/twowaybutton/main.cpp b/examples/statemachine/twowaybutton/main.cpp
new file mode 100644
index 0000000..a2c6e45
--- /dev/null
+++ b/examples/statemachine/twowaybutton/main.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#ifdef QT_STATEMACHINE_SOLUTION
+#include <qstate.h>
+#include <qstatemachine.h>
+#endif
+
+//! [0]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ QPushButton button;
+ QStateMachine machine;
+//! [0]
+
+//! [1]
+ QState *off = new QState();
+ off->assignProperty(&button, "text", "Off");
+ off->setObjectName("off");
+
+ QState *on = new QState();
+ on->setObjectName("on");
+ on->assignProperty(&button, "text", "On");
+//! [1]
+
+//! [2]
+ off->addTransition(&button, SIGNAL(clicked()), on);
+ on->addTransition(&button, SIGNAL(clicked()), off);
+//! [2]
+
+//! [3]
+ machine.addState(off);
+ machine.addState(on);
+//! [3]
+
+//! [4]
+ machine.setInitialState(off);
+ machine.start();
+//! [4]
+
+//! [5]
+ button.resize(100, 50);
+ button.show();
+ return app.exec();
+}
+//! [5]
diff --git a/examples/statemachine/twowaybutton/twowaybutton.pro b/examples/statemachine/twowaybutton/twowaybutton.pro
new file mode 100644
index 0000000..f6cbc57
--- /dev/null
+++ b/examples/statemachine/twowaybutton/twowaybutton.pro
@@ -0,0 +1,7 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/twowaybutton
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS twowaybutton.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/twowaybutton
+INSTALLS += target sources
diff --git a/mkspecs/win32-icc/qmake.conf b/mkspecs/win32-icc/qmake.conf
index 03582fc..78c947d 100644
--- a/mkspecs/win32-icc/qmake.conf
+++ b/mkspecs/win32-icc/qmake.conf
@@ -16,7 +16,7 @@ QMAKE_LEX = flex
QMAKE_LEXFLAGS =
QMAKE_YACC = byacc
QMAKE_YACCFLAGS = -d
-QMAKE_CFLAGS = -nologo -Zm200 /Qprec
+QMAKE_CFLAGS = -nologo -Zm200 /Qprec /Qwd1744,1738
QMAKE_CFLAGS_WARN_ON = -W3 /Qwd673
QMAKE_CFLAGS_WARN_OFF = -W0 /Qwd673
QMAKE_CFLAGS_RELEASE = -O2 -MD
diff --git a/src/3rdparty/easing/easing.cpp b/src/3rdparty/easing/easing.cpp
new file mode 100644
index 0000000..81af40f
--- /dev/null
+++ b/src/3rdparty/easing/easing.cpp
@@ -0,0 +1,670 @@
+/*
+Disclaimer for Robert Penner's Easing Equations license:
+
+TERMS OF USE - EASING EQUATIONS
+
+Open source under the BSD License.
+
+Copyright © 2001 Robert Penner
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <QtCore/qmath.h>
+#include <math.h>
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+#ifndef M_PI_2
+#define M_PI_2 (M_PI / 2)
+#endif
+
+QT_USE_NAMESPACE
+
+/**
+ * Easing equation function for a simple linear tweening, with no easing.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeNone(qreal progress)
+{
+ return progress;
+}
+
+/**
+ * Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInQuad(qreal t)
+{
+ return t*t;
+}
+
+/**
+* Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity.
+*
+* @param t Current time (in frames or seconds).
+* @return The correct value.
+*/
+static qreal easeOutQuad(qreal t)
+{
+ return -t*(t-2);
+}
+
+/**
+ * Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInOutQuad(qreal t)
+{
+ t*=2.0;
+ if (t < 1) {
+ return t*t/qreal(2);
+ } else {
+ --t;
+ return -0.5 * (t*(t-2) - 1);
+ }
+}
+
+/**
+ * Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutInQuad(qreal t)
+{
+ if (t < 0.5) return easeOutQuad (t*2)/2;
+ return easeInQuad((2*t)-1)/2 + 0.5;
+}
+
+/**
+ * Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInCubic(qreal t)
+{
+ return t*t*t;
+}
+
+/**
+ * Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutCubic(qreal t)
+{
+ t-=1.0;
+ return t*t*t + 1;
+}
+
+/**
+ * Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInOutCubic(qreal t)
+{
+ t*=2.0;
+ if(t < 1) {
+ return 0.5*t*t*t;
+ } else {
+ t -= qreal(2.0);
+ return 0.5*(t*t*t + 2);
+ }
+}
+
+/**
+ * Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutInCubic(qreal t)
+{
+ if (t < 0.5) return easeOutCubic (2*t)/2;
+ return easeInCubic(2*t - 1)/2 + 0.5;
+}
+
+/**
+ * Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInQuart(qreal t)
+{
+ return t*t*t*t;
+}
+
+/**
+ * Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutQuart(qreal t)
+{
+ t-= qreal(1.0);
+ return - (t*t*t*t- 1);
+}
+
+/**
+ * Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInOutQuart(qreal t)
+{
+ t*=2;
+ if (t < 1) return 0.5*t*t*t*t;
+ else {
+ t -= 2.0f;
+ return -0.5 * (t*t*t*t- 2);
+ }
+}
+
+/**
+ * Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutInQuart(qreal t)
+{
+ if (t < 0.5) return easeOutQuart (2*t)/2;
+ return easeInQuart(2*t-1)/2 + 0.5;
+}
+
+/**
+ * Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInQuint(qreal t)
+{
+ return t*t*t*t*t;
+}
+
+/**
+ * Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutQuint(qreal t)
+{
+ t-=1.0;
+ return t*t*t*t*t + 1;
+}
+
+/**
+ * Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInOutQuint(qreal t)
+{
+ t*=2.0;
+ if (t < 1) return 0.5*t*t*t*t*t;
+ else {
+ t -= 2.0;
+ return 0.5*(t*t*t*t*t + 2);
+ }
+}
+
+/**
+ * Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutInQuint(qreal t)
+{
+ if (t < 0.5) return easeOutQuint (2*t)/2;
+ return easeInQuint(2*t - 1)/2 + 0.5;
+}
+
+/**
+ * Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInSine(qreal t)
+{
+ return (t == 1.0) ? 1.0 : -::cos(t * M_PI_2) + 1.0;
+}
+
+/**
+ * Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutSine(qreal t)
+{
+ return ::sin(t* M_PI_2);
+}
+
+/**
+ * Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInOutSine(qreal t)
+{
+ return -0.5 * (::cos(M_PI*t) - 1);
+}
+
+/**
+ * Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutInSine(qreal t)
+{
+ if (t < 0.5) return easeOutSine (2*t)/2;
+ return easeInSine(2*t - 1)/2 + 0.5;
+}
+
+/**
+ * Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInExpo(qreal t)
+{
+ return (t==0 || t == 1.0) ? t : ::qPow(2.0, 10 * (t - 1)) - qreal(0.001);
+}
+
+/**
+ * Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutExpo(qreal t)
+{
+ return (t==1.0) ? 1.0 : 1.001 * (-::qPow(2.0f, -10 * t) + 1);
+}
+
+/**
+ * Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInOutExpo(qreal t)
+{
+ if (t==0.0) return qreal(0.0);
+ if (t==1.0) return qreal(1.0);
+ t*=2.0;
+ if (t < 1) return 0.5 * ::qPow(qreal(2.0), 10 * (t - 1)) - 0.0005;
+ return 0.5 * 1.0005 * (-::qPow(qreal(2.0), -10 * (t - 1)) + 2);
+}
+
+/**
+ * Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutInExpo(qreal t)
+{
+ if (t < 0.5) return easeOutExpo (2*t)/2;
+ return easeInExpo(2*t - 1)/2 + 0.5;
+}
+
+/**
+ * Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInCirc(qreal t)
+{
+ return -(::sqrt(1 - t*t) - 1);
+}
+
+/**
+ * Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutCirc(qreal t)
+{
+ t-= qreal(1.0);
+ return ::sqrt(1 - t* t);
+}
+
+/**
+ * Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeInOutCirc(qreal t)
+{
+ t*=qreal(2.0);
+ if (t < 1) {
+ return -0.5 * (::sqrt(1 - t*t) - 1);
+ } else {
+ t -= qreal(2.0);
+ return 0.5 * (::sqrt(1 - t*t) + 1);
+ }
+}
+
+/**
+ * Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @return The correct value.
+ */
+static qreal easeOutInCirc(qreal t)
+{
+ if (t < 0.5) return easeOutCirc (2*t)/2;
+ return easeInCirc(2*t - 1)/2 + 0.5;
+}
+
+static qreal easeInElastic_helper(qreal t, qreal b, qreal c, qreal d, qreal a, qreal p)
+{
+ if (t==0) return b;
+ qreal t_adj = (qreal)t / (qreal)d;
+ if (t_adj==1) return b+c;
+
+ qreal s;
+ if(a < ::fabs(c)) {
+ a = c;
+ s = p / 4.0f;
+ } else {
+ s = p / (2 * M_PI) * ::asin(c / a);
+ }
+
+ t_adj -= 1.0f;
+ return -(a*::qPow(2.0f,10*t_adj) * ::sin( (t_adj*d-s)*(2*M_PI)/p )) + b;
+}
+
+/**
+ * Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param a Amplitude.
+ * @param p Period.
+ * @return The correct value.
+ */
+static qreal easeInElastic(qreal t, qreal a, qreal p)
+{
+ return easeInElastic_helper(t, 0, 1, 1, a, p);
+}
+
+static qreal easeOutElastic_helper(qreal t, qreal /*b*/, qreal c, qreal /*d*/, qreal a, qreal p)
+{
+ if (t==0) return 0;
+ if (t==1) return c;
+
+ qreal s;
+ if(a < c) {
+ a = c;
+ s = p / 4.0f;
+ } else {
+ s = p / (2 * M_PI) * ::asin(c / a);
+ }
+
+ return (a*::qPow(2.0f,-10*t) * ::sin( (t-s)*(2*M_PI)/p ) + c);
+}
+
+/**
+ * Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param a Amplitude.
+ * @param p Period.
+ * @return The correct value.
+ */
+static qreal easeOutElastic(qreal t, qreal a, qreal p)
+{
+ return easeOutElastic_helper(t, 0, 1, 1, a, p);
+}
+
+/**
+ * Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param a Amplitude.
+ * @param p Period.
+ * @return The correct value.
+ */
+static qreal easeInOutElastic(qreal t, qreal a, qreal p)
+{
+ if (t==0) return 0.0;
+ t*=2.0;
+ if (t==2) return 1.0;
+
+ qreal s;
+ if(a < 1.0) {
+ a = 1.0;
+ s = p / 4.0f;
+ } else {
+ s = p / (2 * M_PI) * ::asin(1.0 / a);
+ }
+
+ if (t < 1) return -.5*(a*::qPow(2.0f,10*(t-1)) * ::sin( (t-1-s)*(2*M_PI)/p ));
+ return a*::qPow(2.0f,-10*(t-1)) * ::sin( (t-1-s)*(2*M_PI)/p )*.5 + 1.0;
+}
+
+/**
+ * Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param a Amplitude.
+ * @param p Period.
+ * @return The correct value.
+ */
+static qreal easeOutInElastic(qreal t, qreal a, qreal p)
+{
+ if (t < 0.5) return easeOutElastic_helper(t*2, 0, 0.5, 1.0, a, p);
+ return easeInElastic_helper(2*t - 1.0, 0.5, 0.5, 1.0, a, p);
+}
+
+/**
+ * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
+ * @return The correct value.
+ */
+static qreal easeInBack(qreal t, qreal s)
+{
+ return t*t*((s+1)*t - s);
+}
+
+/**
+ * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
+ * @return The correct value.
+ */
+static qreal easeOutBack(qreal t, qreal s)
+{
+ t-= qreal(1.0);
+ return t*t*((s+1)*t+ s) + 1;
+}
+
+/**
+ * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
+ * @return The correct value.
+ */
+static qreal easeInOutBack(qreal t, qreal s)
+{
+ t *= 2.0;
+ if (t < 1) {
+ s *= 1.525f;
+ return 0.5*(t*t*((s+1)*t - s));
+ } else {
+ t -= 2;
+ s *= 1.525f;
+ return 0.5*(t*t*((s+1)*t+ s) + 2);
+ }
+}
+
+/**
+ * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
+ * @return The correct value.
+ */
+static qreal easeOutInBack(qreal t, qreal s)
+{
+ if (t < 0.5) return easeOutBack (2*t, s)/2;
+ return easeInBack(2*t - 1, s)/2 + 0.5;
+}
+
+static qreal easeOutBounce_helper(qreal t, qreal c, qreal a)
+{
+ if (t == 1.0) return c;
+ if (t < (4/11.0)) {
+ return c*(7.5625*t*t);
+ } else if (t < (8/11.0)) {
+ t -= (6/11.0);
+ return -a * (1. - (7.5625*t*t + .75)) + c;
+ } else if (t < (10/11.0)) {
+ t -= (9/11.0);
+ return -a * (1. - (7.5625*t*t + .9375)) + c;
+ } else {
+ t -= (21/22.0);
+ return -a * (1. - (7.5625*t*t + .984375)) + c;
+ }
+}
+
+/**
+ * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param a Amplitude.
+ * @return The correct value.
+ */
+static qreal easeOutBounce(qreal t, qreal a)
+{
+ return easeOutBounce_helper(t, 1, a);
+}
+
+/**
+ * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param a Amplitude.
+ * @return The correct value.
+ */
+static qreal easeInBounce(qreal t, qreal a)
+{
+ return 1.0 - easeOutBounce_helper(1.0-t, 1.0, a);
+}
+
+
+/**
+ * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param a Amplitude.
+ * @return The correct value.
+ */
+static qreal easeInOutBounce(qreal t, qreal a)
+{
+ if (t < 0.5) return easeInBounce (2*t, a)/2;
+ else return (t == 1.0) ? 1.0 : easeOutBounce (2*t - 1, a)/2 + 0.5;
+}
+
+/**
+ * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration.
+ *
+ * @param t Current time (in frames or seconds).
+ * @param a Amplitude.
+ * @return The correct value.
+ */
+static qreal easeOutInBounce(qreal t, qreal a)
+{
+ if (t < 0.5) return easeOutBounce_helper(t*2, 0.5, a);
+ return 1.0 - easeOutBounce_helper (2.0-2*t, 0.5, a);
+}
+
+static inline qreal qt_sinProgress(qreal value)
+{
+ return qSin((value * M_PI) - M_PI_2) / 2 + qreal(0.5);
+}
+
+static inline qreal qt_smoothBeginEndMixFactor(qreal value)
+{
+ return qMin(qMax(1 - value * 2 + qreal(0.3), qreal(0.0)), qreal(1.0));
+}
+
+// SmoothBegin blends Smooth and Linear Interpolation.
+// Progress 0 - 0.3 : Smooth only
+// Progress 0.3 - ~ 0.5 : Mix of Smooth and Linear
+// Progress ~ 0.5 - 1 : Linear only
+
+/**
+ * Easing function that starts growing slowly, then increases in speed. At the end of the curve the speed will be constant.
+ */
+static qreal easeInCurve(qreal t)
+{
+ const qreal sinProgress = qt_sinProgress(t);
+ const qreal mix = qt_smoothBeginEndMixFactor(t);
+ return sinProgress * mix + t * (1 - mix);
+}
+
+/**
+ * Easing function that starts growing steadily, then ends slowly. The speed will be constant at the beginning of the curve.
+ */
+static qreal easeOutCurve(qreal t)
+{
+ const qreal sinProgress = qt_sinProgress(t);
+ const qreal mix = qt_smoothBeginEndMixFactor(1 - t);
+ return sinProgress * mix + t * (1 - mix);
+}
+
+/**
+ * Easing function where the value grows sinusoidally. Note that the calculated end value will be 0 rather than 1.
+ */
+static qreal easeSineCurve(qreal t)
+{
+ return (qSin(((t * M_PI * 2)) - M_PI_2) + 1) / 2;
+}
+
+/**
+ * Easing function where the value grows cosinusoidally. Note that the calculated start value will be 0.5 and the end value will be 0.5
+ * contrary to the usual 0 to 1 easing curve.
+ */
+static qreal easeCosineCurve(qreal t)
+{
+ return (qCos(((t * M_PI * 2)) - M_PI_2) + 1) / 2;
+}
+
diff --git a/src/3rdparty/easing/legal.qdoc b/src/3rdparty/easing/legal.qdoc
new file mode 100644
index 0000000..25f67e1
--- /dev/null
+++ b/src/3rdparty/easing/legal.qdoc
@@ -0,0 +1,35 @@
+/*!
+\page legal-easing.html
+\title Easing Equations by Robert Penner
+\ingroup animation
+
+\legalese
+\code
+Copyright (c) 2001 Robert Penner
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the author nor the names of contributors may be used
+ to endorse or promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+\endcode
+\endlegalese
+*/
diff --git a/src/3rdparty/webkit/VERSION b/src/3rdparty/webkit/VERSION
index 7adbd6f..7d5d1c5 100644
--- a/src/3rdparty/webkit/VERSION
+++ b/src/3rdparty/webkit/VERSION
@@ -8,4 +8,4 @@ The commit imported was from the
and has the sha1 checksum
- 40b523e9eaaba38c182e5a9c319f0069ebf98330
+ 4ee8af9348b3f57d3c0f3575ae0a58336cf07a92
diff --git a/src/3rdparty/webkit/WebCore/ChangeLog b/src/3rdparty/webkit/WebCore/ChangeLog
index a4cb62d..072beee 100644
--- a/src/3rdparty/webkit/WebCore/ChangeLog
+++ b/src/3rdparty/webkit/WebCore/ChangeLog
@@ -1,3 +1,42 @@
+2009-05-19 Kenneth Rohde Christiansen <kenneth.christiansen@openbossa.org>
+
+ Reviewed by Simon Hausmann.
+
+ Do not call the parent implementation (Widget::) in show() and hide()
+ of the PluginViewQt, as it always changes the visible state of the
+ platformWidget (equal to the platformPluginWidget in the Qt port),
+ thus ignoring the isParentVisible() test.
+
+ * plugins/qt/PluginViewQt.cpp:
+ (WebCore::PluginView::show):
+ (WebCore::PluginView::hide):
+
+2009-04-22 Tamas Szirbucz <szirbucz.tamas@stud.u-szeged.hu>
+
+ Reviewed by Ariya Hidayat.
+
+ https://bugs.webkit.org/show_bug.cgi?id=25023
+ Delete reply in QNetworkReplyHandler::abort() to avoid leak.
+
+ * platform/network/qt/QNetworkReplyHandler.cpp:
+ (WebCore::QNetworkReplyHandler::abort):
+
+2009-05-20 Holger Hans Peter Freyther <zecke@selfish.org>
+
+ Reviewed by Anders Carlsson.
+
+ https://bugs.webkit.org/show_bug.cgi?id=24510
+
+ Fix a bug where the browserfuncs were not properly assigned,
+ make hasproperty use _NP_HasProperty and hasmethod _NP_HasMethod.
+
+ Test: plugins/netscape-invoke-browserfuncs.html
+
+ * plugins/gtk/PluginPackageGtk.cpp:
+ (WebCore::PluginPackage::load): Fix assignment
+ * plugins/qt/PluginPackageQt.cpp:
+ (WebCore::PluginPackage::load): Fix assignment
+
2009-05-11 Yael Aharon <yael.aharon@nokia.com>
Reviewed by Holger Freyther.
diff --git a/src/3rdparty/webkit/WebCore/platform/network/qt/QNetworkReplyHandler.cpp b/src/3rdparty/webkit/WebCore/platform/network/qt/QNetworkReplyHandler.cpp
index 2c730a6..3e9b239 100644
--- a/src/3rdparty/webkit/WebCore/platform/network/qt/QNetworkReplyHandler.cpp
+++ b/src/3rdparty/webkit/WebCore/platform/network/qt/QNetworkReplyHandler.cpp
@@ -174,6 +174,7 @@ void QNetworkReplyHandler::abort()
if (m_reply) {
QNetworkReply* reply = release();
reply->abort();
+ reply->deleteLater();
deleteLater();
}
}
diff --git a/src/3rdparty/webkit/WebCore/plugins/qt/PluginPackageQt.cpp b/src/3rdparty/webkit/WebCore/plugins/qt/PluginPackageQt.cpp
index 4387813..13f5394 100644
--- a/src/3rdparty/webkit/WebCore/plugins/qt/PluginPackageQt.cpp
+++ b/src/3rdparty/webkit/WebCore/plugins/qt/PluginPackageQt.cpp
@@ -151,8 +151,8 @@ bool PluginPackage::load()
m_browserFuncs.getproperty = _NPN_GetProperty;
m_browserFuncs.setproperty = _NPN_SetProperty;
m_browserFuncs.removeproperty = _NPN_RemoveProperty;
- m_browserFuncs.hasproperty = _NPN_HasMethod;
- m_browserFuncs.hasmethod = _NPN_HasProperty;
+ m_browserFuncs.hasproperty = _NPN_HasProperty;
+ m_browserFuncs.hasmethod = _NPN_HasMethod;
m_browserFuncs.setexception = _NPN_SetException;
m_browserFuncs.enumerate = _NPN_Enumerate;
m_browserFuncs.construct = _NPN_Construct;
diff --git a/src/3rdparty/webkit/WebCore/plugins/qt/PluginViewQt.cpp b/src/3rdparty/webkit/WebCore/plugins/qt/PluginViewQt.cpp
index 43c772f..e856f92 100644
--- a/src/3rdparty/webkit/WebCore/plugins/qt/PluginViewQt.cpp
+++ b/src/3rdparty/webkit/WebCore/plugins/qt/PluginViewQt.cpp
@@ -113,7 +113,9 @@ void PluginView::show()
if (isParentVisible() && platformPluginWidget())
platformPluginWidget()->setVisible(true);
- Widget::show();
+ // do not call parent impl. here as it will set the platformWidget
+ // (same as platformPluginWidget in the Qt port) to visible, even
+ // when parent isn't visible.
}
void PluginView::hide()
@@ -123,7 +125,9 @@ void PluginView::hide()
if (isParentVisible() && platformPluginWidget())
platformPluginWidget()->setVisible(false);
- Widget::hide();
+ // do not call parent impl. here as it will set the platformWidget
+ // (same as platformPluginWidget in the Qt port) to invisible, even
+ // when parent isn't visible.
}
void PluginView::paint(GraphicsContext* context, const IntRect& rect)
diff --git a/src/3rdparty/webkit/WebKit/qt/ChangeLog b/src/3rdparty/webkit/WebKit/qt/ChangeLog
index 2aeb8da..d9f925a 100644
--- a/src/3rdparty/webkit/WebKit/qt/ChangeLog
+++ b/src/3rdparty/webkit/WebKit/qt/ChangeLog
@@ -1,3 +1,17 @@
+2009-05-19 Kenneth Rohde Christiansen <kenneth.christiansen@openbossa.org>
+
+ Reviewed by Simon Hausmann.
+
+ Fix a plugin bug in the WebKit code, similar to the one in WebCore.
+
+ The problem is when a non visible QtPluginWidget would show it self
+ in a sibling frame. The problem was due to our clipping. In Qt,
+ if setMask is set with an empty QRegion, no clipping will
+ be performed, so in that case we hide the PluginContainer
+
+ * WebCoreSupport/FrameLoaderClientQt.cpp:
+ (WebCore::):
+
2009-03-27 Erik L. Bunce <elbunce@xendom.com>
Reviewed by Simon Hausmann.
diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp
index c421d42..a2b33c0 100644
--- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp
+++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp
@@ -1058,7 +1058,13 @@ public:
IntRect clipRect(static_cast<FrameView*>(parentScrollView)->windowClipRect());
clipRect.move(-windowRect.x(), -windowRect.y());
clipRect.intersect(platformWidget()->rect());
- platformWidget()->setMask(QRegion(clipRect.x(), clipRect.y(), clipRect.width(), clipRect.height()));
+
+ QRegion clipRegion = QRegion(clipRect);
+ platformWidget()->setMask(clipRegion);
+
+ // if setMask is set with an empty QRegion, no clipping will
+ // be performed, so in that case we hide the platformWidget
+ platformWidget()->setVisible(!clipRegion.isEmpty());
}
};
diff --git a/src/corelib/animation/animation.pri b/src/corelib/animation/animation.pri
new file mode 100644
index 0000000..cb7850c
--- /dev/null
+++ b/src/corelib/animation/animation.pri
@@ -0,0 +1,25 @@
+# Qt core animation module
+
+HEADERS += \
+ animation/qabstractanimation.h \
+ animation/qabstractanimation_p.h \
+ animation/qvariantanimation.h \
+ animation/qvariantanimation_p.h \
+ animation/qpropertyanimation.h \
+ animation/qpropertyanimation_p.h \
+ animation/qanimationgroup.h \
+ animation/qanimationgroup_p.h \
+ animation/qsequentialanimationgroup.h \
+ animation/qsequentialanimationgroup_p.h \
+ animation/qparallelanimationgroup.h \
+ animation/qparallelanimationgroup_p.h \
+ animation/qpauseanimation.h
+
+SOURCES += \
+ animation/qabstractanimation.cpp \
+ animation/qvariantanimation.cpp \
+ animation/qpropertyanimation.cpp \
+ animation/qanimationgroup.cpp \
+ animation/qsequentialanimationgroup.cpp \
+ animation/qparallelanimationgroup.cpp \
+ animation/qpauseanimation.cpp
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp
new file mode 100644
index 0000000..16307e6
--- /dev/null
+++ b/src/corelib/animation/qabstractanimation.cpp
@@ -0,0 +1,733 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \class QAbstractAnimation
+ \ingroup animation
+ \brief The QAbstractAnimation class is the base of all animations.
+ \since 4.6
+
+ The class defines the functions for the functionality shared by
+ all animations. By inheriting this class, you can create custom
+ animations that plug into the rest of the animation framework.
+
+ The progress of an animation is given by its current time
+ (currentTime()), which is measured in milliseconds from the start
+ of the animation (0) to its end (duration()). The value is updated
+ automatically while the animation is running. It can also be set
+ directly with setCurrentTime().
+
+ At any point an animation is in one of three states:
+ \l{QAbstractAnimation::}{Running},
+ \l{QAbstractAnimation::}{Stopped}, or
+ \l{QAbstractAnimation::}{Paused}--as defined by the
+ \l{QAbstractAnimation::}{State} enum. The current state can be
+ changed by calling start(), stop(), pause(), or resume(). An
+ animation will always reset its \l{currentTime()}{current time}
+ when it is started. If paused, it will continue with the same
+ current time when resumed. When an animation is stopped, it cannot
+ be resumed, but will keep its current time (until started again).
+ QAbstractAnimation will emit stateChanged() whenever its state
+ changes.
+
+ An animation can loop any number of times by setting the loopCount
+ property. When an animation's current time reaches its duration(),
+ it will reset the current time and keep running. A loop count of 1
+ (the default value) means that the animation will run one time.
+ Note that a duration of -1 means that the animation will run until
+ stopped; the current time will increase indefinitely. When the
+ current time equals duration() and the animation is in its
+ final loop, the \l{QAbstractAnimation::}{Stopped} state is
+ entered, and the finished() signal is emitted.
+
+ QAbstractAnimation provides pure virtual functions used by
+ subclasses to track the progress of the animation: duration() and
+ updateCurrentTime(). The duration() function lets you report a
+ duration for the animation (as discussed above). The current time
+ is delivered by the animation framework through calls to
+ updateCurrentTime(). By reimplementing this function, you can
+ track the animation progress. Note that neither the interval
+ between calls nor the number of calls to this function are
+ defined; though, it will normally be 60 updates per second.
+
+ By reimplementing updateState(), you can track the animation's
+ state changes, which is particularly useful for animations that
+ are not driven by time.
+
+ \sa QVariantAnimation, QPropertyAnimation, QAnimationGroup, {The Animation Framework}
+*/
+
+/*!
+ \enum QAbstractAnimation::DeletionPolicy
+
+ \value KeepWhenStopped The animation will not be deleted when stopped.
+ \value DeleteWhenStopped The animation will be automatically deleted when
+ stopped.
+*/
+
+/*!
+ \fn QAbstractAnimation::finished()
+
+ QAbstractAnimation emits this signal after the animation has stopped and
+ has reached the end.
+
+ This signal is emitted after stateChanged().
+
+ \sa stateChanged()
+*/
+
+/*!
+ \fn QAbstractAnimation::stateChanged(QAbstractAnimation::State oldState, QAbstractAnimation::State newState)
+
+ QAbstractAnimation emits this signal whenever the state of the animation has
+ changed from \a oldState to \a newState. This signal is emitted after the virtual
+ updateState() function is called.
+
+ \sa updateState()
+*/
+
+/*!
+ \fn QAbstractAnimation::currentLoopChanged(int currentLoop)
+
+ QAbstractAnimation emits this signal whenever the current loop
+ changes. \a currentLoop is the current loop.
+
+ \sa currentLoop(), loopCount()
+*/
+
+/*!
+ \fn QAbstractAnimation::directionChanged(QAbstractAnimation::Direction newDirection);
+
+ QAbstractAnimation emits this signal whenever the direction has been
+ changed. \a newDirection is the new direction.
+
+ \sa direction
+*/
+
+#ifndef QT_NO_ANIMATION
+
+#include "qabstractanimation.h"
+#include "qanimationgroup.h"
+#include <QtCore/qdebug.h>
+
+#include "qabstractanimation_p.h"
+
+#include <QtCore/qmath.h>
+#include <QtCore/qthreadstorage.h>
+#include <QtCore/qcoreevent.h>
+#include <QtCore/qpointer.h>
+
+#define DEFAULT_TIMER_INTERVAL 16
+
+QT_BEGIN_NAMESPACE
+
+Q_GLOBAL_STATIC(QThreadStorage<QUnifiedTimer *>, unifiedTimer);
+
+QUnifiedTimer::QUnifiedTimer() : QObject(), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL), consistentTiming(false)
+{
+}
+
+QUnifiedTimer *QUnifiedTimer::instance()
+{
+ QUnifiedTimer *inst;
+ if (!unifiedTimer()->hasLocalData()) {
+ inst = new QUnifiedTimer;
+ unifiedTimer()->setLocalData(inst);
+ } else {
+ inst = unifiedTimer()->localData();
+ }
+ return inst;
+}
+
+void QUnifiedTimer::updateRecentlyStartedAnimations()
+{
+ if (animationsToStart.isEmpty())
+ return;
+
+ animations += animationsToStart;
+ updateTimer(); //we make sure we start the timer there
+
+ animationsToStart.clear();
+}
+
+void QUnifiedTimer::timerEvent(QTimerEvent *event)
+{
+ //this is simply the time we last received a tick
+ const int oldLastTick = lastTick;
+ if (time.isValid())
+ lastTick = consistentTiming ? oldLastTick + timingInterval : time.elapsed();
+
+ //we transfer the waiting animations into the "really running" state
+ updateRecentlyStartedAnimations();
+
+ if (event->timerId() == startStopAnimationTimer.timerId()) {
+ startStopAnimationTimer.stop();
+ if (animations.isEmpty()) {
+ animationTimer.stop();
+ time = QTime();
+ } else {
+ animationTimer.start(timingInterval, this);
+ lastTick = 0;
+ time.start();
+ }
+ } else if (event->timerId() == animationTimer.timerId()) {
+ const int delta = lastTick - oldLastTick;
+ for (int i = 0; i < animations.count(); ++i) {
+ QAbstractAnimation *animation = animations.at(i);
+ int elapsed = QAbstractAnimationPrivate::get(animation)->totalCurrentTime
+ + (animation->direction() == QAbstractAnimation::Forward ? delta : -delta);
+ animation->setCurrentTime(elapsed);
+ }
+ }
+}
+
+void QUnifiedTimer::updateTimer()
+{
+ //we delay the call to start and stop for the animation timer so that if you
+ //stop and start animations in batch you don't stop/start the timer too often.
+ if (!startStopAnimationTimer.isActive())
+ startStopAnimationTimer.start(0, this); // we delay the actual start of the animation
+}
+
+void QUnifiedTimer::registerAnimation(QAbstractAnimation *animation)
+{
+ if (animations.contains(animation) ||animationsToStart.contains(animation))
+ return;
+ animationsToStart << animation;
+ updateTimer();
+}
+
+void QUnifiedTimer::unregisterAnimation(QAbstractAnimation *animation)
+{
+ animations.removeAll(animation);
+ animationsToStart.removeAll(animation);
+ updateTimer();
+}
+
+
+void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState)
+{
+ Q_Q(QAbstractAnimation);
+ if (state == newState)
+ return;
+
+ QAbstractAnimation::State oldState = state;
+ int oldCurrentTime = currentTime;
+ int oldCurrentLoop = currentLoop;
+ QAbstractAnimation::Direction oldDirection = direction;
+
+ state = newState;
+
+ QPointer<QAbstractAnimation> guard(q);
+
+ guard->updateState(oldState, newState);
+
+ //this is to be safe if updateState changes the state
+ if (state == oldState)
+ return;
+
+ // Notify state change
+ if (guard)
+ emit guard->stateChanged(oldState, newState);
+
+ // Enter running state.
+ switch (state)
+ {
+ case QAbstractAnimation::Paused:
+ case QAbstractAnimation::Running:
+ {
+ // Rewind
+ if (oldState == QAbstractAnimation::Stopped) {
+ if (guard) {
+ if (direction == QAbstractAnimation::Forward)
+ q->setCurrentTime(0);
+ else
+ q->setCurrentTime(loopCount == -1 ? q->duration() : q->totalDuration());
+ }
+
+ // Check if the setCurrentTime() function called stop().
+ // This can happen for a 0-duration animation
+ if (state == QAbstractAnimation::Stopped)
+ return;
+ }
+
+ // Register timer if our parent is not running.
+ if (state == QAbstractAnimation::Running && guard) {
+ if (!group || group->state() == QAbstractAnimation::Stopped) {
+ QUnifiedTimer::instance()->registerAnimation(q);
+ }
+ } else {
+ //new state is paused
+ QUnifiedTimer::instance()->unregisterAnimation(q);
+ }
+ }
+ break;
+ case QAbstractAnimation::Stopped:
+ // Leave running state.
+ int dura = q->duration();
+ if (deleteWhenStopped && guard)
+ q->deleteLater();
+
+ QUnifiedTimer::instance()->unregisterAnimation(q);
+
+ if (dura == -1 || loopCount < 0
+ || (oldDirection == QAbstractAnimation::Forward && (oldCurrentTime * (oldCurrentLoop + 1)) == (dura * loopCount))
+ || (oldDirection == QAbstractAnimation::Backward && oldCurrentTime == 0)) {
+ if (guard)
+ emit q->finished();
+ }
+ break;
+ }
+
+}
+
+/*!
+ Constructs the QAbstractAnimation base class, and passes \a parent to
+ QObject's constructor.
+
+ \sa QVariantAnimation, QAnimationGroup
+*/
+QAbstractAnimation::QAbstractAnimation(QObject *parent)
+ : QObject(*new QAbstractAnimationPrivate, 0)
+{
+ // Allow auto-add on reparent
+ setParent(parent);
+}
+
+/*!
+ \internal
+*/
+QAbstractAnimation::QAbstractAnimation(QAbstractAnimationPrivate &dd, QObject *parent)
+ : QObject(dd, 0)
+{
+ // Allow auto-add on reparent
+ setParent(parent);
+}
+
+/*!
+ Stops the animation if it's running, then destroys the
+ QAbstractAnimation. If the animation is part of a QAnimationGroup, it is
+ automatically removed before it's destroyed.
+*/
+QAbstractAnimation::~QAbstractAnimation()
+{
+ Q_D(QAbstractAnimation);
+ //we can't call stop here. Otherwise we get pure virtual calls
+ if (d->state != Stopped) {
+ QAbstractAnimation::State oldState = d->state;
+ d->state = Stopped;
+ emit stateChanged(oldState, d->state);
+ QUnifiedTimer::instance()->unregisterAnimation(this);
+ }
+}
+
+/*!
+ \property QAbstractAnimation::state
+ \brief state of the animation.
+
+ This property describes the current state of the animation. When the
+ animation state changes, QAbstractAnimation emits the stateChanged()
+ signal.
+*/
+QAbstractAnimation::State QAbstractAnimation::state() const
+{
+ Q_D(const QAbstractAnimation);
+ return d->state;
+}
+
+/*!
+ If this animation is part of a QAnimationGroup, this function returns a
+ pointer to the group; otherwise, it returns 0.
+
+ \sa QAnimationGroup::addAnimation()
+*/
+QAnimationGroup *QAbstractAnimation::group() const
+{
+ Q_D(const QAbstractAnimation);
+ return d->group;
+}
+
+/*!
+ \enum QAbstractAnimation::State
+
+ This enum describes the state of the animation.
+
+ \value Stopped The animation is not running. This is the initial state
+ of QAbstractAnimation, and the state QAbstractAnimation reenters when finished. The current
+ time remain unchanged until either setCurrentTime() is
+ called, or the animation is started by calling start().
+
+ \value Paused The animation is paused (i.e., temporarily
+ suspended). Calling resume() will resume animation activity.
+
+ \value Running The animation is running. While control is in the event
+ loop, QAbstractAnimation will update its current time at regular intervals,
+ calling updateCurrentTime() when appropriate.
+
+ \sa state(), stateChanged()
+*/
+
+/*!
+ \enum QAbstractAnimation::Direction
+
+ This enum describes the direction of the animation when in \l Running state.
+
+ \value Forward The current time of the animation increases with time (i.e.,
+ moves from 0 and towards the end / duration).
+
+ \value Backward The current time of the animation decreases with time (i.e.,
+ moves from the end / duration and towards 0).
+
+ \sa direction
+*/
+
+/*!
+ \property QAbstractAnimation::direction
+ \brief the direction of the animation when it is in \l Running
+ state.
+
+ This direction indicates whether the time moves from 0 towards the
+ animation duration, or from the value of the duration and towards 0 after
+ start() has been called.
+
+ By default, this property is set to \l Forward.
+*/
+QAbstractAnimation::Direction QAbstractAnimation::direction() const
+{
+ Q_D(const QAbstractAnimation);
+ return d->direction;
+}
+void QAbstractAnimation::setDirection(Direction direction)
+{
+ Q_D(QAbstractAnimation);
+ if (d->direction == direction)
+ return;
+
+ d->direction = direction;
+ if (state() == Stopped) {
+ if (direction == Backward) {
+ d->currentTime = duration();
+ d->currentLoop = d->loopCount - 1;
+ } else {
+ d->currentTime = 0;
+ d->currentLoop = 0;
+ }
+ }
+ updateDirection(direction);
+ emit directionChanged(direction);
+}
+
+/*!
+ \property QAbstractAnimation::duration
+ \brief the duration of the animation.
+
+ If the duration is -1, it means that the duration is undefined.
+ In this case, loopCount is ignored.
+*/
+
+/*!
+ \property QAbstractAnimation::loopCount
+ \brief the loop count of the animation
+
+ This property describes the loop count of the animation as an integer.
+ By default this value is 1, indicating that the animation
+ should run once only, and then stop. By changing it you can let the
+ animation loop several times. With a value of 0, the animation will not
+ run at all, and with a value of -1, the animation will loop forever
+ until stopped.
+ It is not supported to have loop on an animation that has an undefined
+ duration. It will only run once.
+*/
+int QAbstractAnimation::loopCount() const
+{
+ Q_D(const QAbstractAnimation);
+ return d->loopCount;
+}
+void QAbstractAnimation::setLoopCount(int loopCount)
+{
+ Q_D(QAbstractAnimation);
+ d->loopCount = loopCount;
+}
+
+/*!
+ \property QAbstractAnimation::currentLoop
+ \brief the current loop of the animation
+
+ This property describes the current loop of the animation. By default,
+ the animation's loop count is 1, and so the current loop will
+ always be 0. If the loop count is 2 and the animation runs past its
+ duration, it will automatically rewind and restart at current time 0, and
+ current loop 1, and so on.
+
+ When the current loop changes, QAbstractAnimation emits the
+ currentLoopChanged() signal.
+*/
+int QAbstractAnimation::currentLoop() const
+{
+ Q_D(const QAbstractAnimation);
+ return d->currentLoop;
+}
+
+/*!
+ \fn virtual int QAbstractAnimation::duration() const = 0
+
+ This pure virtual function returns the duration of the animation, and
+ defines for how long QAbstractAnimation should update the current
+ time. This duration is local, and does not include the loop count.
+
+ A return value of -1 indicates that the animation has no defined duration;
+ the animation should run forever until stopped. This is useful for
+ animations that are not time driven, or where you cannot easily predict
+ its duration (e.g., event driven audio playback in a game).
+
+ If the animation is a parallel QAnimationGroup, the duration will be the longest
+ duration of all its animations. If the animation is a sequential QAnimationGroup,
+ the duration will be the sum of the duration of all its animations.
+ \sa loopCount
+*/
+
+/*!
+ Returns the total and effective duration of the animation, including the
+ loop count.
+
+ \sa duration(), currentTime
+*/
+int QAbstractAnimation::totalDuration() const
+{
+ Q_D(const QAbstractAnimation);
+ if (d->loopCount < 0)
+ return -1;
+ int dura = duration();
+ if (dura == -1)
+ return -1;
+ return dura * d->loopCount;
+}
+
+/*!
+ \property QAbstractAnimation::currentTime
+ \brief the current time and progress of the animation
+
+ This property describes the animation's current time. You can change the
+ current time by calling setCurrentTime, or you can call start() and let
+ the animation run, setting the current time automatically as the animation
+ progresses.
+
+ The animation's current time starts at 0, and ends at duration(). If the
+ animation's loopCount is larger than 1, the current time will rewind and
+ start at 0 again for the consecutive loops. If the animation has a pause.
+ currentTime will also include the duration of the pause.
+
+ \sa loopCount
+ */
+int QAbstractAnimation::currentTime() const
+{
+ Q_D(const QAbstractAnimation);
+ return d->currentTime;
+}
+void QAbstractAnimation::setCurrentTime(int msecs)
+{
+ Q_D(QAbstractAnimation);
+ msecs = qMax(msecs, 0);
+
+ // Calculate new time and loop.
+ int dura = duration();
+ int totalDura = (d->loopCount < 0 || dura == -1) ? -1 : dura * d->loopCount;
+ if (totalDura != -1)
+ msecs = qMin(totalDura, msecs);
+ d->totalCurrentTime = msecs;
+
+ // Update new values.
+ int oldLoop = d->currentLoop;
+ d->currentLoop = ((dura <= 0) ? 0 : (msecs / dura));
+ if (d->currentLoop == d->loopCount) {
+ //we're at the end
+ d->currentTime = qMax(0, dura);
+ d->currentLoop = qMax(0, d->loopCount - 1);
+ } else {
+ if (d->direction == Forward) {
+ d->currentTime = (dura <= 0) ? msecs : (msecs % dura);
+ } else {
+ d->currentTime = (dura <= 0) ? msecs : ((msecs - 1) % dura) + 1;
+ if (d->currentTime == dura)
+ --d->currentLoop;
+ }
+ }
+
+ updateCurrentTime(msecs);
+ if (d->currentLoop != oldLoop)
+ emit currentLoopChanged(d->currentLoop);
+
+ // All animations are responsible for stopping the animation when their
+ // own end state is reached; in this case the animation is time driven,
+ // and has reached the end.
+ if ((d->direction == Forward && d->totalCurrentTime == totalDura)
+ || (d->direction == Backward && d->totalCurrentTime == 0)) {
+ stop();
+ }
+}
+
+/*!
+ Starts the animation. The \a policy argument says whether or not the
+ animation should be deleted when it's done. When the animation starts, the
+ stateChanged() signal is emitted, and state() returns Running. When control
+ reaches the event loop, the animation will run by itself, periodically
+ calling updateCurrentTime() as the animation progresses.
+
+ If the animation is currently stopped or has already reached the end,
+ calling start() will rewind the animation and start again from the beginning.
+ When the animation reaches the end, the animation will either stop, or
+ if the loop level is more than 1, it will rewind and continue from the beginning.
+
+ If the animation is already running, this function does nothing.
+
+ \sa stop(), state()
+*/
+void QAbstractAnimation::start(DeletionPolicy policy)
+{
+ Q_D(QAbstractAnimation);
+ if (d->state == Running)
+ return;
+ d->setState(Running);
+ d->deleteWhenStopped = policy;
+}
+
+/*!
+ Stops the animation. When the animation is stopped, it emits the stateChanged()
+ signal, and state() returns Stopped. The current time is not changed.
+
+ If the animation stops by itself after reaching the end (i.e.,
+ currentTime() == duration() and currentLoop() > loopCount() - 1), the
+ finished() signal is emitted.
+
+ \sa start(), state()
+ */
+void QAbstractAnimation::stop()
+{
+ Q_D(QAbstractAnimation);
+
+ d->setState(Stopped);
+}
+
+/*!
+ Pauses the animation. When the animation is paused, state() returns Paused.
+ The currenttime will remain unchanged until resume() or start() is called.
+ If you want to continue from the current time, call resume().
+
+
+ \sa start(), state(), resume()
+ */
+void QAbstractAnimation::pause()
+{
+ Q_D(QAbstractAnimation);
+ if (d->state == Stopped) {
+ qWarning("QAbstractAnimation::pause: Cannot pause a stopped animation");
+ return;
+ }
+
+ d->setState(Paused);
+}
+
+/*!
+ Resumes the animation after it was paused. When the animation is resumed,
+ it emits the resumed() and stateChanged() signals. The currenttime is not
+ changed.
+
+ \sa start(), pause(), state()
+ */
+void QAbstractAnimation::resume()
+{
+ Q_D(QAbstractAnimation);
+ if (d->state != Paused) {
+ qWarning("QAbstractAnimation::resume: "
+ "Cannot resume an animation that is not paused");
+ return;
+ }
+
+ d->setState(Running);
+}
+
+/*!
+ \reimp
+*/
+bool QAbstractAnimation::event(QEvent *event)
+{
+ return QObject::event(event);
+}
+
+/*!
+ \fn virtual void QAbstractAnimation::updateCurrentTime(int msecs) = 0;
+
+ This pure virtual function is called every time the animation's current
+ time changes. The \a msecs argument is the current time.
+
+ \sa updateState()
+*/
+
+/*!
+ This virtual function is called by QAbstractAnimation when the state
+ of the animation is changed from \a oldState to \a newState.
+
+ \sa start(), stop(), pause(), resume()
+*/
+void QAbstractAnimation::updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+{
+ Q_UNUSED(oldState);
+ Q_UNUSED(newState);
+}
+
+/*!
+ This virtual function is called by QAbstractAnimation when the direction
+ of the animation is changed. The \a direction argument is the new direction.
+
+ \sa setDirection(), direction()
+*/
+void QAbstractAnimation::updateDirection(QAbstractAnimation::Direction direction)
+{
+ Q_UNUSED(direction);
+}
+
+
+QT_END_NAMESPACE
+
+#include "moc_qabstractanimation.cpp"
+
+#endif //QT_NO_ANIMATION
diff --git a/src/corelib/animation/qabstractanimation.h b/src/corelib/animation/qabstractanimation.h
new file mode 100644
index 0000000..d6d50dc
--- /dev/null
+++ b/src/corelib/animation/qabstractanimation.h
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QABSTRACTANIMATION_H
+#define QABSTRACTANIMATION_H
+
+#include <QtCore/qobject.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+#ifndef QT_NO_ANIMATION
+
+class QAnimationGroup;
+class QSequentialAnimationGroup;
+
+class QAbstractAnimationPrivate;
+class Q_CORE_EXPORT QAbstractAnimation : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(State state READ state NOTIFY stateChanged)
+ Q_PROPERTY(int loopCount READ loopCount WRITE setLoopCount)
+ Q_PROPERTY(int currentTime READ currentTime WRITE setCurrentTime)
+ Q_PROPERTY(int currentLoop READ currentLoop NOTIFY currentLoopChanged)
+ Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged)
+ Q_PROPERTY(int duration READ duration)
+
+public:
+ enum Direction {
+ Forward,
+ Backward
+ };
+
+ enum State {
+ Stopped,
+ Paused,
+ Running
+ };
+
+ enum DeletionPolicy {
+ KeepWhenStopped = 0,
+ DeleteWhenStopped
+ };
+
+ QAbstractAnimation(QObject *parent = 0);
+ virtual ~QAbstractAnimation();
+
+ State state() const;
+
+ QAnimationGroup *group() const;
+
+ Direction direction() const;
+ void setDirection(Direction direction);
+
+ int loopCount() const;
+ void setLoopCount(int loopCount);
+ int currentLoop() const;
+
+ virtual int duration() const = 0;
+ int totalDuration() const;
+
+ int currentTime() const;
+
+Q_SIGNALS:
+ void finished();
+ void stateChanged(QAbstractAnimation::State oldState, QAbstractAnimation::State newState);
+ void currentLoopChanged(int currentLoop);
+ void directionChanged(QAbstractAnimation::Direction);
+
+public Q_SLOTS:
+ void start(QAbstractAnimation::DeletionPolicy policy = KeepWhenStopped);
+ void pause();
+ void resume();
+ void stop();
+ void setCurrentTime(int msecs);
+
+protected:
+ QAbstractAnimation(QAbstractAnimationPrivate &dd, QObject *parent = 0);
+ bool event(QEvent *event);
+
+ virtual void updateCurrentTime(int msecs) = 0;
+ virtual void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState);
+ virtual void updateDirection(QAbstractAnimation::Direction direction);
+
+private:
+ Q_DISABLE_COPY(QAbstractAnimation)
+ Q_DECLARE_PRIVATE(QAbstractAnimation)
+};
+
+#endif //QT_NO_ANIMATION
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QABSTRACTANIMATION_H
diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h
new file mode 100644
index 0000000..7a4bfcf
--- /dev/null
+++ b/src/corelib/animation/qabstractanimation_p.h
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QABSTRACTANIMATION_P_H
+#define QABSTRACTANIMATION_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of QIODevice. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qbasictimer.h>
+#include <QtCore/qdatetime.h>
+#include <QtCore/qtimer.h>
+#include <private/qobject_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAnimationGroup;
+class QAbstractAnimation;
+class QAbstractAnimationPrivate : public QObjectPrivate
+{
+public:
+ QAbstractAnimationPrivate()
+ : state(QAbstractAnimation::Stopped),
+ direction(QAbstractAnimation::Forward),
+ deleteWhenStopped(false),
+ totalCurrentTime(0),
+ currentTime(0),
+ loopCount(1),
+ currentLoop(0),
+ group(0)
+ {
+ }
+
+ virtual ~QAbstractAnimationPrivate() {}
+
+ static QAbstractAnimationPrivate *get(QAbstractAnimation *q)
+ {
+ return q->d_func();
+ }
+
+ QAbstractAnimation::State state;
+ QAbstractAnimation::Direction direction;
+ bool deleteWhenStopped;
+ void setState(QAbstractAnimation::State state);
+
+ int totalCurrentTime;
+ int currentTime;
+ int loopCount;
+ int currentLoop;
+
+ QAnimationGroup *group;
+
+private:
+ Q_DECLARE_PUBLIC(QAbstractAnimation)
+};
+
+
+class QUnifiedTimer : public QObject
+{
+private:
+ QUnifiedTimer();
+
+public:
+ //XXX this is needed by dui
+ static Q_CORE_EXPORT QUnifiedTimer *instance();
+
+ void registerAnimation(QAbstractAnimation *animation);
+ void unregisterAnimation(QAbstractAnimation *animation);
+
+ //defines the timing interval. Default is DEFAULT_TIMER_INTERVAL
+ void setTimingInterval(int interval)
+ {
+ timingInterval = interval;
+ if (animationTimer.isActive()) {
+ //we changed the timing interval
+ animationTimer.start(timingInterval, this);
+ }
+ }
+
+ /*
+ this allows to have a consistent timer interval at each tick from the timer
+ not taking the real time that passed into account.
+ */
+ void setConsistentTiming(bool consistent) { consistentTiming = consistent; }
+
+ int elapsedTime() const { return lastTick; }
+
+protected:
+ void timerEvent(QTimerEvent *);
+ void updateTimer();
+
+private:
+ void updateRecentlyStartedAnimations();
+
+ QBasicTimer animationTimer, startStopAnimationTimer;
+ QTime time;
+ int lastTick;
+ int timingInterval;
+ bool consistentTiming;
+ QList<QAbstractAnimation*> animations, animationsToStart;
+};
+
+QT_END_NAMESPACE
+#endif
diff --git a/src/corelib/animation/qanimationgroup.cpp b/src/corelib/animation/qanimationgroup.cpp
new file mode 100644
index 0000000..839b522
--- /dev/null
+++ b/src/corelib/animation/qanimationgroup.cpp
@@ -0,0 +1,309 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \class QAnimationGroup
+ \brief The QAnimationGroup class is an abstract base class for groups of animations.
+ \since 4.6
+ \ingroup animation
+
+ An animation group is a container for animations (subclasses of
+ QAbstractAnimation). A group is usually responsible for managing
+ the \l{QAbstractAnimation::State}{state} of its animations, i.e.,
+ it decides when to start, stop, resume, and pause them. Currently,
+ Qt provides two such groups: QParallelAnimationGroup and
+ QSequentialAnimationGroup. Look up their class descriptions for
+ details.
+
+ Since QAnimationGroup inherits from QAbstractAnimation, you can
+ combine groups, and easily construct complex animation graphs.
+ You can query QAbstractAnimation for the group it belongs to
+ (using the \l{QAbstractAnimation::}{group()} function).
+
+ To start a top-level animation group, you simply use the
+ \l{QAbstractAnimation::}{start()} function from
+ QAbstractAnimation. By a top-level animation group, we think of a
+ group that itself is not contained within another group. Starting
+ sub groups directly is not supported, and may lead to unexpected
+ behavior.
+
+ \omit OK, we'll put in a snippet on this here \endomit
+
+ QAnimationGroup provides methods for adding and retrieving
+ animations. Besides that, you can remove animations by calling
+ remove(), and clear the animation group by calling
+ clearAnimations(). You may keep track of changes in the group's
+ animations by listening to QEvent::ChildAdded and
+ QEvent::ChildRemoved events.
+
+ \omit OK, let's find a snippet here as well. \endomit
+
+ QAnimationGroup takes ownership of the animations it manages, and
+ ensures that they are deleted when the animation group is deleted.
+
+ You can also use a \l{The State Machine Framework}{state machine}
+ to create complex animations. The framework provides a special
+ state, QAnimationState, that plays an animation upon entry and
+ transitions to a new state when the animation has finished
+ playing. This technique can also be combined with using animation
+ groups.
+
+ \sa QAbstractAnimation, QVariantAnimation, {The Animation Framework}
+*/
+
+#ifndef QT_NO_ANIMATION
+
+#include "qanimationgroup.h"
+#include <QtCore/qdebug.h>
+#include <QtCore/qcoreevent.h>
+#include "qanimationgroup_p.h"
+
+QT_BEGIN_NAMESPACE
+
+
+/*!
+ Constructs a QAnimationGroup.
+ \a parent is passed to QObject's constructor.
+*/
+QAnimationGroup::QAnimationGroup(QObject *parent)
+ : QAbstractAnimation(*new QAnimationGroupPrivate, parent)
+{
+}
+
+/*!
+ \internal
+*/
+QAnimationGroup::QAnimationGroup(QAnimationGroupPrivate &dd, QObject *parent)
+ : QAbstractAnimation(dd, parent)
+{
+}
+
+/*!
+ Destroys the animation group. It will also destroy all its animations.
+*/
+QAnimationGroup::~QAnimationGroup()
+{
+}
+
+/*!
+ Returns a pointer to the animation at \a index in this group. This
+ function is useful when you need access to a particular animation. \a
+ index is between 0 and animationCount() - 1.
+
+ \sa animationCount(), indexOfAnimation()
+*/
+QAbstractAnimation *QAnimationGroup::animationAt(int index) const
+{
+ Q_D(const QAnimationGroup);
+
+ if (index < 0 || index >= d->animations.size()) {
+ qWarning("QAnimationGroup::animationAt: index is out of bounds");
+ return 0;
+ }
+
+ return d->animations.at(index);
+}
+
+
+/*!
+ Returns the number of animations managed by this group.
+
+ \sa indexOfAnimation(), addAnimation(), animationAt()
+*/
+int QAnimationGroup::animationCount() const
+{
+ Q_D(const QAnimationGroup);
+ return d->animations.size();
+}
+
+/*!
+ Returns the index of \a animation. The returned index can be passed
+ to the other functions that take an index as an argument.
+
+ \sa insertAnimationAt(), animationAt(), takeAnimationAt()
+*/
+int QAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const
+{
+ Q_D(const QAnimationGroup);
+ return d->animations.indexOf(animation);
+}
+
+/*!
+ Adds \a animation to this group. This will call insertAnimationAt with
+ index equals to animationCount().
+
+ \note The group takes ownership of the animation.
+
+ \sa removeAnimation()
+*/
+void QAnimationGroup::addAnimation(QAbstractAnimation *animation)
+{
+ Q_D(QAnimationGroup);
+ insertAnimationAt(d->animations.count(), animation);
+}
+
+/*!
+ Inserts \a animation into this animation group at \a index.
+ If \a index is 0 the animation is inserted at the beginning.
+ If \a index is animationCount(), the animation is inserted at the end.
+
+ \note The group takes ownership of the animation.
+
+ \sa takeAnimationAt(), addAnimation(), indexOfAnimation(), removeAnimation()
+*/
+void QAnimationGroup::insertAnimationAt(int index, QAbstractAnimation *animation)
+{
+ Q_D(QAnimationGroup);
+
+ if (index < 0 || index > d->animations.size()) {
+ qWarning("QAnimationGroup::insertAnimationAt: index is out of bounds");
+ return;
+ }
+
+ if (QAnimationGroup *oldGroup = animation->group())
+ oldGroup->removeAnimation(animation);
+
+ d->animations.insert(index, animation);
+ QAbstractAnimationPrivate::get(animation)->group = this;
+ // this will make sure that ChildAdded event is sent to 'this'
+ animation->setParent(this);
+ d->animationInsertedAt(index);
+}
+
+/*!
+ Removes \a animation from this group. The ownership of \a animation is
+ transferred to the caller.
+
+ \sa takeAnimationAt(), insertAnimationAt(), addAnimation()
+*/
+void QAnimationGroup::removeAnimation(QAbstractAnimation *animation)
+{
+ Q_D(QAnimationGroup);
+
+ if (!animation) {
+ qWarning("QAnimationGroup::remove: cannot remove null animation");
+ return;
+ }
+ int index = d->animations.indexOf(animation);
+ if (index == -1) {
+ qWarning("QAnimationGroup::remove: animation is not part of this group");
+ return;
+ }
+
+ takeAnimationAt(index);
+}
+
+/*!
+ Returns the animation at \a index and removes it from the animation group.
+
+ \note The ownership of the animation is transferred to the caller.
+
+ \sa removeAnimation(), addAnimation(), insertAnimationAt(), indexOfAnimation()
+*/
+QAbstractAnimation *QAnimationGroup::takeAnimationAt(int index)
+{
+ Q_D(QAnimationGroup);
+ if (index < 0 || index >= d->animations.size()) {
+ qWarning("QAnimationGroup::takeAnimationAt: no animation at index %d", index);
+ return 0;
+ }
+ QAbstractAnimation *animation = d->animations.at(index);
+ QAbstractAnimationPrivate::get(animation)->group = 0;
+ // ### removing from list before doing setParent to avoid inifinite recursion
+ // in ChildRemoved event
+ d->animations.removeAt(index);
+ animation->setParent(0);
+ d->animationRemovedAt(index);
+ return animation;
+}
+
+/*!
+ Removes and deletes all animations in this animation group, and resets the current
+ time to 0.
+
+ \sa addAnimation(), removeAnimation()
+*/
+void QAnimationGroup::clearAnimations()
+{
+ Q_D(QAnimationGroup);
+ qDeleteAll(d->animations);
+}
+
+/*!
+ \reimp
+*/
+bool QAnimationGroup::event(QEvent *event)
+{
+ Q_D(QAnimationGroup);
+ if (event->type() == QEvent::ChildAdded) {
+ QChildEvent *childEvent = static_cast<QChildEvent *>(event);
+ if (QAbstractAnimation *a = qobject_cast<QAbstractAnimation *>(childEvent->child())) {
+ if (a->group() != this)
+ addAnimation(a);
+ }
+ } else if (event->type() == QEvent::ChildRemoved) {
+ QChildEvent *childEvent = static_cast<QChildEvent *>(event);
+ QAbstractAnimation *a = static_cast<QAbstractAnimation *>(childEvent->child());
+ // You can only rely on the child being a QObject because in the QEvent::ChildRemoved
+ // case it might be called from the destructor.
+ int index = d->animations.indexOf(a);
+ if (index != -1)
+ takeAnimationAt(index);
+ }
+ return QAbstractAnimation::event(event);
+}
+
+
+void QAnimationGroupPrivate::animationRemovedAt(int index)
+{
+ Q_Q(QAnimationGroup);
+ Q_UNUSED(index);
+ if (animations.isEmpty()) {
+ currentTime = 0;
+ q->stop();
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qanimationgroup.cpp"
+
+#endif //QT_NO_ANIMATION
diff --git a/src/corelib/animation/qanimationgroup.h b/src/corelib/animation/qanimationgroup.h
new file mode 100644
index 0000000..263bc38
--- /dev/null
+++ b/src/corelib/animation/qanimationgroup.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QANIMATIONGROUP_H
+#define QANIMATIONGROUP_H
+
+#include <QtCore/qabstractanimation.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+#ifndef QT_NO_ANIMATION
+
+class QAnimationGroupPrivate;
+class Q_CORE_EXPORT QAnimationGroup : public QAbstractAnimation
+{
+ Q_OBJECT
+
+public:
+ QAnimationGroup(QObject *parent = 0);
+ ~QAnimationGroup();
+
+ QAbstractAnimation *animationAt(int index) const;
+ int animationCount() const;
+ int indexOfAnimation(QAbstractAnimation *animation) const;
+ void addAnimation(QAbstractAnimation *animation);
+ void insertAnimationAt(int index, QAbstractAnimation *animation);
+ void removeAnimation(QAbstractAnimation *animation);
+ QAbstractAnimation *takeAnimationAt(int index);
+ void clearAnimations();
+
+protected:
+ QAnimationGroup(QAnimationGroupPrivate &dd, QObject *parent);
+ bool event(QEvent *event);
+
+private:
+ Q_DISABLE_COPY(QAnimationGroup)
+ Q_DECLARE_PRIVATE(QAnimationGroup)
+};
+
+#endif //QT_NO_ANIMATION
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif //QANIMATIONGROUP_H
diff --git a/src/corelib/animation/qanimationgroup_p.h b/src/corelib/animation/qanimationgroup_p.h
new file mode 100644
index 0000000..a7bd0fa
--- /dev/null
+++ b/src/corelib/animation/qanimationgroup_p.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QANIMATIONGROUP_P_H
+#define QANIMATIONGROUP_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of QIODevice. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qanimationgroup.h"
+
+#include <QtCore/qlist.h>
+
+#include "qabstractanimation_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QAnimationGroupPrivate : public QAbstractAnimationPrivate
+{
+ Q_DECLARE_PUBLIC(QAnimationGroup)
+public:
+ QAnimationGroupPrivate()
+ { }
+
+ virtual void animationInsertedAt(int index) { Q_UNUSED(index) };
+ virtual void animationRemovedAt(int index);
+
+ QList<QAbstractAnimation *> animations;
+};
+
+QT_END_NAMESPACE
+
+#endif //QANIMATIONGROUP_P_H
diff --git a/src/corelib/animation/qparallelanimationgroup.cpp b/src/corelib/animation/qparallelanimationgroup.cpp
new file mode 100644
index 0000000..13f6073
--- /dev/null
+++ b/src/corelib/animation/qparallelanimationgroup.cpp
@@ -0,0 +1,316 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \class QParallelAnimationGroup
+ \brief The QParallelAnimationGroup class provides a parallel group of animations.
+ \since 4.6
+ \ingroup animation
+
+ QParallelAnimationGroup--a \l{QAnimationGroup}{container for
+ animations}--starts all its animations when it is
+ \l{QAbstractAnimation::start()}{started} itself, i.e., runs all
+ animations in parallel. The animation group finishes when the
+ longest lasting animation has finished.
+
+ You can treat QParallelAnimation as any other QAbstractAnimation,
+ e.g., pause, resume, or add it to other animation groups.
+
+ \code
+ QParallelAnimationGroup *group = new QParallelAnimationGroup;
+ group->addAnimation(anim1);
+ group->addAnimation(anim2);
+
+ group->start();
+ \endcode
+
+ In this example, \c anim1 and \c anim2 are two
+ \l{QPropertyAnimation}s that have already been set up.
+
+ \sa QAnimationGroup, QPropertyAnimation, {The Animation Framework}
+*/
+
+#ifndef QT_NO_ANIMATION
+
+#include "qparallelanimationgroup.h"
+#include "qparallelanimationgroup_p.h"
+//#define QANIMATION_DEBUG
+QT_BEGIN_NAMESPACE
+
+/*!
+ Constructs a QParallelAnimationGroup.
+ \a parent is passed to QObject's constructor.
+*/
+QParallelAnimationGroup::QParallelAnimationGroup(QObject *parent)
+ : QAnimationGroup(*new QParallelAnimationGroupPrivate, parent)
+{
+}
+
+/*!
+ \internal
+*/
+QParallelAnimationGroup::QParallelAnimationGroup(QParallelAnimationGroupPrivate &dd,
+ QObject *parent)
+ : QAnimationGroup(dd, parent)
+{
+}
+
+/*!
+ Destroys the animation group. It will also destroy all its animations.
+*/
+QParallelAnimationGroup::~QParallelAnimationGroup()
+{
+}
+
+/*!
+ \reimp
+*/
+int QParallelAnimationGroup::duration() const
+{
+ Q_D(const QParallelAnimationGroup);
+ int ret = 0;
+
+ for (int i = 0; i < d->animations.size(); ++i) {
+ QAbstractAnimation *animation = d->animations.at(i);
+ const int currentDuration = animation->totalDuration();
+ if (currentDuration == -1)
+ return -1; // Undetermined length
+
+ ret = qMax(ret, currentDuration);
+ }
+
+ return ret;
+}
+
+/*!
+ \reimp
+*/
+void QParallelAnimationGroup::updateCurrentTime(int)
+{
+ Q_D(QParallelAnimationGroup);
+ if (d->animations.isEmpty())
+ return;
+
+ if (d->currentLoop > d->lastLoop) {
+ // simulate completion of the loop
+ int dura = duration();
+ if (dura > 0) {
+ foreach (QAbstractAnimation *animation, d->animations) {
+ animation->setCurrentTime(dura); // will stop
+ }
+ }
+ } else if (d->currentLoop < d->lastLoop) {
+ // simulate completion of the loop seeking backwards
+ foreach (QAbstractAnimation *animation, d->animations) {
+ animation->setCurrentTime(0);
+ animation->stop();
+ }
+ }
+
+ bool timeFwd = ((d->currentLoop == d->lastLoop && d->currentTime >= d->lastCurrentTime)
+ || d->currentLoop > d->lastLoop);
+#ifdef QANIMATION_DEBUG
+ qDebug("QParallellAnimationGroup %5d: setCurrentTime(%d), loop:%d, last:%d, timeFwd:%d, lastcurrent:%d, %d",
+ __LINE__, d->currentTime, d->currentLoop, d->lastLoop, timeFwd, d->lastCurrentTime, state());
+#endif
+ // finally move into the actual time of the current loop
+ foreach (QAbstractAnimation *animation, d->animations) {
+ const int dura = animation->totalDuration();
+ if (dura == -1 && d->isUncontrolledAnimationFinished(animation))
+ continue;
+ if (dura == -1 || (d->currentTime <= dura && dura != 0)
+ || (dura == 0 && d->currentLoop != d->lastLoop)) {
+ switch (state()) {
+ case Running:
+ animation->start();
+ break;
+ case Paused:
+ animation->pause();
+ break;
+ case Stopped:
+ default:
+ break;
+ }
+ }
+
+ if (dura <= 0) {
+ if (dura == -1)
+ animation->setCurrentTime(d->currentTime);
+ continue;
+ }
+
+ if ((timeFwd && d->lastCurrentTime <= dura)
+ || (!timeFwd && d->currentTime <= dura))
+ animation->setCurrentTime(d->currentTime);
+ if (d->currentTime > dura)
+ animation->stop();
+ }
+ d->lastLoop = d->currentLoop;
+ d->lastCurrentTime = d->currentTime;
+}
+
+/*!
+ \reimp
+*/
+void QParallelAnimationGroup::updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+{
+ Q_D(QParallelAnimationGroup);
+ QAnimationGroup::updateState(oldState, newState);
+
+ switch (newState) {
+ case Stopped:
+ foreach (QAbstractAnimation *animation, d->animations)
+ animation->stop();
+ d->disconnectUncontrolledAnimations();
+ break;
+ case Paused:
+ foreach (QAbstractAnimation *animation, d->animations)
+ animation->pause();
+ break;
+ case Running:
+ d->connectUncontrolledAnimations();
+ foreach (QAbstractAnimation *animation, d->animations) {
+ animation->stop();
+ animation->setDirection(d->direction);
+ animation->start();
+ }
+ break;
+ }
+}
+
+void QParallelAnimationGroupPrivate::_q_uncontrolledAnimationFinished()
+{
+ Q_Q(QParallelAnimationGroup);
+
+ QAbstractAnimation *animation = qobject_cast<QAbstractAnimation *>(q->sender());
+ Q_ASSERT(animation);
+
+ int uncontrolledRunningCount = 0;
+ if (animation->duration() == -1 || animation->loopCount() < 0) {
+ QHash<QAbstractAnimation *, int>::iterator it = uncontrolledFinishTime.begin();
+ while (it != uncontrolledFinishTime.end()) {
+ if (it.key() == animation) {
+ *it = animation->currentTime();
+ }
+ if (it.value() == -1)
+ ++uncontrolledRunningCount;
+ ++it;
+ }
+ }
+
+ if (uncontrolledRunningCount > 0)
+ return;
+
+ int maxDuration = 0;
+ foreach (QAbstractAnimation *a, animations)
+ maxDuration = qMax(maxDuration, a->totalDuration());
+
+ if (currentTime >= maxDuration)
+ q->stop();
+}
+
+void QParallelAnimationGroupPrivate::disconnectUncontrolledAnimations()
+{
+ Q_Q(QParallelAnimationGroup);
+
+ QHash<QAbstractAnimation *, int>::iterator it = uncontrolledFinishTime.begin();
+ while (it != uncontrolledFinishTime.end()) {
+ QObject::disconnect(it.key(), SIGNAL(finished()), q, SLOT(_q_uncontrolledAnimationFinished()));
+ ++it;
+ }
+
+ uncontrolledFinishTime.clear();
+}
+
+void QParallelAnimationGroupPrivate::connectUncontrolledAnimations()
+{
+ Q_Q(QParallelAnimationGroup);
+
+ foreach (QAbstractAnimation *animation, animations) {
+ if (animation->duration() == -1 || animation->loopCount() < 0) {
+ uncontrolledFinishTime[animation] = -1;
+ QObject::connect(animation, SIGNAL(finished()), q, SLOT(_q_uncontrolledAnimationFinished()));
+ }
+ }
+}
+
+bool QParallelAnimationGroupPrivate::isUncontrolledAnimationFinished(QAbstractAnimation *anim) const
+{
+ return uncontrolledFinishTime.value(anim, -1) >= 0;
+}
+
+/*!
+ \reimp
+*/
+void QParallelAnimationGroup::updateDirection(QAbstractAnimation::Direction direction)
+{
+ Q_D(QParallelAnimationGroup);
+ //we need to update the direction of the current animation
+ if (state() != Stopped) {
+ foreach(QAbstractAnimation *anim, d->animations) {
+ anim->setDirection(direction);
+ }
+ } else {
+ if (direction == Forward) {
+ d->lastLoop = 0;
+ d->lastCurrentTime = 0;
+ } else {
+ // Looping backwards with loopCount == -1 does not really work well...
+ d->lastLoop = (d->loopCount == -1 ? 0 : d->loopCount - 1);
+ d->lastCurrentTime = duration();
+ }
+ }
+}
+
+/*!
+ \reimp
+*/
+bool QParallelAnimationGroup::event(QEvent *event)
+{
+ return QAnimationGroup::event(event);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qparallelanimationgroup.cpp"
+
+#endif //QT_NO_ANIMATION
diff --git a/src/corelib/animation/qparallelanimationgroup.h b/src/corelib/animation/qparallelanimationgroup.h
new file mode 100644
index 0000000..57a8146
--- /dev/null
+++ b/src/corelib/animation/qparallelanimationgroup.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPARALLELANIMATIONGROUP_H
+#define QPARALLELANIMATIONGROUP_H
+
+#include <QtCore/qanimationgroup.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+#ifndef QT_NO_ANIMATION
+
+class QParallelAnimationGroupPrivate;
+class Q_CORE_EXPORT QParallelAnimationGroup : public QAnimationGroup
+{
+ Q_OBJECT
+
+public:
+ QParallelAnimationGroup(QObject *parent = 0);
+ ~QParallelAnimationGroup();
+
+ int duration() const;
+
+protected:
+ QParallelAnimationGroup(QParallelAnimationGroupPrivate &dd, QObject *parent);
+ bool event(QEvent *event);
+
+ void updateCurrentTime(int msecs);
+ void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState);
+ void updateDirection(QAbstractAnimation::Direction direction);
+
+private:
+ Q_DISABLE_COPY(QParallelAnimationGroup)
+ Q_DECLARE_PRIVATE(QParallelAnimationGroup)
+ Q_PRIVATE_SLOT(d_func(), void _q_uncontrolledAnimationFinished())
+};
+
+#endif //QT_NO_ANIMATION
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QPARALLELANIMATIONGROUP
diff --git a/src/corelib/animation/qparallelanimationgroup_p.h b/src/corelib/animation/qparallelanimationgroup_p.h
new file mode 100644
index 0000000..f36d972
--- /dev/null
+++ b/src/corelib/animation/qparallelanimationgroup_p.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPARALLELANIMATIONGROUP_P_H
+#define QPARALLELANIMATIONGROUP_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of QIODevice. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qparallelanimationgroup.h"
+#include "qanimationgroup_p.h"
+#include <QtCore/QHash>
+
+QT_BEGIN_NAMESPACE
+
+class QParallelAnimationGroupPrivate : public QAnimationGroupPrivate
+{
+ Q_DECLARE_PUBLIC(QParallelAnimationGroup)
+public:
+ QParallelAnimationGroupPrivate()
+ : lastLoop(0), lastCurrentTime(0)
+ {
+ }
+
+ QHash<QAbstractAnimation*, int> uncontrolledFinishTime;
+ int lastLoop;
+ int lastCurrentTime;
+
+ bool isUncontrolledAnimationFinished(QAbstractAnimation *anim) const;
+ void connectUncontrolledAnimations();
+ void disconnectUncontrolledAnimations();
+
+ // private slot
+ void _q_uncontrolledAnimationFinished();
+};
+
+QT_END_NAMESPACE
+
+#endif //QPARALLELANIMATIONGROUP_P_H
diff --git a/src/corelib/animation/qpauseanimation.cpp b/src/corelib/animation/qpauseanimation.cpp
new file mode 100644
index 0000000..b175f0c
--- /dev/null
+++ b/src/corelib/animation/qpauseanimation.cpp
@@ -0,0 +1,154 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \class QPauseAnimation
+ \brief The QPauseAnimation class provides a pause for QSequentialAnimationGroup.
+ \since 4.6
+ \ingroup animation
+
+ If you wish to introduce a delay between animations in a
+ QSequentialAnimationGroup, you can insert a QPauseAnimation. This
+ class does not animate anything, but does not
+ \l{QAbstractAnimation::finished()}{finish} before a specified
+ number of milliseconds have elapsed from when it was started. You
+ specify the duration of the pause in the constructor. It can also
+ be set directly with setDuration().
+
+ It is not necessary to construct a QPauseAnimation yourself.
+ QSequentialAnimationGroup provides the convenience functions
+ \l{QSequentialAnimationGroup::}{addPause()} and
+ \l{QSequentialAnimationGroup::}{insertPauseAt()}. These functions
+ simply take the number of milliseconds the pause should last.
+
+ \sa QSequentialAnimationGroup
+*/
+
+#ifndef QT_NO_ANIMATION
+
+#include "qpauseanimation.h"
+#include "qabstractanimation_p.h"
+
+
+QT_BEGIN_NAMESPACE
+
+class QPauseAnimationPrivate : public QAbstractAnimationPrivate
+{
+public:
+ QPauseAnimationPrivate() : QAbstractAnimationPrivate(), duration(0)
+ {
+ }
+
+ int duration;
+};
+
+/*!
+ Constructs a QPauseAnimation.
+ \a parent is passed to QObject's constructor.
+ The default duration is 0.
+*/
+
+QPauseAnimation::QPauseAnimation(QObject *parent) : QAbstractAnimation(*new QPauseAnimationPrivate, parent)
+{
+}
+
+/*!
+ Constructs a QPauseAnimation.
+ \a msecs is the duration of the pause.
+ \a parent is passed to QObject's constructor.
+*/
+
+QPauseAnimation::QPauseAnimation(int msecs, QObject *parent) : QAbstractAnimation(*new QPauseAnimationPrivate, parent)
+{
+ setDuration(msecs);
+}
+
+/*!
+ Destroys the pause animation.
+*/
+QPauseAnimation::~QPauseAnimation()
+{
+}
+
+/*!
+ \property QPauseAnimation::duration
+ \brief the duration of the pause.
+
+ The duration of the pause. The duration should not be negative.
+*/
+int QPauseAnimation::duration() const
+{
+ Q_D(const QPauseAnimation);
+ return d->duration;
+}
+
+void QPauseAnimation::setDuration(int msecs)
+{
+ if (msecs < 0) {
+ qWarning("QPauseAnimation::setDuration: cannot set a negative duration");
+ return;
+ }
+ Q_D(QPauseAnimation);
+ d->duration = msecs;
+}
+
+/*!
+ \reimp
+ */
+bool QPauseAnimation::event(QEvent *e)
+{
+ return QAbstractAnimation::event(e);
+}
+
+/*!
+ \reimp
+ */
+void QPauseAnimation::updateCurrentTime(int msecs)
+{
+ Q_UNUSED(msecs);
+}
+
+
+QT_END_NAMESPACE
+
+#include "moc_qpauseanimation.cpp"
+
+#endif //QT_NO_ANIMATION
diff --git a/src/corelib/animation/qpauseanimation.h b/src/corelib/animation/qpauseanimation.h
new file mode 100644
index 0000000..cb6e041
--- /dev/null
+++ b/src/corelib/animation/qpauseanimation.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPAUSEANIMATION_P_H
+#define QPAUSEANIMATION_P_H
+
+#include <QtCore/qanimationgroup.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+#ifndef QT_NO_ANIMATION
+
+class QPauseAnimationPrivate;
+
+class Q_CORE_EXPORT QPauseAnimation : public QAbstractAnimation
+{
+ Q_OBJECT
+ Q_PROPERTY(int duration READ duration WRITE setDuration)
+public:
+ QPauseAnimation(QObject *parent = 0);
+ QPauseAnimation(int msecs, QObject *parent = 0);
+ ~QPauseAnimation();
+
+ int duration() const;
+ void setDuration(int msecs);
+
+protected:
+ bool event(QEvent *e);
+ void updateCurrentTime(int msecs);
+
+private:
+ Q_DISABLE_COPY(QPauseAnimation)
+ Q_DECLARE_PRIVATE(QPauseAnimation)
+};
+
+#endif //QT_NO_ANIMATION
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QPAUSEANIMATION_P_H
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp
new file mode 100644
index 0000000..9a17049
--- /dev/null
+++ b/src/corelib/animation/qpropertyanimation.cpp
@@ -0,0 +1,316 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \class QPropertyAnimation
+ \brief The QPropertyAnimation class animates Qt properties
+ \since 4.6
+ \ingroup animation
+
+ QPropertyAnimation interpolates over \l{Qt's Property System}{Qt
+ properties}. As property values are stored in \l{QVariant}s, the
+ class inherits QVariantAnimation, and supports animation of the
+ same \l{QVariant::Type}{variant types} as its super class.
+
+ A class declaring properties must be a QObject. To make it
+ possible to animate a property, it must provide a setter (so that
+ QPropertyAnimation can set the property's value). Note that this
+ makes it possible to animate many of Qt's widgets. Let's look at
+ an example:
+
+ \code
+ QPropertyAnimation animation(myWidget, "geometry");
+ animation.setDuration(10000);
+ animation.setStartValue(QRect(0, 0, 100, 30));
+ animation.setEndValue(QRect(250, 250, 100, 30));
+
+ animation.start();
+ \endcode
+
+ The property name and the QObject instance of which property
+ should be animated are passed to the constructor. You can then
+ specify the start and end value of the property. The procedure is
+ equal for properties in classes you have implemented
+ yourself--just check with QVariantAnimation that your QVariant
+ type is supported.
+
+ The QVariantAnimation class description explains how to set up the
+ animation in detail. Note, however, that if a start value is not
+ set, the property will start at the value it had when the
+ QPropertyAnimation instance was created.
+
+ QPropertyAnimation works like a charm on its own. For complex
+ animations that, for instance, contain several objects,
+ QAnimationGroup is provided. An animation group is an animation
+ that can contain other animations, and that can manage when its
+ animations are played. Look at QParallelAnimationGroup for an
+ example.
+
+ \sa QVariantAnimation, QAnimationGroup, {The Animation Framework}
+*/
+
+#ifndef QT_NO_ANIMATION
+
+#include "qpropertyanimation.h"
+#include "qanimationgroup.h"
+#include <QtCore/qdebug.h>
+
+#include "qpropertyanimation_p.h"
+
+#include <QtCore/qmath.h>
+#include <QtCore/qmutex.h>
+
+QT_BEGIN_NAMESPACE
+
+typedef QPair<QObject *, QByteArray> QPropertyAnimationPair;
+typedef QHash<QPropertyAnimationPair, QPropertyAnimation*> QPropertyAnimationHash;
+Q_GLOBAL_STATIC(QPropertyAnimationHash, _q_runningAnimations);
+Q_GLOBAL_STATIC_WITH_ARGS(QMutex, guardHashLock, (QMutex::Recursive) )
+
+void QPropertyAnimationPrivate::updateMetaProperty()
+{
+ if (!target || propertyName.isEmpty())
+ return;
+
+ if (hasMetaProperty == 0 && !property.isValid()) {
+ const QMetaObject *mo = target->metaObject();
+ propertyIndex = mo->indexOfProperty(propertyName);
+ if (propertyIndex != -1) {
+ hasMetaProperty = 1;
+ property = mo->property(propertyIndex);
+ propertyType = property.userType();
+ } else {
+ if (!target->dynamicPropertyNames().contains(propertyName))
+ qWarning("QPropertyAnimation: you're trying to animate a non-existing property %s of your QObject", propertyName.constData());
+ hasMetaProperty = 2;
+ }
+ }
+
+ if (property.isValid())
+ convertValues(propertyType);
+}
+
+void QPropertyAnimationPrivate::updateProperty(const QVariant &newValue)
+{
+ if (!target || state == QAbstractAnimation::Stopped)
+ return;
+
+ if (hasMetaProperty == 1) {
+ if (newValue.userType() == propertyType) {
+ //no conversion is needed, we directly call the QObject::qt_metacall
+ void *data = const_cast<void*>(newValue.constData());
+ target->qt_metacall(QMetaObject::WriteProperty, propertyIndex, &data);
+ } else {
+ property.write(target, newValue);
+ }
+ } else {
+ target->setProperty(propertyName.constData(), newValue);
+ }
+}
+
+void QPropertyAnimationPrivate::_q_targetDestroyed()
+{
+ Q_Q(QPropertyAnimation);
+ //we stop here so that this animation is removed from the global hash
+ q->stop();
+ target = 0;
+}
+
+/*!
+ Construct a QPropertyAnimation object. \a parent is passed to QObject's
+ constructor.
+*/
+QPropertyAnimation::QPropertyAnimation(QObject *parent)
+ : QVariantAnimation(*new QPropertyAnimationPrivate, parent)
+{
+}
+
+/*!
+ Construct a QPropertyAnimation object. \a parent is passed to QObject's
+ constructor. The animation changes the property \a propertyName on \a
+ target. The default duration is 250ms.
+
+ \sa targetObject, propertyName
+*/
+QPropertyAnimation::QPropertyAnimation(QObject *target, const QByteArray &propertyName, QObject *parent)
+ : QVariantAnimation(*new QPropertyAnimationPrivate, parent)
+{
+ setTargetObject(target);
+ setPropertyName(propertyName);
+}
+
+/*!
+ Destroys the QPropertyAnimation instance.
+ */
+QPropertyAnimation::~QPropertyAnimation()
+{
+ stop();
+}
+
+/*!
+ \property QPropertyAnimation::targetObject
+ \brief the target QObject for this animation.
+
+ This property defines the target QObject for this animation.
+ */
+QObject *QPropertyAnimation::targetObject() const
+{
+ Q_D(const QPropertyAnimation);
+ return d->target;
+}
+
+void QPropertyAnimation::setTargetObject(QObject *target)
+{
+ Q_D(QPropertyAnimation);
+ if (d->target == target)
+ return;
+
+ if (d->state != QAbstractAnimation::Stopped) {
+ qWarning("QPropertyAnimation::setTargetObject: you can't change the target of a running animation");
+ return;
+ }
+
+ //we need to get notified when the target is destroyed
+ if (d->target)
+ disconnect(d->target, SIGNAL(destroyed()), this, SLOT(_q_targetDestroyed()));
+
+ if (target)
+ connect(target, SIGNAL(destroyed()), SLOT(_q_targetDestroyed()));
+
+ d->target = target;
+ d->hasMetaProperty = 0;
+ d->updateMetaProperty();
+}
+
+/*!
+ \property QPropertyAnimation::propertyName
+ \brief the target property name for this animation
+
+ This property defines the target property name for this animation. The
+ property name is required for the animation to operate.
+ */
+QByteArray QPropertyAnimation::propertyName() const
+{
+ Q_D(const QPropertyAnimation);
+ return d->propertyName;
+}
+
+void QPropertyAnimation::setPropertyName(const QByteArray &propertyName)
+{
+ Q_D(QPropertyAnimation);
+ if (d->state != QAbstractAnimation::Stopped) {
+ qWarning("QPropertyAnimation::setPropertyName: you can't change the property name of a running animation");
+ return;
+ }
+
+ d->propertyName = propertyName;
+ d->hasMetaProperty = 0;
+ d->updateMetaProperty();
+}
+
+
+/*!
+ \reimp
+ */
+bool QPropertyAnimation::event(QEvent *event)
+{
+ return QVariantAnimation::event(event);
+}
+
+/*!
+ This virtual function is called by QVariantAnimation whenever the current value
+ changes. \a value is the new, updated value. It updates the current value
+ of the property on the target object.
+
+ \sa currentValue, currentTime
+ */
+void QPropertyAnimation::updateCurrentValue(const QVariant &value)
+{
+ Q_D(QPropertyAnimation);
+ d->updateProperty(value);
+}
+
+/*!
+ \reimp
+
+ If the startValue is not defined when the state of the animation changes from Stopped to Running,
+ the current property value is used as the initial value for the animation.
+*/
+void QPropertyAnimation::updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+{
+ Q_D(QPropertyAnimation);
+
+ if (!d->target) {
+ qWarning("QPropertyAnimation::updateState: Changing state of an animation without target");
+ return;
+ }
+
+ QVariantAnimation::updateState(oldState, newState);
+ QMutexLocker locker(guardHashLock());
+ QPropertyAnimationHash * hash = _q_runningAnimations();
+ QPropertyAnimationPair key(d->target, d->propertyName);
+ if (newState == Running) {
+ d->updateMetaProperty();
+ QPropertyAnimation *oldAnim = hash->value(key, 0);
+ if (oldAnim) {
+ // try to stop the top level group
+ QAbstractAnimation *current = oldAnim;
+ while (current->group() && current->state() != Stopped)
+ current = current->group();
+ current->stop();
+ }
+ hash->insert(key, this);
+
+ // update the default start value
+ if (oldState == Stopped) {
+ d->setDefaultStartValue(d->target->property(d->propertyName.constData()));
+ }
+ } else if (hash->value(key) == this) {
+ hash->remove(key);
+ }
+}
+
+#include "moc_qpropertyanimation.cpp"
+
+QT_END_NAMESPACE
+
+#endif //QT_NO_ANIMATION
diff --git a/src/corelib/animation/qpropertyanimation.h b/src/corelib/animation/qpropertyanimation.h
new file mode 100644
index 0000000..39317ba
--- /dev/null
+++ b/src/corelib/animation/qpropertyanimation.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPROPERTYANIMATION_H
+#define QPROPERTYANIMATION_H
+
+#include <QtCore/qvariantanimation.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+#ifndef QT_NO_ANIMATION
+
+class QPropertyAnimationPrivate;
+class Q_CORE_EXPORT QPropertyAnimation : public QVariantAnimation
+{
+ Q_OBJECT
+ Q_PROPERTY(QByteArray propertyName READ propertyName WRITE setPropertyName)
+ Q_PROPERTY(QObject* targetObject READ targetObject WRITE setTargetObject)
+
+public:
+ QPropertyAnimation(QObject *parent = 0);
+ QPropertyAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = 0);
+ ~QPropertyAnimation();
+
+ QObject *targetObject() const;
+ void setTargetObject(QObject *target);
+
+ QByteArray propertyName() const;
+ void setPropertyName(const QByteArray &propertyName);
+
+protected:
+ bool event(QEvent *event);
+ void updateCurrentValue(const QVariant &value);
+ void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState);
+
+private:
+ Q_PRIVATE_SLOT(d_func(), void _q_targetDestroyed());
+ Q_DISABLE_COPY(QPropertyAnimation)
+ Q_DECLARE_PRIVATE(QPropertyAnimation)
+};
+
+#endif //QT_NO_ANIMATION
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QPROPERTYANIMATION_H
diff --git a/src/corelib/animation/qpropertyanimation_p.h b/src/corelib/animation/qpropertyanimation_p.h
new file mode 100644
index 0000000..b51d039
--- /dev/null
+++ b/src/corelib/animation/qpropertyanimation_p.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPROPERTYANIMATION_P_H
+#define QPROPERTYANIMATION_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of QIODevice. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qpropertyanimation.h"
+#include <QtCore/qmetaobject.h>
+
+#include "qvariantanimation_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QPropertyAnimationPrivate : public QVariantAnimationPrivate
+{
+ Q_DECLARE_PUBLIC(QPropertyAnimation)
+public:
+ QPropertyAnimationPrivate()
+ : target(0), propertyType(0), propertyIndex(0), hasMetaProperty(false)
+ {
+ }
+
+ void _q_targetDestroyed();
+
+ QObject *target;
+
+ //for the QProperty
+ QMetaProperty property;
+ int propertyType;
+ int propertyIndex;
+
+ int hasMetaProperty;
+ QByteArray propertyName;
+ void updateProperty(const QVariant &);
+ void updateMetaProperty();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/corelib/animation/qsequentialanimationgroup.cpp b/src/corelib/animation/qsequentialanimationgroup.cpp
new file mode 100644
index 0000000..14814a7
--- /dev/null
+++ b/src/corelib/animation/qsequentialanimationgroup.cpp
@@ -0,0 +1,594 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \class QSequentialAnimationGroup
+ \brief The QSequentialAnimationGroup class provides a sequential group of animations.
+ \since 4.6
+ \ingroup animation
+
+ QSequentialAnimationGroup is a QAnimationGroup that runs its
+ animations in sequence, i.e., it starts one animation after
+ another has finished playing. The animations are played in the
+ order they are added to the group (using
+ \l{QAnimationGroup::}{addAnimation()} or
+ \l{QAnimationGroup::}{insertAnimationAt()}). The animation group
+ finishes when its last animation has finished.
+
+ At each moment there is at most one animation that is active in
+ the group; it is returned by currentAnimation(). An empty group
+ has no current animation.
+
+ A sequential animation group can be treated as any other
+ animation, i.e., it can be started, stopped, and added to other
+ groups. You can also call addPause() or insertPauseAt() to add a
+ pause to a sequential animation group.
+
+ \code
+ QSequentialAnimationGroup group;
+
+ group.addAnimation(anim1);
+ group.addAnimation(anim2);
+
+ group.start();
+ \endcode
+
+ In this example, \c anim1 and \c anim2 are two already set up
+ \l{QPropertyAnimation}s.
+
+ \sa QAnimationGroup, QAbstractAnimation, {The Animation Framework}
+*/
+
+#ifndef QT_NO_ANIMATION
+
+#include "qsequentialanimationgroup.h"
+#include "qsequentialanimationgroup_p.h"
+
+#include "qpauseanimation.h"
+
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+
+
+bool QSequentialAnimationGroupPrivate::atEnd() const
+{
+ // we try to detect if we're at the end of the group
+ //this is true if the following conditions are true:
+ // 1. we're in the last loop
+ // 2. the direction is forward
+ // 3. the current animation is the last one
+ // 4. the current animation has reached its end
+ const int animTotalCurrentTime = QAbstractAnimationPrivate::get(currentAnimation)->totalCurrentTime;
+ return (currentLoop == loopCount - 1
+ && direction == QAbstractAnimation::Forward
+ && currentAnimation == animations.last()
+ && animTotalCurrentTime == animationActualTotalDuration(currentAnimationIndex));
+}
+
+int QSequentialAnimationGroupPrivate::animationActualTotalDuration(int index) const
+{
+ QAbstractAnimation *anim = animations.at(index);
+ int ret = anim->totalDuration();
+ if (ret == -1 && actualDuration.size() > index)
+ ret = actualDuration.at(index); //we can try the actual duration there
+ return ret;
+}
+
+QSequentialAnimationGroupPrivate::AnimationIndex QSequentialAnimationGroupPrivate::indexForTime(int msecs) const
+{
+ Q_Q(const QSequentialAnimationGroup);
+ Q_ASSERT(!animations.isEmpty());
+
+ AnimationIndex ret;
+ int duration = 0;
+
+ // in case duration is -1, currentLoop will always be 0
+ ret.timeOffset = currentLoop * q->duration();
+
+ for (int i = 0; i < animations.size(); ++i) {
+ duration = animationActualTotalDuration(i);
+
+ // 'animation' is the current animation if one of these reasons is true:
+ // 1. it's duration is undefined
+ // 2. it ends after msecs
+ // 3. it is the last animation (this can happen in case there is at least 1 uncontrolled animation)
+ // 4. it ends exactly in msecs and the direction is backwards
+ if (duration == -1 || msecs < (ret.timeOffset + duration)
+ || (msecs == (ret.timeOffset + duration) && direction == QAbstractAnimation::Backward)) {
+ ret.index = i;
+ return ret;
+ }
+
+ // 'animation' has a non-null defined duration and is not the one at time 'msecs'.
+ ret.timeOffset += duration;
+ }
+
+ // this can only happen when one of those conditions is true:
+ // 1. the duration of the group is undefined and we passed its actual duration
+ // 2. there are only 0-duration animations in the group
+ ret.timeOffset -= duration;
+ ret.index = animations.size() - 1;
+ return ret;
+}
+
+void QSequentialAnimationGroupPrivate::restart()
+{
+ // restarting the group by making the first/last animation the current one
+ if (direction == QAbstractAnimation::Forward) {
+ lastLoop = 0;
+ if (currentAnimationIndex == 0)
+ activateCurrentAnimation();
+ else
+ setCurrentAnimation(0);
+ } else { // direction == QAbstractAnimation::Backward
+ lastLoop = loopCount - 1;
+ int index = animations.size() - 1;
+ if (currentAnimationIndex == index)
+ activateCurrentAnimation();
+ else
+ setCurrentAnimation(index);
+ }
+}
+
+/*!
+ \internal
+ This manages advancing the execution of a group running forwards (time has gone forward),
+ which is the same behaviour for rewinding the execution of a group running backwards
+ (time has gone backward).
+*/
+void QSequentialAnimationGroupPrivate::advanceForwards(const AnimationIndex &newAnimationIndex)
+{
+ if (lastLoop < currentLoop) {
+ // we need to fast forward to the end
+ for (int i = currentAnimationIndex; i < animations.size(); ++i) {
+ QAbstractAnimation *anim = animations.at(i);
+ setCurrentAnimation(i, true);
+ anim->setCurrentTime(animationActualTotalDuration(i));
+ }
+ // this will make sure the current animation is reset to the beginning
+ if (animations.size() == 1)
+ // we need to force activation because setCurrentAnimation will have no effect
+ activateCurrentAnimation();
+ else
+ setCurrentAnimation(0, true);
+ }
+
+ // and now we need to fast forward from the current position to
+ for (int i = currentAnimationIndex; i < newAnimationIndex.index; ++i) { //### WRONG,
+ QAbstractAnimation *anim = animations.at(i);
+ setCurrentAnimation(i, true);
+ anim->setCurrentTime(animationActualTotalDuration(i));
+ }
+ // setting the new current animation will happen later
+}
+
+/*!
+ \internal
+ This manages rewinding the execution of a group running forwards (time has gone forward),
+ which is the same behaviour for advancing the execution of a group running backwards
+ (time has gone backward).
+*/
+void QSequentialAnimationGroupPrivate::rewindForwards(const AnimationIndex &newAnimationIndex)
+{
+ if (lastLoop > currentLoop) {
+ // we need to fast rewind to the beginning
+ for (int i = currentAnimationIndex; i >= 0 ; --i) {
+ QAbstractAnimation *anim = animations.at(i);
+ setCurrentAnimation(i, true);
+ anim->setCurrentTime(0);
+ }
+ // this will make sure the current animation is reset to the end
+ if (animations.size() == 1)
+ // we need to force activation because setCurrentAnimation will have no effect
+ activateCurrentAnimation();
+ else
+ setCurrentAnimation(animations.count() - 1, true);
+ }
+
+ // and now we need to fast rewind from the current position to
+ for (int i = currentAnimationIndex; i > newAnimationIndex.index; --i) {
+ QAbstractAnimation *anim = animations.at(i);
+ setCurrentAnimation(i, true);
+ anim->setCurrentTime(0);
+ }
+ // setting the new current animation will happen later
+}
+
+/*!
+ \fn QSequentialAnimationGroup::currentAnimationChanged(QAbstractAnimation *current)
+
+ QSequentialAnimationGroup emits this signal when currentAnimation
+ has been changed. \a current is the current animation.
+
+ \sa currentAnimation()
+*/
+
+
+/*!
+ Constructs a QSequentialAnimationGroup.
+ \a parent is passed to QObject's constructor.
+*/
+QSequentialAnimationGroup::QSequentialAnimationGroup(QObject *parent)
+ : QAnimationGroup(*new QSequentialAnimationGroupPrivate, parent)
+{
+}
+
+/*!
+ \internal
+*/
+QSequentialAnimationGroup::QSequentialAnimationGroup(QSequentialAnimationGroupPrivate &dd,
+ QObject *parent)
+ : QAnimationGroup(dd, parent)
+{
+}
+
+/*!
+ Destroys the animation group. It will also destroy all its animations.
+*/
+QSequentialAnimationGroup::~QSequentialAnimationGroup()
+{
+}
+
+/*!
+ Adds a pause of \a msecs to this animation group.
+ The pause is considered as a special type of animation, thus count() will be
+ increased by one.
+ \sa insertPauseAt(), QAnimationGroup::addAnimation()
+*/
+QPauseAnimation *QSequentialAnimationGroup::addPause(int msecs)
+{
+ QPauseAnimation *pause = new QPauseAnimation(msecs);
+ addAnimation(pause);
+ return pause;
+}
+
+/*!
+ Inserts a pause of \a msecs milliseconds at \a index in this animation
+ group.
+
+ \sa addPause(), QAnimationGroup::insertAnimationAt()
+*/
+QPauseAnimation *QSequentialAnimationGroup::insertPauseAt(int index, int msecs)
+{
+ Q_D(const QSequentialAnimationGroup);
+
+ if (index < 0 || index > d->animations.size()) {
+ qWarning("QSequentialAnimationGroup::insertPauseAt: index is out of bounds");
+ return 0;
+ }
+
+ QPauseAnimation *pause = new QPauseAnimation(msecs);
+ insertAnimationAt(index, pause);
+ return pause;
+}
+
+
+/*!
+ \property QSequentialAnimationGroup::currentAnimation
+ Returns the animation in the current time.
+
+ \sa currentAnimationChanged()
+*/
+QAbstractAnimation *QSequentialAnimationGroup::currentAnimation() const
+{
+ Q_D(const QSequentialAnimationGroup);
+ return d->currentAnimation;
+}
+
+/*!
+ \reimp
+*/
+int QSequentialAnimationGroup::duration() const
+{
+ Q_D(const QSequentialAnimationGroup);
+ int ret = 0;
+
+ for (int i = 0; i < d->animations.size(); ++i) {
+ QAbstractAnimation *animation = d->animations.at(i);
+ const int currentDuration = animation->totalDuration();
+ if (currentDuration == -1)
+ return -1; // Undetermined length
+
+ ret += currentDuration;
+ }
+
+ return ret;
+}
+
+/*!
+ \reimp
+*/
+void QSequentialAnimationGroup::updateCurrentTime(int msecs)
+{
+ Q_D(QSequentialAnimationGroup);
+ if (!d->currentAnimation)
+ return;
+
+ const QSequentialAnimationGroupPrivate::AnimationIndex newAnimationIndex = d->indexForTime(msecs);
+
+ // remove unneeded animations from actualDuration list
+ while (newAnimationIndex.index < d->actualDuration.size())
+ d->actualDuration.removeLast();
+
+ // newAnimationIndex.index is the new current animation
+ if (d->lastLoop < d->currentLoop
+ || (d->lastLoop == d->currentLoop && d->currentAnimationIndex < newAnimationIndex.index)) {
+ // advancing with forward direction is the same as rewinding with backwards direction
+ d->advanceForwards(newAnimationIndex);
+ } else if (d->lastLoop > d->currentLoop
+ || (d->lastLoop == d->currentLoop && d->currentAnimationIndex > newAnimationIndex.index)) {
+ // rewinding with forward direction is the same as advancing with backwards direction
+ d->rewindForwards(newAnimationIndex);
+ }
+
+ d->setCurrentAnimation(newAnimationIndex.index);
+
+ const int newCurrentTime = msecs - newAnimationIndex.timeOffset;
+
+ if (d->currentAnimation) {
+ d->currentAnimation->setCurrentTime(newCurrentTime);
+ if (d->atEnd()) {
+ //we make sure that we don't exceed the duration here
+ d->currentTime += QAbstractAnimationPrivate::get(d->currentAnimation)->totalCurrentTime - newCurrentTime;
+ stop();
+ }
+ } else {
+ //the only case where currentAnimation could be null
+ //is when all animations have been removed
+ Q_ASSERT(d->animations.isEmpty());
+ d->currentTime = 0;
+ stop();
+ }
+
+ d->lastLoop = d->currentLoop;
+}
+
+/*!
+ \reimp
+*/
+void QSequentialAnimationGroup::updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+{
+ Q_D(QSequentialAnimationGroup);
+ QAnimationGroup::updateState(oldState, newState);
+
+ if (!d->currentAnimation)
+ return;
+
+ switch (newState) {
+ case Stopped:
+ d->currentAnimation->stop();
+ break;
+ case Paused:
+ if (oldState == d->currentAnimation->state()
+ && oldState == QSequentialAnimationGroup::Running) {
+ d->currentAnimation->pause();
+ }
+ else
+ d->restart();
+ break;
+ case Running:
+ if (oldState == d->currentAnimation->state()
+ && oldState == QSequentialAnimationGroup::Paused)
+ d->currentAnimation->start();
+ else
+ d->restart();
+ break;
+ }
+}
+
+/*!
+ \reimp
+*/
+void QSequentialAnimationGroup::updateDirection(QAbstractAnimation::Direction direction)
+{
+ Q_D(QSequentialAnimationGroup);
+ // we need to update the direction of the current animation
+ if (state() != Stopped && d->currentAnimation)
+ d->currentAnimation->setDirection(direction);
+}
+
+/*!
+ \reimp
+*/
+bool QSequentialAnimationGroup::event(QEvent *event)
+{
+ return QAnimationGroup::event(event);
+}
+
+void QSequentialAnimationGroupPrivate::setCurrentAnimation(int index, bool intermediate)
+{
+ Q_Q(QSequentialAnimationGroup);
+
+ index = qMin(index, animations.count() - 1);
+
+ if (index == -1) {
+ Q_ASSERT(animations.isEmpty());
+ currentAnimationIndex = -1;
+ currentAnimation = 0;
+ return;
+ }
+
+ // need these two checks below because this func can be called after the current animation
+ // has been removed
+ if (index == currentAnimationIndex && animations.at(index) == currentAnimation)
+ return;
+
+ // stop the old current animation
+ if (currentAnimation)
+ currentAnimation->stop();
+
+ currentAnimation = animations.at(index);
+ currentAnimationIndex = index;
+
+ emit q->currentAnimationChanged(currentAnimation);
+
+ activateCurrentAnimation(intermediate);
+}
+
+void QSequentialAnimationGroupPrivate::activateCurrentAnimation(bool intermediate)
+{
+ Q_Q(QSequentialAnimationGroup);
+
+ if (!currentAnimation)
+ return;
+
+ if (state == QSequentialAnimationGroup::Stopped)
+ return;
+
+ currentAnimation->stop();
+
+ // we ensure the direction is consistent with the group's direction
+ currentAnimation->setDirection(direction);
+
+ // connects to the finish signal of uncontrolled animations
+ if (currentAnimation->totalDuration() == -1)
+ QObject::connect(currentAnimation, SIGNAL(finished()), q, SLOT(_q_uncontrolledAnimationFinished()));
+
+ currentAnimation->start();
+ if (!intermediate && state == QSequentialAnimationGroup::Paused)
+ currentAnimation->pause();
+}
+
+void QSequentialAnimationGroupPrivate::_q_uncontrolledAnimationFinished()
+{
+ Q_Q(QSequentialAnimationGroup);
+ Q_ASSERT(qobject_cast<QAbstractAnimation *>(q->sender()) == currentAnimation);
+
+ // we trust the duration returned by the animation
+ while (actualDuration.size() < (currentAnimationIndex + 1))
+ actualDuration.append(-1);
+ actualDuration[currentAnimationIndex] = currentAnimation->currentTime();
+
+ QObject::disconnect(currentAnimation, SIGNAL(finished()), q, SLOT(_q_uncontrolledAnimationFinished()));
+
+ if ((direction == QAbstractAnimation::Forward && currentAnimation == animations.last())
+ || (direction == QAbstractAnimation::Backward && currentAnimationIndex == 0)) {
+ // we don't handle looping of a group with undefined duration
+ q->stop();
+ } else if (direction == QAbstractAnimation::Forward) {
+ // set the current animation to be the next one
+ setCurrentAnimation(currentAnimationIndex + 1);
+ } else {
+ // set the current animation to be the previous one
+ setCurrentAnimation(currentAnimationIndex - 1);
+ }
+}
+
+/*!
+ \internal
+ This method is called whenever an animation is added to
+ the group at index \a index.
+ Note: We only support insertion after the current animation
+*/
+void QSequentialAnimationGroupPrivate::animationInsertedAt(int index)
+{
+ if (currentAnimation == 0)
+ setCurrentAnimation(0); // initialize the current animation
+
+ if (currentAnimationIndex == index
+ && currentAnimation->currentTime() == 0 && currentAnimation->currentLoop() == 0) {
+ //in this case we simply insert an animation before the current one has actually started
+ setCurrentAnimation(index);
+ }
+
+ //we update currentAnimationIndex in case it has changed (the animation pointer is still valid)
+ currentAnimationIndex = animations.indexOf(currentAnimation);
+
+ if (index < currentAnimationIndex || currentLoop != 0) {
+ qWarning("QSequentialGroup::insertAnimationAt only supports to add animations after the current one.");
+ return; //we're not affected because it is added after the current one
+ }
+}
+
+/*!
+ \internal
+ This method is called whenever an animation is removed from
+ the group at index \a index. The animation is no more listed when this
+ method is called.
+*/
+void QSequentialAnimationGroupPrivate::animationRemovedAt(int index)
+{
+ Q_Q(QSequentialAnimationGroup);
+ QAnimationGroupPrivate::animationRemovedAt(index);
+
+ Q_ASSERT(currentAnimation); // currentAnimation should always be set
+
+ if (actualDuration.size() > index)
+ actualDuration.removeAt(index);
+
+ const int currentIndex = animations.indexOf(currentAnimation);
+ if (currentIndex == -1) {
+ //we're removing the current animation, let's update it to another one
+ if (index < animations.count())
+ setCurrentAnimation(index); //let's try to take the next one
+ else if (index > 0)
+ setCurrentAnimation(index - 1);
+ else// case all animations were removed
+ setCurrentAnimation(-1);
+ } else if (currentAnimationIndex > index) {
+ currentAnimationIndex--;
+ }
+
+ // duration of the previous animations up to the current animation
+ currentTime = 0;
+ for (int i = 0; i < currentAnimationIndex; ++i) {
+ const int current = animationActualTotalDuration(i);
+ currentTime += current;
+ }
+
+ if (currentIndex != -1) {
+ //the current animation is not the one being removed
+ //so we add its current time to the current time of this group
+ currentTime += QAbstractAnimationPrivate::get(currentAnimation)->totalCurrentTime;
+ }
+
+ //let's also update the total current time
+ totalCurrentTime = currentTime + loopCount * q->duration();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qsequentialanimationgroup.cpp"
+
+#endif //QT_NO_ANIMATION
diff --git a/src/corelib/animation/qsequentialanimationgroup.h b/src/corelib/animation/qsequentialanimationgroup.h
new file mode 100644
index 0000000..4701a76
--- /dev/null
+++ b/src/corelib/animation/qsequentialanimationgroup.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSEQUENTIALANIMATIONGROUP_H
+#define QSEQUENTIALANIMATIONGROUP_H
+
+#include <QtCore/qanimationgroup.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+#ifndef QT_NO_ANIMATION
+
+class QPauseAnimation;
+class QSequentialAnimationGroupPrivate;
+
+class Q_CORE_EXPORT QSequentialAnimationGroup : public QAnimationGroup
+{
+ Q_OBJECT
+ Q_PROPERTY(QAbstractAnimation* currentAnimation READ currentAnimation NOTIFY currentAnimationChanged)
+
+public:
+ QSequentialAnimationGroup(QObject *parent = 0);
+ ~QSequentialAnimationGroup();
+
+ QPauseAnimation *addPause(int msecs);
+ QPauseAnimation *insertPauseAt(int index, int msecs);
+
+ QAbstractAnimation *currentAnimation() const;
+ int duration() const;
+
+Q_SIGNALS:
+ void currentAnimationChanged(QAbstractAnimation *current);
+
+protected:
+ QSequentialAnimationGroup(QSequentialAnimationGroupPrivate &dd, QObject *parent);
+ bool event(QEvent *event);
+
+ void updateCurrentTime(int msecs);
+ void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState);
+ void updateDirection(QAbstractAnimation::Direction direction);
+
+private:
+ Q_DISABLE_COPY(QSequentialAnimationGroup)
+ Q_DECLARE_PRIVATE(QSequentialAnimationGroup)
+ Q_PRIVATE_SLOT(d_func(), void _q_uncontrolledAnimationFinished())
+};
+
+#endif //QT_NO_ANIMATION
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif //QSEQUENTIALANIMATIONGROUP_H
diff --git a/src/corelib/animation/qsequentialanimationgroup_p.h b/src/corelib/animation/qsequentialanimationgroup_p.h
new file mode 100644
index 0000000..3ac90f8
--- /dev/null
+++ b/src/corelib/animation/qsequentialanimationgroup_p.h
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSEQUENTIALANIMATIONGROUP_P_H
+#define QSEQUENTIALANIMATIONGROUP_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of QIODevice. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qsequentialanimationgroup.h"
+#include "qanimationgroup_p.h"
+
+
+QT_BEGIN_NAMESPACE
+
+class QSequentialAnimationGroupPrivate : public QAnimationGroupPrivate
+{
+ Q_DECLARE_PUBLIC(QSequentialAnimationGroup)
+public:
+ QSequentialAnimationGroupPrivate()
+ : currentAnimation(0), currentAnimationIndex(-1), lastLoop(0)
+ { }
+
+
+ struct AnimationIndex
+ {
+ AnimationIndex() : index(0), timeOffset(0) {}
+ // index points to the animation at timeOffset, skipping 0 duration animations.
+ // Note that the index semantic is slightly different depending on the direction.
+ int index; // the index of the animation in timeOffset
+ int timeOffset; // time offset when the animation at index starts.
+ };
+
+ int animationActualTotalDuration(int index) const;
+ AnimationIndex indexForTime(int msecs) const;
+
+ void setCurrentAnimation(int index, bool intermediate = false);
+ void activateCurrentAnimation(bool intermediate = false);
+
+ void animationInsertedAt(int index);
+ void animationRemovedAt(int index);
+
+ bool atEnd() const;
+
+ QAbstractAnimation *currentAnimation;
+ int currentAnimationIndex;
+
+ // this is the actual duration of uncontrolled animations
+ // it helps seeking and even going forward
+ QList<int> actualDuration;
+
+ void restart();
+ int lastLoop;
+
+ // handle time changes
+ void rewindForwards(const AnimationIndex &newAnimationIndex);
+ void advanceForwards(const AnimationIndex &newAnimationIndex);
+
+ // private slot
+ void _q_uncontrolledAnimationFinished();
+};
+
+QT_END_NAMESPACE
+
+#endif //QSEQUENTIALANIMATIONGROUP_P_H
diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp
new file mode 100644
index 0000000..4542a86
--- /dev/null
+++ b/src/corelib/animation/qvariantanimation.cpp
@@ -0,0 +1,653 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT_NO_ANIMATION
+
+#include "qvariantanimation.h"
+#include "qvariantanimation_p.h"
+
+#include <QtCore/QRect>
+#include <QtCore/QLineF>
+#include <QtCore/QLine>
+#include <QtCore/QReadWriteLock>
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QVariantAnimation
+ \ingroup animation
+ \brief The QVariantAnimation class provides an abstract base class for animations.
+ \since 4.6
+
+ This class is part of \l{The Animation Framework}. It serves as a
+ base class for property and item animations, with functions for
+ shared functionality.
+
+ QVariantAnimation cannot be used directly as it is an abstract
+ class; it has a pure virtual method called updateCurrentValue().
+ The class performs interpolation over
+ \l{QVariant}s, but leaves using the interpolated values to its
+ subclasses. Currently, Qt provides QPropertyAnimation, which
+ animates Qt \l{Qt's Property System}{properties}. See the
+ QPropertyAnimation class description if you wish to animate such
+ properties.
+
+ You can then set start and end values for the property by calling
+ setStartValue() and setEndValue(), and finally call start() to
+ start the animation. QVariantAnimation will interpolate the
+ property of the target object and emit valueChanged(). To react to
+ a change in the current value you have to reimplement the
+ updateCurrentValue() virtual function.
+
+ It is also possible to set values at specified steps situated
+ between the start and end value. The interpolation will then
+ touch these points at the specified steps. Note that the start and
+ end values are defined as the key values at 0.0 and 1.0.
+
+ There are two ways to affect how QVariantAnimation interpolates
+ the values. You can set an easing curve by calling
+ setEasingCurve(), and configure the duration by calling
+ setDuration(). You can change how the QVariants are interpolated
+ by creating a subclass of QVariantAnimation, and reimplementing
+ the virtual interpolated() function.
+
+ Subclassing QVariantAnimation can be an alternative if you have
+ \l{QVariant}s that you do not wish to declare as Qt properties.
+ Note, however, that you in most cases will be better off declaring
+ your QVariant as a property.
+
+ Not all QVariant types are supported. Below is a list of currently
+ supported QVariant types:
+
+ \list
+ \o \l{QMetaType::}{Int}
+ \o \l{QMetaType::}{Double}
+ \o \l{QMetaType::}{Float}
+ \o \l{QMetaType::}{QLine}
+ \o \l{QMetaType::}{QLineF}
+ \o \l{QMetaType::}{QPoint}
+ \o \l{QMetaType::}{QSize}
+ \o \l{QMetaType::}{QSizeF}
+ \o \l{QMetaType::}{QRect}
+ \o \l{QMetaType::}{QRectF}
+ \endlist
+
+ If you need to interpolate other variant types, including custom
+ types, you have to implement interpolation for these yourself.
+ You do this by reimplementing interpolated(), which returns
+ interpolation values for the value being interpolated.
+
+ \omit We need some snippets around here. \endomit
+
+ \sa QPropertyAnimation, QAbstractAnimation, {The Animation Framework}
+*/
+
+/*!
+ \fn void QVariantAnimation::valueChanged(const QVariant &value)
+
+ QVariantAnimation emits this signal whenever the current \a value changes.
+
+ \sa currentValue, startValue, endValue
+*/
+
+/*!
+ \fn void QVariantAnimation::updateCurrentValue(const QVariant &value) = 0;
+
+ This pure virtual function is called every time the animation's current
+ value changes. The \a value argument is the new current value.
+
+ \sa currentValue
+*/
+
+
+static bool animationValueLessThan(const QVariantAnimation::KeyValue &p1, const QVariantAnimation::KeyValue &p2)
+{
+ return p1.first < p2.first;
+}
+
+template<> Q_INLINE_TEMPLATE QRect _q_interpolate(const QRect &f, const QRect &t, qreal progress)
+{
+ QRect ret;
+ ret.setCoords(_q_interpolate(f.left(), t.left(), progress),
+ _q_interpolate(f.top(), t.top(), progress),
+ _q_interpolate(f.right(), t.right(), progress),
+ _q_interpolate(f.bottom(), t.bottom(), progress));
+ return ret;
+}
+
+template<> Q_INLINE_TEMPLATE QRectF _q_interpolate(const QRectF &f, const QRectF &t, qreal progress)
+{
+ qreal x1, y1, w1, h1;
+ f.getRect(&x1, &y1, &w1, &h1);
+ qreal x2, y2, w2, h2;
+ t.getRect(&x2, &y2, &w2, &h2);
+ return QRectF(_q_interpolate(x1, x2, progress), _q_interpolate(y1, y2, progress),
+ _q_interpolate(w1, w2, progress), _q_interpolate(h1, h2, progress));
+}
+
+template<> Q_INLINE_TEMPLATE QLine _q_interpolate(const QLine &f, const QLine &t, qreal progress)
+{
+ return QLine( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress));
+}
+
+template<> Q_INLINE_TEMPLATE QLineF _q_interpolate(const QLineF &f, const QLineF &t, qreal progress)
+{
+ return QLineF( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress));
+}
+
+void QVariantAnimationPrivate::convertValues(int t)
+{
+ //this ensures that all the keyValues are of type t
+ for (int i = 0; i < keyValues.count(); ++i) {
+ QVariantAnimation::KeyValue &pair = keyValues[i];
+ if (pair.second.userType() != t)
+ pair.second.convert(static_cast<QVariant::Type>(t));
+ }
+ interpolator = 0; // if the type changed we need to update the interpolator
+}
+
+/*!
+ \internal
+ The goal of this function is to update the currentInterval member. As a consequence, we also
+ need to update the currentValue.
+ Set \a force to true to always recalculate the interval.
+*/
+void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/)
+{
+ // can't interpolate if we have only 1 key value
+ if (keyValues.count() <= 1)
+ return;
+
+ const qreal progress = easing.valueForProgress(((duration == 0) ? qreal(1) : qreal(currentTime) / qreal(duration)));
+
+ if (force || progress < currentInterval.start.first || progress > currentInterval.end.first) {
+ //let's update currentInterval
+ QVariantAnimation::KeyValues::const_iterator itStart = qLowerBound(keyValues.constBegin(),
+ keyValues.constEnd(),
+ qMakePair(progress, QVariant()),
+ animationValueLessThan);
+ QVariantAnimation::KeyValues::const_iterator itEnd = itStart;
+
+ // If we are at the end we should continue to use the last keyValues in case of extrapolation (progress > 1.0).
+ // This is because the easing function can return a value slightly outside the range [0, 1]
+ if (itStart != keyValues.constEnd()) {
+ // this can't happen because we always prepend the default start value there
+ if (itStart == keyValues.constBegin()) {
+ ++itEnd;
+ } else {
+ --itStart;
+ }
+
+ // update all the values of the currentInterval
+ currentInterval.start = *itStart;
+ currentInterval.end = *itEnd;
+ }
+ }
+ setCurrentValueForProgress(progress);
+}
+
+void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress)
+{
+ Q_Q(QVariantAnimation);
+
+ const qreal startProgress = currentInterval.start.first;
+ const qreal endProgress = currentInterval.end.first;
+ const qreal localProgress = (progress - startProgress) / (endProgress - startProgress);
+
+ QVariant ret = q->interpolated(currentInterval.start.second,
+ currentInterval.end.second,
+ localProgress);
+ qSwap(currentValue, ret);
+ q->updateCurrentValue(currentValue);
+ if ((connectedSignals & changedSignalMask) && currentValue != ret) {
+ //the value has changed
+ emit q->valueChanged(currentValue);
+ }
+}
+
+QVariant QVariantAnimationPrivate::valueAt(qreal step) const
+{
+ QVariantAnimation::KeyValues::const_iterator result =
+ qBinaryFind(keyValues.begin(), keyValues.end(), qMakePair(step, QVariant()), animationValueLessThan);
+ if (result != keyValues.constEnd())
+ return result->second;
+
+ return QVariant();
+}
+
+void QVariantAnimationPrivate::setValueAt(qreal step, const QVariant &value)
+{
+ if (step < qreal(0.0) || step > qreal(1.0)) {
+ qWarning("QVariantAnimation::setValueAt: invalid step = %f", step);
+ return;
+ }
+
+ QVariantAnimation::KeyValue pair(step, value);
+
+ QVariantAnimation::KeyValues::iterator result = qLowerBound(keyValues.begin(), keyValues.end(), pair, animationValueLessThan);
+ if (result == keyValues.end() || result->first != step) {
+ keyValues.insert(result, pair);
+ } else {
+ if (value.isValid())
+ result->second = value; // replaces the previous value
+ else if (step == 0 && !hasStartValue && defaultStartValue.isValid())
+ result->second = defaultStartValue; // resets to the default start value
+ else
+ keyValues.erase(result); // removes the previous value
+ }
+
+ recalculateCurrentInterval(/*force=*/true);
+}
+
+void QVariantAnimationPrivate::setDefaultStartValue(const QVariant &value)
+{
+ defaultStartValue = value;
+ if (!hasStartValue)
+ setValueAt(0, value);
+}
+
+/*!
+ Construct a QVariantAnimation object. \a parent is passed to QAbstractAnimation's
+ constructor.
+*/
+QVariantAnimation::QVariantAnimation(QObject *parent) : QAbstractAnimation(*new QVariantAnimationPrivate, parent)
+{
+ d_func()->init();
+}
+
+/*!
+ \internal
+*/
+QVariantAnimation::QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent) : QAbstractAnimation(dd, parent)
+{
+ d_func()->init();
+}
+
+/*!
+ Destroys the animation.
+*/
+QVariantAnimation::~QVariantAnimation()
+{
+}
+
+/*!
+ \property QVariantAnimation::easingCurve
+ \brief the easing curve of the animation
+
+ This property defines the easing curve of the animation. By
+ default, a linear easing curve is used, resulting in linear
+ interpolation. Other curves are provided, for instance,
+ QEasingCurve::InCirc, which provides a circular entry curve.
+ Another example is QEasingCurve::InOutElastic, which provides an
+ elastic effect on the values of the interpolated variant.
+
+ The easing curve is used with the interpolator, the interpolated()
+ virtual function, the animation's duration, and iterationCount, to
+ control how the current value changes as the animation progresses.
+*/
+QEasingCurve QVariantAnimation::easingCurve() const
+{
+ Q_D(const QVariantAnimation);
+ return d->easing;
+}
+
+void QVariantAnimation::setEasingCurve(const QEasingCurve &easing)
+{
+ Q_D(QVariantAnimation);
+ d->easing = easing;
+ d->recalculateCurrentInterval();
+}
+
+Q_GLOBAL_STATIC(QVector<QVariantAnimation::Interpolator>, registeredInterpolators)
+Q_GLOBAL_STATIC(QReadWriteLock, registeredInterpolatorsLock)
+
+/*!
+ \fn void qRegisterAnimationInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress))
+ \relates QVariantAnimation
+ \threadsafe
+
+ Registers a custom interpolator \a func for the template type \c{T}.
+ The interpolator has to be registered before the animation is constructed.
+ To unregister (and use the default interpolator) set \a func to 0.
+ */
+
+/*!
+ \internal
+ \typedef QVariantAnimation::Interpolator
+
+ This is a typedef for a pointer to a function with the following
+ signature:
+ \code
+ QVariant myInterpolator(const QVariant &from, const QVariant &to, qreal progress);
+ \endcode
+
+*/
+
+/*! \internal
+ * Registers a custom interpolator \a func for the specific \a interpolationType.
+ * The interpolator has to be registered before the animation is constructed.
+ * To unregister (and use the default interpolator) set \a func to 0.
+ */
+void QVariantAnimation::registerInterpolator(QVariantAnimation::Interpolator func, int interpolationType)
+{
+ // will override any existing interpolators
+ QWriteLocker locker(registeredInterpolatorsLock());
+ if (int(interpolationType) >= registeredInterpolators()->count())
+ registeredInterpolators()->resize(int(interpolationType) + 1);
+ registeredInterpolators()->replace(interpolationType, func);
+}
+
+
+template<typename T> static inline QVariantAnimation::Interpolator castToInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress))
+{
+ return reinterpret_cast<QVariantAnimation::Interpolator>(func);
+}
+
+QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int interpolationType)
+{
+ QReadLocker locker(registeredInterpolatorsLock());
+ QVariantAnimation::Interpolator ret = 0;
+ if (interpolationType < registeredInterpolators()->count()) {
+ ret = registeredInterpolators()->at(interpolationType);
+ if (ret) return ret;
+ }
+
+ switch(interpolationType)
+ {
+ case QMetaType::Int:
+ return castToInterpolator(_q_interpolateVariant<int>);
+ case QMetaType::Double:
+ return castToInterpolator(_q_interpolateVariant<double>);
+ case QMetaType::Float:
+ return castToInterpolator(_q_interpolateVariant<float>);
+ case QMetaType::QLine:
+ return castToInterpolator(_q_interpolateVariant<QLine>);
+ case QMetaType::QLineF:
+ return castToInterpolator(_q_interpolateVariant<QLineF>);
+ case QMetaType::QPoint:
+ return castToInterpolator(_q_interpolateVariant<QPoint>);
+ case QMetaType::QPointF:
+ return castToInterpolator(_q_interpolateVariant<QPointF>);
+ case QMetaType::QSize:
+ return castToInterpolator(_q_interpolateVariant<QSize>);
+ case QMetaType::QSizeF:
+ return castToInterpolator(_q_interpolateVariant<QSizeF>);
+ case QMetaType::QRect:
+ return castToInterpolator(_q_interpolateVariant<QRect>);
+ case QMetaType::QRectF:
+ return castToInterpolator(_q_interpolateVariant<QRectF>);
+ default:
+ return 0; //this type is not handled
+ }
+}
+
+/*!
+ \property QVariantAnimation::duration
+ \brief the duration of the animation
+
+ This property describes the duration in milliseconds of the
+ animation. The default duration is 250 milliseconds.
+
+ \sa QAbstractAnimation::duration()
+ */
+int QVariantAnimation::duration() const
+{
+ Q_D(const QVariantAnimation);
+ return d->duration;
+}
+
+void QVariantAnimation::setDuration(int msecs)
+{
+ Q_D(QVariantAnimation);
+ if (msecs < 0) {
+ qWarning("QVariantAnimation::setDuration: cannot set a negative duration");
+ return;
+ }
+ if (d->duration == msecs)
+ return;
+ d->duration = msecs;
+ d->recalculateCurrentInterval();
+}
+
+/*!
+ \property QVariantAnimation::startValue
+ \brief the optional start value of the animation
+
+ This property describes the optional start value of the animation. If
+ omitted, or if a null QVariant is assigned as the start value, the
+ animation will use the current position of the end when the animation
+ is started.
+
+ \sa endValue
+*/
+QVariant QVariantAnimation::startValue() const
+{
+ return keyValueAt(0);
+}
+
+void QVariantAnimation::setStartValue(const QVariant &value)
+{
+ setKeyValueAt(0, value);
+}
+
+/*!
+ \property QVariantAnimation::endValue
+ \brief the end value of the animation
+
+ This property describes the end value of the animation.
+
+ \sa startValue
+ */
+QVariant QVariantAnimation::endValue() const
+{
+ return keyValueAt(1);
+}
+
+void QVariantAnimation::setEndValue(const QVariant &value)
+{
+ setKeyValueAt(1, value);
+}
+
+
+/*!
+ Returns the key frame value for the given \a step. The given \a step
+ must be in the range 0 to 1. If there is no KeyValue for \a step,
+ it returns an invalid QVariant.
+
+ \sa keyValues(), setKeyValueAt()
+*/
+QVariant QVariantAnimation::keyValueAt(qreal step) const
+{
+ Q_D(const QVariantAnimation);
+ if (step == 0 && !d->hasStartValue)
+ return QVariant(); //special case where we don't have an explicit startValue
+
+ return d->valueAt(step);
+}
+
+/*!
+ \typedef QVariantAnimation::KeyValue
+
+ This is a typedef for QPair<qreal, QVariant>.
+*/
+/*!
+ \typedef QVariantAnimation::KeyValues
+
+ This is a typedef for QVector<KeyValue>
+*/
+
+/*!
+ Creates a key frame at the given \a step with the given \a value.
+ The given \a step must be in the range 0 to 1.
+
+ \sa setKeyValues(), keyValueAt()
+*/
+void QVariantAnimation::setKeyValueAt(qreal step, const QVariant &value)
+{
+ Q_D(QVariantAnimation);
+ if (step == 0)
+ d->hasStartValue = value.isValid();
+ d->setValueAt(step, value);
+}
+
+/*!
+ Returns the key frames of this animation.
+
+ \sa keyValueAt(), setKeyValues()
+*/
+QVariantAnimation::KeyValues QVariantAnimation::keyValues() const
+{
+ Q_D(const QVariantAnimation);
+ QVariantAnimation::KeyValues ret = d->keyValues;
+ //in case we added the default start value, we remove it
+ if (!d->hasStartValue && !ret.isEmpty() && ret.at(0).first == 0)
+ ret.remove(0);
+ return ret;
+}
+
+/*!
+ Replaces the current set of key frames with the given \a keyValues.
+ the step of the key frames must be in the range 0 to 1.
+
+ \sa keyValues(), keyValueAt()
+*/
+void QVariantAnimation::setKeyValues(const KeyValues &keyValues)
+{
+ Q_D(QVariantAnimation);
+ d->keyValues = keyValues;
+ qSort(d->keyValues.begin(), d->keyValues.end(), animationValueLessThan);
+ d->hasStartValue = !d->keyValues.isEmpty() && d->keyValues.at(0).first == 0;
+ d->recalculateCurrentInterval(/*force=*/true);
+}
+
+/*!
+ \property QVariantAnimation::currentValue
+ \brief the current value of the animation.
+
+ This property describes the current value; an interpolated value
+ between the \l{startValue}{start value} and the \l{endValue}{end
+ value}, using the current time for progress. The value itself is
+ obtained from interpolated(), which is called repeatedly as the
+ animation is running.
+
+ QVariantAnimation calls the virtual updateCurrentValue() function
+ when the current value changes. This is particularly useful for
+ subclasses that need to track updates. For example,
+ QPropertyAnimation uses this function to animate Qt \l{Qt's
+ Property System}{properties}.
+
+ \sa startValue, endValue
+*/
+QVariant QVariantAnimation::currentValue() const
+{
+ Q_D(const QVariantAnimation);
+ if (!d->currentValue.isValid())
+ const_cast<QVariantAnimationPrivate*>(d)->recalculateCurrentInterval();
+ return d->currentValue;
+}
+
+/*!
+ \reimp
+ */
+bool QVariantAnimation::event(QEvent *event)
+{
+ return QAbstractAnimation::event(event);
+}
+
+/*!
+ \reimp
+*/
+void QVariantAnimation::updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+{
+ Q_UNUSED(oldState);
+ Q_UNUSED(newState);
+}
+
+/*!
+
+ This virtual function returns the linear interpolation between
+ variants \a from and \a to, at \a progress, usually a value
+ between 0 and 1. You can reimplement this function in a subclass
+ of QVariantAnimation to provide your own interpolation algorithm.
+
+ Note that in order for the interpolation to work with a
+ QEasingCurve that return a value smaller than 0 or larger than 1
+ (such as QEasingCurve::InBack) you should make sure that it can
+ extrapolate. If the semantic of the datatype does not allow
+ extrapolation this function should handle that gracefully.
+
+ You should call the QVariantAnimation implementation of this
+ function if you want your class to handle the types already
+ supported by Qt (see class QVariantAnimation description for a
+ list of supported types).
+
+ \sa QEasingCurve
+ */
+QVariant QVariantAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
+{
+ Q_D(const QVariantAnimation);
+ if (d->interpolator == 0) {
+ if (from.userType() == to.userType())
+ d->interpolator = QVariantAnimationPrivate::getInterpolator(from.userType());
+ if (d->interpolator == 0) //no interpolator found
+ return QVariant();
+ }
+
+ return d->interpolator(from.constData(), to.constData(), progress);
+}
+
+/*!
+ \reimp
+ */
+void QVariantAnimation::updateCurrentTime(int msecs)
+{
+ Q_D(QVariantAnimation);
+ Q_UNUSED(msecs);
+ d->recalculateCurrentInterval();
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qvariantanimation.cpp"
+
+#endif //QT_NO_ANIMATION
diff --git a/src/corelib/animation/qvariantanimation.h b/src/corelib/animation/qvariantanimation.h
new file mode 100644
index 0000000..3ae172f
--- /dev/null
+++ b/src/corelib/animation/qvariantanimation.h
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QANIMATION_H
+#define QANIMATION_H
+
+#include <QtCore/qeasingcurve.h>
+#include <QtCore/qabstractanimation.h>
+#include <QtCore/qvector.h>
+#include <QtCore/qvariant.h>
+#include <QtCore/qpair.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+#ifndef QT_NO_ANIMATION
+
+class QVariantAnimationPrivate;
+class Q_CORE_EXPORT QVariantAnimation : public QAbstractAnimation
+{
+ Q_OBJECT
+ Q_PROPERTY(QVariant startValue READ startValue WRITE setStartValue)
+ Q_PROPERTY(QVariant endValue READ endValue WRITE setEndValue)
+ Q_PROPERTY(QVariant currentValue READ currentValue NOTIFY currentValueChanged)
+ Q_PROPERTY(int duration READ duration WRITE setDuration)
+ Q_PROPERTY(QEasingCurve easingCurve READ easingCurve WRITE setEasingCurve)
+
+public:
+ typedef QPair<qreal, QVariant> KeyValue;
+ typedef QVector<KeyValue> KeyValues;
+
+ QVariantAnimation(QObject *parent = 0);
+ ~QVariantAnimation();
+
+ QVariant startValue() const;
+ void setStartValue(const QVariant &value);
+
+ QVariant endValue() const;
+ void setEndValue(const QVariant &value);
+
+ QVariant keyValueAt(qreal step) const;
+ void setKeyValueAt(qreal step, const QVariant &value);
+
+ KeyValues keyValues() const;
+ void setKeyValues(const KeyValues &values);
+
+ QVariant currentValue() const;
+
+ int duration() const;
+ void setDuration(int msecs);
+
+ QEasingCurve easingCurve() const;
+ void setEasingCurve(const QEasingCurve &easing);
+
+ typedef QVariant (*Interpolator)(const void *from, const void *to, qreal progress);
+
+Q_SIGNALS:
+ void valueChanged(const QVariant &value);
+
+protected:
+ QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent = 0);
+ bool event(QEvent *event);
+
+ void updateCurrentTime(int msecs);
+ void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState);
+
+ virtual void updateCurrentValue(const QVariant &value) = 0;
+ virtual QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
+
+private:
+ template <typename T> friend void qRegisterAnimationInterpolator(QVariant (*func)(const T &, const T &, qreal));
+ static void registerInterpolator(Interpolator func, int interpolationType);
+
+ Q_DISABLE_COPY(QVariantAnimation)
+ Q_DECLARE_PRIVATE(QVariantAnimation)
+};
+
+template <typename T>
+void qRegisterAnimationInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) {
+ QVariantAnimation::registerInterpolator(reinterpret_cast<QVariantAnimation::Interpolator>(func), qMetaTypeId<T>());
+}
+
+#endif //QT_NO_ANIMATION
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif //QANIMATION_H
diff --git a/src/corelib/animation/qvariantanimation_p.h b/src/corelib/animation/qvariantanimation_p.h
new file mode 100644
index 0000000..0d296db
--- /dev/null
+++ b/src/corelib/animation/qvariantanimation_p.h
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QANIMATION_P_H
+#define QANIMATION_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of QIODevice. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qvariantanimation.h"
+#include <QtCore/qeasingcurve.h>
+#include <QtCore/qmetaobject.h>
+#include <QtCore/qvector.h>
+
+#include "qabstractanimation_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QVariantAnimationPrivate : public QAbstractAnimationPrivate
+{
+ Q_DECLARE_PUBLIC(QVariantAnimation)
+public:
+
+ QVariantAnimationPrivate() : duration(250), hasStartValue(false)
+ {
+ }
+
+ void init()
+ {
+ //we keep the mask so that we emit valueChanged only when needed (for performance reasons)
+ changedSignalMask = (1 << q_func()->metaObject()->indexOfSignal("valueChanged(QVariant)"));
+ currentInterval.start.first = currentInterval.end.first = 2; //will force the initial refresh
+ interpolator = 0;
+ }
+
+ static QVariantAnimationPrivate *get(QVariantAnimation *q)
+ {
+ return q->d_func();
+ }
+
+ void setDefaultStartValue(const QVariant &value);
+
+ int duration;
+ QEasingCurve easing;
+
+ QVariantAnimation::KeyValues keyValues;
+ QVariant currentValue;
+ QVariant defaultStartValue;
+ bool hasStartValue;
+
+ //this is used to keep track of the KeyValue interval in which we currently are
+ struct
+ {
+ QVariantAnimation::KeyValue start, end;
+ } currentInterval;
+
+ mutable QVariantAnimation::Interpolator interpolator;
+
+ quint32 changedSignalMask;
+
+ void setCurrentValueForProgress(const qreal progress);
+ void recalculateCurrentInterval(bool force=false);
+ void setValueAt(qreal, const QVariant &);
+ QVariant valueAt(qreal step) const;
+ void convertValues(int t);
+
+ static QVariantAnimation::Interpolator getInterpolator(int interpolationType);
+};
+
+//this should make the interpolation faster
+template<typename T> inline T _q_interpolate(const T &f, const T &t, qreal progress)
+{
+ return T(f + (t - f) * progress);
+}
+
+template<typename T > inline QVariant _q_interpolateVariant(const T &from, const T &to, qreal progress)
+{
+ return _q_interpolate(from, to, progress);
+}
+
+
+QT_END_NAMESPACE
+
+#endif //QANIMATION_P_H
diff --git a/src/corelib/concurrent/qfuturewatcher_p.h b/src/corelib/concurrent/qfuturewatcher_p.h
index 324839d..d53a1bd 100644
--- a/src/corelib/concurrent/qfuturewatcher_p.h
+++ b/src/corelib/concurrent/qfuturewatcher_p.h
@@ -63,8 +63,8 @@
QT_BEGIN_NAMESPACE
class QFutureWatcherBase;
-class Q_CORE_EXPORT QFutureWatcherBasePrivate : public QObjectPrivate,
- public QFutureCallOutInterface
+class QFutureWatcherBasePrivate : public QObjectPrivate,
+ public QFutureCallOutInterface
{
Q_DECLARE_PUBLIC(QFutureWatcherBase)
diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro
index f99d57f..db51d43 100644
--- a/src/corelib/corelib.pro
+++ b/src/corelib/corelib.pro
@@ -5,6 +5,7 @@ DEFINES += QT_BUILD_CORE_LIB QT_NO_USING_NAMESPACE
win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x67000000
include(../qbase.pri)
+include(animation/animation.pri)
include(arch/arch.pri)
include(concurrent/concurrent.pri)
include(global/global.pri)
@@ -14,6 +15,7 @@ include(io/io.pri)
include(plugin/plugin.pri)
include(kernel/kernel.pri)
include(codecs/codecs.pri)
+include(statemachine/statemachine.pri)
include(xml/xml.pri)
mac|darwin:LIBS += -framework ApplicationServices
diff --git a/src/corelib/global/qfeatures.txt b/src/corelib/global/qfeatures.txt
index 5d63e46..23ec7b0 100644
--- a/src/corelib/global/qfeatures.txt
+++ b/src/corelib/global/qfeatures.txt
@@ -1157,6 +1157,14 @@ Requires: PROPERTIES
Name: Accessibility
SeeAlso: ???
+Feature: ANIMATION
+Description: Provides a framework for animations.
+Section: Utilities
+Requires: PROPERTIES
+Name: Animation
+SeeAlso: ???
+
+
# SVG
Feature: SVG
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index ce98ec4..564e6a5 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -1985,7 +1985,7 @@ void qt_message_output(QtMsgType msgType, const char *buf)
mac_default_handler(buf);
#elif defined(Q_OS_WINCE)
QString fstr = QString::fromLatin1(buf);
- fstr += QLatin1String("\n");
+ fstr += QLatin1Char('\n');
OutputDebugString(reinterpret_cast<const wchar_t *> (fstr.utf16()));
#else
fprintf(stderr, "%s\n", buf);
@@ -2243,7 +2243,7 @@ bool qputenv(const char *varName, const QByteArray& value)
return _putenv_s(varName, value.constData()) == 0;
#else
QByteArray buffer(varName);
- buffer += "=";
+ buffer += '=';
buffer += value;
return putenv(qstrdup(buffer.constData())) == 0;
#endif
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index 9b0fbe5..54121f6 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -85,11 +85,11 @@ public:
delete stream;
}
}
- inline QDebug &space() { stream->space = true; stream->ts << " "; return *this; }
+ inline QDebug &space() { stream->space = true; stream->ts << ' '; return *this; }
inline QDebug &nospace() { stream->space = false; return *this; }
- inline QDebug &maybeSpace() { if (stream->space) stream->ts << " "; return *this; }
+ inline QDebug &maybeSpace() { if (stream->space) stream->ts << ' '; return *this; }
- inline QDebug &operator<<(QChar t) { stream->ts << "\'" << t << "\'"; return maybeSpace(); }
+ inline QDebug &operator<<(QChar t) { stream->ts << '\'' << t << '\''; return maybeSpace(); }
inline QDebug &operator<<(QBool t) { stream->ts << (bool(t) ? "true" : "false"); return maybeSpace(); }
inline QDebug &operator<<(bool t) { stream->ts << (t ? "true" : "false"); return maybeSpace(); }
inline QDebug &operator<<(char t) { stream->ts << t; return maybeSpace(); }
@@ -106,10 +106,10 @@ public:
inline QDebug &operator<<(float t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(double t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(const char* t) { stream->ts << QString::fromAscii(t); return maybeSpace(); }
- inline QDebug &operator<<(const QString & t) { stream->ts << "\"" << t << "\""; return maybeSpace(); }
+ inline QDebug &operator<<(const QString & t) { stream->ts << '\"' << t << '\"'; return maybeSpace(); }
inline QDebug &operator<<(const QStringRef & t) { return operator<<(t.toString()); }
- inline QDebug &operator<<(const QLatin1String &t) { stream->ts << "\"" << t.latin1() << "\""; return maybeSpace(); }
- inline QDebug &operator<<(const QByteArray & t) { stream->ts << "\"" << t << "\""; return maybeSpace(); }
+ inline QDebug &operator<<(const QLatin1String &t) { stream->ts << '\"' << t.latin1() << '\"'; return maybeSpace(); }
+ inline QDebug &operator<<(const QByteArray & t) { stream->ts << '\"' << t << '\"'; return maybeSpace(); }
inline QDebug &operator<<(const void * t) { stream->ts << t; return maybeSpace(); }
inline QDebug &operator<<(QTextStreamFunction f) {
stream->ts << f;
@@ -159,13 +159,13 @@ template <class T>
inline QDebug operator<<(QDebug debug, const QList<T> &list)
#endif
{
- debug.nospace() << "(";
+ debug.nospace() << '(';
for (Q_TYPENAME QList<T>::size_type i = 0; i < list.count(); ++i) {
if (i)
debug << ", ";
debug << list.at(i);
}
- debug << ")";
+ debug << ')';
return debug.space();
}
@@ -192,9 +192,9 @@ inline QDebug operator<<(QDebug debug, const QMap<aKey, aT> &map)
debug.nospace() << "QMap(";
for (typename QMap<aKey, aT>::const_iterator it = map.constBegin();
it != map.constEnd(); ++it) {
- debug << "(" << it.key() << ", " << it.value() << ")";
+ debug << '(' << it.key() << ", " << it.value() << ')';
}
- debug << ")";
+ debug << ')';
return debug.space();
}
@@ -209,8 +209,8 @@ inline QDebug operator<<(QDebug debug, const QHash<aKey, aT> &hash)
debug.nospace() << "QHash(";
for (typename QHash<aKey, aT>::const_iterator it = hash.constBegin();
it != hash.constEnd(); ++it)
- debug << "(" << it.key() << ", " << it.value() << ")";
- debug << ")";
+ debug << '(' << it.key() << ", " << it.value() << ')';
+ debug << ')';
return debug.space();
}
@@ -222,7 +222,7 @@ template <class T1, class T2>
inline QDebug operator<<(QDebug debug, const QPair<T1, T2> &pair)
#endif
{
- debug.nospace() << "QPair(" << pair.first << "," << pair.second << ")";
+ debug.nospace() << "QPair(" << pair.first << ',' << pair.second << ')';
return debug.space();
}
@@ -247,7 +247,7 @@ inline QDebug operator<<(QDebug debug, const QContiguousCache<T> &cache)
if (i != cache.lastIndex())
debug << ", ";
}
- debug << ")";
+ debug << ')';
return debug.space();
}
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 0dc8a63..7d330e6 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -2417,7 +2417,7 @@ QDebug operator<<(QDebug debug, QDir::Filters filters)
if (filters & QDir::System) flags << QLatin1String("System");
if (filters & QDir::CaseSensitive) flags << QLatin1String("CaseSensitive");
}
- debug << "QDir::Filters(" << qPrintable(flags.join(QLatin1String("|"))) << ")";
+ debug << "QDir::Filters(" << qPrintable(flags.join(QLatin1String("|"))) << ')';
return debug;
}
@@ -2439,8 +2439,8 @@ QDebug operator<<(QDebug debug, QDir::SortFlags sorting)
if (sorting & QDir::LocaleAware) flags << QLatin1String("LocaleAware");
if (sorting & QDir::Type) flags << QLatin1String("Type");
debug << "QDir::SortFlags(" << qPrintable(type)
- << "|"
- << qPrintable(flags.join(QLatin1String("|"))) << ")";
+ << '|'
+ << qPrintable(flags.join(QLatin1String("|"))) << ')';
}
return debug;
}
@@ -2452,9 +2452,9 @@ QDebug operator<<(QDebug debug, const QDir &dir)
<< qPrintable(dir.nameFilters().join(QLatin1String(",")))
<< "}, "
<< dir.sorting()
- << ","
+ << ','
<< dir.filter()
- << ")";
+ << ')';
return debug.space();
}
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp
index 04750b0..4deaddb 100644
--- a/src/corelib/io/qfile.cpp
+++ b/src/corelib/io/qfile.cpp
@@ -719,38 +719,47 @@ QFile::rename(const QString &newName)
return true;
}
- QFile in(fileName());
+ if (isSequential()) {
+ d->setError(QFile::RenameError, tr("Will not rename sequential file using block copy"));
+ return false;
+ }
+
QFile out(newName);
- if (in.open(QIODevice::ReadOnly)) {
+ if (open(QIODevice::ReadOnly)) {
if (out.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
bool error = false;
char block[4096];
- qint64 read;
- while ((read = in.read(block, sizeof(block))) > 0) {
- if (read != out.write(block, read)) {
+ qint64 bytes;
+ while ((bytes = read(block, sizeof(block))) > 0) {
+ if (bytes != out.write(block, bytes)) {
d->setError(QFile::RenameError, out.errorString());
error = true;
break;
}
}
- if (read == -1) {
- d->setError(QFile::RenameError, in.errorString());
+ if (bytes == -1) {
+ d->setError(QFile::RenameError, errorString());
error = true;
}
if(!error) {
- if (!in.remove()) {
+ if (!remove()) {
d->setError(QFile::RenameError, tr("Cannot remove source file"));
error = true;
}
}
if (error)
out.remove();
- else
+ else {
+ setPermissions(permissions());
+ unsetError();
setFileName(newName);
+ }
+ close();
return !error;
}
+ close();
}
- d->setError(QFile::RenameError, out.isOpen() ? in.errorString() : out.errorString());
+ d->setError(QFile::RenameError, out.isOpen() ? errorString() : out.errorString());
}
return false;
}
diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp
index 61ea7cc..e79d867 100644
--- a/src/corelib/io/qfsfileengine.cpp
+++ b/src/corelib/io/qfsfileengine.cpp
@@ -312,6 +312,10 @@ bool QFSFileEnginePrivate::openFh(QIODevice::OpenMode openMode, FILE *fh)
if (ret == -1) {
q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
qt_error_string(int(errno)));
+
+ this->openMode = QIODevice::NotOpen;
+ this->fh = 0;
+
return false;
}
}
@@ -335,6 +339,7 @@ bool QFSFileEngine::open(QIODevice::OpenMode openMode, int fd)
if ((openMode & QFile::WriteOnly) && !(openMode & (QFile::ReadOnly | QFile::Append)))
openMode |= QFile::Truncate;
+ d->openMode = openMode;
d->lastFlushFailed = false;
d->closeFileHandle = false;
d->nativeFilePath.clear();
@@ -367,6 +372,10 @@ bool QFSFileEnginePrivate::openFd(QIODevice::OpenMode openMode, int fd)
if (ret == -1) {
q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
qt_error_string(int(errno)));
+
+ this->openMode = QIODevice::NotOpen;
+ this->fd = -1;
+
return false;
}
}
@@ -868,6 +877,119 @@ bool QFSFileEngine::supportsExtension(Extension extension) const
return false;
}
+/*! \fn bool QFSFileEngine::caseSensitive() const
+ Returns true for Windows, false for Unix.
+*/
+
+/*! \fn bool QFSFileEngine::copy(const QString &copyName)
+
+ For windows, copy the file to file \a copyName.
+
+ Not implemented for Unix.
+*/
+
+/*! \fn QString QFSFileEngine::currentPath(const QString &fileName)
+ For Unix, returns the current working directory for the file
+ engine.
+
+ For Windows, returns the canonicalized form of the current path used
+ by the file engine for the drive specified by \a fileName. On
+ Windows, each drive has its own current directory, so a different
+ path is returned for file names that include different drive names
+ (e.g. A: or C:).
+
+ \sa setCurrentPath()
+*/
+
+/*! \fn QFileInfoList QFSFileEngine::drives()
+ For Windows, returns the list of drives in the file system as a list
+ of QFileInfo objects. On unix, Mac OS X and Windows CE, only the
+ root path is returned. On Windows, this function returns all drives
+ (A:\, C:\, D:\, etc.).
+
+ For Unix, the list contains just the root path "/".
+*/
+
+/*! \fn QString QFSFileEngine::fileName(FileName file) const
+ \reimp
+*/
+
+/*! \fn QDateTime QFSFileEngine::fileTime(FileTime time) const
+ \reimp
+*/
+
+/*! \fn QString QFSFileEngine::homePath()
+ Returns the home path of the current user.
+
+ \sa rootPath()
+*/
+
+/*! \fn bool QFSFileEngine::isRelativePath() const
+ \reimp
+*/
+
+/*! \fn bool QFSFileEngine::link(const QString &newName)
+
+ Creates a link from the file currently specified by fileName() to
+ \a newName. What a link is depends on the underlying filesystem
+ (be it a shortcut on Windows or a symbolic link on Unix). Returns
+ true if successful; otherwise returns false.
+*/
+
+/*! \fn bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) const
+ \reimp
+*/
+
+/*! \fn uint QFSFileEngine::ownerId(FileOwner own) const
+ In Unix, if stat() is successful, the \c uid is returned if
+ \a own is the owner. Otherwise the \c gid is returned. If stat()
+ is unsuccessful, -2 is reuturned.
+
+ For Windows, -2 is always returned.
+*/
+
+/*! \fn QString QFSFileEngine::owner() const
+ \reimp
+*/
+
+/*! \fn bool QFSFileEngine::remove()
+ \reimp
+*/
+
+/*! \fn bool QFSFileEngine::rename(const QString &newName)
+ \reimp
+*/
+
+/*! \fn bool QFSFileEngine::rmdir(const QString &name, bool recurseParentDirectories) const
+ \reimp
+*/
+
+/*! \fn QString QFSFileEngine::rootPath()
+ Returns the root path.
+
+ \sa homePath()
+*/
+
+/*! \fn bool QFSFileEngine::setCurrentPath(const QString &path)
+ Sets the current path (e.g., for QDir), to \a path. Returns true if the
+ new path exists; otherwise this function does nothing, and returns false.
+
+ \sa currentPath()
+*/
+
+/*! \fn bool QFSFileEngine::setPermissions(uint perms)
+ \reimp
+*/
+
+/*! \fn bool QFSFileEngine::setSize(qint64 size)
+ \reimp
+*/
+
+/*! \fn QString QFSFileEngine::tempPath()
+ Returns the temporary path (i.e., a path in which it is safe
+ to store temporary files).
+*/
+
QT_END_NAMESPACE
#endif // QT_NO_FSFILEENGINE
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index 7a6a85b..8ea48d1 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -273,9 +273,8 @@ qint64 QFSFileEnginePrivate::nativeRead(char *data, qint64 len)
int oldFlags = fcntl(QT_FILENO(fh), F_GETFL);
for (int i = 0; i < 2; ++i) {
// Unix: Make the underlying file descriptor non-blocking
- int v = 1;
if ((oldFlags & O_NONBLOCK) == 0)
- fcntl(QT_FILENO(fh), F_SETFL, oldFlags | O_NONBLOCK, &v, sizeof(v));
+ fcntl(QT_FILENO(fh), F_SETFL, oldFlags | O_NONBLOCK);
// Cross platform stdlib read
size_t read = 0;
@@ -293,8 +292,7 @@ qint64 QFSFileEnginePrivate::nativeRead(char *data, qint64 len)
// Unix: Restore the blocking state of the underlying socket
if ((oldFlags & O_NONBLOCK) == 0) {
- int v = 1;
- fcntl(QT_FILENO(fh), F_SETFL, oldFlags, &v, sizeof(v));
+ fcntl(QT_FILENO(fh), F_SETFL, oldFlags);
if (readBytes == 0) {
int readByte = 0;
do {
@@ -311,8 +309,7 @@ qint64 QFSFileEnginePrivate::nativeRead(char *data, qint64 len)
}
// Unix: Restore the blocking state of the underlying socket
if ((oldFlags & O_NONBLOCK) == 0) {
- int v = 1;
- fcntl(QT_FILENO(fh), F_SETFL, oldFlags, &v, sizeof(v));
+ fcntl(QT_FILENO(fh), F_SETFL, oldFlags);
}
if (readBytes == 0 && !feof(fh)) {
// if we didn't read anything and we're not at EOF, it must be an error
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index c5b54b4..aee9fde 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -433,7 +433,7 @@ static QString nativeAbsoluteFilePathW(const QString &path)
if (retLen != 0)
ret = QString::fromUtf16((unsigned short *)buf.data(), retLen);
#else
- if (path.startsWith(QLatin1String("/")) || path.startsWith(QLatin1String("\\")))
+ if (path.startsWith(QLatin1Char('/')) || path.startsWith(QLatin1Char('\\')))
ret = QDir::toNativeSeparators(path);
else
ret = QDir::toNativeSeparators(QDir::cleanPath(qfsPrivateCurrentDir + QLatin1Char('/') + path));
@@ -946,9 +946,6 @@ bool QFSFileEnginePrivate::nativeIsSequential() const
return false;
}
-/*!
- \reimp
-*/
bool QFSFileEngine::remove()
{
Q_D(QFSFileEngine);
@@ -959,9 +956,6 @@ bool QFSFileEngine::remove()
});
}
-/*!
- \reimp
-*/
bool QFSFileEngine::copy(const QString &copyName)
{
Q_D(QFSFileEngine);
@@ -974,9 +968,6 @@ bool QFSFileEngine::copy(const QString &copyName)
});
}
-/*!
- \reimp
-*/
bool QFSFileEngine::rename(const QString &newName)
{
Q_D(QFSFileEngine);
@@ -1017,9 +1008,6 @@ static inline bool mkDir(const QString &path)
});
}
-/*!
- \reimp
-*/
static inline bool rmDir(const QString &path)
{
QT_WA({
@@ -1029,9 +1017,6 @@ static inline bool rmDir(const QString &path)
});
}
-/*!
- \reimp
-*/
static inline bool isDirPath(const QString &dirPath, bool *existed)
{
QString path = dirPath;
@@ -1054,9 +1039,6 @@ static inline bool isDirPath(const QString &dirPath, bool *existed)
return fileAttrib & FILE_ATTRIBUTE_DIRECTORY;
}
-/*!
- \reimp
-*/
bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) const
{
QString dirName = name;
@@ -1097,9 +1079,6 @@ bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) con
return mkDir(name);
}
-/*!
- \reimp
-*/
bool QFSFileEngine::rmdir(const QString &name, bool recurseParentDirectories) const
{
QString dirName = name;
@@ -1120,20 +1099,11 @@ bool QFSFileEngine::rmdir(const QString &name, bool recurseParentDirectories) co
return rmDir(name);
}
-/*!
- \reimp
-*/
bool QFSFileEngine::caseSensitive() const
{
return false;
}
-/*!
- Sets the current path (e.g., for QDir), to \a path. Returns true if the
- new path exists; otherwise this function does nothing, and returns false.
-
- \sa currentPath()
-*/
bool QFSFileEngine::setCurrentPath(const QString &path)
{
if (!QDir(path).exists())
@@ -1153,16 +1123,6 @@ bool QFSFileEngine::setCurrentPath(const QString &path)
#endif
}
-/*!
- Returns the canonicalized form of the current path used by the file
- engine for the drive specified by \a fileName.
-
- On Windows, each drive has its own current directory, so a different
- path is returned for file names that include different drive names
- (e.g. A: or C:).
-
- \sa setCurrentPath()
-*/
QString QFSFileEngine::currentPath(const QString &fileName)
{
#if !defined(Q_OS_WINCE)
@@ -1219,11 +1179,6 @@ QString QFSFileEngine::currentPath(const QString &fileName)
#endif
}
-/*!
- Returns the home path of the current user.
-
- \sa rootPath()
-*/
QString QFSFileEngine::homePath()
{
QString ret;
@@ -1277,11 +1232,6 @@ QString QFSFileEngine::homePath()
return QDir::fromNativeSeparators(ret);
}
-/*!
- Returns the root path.
-
- \sa homePath()
-*/
QString QFSFileEngine::rootPath()
{
#if defined(Q_OS_WINCE)
@@ -1290,7 +1240,7 @@ QString QFSFileEngine::rootPath()
QString ret = QString::fromLatin1(qgetenv("SystemDrive").constData());
if(ret.isEmpty())
ret = QLatin1String("c:");
- ret += QLatin1String("/");
+ ret += QLatin1Char('/');
#elif defined(Q_OS_OS2EMX)
char dir[4];
_abspath(dir, QLatin1String("/"), _MAX_PATH);
@@ -1299,10 +1249,6 @@ QString QFSFileEngine::rootPath()
return ret;
}
-/*!
- Returns the temporary path (i.e., a path in which it is safe to store
- temporary files).
-*/
QString QFSFileEngine::tempPath()
{
QString ret;
@@ -1330,11 +1276,6 @@ QString QFSFileEngine::tempPath()
return ret;
}
-/*!
- Returns the list of drives in the file system as a list of QFileInfo
- objects. On unix, Mac OS X and Windows CE, only the root path is returned.
- On Windows, this function returns all drives (A:\, C:\, D:\, etc.).
-*/
QFileInfoList QFSFileEngine::drives()
{
QFileInfoList ret;
@@ -1347,19 +1288,17 @@ QFileInfoList QFSFileEngine::drives()
exit(1);
driveBits &= 0x3ffffff;
#endif
- char driveName[4];
-
- qstrcpy(driveName, "A:/");
+ char driveName[] = "A:/";
while(driveBits) {
if(driveBits & 1)
- ret.append(QString::fromLatin1(driveName).toUpper());
+ ret.append(QString::fromLatin1(driveName));
driveName[0]++;
driveBits = driveBits >> 1;
}
return ret;
#else
- ret.append(QString::fromLatin1("/").toUpper());
+ ret.append(QLatin1Char('/'));
return ret;
#endif
}
@@ -1554,9 +1493,6 @@ QString QFSFileEnginePrivate::getLink() const
return readLink(filePath);
}
-/*!
- \reimp
-*/
bool QFSFileEngine::link(const QString &newName)
{
#if !defined(Q_OS_WINCE)
@@ -1814,9 +1750,6 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(QAbstractFileEngine::Fil
return ret;
}
-/*!
- \reimp
-*/
QString QFSFileEngine::fileName(FileName file) const
{
Q_D(const QFSFileEngine);
@@ -1910,9 +1843,6 @@ QString QFSFileEngine::fileName(FileName file) const
return d->filePath;
}
-/*!
- \reimp
-*/
bool QFSFileEngine::isRelativePath() const
{
Q_D(const QFSFileEngine);
@@ -1922,18 +1852,12 @@ bool QFSFileEngine::isRelativePath() const
|| (d->filePath.at(0) == QLatin1Char('/') && d->filePath.at(1) == QLatin1Char('/'))))); // drive, e.g. a:
}
-/*!
- \reimp
-*/
uint QFSFileEngine::ownerId(FileOwner /*own*/) const
{
static const uint nobodyID = (uint) -2;
return nobodyID;
}
-/*!
- \reimp
-*/
QString QFSFileEngine::owner(FileOwner own) const
{
#if !defined(QT_NO_LIBRARY)
@@ -1972,9 +1896,6 @@ QString QFSFileEngine::owner(FileOwner own) const
return QString(QLatin1String(""));
}
-/*!
- \reimp
-*/
bool QFSFileEngine::setPermissions(uint perms)
{
Q_D(QFSFileEngine);
@@ -2001,9 +1922,6 @@ bool QFSFileEngine::setPermissions(uint perms)
return ret;
}
-/*!
- \reimp
-*/
bool QFSFileEngine::setSize(qint64 size)
{
Q_D(QFSFileEngine);
@@ -2073,9 +1991,6 @@ static inline QDateTime fileTimeToQDateTime(const FILETIME *time)
return ret;
}
-/*!
- \reimp
-*/
QDateTime QFSFileEngine::fileTime(FileTime time) const
{
Q_D(const QFSFileEngine);
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp
index 2ccc6ea..8924b77 100644
--- a/src/corelib/io/qiodevice.cpp
+++ b/src/corelib/io/qiodevice.cpp
@@ -1745,7 +1745,7 @@ QDebug operator<<(QDebug debug, QIODevice::OpenMode modes)
}
qSort(modeList);
debug << modeList.join(QLatin1String("|"));
- debug << ")";
+ debug << ')';
return debug;
}
#endif
diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp
index 6233fde..f50acdb 100644
--- a/src/corelib/io/qnoncontiguousbytedevice.cpp
+++ b/src/corelib/io/qnoncontiguousbytedevice.cpp
@@ -458,7 +458,9 @@ qint64 QByteDeviceWrappingIoDevice::readData( char * data, qint64 maxSize)
qint64 QByteDeviceWrappingIoDevice::writeData( const char* data, qint64 maxSize)
{
- return -1;
+ Q_UNUSED(data);
+ Q_UNUSED(maxSize);
+ return -1;
}
/*!
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index 30f4291..afeaad6 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -1586,7 +1586,7 @@ void QProcess::start(const QString &program, const QStringList &arguments, OpenM
}
#if defined QPROCESS_DEBUG
- qDebug() << "QProcess::start(" << program << "," << arguments << "," << mode << ")";
+ qDebug() << "QProcess::start(" << program << ',' << arguments << ',' << mode << ')';
#endif
d->outputReadBuffer.clear();
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index 2f05f6e..e87c314 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -140,15 +140,6 @@ static void qt_native_close(int fd)
} while (ret == -1 && errno == EINTR);
}
-static void qt_native_sigaction(int signum, const struct sigaction *act,
- struct sigaction *oldact)
-{
- int ret;
- do {
- ret = ::sigaction(signum, act, oldact);
- } while (ret == -1 && errno == EINTR);
-}
-
static void qt_native_dup2(int oldfd, int newfd)
{
int ret;
@@ -255,7 +246,7 @@ QProcessManager::QProcessManager()
memset(&action, 0, sizeof(action));
action.sa_handler = qt_sa_sigchld_handler;
action.sa_flags = SA_NOCLDSTOP;
- qt_native_sigaction(SIGCHLD, &action, &oldAction);
+ ::sigaction(SIGCHLD, &action, &oldAction);
if (oldAction.sa_handler != qt_sa_sigchld_handler)
qt_sa_old_sigchld_handler = oldAction.sa_handler;
}
@@ -282,9 +273,9 @@ QProcessManager::~QProcessManager()
memset(&action, 0, sizeof(action));
action.sa_handler = qt_sa_old_sigchld_handler;
action.sa_flags = SA_NOCLDSTOP;
- qt_native_sigaction(SIGCHLD, &action, &oldAction);
+ ::sigaction(SIGCHLD, &action, &oldAction);
if (oldAction.sa_handler != qt_sa_sigchld_handler) {
- qt_native_sigaction(SIGCHLD, &oldAction, 0);
+ ::sigaction(SIGCHLD, &oldAction, 0);
}
}
@@ -394,17 +385,10 @@ static void qt_create_pipe(int *pipe)
qt_native_close(pipe[0]);
if (pipe[1] != -1)
qt_native_close(pipe[1]);
-#ifdef Q_OS_IRIX
- if (::socketpair(AF_UNIX, SOCK_STREAM, 0, pipe) == -1) {
- qWarning("QProcessPrivate::createPipe: Cannot create pipe %p: %s",
- pipe, qPrintable(qt_error_string(errno)));
- }
-#else
if (::pipe(pipe) != 0) {
qWarning("QProcessPrivate::createPipe: Cannot create pipe %p: %s",
pipe, qPrintable(qt_error_string(errno)));
}
-#endif
::fcntl(pipe[0], F_SETFD, FD_CLOEXEC);
::fcntl(pipe[1], F_SETFD, FD_CLOEXEC);
}
@@ -596,29 +580,27 @@ void QProcessPrivate::startProcess()
processManager()->start();
// Initialize pipes
+ if (!createChannel(stdinChannel) ||
+ !createChannel(stdoutChannel) ||
+ !createChannel(stderrChannel))
+ return;
qt_create_pipe(childStartedPipe);
+ qt_create_pipe(deathPipe);
+ ::fcntl(deathPipe[0], F_SETFD, FD_CLOEXEC);
+ ::fcntl(deathPipe[1], F_SETFD, FD_CLOEXEC);
+
if (threadData->eventDispatcher) {
startupSocketNotifier = new QSocketNotifier(childStartedPipe[0],
QSocketNotifier::Read, q);
QObject::connect(startupSocketNotifier, SIGNAL(activated(int)),
q, SLOT(_q_startupNotification()));
- }
- qt_create_pipe(deathPipe);
- ::fcntl(deathPipe[0], F_SETFD, FD_CLOEXEC);
- ::fcntl(deathPipe[1], F_SETFD, FD_CLOEXEC);
- if (threadData->eventDispatcher) {
deathNotifier = new QSocketNotifier(deathPipe[0],
QSocketNotifier::Read, q);
QObject::connect(deathNotifier, SIGNAL(activated(int)),
q, SLOT(_q_processDied()));
}
- if (!createChannel(stdinChannel) ||
- !createChannel(stdoutChannel) ||
- !createChannel(stderrChannel))
- return;
-
// Start the process (platform dependent)
q->setProcessState(QProcess::Starting);
@@ -906,7 +888,7 @@ static void qt_ignore_sigpipe()
struct sigaction noaction;
memset(&noaction, 0, sizeof(noaction));
noaction.sa_handler = SIG_IGN;
- qt_native_sigaction(SIGPIPE, &noaction, 0);
+ ::sigaction(SIGPIPE, &noaction, 0);
}
}
@@ -1276,7 +1258,7 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a
struct sigaction noaction;
memset(&noaction, 0, sizeof(noaction));
noaction.sa_handler = SIG_IGN;
- qt_native_sigaction(SIGPIPE, &noaction, 0);
+ ::sigaction(SIGPIPE, &noaction, 0);
::setsid();
@@ -1322,7 +1304,7 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a
struct sigaction noaction;
memset(&noaction, 0, sizeof(noaction));
noaction.sa_handler = SIG_IGN;
- qt_native_sigaction(SIGPIPE, &noaction, 0);
+ ::sigaction(SIGPIPE, &noaction, 0);
// '\1' means execv failed
char c = '\1';
@@ -1333,7 +1315,7 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a
struct sigaction noaction;
memset(&noaction, 0, sizeof(noaction));
noaction.sa_handler = SIG_IGN;
- qt_native_sigaction(SIGPIPE, &noaction, 0);
+ ::sigaction(SIGPIPE, &noaction, 0);
// '\2' means internal error
char c = '\2';
diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp
index 5d862e5..179c3d0 100644
--- a/src/corelib/io/qprocess_win.cpp
+++ b/src/corelib/io/qprocess_win.cpp
@@ -272,12 +272,12 @@ static QString qt_create_commandline(const QString &program, const QStringList &
QString args;
if (!program.isEmpty()) {
QString programName = program;
- if (!programName.startsWith(QLatin1Char('\"')) && !programName.endsWith(QLatin1Char('\"')) && programName.contains(QLatin1String(" ")))
- programName = QLatin1String("\"") + programName + QLatin1String("\"");
- programName.replace(QLatin1String("/"), QLatin1String("\\"));
+ if (!programName.startsWith(QLatin1Char('\"')) && !programName.endsWith(QLatin1Char('\"')) && programName.contains(QLatin1Char(' ')))
+ programName = QLatin1Char('\"') + programName + QLatin1Char('\"');
+ programName.replace(QLatin1Char('/'), QLatin1Char('\\'));
// add the prgram as the first arg ... it works better
- args = programName + QLatin1String(" ");
+ args = programName + QLatin1Char(' ');
}
for (int i=0; i<arguments.size(); ++i) {
@@ -285,16 +285,16 @@ static QString qt_create_commandline(const QString &program, const QStringList &
// in the case of \" already being in the string the \ must also be escaped
tmp.replace( QLatin1String("\\\""), QLatin1String("\\\\\"") );
// escape a single " because the arguments will be parsed
- tmp.replace( QLatin1String("\""), QLatin1String("\\\"") );
+ tmp.replace( QLatin1Char('\"'), QLatin1String("\\\"") );
if (tmp.isEmpty() || tmp.contains(QLatin1Char(' ')) || tmp.contains(QLatin1Char('\t'))) {
// The argument must not end with a \ since this would be interpreted
// as escaping the quote -- rather put the \ behind the quote: e.g.
// rather use "foo"\ than "foo\"
- QString endQuote(QLatin1String("\""));
+ QString endQuote(QLatin1Char('\"'));
int i = tmp.length();
while (i>0 && tmp.at(i-1) == QLatin1Char('\\')) {
--i;
- endQuote += QLatin1String("\\");
+ endQuote += QLatin1Char('\\');
}
args += QLatin1String(" \"") + tmp.left(i) + endQuote;
} else {
@@ -427,7 +427,7 @@ void QProcessPrivate::startProcess()
QString fullPathProgram = program;
if (!QDir::isAbsolutePath(fullPathProgram))
fullPathProgram = QFileInfo(fullPathProgram).absoluteFilePath();
- fullPathProgram.replace(QLatin1String("/"), QLatin1String("\\"));
+ fullPathProgram.replace(QLatin1Char('/'), QLatin1Char('\\'));
success = CreateProcessW((WCHAR*)fullPathProgram.utf16(),
(WCHAR*)args.utf16(),
0, 0, false, 0, 0, 0, 0, pid);
@@ -887,8 +887,8 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a
#if defined(Q_OS_WINCE)
QString fullPathProgram = program;
if (!QDir::isAbsolutePath(fullPathProgram))
- fullPathProgram.prepend(QDir::currentPath().append(QLatin1String("/")));
- fullPathProgram.replace(QLatin1String("/"), QLatin1String("\\"));
+ fullPathProgram.prepend(QDir::currentPath().append(QLatin1Char('/')));
+ fullPathProgram.replace(QLatin1Char('/'), QLatin1Char('\\'));
success = CreateProcessW((WCHAR*)fullPathProgram.utf16(),
(WCHAR*)args.utf16(),
0, 0, false, CREATE_NEW_CONSOLE, 0, 0, 0, &pinfo);
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp
index 3b704f6..94dfd4d 100644
--- a/src/corelib/io/qresource.cpp
+++ b/src/corelib/io/qresource.cpp
@@ -623,14 +623,14 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const
QString root = mappingRoot();
if(!root.isEmpty()) {
if(root == path) {
- path = QLatin1String("/");
+ path = QLatin1Char('/');
} else {
- if(!root.endsWith(QLatin1String("/")))
- root += QLatin1String("/");
+ if(!root.endsWith(QLatin1Char('/')))
+ root += QLatin1Char('/');
if(path.size() >= root.size() && path.startsWith(root))
path = path.mid(root.length()-1);
if(path.isEmpty())
- path = QLatin1String("/");
+ path = QLatin1Char('/');
}
}
}
diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp
index a08c969..57f65d6 100644
--- a/src/corelib/io/qsettings_win.cpp
+++ b/src/corelib/io/qsettings_win.cpp
@@ -148,7 +148,7 @@ static QString errorCodeToString(DWORD errorCode)
if (data != 0)
LocalFree(data);
})
- if (result.endsWith(QLatin1String("\n")))
+ if (result.endsWith(QLatin1Char('\n')))
result.truncate(result.length() - 1);
return result;
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 6a9125c..728bf4f 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -203,7 +203,7 @@ static int _gettemp(char *path, int *doopen, int domkdir, int slen)
if (QDir::isAbsolutePath(QString::fromLatin1(path)))
targetPath = QLatin1String(path);
else
- targetPath = QDir::currentPath().append(QLatin1String("/")) + QLatin1String(path);
+ targetPath = QDir::currentPath().append(QLatin1Char('/')) + QLatin1String(path);
if ((*doopen =
QT_OPEN(targetPath.toLocal8Bit(), O_CREAT|O_EXCL|O_RDWR
@@ -291,14 +291,22 @@ class QTemporaryFileEngine : public QFSFileEngine
{
Q_DECLARE_PRIVATE(QFSFileEngine)
public:
- QTemporaryFileEngine(const QString &file) : QFSFileEngine(file) { }
+ QTemporaryFileEngine(const QString &file, bool fileIsTemplate = true)
+ : QFSFileEngine(file), filePathIsTemplate(fileIsTemplate)
+ {
+ }
+
~QTemporaryFileEngine();
+ bool isReallyOpen();
void setFileName(const QString &file);
bool open(QIODevice::OpenMode flags);
bool remove();
+ bool rename(const QString &newName);
bool close();
+
+ bool filePathIsTemplate;
};
QTemporaryFileEngine::~QTemporaryFileEngine()
@@ -306,6 +314,21 @@ QTemporaryFileEngine::~QTemporaryFileEngine()
QFSFileEngine::close();
}
+bool QTemporaryFileEngine::isReallyOpen()
+{
+ Q_D(QFSFileEngine);
+
+ if (!((0 == d->fh) && (-1 == d->fd)
+#if defined Q_OS_WIN
+ && (INVALID_HANDLE_VALUE == d->fileHandle)
+#endif
+ ))
+ return true;
+
+ return false;
+
+}
+
void QTemporaryFileEngine::setFileName(const QString &file)
{
// Really close the file, so we don't leak
@@ -316,13 +339,16 @@ void QTemporaryFileEngine::setFileName(const QString &file)
bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
{
Q_D(QFSFileEngine);
+ Q_ASSERT(!isReallyOpen());
+
+ if (!filePathIsTemplate)
+ return QFSFileEngine::open(openMode);
QString qfilename = d->filePath;
if(!qfilename.contains(QLatin1String("XXXXXX")))
qfilename += QLatin1String(".XXXXXX");
int suffixLength = qfilename.length() - (qfilename.lastIndexOf(QLatin1String("XXXXXX"), -1, Qt::CaseSensitive) + 6);
- d->closeFileHandle = true;
char *filename = qstrdup(qfilename.toLocal8Bit());
#ifndef Q_WS_WIN
@@ -330,16 +356,20 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
if (fd != -1) {
// First open the fd as an external file descriptor to
// initialize the engine properly.
- QFSFileEngine::open(openMode, fd);
+ if (QFSFileEngine::open(openMode, fd)) {
- // Allow the engine to close the handle even if it's "external".
- d->closeFileHandle = true;
+ // Allow the engine to close the handle even if it's "external".
+ d->closeFileHandle = true;
- // Restore the file names (open() resets them).
- d->filePath = QString::fromLocal8Bit(filename); //changed now!
- d->nativeInitFileName();
- delete [] filename;
- return true;
+ // Restore the file names (open() resets them).
+ d->filePath = QString::fromLocal8Bit(filename); //changed now!
+ filePathIsTemplate = false;
+ d->nativeInitFileName();
+ delete [] filename;
+ return true;
+ }
+
+ QT_CLOSE(fd);
}
delete [] filename;
setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno));
@@ -351,6 +381,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
}
d->filePath = QString::fromLocal8Bit(filename);
+ filePathIsTemplate = false;
d->nativeInitFileName();
d->closeFileHandle = true;
delete [] filename;
@@ -364,9 +395,17 @@ bool QTemporaryFileEngine::remove()
// Since the QTemporaryFileEngine::close() does not really close the file,
// we must explicitly call QFSFileEngine::close() before we remove it.
QFSFileEngine::close();
- bool removed = QFSFileEngine::remove();
- d->filePath.clear();
- return removed;
+ if (QFSFileEngine::remove()) {
+ d->filePath.clear();
+ return true;
+ }
+ return false;
+}
+
+bool QTemporaryFileEngine::rename(const QString &newName)
+{
+ QFSFileEngine::close();
+ return QFSFileEngine::rename(newName);
}
bool QTemporaryFileEngine::close()
@@ -388,17 +427,14 @@ protected:
bool autoRemove;
QString templateName;
- mutable QTemporaryFileEngine *fileEngine;
};
-QTemporaryFilePrivate::QTemporaryFilePrivate() : autoRemove(true), fileEngine(0)
+QTemporaryFilePrivate::QTemporaryFilePrivate() : autoRemove(true)
{
}
QTemporaryFilePrivate::~QTemporaryFilePrivate()
{
- delete fileEngine;
- fileEngine = 0;
}
//************* QTemporaryFile
@@ -430,8 +466,8 @@ QTemporaryFilePrivate::~QTemporaryFilePrivate()
file will exist and be kept open internally by QTemporaryFile.
The file name of the temporary file can be found by calling fileName().
- Note that this is only defined while the file is open; the function returns
- an empty string before the file is opened and after it is closed.
+ Note that this is only defined after the file is first opened; the function
+ returns an empty string before this.
A temporary file will have some static part of the name and some
part that is calculated to be unique. The default filename \c
@@ -601,7 +637,8 @@ void QTemporaryFile::setAutoRemove(bool b)
QString QTemporaryFile::fileName() const
{
- if(!isOpen())
+ Q_D(const QTemporaryFile);
+ if(d->fileName.isEmpty())
return QString();
return fileEngine()->fileName(QAbstractFileEngine::DefaultName);
}
@@ -695,8 +732,12 @@ QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
QAbstractFileEngine *QTemporaryFile::fileEngine() const
{
Q_D(const QTemporaryFile);
- if(!d->fileEngine)
- d->fileEngine = new QTemporaryFileEngine(d->templateName);
+ if(!d->fileEngine) {
+ if (d->fileName.isEmpty())
+ d->fileEngine = new QTemporaryFileEngine(d->templateName);
+ else
+ d->fileEngine = new QTemporaryFileEngine(d->fileName, false);
+ }
return d->fileEngine;
}
@@ -711,10 +752,13 @@ bool QTemporaryFile::open(OpenMode flags)
{
Q_D(QTemporaryFile);
if (!d->fileName.isEmpty()) {
- setOpenMode(flags);
- return true;
+ if (static_cast<QTemporaryFileEngine*>(fileEngine())->isReallyOpen()) {
+ setOpenMode(flags);
+ return true;
+ }
}
+ flags |= QIODevice::ReadWrite;
if (QFile::open(flags)) {
d->fileName = d->fileEngine->fileName(QAbstractFileEngine::DefaultName);
return true;
@@ -722,6 +766,8 @@ bool QTemporaryFile::open(OpenMode flags)
return false;
}
+QT_END_NAMESPACE
+
#endif // QT_NO_TEMPORARYFILE
-QT_END_NAMESPACE
+
diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp
index 612d7f7..4563e84 100644
--- a/src/corelib/io/qtextstream.cpp
+++ b/src/corelib/io/qtextstream.cpp
@@ -2292,7 +2292,7 @@ bool QTextStreamPrivate::putNumber(qulonglong number, bool negative)
// ShowBase flag set zero should be written as '00'
if (number == 0 && base == 8 && numberFlags & QTextStream::ShowBase
&& result == QLatin1String("0")) {
- result.prepend(QLatin1String("0"));
+ result.prepend(QLatin1Char('0'));
}
}
return putString(result, true);
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index d1a5cdd..94a53f1 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -5698,7 +5698,7 @@ QUrl QUrl::fromLocalFile(const QString &localFile)
// magic for drives on windows
if (deslashified.length() > 1 && deslashified.at(1) == QLatin1Char(':') && deslashified.at(0) != QLatin1Char('/')) {
- url.setPath(QLatin1String("/") + deslashified);
+ url.setPath(QLatin1Char('/') + deslashified);
// magic for shared drive on windows
} else if (deslashified.startsWith(QLatin1String("//"))) {
int indexOfPath = deslashified.indexOf(QLatin1Char('/'), 2);
@@ -5728,7 +5728,7 @@ QString QUrl::toLocalFile() const
// magic for shared drive on windows
if (!d->host.isEmpty()) {
tmp = QLatin1String("//") + d->host + (ourPath.length() > 0 && ourPath.at(0) != QLatin1Char('/')
- ? QLatin1String("/") + ourPath : ourPath);
+ ? QLatin1Char('/') + ourPath : ourPath);
} else {
tmp = ourPath;
// magic for drives on windows
@@ -5976,7 +5976,7 @@ QDataStream &operator>>(QDataStream &in, QUrl &url)
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug d, const QUrl &url)
{
- d.maybeSpace() << "QUrl(" << url.toString() << ")";
+ d.maybeSpace() << "QUrl(" << url.toString() << ')';
return d.space();
}
#endif
diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h
index 9242092..e9c4a8d 100644
--- a/src/corelib/io/qurl.h
+++ b/src/corelib/io/qurl.h
@@ -223,7 +223,7 @@ public:
inline QT3_SUPPORT QString ref() const { return fragment(); }
inline QT3_SUPPORT void setRef(const QString &txt) { setFragment(txt); }
inline QT3_SUPPORT bool hasRef() const { return !fragment().isEmpty(); }
- inline QT3_SUPPORT void addPath(const QString &p) { setPath(path() + QLatin1String("/") + p); }
+ inline QT3_SUPPORT void addPath(const QString &p) { setPath(path() + QLatin1Char('/') + p); }
QT3_SUPPORT void setFileName(const QString &txt);
QT3_SUPPORT QString fileName() const;
QT3_SUPPORT QString dirPath() const;
diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri
index 68649a6..ecef555 100644
--- a/src/corelib/kernel/kernel.pri
+++ b/src/corelib/kernel/kernel.pri
@@ -12,7 +12,7 @@ HEADERS += \
kernel/qcoreevent.h \
kernel/qmetaobject.h \
kernel/qmetatype.h \
- kernel/qmimedata.h \
+ kernel/qmimedata.h \
kernel/qobject.h \
kernel/qobjectdefs.h \
kernel/qsignalmapper.h \
@@ -27,8 +27,8 @@ HEADERS += \
kernel/qvariant_p.h \
kernel/qmetaobject_p.h \
kernel/qobject_p.h \
- kernel/qcoreglobaldata_p.h \
- kernel/qsharedmemory.h \
+ kernel/qcoreglobaldata_p.h \
+ kernel/qsharedmemory.h \
kernel/qsharedmemory_p.h \
kernel/qsystemsemaphore.h \
kernel/qsystemsemaphore_p.h \
@@ -43,7 +43,7 @@ SOURCES += \
kernel/qcoreevent.cpp \
kernel/qmetaobject.cpp \
kernel/qmetatype.cpp \
- kernel/qmimedata.cpp \
+ kernel/qmimedata.cpp \
kernel/qobject.cpp \
kernel/qobjectcleanuphandler.cpp \
kernel/qsignalmapper.cpp \
diff --git a/src/corelib/kernel/qabstractitemmodel.cpp b/src/corelib/kernel/qabstractitemmodel.cpp
index fd0e105..935c0aa 100644
--- a/src/corelib/kernel/qabstractitemmodel.cpp
+++ b/src/corelib/kernel/qabstractitemmodel.cpp
@@ -428,8 +428,8 @@ bool QPersistentModelIndex::isValid() const
QDebug operator<<(QDebug dbg, const QModelIndex &idx)
{
#ifndef Q_BROKEN_DEBUG_STREAM
- dbg.nospace() << "QModelIndex(" << idx.row() << "," << idx.column()
- << "," << idx.internalPointer() << "," << idx.model() << ")";
+ dbg.nospace() << "QModelIndex(" << idx.row() << ',' << idx.column()
+ << ',' << idx.internalPointer() << ',' << idx.model() << ')';
return dbg.space();
#else
qWarning("This compiler doesn't support streaming QModelIndex to QDebug");
@@ -525,7 +525,7 @@ void QAbstractItemModelPrivate::rowsInserted(const QModelIndex &parent,
if (data->index.isValid()) {
persistent.insertMultiAtEnd(data->index, data);
} else {
- qWarning() << "QAbstractItemModel::endInsertRows: Invalid index (" << old.row() + count << "," << old.column() << ") in model" << q_func();
+ qWarning() << "QAbstractItemModel::endInsertRows: Invalid index (" << old.row() + count << ',' << old.column() << ") in model" << q_func();
}
}
}
@@ -574,7 +574,7 @@ void QAbstractItemModelPrivate::rowsRemoved(const QModelIndex &parent,
if (data->index.isValid()) {
persistent.insertMultiAtEnd(data->index, data);
} else {
- qWarning() << "QAbstractItemModel::endRemoveRows: Invalid index (" << old.row() - count << "," << old.column() << ") in model" << q_func();
+ qWarning() << "QAbstractItemModel::endRemoveRows: Invalid index (" << old.row() - count << ',' << old.column() << ") in model" << q_func();
}
}
QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop();
@@ -619,7 +619,7 @@ void QAbstractItemModelPrivate::columnsInserted(const QModelIndex &parent,
if (data->index.isValid()) {
persistent.insertMultiAtEnd(data->index, data);
} else {
- qWarning() << "QAbstractItemModel::endInsertColumns: Invalid index (" << old.row() << "," << old.column() + count << ") in model" << q_func();
+ qWarning() << "QAbstractItemModel::endInsertColumns: Invalid index (" << old.row() << ',' << old.column() + count << ") in model" << q_func();
}
}
}
@@ -669,7 +669,7 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent,
if (data->index.isValid()) {
persistent.insertMultiAtEnd(data->index, data);
} else {
- qWarning() << "QAbstractItemModel::endRemoveColumns: Invalid index (" << old.row() << "," << old.column() - count << ") in model" << q_func();
+ qWarning() << "QAbstractItemModel::endRemoveColumns: Invalid index (" << old.row() << ',' << old.column() - count << ") in model" << q_func();
}
}
QVector<QPersistentModelIndexData *> persistent_invalidated = persistent.invalidated.pop();
diff --git a/src/corelib/kernel/qabstractitemmodel_p.h b/src/corelib/kernel/qabstractitemmodel_p.h
index df1a6ce..27f1b28 100644
--- a/src/corelib/kernel/qabstractitemmodel_p.h
+++ b/src/corelib/kernel/qabstractitemmodel_p.h
@@ -61,7 +61,7 @@
QT_BEGIN_NAMESPACE
-class Q_CORE_EXPORT QPersistentModelIndexData
+class QPersistentModelIndexData
{
public:
QPersistentModelIndexData() : model(0) {}
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 77ef096..6847173 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -1798,7 +1798,7 @@ QString QCoreApplication::applicationFilePath()
*/
QByteArray pEnv = qgetenv("PATH");
QDir currentDir = QDir::current();
- QStringList paths = QString::fromLocal8Bit(pEnv.constData()).split(QLatin1String(":"));
+ QStringList paths = QString::fromLocal8Bit(pEnv.constData()).split(QLatin1Char(':'));
for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) {
if ((*p).isEmpty())
continue;
@@ -1908,7 +1908,7 @@ QStringList QCoreApplication::arguments()
wchar_t tempFilename[MAX_PATH+1];
if (GetModuleFileNameW(0, tempFilename, MAX_PATH)) {
tempFilename[MAX_PATH] = 0;
- cmdline.prepend(QString(QLatin1String("\"")) + QString::fromUtf16((unsigned short *)tempFilename) + QString(QLatin1String("\" ")));
+ cmdline.prepend(QLatin1Char('\"') + QString::fromUtf16((unsigned short *)tempFilename) + QString(QLatin1String("\" ")));
}
#endif // Q_OS_WINCE
diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp
index 225821f..9868c23 100644
--- a/src/corelib/kernel/qcoreapplication_win.cpp
+++ b/src/corelib/kernel/qcoreapplication_win.cpp
@@ -51,12 +51,11 @@
QT_BEGIN_NAMESPACE
-// ############### DON'T EXPORT HERE!!!
-Q_CORE_EXPORT char appFileName[MAX_PATH+1]; // application file name
-Q_CORE_EXPORT char theAppName[MAX_PATH+1]; // application name
-Q_CORE_EXPORT HINSTANCE appInst = 0; // handle to app instance
-Q_CORE_EXPORT HINSTANCE appPrevInst = 0; // handle to prev app instance
-Q_CORE_EXPORT int appCmdShow = 0;
+char appFileName[MAX_PATH+1]; // application file name
+char theAppName[MAX_PATH+1]; // application name
+HINSTANCE appInst = 0; // handle to app instance
+HINSTANCE appPrevInst = 0; // handle to prev app instance
+int appCmdShow = 0;
bool usingWinMain = false; // whether the qWinMain() is used or not
Q_CORE_EXPORT HINSTANCE qWinAppInst() // get Windows app handle
@@ -69,6 +68,12 @@ Q_CORE_EXPORT HINSTANCE qWinAppPrevInst() // get Windows prev app
return appPrevInst;
}
+Q_CORE_EXPORT int qWinAppCmdShow() // get main window show command
+{
+ return appCmdShow;
+}
+
+
void set_winapp_name()
{
static bool already_set = false;
@@ -89,6 +94,14 @@ void set_winapp_name()
int l = qstrlen(theAppName);
if ((l > 4) && !qstricmp(theAppName + l - 4, ".exe"))
theAppName[l-4] = '\0'; // drop .exe extension
+
+ if (appInst == 0) {
+ QT_WA({
+ appInst = GetModuleHandle(0);
+ }, {
+ appInst = GetModuleHandleA(0);
+ });
+ }
}
}
@@ -134,11 +147,11 @@ Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char* str)
staticCriticalSection.lock();
QT_WA({
QString s(QString::fromLocal8Bit(str));
- s += QLatin1String("\n");
+ s += QLatin1Char('\n');
OutputDebugStringW((TCHAR*)s.utf16());
}, {
QByteArray s(str);
- s += "\n";
+ s += '\n';
OutputDebugStringA(s.data());
})
staticCriticalSection.unlock();
@@ -173,14 +186,14 @@ void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam,
// Create command line
- set_winapp_name();
-
argv = qWinCmdLine<char>(cmdParam, int(strlen(cmdParam)), argc);
// Get Windows parameters
appInst = instance;
appPrevInst = prevInstance;
appCmdShow = cmdShow;
+
+ set_winapp_name();
}
/*!
@@ -618,7 +631,7 @@ QString valueCheck(uint actual, ...)
#ifdef Q_CC_BOR
-Q_CORE_EXPORT QString decodeMSG(const MSG& msg)
+QString decodeMSG(const MSG& msg)
{
return QString::fromLatin1("THis is not supported on Borland");
}
diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp
index 7e25c60..77679dc 100644
--- a/src/corelib/kernel/qcoreevent.cpp
+++ b/src/corelib/kernel/qcoreevent.cpp
@@ -272,6 +272,8 @@ QT_BEGIN_NAMESPACE
\omitvalue NetworkReplyUpdated
\omitvalue FutureCallOut
\omitvalue CocoaRequestModal
+ \omitvalue Wrapped
+ \omitvalue Signal
*/
/*!
diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h
index 84ab390..feefd08 100644
--- a/src/corelib/kernel/qcoreevent.h
+++ b/src/corelib/kernel/qcoreevent.h
@@ -44,6 +44,7 @@
#include <QtCore/qnamespace.h>
#include <QtCore/qbytearray.h>
+#include <QtCore/qobjectdefs.h>
QT_BEGIN_HEADER
@@ -54,7 +55,9 @@ QT_MODULE(Core)
class QEventPrivate;
class Q_CORE_EXPORT QEvent // event base class
{
+ Q_GADGET
QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
+ Q_ENUMS(Type)
public:
enum Type {
/*
@@ -266,15 +269,18 @@ public:
CocoaRequestModal = 190, // Internal for requesting an application modal Cocoa Window
MacGLClearDrawable = 191, // Internal Cocoa, the window has changed, so we must clear
- TouchBegin = 192,
- TouchUpdate = 193,
- TouchEnd = 194,
- GraphicsSceneTouchBegin = 195,
- GraphicsSceneTouchUpdate = 196,
- GraphicsSceneTouchEnd = 197,
+ Signal = 192,
+ Wrapped = 193,
- Gesture = 198,
- GraphicsSceneGesture = 199,
+ TouchBegin = 194,
+ TouchUpdate = 195,
+ TouchEnd = 196,
+ GraphicsSceneTouchBegin = 197,
+ GraphicsSceneTouchUpdate = 198,
+ GraphicsSceneTouchEnd = 199,
+
+ Gesture = 200,
+ GraphicsSceneGesture = 201,
// 512 reserved for Qt Jambi's MetaCall event
// 513 reserved for Qt Jambi's DeleteOnMainThread event
diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h
index 41329cf..8c08bd2 100644
--- a/src/corelib/kernel/qeventdispatcher_unix_p.h
+++ b/src/corelib/kernel/qeventdispatcher_unix_p.h
@@ -153,14 +153,14 @@ public:
int activateTimers();
};
-struct Q_CORE_EXPORT QSockNot
+struct QSockNot
{
QSocketNotifier *obj;
int fd;
fd_set *queue;
};
-class Q_CORE_EXPORT QSockNotType
+class QSockNotType
{
public:
QSockNotType();
diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp
index c4061f4..2dd5534 100644
--- a/src/corelib/kernel/qeventdispatcher_win.cpp
+++ b/src/corelib/kernel/qeventdispatcher_win.cpp
@@ -396,13 +396,6 @@ Q_CORE_EXPORT bool winPostMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
{ return PostMessageA(hWnd, msg, wParam, lParam); });
}
-Q_CORE_EXPORT bool winGetMessage(MSG* msg, HWND hWnd, UINT wMsgFilterMin,
- UINT wMsgFilterMax)
-{
- QT_WA({ return GetMessage(msg, hWnd, wMsgFilterMin, wMsgFilterMax); } ,
- { return GetMessageA(msg, hWnd, wMsgFilterMin, wMsgFilterMax); });
-}
-
// This function is called by a workerthread
void WINAPI CALLBACK qt_fast_timer_proc(uint timerId, uint /*reserved*/, DWORD_PTR user, DWORD_PTR /*reserved*/, DWORD_PTR /*reserved*/)
{
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index cfd8493..65d81f1 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -92,8 +92,8 @@ static int *queuedConnectionTypes(const QList<QByteArray> &typeNames)
return types;
}
-QBasicAtomicPointer<QMutexPool> signalSlotMutexes = Q_BASIC_ATOMIC_INITIALIZER(0);
-QBasicAtomicInt objectCount = Q_BASIC_ATOMIC_INITIALIZER(0);
+static QBasicAtomicPointer<QMutexPool> signalSlotMutexes = Q_BASIC_ATOMIC_INITIALIZER(0);
+static QBasicAtomicInt objectCount = Q_BASIC_ATOMIC_INITIALIZER(0);
/** \internal
* mutex to be locked when accessing the connectionlists or the senders list
@@ -117,8 +117,7 @@ extern "C" Q_CORE_EXPORT void qt_addObject(QObject *)
extern "C" Q_CORE_EXPORT void qt_removeObject(QObject *)
{
if(!objectCount.deref()) {
- QMutexPool *old = signalSlotMutexes;
- signalSlotMutexes.testAndSetAcquire(old, 0);
+ QMutexPool *old = signalSlotMutexes.fetchAndStoreAcquire(0);
delete old;
}
}
@@ -3462,7 +3461,7 @@ QDebug operator<<(QDebug dbg, const QObject *o) {
#ifndef Q_BROKEN_DEBUG_STREAM
if (!o)
return dbg << "QObject(0x0) ";
- dbg.nospace() << o->metaObject()->className() << "(" << (void *)o;
+ dbg.nospace() << o->metaObject()->className() << '(' << (void *)o;
if (!o->objectName().isEmpty())
dbg << ", name = " << o->objectName();
dbg << ')';
diff --git a/src/corelib/kernel/qsharedmemory_unix.cpp b/src/corelib/kernel/qsharedmemory_unix.cpp
index cd248dc..12f21b7 100644
--- a/src/corelib/kernel/qsharedmemory_unix.cpp
+++ b/src/corelib/kernel/qsharedmemory_unix.cpp
@@ -47,9 +47,12 @@
#include <qdir.h>
#include <qdebug.h>
+#include <errno.h>
+
#ifndef QT_NO_SHAREDMEMORY
-#include <errno.h>
+QT_BEGIN_NAMESPACE
+
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
diff --git a/src/corelib/kernel/qsystemsemaphore_p.h b/src/corelib/kernel/qsystemsemaphore_p.h
index 81d4f10..a4a7389 100644
--- a/src/corelib/kernel/qsystemsemaphore_p.h
+++ b/src/corelib/kernel/qsystemsemaphore_p.h
@@ -101,9 +101,9 @@ public:
QSystemSemaphore::SystemSemaphoreError error;
};
-#endif // QT_NO_SYSTEMSEMAPHORE
+QT_END_NAMESPACE
+#endif // QT_NO_SYSTEMSEMAPHORE
-QT_END_NAMESPACE
#endif // QSYSTEMSEMAPHORE_P_H
diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp
index 77d6599..3e4b467 100644
--- a/src/corelib/kernel/qtranslator.cpp
+++ b/src/corelib/kernel/qtranslator.cpp
@@ -819,6 +819,6 @@ bool QTranslator::isEmpty() const
Use translate(\a context, \a sourceText, \a comment) instead.
*/
-#endif // QT_NO_TRANSLATION
-
QT_END_NAMESPACE
+
+#endif // QT_NO_TRANSLATION
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp
new file mode 100644
index 0000000..942722f
--- /dev/null
+++ b/src/corelib/statemachine/qabstractstate.cpp
@@ -0,0 +1,202 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qabstractstate.h"
+#include "qabstractstate_p.h"
+#include "qstate.h"
+#include "qstate_p.h"
+#include "qstatemachine.h"
+#include "qstatemachine_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QAbstractState
+
+ \brief The QAbstractState class is the base class of states of a QStateMachine.
+
+ \since 4.6
+ \ingroup statemachine
+
+ The QAbstractState class is the abstract base class of states that are part
+ of a QStateMachine. It defines the interface that all state objects have in
+ common. QAbstractState is part of \l{The State Machine Framework}.
+
+ The entered() signal is emitted when the state has been entered. The
+ exited() signal is emitted when the state has been exited.
+
+ The parentState() function returns the state's parent state. The machine()
+ function returns the state machine that the state is part of.
+
+ \section1 Subclassing
+
+ The onEntry() function is called when the state is entered; reimplement this
+ function to perform custom processing when the state is entered.
+
+ The onExit() function is called when the state is exited; reimplement this
+ function to perform custom processing when the state is exited.
+*/
+
+QAbstractStatePrivate::QAbstractStatePrivate()
+{
+}
+
+QAbstractStatePrivate *QAbstractStatePrivate::get(QAbstractState *q)
+{
+ return q->d_func();
+}
+
+QStateMachine *QAbstractStatePrivate::machine() const
+{
+ Q_Q(const QAbstractState);
+ QObject *par = q->parent();
+ while (par != 0) {
+ if (QStateMachine *mach = qobject_cast<QStateMachine*>(par))
+ return mach;
+ par = par->parent();
+ }
+ return 0;
+}
+
+void QAbstractStatePrivate::callOnEntry(QEvent *e)
+{
+ Q_Q(QAbstractState);
+ q->onEntry(e);
+}
+
+void QAbstractStatePrivate::callOnExit(QEvent *e)
+{
+ Q_Q(QAbstractState);
+ q->onExit(e);
+}
+
+void QAbstractStatePrivate::emitEntered()
+{
+ Q_Q(QAbstractState);
+ emit q->entered();
+}
+
+void QAbstractStatePrivate::emitExited()
+{
+ Q_Q(QAbstractState);
+ emit q->exited();
+}
+
+/*!
+ Constructs a new state with the given \a parent state.
+*/
+QAbstractState::QAbstractState(QState *parent)
+ : QObject(*new QAbstractStatePrivate, parent)
+{
+}
+
+/*!
+ \internal
+*/
+QAbstractState::QAbstractState(QAbstractStatePrivate &dd, QState *parent)
+ : QObject(dd, parent)
+{
+}
+
+/*!
+ Destroys this state.
+*/
+QAbstractState::~QAbstractState()
+{
+}
+
+/*!
+ Returns this state's parent state, or 0 if the state has no parent state.
+*/
+QState *QAbstractState::parentState() const
+{
+ return qobject_cast<QState*>(parent());
+}
+
+/*!
+ Returns the state machine that this state is part of, or 0 if the state is
+ not part of a state machine.
+*/
+QStateMachine *QAbstractState::machine() const
+{
+ Q_D(const QAbstractState);
+ return d->machine();
+}
+
+/*!
+ \fn QAbstractState::onExit(QEvent *event)
+
+ This function is called when the state is exited. The given \a event is what
+ caused the state to be exited. Reimplement this function to perform custom
+ processing when the state is exited.
+*/
+
+/*!
+ \fn QAbstractState::onEntry(QEvent *event)
+
+ This function is called when the state is entered. The given \a event is
+ what caused the state to be entered. Reimplement this function to perform
+ custom processing when the state is entered.
+*/
+
+/*!
+ \fn QAbstractState::entered()
+
+ This signal is emitted when the state has been entered (after onEntry() has
+ been called).
+*/
+
+/*!
+ \fn QAbstractState::exited()
+
+ This signal is emitted when the state has been exited (after onExit() has
+ been called).
+*/
+
+/*!
+ \reimp
+*/
+bool QAbstractState::event(QEvent *e)
+{
+ return QObject::event(e);
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qabstractstate.h b/src/corelib/statemachine/qabstractstate.h
new file mode 100644
index 0000000..d0ebb52
--- /dev/null
+++ b/src/corelib/statemachine/qabstractstate.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QABSTRACTSTATE_H
+#define QABSTRACTSTATE_H
+
+#include <QtCore/qobject.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QState;
+class QStateMachine;
+
+class QAbstractStatePrivate;
+class Q_CORE_EXPORT QAbstractState : public QObject
+{
+ Q_OBJECT
+public:
+ ~QAbstractState();
+
+ QState *parentState() const;
+ QStateMachine *machine() const;
+
+Q_SIGNALS:
+ void entered();
+ void exited();
+
+protected:
+ QAbstractState(QState *parent = 0);
+
+ virtual void onEntry(QEvent *event) = 0;
+ virtual void onExit(QEvent *event) = 0;
+
+ bool event(QEvent *e);
+
+protected:
+ QAbstractState(QAbstractStatePrivate &dd, QState *parent);
+
+private:
+ Q_DISABLE_COPY(QAbstractState)
+ Q_DECLARE_PRIVATE(QAbstractState)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h
new file mode 100644
index 0000000..b4f3108
--- /dev/null
+++ b/src/corelib/statemachine/qabstractstate_p.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QABSTRACTSTATE_P_H
+#define QABSTRACTSTATE_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 <private/qobject_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QStateMachine;
+
+class QAbstractState;
+class QAbstractStatePrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QAbstractState)
+
+public:
+ QAbstractStatePrivate();
+
+ static QAbstractStatePrivate *get(QAbstractState *q);
+
+ QStateMachine *machine() const;
+
+ void callOnEntry(QEvent *e);
+ void callOnExit(QEvent *e);
+
+ void emitEntered();
+ void emitExited();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/corelib/statemachine/qabstracttransition.cpp b/src/corelib/statemachine/qabstracttransition.cpp
new file mode 100644
index 0000000..dfcafeb
--- /dev/null
+++ b/src/corelib/statemachine/qabstracttransition.cpp
@@ -0,0 +1,342 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qabstracttransition.h"
+#include "qabstracttransition_p.h"
+#include "qabstractstate.h"
+#include "qstate.h"
+#include "qstatemachine.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QAbstractTransition
+
+ \brief The QAbstractTransition class is the base class of transitions between QAbstractState objects.
+
+ \since 4.6
+ \ingroup statemachine
+
+ The QAbstractTransition class is the abstract base class of transitions
+ between states (QAbstractState objects) of a
+ QStateMachine. QAbstractTransition is part of \l{The State Machine
+ Framework}.
+
+ The sourceState() function returns the source of the transition. The
+ targetStates() function returns the targets of the transition. The machine()
+ function returns the state machine that the transition is part of.
+
+ Transitions can cause animations to be played. Use the addAnimation()
+ function to add an animation to the transition.
+
+ \section1 Subclassing
+
+ The eventTest() function is called by the state machine to determine whether
+ an event should trigger the transition. In your reimplementation you
+ typically check the event type and cast the event object to the proper type,
+ and check that one or more properties of the event meet your criteria.
+
+ The onTransition() function is called when the transition is triggered;
+ reimplement this function to perform custom processing for the transition.
+*/
+
+/*!
+ \property QAbstractTransition::sourceState
+
+ \brief the source state (parent) of this transition
+*/
+
+/*!
+ \property QAbstractTransition::targetState
+
+ \brief the target state of this transition
+*/
+
+/*!
+ \property QAbstractTransition::targetStates
+
+ \brief the target states of this transition
+
+ If multiple states are specified, all must be descendants of the same
+ parallel group state.
+*/
+
+QAbstractTransitionPrivate::QAbstractTransitionPrivate()
+{
+}
+
+QAbstractTransitionPrivate *QAbstractTransitionPrivate::get(QAbstractTransition *q)
+{
+ return q->d_func();
+}
+
+QStateMachine *QAbstractTransitionPrivate::machine() const
+{
+ Q_Q(const QAbstractTransition);
+ QObject *par = q->parent();
+ while (par != 0) {
+ if (QStateMachine *mach = qobject_cast<QStateMachine*>(par))
+ return mach;
+ par = par->parent();
+ }
+ return 0;
+}
+
+bool QAbstractTransitionPrivate::callEventTest(QEvent *e)
+{
+ Q_Q(QAbstractTransition);
+ return q->eventTest(e);
+}
+
+void QAbstractTransitionPrivate::callOnTransition(QEvent *e)
+{
+ Q_Q(QAbstractTransition);
+ q->onTransition(e);
+}
+
+QState *QAbstractTransitionPrivate::sourceState() const
+{
+ Q_Q(const QAbstractTransition);
+ return qobject_cast<QState*>(q->parent());
+}
+
+/*!
+ Constructs a new QAbstractTransition object with the given \a sourceState.
+*/
+QAbstractTransition::QAbstractTransition(QState *sourceState)
+ : QObject(*new QAbstractTransitionPrivate, sourceState)
+{
+}
+
+/*!
+ Constructs a new QAbstractTransition object with the given \a targets and \a
+ sourceState.
+*/
+QAbstractTransition::QAbstractTransition(const QList<QAbstractState*> &targets,
+ QState *sourceState)
+ : QObject(*new QAbstractTransitionPrivate, sourceState)
+{
+ setTargetStates(targets);
+}
+
+/*!
+ \internal
+*/
+QAbstractTransition::QAbstractTransition(QAbstractTransitionPrivate &dd,
+ QState *parent)
+ : QObject(dd, parent)
+{
+}
+
+/*!
+ \internal
+*/
+QAbstractTransition::QAbstractTransition(QAbstractTransitionPrivate &dd,
+ const QList<QAbstractState*> &targets,
+ QState *parent)
+ : QObject(dd, parent)
+{
+ setTargetStates(targets);
+}
+
+/*!
+ Destroys this transition.
+*/
+QAbstractTransition::~QAbstractTransition()
+{
+}
+
+/*!
+ Returns the source state of this transition, or 0 if this transition has no
+ source state.
+*/
+QState *QAbstractTransition::sourceState() const
+{
+ Q_D(const QAbstractTransition);
+ return d->sourceState();
+}
+
+/*!
+ Returns the target state of this transition, or 0 if the transition has no
+ target.
+*/
+QAbstractState *QAbstractTransition::targetState() const
+{
+ Q_D(const QAbstractTransition);
+ if (d->targetStates.isEmpty())
+ return 0;
+ return d->targetStates.first();
+}
+
+/*!
+ Sets the \a target state of this transition.
+*/
+void QAbstractTransition::setTargetState(QAbstractState* target)
+{
+ Q_D(QAbstractTransition);
+ if (!target)
+ d->targetStates.clear();
+ else
+ setTargetStates(QList<QAbstractState*>() << target);
+}
+
+/*!
+ Returns the target states of this transition, or an empty list if this
+ transition has no target states.
+*/
+QList<QAbstractState*> QAbstractTransition::targetStates() const
+{
+ Q_D(const QAbstractTransition);
+ QList<QAbstractState*> result;
+ for (int i = 0; i < d->targetStates.size(); ++i) {
+ QAbstractState *target = d->targetStates.at(i);
+ if (target)
+ result.append(target);
+ }
+ return result;
+}
+
+/*!
+ Sets the target states of this transition to be the given \a targets.
+*/
+void QAbstractTransition::setTargetStates(const QList<QAbstractState*> &targets)
+{
+ Q_D(QAbstractTransition);
+
+ for (int i=0; i<targets.size(); ++i) {
+ QAbstractState *target = targets.at(i);
+ if (!target) {
+ qWarning("QAbstractTransition::setTargetStates: target state(s) cannot be null");
+ return;
+ }
+ if (target->machine() != 0 && target->machine()->rootState() == target) {
+ qWarning("QAbstractTransition::setTargetStates: root state cannot be target of transition");
+ return;
+ }
+ }
+
+ d->targetStates.clear();
+ for (int i = 0; i < targets.size(); ++i)
+ d->targetStates.append(targets.at(i));
+}
+
+/*!
+ Returns the state machine that this transition is part of, or 0 if the
+ transition is not part of a state machine.
+*/
+QStateMachine *QAbstractTransition::machine() const
+{
+ Q_D(const QAbstractTransition);
+ return d->machine();
+}
+
+#ifndef QT_NO_ANIMATION
+
+/*!
+ Adds the given \a animation to this transition.
+ The transition does not take ownership of the animation.
+
+ \sa removeAnimation(), animations()
+*/
+void QAbstractTransition::addAnimation(QAbstractAnimation *animation)
+{
+ Q_D(QAbstractTransition);
+ if (!animation) {
+ qWarning("QAbstractTransition::addAnimation: cannot add null animation");
+ return;
+ }
+ d->animations.append(animation);
+}
+
+/*!
+ Removes the given \a animation from this transition.
+
+ \sa addAnimation()
+*/
+void QAbstractTransition::removeAnimation(QAbstractAnimation *animation)
+{
+ Q_D(QAbstractTransition);
+ if (!animation) {
+ qWarning("QAbstractTransition::removeAnimation: cannot remove null animation");
+ return;
+ }
+ d->animations.removeOne(animation);
+}
+
+/*!
+ Returns the list of animations associated with this transition, or an empty
+ list if it has no animations.
+
+ \sa addAnimation()
+*/
+QList<QAbstractAnimation*> QAbstractTransition::animations() const
+{
+ Q_D(const QAbstractTransition);
+ return d->animations;
+}
+
+#endif
+
+/*!
+ \fn QAbstractTransition::eventTest(QEvent *event)
+
+ This function is called to determine whether the given \a event should cause
+ this transition to trigger. Reimplement this function and return true if the
+ event should trigger the transition, otherwise return false.
+*/
+
+/*!
+ \fn QAbstractTransition::onTransition(QEvent *event)
+
+ This function is called when the transition is triggered. The given \a event
+ is what caused the transition to trigger. Reimplement this function to
+ perform custom processing when the transition is triggered.
+*/
+
+/*!
+ \reimp
+*/
+bool QAbstractTransition::event(QEvent *e)
+{
+ return QObject::event(e);
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qabstracttransition.h b/src/corelib/statemachine/qabstracttransition.h
new file mode 100644
index 0000000..c63d55a
--- /dev/null
+++ b/src/corelib/statemachine/qabstracttransition.h
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QABSTRACTTRANSITION_H
+#define QABSTRACTTRANSITION_H
+
+#include <QtCore/qobject.h>
+
+#include <QtCore/qlist.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QEvent;
+class QAbstractState;
+class QState;
+class QStateMachine;
+
+#ifndef QT_NO_ANIMATION
+class QAbstractAnimation;
+#endif
+
+class QAbstractTransitionPrivate;
+class Q_CORE_EXPORT QAbstractTransition : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QState* sourceState READ sourceState)
+ Q_PROPERTY(QAbstractState* targetState READ targetState WRITE setTargetState)
+ Q_PROPERTY(QList<QAbstractState*> targetStates READ targetStates WRITE setTargetStates)
+public:
+ QAbstractTransition(QState *sourceState = 0);
+ QAbstractTransition(const QList<QAbstractState*> &targets, QState *sourceState = 0);
+ virtual ~QAbstractTransition();
+
+ QState *sourceState() const;
+ QAbstractState *targetState() const;
+ void setTargetState(QAbstractState* target);
+ QList<QAbstractState*> targetStates() const;
+ void setTargetStates(const QList<QAbstractState*> &targets);
+
+ QStateMachine *machine() const;
+
+#ifndef QT_NO_ANIMATION
+ void addAnimation(QAbstractAnimation *animation);
+ void removeAnimation(QAbstractAnimation *animation);
+ QList<QAbstractAnimation*> animations() const;
+#endif
+
+protected:
+ virtual bool eventTest(QEvent *event) = 0;
+
+ virtual void onTransition(QEvent *event) = 0;
+
+ bool event(QEvent *e);
+
+protected:
+ QAbstractTransition(QAbstractTransitionPrivate &dd, QState *parent);
+ QAbstractTransition(QAbstractTransitionPrivate &dd,
+ const QList<QAbstractState*> &targets, QState *parent);
+
+private:
+ Q_DISABLE_COPY(QAbstractTransition)
+ Q_DECLARE_PRIVATE(QAbstractTransition)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/corelib/statemachine/qabstracttransition_p.h b/src/corelib/statemachine/qabstracttransition_p.h
new file mode 100644
index 0000000..f067984
--- /dev/null
+++ b/src/corelib/statemachine/qabstracttransition_p.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QABSTRACTTRANSITION_P_H
+#define QABSTRACTTRANSITION_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 <private/qobject_p.h>
+
+#include <QtCore/qlist.h>
+#include <QtCore/qpointer.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAbstractState;
+class QState;
+class QStateMachine;
+
+class QAbstractTransition;
+class Q_CORE_EXPORT QAbstractTransitionPrivate
+ : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QAbstractTransition)
+public:
+ QAbstractTransitionPrivate();
+
+ static QAbstractTransitionPrivate *get(QAbstractTransition *q);
+
+ bool callEventTest(QEvent *e);
+ void callOnTransition(QEvent *e);
+ QState *sourceState() const;
+ QStateMachine *machine() const;
+
+ QList<QPointer<QAbstractState> > targetStates;
+
+#ifndef QT_NO_ANIMATION
+ QList<QAbstractAnimation*> animations;
+#endif
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/corelib/statemachine/qeventtransition.cpp b/src/corelib/statemachine/qeventtransition.cpp
new file mode 100644
index 0000000..f25d821
--- /dev/null
+++ b/src/corelib/statemachine/qeventtransition.cpp
@@ -0,0 +1,285 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qeventtransition.h"
+#include "qeventtransition_p.h"
+#include "qwrappedevent.h"
+#include "qstate.h"
+#include "qstate_p.h"
+#include "qstatemachine.h"
+#include "qstatemachine_p.h"
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QEventTransition
+
+ \brief The QEventTransition class provides a QObject-specific transition for Qt events.
+
+ \since 4.6
+ \ingroup statemachine
+
+ A QEventTransition object binds an event to a particular QObject.
+ QEventTransition is part of \l{The State Machine Framework}.
+
+ Example:
+
+ \code
+ QPushButton *button = ...;
+ QState *s1 = ...;
+ QState *s2 = ...;
+ // If in s1 and the button receives an Enter event, transition to s2
+ QEventTransition *enterTransition = new QEventTransition(button, QEvent::Enter);
+ enterTransition->setTargetState(s2);
+ s1->addTransition(enterTransition);
+ // If in s2 and the button receives an Exit event, transition back to s1
+ QEventTransition *leaveTransition = new QEventTransition(button, QEvent::Leave);
+ leaveTransition->setTargetState(s1);
+ s2->addTransition(leaveTransition);
+ \endcode
+
+ \section1 Subclassing
+
+ When reimplementing the eventTest() function, you should first call the base
+ implementation to verify that the event is a QWrappedEvent for the proper
+ object and event type. You may then cast the event to a QWrappedEvent and
+ get the original event by calling QWrappedEvent::event(), and perform
+ additional checks on that object.
+
+ \sa QState::addTransition()
+*/
+
+/*!
+ \property QEventTransition::eventObject
+
+ \brief the event source that this event transition is associated with
+*/
+
+/*!
+ \property QEventTransition::eventType
+
+ \brief the type of event that this event transition is associated with
+*/
+QEventTransitionPrivate::QEventTransitionPrivate()
+{
+ object = 0;
+ eventType = QEvent::None;
+ registered = false;
+}
+
+QEventTransitionPrivate *QEventTransitionPrivate::get(QEventTransition *q)
+{
+ return q->d_func();
+}
+
+void QEventTransitionPrivate::unregister()
+{
+ Q_Q(QEventTransition);
+ if (!registered || !machine())
+ return;
+ QStateMachinePrivate::get(machine())->unregisterEventTransition(q);
+}
+
+void QEventTransitionPrivate::maybeRegister()
+{
+ Q_Q(QEventTransition);
+ if (!machine() || !machine()->configuration().contains(sourceState()))
+ return;
+ QStateMachinePrivate::get(machine())->registerEventTransition(q);
+}
+
+/*!
+ Constructs a new QEventTransition object with the given \a sourceState.
+*/
+QEventTransition::QEventTransition(QState *sourceState)
+ : QAbstractTransition(*new QEventTransitionPrivate, sourceState)
+{
+}
+
+/*!
+ Constructs a new QEventTransition object associated with events of the given
+ \a type for the given \a object, and with the given \a sourceState.
+*/
+QEventTransition::QEventTransition(QObject *object, QEvent::Type type,
+ QState *sourceState)
+ : QAbstractTransition(*new QEventTransitionPrivate, sourceState)
+{
+ Q_D(QEventTransition);
+ d->registered = false;
+ d->object = object;
+ d->eventType = type;
+}
+
+/*!
+ Constructs a new QEventTransition object associated with events of the given
+ \a type for the given \a object. The transition has the given \a targets and
+ \a sourceState.
+*/
+QEventTransition::QEventTransition(QObject *object, QEvent::Type type,
+ const QList<QAbstractState*> &targets,
+ QState *sourceState)
+ : QAbstractTransition(*new QEventTransitionPrivate, targets, sourceState)
+{
+ Q_D(QEventTransition);
+ d->registered = false;
+ d->object = object;
+ d->eventType = type;
+}
+
+/*!
+ \internal
+*/
+QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QState *parent)
+ : QAbstractTransition(dd, parent)
+{
+}
+
+/*!
+ \internal
+*/
+QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QObject *object,
+ QEvent::Type type, QState *parent)
+ : QAbstractTransition(dd, parent)
+{
+ Q_D(QEventTransition);
+ d->registered = false;
+ d->object = object;
+ d->eventType = type;
+}
+
+/*!
+ \internal
+*/
+QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QObject *object,
+ QEvent::Type type, const QList<QAbstractState*> &targets,
+ QState *parent)
+ : QAbstractTransition(dd, targets, parent)
+{
+ Q_D(QEventTransition);
+ d->registered = false;
+ d->object = object;
+ d->eventType = type;
+}
+
+/*!
+ Destroys this QObject event transition.
+*/
+QEventTransition::~QEventTransition()
+{
+}
+
+/*!
+ Returns the event type that this event transition is associated with.
+*/
+QEvent::Type QEventTransition::eventType() const
+{
+ Q_D(const QEventTransition);
+ return d->eventType;
+}
+
+/*!
+ Sets the event \a type that this event transition is associated with.
+*/
+void QEventTransition::setEventType(QEvent::Type type)
+{
+ Q_D(QEventTransition);
+ if (d->eventType == type)
+ return;
+ d->unregister();
+ d->eventType = type;
+ d->maybeRegister();
+}
+
+/*!
+ Returns the event source associated with this event transition.
+*/
+QObject *QEventTransition::eventObject() const
+{
+ Q_D(const QEventTransition);
+ return d->object;
+}
+
+/*!
+ Sets the event source associated with this event transition to be the given
+ \a object.
+*/
+void QEventTransition::setEventObject(QObject *object)
+{
+ Q_D(QEventTransition);
+ if (d->object == object)
+ return;
+ d->unregister();
+ d->object = object;
+ d->maybeRegister();
+}
+
+/*!
+ \reimp
+*/
+bool QEventTransition::eventTest(QEvent *event)
+{
+ Q_D(const QEventTransition);
+ if (event->type() == QEvent::Wrapped) {
+ QWrappedEvent *we = static_cast<QWrappedEvent*>(event);
+ return (we->object() == d->object)
+ && (we->event()->type() == d->eventType);
+ }
+ return false;
+}
+
+/*!
+ \reimp
+*/
+void QEventTransition::onTransition(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+/*!
+ \reimp
+*/
+bool QEventTransition::event(QEvent *e)
+{
+ return QAbstractTransition::event(e);
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qeventtransition.h b/src/corelib/statemachine/qeventtransition.h
new file mode 100644
index 0000000..3530bdd
--- /dev/null
+++ b/src/corelib/statemachine/qeventtransition.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QEVENTTRANSITION_H
+#define QEVENTTRANSITION_H
+
+#include <QtCore/qabstracttransition.h>
+#include <QtCore/qcoreevent.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QEventTransitionPrivate;
+class Q_CORE_EXPORT QEventTransition : public QAbstractTransition
+{
+ Q_OBJECT
+ Q_PROPERTY(QObject* eventObject READ eventObject WRITE setEventObject)
+ Q_PROPERTY(QEvent::Type eventType READ eventType WRITE setEventType)
+public:
+ QEventTransition(QState *sourceState = 0);
+ QEventTransition(QObject *object, QEvent::Type type, QState *sourceState = 0);
+ QEventTransition(QObject *object, QEvent::Type type,
+ const QList<QAbstractState*> &targets, QState *sourceState = 0);
+ ~QEventTransition();
+
+ QObject *eventObject() const;
+ void setEventObject(QObject *object);
+
+ QEvent::Type eventType() const;
+ void setEventType(QEvent::Type type);
+
+protected:
+ bool eventTest(QEvent *event);
+ void onTransition(QEvent *event);
+
+ bool event(QEvent *e);
+
+protected:
+ QEventTransition(QEventTransitionPrivate &dd, QState *parent);
+ QEventTransition(QEventTransitionPrivate &dd, QObject *object,
+ QEvent::Type type, QState *parent);
+ QEventTransition(QEventTransitionPrivate &dd, QObject *object,
+ QEvent::Type type, const QList<QAbstractState*> &targets,
+ QState *parent);
+
+private:
+ Q_DISABLE_COPY(QEventTransition)
+ Q_DECLARE_PRIVATE(QEventTransition)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/corelib/statemachine/qeventtransition_p.h b/src/corelib/statemachine/qeventtransition_p.h
new file mode 100644
index 0000000..600cec0
--- /dev/null
+++ b/src/corelib/statemachine/qeventtransition_p.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QEVENTTRANSITION_P_H
+#define QEVENTTRANSITION_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 "qabstracttransition_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QEventTransition;
+class Q_CORE_EXPORT QEventTransitionPrivate : public QAbstractTransitionPrivate
+{
+ Q_DECLARE_PUBLIC(QEventTransition)
+public:
+ QEventTransitionPrivate();
+
+ static QEventTransitionPrivate *get(QEventTransition *q);
+
+ void unregister();
+ void maybeRegister();
+
+ bool registered;
+ QObject *object;
+ QEvent::Type eventType;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/corelib/statemachine/qfinalstate.cpp b/src/corelib/statemachine/qfinalstate.cpp
new file mode 100644
index 0000000..0980336
--- /dev/null
+++ b/src/corelib/statemachine/qfinalstate.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qfinalstate.h"
+#include "qabstractstate_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QFinalState
+
+ \brief The QFinalState class provides a final state.
+
+ \since 4.6
+ \ingroup statemachine
+
+ A final state is used to communicate that (part of) a QStateMachine has
+ finished its work. When a final top-level state is entered, the state
+ machine's \l{QStateMachine::finished()}{finished}() signal is emitted. In
+ general, when a final substate (a child of a QState) is entered, the parent
+ state's \l{QState::finished()}{finished}() signal is emitted. QFinalState
+ is part of \l{The State Machine Framework}.
+
+ To use a final state, you create a QFinalState object and add a transition
+ to it from another state. Example:
+
+ \code
+ QPushButton button;
+
+ QStateMachine machine;
+ QState *s1 = new QState();
+ QFinalState *s2 = new QFinalState();
+ s1->addTransition(&button, SIGNAL(clicked()), s2);
+ machine.addState(s1);
+ machine.addState(s2);
+
+ QObject::connect(&machine, SIGNAL(finished()), QApplication::instance(), SLOT(quit()));
+ machine.setInitialState(s1);
+ machine.start();
+ \endcode
+
+ \sa QStateMachine::finished(), QState::finished()
+*/
+
+class QFinalStatePrivate : public QAbstractStatePrivate
+{
+ Q_DECLARE_PUBLIC(QFinalState)
+
+public:
+ QFinalStatePrivate();
+};
+
+QFinalStatePrivate::QFinalStatePrivate()
+{
+}
+
+/*!
+ Constructs a new QFinalState object with the given \a parent state.
+*/
+QFinalState::QFinalState(QState *parent)
+ : QAbstractState(*new QFinalStatePrivate, parent)
+{
+}
+
+/*!
+ Destroys this final state.
+*/
+QFinalState::~QFinalState()
+{
+}
+
+/*!
+ \reimp
+*/
+void QFinalState::onEntry(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+/*!
+ \reimp
+*/
+void QFinalState::onExit(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+/*!
+ \reimp
+*/
+bool QFinalState::event(QEvent *e)
+{
+ return QAbstractState::event(e);
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qfinalstate.h b/src/corelib/statemachine/qfinalstate.h
new file mode 100644
index 0000000..fa68394
--- /dev/null
+++ b/src/corelib/statemachine/qfinalstate.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QFINALSTATE_H
+#define QFINALSTATE_H
+
+#include <QtCore/qabstractstate.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QFinalStatePrivate;
+class Q_CORE_EXPORT QFinalState : public QAbstractState
+{
+ Q_OBJECT
+public:
+ QFinalState(QState *parent = 0);
+ ~QFinalState();
+
+protected:
+ void onEntry(QEvent *event);
+ void onExit(QEvent *event);
+
+ bool event(QEvent *e);
+
+private:
+ Q_DISABLE_COPY(QFinalState)
+ Q_DECLARE_PRIVATE(QFinalState)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/corelib/statemachine/qhistorystate.cpp b/src/corelib/statemachine/qhistorystate.cpp
new file mode 100644
index 0000000..517faa8
--- /dev/null
+++ b/src/corelib/statemachine/qhistorystate.cpp
@@ -0,0 +1,223 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qhistorystate.h"
+#include "qhistorystate_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QHistoryState
+
+ \brief The QHistoryState class provides a means of returning to a previously active substate.
+
+ \since 4.6
+ \ingroup statemachine
+
+ A history state is a pseudo-state that represents the child state that the
+ parent state was in the last time the parent state was exited. A transition
+ with a history state as its target is in fact a transition to one of the
+ other child states of the parent state. QHistoryState is part of \l{The
+ State Machine Framework}.
+
+ Use the setDefaultState() function to set the state that should be entered
+ if the parent state has never been entered. Example:
+
+ \code
+ QStateMachine machine;
+
+ QState *s1 = new QState();
+ QState *s11 = new QState(s1);
+ QState *s12 = new QState(s1);
+
+ QHistoryState *s1h = new QHistoryState(s1);
+ s1h->setDefaultState(s11);
+
+ machine.addState(s1);
+
+ QState *s2 = new QState();
+ machine.addState(s2);
+
+ QPushButton *button = new QPushButton();
+ // Clicking the button will cause the state machine to enter the child state
+ // that s1 was in the last time s1 was exited, or the history state's default
+ // state if s1 has never been entered.
+ s1->addTransition(button, SIGNAL(clicked()), s1h);
+ \endcode
+
+ By default a history state is shallow, meaning that it won't remember nested
+ states. This can be configured through the historyType property.
+*/
+
+/*!
+ \property QHistoryState::defaultState
+
+ \brief the default state of this history state
+*/
+
+/*!
+ \property QHistoryState::historyType
+
+ \brief the type of history that this history state records
+
+ The default value of this property is QHistoryState::ShallowHistory.
+*/
+
+/*!
+ \enum QHistoryState::HistoryType
+
+ This enum specifies the type of history that a QHistoryState records.
+
+ \value ShallowHistory Only the immediate child states of the parent state
+ are recorded. In this case a transition with the history state as its
+ target will end up in the immediate child state that the parent was in the
+ last time it was exited. This is the default.
+
+ \value DeepHistory Nested states are recorded. In this case a transition
+ with the history state as its target will end up in the most deeply nested
+ descendant state the parent was in the last time it was exited.
+*/
+
+QHistoryStatePrivate::QHistoryStatePrivate()
+ : defaultState(0)
+{
+}
+
+QHistoryStatePrivate *QHistoryStatePrivate::get(QHistoryState *q)
+{
+ return q->d_func();
+}
+
+/*!
+ Constructs a new shallow history state with the given \a parent state.
+*/
+QHistoryState::QHistoryState(QState *parent)
+ : QAbstractState(*new QHistoryStatePrivate, parent)
+{
+ Q_D(QHistoryState);
+ d->historyType = ShallowHistory;
+}
+/*!
+ Constructs a new history state of the given \a type, with the given \a
+ parent state.
+*/
+QHistoryState::QHistoryState(HistoryType type, QState *parent)
+ : QAbstractState(*new QHistoryStatePrivate, parent)
+{
+ Q_D(QHistoryState);
+ d->historyType = type;
+}
+
+/*!
+ Destroys this history state.
+*/
+QHistoryState::~QHistoryState()
+{
+}
+
+/*!
+ Returns this history state's default state. The default state indicates the
+ state to transition to if the parent state has never been entered before.
+*/
+QAbstractState *QHistoryState::defaultState() const
+{
+ Q_D(const QHistoryState);
+ return d->defaultState;
+}
+
+/*!
+ Sets this history state's default state to be the given \a state.
+ \a state must be a sibling of this history state.
+*/
+void QHistoryState::setDefaultState(QAbstractState *state)
+{
+ Q_D(QHistoryState);
+ if (state && state->parentState() != parentState()) {
+ qWarning("QHistoryState::setDefaultState: state %p does not belong "
+ "to this history state's group (%p)", state, parentState());
+ return;
+ }
+ d->defaultState = state;
+}
+
+/*!
+ Returns the type of history that this history state records.
+*/
+QHistoryState::HistoryType QHistoryState::historyType() const
+{
+ Q_D(const QHistoryState);
+ return d->historyType;
+}
+
+/*!
+ Sets the \a type of history that this history state records.
+*/
+void QHistoryState::setHistoryType(HistoryType type)
+{
+ Q_D(QHistoryState);
+ d->historyType = type;
+}
+
+/*!
+ \reimp
+*/
+void QHistoryState::onEntry(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+/*!
+ \reimp
+*/
+void QHistoryState::onExit(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+/*!
+ \reimp
+*/
+bool QHistoryState::event(QEvent *e)
+{
+ return QAbstractState::event(e);
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qhistorystate.h b/src/corelib/statemachine/qhistorystate.h
new file mode 100644
index 0000000..a0682bd
--- /dev/null
+++ b/src/corelib/statemachine/qhistorystate.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QHISTORYSTATE_H
+#define QHISTORYSTATE_H
+
+#include <QtCore/qabstractstate.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QHistoryStatePrivate;
+class Q_CORE_EXPORT QHistoryState : public QAbstractState
+{
+ Q_OBJECT
+ Q_PROPERTY(QAbstractState* defaultState READ defaultState WRITE setDefaultState)
+ Q_PROPERTY(HistoryType historyType READ historyType WRITE setHistoryType)
+ Q_ENUMS(HistoryType)
+public:
+ enum HistoryType {
+ ShallowHistory,
+ DeepHistory
+ };
+
+ QHistoryState(QState *parent = 0);
+ QHistoryState(HistoryType type, QState *parent = 0);
+ ~QHistoryState();
+
+ QAbstractState *defaultState() const;
+ void setDefaultState(QAbstractState *state);
+
+ HistoryType historyType() const;
+ void setHistoryType(HistoryType type);
+
+protected:
+ void onEntry(QEvent *event);
+ void onExit(QEvent *event);
+
+ bool event(QEvent *e);
+
+private:
+ Q_DISABLE_COPY(QHistoryState)
+ Q_DECLARE_PRIVATE(QHistoryState)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/corelib/statemachine/qhistorystate_p.h b/src/corelib/statemachine/qhistorystate_p.h
new file mode 100644
index 0000000..5aaa64c
--- /dev/null
+++ b/src/corelib/statemachine/qhistorystate_p.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QHISTORYSTATE_P_H
+#define QHISTORYSTATE_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 "qabstractstate_p.h"
+
+#include <QtCore/qlist.h>
+
+QT_BEGIN_NAMESPACE
+
+class QHistoryState;
+class QHistoryStatePrivate : public QAbstractStatePrivate
+{
+ Q_DECLARE_PUBLIC(QHistoryState)
+
+public:
+ QHistoryStatePrivate();
+
+ static QHistoryStatePrivate *get(QHistoryState *q);
+
+ QAbstractState *defaultState;
+ QHistoryState::HistoryType historyType;
+ QList<QAbstractState*> configuration;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/corelib/statemachine/qsignalevent.h b/src/corelib/statemachine/qsignalevent.h
new file mode 100644
index 0000000..8221f68
--- /dev/null
+++ b/src/corelib/statemachine/qsignalevent.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSIGNALEVENT_H
+#define QSIGNALEVENT_H
+
+#include <QtCore/qcoreevent.h>
+
+#include <QtCore/qlist.h>
+#include <QtCore/qvariant.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class Q_CORE_EXPORT QSignalEvent : public QEvent
+{
+public:
+ QSignalEvent(const QObject *sender, int signalIndex,
+ const QList<QVariant> &arguments);
+ ~QSignalEvent();
+
+ inline const QObject *sender() const { return m_sender; }
+ inline int signalIndex() const { return m_signalIndex; }
+ inline QList<QVariant> arguments() const { return m_arguments; }
+
+private:
+ const QObject *m_sender;
+ int m_signalIndex;
+ QList<QVariant> m_arguments;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/corelib/statemachine/qsignaleventgenerator_p.h b/src/corelib/statemachine/qsignaleventgenerator_p.h
new file mode 100644
index 0000000..cf0ea1e
--- /dev/null
+++ b/src/corelib/statemachine/qsignaleventgenerator_p.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSIGNALEVENTGENERATOR_P_H
+#define QSIGNALEVENTGENERATOR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+
+QT_BEGIN_NAMESPACE
+
+class QStateMachine;
+
+class QSignalEventGenerator : public QObject
+{
+public:
+ QSignalEventGenerator(QStateMachine *parent);
+
+ static const QMetaObject staticMetaObject;
+ virtual const QMetaObject *metaObject() const;
+ virtual void *qt_metacast(const char *);
+ virtual int qt_metacall(QMetaObject::Call, int, void **argv);
+
+private:
+ Q_DISABLE_COPY(QSignalEventGenerator)
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/corelib/statemachine/qsignaltransition.cpp b/src/corelib/statemachine/qsignaltransition.cpp
new file mode 100644
index 0000000..9ffcb9c
--- /dev/null
+++ b/src/corelib/statemachine/qsignaltransition.cpp
@@ -0,0 +1,260 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsignaltransition.h"
+#include "qsignaltransition_p.h"
+#include "qsignalevent.h"
+#include "qstate.h"
+#include "qstate_p.h"
+#include "qstatemachine.h"
+#include "qstatemachine_p.h"
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QSignalTransition
+
+ \brief The QSignalTransition class provides a transition based on a Qt signal.
+
+ \since 4.6
+ \ingroup statemachine
+
+ Typically you would use the overload of QState::addTransition() that takes a
+ sender and signal as arguments, rather than creating QSignalTransition
+ objects directly. QSignalTransition is part of \l{The State Machine
+ Framework}.
+
+ You can subclass QSignalTransition and reimplement eventTest() to make a
+ signal transition conditional; the event object passed to eventTest() will
+ be a QSignalEvent object. Example:
+
+ \code
+ class CheckedTransition : public QSignalTransition
+ {
+ public:
+ CheckedTransition(QCheckBox *check)
+ : QSignalTransition(check, SIGNAL(stateChanged(int))) {}
+ protected:
+ bool eventTest(QEvent *e) const {
+ if (!QSignalTransition::eventTest(e))
+ return false;
+ QSignalEvent *se = static_cast<QSignalEvent*>(e);
+ return (se->arguments().at(0).toInt() == Qt::Checked);
+ }
+ };
+
+ ...
+
+ QCheckBox *check = new QCheckBox();
+ check->setTristate(true);
+
+ QState *s1 = new QState();
+ QState *s2 = new QState();
+ CheckedTransition *t1 = new CheckedTransition(check);
+ t1->setTargetState(s2);
+ s1->addTransition(t1);
+ \endcode
+*/
+
+/*!
+ \property QSignalTransition::senderObject
+
+ \brief the sender object that this signal transition is associated with
+*/
+
+/*!
+ \property QSignalTransition::signal
+
+ \brief the signal that this signal transition is associated with
+*/
+
+QSignalTransitionPrivate::QSignalTransitionPrivate()
+{
+ sender = 0;
+ signalIndex = -1;
+}
+
+QSignalTransitionPrivate *QSignalTransitionPrivate::get(QSignalTransition *q)
+{
+ return q->d_func();
+}
+
+void QSignalTransitionPrivate::unregister()
+{
+ Q_Q(QSignalTransition);
+ if ((signalIndex == -1) || !machine())
+ return;
+ QStateMachinePrivate::get(machine())->unregisterSignalTransition(q);
+}
+
+void QSignalTransitionPrivate::maybeRegister()
+{
+ Q_Q(QSignalTransition);
+ if (!machine() || !machine()->configuration().contains(sourceState()))
+ return;
+ QStateMachinePrivate::get(machine())->registerSignalTransition(q);
+}
+
+/*!
+ Constructs a new signal transition with the given \a sourceState.
+*/
+QSignalTransition::QSignalTransition(QState *sourceState)
+ : QAbstractTransition(*new QSignalTransitionPrivate, sourceState)
+{
+}
+
+/*!
+ Constructs a new signal transition associated with the given \a signal of
+ the given \a sender, and with the given \a sourceState.
+*/
+QSignalTransition::QSignalTransition(QObject *sender, const char *signal,
+ QState *sourceState)
+ : QAbstractTransition(*new QSignalTransitionPrivate, sourceState)
+{
+ Q_D(QSignalTransition);
+ d->sender = sender;
+ d->signal = signal;
+}
+
+/*!
+ Constructs a new signal transition associated with the given \a signal of
+ the given \a sender. The transition has the given \a targets and \a
+ sourceState.
+*/
+QSignalTransition::QSignalTransition(QObject *sender, const char *signal,
+ const QList<QAbstractState*> &targets,
+ QState *sourceState)
+ : QAbstractTransition(*new QSignalTransitionPrivate, targets, sourceState)
+{
+ Q_D(QSignalTransition);
+ d->sender = sender;
+ d->signal = signal;
+}
+
+/*!
+ Destroys this signal transition.
+*/
+QSignalTransition::~QSignalTransition()
+{
+}
+
+/*!
+ Returns the sender object associated with this signal transition.
+*/
+QObject *QSignalTransition::senderObject() const
+{
+ Q_D(const QSignalTransition);
+ return d->sender;
+}
+
+/*!
+ Sets the \a sender object associated with this signal transition.
+*/
+void QSignalTransition::setSenderObject(QObject *sender)
+{
+ Q_D(QSignalTransition);
+ if (sender == d->sender)
+ return;
+ d->unregister();
+ d->sender = sender;
+ d->maybeRegister();
+}
+
+/*!
+ Returns the signal associated with this signal transition.
+*/
+QByteArray QSignalTransition::signal() const
+{
+ Q_D(const QSignalTransition);
+ return d->signal;
+}
+
+/*!
+ Sets the \a signal associated with this signal transition.
+*/
+void QSignalTransition::setSignal(const QByteArray &signal)
+{
+ Q_D(QSignalTransition);
+ if (signal == d->signal)
+ return;
+ d->unregister();
+ d->signal = signal;
+ d->maybeRegister();
+}
+
+/*!
+ \reimp
+
+ The \a event is a QSignalEvent object. The default implementation returns
+ true if the event's sender and signal index match this transition, and
+ returns false otherwise.
+*/
+bool QSignalTransition::eventTest(QEvent *event)
+{
+ Q_D(const QSignalTransition);
+ if (event->type() == QEvent::Signal) {
+ if (d->signalIndex == -1)
+ return false;
+ QSignalEvent *se = static_cast<QSignalEvent*>(event);
+ return (se->sender() == d->sender)
+ && (se->signalIndex() == d->signalIndex);
+ }
+ return false;
+}
+
+/*!
+ \reimp
+*/
+void QSignalTransition::onTransition(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+/*!
+ \reimp
+*/
+bool QSignalTransition::event(QEvent *e)
+{
+ return QAbstractTransition::event(e);
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qsignaltransition.h b/src/corelib/statemachine/qsignaltransition.h
new file mode 100644
index 0000000..b485785
--- /dev/null
+++ b/src/corelib/statemachine/qsignaltransition.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSIGNALTRANSITION_H
+#define QSIGNALTRANSITION_H
+
+#include <QtCore/qabstracttransition.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QSignalTransitionPrivate;
+class Q_CORE_EXPORT QSignalTransition : public QAbstractTransition
+{
+ Q_OBJECT
+ Q_PROPERTY(QObject* senderObject READ senderObject WRITE setSenderObject)
+ Q_PROPERTY(QByteArray signal READ signal WRITE setSignal)
+public:
+ QSignalTransition(QState *sourceState = 0);
+ QSignalTransition(QObject *sender, const char *signal,
+ QState *sourceState = 0);
+ QSignalTransition(QObject *sender, const char *signal,
+ const QList<QAbstractState*> &targets,
+ QState *sourceState = 0);
+ ~QSignalTransition();
+
+ QObject *senderObject() const;
+ void setSenderObject(QObject *sender);
+
+ QByteArray signal() const;
+ void setSignal(const QByteArray &signal);
+
+protected:
+ bool eventTest(QEvent *event);
+ void onTransition(QEvent *event);
+
+ bool event(QEvent *e);
+
+private:
+ Q_DISABLE_COPY(QSignalTransition)
+ Q_DECLARE_PRIVATE(QSignalTransition)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/corelib/statemachine/qsignaltransition_p.h b/src/corelib/statemachine/qsignaltransition_p.h
new file mode 100644
index 0000000..339de63
--- /dev/null
+++ b/src/corelib/statemachine/qsignaltransition_p.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSIGNALTRANSITION_P_H
+#define QSIGNALTRANSITION_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 "qabstracttransition_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSignalTransition;
+class QSignalTransitionPrivate : public QAbstractTransitionPrivate
+{
+ Q_DECLARE_PUBLIC(QSignalTransition)
+public:
+ QSignalTransitionPrivate();
+
+ static QSignalTransitionPrivate *get(QSignalTransition *q);
+
+ void unregister();
+ void maybeRegister();
+
+ QObject *sender;
+ QByteArray signal;
+ int signalIndex;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
new file mode 100644
index 0000000..5463059
--- /dev/null
+++ b/src/corelib/statemachine/qstate.cpp
@@ -0,0 +1,483 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qstate.h"
+#include "qstate_p.h"
+#include "qhistorystate.h"
+#include "qhistorystate_p.h"
+#include "qabstracttransition.h"
+#include "qabstracttransition_p.h"
+#include "qsignaltransition.h"
+#include "qstatemachine.h"
+#include "qstatemachine_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QState
+
+ \brief The QState class provides a general-purpose state for QStateMachine.
+
+ \since 4.6
+ \ingroup statemachine
+
+ QState objects can have child states, and can have transitions to other
+ states. QState is part of \l{The State Machine Framework}.
+
+ The addTransition() function adds a transition. The removeTransition()
+ function removes a transition.
+
+ The assignProperty() function is used for defining property assignments that
+ should be performed when a state is entered.
+
+ Top-level states must be passed QStateMachine::rootState() as their parent
+ state, or added to a state machine using QStateMachine::addState().
+
+ \section1 States with Child States
+
+ The childMode property determines how child states are treated. For
+ non-parallel state groups, the setInitialState() function must be called to
+ set the initial state. The child states are mutually exclusive states, and
+ the state machine needs to know which child state to enter when the parent
+ state is the target of a transition.
+
+ The state emits the QState::finished() signal when a final child state
+ (QFinalState) is entered.
+
+ The setErrorState() sets the state's error state. The error state is the
+ state that the state machine will transition to if an error is detected when
+ attempting to enter the state (e.g. because no initial state has been set).
+
+*/
+
+/*!
+ \property QState::initialState
+
+ \brief the initial state of this state (one of its child states)
+*/
+
+/*!
+ \property QState::errorState
+
+ \brief the error state of this state
+*/
+
+/*!
+ \property QState::childMode
+
+ \brief the child mode of this state
+
+ The default value of this property is QState::ExclusiveStates.
+*/
+
+/*!
+ \enum QState::ChildMode
+
+ This enum specifies how a state's child states are treated.
+
+ \value ExclusiveStates The child states are mutually exclusive and an
+ initial state must be set by calling QState::setInitialState().
+
+ \value ParallelStates The child states are parallel. When the parent state
+ is entered, all its child states are entered in parallel.
+*/
+
+QStatePrivate::QStatePrivate()
+ : errorState(0), initialState(0), childMode(QState::ExclusiveStates)
+{
+}
+
+QStatePrivate::~QStatePrivate()
+{
+}
+
+void QStatePrivate::emitFinished()
+{
+ Q_Q(QState);
+ emit q->finished();
+}
+
+void QStatePrivate::emitPolished()
+{
+ Q_Q(QState);
+ emit q->polished();
+}
+
+/*!
+ Constructs a new state with the given \a parent state.
+*/
+QState::QState(QState *parent)
+ : QAbstractState(*new QStatePrivate, parent)
+{
+}
+
+/*!
+ Constructs a new state with the given \a childMode and the given \a parent
+ state.
+*/
+QState::QState(ChildMode childMode, QState *parent)
+ : QAbstractState(*new QStatePrivate, parent)
+{
+ Q_D(QState);
+ d->childMode = childMode;
+}
+
+/*!
+ \internal
+*/
+QState::QState(QStatePrivate &dd, QState *parent)
+ : QAbstractState(dd, parent)
+{
+}
+
+/*!
+ Destroys this state.
+*/
+QState::~QState()
+{
+}
+
+QList<QAbstractState*> QStatePrivate::childStates() const
+{
+ QList<QAbstractState*> result;
+ QList<QObject*>::const_iterator it;
+ for (it = children.constBegin(); it != children.constEnd(); ++it) {
+ QAbstractState *s = qobject_cast<QAbstractState*>(*it);
+ if (!s || qobject_cast<QHistoryState*>(s))
+ continue;
+ result.append(s);
+ }
+ return result;
+}
+
+QList<QHistoryState*> QStatePrivate::historyStates() const
+{
+ QList<QHistoryState*> result;
+ QList<QObject*>::const_iterator it;
+ for (it = children.constBegin(); it != children.constEnd(); ++it) {
+ QHistoryState *h = qobject_cast<QHistoryState*>(*it);
+ if (h)
+ result.append(h);
+ }
+ return result;
+}
+
+QList<QAbstractTransition*> QStatePrivate::transitions() const
+{
+ QList<QAbstractTransition*> result;
+ QList<QObject*>::const_iterator it;
+ for (it = children.constBegin(); it != children.constEnd(); ++it) {
+ QAbstractTransition *t = qobject_cast<QAbstractTransition*>(*it);
+ if (t)
+ result.append(t);
+ }
+ return result;
+}
+
+/*!
+ Instructs this state to set the property with the given \a name of the given
+ \a object to the given \a value when the state is entered.
+
+ \sa polished()
+*/
+void QState::assignProperty(QObject *object, const char *name,
+ const QVariant &value)
+{
+ Q_D(QState);
+ if (!object) {
+ qWarning("QState::assignProperty: cannot assign property '%s' of null object", name);
+ return;
+ }
+ for (int i = 0; i < d->propertyAssignments.size(); ++i) {
+ QPropertyAssignment &assn = d->propertyAssignments[i];
+ if ((assn.object == object) && (assn.propertyName == name)) {
+ assn.value = value;
+ return;
+ }
+ }
+ d->propertyAssignments.append(QPropertyAssignment(object, name, value));
+}
+
+/*!
+ Returns this state group's error state.
+
+ \sa QStateMachine::errorState(), QStateMachine::setErrorState()
+*/
+QAbstractState *QState::errorState() const
+{
+ Q_D(const QState);
+ return d->errorState;
+}
+
+/*!
+ Sets this state's error state to be the given \a state. If the error state
+ is not set, or if it is set to 0, the state will inherit its parent's error
+ state recursively.
+
+ \sa QStateMachine::setErrorState(), QStateMachine::errorState()
+*/
+void QState::setErrorState(QAbstractState *state)
+{
+ Q_D(QState);
+ if (state != 0 && state->machine() != machine()) {
+ qWarning("QState::setErrorState: error state cannot belong "
+ "to a different state machine");
+ return;
+ }
+ if (state != 0 && state->machine() != 0 && state->machine()->rootState() == state) {
+ qWarning("QStateMachine::setErrorState: root state cannot be error state");
+ return;
+ }
+
+ d->errorState = state;
+}
+
+/*!
+ Adds the given \a transition. The transition has this state as the source.
+ This state takes ownership of the transition. If the transition is successfully
+ added, the function will return the \a transition pointer. Otherwise it will return null.
+*/
+QAbstractTransition *QState::addTransition(QAbstractTransition *transition)
+{
+ Q_D(QState);
+ if (!transition) {
+ qWarning("QState::addTransition: cannot add null transition");
+ return 0;
+ }
+
+ // machine() will always be non-null for root state
+ if (machine() != 0 && machine()->rootState() == this) {
+ qWarning("QState::addTransition: cannot add transition from root state");
+ return 0;
+ }
+
+ const QList<QPointer<QAbstractState> > &targets = QAbstractTransitionPrivate::get(transition)->targetStates;
+ for (int i = 0; i < targets.size(); ++i) {
+ QAbstractState *t = targets.at(i);
+ if (!t) {
+ qWarning("QState::addTransition: cannot add transition to null state");
+ return 0;
+ }
+ if ((QAbstractStatePrivate::get(t)->machine() != d->machine())
+ && QAbstractStatePrivate::get(t)->machine() && d->machine()) {
+ qWarning("QState::addTransition: cannot add transition "
+ "to a state in a different state machine");
+ return 0;
+ }
+ }
+ transition->setParent(this);
+ if (machine() != 0 && machine()->configuration().contains(this))
+ QStateMachinePrivate::get(machine())->registerTransitions(this);
+ return transition;
+}
+
+/*!
+ Adds a transition associated with the given \a signal of the given \a sender
+ object, and returns the new QSignalTransition object. The transition has
+ this state as the source, and the given \a target as the target state.
+*/
+QSignalTransition *QState::addTransition(QObject *sender, const char *signal,
+ QAbstractState *target)
+{
+ if (!sender) {
+ qWarning("QState::addTransition: sender cannot be null");
+ return 0;
+ }
+ if (!signal) {
+ qWarning("QState::addTransition: signal cannot be null");
+ return 0;
+ }
+ if (!target) {
+ qWarning("QState::addTransition: cannot add transition to null state");
+ return 0;
+ }
+ if (*signal && sender->metaObject()->indexOfSignal(signal+1) == -1) {
+ qWarning("QState::addTransition: no such signal %s::%s",
+ sender->metaObject()->className(), signal+1);
+ return 0;
+ }
+ QSignalTransition *trans = new QSignalTransition(sender, signal, QList<QAbstractState*>() << target);
+ addTransition(trans);
+ return trans;
+}
+
+namespace {
+
+// ### Make public?
+class UnconditionalTransition : public QAbstractTransition
+{
+public:
+ UnconditionalTransition(QAbstractState *target)
+ : QAbstractTransition(QList<QAbstractState*>() << target) {}
+protected:
+ void onTransition(QEvent *) {}
+ bool eventTest(QEvent *) { return true; }
+};
+
+} // namespace
+
+/*!
+ Adds an unconditional transition from this state to the given \a target
+ state, and returns then new transition object.
+*/
+QAbstractTransition *QState::addTransition(QAbstractState *target)
+{
+ if (!target) {
+ qWarning("QState::addTransition: cannot add transition to null state");
+ return 0;
+ }
+ UnconditionalTransition *trans = new UnconditionalTransition(target);
+ return addTransition(trans);
+}
+
+/*!
+ Removes the given \a transition from this state. The state releases
+ ownership of the transition.
+
+ \sa addTransition()
+*/
+void QState::removeTransition(QAbstractTransition *transition)
+{
+ Q_D(QState);
+ if (!transition) {
+ qWarning("QState::removeTransition: cannot remove null transition");
+ return;
+ }
+ if (transition->sourceState() != this) {
+ qWarning("QState::removeTransition: transition %p's source state (%p)"
+ " is different from this state (%p)",
+ transition, transition->sourceState(), this);
+ return;
+ }
+ QStateMachinePrivate *mach = QStateMachinePrivate::get(d->machine());
+ if (mach)
+ mach->unregisterTransition(transition);
+ transition->setParent(0);
+}
+
+/*!
+ \reimp
+*/
+void QState::onEntry(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+/*!
+ \reimp
+*/
+void QState::onExit(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+/*!
+ Returns this state's initial state, or 0 if the state has no initial state.
+*/
+QAbstractState *QState::initialState() const
+{
+ Q_D(const QState);
+ return d->initialState;
+}
+
+/*!
+ Sets this state's initial state to be the given \a state.
+ \a state has to be a child of this state.
+*/
+void QState::setInitialState(QAbstractState *state)
+{
+ Q_D(QState);
+ if (d->childMode == QState::ParallelStates) {
+ qWarning("QState::setInitialState: ignoring attempt to set initial state "
+ "of parallel state group %p", this);
+ return;
+ }
+ if (state && (state->parentState() != this)) {
+ qWarning("QState::setInitialState: state %p is not a child of this state (%p)",
+ state, this);
+ return;
+ }
+ d->initialState = state;
+}
+
+/*!
+ Returns the child mode of this state.
+*/
+QState::ChildMode QState::childMode() const
+{
+ Q_D(const QState);
+ return d->childMode;
+}
+
+/*!
+ Sets the child \a mode of this state.
+*/
+void QState::setChildMode(ChildMode mode)
+{
+ Q_D(QState);
+ d->childMode = mode;
+}
+
+/*!
+ \reimp
+*/
+bool QState::event(QEvent *e)
+{
+ return QAbstractState::event(e);
+}
+
+/*!
+ \fn QState::finished()
+
+ This signal is emitted when a final child state of this state is entered.
+
+ \sa QFinalState
+*/
+
+/*!
+ \fn QState::polished()
+
+ This signal is emitted when all properties have been assigned their final value.
+
+ \sa QState::assignProperty(), QAbstractTransition::addAnimation()
+*/
+
+QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h
new file mode 100644
index 0000000..6729c69
--- /dev/null
+++ b/src/corelib/statemachine/qstate.h
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSTATE_H
+#define QSTATE_H
+
+#include <QtCore/qabstractstate.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QAbstractTransition;
+class QSignalTransition;
+
+class QStatePrivate;
+class Q_CORE_EXPORT QState : public QAbstractState
+{
+ Q_OBJECT
+ Q_PROPERTY(QAbstractState* initialState READ initialState WRITE setInitialState)
+ Q_PROPERTY(QAbstractState* errorState READ errorState WRITE setErrorState)
+ Q_PROPERTY(ChildMode childMode READ childMode WRITE setChildMode)
+ Q_ENUMS(ChildMode)
+public:
+ enum ChildMode {
+ ExclusiveStates,
+ ParallelStates
+ };
+
+ QState(QState *parent = 0);
+ QState(ChildMode childMode, QState *parent = 0);
+ ~QState();
+
+ QAbstractState *errorState() const;
+ void setErrorState(QAbstractState *state);
+
+ QAbstractTransition *addTransition(QAbstractTransition *transition);
+ QSignalTransition *addTransition(QObject *sender, const char *signal, QAbstractState *target);
+ QAbstractTransition *addTransition(QAbstractState *target);
+ void removeTransition(QAbstractTransition *transition);
+
+ QAbstractState *initialState() const;
+ void setInitialState(QAbstractState *state);
+
+ ChildMode childMode() const;
+ void setChildMode(ChildMode mode);
+
+ void assignProperty(QObject *object, const char *name,
+ const QVariant &value);
+
+Q_SIGNALS:
+ void finished();
+ void polished();
+
+protected:
+ void onEntry(QEvent *event);
+ void onExit(QEvent *event);
+
+ bool event(QEvent *e);
+
+protected:
+ QState(QStatePrivate &dd, QState *parent);
+
+private:
+ Q_DISABLE_COPY(QState)
+ Q_DECLARE_PRIVATE(QState)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h
new file mode 100644
index 0000000..491cb87
--- /dev/null
+++ b/src/corelib/statemachine/qstate_p.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSTATE_P_H
+#define QSTATE_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 "qabstractstate_p.h"
+
+#include <QtCore/qlist.h>
+#include <QtCore/qbytearray.h>
+#include <QtCore/qvariant.h>
+
+QT_BEGIN_NAMESPACE
+
+struct QPropertyAssignment
+{
+ QPropertyAssignment()
+ : object(0) {}
+ QPropertyAssignment(QObject *o, const QByteArray &n,
+ const QVariant &v, bool es = true)
+ : object(o), propertyName(n), value(v), explicitlySet(es)
+ {}
+ QObject *object;
+ QByteArray propertyName;
+ QVariant value;
+ bool explicitlySet;
+};
+
+class QAbstractTransition;
+class QHistoryState;
+
+class QState;
+class QStatePrivate : public QAbstractStatePrivate
+{
+ Q_DECLARE_PUBLIC(QState)
+public:
+ QStatePrivate();
+ ~QStatePrivate();
+
+ static QStatePrivate *get(QState *q) { return q ? q->d_func() : 0; }
+ static const QStatePrivate *get(const QState *q) { return q? q->d_func() : 0; }
+
+ QList<QAbstractState*> childStates() const;
+ QList<QHistoryState*> historyStates() const;
+ QList<QAbstractTransition*> transitions() const;
+
+ void emitFinished();
+ void emitPolished();
+
+ QAbstractState *errorState;
+ QAbstractState *initialState;
+ QState::ChildMode childMode;
+
+ QList<QPropertyAssignment> propertyAssignments;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
new file mode 100644
index 0000000..757584a
--- /dev/null
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -0,0 +1,2221 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qstatemachine.h"
+#include "qstate.h"
+#include "qstate_p.h"
+#include "qstatemachine_p.h"
+#include "qabstracttransition.h"
+#include "qabstracttransition_p.h"
+#include "qsignaltransition.h"
+#include "qsignaltransition_p.h"
+#include "qsignalevent.h"
+#include "qsignaleventgenerator_p.h"
+#include "qabstractstate.h"
+#include "qabstractstate_p.h"
+#include "qfinalstate.h"
+#include "qhistorystate.h"
+#include "qhistorystate_p.h"
+#include "private/qobject_p.h"
+#include "private/qthread_p.h"
+
+#ifndef QT_NO_STATEMACHINE_EVENTFILTER
+#include "qeventtransition.h"
+#include "qeventtransition_p.h"
+#include "qwrappedevent.h"
+#endif
+
+#ifndef QT_NO_ANIMATION
+#include "qpropertyanimation.h"
+#include "qanimationgroup.h"
+#include <private/qvariantanimation_p.h>
+#endif
+
+#include <QtCore/qmetaobject.h>
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QStateMachine
+ \reentrant
+
+ \brief The QStateMachine class provides a hierarchical finite state machine.
+
+ \since 4.6
+ \ingroup statemachine
+
+ QStateMachine is based on the concepts and notation of
+ \l{Statecharts: A visual formalism for complex
+ systems}{Statecharts}. QStateMachine is part of \l{The State
+ Machine Framework}.
+
+ A state machine manages a set of states (classes that inherit from
+ QAbstractState) and transitions (descendants of
+ QAbstractTransition) between those states; these states and
+ transitions define a state graph. Once a state graph has been
+ built, the state machine can execute it. \l{QStateMachine}'s
+ execution algorithm is based on the \l{State Chart XML: State
+ Machine Notation for Control Abstraction}{State Chart XML (SCXML)}
+ algorithm. The framework's \l{The State Machine
+ Framework}{overview} gives several state graphs and the code to
+ build them.
+
+ The rootState() is the parent of all top-level states in the
+ machine; it is used, for instance, when the state graph is
+ deleted. It is created by the machine.
+
+ Use the addState() function to add a state to the state machine.
+ All top-level states are added to the root state. States are
+ removed with the removeState() function. Removing states while the
+ machine is running is discouraged.
+
+ Before the machine can be started, the \l{initialState}{initial
+ state} must be set. The initial state is the state that the
+ machine enters when started. You can then start() the state
+ machine. The started() signal is emitted when the initial state is
+ entered.
+
+ The machine is event driven and keeps its own event loop. Events
+ are posted to the machine through postEvent(). Note that this
+ means that it executes asynchronously, and that it will not
+ progress without a running event loop. You will normally not have
+ to post events to the machine directly as Qt's transitions, e.g.,
+ QEventTransition and its subclasses, handle this. But for custom
+ transitions triggered by events, postEvent() is useful.
+
+ The state machine processes events and takes transitions until a
+ top-level final state is entered; the state machine then emits the
+ finished() signal. You can also stop() the state machine
+ explicitly. The stopped() signal is emitted in this case.
+
+ The following snippet shows a state machine that will finish when a button
+ is clicked:
+
+ \code
+ QPushButton button;
+
+ QStateMachine machine;
+ QState *s1 = new QState();
+ s1->assignProperty(&button, "text", "Click me");
+
+ QFinalState *s2 = new QFinalState();
+ s1->addTransition(&button, SIGNAL(clicked()), s2);
+
+ machine.addState(s1);
+ machine.addState(s2);
+ machine.setInitialState(s1);
+ machine.start();
+ \endcode
+
+ This code example uses QState, which inherits QAbstractState. The
+ QState class provides a state that you can use to set properties
+ and invoke methods on \l{QObject}s when the state is entered or
+ exited. It also contains convenience functions for adding
+ transitions, e.g., \l{QSignalTransition}s as in this example. See
+ the QState class description for further details.
+
+ If an error is encountered, the machine will enter the
+ \l{errorState}{error state}, which is a special state created by
+ the machine. The types of errors possible are described by the
+ \l{QStateMachine::}{Error} enum. After the error state is entered,
+ the type of the error can be retrieved with error(). The execution
+ of the state graph will not stop when the error state is entered.
+ So it is possible to handle the error, for instance, by connecting
+ to the \l{QAbstractState::}{entered()} signal of the error state.
+ It is also possible to set a custom error state with
+ setErrorState().
+
+ \omit This stuff will be moved elsewhere
+This is
+ typically used in conjunction with \l{Signals and Slots}{signals}; the
+ signals determine the flow of the state graph, whereas the states' property
+ assignments and method invocations are the actions.
+
+ The postEvent() function posts an event to the state machine. This is useful
+ when you are using custom events to trigger transitions.
+ \endomit
+
+ \sa QAbstractState, QAbstractTransition, QState, {The State Machine Framework}
+*/
+
+/*!
+ \property QStateMachine::rootState
+
+ \brief the root state of this state machine
+*/
+
+/*!
+ \property QStateMachine::initialState
+
+ \brief the initial state of this state machine
+
+ The initial state must be one of the rootState()'s child states.
+*/
+
+/*!
+ \property QStateMachine::errorState
+
+ \brief the error state of this state machine
+*/
+
+/*!
+ \property QStateMachine::errorString
+
+ \brief the error string of this state machine
+*/
+
+/*!
+ \property QStateMachine::globalRestorePolicy
+
+ \brief the restore policy for states of this state machine.
+
+ The default value of this property is
+ QStateMachine::DoNotRestoreProperties.
+*/
+
+#ifndef QT_NO_ANIMATION
+/*!
+ \property QStateMachine::animationsEnabled
+
+ \brief whether animations are enabled
+
+ The default value of this property is true.
+
+ \sa QAbstractTransition::addAnimation()
+*/
+#endif
+
+// #define QSTATEMACHINE_DEBUG
+
+QStateMachinePrivate::QStateMachinePrivate()
+{
+ state = NotRunning;
+ processing = false;
+ processingScheduled = false;
+ stop = false;
+ error = QStateMachine::NoError;
+ globalRestorePolicy = QStateMachine::DoNotRestoreProperties;
+ rootState = 0;
+ initialErrorStateForRoot = 0;
+ signalEventGenerator = 0;
+#ifndef QT_NO_ANIMATION
+ animationsEnabled = true;
+#endif
+}
+
+QStateMachinePrivate::~QStateMachinePrivate()
+{
+ qDeleteAll(internalEventQueue);
+ qDeleteAll(externalEventQueue);
+}
+
+QStateMachinePrivate *QStateMachinePrivate::get(QStateMachine *q)
+{
+ if (q)
+ return q->d_func();
+ return 0;
+}
+
+static QEvent *cloneEvent(QEvent *e)
+{
+ switch (e->type()) {
+ case QEvent::None:
+ return new QEvent(*e);
+ case QEvent::Timer:
+ return new QTimerEvent(*static_cast<QTimerEvent*>(e));
+ default:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ }
+ return 0;
+}
+
+const QStateMachinePrivate::Handler qt_kernel_statemachine_handler = {
+ cloneEvent
+};
+
+const QStateMachinePrivate::Handler *QStateMachinePrivate::handler = &qt_kernel_statemachine_handler;
+
+Q_CORE_EXPORT const QStateMachinePrivate::Handler *qcoreStateMachineHandler()
+{
+ return &qt_kernel_statemachine_handler;
+}
+
+static int indexOfDescendant(QState *s, QAbstractState *desc)
+{
+ QList<QAbstractState*> childStates = QStatePrivate::get(s)->childStates();
+ for (int i = 0; i < childStates.size(); ++i) {
+ QAbstractState *c = childStates.at(i);
+ if ((c == desc) || QStateMachinePrivate::isDescendantOf(desc, c)) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+bool QStateMachinePrivate::stateEntryLessThan(QAbstractState *s1, QAbstractState *s2)
+{
+ if (s1->parent() == s2->parent()) {
+ return s1->children().indexOf(s1)
+ < s2->children().indexOf(s2);
+ } else if (isDescendantOf(s1, s2)) {
+ return false;
+ } else if (isDescendantOf(s2, s1)) {
+ return true;
+ } else {
+ QState *lca = findLCA(QList<QAbstractState*>() << s1 << s2);
+ Q_ASSERT(lca != 0);
+ return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2));
+ }
+}
+
+bool QStateMachinePrivate::stateExitLessThan(QAbstractState *s1, QAbstractState *s2)
+{
+ if (s1->parent() == s2->parent()) {
+ return s1->children().indexOf(s1)
+ < s2->children().indexOf(s2);
+ } else if (isDescendantOf(s1, s2)) {
+ return true;
+ } else if (isDescendantOf(s2, s1)) {
+ return false;
+ } else {
+ QState *lca = findLCA(QList<QAbstractState*>() << s1 << s2);
+ Q_ASSERT(lca != 0);
+ return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2));
+ }
+}
+
+QState *QStateMachinePrivate::findLCA(const QList<QAbstractState*> &states)
+{
+ if (states.isEmpty())
+ return 0;
+ QList<QState*> ancestors = properAncestors(states.at(0), 0);
+ for (int i = 0; i < ancestors.size(); ++i) {
+ QState *anc = ancestors.at(i);
+ bool ok = true;
+ for (int j = states.size() - 1; (j > 0) && ok; --j) {
+ const QAbstractState *s = states.at(j);
+ if (!isDescendantOf(s, anc))
+ ok = false;
+ }
+ if (ok)
+ return anc;
+ }
+ return 0;
+}
+
+bool QStateMachinePrivate::isPreempted(const QAbstractState *s, const QSet<QAbstractTransition*> &transitions) const
+{
+ QSet<QAbstractTransition*>::const_iterator it;
+ for (it = transitions.constBegin(); it != transitions.constEnd(); ++it) {
+ QAbstractTransition *t = *it;
+ QList<QAbstractState*> lst = t->targetStates();
+ if (!lst.isEmpty()) {
+ lst.prepend(t->sourceState());
+ QAbstractState *lca = findLCA(lst);
+ if (isDescendantOf(s, lca)) {
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q_func() << ':' << transitions << "preempts selection of a transition from"
+ << s << "because" << s << "is a descendant of" << lca;
+#endif
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+QSet<QAbstractTransition*> QStateMachinePrivate::selectTransitions(QEvent *event) const
+{
+ Q_Q(const QStateMachine);
+ QSet<QAbstractTransition*> enabledTransitions;
+ QSet<QAbstractState*>::const_iterator it;
+ const_cast<QStateMachine*>(q)->beginSelectTransitions(event);
+ for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
+ QAbstractState *state = *it;
+ if (!isAtomic(state))
+ continue;
+ if (isPreempted(state, enabledTransitions))
+ continue;
+ QList<QState*> lst = properAncestors(state, 0);
+ if (QState *grp = qobject_cast<QState*>(state))
+ lst.prepend(grp);
+ bool found = false;
+ for (int j = 0; (j < lst.size()) && !found; ++j) {
+ QState *s = lst.at(j);
+ QList<QAbstractTransition*> transitions = QStatePrivate::get(s)->transitions();
+ for (int k = 0; k < transitions.size(); ++k) {
+ QAbstractTransition *t = transitions.at(k);
+ if (QAbstractTransitionPrivate::get(t)->callEventTest(event)) {
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": selecting transition" << t;
+#endif
+ enabledTransitions.insert(t);
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+ const_cast<QStateMachine*>(q)->endSelectTransitions(event);
+ return enabledTransitions;
+}
+
+void QStateMachinePrivate::microstep(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions)
+{
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q_func() << ": begin microstep( enabledTransitions:" << enabledTransitions << ')';
+ qDebug() << q_func() << ": configuration before exiting states:" << configuration;
+#endif
+ QList<QAbstractState*> exitedStates = exitStates(event, enabledTransitions);
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q_func() << ": configuration after exiting states:" << configuration;
+#endif
+ executeTransitionContent(event, enabledTransitions);
+ QList<QAbstractState*> enteredStates = enterStates(event, enabledTransitions);
+ applyProperties(enabledTransitions, exitedStates, enteredStates);
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q_func() << ": configuration after entering states:" << configuration;
+ qDebug() << q_func() << ": end microstep";
+#endif
+}
+
+QList<QAbstractState*> QStateMachinePrivate::exitStates(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions)
+{
+// qDebug() << "exitStates(" << enabledTransitions << ')';
+ QSet<QAbstractState*> statesToExit;
+// QSet<QAbstractState*> statesToSnapshot;
+ for (int i = 0; i < enabledTransitions.size(); ++i) {
+ QAbstractTransition *t = enabledTransitions.at(i);
+ QList<QAbstractState*> lst = t->targetStates();
+ if (lst.isEmpty())
+ continue;
+ lst.prepend(t->sourceState());
+ QAbstractState *lca = findLCA(lst);
+ if (lca == 0) {
+ setError(QStateMachine::NoCommonAncestorForTransitionError, t->sourceState());
+ lst = pendingErrorStates.toList();
+ lst.prepend(t->sourceState());
+
+ lca = findLCA(lst);
+ Q_ASSERT(lca != 0);
+ }
+
+ {
+ QSet<QAbstractState*>::const_iterator it;
+ for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
+ QAbstractState *s = *it;
+ if (isDescendantOf(s, lca))
+ statesToExit.insert(s);
+ }
+ }
+ }
+ QList<QAbstractState*> statesToExit_sorted = statesToExit.toList();
+ qSort(statesToExit_sorted.begin(), statesToExit_sorted.end(), stateExitLessThan);
+ for (int i = 0; i < statesToExit_sorted.size(); ++i) {
+ QAbstractState *s = statesToExit_sorted.at(i);
+ if (QState *grp = qobject_cast<QState*>(s)) {
+ QList<QHistoryState*> hlst = QStatePrivate::get(grp)->historyStates();
+ for (int j = 0; j < hlst.size(); ++j) {
+ QHistoryState *h = hlst.at(j);
+ QHistoryStatePrivate::get(h)->configuration.clear();
+ QSet<QAbstractState*>::const_iterator it;
+ for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
+ QAbstractState *s0 = *it;
+ if (QHistoryStatePrivate::get(h)->historyType == QHistoryState::DeepHistory) {
+ if (isAtomic(s0) && isDescendantOf(s0, s))
+ QHistoryStatePrivate::get(h)->configuration.append(s0);
+ } else if (s0->parentState() == s) {
+ QHistoryStatePrivate::get(h)->configuration.append(s0);
+ }
+ }
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q_func() << ": recorded" << ((QHistoryStatePrivate::get(h)->historyType == QHistoryState::DeepHistory) ? "deep" : "shallow")
+ << "history for" << s << "in" << h << ':' << QHistoryStatePrivate::get(h)->configuration;
+#endif
+ }
+ }
+ }
+ for (int i = 0; i < statesToExit_sorted.size(); ++i) {
+ QAbstractState *s = statesToExit_sorted.at(i);
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q_func() << ": exiting" << s;
+#endif
+ QAbstractStatePrivate::get(s)->callOnExit(event);
+ configuration.remove(s);
+ QAbstractStatePrivate::get(s)->emitExited();
+ }
+ return statesToExit_sorted;
+}
+
+void QStateMachinePrivate::executeTransitionContent(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions)
+{
+ for (int i = 0; i < enabledTransitions.size(); ++i) {
+ QAbstractTransition *t = enabledTransitions.at(i);
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q_func() << ": triggering" << t;
+#endif
+ QAbstractTransitionPrivate::get(t)->callOnTransition(event);
+ }
+}
+
+QList<QAbstractState*> QStateMachinePrivate::enterStates(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions)
+{
+#ifdef QSTATEMACHINE_DEBUG
+ Q_Q(QStateMachine);
+#endif
+// qDebug() << "enterStates(" << enabledTransitions << ')';
+ QSet<QAbstractState*> statesToEnter;
+ QSet<QAbstractState*> statesForDefaultEntry;
+
+ if (pendingErrorStates.isEmpty()) {
+ for (int i = 0; i < enabledTransitions.size(); ++i) {
+ QAbstractTransition *t = enabledTransitions.at(i);
+ QList<QAbstractState*> lst = t->targetStates();
+ if (lst.isEmpty())
+ continue;
+ lst.prepend(t->sourceState());
+ QState *lca = findLCA(lst);
+ for (int j = 1; j < lst.size(); ++j) {
+ QAbstractState *s = lst.at(j);
+ addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry);
+ if (isParallel(lca)) {
+ QList<QAbstractState*> lcac = QStatePrivate::get(lca)->childStates();
+ foreach (QAbstractState* child,lcac) {
+ if (!statesToEnter.contains(child))
+ addStatesToEnter(child,lca,statesToEnter,statesForDefaultEntry);
+ }
+ }
+ }
+ }
+ }
+
+ // Did an error occur while selecting transitions? Then we enter the error state.
+ if (!pendingErrorStates.isEmpty()) {
+ statesToEnter.clear();
+ statesToEnter = pendingErrorStates;
+ statesForDefaultEntry = pendingErrorStatesForDefaultEntry;
+ pendingErrorStates.clear();
+ pendingErrorStatesForDefaultEntry.clear();
+ }
+
+ QList<QAbstractState*> statesToEnter_sorted = statesToEnter.toList();
+ qSort(statesToEnter_sorted.begin(), statesToEnter_sorted.end(), stateEntryLessThan);
+
+ for (int i = 0; i < statesToEnter_sorted.size(); ++i) {
+ QAbstractState *s = statesToEnter_sorted.at(i);
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": entering" << s;
+#endif
+ configuration.insert(s);
+ registerTransitions(s);
+ QAbstractStatePrivate::get(s)->callOnEntry(event);
+ QAbstractStatePrivate::get(s)->emitEntered();
+ if (statesForDefaultEntry.contains(s)) {
+ // ### executeContent(s.initial.transition.children())
+ }
+ if (isFinal(s)) {
+ QState *parent = s->parentState();
+ if (parent) {
+ QState *grandparent = parent->parentState();
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": emitting finished signal for" << parent;
+#endif
+ QStatePrivate::get(parent)->emitFinished();
+ if (grandparent && isParallel(grandparent)) {
+ bool allChildStatesFinal = true;
+ QList<QAbstractState*> childStates = QStatePrivate::get(grandparent)->childStates();
+ for (int j = 0; j < childStates.size(); ++j) {
+ QAbstractState *cs = childStates.at(j);
+ if (!isInFinalState(cs)) {
+ allChildStatesFinal = false;
+ break;
+ }
+ }
+ if (allChildStatesFinal) {
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": emitting finished signal for" << grandparent;
+#endif
+ QStatePrivate::get(grandparent)->emitFinished();
+ }
+ }
+ }
+ }
+ }
+ {
+ QSet<QAbstractState*>::const_iterator it;
+ for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
+ if (isFinal(*it) && (*it)->parentState() == rootState) {
+ processing = false;
+ stopProcessingReason = Finished;
+ break;
+ }
+ }
+ }
+// qDebug() << "configuration:" << configuration.toList();
+ return statesToEnter_sorted;
+}
+
+void QStateMachinePrivate::addStatesToEnter(QAbstractState *s, QState *root,
+ QSet<QAbstractState*> &statesToEnter,
+ QSet<QAbstractState*> &statesForDefaultEntry)
+{
+ if (QHistoryState *h = qobject_cast<QHistoryState*>(s)) {
+ QList<QAbstractState*> hconf = QHistoryStatePrivate::get(h)->configuration;
+ if (!hconf.isEmpty()) {
+ for (int k = 0; k < hconf.size(); ++k) {
+ QAbstractState *s0 = hconf.at(k);
+ addStatesToEnter(s0, root, statesToEnter, statesForDefaultEntry);
+ }
+ #ifdef QSTATEMACHINE_DEBUG
+ qDebug() <<q_func() << ": restoring"
+ << ((QHistoryStatePrivate::get(h)->historyType == QHistoryState::DeepHistory) ? "deep" : "shallow")
+ << "history from" << s << ':' << hconf;
+ #endif
+ } else {
+ QList<QAbstractState*> hlst;
+ if (QHistoryStatePrivate::get(h)->defaultState)
+ hlst.append(QHistoryStatePrivate::get(h)->defaultState);
+
+ if (hlst.isEmpty()) {
+ setError(QStateMachine::NoDefaultStateInHistoryStateError, h);
+ } else {
+ for (int k = 0; k < hlst.size(); ++k) {
+ QAbstractState *s0 = hlst.at(k);
+ addStatesToEnter(s0, root, statesToEnter, statesForDefaultEntry);
+ }
+ #ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q_func() << ": initial history targets for" << s << ':' << hlst;
+ #endif
+ }
+ }
+ } else {
+ statesToEnter.insert(s);
+ if (isParallel(s)) {
+ QState *grp = qobject_cast<QState*>(s);
+ QList<QAbstractState*> lst = QStatePrivate::get(grp)->childStates();
+ for (int i = 0; i < lst.size(); ++i) {
+ QAbstractState *child = lst.at(i);
+ addStatesToEnter(child, grp, statesToEnter, statesForDefaultEntry);
+ }
+ } else if (isCompound(s)) {
+ statesForDefaultEntry.insert(s);
+ QState *grp = qobject_cast<QState*>(s);
+ QAbstractState *initial = grp->initialState();
+ if (initial != 0) {
+ addStatesToEnter(initial, grp, statesToEnter, statesForDefaultEntry);
+ } else {
+ setError(QStateMachine::NoInitialStateError, grp);
+ return;
+ }
+ }
+ QList<QState*> ancs = properAncestors(s, root);
+ for (int i = 0; i < ancs.size(); ++i) {
+ QState *anc = ancs.at(i);
+ if (!anc->parentState())
+ continue;
+ statesToEnter.insert(anc);
+ if (isParallel(anc)) {
+ QList<QAbstractState*> lst = QStatePrivate::get(anc)->childStates();
+ for (int j = 0; j < lst.size(); ++j) {
+ QAbstractState *child = lst.at(j);
+ bool hasDescendantInList = false;
+ QSet<QAbstractState*>::const_iterator it;
+ for (it = statesToEnter.constBegin(); it != statesToEnter.constEnd(); ++it) {
+ if (isDescendantOf(*it, child)) {
+ hasDescendantInList = true;
+ break;
+ }
+ }
+ if (!hasDescendantInList)
+ addStatesToEnter(child, anc, statesToEnter, statesForDefaultEntry);
+ }
+ }
+ }
+ }
+}
+
+void QStateMachinePrivate::applyProperties(const QList<QAbstractTransition*> &transitionList,
+ const QList<QAbstractState*> &exitedStates,
+ const QList<QAbstractState*> &enteredStates)
+{
+#ifdef QT_NO_ANIMATION
+ Q_UNUSED(transitionList);
+ Q_UNUSED(exitedStates);
+#else
+ Q_Q(QStateMachine);
+#endif
+ // Process the property assignments of the entered states.
+ QHash<QAbstractState*, QList<QPropertyAssignment> > propertyAssignmentsForState;
+ QHash<RestorableId, QVariant> pendingRestorables = registeredRestorables;
+ for (int i = 0; i < enteredStates.size(); ++i) {
+ QState *s = qobject_cast<QState*>(enteredStates.at(i));
+ if (!s)
+ continue;
+
+ QList<QPropertyAssignment> assignments = QStatePrivate::get(s)->propertyAssignments;
+ for (int j = 0; j < assignments.size(); ++j) {
+ const QPropertyAssignment &assn = assignments.at(j);
+ if (globalRestorePolicy == QStateMachine::RestoreProperties) {
+ registerRestorable(assn.object, assn.propertyName);
+ }
+ pendingRestorables.remove(RestorableId(assn.object, assn.propertyName));
+ propertyAssignmentsForState[s].append(assn);
+ }
+
+ // Remove pending restorables for all parent states to avoid restoring properties
+ // before the state that assigned them is exited. If state does not explicitly
+ // assign a property which is assigned by the parent, it inherits the parent's assignment.
+ QState *parentState = s;
+ while ((parentState = parentState->parentState()) != 0) {
+ assignments = QStatePrivate::get(parentState)->propertyAssignments;
+ for (int j=0; j<assignments.size(); ++j) {
+ const QPropertyAssignment &assn = assignments.at(j);
+ int c = pendingRestorables.remove(RestorableId(assn.object, assn.propertyName));
+ if (c > 0)
+ propertyAssignmentsForState[s].append(assn);
+ }
+ }
+ }
+ if (!pendingRestorables.isEmpty()) {
+ QAbstractState *s;
+ if (!enteredStates.isEmpty())
+ s = enteredStates.last(); // ### handle if parallel
+ else
+ s = 0;
+ propertyAssignmentsForState[s] << restorablesToPropertyList(pendingRestorables);
+ }
+
+#ifndef QT_NO_ANIMATION
+ // Gracefully terminate playing animations for states that are exited.
+ for (int i = 0; i < exitedStates.size(); ++i) {
+ QAbstractState *s = exitedStates.at(i);
+ QList<QAbstractAnimation*> animations = animationsForState.take(s);
+ for (int j = 0; j < animations.size(); ++j) {
+ QAbstractAnimation *anim = animations.at(j);
+ QObject::disconnect(anim, SIGNAL(finished()), q, SLOT(_q_animationFinished()));
+ stateForAnimation.remove(anim);
+
+ // Stop the (top-level) animation.
+ // ### Stopping nested animation has weird behavior.
+ QAbstractAnimation *topLevelAnim = anim;
+ while (QAnimationGroup *group = topLevelAnim->group())
+ topLevelAnim = group;
+ topLevelAnim->stop();
+
+ if (resetAnimationEndValues.contains(anim)) {
+ qobject_cast<QVariantAnimation*>(anim)->setEndValue(QVariant()); // ### generalize
+ resetAnimationEndValues.remove(anim);
+ }
+ QPropertyAssignment assn = propertyForAnimation.take(anim);
+ Q_ASSERT(assn.object != 0);
+ // If there is no property assignment that sets this property,
+ // set the property to its target value.
+ bool found = false;
+ QHash<QAbstractState*, QList<QPropertyAssignment> >::const_iterator it;
+ for (it = propertyAssignmentsForState.constBegin(); it != propertyAssignmentsForState.constEnd(); ++it) {
+ const QList<QPropertyAssignment> &assignments = it.value();
+ for (int k = 0; k < assignments.size(); ++k) {
+ if ((assignments.at(k).object == assn.object)
+ && (assignments.at(k).propertyName == assn.propertyName)) {
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found) {
+ assn.object->setProperty(assn.propertyName, assn.value);
+ }
+ }
+ }
+
+ // Find the animations to use for the state change.
+ QList<QAbstractAnimation*> selectedAnimations;
+ if (animationsEnabled) {
+ for (int i = 0; i < transitionList.size(); ++i) {
+ QAbstractTransition *transition = transitionList.at(i);
+
+ selectedAnimations << transition->animations();
+ selectedAnimations << defaultAnimationsForSource.values(transition->sourceState());
+
+ QList<QAbstractState *> targetStates = transition->targetStates();
+ for (int j=0; j<targetStates.size(); ++j)
+ selectedAnimations << defaultAnimationsForTarget.values(targetStates.at(j));
+ }
+ selectedAnimations << defaultAnimations;
+ }
+
+ // Initialize animations from property assignments.
+ for (int i = 0; i < selectedAnimations.size(); ++i) {
+ QAbstractAnimation *anim = selectedAnimations.at(i);
+ QHash<QAbstractState*, QList<QPropertyAssignment> >::iterator it;
+ for (it = propertyAssignmentsForState.begin(); it != propertyAssignmentsForState.end(); ) {
+ QList<QPropertyAssignment>::iterator it2;
+ QAbstractState *s = it.key();
+ QList<QPropertyAssignment> &assignments = it.value();
+ for (it2 = assignments.begin(); it2 != assignments.end(); ) {
+ QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> > ret;
+ ret = initializeAnimation(anim, *it2);
+ QList<QAbstractAnimation*> handlers = ret.first;
+ if (!handlers.isEmpty()) {
+ for (int j = 0; j < handlers.size(); ++j) {
+ QAbstractAnimation *a = handlers.at(j);
+ propertyForAnimation.insert(a, *it2);
+ stateForAnimation.insert(a, s);
+ animationsForState[s].append(a);
+ // ### connect to just the top-level animation?
+ QObject::disconnect(a, SIGNAL(finished()), q, SLOT(_q_animationFinished()));
+ QObject::connect(a, SIGNAL(finished()), q, SLOT(_q_animationFinished()));
+ }
+ it2 = assignments.erase(it2);
+ } else {
+ ++it2;
+ }
+ for (int j = 0; j < ret.second.size(); ++j)
+ resetAnimationEndValues.insert(ret.second.at(j));
+ }
+ if (assignments.isEmpty())
+ it = propertyAssignmentsForState.erase(it);
+ else
+ ++it;
+ }
+ // We require that at least one animation is valid.
+ // ### generalize
+ QList<QVariantAnimation*> variantAnims = qFindChildren<QVariantAnimation*>(anim);
+ if (QVariantAnimation *va = qobject_cast<QVariantAnimation*>(anim))
+ variantAnims.append(va);
+
+ bool hasValidEndValue = false;
+ for (int j = 0; j < variantAnims.size(); ++j) {
+ if (variantAnims.at(j)->endValue().isValid()) {
+ hasValidEndValue = true;
+ break;
+ }
+ }
+
+ if (hasValidEndValue) {
+ anim->start();
+ }
+ }
+#endif // !QT_NO_ANIMATION
+
+ // Immediately set the properties that are not animated.
+ {
+ QHash<QAbstractState*, QList<QPropertyAssignment> >::const_iterator it;
+ for (it = propertyAssignmentsForState.constBegin(); it != propertyAssignmentsForState.constEnd(); ++it) {
+ const QList<QPropertyAssignment> &assignments = it.value();
+ for (int i = 0; i < assignments.size(); ++i) {
+ const QPropertyAssignment &assn = assignments.at(i);
+ assn.object->setProperty(assn.propertyName, assn.value);
+ }
+ }
+ }
+
+ // Emit polished signal for entered states that have no animated properties.
+ for (int i = 0; i < enteredStates.size(); ++i) {
+ QState *s = qobject_cast<QState*>(enteredStates.at(i));
+ if (s
+#ifndef QT_NO_ANIMATION
+ && !animationsForState.contains(s)
+#endif
+ )
+ QStatePrivate::get(s)->emitPolished();
+ }
+}
+
+bool QStateMachinePrivate::isFinal(const QAbstractState *s)
+{
+ return qobject_cast<const QFinalState*>(s) != 0;
+}
+
+bool QStateMachinePrivate::isParallel(const QAbstractState *s)
+{
+ const QState *ss = qobject_cast<const QState*>(s);
+ return ss && (QStatePrivate::get(ss)->childMode == QState::ParallelStates);
+}
+
+bool QStateMachinePrivate::isCompound(const QAbstractState *s)
+{
+ const QState *group = qobject_cast<const QState*>(s);
+ if (!group)
+ return false;
+ return (!isParallel(group) && !QStatePrivate::get(group)->childStates().isEmpty())
+ || (qobject_cast<QStateMachine*>(group->parent()) != 0);
+}
+
+bool QStateMachinePrivate::isAtomic(const QAbstractState *s)
+{
+ const QState *ss = qobject_cast<const QState*>(s);
+ return (ss && QStatePrivate::get(ss)->childStates().isEmpty())
+ || isFinal(s);
+}
+
+
+bool QStateMachinePrivate::isDescendantOf(const QAbstractState *state, const QAbstractState *other)
+{
+ Q_ASSERT(state != 0);
+ for (QAbstractState *s = state->parentState(); s != 0; s = s->parentState()) {
+ if (s == other)
+ return true;
+ }
+ return false;
+}
+
+QList<QState*> QStateMachinePrivate::properAncestors(const QAbstractState *state, const QState *upperBound)
+{
+ Q_ASSERT(state != 0);
+ QList<QState*> result;
+ for (QState *s = state->parentState(); s && s != upperBound; s = s->parentState()) {
+ result.append(s);
+ }
+ return result;
+}
+
+bool QStateMachinePrivate::isInFinalState(QAbstractState* s) const
+{
+ if (isCompound(s)) {
+ QState *grp = qobject_cast<QState*>(s);
+ QList<QAbstractState*> lst = QStatePrivate::get(grp)->childStates();
+ for (int i = 0; i < lst.size(); ++i) {
+ QAbstractState *cs = lst.at(i);
+ if (isFinal(cs) && configuration.contains(cs))
+ return true;
+ }
+ return false;
+ } else if (isParallel(s)) {
+ QState *grp = qobject_cast<QState*>(s);
+ QList<QAbstractState*> lst = QStatePrivate::get(grp)->childStates();
+ for (int i = 0; i < lst.size(); ++i) {
+ QAbstractState *cs = lst.at(i);
+ if (!isInFinalState(cs))
+ return false;
+ }
+ return true;
+ }
+ else
+ return false;
+}
+
+void QStateMachinePrivate::registerRestorable(QObject *object, const QByteArray &propertyName)
+{
+ RestorableId id(object, propertyName);
+ if (!registeredRestorables.contains(id))
+ registeredRestorables.insert(id, object->property(propertyName));
+}
+
+QList<QPropertyAssignment> QStateMachinePrivate::restorablesToPropertyList(const QHash<RestorableId, QVariant> &restorables) const
+{
+ QList<QPropertyAssignment> result;
+ QHash<RestorableId, QVariant>::const_iterator it;
+ for (it = restorables.constBegin(); it != restorables.constEnd(); ++it) {
+// qDebug() << "restorable:" << it.key().first << it.key().second << it.value();
+ result.append(QPropertyAssignment(it.key().first, it.key().second, it.value(), /*explicitlySet=*/false));
+ }
+ return result;
+}
+
+/*!
+ \internal
+ Returns true if the variable with the given \a id has been registered for restoration.
+*/
+bool QStateMachinePrivate::hasRestorable(QObject *object, const QByteArray &propertyName) const
+{
+ return registeredRestorables.contains(RestorableId(object, propertyName));
+}
+
+QVariant QStateMachinePrivate::restorableValue(QObject *object, const QByteArray &propertyName) const
+{
+ return registeredRestorables.value(RestorableId(object, propertyName), QVariant());
+}
+
+
+/*!
+ \internal
+ Unregisters the variable identified by \a id
+*/
+void QStateMachinePrivate::unregisterRestorable(QObject *object, const QByteArray &propertyName)
+{
+// qDebug() << "unregisterRestorable(" << object << propertyName << ')';
+ RestorableId id(object, propertyName);
+ registeredRestorables.remove(id);
+}
+
+QAbstractState *QStateMachinePrivate::findErrorState(QAbstractState *context)
+{
+ // If the user sets the root state's error state to 0, we return the initial error state
+ if (context == 0)
+ return initialErrorStateForRoot;
+
+ // Find error state recursively in parent hierarchy if not set explicitly for context state
+ QAbstractState *errorState = 0;
+
+ QState *s = qobject_cast<QState*>(context);
+ if (s)
+ errorState = s->errorState();
+
+ if (!errorState)
+ errorState = findErrorState(context->parentState());
+
+ return errorState;
+}
+
+void QStateMachinePrivate::setError(QStateMachine::Error errorCode, QAbstractState *currentContext)
+{
+ error = errorCode;
+
+ switch (errorCode) {
+ case QStateMachine::NoInitialStateError:
+ Q_ASSERT(currentContext != 0);
+
+ errorString = QStateMachine::tr("Missing initial state in compound state '%1'")
+ .arg(currentContext->objectName());
+
+ break;
+ case QStateMachine::NoDefaultStateInHistoryStateError:
+ Q_ASSERT(currentContext != 0);
+
+ errorString = QStateMachine::tr("Missing default state in history state '%1'")
+ .arg(currentContext->objectName());
+ break;
+
+ case QStateMachine::NoCommonAncestorForTransitionError:
+ Q_ASSERT(currentContext != 0);
+
+ errorString = QStateMachine::tr("No common ancestor for targets and source of transition from state '%1'")
+ .arg(currentContext->objectName());
+ break;
+ default:
+ errorString = QStateMachine::tr("Unknown error");
+ };
+
+ pendingErrorStates.clear();
+ pendingErrorStatesForDefaultEntry.clear();
+
+ QAbstractState *currentErrorState = findErrorState(currentContext);
+
+ // Avoid infinite loop if the error state itself has an error
+ if (currentContext == currentErrorState) {
+ Q_ASSERT(currentContext != initialErrorStateForRoot); // RootErrorState is broken
+ currentErrorState = initialErrorStateForRoot;
+ }
+
+ Q_ASSERT(currentErrorState != 0);
+ Q_ASSERT(currentErrorState != rootState);
+
+ QState *lca = findLCA(QList<QAbstractState*>() << currentErrorState << currentContext);
+ addStatesToEnter(currentErrorState, lca, pendingErrorStates, pendingErrorStatesForDefaultEntry);
+}
+
+#ifndef QT_NO_ANIMATION
+
+QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> >
+QStateMachinePrivate::initializeAnimation(QAbstractAnimation *abstractAnimation,
+ const QPropertyAssignment &prop)
+{
+ QList<QAbstractAnimation*> handledAnimations;
+ QList<QAbstractAnimation*> localResetEndValues;
+ QAnimationGroup *group = qobject_cast<QAnimationGroup*>(abstractAnimation);
+ if (group) {
+ for (int i = 0; i < group->animationCount(); ++i) {
+ QAbstractAnimation *animationChild = group->animationAt(i);
+ QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> > ret;
+ ret = initializeAnimation(animationChild, prop);
+ handledAnimations << ret.first;
+ localResetEndValues << ret.second;
+ }
+ } else {
+ QPropertyAnimation *animation = qobject_cast<QPropertyAnimation *>(abstractAnimation);
+ if (animation != 0
+ && prop.object == animation->targetObject()
+ && prop.propertyName == animation->propertyName()) {
+
+ // Only change end value if it is undefined
+ if (!animation->endValue().isValid()) {
+ animation->setEndValue(prop.value);
+ localResetEndValues.append(animation);
+ }
+ handledAnimations.append(animation);
+ }
+ }
+ return qMakePair(handledAnimations, localResetEndValues);
+}
+
+void QStateMachinePrivate::_q_animationFinished()
+{
+ Q_Q(QStateMachine);
+ QAbstractAnimation *anim = qobject_cast<QAbstractAnimation*>(q->sender());
+ Q_ASSERT(anim != 0);
+ QObject::disconnect(anim, SIGNAL(finished()), q, SLOT(_q_animationFinished()));
+ if (resetAnimationEndValues.contains(anim)) {
+ qobject_cast<QVariantAnimation*>(anim)->setEndValue(QVariant()); // ### generalize
+ resetAnimationEndValues.remove(anim);
+ }
+
+ // Set the final property value.
+ QPropertyAssignment assn = propertyForAnimation.take(anim);
+ Q_ASSERT(assn.object != 0);
+ assn.object->setProperty(assn.propertyName, assn.value);
+ if (!assn.explicitlySet)
+ unregisterRestorable(assn.object, assn.propertyName);
+
+ QAbstractState *state = stateForAnimation.take(anim);
+ Q_ASSERT(state != 0);
+ QHash<QAbstractState*, QList<QAbstractAnimation*> >::iterator it;
+ it = animationsForState.find(state);
+ Q_ASSERT(it != animationsForState.end());
+ QList<QAbstractAnimation*> &animations = it.value();
+ animations.removeOne(anim);
+ if (animations.isEmpty()) {
+ animationsForState.erase(it);
+ QStatePrivate::get(qobject_cast<QState*>(state))->emitPolished();
+ }
+}
+
+#endif // !QT_NO_ANIMATION
+
+namespace {
+
+class StartState : public QState
+{
+public:
+ StartState(QState *parent)
+ : QState(parent) {}
+protected:
+ void onEntry(QEvent *) {}
+ void onExit(QEvent *) {}
+};
+
+class InitialTransition : public QAbstractTransition
+{
+public:
+ InitialTransition(QAbstractState *target)
+ : QAbstractTransition(QList<QAbstractState*>() << target) {}
+protected:
+ virtual bool eventTest(QEvent *) { return true; }
+ virtual void onTransition(QEvent *) {}
+};
+
+} // namespace
+
+void QStateMachinePrivate::_q_start()
+{
+ Q_Q(QStateMachine);
+ Q_ASSERT(state == Starting);
+ if (!rootState) {
+ state = NotRunning;
+ return;
+ }
+ QAbstractState *initial = rootState->initialState();
+ if (initial == 0)
+ setError(QStateMachine::NoInitialStateError, rootState);
+
+ configuration.clear();
+ qDeleteAll(internalEventQueue);
+ internalEventQueue.clear();
+ qDeleteAll(externalEventQueue);
+ externalEventQueue.clear();
+
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": starting";
+#endif
+ state = Running;
+ processingScheduled = true; // we call _q_process() below
+ emit q->started();
+
+ StartState *start = new StartState(rootState);
+ QAbstractTransition *initialTransition = new InitialTransition(initial);
+ start->addTransition(initialTransition);
+ QList<QAbstractTransition*> transitions;
+ transitions.append(initialTransition);
+ QEvent nullEvent(QEvent::None);
+ executeTransitionContent(&nullEvent, transitions);
+ enterStates(&nullEvent, transitions);
+ applyProperties(transitions, QList<QAbstractState*>() << start,
+ QList<QAbstractState*>() << initial);
+ delete start;
+
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": initial configuration:" << configuration;
+#endif
+ _q_process();
+}
+
+void QStateMachinePrivate::_q_process()
+{
+ Q_Q(QStateMachine);
+ Q_ASSERT(state == Running);
+ Q_ASSERT(!processing);
+ processing = true;
+ processingScheduled = false;
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": starting the event processing loop";
+#endif
+ while (processing) {
+ if (stop) {
+ stop = false;
+ processing = false;
+ stopProcessingReason = Stopped;
+ break;
+ }
+ QSet<QAbstractTransition*> enabledTransitions;
+ QEvent *e = new QEvent(QEvent::None);
+ enabledTransitions = selectTransitions(e);
+ if (enabledTransitions.isEmpty()) {
+ delete e;
+ e = 0;
+ }
+ if (enabledTransitions.isEmpty() && !internalEventQueue.isEmpty()) {
+ e = internalEventQueue.takeFirst();
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": dequeued internal event" << e << "of type" << e->type();
+#endif
+ enabledTransitions = selectTransitions(e);
+ if (enabledTransitions.isEmpty()) {
+ delete e;
+ e = 0;
+ }
+ }
+ if (enabledTransitions.isEmpty()) {
+ if (externalEventQueue.isEmpty()) {
+ if (internalEventQueue.isEmpty()) {
+ processing = false;
+ stopProcessingReason = EventQueueEmpty;
+ }
+ } else {
+ e = externalEventQueue.takeFirst();
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": dequeued external event" << e << "of type" << e->type();
+#endif
+ enabledTransitions = selectTransitions(e);
+ if (enabledTransitions.isEmpty()) {
+ delete e;
+ e = 0;
+ }
+ }
+ }
+ if (!enabledTransitions.isEmpty()) {
+ q->beginMicrostep(e);
+ microstep(e, enabledTransitions.toList());
+ q->endMicrostep(e);
+ }
+#ifdef QSTATEMACHINE_DEBUG
+ else {
+ qDebug() << q << ": no transitions enabled";
+ }
+#endif
+ delete e;
+ }
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": finished the event processing loop";
+#endif
+ switch (stopProcessingReason) {
+ case EventQueueEmpty:
+ break;
+ case Finished:
+ state = NotRunning;
+ unregisterAllTransitions();
+ emit q->finished();
+ break;
+ case Stopped:
+ state = NotRunning;
+ unregisterAllTransitions();
+ emit q->stopped();
+ break;
+ }
+}
+
+void QStateMachinePrivate::scheduleProcess()
+{
+ if ((state != Running) || processing || processingScheduled)
+ return;
+ processingScheduled = true;
+ QMetaObject::invokeMethod(q_func(), "_q_process", Qt::QueuedConnection);
+}
+
+void QStateMachinePrivate::registerTransitions(QAbstractState *state)
+{
+ QState *group = qobject_cast<QState*>(state);
+ if (!group)
+ return;
+ QList<QAbstractTransition*> transitions = QStatePrivate::get(group)->transitions();
+ for (int i = 0; i < transitions.size(); ++i) {
+ QAbstractTransition *t = transitions.at(i);
+ if (QSignalTransition *st = qobject_cast<QSignalTransition*>(t)) {
+ registerSignalTransition(st);
+ }
+#ifndef QT_NO_STATEMACHINE_EVENTFILTER
+ else if (QEventTransition *oet = qobject_cast<QEventTransition*>(t)) {
+ registerEventTransition(oet);
+ }
+#endif
+ }
+}
+
+void QStateMachinePrivate::unregisterTransition(QAbstractTransition *transition)
+{
+ if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
+ unregisterSignalTransition(st);
+ }
+#ifndef QT_NO_STATEMACHINE_EVENTFILTER
+ else if (QEventTransition *oet = qobject_cast<QEventTransition*>(transition)) {
+ unregisterEventTransition(oet);
+ }
+#endif
+}
+
+static int senderSignalIndex(const QObject *sender)
+{
+ QObjectPrivate *d = QObjectPrivate::get(const_cast<QObject*>(sender));
+ QMutexLocker(&d->threadData->mutex);
+ if (!d->currentSender)
+ return -1;
+
+ // Return -1 if d->currentSender isn't in d->senders
+ bool found = false;
+ for (int i = 0; !found && i < d->senders.count(); ++i)
+ found = (d->senders.at(i)->sender == d->currentSender->sender);
+ if (!found)
+ return -1;
+ return d->currentSender->signal;
+}
+
+void QStateMachinePrivate::registerSignalTransition(QSignalTransition *transition)
+{
+ Q_Q(QStateMachine);
+ if (QSignalTransitionPrivate::get(transition)->signalIndex != -1)
+ return; // already registered
+ QObject *sender = QSignalTransitionPrivate::get(transition)->sender;
+ if (!sender)
+ return;
+ QByteArray signal = QSignalTransitionPrivate::get(transition)->signal;
+ if (signal.startsWith('0'+QSIGNAL_CODE))
+ signal.remove(0, 1);
+ int signalIndex = sender->metaObject()->indexOfSignal(signal);
+ if (signalIndex == -1) {
+ qWarning("QSignalTransition: no such signal: %s::%s",
+ sender->metaObject()->className(), signal.constData());
+ return;
+ }
+ QVector<int> &connectedSignalIndexes = connections[sender];
+ if (connectedSignalIndexes.size() <= signalIndex)
+ connectedSignalIndexes.resize(signalIndex+1);
+ if (connectedSignalIndexes.at(signalIndex) == 0) {
+ if (!signalEventGenerator)
+ signalEventGenerator = new QSignalEventGenerator(q);
+ bool ok = QMetaObject::connect(sender, signalIndex, signalEventGenerator,
+ signalEventGenerator->metaObject()->methodOffset());
+ if (!ok) {
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": FAILED to add signal transition from" << transition->sourceState()
+ << ": ( sender =" << sender << ", signal =" << (signal.mid(1))
+ << ", targets =" << transition->targetStates() << ')';
+#endif
+ return;
+ }
+ }
+ ++connectedSignalIndexes[signalIndex];
+ QSignalTransitionPrivate::get(transition)->signalIndex = signalIndex;
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": added signal transition from" << transition->sourceState()
+ << ": ( sender =" << sender << ", signal =" << (signal.mid(1))
+ << ", targets =" << transition->targetStates() << ')';
+#endif
+}
+
+void QStateMachinePrivate::unregisterSignalTransition(QSignalTransition *transition)
+{
+ int signalIndex = QSignalTransitionPrivate::get(transition)->signalIndex;
+ if (signalIndex == -1)
+ return; // not registered
+ QSignalTransitionPrivate::get(transition)->signalIndex = -1;
+ const QObject *sender = QSignalTransitionPrivate::get(transition)->sender;
+ QVector<int> &connectedSignalIndexes = connections[sender];
+ Q_ASSERT(connectedSignalIndexes.size() > signalIndex);
+ Q_ASSERT(connectedSignalIndexes.at(signalIndex) != 0);
+ if (--connectedSignalIndexes[signalIndex] == 0) {
+ Q_ASSERT(signalEventGenerator != 0);
+ QMetaObject::disconnect(sender, signalIndex, signalEventGenerator,
+ signalEventGenerator->metaObject()->methodOffset());
+ int sum = 0;
+ for (int i = 0; i < connectedSignalIndexes.size(); ++i)
+ sum += connectedSignalIndexes.at(i);
+ if (sum == 0)
+ connections.remove(sender);
+ }
+}
+
+void QStateMachinePrivate::unregisterAllTransitions()
+{
+ {
+ QList<QSignalTransition*> transitions = qFindChildren<QSignalTransition*>(rootState);
+ for (int i = 0; i < transitions.size(); ++i)
+ unregisterSignalTransition(transitions.at(i));
+ }
+ {
+ QList<QEventTransition*> transitions = qFindChildren<QEventTransition*>(rootState);
+ for (int i = 0; i < transitions.size(); ++i)
+ unregisterEventTransition(transitions.at(i));
+ }
+}
+
+#ifndef QT_NO_STATEMACHINE_EVENTFILTER
+void QStateMachinePrivate::registerEventTransition(QEventTransition *transition)
+{
+ Q_Q(QStateMachine);
+ if (QEventTransitionPrivate::get(transition)->registered)
+ return;
+ if (transition->eventType() >= QEvent::User) {
+ qWarning("QObject event transitions are not supported for custom types");
+ return;
+ }
+ QObject *object = QEventTransitionPrivate::get(transition)->object;
+ if (!object)
+ return;
+ QObjectPrivate *od = QObjectPrivate::get(object);
+ if (!od->eventFilters.contains(q))
+ object->installEventFilter(q);
+ ++qobjectEvents[object][transition->eventType()];
+ QEventTransitionPrivate::get(transition)->registered = true;
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q << ": added event transition from" << transition->sourceState()
+ << ": ( object =" << object << ", event =" << transition->eventType()
+ << ", targets =" << transition->targetStates() << ')';
+#endif
+}
+
+void QStateMachinePrivate::unregisterEventTransition(QEventTransition *transition)
+{
+ Q_Q(QStateMachine);
+ if (!QEventTransitionPrivate::get(transition)->registered)
+ return;
+ QObject *object = QEventTransitionPrivate::get(transition)->object;
+ QHash<QEvent::Type, int> &events = qobjectEvents[object];
+ Q_ASSERT(events.value(transition->eventType()) > 0);
+ if (--events[transition->eventType()] == 0) {
+ events.remove(transition->eventType());
+ int sum = 0;
+ QHash<QEvent::Type, int>::const_iterator it;
+ for (it = events.constBegin(); it != events.constEnd(); ++it)
+ sum += it.value();
+ if (sum == 0) {
+ qobjectEvents.remove(object);
+ object->removeEventFilter(q);
+ }
+ }
+ QEventTransitionPrivate::get(transition)->registered = false;
+}
+#endif
+
+void QStateMachinePrivate::handleTransitionSignal(const QObject *sender, int signalIndex,
+ void **argv)
+{
+ Q_ASSERT(connections[sender].at(signalIndex) != 0);
+ const QMetaObject *meta = sender->metaObject();
+ QMetaMethod method = meta->method(signalIndex);
+ QList<QByteArray> parameterTypes = method.parameterTypes();
+ int argc = parameterTypes.count();
+ QList<QVariant> vargs;
+ for (int i = 0; i < argc; ++i) {
+ int type = QMetaType::type(parameterTypes.at(i));
+ vargs.append(QVariant(type, argv[i+1]));
+ }
+
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << q_func() << ": sending signal event ( sender =" << sender
+ << ", signal =" << sender->metaObject()->method(signalIndex).signature() << ')';
+#endif
+ internalEventQueue.append(new QSignalEvent(sender, signalIndex, vargs));
+ scheduleProcess();
+}
+
+/*!
+ Constructs a new state machine with the given \a parent.
+*/
+QStateMachine::QStateMachine(QObject *parent)
+ : QObject(*new QStateMachinePrivate, parent)
+{
+}
+
+/*!
+ \internal
+*/
+QStateMachine::QStateMachine(QStateMachinePrivate &dd, QObject *parent)
+ : QObject(dd, parent)
+{
+}
+
+/*!
+ Destroys this state machine.
+*/
+QStateMachine::~QStateMachine()
+{
+}
+
+namespace {
+
+class RootErrorState : public QAbstractState
+{
+public:
+ RootErrorState(QState *parent)
+ : QAbstractState(parent)
+ {
+ setObjectName(QString::fromLatin1("DefaultErrorState"));
+ }
+
+ void onEntry(QEvent *)
+ {
+ QAbstractStatePrivate *d = QAbstractStatePrivate::get(this);
+ QStateMachine *machine = d->machine();
+
+ qWarning("Unrecoverable error detected in running state machine: %s",
+ qPrintable(machine->errorString()));
+ }
+
+ void onExit(QEvent *) {}
+};
+
+class RootState : public QState
+{
+public:
+ RootState(QState *parent)
+ : QState(parent)
+ {
+ }
+
+ void onEntry(QEvent *) {}
+ void onExit(QEvent *) {}
+};
+
+} // namespace
+
+/*!
+ Returns this state machine's root state.
+*/
+QState *QStateMachine::rootState() const
+{
+ Q_D(const QStateMachine);
+ if (!d->rootState) {
+ const_cast<QStateMachinePrivate*>(d)->rootState = new RootState(0);
+ const_cast<QStateMachinePrivate*>(d)->initialErrorStateForRoot = new RootErrorState(d->rootState);
+ d->rootState->setParent(const_cast<QStateMachine*>(this));
+ d->rootState->setErrorState(d->initialErrorStateForRoot);
+ }
+ return d->rootState;
+}
+
+/*!
+ Returns the error state of the state machine's root state.
+
+ \sa QState::errorState()
+*/
+QAbstractState *QStateMachine::errorState() const
+{
+ return rootState()->errorState();
+}
+
+/*!
+ Sets the error state of this state machine's root state to be \a state. When a running state
+ machine encounters an error which puts it in an undefined state, it will enter an error state
+ based on the context of the error that occurred. It will enter this state regardless of what
+ is currently in the event queue.
+
+ If the erroneous state has an error state set, this will be entered by the machine. If no error
+ state has been set, the state machine will search the parent hierarchy recursively for an
+ error state. The error state of the root state can thus be seen as a global error state that
+ applies for the states for which a more specific error state has not been set.
+
+ Before entering the error state, the state machine will set the error code returned by error() and
+ error message returned by errorString().
+
+ The default error state will print a warning to the console containing the information returned by
+ errorString(). By setting a new error state on either the state machine itself, or on specific
+ states, you can fine tune error handling in the state machine.
+
+ If the root state's error state is set to 0, or if the error state selected by the machine itself
+ contains an error, the default error state will be used.
+
+ \sa QState::setErrorState(), rootState()
+*/
+void QStateMachine::setErrorState(QAbstractState *state)
+{
+ rootState()->setErrorState(state);
+}
+
+/*! \enum QStateMachine::Error
+
+ This enum type defines errors that can occur in the state machine at run time. When the state
+ machine encounters an unrecoverable error at run time, it will set the error code returned
+ by error(), the error message returned by errorString(), and enter an error state based on
+ the context of the error.
+
+ \value NoError No error has occurred.
+ \value NoInitialStateError The machine has entered a QState with children which does not have an
+ initial state set. The context of this error is the state which is missing an initial
+ state.
+ \value NoDefaultStateInHistoryStateError The machine has entered a QHistoryState which does not have
+ a default state set. The context of this error is the QHistoryState which is missing a
+ default state.
+ \value NoCommonAncestorForTransitionError The machine has selected a transition whose source
+ and targets are not part of the same tree of states, and thus are not part of the same
+ state machine. Commonly, this could mean that one of the states has not been given
+ any parent or added to any machine. The context of this error is the source state of
+ the transition.
+
+ \sa setErrorState()
+*/
+
+/*!
+ \enum QStateMachine::RestorePolicy
+
+ This enum specifies the restore policy type. The restore policy
+ takes effect when the machine enters a state which sets one or more
+ properties. If the restore policy is set to RestoreProperties,
+ the state machine will save the original value of the property before the
+ new value is set.
+
+ Later, when the machine either enters a state which does not set
+ a value for the given property, the property will automatically be restored
+ to its initial value.
+
+ Only one initial value will be saved for any given property. If a value for a property has
+ already been saved by the state machine, it will not be overwritten until the property has been
+ successfully restored.
+
+ \value DoNotRestoreProperties The state machine should not save the initial values of properties
+ and restore them later.
+ \value RestoreProperties The state machine should save the initial values of properties
+ and restore them later.
+
+ \sa QStateMachine::globalRestorePolicy QState::assignProperty()
+*/
+
+
+/*!
+ Returns the error code of the last error that occurred in the state machine.
+*/
+QStateMachine::Error QStateMachine::error() const
+{
+ Q_D(const QStateMachine);
+ return d->error;
+}
+
+/*!
+ Returns the error string of the last error that occurred in the state machine.
+*/
+QString QStateMachine::errorString() const
+{
+ Q_D(const QStateMachine);
+ return d->errorString;
+}
+
+/*!
+ Clears the error string and error code of the state machine.
+*/
+void QStateMachine::clearError()
+{
+ Q_D(QStateMachine);
+ d->errorString.clear();
+ d->error = NoError;
+}
+
+/*!
+ Returns the restore policy of the state machine.
+
+ \sa setGlobalRestorePolicy()
+*/
+QStateMachine::RestorePolicy QStateMachine::globalRestorePolicy() const
+{
+ Q_D(const QStateMachine);
+ return d->globalRestorePolicy;
+}
+
+/*!
+ Sets the restore policy of the state machine to \a restorePolicy. The default
+ restore policy is QAbstractState::DoNotRestoreProperties.
+
+ \sa globalRestorePolicy()
+*/
+void QStateMachine::setGlobalRestorePolicy(QStateMachine::RestorePolicy restorePolicy)
+{
+ Q_D(QStateMachine);
+ d->globalRestorePolicy = restorePolicy;
+}
+
+/*!
+ Returns this state machine's initial state, or 0 if no initial state has
+ been set.
+*/
+QAbstractState *QStateMachine::initialState() const
+{
+ Q_D(const QStateMachine);
+ if (!d->rootState)
+ return 0;
+ return d->rootState->initialState();
+}
+
+/*!
+ Sets this state machine's initial \a state.
+*/
+void QStateMachine::setInitialState(QAbstractState *state)
+{
+ Q_D(QStateMachine);
+ if (!d->rootState) {
+ if (!state)
+ return;
+ rootState()->setInitialState(state);
+ }
+ d->rootState->setInitialState(state);
+}
+
+/*!
+ Adds the given \a state to this state machine. The state becomes a top-level
+ state (i.e. a child of the rootState()).
+
+ If the state is already in a different machine, it will first be removed
+ from its old machine, and then added to this machine.
+
+ \sa removeState(), rootState(), setInitialState()
+*/
+void QStateMachine::addState(QAbstractState *state)
+{
+ if (!state) {
+ qWarning("QStateMachine::addState: cannot add null state");
+ return;
+ }
+ if (QAbstractStatePrivate::get(state)->machine() == this) {
+ qWarning("QStateMachine::addState: state has already been added to this machine");
+ return;
+ }
+ state->setParent(rootState());
+}
+
+/*!
+ Removes the given \a state from this state machine. The state machine
+ releases ownership of the state.
+
+ \sa addState()
+*/
+void QStateMachine::removeState(QAbstractState *state)
+{
+ if (!state) {
+ qWarning("QStateMachine::removeState: cannot remove null state");
+ return;
+ }
+ if (QAbstractStatePrivate::get(state)->machine() != this) {
+ qWarning("QStateMachine::removeState: state %p's machine (%p)"
+ " is different from this machine (%p)",
+ state, QAbstractStatePrivate::get(state)->machine(), this);
+ return;
+ }
+ state->setParent(0);
+}
+
+/*!
+ Returns whether this state machine is running.
+
+ start(), stop()
+*/
+bool QStateMachine::isRunning() const
+{
+ Q_D(const QStateMachine);
+ return (d->state == QStateMachinePrivate::Running);
+}
+
+/*!
+ Starts this state machine. The machine will reset its configuration and
+ transition to the initial state. When a final top-level state (QFinalState)
+ is entered, the machine will emit the finished() signal.
+
+ \sa started(), finished(), stop(), initialState()
+*/
+void QStateMachine::start()
+{
+ Q_D(QStateMachine);
+
+ if (rootState()->initialState() == 0) {
+ qWarning("QStateMachine::start: No initial state set for machine. Refusing to start.");
+ return;
+ }
+
+ switch (d->state) {
+ case QStateMachinePrivate::NotRunning:
+ d->state = QStateMachinePrivate::Starting;
+ QMetaObject::invokeMethod(this, "_q_start", Qt::QueuedConnection);
+ break;
+ case QStateMachinePrivate::Starting:
+ break;
+ case QStateMachinePrivate::Running:
+ qWarning("QStateMachine::start(): already running");
+ break;
+ }
+}
+
+/*!
+ Stops this state machine. The state machine will stop processing events and
+ then emit the stopped() signal.
+
+ \sa stopped(), start()
+*/
+void QStateMachine::stop()
+{
+ Q_D(QStateMachine);
+ switch (d->state) {
+ case QStateMachinePrivate::NotRunning:
+ break;
+ case QStateMachinePrivate::Starting:
+ // the machine will exit as soon as it enters the event processing loop
+ d->stop = true;
+ break;
+ case QStateMachinePrivate::Running:
+ d->stop = true;
+ d->scheduleProcess();
+ break;
+ }
+}
+
+/*!
+ Posts the given \a event for processing by this state machine, with a delay
+ of \a delay milliseconds.
+
+ This function returns immediately. The event is added to the state machine's
+ event queue. Events are processed in the order posted. The state machine
+ takes ownership of the event and deletes it once it has been processed.
+
+ You can only post events when the state machine is running.
+*/
+void QStateMachine::postEvent(QEvent *event, int delay)
+{
+ Q_D(QStateMachine);
+ if (d->state != QStateMachinePrivate::Running) {
+ qWarning("QStateMachine::postEvent: cannot post event when the state machine is not running");
+ return;
+ }
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << this << ": posting external event" << event << "with delay" << delay;
+#endif
+ if (delay) {
+ int tid = startTimer(delay);
+ d->delayedEvents[tid] = event;
+ } else {
+ d->externalEventQueue.append(event);
+ d->scheduleProcess();
+ }
+}
+
+/*!
+ \internal
+
+ Posts the given internal \a event for processing by this state machine.
+*/
+void QStateMachine::postInternalEvent(QEvent *event)
+{
+ Q_D(QStateMachine);
+#ifdef QSTATEMACHINE_DEBUG
+ qDebug() << this << ": posting internal event" << event;
+#endif
+ d->internalEventQueue.append(event);
+ d->scheduleProcess();
+}
+
+/*!
+ \internal
+
+ Returns the maximal consistent set of states (including parallel and final
+ states) that this state machine is currently in. If a state \c s is in the
+ configuration, it is always the case that the parent of \c s is also in
+ c. Note, however, that the rootState() is not an explicit member of the
+ configuration.
+*/
+QSet<QAbstractState*> QStateMachine::configuration() const
+{
+ Q_D(const QStateMachine);
+ return d->configuration;
+}
+
+/*!
+ \fn QStateMachine::started()
+
+ This signal is emitted when the state machine has entered its initial state
+ (QStateMachine::initialState).
+
+ \sa QStateMachine::finished(), QStateMachine::start()
+*/
+
+/*!
+ \fn QStateMachine::finished()
+
+ This signal is emitted when the state machine has reached a top-level final
+ state (QFinalState).
+
+ \sa QStateMachine::started()
+*/
+
+/*!
+ \fn QStateMachine::stopped()
+
+ This signal is emitted when the state machine has stopped.
+
+ \sa QStateMachine::stop(), QStateMachine::finished()
+*/
+
+/*!
+ \reimp
+*/
+bool QStateMachine::event(QEvent *e)
+{
+ Q_D(QStateMachine);
+ if (e->type() == QEvent::Timer) {
+ QTimerEvent *te = static_cast<QTimerEvent*>(e);
+ int tid = te->timerId();
+ if (d->delayedEvents.contains(tid)) {
+ killTimer(tid);
+ QEvent *ee = d->delayedEvents.take(tid);
+ d->externalEventQueue.append(ee);
+ d->scheduleProcess();
+ return true;
+ }
+ } else if (e->type() == QEvent::ChildAdded) {
+ QChildEvent *ce = static_cast<QChildEvent*>(e);
+ if (QAbstractState *state = qobject_cast<QAbstractState*>(ce->child())) {
+ if (state != rootState()) {
+ state->setParent(rootState());
+ return true;
+ }
+ }
+ }
+ return QObject::event(e);
+}
+
+#ifndef QT_NO_STATEMACHINE_EVENTFILTER
+/*!
+ \reimp
+*/
+bool QStateMachine::eventFilter(QObject *watched, QEvent *event)
+{
+ Q_D(QStateMachine);
+ Q_ASSERT(d->qobjectEvents.contains(watched));
+ if (d->qobjectEvents[watched].contains(event->type()))
+ postEvent(new QWrappedEvent(watched, d->handler->cloneEvent(event)));
+ return false;
+}
+#endif
+
+/*!
+ \internal
+
+ This function is called when the state machine is about to select
+ transitions based on the given \a event.
+
+ The default implementation does nothing.
+*/
+void QStateMachine::beginSelectTransitions(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+/*!
+ \internal
+
+ This function is called when the state machine has finished selecting
+ transitions based on the given \a event.
+
+ The default implementation does nothing.
+*/
+void QStateMachine::endSelectTransitions(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+/*!
+ \internal
+
+ This function is called when the state machine is about to do a microstep.
+
+ The default implementation does nothing.
+*/
+void QStateMachine::beginMicrostep(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+/*!
+ \internal
+
+ This function is called when the state machine has finished doing a
+ microstep.
+
+ The default implementation does nothing.
+*/
+void QStateMachine::endMicrostep(QEvent *event)
+{
+ Q_UNUSED(event);
+}
+
+#ifndef QT_NO_ANIMATION
+
+/*!
+ Returns whether animations are enabled for this state machine.
+*/
+bool QStateMachine::animationsEnabled() const
+{
+ Q_D(const QStateMachine);
+ return d->animationsEnabled;
+}
+
+/*!
+ Sets whether animations are \a enabled for this state machine.
+*/
+void QStateMachine::setAnimationsEnabled(bool enabled)
+{
+ Q_D(QStateMachine);
+ d->animationsEnabled = enabled;
+}
+
+/*!
+ Adds a default \a animation to be considered for any transition.
+*/
+void QStateMachine::addDefaultAnimation(QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimations.append(animation);
+}
+
+/*!
+ Returns the list of default animations that will be considered for any transition.
+*/
+QList<QAbstractAnimation*> QStateMachine::defaultAnimations() const
+{
+ Q_D(const QStateMachine);
+ return d->defaultAnimations;
+}
+
+/*!
+ Removes \a animation from the list of default animations.
+*/
+void QStateMachine::removeDefaultAnimation(QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimations.removeAll(animation);
+}
+
+#endif // QT_NO_ANIMATION
+
+
+static const uint qt_meta_data_QSignalEventGenerator[] = {
+
+ // content:
+ 2, // revision
+ 0, // classname
+ 0, 0, // classinfo
+ 1, 12, // methods
+ 0, 0, // properties
+ 0, 0, // enums/sets
+ 0, 0, // constructors
+
+ // slots: signature, parameters, type, tag, flags
+ 23, 22, 22, 22, 0x0a,
+
+ 0 // eod
+};
+
+static const char qt_meta_stringdata_QSignalEventGenerator[] = {
+ "QSignalEventGenerator\0\0execute()\0"
+};
+
+const QMetaObject QSignalEventGenerator::staticMetaObject = {
+ { &QObject::staticMetaObject, qt_meta_stringdata_QSignalEventGenerator,
+ qt_meta_data_QSignalEventGenerator, 0 }
+};
+
+const QMetaObject *QSignalEventGenerator::metaObject() const
+{
+ return &staticMetaObject;
+}
+
+void *QSignalEventGenerator::qt_metacast(const char *_clname)
+{
+ if (!_clname) return 0;
+ if (!strcmp(_clname, qt_meta_stringdata_QSignalEventGenerator))
+ return static_cast<void*>(const_cast< QSignalEventGenerator*>(this));
+ return QObject::qt_metacast(_clname);
+}
+
+int QSignalEventGenerator::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
+{
+ _id = QObject::qt_metacall(_c, _id, _a);
+ if (_id < 0)
+ return _id;
+ if (_c == QMetaObject::InvokeMetaMethod) {
+ switch (_id) {
+ case 0: {
+// ### in Qt 4.6 we can use QObject::senderSignalIndex()
+ int signalIndex = senderSignalIndex(this);
+ Q_ASSERT(signalIndex != -1);
+ QStateMachine *machine = qobject_cast<QStateMachine*>(parent());
+ QStateMachinePrivate::get(machine)->handleTransitionSignal(sender(), signalIndex, _a);
+ break;
+ }
+ default: ;
+ }
+ _id -= 1;
+ }
+ return _id;
+}
+
+QSignalEventGenerator::QSignalEventGenerator(QStateMachine *parent)
+ : QObject(parent)
+{
+}
+
+/*!
+ \class QSignalEvent
+
+ \brief The QSignalEvent class represents a Qt signal event.
+
+ \since 4.6
+ \ingroup statemachine
+
+ A signal event is generated by a QStateMachine in response to a Qt
+ signal. The QSignalTransition class provides a transition associated with a
+ signal event. QSignalEvent is part of \l{The State Machine Framework}.
+
+ The sender() function returns the object that generated the signal. The
+ signalIndex() function returns the index of the signal. The arguments()
+ function returns the arguments of the signal.
+
+ \sa QSignalTransition
+*/
+
+/*!
+ \internal
+
+ Constructs a new QSignalEvent object with the given \a sender, \a
+ signalIndex and \a arguments.
+*/
+QSignalEvent::QSignalEvent(const QObject *sender, int signalIndex,
+ const QList<QVariant> &arguments)
+ : QEvent(QEvent::Signal), m_sender(sender),
+ m_signalIndex(signalIndex), m_arguments(arguments)
+{
+}
+
+/*!
+ Destroys this QSignalEvent.
+*/
+QSignalEvent::~QSignalEvent()
+{
+}
+
+/*!
+ \fn QSignalEvent::sender() const
+
+ Returns the object that emitted the signal.
+
+ \sa QObject::sender()
+*/
+
+/*!
+ \fn QSignalEvent::signalIndex() const
+
+ Returns the index of the signal.
+
+ \sa QMetaObject::indexOfSignal(), QMetaObject::method()
+*/
+
+/*!
+ \fn QSignalEvent::arguments() const
+
+ Returns the arguments of the signal.
+*/
+
+
+/*!
+ \class QWrappedEvent
+
+ \brief The QWrappedEvent class holds a clone of an event associated with a QObject.
+
+ \since 4.6
+ \ingroup statemachine
+
+ A wrapped event is generated by a QStateMachine in response to a Qt
+ event. The QEventTransition class provides a transition associated with a
+ such an event. QWrappedEvent is part of \l{The State Machine Framework}.
+
+ The object() function returns the object that generated the event. The
+ event() function returns a clone of the original event.
+
+ \sa QEventTransition
+*/
+
+/*!
+ \internal
+
+ Constructs a new QWrappedEvent object with the given \a object
+ and \a event.
+*/
+QWrappedEvent::QWrappedEvent(QObject *object, QEvent *event)
+ : QEvent(QEvent::Wrapped), m_object(object), m_event(event)
+{
+}
+
+/*!
+ Destroys this QWrappedEvent.
+*/
+QWrappedEvent::~QWrappedEvent()
+{
+}
+
+/*!
+ \fn QWrappedEvent::object() const
+
+ Returns the object that the event is associated with.
+*/
+
+/*!
+ \fn QWrappedEvent::event() const
+
+ Returns a clone of the original event.
+*/
+
+QT_END_NAMESPACE
+
+#include "moc_qstatemachine.cpp"
diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h
new file mode 100644
index 0000000..2a98a9a
--- /dev/null
+++ b/src/corelib/statemachine/qstatemachine.h
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSTATEMACHINE_H
+#define QSTATEMACHINE_H
+
+#include <QtCore/qabstractstate.h>
+
+#include <QtCore/qlist.h>
+#include <QtCore/qobject.h>
+#include <QtCore/qset.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QEvent;
+class QAbstractState;
+class QState;
+
+class QStateMachinePrivate;
+class QAbstractAnimation;
+class QAbstractState;
+class Q_CORE_EXPORT QStateMachine : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QState* rootState READ rootState)
+ Q_PROPERTY(QAbstractState* initialState READ initialState WRITE setInitialState)
+ Q_PROPERTY(QAbstractState* errorState READ errorState WRITE setErrorState)
+ Q_PROPERTY(QString errorString READ errorString)
+ Q_PROPERTY(RestorePolicy globalRestorePolicy READ globalRestorePolicy WRITE setGlobalRestorePolicy)
+ Q_ENUMS(RestorePolicy)
+#ifndef QT_NO_ANIMATION
+ Q_PROPERTY(bool animationsEnabled READ animationsEnabled WRITE setAnimationsEnabled)
+#endif
+public:
+ enum RestorePolicy {
+ DoNotRestoreProperties,
+ RestoreProperties
+ };
+
+ enum Error {
+ NoError,
+ NoInitialStateError,
+ NoDefaultStateInHistoryStateError,
+ NoCommonAncestorForTransitionError
+ };
+
+ QStateMachine(QObject *parent = 0);
+ ~QStateMachine();
+
+ void addState(QAbstractState *state);
+ void removeState(QAbstractState *state);
+
+ QState *rootState() const;
+
+ QAbstractState *initialState() const;
+ void setInitialState(QAbstractState *state);
+
+ QAbstractState *errorState() const;
+ void setErrorState(QAbstractState *state);
+
+ Error error() const;
+ QString errorString() const;
+ void clearError();
+
+ bool isRunning() const;
+
+#ifndef QT_NO_ANIMATION
+ bool animationsEnabled() const;
+ void setAnimationsEnabled(bool enabled);
+
+ void addDefaultAnimation(QAbstractAnimation *animation);
+ QList<QAbstractAnimation *> defaultAnimations() const;
+ void removeDefaultAnimation(QAbstractAnimation *animation);
+#endif // QT_NO_ANIMATION
+
+ QStateMachine::RestorePolicy globalRestorePolicy() const;
+ void setGlobalRestorePolicy(QStateMachine::RestorePolicy restorePolicy);
+
+ void postEvent(QEvent *event, int delay = 0);
+
+ QSet<QAbstractState*> configuration() const;
+
+#ifndef QT_NO_STATEMACHINE_EVENTFILTER
+ bool eventFilter(QObject *watched, QEvent *event);
+#endif
+
+public Q_SLOTS:
+ void start();
+ void stop();
+
+Q_SIGNALS:
+ void started();
+ void stopped();
+ void finished();
+
+protected:
+ void postInternalEvent(QEvent *event);
+
+ virtual void beginSelectTransitions(QEvent *event);
+ virtual void endSelectTransitions(QEvent *event);
+
+ virtual void beginMicrostep(QEvent *event);
+ virtual void endMicrostep(QEvent *event);
+
+ bool event(QEvent *e);
+
+protected:
+ QStateMachine(QStateMachinePrivate &dd, QObject *parent);
+
+private:
+ Q_DISABLE_COPY(QStateMachine)
+ Q_DECLARE_PRIVATE(QStateMachine)
+ Q_PRIVATE_SLOT(d_func(), void _q_start())
+ Q_PRIVATE_SLOT(d_func(), void _q_process())
+#ifndef QT_NO_ANIMATION
+ Q_PRIVATE_SLOT(d_func(), void _q_animationFinished())
+#endif
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
new file mode 100644
index 0000000..54953b4
--- /dev/null
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -0,0 +1,216 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSTATEMACHINE_P_H
+#define QSTATEMACHINE_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 <private/qobject_p.h>
+#include <QtCore/qcoreevent.h>
+#include <QtCore/qhash.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qpair.h>
+#include <QtCore/qset.h>
+#include <QtCore/qvector.h>
+
+#include "qstate.h"
+#include "qstate_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QEvent;
+#ifndef QT_NO_STATEMACHINE_EVENTFILTER
+class QEventTransition;
+#endif
+class QSignalEventGenerator;
+class QSignalTransition;
+class QAbstractState;
+class QAbstractTransition;
+class QState;
+
+#ifndef QT_NO_ANIMATION
+class QAbstractAnimation;
+#endif
+
+class QStateMachine;
+class QStateMachinePrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QStateMachine)
+public:
+ enum State {
+ NotRunning,
+ Starting,
+ Running
+ };
+ enum StopProcessingReason {
+ EventQueueEmpty,
+ Finished,
+ Stopped
+ };
+
+ QStateMachinePrivate();
+ ~QStateMachinePrivate();
+
+ static QStateMachinePrivate *get(QStateMachine *q);
+
+ static QState *findLCA(const QList<QAbstractState*> &states);
+
+ static bool stateEntryLessThan(QAbstractState *s1, QAbstractState *s2);
+ static bool stateExitLessThan(QAbstractState *s1, QAbstractState *s2);
+
+ QAbstractState *findErrorState(QAbstractState *context);
+ void setError(QStateMachine::Error error, QAbstractState *currentContext);
+
+ // private slots
+ void _q_start();
+ void _q_process();
+#ifndef QT_NO_ANIMATION
+ void _q_animationFinished();
+#endif
+
+ void microstep(QEvent *event, const QList<QAbstractTransition*> &transitionList);
+ bool isPreempted(const QAbstractState *s, const QSet<QAbstractTransition*> &transitions) const;
+ QSet<QAbstractTransition*> selectTransitions(QEvent *event) const;
+ QList<QAbstractState*> exitStates(QEvent *event, const QList<QAbstractTransition*> &transitionList);
+ void executeTransitionContent(QEvent *event, const QList<QAbstractTransition*> &transitionList);
+ QList<QAbstractState*> enterStates(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions);
+ void addStatesToEnter(QAbstractState *s, QState *root,
+ QSet<QAbstractState*> &statesToEnter,
+ QSet<QAbstractState*> &statesForDefaultEntry);
+
+ void applyProperties(const QList<QAbstractTransition*> &transitionList,
+ const QList<QAbstractState*> &exitedStates,
+ const QList<QAbstractState*> &enteredStates);
+
+ bool isInFinalState(QAbstractState *s) const;
+ static bool isFinal(const QAbstractState *s);
+ static bool isParallel(const QAbstractState *s);
+ static bool isCompound(const QAbstractState *s);
+ static bool isAtomic(const QAbstractState *s);
+ static bool isDescendantOf(const QAbstractState *s, const QAbstractState *other);
+ static QList<QState*> properAncestors(const QAbstractState *s, const QState *upperBound);
+
+ void registerTransitions(QAbstractState *state);
+ void registerSignalTransition(QSignalTransition *transition);
+ void unregisterSignalTransition(QSignalTransition *transition);
+#ifndef QT_NO_STATEMACHINE_EVENTFILTER
+ void registerEventTransition(QEventTransition *transition);
+ void unregisterEventTransition(QEventTransition *transition);
+#endif
+ void unregisterTransition(QAbstractTransition *transition);
+ void unregisterAllTransitions();
+ void handleTransitionSignal(const QObject *sender, int signalIndex,
+ void **args);
+ void scheduleProcess();
+
+ typedef QPair<QObject *, QByteArray> RestorableId;
+ QHash<RestorableId, QVariant> registeredRestorables;
+ void registerRestorable(QObject *object, const QByteArray &propertyName);
+ void unregisterRestorable(QObject *object, const QByteArray &propertyName);
+ bool hasRestorable(QObject *object, const QByteArray &propertyName) const;
+ QVariant restorableValue(QObject *object, const QByteArray &propertyName) const;
+ QList<QPropertyAssignment> restorablesToPropertyList(const QHash<RestorableId, QVariant> &restorables) const;
+
+ State state;
+ bool processing;
+ bool processingScheduled;
+ bool stop;
+ StopProcessingReason stopProcessingReason;
+ QState *rootState;
+ QSet<QAbstractState*> configuration;
+ QList<QEvent*> internalEventQueue;
+ QList<QEvent*> externalEventQueue;
+
+ QStateMachine::Error error;
+ QStateMachine::RestorePolicy globalRestorePolicy;
+
+ QString errorString;
+ QSet<QAbstractState *> pendingErrorStates;
+ QSet<QAbstractState *> pendingErrorStatesForDefaultEntry;
+ QAbstractState *initialErrorStateForRoot;
+
+#ifndef QT_NO_ANIMATION
+ bool animationsEnabled;
+
+ QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> >
+ initializeAnimation(QAbstractAnimation *abstractAnimation,
+ const QPropertyAssignment &prop);
+
+ QHash<QAbstractState*, QList<QAbstractAnimation*> > animationsForState;
+ QHash<QAbstractAnimation*, QPropertyAssignment> propertyForAnimation;
+ QHash<QAbstractAnimation*, QAbstractState*> stateForAnimation;
+ QSet<QAbstractAnimation*> resetAnimationEndValues;
+
+ QList<QAbstractAnimation *> defaultAnimations;
+ QMultiHash<QAbstractState *, QAbstractAnimation *> defaultAnimationsForSource;
+ QMultiHash<QAbstractState *, QAbstractAnimation *> defaultAnimationsForTarget;
+
+#endif // QT_NO_ANIMATION
+
+ QSignalEventGenerator *signalEventGenerator;
+
+ QHash<const QObject*, QVector<int> > connections;
+#ifndef QT_NO_STATEMACHINE_EVENTFILTER
+ QHash<QObject*, QHash<QEvent::Type, int> > qobjectEvents;
+#endif
+ QHash<int, QEvent*> delayedEvents;
+
+ typedef QEvent* (*f_cloneEvent)(QEvent*);
+ struct Handler {
+ f_cloneEvent cloneEvent;
+ };
+
+ static Q_CORE_EXPORT const Handler *handler;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/corelib/statemachine/qwrappedevent.h b/src/corelib/statemachine/qwrappedevent.h
new file mode 100644
index 0000000..b01c608
--- /dev/null
+++ b/src/corelib/statemachine/qwrappedevent.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWRAPPEDEVENT_H
+#define QWRAPPEDEVENT_H
+
+#include <QtCore/qcoreevent.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QObject;
+
+class Q_CORE_EXPORT QWrappedEvent : public QEvent
+{
+public:
+ QWrappedEvent(QObject *object, QEvent *event);
+ ~QWrappedEvent();
+
+ inline QObject *object() const { return m_object; }
+ inline QEvent *event() const { return m_event; }
+
+private:
+ QObject *m_object;
+ QEvent *m_event;
+
+private:
+ Q_DISABLE_COPY(QWrappedEvent)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/corelib/statemachine/statemachine.pri b/src/corelib/statemachine/statemachine.pri
new file mode 100644
index 0000000..5b19bc1
--- /dev/null
+++ b/src/corelib/statemachine/statemachine.pri
@@ -0,0 +1,30 @@
+HEADERS += $$PWD/qstatemachine.h \
+ $$PWD/qstatemachine_p.h \
+ $$PWD/qsignaleventgenerator_p.h \
+ $$PWD/qabstractstate.h \
+ $$PWD/qabstractstate_p.h \
+ $$PWD/qstate.h \
+ $$PWD/qstate_p.h \
+ $$PWD/qfinalstate.h \
+ $$PWD/qhistorystate.h \
+ $$PWD/qhistorystate_p.h \
+ $$PWD/qabstracttransition.h \
+ $$PWD/qabstracttransition_p.h \
+ $$PWD/qsignalevent.h \
+ $$PWD/qsignaltransition.h \
+ $$PWD/qsignaltransition_p.h
+
+SOURCES += $$PWD/qstatemachine.cpp \
+ $$PWD/qabstractstate.cpp \
+ $$PWD/qstate.cpp \
+ $$PWD/qfinalstate.cpp \
+ $$PWD/qhistorystate.cpp \
+ $$PWD/qabstracttransition.cpp \
+ $$PWD/qsignaltransition.cpp
+
+!contains(DEFINES, QT_NO_STATEMACHINE_EVENTFILTER) {
+HEADERS += $$PWD/qwrappedevent.h \
+ $$PWD/qeventtransition.h \
+ $$PWD/qeventtransition_p.h
+SOURCES += $$PWD/qeventtransition.cpp
+}
diff --git a/src/corelib/thread/qmutexpool.cpp b/src/corelib/thread/qmutexpool.cpp
index 96a9940..0d7c890 100644
--- a/src/corelib/thread/qmutexpool.cpp
+++ b/src/corelib/thread/qmutexpool.cpp
@@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE
// qt_global_mutexpool is here for backwards compatability only,
// use QMutexpool::instance() in new clode.
Q_CORE_EXPORT QMutexPool *qt_global_mutexpool = 0;
-Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (true))
+Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (QMutex::Recursive))
/*!
\class QMutexPool
@@ -88,17 +88,17 @@ Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (true))
*/
/*!
- Constructs a QMutexPool, reserving space for \a size QMutexes. If
- \a recursive is true, all QMutexes in the pool will be recursive
- mutexes; otherwise they will all be non-recursive (the default).
+ Constructs a QMutexPool, reserving space for \a size QMutexes. All
+ mutexes in the pool are created with \a recursionMode. By default,
+ all mutexes are non-recursive.
The QMutexes are created when needed, and deleted when the
QMutexPool is destructed.
*/
-QMutexPool::QMutexPool(bool recursive, int size)
- : mutexes(size), count(size), recurs(recursive)
+QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size)
+ : mutexes(size), recursionMode(recursionMode)
{
- for (int index = 0; index < count; ++index) {
+ for (int index = 0; index < mutexes.count(); ++index) {
mutexes[index] = 0;
}
}
@@ -109,7 +109,7 @@ QMutexPool::QMutexPool(bool recursive, int size)
*/
QMutexPool::~QMutexPool()
{
- for (int index = 0; index < count; ++index) {
+ for (int index = 0; index < mutexes.count(); ++index) {
delete mutexes[index];
mutexes[index] = 0;
}
@@ -130,11 +130,11 @@ QMutexPool *QMutexPool::instance()
QMutex *QMutexPool::get(const void *address)
{
Q_ASSERT_X(address != 0, "QMutexPool::get()", "'address' argument cannot be zero");
- int index = int((quintptr(address) >> (sizeof(address) >> 1)) % count);
+ int index = int((quintptr(address) >> (sizeof(address) >> 1)) % mutexes.count());
if (!mutexes[index]) {
// mutex not created, create one
- QMutex *newMutex = new QMutex(recurs ? QMutex::Recursive : QMutex::NonRecursive);
+ QMutex *newMutex = new QMutex(recursionMode);
if (!mutexes[index].testAndSetOrdered(0, newMutex))
delete newMutex;
}
diff --git a/src/corelib/thread/qmutexpool_p.h b/src/corelib/thread/qmutexpool_p.h
index 1009ebb..30a16d4 100644
--- a/src/corelib/thread/qmutexpool_p.h
+++ b/src/corelib/thread/qmutexpool_p.h
@@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QMutexPool
{
public:
- explicit QMutexPool(bool recursive = false, int size = 128);
+ explicit QMutexPool(QMutex::RecursionMode recursionMode = QMutex::NonRecursive, int size = 131);
~QMutexPool();
QMutex *get(const void *address);
@@ -72,9 +72,8 @@ public:
static QMutex *globalInstanceGet(const void *address);
private:
- QVarLengthArray<QAtomicPointer<QMutex>, 128> mutexes;
- int count;
- bool recurs;
+ QVarLengthArray<QAtomicPointer<QMutex>, 131> mutexes;
+ QMutex::RecursionMode recursionMode;
};
extern Q_CORE_EXPORT QMutexPool *qt_global_mutexpool;
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 6aa35f3..49dd52d 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -579,7 +579,7 @@ static inline char qToLower(char c)
return c;
}
-Q_CORE_EXPORT QByteArray::Data QByteArray::shared_null = {Q_BASIC_ATOMIC_INITIALIZER(1),
+QByteArray::Data QByteArray::shared_null = {Q_BASIC_ATOMIC_INITIALIZER(1),
0, 0, shared_null.array, {0} };
QByteArray::Data QByteArray::shared_empty = { Q_BASIC_ATOMIC_INITIALIZER(1),
0, 0, shared_empty.array, {0} };
diff --git a/src/corelib/tools/qcontiguouscache.cpp b/src/corelib/tools/qcontiguouscache.cpp
index 7db3a5a..996ac18 100644
--- a/src/corelib/tools/qcontiguouscache.cpp
+++ b/src/corelib/tools/qcontiguouscache.cpp
@@ -40,10 +40,13 @@
****************************************************************************/
#include "qcontiguouscache.h"
+#ifdef QT_QCONTIGUOUSCACHE_DEBUG
#include <QDebug>
+#endif
QT_BEGIN_NAMESPACE
+#ifdef QT_QCONTIGUOUSCACHE_DEBUG
void QContiguousCacheData::dump() const
{
qDebug() << "capacity:" << alloc;
@@ -51,6 +54,7 @@ void QContiguousCacheData::dump() const
qDebug() << "start:" << start;
qDebug() << "offset:" << offset;
}
+#endif
/*! \class QContiguousCache
\brief The QContiguousCache class is a template class that provides a contiguous cache.
diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h
index 5cd1582..2437f63 100644
--- a/src/corelib/tools/qcontiguouscache.h
+++ b/src/corelib/tools/qcontiguouscache.h
@@ -49,8 +49,10 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
+#undef QT_QCONTIGUOUSCACHE_DEBUG
QT_MODULE(Core)
+
struct Q_CORE_EXPORT QContiguousCacheData
{
QBasicAtomicInt ref;
@@ -60,7 +62,9 @@ struct Q_CORE_EXPORT QContiguousCacheData
int offset;
uint sharable : 1;
+#ifdef QT_QCONTIGUOUSCACHE_DEBUG
void dump() const;
+#endif
};
template <typename T>
@@ -131,8 +135,10 @@ public:
{ return d->offset >= 0 && d->offset < INT_MAX - d->count && (d->offset % d->alloc) == d->start; }
inline void normalizeIndexes() { d->offset = d->start; }
- // debug
+
+#ifdef QT_QCONTIGUOUSCACHE_DEBUG
void dump() const { p->dump(); }
+#endif
private:
void detach_helper();
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index 781514c..090ca61 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -3833,19 +3833,19 @@ void QDateTimePrivate::getUTC(QDate &outDate, QTime &outTime) const
#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_NO_DATESTRING)
QDebug operator<<(QDebug dbg, const QDate &date)
{
- dbg.nospace() << "QDate(" << date.toString() << ")";
+ dbg.nospace() << "QDate(" << date.toString() << ')';
return dbg.space();
}
QDebug operator<<(QDebug dbg, const QTime &time)
{
- dbg.nospace() << "QTime(" << time.toString() << ")";
+ dbg.nospace() << "QTime(" << time.toString() << ')';
return dbg.space();
}
QDebug operator<<(QDebug dbg, const QDateTime &date)
{
- dbg.nospace() << "QDateTime(" << date.toString() << ")";
+ dbg.nospace() << "QDateTime(" << date.toString() << ')';
return dbg.space();
}
#endif
diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp
new file mode 100644
index 0000000..2b027fc
--- /dev/null
+++ b/src/corelib/tools/qeasingcurve.cpp
@@ -0,0 +1,846 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+
+| *property* | *Used for type* |
+| period | QEasingCurve::{In,Out,InOut,OutIn}Elastic |
+| amplitude | QEasingCurve::{In,Out,InOut,OutIn}Bounce, QEasingCurve::{In,Out,InOut,OutIn}Elastic |
+| overshoot | QEasingCurve::{In,Out,InOut,OutIn}Back |
+
+*/
+
+
+
+
+/*!
+ \class QEasingCurve
+ \since 4.6
+ \ingroup animation
+ \brief The QEasingCurve class provides easing curves for controlling animation.
+
+ Easing curves describe a function that controls how the speed of the interpolation
+ between 0 and 1 should be. Easing curves allow transitions from
+ one value to another to appear more natural than a simple constant speed would allow.
+ The QEasingCurve class is usually used in conjunction with the QAnimation class,
+ but can be used on its own.
+
+ To calculate the speed of the interpolation, the easing curve provides the function
+ valueForProgress(), where the \a progress argument specifies the progress of the
+ interpolation: 0 is the start value of the interpolation, 1 is the end value of the
+ interpolation. The returned value is the effective progress of the interpolation.
+ If the returned value is the same as the input value for all input values the easing
+ curve is a linear curve. This is the default behaviour.
+
+ For example,
+ \code
+ QEasingCurve easing(QEasingCurve::InOutQuad);
+
+ for(qreal t = 0.0; t < 1.0; t+=0.1)
+ qWarning() << "Effective progress" << t << " is
+ << easing.valueForProgress(t);
+ \endcode
+ will print the effective progress of the interpolation between 0 and 1.
+
+ When using a QAnimation, the easing curve will be used to control the
+ progress of the interpolation between startValue and endValue:
+ \code
+ QAnimation animation;
+ animation.setStartValue(0);
+ animation.setEndValue(1000);
+ animation.setDuration(1000);
+ animation.setEasingCurve(QEasingCurve::InOutQuad);
+ \endcode
+ */
+
+/*!
+ \enum QEasingCurve::Type
+
+ The type of easing curve.
+
+ \value Linear \inlineimage qeasingcurve-linear.png
+ \br
+ Easing equation function for a simple linear tweening,
+ with no easing.
+ \value InQuad \inlineimage qeasingcurve-inquad.png
+ \br
+ Easing equation function for a quadratic (t^2) easing
+ in: accelerating from zero velocity.
+ \value OutQuad \inlineimage qeasingcurve-outquad.png
+ \br
+ Easing equation function for a quadratic (t^2) easing
+ out: decelerating to zero velocity.
+ \value InOutQuad \inlineimage qeasingcurve-inoutquad.png
+ \br
+ Easing equation function for a quadratic (t^2) easing
+ in/out: acceleration until halfway, then deceleration.
+ \value OutInQuad \inlineimage qeasingcurve-outinquad.png
+ \br
+ Easing equation function for a quadratic (t^2) easing
+ out/in: deceleration until halfway, then acceleration.
+ \value InCubic \inlineimage qeasingcurve-incubic.png
+ \br
+ Easing equation function for a cubic (t^3) easing
+ in: accelerating from zero velocity.
+ \value OutCubic \inlineimage qeasingcurve-outcubic.png
+ \br
+ Easing equation function for a cubic (t^3) easing
+ out: decelerating from zero velocity.
+ \value InOutCubic \inlineimage qeasingcurve-inoutcubic.png
+ \br
+ Easing equation function for a cubic (t^3) easing
+ in/out: acceleration until halfway, then deceleration.
+ \value OutInCubic \inlineimage qeasingcurve-outincubic.png
+ \br
+ Easing equation function for a cubic (t^3) easing
+ out/in: deceleration until halfway, then acceleration.
+ \value InQuart \inlineimage qeasingcurve-inquart.png
+ \br
+ Easing equation function for a quartic (t^4) easing
+ in: accelerating from zero velocity.
+ \value OutQuart \inlineimage qeasingcurve-outquart.png
+ \br
+ Easing equation function for a quartic (t^4) easing
+ out: decelerating from zero velocity.
+ \value InOutQuart \inlineimage qeasingcurve-inoutquart.png
+ \br
+ Easing equation function for a quartic (t^4) easing
+ in/out: acceleration until halfway, then deceleration.
+ \value OutInQuart \inlineimage qeasingcurve-outinquart.png
+ \br
+ Easing equation function for a quartic (t^4) easing
+ out/in: deceleration until halfway, then acceleration.
+ \value InQuint \inlineimage qeasingcurve-inquint.png
+ \br
+ Easing equation function for a quintic (t^5) easing
+ in: accelerating from zero velocity.
+ \value OutQuint \inlineimage qeasingcurve-outquint.png
+ \br
+ Easing equation function for a quintic (t^5) easing
+ out: decelerating from zero velocity.
+ \value InOutQuint \inlineimage qeasingcurve-inoutquint.png
+ \br
+ Easing equation function for a quintic (t^5) easing
+ in/out: acceleration until halfway, then deceleration.
+ \value OutInQuint \inlineimage qeasingcurve-outinquint.png
+ \br
+ Easing equation function for a quintic (t^5) easing
+ out/in: deceleration until halfway, then acceleration.
+ \value InSine \inlineimage qeasingcurve-insine.png
+ \br
+ Easing equation function for a sinusoidal (sin(t)) easing
+ in: accelerating from zero velocity.
+ \value OutSine \inlineimage qeasingcurve-outsine.png
+ \br
+ Easing equation function for a sinusoidal (sin(t)) easing
+ out: decelerating from zero velocity.
+ \value InOutSine \inlineimage qeasingcurve-inoutsine.png
+ \br
+ Easing equation function for a sinusoidal (sin(t)) easing
+ in/out: acceleration until halfway, then deceleration.
+ \value OutInSine \inlineimage qeasingcurve-outinsine.png
+ \br
+ Easing equation function for a sinusoidal (sin(t)) easing
+ out/in: deceleration until halfway, then acceleration.
+ \value InExpo \inlineimage qeasingcurve-inexpo.png
+ \br
+ Easing equation function for an exponential (2^t) easing
+ in: accelerating from zero velocity.
+ \value OutExpo \inlineimage qeasingcurve-outexpo.png
+ \br
+ Easing equation function for an exponential (2^t) easing
+ out: decelerating from zero velocity.
+ \value InOutExpo \inlineimage qeasingcurve-inoutexpo.png
+ \br
+ Easing equation function for an exponential (2^t) easing
+ in/out: acceleration until halfway, then deceleration.
+ \value OutInExpo \inlineimage qeasingcurve-outinexpo.png
+ \br
+ Easing equation function for an exponential (2^t) easing
+ out/in: deceleration until halfway, then acceleration.
+ \value InCirc \inlineimage qeasingcurve-incirc.png
+ \br
+ Easing equation function for a circular (sqrt(1-t^2)) easing
+ in: accelerating from zero velocity.
+ \value OutCirc \inlineimage qeasingcurve-outcirc.png
+ \br
+ Easing equation function for a circular (sqrt(1-t^2)) easing
+ out: decelerating from zero velocity.
+ \value InOutCirc \inlineimage qeasingcurve-inoutcirc.png
+ \br
+ Easing equation function for a circular (sqrt(1-t^2)) easing
+ in/out: acceleration until halfway, then deceleration.
+ \value OutInCirc \inlineimage qeasingcurve-outincirc.png
+ \br
+ Easing equation function for a circular (sqrt(1-t^2)) easing
+ out/in: deceleration until halfway, then acceleration.
+ \value InElastic \inlineimage qeasingcurve-inelastic.png
+ \br
+ Easing equation function for an elastic
+ (exponentially decaying sine wave) easing in:
+ accelerating from zero velocity. The peak amplitude
+ can be set with the \e amplitude parameter, and the
+ period of decay by the \e period parameter.
+ \value OutElastic \inlineimage qeasingcurve-outelastic.png
+ \br
+ Easing equation function for an elastic
+ (exponentially decaying sine wave) easing out:
+ decelerating from zero velocity. The peak amplitude
+ can be set with the \e amplitude parameter, and the
+ period of decay by the \e period parameter.
+ \value InOutElastic \inlineimage qeasingcurve-inoutelastic.png
+ \br
+ Easing equation function for an elastic
+ (exponentially decaying sine wave) easing in/out:
+ acceleration until halfway, then deceleration.
+ \value OutInElastic \inlineimage qeasingcurve-outinelastic.png
+ \br
+ Easing equation function for an elastic
+ (exponentially decaying sine wave) easing out/in:
+ deceleration until halfway, then acceleration.
+ \value InBack \inlineimage qeasingcurve-inback.png
+ \br
+ Easing equation function for a back (overshooting
+ cubic easing: (s+1)*t^3 - s*t^2) easing in:
+ accelerating from zero velocity.
+ \value OutBack \inlineimage qeasingcurve-outback.png
+ \br
+ Easing equation function for a back (overshooting
+ cubic easing: (s+1)*t^3 - s*t^2) easing out:
+ decelerating from zero velocity.
+ \value InOutBack \inlineimage qeasingcurve-inoutback.png
+ \br
+ Easing equation function for a back (overshooting
+ cubic easing: (s+1)*t^3 - s*t^2) easing in/out:
+ acceleration until halfway, then deceleration.
+ \value OutInBack \inlineimage qeasingcurve-outinback.png
+ \br
+ Easing equation function for a back (overshooting
+ cubic easing: (s+1)*t^3 - s*t^2) easing out/in:
+ deceleration until halfway, then acceleration.
+ \value InBounce \inlineimage qeasingcurve-inbounce.png
+ \br
+ Easing equation function for a bounce (exponentially
+ decaying parabolic bounce) easing in: accelerating
+ from zero velocity.
+ \value OutBounce \inlineimage qeasingcurve-outbounce.png
+ \br
+ Easing equation function for a bounce (exponentially
+ decaying parabolic bounce) easing out: decelerating
+ from zero velocity.
+ \value InOutBounce \inlineimage qeasingcurve-inoutbounce.png
+ \br
+ Easing equation function for a bounce (exponentially
+ decaying parabolic bounce) easing in/out:
+ acceleration until halfway, then deceleration.
+ \value OutInBounce \inlineimage qeasingcurve-outinbounce.png
+ \br
+ Easing equation function for a bounce (exponentially
+ decaying parabolic bounce) easing out/in:
+ deceleration until halfway, then acceleration.
+ \omitvalue InCurve
+ \omitvalue OutCurve
+ \omitvalue SineCurve
+ \omitvalue CosineCurve
+ \value Custom This is returned if the user have specified a custom curve type with setCustomType(). Note that you cannot call setType() with this value, but type() can return it.
+ \omitvalue NCurveTypes
+*/
+
+/*!
+ \typedef QEasingCurve::EasingFunction
+
+ This is a typedef for a pointer to a function with the following
+ signature:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qeasingcurve.cpp 0
+*/
+
+#include "qeasingcurve.h"
+
+#ifndef QT_NO_DEBUG_STREAM
+#include <QtCore/qdebug.h>
+#include <QtCore/QString>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+static bool isConfigFunction(QEasingCurve::Type type)
+{
+ return type >= QEasingCurve::InElastic
+ && type <= QEasingCurve::OutInBounce;
+}
+
+class QEasingCurveFunction
+{
+public:
+ enum Type { In, Out, InOut, OutIn };
+
+ QEasingCurveFunction(QEasingCurveFunction::Type type = In, qreal period = 0.3, qreal amplitude = 1.0,
+ qreal overshoot = 1.70158f)
+ : _t(type), _p(period), _a(amplitude), _o(overshoot)
+ { }
+ virtual ~QEasingCurveFunction() {}
+ virtual qreal value(qreal t);
+ virtual QEasingCurveFunction *copy() const;
+ bool operator==(const QEasingCurveFunction& other);
+
+ Type _t;
+ qreal _p;
+ qreal _a;
+ qreal _o;
+};
+
+qreal QEasingCurveFunction::value(qreal t)
+{
+ return t;
+}
+
+QEasingCurveFunction *QEasingCurveFunction::copy() const
+{
+ return new QEasingCurveFunction(_t, _p, _a, _o);
+}
+
+bool QEasingCurveFunction::operator==(const QEasingCurveFunction& other)
+{
+ return _t == other._t &&
+ _p == other._p &&
+ _a == other._a &&
+ _o == other._o;
+}
+
+QT_BEGIN_INCLUDE_NAMESPACE
+#include "../../3rdparty/easing/easing.cpp"
+QT_END_INCLUDE_NAMESPACE
+
+class QEasingCurvePrivate
+{
+public:
+ QEasingCurvePrivate()
+ : type(QEasingCurve::Linear),
+ config(0),
+ func(&easeNone)
+ { }
+ ~QEasingCurvePrivate() { delete config; }
+ void setType_helper(QEasingCurve::Type);
+
+ QEasingCurve::Type type;
+ QEasingCurveFunction *config;
+ QEasingCurve::EasingFunction func;
+};
+
+struct ElasticEase : public QEasingCurveFunction
+{
+ ElasticEase(Type type)
+ : QEasingCurveFunction(type, qreal(0.3), qreal(1.0))
+ { }
+
+ QEasingCurveFunction *copy() const
+ {
+ ElasticEase *rv = new ElasticEase(_t);
+ rv->_p = _p;
+ rv->_a = _a;
+ return rv;
+ }
+
+ qreal value(qreal t)
+ {
+ qreal p = (_p < 0) ? 0.3f : _p;
+ qreal a = (_a < 0) ? 1.0f : _a;
+ switch(_t) {
+ case In:
+ return easeInElastic(t, a, p);
+ case Out:
+ return easeOutElastic(t, a, p);
+ case InOut:
+ return easeInOutElastic(t, a, p);
+ case OutIn:
+ return easeOutInElastic(t, a, p);
+ default:
+ return t;
+ }
+ }
+};
+
+struct BounceEase : public QEasingCurveFunction
+{
+ BounceEase(Type type)
+ : QEasingCurveFunction(type, 0.3f, 1.0f)
+ { }
+
+ QEasingCurveFunction *copy() const
+ {
+ BounceEase *rv = new BounceEase(_t);
+ rv->_a = _a;
+ return rv;
+ }
+
+ qreal value(qreal t)
+ {
+ qreal a = (_a < 0) ? 1.0f : _a;
+ switch(_t) {
+ case In:
+ return easeInBounce(t, a);
+ case Out:
+ return easeOutBounce(t, a);
+ case InOut:
+ return easeInOutBounce(t, a);
+ case OutIn:
+ return easeOutInBounce(t, a);
+ default:
+ return t;
+ }
+ }
+};
+
+struct BackEase : public QEasingCurveFunction
+{
+ BackEase(Type type)
+ : QEasingCurveFunction(type, 0.3f, 1.0f, 1.70158f)
+ { }
+
+ QEasingCurveFunction *copy() const
+ {
+ BackEase *rv = new BackEase(_t);
+ rv->_o = _o;
+ return rv;
+ }
+
+ qreal value(qreal t)
+ {
+ qreal o = (_o < 0) ? 1.70158f : _o;
+ switch(_t) {
+ case In:
+ return easeInBack(t, o);
+ case Out:
+ return easeOutBack(t, o);
+ case InOut:
+ return easeInOutBack(t, o);
+ case OutIn:
+ return easeOutInBack(t, o);
+ default:
+ return t;
+ }
+ }
+};
+
+static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve)
+{
+ switch(curve) {
+ case QEasingCurve::Linear:
+ return &easeNone;
+ case QEasingCurve::InQuad:
+ return &easeInQuad;
+ case QEasingCurve::OutQuad:
+ return &easeOutQuad;
+ case QEasingCurve::InOutQuad:
+ return &easeInOutQuad;
+ case QEasingCurve::OutInQuad:
+ return &easeOutInQuad;
+ case QEasingCurve::InCubic:
+ return &easeInCubic;
+ case QEasingCurve::OutCubic:
+ return &easeOutCubic;
+ case QEasingCurve::InOutCubic:
+ return &easeInOutCubic;
+ case QEasingCurve::OutInCubic:
+ return &easeOutInCubic;
+ case QEasingCurve::InQuart:
+ return &easeInQuart;
+ case QEasingCurve::OutQuart:
+ return &easeOutQuart;
+ case QEasingCurve::InOutQuart:
+ return &easeInOutQuart;
+ case QEasingCurve::OutInQuart:
+ return &easeOutInQuart;
+ case QEasingCurve::InQuint:
+ return &easeInQuint;
+ case QEasingCurve::OutQuint:
+ return &easeOutQuint;
+ case QEasingCurve::InOutQuint:
+ return &easeInOutQuint;
+ case QEasingCurve::OutInQuint:
+ return &easeOutInQuint;
+ case QEasingCurve::InSine:
+ return &easeInSine;
+ case QEasingCurve::OutSine:
+ return &easeOutSine;
+ case QEasingCurve::InOutSine:
+ return &easeInOutSine;
+ case QEasingCurve::OutInSine:
+ return &easeOutInSine;
+ case QEasingCurve::InExpo:
+ return &easeInExpo;
+ case QEasingCurve::OutExpo:
+ return &easeOutExpo;
+ case QEasingCurve::InOutExpo:
+ return &easeInOutExpo;
+ case QEasingCurve::OutInExpo:
+ return &easeOutInExpo;
+ case QEasingCurve::InCirc:
+ return &easeInCirc;
+ case QEasingCurve::OutCirc:
+ return &easeOutCirc;
+ case QEasingCurve::InOutCirc:
+ return &easeInOutCirc;
+ case QEasingCurve::OutInCirc:
+ return &easeOutInCirc;
+ // Internal for, compatibility with QTimeLine only ??
+ case QEasingCurve::InCurve:
+ return &easeInCurve;
+ case QEasingCurve::OutCurve:
+ return &easeOutCurve;
+ case QEasingCurve::SineCurve:
+ return &easeSineCurve;
+ case QEasingCurve::CosineCurve:
+ return &easeCosineCurve;
+ default:
+ return 0;
+ };
+}
+
+static QEasingCurveFunction *curveToFunctionObject(QEasingCurve::Type type)
+{
+ QEasingCurveFunction *curveFunc = 0;
+ switch(type) {
+ case QEasingCurve::InElastic:
+ curveFunc = new ElasticEase(ElasticEase::In);
+ break;
+ case QEasingCurve::OutElastic:
+ curveFunc = new ElasticEase(ElasticEase::Out);
+ break;
+ case QEasingCurve::InOutElastic:
+ curveFunc = new ElasticEase(ElasticEase::InOut);
+ break;
+ case QEasingCurve::OutInElastic:
+ curveFunc = new ElasticEase(ElasticEase::OutIn);
+ break;
+ case QEasingCurve::OutBounce:
+ curveFunc = new BounceEase(BounceEase::Out);
+ break;
+ case QEasingCurve::InBounce:
+ curveFunc = new BounceEase(BounceEase::In);
+ break;
+ case QEasingCurve::OutInBounce:
+ curveFunc = new BounceEase(BounceEase::OutIn);
+ break;
+ case QEasingCurve::InOutBounce:
+ curveFunc = new BounceEase(BounceEase::InOut);
+ break;
+ case QEasingCurve::InBack:
+ curveFunc = new BackEase(BackEase::In);
+ break;
+ case QEasingCurve::OutBack:
+ curveFunc = new BackEase(BackEase::Out);
+ break;
+ case QEasingCurve::InOutBack:
+ curveFunc = new BackEase(BackEase::InOut);
+ break;
+ case QEasingCurve::OutInBack:
+ curveFunc = new BackEase(BackEase::OutIn);
+ break;
+ default:
+ curveFunc = new QEasingCurveFunction(QEasingCurveFunction::In, 0.3f, 1.0f, 1.70158f); // ###
+ }
+
+ return curveFunc;
+}
+
+/*!
+ Constructs an easing curve of the given \a type.
+ */
+QEasingCurve::QEasingCurve(Type type)
+ : d_ptr(new QEasingCurvePrivate)
+{
+ setType(type);
+}
+
+/*!
+ Construct a copy of \a other.
+ */
+QEasingCurve::QEasingCurve(const QEasingCurve &other)
+: d_ptr(new QEasingCurvePrivate)
+{
+ // ### non-atomic, requires malloc on shallow copy
+ *d_ptr = *other.d_ptr;
+ if(other.d_ptr->config)
+ d_ptr->config = other.d_ptr->config->copy();
+}
+
+/*!
+ Destructor.
+ */
+
+QEasingCurve::~QEasingCurve()
+{
+ delete d_ptr;
+}
+
+/*!
+ Copy \a other.
+ */
+QEasingCurve &QEasingCurve::operator=(const QEasingCurve &other)
+{
+ // ### non-atomic, requires malloc on shallow copy
+ if (d_ptr->config) {
+ delete d_ptr->config;
+ d_ptr->config = 0;
+ }
+
+ *d_ptr = *other.d_ptr;
+ if(other.d_ptr->config)
+ d_ptr->config = other.d_ptr->config->copy();
+
+ return *this;
+}
+
+/*!
+ Compare this easing curve with \a other and returns true if they are
+ equal. It will also compare the properties of a curve.
+ */
+bool QEasingCurve::operator==(const QEasingCurve &other) const
+{
+ bool res = d_ptr->func == other.d_ptr->func
+ && d_ptr->type == other.d_ptr->type;
+ if (res && d_ptr->config && other.d_ptr->config) {
+ // catch the config content
+ res = d_ptr->config->operator==(*(other.d_ptr->config));
+ }
+ return res;
+}
+
+/*!
+ \fn bool QEasingCurve::operator!=(const QEasingCurve &other) const
+ Compare this easing curve with \a other and returns true if they are not equal.
+ It will also compare the properties of a curve.
+
+ \sa operator==()
+*/
+
+/*!
+ Returns the amplitude. This is not applicable for all curve types.
+ It is only applicable for bounce and elastic curves (curves of type()
+ QEasingCurve::InBounce, QEasingCurve::OutBounce, QEasingCurve::InOutBounce,
+ QEasingCurve::OutInBounce, QEasingCurve::InElastic, QEasingCurve::OutElastic,
+ QEasingCurve::InOutElastic or QEasingCurve::OutInElastic).
+ */
+qreal QEasingCurve::amplitude() const
+{
+ return d_ptr->config ? d_ptr->config->_a : 1.0;
+}
+
+/*!
+ Sets the amplitude to \a amplitude.
+
+ This will set the amplitude of the bounce or the amplitude of the
+ elastic "spring" effect. The higher the number, the higher the amplitude.
+ \sa amplitude()
+*/
+void QEasingCurve::setAmplitude(qreal amplitude)
+{
+ if (!d_ptr->config)
+ d_ptr->config = curveToFunctionObject(d_ptr->type);
+ d_ptr->config->_a = amplitude;
+}
+
+/*!
+ Returns the period. This is not applicable for all curve types.
+ It is only applicable if type() is QEasingCurve::InElastic, QEasingCurve::OutElastic,
+ QEasingCurve::InOutElastic or QEasingCurve::OutInElastic.
+ */
+qreal QEasingCurve::period() const
+{
+ return d_ptr->config ? d_ptr->config->_p : 0.3;
+}
+
+/*!
+ Sets the period to \a period.
+ Setting a small period value will give a high frequency of the curve. A
+ large period will give it a small frequency.
+
+ \sa period()
+*/
+void QEasingCurve::setPeriod(qreal period)
+{
+ if (!d_ptr->config)
+ d_ptr->config = curveToFunctionObject(d_ptr->type);
+ d_ptr->config->_p = period;
+}
+
+/*!
+ Returns the overshoot. This is not applicable for all curve types.
+ It is only applicable if type() is QEasingCurve::InBack, QEasingCurve::OutBack,
+ QEasingCurve::InOutBack or QEasingCurve::OutInBack.
+ */
+qreal QEasingCurve::overshoot() const
+{
+ return d_ptr->config ? d_ptr->config->_o : 1.70158f;
+}
+
+/*!
+ Sets the overshoot to \a overshoot.
+
+ 0 produces no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent.
+
+ \sa overshoot()
+*/
+void QEasingCurve::setOvershoot(qreal overshoot)
+{
+ if (!d_ptr->config)
+ d_ptr->config = curveToFunctionObject(d_ptr->type);
+ d_ptr->config->_o = overshoot;
+}
+
+/*!
+ Returns the type of the easing curve.
+*/
+QEasingCurve::Type QEasingCurve::type() const
+{
+ return d_ptr->type;
+}
+
+void QEasingCurvePrivate::setType_helper(QEasingCurve::Type newType)
+{
+ qreal amp = -1.0;
+ qreal period = -1.0;
+ qreal overshoot = -1.0;
+
+ if (config) {
+ amp = config->_a;
+ period = config->_p;
+ overshoot = config->_o;
+ delete config;
+ config = 0;
+ }
+
+ if (isConfigFunction(newType) || (amp != -1.0) || (period != -1.0) || (overshoot != -1.0)) {
+ config = curveToFunctionObject(newType);
+ if (amp != -1.0)
+ config->_a = amp;
+ if (period != -1.0)
+ config->_p = period;
+ if (overshoot != -1.0)
+ config->_o = overshoot;
+ func = 0;
+ } else if (newType != QEasingCurve::Custom) {
+ func = curveToFunc(newType);
+ }
+ Q_ASSERT((func == 0) == (config != 0));
+ type = newType;
+}
+
+/*!
+ Sets the type of the easing curve to \a type.
+*/
+void QEasingCurve::setType(Type type)
+{
+ if (d_ptr->type == type)
+ return;
+ if (type < Linear || type >= NCurveTypes - 1) {
+ qWarning("QEasingCurve: Invalid curve type %d", type);
+ return;
+ }
+
+ d_ptr->setType_helper(type);
+}
+
+/*!
+ Sets a custom easing curve that is defined by the user in the function \a func.
+ The signature of the function is qreal myEasingFunction(qreal progress),
+ where \e progress and the return value is considered to be normalized between 0 and 1.
+ (In some cases the return value can be outside that range)
+ After calling this function type() will return QEasingCurve::Custom.
+ \a func cannot be zero.
+
+ \sa customType()
+ \sa valueForProgress()
+*/
+void QEasingCurve::setCustomType(EasingFunction func)
+{
+ if (!func) {
+ qWarning("Function pointer must not be null");
+ return;
+ }
+ d_ptr->func = func;
+ d_ptr->setType_helper(Custom);
+}
+
+/*!
+ Returns the function pointer to the custom easing curve.
+ If type() does not return QEasingCurve::Custom, this function
+ will return 0.
+*/
+QEasingCurve::EasingFunction QEasingCurve::customType() const
+{
+ return d_ptr->type == Custom ? d_ptr->func : 0;
+}
+
+/*!
+ Return the effective progress for the easing curve at \a progress.
+ While \a progress must be between 0 and 1, the returned effective progress
+ can be outside those bounds. For instance, QEasingCurve::InBack will
+ return negative values in the beginning of the function.
+ */
+qreal QEasingCurve::valueForProgress(qreal progress) const
+{
+ progress = qBound<qreal>(0, progress, 1);
+ if (d_ptr->func)
+ return d_ptr->func(progress);
+ else if (d_ptr->config)
+ return d_ptr->config->value(progress);
+ else
+ return progress;
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug debug, const QEasingCurve &item)
+{
+ debug << "type:" << item.d_ptr->type
+ << "func:" << item.d_ptr->func;
+ if (item.d_ptr->config) {
+ debug << QString::fromAscii("period:%1").arg(item.d_ptr->config->_p, 0, 'f', 20)
+ << QString::fromAscii("amp:%1").arg(item.d_ptr->config->_a, 0, 'f', 20)
+ << QString::fromAscii("overshoot:%1").arg(item.d_ptr->config->_o, 0, 'f', 20);
+ }
+ return debug;
+}
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/corelib/tools/qeasingcurve.h b/src/corelib/tools/qeasingcurve.h
new file mode 100644
index 0000000..a240bc0
--- /dev/null
+++ b/src/corelib/tools/qeasingcurve.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QEASINGCURVE_H
+#define QEASINGCURVE_H
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qobjectdefs.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QEasingCurvePrivate;
+class Q_CORE_EXPORT QEasingCurve
+{
+ Q_GADGET
+ Q_ENUMS(Type)
+public:
+ enum Type {
+ Linear,
+ InQuad, OutQuad, InOutQuad, OutInQuad,
+ InCubic, OutCubic, InOutCubic, OutInCubic,
+ InQuart, OutQuart, InOutQuart, OutInQuart,
+ InQuint, OutQuint, InOutQuint, OutInQuint,
+ InSine, OutSine, InOutSine, OutInSine,
+ InExpo, OutExpo, InOutExpo, OutInExpo,
+ InCirc, OutCirc, InOutCirc, OutInCirc,
+ InElastic, OutElastic, InOutElastic, OutInElastic,
+ InBack, OutBack, InOutBack, OutInBack,
+ InBounce, OutBounce, InOutBounce, OutInBounce,
+ InCurve, OutCurve, SineCurve, CosineCurve,
+ Custom, NCurveTypes
+ };
+
+ QEasingCurve(Type type = Linear);
+ QEasingCurve(const QEasingCurve &other);
+ ~QEasingCurve();
+
+ QEasingCurve &operator=(const QEasingCurve &other);
+ bool operator==(const QEasingCurve &other) const;
+ inline bool operator!=(const QEasingCurve &other) const
+ { return !(this->operator==(other)); }
+
+ qreal amplitude() const;
+ void setAmplitude(qreal amplitude);
+
+ qreal period() const;
+ void setPeriod(qreal period);
+
+ qreal overshoot() const;
+ void setOvershoot(qreal overshoot);
+
+ Type type() const;
+ void setType(Type type);
+ typedef qreal (*EasingFunction)(qreal progress);
+ void setCustomType(EasingFunction func);
+ EasingFunction customType() const;
+
+ qreal valueForProgress(qreal progress) const;
+private:
+ QEasingCurvePrivate *d_ptr;
+ friend Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QEasingCurve &item);
+};
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QEasingCurve &item);
+#endif
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp
index f615dcd..88825a3 100644
--- a/src/corelib/tools/qline.cpp
+++ b/src/corelib/tools/qline.cpp
@@ -260,7 +260,7 @@ QT_BEGIN_NAMESPACE
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug d, const QLine &p)
{
- d << "QLine(" << p.p1() << "," << p.p2() << ")";
+ d << "QLine(" << p.p1() << ',' << p.p2() << ')';
return d;
}
#endif
@@ -822,7 +822,7 @@ qreal QLineF::angle(const QLineF &l) const
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug d, const QLineF &p)
{
- d << "QLineF(" << p.p1() << "," << p.p2() << ")";
+ d << "QLineF(" << p.p1() << ',' << p.p2() << ')';
return d;
}
#endif
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 66e3921..248137a 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -120,7 +120,7 @@ static char *_qdtoa( NEEDS_VOLATILE double d, int mode, int ndigits, int *decpt,
Q_CORE_EXPORT char *qdtoa(double d, int mode, int ndigits, int *decpt,
int *sign, char **rve, char **digits_str);
Q_CORE_EXPORT double qstrtod(const char *s00, char const **se, bool *ok);
-Q_CORE_EXPORT qlonglong qstrtoll(const char *nptr, const char **endptr, register int base, bool *ok);
+static qlonglong qstrtoll(const char *nptr, const char **endptr, register int base, bool *ok);
static qulonglong qstrtoull(const char *nptr, const char **endptr, register int base, bool *ok);
/******************************************************************************
@@ -1136,7 +1136,7 @@ static QString macToQtFormat(const QString &sys_fmt)
break;
case 'S': // fractional second
if (repeat < 3)
- result += QLatin1String("z");
+ result += QLatin1Char('z');
else
result += QLatin1String("zzz");
break;
@@ -1150,7 +1150,7 @@ static QString macToQtFormat(const QString &sys_fmt)
if (repeat >= 2)
result += QLatin1String("dd");
else
- result += QLatin1String("d");
+ result += QLatin1Char('d');
break;
case 'a':
result += QLatin1String("AP");
@@ -4671,7 +4671,7 @@ static qulonglong qstrtoull(const char *nptr, const char **endptr, register int
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
-Q_CORE_EXPORT qlonglong qstrtoll(const char *nptr, const char **endptr, register int base, bool *ok)
+static qlonglong qstrtoll(const char *nptr, const char **endptr, register int base, bool *ok)
{
register const char *s;
register qulonglong acc;
diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp
index 5cc71d6..90b44b1 100644
--- a/src/corelib/tools/qpoint.cpp
+++ b/src/corelib/tools/qpoint.cpp
@@ -373,7 +373,7 @@ QDebug operator<<(QDebug dbg, const QPoint &p) {
QDebug operator<<(QDebug d, const QPointF &p)
{
- d.nospace() << "QPointF(" << p.x() << ", " << p.y() << ")";
+ d.nospace() << "QPointF(" << p.x() << ", " << p.y() << ')';
return d;
}
#endif
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index c3649e3..29509c5 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -195,6 +195,68 @@ static int ucstrnicmp(const ushort *a, const ushort *b, int l)
return ucstricmp(a, a + l, b, b + l);
}
+static bool qMemEquals(const quint16 *a, const quint16 *b, int length)
+{
+ // Benchmarking indicates that doing memcmp is much slower than
+ // executing the comparison ourselves.
+ // To make it even faster, we do a 32-bit comparison, comparing
+ // twice the amount of data as a normal word-by-word comparison.
+ //
+ // Benchmarking results on a 2.33 GHz Core2 Duo, with a 64-QChar
+ // block of data, with 4194304 iterations (per iteration):
+ // operation usec cpu ticks
+ // memcmp 330 710
+ // 16-bit 79 167-171
+ // 32-bit aligned 49 105-109
+ //
+ // Testing also indicates that unaligned 32-bit loads are as
+ // performant as 32-bit aligned.
+ if (a == b || !length)
+ return true;
+
+ register union {
+ const quint16 *w;
+ const quint32 *d;
+ quintptr value;
+ } sa, sb;
+ sa.w = a;
+ sb.w = b;
+
+ // check alignment
+ if ((sa.value & 2) == (sb.value & 2)) {
+ // both addresses have the same alignment
+ if (sa.value & 2) {
+ // both addresses are not aligned to 4-bytes boundaries
+ // compare the first character
+ if (*sa.w != *sb.w)
+ return false;
+ --length;
+ ++sa.w;
+ ++sb.w;
+
+ // now both addresses are 4-bytes aligned
+ }
+
+ // both addresses are 4-bytes aligned
+ // do a fast 32-bit comparison
+ register const quint32 *e = sa.d + (length >> 1);
+ for ( ; sa.d != e; ++sa.d, ++sb.d) {
+ if (*sa.d != *sb.d)
+ return false;
+ }
+
+ // do we have a tail?
+ return (length & 1) ? *sa.w == *sb.w : true;
+ } else {
+ // one of the addresses isn't 4-byte aligned but the other is
+ register const quint16 *e = sa.w + length;
+ for ( ; sa.w != e; ++sa.w, ++sb.w) {
+ if (*sa.w != *sb.w)
+ return false;
+ }
+ }
+ return true;
+}
/*!
\internal
@@ -1908,8 +1970,10 @@ QString &QString::replace(QChar c, const QLatin1String &after, Qt::CaseSensitivi
*/
bool QString::operator==(const QString &other) const
{
- return (size() == other.size()) &&
- (memcmp((char*)unicode(),(char*)other.unicode(), size()*sizeof(QChar))==0);
+ if (d->size != other.d->size)
+ return false;
+
+ return qMemEquals(d->data, other.d->data, d->size);
}
/*!
@@ -3136,7 +3200,7 @@ bool QString::startsWith(const QString& s, Qt::CaseSensitivity cs) const
if (s.d->size > d->size)
return false;
if (cs == Qt::CaseSensitive) {
- return memcmp((char*)d->data, (char*)s.d->data, s.d->size*sizeof(QChar)) == 0;
+ return qMemEquals(d->data, s.d->data, s.d->size);
} else {
uint last = 0;
uint olast = 0;
@@ -3207,7 +3271,7 @@ bool QString::endsWith(const QString& s, Qt::CaseSensitivity cs) const
if (pos < 0)
return false;
if (cs == Qt::CaseSensitive) {
- return memcmp((char*)&d->data[pos], (char*)s.d->data, s.d->size*sizeof(QChar)) == 0;
+ return qMemEquals(d->data + pos, s.d->data, s.d->size);
} else {
uint last = 0;
uint olast = 0;
@@ -7692,7 +7756,8 @@ QString QStringRef::toString() const {
*/
bool operator==(const QStringRef &s1,const QStringRef &s2)
{ return (s1.size() == s2.size() &&
- (memcmp((char*)s1.unicode(), (char*)s2.unicode(), s1.size()*sizeof(QChar))==0)); }
+ qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));
+}
/*! \relates QStringRef
@@ -7701,7 +7766,8 @@ bool operator==(const QStringRef &s1,const QStringRef &s2)
*/
bool operator==(const QString &s1,const QStringRef &s2)
{ return (s1.size() == s2.size() &&
- (memcmp((char*)s1.unicode(), (char*)s2.unicode(), s1.size()*sizeof(QChar))==0)); }
+ qMemEquals((const ushort *)s1.unicode(), (const ushort *)s2.unicode(), s1.size()));
+}
/*! \relates QStringRef
diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp
index 3a03558..ee4f73c 100644
--- a/src/corelib/tools/qtimeline.cpp
+++ b/src/corelib/tools/qtimeline.cpp
@@ -48,20 +48,6 @@
QT_BEGIN_NAMESPACE
-static const qreal pi = qreal(3.14159265359);
-static const qreal halfPi = pi / qreal(2.0);
-
-
-static inline qreal qt_sinProgress(qreal value)
-{
- return qSin((value * pi) - halfPi) / 2 + qreal(0.5);
-}
-
-static inline qreal qt_smoothBeginEndMixFactor(qreal value)
-{
- return qMin(qMax(1 - value * 2 + qreal(0.3), qreal(0.0)), qreal(1.0));
-}
-
class QTimeLinePrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QTimeLine)
@@ -70,7 +56,7 @@ public:
: startTime(0), duration(1000), startFrame(0), endFrame(0),
updateInterval(1000 / 25),
totalLoopCount(1), currentLoopCount(0), currentTime(0), timerId(0),
- direction(QTimeLine::Forward), curveShape(QTimeLine::EaseInOutCurve),
+ direction(QTimeLine::Forward), easingCurve(QEasingCurve::InOutSine),
state(QTimeLine::NotRunning)
{ }
@@ -88,7 +74,7 @@ public:
QTime timer;
QTimeLine::Direction direction;
- QTimeLine::CurveShape curveShape;
+ QEasingCurve easingCurve;
QTimeLine::State state;
inline void setState(QTimeLine::State newState)
{
@@ -523,12 +509,68 @@ void QTimeLine::setUpdateInterval(int interval)
QTimeLine::CurveShape QTimeLine::curveShape() const
{
Q_D(const QTimeLine);
- return d->curveShape;
+ switch (d->easingCurve.type()) {
+ default:
+ case QEasingCurve::InOutSine:
+ return EaseInOutCurve;
+ case QEasingCurve::InCurve:
+ return EaseInCurve;
+ case QEasingCurve::OutCurve:
+ return EaseOutCurve;
+ case QEasingCurve::Linear:
+ return LinearCurve;
+ case QEasingCurve::SineCurve:
+ return SineCurve;
+ case QEasingCurve::CosineCurve:
+ return CosineCurve;
+ }
+ return EaseInOutCurve;
}
+
void QTimeLine::setCurveShape(CurveShape shape)
{
+ switch (shape) {
+ default:
+ case EaseInOutCurve:
+ setEasingCurve(QEasingCurve(QEasingCurve::InOutSine));
+ break;
+ case EaseInCurve:
+ setEasingCurve(QEasingCurve(QEasingCurve::InCurve));
+ break;
+ case EaseOutCurve:
+ setEasingCurve(QEasingCurve(QEasingCurve::OutCurve));
+ break;
+ case LinearCurve:
+ setEasingCurve(QEasingCurve(QEasingCurve::Linear));
+ break;
+ case SineCurve:
+ setEasingCurve(QEasingCurve(QEasingCurve::SineCurve));
+ break;
+ case CosineCurve:
+ setEasingCurve(QEasingCurve(QEasingCurve::CosineCurve));
+ break;
+ }
+}
+
+/*!
+ \property QTimeLine::easingCurve
+
+ Specifies the easing curve that the timeline will use.
+ If both easing curve and curveShape are set, the last set property will
+ override the previous one. (If valueForTime() is reimplemented it will
+ override both)
+*/
+
+QEasingCurve QTimeLine::easingCurve() const
+{
+ Q_D(const QTimeLine);
+ return d->easingCurve;
+}
+
+void QTimeLine::setEasingCurve(const QEasingCurve& curve)
+{
Q_D(QTimeLine);
- d->curveShape = shape;
+ d->easingCurve = curve;
}
/*!
@@ -608,42 +650,8 @@ qreal QTimeLine::valueForTime(int msec) const
Q_D(const QTimeLine);
msec = qMin(qMax(msec, 0), d->duration);
- // Simple linear interpolation
qreal value = msec / qreal(d->duration);
-
- switch (d->curveShape) {
- case EaseInOutCurve:
- value = qt_sinProgress(value);
- break;
- // SmoothBegin blends Smooth and Linear Interpolation.
- // Progress 0 - 0.3 : Smooth only
- // Progress 0.3 - ~ 0.5 : Mix of Smooth and Linear
- // Progress ~ 0.5 - 1 : Linear only
- case EaseInCurve: {
- const qreal sinProgress = qt_sinProgress(value);
- const qreal linearProgress = value;
- const qreal mix = qt_smoothBeginEndMixFactor(value);
- value = sinProgress * mix + linearProgress * (1 - mix);
- break;
- }
- case EaseOutCurve: {
- const qreal sinProgress = qt_sinProgress(value);
- const qreal linearProgress = value;
- const qreal mix = qt_smoothBeginEndMixFactor(1 - value);
- value = sinProgress * mix + linearProgress * (1 - mix);
- break;
- }
- case SineCurve:
- value = (qSin(((msec * pi * 2) / d->duration) - pi/2) + 1) / 2;
- break;
- case CosineCurve:
- value = (qCos(((msec * pi * 2) / d->duration) - pi/2) + 1) / 2;
- break;
- default:
- break;
- }
-
- return value;
+ return d->easingCurve.valueForProgress(value);
}
/*!
diff --git a/src/corelib/tools/qtimeline.h b/src/corelib/tools/qtimeline.h
index 18c3980..48c9232 100644
--- a/src/corelib/tools/qtimeline.h
+++ b/src/corelib/tools/qtimeline.h
@@ -42,6 +42,7 @@
#ifndef QTIMELINE_H
#define QTIMELINE_H
+#include <QtCore/qeasingcurve.h>
#include <QtCore/qobject.h>
QT_BEGIN_HEADER
@@ -60,6 +61,7 @@ class Q_CORE_EXPORT QTimeLine : public QObject
Q_PROPERTY(Direction direction READ direction WRITE setDirection)
Q_PROPERTY(int loopCount READ loopCount WRITE setLoopCount)
Q_PROPERTY(CurveShape curveShape READ curveShape WRITE setCurveShape)
+ Q_PROPERTY(QEasingCurve easingCurve READ easingCurve WRITE setEasingCurve)
public:
enum State {
NotRunning,
@@ -105,6 +107,9 @@ public:
CurveShape curveShape() const;
void setCurveShape(CurveShape shape);
+ QEasingCurve easingCurve() const;
+ void setEasingCurve(const QEasingCurve &curve);
+
int currentTime() const;
int currentFrame() const;
qreal currentValue() const;
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index a6fdac7..90287cb 100644
--- a/src/corelib/tools/tools.pri
+++ b/src/corelib/tools/tools.pri
@@ -11,6 +11,7 @@ HEADERS += \
tools/qcryptographichash.h \
tools/qdatetime.h \
tools/qdatetime_p.h \
+ tools/qeasingcurve.h \
tools/qhash.h \
tools/qline.h \
tools/qlinkedlist.h \
@@ -46,6 +47,7 @@ SOURCES += \
tools/qbytearraymatcher.cpp \
tools/qcryptographichash.cpp \
tools/qdatetime.cpp \
+ tools/qeasingcurve.cpp \
tools/qhash.cpp \
tools/qline.cpp \
tools/qlinkedlist.cpp \
diff --git a/src/gui/animation/animation.pri b/src/gui/animation/animation.pri
new file mode 100644
index 0000000..27763ca
--- /dev/null
+++ b/src/gui/animation/animation.pri
@@ -0,0 +1,3 @@
+# Qt gui animation module
+
+SOURCES += animation/qguivariantanimation.cpp
diff --git a/src/gui/animation/qguivariantanimation.cpp b/src/gui/animation/qguivariantanimation.cpp
new file mode 100644
index 0000000..37ca6a1
--- /dev/null
+++ b/src/gui/animation/qguivariantanimation.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT_NO_ANIMATION
+
+#include <QtCore/qvariantanimation.h>
+#include <private/qvariantanimation_p.h>
+
+#include <QtGui/qcolor.h>
+
+QT_BEGIN_NAMESPACE
+
+template<> Q_INLINE_TEMPLATE QColor _q_interpolate(const QColor &f,const QColor &t, qreal progress)
+{
+ return QColor(_q_interpolate(f.red(), t.red(), progress),
+ _q_interpolate(f.green(), t.green(), progress),
+ _q_interpolate(f.blue(), t.blue(), progress),
+ _q_interpolate(f.alpha(), t.alpha(), progress));
+}
+
+static int qRegisterGuiGetInterpolator()
+{
+ qRegisterAnimationInterpolator<QColor>(_q_interpolateVariant<QColor>);
+ return 1;
+}
+Q_CONSTRUCTOR_FUNCTION(qRegisterGuiGetInterpolator)
+
+static int qUnregisterGuiGetInterpolator()
+{
+ qRegisterAnimationInterpolator<QColor>(0);
+ return 1;
+}
+Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator)
+
+QT_END_NAMESPACE
+
+#endif //QT_NO_ANIMATION
diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp
index 903cd74..3ccae3a 100644
--- a/src/gui/dialogs/qfiledialog.cpp
+++ b/src/gui/dialogs/qfiledialog.cpp
@@ -837,8 +837,8 @@ QStringList QFileDialogPrivate::addDefaultSuffixToFiles(const QStringList filesT
// This check is needed since we might be at the root directory
// and on Windows it already ends with slash.
QString path = rootPath();
- if (!path.endsWith(QLatin1String("/")))
- path += QLatin1String("/");
+ if (!path.endsWith(QLatin1Char('/')))
+ path += QLatin1Char('/');
path += name;
files.append(path);
}
@@ -2649,7 +2649,7 @@ void QFileDialogPrivate::_q_deleteCurrent()
void QFileDialogPrivate::_q_autoCompleteFileName(const QString &text)
{
- if (text.startsWith(QLatin1String("//")) || text.startsWith(QLatin1String("\\"))) {
+ if (text.startsWith(QLatin1String("//")) || text.startsWith(QLatin1Char('\\'))) {
qFileDialogUi->listView->selectionModel()->clearSelection();
return;
}
@@ -2691,7 +2691,7 @@ void QFileDialogPrivate::_q_updateOkButton()
QStringList files = q->selectedFiles();
QString lineEditText = lineEdit()->text();
- if (lineEditText.startsWith(QLatin1String("//")) || lineEditText.startsWith(QLatin1String("\\"))) {
+ if (lineEditText.startsWith(QLatin1String("//")) || lineEditText.startsWith(QLatin1Char('\\'))) {
button->setEnabled(true);
if (acceptMode == QFileDialog::AcceptSave)
button->setText(isOpenDirectory ? QFileDialog::tr("&Open") : acceptLabel);
@@ -3197,7 +3197,7 @@ QStringList QFSCompletor::splitPath(const QString &path) const
doubleSlash.clear();
#endif
- QRegExp re(QLatin1String("[") + QRegExp::escape(sep) + QLatin1String("]"));
+ QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']'));
#ifdef Q_OS_WIN
QStringList parts = pathCopy.split(re, QString::SkipEmptyParts);
diff --git a/src/gui/dialogs/qfiledialog_win.cpp b/src/gui/dialogs/qfiledialog_win.cpp
index 6962674..75a1820 100644
--- a/src/gui/dialogs/qfiledialog_win.cpp
+++ b/src/gui/dialogs/qfiledialog_win.cpp
@@ -214,10 +214,10 @@ static OPENFILENAMEA *qt_win_make_OFNA(QWidget *parent,
aInitSel = "";
} else {
aInitSel = QDir::toNativeSeparators(initialSelection).toLocal8Bit();
- aInitSel.replace("<", "");
- aInitSel.replace(">", "");
- aInitSel.replace("\"", "");
- aInitSel.replace("|", "");
+ aInitSel.replace('<', "");
+ aInitSel.replace('>', "");
+ aInitSel.replace('\"', "");
+ aInitSel.replace('|', "");
}
int maxLen = mode == QFileDialog::ExistingFiles ? maxMultiLen : maxNameLen;
aInitSel.resize(maxLen + 1); // make room for return value
@@ -286,10 +286,10 @@ static OPENFILENAME* qt_win_make_OFN(QWidget *parent,
tTitle = title;
QString initSel = QDir::toNativeSeparators(initialSelection);
if (!initSel.isEmpty()) {
- initSel.replace(QLatin1String("<"), QLatin1String(""));
- initSel.replace(QLatin1String(">"), QLatin1String(""));
- initSel.replace(QLatin1String("\""), QLatin1String(""));
- initSel.replace(QLatin1String("|"), QLatin1String(""));
+ initSel.remove(QLatin1Char('<'));
+ initSel.remove(QLatin1Char('>'));
+ initSel.remove(QLatin1Char('\"'));
+ initSel.remove(QLatin1Char('|'));
}
int maxLen = mode == QFileDialog::ExistingFiles ? maxMultiLen : maxNameLen;
@@ -811,7 +811,7 @@ QString qt_win_get_existing_directory(const QFileDialogArgs &args)
QDir::setCurrent(currentDir);
if (!result.isEmpty())
- result.replace(QLatin1String("\\"), QLatin1String("/"));
+ result.replace(QLatin1Char('\\'), QLatin1Char('/'));
return result;
}
diff --git a/src/gui/dialogs/qfilesystemmodel.cpp b/src/gui/dialogs/qfilesystemmodel.cpp
index 012d3a1..825f8b6 100644
--- a/src/gui/dialogs/qfilesystemmodel.cpp
+++ b/src/gui/dialogs/qfilesystemmodel.cpp
@@ -337,7 +337,7 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS
{
Q_Q(const QFileSystemModel);
Q_UNUSED(q);
- if (path.isEmpty() || path == myComputer() || path.startsWith(QLatin1String(":")))
+ if (path.isEmpty() || path == myComputer() || path.startsWith(QLatin1Char(':')))
return const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
// Construct the nodes up to the new root path if they need to be built
diff --git a/src/gui/dialogs/qmessagebox.cpp b/src/gui/dialogs/qmessagebox.cpp
index 533c538..ae5b4a3 100644
--- a/src/gui/dialogs/qmessagebox.cpp
+++ b/src/gui/dialogs/qmessagebox.cpp
@@ -1310,7 +1310,7 @@ void QMessageBox::keyPressEvent(QKeyEvent *e)
if (e == QKeySequence::Copy) {
QString separator = QString::fromLatin1("---------------------------\n");
QString textToCopy = separator;
- separator.prepend(QLatin1String("\n"));
+ separator.prepend(QLatin1Char('\n'));
textToCopy += windowTitle() + separator; // title
textToCopy += d->label->text() + separator; // text
diff --git a/src/gui/dialogs/qmessagebox.h b/src/gui/dialogs/qmessagebox.h
index 8d9b9fa..c6fb3bc 100644
--- a/src/gui/dialogs/qmessagebox.h
+++ b/src/gui/dialogs/qmessagebox.h
@@ -191,6 +191,8 @@ public:
static StandardButton information(QWidget *parent, const QString &title,
const QString &text, StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton);
+ // ### Qt 5: Replace Ok with Yes|No in question() function.
+ // Also consider if Ok == Yes and Cancel == No.
static StandardButton question(QWidget *parent, const QString &title,
const QString &text, StandardButtons buttons = Ok,
StandardButton defaultButton = NoButton);
diff --git a/src/gui/dialogs/qprintpreviewdialog.cpp b/src/gui/dialogs/qprintpreviewdialog.cpp
index 3580fdc..29a2738 100644
--- a/src/gui/dialogs/qprintpreviewdialog.cpp
+++ b/src/gui/dialogs/qprintpreviewdialog.cpp
@@ -558,7 +558,7 @@ void QPrintPreviewDialogPrivate::_q_print()
suffix = QLatin1String(".ps");
}
QString fileName = QFileDialog::getSaveFileName(q, title, printer->outputFileName(),
- QLatin1String("*") + suffix);
+ QLatin1Char('*') + suffix);
if (!fileName.isEmpty()) {
if (QFileInfo(fileName).suffix().isEmpty())
fileName.append(suffix);
diff --git a/src/gui/embedded/qscreen_qws.cpp b/src/gui/embedded/qscreen_qws.cpp
index f3f54d9..91121e7 100644
--- a/src/gui/embedded/qscreen_qws.cpp
+++ b/src/gui/embedded/qscreen_qws.cpp
@@ -49,6 +49,7 @@
#include "qpixmap.h"
#include "qvarlengtharray.h"
#include "qwsdisplay_qws.h"
+#include "qpainter.h"
#include <private/qdrawhelper_p.h>
#include <private/qpaintengine_raster_p.h>
#include <private/qpixmap_raster_p.h>
@@ -2710,7 +2711,7 @@ void QScreen::compose(int level, const QRegion &exposed, QRegion &blend,
default:
break;
}
- spanData.setup(qwsServer->backgroundBrush(), 256);
+ spanData.setup(qwsServer->backgroundBrush(), 256, QPainter::CompositionMode_SourceOver);
spanData.dx = off.x();
spanData.dy = off.y();
} else if (!surface->isBuffered()) {
@@ -2775,7 +2776,7 @@ void QScreen::paintBackground(const QRegion &r)
rb.prepare(&img);
QSpanData spanData;
spanData.init(&rb, 0);
- spanData.setup(bg, 256);
+ spanData.setup(bg, 256, QPainter::CompositionMode_Source);
spanData.dx = off.x();
spanData.dy = off.y();
Q_ASSERT(spanData.blend);
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index fb95875..7096dab 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -130,12 +130,18 @@
\img graphicsview-parentchild.png
+ \section Transformation
+
QGraphicsItem supports affine transformations in addition to its base
position, pos(). To change the item's transformation, you can either pass
- a transformation matrix to setTransform(), or call one of the convenience
- functions rotate(), scale(), translate(), or shear(). Item transformations
- accumulate from parent to child, so if both a parent and child item are
- rotated 90 degrees, the child's total transformation will be 180 degrees.
+ a transformation matrix to setTransform(), or set the different transformation
+ properties (transformOrigin, x/y/zRotation, x/yScale, horizontal/verticalShear).
+ Note that setting the transformation matrix conflicts with using the properties.
+ Setting the properties will overwrite the transformation set with setTransform,
+ and using setTransform will reset the properties.
+
+ Item transformations accumulate from parent to child, so if both a parent and child
+ item are rotated 90 degrees, the child's total transformation will be 180 degrees.
Similarly, if the item's parent is scaled to 2x its original size, its
children will also be twice as large. An item's transformation does not
affect its own local geometry; all geometry functions (e.g., contains(),
@@ -146,6 +152,22 @@
and scenePos(), which returns its position in scene coordinates. To reset
an item's matrix, call resetTransform().
+ The order you set the transformation properties does not affect the resulting transformation
+ The resulting transformation is always computed in the following order
+
+ \code
+ [Origin] [RotateX] [RotateY] [RotateZ] [Shear] [Scale] [-Origin]
+ \endcode
+
+ So the transformation is equivalent to the following code
+
+ \code
+ QTransform().translate(xOrigin, yOrigin).rotate(xRotation, Qt::XAxis).rotate(yRotation, Qt::YAxis).rotate(zRotation, Qt::ZAxis)
+ .shear(horizontalShear, verticalShear).scale(xScale, yScale).translate(-xOrigin, -yOrigin);
+ \endcode
+
+ \section Painting
+
The paint() function is called by QGraphicsView to paint the item's
contents. The item has no background or default fill of its own; whatever
is behind the item will shine through all areas that are not explicitly
@@ -161,6 +183,8 @@
high z-values. Stacking order applies to sibling items; parents are always
drawn before their children.
+ \section Events
+
QGraphicsItem receives events from QGraphicsScene through the virtual
function sceneEvent(). This function distributes the most common events
to a set of convenience event handlers:
@@ -186,6 +210,8 @@
by the virtual function sceneEventFilter(). You can remove item
event filters by calling removeSceneEventFilter().
+ \section Custom Data
+
Sometimes it's useful to register custom data with an item, be it a custom
item, or a standard item. You can call setData() on any item to store data
in it using a key-value pair (the key being an integer, and the value is a
@@ -338,16 +364,17 @@
\value ItemTransformChange The item's transformation matrix changes. This
notification is only sent when the item's local transformation matrix
- changes (i.e., as a result of calling setTransform(), or one of the
- convenience transformation functions, such as rotate()). The value
+ changes (i.e., as a result of calling setTransform(). The value
argument is the new matrix (i.e., a QTransform); to get the old matrix,
- call transform(). Do not call setTransform() or any of the transformation
- convenience functions in itemChange() as this notification is delivered;
+ call transform(). Do not call setTransform() or set any of the transformation
+ properties in itemChange() as this notification is delivered;
instead, you can return the new matrix from itemChange().
+ This notification is not sent if you change the transformation properties.
\value ItemTransformHasChanged The item's transformation matrix has
- changed. This notification is only sent after the item's local
- trasformation matrix has changed. The value argument is the new matrix
+ changed either because setTransform is called, or one of the transformation
+ properties is changed. This notification is only sent after the item's local
+ transformation matrix has changed. The value argument is the new matrix
(same as transform()), and QGraphicsItem ignores the return value for this
notification (i.e., a read-only notification).
@@ -2588,8 +2615,13 @@ QMatrix QGraphicsItem::matrix() const
/*!
\since 4.3
- Returns this item's transformation matrix. If no matrix has been set, the
- identity matrix is returned.
+ Returns this item's transformation matrix.
+
+ Either the one set by setTransform, or the resulting transformation from
+ all the transfmation properties
+
+ If no matrix or transformation property has been set, the
+ identity matrix is returned.
\sa setTransform(), sceneTransform()
*/
@@ -2597,10 +2629,306 @@ QTransform QGraphicsItem::transform() const
{
if (!d_ptr->hasTransform)
return QTransform();
+ if (d_ptr->hasDecomposedTransform && d_ptr->dirtyTransform) {
+ QGraphicsItemPrivate::DecomposedTransform *decomposed = d_ptr->decomposedTransform();
+ QTransform x;
+ decomposed->generateTransform(&x);
+ QVariant v(x);
+ d_ptr->setExtra(QGraphicsItemPrivate::ExtraTransform, v);
+ d_ptr->dirtyTransform = 0;
+ const_cast<QGraphicsItem *>(this)->itemChange(ItemTransformHasChanged, v);
+ return x;
+ }
return qVariantValue<QTransform>(d_ptr->extra(QGraphicsItemPrivate::ExtraTransform));
}
/*!
+ \property QGraphicsItem::xRotation
+
+ \since 4.6
+
+ This property holds the rotation angle in degrees around the X axis
+
+ The default is 0
+
+ \warning setting this property is conflicting with calling setTransform.
+ If a transform has been set, this function return the default value.
+
+ \sa {Transformations}
+*/
+qreal QGraphicsItem::xRotation() const
+{
+ return d_ptr->decomposedTransform()->xRotation;
+}
+
+void QGraphicsItem::setXRotation(qreal angle)
+{
+ if (!d_ptr->dirtyTransform) {
+ d_ptr->fullUpdateHelper(true);
+ prepareGeometryChange();
+ }
+ QGraphicsItemPrivate::DecomposedTransform *decomposed = d_ptr->decomposedTransform();
+ decomposed->xRotation = angle;
+ if (!d_ptr->dirtyTransform)
+ d_ptr->invalidateSceneTransformCache();
+ d_ptr->dirtyTransform = 1;
+ d_ptr->hasTransform = 1;
+}
+
+/*!
+ \property QGraphicsItem::yRotation
+
+ \since 4.6
+
+ This property holds the rotation angle in degrees around the Y axis
+
+ The default is 0
+
+ \warning setting this property is conflicting with calling setTransform.
+ If a transform has been set, this function return the default value.
+
+ \sa {Transformations}
+*/
+qreal QGraphicsItem::yRotation() const
+{
+ return d_ptr->decomposedTransform()->yRotation;
+}
+
+void QGraphicsItem::setYRotation(qreal angle)
+{
+ if (!d_ptr->dirtyTransform) {
+ d_ptr->fullUpdateHelper(true);
+ prepareGeometryChange();
+ }
+ QGraphicsItemPrivate::DecomposedTransform *decomposed = d_ptr->decomposedTransform();
+ decomposed->yRotation = angle;
+ if (!d_ptr->dirtyTransform)
+ d_ptr->invalidateSceneTransformCache();
+ d_ptr->dirtyTransform = 1;
+ d_ptr->hasTransform = 1;
+}
+
+/*!
+ \property QGraphicsItem::zRotation
+
+ \since 4.6
+
+ This property holds the rotation angle in degrees around the Z axis
+
+ The default is 0
+
+ \warning setting this property is conflicting with calling setTransform.
+ If a transform has been set, this function return the default value.
+
+ \sa {Transformations}
+*/
+qreal QGraphicsItem::zRotation() const
+{
+ return d_ptr->decomposedTransform()->zRotation;
+}
+
+void QGraphicsItem::setZRotation(qreal angle)
+{
+ if (!d_ptr->dirtyTransform) {
+ d_ptr->fullUpdateHelper(true);
+ prepareGeometryChange();
+ }
+ QGraphicsItemPrivate::DecomposedTransform *decomposed = d_ptr->decomposedTransform();
+ decomposed->zRotation = angle;
+ if (!d_ptr->dirtyTransform)
+ d_ptr->invalidateSceneTransformCache();
+ d_ptr->dirtyTransform = 1;
+ d_ptr->hasTransform = 1;
+}
+
+void QGraphicsItem::setRotation(qreal x, qreal y, qreal z)
+{
+ setXRotation(x);
+ setYRotation(y);
+ setZRotation(z);
+}
+
+/*!
+ \property QGraphicsItem::xScale
+
+ \since 4.6
+
+ This property holds the scale factor on the X axis.
+
+ The default is 1
+
+ \warning setting this property is conflicting with calling setTransform.
+ If a transform has been set, this function return the default value.
+
+ \sa {Transformations}
+*/
+qreal QGraphicsItem::xScale() const
+{
+ return d_ptr->decomposedTransform()->xScale;
+}
+
+void QGraphicsItem::setXScale(qreal factor)
+{
+ if (!d_ptr->dirtyTransform) {
+ d_ptr->fullUpdateHelper(true);
+ prepareGeometryChange();
+ }
+ QGraphicsItemPrivate::DecomposedTransform *decomposed = d_ptr->decomposedTransform();
+ decomposed->xScale = factor;
+ if (!d_ptr->dirtyTransform)
+ d_ptr->invalidateSceneTransformCache();
+ d_ptr->dirtyTransform = 1;
+ d_ptr->hasTransform = 1;
+}
+
+/*!
+ \property QGraphicsItem::yScale
+
+ \since 4.6
+
+ This property holds the scale factor on the Y axis.
+
+ The default is 1
+
+ \warning setting this property is conflicting with calling setTransform.
+ If a transform has been set, this function return the default value.
+
+ \sa {Transformations}
+*/
+qreal QGraphicsItem::yScale() const
+{
+ return d_ptr->decomposedTransform()->yScale;
+}
+
+void QGraphicsItem::setYScale(qreal factor)
+{
+ if (!d_ptr->dirtyTransform) {
+ d_ptr->fullUpdateHelper(true);
+ prepareGeometryChange();
+ }
+ QGraphicsItemPrivate::DecomposedTransform *decomposed = d_ptr->decomposedTransform();
+ decomposed->yScale = factor;
+ if (!d_ptr->dirtyTransform)
+ d_ptr->invalidateSceneTransformCache();
+ d_ptr->dirtyTransform = 1;
+ d_ptr->hasTransform = 1;
+}
+
+void QGraphicsItem::setScale(qreal sx, qreal sy)
+{
+ setXScale(sx);
+ setYScale(sy);
+}
+
+/*!
+ \property QGraphicsItem::horizontalShear
+
+ \since 4.6
+
+ This property holds the horizontal shear.
+
+ The default is 0.
+
+ \warning setting this property is conflicting with calling setTransform.
+ If a transform has been set, this function return the default value.
+
+ \sa {Transformations}
+*/
+qreal QGraphicsItem::horizontalShear() const
+{
+ return d_ptr->decomposedTransform()->horizontalShear;
+}
+
+void QGraphicsItem::setHorizontalShear(qreal shear)
+{
+ if (!d_ptr->dirtyTransform) {
+ d_ptr->fullUpdateHelper(true);
+ prepareGeometryChange();
+ }
+ QGraphicsItemPrivate::DecomposedTransform *decomposed = d_ptr->decomposedTransform();
+ decomposed->horizontalShear = shear;
+ if (!d_ptr->dirtyTransform)
+ d_ptr->invalidateSceneTransformCache();
+ d_ptr->dirtyTransform = 1;
+ d_ptr->hasTransform = 1;
+}
+
+/*!
+ \property QGraphicsItem::verticalShear
+
+ \since 4.6
+
+ This property holds the vertical shear.
+
+ The default is 0.
+
+ \warning setting this property is conflicting with calling setTransform.
+ If a transform has been set, this function return the default value.
+
+ \sa {Transformations}
+*/
+qreal QGraphicsItem::verticalShear() const
+{
+ return d_ptr->decomposedTransform()->verticalShear;
+}
+
+void QGraphicsItem::setVerticalShear(qreal shear)
+{
+ if (!d_ptr->dirtyTransform) {
+ d_ptr->fullUpdateHelper(true);
+ prepareGeometryChange();
+ }
+ QGraphicsItemPrivate::DecomposedTransform *decomposed = d_ptr->decomposedTransform();
+ decomposed->verticalShear = shear;
+ if (!d_ptr->dirtyTransform)
+ d_ptr->invalidateSceneTransformCache();
+ d_ptr->dirtyTransform = 1;
+ d_ptr->hasTransform = 1;
+}
+
+void QGraphicsItem::setShear(qreal sh, qreal sv)
+{
+ setHorizontalShear(sh);
+ setVerticalShear(sv);
+}
+
+/*!
+ \property QGraphicsItem::transformOrigin
+
+ \since 4.6
+
+ This property holds the transformation origin for the transformation properties.
+ This does not apply to the transformation set by setTransform.
+
+ The default is QPointF(0,0).
+
+ \warning setting this property is conflicting with calling setTransform.
+ If a transform has been set, this function return the default value.
+
+ \sa {Transformations}
+*/
+QPointF QGraphicsItem::transformOrigin() const
+{
+ const QGraphicsItemPrivate::DecomposedTransform *decomposed = d_ptr->decomposedTransform();
+ return QPointF(decomposed->xOrigin, decomposed->yOrigin);
+}
+
+void QGraphicsItem::setTransformOrigin(const QPointF &origin)
+{
+ if (!d_ptr->dirtyTransform) {
+ d_ptr->fullUpdateHelper(true);
+ prepareGeometryChange();
+ }
+ QGraphicsItemPrivate::DecomposedTransform *decomposed = d_ptr->decomposedTransform();
+ decomposed->xOrigin = origin.x();
+ decomposed->yOrigin = origin.y();
+ if (!d_ptr->dirtyTransform)
+ d_ptr->invalidateSceneTransformCache();
+ d_ptr->dirtyTransform = 1;
+ d_ptr->hasTransform = 1;
+}
+
+/*!
\obsolete
Use sceneTransform() instead.
@@ -2875,7 +3203,7 @@ QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) co
Use setTransform() instead.
- \sa transform(), rotate(), scale(), shear(), translate(), {The Graphics View Coordinate System}
+ \sa transform(), {The Graphics View Coordinate System}
*/
void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine)
{
@@ -2900,6 +3228,8 @@ void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine)
prepareGeometryChange();
d_ptr->hasTransform = !newTransform.isIdentity();
d_ptr->setExtra(QGraphicsItemPrivate::ExtraTransform, newTransform);
+ d_ptr->dirtyTransformComponents = 1;
+ d_ptr->dirtyTransform = 0;
d_ptr->invalidateSceneTransformCache();
// Send post-notification.
@@ -2923,7 +3253,10 @@ void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine)
to map an item coordiate to a scene coordinate, or mapFromScene() to map
from scene coordinates to item coordinates.
- \sa transform(), rotate(), scale(), shear(), translate(), {The Graphics View Coordinate System}
+ \warning using this function conflicts with using the transformation properties.
+ If you set a transformation, getting the properties will return default values.
+
+ \sa transform(), setRotation(), setScale(), setShear(), setTransformOrigin() {The Graphics View Coordinate System}
*/
void QGraphicsItem::setTransform(const QTransform &matrix, bool combine)
{
@@ -2948,6 +3281,8 @@ void QGraphicsItem::setTransform(const QTransform &matrix, bool combine)
prepareGeometryChange();
d_ptr->hasTransform = !newTransform.isIdentity();
d_ptr->setExtra(QGraphicsItemPrivate::ExtraTransform, newTransform);
+ d_ptr->dirtyTransformComponents = 1;
+ d_ptr->dirtyTransform = 0;
d_ptr->invalidateSceneTransformCache();
// Send post-notification.
@@ -2967,8 +3302,9 @@ void QGraphicsItem::resetMatrix()
/*!
\since 4.3
- Resets this item's transformation matrix to the identity matrix. This is
- equivalent to calling \c setTransform(QTransform()).
+ Resets this item's transformation matrix to the identity matrix or
+ all the transformation properties to their default values.
+ This is equivalent to calling \c setTransform(QTransform()).
\sa setTransform(), transform()
*/
@@ -2978,6 +3314,9 @@ void QGraphicsItem::resetTransform()
}
/*!
+ \obsolete
+ Use setZRotation() instead
+
Rotates the current item transformation \a angle degrees clockwise around
its origin. To translate around an arbitrary point (x, y), you need to
combine translation and rotation with setTransform().
@@ -2986,6 +3325,9 @@ void QGraphicsItem::resetTransform()
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 6
+ \warning using this function conflicts with using the transformation properties.
+ Getting those properties after using this function will return default values.
+
\sa setTransform(), transform(), scale(), shear(), translate()
*/
void QGraphicsItem::rotate(qreal angle)
@@ -2994,6 +3336,9 @@ void QGraphicsItem::rotate(qreal angle)
}
/*!
+ \obsolete
+ Use setScale() instead
+
Scales the current item transformation by (\a sx, \a sy) around its
origin. To scale from an arbitrary point (x, y), you need to combine
translation and scaling with setTransform().
@@ -3002,7 +3347,10 @@ void QGraphicsItem::rotate(qreal angle)
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 7
- \sa setTransform(), transform(), rotate(), shear(), translate()
+ \warning using this function conflicts with using the transformation properties.
+ Getting those properties after using this function will return default values.
+
+ \sa setTransform(), transform()
*/
void QGraphicsItem::scale(qreal sx, qreal sy)
{
@@ -3010,9 +3358,15 @@ void QGraphicsItem::scale(qreal sx, qreal sy)
}
/*!
+ \obsolete
+ Use setShear instead.
+
Shears the current item transformation by (\a sh, \a sv).
- \sa setTransform(), transform(), rotate(), scale(), translate()
+ \warning using this function conflicts with using the transformation properties.
+ Getting those properties after using this function will return default values.
+
+ \sa setTransform(), transform()
*/
void QGraphicsItem::shear(qreal sh, qreal sv)
{
@@ -3020,13 +3374,19 @@ void QGraphicsItem::shear(qreal sh, qreal sv)
}
/*!
+ \obsolete
+ Use setPos() or setTransformOrigin() instead.
+
Translates the current item transformation by (\a dx, \a dy).
If all you want is to move an item, you should call moveBy() or
setPos() instead; this function changes the item's translation,
which is conceptually separate from its position.
- \sa setTransform(), transform(), rotate(), scale(), shear()
+ \warning using this function conflicts with using the transformation properties.
+ Getting those properties after using this function will return default values.
+
+ \sa setTransform(), transform()
*/
void QGraphicsItem::translate(qreal dx, qreal dy)
{
@@ -3150,7 +3510,7 @@ QRectF QGraphicsItem::childrenBoundingRect() const
Although the item's shape can be arbitrary, the bounding rect is
always rectangular, and it is unaffected by the items'
- transformation (scale(), rotate(), etc.).
+ transformation.
If you want to change the item's bounding rectangle, you must first call
prepareGeometryChange(). This notifies the scene of the imminent change,
@@ -8285,19 +8645,19 @@ bool QGraphicsTextItem::sceneEvent(QEvent *event)
void QGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if ((QGraphicsItem::d_ptr->flags & (ItemIsSelectable | ItemIsMovable))
- && (event->buttons() & Qt::LeftButton) && dd->_q_mouseOnEdge(event)) {
- // User left-pressed on edge of selectable/movable item, use
- // base impl.
- dd->useDefaultImpl = true;
+ && (event->buttons() & Qt::LeftButton) && dd->_q_mouseOnEdge(event)) {
+ // User left-pressed on edge of selectable/movable item, use
+ // base impl.
+ dd->useDefaultImpl = true;
} else if (event->buttons() == event->button()
- && dd->control->textInteractionFlags() == Qt::NoTextInteraction) {
- // User pressed first button on non-interactive item.
- dd->useDefaultImpl = true;
+ && dd->control->textInteractionFlags() == Qt::NoTextInteraction) {
+ // User pressed first button on non-interactive item.
+ dd->useDefaultImpl = true;
}
if (dd->useDefaultImpl) {
QGraphicsItem::mousePressEvent(event);
- if (!event->isAccepted())
- dd->useDefaultImpl = false;
+ if (!event->isAccepted())
+ dd->useDefaultImpl = false;
return;
}
dd->sendControlEvent(event);
@@ -8322,14 +8682,14 @@ void QGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (dd->useDefaultImpl) {
QGraphicsItem::mouseReleaseEvent(event);
- if (dd->control->textInteractionFlags() == Qt::NoTextInteraction
- && !event->buttons()) {
- // User released last button on non-interactive item.
+ if (dd->control->textInteractionFlags() == Qt::NoTextInteraction
+ && !event->buttons()) {
+ // User released last button on non-interactive item.
dd->useDefaultImpl = false;
- } else if ((event->buttons() & Qt::LeftButton) == 0) {
- // User released the left button on an interactive item.
+ } else if ((event->buttons() & Qt::LeftButton) == 0) {
+ // User released the left button on an interactive item.
dd->useDefaultImpl = false;
- }
+ }
return;
}
dd->sendControlEvent(event);
@@ -8619,9 +8979,9 @@ bool QGraphicsTextItemPrivate::_q_mouseOnEdge(QGraphicsSceneMouseEvent *event)
Sets the flags \a flags to specify how the text item should react to user
input.
- The default for a QGraphicsTextItem is Qt::NoTextInteraction. Setting a
- value different to Qt::NoTextInteraction will also set the ItemIsFocusable
- QGraphicsItem flag.
+ The default for a QGraphicsTextItem is Qt::NoTextInteraction. This function
+ also affects the ItemIsFocusable QGraphicsItem flag by setting it if \a flags
+ is different from Qt::NoTextInteraction and clearing it otherwise.
By default, the text is read-only. To transform the item into an editor,
set the Qt::TextEditable flag.
@@ -9370,17 +9730,17 @@ QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag flag)
QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlags flags)
{
- debug << "(";
+ debug << '(';
bool f = false;
for (int i = 0; i < 9; ++i) {
if (flags & (1 << i)) {
if (f)
- debug << "|";
+ debug << '|';
f = true;
debug << QGraphicsItem::GraphicsItemFlag(int(flags & (1 << i)));
}
}
- debug << ")";
+ debug << ')';
return debug;
}
diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h
index e5779f7..11e05d0 100644
--- a/src/gui/graphicsview/qgraphicsitem.h
+++ b/src/gui/graphicsview/qgraphicsitem.h
@@ -243,11 +243,41 @@ public:
QTransform itemTransform(const QGraphicsItem *other, bool *ok = 0) const;
void setTransform(const QTransform &matrix, bool combine = false);
void resetTransform();
-
- void rotate(qreal angle);
- void scale(qreal sx, qreal sy);
- void shear(qreal sh, qreal sv);
- void translate(qreal dx, qreal dy);
+
+ void rotate(qreal angle); // ### obsolete
+ void scale(qreal sx, qreal sy); // ### obsolete
+ void shear(qreal sh, qreal sv); // ### obsolete
+ void translate(qreal dx, qreal dy); // ### obsolete
+
+ qreal xRotation() const;
+ void setXRotation(qreal angle);
+
+ qreal yRotation() const;
+ void setYRotation(qreal angle);
+
+ qreal zRotation() const;
+ void setZRotation(qreal angle);
+ void setRotation(qreal x, qreal y, qreal z);
+
+ qreal xScale() const;
+ void setXScale(qreal factor);
+
+ qreal yScale() const;
+ void setYScale(qreal factor);
+ void setScale(qreal sx, qreal sy);
+
+ qreal horizontalShear() const;
+ void setHorizontalShear(qreal shear);
+
+ qreal verticalShear() const;
+ void setVerticalShear(qreal shear);
+ void setShear(qreal sh, qreal sv);
+
+ QPointF transformOrigin() const;
+ void setTransformOrigin(const QPointF &origin);
+ inline void setTransformOrigin(qreal x, qreal y)
+ { setTransformOrigin(QPointF(x,y)); }
+
virtual void advance(int phase);
// Stacking order
@@ -1022,4 +1052,3 @@ QT_END_NAMESPACE
QT_END_HEADER
#endif // QGRAPHICSITEM_H
-
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index 7642b98..4a12bcb 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -57,6 +57,8 @@
#include "qset.h"
#include "qpixmapcache.h"
+#include <QtCore/qpoint.h>
+
#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
QT_BEGIN_NAMESPACE
@@ -100,6 +102,15 @@ class Q_AUTOTEST_EXPORT QGraphicsItemPrivate
{
Q_DECLARE_PUBLIC(QGraphicsItem)
public:
+ struct TransformData
+ {
+ TransformData() : rotationX(0),rotationY(0),rotationZ(0),scaleX(1),scaleY(1), dirty(true) {}
+ QTransform baseTransform;
+ QTransform transform;
+ QPointF transformCenter;
+ qreal rotationX,rotationY,rotationZ,scaleX,scaleY;
+ bool dirty;
+ };
enum Extra {
ExtraTransform,
ExtraToolTip,
@@ -109,6 +120,7 @@ public:
ExtraBoundingRegionGranularity,
ExtraOpacity,
ExtraEffectiveOpacity,
+ ExtraDecomposedTransform
ExtraGestures
};
@@ -153,6 +165,9 @@ public:
inSetPosHelper(0),
flags(0),
allChildrenCombineOpacity(1),
+ hasDecomposedTransform(0),
+ dirtyTransform(0),
+ dirtyTransformComponents(0),
acceptTouchEvents(0),
acceptedTouchBeginEvent(0),
globalStackingOrder(-1),
@@ -243,7 +258,7 @@ public:
}
}
}
-
+
struct ExtraStruct {
ExtraStruct(Extra type, QVariant value)
: type(type), value(value)
@@ -255,6 +270,7 @@ public:
bool operator<(Extra extra) const
{ return type < extra; }
};
+
QList<ExtraStruct> extras;
QGraphicsItemCache *maybeExtraItemCache() const;
@@ -365,17 +381,86 @@ public:
// New 32 bits
quint32 flags : 10;
quint32 allChildrenCombineOpacity : 1;
+ quint32 hasDecomposedTransform : 1;
+ quint32 dirtyTransform : 1;
+ quint32 dirtyTransformComponents : 1;
quint32 acceptTouchEvents : 1;
quint32 acceptedTouchBeginEvent : 1;
- quint32 padding : 19; // feel free to use
+ quint32 padding : 16; // feel free to use
// Optional stacking order
int globalStackingOrder;
int sceneTransformIndex;
+ struct DecomposedTransform;
+ DecomposedTransform *decomposedTransform() const
+ {
+ QGraphicsItemPrivate *that = const_cast<QGraphicsItemPrivate *>(this);
+ DecomposedTransform *decomposed;
+ if (hasDecomposedTransform) {
+ decomposed = qVariantValue<DecomposedTransform *>(extra(ExtraDecomposedTransform));
+ } else {
+ decomposed = new DecomposedTransform;
+ that->setExtra(ExtraDecomposedTransform, qVariantFromValue<DecomposedTransform *>(decomposed));
+ that->hasDecomposedTransform = 1;
+ if (!dirtyTransformComponents)
+ decomposed->reset();
+ }
+ if (dirtyTransformComponents) {
+ decomposed->initFrom(q_ptr->transform());
+ that->dirtyTransformComponents = 0;
+ }
+ return decomposed;
+ }
+
+ struct DecomposedTransform {
+ qreal xScale;
+ qreal yScale;
+ qreal xRotation;
+ qreal yRotation;
+ qreal zRotation;
+ qreal horizontalShear;
+ qreal verticalShear;
+ qreal xOrigin;
+ qreal yOrigin;
+
+ inline void reset()
+ {
+ xScale = 1.0;
+ yScale = 1.0;
+ xRotation = 0.0;
+ yRotation = 0.0;
+ zRotation = 0.0;
+ horizontalShear = 0.0;
+ verticalShear = 0.0;
+ xOrigin = 0.0;
+ yOrigin = 0.0;
+ }
+
+ inline void initFrom(const QTransform &x)
+ {
+ reset();
+ // ### decompose transform
+ Q_UNUSED(x);
+ }
+
+ inline void generateTransform(QTransform *x) const
+ {
+ x->translate(xOrigin, yOrigin);
+ x->rotate(xRotation, Qt::XAxis);
+ x->rotate(yRotation, Qt::YAxis);
+ x->rotate(zRotation, Qt::ZAxis);
+ x->shear(horizontalShear, verticalShear);
+ x->scale(xScale, yScale);
+ x->translate(-xOrigin, -yOrigin);
+ }
+ };
+
QGraphicsItem *q_ptr;
};
+Q_DECLARE_METATYPE(QGraphicsItemPrivate::DecomposedTransform *)
+
QT_END_NAMESPACE
#endif // QT_NO_GRAPHICSVIEW
diff --git a/src/gui/graphicsview/qgraphicsproxywidget.cpp b/src/gui/graphicsview/qgraphicsproxywidget.cpp
index 5641068..8f11d6f 100644
--- a/src/gui/graphicsview/qgraphicsproxywidget.cpp
+++ b/src/gui/graphicsview/qgraphicsproxywidget.cpp
@@ -990,6 +990,7 @@ void QGraphicsProxyWidget::contextMenuEvent(QGraphicsSceneContextMenuEvent *even
}
#endif // QT_NO_CONTEXTMENU
+#ifndef QT_NO_DRAGANDDROP
/*!
\reimp
*/
@@ -1110,6 +1111,7 @@ void QGraphicsProxyWidget::dropEvent(QGraphicsSceneDragDropEvent *event)
}
#endif
}
+#endif
/*!
\reimp
diff --git a/src/gui/graphicsview/qgraphicsproxywidget.h b/src/gui/graphicsview/qgraphicsproxywidget.h
index b2c3c8f..ab8c9da 100644
--- a/src/gui/graphicsview/qgraphicsproxywidget.h
+++ b/src/gui/graphicsview/qgraphicsproxywidget.h
@@ -90,10 +90,12 @@ protected:
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
#endif
+#ifndef QT_NO_DRAGANDDROP
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent *event);
+#endif
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index 7638907..952e0c1 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -4875,10 +4875,7 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
}
// Find pixmap in cache.
- if (!itemCache->allExposed)
- pixmapFound = QPixmapCache::find(pixmapKey, &pix);
- else
- pixmapFound = false;
+ pixmapFound = QPixmapCache::find(pixmapKey, &pix);
// Render using item coordinate cache mode.
if (cacheMode == QGraphicsItem::ItemCoordinateCache) {
diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp
index f3feb15..8c94451 100644
--- a/src/gui/graphicsview/qgraphicsview.cpp
+++ b/src/gui/graphicsview/qgraphicsview.cpp
@@ -3455,7 +3455,7 @@ void QGraphicsView::paintEvent(QPaintEvent *event)
#ifdef QGRAPHICSVIEW_DEBUG
QTime stopWatch;
stopWatch.start();
- qDebug() << "QGraphicsView::paintEvent(" << exposedRegion << ")";
+ qDebug() << "QGraphicsView::paintEvent(" << exposedRegion << ')';
#endif
// Find all exposed items
diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp
index 702e0b6..a2e55e1 100644
--- a/src/gui/graphicsview/qgraphicswidget.cpp
+++ b/src/gui/graphicsview/qgraphicswidget.cpp
@@ -2295,7 +2295,7 @@ void QGraphicsWidget::dumpFocusChain()
qWarning("Found a focus chain that is not circular, (next == 0)");
break;
}
- qDebug() << i++ << QString::number(uint(next), 16) << next->className() << next->data(0) << QString::fromAscii("focusItem:%1").arg(next->hasFocus() ? "1" : "0") << QLatin1String("next:") << next->d_func()->focusNext->data(0) << QLatin1String("prev:") << next->d_func()->focusPrev->data(0);
+ qDebug() << i++ << QString::number(uint(next), 16) << next->className() << next->data(0) << QString::fromAscii("focusItem:%1").arg(next->hasFocus() ? '1' : '0') << QLatin1String("next:") << next->d_func()->focusNext->data(0) << QLatin1String("prev:") << next->d_func()->focusPrev->data(0);
if (visited.contains(next)) {
qWarning("Already visited this node. However, I expected to dump until I found myself.");
break;
diff --git a/src/gui/graphicsview/qgraphicswidget.h b/src/gui/graphicsview/qgraphicswidget.h
index 34f1c5f..a5c9068 100644
--- a/src/gui/graphicsview/qgraphicswidget.h
+++ b/src/gui/graphicsview/qgraphicswidget.h
@@ -81,7 +81,14 @@ class Q_GUI_EXPORT QGraphicsWidget : public QObject, public QGraphicsItem, publi
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
-
+ Q_PROPERTY(QPointF transformOrigin READ transformOrigin WRITE setTransformOrigin)
+ Q_PROPERTY(qreal xRotation READ xRotation WRITE setXRotation)
+ Q_PROPERTY(qreal yRotation READ yRotation WRITE setYRotation)
+ Q_PROPERTY(qreal zRotation READ zRotation WRITE setZRotation)
+ Q_PROPERTY(qreal xScale READ xScale WRITE setXScale)
+ Q_PROPERTY(qreal yScale READ yScale WRITE setYScale)
+ Q_PROPERTY(qreal horizontalShear READ horizontalShear WRITE setHorizontalShear)
+ Q_PROPERTY(qreal verticalShear READ verticalShear WRITE setVerticalShear)
public:
QGraphicsWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
~QGraphicsWidget();
diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp
index c150b0e..88712c2 100644
--- a/src/gui/graphicsview/qgridlayoutengine.cpp
+++ b/src/gui/graphicsview/qgridlayoutengine.cpp
@@ -1131,9 +1131,9 @@ void QGridLayoutEngine::dump(int indent) const
QString message = QLatin1String("[ ");
for (int column = 0; column < internalGridColumnCount(); ++column) {
message += QString::number(q_items.indexOf(itemAt(row, column))).rightJustified(3);
- message += QLatin1String(" ");
+ message += QLatin1Char(' ');
}
- message += QLatin1String("]");
+ message += QLatin1Char(']');
qDebug("%*s %s", indent, "", qPrintable(message));
}
@@ -1157,7 +1157,7 @@ void QGridLayoutEngine::dump(int indent) const
message += QLatin1String((message.isEmpty() ? "[" : ", "));
message += QString::number(cellPos->at(i));
}
- message += QLatin1String("]");
+ message += QLatin1Char(']');
qDebug("%*s %s %s", indent, "", (pass == 0 ? "rows:" : "columns:"), qPrintable(message));
cellPos = &q_xx;
}
diff --git a/src/gui/gui.pro b/src/gui/gui.pro
index 1aa6558..329fb01 100644
--- a/src/gui/gui.pro
+++ b/src/gui/gui.pro
@@ -19,6 +19,7 @@ win32:include(kernel/win.pri)
embedded:include(embedded/embedded.pri)
#modules
+include(animation/animation.pri)
include(kernel/kernel.pri)
include(image/image.pri)
include(painting/painting.pri)
@@ -31,6 +32,7 @@ include(itemviews/itemviews.pri)
include(inputmethod/inputmethod.pri)
include(graphicsview/graphicsview.pri)
include(util/util.pri)
+include(statemachine/statemachine.pri)
include(math3d/math3d.pri)
embedded: QT += network
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp
index 810ce65..3cfc191 100644
--- a/src/gui/image/qpixmapcache.cpp
+++ b/src/gui/image/qpixmapcache.cpp
@@ -128,6 +128,11 @@ bool QPixmapCache::Key::operator ==(const Key &key) const
}
/*!
+ \fn bool QPixmapCache::Key::operator !=(const Key &key) const
+ \internal
+*/
+
+/*!
\internal
*/
QPixmapCache::Key &QPixmapCache::Key::operator =(const Key &other)
@@ -183,7 +188,7 @@ QT_BEGIN_INCLUDE_NAMESPACE
#include "qpixmapcache.moc"
QT_END_INCLUDE_NAMESPACE
-static uint qHash(const QPixmapCache::Key &k)
+uint qHash(const QPixmapCache::Key &k)
{
return qHash(QPMCache::get(k)->key);
}
@@ -431,8 +436,10 @@ bool QPixmapCache::find(const QString &key, QPixmap& pixmap)
/*!
Looks for a cached pixmap associated with the \a key in the cache.
- If the pixmap is found, the function sets \a pm to that pixmap and
- returns true; otherwise it leaves \a pm alone and returns false.
+ If the pixmap is found, the function sets \a pixmap to that pixmap and
+ returns true; otherwise it leaves \a pixmap alone and returns false.
+
+ \since 4.6
Example:
\snippet doc/src/snippets/code/src_gui_image_qpixmapcache.cpp 1
@@ -448,10 +455,12 @@ bool QPixmapCache::find(const QString &key, QPixmap* pixmap)
/*!
Looks for a cached pixmap associated with the \a key in the cache.
- If the pixmap is found, the function sets \a pm to that pixmap and
- returns true; otherwise it leaves \a pm alone and returns false. If
+ If the pixmap is found, the function sets \a pixmap to that pixmap and
+ returns true; otherwise it leaves \a pixmap alone and returns false. If
the pixmap is not found, it means that the \a key is not valid anymore,
so it will be released for the next insertion.
+
+ \since 4.6
*/
bool QPixmapCache::find(const Key &key, QPixmap* pixmap)
{
@@ -465,7 +474,7 @@ bool QPixmapCache::find(const Key &key, QPixmap* pixmap)
}
/*!
- Inserts a copy of the pixmap \a pm associated with the \a key into
+ Inserts a copy of the pixmap \a pixmap associated with the \a key into
the cache.
All pixmaps inserted by the Qt library have a key starting with
@@ -490,9 +499,8 @@ bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)
}
/*!
- Inserts a copy of the pixmap \a pm into
- the cache and return you the key. The key is always greater than 0.
- If the key is equals 0 then the insertion failed.
+ Inserts a copy of the pixmap \a pixmap into
+ the cache and return you the key.
When a pixmap is inserted and the cache is about to exceed its
limit, it removes pixmaps until there is enough room for the
@@ -502,6 +510,8 @@ bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)
deleted when more space is needed.
\sa setCacheLimit(), replace()
+
+ \since 4.6
*/
QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)
{
@@ -510,10 +520,12 @@ QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)
/*!
Replace the pixmap associated to the \a key into
- the cache. It return true if the pixmap \a pm has been correctly
+ the cache. It return true if the pixmap \a pixmap has been correctly
inserted into the cache false otherwise.
\sa setCacheLimit(), insert()
+
+ \since 4.6
*/
bool QPixmapCache::replace(const Key &key, const QPixmap &pixmap)
{
@@ -563,6 +575,8 @@ void QPixmapCache::remove(const QString &key)
/*!
Removes the pixmap associated with \a key from the cache and release
the key for a future insertion.
+
+ \since 4.6
*/
void QPixmapCache::remove(const Key &key)
{
diff --git a/src/gui/image/qpixmapcache_p.h b/src/gui/image/qpixmapcache_p.h
index 5aa6eaf..a35e0d2 100644
--- a/src/gui/image/qpixmapcache_p.h
+++ b/src/gui/image/qpixmapcache_p.h
@@ -60,6 +60,8 @@
QT_BEGIN_NAMESPACE
+uint qHash(const QPixmapCache::Key &k);
+
class QPixmapCache::KeyData
{
public:
diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp
index 90bd2ab..f4062ad 100644
--- a/src/gui/image/qxpmhandler.cpp
+++ b/src/gui/image/qxpmhandler.cpp
@@ -1146,7 +1146,7 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
QTextStream s(device);
s << "/* XPM */" << endl
<< "static char *" << fbname(fileName) << "[]={" << endl
- << "\"" << w << " " << h << " " << ncolors << " " << cpp << "\"";
+ << '\"' << w << ' ' << h << ' ' << ncolors << ' ' << cpp << '\"';
// write palette
QMap<QRgb, int>::Iterator c = colorMap.begin();
@@ -1162,7 +1162,7 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
qGreen(color),
qBlue(color));
++c;
- s << "," << endl << line;
+ s << ',' << endl << line;
}
// write pixels, limit to 4 characters per pixel
@@ -1184,7 +1184,7 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
}
}
}
- s << "," << endl << "\"" << line << "\"";
+ s << ',' << endl << '\"' << line << '\"';
}
s << "};" << endl;
return (s.status() == QTextStream::Ok);
diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp
index 054f4cf..434bcde 100644
--- a/src/gui/itemviews/qfileiconprovider.cpp
+++ b/src/gui/itemviews/qfileiconprovider.cpp
@@ -215,8 +215,7 @@ QIcon QFileIconProvider::icon(IconType type) const
QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const
{
QIcon retIcon;
- QString fileExtension = fileInfo.suffix().toUpper();
- fileExtension.prepend( QLatin1String(".") );
+ const QString fileExtension = QLatin1Char('.') + fileInfo.suffix().toUpper();
QString key;
if (fileInfo.isFile() && !fileInfo.isExecutable() && !fileInfo.isSymLink())
diff --git a/src/gui/itemviews/qitemdelegate.cpp b/src/gui/itemviews/qitemdelegate.cpp
index 3b7eb2d..a748199 100644
--- a/src/gui/itemviews/qitemdelegate.cpp
+++ b/src/gui/itemviews/qitemdelegate.cpp
@@ -47,6 +47,7 @@
#include <qbrush.h>
#include <qlineedit.h>
#include <qtextedit.h>
+#include <qplaintextedit.h>
#include <qpainter.h>
#include <qpalette.h>
#include <qpoint.h>
@@ -1194,7 +1195,7 @@ bool QItemDelegate::eventFilter(QObject *object, QEvent *event)
case Qt::Key_Enter:
case Qt::Key_Return:
#ifndef QT_NO_TEXTEDIT
- if (qobject_cast<QTextEdit*>(editor))
+ if (qobject_cast<QTextEdit *>(editor) || qobject_cast<QPlainTextEdit *>(editor))
return false; // don't filter enter key events for QTextEdit
// We want the editor to be able to process the key press
// before committing the data (e.g. so it can do
diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp
index 8baefdf..696b8fa 100644
--- a/src/gui/itemviews/qitemselectionmodel.cpp
+++ b/src/gui/itemviews/qitemselectionmodel.cpp
@@ -1553,7 +1553,7 @@ QDebug operator<<(QDebug dbg, const QItemSelectionRange &range)
{
#ifndef Q_BROKEN_DEBUG_STREAM
dbg.nospace() << "QItemSelectionRange(" << range.topLeft()
- << "," << range.bottomRight() << ")";
+ << ',' << range.bottomRight() << ')';
return dbg.space();
#else
qWarning("This compiler doesn't support streaming QItemSelectionRange to QDebug");
diff --git a/src/gui/itemviews/qstyleditemdelegate.cpp b/src/gui/itemviews/qstyleditemdelegate.cpp
index be0971b..7f2c8ed 100644
--- a/src/gui/itemviews/qstyleditemdelegate.cpp
+++ b/src/gui/itemviews/qstyleditemdelegate.cpp
@@ -47,6 +47,7 @@
#include <qbrush.h>
#include <qlineedit.h>
#include <qtextedit.h>
+#include <qplaintextedit.h>
#include <qpainter.h>
#include <qpalette.h>
#include <qpoint.h>
@@ -646,7 +647,7 @@ bool QStyledItemDelegate::eventFilter(QObject *object, QEvent *event)
case Qt::Key_Enter:
case Qt::Key_Return:
#ifndef QT_NO_TEXTEDIT
- if (qobject_cast<QTextEdit*>(editor))
+ if (qobject_cast<QTextEdit *>(editor) || qobject_cast<QPlainTextEdit *>(editor))
return false; // don't filter enter key events for QTextEdit
// We want the editor to be able to process the key press
// before committing the data (e.g. so it can do
diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp
index 757ecf2..0bded54 100644
--- a/src/gui/itemviews/qtableview.cpp
+++ b/src/gui/itemviews/qtableview.cpp
@@ -282,7 +282,7 @@ void QTableViewPrivate::trimHiddenSelections(QItemSelectionRange *range) const
void QTableViewPrivate::setSpan(int row, int column, int rowSpan, int columnSpan)
{
if (row < 0 || column < 0 || rowSpan <= 0 || columnSpan <= 0) {
- qWarning() << "QTableView::setSpan: invalid span given: (" << row << "," << column << "," << rowSpan << "," << columnSpan << ")";
+ qWarning() << "QTableView::setSpan: invalid span given: (" << row << ',' << column << ',' << rowSpan << ',' << columnSpan << ')';
return;
}
QSpanCollection::Span *sp = spans.spanAt(column, row);
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index b142f2e..307d0ad 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -853,6 +853,9 @@ void QApplicationPrivate::initialize()
// trigger registering of QVariant's GUI types
extern int qRegisterGuiVariant();
qRegisterGuiVariant();
+ // trigger registering of QStateMachine's GUI types
+ extern int qRegisterGuiStateMachine();
+ qRegisterGuiStateMachine();
is_app_running = true; // no longer starting up
@@ -1074,6 +1077,9 @@ QApplication::~QApplication()
QApplicationPrivate::fade_tooltip = false;
QApplicationPrivate::widgetCount = false;
+ // trigger unregistering of QStateMachine's GUI types
+ extern int qUnregisterGuiStateMachine();
+ qUnregisterGuiStateMachine();
// trigger unregistering of QVariant's GUI types
extern int qUnregisterGuiVariant();
qUnregisterGuiVariant();
diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp
index f537805..f134e55 100644
--- a/src/gui/kernel/qapplication_win.cpp
+++ b/src/gui/kernel/qapplication_win.cpp
@@ -410,11 +410,6 @@ QRgb qt_colorref2qrgb(COLORREF col)
Internal variables and functions
*****************************************************************************/
-extern Q_CORE_EXPORT char theAppName[];
-extern Q_CORE_EXPORT char appFileName[];
-extern Q_CORE_EXPORT HINSTANCE appInst; // handle to app instance
-extern Q_CORE_EXPORT HINSTANCE appPrevInst; // handle to prev app instance
-extern Q_CORE_EXPORT int appCmdShow; // main window show command
static HWND curWin = 0; // current window
static HDC displayDC = 0; // display device context
@@ -786,20 +781,11 @@ void qt_init(QApplicationPrivate *priv, int)
priv->argc = j;
}
- // Get the application name/instance if qWinMain() was not invoked
#ifndef Q_WS_WINCE
// No message boxes but important ones
SetErrorMode(SetErrorMode(0) | SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
#endif
- if (appInst == 0) {
- QT_WA({
- appInst = GetModuleHandle(0);
- }, {
- appInst = GetModuleHandleA(0);
- });
- }
-
#ifndef Q_WS_WINCE
// Initialize OLE/COM
// S_OK means success and S_FALSE means that it has already
@@ -824,7 +810,7 @@ void qt_init(QApplicationPrivate *priv, int)
#ifndef QT_NO_CURSOR
QCursorData::initialize();
#endif
- qApp->setObjectName(QLatin1String(theAppName));
+ qApp->setObjectName(priv->appName());
#if !defined(Q_WS_WINCE)
// default font
@@ -924,12 +910,6 @@ void qt_cleanup()
Platform specific global and internal functions
*****************************************************************************/
-Q_GUI_EXPORT int qWinAppCmdShow() // get main window show command
-{
- return appCmdShow;
-}
-
-
Q_GUI_EXPORT HDC qt_win_display_dc() // get display DC
{
Q_ASSERT(qApp && qApp->thread() == QThread::currentThread());
@@ -1025,11 +1005,11 @@ const QString qt_reg_winclass(QWidget *w) // register window class
if (classExists == -1) {
QT_WA({
WNDCLASS wcinfo;
- classExists = GetClassInfo((HINSTANCE)qWinAppInst(), (TCHAR*)cname.utf16(), &wcinfo);
+ classExists = GetClassInfo(qWinAppInst(), (TCHAR*)cname.utf16(), &wcinfo);
classExists = classExists && wcinfo.lpfnWndProc != QtWndProc;
}, {
WNDCLASSA wcinfo;
- classExists = GetClassInfoA((HINSTANCE)qWinAppInst(), cname.toLatin1(), &wcinfo);
+ classExists = GetClassInfoA(qWinAppInst(), cname.toLatin1(), &wcinfo);
classExists = classExists && wcinfo.lpfnWndProc != QtWndProc;
});
}
@@ -1049,9 +1029,9 @@ const QString qt_reg_winclass(QWidget *w) // register window class
wc.lpfnWndProc = (WNDPROC)QtWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
- wc.hInstance = (HINSTANCE)qWinAppInst();
+ wc.hInstance = qWinAppInst();
if (icon) {
- wc.hIcon = LoadIcon(appInst, L"IDI_ICON1");
+ wc.hIcon = LoadIcon(qWinAppInst(), L"IDI_ICON1");
if (!wc.hIcon)
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
} else {
@@ -1068,9 +1048,9 @@ const QString qt_reg_winclass(QWidget *w) // register window class
wc.lpfnWndProc = (WNDPROC)QtWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
- wc.hInstance = (HINSTANCE)qWinAppInst();
+ wc.hInstance = qWinAppInst();
if (icon) {
- wc.hIcon = LoadIconA(appInst, (char*)"IDI_ICON1");
+ wc.hIcon = LoadIconA(qWinAppInst(), (char*)"IDI_ICON1");
if (!wc.hIcon)
wc.hIcon = LoadIconA(0, (char*)IDI_APPLICATION);
} else {
@@ -1089,9 +1069,9 @@ const QString qt_reg_winclass(QWidget *w) // register window class
wc.lpfnWndProc = (WNDPROC)QtWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
- wc.hInstance = (HINSTANCE)qWinAppInst();
+ wc.hInstance = qWinAppInst();
if (icon) {
- wc.hIcon = LoadIcon(appInst, L"IDI_ICON1");
+ wc.hIcon = LoadIcon(qWinAppInst(), L"IDI_ICON1");
// if (!wc.hIcon)
// wc.hIcon = LoadIcon(0, IDI_APPLICATION);
} else {
@@ -1125,9 +1105,9 @@ static void unregWinClasses()
QHash<QString, int>::ConstIterator it = hash->constBegin();
while (it != hash->constEnd()) {
QT_WA({
- UnregisterClass((TCHAR*)it.key().utf16(), (HINSTANCE)qWinAppInst());
+ UnregisterClass((TCHAR*)it.key().utf16(), qWinAppInst());
} , {
- UnregisterClassA(it.key().toLatin1(), (HINSTANCE)qWinAppInst());
+ UnregisterClassA(it.key().toLatin1(), qWinAppInst());
});
++it;
}
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index d616e5e..53010e1 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -3083,7 +3083,7 @@ QDebug operator<<(QDebug dbg, const QEvent *e) {
<< ", " << me->button()
<< ", " << hex << (int)me->buttons()
<< ", " << hex << (int)me->modifiers()
- << ")";
+ << ')';
}
return dbg.space();
@@ -3104,7 +3104,7 @@ QDebug operator<<(QDebug dbg, const QEvent *e) {
#ifndef QT_NO_WHEELEVENT
case QEvent::Wheel:
dbg.nospace() << "QWheelEvent(" << static_cast<const QWheelEvent *>(e)->delta()
- << ")";
+ << ')';
return dbg.space();
#endif
case QEvent::KeyPress:
@@ -3130,7 +3130,7 @@ QDebug operator<<(QDebug dbg, const QEvent *e) {
<< ", \"" << ke->text()
<< "\", " << ke->isAutoRepeat()
<< ", " << ke->count()
- << ")";
+ << ')';
}
return dbg.space();
case QEvent::FocusIn:
diff --git a/src/gui/kernel/qlayoutengine.cpp b/src/gui/kernel/qlayoutengine.cpp
index fbaa388..3673f08 100644
--- a/src/gui/kernel/qlayoutengine.cpp
+++ b/src/gui/kernel/qlayoutengine.cpp
@@ -329,7 +329,7 @@ void qGeomCalc(QVector<QLayoutStruct> &chain, int start, int count,
qDebug() << "qGeomCalc" << "start" << start << "count" << count << "pos" << pos
<< "space" << space << "spacer" << spacer;
for (i = start; i < start + count; ++i) {
- qDebug() << i << ":" << chain[i].minimumSize << chain[i].smartSizeHint()
+ qDebug() << i << ':' << chain[i].minimumSize << chain[i].smartSizeHint()
<< chain[i].maximumSize << "stretch" << chain[i].stretch
<< "empty" << chain[i].empty << "expansive" << chain[i].expansive
<< "spacing" << chain[i].spacing;
diff --git a/src/gui/kernel/qmime_win.cpp b/src/gui/kernel/qmime_win.cpp
index cd0aae6..109ce20 100644
--- a/src/gui/kernel/qmime_win.cpp
+++ b/src/gui/kernel/qmime_win.cpp
@@ -852,7 +852,7 @@ QVariant QWindowsMimeHtml::convertToMime(const QString &mime, IDataObject *pData
if (end > start && start > 0) {
html = "<!--StartFragment-->" + html.mid(start, end - start);
html += "<!--EndFragment-->";
- html.replace("\r", "");
+ html.replace('\r', "");
result = QString::fromUtf8(html);
}
}
diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp
index f998bb2..3c2fcdd 100644
--- a/src/gui/kernel/qshortcutmap.cpp
+++ b/src/gui/kernel/qshortcutmap.cpp
@@ -109,7 +109,7 @@ QDebug &operator<<(QDebug &dbg, const QShortcutEntry *se) {
dbg.nospace()
<< "QShortcutEntry(" << se->keyseq
<< "), id(" << se->id << "), enabled(" << se->enabled << "), autorepeat(" << se->autorepeat
- << "), owner(" << se->owner << ")";
+ << "), owner(" << se->owner << ')';
return dbg.space();
}
#endif // QT_NO_DEBUGSTREAM
@@ -876,7 +876,7 @@ void QShortcutMap::dispatchEvent(QKeyEvent *e)
qDebug().nospace()
<< "QShortcutMap::dispatchEvent(): Sending QShortcutEvent(\""
<< (QString)next->keyseq << "\", " << next->id << ", "
- << (bool)(enabledShortcuts>1) << ") to object(" << next->owner << ")";
+ << (bool)(enabledShortcuts>1) << ") to object(" << next->owner << ')';
#endif
QShortcutEvent se(next->keyseq, next->id, enabledShortcuts>1);
QApplication::sendEvent(const_cast<QObject *>(next->owner), &se);
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp
index 4b2fed7..7b1b38c 100644
--- a/src/gui/kernel/qwidget.cpp
+++ b/src/gui/kernel/qwidget.cpp
@@ -5239,7 +5239,7 @@ static QString constructWindowTitleFromFilePath(const QString &filePath)
#ifndef Q_WS_MAC
QString appName = QApplication::applicationName();
if (!appName.isEmpty())
- windowTitle += QLatin1String(" ") + QChar(0x2014) + QLatin1String(" ") + appName;
+ windowTitle += QLatin1Char(' ') + QChar(0x2014) + QLatin1Char(' ') + appName;
#endif
return windowTitle;
}
@@ -5303,7 +5303,7 @@ QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widg
&& widget->style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, widget))
cap.replace(lastIndex, 3, QWidget::tr("*"));
else
- cap.replace(lastIndex, 3, QLatin1String(""));
+ cap.remove(lastIndex, 3);
}
index = cap.indexOf(placeHolder, index);
diff --git a/src/gui/kernel/qwindowdefs_win.h b/src/gui/kernel/qwindowdefs_win.h
index 3899c23..a24afd4 100644
--- a/src/gui/kernel/qwindowdefs_win.h
+++ b/src/gui/kernel/qwindowdefs_win.h
@@ -122,7 +122,7 @@ QT_BEGIN_NAMESPACE
Q_CORE_EXPORT HINSTANCE qWinAppInst();
Q_CORE_EXPORT HINSTANCE qWinAppPrevInst();
-Q_GUI_EXPORT int qWinAppCmdShow();
+Q_CORE_EXPORT int qWinAppCmdShow();
Q_GUI_EXPORT HDC qt_win_display_dc();
QT_END_NAMESPACE
diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp
index 534a425..6b58f14 100644
--- a/src/gui/painting/qcolor.cpp
+++ b/src/gui/painting/qcolor.cpp
@@ -2022,12 +2022,12 @@ QDebug operator<<(QDebug dbg, const QColor &c)
if (!c.isValid())
dbg.nospace() << "QColor(Invalid)";
else if (c.spec() == QColor::Rgb)
- dbg.nospace() << "QColor(ARGB " << c.alphaF() << ", " << c.redF() << ", " << c.greenF() << ", " << c.blueF() << ")";
+ dbg.nospace() << "QColor(ARGB " << c.alphaF() << ", " << c.redF() << ", " << c.greenF() << ", " << c.blueF() << ')';
else if (c.spec() == QColor::Hsv)
- dbg.nospace() << "QColor(AHSV " << c.alphaF() << ", " << c.hueF() << ", " << c.saturationF() << ", " << c.valueF() << ")";
+ dbg.nospace() << "QColor(AHSV " << c.alphaF() << ", " << c.hueF() << ", " << c.saturationF() << ", " << c.valueF() << ')';
else if (c.spec() == QColor::Cmyk)
dbg.nospace() << "QColor(ACMYK " << c.alphaF() << ", " << c.cyanF() << ", " << c.magentaF() << ", " << c.yellowF() << ", "
- << c.blackF()<< ")";
+ << c.blackF()<< ')';
return dbg.space();
#else
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp
index fdd0c21..bbe1a76 100644
--- a/src/gui/painting/qdrawhelper.cpp
+++ b/src/gui/painting/qdrawhelper.cpp
@@ -6930,7 +6930,7 @@ static void qt_alphamapblit_quint16(QRasterBuffer *rasterBuffer,
}
void qt_build_pow_tables() {
- qreal smoothing = 1.7;
+ qreal smoothing = qreal(1.7);
#ifdef Q_WS_MAC
// decided by testing a few things on an iMac, should probably get this from the
@@ -6952,15 +6952,15 @@ void qt_build_pow_tables() {
}
#else
for (int i=0; i<256; ++i) {
- qt_pow_rgb_gamma[i] = uchar(qRound(pow(i / 255.0, smoothing) * 255));
- qt_pow_rgb_invgamma[i] = uchar(qRound(pow(i / 255.0, 1 / smoothing) * 255));
+ qt_pow_rgb_gamma[i] = uchar(qRound(pow(i / qreal(255.0), smoothing) * 255));
+ qt_pow_rgb_invgamma[i] = uchar(qRound(pow(i / qreal(255.), 1 / smoothing) * 255));
}
#endif
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
const qreal gray_gamma = 2.31;
for (int i=0; i<256; ++i)
- qt_pow_gamma[i] = uint(qRound(pow(i / 255.0, gray_gamma) * 2047));
+ qt_pow_gamma[i] = uint(qRound(pow(i / qreal(255.), gray_gamma) * 2047));
for (int i=0; i<2048; ++i)
qt_pow_invgamma[i] = uchar(qRound(pow(i / 2047.0, 1 / gray_gamma) * 255));
#endif
diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h
index de97683..019402a 100644
--- a/src/gui/painting/qdrawhelper_p.h
+++ b/src/gui/painting/qdrawhelper_p.h
@@ -110,6 +110,7 @@ struct QSpanData;
class QGradient;
class QRasterBuffer;
class QClipData;
+class QRasterPaintEngineState;
typedef QT_FT_SpanFunc ProcessSpans;
typedef void (*BitmapBlitFunc)(QRasterBuffer *rasterBuffer,
@@ -293,7 +294,7 @@ struct QSpanData
};
void init(QRasterBuffer *rb, const QRasterPaintEngine *pe);
- void setup(const QBrush &brush, int alpha);
+ void setup(const QBrush &brush, int alpha, QPainter::CompositionMode compositionMode);
void setupMatrix(const QTransform &matrix, int bilinear);
void initTexture(const QImage *image, int alpha, QTextureData::Type = QTextureData::Plain, const QRect &sourceRect = QRect());
void adjustSpanMethods();
diff --git a/src/gui/painting/qmatrix.cpp b/src/gui/painting/qmatrix.cpp
index 31abcad..030415d 100644
--- a/src/gui/painting/qmatrix.cpp
+++ b/src/gui/painting/qmatrix.cpp
@@ -1178,7 +1178,7 @@ QDebug operator<<(QDebug dbg, const QMatrix &m)
<< " 22=" << m.m22()
<< " dx=" << m.dx()
<< " dy=" << m.dy()
- << ")";
+ << ')';
return dbg.space();
}
#endif
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index c986e99..93e0db0 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -139,7 +139,6 @@ extern bool qt_cleartype_enabled;
* Span functions
*/
static void qt_span_fill_clipRect(int count, const QSpan *spans, void *userData);
-static void qt_span_fill_clipRegion(int count, const QSpan *spans, void *userData);
static void qt_span_fill_clipped(int count, const QSpan *spans, void *userData);
static void qt_span_clip(int count, const QSpan *spans, void *userData);
static void qt_merge_clip(const QClipData *c1, const QClipData *c2, QClipData *result);
@@ -363,7 +362,8 @@ void QRasterPaintEngine::init()
d->basicStroker.setCubicToHook(qt_ft_outline_cubic_to);
d->dashStroker = 0;
- d->baseClip = 0;
+ d->baseClip = new QClipData(d->device->height());
+ d->baseClip->setClipRect(QRect(0, 0, d->device->width(), d->device->height()));
d->image_filler.init(d->rasterBuffer, this);
d->image_filler.type = QSpanData::Texture;
@@ -447,6 +447,8 @@ QRasterPaintEngine::~QRasterPaintEngine()
delete d->outlineMapper;
delete d->rasterizer;
delete d->dashStroker;
+
+ delete d->baseClip;
}
/*!
@@ -483,12 +485,12 @@ bool QRasterPaintEngine::begin(QPaintDevice *device)
d->rasterizer->setClipRect(d->deviceRect);
s->penData.init(d->rasterBuffer, this);
- s->penData.setup(s->pen.brush(), s->intOpacity);
+ s->penData.setup(s->pen.brush(), s->intOpacity, s->composition_mode);
s->stroker = &d->basicStroker;
d->basicStroker.setClipRect(d->deviceRect);
s->brushData.init(d->rasterBuffer, this);
- s->brushData.setup(s->brush, s->intOpacity);
+ s->brushData.setup(s->brush, s->intOpacity, s->composition_mode);
d->rasterBuffer->compositionMode = QPainter::CompositionMode_SourceOver;
@@ -534,19 +536,14 @@ bool QRasterPaintEngine::begin(QPaintDevice *device)
*/
bool QRasterPaintEngine::end()
{
- Q_D(QRasterPaintEngine);
#ifdef QT_DEBUG_DRAW
+ Q_D(QRasterPaintEngine);
qDebug() << "QRasterPaintEngine::end devRect:" << d->deviceRect;
if (d->baseClip) {
dumpClip(d->rasterBuffer->width(), d->rasterBuffer->height(), d->baseClip);
}
#endif
- if (d->baseClip) {
- delete d->baseClip;
- d->baseClip = 0;
- }
-
return true;
}
@@ -773,7 +770,7 @@ void QRasterPaintEngine::updatePen(const QPen &pen)
s->strokeFlags = 0;
s->penData.clip = d->clip();
- s->penData.setup(pen_style == Qt::NoPen ? QBrush() : pen.brush(), s->intOpacity);
+ s->penData.setup(pen_style == Qt::NoPen ? QBrush() : pen.brush(), s->intOpacity, s->composition_mode);
if (s->strokeFlags & QRasterPaintEngine::DirtyTransform
|| pen.brush().transform().type() >= QTransform::TxNone) {
@@ -873,7 +870,7 @@ void QRasterPaintEngine::updateBrush(const QBrush &brush)
QRasterPaintEngineState *s = state();
// must set clip prior to setup, as setup uses it...
s->brushData.clip = d->clip();
- s->brushData.setup(brush, s->intOpacity);
+ s->brushData.setup(brush, s->intOpacity, s->composition_mode);
if (s->fillFlags & DirtyTransform
|| brush.transform().type() >= QTransform::TxNone)
d_func()->updateMatrixData(&s->brushData, brush, d->brushMatrix());
@@ -1028,6 +1025,10 @@ void QRasterPaintEnginePrivate::drawImage(const QPointF &pt,
{
if (alpha == 0 || !clip.isValid())
return;
+
+ if (alpha ==0)
+ return;
+
Q_ASSERT(img.depth() >= 8);
int srcBPL = img.bytesPerLine();
@@ -1096,11 +1097,10 @@ void QRasterPaintEnginePrivate::systemStateChanged()
if (!systemClip.isEmpty()) {
QRegion clippedDeviceRgn = systemClip & clipRect;
deviceRect = clippedDeviceRgn.boundingRect();
- delete baseClip;
- baseClip = new QClipData(device->height());
baseClip->setClipRegion(clippedDeviceRgn);
} else {
deviceRect = clipRect;
+ baseClip->setClipRect(deviceRect);
}
#ifdef QT_DEBUG_DRAW
qDebug() << "systemStateChanged" << this << "deviceRect" << deviceRect << clipRect << systemClip;
@@ -1172,6 +1172,25 @@ static void checkClipRatios(QRasterPaintEnginePrivate *d)
}
#endif
+static void qrasterpaintengine_state_setNoClip(QRasterPaintEngineState *s)
+{
+ if (s->flags.has_clip_ownership)
+ delete s->clip;
+ s->clip = 0;
+ s->flags.has_clip_ownership = false;
+}
+
+static void qrasterpaintengine_dirty_clip(QRasterPaintEnginePrivate *d, QRasterPaintEngineState *s)
+{
+ s->fillFlags |= QPaintEngine::DirtyClipPath;
+ s->strokeFlags |= QPaintEngine::DirtyClipPath;
+ s->pixmapFlags |= QPaintEngine::DirtyClipPath;
+
+ d->solid_color_filler.clip = d->clip();
+ d->solid_color_filler.adjustSpanMethods();
+}
+
+
/*!
\internal
*/
@@ -1183,12 +1202,12 @@ void QRasterPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op)
if (path.elements()) {
for (int i=0; i<path.elementCount(); ++i) {
qDebug() << " - " << path.elements()[i]
- << "(" << path.points()[i*2] << ", " << path.points()[i*2+1] << ")";
+ << '(' << path.points()[i*2] << ", " << path.points()[i*2+1] << ')';
}
} else {
for (int i=0; i<path.elementCount(); ++i) {
qDebug() << " ---- "
- << "(" << path.points()[i*2] << ", " << path.points()[i*2+1] << ")";
+ << '(' << path.points()[i*2] << ", " << path.points()[i*2+1] << ')';
}
}
#endif
@@ -1220,10 +1239,7 @@ void QRasterPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op)
}
if (op == Qt::NoClip) {
- if (s->flags.has_clip_ownership)
- delete s->clip;
- s->clip = 0;
- s->flags.has_clip_ownership = false;
+ qrasterpaintengine_state_setNoClip(s);
} else {
QClipData *base = d->baseClip;
@@ -1265,17 +1281,7 @@ void QRasterPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op)
s->clip = newClip;
s->flags.has_clip_ownership = true;
}
-
- s->fillFlags |= DirtyClipPath;
- s->strokeFlags |= DirtyClipPath;
- s->pixmapFlags |= DirtyClipPath;
-
- d->solid_color_filler.clip = d->clip();
- d->solid_color_filler.adjustSpanMethods();
-
-#ifdef QT_CLIPPING_RATIOS
- checkClipRatios(d);
-#endif
+ qrasterpaintengine_dirty_clip(d, s);
}
@@ -1293,10 +1299,7 @@ void QRasterPaintEngine::clip(const QRect &rect, Qt::ClipOperation op)
QRasterPaintEngineState *s = state();
if (op == Qt::NoClip) {
- if (s->flags.has_clip_ownership)
- delete s->clip;
- s->clip = d->baseClip;
- s->flags.has_clip_ownership = false;
+ qrasterpaintengine_state_setNoClip(s);
} else if (op == Qt::UniteClip || s->matrix.type() > QTransform::TxScale) {
QPaintEngineEx::clip(rect, op);
@@ -1340,37 +1343,63 @@ void QRasterPaintEngine::clip(const QRect &rect, Qt::ClipOperation op)
return;
}
}
-
- s->brushData.clip = d->clip();
- s->penData.clip = d->clip();
-
- s->fillFlags |= DirtyClipPath;
- s->strokeFlags |= DirtyClipPath;
- s->pixmapFlags |= DirtyClipPath;
-
- d->solid_color_filler.clip = d->clip();
- d->solid_color_filler.adjustSpanMethods();
-
-
-#ifdef QT_CLIPPING_RATIOS
- checkClipRatios(d);
-#endif
+ qrasterpaintengine_dirty_clip(d, s);
}
+
/*!
\internal
*/
void QRasterPaintEngine::clip(const QRegion &region, Qt::ClipOperation op)
{
- QPaintEngineEx::clip(region, op);
-}
+#ifdef QT_DEBUG_DRAW
+ qDebug() << "QRasterPaintEngine::clip(): " << region << op;
+#endif
-/*!
- \internal
-*/
-void QRasterPaintEngine::clip(const QPainterPath &path, Qt::ClipOperation op)
-{
- QPaintEngineEx::clip(path, op);
+ Q_D(QRasterPaintEngine);
+
+ if (region.numRects() == 1) {
+ clip(region.boundingRect(), op);
+ return;
+ }
+
+ QRasterPaintEngineState *s = state();
+ const QClipData *clip = d->clip();
+ const QClipData *baseClip = d->baseClip;
+
+ if (op == Qt::NoClip) {
+ qrasterpaintengine_state_setNoClip(s);
+ } else if (s->matrix.type() > QTransform::TxScale
+ || op == Qt::UniteClip
+ || (op == Qt::IntersectClip && !clip->hasRectClip && !clip->hasRegionClip)
+ || (op == Qt::ReplaceClip && !baseClip->hasRectClip && !baseClip->hasRegionClip)) {
+ QPaintEngineEx::clip(region, op);
+ } else {
+ const QClipData *curClip;
+ QClipData *newClip;
+
+ if (op == Qt::IntersectClip)
+ curClip = clip;
+ else
+ curClip = baseClip;
+
+ if (s->flags.has_clip_ownership) {
+ newClip = s->clip;
+ Q_ASSERT(newClip);
+ } else {
+ newClip = new QClipData(d->rasterBuffer->height());
+ s->clip = newClip;
+ s->flags.has_clip_ownership = true;
+ }
+
+ QRegion r = s->matrix.map(region);
+ if (curClip->hasRectClip)
+ newClip->setClipRegion(r & curClip->clipRect);
+ else if (curClip->hasRegionClip)
+ newClip->setClipRegion(r & clip->clipRegion);
+
+ qrasterpaintengine_dirty_clip(d, s);
+ }
}
/*!
@@ -1412,7 +1441,7 @@ static void fillRect_normalized(const QRect &r, QSpanData *data,
{
int x1, x2, y1, y2;
- bool rectClipped = false;
+ bool rectClipped = true;
if (data->clip) {
x1 = qMax(r.x(), data->clip->xmin);
@@ -1742,12 +1771,17 @@ void QRasterPaintEngine::stroke(const QVectorPath &path, const QPen &pen)
static inline QRect toNormalizedFillRect(const QRectF &rect)
{
- const int x1 = qRound(rect.x() + aliasedCoordinateDelta);
- const int y1 = qRound(rect.y() + aliasedCoordinateDelta);
- const int x2 = qRound(rect.right() + aliasedCoordinateDelta);
- const int y2 = qRound(rect.bottom() + aliasedCoordinateDelta);
+ int x1 = int(rect.x() + aliasedCoordinateDelta);
+ int y1 = int(rect.y() + aliasedCoordinateDelta);
+ int x2 = int(rect.right() + aliasedCoordinateDelta);
+ int y2 = int(rect.bottom() + aliasedCoordinateDelta);
+
+ if (x2 < x1)
+ qSwap(x1, x2);
+ if (y2 < y1)
+ qSwap(y1, y2);
- return QRect(x1, y1, x2 - x1, y2 - y1).normalized();
+ return QRect(x1, y1, x2 - x1, y2 - y1);
}
/*!
@@ -1907,9 +1941,12 @@ void QRasterPaintEngine::fillRect(const QRectF &r, const QColor &color)
QRasterPaintEngineState *s = state();
d->solid_color_filler.solid.color = PREMUL(ARGB_COMBINE_ALPHA(color.rgba(), s->intOpacity));
+ if ((d->solid_color_filler.solid.color & 0xff000000) == 0
+ && s->composition_mode == QPainter::CompositionMode_SourceOver) {
+ return;
+ }
d->solid_color_filler.clip = d->clip();
d->solid_color_filler.adjustSpanMethods();
-
fillRect(r, &d->solid_color_filler);
}
@@ -3076,7 +3113,7 @@ bool QRasterPaintEnginePrivate::isUnclipped_normalized(const QRect &r) const
if (cl->clipRect == deviceRect)
return true;
- if (cl->hasRegionClip) {
+ if (cl->hasRectClip) {
// inline contains() for performance (we know the rects are normalized)
const QRect &r1 = cl->clipRect;
return (r.left() >= r1.left() && r.right() <= r1.right()
@@ -4307,6 +4344,7 @@ void QClipData::initialize()
m_clipLines = (ClipLine *)calloc(sizeof(ClipLine), clipSpanHeight);
m_spans = (QSpan *)malloc(clipSpanHeight*sizeof(QSpan));
+ allocated = clipSpanHeight;
if (hasRectClip) {
int y = 0;
@@ -4351,6 +4389,7 @@ void QClipData::initialize()
int y = 0;
int firstInBand = 0;
+ count = 0;
while (firstInBand < numRects) {
const int currMinY = rects.at(firstInBand).y();
const int currMaxY = currMinY + rects.at(firstInBand).height();
@@ -4411,20 +4450,39 @@ void QClipData::fixup()
ymax = m_spans[count-1].y + 1;
xmin = INT_MAX;
xmax = 0;
+
+ bool isRect = true;
+ int left = m_spans[0].x;
+ int right = m_spans[0].x + m_spans[0].len;
+
for (int i = 0; i < count; ++i) {
-// qDebug() << " " << spans[i].x << spans[i].y << spans[i].len << spans[i].coverage;
if (m_spans[i].y != y) {
+ if (m_spans[i].y != y + 1 && y != -1) {
+ isRect = false;
+ }
y = m_spans[i].y;
m_clipLines[y].spans = m_spans+i;
m_clipLines[y].count = 0;
// qDebug() << " new line: y=" << y;
}
++m_clipLines[y].count;
+ int sl = (int) m_spans[i].x;
+ int sr = sl + m_spans[i].len;
+
xmin = qMin(xmin, (int)m_spans[i].x);
xmax = qMax(xmax, (int)m_spans[i].x + m_spans[i].len);
+
+ if (sl != left || sr != right)
+ isRect = false;
}
++xmax;
-// qDebug("xmin=%d,xmax=%d,ymin=%d,ymax=%d", xmin, xmax, ymin, ymax);
+// qDebug("xmin=%d,xmax=%d,ymin=%d,ymax=%d %s", xmin, xmax, ymin, ymax, isRect ? "rectangular" : "");
+
+ if (isRect) {
+ hasRectClip = true;
+ clipRect.setRect(xmin, ymin, xmax - xmin, ymax - ymin);
+ }
+
}
/*
@@ -4437,6 +4495,7 @@ void QClipData::setClipRect(const QRect &rect)
// qDebug() << "setClipRect" << clipSpanHeight << count << allocated << rect;
hasRectClip = true;
+ hasRegionClip = false;
clipRect = rect;
xmin = rect.x();
@@ -4445,7 +4504,7 @@ void QClipData::setClipRect(const QRect &rect)
ymax = qMin(rect.y() + rect.height(), clipSpanHeight);
if (m_spans) {
- delete m_spans;
+ free(m_spans);
m_spans = 0;
}
@@ -4463,6 +4522,7 @@ void QClipData::setClipRegion(const QRegion &region)
}
hasRegionClip = true;
+ hasRectClip = false;
clipRegion = region;
{ // set bounding rect
@@ -4474,7 +4534,7 @@ void QClipData::setClipRegion(const QRegion &region)
}
if (m_spans) {
- delete m_spans;
+ free(m_spans);
m_spans = 0;
}
@@ -4722,29 +4782,6 @@ static void qt_span_fill_clipRect(int count, const QSpan *spans,
fillData->unclipped_blend(count, spans, fillData);
}
-static void qt_span_fill_clipRegion(int count, const QSpan *spans,
- void *userData)
-{
- QSpanData *fillData = reinterpret_cast<QSpanData *>(userData);
- Q_ASSERT(fillData->blend && fillData->unclipped_blend);
-
- Q_ASSERT(fillData->clip);
- Q_ASSERT(!fillData->clip->clipRegion.isEmpty());
-
- const int NSPANS = 256;
- QSpan cspans[NSPANS];
- int currentClip = 0;
- while (currentClip < count) {
- const int unclipped = qt_intersect_spans(const_cast<QSpan*>(spans),
- count, &currentClip,
- &cspans[0], NSPANS,
- fillData->clip->clipRegion);
- if (unclipped > 0)
- fillData->unclipped_blend(unclipped, cspans, fillData);
- }
-
-}
-
static void qt_span_clip(int count, const QSpan *spans, void *userData)
{
ClipData *clipData = reinterpret_cast<ClipData *>(userData);
@@ -5017,7 +5054,7 @@ void QSpanData::init(QRasterBuffer *rb, const QRasterPaintEngine *pe)
extern QImage qt_imageForBrush(int brushStyle, bool invert);
-void QSpanData::setup(const QBrush &brush, int alpha)
+void QSpanData::setup(const QBrush &brush, int alpha, QPainter::CompositionMode compositionMode)
{
Qt::BrushStyle brushStyle = qbrush_style(brush);
switch (brushStyle) {
@@ -5025,6 +5062,10 @@ void QSpanData::setup(const QBrush &brush, int alpha)
type = Solid;
QColor c = qbrush_color(brush);
solid.color = PREMUL(ARGB_COMBINE_ALPHA(c.rgba(), alpha));
+ if ((solid.color & 0xff000000) == 0
+ && compositionMode == QPainter::CompositionMode_SourceOver) {
+ type = None;
+ }
break;
}
@@ -5165,8 +5206,6 @@ void QSpanData::adjustSpanMethods()
blend = unclipped_blend;
} else if (clip->hasRectClip) {
blend = clip->clipRect.isEmpty() ? 0 : qt_span_fill_clipRect;
- } else if (clip->hasRegionClip) {
- blend = clip->clipRegion.isEmpty() ? 0 : qt_span_fill_clipRegion;
} else {
blend = qt_span_fill_clipped;
}
@@ -6147,7 +6186,7 @@ void dumpClip(int width, int height, QClipData *clip)
int y1 = 0;
for (int i = 0; i < clip->count; ++i) {
- QSpan *span = clip->spans + i;
+ QSpan *span = clip->spans() + i;
for (int j = 0; j < span->len; ++j)
clipImg.setPixel(span->x + j, span->y, 0xffffff00);
x0 = qMin(x0, int(span->x));
diff --git a/src/gui/painting/qpaintengine_raster_p.h b/src/gui/painting/qpaintengine_raster_p.h
index 26a2b3f..1f3f006 100644
--- a/src/gui/painting/qpaintengine_raster_p.h
+++ b/src/gui/painting/qpaintengine_raster_p.h
@@ -202,7 +202,6 @@ public:
void clip(const QVectorPath &path, Qt::ClipOperation op);
void clip(const QRect &rect, Qt::ClipOperation op);
void clip(const QRegion &region, Qt::ClipOperation op);
- void clip(const QPainterPath &path, Qt::ClipOperation op);
enum ClipType {
RectClip,
diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp
index 8eaad60..28f9220 100644
--- a/src/gui/painting/qpaintengineex.cpp
+++ b/src/gui/painting/qpaintengineex.cpp
@@ -105,7 +105,7 @@ QDebug Q_GUI_EXPORT &operator<<(QDebug &s, const QVectorPath &path)
vectorPathBounds.x2 - vectorPathBounds.x1, vectorPathBounds.y2 - vectorPathBounds.y1);
s << "QVectorPath(size:" << path.elementCount()
<< " hints:" << hex << path.hints()
- << rf << ")";
+ << rf << ')';
return s;
}
#endif
@@ -778,7 +778,7 @@ void QPaintEngineEx::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, con
{
QBrush brush(state()->pen.color(), pixmap);
QTransform xform;
- xform.translate(-s.x(), -s.y());
+ xform.translate(r.x() - s.x(), r.y() - s.y());
brush.setTransform(xform);
qreal pts[] = { r.x(), r.y(),
diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp
index 3645d9a..262a033 100644
--- a/src/gui/painting/qpainterpath.cpp
+++ b/src/gui/painting/qpainterpath.cpp
@@ -3348,7 +3348,7 @@ QDebug operator<<(QDebug s, const QPainterPath &p)
s.nospace() << "QPainterPath: Element count=" << p.elementCount() << endl;
const char *types[] = {"MoveTo", "LineTo", "CurveTo", "CurveToData"};
for (int i=0; i<p.elementCount(); ++i) {
- s.nospace() << " -> " << types[p.elementAt(i).type] << "(x=" << p.elementAt(i).x << ", y=" << p.elementAt(i).y << ")" << endl;
+ s.nospace() << " -> " << types[p.elementAt(i).type] << "(x=" << p.elementAt(i).x << ", y=" << p.elementAt(i).y << ')' << endl;
}
return s;
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp
index 55006f6..0b2db8c 100644
--- a/src/gui/painting/qpdf.cpp
+++ b/src/gui/painting/qpdf.cpp
@@ -346,7 +346,7 @@ QByteArray QPdf::generateDashes(const QPen &pen)
{
QByteArray result;
ByteStream s(&result);
- s << "[";
+ s << '[';
QVector<qreal> dasharray = pen.dashPattern();
qreal w = pen.widthF();
@@ -357,7 +357,7 @@ QByteArray QPdf::generateDashes(const QPen &pen)
if (dw < 0.0001) dw = 0.0001;
s << dw;
}
- s << "]";
+ s << ']';
//qDebug() << "dasharray: pen has" << dasharray;
//qDebug() << " => " << result;
return result;
@@ -915,17 +915,17 @@ const char *QPdf::paperSizeToString(QPrinter::PaperSize paperSize)
QByteArray QPdf::stripSpecialCharacters(const QByteArray &string)
{
QByteArray s = string;
- s.replace(" ", "");
- s.replace("(", "");
- s.replace(")", "");
- s.replace("<", "");
- s.replace(">", "");
- s.replace("[", "");
- s.replace("]", "");
- s.replace("{", "");
- s.replace("}", "");
- s.replace("/", "");
- s.replace("%", "");
+ s.replace(' ', "");
+ s.replace('(', "");
+ s.replace(')', "");
+ s.replace('<', "");
+ s.replace('>', "");
+ s.replace('[', "");
+ s.replace(']', "");
+ s.replace('{', "");
+ s.replace('}', "");
+ s.replace('/', "");
+ s.replace('%', "");
return s;
}
diff --git a/src/gui/painting/qpen.cpp b/src/gui/painting/qpen.cpp
index 1d68520..ab60861 100644
--- a/src/gui/painting/qpen.cpp
+++ b/src/gui/painting/qpen.cpp
@@ -978,7 +978,7 @@ QDebug operator<<(QDebug dbg, const QPen &p)
dbg.nospace() << "QPen(" << p.width() << ',' << p.brush()
<< ',' << int(p.style()) << ',' << int(p.capStyle())
<< ',' << int(p.joinStyle()) << ',' << p.dashPattern()
- << "," << p.dashOffset()
+ << ',' << p.dashOffset()
<< ',' << p.miterLimit() << ')';
return dbg.space();
#else
diff --git a/src/gui/painting/qprintengine_pdf.cpp b/src/gui/painting/qprintengine_pdf.cpp
index 2e063b7..e504558 100644
--- a/src/gui/painting/qprintengine_pdf.cpp
+++ b/src/gui/painting/qprintengine_pdf.cpp
@@ -423,7 +423,7 @@ int QPdfEnginePrivate::addConstantAlphaObject(int brushAlpha, int penAlpha)
object = addXrefEntry(-1);
QByteArray alphaDef;
QPdf::ByteStream s(&alphaDef);
- s << "<<\n/ca " << (brushAlpha/qreal(255.)) << "\n";
+ s << "<<\n/ca " << (brushAlpha/qreal(255.)) << '\n';
s << "/CA " << (penAlpha/qreal(255.)) << "\n>>";
xprintf("%s\nendobj\n", alphaDef.constData());
alphaCache.insert(QPair<uint, uint>(brushAlpha, penAlpha), object);
@@ -1010,7 +1010,7 @@ void QPdfEnginePrivate::embedFont(QFontSubset *font)
s << (char)('A' + (tag % 26));
tag /= 26;
}
- s << "+" << properties.postscriptName << "\n"
+ s << '+' << properties.postscriptName << "\n"
"/Flags " << 4 << "\n"
"/FontBBox ["
<< properties.boundingBox.x()*scale
diff --git a/src/gui/painting/qprintengine_ps.cpp b/src/gui/painting/qprintengine_ps.cpp
index 97ec640..29f364e 100644
--- a/src/gui/painting/qprintengine_ps.cpp
+++ b/src/gui/painting/qprintengine_ps.cpp
@@ -167,7 +167,7 @@ static QByteArray wrapDSC(const QByteArray &str)
}
wrapped += "\n%%+" + tmp;
}
- return wrapped + "\n";
+ return wrapped + '\n';
}
// ----------------------------- Internal class declarations -----------------------------
@@ -422,7 +422,7 @@ void QPSPrintEnginePrivate::drawImageHelper(qreal x, qreal y, qreal w, qreal h,
<< size << " string readstring\n";
ps_r7(*currentPage, out, out.size());
*currentPage << " pop def\n";
- *currentPage << width << ' ' << height << "[" << scaleX << " 0 0 " << scaleY << " 0 0]sl "
+ *currentPage << width << ' ' << height << '[' << scaleX << " 0 0 " << scaleY << " 0 0]sl "
<< bits << (!mask.isNull() ? "mask " : "false ")
<< x << ' ' << y << " di\n";
}
@@ -529,7 +529,7 @@ void QPSPrintEnginePrivate::emitHeader(bool finished)
else
s << "\n%%BoundingBox: 0 0 " << w << h;
}
- s << "\n" << wrapDSC("%%Creator: " + creator.toUtf8());
+ s << '\n' << wrapDSC("%%Creator: " + creator.toUtf8());
if (!title.isEmpty())
s << wrapDSC("%%Title: " + title.toUtf8());
#ifndef QT_NO_DATESTRING
@@ -549,7 +549,7 @@ void QPSPrintEnginePrivate::emitHeader(bool finished)
"% Prolog copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).\n"
"% You may copy this prolog in any way that is directly related to this document.\n"
"% For other use of this prolog, see your licensing agreement for Qt.\n"
- << ps_header << "\n";
+ << ps_header << '\n';
s << "/pageinit {\n";
@@ -560,12 +560,12 @@ void QPSPrintEnginePrivate::emitHeader(bool finished)
s << mtop*scale << mleft*scale << "translate\n";
}
if (orientation == QPrinter::Portrait) {
- s << "% " << printer->widthMM() << "*" << printer->heightMM()
+ s << "% " << printer->widthMM() << '*' << printer->heightMM()
<< "mm (portrait)\n0 " << height*scale
- << "translate " << scale << "-" << scale << "scale } def\n";
+ << "translate " << scale << '-' << scale << "scale } def\n";
} else {
- s << "% " << printer->heightMM() << "*" << printer->widthMM()
- << " mm (landscape)\n 90 rotate " << scale << "-" << scale << "scale } def\n";
+ s << "% " << printer->heightMM() << '*' << printer->widthMM()
+ << " mm (landscape)\n 90 rotate " << scale << '-' << scale << "scale } def\n";
}
s << "%%EndProlog\n";
@@ -619,8 +619,8 @@ void QPSPrintEnginePrivate::flushPage(bool last)
QPdf::ByteStream e(&trailer);
buffer << "%%Page: "
<< pageCount << pageCount << "\n"
- << "%%BeginPageSetup\n"
- << "QI\n";
+ "%%BeginPageSetup\n"
+ "QI\n";
if (hugeDocument) {
for (QHash<QFontEngine::FaceId, QFontSubset *>::const_iterator it = fonts.constBegin();
it != fonts.constEnd(); ++it) {
@@ -776,8 +776,8 @@ bool QPSPrintEngine::end()
d->flushPage(true);
QByteArray trailer;
QPdf::ByteStream s(&trailer);
- s << "%%Trailer\n";
- s << "%%Pages: " << d->pageCount - 1 << "\n" <<
+ s << "%%Trailer\n"
+ "%%Pages: " << d->pageCount - 1 << '\n' <<
wrapDSC("%%DocumentFonts: " + d->fontsUsed);
s << "%%EOF\n";
d->outDevice->write(trailer);
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp
index c88af7c..c4cd77a 100644
--- a/src/gui/painting/qregion.cpp
+++ b/src/gui/painting/qregion.cpp
@@ -450,9 +450,9 @@ QDebug operator<<(QDebug s, const QRegion &r)
{
QVector<QRect> rects = r.rects();
s.nospace() << "QRegion(size=" << rects.size() << "), "
- << "bounds = " << r.boundingRect() << "\n";
+ << "bounds = " << r.boundingRect() << '\n';
for (int i=0; i<rects.size(); ++i)
- s << "- " << i << rects.at(i) << "\n";
+ s << "- " << i << rects.at(i) << '\n';
return s;
}
#endif
@@ -1601,7 +1601,7 @@ void QRegionPrivate::selfTest() const
for (int i = 0; i < numRects; ++i) {
const QRect r = rects.at(i);
if ((r.width() * r.height()) > innerArea)
- qDebug() << "selfTest(): innerRect" << innerRect << "<" << r;
+ qDebug() << "selfTest(): innerRect" << innerRect << '<' << r;
}
QRect r = rects.first();
diff --git a/src/gui/painting/qtessellator.cpp b/src/gui/painting/qtessellator.cpp
index ce5ab74..b743940 100644
--- a/src/gui/painting/qtessellator.cpp
+++ b/src/gui/painting/qtessellator.cpp
@@ -1081,7 +1081,7 @@ void QTessellatorPrivate::addIntersection(const Edge *e1, const Edge *e2)
yi = y;
}
QDEBUG() << " between edges " << e1->edge << "and" << e2->edge << "at point ("
- << Q27Dot5ToDouble(yi) << ")";
+ << Q27Dot5ToDouble(yi) << ')';
Intersection i1;
i1.y = yi;
@@ -1174,7 +1174,7 @@ void QTessellatorPrivate::addIntersections()
for (int i = 0; i < scanline.size; ++i) {
Edge *e = scanline.edges[i];
QDEBUG() << " " << i << e->edge << "isect=(" << e->intersect_left << e->intersect_right
- << ")";
+ << ')';
}
#endif
@@ -1240,8 +1240,8 @@ QRectF QTessellator::tessellate(const QPointF *points, int nPoints)
QDEBUG() << " " << i << ": "
<< "point=" << d->vertices.position(d->vertices.sorted[i])
<< "flags=" << d->vertices.sorted[i]->flags
- << "pos=(" << Q27Dot5ToDouble(d->vertices.sorted[i]->x) << "/"
- << Q27Dot5ToDouble(d->vertices.sorted[i]->y) << ")";
+ << "pos=(" << Q27Dot5ToDouble(d->vertices.sorted[i]->x) << '/'
+ << Q27Dot5ToDouble(d->vertices.sorted[i]->y) << ')';
}
#endif
@@ -1271,9 +1271,9 @@ QRectF QTessellator::tessellate(const QPointF *points, int nPoints)
for (int i = 0; i < d->scanline.size; ++i) {
QDEBUG() << " " << d->scanline.edges[i]->edge
<< "p0= (" << Q27Dot5ToDouble(d->scanline.edges[i]->v0->x)
- << "/" << Q27Dot5ToDouble(d->scanline.edges[i]->v0->y)
+ << '/' << Q27Dot5ToDouble(d->scanline.edges[i]->v0->y)
<< ") p1= (" << Q27Dot5ToDouble(d->scanline.edges[i]->v1->x)
- << "/" << Q27Dot5ToDouble(d->scanline.edges[i]->v1->y) << ")"
+ << '/' << Q27Dot5ToDouble(d->scanline.edges[i]->v1->y) << ")"
<< "x=" << Q27Dot5ToDouble(d->scanline.edges[i]->positionAt(d->y))
<< "isLeftOfNext="
<< ((i < d->scanline.size - 1)
diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp
index ec8c1dc..c00012a 100644
--- a/src/gui/painting/qtransform.cpp
+++ b/src/gui/painting/qtransform.cpp
@@ -1020,7 +1020,7 @@ QDebug operator<<(QDebug dbg, const QTransform &m)
<< " 31=" << m.m31()
<< " 32=" << m.m32()
<< " 33=" << m.m33()
- << ")";
+ << ')';
return dbg.space();
}
#endif
diff --git a/src/gui/painting/qtransform.h b/src/gui/painting/qtransform.h
index 7e93f74..aac7c31 100644
--- a/src/gui/painting/qtransform.h
+++ b/src/gui/painting/qtransform.h
@@ -275,13 +275,6 @@ inline qreal QTransform::dy() const
return affine._dy;
}
-#if defined(Q_CC_GNU)
-# define Q_CC_GNU_VERSION (((__GNUC__)<<16)|((__GNUC_MINOR__)<<8)|(__GNUC_PATCHLEVEL__))
-# if Q_CC_GNU_VERSION >= 0x040201
-# pragma GCC diagnostic ignored "-Wfloat-equal"
-# endif
-#endif
-
inline QTransform &QTransform::operator*=(qreal num)
{
if (num == 1.)
@@ -338,13 +331,6 @@ inline QTransform &QTransform::operator-=(qreal num)
return *this;
}
-#if defined(Q_CC_GNU_VERSION)
-# if Q_CC_GNU_VERSION >= 0x040201
-# pragma GCC diagnostic warning "-Wfloat-equal"
-# endif
-# undef Q_CC_GNU_VERSION
-#endif
-
/****** stream functions *******************/
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QTransform &);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QTransform &);
diff --git a/src/gui/statemachine/qbasickeyeventtransition.cpp b/src/gui/statemachine/qbasickeyeventtransition.cpp
new file mode 100644
index 0000000..f7f1eb6
--- /dev/null
+++ b/src/gui/statemachine/qbasickeyeventtransition.cpp
@@ -0,0 +1,203 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbasickeyeventtransition_p.h"
+#include <QtGui/qevent.h>
+#include <qdebug.h>
+#include <private/qabstracttransition_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \internal
+ \class QBasicKeyEventTransition
+ \since 4.6
+ \ingroup statemachine
+
+ \brief The QBasicKeyEventTransition class provides a transition for Qt key events.
+*/
+
+class QBasicKeyEventTransitionPrivate : public QAbstractTransitionPrivate
+{
+ Q_DECLARE_PUBLIC(QBasicKeyEventTransition)
+public:
+ QBasicKeyEventTransitionPrivate();
+
+ static QBasicKeyEventTransitionPrivate *get(QBasicKeyEventTransition *q);
+
+ QEvent::Type eventType;
+ int key;
+ Qt::KeyboardModifiers modifiersMask;
+};
+
+QBasicKeyEventTransitionPrivate::QBasicKeyEventTransitionPrivate()
+{
+ eventType = QEvent::None;
+ key = 0;
+ modifiersMask = Qt::NoModifier;
+}
+
+QBasicKeyEventTransitionPrivate *QBasicKeyEventTransitionPrivate::get(QBasicKeyEventTransition *q)
+{
+ return q->d_func();
+}
+
+/*!
+ Constructs a new key event transition with the given \a sourceState.
+*/
+QBasicKeyEventTransition::QBasicKeyEventTransition(QState *sourceState)
+ : QAbstractTransition(*new QBasicKeyEventTransitionPrivate, sourceState)
+{
+}
+
+/*!
+ Constructs a new event transition for events of the given \a type for the
+ given \a key, with the given \a sourceState.
+*/
+QBasicKeyEventTransition::QBasicKeyEventTransition(QEvent::Type type, int key,
+ QState *sourceState)
+ : QAbstractTransition(*new QBasicKeyEventTransitionPrivate, sourceState)
+{
+ Q_D(QBasicKeyEventTransition);
+ d->eventType = type;
+ d->key = key;
+}
+
+/*!
+ Constructs a new event transition for events of the given \a type for the
+ given \a key, with the given \a modifiersMask and \a sourceState.
+*/
+QBasicKeyEventTransition::QBasicKeyEventTransition(QEvent::Type type, int key,
+ Qt::KeyboardModifiers modifiersMask,
+ QState *sourceState)
+ : QAbstractTransition(*new QBasicKeyEventTransitionPrivate, sourceState)
+{
+ Q_D(QBasicKeyEventTransition);
+ d->eventType = type;
+ d->key = key;
+ d->modifiersMask = modifiersMask;
+}
+
+/*!
+ Destroys this event transition.
+*/
+QBasicKeyEventTransition::~QBasicKeyEventTransition()
+{
+}
+
+/*!
+ Returns the event type that this key event transition is associated with.
+*/
+QEvent::Type QBasicKeyEventTransition::eventType() const
+{
+ Q_D(const QBasicKeyEventTransition);
+ return d->eventType;
+}
+
+/*!
+ Sets the event \a type that this key event transition is associated with.
+*/
+void QBasicKeyEventTransition::setEventType(QEvent::Type type)
+{
+ Q_D(QBasicKeyEventTransition);
+ d->eventType = type;
+}
+
+/*!
+ Returns the key that this key event transition checks for.
+*/
+int QBasicKeyEventTransition::key() const
+{
+ Q_D(const QBasicKeyEventTransition);
+ return d->key;
+}
+
+/*!
+ Sets the key that this key event transition will check for.
+*/
+void QBasicKeyEventTransition::setKey(int key)
+{
+ Q_D(QBasicKeyEventTransition);
+ d->key = key;
+}
+
+/*!
+ Returns the keyboard modifiers mask that this key event transition checks
+ for.
+*/
+Qt::KeyboardModifiers QBasicKeyEventTransition::modifiersMask() const
+{
+ Q_D(const QBasicKeyEventTransition);
+ return d->modifiersMask;
+}
+
+/*!
+ Sets the keyboard modifiers mask that this key event transition will check
+ for.
+*/
+void QBasicKeyEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask)
+{
+ Q_D(QBasicKeyEventTransition);
+ d->modifiersMask = modifiersMask;
+}
+
+/*!
+ \reimp
+*/
+bool QBasicKeyEventTransition::eventTest(QEvent *event)
+{
+ Q_D(const QBasicKeyEventTransition);
+ if (event->type() == d->eventType) {
+ QKeyEvent *ke = static_cast<QKeyEvent*>(event);
+ return (ke->key() == d->key)
+ && ((ke->modifiers() & d->modifiersMask) == d->modifiersMask);
+ }
+ return false;
+}
+
+/*!
+ \reimp
+*/
+void QBasicKeyEventTransition::onTransition(QEvent *)
+{
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/statemachine/qbasickeyeventtransition_p.h b/src/gui/statemachine/qbasickeyeventtransition_p.h
new file mode 100644
index 0000000..39fa6ad
--- /dev/null
+++ b/src/gui/statemachine/qbasickeyeventtransition_p.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QBASICKEYEVENTTRANSITION_P_H
+#define QBASICKEYEVENTTRANSITION_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qabstracttransition.h>
+#include <QtGui/qevent.h>
+
+QT_BEGIN_NAMESPACE
+
+class QBasicKeyEventTransitionPrivate;
+class Q_AUTOTEST_EXPORT QBasicKeyEventTransition : public QAbstractTransition
+{
+ Q_OBJECT
+public:
+ QBasicKeyEventTransition(QState *sourceState = 0);
+ QBasicKeyEventTransition(QEvent::Type type, int key, QState *sourceState = 0);
+ QBasicKeyEventTransition(QEvent::Type type, int key,
+ Qt::KeyboardModifiers modifiersMask,
+ QState *sourceState = 0);
+ ~QBasicKeyEventTransition();
+
+ QEvent::Type eventType() const;
+ void setEventType(QEvent::Type type);
+
+ int key() const;
+ void setKey(int key);
+
+ Qt::KeyboardModifiers modifiersMask() const;
+ void setModifiersMask(Qt::KeyboardModifiers modifiers);
+
+protected:
+ bool eventTest(QEvent *event);
+ void onTransition(QEvent *);
+
+private:
+ Q_DISABLE_COPY(QBasicKeyEventTransition)
+ Q_DECLARE_PRIVATE(QBasicKeyEventTransition)
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/gui/statemachine/qbasicmouseeventtransition.cpp b/src/gui/statemachine/qbasicmouseeventtransition.cpp
new file mode 100644
index 0000000..20dd792
--- /dev/null
+++ b/src/gui/statemachine/qbasicmouseeventtransition.cpp
@@ -0,0 +1,208 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbasicmouseeventtransition_p.h"
+#include <QtGui/qevent.h>
+#include <QtGui/qpainterpath.h>
+#include <qdebug.h>
+#include <private/qabstracttransition_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \internal
+ \class QBasicMouseEventTransition
+ \since 4.6
+ \ingroup statemachine
+
+ \brief The QBasicMouseEventTransition class provides a transition for Qt mouse events.
+*/
+
+class QBasicMouseEventTransitionPrivate : public QAbstractTransitionPrivate
+{
+ Q_DECLARE_PUBLIC(QBasicMouseEventTransition)
+public:
+ QBasicMouseEventTransitionPrivate();
+
+ static QBasicMouseEventTransitionPrivate *get(QBasicMouseEventTransition *q);
+
+ QEvent::Type eventType;
+ Qt::MouseButton button;
+ Qt::KeyboardModifiers modifiersMask;
+ QPainterPath path;
+};
+
+QBasicMouseEventTransitionPrivate::QBasicMouseEventTransitionPrivate()
+{
+ eventType = QEvent::None;
+ button = Qt::NoButton;
+}
+
+QBasicMouseEventTransitionPrivate *QBasicMouseEventTransitionPrivate::get(QBasicMouseEventTransition *q)
+{
+ return q->d_func();
+}
+
+/*!
+ Constructs a new mouse event transition with the given \a sourceState.
+*/
+QBasicMouseEventTransition::QBasicMouseEventTransition(QState *sourceState)
+ : QAbstractTransition(*new QBasicMouseEventTransitionPrivate, sourceState)
+{
+}
+
+/*!
+ Constructs a new mouse event transition for events of the given \a type.
+*/
+QBasicMouseEventTransition::QBasicMouseEventTransition(QEvent::Type type,
+ Qt::MouseButton button,
+ QState *sourceState)
+ : QAbstractTransition(*new QBasicMouseEventTransitionPrivate, sourceState)
+{
+ Q_D(QBasicMouseEventTransition);
+ d->eventType = type;
+ d->button = button;
+}
+
+/*!
+ Destroys this mouse event transition.
+*/
+QBasicMouseEventTransition::~QBasicMouseEventTransition()
+{
+}
+
+/*!
+ Returns the event type that this mouse event transition is associated with.
+*/
+QEvent::Type QBasicMouseEventTransition::eventType() const
+{
+ Q_D(const QBasicMouseEventTransition);
+ return d->eventType;
+}
+
+/*!
+ Sets the event \a type that this mouse event transition is associated with.
+*/
+void QBasicMouseEventTransition::setEventType(QEvent::Type type)
+{
+ Q_D(QBasicMouseEventTransition);
+ d->eventType = type;
+}
+
+/*!
+ Returns the button that this mouse event transition checks for.
+*/
+Qt::MouseButton QBasicMouseEventTransition::button() const
+{
+ Q_D(const QBasicMouseEventTransition);
+ return d->button;
+}
+
+/*!
+ Sets the button that this mouse event transition will check for.
+*/
+void QBasicMouseEventTransition::setButton(Qt::MouseButton button)
+{
+ Q_D(QBasicMouseEventTransition);
+ d->button = button;
+}
+
+/*!
+ Returns the keyboard modifiers mask that this mouse event transition checks
+ for.
+*/
+Qt::KeyboardModifiers QBasicMouseEventTransition::modifiersMask() const
+{
+ Q_D(const QBasicMouseEventTransition);
+ return d->modifiersMask;
+}
+
+/*!
+ Sets the keyboard modifiers mask that this mouse event transition will check
+ for.
+*/
+void QBasicMouseEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask)
+{
+ Q_D(QBasicMouseEventTransition);
+ d->modifiersMask = modifiersMask;
+}
+
+/*!
+ Returns the path for this mouse event transition.
+*/
+QPainterPath QBasicMouseEventTransition::path() const
+{
+ Q_D(const QBasicMouseEventTransition);
+ return d->path;
+}
+
+/*!
+ Sets the path for this mouse event transition.
+*/
+void QBasicMouseEventTransition::setPath(const QPainterPath &path)
+{
+ Q_D(QBasicMouseEventTransition);
+ d->path = path;
+}
+
+/*!
+ \reimp
+*/
+bool QBasicMouseEventTransition::eventTest(QEvent *event)
+{
+ Q_D(const QBasicMouseEventTransition);
+ if (event->type() == d->eventType) {
+ QMouseEvent *me = static_cast<QMouseEvent*>(event);
+ return (me->button() == d->button)
+ && ((me->modifiers() & d->modifiersMask) == d->modifiersMask)
+ && (d->path.isEmpty() || d->path.contains(me->pos()));
+ }
+ return false;
+}
+
+/*!
+ \reimp
+*/
+void QBasicMouseEventTransition::onTransition(QEvent *)
+{
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/statemachine/qbasicmouseeventtransition_p.h b/src/gui/statemachine/qbasicmouseeventtransition_p.h
new file mode 100644
index 0000000..6c0afe4
--- /dev/null
+++ b/src/gui/statemachine/qbasicmouseeventtransition_p.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QBASICMOUSEEVENTTRANSITION_P_H
+#define QBASICMOUSEEVENTTRANSITION_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qabstracttransition.h>
+#include <QtGui/qevent.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPainterPath;
+
+class QBasicMouseEventTransitionPrivate;
+class Q_AUTOTEST_EXPORT QBasicMouseEventTransition : public QAbstractTransition
+{
+ Q_OBJECT
+public:
+ QBasicMouseEventTransition(QState *sourceState = 0);
+ QBasicMouseEventTransition(QEvent::Type type, Qt::MouseButton button,
+ QState *sourceState = 0);
+ ~QBasicMouseEventTransition();
+
+ QEvent::Type eventType() const;
+ void setEventType(QEvent::Type type);
+
+ Qt::MouseButton button() const;
+ void setButton(Qt::MouseButton button);
+
+ Qt::KeyboardModifiers modifiersMask() const;
+ void setModifiersMask(Qt::KeyboardModifiers modifiers);
+
+ QPainterPath path() const;
+ void setPath(const QPainterPath &path);
+
+protected:
+ bool eventTest(QEvent *event);
+ void onTransition(QEvent *);
+
+private:
+ Q_DISABLE_COPY(QBasicMouseEventTransition)
+ Q_DECLARE_PRIVATE(QBasicMouseEventTransition)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/gui/statemachine/qguistatemachine.cpp b/src/gui/statemachine/qguistatemachine.cpp
new file mode 100644
index 0000000..612e43e
--- /dev/null
+++ b/src/gui/statemachine/qguistatemachine.cpp
@@ -0,0 +1,559 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/qstatemachine.h>
+#include <private/qstatemachine_p.h>
+#include <QtGui/qevent.h>
+#include <QtGui/qgraphicssceneevent.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_CORE_EXPORT const QStateMachinePrivate::Handler *qcoreStateMachineHandler();
+
+static QEvent *cloneEvent(QEvent *e)
+{
+ switch (e->type()) {
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseButtonRelease:
+ case QEvent::MouseButtonDblClick:
+ case QEvent::MouseMove:
+ return new QMouseEvent(*static_cast<QMouseEvent*>(e));
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease:
+ return new QKeyEvent(*static_cast<QKeyEvent*>(e));
+ case QEvent::FocusIn:
+ case QEvent::FocusOut:
+ return new QFocusEvent(*static_cast<QFocusEvent*>(e));
+ case QEvent::Enter:
+ return new QEvent(*e);
+ case QEvent::Leave:
+ return new QEvent(*e);
+ break;
+ case QEvent::Paint:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::Move:
+ return new QMoveEvent(*static_cast<QMoveEvent*>(e));
+ case QEvent::Resize:
+ return new QResizeEvent(*static_cast<QResizeEvent*>(e));
+ case QEvent::Create:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::Destroy:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::Show:
+ return new QShowEvent(*static_cast<QShowEvent*>(e));
+ case QEvent::Hide:
+ return new QHideEvent(*static_cast<QHideEvent*>(e));
+ case QEvent::Close:
+ return new QCloseEvent(*static_cast<QCloseEvent*>(e));
+ case QEvent::Quit:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ParentChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ParentAboutToChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ThreadChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::WindowActivate:
+ case QEvent::WindowDeactivate:
+ return new QEvent(*e);
+
+ case QEvent::ShowToParent:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::HideToParent:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::Wheel:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::WindowTitleChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::WindowIconChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ApplicationWindowIconChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ApplicationFontChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ApplicationLayoutDirectionChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ApplicationPaletteChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::PaletteChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::Clipboard:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::Speech:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::MetaCall:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::SockAct:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::WinEventAct:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::DeferredDelete:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::DragEnter:
+ return new QDragEnterEvent(*static_cast<QDragEnterEvent*>(e));
+ case QEvent::DragMove:
+ return new QDragMoveEvent(*static_cast<QDragMoveEvent*>(e));
+ case QEvent::DragLeave:
+ return new QDragLeaveEvent(*static_cast<QDragLeaveEvent*>(e));
+ case QEvent::Drop:
+ return new QDropEvent(*static_cast<QDragMoveEvent*>(e));
+ case QEvent::DragResponse:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ChildAdded:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ChildPolished:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+#ifdef QT3_SUPPORT
+ case QEvent::ChildInsertedRequest:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ChildInserted:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::LayoutHint:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+#endif
+ case QEvent::ChildRemoved:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ShowWindowRequest:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::PolishRequest:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::Polish:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::LayoutRequest:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::UpdateRequest:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::UpdateLater:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::EmbeddingControl:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ActivateControl:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::DeactivateControl:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ContextMenu:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::InputMethod:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::AccessibilityPrepare:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::TabletMove:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::LocaleChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::LanguageChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::LayoutDirectionChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::Style:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::TabletPress:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::TabletRelease:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::OkRequest:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::HelpRequest:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::IconDrag:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::FontChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::EnabledChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ActivationChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::StyleChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::IconTextChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ModifiedChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::MouseTrackingChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::WindowBlocked:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::WindowUnblocked:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::WindowStateChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::ToolTip:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::WhatsThis:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::StatusTip:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::ActionChanged:
+ case QEvent::ActionAdded:
+ case QEvent::ActionRemoved:
+ return new QActionEvent(*static_cast<QActionEvent*>(e));
+
+ case QEvent::FileOpen:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::Shortcut:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ShortcutOverride:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+#ifdef QT3_SUPPORT
+ case QEvent::Accel:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::AccelAvailable:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+#endif
+
+ case QEvent::WhatsThisClicked:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::ToolBarChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::ApplicationActivate:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ApplicationDeactivate:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::QueryWhatsThis:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::EnterWhatsThisMode:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::LeaveWhatsThisMode:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::ZOrderChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::HoverEnter:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::HoverLeave:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::HoverMove:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::AccessibilityHelp:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::AccessibilityDescription:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+#ifdef QT_KEYPAD_NAVIGATION
+ case QEvent::EnterEditFocus:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::LeaveEditFocus:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+#endif
+ case QEvent::AcceptDropsChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::MenubarUpdated:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::ZeroTimerEvent:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::GraphicsSceneMouseMove:
+ case QEvent::GraphicsSceneMousePress:
+ case QEvent::GraphicsSceneMouseRelease:
+ case QEvent::GraphicsSceneMouseDoubleClick: {
+ QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent*>(e);
+ QGraphicsSceneMouseEvent *me2 = new QGraphicsSceneMouseEvent(me->type());
+ me2->setWidget(me->widget());
+ me2->setPos(me->pos());
+ me2->setScenePos(me->scenePos());
+ me2->setScreenPos(me->screenPos());
+// ### for all buttons
+ me2->setButtonDownPos(Qt::LeftButton, me->buttonDownPos(Qt::LeftButton));
+ me2->setButtonDownPos(Qt::RightButton, me->buttonDownPos(Qt::RightButton));
+ me2->setButtonDownScreenPos(Qt::LeftButton, me->buttonDownScreenPos(Qt::LeftButton));
+ me2->setButtonDownScreenPos(Qt::RightButton, me->buttonDownScreenPos(Qt::RightButton));
+ me2->setLastPos(me->lastPos());
+ me2->setLastScenePos(me->lastScenePos());
+ me2->setLastScreenPos(me->lastScreenPos());
+ me2->setButtons(me->buttons());
+ me2->setButton(me->button());
+ me2->setModifiers(me->modifiers());
+ return me2;
+ }
+
+ case QEvent::GraphicsSceneContextMenu: {
+ QGraphicsSceneContextMenuEvent *me = static_cast<QGraphicsSceneContextMenuEvent*>(e);
+ QGraphicsSceneContextMenuEvent *me2 = new QGraphicsSceneContextMenuEvent(me->type());
+ me2->setWidget(me->widget());
+ me2->setPos(me->pos());
+ me2->setScenePos(me->scenePos());
+ me2->setScreenPos(me->screenPos());
+ me2->setModifiers(me->modifiers());
+ me2->setReason(me->reason());
+ return me2;
+ }
+
+ case QEvent::GraphicsSceneHoverEnter:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::GraphicsSceneHoverMove:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::GraphicsSceneHoverLeave:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::GraphicsSceneHelp:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::GraphicsSceneDragEnter:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::GraphicsSceneDragMove:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::GraphicsSceneDragLeave:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::GraphicsSceneDrop:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::GraphicsSceneWheel:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::KeyboardLayoutChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::DynamicPropertyChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::TabletEnterProximity:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::TabletLeaveProximity:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::NonClientAreaMouseMove:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::NonClientAreaMouseButtonPress:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::NonClientAreaMouseButtonRelease:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::NonClientAreaMouseButtonDblClick:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::MacSizeChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::ContentsRectChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::MacGLWindowChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::FutureCallOut:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::GraphicsSceneResize:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::GraphicsSceneMove: {
+ QGraphicsSceneMoveEvent *me = static_cast<QGraphicsSceneMoveEvent*>(e);
+ QGraphicsSceneMoveEvent *me2 = new QGraphicsSceneMoveEvent();
+ me2->setWidget(me->widget());
+ me2->setNewPos(me->newPos());
+ me2->setOldPos(me->oldPos());
+ return me2;
+ }
+
+ case QEvent::CursorChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ case QEvent::ToolTipChange:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::NetworkReplyUpdated:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+
+ case QEvent::GrabMouse:
+ case QEvent::UngrabMouse:
+ case QEvent::GrabKeyboard:
+ case QEvent::UngrabKeyboard:
+ return new QEvent(*e);
+
+#ifdef QT_MAC_USE_COCOA
+ case QEvent::CocoaRequestModal:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+#endif
+ case QEvent::User:
+ case QEvent::MaxUser:
+ Q_ASSERT_X(false, "cloneEvent()", "not implemented");
+ break;
+ default:
+ ;
+ }
+ return qcoreStateMachineHandler()->cloneEvent(e);
+}
+
+const QStateMachinePrivate::Handler qt_gui_statemachine_handler = {
+ cloneEvent
+};
+
+static const QStateMachinePrivate::Handler *qt_guistatemachine_last_handler = 0;
+int qRegisterGuiStateMachine()
+{
+ qt_guistatemachine_last_handler = QStateMachinePrivate::handler;
+ QStateMachinePrivate::handler = &qt_gui_statemachine_handler;
+ return 1;
+}
+Q_CONSTRUCTOR_FUNCTION(qRegisterGuiStateMachine)
+
+int qUnregisterGuiStateMachine()
+{
+ QStateMachinePrivate::handler = qt_guistatemachine_last_handler;
+ return 1;
+}
+Q_DESTRUCTOR_FUNCTION(qUnregisterGuiStateMachine)
+
+QT_END_NAMESPACE
diff --git a/src/gui/statemachine/qkeyeventtransition.cpp b/src/gui/statemachine/qkeyeventtransition.cpp
new file mode 100644
index 0000000..f803711
--- /dev/null
+++ b/src/gui/statemachine/qkeyeventtransition.cpp
@@ -0,0 +1,186 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qkeyeventtransition.h"
+#include "qbasickeyeventtransition_p.h"
+#include <QtCore/qwrappedevent.h>
+#include <private/qeventtransition_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QKeyEventTransition
+
+ \brief The QKeyEventTransition class provides a transition for key events.
+
+ \since 4.6
+ \ingroup statemachine
+
+ QKeyEventTransition is part of \l{The State Machine Framework}.
+
+ \sa QState::addTransition()
+*/
+
+/*!
+ \property QKeyEventTransition::key
+
+ \brief the key that this key event transition is associated with
+*/
+
+/*!
+ \property QKeyEventTransition::modifiersMask
+
+ \brief the keyboard modifiers mask that this key event transition checks for
+*/
+
+class QKeyEventTransitionPrivate : public QEventTransitionPrivate
+{
+ Q_DECLARE_PUBLIC(QKeyEventTransition)
+public:
+ QKeyEventTransitionPrivate() {}
+
+ QBasicKeyEventTransition *transition;
+};
+
+/*!
+ Constructs a new key event transition with the given \a sourceState.
+*/
+QKeyEventTransition::QKeyEventTransition(QState *sourceState)
+ : QEventTransition(*new QKeyEventTransitionPrivate, sourceState)
+{
+ Q_D(QKeyEventTransition);
+ d->transition = new QBasicKeyEventTransition();
+}
+
+/*!
+ Constructs a new key event transition for events of the given \a type for
+ the given \a object, with the given \a key and \a sourceState.
+*/
+QKeyEventTransition::QKeyEventTransition(QObject *object, QEvent::Type type,
+ int key, QState *sourceState)
+ : QEventTransition(*new QKeyEventTransitionPrivate, object, type, sourceState)
+{
+ Q_D(QKeyEventTransition);
+ d->transition = new QBasicKeyEventTransition(type, key);
+}
+
+/*!
+ Constructs a new key event transition for events of the given \a type for
+ the given \a object, with the given \a key, \a targets and \a sourceState.
+*/
+QKeyEventTransition::QKeyEventTransition(QObject *object, QEvent::Type type,
+ int key, const QList<QAbstractState*> &targets,
+ QState *sourceState)
+ : QEventTransition(*new QKeyEventTransitionPrivate, object, type, targets, sourceState)
+{
+ Q_D(QKeyEventTransition);
+ d->transition = new QBasicKeyEventTransition(type, key);
+}
+
+/*!
+ Destroys this key event transition.
+*/
+QKeyEventTransition::~QKeyEventTransition()
+{
+ Q_D(QKeyEventTransition);
+ delete d->transition;
+}
+
+/*!
+ Returns the key that this key event transition checks for.
+*/
+int QKeyEventTransition::key() const
+{
+ Q_D(const QKeyEventTransition);
+ return d->transition->key();
+}
+
+/*!
+ Sets the key that this key event transition will check for.
+*/
+void QKeyEventTransition::setKey(int key)
+{
+ Q_D(QKeyEventTransition);
+ d->transition->setKey(key);
+}
+
+/*!
+ Returns the keyboard modifiers mask that this key event transition checks
+ for.
+*/
+Qt::KeyboardModifiers QKeyEventTransition::modifiersMask() const
+{
+ Q_D(const QKeyEventTransition);
+ return d->transition->modifiersMask();
+}
+
+/*!
+ Sets the keyboard \a modifiers mask that this key event transition will
+ check for.
+*/
+void QKeyEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask)
+{
+ Q_D(QKeyEventTransition);
+ d->transition->setModifiersMask(modifiersMask);
+}
+
+/*!
+ \reimp
+*/
+bool QKeyEventTransition::eventTest(QEvent *event)
+{
+ Q_D(const QKeyEventTransition);
+ if (!QEventTransition::eventTest(event))
+ return false;
+ QWrappedEvent *we = static_cast<QWrappedEvent*>(event);
+ d->transition->setEventType(we->event()->type());
+ return QAbstractTransitionPrivate::get(d->transition)->callEventTest(we->event());
+}
+
+/*!
+ \reimp
+*/
+void QKeyEventTransition::onTransition(QEvent *event)
+{
+ QEventTransition::onTransition(event);
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/statemachine/qkeyeventtransition.h b/src/gui/statemachine/qkeyeventtransition.h
new file mode 100644
index 0000000..3c8295f
--- /dev/null
+++ b/src/gui/statemachine/qkeyeventtransition.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QKEYEVENTTRANSITION_H
+#define QKEYEVENTTRANSITION_H
+
+#include <QtCore/qeventtransition.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QKeyEventTransitionPrivate;
+class Q_GUI_EXPORT QKeyEventTransition : public QEventTransition
+{
+ Q_OBJECT
+ Q_PROPERTY(int key READ key WRITE setKey)
+ Q_PROPERTY(Qt::KeyboardModifiers modifiersMask READ modifiersMask WRITE setModifiersMask)
+public:
+ QKeyEventTransition(QState *sourceState = 0);
+ QKeyEventTransition(QObject *object, QEvent::Type type, int key,
+ QState *sourceState = 0);
+ QKeyEventTransition(QObject *object, QEvent::Type type, int key,
+ const QList<QAbstractState*> &targets,
+ QState *sourceState = 0);
+ ~QKeyEventTransition();
+
+ int key() const;
+ void setKey(int key);
+
+ Qt::KeyboardModifiers modifiersMask() const;
+ void setModifiersMask(Qt::KeyboardModifiers modifiers);
+
+protected:
+ void onTransition(QEvent *event);
+ bool eventTest(QEvent *event);
+
+private:
+ Q_DISABLE_COPY(QKeyEventTransition)
+ Q_DECLARE_PRIVATE(QKeyEventTransition)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/gui/statemachine/qmouseeventtransition.cpp b/src/gui/statemachine/qmouseeventtransition.cpp
new file mode 100644
index 0000000..e4e18eb
--- /dev/null
+++ b/src/gui/statemachine/qmouseeventtransition.cpp
@@ -0,0 +1,216 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmouseeventtransition.h"
+#include "qbasicmouseeventtransition_p.h"
+#include <QtCore/qwrappedevent.h>
+#include <QtGui/qpainterpath.h>
+#include <private/qeventtransition_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QMouseEventTransition
+
+ \brief The QMouseEventTransition class provides a transition for mouse events.
+
+ \since 4.6
+ \ingroup statemachine
+
+ QMouseEventTransition is part of \l{The State Machine Framework}.
+
+ \sa QState::addTransition()
+*/
+
+/*!
+ \property QMouseEventTransition::button
+
+ \brief the button that this mouse event transition is associated with
+*/
+
+/*!
+ \property QMouseEventTransition::modifiersMask
+
+ \brief the keyboard modifiers mask that this mouse event transition checks for
+*/
+
+class QMouseEventTransitionPrivate : public QEventTransitionPrivate
+{
+ Q_DECLARE_PUBLIC(QMouseEventTransition)
+public:
+ QMouseEventTransitionPrivate();
+
+ QBasicMouseEventTransition *transition;
+};
+
+QMouseEventTransitionPrivate::QMouseEventTransitionPrivate()
+{
+}
+
+/*!
+ Constructs a new mouse event transition with the given \a sourceState.
+*/
+QMouseEventTransition::QMouseEventTransition(QState *sourceState)
+ : QEventTransition(*new QMouseEventTransitionPrivate, sourceState)
+{
+ Q_D(QMouseEventTransition);
+ d->transition = new QBasicMouseEventTransition();
+}
+
+/*!
+ Constructs a new mouse event transition for events of the given \a type for
+ the given \a object, with the given \a button and \a sourceState.
+*/
+QMouseEventTransition::QMouseEventTransition(QObject *object, QEvent::Type type,
+ Qt::MouseButton button,
+ QState *sourceState)
+ : QEventTransition(*new QMouseEventTransitionPrivate, object, type, sourceState)
+{
+ Q_D(QMouseEventTransition);
+ d->transition = new QBasicMouseEventTransition(type, button);
+}
+
+/*!
+ Constructs a new mouse event transition for events of the given \a type for
+ the given \a object, with the given \a button, \a targets and \a
+ sourceState.
+*/
+QMouseEventTransition::QMouseEventTransition(QObject *object, QEvent::Type type,
+ Qt::MouseButton button,
+ const QList<QAbstractState*> &targets,
+ QState *sourceState)
+ : QEventTransition(*new QMouseEventTransitionPrivate, object, type, targets, sourceState)
+{
+ Q_D(QMouseEventTransition);
+ d->transition = new QBasicMouseEventTransition(type, button);
+}
+
+/*!
+ Destroys this mouse event transition.
+*/
+QMouseEventTransition::~QMouseEventTransition()
+{
+ Q_D(QMouseEventTransition);
+ delete d->transition;
+}
+
+/*!
+ Returns the button that this mouse event transition checks for.
+*/
+Qt::MouseButton QMouseEventTransition::button() const
+{
+ Q_D(const QMouseEventTransition);
+ return d->transition->button();
+}
+
+/*!
+ Sets the \a button that this mouse event transition will check for.
+*/
+void QMouseEventTransition::setButton(Qt::MouseButton button)
+{
+ Q_D(QMouseEventTransition);
+ d->transition->setButton(button);
+}
+
+/*!
+ Returns the keyboard modifiers mask that this mouse event transition checks
+ for.
+*/
+Qt::KeyboardModifiers QMouseEventTransition::modifiersMask() const
+{
+ Q_D(const QMouseEventTransition);
+ return d->transition->modifiersMask();
+}
+
+/*!
+ Sets the keyboard \a modifiers mask that this mouse event transition will
+ check for.
+*/
+void QMouseEventTransition::setModifiersMask(Qt::KeyboardModifiers modifiersMask)
+{
+ Q_D(QMouseEventTransition);
+ d->transition->setModifiersMask(modifiersMask);
+}
+
+/*!
+ Returns the path for this mouse event transition.
+*/
+QPainterPath QMouseEventTransition::path() const
+{
+ Q_D(const QMouseEventTransition);
+ return d->transition->path();
+}
+
+/*!
+ Sets the \a path for this mouse event transition.
+ If a valid path has been set, the transition will only trigger if the mouse
+ event position (QMouseEvent::pos()) is inside the path.
+
+ \sa QPainterPath::contains()
+*/
+void QMouseEventTransition::setPath(const QPainterPath &path)
+{
+ Q_D(QMouseEventTransition);
+ d->transition->setPath(path);
+}
+
+/*!
+ \reimp
+*/
+bool QMouseEventTransition::eventTest(QEvent *event)
+{
+ Q_D(const QMouseEventTransition);
+ if (!QEventTransition::eventTest(event))
+ return false;
+ QWrappedEvent *we = static_cast<QWrappedEvent*>(event);
+ d->transition->setEventType(we->event()->type());
+ return QAbstractTransitionPrivate::get(d->transition)->callEventTest(we->event());
+}
+
+/*!
+ \reimp
+*/
+void QMouseEventTransition::onTransition(QEvent *event)
+{
+ QEventTransition::onTransition(event);
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/statemachine/qmouseeventtransition.h b/src/gui/statemachine/qmouseeventtransition.h
new file mode 100644
index 0000000..3f5f3ac
--- /dev/null
+++ b/src/gui/statemachine/qmouseeventtransition.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMOUSEEVENTTRANSITION_H
+#define QMOUSEEVENTTRANSITION_H
+
+#include <QtCore/qeventtransition.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+class QMouseEventTransitionPrivate;
+class QPainterPath;
+class Q_GUI_EXPORT QMouseEventTransition : public QEventTransition
+{
+ Q_OBJECT
+ Q_PROPERTY(Qt::MouseButton button READ button WRITE setButton)
+ Q_PROPERTY(Qt::KeyboardModifiers modifiersMask READ modifiersMask WRITE setModifiersMask)
+public:
+ QMouseEventTransition(QState *sourceState = 0);
+ QMouseEventTransition(QObject *object, QEvent::Type type,
+ Qt::MouseButton button, QState *sourceState = 0);
+ QMouseEventTransition(QObject *object, QEvent::Type type,
+ Qt::MouseButton button,
+ const QList<QAbstractState*> &targets,
+ QState *sourceState = 0);
+ ~QMouseEventTransition();
+
+ Qt::MouseButton button() const;
+ void setButton(Qt::MouseButton button);
+
+ Qt::KeyboardModifiers modifiersMask() const;
+ void setModifiersMask(Qt::KeyboardModifiers modifiers);
+
+ QPainterPath path() const;
+ void setPath(const QPainterPath &path);
+
+protected:
+ void onTransition(QEvent *event);
+ bool eventTest(QEvent *event);
+
+private:
+ Q_DISABLE_COPY(QMouseEventTransition)
+ Q_DECLARE_PRIVATE(QMouseEventTransition)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/gui/statemachine/statemachine.pri b/src/gui/statemachine/statemachine.pri
new file mode 100644
index 0000000..2eb1e05
--- /dev/null
+++ b/src/gui/statemachine/statemachine.pri
@@ -0,0 +1,13 @@
+SOURCES += $$PWD/qguistatemachine.cpp
+!contains(DEFINES, QT_NO_STATEMACHINE_EVENTFILTER) {
+ HEADERS += \
+ $$PWD/qkeyeventtransition.h \
+ $$PWD/qmouseeventtransition.h \
+ $$PWD/qbasickeyeventtransition_p.h \
+ $$PWD/qbasicmouseeventtransition_p.h
+ SOURCES += \
+ $$PWD/qkeyeventtransition.cpp \
+ $$PWD/qmouseeventtransition.cpp \
+ $$PWD/qbasickeyeventtransition.cpp \
+ $$PWD/qbasicmouseeventtransition.cpp
+}
diff --git a/src/gui/styles/gtksymbols.cpp b/src/gui/styles/gtksymbols.cpp
index 99d7261..07cec93 100644
--- a/src/gui/styles/gtksymbols.cpp
+++ b/src/gui/styles/gtksymbols.cpp
@@ -633,31 +633,14 @@ GtkStyle* QGtk::gtkStyle(const QString &path)
return 0;
}
-#ifdef Q_OS_LINUX
-QT_END_NAMESPACE
-
-int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
-int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid);
-
-QT_BEGIN_NAMESPACE
-#endif
-
void QGtk::initGtkWidgets()
{
// From gtkmain.c
-
- uid_t ruid, rgid, euid, egid, suid, sgid;
-
-#ifdef Q_OS_LINUX
- if (getresuid (&ruid, &euid, &suid) != 0 || getresgid (&rgid, &egid, &sgid) != 0)
-#endif
- {
- suid = ruid = getuid ();
- sgid = rgid = getgid ();
- euid = geteuid ();
- egid = getegid ();
- }
- if (ruid != euid || ruid != suid || rgid != egid || rgid != sgid) {
+ uid_t ruid = getuid ();
+ uid_t rgid = getgid ();
+ uid_t euid = geteuid ();
+ uid_t egid = getegid ();
+ if (ruid != euid || rgid != egid) {
qWarning("\nThis process is currently running setuid or setgid.\nGTK+ does not allow this "
"therefore Qt cannot use the GTK+ integration.\nTry launching your app using \'gksudo\', "
"\'kdesudo\' or a similar tool.\n\n"
diff --git a/src/gui/styles/qcleanlooksstyle.cpp b/src/gui/styles/qcleanlooksstyle.cpp
index 3fb63f2..5c37794 100644
--- a/src/gui/styles/qcleanlooksstyle.cpp
+++ b/src/gui/styles/qcleanlooksstyle.cpp
@@ -1646,8 +1646,8 @@ void QCleanlooksStyle::drawControl(ControlElement element, const QStyleOption *o
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
QPixmap cache;
QString pixmapName = QStyleHelper::uniqueName(QLatin1String("headersection"), option, option->rect.size());
- pixmapName += QLatin1String("-") + QString::number(int(header->position));
- pixmapName += QLatin1String("-") + QString::number(int(header->orientation));
+ pixmapName += QString::number(- int(header->position));
+ pixmapName += QString::number(- int(header->orientation));
QRect r = option->rect;
QColor gradientStopColor;
QColor gradientStartColor = option->palette.button().color();
@@ -3858,7 +3858,7 @@ void QCleanlooksStyle::polish(QApplication *app)
dataDirs = QLatin1String("/usr/local/share/:/usr/share/");
dataDirs.prepend(QDir::homePath() + QLatin1String("/:"));
- d->iconDirs = dataDirs.split(QLatin1String(":"));
+ d->iconDirs = dataDirs.split(QLatin1Char(':'));
#endif
}
diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp
index 6972803..1285598 100644
--- a/src/gui/styles/qcommonstyle.cpp
+++ b/src/gui/styles/qcommonstyle.cpp
@@ -851,7 +851,7 @@ void QCommonStylePrivate::lookupIconTheme() const
dataDirs.prepend(QDir::homePath() + QLatin1String("/:"));
QStringList kdeDirs = QString::fromLocal8Bit(getenv("KDEDIRS")).split(QLatin1Char(':'));
foreach (const QString &dirName, kdeDirs)
- dataDirs.append(QLatin1String(":") + dirName + QLatin1String("/share"));
+ dataDirs.append(QLatin1Char(':') + dirName + QLatin1String("/share"));
iconDirs = dataDirs.split(QLatin1Char(':'));
QFileInfo fileInfo(QLatin1String("/usr/share/icons/default.kde"));
@@ -893,7 +893,7 @@ QIconTheme QCommonStylePrivate::parseIndexFile(const QString &themeName) const
parents = line.split(QLatin1Char(','));
}
- if (line.startsWith(QLatin1String("["))) {
+ if (line.startsWith(QLatin1Char('['))) {
line = line.trimmed();
line.chop(1);
QString dirName = line.right(line.length() - 1);
@@ -1695,7 +1695,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
pr.setHeight(pmSize.height() + 6);
- tr.adjust(0, pr.height(), 0, -3);
+ tr.adjust(0, pr.height() - 1, 0, -3);
pr.translate(shiftX, shiftY);
if (!hasArrow) {
drawItemPixmap(p, pr, Qt::AlignCenter, pm);
diff --git a/src/gui/styles/qgtkstyle.cpp b/src/gui/styles/qgtkstyle.cpp
index ca71da2..86653df 100644
--- a/src/gui/styles/qgtkstyle.cpp
+++ b/src/gui/styles/qgtkstyle.cpp
@@ -140,10 +140,7 @@ static const char * const dock_widget_restore_xpm[] =
class QGtkStyleFilter : public QObject
{
public:
- QGtkStyleFilter() {
- qApp->installEventFilter(this);
- }
-
+ QGtkStyleFilter() {}
private:
bool eventFilter(QObject *obj, QEvent *e);
};
@@ -167,7 +164,12 @@ class QGtkStylePrivate : public QCleanlooksStylePrivate
public:
QGtkStylePrivate()
: QCleanlooksStylePrivate()
- {}
+ {
+ QGtk::initGtkWidgets();
+ if (QGtk::isThemeAvailable())
+ qApp->installEventFilter(&filter);
+
+ }
QGtkStyleFilter filter;
};
@@ -243,7 +245,6 @@ static QString uniqueName(const QString &key, const QStyleOption *option, const
QGtkStyle::QGtkStyle()
: QCleanlooksStyle(*new QGtkStylePrivate)
{
- QGtk::initGtkWidgets();
}
/*!
diff --git a/src/gui/styles/qplastiquestyle.cpp b/src/gui/styles/qplastiquestyle.cpp
index 66464ff..91ad64e 100644
--- a/src/gui/styles/qplastiquestyle.cpp
+++ b/src/gui/styles/qplastiquestyle.cpp
@@ -2845,8 +2845,8 @@ void QPlastiqueStyle::drawControl(ControlElement element, const QStyleOption *op
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
QPixmap cache;
QString pixmapName = uniqueName(QLatin1String("headersection"), option, option->rect.size());
- pixmapName += QLatin1String("-") + QString::number(int(header->position));
- pixmapName += QLatin1String("-") + QString::number(int(header->orientation));
+ pixmapName += QString::number(- int(header->position));
+ pixmapName += QString::number(- int(header->orientation));
if (!UsePixmapCache || !QPixmapCache::find(pixmapName, cache)) {
cache = QPixmap(option->rect.size());
@@ -5460,6 +5460,11 @@ int QPlastiqueStyle::styleHint(StyleHint hint, const QStyleOption *option, const
case SH_Menu_SubMenuPopupDelay:
ret = 96; // from Plastik
break;
+#ifndef Q_OS_WIN
+ case SH_Menu_AllowActiveAndDisabled:
+ ret = false;
+ break;
+#endif
default:
ret = QWindowsStyle::styleHint(hint, option, widget, returnData);
break;
diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp
index 514f67b..3fab682 100644
--- a/src/gui/styles/qstyle.cpp
+++ b/src/gui/styles/qstyle.cpp
@@ -2439,7 +2439,7 @@ QDebug operator<<(QDebug debug, QStyle::State state)
qSort(states);
debug << states.join(QLatin1String(" | "));
- debug << ")";
+ debug << ')';
return debug;
}
#endif
diff --git a/src/gui/styles/qstyleoption.cpp b/src/gui/styles/qstyleoption.cpp
index 5b1bc61..e441101 100644
--- a/src/gui/styles/qstyleoption.cpp
+++ b/src/gui/styles/qstyleoption.cpp
@@ -5362,10 +5362,10 @@ QDebug operator<<(QDebug debug, const QStyleOption &option)
{
debug << "QStyleOption(";
debug << QStyleOption::OptionType(option.type);
- debug << "," << (option.direction == Qt::RightToLeft ? "RightToLeft" : "LeftToRight");
- debug << "," << option.state;
- debug << "," << option.rect;
- debug << ")";
+ debug << ',' << (option.direction == Qt::RightToLeft ? "RightToLeft" : "LeftToRight");
+ debug << ',' << option.state;
+ debug << ',' << option.rect;
+ debug << ')';
return debug;
}
#endif
diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp
index fdd51c3..1231561 100644
--- a/src/gui/styles/qstylesheetstyle.cpp
+++ b/src/gui/styles/qstylesheetstyle.cpp
@@ -1555,7 +1555,7 @@ QVector<QCss::StyleRule> QStyleSheetStyle::styleRules(const QWidget *w) const
if (widCacheIt == styleSheetCache->constEnd()) {
parser.init(wid->styleSheet());
if (!parser.parse(&ss)) {
- parser.init(QLatin1String("* {") + wid->styleSheet() + QLatin1String("}"));
+ parser.init(QLatin1String("* {") + wid->styleSheet() + QLatin1Char('}'));
if (!parser.parse(&ss))
qWarning("Could not parse stylesheet of widget %p", wid);
}
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp
index 38621c1..0494b72 100644
--- a/src/gui/text/qcssparser.cpp
+++ b/src/gui/text/qcssparser.cpp
@@ -1508,7 +1508,7 @@ QRect Declaration::rectValue() const
QStringList func = v.variant.toStringList();
if (func.count() != 2 || func.at(0).compare(QLatin1String("rect")) != 0)
return QRect();
- QStringList args = func[1].split(QLatin1String(" "), QString::SkipEmptyParts);
+ QStringList args = func[1].split(QLatin1Char(' '), QString::SkipEmptyParts);
if (args.count() != 4)
return QRect();
QRect rect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt());
@@ -2153,7 +2153,7 @@ void Parser::init(const QString &css, bool isFile)
if (isFile) {
QFile file(css);
if (file.open(QFile::ReadOnly)) {
- sourcePath = QFileInfo(styleSheet).absolutePath() + QLatin1String("/");
+ sourcePath = QFileInfo(styleSheet).absolutePath() + QLatin1Char('/');
QTextStream stream(&file);
styleSheet = stream.readAll();
} else {
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index c3fc9f5..d3020b0 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -792,7 +792,7 @@ static void initFontDef(const QtFontDesc &desc, const QFontDef &request, QFontDe
if (! desc.foundry->name.isEmpty() && desc.family->count > 1) {
fontDef->family += QString::fromLatin1(" [");
fontDef->family += desc.foundry->name;
- fontDef->family += QString::fromLatin1("]");
+ fontDef->family += QLatin1Char(']');
}
if (desc.style->smoothScalable)
@@ -1495,7 +1495,7 @@ QStringList QFontDatabase::families(WritingSystem writingSystem) const
if (!foundry.isEmpty()) {
str += QLatin1String(" [");
str += foundry;
- str += QLatin1String("]");
+ str += QLatin1Char(']');
}
flist.append(str);
}
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index d7a9c23..97cb1ed 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -915,7 +915,7 @@ void QFontEngine::loadKerningPairs(QFixed scalingFactor)
end:
qSort(kerning_pairs);
// for (int i = 0; i < kerning_pairs.count(); ++i)
-// qDebug() << "i" << i << "left_right" << hex << kerning_pairs.at(i).left_right;
+// qDebug() << 'i' << i << "left_right" << hex << kerning_pairs.at(i).left_right;
}
#else
diff --git a/src/gui/text/qfontengine_mac.mm b/src/gui/text/qfontengine_mac.mm
index 6b5bd0f..2e62086 100644
--- a/src/gui/text/qfontengine_mac.mm
+++ b/src/gui/text/qfontengine_mac.mm
@@ -553,7 +553,9 @@ QImage QCoreTextFontEngine::alphaMapForGlyph(glyph_t glyph)
8, im.bytesPerLine(), colorspace,
cgflags);
CGContextSetFontSize(ctx, fontDef.pixelSize);
- CGContextSetShouldAntialias(ctx, fontDef.pointSize > qt_antialiasing_threshold && !(fontDef.styleStrategy & QFont::NoAntialias));
+ CGContextSetShouldAntialias(ctx, fontDef.pointSize > qt_antialiasing_threshold
+ && !(fontDef.styleStrategy & QFont::NoAntialias));
+ CGContextSetShouldSmoothFonts(ctx, false);
CGAffineTransform oldTextMatrix = CGContextGetTextMatrix(ctx);
CGAffineTransform cgMatrix = CGAffineTransformMake(1, 0, 0, 1, 0, 0);
diff --git a/src/gui/text/qfontsubset.cpp b/src/gui/text/qfontsubset.cpp
index 0d1a884..e4d813d 100644
--- a/src/gui/text/qfontsubset.cpp
+++ b/src/gui/text/qfontsubset.cpp
@@ -333,17 +333,17 @@ QByteArray QFontSubset::glyphName(unsigned int glyph, const QVector<int> reverse
name[0] = 0;
}
if (name[0]) {
- s << "/" << name;
+ s << '/' << name;
} else
#endif
#if defined(Q_WS_X11)
if (fontEngine->type() == QFontEngine::XLFD) {
uint uc = static_cast<QFontEngineXLFD *>(fontEngine)->toUnicode(glyphIndex);
- s << "/" << glyphName(uc, false /* ### */);
+ s << '/' << glyphName(uc, false /* ### */);
} else
#endif
if (reverseMap[glyphIndex] && reverseMap[glyphIndex] < 0x10000) {
- s << "/" << glyphName(reverseMap[glyphIndex], false);
+ s << '/' << glyphName(reverseMap[glyphIndex], false);
} else {
s << "/gl" << (int)glyphIndex;
}
@@ -395,13 +395,13 @@ QByteArray QFontSubset::widthArray() const
int endnonlinear = startLinear ? startLinear : g;
// qDebug(" startLinear=%x endnonlinear=%x", startLinear,endnonlinear);
if (endnonlinear > start) {
- s << start << "[";
+ s << start << '[';
for (int i = start; i < endnonlinear; ++i)
s << (widths[i]*scale).toInt();
s << "]\n";
}
if (startLinear)
- s << startLinear << g - 1 << (widths[startLinear]*scale).toInt() << "\n";
+ s << startLinear << g - 1 << (widths[startLinear]*scale).toInt() << '\n';
}
s << "]\n";
}
@@ -488,14 +488,14 @@ QByteArray QFontSubset::createToUnicodeMap() const
int endnonlinear = startLinear ? startLinear : g;
// qDebug(" startLinear=%x endnonlinear=%x", startLinear,endnonlinear);
if (endnonlinear > start) {
- s << "<" << QPdf::toHex((ushort)start, buf) << "> <";
+ s << '<' << QPdf::toHex((ushort)start, buf) << "> <";
s << QPdf::toHex((ushort)(endnonlinear - 1), buf) << "> ";
if (endnonlinear == start + 1) {
- s << "<" << QPdf::toHex((ushort)reverseMap[start], buf) << ">\n";
+ s << '<' << QPdf::toHex((ushort)reverseMap[start], buf) << ">\n";
} else {
- s << "[";
+ s << '[';
for (int i = start; i < endnonlinear; ++i) {
- s << "<" << QPdf::toHex((ushort)reverseMap[i], buf) << "> ";
+ s << '<' << QPdf::toHex((ushort)reverseMap[i], buf) << "> ";
}
s << "]\n";
}
@@ -508,9 +508,9 @@ QByteArray QFontSubset::createToUnicodeMap() const
int uc_end = uc_start + len - 1;
if ((uc_end >> 8) != (uc_start >> 8))
len = 256 - (uc_start & 0xff);
- s << "<" << QPdf::toHex((ushort)startLinear, buf) << "> <";
+ s << '<' << QPdf::toHex((ushort)startLinear, buf) << "> <";
s << QPdf::toHex((ushort)(startLinear + len - 1), buf) << "> ";
- s << "<" << QPdf::toHex((ushort)reverseMap[startLinear], buf) << ">\n";
+ s << '<' << QPdf::toHex((ushort)reverseMap[startLinear], buf) << ">\n";
checkRanges(ts, ranges, nranges);
startLinear += len;
}
@@ -1655,7 +1655,7 @@ QByteArray QFontSubset::toType1() const
QByteArray id = QByteArray::number(object_id);
QByteArray psname = properties.postscriptName;
- psname.replace(" ", "");
+ psname.replace(' ', "");
standard_font = false;
@@ -1681,12 +1681,12 @@ QByteArray QFontSubset::toType1() const
#endif
s << "/F" << id << "-Base\n";
if (standard_font) {
- s << "/" << psname << " findfont\n"
+ s << '/' << psname << " findfont\n"
"0 dict copy dup /NumGlyphs 0 put dup /CMap 256 array put def\n";
} else {
s << "<<\n";
if(!psname.isEmpty())
- s << "/FontName /" << psname << "\n";
+ s << "/FontName /" << psname << '\n';
s << "/FontInfo <</FsType " << (int)fontEngine->fsType << ">>\n"
"/FontType 1\n"
"/PaintType 0\n"
@@ -1722,7 +1722,7 @@ QByteArray QFontSubset::type1AddedGlyphs() const
int nGlyphs = glyph_indices.size();
QByteArray id = QByteArray::number(object_id);
- s << "F" << id << "-Base [\n";
+ s << 'F' << id << "-Base [\n";
for (int i = downloaded_glyphs; i < nGlyphs; ++i) {
glyph_t g = glyph_indices.at(i);
QPainterPath path;
diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp
index f3d025c..0958b52 100644
--- a/src/gui/text/qtextcontrol.cpp
+++ b/src/gui/text/qtextcontrol.cpp
@@ -82,7 +82,7 @@
#include "private/qapplication_p.h"
#include "private/qshortcutmap_p.h"
#include <qkeysequence.h>
-#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1String("\t") + QString(QKeySequence(k)) : QString())
+#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1Char('\t') + QString(QKeySequence(k)) : QString())
#else
#define ACCEL_KEY(k) QString()
#endif
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index 873f846..23c3c20 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -2201,7 +2201,7 @@ void QTextHtmlExporter::emitTextLength(const char *attribute, const QTextLength
if (length.type() == QTextLength::PercentageLength)
html += QLatin1String("%\"");
else
- html += QLatin1String("\"");
+ html += QLatin1Char('\"');
}
void QTextHtmlExporter::emitAlignment(Qt::Alignment align)
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index faa06b7..a28c655 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -363,7 +363,7 @@ static bool bidiItemize(QTextEngine *engine, QScriptAnalysis *analysis, QBidiCon
#if (BIDI_DEBUG >= 2)
// qDebug() << "pos=" << current << " dir=" << directions[dir]
// << " current=" << directions[dirCurrent] << " last=" << directions[status.last]
-// << " eor=" << eor << "/" << directions[status.eor]
+// << " eor=" << eor << '/' << directions[status.eor]
// << " sor=" << sor << " lastStrong="
// << directions[status.lastStrong]
// << " level=" << (int)control.level << " override=" << (bool)control.override;
@@ -1099,6 +1099,16 @@ void QTextEngine::shapeTextWithCE(int item) const
}
#endif
+static inline void moveGlyphData(const QGlyphLayout &destination, const QGlyphLayout &source, int num)
+{
+ if (num > 0 && destination.glyphs != source.glyphs) {
+ memmove(destination.glyphs, source.glyphs, num * sizeof(HB_Glyph));
+ memmove(destination.attributes, source.attributes, num * sizeof(HB_GlyphAttributes));
+ memmove(destination.advances_x, source.advances_x, num * sizeof(HB_Fixed));
+ memmove(destination.offsets, source.offsets, num * sizeof(HB_FixedPoint));
+ }
+}
+
/// take the item from layoutData->items and
void QTextEngine::shapeTextWithHarfbuzz(int item) const
{
@@ -1189,7 +1199,7 @@ void QTextEngine::shapeTextWithHarfbuzz(int item) const
- int initial_glyph_pos = 0;
+ int remaining_glyphs = entire_shaper_item.num_glyphs;
int glyph_pos = 0;
// for each item shape using harfbuzz and store the results in our layoutData's glyphs array.
for (int k = 0; k < itemBoundaries.size(); k += 2) { // for the +2, see the comment at the definition of itemBoundaries
@@ -1209,7 +1219,7 @@ void QTextEngine::shapeTextWithHarfbuzz(int item) const
QFontEngine *actualFontEngine = font;
uint engineIdx = 0;
if (font->type() == QFontEngine::Multi) {
- engineIdx = uint(initialGlyphs.glyphs[itemBoundaries[k + 1]] >> 24);
+ engineIdx = uint(availableGlyphs(&si).glyphs[glyph_pos] >> 24);
actualFontEngine = static_cast<QFontEngineMulti *>(font)->engine(engineIdx);
}
@@ -1219,16 +1229,18 @@ void QTextEngine::shapeTextWithHarfbuzz(int item) const
shaper_item.glyphIndicesPresent = true;
+ remaining_glyphs -= shaper_item.initialGlyphCount;
+
do {
- ensureSpace(glyph_pos + shaper_item.num_glyphs);
- initialGlyphs = availableGlyphs(&si).mid(0, entire_shaper_item.num_glyphs);
- shaper_item.num_glyphs = layoutData->glyphLayout.numGlyphs - layoutData->used - glyph_pos;
+ ensureSpace(glyph_pos + shaper_item.num_glyphs + remaining_glyphs);
- const QGlyphLayout g = availableGlyphs(&si);
- shaper_item.glyphs = g.glyphs + glyph_pos;
- shaper_item.attributes = g.attributes + glyph_pos;
- shaper_item.advances = reinterpret_cast<HB_Fixed *>(g.advances_x + glyph_pos);
- shaper_item.offsets = reinterpret_cast<HB_FixedPoint *>(g.offsets + glyph_pos);
+ const QGlyphLayout g = availableGlyphs(&si).mid(glyph_pos);
+ moveGlyphData(g.mid(shaper_item.num_glyphs), g.mid(shaper_item.initialGlyphCount), remaining_glyphs);
+
+ shaper_item.glyphs = g.glyphs;
+ shaper_item.attributes = g.attributes;
+ shaper_item.advances = reinterpret_cast<HB_Fixed *>(g.advances_x);
+ shaper_item.offsets = reinterpret_cast<HB_FixedPoint *>(g.offsets);
if (shaper_item.glyphIndicesPresent) {
for (hb_uint32 i = 0; i < shaper_item.initialGlyphCount; ++i)
@@ -1241,18 +1253,18 @@ void QTextEngine::shapeTextWithHarfbuzz(int item) const
} while (!qShapeItem(&shaper_item)); // this does the actual shaping via harfbuzz.
QGlyphLayout g = availableGlyphs(&si).mid(glyph_pos, shaper_item.num_glyphs);
+ moveGlyphData(g.mid(shaper_item.num_glyphs), g.mid(shaper_item.initialGlyphCount), remaining_glyphs);
- for (hb_uint32 i = 0; i < shaper_item.item.length; ++i) {
+ for (hb_uint32 i = 0; i < shaper_item.num_glyphs; ++i)
g.glyphs[i] = g.glyphs[i] | (engineIdx << 24);
+
+ for (hb_uint32 i = 0; i < shaper_item.item.length; ++i)
shaper_item.log_clusters[i] += glyph_pos;
- }
if (kerningEnabled && !shaper_item.kerning_applied)
font->doKerning(&g, option.useDesignMetrics() ? QFlag(QTextEngine::DesignMetrics) : QFlag(0));
glyph_pos += shaper_item.num_glyphs;
-
- initial_glyph_pos += shaper_item.initialGlyphCount;
}
// qDebug(" -> item: script=%d num_glyphs=%d", shaper_item.script, shaper_item.num_glyphs);
diff --git a/src/gui/util/qcompleter.cpp b/src/gui/util/qcompleter.cpp
index faa4e7b..bed10dc 100644
--- a/src/gui/util/qcompleter.cpp
+++ b/src/gui/util/qcompleter.cpp
@@ -1664,7 +1664,7 @@ QStringList QCompleter::splitPath(const QString& path) const
doubleSlash.clear();
#endif
- QRegExp re(QLatin1String("[") + QRegExp::escape(sep) + QLatin1String("]"));
+ QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']'));
QStringList parts = pathCopy.split(re);
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
diff --git a/src/gui/util/qsystemtrayicon_win.cpp b/src/gui/util/qsystemtrayicon_win.cpp
index a6dcea6..c46c929 100644
--- a/src/gui/util/qsystemtrayicon_win.cpp
+++ b/src/gui/util/qsystemtrayicon_win.cpp
@@ -662,7 +662,7 @@ void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString
//message is limited to 255 chars + NULL
QString messageString;
if (message.isEmpty() && !title.isEmpty())
- messageString = QLatin1String(" "); //ensures that the message shows when only title is set
+ messageString = QLatin1Char(' '); //ensures that the message shows when only title is set
else
messageString = message.left(255) + QChar();
diff --git a/src/gui/widgets/qabstractspinbox.cpp b/src/gui/widgets/qabstractspinbox.cpp
index d640c70..09accc7 100644
--- a/src/gui/widgets/qabstractspinbox.cpp
+++ b/src/gui/widgets/qabstractspinbox.cpp
@@ -1781,8 +1781,8 @@ void QAbstractSpinBoxPrivate::interpret(EmitPolicy ep)
q->fixup(tmp);
QASBDEBUG() << "QAbstractSpinBoxPrivate::interpret() text '"
<< edit->displayText()
- << "' >> '" << copy << "'"
- << "' >> '" << tmp << "'";
+ << "' >> '" << copy << '\''
+ << "' >> '" << tmp << '\'';
doInterpret = tmp != copy && (q->validate(tmp, pos) == QValidator::Acceptable);
if (!doInterpret) {
diff --git a/src/gui/widgets/qcalendarwidget.cpp b/src/gui/widgets/qcalendarwidget.cpp
index 4436c04..8703139 100644
--- a/src/gui/widgets/qcalendarwidget.cpp
+++ b/src/gui/widgets/qcalendarwidget.cpp
@@ -198,7 +198,7 @@ QString QCalendarDayValidator::text() const
{
QString str;
if (m_day / 10 == 0)
- str += QLatin1String("0");
+ str += QLatin1Char('0');
str += QString::number(m_day);
return highlightString(str, m_pos);
}
@@ -210,7 +210,7 @@ QString QCalendarDayValidator::text(const QDate &date, int repeat) const
} else if (repeat == 2) {
QString str;
if (date.day() / 10 == 0)
- str += QLatin1String("0");
+ str += QLatin1Char('0');
return str + QString::number(date.day());
} else if (repeat == 3) {
return m_locale.dayName(date.dayOfWeek(), QLocale::ShortFormat);
@@ -316,7 +316,7 @@ QString QCalendarMonthValidator::text() const
{
QString str;
if (m_month / 10 == 0)
- str += QLatin1String("0");
+ str += QLatin1Char('0');
str += QString::number(m_month);
return highlightString(str, m_pos);
}
@@ -328,7 +328,7 @@ QString QCalendarMonthValidator::text(const QDate &date, int repeat) const
} else if (repeat == 2) {
QString str;
if (date.month() / 10 == 0)
- str += QLatin1String("0");
+ str += QLatin1Char('0');
return str + QString::number(date.month());
} else if (repeat == 3) {
return m_locale.standaloneMonthName(date.month(), QLocale::ShortFormat);
@@ -432,7 +432,7 @@ QString QCalendarYearValidator::text() const
int pow = 10;
for (int i = 0; i < 3; i++) {
if (m_year / pow == 0)
- str += QLatin1String("0");
+ str += QLatin1Char('0');
pow *= 10;
}
str += QString::number(m_year);
@@ -445,7 +445,7 @@ QString QCalendarYearValidator::text(const QDate &date, int repeat) const
QString str;
int year = date.year() % 100;
if (year / 10 == 0)
- str = QLatin1String("0");
+ str = QLatin1Char('0');
return str + QString::number(year);
}
return QString::number(date.year());
@@ -577,7 +577,7 @@ void QCalendarDateValidator::setFormat(const QString &format)
clear();
int pos = 0;
- const QLatin1String quote("'");
+ const QLatin1Char quote('\'');
bool quoting = false;
QString separator;
while (pos < format.size()) {
diff --git a/src/gui/widgets/qlabel.cpp b/src/gui/widgets/qlabel.cpp
index 016b7c1..1aef133 100644
--- a/src/gui/widgets/qlabel.cpp
+++ b/src/gui/widgets/qlabel.cpp
@@ -1170,7 +1170,7 @@ void QLabelPrivate::updateShortcut()
shortcutCursor.deleteChar(); // remove the ampersand
shortcutCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
} else {
- if (!text.contains(QLatin1String("&")))
+ if (!text.contains(QLatin1Char('&')))
return;
hasShortcut = true;
shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp
index 128f243..a4b0b4f 100644
--- a/src/gui/widgets/qlineedit.cpp
+++ b/src/gui/widgets/qlineedit.cpp
@@ -79,7 +79,7 @@
#include "private/qapplication_p.h"
#include "private/qshortcutmap_p.h"
#include "qkeysequence.h"
-#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1String("\t") + QString(QKeySequence(k)) : QString())
+#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1Char('\t') + QString(QKeySequence(k)) : QString())
#else
#define ACCEL_KEY(k) QString()
#endif
diff --git a/src/gui/widgets/qspinbox.cpp b/src/gui/widgets/qspinbox.cpp
index c691eaf..b7426f0 100644
--- a/src/gui/widgets/qspinbox.cpp
+++ b/src/gui/widgets/qspinbox.cpp
@@ -1030,7 +1030,7 @@ QVariant QSpinBoxPrivate::validateAndInterpret(QString &input, int &pos,
{
if (cachedText == input && !input.isEmpty()) {
state = cachedState;
- QSBDEBUG() << "cachedText was" << "'" << cachedText << "'" << "state was "
+ QSBDEBUG() << "cachedText was '" << cachedText << "' state was "
<< state << " and value was " << cachedValue;
return cachedValue;
@@ -1048,7 +1048,7 @@ QVariant QSpinBoxPrivate::validateAndInterpret(QString &input, int &pos,
|| (min >= 0 && copy == QLatin1String("+")))) {
state = QValidator::Intermediate;
QSBDEBUG() << __FILE__ << __LINE__<< "num is set to" << num;
- } else if (copy.startsWith(QLatin1String("-")) && min >= 0) {
+ } else if (copy.startsWith(QLatin1Char('-')) && min >= 0) {
state = QValidator::Invalid; // special-case -0 will be interpreted as 0 and thus not be invalid with a range from 0-100
} else {
bool ok = false;
@@ -1271,7 +1271,7 @@ QVariant QDoubleSpinBoxPrivate::validateAndInterpret(QString &input, int &pos,
{
if (cachedText == input && !input.isEmpty()) {
state = cachedState;
- QSBDEBUG() << "cachedText was" << "'" << cachedText << "'" << "state was "
+ QSBDEBUG() << "cachedText was '" << cachedText << "' state was "
<< state << " and value was " << cachedValue;
return cachedValue;
}
diff --git a/src/network/access/qhttp.cpp b/src/network/access/qhttp.cpp
index c761a02..49ce5a3 100644
--- a/src/network/access/qhttp.cpp
+++ b/src/network/access/qhttp.cpp
@@ -64,10 +64,10 @@
# include "qtimer.h"
#endif
-QT_BEGIN_NAMESPACE
-
#ifndef QT_NO_HTTP
+QT_BEGIN_NAMESPACE
+
class QHttpNormalRequest;
class QHttpRequest
{
diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp
index 0a34e2b..472bc4b 100644
--- a/src/network/kernel/qhostinfo_win.cpp
+++ b/src/network/kernel/qhostinfo_win.cpp
@@ -72,21 +72,6 @@ struct qt_addrinfo
qt_addrinfo *ai_next;
};
-// sockaddr_in6 size changed between old and new SDK
-// Only the new version is the correct one, so always
-// use this structure.
-struct qt_in6_addr {
- uchar qt_s6_addr[16];
-};
-
-struct qt_sockaddr_in6 {
- short sin6_family; /* AF_INET6 */
- u_short sin6_port; /* Transport level port number */
- u_long sin6_flowinfo; /* IPv6 flow information */
- struct qt_in6_addr sin6_addr; /* IPv6 address */
- u_long sin6_scope_id; /* set of interfaces for a scope */
-};
-
//###
#define QT_SOCKLEN_T int
#ifndef NI_MAXHOST // already defined to 1025 in ws2tcpip.h?
diff --git a/src/network/kernel/qnetworkproxy.cpp b/src/network/kernel/qnetworkproxy.cpp
index 62bdfc7..fd3a85a 100644
--- a/src/network/kernel/qnetworkproxy.cpp
+++ b/src/network/kernel/qnetworkproxy.cpp
@@ -1258,6 +1258,6 @@ QList<QNetworkProxy> QNetworkProxyFactory::proxyForQuery(const QNetworkProxyQuer
return globalNetworkProxy()->proxyForQuery(query);
}
-#endif // QT_NO_NETWORKPROXY
-
QT_END_NAMESPACE
+
+#endif // QT_NO_NETWORKPROXY
diff --git a/src/network/kernel/qurlinfo.cpp b/src/network/kernel/qurlinfo.cpp
index 255c9ea..d90c480 100644
--- a/src/network/kernel/qurlinfo.cpp
+++ b/src/network/kernel/qurlinfo.cpp
@@ -726,6 +726,6 @@ bool QUrlInfo::isValid() const
return d != 0;
}
-#endif // QT_NO_URLINFO
-
QT_END_NAMESPACE
+
+#endif // QT_NO_URLINFO
diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp
index 540c443..5a2a746 100644
--- a/src/network/socket/qhttpsocketengine.cpp
+++ b/src/network/socket/qhttpsocketengine.cpp
@@ -768,6 +768,6 @@ QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(int, QObject
return 0;
}
-#endif
-
QT_END_NAMESPACE
+
+#endif
diff --git a/src/network/socket/qnativesocketengine_p.h b/src/network/socket/qnativesocketengine_p.h
index 3366f2d..eb031d3 100644
--- a/src/network/socket/qnativesocketengine_p.h
+++ b/src/network/socket/qnativesocketengine_p.h
@@ -56,7 +56,9 @@
#include "QtNetwork/qhostaddress.h"
#include "private/qabstractsocketengine_p.h"
#ifndef Q_OS_WIN
-#include "qplatformdefs.h"
+# include "qplatformdefs.h"
+#else
+# include <winsock2.h>
#endif
QT_BEGIN_NAMESPACE
@@ -90,6 +92,39 @@ static inline int qt_socket_socket(int domain, int type, int protocol)
#endif
+// Use our own defines and structs which we know are correct
+# define QT_SS_MAXSIZE 128
+# define QT_SS_ALIGNSIZE (sizeof(qint64))
+# define QT_SS_PAD1SIZE (QT_SS_ALIGNSIZE - sizeof (short))
+# define QT_SS_PAD2SIZE (QT_SS_MAXSIZE - (sizeof (short) + QT_SS_PAD1SIZE + QT_SS_ALIGNSIZE))
+struct qt_sockaddr_storage {
+ short ss_family;
+ char __ss_pad1[QT_SS_PAD1SIZE];
+ qint64 __ss_align;
+ char __ss_pad2[QT_SS_PAD2SIZE];
+};
+
+// sockaddr_in6 size changed between old and new SDK
+// Only the new version is the correct one, so always
+// use this structure.
+struct qt_in6_addr {
+ quint8 qt_s6_addr[16];
+};
+struct qt_sockaddr_in6 {
+ short sin6_family; /* AF_INET6 */
+ quint16 sin6_port; /* Transport level port number */
+ quint32 sin6_flowinfo; /* IPv6 flow information */
+ struct qt_in6_addr sin6_addr; /* IPv6 address */
+ quint32 sin6_scope_id; /* set of interfaces for a scope */
+};
+
+union qt_sockaddr {
+ sockaddr a;
+ sockaddr_in a4;
+ qt_sockaddr_in6 a6;
+ qt_sockaddr_storage storage;
+};
+
class QNativeSocketEnginePrivate;
class Q_AUTOTEST_EXPORT QNativeSocketEngine : public QAbstractSocketEngine
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index cc372a6..75b5a64 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -114,36 +114,34 @@ static void qt_ignore_sigpipe()
Extracts the port and address from a sockaddr, and stores them in
\a port and \a addr if they are non-null.
*/
-static inline void qt_socket_getPortAndAddress(struct sockaddr *sa, quint16 *port, QHostAddress *addr)
+static inline void qt_socket_getPortAndAddress(const qt_sockaddr *s, quint16 *port, QHostAddress *addr)
{
#if !defined(QT_NO_IPV6)
- if (sa->sa_family == AF_INET6) {
- struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
+ if (s->a.sa_family == AF_INET6) {
Q_IPV6ADDR tmp;
- memcpy(&tmp, &sa6->sin6_addr.s6_addr, sizeof(tmp));
+ memcpy(&tmp, &s->a6.sin6_addr, sizeof(tmp));
if (addr) {
QHostAddress tmpAddress;
tmpAddress.setAddress(tmp);
*addr = tmpAddress;
#ifndef QT_NO_IPV6IFNAME
char scopeid[IFNAMSIZ];
- if (::if_indextoname(sa6->sin6_scope_id, scopeid) > 0) {
+ if (::if_indextoname(s->a6.sin6_scope_id, scopeid) > 0) {
addr->setScopeId(QLatin1String(scopeid));
} else
#endif
- addr->setScopeId(QString::number(sa6->sin6_scope_id));
+ addr->setScopeId(QString::number(s->a6.sin6_scope_id));
}
if (port)
- *port = ntohs(sa6->sin6_port);
+ *port = ntohs(s->a6.sin6_port);
return;
}
#endif
- struct sockaddr_in *sa4 = (struct sockaddr_in *)sa;
if (port)
- *port = ntohs(sa4->sin_port);
+ *port = ntohs(s->a4.sin_port);
if (addr) {
QHostAddress tmpAddress;
- tmpAddress.setAddress(ntohl(sa4->sin_addr.s_addr));
+ tmpAddress.setAddress(ntohl(s->a4.sin_addr.s_addr));
*addr = tmpAddress;
}
}
@@ -521,26 +519,16 @@ qint64 QNativeSocketEnginePrivate::nativeBytesAvailable() const
bool QNativeSocketEnginePrivate::nativeHasPendingDatagrams() const
{
// Create a sockaddr struct and reset its port number.
-#if !defined(QT_NO_IPV6)
- struct sockaddr_storage storage;
- sockaddr_in6 *storagePtrIPv6 = reinterpret_cast<sockaddr_in6 *>(&storage);
- storagePtrIPv6->sin6_port = 0;
-#else
- struct sockaddr storage;
-#endif
- sockaddr *storagePtr = reinterpret_cast<sockaddr *>(&storage);
- storagePtr->sa_family = 0;
-
- sockaddr_in *storagePtrIPv4 = reinterpret_cast<sockaddr_in *>(&storage);
- storagePtrIPv4->sin_port = 0;
+ qt_sockaddr storage;
QT_SOCKLEN_T storageSize = sizeof(storage);
+ memset(&storage, 0, storageSize);
// Peek 0 bytes into the next message. The size of the message may
// well be 0, so we can't check recvfrom's return value.
ssize_t readBytes;
do {
char c;
- readBytes = ::recvfrom(socketDescriptor, &c, 1, MSG_PEEK, storagePtr, &storageSize);
+ readBytes = ::recvfrom(socketDescriptor, &c, 1, MSG_PEEK, &storage.a, &storageSize);
} while (readBytes == -1 && errno == EINTR);
// If there's no error, or if our buffer was too small, there must be a
@@ -583,11 +571,7 @@ qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const
qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxSize,
QHostAddress *address, quint16 *port)
{
-#if !defined(QT_NO_IPV6)
- struct sockaddr_storage aa;
-#else
- struct sockaddr_in aa;
-#endif
+ qt_sockaddr aa;
memset(&aa, 0, sizeof(aa));
QT_SOCKLEN_T sz;
sz = sizeof(aa);
@@ -596,13 +580,13 @@ qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxS
do {
char c;
recvFromResult = ::recvfrom(socketDescriptor, maxSize ? data : &c, maxSize ? maxSize : 1,
- 0, (struct sockaddr *)&aa, &sz);
+ 0, &aa.a, &sz);
} while (recvFromResult == -1 && errno == EINTR);
if (recvFromResult == -1) {
setError(QAbstractSocket::NetworkError, ReceiveDatagramErrorString);
} else if (port || address) {
- qt_socket_getPortAndAddress((struct sockaddr *) &aa, port, address);
+ qt_socket_getPortAndAddress(&aa, port, address);
}
#if defined (QNATIVESOCKETENGINE_DEBUG)
@@ -682,21 +666,16 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters()
if (socketDescriptor == -1)
return false;
-#if !defined(QT_NO_IPV6)
- struct sockaddr_storage sa;
-#else
- struct sockaddr_in sa;
-#endif
- struct sockaddr *sockAddrPtr = (struct sockaddr *) &sa;
+ qt_sockaddr sa;
QT_SOCKLEN_T sockAddrSize = sizeof(sa);
// Determine local address
memset(&sa, 0, sizeof(sa));
- if (::getsockname(socketDescriptor, sockAddrPtr, &sockAddrSize) == 0) {
- qt_socket_getPortAndAddress(sockAddrPtr, &localPort, &localAddress);
+ if (::getsockname(socketDescriptor, &sa.a, &sockAddrSize) == 0) {
+ qt_socket_getPortAndAddress(&sa, &localPort, &localAddress);
// Determine protocol family
- switch (sockAddrPtr->sa_family) {
+ switch (sa.a.sa_family) {
case AF_INET:
socketProtocol = QAbstractSocket::IPv4Protocol;
break;
@@ -716,8 +695,8 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters()
}
// Determine the remote address
- if (!::getpeername(socketDescriptor, sockAddrPtr, &sockAddrSize))
- qt_socket_getPortAndAddress(sockAddrPtr, &peerPort, &peerAddress);
+ if (!::getpeername(socketDescriptor, &sa.a, &sockAddrSize))
+ qt_socket_getPortAndAddress(&sa, &peerPort, &peerAddress);
// Determine the socket type (UDP/TCP)
int value = 0;
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index d140be2..b08d7b0 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -149,41 +149,6 @@ static QByteArray qt_prettyDebug(const char *data, int len, int maxLength)
#endif
-#if !defined (QT_NO_IPV6)
-
-// Use our own defines and structs which we know are correct
-# define QT_SS_MAXSIZE 128
-# define QT_SS_ALIGNSIZE (sizeof(__int64))
-# define QT_SS_PAD1SIZE (QT_SS_ALIGNSIZE - sizeof (short))
-# define QT_SS_PAD2SIZE (QT_SS_MAXSIZE - (sizeof (short) + QT_SS_PAD1SIZE + QT_SS_ALIGNSIZE))
-struct qt_sockaddr_storage {
- short ss_family;
- char __ss_pad1[QT_SS_PAD1SIZE];
- __int64 __ss_align;
- char __ss_pad2[QT_SS_PAD2SIZE];
-};
-
-// sockaddr_in6 size changed between old and new SDK
-// Only the new version is the correct one, so always
-// use this structure.
-struct qt_in6_addr {
- u_char qt_s6_addr[16];
-};
-typedef struct {
- short sin6_family; /* AF_INET6 */
- u_short sin6_port; /* Transport level port number */
- u_long sin6_flowinfo; /* IPv6 flow information */
- struct qt_in6_addr sin6_addr; /* IPv6 address */
- u_long sin6_scope_id; /* set of interfaces for a scope */
-} qt_sockaddr_in6;
-
-#else
-
-typedef void * qt_sockaddr_in6 ;
-
-
-#endif
-
#ifndef AF_INET6
#define AF_INET6 23 /* Internetwork Version 6 */
#endif
diff --git a/src/opengl/gl2paintengineex/glgc_shader_source.h b/src/opengl/gl2paintengineex/glgc_shader_source.h
deleted file mode 100644
index 5b9d28b..0000000
--- a/src/opengl/gl2paintengineex/glgc_shader_source.h
+++ /dev/null
@@ -1,289 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtOpenGL module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef GLGC_SHADER_SOURCE_H
-#define GLGC_SHADER_SOURCE_H
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(OpenGL)
-
-static const char* qglslImageVertexShader = "\
- attribute highp vec4 inputVertex; \
- attribute lowp vec2 textureCoord; \
- uniform highp mat4 pmvMatrix; \
- varying lowp vec2 fragTextureCoord; \
- void main(void) \
- {\
- gl_Position = pmvMatrix * inputVertex;\
- fragTextureCoord = textureCoord; \
- }";
-
-static const char* qglslImageFragmentShader = "\
- varying lowp vec2 fragTextureCoord;\
- uniform sampler2D textureSampler;\
- uniform lowp float opacity; \
- void main(void) \
- {\
- gl_FragColor = texture2D(textureSampler, fragTextureCoord) * opacity; \
- }";
-
-static const char* qglslTextFragmentShader = "\
- varying lowp vec2 fragTextureCoord;\
- uniform mediump vec4 fragmentColor;\
- uniform sampler2D textureSampler;\
- void main(void) \
- {\
- highp vec4 tex = texture2D(textureSampler, fragTextureCoord); \
- tex = fragmentColor * tex.r; \
- gl_FragColor = tex; \
- }";
-
-static const char* qglslDefaultVertexShader = "\
- attribute highp vec4 inputVertex;\
- uniform highp mat4 pmvMatrix;\
- void main(void)\
- {\
- gl_Position = pmvMatrix * inputVertex;\
- }";
-
-static const char* qglslSimpleFragmentShader = "\
- void main (void)\
- {\
- gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\
- }";
-
-
-/**** FRAGMENT SHADER MAIN FUNCTIONS ****/
-// NOTE: Currently, the engine assumes brushes return colors already in pre-multiplied
-// format. However, this may change if we add support for non-premultiplied
-
-static const char* qglslNoOpacityFragmentShaderMain = "\n\
- mediump vec4 brush();\
- void main (void)\
- {\
- gl_FragColor = brush();\
- }\n";
-
-static const char* qglslFragmentShaderMain = "\n\
- mediump vec4 brush();\
- uniform lowp float opacity; \
- void main (void)\
- {\
- gl_FragColor = brush() * opacity;\
- }\n";
-
-
-
-/**** BRUSH SHADERS ****/
-
-// This should never actually be used
-static const char* qglslNoBrushFragmentShader = "\n\
- mediump vec4 brush() { \
- discard; \
- return vec4(1.0, 0.8, 0.8, 1.0);\
- }\n";
-
-// Solid Fill Brush
-static const char* qglslSolidBrushFragmentShader = "\n\
- uniform mediump vec4 fragmentColor; \
- mediump vec4 brush() { \
- return fragmentColor;\
- }\n";
-
-// Texture Brush
-static const char* qglslTextureBrushVertexShader = "\
- attribute highp vec4 inputVertex; \
- uniform highp mat4 pmvMatrix; \
- uniform mediump vec2 halfViewportSize; \
- uniform mediump vec2 invertedTextureSize; \
- uniform mediump mat3 brushTransform; \
- varying mediump vec2 texCoords; \
- void main(void) { \
- gl_Position = pmvMatrix * inputVertex;\
- gl_Position.xy = gl_Position.xy / gl_Position.w; \
- mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
- mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
- mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
- gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
- gl_Position.w = invertedHTexCoordsZ; \
- texCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \
- texCoords.y = -texCoords.y; \
- }";
-
-static const char* qglslTextureBrushFragmentShader = "\n\
- varying mediump vec2 texCoords;\
- uniform sampler2D brushTexture;\
- mediump vec4 brush() { \
- return texture2D(brushTexture, texCoords); \
- }\n";
-
-
-// Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125
-static const char* qglslPatternBrushVertexShader = "\
- attribute highp vec4 inputVertex; \
- uniform highp mat4 pmvMatrix; \
- uniform mediump vec2 halfViewportSize; \
- uniform mediump vec2 invertedTextureSize; \
- uniform mediump mat3 brushTransform; \
- varying mediump vec2 texCoords; \
- void main(void) { \
- gl_Position = pmvMatrix * inputVertex;\
- gl_Position.xy = gl_Position.xy / gl_Position.w; \
- mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
- mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
- mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
- gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
- gl_Position.w = invertedHTexCoordsZ; \
- texCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \
- texCoords.y = -texCoords.y; \
- }";
-
-static const char* qglslPatternBrushFragmentShader = "\n\
- uniform sampler2D brushTexture;\
- uniform lowp vec4 patternColor; \
- varying mediump vec2 texCoords;\
- mediump vec4 brush() { \
- return patternColor * texture2D(brushTexture, texCoords).r; \
- }\n";
-
-
-// Linear Gradient Brush
-static const char* qglslLinearGradientBrushVertexShader = "\
- attribute highp vec4 inputVertex; \
- uniform highp mat4 pmvMatrix; \
- uniform mediump vec2 halfViewportSize; \
- uniform highp vec3 linearData; \
- uniform mediump mat3 brushTransform; \
- varying mediump float index ; \
- void main() { \
- gl_Position = pmvMatrix * inputVertex;\
- gl_Position.xy = gl_Position.xy / gl_Position.w; \
- mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
- mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
- mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
- gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
- gl_Position.w = invertedHTexCoordsZ; \
- index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \
- }";
-
-static const char* qglslLinearGradientBrushFragmentShader = "\n\
- uniform sampler2D brushTexture; \
- varying mediump float index; \
- mediump vec4 brush() { \
- mediump vec2 val = vec2(index, 0.5); \
- return texture2D(brushTexture, val); \
- }\n";
-
-
-static const char* qglslRadialGradientBrushVertexShader = "\
- attribute highp vec4 inputVertex;\
- uniform highp mat4 pmvMatrix;\
- uniform mediump vec2 halfViewportSize; \
- uniform highp mat3 brushTransform; \
- uniform highp vec2 fmp; \
- varying highp float b; \
- varying highp vec2 A; \
- void main(void) \
- {\
- gl_Position = pmvMatrix * inputVertex;\
- gl_Position.xy = gl_Position.xy / gl_Position.w; \
- mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
- mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
- mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
- gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
- gl_Position.w = invertedHTexCoordsZ; \
- A = hTexCoords.xy * invertedHTexCoordsZ; \
- b = 2.0 * fmp * (A.x + A.y); \
-\
- }";
-
-static const char* qglslRadialGradientBrushFragmentShader = "\n\
- uniform sampler2D brushTexture; \
- uniform highp float fmp2_m_radius2; \
- uniform highp float inverse_2_fmp2_m_radius2; \
- varying highp float b; \
- varying highp vec2 A; \
-\
- mediump vec4 brush() { \
- highp float c = -dot(A, A); \
- highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \
- return texture2D(brushTexture, val); \
- }\n";
-
-static const char* qglslConicalGradientBrushVertexShader = "\
- attribute highp vec4 inputVertex;\
- uniform highp mat4 pmvMatrix;\
- uniform mediump vec2 halfViewportSize; \
- uniform highp mat3 brushTransform; \
- varying highp vec2 A; \
- void main(void)\
- {\
- gl_Position = pmvMatrix * inputVertex;\
- gl_Position.xy = gl_Position.xy / gl_Position.w; \
- mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
- mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
- mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
- gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
- gl_Position.w = invertedHTexCoordsZ; \
- A = hTexCoords.xy * invertedHTexCoordsZ; \
- }";
-
-static const char* qglslConicalGradientBrushFragmentShader = "\n\
- #define INVERSE_2PI 0.1591549430918953358 \n\
- uniform sampler2D brushTexture; \
- uniform mediump float angle; \
- varying highp vec2 A; \
- mediump vec4 brush() { \
- if (abs(A.y) == abs(A.x)) \
- A.y += 0.002; \
- highp float t = (atan2(-A.y, A.x) + angle) * INVERSE_2PI; \
- return texture2D(brushTexture, vec2(t - floor(t), 0.5)); \
- }\n";
-
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // GLGC_SHADER_SOURCE_H
diff --git a/src/opengl/gl2paintengineex/qgl2pexvertexarray.cpp b/src/opengl/gl2paintengineex/qgl2pexvertexarray.cpp
index 0352d39..f237847 100644
--- a/src/opengl/gl2paintengineex/qgl2pexvertexarray.cpp
+++ b/src/opengl/gl2paintengineex/qgl2pexvertexarray.cpp
@@ -59,6 +59,12 @@ QGLRect QGL2PEXVertexArray::boundingRect() const
return QGLRect(minX, minY, maxX, maxY);
}
+void QGL2PEXVertexArray::addRect(const QRectF &rect)
+{
+ vertexArray << rect.topLeft() << rect.topRight() << rect.bottomRight()
+ << rect.bottomRight() << rect.bottomLeft() << rect.topLeft();
+}
+
void QGL2PEXVertexArray::addPath(const QVectorPath &path, GLfloat curveInverseScale)
{
const QPointF* const points = reinterpret_cast<const QPointF*>(path.points());
diff --git a/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h b/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h
index c205022..a83f13e 100644
--- a/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h
+++ b/src/opengl/gl2paintengineex/qgl2pexvertexarray_p.h
@@ -62,7 +62,7 @@ public:
QGLPoint(GLfloat new_x, GLfloat new_y) :
x(new_x), y(new_y) {};
- QGLPoint(QPointF p) :
+ QGLPoint(const QPointF &p) :
x(p.x()), y(p.y()) {};
QGLPoint(const QPointF* p) :
@@ -77,7 +77,7 @@ public:
struct QGLRect
{
- QGLRect(QRectF r)
+ QGLRect(const QRectF &r)
: left(r.left()), top(r.top()), right(r.right()), bottom(r.bottom()) {}
QGLRect(GLfloat l, GLfloat t, GLfloat r, GLfloat b)
@@ -98,6 +98,7 @@ public:
maxX(-2e10), maxY(-2e10), minX(2e10), minY(2e10),
boundingRectDirty(true) {}
+ void addRect(const QRectF &rect);
void addPath(const QVectorPath &path, GLfloat curveInverseScale);
void clear();
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
new file mode 100644
index 0000000..514aac0
--- /dev/null
+++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
@@ -0,0 +1,465 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qglengineshadermanager_p.h"
+#include "qglengineshadersource_p.h"
+
+#if defined(QT_DEBUG)
+#include <QMetaEnum>
+#endif
+
+
+const char* QGLEngineShaderManager::qglEngineShaderSourceCode[] = {
+ 0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0
+};
+
+QGLEngineShaderManager::QGLEngineShaderManager(QGLContext* context)
+ : ctx(context),
+ shaderProgNeedsChanging(true),
+ srcPixelType(Qt::NoBrush),
+ useGlobalOpacity(false),
+ maskType(NoMask),
+ useTextureCoords(false),
+ compositionMode(QPainter::CompositionMode_SourceOver),
+ simpleShaderProg(0),
+ currentShaderProg(0)
+{
+ memset(compiledShaders, 0, sizeof(compiledShaders));
+
+/*
+ Rather than having the shader source array statically initialised, it is initialised
+ here instead. This is to allow new shader names to be inserted or existing names moved
+ around without having to change the order of the glsl strings. It is hoped this will
+ make future hard-to-find runtime bugs more obvious and generally give more solid code.
+*/
+ static bool qglEngineShaderSourceCodePopulated = false;
+ if (!qglEngineShaderSourceCodePopulated) {
+
+ const char** code = qglEngineShaderSourceCode; // shortcut
+
+ code[MainVertexShader] = qglslMainVertexShader;
+ code[MainWithTexCoordsVertexShader] = qglslMainWithTexCoordsVertexShader;
+
+ code[PositionOnlyVertexShader] = qglslPositionOnlyVertexShader;
+ code[PositionWithPatternBrushVertexShader] = qglslPositionWithPatternBrushVertexShader;
+ code[PositionWithLinearGradientBrushVertexShader] = qglslPositionWithLinearGradientBrushVertexShader;
+ code[PositionWithConicalGradientBrushVertexShader] = qglslPositionWithConicalGradientBrushVertexShader;
+ code[PositionWithRadialGradientBrushVertexShader] = qglslPositionWithRadialGradientBrushVertexShader;
+ code[PositionWithTextureBrushVertexShader] = qglslPositionWithTextureBrushVertexShader;
+ code[AffinePositionWithPatternBrushVertexShader] = qglslAffinePositionWithPatternBrushVertexShader;
+ code[AffinePositionWithLinearGradientBrushVertexShader] = qglslAffinePositionWithLinearGradientBrushVertexShader;
+ code[AffinePositionWithConicalGradientBrushVertexShader] = qglslAffinePositionWithConicalGradientBrushVertexShader;
+ code[AffinePositionWithRadialGradientBrushVertexShader] = qglslAffinePositionWithRadialGradientBrushVertexShader;
+ code[AffinePositionWithTextureBrushVertexShader] = qglslAffinePositionWithTextureBrushVertexShader;
+
+ code[MainFragmentShader_CMO] = qglslMainFragmentShader_CMO;
+ code[MainFragmentShader_CM] = qglslMainFragmentShader_CM;
+ code[MainFragmentShader_MO] = qglslMainFragmentShader_MO;
+ code[MainFragmentShader_M] = qglslMainFragmentShader_M;
+ code[MainFragmentShader_CO] = qglslMainFragmentShader_CO;
+ code[MainFragmentShader_C] = qglslMainFragmentShader_C;
+ code[MainFragmentShader_O] = qglslMainFragmentShader_O;
+ code[MainFragmentShader] = qglslMainFragmentShader;
+
+ code[ImageSrcFragmentShader] = qglslImageSrcFragmentShader;
+ code[NonPremultipliedImageSrcFragmentShader] = qglslNonPremultipliedImageSrcFragmentShader;
+ code[SolidBrushSrcFragmentShader] = qglslSolidBrushSrcFragmentShader;
+ code[TextureBrushSrcFragmentShader] = qglslTextureBrushSrcFragmentShader;
+ code[PatternBrushSrcFragmentShader] = qglslPatternBrushSrcFragmentShader;
+ code[LinearGradientBrushSrcFragmentShader] = qglslLinearGradientBrushSrcFragmentShader;
+ code[RadialGradientBrushSrcFragmentShader] = qglslRadialGradientBrushSrcFragmentShader;
+ code[ConicalGradientBrushSrcFragmentShader] = qglslConicalGradientBrushSrcFragmentShader;
+ code[ShockingPinkSrcFragmentShader] = qglslShockingPinkSrcFragmentShader;
+
+ code[MaskFragmentShader] = qglslMaskFragmentShader;
+ code[RgbMaskFragmentShader] = ""; //###
+ code[RgbMaskWithGammaFragmentShader] = ""; //###
+
+ code[MultiplyCompositionModeFragmentShader] = ""; //###
+ code[ScreenCompositionModeFragmentShader] = ""; //###
+ code[OverlayCompositionModeFragmentShader] = ""; //###
+ code[DarkenCompositionModeFragmentShader] = ""; //###
+ code[LightenCompositionModeFragmentShader] = ""; //###
+ code[ColorDodgeCompositionModeFragmentShader] = ""; //###
+ code[ColorBurnCompositionModeFragmentShader] = ""; //###
+ code[HardLightCompositionModeFragmentShader] = ""; //###
+ code[SoftLightCompositionModeFragmentShader] = ""; //###
+ code[DifferenceCompositionModeFragmentShader] = ""; //###
+ code[ExclusionCompositionModeFragmentShader] = ""; //###
+
+#if defined(QT_DEBUG)
+ // Check that all the elements have been filled:
+ for (int i = 0; i < TotalShaderCount; ++i) {
+ if (qglEngineShaderSourceCode[i] == 0) {
+ int enumIndex = staticMetaObject.indexOfEnumerator("ShaderName");
+ QMetaEnum m = staticMetaObject.enumerator(enumIndex);
+
+ qCritical() << "qglEngineShaderSourceCode: Source for" << m.valueToKey(i)
+ << "(shader" << i << ") missing!";
+ }
+ }
+#endif
+ qglEngineShaderSourceCodePopulated = true;
+ }
+
+ // Compile up the simple shader:
+ simpleShaderProg = new QGLShaderProgram(ctx, this);
+ compileNamedShader(MainVertexShader, QGLShader::PartialVertexShader);
+ compileNamedShader(PositionOnlyVertexShader, QGLShader::PartialVertexShader);
+ compileNamedShader(MainFragmentShader, QGLShader::PartialFragmentShader);
+ compileNamedShader(ShockingPinkSrcFragmentShader, QGLShader::PartialFragmentShader);
+ simpleShaderProg->addShader(compiledShaders[MainVertexShader]);
+ simpleShaderProg->addShader(compiledShaders[PositionOnlyVertexShader]);
+ simpleShaderProg->addShader(compiledShaders[MainFragmentShader]);
+ simpleShaderProg->addShader(compiledShaders[ShockingPinkSrcFragmentShader]);
+ simpleShaderProg->link();
+ if (!simpleShaderProg->isLinked()) {
+ qCritical() << "Errors linking simple shader:"
+ << simpleShaderProg->log();
+ }
+}
+
+QGLEngineShaderManager::~QGLEngineShaderManager()
+{
+ //###
+}
+
+
+
+
+
+void QGLEngineShaderManager::optimiseForBrushTransform(const QTransform &transform)
+{
+ Q_UNUSED(transform); // Currently ignored
+}
+
+void QGLEngineShaderManager::setSrcPixelType(Qt::BrushStyle style)
+{
+ srcPixelType = style;
+ shaderProgNeedsChanging = true; //###
+}
+
+void QGLEngineShaderManager::setSrcPixelType(PixelSrcType type)
+{
+ srcPixelType = type;
+ shaderProgNeedsChanging = true; //###
+}
+
+void QGLEngineShaderManager::setTextureCoordsEnabled(bool enabled)
+{
+ useTextureCoords = enabled;
+ shaderProgNeedsChanging = true; //###
+}
+
+void QGLEngineShaderManager::setUseGlobalOpacity(bool useOpacity)
+{
+ useGlobalOpacity = useOpacity;
+ shaderProgNeedsChanging = true; //###
+}
+
+void QGLEngineShaderManager::setMaskType(MaskType type)
+{
+ maskType = type;
+ shaderProgNeedsChanging = true; //###
+}
+
+void QGLEngineShaderManager::setCompositionMode(QPainter::CompositionMode mode)
+{
+ compositionMode = mode;
+ shaderProgNeedsChanging = true; //###
+}
+
+QGLShaderProgram* QGLEngineShaderManager::currentProgram()
+{
+ return currentShaderProg;
+}
+
+QGLShaderProgram* QGLEngineShaderManager::simpleProgram()
+{
+ return simpleShaderProg;
+}
+
+
+
+
+// Select & use the correct shader program using the current state.
+// Returns true if program needed changing.
+bool QGLEngineShaderManager::useCorrectShaderProg()
+{
+ if (!shaderProgNeedsChanging)
+ return false;
+
+ QGLEngineShaderProg requiredProgram;
+ requiredProgram.program = 0;
+
+ // Choose vertex shader main function
+ QGLEngineShaderManager::ShaderName mainVertexShaderName = InvalidShaderName;
+ if (useTextureCoords)
+ mainVertexShaderName = MainWithTexCoordsVertexShader;
+ else
+ mainVertexShaderName = MainVertexShader;
+ compileNamedShader(mainVertexShaderName, QGLShader::PartialVertexShader);
+ requiredProgram.mainVertexShader = compiledShaders[mainVertexShaderName];
+
+ // Choose vertex shader shader position function (which typically also sets
+ // varyings) and the source pixel (srcPixel) fragment shader function:
+ QGLEngineShaderManager::ShaderName positionVertexShaderName = InvalidShaderName;
+ QGLEngineShaderManager::ShaderName srcPixelFragShaderName = InvalidShaderName;
+ bool isAffine = brushTransform.isAffine();
+ if ( (srcPixelType >= Qt::Dense1Pattern) && (srcPixelType <= Qt::DiagCrossPattern) ) {
+ if (isAffine)
+ positionVertexShaderName = AffinePositionWithPatternBrushVertexShader;
+ else
+ positionVertexShaderName = PositionWithPatternBrushVertexShader;
+
+ srcPixelFragShaderName = PatternBrushSrcFragmentShader;
+ }
+ else switch (srcPixelType) {
+ default:
+ case Qt::NoBrush:
+ qCritical("QGLEngineShaderManager::useCorrectShaderProg() - I'm scared, Qt::NoBrush style is set");
+ break;
+ case QGLEngineShaderManager::ImageSrc:
+ srcPixelFragShaderName = ImageSrcFragmentShader;
+ positionVertexShaderName = PositionOnlyVertexShader;
+ break;
+ case QGLEngineShaderManager::NonPremultipliedImageSrc:
+ srcPixelFragShaderName = NonPremultipliedImageSrcFragmentShader;
+ positionVertexShaderName = PositionOnlyVertexShader;
+ break;
+ case Qt::SolidPattern:
+ srcPixelFragShaderName = SolidBrushSrcFragmentShader;
+ positionVertexShaderName = PositionOnlyVertexShader;
+ break;
+ case Qt::LinearGradientPattern:
+ srcPixelFragShaderName = LinearGradientBrushSrcFragmentShader;
+ positionVertexShaderName = isAffine ? AffinePositionWithLinearGradientBrushVertexShader
+ : PositionWithLinearGradientBrushVertexShader;
+ break;
+ case Qt::ConicalGradientPattern:
+ srcPixelFragShaderName = ConicalGradientBrushSrcFragmentShader;
+ positionVertexShaderName = isAffine ? AffinePositionWithConicalGradientBrushVertexShader
+ : PositionWithConicalGradientBrushVertexShader;
+ break;
+ case Qt::RadialGradientPattern:
+ srcPixelFragShaderName = RadialGradientBrushSrcFragmentShader;
+ positionVertexShaderName = isAffine ? AffinePositionWithRadialGradientBrushVertexShader
+ : PositionWithRadialGradientBrushVertexShader;
+ break;
+ case Qt::TexturePattern:
+ srcPixelFragShaderName = TextureBrushSrcFragmentShader;
+ positionVertexShaderName = isAffine ? AffinePositionWithTextureBrushVertexShader
+ : PositionWithTextureBrushVertexShader;
+ break;
+ };
+ compileNamedShader(positionVertexShaderName, QGLShader::PartialVertexShader);
+ compileNamedShader(srcPixelFragShaderName, QGLShader::PartialFragmentShader);
+ requiredProgram.positionVertexShader = compiledShaders[positionVertexShaderName];
+ requiredProgram.srcPixelFragShader = compiledShaders[srcPixelFragShaderName];
+
+
+ const bool hasCompose = compositionMode > QPainter::CompositionMode_Plus;
+ const bool hasMask = maskType != QGLEngineShaderManager::NoMask;
+
+ // Choose fragment shader main function:
+ QGLEngineShaderManager::ShaderName mainFragShaderName;
+
+ if (hasCompose && hasMask && useGlobalOpacity)
+ mainFragShaderName = MainFragmentShader_CMO;
+ if (hasCompose && hasMask && !useGlobalOpacity)
+ mainFragShaderName = MainFragmentShader_CM;
+ if (!hasCompose && hasMask && useGlobalOpacity)
+ mainFragShaderName = MainFragmentShader_MO;
+ if (!hasCompose && hasMask && !useGlobalOpacity)
+ mainFragShaderName = MainFragmentShader_M;
+ if (hasCompose && !hasMask && useGlobalOpacity)
+ mainFragShaderName = MainFragmentShader_CO;
+ if (hasCompose && !hasMask && !useGlobalOpacity)
+ mainFragShaderName = MainFragmentShader_C;
+ if (!hasCompose && !hasMask && useGlobalOpacity)
+ mainFragShaderName = MainFragmentShader_O;
+ if (!hasCompose && !hasMask && !useGlobalOpacity)
+ mainFragShaderName = MainFragmentShader;
+
+ compileNamedShader(mainFragShaderName, QGLShader::PartialFragmentShader);
+ requiredProgram.mainFragShader = compiledShaders[mainFragShaderName];
+
+ if (hasMask) {
+ QGLEngineShaderManager::ShaderName maskShaderName = QGLEngineShaderManager::InvalidShaderName;
+ if (maskType == PixelMask)
+ maskShaderName = MaskFragmentShader;
+ else if (maskType == SubPixelMask)
+ maskShaderName = RgbMaskFragmentShader;
+ else if (maskType == SubPixelWithGammaMask)
+ maskShaderName = RgbMaskWithGammaFragmentShader;
+ else
+ qCritical("QGLEngineShaderManager::useCorrectShaderProg() - Unknown mask type");
+
+ compileNamedShader(maskShaderName, QGLShader::PartialFragmentShader);
+ requiredProgram.maskFragShader = compiledShaders[maskShaderName];
+ }
+ else
+ requiredProgram.maskFragShader = 0;
+
+ if (hasCompose) {
+ QGLEngineShaderManager::ShaderName compositionShaderName = QGLEngineShaderManager::InvalidShaderName;
+ switch (compositionMode) {
+ case QPainter::CompositionMode_Multiply:
+ compositionShaderName = MultiplyCompositionModeFragmentShader;
+ break;
+ case QPainter::CompositionMode_Screen:
+ compositionShaderName = ScreenCompositionModeFragmentShader;
+ break;
+ case QPainter::CompositionMode_Overlay:
+ compositionShaderName = OverlayCompositionModeFragmentShader;
+ break;
+ case QPainter::CompositionMode_Darken:
+ compositionShaderName = DarkenCompositionModeFragmentShader;
+ break;
+ case QPainter::CompositionMode_Lighten:
+ compositionShaderName = LightenCompositionModeFragmentShader;
+ break;
+ case QPainter::CompositionMode_ColorDodge:
+ compositionShaderName = ColorDodgeCompositionModeFragmentShader;
+ break;
+ case QPainter::CompositionMode_ColorBurn:
+ compositionShaderName = ColorBurnCompositionModeFragmentShader;
+ break;
+ case QPainter::CompositionMode_HardLight:
+ compositionShaderName = HardLightCompositionModeFragmentShader;
+ break;
+ case QPainter::CompositionMode_SoftLight:
+ compositionShaderName = SoftLightCompositionModeFragmentShader;
+ break;
+ case QPainter::CompositionMode_Difference:
+ compositionShaderName = DifferenceCompositionModeFragmentShader;
+ break;
+ case QPainter::CompositionMode_Exclusion:
+ compositionShaderName = ExclusionCompositionModeFragmentShader;
+ break;
+ default:
+ qWarning("QGLEngineShaderManager::useCorrectShaderProg() - Unsupported composition mode");
+ }
+ compileNamedShader(compositionShaderName, QGLShader::PartialFragmentShader);
+ requiredProgram.compositionFragShader = compiledShaders[compositionShaderName];
+ }
+ else
+ requiredProgram.compositionFragShader = 0;
+
+
+ // At this point, requiredProgram is fully populated so try to find the program in the cache
+ foreach (const QGLEngineShaderProg &prog, cachedPrograms) {
+ if ( (prog.mainVertexShader == requiredProgram.mainVertexShader)
+ && (prog.positionVertexShader == requiredProgram.positionVertexShader)
+ && (prog.mainFragShader == requiredProgram.mainFragShader)
+ && (prog.srcPixelFragShader == requiredProgram.srcPixelFragShader)
+ && (prog.compositionFragShader == requiredProgram.compositionFragShader) )
+ {
+ currentShaderProg = prog.program;
+ currentShaderProg->enable();
+ shaderProgNeedsChanging = false;
+ return true;
+ }
+ }
+
+ // Shader program not found in cache, create it now.
+ requiredProgram.program = new QGLShaderProgram(ctx, this);
+ requiredProgram.program->addShader(requiredProgram.mainVertexShader);
+ requiredProgram.program->addShader(requiredProgram.positionVertexShader);
+ requiredProgram.program->addShader(requiredProgram.mainFragShader);
+ requiredProgram.program->addShader(requiredProgram.srcPixelFragShader);
+ requiredProgram.program->addShader(requiredProgram.maskFragShader);
+ requiredProgram.program->addShader(requiredProgram.compositionFragShader);
+
+ // We have to bind the vertex attribute names before the program is linked:
+ requiredProgram.program->bindAttributeLocation("inputVertex", QT_VERTEX_COORDS_ATTR);
+ if (useTextureCoords)
+ requiredProgram.program->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
+
+ requiredProgram.program->link();
+ if (!requiredProgram.program->isLinked()) {
+ QString error;
+ qWarning() << "Shader program failed to link,"
+#if defined(QT_DEBUG)
+ << '\n'
+ << " Shaders Used:" << '\n'
+ << " mainVertexShader = " << requiredProgram.mainVertexShader->objectName() << '\n'
+ << " positionVertexShader = " << requiredProgram.positionVertexShader->objectName() << '\n'
+ << " mainFragShader = " << requiredProgram.mainFragShader->objectName() << '\n'
+ << " srcPixelFragShader = " << requiredProgram.srcPixelFragShader->objectName() << '\n'
+ << " maskFragShader = " << requiredProgram.maskFragShader->objectName() << '\n'
+ << " compositionFragShader = "<< requiredProgram.compositionFragShader->objectName() << '\n'
+#endif
+ << " Error Log:" << '\n'
+ << " " << requiredProgram.program->log();
+ qWarning() << error;
+ }
+ else {
+ cachedPrograms.append(requiredProgram);
+ currentShaderProg = requiredProgram.program;
+ currentShaderProg->enable();
+ }
+ shaderProgNeedsChanging = false;
+ return true;
+}
+
+void QGLEngineShaderManager::compileNamedShader(QGLEngineShaderManager::ShaderName name, QGLShader::ShaderType type)
+{
+ if (compiledShaders[name])
+ return;
+
+ QGLShader *newShader = new QGLShader(type, ctx, this);
+ newShader->setSourceCode(qglEngineShaderSourceCode[name]);
+ // newShader->compile(); ### does not exist?
+
+#if defined(QT_DEBUG)
+ // Name the shader for easier debugging
+ QMetaEnum m = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("ShaderName"));
+ newShader->setObjectName(QLatin1String(m.valueToKey(name)));
+#endif
+
+ compiledShaders[name] = newShader;
+}
+
+
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h
new file mode 100644
index 0000000..b8b2745
--- /dev/null
+++ b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h
@@ -0,0 +1,385 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// 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.
+//
+
+/*
+ VERTEX SHADERS
+ ==============
+
+ Vertex shaders are specified as multiple (partial) shaders. On desktop,
+ this works fine. On ES, QGLShader & QGLShaderProgram will make partial
+ shaders work by concatenating the source in each QGLShader and compiling
+ it as a single shader. This is abstracted nicely by QGLShaderProgram and
+ the GL2 engine doesn't need to worry about it.
+
+ Generally, there's two vertex shader objects. The position shaders are
+ the ones which set gl_Position. There's also two "main" vertex shaders,
+ one which just calls the position shader and another which also passes
+ through some texture coordinates from a vertex attribute array to a
+ varying. These texture coordinates are used for mask position in text
+ rendering and for the source coordinates in drawImage/drawPixmap. There's
+ also a "Simple" vertex shader for rendering a solid colour (used to render
+ into the stencil buffer where the actual colour value is discarded).
+
+ The position shaders for brushes look scary. This is because many of the
+ calculations which logically belong in the fragment shader have been moved
+ into the vertex shader to improve performance. This is why the position
+ calculation is in a seperate shader. Not only does it calculate the
+ position, but it also calculates some data to be passed to the fragment
+ shader as a varying. It is optimal to move as much of the calculation as
+ possible into the vertex shader as this is executed less often.
+
+ The varyings passed to the fragment shaders are interpolated (which is
+ cheap). Unfortunately, GL will apply perspective correction to the
+ interpolation calusing errors. To get around this, the vertex shader must
+ apply perspective correction itself and set the w-value of gl_Position to
+ zero. That way, GL will be tricked into thinking it doesn't need to apply a
+ perspective correction and use linear interpolation instead (which is what
+ we want). Of course, if the brush transform is affeine, no perspective
+ correction is needed and a simpler vertex shader can be used instead.
+
+ So there are the following "main" vertex shaders:
+ qglslMainVertexShader
+ qglslMainWithTexCoordsVertexShader
+
+ And the the following position vertex shaders:
+ qglslPositionOnlyVertexShader
+ qglslPositionWithTextureBrushVertexShader
+ qglslPositionWithPatternBrushVertexShader
+ qglslPositionWithLinearGradientBrushVertexShader
+ qglslPositionWithRadialGradientBrushVertexShader
+ qglslPositionWithConicalGradientBrushVertexShader
+ qglslAffinePositionWithTextureBrushVertexShader
+ qglslAffinePositionWithPatternBrushVertexShader
+ qglslAffinePositionWithLinearGradientBrushVertexShader
+ qglslAffinePositionWithRadialGradientBrushVertexShader
+ qglslAffinePositionWithConicalGradientBrushVertexShader
+
+ Leading to 23 possible vertex shaders
+
+
+ FRAGMENT SHADERS
+ ================
+
+ Fragment shaders are also specified as multiple (partial) shaders. The
+ different fragment shaders represent the different stages in Qt's fragment
+ pipeline. There are 1-3 stages in this pipeline: First stage is to get the
+ fragment's colour value. The next stage is to get the fragment's mask value
+ (coverage value for anti-aliasing) and the final stage is to blend the
+ incoming fragment with the background (for composition modes not supported
+ by GL).
+
+ Of these, the first stage will always be present. If Qt doesn't need to
+ apply anti-aliasing (because it's off or handled by multisampling) then
+ the coverage value doesn't need to be applied. (Note: There are two types
+ of mask, one for regular anti-aliasing and one for sub-pixel anti-
+ aliasing.) If the composition mode is one which GL supports natively then
+ the blending stage doesn't need to be applied.
+
+ As eash stage can have multiple implementations, they are abstracted as
+ GLSL function calls with the following signatures:
+
+ Brushes & image drawing are implementations of "qcolorp vec4 srcPixel()":
+ qglslImageSrcFragShader
+ qglslNonPremultipliedImageSrcFragShader
+ qglslSolidBrushSrcFragShader
+ qglslTextureBrushSrcFragShader
+ qglslPatternBrushSrcFragShader
+ qglslLinearGradientBrushSrcFragShader
+ qglslRadialGradientBrushSrcFragShader
+ qglslConicalGradientBrushSrcFragShader
+ NOTE: It is assumed the colour returned by srcPixel() is pre-multiplied
+
+ Masks are implementations of "qcolorp vec4 applyMask(qcolorp vec4 src)":
+ qglslMaskFragmentShader
+ qglslRgbMaskFragmentShader
+ qglslRgbMaskWithGammaFragmentShader
+
+ Composition modes are "qcolorp vec4 compose(qcolorp vec4 src)":
+ qglslColorBurnCompositionModeFragmentShader
+ qglslColorDodgeCompositionModeFragmentShader
+ qglslDarkenCompositionModeFragmentShader
+ qglslDifferenceCompositionModeFragmentShader
+ qglslExclusionCompositionModeFragmentShader
+ qglslHardLightCompositionModeFragmentShader
+ qglslLightenCompositionModeFragmentShader
+ qglslMultiplyCompositionModeFragmentShader
+ qglslOverlayCompositionModeFragmentShader
+ qglslScreenCompositionModeFragmentShader
+ qglslSoftLightCompositionModeFragmentShader
+
+
+ Note: In the future, some GLSL compilers will support an extension allowing
+ a new 'color' precision specifier. To support this, qcolorp is used for
+ all color components so it can be defined to colorp or lowp depending upon
+ the implementation.
+
+ So there are differnt frament shader main functions, depending on the
+ number & type of pipelines the fragment needs to go through.
+
+ The choice of which main() fragment shader string to use depends on:
+ - Use of global opacity
+ - Brush style (some brushes apply opacity themselves)
+ - Use & type of mask (TODO: Need to support high quality anti-aliasing & text)
+ - Use of non-GL Composition mode
+
+ Leading to the following fragment shader main functions:
+ gl_FragColor = compose(applyMask(srcPixel()*globalOpacity));
+ gl_FragColor = compose(applyMask(srcPixel()));
+ gl_FragColor = applyMask(srcPixel()*globalOpacity);
+ gl_FragColor = applyMask(srcPixel());
+ gl_FragColor = compose(srcPixel()*globalOpacity);
+ gl_FragColor = compose(srcPixel());
+ gl_FragColor = srcPixel()*globalOpacity;
+ gl_FragColor = srcPixel();
+
+ Called:
+ qglslMainFragmentShader_CMO
+ qglslMainFragmentShader_CM
+ qglslMainFragmentShader_MO
+ qglslMainFragmentShader_M
+ qglslMainFragmentShader_CO
+ qglslMainFragmentShader_C
+ qglslMainFragmentShader_O
+ qglslMainFragmentShader
+
+ Where:
+ M = Mask
+ C = Composition
+ O = Global Opacity
+
+
+ CUSTOM SHADER CODE (idea, depricated)
+ ==================
+
+ The use of custom shader code is supported by the engine for drawImage and
+ drawPixmap calls. This is implemented via hooks in the fragment pipeline.
+ The custom shader is passed to the engine as a partial fragment shader
+ (QGLCustomizedShader). The shader will implement a pre-defined method name
+ which Qt's fragment pipeline will call. There are two different hooks which
+ can be implemented as custom shader code:
+
+ mediump vec4 customShader(sampler2d src, vec2 srcCoords)
+ mediump vec4 customShaderWithDest(sampler2d dest, sampler2d src, vec2 srcCoords)
+
+*/
+
+#ifndef QGLENGINE_SHADER_MANAGER_H
+#define QGLENGINE_SHADER_MANAGER_H
+
+#include <QGLShader>
+#include <QGLShaderProgram>
+#include <QPainter>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(OpenGL)
+
+
+struct QGLEngineShaderProg
+{
+ QGLShader* mainVertexShader;
+ QGLShader* positionVertexShader;
+ QGLShader* mainFragShader;
+ QGLShader* srcPixelFragShader;
+ QGLShader* maskFragShader; // Can be null for no mask
+ QGLShader* compositionFragShader; // Can be null for GL-handled mode
+ QGLShaderProgram* program;
+};
+
+/*
+struct QGLEngineCachedShaderProg
+{
+ QGLEngineCachedShaderProg(QGLEngineShaderManager::ShaderName vertexMain,
+ QGLEngineShaderManager::ShaderName vertexPosition,
+ QGLEngineShaderManager::ShaderName fragMain,
+ QGLEngineShaderManager::ShaderName pixelSrc,
+ QGLEngineShaderManager::ShaderName mask,
+ QGLEngineShaderManager::ShaderName composition);
+
+ int cacheKey;
+ QGLShaderProgram* program;
+}
+*/
+
+static const GLuint QT_VERTEX_COORDS_ATTR = 0;
+static const GLuint QT_TEXTURE_COORDS_ATTR = 1;
+
+class QGLEngineShaderManager : public QObject
+{
+ Q_OBJECT;
+public:
+ QGLEngineShaderManager(QGLContext* context);
+ ~QGLEngineShaderManager();
+
+ enum MaskType {NoMask, PixelMask, SubPixelMask, SubPixelWithGammaMask};
+ enum PixelSrcType {
+ ImageSrc = Qt::TexturePattern+1,
+ NonPremultipliedImageSrc = Qt::TexturePattern+2
+ };
+
+ // There are optimisations we can do, depending on the brush transform:
+ // 1) May not have to apply perspective-correction
+ // 2) Can use lower precision for matrix
+ void optimiseForBrushTransform(const QTransform &transform);
+ void setSrcPixelType(Qt::BrushStyle);
+ void setSrcPixelType(PixelSrcType); // For non-brush sources, like pixmaps & images
+ void setTextureCoordsEnabled(bool); // For images & text glyphs
+ void setUseGlobalOpacity(bool);
+ void setMaskType(MaskType);
+ void setCompositionMode(QPainter::CompositionMode);
+
+ bool useCorrectShaderProg(); // returns true if the shader program needed to be changed
+
+ QGLShaderProgram* currentProgram(); // Returns pointer to the shader the manager has chosen
+ QGLShaderProgram* simpleProgram(); // Used to draw into e.g. stencil buffers
+
+ enum ShaderName {
+ MainVertexShader,
+ MainWithTexCoordsVertexShader,
+
+ PositionOnlyVertexShader,
+ PositionWithPatternBrushVertexShader,
+ PositionWithLinearGradientBrushVertexShader,
+ PositionWithConicalGradientBrushVertexShader,
+ PositionWithRadialGradientBrushVertexShader,
+ PositionWithTextureBrushVertexShader,
+ AffinePositionWithPatternBrushVertexShader,
+ AffinePositionWithLinearGradientBrushVertexShader,
+ AffinePositionWithConicalGradientBrushVertexShader,
+ AffinePositionWithRadialGradientBrushVertexShader,
+ AffinePositionWithTextureBrushVertexShader,
+
+ MainFragmentShader_CMO,
+ MainFragmentShader_CM,
+ MainFragmentShader_MO,
+ MainFragmentShader_M,
+ MainFragmentShader_CO,
+ MainFragmentShader_C,
+ MainFragmentShader_O,
+ MainFragmentShader,
+
+ ImageSrcFragmentShader,
+ NonPremultipliedImageSrcFragmentShader,
+ SolidBrushSrcFragmentShader,
+ TextureBrushSrcFragmentShader,
+ PatternBrushSrcFragmentShader,
+ LinearGradientBrushSrcFragmentShader,
+ RadialGradientBrushSrcFragmentShader,
+ ConicalGradientBrushSrcFragmentShader,
+ ShockingPinkSrcFragmentShader,
+
+ MaskFragmentShader,
+ RgbMaskFragmentShader,
+ RgbMaskWithGammaFragmentShader,
+
+ MultiplyCompositionModeFragmentShader,
+ ScreenCompositionModeFragmentShader,
+ OverlayCompositionModeFragmentShader,
+ DarkenCompositionModeFragmentShader,
+ LightenCompositionModeFragmentShader,
+ ColorDodgeCompositionModeFragmentShader,
+ ColorBurnCompositionModeFragmentShader,
+ HardLightCompositionModeFragmentShader,
+ SoftLightCompositionModeFragmentShader,
+ DifferenceCompositionModeFragmentShader,
+ ExclusionCompositionModeFragmentShader,
+
+ TotalShaderCount, InvalidShaderName
+ };
+
+/*
+ // These allow the ShaderName enum to be used as a cache key
+ const int mainVertexOffset = 0;
+ const int positionVertexOffset = (1<<2) - PositionOnlyVertexShader;
+ const int mainFragOffset = (1<<6) - MainFragmentShader_CMO;
+ const int srcPixelOffset = (1<<10) - ImageSrcFragmentShader;
+ const int maskOffset = (1<<14) - NoMaskShader;
+ const int compositionOffset = (1 << 16) - MultiplyCompositionModeFragmentShader;
+*/
+
+#if defined (QT_DEBUG)
+ Q_ENUMS(ShaderName);
+#endif
+
+
+private:
+ QGLContext* ctx;
+ bool shaderProgNeedsChanging;
+
+ // Current state variables which influence the choice of shader:
+ QTransform brushTransform;
+ int srcPixelType;
+ bool useGlobalOpacity;
+ MaskType maskType;
+ bool useTextureCoords;
+ QPainter::CompositionMode compositionMode;
+
+ QGLShaderProgram* simpleShaderProg;
+ QGLShaderProgram* currentShaderProg;
+
+ // TODO: Possibly convert to a LUT
+ QList<QGLEngineShaderProg> cachedPrograms;
+
+ QGLShader* compiledShaders[TotalShaderCount];
+
+ void compileNamedShader(QGLEngineShaderManager::ShaderName name, QGLShader::ShaderType type);
+
+ static const char* qglEngineShaderSourceCode[TotalShaderCount];
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif //QGLENGINE_SHADER_MANAGER_H
diff --git a/src/opengl/gl2paintengineex/qglengineshadersource_p.h b/src/opengl/gl2paintengineex/qglengineshadersource_p.h
new file mode 100644
index 0000000..fdbba72
--- /dev/null
+++ b/src/opengl/gl2paintengineex/qglengineshadersource_p.h
@@ -0,0 +1,383 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// 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.
+//
+
+
+#ifndef QGL_ENGINE_SHADER_SOURCE_H
+#define QGL_ENGINE_SHADER_SOURCE_H
+
+#include "qglengineshadermanager_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(OpenGL)
+
+
+static const char* const qglslMainVertexShader = "\
+ void setPosition();\
+ void main(void)\
+ {\
+ setPosition();\
+ }";
+
+static const char* const qglslMainWithTexCoordsVertexShader = "\
+ attribute lowp vec2 textureCoordArray; \
+ varying lowp vec2 textureCoords; \
+ void setPosition();\
+ void main(void) \
+ {\
+ setPosition();\
+ textureCoords = textureCoordArray; \
+ }";
+
+
+static const char* const qglslPositionOnlyVertexShader = "\
+ attribute highp vec4 vertexCoordsArray;\
+ uniform highp mat4 pmvMatrix;\
+ void setPosition(void)\
+ {\
+ gl_Position = pmvMatrix * vertexCoordsArray;\
+ }";
+
+
+// Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125
+static const char* const qglslPositionWithPatternBrushVertexShader = "\
+ attribute highp vec4 vertexCoordsArray; \
+ uniform highp mat4 pmvMatrix; \
+ uniform mediump vec2 halfViewportSize; \
+ uniform mediump vec2 invertedTextureSize; \
+ uniform mediump mat3 brushTransform; \
+ varying mediump vec2 patternTexCoords; \
+ void setPosition(void) { \
+ gl_Position = pmvMatrix * vertexCoordsArray;\
+ gl_Position.xy = gl_Position.xy / gl_Position.w; \
+ mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
+ mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
+ mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
+ gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
+ gl_Position.w = invertedHTexCoordsZ; \
+ patternTexCoords.xy = (hTexCoords.xy * 0.125) * invertedHTexCoordsZ; \
+ patternTexCoords.y = -patternTexCoords.y; \
+ }";
+
+static const char* const qglslAffinePositionWithPatternBrushVertexShader
+ = qglslPositionWithPatternBrushVertexShader;
+
+static const char* const qglslPatternBrushSrcFragmentShader = "\
+ uniform sampler2D brushTexture;\
+ uniform lowp vec4 patternColor; \
+ varying mediump vec2 patternTexCoords;\
+ lowp vec4 srcPixel() { \
+ return patternColor * texture2D(brushTexture, patternTexCoords).r; \
+ }\n";
+
+
+// Linear Gradient Brush
+static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\
+ attribute highp vec4 vertexCoordsArray; \
+ uniform highp mat4 pmvMatrix; \
+ uniform mediump vec2 halfViewportSize; \
+ uniform highp vec3 linearData; \
+ uniform highp mat3 brushTransform; \
+ varying mediump float index ; \
+ void setPosition() { \
+ gl_Position = pmvMatrix * vertexCoordsArray;\
+ gl_Position.xy = gl_Position.xy / gl_Position.w; \
+ mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
+ mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
+ mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
+ gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
+ gl_Position.w = invertedHTexCoordsZ; \
+ index = (dot(linearData.xy, hTexCoords.xy) * linearData.z) * invertedHTexCoordsZ; \
+ }";
+
+static const char* const qglslAffinePositionWithLinearGradientBrushVertexShader
+ = qglslPositionWithLinearGradientBrushVertexShader;
+
+static const char* const qglslLinearGradientBrushSrcFragmentShader = "\
+ uniform sampler2D brushTexture; \
+ varying mediump float index; \
+ lowp vec4 srcPixel() { \
+ mediump vec2 val = vec2(index, 0.5); \
+ return texture2D(brushTexture, val); \
+ }\n";
+
+
+// Conical Gradient Brush
+static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\
+ attribute highp vec4 vertexCoordsArray;\
+ uniform highp mat4 pmvMatrix;\
+ uniform mediump vec2 halfViewportSize; \
+ uniform highp mat3 brushTransform; \
+ varying highp vec2 A; \
+ void setPosition(void)\
+ {\
+ gl_Position = pmvMatrix * vertexCoordsArray;\
+ gl_Position.xy = gl_Position.xy / gl_Position.w; \
+ mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
+ mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
+ mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
+ gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
+ gl_Position.w = invertedHTexCoordsZ; \
+ A = hTexCoords.xy * invertedHTexCoordsZ; \
+ }";
+
+static const char* const qglslAffinePositionWithConicalGradientBrushVertexShader
+ = qglslPositionWithConicalGradientBrushVertexShader;
+
+static const char* const qglslConicalGradientBrushSrcFragmentShader = "\n\
+ #define INVERSE_2PI 0.1591549430918953358 \n\
+ uniform sampler2D brushTexture; \n\
+ uniform mediump float angle; \
+ varying highp vec2 A; \
+ lowp vec4 srcPixel() { \
+ highp float t; \
+ if (abs(A.y) == abs(A.x)) \
+ t = (atan(-A.y + 0.002, A.x) + angle) * INVERSE_2PI; \
+ else \
+ t = (atan(-A.y, A.x) + angle) * INVERSE_2PI; \
+ return texture2D(brushTexture, vec2(t - floor(t), 0.5)); \
+ }";
+
+
+// Radial Gradient Brush
+static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\
+ attribute highp vec4 vertexCoordsArray;\
+ uniform highp mat4 pmvMatrix;\
+ uniform mediump vec2 halfViewportSize; \
+ uniform highp mat3 brushTransform; \
+ uniform highp vec2 fmp; \
+ varying highp float b; \
+ varying highp vec2 A; \
+ void setPosition(void) \
+ {\
+ gl_Position = pmvMatrix * vertexCoordsArray;\
+ gl_Position.xy = gl_Position.xy / gl_Position.w; \
+ mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
+ mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
+ mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
+ gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
+ gl_Position.w = invertedHTexCoordsZ; \
+ A = hTexCoords.xy * invertedHTexCoordsZ; \
+ b = 2.0 * dot(A, fmp); \
+ }";
+
+static const char* const qglslAffinePositionWithRadialGradientBrushVertexShader
+ = qglslPositionWithRadialGradientBrushVertexShader;
+
+static const char* const qglslRadialGradientBrushSrcFragmentShader = "\
+ uniform sampler2D brushTexture; \
+ uniform highp float fmp2_m_radius2; \
+ uniform highp float inverse_2_fmp2_m_radius2; \
+ varying highp float b; \
+ varying highp vec2 A; \
+ lowp vec4 srcPixel() { \
+ highp float c = -dot(A, A); \
+ highp vec2 val = vec2((-b + sqrt(b*b - 4.0*fmp2_m_radius2*c)) * inverse_2_fmp2_m_radius2, 0.5); \
+ return texture2D(brushTexture, val); \
+ }";
+
+
+// Texture Brush
+static const char* const qglslPositionWithTextureBrushVertexShader = "\
+ attribute highp vec4 vertexCoordsArray; \
+ uniform highp mat4 pmvMatrix; \
+ uniform mediump vec2 halfViewportSize; \
+ uniform mediump vec2 invertedTextureSize; \
+ uniform mediump mat3 brushTransform; \
+ varying mediump vec2 brushTextureCoords; \
+ void setPosition(void) { \
+ gl_Position = pmvMatrix * vertexCoordsArray;\
+ gl_Position.xy = gl_Position.xy / gl_Position.w; \
+ mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
+ mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
+ mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
+ gl_Position.xy = gl_Position.xy * invertedHTexCoordsZ; \
+ gl_Position.w = invertedHTexCoordsZ; \
+ brushTextureCoords.xy = (hTexCoords.xy * invertedTextureSize) * gl_Position.w; \
+ brushTextureCoords.y = -brushTextureCoords.y; \
+ }";
+
+static const char* const qglslAffinePositionWithTextureBrushVertexShader
+ = qglslPositionWithTextureBrushVertexShader;
+
+static const char* const qglslTextureBrushSrcFragmentShader = "\
+ varying mediump vec2 brushTextureCoords; \
+ uniform sampler2D brushTexture; \
+ lowp vec4 srcPixel() { \
+ return texture2D(brushTexture, brushTextureCoords); \
+ }";
+
+
+// Solid Fill Brush
+static const char* const qglslSolidBrushSrcFragmentShader = "\
+ uniform lowp vec4 fragmentColor; \
+ lowp vec4 srcPixel() { \
+ return fragmentColor; \
+ }";
+
+static const char* const qglslImageSrcFragmentShader = "\
+ varying highp vec2 textureCoords; \
+ uniform sampler2D imageTexture; \
+ lowp vec4 srcPixel() { \
+ return texture2D(imageTexture, textureCoords); \
+ }";
+
+static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\
+ varying highp vec2 textureCoords; \
+ uniform sampler2D imageTexture; \
+ lowp vec4 srcPixel() { \
+ lowp vec4 sample = texture2D(imageTexture, textureCoords); \
+ sample.rgb = sample.rgb * sample.a; \
+ return sample; \
+ }";
+
+static const char* const qglslShockingPinkSrcFragmentShader = "\
+ lowp vec4 srcPixel() { \
+ return vec4(0.98, 0.06, 0.75, 1.0); \
+ }";
+
+
+static const char* const qglslMainFragmentShader_CMO = "\
+ uniform lowp float globalOpacity; \
+ lowp vec4 srcPixel(); \
+ lowp vec4 applyMask(lowp vec4); \
+ lowp vec4 compose(lowp vec4); \
+ void main() { \
+ gl_FragColor = applyMask(compose(srcPixel()*globalOpacity))); \
+ }";
+
+static const char* const qglslMainFragmentShader_CM = "\
+ lowp vec4 srcPixel(); \
+ lowp vec4 applyMask(lowp vec4); \
+ lowp vec4 compose(lowp vec4); \
+ void main() { \
+ gl_FragColor = applyMask(compose(srcPixel())); \
+ }";
+
+static const char* const qglslMainFragmentShader_MO = "\
+ uniform lowp float globalOpacity; \
+ lowp vec4 srcPixel(); \
+ lowp vec4 applyMask(lowp vec4); \
+ void main() { \
+ gl_FragColor = applyMask(srcPixel()*globalOpacity); \
+ }";
+
+static const char* const qglslMainFragmentShader_M = "\
+ lowp vec4 srcPixel(); \
+ lowp vec4 applyMask(lowp vec4); \
+ void main() { \
+ gl_FragColor = applyMask(srcPixel()); \
+ }";
+
+static const char* const qglslMainFragmentShader_CO = "\
+ uniform lowp float globalOpacity; \
+ lowp vec4 srcPixel(); \
+ lowp vec4 compose(lowp vec4); \
+ void main() { \
+ gl_FragColor = compose(srcPixel()*globalOpacity); \
+ }";
+
+static const char* const qglslMainFragmentShader_C = "\
+ lowp vec4 srcPixel(); \
+ lowp vec4 compose(lowp vec4); \
+ void main() { \
+ gl_FragColor = compose(srcPixel()); \
+ }";
+
+static const char* const qglslMainFragmentShader_O = "\
+ uniform lowp float globalOpacity; \
+ lowp vec4 srcPixel(); \
+ void main() { \
+ gl_FragColor = srcPixel()*globalOpacity; \
+ }";
+
+static const char* const qglslMainFragmentShader = "\
+ lowp vec4 srcPixel(); \
+ void main() { \
+ gl_FragColor = srcPixel(); \
+ }";
+
+static const char* const qglslMaskFragmentShader = "\
+ varying highp vec2 textureCoords;\
+ uniform sampler2D maskTexture;\
+ lowp vec4 applyMask(lowp vec4 src) \
+ {\
+ lowp vec4 mask = texture2D(maskTexture, textureCoords); \
+ return src * mask.r; \
+ }";
+
+/*
+ Left to implement:
+ RgbMaskFragmentShader,
+ RgbMaskWithGammaFragmentShader,
+
+ MultiplyCompositionModeFragmentShader,
+ ScreenCompositionModeFragmentShader,
+ OverlayCompositionModeFragmentShader,
+ DarkenCompositionModeFragmentShader,
+ LightenCompositionModeFragmentShader,
+ ColorDodgeCompositionModeFragmentShader,
+ ColorBurnCompositionModeFragmentShader,
+ HardLightCompositionModeFragmentShader,
+ SoftLightCompositionModeFragmentShader,
+ DifferenceCompositionModeFragmentShader,
+ ExclusionCompositionModeFragmentShader,
+*/
+
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // GLGC_SHADER_SOURCE_H
diff --git a/src/opengl/gl2paintengineex/qglgradientcache.cpp b/src/opengl/gl2paintengineex/qglgradientcache.cpp
index b4591b2..2239c2f 100644
--- a/src/opengl/gl2paintengineex/qglgradientcache.cpp
+++ b/src/opengl/gl2paintengineex/qglgradientcache.cpp
@@ -44,7 +44,7 @@
#include "qglgradientcache_p.h"
-void QGLGradientCache::cleanCache() {
+void QGL2GradientCache::cleanCache() {
QGLGradientColorTableHash::const_iterator it = cache.constBegin();
for (; it != cache.constEnd(); ++it) {
const CacheInfo &cache_info = it.value();
@@ -53,7 +53,7 @@ void QGLGradientCache::cleanCache() {
cache.clear();
}
-GLuint QGLGradientCache::getBuffer(const QGradient &gradient, qreal opacity, const QGLContext *ctx)
+GLuint QGL2GradientCache::getBuffer(const QGradient &gradient, qreal opacity, const QGLContext *ctx)
{
if (buffer_ctx && !qgl_share_reg()->checkSharing(buffer_ctx, ctx))
cleanCache();
@@ -84,7 +84,7 @@ GLuint QGLGradientCache::getBuffer(const QGradient &gradient, qreal opacity, con
}
-GLuint QGLGradientCache::addCacheElement(quint64 hash_val, const QGradient &gradient, qreal opacity)
+GLuint QGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient &gradient, qreal opacity)
{
if (cache.size() == maxCacheSize()) {
int elem_to_remove = qrand() % maxCacheSize();
@@ -109,34 +109,31 @@ GLuint QGLGradientCache::addCacheElement(quint64 hash_val, const QGradient &grad
}
-// GL's expects pixels in RGBA, bin-endian (ABGR on x86).
-// Qt stores in ARGB using whatever byte-order the mancine uses.
+// GL's expects pixels in RGBA (when using GL_RGBA), bin-endian (ABGR on x86).
+// Qt always stores in ARGB reguardless of the byte-order the mancine uses.
static inline uint qtToGlColor(uint c)
{
uint o;
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
- o = c & 0xFF00FF00; // alpha & green already in the right place
- o |= (c >> 16) & 0x000000FF; // red
- o |= (c << 16) & 0x00FF0000; // blue
-
+ o = (c & 0xff00ff00) // alpha & green already in the right place
+ | ((c >> 16) & 0x000000ff) // red
+ | ((c << 16) & 0x00ff0000); // blue
#else //Q_BIG_ENDIAN
- o = c & 0x00FF00FF; // alpha & green already in the right place
- o |= (c << 16) & 0xFF000000; // red
- o |= (c >> 16) & 0x0000FF00; // blue
-#error big endian not tested with QGLGraphicsContext
+ o = (c << 8)
+ | ((c >> 24) & 0x000000ff);
#endif // Q_BYTE_ORDER
return o;
}
//TODO: Let GL generate the texture using an FBO
-void QGLGradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, qreal opacity) const
+void QGL2GradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, qreal opacity) const
{
int pos = 0;
QGradientStops s = gradient.stops();
QVector<uint> colors(s.size());
for (int i = 0; i < s.size(); ++i)
- colors[i] = s[i].second.rgba(); // Qt LIES! It returns ARGB
+ colors[i] = s[i].second.rgba(); // Qt LIES! It returns ARGB (on little-endian AND on big-endian)
bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation);
diff --git a/src/opengl/gl2paintengineex/qglgradientcache_p.h b/src/opengl/gl2paintengineex/qglgradientcache_p.h
index 346ea13..6acaa00 100644
--- a/src/opengl/gl2paintengineex/qglgradientcache_p.h
+++ b/src/opengl/gl2paintengineex/qglgradientcache_p.h
@@ -54,7 +54,7 @@
#include <QObject>
#include <QtOpenGL>
-class QGLGradientCache : public QObject
+class QGL2GradientCache : public QObject
{
Q_OBJECT
struct CacheInfo
@@ -71,7 +71,7 @@ class QGLGradientCache : public QObject
typedef QMultiHash<quint64, CacheInfo> QGLGradientColorTableHash;
public:
- QGLGradientCache() : QObject(), buffer_ctx(0)
+ QGL2GradientCache() : QObject(), buffer_ctx(0)
{
/*
connect(QGLSignalProxy::instance(),
diff --git a/src/opengl/gl2paintengineex/qglpexshadermanager.cpp b/src/opengl/gl2paintengineex/qglpexshadermanager.cpp
deleted file mode 100644
index e460e08..0000000
--- a/src/opengl/gl2paintengineex/qglpexshadermanager.cpp
+++ /dev/null
@@ -1,450 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtOpenGL module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qglpexshadermanager_p.h"
-
-#include "glgc_shader_source.h"
-
-QGLPEXShaderManager::QGLPEXShaderManager(const QGLContext* context)
-{
- ctx = const_cast<QGLContext*>(context);
-
- defaultVertexShader= new QGLShader(QGLShader::VertexShader, context);
- defaultVertexShader->addSource(QLatin1String(qglslDefaultVertexShader));
- if (!defaultVertexShader->compile())
- qWarning() << "Default vertex shader failed to compile: " << defaultVertexShader->log();
-
- noBrushShader = new QGLShader(QGLShader::FragmentShader, context);
- noBrushShader->addSource(QLatin1String(qglslFragmentShaderMain));
- noBrushShader->addSource(QLatin1String(qglslNoBrushFragmentShader));
- if (!noBrushShader->compile())
- qWarning() << "No brush shader failed to compile:" << noBrushShader->log();
-
-
- // Create a program for noBrush:
- QGLShaderProgram* noBrushProg = new QGLShaderProgram(ctx);
- noBrushProg->addShader(defaultVertexShader);
- noBrushProg->addShader(noBrushShader);
- if (!noBrushProg->link())
- qWarning() << "NoBrush shader program failed to link:" << noBrushProg->log();
-
- // Add noBrush Program to cache:
- QGLCachedShaderProg cachedProg;
- cachedProg.vertexShader = defaultVertexShader;
- cachedProg.brushShader = noBrushShader;
- cachedProg.compositionShader = 0;
- cachedProg.shader = noBrushProg;
- cachedPrograms.append(cachedProg);
-
-
- // Set state
- useGlobalOpacity = true;
- currentBrushStyle = Qt::NoBrush;
- currentTransformType = FullTransform;
- shaderProgNeedsChanging = false;
- activeProgram = noBrushProg;
-
- solidBrushShader = 0;
-
- conicalBrushVertexShader = 0;
- conicalBrushFragmentShader = 0;
-
- radialBrushVertexShader = 0;
- radialBrushFragmentShader = 0;
-
- linearBrushVertexShader = 0;
- linearBrushFragmentShader = 0;
-
- patternBrushVertexShader = 0;
- patternBrushFragmentShader = 0;
-
- textureBrushFragmentShader = 0;
- textureBrushVertexShader = 0;
-
- simpleFragmentShader = 0;
- simpleShaderProgram = 0;
-
- imageVertexShader = 0;
- imageFragmentShader = 0;
- imageShaderProgram = 0;
-
- textVertexShader = 0;
- textFragmentShader = 0;
- textShaderProgram = 0;
-}
-
-QGLPEXShaderManager::~QGLPEXShaderManager()
-{
- delete defaultVertexShader;
- delete imageVertexShader;
- delete imageFragmentShader;
- delete imageShaderProgram;
- delete textVertexShader;
- delete textFragmentShader;
- delete textShaderProgram;
- delete noBrushShader;
- delete solidBrushShader;
-
- delete conicalBrushVertexShader;
- delete conicalBrushFragmentShader;
-
- delete radialBrushVertexShader;
- delete radialBrushFragmentShader;
-
- delete linearBrushFragmentShader;
- delete linearBrushVertexShader;
-
- delete patternBrushFragmentShader;
- delete patternBrushVertexShader;
-
- delete textureBrushFragmentShader;
- delete textureBrushVertexShader;
-
- delete simpleFragmentShader;
- delete simpleShaderProgram;
-}
-
-void QGLPEXShaderManager::setUseGlobalOpacity(bool value)
-{
- if (value != useGlobalOpacity)
- shaderProgNeedsChanging = true;
-
- useGlobalOpacity = value;
-}
-
-void QGLPEXShaderManager::setBrushStyle(Qt::BrushStyle style)
-{
- if (currentBrushStyle != style)
- shaderProgNeedsChanging = true;
-
- currentBrushStyle = style;
-}
-
-void QGLPEXShaderManager::setAffineOnlyBrushTransform(bool value)
-{
- Q_UNUSED(value);
- // TODO
-}
-
-bool QGLPEXShaderManager::useCorrectShaderProg()
-{
- if (!shaderProgNeedsChanging) {
- activeProgram->use();
- return false;
- }
-
- const char* fragmentShaderMainSrc = qglslFragmentShaderMain;
- QGLShader* vertexShader = defaultVertexShader;
- QGLShader* fragmentShader = noBrushShader;
-
- // Make sure we compile up the correct brush shader
- switch (currentBrushStyle) {
- case Qt::NoBrush:
- break;
- case Qt::SolidPattern:
- if (!solidBrushShader) {
- qDebug("Compiling qglslSolidBrushFragmentShader");
- solidBrushShader = new QGLShader(QGLShader::FragmentShader, ctx);
- solidBrushShader->addSource(QLatin1String(qglslNoOpacityFragmentShaderMain));
- solidBrushShader->addSource(QLatin1String(qglslSolidBrushFragmentShader));
- if (!solidBrushShader->compile())
- qWarning() << "qglslSolidBrush failed to compile:" << solidBrushShader->log();
- }
- fragmentShader = solidBrushShader;
- break;
- case Qt::TexturePattern:
- if (!textureBrushVertexShader) {
- qDebug("Compiling qglslTextureBrushVertexShader");
- textureBrushVertexShader = new QGLShader(QGLShader::VertexShader, ctx);
- textureBrushVertexShader->addSource(QLatin1String(qglslTextureBrushVertexShader));
- if (!textureBrushVertexShader->compile()) {
- qWarning() << "qglslTextureBrushVertexShader failed to compile: "
- << textureBrushVertexShader->log();
- }
- }
- vertexShader = textureBrushVertexShader;
-
- if (!textureBrushFragmentShader) {
- qDebug("Compiling qglslTextureBrushFragmentShader");
- textureBrushFragmentShader = new QGLShader(QGLShader::FragmentShader, ctx);
- textureBrushFragmentShader->addSource(QLatin1String(fragmentShaderMainSrc));
- textureBrushFragmentShader->addSource(QLatin1String(qglslTextureBrushFragmentShader));
- if (!textureBrushFragmentShader->compile()) {
- qWarning() << "qglslTextureBrushFragmentShader failed to compile:"
- << textureBrushFragmentShader->log();
- }
- }
- fragmentShader = textureBrushFragmentShader;
- break;
- case Qt::LinearGradientPattern:
- if (!linearBrushVertexShader) {
- qDebug("Compiling qglslLinearGradientBrushVertexShader");
- linearBrushVertexShader = new QGLShader(QGLShader::VertexShader, ctx);
- linearBrushVertexShader->addSource(QLatin1String(qglslLinearGradientBrushVertexShader));
- if (!linearBrushVertexShader->compile()) {
- qWarning() << "qglslLinearGradientBrushVertexShader failed to compile: "
- << linearBrushVertexShader->log();
- }
- }
- vertexShader = linearBrushVertexShader;
-
- if (!linearBrushFragmentShader) {
- qDebug("Compiling qglslLinearGradientBrushFragmentShader");
- linearBrushFragmentShader = new QGLShader(QGLShader::FragmentShader, ctx);
- linearBrushFragmentShader->addSource(QLatin1String(fragmentShaderMainSrc));
- linearBrushFragmentShader->addSource(QLatin1String(qglslLinearGradientBrushFragmentShader));
- if (!linearBrushFragmentShader->compile()) {
- qWarning() << "qglslLinearGradientBrushFragmentShader failed to compile:"
- << linearBrushFragmentShader->log();
- }
- }
- fragmentShader = linearBrushFragmentShader;
- break;
- case Qt::RadialGradientPattern:
- if (!radialBrushVertexShader) {
- qDebug("Compiling qglslRadialGradientBrushVertexShader");
- radialBrushVertexShader = new QGLShader(QGLShader::VertexShader, ctx);
- radialBrushVertexShader->addSource(QLatin1String(qglslRadialGradientBrushVertexShader));
- if (!radialBrushVertexShader->compile()) {
- qWarning() << "qglslRadialGradientBrushVertexShader failed to compile: "
- << radialBrushVertexShader->log();
- }
- }
- vertexShader = radialBrushVertexShader;
-
- if (!radialBrushFragmentShader) {
- qDebug("Compiling qglslRadialGradientBrushFragmentShader");
- radialBrushFragmentShader = new QGLShader(QGLShader::FragmentShader, ctx);
- radialBrushFragmentShader->addSource(QLatin1String(fragmentShaderMainSrc));
- radialBrushFragmentShader->addSource(QLatin1String(qglslRadialGradientBrushFragmentShader));
- if (!radialBrushFragmentShader->compile()) {
- qWarning() << "qglslRadialGradientBrushFragmentShader failed to compile:"
- << radialBrushFragmentShader->log();
- }
- }
- fragmentShader = radialBrushFragmentShader;
- break;
- case Qt::ConicalGradientPattern:
- // FIXME: We currently use the same vertex shader as radial brush
- if (!conicalBrushVertexShader) {
- qDebug("Compiling qglslConicalGradientBrushVertexShader");
- conicalBrushVertexShader = new QGLShader(QGLShader::VertexShader, ctx);
- conicalBrushVertexShader->addSource(QLatin1String(qglslConicalGradientBrushVertexShader));
- if (!conicalBrushVertexShader->compile()) {
- qWarning() << "qglslConicalGradientBrushVertexShader failed to compile: "
- << conicalBrushVertexShader->log();
- }
- }
- vertexShader = conicalBrushVertexShader;
-
- if (!conicalBrushFragmentShader) {
- qDebug("Compiling qglslConicalGradientBrushFragmentShader");
- conicalBrushFragmentShader = new QGLShader(QGLShader::FragmentShader, ctx);
- conicalBrushFragmentShader->addSource(QLatin1String(fragmentShaderMainSrc));
- conicalBrushFragmentShader->addSource(QLatin1String(qglslConicalGradientBrushFragmentShader));
- if (!conicalBrushFragmentShader->compile()) {
- qWarning() << "qglslConicalGradientBrushFragmentShader failed to compile:"
- << conicalBrushFragmentShader->log();
- }
- }
- fragmentShader = conicalBrushFragmentShader;
- break;
- case Qt::Dense1Pattern:
- case Qt::Dense2Pattern:
- case Qt::Dense3Pattern:
- case Qt::Dense4Pattern:
- case Qt::Dense5Pattern:
- case Qt::Dense6Pattern:
- case Qt::Dense7Pattern:
- case Qt::HorPattern:
- case Qt::VerPattern:
- case Qt::CrossPattern:
- case Qt::BDiagPattern:
- case Qt::FDiagPattern:
- case Qt::DiagCrossPattern:
- if (!patternBrushVertexShader) {
- qDebug("Compiling qglslPatternBrushVertexShader");
- patternBrushVertexShader = new QGLShader(QGLShader::VertexShader, ctx);
- patternBrushVertexShader->addSource(QLatin1String(qglslPatternBrushVertexShader));
- if (!patternBrushVertexShader->compile()) {
- qWarning() << "qglslPatternBrushVertexShader failed to compile: "
- << patternBrushVertexShader->log();
- }
- }
- vertexShader = patternBrushVertexShader;
-
- if (!patternBrushFragmentShader) {
- qDebug("Compiling qglslPatternBrushFragmentShader");
- patternBrushFragmentShader = new QGLShader(QGLShader::FragmentShader, ctx);
- patternBrushFragmentShader->addSource(QLatin1String(qglslNoOpacityFragmentShaderMain));
- patternBrushFragmentShader->addSource(QLatin1String(qglslPatternBrushFragmentShader));
- if (!patternBrushFragmentShader->compile()) {
- qWarning() << "qglslPatternBrushFragmentShader failed to compile:"
- << patternBrushFragmentShader->log();
- }
- }
- fragmentShader = patternBrushFragmentShader;
- break;
- default:
- qWarning("Unimplemented brush style (%d)", currentBrushStyle);
- }
-
- // Now newBrushShader is set correctly, check to see if we already have the program
- // already linked and ready to go in the cache:
- bool foundProgram = false;
- foreach (QGLCachedShaderProg cachedProg, cachedPrograms) {
- if ((cachedProg.vertexShader == vertexShader) &&
- (cachedProg.brushShader == fragmentShader) &&
- (cachedProg.compositionShader == 0) ) {
-
- activeProgram = cachedProg.shader;
- foundProgram = true;
- break;
- }
- }
-
- if (!foundProgram) {
- qDebug() << "Linking shader program for " << currentBrushStyle;
- // Required program not found - create it.
- QGLShaderProgram* newProg = new QGLShaderProgram(ctx);
-
- newProg->addShader(vertexShader);
- newProg->addShader(fragmentShader);
-
- if (!newProg->link())
- qWarning() << "Shader program for " << currentBrushStyle << "failed to link:" << newProg->log();
-
- QGLCachedShaderProg cachedProg;
- cachedProg.vertexShader = vertexShader;
- cachedProg.brushShader = fragmentShader;
- cachedProg.compositionShader = 0;
- cachedProg.shader = newProg;
-
- cachedPrograms.append(cachedProg);
- activeProgram = newProg;
- }
-
- activeProgram->use();
- shaderProgNeedsChanging = false;
- return true;
-}
-
-QGLShaderProgram* QGLPEXShaderManager::brushShader()
-{
- return activeProgram;
-}
-
-// The only uniform the simple shader has is the PMV matrix
-QGLShaderProgram* QGLPEXShaderManager::simpleShader()
-{
- if (!simpleShaderProgram) {
- simpleShaderProgram = new QGLShaderProgram(ctx);
-
- if (!simpleFragmentShader) {
- simpleFragmentShader = new QGLShader(QGLShader::FragmentShader, ctx);
- simpleFragmentShader->addSource(QLatin1String(qglslSimpleFragmentShader));
- if (!simpleFragmentShader->compile())
- qWarning() << "qglslSimpleFragmentShader failed to compile:" << simpleFragmentShader->log();
- }
-
- simpleShaderProgram->addShader(defaultVertexShader);
- simpleShaderProgram->addShader(simpleFragmentShader);
- if (!simpleShaderProgram->link())
- qWarning() << "Simple shader program failed to link:" << simpleShaderProgram->log();
- }
-
- return simpleShaderProgram;
-}
-
-QGLShaderProgram* QGLPEXShaderManager::imageShader()
-{
- if (!imageShaderProgram) {
- if (!imageVertexShader) {
- imageVertexShader = new QGLShader(QGLShader::VertexShader, ctx);
- imageVertexShader->addSource(QLatin1String(qglslImageVertexShader));
- if (!imageVertexShader->compile())
- qWarning() << "Image/Pixmap vertex shader failed to compile:" << imageVertexShader->log();
- }
-
- if (!imageFragmentShader) {
- imageFragmentShader = new QGLShader(QGLShader::FragmentShader, ctx);
- imageFragmentShader->addSource(QLatin1String(qglslImageFragmentShader));
- if (!imageFragmentShader->compile())
- qWarning() << "Image/Pixmap fragment shader failed to compile:" << imageFragmentShader->log();
- }
-
- imageShaderProgram = new QGLShaderProgram(ctx);
- imageShaderProgram->addShader(imageVertexShader);
- imageShaderProgram->addShader(imageFragmentShader);
- if (!imageShaderProgram->link())
- qWarning() << "Image/Pixmap shader program failed to link:" << imageShaderProgram->log();
- }
-
- return imageShaderProgram;
-}
-
-QGLShaderProgram* QGLPEXShaderManager::textShader()
-{
- if (!textShaderProgram) {
- if (!textVertexShader) {
- textVertexShader = new QGLShader(QGLShader::VertexShader, ctx);
- textVertexShader->addSource(QLatin1String(qglslImageVertexShader));
- if (!textVertexShader->compile())
- qWarning() << "Text vertex shader failed to compile:" << textVertexShader->log();
- }
-
- if (!textFragmentShader) {
- textFragmentShader = new QGLShader(QGLShader::FragmentShader, ctx);
- textFragmentShader->addSource(QLatin1String(qglslTextFragmentShader));
- if (!textFragmentShader->compile())
- qWarning() << "Text fragment shader failed to compile:" << textFragmentShader->log();
- }
-
- textShaderProgram = new QGLShaderProgram(ctx);
- textShaderProgram->addShader(textVertexShader);
- textShaderProgram->addShader(textFragmentShader);
- if (!textShaderProgram->link())
- qWarning() << "Text shader program failed to link:" << textShaderProgram->log();
- }
-
- return textShaderProgram;
-}
-
diff --git a/src/opengl/gl2paintengineex/qglpexshadermanager_p.h b/src/opengl/gl2paintengineex/qglpexshadermanager_p.h
deleted file mode 100644
index c8f47b2..0000000
--- a/src/opengl/gl2paintengineex/qglpexshadermanager_p.h
+++ /dev/null
@@ -1,156 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtOpenGL module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// 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 "qglshader_p.h"
-
-
-// Worstcase combo: Brush->Mask->Composition
-
-/*
- Vertex shader source is specified with a single string. This string
- contains the main function and sets the gl_Position. The choice of
- which vertex shader to use depends on:
- - Brush style
- - Brush transform->isAffine()
-
- Fragment shaders are specified as multiple strings, one for the main
- function, one for the brush calculation and optionally one for the
- extended composition mode. Brushes are implementations of
- "mediump vec4 brush()"
- Composition modes are implemented as a
- "mediump vec4 compose(mediump vec4 color)"
- NOTE: Precision may change in future.
-
- The choice of which main() fragment shader string to use depends on:
- - Global opacity
- - Brush style (some brushes apply opacity themselves)
- - Use of mask (TODO: Need to support high quality anti-aliasing & text)
- - Composition mode
-
- The choice of which brush() fragment shader to use depends on:
- - Brush style
-
-*/
-
-
-struct QGLCachedShaderProg
-{
- QGLShader* vertexShader;
- QGLShader* brushShader;
- QGLShader* compositionShader;
- QGLShaderProgram* shader;
-};
-
-class QGLPEXShaderManager
-{
-public:
- QGLPEXShaderManager(const QGLContext* context);
- ~QGLPEXShaderManager();
-
- enum TransformType {IdentityTransform, ScaleTransform, TranslateTransform, FullTransform};
-
- void optimiseForBrushTransform(const QTransform& transform);
- void setBrushStyle(Qt::BrushStyle style);
- void setUseGlobalOpacity(bool value);
- void setAffineOnlyBrushTransform(bool value); // I.e. Do we need to apply perspective-correction?
- // Not doing so saves some vertex shader calculations.
-
- bool useCorrectShaderProg(); // returns true if the shader program has changed
-
- QGLShaderProgram* brushShader();
- QGLShaderProgram* simpleShader(); // Used to draw into e.g. stencil buffers
- QGLShaderProgram* imageShader();
- QGLShaderProgram* textShader();
-
-private:
- QGLShader* defaultVertexShader;
-
- QGLShader* imageVertexShader;
- QGLShader* imageFragmentShader;
- QGLShaderProgram* imageShaderProgram;
-
- QGLShader* textVertexShader;
- QGLShader* textFragmentShader;
- QGLShaderProgram* textShaderProgram;
-
- QGLShader* noBrushShader;
- QGLShader* solidBrushShader;
-
- QGLShader* conicalBrushVertexShader;
- QGLShader* conicalBrushFragmentShader;
-
- QGLShader* radialBrushVertexShader;
- QGLShader* radialBrushFragmentShader;
-
- QGLShader* linearBrushVertexShader;
- QGLShader* linearBrushFragmentShader;
-
- QGLShader* patternBrushVertexShader;
- QGLShader* patternBrushFragmentShader;
-
- QGLShader* textureBrushFragmentShader;
- QGLShader* textureBrushVertexShader;
-
- QGLShader* simpleFragmentShader;
- QGLShaderProgram* simpleShaderProgram;
-
- QGLShaderProgram* activeProgram;
-
- Qt::BrushStyle currentBrushStyle;
- bool useGlobalOpacity;
- TransformType currentTransformType;
- bool shaderProgNeedsChanging;
-
- QList<QGLCachedShaderProg> cachedPrograms;
-
- QGLContext* ctx;
-};
diff --git a/src/opengl/gl2paintengineex/qglshader.cpp b/src/opengl/gl2paintengineex/qglshader.cpp
deleted file mode 100644
index 634be84..0000000
--- a/src/opengl/gl2paintengineex/qglshader.cpp
+++ /dev/null
@@ -1,605 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtOpenGL module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qglshader_p.h"
-
-
-// Windows needs to resolve OpenGL 2.0 function pointers for each context. The
-// QGL OpenGL 2.0 functions are actually macros, which take a "ctx" parameter.
-#define Q_CTX QGLContext* ctx = d->ctx; \
- if (!ctx) \
- return false; \
- ctx->makeCurrent(); \
-
-
-
-
-class QGLShaderPrivate
-{
-public:
- QGLShaderPrivate() : shaderId(0), valid(false), ctx(0) {}
-
- GLuint shaderId;
- QString source;
- bool valid;
- QGLShader::ShaderType type;
- QGLContext* ctx;
-};
-
-
-QGLShader::QGLShader(QGLShader::ShaderType type, const QGLContext* ctx)
- : d_ptr(new QGLShaderPrivate)
-{
- Q_D(QGLShader);
-
- if (!ctx)
- ctx = QGLContext::currentContext();
-
- if (!ctx) {
- qWarning("QGLShader being created without a context");
- return;
- }
-
- d->ctx = const_cast<QGLContext*>(ctx);
- d->ctx->makeCurrent();
-
- if (type == QGLShader::FragmentShader)
- d->shaderId = glCreateShader(GL_FRAGMENT_SHADER);
- else
- d->shaderId = glCreateShader(GL_VERTEX_SHADER);
-
- if (d->shaderId == 0) {
- qWarning("Error creating shader object");
- return;
- }
-
- d->type = type;
-}
-
-GLuint QGLShader::id()
-{
- Q_D(QGLShader);
- return d->shaderId;
-}
-
-const QGLContext* QGLShader::context()
-{
- Q_D(QGLShader);
- return d->ctx;
-}
-
-void QGLShader::clearSource()
-{
- Q_D(QGLShader);
- d->source.clear();
- d->valid = false;
-}
-
-void QGLShader::addSource(const QLatin1String& newSource)
-{
- Q_D(QGLShader);
- d->source += newSource;
- d->valid = false;
-}
-
-
-bool QGLShader::compile()
-{
- Q_D(QGLShader);
-
- d->valid = false;
-
- if (d->source.size() == 0)
- return false;
-
- const QByteArray src_ba = d->source.toAscii();
- const char* src = src_ba.constData();
-
- glShaderSource(d->shaderId, 1, &src, 0);
-
- glCompileShader(d->shaderId);
-
- GLint shaderCompiled;
- glGetShaderiv(d->shaderId, GL_COMPILE_STATUS, &shaderCompiled);
- if (!shaderCompiled)
- return false;
-
- d->valid = true;
- return true;
-}
-
-bool QGLShader::isValid()
-{
- Q_D(QGLShader);
- return d->valid;
-}
-
-QString QGLShader::log()
-{
- Q_D(QGLShader);
-
- char* logData;
- GLint logSize;
- GLint logLength;
-
- glGetShaderiv(d->shaderId, GL_INFO_LOG_LENGTH, &logSize);
-
- if (!logSize)
- return QString();
-
- logData = new char[logSize];
- glGetShaderInfoLog(d->shaderId, logSize, &logLength, logData);
- QString result = QString::fromAscii(logData);
- delete [] logData;
-
- return result;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-class QGLShaderProgramPrivate
-{
-public:
- QGLShaderProgramPrivate() : valid(false), programId(0), ctx(0) {}
- void populateVariableLists();
-
- QVector<QGLShader*> shaders;
- QGLUniformList uniforms;
- QGLVertexAttributeList attributeArrays;
- bool valid;
- GLuint programId;
- QGLContext* ctx;
-};
-
-
-
-void QGLShaderProgramPrivate::populateVariableLists()
-{
- attributeArrays.clear();
- uniforms.clear();
-
- int count;
- int sizeOfNameBuff;
- char* name;
- GLint nameLength;
- GLenum type;
- GLint size;
- GLint location;
-
- glGetProgramiv(programId, GL_ACTIVE_ATTRIBUTES, &count);
- glGetProgramiv(programId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &sizeOfNameBuff);
- name = new char[sizeOfNameBuff];
-
- for (int i = 0; i < count; ++i) {
- nameLength = -1;
- glGetActiveAttrib(programId, i, sizeOfNameBuff, &nameLength, &size, &type, name);
- if (nameLength == -1)
- continue;
-
- location = glGetAttribLocation(programId, name);
- attributeArrays.insert(QString::fromAscii(name), QGLVertexAttribute(type, location, ctx));
- }
-
- delete [] name;
-
-
- glGetProgramiv(programId, GL_ACTIVE_UNIFORMS, &count);
- glGetProgramiv(programId, GL_ACTIVE_UNIFORM_MAX_LENGTH, &sizeOfNameBuff);
-
- name = new char[sizeOfNameBuff];
-
- for (int i = 0; i < count; ++i) {
- nameLength = -1;
- glGetActiveUniform(programId, i, sizeOfNameBuff, &nameLength, &size, &type, name);
- if (nameLength == -1)
- continue;
-
- location = glGetUniformLocation(programId, name);
- uniforms.insert(QString::fromAscii(name), QGLUniform(type, location, ctx));
- }
-}
-
-
-QGLShaderProgram::QGLShaderProgram(const QGLContext* ctx)
- : d_ptr(new QGLShaderProgramPrivate)
-{
- Q_D(QGLShaderProgram);
- if (!ctx)
- ctx = QGLContext::currentContext();
-
- if (!ctx) {
- qWarning("QGLShaderProgram being created without a context");
- return;
- }
-
- d->ctx = const_cast<QGLContext*>(ctx);
- d->ctx->makeCurrent();
-
- d->programId = glCreateProgram();
-
- d->valid = false;
-}
-
-
-const QGLUniformList & QGLShaderProgram::uniforms()
-{
- Q_D(QGLShaderProgram);
- return const_cast<const QGLUniformList&>(d->uniforms);
-}
-
-
-const QGLVertexAttributeList& QGLShaderProgram::vertexAttributes()
-{
- Q_D(QGLShaderProgram);
- return const_cast<const QGLVertexAttributeList&>(d->attributeArrays);
-}
-
-
-bool QGLShaderProgram::addShader(QGLShader* newShader)
-{
- Q_D(QGLShaderProgram);
- if (!newShader || !d->ctx)
- return false;
-
- if (newShader->context() != d->ctx) {
- qWarning("Shader object's context does not match program's context");
- return false;
- }
-
- if (!newShader->isValid())
- return false;
-
- QGLContext* ctx = d->ctx;
- if (!ctx)
- return false;
- ctx->makeCurrent();
-
- glAttachShader(d->programId, newShader->id());
-
- d->shaders.append(newShader);
- return true;
-}
-
-
-bool QGLShaderProgram::removeShader(QGLShader* oldShader)
-{
- Q_D(QGLShaderProgram);
-
- int idx = d->shaders.indexOf(oldShader);
-
- if (idx == -1)
- return false;
-
- d->shaders.remove(idx);
-
- QGLContext* ctx = d->ctx;
- if (!ctx)
- return false;
- ctx->makeCurrent();
-
- glDetachShader(d->programId, oldShader->id());
- return true;
-}
-
-
-bool QGLShaderProgram::removeAllShaders()
-{
- Q_D(QGLShaderProgram);
-
- QGLContext* ctx = d->ctx;
- if (!ctx)
- return false;
- ctx->makeCurrent();
-
- foreach (QGLShader* shader, d->shaders)
- glDetachShader(d->programId, shader->id());
-
- d->shaders.clear();
- return true;
-}
-
-#include <stdio.h>
-
-bool QGLShaderProgram::link()
-{
- Q_D(QGLShaderProgram);
-
- QGLContext* ctx = d->ctx;
- if (!ctx)
- return false;
- ctx->makeCurrent();
-
- glLinkProgram(d->programId);
-
-
- GLint linked;
- glGetProgramiv(d->programId, GL_LINK_STATUS, &linked);
-
- if (!linked)
- return false;
-
- d->populateVariableLists();
-
- d->valid = true;
- return true;
-}
-
-void QGLShaderProgram::use()
-{
- Q_D(QGLShaderProgram);
- if (!d->valid)
- return;
-
- glUseProgram(d->programId);
-}
-
-
-QString QGLShaderProgram::log()
-{
- Q_D(QGLShaderProgram);
-
- QGLContext* ctx = d->ctx;
- if (!ctx)
- return QString();
- ctx->makeCurrent();
-
- GLint logSize = -666;
- glGetProgramiv(d->programId, GL_INFO_LOG_LENGTH, &logSize);
-
- char* logData = new char[logSize];
- GLint logLength;
-
- glGetProgramInfoLog(d->programId, logSize, &logLength, logData);
-
- QString result = QString::fromAscii(logData);
- delete [] logData;
-
- return result;
-}
-
-GLuint QGLShaderProgram::id()
-{
- Q_D(QGLShaderProgram);
- return d->programId;
-}
-
-/////////////////////////////////////////////////////////////////////////
-
-
-
-
-QGLUniform::QGLUniform()
- : m_id(0), m_type(QGLInvalidType), ctx(0)
-{
- qWarning("Unknown uniform! Either the uniform doesn't exist or it was removed at shader link");
-}
-
-const QGLUniform& QGLUniform::operator=(const GLfloat& rhs) const
-{
- if (m_type != QGLFloatType)
- return *this;
-
- glUniform1f(m_id, rhs);
-
- return *this;
-}
-
-const QGLUniform& QGLUniform::operator=(const QGLVec2& rhs) const
-{
- if (m_type != QGLVec2Type)
- return *this;
-
- glUniform2fv(m_id, 1, (const GLfloat*)&rhs);
-
- return *this;
-}
-
-const QGLUniform& QGLUniform::operator=(const QSizeF& rhs) const
-{
- if (m_type != QGLVec2Type)
- return *this;
-
- glUniform2f(m_id, rhs.width(), rhs.height());
-
- return *this;
-}
-
-const QGLUniform& QGLUniform::operator=(const QPointF& rhs) const
-{
- if (m_type != QGLVec2Type)
- return *this;
-
- glUniform2f(m_id, rhs.x(), rhs.y());
-
- return *this;
-}
-
-const QGLUniform& QGLUniform::operator=(const QGLVec3& rhs) const
-{
- if (m_type != QGLVec3Type)
- return *this;
-
- glUniform3fv(m_id, 1, (const GLfloat*)&rhs);
-
- return *this;
-}
-
-const QGLUniform& QGLUniform::operator=(const QGLVec4& rhs) const
-{
- if (m_type != QGLVec4Type)
- return *this;
-
- glUniform4fv(m_id, 1, (const GLfloat*)&rhs);
-
- return *this;
-}
-
-const QGLUniform& QGLUniform::operator=(const QColor& rhs) const
-{
- if (m_type != QGLVec4Type)
- return *this;
-
- glUniform4f(m_id, rhs.redF(), rhs.greenF(), rhs.blueF(), rhs.alphaF());
-
- return *this;
-}
-
-const QGLUniform& QGLUniform::operator=(const GLfloat rhs[2][2]) const
-{
- if (m_type != QGLMat2Type)
- return *this;
-
- glUniformMatrix2fv(m_id, 1, GL_FALSE, (GLfloat*)rhs);
-
- return *this;
-}
-
-const QGLUniform& QGLUniform::operator=(const GLfloat rhs[3][3]) const
-{
- if (m_type != QGLMat3Type)
- return *this;
-
- glUniformMatrix3fv(m_id, 1, GL_FALSE, (GLfloat*)rhs);
-
- return *this;
-}
-
-// Transposes ready for GL
-const QGLUniform& QGLUniform::operator=(const QTransform& rhs) const
-{
- if (m_type != QGLMat3Type)
- return *this;
-
- GLfloat mat3[3][3] = {
- {rhs.m11(), rhs.m12(), rhs.m13()},
- {rhs.m21(), rhs.m22(), rhs.m23()},
- {rhs.m31(), rhs.m32(), rhs.m33()}
- };
-
- glUniformMatrix3fv(m_id, 1, GL_FALSE, (GLfloat*)mat3);
-
- return *this;
-}
-
-const QGLUniform& QGLUniform::operator=(const GLfloat rhs[4][4]) const
-{
- if (m_type != QGLMat4Type)
- return *this;
-
- glUniformMatrix4fv(m_id, 1, GL_FALSE, (GLfloat*)rhs);
-
- return *this;
-}
-
-const QGLUniform& QGLUniform::operator=(const GLuint& rhs) const
-{
- if ((m_type != QGLSampler2DType) || (m_type != QGLSamplerCubeType))
- return *this;
-
- glUniform1i(m_id, rhs);
-
- return *this;
-}
-
-
-
-
-/////////////////////////////////////////////////////////////////////////
-
-QGLVertexAttribute::QGLVertexAttribute()
- : m_id(0), m_type(QGLInvalidType), ctx(0)
-{
- qWarning("Unknown vertex attribute!");
-}
-
-void QGLVertexAttribute::enable() const
-{
- glEnableVertexAttribArray(m_id);
-}
-
-void QGLVertexAttribute::disable() const
-{
- glDisableVertexAttribArray(m_id);
-}
-
-// NOTE: Under PC emulation, QGLVec4Type is _always_ returned as the type, so this
-// method isn't very useful. I.e. The datatypes are needed to distinguish the different
-// sizes for the function signatures.
-const QGLVertexAttribute& QGLVertexAttribute::operator=(const GLfloat* rhs) const
-{
- int size = -1;
- if (m_type == QGLFloatType)
- size = 1;
- else if (m_type == QGLVec2Type)
- size = 2;
- else if (m_type == QGLVec3Type)
- size = 3;
- else if (m_type == QGLVec4Type)
- size = 4;
- else if (m_type == QGLMat2Type) //### Not sure if this is right for matrix attributes...
- size = 4;
- else if (m_type == QGLMat3Type) //### Not sure if this is right for matrix attributes...
- size = 9;
- else if (m_type == QGLMat4Type) //### Not sure if this is right for matrix attributes...
- size = 16;
- else
- return *this;
-
- glVertexAttribPointer(m_id, size, GL_FLOAT, GL_FALSE, 0, rhs);
-
- return *this;
-}
-
-const QGLVertexAttribute& QGLVertexAttribute::operator=(const QGLVec3* rhs) const
-{
- glVertexAttribPointer(m_id, 3, GL_FLOAT, GL_FALSE, 0, (GLfloat*)rhs);
-
- return *this;
-}
diff --git a/src/opengl/gl2paintengineex/qglshader_p.h b/src/opengl/gl2paintengineex/qglshader_p.h
deleted file mode 100644
index 1625b84..0000000
--- a/src/opengl/gl2paintengineex/qglshader_p.h
+++ /dev/null
@@ -1,260 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtOpenGL module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, 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.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// 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.
-//
-
-/*
-Uniform Types in OpenGL ES 2.0
-==============================
-GL_FLOAT GLfloat GLfloat
-GL_FLOAT_VEC2 QGLVec2 GLfloat[2]
-GL_FLOAT_VEC3 QGLVec3 GLfloat[3]
-GL_FLOAT_VEC4 QGLVec4 GLfloat[4]
-GL_INT GLint GLint
-GL_INT_VEC2 QGLIVec2 GLint[2]
-GL_INT_VEC3 QGLIVec3 GLint[3]
-GL_INT_VEC4 QGLIVec4 GLint[4]
-GL_BOOL GLbool GLbool
-GL_BOOL_VEC2 QGLBVec2 GLbool[2]
-GL_BOOL_VEC3 QGLBVec3 GLbool[3]
-GL_BOOL_VEC4 QGLBVec4 GLbool[4]
-GL_FLOAT_MAT2 QGLMat2 GLfloat[2][2]
-GL_FLOAT_MAT3 QGLMat3 GLfloat[3][3]
-GL_FLOAT_MAT4 QGLMat4 GLfloat[4][4]
-GL_SAMPLER_2D QGLSampler2D GLuint
-GL_SAMPLER_CUBE QGLSamplerCube GLuint
-
-Additional Types in Desktop OpenGL 2.0
-======================================
-SAMPLER_1D,
-SAMPLER_3D,
-SAMPLER_1D_SHADOW,
-SAMPLER_2D_SHADOW.
-*/
-
-#include <QtOpenGL>
-
-
-typedef struct {
- GLfloat a;
- GLfloat b;
-} QGLVec2;
-
-typedef struct {
- GLfloat a;
- GLfloat b;
- GLfloat c;
-} QGLVec3;
-
-typedef struct {
- GLfloat a;
- GLfloat b;
- GLfloat c;
- GLfloat d;
-} QGLVec4;
-
-
-class QGLShaderProgram;
-
-class QGLShaderPrivate;
-
-class QGLShader : QObject
-{
- Q_OBJECT
-public:
- enum ShaderType {VertexShader, FragmentShader};
-
- QGLShader(ShaderType type, const QGLContext* ctx = 0);
-
- GLuint id();
- void clearSource();
- void addSource(const QLatin1String& newSource);
- bool compile();
- bool isValid();
- QString log();
- const QGLContext* context(); //maybe make private with prog a friend?
-
-private:
- QGLShaderPrivate* d_ptr;
- Q_DECLARE_PRIVATE(QGLShader);
-
-/*
-public slots:
- void cleanupGLContextRefs(const QGLContext *context);
-*/
-};
-
-
-enum QGLType {
- QGLInvalidType = 0,
- QGLFloatType = GL_FLOAT,
- QGLVec2Type = GL_FLOAT_VEC2,
- QGLVec3Type = GL_FLOAT_VEC3,
- QGLVec4Type = GL_FLOAT_VEC4,
- QGLIntType = GL_INT,
- QGLIVec2Type = GL_INT_VEC2,
- QGLIVec3Type = GL_INT_VEC3,
- QGLIVec4Type = GL_INT_VEC4,
- QGLBoolType = GL_BOOL,
- QGLBVec2Type = GL_BOOL_VEC2,
- QGLBVec3Type = GL_BOOL_VEC3,
- QGLBVec4Type = GL_BOOL_VEC4,
- QGLMat2Type = GL_FLOAT_MAT2,
- QGLMat3Type = GL_FLOAT_MAT3,
- QGLMat4Type = GL_FLOAT_MAT4,
- QGLSampler2DType = GL_SAMPLER_2D,
- QGLSamplerCubeType = GL_SAMPLER_CUBE
-};
-
-class QGLUniform
-{
-public:
-
- QGLUniform(GLenum glType, GLint location, QGLContext* context)
- : m_id(location), m_type(QGLType(glType)), ctx(context) {}
-
- QGLUniform(); // Called by QMap when there's no match on the name
-
- QGLType type() const {return m_type;}
- GLuint id() const {return m_id;}
-
- // Seems odd to be const, but it doesn't actually modify any of the
- // class members, only the GL state!
- const QGLUniform& operator=(const GLfloat&) const;
-
- const QGLUniform& operator=(const QGLVec2&) const;
- const QGLUniform& operator=(const QSizeF&) const;
- const QGLUniform& operator=(const QPointF&) const;
-
- const QGLUniform& operator=(const QGLVec3&) const;
-
- const QGLUniform& operator=(const QGLVec4&) const;
- const QGLUniform& operator=(const QColor&) const;
-
- const QGLUniform& operator=(const GLfloat[2][2]) const;
-
- const QGLUniform& operator=(const GLfloat[3][3]) const;
- const QGLUniform& operator=(const QTransform&) const;
-
- const QGLUniform& operator=(const GLfloat[4][4]) const;
-
- const QGLUniform& operator=(const GLuint&) const; // sampler2d, specifying a texture unit
-
-
-protected:
- GLuint m_id;
- QGLType m_type;
- QGLContext* ctx;
-};
-
-typedef QMap<QString, QGLUniform> QGLUniformList;
-typedef QMapIterator<QString, QGLUniform> QGLUniformListIterator;
-
-
-class QGLVertexAttribute
-{
-public:
- QGLVertexAttribute(GLenum glType, GLuint location, QGLContext* context)
- : m_id(location), m_type(QGLType(glType)), ctx(context) {}
-
- QGLVertexAttribute(); // Called by QMap when there's no match on the name
-
- QGLType type() const {return m_type;}
- GLuint id() const {return m_id;}
- void enable() const;
- void disable() const;
-
- const QGLVertexAttribute& operator=(const GLfloat* rhs) const;
- const QGLVertexAttribute& operator=(const QGLVec3* rhs) const;
-
-protected:
- GLuint m_id;
- QGLType m_type;
- QGLContext* ctx;
-};
-
-//TODO: Convert into setter overloads on QGLShaderProgram
-typedef QMap<QString, QGLVertexAttribute> QGLVertexAttributeList;
-typedef QMapIterator<QString, QGLVertexAttribute> QGLVertexAttributeListIterator;
-
-
-
-class QGLShaderProgramPrivate;
-
-class QGLShaderProgram : QObject
-{
- Q_OBJECT
-public:
- QGLShaderProgram(const QGLContext* ctx = 0);
-
- const QGLUniformList & uniforms();
- const QGLVertexAttributeList& vertexAttributes();
-
- bool addShader(QGLShader* newShader);
- bool removeShader(QGLShader* oldShader);
- bool removeAllShaders();
-
- bool link();
- QString log();
- bool isValid();
- void use();
-
- GLuint id();
-
-private:
- QGLShaderProgramPrivate* d_ptr;
- Q_DECLARE_PRIVATE(QGLShaderProgram);
-
-/*
-public slots:
- void cleanupGLContextRefs(const QGLContext *context);
-*/
-};
-
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index a74f044..f174306 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -77,7 +77,7 @@
#include <private/qtextureglyphcache_p.h>
#include "qglgradientcache_p.h"
-#include "qglpexshadermanager_p.h"
+#include "qglengineshadermanager_p.h"
#include "qgl2pexvertexarray_p.h"
@@ -86,10 +86,16 @@ extern QImage qt_imageForBrush(int brushStyle, bool invert); //in qbrush.cpp
#include <QDebug>
+enum EngineMode {
+ ImageDrawingMode,
+ TextDrawingMode,
+ BrushDrawingMode
+};
-static const GLuint QT_VERTEX_COORDS_ATTR = 0;
-static const GLuint QT_TEXTURE_COORDS_ATTR = 1;
-static const GLuint QT_BRUSH_TEXTURE_UNIT = 0;
+static const GLuint QT_BRUSH_TEXTURE_UNIT = 0;
+static const GLuint QT_IMAGE_TEXTURE_UNIT = 0; //Can be the same as brush texture unit
+static const GLuint QT_MASK_TEXTURE_UNIT = 1;
+static const GLuint QT_BACKGROUND_TEXTURE_UNIT = 2;
class QGL2PaintEngineExPrivate : public QPaintEngineExPrivate
{
@@ -114,10 +120,13 @@ public:
void setBrush(const QBrush* brush);
- void drawTexture(const QGLRect& dest, const QGLRect& src, int txtWidth, int txtHeight);
+ void transferMode(EngineMode newMode);
+ // fill, drawOutline, drawTexture & drawCachedGlyphs are the rendering entry points:
void fill(const QVectorPath &path);
void drawOutline(const QVectorPath& path);
+ void drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize);
+ void drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti);
void drawVertexArrays(QGL2PEXVertexArray& vertexArray, GLenum primitive);
// ^ draws whatever is in the vertex array
@@ -127,16 +136,17 @@ public:
// ^ Calls drawVertexArrays to render into stencil buffer
void cleanStencilBuffer(const QGLRect& area);
- void prepareForDraw();
+ void prepareForDraw(bool srcPixelsAreOpaque);
inline void useSimpleShader();
inline QColor premultiplyColor(QColor c, GLfloat opacity);
QGL2PaintEngineEx* q;
-
- //### Move into QGLDrawable
+ QGLDrawable drawable;
int width, height;
- QGLContext* ctx;
+ QGLContext *ctx;
+
+ EngineMode mode;
// Dirty flags
bool matrixDirty; // Implies matrix uniforms are also dirty
@@ -144,24 +154,29 @@ public:
bool brushTextureDirty;
bool brushUniformsDirty;
bool simpleShaderMatrixUniformDirty;
- bool brushShaderMatrixUniformDirty;
- bool imageShaderMatrixUniformDirty;
- bool textShaderMatrixUniformDirty;
+ bool shaderMatrixUniformDirty;
bool stencilBuferDirty;
const QBrush* currentBrush; // May not be the state's brush!
GLfloat inverseScale;
- QGL2PEXVertexArray pathVertexArray;
+ QGL2PEXVertexArray vertexCoordinateArray;
+ QGL2PEXVertexArray textureCoordinateArray;
+
+ GLfloat staticVertexCoordinateArray[8];
+ GLfloat staticTextureCoordinateArray[8];
GLfloat pmvMatrix[4][4];
- QGLPEXShaderManager* shaderManager;
+ QGLEngineShaderManager* shaderManager;
// Clipping & state stuff stolen from QOpenGLPaintEngine:
void updateDepthClip();
+ void systemStateChanged();
uint use_system_clip : 1;
+
+ QPaintEngine *last_engine;
};
@@ -177,7 +192,7 @@ QGL2PaintEngineExPrivate::~QGL2PaintEngineExPrivate()
void QGL2PaintEngineExPrivate::updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform)
{
- glActiveTexture(QT_BRUSH_TEXTURE_UNIT);
+// glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); //### Is it always this texture unit?
if (smoothPixmapTransform) {
glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -206,27 +221,27 @@ void QGL2PaintEngineExPrivate::setBrush(const QBrush* brush)
currentBrush = brush;
brushTextureDirty = true;
brushUniformsDirty = true;
- shaderManager->setBrushStyle(currentBrush->style());
- shaderManager->setAffineOnlyBrushTransform(currentBrush->transform().isAffine());
+ shaderManager->setSrcPixelType(currentBrush->style());
+ shaderManager->optimiseForBrushTransform(currentBrush->transform());
}
// Unless this gets used elsewhere, it's probably best to merge it into fillStencilWithVertexArray
void QGL2PaintEngineExPrivate::useSimpleShader()
{
- shaderManager->simpleShader()->use();
+ shaderManager->simpleProgram()->enable();
if (matrixDirty)
updateMatrix();
if (simpleShaderMatrixUniformDirty) {
- shaderManager->simpleShader()->uniforms()[QLatin1String("pmvMatrix")] = pmvMatrix;
+ shaderManager->simpleProgram()->setUniformValue("pmvMatrix", pmvMatrix);
simpleShaderMatrixUniformDirty = false;
}
}
-Q_GLOBAL_STATIC(QGLGradientCache, qt_opengl_gradient_cache)
+Q_GLOBAL_STATIC(QGL2GradientCache, qt_opengl_gradient_cache)
void QGL2PaintEngineExPrivate::updateBrushTexture()
{
@@ -237,7 +252,7 @@ void QGL2PaintEngineExPrivate::updateBrushTexture()
// Get the image data for the pattern
QImage texImage = qt_imageForBrush(style, true);
- glActiveTexture(QT_BRUSH_TEXTURE_UNIT);
+ glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT);
ctx->d_func()->bindTexture(texImage, GL_TEXTURE_2D, GL_RGBA, true);
updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, true);
}
@@ -257,12 +272,13 @@ void QGL2PaintEngineExPrivate::updateBrushTexture()
else
updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, true);
+ glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT);
glBindTexture(GL_TEXTURE_2D, texId);
}
else if (style == Qt::TexturePattern) {
const QPixmap& texPixmap = currentBrush->texture();
- glActiveTexture(QT_BRUSH_TEXTURE_UNIT);
+ glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT);
ctx->d_func()->bindTexture(texPixmap, GL_TEXTURE_2D, GL_RGBA, true);
updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, true);
}
@@ -278,17 +294,11 @@ void QGL2PaintEngineExPrivate::updateBrushUniforms()
if (style == Qt::NoBrush)
return;
- GLfloat opacity = 1.0;
- if (q->state()->opacity < 0.99f)
- opacity = (GLfloat)q->state()->opacity;
- bool setOpacity = true;
-
QTransform brushQTransform = currentBrush->transform();
if (style == Qt::SolidPattern) {
- QColor col = premultiplyColor(currentBrush->color(), opacity);
- shaderManager->brushShader()->uniforms()[QLatin1String("fragmentColor")] = col;
- setOpacity = false;
+ QColor col = premultiplyColor(currentBrush->color(), (GLfloat)q->state()->opacity);
+ shaderManager->currentProgram()->setUniformValue("fragmentColor", col);
}
else {
// All other brushes have a transform and thus need the translation point:
@@ -297,13 +307,12 @@ void QGL2PaintEngineExPrivate::updateBrushUniforms()
if (style <= Qt::DiagCrossPattern) {
translationPoint = q->state()->brushOrigin;
- QColor col = premultiplyColor(currentBrush->color(), opacity);
+ QColor col = premultiplyColor(currentBrush->color(), (GLfloat)q->state()->opacity);
- shaderManager->brushShader()->uniforms()[QLatin1String("patternColor")] = col;
- setOpacity = false; //So code below doesn't try to set the opacity uniform
+ shaderManager->currentProgram()->setUniformValue("patternColor", col);
- QGLVec2 halfViewportSize = { width*0.5, height*0.5 };
- shaderManager->brushShader()->uniforms()[QLatin1String("halfViewportSize")] = halfViewportSize;
+ QVector2D halfViewportSize(width*0.5, height*0.5);
+ shaderManager->currentProgram()->setUniformValue("halfViewportSize", halfViewportSize);
}
else if (style == Qt::LinearGradientPattern) {
const QLinearGradient *g = static_cast<const QLinearGradient *>(currentBrush->gradient());
@@ -314,17 +323,16 @@ void QGL2PaintEngineExPrivate::updateBrushUniforms()
QPointF l = realFinal - realStart;
- // ###
- QGLVec3 linearData = {
+ QVector3D linearData(
l.x(),
l.y(),
1.0f / (l.x() * l.x() + l.y() * l.y())
- };
+ );
- shaderManager->brushShader()->uniforms()[QLatin1String("linearData")] = linearData;
+ shaderManager->currentProgram()->setUniformValue("linearData", linearData);
- QGLVec2 halfViewportSize = { width*0.5, height*0.5 };
- shaderManager->brushShader()->uniforms()[QLatin1String("halfViewportSize")] = halfViewportSize;
+ QVector2D halfViewportSize(width*0.5, height*0.5);
+ shaderManager->currentProgram()->setUniformValue("halfViewportSize", halfViewportSize);
}
else if (style == Qt::ConicalGradientPattern) {
const QConicalGradient *g = static_cast<const QConicalGradient *>(currentBrush->gradient());
@@ -332,10 +340,10 @@ void QGL2PaintEngineExPrivate::updateBrushUniforms()
GLfloat angle = -(g->angle() * 2 * Q_PI) / 360.0;
- shaderManager->brushShader()->uniforms()[QLatin1String("angle")] = angle;
+ shaderManager->currentProgram()->setUniformValue("angle", angle);
- QGLVec2 halfViewportSize = { width*0.5, height*0.5 };
- shaderManager->brushShader()->uniforms()[QLatin1String("halfViewportSize")] = halfViewportSize;
+ QVector2D halfViewportSize(width*0.5, height*0.5);
+ shaderManager->currentProgram()->setUniformValue("halfViewportSize", halfViewportSize);
}
else if (style == Qt::RadialGradientPattern) {
const QRadialGradient *g = static_cast<const QRadialGradient *>(currentBrush->gradient());
@@ -345,16 +353,15 @@ void QGL2PaintEngineExPrivate::updateBrushUniforms()
translationPoint = realFocal;
QPointF fmp = realCenter - realFocal;
- shaderManager->brushShader()->uniforms()[QLatin1String("fmp")] = fmp;
+ shaderManager->currentProgram()->setUniformValue("fmp", fmp);
GLfloat fmp2_m_radius2 = -fmp.x() * fmp.x() - fmp.y() * fmp.y() + realRadius*realRadius;
- shaderManager->brushShader()->uniforms()[QLatin1String("fmp2_m_radius2")] = fmp2_m_radius2;
-
- shaderManager->brushShader()->uniforms()[QLatin1String("inverse_2_fmp2_m_radius2")] =
- GLfloat(1.0 / (2.0*fmp2_m_radius2));
+ shaderManager->currentProgram()->setUniformValue("fmp2_m_radius2", fmp2_m_radius2);
+ shaderManager->currentProgram()->setUniformValue("inverse_2_fmp2_m_radius2",
+ GLfloat(1.0 / (2.0*fmp2_m_radius2)));
- QGLVec2 halfViewportSize = { width*0.5, height*0.5 };
- shaderManager->brushShader()->uniforms()[QLatin1String("halfViewportSize")] = halfViewportSize;
+ QVector2D halfViewportSize(width*0.5, height*0.5);
+ shaderManager->currentProgram()->setUniformValue("halfViewportSize", halfViewportSize);
}
else if (style == Qt::TexturePattern) {
translationPoint = q->state()->brushOrigin;
@@ -362,10 +369,10 @@ void QGL2PaintEngineExPrivate::updateBrushUniforms()
const QPixmap& texPixmap = currentBrush->texture();
QSizeF invertedTextureSize( 1.0 / texPixmap.width(), 1.0 / texPixmap.height() );
- shaderManager->brushShader()->uniforms()[QLatin1String("invertedTextureSize")] = invertedTextureSize;
+ shaderManager->currentProgram()->setUniformValue("invertedTextureSize", invertedTextureSize);
- QGLVec2 halfViewportSize = { width*0.5, height*0.5 };
- shaderManager->brushShader()->uniforms()[QLatin1String("halfViewportSize")] = halfViewportSize;
+ QVector2D halfViewportSize(width*0.5, height*0.5);
+ shaderManager->currentProgram()->setUniformValue("halfViewportSize", halfViewportSize);
}
else
qWarning("QGL2PaintEngineEx: Unimplemented fill style");
@@ -374,11 +381,8 @@ void QGL2PaintEngineExPrivate::updateBrushUniforms()
QTransform gl_to_qt(1, 0, 0, -1, 0, height);
QTransform inv_matrix = gl_to_qt * (brushQTransform * q->state()->matrix).inverted() * translate;
- shaderManager->brushShader()->uniforms()[QLatin1String("brushTransform")] = inv_matrix;
- shaderManager->brushShader()->uniforms()[QLatin1String("brushTexture")] = QT_BRUSH_TEXTURE_UNIT;
-
- if (setOpacity)
- shaderManager->brushShader()->uniforms()[QLatin1String("opacity")] = opacity;
+ shaderManager->currentProgram()->setUniformValue("brushTransform", inv_matrix);
+ shaderManager->currentProgram()->setUniformValue("brushTexture", QT_BRUSH_TEXTURE_UNIT);
}
brushUniformsDirty = false;
}
@@ -397,38 +401,51 @@ void QGL2PaintEngineExPrivate::updateMatrix()
{0.0, 0.0, 0.0, 1.0}
};
- // Use the (3x3) transform for the Model~View matrix:
const QTransform& transform = q->state()->matrix;
- GLfloat MV[4][4] = {
- {transform.m11(), transform.m21(), 0.0, transform.dx() + 0.5},
- {transform.m12(), transform.m22(), 0.0, transform.dy() + 0.5},
- {0.0, 0.0, 1.0, 0.0},
- {transform.m13(), transform.m23(), 0.0, transform.m33()}
- };
- // NOTE: OpenGL ES works with column-major matrices, so when we multiply the matrices,
- // we also transpose them ready for GL.
- for (int row = 0; row < 4; ++row) {
- for (int col = 0; col < 4; ++col) {
- pmvMatrix[col][row] = 0.0;
- for (int n = 0; n < 4; ++n)
- pmvMatrix[col][row] += P[row][n] * MV[n][col];
+ if (mode == TextDrawingMode) {
+ // Text drawing mode is only used for non-scaling transforms
+ for (int row = 0; row < 4; ++row)
+ for (int col = 0; col < 4; ++col)
+ pmvMatrix[col][row] = P[row][col];
+
+ pmvMatrix[3][0] += P[0][0] * qRound(transform.dx());
+ pmvMatrix[3][1] += P[1][1] * qRound(transform.dy());
+
+ inverseScale = 1;
+ } else {
+ // Use the (3x3) transform for the Model~View matrix:
+ GLfloat MV[4][4] = {
+ {transform.m11(), transform.m21(), 0.0, transform.dx()},
+ {transform.m12(), transform.m22(), 0.0, transform.dy()},
+ {0.0, 0.0, 1.0, 0.0},
+ {transform.m13(), transform.m23(), 0.0, transform.m33()}
+ };
+
+ // NOTE: OpenGL ES works with column-major matrices, so when we multiply the matrices,
+ // we also transpose them ready for GL.
+ for (int row = 0; row < 4; ++row) {
+ for (int col = 0; col < 4; ++col) {
+ pmvMatrix[col][row] = 0.0;
+
+ // P[row][n] is 0.0 for n < row
+ for (int n = row; n < 4; ++n)
+ pmvMatrix[col][row] += P[row][n] * MV[n][col];
+ }
}
- }
- // 1/10000 == 0.0001, so we have good enough res to cover curves
- // that span the entire widget...
- inverseScale = qMax(1 / qMax( qMax(qAbs(transform.m11()), qAbs(transform.m22())),
- qMax(qAbs(transform.m12()), qAbs(transform.m21())) ),
- qreal(0.0001));
+ // 1/10000 == 0.0001, so we have good enough res to cover curves
+ // that span the entire widget...
+ inverseScale = qMax(1 / qMax( qMax(qAbs(transform.m11()), qAbs(transform.m22())),
+ qMax(qAbs(transform.m12()), qAbs(transform.m21())) ),
+ qreal(0.0001));
+ }
matrixDirty = false;
// The actual data has been updated so both shader program's uniforms need updating
simpleShaderMatrixUniformDirty = true;
- brushShaderMatrixUniformDirty = true;
- imageShaderMatrixUniformDirty = true;
- textShaderMatrixUniformDirty = true;
+ shaderMatrixUniformDirty = true;
}
@@ -485,120 +502,140 @@ void QGL2PaintEngineExPrivate::updateCompositionMode()
compositionModeDirty = false;
}
+static inline void setCoords(GLfloat *coords, const QGLRect &rect)
+{
+ coords[0] = rect.left;
+ coords[1] = rect.top;
+ coords[2] = rect.right;
+ coords[3] = rect.top;
+ coords[4] = rect.right;
+ coords[5] = rect.bottom;
+ coords[6] = rect.left;
+ coords[7] = rect.bottom;
+}
-void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& src, int txtWidth, int txtHeight)
+void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize)
{
-// qDebug("QGL2PaintEngineExPrivate::drawImage()");
+ transferMode(ImageDrawingMode);
- // We have a shader specifically for drawPixmap/drawImage...
- shaderManager->imageShader()->use();
+ updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform);
- updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false);
+ // Setup for texture drawing
+ shaderManager->setSrcPixelType(QGLEngineShaderManager::ImageSrc);
+ shaderManager->setTextureCoordsEnabled(true);
+ prepareForDraw(false); // ###
- if (compositionModeDirty)
- updateCompositionMode();
+ shaderManager->currentProgram()->setUniformValue("imageTexture", QT_IMAGE_TEXTURE_UNIT);
- if (matrixDirty)
- updateMatrix();
+ GLfloat dx = 1.0 / textureSize.width();
+ GLfloat dy = 1.0 / textureSize.height();
- if (imageShaderMatrixUniformDirty) {
- shaderManager->imageShader()->uniforms()[QLatin1String("pmvMatrix")] = pmvMatrix;
- imageShaderMatrixUniformDirty = false;
- }
+ QGLRect srcTextureRect(src.left*dx, 1.0 - src.top*dy, src.right*dx, 1.0 - src.bottom*dy);
- shaderManager->imageShader()->uniforms()[QLatin1String("textureSampler")] = QT_BRUSH_TEXTURE_UNIT;
+ setCoords(staticVertexCoordinateArray, dest);
+ setCoords(staticTextureCoordinateArray, srcTextureRect);
-// if (q->state()->opacity < 0.99f)
- shaderManager->imageShader()->uniforms()[QLatin1String("opacity")] = (GLfloat)q->state()->opacity;
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+}
- GLfloat vertexCoords[] = {
- dest.left, dest.top,
- dest.left, dest.bottom,
- dest.right, dest.bottom,
- dest.right, dest.top
- };
+void QGL2PaintEngineExPrivate::transferMode(EngineMode newMode)
+{
+ if (newMode == mode)
+ return;
- glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
- glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoords);
+ if (mode == TextDrawingMode || mode == ImageDrawingMode) {
+ glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
+ glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
+ }
- GLfloat dx = 1.0 / txtWidth;
- GLfloat dy = 1.0 / txtHeight;
+ if (mode == TextDrawingMode)
+ matrixDirty = true;
- QGLRect srcTextureRect(src.left*dx, 1.0 - src.top*dy, src.right*dx, 1.0 - src.bottom*dy);
+ if (newMode == TextDrawingMode) {
+ glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
+ glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
- GLfloat textureCoords[] = {
- srcTextureRect.left, srcTextureRect.top,
- srcTextureRect.left, srcTextureRect.bottom,
- srcTextureRect.right, srcTextureRect.bottom,
- srcTextureRect.right, srcTextureRect.top
- };
+ glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray.data());
+ glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray.data());
- glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
- glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoords);
+ matrixDirty = true;
+ }
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ if (newMode == ImageDrawingMode) {
+ glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
+ glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
- glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
- glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
-}
+ glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, staticVertexCoordinateArray);
+ glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, staticTextureCoordinateArray);
+ }
+
+ // This needs to change when we implement high-quality anti-aliasing...
+ if (newMode != TextDrawingMode)
+ shaderManager->setMaskType(QGLEngineShaderManager::NoMask);
+ mode = newMode;
+}
void QGL2PaintEngineExPrivate::drawOutline(const QVectorPath& path)
{
-// qDebug("QGL2PaintEngineExPrivate::drawOutline()");
+ transferMode(BrushDrawingMode);
+
+ // Might need to call updateMatrix to re-calculate inverseScale
if (matrixDirty)
updateMatrix();
- pathVertexArray.clear();
- pathVertexArray.addPath(path, inverseScale);
+ vertexCoordinateArray.clear();
+ vertexCoordinateArray.addPath(path, inverseScale);
if (path.hasImplicitClose()) {
// Close the path's outline
- pathVertexArray.lineToArray(path.points()[0], path.points()[1]);
- pathVertexArray.stops().last() += 1;
+ vertexCoordinateArray.lineToArray(path.points()[0], path.points()[1]);
+ vertexCoordinateArray.stops().last() += 1;
}
- prepareForDraw();
- drawVertexArrays(pathVertexArray, GL_LINE_STRIP);
+ prepareForDraw(currentBrush->isOpaque());
+ drawVertexArrays(vertexCoordinateArray, GL_LINE_STRIP);
}
// Assumes everything is configured for the brush you want to use
void QGL2PaintEngineExPrivate::fill(const QVectorPath& path)
{
+ transferMode(BrushDrawingMode);
+
+ // Might need to call updateMatrix to re-calculate inverseScale
if (matrixDirty)
updateMatrix();
const QPointF* const points = reinterpret_cast<const QPointF*>(path.points());
-
// Check to see if there's any hints
if (path.shape() == QVectorPath::RectangleHint) {
QGLRect rect(points[0].x(), points[0].y(), points[2].x(), points[2].y());
- prepareForDraw();
+ prepareForDraw(currentBrush->isOpaque());
composite(rect);
}
else if (path.shape() == QVectorPath::EllipseHint) {
- pathVertexArray.clear();
- pathVertexArray.addPath(path, inverseScale);
- prepareForDraw();
- drawVertexArrays(pathVertexArray, GL_TRIANGLE_FAN);
+ vertexCoordinateArray.clear();
+ vertexCoordinateArray.addPath(path, inverseScale);
+ prepareForDraw(currentBrush->isOpaque());
+ drawVertexArrays(vertexCoordinateArray, GL_TRIANGLE_FAN);
}
else {
// The path is too complicated & needs the stencil technique
- pathVertexArray.clear();
- pathVertexArray.addPath(path, inverseScale);
+ vertexCoordinateArray.clear();
+ vertexCoordinateArray.addPath(path, inverseScale);
- fillStencilWithVertexArray(pathVertexArray, path.hasWindingFill());
+ fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill());
// Stencil the brush onto the dest buffer
glStencilFunc(GL_NOTEQUAL, 0, 0xFFFF); // Pass if stencil buff value != 0
glEnable(GL_STENCIL_TEST);
- prepareForDraw();
- composite(pathVertexArray.boundingRect());
+ prepareForDraw(currentBrush->isOpaque());
+ composite(vertexCoordinateArray.boundingRect());
glDisable(GL_STENCIL_TEST);
- cleanStencilBuffer(pathVertexArray.boundingRect());
+ cleanStencilBuffer(vertexCoordinateArray.boundingRect());
}
}
@@ -674,32 +711,53 @@ void QGL2PaintEngineExPrivate::cleanStencilBuffer(const QGLRect& area)
glDisable(GL_STENCIL_TEST);
}
-void QGL2PaintEngineExPrivate::prepareForDraw()
+void QGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque)
{
- if (brushTextureDirty)
+ if (brushTextureDirty && mode != ImageDrawingMode)
updateBrushTexture();
if (compositionModeDirty)
updateCompositionMode();
+ if (matrixDirty)
+ updateMatrix();
+
+ const bool stateHasOpacity = q->state()->opacity < 0.99f;
+ if ( (!srcPixelsAreOpaque || stateHasOpacity) &&
+ q->state()->compositionMode() != QPainter::CompositionMode_Source)
+ glEnable(GL_BLEND);
+ else
+ glDisable(GL_BLEND);
+
+ bool useGlobalOpacityUniform = stateHasOpacity;
+ if (stateHasOpacity && (mode != ImageDrawingMode)) {
+ // Using a brush
+ bool brushIsPattern = (currentBrush->style() >= Qt::Dense1Pattern) &&
+ (currentBrush->style() <= Qt::DiagCrossPattern);
+
+ if ((currentBrush->style() == Qt::SolidPattern) || brushIsPattern)
+ useGlobalOpacityUniform = false; // Global opacity handled by srcPixel shader
+ }
+ shaderManager->setUseGlobalOpacity(useGlobalOpacityUniform);
+
+
+ // If the shader program needs changing, we change it and mark all uniforms as dirty
if (shaderManager->useCorrectShaderProg()) {
// The shader program has changed so mark all uniforms as dirty:
brushUniformsDirty = true;
- brushShaderMatrixUniformDirty = true;
+ shaderMatrixUniformDirty = true;
}
- if (brushUniformsDirty)
+ if (brushUniformsDirty && mode != ImageDrawingMode)
updateBrushUniforms();
- if (brushShaderMatrixUniformDirty) {
- shaderManager->brushShader()->uniforms()[QLatin1String("pmvMatrix")] = pmvMatrix;
- brushShaderMatrixUniformDirty = false;
+ if (shaderMatrixUniformDirty) {
+ shaderManager->currentProgram()->setUniformValue("pmvMatrix", pmvMatrix);
+ shaderMatrixUniformDirty = false;
}
- if ((q->state()->opacity < 0.99f) || !currentBrush->isOpaque())
- glEnable(GL_BLEND);
- else
- glDisable(GL_BLEND);
+ if (useGlobalOpacityUniform)
+ shaderManager->currentProgram()->setUniformValue("globalOpacity", (GLfloat)q->state()->opacity);
}
void QGL2PaintEngineExPrivate::composite(const QGLRect& boundingRect)
@@ -749,8 +807,6 @@ void QGL2PaintEngineExPrivate::drawVertexArrays(QGL2PEXVertexArray& vertexArray,
QGL2PaintEngineEx::QGL2PaintEngineEx()
: QPaintEngineEx(*(new QGL2PaintEngineExPrivate(this)))
{
- qDebug("QGL2PaintEngineEx::QGL2PaintEngineEx()");
-
}
QGL2PaintEngineEx::~QGL2PaintEngineEx()
@@ -761,8 +817,10 @@ void QGL2PaintEngineEx::fill(const QVectorPath &path, const QBrush &brush)
{
Q_D(QGL2PaintEngineEx);
- QTime startTime = QTime::currentTime();
+ if (brush.style() == Qt::NoBrush)
+ return;
+ ensureActive();
d->setBrush(&brush);
d->fill(path);
d->setBrush(&(state()->brush)); // reset back to the state's brush
@@ -772,6 +830,7 @@ void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen)
{
Q_D(QGL2PaintEngineEx);
+ ensureActive();
if (pen.style() == Qt::NoPen)
return;
@@ -790,7 +849,6 @@ void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen)
d->setBrush(&(state()->brush));
} else
return QPaintEngineEx::stroke(path, pen);
-
}
void QGL2PaintEngineEx::penChanged()
@@ -819,7 +877,6 @@ void QGL2PaintEngineEx::opacityChanged()
Q_D(QGL2PaintEngineEx);
Q_ASSERT(d->shaderManager);
- d->shaderManager->setUseGlobalOpacity(state()->opacity > 0.999);
d->brushUniformsDirty = true;
}
@@ -845,9 +902,12 @@ void QGL2PaintEngineEx::transformChanged()
void QGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixmap, const QRectF & src)
{
Q_D(QGL2PaintEngineEx);
- glActiveTexture(QT_BRUSH_TEXTURE_UNIT);
+ ensureActive();
+ d->transferMode(ImageDrawingMode);
- d->ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, true);
+ QGLContext *ctx = d->ctx;
+ glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
+ ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, true);
//FIXME: we should use hasAlpha() instead, but that's SLOW at the moment
if ((state()->opacity < 0.99f) || pixmap.hasAlphaChannel())
@@ -855,35 +915,39 @@ void QGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixmap, c
else
glDisable(GL_BLEND);
- d->drawTexture(dest, src, pixmap.width(), pixmap.height());
+ d->drawTexture(dest, src, pixmap.size());
}
void QGL2PaintEngineEx::drawImage(const QRectF& dest, const QImage& image, const QRectF& src,
Qt::ImageConversionFlags)
{
Q_D(QGL2PaintEngineEx);
- glActiveTexture(QT_BRUSH_TEXTURE_UNIT);
- d->ctx->d_func()->bindTexture(image, GL_TEXTURE_2D, GL_RGBA, true);
+ ensureActive();
+ d->transferMode(ImageDrawingMode);
+
+ QGLContext *ctx = d->ctx;
+ glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
+ ctx->d_func()->bindTexture(image, GL_TEXTURE_2D, GL_RGBA, true);
if ((state()->opacity < 0.99f) || image.hasAlphaChannel())
glEnable(GL_BLEND);
else
glDisable(GL_BLEND);
- d->drawTexture(dest, src, image.width(), image.height());
+ d->drawTexture(dest, src, image.size());
}
void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem)
{
- QOpenGLPaintEngineState *s = state();
+ Q_D(QGL2PaintEngineEx);
+
+ ensureActive();
+ QOpenGL2PaintEngineState *s = state();
const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
bool drawCached = true;
- if (state()->pen.brush().style() != Qt::SolidPattern)
- drawCached = false;
-
if (s->matrix.type() > QTransform::TxTranslate)
drawCached = false;
@@ -892,17 +956,19 @@ void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem
drawCached = false;
if (drawCached) {
- drawCachedGlyphs(p, ti);
+ d->drawCachedGlyphs(p, ti);
return;
}
QPaintEngineEx::drawTextItem(p, ti);
}
-void QGL2PaintEngineEx::drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti)
+void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti)
{
- Q_D(QGL2PaintEngineEx);
- QOpenGLPaintEngineState *s = state();
+ transferMode(TextDrawingMode);
+
+ Q_Q(QGL2PaintEngineEx);
+ QOpenGL2PaintEngineState *s = q->state();
QVarLengthArray<QFixedPoint> positions;
QVarLengthArray<glyph_t> glyphs;
@@ -910,10 +976,22 @@ void QGL2PaintEngineEx::drawCachedGlyphs(const QPointF &p, const QTextItemInt &t
matrix.translate(p.x(), p.y());
ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
+
QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0
? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat)
: QFontEngineGlyphCache::Raster_A8;
+ GLenum maskFormat = GL_RGBA;
+ if (glyphType == QFontEngineGlyphCache::Raster_A8) {
+ shaderManager->setMaskType(QGLEngineShaderManager::PixelMask);
+// maskFormat = GL_ALPHA;
+ }
+ else if (glyphType == QFontEngineGlyphCache::Raster_RGBMask)
+ shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMask);
+ //### TODO: Gamma correction
+ shaderManager->setTextureCoordsEnabled(true);
+
+
QImageTextureGlyphCache *cache =
(QImageTextureGlyphCache *) ti.fontEngine->glyphCache(glyphType, s->matrix);
if (!cache) {
@@ -926,66 +1004,46 @@ void QGL2PaintEngineEx::drawCachedGlyphs(const QPointF &p, const QTextItemInt &t
const QImage &image = cache->image();
int margin = cache->glyphMargin();
- glActiveTexture(QT_BRUSH_TEXTURE_UNIT);
- d->ctx->d_func()->bindTexture(image, GL_TEXTURE_2D, GL_RGBA, true);
-
- glEnable(GL_BLEND);
-
- d->shaderManager->textShader()->use();
- d->updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false);
-
- if (d->compositionModeDirty)
- d->updateCompositionMode();
-
- if (d->matrixDirty)
- d->updateMatrix();
-
- if (d->textShaderMatrixUniformDirty) {
- d->shaderManager->textShader()->uniforms()[QLatin1String("pmvMatrix")] = d->pmvMatrix;
- d->textShaderMatrixUniformDirty = false;
- }
-
- d->shaderManager->textShader()->uniforms()[QLatin1String("textureSampler")] = QT_BRUSH_TEXTURE_UNIT;
- QColor col = d->premultiplyColor(state()->pen.color(), (GLfloat)state()->opacity);
- d->shaderManager->textShader()->uniforms()[QLatin1String("fragmentColor")] = col;
+ if (image.isNull())
+ return;
GLfloat dx = 1.0 / image.width();
GLfloat dy = 1.0 / image.height();
- glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
- glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
+ QGLPoint *oldVertexCoordinateDataPtr = vertexCoordinateArray.data();
+ QGLPoint *oldTextureCoordinateDataPtr = textureCoordinateArray.data();
+
+ vertexCoordinateArray.clear();
+ textureCoordinateArray.clear();
+
for (int i=0; i<glyphs.size(); ++i) {
const QTextureGlyphCache::Coord &c = cache->coords.value(glyphs[i]);
int x = positions[i].x.toInt() + c.baseLineX - margin;
int y = positions[i].y.toInt() - c.baseLineY - margin;
- QGLRect dest = QRectF(x, y, c.w, c.h);
- QGLRect src = QRectF(c.x, c.y, c.w, c.h);
+ vertexCoordinateArray.addRect(QRectF(x, y, c.w, c.h));
+ textureCoordinateArray.addRect(QRectF(c.x*dx, 1 - c.y*dy, c.w * dx, -c.h * dy));
+ }
- GLfloat vertexCoords[] = {
- dest.left, dest.top,
- dest.left, dest.bottom,
- dest.right, dest.bottom,
- dest.right, dest.top
- };
+ glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT);
+ ctx->d_func()->bindTexture(image, GL_TEXTURE_2D, GL_RGBA, true);
+ updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false);
- glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoords);
+ QBrush pensBrush = q->state()->pen.brush();
+ setBrush(&pensBrush);
- QGLRect srcTextureRect(src.left*dx, 1.0 - src.top*dy, src.right*dx, 1.0 - src.bottom*dy);
+ prepareForDraw(false); // Text always causes src pixels to be transparent
- GLfloat textureCoords[] = {
- srcTextureRect.left, srcTextureRect.top,
- srcTextureRect.left, srcTextureRect.bottom,
- srcTextureRect.right, srcTextureRect.bottom,
- srcTextureRect.right, srcTextureRect.top
- };
+ shaderManager->currentProgram()->setUniformValue("maskTexture", QT_MASK_TEXTURE_UNIT);
- glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoords);
+ if (vertexCoordinateArray.data() != oldVertexCoordinateDataPtr)
+ glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinateArray.data());
+ if (textureCoordinateArray.data() != oldTextureCoordinateDataPtr)
+ glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray.data());
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- }
- glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
- glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
+ glDrawArrays(GL_TRIANGLES, 0, 6 * glyphs.size());
+
+ setBrush(&(q->state()->brush)); //###
}
bool QGL2PaintEngineEx::begin(QPaintDevice *pdev)
@@ -994,14 +1052,28 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev)
// qDebug("QGL2PaintEngineEx::begin()");
- QGLWidget* widget = static_cast<QGLWidget*>(pdev);
- d->ctx = const_cast<QGLContext*>(widget->context());
- d->ctx->makeCurrent();
- d->width = widget->width();
- d->height = widget->height();
+ d->drawable.setDevice(pdev);
+ d->drawable.makeCurrent();
+ d->ctx = d->drawable.context();
+ QSize sz = d->drawable.size();
+ d->width = sz.width();
+ d->height = sz.height();
+ d->mode = BrushDrawingMode;
+
+#if !defined(QT_OPENGL_ES_2)
+ qt_resolve_version_2_0_functions(d->ctx);
+#endif
+
+ d->last_engine = d->ctx->d_ptr->active_engine;
+ d->ctx->d_ptr->active_engine = this;
+
+ if (d->last_engine) {
+ QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(d->last_engine);
+ static_cast<QGL2PaintEngineExPrivate *>(engine->d_ptr)->transferMode(BrushDrawingMode);
+ }
if (!d->shaderManager)
- d->shaderManager = new QGLPEXShaderManager(d->ctx);
+ d->shaderManager = new QGLEngineShaderManager(d->ctx);
glViewport(0, 0, d->width, d->height);
@@ -1020,17 +1092,84 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev)
d->use_system_clip = !systemClip().isEmpty();
glDisable(GL_DEPTH_TEST);
+ glDisable(GL_SCISSOR_TEST);
+
+ QGLPixmapData *source = d->drawable.copyOnBegin();
+ if (source) {
+ d->transferMode(ImageDrawingMode);
+
+ source->bind(false);
+
+ glDisable(GL_BLEND);
+
+ QRect rect(0, 0, source->width(), source->height());
+ d->drawTexture(QRectF(rect), QRectF(rect), rect.size());
+ }
+ updateClipRegion(QRegion(), Qt::NoClip);
return true;
}
bool QGL2PaintEngineEx::end()
{
Q_D(QGL2PaintEngineEx);
- d->ctx->swapBuffers();
+ QGLContext *ctx = d->ctx;
+ if (ctx->d_ptr->active_engine != this) {
+ QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(d->last_engine);
+ if (engine) {
+ QGL2PaintEngineExPrivate *p = static_cast<QGL2PaintEngineExPrivate *>(engine->d_ptr);
+ p->transferMode(BrushDrawingMode);
+ p->drawable.doneCurrent();
+ }
+ d->drawable.makeCurrent();
+ }
+
+ glUseProgram(0);
+ d->transferMode(BrushDrawingMode);
+ d->drawable.swapBuffers();
+ d->drawable.doneCurrent();
+ d->ctx->d_ptr->active_engine = d->last_engine;
+
+ if (d->last_engine) {
+ QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(d->last_engine);
+ QGL2PaintEngineExPrivate *p = static_cast<QGL2PaintEngineExPrivate *>(engine->d_ptr);
+
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_SCISSOR_TEST);
+
+ glViewport(0, 0, p->width, p->height);
+ engine->setState(engine->state());
+ p->updateDepthClip();
+ }
+
return false;
}
+void QGL2PaintEngineEx::ensureActive()
+{
+ Q_D(QGL2PaintEngineEx);
+ QGLContext *ctx = d->ctx;
+
+ if (isActive() && ctx->d_ptr->active_engine != this) {
+ QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(ctx->d_ptr->active_engine);
+ if (engine) {
+ QGL2PaintEngineExPrivate *p = static_cast<QGL2PaintEngineExPrivate *>(engine->d_ptr);
+ p->transferMode(BrushDrawingMode);
+ p->drawable.doneCurrent();
+ }
+ d->drawable.makeCurrent();
+
+ ctx->d_ptr->active_engine = this;
+
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_SCISSOR_TEST);
+
+ glViewport(0, 0, d->width, d->height);
+ setState(state());
+ d->updateDepthClip();
+ }
+}
+
/////////////////////////////////// State/Clipping stolen from QOpenGLPaintEngine //////////////////////////////////////////
@@ -1161,14 +1300,19 @@ void QGL2PaintEngineEx::updateClipRegion(const QRegion &clipRegion, Qt::ClipOper
state()->hasClipping = op != Qt::NoClip || d->use_system_clip;
}
- if (state()->hasClipping && state()->clipRegion.rects().size() == 1)
- state()->fastClip = state()->clipRegion.rects().at(0);
- else
- state()->fastClip = QRect();
-
d->updateDepthClip();
}
+void QGL2PaintEngineExPrivate::systemStateChanged()
+{
+ Q_Q(QGL2PaintEngineEx);
+ use_system_clip = !systemClip.isEmpty();
+
+ if (q->painter()->hasClipping())
+ q->updateClipRegion(q->painter()->clipRegion(), Qt::ReplaceClip);
+ else
+ q->updateClipRegion(QRegion(), Qt::NoClip);
+}
void QGL2PaintEngineExPrivate::updateDepthClip()
{
@@ -1176,20 +1320,17 @@ void QGL2PaintEngineExPrivate::updateDepthClip()
Q_Q(QGL2PaintEngineEx);
+ q->ensureActive();
glDisable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
if (!q->state()->hasClipping)
return;
- QRect fastClip;
- if (q->state()->clipEnabled) {
- fastClip = q->state()->fastClip;
- } else if (use_system_clip && q->systemClip().rects().count() == 1) {
- fastClip = q->systemClip().rects().at(0);
- }
+ const QVector<QRect> rects = q->state()->clipEnabled ? q->state()->clipRegion.rects() : q->systemClip().rects();
+ if (rects.size() == 1) {
+ QRect fastClip = rects.at(0);
- if (!fastClip.isEmpty()) {
glEnable(GL_SCISSOR_TEST);
const int left = fastClip.left();
@@ -1201,12 +1342,11 @@ void QGL2PaintEngineExPrivate::updateDepthClip()
return;
}
- glClearDepthf(0x0);
+ glClearDepth(0x0);
glDepthMask(true);
glClear(GL_DEPTH_BUFFER_BIT);
- glClearDepthf(0x1);
+ glClearDepth(0x1);
- const QVector<QRect> rects = q->state()->clipEnabled ? q->state()->clipRegion.rects() : q->systemClip().rects();
glEnable(GL_SCISSOR_TEST);
for (int i = 0; i < rects.size(); ++i) {
QRect rect = rects.at(i);
@@ -1229,50 +1369,56 @@ void QGL2PaintEngineExPrivate::updateDepthClip()
-void QGL2PaintEngineEx::setState(QPainterState *s)
+void QGL2PaintEngineEx::setState(QPainterState *new_state)
{
// qDebug("QGL2PaintEngineEx::setState()");
Q_D(QGL2PaintEngineEx);
+
+ QOpenGL2PaintEngineState *s = static_cast<QOpenGL2PaintEngineState *>(new_state);
+
+ QOpenGL2PaintEngineState *old_state = state();
+ const bool needsDepthClipUpdate = !old_state
+ || s->clipEnabled != old_state->clipEnabled
+ || (s->clipEnabled && s->clipRegion != old_state->clipRegion);
+
QPaintEngineEx::setState(s);
- d->updateDepthClip();
+ if (needsDepthClipUpdate)
+ d->updateDepthClip();
d->matrixDirty = true;
d->compositionModeDirty = true;
d->brushTextureDirty = true;
d->brushUniformsDirty = true;
d->simpleShaderMatrixUniformDirty = true;
- d->brushShaderMatrixUniformDirty = true;
- d->imageShaderMatrixUniformDirty = true;
- d->textShaderMatrixUniformDirty = true;
+ d->shaderMatrixUniformDirty = true;
}
QPainterState *QGL2PaintEngineEx::createState(QPainterState *orig) const
{
- QOpenGLPaintEngineState *s;
+ QOpenGL2PaintEngineState *s;
if (!orig)
- s = new QOpenGLPaintEngineState();
+ s = new QOpenGL2PaintEngineState();
else
- s = new QOpenGLPaintEngineState(*static_cast<QOpenGLPaintEngineState *>(orig));
+ s = new QOpenGL2PaintEngineState(*static_cast<QOpenGL2PaintEngineState *>(orig));
return s;
}
-QOpenGLPaintEngineState::QOpenGLPaintEngineState(QOpenGLPaintEngineState &other)
+QOpenGL2PaintEngineState::QOpenGL2PaintEngineState(QOpenGL2PaintEngineState &other)
: QPainterState(other)
{
clipRegion = other.clipRegion;
hasClipping = other.hasClipping;
- fastClip = other.fastClip;
}
-QOpenGLPaintEngineState::QOpenGLPaintEngineState()
+QOpenGL2PaintEngineState::QOpenGL2PaintEngineState()
{
hasClipping = false;
}
-QOpenGLPaintEngineState::~QOpenGLPaintEngineState()
+QOpenGL2PaintEngineState::~QOpenGL2PaintEngineState()
{
}
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
index ce66e4b..ccf89f0 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
@@ -58,16 +58,15 @@
class QGL2PaintEngineExPrivate;
-class QOpenGLPaintEngineState : public QPainterState
+class QOpenGL2PaintEngineState : public QPainterState
{
public:
- QOpenGLPaintEngineState(QOpenGLPaintEngineState &other);
- QOpenGLPaintEngineState();
- ~QOpenGLPaintEngineState();
+ QOpenGL2PaintEngineState(QOpenGL2PaintEngineState &other);
+ QOpenGL2PaintEngineState();
+ ~QOpenGL2PaintEngineState();
QRegion clipRegion;
bool hasClipping;
- QRect fastClip;
};
@@ -81,6 +80,8 @@ public:
bool begin(QPaintDevice *device);
bool end();
+ void ensureActive();
+
virtual void fill(const QVectorPath &path, const QBrush &brush);
virtual void stroke(const QVectorPath &path, const QPen &pen);
virtual void clip(const QVectorPath &path, Qt::ClipOperation op);
@@ -100,19 +101,17 @@ public:
virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
Qt::ImageConversionFlags flags = Qt::AutoColor);
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
- void drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti);
Type type() const { return OpenGL; }
-
// State stuff is just for clipping and ripped off from QGLPaintEngine
void setState(QPainterState *s);
QPainterState *createState(QPainterState *orig) const;
- inline QOpenGLPaintEngineState *state() {
- return static_cast<QOpenGLPaintEngineState *>(QPaintEngineEx::state());
+ inline QOpenGL2PaintEngineState *state() {
+ return static_cast<QOpenGL2PaintEngineState *>(QPaintEngineEx::state());
}
- inline const QOpenGLPaintEngineState *state() const {
- return static_cast<const QOpenGLPaintEngineState *>(QPaintEngineEx::state());
+ inline const QOpenGL2PaintEngineState *state() const {
+ return static_cast<const QOpenGL2PaintEngineState *>(QPaintEngineEx::state());
}
void updateClipRegion(const QRegion &clipRegion, Qt::ClipOperation op);
@@ -120,6 +119,4 @@ private:
Q_DISABLE_COPY(QGL2PaintEngineEx)
};
-
-
#endif
diff --git a/src/opengl/opengl.pro b/src/opengl/opengl.pro
index 78aaddb..73af174 100644
--- a/src/opengl/opengl.pro
+++ b/src/opengl/opengl.pro
@@ -13,18 +13,15 @@ include(../qbase.pri)
!win32:!embedded:!mac:CONFIG += x11
contains(QT_CONFIG, opengl):CONFIG += opengl
contains(QT_CONFIG, opengles1):CONFIG += opengles1
+contains(QT_CONFIG, opengles1):CONFIG += opengles1cl
contains(QT_CONFIG, opengles2):CONFIG += opengles2
-!contains(QT_CONFIG, opengles2) {
- HEADERS += qgraphicssystem_gl_p.h qwindowsurface_gl_p.h qpixmapdata_gl_p.h
- SOURCES += qgraphicssystem_gl.cpp qwindowsurface_gl.cpp qpixmapdata_gl.cpp
-}
-
HEADERS += qgl.h \
qgl_p.h \
qglcolormap.h \
qglpixelbuffer.h \
qglframebufferobject.h \
+ qglextensions_p.h
SOURCES += qgl.cpp \
qglcolormap.cpp \
@@ -33,25 +30,34 @@ SOURCES += qgl.cpp \
qglextensions.cpp \
!contains(QT_CONFIG, opengles2) {
- HEADERS += qpaintengine_opengl_p.h qglpixmapfilter_p.h
- SOURCES += qpaintengine_opengl.cpp qglpixmapfilter.cpp
+ HEADERS += qpaintengine_opengl_p.h
+ SOURCES += qpaintengine_opengl.cpp
}
-contains(QT_CONFIG, opengles2) {
- SOURCES += gl2paintengineex/qglgradientcache.cpp \
- gl2paintengineex/qglpexshadermanager.cpp \
- gl2paintengineex/qglshader.cpp \
+!contains(QT_CONFIG, opengles1):!contains(QT_CONFIG, opengles1cl) {
+ HEADERS += qglshaderprogram.h \
+ qglpixmapfilter_p.h \
+ qgraphicssystem_gl_p.h \
+ qwindowsurface_gl_p.h \
+ qpixmapdata_gl_p.h \
+ gl2paintengineex/qglgradientcache_p.h \
+ gl2paintengineex/qglengineshadermanager_p.h \
+ gl2paintengineex/qgl2pexvertexarray_p.h \
+ gl2paintengineex/qpaintengineex_opengl2_p.h \
+ gl2paintengineex/qglengineshadersource_p.h
+
+ SOURCES += qglshaderprogram.cpp \
+ qglpixmapfilter.cpp \
+ qgraphicssystem_gl.cpp \
+ qwindowsurface_gl.cpp \
+ qpixmapdata_gl.cpp \
+ gl2paintengineex/qglgradientcache.cpp \
+ gl2paintengineex/qglengineshadermanager.cpp \
gl2paintengineex/qgl2pexvertexarray.cpp \
gl2paintengineex/qpaintengineex_opengl2.cpp
- HEADERS += gl2paintengineex/qglgradientcache_p.h \
- gl2paintengineex/qglpexshadermanager_p.h \
- gl2paintengineex/qglshader_p.h \
- gl2paintengineex/qgl2pexvertexarray_p.h \
- gl2paintengineex/qpaintengineex_opengl2_p.h
}
-
x11 {
contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles1cl)|contains(QT_CONFIG, opengles2) {
SOURCES += qgl_x11egl.cpp \
diff --git a/src/opengl/qegl.cpp b/src/opengl/qegl.cpp
index 165a0f3..c6c258b 100644
--- a/src/opengl/qegl.cpp
+++ b/src/opengl/qegl.cpp
@@ -119,7 +119,7 @@ bool QEglContext::chooseConfig
if (red == props.value(EGL_RED_SIZE) &&
green == props.value(EGL_GREEN_SIZE) &&
blue == props.value(EGL_BLUE_SIZE) &&
- (props.value(EGL_ALPHA_SIZE) == EGL_DONT_CARE ||
+ (props.value(EGL_ALPHA_SIZE) == 0 ||
alpha == props.value(EGL_ALPHA_SIZE))) {
cfg = configs[index];
delete [] configs;
@@ -405,7 +405,54 @@ int QEglProperties::value(int name) const
if (props[index] == name)
return props[index + 1];
}
- return EGL_DONT_CARE;
+
+ // If the attribute has not been explicitly set, return the EGL default
+ // The following defaults were taken from the EGL 1.4 spec:
+ switch(name) {
+ case EGL_BUFFER_SIZE: return 0;
+ case EGL_RED_SIZE: return 0;
+ case EGL_GREEN_SIZE: return 0;
+ case EGL_BLUE_SIZE: return 0;
+ case EGL_LUMINANCE_SIZE: return 0;
+ case EGL_ALPHA_SIZE: return 0;
+ case EGL_ALPHA_MASK_SIZE: return 0;
+ case EGL_BIND_TO_TEXTURE_RGB: return EGL_DONT_CARE;
+ case EGL_BIND_TO_TEXTURE_RGBA: return EGL_DONT_CARE;
+ case EGL_COLOR_BUFFER_TYPE: return EGL_RGB_BUFFER;
+ case EGL_CONFIG_CAVEAT: return EGL_DONT_CARE;
+ case EGL_CONFIG_ID: return EGL_DONT_CARE;
+ case EGL_DEPTH_SIZE: return 0;
+ case EGL_LEVEL: return 0;
+ case EGL_NATIVE_RENDERABLE: return EGL_DONT_CARE;
+ case EGL_NATIVE_VISUAL_TYPE: return EGL_DONT_CARE;
+ case EGL_MAX_SWAP_INTERVAL: return EGL_DONT_CARE;
+ case EGL_MIN_SWAP_INTERVAL: return EGL_DONT_CARE;
+ case EGL_RENDERABLE_TYPE: return EGL_OPENGL_ES_BIT;
+ case EGL_SAMPLE_BUFFERS: return 0;
+ case EGL_SAMPLES: return 0;
+ case EGL_STENCIL_SIZE: return 0;
+ case EGL_SURFACE_TYPE: return EGL_WINDOW_BIT;
+ case EGL_TRANSPARENT_TYPE: return EGL_NONE;
+ case EGL_TRANSPARENT_RED_VALUE: return EGL_DONT_CARE;
+ case EGL_TRANSPARENT_GREEN_VALUE: return EGL_DONT_CARE;
+ case EGL_TRANSPARENT_BLUE_VALUE: return EGL_DONT_CARE;
+
+#if defined(EGL_VERSION_1_3)
+ case EGL_CONFORMANT: return 0;
+ case EGL_MATCH_NATIVE_PIXMAP: return EGL_NONE;
+#endif
+
+ case EGL_MAX_PBUFFER_HEIGHT:
+ case EGL_MAX_PBUFFER_WIDTH:
+ case EGL_MAX_PBUFFER_PIXELS:
+ case EGL_NATIVE_VISUAL_ID:
+ case EGL_NONE:
+ qWarning("QEglProperties::value() - Attibute %d does not affect config selection", name);
+ return EGL_DONT_CARE;
+ default:
+ qWarning("QEglProperties::value() - Attibute %d is unknown in EGL <=1.4", name);
+ return EGL_DONT_CARE;
+ }
}
// Set the value associated with a property, replacing an existing
@@ -593,13 +640,13 @@ QString QEglProperties::toString() const
#endif
val = value(EGL_DEPTH_SIZE);
- if (val != EGL_DONT_CARE) {
+ if (val != 0) {
addTag(str, QLatin1String(" depth="));
str += QString::number(val);
}
val = value(EGL_STENCIL_SIZE);
- if (val != EGL_DONT_CARE) {
+ if (val != 0) {
addTag(str, QLatin1String(" stencil="));
str += QString::number(val);
}
@@ -649,7 +696,7 @@ QString QEglProperties::toString() const
}
val = value(EGL_LEVEL);
- if (val != EGL_DONT_CARE) {
+ if (val != 0) {
addTag(str, QLatin1String(" level="));
str += QString::number(val);
}
@@ -700,13 +747,13 @@ QString QEglProperties::toString() const
#endif
val = value(EGL_SAMPLES);
- if (val != EGL_DONT_CARE) {
+ if (val != 0) {
addTag(str, QLatin1String(" samples="));
str += QString::number(val);
}
val = value(EGL_SAMPLE_BUFFERS);
- if (val != EGL_DONT_CARE) {
+ if (val != 0) {
addTag(str, QLatin1String(" sample-buffers="));
str += QString::number(val);
}
@@ -755,7 +802,7 @@ QString QEglProperties::toString() const
#ifdef EGL_LUMINANCE_SIZE
val = value(EGL_LUMINANCE_SIZE);
- if (val != EGL_DONT_CARE) {
+ if (val != 0) {
addTag(str, QLatin1String(" luminance="));
str += QString::number(val);
}
@@ -763,7 +810,7 @@ QString QEglProperties::toString() const
#ifdef EGL_ALPHA_MASK_SIZE
val = value(EGL_ALPHA_MASK_SIZE);
- if (val != EGL_DONT_CARE) {
+ if (val != 0) {
addTag(str, QLatin1String(" alpha-mask="));
str += QString::number(val);
}
@@ -771,7 +818,7 @@ QString QEglProperties::toString() const
#ifdef EGL_CONFORMANT
val = value(EGL_CONFORMANT);
- if (val != EGL_DONT_CARE) {
+ if (val != 0) {
if (val)
addTag(str, QLatin1String(" conformant=true"));
else
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index a534cc5..0a2a196 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -65,15 +65,20 @@
#include "qimage.h"
#include "qgl_p.h"
-#if defined(QT_OPENGL_ES_2)
#include "gl2paintengineex/qpaintengineex_opengl2_p.h"
-#else
+
+#ifndef QT_OPENGL_ES_2
#include <private/qpaintengine_opengl_p.h>
#endif
+#include <qglpixelbuffer.h>
+#include <qglframebufferobject.h>
+
#include <private/qimage_p.h>
#include <private/qpixmapdata_p.h>
#include <private/qpixmapdata_gl_p.h>
+#include <private/qglpixelbuffer_p.h>
+#include <private/qwindowsurface_gl_p.h>
#include "qcolormap.h"
#include "qcache.h"
#include "qfile.h"
@@ -1290,6 +1295,7 @@ void QGLContextPrivate::init(QPaintDevice *dev, const QGLFormat &format)
eglContext = 0;
#endif
pbo = 0;
+ fbo = 0;
crWin = false;
initDone = false;
sharing = false;
@@ -1298,6 +1304,7 @@ void QGLContextPrivate::init(QPaintDevice *dev, const QGLFormat &format)
version_flags_cached = false;
version_flags = QGLFormat::OpenGL_Version_None;
current_fbo = 0;
+ active_engine = 0;
}
QGLContext* QGLContext::currentCtx = 0;
@@ -1308,12 +1315,8 @@ QGLContext* QGLContext::currentCtx = 0;
QGLFramebufferObject::toImage()
*/
-QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha)
+static void convertFromGLImage(QImage &img, int w, int h, bool alpha_format, bool include_alpha)
{
- QImage img(size, alpha_format ? QImage::Format_ARGB32 : QImage::Format_RGB32);
- int w = size.width();
- int h = size.height();
- glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, img.bits());
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
// OpenGL gives RGBA; Qt wants ARGB
uint *p = (uint*)img.bits();
@@ -1344,7 +1347,30 @@ QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include
}
}
- return img.mirrored();
+ img = img.mirrored();
+}
+
+QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha)
+{
+ QImage img(size, alpha_format ? QImage::Format_ARGB32 : QImage::Format_RGB32);
+ int w = size.width();
+ int h = size.height();
+ glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, img.bits());
+ convertFromGLImage(img, w, h, alpha_format, include_alpha);
+ return img;
+}
+
+QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha)
+{
+ QImage img(size, alpha_format ? QImage::Format_ARGB32 : QImage::Format_RGB32);
+ int w = size.width();
+ int h = size.height();
+#if !defined(QT_OPENGL_ES_2) && !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ //### glGetTexImage not in GL ES 2.0, need to do something else here!
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits());
+#endif
+ convertFromGLImage(img, w, h, alpha_format, include_alpha);
+ return img;
}
// returns the highest number closest to v, which is a power of 2
@@ -1548,7 +1574,7 @@ void QGLContextPrivate::cleanup()
Q_Q(QGLContext);
if (pbo) {
QGLContext *ctx = q;
- glDeleteBuffersARB(1, &pbo);
+ glDeleteBuffers(1, &pbo);
pbo = 0;
}
}
@@ -1813,7 +1839,7 @@ GLuint QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint
use_pbo = qt_resolve_buffer_extensions(ctx);
if (use_pbo && pbo == 0)
- glGenBuffersARB(1, &pbo);
+ glGenBuffers(1, &pbo);
}
// the GL_BGRA format is only present in GL version >= 1.2
@@ -1864,8 +1890,8 @@ GLuint QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint
uchar *ptr = 0;
if (use_pbo) {
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
- glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, img.width() * img.height() * 4, 0, GL_STREAM_DRAW_ARB);
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
+ glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, img.width() * img.height() * 4, 0, GL_STREAM_DRAW_ARB);
ptr = reinterpret_cast<uchar *>(glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB));
}
@@ -1892,7 +1918,7 @@ GLuint QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint
}
if (use_pbo)
- glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
// this assumes the size of a texture is always smaller than the max cache size
int cost = img.width()*img.height()*4/1024;
@@ -1944,11 +1970,13 @@ GLuint QGLContextPrivate::bindTexture(const QImage &image, GLenum target, GLint
/*! \internal */
GLuint QGLContextPrivate::bindTexture(const QPixmap &pixmap, GLenum target, GLint format, bool clean)
{
-#if !defined(QT_OPENGL_ES_2)
- if (target == qt_gl_preferredTextureTarget() && pixmap.pixmapData()->classId() == QPixmapData::OpenGLClass) {
- const QGLPixmapData *data = static_cast<const QGLPixmapData *>(pixmap.pixmapData());
+ Q_Q(QGLContext);
+ QPixmapData *pd = pixmap.pixmapData();
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ if (target == GL_TEXTURE_2D && pd->classId() == QPixmapData::OpenGLClass) {
+ const QGLPixmapData *data = static_cast<const QGLPixmapData *>(pd);
- if (data->isValidContext(QGLContext::currentContext()))
+ if (data->isValidContext(q))
return data->bind();
}
#endif
@@ -2100,12 +2128,34 @@ void QGLContext::deleteTexture(QMacCompatGLuint id)
}
#endif
-// qpaintengine_opengl.cpp
-#if !defined(QT_OPENGL_ES_2)
-extern void qt_add_rect_to_array(const QRectF &r, q_vertexType *array);
-#else
-void qt_add_rect_to_array(const QRectF &r, q_vertexType *array) {};
-#endif
+void qt_add_rect_to_array(const QRectF &r, q_vertexType *array)
+{
+ qreal left = r.left();
+ qreal right = r.right();
+ qreal top = r.top();
+ qreal bottom = r.bottom();
+
+ array[0] = f2vt(left);
+ array[1] = f2vt(top);
+ array[2] = f2vt(right);
+ array[3] = f2vt(top);
+ array[4] = f2vt(right);
+ array[5] = f2vt(bottom);
+ array[6] = f2vt(left);
+ array[7] = f2vt(bottom);
+}
+
+void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, q_vertexType *array)
+{
+ array[0] = f2vt(x1);
+ array[1] = f2vt(y1);
+ array[2] = f2vt(x2);
+ array[3] = f2vt(y1);
+ array[4] = f2vt(x2);
+ array[5] = f2vt(y2);
+ array[6] = f2vt(x1);
+ array[7] = f2vt(y2);
+}
static void qDrawTextureRect(const QRectF &target, GLint textureWidth, GLint textureHeight, GLenum textureTarget)
{
@@ -4112,14 +4162,16 @@ void QGLWidget::drawTexture(const QPointF &point, QMacCompatGLuint textureId, QM
}
#endif
-#if defined(QT_OPENGL_ES_2)
-Q_GLOBAL_STATIC(QGL2PaintEngineEx, qt_gl_engine)
-#else
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+Q_GLOBAL_STATIC(QGL2PaintEngineEx, qt_gl_2_engine)
+#endif
+
+#ifndef QT_OPENGL_ES_2
Q_GLOBAL_STATIC(QOpenGLPaintEngine, qt_gl_engine)
#endif
#ifdef Q_WS_QWS
-Q_OPENGL_EXPORT QOpenGLPaintEngine* qt_qgl_paint_engine()
+Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine()
{
#if !defined(QT_OPENGL_ES_2)
return qt_gl_engine();
@@ -4137,7 +4189,16 @@ Q_OPENGL_EXPORT QOpenGLPaintEngine* qt_qgl_paint_engine()
*/
QPaintEngine *QGLWidget::paintEngine() const
{
+#if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_1_CL)
return qt_gl_engine();
+#elif defined(QT_OPENGL_ES_2)
+ return qt_gl_2_engine();
+#else
+ if (!qt_gl_preferGL2Engine())
+ return qt_gl_engine();
+ else
+ return qt_gl_2_engine();
+#endif
}
#ifdef QT3_SUPPORT
@@ -4226,6 +4287,8 @@ void QGLExtensions::init_extensions()
glExtensions |= FramebufferObject;
glExtensions |= GenerateMipmap;
#endif
+ if (extensions.contains(QLatin1String("EXT_framebuffer_blit")))
+ glExtensions |= FramebufferBlit;
QGLContext cx(QGLFormat::defaultFormat());
if (glExtensions & TextureCompression) {
@@ -4275,4 +4338,202 @@ Q_OPENGL_EXPORT const QString qt_gl_library_name()
}
#endif
+void QGLDrawable::setDevice(QPaintDevice *pdev)
+{
+ wasBound = false;
+ widget = 0;
+ buffer = 0;
+ fbo = 0;
+#ifdef Q_WS_QWS
+ wsurf = 0;
+#endif
+
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ if (pdev->devType() == QInternal::Pixmap) {
+ QPixmapData *data = static_cast<QPixmap *>(pdev)->pixmapData();
+ Q_ASSERT(data->classId() == QPixmapData::OpenGLClass);
+ pixmapData = static_cast<QGLPixmapData *>(data);
+
+ fbo = pixmapData->fbo();
+ }
+#else
+ Q_ASSERT(pdev->devType() != QInternal::Pixmap);
+#endif
+
+ if (pdev->devType() == QInternal::Widget)
+ widget = static_cast<QGLWidget *>(pdev);
+ else if (pdev->devType() == QInternal::Pbuffer)
+ buffer = static_cast<QGLPixelBuffer *>(pdev);
+ else if (pdev->devType() == QInternal::FramebufferObject)
+ fbo = static_cast<QGLFramebufferObject *>(pdev);
+#ifdef Q_WS_QWS
+ else if (pdev->devType() == QInternal::UnknownDevice)
+ wsurf = static_cast<QWSGLPaintDevice*>(pdev)->windowSurface();
+#elif !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ else if (pdev->devType() == QInternal::UnknownDevice)
+ wsurf = static_cast<QGLWindowSurface *>(pdev);
+#endif
+}
+
+void QGLDrawable::swapBuffers()
+{
+ if (widget) {
+ if (widget->autoBufferSwap())
+ widget->swapBuffers();
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ } else if (pixmapData) {
+ pixmapData->swapBuffers();
+#endif
+ } else {
+ glFlush();
+ }
+}
+
+void QGLDrawable::makeCurrent()
+{
+ if (widget)
+ widget->makeCurrent();
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ else if (pixmapData)
+ pixmapData->makeCurrent();
+#endif
+ else if (buffer)
+ buffer->makeCurrent();
+#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL))
+ else if (wsurf)
+ wsurf->context()->makeCurrent();
+#endif
+ else if (fbo) {
+ wasBound = fbo->isBound();
+ if (!wasBound)
+ fbo->bind();
+ }
+}
+
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+QGLPixmapData *QGLDrawable::copyOnBegin() const
+{
+ if (!pixmapData || pixmapData->isUninitialized())
+ return 0;
+ return pixmapData;
+}
+#endif
+
+void QGLDrawable::doneCurrent()
+{
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ if (pixmapData) {
+ pixmapData->doneCurrent();
+ return;
+ }
+#endif
+
+ if (fbo && !wasBound)
+ fbo->release();
+}
+
+QSize QGLDrawable::size() const
+{
+ if (widget) {
+ return QSize(widget->d_func()->glcx->device()->width(),
+ widget->d_func()->glcx->device()->height());
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ } else if (pixmapData) {
+ return pixmapData->size();
+#endif
+ } else if (buffer) {
+ return buffer->size();
+ } else if (fbo) {
+ return fbo->size();
+ }
+#ifdef Q_WS_QWS
+ else if (wsurf)
+ return wsurf->window()->frameSize();
+#elif !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ else if (wsurf)
+ return QSize(wsurf->width(), wsurf->height());
+#endif
+ return QSize();
+}
+
+QGLFormat QGLDrawable::format() const
+{
+ if (widget)
+ return widget->format();
+ else if (buffer)
+ return buffer->format();
+#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL))
+ else if (wsurf)
+ return wsurf->context()->format();
+#endif
+ else if (fbo && QGLContext::currentContext()) {
+ QGLFormat fmt = QGLContext::currentContext()->format();
+ fmt.setStencil(fbo->attachment() == QGLFramebufferObject::CombinedDepthStencil);
+ fmt.setDepth(fbo->attachment() != QGLFramebufferObject::NoAttachment);
+ return fmt;
+ }
+
+ return QGLFormat();
+}
+
+GLuint QGLDrawable::bindTexture(const QImage &image, GLenum target, GLint format)
+{
+ if (widget)
+ return widget->d_func()->glcx->d_func()->bindTexture(image, target, format, true);
+ else if (buffer)
+ return buffer->d_func()->qctx->d_func()->bindTexture(image, target, format, true);
+ else if (fbo && QGLContext::currentContext())
+ return const_cast<QGLContext *>(QGLContext::currentContext())->d_func()->bindTexture(image, target, format, true);
+#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL))
+ else if (wsurf)
+ return wsurf->context()->d_func()->bindTexture(image, target, format, true);
+#endif
+ return 0;
+}
+
+GLuint QGLDrawable::bindTexture(const QPixmap &pixmap, GLenum target, GLint format)
+{
+ if (widget)
+ return widget->d_func()->glcx->d_func()->bindTexture(pixmap, target, format, true);
+ else if (buffer)
+ return buffer->d_func()->qctx->d_func()->bindTexture(pixmap, target, format, true);
+ else if (fbo && QGLContext::currentContext())
+ return const_cast<QGLContext *>(QGLContext::currentContext())->d_func()->bindTexture(pixmap, target, format, true);
+#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL))
+ else if (wsurf)
+ return wsurf->context()->d_func()->bindTexture(pixmap, target, format, true);
+#endif
+ return 0;
+}
+
+QColor QGLDrawable::backgroundColor() const
+{
+ if (widget)
+ return widget->palette().brush(widget->backgroundRole()).color();
+ return QApplication::palette().brush(QPalette::Background).color();
+}
+
+QGLContext *QGLDrawable::context() const
+{
+ if (widget)
+ return widget->d_func()->glcx;
+ else if (buffer)
+ return buffer->d_func()->qctx;
+ else if (fbo)
+ return const_cast<QGLContext *>(QGLContext::currentContext());
+#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL))
+ else if (wsurf)
+ return wsurf->context();
+#endif
+ return 0;
+}
+
+bool QGLDrawable::autoFillBackground() const
+{
+ if (widget)
+ return widget->autoFillBackground();
+ else
+ return false;
+}
+
QT_END_NAMESPACE
diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h
index 32fbce2..19d779a 100644
--- a/src/opengl/qgl.h
+++ b/src/opengl/qgl.h
@@ -372,8 +372,8 @@ private:
friend QGLContextPrivate *qt_phonon_get_dptr(const QGLContext *);
#endif
friend class QGLFramebufferObject;
-#ifdef Q_WS_WIN
friend class QGLFramebufferObjectPrivate;
+#ifdef Q_WS_WIN
friend bool qt_resolve_GLSL_functions(QGLContext *ctx);
friend bool qt_createGLSLProgram(QGLContext *ctx, GLuint &program, const char *shader_src, GLuint &shader);
#endif
diff --git a/src/opengl/qgl_egl.cpp b/src/opengl/qgl_egl.cpp
index 98c5710..287c537 100644
--- a/src/opengl/qgl_egl.cpp
+++ b/src/opengl/qgl_egl.cpp
@@ -57,14 +57,14 @@ void qt_egl_set_format(QEglProperties& props, int deviceType, const QGLFormat& f
// Set the pixel format to that contained in the QGLFormat
// if the system hasn't already chosen a fixed format to
// match the pixmap, widget, etc.
- if (props.value(EGL_RED_SIZE) == EGL_DONT_CARE || f.redBufferSize() != -1)
+ if (props.value(EGL_RED_SIZE) == 0 || f.redBufferSize() != -1)
props.setValue(EGL_RED_SIZE, f.redBufferSize() == -1 ? 1 : f.redBufferSize());
- if (props.value(EGL_GREEN_SIZE) == EGL_DONT_CARE || f.greenBufferSize() != -1)
+ if (props.value(EGL_GREEN_SIZE) == 0 || f.greenBufferSize() != -1)
props.setValue(EGL_GREEN_SIZE, f.greenBufferSize() == -1 ? 1 : f.greenBufferSize());
- if (props.value(EGL_BLUE_SIZE) == EGL_DONT_CARE || f.blueBufferSize() != -1)
+ if (props.value(EGL_BLUE_SIZE) == 0 || f.blueBufferSize() != -1)
props.setValue(EGL_BLUE_SIZE, f.blueBufferSize() == -1 ? 1 : f.blueBufferSize());
if (f.alpha()) {
- if (props.value(EGL_ALPHA_SIZE) == EGL_DONT_CARE || f.alphaBufferSize() != -1)
+ if (props.value(EGL_ALPHA_SIZE) == 0 || f.alphaBufferSize() != -1)
props.setValue(EGL_ALPHA_SIZE, f.alphaBufferSize() == -1 ? 1 : f.alphaBufferSize());
}
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index 1214f20..b421eee 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -61,6 +61,10 @@
#include "QtCore/qhash.h"
#include "private/qwidget_p.h"
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+#include "private/qpixmapdata_gl_p.h"
+#endif
+
#ifndef QT_OPENGL_ES_1_CL
#define q_vertexType float
#define q_vertexTypeEnum GL_FLOAT
@@ -239,6 +243,7 @@ public:
QGLFormat glFormat;
QGLFormat reqFormat;
GLuint pbo;
+ GLuint fbo;
uint valid : 1;
uint sharing : 1;
@@ -256,6 +261,7 @@ public:
GLint max_texture_size;
GLuint current_fbo;
+ QPaintEngine *active_engine;
#ifdef Q_WS_WIN
static inline QGLExtensionFuncs& qt_get_extension_funcs(const QGLContext *ctx) { return ctx->d_ptr->extensionFuncs; }
@@ -283,6 +289,52 @@ Q_SIGNALS:
void aboutToDestroyContext(const QGLContext *context);
};
+class QGLPixelBuffer;
+class QGLFramebufferObject;
+class QWSGLWindowSurface;
+class QGLWindowSurface;
+class QGLDrawable {
+public:
+ QGLDrawable() : widget(0), buffer(0), fbo(0)
+#if defined(Q_WS_QWS) || (!defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL))
+ , wsurf(0)
+#endif
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ , pixmapData(0)
+#endif
+ {}
+ void setDevice(QPaintDevice *pdev);
+ void swapBuffers();
+ void makeCurrent();
+ void doneCurrent();
+ QSize size() const;
+ QGLFormat format() const;
+ GLuint bindTexture(const QImage &image, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA);
+ GLuint bindTexture(const QPixmap &pixmap, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA);
+ QColor backgroundColor() const;
+ QGLContext *context() const;
+ bool autoFillBackground() const;
+
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ QGLPixmapData *copyOnBegin() const;
+#endif
+
+private:
+ bool wasBound;
+ QGLWidget *widget;
+ QGLPixelBuffer *buffer;
+ QGLFramebufferObject *fbo;
+#ifdef Q_WS_QWS
+ QWSGLWindowSurface *wsurf;
+#elif !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ QGLWindowSurface *wsurf;
+#endif
+
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+ QGLPixmapData *pixmapData;
+#endif
+};
+
// GL extension definitions
class QGLExtensions {
public:
@@ -298,7 +350,8 @@ public:
StencilWrap = 0x00000100,
PackedDepthStencil = 0x00000200,
NVFloatBuffer = 0x00000400,
- PixelBufferObject = 0x00000800
+ PixelBufferObject = 0x00000800,
+ FramebufferBlit = 0x00001000
};
Q_DECLARE_FLAGS(Extensions, Extension)
@@ -379,6 +432,16 @@ extern QOpenGLPaintEngine* qt_qgl_paint_engine();
extern EGLDisplay qt_qgl_egl_display();
#endif
+inline bool qt_gl_preferGL2Engine()
+{
+#if defined(QT_OPENGL_ES_2)
+ return true;
+#else
+ return (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0)
+ && !qgetenv("QT_GL_USE_OPENGL2ENGINE").isEmpty();
+#endif
+}
+
inline GLenum qt_gl_preferredTextureFormat()
{
return QSysInfo::ByteOrder == QSysInfo::BigEndian ? GL_RGBA : GL_BGRA;
@@ -386,12 +449,16 @@ inline GLenum qt_gl_preferredTextureFormat()
inline GLenum qt_gl_preferredTextureTarget()
{
+#if defined(QT_OPENGL_ES_2)
+ return GL_TEXTURE_2D;
+#else
return (QGLExtensions::glExtensions & QGLExtensions::TextureRectangle)
+ && !qt_gl_preferGL2Engine()
? GL_TEXTURE_RECTANGLE_NV
: GL_TEXTURE_2D;
+#endif
}
-
QT_END_NAMESPACE
#endif // QGL_P_H
diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp
index 480a2dc..514e763 100644
--- a/src/opengl/qgl_x11egl.cpp
+++ b/src/opengl/qgl_x11egl.cpp
@@ -114,13 +114,6 @@ bool QGLContext::chooseContext(const QGLContext* shareContext)
eglSwapInterval(d->eglContext->display(), d->glFormat.swapInterval());
#endif
- // Create the EGL surface to draw into.
- if (!d->eglContext->createSurface(device())) {
- delete d->eglContext;
- d->eglContext = 0;
- return false;
- }
-
return true;
}
@@ -250,13 +243,34 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext,
return;
}
+
+ // Create the EGL Context (which will also choose the config for us)
if (d->glcx)
d->glcx->doneCurrent();
QGLContext* oldcx = d->glcx;
d->glcx = context;
+ bool createFailed = false;
+ if (!d->glcx->isValid()) {
+ if (!d->glcx->create(shareContext ? shareContext : oldcx))
+ createFailed = true;
+ }
+ if (createFailed) {
+ if (deleteOldContext)
+ delete oldcx;
+ return;
+ }
+
+ if (d->glcx->windowCreated() || d->glcx->deviceIsPixmap()) {
+ if (deleteOldContext)
+ delete oldcx;
+ return;
+ }
+
+
+
+ // Make sure native winIds are avaliable
if (parentWidget()) {
- // force creation of delay-created widgets
parentWidget()->winId();
if (parentWidget()->x11Info().screen() != x11Info().screen())
d_func()->xinfo = parentWidget()->d_func()->xinfo;
@@ -267,16 +281,97 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext,
hide();
XVisualInfo vi;
+ memset(&vi, 0, sizeof(XVisualInfo));
+
+ // Check to see if EGL is suggesting an appropriate visual id:
+ EGLint nativeVisualId;
+ QEglContext* qeglCtx = d->glcx->d_func()->eglContext;
+ qeglCtx->configAttrib(EGL_NATIVE_VISUAL_ID, &nativeVisualId);
+ vi.visualid = nativeVisualId;
+
+ if (vi.visualid) {
+ // EGL has suggested a visual id, so get the rest of the visual info for that id:
+ XVisualInfo *chosenVisualInfo;
+ int matchingCount = 0;
+ chosenVisualInfo = XGetVisualInfo(x11Info().display(), VisualIDMask, &vi, &matchingCount);
+ if (chosenVisualInfo) {
+ qDebug("Using X Visual ID (%d) provided by EGL", (int)vi.visualid);
+ vi = *chosenVisualInfo;
+ XFree(chosenVisualInfo);
+ }
+ else {
+ qWarning("Warning: EGL suggested using X visual ID %d for config %d, but this seems to be invalid!",
+ nativeVisualId, (int)qeglCtx->config());
+ vi.visualid = 0;
+ }
+ }
- int err = XMatchVisualInfo(x11Info().display(), x11Info().screen(), x11Info().depth(), TrueColor, &vi);
- if (err == 0) {
- qWarning("Error: Couldn't get a matching X visual for format");
- return;
+ // If EGL does not know the visual ID, so try to select an appropriate one ourselves, first
+ // using XRender if we're supposed to have an alpha, then falling back to XGetVisualInfo
+
+ bool useArgb = context->format().alpha() && !context->deviceIsPixmap();
+#if !defined(QT_NO_XRENDER)
+ if (vi.visualid == 0 && useArgb) {
+ // Try to use XRender to find an ARGB visual we can use
+ vi.screen = x11Info().screen();
+ vi.depth = 32;
+ vi.c_class = TrueColor;
+ XVisualInfo *matchingVisuals;
+ int matchingCount = 0;
+ matchingVisuals = XGetVisualInfo(x11Info().display(),
+ VisualScreenMask|VisualDepthMask|VisualClassMask,
+ &vi, &matchingCount);
+
+ for (int i = 0; i < matchingCount; ++i) {
+ XRenderPictFormat *format;
+ format = XRenderFindVisualFormat(x11Info().display(), matchingVisuals[i].visual);
+ if (format->type == PictTypeDirect && format->direct.alphaMask) {
+ vi = matchingVisuals[i];
+ qDebug("Using X Visual ID (%d) for ARGB visual as provided by XRender", (int)vi.visualid);
+ break;
+ }
+ }
+ XFree(matchingVisuals);
}
+#endif
+
+ if (vi.visualid == 0) {
+ EGLint depth;
+ qeglCtx->configAttrib(EGL_BUFFER_SIZE, &depth);
+ int err;
+ err = XMatchVisualInfo(x11Info().display(), x11Info().screen(), depth, TrueColor, &vi);
+ if (err == 0) {
+ qWarning("Warning: Can't find an X visual which matches the EGL config(%d)'s depth (%d)!",
+ (int)qeglCtx->config(), depth);
+ depth = x11Info().depth();
+ err = XMatchVisualInfo(x11Info().display(), x11Info().screen(), depth, TrueColor, &vi);
+ if (err == 0) {
+ qWarning("Error: Couldn't get any matching X visual!");
+ return;
+ } else
+ qWarning(" - Falling back to X11 suggested depth (%d)", depth);
+ } else
+ qDebug("Using X Visual ID (%d) for EGL provided depth (%d)", (int)vi.visualid, depth);
+
+ // Don't try to use ARGB now unless the visual is 32-bit - even then it might stil fail :-(
+ if (useArgb)
+ useArgb = vi.depth == 32;
+ }
+
+// qDebug("Visual Info:");
+// qDebug(" bits_per_rgb=%d", vi.bits_per_rgb);
+// qDebug(" red_mask=0x%x", vi.red_mask);
+// qDebug(" green_mask=0x%x", vi.green_mask);
+// qDebug(" blue_mask=0x%x", vi.blue_mask);
+// qDebug(" colormap_size=%d", vi.colormap_size);
+// qDebug(" c_class=%d", vi.c_class);
+// qDebug(" depth=%d", vi.depth);
+// qDebug(" screen=%d", vi.screen);
+// qDebug(" visualid=%d", vi.visualid);
XSetWindowAttributes a;
- Window p = RootWindow(X11->display, vi.screen);
+ Window p = RootWindow(x11Info().display(), x11Info().screen());
if (parentWidget())
p = parentWidget()->winId();
@@ -284,9 +379,13 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext,
a.background_pixel = colmap.pixel(palette().color(backgroundRole()));
a.border_pixel = colmap.pixel(Qt::black);
- Window w = XCreateWindow(X11->display, p, x(), y(), width(), height(),
- 0, vi.depth, InputOutput, vi.visual,
- CWBackPixel|CWBorderPixel, &a);
+ unsigned int valueMask = CWBackPixel|CWBorderPixel;
+ if(useArgb) {
+ a.colormap = XCreateColormap(x11Info().display(), p, vi.visual, AllocNone);
+ valueMask |= CWColormap;
+ }
+ Window w = XCreateWindow(x11Info().display(), p, x(), y(), width(), height(),
+ 0, vi.depth, InputOutput, vi.visual, valueMask, &a);
if (deleteOldContext)
delete oldcx;
@@ -294,27 +393,18 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext,
create(w); // Create with the ID of the window we've just created
- d->eglSurfaceWindowId = w; // Remember the window id we created the surface for
-
- if (visible)
- show();
- bool createFailed = false;
- if (!d->glcx->isValid()) {
- if (!d->glcx->create(shareContext ? shareContext : oldcx))
- createFailed = true;
- }
- if (createFailed) {
- if (deleteOldContext)
- delete oldcx;
+ // Create the EGL surface to draw into.
+ if (!d->glcx->d_func()->eglContext->createSurface(this)) {
+ delete d->glcx->d_func()->eglContext;
+ d->glcx->d_func()->eglContext = 0;
return;
}
- if (d->glcx->windowCreated() || d->glcx->deviceIsPixmap()) {
- if (deleteOldContext)
- delete oldcx;
- return;
- }
+ d->eglSurfaceWindowId = w; // Remember the window id we created the surface for
+
+ if (visible)
+ show();
d->glcx->setWindowCreated(true);
}
diff --git a/src/opengl/qglextensions.cpp b/src/opengl/qglextensions.cpp
index 8357cf9..3c198fb 100644
--- a/src/opengl/qglextensions.cpp
+++ b/src/opengl/qglextensions.cpp
@@ -45,9 +45,15 @@ QT_BEGIN_NAMESPACE
bool qt_resolve_framebufferobject_extensions(QGLContext *ctx)
{
-#if !defined(QT_OPENGL_ES_2)
- if (glIsRenderbufferEXT != 0)
+#if defined(QT_OPENGL_ES_2)
+ static bool have_resolved = false;
+ if (have_resolved)
+ return true;
+ have_resolved = true;
+#else
+ if (glIsRenderbuffer != 0)
return true;
+#endif
if (ctx == 0) {
qWarning("QGLFramebufferObject: Unable to resolve framebuffer object extensions -"
@@ -55,32 +61,37 @@ bool qt_resolve_framebufferobject_extensions(QGLContext *ctx)
return false;
}
- glIsRenderbufferEXT = (_glIsRenderbufferEXT) ctx->getProcAddress(QLatin1String("glIsRenderbufferEXT"));
- glBindRenderbufferEXT = (_glBindRenderbufferEXT) ctx->getProcAddress(QLatin1String("glBindRenderbufferEXT"));
- glDeleteRenderbuffersEXT = (_glDeleteRenderbuffersEXT) ctx->getProcAddress(QLatin1String("glDeleteRenderbuffersEXT"));
- glGenRenderbuffersEXT = (_glGenRenderbuffersEXT) ctx->getProcAddress(QLatin1String("glGenRenderbuffersEXT"));
- glRenderbufferStorageEXT = (_glRenderbufferStorageEXT) ctx->getProcAddress(QLatin1String("glRenderbufferStorageEXT"));
- glGetRenderbufferParameterivEXT =
- (_glGetRenderbufferParameterivEXT) ctx->getProcAddress(QLatin1String("glGetRenderbufferParameterivEXT"));
- glIsFramebufferEXT = (_glIsFramebufferEXT) ctx->getProcAddress(QLatin1String("glIsFramebufferEXT"));
- glBindFramebufferEXT = (_glBindFramebufferEXT) ctx->getProcAddress(QLatin1String("glBindFramebufferEXT"));
- glDeleteFramebuffersEXT = (_glDeleteFramebuffersEXT) ctx->getProcAddress(QLatin1String("glDeleteFramebuffersEXT"));
- glGenFramebuffersEXT = (_glGenFramebuffersEXT) ctx->getProcAddress(QLatin1String("glGenFramebuffersEXT"));
- glCheckFramebufferStatusEXT = (_glCheckFramebufferStatusEXT) ctx->getProcAddress(QLatin1String("glCheckFramebufferStatusEXT"));
- glFramebufferTexture1DEXT = (_glFramebufferTexture1DEXT) ctx->getProcAddress(QLatin1String("glFramebufferTexture1DEXT"));
- glFramebufferTexture2DEXT = (_glFramebufferTexture2DEXT) ctx->getProcAddress(QLatin1String("glFramebufferTexture2DEXT"));
- glFramebufferTexture3DEXT = (_glFramebufferTexture3DEXT) ctx->getProcAddress(QLatin1String("glFramebufferTexture3DEXT"));
- glFramebufferRenderbufferEXT = (_glFramebufferRenderbufferEXT) ctx->getProcAddress(QLatin1String("glFramebufferRenderbufferEXT"));
- glGetFramebufferAttachmentParameterivEXT =
- (_glGetFramebufferAttachmentParameterivEXT) ctx->getProcAddress(QLatin1String("glGetFramebufferAttachmentParameterivEXT"));
- glGenerateMipmapEXT = (_glGenerateMipmapEXT) ctx->getProcAddress(QLatin1String("glGenerateMipmapEXT"));
- return glIsRenderbufferEXT;
+
+ glBlitFramebufferEXT = (_glBlitFramebufferEXT) ctx->getProcAddress(QLatin1String("glBlitFramebufferEXT"));
+ glRenderbufferStorageMultisampleEXT =
+ (_glRenderbufferStorageMultisampleEXT) ctx->getProcAddress(QLatin1String("glRenderbufferStorageMultisampleEXT"));
+
+#if !defined(QT_OPENGL_ES_2)
+ glIsRenderbuffer = (_glIsRenderbuffer) ctx->getProcAddress(QLatin1String("glIsRenderbufferEXT"));
+ glBindRenderbuffer = (_glBindRenderbuffer) ctx->getProcAddress(QLatin1String("glBindRenderbufferEXT"));
+ glDeleteRenderbuffers = (_glDeleteRenderbuffers) ctx->getProcAddress(QLatin1String("glDeleteRenderbuffersEXT"));
+ glGenRenderbuffers = (_glGenRenderbuffers) ctx->getProcAddress(QLatin1String("glGenRenderbuffersEXT"));
+ glRenderbufferStorage = (_glRenderbufferStorage) ctx->getProcAddress(QLatin1String("glRenderbufferStorageEXT"));
+ glGetRenderbufferParameteriv =
+ (_glGetRenderbufferParameteriv) ctx->getProcAddress(QLatin1String("glGetRenderbufferParameterivEXT"));
+ glIsFramebuffer = (_glIsFramebuffer) ctx->getProcAddress(QLatin1String("glIsFramebufferEXT"));
+ glBindFramebuffer = (_glBindFramebuffer) ctx->getProcAddress(QLatin1String("glBindFramebufferEXT"));
+ glDeleteFramebuffers = (_glDeleteFramebuffers) ctx->getProcAddress(QLatin1String("glDeleteFramebuffersEXT"));
+ glGenFramebuffers = (_glGenFramebuffers) ctx->getProcAddress(QLatin1String("glGenFramebuffersEXT"));
+ glCheckFramebufferStatus = (_glCheckFramebufferStatus) ctx->getProcAddress(QLatin1String("glCheckFramebufferStatusEXT"));
+ glFramebufferTexture2D = (_glFramebufferTexture2D) ctx->getProcAddress(QLatin1String("glFramebufferTexture2DEXT"));
+ glFramebufferRenderbuffer = (_glFramebufferRenderbuffer) ctx->getProcAddress(QLatin1String("glFramebufferRenderbufferEXT"));
+ glGetFramebufferAttachmentParameteriv =
+ (_glGetFramebufferAttachmentParameteriv) ctx->getProcAddress(QLatin1String("glGetFramebufferAttachmentParameterivEXT"));
+ glGenerateMipmap = (_glGenerateMipmap) ctx->getProcAddress(QLatin1String("glGenerateMipmapEXT"));
+
+ return glIsRenderbuffer;
#else
- Q_UNUSED(ctx);
return true;
#endif
}
+#if !defined(QT_OPENGL_ES_2)
bool qt_resolve_version_1_3_functions(QGLContext *ctx)
{
if (glMultiTexCoord4f != 0)
@@ -89,14 +100,12 @@ bool qt_resolve_version_1_3_functions(QGLContext *ctx)
QGLContext cx(QGLFormat::defaultFormat());
glMultiTexCoord4f = (_glMultiTexCoord4f) ctx->getProcAddress(QLatin1String("glMultiTexCoord4f"));
-#if defined(QT_OPENGL_ES_2)
- return glMultiTexCoord4f;
-#else
glActiveTexture = (_glActiveTexture) ctx->getProcAddress(QLatin1String("glActiveTexture"));
return glMultiTexCoord4f && glActiveTexture;
-#endif
}
+#endif
+#if !defined(QT_OPENGL_ES_2)
bool qt_resolve_stencil_face_extension(QGLContext *ctx)
{
if (glActiveStencilFaceEXT != 0)
@@ -107,7 +116,10 @@ bool qt_resolve_stencil_face_extension(QGLContext *ctx)
return glActiveStencilFaceEXT;
}
+#endif
+
+#if !defined(QT_OPENGL_ES_2)
bool qt_resolve_frag_program_extensions(QGLContext *ctx)
{
if (glProgramStringARB != 0)
@@ -126,60 +138,215 @@ bool qt_resolve_frag_program_extensions(QGLContext *ctx)
&& glGenProgramsARB
&& glProgramLocalParameter4fvARB;
}
+#endif
+
bool qt_resolve_buffer_extensions(QGLContext *ctx)
{
- if (glBindBufferARB && glDeleteBuffersARB && glGenBuffersARB && glBufferDataARB
- && glMapBufferARB && glUnmapBufferARB)
+ if (glMapBufferARB && glUnmapBufferARB
+#if !defined(QT_OPENGL_ES_2)
+ && glBindBuffer && glDeleteBuffers && glGenBuffers && glBufferData
+#endif
+ )
return true;
- glBindBufferARB = (_glBindBufferARB) ctx->getProcAddress(QLatin1String("glBindBufferARB"));
- glDeleteBuffersARB = (_glDeleteBuffersARB) ctx->getProcAddress(QLatin1String("glDeleteBuffersARB"));
- glGenBuffersARB = (_glGenBuffersARB) ctx->getProcAddress(QLatin1String("glGenBuffersARB"));
- glBufferDataARB = (_glBufferDataARB) ctx->getProcAddress(QLatin1String("glBufferDataARB"));
+#if !defined(QT_OPENGL_ES_2)
+ glBindBuffer = (_glBindBuffer) ctx->getProcAddress(QLatin1String("glBindBufferARB"));
+ glDeleteBuffers = (_glDeleteBuffers) ctx->getProcAddress(QLatin1String("glDeleteBuffersARB"));
+ glGenBuffers = (_glGenBuffers) ctx->getProcAddress(QLatin1String("glGenBuffersARB"));
+ glBufferData = (_glBufferData) ctx->getProcAddress(QLatin1String("glBufferDataARB"));
+#endif
glMapBufferARB = (_glMapBufferARB) ctx->getProcAddress(QLatin1String("glMapBufferARB"));
glUnmapBufferARB = (_glUnmapBufferARB) ctx->getProcAddress(QLatin1String("glUnmapBufferARB"));
- return glBindBufferARB
- && glDeleteBuffersARB
- && glGenBuffersARB
- && glBufferDataARB
- && glMapBufferARB
- && glUnmapBufferARB;
+ return glMapBufferARB
+ && glUnmapBufferARB
+#if !defined(QT_OPENGL_ES_2)
+ && glBindBuffer
+ && glDeleteBuffers
+ && glGenBuffers
+ && glBufferData
+#endif
+ ;
}
bool qt_resolve_glsl_extensions(QGLContext *ctx)
{
+#if defined(QT_OPENGL_ES_2)
+ // The GLSL shader functions are always present in OpenGL/ES 2.0.
+ // The only exceptions are glGetProgramBinaryOES and glProgramBinaryOES.
+ if (!QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glslResolved) {
+ glGetProgramBinaryOES = (_glGetProgramBinaryOES) ctx->getProcAddress(QLatin1String("glGetProgramBinaryOES"));
+ glProgramBinaryOES = (_glProgramBinaryOES) ctx->getProcAddress(QLatin1String("glProgramBinaryOES"));
+ QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glslResolved = true;
+ }
+ return true;
+#else
if (glCreateShader)
return true;
glCreateShader = (_glCreateShader) ctx->getProcAddress(QLatin1String("glCreateShader"));
- glShaderSource = (_glShaderSource) ctx->getProcAddress(QLatin1String("glShaderSource"));
- glCompileShader = (_glCompileShader) ctx->getProcAddress(QLatin1String("glCompileShader"));
- glDeleteShader = (_glDeleteShader) ctx->getProcAddress(QLatin1String("glDeleteShader"));
-
- glCreateProgram = (_glCreateProgram) ctx->getProcAddress(QLatin1String("glCreateProgram"));
- glAttachShader = (_glAttachShader) ctx->getProcAddress(QLatin1String("glAttachShader"));
- glDetachShader = (_glDetachShader) ctx->getProcAddress(QLatin1String("glDetachShader"));
- glLinkProgram = (_glLinkProgram) ctx->getProcAddress(QLatin1String("glLinkProgram"));
- glUseProgram = (_glUseProgram) ctx->getProcAddress(QLatin1String("glUseProgram"));
- glDeleteProgram = (_glDeleteProgram) ctx->getProcAddress(QLatin1String("glDeleteProgram"));
-
- glGetShaderInfoLog = (_glGetShaderInfoLog) ctx->getProcAddress(QLatin1String("glGetShaderInfoLog"));
- glGetShaderiv = (_glGetShaderiv) ctx->getProcAddress(QLatin1String("glGetShaderiv"));
- glGetProgramiv = (_glGetProgramiv) ctx->getProcAddress(QLatin1String("glGetProgramiv"));
-
- glGetUniformLocation = (_glGetUniformLocation) ctx->getProcAddress(QLatin1String("glGetUniformLocation"));
- glUniform4fv = (_glUniform4fv) ctx->getProcAddress(QLatin1String("glUniform4fv"));
- glUniform3fv = (_glUniform3fv) ctx->getProcAddress(QLatin1String("glUniform3fv"));
- glUniform2fv = (_glUniform2fv) ctx->getProcAddress(QLatin1String("glUniform2fv"));
- glUniform1fv = (_glUniform1fv) ctx->getProcAddress(QLatin1String("glUniform1fv"));
- glUniform1i = (_glUniform1i) ctx->getProcAddress(QLatin1String("glUniform1i"));
-
- return glCreateShader && glShaderSource && glCompileShader && glDeleteProgram &&
- glCreateProgram && glAttachShader && glDetachShader && glLinkProgram && glUseProgram &&
- glDeleteProgram && glGetShaderInfoLog && glGetShaderiv && glGetProgramiv && glGetUniformLocation &&
- glUniform1i && glUniform1fv && glUniform2fv && glUniform3fv && glUniform4fv;
+ if (glCreateShader) {
+ glShaderSource = (_glShaderSource) ctx->getProcAddress(QLatin1String("glShaderSource"));
+ glShaderBinary = (_glShaderBinary) ctx->getProcAddress(QLatin1String("glShaderBinary"));
+ glCompileShader = (_glCompileShader) ctx->getProcAddress(QLatin1String("glCompileShader"));
+ glDeleteShader = (_glDeleteShader) ctx->getProcAddress(QLatin1String("glDeleteShader"));
+ glIsShader = (_glIsShader) ctx->getProcAddress(QLatin1String("glIsShader"));
+
+ glCreateProgram = (_glCreateProgram) ctx->getProcAddress(QLatin1String("glCreateProgram"));
+ glAttachShader = (_glAttachShader) ctx->getProcAddress(QLatin1String("glAttachShader"));
+ glDetachShader = (_glDetachShader) ctx->getProcAddress(QLatin1String("glDetachShader"));
+ glLinkProgram = (_glLinkProgram) ctx->getProcAddress(QLatin1String("glLinkProgram"));
+ glUseProgram = (_glUseProgram) ctx->getProcAddress(QLatin1String("glUseProgram"));
+ glDeleteProgram = (_glDeleteProgram) ctx->getProcAddress(QLatin1String("glDeleteProgram"));
+ glIsProgram = (_glIsProgram) ctx->getProcAddress(QLatin1String("glIsProgram"));
+
+ glGetShaderInfoLog = (_glGetShaderInfoLog) ctx->getProcAddress(QLatin1String("glGetShaderInfoLog"));
+ glGetShaderiv = (_glGetShaderiv) ctx->getProcAddress(QLatin1String("glGetShaderiv"));
+ glGetShaderSource = (_glGetShaderSource) ctx->getProcAddress(QLatin1String("glGetShaderSource"));
+ glGetProgramiv = (_glGetProgramiv) ctx->getProcAddress(QLatin1String("glGetProgramiv"));
+ glGetProgramInfoLog = (_glGetProgramInfoLog) ctx->getProcAddress(QLatin1String("glGetProgramInfoLog"));
+
+ glGetUniformLocation = (_glGetUniformLocation) ctx->getProcAddress(QLatin1String("glGetUniformLocation"));
+ glUniform4fv = (_glUniform4fv) ctx->getProcAddress(QLatin1String("glUniform4fv"));
+ glUniform3fv = (_glUniform3fv) ctx->getProcAddress(QLatin1String("glUniform3fv"));
+ glUniform2fv = (_glUniform2fv) ctx->getProcAddress(QLatin1String("glUniform2fv"));
+ glUniform1fv = (_glUniform1fv) ctx->getProcAddress(QLatin1String("glUniform1fv"));
+ glUniform1i = (_glUniform1i) ctx->getProcAddress(QLatin1String("glUniform1i"));
+ glUniform1iv = (_glUniform1iv) ctx->getProcAddress(QLatin1String("glUniform1iv"));
+ glUniformMatrix2fv = (_glUniformMatrix2fv) ctx->getProcAddress(QLatin1String("glUniformMatrix2fv"));
+ glUniformMatrix3fv = (_glUniformMatrix3fv) ctx->getProcAddress(QLatin1String("glUniformMatrix3fv"));
+ glUniformMatrix4fv = (_glUniformMatrix4fv) ctx->getProcAddress(QLatin1String("glUniformMatrix4fv"));
+ glUniformMatrix2x3fv = (_glUniformMatrix2x3fv) ctx->getProcAddress(QLatin1String("glUniformMatrix2x3fv"));
+ glUniformMatrix2x4fv = (_glUniformMatrix2x4fv) ctx->getProcAddress(QLatin1String("glUniformMatrix2x4fv"));
+ glUniformMatrix3x2fv = (_glUniformMatrix3x2fv) ctx->getProcAddress(QLatin1String("glUniformMatrix3x2fv"));
+ glUniformMatrix3x4fv = (_glUniformMatrix3x4fv) ctx->getProcAddress(QLatin1String("glUniformMatrix3x4fv"));
+ glUniformMatrix4x2fv = (_glUniformMatrix4x2fv) ctx->getProcAddress(QLatin1String("glUniformMatrix4x2fv"));
+ glUniformMatrix4x3fv = (_glUniformMatrix4x3fv) ctx->getProcAddress(QLatin1String("glUniformMatrix4x3fv"));
+
+ glBindAttribLocation = (_glBindAttribLocation) ctx->getProcAddress(QLatin1String("glBindAttribLocation"));
+ glGetAttribLocation = (_glGetAttribLocation) ctx->getProcAddress(QLatin1String("glGetAttribLocation"));
+ glVertexAttrib1fv = (_glVertexAttrib1fv) ctx->getProcAddress(QLatin1String("glVertexAttrib1fv"));
+ glVertexAttrib2fv = (_glVertexAttrib2fv) ctx->getProcAddress(QLatin1String("glVertexAttrib2fv"));
+ glVertexAttrib3fv = (_glVertexAttrib3fv) ctx->getProcAddress(QLatin1String("glVertexAttrib3fv"));
+ glVertexAttrib4fv = (_glVertexAttrib4fv) ctx->getProcAddress(QLatin1String("glVertexAttrib4fv"));
+ glVertexAttribPointer = (_glVertexAttribPointer) ctx->getProcAddress(QLatin1String("glVertexAttribPointer"));
+ glDisableVertexAttribArray = (_glDisableVertexAttribArray) ctx->getProcAddress(QLatin1String("glDisableVertexAttribArray"));
+ glEnableVertexAttribArray = (_glEnableVertexAttribArray) ctx->getProcAddress(QLatin1String("glEnableVertexAttribArray"));
+
+ } else {
+ // We may not have the standard shader functions, but we might
+ // have the older ARB functions instead.
+ glCreateShader = (_glCreateShader) ctx->getProcAddress(QLatin1String("glCreateShaderObjectARB"));
+ glShaderSource = (_glShaderSource) ctx->getProcAddress(QLatin1String("glShaderSourceARB"));
+ glShaderBinary = (_glShaderBinary) ctx->getProcAddress(QLatin1String("glShaderBinaryARB"));
+ glCompileShader = (_glCompileShader) ctx->getProcAddress(QLatin1String("glCompileShaderARB"));
+ glDeleteShader = (_glDeleteShader) ctx->getProcAddress(QLatin1String("glDeleteObjectARB"));
+ glIsShader = 0;
+
+ glCreateProgram = (_glCreateProgram) ctx->getProcAddress(QLatin1String("glCreateProgramObjectARB"));
+ glAttachShader = (_glAttachShader) ctx->getProcAddress(QLatin1String("glAttachObjectARB"));
+ glDetachShader = (_glDetachShader) ctx->getProcAddress(QLatin1String("glDetachObjectARB"));
+ glLinkProgram = (_glLinkProgram) ctx->getProcAddress(QLatin1String("glLinkProgramARB"));
+ glUseProgram = (_glUseProgram) ctx->getProcAddress(QLatin1String("glUseProgramObjectARB"));
+ glDeleteProgram = (_glDeleteProgram) ctx->getProcAddress(QLatin1String("glDeleteObjectARB"));
+ glIsProgram = 0;
+
+ glGetShaderInfoLog = (_glGetShaderInfoLog) ctx->getProcAddress(QLatin1String("glGetInfoLogARB"));
+ glGetShaderiv = (_glGetShaderiv) ctx->getProcAddress(QLatin1String("glGetObjectParameterivARB"));
+ glGetShaderSource = (_glGetShaderSource) ctx->getProcAddress(QLatin1String("glGetShaderSourceARB"));
+ glGetProgramiv = (_glGetProgramiv) ctx->getProcAddress(QLatin1String("glGetObjectParameterivARB"));
+ glGetProgramInfoLog = (_glGetProgramInfoLog) ctx->getProcAddress(QLatin1String("glGetInfoLogARB"));
+
+ glGetUniformLocation = (_glGetUniformLocation) ctx->getProcAddress(QLatin1String("glGetUniformLocationARB"));
+ glUniform4fv = (_glUniform4fv) ctx->getProcAddress(QLatin1String("glUniform4fvARB"));
+ glUniform3fv = (_glUniform3fv) ctx->getProcAddress(QLatin1String("glUniform3fvARB"));
+ glUniform2fv = (_glUniform2fv) ctx->getProcAddress(QLatin1String("glUniform2fvARB"));
+ glUniform1fv = (_glUniform1fv) ctx->getProcAddress(QLatin1String("glUniform1fvARB"));
+ glUniform1i = (_glUniform1i) ctx->getProcAddress(QLatin1String("glUniform1iARB"));
+ glUniform1iv = (_glUniform1iv) ctx->getProcAddress(QLatin1String("glUniform1ivARB"));
+ glUniformMatrix2fv = (_glUniformMatrix2fv) ctx->getProcAddress(QLatin1String("glUniformMatrix2fvARB"));
+ glUniformMatrix3fv = (_glUniformMatrix3fv) ctx->getProcAddress(QLatin1String("glUniformMatrix3fvARB"));
+ glUniformMatrix4fv = (_glUniformMatrix4fv) ctx->getProcAddress(QLatin1String("glUniformMatrix4fvARB"));
+ glUniformMatrix2x3fv = (_glUniformMatrix2x3fv) ctx->getProcAddress(QLatin1String("glUniformMatrix2x3fvARB"));
+ glUniformMatrix2x4fv = (_glUniformMatrix2x4fv) ctx->getProcAddress(QLatin1String("glUniformMatrix2x4fvARB"));
+ glUniformMatrix3x2fv = (_glUniformMatrix3x2fv) ctx->getProcAddress(QLatin1String("glUniformMatrix3x2fvARB"));
+ glUniformMatrix3x4fv = (_glUniformMatrix3x4fv) ctx->getProcAddress(QLatin1String("glUniformMatrix3x4fvARB"));
+ glUniformMatrix4x2fv = (_glUniformMatrix4x2fv) ctx->getProcAddress(QLatin1String("glUniformMatrix4x2fvARB"));
+ glUniformMatrix4x3fv = (_glUniformMatrix4x3fv) ctx->getProcAddress(QLatin1String("glUniformMatrix4x3fvARB"));
+
+ glBindAttribLocation = (_glBindAttribLocation) ctx->getProcAddress(QLatin1String("glBindAttribLocationARB"));
+ glGetAttribLocation = (_glGetAttribLocation) ctx->getProcAddress(QLatin1String("glGetAttribLocationARB"));
+ glVertexAttrib1fv = (_glVertexAttrib1fv) ctx->getProcAddress(QLatin1String("glVertexAttrib1fvARB"));
+ glVertexAttrib2fv = (_glVertexAttrib2fv) ctx->getProcAddress(QLatin1String("glVertexAttrib2fvARB"));
+ glVertexAttrib3fv = (_glVertexAttrib3fv) ctx->getProcAddress(QLatin1String("glVertexAttrib3fvARB"));
+ glVertexAttrib4fv = (_glVertexAttrib4fv) ctx->getProcAddress(QLatin1String("glVertexAttrib4fvARB"));
+ glVertexAttribPointer = (_glVertexAttribPointer) ctx->getProcAddress(QLatin1String("glVertexAttribPointerARB"));
+ glDisableVertexAttribArray = (_glDisableVertexAttribArray) ctx->getProcAddress(QLatin1String("glDisableVertexAttribArrayARB"));
+ glEnableVertexAttribArray = (_glEnableVertexAttribArray) ctx->getProcAddress(QLatin1String("glEnableVertexAttribArrayARB"));
+ }
+
+ // Note: glShaderBinary(), glIsShader(), glIsProgram(), and
+ // glUniformMatrixNxMfv() are optional, but all other functions
+ // are required.
+
+ return glCreateShader &&
+ glShaderSource &&
+ glCompileShader &&
+ glDeleteProgram &&
+ glCreateProgram &&
+ glAttachShader &&
+ glDetachShader &&
+ glLinkProgram &&
+ glUseProgram &&
+ glDeleteProgram &&
+ glGetShaderInfoLog &&
+ glGetShaderiv &&
+ glGetShaderSource &&
+ glGetProgramiv &&
+ glGetProgramInfoLog &&
+ glGetUniformLocation &&
+ glUniform1fv &&
+ glUniform2fv &&
+ glUniform3fv &&
+ glUniform4fv &&
+ glUniform1i &&
+ glUniform1iv &&
+ glUniformMatrix2fv &&
+ glUniformMatrix3fv &&
+ glUniformMatrix4fv &&
+ glBindAttribLocation &&
+ glGetAttribLocation &&
+ glVertexAttrib1fv &&
+ glVertexAttrib2fv &&
+ glVertexAttrib3fv &&
+ glVertexAttrib4fv &&
+ glVertexAttribPointer &&
+ glDisableVertexAttribArray &&
+ glEnableVertexAttribArray;
+#endif
}
+#if !defined(QT_OPENGL_ES_2)
+bool qt_resolve_version_2_0_functions(QGLContext *ctx)
+{
+ bool gl2supported = true;
+ if (!qt_resolve_glsl_extensions(ctx))
+ gl2supported = false;
+
+ if (!qt_resolve_version_1_3_functions(ctx))
+ gl2supported = false;
+
+ if (glStencilOpSeparate)
+ return gl2supported;
+
+ glStencilOpSeparate = (_glStencilOpSeparate) ctx->getProcAddress(QLatin1String("glStencilOpSeparate"));
+ if (!glStencilOpSeparate)
+ gl2supported = false;
+
+ return gl2supported;
+}
+#endif
+
+
QT_END_NAMESPACE
diff --git a/src/opengl/qglextensions_p.h b/src/opengl/qglextensions_p.h
index a0517f5..d6edfb6 100644
--- a/src/opengl/qglextensions_p.h
+++ b/src/opengl/qglextensions_p.h
@@ -74,11 +74,15 @@
typedef ptrdiff_t GLsizeiptrARB;
#endif
+#ifndef GL_VERSION_2_0
+typedef char GLchar;
+#endif
+
// ARB_pixel_buffer_object
-typedef void (APIENTRY *_glBindBufferARB) (GLenum, GLuint);
-typedef void (APIENTRY *_glDeleteBuffersARB) (GLsizei, const GLuint *);
-typedef void (APIENTRY *_glGenBuffersARB) (GLsizei, GLuint *);
-typedef void (APIENTRY *_glBufferDataARB) (GLenum, GLsizeiptrARB, const GLvoid *, GLenum);
+typedef void (APIENTRY *_glBindBuffer) (GLenum, GLuint);
+typedef void (APIENTRY *_glDeleteBuffers) (GLsizei, const GLuint *);
+typedef void (APIENTRY *_glGenBuffers) (GLsizei, GLuint *);
+typedef void (APIENTRY *_glBufferData) (GLenum, GLsizeiptrARB, const GLvoid *, GLenum);
typedef GLvoid* (APIENTRY *_glMapBufferARB) (GLenum, GLenum);
typedef GLboolean (APIENTRY *_glUnmapBufferARB) (GLenum);
@@ -92,8 +96,10 @@ typedef void (APIENTRY *_glProgramLocalParameter4fvARB) (GLenum, GLuint, const G
// GLSL
typedef GLuint (APIENTRY *_glCreateShader) (GLenum);
typedef void (APIENTRY *_glShaderSource) (GLuint, GLsizei, const char **, const GLint *);
+typedef void (APIENTRY *_glShaderBinary) (GLint, const GLuint*, GLenum, const void*, GLint);
typedef void (APIENTRY *_glCompileShader) (GLuint);
typedef void (APIENTRY *_glDeleteShader) (GLuint);
+typedef GLboolean (APIENTRY *_glIsShader) (GLuint);
typedef GLuint (APIENTRY *_glCreateProgram) ();
typedef void (APIENTRY *_glAttachShader) (GLuint, GLuint);
@@ -101,62 +107,101 @@ typedef void (APIENTRY *_glDetachShader) (GLuint, GLuint);
typedef void (APIENTRY *_glLinkProgram) (GLuint);
typedef void (APIENTRY *_glUseProgram) (GLuint);
typedef void (APIENTRY *_glDeleteProgram) (GLuint);
+typedef GLboolean (APIENTRY *_glIsProgram) (GLuint);
typedef void (APIENTRY *_glGetShaderInfoLog) (GLuint, GLsizei, GLsizei *, char *);
typedef void (APIENTRY *_glGetShaderiv) (GLuint, GLenum, GLint *);
+typedef void (APIENTRY *_glGetShaderSource) (GLuint, GLsizei, GLsizei *, char *);
typedef void (APIENTRY *_glGetProgramiv) (GLuint, GLenum, GLint *);
+typedef void (APIENTRY *_glGetProgramInfoLog) (GLuint, GLsizei, GLsizei *, char *);
typedef GLuint (APIENTRY *_glGetUniformLocation) (GLuint, const char*);
-typedef void (APIENTRY *_glUniform4fv) (GLint, GLsizei, GLfloat *);
-typedef void (APIENTRY *_glUniform3fv) (GLint, GLsizei, GLfloat *);
-typedef void (APIENTRY *_glUniform2fv) (GLint, GLsizei, GLfloat *);
-typedef void (APIENTRY *_glUniform1fv) (GLint, GLsizei, GLfloat *);
+typedef void (APIENTRY *_glUniform4fv) (GLint, GLsizei, const GLfloat *);
+typedef void (APIENTRY *_glUniform3fv) (GLint, GLsizei, const GLfloat *);
+typedef void (APIENTRY *_glUniform2fv) (GLint, GLsizei, const GLfloat *);
+typedef void (APIENTRY *_glUniform1fv) (GLint, GLsizei, const GLfloat *);
typedef void (APIENTRY *_glUniform1i) (GLint, GLint);
+typedef void (APIENTRY *_glUniform1iv) (GLint, GLsizei, const GLint *);
+typedef void (APIENTRY *_glUniformMatrix2fv) (GLint, GLsizei, GLboolean, const GLfloat *);
+typedef void (APIENTRY *_glUniformMatrix3fv) (GLint, GLsizei, GLboolean, const GLfloat *);
+typedef void (APIENTRY *_glUniformMatrix4fv) (GLint, GLsizei, GLboolean, const GLfloat *);
+typedef void (APIENTRY *_glUniformMatrix2x3fv) (GLint, GLsizei, GLboolean, const GLfloat *);
+typedef void (APIENTRY *_glUniformMatrix2x4fv) (GLint, GLsizei, GLboolean, const GLfloat *);
+typedef void (APIENTRY *_glUniformMatrix3x2fv) (GLint, GLsizei, GLboolean, const GLfloat *);
+typedef void (APIENTRY *_glUniformMatrix3x4fv) (GLint, GLsizei, GLboolean, const GLfloat *);
+typedef void (APIENTRY *_glUniformMatrix4x2fv) (GLint, GLsizei, GLboolean, const GLfloat *);
+typedef void (APIENTRY *_glUniformMatrix4x3fv) (GLint, GLsizei, GLboolean, const GLfloat *);
+
+typedef void (APIENTRY *_glBindAttribLocation) (GLuint, GLuint, const char *);
+typedef GLint (APIENTRY *_glGetAttribLocation) (GLuint, const char *);
+typedef void (APIENTRY *_glVertexAttrib1fv) (GLuint, const GLfloat *);
+typedef void (APIENTRY *_glVertexAttrib2fv) (GLuint, const GLfloat *);
+typedef void (APIENTRY *_glVertexAttrib3fv) (GLuint, const GLfloat *);
+typedef void (APIENTRY *_glVertexAttrib4fv) (GLuint, const GLfloat *);
+typedef void (APIENTRY *_glVertexAttribPointer) (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid *);
+typedef void (APIENTRY *_glDisableVertexAttribArray) (GLuint);
+typedef void (APIENTRY *_glEnableVertexAttribArray) (GLuint);
+
+typedef void (APIENTRY *_glGetProgramBinaryOES) (GLuint, GLsizei, GLsizei *, GLenum *, void *);
+typedef void (APIENTRY *_glProgramBinaryOES) (GLuint, GLenum, const void *, GLint);
-typedef void (APIENTRY *_glActiveStencilFaceEXT) (GLenum );
typedef void (APIENTRY *_glMultiTexCoord4f) (GLenum, GLfloat, GLfloat, GLfloat, GLfloat);
+typedef void (APIENTRY *_glActiveStencilFaceEXT) (GLenum );
+
+// Needed for GL2 engine:
+typedef void (APIENTRY *_glStencilOpSeparate) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
typedef void (APIENTRY *_glActiveTexture) (GLenum);
+
// EXT_GL_framebuffer_object
-typedef GLboolean (APIENTRY *_glIsRenderbufferEXT) (GLuint renderbuffer);
-typedef void (APIENTRY *_glBindRenderbufferEXT) (GLenum target, GLuint renderbuffer);
-typedef void (APIENTRY *_glDeleteRenderbuffersEXT) (GLsizei n, const GLuint *renderbuffers);
-typedef void (APIENTRY *_glGenRenderbuffersEXT) (GLsizei n, GLuint *renderbuffers);
-typedef void (APIENTRY *_glRenderbufferStorageEXT) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
-typedef void (APIENTRY *_glGetRenderbufferParameterivEXT) (GLenum target, GLenum pname, GLint *params);
-typedef GLboolean (APIENTRY *_glIsFramebufferEXT) (GLuint framebuffer);
-typedef void (APIENTRY *_glBindFramebufferEXT) (GLenum target, GLuint framebuffer);
-typedef void (APIENTRY *_glDeleteFramebuffersEXT) (GLsizei n, const GLuint *framebuffers);
-typedef void (APIENTRY *_glGenFramebuffersEXT) (GLsizei n, GLuint *framebuffers);
-typedef GLenum (APIENTRY *_glCheckFramebufferStatusEXT) (GLenum target);
-typedef void (APIENTRY *_glFramebufferTexture1DEXT) (GLenum target, GLenum attachment, GLenum textarget,
- GLuint texture, GLint level);
-typedef void (APIENTRY *_glFramebufferTexture2DEXT) (GLenum target, GLenum attachment, GLenum textarget,
+typedef GLboolean (APIENTRY *_glIsRenderbuffer) (GLuint renderbuffer);
+typedef void (APIENTRY *_glBindRenderbuffer) (GLenum target, GLuint renderbuffer);
+typedef void (APIENTRY *_glDeleteRenderbuffers) (GLsizei n, const GLuint *renderbuffers);
+typedef void (APIENTRY *_glGenRenderbuffers) (GLsizei n, GLuint *renderbuffers);
+typedef void (APIENTRY *_glRenderbufferStorage) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRY *_glGetRenderbufferParameteriv) (GLenum target, GLenum pname, GLint *params);
+typedef GLboolean (APIENTRY *_glIsFramebuffer) (GLuint framebuffer);
+typedef void (APIENTRY *_glBindFramebuffer) (GLenum target, GLuint framebuffer);
+typedef void (APIENTRY *_glDeleteFramebuffers) (GLsizei n, const GLuint *framebuffers);
+typedef void (APIENTRY *_glGenFramebuffers) (GLsizei n, GLuint *framebuffers);
+typedef GLenum (APIENTRY *_glCheckFramebufferStatus) (GLenum target);
+typedef void (APIENTRY *_glFramebufferTexture2D) (GLenum target, GLenum attachment, GLenum textarget,
GLuint texture, GLint level);
-typedef void (APIENTRY *_glFramebufferTexture3DEXT) (GLenum target, GLenum attachment, GLenum textarget,
- GLuint texture, GLint level, GLint zoffset);
-typedef void (APIENTRY *_glFramebufferRenderbufferEXT) (GLenum target, GLenum attachment, GLenum renderbuffertarget,
+typedef void (APIENTRY *_glFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget,
GLuint renderbuffer);
-typedef void (APIENTRY *_glGetFramebufferAttachmentParameterivEXT) (GLenum target, GLenum attachment, GLenum pname,
+typedef void (APIENTRY *_glGetFramebufferAttachmentParameteriv) (GLenum target, GLenum attachment, GLenum pname,
GLint *params);
-typedef void (APIENTRY *_glGenerateMipmapEXT) (GLenum target);
+typedef void (APIENTRY *_glGenerateMipmap) (GLenum target);
+
+// EXT_GL_framebuffer_blit
+typedef void (APIENTRY *_glBlitFramebufferEXT) (int srcX0, int srcY0, int srcX1, int srcY1,
+ int dstX0, int dstY0, int dstX1, int dstY1,
+ GLbitfield mask, GLenum filter);
+
+// EXT_GL_framebuffer_multisample
+typedef void (APIENTRY *_glRenderbufferStorageMultisampleEXT) (GLenum target, GLsizei samples,
+ GLenum internalformat, GLsizei width, GLsizei height);
QT_BEGIN_NAMESPACE
struct QGLExtensionFuncs
{
QGLExtensionFuncs() {
+#if !defined(QT_OPENGL_ES_2)
qt_glProgramStringARB = 0;
qt_glBindProgramARB = 0;
qt_glDeleteProgramsARB = 0;
qt_glGenProgramsARB = 0;
qt_glProgramLocalParameter4fvARB = 0;
+ // GLSL
qt_glCreateShader = 0;
qt_glShaderSource = 0;
+ qt_glShaderBinary = 0;
qt_glCompileShader = 0;
qt_glDeleteShader = 0;
+ qt_glIsShader = 0;
qt_glCreateProgram = 0;
qt_glAttachShader = 0;
@@ -164,10 +209,13 @@ struct QGLExtensionFuncs
qt_glLinkProgram = 0;
qt_glUseProgram = 0;
qt_glDeleteProgram = 0;
+ qt_glIsProgram = 0;
qt_glGetShaderInfoLog = 0;
qt_glGetShaderiv = 0;
+ qt_glGetShaderSource = 0;
qt_glGetProgramiv = 0;
+ qt_glGetProgramInfoLog = 0;
qt_glGetUniformLocation = 0;
qt_glUniform4fv = 0;
@@ -175,40 +223,74 @@ struct QGLExtensionFuncs
qt_glUniform2fv = 0;
qt_glUniform1fv = 0;
qt_glUniform1i = 0;
+ qt_glUniform1iv = 0;
+ qt_glUniformMatrix2fv = 0;
+ qt_glUniformMatrix3fv = 0;
+ qt_glUniformMatrix4fv = 0;
+ qt_glUniformMatrix2x3fv = 0;
+ qt_glUniformMatrix2x4fv = 0;
+ qt_glUniformMatrix3x2fv = 0;
+ qt_glUniformMatrix3x4fv = 0;
+ qt_glUniformMatrix4x2fv = 0;
+ qt_glUniformMatrix4x3fv = 0;
+
+ qt_glBindAttribLocation = 0;
+ qt_glGetAttribLocation = 0;
+ qt_glVertexAttrib1fv = 0;
+ qt_glVertexAttrib2fv = 0;
+ qt_glVertexAttrib3fv = 0;
+ qt_glVertexAttrib4fv = 0;
+ qt_glVertexAttribPointer = 0;
+ qt_glDisableVertexAttribArray = 0;
+ qt_glEnableVertexAttribArray = 0;
+
+ // Extras for GL2 engine:
+ qt_glActiveTexture = 0;
+ qt_glStencilOpSeparate = 0;
qt_glActiveStencilFaceEXT = 0;
-
qt_glMultiTexCoord4f = 0;
- qt_glActiveTexture = 0;
+#else
+ qt_glslResolved = false;
+
+ qt_glGetProgramBinaryOES = 0;
+ qt_glProgramBinaryOES = 0;
+#endif
+ // FBOs
#if !defined(QT_OPENGL_ES_2)
- qt_glIsRenderbufferEXT = 0;
- qt_glBindRenderbufferEXT = 0;
- qt_glDeleteRenderbuffersEXT = 0;
- qt_glGenRenderbuffersEXT = 0;
- qt_glRenderbufferStorageEXT = 0;
- qt_glGetRenderbufferParameterivEXT = 0;
- qt_glIsFramebufferEXT = 0;
- qt_glBindFramebufferEXT = 0;
- qt_glDeleteFramebuffersEXT = 0;
- qt_glGenFramebuffersEXT = 0;
- qt_glCheckFramebufferStatusEXT = 0;
- qt_glFramebufferTexture1DEXT = 0;
- qt_glFramebufferTexture2DEXT = 0;
- qt_glFramebufferTexture3DEXT = 0;
- qt_glFramebufferRenderbufferEXT = 0;
- qt_glGetFramebufferAttachmentParameterivEXT = 0;
- qt_glGenerateMipmapEXT = 0;
-#endif
-
- qt_glBindBufferARB = 0;
- qt_glDeleteBuffersARB = 0;
- qt_glGenBuffersARB = 0;
- qt_glBufferDataARB = 0;
+ qt_glIsRenderbuffer = 0;
+ qt_glBindRenderbuffer = 0;
+ qt_glDeleteRenderbuffers = 0;
+ qt_glGenRenderbuffers = 0;
+ qt_glRenderbufferStorage = 0;
+ qt_glGetRenderbufferParameteriv = 0;
+ qt_glIsFramebuffer = 0;
+ qt_glBindFramebuffer = 0;
+ qt_glDeleteFramebuffers = 0;
+ qt_glGenFramebuffers = 0;
+ qt_glCheckFramebufferStatus = 0;
+ qt_glFramebufferTexture2D = 0;
+ qt_glFramebufferRenderbuffer = 0;
+ qt_glGetFramebufferAttachmentParameteriv = 0;
+ qt_glGenerateMipmap = 0;
+#endif
+ qt_glBlitFramebufferEXT = 0;
+ qt_glRenderbufferStorageMultisampleEXT = 0;
+
+ // Buffer objects:
+#if !defined(QT_OPENGL_ES_2)
+ qt_glBindBuffer = 0;
+ qt_glDeleteBuffers = 0;
+ qt_glGenBuffers = 0;
+ qt_glBufferData = 0;
+#endif
qt_glMapBufferARB = 0;
qt_glUnmapBufferARB = 0;
}
+
+#if !defined(QT_OPENGL_ES_2)
_glProgramStringARB qt_glProgramStringARB;
_glBindProgramARB qt_glBindProgramARB;
_glDeleteProgramsARB qt_glDeleteProgramsARB;
@@ -218,8 +300,10 @@ struct QGLExtensionFuncs
// GLSL definitions
_glCreateShader qt_glCreateShader;
_glShaderSource qt_glShaderSource;
+ _glShaderBinary qt_glShaderBinary;
_glCompileShader qt_glCompileShader;
_glDeleteShader qt_glDeleteShader;
+ _glIsShader qt_glIsShader;
_glCreateProgram qt_glCreateProgram;
_glAttachShader qt_glAttachShader;
@@ -227,10 +311,13 @@ struct QGLExtensionFuncs
_glLinkProgram qt_glLinkProgram;
_glUseProgram qt_glUseProgram;
_glDeleteProgram qt_glDeleteProgram;
+ _glIsProgram qt_glIsProgram;
_glGetShaderInfoLog qt_glGetShaderInfoLog;
_glGetShaderiv qt_glGetShaderiv;
+ _glGetShaderSource qt_glGetShaderSource;
_glGetProgramiv qt_glGetProgramiv;
+ _glGetProgramInfoLog qt_glGetProgramInfoLog;
_glGetUniformLocation qt_glGetUniformLocation;
_glUniform4fv qt_glUniform4fv;
@@ -238,38 +325,74 @@ struct QGLExtensionFuncs
_glUniform2fv qt_glUniform2fv;
_glUniform1fv qt_glUniform1fv;
_glUniform1i qt_glUniform1i;
+ _glUniform1iv qt_glUniform1iv;
+ _glUniformMatrix2fv qt_glUniformMatrix2fv;
+ _glUniformMatrix3fv qt_glUniformMatrix3fv;
+ _glUniformMatrix4fv qt_glUniformMatrix4fv;
+ _glUniformMatrix2x3fv qt_glUniformMatrix2x3fv;
+ _glUniformMatrix2x4fv qt_glUniformMatrix2x4fv;
+ _glUniformMatrix3x2fv qt_glUniformMatrix3x2fv;
+ _glUniformMatrix3x4fv qt_glUniformMatrix3x4fv;
+ _glUniformMatrix4x2fv qt_glUniformMatrix4x2fv;
+ _glUniformMatrix4x3fv qt_glUniformMatrix4x3fv;
+
+ _glBindAttribLocation qt_glBindAttribLocation;
+ _glGetAttribLocation qt_glGetAttribLocation;
+ _glVertexAttrib1fv qt_glVertexAttrib1fv;
+ _glVertexAttrib2fv qt_glVertexAttrib2fv;
+ _glVertexAttrib3fv qt_glVertexAttrib3fv;
+ _glVertexAttrib4fv qt_glVertexAttrib4fv;
+ _glVertexAttribPointer qt_glVertexAttribPointer;
+ _glDisableVertexAttribArray qt_glDisableVertexAttribArray;
+ _glEnableVertexAttribArray qt_glEnableVertexAttribArray;
- _glActiveStencilFaceEXT qt_glActiveStencilFaceEXT;
+#else
+ bool qt_glslResolved;
+
+ _glGetProgramBinaryOES qt_glGetProgramBinaryOES;
+ _glProgramBinaryOES qt_glProgramBinaryOES;
+#endif
+ _glActiveStencilFaceEXT qt_glActiveStencilFaceEXT;
_glMultiTexCoord4f qt_glMultiTexCoord4f;
+
+#if !defined(QT_OPENGL_ES_2)
+ // Extras needed for GL2 engine:
_glActiveTexture qt_glActiveTexture;
+ _glStencilOpSeparate qt_glStencilOpSeparate;
+#endif
+ // FBOs
#if !defined(QT_OPENGL_ES_2)
- _glIsRenderbufferEXT qt_glIsRenderbufferEXT;
- _glBindRenderbufferEXT qt_glBindRenderbufferEXT;
- _glDeleteRenderbuffersEXT qt_glDeleteRenderbuffersEXT;
- _glGenRenderbuffersEXT qt_glGenRenderbuffersEXT;
- _glRenderbufferStorageEXT qt_glRenderbufferStorageEXT;
- _glGetRenderbufferParameterivEXT qt_glGetRenderbufferParameterivEXT;
- _glIsFramebufferEXT qt_glIsFramebufferEXT;
- _glBindFramebufferEXT qt_glBindFramebufferEXT;
- _glDeleteFramebuffersEXT qt_glDeleteFramebuffersEXT;
- _glGenFramebuffersEXT qt_glGenFramebuffersEXT;
- _glCheckFramebufferStatusEXT qt_glCheckFramebufferStatusEXT;
- _glFramebufferTexture1DEXT qt_glFramebufferTexture1DEXT;
- _glFramebufferTexture2DEXT qt_glFramebufferTexture2DEXT;
- _glFramebufferTexture3DEXT qt_glFramebufferTexture3DEXT;
- _glFramebufferRenderbufferEXT qt_glFramebufferRenderbufferEXT;
- _glGetFramebufferAttachmentParameterivEXT qt_glGetFramebufferAttachmentParameterivEXT;
- _glGenerateMipmapEXT qt_glGenerateMipmapEXT;
-#endif
-
- _glBindBufferARB qt_glBindBufferARB;
- _glDeleteBuffersARB qt_glDeleteBuffersARB;
- _glGenBuffersARB qt_glGenBuffersARB;
- _glBufferDataARB qt_glBufferDataARB;
+ _glIsRenderbuffer qt_glIsRenderbuffer;
+ _glBindRenderbuffer qt_glBindRenderbuffer;
+ _glDeleteRenderbuffers qt_glDeleteRenderbuffers;
+ _glGenRenderbuffers qt_glGenRenderbuffers;
+ _glRenderbufferStorage qt_glRenderbufferStorage;
+ _glGetRenderbufferParameteriv qt_glGetRenderbufferParameteriv;
+ _glIsFramebuffer qt_glIsFramebuffer;
+ _glBindFramebuffer qt_glBindFramebuffer;
+ _glDeleteFramebuffers qt_glDeleteFramebuffers;
+ _glGenFramebuffers qt_glGenFramebuffers;
+ _glCheckFramebufferStatus qt_glCheckFramebufferStatus;
+ _glFramebufferTexture2D qt_glFramebufferTexture2D;
+ _glFramebufferRenderbuffer qt_glFramebufferRenderbuffer;
+ _glGetFramebufferAttachmentParameteriv qt_glGetFramebufferAttachmentParameteriv;
+ _glGenerateMipmap qt_glGenerateMipmap;
+#endif
+ _glBlitFramebufferEXT qt_glBlitFramebufferEXT;
+ _glRenderbufferStorageMultisampleEXT qt_glRenderbufferStorageMultisampleEXT;
+
+ // Buffer objects
+#if !defined(QT_OPENGL_ES_2)
+ _glBindBuffer qt_glBindBuffer;
+ _glDeleteBuffers qt_glDeleteBuffers;
+ _glGenBuffers qt_glGenBuffers;
+ _glBufferData qt_glBufferData;
+#endif
_glMapBufferARB qt_glMapBufferARB;
_glUnmapBufferARB qt_glUnmapBufferARB;
+
};
@@ -397,6 +520,28 @@ struct QGLExtensionFuncs
#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55
#endif
+// GL_EXT_framebuffer_blit
+#ifndef GL_READ_FRAMEBUFFER_EXT
+#define GL_READ_FRAMEBUFFER_EXT 0x8CA8
+#endif
+
+// GL_EXT_framebuffer_multisample
+#ifndef GL_RENDERBUFFER_SAMPLES_EXT
+#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB
+#endif
+
+#ifndef GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56
+#endif
+
+#ifndef GL_MAX_SAMPLES_EXT
+#define GL_MAX_SAMPLES_EXT 0x8D5
+#endif
+
+#ifndef GL_DRAW_FRAMEBUFFER_EXT
+#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9
+#endif
+
#ifndef GL_EXT_packed_depth_stencil
#define GL_DEPTH_STENCIL_EXT 0x84F9
#define GL_UNSIGNED_INT_24_8_EXT 0x84FA
@@ -416,6 +561,42 @@ struct QGLExtensionFuncs
#define GL_UNPACK_IMAGE_HEIGHT 0x806E
#endif
+#ifndef GL_VERSION_1_4
+#define GL_INCR_WRAP 0x8507
+#define GL_DECR_WRAP 0x8508
+#endif
+
+#ifndef GL_VERSION_2_0
+#define GL_FRAGMENT_SHADER 0x8B30
+#define GL_VERTEX_SHADER 0x8B31
+#define GL_FLOAT_VEC2 0x8B50
+#define GL_FLOAT_VEC3 0x8B51
+#define GL_FLOAT_VEC4 0x8B52
+#define GL_INT_VEC2 0x8B53
+#define GL_INT_VEC3 0x8B54
+#define GL_INT_VEC4 0x8B55
+#define GL_BOOL 0x8B56
+#define GL_BOOL_VEC2 0x8B57
+#define GL_BOOL_VEC3 0x8B58
+#define GL_BOOL_VEC4 0x8B59
+#define GL_FLOAT_MAT2 0x8B5A
+#define GL_FLOAT_MAT3 0x8B5B
+#define GL_FLOAT_MAT4 0x8B5C
+#define GL_SAMPLER_1D 0x8B5D
+#define GL_SAMPLER_2D 0x8B5E
+#define GL_SAMPLER_3D 0x8B5F
+#define GL_SAMPLER_CUBE 0x8B60
+#define GL_COMPILE_STATUS 0x8B81
+#define GL_LINK_STATUS 0x8B82
+#define GL_INFO_LOG_LENGTH 0x8B84
+#define GL_ACTIVE_UNIFORMS 0x8B86
+#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#define GL_ACTIVE_ATTRIBUTES 0x8B89
+#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#endif
+
+
+#if !defined(QT_OPENGL_ES_2)
#define glProgramStringARB QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glProgramStringARB
#define glBindProgramARB QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glBindProgramARB
#define glDeleteProgramsARB QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glDeleteProgramsARB
@@ -426,63 +607,52 @@ struct QGLExtensionFuncs
#define glMultiTexCoord4f QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glMultiTexCoord4f
-#if !defined(QT_OPENGL_ES_2)
#define glActiveTexture QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glActiveTexture
-#endif
-
-#if !defined(QT_OPENGL_ES_2)
-
-#define glIsRenderbufferEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glIsRenderbufferEXT
-#define glBindRenderbufferEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glBindRenderbufferEXT
-#define glDeleteRenderbuffersEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glDeleteRenderbuffersEXT
-#define glGenRenderbuffersEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGenRenderbuffersEXT
-#define glRenderbufferStorageEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glRenderbufferStorageEXT
-#define glGetRenderbufferParameterivEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetRenderbufferParameterivEXT
-#define glIsFramebufferEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glIsFramebufferEXT
-#define glBindFramebufferEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glBindFramebufferEXT
-#define glDeleteFramebuffersEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glDeleteFramebuffersEXT
-#define glGenFramebuffersEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGenFramebuffersEXT
-#define glCheckFramebufferStatusEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glCheckFramebufferStatusEXT
-#define glFramebufferTexture1DEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glFramebufferTexture1DEXT
-#define glFramebufferTexture2DEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glFramebufferTexture2DEXT
-#define glFramebufferTexture3DEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glFramebufferTexture3DEXT
-#define glFramebufferRenderbufferEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glFramebufferRenderbufferEXT
-#define glGetFramebufferAttachmentParameterivEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetFramebufferAttachmentParameterivEXT
-#define glGenerateMipmapEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGenerateMipmapEXT
-
-#else // QT_OPENGL_ES_2
+#endif // !defined(QT_OPENGL_ES_2)
-#define glIsRenderbufferEXT glIsRenderbuffer
-#define glBindRenderbufferEXT glBindRenderbuffer
-#define glDeleteRenderbuffersEXT glDeleteRenderbuffers
-#define glGenRenderbuffersEXT glGenRenderbuffers
-#define glRenderbufferStorageEXT glRenderbufferStorage
-#define glGetRenderbufferParameterivEXT glGetRenderbufferParameteriv
-#define glIsFramebufferEXT glIsFramebuffer
-#define glBindFramebufferEXT glBindFramebuffer
-#define glDeleteFramebuffersEXT glDeleteFramebuffers
-#define glGenFramebuffersEXT glGenFramebuffers
-#define glCheckFramebufferStatusEXT glCheckFramebufferStatus
-#define glFramebufferTexture1DEXT glFramebufferTexture1D
-#define glFramebufferTexture2DEXT glFramebufferTexture2D
-#define glFramebufferTexture3DEXT glFramebufferTexture3D
-#define glFramebufferRenderbufferEXT glFramebufferRenderbuffer
-#define glGetFramebufferAttachmentParameterivEXT glGetFramebufferAttachmentParameteriv
-#define glGenerateMipmapEXT glGenerateMipmap
+// FBOs
+#if !defined(QT_OPENGL_ES_2)
+#define glIsRenderbuffer QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glIsRenderbuffer
+#define glBindRenderbuffer QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glBindRenderbuffer
+#define glDeleteRenderbuffers QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glDeleteRenderbuffers
+#define glGenRenderbuffers QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGenRenderbuffers
+#define glRenderbufferStorage QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glRenderbufferStorage
+#define glGetRenderbufferParameteriv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetRenderbufferParameteriv
+#define glIsFramebuffer QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glIsFramebuffer
+#define glBindFramebuffer QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glBindFramebuffer
+#define glDeleteFramebuffers QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glDeleteFramebuffers
+#define glGenFramebuffers QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGenFramebuffers
+#define glCheckFramebufferStatus QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glCheckFramebufferStatus
+#define glFramebufferTexture2D QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glFramebufferTexture2D
+#define glFramebufferRenderbuffer QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glFramebufferRenderbuffer
+#define glGetFramebufferAttachmentParameteriv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetFramebufferAttachmentParameteriv
+#define glGenerateMipmap QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGenerateMipmap
#endif // QT_OPENGL_ES_2
+#define glBlitFramebufferEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glBlitFramebufferEXT
+#define glRenderbufferStorageMultisampleEXT QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glRenderbufferStorageMultisampleEXT
+
-#define glBindBufferARB QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glBindBufferARB
-#define glDeleteBuffersARB QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glDeleteBuffersARB
-#define glGenBuffersARB QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGenBuffersARB
-#define glBufferDataARB QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glBufferDataARB
+// Buffer objects
+#if !defined(QT_OPENGL_ES_2)
+#define glBindBuffer QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glBindBuffer
+#define glDeleteBuffers QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glDeleteBuffers
+#define glGenBuffers QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGenBuffers
+#define glBufferData QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glBufferData
+#endif
#define glMapBufferARB QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glMapBufferARB
#define glUnmapBufferARB QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUnmapBufferARB
+
+// GLSL
+#if !defined(QT_OPENGL_ES_2)
+
#define glCreateShader QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glCreateShader
#define glShaderSource QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glShaderSource
+#define glShaderBinary QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glShaderBinary
#define glCompileShader QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glCompileShader
#define glDeleteShader QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glDeleteShader
+#define glIsShader QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glIsShader
#define glCreateProgram QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glCreateProgram
#define glAttachShader QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glAttachShader
@@ -490,10 +660,13 @@ struct QGLExtensionFuncs
#define glLinkProgram QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glLinkProgram
#define glUseProgram QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUseProgram
#define glDeleteProgram QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glDeleteProgram
+#define glIsProgram QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glIsProgram
#define glGetShaderInfoLog QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetShaderInfoLog
#define glGetShaderiv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetShaderiv
+#define glGetShaderSource QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetShaderSource
#define glGetProgramiv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetProgramiv
+#define glGetProgramInfoLog QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetProgramInfoLog
#define glGetUniformLocation QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetUniformLocation
#define glUniform4fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniform4fv
@@ -501,11 +674,48 @@ struct QGLExtensionFuncs
#define glUniform2fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniform2fv
#define glUniform1fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniform1fv
#define glUniform1i QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniform1i
+#define glUniform1iv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniform1iv
+#define glUniformMatrix2fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniformMatrix2fv
+#define glUniformMatrix3fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniformMatrix3fv
+#define glUniformMatrix4fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniformMatrix4fv
+#define glUniformMatrix2x3fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniformMatrix2x3fv
+#define glUniformMatrix2x4fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniformMatrix2x4fv
+#define glUniformMatrix3x2fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniformMatrix3x2fv
+#define glUniformMatrix3x4fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniformMatrix3x4fv
+#define glUniformMatrix4x2fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniformMatrix4x2fv
+#define glUniformMatrix4x3fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glUniformMatrix4x3fv
+
+#define glBindAttribLocation QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glBindAttribLocation
+#define glGetAttribLocation QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetAttribLocation
+#define glVertexAttrib1fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glVertexAttrib1fv
+#define glVertexAttrib2fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glVertexAttrib2fv
+#define glVertexAttrib3fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glVertexAttrib3fv
+#define glVertexAttrib4fv QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glVertexAttrib4fv
+#define glVertexAttribPointer QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glVertexAttribPointer
+#define glDisableVertexAttribArray QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glDisableVertexAttribArray
+#define glEnableVertexAttribArray QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glEnableVertexAttribArray
+
+#else // QT_OPENGL_ES_2
+
+#define glGetProgramBinaryOES QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glGetProgramBinaryOES
+#define glProgramBinaryOES QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glProgramBinaryOES
+
+#endif // QT_OPENGL_ES_2
+
+
+#if !defined(QT_OPENGL_ES_2)
+#define glStencilOpSeparate QGLContextPrivate::qt_get_extension_funcs(ctx).qt_glStencilOpSeparate
+#endif
+
+#if defined(QT_OPENGL_ES_2)
+#define glClearDepth glClearDepthf
+#endif
extern bool qt_resolve_framebufferobject_extensions(QGLContext *ctx);
bool qt_resolve_buffer_extensions(QGLContext *ctx);
bool qt_resolve_version_1_3_functions(QGLContext *ctx);
+bool qt_resolve_version_2_0_functions(QGLContext *ctx);
bool qt_resolve_stencil_face_extension(QGLContext *ctx);
bool qt_resolve_frag_program_extensions(QGLContext *ctx);
diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp
index 4ba9213..2b7ad4f 100644
--- a/src/opengl/qglframebufferobject.cpp
+++ b/src/opengl/qglframebufferobject.cpp
@@ -43,7 +43,12 @@
#include <qdebug.h>
#include <private/qgl_p.h>
+#include <private/qpaintengineex_opengl2_p.h>
+
+#ifndef QT_OPENGL_ES_2
#include <private/qpaintengine_opengl_p.h>
+#endif
+
#include <qglframebufferobject.h>
#include <qlibrary.h>
#include <qimage.h>
@@ -67,6 +72,215 @@ extern QImage qt_gl_read_framebuffer(const QSize&, bool, bool);
} \
}
+class QGLFramebufferObjectFormatPrivate
+{
+public:
+ int samples;
+ QGLFramebufferObject::Attachment attachment;
+ GLenum target;
+ GLenum internal_format;
+};
+
+/*!
+ \class QGLFramebufferObjectFormat
+ \brief The QGLFramebufferObjectFormat class specifies the format of an OpenGL
+ framebuffer object.
+
+ \since 4.6
+
+ \ingroup multimedia
+
+ A framebuffer object has several characteristics:
+ \list
+ \i \link setSamples() Number of samples per pixels.\endlink
+ \i \link setAttachment() Depth and/or stencil attachments.\endlink
+ \i \link setTextureTarget() Texture target.\endlink
+ \i \link setInternalFormat() Internal format.\endlink
+ \endlist
+
+ Note that the desired attachments or number of samples per pixels might not
+ be supported by the hardware driver. Call QGLFramebufferObject::format()
+ after creating a QGLFramebufferObject to find the exact format that was
+ used to create the frame buffer object.
+
+ \sa QGLFramebufferObject
+*/
+
+/*!
+ \since 4.6
+
+ Creates a QGLFramebufferObjectFormat object with properties specifying
+ the format of an OpenGL framebuffer object.
+
+ A multisample framebuffer object is specified by setting \a samples
+ to a value different from zero. If the desired amount of samples per pixel is
+ not supported by the hardware then the maximum number of samples per pixel
+ will be used. Note that multisample framebuffer objects can not be bound as
+ textures. Also, the \c{GL_EXT_framebuffer_multisample} extension is required
+ to create a framebuffer with more than one sample per pixel.
+
+ For multisample framebuffer objects a color render buffer is created,
+ otherwise a texture with the texture target \a target is created.
+ The color render buffer or texture will have the internal format
+ \a internalFormat, and will be bound to the \c GL_COLOR_ATTACHMENT0
+ attachment in the framebuffer object.
+
+ The \a attachment parameter describes the depth/stencil buffer
+ configuration.
+
+ \sa samples(), attachment(), target(), internalFormat()
+*/
+
+QGLFramebufferObjectFormat::QGLFramebufferObjectFormat(int samples,
+ QGLFramebufferObject::Attachment attachment,
+ GLenum target,
+ GLenum internalFormat)
+{
+ d = new QGLFramebufferObjectFormatPrivate;
+ d->samples = samples;
+ d->attachment = attachment;
+ d->target = target;
+ d->internal_format = internalFormat;
+}
+
+/*!
+ \since 4.6
+
+ Constructs a copy of \a other.
+*/
+
+QGLFramebufferObjectFormat::QGLFramebufferObjectFormat(const QGLFramebufferObjectFormat &other)
+{
+ d = new QGLFramebufferObjectFormatPrivate;
+ *d = *other.d;
+}
+
+/*!
+ \since 4.6
+
+ Assigns \a other to this object.
+*/
+
+QGLFramebufferObjectFormat &QGLFramebufferObjectFormat::operator=(const QGLFramebufferObjectFormat &other)
+{
+ *d = *other.d;
+ return *this;
+}
+
+/*!
+ \since 4.6
+
+ Destroys the QGLFramebufferObjectFormat.
+*/
+QGLFramebufferObjectFormat::~QGLFramebufferObjectFormat()
+{
+ delete d;
+}
+
+/*!
+ \since 4.6
+
+ Sets the number of samples per pixel for a multisample framebuffer object
+ to \a samples.
+ A sample count of 0 represents a regular non-multisample framebuffer object.
+
+ \sa samples()
+*/
+void QGLFramebufferObjectFormat::setSamples(int samples)
+{
+ d->samples = samples;
+}
+
+/*!
+ \since 4.6
+
+ Returns the number of samples per pixel if a framebuffer object
+ is a multisample framebuffer object. Otherwise, returns 0.
+
+ \sa setSamples()
+*/
+int QGLFramebufferObjectFormat::samples() const
+{
+ return d->samples;
+}
+
+/*!
+ \since 4.6
+
+ Sets the attachments a framebuffer object should have to \a attachment.
+
+ \sa attachment()
+*/
+void QGLFramebufferObjectFormat::setAttachment(QGLFramebufferObject::Attachment attachment)
+{
+ d->attachment = attachment;
+}
+
+/*!
+ \since 4.6
+
+ Returns the status of the depth and stencil buffers attached to
+ a framebuffer object.
+
+ \sa setAttachment()
+*/
+QGLFramebufferObject::Attachment QGLFramebufferObjectFormat::attachment() const
+{
+ return d->attachment;
+}
+
+/*!
+ \since 4.6
+
+ Sets the texture target of the texture attached to a framebuffer object to
+ \a target. Ignored for multisample framebuffer objects.
+
+ \sa textureTarget(), samples()
+*/
+void QGLFramebufferObjectFormat::setTextureTarget(GLenum target)
+{
+ d->target = target;
+}
+
+/*!
+ \since 4.6
+
+ Returns the texture target of the texture attached to a framebuffer object.
+ Ignored for multisample framebuffer objects.
+
+ \sa setTextureTarget(), samples()
+*/
+GLenum QGLFramebufferObjectFormat::textureTarget() const
+{
+ return d->target;
+}
+
+/*!
+ \since 4.6
+
+ Sets the internal format of a framebuffer object's texture or multisample
+ framebuffer object's color buffer to \a internalFormat.
+
+ \sa internalFormat()
+*/
+void QGLFramebufferObjectFormat::setInternalFormat(GLenum internalFormat)
+{
+ d->internal_format = internalFormat;
+}
+
+/*!
+ \since 4.6
+
+ Returns the internal format of a framebuffer object's texture or
+ multisample framebuffer object's color buffer.
+
+ \sa setInternalFormat()
+*/
+GLenum QGLFramebufferObjectFormat::internalFormat() const
+{
+ return d->internal_format;
+}
+
class QGLFramebufferObjectPrivate
{
public:
@@ -74,13 +288,16 @@ public:
~QGLFramebufferObjectPrivate() {}
void init(const QSize& sz, QGLFramebufferObject::Attachment attachment,
- GLenum internal_format, GLenum texture_target);
+ GLenum internal_format, GLenum texture_target, GLint samples = 0);
bool checkFramebufferStatus() const;
GLuint texture;
GLuint fbo;
GLuint depth_stencil_buffer;
+ GLuint color_buffer;
GLenum target;
QSize size;
+ QGLFramebufferObjectFormat format;
+ int samples;
uint valid : 1;
uint bound : 1;
QGLFramebufferObject::Attachment fbo_attachment;
@@ -90,7 +307,7 @@ public:
bool QGLFramebufferObjectPrivate::checkFramebufferStatus() const
{
- GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
switch(status) {
case GL_NO_ERROR:
case GL_FRAMEBUFFER_COMPLETE_EXT:
@@ -122,6 +339,9 @@ bool QGLFramebufferObjectPrivate::checkFramebufferStatus() const
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
qDebug("QGLFramebufferObject: Framebuffer incomplete, missing read buffer.");
break;
+ case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT:
+ qDebug("QGLFramebufferObject: Framebuffer incomplete, attachments must have same number of samples per pixel.");
+ break;
default:
qDebug() <<"QGLFramebufferObject: An undefined error has occurred: "<< status;
break;
@@ -130,7 +350,7 @@ bool QGLFramebufferObjectPrivate::checkFramebufferStatus() const
}
void QGLFramebufferObjectPrivate::init(const QSize &sz, QGLFramebufferObject::Attachment attachment,
- GLenum texture_target, GLenum internal_format)
+ GLenum texture_target, GLenum internal_format, GLint samples)
{
ctx = const_cast<QGLContext *>(QGLContext::currentContext());
bool ext_detected = (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject);
@@ -142,81 +362,137 @@ void QGLFramebufferObjectPrivate::init(const QSize &sz, QGLFramebufferObject::At
// texture dimensions
while (glGetError() != GL_NO_ERROR) {} // reset error state
- glGenFramebuffersEXT(1, &fbo);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
+ glGenFramebuffers(1, &fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo);
QT_CHECK_GLERROR();
// init texture
- glGenTextures(1, &texture);
- glBindTexture(target, texture);
- glTexImage2D(target, 0, internal_format, size.width(), size.height(), 0,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ if (samples == 0) {
+ glGenTextures(1, &texture);
+ glBindTexture(target, texture);
+ glTexImage2D(target, 0, internal_format, size.width(), size.height(), 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, NULL);
#ifndef QT_OPENGL_ES
- glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#else
- glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#endif
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- target, texture, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ target, texture, 0);
- QT_CHECK_GLERROR();
- valid = checkFramebufferStatus();
+ QT_CHECK_GLERROR();
+ valid = checkFramebufferStatus();
+
+ color_buffer = 0;
+ samples = 0;
+ } else {
+ GLint maxSamples;
+ glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSamples);
+
+ samples = qBound(1, samples, int(maxSamples));
+
+ glGenRenderbuffers(1, &color_buffer);
+ glBindRenderbuffer(GL_RENDERBUFFER_EXT, color_buffer);
+ if (glRenderbufferStorageMultisampleEXT) {
+ glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples,
+ internal_format, size.width(), size.height());
+ } else {
+ samples = 0;
+ glRenderbufferStorage(GL_RENDERBUFFER_EXT, internal_format,
+ size.width(), size.height());
+ }
+
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_RENDERBUFFER_EXT, color_buffer);
+
+ QT_CHECK_GLERROR();
+ valid = checkFramebufferStatus();
+
+ if (valid)
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_SAMPLES_EXT, &samples);
+ }
if (attachment == QGLFramebufferObject::CombinedDepthStencil
&& (QGLExtensions::glExtensions & QGLExtensions::PackedDepthStencil)) {
// depth and stencil buffer needs another extension
- glGenRenderbuffersEXT(1, &depth_stencil_buffer);
- Q_ASSERT(!glIsRenderbufferEXT(depth_stencil_buffer));
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_stencil_buffer);
- Q_ASSERT(glIsRenderbufferEXT(depth_stencil_buffer));
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, size.width(), size.height());
+ glGenRenderbuffers(1, &depth_stencil_buffer);
+ Q_ASSERT(!glIsRenderbuffer(depth_stencil_buffer));
+ glBindRenderbuffer(GL_RENDERBUFFER_EXT, depth_stencil_buffer);
+ Q_ASSERT(glIsRenderbuffer(depth_stencil_buffer));
+ if (samples != 0 && glRenderbufferStorageMultisampleEXT)
+ glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples,
+ GL_DEPTH24_STENCIL8_EXT, size.width(), size.height());
+ else
+ glRenderbufferStorage(GL_RENDERBUFFER_EXT,
+ GL_DEPTH24_STENCIL8_EXT, size.width(), size.height());
+
GLint i = 0;
- glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_DEPTH_SIZE_EXT, &i);
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_DEPTH_SIZE_EXT, &i);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, depth_stencil_buffer);
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, depth_stencil_buffer);
fbo_attachment = QGLFramebufferObject::CombinedDepthStencil;
+
valid = checkFramebufferStatus();
if (!valid)
- glDeleteRenderbuffersEXT(1, &depth_stencil_buffer);
+ glDeleteRenderbuffers(1, &depth_stencil_buffer);
} else if (attachment == QGLFramebufferObject::Depth
|| attachment == QGLFramebufferObject::CombinedDepthStencil)
{
- glGenRenderbuffersEXT(1, &depth_stencil_buffer);
- Q_ASSERT(!glIsRenderbufferEXT(depth_stencil_buffer));
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_stencil_buffer);
- Q_ASSERT(glIsRenderbufferEXT(depth_stencil_buffer));
+ glGenRenderbuffers(1, &depth_stencil_buffer);
+ Q_ASSERT(!glIsRenderbuffer(depth_stencil_buffer));
+ glBindRenderbuffer(GL_RENDERBUFFER_EXT, depth_stencil_buffer);
+ Q_ASSERT(glIsRenderbuffer(depth_stencil_buffer));
+ if (samples != 0 && glRenderbufferStorageMultisampleEXT) {
#ifdef QT_OPENGL_ES
#define GL_DEPTH_COMPONENT16 0x81A5
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT16, size.width(), size.height());
+ glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples,
+ GL_DEPTH_COMPONENT16, size.width(), size.height());
#else
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, size.width(), size.height());
+ glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples,
+ GL_DEPTH_COMPONENT, size.width(), size.height());
#endif
+ } else {
+#ifdef QT_OPENGL_ES
+#define GL_DEPTH_COMPONENT16 0x81A5
+ glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT16, size.width(), size.height());
+#else
+ glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, size.width(), size.height());
+#endif
+ }
GLint i = 0;
- glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_DEPTH_SIZE_EXT, &i);
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_DEPTH_SIZE_EXT, &i);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, depth_stencil_buffer);
fbo_attachment = QGLFramebufferObject::Depth;
valid = checkFramebufferStatus();
if (!valid)
- glDeleteRenderbuffersEXT(1, &depth_stencil_buffer);
+ glDeleteRenderbuffers(1, &depth_stencil_buffer);
} else {
fbo_attachment = QGLFramebufferObject::NoAttachment;
}
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo);
if (!valid) {
- glDeleteTextures(1, &texture);
- glDeleteFramebuffersEXT(1, &fbo);
+ if (color_buffer)
+ glDeleteRenderbuffers(1, &color_buffer);
+ else
+ glDeleteTextures(1, &texture);
+ glDeleteFramebuffers(1, &fbo);
}
QT_CHECK_GLERROR();
+
+ format.setTextureTarget(target);
+ format.setSamples(int(samples));
+ format.setAttachment(fbo_attachment);
+ format.setInternalFormat(internal_format);
}
/*!
@@ -264,13 +540,18 @@ void QGLFramebufferObjectPrivate::init(const QSize &sz, QGLFramebufferObject::At
framebuffer objects more portable.
\endlist
- Note that primitives drawn to a QGLFramebufferObject with QPainter
- will only be antialiased if the QPainter::HighQualityAntialiasing
- render hint is set. This is because there is currently no support
- for the \c{GL_EXT_framebuffer_multisample} extension, which is
- required to do multisample based antialiasing. Also note that the
- QPainter::HighQualityAntialiasing render hint requires the
- \c{GL_ARB_fragment_program} extension to work in OpenGL.
+ Note that you need to create a QGLFramebufferObject with more than one
+ sample per pixel for primitives to be antialiased when drawing using a
+ QPainter, unless if the QPainter::HighQualityAntialiasing render hint is
+ set. The QPainter::HighQualityAntialiasing render hint will enable
+ antialiasing as long as the \c{GL_ARB_fragment_program} extension is
+ present. To create a multisample framebuffer object you should use one of
+ the constructors that take a QGLFramebufferObject parameter, and set the
+ QGLFramebufferObject::samples() property to a non-zero value.
+
+ If you want to use a framebuffer object with multisampling enabled
+ as a texture, you first need to copy from it to a regular framebuffer
+ object using QGLContext::blitFramebuffer().
\sa {Framebuffer Object Example}
*/
@@ -358,6 +639,32 @@ QGLFramebufferObject::QGLFramebufferObject(int width, int height, GLenum target)
d->init(QSize(width, height), NoAttachment, target, DEFAULT_FORMAT);
}
+/*! \overload
+
+ Constructs an OpenGL framebuffer object of the given \a size based on the
+ supplied \a format.
+*/
+
+QGLFramebufferObject::QGLFramebufferObject(const QSize &size, const QGLFramebufferObjectFormat &format)
+ : d_ptr(new QGLFramebufferObjectPrivate)
+{
+ Q_D(QGLFramebufferObject);
+ d->init(size, format.attachment(), format.textureTarget(), format.internalFormat(), format.samples());
+}
+
+/*! \overload
+
+ Constructs an OpenGL framebuffer object of the given \a width and \a height
+ based on the supplied \a format.
+*/
+
+QGLFramebufferObject::QGLFramebufferObject(int width, int height, const QGLFramebufferObjectFormat &format)
+ : d_ptr(new QGLFramebufferObjectPrivate)
+{
+ Q_D(QGLFramebufferObject);
+ d->init(QSize(width, height), format.attachment(), format.textureTarget(), format.internalFormat(), format.samples());
+}
+
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS
/*! \internal */
QGLFramebufferObject::QGLFramebufferObject(int width, int height, QMacCompatGLenum target)
@@ -445,9 +752,11 @@ QGLFramebufferObject::~QGLFramebufferObject()
|| qgl_share_reg()->checkSharing(d->ctx, QGLContext::currentContext())))
{
glDeleteTextures(1, &d->texture);
+ if (d->color_buffer)
+ glDeleteRenderbuffers(1, &d->color_buffer);
if (d->depth_stencil_buffer)
- glDeleteRenderbuffersEXT(1, &d->depth_stencil_buffer);
- glDeleteFramebuffersEXT(1, &d->fbo);
+ glDeleteRenderbuffers(1, &d->depth_stencil_buffer);
+ glDeleteFramebuffers(1, &d->fbo);
}
delete d_ptr;
}
@@ -490,7 +799,7 @@ bool QGLFramebufferObject::bind()
return false;
Q_D(QGLFramebufferObject);
QGL_FUNC_CONTEXT;
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, d->fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER_EXT, d->fbo);
d->bound = d->valid = d->checkFramebufferStatus();
const QGLContext *context = QGLContext::currentContext();
if (d->valid && context) {
@@ -520,18 +829,17 @@ bool QGLFramebufferObject::release()
return false;
Q_D(QGLFramebufferObject);
QGL_FUNC_CONTEXT;
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- d->valid = d->checkFramebufferStatus();
d->bound = false;
+
const QGLContext *context = QGLContext::currentContext();
- if (d->valid && context) {
+ if (context) {
// Restore the previous setting for stacked framebuffer objects.
context->d_ptr->current_fbo = d->previous_fbo;
- if (d->previous_fbo)
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, d->previous_fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER_EXT, d->previous_fbo);
d->previous_fbo = 0;
}
- return d->valid;
+
+ return true;
}
/*!
@@ -540,6 +848,9 @@ bool QGLFramebufferObject::release()
Returns the texture id for the texture attached as the default
rendering target in this framebuffer object. This texture id can
be bound as a normal texture in your own GL code.
+
+ If a multisample framebuffer object is used then the value returned
+ from this function will be invalid.
*/
GLuint QGLFramebufferObject::texture() const
{
@@ -560,6 +871,15 @@ QSize QGLFramebufferObject::size() const
}
/*!
+ Returns the format of this framebuffer object.
+*/
+const QGLFramebufferObjectFormat &QGLFramebufferObject::format() const
+{
+ Q_D(const QGLFramebufferObject);
+ return d->format;
+}
+
+/*!
\fn QImage QGLFramebufferObject::toImage() const
Returns the contents of this framebuffer object as a QImage.
@@ -577,17 +897,27 @@ QImage QGLFramebufferObject::toImage() const
return image;
}
-#if !defined(QT_OPENGL_ES_2)
-Q_GLOBAL_STATIC(QOpenGLPaintEngine, qt_buffer_paintengine)
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+Q_GLOBAL_STATIC(QGL2PaintEngineEx, qt_buffer_2_engine)
+#endif
+
+#ifndef QT_OPENGL_ES_2
+Q_GLOBAL_STATIC(QOpenGLPaintEngine, qt_buffer_engine)
#endif
/*! \reimp */
QPaintEngine *QGLFramebufferObject::paintEngine() const
{
-#if !defined(QT_OPENGL_ES_2)
- return qt_buffer_paintengine();
+#if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_1_CL)
+ return qt_buffer_engine();
+#elif defined(QT_OPENGL_ES_2)
+ return qt_buffer_2_engine();
#else
- return 0;
+ Q_D(const QGLFramebufferObject);
+ if (d->ctx->d_func()->internal_context || qt_gl_preferGL2Engine())
+ return qt_buffer_2_engine();
+ else
+ return qt_buffer_engine();
#endif
}
@@ -599,7 +929,8 @@ QPaintEngine *QGLFramebufferObject::paintEngine() const
*/
bool QGLFramebufferObject::hasOpenGLFramebufferObjects()
{
- QGLWidget dmy; // needed to detect and init the QGLExtensions object
+ if (!QGLContext::currentContext())
+ QGLWidget dmy; // needed to detect and init the QGLExtensions object
return (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject);
}
@@ -654,15 +985,16 @@ void QGLFramebufferObject::drawTexture(const QPointF &point, QMacCompatGLuint te
}
#endif
-extern int qt_defaultDpi();
+extern int qt_defaultDpiX();
+extern int qt_defaultDpiY();
/*! \reimp */
int QGLFramebufferObject::metric(PaintDeviceMetric metric) const
{
Q_D(const QGLFramebufferObject);
- float dpmx = qt_defaultDpi()*100./2.54;
- float dpmy = qt_defaultDpi()*100./2.54;
+ float dpmx = qt_defaultDpiX()*100./2.54;
+ float dpmy = qt_defaultDpiY()*100./2.54;
int w = d->size.width();
int h = d->size.height();
switch (metric) {
@@ -685,16 +1017,16 @@ int QGLFramebufferObject::metric(PaintDeviceMetric metric) const
return 32;//d->depth;
case PdmDpiX:
- return (int)(dpmx * 0.0254);
+ return qRound(dpmx * 0.0254);
case PdmDpiY:
- return (int)(dpmy * 0.0254);
+ return qRound(dpmy * 0.0254);
case PdmPhysicalDpiX:
- return (int)(dpmx * 0.0254);
+ return qRound(dpmx * 0.0254);
case PdmPhysicalDpiY:
- return (int)(dpmy * 0.0254);
+ return qRound(dpmy * 0.0254);
default:
qWarning("QGLFramebufferObject::metric(), Unhandled metric type: %d.\n", metric);
@@ -750,4 +1082,85 @@ bool QGLFramebufferObject::isBound() const
return d->bound;
}
+/*!
+ \fn bool QGLFramebufferObject::hasOpenGLFramebufferBlit()
+
+ \since 4.6
+
+ Returns true if the OpenGL \c{GL_EXT_framebuffer_blit} extension
+ is present on this system; otherwise returns false.
+*/
+bool QGLFramebufferObject::hasOpenGLFramebufferBlit()
+{
+ if (!QGLContext::currentContext())
+ QGLWidget dmy; // needed to detect and init the QGLExtensions object
+ return (QGLExtensions::glExtensions & QGLExtensions::FramebufferBlit);
+}
+
+/*!
+ \since 4.6
+
+ Blits from the \a sourceRect rectangle in the \a source framebuffer
+ object to the \a targetRect rectangle in the \a target framebuffer object.
+
+ If \a source or \a target is 0, the default framebuffer will be used
+ instead of a framebuffer object as source or target respectively.
+
+ The \a buffers parameter should be a mask consisting of any combination of
+ COLOR_BUFFER_BIT, DEPTH_BUFFER_BIT, and STENCIL_BUFFER_BIT. Any buffer type
+ that is not present both in the source and target buffers is ignored.
+
+ The \a sourceRect and \a targetRect rectangles may have different sizes;
+ in this case \a buffers should not contain DEPTH_BUFFER_BIT or
+ STENCIL_BUFFER_BIT. The \a filter parameter should be set to GL_LINEAR or
+ GL_NEAREST, and specifies whether linear or nearest interpolation should
+ be used when scaling is performed.
+
+ If \a source equals \a target a copy is performed within the same buffer.
+ Results are undefined if the source and target rectangles overlap and
+ have different sizes. The sizes must also be the same if any of the
+ framebuffer objects are multisample framebuffers.
+
+ Note that the scissor test will restrict the blit area if enabled.
+
+ This function will have no effect unless hasOpenGLFramebufferBlit() returns
+ true.
+*/
+void QGLFramebufferObject::blitFramebuffer(QGLFramebufferObject *target, const QRect &targetRect,
+ QGLFramebufferObject *source, const QRect &sourceRect,
+ GLbitfield buffers,
+ GLenum filter)
+{
+ if (!(QGLExtensions::glExtensions & QGLExtensions::FramebufferBlit))
+ return;
+
+ const QGLContext *ctx = QGLContext::currentContext();
+ if (!ctx)
+ return;
+
+ const int height = ctx->device()->height();
+
+ const int sh = source ? source->height() : height;
+ const int th = target ? target->height() : height;
+
+ const int sx0 = sourceRect.left();
+ const int sx1 = sourceRect.left() + sourceRect.width();
+ const int sy0 = sh - (sourceRect.top() + sourceRect.height());
+ const int sy1 = sh - sourceRect.top();
+
+ const int tx0 = targetRect.left();
+ const int tx1 = targetRect.left() + targetRect.width();
+ const int ty0 = th - (targetRect.top() + targetRect.height());
+ const int ty1 = th - targetRect.top();
+
+ glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, source ? source->handle() : 0);
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, target ? target->handle() : 0);
+
+ glBlitFramebufferEXT(sx0, sy0, sx1, sy1,
+ tx0, ty0, tx1, ty1,
+ buffers, filter);
+
+ glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo);
+}
+
QT_END_NAMESPACE
diff --git a/src/opengl/qglframebufferobject.h b/src/opengl/qglframebufferobject.h
index a9e1b2f..0a2a9d2 100644
--- a/src/opengl/qglframebufferobject.h
+++ b/src/opengl/qglframebufferobject.h
@@ -52,6 +52,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(OpenGL)
class QGLFramebufferObjectPrivate;
+class QGLFramebufferObjectFormat;
class Q_OPENGL_EXPORT QGLFramebufferObject : public QPaintDevice
{
@@ -77,6 +78,9 @@ public:
GLenum target = GL_TEXTURE_2D, GLenum internal_format = GL_RGBA);
#endif
+ QGLFramebufferObject(const QSize &size, const QGLFramebufferObjectFormat &format);
+ QGLFramebufferObject(int width, int height, const QGLFramebufferObjectFormat &format);
+
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS
QGLFramebufferObject(const QSize &size, QMacCompatGLenum target = GL_TEXTURE_2D);
QGLFramebufferObject(int width, int height, QMacCompatGLenum target = GL_TEXTURE_2D);
@@ -89,10 +93,13 @@ public:
virtual ~QGLFramebufferObject();
+ const QGLFramebufferObjectFormat &format() const;
+
bool isValid() const;
bool isBound() const;
bool bind();
bool release();
+
GLuint texture() const;
QSize size() const;
QImage toImage() const;
@@ -110,6 +117,12 @@ public:
void drawTexture(const QPointF &point, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget = GL_TEXTURE_2D);
#endif
+ static bool hasOpenGLFramebufferBlit();
+ static void blitFramebuffer(QGLFramebufferObject *target, const QRect &targetRect,
+ QGLFramebufferObject *source, const QRect &sourceRect,
+ GLbitfield buffers = GL_COLOR_BUFFER_BIT,
+ GLenum filter = GL_NEAREST);
+
protected:
int metric(PaintDeviceMetric metric) const;
int devType() const { return QInternal::FramebufferObject; }
@@ -120,6 +133,42 @@ private:
friend class QGLDrawable;
};
+class QGLFramebufferObjectFormatPrivate;
+class Q_OPENGL_EXPORT QGLFramebufferObjectFormat
+{
+public:
+#if !defined(QT_OPENGL_ES) || defined(Q_QDOC)
+ QGLFramebufferObjectFormat(int samples = 0,
+ QGLFramebufferObject::Attachment attachment = QGLFramebufferObject::NoAttachment,
+ GLenum target = GL_TEXTURE_2D,
+ GLenum internalFormat = GL_RGBA8);
+#else
+ QGLFramebufferObjectFormat(int samples = 0,
+ QGLFramebufferObject::Attachment attachment = QGLFramebufferObject::NoAttachment,
+ GLenum target = GL_TEXTURE_2D,
+ GLenum internalFormat = GL_RGBA);
+#endif
+
+ QGLFramebufferObjectFormat(const QGLFramebufferObjectFormat &other);
+ QGLFramebufferObjectFormat &operator=(const QGLFramebufferObjectFormat &other);
+ ~QGLFramebufferObjectFormat();
+
+ void setSamples(int samples);
+ int samples() const;
+
+ void setAttachment(QGLFramebufferObject::Attachment attachment);
+ QGLFramebufferObject::Attachment attachment() const;
+
+ void setTextureTarget(GLenum target);
+ GLenum textureTarget() const;
+
+ void setInternalFormat(GLenum internalFormat);
+ GLenum internalFormat() const;
+
+private:
+ QGLFramebufferObjectFormatPrivate *d;
+};
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/opengl/qglpixelbuffer.cpp b/src/opengl/qglpixelbuffer.cpp
index 5f74f26..efc58f2 100644
--- a/src/opengl/qglpixelbuffer.cpp
+++ b/src/opengl/qglpixelbuffer.cpp
@@ -81,7 +81,9 @@
#include <private/qglpixelbuffer_p.h>
#include <qimage.h>
-#if !defined(QT_OPENGL_ES_2)
+#include <private/qpaintengineex_opengl2_p.h>
+
+#ifndef QT_OPENGL_ES_2
#include <private/qpaintengine_opengl_p.h>
#endif
@@ -363,29 +365,39 @@ bool QGLPixelBuffer::isValid() const
return !d->invalid;
}
-#if !defined(QT_OPENGL_ES_2)
-Q_GLOBAL_STATIC(QOpenGLPaintEngine, qt_buffer_paintengine)
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
+Q_GLOBAL_STATIC(QGL2PaintEngineEx, qt_buffer_2_engine)
+#endif
+
+#ifndef QT_OPENGL_ES_2
+Q_GLOBAL_STATIC(QOpenGLPaintEngine, qt_buffer_engine)
#endif
/*! \reimp */
QPaintEngine *QGLPixelBuffer::paintEngine() const
{
-#if !defined(QT_OPENGL_ES_2)
- return qt_buffer_paintengine();
+#if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_1_CL)
+ return qt_buffer_engine();
+#elif defined(QT_OPENGL_ES_2)
+ return qt_buffer_2_engine();
#else
- return 0;
+ if (d_ptr->qctx->d_func()->internal_context || qt_gl_preferGL2Engine())
+ return qt_buffer_2_engine();
+ else
+ return qt_buffer_engine();
#endif
}
-extern int qt_defaultDpi();
+extern int qt_defaultDpiX();
+extern int qt_defaultDpiY();
/*! \reimp */
int QGLPixelBuffer::metric(PaintDeviceMetric metric) const
{
Q_D(const QGLPixelBuffer);
- float dpmx = qt_defaultDpi()*100./2.54;
- float dpmy = qt_defaultDpi()*100./2.54;
+ float dpmx = qt_defaultDpiX()*100./2.54;
+ float dpmy = qt_defaultDpiY()*100./2.54;
int w = d->req_size.width();
int h = d->req_size.height();
switch (metric) {
@@ -408,16 +420,16 @@ int QGLPixelBuffer::metric(PaintDeviceMetric metric) const
return 32;//d->depth;
case PdmDpiX:
- return (int)(dpmx * 0.0254);
+ return qRound(dpmx * 0.0254);
case PdmDpiY:
- return (int)(dpmy * 0.0254);
+ return qRound(dpmy * 0.0254);
case PdmPhysicalDpiX:
- return (int)(dpmx * 0.0254);
+ return qRound(dpmx * 0.0254);
case PdmPhysicalDpiY:
- return (int)(dpmy * 0.0254);
+ return qRound(dpmy * 0.0254);
default:
qWarning("QGLPixelBuffer::metric(), Unhandled metric type: %d\n", metric);
diff --git a/src/opengl/qglpixmapfilter.cpp b/src/opengl/qglpixmapfilter.cpp
index ff23948..eb3298b 100644
--- a/src/opengl/qglpixmapfilter.cpp
+++ b/src/opengl/qglpixmapfilter.cpp
@@ -45,27 +45,12 @@
#include "qpaintengine_opengl_p.h"
#include "qglpixelbuffer.h"
-#include "qglextensions_p.h"
+#include "qglshaderprogram.h"
#include "qgl_p.h"
#include "private/qapplication_p.h"
-#ifndef GL_FRAGMENT_SHADER
-#define GL_FRAGMENT_SHADER 0x8B30
-#endif
-
-#ifndef GL_COMPILE_STATUS
-#define GL_COMPILE_STATUS 0x8B81
-#endif
-
-#ifndef GL_LINK_STATUS
-#define GL_LINK_STATUS 0x8B82
-#endif
-
-
-
-
QT_BEGIN_NAMESPACE
@@ -79,117 +64,6 @@ void QGLPixmapFilterBase::drawImpl(QPainter *painter, const QPointF &pos, const
processGL(painter, pos, src, source);
}
-QGLSLProgram::QGLSLProgram(const QString &src)
- : ctx(QGLContext::currentContext())
-{
- if (!qt_resolve_glsl_extensions(const_cast<QGLContext *>(ctx))) {
- qWarning("Failed to resolve GLSL functions");
- m_valid = false;
- return;
- }
-
- m_shader = glCreateShader(GL_FRAGMENT_SHADER);
-
- const QByteArray src_ba = src.toAscii();
- const char *src_cstr = src_ba.constData();
-
- glShaderSource(m_shader, 1, &src_cstr, 0);
- glCompileShader(m_shader);
- glGetShaderiv(m_shader, GL_COMPILE_STATUS, &m_valid);
- if (!m_valid) {
- char data[4096];
- GLsizei len;
- glGetShaderInfoLog(m_shader, 4096, &len, data);
- qWarning("Failed to compile GLSL shader:\n%s\nCODE:\n%s\n", data, src_cstr);
- return;
- }
-
- m_program = glCreateProgram();
- glAttachShader(m_program, m_shader);
- glLinkProgram(m_program);
- glGetProgramiv(m_program, GL_LINK_STATUS, &m_valid);
- if (!m_valid) {
- char data[4096];
- GLsizei len;
- glGetShaderInfoLog(m_shader, 4096, &len, data);
- qWarning("Failed to link GLSL program:\n%s\nCODE:\n%s\n", data, src_cstr);
- return;
- }
-}
-
-QGLSLProgram::~QGLSLProgram()
-{
- glDeleteProgram(m_program);
- glDeleteShader(m_shader);
-}
-
-bool QGLSLProgram::success() const
-{
- return m_valid;
-}
-
-void QGLSLProgram::enable()
-{
- glUseProgram(m_program);
-}
-
-void QGLSLProgram::disable()
-{
- glUseProgram(0);
-}
-
-typedef GLuint (APIENTRY *_glGetUniformLocation) (GLuint, const char*);
-typedef void (APIENTRY *_glUniform4fv) (GLint, GLsizei, GLfloat *);
-typedef void (APIENTRY *_glUniform3fv) (GLint, GLsizei, GLfloat *);
-typedef void (APIENTRY *_glUniform2fv) (GLint, GLsizei, GLfloat *);
-typedef void (APIENTRY *_glUniform1fv) (GLint, GLsizei, GLfloat *);
-typedef void (APIENTRY *_glUniform1i) (GLint, GLint);
-
-int QGLSLProgram::getUniformLocation(const QString &name)
-{
- return glGetUniformLocation(m_program, name.toAscii().constData());
-}
-
-void QGLSLProgram::setUniform(int uniform, int value)
-{
- enable();
- glUniform1i(uniform, value);
-}
-
-void QGLSLProgram::setUniform(int uniform, qreal value)
-{
- enable();
- GLfloat v[] = { value };
- glUniform1fv(uniform, 1, v);
-}
-
-void QGLSLProgram::setUniform(int uniform, qreal v1, qreal v2)
-{
- enable();
- GLfloat v[] = { v1, v2 };
- glUniform2fv(uniform, 1, v);
-}
-
-void QGLSLProgram::setUniform(int uniform, qreal v1, qreal v2, qreal v3)
-{
- enable();
- GLfloat v[] = { v1, v2, v3 };
- glUniform3fv(uniform, 1, v);
-}
-
-void QGLSLProgram::setUniform(int uniform, qreal v1, qreal v2, qreal v3, qreal v4)
-{
- enable();
- GLfloat v[] = { v1, v2, v3, v4 };
- glUniform4fv(uniform, 1, v);
-}
-
-void QGLSLProgram::setUniform(int uniform, int count, float *v)
-{
- enable();
- glUniform1fv(uniform, count, v);
-}
-
class QGLPixmapColorizeFilter: public QGLPixmapFilter<QPixmapColorizeFilter>
{
public:
@@ -199,8 +73,8 @@ protected:
bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &pixmap, const QRectF &srcRect) const;
private:
- mutable QGLSLProgram m_program;
- uint m_colorUniform;
+ mutable QGLShaderProgram m_program;
+ int m_colorUniform;
};
class QGLPixmapConvolutionFilter: public QGLPixmapFilter<QPixmapConvolutionFilter>
@@ -213,11 +87,11 @@ protected:
bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const;
private:
- QString generateConvolutionShader() const;
+ QByteArray generateConvolutionShader() const;
- mutable QGLSLProgram *m_program;
- mutable uint m_scaleUniform;
- mutable uint m_matrixUniform;
+ mutable QGLShaderProgram *m_program;
+ mutable int m_scaleUniform;
+ mutable int m_matrixUniform;
mutable int m_kernelWidth;
mutable int m_kernelHeight;
@@ -242,10 +116,8 @@ QPixmapFilter *QGLContextPrivate::createPixmapFilter(int type) const
return 0;
}
-#if !defined(QT_OPENGL_ES_2)
extern void qt_add_rect_to_array(const QRectF &r, q_vertexType *array);
extern void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, q_vertexType *array);
-#endif
static void qgl_drawTexture(const QRectF &rect, int tx_width, int tx_height, const QRectF & src)
{
@@ -294,10 +166,12 @@ static const char *qt_gl_colorize_filter =
"}";
QGLPixmapColorizeFilter::QGLPixmapColorizeFilter()
- : m_program(QLatin1String(qt_gl_colorize_filter))
{
- m_program.setUniform(m_program.getUniformLocation(QLatin1String("texture")), 0); // GL_TEXTURE_0
- m_colorUniform = m_program.getUniformLocation(QLatin1String("color"));
+ m_program.addShader(QGLShader::FragmentShader, qt_gl_colorize_filter);
+ m_program.link();
+ m_program.enable();
+ m_program.setUniformValue(m_program.uniformLocation("texture"), GLint(0)); // GL_TEXTURE_0
+ m_colorUniform = m_program.uniformLocation("color");
}
bool QGLPixmapColorizeFilter::processGL(QPainter *, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const
@@ -305,10 +179,10 @@ bool QGLPixmapColorizeFilter::processGL(QPainter *, const QPointF &pos, const QP
bindTexture(src);
QColor col = color();
- m_program.setUniform(m_colorUniform, col.redF(), col.greenF(), col.blueF());
+ m_program.enable();
+ m_program.setUniformValue(m_colorUniform, col.redF(), col.greenF(), col.blueF());
QRectF target = (srcRect.isNull() ? QRectF(src.rect()) : srcRect).translated(pos);
- m_program.enable();
qgl_drawTexture(target, src.width(), src.height(), srcRect);
m_program.disable();
@@ -316,7 +190,7 @@ bool QGLPixmapColorizeFilter::processGL(QPainter *, const QPointF &pos, const QP
}
// generates convolution filter code for arbitrary sized kernel
-QString QGLPixmapConvolutionFilter::generateConvolutionShader() const {
+QByteArray QGLPixmapConvolutionFilter::generateConvolutionShader() const {
QByteArray code;
code.append("uniform sampler2D texture;\n");
code.append("uniform vec2 inv_texture_size;\n");
@@ -352,7 +226,7 @@ QString QGLPixmapConvolutionFilter::generateConvolutionShader() const {
code.append(" }\n");
code.append(" gl_FragColor = sum;\n");
code.append("}");
- return QLatin1String(code);
+ return code;
}
QGLPixmapConvolutionFilter::QGLPixmapConvolutionFilter()
@@ -384,10 +258,12 @@ bool QGLPixmapConvolutionFilter::processGL(QPainter *, const QPointF &pos, const
m_kernelWidth = columns();
m_kernelHeight = rows();
- QString code = generateConvolutionShader();
- m_program = new QGLSLProgram(code);
- m_scaleUniform = m_program->getUniformLocation(QLatin1String("inv_texture_size"));
- m_matrixUniform = m_program->getUniformLocation(QLatin1String("matrix"));
+ QByteArray code = generateConvolutionShader();
+ m_program = new QGLShaderProgram();
+ m_program->addShader(QGLShader::FragmentShader, code);
+ m_program->link();
+ m_scaleUniform = m_program->uniformLocation("inv_texture_size");
+ m_matrixUniform = m_program->uniformLocation("matrix");
}
const qreal *kernel = convolutionKernel();
@@ -397,10 +273,10 @@ bool QGLPixmapConvolutionFilter::processGL(QPainter *, const QPointF &pos, const
const qreal iw = 1.0 / src.width();
const qreal ih = 1.0 / src.height();
- m_program->setUniform(m_scaleUniform, iw, ih);
- m_program->setUniform(m_matrixUniform, m_kernelWidth * m_kernelHeight, conv);
-
m_program->enable();
+ m_program->setUniformValue(m_scaleUniform, iw, ih);
+ m_program->setUniformValueArray(m_matrixUniform, conv, m_kernelWidth * m_kernelHeight, 1);
+
qgl_drawTexture(target, src.width(), src.height(), boundingRectFor(srcRect));
m_program->disable();
return true;
diff --git a/src/opengl/qglpixmapfilter_p.h b/src/opengl/qglpixmapfilter_p.h
index dc2eea6..d6742fc 100644
--- a/src/opengl/qglpixmapfilter_p.h
+++ b/src/opengl/qglpixmapfilter_p.h
@@ -87,35 +87,6 @@ public:
}
};
-class Q_OPENGL_EXPORT QGLSLProgram
-{
-public:
- QGLSLProgram(const QString &src);
- ~QGLSLProgram();
-
- bool success() const;
-
- void enable();
- void disable();
-
- int getUniformLocation(const QString &name);
-
- void setUniform(int uniform, int value);
- void setUniform(int uniform, qreal value);
- void setUniform(int uniform, qreal v1, qreal v2);
- void setUniform(int uniform, qreal v1, qreal v2, qreal v3);
- void setUniform(int uniform, qreal v1, qreal v2, qreal v3, qreal v4);
- void setUniform(int uniform, int count, float *v);
-
-private:
- GLuint m_shader;
- GLuint m_program;
-
- GLint m_valid;
-
- const QGLContext *ctx;
-};
-
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp
new file mode 100644
index 0000000..d74b930
--- /dev/null
+++ b/src/opengl/qglshaderprogram.cpp
@@ -0,0 +1,2992 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qglshaderprogram.h"
+#include "qglextensions_p.h"
+#include "qgl_p.h"
+#include <QtCore/qdebug.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qvarlengtharray.h>
+#include <QtCore/qvector.h>
+
+QT_BEGIN_NAMESPACE
+
+#if !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
+
+/*!
+ \class QGLShaderProgram
+ \brief The QGLShaderProgram class allows OpenGL shader programs to be linked and used.
+ \since 4.6
+
+ \section1 Introduction
+
+ This class supports shader programs written in the OpenGL Shading
+ Language (GLSL) and in the OpenGL/ES Shading Language (GLSL/ES).
+
+ QGLShader and QGLShaderProgram shelter the programmer from the details of
+ compiling and linking vertex and fragment shaders.
+
+ The following example creates a vertex shader program using the
+ supplied source \c{code}. Once compiled and linked, the shader
+ program is activated in the current QGLContext by calling
+ QGLShaderProgram::enable():
+
+ \code
+ QGLShader shader(QGLShader::VertexShader);
+ shader.setSourceCode(code);
+
+ QGLShaderProgram program(context);
+ program.addShader(shader);
+ program.link();
+
+ program.enable();
+ \endcode
+
+ \section1 Writing portable shaders
+
+ Shader programs can be difficult to reuse across OpenGL implementations
+ because of varying levels of support for standard vertex attributes and
+ uniform variables. In particular, GLSL/ES lacks all of the
+ standard variables that are present on desktop OpenGL systems:
+ \c{gl_Vertex}, \c{gl_Normal}, \c{gl_Color}, and so on. Desktop OpenGL
+ lacks the variable qualifiers \c{highp}, \c{mediump}, and \c{lowp}.
+
+ The QGLShaderProgram class makes the process of writing portable shaders
+ easier by prefixing all shader programs with the following lines on
+ desktop OpenGL:
+
+ \code
+ #define highp
+ #define mediump
+ #define lowp
+ \endcode
+
+ This makes it possible to run most GLSL/ES shader programs
+ on desktop systems. The programmer should restrict themselves
+ to just features that are present in GLSL/ES, and avoid
+ standard variable names that only work on the desktop.
+
+ \section1 Simple shader example
+
+ \code
+ program.addShader(QGLShader::VertexShader,
+ "attribute highp vec4 vertex;\n"
+ "attribute mediump mat4 matrix;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_Position = matrix * vertex;\n"
+ "}");
+ program.addShader(QGLShader::FragmentShader,
+ "uniform mediump vec4 color;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_FragColor = color;\n"
+ "}");
+ program.link();
+ program.enable();
+
+ int vertexLocation = program.attributeLocation("vertex");
+ int matrixLocation = program.attributeLocation("matrix");
+ int colorLocation = program.uniformLocation("color");
+ \endcode
+
+ With the above shader program active, we can draw a green triangle
+ as follows:
+
+ \code
+ static GLfloat const triangleVertices[] = {
+ 60.0f, 10.0f, 0.0f,
+ 110.0f, 110.0f, 0.0f,
+ 10.0f, 110.0f, 0.0f
+ };
+
+ QColor color(0, 255, 0, 255);
+
+ QMatrix4x4 pmvMatrix;
+ pmvMatrix.ortho(rect());
+
+ program.setAttributeArray(vertexLocation, triangleVertices, 3);
+ program.setUniformValue(matrixLocation, pmvMatrix);
+ program.setUniformValue(colorLocation, color);
+
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+ \endcode
+
+ \section1 Partial shaders
+
+ Desktop GLSL can attach an arbitrary number of vertex and fragment
+ shaders to a shader program. Embedded GLSL/ES on the other hand
+ supports only a single shader of each type on a shader program.
+
+ Multiple shaders of the same type can be useful when large libraries
+ of shaders are needed. Common functions can be factored out into
+ library shaders that can be reused in multiple shader programs.
+
+ To support this use of shaders, the application programmer can
+ create shaders with the QGLShader::PartialVertexShader and
+ QGLShader::PartialFragmentShader types. These types direct
+ QGLShader and QGLShaderProgram to delay shader compilation until
+ link time.
+
+ When link() is called, the sources for the partial shaders are
+ concatenated, and a single vertex or fragment shader is compiled
+ and linked into the shader program.
+
+ It is more efficient to use the QGLShader::VertexShader and
+ QGLShader::FragmentShader when there is only one shader of that
+ type in the program.
+
+ \sa QGLShader
+*/
+
+/*!
+ \class QGLShader
+ \brief The QGLShader class allows OpenGL shaders to be compiled.
+ \since 4.6
+
+ This class supports shaders written in the OpenGL Shading Language (GLSL)
+ and in the OpenGL/ES Shading Language (GLSL/ES).
+
+ QGLShader and QGLShaderProgram shelter the programmer from the details of
+ compiling and linking vertex and fragment shaders.
+
+ \sa QGLShaderProgram
+*/
+
+/*!
+ \enum QGLShader::ShaderType
+ This enum specifies the type of QGLShader that is being created.
+
+ \value VertexShader Vertex shader written in the OpenGL Shading Language (GLSL).
+ \value FragmentShader Fragment shader written in the OpenGL Shading Language (GLSL).
+ \value PartialVertexShader Partial vertex shader that will be concatenated with all other partial vertex shaders at link time.
+ \value PartialFragmentShader Partial fragment shader that will be concatenated with all other partial fragment shaders at link time.
+*/
+
+#ifndef GL_FRAGMENT_SHADER
+#define GL_FRAGMENT_SHADER 0x8B30
+#endif
+#ifndef GL_VERTEX_SHADER
+#define GL_VERTEX_SHADER 0x8B31
+#endif
+#ifndef GL_COMPILE_STATUS
+#define GL_COMPILE_STATUS 0x8B81
+#endif
+#ifndef GL_LINK_STATUS
+#define GL_LINK_STATUS 0x8B82
+#endif
+#ifndef GL_INFO_LOG_LENGTH
+#define GL_INFO_LOG_LENGTH 0x8B84
+#endif
+#ifndef GL_ACTIVE_UNIFORMS
+#define GL_ACTIVE_UNIFORMS 0x8B86
+#endif
+#ifndef GL_ACTIVE_UNIFORM_MAX_LENGTH
+#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#endif
+#ifndef GL_ACTIVE_ATTRIBUTES
+#define GL_ACTIVE_ATTRIBUTES 0x8B89
+#endif
+#ifndef GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
+#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#endif
+#ifndef GL_CURRENT_VERTEX_ATTRIB
+#define GL_CURRENT_VERTEX_ATTRIB 0x8626
+#endif
+#ifndef GL_SHADER_SOURCE_LENGTH
+#define GL_SHADER_SOURCE_LENGTH 0x8B88
+#endif
+#ifndef GL_SHADER_BINARY_FORMATS
+#define GL_SHADER_BINARY_FORMATS 0x8DF8
+#endif
+#ifndef GL_NUM_SHADER_BINARY_FORMATS
+#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9
+#endif
+
+class QGLShaderPrivate
+{
+public:
+ QGLShaderPrivate(QGLShader::ShaderType type, const QGLContext *ctx)
+ {
+ context = ctx;
+ shader = 0;
+ shaderType = type;
+ compiled = false;
+ isPartial = (type == QGLShader::PartialVertexShader ||
+ type == QGLShader::PartialFragmentShader);
+ hasPartialSource = false;
+ }
+
+ const QGLContext *context;
+ GLuint shader;
+ QGLShader::ShaderType shaderType;
+ bool compiled;
+ bool isPartial;
+ bool hasPartialSource;
+ QString log;
+ QByteArray partialSource;
+
+ bool create();
+ bool compile();
+};
+
+#define ctx context
+
+bool QGLShaderPrivate::create()
+{
+ if (isPartial)
+ return true;
+ if (!context)
+ context = QGLContext::currentContext();
+ if (!context)
+ return false;
+ if (qt_resolve_glsl_extensions(const_cast<QGLContext *>(context))) {
+ if (shaderType == QGLShader::VertexShader)
+ shader = glCreateShader(GL_VERTEX_SHADER);
+ else
+ shader = glCreateShader(GL_FRAGMENT_SHADER);
+ if (!shader) {
+ qWarning() << "QGLShader: could not create shader";
+ return false;
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool QGLShaderPrivate::compile()
+{
+ // Partial shaders are compiled during QGLShaderProgram::link().
+ if (isPartial && hasPartialSource) {
+ compiled = true;
+ return true;
+ }
+ if (!shader)
+ return false;
+ glCompileShader(shader);
+ GLint value = 0;
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &value);
+ compiled = (value != 0);
+ value = 0;
+ glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &value);
+ if (!compiled && value > 1) {
+ char *logbuf = new char [value];
+ GLint len;
+ glGetShaderInfoLog(shader, value, &len, logbuf);
+ log = QString::fromLatin1(logbuf);
+ qWarning() << "QGLShader::compile:" << log;
+ delete [] logbuf;
+ }
+ return compiled;
+}
+
+#undef ctx
+#define ctx d->context
+
+/*!
+ Constructs a new QGLShader object of the specified \a type
+ and attaches it to \a parent. If shader programs are not supported,
+ then isValid() will return false.
+
+ This constructor is normally followed by a call to setSourceCode()
+ or setSourceCodeFile().
+
+ The shader will be associated with the current QGLContext.
+
+ \sa setSourceCode(), setSourceCodeFile(), isValid()
+*/
+QGLShader::QGLShader(QGLShader::ShaderType type, QObject *parent)
+ : QObject(parent)
+{
+ d = new QGLShaderPrivate(type, QGLContext::currentContext());
+ d->create();
+}
+
+/*!
+ Constructs a new QGLShader object from the source code in \a fileName
+ and attaches it to \a parent. If the filename ends in \c{.fsh},
+ it is assumed to be a fragment shader, otherwise it is assumed to
+ be a vertex shader (normally the extension is \c{.vsh} for vertex shaders).
+ If the shader could not be loaded, then isValid() will return false.
+
+ The shader will be associated with the current QGLContext.
+
+ \sa isValid()
+*/
+QGLShader::QGLShader(const QString& fileName, QObject *parent)
+ : QObject(parent)
+{
+ if (fileName.endsWith(QLatin1String(".fsh"), Qt::CaseInsensitive))
+ d = new QGLShaderPrivate(QGLShader::FragmentShader, QGLContext::currentContext());
+ else
+ d = new QGLShaderPrivate(QGLShader::VertexShader, QGLContext::currentContext());
+ if (d->create() && !setSourceCodeFile(fileName)) {
+ if (d->shader)
+ glDeleteShader(d->shader);
+ d->shader = 0;
+ }
+}
+
+/*!
+ Constructs a new QGLShader object of the specified \a type from the
+ source code in \a fileName and attaches it to \a parent.
+ If the shader could not be loaded, then isValid() will return false.
+
+ The shader will be associated with the current QGLContext.
+
+ \sa isValid()
+*/
+QGLShader::QGLShader
+ (const QString& fileName, QGLShader::ShaderType type, QObject *parent)
+ : QObject(parent)
+{
+ d = new QGLShaderPrivate(type, QGLContext::currentContext());
+ if (d->create() && !setSourceCodeFile(fileName)) {
+ if (d->shader)
+ glDeleteShader(d->shader);
+ d->shader = 0;
+ }
+}
+
+/*!
+ Constructs a new QGLShader object of the specified \a type
+ and attaches it to \a parent. If shader programs are not supported,
+ then isValid() will return false.
+
+ This constructor is normally followed by a call to setSourceCode()
+ or setSourceCodeFile().
+
+ The shader will be associated with \a context.
+
+ \sa setSourceCode(), setSourceCodeFile(), isValid()
+*/
+QGLShader::QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObject *parent)
+ : QObject(parent)
+{
+ d = new QGLShaderPrivate(type, context);
+ d->create();
+}
+
+/*!
+ Constructs a new QGLShader object from the source code in \a fileName
+ and attaches it to \a parent. If the filename ends in \c{.fsh},
+ it is assumed to be a fragment shader, otherwise it is assumed to
+ be a vertex shader (normally the extension is \c{.vsh} for vertex shaders).
+ If the shader could not be loaded, then isValid() will return false.
+
+ The shader will be associated with \a context.
+
+ \sa isValid()
+*/
+QGLShader::QGLShader(const QString& fileName, const QGLContext *context, QObject *parent)
+ : QObject(parent)
+{
+ if (fileName.endsWith(QLatin1String(".fsh"), Qt::CaseInsensitive))
+ d = new QGLShaderPrivate(QGLShader::FragmentShader, context);
+ else
+ d = new QGLShaderPrivate(QGLShader::VertexShader, context);
+ if (d->create() && !setSourceCodeFile(fileName)) {
+ if (d->shader)
+ glDeleteShader(d->shader);
+ d->shader = 0;
+ }
+}
+
+/*!
+ Constructs a new QGLShader object of the specified \a type from the
+ source code in \a fileName and attaches it to \a parent.
+ If the shader could not be loaded, then isValid() will return false.
+
+ The shader will be associated with \a context.
+
+ \sa isValid()
+*/
+QGLShader::QGLShader
+ (const QString& fileName, QGLShader::ShaderType type, const QGLContext *context, QObject *parent)
+ : QObject(parent)
+{
+ d = new QGLShaderPrivate(type, context);
+ if (d->create() && !setSourceCodeFile(fileName)) {
+ if (d->shader)
+ glDeleteShader(d->shader);
+ d->shader = 0;
+ }
+}
+
+/*!
+ Deletes this shader. If the shader has been attached to a
+ QGLShaderProgram object, then the actual shader will stay around
+ until the QGLShaderProgram is destroyed.
+*/
+QGLShader::~QGLShader()
+{
+ if (d->shader)
+ glDeleteShader(d->shader);
+ delete d;
+}
+
+/*!
+ Returns true if this shader is valid. Shaders become invalid
+ when they are destroyed and no longer attached to a QGLShaderProgram.
+*/
+bool QGLShader::isValid() const
+{
+ if (d->isPartial && d->hasPartialSource)
+ return true;
+ if (!d->shader)
+ return false;
+#if defined(QT_OPENGL_ES_2)
+ return glIsShader(d->shader);
+#else
+ // glIsShader() may not exist on some systems.
+ return (!glIsShader || glIsShader(d->shader));
+#endif
+}
+
+/*!
+ Returns the type of this shader.
+*/
+QGLShader::ShaderType QGLShader::shaderType() const
+{
+ return d->shaderType;
+}
+
+// The precision qualifiers are useful on OpenGL/ES systems,
+// but usually not present on desktop systems. Define the
+// keywords to empty strings on desktop systems.
+#ifndef QT_OPENGL_ES
+#define QGL_DEFINE_QUALIFIERS 1
+static const char qualifierDefines[] =
+ "#define lowp\n"
+ "#define mediump\n"
+ "#define highp\n";
+#endif
+
+/*!
+ Sets the \a source code for this shader and compiles it.
+ Returns true if the source was successfully compiled, false otherwise.
+
+ If shaderType() is PartialVertexShader or PartialFragmentShader,
+ then this function will always return true, even if the source code
+ is invalid. Partial shaders are compiled when QGLShaderProgram::link()
+ is called.
+*/
+bool QGLShader::setSourceCode(const char *source)
+{
+ if (d->isPartial) {
+ d->partialSource = QByteArray(source);
+ d->hasPartialSource = true;
+ return d->compile();
+ } else if (d->shader) {
+ QVarLengthArray<const char *> src;
+#ifdef QGL_DEFINE_QUALIFIERS
+ src.append(qualifierDefines);
+#endif
+ src.append(source);
+ glShaderSource(d->shader, src.size(), src.data(), 0);
+ return d->compile();
+ } else {
+ return false;
+ }
+}
+
+/*!
+ \overload
+
+ Sets the \a source code for this shader and compiles it.
+ Returns true if the source was successfully compiled, false otherwise.
+
+ If shaderType() is PartialVertexShader or PartialFragmentShader,
+ then this function will always return true, even if the source code
+ is invalid. Partial shaders are compiled when QGLShaderProgram::link()
+ is called.
+*/
+bool QGLShader::setSourceCode(const QByteArray& source)
+{
+ return setSourceCode(source.constData());
+}
+
+/*!
+ \overload
+
+ Sets the \a source code for this shader and compiles it.
+ Returns true if the source was successfully compiled, false otherwise.
+
+ If shaderType() is PartialVertexShader or PartialFragmentShader,
+ then this function will always return true, even if the source code
+ is invalid. Partial shaders are compiled when QGLShaderProgram::link()
+ is called.
+*/
+bool QGLShader::setSourceCode(const QString& source)
+{
+ return setSourceCode(source.toLatin1().constData());
+}
+
+/*!
+ Sets the source code for this shader to the contents of \a fileName
+ and compiles it. Returns true if the file could be opened and the
+ source compiled, false otherwise.
+
+ If shaderType() is PartialVertexShader or PartialFragmentShader,
+ then this function will always return true, even if the source code
+ is invalid. Partial shaders are compiled when QGLShaderProgram::link()
+ is called.
+*/
+bool QGLShader::setSourceCodeFile(const QString& fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly)) {
+ qWarning() << "QGLShader: Unable to open file" << fileName;
+ return false;
+ }
+
+ QByteArray contents = file.readAll();
+ return setSourceCode(contents.constData());
+}
+
+/*!
+ Sets the binary code for this shader to the \a length bytes from
+ the array \a binary. The \a format specifies how the binary data
+ should be interpreted by the OpenGL engine. Returns true if the
+ binary was set on the shader; false otherwise.
+
+ This function cannot be used with PartialVertexShader or
+ PartialFragmentShader.
+
+ \sa shaderBinaryFormats()
+*/
+bool QGLShader::setBinaryCode(GLenum format, const void *binary, int length)
+{
+#if !defined(QT_OPENGL_ES_2)
+ if (!glShaderBinary)
+ return false;
+#endif
+ if (d->isPartial || !d->shader)
+ return false;
+ glGetError(); // Clear error state.
+ glShaderBinary(1, &(d->shader), format, binary, length);
+ return (glGetError() == GL_NO_ERROR);
+}
+
+/*!
+ Sets the binary code for this shader to the \a length bytes from
+ the array \a binary. The \a format specifies how the binary data
+ should be interpreted by the OpenGL engine. Returns true if the
+ binary was set on the shader; false otherwise.
+
+ The \a otherShader will also have binary code set on it. This is
+ for the case where \a binary contains both vertex and fragment
+ shader code.
+
+ This function cannot be used with PartialVertexShader or
+ PartialFragmentShader.
+
+ \sa shaderBinaryFormats()
+*/
+bool QGLShader::setBinaryCode
+ (QGLShader& otherShader, GLenum format, const void *binary, int length)
+{
+#if !defined(QT_OPENGL_ES_2)
+ if (!glShaderBinary)
+ return false;
+#endif
+ if (d->isPartial || !d->shader)
+ return false;
+ if (otherShader.d->isPartial || !otherShader.d->shader)
+ return false;
+ glGetError(); // Clear error state.
+ GLuint shaders[2];
+ shaders[0] = d->shader;
+ shaders[1] = otherShader.d->shader;
+ glShaderBinary(2, shaders, format, binary, length);
+ return (glGetError() == GL_NO_ERROR);
+}
+
+/*!
+ Returns a list of all binary formats that are supported by
+ setBinaryCode() on this system.
+
+ \sa setBinaryCode()
+*/
+QList<GLenum> QGLShader::shaderBinaryFormats()
+{
+ GLint num;
+ QList<GLenum> list;
+ glGetError(); // Clear error state.
+ glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &num);
+ if (glGetError() != GL_NO_ERROR || num <= 0)
+ return list;
+ QVarLengthArray<GLint> formats(num);
+ glGetIntegerv(GL_SHADER_BINARY_FORMATS, formats.data());
+ for (GLint i = 0; i < num; ++i)
+ list += (GLenum)(formats[i]);
+ return list;
+}
+
+/*!
+ Returns the source code for this shader.
+
+ \sa setSourceCode()
+*/
+QByteArray QGLShader::sourceCode() const
+{
+ if (d->isPartial)
+ return d->partialSource;
+ if (!d->shader)
+ return QByteArray();
+ GLint size = 0;
+ glGetShaderiv(d->shader, GL_SHADER_SOURCE_LENGTH, &size);
+ if (size <= 0)
+ return QByteArray();
+ GLint len = 0;
+ char *source = new char [size];
+ glGetShaderSource(d->shader, size, &len, source);
+ QByteArray src(source);
+ delete [] source;
+ return src;
+}
+
+/*!
+ Returns true if this shader has been compiled; false otherwise.
+
+ \sa setSourceCode()
+*/
+bool QGLShader::isCompiled() const
+{
+ return d->compiled;
+}
+
+/*!
+ Returns the errors and warnings that occurred during the last compile.
+
+ \sa setSourceCode()
+*/
+QString QGLShader::log() const
+{
+ return d->log;
+}
+
+/*!
+ Returns the OpenGL identifier associated with this shader.
+
+ If shaderType() is PartialVertexShader or PartialFragmentShader,
+ this function will always return zero. Partial shaders are
+ created and compiled when QGLShaderProgram::link() is called.
+
+ \sa QGLShaderProgram::programId()
+*/
+GLuint QGLShader::shaderId() const
+{
+ return d->shader;
+}
+
+#undef ctx
+#define ctx context
+
+class QGLShaderProgramPrivate
+{
+public:
+ QGLShaderProgramPrivate(const QGLContext *ctx)
+ {
+ context = ctx;
+ program = 0;
+ linked = false;
+ inited = false;
+ hasPartialShaders = false;
+ vertexShader = 0;
+ fragmentShader = 0;
+ }
+ ~QGLShaderProgramPrivate()
+ {
+ if (program)
+ glDeleteProgram(program);
+ }
+
+ const QGLContext *context;
+ GLuint program;
+ bool linked;
+ bool inited;
+ bool hasPartialShaders;
+ QString log;
+ QList<QGLShader *> shaders;
+ QList<QGLShader *> anonShaders;
+ QGLShader *vertexShader;
+ QGLShader *fragmentShader;
+};
+
+#undef ctx
+#define ctx d->context
+
+/*!
+ Constructs a new shader program and attaches it to \a parent.
+ The program will be invalid until addShader() is called.
+
+ The shader program will be associated with the current QGLContext.
+
+ \sa isValid(), addShader()
+*/
+QGLShaderProgram::QGLShaderProgram(QObject *parent)
+ : QObject(parent)
+{
+ d = new QGLShaderProgramPrivate(QGLContext::currentContext());
+}
+
+/*!
+ Constructs a new shader program and attaches it to \a parent.
+ The program will be invalid until addShader() is called.
+
+ The shader program will be associated with \a context.
+
+ \sa isValid(), addShader()
+*/
+QGLShaderProgram::QGLShaderProgram(const QGLContext *context, QObject *parent)
+ : QObject(parent)
+{
+ d = new QGLShaderProgramPrivate(context);
+}
+
+/*!
+ Deletes this shader program.
+*/
+QGLShaderProgram::~QGLShaderProgram()
+{
+ delete d;
+}
+
+bool QGLShaderProgram::init()
+{
+ if (d->program || d->inited)
+ return true;
+ d->inited = true;
+ if (!d->context)
+ d->context = QGLContext::currentContext();
+ if (!d->context)
+ return false;
+ if (qt_resolve_glsl_extensions(const_cast<QGLContext *>(d->context))) {
+ d->program = glCreateProgram();
+ if (!(d->program)) {
+ qWarning() << "QGLShaderProgram: could not create shader program";
+ return false;
+ }
+ return true;
+ } else {
+ qWarning() << "QGLShaderProgram: shader programs are not supported";
+ return false;
+ }
+}
+
+/*!
+ Returns true if this shader program object is valid, false otherwise.
+*/
+bool QGLShaderProgram::isValid() const
+{
+ if (!d->program)
+ return false;
+#if defined(QT_OPENGL_ES_2)
+ return glIsProgram(d->program);
+#else
+ // glIsProgram() may not exist on some systems.
+ return (!glIsProgram || glIsProgram(d->program));
+#endif
+}
+
+/*!
+ Adds a compiled \a shader to this shader program. Returns true
+ if the shader could be added, or false otherwise.
+
+ Ownership of the \a shader object remains with the caller.
+ It will not be deleted when this QGLShaderProgram instance
+ is deleted. This allows the caller to add the same shader
+ to multiple shader programs.
+
+ \sa removeShader(), link(), removeAllShaders()
+*/
+bool QGLShaderProgram::addShader(QGLShader *shader)
+{
+ if (!init())
+ return false;
+ if (d->shaders.contains(shader))
+ return true; // Already added to this shader program.
+ if (d->program && shader) {
+ if (!shader->d->compiled)
+ return false;
+ if (!shader->d->isPartial) {
+ if (!shader->d->shader)
+ return false;
+ glAttachShader(d->program, shader->d->shader);
+ } else {
+ d->hasPartialShaders = true;
+ }
+ d->linked = false; // Program needs to be relinked.
+ d->shaders.append(shader);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/*!
+ Compiles \a source as a shader of the specified \a type and
+ adds it to this shader program. Returns true if compilation
+ was successful, false otherwise. The compilation errors
+ and warnings will be made available via log().
+
+ This function is intended to be a short-cut for quickly
+ adding vertex and fragment shaders to a shader program without
+ creating an instance of QGLShader first.
+
+ \sa removeShader(), link(), log(), removeAllShaders()
+*/
+bool QGLShaderProgram::addShader(QGLShader::ShaderType type, const char *source)
+{
+ if (!init())
+ return false;
+ QGLShader *shader = new QGLShader(type, this);
+ if (!shader->setSourceCode(source)) {
+ d->log = shader->log();
+ delete shader;
+ return false;
+ }
+ d->anonShaders.append(shader);
+ return addShader(shader);
+}
+
+/*!
+ \overload
+
+ Compiles \a source as a shader of the specified \a type and
+ adds it to this shader program. Returns true if compilation
+ was successful, false otherwise. The compilation errors
+ and warnings will be made available via log().
+
+ This function is intended to be a short-cut for quickly
+ adding vertex and fragment shaders to a shader program without
+ creating an instance of QGLShader first.
+
+ \sa removeShader(), link(), log(), removeAllShaders()
+*/
+bool QGLShaderProgram::addShader(QGLShader::ShaderType type, const QByteArray& source)
+{
+ return addShader(type, source.constData());
+}
+
+/*!
+ \overload
+
+ Compiles \a source as a shader of the specified \a type and
+ adds it to this shader program. Returns true if compilation
+ was successful, false otherwise. The compilation errors
+ and warnings will be made available via log().
+
+ This function is intended to be a short-cut for quickly
+ adding vertex and fragment shaders to a shader program without
+ creating an instance of QGLShader first.
+
+ \sa removeShader(), link(), log(), removeAllShaders()
+*/
+bool QGLShaderProgram::addShader(QGLShader::ShaderType type, const QString& source)
+{
+ return addShader(type, source.toLatin1().constData());
+}
+
+/*!
+ Removes \a shader from this shader program. The object is not deleted.
+
+ \sa addShader(), link(), removeAllShaders()
+*/
+void QGLShaderProgram::removeShader(QGLShader *shader)
+{
+ if (d->program && shader && shader->d->shader) {
+ glDetachShader(d->program, shader->d->shader);
+ d->linked = false; // Program needs to be relinked.
+ }
+ d->shaders.removeAll(shader);
+ d->anonShaders.removeAll(shader);
+}
+
+/*!
+ Returns a list of all shaders that have been added to this shader
+ program using addShader().
+
+ \sa addShader(), removeShader()
+*/
+QList<QGLShader *> QGLShaderProgram::shaders() const
+{
+ return d->shaders;
+}
+
+/*!
+ Removes all of the shaders that were added to this program previously.
+ The QGLShader objects for the shaders will not be deleted if they
+ were constructed externally. QGLShader objects that are constructed
+ internally by QGLShaderProgram will be deleted.
+
+ \sa addShader(), removeShader()
+*/
+void QGLShaderProgram::removeAllShaders()
+{
+ foreach (QGLShader *shader, d->shaders) {
+ if (d->program && shader && shader->d->shader)
+ glDetachShader(d->program, shader->d->shader);
+ }
+ foreach (QGLShader *shader, d->anonShaders) {
+ // Delete shader objects that were created anonymously.
+ delete shader;
+ }
+ d->shaders.clear();
+ d->anonShaders.clear();
+ d->linked = false; // Program needs to be relinked.
+}
+
+#if defined(QT_OPENGL_ES_2)
+
+#ifndef GL_PROGRAM_BINARY_LENGTH_OES
+#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741
+#endif
+#ifndef GL_NUM_PROGRAM_BINARY_FORMATS_OES
+#define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE
+#endif
+#ifndef GL_PROGRAM_BINARY_FORMATS_OES
+#define GL_PROGRAM_BINARY_FORMATS_OES 0x87FF
+#endif
+
+#endif
+
+/*!
+ Returns the program binary associated with this shader program.
+ The numeric identifier of the program binary format is returned
+ in \a format. The \c OES_get_program_binary extension will need
+ to be supported by the system for binary retrieval to succeed.
+
+ Returns an empty QByteArray if the program binary cannot be
+ retrieved on this system, or the shader program has not yet
+ been linked.
+
+ The returned binary can be supplied to setProgramBinary() on the
+ same machine at some future point to reload the program. It contains
+ the compiled code of all of the shaders that were attached to the
+ program at the time programBinary() is called.
+
+ \sa setProgramBinary(), programBinaryFormats()
+*/
+QByteArray QGLShaderProgram::programBinary(int *format) const
+{
+#if defined(QT_OPENGL_ES_2)
+ if (!isLinked())
+ return QByteArray();
+
+ // Get the length of the binary data, bailing out if there is none.
+ GLint length = 0;
+ glGetProgramiv(d->program, GL_PROGRAM_BINARY_LENGTH_OES, &length);
+ if (length <= 0)
+ return QByteArray();
+
+ // Retrieve the binary data.
+ QByteArray binary(length, 0);
+ GLenum binaryFormat;
+ glGetProgramBinaryOES(d->program, length, 0, &binaryFormat, binary.data());
+ if (format)
+ *format = (int)binaryFormat;
+ return binary;
+#else
+ Q_UNUSED(format);
+ return QByteArray();
+#endif
+}
+
+/*!
+ Sets the \a binary for this shader program according to \a format.
+ Returns true if the binary was set, or false if the binary format
+ is not supported or this system does not support program binaries.
+ The program will be linked if the load succeeds.
+
+ \sa programBinary(), programBinaryFormats(), isLinked()
+*/
+bool QGLShaderProgram::setProgramBinary(int format, const QByteArray& binary)
+{
+#if defined(QT_OPENGL_ES_2)
+ // Load the binary and check that it was linked correctly.
+ glProgramBinaryOES(d->program, (GLenum)format,
+ binary.constData(), binary.size());
+ GLint value = 0;
+ glGetProgramiv(d->program, GL_LINK_STATUS, &value);
+ d->linked = (value != 0);
+ value = 0;
+ glGetProgramiv(d->program, GL_INFO_LOG_LENGTH, &value);
+ d->log = QString();
+ if (value > 1) {
+ char *logbuf = new char [value];
+ GLint len;
+ glGetProgramInfoLog(d->program, value, &len, logbuf);
+ d->log = QString::fromLatin1(logbuf);
+ qWarning() << "QGLShaderProgram::setProgramBinary:" << d->log;
+ delete [] logbuf;
+ }
+ return d->linked;
+#else
+ Q_UNUSED(format);
+ Q_UNUSED(binary);
+ return false;
+#endif
+}
+
+/*!
+ Returns the list of program binary formats that are accepted by
+ this system for use with setProgramBinary().
+
+ \sa programBinary(), setProgramBinary()
+*/
+QList<int> QGLShaderProgram::programBinaryFormats()
+{
+#if defined(QT_OPENGL_ES_2)
+ GLint count = 0;
+ glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS_OES, &count);
+ if (count <= 0)
+ return QList<int>();
+ QVector<int> list;
+ list.resize(count);
+ glGetIntegerv(GL_PROGRAM_BINARY_FORMATS_OES, list.data());
+ return list.toList();
+#else
+ return QList<int>();
+#endif
+}
+
+/*!
+ Links together the shaders that were added to this program with
+ addShader(). Returns true if the link was successful or
+ false otherwise. If the link failed, the error messages can
+ be retrieved with log().
+
+ Subclasses can override this function to initialize attributes
+ and uniform variables for use in specific shader programs.
+
+ If the shader program was already linked, calling this
+ function again will force it to be re-linked.
+
+ \sa addShader(), log()
+*/
+bool QGLShaderProgram::link()
+{
+ if (!d->program)
+ return false;
+ if (d->hasPartialShaders) {
+ // Compile the partial vertex and fragment shaders.
+ QByteArray vertexSource;
+ QByteArray fragmentSource;
+ foreach (QGLShader *shader, d->shaders) {
+ if (shader->shaderType() == QGLShader::PartialVertexShader)
+ vertexSource += shader->sourceCode();
+ else if (shader->shaderType() == QGLShader::PartialFragmentShader)
+ fragmentSource += shader->sourceCode();
+ }
+ if (vertexSource.isEmpty()) {
+ if (d->vertexShader) {
+ glDetachShader(d->program, d->vertexShader->d->shader);
+ delete d->vertexShader;
+ d->vertexShader = 0;
+ }
+ } else {
+ if (!d->vertexShader) {
+ d->vertexShader =
+ new QGLShader(QGLShader::VertexShader, this);
+ }
+ if (!d->vertexShader->setSourceCode(vertexSource)) {
+ d->log = d->vertexShader->log();
+ return false;
+ }
+ glAttachShader(d->program, d->vertexShader->d->shader);
+ }
+ if (fragmentSource.isEmpty()) {
+ if (d->fragmentShader) {
+ glDetachShader(d->program, d->fragmentShader->d->shader);
+ delete d->fragmentShader;
+ d->fragmentShader = 0;
+ }
+ } else {
+ if (!d->fragmentShader) {
+ d->fragmentShader =
+ new QGLShader(QGLShader::FragmentShader, this);
+ }
+ if (!d->fragmentShader->setSourceCode(fragmentSource)) {
+ d->log = d->fragmentShader->log();
+ return false;
+ }
+ glAttachShader(d->program, d->fragmentShader->d->shader);
+ }
+ }
+ glLinkProgram(d->program);
+ GLint value = 0;
+ glGetProgramiv(d->program, GL_LINK_STATUS, &value);
+ d->linked = (value != 0);
+ value = 0;
+ glGetProgramiv(d->program, GL_INFO_LOG_LENGTH, &value);
+ d->log = QString();
+ if (value > 1) {
+ char *logbuf = new char [value];
+ GLint len;
+ glGetProgramInfoLog(d->program, value, &len, logbuf);
+ d->log = QString::fromLatin1(logbuf);
+ qWarning() << "QGLShaderProgram::link:" << d->log;
+ delete [] logbuf;
+ }
+ return d->linked;
+}
+
+/*!
+ Returns true if this shader program has been linked; false otherwise.
+
+ \sa link()
+*/
+bool QGLShaderProgram::isLinked() const
+{
+ return d->linked;
+}
+
+/*!
+ Returns the errors and warnings that occurred during the last link()
+ or addShader() with explicitly specified source code.
+
+ \sa link()
+*/
+QString QGLShaderProgram::log() const
+{
+ return d->log;
+}
+
+/*!
+ Enable use of this shader program in the currently active QGLContext.
+ Returns true if the program was successfully enabled; false
+ otherwise. If the shader program has not yet been linked,
+ or it needs to be re-linked, this function will call link().
+
+ \sa link(), disable()
+*/
+bool QGLShaderProgram::enable()
+{
+ if (!d->program)
+ return false;
+ if (!d->linked && !link())
+ return false;
+ glUseProgram(d->program);
+ return true;
+}
+
+#undef ctx
+#define ctx QGLContext::currentContext()
+
+/*!
+ Disables the active shader program in the current QGLContext.
+ This is equivalent to calling \c{glUseProgram(0)}.
+
+ \sa enable()
+*/
+void QGLShaderProgram::disable()
+{
+#if defined(QT_OPENGL_ES_2)
+ glUseProgram(0);
+#else
+ if (glUseProgram)
+ glUseProgram(0);
+#endif
+}
+
+#undef ctx
+#define ctx d->context
+
+/*!
+ Returns the OpenGL identifier associated with this shader program.
+
+ \sa QGLShader::shaderId()
+*/
+GLuint QGLShaderProgram::programId() const
+{
+ return d->program;
+}
+
+/*!
+ Binds the attribute \a name to the specified \a location. This
+ function can be called before or after the program has been linked.
+ Any attributes that have not been explicitly bound when the program
+ is linked will be assigned locations automatically.
+
+ \sa attributeLocation()
+*/
+void QGLShaderProgram::bindAttributeLocation(const char *name, int location)
+{
+ glBindAttribLocation(d->program, location, name);
+}
+
+/*!
+ \overload
+
+ Binds the attribute \a name to the specified \a location. This
+ function can be called before or after the program has been linked.
+ Any attributes that have not been explicitly bound when the program
+ is linked will be assigned locations automatically.
+
+ \sa attributeLocation()
+*/
+void QGLShaderProgram::bindAttributeLocation(const QByteArray& name, int location)
+{
+ glBindAttribLocation(d->program, location, name.constData());
+}
+
+/*!
+ \overload
+
+ Binds the attribute \a name to the specified \a location. This
+ function can be called before or after the program has been linked.
+ Any attributes that have not been explicitly bound when the program
+ is linked will be assigned locations automatically.
+
+ \sa attributeLocation()
+*/
+void QGLShaderProgram::bindAttributeLocation(const QString& name, int location)
+{
+ glBindAttribLocation(d->program, location, name.toLatin1().constData());
+}
+
+/*!
+ Returns the location of the attribute \a name within this shader
+ program's parameter list. Returns -1 if \a name is not a valid
+ attribute for this shader program.
+
+ \sa uniformLocation(), bindAttributeLocation()
+*/
+int QGLShaderProgram::attributeLocation(const char *name) const
+{
+ if (d->linked) {
+ return glGetAttribLocation(d->program, name);
+ } else {
+ qWarning() << "QGLShaderProgram::attributeLocation(" << name
+ << "): shader program is not linked";
+ return -1;
+ }
+}
+
+/*!
+ \overload
+
+ Returns the location of the attribute \a name within this shader
+ program's parameter list. Returns -1 if \a name is not a valid
+ attribute for this shader program.
+
+ \sa uniformLocation(), bindAttributeLocation()
+*/
+int QGLShaderProgram::attributeLocation(const QByteArray& name) const
+{
+ return attributeLocation(name.constData());
+}
+
+/*!
+ \overload
+
+ Returns the location of the attribute \a name within this shader
+ program's parameter list. Returns -1 if \a name is not a valid
+ attribute for this shader program.
+
+ \sa uniformLocation(), bindAttributeLocation()
+*/
+int QGLShaderProgram::attributeLocation(const QString& name) const
+{
+ return attributeLocation(name.toLatin1().constData());
+}
+
+/*!
+ Sets the attribute at \a location in the current context to \a value.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(int location, GLfloat value)
+{
+ if (location != -1)
+ glVertexAttrib1fv(location, &value);
+}
+
+/*!
+ \overload
+
+ Sets the attribute called \a name in the current context to \a value.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(const char *name, GLfloat value)
+{
+ setAttributeValue(attributeLocation(name), value);
+}
+
+/*!
+ Sets the attribute at \a location in the current context to
+ the 2D vector (\a x, \a y).
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(int location, GLfloat x, GLfloat y)
+{
+ if (location != -1) {
+ GLfloat values[2] = {x, y};
+ glVertexAttrib2fv(location, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the attribute called \a name in the current context to
+ the 2D vector (\a x, \a y).
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(const char *name, GLfloat x, GLfloat y)
+{
+ setAttributeValue(attributeLocation(name), x, y);
+}
+
+/*!
+ Sets the attribute at \a location in the current context to
+ the 3D vector (\a x, \a y, \a z).
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue
+ (int location, GLfloat x, GLfloat y, GLfloat z)
+{
+ if (location != -1) {
+ GLfloat values[3] = {x, y, z};
+ glVertexAttrib3fv(location, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the attribute called \a name in the current context to
+ the 3D vector (\a x, \a y, \a z).
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue
+ (const char *name, GLfloat x, GLfloat y, GLfloat z)
+{
+ setAttributeValue(attributeLocation(name), x, y, z);
+}
+
+/*!
+ Sets the attribute at \a location in the current context to
+ the 4D vector (\a x, \a y, \a z, \a w).
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue
+ (int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ if (location != -1) {
+ GLfloat values[4] = {x, y, z, w};
+ glVertexAttrib4fv(location, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the attribute called \a name in the current context to
+ the 4D vector (\a x, \a y, \a z, \a w).
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue
+ (const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ setAttributeValue(attributeLocation(name), x, y, z, w);
+}
+
+/*!
+ Sets the attribute at \a location in the current context to \a value.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(int location, const QVector2D& value)
+{
+ if (location != -1)
+ glVertexAttrib2fv(location, reinterpret_cast<const GLfloat *>(&value));
+}
+
+/*!
+ \overload
+
+ Sets the attribute called \a name in the current context to \a value.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(const char *name, const QVector2D& value)
+{
+ setAttributeValue(attributeLocation(name), value);
+}
+
+/*!
+ Sets the attribute at \a location in the current context to \a value.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(int location, const QVector3D& value)
+{
+ if (location != -1)
+ glVertexAttrib3fv(location, reinterpret_cast<const GLfloat *>(&value));
+}
+
+/*!
+ \overload
+
+ Sets the attribute called \a name in the current context to \a value.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(const char *name, const QVector3D& value)
+{
+ setAttributeValue(attributeLocation(name), value);
+}
+
+/*!
+ Sets the attribute at \a location in the current context to \a value.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(int location, const QVector4D& value)
+{
+ if (location != -1)
+ glVertexAttrib4fv(location, reinterpret_cast<const GLfloat *>(&value));
+}
+
+/*!
+ \overload
+
+ Sets the attribute called \a name in the current context to \a value.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(const char *name, const QVector4D& value)
+{
+ setAttributeValue(attributeLocation(name), value);
+}
+
+/*!
+ Sets the attribute at \a location in the current context to \a value.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(int location, const QColor& value)
+{
+ if (location != -1) {
+ GLfloat values[4] = {value.redF(), value.greenF(), value.blueF(), value.alphaF()};
+ glVertexAttrib4fv(location, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the attribute called \a name in the current context to \a value.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue(const char *name, const QColor& value)
+{
+ setAttributeValue(attributeLocation(name), value);
+}
+
+/*!
+ Sets the attribute at \a location in the current context to the
+ contents of \a values, which contains \a columns elements, each
+ consisting of \a rows elements. The \a rows value should be
+ 1, 2, 3, or 4. This function is typically used to set matrix
+ values and column vectors.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue
+ (int location, const GLfloat *values, int columns, int rows)
+{
+ if (rows < 1 || rows > 4) {
+ qWarning() << "QGLShaderProgram::setAttributeValue: rows" << rows << "not supported";
+ return;
+ }
+ if (location != -1) {
+ while (columns-- > 0) {
+ if (rows == 1)
+ glVertexAttrib1fv(location, values);
+ else if (rows == 2)
+ glVertexAttrib2fv(location, values);
+ else if (rows == 3)
+ glVertexAttrib3fv(location, values);
+ else
+ glVertexAttrib4fv(location, values);
+ values += rows;
+ ++location;
+ }
+ }
+}
+
+/*!
+ \overload
+
+ Sets the attribute called \a name in the current context to the
+ contents of \a values, which contains \a columns elements, each
+ consisting of \a rows elements. The \a rows value should be
+ 1, 2, 3, or 4. This function is typically used to set matrix
+ values and column vectors.
+
+ \sa setUniformValue()
+*/
+void QGLShaderProgram::setAttributeValue
+ (const char *name, const GLfloat *values, int columns, int rows)
+{
+ setAttributeValue(attributeLocation(name), values, columns, rows);
+}
+
+/*!
+ Sets an array of vertex \a values on the attribute at \a location
+ in this shader program. The \a size indicates the number of
+ components per vertex (1, 2, 3, or 4), and the \a stride indicates
+ the number of bytes between vertices. A default \a stride value
+ of zero indicates that the vertices are densely packed in \a values.
+
+ \sa setAttributeValue(), setUniformValue(), disableAttributeArray()
+*/
+void QGLShaderProgram::setAttributeArray
+ (int location, const GLfloat *values, int size, int stride)
+{
+ if (location != -1) {
+ glVertexAttribPointer(location, size, GL_FLOAT, GL_FALSE,
+ stride, values);
+ glEnableVertexAttribArray(location);
+ }
+}
+
+/*!
+ Sets an array of 2D vertex \a values on the attribute at \a location
+ in this shader program. The \a stride indicates the number of bytes
+ between vertices. A default \a stride value of zero indicates that
+ the vertices are densely packed in \a values.
+
+ \sa setAttributeValue(), setUniformValue(), disableAttributeArray()
+*/
+void QGLShaderProgram::setAttributeArray
+ (int location, const QVector2D *values, int stride)
+{
+ if (location != -1) {
+ glVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE,
+ stride, values);
+ glEnableVertexAttribArray(location);
+ }
+}
+
+/*!
+ Sets an array of 3D vertex \a values on the attribute at \a location
+ in this shader program. The \a stride indicates the number of bytes
+ between vertices. A default \a stride value of zero indicates that
+ the vertices are densely packed in \a values.
+
+ \sa setAttributeValue(), setUniformValue(), disableAttributeArray()
+*/
+void QGLShaderProgram::setAttributeArray
+ (int location, const QVector3D *values, int stride)
+{
+ if (location != -1) {
+ glVertexAttribPointer(location, 3, GL_FLOAT, GL_FALSE,
+ stride, values);
+ glEnableVertexAttribArray(location);
+ }
+}
+
+/*!
+ Sets an array of 4D vertex \a values on the attribute at \a location
+ in this shader program. The \a stride indicates the number of bytes
+ between vertices. A default \a stride value of zero indicates that
+ the vertices are densely packed in \a values.
+
+ \sa setAttributeValue(), setUniformValue(), disableAttributeArray()
+*/
+void QGLShaderProgram::setAttributeArray
+ (int location, const QVector4D *values, int stride)
+{
+ if (location != -1) {
+ glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE,
+ stride, values);
+ glEnableVertexAttribArray(location);
+ }
+}
+
+/*!
+ \overload
+
+ Sets an array of vertex \a values on the attribute called \a name
+ in this shader program. The \a size indicates the number of
+ components per vertex (1, 2, 3, or 4), and the \a stride indicates
+ the number of bytes between vertices. A default \a stride value
+ of zero indicates that the vertices are densely packed in \a values.
+
+ \sa setAttributeValue(), setUniformValue(), disableAttributeArray()
+*/
+void QGLShaderProgram::setAttributeArray
+ (const char *name, const GLfloat *values, int size, int stride)
+{
+ setAttributeArray(attributeLocation(name), values, size, stride);
+}
+
+/*!
+ \overload
+
+ Sets an array of 2D vertex \a values on the attribute called \a name
+ in this shader program. The \a stride indicates the number of bytes
+ between vertices. A default \a stride value of zero indicates that
+ the vertices are densely packed in \a values.
+
+ \sa setAttributeValue(), setUniformValue(), disableAttributeArray()
+*/
+void QGLShaderProgram::setAttributeArray
+ (const char *name, const QVector2D *values, int stride)
+{
+ setAttributeArray(attributeLocation(name), values, stride);
+}
+
+/*!
+ \overload
+
+ Sets an array of 3D vertex \a values on the attribute called \a name
+ in this shader program. The \a stride indicates the number of bytes
+ between vertices. A default \a stride value of zero indicates that
+ the vertices are densely packed in \a values.
+
+ \sa setAttributeValue(), setUniformValue(), disableAttributeArray()
+*/
+void QGLShaderProgram::setAttributeArray
+ (const char *name, const QVector3D *values, int stride)
+{
+ setAttributeArray(attributeLocation(name), values, stride);
+}
+
+/*!
+ \overload
+
+ Sets an array of 4D vertex \a values on the attribute called \a name
+ in this shader program. The \a stride indicates the number of bytes
+ between vertices. A default \a stride value of zero indicates that
+ the vertices are densely packed in \a values.
+
+ \sa setAttributeValue(), setUniformValue(), disableAttributeArray()
+*/
+void QGLShaderProgram::setAttributeArray
+ (const char *name, const QVector4D *values, int stride)
+{
+ setAttributeArray(attributeLocation(name), values, stride);
+}
+
+/*!
+ Disables the vertex array at \a location in this shader program
+ that was enabled by a previous call to setAttributeArray().
+
+ \sa setAttributeArray(), setAttributeValue(), setUniformValue()
+*/
+void QGLShaderProgram::disableAttributeArray(int location)
+{
+ if (location != -1)
+ glDisableVertexAttribArray(location);
+}
+
+/*!
+ \overload
+
+ Disables the vertex array called \a name in this shader program
+ that was enabled by a previous call to setAttributeArray().
+
+ \sa setAttributeArray(), setAttributeValue(), setUniformValue()
+*/
+void QGLShaderProgram::disableAttributeArray(const char *name)
+{
+ disableAttributeArray(attributeLocation(name));
+}
+
+/*!
+ Returns the location of the uniform variable \a name within this shader
+ program's parameter list. Returns -1 if \a name is not a valid
+ uniform variable for this shader program.
+
+ \sa attributeLocation()
+*/
+int QGLShaderProgram::uniformLocation(const char *name) const
+{
+ if (d->linked) {
+ return glGetUniformLocation(d->program, name);
+ } else {
+ qWarning() << "QGLShaderProgram::uniformLocation(" << name
+ << "): shader program is not linked";
+ return -1;
+ }
+}
+
+/*!
+ \overload
+
+ Returns the location of the uniform variable \a name within this shader
+ program's parameter list. Returns -1 if \a name is not a valid
+ uniform variable for this shader program.
+
+ \sa attributeLocation()
+*/
+int QGLShaderProgram::uniformLocation(const QByteArray& name) const
+{
+ return uniformLocation(name.constData());
+}
+
+/*!
+ \overload
+
+ Returns the location of the uniform variable \a name within this shader
+ program's parameter list. Returns -1 if \a name is not a valid
+ uniform variable for this shader program.
+
+ \sa attributeLocation()
+*/
+int QGLShaderProgram::uniformLocation(const QString& name) const
+{
+ return uniformLocation(name.toLatin1().constData());
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, GLfloat value)
+{
+ if (location != -1)
+ glUniform1fv(location, 1, &value);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, GLfloat value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, GLint value)
+{
+ if (location != -1)
+ glUniform1i(location, value);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, GLint value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to \a value.
+ This function should be used when setting sampler values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, GLuint value)
+{
+ if (location != -1)
+ glUniform1i(location, value);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to \a value. This function should be used when setting sampler values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, GLuint value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to
+ the 2D vector (\a x, \a y).
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, GLfloat x, GLfloat y)
+{
+ if (location != -1) {
+ GLfloat values[2] = {x, y};
+ glUniform2fv(location, 1, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context to
+ the 2D vector (\a x, \a y).
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, GLfloat x, GLfloat y)
+{
+ setUniformValue(uniformLocation(name), x, y);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to
+ the 3D vector (\a x, \a y, \a z).
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue
+ (int location, GLfloat x, GLfloat y, GLfloat z)
+{
+ if (location != -1) {
+ GLfloat values[3] = {x, y, z};
+ glUniform3fv(location, 1, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context to
+ the 3D vector (\a x, \a y, \a z).
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue
+ (const char *name, GLfloat x, GLfloat y, GLfloat z)
+{
+ setUniformValue(uniformLocation(name), x, y, z);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to
+ the 4D vector (\a x, \a y, \a z, \a w).
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue
+ (int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ if (location != -1) {
+ GLfloat values[4] = {x, y, z, w};
+ glUniform4fv(location, 1, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context to
+ the 4D vector (\a x, \a y, \a z, \a w).
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue
+ (const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ setUniformValue(uniformLocation(name), x, y, z, w);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QVector2D& value)
+{
+ if (location != -1)
+ glUniform2fv(location, 1, reinterpret_cast<const GLfloat *>(&value));
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QVector2D& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QVector3D& value)
+{
+ if (location != -1)
+ glUniform3fv(location, 1, reinterpret_cast<const GLfloat *>(&value));
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QVector3D& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QVector4D& value)
+{
+ if (location != -1)
+ glUniform4fv(location, 1, reinterpret_cast<const GLfloat *>(&value));
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QVector4D& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to
+ the red, green, blue, and alpha components of \a color.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QColor& color)
+{
+ if (location != -1) {
+ GLfloat values[4] = {color.redF(), color.greenF(), color.blueF(), color.alphaF()};
+ glUniform4fv(location, 1, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context to
+ the red, green, blue, and alpha components of \a color.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QColor& color)
+{
+ setUniformValue(uniformLocation(name), color);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to
+ the x and y coordinates of \a point.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QPoint& point)
+{
+ if (location != -1) {
+ GLfloat values[4] = {point.x(), point.y()};
+ glUniform2fv(location, 1, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable associated with \a name in the current
+ context to the x and y coordinates of \a point.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QPoint& point)
+{
+ setUniformValue(uniformLocation(name), point);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to
+ the x and y coordinates of \a point.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QPointF& point)
+{
+ if (location != -1) {
+ GLfloat values[4] = {point.x(), point.y()};
+ glUniform2fv(location, 1, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable associated with \a name in the current
+ context to the x and y coordinates of \a point.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QPointF& point)
+{
+ setUniformValue(uniformLocation(name), point);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to
+ the width and height of the given \a size.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QSize& size)
+{
+ if (location != -1) {
+ GLfloat values[4] = {size.width(), size.width()};
+ glUniform2fv(location, 1, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable associated with \a name in the current
+ context to the width and height of the given \a size.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QSize& size)
+{
+ setUniformValue(uniformLocation(name), size);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to
+ the width and height of the given \a size.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QSizeF& size)
+{
+ if (location != -1) {
+ GLfloat values[4] = {size.width(), size.height()};
+ glUniform2fv(location, 1, values);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable associated with \a name in the current
+ context to the width and height of the given \a size.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QSizeF& size)
+{
+ setUniformValue(uniformLocation(name), size);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context
+ to a 2x2 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QMatrix2x2& value)
+{
+ if (location != -1)
+ glUniformMatrix2fv(location, 1, GL_FALSE, value.data());
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to a 2x2 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x2& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context
+ to a 2x3 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QMatrix2x3& value)
+{
+#if !defined(QT_OPENGL_ES_2)
+ if (location != -1) {
+ if (glUniformMatrix2x3fv) {
+ // OpenGL 2.1+: pass the matrix directly.
+ glUniformMatrix2x3fv(location, 1, GL_FALSE, value.data());
+ } else {
+ // OpenGL 2.0: pass the matrix columns as a vector.
+ glUniform3fv(location, 2, value.data());
+ }
+ }
+#else
+ if (location != -1)
+ glUniform3fv(location, 2, value.data());
+#endif
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to a 2x3 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x3& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context
+ to a 2x4 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QMatrix2x4& value)
+{
+#if !defined(QT_OPENGL_ES_2)
+ if (location != -1) {
+ if (glUniformMatrix2x4fv) {
+ // OpenGL 2.1+: pass the matrix directly.
+ glUniformMatrix2x4fv(location, 1, GL_FALSE, value.data());
+ } else {
+ // OpenGL 2.0: pass the matrix columns as a vector.
+ glUniform4fv(location, 2, value.data());
+ }
+ }
+#else
+ if (location != -1)
+ glUniform4fv(location, 2, value.data());
+#endif
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to a 2x4 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x4& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context
+ to a 3x2 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QMatrix3x2& value)
+{
+#if !defined(QT_OPENGL_ES_2)
+ if (location != -1) {
+ if (glUniformMatrix3x2fv) {
+ // OpenGL 2.1+: pass the matrix directly.
+ glUniformMatrix3x2fv(location, 1, GL_FALSE, value.data());
+ } else {
+ // OpenGL 2.0: pass the matrix columns as a vector.
+ glUniform2fv(location, 3, value.data());
+ }
+ }
+#else
+ if (location != -1)
+ glUniform2fv(location, 3, value.data());
+#endif
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to a 3x2 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x2& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context
+ to a 3x3 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QMatrix3x3& value)
+{
+ if (location != -1)
+ glUniformMatrix3fv(location, 1, GL_FALSE, value.data());
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to a 3x3 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x3& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context
+ to a 3x4 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QMatrix3x4& value)
+{
+#if !defined(QT_OPENGL_ES_2)
+ if (location != -1) {
+ if (glUniformMatrix3x4fv) {
+ // OpenGL 2.1+: pass the matrix directly.
+ glUniformMatrix3x4fv(location, 1, GL_FALSE, value.data());
+ } else {
+ // OpenGL 2.0: pass the matrix columns as a vector.
+ glUniform4fv(location, 3, value.data());
+ }
+ }
+#else
+ if (location != -1)
+ glUniform4fv(location, 3, value.data());
+#endif
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to a 3x4 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x4& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context
+ to a 4x2 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QMatrix4x2& value)
+{
+#if !defined(QT_OPENGL_ES_2)
+ if (location != -1) {
+ if (glUniformMatrix4x2fv) {
+ // OpenGL 2.1+: pass the matrix directly.
+ glUniformMatrix4x2fv(location, 1, GL_FALSE, value.data());
+ } else {
+ // OpenGL 2.0: pass the matrix columns as a vector.
+ glUniform2fv(location, 4, value.data());
+ }
+ }
+#else
+ if (location != -1)
+ glUniform2fv(location, 4, value.data());
+#endif
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to a 4x2 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x2& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context
+ to a 4x3 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QMatrix4x3& value)
+{
+#if !defined(QT_OPENGL_ES_2)
+ if (location != -1) {
+ if (glUniformMatrix4x3fv) {
+ // OpenGL 2.1+: pass the matrix directly.
+ glUniformMatrix4x3fv(location, 1, GL_FALSE, value.data());
+ } else {
+ // OpenGL 2.0: pass the matrix columns as a vector.
+ glUniform3fv(location, 4, value.data());
+ }
+ }
+#else
+ if (location != -1)
+ glUniform3fv(location, 4, value.data());
+#endif
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to a 4x3 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x3& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context
+ to a 4x4 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const QMatrix4x4& value)
+{
+ if (location != -1)
+ glUniformMatrix4fv(location, 1, GL_FALSE, value.data());
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to a 4x4 matrix \a value.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x4& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable at \a location in the current context
+ to a 4x4 matrix \a value. The matrix elements must be specified
+ in column-major order.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(int location, const GLfloat value[4][4])
+{
+ if (location != -1)
+ glUniformMatrix4fv(location, 1, GL_FALSE, value[0]);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context
+ to a 4x4 matrix \a value. The matrix elements must be specified
+ in column-major order.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValue(const char *name, const GLfloat value[4][4])
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable at \a location in the current context to a
+ 3x3 transformation matrix \a value that is specified as a QTransform value.
+
+ To set a QTransform value as a 4x4 matrix in a shader, use
+ \c{setUniformValue(location, QMatrix4x4(value))}.
+*/
+void QGLShaderProgram::setUniformValue(int location, const QTransform& value)
+{
+ if (location != -1) {
+ GLfloat mat[3][3] = {
+ {value.m11(), value.m12(), value.m13()},
+ {value.m21(), value.m22(), value.m23()},
+ {value.m31(), value.m32(), value.m33()}
+ };
+ glUniformMatrix3fv(location, 1, GL_FALSE, mat[0]);
+ }
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable called \a name in the current context to a
+ 3x3 transformation matrix \a value that is specified as a QTransform value.
+
+ To set a QTransform value as a 4x4 matrix in a shader, use
+ \c{setUniformValue(name, QMatrix4x4(value))}.
+*/
+void QGLShaderProgram::setUniformValue
+ (const char *name, const QTransform& value)
+{
+ setUniformValue(uniformLocation(name), value);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const GLint *values, int count)
+{
+ if (location != -1)
+ glUniform1iv(location, count, values);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray
+ (const char *name, const GLint *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count elements of \a values. This overload
+ should be used when setting an array of sampler values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const GLuint *values, int count)
+{
+ if (location != -1)
+ glUniform1iv(location, count, reinterpret_cast<const GLint *>(values));
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count elements of \a values. This overload
+ should be used when setting an array of sampler values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray
+ (const char *name, const GLuint *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count elements of \a values. Each element
+ has \a size components. The \a size must be 1, 2, 3, or 4.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const GLfloat *values, int count, int size)
+{
+ if (location != -1) {
+ if (size == 1)
+ glUniform1fv(location, count, values);
+ else if (size == 2)
+ glUniform2fv(location, count, values);
+ else if (size == 3)
+ glUniform3fv(location, count, values);
+ else if (size == 4)
+ glUniform4fv(location, count, values);
+ else
+ qWarning() << "QGLShaderProgram::setUniformValue: size" << size << "not supported";
+ }
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count elements of \a values. Each element
+ has \a size components. The \a size must be 1, 2, 3, or 4.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray
+ (const char *name, const GLfloat *values, int count, int size)
+{
+ setUniformValueArray(uniformLocation(name), values, count, size);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 2D vector elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QVector2D *values, int count)
+{
+ if (location != -1)
+ glUniform2fv(location, count, reinterpret_cast<const GLfloat *>(values));
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 2D vector elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QVector2D *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 3D vector elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QVector3D *values, int count)
+{
+ if (location != -1)
+ glUniform3fv(location, count, reinterpret_cast<const GLfloat *>(values));
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 3D vector elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QVector3D *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 4D vector elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QVector4D *values, int count)
+{
+ if (location != -1)
+ glUniform4fv(location, count, reinterpret_cast<const GLfloat *>(values));
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 4D vector elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QVector4D *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+// We may have to repack matrix arrays if the matrix types
+// contain additional flag bits. Especially QMatrix4x4.
+#define setUniformMatrixArray(func,location,values,count,type,cols,rows) \
+ if (location == -1 || count <= 0) \
+ return; \
+ if (count == 1 || sizeof(type) == cols * rows * sizeof(GLfloat)) { \
+ func(location, count, GL_FALSE, values->constData()); \
+ } else { \
+ QVarLengthArray<GLfloat> temp(cols * rows * count); \
+ for (int index = 0; index < count; ++index) { \
+ qMemCopy(temp.data() + cols * rows * index, \
+ values[index].constData(), cols * rows * sizeof(GLfloat)); \
+ } \
+ func(location, count, GL_FALSE, temp.constData()); \
+ }
+#if !defined(QT_OPENGL_ES_2)
+#define setUniformGenericMatrixArray(func,colfunc,location,values,count,type,cols,rows) \
+ if (location == -1 || count <= 0) \
+ return; \
+ if (count == 1 || sizeof(type) == cols * rows * sizeof(GLfloat)) { \
+ if (func) \
+ func(location, count, GL_FALSE, values->constData()); \
+ else \
+ colfunc(location, cols * count, values->constData()); \
+ } else { \
+ QVarLengthArray<GLfloat> temp(cols * rows * count); \
+ for (int index = 0; index < count; ++index) { \
+ qMemCopy(temp.data() + cols * rows * index, \
+ values[index].constData(), cols * rows * sizeof(GLfloat)); \
+ } \
+ if (func) \
+ func(location, count, GL_FALSE, temp.constData()); \
+ else \
+ colfunc(location, count * cols, temp.constData()); \
+ }
+#else
+#define setUniformGenericMatrixArray(func,colfunc,location,values,count,type,cols,rows) \
+ if (location == -1 || count <= 0) \
+ return; \
+ if (count == 1 || sizeof(type) == cols * rows * sizeof(GLfloat)) { \
+ colfunc(location, cols * count, values->constData()); \
+ } else { \
+ QVarLengthArray<GLfloat> temp(cols * rows * count); \
+ for (int index = 0; index < count; ++index) { \
+ qMemCopy(temp.data() + cols * rows * index, \
+ values[index].constData(), cols * rows * sizeof(GLfloat)); \
+ } \
+ colfunc(location, count * cols, temp.constData()); \
+ }
+#endif
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 2x2 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x2 *values, int count)
+{
+ setUniformMatrixArray
+ (glUniformMatrix2fv, location, values, count, QMatrix2x2, 2, 2);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 2x2 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x2 *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 2x3 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x3 *values, int count)
+{
+ setUniformGenericMatrixArray
+ (glUniformMatrix2x3fv, glUniform3fv, location, values, count,
+ QMatrix2x3, 2, 3);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 2x3 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x3 *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 2x4 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x4 *values, int count)
+{
+ setUniformGenericMatrixArray
+ (glUniformMatrix2x4fv, glUniform4fv, location, values, count,
+ QMatrix2x4, 2, 4);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 2x4 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x4 *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 3x2 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x2 *values, int count)
+{
+ setUniformGenericMatrixArray
+ (glUniformMatrix3x2fv, glUniform2fv, location, values, count,
+ QMatrix3x2, 3, 2);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 3x2 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x2 *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 3x3 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x3 *values, int count)
+{
+ setUniformMatrixArray
+ (glUniformMatrix3fv, location, values, count, QMatrix3x3, 3, 3);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 3x3 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x3 *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 3x4 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x4 *values, int count)
+{
+ setUniformGenericMatrixArray
+ (glUniformMatrix3x4fv, glUniform4fv, location, values, count,
+ QMatrix3x4, 3, 4);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 3x4 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x4 *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 4x2 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x2 *values, int count)
+{
+ setUniformGenericMatrixArray
+ (glUniformMatrix4x2fv, glUniform2fv, location, values, count,
+ QMatrix4x2, 4, 2);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 4x2 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x2 *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 4x3 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x3 *values, int count)
+{
+ setUniformGenericMatrixArray
+ (glUniformMatrix4x3fv, glUniform3fv, location, values, count,
+ QMatrix4x3, 4, 3);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 4x3 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x3 *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Sets the uniform variable array at \a location in the current
+ context to the \a count 4x4 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x4 *values, int count)
+{
+ setUniformMatrixArray
+ (glUniformMatrix4fv, location, values, count, QMatrix4x4, 4, 4);
+}
+
+/*!
+ \overload
+
+ Sets the uniform variable array called \a name in the current
+ context to the \a count 4x4 matrix elements of \a values.
+
+ \sa setAttributeValue()
+*/
+void QGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x4 *values, int count)
+{
+ setUniformValueArray(uniformLocation(name), values, count);
+}
+
+/*!
+ Returns true if shader programs written in the OpenGL Shading
+ Language (GLSL) are supported on this system; false otherwise.
+
+ The \a context is used to resolve the GLSL extensions.
+ If \a context is null, then QGLContext::currentContext() is used.
+*/
+bool QGLShaderProgram::hasShaderPrograms(const QGLContext *context)
+{
+#if !defined(QT_OPENGL_ES_2)
+ if (!context)
+ context = QGLContext::currentContext();
+ if (!context)
+ return false;
+ return qt_resolve_glsl_extensions(const_cast<QGLContext *>(context));
+#else
+ Q_UNUSED(context);
+ return true;
+#endif
+}
+
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/opengl/qglshaderprogram.h b/src/opengl/qglshaderprogram.h
new file mode 100644
index 0000000..b69d28e
--- /dev/null
+++ b/src/opengl/qglshaderprogram.h
@@ -0,0 +1,297 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGLSHADERPROGRAM_H
+#define QGLSHADERPROGRAM_H
+
+#include <QtOpenGL/qgl.h>
+#include <QtGui/qvector2d.h>
+#include <QtGui/qvector3d.h>
+#include <QtGui/qvector4d.h>
+#include <QtGui/qmatrix4x4.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(OpenGL)
+
+#if !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
+
+class QGLShaderProgram;
+class QGLShaderPrivate;
+
+class Q_OPENGL_EXPORT QGLShader : public QObject
+{
+ Q_OBJECT
+public:
+ enum ShaderType
+ {
+ VertexShader,
+ FragmentShader,
+ PartialVertexShader,
+ PartialFragmentShader
+ };
+
+ explicit QGLShader(QGLShader::ShaderType type, QObject *parent = 0);
+ explicit QGLShader(const QString& fileName, QObject *parent = 0);
+ QGLShader(const QString& fileName, QGLShader::ShaderType type, QObject *parent = 0);
+ QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObject *parent = 0);
+ QGLShader(const QString& fileName, const QGLContext *context, QObject *parent = 0);
+ QGLShader(const QString& fileName, QGLShader::ShaderType type, const QGLContext *context, QObject *parent = 0);
+ virtual ~QGLShader();
+
+ bool isValid() const;
+
+ QGLShader::ShaderType shaderType() const;
+
+ bool setSourceCode(const char *source);
+ bool setSourceCode(const QByteArray& source);
+ bool setSourceCode(const QString& source);
+ bool setSourceCodeFile(const QString& fileName);
+
+ bool setBinaryCode(GLenum format, const void *binary, int length);
+ bool setBinaryCode(QGLShader& otherShader, GLenum format, const void *binary, int length);
+
+ static QList<GLenum> shaderBinaryFormats();
+
+ QByteArray sourceCode() const;
+
+ bool isCompiled() const;
+ QString log() const;
+
+ GLuint shaderId() const;
+
+private:
+ QGLShaderPrivate *d;
+
+ friend class QGLShaderProgram;
+
+ Q_DISABLE_COPY(QGLShader);
+};
+
+class QGLShaderProgramPrivate;
+
+class Q_OPENGL_EXPORT QGLShaderProgram : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QGLShaderProgram(QObject *parent = 0);
+ explicit QGLShaderProgram(const QGLContext *context, QObject *parent = 0);
+ virtual ~QGLShaderProgram();
+
+ bool isValid() const;
+
+ bool addShader(QGLShader *shader);
+ void removeShader(QGLShader *shader);
+ QList<QGLShader *> shaders() const;
+
+ bool addShader(QGLShader::ShaderType type, const char *source);
+ bool addShader(QGLShader::ShaderType type, const QByteArray& source);
+ bool addShader(QGLShader::ShaderType type, const QString& source);
+
+ void removeAllShaders();
+
+ QByteArray programBinary(int *format) const;
+ bool setProgramBinary(int format, const QByteArray& binary);
+ static QList<int> programBinaryFormats();
+
+ virtual bool link();
+ bool isLinked() const;
+ QString log() const;
+
+ bool enable();
+ static void disable();
+
+ GLuint programId() const;
+
+ void bindAttributeLocation(const char *name, int location);
+ void bindAttributeLocation(const QByteArray& name, int location);
+ void bindAttributeLocation(const QString& name, int location);
+
+ int attributeLocation(const char *name) const;
+ int attributeLocation(const QByteArray& name) const;
+ int attributeLocation(const QString& name) const;
+
+ void setAttributeValue(int location, GLfloat value);
+ void setAttributeValue(int location, GLfloat x, GLfloat y);
+ void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z);
+ void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+ void setAttributeValue(int location, const QVector2D& value);
+ void setAttributeValue(int location, const QVector3D& value);
+ void setAttributeValue(int location, const QVector4D& value);
+ void setAttributeValue(int location, const QColor& value);
+ void setAttributeValue(int location, const GLfloat *values, int columns, int rows);
+
+ void setAttributeValue(const char *name, GLfloat value);
+ void setAttributeValue(const char *name, GLfloat x, GLfloat y);
+ void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
+ void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+ void setAttributeValue(const char *name, const QVector2D& value);
+ void setAttributeValue(const char *name, const QVector3D& value);
+ void setAttributeValue(const char *name, const QVector4D& value);
+ void setAttributeValue(const char *name, const QColor& value);
+ void setAttributeValue(const char *name, const GLfloat *values, int columns, int rows);
+
+ void setAttributeArray
+ (int location, const GLfloat *values, int size, int stride = 0);
+ void setAttributeArray
+ (int location, const QVector2D *values, int stride = 0);
+ void setAttributeArray
+ (int location, const QVector3D *values, int stride = 0);
+ void setAttributeArray
+ (int location, const QVector4D *values, int stride = 0);
+ void setAttributeArray
+ (const char *name, const GLfloat *values, int size, int stride = 0);
+ void setAttributeArray
+ (const char *name, const QVector2D *values, int stride = 0);
+ void setAttributeArray
+ (const char *name, const QVector3D *values, int stride = 0);
+ void setAttributeArray
+ (const char *name, const QVector4D *values, int stride = 0);
+ void disableAttributeArray(int location);
+ void disableAttributeArray(const char *name);
+
+ int uniformLocation(const char *name) const;
+ int uniformLocation(const QByteArray& name) const;
+ int uniformLocation(const QString& name) const;
+
+ void setUniformValue(int location, GLfloat value);
+ void setUniformValue(int location, GLint value);
+ void setUniformValue(int location, GLuint value);
+ void setUniformValue(int location, GLfloat x, GLfloat y);
+ void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z);
+ void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+ void setUniformValue(int location, const QVector2D& value);
+ void setUniformValue(int location, const QVector3D& value);
+ void setUniformValue(int location, const QVector4D& value);
+ void setUniformValue(int location, const QColor& color);
+ void setUniformValue(int location, const QPoint& point);
+ void setUniformValue(int location, const QPointF& point);
+ void setUniformValue(int location, const QSize& size);
+ void setUniformValue(int location, const QSizeF& size);
+ void setUniformValue(int location, const QMatrix2x2& value);
+ void setUniformValue(int location, const QMatrix2x3& value);
+ void setUniformValue(int location, const QMatrix2x4& value);
+ void setUniformValue(int location, const QMatrix3x2& value);
+ void setUniformValue(int location, const QMatrix3x3& value);
+ void setUniformValue(int location, const QMatrix3x4& value);
+ void setUniformValue(int location, const QMatrix4x2& value);
+ void setUniformValue(int location, const QMatrix4x3& value);
+ void setUniformValue(int location, const QMatrix4x4& value);
+ void setUniformValue(int location, const GLfloat value[4][4]);
+ void setUniformValue(int location, const QTransform& value);
+
+ void setUniformValue(const char *name, GLfloat value);
+ void setUniformValue(const char *name, GLint value);
+ void setUniformValue(const char *name, GLuint value);
+ void setUniformValue(const char *name, GLfloat x, GLfloat y);
+ void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
+ void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+ void setUniformValue(const char *name, const QVector2D& value);
+ void setUniformValue(const char *name, const QVector3D& value);
+ void setUniformValue(const char *name, const QVector4D& value);
+ void setUniformValue(const char *name, const QColor& color);
+ void setUniformValue(const char *name, const QPoint& point);
+ void setUniformValue(const char *name, const QPointF& point);
+ void setUniformValue(const char *name, const QSize& size);
+ void setUniformValue(const char *name, const QSizeF& size);
+ void setUniformValue(const char *name, const QMatrix2x2& value);
+ void setUniformValue(const char *name, const QMatrix2x3& value);
+ void setUniformValue(const char *name, const QMatrix2x4& value);
+ void setUniformValue(const char *name, const QMatrix3x2& value);
+ void setUniformValue(const char *name, const QMatrix3x3& value);
+ void setUniformValue(const char *name, const QMatrix3x4& value);
+ void setUniformValue(const char *name, const QMatrix4x2& value);
+ void setUniformValue(const char *name, const QMatrix4x3& value);
+ void setUniformValue(const char *name, const QMatrix4x4& value);
+ void setUniformValue(const char *name, const GLfloat value[4][4]);
+ void setUniformValue(const char *name, const QTransform& value);
+
+ void setUniformValueArray(int location, const GLfloat *values, int count, int size);
+ void setUniformValueArray(int location, const GLint *values, int count);
+ void setUniformValueArray(int location, const GLuint *values, int count);
+ void setUniformValueArray(int location, const QVector2D *values, int count);
+ void setUniformValueArray(int location, const QVector3D *values, int count);
+ void setUniformValueArray(int location, const QVector4D *values, int count);
+ void setUniformValueArray(int location, const QMatrix2x2 *values, int count);
+ void setUniformValueArray(int location, const QMatrix2x3 *values, int count);
+ void setUniformValueArray(int location, const QMatrix2x4 *values, int count);
+ void setUniformValueArray(int location, const QMatrix3x2 *values, int count);
+ void setUniformValueArray(int location, const QMatrix3x3 *values, int count);
+ void setUniformValueArray(int location, const QMatrix3x4 *values, int count);
+ void setUniformValueArray(int location, const QMatrix4x2 *values, int count);
+ void setUniformValueArray(int location, const QMatrix4x3 *values, int count);
+ void setUniformValueArray(int location, const QMatrix4x4 *values, int count);
+
+ void setUniformValueArray(const char *name, const GLfloat *values, int count, int size);
+ void setUniformValueArray(const char *name, const GLint *values, int count);
+ void setUniformValueArray(const char *name, const GLuint *values, int count);
+ void setUniformValueArray(const char *name, const QVector2D *values, int count);
+ void setUniformValueArray(const char *name, const QVector3D *values, int count);
+ void setUniformValueArray(const char *name, const QVector4D *values, int count);
+ void setUniformValueArray(const char *name, const QMatrix2x2 *values, int count);
+ void setUniformValueArray(const char *name, const QMatrix2x3 *values, int count);
+ void setUniformValueArray(const char *name, const QMatrix2x4 *values, int count);
+ void setUniformValueArray(const char *name, const QMatrix3x2 *values, int count);
+ void setUniformValueArray(const char *name, const QMatrix3x3 *values, int count);
+ void setUniformValueArray(const char *name, const QMatrix3x4 *values, int count);
+ void setUniformValueArray(const char *name, const QMatrix4x2 *values, int count);
+ void setUniformValueArray(const char *name, const QMatrix4x3 *values, int count);
+ void setUniformValueArray(const char *name, const QMatrix4x4 *values, int count);
+
+ static bool hasShaderPrograms(const QGLContext *context = 0);
+
+private:
+ QGLShaderProgramPrivate *d;
+
+ Q_DISABLE_COPY(QGLShaderProgram);
+
+ bool init();
+};
+
+#endif
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp
index 4259a5c..6f7078a 100644
--- a/src/opengl/qpaintengine_opengl.cpp
+++ b/src/opengl/qpaintengine_opengl.cpp
@@ -57,13 +57,11 @@
#include "qpen.h"
#include "qvarlengtharray.h"
#include <private/qpainter_p.h>
-#include <qglpixelbuffer.h>
#include <private/qglpixelbuffer_p.h>
#include <private/qbezier_p.h>
#include <qglframebufferobject.h>
#include "private/qtessellator_p.h"
-#include "private/qwindowsurface_gl_p.h"
#include "util/fragmentprograms_p.h"
@@ -125,35 +123,6 @@ struct QT_PointF {
qreal y;
};
-void qt_add_rect_to_array(const QRectF &r, q_vertexType *array)
-{
- qreal left = r.left();
- qreal right = r.right();
- qreal top = r.top();
- qreal bottom = r.bottom();
-
- array[0] = f2vt(left);
- array[1] = f2vt(top);
- array[2] = f2vt(right);
- array[3] = f2vt(top);
- array[4] = f2vt(right);
- array[5] = f2vt(bottom);
- array[6] = f2vt(left);
- array[7] = f2vt(bottom);
-}
-
-void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, q_vertexType *array)
-{
- array[0] = f2vt(x1);
- array[1] = f2vt(y1);
- array[2] = f2vt(x2);
- array[3] = f2vt(y1);
- array[4] = f2vt(x2);
- array[5] = f2vt(y2);
- array[6] = f2vt(x1);
- array[7] = f2vt(y2);
-}
-
struct QGLTrapezoid
{
QGLTrapezoid()
@@ -190,180 +159,6 @@ const QGLTrapezoid QGLTrapezoid::translated(const QPointF &delta) const
return trap;
}
-class QGLDrawable {
-public:
- QGLDrawable() : widget(0), buffer(0), fbo(0)
- , wsurf(0)
- {}
- inline void setDevice(QPaintDevice *pdev);
- inline void swapBuffers();
- inline void makeCurrent();
- inline void doneCurrent();
- inline QSize size() const;
- inline QGLFormat format() const;
- inline GLuint bindTexture(const QImage &image, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA);
- inline GLuint bindTexture(const QPixmap &pixmap, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA);
- inline QColor backgroundColor() const;
- inline QGLContext *context() const;
- inline bool autoFillBackground() const;
-
-private:
- bool wasBound;
- QGLWidget *widget;
- QGLPixelBuffer *buffer;
- QGLFramebufferObject *fbo;
-#ifdef Q_WS_QWS
- QWSGLWindowSurface *wsurf;
-#else
- QGLWindowSurface *wsurf;
-#endif
-};
-
-void QGLDrawable::setDevice(QPaintDevice *pdev)
-{
- wasBound = false;
- widget = 0;
- buffer = 0;
- fbo = 0;
-#ifdef Q_WS_QWS
- wsurf = 0;
-#endif
- if (pdev->devType() == QInternal::Widget)
- widget = static_cast<QGLWidget *>(pdev);
- else if (pdev->devType() == QInternal::Pbuffer)
- buffer = static_cast<QGLPixelBuffer *>(pdev);
- else if (pdev->devType() == QInternal::FramebufferObject)
- fbo = static_cast<QGLFramebufferObject *>(pdev);
- else if (pdev->devType() == QInternal::UnknownDevice)
-#ifdef Q_WS_QWS
- wsurf = static_cast<QWSGLPaintDevice*>(pdev)->windowSurface();
-#else
- wsurf = static_cast<QGLWindowSurface *>(pdev);
-#endif
-}
-
-inline void QGLDrawable::swapBuffers()
-{
- if (widget) {
- if (widget->autoBufferSwap())
- widget->swapBuffers();
- } else {
- glFlush();
- }
-}
-
-inline void QGLDrawable::makeCurrent()
-{
- if (widget)
- widget->makeCurrent();
- else if (buffer)
- buffer->makeCurrent();
- else if (wsurf)
- wsurf->context()->makeCurrent();
- else if (fbo) {
- wasBound = fbo->isBound();
- if (!wasBound)
- fbo->bind();
- }
-}
-
-inline void QGLDrawable::doneCurrent()
-{
- if (fbo && !wasBound)
- fbo->release();
-}
-
-inline QSize QGLDrawable::size() const
-{
- if (widget) {
- return QSize(widget->d_func()->glcx->device()->width(),
- widget->d_func()->glcx->device()->height());
- } else if (buffer) {
- return buffer->size();
- } else if (fbo) {
- return fbo->size();
- } else if (wsurf) {
-#ifdef Q_WS_QWS
- return wsurf->window()->frameSize();
-#else
- return QSize(wsurf->width(), wsurf->height());
-#endif
- }
- return QSize();
-}
-
-inline QGLFormat QGLDrawable::format() const
-{
- if (widget)
- return widget->format();
- else if (buffer)
- return buffer->format();
- else if (wsurf)
- return wsurf->context()->format();
- else if (fbo && QGLContext::currentContext()) {
- QGLFormat fmt = QGLContext::currentContext()->format();
- fmt.setStencil(fbo->attachment() == QGLFramebufferObject::CombinedDepthStencil);
- fmt.setDepth(fbo->attachment() != QGLFramebufferObject::NoAttachment);
- return fmt;
- }
-
- return QGLFormat();
-}
-
-inline GLuint QGLDrawable::bindTexture(const QImage &image, GLenum target, GLint format)
-{
- if (widget)
- return widget->d_func()->glcx->d_func()->bindTexture(image, target, format, true);
- else if (buffer)
- return buffer->d_func()->qctx->d_func()->bindTexture(image, target, format, true);
- else if (fbo && QGLContext::currentContext())
- return const_cast<QGLContext *>(QGLContext::currentContext())->d_func()->bindTexture(image, target, format, true);
- else if (wsurf)
- return wsurf->context()->d_func()->bindTexture(image, target, format, true);
- return 0;
-}
-
-inline GLuint QGLDrawable::bindTexture(const QPixmap &pixmap, GLenum target, GLint format)
-{
- if (widget)
- return widget->d_func()->glcx->d_func()->bindTexture(pixmap, target, format, true);
- else if (buffer)
- return buffer->d_func()->qctx->d_func()->bindTexture(pixmap, target, format, true);
- else if (fbo && QGLContext::currentContext())
- return const_cast<QGLContext *>(QGLContext::currentContext())->d_func()->bindTexture(pixmap, target, format, true);
- else if (wsurf)
- return wsurf->context()->d_func()->bindTexture(pixmap, target, format, true);
- return 0;
-}
-
-inline QColor QGLDrawable::backgroundColor() const
-{
- if (widget)
- return widget->palette().brush(widget->backgroundRole()).color();
- return QApplication::palette().brush(QPalette::Background).color();
-}
-
-inline QGLContext *QGLDrawable::context() const
-{
- if (widget)
- return widget->d_func()->glcx;
- else if (buffer)
- return buffer->d_func()->qctx;
- else if (fbo)
- return const_cast<QGLContext *>(QGLContext::currentContext());
- else if (wsurf)
- return wsurf->context();
- return 0;
-}
-
-inline bool QGLDrawable::autoFillBackground() const
-{
- if (widget)
- return widget->autoFillBackground();
- else
- return false;
-}
-
class QOpenGLImmediateModeTessellator;
class QGLMaskGenerator;
@@ -2444,11 +2239,12 @@ void QOpenGLPaintEnginePrivate::updateDepthClip()
return;
}
-#ifndef QT_OPENGL_ES
- glClearDepth(0.0f);
-#else
+#if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_2) || defined(QT_OPENGL_ES_1_CL)
glClearDepthf(0.0f);
+#else
+ glClearDepth(0.0f);
#endif
+
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glClear(GL_DEPTH_BUFFER_BIT);
@@ -3284,6 +3080,9 @@ QGLTrapezoidMaskGenerator::QGLTrapezoidMaskGenerator(const QPainterPath &path, c
{
}
+extern void qt_add_rect_to_array(const QRectF &r, q_vertexType *array);
+extern void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, q_vertexType *array);
+
void QGLTrapezoidMaskGenerator::drawMask(const QRect &rect)
{
#ifdef QT_OPENGL_ES
@@ -5766,9 +5565,11 @@ void QOpenGLPaintEnginePrivate::ensureDrawableTexture()
QPixmapFilter *QOpenGLPaintEngine::createPixmapFilter(int type) const
{
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
if (QGLContext::currentContext())
return QGLContext::currentContext()->d_func()->createPixmapFilter(type);
else
+#endif
return 0;
}
diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp
index b079557..c89b99b 100644
--- a/src/opengl/qpixmapdata_gl.cpp
+++ b/src/opengl/qpixmapdata_gl.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "qpixmap.h"
+#include "qglframebufferobject.h"
#include <private/qpaintengine_raster_p.h>
@@ -48,6 +49,8 @@
#include <private/qgl_p.h>
#include <private/qdrawhelper_p.h>
+#include <private/qpaintengineex_opengl2_p.h>
+
QT_BEGIN_NAMESPACE
extern QGLWidget* qt_gl_share_widget();
@@ -57,12 +60,14 @@ class QGLShareContextScope
public:
QGLShareContextScope(const QGLContext *ctx)
: m_oldContext(0)
- , m_ctx(const_cast<QGLContext *>(ctx))
{
- const QGLContext *currentContext = QGLContext::currentContext();
+ QGLContext *currentContext = const_cast<QGLContext *>(QGLContext::currentContext());
if (currentContext != ctx && !qgl_share_reg()->checkSharing(ctx, currentContext)) {
- m_oldContext = const_cast<QGLContext *>(currentContext);
+ m_oldContext = currentContext;
+ m_ctx = const_cast<QGLContext *>(ctx);
m_ctx->makeCurrent();
+ } else {
+ m_ctx = currentContext;
}
}
@@ -87,47 +92,16 @@ private:
QGLContext *m_ctx;
};
-void qt_gl_convertFromGLImage(QImage *img)
-{
- const int w = img->width();
- const int h = img->height();
-
- if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
- uint *p = (uint*)img->bits();
- uint *end = p + w*h;
-
- while (p < end) {
- uint a = *p << 24;
- *p = (*p >> 8) | a;
- p++;
- }
-
- *img = img->mirrored();
- } else {
- // mirror image
- uint *data = (uint *)img->bits();
-
- const int mid = h/2;
-
- for (int y = 0; y < mid; ++y) {
- uint *p = data + y * w;
- uint *end = p + w;
- uint *q = data + (h - y - 1) * w;
-
- while (p < end)
- qSwap(*p++, *q++);
- }
- }
-}
-
-
static int qt_gl_pixmap_serial = 0;
QGLPixmapData::QGLPixmapData(PixelType type)
: QPixmapData(type, OpenGLClass)
, m_width(0)
, m_height(0)
- , m_texture(0)
+ , m_renderFbo(0)
+ , m_textureId(0)
+ , m_engine(0)
+ , m_ctx(0)
, m_dirty(false)
{
setSerialNumber(++qt_gl_pixmap_serial);
@@ -135,10 +109,11 @@ QGLPixmapData::QGLPixmapData(PixelType type)
QGLPixmapData::~QGLPixmapData()
{
- if (m_texture && qt_gl_share_widget()) {
- QGLShareContextScope ctx(qt_gl_share_widget()->context());
- glDeleteTextures(1, &m_texture);
- }
+ QGLWidget *shareWidget = qt_gl_share_widget();
+ if (!shareWidget)
+ return;
+ QGLShareContextScope ctx(shareWidget->context());
+ glDeleteTextures(1, &m_textureId);
}
bool QGLPixmapData::isValid() const
@@ -148,6 +123,9 @@ bool QGLPixmapData::isValid() const
bool QGLPixmapData::isValidContext(const QGLContext *ctx) const
{
+ if (ctx == m_ctx)
+ return true;
+
const QGLContext *share_ctx = qt_gl_share_widget()->context();
return ctx == share_ctx || qgl_share_reg()->checkSharing(ctx, share_ctx);
}
@@ -160,6 +138,12 @@ void QGLPixmapData::resize(int width, int height)
m_width = width;
m_height = height;
+ if (m_textureId) {
+ QGLShareContextScope ctx(qt_gl_share_widget()->context());
+ glDeleteTextures(1, &m_textureId);
+ m_textureId = 0;
+ }
+
m_source = QImage();
m_dirty = isValid();
setSerialNumber(++qt_gl_pixmap_serial);
@@ -173,28 +157,37 @@ void QGLPixmapData::ensureCreated() const
m_dirty = false;
QGLShareContextScope ctx(qt_gl_share_widget()->context());
+ m_ctx = ctx;
const GLenum format = qt_gl_preferredTextureFormat();
- const GLenum target = qt_gl_preferredTextureTarget();
-
- if (!m_texture)
- glGenTextures(1, &m_texture);
-
- glBindTexture(target, m_texture);
+ const GLenum target = GL_TEXTURE_2D;
+
+ if (!m_textureId) {
+ glGenTextures(1, &m_textureId);
+ glBindTexture(target, m_textureId);
+ glTexImage2D(target, 0, GL_RGBA, m_width, m_height, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ }
- if (m_source.isNull()) {
- glTexImage2D(target, 0, GL_RGBA, m_width, m_height, 0, format, GL_UNSIGNED_BYTE, 0);
- } else {
+ if (!m_source.isNull()) {
const QImage tx = ctx->d_func()->convertToGLFormat(m_source, true, format);
- glBindTexture(target, m_texture);
- glTexImage2D(target, 0, GL_RGBA, m_width, m_height, 0, format,
- GL_UNSIGNED_BYTE, tx.bits());
+ glBindTexture(target, m_textureId);
+ glTexSubImage2D(target, 0, 0, 0, m_width, m_height, format,
+ GL_UNSIGNED_BYTE, tx.bits());
- m_source = QImage();
+ if (useFramebufferObjects())
+ m_source = QImage();
}
}
+QGLFramebufferObject *QGLPixmapData::fbo() const
+{
+ return m_renderFbo;
+}
+
void QGLPixmapData::fromImage(const QImage &image,
Qt::ImageConversionFlags)
{
@@ -213,6 +206,17 @@ bool QGLPixmapData::scroll(int dx, int dy, const QRect &rect)
return false;
}
+void QGLPixmapData::copy(const QPixmapData *data, const QRect &rect)
+{
+ if (data->classId() != QPixmapData::OpenGLClass) {
+ QPixmapData::copy(data, rect);
+ return;
+ }
+
+ // can be optimized to do a framebuffer blit or similar ...
+ QPixmapData::copy(data, rect);
+}
+
void QGLPixmapData::fill(const QColor &color)
{
if (!isValid())
@@ -239,29 +243,108 @@ QImage QGLPixmapData::toImage() const
if (!isValid())
return QImage();
- if (!m_source.isNull())
+ if (m_renderFbo)
+ copyBackFromRenderFbo(true);
+ else if (!m_source.isNull())
return m_source;
else if (m_dirty)
return QImage(m_width, m_height, QImage::Format_ARGB32_Premultiplied);
+ else
+ ensureCreated();
+
+ QGLShareContextScope ctx(qt_gl_share_widget()->context());
+ extern QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha);
+ glBindTexture(GL_TEXTURE_2D, m_textureId);
+ return qt_gl_read_texture(QSize(m_width, m_height), true, true);
+}
+
+struct TextureBuffer
+{
+ QGLFramebufferObject *fbo;
+ QGL2PaintEngineEx *engine;
+};
+
+static QVector<TextureBuffer> textureBufferStack;
+static int currentTextureBuffer = 0;
+
+void QGLPixmapData::copyBackFromRenderFbo(bool keepCurrentFboBound) const
+{
+ if (!isValid())
+ return;
+
+ const QGLContext *share_ctx = qt_gl_share_widget()->context();
+ QGLShareContextScope ctx(share_ctx);
ensureCreated();
- QGLShareContextScope ctx(qt_gl_share_widget()->context());
- QImage img(m_width, m_height, QImage::Format_ARGB32_Premultiplied);
+ if (!ctx->d_ptr->fbo)
+ glGenFramebuffers(1, &ctx->d_ptr->fbo);
+
+ glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->fbo);
+ glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_TEXTURE_2D, m_textureId, 0);
+
+ const int x0 = 0;
+ const int x1 = m_width;
+ const int y0 = 0;
+ const int y1 = m_height;
+
+ glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, m_renderFbo->handle());
+
+ glDisable(GL_SCISSOR_TEST);
+
+ glBlitFramebufferEXT(x0, y0, x1, y1,
+ x0, y0, x1, y1,
+ GL_COLOR_BUFFER_BIT,
+ GL_NEAREST);
- GLenum format = qt_gl_preferredTextureFormat();
- GLenum target = qt_gl_preferredTextureTarget();
+ if (keepCurrentFboBound)
+ glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo);
+}
+
+void QGLPixmapData::swapBuffers()
+{
+ if (!isValid())
+ return;
- glBindTexture(target, m_texture);
-#ifndef QT_OPENGL_ES
- glGetTexImage(target, 0, format, GL_UNSIGNED_BYTE, img.bits());
-#else
- // XXX - cannot download textures this way on OpenGL/ES.
-#endif
+ copyBackFromRenderFbo(false);
+ m_renderFbo->release();
- qt_gl_convertFromGLImage(&img);
+ --currentTextureBuffer;
- return img;
+ m_renderFbo = 0;
+ m_engine = 0;
+}
+
+void QGLPixmapData::makeCurrent()
+{
+ if (isValid() && m_renderFbo)
+ m_renderFbo->bind();
+}
+
+void QGLPixmapData::doneCurrent()
+{
+ if (isValid() && m_renderFbo)
+ m_renderFbo->release();
+}
+
+static TextureBuffer createTextureBuffer(const QSize &size, QGL2PaintEngineEx *engine = 0)
+{
+ TextureBuffer buffer;
+ QGLFramebufferObjectFormat fmt;
+ fmt.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
+ fmt.setSamples(4);
+
+ buffer.fbo = new QGLFramebufferObject(size, fmt);
+ buffer.engine = engine ? engine : new QGL2PaintEngineEx;
+
+ return buffer;
+}
+
+bool QGLPixmapData::useFramebufferObjects()
+{
+ return QGLFramebufferObject::hasOpenGLFramebufferObjects()
+ && QGLFramebufferObject::hasOpenGLFramebufferBlit();
}
QPaintEngine* QGLPixmapData::paintEngine() const
@@ -269,23 +352,62 @@ QPaintEngine* QGLPixmapData::paintEngine() const
if (!isValid())
return 0;
- m_source = toImage();
- m_dirty = true;
+ if (m_engine)
+ return m_engine;
+ else if (!useFramebufferObjects()) {
+ m_dirty = true;
+
+ if (m_source.size() != size())
+ m_source = QImage(size(), QImage::Format_ARGB32_Premultiplied);
+ return m_source.paintEngine();
+ }
- return m_source.paintEngine();
+ extern QGLWidget* qt_gl_share_widget();
+
+ if (!QGLContext::currentContext())
+ qt_gl_share_widget()->makeCurrent();
+ QGLShareContextScope ctx(qt_gl_share_widget()->context());
+
+ if (textureBufferStack.size() <= currentTextureBuffer) {
+ textureBufferStack << createTextureBuffer(size());
+ } else {
+ QSize sz = textureBufferStack.at(currentTextureBuffer).fbo->size();
+ if (sz.width() < m_width || sz.height() < m_height) {
+ if (sz.width() < m_width)
+ sz.setWidth(qMax(m_width, qRound(sz.width() * 1.5)));
+ if (sz.height() < m_height)
+ sz.setHeight(qMax(m_height, qRound(sz.height() * 1.5)));
+ delete textureBufferStack.at(currentTextureBuffer).fbo;
+ textureBufferStack[currentTextureBuffer] =
+ createTextureBuffer(sz, textureBufferStack.at(currentTextureBuffer).engine);
+ qDebug() << "Creating new pixmap texture buffer:" << sz;
+ }
+ }
+
+ m_renderFbo = textureBufferStack.at(currentTextureBuffer).fbo;
+ m_engine = textureBufferStack.at(currentTextureBuffer).engine;
+
+ ++currentTextureBuffer;
+
+ return m_engine;
}
-GLuint QGLPixmapData::bind() const
+GLuint QGLPixmapData::bind(bool copyBack) const
{
- ensureCreated();
- glBindTexture(qt_gl_preferredTextureTarget(), m_texture);
- return m_texture;
+ if (m_renderFbo && copyBack)
+ copyBackFromRenderFbo(true);
+ else
+ ensureCreated();
+
+ GLuint id = m_textureId;
+ glBindTexture(GL_TEXTURE_2D, id);
+ return id;
}
GLuint QGLPixmapData::textureId() const
{
ensureCreated();
- return m_texture;
+ return m_textureId;
}
extern int qt_defaultDpiX();
diff --git a/src/opengl/qpixmapdata_gl_p.h b/src/opengl/qpixmapdata_gl_p.h
index e450f01..536f33d 100644
--- a/src/opengl/qpixmapdata_gl_p.h
+++ b/src/opengl/qpixmapdata_gl_p.h
@@ -60,6 +60,7 @@
QT_BEGIN_NAMESPACE
class QPaintEngine;
+class QGLFramebufferObject;
class QGLPixmapData : public QPixmapData
{
@@ -72,6 +73,7 @@ public:
void resize(int width, int height);
void fromImage(const QImage &image,
Qt::ImageConversionFlags flags);
+ void copy(const QPixmapData *data, const QRect &rect);
bool scroll(int dx, int dy, const QRect &rect);
@@ -80,13 +82,25 @@ public:
QImage toImage() const;
QPaintEngine* paintEngine() const;
- GLuint bind() const;
+ GLuint bind(bool copyBack = true) const;
GLuint textureId() const;
bool isValidContext(const QGLContext *ctx) const;
void ensureCreated() const;
+ bool isUninitialized() const { return m_dirty && m_source.isNull(); }
+
+ QSize size() const { return QSize(m_width, m_height); }
+ int width() const { return m_width; }
+ int height() const { return m_height; }
+
+ QGLFramebufferObject *fbo() const;
+
+ void makeCurrent();
+ void doneCurrent();
+ void swapBuffers();
+
protected:
int metric(QPaintDevice::PaintDeviceMetric metric) const;
@@ -94,10 +108,17 @@ private:
QGLPixmapData(const QGLPixmapData &other);
QGLPixmapData &operator=(const QGLPixmapData &other);
+ void copyBackFromRenderFbo(bool keepCurrentFboBound) const;
+
+ static bool useFramebufferObjects();
+
int m_width;
int m_height;
- mutable GLuint m_texture;
+ mutable QGLFramebufferObject *m_renderFbo;
+ mutable uint m_textureId;
+ mutable QPaintEngine *m_engine;
+ mutable QGLContext *m_ctx;
mutable bool m_dirty;
mutable QImage m_source;
};
diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp
index b41adf9..a3422b5 100644
--- a/src/opengl/qwindowsurface_gl.cpp
+++ b/src/opengl/qwindowsurface_gl.cpp
@@ -69,7 +69,8 @@
#include <private/qglpixelbuffer_p.h>
#include <private/qgraphicssystem_gl_p.h>
-#include <private/qpaintengine_opengl_p.h>
+
+#include <private/qpaintengineex_opengl2_p.h>
#ifndef GLX_ARB_multisample
#define GLX_SAMPLE_BUFFERS_ARB 100000
@@ -100,17 +101,19 @@ QGLGraphicsSystem::QGLGraphicsSystem()
int i = 0;
int spec[16];
spec[i++] = GLX_RGBA;
-#if 0
spec[i++] = GLX_DOUBLEBUFFER;
- spec[i++] = GLX_DEPTH_SIZE;
- spec[i++] = 8;
- spec[i++] = GLX_STENCIL_SIZE;
- spec[i++] = 8;
- spec[i++] = GLX_SAMPLE_BUFFERS_ARB;
- spec[i++] = 1;
- spec[i++] = GLX_SAMPLES_ARB;
- spec[i++] = 4;
-#endif
+
+ if (!qgetenv("QT_GL_SWAPBUFFER_PRESERVE").isNull()) {
+ spec[i++] = GLX_DEPTH_SIZE;
+ spec[i++] = 8;
+ spec[i++] = GLX_STENCIL_SIZE;
+ spec[i++] = 8;
+ spec[i++] = GLX_SAMPLE_BUFFERS_ARB;
+ spec[i++] = 1;
+ spec[i++] = GLX_SAMPLES_ARB;
+ spec[i++] = 4;
+ }
+
spec[i++] = XNone;
XVisualInfo *vi = glXChooseVisual(X11->display, X11->defaultScreen, spec);
@@ -187,9 +190,10 @@ public:
}
void cleanup() {
- delete widget;
- widget = 0;
+ QGLWidget *w = widget;
cleanedUp = true;
+ widget = 0;
+ delete w;
}
static bool cleanedUp;
@@ -227,6 +231,7 @@ struct QGLWindowSurfacePrivate
int tried_fbo : 1;
int tried_pb : 1;
+ int destructive_swap_buffers : 1;
QGLContext *ctx;
@@ -250,6 +255,7 @@ QGLWindowSurface::QGLWindowSurface(QWidget *window)
d_ptr->ctx = 0;
d_ptr->tried_fbo = false;
d_ptr->tried_pb = false;
+ d_ptr->destructive_swap_buffers = qgetenv("QT_GL_SWAPBUFFER_PRESERVE").isNull();
}
QGLWindowSurface::~QGLWindowSurface()
@@ -287,18 +293,12 @@ void QGLWindowSurface::hijackWindow(QWidget *widget)
qDebug() << "hijackWindow() context created for" << widget << d_ptr->contexts.size();
}
-#if !defined(QT_OPENGL_ES_2)
-Q_GLOBAL_STATIC(QOpenGLPaintEngine, qt_gl_window_surface_paintengine)
-#endif
+Q_GLOBAL_STATIC(QGL2PaintEngineEx, qt_gl_window_surface_2_engine)
/*! \reimp */
QPaintEngine *QGLWindowSurface::paintEngine() const
{
-#if !defined(QT_OPENGL_ES_2)
- return qt_gl_window_surface_paintengine();
-#else
- return 0;
-#endif
+ return qt_gl_window_surface_2_engine();
}
int QGLWindowSurface::metric(PaintDeviceMetric m) const
@@ -313,6 +313,8 @@ QGLContext *QGLWindowSurface::context() const
QPaintDevice *QGLWindowSurface::paintDevice()
{
+ updateGeometry();
+
if (d_ptr->pb)
return d_ptr->pb;
@@ -328,6 +330,7 @@ static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize,
void QGLWindowSurface::beginPaint(const QRegion &)
{
+ updateGeometry();
}
void QGLWindowSurface::endPaint(const QRegion &rgn)
@@ -343,6 +346,9 @@ void QGLWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &
QWidget *parent = widget->internalWinId() ? widget : widget->nativeParentWidget();
Q_ASSERT(parent);
+ if (!geometry().isValid())
+ return;
+
hijackWindow(parent);
QRect br = rgn.boundingRect().translated(offset);
@@ -350,52 +356,56 @@ void QGLWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &
QPoint wOffset = qt_qwidget_data(parent)->wrect.topLeft();
QRect rect = br.translated(-offset - wOffset);
- const GLenum target = qt_gl_preferredTextureTarget();
+ const GLenum target = GL_TEXTURE_2D;
if (context()) {
context()->makeCurrent();
if (context()->format().doubleBuffer()) {
- glBindTexture(target, d_ptr->tex_id);
+#if !defined(QT_OPENGL_ES_2)
+ if (d_ptr->destructive_swap_buffers) {
+ glBindTexture(target, d_ptr->tex_id);
- QVector<QRect> rects = d_ptr->paintedRegion.rects();
- for (int i = 0; i < rects.size(); ++i) {
- QRect br = rects.at(i);
- if (br.isEmpty())
- continue;
+ QVector<QRect> rects = d_ptr->paintedRegion.rects();
+ for (int i = 0; i < rects.size(); ++i) {
+ QRect br = rects.at(i);
+ if (br.isEmpty())
+ continue;
- const uint bottom = window()->height() - (br.y() + br.height());
- glCopyTexSubImage2D(target, 0, br.x(), bottom, br.x(), bottom, br.width(), br.height());
- }
+ const uint bottom = window()->height() - (br.y() + br.height());
+ glCopyTexSubImage2D(target, 0, br.x(), bottom, br.x(), bottom, br.width(), br.height());
+ }
- glBindTexture(target, 0);
+ glBindTexture(target, 0);
- QRegion dirtyRegion = QRegion(window()->rect()) - d_ptr->paintedRegion;
+ QRegion dirtyRegion = QRegion(window()->rect()) - d_ptr->paintedRegion;
- if (!dirtyRegion.isEmpty()) {
- context()->makeCurrent();
+ if (!dirtyRegion.isEmpty()) {
+ context()->makeCurrent();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
#ifndef QT_OPENGL_ES
- glOrtho(0, window()->width(), window()->height(), 0, -999999, 999999);
+ glOrtho(0, window()->width(), window()->height(), 0, -999999, 999999);
#else
- glOrthof(0, window()->width(), window()->height(), 0, -999999, 999999);
+ glOrthof(0, window()->width(), window()->height(), 0, -999999, 999999);
#endif
- glViewport(0, 0, window()->width(), window()->height());
+ glViewport(0, 0, window()->width(), window()->height());
- QVector<QRect> rects = dirtyRegion.rects();
- glColor4f(1, 1, 1, 1);
- for (int i = 0; i < rects.size(); ++i) {
- QRect rect = rects.at(i);
- if (rect.isEmpty())
- continue;
+ QVector<QRect> rects = dirtyRegion.rects();
+ glColor4f(1, 1, 1, 1);
+ for (int i = 0; i < rects.size(); ++i) {
+ QRect rect = rects.at(i);
+ if (rect.isEmpty())
+ continue;
- drawTexture(rect, d_ptr->tex_id, window()->size(), rect);
+ drawTexture(rect, d_ptr->tex_id, window()->size(), rect);
+ }
}
+#endif
}
d_ptr->paintedRegion = QRegion();
@@ -421,48 +431,75 @@ void QGLWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &
}
QSize size = widget->rect().size();
- if (ctx->format().doubleBuffer()) {
+ if (d_ptr->destructive_swap_buffers && ctx->format().doubleBuffer()) {
rect = parent->rect();
br = rect.translated(wOffset);
size = parent->size();
}
- ctx->makeCurrent();
+ glDisable(GL_SCISSOR_TEST);
+
+ if (d_ptr->fbo && QGLExtensions::glExtensions & QGLExtensions::FramebufferBlit) {
+ const int h = d_ptr->fbo->height();
+
+ const int x0 = rect.left();
+ const int x1 = rect.left() + rect.width();
+ const int y0 = h - (rect.top() + rect.height());
+ const int y1 = h - rect.top();
+
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0);
+
+ glBlitFramebufferEXT(x0, y0, x1, y1,
+ x0, y0, x1, y1,
+ GL_COLOR_BUFFER_BIT,
+ GL_NEAREST);
+
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, d_ptr->fbo->handle());
+ }
+#if !defined(QT_OPENGL_ES_2)
+ else {
+ glDisable(GL_DEPTH_TEST);
+
+ if (d_ptr->fbo) {
+ d_ptr->fbo->release();
+ } else {
+ ctx->makeCurrent();
#ifdef Q_WS_MAC
- ctx->updatePaintDevice();
+ ctx->updatePaintDevice();
#endif
- if (d_ptr->fbo)
- d_ptr->fbo->release();
+ }
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
#ifndef QT_OPENGL_ES
- glOrtho(0, size.width(), size.height(), 0, -999999, 999999);
+ glOrtho(0, size.width(), size.height(), 0, -999999, 999999);
#else
- glOrthof(0, size.width(), size.height(), 0, -999999, 999999);
+ glOrthof(0, size.width(), size.height(), 0, -999999, 999999);
#endif
- glViewport(0, 0, size.width(), size.height());
+ glViewport(0, 0, size.width(), size.height());
- glColor4f(1, 1, 1, 1);
- drawTexture(rect, texture, window()->size(), br);
+ glColor4f(1, 1, 1, 1);
+ drawTexture(rect, texture, window()->size(), br);
+
+ if (d_ptr->fbo)
+ d_ptr->fbo->bind();
+ }
+#endif
if (ctx->format().doubleBuffer())
ctx->swapBuffers();
else
glFlush();
-
- if (d_ptr->fbo)
- d_ptr->fbo->bind();
}
-void QGLWindowSurface::setGeometry(const QRect &rect)
+void QGLWindowSurface::updateGeometry()
{
- QWindowSurface::setGeometry(rect);
+ QRect rect = QWindowSurface::geometry();
- const GLenum target = qt_gl_preferredTextureTarget();
+ const GLenum target = GL_TEXTURE_2D;
if (rect.width() <= 0 || rect.height() <= 0)
return;
@@ -473,13 +510,51 @@ void QGLWindowSurface::setGeometry(const QRect &rect)
d_ptr->size = rect.size();
if (d_ptr->ctx) {
- glBindTexture(target, d_ptr->tex_id);
- glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
- glBindTexture(target, 0);
+ if (d_ptr->destructive_swap_buffers) {
+ glBindTexture(target, d_ptr->tex_id);
+ glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
+ glBindTexture(target, 0);
+ }
return;
}
- if (d_ptr->pb || !d_ptr->tried_pb) {
+ if (d_ptr->destructive_swap_buffers
+ && (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject)
+#ifdef QT_OPENGL_ES_2
+ && (QGLExtensions::glExtensions & QGLExtensions::FramebufferBlit)
+#endif
+ && (d_ptr->fbo || !d_ptr->tried_fbo))
+ {
+ d_ptr->tried_fbo = true;
+ hijackWindow(window());
+ QGLContext *ctx = reinterpret_cast<QGLContext *>(window()->d_func()->extraData()->glContext);
+ ctx->d_ptr->internal_context = true;
+ ctx->makeCurrent();
+ delete d_ptr->fbo;
+
+ QGLFramebufferObjectFormat format;
+ format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
+ format.setInternalFormat(GL_RGBA);
+ format.setTextureTarget(target);
+
+ if (QGLExtensions::glExtensions & QGLExtensions::FramebufferBlit)
+ format.setSamples(8);
+
+ d_ptr->fbo = new QGLFramebufferObject(rect.size(), format);
+ d_ptr->fbo->bind();
+ if (d_ptr->fbo->isValid()) {
+ qDebug() << "Created Window Surface FBO" << rect.size()
+ << "with samples" << d_ptr->fbo->format().samples();
+ return;
+ } else {
+ qDebug() << "QGLWindowSurface: Failed to create valid FBO, falling back";
+ delete d_ptr->fbo;
+ d_ptr->fbo = 0;
+ }
+ }
+
+#if !defined(QT_OPENGL_ES_2)
+ if (d_ptr->destructive_swap_buffers && (d_ptr->pb || !d_ptr->tried_pb)) {
d_ptr->tried_pb = true;
if (d_ptr->pb) {
@@ -494,7 +569,7 @@ void QGLWindowSurface::setGeometry(const QRect &rect)
qt_gl_share_widget());
if (d_ptr->pb->isValid()) {
- qDebug() << "PB Sample buffers:" << d_ptr->pb->format().sampleBuffers();
+ qDebug() << "Created Window Surface Pixelbuffer, Sample buffers:" << d_ptr->pb->format().sampleBuffers();
d_ptr->pb->makeCurrent();
glGenTextures(1, &d_ptr->pb_tex_id);
@@ -521,44 +596,32 @@ void QGLWindowSurface::setGeometry(const QRect &rect)
d_ptr->pb = 0;
}
}
-
- if ((QGLExtensions::glExtensions & QGLExtensions::FramebufferObject) && (d_ptr->fbo || !d_ptr->tried_fbo)) {
- d_ptr->tried_fbo = true;
- hijackWindow(window());
- QGLContext *ctx = reinterpret_cast<QGLContext *>(window()->d_func()->extraData()->glContext);
- ctx->d_ptr->internal_context = true;
- ctx->makeCurrent();
- delete d_ptr->fbo;
- d_ptr->fbo = new QGLFramebufferObject(rect.size(), QGLFramebufferObject::CombinedDepthStencil,
- GLenum(target), GLenum(GL_RGBA));
-
- d_ptr->fbo->bind();
- if (d_ptr->fbo->isValid()) {
- return;
- } else {
- qDebug() << "QGLWindowSurface: Failed to create valid FBO, falling back";
- delete d_ptr->fbo;
- d_ptr->fbo = 0;
- }
- }
+#endif // !defined(QT_OPENGL_ES_2)
hijackWindow(window());
QGLContext *ctx = reinterpret_cast<QGLContext *>(window()->d_func()->extraData()->glContext);
ctx->makeCurrent();
- glGenTextures(1, &d_ptr->tex_id);
- glBindTexture(target, d_ptr->tex_id);
- glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
+ if (d_ptr->destructive_swap_buffers) {
+ glGenTextures(1, &d_ptr->tex_id);
+ glBindTexture(target, d_ptr->tex_id);
+ glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
- glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glBindTexture(target, 0);
+ glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glBindTexture(target, 0);
+ }
qDebug() << "QGLWindowSurface: Using plain widget as window surface" << this;;
d_ptr->ctx = ctx;
d_ptr->ctx->d_ptr->internal_context = true;
}
+void QGLWindowSurface::setGeometry(const QRect &rect)
+{
+ QWindowSurface::setGeometry(rect);
+}
+
bool QGLWindowSurface::scroll(const QRegion &area, int dx, int dy)
{
// this code randomly fails currently for unknown reasons
@@ -582,7 +645,7 @@ bool QGLWindowSurface::scroll(const QRegion &area, int dx, int dy)
return true;
#endif
- const GLenum target = qt_gl_preferredTextureTarget();
+ const GLenum target = GL_TEXTURE_2D;
glBindTexture(target, d_ptr->tex_id);
glCopyTexImage2D(target, 0, GL_RGBA, br.x(), d_ptr->pb->height() - (br.y() + br.height()), br.width(), br.height(), 0);
@@ -595,7 +658,7 @@ bool QGLWindowSurface::scroll(const QRegion &area, int dx, int dy)
static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &br)
{
- const GLenum target = qt_gl_preferredTextureTarget();
+ const GLenum target = GL_TEXTURE_2D;
QRectF src = br.isEmpty()
? QRectF(QPointF(), texSize)
: QRectF(QPointF(br.x(), texSize.height() - br.bottom()), br.size());
@@ -623,6 +686,7 @@ static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize,
extern void qt_add_rect_to_array(const QRectF &r, q_vertexType *array); // qpaintengine_opengl.cpp
qt_add_rect_to_array(rect, vertexArray);
+#if !defined(QT_OPENGL_ES_2)
glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);
glTexCoordPointer(2, q_vertexTypeEnum, 0, texCoordArray);
@@ -634,6 +698,7 @@ static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize,
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+#endif
glDisable(target);
glBindTexture(target, 0);
diff --git a/src/opengl/qwindowsurface_gl_p.h b/src/opengl/qwindowsurface_gl_p.h
index 0194378..d47e3e3 100644
--- a/src/opengl/qwindowsurface_gl_p.h
+++ b/src/opengl/qwindowsurface_gl_p.h
@@ -74,6 +74,7 @@ public:
QPaintDevice *paintDevice();
void flush(QWidget *widget, const QRegion &region, const QPoint &offset);
void setGeometry(const QRect &rect);
+ void updateGeometry();
bool scroll(const QRegion &area, int dx, int dy);
void beginPaint(const QRegion &region);
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp
index 989a37a..a68bc8f 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp
@@ -383,7 +383,7 @@ void QDirectFBPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op)
{
Q_D(QDirectFBPaintEngine);
d->dirtyClip = true;
- const QPoint bottom = d->transform.map(QPoint(0, path.controlPointRect().y2));
+ const QPoint bottom = d->transform.map(QPoint(0, int(path.controlPointRect().y2)));
if (bottom.y() >= d->lastLockedHeight)
d->lock();
QRasterPaintEngine::clip(path, op);
diff --git a/src/scripttools/debugging/qscriptenginedebugger.cpp b/src/scripttools/debugging/qscriptenginedebugger.cpp
index e35bd1d..0f8b600 100644
--- a/src/scripttools/debugging/qscriptenginedebugger.cpp
+++ b/src/scripttools/debugging/qscriptenginedebugger.cpp
@@ -63,16 +63,23 @@
#include <QtGui/qtoolbar.h>
#include <QtGui/qboxlayout.h>
+// this has to be outside the namespace
+static void initScriptEngineDebuggerResources()
+{
+ Q_INIT_RESOURCE(scripttools_debugging);
+}
+
+QT_BEGIN_NAMESPACE
+
class QtScriptDebuggerResourceInitializer
{
public:
QtScriptDebuggerResourceInitializer() {
- Q_INIT_RESOURCE(scripttools_debugging);
+ // call outside-the-namespace function
+ initScriptEngineDebuggerResources();
}
};
-QT_BEGIN_NAMESPACE
-
/*!
\since 4.5
\class QScriptEngineDebugger
diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp
index 51fc306..53645c9 100644
--- a/src/sql/drivers/mysql/qsql_mysql.cpp
+++ b/src/sql/drivers/mysql/qsql_mysql.cpp
@@ -927,6 +927,7 @@ bool QMYSQLResult::exec()
nullVector[i] = static_cast<my_bool>(val.isNull());
currBind->is_null = &nullVector[i];
currBind->length = 0;
+ currBind->is_unsigned = 0;
switch (val.type()) {
case QVariant::ByteArray:
@@ -973,7 +974,6 @@ bool QMYSQLResult::exec()
currBind->buffer_type = MYSQL_TYPE_DOUBLE;
currBind->buffer = data;
currBind->buffer_length = sizeof(double);
- currBind->is_unsigned = 0;
break;
case QVariant::LongLong:
case QVariant::ULongLong:
@@ -989,7 +989,6 @@ bool QMYSQLResult::exec()
currBind->buffer_type = MYSQL_TYPE_STRING;
currBind->buffer = const_cast<char *>(ba.constData());
currBind->buffer_length = ba.length();
- currBind->is_unsigned = 0;
break; }
}
}
diff --git a/src/sql/drivers/oci/qsql_oci.cpp b/src/sql/drivers/oci/qsql_oci.cpp
index d63c482..a7031b1 100644
--- a/src/sql/drivers/oci/qsql_oci.cpp
+++ b/src/sql/drivers/oci/qsql_oci.cpp
@@ -1789,7 +1789,7 @@ bool QOCIResult::prepare(const QString& query)
bool QOCIResult::exec()
{
int r = 0;
- ub2 stmtType;
+ ub2 stmtType=0;
ub4 iters;
ub4 mode;
QList<QByteArray> tmpStorage;
@@ -1803,6 +1803,16 @@ bool QOCIResult::exec()
OCI_ATTR_STMT_TYPE,
d->err);
+ if (r != OCI_SUCCESS && r != OCI_SUCCESS_WITH_INFO) {
+ qOraWarning("QOCIResult::exec: Unable to get statement type:", d->err);
+ setLastError(qMakeError(QCoreApplication::translate("QOCIResult",
+ "Unable to get statement type"), QSqlError::StatementError, d->err));
+#ifdef QOCI_DEBUG
+ qDebug() << "lastQuery()" << lastQuery();
+#endif
+ return false;
+ }
+
if (stmtType == OCI_STMT_SELECT) {
iters = 0;
mode = OCI_DEFAULT;
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp
index 550abc9..dc6ff92 100644
--- a/src/xml/dom/qdom.cpp
+++ b/src/xml/dom/qdom.cpp
@@ -2694,7 +2694,7 @@ void QDomNode::save(QTextStream& str, int indent) const
If the document contains invalid XML characters or characters that cannot be
encoded in the given encoding, the result and behavior is undefined.
- \since 4.2
+ \since 4.2
*/
void QDomNode::save(QTextStream& str, int indent, EncodingPolicy encodingPolicy) const
{
@@ -4597,9 +4597,9 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const
/* Write out attributes. */
if (!m_attr->map.isEmpty()) {
- s << ' ';
QHash<QString, QDomNodePrivate *>::const_iterator it = m_attr->map.constBegin();
for (; it != m_attr->map.constEnd(); ++it) {
+ s << ' ';
if (it.value()->namespaceURI.isNull()) {
s << it.value()->name << "=\"" << encodeText(it.value()->value, s, true, true) << '\"';
} else {
@@ -4622,7 +4622,6 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const
outputtedPrefixes.insert(it.value()->prefix);
}
}
- s << ' ';
}
}
diff --git a/tests/auto/_networkselftest/_networkselftest.pro b/tests/auto/_networkselftest/_networkselftest.pro
new file mode 100644
index 0000000..9e2ad0e
--- /dev/null
+++ b/tests/auto/_networkselftest/_networkselftest.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES += tst_networkselftest.cpp
+QT = core network
+DEFINES += SRCDIR=\\\"$$PWD\\\"
+
diff --git a/tests/auto/_networkselftest/tst_networkselftest.cpp b/tests/auto/_networkselftest/tst_networkselftest.cpp
new file mode 100644
index 0000000..dab4433
--- /dev/null
+++ b/tests/auto/_networkselftest/tst_networkselftest.cpp
@@ -0,0 +1,592 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtNetwork/QtNetwork>
+#include "../network-settings.h"
+
+class tst_NetworkSelfTest: public QObject
+{
+ Q_OBJECT
+private slots:
+ void hostTest();
+ void dnsResolution_data();
+ void dnsResolution();
+ void serverReachability();
+ void remotePortsOpen_data();
+ void remotePortsOpen();
+
+ // specific protocol tests
+ void ftpServer();
+ void imapServer();
+ void httpServer();
+ void httpsServer();
+ void httpProxy();
+ void httpProxyBasicAuth();
+ void httpProxyNtlmAuth();
+ void socks5Proxy();
+ void socks5ProxyAuth();
+};
+
+class Chat
+{
+public:
+ enum Type {
+ Reconnect,
+ Send,
+ Expect,
+ SkipBytes,
+ DiscardUntil,
+ DiscardUntilDisconnect,
+ Disconnect,
+ RemoteDisconnect,
+ StartEncryption
+ };
+ Chat(Type t, const QByteArray &d)
+ : data(d), type(t)
+ {
+ }
+ Chat(Type t, int val = 0)
+ : value(val), type(t)
+ {
+ }
+
+ static inline Chat send(const QByteArray &data)
+ { return Chat(Send, data); }
+ static inline Chat expect(const QByteArray &data)
+ { return Chat(Expect, data); }
+ static inline Chat discardUntil(const QByteArray &data)
+ { return Chat(DiscardUntil, data); }
+ static inline Chat skipBytes(int count)
+ { return Chat(SkipBytes, count); }
+
+ QByteArray data;
+ int value;
+ Type type;
+};
+
+static QString prettyByteArray(const QByteArray &array)
+{
+ // any control chars?
+ QString result;
+ result.reserve(array.length() + array.length() / 3);
+ for (int i = 0; i < array.length(); ++i) {
+ char c = array.at(i);
+ switch (c) {
+ case '\n':
+ result += "\\n";
+ continue;
+ case '\r':
+ result += "\\r";
+ continue;
+ case '\t':
+ result += "\\t";
+ continue;
+ case '"':
+ result += "\\\"";
+ continue;
+ default:
+ break;
+ }
+
+ if (c < 0x20 || uchar(c) >= 0x7f) {
+ result += '\\';
+ result += QString::number(uchar(c), 8);
+ } else {
+ result += c;
+ }
+ }
+ return result;
+}
+
+static bool doSocketRead(QTcpSocket *socket, int minBytesAvailable, int timeout = 2000)
+{
+ QTime timer;
+ timer.start();
+ forever {
+ if (socket->bytesAvailable() >= minBytesAvailable)
+ return true;
+ if (socket->state() == QAbstractSocket::UnconnectedState
+ || timer.elapsed() >= timeout)
+ return false;
+ if (!socket->waitForReadyRead(timeout - timer.elapsed()))
+ return false;
+ }
+}
+
+static bool doSocketFlush(QTcpSocket *socket, int timeout = 2000)
+{
+#ifndef QT_NO_OPENSSL
+ QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket);
+#endif
+ QTime timer;
+ timer.start();
+ forever {
+ if (socket->bytesToWrite() == 0
+#ifndef QT_NO_OPENSSL
+ && sslSocket->encryptedBytesToWrite() == 0
+#endif
+ )
+ return true;
+ if (socket->state() == QAbstractSocket::UnconnectedState
+ || timer.elapsed() >= timeout)
+ return false;
+ if (!socket->waitForBytesWritten(timeout - timer.elapsed()))
+ return false;
+ }
+}
+
+static void netChat(int port, const QList<Chat> &chat)
+{
+#ifndef QT_NO_OPENSSL
+ QSslSocket socket;
+#else
+ QTcpSocket socket;
+#endif
+
+ socket.connectToHost(QtNetworkSettings::serverName(), port);
+ qDebug() << 0 << "Connecting to server on port" << port;
+ QVERIFY2(socket.waitForConnected(10000),
+ QString("Failed to connect to server in step 0: %1").arg(socket.errorString()).toLocal8Bit());
+
+ // now start the chat
+ QList<Chat>::ConstIterator it = chat.constBegin();
+ for (int i = 1; it != chat.constEnd(); ++it, ++i) {
+ if (it->type != Chat::Reconnect
+ && socket.state() != QAbstractSocket::ConnectedState
+ && socket.state() != QAbstractSocket::ClosingState)
+ QFAIL(QString("Internal error: socket is in invalid state %1 in step %2")
+ .arg(socket.state()).arg(i).toLocal8Bit());
+
+ switch (it->type) {
+ case Chat::Expect: {
+ qDebug() << i << "Expecting" << prettyByteArray(it->data);
+ if (!doSocketRead(&socket, it->data.length()))
+ QFAIL(QString("Failed to receive data in step %1: timeout").arg(i).toLocal8Bit());
+
+ // pop that many bytes off the socket
+ QByteArray received = socket.read(it->data.length());
+
+ // is it what we expected?
+ QVERIFY2(received == it->data,
+ QString("Did not receive expected data in step %1: data received was:\n%2")
+ .arg(i).arg(prettyByteArray(received)).toLocal8Bit());
+
+ break;
+ }
+
+ case Chat::DiscardUntil:
+ qDebug() << i << "Discarding until" << prettyByteArray(it->data);
+ while (true) {
+ // scan the buffer until we have our string
+ if (!doSocketRead(&socket, it->data.length()))
+ QFAIL(QString("Failed to receive data in step %1: timeout").arg(i).toLocal8Bit());
+
+ QByteArray buffer;
+ buffer.resize(socket.bytesAvailable());
+ socket.peek(buffer.data(), socket.bytesAvailable());
+
+ int pos = buffer.indexOf(it->data);
+ if (pos == -1) {
+ // data not found, keep trying
+ continue;
+ }
+
+ buffer = socket.read(pos + it->data.length());
+ qDebug() << i << "Discarded" << prettyByteArray(buffer);
+ break;
+ }
+ break;
+
+ case Chat::SkipBytes: {
+ qDebug() << i << "Skipping" << it->value << "bytes";
+ if (!doSocketRead(&socket, it->value))
+ QFAIL(QString("Failed to receive data in step %1: timeout").arg(i).toLocal8Bit());
+
+ // now discard the bytes
+ QByteArray buffer = socket.read(it->value);
+ qDebug() << i << "Skipped" << prettyByteArray(buffer);
+ break;
+ }
+
+ case Chat::Send: {
+ qDebug() << i << "Sending" << prettyByteArray(it->data);
+ socket.write(it->data);
+ if (!doSocketFlush(&socket)) {
+ QVERIFY2(socket.state() == QAbstractSocket::ConnectedState,
+ QString("Socket disconnected while sending data in step %1").arg(i).toLocal8Bit());
+ QFAIL(QString("Failed to send data in step %1: timeout").arg(i).toLocal8Bit());
+ }
+ break;
+ }
+
+ case Chat::Disconnect:
+ qDebug() << i << "Disconnecting from host";
+ socket.disconnectFromHost();
+
+ // is this the last command?
+ if (it + 1 != chat.constEnd())
+ break;
+
+ // fall through:
+ case Chat::RemoteDisconnect:
+ case Chat::DiscardUntilDisconnect:
+ qDebug() << i << "Waiting for remote disconnect";
+ if (socket.state() != QAbstractSocket::UnconnectedState)
+ socket.waitForDisconnected(10000);
+ QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState,
+ QString("Socket did not disconnect as expected in step %1").arg(i).toLocal8Bit());
+
+ // any data left?
+ if (it->type == Chat::DiscardUntilDisconnect) {
+ QByteArray buffer = socket.readAll();
+ qDebug() << i << "Discarded in the process:" << prettyByteArray(buffer);
+ }
+
+ if (socket.bytesAvailable() != 0)
+ QFAIL(QString("Unexpected bytes still on buffer when disconnecting in step %1:\n%2")
+ .arg(i).arg(prettyByteArray(socket.readAll())).toLocal8Bit());
+ break;
+
+ case Chat::Reconnect:
+ qDebug() << i << "Reconnecting to server on port" << port;
+ socket.connectToHost(QtNetworkSettings::serverName(), port);
+ QVERIFY2(socket.waitForConnected(10000),
+ QString("Failed to reconnect to server in step %1: %2").arg(i).arg(socket.errorString()).toLocal8Bit());
+ break;
+
+ case Chat::StartEncryption:
+#ifdef QT_NO_OPENSSL
+ QFAIL("Internal error: SSL required for this test");
+#else
+ qDebug() << i << "Starting client encryption";
+ socket.ignoreSslErrors();
+ socket.startClientEncryption();
+ QVERIFY2(socket.waitForEncrypted(5000),
+ QString("Failed to start client encryption in step %1: %2").arg(i)
+ .arg(socket.errorString()).toLocal8Bit());
+ break;
+#endif
+ }
+ }
+}
+
+void tst_NetworkSelfTest::hostTest()
+{
+ // this is a localhost self-test
+ QHostInfo localhost = QHostInfo::fromName("localhost");
+ QCOMPARE(localhost.error(), QHostInfo::NoError);
+ QVERIFY(!localhost.addresses().isEmpty());
+
+ QTcpServer server;
+ QVERIFY(server.listen());
+
+ QTcpSocket socket;
+ socket.connectToHost("127.0.0.1", server.serverPort());
+ QVERIFY(socket.waitForConnected(10000));
+}
+
+void tst_NetworkSelfTest::dnsResolution_data()
+{
+ QTest::addColumn<QString>("hostName");
+ QTest::newRow("local-name") << QtNetworkSettings::serverLocalName();
+ QTest::newRow("fqdn") << QtNetworkSettings::serverName();
+}
+
+void tst_NetworkSelfTest::dnsResolution()
+{
+ QFETCH(QString, hostName);
+ QHostInfo resolved = QHostInfo::fromName(hostName);
+ QVERIFY2(resolved.error() == QHostInfo::NoError,
+ QString("Failed to resolve hostname %1: %2").arg(hostName, resolved.errorString()).toLocal8Bit());
+}
+
+void tst_NetworkSelfTest::serverReachability()
+{
+ // check that we get a proper error connecting to port 1
+ QTcpSocket socket;
+ socket.connectToHost(QtNetworkSettings::serverName(), 1);
+ socket.waitForConnected(10000);
+ QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!");
+ QVERIFY2(socket.error() == QAbstractSocket::ConnectionRefusedError,
+ QString("Could not reach server: %1").arg(socket.errorString()).toLocal8Bit());
+}
+
+void tst_NetworkSelfTest::remotePortsOpen_data()
+{
+ QTest::addColumn<int>("portNumber");
+ QTest::newRow("ftp") << 21;
+ QTest::newRow("ssh") << 22;
+ QTest::newRow("imap") << 143;
+ QTest::newRow("http") << 80;
+ QTest::newRow("https") << 443;
+ QTest::newRow("http-proxy") << 3128;
+ QTest::newRow("http-proxy-auth-basic") << 3129;
+ QTest::newRow("http-proxy-auth-ntlm") << 3130;
+ QTest::newRow("socks5-proxy") << 1080;
+ QTest::newRow("socks5-proxy-auth") << 1081;
+}
+
+void tst_NetworkSelfTest::remotePortsOpen()
+{
+ QFETCH(int, portNumber);
+ QTcpSocket socket;
+ socket.connectToHost(QtNetworkSettings::serverName(), portNumber);
+
+ if (!socket.waitForConnected(10000)) {
+ if (socket.error() == QAbstractSocket::SocketTimeoutError)
+ QFAIL(QString("Network timeout connecting to the server on port %1").arg(portNumber).toLocal8Bit());
+ else
+ QFAIL(QString("Error connecting to server on port %1: %2").arg(portNumber).arg(socket.errorString()).toLocal8Bit());
+ }
+ QVERIFY(socket.state() == QAbstractSocket::ConnectedState);
+}
+
+static QList<Chat> ftpChat()
+{
+ return QList<Chat>() << Chat::expect("220")
+ << Chat::discardUntil("\r\n")
+ << Chat::send("USER anonymous\r\n")
+ << Chat::expect("331")
+ << Chat::discardUntil("\r\n")
+ << Chat::send("PASS user@hostname\r\n")
+ << Chat::expect("230")
+ << Chat::discardUntil("\r\n")
+ << Chat::send("QUIT\r\n")
+ << Chat::expect("221")
+ << Chat::discardUntil("\r\n")
+ << Chat::RemoteDisconnect;
+}
+
+void tst_NetworkSelfTest::ftpServer()
+{
+ netChat(21, ftpChat());
+}
+
+void tst_NetworkSelfTest::imapServer()
+{
+ netChat(143, QList<Chat>()
+ << Chat::expect("* OK ")
+ << Chat::discardUntil("\r\n")
+ << Chat::send("1 CAPABILITY\r\n")
+ << Chat::expect("* CAPABILITY ")
+ << Chat::discardUntil("1 OK")
+ << Chat::discardUntil("\r\n")
+ << Chat::send("2 LOGOUT\r\n")
+ << Chat::discardUntil("2 OK")
+ << Chat::discardUntil("\r\n")
+ << Chat::RemoteDisconnect);
+}
+
+void tst_NetworkSelfTest::httpServer()
+{
+ netChat(80, QList<Chat>()
+ // HTTP/0.9 chat:
+ << Chat::send("GET /\r\n")
+ << Chat::DiscardUntilDisconnect
+
+ // HTTP/1.0 chat:
+ << Chat::Reconnect
+ << Chat::send("GET / HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Connection: close\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::DiscardUntilDisconnect
+
+ // HTTP/1.0 POST:
+ << Chat::Reconnect
+ << Chat::send("POST / HTTP/1.0\r\n"
+ "Content-Length: 5\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Connection: close\r\n"
+ "\r\n"
+ "Hello")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::DiscardUntilDisconnect
+ );
+}
+
+void tst_NetworkSelfTest::httpsServer()
+{
+#ifndef QT_NO_OPENSSL
+ netChat(443, QList<Chat>()
+ << Chat::StartEncryption
+ << Chat::send("GET / HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Connection: close\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::DiscardUntilDisconnect);
+#else
+ QSKIP("SSL not enabled, cannot test");
+#endif
+}
+
+void tst_NetworkSelfTest::httpProxy()
+{
+ netChat(3128, QList<Chat>()
+ // proxy GET
+ << Chat::send("GET http://" + QtNetworkSettings::serverName().toLatin1() + "/ HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Proxy-connection: close\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::DiscardUntilDisconnect
+
+ // proxy CONNECT
+ << Chat::Reconnect
+ << Chat::send("CONNECT " + QtNetworkSettings::serverName().toLatin1() + ":21 HTTP/1.0\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::discardUntil("\r\n\r\n")
+ << ftpChat());
+}
+
+void tst_NetworkSelfTest::httpProxyBasicAuth()
+{
+ netChat(3129, QList<Chat>()
+ // test auth required response
+ << Chat::send("GET http://" + QtNetworkSettings::serverName().toLatin1() + "/ HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Proxy-connection: close\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("407 ")
+ << Chat::discardUntil("\r\nProxy-Authenticate: Basic realm=\"")
+ << Chat::DiscardUntilDisconnect
+
+ // now try sending our credentials
+ << Chat::Reconnect
+ << Chat::send("GET http://" + QtNetworkSettings::serverName().toLatin1() + "/ HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Proxy-connection: close\r\n"
+ "Proxy-Authorization: Basic cXNvY2tzdGVzdDpwYXNzd29yZA==\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::DiscardUntilDisconnect);
+}
+
+void tst_NetworkSelfTest::httpProxyNtlmAuth()
+{
+ netChat(3130, QList<Chat>()
+ // test auth required response
+ << Chat::send("GET http://" + QtNetworkSettings::serverName().toLatin1() + "/ HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Proxy-connection: keep-alive\r\n" // NTLM auth will disconnect
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("407 ")
+ << Chat::discardUntil("\r\nProxy-Authenticate: NTLM\r\n")
+ << Chat::DiscardUntilDisconnect
+ );
+}
+
+// SOCKSv5 is a binary protocol
+static const char handshakeNoAuth[] = "\5\1\0";
+static const char handshakeOkNoAuth[] = "\5\0";
+static const char handshakeAuthPassword[] = "\5\1\2\1\12qsockstest\10password";
+static const char handshakeOkPasswdAuth[] = "\5\2\1\0";
+static const char handshakeAuthNotOk[] = "\5\377";
+static const char connect1[] = "\5\1\0\1\177\0\0\1\0\25"; // Connect IPv4 127.0.0.1 port 21
+static const char connect2[] = "\5\1\0\3\11localhost\0\25"; // Connect hostname localhost 21
+static const char connected[] = "\5\0\0";
+
+void tst_NetworkSelfTest::socks5Proxy()
+{
+ netChat(1080, QList<Chat>()
+ // IP address connection
+ << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
+ << Chat::expect(QByteArray(handshakeOkNoAuth, -1 + sizeof handshakeOkNoAuth))
+ << Chat::send(QByteArray(connect1, -1 + sizeof connect1))
+ << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+ << Chat::expect("\1") // IPv4 address following
+ << Chat::skipBytes(6) // the server's local address and port
+ << ftpChat()
+
+ // hostname connection
+ << Chat::Reconnect
+ << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
+ << Chat::expect(QByteArray(handshakeOkNoAuth, -1 + sizeof handshakeOkNoAuth))
+ << Chat::send(QByteArray(connect2, -1 + sizeof connect2))
+ << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+ << Chat::expect("\1") // IPv4 address following
+ << Chat::skipBytes(6) // the server's local address and port
+ << ftpChat()
+ );
+}
+
+void tst_NetworkSelfTest::socks5ProxyAuth()
+{
+ netChat(1081, QList<Chat>()
+ // unauthenticated connect -- will get error
+ << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
+ << Chat::expect(QByteArray(handshakeAuthNotOk, -1 + sizeof handshakeAuthNotOk))
+ << Chat::RemoteDisconnect
+
+ // now try to connect with authentication
+ << Chat::Reconnect
+ << Chat::send(QByteArray(handshakeAuthPassword, -1 + sizeof handshakeAuthPassword))
+ << Chat::expect(QByteArray(handshakeOkPasswdAuth, -1 + sizeof handshakeOkPasswdAuth))
+ << Chat::send(QByteArray(connect1, -1 + sizeof connect1))
+ << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+ << Chat::expect("\1") // IPv4 address following
+ << Chat::skipBytes(6) // the server's local address and port
+ << ftpChat()
+ );
+}
+
+QTEST_MAIN(tst_NetworkSelfTest)
+#include "tst_networkselftest.moc"
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 714e19d..27e3c74 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -4,7 +4,8 @@ TEMPLATE = subdirs
!wince*:SUBDIRS += \
headers
-SUBDIRS += bic \
+SUBDIRS += _networkselftest \
+ bic \
collections \
compile \
compilerwarnings \
@@ -75,6 +76,7 @@ SUBDIRS += bic \
qaction \
qactiongroup \
qalgorithms \
+ qanimationgroup \
qapplication \
qatomicint \
qatomicpointer \
@@ -214,6 +216,7 @@ SUBDIRS += bic \
qpainter \
qpainterpath \
qpalette \
+ qparallelanimationgroup \
qpathclipper \
qpen \
qpicture \
@@ -229,6 +232,7 @@ SUBDIRS += bic \
qprocess \
qprogressbar \
qprogressdialog \
+ qpropertyanimation \
qpushbutton \
qqueue \
qradiobutton \
@@ -256,6 +260,7 @@ SUBDIRS += bic \
qscrollarea \
qsemaphore \
qsharedpointer \
+ qsequentialanimationgroup \
qset \
qsettings \
qshortcut \
@@ -289,6 +294,8 @@ SUBDIRS += bic \
qstackedwidget \
qstandarditem \
qstandarditemmodel \
+ qstate \
+ qstatemachine \
qstatusbar \
qstl \
qstring \
@@ -342,6 +349,7 @@ SUBDIRS += bic \
qtranslator \
qtransform \
qtransformedscreen \
+ qtransition \
qtreeview \
qtreewidget \
qtreewidgetitemiterator \
diff --git a/tests/auto/qanimationgroup/qanimationgroup.pro b/tests/auto/qanimationgroup/qanimationgroup.pro
new file mode 100644
index 0000000..97d33dd
--- /dev/null
+++ b/tests/auto/qanimationgroup/qanimationgroup.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+QT = core gui
+SOURCES += tst_qanimationgroup.cpp
+
+
diff --git a/tests/auto/qanimationgroup/tst_qanimationgroup.cpp b/tests/auto/qanimationgroup/tst_qanimationgroup.cpp
new file mode 100644
index 0000000..2952a39
--- /dev/null
+++ b/tests/auto/qanimationgroup/tst_qanimationgroup.cpp
@@ -0,0 +1,413 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtCore/qanimationgroup.h>
+#include <QtCore/qsequentialanimationgroup.h>
+#include <QtCore/qparallelanimationgroup.h>
+
+//TESTED_CLASS=QAnimationGroup
+//TESTED_FILES=
+
+Q_DECLARE_METATYPE(QAbstractAnimation::State)
+
+class tst_QAnimationGroup : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QAnimationGroup();
+ virtual ~tst_QAnimationGroup();
+
+public Q_SLOTS:
+ void init();
+ void cleanup();
+
+private slots:
+ void construction();
+ void emptyGroup();
+ void setCurrentTime();
+ void statesAndSignals();
+ void setParentAutoAdd();
+ void beginNestedGroup();
+ void addChildTwice();
+ void loopWithoutStartValue();
+};
+
+tst_QAnimationGroup::tst_QAnimationGroup()
+{
+}
+
+tst_QAnimationGroup::~tst_QAnimationGroup()
+{
+}
+
+void tst_QAnimationGroup::init()
+{
+ qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
+}
+
+void tst_QAnimationGroup::cleanup()
+{
+}
+
+void tst_QAnimationGroup::construction()
+{
+ QSequentialAnimationGroup animationgroup;
+}
+
+class AnimationObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value WRITE setValue)
+public:
+ AnimationObject(int startValue = 0)
+ : v(startValue)
+ { }
+
+ int value() const { return v; }
+ void setValue(int value) { v = value; }
+
+ int v;
+};
+
+class TestAnimation : public QVariantAnimation
+{
+ Q_OBJECT
+public:
+ virtual void updateCurrentValue(const QVariant &value) { Q_UNUSED(value)};
+ virtual void updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+ {
+ Q_UNUSED(oldState)
+ Q_UNUSED(newState)
+ };
+};
+
+class UncontrolledAnimation : public QPropertyAnimation
+{
+ Q_OBJECT
+public:
+ UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = 0)
+ : QPropertyAnimation(target, propertyName, parent), id(0)
+ {
+ setDuration(250);
+ }
+
+ int duration() const { return -1; /* not time driven */ }
+
+protected:
+ void timerEvent(QTimerEvent *event)
+ {
+ if (event->timerId() == id)
+ stop();
+ }
+
+ void updateRunning(bool running)
+ {
+ if (running) {
+ id = startTimer(500);
+ } else {
+ killTimer(id);
+ id = 0;
+ }
+ }
+
+private:
+ int id;
+};
+
+void tst_QAnimationGroup::emptyGroup()
+{
+ QSequentialAnimationGroup group;
+ QSignalSpy groupStateChangedSpy(&group, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ group.start();
+
+ QCOMPARE(groupStateChangedSpy.count(), 2);
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+
+ QTest::ignoreMessage(QtWarningMsg, "QAbstractAnimation::pause: Cannot pause a stopped animation");
+ group.pause();
+
+ QCOMPARE(groupStateChangedSpy.count(), 2);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+
+ group.start();
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(2).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(3).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+
+ group.stop();
+
+ QCOMPARE(groupStateChangedSpy.count(), 4);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QAnimationGroup::setCurrentTime()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject s_o3;
+ AnimationObject p_o1;
+ AnimationObject p_o2;
+ AnimationObject p_o3;
+ AnimationObject t_o1;
+ AnimationObject t_o2;
+
+ // sequence operating on same object/property
+ QSequentialAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ a2_s_o1->setLoopCount(3);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+
+ // sequence operating on different object/properties
+ QAnimationGroup *sequence2 = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value");
+ QVariantAnimation *a1_s_o3 = new QPropertyAnimation(&s_o3, "value");
+ sequence2->addAnimation(a1_s_o2);
+ sequence2->addAnimation(a1_s_o3);
+
+ // parallel operating on different object/properties
+ QAnimationGroup *parallel = new QParallelAnimationGroup();
+ QVariantAnimation *a1_p_o1 = new QPropertyAnimation(&p_o1, "value");
+ QVariantAnimation *a1_p_o2 = new QPropertyAnimation(&p_o2, "value");
+ QVariantAnimation *a1_p_o3 = new QPropertyAnimation(&p_o3, "value");
+ a1_p_o2->setLoopCount(3);
+ parallel->addAnimation(a1_p_o1);
+ parallel->addAnimation(a1_p_o2);
+ parallel->addAnimation(a1_p_o3);
+
+ UncontrolledAnimation *notTimeDriven = new UncontrolledAnimation(&t_o1, "value");
+ QCOMPARE(notTimeDriven->totalDuration(), -1);
+
+ QVariantAnimation *loopsForever = new QPropertyAnimation(&t_o2, "value");
+ loopsForever->setLoopCount(-1);
+ QCOMPARE(loopsForever->totalDuration(), -1);
+
+ QParallelAnimationGroup group;
+ group.addAnimation(sequence);
+ group.addAnimation(sequence2);
+ group.addAnimation(parallel);
+ group.addAnimation(notTimeDriven);
+ group.addAnimation(loopsForever);
+
+ // Current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(parallel->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o3->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 1);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+ QCOMPARE(a1_p_o1->currentTime(), 1);
+ QCOMPARE(a1_p_o2->currentTime(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 1);
+ QCOMPARE(notTimeDriven->currentTime(), 1);
+ QCOMPARE(loopsForever->currentTime(), 1);
+
+ // Current time = 250
+ group.setCurrentTime(250);
+ QCOMPARE(group.currentTime(), 250);
+ QCOMPARE(sequence->currentTime(), 250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+ QCOMPARE(a1_p_o1->currentTime(), 250);
+ QCOMPARE(a1_p_o2->currentTime(), 0);
+ QCOMPARE(a1_p_o2->currentLoop(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 250);
+ QCOMPARE(loopsForever->currentTime(), 0);
+ QCOMPARE(loopsForever->currentLoop(), 1);
+ QCOMPARE(sequence->currentAnimation(), a2_s_o1);
+
+ // Current time = 251
+ group.setCurrentTime(251);
+ QCOMPARE(group.currentTime(), 251);
+ QCOMPARE(sequence->currentTime(), 251);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentLoop(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 251);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 1);
+ QCOMPARE(a1_p_o1->currentTime(), 250);
+ QCOMPARE(a1_p_o2->currentTime(), 1);
+ QCOMPARE(a1_p_o2->currentLoop(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 251);
+ QCOMPARE(loopsForever->currentTime(), 1);
+ QCOMPARE(sequence->currentAnimation(), a2_s_o1);
+}
+
+void tst_QAnimationGroup::statesAndSignals()
+{
+}
+
+void tst_QAnimationGroup::setParentAutoAdd()
+{
+ QParallelAnimationGroup group;
+ QVariantAnimation *animation = new QPropertyAnimation(&group);
+ QCOMPARE(animation->group(), &group);
+}
+
+void tst_QAnimationGroup::beginNestedGroup()
+{
+ QAnimationGroup *subGroup;
+ QAnimationGroup *parent = new QParallelAnimationGroup();
+
+ for (int i = 0; i < 10; ++i) {
+ if (i & 1)
+ subGroup = new QParallelAnimationGroup(parent);
+ else
+ subGroup = new QSequentialAnimationGroup(parent);
+
+ QCOMPARE(parent->animationCount(), 1);
+ QAnimationGroup *child = static_cast<QAnimationGroup *>(parent->animationAt(0));
+
+ QCOMPARE(child->parent(), static_cast<QObject *>(parent));
+ if (i & 1)
+ QVERIFY(qobject_cast<QParallelAnimationGroup *> (child));
+ else
+ QVERIFY(qobject_cast<QSequentialAnimationGroup *> (child));
+
+ parent = child;
+ }
+}
+
+void tst_QAnimationGroup::addChildTwice()
+{
+ QPropertyAnimation *subGroup;
+ QPropertyAnimation *subGroup2;
+ QAnimationGroup *parent = new QSequentialAnimationGroup();
+
+ subGroup = new QPropertyAnimation();
+ subGroup->setParent(parent);
+ parent->addAnimation(subGroup);
+ QCOMPARE(parent->animationCount(), 1);
+
+ parent->clearAnimations();
+
+ QCOMPARE(parent->animationCount(), 0);
+
+ // adding the same item twice to a group will remove the item from its current position
+ // and append it to the end
+ subGroup = new QPropertyAnimation(parent);
+ subGroup2 = new QPropertyAnimation(parent);
+
+ QCOMPARE(parent->animationCount(), 2);
+ QCOMPARE(parent->animationAt(0), subGroup);
+ QCOMPARE(parent->animationAt(1), subGroup2);
+
+ parent->addAnimation(subGroup);
+
+ QCOMPARE(parent->animationCount(), 2);
+ QCOMPARE(parent->animationAt(0), subGroup2);
+ QCOMPARE(parent->animationAt(1), subGroup);
+
+ delete parent;
+}
+
+void tst_QAnimationGroup::loopWithoutStartValue()
+{
+ QAnimationGroup *parent = new QSequentialAnimationGroup();
+ QObject o;
+ o.setProperty("ole", 0);
+ QCOMPARE(o.property("ole").toInt(), 0);
+
+ QPropertyAnimation anim1(&o, "ole");
+ anim1.setEndValue(-50);
+ anim1.setDuration(100);
+
+ QPropertyAnimation anim2(&o, "ole");
+ anim2.setEndValue(50);
+ anim2.setDuration(100);
+
+ parent->addAnimation(&anim1);
+ parent->addAnimation(&anim2);
+
+ parent->setLoopCount(-1);
+ parent->start();
+
+ QVERIFY(anim1.startValue().isNull());
+ QCOMPARE(anim1.currentValue().toInt(), 0);
+ QCOMPARE(parent->currentLoop(), 0);
+
+ parent->setCurrentTime(200);
+ QCOMPARE(parent->currentLoop(), 1);
+ QCOMPARE(anim1.currentValue().toInt(), 50);
+ parent->stop();
+}
+
+QTEST_MAIN(tst_QAnimationGroup)
+#include "tst_qanimationgroup.moc"
diff --git a/tests/auto/qeasingcurve/qeasingcurve.pro b/tests/auto/qeasingcurve/qeasingcurve.pro
new file mode 100644
index 0000000..2b66081
--- /dev/null
+++ b/tests/auto/qeasingcurve/qeasingcurve.pro
@@ -0,0 +1,3 @@
+load(qttest_p4)
+QT = core
+SOURCES += tst_qeasingcurve.cpp
diff --git a/tests/auto/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/qeasingcurve/tst_qeasingcurve.cpp
new file mode 100644
index 0000000..8fe15b1
--- /dev/null
+++ b/tests/auto/qeasingcurve/tst_qeasingcurve.cpp
@@ -0,0 +1,665 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+
+#if QT_VERSION < 0x040200
+QTEST_NOOP_MAIN
+#else
+
+#include <qeasingcurve.h>
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+class tst_QEasingCurve : public QObject {
+ Q_OBJECT
+
+public:
+ tst_QEasingCurve();
+ virtual ~tst_QEasingCurve();
+
+public Q_SLOTS:
+ void init();
+ void cleanup();
+
+private slots:
+ void type();
+ void propertyDefaults();
+ void valueForProgress_data();
+ void valueForProgress();
+ void setCustomType();
+ void operators();
+
+protected:
+};
+
+tst_QEasingCurve::tst_QEasingCurve()
+{
+}
+
+tst_QEasingCurve::~tst_QEasingCurve()
+{
+}
+
+void tst_QEasingCurve::init()
+{
+}
+
+void tst_QEasingCurve::cleanup()
+{
+}
+#include <qdebug.h>
+
+void tst_QEasingCurve::type()
+{
+ {
+ QEasingCurve curve(QEasingCurve::Linear);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+
+ curve.setPeriod(5);
+ curve.setAmplitude(3);
+ QCOMPARE(curve.period(), 5.0);
+ QCOMPARE(curve.amplitude(), 3.0);
+
+ curve.setType(QEasingCurve::InElastic);
+ QCOMPARE(curve.period(), 5.0);
+ QCOMPARE(curve.amplitude(), 3.0);
+ }
+
+ {
+ QEasingCurve curve(QEasingCurve::InElastic);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+ curve.setAmplitude(2);
+ QCOMPARE(curve.type(), QEasingCurve::InElastic);
+ curve.setType(QEasingCurve::Linear);
+ }
+
+ {
+ // check bounaries
+ QEasingCurve curve(QEasingCurve::InCubic);
+ QTest::ignoreMessage(QtWarningMsg, "QEasingCurve: Invalid curve type 9999");
+ curve.setType((QEasingCurve::Type)9999);
+ QCOMPARE(curve.type(), QEasingCurve::InCubic);
+ QTest::ignoreMessage(QtWarningMsg, "QEasingCurve: Invalid curve type -9999");
+ curve.setType((QEasingCurve::Type)-9999);
+ QCOMPARE(curve.type(), QEasingCurve::InCubic);
+ QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
+ .arg(QEasingCurve::NCurveTypes).toLatin1().constData());
+ curve.setType(QEasingCurve::NCurveTypes);
+ QCOMPARE(curve.type(), QEasingCurve::InCubic);
+ QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
+ .arg(QEasingCurve::Custom).toLatin1().constData());
+ curve.setType(QEasingCurve::Custom);
+ QCOMPARE(curve.type(), QEasingCurve::InCubic);
+ QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
+ .arg(-1).toLatin1().constData());
+ curve.setType((QEasingCurve::Type)-1);
+ QCOMPARE(curve.type(), QEasingCurve::InCubic);
+ curve.setType(QEasingCurve::Linear);
+ QCOMPARE(curve.type(), QEasingCurve::Linear);
+ curve.setType(QEasingCurve::CosineCurve);
+ QCOMPARE(curve.type(), QEasingCurve::CosineCurve);
+ }
+}
+
+void tst_QEasingCurve::propertyDefaults()
+{
+ {
+ // checks if the defaults are correct, but also demonstrates a weakness with the API.
+ QEasingCurve curve(QEasingCurve::InElastic);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+ QCOMPARE(curve.overshoot(), qreal(1.70158f));
+ curve.setType(QEasingCurve::InBounce);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+ QCOMPARE(curve.overshoot(), qreal(1.70158f));
+ curve.setType(QEasingCurve::Linear);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+ QCOMPARE(curve.overshoot(), qreal(1.70158f));
+ curve.setType(QEasingCurve::InElastic);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+ QCOMPARE(curve.overshoot(), qreal(1.70158f));
+ curve.setPeriod(0.4);
+ curve.setAmplitude(0.6);
+ curve.setOvershoot(1.0);
+ curve.setType(QEasingCurve::Linear);
+ QCOMPARE(curve.period(), 0.4);
+ QCOMPARE(curve.amplitude(), 0.6);
+ QCOMPARE(curve.overshoot(), 1.0);
+ curve.setType(QEasingCurve::InElastic);
+ QCOMPARE(curve.period(), 0.4);
+ QCOMPARE(curve.amplitude(), 0.6);
+ QCOMPARE(curve.overshoot(), 1.0);
+ }
+}
+
+typedef QList<int> IntList;
+typedef QList<qreal> RealList;
+Q_DECLARE_METATYPE(IntList)
+Q_DECLARE_METATYPE(RealList)
+
+void tst_QEasingCurve::valueForProgress_data()
+{
+ QTest::addColumn<int>("type");
+ QTest::addColumn<IntList>("at");
+ QTest::addColumn<RealList>("expected");
+ // automatically generated.
+ // note that values are scaled from range [0,1] to range [0, 100] in order to store them as
+ // integer values and avoid fp inaccuracies
+ QTest::newRow("Linear") << int(QEasingCurve::Linear)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.1 << 0.2 << 0.3 << 0.4 << 0.5 << 0.6 << 0.7 << 0.8 << 0.9 << 1);
+
+ QTest::newRow("InQuad") << int(QEasingCurve::InQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.01 << 0.04 << 0.09 << 0.16 << 0.25 << 0.36 << 0.49 << 0.64 << 0.81 << 1);
+
+ QTest::newRow("OutQuad") << int(QEasingCurve::OutQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.19 << 0.36 << 0.51 << 0.64 << 0.75 << 0.84 << 0.91 << 0.96 << 0.99 << 1);
+
+ QTest::newRow("InOutQuad") << int(QEasingCurve::InOutQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.02 << 0.08 << 0.18 << 0.32 << 0.5 << 0.68 << 0.82 << 0.92 << 0.98 << 1);
+
+ QTest::newRow("OutInQuad") << int(QEasingCurve::OutInQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.18 << 0.32 << 0.42 << 0.48 << 0.5 << 0.52 << 0.58 << 0.68 << 0.82 << 1);
+
+ QTest::newRow("InCubic") << int(QEasingCurve::InCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.001 << 0.008 << 0.027 << 0.064 << 0.125 << 0.216 << 0.343 << 0.512 << 0.729 << 1);
+
+ QTest::newRow("OutCubic") << int(QEasingCurve::OutCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.271 << 0.488 << 0.657 << 0.784 << 0.875 << 0.936 << 0.973 << 0.992 << 0.999 << 1);
+
+ QTest::newRow("InOutCubic") << int(QEasingCurve::InOutCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.004 << 0.032 << 0.108 << 0.256 << 0.5 << 0.744 << 0.892 << 0.968 << 0.996 << 1);
+
+ QTest::newRow("OutInCubic") << int(QEasingCurve::OutInCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.244 << 0.392 << 0.468 << 0.496 << 0.5 << 0.504 << 0.532 << 0.608 << 0.756 << 1);
+
+ QTest::newRow("InQuart") << int(QEasingCurve::InQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.0001 << 0.0016 << 0.0081 << 0.0256 << 0.0625 << 0.1296 << 0.2401 << 0.4096 << 0.6561 << 1);
+
+ QTest::newRow("OutQuart") << int(QEasingCurve::OutQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.3439 << 0.5904 << 0.7599 << 0.8704 << 0.9375 << 0.9744 << 0.9919 << 0.9984 << 0.9999 << 1);
+
+ QTest::newRow("InOutQuart") << int(QEasingCurve::InOutQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.0008 << 0.0128 << 0.0648 << 0.2048 << 0.5 << 0.7952 << 0.9352 << 0.9872 << 0.9992 << 1);
+
+ QTest::newRow("OutInQuart") << int(QEasingCurve::OutInQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.2952 << 0.4352 << 0.4872 << 0.4992 << 0.5 << 0.5008 << 0.5128 << 0.5648 << 0.7048 << 1);
+
+ QTest::newRow("InQuint") << int(QEasingCurve::InQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 1e-05 << 0.00032 << 0.00243 << 0.01024 << 0.03125 << 0.07776 << 0.1681 << 0.3277 << 0.5905 << 1);
+
+ QTest::newRow("OutQuint") << int(QEasingCurve::OutQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.4095 << 0.6723 << 0.8319 << 0.9222 << 0.9688 << 0.9898 << 0.9976 << 0.9997 << 1 << 1);
+
+ QTest::newRow("InOutQuint") << int(QEasingCurve::InOutQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.00016 << 0.00512 << 0.03888 << 0.1638 << 0.5 << 0.8362 << 0.9611 << 0.9949 << 0.9998 << 1);
+
+ QTest::newRow("OutInQuint") << int(QEasingCurve::OutInQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.3362 << 0.4611 << 0.4949 << 0.4998 << 0.5 << 0.5002 << 0.5051 << 0.5389 << 0.6638 << 1);
+
+ QTest::newRow("InSine") << int(QEasingCurve::InSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.01231 << 0.04894 << 0.109 << 0.191 << 0.2929 << 0.4122 << 0.546 << 0.691 << 0.8436 << 1);
+
+ QTest::newRow("OutSine") << int(QEasingCurve::OutSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.1564 << 0.309 << 0.454 << 0.5878 << 0.7071 << 0.809 << 0.891 << 0.9511 << 0.9877 << 1);
+
+ QTest::newRow("InOutSine") << int(QEasingCurve::InOutSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.02447 << 0.09549 << 0.2061 << 0.3455 << 0.5 << 0.6545 << 0.7939 << 0.9045 << 0.9755 << 1);
+
+ QTest::newRow("OutInSine") << int(QEasingCurve::OutInSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.1545 << 0.2939 << 0.4045 << 0.4755 << 0.5 << 0.5245 << 0.5955 << 0.7061 << 0.8455 << 1);
+
+ QTest::newRow("InExpo") << int(QEasingCurve::InExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.0009531 << 0.002906 << 0.006812 << 0.01462 << 0.03025 << 0.0615 << 0.124 << 0.249 << 0.499 << 1);
+
+ QTest::newRow("OutExpo") << int(QEasingCurve::OutExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.5005 << 0.7507 << 0.8759 << 0.9384 << 0.9697 << 0.9854 << 0.9932 << 0.9971 << 0.999 << 1);
+
+ QTest::newRow("InOutExpo") << int(QEasingCurve::InOutExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.001453 << 0.007312 << 0.03075 << 0.1245 << 0.5002 << 0.8754 << 0.9692 << 0.9927 << 0.9985 << 1);
+
+ QTest::newRow("OutInExpo") << int(QEasingCurve::OutInExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.3754 << 0.4692 << 0.4927 << 0.4985 << 0.5 << 0.5015 << 0.5073 << 0.5308 << 0.6245 << 1);
+
+ QTest::newRow("InCirc") << int(QEasingCurve::InCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.005013 << 0.0202 << 0.04606 << 0.08348 << 0.134 << 0.2 << 0.2859 << 0.4 << 0.5641 << 1);
+
+ QTest::newRow("OutCirc") << int(QEasingCurve::OutCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.4359 << 0.6 << 0.7141 << 0.8 << 0.866 << 0.9165 << 0.9539 << 0.9798 << 0.995 << 1);
+
+ QTest::newRow("InOutCirc") << int(QEasingCurve::InOutCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.0101 << 0.04174 << 0.1 << 0.2 << 0.5 << 0.8 << 0.9 << 0.9583 << 0.9899 << 1);
+
+ QTest::newRow("OutInCirc") << int(QEasingCurve::OutInCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.3 << 0.4 << 0.4583 << 0.4899 << 0.5 << 0.5101 << 0.5417 << 0.6 << 0.7 << 1);
+
+ QTest::newRow("InElastic") << int(QEasingCurve::InElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.001953 << -0.001953 << -0.003906 << 0.01562 << -0.01562 << -0.03125 << 0.125 << -0.125 << -0.25 << 1);
+
+ QTest::newRow("OutElastic") << int(QEasingCurve::OutElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 1.25 << 1.125 << 0.875 << 1.031 << 1.016 << 0.9844 << 1.004 << 1.002 << 0.998 << 1);
+
+ QTest::newRow("InOutElastic") << int(QEasingCurve::InOutElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << -0.0009766 << 0.007812 << -0.01563 << -0.0625 << 0.5 << 1.062 << 1.016 << 0.9922 << 1.001 << 1);
+
+ QTest::newRow("OutInElastic") << int(QEasingCurve::OutInElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.375 << 0.5625 << 0.4922 << 0.498 << 0.5 << 0.4961 << 0.5078 << 0.5313 << 0.25 << 1);
+
+ QTest::newRow("InBack") << int(QEasingCurve::InBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << -0.01431 << -0.04645 << -0.0802 << -0.09935 << -0.0877 << -0.02903 << 0.09287 << 0.2942 << 0.5912 << 1);
+
+ QTest::newRow("OutBack") << int(QEasingCurve::OutBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.4088 << 0.7058 << 0.9071 << 1.029 << 1.088 << 1.099 << 1.08 << 1.046 << 1.014 << 1);
+
+ QTest::newRow("InOutBack") << int(QEasingCurve::InOutBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << -0.03752 << -0.09256 << -0.07883 << 0.08993 << 0.5 << 0.9101 << 1.079 << 1.093 << 1.038 << 1);
+
+ QTest::newRow("OutInBack") << int(QEasingCurve::OutInBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.3529 << 0.5145 << 0.5497 << 0.5232 << 0.5 << 0.4768 << 0.4503 << 0.4855 << 0.6471 << 1);
+
+ QTest::newRow("InBounce") << int(QEasingCurve::InBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.01188 << 0.06 << 0.06937 << 0.2275 << 0.2344 << 0.09 << 0.3194 << 0.6975 << 0.9244 << 1);
+
+ QTest::newRow("OutBounce") << int(QEasingCurve::OutBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.07563 << 0.3025 << 0.6806 << 0.91 << 0.7656 << 0.7725 << 0.9306 << 0.94 << 0.9881 << 1);
+
+ QTest::newRow("InOutBounce") << int(QEasingCurve::InOutBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.03 << 0.1138 << 0.045 << 0.3488 << 0.5 << 0.6512 << 0.955 << 0.8862 << 0.97 << 1);
+
+ QTest::newRow("OutInBounce") << int(QEasingCurve::OutInBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.1513 << 0.41 << 0.2725 << 0.44 << 0.5 << 0.56 << 0.7275 << 0.59 << 0.8488 << 1);
+
+ QTest::newRow("InCurve") << int(QEasingCurve::InCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.02447 << 0.1059 << 0.2343 << 0.3727 << 0.5 << 0.6055 << 0.7 << 0.8 << 0.9 << 1);
+
+ QTest::newRow("OutCurve") << int(QEasingCurve::OutCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.1 << 0.2 << 0.3 << 0.3945 << 0.5 << 0.6273 << 0.7657 << 0.8941 << 0.9755 << 1);
+
+ QTest::newRow("SineCurve") << int(QEasingCurve::SineCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.09549 << 0.3455 << 0.6545 << 0.9045 << 1 << 0.9045 << 0.6545 << 0.3455 << 0.09549 << 0);
+
+ QTest::newRow("CosineCurve") << int(QEasingCurve::CosineCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0.5 << 0.7939 << 0.9755 << 0.9755 << 0.7939 << 0.5 << 0.2061 << 0.02447 << 0.02447 << 0.2061 << 0.5);
+
+ /*
+ QTest::newRow("InQuad") << int(QEasingCurve::InQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.01 << 0.04 << 0.09 << 0.16 << 0.25 << 0.36 << 0.49 << 0.64 << 0.81 << 1);
+ QTest::newRow("OutQuad") << int(QEasingCurve::OutQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0.19 << 0.36 << 0.51 << 0.64 << 0.75 << 0.84 << 0.91 << 0.96 << 0.99 << 1);
+
+ QTest::newRow("InOutQuad") << int(QEasingCurve::InOutQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 2 << 8 << 18 << 32 << 50 << 68 << 82 << 92 << 98 << 100);
+
+ QTest::newRow("OutInQuad") << int(QEasingCurve::OutInQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 18 << 32 << 42 << 48 << 50 << 52 << 57 << 68 << 82 << 100);
+
+ QTest::newRow("InCubic") << int(QEasingCurve::InCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0 << 0 << 2 << 6 << 12 << 21 << 34 << 51 << 72 << 100);
+
+ QTest::newRow("OutCubic") << int(QEasingCurve::OutCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 27 << 48 << 65 << 78 << 87 << 93 << 97 << 99 << 99 << 100);
+
+ QTest::newRow("InOutCubic") << int(QEasingCurve::InOutCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0 << 3 << 10 << 25 << 50 << 74 << 89 << 96 << 99 << 100);
+
+ QTest::newRow("OutInCubic") << int(QEasingCurve::OutInCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 24 << 39 << 46 << 49 << 50 << 50 << 53 << 60 << 75 << 100);
+
+ QTest::newRow("InQuart") << int(QEasingCurve::InQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0 << 0 << 0 << 2 << 6 << 12 << 24 << 40 << 65 << 100);
+
+ QTest::newRow("OutQuart") << int(QEasingCurve::OutQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 34 << 59 << 75 << 87 << 93 << 97 << 99 << 99 << 99 << 100);
+
+ QTest::newRow("InOutQuart") << int(QEasingCurve::InOutQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0 << 1 << 6 << 20 << 50 << 79 << 93 << 98 << 99 << 100);
+
+ QTest::newRow("OutInQuart") << int(QEasingCurve::OutInQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 29 << 43 << 48 << 49 << 50 << 50 << 51 << 56 << 70 << 100);
+
+ QTest::newRow("InQuint") << int(QEasingCurve::InQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0 << 0 << 0 << 1 << 3 << 7 << 16 << 32 << 59 << 100);
+
+ QTest::newRow("OutQuint") << int(QEasingCurve::OutQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 40 << 67 << 83 << 92 << 96 << 98 << 99 << 99 << 99 << 100);
+
+ QTest::newRow("InOutQuint") << int(QEasingCurve::InOutQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0 << 0 << 3 << 16 << 50 << 83 << 96 << 99 << 99 << 100);
+
+ QTest::newRow("OutInQuint") << int(QEasingCurve::OutInQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 33 << 46 << 49 << 49 << 50 << 50 << 50 << 53 << 66 << 100);
+
+ QTest::newRow("InSine") << int(QEasingCurve::InSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 1 << 4 << 10 << 19 << 29 << 41 << 54 << 69 << 84 << 100);
+
+ QTest::newRow("OutSine") << int(QEasingCurve::OutSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 15 << 30 << 45 << 58 << 70 << 80 << 89 << 95 << 98 << 100);
+
+ QTest::newRow("InOutSine") << int(QEasingCurve::InOutSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 2 << 9 << 20 << 34 << 49 << 65 << 79 << 90 << 97 << 100);
+
+ QTest::newRow("OutInSine") << int(QEasingCurve::OutInSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 15 << 29 << 40 << 47 << 50 << 52 << 59 << 70 << 84 << 100);
+
+ QTest::newRow("InExpo") << int(QEasingCurve::InExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0 << 0 << 0 << 1 << 3 << 6 << 12 << 24 << 49 << 100);
+
+ QTest::newRow("OutExpo") << int(QEasingCurve::OutExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 50 << 75 << 87 << 93 << 96 << 98 << 99 << 99 << 99 << 100);
+
+ QTest::newRow("InOutExpo") << int(QEasingCurve::InOutExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0 << 0 << 3 << 12 << 50 << 87 << 96 << 99 << 99 << 100);
+
+ QTest::newRow("OutInExpo") << int(QEasingCurve::OutInExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 37 << 46 << 49 << 49 << 50 << 50 << 50 << 53 << 62 << 100);
+
+ QTest::newRow("InCirc") << int(QEasingCurve::InCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0 << 2 << 4 << 8 << 13 << 19 << 28 << 40 << 56 << 100);
+
+ QTest::newRow("OutCirc") << int(QEasingCurve::OutCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 43 << 59 << 71 << 80 << 86 << 91 << 95 << 97 << 99 << 100);
+
+ QTest::newRow("InOutCirc") << int(QEasingCurve::InOutCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 1 << 4 << 9 << 20 << 50 << 80 << 89 << 95 << 98 << 100);
+
+ QTest::newRow("OutInCirc") << int(QEasingCurve::OutInCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 29 << 40 << 45 << 48 << 50 << 51 << 54 << 60 << 70 << 100);
+
+ QTest::newRow("InElastic") << int(QEasingCurve::InElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0 << 0 << 0 << 1 << -1 << -3 << 12 << -12 << -25 << 100);
+
+ QTest::newRow("OutElastic") << int(QEasingCurve::OutElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 125 << 112 << 87 << 103 << 101 << 98 << 100 << 100 << 99 << 100);
+
+ QTest::newRow("InOutElastic") << int(QEasingCurve::InOutElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 0 << 0 << -1 << -6 << 50 << 106 << 101 << 99 << 100 << 100);
+
+ QTest::newRow("OutInElastic") << int(QEasingCurve::OutInElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 37 << 56 << 49 << 49 << 50 << 49 << 50 << 53 << 24 << 100);
+
+ QTest::newRow("InBack") << int(QEasingCurve::InBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << -1 << -4 << -8 << -9 << -8 << -2 << 9 << 29 << 59 << 100);
+
+ QTest::newRow("OutBack") << int(QEasingCurve::OutBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 40 << 70 << 90 << 102 << 108 << 109 << 108 << 104 << 101 << 100);
+
+ QTest::newRow("InOutBack") << int(QEasingCurve::InOutBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << -3 << -9 << -7 << 8 << 50 << 91 << 107 << 109 << 103 << 100);
+
+ QTest::newRow("OutInBack") << int(QEasingCurve::OutInBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 35 << 51 << 54 << 52 << 50 << 47 << 45 << 48 << 64 << 100);
+
+ QTest::newRow("InBounce") << int(QEasingCurve::InBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 1 << 6 << 6 << 22 << 23 << 9 << 31 << 69 << 92 << 100);
+
+ QTest::newRow("OutBounce") << int(QEasingCurve::OutBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 7 << 30 << 68 << 90 << 76 << 77 << 93 << 94 << 98 << 100);
+
+ QTest::newRow("InOutBounce") << int(QEasingCurve::InOutBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 3 << 11 << 4 << 34 << 50 << 65 << 95 << 88 << 97 << 100);
+
+ QTest::newRow("OutInBounce") << int(QEasingCurve::OutInBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 15 << 40 << 27 << 43 << 50 << 56 << 72 << 58 << 84 << 100);
+
+ QTest::newRow("InCurve") << int(QEasingCurve::InCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 2 << 10 << 23 << 37 << 50 << 60 << 70 << 80 << 90 << 100);
+
+ QTest::newRow("OutCurve") << int(QEasingCurve::OutCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 10 << 20 << 30 << 39 << 50 << 62 << 76 << 89 << 97 << 100);
+
+ QTest::newRow("SineCurve") << int(QEasingCurve::SineCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 0 << 9 << 34 << 65 << 90 << 100 << 90 << 65 << 34 << 9 << 0);
+
+ QTest::newRow("CosineCurve") << int(QEasingCurve::CosineCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (IntList() << 50 << 79 << 97 << 97 << 79 << 50 << 20 << 2 << 2 << 20 << 49);
+*/
+}
+
+
+void tst_QEasingCurve::valueForProgress()
+{
+#if 0
+ // used to generate data tables...
+ QFile out;
+ out.open(stdout, QIODevice::WriteOnly);
+ for (int c = QEasingCurve::Linear; c < QEasingCurve::NCurveTypes - 1; ++c) {
+ QEasingCurve curve((QEasingCurve::Type)c);
+ QMetaObject mo = QEasingCurve::staticMetaObject;
+ QString strCurve = QLatin1String(mo.enumerator(mo.indexOfEnumerator("Type")).key(c));
+ QString strInputs;
+ QString strOutputs;
+
+ for (int t = 0; t <= 100; t+= 10) {
+ qreal ease = curve.valueForProgress(t/qreal(100));
+ strInputs += QString::fromAscii(" << %1").arg(t);
+ strOutputs += " << " + QString().setNum(ease, 'g', 4);
+ }
+ QString str = QString::fromAscii(" QTest::newRow(\"%1\") << int(QEasingCurve::%2)\n"
+ " << (IntList() %3)\n"
+ " << (RealList()%4);\n\n")
+ .arg(strCurve)
+ .arg(strCurve)
+ .arg(strInputs)
+ .arg(strOutputs);
+ out.write(str.toLatin1().constData());
+ }
+ out.close();
+ exit(1);
+#else
+ QFETCH(int, type);
+ QFETCH(IntList, at);
+ QFETCH(RealList, expected);
+
+ QEasingCurve curve((QEasingCurve::Type)type);
+ for (int i = 0; i < at.count(); ++i) {
+ qreal ease = curve.valueForProgress(at.at(i)/qreal(100));
+ // converting ease to 4 precision qreal to match the generated samples
+ qreal easeConv = qreal(QString().setNum(ease, 'g', 4).toDouble());
+ qreal ex = expected.at(i);
+ QVERIFY(qFuzzyCompare(easeConv, ex));
+ }
+#endif
+}
+
+static qreal discreteEase(qreal progress)
+{
+ return qFloor(progress * 10) / qreal(10.0);
+}
+
+void tst_QEasingCurve::setCustomType()
+{
+ QEasingCurve curve;
+ curve.setCustomType(&discreteEase);
+ QCOMPARE(curve.type(), QEasingCurve::Custom);
+ QCOMPARE(curve.valueForProgress(0.0), 0.0);
+ QCOMPARE(curve.valueForProgress(0.05), 0.0);
+ QCOMPARE(curve.valueForProgress(0.10), 0.1);
+ QCOMPARE(curve.valueForProgress(0.15), 0.1);
+ QCOMPARE(curve.valueForProgress(0.20), 0.2);
+ QCOMPARE(curve.valueForProgress(0.25), 0.2);
+ QCOMPARE(curve.valueForProgress(0.30), 0.3);
+ QCOMPARE(curve.valueForProgress(0.35), 0.3);
+ QCOMPARE(curve.valueForProgress(0.999999), 0.9);
+
+ curve.setType(QEasingCurve::Linear);
+ QCOMPARE(curve.type(), QEasingCurve::Linear);
+ QCOMPARE(curve.valueForProgress(0.0), 0.0);
+ QCOMPARE(curve.valueForProgress(0.1), 0.1);
+ QCOMPARE(curve.valueForProgress(0.5), 0.5);
+ QCOMPARE(curve.valueForProgress(0.99), 0.99);
+}
+
+void tst_QEasingCurve::operators()
+{
+ // operator=
+ QEasingCurve curve;
+ QEasingCurve curve2;
+ curve.setCustomType(&discreteEase);
+ curve2 = curve;
+ QCOMPARE(curve2.type(), QEasingCurve::Custom);
+ QCOMPARE(curve2.valueForProgress(0.0), 0.0);
+ QCOMPARE(curve2.valueForProgress(0.05), 0.0);
+ QCOMPARE(curve2.valueForProgress(0.15), 0.1);
+ QCOMPARE(curve2.valueForProgress(0.25), 0.2);
+ QCOMPARE(curve2.valueForProgress(0.35), 0.3);
+ QCOMPARE(curve2.valueForProgress(0.999999), 0.9);
+
+ // operator==
+ curve.setType(QEasingCurve::InBack);
+ curve2 = curve;
+ curve2.setOvershoot(qreal(1.70158f));
+ QCOMPARE(curve.overshoot(), curve2.overshoot());
+ QVERIFY(curve2 == curve);
+
+ curve.setOvershoot(3.0);
+ QVERIFY(curve2 != curve);
+ curve2.setOvershoot(3.0);
+ QVERIFY(curve2 == curve);
+
+ curve2.setType(QEasingCurve::Linear);
+ QCOMPARE(curve.overshoot(), curve2.overshoot());
+ QVERIFY(curve2 != curve);
+ curve2.setType(QEasingCurve::InBack);
+ QCOMPARE(curve.overshoot(), curve2.overshoot());
+ QVERIFY(curve2 == curve);
+}
+
+
+QTEST_MAIN(tst_QEasingCurve)
+#include "tst_qeasingcurve.moc"
+
+#endif //QT_VERSION
diff --git a/tests/auto/qfile/copy-fallback.qrc b/tests/auto/qfile/copy-fallback.qrc
new file mode 100644
index 0000000..864491f
--- /dev/null
+++ b/tests/auto/qfile/copy-fallback.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>copy-fallback.qrc</file>
+</qresource>
+</RCC>
diff --git a/tests/auto/qfile/test/test.pro b/tests/auto/qfile/test/test.pro
index 68f4c05..8d26f5e 100644
--- a/tests/auto/qfile/test/test.pro
+++ b/tests/auto/qfile/test/test.pro
@@ -17,7 +17,7 @@ QT = core network
DEFINES += SRCDIR=\\\"$$PWD/../\\\"
}
-RESOURCES += ../qfile.qrc ../rename-fallback.qrc
+RESOURCES += ../qfile.qrc ../rename-fallback.qrc ../copy-fallback.qrc
TARGET = ../tst_qfile
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp
index cb8091b..d650b0d 100644
--- a/tests/auto/qfile/tst_qfile.cpp
+++ b/tests/auto/qfile/tst_qfile.cpp
@@ -126,6 +126,7 @@ private slots:
void copyAfterFail();
void copyRemovesTemporaryFile() const;
void copyShouldntOverwrite();
+ void copyFallback();
void link();
void linkToDir();
void absolutePathLinkToRelativePath();
@@ -214,6 +215,13 @@ void tst_QFile::cleanup()
// TODO: Add cleanup code here.
// This will be executed immediately after each test is run.
+ // for copyFallback()
+ if (QFile::exists("file-copy-destination.txt")) {
+ QFile::setPermissions("file-copy-destination.txt",
+ QFile::ReadOwner | QFile::WriteOwner);
+ QFile::remove("file-copy-destination.txt");
+ }
+
// for renameFallback()
QFile::remove("file-rename-destination.txt");
@@ -948,6 +956,34 @@ void tst_QFile::copyShouldntOverwrite()
QFile::remove("tst_qfile.cpy");
}
+void tst_QFile::copyFallback()
+{
+ // Using a resource file to trigger QFile::copy's fallback handling
+ QFile file(":/copy-fallback.qrc");
+ QFile::remove("file-copy-destination.txt");
+
+ QVERIFY2(file.exists(), "test precondition");
+ QVERIFY2(!QFile::exists("file-copy-destination.txt"), "test precondition");
+
+ // Fallback copy of closed file.
+ QVERIFY(file.copy("file-copy-destination.txt"));
+ QVERIFY(QFile::exists("file-copy-destination.txt"));
+ QVERIFY(!file.isOpen());
+
+ // Need to reset permissions on Windows to be able to delete
+ QVERIFY(QFile::setPermissions("file-copy-destination.txt",
+ QFile::ReadOwner | QFile::WriteOwner));
+ QVERIFY(QFile::remove("file-copy-destination.txt"));
+
+ // Fallback copy of open file.
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QVERIFY(file.copy("file-copy-destination.txt"));
+ QVERIFY(QFile::exists("file-copy-destination.txt"));
+ QVERIFY(!file.isOpen());
+
+ QFile::remove("file-copy-destination.txt");
+}
+
#ifdef Q_OS_WIN
#include <objbase.h>
#include <shlobj.h>
@@ -2122,6 +2158,7 @@ void tst_QFile::renameFallback()
QVERIFY(!file.rename("file-rename-destination.txt"));
QVERIFY(!QFile::exists("file-rename-destination.txt"));
+ QVERIFY(!file.isOpen());
}
void tst_QFile::renameMultiple()
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index b3ae60a..c03c420 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -219,6 +219,8 @@ private slots:
void updateCachedItemAfterMove();
void deviceTransform_data();
void deviceTransform();
+ void setTransformProperties_data();
+ void setTransformProperties();
// task specific tests below me
void task141694_textItemEnsureVisible();
@@ -6390,5 +6392,129 @@ void tst_QGraphicsItem::deviceTransform()
QCOMPARE(rect3->deviceTransform(deviceX).map(QPointF(50, 50)), mapResult3);
}
+void tst_QGraphicsItem::setTransformProperties_data()
+{
+ QTest::addColumn<QPointF>("origin");
+ QTest::addColumn<qreal>("rotationX");
+ QTest::addColumn<qreal>("rotationY");
+ QTest::addColumn<qreal>("rotationZ");
+ QTest::addColumn<qreal>("scaleX");
+ QTest::addColumn<qreal>("scaleY");
+ QTest::addColumn<qreal>("shearX");
+ QTest::addColumn<qreal>("shearY");
+
+ QTest::newRow("nothing") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("rotationZ") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(42.2)
+ << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("rotationXY") << QPointF() << qreal(12.5) << qreal(53.6) << qreal(0.0)
+ << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("rotationXYZ") << QPointF() << qreal(-25) << qreal(12) << qreal(556)
+ << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("rotationXYZ dicentred") << QPointF(-53, 25.2)
+ << qreal(-2578.2) << qreal(4565.2) << qreal(56)
+ << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("Scale") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << qreal(6) << qreal(0.5) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("Shear") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << qreal(1) << qreal(1) << qreal(2.2) << qreal(0.5);
+
+ QTest::newRow("Scale and Shear") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << qreal(5.2) << qreal(2.1) << qreal(5.2) << qreal(5.5);
+
+ QTest::newRow("Everything") << QPointF() << qreal(41) << qreal(-23) << qreal(0.56)
+ << qreal(8.2) << qreal(-0.2) << qreal(-12) << qreal(-0.8);
+
+ QTest::newRow("Everything dicentred") << QPointF(qreal(22.3), qreal(-56.2)) << qreal(-175) << qreal(196) << qreal(-1260)
+ << qreal(4) << qreal(2) << qreal(2.56) << qreal(0.8);
+}
+
+void tst_QGraphicsItem::setTransformProperties()
+{
+ QFETCH(QPointF,origin);
+ QFETCH(qreal,rotationX);
+ QFETCH(qreal,rotationY);
+ QFETCH(qreal,rotationZ);
+ QFETCH(qreal,scaleX);
+ QFETCH(qreal,scaleY);
+ QFETCH(qreal,shearX);
+ QFETCH(qreal,shearY);
+
+ QTransform result;
+ result.translate(origin.x(), origin.y());
+ result.rotate(rotationX, Qt::XAxis);
+ result.rotate(rotationY, Qt::YAxis);
+ result.rotate(rotationZ, Qt::ZAxis);
+ result.shear(shearX, shearY);
+ result.scale(scaleX, scaleY);
+ result.translate(-origin.x(), -origin.y());
+
+ QGraphicsScene scene;
+ QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 100, 100));
+ scene.addItem(item);
+ item->setPos(100, 100);
+
+ item->setRotation(rotationX, rotationY, rotationZ);
+ item->setScale(scaleX, scaleY);
+ item->setShear(shearX, shearY);
+ item->setTransformOrigin(origin);
+
+ QCOMPARE(item->xRotation(), rotationX);
+ QCOMPARE(item->yRotation(), rotationY);
+ QCOMPARE(item->zRotation(), rotationZ);
+ QCOMPARE(item->xScale(), scaleX);
+ QCOMPARE(item->yScale(), scaleY);
+ QCOMPARE(item->horizontalShear(), shearX);
+ QCOMPARE(item->verticalShear(), shearY);
+ QCOMPARE(item->transformOrigin(), origin);
+
+ QCOMPARE(result, item->transform());
+
+ //-----------------------------------------------------------------
+ //Change the rotation Z
+ item->setZRotation(45);
+ QTransform result2;
+ result2.translate(origin.x(), origin.y());
+ result2.rotate(rotationX, Qt::XAxis);
+ result2.rotate(rotationY, Qt::YAxis);
+ result2.rotate(45, Qt::ZAxis);
+ result2.shear(shearX, shearY);
+ result2.scale(scaleX, scaleY);
+ result2.translate(-origin.x(), -origin.y());
+
+ QCOMPARE(item->xRotation(), rotationX);
+ QCOMPARE(item->yRotation(), rotationY);
+ QCOMPARE(item->zRotation(), 45.0);
+ QCOMPARE(item->xScale(), scaleX);
+ QCOMPARE(item->yScale(), scaleY);
+ QCOMPARE(item->horizontalShear(), shearX);
+ QCOMPARE(item->verticalShear(), shearY);
+ QCOMPARE(item->transformOrigin(), origin);
+
+ QCOMPARE(result2, item->transform());
+
+ //-----------------------------------------------------------------
+ // calling setTransform() should reset the properties to their default
+ item->setTransform(result);
+
+ QCOMPARE(item->xRotation(), 0.0);
+ QCOMPARE(item->yRotation(), 0.0);
+ QCOMPARE(item->zRotation(), 0.0);
+ QCOMPARE(item->xScale(), 1.0);
+ QCOMPARE(item->yScale(), 1.0);
+ QCOMPARE(item->horizontalShear(), 0.0);
+ QCOMPARE(item->verticalShear(), 0.0);
+ QCOMPARE(item->transformOrigin(), QPointF(0,0));
+
+ QCOMPARE(result, item->transform());
+}
+
+
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"
diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
index 27741e0..615ac01 100644
--- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
+++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
@@ -59,6 +59,8 @@
#include <QItemDelegate>
#include <QAbstractItemDelegate>
+#include <QTextEdit>
+#include <QPlainTextEdit>
Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint)
@@ -226,6 +228,8 @@ private slots:
void decoration();
void editorEvent_data();
void editorEvent();
+ void enterKey_data();
+ void enterKey();
};
@@ -1048,6 +1052,80 @@ void tst_QItemDelegate::editorEvent()
QCOMPARE(index.data(Qt::CheckStateRole).toInt(), expectedCheckState);
}
+void tst_QItemDelegate::enterKey_data()
+{
+ QTest::addColumn<int>("widget");
+ QTest::addColumn<int>("key");
+ QTest::addColumn<bool>("expectedFocus");
+
+ QTest::newRow("lineedit enter") << 1 << int(Qt::Key_Enter) << false;
+ QTest::newRow("textedit enter") << 2 << int(Qt::Key_Enter) << true;
+ QTest::newRow("plaintextedit enter") << 3 << int(Qt::Key_Enter) << true;
+ QTest::newRow("plaintextedit return") << 3 << int(Qt::Key_Return) << true;
+ QTest::newRow("plaintextedit tab") << 3 << int(Qt::Key_Tab) << false;
+ QTest::newRow("lineedit tab") << 1 << int(Qt::Key_Tab) << false;
+}
+
+void tst_QItemDelegate::enterKey()
+{
+ QFETCH(int, widget);
+ QFETCH(int, key);
+ QFETCH(bool, expectedFocus);
+
+ QStandardItemModel model;
+ model.appendRow(new QStandardItem());
+
+ QListView view;
+ view.setModel(&model);
+ view.show();
+ QApplication::setActiveWindow(&view);
+ view.setFocus();
+ QTest::qWait(30);
+
+ struct TestDelegate : public QItemDelegate
+ {
+ int widgetType;
+ virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
+ {
+ QWidget *editor = 0;
+ switch(widgetType) {
+ case 1:
+ editor = new QLineEdit(parent);
+ break;
+ case 2:
+ editor = new QTextEdit(parent);
+ break;
+ case 3:
+ editor = new QPlainTextEdit(parent);
+ break;
+ }
+ editor->setObjectName(QString::fromLatin1("TheEditor"));
+ return editor;
+ }
+ } delegate;
+
+ delegate.widgetType = widget;
+
+ view.setItemDelegate(&delegate);
+ QModelIndex index = model.index(0, 0);
+ view.setCurrentIndex(index); // the editor will only selectAll on the current index
+ view.edit(index);
+ QTest::qWait(30);
+
+ QList<QWidget*> lineEditors = qFindChildren<QWidget *>(view.viewport(), QString::fromLatin1("TheEditor"));
+ QCOMPARE(lineEditors.count(), 1);
+
+ QWidget *editor = lineEditors.at(0);
+ QCOMPARE(editor->hasFocus(), true);
+
+ QTest::keyClick(editor, Qt::Key(key));
+ QApplication::processEvents();
+
+ QCOMPARE(editor->hasFocus(), expectedFocus);
+}
+
+
+
// ### _not_ covered:
// editing with a custom editor factory
diff --git a/tests/auto/qmake/testdata/bundle-spaces/some-file b/tests/auto/qmake/testdata/bundle-spaces/some-file
index e69de29..9975dba 100644
--- a/tests/auto/qmake/testdata/bundle-spaces/some-file
+++ b/tests/auto/qmake/testdata/bundle-spaces/some-file
@@ -0,0 +1,6 @@
+all:
+ C:\git\qt-kinetic-animations\bin\qmake qdir.pro -o Makefile -spec win32-msvc2008
+ nmake -f Makefile
+first: all
+qmake:
+ C:\git\qt-kinetic-animations\bin\qmake qdir.pro -o Makefile -spec win32-msvc2008
diff --git a/tests/auto/qparallelanimationgroup/qparallelanimationgroup.pro b/tests/auto/qparallelanimationgroup/qparallelanimationgroup.pro
new file mode 100644
index 0000000..f2cacd3
--- /dev/null
+++ b/tests/auto/qparallelanimationgroup/qparallelanimationgroup.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+QT = core gui
+SOURCES += tst_qparallelanimationgroup.cpp
+
+
diff --git a/tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp b/tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp
new file mode 100644
index 0000000..f2ab57a
--- /dev/null
+++ b/tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp
@@ -0,0 +1,834 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtCore/qparallelanimationgroup.h>
+
+//TESTED_CLASS=QParallelAnimationGroup
+//TESTED_FILES=
+
+Q_DECLARE_METATYPE(QAbstractAnimation::State)
+
+class tst_QParallelAnimationGroup : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QParallelAnimationGroup();
+ virtual ~tst_QParallelAnimationGroup();
+
+public Q_SLOTS:
+ void init();
+ void cleanup();
+
+private slots:
+ void construction();
+ void setCurrentTime();
+ void clearGroup();
+ void propagateGroupUpdateToChildren();
+ void updateChildrenWithRunningGroup();
+ void deleteChildrenWithRunningGroup();
+ void startChildrenWithStoppedGroup();
+ void stopGroupWithRunningChild();
+ void startGroupWithRunningChild();
+ void zeroDurationAnimation();
+ void stopUncontrolledAnimations();
+ void loopCount_data();
+ void loopCount();
+ void autoAdd();
+};
+
+tst_QParallelAnimationGroup::tst_QParallelAnimationGroup()
+{
+}
+
+tst_QParallelAnimationGroup::~tst_QParallelAnimationGroup()
+{
+}
+
+void tst_QParallelAnimationGroup::init()
+{
+ qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
+}
+
+void tst_QParallelAnimationGroup::cleanup()
+{
+}
+
+void tst_QParallelAnimationGroup::construction()
+{
+ QParallelAnimationGroup animationgroup;
+}
+
+class AnimationObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value WRITE setValue)
+public:
+ AnimationObject(int startValue = 0)
+ : v(startValue)
+ { }
+
+ int value() const { return v; }
+ void setValue(int value) { v = value; }
+
+ int v;
+};
+
+class TestAnimation : public QVariantAnimation
+{
+ Q_OBJECT
+public:
+ virtual void updateCurrentValue(const QVariant &value) { Q_UNUSED(value)};
+ virtual void updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+ {
+ Q_UNUSED(oldState)
+ Q_UNUSED(newState)
+ };
+};
+
+class TestAnimation2 : public QVariantAnimation
+{
+ Q_OBJECT
+public:
+ TestAnimation2(QAbstractAnimation *animation) : QVariantAnimation(animation) {}
+ TestAnimation2(int duration, QAbstractAnimation *animation) : QVariantAnimation(animation), m_duration(duration) {}
+
+ virtual void updateCurrentValue(const QVariant &value) { Q_UNUSED(value)};
+ virtual void updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+ {
+ Q_UNUSED(oldState)
+ Q_UNUSED(newState)
+ };
+
+ virtual int duration() const {
+ return m_duration;
+ }
+private:
+ int m_duration;
+};
+
+class UncontrolledAnimation : public QPropertyAnimation
+{
+ Q_OBJECT
+public:
+ UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = 0)
+ : QPropertyAnimation(target, propertyName, parent), id(0)
+ {
+ setDuration(250);
+ }
+
+ int duration() const { return -1; /* not time driven */ }
+
+protected:
+ void timerEvent(QTimerEvent *event)
+ {
+ if (event->timerId() == id)
+ stop();
+ }
+
+ void updateRunning(bool running)
+ {
+ if (running) {
+ id = startTimer(500);
+ } else {
+ killTimer(id);
+ id = 0;
+ }
+ }
+
+private:
+ int id;
+};
+
+void tst_QParallelAnimationGroup::setCurrentTime()
+{
+ AnimationObject p_o1;
+ AnimationObject p_o2;
+ AnimationObject p_o3;
+ AnimationObject t_o1;
+ AnimationObject t_o2;
+
+ // parallel operating on different object/properties
+ QAnimationGroup *parallel = new QParallelAnimationGroup();
+ QVariantAnimation *a1_p_o1 = new QPropertyAnimation(&p_o1, "value");
+ QVariantAnimation *a1_p_o2 = new QPropertyAnimation(&p_o2, "value");
+ QVariantAnimation *a1_p_o3 = new QPropertyAnimation(&p_o3, "value");
+ a1_p_o2->setLoopCount(3);
+ parallel->addAnimation(a1_p_o1);
+ parallel->addAnimation(a1_p_o2);
+ parallel->addAnimation(a1_p_o3);
+
+ UncontrolledAnimation *notTimeDriven = new UncontrolledAnimation(&t_o1, "value");
+ QCOMPARE(notTimeDriven->totalDuration(), -1);
+
+ QVariantAnimation *loopsForever = new QPropertyAnimation(&t_o2, "value");
+ loopsForever->setLoopCount(-1);
+ QCOMPARE(loopsForever->totalDuration(), -1);
+
+ QParallelAnimationGroup group;
+ group.addAnimation(parallel);
+ group.addAnimation(notTimeDriven);
+ group.addAnimation(loopsForever);
+
+ // Current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(parallel->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o3->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(a1_p_o1->currentTime(), 1);
+ QCOMPARE(a1_p_o2->currentTime(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 1);
+ QCOMPARE(notTimeDriven->currentTime(), 1);
+ QCOMPARE(loopsForever->currentTime(), 1);
+
+ // Current time = 250
+ group.setCurrentTime(250);
+ QCOMPARE(group.currentTime(), 250);
+ QCOMPARE(a1_p_o1->currentTime(), 250);
+ QCOMPARE(a1_p_o2->currentTime(), 0);
+ QCOMPARE(a1_p_o2->currentLoop(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 250);
+ QCOMPARE(loopsForever->currentTime(), 0);
+ QCOMPARE(loopsForever->currentLoop(), 1);
+
+ // Current time = 251
+ group.setCurrentTime(251);
+ QCOMPARE(group.currentTime(), 251);
+ QCOMPARE(a1_p_o1->currentTime(), 250);
+ QCOMPARE(a1_p_o2->currentTime(), 1);
+ QCOMPARE(a1_p_o2->currentLoop(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 251);
+ QCOMPARE(loopsForever->currentTime(), 1);
+}
+
+void tst_QParallelAnimationGroup::clearGroup()
+{
+ QParallelAnimationGroup group;
+
+ for (int i = 0; i < 10; ++i) {
+ new QParallelAnimationGroup(&group);
+ }
+
+ QCOMPARE(group.animationCount(), 10);
+
+ int count = group.animationCount();
+ QPointer<QAbstractAnimation> *children = new QPointer<QAbstractAnimation>[count];
+ for (int i = 0; i < count; ++i) {
+ QVERIFY(group.animationAt(i) != 0);
+ children[i] = group.animationAt(i);
+ }
+
+ group.clearAnimations();
+ QCOMPARE(group.animationCount(), 0);
+ QCOMPARE(group.currentTime(), 0);
+ for (int i = 0; i < count; ++i)
+ QCOMPARE(children[i], QPointer<QAbstractAnimation>());
+
+ delete[] children;
+}
+
+void tst_QParallelAnimationGroup::propagateGroupUpdateToChildren()
+{
+ // this test verifies if group state changes are updating its children correctly
+ QParallelAnimationGroup group;
+
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation anim1(&o, "ole");
+ anim1.setEndValue(43);
+ anim1.setDuration(100);
+ QVERIFY(!anim1.currentValue().isValid());
+ QCOMPARE(anim1.currentValue().toInt(), 0);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QVERIFY(anim2.currentValue().isValid());
+ QCOMPARE(anim2.currentValue().toInt(), 0);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ group.start();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Running);
+
+ group.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(anim1.state(), QAnimationGroup::Paused);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QParallelAnimationGroup::updateChildrenWithRunningGroup()
+{
+ // assert that its possible to modify a child's state directly while their group is running
+ QParallelAnimationGroup group;
+
+ TestAnimation anim;
+ anim.setStartValue(0);
+ anim.setEndValue(100);
+ anim.setDuration(200);
+
+ QSignalSpy groupStateChangedSpy(&group, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy childStateChangedSpy(&anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QCOMPARE(groupStateChangedSpy.count(), 0);
+ QCOMPARE(childStateChangedSpy.count(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim);
+
+ group.start();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Running);
+
+ QCOMPARE(groupStateChangedSpy.count(), 1);
+ QCOMPARE(childStateChangedSpy.count(), 1);
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(childStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+
+ // starting directly a running child will not have any effect
+ anim.start();
+
+ QCOMPARE(groupStateChangedSpy.count(), 1);
+ QCOMPARE(childStateChangedSpy.count(), 1);
+
+ anim.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Paused);
+
+ // in the animation stops directly, the group will still be running
+ anim.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QParallelAnimationGroup::deleteChildrenWithRunningGroup()
+{
+ // test if children can be activated when their group is stopped
+ QParallelAnimationGroup group;
+
+ QVariantAnimation *anim1 = new TestAnimation;
+ anim1->setStartValue(0);
+ anim1->setEndValue(100);
+ anim1->setDuration(200);
+ group.addAnimation(anim1);
+
+ QCOMPARE(group.duration(), anim1->duration());
+
+ group.start();
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1->state(), QAnimationGroup::Running);
+
+ QTest::qWait(50);
+ QVERIFY(group.currentTime() > 0);
+
+ delete anim1;
+ QVERIFY(group.animationCount() == 0);
+ QCOMPARE(group.duration(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.currentTime(), 0); //that's the invariant
+}
+
+void tst_QParallelAnimationGroup::startChildrenWithStoppedGroup()
+{
+ // test if children can be activated when their group is stopped
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(200);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ anim1.start();
+ anim2.start();
+ anim2.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+}
+
+void tst_QParallelAnimationGroup::stopGroupWithRunningChild()
+{
+ // children that started independently will not be affected by a group stop
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(200);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ anim1.start();
+ anim2.start();
+ anim2.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ anim1.stop();
+ anim2.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QParallelAnimationGroup::startGroupWithRunningChild()
+{
+ // as the group has precedence over its children, starting a group will restart all the children
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(200);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QSignalSpy stateChangedSpy1(&anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy stateChangedSpy2(&anim2, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QCOMPARE(stateChangedSpy1.count(), 0);
+ QCOMPARE(stateChangedSpy2.count(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ anim1.start();
+ anim2.start();
+ anim2.pause();
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(1).at(1)),
+ QAnimationGroup::Paused);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ group.start();
+
+ QCOMPARE(stateChangedSpy1.count(), 3);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(1).at(1)),
+ QAnimationGroup::Stopped);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(2).at(1)),
+ QAnimationGroup::Running);
+
+ QCOMPARE(stateChangedSpy2.count(), 4);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(2).at(1)),
+ QAnimationGroup::Stopped);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(3).at(1)),
+ QAnimationGroup::Running);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Running);
+}
+
+void tst_QParallelAnimationGroup::zeroDurationAnimation()
+{
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(0);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(100);
+
+ QSignalSpy stateChangedSpy1(&anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy finishedSpy1(&anim1, SIGNAL(finished()));
+
+ QSignalSpy stateChangedSpy2(&anim2, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy finishedSpy2(&anim2, SIGNAL(finished()));
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+ QCOMPARE(stateChangedSpy1.count(), 0);
+ group.start();
+ QCOMPARE(stateChangedSpy1.count(), 2);
+ QCOMPARE(finishedSpy1.count(), 1);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(1).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(stateChangedSpy2.count(), 1);
+ QCOMPARE(finishedSpy2.count(), 0);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(0).at(1)),
+ QAnimationGroup::Running);
+
+
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Running);
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+
+
+ group.stop();
+ group.setLoopCount(4);
+ stateChangedSpy1.clear();
+ stateChangedSpy2.clear();
+
+ group.start();
+ QCOMPARE(stateChangedSpy1.count(), 2);
+ QCOMPARE(stateChangedSpy2.count(), 1);
+ group.setCurrentTime(50);
+ QCOMPARE(stateChangedSpy1.count(), 2);
+ QCOMPARE(stateChangedSpy2.count(), 1);
+ group.setCurrentTime(150);
+ QCOMPARE(stateChangedSpy1.count(), 4);
+ QCOMPARE(stateChangedSpy2.count(), 3);
+ group.setCurrentTime(50);
+ QCOMPARE(stateChangedSpy1.count(), 6);
+ QCOMPARE(stateChangedSpy2.count(), 5);
+
+}
+
+void tst_QParallelAnimationGroup::stopUncontrolledAnimations()
+{
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(0);
+
+ AnimationObject o1;
+ UncontrolledAnimation notTimeDriven(&o1, "value");
+ QCOMPARE(notTimeDriven.totalDuration(), -1);
+
+ TestAnimation loopsForever;
+ loopsForever.setStartValue(0);
+ loopsForever.setEndValue(100);
+ loopsForever.setDuration(100);
+ loopsForever.setLoopCount(-1);
+
+ QSignalSpy stateChangedSpy(&anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&notTimeDriven);
+ group.addAnimation(&loopsForever);
+
+ group.start();
+
+ QCOMPARE(stateChangedSpy.count(), 2);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Running);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+
+ notTimeDriven.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Running);
+
+ loopsForever.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Stopped);
+}
+
+struct AnimState {
+ AnimState(int time = -1) : time(time), state(-1) {}
+ AnimState(int time, int state) : time(time), state(state) {}
+ int time;
+ int state;
+};
+
+#define Running QAbstractAnimation::Running
+#define Stopped QAbstractAnimation::Stopped
+
+Q_DECLARE_METATYPE(AnimState)
+void tst_QParallelAnimationGroup::loopCount_data()
+{
+ QTest::addColumn<bool>("directionBackward");
+ QTest::addColumn<int>("setLoopCount");
+ QTest::addColumn<int>("initialGroupTime");
+ QTest::addColumn<int>("currentGroupTime");
+ QTest::addColumn<AnimState>("expected1");
+ QTest::addColumn<AnimState>("expected2");
+ QTest::addColumn<AnimState>("expected3");
+
+ // D U R A T I O N
+ // 100 60*2 0
+ // direction = Forward
+ QTest::newRow("50") << false << 3 << 0 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("100") << false << 3 << 0 << 100 << AnimState(100 ) << AnimState( 40, Running) << AnimState( 0, Stopped);
+ QTest::newRow("110") << false << 3 << 0 << 110 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("120") << false << 3 << 0 << 120 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
+
+ QTest::newRow("170") << false << 3 << 0 << 170 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("220") << false << 3 << 0 << 220 << AnimState(100 ) << AnimState( 40, Running) << AnimState( 0, Stopped);
+ QTest::newRow("230") << false << 3 << 0 << 230 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("240") << false << 3 << 0 << 240 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
+
+ QTest::newRow("290") << false << 3 << 0 << 290 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("340") << false << 3 << 0 << 340 << AnimState(100 ) << AnimState( 40, Running) << AnimState( 0, Stopped);
+ QTest::newRow("350") << false << 3 << 0 << 350 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("360") << false << 3 << 0 << 360 << AnimState(100, Stopped) << AnimState( 60 ) << AnimState( 0, Stopped);
+
+ QTest::newRow("410") << false << 3 << 0 << 410 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
+ QTest::newRow("460") << false << 3 << 0 << 460 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
+ QTest::newRow("470") << false << 3 << 0 << 470 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
+ QTest::newRow("480") << false << 3 << 0 << 480 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
+
+ // direction = Forward, rewind
+ QTest::newRow("120-110") << false << 3 << 120 << 110 << AnimState( 0, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("120-50") << false << 3 << 120 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("120-0") << false << 3 << 120 << 0 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
+ QTest::newRow("300-110") << false << 3 << 300 << 110 << AnimState( 0, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("300-50") << false << 3 << 300 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("300-0") << false << 3 << 300 << 0 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
+ QTest::newRow("115-105") << false << 3 << 115 << 105 << AnimState( 42, Stopped) << AnimState( 45, Running) << AnimState( 0, Stopped);
+
+ // direction = Backward
+ QTest::newRow("b120-120") << true << 3 << 120 << 120 << AnimState( 42, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b120-110") << true << 3 << 120 << 110 << AnimState( 42, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b120-100") << true << 3 << 120 << 100 << AnimState(100, Running) << AnimState( 40, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b120-50") << true << 3 << 120 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b120-0") << true << 3 << 120 << 0 << AnimState( 0, Stopped) << AnimState( 0, Stopped) << AnimState( 0, Stopped);
+ QTest::newRow("b360-170") << true << 3 << 360 << 170 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b360-220") << true << 3 << 360 << 220 << AnimState(100, Running) << AnimState( 40, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b360-210") << true << 3 << 360 << 210 << AnimState( 90, Running) << AnimState( 30, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b360-120") << true << 3 << 360 << 120 << AnimState( 0, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
+
+ // rewind, direction = Backward
+ QTest::newRow("b50-110") << true << 3 << 50 << 110 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b50-120") << true << 3 << 50 << 120 << AnimState(100, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b50-140") << true << 3 << 50 << 140 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b50-240") << true << 3 << 50 << 240 << AnimState(100, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b50-260") << true << 3 << 50 << 260 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b50-350") << true << 3 << 50 << 350 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+
+ // infinite looping
+ QTest::newRow("inf1220") << false << -1 << 0 << 1220 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
+ QTest::newRow("inf1310") << false << -1 << 0 << 1310 << AnimState( 100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ // infinite looping, direction = Backward (will only loop once)
+ QTest::newRow("b.inf120-120") << true << -1 << 120 << 120 << AnimState( 42, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b.inf120-20") << true << -1 << 120 << 20 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b.inf120-110") << true << -1 << 120 << 110 << AnimState( 42, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+
+
+}
+
+void tst_QParallelAnimationGroup::loopCount()
+{
+ QFETCH(bool, directionBackward);
+ QFETCH(int, setLoopCount);
+ QFETCH(int, initialGroupTime);
+ QFETCH(int, currentGroupTime);
+ QFETCH(AnimState, expected1);
+ QFETCH(AnimState, expected2);
+ QFETCH(AnimState, expected3);
+
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(100);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(60); //total 120
+ anim2.setLoopCount(2);
+
+ TestAnimation anim3;
+ anim3.setStartValue(0);
+ anim3.setEndValue(100);
+ anim3.setDuration(0);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+ group.addAnimation(&anim3);
+
+ group.setLoopCount(setLoopCount);
+ if (initialGroupTime >= 0)
+ group.setCurrentTime(initialGroupTime);
+ if (directionBackward)
+ group.setDirection(QAbstractAnimation::Backward);
+
+ group.start();
+ if (initialGroupTime >= 0)
+ group.setCurrentTime(initialGroupTime);
+
+ anim1.setCurrentTime(42); // 42 is "untouched"
+ anim2.setCurrentTime(42);
+
+ group.setCurrentTime(currentGroupTime);
+
+ QCOMPARE(anim1.currentTime(), expected1.time);
+ QCOMPARE(anim2.currentTime(), expected2.time);
+ QCOMPARE(anim3.currentTime(), expected3.time);
+
+ if (expected1.state >=0)
+ QCOMPARE(int(anim1.state()), expected1.state);
+ if (expected2.state >=0)
+ QCOMPARE(int(anim2.state()), expected2.state);
+ if (expected3.state >=0)
+ QCOMPARE(int(anim3.state()), expected3.state);
+
+}
+
+void tst_QParallelAnimationGroup::autoAdd()
+{
+ QParallelAnimationGroup group;
+ QCOMPARE(group.duration(), 0);
+ TestAnimation2 *test = new TestAnimation2(250, &group); // 0, duration = 250;
+ QCOMPARE(test->group(), &group);
+ QCOMPARE(test->duration(), 250);
+ QCOMPARE(group.duration(), 250);
+
+ test = new TestAnimation2(750, &group); // 1
+ QCOMPARE(test->group(), &group);
+ QCOMPARE(group.duration(), 750);
+ test = new TestAnimation2(500, &group); // 2
+ QCOMPARE(test->group(), &group);
+ QCOMPARE(group.duration(), 750);
+
+ delete group.animationAt(1); // remove the one with duration = 750
+ QCOMPARE(group.duration(), 500);
+
+ delete group.animationAt(1); // remove the one with duration = 500
+ QCOMPARE(group.duration(), 250);
+
+ test = static_cast<TestAnimation2*>(group.animationAt(0));
+ test->setParent(0); // remove the last one (with duration = 250)
+ QCOMPARE(test->group(), static_cast<QAnimationGroup*>(0));
+ QCOMPARE(group.duration(), 0);
+}
+
+QTEST_MAIN(tst_QParallelAnimationGroup)
+#include "tst_qparallelanimationgroup.moc"
diff --git a/tests/auto/qpropertyanimation/qpropertyanimation.pro b/tests/auto/qpropertyanimation/qpropertyanimation.pro
new file mode 100644
index 0000000..6d6ddbf
--- /dev/null
+++ b/tests/auto/qpropertyanimation/qpropertyanimation.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+QT = core gui
+SOURCES += tst_qpropertyanimation.cpp
+
+
diff --git a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp
new file mode 100644
index 0000000..7e910d4
--- /dev/null
+++ b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp
@@ -0,0 +1,919 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtCore/qpropertyanimation.h>
+#include <QtCore/qvariantanimation.h>
+#include <QtGui/qwidget.h>
+
+//TESTED_CLASS=QPropertyAnimation
+//TESTED_FILES=
+
+class UncontrolledAnimation : public QPropertyAnimation
+{
+ Q_OBJECT
+public:
+ int duration() const { return -1; /* not time driven */ }
+
+protected:
+ void updateCurrentTime(int msecs)
+ {
+ QPropertyAnimation::updateCurrentTime(msecs);
+ if (msecs >= QPropertyAnimation::duration())
+ stop();
+ }
+};
+
+class tst_QPropertyAnimation : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QPropertyAnimation();
+ virtual ~tst_QPropertyAnimation();
+
+public Q_SLOTS:
+ void init();
+ void cleanup();
+
+private slots:
+ void construction();
+ void setCurrentTime_data();
+ void setCurrentTime();
+ void statesAndSignals_data();
+ void statesAndSignals();
+ void deletion1();
+ void deletion2();
+ void deletion3();
+ void duration0();
+ void noStartValue();
+ void noStartValueWithLoop();
+ void startWhenAnotherIsRunning();
+ void easingcurve_data();
+ void easingcurve();
+ void startWithoutStartValue();
+ void playForwardBackward();
+ void interpolated();
+ void setStartEndValues();
+ void zeroDurationStart();
+ void operationsInStates_data();
+ void operationsInStates();
+ void oneKeyValue();
+ void updateOnSetKeyValues();
+};
+
+tst_QPropertyAnimation::tst_QPropertyAnimation()
+{
+}
+
+tst_QPropertyAnimation::~tst_QPropertyAnimation()
+{
+}
+
+void tst_QPropertyAnimation::init()
+{
+ qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
+ qRegisterMetaType<QAbstractAnimation::DeletionPolicy>("QAbstractAnimation::DeletionPolicy");
+}
+
+void tst_QPropertyAnimation::cleanup()
+{
+}
+
+class AnimationObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value WRITE setValue)
+ Q_PROPERTY(qreal realValue READ realValue WRITE setRealValue)
+public:
+ AnimationObject(int startValue = 0)
+ : v(startValue)
+ { }
+
+ int value() const { return v; }
+ void setValue(int value) { v = value; }
+
+ qreal realValue() const { return rv; }
+ void setRealValue(qreal value) { rv = value; }
+
+ int v;
+ qreal rv;
+};
+
+
+void tst_QPropertyAnimation::construction()
+{
+ QPropertyAnimation panimation;
+}
+
+void tst_QPropertyAnimation::setCurrentTime_data()
+{
+ QTest::addColumn<int>("duration");
+ QTest::addColumn<int>("loopCount");
+ QTest::addColumn<int>("currentTime");
+ QTest::addColumn<int>("testCurrentTime");
+ QTest::addColumn<int>("testCurrentLoop");
+
+ QTest::newRow("-1") << -1 << 1 << 0 << 0 << 0;
+ QTest::newRow("0") << 0 << 1 << 0 << 0 << 0;
+ QTest::newRow("1") << 0 << 1 << 1 << 0 << 0;
+ QTest::newRow("2") << 0 << 2 << 1 << 0 << 0;
+ QTest::newRow("3") << 1 << 1 << 0 << 0 << 0;
+ QTest::newRow("4") << 1 << 1 << 1 << 1 << 0;
+ QTest::newRow("5") << 1 << 2 << 1 << 0 << 1;
+ QTest::newRow("6") << 1 << 2 << 2 << 1 << 1;
+ QTest::newRow("7") << 1 << 2 << 3 << 1 << 1;
+ QTest::newRow("8") << 1 << 3 << 2 << 0 << 2;
+ QTest::newRow("9") << 1 << 3 << 3 << 1 << 2;
+ QTest::newRow("a") << 10 << 1 << 0 << 0 << 0;
+ QTest::newRow("b") << 10 << 1 << 1 << 1 << 0;
+ QTest::newRow("c") << 10 << 1 << 10 << 10 << 0;
+ QTest::newRow("d") << 10 << 2 << 10 << 0 << 1;
+ QTest::newRow("e") << 10 << 2 << 11 << 1 << 1;
+ QTest::newRow("f") << 10 << 2 << 20 << 10 << 1;
+ QTest::newRow("g") << 10 << 2 << 21 << 10 << 1;
+ QTest::newRow("negloop 0") << 10 << -1 << 0 << 0 << 0;
+ QTest::newRow("negloop 1") << 10 << -1 << 10 << 0 << 1;
+ QTest::newRow("negloop 2") << 10 << -1 << 15 << 5 << 1;
+ QTest::newRow("negloop 3") << 10 << -1 << 20 << 0 << 2;
+ QTest::newRow("negloop 4") << 10 << -1 << 30 << 0 << 3;
+}
+
+void tst_QPropertyAnimation::setCurrentTime()
+{
+ QFETCH(int, duration);
+ QFETCH(int, loopCount);
+ QFETCH(int, currentTime);
+ QFETCH(int, testCurrentTime);
+ QFETCH(int, testCurrentLoop);
+
+ QPropertyAnimation animation;
+ if (duration < 0)
+ QTest::ignoreMessage(QtWarningMsg, "QVariantAnimation::setDuration: cannot set a negative duration");
+ animation.setDuration(duration);
+ animation.setLoopCount(loopCount);
+ animation.setCurrentTime(currentTime);
+
+ QCOMPARE(animation.currentTime(), testCurrentTime);
+ QCOMPARE(animation.currentLoop(), testCurrentLoop);
+}
+
+void tst_QPropertyAnimation::statesAndSignals_data()
+{
+ QTest::addColumn<bool>("uncontrolled");
+ QTest::newRow("normal animation") << false;
+ QTest::newRow("animation with undefined duration") << true;
+}
+
+void tst_QPropertyAnimation::statesAndSignals()
+{
+ QFETCH(bool, uncontrolled);
+ QPropertyAnimation *anim = uncontrolled ? new UncontrolledAnimation : new QPropertyAnimation;
+ anim->setDuration(100);
+
+ QSignalSpy finishedSpy(anim, SIGNAL(finished()));
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy currentLoopSpy(anim, SIGNAL(currentLoopChanged(int)));
+
+ anim->setCurrentTime(1);
+ anim->setCurrentTime(100);
+ QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(runningSpy.count(), 0);
+ QCOMPARE(currentLoopSpy.count(), 0);
+ QCOMPARE(anim->state(), QAnimationGroup::Stopped);
+
+ anim->setLoopCount(3);
+ anim->setCurrentTime(101);
+
+ if (uncontrolled)
+ QSKIP("Uncontrolled animations don't handle looping", SkipSingle);
+
+ QCOMPARE(currentLoopSpy.count(), 1);
+ QCOMPARE(anim->currentLoop(), 1);
+
+ anim->setCurrentTime(0);
+ QCOMPARE(currentLoopSpy.count(), 2);
+ QCOMPARE(anim->currentLoop(), 0);
+
+ anim->start();
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QCOMPARE(runningSpy.count(), 1); //anim must have started
+ QCOMPARE(anim->currentLoop(), 0);
+ runningSpy.clear();
+
+ anim->stop();
+ QCOMPARE(anim->state(), QAnimationGroup::Stopped);
+ QCOMPARE(runningSpy.count(), 1); //anim must have stopped
+ QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(anim->currentTime(), 0);
+ QCOMPARE(anim->currentLoop(), 0);
+ QCOMPARE(currentLoopSpy.count(), 2);
+ runningSpy.clear();
+
+ anim->start();
+ QTest::qWait(1000);
+ QCOMPARE(anim->state(), QAnimationGroup::Stopped);
+ QCOMPARE(runningSpy.count(), 2); //started and stopped again
+ runningSpy.clear();
+ QCOMPARE(finishedSpy.count(), 1);
+ QCOMPARE(anim->currentTime(), 100);
+ QCOMPARE(anim->currentLoop(), 2);
+ QCOMPARE(currentLoopSpy.count(), 4);
+
+ anim->start(); // auto-rewinds
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QCOMPARE(anim->currentTime(), 0);
+ QCOMPARE(anim->currentLoop(), 0);
+ QCOMPARE(currentLoopSpy.count(), 5);
+ QCOMPARE(runningSpy.count(), 1); // anim has started
+ QCOMPARE(finishedSpy.count(), 1);
+ QCOMPARE(anim->currentLoop(), 0);
+ runningSpy.clear();
+
+ QTest::qWait(1000);
+
+ QCOMPARE(currentLoopSpy.count(), 7);
+ QCOMPARE(anim->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim->currentLoop(), 2);
+ QCOMPARE(runningSpy.count(), 1); // anim has stopped
+ QCOMPARE(finishedSpy.count(), 2);
+ QCOMPARE(anim->currentTime(), 100);
+
+ delete anim;
+}
+
+void tst_QPropertyAnimation::deletion1()
+{
+ QObject *object = new QWidget;
+ QPointer<QPropertyAnimation> anim = new QPropertyAnimation(object,"minimumWidth");
+
+ //test that the animation is deleted correctly depending of the deletion flag passed in start()
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy finishedSpy(anim, SIGNAL(finished()));
+ anim->setStartValue(10);
+ anim->setEndValue(20);
+ anim->setDuration(200);
+ anim->start();
+ QCOMPARE(runningSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ QVERIFY(anim);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QTest::qWait(100);
+ QVERIFY(anim);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QTest::qWait(150);
+ QVERIFY(anim); //The animation should not have been deleted
+ QCOMPARE(anim->state(), QAnimationGroup::Stopped);
+ QCOMPARE(runningSpy.count(), 2);
+ QCOMPARE(finishedSpy.count(), 1);
+
+ anim->start(QVariantAnimation::DeleteWhenStopped);
+ QVERIFY(anim);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QTest::qWait(100);
+ QVERIFY(anim);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QTest::qWait(150);
+ QVERIFY(!anim); //The animation must have been deleted
+ QCOMPARE(runningSpy.count(), 4);
+ QCOMPARE(finishedSpy.count(), 2);
+ delete object;
+}
+
+void tst_QPropertyAnimation::deletion2()
+{
+ //test that the animation get deleted if the object is deleted
+ QObject *object = new QWidget;
+ QPointer<QPropertyAnimation> anim = new QPropertyAnimation(object,"minimumWidth");
+ anim->setStartValue(10);
+ anim->setEndValue(20);
+ anim->setDuration(200);
+
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy finishedSpy(anim, SIGNAL(finished()));
+
+ anim->setStartValue(10);
+ anim->setEndValue(20);
+ anim->setDuration(200);
+ anim->start();
+
+ QTest::qWait(50);
+ QVERIFY(anim);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+
+ QCOMPARE(runningSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ //we can't call deletaLater directly because the delete would only happen in the next loop of _this_ event loop
+ QTimer::singleShot(0, object, SLOT(deleteLater()));
+ QTest::qWait(50);
+
+ QVERIFY(anim->targetObject() == 0);
+}
+
+void tst_QPropertyAnimation::deletion3()
+{
+ //test that the stopped signal is emit when the animation is destroyed
+ QObject *object = new QWidget;
+ QPropertyAnimation *anim = new QPropertyAnimation(object,"minimumWidth");
+ anim->setStartValue(10);
+ anim->setEndValue(20);
+ anim->setDuration(200);
+
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy finishedSpy(anim, SIGNAL(finished()));
+ anim->start();
+
+ QTest::qWait(50);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QCOMPARE(runningSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+ delete anim;
+ QCOMPARE(runningSpy.count(), 2);
+ QCOMPARE(finishedSpy.count(), 0);
+}
+
+void tst_QPropertyAnimation::duration0()
+{
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation animation(&o, "ole");
+ animation.setEndValue(43);
+ QVERIFY(!animation.currentValue().isValid());
+ QCOMPARE(animation.currentValue().toInt(), 0);
+ QCOMPARE(o.property("ole").toInt(), 42);
+ animation.setDuration(0);
+ animation.start();
+ QCOMPARE(animation.state(), QAnimationGroup::Stopped);
+ QCOMPARE(animation.currentTime(), 0);
+ QCOMPARE(o.property("ole").toInt(), 43);
+}
+
+class StartValueTester : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int ole READ ole WRITE setOle)
+public:
+ StartValueTester() : o(0) { }
+ int ole() const { return o; }
+ void setOle(int v) { o = v; values << v; }
+
+ int o;
+ QList<int> values;
+};
+
+void tst_QPropertyAnimation::noStartValue()
+{
+ StartValueTester o;
+ o.setProperty("ole", 42);
+ o.values.clear();
+
+ QPropertyAnimation a(&o, "ole");
+ a.setEndValue(420);
+ a.setDuration(250);
+ a.start();
+
+ QTest::qWait(300);
+
+ QCOMPARE(o.values.first(), 42);
+ QCOMPARE(o.values.last(), 420);
+}
+
+void tst_QPropertyAnimation::noStartValueWithLoop()
+{
+ StartValueTester o;
+ o.setProperty("ole", 42);
+ o.values.clear();
+
+ QPropertyAnimation a(&o, "ole");
+ a.setEndValue(420);
+ a.setDuration(250);
+ a.setLoopCount(2);
+ a.start();
+
+ a.setCurrentTime(250);
+ QCOMPARE(o.values.first(), 42);
+ QCOMPARE(a.currentValue().toInt(), 42);
+ QCOMPARE(o.values.last(), 42);
+
+ a.setCurrentTime(500);
+ QCOMPARE(a.currentValue().toInt(), 420);
+}
+
+void tst_QPropertyAnimation::startWhenAnotherIsRunning()
+{
+ StartValueTester o;
+ o.setProperty("ole", 42);
+ o.values.clear();
+
+ {
+ //normal case: the animation finishes and is deleted
+ QPointer<QVariantAnimation> anim = new QPropertyAnimation(&o, "ole");
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ anim->start(QVariantAnimation::DeleteWhenStopped);
+ QTest::qWait(anim->duration() + 50);
+ QCOMPARE(runningSpy.count(), 2); //started and then stopped
+ QVERIFY(!anim);
+ }
+
+ {
+ QPointer<QVariantAnimation> anim = new QPropertyAnimation(&o, "ole");
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ anim->start(QVariantAnimation::DeleteWhenStopped);
+ QTest::qWait(anim->duration()/2);
+ QPointer<QVariantAnimation> anim2 = new QPropertyAnimation(&o, "ole");
+ QCOMPARE(runningSpy.count(), 1);
+ QCOMPARE(anim->state(), QVariantAnimation::Running);
+
+ //anim2 will interrupt anim1
+ QMetaObject::invokeMethod(anim2, "start", Qt::QueuedConnection, Q_ARG(QAbstractAnimation::DeletionPolicy, QVariantAnimation::DeleteWhenStopped));
+ QTest::qWait(50);
+ QVERIFY(!anim); //anim should have been deleted
+ QVERIFY(anim2);
+ QTest::qWait(anim2->duration());
+ QVERIFY(!anim2); //anim2 is finished: it should have been deleted by now
+ QVERIFY(!anim);
+ }
+
+}
+
+// copy from easing.cpp in case that function changes definition
+static qreal easeInOutBack(qreal t)
+{
+ qreal s = 1.70158;
+ qreal t_adj = 2.0f * (qreal)t;
+ if (t_adj < 1) {
+ s *= 1.525f;
+ return 1.0/2*(t_adj*t_adj*((s+1)*t_adj - s));
+ } else {
+ t_adj -= 2;
+ s *= 1.525f;
+ return 1.0/2*(t_adj*t_adj*((s+1)*t_adj + s) + 2);
+ }
+}
+
+void tst_QPropertyAnimation::easingcurve_data()
+{
+ QTest::addColumn<int>("currentTime");
+ QTest::addColumn<int>("expectedvalue");
+
+ QTest::newRow("interpolation1") << 0 << 0;
+ QTest::newRow("interpolation2") << 1000 << 1000;
+ QTest::newRow("extrapolationbelow") << 250 << -99;
+ QTest::newRow("extrapolationabove") << 750 << 1099;
+}
+
+void tst_QPropertyAnimation::easingcurve()
+{
+ QFETCH(int, currentTime);
+ QFETCH(int, expectedvalue);
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation pAnimation(&o, "ole");
+ pAnimation.setStartValue(0);
+ pAnimation.setEndValue(1000);
+ pAnimation.setDuration(1000);
+
+ // this easingcurve assumes that we extrapolate before startValue and after endValue
+ QEasingCurve easingCurve;
+ easingCurve.setCustomType(easeInOutBack);
+ pAnimation.setEasingCurve(easingCurve);
+ pAnimation.start();
+ pAnimation.pause();
+ pAnimation.setCurrentTime(currentTime);
+ QCOMPARE(o.property("ole").toInt(), expectedvalue);
+}
+
+void tst_QPropertyAnimation::startWithoutStartValue()
+{
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation anim(&o, "ole");
+ anim.setEndValue(100);
+
+ anim.start();
+
+ QTest::qWait(100);
+ int current = anim.currentValue().toInt();
+ //it is somewhere in the animation
+ QVERIFY(current > 42);
+ QVERIFY(current < 100);
+
+ QTest::qWait(200);
+ QCOMPARE(anim.state(), QVariantAnimation::Stopped);
+
+ anim.setEndValue(110);
+ anim.start();
+ current = anim.currentValue().toInt();
+ // the default start value will reevaluate the current property
+ // and set it to the end value of the last iteration
+ QCOMPARE(current, 100);
+ QTest::qWait(100);
+ current = anim.currentValue().toInt();
+ //it is somewhere in the animation
+ QVERIFY(current >= 100);
+ QVERIFY(current <= 110);
+}
+
+void tst_QPropertyAnimation::playForwardBackward()
+{
+ QObject o;
+ o.setProperty("ole", 0);
+ QCOMPARE(o.property("ole").toInt(), 0);
+
+ QPropertyAnimation anim(&o, "ole");
+ anim.setEndValue(100);
+ anim.start();
+ QTest::qWait(anim.duration() + 50);
+ QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(anim.currentTime(), anim.duration());
+
+ //the animation is at the end
+ anim.setDirection(QVariantAnimation::Backward);
+ anim.start();
+ QCOMPARE(anim.state(), QAbstractAnimation::Running);
+ QTest::qWait(anim.duration() + 50);
+ QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(anim.currentTime(), 0);
+
+ //the direction is backward
+ //restarting should jump to the end
+ anim.start();
+ QCOMPARE(anim.state(), QAbstractAnimation::Running);
+ QCOMPARE(anim.currentTime(), anim.duration());
+ QTest::qWait(anim.duration() + 50);
+ QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(anim.currentTime(), 0);
+}
+
+struct Number
+{
+ Number() {}
+ Number(int n)
+ : n(n) {}
+
+ Number(const Number &other)
+ : n(other.n){}
+
+ Number &operator=(const Number &other) {
+ n = other.n;
+ return *this;
+ }
+ bool operator==(const Number &other) const {
+ return n == other.n;
+ }
+
+ int n;
+};
+
+Q_DECLARE_METATYPE(Number)
+Q_DECLARE_METATYPE(QAbstractAnimation::State)
+
+QVariant numberInterpolator(const Number &f, const Number &t, qreal progress)
+{
+ return qVariantFromValue<Number>(Number(f.n + (t.n - f.n)*progress));
+}
+
+QVariant xaxisQPointInterpolator(const QPointF &f, const QPointF &t, qreal progress)
+{
+ return QPointF(f.x() + (t.x() - f.x())*progress, f.y());
+}
+
+void tst_QPropertyAnimation::interpolated()
+{
+ QObject o;
+ o.setProperty("point", QPointF()); //this will avoid warnings
+ o.setProperty("number", qVariantFromValue<Number>(Number(42)));
+ QCOMPARE(qVariantValue<Number>(o.property("number")), Number(42));
+ {
+ qRegisterAnimationInterpolator<Number>(numberInterpolator);
+ QPropertyAnimation anim(&o, "number");
+ anim.setStartValue(qVariantFromValue<Number>(Number(0)));
+ anim.setEndValue(qVariantFromValue<Number>(Number(100)));
+ anim.setDuration(1000);
+ anim.start();
+ anim.pause();
+ anim.setCurrentTime(100);
+ Number t(qVariantValue<Number>(o.property("number")));
+ QCOMPARE(t, Number(10));
+ anim.setCurrentTime(500);
+ QCOMPARE(qVariantValue<Number>(o.property("number")), Number(50));
+ }
+ {
+ qRegisterAnimationInterpolator<QPointF>(xaxisQPointInterpolator);
+ QPropertyAnimation anim(&o, "point");
+ anim.setStartValue(QPointF(0,0));
+ anim.setEndValue(QPointF(100, 100));
+ anim.setDuration(1000);
+ anim.start();
+ anim.pause();
+ anim.setCurrentTime(100);
+ QCOMPARE(o.property("point"), QVariant(QPointF(10, 0)));
+ anim.setCurrentTime(500);
+ QCOMPARE(o.property("point"), QVariant(QPointF(50, 0)));
+ }
+ {
+ // unregister it and see if we get back the default behaviour
+ qRegisterAnimationInterpolator<QPointF>(0);
+ QPropertyAnimation anim(&o, "point");
+ anim.setStartValue(QPointF(0,0));
+ anim.setEndValue(QPointF(100, 100));
+ anim.setDuration(1000);
+ anim.start();
+ anim.pause();
+ anim.setCurrentTime(100);
+ QCOMPARE(o.property("point").toPointF(), QPointF(10, 10));
+ anim.setCurrentTime(500);
+ QCOMPARE(o.property("point").toPointF(), QPointF(50, 50));
+ }
+
+ {
+ // Interpolate a qreal property with a int interpolator
+ AnimationObject o1;
+ o1.setRealValue(42.42);
+ QPropertyAnimation anim(&o1, "realValue");
+ anim.setStartValue(0);
+ anim.setEndValue(100);
+ anim.start();
+ QCOMPARE(o1.realValue(), qreal(0));
+ anim.setCurrentTime(250);
+ QCOMPARE(o1.realValue(), qreal(100));
+ }
+}
+
+void tst_QPropertyAnimation::setStartEndValues()
+{
+ //this tests the start value, end value and default start value
+ QObject o;
+ o.setProperty("ole", 42);
+ QPropertyAnimation anim(&o, "ole");
+ QVariantAnimation::KeyValues values;
+ QCOMPARE(anim.keyValues(), values);
+
+ //let's add a start value
+ anim.setStartValue(0);
+ values << QVariantAnimation::KeyValue(0, 0);
+ QCOMPARE(anim.keyValues(), values);
+
+ anim.setEndValue(10);
+ values << QVariantAnimation::KeyValue(1, 10);
+ QCOMPARE(anim.keyValues(), values);
+
+ //now we can play with objects
+ QCOMPARE(o.property("ole").toInt(), 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+ anim.start();
+ QVERIFY(anim.startValue().isValid());
+ QCOMPARE(o.property("ole"), anim.startValue());
+
+ //now we remove the explicit start value and test the implicit one
+ anim.stop();
+ o.setProperty("ole", 42);
+ values.remove(0);
+ anim.setStartValue(QVariant()); //reset the start value
+ QCOMPARE(anim.keyValues(), values);
+ QVERIFY(!anim.startValue().isValid());
+ anim.start();
+ QCOMPARE(o.property("ole").toInt(), 42);
+ anim.setCurrentTime(anim.duration()/2);
+ QCOMPARE(o.property("ole").toInt(), 26); //just in the middle of the animation
+ anim.setCurrentTime(anim.duration());
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped); //it should have stopped
+ QVERIFY(anim.endValue().isValid());
+ QCOMPARE(o.property("ole"), anim.endValue()); //end of the animations
+
+ //now we set back the startValue
+ anim.setStartValue(5);
+ QVERIFY(anim.startValue().isValid());
+ anim.start();
+ QCOMPARE(o.property("ole").toInt(), 5);
+}
+
+void tst_QPropertyAnimation::zeroDurationStart()
+{
+ QPropertyAnimation anim;
+ QSignalSpy spy(&anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ anim.setDuration(0);
+ QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
+ anim.start();
+ //the animation stops immediately
+ QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(spy.count(), 2);
+
+ //let's check the first state change
+ const QVariantList firstChange = spy.first();
+ //old state
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(firstChange.first()), QAbstractAnimation::Stopped);
+ //new state
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(firstChange.last()), QAbstractAnimation::Running);
+
+ //let's check the first state change
+ const QVariantList secondChange = spy.last();
+ //old state
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(secondChange.first()), QAbstractAnimation::Running);
+ //new state
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(secondChange.last()), QAbstractAnimation::Stopped);
+}
+
+#define Pause 1
+#define Start 2
+#define Resume 3
+#define Stop 4
+
+void tst_QPropertyAnimation::operationsInStates_data()
+{
+ QTest::addColumn<QAbstractAnimation::State>("originState");
+ QTest::addColumn<int>("operation");
+ QTest::addColumn<QString>("expectedWarning");
+ QTest::addColumn<QAbstractAnimation::State>("expectedState");
+
+ QString pauseWarn(QLatin1String("QAbstractAnimation::pause: Cannot pause a stopped animation"));
+ QString resumeWarn(QLatin1String("QAbstractAnimation::resume: Cannot resume an animation that is not paused"));
+
+ QTest::newRow("S-pause") << QAbstractAnimation::Stopped << Pause << pauseWarn << QAbstractAnimation::Stopped;
+ QTest::newRow("S-start") << QAbstractAnimation::Stopped << Start << QString() << QAbstractAnimation::Running;
+ QTest::newRow("S-resume") << QAbstractAnimation::Stopped << Resume << resumeWarn << QAbstractAnimation::Stopped;
+ QTest::newRow("S-stop") << QAbstractAnimation::Stopped << Stop << QString() << QAbstractAnimation::Stopped;
+
+ QTest::newRow("P-pause") << QAbstractAnimation::Paused << Pause << QString() << QAbstractAnimation::Paused;
+ QTest::newRow("P-start") << QAbstractAnimation::Paused << Start << QString() << QAbstractAnimation::Running;
+ QTest::newRow("P-resume") << QAbstractAnimation::Paused << Resume << QString() << QAbstractAnimation::Running;
+ QTest::newRow("P-stop") << QAbstractAnimation::Paused << Stop << QString() << QAbstractAnimation::Stopped;
+
+ QTest::newRow("R-pause") << QAbstractAnimation::Running << Pause << QString() << QAbstractAnimation::Paused;
+ QTest::newRow("R-start") << QAbstractAnimation::Running << Start << QString() << QAbstractAnimation::Running;
+ QTest::newRow("R-resume") << QAbstractAnimation::Running << Resume << resumeWarn << QAbstractAnimation::Running;
+ QTest::newRow("R-stop") << QAbstractAnimation::Running << Stop << QString() << QAbstractAnimation::Stopped;
+}
+
+void tst_QPropertyAnimation::operationsInStates()
+{
+/**
+ * | pause() |start() |resume() |stop()
+ * ----------+------------+-----------+-----------+-------------------+
+ * Stopped | Stopped |Running |Stopped |Stopped |
+ * _| qWarning |restart |qWarning | |
+ * Paused | Paused |Running |Running |Stopped |
+ * _| | | | |
+ * Running | Paused |Running |Running |Stopped |
+ * | |restart |qWarning | |
+ * ----------+------------+-----------+-----------+-------------------+
+**/
+
+ QFETCH(QAbstractAnimation::State, originState);
+ QFETCH(int, operation);
+ QFETCH(QString, expectedWarning);
+ QFETCH(QAbstractAnimation::State, expectedState);
+
+ QObject o;
+ o.setProperty("ole", 42);
+ QPropertyAnimation anim(&o, "ole");
+ QSignalSpy spy(&anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ anim.stop();
+ switch (originState) {
+ case QAbstractAnimation::Stopped:
+ break;
+ case QAbstractAnimation::Paused:
+ anim.start();
+ anim.pause();
+ break;
+ case QAbstractAnimation::Running:
+ anim.start();
+ break;
+ }
+ if (!expectedWarning.isEmpty()) {
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(expectedWarning));
+ }
+ QCOMPARE(anim.state(), originState);
+ switch (operation) {
+ case Pause:
+ anim.pause();
+ break;
+ case Start:
+ anim.start();
+ break;
+ case Resume:
+ anim.resume();
+ break;
+ case Stop:
+ anim.stop();
+ break;
+ }
+
+ QCOMPARE(anim.state(), expectedState);
+}
+#undef Pause
+#undef Start
+#undef Resume
+#undef Stop
+
+void tst_QPropertyAnimation::oneKeyValue()
+{
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation animation(&o, "ole");
+ animation.setStartValue(43);
+ animation.setEndValue(44);
+ animation.setDuration(100);
+
+ animation.setCurrentTime(0);
+
+ QVERIFY(animation.currentValue().isValid());
+ QCOMPARE(animation.currentValue().toInt(), 43);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ // remove the last key value
+ animation.setKeyValueAt(1.0, QVariant());
+
+ // we will neither interpolate, nor update the current value
+ // since there is only one 1 key value defined
+ animation.setCurrentTime(100);
+
+ // the animation should not have been modified
+ QVERIFY(animation.currentValue().isValid());
+ QCOMPARE(animation.currentValue().toInt(), 43);
+ QCOMPARE(o.property("ole").toInt(), 42);
+}
+
+void tst_QPropertyAnimation::updateOnSetKeyValues()
+{
+ QObject o;
+ o.setProperty("ole", 100);
+ QCOMPARE(o.property("ole").toInt(), 100);
+
+ QPropertyAnimation animation(&o, "ole");
+ animation.setStartValue(100);
+ animation.setEndValue(200);
+ animation.setDuration(100);
+
+ animation.setCurrentTime(50);
+ QCOMPARE(animation.currentValue().toInt(), 150);
+ animation.setKeyValueAt(0.0, 300);
+ QCOMPARE(animation.currentValue().toInt(), 250);
+
+ o.setProperty("ole", 100);
+ QPropertyAnimation animation2(&o, "ole");
+ QVariantAnimation::KeyValues kValues;
+ kValues << QVariantAnimation::KeyValue(0.0, 100) << QVariantAnimation::KeyValue(1.0, 200);
+ animation2.setKeyValues(kValues);
+ animation2.setDuration(100);
+ animation2.setCurrentTime(50);
+ QCOMPARE(animation2.currentValue().toInt(), 150);
+
+ kValues.clear();
+ kValues << QVariantAnimation::KeyValue(0.0, 300) << QVariantAnimation::KeyValue(1.0, 200);
+ animation2.setKeyValues(kValues);
+
+ QCOMPARE(animation2.currentValue().toInt(), animation.currentValue().toInt());
+}
+
+QTEST_MAIN(tst_QPropertyAnimation)
+#include "tst_qpropertyanimation.moc"
diff --git a/tests/auto/qsequentialanimationgroup/qsequentialanimationgroup.pro b/tests/auto/qsequentialanimationgroup/qsequentialanimationgroup.pro
new file mode 100644
index 0000000..ad861c3
--- /dev/null
+++ b/tests/auto/qsequentialanimationgroup/qsequentialanimationgroup.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+QT = core gui
+SOURCES += tst_qsequentialanimationgroup.cpp
+
+
diff --git a/tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp b/tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
new file mode 100644
index 0000000..0631343
--- /dev/null
+++ b/tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
@@ -0,0 +1,1649 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include "../../shared/util.h"
+
+#include <QtCore/qanimationgroup.h>
+#include <QtCore/qsequentialanimationgroup.h>
+
+//TESTED_CLASS=QSequentialAnimationGroup
+//TESTED_FILES=
+
+Q_DECLARE_METATYPE(QAbstractAnimation::State)
+Q_DECLARE_METATYPE(QAbstractAnimation*)
+
+class tst_QSequentialAnimationGroup : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QSequentialAnimationGroup();
+ virtual ~tst_QSequentialAnimationGroup();
+
+public Q_SLOTS:
+ void init();
+ void cleanup();
+
+private slots:
+ void construction();
+ void setCurrentTime();
+ void setCurrentTimeWithUncontrolledAnimation();
+ void seekingForwards();
+ void seekingBackwards();
+ void pauseAndResume();
+ void restart();
+ void looping();
+ void startDelay();
+ void clearGroup();
+ void groupWithZeroDurationAnimations();
+ void propagateGroupUpdateToChildren();
+ void updateChildrenWithRunningGroup();
+ void deleteChildrenWithRunningGroup();
+ void startChildrenWithStoppedGroup();
+ void stopGroupWithRunningChild();
+ void startGroupWithRunningChild();
+ void zeroDurationAnimation();
+ void stopUncontrolledAnimations();
+ void finishWithUncontrolledAnimation();
+ void addRemoveAnimation();
+ void currentAnimation();
+ void currentAnimationWithZeroDuration();
+ void insertAnimation();
+ void clearAnimations();
+};
+
+tst_QSequentialAnimationGroup::tst_QSequentialAnimationGroup()
+{
+}
+
+tst_QSequentialAnimationGroup::~tst_QSequentialAnimationGroup()
+{
+}
+
+void tst_QSequentialAnimationGroup::init()
+{
+ qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
+ qRegisterMetaType<QAbstractAnimation*>("QAbstractAnimation*");
+}
+
+void tst_QSequentialAnimationGroup::cleanup()
+{
+}
+
+void tst_QSequentialAnimationGroup::construction()
+{
+ QSequentialAnimationGroup animationgroup;
+}
+
+class AnimationObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value WRITE setValue)
+public:
+ AnimationObject(int startValue = 0)
+ : v(startValue)
+ { }
+
+ int value() const { return v; }
+ void setValue(int value) { v = value; }
+
+ int v;
+};
+
+class TestAnimation : public QVariantAnimation
+{
+ Q_OBJECT
+public:
+ virtual void updateCurrentValue(const QVariant &value) { Q_UNUSED(value)};
+ virtual void updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+ {
+ Q_UNUSED(oldState)
+ Q_UNUSED(newState)
+ };
+};
+
+class UncontrolledAnimation : public QPropertyAnimation
+{
+ Q_OBJECT
+public:
+ UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = 0)
+ : QPropertyAnimation(target, propertyName, parent)
+ {
+ setDuration(250);
+ }
+
+ int duration() const { return -1; /* not time driven */ }
+
+protected:
+ void updateCurrentTime(int msecs)
+ {
+ QPropertyAnimation::updateCurrentTime(msecs);
+ if (msecs >= QPropertyAnimation::duration())
+ stop();
+ }
+};
+
+void tst_QSequentialAnimationGroup::setCurrentTime()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject s_o3;
+
+ // sequence operating on same object/property
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ a2_s_o1->setLoopCount(3);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+
+ // sequence operating on different object/properties
+ QAnimationGroup *sequence2 = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value");
+ QVariantAnimation *a1_s_o3 = new QPropertyAnimation(&s_o3, "value");
+ sequence2->addAnimation(a1_s_o2);
+ sequence2->addAnimation(a1_s_o3);
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+ group.addAnimation(sequence2);
+
+ // Current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 250
+ group.setCurrentTime(250);
+ QCOMPARE(group.currentTime(), 250);
+ QCOMPARE(sequence->currentTime(), 250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 251
+ group.setCurrentTime(251);
+ QCOMPARE(group.currentTime(), 251);
+ QCOMPARE(sequence->currentTime(), 251);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentLoop(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 750
+ group.setCurrentTime(750);
+ QCOMPARE(group.currentTime(), 750);
+ QCOMPARE(sequence->currentTime(), 750);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1000
+ group.setCurrentTime(1000);
+ QCOMPARE(group.currentTime(), 1000);
+ QCOMPARE(sequence->currentTime(), 1000);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1010
+ group.setCurrentTime(1010);
+ QCOMPARE(group.currentTime(), 1010);
+ QCOMPARE(sequence->currentTime(), 1010);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 10);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1250
+ group.setCurrentTime(1250);
+ QCOMPARE(group.currentTime(), 1250);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1500
+ group.setCurrentTime(1500);
+ QCOMPARE(group.currentTime(), 1500);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1750
+ group.setCurrentTime(1750);
+ QCOMPARE(group.currentTime(), 1750);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 500);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 250);
+
+ // Current time = 2000
+ group.setCurrentTime(2000);
+ QCOMPARE(group.currentTime(), 1750);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 500);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 250);
+}
+
+void tst_QSequentialAnimationGroup::setCurrentTimeWithUncontrolledAnimation()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject t_o1;
+ AnimationObject t_o2;
+
+ // sequence operating on different object/properties
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value");
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a1_s_o2);
+
+ UncontrolledAnimation *notTimeDriven = new UncontrolledAnimation(&t_o1, "value");
+ QCOMPARE(notTimeDriven->totalDuration(), -1);
+
+ QVariantAnimation *loopsForever = new QPropertyAnimation(&t_o2, "value");
+ loopsForever->setLoopCount(-1);
+ QCOMPARE(loopsForever->totalDuration(), -1);
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+ group.addAnimation(notTimeDriven);
+ group.addAnimation(loopsForever);
+ group.start();
+ group.pause(); // this allows the group to listen for the finish signal of its children
+
+ // Current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(notTimeDriven->currentTime(), 0);
+ QCOMPARE(loopsForever->currentTime(), 0);
+
+ // Current time = 250
+ group.setCurrentTime(250);
+ QCOMPARE(group.currentTime(), 250);
+ QCOMPARE(sequence->currentTime(), 250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(notTimeDriven->currentTime(), 0);
+ QCOMPARE(loopsForever->currentTime(), 0);
+
+ // Current time = 500
+ group.setCurrentTime(500);
+ QCOMPARE(group.currentTime(), 500);
+ QCOMPARE(sequence->currentTime(), 500);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 0);
+ QCOMPARE(loopsForever->currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), notTimeDriven);
+
+ // Current time = 505
+ group.setCurrentTime(505);
+ QCOMPARE(group.currentTime(), 505);
+ QCOMPARE(sequence->currentTime(), 500);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 5);
+ QCOMPARE(loopsForever->currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), notTimeDriven);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Paused);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
+
+ // Current time = 750 (end of notTimeDriven animation)
+ group.setCurrentTime(750);
+ QCOMPARE(group.currentTime(), 750);
+ QCOMPARE(sequence->currentTime(), 500);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 250);
+ QCOMPARE(loopsForever->currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), loopsForever);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Paused);
+
+ // Current time = 800 (as notTimeDriven was finished at 750, loopsforever should still run)
+ group.setCurrentTime(800);
+ QCOMPARE(group.currentTime(), 800);
+ QCOMPARE(group.currentAnimation(), loopsForever);
+ QCOMPARE(sequence->currentTime(), 500);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 250);
+ QCOMPARE(loopsForever->currentTime(), 50);
+
+ loopsForever->stop(); // this should stop the group
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::seekingForwards()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject s_o3;
+
+ // sequence operating on same object/property
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ a2_s_o1->setLoopCount(3);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+
+ // sequence operating on different object/properties
+ QAnimationGroup *sequence2 = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value");
+ QVariantAnimation *a1_s_o3 = new QPropertyAnimation(&s_o3, "value");
+ sequence2->addAnimation(a1_s_o2);
+ sequence2->addAnimation(a1_s_o3);
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+ group.addAnimation(sequence2);
+
+ // Current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o3->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1500
+ group.setCurrentTime(1500);
+ QCOMPARE(group.currentTime(), 1500);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // this will restart the group
+ group.start();
+ group.pause();
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o3->state(), QAnimationGroup::Stopped);
+
+ // Current time = 1750
+ group.setCurrentTime(1750);
+ QCOMPARE(group.currentTime(), 1750);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 500);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 250);
+}
+
+void tst_QSequentialAnimationGroup::seekingBackwards()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject s_o3;
+
+ // sequence operating on same object/property
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ a2_s_o1->setLoopCount(3);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+
+ // sequence operating on different object/properties
+ QAnimationGroup *sequence2 = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value");
+ QVariantAnimation *a1_s_o3 = new QPropertyAnimation(&s_o3, "value");
+ sequence2->addAnimation(a1_s_o2);
+ sequence2->addAnimation(a1_s_o3);
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+ group.addAnimation(sequence2);
+
+ group.start();
+
+ // Current time = 1600
+ group.setCurrentTime(1600);
+ QCOMPARE(group.currentTime(), 1600);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 350);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 100);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Running);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o3->state(), QAnimationGroup::Running);
+
+ // Seeking backwards, current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+
+ QEXPECT_FAIL("", "rewinding in nested groups is considered as a restart from the children,"
+ "hence they don't reset from their current animation", Continue);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QEXPECT_FAIL("", "rewinding in nested groups is considered as a restart from the children,"
+ "hence they don't reset from their current animation", Continue);
+ QCOMPARE(a2_s_o1->currentLoop(), 0);
+ QEXPECT_FAIL("", "rewinding in nested groups is considered as a restart from the children,"
+ "hence they don't reset from their current animation", Continue);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(sequence->state(), QAnimationGroup::Running);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Running);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o3->state(), QAnimationGroup::Stopped);
+
+ // Current time = 2000
+ group.setCurrentTime(2000);
+ QCOMPARE(group.currentTime(), 1750);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 500);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 250);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o3->state(), QAnimationGroup::Stopped);
+}
+
+typedef QList<QAbstractAnimation::State> StateList;
+
+static bool compareStates(const QSignalSpy& spy, const StateList &expectedStates)
+{
+ bool equals = true;
+ for (int i = 0; i < qMax(expectedStates.count(), spy.count()); ++i) {
+ if (i >= spy.count() || i >= expectedStates.count()) {
+ equals = false;
+ break;
+ }
+ QList<QVariant> args = spy.at(i);
+ QAbstractAnimation::State st = expectedStates.at(i);
+ QAbstractAnimation::State actual = qVariantValue<QAbstractAnimation::State>(args.value(1));
+ if (equals && actual != st) {
+ equals = false;
+ break;
+ }
+ }
+ if (!equals) {
+ const char *stateStrings[] = {"Stopped", "Paused", "Running"};
+ QString e,a;
+ for (int i = 0; i < qMax(expectedStates.count(), spy.count()); ++i) {
+ if (i < expectedStates.count()) {
+ int exp = int(expectedStates.at(i));
+ if (!e.isEmpty())
+ e += QLatin1String(", ");
+ e += QLatin1String(stateStrings[exp]);
+ }
+ if (i < spy.count()) {
+ QList<QVariant> args = spy.at(i);
+ QAbstractAnimation::State actual = qVariantValue<QAbstractAnimation::State>(args.value(1));
+ if (!a.isEmpty())
+ a += QLatin1String(", ");
+ if (int(actual) >= 0 && int(actual) <= 2) {
+ a += QLatin1String(stateStrings[int(actual)]);
+ } else {
+ a += QLatin1String("NaN");
+ }
+ }
+
+ }
+ qDebug("\n"
+ "expected (count == %d): %s\n"
+ "actual (count == %d): %s\n", expectedStates.count(), qPrintable(e), spy.count(), qPrintable(a));
+ }
+ return equals;
+}
+
+void tst_QSequentialAnimationGroup::pauseAndResume()
+{
+ AnimationObject s_o1;
+
+ // sequence operating on same object/property
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ a2_s_o1->setLoopCount(2);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+ sequence->setLoopCount(2);
+
+ QSignalSpy a1StateChangedSpy(a1_s_o1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy seqStateChangedSpy(sequence, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+
+ group.start();
+ group.pause();
+
+ // Current time = 1751
+ group.setCurrentTime(1751);
+ QCOMPARE(group.currentTime(), 1751);
+ QCOMPARE(sequence->currentTime(), 751);
+ QCOMPARE(sequence->currentLoop(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 1);
+ QCOMPARE(a3_s_o1->currentLoop(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 1);
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3_s_o1->state(), QAnimationGroup::Paused);
+
+ QCOMPARE(a1StateChangedSpy.count(), 5); // Running,Paused,Stopped,Running,Stopped
+ QCOMPARE(seqStateChangedSpy.count(), 2); // Running,Paused
+
+ QVERIFY(compareStates(a1StateChangedSpy, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running
+ << QAbstractAnimation::Stopped)));
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(a1StateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(a1StateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Paused);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(a1StateChangedSpy.at(2).at(1)),
+ QAnimationGroup::Stopped);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(a1StateChangedSpy.at(3).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(a1StateChangedSpy.at(4).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Paused);
+
+ group.resume();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(sequence->state(), QAnimationGroup::Running);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3_s_o1->state(), QAnimationGroup::Running);
+
+ QVERIFY(group.currentTime() >= 1751);
+ QVERIFY(sequence->currentTime() >= 751);
+ QCOMPARE(sequence->currentLoop(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 1);
+ QCOMPARE(a3_s_o1->currentLoop(), 0);
+ QVERIFY(a3_s_o1->currentTime() >= 1);
+
+ QCOMPARE(seqStateChangedSpy.count(), 3); // Running,Paused,Running
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(2).at(1)),
+ QAnimationGroup::Running);
+
+ group.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3_s_o1->state(), QAnimationGroup::Paused);
+
+ QVERIFY(group.currentTime() >= 1751);
+ QVERIFY(sequence->currentTime() >= 751);
+ QCOMPARE(sequence->currentLoop(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 1);
+ QCOMPARE(a3_s_o1->currentLoop(), 0);
+ QVERIFY(a3_s_o1->currentTime() >= 1);
+
+ QCOMPARE(seqStateChangedSpy.count(), 4); // Running,Paused,Running,Paused
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(3).at(1)),
+ QAnimationGroup::Paused);
+
+ group.stop();
+
+ QCOMPARE(seqStateChangedSpy.count(), 5); // Running,Paused,Running,Paused,Stopped
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(4).at(1)),
+ QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::restart()
+{
+ AnimationObject s_o1;
+
+ // sequence operating on same object/property
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QSignalSpy seqCurrentAnimChangedSpy(sequence, SIGNAL(currentAnimationChanged(QAbstractAnimation*)));
+ QSignalSpy seqStateChangedSpy(sequence, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QVariantAnimation *anims[3];
+ QSignalSpy *animsStateChanged[3];
+
+ for (int i = 0; i < 3; i++) {
+ anims[i] = new QPropertyAnimation(&s_o1, "value");
+ anims[i]->setDuration(100);
+ animsStateChanged[i] = new QSignalSpy(anims[i], SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ }
+
+ anims[1]->setLoopCount(2);
+ sequence->addAnimation(anims[0]);
+ sequence->addAnimation(anims[1]);
+ sequence->addAnimation(anims[2]);
+ sequence->setLoopCount(2);
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+
+ group.start();
+
+ QTest::qWait(500);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+
+ QTest::qWait(300);
+ QTRY_COMPARE(group.state(), QAnimationGroup::Stopped);
+
+ for (int i = 0; i < 3; i++) {
+ QCOMPARE(animsStateChanged[i]->count(), 4);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(animsStateChanged[i]->at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(animsStateChanged[i]->at(1).at(1)),
+ QAnimationGroup::Stopped);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(animsStateChanged[i]->at(2).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(animsStateChanged[i]->at(3).at(1)),
+ QAnimationGroup::Stopped);
+ }
+
+ QCOMPARE(seqStateChangedSpy.count(), 2);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(seqCurrentAnimChangedSpy.count(), 6);
+ for(int i=0; i<seqCurrentAnimChangedSpy.count(); i++)
+ QCOMPARE(anims[i%3], qVariantValue<QAbstractAnimation*>(seqCurrentAnimChangedSpy.at(i).at(0)));
+
+ group.start();
+
+ QCOMPARE(animsStateChanged[0]->count(), 5);
+ QCOMPARE(animsStateChanged[1]->count(), 4);
+ QCOMPARE(animsStateChanged[2]->count(), 4);
+ QCOMPARE(seqStateChangedSpy.count(), 3);
+}
+
+void tst_QSequentialAnimationGroup::looping()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject s_o3;
+
+ // sequence operating on same object/property
+ QSequentialAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+
+ QSignalSpy a1Spy(a1_s_o1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy a2Spy(a2_s_o1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy a3Spy(a3_s_o1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy seqSpy(sequence, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ a2_s_o1->setLoopCount(2);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+ sequence->setLoopCount(2);
+
+ QSequentialAnimationGroup group;
+ QSignalSpy groupSpy(&group, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ group.addAnimation(sequence);
+ group.setLoopCount(2);
+
+ group.start();
+ group.pause();
+
+ // Current time = 1750
+ group.setCurrentTime(1750);
+ QCOMPARE(group.currentTime(), 1750);
+ QCOMPARE(sequence->currentTime(), 750);
+ QCOMPARE(sequence->currentLoop(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 1);
+ // this animation is at the beginning because it is the current one inside sequence
+ QCOMPARE(a3_s_o1->currentLoop(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence->currentAnimation(), a3_s_o1);
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3_s_o1->state(), QAnimationGroup::Paused);
+
+ QCOMPARE(a1Spy.count(), 5); // Running,Paused,Stopped,Running,Stopped
+ QVERIFY(compareStates(a1Spy, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running
+ << QAbstractAnimation::Stopped)));
+
+ QCOMPARE(a2Spy.count(), 4); // Running,Stopped,Running,Stopped
+ QVERIFY(compareStates(a3Spy, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused)));
+
+ QCOMPARE(seqSpy.count(), 2); // Running,Paused
+ QCOMPARE(groupSpy.count(), 2); // Running,Paused
+
+ // Looping, current time = duration + 1
+ group.setCurrentTime(group.duration() + 1);
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(group.currentLoop(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(sequence->currentLoop(), 0);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 1);
+ // this animation is at the end because it was run on the previous loop
+ QCOMPARE(a3_s_o1->currentLoop(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Paused);
+ QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3_s_o1->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(a1Spy.count(), 7); // Running,Paused,Stopped,Running,Stopped,Running,Stopped
+ QCOMPARE(a2Spy.count(), 4); // Running, Stopped, Running, Stopped
+ QVERIFY(compareStates(a3Spy, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused
+ << QAbstractAnimation::Stopped)));
+ QVERIFY(compareStates(seqSpy, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused)));
+ QCOMPARE(groupSpy.count(), 2);
+}
+
+void tst_QSequentialAnimationGroup::startDelay()
+{
+ QSequentialAnimationGroup group;
+ group.addPause(250);
+ group.addPause(125);
+ QCOMPARE(group.totalDuration(), 375);
+
+ QEventLoop loop;
+ QObject::connect(&group, SIGNAL(finished()), &loop, SLOT(quit()));
+
+ QTime time;
+ time.start();
+ group.start();
+ loop.exec();
+
+ QVERIFY(time.elapsed() >= 375);
+ QVERIFY(time.elapsed() < 1000);
+}
+
+void tst_QSequentialAnimationGroup::clearGroup()
+{
+ QSequentialAnimationGroup group;
+
+ for (int i = 0; i < 10; ++i) {
+ QSequentialAnimationGroup *subGroup = new QSequentialAnimationGroup(&group);
+ group.addPause(100);
+ subGroup->addPause(10);
+ }
+
+ QCOMPARE(group.animationCount(), 20);
+
+ int count = group.animationCount();
+ QPointer<QAbstractAnimation> *children = new QPointer<QAbstractAnimation>[count];
+ for (int i = 0; i < count; ++i) {
+ QVERIFY(group.animationAt(i) != 0);
+ children[i] = group.animationAt(i);
+ }
+
+ group.clearAnimations();
+ QCOMPARE(group.animationCount(), 0);
+ QCOMPARE(group.currentTime(), 0);
+ for (int i = 0; i < count; ++i)
+ QCOMPARE(children[i], QPointer<QAbstractAnimation>());
+
+ delete[] children;
+}
+
+void tst_QSequentialAnimationGroup::groupWithZeroDurationAnimations()
+{
+ QObject o;
+ QObject o2;
+
+ o.setProperty("myProperty", 42);
+ o.setProperty("myOtherProperty", 13);
+ o2.setProperty("myProperty", 42);
+ o2.setProperty("myOtherProperty", 13);
+
+ QSequentialAnimationGroup group;
+
+ QVariantAnimation *a1 = new QPropertyAnimation(&o, "myProperty");
+ a1->setDuration(0);
+ a1->setEndValue(43);
+ group.addAnimation(a1);
+
+ //this should just run fine and change nothing
+ group.setCurrentTime(0);
+ QCOMPARE(group.currentAnimation(), a1);
+
+ QVariantAnimation *a2 = new QPropertyAnimation(&o2, "myOtherProperty");
+ a2->setDuration(500);
+ a2->setEndValue(31);
+ group.addAnimation(a2);
+
+ QVariantAnimation *a3 = new QPropertyAnimation(&o, "myProperty");
+ a3->setDuration(0);
+ a3->setEndValue(44);
+ group.addAnimation(a3);
+
+ QVariantAnimation *a4 = new QPropertyAnimation(&o, "myOtherProperty");
+ a4->setDuration(250);
+ a4->setEndValue(75);
+ group.addAnimation(a4);
+
+ QVariantAnimation *a5 = new QPropertyAnimation(&o2, "myProperty");
+ a5->setDuration(0);
+ a5->setEndValue(12);
+ group.addAnimation(a5);
+
+ QCOMPARE(o.property("myProperty").toInt(), 42);
+ QCOMPARE(o.property("myOtherProperty").toInt(), 13);
+ QCOMPARE(o2.property("myProperty").toInt(), 42);
+ QCOMPARE(o2.property("myOtherProperty").toInt(), 13);
+
+
+ group.start();
+
+ QCOMPARE(o.property("myProperty").toInt(), 43);
+ QCOMPARE(o.property("myOtherProperty").toInt(), 13);
+ QCOMPARE(o2.property("myProperty").toInt(), 42);
+ QCOMPARE(o2.property("myOtherProperty").toInt(), 13);
+
+ QTest::qWait(50);
+
+ int o2val = o2.property("myOtherProperty").toInt();
+ QVERIFY(o2val > 13);
+ QVERIFY(o2val < 31);
+ QCOMPARE(o.property("myProperty").toInt(), 43);
+ QCOMPARE(o.property("myOtherProperty").toInt(), 13);
+
+ QTest::qWait(500);
+
+ QCOMPARE(o.property("myProperty").toInt(), 44);
+ QCOMPARE(o2.property("myProperty").toInt(), 42);
+ QCOMPARE(o2.property("myOtherProperty").toInt(), 31);
+ QCOMPARE(a1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a4->state(), QAnimationGroup::Running);
+ QCOMPARE(a5->state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QTest::qWait(500);
+
+ QTRY_COMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(o.property("myProperty").toInt(), 44);
+ QCOMPARE(o.property("myOtherProperty").toInt(), 75);
+ QCOMPARE(o2.property("myProperty").toInt(), 12);
+ QCOMPARE(o2.property("myOtherProperty").toInt(), 31);
+ QCOMPARE(a1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a4->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a5->state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::propagateGroupUpdateToChildren()
+{
+ // this test verifies if group state changes are updating its children correctly
+ QSequentialAnimationGroup group;
+
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation anim1(&o, "ole");
+ anim1.setEndValue(43);
+ anim1.setDuration(100);
+ QVERIFY(!anim1.currentValue().isValid());
+ QCOMPARE(anim1.currentValue().toInt(), 0);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QVERIFY(anim2.currentValue().isValid());
+ QCOMPARE(anim2.currentValue().toInt(), 0);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ group.start();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(anim1.state(), QAnimationGroup::Paused);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::updateChildrenWithRunningGroup()
+{
+ // assert that its possible to modify a child's state directly while their group is running
+ QSequentialAnimationGroup group;
+
+ TestAnimation anim;
+ anim.setStartValue(0);
+ anim.setEndValue(100);
+ anim.setDuration(200);
+
+ QSignalSpy groupStateChangedSpy(&group, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy childStateChangedSpy(&anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QCOMPARE(groupStateChangedSpy.count(), 0);
+ QCOMPARE(childStateChangedSpy.count(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim);
+
+ group.start();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Running);
+
+ QCOMPARE(groupStateChangedSpy.count(), 1);
+ QCOMPARE(childStateChangedSpy.count(), 1);
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(childStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+
+ // starting directly a running child will not have any effect
+ anim.start();
+
+ QCOMPARE(groupStateChangedSpy.count(), 1);
+ QCOMPARE(childStateChangedSpy.count(), 1);
+
+ anim.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Paused);
+
+ // in the animation stops directly, the group will still be running
+ anim.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::deleteChildrenWithRunningGroup()
+{
+ // test if children can be activated when their group is stopped
+ QSequentialAnimationGroup group;
+
+ QVariantAnimation *anim1 = new TestAnimation;
+ anim1->setStartValue(0);
+ anim1->setEndValue(100);
+ anim1->setDuration(200);
+ group.addAnimation(anim1);
+
+ QCOMPARE(group.duration(), anim1->duration());
+
+ group.start();
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1->state(), QAnimationGroup::Running);
+
+ QTest::qWait(50);
+ QVERIFY(group.currentTime() > 0);
+
+ delete anim1;
+ QCOMPARE(group.animationCount(), 0);
+ QCOMPARE(group.duration(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.currentTime(), 0); //that's the invariant
+}
+
+void tst_QSequentialAnimationGroup::startChildrenWithStoppedGroup()
+{
+ // test if children can be activated when their group is stopped
+ QSequentialAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(200);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ anim1.start();
+ anim2.start();
+ anim2.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+}
+
+void tst_QSequentialAnimationGroup::stopGroupWithRunningChild()
+{
+ // children that started independently will not be affected by a group stop
+ QSequentialAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(200);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ anim1.start();
+ anim2.start();
+ anim2.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ anim1.stop();
+ anim2.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::startGroupWithRunningChild()
+{
+ // as the group has precedence over its children, starting a group will restart all the children
+ QSequentialAnimationGroup group;
+
+ TestAnimation *anim1 = new TestAnimation();
+ anim1->setStartValue(0);
+ anim1->setEndValue(100);
+ anim1->setDuration(200);
+
+ TestAnimation *anim2 = new TestAnimation();
+ anim2->setStartValue(0);
+ anim2->setEndValue(100);
+ anim2->setDuration(200);
+
+ QSignalSpy stateChangedSpy1(anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy stateChangedSpy2(anim2, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QCOMPARE(stateChangedSpy1.count(), 0);
+ QCOMPARE(stateChangedSpy2.count(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2->state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(anim1);
+ group.addAnimation(anim2);
+
+ anim1->start();
+ anim2->start();
+ anim2->pause();
+
+ QVERIFY(compareStates(stateChangedSpy1, (StateList() << QAbstractAnimation::Running)));
+
+ QVERIFY(compareStates(stateChangedSpy2, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused)));
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1->state(), QAnimationGroup::Running);
+ QCOMPARE(anim2->state(), QAnimationGroup::Paused);
+
+ group.start();
+
+ QVERIFY(compareStates(stateChangedSpy1, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running)));
+ QVERIFY(compareStates(stateChangedSpy2, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused)));
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1->state(), QAnimationGroup::Running);
+ QCOMPARE(anim2->state(), QAnimationGroup::Paused);
+
+ QTest::qWait(300);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2->state(), QAnimationGroup::Running);
+
+ QCOMPARE(stateChangedSpy2.count(), 4);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(2).at(1)),
+ QAnimationGroup::Stopped);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(3).at(1)),
+ QAnimationGroup::Running);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2->state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::zeroDurationAnimation()
+{
+ QSequentialAnimationGroup group;
+
+ TestAnimation *anim1 = new TestAnimation();
+ anim1->setStartValue(0);
+ anim1->setEndValue(100);
+ anim1->setDuration(0);
+
+ TestAnimation *anim2 = new TestAnimation();
+ anim2->setStartValue(0);
+ anim2->setEndValue(100);
+ anim2->setDuration(100);
+
+ AnimationObject o1;
+ QPropertyAnimation *anim3 = new QPropertyAnimation(&o1, "value");
+ anim3->setEndValue(100);
+ anim3->setDuration(0);
+
+ QSignalSpy stateChangedSpy(anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ group.addAnimation(anim1);
+ group.addAnimation(anim2);
+ group.addAnimation(anim3);
+ group.setLoopCount(2);
+ group.start();
+
+ QCOMPARE(stateChangedSpy.count(), 2);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(anim1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2->state(), QAnimationGroup::Running);
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+
+ //now let's try to seek to the next loop
+ group.setCurrentTime(group.duration() + 1);
+ QCOMPARE(anim1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2->state(), QAnimationGroup::Running);
+ QCOMPARE(anim3->state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(o1.value(), 100); //anim3 should have been run
+}
+
+void tst_QSequentialAnimationGroup::stopUncontrolledAnimations()
+{
+ QSequentialAnimationGroup group;
+
+ AnimationObject o1;
+ UncontrolledAnimation notTimeDriven(&o1, "value");
+ QCOMPARE(notTimeDriven.totalDuration(), -1);
+
+ TestAnimation loopsForever;
+ loopsForever.setStartValue(0);
+ loopsForever.setEndValue(100);
+ loopsForever.setDuration(100);
+ loopsForever.setLoopCount(-1);
+
+ group.addAnimation(&notTimeDriven);
+ group.addAnimation(&loopsForever);
+
+ group.start();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Running);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Stopped);
+
+ notTimeDriven.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Running);
+
+ loopsForever.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::finishWithUncontrolledAnimation()
+{
+ AnimationObject o1;
+
+ //1st case:
+ //first we test a group with one uncontrolled animation
+ QSequentialAnimationGroup group;
+ UncontrolledAnimation notTimeDriven(&o1, "value", &group);
+ QSignalSpy spy(&group, SIGNAL(finished()));
+
+ group.start();
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Running);
+ QCOMPARE(group.currentTime(), 0);
+ QCOMPARE(notTimeDriven.currentTime(), 0);
+
+ QTest::qWait(300); //wait for the end of notTimeDriven
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ const int actualDuration = notTimeDriven.currentTime();
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.currentTime(), actualDuration);
+ QCOMPARE(spy.count(), 1);
+
+ //2nd case:
+ // lets make sure the seeking will work again
+ spy.clear();
+ QPropertyAnimation anim(&group);
+ QSignalSpy animStateChangedSpy(&anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ group.setCurrentTime(300);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven.currentTime(), actualDuration);
+ QCOMPARE(group.currentAnimation(), &anim);
+
+ //3rd case:
+ //now let's add a perfectly defined animation at the end
+ QCOMPARE(animStateChangedSpy.count(), 0);
+ group.start();
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Running);
+ QCOMPARE(group.currentTime(), 0);
+ QCOMPARE(notTimeDriven.currentTime(), 0);
+
+ QCOMPARE(animStateChangedSpy.count(), 0);
+
+ QTest::qWait(300); //wait for the end of notTimeDriven
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Running);
+ QCOMPARE(group.currentAnimation(), &anim);
+ QCOMPARE(animStateChangedSpy.count(), 1);
+ QTest::qWait(300); //wait for the end of anim
+
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim.currentTime(), anim.duration());
+
+ //we should simply be at the end
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(animStateChangedSpy.count(), 2);
+ QCOMPARE(group.currentTime(), notTimeDriven.currentTime() + anim.currentTime());
+}
+
+void tst_QSequentialAnimationGroup::addRemoveAnimation()
+{
+ //this test is specific to the sequential animation group
+ QSequentialAnimationGroup group;
+
+ QCOMPARE(group.duration(), 0);
+ QCOMPARE(group.currentTime(), 0);
+ QVariantAnimation *anim1 = new QPropertyAnimation;
+ group.addAnimation(anim1);
+ QCOMPARE(group.duration(), 250);
+ QCOMPARE(group.currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), anim1);
+
+ //let's append an animation
+ QVariantAnimation *anim2 = new QPropertyAnimation;
+ group.addAnimation(anim2);
+ QCOMPARE(group.duration(), 500);
+ QCOMPARE(group.currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), anim1);
+
+ //let's prepend an animation
+ QVariantAnimation *anim0 = new QPropertyAnimation;
+ group.insertAnimationAt(0, anim0);
+ QCOMPARE(group.duration(), 750);
+ QCOMPARE(group.currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), anim0); //anim0 has become the new currentAnimation
+
+ group.setCurrentTime(300); //anim0 | anim1 | anim2
+ QCOMPARE(group.currentTime(), 300);
+ QCOMPARE(group.currentAnimation(), anim1);
+ QCOMPARE(anim1->currentTime(), 50);
+
+ group.removeAnimation(anim0); //anim1 | anim2
+ QCOMPARE(group.currentTime(), 50);
+ QCOMPARE(group.currentAnimation(), anim1);
+ QCOMPARE(anim1->currentTime(), 50);
+
+ group.setCurrentTime(0);
+ group.insertAnimationAt(0, anim0); //anim0 | anim1 | anim2
+ group.setCurrentTime(300);
+ QCOMPARE(group.currentTime(), 300);
+ QCOMPARE(group.currentAnimation(), anim1);
+ QCOMPARE(anim1->currentTime(), 50);
+
+ group.removeAnimation(anim1); //anim0 | anim2
+ QCOMPARE(group.currentTime(), 250);
+ QCOMPARE(group.currentAnimation(), anim2);
+ QCOMPARE(anim0->currentTime(), 250);
+}
+
+void tst_QSequentialAnimationGroup::currentAnimation()
+{
+ QSequentialAnimationGroup group;
+ QVERIFY(group.currentAnimation() == 0);
+
+ QPropertyAnimation anim;
+ anim.setDuration(0);
+ group.addAnimation(&anim);
+ QCOMPARE(group.currentAnimation(), &anim);
+}
+
+void tst_QSequentialAnimationGroup::currentAnimationWithZeroDuration()
+{
+ QSequentialAnimationGroup group;
+ QVERIFY(group.currentAnimation() == 0);
+
+ QPropertyAnimation zero1;
+ zero1.setDuration(0);
+ QPropertyAnimation zero2;
+ zero2.setDuration(0);
+
+ QPropertyAnimation anim;
+
+ QPropertyAnimation zero3;
+ zero3.setDuration(0);
+ QPropertyAnimation zero4;
+ zero4.setDuration(0);
+
+
+ group.addAnimation(&zero1);
+ group.addAnimation(&zero2);
+ group.addAnimation(&anim);
+ group.addAnimation(&zero3);
+ group.addAnimation(&zero4);
+
+ QCOMPARE(group.currentAnimation(), &zero1);
+
+ group.setCurrentTime(0);
+ QCOMPARE(group.currentAnimation(), &anim);
+
+ group.setCurrentTime(group.duration());
+ QCOMPARE(group.currentAnimation(), &zero4);
+
+ group.setDirection(QAbstractAnimation::Backward);
+
+ group.setCurrentTime(0);
+ QCOMPARE(group.currentAnimation(), &zero1);
+
+ group.setCurrentTime(group.duration());
+ QCOMPARE(group.currentAnimation(), &anim);
+}
+
+void tst_QSequentialAnimationGroup::insertAnimation()
+{
+ QSequentialAnimationGroup group;
+ group.setLoopCount(2);
+ QPropertyAnimation *anim = new QPropertyAnimation(&group);
+ QCOMPARE(group.duration(), anim->duration());
+ group.setCurrentTime(300);
+ QCOMPARE(group.currentLoop(), 1);
+
+ //this will crash if the sequential group calls duration on the created animation
+ new QPropertyAnimation(&group);
+}
+
+
+class SequentialAnimationGroup : public QSequentialAnimationGroup
+{
+ Q_OBJECT
+public slots:
+ void clearAnimations()
+ {
+ QSequentialAnimationGroup::clearAnimations();
+ }
+
+ void refill()
+ {
+ stop();
+ clearAnimations();
+ new QPropertyAnimation(this);
+ start();
+ }
+
+};
+
+
+void tst_QSequentialAnimationGroup::clearAnimations()
+{
+ SequentialAnimationGroup group;
+ QPointer<QAbstractAnimation> anim1 = new QPropertyAnimation(&group);
+ group.connect(anim1, SIGNAL(finished()), SLOT(clearAnimations()));
+ new QPropertyAnimation(&group);
+ QCOMPARE(group.animationCount(), 2);
+
+ group.start();
+ QTest::qWait(anim1->duration() + 100);
+ QCOMPARE(group.animationCount(), 0);
+ QCOMPARE(group.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(group.currentTime(), 0);
+
+ anim1 = new QPropertyAnimation(&group);
+ group.connect(anim1, SIGNAL(finished()), SLOT(refill()));
+ group.start();
+ QTest::qWait(anim1->duration() + 100);
+ QVERIFY(anim1 == 0); //anim1 should have been deleted
+ QCOMPARE(group.state(), QAbstractAnimation::Running);
+}
+
+QTEST_MAIN(tst_QSequentialAnimationGroup)
+#include "tst_qsequentialanimationgroup.moc"
diff --git a/tests/auto/qstate/qstate.pro b/tests/auto/qstate/qstate.pro
new file mode 100644
index 0000000..9131fa8
--- /dev/null
+++ b/tests/auto/qstate/qstate.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+QT = core
+SOURCES += tst_qstate.cpp
+
+
diff --git a/tests/auto/qstate/tst_qstate.cpp b/tests/auto/qstate/tst_qstate.cpp
new file mode 100644
index 0000000..75b1905
--- /dev/null
+++ b/tests/auto/qstate/tst_qstate.cpp
@@ -0,0 +1,340 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include "qstate.h"
+#include "qstatemachine.h"
+#include "qsignaltransition.h"
+
+// Will try to wait for the condition while allowing event processing
+#define QTRY_COMPARE(__expr, __expected) \
+ do { \
+ const int __step = 50; \
+ const int __timeout = 5000; \
+ if ((__expr) != (__expected)) { \
+ QTest::qWait(0); \
+ } \
+ for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
+ QTest::qWait(__step); \
+ } \
+ QCOMPARE(__expr, __expected); \
+ } while(0)
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+class tst_QState : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QState();
+ virtual ~tst_QState();
+
+private slots:
+#if 0
+ void test();
+#endif
+ void assignProperty();
+ void assignPropertyTwice();
+ void historyInitialState();
+
+private:
+ bool functionCalled;
+};
+
+tst_QState::tst_QState() : functionCalled(false)
+{
+}
+
+tst_QState::~tst_QState()
+{
+}
+
+#if 0
+void tst_QState::test()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+
+ QCOMPARE(s1->machine(), &machine);
+ QCOMPARE(s1->parentState(), machine.rootState());
+ QCOMPARE(s1->initialState(), (QState*)0);
+ QVERIFY(s1->childStates().isEmpty());
+ QVERIFY(s1->transitions().isEmpty());
+
+ QCOMPARE(s1->isFinal(), false);
+ s1->setFinal(true);
+ QCOMPARE(s1->isFinal(), true);
+ s1->setFinal(false);
+ QCOMPARE(s1->isFinal(), false);
+
+ QCOMPARE(s1->isParallel(), false);
+ s1->setParallel(true);
+ QCOMPARE(s1->isParallel(), true);
+ s1->setParallel(false);
+ QCOMPARE(s1->isParallel(), false);
+
+ QCOMPARE(s1->isAtomic(), true);
+ QCOMPARE(s1->isCompound(), false);
+ QCOMPARE(s1->isComplex(), false);
+
+ QState *s11 = new QState(s1);
+ QCOMPARE(s11->parentState(), s1);
+ QCOMPARE(s11->isAtomic(), true);
+ QCOMPARE(s11->isCompound(), false);
+ QCOMPARE(s11->isComplex(), false);
+ QCOMPARE(s11->machine(), s1->machine());
+ QVERIFY(s11->isDescendantOf(s1));
+
+ QCOMPARE(s1->initialState(), (QState*)0);
+ QCOMPARE(s1->childStates().size(), 1);
+ QCOMPARE(s1->childStates().at(0), s11);
+
+ QCOMPARE(s1->isAtomic(), false);
+ QCOMPARE(s1->isCompound(), true);
+ QCOMPARE(s1->isComplex(), true);
+
+ s1->setParallel(true);
+ QCOMPARE(s1->isAtomic(), false);
+ QCOMPARE(s1->isCompound(), false);
+ QCOMPARE(s1->isComplex(), true);
+
+ QState *s12 = new QState(s1);
+ QCOMPARE(s12->parentState(), s1);
+ QCOMPARE(s12->isAtomic(), true);
+ QCOMPARE(s12->isCompound(), false);
+ QCOMPARE(s12->isComplex(), false);
+ QCOMPARE(s12->machine(), s1->machine());
+ QVERIFY(s12->isDescendantOf(s1));
+ QVERIFY(!s12->isDescendantOf(s11));
+
+ QCOMPARE(s1->initialState(), (QState*)0);
+ QCOMPARE(s1->childStates().size(), 2);
+ QCOMPARE(s1->childStates().at(0), s11);
+ QCOMPARE(s1->childStates().at(1), s12);
+
+ QCOMPARE(s1->isAtomic(), false);
+ QCOMPARE(s1->isCompound(), false);
+ QCOMPARE(s1->isComplex(), true);
+
+ s1->setParallel(false);
+ QCOMPARE(s1->isAtomic(), false);
+ QCOMPARE(s1->isCompound(), true);
+ QCOMPARE(s1->isComplex(), true);
+
+ s1->setInitialState(s11);
+ QCOMPARE(s1->initialState(), s11);
+
+ s1->setInitialState(0);
+ QCOMPARE(s1->initialState(), (QState*)0);
+
+ s1->setInitialState(s12);
+ QCOMPARE(s1->initialState(), s12);
+
+ QState *s13 = new QState();
+ s1->setInitialState(s13);
+ QCOMPARE(s13->parentState(), s1);
+ QCOMPARE(s1->childStates().size(), 3);
+ QCOMPARE(s1->childStates().at(0), s11);
+ QCOMPARE(s1->childStates().at(1), s12);
+ QCOMPARE(s1->childStates().at(2), s13);
+ QVERIFY(s13->isDescendantOf(s1));
+
+ QVERIFY(s12->childStates().isEmpty());
+
+ QState *s121 = new QState(s12);
+ QCOMPARE(s121->parentState(), s12);
+ QCOMPARE(s121->isAtomic(), true);
+ QCOMPARE(s121->isCompound(), false);
+ QCOMPARE(s121->isComplex(), false);
+ QCOMPARE(s121->machine(), s12->machine());
+ QVERIFY(s121->isDescendantOf(s12));
+ QVERIFY(s121->isDescendantOf(s1));
+ QVERIFY(!s121->isDescendantOf(s11));
+
+ QCOMPARE(s12->childStates().size(), 1);
+ QCOMPARE(s12->childStates().at(0), (QState*)s121);
+
+ QCOMPARE(s1->childStates().size(), 3);
+ QCOMPARE(s1->childStates().at(0), s11);
+ QCOMPARE(s1->childStates().at(1), s12);
+ QCOMPARE(s1->childStates().at(2), s13);
+
+ s11->addTransition(s12);
+ QCOMPARE(s11->transitions().size(), 1);
+ QCOMPARE(s11->transitions().at(0)->sourceState(), s11);
+ QCOMPARE(s11->transitions().at(0)->targetStates().size(), 1);
+ QCOMPARE(s11->transitions().at(0)->targetStates().at(0), s12);
+ QCOMPARE(s11->transitions().at(0)->eventType(), QEvent::None);
+
+ QState *s14 = new QState();
+ s12->addTransition(QList<QState*>() << s13 << s14);
+ QCOMPARE(s12->transitions().size(), 1);
+ QCOMPARE(s12->transitions().at(0)->sourceState(), s12);
+ QCOMPARE(s12->transitions().at(0)->targetStates().size(), 2);
+ QCOMPARE(s12->transitions().at(0)->targetStates().at(0), s13);
+ QCOMPARE(s12->transitions().at(0)->targetStates().at(1), s14);
+ QCOMPARE(s12->transitions().at(0)->eventType(), QEvent::None);
+
+ s13->addTransition(this, SIGNAL(destroyed()), s14);
+ QCOMPARE(s13->transitions().size(), 1);
+ QCOMPARE(s13->transitions().at(0)->sourceState(), s13);
+ QCOMPARE(s13->transitions().at(0)->targetStates().size(), 1);
+ QCOMPARE(s13->transitions().at(0)->targetStates().at(0), s14);
+ QCOMPARE(s13->transitions().at(0)->eventType(), QEvent::Signal);
+ QVERIFY(qobject_cast<QSignalTransition*>(s13->transitions().at(0)) != 0);
+
+ delete s13->transitions().at(0);
+ QCOMPARE(s13->transitions().size(), 0);
+
+ s12->addTransition(this, SIGNAL(destroyed()), s11);
+ QCOMPARE(s12->transitions().size(), 2);
+}
+#endif
+
+class TestClass: public QObject
+{
+ Q_OBJECT
+public:
+ TestClass() : called(false) {}
+ bool called;
+
+public slots:
+ void slot() { called = true; }
+
+
+};
+
+void tst_QState::assignProperty()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("fooBar", 10);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(object, "fooBar", 20);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("fooBar").toInt(), 20);
+}
+
+void tst_QState::assignPropertyTwice()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("fooBar", 10);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(object, "fooBar", 20);
+ s1->assignProperty(object, "fooBar", 30);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("fooBar").toInt(), 30);
+}
+
+class EventTestTransition: public QAbstractTransition
+{
+public:
+ EventTestTransition(QEvent::Type type, QState *targetState)
+ : QAbstractTransition(QList<QAbstractState*>() << targetState), m_type(type)
+ {
+ }
+
+protected:
+ bool eventTest(QEvent *e)
+ {
+ return e->type() == m_type;
+ }
+
+ void onTransition(QEvent *) {}
+
+private:
+ QEvent::Type m_type;
+
+};
+
+void tst_QState::historyInitialState()
+{
+ QStateMachine machine;
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ QHistoryState *h1 = new QHistoryState(s2);
+
+ s2->setInitialState(h1);
+
+ QState *s3 = new QState(s2);
+ h1->setDefaultState(s3);
+
+ QState *s4 = new QState(s2);
+
+ s1->addTransition(new EventTestTransition(QEvent::User, s2));
+ s2->addTransition(new EventTestTransition(QEvent::User, s1));
+ s3->addTransition(new EventTestTransition(QEvent::Type(QEvent::User+1), s4));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s3));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s3));
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User+1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s4));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s4));
+}
+
+
+QTEST_MAIN(tst_QState)
+#include "tst_qstate.moc"
diff --git a/tests/auto/qstatemachine/qstatemachine.pro b/tests/auto/qstatemachine/qstatemachine.pro
new file mode 100644
index 0000000..e5b32b5
--- /dev/null
+++ b/tests/auto/qstatemachine/qstatemachine.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+QT = core gui
+SOURCES += tst_qstatemachine.cpp
+
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
new file mode 100644
index 0000000..768a683
--- /dev/null
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -0,0 +1,3730 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtCore/QCoreApplication>
+#include <QtGui/QPushButton>
+
+#include "qstatemachine.h"
+#include "qstate.h"
+#include "qhistorystate.h"
+#include "qkeyeventtransition.h"
+#include "qmouseeventtransition.h"
+#include "private/qstate_p.h"
+#include "private/qstatemachine_p.h"
+
+// Will try to wait for the condition while allowing event processing
+#define QTRY_COMPARE(__expr, __expected) \
+ do { \
+ const int __step = 50; \
+ const int __timeout = 5000; \
+ if ((__expr) != (__expected)) { \
+ QTest::qWait(0); \
+ } \
+ for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
+ QTest::qWait(__step); \
+ } \
+ QCOMPARE(__expr, __expected); \
+ } while(0)
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+static int globalTick;
+
+// Run exec for a maximum of TIMEOUT msecs
+#define QCOREAPPLICATION_EXEC(TIMEOUT) \
+{ \
+ QTimer timer; \
+ timer.setSingleShot(true); \
+ timer.setInterval(TIMEOUT); \
+ timer.start(); \
+ connect(&timer, SIGNAL(timeout()), QCoreApplication::instance(), SLOT(quit())); \
+ QCoreApplication::exec(); \
+}
+
+class SignalEmitter : public QObject
+{
+Q_OBJECT
+ public:
+ SignalEmitter(QObject *parent = 0)
+ : QObject(parent) {}
+ void emitSignalWithNoArg()
+ { emit signalWithNoArg(); }
+ void emitSignalWithIntArg(int arg)
+ { emit signalWithIntArg(arg); }
+ void emitSignalWithStringArg(const QString &arg)
+ { emit signalWithStringArg(arg); }
+Q_SIGNALS:
+ void signalWithNoArg();
+ void signalWithIntArg(int);
+ void signalWithStringArg(const QString &);
+};
+
+class tst_QStateMachine : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QStateMachine();
+ virtual ~tst_QStateMachine();
+
+private slots:
+ void init();
+ void cleanup();
+
+ void rootState();
+ void addAndRemoveState();
+ void stateEntryAndExit();
+ void assignProperty();
+ void assignPropertyWithAnimation();
+ void postEvent();
+ void stateFinished();
+ void parallelStates();
+ void allSourceToTargetConfigurations();
+ void signalTransitions();
+ void eventTransitions();
+ void historyStates();
+ void startAndStop();
+ void targetStateWithNoParent();
+ void targetStateDeleted();
+ void transitionToRootState();
+ void transitionEntersParent();
+
+ void defaultErrorState();
+ void customGlobalErrorState();
+ void customLocalErrorStateInBrokenState();
+ void customLocalErrorStateInOtherState();
+ void customLocalErrorStateInParentOfBrokenState();
+ void customLocalErrorStateOverridesParent();
+ void errorStateHasChildren();
+ void errorStateHasErrors();
+ void errorStateIsRootState();
+ void errorStateEntersParentFirst();
+ void customErrorStateIsNull();
+ void clearError();
+ void historyStateHasNowhereToGo();
+ void historyStateAsInitialState();
+ void brokenStateIsNeverEntered();
+ void customErrorStateNotInGraph();
+ void transitionToStateNotInGraph();
+ void restoreProperties();
+
+ void defaultGlobalRestorePolicy();
+ void globalRestorePolicySetToRestore();
+ void globalRestorePolicySetToDoNotRestore();
+
+ //void restorePolicyNotInherited();
+ //void mixedRestoreProperties();
+ //void setRestorePolicyToDoNotRestore();
+ //void setGlobalRestorePolicyToGlobalRestore();
+ //void restorePolicyOnChildState();
+
+ void transitionWithParent();
+ void transitionsFromParallelStateWithNoChildren();
+ void parallelStateTransition();
+ void parallelStateAssignmentsDone();
+ void nestedRestoreProperties();
+ void nestedRestoreProperties2();
+
+ void simpleAnimation();
+ void twoAnimations();
+ void twoAnimatedTransitions();
+ void playAnimationTwice();
+ void nestedTargetStateForAnimation();
+ void animatedGlobalRestoreProperty();
+ void specificTargetValueOfAnimation();
+
+ void addDefaultAnimation();
+ void addDefaultAnimationWithUnusedAnimation();
+ void removeDefaultAnimation();
+ void overrideDefaultAnimationWithSpecific();
+
+// void addDefaultAnimationForSource();
+// void addDefaultAnimationForTarget();
+// void removeDefaultAnimationForSource();
+// void removeDefaultAnimationForTarget();
+// void overrideDefaultAnimationWithSource();
+// void overrideDefaultAnimationWithTarget();
+// void overrideDefaultSourceAnimationWithSpecific();
+// void overrideDefaultTargetAnimationWithSpecific();
+// void overrideDefaultTargetAnimationWithSource();
+};
+
+tst_QStateMachine::tst_QStateMachine()
+{
+}
+
+tst_QStateMachine::~tst_QStateMachine()
+{
+}
+
+class TestState : public QState
+{
+public:
+ enum Event {
+ Entry,
+ Exit
+ };
+ TestState(QState *parent)
+ : QState(parent) {}
+ QList<QPair<int, Event> > events;
+protected:
+ virtual void onEntry(QEvent *) {
+ events.append(qMakePair(globalTick++, Entry));
+ }
+ virtual void onExit(QEvent *) {
+ events.append(qMakePair(globalTick++, Exit));
+ }
+};
+
+class TestTransition : public QAbstractTransition
+{
+public:
+ TestTransition(QAbstractState *target)
+ : QAbstractTransition(QList<QAbstractState*>() << target) {}
+ QList<int> triggers;
+protected:
+ virtual bool eventTest(QEvent *) {
+ return true;
+ }
+ virtual void onTransition(QEvent *) {
+ triggers.append(globalTick++);
+ }
+};
+
+void tst_QStateMachine::init()
+{
+}
+
+void tst_QStateMachine::cleanup()
+{
+}
+
+class EventTransition : public QAbstractTransition
+{
+public:
+ EventTransition(QEvent::Type type, QAbstractState *target, QState *parent = 0)
+ : QAbstractTransition(QList<QAbstractState*>() << target, parent), m_type(type) {}
+protected:
+ virtual bool eventTest(QEvent *e) {
+ return (e->type() == m_type);
+ }
+ virtual void onTransition(QEvent *) {}
+private:
+ QEvent::Type m_type;
+};
+
+void tst_QStateMachine::transitionToRootState()
+{
+ QStateMachine machine;
+
+ QState *initialState = new QState();
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QTest::ignoreMessage(QtWarningMsg, "QAbstractTransition::setTargetStates: root state cannot be target of transition");
+ initialState->addTransition(new EventTransition(QEvent::User, machine.rootState()));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(initialState));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(initialState));
+}
+
+void tst_QStateMachine::transitionEntersParent()
+{
+ QStateMachine machine;
+
+ QObject *entryController = new QObject(&machine);
+ entryController->setObjectName("entryController");
+ entryController->setProperty("greatGrandParentEntered", false);
+ entryController->setProperty("grandParentEntered", false);
+ entryController->setProperty("parentEntered", false);
+ entryController->setProperty("stateEntered", false);
+
+ QState *greatGrandParent = new QState();
+ greatGrandParent->setObjectName("grandParent");
+ greatGrandParent->assignProperty(entryController, "greatGrandParentEntered", true);
+ machine.addState(greatGrandParent);
+ machine.setInitialState(greatGrandParent);
+
+ QState *grandParent = new QState(greatGrandParent);
+ grandParent->setObjectName("grandParent");
+ grandParent->assignProperty(entryController, "grandParentEntered", true);
+
+ QState *parent = new QState(grandParent);
+ parent->setObjectName("parent");
+ parent->assignProperty(entryController, "parentEntered", true);
+
+ QState *state = new QState(parent);
+ state->setObjectName("state");
+ state->assignProperty(entryController, "stateEntered", true);
+
+ QState *initialStateOfGreatGrandParent = new QState(greatGrandParent);
+ initialStateOfGreatGrandParent->setObjectName("initialStateOfGreatGrandParent");
+ greatGrandParent->setInitialState(initialStateOfGreatGrandParent);
+
+ initialStateOfGreatGrandParent->addTransition(new EventTransition(QEvent::User, state));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(entryController->property("greatGrandParentEntered").toBool(), true);
+ QCOMPARE(entryController->property("grandParentEntered").toBool(), false);
+ QCOMPARE(entryController->property("parentEntered").toBool(), false);
+ QCOMPARE(entryController->property("stateEntered").toBool(), false);
+ QCOMPARE(machine.configuration().count(), 2);
+ QVERIFY(machine.configuration().contains(greatGrandParent));
+ QVERIFY(machine.configuration().contains(initialStateOfGreatGrandParent));
+
+ entryController->setProperty("greatGrandParentEntered", false);
+ entryController->setProperty("grandParentEntered", false);
+ entryController->setProperty("parentEntered", false);
+ entryController->setProperty("stateEntered", false);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(entryController->property("greatGrandParentEntered").toBool(), false);
+ QCOMPARE(entryController->property("grandParentEntered").toBool(), true);
+ QCOMPARE(entryController->property("parentEntered").toBool(), true);
+ QCOMPARE(entryController->property("stateEntered").toBool(), true);
+ QCOMPARE(machine.configuration().count(), 4);
+ QVERIFY(machine.configuration().contains(greatGrandParent));
+ QVERIFY(machine.configuration().contains(grandParent));
+ QVERIFY(machine.configuration().contains(parent));
+ QVERIFY(machine.configuration().contains(state));
+}
+
+void tst_QStateMachine::defaultErrorState()
+{
+ QStateMachine machine;
+ QVERIFY(machine.errorState() != 0);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("MyInitialState");
+
+ machine.addState(brokenState);
+ machine.setInitialState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state 'MyInitialState'");
+
+ // initialState has no initial state
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.error(), QStateMachine::NoInitialStateError);
+ QCOMPARE(machine.errorString(), QString::fromLatin1("Missing initial state in compound state 'MyInitialState'"));
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+}
+
+class CustomErrorState: public QState
+{
+public:
+ CustomErrorState(QStateMachine *machine, QState *parent = 0)
+ : QState(parent), error(QStateMachine::NoError), m_machine(machine)
+ {
+ }
+
+ void onEntry(QEvent *)
+ {
+ error = m_machine->error();
+ errorString = m_machine->errorString();
+ }
+
+ QStateMachine::Error error;
+ QString errorString;
+
+private:
+ QStateMachine *m_machine;
+};
+
+void tst_QStateMachine::customGlobalErrorState()
+{
+ QStateMachine machine;
+
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ customErrorState->setObjectName("customErrorState");
+ machine.addState(customErrorState);
+ machine.setErrorState(customErrorState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+ machine.addState(brokenState);
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.errorState(), customErrorState);
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(initialState));
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(initialState));
+
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(customErrorState));
+ QCOMPARE(customErrorState->error, QStateMachine::NoInitialStateError);
+ QCOMPARE(customErrorState->errorString, QString::fromLatin1("Missing initial state in compound state 'brokenState'"));
+ QCOMPARE(machine.error(), QStateMachine::NoInitialStateError);
+ QCOMPARE(machine.errorString(), QString::fromLatin1("Missing initial state in compound state 'brokenState'"));
+}
+
+void tst_QStateMachine::customLocalErrorStateInBrokenState()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ machine.addState(customErrorState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+ machine.addState(brokenState);
+ brokenState->setErrorState(customErrorState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(customErrorState));
+ QCOMPARE(customErrorState->error, QStateMachine::NoInitialStateError);
+}
+
+void tst_QStateMachine::customLocalErrorStateInOtherState()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ machine.addState(customErrorState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ QTest::ignoreMessage(QtWarningMsg, "QState::setErrorState: error state cannot belong to a different state machine");
+ initialState->setErrorState(customErrorState);
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+
+ machine.addState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state 'brokenState'");
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+}
+
+void tst_QStateMachine::customLocalErrorStateInParentOfBrokenState()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ machine.addState(customErrorState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *parentOfBrokenState = new QState();
+ machine.addState(parentOfBrokenState);
+ parentOfBrokenState->setObjectName("parentOfBrokenState");
+ parentOfBrokenState->setErrorState(customErrorState);
+
+ QState *brokenState = new QState(parentOfBrokenState);
+ brokenState->setObjectName("brokenState");
+ parentOfBrokenState->setInitialState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(customErrorState));
+}
+
+void tst_QStateMachine::customLocalErrorStateOverridesParent()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorStateForParent = new CustomErrorState(&machine);
+ machine.addState(customErrorStateForParent);
+
+ CustomErrorState *customErrorStateForBrokenState = new CustomErrorState(&machine);
+ machine.addState(customErrorStateForBrokenState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *parentOfBrokenState = new QState();
+ machine.addState(parentOfBrokenState);
+ parentOfBrokenState->setObjectName("parentOfBrokenState");
+ parentOfBrokenState->setErrorState(customErrorStateForParent);
+
+ QState *brokenState = new QState(parentOfBrokenState);
+ brokenState->setObjectName("brokenState");
+ brokenState->setErrorState(customErrorStateForBrokenState);
+ parentOfBrokenState->setInitialState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(customErrorStateForBrokenState));
+ QCOMPARE(customErrorStateForBrokenState->error, QStateMachine::NoInitialStateError);
+ QCOMPARE(customErrorStateForParent->error, QStateMachine::NoError);
+}
+
+void tst_QStateMachine::errorStateHasChildren()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ customErrorState->setObjectName("customErrorState");
+ machine.addState(customErrorState);
+
+ machine.setErrorState(customErrorState);
+
+ QState *childOfErrorState = new QState(customErrorState);
+ childOfErrorState->setObjectName("childOfErrorState");
+ customErrorState->setInitialState(childOfErrorState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+ machine.addState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 2);
+ QVERIFY(machine.configuration().contains(customErrorState));
+ QVERIFY(machine.configuration().contains(childOfErrorState));
+}
+
+
+void tst_QStateMachine::errorStateHasErrors()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ customErrorState->setObjectName("customErrorState");
+ machine.addState(customErrorState);
+
+ QAbstractState *oldErrorState = machine.errorState();
+ machine.setErrorState(customErrorState);
+
+ QState *childOfErrorState = new QState(customErrorState);
+ childOfErrorState->setObjectName("childOfErrorState");
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+ machine.addState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state 'customErrorState'");
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(oldErrorState)); // Fall back to default
+ QCOMPARE(machine.error(), QStateMachine::NoInitialStateError);
+ QCOMPARE(machine.errorString(), QString::fromLatin1("Missing initial state in compound state 'customErrorState'"));
+}
+
+void tst_QStateMachine::errorStateIsRootState()
+{
+ QStateMachine machine;
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::setErrorState: root state cannot be error state");
+ machine.setErrorState(machine.rootState());
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+ machine.addState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state 'brokenState'");
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+}
+
+void tst_QStateMachine::errorStateEntersParentFirst()
+{
+ QStateMachine machine;
+
+ QObject *entryController = new QObject(&machine);
+ entryController->setObjectName("entryController");
+ entryController->setProperty("greatGrandParentEntered", false);
+ entryController->setProperty("grandParentEntered", false);
+ entryController->setProperty("parentEntered", false);
+ entryController->setProperty("errorStateEntered", false);
+
+ QState *greatGrandParent = new QState();
+ greatGrandParent->setObjectName("greatGrandParent");
+ greatGrandParent->assignProperty(entryController, "greatGrandParentEntered", true);
+ machine.addState(greatGrandParent);
+ machine.setInitialState(greatGrandParent);
+
+ QState *grandParent = new QState(greatGrandParent);
+ grandParent->setObjectName("grandParent");
+ grandParent->assignProperty(entryController, "grandParentEntered", true);
+
+ QState *parent = new QState(grandParent);
+ parent->setObjectName("parent");
+ parent->assignProperty(entryController, "parentEntered", true);
+
+ QState *errorState = new QState(parent);
+ errorState->setObjectName("errorState");
+ errorState->assignProperty(entryController, "errorStateEntered", true);
+ machine.setErrorState(errorState);
+
+ QState *initialStateOfGreatGrandParent = new QState(greatGrandParent);
+ initialStateOfGreatGrandParent->setObjectName("initialStateOfGreatGrandParent");
+ greatGrandParent->setInitialState(initialStateOfGreatGrandParent);
+
+ QState *brokenState = new QState(greatGrandParent);
+ brokenState->setObjectName("brokenState");
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialStateOfGreatGrandParent->addTransition(new EventTransition(QEvent::User, brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(entryController->property("greatGrandParentEntered").toBool(), true);
+ QCOMPARE(entryController->property("grandParentEntered").toBool(), false);
+ QCOMPARE(entryController->property("parentEntered").toBool(), false);
+ QCOMPARE(entryController->property("errorStateEntered").toBool(), false);
+ QCOMPARE(machine.configuration().count(), 2);
+ QVERIFY(machine.configuration().contains(greatGrandParent));
+ QVERIFY(machine.configuration().contains(initialStateOfGreatGrandParent));
+
+ entryController->setProperty("greatGrandParentEntered", false);
+ entryController->setProperty("grandParentEntered", false);
+ entryController->setProperty("parentEntered", false);
+ entryController->setProperty("errorStateEntered", false);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(entryController->property("greatGrandParentEntered").toBool(), false);
+ QCOMPARE(entryController->property("grandParentEntered").toBool(), true);
+ QCOMPARE(entryController->property("parentEntered").toBool(), true);
+ QCOMPARE(entryController->property("errorStateEntered").toBool(), true);
+ QCOMPARE(machine.configuration().count(), 4);
+ QVERIFY(machine.configuration().contains(greatGrandParent));
+ QVERIFY(machine.configuration().contains(grandParent));
+ QVERIFY(machine.configuration().contains(parent));
+ QVERIFY(machine.configuration().contains(errorState));
+}
+
+void tst_QStateMachine::customErrorStateIsNull()
+{
+ QStateMachine machine;
+ QAbstractState *oldErrorState = machine.errorState();
+ machine.rootState()->setErrorState(0);
+
+ QState *initialState = new QState();
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ machine.addState(brokenState);
+
+ new QState(brokenState);
+ initialState->addTransition(new EventTransition(QEvent::User, brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state ''");
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.errorState(), reinterpret_cast<void *>(0));
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(oldErrorState));
+}
+
+void tst_QStateMachine::clearError()
+{
+ QStateMachine machine;
+ machine.setErrorState(new QState(machine.rootState())); // avoid warnings
+
+ QState *brokenState = new QState(machine.rootState());
+ brokenState->setObjectName("brokenState");
+ machine.setInitialState(brokenState);
+ new QState(brokenState);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.error(), QStateMachine::NoInitialStateError);
+ QCOMPARE(machine.errorString(), QString::fromLatin1("Missing initial state in compound state 'brokenState'"));
+
+ machine.clearError();
+
+ QCOMPARE(machine.error(), QStateMachine::NoError);
+ QVERIFY(machine.errorString().isEmpty());
+}
+
+void tst_QStateMachine::historyStateAsInitialState()
+{
+ QStateMachine machine;
+
+ QHistoryState *hs = new QHistoryState(machine.rootState());
+ machine.setInitialState(hs);
+
+ QState *s1 = new QState(machine.rootState());
+ hs->setDefaultState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+
+ QHistoryState *s2h = new QHistoryState(s2);
+ s2->setInitialState(s2h);
+
+ QState *s21 = new QState(s2);
+ s2h->setDefaultState(s21);
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s21));
+}
+
+void tst_QStateMachine::historyStateHasNowhereToGo()
+{
+ QStateMachine machine;
+
+ QState *initialState = new QState(machine.rootState());
+ machine.setInitialState(initialState);
+ machine.setErrorState(new QState(machine.rootState())); // avoid warnings
+
+ QState *brokenState = new QState(machine.rootState());
+ brokenState->setObjectName("brokenState");
+ brokenState->setInitialState(new QState(brokenState));
+
+ QHistoryState *historyState = new QHistoryState(brokenState);
+ historyState->setObjectName("historyState");
+ initialState->addTransition(new EventTransition(QEvent::User, historyState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+ QCOMPARE(machine.error(), QStateMachine::NoDefaultStateInHistoryStateError);
+ QCOMPARE(machine.errorString(), QString::fromLatin1("Missing default state in history state 'historyState'"));
+}
+
+void tst_QStateMachine::brokenStateIsNeverEntered()
+{
+ QStateMachine machine;
+
+ QObject *entryController = new QObject(&machine);
+ entryController->setProperty("brokenStateEntered", false);
+ entryController->setProperty("childStateEntered", false);
+ entryController->setProperty("errorStateEntered", false);
+
+ QState *initialState = new QState(machine.rootState());
+ machine.setInitialState(initialState);
+
+ QState *errorState = new QState(machine.rootState());
+ errorState->assignProperty(entryController, "errorStateEntered", true);
+ machine.setErrorState(errorState);
+
+ QState *brokenState = new QState(machine.rootState());
+ brokenState->assignProperty(entryController, "brokenStateEntered", true);
+ brokenState->setObjectName("brokenState");
+
+ QState *childState = new QState(brokenState);
+ childState->assignProperty(entryController, "childStateEntered", true);
+
+ initialState->addTransition(new EventTransition(QEvent::User, brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(entryController->property("errorStateEntered").toBool(), true);
+ QCOMPARE(entryController->property("brokenStateEntered").toBool(), false);
+ QCOMPARE(entryController->property("childStateEntered").toBool(), false);
+}
+
+void tst_QStateMachine::transitionToStateNotInGraph()
+{
+ QStateMachine machine;
+
+ QState *initialState = new QState(machine.rootState());
+ initialState->setObjectName("initialState");
+ machine.setInitialState(initialState);
+
+ QState independentState;
+ independentState.setObjectName("independentState");
+ initialState->addTransition(&independentState);
+
+ machine.start();
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: No common ancestor for targets and source of transition from state 'initialState'");
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(qobject_cast<QState*>(machine.rootState())->errorState()));
+}
+
+void tst_QStateMachine::customErrorStateNotInGraph()
+{
+ QStateMachine machine;
+
+ QState errorState;
+ errorState.setObjectName("errorState");
+ QTest::ignoreMessage(QtWarningMsg, "QState::setErrorState: error state cannot belong to a different state machine");
+ machine.setErrorState(&errorState);
+ QVERIFY(&errorState != machine.errorState());
+
+ QState *initialBrokenState = new QState(machine.rootState());
+ initialBrokenState->setObjectName("initialBrokenState");
+ machine.setInitialState(initialBrokenState);
+ new QState(initialBrokenState);
+
+ machine.start();
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state 'initialBrokenState'");
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+}
+
+void tst_QStateMachine::restoreProperties()
+{
+ QStateMachine machine;
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::DoNotRestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("a", 1);
+ object->setProperty("b", 2);
+
+ QState *S1 = new QState();
+ S1->setObjectName("S1");
+ S1->assignProperty(object, "a", 3);
+ machine.addState(S1);
+
+ QState *S2 = new QState();
+ S2->setObjectName("S2");
+ S2->assignProperty(object, "b", 5);
+ machine.addState(S2);
+
+ QState *S3 = new QState();
+ S3->setObjectName("S3");
+ machine.addState(S3);
+
+ QFinalState *S4 = new QFinalState();
+ machine.addState(S4);
+
+ S1->addTransition(new EventTransition(QEvent::User, S2));
+ S2->addTransition(new EventTransition(QEvent::User, S3));
+ S3->addTransition(S4);
+
+ machine.setInitialState(S1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 3);
+ QCOMPARE(object->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 1);
+ QCOMPARE(object->property("b").toInt(), 5);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 1);
+ QCOMPARE(object->property("b").toInt(), 2);
+}
+
+void tst_QStateMachine::rootState()
+{
+ QStateMachine machine;
+ QVERIFY(machine.rootState() != 0);
+ QVERIFY(qobject_cast<QState*>(machine.rootState()) != 0);
+ QCOMPARE(qobject_cast<QState*>(machine.rootState())->parentState(), (QState*)0);
+ QCOMPARE(machine.rootState()->parent(), (QObject*)&machine);
+ QCOMPARE(machine.rootState()->machine(), &machine);
+
+ QState *s1 = new QState(machine.rootState());
+ QCOMPARE(s1->parentState(), machine.rootState());
+
+ QState *s2 = new QState();
+ s2->setParent(&machine);
+ QCOMPARE(s2->parentState(), machine.rootState());
+}
+
+void tst_QStateMachine::addAndRemoveState()
+{
+ QStateMachine machine;
+ QStatePrivate *root_d = QStatePrivate::get(machine.rootState());
+ QCOMPARE(root_d->childStates().size(), 1); // the error state
+ QCOMPARE(root_d->childStates().at(0), (QAbstractState*)machine.errorState());
+
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::addState: cannot add null state");
+ machine.addState(0);
+
+ QState *s1 = new QState();
+ QCOMPARE(s1->parentState(), (QState*)0);
+ QCOMPARE(s1->machine(), (QStateMachine*)0);
+ machine.addState(s1);
+ QCOMPARE(s1->machine(), &machine);
+ QCOMPARE(s1->parentState(), machine.rootState());
+ QCOMPARE(root_d->childStates().size(), 2);
+ QCOMPARE(root_d->childStates().at(0), (QAbstractState*)machine.errorState());
+ QCOMPARE(root_d->childStates().at(1), (QAbstractState*)s1);
+
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::addState: state has already been added to this machine");
+ machine.addState(s1);
+
+ QState *s2 = new QState();
+ QCOMPARE(s2->parentState(), (QState*)0);
+ machine.addState(s2);
+ QCOMPARE(s2->parentState(), machine.rootState());
+ QCOMPARE(root_d->childStates().size(), 3);
+ QCOMPARE(root_d->childStates().at(0), (QAbstractState*)machine.errorState());
+ QCOMPARE(root_d->childStates().at(1), (QAbstractState*)s1);
+ QCOMPARE(root_d->childStates().at(2), (QAbstractState*)s2);
+
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::addState: state has already been added to this machine");
+ machine.addState(s2);
+
+ machine.removeState(s1);
+ QCOMPARE(s1->parentState(), (QState*)0);
+ QCOMPARE(root_d->childStates().size(), 2);
+ QCOMPARE(root_d->childStates().at(0), (QAbstractState*)machine.errorState());
+ QCOMPARE(root_d->childStates().at(1), (QAbstractState*)s2);
+
+ machine.removeState(s2);
+ QCOMPARE(s2->parentState(), (QState*)0);
+ QCOMPARE(root_d->childStates().size(), 1);
+ QCOMPARE(root_d->childStates().at(0), (QAbstractState*)machine.errorState());
+
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::removeState: cannot remove null state");
+ machine.removeState(0);
+
+ {
+ QStateMachine machine2;
+ {
+ char warning[256];
+ sprintf(warning, "QStateMachine::removeState: state %p's machine (%p) is different from this machine (%p)",
+ machine2.rootState(), &machine2, &machine);
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ machine.removeState(machine2.rootState());
+ }
+ // ### check this behavior
+ machine.addState(machine2.rootState());
+ QCOMPARE(machine2.rootState()->parent(), (QObject*)machine.rootState());
+ }
+
+ delete s1;
+ delete s2;
+ // ### how to deal with this?
+ // machine.removeState(machine.errorState());
+}
+
+void tst_QStateMachine::stateEntryAndExit()
+{
+ // Two top-level states
+ {
+ QStateMachine machine;
+
+ TestState *s1 = new TestState(machine.rootState());
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: cannot add transition to null state");
+ s1->addTransition((QAbstractState*)0);
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: cannot add null transition");
+ s1->addTransition((QAbstractTransition*)0);
+ QTest::ignoreMessage(QtWarningMsg, "QState::removeTransition: cannot remove null transition");
+ s1->removeTransition((QAbstractTransition*)0);
+
+ TestState *s2 = new TestState(machine.rootState());
+ QFinalState *s3 = new QFinalState(machine.rootState());
+
+ TestTransition *t = new TestTransition(s2);
+ QCOMPARE(t->machine(), (QStateMachine*)0);
+ QCOMPARE(t->sourceState(), (QState*)0);
+ QCOMPARE(t->targetState(), s2);
+ QCOMPARE(t->targetStates().size(), 1);
+ QCOMPARE(t->targetStates().at(0), s2);
+ t->setTargetState(0);
+ QCOMPARE(t->targetState(), (QState*)0);
+ QVERIFY(t->targetStates().isEmpty());
+ t->setTargetState(s2);
+ QCOMPARE(t->targetState(), s2);
+ QTest::ignoreMessage(QtWarningMsg, "QAbstractTransition::setTargetStates: target state(s) cannot be null");
+ t->setTargetStates(QList<QAbstractState*>() << 0);
+ QCOMPARE(t->targetState(), s2);
+ t->setTargetStates(QList<QAbstractState*>() << s2);
+ QCOMPARE(t->targetState(), s2);
+ QCOMPARE(t->targetStates().size(), 1);
+ QCOMPARE(t->targetStates().at(0), s2);
+ QCOMPARE(s1->addTransition(t), (QAbstractTransition*)t);
+ QCOMPARE(t->sourceState(), s1);
+ QCOMPARE(t->machine(), &machine);
+
+ {
+ QAbstractTransition *trans = s2->addTransition(s3);
+ QVERIFY(trans != 0);
+ QCOMPARE(trans->sourceState(), (QAbstractState*)s2);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s3);
+ {
+ char warning[256];
+ sprintf(warning, "QState::removeTransition: transition %p's source state (%p) is different from this state (%p)", trans, s2, s1);
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ s1->removeTransition(trans);
+ }
+ s2->removeTransition(trans);
+ QCOMPARE(trans->sourceState(), (QAbstractState*)0);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s3);
+ QCOMPARE(s2->addTransition(trans), trans);
+ QCOMPARE(trans->sourceState(), (QAbstractState*)s2);
+ }
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy stoppedSpy(&machine, SIGNAL(stopped()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s1);
+ QCOMPARE(machine.initialState(), (QAbstractState*)s1);
+ {
+ char warning[256];
+ sprintf(warning, "QState::setInitialState: state %p is not a child of this state (%p)", machine.rootState(), machine.rootState());
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ machine.setInitialState(machine.rootState());
+ QCOMPARE(machine.initialState(), (QAbstractState*)s1);
+ }
+ QVERIFY(machine.configuration().isEmpty());
+ globalTick = 0;
+ QVERIFY(!machine.isRunning());
+ machine.start();
+
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QTRY_COMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(s3));
+
+ // s1 is entered
+ QCOMPARE(s1->events.count(), 2);
+ QCOMPARE(s1->events.at(0).first, 0);
+ QCOMPARE(s1->events.at(0).second, TestState::Entry);
+ // s1 is exited
+ QCOMPARE(s1->events.at(1).first, 1);
+ QCOMPARE(s1->events.at(1).second, TestState::Exit);
+ // t is triggered
+ QCOMPARE(t->triggers.count(), 1);
+ QCOMPARE(t->triggers.at(0), 2);
+ // s2 is entered
+ QCOMPARE(s2->events.count(), 2);
+ QCOMPARE(s2->events.at(0).first, 3);
+ QCOMPARE(s2->events.at(0).second, TestState::Entry);
+ // s2 is exited
+ QCOMPARE(s2->events.at(1).first, 4);
+ QCOMPARE(s2->events.at(1).second, TestState::Exit);
+ }
+ // Two top-level states, one has two child states
+ {
+ QStateMachine machine;
+
+ TestState *s1 = new TestState(machine.rootState());
+ TestState *s11 = new TestState(s1);
+ TestState *s12 = new TestState(s1);
+ TestState *s2 = new TestState(machine.rootState());
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s1->setInitialState(s11);
+ TestTransition *t1 = new TestTransition(s12);
+ s11->addTransition(t1);
+ TestTransition *t2 = new TestTransition(s2);
+ s12->addTransition(t2);
+ s2->addTransition(s3);
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s1);
+ globalTick = 0;
+ machine.start();
+
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(s3));
+
+ // s1 is entered
+ QCOMPARE(s1->events.count(), 2);
+ QCOMPARE(s1->events.at(0).first, 0);
+ QCOMPARE(s1->events.at(0).second, TestState::Entry);
+ // s11 is entered
+ QCOMPARE(s11->events.count(), 2);
+ QCOMPARE(s11->events.at(0).first, 1);
+ QCOMPARE(s11->events.at(0).second, TestState::Entry);
+ // s11 is exited
+ QCOMPARE(s11->events.at(1).first, 2);
+ QCOMPARE(s11->events.at(1).second, TestState::Exit);
+ // t1 is triggered
+ QCOMPARE(t1->triggers.count(), 1);
+ QCOMPARE(t1->triggers.at(0), 3);
+ // s12 is entered
+ QCOMPARE(s12->events.count(), 2);
+ QCOMPARE(s12->events.at(0).first, 4);
+ QCOMPARE(s12->events.at(0).second, TestState::Entry);
+ // s12 is exited
+ QCOMPARE(s12->events.at(1).first, 5);
+ QCOMPARE(s12->events.at(1).second, TestState::Exit);
+ // s1 is exited
+ QCOMPARE(s1->events.at(1).first, 6);
+ QCOMPARE(s1->events.at(1).second, TestState::Exit);
+ // t2 is triggered
+ QCOMPARE(t2->triggers.count(), 1);
+ QCOMPARE(t2->triggers.at(0), 7);
+ // s2 is entered
+ QCOMPARE(s2->events.count(), 2);
+ QCOMPARE(s2->events.at(0).first, 8);
+ QCOMPARE(s2->events.at(0).second, TestState::Entry);
+ // s2 is exited
+ QCOMPARE(s2->events.at(1).first, 9);
+ QCOMPARE(s2->events.at(1).second, TestState::Exit);
+ }
+}
+
+void tst_QStateMachine::assignProperty()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+
+ QTest::ignoreMessage(QtWarningMsg, "QState::assignProperty: cannot assign property 'foo' of null object");
+ s1->assignProperty(0, "foo", QVariant());
+
+ s1->assignProperty(s1, "objectName", "s1");
+ QFinalState *s2 = new QFinalState(machine.rootState());
+ s1->addTransition(s2);
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(s1->objectName(), QString::fromLatin1("s1"));
+
+ s1->assignProperty(s1, "objectName", "foo");
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(s1->objectName(), QString::fromLatin1("foo"));
+
+ s1->assignProperty(s1, "noSuchProperty", 123);
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(s1->objectName(), QString::fromLatin1("foo"));
+ QCOMPARE(s1->dynamicPropertyNames().size(), 1);
+ QCOMPARE(s1->dynamicPropertyNames().at(0), QByteArray("noSuchProperty"));
+
+ QSignalSpy polishedSpy(s1, SIGNAL(polished()));
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(polishedSpy.count(), 1);
+}
+
+void tst_QStateMachine::assignPropertyWithAnimation()
+{
+ // Single animation
+ {
+ QStateMachine machine;
+ QVERIFY(machine.animationsEnabled());
+ machine.setAnimationsEnabled(false);
+ QVERIFY(!machine.animationsEnabled());
+ machine.setAnimationsEnabled(true);
+ QVERIFY(machine.animationsEnabled());
+ QObject obj;
+ obj.setProperty("foo", 321);
+ obj.setProperty("bar", 654);
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(&obj, "foo", 123);
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(&obj, "foo", 456);
+ s2->assignProperty(&obj, "bar", 789);
+ QAbstractTransition *trans = s1->addTransition(s2);
+ QVERIFY(trans->animations().isEmpty());
+ QTest::ignoreMessage(QtWarningMsg, "QAbstractTransition::addAnimation: cannot add null animation");
+ trans->addAnimation(0);
+ QPropertyAnimation anim(&obj, "foo");
+ anim.setDuration(250);
+ trans->addAnimation(&anim);
+ QCOMPARE(trans->animations().size(), 1);
+ QCOMPARE(trans->animations().at(0), (QAbstractAnimation*)&anim);
+ QCOMPARE(anim.parent(), (QObject*)0);
+ QTest::ignoreMessage(QtWarningMsg, "QAbstractTransition::removeAnimation: cannot remove null animation");
+ trans->removeAnimation(0);
+ trans->removeAnimation(&anim);
+ QVERIFY(trans->animations().isEmpty());
+ trans->addAnimation(&anim);
+ QCOMPARE(trans->animations().size(), 1);
+ QCOMPARE(trans->animations().at(0), (QAbstractAnimation*)&anim);
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s2->addTransition(s2, SIGNAL(polished()), s3);
+
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(obj.property("foo").toInt(), 456);
+ QCOMPARE(obj.property("bar").toInt(), 789);
+ }
+ // Two animations
+ {
+ QStateMachine machine;
+ QObject obj;
+ obj.setProperty("foo", 321);
+ obj.setProperty("bar", 654);
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(&obj, "foo", 123);
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(&obj, "foo", 456);
+ s2->assignProperty(&obj, "bar", 789);
+ QAbstractTransition *trans = s1->addTransition(s2);
+ QPropertyAnimation anim(&obj, "foo");
+ anim.setDuration(150);
+ trans->addAnimation(&anim);
+ QPropertyAnimation anim2(&obj, "bar");
+ anim2.setDuration(150);
+ trans->addAnimation(&anim2);
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s2->addTransition(s2, SIGNAL(polished()), s3);
+
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(obj.property("foo").toInt(), 456);
+ QCOMPARE(obj.property("bar").toInt(), 789);
+ }
+ // Animation group
+ {
+ QStateMachine machine;
+ QObject obj;
+ obj.setProperty("foo", 321);
+ obj.setProperty("bar", 654);
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(&obj, "foo", 123);
+ s1->assignProperty(&obj, "bar", 321);
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(&obj, "foo", 456);
+ s2->assignProperty(&obj, "bar", 654);
+ s2->assignProperty(&obj, "baz", 789);
+ QAbstractTransition *trans = s1->addTransition(s2);
+ QSequentialAnimationGroup group;
+ group.addAnimation(new QPropertyAnimation(&obj, "foo"));
+ group.addAnimation(new QPropertyAnimation(&obj, "bar"));
+ trans->addAnimation(&group);
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s2->addTransition(s2, SIGNAL(polished()), s3);
+
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(obj.property("foo").toInt(), 456);
+ QCOMPARE(obj.property("bar").toInt(), 654);
+ QCOMPARE(obj.property("baz").toInt(), 789);
+ }
+ // Nested states
+ {
+ QStateMachine machine;
+ QObject obj;
+ obj.setProperty("foo", 321);
+ obj.setProperty("bar", 654);
+ QState *s1 = new QState(machine.rootState());
+ QCOMPARE(s1->childMode(), QState::ExclusiveStates);
+ s1->setChildMode(QState::ParallelStates);
+ QCOMPARE(s1->childMode(), QState::ParallelStates);
+ s1->setChildMode(QState::ExclusiveStates);
+ QCOMPARE(s1->childMode(), QState::ExclusiveStates);
+ QCOMPARE(s1->initialState(), (QAbstractState*)0);
+ s1->setObjectName("s1");
+ s1->assignProperty(&obj, "foo", 123);
+ s1->assignProperty(&obj, "bar", 456);
+ QState *s2 = new QState(machine.rootState());
+ s2->setObjectName("s2");
+ s2->assignProperty(&obj, "foo", 321);
+ QState *s21 = new QState(s2);
+ s21->setObjectName("s21");
+ s21->assignProperty(&obj, "bar", 654);
+ QState *s22 = new QState(s2);
+ s22->setObjectName("s22");
+ s22->assignProperty(&obj, "bar", 789);
+ s2->setInitialState(s21);
+ QCOMPARE(s2->initialState(), (QAbstractState*)s21);
+
+ QAbstractTransition *trans = s1->addTransition(s2);
+ QPropertyAnimation anim(&obj, "foo");
+ anim.setDuration(500);
+ trans->addAnimation(&anim);
+ QPropertyAnimation anim2(&obj, "bar");
+ anim2.setDuration(250);
+ trans->addAnimation(&anim2);
+
+ s21->addTransition(s21, SIGNAL(polished()), s22);
+
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s22->addTransition(s2, SIGNAL(polished()), s3);
+
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(obj.property("foo").toInt(), 321);
+ QCOMPARE(obj.property("bar").toInt(), 789);
+ }
+ // Aborted animation
+ {
+ QStateMachine machine;
+ SignalEmitter emitter;
+ QObject obj;
+ obj.setProperty("foo", 321);
+ obj.setProperty("bar", 654);
+ QState *group = new QState(machine.rootState());
+ QState *s1 = new QState(group);
+ group->setInitialState(s1);
+ s1->assignProperty(&obj, "foo", 123);
+ QState *s2 = new QState(group);
+ s2->assignProperty(&obj, "foo", 456);
+ s2->assignProperty(&obj, "bar", 789);
+ QAbstractTransition *trans = s1->addTransition(&emitter, SIGNAL(signalWithNoArg()), s2);
+ QPropertyAnimation anim(&obj, "foo");
+ anim.setDuration(8000);
+ trans->addAnimation(&anim);
+ QPropertyAnimation anim2(&obj, "bar");
+ anim2.setDuration(8000);
+ trans->addAnimation(&anim2);
+ QState *s3 = new QState(group);
+ s3->assignProperty(&obj, "foo", 911);
+ s2->addTransition(&emitter, SIGNAL(signalWithNoArg()), s3);
+
+ machine.setInitialState(group);
+ machine.start();
+ QTRY_COMPARE(machine.configuration().contains(s1), true);
+ QSignalSpy polishedSpy(s2, SIGNAL(polished()));
+ emitter.emitSignalWithNoArg();
+ QTRY_COMPARE(machine.configuration().contains(s2), true);
+ QVERIFY(polishedSpy.isEmpty());
+ emitter.emitSignalWithNoArg(); // will cause animations from s1-->s2 to abort
+ QTRY_COMPARE(machine.configuration().contains(s3), true);
+ QVERIFY(polishedSpy.isEmpty());
+ QCOMPARE(obj.property("foo").toInt(), 911);
+ QCOMPARE(obj.property("bar").toInt(), 789);
+ }
+}
+
+struct StringEvent : public QEvent
+{
+public:
+ StringEvent(const QString &val)
+ : QEvent(QEvent::Type(QEvent::User+2)),
+ value(val) {}
+
+ QString value;
+};
+
+class StringTransition : public QAbstractTransition
+{
+public:
+ StringTransition(const QString &value, QAbstractState *target)
+ : QAbstractTransition(QList<QAbstractState*>() << target), m_value(value) {}
+
+protected:
+ virtual bool eventTest(QEvent *e)
+ {
+ if (e->type() != QEvent::Type(QEvent::User+2))
+ return false;
+ StringEvent *se = static_cast<StringEvent*>(e);
+ return (m_value == se->value) && (!m_cond.isValid() || (m_cond.indexIn(m_value) != -1));
+ }
+ virtual void onTransition(QEvent *) {}
+
+private:
+ QString m_value;
+ QRegExp m_cond;
+};
+
+class StringEventPoster : public QState
+{
+public:
+ StringEventPoster(QStateMachine *machine, const QString &value, QState *parent = 0)
+ : QState(parent), m_machine(machine), m_value(value), m_delay(0) {}
+
+ void setString(const QString &value)
+ { m_value = value; }
+ void setDelay(int delay)
+ { m_delay = delay; }
+
+protected:
+ virtual void onEntry(QEvent *)
+ {
+ m_machine->postEvent(new StringEvent(m_value), m_delay);
+ }
+ virtual void onExit(QEvent *) {}
+
+private:
+ QStateMachine *m_machine;
+ QString m_value;
+ int m_delay;
+};
+
+void tst_QStateMachine::postEvent()
+{
+ for (int x = 0; x < 2; ++x) {
+ QStateMachine machine;
+ {
+ QEvent e(QEvent::None);
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::postEvent: cannot post event when the state machine is not running");
+ machine.postEvent(&e);
+ }
+ StringEventPoster *s1 = new StringEventPoster(&machine, "a");
+ if (x == 1)
+ s1->setDelay(100);
+ QFinalState *s2 = new QFinalState;
+ s1->addTransition(new StringTransition("a", s2));
+ machine.addState(s1);
+ machine.addState(s2);
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+
+ s1->setString("b");
+ QFinalState *s3 = new QFinalState();
+ machine.addState(s3);
+ s1->addTransition(new StringTransition("b", s3));
+ finishedSpy.clear();
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s3));
+ }
+}
+
+void tst_QStateMachine::stateFinished()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+ QState *s1_1 = new QState(s1);
+ QFinalState *s1_2 = new QFinalState(s1);
+ s1_1->addTransition(s1_2);
+ s1->setInitialState(s1_1);
+ QFinalState *s2 = new QFinalState(machine.rootState());
+ s1->addTransition(s1, SIGNAL(finished()), s2);
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+}
+
+void tst_QStateMachine::parallelStates()
+{
+ QStateMachine machine;
+
+ QState *s1 = new QState(QState::ParallelStates);
+ QCOMPARE(s1->childMode(), QState::ParallelStates);
+ QState *s1_1 = new QState(s1);
+ QState *s1_1_1 = new QState(s1_1);
+ QFinalState *s1_1_f = new QFinalState(s1_1);
+ s1_1_1->addTransition(s1_1_f);
+ s1_1->setInitialState(s1_1_1);
+ QState *s1_2 = new QState(s1);
+ QState *s1_2_1 = new QState(s1_2);
+ QFinalState *s1_2_f = new QFinalState(s1_2);
+ s1_2_1->addTransition(s1_2_f);
+ s1_2->setInitialState(s1_2_1);
+ {
+ char warning[256];
+ sprintf(warning, "QState::setInitialState: ignoring attempt to set initial state of parallel state group %p", s1);
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ s1->setInitialState(0);
+ }
+ machine.addState(s1);
+
+ QFinalState *s2 = new QFinalState();
+ machine.addState(s2);
+
+ s1->addTransition(s1, SIGNAL(finished()), s2);
+
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+}
+
+void tst_QStateMachine::allSourceToTargetConfigurations()
+{
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ s0->setObjectName("s0");
+ QState *s1 = new QState(s0);
+ s1->setObjectName("s1");
+ QState *s11 = new QState(s1);
+ s11->setObjectName("s11");
+ QState *s2 = new QState(s0);
+ s2->setObjectName("s2");
+ QState *s21 = new QState(s2);
+ s21->setObjectName("s21");
+ QState *s211 = new QState(s21);
+ s211->setObjectName("s211");
+ QFinalState *f = new QFinalState(machine.rootState());
+ f->setObjectName("f");
+
+ s0->setInitialState(s1);
+ s1->setInitialState(s11);
+ s2->setInitialState(s21);
+ s21->setInitialState(s211);
+
+ s11->addTransition(new StringTransition("g", s211));
+ s1->addTransition(new StringTransition("a", s1));
+ s1->addTransition(new StringTransition("b", s11));
+ s1->addTransition(new StringTransition("c", s2));
+ s1->addTransition(new StringTransition("d", s0));
+ s1->addTransition(new StringTransition("f", s211));
+ s211->addTransition(new StringTransition("d", s21));
+ s211->addTransition(new StringTransition("g", s0));
+ s211->addTransition(new StringTransition("h", f));
+ s21->addTransition(new StringTransition("b", s211));
+ s2->addTransition(new StringTransition("c", s1));
+ s2->addTransition(new StringTransition("f", s11));
+ s0->addTransition(new StringTransition("e", s211));
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new StringEvent("a"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("b"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("c"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("d"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("e"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("f"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("g"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("h"));
+ QCoreApplication::processEvents();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+}
+
+class TestSignalTransition : public QSignalTransition
+{
+public:
+ TestSignalTransition(QState *sourceState = 0)
+ : QSignalTransition(sourceState) {}
+ TestSignalTransition(QObject *sender, const char *signal,
+ QAbstractState *target)
+ : QSignalTransition(sender, signal, QList<QAbstractState*>() << target) {}
+ QVariantList argumentsReceived() const {
+ return m_args;
+ }
+protected:
+ bool eventTest(QEvent *e) {
+ if (!QSignalTransition::eventTest(e))
+ return false;
+ QSignalEvent *se = static_cast<QSignalEvent*>(e);
+ const_cast<TestSignalTransition*>(this)->m_args = se->arguments();
+ return true;
+ }
+private:
+ QVariantList m_args;
+};
+
+void tst_QStateMachine::signalTransitions()
+{
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: sender cannot be null");
+ QCOMPARE(s0->addTransition(0, SIGNAL(noSuchSignal()), 0), (QObject*)0);
+
+ SignalEmitter emitter;
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: signal cannot be null");
+ QCOMPARE(s0->addTransition(&emitter, 0, 0), (QObject*)0);
+
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: cannot add transition to null state");
+ QCOMPARE(s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), 0), (QObject*)0);
+
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: no such signal SignalEmitter::noSuchSignal()");
+ QCOMPARE(s0->addTransition(&emitter, SIGNAL(noSuchSignal()), s1), (QObject*)0);
+
+ QSignalTransition *trans = s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
+ QVERIFY(trans != 0);
+ QCOMPARE(trans->sourceState(), s0);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s1);
+ QCOMPARE(trans->senderObject(), (QObject*)&emitter);
+ QCOMPARE(trans->signal(), QByteArray(SIGNAL(signalWithNoArg())));
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ emitter.emitSignalWithNoArg();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+
+ emitter.emitSignalWithNoArg();
+
+ trans->setSignal(SIGNAL(signalWithIntArg(int)));
+ QCOMPARE(trans->signal(), QByteArray(SIGNAL(signalWithIntArg(int))));
+ machine.start();
+ QCoreApplication::processEvents();
+ emitter.emitSignalWithIntArg(123);
+ QTRY_COMPARE(finishedSpy.count(), 2);
+
+ machine.start();
+ QCoreApplication::processEvents();
+ trans->setSignal(SIGNAL(signalWithNoArg()));
+ QCOMPARE(trans->signal(), QByteArray(SIGNAL(signalWithNoArg())));
+ emitter.emitSignalWithNoArg();
+ QTRY_COMPARE(finishedSpy.count(), 3);
+
+ SignalEmitter emitter2;
+ machine.start();
+ QCoreApplication::processEvents();
+ trans->setSenderObject(&emitter2);
+ emitter2.emitSignalWithNoArg();
+ QTRY_COMPARE(finishedSpy.count(), 4);
+
+ machine.start();
+ QCoreApplication::processEvents();
+ QTest::ignoreMessage(QtWarningMsg, "QSignalTransition: no such signal: SignalEmitter::noSuchSignal()");
+ trans->setSignal(SIGNAL(noSuchSignal()));
+ QCOMPARE(trans->signal(), QByteArray(SIGNAL(noSuchSignal())));
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ SignalEmitter emitter;
+ TestSignalTransition *trans = new TestSignalTransition(&emitter, SIGNAL(signalWithIntArg(int)), s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ emitter.emitSignalWithIntArg(123);
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(trans->argumentsReceived().size(), 1);
+ QCOMPARE(trans->argumentsReceived().at(0).toInt(), 123);
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ SignalEmitter emitter;
+ TestSignalTransition *trans = new TestSignalTransition(&emitter, SIGNAL(signalWithStringArg(QString)), s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QString testString = QString::fromLatin1("hello");
+ emitter.emitSignalWithStringArg(testString);
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(trans->argumentsReceived().size(), 1);
+ QCOMPARE(trans->argumentsReceived().at(0).toString(), testString);
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ TestSignalTransition *trans = new TestSignalTransition();
+ QCOMPARE(trans->senderObject(), (QObject*)0);
+ QCOMPARE(trans->signal(), QByteArray());
+
+ SignalEmitter emitter;
+ trans->setSenderObject(&emitter);
+ QCOMPARE(trans->senderObject(), (QObject*)&emitter);
+ trans->setSignal(SIGNAL(signalWithNoArg()));
+ QCOMPARE(trans->signal(), QByteArray(SIGNAL(signalWithNoArg())));
+ trans->setTargetState(s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ emitter.emitSignalWithNoArg();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+ // Multiple transitions for same (object,signal)
+ {
+ QStateMachine machine;
+ SignalEmitter emitter;
+ QState *s0 = new QState(machine.rootState());
+ QState *s1 = new QState(machine.rootState());
+ QSignalTransition *t0 = s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
+ QSignalTransition *t1 = s1->addTransition(&emitter, SIGNAL(signalWithNoArg()), s0);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ emitter.emitSignalWithNoArg();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ s0->removeTransition(t0);
+ emitter.emitSignalWithNoArg();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ emitter.emitSignalWithNoArg();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ s1->removeTransition(t1);
+ emitter.emitSignalWithNoArg();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ s0->addTransition(t0);
+ s1->addTransition(t1);
+ emitter.emitSignalWithNoArg();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+ }
+ // multiple signal transitions from same source
+ {
+ QStateMachine machine;
+ SignalEmitter emitter;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
+ QFinalState *s2 = new QFinalState(machine.rootState());
+ s0->addTransition(&emitter, SIGNAL(signalWithIntArg(int)), s2);
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s0->addTransition(&emitter, SIGNAL(signalWithStringArg(QString)), s3);
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 1);
+ emitter.emitSignalWithNoArg();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 2);
+ emitter.emitSignalWithIntArg(123);
+ QTRY_COMPARE(finishedSpy.count(), 2);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 3);
+ emitter.emitSignalWithStringArg("hello");
+ QTRY_COMPARE(finishedSpy.count(), 3);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s3));
+ }
+}
+
+void tst_QStateMachine::eventTransitions()
+{
+ QPushButton button;
+ for (int x = 0; x < 2; ++x) {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QMouseEventTransition *trans;
+ if (x == 0) {
+ trans = new QMouseEventTransition(&button, QEvent::MouseButtonPress, Qt::LeftButton);
+ QCOMPARE(trans->targetState(), (QAbstractState*)0);
+ trans->setTargetState(s1);
+ } else {
+ trans = new QMouseEventTransition(&button, QEvent::MouseButtonPress,
+ Qt::LeftButton, QList<QAbstractState*>() << s1);
+ }
+ QCOMPARE(trans->eventType(), QEvent::MouseButtonPress);
+ QCOMPARE(trans->button(), Qt::LeftButton);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 1);
+
+ QTest::mousePress(&button, Qt::LeftButton);
+
+ trans->setEventType(QEvent::MouseButtonRelease);
+ QCOMPARE(trans->eventType(), QEvent::MouseButtonRelease);
+ machine.start();
+ QCoreApplication::processEvents();
+ QTest::mouseRelease(&button, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 2);
+
+ machine.start();
+ QCoreApplication::processEvents();
+ trans->setEventType(QEvent::MouseButtonPress);
+ QTest::mousePress(&button, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 3);
+
+ QPushButton button2;
+ machine.start();
+ QCoreApplication::processEvents();
+ trans->setEventObject(&button2);
+ QTest::mousePress(&button2, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 4);
+ }
+ for (int x = 0; x < 3; ++x) {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QEventTransition *trans;
+ if (x == 0) {
+ trans = new QEventTransition();
+ QCOMPARE(trans->eventObject(), (QObject*)0);
+ QCOMPARE(trans->eventType(), QEvent::None);
+ trans->setEventObject(&button);
+ trans->setEventType(QEvent::MouseButtonPress);
+ trans->setTargetState(s1);
+ } else if (x == 1) {
+ trans = new QEventTransition(&button, QEvent::MouseButtonPress);
+ trans->setTargetState(s1);
+ } else {
+ trans = new QEventTransition(&button, QEvent::MouseButtonPress,
+ QList<QAbstractState*>() << s1);
+ }
+ QCOMPARE(trans->eventObject(), (QObject*)&button);
+ QCOMPARE(trans->eventType(), QEvent::MouseButtonPress);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QMouseEventTransition *trans = new QMouseEventTransition();
+ QCOMPARE(trans->eventObject(), (QObject*)0);
+ QCOMPARE(trans->eventType(), QEvent::None);
+ QCOMPARE(trans->button(), Qt::NoButton);
+ trans->setEventObject(&button);
+ trans->setEventType(QEvent::MouseButtonPress);
+ trans->setButton(Qt::LeftButton);
+ trans->setTargetState(s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QKeyEventTransition *trans = new QKeyEventTransition(&button, QEvent::KeyPress, Qt::Key_A);
+ QCOMPARE(trans->eventType(), QEvent::KeyPress);
+ QCOMPARE(trans->key(), (int)Qt::Key_A);
+ trans->setTargetState(s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QTest::keyPress(&button, Qt::Key_A);
+ QCoreApplication::processEvents();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QKeyEventTransition *trans = new QKeyEventTransition();
+ QCOMPARE(trans->eventObject(), (QObject*)0);
+ QCOMPARE(trans->eventType(), QEvent::None);
+ QCOMPARE(trans->key(), 0);
+ trans->setEventObject(&button);
+ trans->setEventType(QEvent::KeyPress);
+ trans->setKey(Qt::Key_A);
+ trans->setTargetState(s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QTest::keyPress(&button, Qt::Key_A);
+ QCoreApplication::processEvents();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+ // Multiple transitions for same (object,event)
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QState *s1 = new QState(machine.rootState());
+ QEventTransition *t0 = new QEventTransition(&button, QEvent::MouseButtonPress);
+ t0->setTargetState(s1);
+ s0->addTransition(t0);
+ QEventTransition *t1 = new QEventTransition(&button, QEvent::MouseButtonPress);
+ t1->setTargetState(s0);
+ s1->addTransition(t1);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ s0->removeTransition(t0);
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ s1->removeTransition(t1);
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ s0->addTransition(t0);
+ s1->addTransition(t1);
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+ }
+ // multiple event transitions from same source
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ QFinalState *s2 = new QFinalState(machine.rootState());
+ QEventTransition *t0 = new QEventTransition(&button, QEvent::MouseButtonPress);
+ t0->setTargetState(s1);
+ s0->addTransition(t0);
+ QEventTransition *t1 = new QEventTransition(&button, QEvent::MouseButtonRelease);
+ t1->setTargetState(s2);
+ s0->addTransition(t1);
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QTest::mousePress(&button, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 2);
+ QTest::mouseRelease(&button, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 2);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+ }
+ // custom event
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QEventTransition *trans = new QEventTransition(&button, QEvent::Type(QEvent::User+1));
+ trans->setTargetState(s1);
+ s0->addTransition(trans);
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ machine.setInitialState(s0);
+ machine.start();
+ QTest::ignoreMessage(QtWarningMsg, "QObject event transitions are not supported for custom types");
+ QTRY_COMPARE(startedSpy.count(), 1);
+ }
+}
+
+void tst_QStateMachine::historyStates()
+{
+ for (int x = 0; x < 2; ++x) {
+ QStateMachine machine;
+ QState *root = machine.rootState();
+ QState *s0 = new QState(root);
+ QState *s00 = new QState(s0);
+ QState *s01 = new QState(s0);
+ QHistoryState *s0h;
+ if (x == 0) {
+ s0h = new QHistoryState(s0);
+ QCOMPARE(s0h->historyType(), QHistoryState::ShallowHistory);
+ s0h->setHistoryType(QHistoryState::DeepHistory);
+ } else {
+ s0h = new QHistoryState(QHistoryState::DeepHistory, s0);
+ }
+ QCOMPARE(s0h->historyType(), QHistoryState::DeepHistory);
+ s0h->setHistoryType(QHistoryState::ShallowHistory);
+ QCOMPARE(s0h->historyType(), QHistoryState::ShallowHistory);
+ QCOMPARE(s0h->defaultState(), (QAbstractState*)0);
+ s0h->setDefaultState(s00);
+ QCOMPARE(s0h->defaultState(), (QAbstractState*)s00);
+ char warning[256];
+ sprintf(warning, "QHistoryState::setDefaultState: state %p does not belong to this history state's group (%p)", s0, s0);
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ s0h->setDefaultState(s0);
+ QState *s1 = new QState(root);
+ QFinalState *s2 = new QFinalState(root);
+
+ s00->addTransition(new StringTransition("a", s01));
+ s0->addTransition(new StringTransition("b", s1));
+ s1->addTransition(new StringTransition("c", s0h));
+ s0->addTransition(new StringTransition("d", s2));
+
+ root->setInitialState(s0);
+ s0->setInitialState(s00);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s0));
+ QVERIFY(machine.configuration().contains(s00));
+
+ machine.postEvent(new StringEvent("a"));
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s0));
+ QVERIFY(machine.configuration().contains(s01));
+
+ machine.postEvent(new StringEvent("b"));
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.postEvent(new StringEvent("c"));
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s0));
+ QVERIFY(machine.configuration().contains(s01));
+
+ machine.postEvent(new StringEvent("d"));
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+}
+
+void tst_QStateMachine::startAndStop()
+{
+ QStateMachine machine;
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy stoppedSpy(&machine, SIGNAL(stopped()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ QVERIFY(!machine.isRunning());
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::start: No initial state set for machine. Refusing to start.");
+ machine.start();
+ QCOMPARE(startedSpy.count(), 0);
+ QCOMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+ QVERIFY(!machine.isRunning());
+ machine.stop();
+ QCOMPARE(startedSpy.count(), 0);
+ QCOMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+ machine.start();
+ QTRY_COMPARE(machine.isRunning(), true);
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QCOMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::start(): already running");
+ machine.start();
+
+ machine.stop();
+ QTRY_COMPARE(machine.isRunning(), false);
+ QTRY_COMPARE(stoppedSpy.count(), 1);
+ QCOMPARE(startedSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.start();
+ machine.stop();
+ QTRY_COMPARE(startedSpy.count(), 2);
+ QCOMPARE(stoppedSpy.count(), 2);
+}
+
+void tst_QStateMachine::targetStateWithNoParent()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+ s1->setObjectName("s1");
+ QState s2;
+ s1->addTransition(&s2);
+ machine.setInitialState(s1);
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy stoppedSpy(&machine, SIGNAL(stopped()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: No common ancestor for targets and source of transition from state 's1'");
+ QTRY_COMPARE(machine.isRunning(), true);
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QCOMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+ QCOMPARE(machine.error(), QStateMachine::NoCommonAncestorForTransitionError);
+}
+
+void tst_QStateMachine::targetStateDeleted()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+ s1->setObjectName("s1");
+ QState *s2 = new QState(machine.rootState());
+ QAbstractTransition *trans = s1->addTransition(s2);
+ delete s2;
+ QCOMPARE(trans->targetState(), (QAbstractState*)0);
+ QVERIFY(trans->targetStates().isEmpty());
+}
+
+void tst_QStateMachine::defaultGlobalRestorePolicy()
+{
+ QStateMachine machine;
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("a", 1);
+ propertyHolder->setProperty("b", 2);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(propertyHolder, "a", 3);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "b", 4);
+
+ QState *s3 = new QState(machine.rootState());
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+}
+
+/*
+void tst_QStateMachine::restorePolicyNotInherited()
+{
+ QStateMachine machine;
+
+ QObject *propertyHolder = new QObject();
+ propertyHolder->setProperty("a", 1);
+ propertyHolder->setProperty("b", 2);
+
+ QState *parentState = new QState(machine.rootState());
+ parentState->setObjectName("parentState");
+ parentState->setRestorePolicy(QState::RestoreProperties);
+
+ QState *s1 = new QState(parentState);
+ s1->setObjectName("s1");
+ s1->assignProperty(propertyHolder, "a", 3);
+ parentState->setInitialState(s1);
+
+ QState *s2 = new QState(parentState);
+ s2->setObjectName("s2");
+ s2->assignProperty(propertyHolder, "b", 4);
+
+ QState *s3 = new QState(parentState);
+ s3->setObjectName("s3");
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(parentState);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+}*/
+
+void tst_QStateMachine::globalRestorePolicySetToDoNotRestore()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::DoNotRestoreProperties);
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("a", 1);
+ propertyHolder->setProperty("b", 2);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(propertyHolder, "a", 3);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "b", 4);
+
+ QState *s3 = new QState(machine.rootState());
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+}
+
+/*
+void tst_QStateMachine::setRestorePolicyToDoNotRestore()
+{
+ QObject *object = new QObject();
+ object->setProperty("a", 1);
+ object->setProperty("b", 2);
+
+ QStateMachine machine;
+
+ QState *S1 = new QState();
+ S1->setObjectName("S1");
+ S1->assignProperty(object, "a", 3);
+ S1->setRestorePolicy(QState::DoNotRestoreProperties);
+ machine.addState(S1);
+
+ QState *S2 = new QState();
+ S2->setObjectName("S2");
+ S2->assignProperty(object, "b", 5);
+ S2->setRestorePolicy(QState::DoNotRestoreProperties);
+ machine.addState(S2);
+
+ QState *S3 = new QState();
+ S3->setObjectName("S3");
+ S3->setRestorePolicy(QState::DoNotRestoreProperties);
+ machine.addState(S3);
+
+ QFinalState *S4 = new QFinalState();
+ machine.addState(S4);
+
+ S1->addTransition(new EventTransition(QEvent::User, S2));
+ S2->addTransition(new EventTransition(QEvent::User, S3));
+ S3->addTransition(S4);
+
+ machine.setInitialState(S1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 3);
+ QCOMPARE(object->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 3);
+ QCOMPARE(object->property("b").toInt(), 5);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 3);
+ QCOMPARE(object->property("b").toInt(), 5);
+}
+
+void tst_QStateMachine::setGlobalRestorePolicyToGlobalRestore()
+{
+ s_countWarnings = false;
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::GlobalRestorePolicy);
+
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::DoNotRestoreProperties);
+ QCOMPARE(s_msgType, QtWarningMsg);
+
+ s_msgType = QtDebugMsg;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::GlobalRestorePolicy);
+
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::RestoreProperties);
+ QCOMPARE(s_msgType, QtWarningMsg);
+}
+
+
+void tst_QStateMachine::restorePolicyOnChildState()
+{
+ QStateMachine machine;
+
+ QObject *propertyHolder = new QObject();
+ propertyHolder->setProperty("a", 1);
+ propertyHolder->setProperty("b", 2);
+
+ QState *parentState = new QState(machine.rootState());
+ parentState->setObjectName("parentState");
+
+ QState *s1 = new QState(parentState);
+ s1->setRestorePolicy(QState::RestoreProperties);
+ s1->setObjectName("s1");
+ s1->assignProperty(propertyHolder, "a", 3);
+ parentState->setInitialState(s1);
+
+ QState *s2 = new QState(parentState);
+ s2->setRestorePolicy(QState::RestoreProperties);
+ s2->setObjectName("s2");
+ s2->assignProperty(propertyHolder, "b", 4);
+
+ QState *s3 = new QState(parentState);
+ s3->setRestorePolicy(QState::RestoreProperties);
+ s3->setObjectName("s3");
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(parentState);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 1);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 1);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+}
+*/
+
+void tst_QStateMachine::globalRestorePolicySetToRestore()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("a", 1);
+ propertyHolder->setProperty("b", 2);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(propertyHolder, "a", 3);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "b", 4);
+
+ QState *s3 = new QState(machine.rootState());
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 1);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 1);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+}
+
+/*
+void tst_QStateMachine::mixedRestoreProperties()
+{
+ QStateMachine machine;
+
+ QObject *propertyHolder = new QObject();
+ propertyHolder->setProperty("a", 1);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->setRestorePolicy(QState::RestoreProperties);
+ s1->assignProperty(propertyHolder, "a", 3);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "a", 4);
+
+ QState *s3 = new QState(machine.rootState());
+
+ QState *s4 = new QState(machine.rootState());
+ s4->assignProperty(propertyHolder, "a", 5);
+
+ QState *s5 = new QState(machine.rootState());
+ s5->setRestorePolicy(QState::RestoreProperties);
+ s5->assignProperty(propertyHolder, "a", 6);
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+ s3->addTransition(new EventTransition(QEvent::User, s4));
+ s4->addTransition(new EventTransition(QEvent::User, s5));
+ s5->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ // Enter s1, save current
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ // Enter s2, restorePolicy == DoNotRestore, so restore all properties
+ QCOMPARE(propertyHolder->property("a").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ // Enter s3
+ QCOMPARE(propertyHolder->property("a").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ // Enter s4
+ QCOMPARE(propertyHolder->property("a").toInt(), 5);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ // Enter s5, save current
+ QCOMPARE(propertyHolder->property("a").toInt(), 6);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ // Enter s3, restore
+ QCOMPARE(propertyHolder->property("a").toInt(), 5);
+}
+*/
+
+void tst_QStateMachine::transitionWithParent()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ EventTransition *trans = new EventTransition(QEvent::User, s2, s1);
+ QCOMPARE(trans->sourceState(), s1);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s2);
+ QCOMPARE(trans->targetStates().size(), 1);
+ QCOMPARE(trans->targetStates().at(0), (QAbstractState*)s2);
+}
+
+void tst_QStateMachine::simpleAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("fooBar", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "fooBar", 2.0);
+
+ EventTransition *et = new EventTransition(QEvent::User, s2);
+ QPropertyAnimation *animation = new QPropertyAnimation(object, "fooBar", s2);
+ et->addAnimation(animation);
+ s1->addTransition(et);
+
+ QState *s3 = new QState(machine.rootState());
+ s2->addTransition(animation, SIGNAL(finished()), s3);
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("fooBar").toDouble(), 2.0);
+}
+
+class SlotCalledCounter: public QObject
+{
+ Q_OBJECT
+public:
+ SlotCalledCounter() : counter(0) {}
+
+ int counter;
+
+public slots:
+ void slot() { counter++; }
+};
+
+void tst_QStateMachine::twoAnimations()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 3.0);
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+ s2->assignProperty(object, "bar", 10.0);
+
+ QPropertyAnimation *animationFoo = new QPropertyAnimation(object, "foo", s2);
+ QPropertyAnimation *animationBar = new QPropertyAnimation(object, "bar", s2);
+ animationBar->setDuration(900);
+
+ SlotCalledCounter counter;
+ connect(animationFoo, SIGNAL(finished()), &counter, SLOT(slot()));
+ connect(animationBar, SIGNAL(finished()), &counter, SLOT(slot()));
+
+ EventTransition *et = new EventTransition(QEvent::User, s2);
+ et->addAnimation(animationFoo);
+ et->addAnimation(animationBar);
+ s1->addTransition(et);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(s2, SIGNAL(polished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(object->property("bar").toDouble(), 10.0);
+
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::twoAnimatedTransitions()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 5.0);
+ QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
+
+ QState *s4 = new QState(machine.rootState());
+ s4->assignProperty(object, "foo", 2.0);
+ QPropertyAnimation *fooAnimation2 = new QPropertyAnimation(object, "foo", s4);
+ s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation2);
+
+ QState *s5 = new QState(machine.rootState());
+ QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit()));
+ s4->addTransition(fooAnimation2, SIGNAL(finished()), s5);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 5.0);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s5));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::playAnimationTwice()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 5.0);
+ QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
+
+ QState *s4 = new QState(machine.rootState());
+ s4->assignProperty(object, "foo", 2.0);
+ s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation);
+
+ QState *s5 = new QState(machine.rootState());
+ QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit()));
+ s4->addTransition(fooAnimation, SIGNAL(finished()), s5);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 5.0);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s5));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::nestedTargetStateForAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 3.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s2Child = new QState(s2);
+ s2Child->assignProperty(object, "bar", 10.0);
+ s2->setInitialState(s2Child);
+
+ QState *s2Child2 = new QState(s2);
+ s2Child2->assignProperty(object, "bar", 11.0);
+ QAbstractTransition *at = s2Child->addTransition(new EventTransition(QEvent::User, s2Child2));
+
+ QPropertyAnimation *animation = new QPropertyAnimation(object, "bar", s2);
+ animation->setDuration(2000);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ animation = new QPropertyAnimation(object, "foo", s2);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ animation = new QPropertyAnimation(object, "bar", s2);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ QState *s3 = new QState(machine.rootState());
+ s2->addTransition(s2Child, SIGNAL(polished()), s3);
+
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+ machine.postEvent(new QEvent(QEvent::User));
+
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(object->property("bar").toDouble(), 10.0);
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::animatedGlobalRestoreProperty()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+
+ QState *s4 = new QState(machine.rootState());
+ QObject::connect(s4, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", s2);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ at = s2->addTransition(pa, SIGNAL(finished()), s3);
+ pa = new QPropertyAnimation(object, "foo", s3);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ at = s3->addTransition(pa, SIGNAL(finished()), s4);
+ pa = new QPropertyAnimation(object, "foo", s4);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s4));
+ QCOMPARE(object->property("foo").toDouble(), 1.0);
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::specificTargetValueOfAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(object, "foo");
+ anim->setEndValue(10.0);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(anim);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(anim, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(anim->endValue().toDouble(), 10.0);
+}
+
+void tst_QStateMachine::addDefaultAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimation(pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::addDefaultAnimationWithUnusedAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 2.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ machine.addDefaultAnimation(pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ pa = new QPropertyAnimation(object, "bar", &machine);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ machine.addDefaultAnimation(pa);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(counter.counter, 1);
+}
+
+void tst_QStateMachine::removeDefaultAnimation()
+{
+ QStateMachine machine;
+
+ QObject propertyHolder;
+ propertyHolder.setProperty("foo", 0);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(&propertyHolder, "foo");
+
+ machine.addDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 1);
+ QVERIFY(machine.defaultAnimations().contains(anim));
+
+ machine.removeDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+
+ machine.addDefaultAnimation(anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(&propertyHolder, "foo");
+ machine.addDefaultAnimation(anim2);
+
+ QCOMPARE(machine.defaultAnimations().size(), 2);
+ QVERIFY(machine.defaultAnimations().contains(anim));
+ QVERIFY(machine.defaultAnimations().contains(anim2));
+
+ machine.removeDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 1);
+ QVERIFY(machine.defaultAnimations().contains(anim2));
+
+ machine.removeDefaultAnimation(anim2);
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+}
+
+void tst_QStateMachine::overrideDefaultAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+/*
+void tst_QStateMachine::addDefaultAnimationForSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimationForSourceState(s1, pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::addDefaultAnimationForTarget()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimationForTargetState(s2, pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::removeDefaultAnimationForSource()
+{
+ QStateMachine machine;
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
+
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim2);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 2);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim2);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+}
+
+void tst_QStateMachine::removeDefaultAnimationForTarget()
+{
+ QStateMachine machine;
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
+
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim2);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 2);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim2);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+}
+
+void tst_QStateMachine::overrideDefaultAnimationWithSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ machine.addDefaultAnimationForSourceState(s1, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultAnimationWithTarget()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ machine.addDefaultAnimationForTargetState(s2, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+
+}
+
+void tst_QStateMachine::overrideDefaultSourceAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForSourceState(s1, defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultTargetAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForTargetState(s2, defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultTargetAnimationWithSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForTargetState(s2, defaultAnimation);
+ machine.addDefaultAnimationForSourceState(s1, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+*/
+
+void tst_QStateMachine::parallelStateAssignmentsDone()
+{
+ QStateMachine machine;
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("foo", 123);
+ propertyHolder->setProperty("bar", 456);
+ propertyHolder->setProperty("zoot", 789);
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *parallelState = new QState(QState::ParallelStates, machine.rootState());
+ parallelState->assignProperty(propertyHolder, "foo", 321);
+
+ QState *s2 = new QState(parallelState);
+ s2->assignProperty(propertyHolder, "bar", 654);
+
+ QState *s3 = new QState(parallelState);
+ s3->assignProperty(propertyHolder, "zoot", 987);
+
+ s1->addTransition(new EventTransition(QEvent::User, parallelState));
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("foo").toInt(), 123);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 456);
+ QCOMPARE(propertyHolder->property("zoot").toInt(), 789);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("foo").toInt(), 321);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 654);
+ QCOMPARE(propertyHolder->property("zoot").toInt(), 987);
+}
+
+void tst_QStateMachine::transitionsFromParallelStateWithNoChildren()
+{
+ QStateMachine machine;
+
+ QState *parallelState = new QState(QState::ParallelStates, machine.rootState());
+ machine.setInitialState(parallelState);
+
+ QState *s1 = new QState(machine.rootState());
+ parallelState->addTransition(new EventTransition(QEvent::User, s1));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(1, machine.configuration().size());
+ QVERIFY(machine.configuration().contains(parallelState));
+
+ machine.postEvent(new QEvent(QEvent::User));
+
+ QCoreApplication::processEvents();
+
+ QCOMPARE(1, machine.configuration().size());
+ QVERIFY(machine.configuration().contains(s1));
+}
+
+void tst_QStateMachine::parallelStateTransition()
+{
+ QStateMachine machine;
+
+ QState *parallelState = new QState(QState::ParallelStates, machine.rootState());
+ machine.setInitialState(parallelState);
+
+ QState *s1 = new QState(parallelState);
+ QState *s2 = new QState(parallelState);
+
+ QState *s1InitialChild = new QState(s1);
+ s1->setInitialState(s1InitialChild);
+
+ QState *s2InitialChild = new QState(s2);
+ s2->setInitialState(s2InitialChild);
+
+ QState *s1OtherChild = new QState(s1);
+
+ s1->addTransition(new EventTransition(QEvent::User, s1OtherChild));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QVERIFY(machine.configuration().contains(parallelState));
+ QVERIFY(machine.configuration().contains(s1));
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s1InitialChild));
+ QVERIFY(machine.configuration().contains(s2InitialChild));
+ QCOMPARE(machine.configuration().size(), 5);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QVERIFY(machine.configuration().contains(parallelState));
+
+ QVERIFY(machine.configuration().contains(s1));
+
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s1OtherChild));
+ QVERIFY(machine.configuration().contains(s2InitialChild));
+ QCOMPARE(machine.configuration().size(), 5);
+
+}
+
+void tst_QStateMachine::nestedRestoreProperties()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("foo", 1);
+ propertyHolder->setProperty("bar", 2);
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "foo", 3);
+
+ QState *s21 = new QState(s2);
+ s21->assignProperty(propertyHolder, "bar", 4);
+ s2->setInitialState(s21);
+
+ QState *s22 = new QState(s2);
+ s22->assignProperty(propertyHolder, "bar", 5);
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s21->addTransition(new EventTransition(QEvent::User, s22));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 1);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s21));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 3);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s22));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 3);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 5);
+}
+
+void tst_QStateMachine::nestedRestoreProperties2()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("foo", 1);
+ propertyHolder->setProperty("bar", 2);
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "foo", 3);
+
+ QState *s21 = new QState(s2);
+ s21->assignProperty(propertyHolder, "bar", 4);
+ s2->setInitialState(s21);
+
+ QState *s22 = new QState(s2);
+ s22->assignProperty(propertyHolder, "foo", 6);
+ s22->assignProperty(propertyHolder, "bar", 5);
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s21->addTransition(new EventTransition(QEvent::User, s22));
+ s22->addTransition(new EventTransition(QEvent::User, s21));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 1);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s21));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 3);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s22));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 6);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 5);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s21));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 3);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 4);
+
+}
+
+
+QTEST_MAIN(tst_QStateMachine)
+#include "tst_qstatemachine.moc"
diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
index 2daa0f6..26f5f40 100644
--- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -77,6 +77,7 @@ private slots:
void fileTemplate_data();
void getSetCheck();
void fileName();
+ void fileNameIsEmpty();
void autoRemove();
void write();
void openCloseOpenClose();
@@ -86,6 +87,8 @@ private slots:
void stressTest();
void rename();
void renameFdLeak();
+ void reOpenThroughQFile();
+
public:
};
@@ -189,6 +192,27 @@ void tst_QTemporaryFile::fileName()
QCOMPARE(absoluteFilePath, absoluteTempPath);
}
+void tst_QTemporaryFile::fileNameIsEmpty()
+{
+ QString filename;
+ {
+ QTemporaryFile file;
+ QVERIFY(file.fileName().isEmpty());
+
+ QVERIFY(file.open());
+ QVERIFY(!file.fileName().isEmpty());
+
+ filename = file.fileName();
+ QVERIFY(QFile::exists(filename));
+
+ file.close();
+ QVERIFY(!file.isOpen());
+ QVERIFY(QFile::exists(filename));
+ QVERIFY(!file.fileName().isEmpty());
+ }
+ QVERIFY(!QFile::exists(filename));
+}
+
void tst_QTemporaryFile::autoRemove()
{
// Test auto remove
@@ -358,6 +382,7 @@ void tst_QTemporaryFile::rename()
QVERIFY(file.rename("temporary-file.txt"));
QVERIFY(!dir.exists(tempname));
QVERIFY(dir.exists("temporary-file.txt"));
+ QCOMPARE(file.fileName(), QString("temporary-file.txt"));
}
QVERIFY(!dir.exists(tempname));
@@ -401,5 +426,18 @@ void tst_QTemporaryFile::renameFdLeak()
#endif
}
+void tst_QTemporaryFile::reOpenThroughQFile()
+{
+ QByteArray data("abcdefghij");
+
+ QTemporaryFile file;
+ QVERIFY(((QFile &)file).open(QIODevice::WriteOnly));
+ QCOMPARE(file.write(data), (qint64)data.size());
+
+ file.close();
+ QVERIFY(file.open());
+ QCOMPARE(file.readAll(), data);
+}
+
QTEST_MAIN(tst_QTemporaryFile)
#include "tst_qtemporaryfile.moc"
diff --git a/tests/benchmarks/benchmarks.pro b/tests/benchmarks/benchmarks.pro
index 8e2c243..4c39373 100644
--- a/tests/benchmarks/benchmarks.pro
+++ b/tests/benchmarks/benchmarks.pro
@@ -1,6 +1,7 @@
TEMPLATE = subdirs
SUBDIRS = containers-associative \
containers-sequential \
+ qanimation \
qbytearray \
qpainter \
qtestlib-simple events \
diff --git a/tests/benchmarks/qanimation/dummyanimation.cpp b/tests/benchmarks/qanimation/dummyanimation.cpp
new file mode 100644
index 0000000..6fb1d0a
--- /dev/null
+++ b/tests/benchmarks/qanimation/dummyanimation.cpp
@@ -0,0 +1,20 @@
+#include "dummyanimation.h"
+#include "dummyobject.h"
+
+
+DummyAnimation::DummyAnimation(DummyObject *d) : m_dummy(d)
+{
+}
+
+void DummyAnimation::updateCurrentValue(const QVariant &value)
+{
+ if (state() == Stopped)
+ return;
+ if (m_dummy)
+ m_dummy->setRect(value.toRect());
+}
+
+void DummyAnimation::updateState(State state)
+{
+ Q_UNUSED(state);
+}
diff --git a/tests/benchmarks/qanimation/dummyanimation.h b/tests/benchmarks/qanimation/dummyanimation.h
new file mode 100644
index 0000000..fe6592b
--- /dev/null
+++ b/tests/benchmarks/qanimation/dummyanimation.h
@@ -0,0 +1,19 @@
+#include <QtGui>
+
+#ifndef _DUMMYANIMATION_H__
+
+class DummyObject;
+
+class DummyAnimation : public QVariantAnimation
+{
+public:
+ DummyAnimation(DummyObject *d);
+
+ void updateCurrentValue(const QVariant &value);
+ void updateState(State state);
+
+private:
+ DummyObject *m_dummy;
+};
+
+#endif \ No newline at end of file
diff --git a/tests/benchmarks/qanimation/dummyobject.cpp b/tests/benchmarks/qanimation/dummyobject.cpp
new file mode 100644
index 0000000..bd76388
--- /dev/null
+++ b/tests/benchmarks/qanimation/dummyobject.cpp
@@ -0,0 +1,25 @@
+#include "dummyobject.h"
+
+DummyObject::DummyObject()
+{
+}
+
+QRect DummyObject::rect() const
+{
+ return m_rect;
+}
+
+void DummyObject::setRect(const QRect &r)
+{
+ m_rect = r;
+}
+
+float DummyObject::opacity() const
+{
+ return m_opacity;
+}
+
+void DummyObject::setOpacity(float o)
+{
+ m_opacity = o;
+}
diff --git a/tests/benchmarks/qanimation/dummyobject.h b/tests/benchmarks/qanimation/dummyobject.h
new file mode 100644
index 0000000..c989662
--- /dev/null
+++ b/tests/benchmarks/qanimation/dummyobject.h
@@ -0,0 +1,23 @@
+#include <QtGui>
+
+#ifndef _DUMMYOBJECT_H__
+
+class DummyObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QRect rect READ rect WRITE setRect)
+ Q_PROPERTY(float opacity READ opacity WRITE setOpacity)
+public:
+ DummyObject();
+ QRect rect() const;
+ void setRect(const QRect &r);
+ float opacity() const;
+ void setOpacity(float);
+
+private:
+ QRect m_rect;
+ float m_opacity;
+};
+
+
+#endif \ No newline at end of file
diff --git a/tests/benchmarks/qanimation/main.cpp b/tests/benchmarks/qanimation/main.cpp
new file mode 100644
index 0000000..7bb770f
--- /dev/null
+++ b/tests/benchmarks/qanimation/main.cpp
@@ -0,0 +1,150 @@
+#include <QtGui>
+#include <qtest.h>
+
+#include "dummyobject.h"
+#include "dummyanimation.h"
+#include "rectanimation.h"
+
+#define ITERATION_COUNT 10e3
+
+class tst_qanimation : public QObject
+{
+ Q_OBJECT
+private slots:
+ void itemPropertyAnimation();
+ void itemPropertyAnimation_data() { data();}
+ void dummyAnimation();
+ void dummyAnimation_data() { data();}
+ void dummyPropertyAnimation();
+ void dummyPropertyAnimation_data() { data();}
+ void rectAnimation();
+ void rectAnimation_data() { data();}
+
+ void floatAnimation_data() { data(); }
+ void floatAnimation();
+
+private:
+ void data();
+};
+
+
+void tst_qanimation::data()
+{
+ QTest::addColumn<bool>("started");
+ QTest::newRow("NotRunning") << false;
+ QTest::newRow("Running") << true;
+}
+
+void tst_qanimation::itemPropertyAnimation()
+{
+ QFETCH(bool, started);
+ QGraphicsWidget item;
+
+ //then the property animation
+ {
+ QPropertyAnimation anim(&item, "pos");
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QPointF(0,0));
+ anim.setEndValue(QPointF(ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+
+}
+
+void tst_qanimation::dummyAnimation()
+{
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //first the dummy animation
+ {
+ DummyAnimation anim(&dummy);
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QRect(0, 0, 0, 0));
+ anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < anim.duration(); ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+void tst_qanimation::dummyPropertyAnimation()
+{
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //then the property animation
+ {
+ QPropertyAnimation anim(&dummy, "rect");
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QRect(0, 0, 0, 0));
+ anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+void tst_qanimation::rectAnimation()
+{
+ //this is the simplest animation you can do
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //then the property animation
+ {
+ RectAnimation anim(&dummy);
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QRect(0, 0, 0, 0));
+ anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+void tst_qanimation::floatAnimation()
+{
+ //this is the simplest animation you can do
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //then the property animation
+ {
+ QPropertyAnimation anim(&dummy, "opacity");
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(0.f);
+ anim.setEndValue(1.f);
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+
+
+QTEST_MAIN(tst_qanimation)
+
+#include "main.moc"
diff --git a/tests/benchmarks/qanimation/qanimation.pro b/tests/benchmarks/qanimation/qanimation.pro
new file mode 100644
index 0000000..55cd75e
--- /dev/null
+++ b/tests/benchmarks/qanimation/qanimation.pro
@@ -0,0 +1,18 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qanimation
+DEPENDPATH += .
+INCLUDEPATH += .
+
+CONFIG += release
+#CONFIG += debug
+
+
+SOURCES += main.cpp \
+ dummyobject.cpp \
+ dummyanimation.cpp \
+ rectanimation.cpp
+
+HEADERS += dummyobject.h \
+ dummyanimation.h \
+ rectanimation.h
diff --git a/tests/benchmarks/qanimation/rectanimation.cpp b/tests/benchmarks/qanimation/rectanimation.cpp
new file mode 100644
index 0000000..d60a943
--- /dev/null
+++ b/tests/benchmarks/qanimation/rectanimation.cpp
@@ -0,0 +1,58 @@
+#include "rectanimation.h"
+#include "dummyobject.h"
+
+static inline int interpolateInteger(int from, int to, qreal progress)
+{
+ return from + (to - from) * progress;
+}
+
+
+RectAnimation::RectAnimation(DummyObject *obj) : m_object(obj), m_dura(250)
+{
+}
+
+void RectAnimation::setEndValue(const QRect &rect)
+{
+ m_end = rect;
+}
+
+void RectAnimation::setStartValue(const QRect &rect)
+{
+ m_start = rect;
+}
+
+void RectAnimation::setDuration(int d)
+{
+ m_dura = d;
+}
+
+int RectAnimation::duration() const
+{
+ return m_dura;
+}
+
+
+void RectAnimation::updateCurrentTime(int msecs)
+{
+ qreal progress = m_easing.valueForProgress( qreal(msecs) / qreal(m_dura) );
+ QRect now;
+ now.setCoords(interpolateInteger(m_start.left(), m_end.left(), progress),
+ interpolateInteger(m_start.top(), m_end.top(), progress),
+ interpolateInteger(m_start.right(), m_end.right(), progress),
+ interpolateInteger(m_start.bottom(), m_end.bottom(), progress));
+
+ bool changed = (now != m_current);
+ if (changed)
+ m_current = now;
+
+ if (state() == Stopped)
+ return;
+
+ if (m_object)
+ m_object->setRect(m_current);
+}
+
+void RectAnimation::updateState(QAbstractAnimation::State state)
+{
+ Q_UNUSED(state);
+}
diff --git a/tests/benchmarks/qanimation/rectanimation.h b/tests/benchmarks/qanimation/rectanimation.h
new file mode 100644
index 0000000..99b82b4
--- /dev/null
+++ b/tests/benchmarks/qanimation/rectanimation.h
@@ -0,0 +1,30 @@
+#include <QtGui>
+
+#ifndef _RECTANIMATION_H__
+
+class DummyObject;
+
+//this class is even simpler than the dummy
+//and uses no QVariant at all
+class RectAnimation : public QAbstractAnimation
+{
+public:
+ RectAnimation(DummyObject *obj);
+
+ void setEndValue(const QRect &rect);
+ void setStartValue(const QRect &rect);
+
+ void setDuration(int d);
+ int duration() const;
+
+ virtual void updateCurrentTime(int msecs);
+ virtual void updateState(QAbstractAnimation::State state);
+
+private:
+ DummyObject *m_object;
+ QEasingCurve m_easing;
+ QRect m_start, m_end, m_current;
+ int m_dura;
+};
+
+#endif
diff --git a/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro b/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro
new file mode 100644
index 0000000..c8fc07b
--- /dev/null
+++ b/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qgraphicsitem
+
+SOURCES += tst_qgraphicsitem.cpp
+
diff --git a/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp
new file mode 100644
index 0000000..68e3aa1
--- /dev/null
+++ b/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QGraphicsItem>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+
+//TESTED_FILES=
+
+class tst_QGraphicsItem : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QGraphicsItem();
+ virtual ~tst_QGraphicsItem();
+
+public slots:
+ void init();
+ void cleanup();
+
+private slots:
+ void setPos_data();
+ void setPos();
+ void setTransform_data();
+ void setTransform();
+ void rotate();
+ void scale();
+ void shear();
+ void translate();
+ void setRotation();
+ void setRotationXYZ();
+};
+
+tst_QGraphicsItem::tst_QGraphicsItem()
+{
+}
+
+tst_QGraphicsItem::~tst_QGraphicsItem()
+{
+}
+
+void tst_QGraphicsItem::init()
+{
+}
+
+void tst_QGraphicsItem::cleanup()
+{
+}
+
+void tst_QGraphicsItem::setPos_data()
+{
+ QTest::addColumn<QPointF>("pos");
+
+ QTest::newRow("0, 0") << QPointF(0, 0);
+ QTest::newRow("10, 10") << QPointF(10, 10);
+ QTest::newRow("-10, -10") << QPointF(-10, -10);
+}
+
+void tst_QGraphicsItem::setPos()
+{
+ QFETCH(QPointF, pos);
+
+ QGraphicsScene scene;
+ QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ rect->setPos(10, 10);
+ rect->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::setTransform_data()
+{
+ QTest::addColumn<QTransform>("transform");
+
+ QTest::newRow("id") << QTransform();
+ QTest::newRow("rotate 45z") << QTransform().rotate(45);
+ QTest::newRow("scale 2x2") << QTransform().scale(2, 2);
+ QTest::newRow("translate 100, 100") << QTransform().translate(100, 100);
+ QTest::newRow("rotate 45x 45y 45z") << QTransform().rotate(45, Qt::XAxis)
+ .rotate(45, Qt::YAxis).rotate(45, Qt::ZAxis);
+}
+
+void tst_QGraphicsItem::setTransform()
+{
+ QFETCH(QTransform, transform);
+
+ QGraphicsScene scene;
+ QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->setTransform(transform);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::rotate()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->rotate(45);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::scale()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->scale(2, 2);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::shear()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->shear(1.5, 1.5);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::translate()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->translate(100, 100);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::setRotation()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->setXRotation(45);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::setRotationXYZ()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->setRotation(45, 45, 45);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+QTEST_MAIN(tst_QGraphicsItem)
+#include "tst_qgraphicsitem.moc"
diff --git a/tests/benchmarks/qstring/main.cpp b/tests/benchmarks/qstring/main.cpp
new file mode 100644
index 0000000..cbbf0a1
--- /dev/null
+++ b/tests/benchmarks/qstring/main.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QStringList>
+#include <qtest.h>
+
+class tst_QString: public QObject
+{
+ Q_OBJECT
+private slots:
+ void equals() const;
+ void equals_data() const;
+};
+
+void tst_QString::equals() const
+{
+ QFETCH(QString, a);
+ QFETCH(QString, b);
+
+ QBENCHMARK {
+ a == b;
+ }
+}
+
+void tst_QString::equals_data() const
+{
+ static const struct {
+ ushort data[80];
+ int dummy; // just to ensure 4-byte alignment
+ } data = {
+ {
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 16
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 32
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 48
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 64
+ 64, 64, 64, 64, 96, 96, 96, 96,
+ 64, 64, 96, 96, 96, 96, 96, 96 // 80
+ }, 0
+ };
+ const QChar *ptr = reinterpret_cast<const QChar *>(data.data);
+
+ QTest::addColumn<QString>("a");
+ QTest::addColumn<QString>("b");
+ QString base = QString::fromRawData(ptr, 64);
+
+ QTest::newRow("different-length") << base << QString::fromRawData(ptr, 4);
+ QTest::newRow("same-string") << base << base;
+ QTest::newRow("same-data") << base << QString::fromRawData(ptr, 64);
+
+ // try to avoid crossing a cache line (that is, at ptr[64])
+ QTest::newRow("aligned-aligned-4n")
+ << QString::fromRawData(ptr, 60) << QString::fromRawData(ptr + 2, 60);
+ QTest::newRow("aligned-unaligned-4n")
+ << QString::fromRawData(ptr, 60) << QString::fromRawData(ptr + 1, 60);
+ QTest::newRow("unaligned-unaligned-4n")
+ << QString::fromRawData(ptr + 1, 60) << QString::fromRawData(ptr + 3, 60);
+
+ QTest::newRow("aligned-aligned-4n+1")
+ << QString::fromRawData(ptr, 61) << QString::fromRawData(ptr + 2, 61);
+ QTest::newRow("aligned-unaligned-4n+1")
+ << QString::fromRawData(ptr, 61) << QString::fromRawData(ptr + 1, 61);
+ QTest::newRow("unaligned-unaligned-4n+1")
+ << QString::fromRawData(ptr + 1, 61) << QString::fromRawData(ptr + 3, 61);
+
+ QTest::newRow("aligned-aligned-4n-1")
+ << QString::fromRawData(ptr, 59) << QString::fromRawData(ptr + 2, 59);
+ QTest::newRow("aligned-unaligned-4n-1")
+ << QString::fromRawData(ptr, 59) << QString::fromRawData(ptr + 1, 59);
+ QTest::newRow("unaligned-unaligned-4n-1")
+ << QString::fromRawData(ptr + 1, 59) << QString::fromRawData(ptr + 3, 59);
+
+ QTest::newRow("aligned-aligned-2n")
+ << QString::fromRawData(ptr, 58) << QString::fromRawData(ptr + 2, 58);
+ QTest::newRow("aligned-unaligned-2n")
+ << QString::fromRawData(ptr, 58) << QString::fromRawData(ptr + 1, 58);
+ QTest::newRow("unaligned-unaligned-2n")
+ << QString::fromRawData(ptr + 1, 58) << QString::fromRawData(ptr + 3, 58);
+}
+
+QTEST_MAIN(tst_QString)
+
+#include "main.moc"
diff --git a/tests/benchmarks/qstring/qstring.pro b/tests/benchmarks/qstring/qstring.pro
new file mode 100644
index 0000000..74423e7
--- /dev/null
+++ b/tests/benchmarks/qstring/qstring.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+TARGET = tst_qstring
+QT -= gui
+SOURCES += main.cpp
diff --git a/tests/benchmarks/qvariant/qvariant.pro b/tests/benchmarks/qvariant/qvariant.pro
index 68b4a97..63b5442 100644
--- a/tests/benchmarks/qvariant/qvariant.pro
+++ b/tests/benchmarks/qvariant/qvariant.pro
@@ -3,7 +3,6 @@ TEMPLATE = app
TARGET = tst_qvariant
DEPENDPATH += .
INCLUDEPATH += .
-QT -= gui
CONFIG += release
#CONFIG += debug
diff --git a/tests/benchmarks/qvariant/tst_qvariant.cpp b/tests/benchmarks/qvariant/tst_qvariant.cpp
index 4a7ad02..0eb1ae2 100644
--- a/tests/benchmarks/qvariant/tst_qvariant.cpp
+++ b/tests/benchmarks/qvariant/tst_qvariant.cpp
@@ -38,7 +38,9 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
#include <QtCore>
+#include <QtGui/QPixmap>
#include <qtest.h>
#define ITERATION_COUNT 1e5
@@ -47,64 +49,73 @@ class tst_qvariant : public QObject
{
Q_OBJECT
private slots:
+ void testBound();
+
void doubleVariantCreation();
void floatVariantCreation();
void rectVariantCreation();
void stringVariantCreation();
+ void pixmapVariantCreation();
+
void doubleVariantSetValue();
void floatVariantSetValue();
void rectVariantSetValue();
void stringVariantSetValue();
+
void doubleVariantAssignment();
void floatVariantAssignment();
void rectVariantAssignment();
void stringVariantAssignment();
};
-
-void tst_qvariant::doubleVariantCreation()
+void tst_qvariant::testBound()
{
- double d = 0;
+ qreal d = qreal(.5);
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(d);
+ d = qBound<qreal>(0, d, 1);
}
}
}
-void tst_qvariant::floatVariantCreation()
+template <typename T>
+static void variantCreation(T val)
{
- float f = 0;
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(f);
+ QVariant v(val);
}
}
}
+void tst_qvariant::doubleVariantCreation()
+{
+ variantCreation<double>(0.0);
+}
+
+void tst_qvariant::floatVariantCreation()
+{
+ variantCreation<float>(0.0f);
+}
+
void tst_qvariant::rectVariantCreation()
{
- QRect r(1,2,3,4);
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(r);
- }
- }
+ variantCreation<QRect>(QRect(1, 2, 3, 4));
}
void tst_qvariant::stringVariantCreation()
{
- QString s;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(s);
- }
- }
+ variantCreation<QString>(QString());
}
-void tst_qvariant::doubleVariantSetValue()
+void tst_qvariant::pixmapVariantCreation()
+{
+ variantCreation<QPixmap>(QPixmap());
+}
+
+template <typename T>
+static void variantSetValue(T d)
{
- double d = 0;
QVariant v;
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
@@ -113,42 +124,29 @@ void tst_qvariant::doubleVariantSetValue()
}
}
+void tst_qvariant::doubleVariantSetValue()
+{
+ variantSetValue<double>(0.0);
+}
+
void tst_qvariant::floatVariantSetValue()
{
- float f = 0;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- qVariantSetValue(v, f);
- }
- }
+ variantSetValue<float>(0.0f);
}
void tst_qvariant::rectVariantSetValue()
{
- QRect r;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- qVariantSetValue(v, r);
- }
- }
+ variantSetValue<QRect>(QRect());
}
void tst_qvariant::stringVariantSetValue()
{
- QString s;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- qVariantSetValue(v, s);
- }
- }
+ variantSetValue<QString>(QString());
}
-void tst_qvariant::doubleVariantAssignment()
+template <typename T>
+static void variantAssignment(T d)
{
- double d = 0;
QVariant v;
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
@@ -157,37 +155,24 @@ void tst_qvariant::doubleVariantAssignment()
}
}
+void tst_qvariant::doubleVariantAssignment()
+{
+ variantAssignment<double>(0.0);
+}
+
void tst_qvariant::floatVariantAssignment()
{
- float f = 0;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- v = f;
- }
- }
+ variantAssignment<float>(0.0f);
}
void tst_qvariant::rectVariantAssignment()
{
- QRect r;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- v = r;
- }
- }
+ variantAssignment<QRect>(QRect());
}
void tst_qvariant::stringVariantAssignment()
{
- QString s;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- v = s;
- }
- }
+ variantAssignment<QString>(QString());
}
QTEST_MAIN(tst_qvariant)
diff --git a/tools/designer/src/components/formeditor/qdesigner_resource.cpp b/tools/designer/src/components/formeditor/qdesigner_resource.cpp
index 75a53b7..5f53ae2 100644
--- a/tools/designer/src/components/formeditor/qdesigner_resource.cpp
+++ b/tools/designer/src/components/formeditor/qdesigner_resource.cpp
@@ -743,26 +743,6 @@ void QDesignerResource::setSaveRelative(bool relative)
m_resourceBuilder->setSaveRelative(relative);
}
-static bool addFakeMethods(const DomSlots *domSlots, QStringList &fakeSlots, QStringList &fakeSignals)
-{
- if (!domSlots)
- return false;
-
- bool rc = false;
- foreach (const QString &fakeSlot, domSlots->elementSlot())
- if (fakeSlots.indexOf(fakeSlot) == -1) {
- fakeSlots += fakeSlot;
- rc = true;
- }
-
- foreach (const QString &fakeSignal, domSlots->elementSignal())
- if (fakeSignals.indexOf(fakeSignal) == -1) {
- fakeSignals += fakeSignal;
- rc = true;
- }
- return rc;
-}
-
QWidget *QDesignerResource::create(DomUI *ui, QWidget *parentWidget)
{
// Load extra info extension. This is used by Jambi for preventing
@@ -1425,108 +1405,9 @@ DomLayoutItem *QDesignerResource::createDom(QLayoutItem *item, DomLayout *ui_lay
return ui_item;
}
-static void addFakeMethodsToWidgetDataBase(const DomCustomWidget *domCustomWidget, WidgetDataBaseItem *item)
-{
- const DomSlots *domSlots = domCustomWidget->elementSlots();
- if (!domSlots)
- return;
-
- // Merge in new slots, signals
- QStringList fakeSlots = item->fakeSlots();
- QStringList fakeSignals = item->fakeSignals();
- if (addFakeMethods(domSlots, fakeSlots, fakeSignals)) {
- item->setFakeSlots(fakeSlots);
- item->setFakeSignals(fakeSignals);
- }
-}
-
-void QDesignerResource::addCustomWidgetsToWidgetDatabase(DomCustomWidgetList& custom_widget_list)
-{
- // Perform one iteration of adding the custom widgets to the database,
- // looking up the base class and inheriting its data.
- // Remove the succeeded custom widgets from the list.
- // Classes whose base class could not be found are left in the list.
- QDesignerWidgetDataBaseInterface *db = m_formWindow->core()->widgetDataBase();
- for (int i=0; i < custom_widget_list.size(); ) {
- bool classInserted = false;
- DomCustomWidget *custom_widget = custom_widget_list[i];
- const QString customClassName = custom_widget->elementClass();
- const QString base_class = custom_widget->elementExtends();
- QString includeFile;
- IncludeType includeType = IncludeLocal;
- if (const DomHeader *header = custom_widget->elementHeader()) {
- includeFile = header->text();
- if (header->hasAttributeLocation() && header->attributeLocation() == QLatin1String("global"))
- includeType = IncludeGlobal;
- }
- const bool domIsContainer = custom_widget->elementContainer();
- // Append a new item
- if (base_class.isEmpty()) {
- WidgetDataBaseItem *item = new WidgetDataBaseItem(customClassName);
- item->setPromoted(false);
- item->setGroup(QApplication::translate("Designer", "Custom Widgets"));
- item->setIncludeFile(buildIncludeFile(includeFile, includeType));
- item->setContainer(domIsContainer);
- item->setCustom(true);
- addFakeMethodsToWidgetDataBase(custom_widget, item);
- db->append(item);
- custom_widget_list.removeAt(i);
- classInserted = true;
- } else {
- // Create a new entry cloned from base class. Note that this will ignore existing
- // classes, eg, plugin custom widgets.
- QDesignerWidgetDataBaseItemInterface *item =
- appendDerived(db, customClassName, QApplication::translate("Designer", "Promoted Widgets"),
- base_class,
- buildIncludeFile(includeFile, includeType),
- true,true);
- // Ok, base class found.
- if (item) {
- // Hack to accommodate for old UI-files in which "contains" is not set properly:
- // Apply "contains" from DOM only if true (else, eg classes from QFrame might not accept
- // dropping child widgets on them as container=false). This also allows for
- // QWidget-derived stacked pages.
- if (domIsContainer)
- item->setContainer(domIsContainer);
-
- addFakeMethodsToWidgetDataBase(custom_widget, static_cast<WidgetDataBaseItem*>(item));
- custom_widget_list.removeAt(i);
- classInserted = true;
- }
- }
- // Skip failed item.
- if (!classInserted)
- i++;
- }
-
-}
void QDesignerResource::createCustomWidgets(DomCustomWidgets *dom_custom_widgets)
{
- if (dom_custom_widgets == 0)
- return;
- DomCustomWidgetList custom_widget_list = dom_custom_widgets->elementCustomWidget();
- // Attempt to insert each item derived from its base class.
- // This should at most require two iterations in the event that the classes are out of order
- // (derived first, max depth: promoted custom plugin = 2)
- for (int iteration = 0; iteration < 2; iteration++) {
- addCustomWidgetsToWidgetDatabase(custom_widget_list);
- if (custom_widget_list.empty())
- return;
- }
- // Oops, there are classes left whose base class could not be found.
- // Default them to QWidget with warnings.
- const QString fallBackBaseClass = QLatin1String("QWidget");
- for (int i=0; i < custom_widget_list.size(); i++ ) {
- DomCustomWidget *custom_widget = custom_widget_list[i];
- const QString customClassName = custom_widget->elementClass();
- const QString base_class = custom_widget->elementExtends();
- qDebug() << "** WARNING The base class " << base_class << " of the custom widget class " << customClassName
- << " could not be found. Defaulting to " << fallBackBaseClass << '.';
- custom_widget->setElementExtends(fallBackBaseClass);
- }
- // One more pass.
- addCustomWidgetsToWidgetDatabase(custom_widget_list);
- Q_ASSERT(custom_widget_list.empty());
+ QSimpleResource::handleDomCustomWidgets(core(), dom_custom_widgets);
}
DomTabStops *QDesignerResource::saveTabStops()
diff --git a/tools/designer/src/lib/shared/newformwidget.cpp b/tools/designer/src/lib/shared/newformwidget.cpp
index d79d77a..503e597 100644
--- a/tools/designer/src/lib/shared/newformwidget.cpp
+++ b/tools/designer/src/lib/shared/newformwidget.cpp
@@ -310,9 +310,8 @@ QImage NewFormWidget::grabForm(QDesignerFormEditorInterface *core,
const QString &workingDir,
const qdesigner_internal::DeviceProfile &dp)
{
- qdesigner_internal::QDesignerFormBuilder formBuilder(core,
- qdesigner_internal::QDesignerFormBuilder::DisableScripts,
- dp);
+ qdesigner_internal::NewFormWidgetFormBuilder
+ formBuilder(core, qdesigner_internal::QDesignerFormBuilder::DisableScripts, dp);
if (!workingDir.isEmpty())
formBuilder.setWorkingDirectory(workingDir);
diff --git a/tools/designer/src/lib/shared/qdesigner_formbuilder.cpp b/tools/designer/src/lib/shared/qdesigner_formbuilder.cpp
index 6394847..b92a48d 100644
--- a/tools/designer/src/lib/shared/qdesigner_formbuilder.cpp
+++ b/tools/designer/src/lib/shared/qdesigner_formbuilder.cpp
@@ -473,6 +473,20 @@ QPixmap QDesignerFormBuilder::createPreviewPixmap(const QDesignerFormWindowInter
return rc;
}
+// ---------- NewFormWidgetFormBuilder
+
+NewFormWidgetFormBuilder::NewFormWidgetFormBuilder(QDesignerFormEditorInterface *core,
+ Mode mode,
+ const DeviceProfile &deviceProfile) :
+ QDesignerFormBuilder(core, mode, deviceProfile)
+{
+}
+
+void NewFormWidgetFormBuilder::createCustomWidgets(DomCustomWidgets *dc)
+{
+ QSimpleResource::handleDomCustomWidgets(core(), dc);
+}
+
} // namespace qdesigner_internal
QT_END_NAMESPACE
diff --git a/tools/designer/src/lib/shared/qdesigner_formbuilder_p.h b/tools/designer/src/lib/shared/qdesigner_formbuilder_p.h
index b982e1c..ee40085 100644
--- a/tools/designer/src/lib/shared/qdesigner_formbuilder_p.h
+++ b/tools/designer/src/lib/shared/qdesigner_formbuilder_p.h
@@ -75,7 +75,7 @@ namespace qdesigner_internal {
class DesignerPixmapCache;
class DesignerIconCache;
-/* Form builder used for previewing forms, widget box and new form dialog.
+/* Form builder used for previewing forms and widget box.
* It applies the system settings to its toplevel window. */
class QDESIGNER_SHARED_EXPORT QDesignerFormBuilder: public QFormBuilder
@@ -159,6 +159,21 @@ private:
bool m_mainWidget;
};
+// Form builder for a new form widget (preview). To allow for promoted
+// widgets in the template, it implements the handling of custom widgets
+// (adding of them to the widget database).
+
+class QDESIGNER_SHARED_EXPORT NewFormWidgetFormBuilder: public QDesignerFormBuilder {
+public:
+ NewFormWidgetFormBuilder(QDesignerFormEditorInterface *core,
+ Mode mode,
+ const DeviceProfile &deviceProfile = DeviceProfile());
+
+protected:
+ virtual void createCustomWidgets(DomCustomWidgets *);
+};
+
+
} // namespace qdesigner_internal
QT_END_NAMESPACE
diff --git a/tools/designer/src/lib/shared/qdesigner_toolbar.cpp b/tools/designer/src/lib/shared/qdesigner_toolbar.cpp
index 0bb91ee..898be1e 100644
--- a/tools/designer/src/lib/shared/qdesigner_toolbar.cpp
+++ b/tools/designer/src/lib/shared/qdesigner_toolbar.cpp
@@ -440,18 +440,14 @@ QAction *ToolBarEventFilter::actionAt(const QToolBar *tb, const QPoint &pos)
return tb->actions().at(index);
}
+//that's a trick to get acces to the initStyleOption which is a protected member
+class FriendlyToolBar : public QToolBar {
+public:
+ friend class ToolBarEventFilter;
+};
+
QRect ToolBarEventFilter::handleArea(const QToolBar *tb)
{
- //that's a trick to get acces to the initStyleOption which is a protected member
- class FriendlyToolBar : public QToolBar
- {
- public:
-#ifdef Q_NO_USING_KEYWORD
- void initStyleOption(QStyleOptionToolBar *option) { QToolBar::initStyleOption(option); }
-#else
- using QToolBar::initStyleOption;
-#endif
- };
QStyleOptionToolBar opt;
static_cast<const FriendlyToolBar*>(tb)->initStyleOption(&opt);
return tb->style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, tb);
diff --git a/tools/designer/src/lib/shared/qsimpleresource.cpp b/tools/designer/src/lib/shared/qsimpleresource.cpp
index 8d29002..69d48fd 100644
--- a/tools/designer/src/lib/shared/qsimpleresource.cpp
+++ b/tools/designer/src/lib/shared/qsimpleresource.cpp
@@ -41,6 +41,7 @@
#include "qsimpleresource_p.h"
#include "widgetfactory_p.h"
+#include "widgetdatabase_p.h"
#include <formscriptrunner_p.h>
#include <properties_p.h>
@@ -57,6 +58,8 @@
#include <QtGui/QWidget>
#include <QtGui/QAction>
#include <QtCore/QDebug>
+#include <QtCore/QCoreApplication>
+
QT_BEGIN_NAMESPACE
@@ -267,6 +270,136 @@ bool QSimpleResource::warningsEnabled()
return m_warningsEnabled;
}
+// Custom widgets handling helpers
+
+// Add unique fake slots and signals to lists
+bool QSimpleResource::addFakeMethods(const DomSlots *domSlots, QStringList &fakeSlots, QStringList &fakeSignals)
+{
+ if (!domSlots)
+ return false;
+
+ bool rc = false;
+ foreach (const QString &fakeSlot, domSlots->elementSlot())
+ if (fakeSlots.indexOf(fakeSlot) == -1) {
+ fakeSlots += fakeSlot;
+ rc = true;
+ }
+
+ foreach (const QString &fakeSignal, domSlots->elementSignal())
+ if (fakeSignals.indexOf(fakeSignal) == -1) {
+ fakeSignals += fakeSignal;
+ rc = true;
+ }
+ return rc;
+}
+
+void QSimpleResource::addFakeMethodsToWidgetDataBase(const DomCustomWidget *domCustomWidget, WidgetDataBaseItem *item)
+{
+ const DomSlots *domSlots = domCustomWidget->elementSlots();
+ if (!domSlots)
+ return;
+
+ // Merge in new slots, signals
+ QStringList fakeSlots = item->fakeSlots();
+ QStringList fakeSignals = item->fakeSignals();
+ if (addFakeMethods(domSlots, fakeSlots, fakeSignals)) {
+ item->setFakeSlots(fakeSlots);
+ item->setFakeSignals(fakeSignals);
+ }
+}
+
+// Perform one iteration of adding the custom widgets to the database,
+// looking up the base class and inheriting its data.
+// Remove the succeeded custom widgets from the list.
+// Classes whose base class could not be found are left in the list.
+
+void QSimpleResource::addCustomWidgetsToWidgetDatabase(const QDesignerFormEditorInterface *core,
+ QList<DomCustomWidget*>& custom_widget_list)
+{
+ QDesignerWidgetDataBaseInterface *db = core->widgetDataBase();
+ for (int i=0; i < custom_widget_list.size(); ) {
+ bool classInserted = false;
+ DomCustomWidget *custom_widget = custom_widget_list[i];
+ const QString customClassName = custom_widget->elementClass();
+ const QString base_class = custom_widget->elementExtends();
+ QString includeFile;
+ IncludeType includeType = IncludeLocal;
+ if (const DomHeader *header = custom_widget->elementHeader()) {
+ includeFile = header->text();
+ if (header->hasAttributeLocation() && header->attributeLocation() == QLatin1String("global"))
+ includeType = IncludeGlobal;
+ }
+ const bool domIsContainer = custom_widget->elementContainer();
+ // Append a new item
+ if (base_class.isEmpty()) {
+ WidgetDataBaseItem *item = new WidgetDataBaseItem(customClassName);
+ item->setPromoted(false);
+ item->setGroup(QCoreApplication::translate("Designer", "Custom Widgets"));
+ item->setIncludeFile(buildIncludeFile(includeFile, includeType));
+ item->setContainer(domIsContainer);
+ item->setCustom(true);
+ addFakeMethodsToWidgetDataBase(custom_widget, item);
+ db->append(item);
+ custom_widget_list.removeAt(i);
+ classInserted = true;
+ } else {
+ // Create a new entry cloned from base class. Note that this will ignore existing
+ // classes, eg, plugin custom widgets.
+ QDesignerWidgetDataBaseItemInterface *item =
+ appendDerived(db, customClassName, QCoreApplication::translate("Designer", "Promoted Widgets"),
+ base_class,
+ buildIncludeFile(includeFile, includeType),
+ true,true);
+ // Ok, base class found.
+ if (item) {
+ // Hack to accommodate for old UI-files in which "container" is not set properly:
+ // Apply "container" from DOM only if true (else, eg classes from QFrame might not accept
+ // dropping child widgets on them as container=false). This also allows for
+ // QWidget-derived stacked pages.
+ if (domIsContainer)
+ item->setContainer(domIsContainer);
+
+ addFakeMethodsToWidgetDataBase(custom_widget, static_cast<WidgetDataBaseItem*>(item));
+ custom_widget_list.removeAt(i);
+ classInserted = true;
+ }
+ }
+ // Skip failed item.
+ if (!classInserted)
+ i++;
+ }
+
+}
+
+void QSimpleResource::handleDomCustomWidgets(const QDesignerFormEditorInterface *core,
+ const DomCustomWidgets *dom_custom_widgets)
+{
+ if (dom_custom_widgets == 0)
+ return;
+ QList<DomCustomWidget*> custom_widget_list = dom_custom_widgets->elementCustomWidget();
+ // Attempt to insert each item derived from its base class.
+ // This should at most require two iterations in the event that the classes are out of order
+ // (derived first, max depth: promoted custom plugin = 2)
+ for (int iteration = 0; iteration < 2; iteration++) {
+ addCustomWidgetsToWidgetDatabase(core, custom_widget_list);
+ if (custom_widget_list.empty())
+ return;
+ }
+ // Oops, there are classes left whose base class could not be found.
+ // Default them to QWidget with warnings.
+ const QString fallBackBaseClass = QLatin1String("QWidget");
+ for (int i=0; i < custom_widget_list.size(); i++ ) {
+ DomCustomWidget *custom_widget = custom_widget_list[i];
+ const QString customClassName = custom_widget->elementClass();
+ const QString base_class = custom_widget->elementExtends();
+ qDebug() << "** WARNING The base class " << base_class << " of the custom widget class " << customClassName
+ << " could not be found. Defaulting to " << fallBackBaseClass << '.';
+ custom_widget->setElementExtends(fallBackBaseClass);
+ }
+ // One more pass.
+ addCustomWidgetsToWidgetDatabase(core, custom_widget_list);
+}
+
// ------------ FormBuilderClipboard
FormBuilderClipboard::FormBuilderClipboard(QWidget *w)
diff --git a/tools/designer/src/lib/shared/qsimpleresource_p.h b/tools/designer/src/lib/shared/qsimpleresource_p.h
index 8d45c3c..a25cb88 100644
--- a/tools/designer/src/lib/shared/qsimpleresource_p.h
+++ b/tools/designer/src/lib/shared/qsimpleresource_p.h
@@ -55,15 +55,21 @@
#include "shared_global_p.h"
#include "abstractformbuilder.h"
+#include <QtCore/QStringList>
QT_BEGIN_NAMESPACE
class DomScript;
+class DomCustomWidgets;
+class DomCustomWidget;
+class DomSlots;
class QDesignerFormEditorInterface;
namespace qdesigner_internal {
+class WidgetDataBaseItem;
+
class QDESIGNER_SHARED_EXPORT QSimpleResource : public QAbstractFormBuilder
{
public:
@@ -92,6 +98,11 @@ public:
static QString customWidgetScript(QDesignerFormEditorInterface *core, const QString &className);
static bool hasCustomWidgetScript(QDesignerFormEditorInterface *core, QObject *object);
+ // Implementation for FormBuilder::createDomCustomWidgets() that adds
+ // the custom widgets to the widget database
+ static void handleDomCustomWidgets(const QDesignerFormEditorInterface *core,
+ const DomCustomWidgets *dom_custom_widgets);
+
protected:
virtual QIcon nameToIcon(const QString &filePath, const QString &qrcPath);
virtual QString iconToFilePath(const QIcon &pm) const;
@@ -105,7 +116,13 @@ protected:
typedef QList<DomScript*> DomScripts;
static void addScript(const QString &script, ScriptSource source, DomScripts &domScripts);
+ static bool addFakeMethods(const DomSlots *domSlots, QStringList &fakeSlots, QStringList &fakeSignals);
+
private:
+ static void addCustomWidgetsToWidgetDatabase(const QDesignerFormEditorInterface *core,
+ QList<DomCustomWidget*>& custom_widget_list);
+ static void addFakeMethodsToWidgetDataBase(const DomCustomWidget *domCustomWidget, WidgetDataBaseItem *item);
+
static bool m_warningsEnabled;
QDesignerFormEditorInterface *m_core;
};
diff --git a/tools/linguist/lconvert/main.cpp b/tools/linguist/lconvert/main.cpp
index bdc6c9a..ce17b6f 100644
--- a/tools/linguist/lconvert/main.cpp
+++ b/tools/linguist/lconvert/main.cpp
@@ -97,6 +97,11 @@ static int usage(const QStringList &args)
" Drop obsolete messages.\n\n"
" --no-finished\n"
" Drop finished messages.\n\n"
+ " --locations {absolute|relative|none}\n"
+ " Override how source code references are saved in ts files.\n"
+ " Default is absolute.\n}n"
+ " --no-ui-lines\n"
+ " Drop line numbers from references to .ui files.\n\n"
" --verbose\n"
" be a bit more verbose\n\n"
"Long options can be specified with only one leading dash, too.\n\n"
@@ -129,6 +134,8 @@ int main(int argc, char *argv[])
bool noObsolete = false;
bool noFinished = false;
bool verbose = false;
+ bool noUiLines = false;
+ Translator::LocationsType locations = Translator::DefaultLocations;
ConversionData cd;
Translator tr;
@@ -180,6 +187,19 @@ int main(int argc, char *argv[])
noObsolete = true;
} else if (args[i] == QLatin1String("-no-finished")) {
noFinished = true;
+ } else if (args[i] == QLatin1String("-locations")) {
+ if (++i >= args.size())
+ return usage(args);
+ if (args[i] == QLatin1String("none"))
+ locations = Translator::NoLocations;
+ else if (args[i] == QLatin1String("relative"))
+ locations = Translator::RelativeLocations;
+ else if (args[i] == QLatin1String("absolute"))
+ locations = Translator::AbsoluteLocations;
+ else
+ return usage(args);
+ } else if (args[i] == QLatin1String("-no-ui-lines")) {
+ noUiLines = true;
} else if (args[i] == QLatin1String("-verbose")) {
verbose = true;
} else if (args[i].startsWith(QLatin1Char('-'))) {
@@ -224,6 +244,10 @@ int main(int argc, char *argv[])
tr.stripFinishedMessages();
if (dropTranslations)
tr.dropTranslations();
+ if (noUiLines)
+ tr.dropUiLines();
+ if (locations != Translator::DefaultLocations)
+ tr.setLocationsType(locations);
if (!tr.save(outFileName, cd, outFormat)) {
qWarning("%s", qPrintable(cd.error()));
diff --git a/tools/linguist/lupdate/java.cpp b/tools/linguist/lupdate/java.cpp
index 31024f9..658aebf 100644
--- a/tools/linguist/lupdate/java.cpp
+++ b/tools/linguist/lupdate/java.cpp
@@ -375,22 +375,13 @@ static bool matchString( QString &s )
return true;
}
-static bool matchInteger( qlonglong *number)
-{
- bool matches = (yyTok == Tok_Integer);
- if (matches) {
- yyTok = getToken();
- *number = yyInteger;
- }
- return matches;
-}
-
static bool matchStringOrNull(QString &s)
{
bool matches = matchString(s);
if (!matches) {
matches = (yyTok == Tok_null);
- if (matches) yyTok = getToken();
+ if (matches)
+ yyTok = getToken();
}
return matches;
}
diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp
index 312bb71..c1f242d 100644
--- a/tools/linguist/shared/translator.cpp
+++ b/tools/linguist/shared/translator.cpp
@@ -416,6 +416,26 @@ void Translator::dropTranslations()
}
}
+void Translator::dropUiLines()
+{
+ QString uiXt = QLatin1String(".ui");
+ QString juiXt = QLatin1String(".jui");
+ for (TMM::Iterator it = m_messages.begin(); it != m_messages.end(); ++it) {
+ QHash<QString, int> have;
+ QList<TranslatorMessage::Reference> refs;
+ foreach (const TranslatorMessage::Reference &itref, it->allReferences()) {
+ const QString &fn = itref.fileName();
+ if (fn.endsWith(uiXt) || fn.endsWith(juiXt)) {
+ if (++have[fn] == 1)
+ refs.append(TranslatorMessage::Reference(fn, -1));
+ } else {
+ refs.append(itref);
+ }
+ }
+ it->setReferences(refs);
+ }
+}
+
QSet<TranslatorMessagePtr> Translator::resolveDuplicates()
{
QSet<TranslatorMessagePtr> dups;
diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h
index 4e97000..5d0549b 100644
--- a/tools/linguist/shared/translator.h
+++ b/tools/linguist/shared/translator.h
@@ -132,6 +132,7 @@ public:
void stripNonPluralForms();
void stripIdenticalSourceTranslations();
void dropTranslations();
+ void dropUiLines();
void makeFileNamesAbsolute(const QDir &originalPath);
QSet<TranslatorMessagePtr> resolveDuplicates();
static void reportDuplicates(const QSet<TranslatorMessagePtr> &dupes,
@@ -143,7 +144,7 @@ public:
QString languageCode() const { return m_language; }
QString sourceLanguageCode() const { return m_sourceLanguage; }
- enum LocationsType { NoLocations, RelativeLocations, AbsoluteLocations };
+ enum LocationsType { DefaultLocations, NoLocations, RelativeLocations, AbsoluteLocations };
void setLocationsType(LocationsType lt) { m_locationsType = lt; }
LocationsType locationsType() const { return m_locationsType; }
diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp
index e271338..798cbb5 100644
--- a/tools/qdoc3/htmlgenerator.cpp
+++ b/tools/qdoc3/htmlgenerator.cpp
@@ -2202,7 +2202,7 @@ void HtmlGenerator::generateSectionList(const Section& section,
if (name_alignment) {
out() << "<tr><td class=\"memItemLeft\" "
- << "nowrap align=\"right\" valign=\"top\">";
+ << "align=\"right\" valign=\"top\">";
}
else {
if (twoColumn && i == (int) (section.members.count() + 1) / 2)
diff --git a/tools/qdoc3/test/classic.css b/tools/qdoc3/test/classic.css
index 8e9eb78..22f1668 100644
--- a/tools/qdoc3/test/classic.css
+++ b/tools/qdoc3/test/classic.css
@@ -1,9 +1,6 @@
BODY,H1,H2,H3,H4,H5,H6,P,CENTER,TD,TH,UL,DL,DIV {
font-family: Arial, Geneva, Helvetica, sans-serif;
}
-BODY,TD {
- font-size: 90%;
-}
H1 {
text-align: center;
font-size: 160%;
@@ -86,6 +83,7 @@ table td.memItemLeft {
border-left-style: none;
background-color: #FAFAFA;
font-size: 80%;
+ white-space: nowrap
}
table td.memItemRight {
padding: 1px 8px 0px 8px;