summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2012-08-17 13:23:19 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-20 12:20:55 +0200
commit806dda08d685bc5f9ed71dfe8b61f21848d48066 (patch)
treea63533a1c4a335ae17adc105abb0ae4e62e2f26e /examples/widgets
parent9f942014e31842b512c3198de035d041c59f54a9 (diff)
Moving .qdoc files under examples/widgets/doc
Updated those .qdoc files to refer to the new relative examples emplacement. Images and snippets to be moved later. Also grouped all widgets related examples under widgets. Change-Id: Ib29696e2d8948524537f53e8dda88f9ee26a597f Reviewed-by: J-P Nurmi <j-p.nurmi@nokia.com>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/animation/README8
-rw-r--r--examples/widgets/animation/animatedtiles/animatedtiles.desktop11
-rw-r--r--examples/widgets/animation/animatedtiles/animatedtiles.pro10
-rw-r--r--examples/widgets/animation/animatedtiles/animatedtiles.qrc11
-rw-r--r--examples/widgets/animation/animatedtiles/images/Time-For-Lunch-2.jpgbin0 -> 32471 bytes
-rw-r--r--examples/widgets/animation/animatedtiles/images/centered.pngbin0 -> 892 bytes
-rw-r--r--examples/widgets/animation/animatedtiles/images/ellipse.pngbin0 -> 10767 bytes
-rw-r--r--examples/widgets/animation/animatedtiles/images/figure8.pngbin0 -> 14050 bytes
-rw-r--r--examples/widgets/animation/animatedtiles/images/kinetic.pngbin0 -> 6776 bytes
-rw-r--r--examples/widgets/animation/animatedtiles/images/random.pngbin0 -> 14969 bytes
-rw-r--r--examples/widgets/animation/animatedtiles/images/tile.pngbin0 -> 16337 bytes
-rw-r--r--examples/widgets/animation/animatedtiles/main.cpp256
-rw-r--r--examples/widgets/animation/animation.pro17
-rw-r--r--examples/widgets/animation/appchooser/accessories-dictionary.pngbin0 -> 5396 bytes
-rw-r--r--examples/widgets/animation/appchooser/akregator.pngbin0 -> 4873 bytes
-rw-r--r--examples/widgets/animation/appchooser/appchooser.desktop11
-rw-r--r--examples/widgets/animation/appchooser/appchooser.pro10
-rw-r--r--examples/widgets/animation/appchooser/appchooser.qrc8
-rw-r--r--examples/widgets/animation/appchooser/digikam.pngbin0 -> 3334 bytes
-rw-r--r--examples/widgets/animation/appchooser/k3b.pngbin0 -> 8220 bytes
-rw-r--r--examples/widgets/animation/appchooser/main.cpp173
-rw-r--r--examples/widgets/animation/easing/animation.h100
-rw-r--r--examples/widgets/animation/easing/easing.desktop11
-rw-r--r--examples/widgets/animation/easing/easing.pro17
-rw-r--r--examples/widgets/animation/easing/easing.qrc5
-rw-r--r--examples/widgets/animation/easing/form.ui270
-rw-r--r--examples/widgets/animation/easing/images/qt-logo.pngbin0 -> 5149 bytes
-rw-r--r--examples/widgets/animation/easing/main.cpp54
-rw-r--r--examples/widgets/animation/easing/window.cpp177
-rw-r--r--examples/widgets/animation/easing/window.h76
-rw-r--r--examples/widgets/animation/moveblocks/main.cpp321
-rw-r--r--examples/widgets/animation/moveblocks/moveblocks.desktop11
-rw-r--r--examples/widgets/animation/moveblocks/moveblocks.pro9
-rw-r--r--examples/widgets/animation/states/accessories-dictionary.pngbin0 -> 5396 bytes
-rw-r--r--examples/widgets/animation/states/akregator.pngbin0 -> 4873 bytes
-rw-r--r--examples/widgets/animation/states/digikam.pngbin0 -> 3334 bytes
-rw-r--r--examples/widgets/animation/states/help-browser.pngbin0 -> 6984 bytes
-rw-r--r--examples/widgets/animation/states/k3b.pngbin0 -> 8220 bytes
-rw-r--r--examples/widgets/animation/states/kchart.pngbin0 -> 4887 bytes
-rw-r--r--examples/widgets/animation/states/main.cpp285
-rw-r--r--examples/widgets/animation/states/states.desktop11
-rw-r--r--examples/widgets/animation/states/states.pro10
-rw-r--r--examples/widgets/animation/states/states.qrc10
-rw-r--r--examples/widgets/animation/stickman/animation.cpp189
-rw-r--r--examples/widgets/animation/stickman/animation.h82
-rw-r--r--examples/widgets/animation/stickman/animations/chilling.binbin0 -> 6508 bytes
-rw-r--r--examples/widgets/animation/stickman/animations/dancing.binbin0 -> 2348 bytes
-rw-r--r--examples/widgets/animation/stickman/animations/dead.binbin0 -> 268 bytes
-rw-r--r--examples/widgets/animation/stickman/animations/jumping.binbin0 -> 1308 bytes
-rw-r--r--examples/widgets/animation/stickman/graphicsview.cpp60
-rw-r--r--examples/widgets/animation/stickman/graphicsview.h64
-rw-r--r--examples/widgets/animation/stickman/lifecycle.cpp217
-rw-r--r--examples/widgets/animation/stickman/lifecycle.h80
-rw-r--r--examples/widgets/animation/stickman/main.cpp106
-rw-r--r--examples/widgets/animation/stickman/node.cpp92
-rw-r--r--examples/widgets/animation/stickman/node.h70
-rw-r--r--examples/widgets/animation/stickman/rectbutton.cpp73
-rw-r--r--examples/widgets/animation/stickman/rectbutton.h65
-rw-r--r--examples/widgets/animation/stickman/stickman.cpp337
-rw-r--r--examples/widgets/animation/stickman/stickman.desktop11
-rw-r--r--examples/widgets/animation/stickman/stickman.h103
-rw-r--r--examples/widgets/animation/stickman/stickman.pro23
-rw-r--r--examples/widgets/animation/stickman/stickman.qrc8
-rw-r--r--examples/widgets/animation/sub-attaq/animationmanager.cpp98
-rw-r--r--examples/widgets/animation/sub-attaq/animationmanager.h73
-rw-r--r--examples/widgets/animation/sub-attaq/boat.cpp272
-rw-r--r--examples/widgets/animation/sub-attaq/boat.h95
-rw-r--r--examples/widgets/animation/sub-attaq/boat_p.h232
-rw-r--r--examples/widgets/animation/sub-attaq/bomb.cpp118
-rw-r--r--examples/widgets/animation/sub-attaq/bomb.h67
-rw-r--r--examples/widgets/animation/sub-attaq/data.xml39
-rw-r--r--examples/widgets/animation/sub-attaq/graphicsscene.cpp282
-rw-r--r--examples/widgets/animation/sub-attaq/graphicsscene.h122
-rw-r--r--examples/widgets/animation/sub-attaq/main.cpp57
-rw-r--r--examples/widgets/animation/sub-attaq/mainwindow.cpp82
-rw-r--r--examples/widgets/animation/sub-attaq/mainwindow.h63
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/background.pngbin0 -> 48858 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/boat.pngbin0 -> 5198 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/bomb.pngbin0 -> 760 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step1.pngbin0 -> 5760 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step2.pngbin0 -> 9976 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step3.pngbin0 -> 12411 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step4.pngbin0 -> 15438 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step1.pngbin0 -> 3354 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step2.pngbin0 -> 6205 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step3.pngbin0 -> 6678 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step4.pngbin0 -> 6666 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/submarine.pngbin0 -> 3202 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/surface.pngbin0 -> 575 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/big/torpedo.pngbin0 -> 951 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/scalable/background-n810.svg171
-rw-r--r--examples/widgets/animation/sub-attaq/pics/scalable/background.svg171
-rw-r--r--examples/widgets/animation/sub-attaq/pics/scalable/boat.svg279
-rw-r--r--examples/widgets/animation/sub-attaq/pics/scalable/bomb.svg138
-rw-r--r--examples/widgets/animation/sub-attaq/pics/scalable/sand.svg103
-rw-r--r--examples/widgets/animation/sub-attaq/pics/scalable/see.svg44
-rw-r--r--examples/widgets/animation/sub-attaq/pics/scalable/sky.svg45
-rw-r--r--examples/widgets/animation/sub-attaq/pics/scalable/sub-attaq.svg1473
-rw-r--r--examples/widgets/animation/sub-attaq/pics/scalable/submarine.svg214
-rw-r--r--examples/widgets/animation/sub-attaq/pics/scalable/surface.svg49
-rw-r--r--examples/widgets/animation/sub-attaq/pics/scalable/torpedo.svg127
-rw-r--r--examples/widgets/animation/sub-attaq/pics/small/background.pngbin0 -> 34634 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/small/boat.pngbin0 -> 2394 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/small/bomb.pngbin0 -> 760 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/small/submarine.pngbin0 -> 1338 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/small/surface.pngbin0 -> 502 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/small/torpedo.pngbin0 -> 951 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/welcome/logo-a.pngbin0 -> 5972 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/welcome/logo-a2.pngbin0 -> 5969 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/welcome/logo-b.pngbin0 -> 6869 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/welcome/logo-dash.pngbin0 -> 2255 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/welcome/logo-excl.pngbin0 -> 2740 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/welcome/logo-q.pngbin0 -> 7016 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/welcome/logo-s.pngbin0 -> 5817 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/welcome/logo-t.pngbin0 -> 3717 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/welcome/logo-t2.pngbin0 -> 3688 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pics/welcome/logo-u.pngbin0 -> 5374 bytes
-rw-r--r--examples/widgets/animation/sub-attaq/pixmapitem.cpp76
-rw-r--r--examples/widgets/animation/sub-attaq/pixmapitem.h63
-rw-r--r--examples/widgets/animation/sub-attaq/progressitem.cpp67
-rw-r--r--examples/widgets/animation/sub-attaq/progressitem.h61
-rw-r--r--examples/widgets/animation/sub-attaq/qanimationstate.cpp150
-rw-r--r--examples/widgets/animation/sub-attaq/qanimationstate.h91
-rw-r--r--examples/widgets/animation/sub-attaq/states.cpp330
-rw-r--r--examples/widgets/animation/sub-attaq/states.h180
-rw-r--r--examples/widgets/animation/sub-attaq/sub-attaq.pro42
-rw-r--r--examples/widgets/animation/sub-attaq/subattaq.qrc39
-rw-r--r--examples/widgets/animation/sub-attaq/submarine.cpp182
-rw-r--r--examples/widgets/animation/sub-attaq/submarine.h93
-rw-r--r--examples/widgets/animation/sub-attaq/submarine_p.h137
-rw-r--r--examples/widgets/animation/sub-attaq/textinformationitem.cpp54
-rw-r--r--examples/widgets/animation/sub-attaq/textinformationitem.h55
-rw-r--r--examples/widgets/animation/sub-attaq/torpedo.cpp114
-rw-r--r--examples/widgets/animation/sub-attaq/torpedo.h67
-rw-r--r--examples/widgets/desktop/README10
-rw-r--r--examples/widgets/desktop/desktop.pro11
-rw-r--r--examples/widgets/desktop/screenshot/main.cpp51
-rw-r--r--examples/widgets/desktop/screenshot/screenshot.cpp199
-rw-r--r--examples/widgets/desktop/screenshot/screenshot.desktop11
-rw-r--r--examples/widgets/desktop/screenshot/screenshot.h99
-rw-r--r--examples/widgets/desktop/screenshot/screenshot.pro12
-rw-r--r--examples/widgets/desktop/systray/images/bad.pngbin0 -> 2496 bytes
-rw-r--r--examples/widgets/desktop/systray/images/heart.pngbin0 -> 25780 bytes
-rw-r--r--examples/widgets/desktop/systray/images/trash.pngbin0 -> 12128 bytes
-rw-r--r--examples/widgets/desktop/systray/main.cpp63
-rw-r--r--examples/widgets/desktop/systray/systray.desktop11
-rw-r--r--examples/widgets/desktop/systray/systray.pro14
-rw-r--r--examples/widgets/desktop/systray/systray.qrc7
-rw-r--r--examples/widgets/desktop/systray/window.cpp270
-rw-r--r--examples/widgets/desktop/systray/window.h112
-rw-r--r--examples/widgets/dialogs/README9
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.cpp430
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.desktop11
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.h156
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.pro13
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.qrc11
-rw-r--r--examples/widgets/dialogs/classwizard/images/background.pngbin0 -> 22578 bytes
-rw-r--r--examples/widgets/dialogs/classwizard/images/banner.pngbin0 -> 3947 bytes
-rw-r--r--examples/widgets/dialogs/classwizard/images/logo1.pngbin0 -> 1619 bytes
-rw-r--r--examples/widgets/dialogs/classwizard/images/logo2.pngbin0 -> 1619 bytes
-rw-r--r--examples/widgets/dialogs/classwizard/images/logo3.pngbin0 -> 1619 bytes
-rw-r--r--examples/widgets/dialogs/classwizard/images/watermark1.pngbin0 -> 14516 bytes
-rw-r--r--examples/widgets/dialogs/classwizard/images/watermark2.pngbin0 -> 14912 bytes
-rw-r--r--examples/widgets/dialogs/classwizard/main.cpp63
-rw-r--r--examples/widgets/dialogs/configdialog/configdialog.cpp116
-rw-r--r--examples/widgets/dialogs/configdialog/configdialog.desktop11
-rw-r--r--examples/widgets/dialogs/configdialog/configdialog.h69
-rw-r--r--examples/widgets/dialogs/configdialog/configdialog.pro17
-rw-r--r--examples/widgets/dialogs/configdialog/configdialog.qrc7
-rw-r--r--examples/widgets/dialogs/configdialog/images/config.pngbin0 -> 6758 bytes
-rw-r--r--examples/widgets/dialogs/configdialog/images/query.pngbin0 -> 2116 bytes
-rw-r--r--examples/widgets/dialogs/configdialog/images/update.pngbin0 -> 7890 bytes
-rw-r--r--examples/widgets/dialogs/configdialog/main.cpp52
-rw-r--r--examples/widgets/dialogs/configdialog/pages.cpp151
-rw-r--r--examples/widgets/dialogs/configdialog/pages.h64
-rw-r--r--examples/widgets/dialogs/dialogs.pro19
-rw-r--r--examples/widgets/dialogs/extension/extension.desktop11
-rw-r--r--examples/widgets/dialogs/extension/extension.pro12
-rw-r--r--examples/widgets/dialogs/extension/finddialog.cpp114
-rw-r--r--examples/widgets/dialogs/extension/finddialog.h78
-rw-r--r--examples/widgets/dialogs/extension/main.cpp53
-rw-r--r--examples/widgets/dialogs/findfiles/findfiles.desktop11
-rw-r--r--examples/widgets/dialogs/findfiles/findfiles.pro11
-rw-r--r--examples/widgets/dialogs/findfiles/main.cpp (renamed from examples/widgets/groupbox/main.cpp)0
-rw-r--r--examples/widgets/dialogs/findfiles/window.cpp247
-rw-r--r--examples/widgets/dialogs/findfiles/window.h90
-rw-r--r--examples/widgets/dialogs/licensewizard/images/logo.pngbin0 -> 1810 bytes
-rw-r--r--examples/widgets/dialogs/licensewizard/images/watermark.pngbin0 -> 34998 bytes
-rw-r--r--examples/widgets/dialogs/licensewizard/licensewizard.cpp363
-rw-r--r--examples/widgets/dialogs/licensewizard/licensewizard.desktop11
-rw-r--r--examples/widgets/dialogs/licensewizard/licensewizard.h163
-rw-r--r--examples/widgets/dialogs/licensewizard/licensewizard.pro13
-rw-r--r--examples/widgets/dialogs/licensewizard/licensewizard.qrc6
-rw-r--r--examples/widgets/dialogs/licensewizard/main.cpp63
-rw-r--r--examples/widgets/dialogs/sipdialog/dialog.cpp122
-rw-r--r--examples/widgets/dialogs/sipdialog/dialog.h63
-rw-r--r--examples/widgets/dialogs/sipdialog/main.cpp52
-rw-r--r--examples/widgets/dialogs/sipdialog/sipdialog.desktop11
-rw-r--r--examples/widgets/dialogs/sipdialog/sipdialog.pro15
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.cpp471
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.h101
-rw-r--r--examples/widgets/dialogs/standarddialogs/main.cpp62
-rw-r--r--examples/widgets/dialogs/standarddialogs/standarddialogs.desktop11
-rw-r--r--examples/widgets/dialogs/standarddialogs/standarddialogs.pro13
-rw-r--r--examples/widgets/dialogs/tabdialog/main.cpp59
-rw-r--r--examples/widgets/dialogs/tabdialog/tabdialog.cpp196
-rw-r--r--examples/widgets/dialogs/tabdialog/tabdialog.desktop11
-rw-r--r--examples/widgets/dialogs/tabdialog/tabdialog.h99
-rw-r--r--examples/widgets/dialogs/tabdialog/tabdialog.pro12
-rw-r--r--examples/widgets/dialogs/trivialwizard/trivialwizard.cpp135
-rw-r--r--examples/widgets/dialogs/trivialwizard/trivialwizard.desktop11
-rw-r--r--examples/widgets/dialogs/trivialwizard/trivialwizard.pro10
-rw-r--r--examples/widgets/doc/addressbook.qdoc442
-rw-r--r--examples/widgets/doc/affine.qdoc48
-rw-r--r--examples/widgets/doc/analogclock.qdoc154
-rw-r--r--examples/widgets/doc/animatedtiles.qdoc36
-rw-r--r--examples/widgets/doc/appchooser.qdoc38
-rw-r--r--examples/widgets/doc/application.qdoc396
-rw-r--r--examples/widgets/doc/basicdrawing.qdoc454
-rw-r--r--examples/widgets/doc/basicgraphicslayouts.qdoc164
-rw-r--r--examples/widgets/doc/basiclayouts.qdoc190
-rw-r--r--examples/widgets/doc/basicsortfiltermodel.qdoc37
-rw-r--r--examples/widgets/doc/blurpicker.qdoc33
-rw-r--r--examples/widgets/doc/borderlayout.qdoc36
-rw-r--r--examples/widgets/doc/boxes.qdoc49
-rw-r--r--examples/widgets/doc/calculator.qdoc375
-rw-r--r--examples/widgets/doc/calendar.qdoc223
-rw-r--r--examples/widgets/doc/calendarwidget.qdoc291
-rw-r--r--examples/widgets/doc/charactermap.qdoc274
-rw-r--r--examples/widgets/doc/chart.qdoc82
-rw-r--r--examples/widgets/doc/chip.qdoc38
-rw-r--r--examples/widgets/doc/classwizard.qdoc190
-rw-r--r--examples/widgets/doc/codeeditor.qdoc197
-rw-r--r--examples/widgets/doc/coloreditorfactory.qdoc155
-rw-r--r--examples/widgets/doc/combowidgetmapper.qdoc167
-rw-r--r--examples/widgets/doc/composition.qdoc44
-rw-r--r--examples/widgets/doc/concentriccircles.qdoc231
-rw-r--r--examples/widgets/doc/configdialog.qdoc36
-rw-r--r--examples/widgets/doc/customsortfiltermodel.qdoc289
-rw-r--r--examples/widgets/doc/deform.qdoc51
-rw-r--r--examples/widgets/doc/diagramscene.qdoc834
-rw-r--r--examples/widgets/doc/digitalclock.qdoc74
-rw-r--r--examples/widgets/doc/dirview.qdoc36
-rw-r--r--examples/widgets/doc/dockwidgets.qdoc163
-rw-r--r--examples/widgets/doc/dragdroprobot.qdoc365
-rw-r--r--examples/widgets/doc/dynamiclayouts.qdoc34
-rw-r--r--examples/widgets/doc/easing.qdoc37
-rw-r--r--examples/widgets/doc/editabletreemodel.qdoc446
-rw-r--r--examples/widgets/doc/elasticnodes.qdoc430
-rw-r--r--examples/widgets/doc/elidedlabel.qdoc162
-rw-r--r--examples/widgets/doc/embeddeddialogs.qdoc37
-rw-r--r--examples/widgets/doc/eventtransitions.qdoc72
-rw-r--r--examples/widgets/doc/extension.qdoc138
-rw-r--r--examples/widgets/doc/factorial.qdoc88
-rw-r--r--examples/widgets/doc/fademessage.qdoc37
-rw-r--r--examples/widgets/doc/fetchmore.qdoc111
-rw-r--r--examples/widgets/doc/findfiles.qdoc249
-rw-r--r--examples/widgets/doc/flowlayout.qdoc145
-rw-r--r--examples/widgets/doc/fontsampler.qdoc35
-rw-r--r--examples/widgets/doc/frozencolumn.qdoc133
-rw-r--r--examples/widgets/doc/gradients.qdoc55
-rw-r--r--examples/widgets/doc/groupbox.qdoc140
-rw-r--r--examples/widgets/doc/icons.qdoc780
-rw-r--r--examples/widgets/doc/imagecomposition.qdoc165
-rw-r--r--examples/widgets/doc/imageviewer.qdoc326
-rw-r--r--examples/widgets/doc/interview.qdoc37
-rw-r--r--examples/widgets/doc/licensewizard.qdoc218
-rw-r--r--examples/widgets/doc/lighting.qdoc33
-rw-r--r--examples/widgets/doc/lineedits.qdoc161
-rw-r--r--examples/widgets/doc/mainwindow.qdoc36
-rw-r--r--examples/widgets/doc/mdi.qdoc37
-rw-r--r--examples/widgets/doc/menus.qdoc218
-rw-r--r--examples/widgets/doc/moveblocks.qdoc214
-rw-r--r--examples/widgets/doc/movie.qdoc39
-rw-r--r--examples/widgets/doc/orderform.qdoc364
-rw-r--r--examples/widgets/doc/padnavigator.qdoc583
-rw-r--r--examples/widgets/doc/painterpaths.qdoc418
-rw-r--r--examples/widgets/doc/pathstroke.qdoc47
-rw-r--r--examples/widgets/doc/pingpong.qdoc93
-rw-r--r--examples/widgets/doc/pixelator.qdoc255
-rw-r--r--examples/widgets/doc/recentfiles.qdoc36
-rw-r--r--examples/widgets/doc/rogue.qdoc208
-rw-r--r--examples/widgets/doc/screenshot.qdoc247
-rw-r--r--examples/widgets/doc/scribble.qdoc417
-rw-r--r--examples/widgets/doc/sdi.qdoc36
-rw-r--r--examples/widgets/doc/shapedclock.qdoc131
-rw-r--r--examples/widgets/doc/simpledommodel.qdoc280
-rw-r--r--examples/widgets/doc/simpletreemodel.qdoc333
-rw-r--r--examples/widgets/doc/simplewidgetmapper.qdoc125
-rw-r--r--examples/widgets/doc/sipdialog.qdoc127
-rw-r--r--examples/widgets/doc/sliders.qdoc255
-rw-r--r--examples/widgets/doc/spinboxdelegate.qdoc141
-rw-r--r--examples/widgets/doc/spinboxes.qdoc191
-rw-r--r--examples/widgets/doc/spreadsheet.qdoc37
-rw-r--r--examples/widgets/doc/standarddialogs.qdoc35
-rw-r--r--examples/widgets/doc/stardelegate.qdoc296
-rw-r--r--examples/widgets/doc/states.qdoc36
-rw-r--r--examples/widgets/doc/stickman.qdoc102
-rw-r--r--examples/widgets/doc/styles.qdoc472
-rw-r--r--examples/widgets/doc/stylesheet.qdoc36
-rw-r--r--examples/widgets/doc/sub-attaq.qdoc40
-rw-r--r--examples/widgets/doc/syntaxhighlighter.qdoc252
-rw-r--r--examples/widgets/doc/tabdialog.qdoc134
-rw-r--r--examples/widgets/doc/tablet.qdoc369
-rw-r--r--examples/widgets/doc/tetrix.qdoc431
-rw-r--r--examples/widgets/doc/textedit.qdoc36
-rw-r--r--examples/widgets/doc/tooltips.qdoc394
-rw-r--r--examples/widgets/doc/trafficlight.qdoc85
-rw-r--r--examples/widgets/doc/transformations.qdoc371
-rw-r--r--examples/widgets/doc/trivialwizard.qdoc82
-rw-r--r--examples/widgets/doc/twowaybutton.qdoc68
-rw-r--r--examples/widgets/doc/wiggly.qdoc167
-rw-r--r--examples/widgets/doc/windowflags.qdoc216
-rw-r--r--examples/widgets/draganddrop/README9
-rw-r--r--examples/widgets/draganddrop/delayedencoding/delayedencoding.desktop11
-rw-r--r--examples/widgets/draganddrop/draganddrop.pro13
-rw-r--r--examples/widgets/draganddrop/draggableicons/draggableicons.desktop11
-rw-r--r--examples/widgets/draganddrop/draggableicons/draggableicons.pro12
-rw-r--r--examples/widgets/draganddrop/draggableicons/draggableicons.qrc7
-rw-r--r--examples/widgets/draganddrop/draggableicons/dragwidget.cpp168
-rw-r--r--examples/widgets/draganddrop/draggableicons/dragwidget.h65
-rw-r--r--examples/widgets/draganddrop/draggableicons/images/boat.pngbin0 -> 2772 bytes
-rw-r--r--examples/widgets/draganddrop/draggableicons/images/car.pngbin0 -> 2963 bytes
-rw-r--r--examples/widgets/draganddrop/draggableicons/images/house.pngbin0 -> 3292 bytes
-rw-r--r--examples/widgets/draganddrop/draggableicons/main.cpp61
-rw-r--r--examples/widgets/draganddrop/draggabletext/draggabletext.desktop11
-rw-r--r--examples/widgets/draganddrop/draggabletext/draggabletext.pro15
-rw-r--r--examples/widgets/draganddrop/draggabletext/draggabletext.qrc5
-rw-r--r--examples/widgets/draganddrop/draggabletext/draglabel.cpp51
-rw-r--r--examples/widgets/draganddrop/draggabletext/draglabel.h58
-rw-r--r--examples/widgets/draganddrop/draggabletext/dragwidget.cpp165
-rw-r--r--examples/widgets/draganddrop/draggabletext/dragwidget.h62
-rw-r--r--examples/widgets/draganddrop/draggabletext/main.cpp52
-rw-r--r--examples/widgets/draganddrop/draggabletext/words.txt41
-rw-r--r--examples/widgets/draganddrop/dropsite/droparea.cpp126
-rw-r--r--examples/widgets/draganddrop/dropsite/droparea.h77
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsite.desktop11
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsite.pro14
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.cpp143
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.h77
-rw-r--r--examples/widgets/draganddrop/dropsite/main.cpp53
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/draglabel.cpp89
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/draglabel.h64
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp212
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/dragwidget.h65
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/fridgemagnets.desktop11
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro15
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc5
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/main.cpp61
-rw-r--r--examples/widgets/draganddrop/fridgemagnets/words.txt48
-rw-r--r--examples/widgets/draganddrop/puzzle/example.jpgbin0 -> 42654 bytes
-rw-r--r--examples/widgets/draganddrop/puzzle/main.cpp54
-rw-r--r--examples/widgets/draganddrop/puzzle/mainwindow.cpp152
-rw-r--r--examples/widgets/draganddrop/puzzle/mainwindow.h76
-rw-r--r--examples/widgets/draganddrop/puzzle/pieceslist.cpp121
-rw-r--r--examples/widgets/draganddrop/puzzle/pieceslist.h63
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzle.desktop11
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzle.pro23
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzle.qrc5
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzlewidget.cpp214
-rw-r--r--examples/widgets/draganddrop/puzzle/puzzlewidget.h89
-rw-r--r--examples/widgets/effects/blurpicker/blureffect.cpp68
-rw-r--r--examples/widgets/effects/blurpicker/blureffect.h66
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.cpp161
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.desktop11
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.h75
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.pro11
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.qrc14
-rw-r--r--examples/widgets/effects/blurpicker/images/README.txt5
-rw-r--r--examples/widgets/effects/blurpicker/images/accessories-calculator.pngbin0 -> 3760 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/accessories-text-editor.pngbin0 -> 4746 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/background.jpgbin0 -> 16259 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/help-browser.pngbin0 -> 5392 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/internet-group-chat.pngbin0 -> 2809 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/internet-mail.pngbin0 -> 3899 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/internet-web-browser.pngbin0 -> 6376 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/office-calendar.pngbin0 -> 4010 bytes
-rw-r--r--examples/widgets/effects/blurpicker/images/system-users.pngbin0 -> 5353 bytes
-rw-r--r--examples/widgets/effects/blurpicker/main.cpp55
-rw-r--r--examples/widgets/effects/effects.pro14
-rw-r--r--examples/widgets/effects/fademessage/README.txt2
-rw-r--r--examples/widgets/effects/fademessage/background.jpgbin0 -> 159108 bytes
-rw-r--r--examples/widgets/effects/fademessage/fademessage.cpp128
-rw-r--r--examples/widgets/effects/fademessage/fademessage.desktop11
-rw-r--r--examples/widgets/effects/fademessage/fademessage.h70
-rw-r--r--examples/widgets/effects/fademessage/fademessage.pro18
-rw-r--r--examples/widgets/effects/fademessage/fademessage.qrc5
-rw-r--r--examples/widgets/effects/fademessage/main.cpp55
-rw-r--r--examples/widgets/effects/lighting/lighting.cpp139
-rw-r--r--examples/widgets/effects/lighting/lighting.desktop11
-rw-r--r--examples/widgets/effects/lighting/lighting.h70
-rw-r--r--examples/widgets/effects/lighting/lighting.pro11
-rw-r--r--examples/widgets/effects/lighting/main.cpp55
-rw-r--r--examples/widgets/graphicsview/README9
-rw-r--r--examples/widgets/graphicsview/anchorlayout/anchorlayout.desktop11
-rw-r--r--examples/widgets/graphicsview/anchorlayout/anchorlayout.pro13
-rw-r--r--examples/widgets/graphicsview/anchorlayout/main.cpp129
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.desktop11
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro14
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.qrc5
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/images/block.pngbin0 -> 2146 bytes
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp130
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h65
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/main.cpp58
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/window.cpp90
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/window.h57
-rw-r--r--examples/widgets/graphicsview/boxes/3rdparty/fbm.c207
-rw-r--r--examples/widgets/graphicsview/boxes/3rdparty/fbm.h40
-rw-r--r--examples/widgets/graphicsview/boxes/basic.fsh73
-rw-r--r--examples/widgets/graphicsview/boxes/basic.vsh61
-rw-r--r--examples/widgets/graphicsview/boxes/boxes.pro39
-rw-r--r--examples/widgets/graphicsview/boxes/boxes.qrc25
-rw-r--r--examples/widgets/graphicsview/boxes/cubemap_negx.jpgbin0 -> 41060 bytes
-rw-r--r--examples/widgets/graphicsview/boxes/cubemap_negy.jpgbin0 -> 15520 bytes
-rw-r--r--examples/widgets/graphicsview/boxes/cubemap_negz.jpgbin0 -> 68911 bytes
-rw-r--r--examples/widgets/graphicsview/boxes/cubemap_posx.jpgbin0 -> 74915 bytes
-rw-r--r--examples/widgets/graphicsview/boxes/cubemap_posy.jpgbin0 -> 24193 bytes
-rw-r--r--examples/widgets/graphicsview/boxes/cubemap_posz.jpgbin0 -> 57881 bytes
-rw-r--r--examples/widgets/graphicsview/boxes/dotted.fsh66
-rw-r--r--examples/widgets/graphicsview/boxes/fresnel.fsh79
-rw-r--r--examples/widgets/graphicsview/boxes/glass.fsh76
-rw-r--r--examples/widgets/graphicsview/boxes/glbuffers.cpp402
-rw-r--r--examples/widgets/graphicsview/boxes/glbuffers.h366
-rw-r--r--examples/widgets/graphicsview/boxes/glextensions.cpp98
-rw-r--r--examples/widgets/graphicsview/boxes/glextensions.h202
-rw-r--r--examples/widgets/graphicsview/boxes/gltrianglemesh.h91
-rw-r--r--examples/widgets/graphicsview/boxes/granite.fsh76
-rw-r--r--examples/widgets/graphicsview/boxes/main.cpp150
-rw-r--r--examples/widgets/graphicsview/boxes/marble.fsh71
-rw-r--r--examples/widgets/graphicsview/boxes/parameters.par5
-rw-r--r--examples/widgets/graphicsview/boxes/qt-logo.jpgbin0 -> 40886 bytes
-rw-r--r--examples/widgets/graphicsview/boxes/qt-logo.pngbin0 -> 13923 bytes
-rw-r--r--examples/widgets/graphicsview/boxes/qtbox.cpp480
-rw-r--r--examples/widgets/graphicsview/boxes/qtbox.h118
-rw-r--r--examples/widgets/graphicsview/boxes/reflection.fsh54
-rw-r--r--examples/widgets/graphicsview/boxes/refraction.fsh70
-rw-r--r--examples/widgets/graphicsview/boxes/roundedbox.cpp161
-rw-r--r--examples/widgets/graphicsview/boxes/roundedbox.h72
-rw-r--r--examples/widgets/graphicsview/boxes/scene.cpp1085
-rw-r--r--examples/widgets/graphicsview/boxes/scene.h245
-rw-r--r--examples/widgets/graphicsview/boxes/smiley.pngbin0 -> 14508 bytes
-rw-r--r--examples/widgets/graphicsview/boxes/square.jpgbin0 -> 14542 bytes
-rw-r--r--examples/widgets/graphicsview/boxes/trackball.cpp160
-rw-r--r--examples/widgets/graphicsview/boxes/trackball.h79
-rw-r--r--examples/widgets/graphicsview/boxes/wood.fsh70
-rw-r--r--examples/widgets/graphicsview/chip/chip.cpp183
-rw-r--r--examples/widgets/graphicsview/chip/chip.h68
-rw-r--r--examples/widgets/graphicsview/chip/chip.pro21
-rw-r--r--examples/widgets/graphicsview/chip/fileprint.pngbin0 -> 1456 bytes
-rw-r--r--examples/widgets/graphicsview/chip/images.qrc10
-rw-r--r--examples/widgets/graphicsview/chip/main.cpp57
-rw-r--r--examples/widgets/graphicsview/chip/mainwindow.cpp109
-rw-r--r--examples/widgets/graphicsview/chip/mainwindow.h68
-rw-r--r--examples/widgets/graphicsview/chip/qt4logo.pngbin0 -> 48333 bytes
-rw-r--r--examples/widgets/graphicsview/chip/rotateleft.pngbin0 -> 1754 bytes
-rw-r--r--examples/widgets/graphicsview/chip/rotateright.pngbin0 -> 1732 bytes
-rw-r--r--examples/widgets/graphicsview/chip/view.cpp279
-rw-r--r--examples/widgets/graphicsview/chip/view.h104
-rw-r--r--examples/widgets/graphicsview/chip/zoomin.pngbin0 -> 1622 bytes
-rw-r--r--examples/widgets/graphicsview/chip/zoomout.pngbin0 -> 1601 bytes
-rw-r--r--examples/widgets/graphicsview/collidingmice/collidingmice.desktop11
-rw-r--r--examples/widgets/graphicsview/collidingmice/collidingmice.pro17
-rw-r--r--examples/widgets/graphicsview/collidingmice/images/cheese.jpgbin0 -> 3029 bytes
-rw-r--r--examples/widgets/graphicsview/collidingmice/main.cpp91
-rw-r--r--examples/widgets/graphicsview/collidingmice/mice.qrc5
-rw-r--r--examples/widgets/graphicsview/collidingmice/mouse.cpp200
-rw-r--r--examples/widgets/graphicsview/collidingmice/mouse.h68
-rw-r--r--examples/widgets/graphicsview/diagramscene/arrow.cpp145
-rw-r--r--examples/widgets/graphicsview/diagramscene/arrow.h91
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramitem.cpp152
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramitem.h96
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.cpp240
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.desktop11
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.h112
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.pro23
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.qrc20
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramtextitem.cpp81
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramtextitem.h78
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/background1.pngbin0 -> 112 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/background2.pngbin0 -> 114 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/background3.pngbin0 -> 116 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/background4.pngbin0 -> 96 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/bold.pngbin0 -> 274 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/bringtofront.pngbin0 -> 293 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/delete.pngbin0 -> 831 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/floodfill.pngbin0 -> 282 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/italic.pngbin0 -> 247 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/linecolor.pngbin0 -> 145 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/linepointer.pngbin0 -> 141 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/pointer.pngbin0 -> 173 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/sendtoback.pngbin0 -> 318 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/textpointer.pngbin0 -> 753 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/images/underline.pngbin0 -> 250 bytes
-rw-r--r--examples/widgets/graphicsview/diagramscene/main.cpp55
-rw-r--r--examples/widgets/graphicsview/diagramscene/mainwindow.cpp661
-rw-r--r--examples/widgets/graphicsview/diagramscene/mainwindow.h150
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/coloritem.cpp142
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/coloritem.h65
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/dragdroprobot.desktop11
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/dragdroprobot.pro22
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/images/head.pngbin0 -> 14972 bytes
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/main.cpp94
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/robot.cpp307
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/robot.h118
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/robot.qrc5
-rw-r--r--examples/widgets/graphicsview/elasticnodes/edge.cpp149
-rw-r--r--examples/widgets/graphicsview/elasticnodes/edge.h75
-rw-r--r--examples/widgets/graphicsview/elasticnodes/elasticnodes.desktop11
-rw-r--r--examples/widgets/graphicsview/elasticnodes/elasticnodes.pro20
-rw-r--r--examples/widgets/graphicsview/elasticnodes/graphwidget.cpp250
-rw-r--r--examples/widgets/graphicsview/elasticnodes/graphwidget.h77
-rw-r--r--examples/widgets/graphicsview/elasticnodes/main.cpp57
-rw-r--r--examples/widgets/graphicsview/elasticnodes/node.cpp212
-rw-r--r--examples/widgets/graphicsview/elasticnodes/node.h85
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpgbin0 -> 30730 bytes
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp167
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.h76
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp106
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h66
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui87
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro19
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc5
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/main.cpp83
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.cpp213
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.desktop11
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.h76
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.pro14
-rw-r--r--examples/widgets/graphicsview/flowlayout/main.cpp57
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.cpp62
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.h47
-rw-r--r--examples/widgets/graphicsview/graphicsview.pro28
-rw-r--r--examples/widgets/graphicsview/padnavigator/flippablepad.cpp98
-rw-r--r--examples/widgets/graphicsview/padnavigator/flippablepad.h63
-rw-r--r--examples/widgets/graphicsview/padnavigator/form.ui208
-rw-r--r--examples/widgets/graphicsview/padnavigator/images/artsfftscope.pngbin0 -> 1291 bytes
-rw-r--r--examples/widgets/graphicsview/padnavigator/images/blue_angle_swirl.jpgbin0 -> 11826 bytes
-rw-r--r--examples/widgets/graphicsview/padnavigator/images/kontact_contacts.pngbin0 -> 4382 bytes
-rw-r--r--examples/widgets/graphicsview/padnavigator/images/kontact_journal.pngbin0 -> 3261 bytes
-rw-r--r--examples/widgets/graphicsview/padnavigator/images/kontact_mail.pngbin0 -> 3202 bytes
-rw-r--r--examples/widgets/graphicsview/padnavigator/images/kontact_notes.pngbin0 -> 3893 bytes
-rw-r--r--examples/widgets/graphicsview/padnavigator/images/kopeteavailable.pngbin0 -> 2380 bytes
-rw-r--r--examples/widgets/graphicsview/padnavigator/images/metacontact_online.pngbin0 -> 2545 bytes
-rw-r--r--examples/widgets/graphicsview/padnavigator/images/minitools.pngbin0 -> 2087 bytes
-rw-r--r--examples/widgets/graphicsview/padnavigator/main.cpp55
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.cpp306
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.desktop11
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.h70
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.pro28
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.qrc13
-rw-r--r--examples/widgets/graphicsview/padnavigator/roundrectitem.cpp113
-rw-r--r--examples/widgets/graphicsview/padnavigator/roundrectitem.h75
-rw-r--r--examples/widgets/graphicsview/padnavigator/splashitem.cpp83
-rw-r--r--examples/widgets/graphicsview/padnavigator/splashitem.h61
-rw-r--r--examples/widgets/graphicsview/portedasteroids/portedasteroids.desktop11
-rw-r--r--examples/widgets/graphicsview/portedcanvas/portedcanvas.desktop11
-rw-r--r--examples/widgets/graphicsview/simpleanchorlayout/main.cpp134
-rw-r--r--examples/widgets/graphicsview/simpleanchorlayout/simpleanchorlayout.desktop11
-rw-r--r--examples/widgets/graphicsview/simpleanchorlayout/simpleanchorlayout.pro12
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/images/5days.jpgbin0 -> 5748 bytes
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/images/details.jpgbin0 -> 5323 bytes
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/images/place.jpgbin0 -> 62438 bytes
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/images/tabbar.jpgbin0 -> 849 bytes
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/images/title.jpgbin0 -> 3472 bytes
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/images/weather-few-clouds.pngbin0 -> 18976 bytes
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/main.cpp274
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.desktop11
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.pro12
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.qrc10
-rw-r--r--examples/widgets/itemviews/README8
-rw-r--r--examples/widgets/itemviews/addressbook/adddialog.cpp82
-rw-r--r--examples/widgets/itemviews/addressbook/adddialog.h71
-rw-r--r--examples/widgets/itemviews/addressbook/addressbook.desktop11
-rw-r--r--examples/widgets/itemviews/addressbook/addressbook.pro19
-rw-r--r--examples/widgets/itemviews/addressbook/addresswidget.cpp236
-rw-r--r--examples/widgets/itemviews/addressbook/addresswidget.h82
-rw-r--r--examples/widgets/itemviews/addressbook/main.cpp52
-rw-r--r--examples/widgets/itemviews/addressbook/mainwindow.cpp137
-rw-r--r--examples/widgets/itemviews/addressbook/mainwindow.h75
-rw-r--r--examples/widgets/itemviews/addressbook/newaddresstab.cpp77
-rw-r--r--examples/widgets/itemviews/addressbook/newaddresstab.h74
-rw-r--r--examples/widgets/itemviews/addressbook/tablemodel.cpp184
-rw-r--r--examples/widgets/itemviews/addressbook/tablemodel.h72
-rw-r--r--examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.desktop11
-rw-r--r--examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro12
-rw-r--r--examples/widgets/itemviews/basicsortfiltermodel/main.cpp93
-rw-r--r--examples/widgets/itemviews/basicsortfiltermodel/window.cpp157
-rw-r--r--examples/widgets/itemviews/basicsortfiltermodel/window.h88
-rw-r--r--examples/widgets/itemviews/chart/chart.desktop11
-rw-r--r--examples/widgets/itemviews/chart/chart.pro18
-rw-r--r--examples/widgets/itemviews/chart/chart.qrc5
-rw-r--r--examples/widgets/itemviews/chart/main.cpp53
-rw-r--r--examples/widgets/itemviews/chart/mainwindow.cpp172
-rw-r--r--examples/widgets/itemviews/chart/mainwindow.h72
-rw-r--r--examples/widgets/itemviews/chart/mydata.cht8
-rw-r--r--examples/widgets/itemviews/chart/pieview.cpp557
-rw-r--r--examples/widgets/itemviews/chart/pieview.h114
-rw-r--r--examples/widgets/itemviews/chart/qtdata.cht14
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.desktop11
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro14
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp76
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h69
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/main.cpp53
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/window.cpp94
-rw-r--r--examples/widgets/itemviews/coloreditorfactory/window.h57
-rw-r--r--examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.desktop11
-rw-r--r--examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.pro11
-rw-r--r--examples/widgets/itemviews/combowidgetmapper/main.cpp51
-rw-r--r--examples/widgets/itemviews/combowidgetmapper/window.cpp136
-rw-r--r--examples/widgets/itemviews/combowidgetmapper/window.h86
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.desktop11
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.pro14
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/main.cpp95
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp115
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.h73
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/window.cpp166
-rw-r--r--examples/widgets/itemviews/customsortfiltermodel/window.h90
-rw-r--r--examples/widgets/itemviews/dirview/dirview.desktop11
-rw-r--r--examples/widgets/itemviews/dirview/dirview.pro9
-rw-r--r--examples/widgets/itemviews/dirview/main.cpp62
-rw-r--r--examples/widgets/itemviews/editabletreemodel/default.txt40
-rw-r--r--examples/widgets/itemviews/editabletreemodel/editabletreemodel.desktop11
-rw-r--r--examples/widgets/itemviews/editabletreemodel/editabletreemodel.pro18
-rw-r--r--examples/widgets/itemviews/editabletreemodel/editabletreemodel.qrc5
-rw-r--r--examples/widgets/itemviews/editabletreemodel/main.cpp53
-rw-r--r--examples/widgets/itemviews/editabletreemodel/mainwindow.cpp181
-rw-r--r--examples/widgets/itemviews/editabletreemodel/mainwindow.h71
-rw-r--r--examples/widgets/itemviews/editabletreemodel/mainwindow.ui128
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treeitem.cpp179
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treeitem.h74
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treemodel.cpp288
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treemodel.h97
-rw-r--r--examples/widgets/itemviews/fetchmore/fetchmore.desktop11
-rw-r--r--examples/widgets/itemviews/fetchmore/fetchmore.pro13
-rw-r--r--examples/widgets/itemviews/fetchmore/filelistmodel.cpp116
-rw-r--r--examples/widgets/itemviews/fetchmore/filelistmodel.h75
-rw-r--r--examples/widgets/itemviews/fetchmore/main.cpp50
-rw-r--r--examples/widgets/itemviews/fetchmore/window.cpp81
-rw-r--r--examples/widgets/itemviews/fetchmore/window.h64
-rw-r--r--examples/widgets/itemviews/frozencolumn/freezetablewidget.cpp165
-rw-r--r--examples/widgets/itemviews/frozencolumn/freezetablewidget.h72
-rw-r--r--examples/widgets/itemviews/frozencolumn/frozencolumn.desktop11
-rw-r--r--examples/widgets/itemviews/frozencolumn/frozencolumn.pro11
-rw-r--r--examples/widgets/itemviews/frozencolumn/grades.qrc5
-rw-r--r--examples/widgets/itemviews/frozencolumn/grades.txt36
-rw-r--r--examples/widgets/itemviews/frozencolumn/main.cpp88
-rw-r--r--examples/widgets/itemviews/interview/README2
-rw-r--r--examples/widgets/itemviews/interview/images/folder.pngbin0 -> 3910 bytes
-rw-r--r--examples/widgets/itemviews/interview/images/interview.pngbin0 -> 174 bytes
-rw-r--r--examples/widgets/itemviews/interview/images/services.pngbin0 -> 3749 bytes
-rw-r--r--examples/widgets/itemviews/interview/interview.pro19
-rw-r--r--examples/widgets/itemviews/interview/interview.qrc7
-rw-r--r--examples/widgets/itemviews/interview/main.cpp95
-rw-r--r--examples/widgets/itemviews/interview/model.cpp147
-rw-r--r--examples/widgets/itemviews/interview/model.h90
-rw-r--r--examples/widgets/itemviews/itemviews.pro25
-rw-r--r--examples/widgets/itemviews/pixelator/imagemodel.cpp92
-rw-r--r--examples/widgets/itemviews/pixelator/imagemodel.h68
-rw-r--r--examples/widgets/itemviews/pixelator/images.qrc5
-rw-r--r--examples/widgets/itemviews/pixelator/images/qt.pngbin0 -> 656 bytes
-rw-r--r--examples/widgets/itemviews/pixelator/main.cpp54
-rw-r--r--examples/widgets/itemviews/pixelator/mainwindow.cpp248
-rw-r--r--examples/widgets/itemviews/pixelator/mainwindow.h74
-rw-r--r--examples/widgets/itemviews/pixelator/pixelator.desktop11
-rw-r--r--examples/widgets/itemviews/pixelator/pixelator.pro17
-rw-r--r--examples/widgets/itemviews/pixelator/pixeldelegate.cpp107
-rw-r--r--examples/widgets/itemviews/pixelator/pixeldelegate.h79
-rw-r--r--examples/widgets/itemviews/puzzle/example.jpgbin0 -> 42654 bytes
-rw-r--r--examples/widgets/itemviews/puzzle/main.cpp54
-rw-r--r--examples/widgets/itemviews/puzzle/mainwindow.cpp149
-rw-r--r--examples/widgets/itemviews/puzzle/mainwindow.h77
-rw-r--r--examples/widgets/itemviews/puzzle/piecesmodel.cpp203
-rw-r--r--examples/widgets/itemviews/puzzle/piecesmodel.h82
-rw-r--r--examples/widgets/itemviews/puzzle/puzzle.desktop11
-rw-r--r--examples/widgets/itemviews/puzzle/puzzle.pro22
-rw-r--r--examples/widgets/itemviews/puzzle/puzzle.qrc5
-rw-r--r--examples/widgets/itemviews/puzzle/puzzlewidget.cpp214
-rw-r--r--examples/widgets/itemviews/puzzle/puzzlewidget.h89
-rw-r--r--examples/widgets/itemviews/simpledommodel/domitem.cpp101
-rw-r--r--examples/widgets/itemviews/simpledommodel/domitem.h66
-rw-r--r--examples/widgets/itemviews/simpledommodel/dommodel.cpp189
-rw-r--r--examples/widgets/itemviews/simpledommodel/dommodel.h76
-rw-r--r--examples/widgets/itemviews/simpledommodel/main.cpp52
-rw-r--r--examples/widgets/itemviews/simpledommodel/mainwindow.cpp84
-rw-r--r--examples/widgets/itemviews/simpledommodel/mainwindow.h70
-rw-r--r--examples/widgets/itemviews/simpledommodel/simpledommodel.desktop11
-rw-r--r--examples/widgets/itemviews/simpledommodel/simpledommodel.pro16
-rw-r--r--examples/widgets/itemviews/simpletreemodel/default.txt40
-rw-r--r--examples/widgets/itemviews/simpletreemodel/main.cpp61
-rw-r--r--examples/widgets/itemviews/simpletreemodel/simpletreemodel.desktop11
-rw-r--r--examples/widgets/itemviews/simpletreemodel/simpletreemodel.pro15
-rw-r--r--examples/widgets/itemviews/simpletreemodel/simpletreemodel.qrc5
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treeitem.cpp116
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treeitem.h70
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treemodel.cpp218
-rw-r--r--examples/widgets/itemviews/simpletreemodel/treemodel.h76
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/main.cpp51
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.desktop11
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro11
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/window.cpp133
-rw-r--r--examples/widgets/itemviews/simplewidgetmapper/window.h84
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/delegate.cpp102
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/delegate.h70
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/main.cpp86
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.desktop11
-rw-r--r--examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro13
-rw-r--r--examples/widgets/itemviews/spreadsheet/images/interview.pngbin0 -> 174 bytes
-rw-r--r--examples/widgets/itemviews/spreadsheet/main.cpp55
-rw-r--r--examples/widgets/itemviews/spreadsheet/printview.cpp62
-rw-r--r--examples/widgets/itemviews/spreadsheet/printview.h63
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheet.cpp639
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheet.h124
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheet.pro23
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheet.qrc5
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp114
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h65
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp167
-rw-r--r--examples/widgets/itemviews/spreadsheet/spreadsheetitem.h73
-rw-r--r--examples/widgets/itemviews/stardelegate/main.cpp107
-rw-r--r--examples/widgets/itemviews/stardelegate/stardelegate.cpp129
-rw-r--r--examples/widgets/itemviews/stardelegate/stardelegate.desktop11
-rw-r--r--examples/widgets/itemviews/stardelegate/stardelegate.h69
-rw-r--r--examples/widgets/itemviews/stardelegate/stardelegate.pro17
-rw-r--r--examples/widgets/itemviews/stardelegate/stareditor.cpp98
-rw-r--r--examples/widgets/itemviews/stardelegate/stareditor.h77
-rw-r--r--examples/widgets/itemviews/stardelegate/starrating.cpp102
-rw-r--r--examples/widgets/itemviews/stardelegate/starrating.h76
-rw-r--r--examples/widgets/layouts/README10
-rw-r--r--examples/widgets/layouts/basiclayouts/basiclayouts.desktop11
-rw-r--r--examples/widgets/layouts/basiclayouts/basiclayouts.pro13
-rw-r--r--examples/widgets/layouts/basiclayouts/dialog.cpp149
-rw-r--r--examples/widgets/layouts/basiclayouts/dialog.h90
-rw-r--r--examples/widgets/layouts/basiclayouts/main.cpp52
-rw-r--r--examples/widgets/layouts/borderlayout/borderlayout.cpp213
-rw-r--r--examples/widgets/layouts/borderlayout/borderlayout.desktop11
-rw-r--r--examples/widgets/layouts/borderlayout/borderlayout.h88
-rw-r--r--examples/widgets/layouts/borderlayout/borderlayout.pro13
-rw-r--r--examples/widgets/layouts/borderlayout/main.cpp (renamed from examples/widgets/lineedits/main.cpp)0
-rw-r--r--examples/widgets/layouts/borderlayout/window.cpp68
-rw-r--r--examples/widgets/layouts/borderlayout/window.h61
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dialog.cpp169
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dialog.h91
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dynamiclayouts.desktop11
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro13
-rw-r--r--examples/widgets/layouts/dynamiclayouts/main.cpp51
-rw-r--r--examples/widgets/layouts/flowlayout/flowlayout.cpp213
-rw-r--r--examples/widgets/layouts/flowlayout/flowlayout.desktop11
-rw-r--r--examples/widgets/layouts/flowlayout/flowlayout.h78
-rw-r--r--examples/widgets/layouts/flowlayout/flowlayout.pro13
-rw-r--r--examples/widgets/layouts/flowlayout/main.cpp (renamed from examples/widgets/sliders/main.cpp)0
-rw-r--r--examples/widgets/layouts/flowlayout/window.cpp59
-rw-r--r--examples/widgets/layouts/flowlayout/window.h59
-rw-r--r--examples/widgets/layouts/layouts.pro12
-rw-r--r--examples/widgets/mainwindows/README9
-rw-r--r--examples/widgets/mainwindows/application/application.desktop11
-rw-r--r--examples/widgets/mainwindows/application/application.pro16
-rw-r--r--examples/widgets/mainwindows/application/application.qrc10
-rw-r--r--examples/widgets/mainwindows/application/images/copy.pngbin0 -> 1338 bytes
-rw-r--r--examples/widgets/mainwindows/application/images/cut.pngbin0 -> 1323 bytes
-rw-r--r--examples/widgets/mainwindows/application/images/new.pngbin0 -> 852 bytes
-rw-r--r--examples/widgets/mainwindows/application/images/open.pngbin0 -> 2073 bytes
-rw-r--r--examples/widgets/mainwindows/application/images/paste.pngbin0 -> 1645 bytes
-rw-r--r--examples/widgets/mainwindows/application/images/save.pngbin0 -> 1187 bytes
-rw-r--r--examples/widgets/mainwindows/application/main.cpp57
-rw-r--r--examples/widgets/mainwindows/application/mainwindow.cpp392
-rw-r--r--examples/widgets/mainwindows/application/mainwindow.h105
-rw-r--r--examples/widgets/mainwindows/dockwidgets/dockwidgets.desktop11
-rw-r--r--examples/widgets/mainwindows/dockwidgets/dockwidgets.pro15
-rw-r--r--examples/widgets/mainwindows/dockwidgets/dockwidgets.qrc8
-rw-r--r--examples/widgets/mainwindows/dockwidgets/images/new.pngbin0 -> 977 bytes
-rw-r--r--examples/widgets/mainwindows/dockwidgets/images/print.pngbin0 -> 1732 bytes
-rw-r--r--examples/widgets/mainwindows/dockwidgets/images/save.pngbin0 -> 1894 bytes
-rw-r--r--examples/widgets/mainwindows/dockwidgets/images/undo.pngbin0 -> 1768 bytes
-rw-r--r--examples/widgets/mainwindows/dockwidgets/main.cpp52
-rw-r--r--examples/widgets/mainwindows/dockwidgets/mainwindow.cpp345
-rw-r--r--examples/widgets/mainwindows/dockwidgets/mainwindow.h97
-rw-r--r--examples/widgets/mainwindows/mainwindow/colorswatch.cpp746
-rw-r--r--examples/widgets/mainwindows/mainwindow/colorswatch.h136
-rw-r--r--examples/widgets/mainwindows/mainwindow/main.cpp164
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.cpp509
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.h90
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.pro17
-rw-r--r--examples/widgets/mainwindows/mainwindow/mainwindow.qrc8
-rw-r--r--examples/widgets/mainwindows/mainwindow/qt.pngbin0 -> 2037 bytes
-rw-r--r--examples/widgets/mainwindows/mainwindow/titlebarCenter.pngbin0 -> 146 bytes
-rw-r--r--examples/widgets/mainwindows/mainwindow/titlebarLeft.pngbin0 -> 5148 bytes
-rw-r--r--examples/widgets/mainwindows/mainwindow/titlebarRight.pngbin0 -> 2704 bytes
-rw-r--r--examples/widgets/mainwindows/mainwindow/toolbar.cpp383
-rw-r--r--examples/widgets/mainwindows/mainwindow/toolbar.h118
-rw-r--r--examples/widgets/mainwindows/mainwindows.pro16
-rw-r--r--examples/widgets/mainwindows/mdi/images/copy.pngbin0 -> 1338 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/images/cut.pngbin0 -> 1323 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/images/new.pngbin0 -> 852 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/images/open.pngbin0 -> 2073 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/images/paste.pngbin0 -> 1645 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/images/save.pngbin0 -> 1187 bytes
-rw-r--r--examples/widgets/mainwindows/mdi/main.cpp53
-rw-r--r--examples/widgets/mainwindows/mdi/mainwindow.cpp411
-rw-r--r--examples/widgets/mainwindows/mdi/mainwindow.h122
-rw-r--r--examples/widgets/mainwindows/mdi/mdi.desktop11
-rw-r--r--examples/widgets/mainwindows/mdi/mdi.pro16
-rw-r--r--examples/widgets/mainwindows/mdi/mdi.qrc10
-rw-r--r--examples/widgets/mainwindows/mdi/mdichild.cpp175
-rw-r--r--examples/widgets/mainwindows/mdi/mdichild.h76
-rw-r--r--examples/widgets/mainwindows/menus/main.cpp (renamed from examples/widgets/charactermap/main.cpp)0
-rw-r--r--examples/widgets/mainwindows/menus/mainwindow.cpp370
-rw-r--r--examples/widgets/mainwindows/menus/mainwindow.h124
-rw-r--r--examples/widgets/mainwindows/menus/menus.desktop11
-rw-r--r--examples/widgets/mainwindows/menus/menus.pro11
-rw-r--r--examples/widgets/mainwindows/recentfiles/main.cpp53
-rw-r--r--examples/widgets/mainwindows/recentfiles/mainwindow.cpp251
-rw-r--r--examples/widgets/mainwindows/recentfiles/mainwindow.h96
-rw-r--r--examples/widgets/mainwindows/recentfiles/recentfiles.desktop11
-rw-r--r--examples/widgets/mainwindows/recentfiles/recentfiles.pro13
-rw-r--r--examples/widgets/mainwindows/sdi/images/copy.pngbin0 -> 1338 bytes
-rw-r--r--examples/widgets/mainwindows/sdi/images/cut.pngbin0 -> 1323 bytes
-rw-r--r--examples/widgets/mainwindows/sdi/images/new.pngbin0 -> 852 bytes
-rw-r--r--examples/widgets/mainwindows/sdi/images/open.pngbin0 -> 2073 bytes
-rw-r--r--examples/widgets/mainwindows/sdi/images/paste.pngbin0 -> 1645 bytes
-rw-r--r--examples/widgets/mainwindows/sdi/images/save.pngbin0 -> 1187 bytes
-rw-r--r--examples/widgets/mainwindows/sdi/main.cpp54
-rw-r--r--examples/widgets/mainwindows/sdi/mainwindow.cpp372
-rw-r--r--examples/widgets/mainwindows/sdi/mainwindow.h110
-rw-r--r--examples/widgets/mainwindows/sdi/sdi.desktop11
-rw-r--r--examples/widgets/mainwindows/sdi/sdi.pro14
-rw-r--r--examples/widgets/mainwindows/sdi/sdi.qrc10
-rw-r--r--examples/widgets/painting/README11
-rw-r--r--examples/widgets/painting/affine/affine.pro24
-rw-r--r--examples/widgets/painting/affine/affine.qrc7
-rw-r--r--examples/widgets/painting/affine/bg1.jpgbin0 -> 23771 bytes
-rw-r--r--examples/widgets/painting/affine/main.cpp65
-rw-r--r--examples/widgets/painting/affine/xform.cpp902
-rw-r--r--examples/widgets/painting/affine/xform.h141
-rw-r--r--examples/widgets/painting/affine/xform.html23
-rw-r--r--examples/widgets/painting/basicdrawing/basicdrawing.desktop11
-rw-r--r--examples/widgets/painting/basicdrawing/basicdrawing.pro14
-rw-r--r--examples/widgets/painting/basicdrawing/basicdrawing.qrc6
-rw-r--r--examples/widgets/painting/basicdrawing/images/brick.pngbin0 -> 767 bytes
-rw-r--r--examples/widgets/painting/basicdrawing/images/qt-logo.pngbin0 -> 3696 bytes
-rw-r--r--examples/widgets/painting/basicdrawing/main.cpp53
-rw-r--r--examples/widgets/painting/basicdrawing/renderarea.cpp207
-rw-r--r--examples/widgets/painting/basicdrawing/renderarea.h83
-rw-r--r--examples/widgets/painting/basicdrawing/window.cpp259
-rw-r--r--examples/widgets/painting/basicdrawing/window.h87
-rw-r--r--examples/widgets/painting/composition/composition.cpp522
-rw-r--r--examples/widgets/painting/composition/composition.h187
-rw-r--r--examples/widgets/painting/composition/composition.html23
-rw-r--r--examples/widgets/painting/composition/composition.pro29
-rw-r--r--examples/widgets/painting/composition/composition.qrc8
-rw-r--r--examples/widgets/painting/composition/flower.jpgbin0 -> 49616 bytes
-rw-r--r--examples/widgets/painting/composition/flower_alpha.jpgbin0 -> 67326 bytes
-rw-r--r--examples/widgets/painting/composition/main.cpp65
-rw-r--r--examples/widgets/painting/concentriccircles/circlewidget.cpp124
-rw-r--r--examples/widgets/painting/concentriccircles/circlewidget.h73
-rw-r--r--examples/widgets/painting/concentriccircles/concentriccircles.desktop11
-rw-r--r--examples/widgets/painting/concentriccircles/concentriccircles.pro14
-rw-r--r--examples/widgets/painting/concentriccircles/main.cpp (renamed from examples/widgets/spinboxes/main.cpp)0
-rw-r--r--examples/widgets/painting/concentriccircles/window.cpp93
-rw-r--r--examples/widgets/painting/concentriccircles/window.h70
-rw-r--r--examples/widgets/painting/deform/deform.pro20
-rw-r--r--examples/widgets/painting/deform/deform.qrc6
-rw-r--r--examples/widgets/painting/deform/main.cpp72
-rw-r--r--examples/widgets/painting/deform/pathdeform.cpp646
-rw-r--r--examples/widgets/painting/deform/pathdeform.h153
-rw-r--r--examples/widgets/painting/deform/pathdeform.html24
-rw-r--r--examples/widgets/painting/fontsampler/fontsampler.desktop11
-rw-r--r--examples/widgets/painting/fontsampler/fontsampler.pro13
-rw-r--r--examples/widgets/painting/fontsampler/main.cpp (renamed from examples/widgets/scribble/main.cpp)0
-rw-r--r--examples/widgets/painting/fontsampler/mainwindow.cpp380
-rw-r--r--examples/widgets/painting/fontsampler/mainwindow.h87
-rw-r--r--examples/widgets/painting/fontsampler/mainwindowbase.ui142
-rw-r--r--examples/widgets/painting/gradients/gradients.cpp516
-rw-r--r--examples/widgets/painting/gradients/gradients.h170
-rw-r--r--examples/widgets/painting/gradients/gradients.html31
-rw-r--r--examples/widgets/painting/gradients/gradients.pro20
-rw-r--r--examples/widgets/painting/gradients/gradients.qrc6
-rw-r--r--examples/widgets/painting/gradients/main.cpp63
-rw-r--r--examples/widgets/painting/imagecomposition/imagecomposer.cpp211
-rw-r--r--examples/widgets/painting/imagecomposition/imagecomposer.h87
-rw-r--r--examples/widgets/painting/imagecomposition/imagecomposition.desktop11
-rw-r--r--examples/widgets/painting/imagecomposition/imagecomposition.pro13
-rw-r--r--examples/widgets/painting/imagecomposition/imagecomposition.qrc6
-rw-r--r--examples/widgets/painting/imagecomposition/images/background.pngbin0 -> 18579 bytes
-rw-r--r--examples/widgets/painting/imagecomposition/images/blackrectangle.pngbin0 -> 90 bytes
-rw-r--r--examples/widgets/painting/imagecomposition/images/butterfly.pngbin0 -> 36868 bytes
-rw-r--r--examples/widgets/painting/imagecomposition/images/checker.pngbin0 -> 10384 bytes
-rw-r--r--examples/widgets/painting/imagecomposition/main.cpp55
-rw-r--r--examples/widgets/painting/painterpaths/main.cpp51
-rw-r--r--examples/widgets/painting/painterpaths/painterpaths.desktop11
-rw-r--r--examples/widgets/painting/painterpaths/painterpaths.pro15
-rw-r--r--examples/widgets/painting/painterpaths/renderarea.cpp130
-rw-r--r--examples/widgets/painting/painterpaths/renderarea.h80
-rw-r--r--examples/widgets/painting/painterpaths/window.cpp289
-rw-r--r--examples/widgets/painting/painterpaths/window.h90
-rw-r--r--examples/widgets/painting/painting.pro36
-rw-r--r--examples/widgets/painting/pathstroke/main.cpp71
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.cpp685
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.h171
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.html20
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.pro21
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.qrc6
-rw-r--r--examples/widgets/painting/shared/arthurstyle.cpp452
-rw-r--r--examples/widgets/painting/shared/arthurstyle.h79
-rw-r--r--examples/widgets/painting/shared/arthurwidgets.cpp355
-rw-r--r--examples/widgets/painting/shared/arthurwidgets.h137
-rw-r--r--examples/widgets/painting/shared/hoverpoints.cpp415
-rw-r--r--examples/widgets/painting/shared/hoverpoints.h162
-rw-r--r--examples/widgets/painting/shared/images/bg_pattern.pngbin0 -> 104 bytes
-rw-r--r--examples/widgets/painting/shared/images/button_normal_cap_left.pngbin0 -> 654 bytes
-rw-r--r--examples/widgets/painting/shared/images/button_normal_cap_right.pngbin0 -> 674 bytes
-rw-r--r--examples/widgets/painting/shared/images/button_normal_stretch.pngbin0 -> 185 bytes
-rw-r--r--examples/widgets/painting/shared/images/button_pressed_cap_left.pngbin0 -> 710 bytes
-rw-r--r--examples/widgets/painting/shared/images/button_pressed_cap_right.pngbin0 -> 785 bytes
-rw-r--r--examples/widgets/painting/shared/images/button_pressed_stretch.pngbin0 -> 217 bytes
-rw-r--r--examples/widgets/painting/shared/images/curve_thing_edit-6.pngbin0 -> 58097 bytes
-rw-r--r--examples/widgets/painting/shared/images/frame_bottom.pngbin0 -> 166 bytes
-rw-r--r--examples/widgets/painting/shared/images/frame_bottomleft.pngbin0 -> 602 bytes
-rw-r--r--examples/widgets/painting/shared/images/frame_bottomright.pngbin0 -> 553 bytes
-rw-r--r--examples/widgets/painting/shared/images/frame_left.pngbin0 -> 182 bytes
-rw-r--r--examples/widgets/painting/shared/images/frame_right.pngbin0 -> 175 bytes
-rw-r--r--examples/widgets/painting/shared/images/frame_top.pngbin0 -> 188 bytes
-rw-r--r--examples/widgets/painting/shared/images/frame_topleft.pngbin0 -> 801 bytes
-rw-r--r--examples/widgets/painting/shared/images/frame_topright.pngbin0 -> 851 bytes
-rw-r--r--examples/widgets/painting/shared/images/groupframe_bottom_left.pngbin0 -> 397 bytes
-rw-r--r--examples/widgets/painting/shared/images/groupframe_bottom_right.pngbin0 -> 383 bytes
-rw-r--r--examples/widgets/painting/shared/images/groupframe_bottom_stretch.pngbin0 -> 141 bytes
-rw-r--r--examples/widgets/painting/shared/images/groupframe_left_stretch.pngbin0 -> 132 bytes
-rw-r--r--examples/widgets/painting/shared/images/groupframe_right_stretch.pngbin0 -> 113 bytes
-rw-r--r--examples/widgets/painting/shared/images/groupframe_top_stretch.pngbin0 -> 115 bytes
-rw-r--r--examples/widgets/painting/shared/images/groupframe_topleft.pngbin0 -> 412 bytes
-rw-r--r--examples/widgets/painting/shared/images/groupframe_topright.pngbin0 -> 449 bytes
-rw-r--r--examples/widgets/painting/shared/images/line_dash_dot.pngbin0 -> 151 bytes
-rw-r--r--examples/widgets/painting/shared/images/line_dash_dot_dot.pngbin0 -> 155 bytes
-rw-r--r--examples/widgets/painting/shared/images/line_dashed.pngbin0 -> 121 bytes
-rw-r--r--examples/widgets/painting/shared/images/line_dotted.pngbin0 -> 116 bytes
-rw-r--r--examples/widgets/painting/shared/images/line_solid.pngbin0 -> 110 bytes
-rw-r--r--examples/widgets/painting/shared/images/radiobutton-off.pngbin0 -> 442 bytes
-rw-r--r--examples/widgets/painting/shared/images/radiobutton-on.pngbin0 -> 474 bytes
-rw-r--r--examples/widgets/painting/shared/images/radiobutton_off.pngbin0 -> 442 bytes
-rw-r--r--examples/widgets/painting/shared/images/radiobutton_on.pngbin0 -> 499 bytes
-rw-r--r--examples/widgets/painting/shared/images/slider_bar.pngbin0 -> 748 bytes
-rw-r--r--examples/widgets/painting/shared/images/slider_thumb_off.pngbin0 -> 823 bytes
-rw-r--r--examples/widgets/painting/shared/images/slider_thumb_on.pngbin0 -> 798 bytes
-rw-r--r--examples/widgets/painting/shared/images/title_cap_left.pngbin0 -> 179 bytes
-rw-r--r--examples/widgets/painting/shared/images/title_cap_right.pngbin0 -> 184 bytes
-rw-r--r--examples/widgets/painting/shared/images/title_stretch.pngbin0 -> 106 bytes
-rw-r--r--examples/widgets/painting/shared/shared.pri20
-rw-r--r--examples/widgets/painting/shared/shared.pro34
-rw-r--r--examples/widgets/painting/shared/shared.qrc39
-rw-r--r--examples/widgets/painting/svggenerator/svggenerator.desktop11
-rw-r--r--examples/widgets/painting/svgviewer/svgviewer.desktop11
-rw-r--r--examples/widgets/painting/transformations/main.cpp51
-rw-r--r--examples/widgets/painting/transformations/renderarea.cpp172
-rw-r--r--examples/widgets/painting/transformations/renderarea.h90
-rw-r--r--examples/widgets/painting/transformations/transformations.desktop11
-rw-r--r--examples/widgets/painting/transformations/transformations.pro13
-rw-r--r--examples/widgets/painting/transformations/window.cpp180
-rw-r--r--examples/widgets/painting/transformations/window.h80
-rw-r--r--examples/widgets/richtext/README11
-rw-r--r--examples/widgets/richtext/calendar/calendar.desktop11
-rw-r--r--examples/widgets/richtext/calendar/calendar.pro11
-rw-r--r--examples/widgets/richtext/calendar/main.cpp52
-rw-r--r--examples/widgets/richtext/calendar/mainwindow.cpp215
-rw-r--r--examples/widgets/richtext/calendar/mainwindow.h73
-rw-r--r--examples/widgets/richtext/orderform/detailsdialog.cpp156
-rw-r--r--examples/widgets/richtext/orderform/detailsdialog.h90
-rw-r--r--examples/widgets/richtext/orderform/main.cpp55
-rw-r--r--examples/widgets/richtext/orderform/mainwindow.cpp253
-rw-r--r--examples/widgets/richtext/orderform/mainwindow.h76
-rw-r--r--examples/widgets/richtext/orderform/orderform.desktop11
-rw-r--r--examples/widgets/richtext/orderform/orderform.pro14
-rw-r--r--examples/widgets/richtext/richtext.pro11
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/highlighter.cpp147
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/highlighter.h84
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/main.cpp52
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp128
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/mainwindow.h75
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.desktop11
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro20
-rw-r--r--examples/widgets/richtext/textedit/example.html79
-rw-r--r--examples/widgets/richtext/textedit/images/logo32.pngbin0 -> 1410 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editcopy.pngbin0 -> 1468 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editcut.pngbin0 -> 1512 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editpaste.pngbin0 -> 1906 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editredo.pngbin0 -> 1752 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editundo.pngbin0 -> 1746 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/exportpdf.pngbin0 -> 1215 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/filenew.pngbin0 -> 1172 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/fileopen.pngbin0 -> 2168 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/fileprint.pngbin0 -> 2087 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/filesave.pngbin0 -> 1206 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textbold.pngbin0 -> 1611 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textcenter.pngbin0 -> 1404 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textitalic.pngbin0 -> 1164 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textjustify.pngbin0 -> 1257 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textleft.pngbin0 -> 1235 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textright.pngbin0 -> 1406 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textunder.pngbin0 -> 1183 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/zoomin.pngbin0 -> 1696 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/zoomout.pngbin0 -> 1662 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editcopy.pngbin0 -> 1325 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editcut.pngbin0 -> 1896 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editpaste.pngbin0 -> 1482 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editredo.pngbin0 -> 1787 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editundo.pngbin0 -> 1768 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/exportpdf.pngbin0 -> 1059 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/filenew.pngbin0 -> 768 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/fileopen.pngbin0 -> 1662 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/fileprint.pngbin0 -> 1456 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/filesave.pngbin0 -> 1205 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textbold.pngbin0 -> 1134 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textcenter.pngbin0 -> 627 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textitalic.pngbin0 -> 829 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textjustify.pngbin0 -> 695 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textleft.pngbin0 -> 673 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textright.pngbin0 -> 677 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textunder.pngbin0 -> 971 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/zoomin.pngbin0 -> 1208 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/zoomout.pngbin0 -> 1226 bytes
-rw-r--r--examples/widgets/richtext/textedit/main.cpp54
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp737
-rw-r--r--examples/widgets/richtext/textedit/textedit.h130
-rw-r--r--examples/widgets/richtext/textedit/textedit.pro23
-rw-r--r--examples/widgets/richtext/textedit/textedit.qdoc45
-rw-r--r--examples/widgets/richtext/textedit/textedit.qrc44
-rw-r--r--examples/widgets/scroller/graphicsview/graphicsview.pro9
-rw-r--r--examples/widgets/scroller/graphicsview/main.cpp291
-rw-r--r--examples/widgets/scroller/scroller.pro2
-rw-r--r--examples/widgets/statemachine/README6
-rw-r--r--examples/widgets/statemachine/eventtransitions/eventtransitions.desktop11
-rw-r--r--examples/widgets/statemachine/eventtransitions/eventtransitions.pro11
-rw-r--r--examples/widgets/statemachine/eventtransitions/main.cpp115
-rw-r--r--examples/widgets/statemachine/factorial/factorial.desktop11
-rw-r--r--examples/widgets/statemachine/factorial/factorial.pro13
-rw-r--r--examples/widgets/statemachine/factorial/main.cpp175
-rw-r--r--examples/widgets/statemachine/pingpong/main.cpp139
-rw-r--r--examples/widgets/statemachine/pingpong/pingpong.desktop11
-rw-r--r--examples/widgets/statemachine/pingpong/pingpong.pro13
-rw-r--r--examples/widgets/statemachine/rogue/main.cpp54
-rw-r--r--examples/widgets/statemachine/rogue/movementtransition.h112
-rw-r--r--examples/widgets/statemachine/rogue/rogue.desktop11
-rw-r--r--examples/widgets/statemachine/rogue/rogue.pro13
-rw-r--r--examples/widgets/statemachine/rogue/window.cpp251
-rw-r--r--examples/widgets/statemachine/rogue/window.h90
-rw-r--r--examples/widgets/statemachine/statemachine.pro18
-rw-r--r--examples/widgets/statemachine/trafficlight/main.cpp184
-rw-r--r--examples/widgets/statemachine/trafficlight/trafficlight.desktop11
-rw-r--r--examples/widgets/statemachine/trafficlight/trafficlight.pro10
-rw-r--r--examples/widgets/statemachine/twowaybutton/main.cpp81
-rw-r--r--examples/widgets/statemachine/twowaybutton/twowaybutton.desktop11
-rw-r--r--examples/widgets/statemachine/twowaybutton/twowaybutton.pro10
-rw-r--r--examples/widgets/widgets.pro52
-rw-r--r--examples/widgets/widgets/README (renamed from examples/widgets/README)0
-rw-r--r--examples/widgets/widgets/analogclock/analogclock.cpp (renamed from examples/widgets/analogclock/analogclock.cpp)0
-rw-r--r--examples/widgets/widgets/analogclock/analogclock.desktop (renamed from examples/widgets/analogclock/analogclock.desktop)0
-rw-r--r--examples/widgets/widgets/analogclock/analogclock.h (renamed from examples/widgets/analogclock/analogclock.h)0
-rw-r--r--examples/widgets/widgets/analogclock/analogclock.pro (renamed from examples/widgets/analogclock/analogclock.pro)0
-rw-r--r--examples/widgets/widgets/analogclock/main.cpp (renamed from examples/widgets/analogclock/main.cpp)0
-rw-r--r--examples/widgets/widgets/applicationicon/applicationicon.desktop (renamed from examples/widgets/applicationicon/applicationicon.desktop)0
-rw-r--r--examples/widgets/widgets/applicationicon/applicationicon.png (renamed from examples/widgets/applicationicon/applicationicon.png)bin4023 -> 4023 bytes
-rw-r--r--examples/widgets/widgets/applicationicon/applicationicon.pro (renamed from examples/widgets/applicationicon/applicationicon.pro)0
-rw-r--r--examples/widgets/widgets/applicationicon/applicationicon.svg (renamed from examples/widgets/applicationicon/applicationicon.svg)0
-rw-r--r--examples/widgets/widgets/applicationicon/main.cpp (renamed from examples/widgets/applicationicon/main.cpp)0
-rw-r--r--examples/widgets/widgets/calculator/button.cpp (renamed from examples/widgets/calculator/button.cpp)0
-rw-r--r--examples/widgets/widgets/calculator/button.h (renamed from examples/widgets/calculator/button.h)0
-rw-r--r--examples/widgets/widgets/calculator/calculator.cpp (renamed from examples/widgets/calculator/calculator.cpp)0
-rw-r--r--examples/widgets/widgets/calculator/calculator.desktop (renamed from examples/widgets/calculator/calculator.desktop)0
-rw-r--r--examples/widgets/widgets/calculator/calculator.h (renamed from examples/widgets/calculator/calculator.h)0
-rw-r--r--examples/widgets/widgets/calculator/calculator.pro (renamed from examples/widgets/calculator/calculator.pro)0
-rw-r--r--examples/widgets/widgets/calculator/main.cpp (renamed from examples/widgets/calculator/main.cpp)0
-rw-r--r--examples/widgets/widgets/calculator/releasenotes.txt (renamed from examples/widgets/calculator/releasenotes.txt)0
-rw-r--r--examples/widgets/widgets/calendarwidget/calendarwidget.desktop (renamed from examples/widgets/calendarwidget/calendarwidget.desktop)0
-rw-r--r--examples/widgets/widgets/calendarwidget/calendarwidget.pro (renamed from examples/widgets/calendarwidget/calendarwidget.pro)0
-rw-r--r--examples/widgets/widgets/calendarwidget/main.cpp (renamed from examples/widgets/calendarwidget/main.cpp)0
-rw-r--r--examples/widgets/widgets/calendarwidget/window.cpp (renamed from examples/widgets/calendarwidget/window.cpp)0
-rw-r--r--examples/widgets/widgets/calendarwidget/window.h (renamed from examples/widgets/calendarwidget/window.h)0
-rw-r--r--examples/widgets/widgets/charactermap/charactermap.desktop (renamed from examples/widgets/charactermap/charactermap.desktop)0
-rw-r--r--examples/widgets/widgets/charactermap/charactermap.pro (renamed from examples/widgets/charactermap/charactermap.pro)0
-rw-r--r--examples/widgets/widgets/charactermap/characterwidget.cpp (renamed from examples/widgets/charactermap/characterwidget.cpp)0
-rw-r--r--examples/widgets/widgets/charactermap/characterwidget.h (renamed from examples/widgets/charactermap/characterwidget.h)0
-rw-r--r--examples/widgets/widgets/charactermap/main.cpp51
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.cpp (renamed from examples/widgets/charactermap/mainwindow.cpp)0
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.h (renamed from examples/widgets/charactermap/mainwindow.h)0
-rw-r--r--examples/widgets/widgets/codeeditor/codeeditor.cpp (renamed from examples/widgets/codeeditor/codeeditor.cpp)0
-rw-r--r--examples/widgets/widgets/codeeditor/codeeditor.desktop (renamed from examples/widgets/codeeditor/codeeditor.desktop)0
-rw-r--r--examples/widgets/widgets/codeeditor/codeeditor.h (renamed from examples/widgets/codeeditor/codeeditor.h)0
-rw-r--r--examples/widgets/widgets/codeeditor/codeeditor.pro (renamed from examples/widgets/codeeditor/codeeditor.pro)0
-rw-r--r--examples/widgets/widgets/codeeditor/main.cpp (renamed from examples/widgets/codeeditor/main.cpp)0
-rw-r--r--examples/widgets/widgets/digitalclock/digitalclock.cpp (renamed from examples/widgets/digitalclock/digitalclock.cpp)0
-rw-r--r--examples/widgets/widgets/digitalclock/digitalclock.desktop (renamed from examples/widgets/digitalclock/digitalclock.desktop)0
-rw-r--r--examples/widgets/widgets/digitalclock/digitalclock.h (renamed from examples/widgets/digitalclock/digitalclock.h)0
-rw-r--r--examples/widgets/widgets/digitalclock/digitalclock.pro (renamed from examples/widgets/digitalclock/digitalclock.pro)0
-rw-r--r--examples/widgets/widgets/digitalclock/main.cpp (renamed from examples/widgets/digitalclock/main.cpp)0
-rw-r--r--examples/widgets/widgets/elidedlabel/elidedlabel.cpp (renamed from examples/widgets/elidedlabel/elidedlabel.cpp)0
-rw-r--r--examples/widgets/widgets/elidedlabel/elidedlabel.desktop (renamed from examples/widgets/elidedlabel/elidedlabel.desktop)0
-rw-r--r--examples/widgets/widgets/elidedlabel/elidedlabel.h (renamed from examples/widgets/elidedlabel/elidedlabel.h)0
-rw-r--r--examples/widgets/widgets/elidedlabel/elidedlabel.pro (renamed from examples/widgets/elidedlabel/elidedlabel.pro)0
-rw-r--r--examples/widgets/widgets/elidedlabel/main.cpp (renamed from examples/widgets/elidedlabel/main.cpp)0
-rw-r--r--examples/widgets/widgets/elidedlabel/testwidget.cpp (renamed from examples/widgets/elidedlabel/testwidget.cpp)0
-rw-r--r--examples/widgets/widgets/elidedlabel/testwidget.h (renamed from examples/widgets/elidedlabel/testwidget.h)0
-rw-r--r--examples/widgets/widgets/groupbox/groupbox.desktop (renamed from examples/widgets/groupbox/groupbox.desktop)0
-rw-r--r--examples/widgets/widgets/groupbox/groupbox.pro (renamed from examples/widgets/groupbox/groupbox.pro)0
-rw-r--r--examples/widgets/widgets/groupbox/main.cpp51
-rw-r--r--examples/widgets/widgets/groupbox/window.cpp (renamed from examples/widgets/groupbox/window.cpp)0
-rw-r--r--examples/widgets/widgets/groupbox/window.h (renamed from examples/widgets/groupbox/window.h)0
-rw-r--r--examples/widgets/widgets/icons/iconpreviewarea.cpp (renamed from examples/widgets/icons/iconpreviewarea.cpp)0
-rw-r--r--examples/widgets/widgets/icons/iconpreviewarea.h (renamed from examples/widgets/icons/iconpreviewarea.h)0
-rw-r--r--examples/widgets/widgets/icons/icons.desktop (renamed from examples/widgets/icons/icons.desktop)0
-rw-r--r--examples/widgets/widgets/icons/icons.pro (renamed from examples/widgets/icons/icons.pro)0
-rw-r--r--examples/widgets/widgets/icons/iconsizespinbox.cpp (renamed from examples/widgets/icons/iconsizespinbox.cpp)0
-rw-r--r--examples/widgets/widgets/icons/iconsizespinbox.h (renamed from examples/widgets/icons/iconsizespinbox.h)0
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.cpp (renamed from examples/widgets/icons/imagedelegate.cpp)0
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.h (renamed from examples/widgets/icons/imagedelegate.h)0
-rw-r--r--examples/widgets/widgets/icons/images/designer.png (renamed from examples/widgets/icons/images/designer.png)bin4205 -> 4205 bytes
-rw-r--r--examples/widgets/widgets/icons/images/find_disabled.png (renamed from examples/widgets/icons/images/find_disabled.png)bin501 -> 501 bytes
-rw-r--r--examples/widgets/widgets/icons/images/find_normal.png (renamed from examples/widgets/icons/images/find_normal.png)bin838 -> 838 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_off_128x128.png (renamed from examples/widgets/icons/images/monkey_off_128x128.png)bin7045 -> 7045 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_off_16x16.png (renamed from examples/widgets/icons/images/monkey_off_16x16.png)bin683 -> 683 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_off_32x32.png (renamed from examples/widgets/icons/images/monkey_off_32x32.png)bin1609 -> 1609 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_off_64x64.png (renamed from examples/widgets/icons/images/monkey_off_64x64.png)bin3533 -> 3533 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_on_128x128.png (renamed from examples/widgets/icons/images/monkey_on_128x128.png)bin6909 -> 6909 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_on_16x16.png (renamed from examples/widgets/icons/images/monkey_on_16x16.png)bin681 -> 681 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_on_32x32.png (renamed from examples/widgets/icons/images/monkey_on_32x32.png)bin1577 -> 1577 bytes
-rw-r--r--examples/widgets/widgets/icons/images/monkey_on_64x64.png (renamed from examples/widgets/icons/images/monkey_on_64x64.png)bin3479 -> 3479 bytes
-rw-r--r--examples/widgets/widgets/icons/images/qt_extended_16x16.png (renamed from examples/widgets/icons/images/qt_extended_16x16.png)bin834 -> 834 bytes
-rw-r--r--examples/widgets/widgets/icons/images/qt_extended_32x32.png (renamed from examples/widgets/icons/images/qt_extended_32x32.png)bin1892 -> 1892 bytes
-rw-r--r--examples/widgets/widgets/icons/images/qt_extended_48x48.png (renamed from examples/widgets/icons/images/qt_extended_48x48.png)bin3672 -> 3672 bytes
-rw-r--r--examples/widgets/widgets/icons/main.cpp (renamed from examples/widgets/icons/main.cpp)0
-rw-r--r--examples/widgets/widgets/icons/mainwindow.cpp (renamed from examples/widgets/icons/mainwindow.cpp)0
-rw-r--r--examples/widgets/widgets/icons/mainwindow.h (renamed from examples/widgets/icons/mainwindow.h)0
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.cpp (renamed from examples/widgets/imageviewer/imageviewer.cpp)0
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.desktop (renamed from examples/widgets/imageviewer/imageviewer.desktop)0
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.h (renamed from examples/widgets/imageviewer/imageviewer.h)0
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.pro (renamed from examples/widgets/imageviewer/imageviewer.pro)0
-rw-r--r--examples/widgets/widgets/imageviewer/main.cpp (renamed from examples/widgets/imageviewer/main.cpp)0
-rw-r--r--examples/widgets/widgets/lineedits/lineedits.desktop (renamed from examples/widgets/lineedits/lineedits.desktop)0
-rw-r--r--examples/widgets/widgets/lineedits/lineedits.pro (renamed from examples/widgets/lineedits/lineedits.pro)0
-rw-r--r--examples/widgets/widgets/lineedits/main.cpp51
-rw-r--r--examples/widgets/widgets/lineedits/window.cpp (renamed from examples/widgets/lineedits/window.cpp)0
-rw-r--r--examples/widgets/widgets/lineedits/window.h (renamed from examples/widgets/lineedits/window.h)0
-rw-r--r--examples/widgets/widgets/mousebuttons/buttontester.cpp (renamed from examples/widgets/mousebuttons/buttontester.cpp)0
-rw-r--r--examples/widgets/widgets/mousebuttons/buttontester.h (renamed from examples/widgets/mousebuttons/buttontester.h)0
-rw-r--r--examples/widgets/widgets/mousebuttons/main.cpp (renamed from examples/widgets/mousebuttons/main.cpp)0
-rw-r--r--examples/widgets/widgets/mousebuttons/mousebuttons.pro (renamed from examples/widgets/mousebuttons/mousebuttons.pro)0
-rw-r--r--examples/widgets/widgets/movie/animation.gif (renamed from examples/widgets/movie/animation.gif)bin42629 -> 42629 bytes
-rw-r--r--examples/widgets/widgets/movie/main.cpp (renamed from examples/widgets/movie/main.cpp)0
-rw-r--r--examples/widgets/widgets/movie/movie.desktop (renamed from examples/widgets/movie/movie.desktop)0
-rw-r--r--examples/widgets/widgets/movie/movie.pro (renamed from examples/widgets/movie/movie.pro)0
-rw-r--r--examples/widgets/widgets/movie/movieplayer.cpp (renamed from examples/widgets/movie/movieplayer.cpp)0
-rw-r--r--examples/widgets/widgets/movie/movieplayer.h (renamed from examples/widgets/movie/movieplayer.h)0
-rw-r--r--examples/widgets/widgets/orientation/image_a.png (renamed from examples/widgets/orientation/image_a.png)bin1075 -> 1075 bytes
-rw-r--r--examples/widgets/widgets/orientation/image_b.png (renamed from examples/widgets/orientation/image_b.png)bin1020 -> 1020 bytes
-rw-r--r--examples/widgets/widgets/orientation/image_c.png (renamed from examples/widgets/orientation/image_c.png)bin1163 -> 1163 bytes
-rw-r--r--examples/widgets/widgets/orientation/images.qrc (renamed from examples/widgets/orientation/images.qrc)0
-rw-r--r--examples/widgets/widgets/orientation/landscape.ui (renamed from examples/widgets/orientation/landscape.ui)0
-rw-r--r--examples/widgets/widgets/orientation/main.cpp (renamed from examples/widgets/orientation/main.cpp)0
-rw-r--r--examples/widgets/widgets/orientation/mainwindow.cpp (renamed from examples/widgets/orientation/mainwindow.cpp)0
-rw-r--r--examples/widgets/widgets/orientation/mainwindow.h (renamed from examples/widgets/orientation/mainwindow.h)0
-rw-r--r--examples/widgets/widgets/orientation/orientation.desktop (renamed from examples/widgets/orientation/orientation.desktop)0
-rw-r--r--examples/widgets/widgets/orientation/orientation.pro (renamed from examples/widgets/orientation/orientation.pro)0
-rw-r--r--examples/widgets/widgets/orientation/portrait.ui (renamed from examples/widgets/orientation/portrait.ui)0
-rw-r--r--examples/widgets/widgets/scribble/main.cpp51
-rw-r--r--examples/widgets/widgets/scribble/mainwindow.cpp (renamed from examples/widgets/scribble/mainwindow.cpp)0
-rw-r--r--examples/widgets/widgets/scribble/mainwindow.h (renamed from examples/widgets/scribble/mainwindow.h)0
-rw-r--r--examples/widgets/widgets/scribble/scribble.desktop (renamed from examples/widgets/scribble/scribble.desktop)0
-rw-r--r--examples/widgets/widgets/scribble/scribble.pro (renamed from examples/widgets/scribble/scribble.pro)0
-rw-r--r--examples/widgets/widgets/scribble/scribblearea.cpp (renamed from examples/widgets/scribble/scribblearea.cpp)0
-rw-r--r--examples/widgets/widgets/scribble/scribblearea.h (renamed from examples/widgets/scribble/scribblearea.h)0
-rw-r--r--examples/widgets/widgets/shapedclock/main.cpp (renamed from examples/widgets/shapedclock/main.cpp)0
-rw-r--r--examples/widgets/widgets/shapedclock/shapedclock.cpp (renamed from examples/widgets/shapedclock/shapedclock.cpp)0
-rw-r--r--examples/widgets/widgets/shapedclock/shapedclock.desktop (renamed from examples/widgets/shapedclock/shapedclock.desktop)0
-rw-r--r--examples/widgets/widgets/shapedclock/shapedclock.h (renamed from examples/widgets/shapedclock/shapedclock.h)0
-rw-r--r--examples/widgets/widgets/shapedclock/shapedclock.pro (renamed from examples/widgets/shapedclock/shapedclock.pro)0
-rw-r--r--examples/widgets/widgets/sliders/main.cpp51
-rw-r--r--examples/widgets/widgets/sliders/sliders.desktop (renamed from examples/widgets/sliders/sliders.desktop)0
-rw-r--r--examples/widgets/widgets/sliders/sliders.pro (renamed from examples/widgets/sliders/sliders.pro)0
-rw-r--r--examples/widgets/widgets/sliders/slidersgroup.cpp (renamed from examples/widgets/sliders/slidersgroup.cpp)0
-rw-r--r--examples/widgets/widgets/sliders/slidersgroup.h (renamed from examples/widgets/sliders/slidersgroup.h)0
-rw-r--r--examples/widgets/widgets/sliders/window.cpp (renamed from examples/widgets/sliders/window.cpp)0
-rw-r--r--examples/widgets/widgets/sliders/window.h (renamed from examples/widgets/sliders/window.h)0
-rw-r--r--examples/widgets/widgets/softkeys/main.cpp (renamed from examples/widgets/softkeys/main.cpp)0
-rw-r--r--examples/widgets/widgets/softkeys/softkeys.cpp (renamed from examples/widgets/softkeys/softkeys.cpp)0
-rw-r--r--examples/widgets/widgets/softkeys/softkeys.desktop (renamed from examples/widgets/softkeys/softkeys.desktop)0
-rw-r--r--examples/widgets/widgets/softkeys/softkeys.h (renamed from examples/widgets/softkeys/softkeys.h)0
-rw-r--r--examples/widgets/widgets/softkeys/softkeys.pro (renamed from examples/widgets/softkeys/softkeys.pro)0
-rw-r--r--examples/widgets/widgets/spinboxes/main.cpp51
-rw-r--r--examples/widgets/widgets/spinboxes/spinboxes.desktop (renamed from examples/widgets/spinboxes/spinboxes.desktop)0
-rw-r--r--examples/widgets/widgets/spinboxes/spinboxes.pro (renamed from examples/widgets/spinboxes/spinboxes.pro)0
-rw-r--r--examples/widgets/widgets/spinboxes/window.cpp (renamed from examples/widgets/spinboxes/window.cpp)0
-rw-r--r--examples/widgets/widgets/spinboxes/window.h (renamed from examples/widgets/spinboxes/window.h)0
-rw-r--r--examples/widgets/widgets/styles/images/woodbackground.png (renamed from examples/widgets/styles/images/woodbackground.png)bin7691 -> 7691 bytes
-rw-r--r--examples/widgets/widgets/styles/images/woodbutton.png (renamed from examples/widgets/styles/images/woodbutton.png)bin7689 -> 7689 bytes
-rw-r--r--examples/widgets/widgets/styles/main.cpp (renamed from examples/widgets/styles/main.cpp)0
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.cpp (renamed from examples/widgets/styles/norwegianwoodstyle.cpp)0
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.h (renamed from examples/widgets/styles/norwegianwoodstyle.h)0
-rw-r--r--examples/widgets/widgets/styles/styles.desktop (renamed from examples/widgets/styles/styles.desktop)0
-rw-r--r--examples/widgets/widgets/styles/styles.pro (renamed from examples/widgets/styles/styles.pro)0
-rw-r--r--examples/widgets/widgets/styles/styles.qrc (renamed from examples/widgets/styles/styles.qrc)0
-rw-r--r--examples/widgets/widgets/styles/widgetgallery.cpp (renamed from examples/widgets/styles/widgetgallery.cpp)0
-rw-r--r--examples/widgets/widgets/styles/widgetgallery.h (renamed from examples/widgets/styles/widgetgallery.h)0
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_checked.png (renamed from examples/widgets/stylesheet/images/checkbox_checked.png)bin263 -> 263 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_checked_hover.png (renamed from examples/widgets/stylesheet/images/checkbox_checked_hover.png)bin266 -> 266 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_checked_pressed.png (renamed from examples/widgets/stylesheet/images/checkbox_checked_pressed.png)bin425 -> 425 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_unchecked.png (renamed from examples/widgets/stylesheet/images/checkbox_unchecked.png)bin159 -> 159 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_unchecked_hover.png (renamed from examples/widgets/stylesheet/images/checkbox_unchecked_hover.png)bin159 -> 159 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/checkbox_unchecked_pressed.png (renamed from examples/widgets/stylesheet/images/checkbox_unchecked_pressed.png)bin320 -> 320 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/down_arrow.png (renamed from examples/widgets/stylesheet/images/down_arrow.png)bin175 -> 175 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/down_arrow_disabled.png (renamed from examples/widgets/stylesheet/images/down_arrow_disabled.png)bin174 -> 174 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/frame.png (renamed from examples/widgets/stylesheet/images/frame.png)bin253 -> 253 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/pagefold.png (renamed from examples/widgets/stylesheet/images/pagefold.png)bin1545 -> 1545 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/pushbutton.png (renamed from examples/widgets/stylesheet/images/pushbutton.png)bin533 -> 533 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/pushbutton_hover.png (renamed from examples/widgets/stylesheet/images/pushbutton_hover.png)bin525 -> 525 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/pushbutton_pressed.png (renamed from examples/widgets/stylesheet/images/pushbutton_pressed.png)bin513 -> 513 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_checked.png (renamed from examples/widgets/stylesheet/images/radiobutton_checked.png)bin355 -> 355 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_checked_hover.png (renamed from examples/widgets/stylesheet/images/radiobutton_checked_hover.png)bin532 -> 532 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_checked_pressed.png (renamed from examples/widgets/stylesheet/images/radiobutton_checked_pressed.png)bin599 -> 599 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_unchecked.png (renamed from examples/widgets/stylesheet/images/radiobutton_unchecked.png)bin240 -> 240 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_hover.png (renamed from examples/widgets/stylesheet/images/radiobutton_unchecked_hover.png)bin492 -> 492 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_pressed.png (renamed from examples/widgets/stylesheet/images/radiobutton_unchecked_pressed.png)bin556 -> 556 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/sizegrip.png (renamed from examples/widgets/stylesheet/images/sizegrip.png)bin129 -> 129 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spindown.png (renamed from examples/widgets/stylesheet/images/spindown.png)bin276 -> 276 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spindown_hover.png (renamed from examples/widgets/stylesheet/images/spindown_hover.png)bin268 -> 268 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spindown_off.png (renamed from examples/widgets/stylesheet/images/spindown_off.png)bin249 -> 249 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spindown_pressed.png (renamed from examples/widgets/stylesheet/images/spindown_pressed.png)bin264 -> 264 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spinup.png (renamed from examples/widgets/stylesheet/images/spinup.png)bin283 -> 283 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spinup_hover.png (renamed from examples/widgets/stylesheet/images/spinup_hover.png)bin277 -> 277 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spinup_off.png (renamed from examples/widgets/stylesheet/images/spinup_off.png)bin274 -> 274 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/spinup_pressed.png (renamed from examples/widgets/stylesheet/images/spinup_pressed.png)bin277 -> 277 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/up_arrow.png (renamed from examples/widgets/stylesheet/images/up_arrow.png)bin197 -> 197 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/images/up_arrow_disabled.png (renamed from examples/widgets/stylesheet/images/up_arrow_disabled.png)bin172 -> 172 bytes
-rw-r--r--examples/widgets/widgets/stylesheet/layouts/default.ui (renamed from examples/widgets/stylesheet/layouts/default.ui)0
-rw-r--r--examples/widgets/widgets/stylesheet/layouts/pagefold.ui (renamed from examples/widgets/stylesheet/layouts/pagefold.ui)0
-rw-r--r--examples/widgets/widgets/stylesheet/main.cpp (renamed from examples/widgets/stylesheet/main.cpp)0
-rw-r--r--examples/widgets/widgets/stylesheet/mainwindow.cpp (renamed from examples/widgets/stylesheet/mainwindow.cpp)0
-rw-r--r--examples/widgets/widgets/stylesheet/mainwindow.h (renamed from examples/widgets/stylesheet/mainwindow.h)0
-rw-r--r--examples/widgets/widgets/stylesheet/mainwindow.ui (renamed from examples/widgets/stylesheet/mainwindow.ui)0
-rw-r--r--examples/widgets/widgets/stylesheet/qss/coffee.qss (renamed from examples/widgets/stylesheet/qss/coffee.qss)0
-rw-r--r--examples/widgets/widgets/stylesheet/qss/default.qss (renamed from examples/widgets/stylesheet/qss/default.qss)0
-rw-r--r--examples/widgets/widgets/stylesheet/qss/pagefold.qss (renamed from examples/widgets/stylesheet/qss/pagefold.qss)0
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheet.desktop (renamed from examples/widgets/stylesheet/stylesheet.desktop)0
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheet.pro (renamed from examples/widgets/stylesheet/stylesheet.pro)0
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheet.qrc (renamed from examples/widgets/stylesheet/stylesheet.qrc)0
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheeteditor.cpp (renamed from examples/widgets/stylesheet/stylesheeteditor.cpp)0
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheeteditor.h (renamed from examples/widgets/stylesheet/stylesheeteditor.h)0
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheeteditor.ui (renamed from examples/widgets/stylesheet/stylesheeteditor.ui)0
-rw-r--r--examples/widgets/widgets/tablet/main.cpp (renamed from examples/widgets/tablet/main.cpp)0
-rw-r--r--examples/widgets/widgets/tablet/mainwindow.cpp (renamed from examples/widgets/tablet/mainwindow.cpp)0
-rw-r--r--examples/widgets/widgets/tablet/mainwindow.h (renamed from examples/widgets/tablet/mainwindow.h)0
-rw-r--r--examples/widgets/widgets/tablet/tablet.desktop (renamed from examples/widgets/tablet/tablet.desktop)0
-rw-r--r--examples/widgets/widgets/tablet/tablet.pro (renamed from examples/widgets/tablet/tablet.pro)0
-rw-r--r--examples/widgets/widgets/tablet/tabletapplication.cpp (renamed from examples/widgets/tablet/tabletapplication.cpp)0
-rw-r--r--examples/widgets/widgets/tablet/tabletapplication.h (renamed from examples/widgets/tablet/tabletapplication.h)0
-rw-r--r--examples/widgets/widgets/tablet/tabletcanvas.cpp (renamed from examples/widgets/tablet/tabletcanvas.cpp)0
-rw-r--r--examples/widgets/widgets/tablet/tabletcanvas.h (renamed from examples/widgets/tablet/tabletcanvas.h)0
-rw-r--r--examples/widgets/widgets/tetrix/main.cpp (renamed from examples/widgets/tetrix/main.cpp)0
-rw-r--r--examples/widgets/widgets/tetrix/tetrix.desktop (renamed from examples/widgets/tetrix/tetrix.desktop)0
-rw-r--r--examples/widgets/widgets/tetrix/tetrix.pro (renamed from examples/widgets/tetrix/tetrix.pro)0
-rw-r--r--examples/widgets/widgets/tetrix/tetrixboard.cpp (renamed from examples/widgets/tetrix/tetrixboard.cpp)0
-rw-r--r--examples/widgets/widgets/tetrix/tetrixboard.h (renamed from examples/widgets/tetrix/tetrixboard.h)0
-rw-r--r--examples/widgets/widgets/tetrix/tetrixpiece.cpp (renamed from examples/widgets/tetrix/tetrixpiece.cpp)0
-rw-r--r--examples/widgets/widgets/tetrix/tetrixpiece.h (renamed from examples/widgets/tetrix/tetrixpiece.h)0
-rw-r--r--examples/widgets/widgets/tetrix/tetrixwindow.cpp (renamed from examples/widgets/tetrix/tetrixwindow.cpp)0
-rw-r--r--examples/widgets/widgets/tetrix/tetrixwindow.h (renamed from examples/widgets/tetrix/tetrixwindow.h)0
-rw-r--r--examples/widgets/widgets/tooltips/images/circle.png (renamed from examples/widgets/tooltips/images/circle.png)bin165 -> 165 bytes
-rw-r--r--examples/widgets/widgets/tooltips/images/square.png (renamed from examples/widgets/tooltips/images/square.png)bin94 -> 94 bytes
-rw-r--r--examples/widgets/widgets/tooltips/images/triangle.png (renamed from examples/widgets/tooltips/images/triangle.png)bin170 -> 170 bytes
-rw-r--r--examples/widgets/widgets/tooltips/main.cpp (renamed from examples/widgets/tooltips/main.cpp)0
-rw-r--r--examples/widgets/widgets/tooltips/shapeitem.cpp (renamed from examples/widgets/tooltips/shapeitem.cpp)0
-rw-r--r--examples/widgets/widgets/tooltips/shapeitem.h (renamed from examples/widgets/tooltips/shapeitem.h)0
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.cpp (renamed from examples/widgets/tooltips/sortingbox.cpp)0
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.h (renamed from examples/widgets/tooltips/sortingbox.h)0
-rw-r--r--examples/widgets/widgets/tooltips/tooltips.desktop (renamed from examples/widgets/tooltips/tooltips.desktop)0
-rw-r--r--examples/widgets/widgets/tooltips/tooltips.pro (renamed from examples/widgets/tooltips/tooltips.pro)0
-rw-r--r--examples/widgets/widgets/tooltips/tooltips.qrc (renamed from examples/widgets/tooltips/tooltips.qrc)0
-rw-r--r--examples/widgets/widgets/validators/ledoff.png (renamed from examples/widgets/validators/ledoff.png)bin562 -> 562 bytes
-rw-r--r--examples/widgets/widgets/validators/ledon.png (renamed from examples/widgets/validators/ledon.png)bin486 -> 486 bytes
-rw-r--r--examples/widgets/widgets/validators/ledwidget.cpp (renamed from examples/widgets/validators/ledwidget.cpp)0
-rw-r--r--examples/widgets/widgets/validators/ledwidget.h (renamed from examples/widgets/validators/ledwidget.h)0
-rw-r--r--examples/widgets/widgets/validators/localeselector.cpp (renamed from examples/widgets/validators/localeselector.cpp)0
-rw-r--r--examples/widgets/widgets/validators/localeselector.h (renamed from examples/widgets/validators/localeselector.h)0
-rw-r--r--examples/widgets/widgets/validators/main.cpp (renamed from examples/widgets/validators/main.cpp)0
-rw-r--r--examples/widgets/widgets/validators/validators.desktop (renamed from examples/widgets/validators/validators.desktop)0
-rw-r--r--examples/widgets/widgets/validators/validators.pro (renamed from examples/widgets/validators/validators.pro)0
-rw-r--r--examples/widgets/widgets/validators/validators.qrc (renamed from examples/widgets/validators/validators.qrc)0
-rw-r--r--examples/widgets/widgets/validators/validators.ui (renamed from examples/widgets/validators/validators.ui)0
-rw-r--r--examples/widgets/widgets/widgets.pro34
-rw-r--r--examples/widgets/widgets/wiggly/dialog.cpp (renamed from examples/widgets/wiggly/dialog.cpp)0
-rw-r--r--examples/widgets/widgets/wiggly/dialog.h (renamed from examples/widgets/wiggly/dialog.h)0
-rw-r--r--examples/widgets/widgets/wiggly/main.cpp (renamed from examples/widgets/wiggly/main.cpp)0
-rw-r--r--examples/widgets/widgets/wiggly/wiggly.desktop (renamed from examples/widgets/wiggly/wiggly.desktop)0
-rw-r--r--examples/widgets/widgets/wiggly/wiggly.pro (renamed from examples/widgets/wiggly/wiggly.pro)0
-rw-r--r--examples/widgets/widgets/wiggly/wigglywidget.cpp (renamed from examples/widgets/wiggly/wigglywidget.cpp)0
-rw-r--r--examples/widgets/widgets/wiggly/wigglywidget.h (renamed from examples/widgets/wiggly/wigglywidget.h)0
-rw-r--r--examples/widgets/widgets/windowflags/controllerwindow.cpp (renamed from examples/widgets/windowflags/controllerwindow.cpp)0
-rw-r--r--examples/widgets/widgets/windowflags/controllerwindow.h (renamed from examples/widgets/windowflags/controllerwindow.h)0
-rw-r--r--examples/widgets/widgets/windowflags/main.cpp (renamed from examples/widgets/windowflags/main.cpp)0
-rw-r--r--examples/widgets/widgets/windowflags/previewwindow.cpp (renamed from examples/widgets/windowflags/previewwindow.cpp)0
-rw-r--r--examples/widgets/widgets/windowflags/previewwindow.h (renamed from examples/widgets/windowflags/previewwindow.h)0
-rw-r--r--examples/widgets/widgets/windowflags/windowflags.desktop (renamed from examples/widgets/windowflags/windowflags.desktop)0
-rw-r--r--examples/widgets/widgets/windowflags/windowflags.pro (renamed from examples/widgets/windowflags/windowflags.pro)0
1299 files changed, 83542 insertions, 31 deletions
diff --git a/examples/widgets/animation/README b/examples/widgets/animation/README
new file mode 100644
index 0000000000..e723a28722
--- /dev/null
+++ b/examples/widgets/animation/README
@@ -0,0 +1,8 @@
+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.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/animation/animatedtiles/animatedtiles.desktop b/examples/widgets/animation/animatedtiles/animatedtiles.desktop
new file mode 100644
index 0000000000..97e646fdf8
--- /dev/null
+++ b/examples/widgets/animation/animatedtiles/animatedtiles.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Animated Tiles
+Exec=/opt/usr/bin/animatedtiles
+Icon=animatedtiles
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/animation/animatedtiles/animatedtiles.pro b/examples/widgets/animation/animatedtiles/animatedtiles.pro
new file mode 100644
index 0000000000..1bba99449c
--- /dev/null
+++ b/examples/widgets/animation/animatedtiles/animatedtiles.pro
@@ -0,0 +1,10 @@
+SOURCES = main.cpp
+RESOURCES = animatedtiles.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/animatedtiles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS animatedtiles.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/animatedtiles
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/animation/animatedtiles/animatedtiles.qrc b/examples/widgets/animation/animatedtiles/animatedtiles.qrc
new file mode 100644
index 0000000000..c43a979723
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/animatedtiles/images/Time-For-Lunch-2.jpg b/examples/widgets/animation/animatedtiles/images/Time-For-Lunch-2.jpg
new file mode 100644
index 0000000000..c57a555490
--- /dev/null
+++ b/examples/widgets/animation/animatedtiles/images/Time-For-Lunch-2.jpg
Binary files differ
diff --git a/examples/widgets/animation/animatedtiles/images/centered.png b/examples/widgets/animation/animatedtiles/images/centered.png
new file mode 100644
index 0000000000..e416156a0e
--- /dev/null
+++ b/examples/widgets/animation/animatedtiles/images/centered.png
Binary files differ
diff --git a/examples/widgets/animation/animatedtiles/images/ellipse.png b/examples/widgets/animation/animatedtiles/images/ellipse.png
new file mode 100644
index 0000000000..2c3ba881c5
--- /dev/null
+++ b/examples/widgets/animation/animatedtiles/images/ellipse.png
Binary files differ
diff --git a/examples/widgets/animation/animatedtiles/images/figure8.png b/examples/widgets/animation/animatedtiles/images/figure8.png
new file mode 100644
index 0000000000..6b058041c4
--- /dev/null
+++ b/examples/widgets/animation/animatedtiles/images/figure8.png
Binary files differ
diff --git a/examples/widgets/animation/animatedtiles/images/kinetic.png b/examples/widgets/animation/animatedtiles/images/kinetic.png
new file mode 100644
index 0000000000..55cfa5515f
--- /dev/null
+++ b/examples/widgets/animation/animatedtiles/images/kinetic.png
Binary files differ
diff --git a/examples/widgets/animation/animatedtiles/images/random.png b/examples/widgets/animation/animatedtiles/images/random.png
new file mode 100644
index 0000000000..415d96f856
--- /dev/null
+++ b/examples/widgets/animation/animatedtiles/images/random.png
Binary files differ
diff --git a/examples/widgets/animation/animatedtiles/images/tile.png b/examples/widgets/animation/animatedtiles/images/tile.png
new file mode 100644
index 0000000000..c8f39d8d40
--- /dev/null
+++ b/examples/widgets/animation/animatedtiles/images/tile.png
Binary files differ
diff --git a/examples/widgets/animation/animatedtiles/main.cpp b/examples/widgets/animation/animatedtiles/main.cpp
new file mode 100644
index 0000000000..50bd33860e
--- /dev/null
+++ b/examples/widgets/animation/animatedtiles/main.cpp
@@ -0,0 +1,256 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#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->setTransform(QTransform::fromScale(0.75, 0.75), true);
+ 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 < items.count(); ++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 < items.count(); ++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);
+
+ trans = rootState->addTransition(figure8Button, SIGNAL(pressed()), figure8State);
+ trans->addAnimation(group);
+
+ trans = rootState->addTransition(randomButton, SIGNAL(pressed()), randomState);
+ trans->addAnimation(group);
+
+ trans = rootState->addTransition(tiledButton, SIGNAL(pressed()), tiledState);
+ trans->addAnimation(group);
+
+ trans = rootState->addTransition(centeredButton, SIGNAL(pressed()), centeredState);
+ trans->addAnimation(group);
+
+ QTimer timer;
+ timer.start(125);
+ timer.setSingleShot(true);
+ trans = rootState->addTransition(&timer, SIGNAL(timeout()), ellipseState);
+ trans->addAnimation(group);
+
+ states.start();
+
+#ifdef QT_KEYPAD_NAVIGATION
+ QApplication::setNavigationMode(Qt::NavigationModeCursorAuto);
+#endif
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/widgets/animation/animation.pro b/examples/widgets/animation/animation.pro
new file mode 100644
index 0000000000..b17aa0e0fe
--- /dev/null
+++ b/examples/widgets/animation/animation.pro
@@ -0,0 +1,17 @@
+TEMPLATE = \
+ subdirs
+SUBDIRS += \
+ animatedtiles \
+ appchooser \
+ easing \
+ moveblocks \
+ states \
+ stickman \
+ sub-attaq \
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS animation.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation
+INSTALLS += target sources
+QT += widgets
diff --git a/examples/widgets/animation/appchooser/accessories-dictionary.png b/examples/widgets/animation/appchooser/accessories-dictionary.png
new file mode 100644
index 0000000000..e9bd55d918
--- /dev/null
+++ b/examples/widgets/animation/appchooser/accessories-dictionary.png
Binary files differ
diff --git a/examples/widgets/animation/appchooser/akregator.png b/examples/widgets/animation/appchooser/akregator.png
new file mode 100644
index 0000000000..a086f45ab6
--- /dev/null
+++ b/examples/widgets/animation/appchooser/akregator.png
Binary files differ
diff --git a/examples/widgets/animation/appchooser/appchooser.desktop b/examples/widgets/animation/appchooser/appchooser.desktop
new file mode 100644
index 0000000000..8e413e96c2
--- /dev/null
+++ b/examples/widgets/animation/appchooser/appchooser.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Application Chooser
+Exec=/opt/usr/bin/appchooser
+Icon=appchooser
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/animation/appchooser/appchooser.pro b/examples/widgets/animation/appchooser/appchooser.pro
new file mode 100644
index 0000000000..158a0eca9f
--- /dev/null
+++ b/examples/widgets/animation/appchooser/appchooser.pro
@@ -0,0 +1,10 @@
+SOURCES = main.cpp
+RESOURCES = appchooser.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/appchooser
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS appchooser.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/appchooser
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/animation/appchooser/appchooser.qrc b/examples/widgets/animation/appchooser/appchooser.qrc
new file mode 100644
index 0000000000..28a3e1c4c1
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/appchooser/digikam.png b/examples/widgets/animation/appchooser/digikam.png
new file mode 100644
index 0000000000..9de9fb2f80
--- /dev/null
+++ b/examples/widgets/animation/appchooser/digikam.png
Binary files differ
diff --git a/examples/widgets/animation/appchooser/k3b.png b/examples/widgets/animation/appchooser/k3b.png
new file mode 100644
index 0000000000..bbcafcfba1
--- /dev/null
+++ b/examples/widgets/animation/appchooser/k3b.png
Binary files differ
diff --git a/examples/widgets/animation/appchooser/main.cpp b/examples/widgets/animation/appchooser/main.cpp
new file mode 100644
index 0000000000..c8e60c0641
--- /dev/null
+++ b/examples/widgets/animation/appchooser/main.cpp
@@ -0,0 +1,173 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <QtWidgets>
+
+
+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;
+};
+
+class GraphicsView : public QGraphicsView
+{
+ Q_OBJECT
+public:
+ GraphicsView(QGraphicsScene *scene, QWidget *parent = 0) : QGraphicsView(scene, parent)
+ {
+ }
+
+ virtual void resizeEvent(QResizeEvent *)
+ {
+ fitInView(sceneRect(), Qt::KeepAspectRatio);
+ }
+};
+
+
+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);
+
+ GraphicsView window(&scene);
+ window.setFrameStyle(0);
+ window.setAlignment(Qt::AlignLeft | Qt::AlignTop);
+ window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QState::RestoreProperties);
+
+ QState *group = new QState(&machine);
+ 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/widgets/animation/easing/animation.h b/examples/widgets/animation/easing/animation.h
new file mode 100644
index 0000000000..35cbed4555
--- /dev/null
+++ b/examples/widgets/animation/easing/animation.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANIMATION_H
+#define ANIMATION_H
+
+#include <QtWidgets>
+
+#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 currentTime)
+ {
+ 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(currentTime);
+ }
+ }
+
+ QPainterPath m_path;
+ PathType m_pathType;
+};
+
+#endif // ANIMATION_H
diff --git a/examples/widgets/animation/easing/easing.desktop b/examples/widgets/animation/easing/easing.desktop
new file mode 100644
index 0000000000..56d122217a
--- /dev/null
+++ b/examples/widgets/animation/easing/easing.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Easing Curves
+Exec=/opt/usr/bin/easing
+Icon=easing
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/animation/easing/easing.pro b/examples/widgets/animation/easing/easing.pro
new file mode 100644
index 0000000000..155d17d9b9
--- /dev/null
+++ b/examples/widgets/animation/easing/easing.pro
@@ -0,0 +1,17 @@
+HEADERS = window.h \
+ animation.h
+SOURCES = main.cpp \
+ window.cpp
+
+FORMS = form.ui
+
+RESOURCES = easing.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/easing
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS easing.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/easing
+INSTALLS += target sources
+
+QT += widgets
+
diff --git a/examples/widgets/animation/easing/easing.qrc b/examples/widgets/animation/easing/easing.qrc
new file mode 100644
index 0000000000..7e112d3a9d
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/easing/form.ui b/examples/widgets/animation/easing/form.ui
new file mode 100644
index 0000000000..364aebeda6
--- /dev/null
+++ b/examples/widgets/animation/easing/form.ui
@@ -0,0 +1,270 @@
+<?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="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Path type</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QRadioButton" name="lineRadio">
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::LeftToRight</enum>
+ </property>
+ <property name="text">
+ <string>Line</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QRadioButton" name="circleRadio">
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>40</height>
+ </size>
+ </property>
+ <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="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>30</height>
+ </size>
+ </property>
+ <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="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>30</height>
+ </size>
+ </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="1">
+ <widget class="QDoubleSpinBox" name="amplitudeSpinBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>30</height>
+ </size>
+ </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="4" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Overshoot</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QDoubleSpinBox" name="overshootSpinBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>30</height>
+ </size>
+ </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_2">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Amplitude</string>
+ </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/widgets/animation/easing/images/qt-logo.png b/examples/widgets/animation/easing/images/qt-logo.png
new file mode 100644
index 0000000000..14ddf2a028
--- /dev/null
+++ b/examples/widgets/animation/easing/images/qt-logo.png
Binary files differ
diff --git a/examples/widgets/animation/easing/main.cpp b/examples/widgets/animation/easing/main.cpp
new file mode 100644
index 0000000000..05d4014fc2
--- /dev/null
+++ b/examples/widgets/animation/easing/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#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/widgets/animation/easing/window.cpp b/examples/widgets/animation/easing/window.cpp
new file mode 100644
index 0000000000..33468db59c
--- /dev/null
+++ b/examples/widgets/animation/easing/window.cpp
@@ -0,0 +1,177 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "window.h"
+
+Window::Window(QWidget *parent)
+ : QWidget(parent),
+ m_iconSize(64, 64)
+{
+ m_ui.setupUi(this);
+ QButtonGroup *buttonGroup = findChild<QButtonGroup *>(); // ### 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());
+
+ qreal curveScale = m_iconSize.height()/2;
+
+ painter.setPen(Qt::NoPen);
+
+ // start point
+ painter.setBrush(Qt::red);
+ QPoint start(yAxis, xAxis - curveScale * curve.valueForProgress(0));
+ painter.drawRect(start.x() - 1, start.y() - 1, 3, 3);
+
+ // end point
+ painter.setBrush(Qt::blue);
+ QPoint end(yAxis + curveScale, xAxis - curveScale * curve.valueForProgress(1));
+ painter.drawRect(end.x() - 1, end.y() - 1, 3, 3);
+
+ QPainterPath curvePath;
+ curvePath.moveTo(start);
+ 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));
+ curvePath.lineTo(to);
+ }
+ painter.setRenderHint(QPainter::Antialiasing, true);
+ painter.strokePath(curvePath, QColor(32, 32, 32));
+ painter.setRenderHint(QPainter::Antialiasing, false);
+ 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/widgets/animation/easing/window.h b/examples/widgets/animation/easing/window.h
new file mode 100644
index 0000000000..bf5014c0cc
--- /dev/null
+++ b/examples/widgets/animation/easing/window.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#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/widgets/animation/moveblocks/main.cpp b/examples/widgets/animation/moveblocks/main.cpp
new file mode 100644
index 0000000000..d807bb63d9
--- /dev/null
+++ b/examples/widgets/animation/moveblocks/main.cpp
@@ -0,0 +1,321 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <QtWidgets>
+
+//![15]
+class StateSwitchEvent: public QEvent
+{
+public:
+ StateSwitchEvent()
+ : QEvent(Type(StateSwitchType))
+ {
+ }
+
+ explicit StateSwitchEvent(int rand)
+ : QEvent(Type(StateSwitchType)),
+ m_rand(rand)
+ {
+ }
+
+ enum { StateSwitchType = QEvent::User + 256 };
+
+ int rand() const { return m_rand; }
+
+private:
+ int m_rand;
+};
+//![15]
+
+//![16]
+class QGraphicsRectWidget : public QGraphicsWidget
+{
+public:
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *,
+ QWidget *)
+ {
+ painter->fillRect(rect(), Qt::blue);
+ }
+};
+//![16]
+
+class StateSwitchTransition: public QAbstractTransition
+{
+public:
+ StateSwitchTransition(int rand)
+ : QAbstractTransition(),
+ m_rand(rand)
+ {
+ }
+
+protected:
+//![14]
+ virtual bool eventTest(QEvent *event)
+ {
+ return (event->type() == QEvent::Type(StateSwitchEvent::StateSwitchType))
+ && (static_cast<StateSwitchEvent *>(event)->rand() == m_rand);
+ }
+//![14]
+
+ virtual void onTransition(QEvent *) {}
+
+private:
+ int m_rand;
+};
+
+//![10]
+class StateSwitcher : public QState
+{
+ Q_OBJECT
+public:
+ StateSwitcher(QStateMachine *machine)
+ : QState(machine), m_stateCount(0), m_lastIndex(0)
+ { }
+//![10]
+
+//![11]
+ virtual void onEntry(QEvent *)
+ {
+ int n;
+ while ((n = (qrand() % m_stateCount + 1)) == m_lastIndex)
+ { }
+ m_lastIndex = n;
+ machine()->postEvent(new StateSwitchEvent(n));
+ }
+ virtual void onExit(QEvent *) {}
+//![11]
+
+//![12]
+ void addState(QState *state, QAbstractAnimation *animation) {
+ StateSwitchTransition *trans = new StateSwitchTransition(++m_stateCount);
+ trans->setTargetState(state);
+ addTransition(trans);
+ trans->addAnimation(animation);
+ }
+//![12]
+
+private:
+ int m_stateCount;
+ int m_lastIndex;
+};
+
+//![13]
+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(w2, "geometry", rect2);
+ result->assignProperty(w3, "geometry", rect3);
+ result->assignProperty(w4, "geometry", rect4);
+
+ return result;
+}
+//![13]
+
+
+class GraphicsView : public QGraphicsView
+{
+ Q_OBJECT
+public:
+ GraphicsView(QGraphicsScene *scene, QWidget *parent = NULL) : QGraphicsView(scene, parent)
+ {
+ }
+
+protected:
+ virtual void resizeEvent(QResizeEvent *event)
+ {
+ fitInView(scene()->sceneRect());
+ QGraphicsView::resizeEvent(event);
+ }
+};
+
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+//![1]
+ 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);
+//![1]
+ GraphicsView window(&scene);
+ window.setFrameStyle(0);
+ window.setAlignment(Qt::AlignLeft | Qt::AlignTop);
+ window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+//![2]
+ 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()));
+//![2]
+
+//![3]
+ 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);
+//![3]
+ 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);
+//![4]
+ 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);
+//![4]
+
+//![5]
+ QParallelAnimationGroup animationGroup;
+ QSequentialAnimationGroup *subGroup;
+
+ QPropertyAnimation *anim = new QPropertyAnimation(button4, "geometry");
+ anim->setDuration(1000);
+ anim->setEasingCurve(QEasingCurve::OutElastic);
+ animationGroup.addAnimation(anim);
+//![5]
+
+//![6]
+ subGroup = new QSequentialAnimationGroup(&animationGroup);
+ subGroup->addPause(100);
+ anim = new QPropertyAnimation(button3, "geometry");
+ anim->setDuration(1000);
+ anim->setEasingCurve(QEasingCurve::OutElastic);
+ subGroup->addAnimation(anim);
+//![6]
+
+ 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);
+
+//![7]
+ StateSwitcher *stateSwitcher = new StateSwitcher(&machine);
+ stateSwitcher->setObjectName("stateSwitcher");
+ group->addTransition(&timer, SIGNAL(timeout()), stateSwitcher);
+ stateSwitcher->addState(state1, &animationGroup);
+ stateSwitcher->addState(state2, &animationGroup);
+//![7]
+ stateSwitcher->addState(state3, &animationGroup);
+ stateSwitcher->addState(state4, &animationGroup);
+ stateSwitcher->addState(state5, &animationGroup);
+ stateSwitcher->addState(state6, &animationGroup);
+//![8]
+ stateSwitcher->addState(state7, &animationGroup);
+//![8]
+
+//![9]
+ machine.addState(group);
+ machine.setInitialState(group);
+ machine.start();
+//![9]
+
+ window.resize(300, 300);
+ window.show();
+
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/widgets/animation/moveblocks/moveblocks.desktop b/examples/widgets/animation/moveblocks/moveblocks.desktop
new file mode 100644
index 0000000000..4100f448df
--- /dev/null
+++ b/examples/widgets/animation/moveblocks/moveblocks.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Move Blocks
+Exec=/opt/usr/bin/moveblocks
+Icon=moveblocks
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/animation/moveblocks/moveblocks.pro b/examples/widgets/animation/moveblocks/moveblocks.pro
new file mode 100644
index 0000000000..7c242e31e6
--- /dev/null
+++ b/examples/widgets/animation/moveblocks/moveblocks.pro
@@ -0,0 +1,9 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/moveblocks
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS moveblocks.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/moveblocks
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/animation/states/accessories-dictionary.png b/examples/widgets/animation/states/accessories-dictionary.png
new file mode 100644
index 0000000000..e9bd55d918
--- /dev/null
+++ b/examples/widgets/animation/states/accessories-dictionary.png
Binary files differ
diff --git a/examples/widgets/animation/states/akregator.png b/examples/widgets/animation/states/akregator.png
new file mode 100644
index 0000000000..a086f45ab6
--- /dev/null
+++ b/examples/widgets/animation/states/akregator.png
Binary files differ
diff --git a/examples/widgets/animation/states/digikam.png b/examples/widgets/animation/states/digikam.png
new file mode 100644
index 0000000000..9de9fb2f80
--- /dev/null
+++ b/examples/widgets/animation/states/digikam.png
Binary files differ
diff --git a/examples/widgets/animation/states/help-browser.png b/examples/widgets/animation/states/help-browser.png
new file mode 100644
index 0000000000..db92faa4e7
--- /dev/null
+++ b/examples/widgets/animation/states/help-browser.png
Binary files differ
diff --git a/examples/widgets/animation/states/k3b.png b/examples/widgets/animation/states/k3b.png
new file mode 100644
index 0000000000..bbcafcfba1
--- /dev/null
+++ b/examples/widgets/animation/states/k3b.png
Binary files differ
diff --git a/examples/widgets/animation/states/kchart.png b/examples/widgets/animation/states/kchart.png
new file mode 100644
index 0000000000..1dd115be87
--- /dev/null
+++ b/examples/widgets/animation/states/kchart.png
Binary files differ
diff --git a/examples/widgets/animation/states/main.cpp b/examples/widgets/animation/states/main.cpp
new file mode 100644
index 0000000000..faa97ccbd0
--- /dev/null
+++ b/examples/widgets/animation/states/main.cpp
@@ -0,0 +1,285 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+class Pixmap : public QGraphicsObject
+{
+ Q_OBJECT
+public:
+ Pixmap(const QPixmap &pix) : QGraphicsObject(), p(pix)
+ {
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ {
+ painter->drawPixmap(QPointF(), p);
+ }
+
+ QRectF boundingRect() const
+ {
+ return QRectF( QPointF(0, 0), p.size());
+ }
+
+private:
+ QPixmap p;
+};
+
+class GraphicsView : public QGraphicsView
+{
+public:
+ GraphicsView(QGraphicsScene *scene) : QGraphicsView(scene)
+ {
+ }
+
+ virtual void resizeEvent(QResizeEvent *)
+ {
+ fitInView(sceneRect(), Qt::KeepAspectRatio);
+ }
+};
+
+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 *state1 = new QState(&machine);
+ QState *state2 = new QState(&machine);
+ QState *state3 = new QState(&machine);
+ 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, "pos", QPointF(68, 200)); // 185));
+ state1->assignProperty(p2, "pos", QPointF(168, 200)); // 185));
+ state1->assignProperty(p3, "pos", QPointF(268, 200)); // 185));
+ state1->assignProperty(p4, "pos", QPointF(68 - 150, 48 - 150));
+ state1->assignProperty(p5, "pos", QPointF(168, 48 - 150));
+ state1->assignProperty(p6, "pos", QPointF(268 + 150, 48 - 150));
+ state1->assignProperty(p1, "rotation", qreal(0));
+ state1->assignProperty(p2, "rotation", qreal(0));
+ state1->assignProperty(p3, "rotation", qreal(0));
+ state1->assignProperty(p4, "rotation", qreal(-270));
+ state1->assignProperty(p5, "rotation", qreal(-90));
+ state1->assignProperty(p6, "rotation", 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, "pos", QPointF(68 - 150, 185 + 150));
+ state2->assignProperty(p2, "pos", QPointF(168, 185 + 150));
+ state2->assignProperty(p3, "pos", QPointF(268 + 150, 185 + 150));
+ state2->assignProperty(p4, "pos", QPointF(64, 48));
+ state2->assignProperty(p5, "pos", QPointF(168, 48));
+ state2->assignProperty(p6, "pos", QPointF(268, 48));
+ state2->assignProperty(p1, "rotation", qreal(-270));
+ state2->assignProperty(p2, "rotation", qreal(90));
+ state2->assignProperty(p3, "rotation", qreal(270));
+ state2->assignProperty(p4, "rotation", qreal(0));
+ state2->assignProperty(p5, "rotation", qreal(0));
+ state2->assignProperty(p6, "rotation", 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, "pos", QPointF(0, 5));
+ state3->assignProperty(p2, "pos", QPointF(0, 5 + 64 + 5));
+ state3->assignProperty(p3, "pos", QPointF(5, 5 + (64 + 5) + 64));
+ state3->assignProperty(p4, "pos", QPointF(5 + 64 + 5, 5));
+ state3->assignProperty(p5, "pos", QPointF(5 + 64 + 5, 5 + 64 + 5));
+ state3->assignProperty(p6, "pos", QPointF(5 + 64 + 5, 5 + (64 + 5) + 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));
+
+ QAbstractTransition *t1 = state1->addTransition(button, SIGNAL(clicked()), state2);
+ QSequentialAnimationGroup *animation1SubGroup = new QSequentialAnimationGroup;
+ animation1SubGroup->addPause(250);
+ animation1SubGroup->addAnimation(new QPropertyAnimation(box, "geometry"));
+ t1->addAnimation(animation1SubGroup);
+ t1->addAnimation(new QPropertyAnimation(widget, "geometry"));
+ t1->addAnimation(new QPropertyAnimation(p1, "pos"));
+ t1->addAnimation(new QPropertyAnimation(p2, "pos"));
+ t1->addAnimation(new QPropertyAnimation(p3, "pos"));
+ t1->addAnimation(new QPropertyAnimation(p4, "pos"));
+ t1->addAnimation(new QPropertyAnimation(p5, "pos"));
+ t1->addAnimation(new QPropertyAnimation(p6, "pos"));
+ t1->addAnimation(new QPropertyAnimation(p1, "rotation"));
+ t1->addAnimation(new QPropertyAnimation(p2, "rotation"));
+ t1->addAnimation(new QPropertyAnimation(p3, "rotation"));
+ t1->addAnimation(new QPropertyAnimation(p4, "rotation"));
+ t1->addAnimation(new QPropertyAnimation(p5, "rotation"));
+ t1->addAnimation(new QPropertyAnimation(p6, "rotation"));
+ t1->addAnimation(new QPropertyAnimation(p1, "opacity"));
+ t1->addAnimation(new QPropertyAnimation(p2, "opacity"));
+ t1->addAnimation(new QPropertyAnimation(p3, "opacity"));
+ t1->addAnimation(new QPropertyAnimation(p4, "opacity"));
+ t1->addAnimation(new QPropertyAnimation(p5, "opacity"));
+ t1->addAnimation(new QPropertyAnimation(p6, "opacity"));
+
+ QAbstractTransition *t2 = state2->addTransition(button, SIGNAL(clicked()), state3);
+ t2->addAnimation(new QPropertyAnimation(box, "geometry"));
+ t2->addAnimation(new QPropertyAnimation(widget, "geometry"));
+ t2->addAnimation(new QPropertyAnimation(p1, "pos"));
+ t2->addAnimation(new QPropertyAnimation(p2, "pos"));
+ t2->addAnimation(new QPropertyAnimation(p3, "pos"));
+ t2->addAnimation(new QPropertyAnimation(p4, "pos"));
+ t2->addAnimation(new QPropertyAnimation(p5, "pos"));
+ t2->addAnimation(new QPropertyAnimation(p6, "pos"));
+ t2->addAnimation(new QPropertyAnimation(p1, "rotation"));
+ t2->addAnimation(new QPropertyAnimation(p2, "rotation"));
+ t2->addAnimation(new QPropertyAnimation(p3, "rotation"));
+ t2->addAnimation(new QPropertyAnimation(p4, "rotation"));
+ t2->addAnimation(new QPropertyAnimation(p5, "rotation"));
+ t2->addAnimation(new QPropertyAnimation(p6, "rotation"));
+ t2->addAnimation(new QPropertyAnimation(p1, "opacity"));
+ t2->addAnimation(new QPropertyAnimation(p2, "opacity"));
+ t2->addAnimation(new QPropertyAnimation(p3, "opacity"));
+ t2->addAnimation(new QPropertyAnimation(p4, "opacity"));
+ t2->addAnimation(new QPropertyAnimation(p5, "opacity"));
+ t2->addAnimation(new QPropertyAnimation(p6, "opacity"));
+
+ QAbstractTransition *t3 = state3->addTransition(button, SIGNAL(clicked()), state1);
+ t3->addAnimation(new QPropertyAnimation(box, "geometry"));
+ t3->addAnimation(new QPropertyAnimation(widget, "geometry"));
+ t3->addAnimation(new QPropertyAnimation(p1, "pos"));
+ t3->addAnimation(new QPropertyAnimation(p2, "pos"));
+ t3->addAnimation(new QPropertyAnimation(p3, "pos"));
+ t3->addAnimation(new QPropertyAnimation(p4, "pos"));
+ t3->addAnimation(new QPropertyAnimation(p5, "pos"));
+ t3->addAnimation(new QPropertyAnimation(p6, "pos"));
+ t3->addAnimation(new QPropertyAnimation(p1, "rotation"));
+ t3->addAnimation(new QPropertyAnimation(p2, "rotation"));
+ t3->addAnimation(new QPropertyAnimation(p3, "rotation"));
+ t3->addAnimation(new QPropertyAnimation(p4, "rotation"));
+ t3->addAnimation(new QPropertyAnimation(p5, "rotation"));
+ t3->addAnimation(new QPropertyAnimation(p6, "rotation"));
+ t3->addAnimation(new QPropertyAnimation(p1, "opacity"));
+ t3->addAnimation(new QPropertyAnimation(p2, "opacity"));
+ t3->addAnimation(new QPropertyAnimation(p3, "opacity"));
+ t3->addAnimation(new QPropertyAnimation(p4, "opacity"));
+ t3->addAnimation(new QPropertyAnimation(p5, "opacity"));
+ t3->addAnimation(new QPropertyAnimation(p6, "opacity"));
+
+ machine.start();
+
+ GraphicsView view(&scene);
+
+ view.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/widgets/animation/states/states.desktop b/examples/widgets/animation/states/states.desktop
new file mode 100644
index 0000000000..8429979f23
--- /dev/null
+++ b/examples/widgets/animation/states/states.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=States
+Exec=/opt/usr/bin/states
+Icon=states
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/animation/states/states.pro b/examples/widgets/animation/states/states.pro
new file mode 100644
index 0000000000..adf0e8d58c
--- /dev/null
+++ b/examples/widgets/animation/states/states.pro
@@ -0,0 +1,10 @@
+SOURCES += main.cpp
+RESOURCES += states.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/states
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS states.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/states
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/animation/states/states.qrc b/examples/widgets/animation/states/states.qrc
new file mode 100644
index 0000000000..60ab3f7a60
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/stickman/animation.cpp b/examples/widgets/animation/stickman/animation.cpp
new file mode 100644
index 0000000000..afdfae6eca
--- /dev/null
+++ b/examples/widgets/animation/stickman/animation.cpp
@@ -0,0 +1,189 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "animation.h"
+
+#include <QPointF>
+#include <QVector>
+#include <QIODevice>
+#include <QDataStream>
+
+class Frame
+{
+public:
+ Frame() {
+ }
+
+ int nodeCount() const
+ {
+ return m_nodePositions.size();
+ }
+
+ void setNodeCount(int nodeCount)
+ {
+ m_nodePositions.resize(nodeCount);
+ }
+
+ QPointF nodePos(int idx) const
+ {
+ return m_nodePositions.at(idx);
+ }
+
+ void setNodePos(int idx, const QPointF &pos)
+ {
+ m_nodePositions[idx] = pos;
+ }
+
+private:
+ QVector<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/widgets/animation/stickman/animation.h b/examples/widgets/animation/stickman/animation.h
new file mode 100644
index 0000000000..d5dab530e6
--- /dev/null
+++ b/examples/widgets/animation/stickman/animation.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/widgets/animation/stickman/animations/chilling.bin b/examples/widgets/animation/stickman/animations/chilling.bin
new file mode 100644
index 0000000000..a81fc7a18c
--- /dev/null
+++ b/examples/widgets/animation/stickman/animations/chilling.bin
Binary files differ
diff --git a/examples/widgets/animation/stickman/animations/dancing.bin b/examples/widgets/animation/stickman/animations/dancing.bin
new file mode 100644
index 0000000000..462f66f89b
--- /dev/null
+++ b/examples/widgets/animation/stickman/animations/dancing.bin
Binary files differ
diff --git a/examples/widgets/animation/stickman/animations/dead.bin b/examples/widgets/animation/stickman/animations/dead.bin
new file mode 100644
index 0000000000..9859b4b4cd
--- /dev/null
+++ b/examples/widgets/animation/stickman/animations/dead.bin
Binary files differ
diff --git a/examples/widgets/animation/stickman/animations/jumping.bin b/examples/widgets/animation/stickman/animations/jumping.bin
new file mode 100644
index 0000000000..12661a15f8
--- /dev/null
+++ b/examples/widgets/animation/stickman/animations/jumping.bin
Binary files differ
diff --git a/examples/widgets/animation/stickman/graphicsview.cpp b/examples/widgets/animation/stickman/graphicsview.cpp
new file mode 100644
index 0000000000..134fb8acf1
--- /dev/null
+++ b/examples/widgets/animation/stickman/graphicsview.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "graphicsview.h"
+#include "stickman.h"
+
+#include <QtGui/QKeyEvent>
+#include <QtWidgets/QGraphicsScene>
+#include <QtWidgets/QGraphicsView>
+
+GraphicsView::GraphicsView(QWidget *parent) : QGraphicsView(parent), m_editor(0) {}
+
+void GraphicsView::keyPressEvent(QKeyEvent *e)
+{
+ if (e->key() == Qt::Key_Escape)
+ close();
+ emit keyPressed(Qt::Key(e->key()));
+}
+
+void GraphicsView::resizeEvent(QResizeEvent *)
+{
+ fitInView(scene()->sceneRect());
+}
diff --git a/examples/widgets/animation/stickman/graphicsview.h b/examples/widgets/animation/stickman/graphicsview.h
new file mode 100644
index 0000000000..38bf6e1eb6
--- /dev/null
+++ b/examples/widgets/animation/stickman/graphicsview.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GRAPHICSVIEW_H
+#define GRAPHICSVIEW
+
+#include <QtWidgets/QGraphicsView>
+
+class MainWindow;
+class GraphicsView: public QGraphicsView
+{
+ Q_OBJECT
+public:
+ GraphicsView(QWidget *parent = 0);
+
+protected:
+ virtual void resizeEvent(QResizeEvent *event);
+ void keyPressEvent(QKeyEvent *);
+
+signals:
+ void keyPressed(int key);
+
+private:
+ MainWindow *m_editor;
+};
+
+#endif
diff --git a/examples/widgets/animation/stickman/lifecycle.cpp b/examples/widgets/animation/stickman/lifecycle.cpp
new file mode 100644
index 0000000000..53249ccd6f
--- /dev/null
+++ b/examples/widgets/animation/stickman/lifecycle.cpp
@@ -0,0 +1,217 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "lifecycle.h"
+#include "stickman.h"
+#include "node.h"
+#include "animation.h"
+#include "graphicsview.h"
+
+#include <QtCore>
+#include <QtWidgets>
+
+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))), m_key(key)
+ {
+ setTargetState(target);
+ }
+
+ virtual bool eventTest(QEvent *e)
+ {
+ if (QSignalTransition::eventTest(e)) {
+ QVariant key = static_cast<QStateMachine::SignalEvent*>(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)
+ {
+ setTargetState(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), "pos");
+ m_animationGroup->addAnimation(pa);
+ }
+
+ // Set up initial state graph
+//! [3]
+ m_machine = new QStateMachine();
+ m_machine->addDefaultAnimation(m_animationGroup);
+//! [3]
+
+ m_alive = new QState(m_machine);
+ m_alive->setObjectName("alive");
+
+ // Make it blink when lightning strikes before entering dead animation
+ QState *lightningBlink = new QState(m_machine);
+ 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);
+ 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, QObject *sender, const char *signal)
+{
+ QState *state = makeState(m_alive, fileName);
+ m_alive->addTransition(new KeyPressTransition(m_keyReceiver, key, state));
+
+ if((sender != NULL) || (signal != NULL)) {
+ m_alive->addTransition(sender, signal, 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), "pos", animation.nodePos(j));
+//! [1]
+
+ frameState->setObjectName(QString::fromLatin1("frame %0").arg(i));
+ if (previousState == 0)
+ topLevel->setInitialState(frameState);
+ else
+//! [2]
+ previousState->addTransition(previousState, SIGNAL(propertiesAssigned()), frameState);
+//! [2]
+
+ previousState = frameState;
+ }
+
+ // Loop
+ previousState->addTransition(previousState, SIGNAL(propertiesAssigned()), topLevel->initialState());
+
+ return topLevel;
+
+}
+
+LifeCycle::~LifeCycle()
+{
+ delete m_machine;
+ delete m_animationGroup;
+}
diff --git a/examples/widgets/animation/stickman/lifecycle.h b/examples/widgets/animation/stickman/lifecycle.h
new file mode 100644
index 0000000000..8e8bb50659
--- /dev/null
+++ b/examples/widgets/animation/stickman/lifecycle.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LIFECYCLE_H
+#define LIFECYCLE_H
+
+#include <Qt>
+
+class StickMan;
+QT_BEGIN_NAMESPACE
+class QStateMachine;
+class QAnimationGroup;
+class QState;
+class QAbstractState;
+class QAbstractTransition;
+class QObject;
+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, QObject *sender = NULL, const char *signal = NULL);
+
+ 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/widgets/animation/stickman/main.cpp b/examples/widgets/animation/stickman/main.cpp
new file mode 100644
index 0000000000..3e49da8de3
--- /dev/null
+++ b/examples/widgets/animation/stickman/main.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "animation.h"
+#include "node.h"
+#include "lifecycle.h"
+#include "stickman.h"
+#include "graphicsview.h"
+#include "rectbutton.h"
+
+#include <QtCore>
+#include <QtWidgets>
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(stickman);
+ 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;
+ scene.addItem(stickMan);
+
+ scene.addItem(textItem);
+ scene.setBackgroundBrush(Qt::black);
+
+ GraphicsView view;
+ view.setRenderHints(QPainter::Antialiasing);
+ view.setTransformationAnchor(QGraphicsView::NoAnchor);
+ view.setScene(&scene);
+
+ QRectF sceneRect = scene.sceneRect();
+ // making enough room in the scene for stickman to jump and die
+ view.resize(sceneRect.width() + 100, sceneRect.height() + 100);
+ view.setSceneRect(sceneRect);
+
+ view.show();
+ view.setFocus();
+
+ LifeCycle cycle(stickMan, &view);
+ cycle.setDeathAnimation(":/animations/dead.bin");
+
+ cycle.addActivity(":/animations/jumping.bin", Qt::Key_J);
+ cycle.addActivity(":/animations/dancing.bin", Qt::Key_D);
+ cycle.addActivity(":/animations/chilling.bin", Qt::Key_C);
+
+ cycle.start();
+
+
+ return app.exec();
+}
diff --git a/examples/widgets/animation/stickman/node.cpp b/examples/widgets/animation/stickman/node.cpp
new file mode 100644
index 0000000000..2de34b379c
--- /dev/null
+++ b/examples/widgets/animation/stickman/node.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "node.h"
+#include "stickman.h"
+
+#include <QRectF>
+#include <QPainter>
+#include <QGraphicsSceneMouseEvent>
+
+Node::Node(const QPointF &pos, QGraphicsItem *parent)
+ : QGraphicsObject(parent), m_dragging(false)
+{
+ setPos(pos);
+ setFlag(QGraphicsItem::ItemSendsGeometryChanges);
+}
+
+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 QGraphicsObject::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/widgets/animation/stickman/node.h b/examples/widgets/animation/stickman/node.h
new file mode 100644
index 0000000000..ae6e2a3ed0
--- /dev/null
+++ b/examples/widgets/animation/stickman/node.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef NODE_H
+#define NODE_H
+
+#include <QGraphicsItem>
+
+class Node: public QGraphicsObject
+{
+ Q_OBJECT
+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/widgets/animation/stickman/rectbutton.cpp b/examples/widgets/animation/stickman/rectbutton.cpp
new file mode 100644
index 0000000000..8b17600ef5
--- /dev/null
+++ b/examples/widgets/animation/stickman/rectbutton.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "rectbutton.h"
+#include <QPainter>
+
+RectButton::RectButton(QString buttonText) : m_ButtonText(buttonText)
+{
+}
+
+
+RectButton::~RectButton()
+{
+}
+
+
+void RectButton::mousePressEvent (QGraphicsSceneMouseEvent *)
+{
+ emit clicked();
+}
+
+
+QRectF RectButton::boundingRect() const
+{
+ return QRectF(0.0, 0.0, 90.0, 40.0);
+}
+
+
+void RectButton::paint(QPainter *painter, const QStyleOptionGraphicsItem * /* option */, QWidget * /* widget */)
+{
+ painter->setBrush(Qt::gray);
+ painter->drawRoundedRect(boundingRect(), 5, 5);
+
+ painter->setPen(Qt::white);
+ painter->drawText(20, 25, m_ButtonText);
+}
diff --git a/examples/widgets/animation/stickman/rectbutton.h b/examples/widgets/animation/stickman/rectbutton.h
new file mode 100644
index 0000000000..ead8f21420
--- /dev/null
+++ b/examples/widgets/animation/stickman/rectbutton.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RECTBUTTON_H
+#define RECTBUTTON_H
+
+#include <QGraphicsObject>
+
+class RectButton : public QGraphicsObject
+{
+ Q_OBJECT
+public:
+ RectButton(QString buttonText);
+ ~RectButton();
+
+ virtual QRectF boundingRect() const;
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+protected:
+ QString m_ButtonText;
+
+ virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
+
+signals:
+ void clicked();
+};
+
+#endif // RECTBUTTON_H
diff --git a/examples/widgets/animation/stickman/stickman.cpp b/examples/widgets/animation/stickman/stickman.cpp
new file mode 100644
index 0000000000..667ed7d141
--- /dev/null
+++ b/examples/widgets/animation/stickman/stickman.cpp
@@ -0,0 +1,337 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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 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 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_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()));
+ }
+
+ 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()
+{
+}
+
+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/widgets/animation/stickman/stickman.desktop b/examples/widgets/animation/stickman/stickman.desktop
new file mode 100644
index 0000000000..1722d4db3e
--- /dev/null
+++ b/examples/widgets/animation/stickman/stickman.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Stickman
+Exec=/opt/usr/bin/stickman
+Icon=stickman
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/animation/stickman/stickman.h b/examples/widgets/animation/stickman/stickman.h
new file mode 100644
index 0000000000..f50ed1a6c2
--- /dev/null
+++ b/examples/widgets/animation/stickman/stickman.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STICKMAN_H
+#define STICKMAN_H
+
+#include <QGraphicsObject>
+
+static const int NodeCount = 16;
+static const int BoneCount = 24;
+
+class Node;
+QT_BEGIN_NAMESPACE
+QT_END_NAMESPACE
+class StickMan: public QGraphicsObject
+{
+ 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[NodeCount];
+ qreal m_perfectBoneLengths[BoneCount];
+
+ 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/widgets/animation/stickman/stickman.pro b/examples/widgets/animation/stickman/stickman.pro
new file mode 100644
index 0000000000..43aaec113d
--- /dev/null
+++ b/examples/widgets/animation/stickman/stickman.pro
@@ -0,0 +1,23 @@
+HEADERS += stickman.h \
+ animation.h \
+ node.h \
+ lifecycle.h \
+ graphicsview.h \
+ rectbutton.h
+SOURCES += main.cpp \
+ stickman.cpp \
+ animation.cpp \
+ node.cpp \
+ lifecycle.cpp \
+ graphicsview.cpp \
+ rectbutton.cpp
+
+RESOURCES += stickman.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/stickman
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS stickman.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/stickman
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/animation/stickman/stickman.qrc b/examples/widgets/animation/stickman/stickman.qrc
new file mode 100644
index 0000000000..4cf3ba3828
--- /dev/null
+++ b/examples/widgets/animation/stickman/stickman.qrc
@@ -0,0 +1,8 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>animations/chilling.bin</file>
+ <file>animations/dancing.bin</file>
+ <file>animations/dead.bin</file>
+ <file>animations/jumping.bin</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/animation/sub-attaq/animationmanager.cpp b/examples/widgets/animation/sub-attaq/animationmanager.cpp
new file mode 100644
index 0000000000..7dcb9dfb50
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/animationmanager.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//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)
+{
+ QObject::connect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*)));
+ animations.append(anim);
+}
+
+void AnimationManager::unregisterAnimation_helper(QObject *obj)
+{
+ unregisterAnimation(static_cast<QAbstractAnimation*>(obj));
+}
+
+void AnimationManager::unregisterAnimation(QAbstractAnimation *anim)
+{
+ QObject::disconnect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*)));
+ 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/widgets/animation/sub-attaq/animationmanager.h b/examples/widgets/animation/sub-attaq/animationmanager.h
new file mode 100644
index 0000000000..6587e39b14
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/animationmanager.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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 slots:
+ void unregisterAnimation_helper(QObject *obj);
+
+private:
+ static AnimationManager *instance;
+ QList<QAbstractAnimation *> animations;
+};
+
+#endif // ANIMATIONMANAGER_H
diff --git a/examples/widgets/animation/sub-attaq/boat.cpp b/examples/widgets/animation/sub-attaq/boat.cpp
new file mode 100644
index 0000000000..88332dbfe7
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/boat.cpp
@@ -0,0 +1,272 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "boat.h"
+#include "boat_p.h"
+#include "bomb.h"
+#include "pixmapitem.h"
+#include "graphicsscene.h"
+#include "animationmanager.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);
+ for (int i = 1; i <= 4; i++) {
+ PixmapItem *step = new PixmapItem(QString("explosion/boat/step%1").arg(i),GraphicsScene::Big, boat);
+ step->setZValue(6);
+ step->setOpacity(0);
+
+ //fade-in
+ QPropertyAnimation *anim = new QPropertyAnimation(step, "opacity");
+ anim->setEndValue(1);
+ anim->setDuration(100);
+ group->insertAnimation(i-1, anim);
+
+ //and then fade-out
+ QPropertyAnimation *anim2 = new QPropertyAnimation(step, "opacity");
+ anim2->setEndValue(0);
+ anim2->setDuration(100);
+ group->addAnimation(anim2);
+ }
+
+ AnimationManager::self()->registerAnimation(group);
+ return group;
+}
+
+
+
+Boat::Boat() : PixmapItem(QString("boat"), GraphicsScene::Big),
+ speed(0), bombsAlreadyLaunched(0), direction(Boat::None), movementAnimation(0)
+{
+ setZValue(4);
+ setFlags(QGraphicsItem::ItemIsFocusable);
+
+ //The movement animation used to animate the boat
+ movementAnimation = new QPropertyAnimation(this, "pos");
+
+ //The destroy animation used to explode the boat
+ destroyAnimation = setupDestroyAnimation(this);
+
+ //We setup the state machine of the boat
+ machine = new QStateMachine(this);
+ QState *moving = new QState(machine);
+ 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);
+ LaunchStateLeft *launchStateLeft = new LaunchStateLeft(this, machine);
+
+ //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);
+
+ //This state play the destroyed animation
+ QAnimationState *destroyedState = new QAnimationState(machine);
+ 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();
+
+ 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/widgets/animation/sub-attaq/boat.h b/examples/widgets/animation/sub-attaq/boat.h
new file mode 100644
index 0000000000..0b2fe5c8eb
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/boat.h
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __BOAT__H__
+#define __BOAT__H__
+
+#include "pixmapitem.h"
+
+class Bomb;
+QT_BEGIN_NAMESPACE
+class QVariantAnimation;
+class QAbstractAnimation;
+class QStateMachine;
+QT_END_NAMESPACE
+
+class Boat : public PixmapItem
+{
+Q_OBJECT
+public:
+ enum Movement {
+ None = 0,
+ Left,
+ Right
+ };
+ enum { Type = UserType + 2 };
+ Boat();
+ 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;
+
+signals:
+ void boatDestroyed();
+ void boatExecutionFinished();
+
+private:
+ int speed;
+ int bombsAlreadyLaunched;
+ Movement direction;
+ QVariantAnimation *movementAnimation;
+ QAbstractAnimation *destroyAnimation;
+ QStateMachine *machine;
+};
+
+#endif //__BOAT__H__
diff --git a/examples/widgets/animation/sub-attaq/boat_p.h b/examples/widgets/animation/sub-attaq/boat_p.h
new file mode 100644
index 0000000000..38be985777
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/boat_p.h
@@ -0,0 +1,232 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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 <QtWidgets/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 *b, QEvent::Type t, int k)
+ : QKeyEventTransition(b, t, k), boat(b), key(k)
+ {
+ }
+protected:
+ virtual bool eventTest(QEvent *event)
+ {
+ if (!QKeyEventTransition::eventTest(event))
+ return false;
+ return (boat->currentSpeed() == 1);
+ }
+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 *b, QEvent::Type t, int k)
+ : QKeyEventTransition(b, t, k), boat(b), key(k)
+ {
+ }
+protected:
+ virtual bool eventTest(QEvent *event)
+ {
+ if (!QKeyEventTransition::eventTest(event))
+ return false;
+ return (boat->currentSpeed() >= 0);
+ }
+ 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), boat(boat), key(key)
+ {
+ }
+protected:
+ virtual bool eventTest(QEvent *event)
+ {
+ if (!QKeyEventTransition::eventTest(event))
+ return false;
+ //We have enough bomb?
+ return (boat->bombsLaunched() < MAX_BOMB);
+ }
+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), 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), 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), 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), 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), 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/widgets/animation/sub-attaq/bomb.cpp b/examples/widgets/animation/sub-attaq/bomb.cpp
new file mode 100644
index 0000000000..e47e9423a9
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/bomb.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//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() : PixmapItem(QString("bomb"), GraphicsScene::Big)
+{
+ setZValue(2);
+}
+
+void Bomb::launch(Bomb::Direction direction)
+{
+ QSequentialAnimationGroup *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(QVariant)),this,SLOT(onAnimationLaunchValueChanged(QVariant)));
+ connect(this, SIGNAL(bombExploded()), launchAnimation, SLOT(stop()));
+ //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);
+ launched->setAnimation(launchAnimation);
+
+ //End
+ QFinalState *final = new QFinalState(machine);
+
+ machine->setInitialState(launched);
+
+ //### Add a nice animation when the bomb is destroyed
+ launched->addTransition(this, SIGNAL(bombExploded()),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()
+{
+ emit bombExploded();
+}
diff --git a/examples/widgets/animation/sub-attaq/bomb.h b/examples/widgets/animation/sub-attaq/bomb.h
new file mode 100644
index 0000000000..74ed734caf
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/bomb.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __BOMB__H__
+#define __BOMB__H__
+
+#include "pixmapitem.h"
+
+class Bomb : public PixmapItem
+{
+Q_OBJECT
+public:
+ enum Direction {
+ Left = 0,
+ Right
+ };
+ Bomb();
+ void launch(Direction direction);
+ void destroy();
+
+signals:
+ void bombExploded();
+ void bombExecutionFinished();
+
+private slots:
+ void onAnimationLaunchValueChanged(const QVariant &);
+};
+
+#endif //__BOMB__H__
diff --git a/examples/widgets/animation/sub-attaq/data.xml b/examples/widgets/animation/sub-attaq/data.xml
new file mode 100644
index 0000000000..0f30515ddf
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/data.xml
@@ -0,0 +1,39 @@
+<?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="1"/>
+ </level>
+ <level id="1" name="Seaman apprentice">
+ <subinstance type="0" nb="2"/>
+ </level>
+ <level id="2" name="Seaman">
+ <subinstance type="0" nb="4"/>
+ </level>
+ <level id="3" name="Petty Officer Third Class">
+ <subinstance type="0" nb="6"/>
+ </level>
+ <level id="4" name="Petty Officer Second Class">
+ <subinstance type="0" nb="6"/>
+ </level>
+ <level id="5" name="Petty Officer First Class">
+ <subinstance type="0" nb="8"/>
+ </level>
+ <level id="6" name="Lieutenant">
+ <subinstance type="0" nb="10"/>
+ </level>
+ <level id="7" name="Commander">
+ <subinstance type="0" nb="15"/>
+ </level>
+ <level id="8" name="Captain">
+ <subinstance type="0" nb="12"/>
+ </level>
+ <level id="9" name="Admiral">
+ <subinstance type="0" nb="12"/>
+ </level>
+ </levels>
+</subattaq>
diff --git a/examples/widgets/animation/sub-attaq/graphicsscene.cpp b/examples/widgets/animation/sub-attaq/graphicsscene.cpp
new file mode 100644
index 0000000000..a2b3e2f101
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/graphicsscene.cpp
@@ -0,0 +1,282 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "graphicsscene.h"
+#include "states.h"
+#include "boat.h"
+#include "submarine.h"
+#include "torpedo.h"
+#include "bomb.h"
+#include "pixmapitem.h"
+#include "animationmanager.h"
+#include "qanimationstate.h"
+#include "progressitem.h"
+#include "textinformationitem.h"
+
+//Qt
+#include <QtCore/QPropertyAnimation>
+#include <QtCore/QSequentialAnimationGroup>
+#include <QtCore/QParallelAnimationGroup>
+#include <QtCore/QStateMachine>
+#include <QtCore/QFinalState>
+#include <QtCore/QPauseAnimation>
+#include <QtWidgets/QAction>
+#include <QtCore/QDir>
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QMessageBox>
+#include <QtWidgets/QGraphicsView>
+#include <QtWidgets/QGraphicsSceneMouseEvent>
+#include <QtCore/QXmlStreamReader>
+
+GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode)
+ : QGraphicsScene(x , y, width, height), mode(mode), boat(new Boat)
+{
+ PixmapItem *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);
+
+ textInformationItem = new TextInformationItem(backgroundItem);
+ textInformationItem->hide();
+ //We create the 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(":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);
+ } else if (reader.name() == "level") {
+ currentLevel.id = reader.attributes().value("id").toString().toInt();
+ currentLevel.name = reader.attributes().value("name").toString();
+ } else if (reader.name() == "subinstance") {
+ currentLevel.submarines.append(qMakePair(reader.attributes().value("type").toString().toInt(), reader.attributes().value("nb").toString().toInt()));
+ }
+ } else if (reader.tokenType() == QXmlStreamReader::EndElement) {
+ if (reader.name() == "level") {
+ levelsData.insert(currentLevel.id, currentLevel);
+ currentLevel.submarines.clear();
+ }
+ }
+ }
+}
+
+qreal GraphicsScene::sealLevel() const
+{
+ return (mode == Big) ? 220 : 160;
+}
+
+void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
+{
+ static const int nLetters = 10;
+ static struct {
+ char const *pix;
+ qreal initX, initY;
+ qreal destX, destY;
+ } logoData[nLetters] = {
+ {"s", -1000, -1000, 300, 150 },
+ {"u", -800, -1000, 350, 150 },
+ {"b", -600, -1000, 400, 120 },
+ {"dash", -400, -1000, 460, 150 },
+ {"a", 1000, 2000, 350, 250 },
+ {"t", 800, 2000, 400, 250 },
+ {"t2", 600, 2000, 430, 250 },
+ {"a2", 400, 2000, 465, 250 },
+ {"q", 200, 2000, 510, 250 },
+ {"excl", 0, 2000, 570, 220 } };
+
+ QSequentialAnimationGroup * lettersGroupMoving = new QSequentialAnimationGroup(this);
+ QParallelAnimationGroup * lettersGroupFading = new QParallelAnimationGroup(this);
+
+ for (int i = 0; i < nLetters; ++i) {
+ PixmapItem *logo = new PixmapItem(QLatin1String(":/logo-") + logoData[i].pix, this);
+ logo->setPos(logoData[i].initX, logoData[i].initY);
+ logo->setZValue(i + 3);
+ //creation of the animations for moving letters
+ QPropertyAnimation *moveAnim = new QPropertyAnimation(logo, "pos", lettersGroupMoving);
+ moveAnim->setEndValue(QPointF(logoData[i].destX, logoData[i].destY));
+ moveAnim->setDuration(200);
+ moveAnim->setEasingCurve(QEasingCurve::OutElastic);
+ lettersGroupMoving->addPause(50);
+ //creation of the animations for fading out the letters
+ QPropertyAnimation *fadeAnim = new QPropertyAnimation(logo, "opacity", lettersGroupFading);
+ fadeAnim->setDuration(800);
+ fadeAnim->setEndValue(0);
+ fadeAnim->setEasingCurve(QEasingCurve::OutQuad);
+ }
+
+ QStateMachine *machine = new QStateMachine(this);
+
+ //This state is when the player is playing
+ PlayState *gameState = new PlayState(this, machine);
+
+ //Final state
+ QFinalState *final = new QFinalState(machine);
+
+ //Animation when the player enter in the game
+ QAnimationState *lettersMovingState = new QAnimationState(machine);
+ lettersMovingState->setAnimation(lettersGroupMoving);
+
+ //Animation when the welcome screen disappear
+ QAnimationState *lettersFadingState = new QAnimationState(machine);
+ 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()), qApp, SLOT(quit()));
+}
+
+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::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();
+}
+
+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();
+ boat->setEnabled(true);
+}
diff --git a/examples/widgets/animation/sub-attaq/graphicsscene.h b/examples/widgets/animation/sub-attaq/graphicsscene.h
new file mode 100644
index 0000000000..3e571a878c
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/graphicsscene.h
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __GRAPHICSSCENE__H__
+#define __GRAPHICSSCENE__H__
+
+//Qt
+#include <QtWidgets/QGraphicsScene>
+#include <QtCore/QSet>
+#include <QtCore/QState>
+
+
+class Boat;
+class SubMarine;
+class Torpedo;
+class Bomb;
+class PixmapItem;
+class ProgressItem;
+class TextInformationItem;
+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(QAction *newAction, QAction *quitAction);
+ void addItem(Bomb *bomb);
+ void addItem(Torpedo *torpedo);
+ void addItem(SubMarine *submarine);
+ void addItem(QGraphicsItem *item);
+ void clearScene();
+
+signals:
+ void subMarineDestroyed(int);
+ void allSubMarineDestroyed(int);
+
+private slots:
+ void onBombExecutionFinished();
+ void onTorpedoExecutionFinished();
+ void onSubMarineExecutionFinished();
+
+private:
+ Mode mode;
+ ProgressItem *progressItem;
+ TextInformationItem *textInformationItem;
+ Boat *boat;
+ QSet<SubMarine *> submarines;
+ QSet<Bomb *> bombs;
+ QSet<Torpedo *> torpedos;
+ 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/widgets/animation/sub-attaq/main.cpp b/examples/widgets/animation/sub-attaq/main.cpp
new file mode 100644
index 0000000000..df18c83435
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#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/widgets/animation/sub-attaq/mainwindow.cpp b/examples/widgets/animation/sub-attaq/mainwindow.cpp
new file mode 100644
index 0000000000..70f0303177
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/mainwindow.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "mainwindow.h"
+#include "graphicsscene.h"
+
+//Qt
+#include <QGraphicsView>
+#include <QApplication>
+#include <QMenu>
+#include <QMenuBar>
+#include <QLayout>
+
+#ifndef QT_NO_OPENGL
+# include <QtOpenGL/QtOpenGL>
+#endif
+
+MainWindow::MainWindow() : QMainWindow(0)
+{
+ QMenu *file = menuBar()->addMenu(tr("&File"));
+
+ QAction *newAction = file->addAction(tr("New Game"));
+ newAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N));
+ QAction *quitAction = file->addAction(tr("Quit"));
+ quitAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
+
+ if (QApplication::arguments().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);
+ scene->setupScene(newAction, quitAction);
+#ifndef QT_NO_OPENGL
+ view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
+#endif
+
+ setCentralWidget(view);
+}
diff --git a/examples/widgets/animation/sub-attaq/mainwindow.h b/examples/widgets/animation/sub-attaq/mainwindow.h
new file mode 100644
index 0000000000..596157d38f
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/mainwindow.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __MAINWINDOW__H__
+#define __MAINWINDOW__H__
+
+//Qt
+#include <QtWidgets/QMainWindow>
+class GraphicsScene;
+QT_BEGIN_NAMESPACE
+class QGraphicsView;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+Q_OBJECT
+public:
+ MainWindow();
+
+private:
+ GraphicsScene *scene;
+ QGraphicsView *view;
+};
+
+#endif //__MAINWINDOW__H__
diff --git a/examples/widgets/animation/sub-attaq/pics/big/background.png b/examples/widgets/animation/sub-attaq/pics/big/background.png
new file mode 100644
index 0000000000..9f581571fa
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/background.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/boat.png b/examples/widgets/animation/sub-attaq/pics/big/boat.png
new file mode 100644
index 0000000000..be82dff62a
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/boat.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/bomb.png b/examples/widgets/animation/sub-attaq/pics/big/bomb.png
new file mode 100644
index 0000000000..3af5f2f29c
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/bomb.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step1.png b/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step1.png
new file mode 100644
index 0000000000..c9fd8b0984
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step1.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step2.png b/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step2.png
new file mode 100644
index 0000000000..7528f2d2da
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step2.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step3.png b/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step3.png
new file mode 100644
index 0000000000..aae9c9c184
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step3.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step4.png b/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step4.png
new file mode 100644
index 0000000000..d697c1bae8
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/explosion/boat/step4.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step1.png b/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step1.png
new file mode 100644
index 0000000000..88ca5144b7
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step1.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step2.png b/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step2.png
new file mode 100644
index 0000000000..524f5890ee
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step2.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step3.png b/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step3.png
new file mode 100644
index 0000000000..2cca1e80fe
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step3.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step4.png b/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step4.png
new file mode 100644
index 0000000000..82100a8260
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/explosion/submarine/step4.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/submarine.png b/examples/widgets/animation/sub-attaq/pics/big/submarine.png
new file mode 100644
index 0000000000..df435dc47d
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/submarine.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/surface.png b/examples/widgets/animation/sub-attaq/pics/big/surface.png
new file mode 100644
index 0000000000..4eba29e9cd
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/surface.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/big/torpedo.png b/examples/widgets/animation/sub-attaq/pics/big/torpedo.png
new file mode 100644
index 0000000000..f9c26873f1
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/big/torpedo.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/scalable/background-n810.svg b/examples/widgets/animation/sub-attaq/pics/scalable/background-n810.svg
new file mode 100644
index 0000000000..ece9f7aaf1
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/sub-attaq/pics/scalable/background.svg b/examples/widgets/animation/sub-attaq/pics/scalable/background.svg
new file mode 100644
index 0000000000..0be268010e
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/sub-attaq/pics/scalable/boat.svg b/examples/widgets/animation/sub-attaq/pics/scalable/boat.svg
new file mode 100644
index 0000000000..5298821ba8
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/sub-attaq/pics/scalable/bomb.svg b/examples/widgets/animation/sub-attaq/pics/scalable/bomb.svg
new file mode 100644
index 0000000000..294771a6dd
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/sub-attaq/pics/scalable/sand.svg b/examples/widgets/animation/sub-attaq/pics/scalable/sand.svg
new file mode 100644
index 0000000000..8af11b7a66
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/sub-attaq/pics/scalable/see.svg b/examples/widgets/animation/sub-attaq/pics/scalable/see.svg
new file mode 100644
index 0000000000..0666691215
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/sub-attaq/pics/scalable/sky.svg b/examples/widgets/animation/sub-attaq/pics/scalable/sky.svg
new file mode 100644
index 0000000000..1546c087a7
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/sub-attaq/pics/scalable/sub-attaq.svg b/examples/widgets/animation/sub-attaq/pics/scalable/sub-attaq.svg
new file mode 100644
index 0000000000..b075179b46
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/sub-attaq/pics/scalable/submarine.svg b/examples/widgets/animation/sub-attaq/pics/scalable/submarine.svg
new file mode 100644
index 0000000000..8a0ffddbca
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/sub-attaq/pics/scalable/surface.svg b/examples/widgets/animation/sub-attaq/pics/scalable/surface.svg
new file mode 100644
index 0000000000..40ed239638
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/sub-attaq/pics/scalable/torpedo.svg b/examples/widgets/animation/sub-attaq/pics/scalable/torpedo.svg
new file mode 100644
index 0000000000..48e429d2bf
--- /dev/null
+++ b/examples/widgets/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/widgets/animation/sub-attaq/pics/small/background.png b/examples/widgets/animation/sub-attaq/pics/small/background.png
new file mode 100644
index 0000000000..5ad3db660a
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/small/background.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/small/boat.png b/examples/widgets/animation/sub-attaq/pics/small/boat.png
new file mode 100644
index 0000000000..114ccc310e
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/small/boat.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/small/bomb.png b/examples/widgets/animation/sub-attaq/pics/small/bomb.png
new file mode 100644
index 0000000000..3af5f2f29c
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/small/bomb.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/small/submarine.png b/examples/widgets/animation/sub-attaq/pics/small/submarine.png
new file mode 100644
index 0000000000..0c0c350600
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/small/submarine.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/small/surface.png b/examples/widgets/animation/sub-attaq/pics/small/surface.png
new file mode 100644
index 0000000000..06d0e47a5c
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/small/surface.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/small/torpedo.png b/examples/widgets/animation/sub-attaq/pics/small/torpedo.png
new file mode 100644
index 0000000000..f9c26873f1
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/small/torpedo.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/welcome/logo-a.png b/examples/widgets/animation/sub-attaq/pics/welcome/logo-a.png
new file mode 100644
index 0000000000..67dd76dac0
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/welcome/logo-a.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/welcome/logo-a2.png b/examples/widgets/animation/sub-attaq/pics/welcome/logo-a2.png
new file mode 100644
index 0000000000..17668b07de
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/welcome/logo-a2.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/welcome/logo-b.png b/examples/widgets/animation/sub-attaq/pics/welcome/logo-b.png
new file mode 100644
index 0000000000..cf6c04560b
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/welcome/logo-b.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/welcome/logo-dash.png b/examples/widgets/animation/sub-attaq/pics/welcome/logo-dash.png
new file mode 100644
index 0000000000..219233ce6b
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/welcome/logo-dash.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/welcome/logo-excl.png b/examples/widgets/animation/sub-attaq/pics/welcome/logo-excl.png
new file mode 100644
index 0000000000..8dd0a2eb86
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/welcome/logo-excl.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/welcome/logo-q.png b/examples/widgets/animation/sub-attaq/pics/welcome/logo-q.png
new file mode 100644
index 0000000000..86e588d4d8
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/welcome/logo-q.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/welcome/logo-s.png b/examples/widgets/animation/sub-attaq/pics/welcome/logo-s.png
new file mode 100644
index 0000000000..7b6a36e93a
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/welcome/logo-s.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/welcome/logo-t.png b/examples/widgets/animation/sub-attaq/pics/welcome/logo-t.png
new file mode 100644
index 0000000000..b2e3526bea
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/welcome/logo-t.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/welcome/logo-t2.png b/examples/widgets/animation/sub-attaq/pics/welcome/logo-t2.png
new file mode 100644
index 0000000000..b11a77886e
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/welcome/logo-t2.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pics/welcome/logo-u.png b/examples/widgets/animation/sub-attaq/pics/welcome/logo-u.png
new file mode 100644
index 0000000000..24eede887a
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pics/welcome/logo-u.png
Binary files differ
diff --git a/examples/widgets/animation/sub-attaq/pixmapitem.cpp b/examples/widgets/animation/sub-attaq/pixmapitem.cpp
new file mode 100644
index 0000000000..077151d708
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pixmapitem.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "pixmapitem.h"
+
+//Qt
+#include <QPainter>
+
+PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphicsItem * parent) : QGraphicsObject(parent)
+{
+ if (mode == GraphicsScene::Big)
+ pix = QPixmap(QStringLiteral(":/big/") + fileName);
+ else
+ pix = QPixmap(QStringLiteral(":/small/") + fileName);
+}
+
+PixmapItem::PixmapItem(const QString &fileName, QGraphicsScene *scene) : QGraphicsObject(), pix(fileName)
+{
+ scene->addItem(this);
+}
+
+QSizeF PixmapItem::size() const
+{
+ return pix.size();
+}
+
+QRectF PixmapItem::boundingRect() const
+{
+ return QRectF(QPointF(0, 0), pix.size());
+}
+
+void PixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ painter->drawPixmap(0, 0, pix);
+}
+
+
diff --git a/examples/widgets/animation/sub-attaq/pixmapitem.h b/examples/widgets/animation/sub-attaq/pixmapitem.h
new file mode 100644
index 0000000000..0a3b1287c7
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/pixmapitem.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __PIXMAPITEM__H__
+#define __PIXMAPITEM__H__
+
+//Own
+#include "graphicsscene.h"
+
+//Qt
+#include <QtWidgets/QGraphicsObject>
+
+class PixmapItem : public QGraphicsObject
+{
+public:
+ PixmapItem(const QString &fileName, GraphicsScene::Mode mode, QGraphicsItem * parent = 0);
+ PixmapItem(const QString &fileName, QGraphicsScene *scene);
+ QSizeF size() const;
+ QRectF boundingRect() const;
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
+private:
+ QPixmap pix;
+};
+
+#endif //__PIXMAPITEM__H__
diff --git a/examples/widgets/animation/sub-attaq/progressitem.cpp b/examples/widgets/animation/sub-attaq/progressitem.cpp
new file mode 100644
index 0000000000..bad9ceb471
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/progressitem.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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/widgets/animation/sub-attaq/progressitem.h b/examples/widgets/animation/sub-attaq/progressitem.h
new file mode 100644
index 0000000000..dc6d7ba6bc
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/progressitem.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PROGRESSITEM_H
+#define PROGRESSITEM_H
+
+//Qt
+#include <QtWidgets/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/widgets/animation/sub-attaq/qanimationstate.cpp b/examples/widgets/animation/sub-attaq/qanimationstate.cpp
new file mode 100644
index 0000000000..b122acc858
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/qanimationstate.cpp
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "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/widgets/animation/sub-attaq/qanimationstate.h b/examples/widgets/animation/sub-attaq/qanimationstate.h
new file mode 100644
index 0000000000..2672f640e4
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/qanimationstate.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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
+
+
+#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;
+
+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/widgets/animation/sub-attaq/states.cpp b/examples/widgets/animation/sub-attaq/states.cpp
new file mode 100644
index 0000000000..32ad218693
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/states.cpp
@@ -0,0 +1,330 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "states.h"
+#include "graphicsscene.h"
+#include "boat.h"
+#include "submarine.h"
+#include "torpedo.h"
+#include "animationmanager.h"
+#include "progressitem.h"
+#include "textinformationitem.h"
+
+//Qt
+#include <QtWidgets/QMessageBox>
+#include <QtWidgets/QGraphicsView>
+#include <QtCore/QStateMachine>
+#include <QtWidgets/QKeyEventTransition>
+#include <QtCore/QFinalState>
+
+PlayState::PlayState(GraphicsScene *scene, QState *parent)
+ : QState(parent),
+ scene(scene),
+ machine(0),
+ currentLevel(0),
+ score(0)
+{
+}
+
+PlayState::~PlayState()
+{
+ delete machine;
+}
+
+void PlayState::onEntry(QEvent *)
+{
+ //We are now playing?
+ if (machine) {
+ machine->stop();
+ //we hide the information
+ scene->textInformationItem->hide();
+ scene->clearScene();
+ currentLevel = 0;
+ score = 0;
+ delete machine;
+ }
+
+ machine = new QStateMachine;
+
+ //This state is when player is playing
+ LevelState *levelState = new LevelState(scene, this, machine);
+
+ //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);
+
+ //This state is when player have won
+ WinState *winState = new WinState(scene, this, machine);
+
+ //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);
+
+ //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 inform the player
+ scene->textInformationItem->setMessage(message);
+ scene->textInformationItem->show();
+}
+
+void LostState::onExit(QEvent *)
+{
+ //we hide the information
+ scene->textInformationItem->hide();
+}
+
+/** 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.").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 inform the player
+ scene->textInformationItem->setMessage(message);
+ scene->textInformationItem->show();
+}
+
+void WinState::onExit(QEvent *)
+{
+ //we hide the information
+ scene->textInformationItem->hide();
+}
+
+/** UpdateScore State */
+UpdateScoreState::UpdateScoreState(PlayState *g, QState *parent) : QState(parent), game(g)
+{
+}
+
+/** Win transition */
+UpdateScoreTransition::UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target)
+ : QSignalTransition(scene,SIGNAL(subMarineDestroyed(int))),
+ game(game), scene(scene)
+{
+ setTargetState(target);
+}
+
+bool UpdateScoreTransition::eventTest(QEvent *event)
+{
+ if (!QSignalTransition::eventTest(event))
+ return false;
+ QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(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))),
+ game(game), scene(scene)
+{
+ setTargetState(target);
+}
+
+bool WinTransition::eventTest(QEvent *event)
+{
+ if (!QSignalTransition::eventTest(event))
+ return false;
+ QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(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)
+{
+ if (!QKeyEventTransition::eventTest(event))
+ return false;
+ return (game->currentLevel != 0);
+}
diff --git a/examples/widgets/animation/sub-attaq/states.h b/examples/widgets/animation/sub-attaq/states.h
new file mode 100644
index 0000000000..e43370302c
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/states.h
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STATES_H
+#define STATES_H
+
+//Qt
+#include <QtCore/QState>
+#include <QtCore/QSignalTransition>
+#include <QtCore/QPropertyAnimation>
+#include <QtWidgets/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 *);
+ void onExit(QEvent *);
+private :
+ GraphicsScene *scene;
+ PlayState *game;
+};
+
+class WinState : public QState
+{
+public:
+ WinState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
+
+protected:
+ void onEntry(QEvent *);
+ void onExit(QEvent *);
+private :
+ GraphicsScene *scene;
+ PlayState *game;
+};
+
+class UpdateScoreState : public QState
+{
+public:
+ UpdateScoreState(PlayState *game, QState *parent);
+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/widgets/animation/sub-attaq/sub-attaq.pro b/examples/widgets/animation/sub-attaq/sub-attaq.pro
new file mode 100644
index 0000000000..6d9b3195ac
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/sub-attaq.pro
@@ -0,0 +1,42 @@
+QT += widgets
+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 \
+ qanimationstate.h \
+ progressitem.h \
+ textinformationitem.h
+SOURCES += boat.cpp \
+ bomb.cpp \
+ main.cpp \
+ mainwindow.cpp \
+ submarine.cpp \
+ torpedo.cpp \
+ pixmapitem.cpp \
+ graphicsscene.cpp \
+ animationmanager.cpp \
+ states.cpp \
+ qanimationstate.cpp \
+ progressitem.cpp \
+ textinformationitem.cpp
+RESOURCES += subattaq.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/sub-attaq
+sources.files = $$SOURCES \
+ $$HEADERS \
+ $$RESOURCES \
+ $$FORMS \
+ sub-attaq.pro \
+ pics
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/animation/sub-attaq
+INSTALLS += target \
+ sources
diff --git a/examples/widgets/animation/sub-attaq/subattaq.qrc b/examples/widgets/animation/sub-attaq/subattaq.qrc
new file mode 100644
index 0000000000..80a3af11cc
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/subattaq.qrc
@@ -0,0 +1,39 @@
+<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>
+ <file>data.xml</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/animation/sub-attaq/submarine.cpp b/examples/widgets/animation/sub-attaq/submarine.cpp
new file mode 100644
index 0000000000..68eaf7ef38
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/submarine.cpp
@@ -0,0 +1,182 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//Own
+#include "submarine.h"
+#include "submarine_p.h"
+#include "torpedo.h"
+#include "pixmapitem.h"
+#include "graphicsscene.h"
+#include "animationmanager.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);
+ for (int i = 1; i <= 4; ++i) {
+ PixmapItem *step = new PixmapItem(QString::fromLatin1("explosion/submarine/step%1").arg(i), GraphicsScene::Big, sub);
+ step->setZValue(6);
+ step->setOpacity(0);
+ QPropertyAnimation *anim = new QPropertyAnimation(step, "opacity", group);
+ anim->setDuration(100);
+ anim->setEndValue(1);
+ }
+ AnimationManager::self()->registerAnimation(group);
+ return group;
+}
+
+
+SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QString("submarine"), GraphicsScene::Big),
+ subType(type), subName(name), subPoints(points), speed(0), direction(SubMarine::None)
+{
+ setZValue(5);
+ setTransformOriginPoint(boundingRect().center());
+
+ graphicsRotation = new QGraphicsRotation(this);
+ graphicsRotation->setAxis(Qt::YAxis);
+ graphicsRotation->setOrigin(QVector3D(size().width()/2, size().height()/2, 0));
+ QList<QGraphicsTransform *> r;
+ r.append(graphicsRotation);
+ setTransformations(r);
+
+ //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);
+
+ //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);
+
+ //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);
+ 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() const
+{
+ return subPoints;
+}
+
+void SubMarine::setCurrentDirection(SubMarine::Movement direction)
+{
+ if (this->direction == direction)
+ return;
+ if (direction == SubMarine::Right && this->direction == SubMarine::None) {
+ graphicsRotation->setAngle(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(pos());
+ torp->setCurrentSpeed(speed);
+ torp->launch();
+}
+
+void SubMarine::destroy()
+{
+ emit subMarineDestroyed();
+}
+
+int SubMarine::type() const
+{
+ return Type;
+}
diff --git a/examples/widgets/animation/sub-attaq/submarine.h b/examples/widgets/animation/sub-attaq/submarine.h
new file mode 100644
index 0000000000..b113bc8797
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/submarine.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __SUBMARINE__H__
+#define __SUBMARINE__H__
+
+//Qt
+#include <QtWidgets/QGraphicsTransform>
+
+#include "pixmapitem.h"
+
+class Torpedo;
+
+class SubMarine : public PixmapItem
+{
+Q_OBJECT
+public:
+ enum Movement {
+ None = 0,
+ Left,
+ Right
+ };
+ enum { Type = UserType + 1 };
+ SubMarine(int type, const QString &name, int points);
+
+ int points() const;
+
+ 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;
+
+ QGraphicsRotation *rotation() const { return graphicsRotation; }
+
+signals:
+ void subMarineDestroyed();
+ void subMarineExecutionFinished();
+ void subMarineStateChanged();
+
+private:
+ int subType;
+ QString subName;
+ int subPoints;
+ int speed;
+ Movement direction;
+ QGraphicsRotation *graphicsRotation;
+};
+
+#endif //__SUBMARINE__H__
diff --git a/examples/widgets/animation/sub-attaq/submarine_p.h b/examples/widgets/animation/sub-attaq/submarine_p.h
new file mode 100644
index 0000000000..f24487aa17
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/submarine_p.h
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef 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 <QtWidgets/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);
+ }
+ 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->rotation(), "angle");
+ returnAnimation->setDuration(500);
+ AnimationManager::self()->registerAnimation(returnAnimation);
+ setAnimation(returnAnimation);
+ this->submarine = submarine;
+ }
+
+protected:
+ void onEntry(QEvent *e)
+ {
+ returnAnimation->stop();
+ returnAnimation->setEndValue(submarine->currentDirection() == SubMarine::Right ? 360. : 180.);
+ 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/widgets/animation/sub-attaq/textinformationitem.cpp b/examples/widgets/animation/sub-attaq/textinformationitem.cpp
new file mode 100644
index 0000000000..ce2e297287
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/textinformationitem.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "textinformationitem.h"
+#include "pixmapitem.h"
+
+TextInformationItem::TextInformationItem (QGraphicsItem * parent)
+ : QGraphicsTextItem(parent)
+{
+ setFont(QFont("Comic Sans MS", 15));
+}
+#include <QDebug>
+void TextInformationItem::setMessage(const QString& text)
+{
+ setHtml(text);
+ setPos(parentItem()->boundingRect().center().x() - boundingRect().size().width()/2 , parentItem()->boundingRect().center().y());
+}
diff --git a/examples/widgets/animation/sub-attaq/textinformationitem.h b/examples/widgets/animation/sub-attaq/textinformationitem.h
new file mode 100644
index 0000000000..adad8be90b
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/textinformationitem.h
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TEXTINFORMATIONITEM_H
+#define TEXTINFORMATIONITEM_H
+
+//Qt
+#include <QtWidgets/QGraphicsTextItem>
+
+class TextInformationItem : public QGraphicsTextItem
+{
+public:
+ TextInformationItem(QGraphicsItem * parent = 0);
+ void setMessage(const QString& text);
+};
+
+#endif // TEXTINFORMATIONITEM_H
diff --git a/examples/widgets/animation/sub-attaq/torpedo.cpp b/examples/widgets/animation/sub-attaq/torpedo.cpp
new file mode 100644
index 0000000000..34c32fe059
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/torpedo.cpp
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//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() : PixmapItem(QString::fromLatin1("torpedo"),GraphicsScene::Big),
+ currentSpeed(0)
+{
+ setZValue(2);
+}
+
+void Torpedo::launch()
+{
+ QPropertyAnimation *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(QVariant)),this,SLOT(onAnimationLaunchValueChanged(QVariant)));
+ connect(this,SIGNAL(torpedoExploded()), launchAnimation, SLOT(stop()));
+
+ //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);
+ launched->setAnimation(launchAnimation);
+
+ //End
+ QFinalState *final = new QFinalState(machine);
+
+ machine->setInitialState(launched);
+
+ //### Add a nice animation when the torpedo is destroyed
+ launched->addTransition(this, SIGNAL(torpedoExploded()),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 (Boat *b = qgraphicsitem_cast<Boat*>(item))
+ b->destroy();
+ }
+}
+
+void Torpedo::destroy()
+{
+ emit torpedoExploded();
+}
diff --git a/examples/widgets/animation/sub-attaq/torpedo.h b/examples/widgets/animation/sub-attaq/torpedo.h
new file mode 100644
index 0000000000..59209e3d75
--- /dev/null
+++ b/examples/widgets/animation/sub-attaq/torpedo.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef __TORPEDO__H__
+#define __TORPEDO__H__
+
+#include "pixmapitem.h"
+
+class Torpedo : public PixmapItem
+{
+Q_OBJECT
+public:
+ Torpedo();
+ void launch();
+ void setCurrentSpeed(int speed);
+ void destroy();
+
+signals:
+ void torpedoExploded();
+ void torpedoExecutionFinished();
+
+private slots:
+ void onAnimationLaunchValueChanged(const QVariant &);
+
+private:
+ int currentSpeed;
+};
+
+#endif //__TORPEDO__H__
diff --git a/examples/widgets/desktop/README b/examples/widgets/desktop/README
new file mode 100644
index 0000000000..4a949d1cf7
--- /dev/null
+++ b/examples/widgets/desktop/README
@@ -0,0 +1,10 @@
+Qt provides features to enable applications to integrate with the user's
+preferred desktop environment.
+
+Features such as system tray icons, access to the desktop widget, and
+support for desktop services can be used to improve the appearance of
+applications and take advantage of underlying desktop facilities.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/desktop/desktop.pro b/examples/widgets/desktop/desktop.pro
new file mode 100644
index 0000000000..adfa51f130
--- /dev/null
+++ b/examples/widgets/desktop/desktop.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+SUBDIRS = screenshot systray
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS desktop.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/desktop/screenshot/main.cpp b/examples/widgets/desktop/screenshot/main.cpp
new file mode 100644
index 0000000000..3f9b2e1126
--- /dev/null
+++ b/examples/widgets/desktop/screenshot/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "screenshot.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Screenshot screenshot;
+ screenshot.show();
+ return app.exec();
+}
diff --git a/examples/widgets/desktop/screenshot/screenshot.cpp b/examples/widgets/desktop/screenshot/screenshot.cpp
new file mode 100644
index 0000000000..12c6bee6d4
--- /dev/null
+++ b/examples/widgets/desktop/screenshot/screenshot.cpp
@@ -0,0 +1,199 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "screenshot.h"
+
+//! [0]
+Screenshot::Screenshot()
+{
+ screenshotLabel = new QLabel;
+ screenshotLabel->setSizePolicy(QSizePolicy::Expanding,
+ QSizePolicy::Expanding);
+ screenshotLabel->setAlignment(Qt::AlignCenter);
+ screenshotLabel->setMinimumSize(240, 160);
+
+ createOptionsGroupBox();
+ createButtonsLayout();
+
+ mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(screenshotLabel);
+ mainLayout->addWidget(optionsGroupBox);
+ mainLayout->addLayout(buttonsLayout);
+ setLayout(mainLayout);
+
+ shootScreen();
+ delaySpinBox->setValue(5);
+
+ setWindowTitle(tr("Screenshot"));
+ resize(300, 200);
+}
+//! [0]
+
+//! [1]
+void Screenshot::resizeEvent(QResizeEvent * /* event */)
+{
+ QSize scaledSize = originalPixmap.size();
+ scaledSize.scale(screenshotLabel->size(), Qt::KeepAspectRatio);
+ if (!screenshotLabel->pixmap()
+ || scaledSize != screenshotLabel->pixmap()->size())
+ updateScreenshotLabel();
+}
+//! [1]
+
+//! [2]
+void Screenshot::newScreenshot()
+{
+ if (hideThisWindowCheckBox->isChecked())
+ hide();
+ newScreenshotButton->setDisabled(true);
+
+ QTimer::singleShot(delaySpinBox->value() * 1000, this, SLOT(shootScreen()));
+}
+//! [2]
+
+//! [3]
+void Screenshot::saveScreenshot()
+{
+ QString format = "png";
+ QString initialPath = QDir::currentPath() + tr("/untitled.") + format;
+
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
+ initialPath,
+ tr("%1 Files (*.%2);;All Files (*)")
+ .arg(format.toUpper())
+ .arg(format));
+ if (!fileName.isEmpty())
+ originalPixmap.save(fileName, format.toLatin1().constData());
+}
+//! [3]
+
+//! [4]
+void Screenshot::shootScreen()
+{
+ if (delaySpinBox->value() != 0)
+ qApp->beep();
+//! [4]
+ originalPixmap = QPixmap(); // clear image for low memory situations
+ // on embedded devices.
+//! [5]
+ QScreen *screen = QGuiApplication::primaryScreen();
+ if (screen)
+ originalPixmap = screen->grabWindow(0);
+ updateScreenshotLabel();
+
+ newScreenshotButton->setDisabled(false);
+ if (hideThisWindowCheckBox->isChecked())
+ show();
+}
+//! [5]
+
+//! [6]
+void Screenshot::updateCheckBox()
+{
+ if (delaySpinBox->value() == 0) {
+ hideThisWindowCheckBox->setDisabled(true);
+ hideThisWindowCheckBox->setChecked(false);
+ }
+ else
+ hideThisWindowCheckBox->setDisabled(false);
+}
+//! [6]
+
+//! [7]
+void Screenshot::createOptionsGroupBox()
+{
+ optionsGroupBox = new QGroupBox(tr("Options"));
+
+ delaySpinBox = new QSpinBox;
+ delaySpinBox->setSuffix(tr(" s"));
+ delaySpinBox->setMaximum(60);
+ connect(delaySpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateCheckBox()));
+
+ delaySpinBoxLabel = new QLabel(tr("Screenshot Delay:"));
+
+ hideThisWindowCheckBox = new QCheckBox(tr("Hide This Window"));
+
+ optionsGroupBoxLayout = new QGridLayout;
+ optionsGroupBoxLayout->addWidget(delaySpinBoxLabel, 0, 0);
+ optionsGroupBoxLayout->addWidget(delaySpinBox, 0, 1);
+ optionsGroupBoxLayout->addWidget(hideThisWindowCheckBox, 1, 0, 1, 2);
+ optionsGroupBox->setLayout(optionsGroupBoxLayout);
+}
+//! [7]
+
+//! [8]
+void Screenshot::createButtonsLayout()
+{
+ newScreenshotButton = createButton(tr("New Screenshot"),
+ this, SLOT(newScreenshot()));
+
+ saveScreenshotButton = createButton(tr("Save Screenshot"),
+ this, SLOT(saveScreenshot()));
+
+ quitScreenshotButton = createButton(tr("Quit"), this, SLOT(close()));
+
+ buttonsLayout = new QHBoxLayout;
+ buttonsLayout->addStretch();
+ buttonsLayout->addWidget(newScreenshotButton);
+ buttonsLayout->addWidget(saveScreenshotButton);
+ buttonsLayout->addWidget(quitScreenshotButton);
+}
+//! [8]
+
+//! [9]
+QPushButton *Screenshot::createButton(const QString &text, QWidget *receiver,
+ const char *member)
+{
+ QPushButton *button = new QPushButton(text);
+ button->connect(button, SIGNAL(clicked()), receiver, member);
+ return button;
+}
+//! [9]
+
+//! [10]
+void Screenshot::updateScreenshotLabel()
+{
+ screenshotLabel->setPixmap(originalPixmap.scaled(screenshotLabel->size(),
+ Qt::KeepAspectRatio,
+ Qt::SmoothTransformation));
+}
+//! [10]
diff --git a/examples/widgets/desktop/screenshot/screenshot.desktop b/examples/widgets/desktop/screenshot/screenshot.desktop
new file mode 100644
index 0000000000..236d360123
--- /dev/null
+++ b/examples/widgets/desktop/screenshot/screenshot.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Screenshot
+Exec=/opt/usr/bin/screenshot
+Icon=screenshot
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/desktop/screenshot/screenshot.h b/examples/widgets/desktop/screenshot/screenshot.h
new file mode 100644
index 0000000000..98251f3428
--- /dev/null
+++ b/examples/widgets/desktop/screenshot/screenshot.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SCREENSHOT_H
+#define SCREENSHOT_H
+
+#include <QPixmap>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QGridLayout;
+class QGroupBox;
+class QHBoxLayout;
+class QLabel;
+class QPushButton;
+class QSpinBox;
+class QVBoxLayout;
+QT_END_NAMESPACE
+
+//! [0]
+class Screenshot : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Screenshot();
+
+protected:
+ void resizeEvent(QResizeEvent *event);
+
+private slots:
+ void newScreenshot();
+ void saveScreenshot();
+ void shootScreen();
+ void updateCheckBox();
+
+private:
+ void createOptionsGroupBox();
+ void createButtonsLayout();
+ QPushButton *createButton(const QString &text, QWidget *receiver,
+ const char *member);
+ void updateScreenshotLabel();
+
+ QPixmap originalPixmap;
+
+ QLabel *screenshotLabel;
+ QGroupBox *optionsGroupBox;
+ QSpinBox *delaySpinBox;
+ QLabel *delaySpinBoxLabel;
+ QCheckBox *hideThisWindowCheckBox;
+ QPushButton *newScreenshotButton;
+ QPushButton *saveScreenshotButton;
+ QPushButton *quitScreenshotButton;
+
+ QVBoxLayout *mainLayout;
+ QGridLayout *optionsGroupBoxLayout;
+ QHBoxLayout *buttonsLayout;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/desktop/screenshot/screenshot.pro b/examples/widgets/desktop/screenshot/screenshot.pro
new file mode 100644
index 0000000000..e9f53f7450
--- /dev/null
+++ b/examples/widgets/desktop/screenshot/screenshot.pro
@@ -0,0 +1,12 @@
+HEADERS = screenshot.h
+SOURCES = main.cpp \
+ screenshot.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop/screenshot
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS screenshot.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop/screenshot
+INSTALLS += target sources
+
+QT += widgets
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/desktop/systray/images/bad.png b/examples/widgets/desktop/systray/images/bad.png
new file mode 100644
index 0000000000..c8701a241a
--- /dev/null
+++ b/examples/widgets/desktop/systray/images/bad.png
Binary files differ
diff --git a/examples/widgets/desktop/systray/images/heart.png b/examples/widgets/desktop/systray/images/heart.png
new file mode 100644
index 0000000000..cee1302b7d
--- /dev/null
+++ b/examples/widgets/desktop/systray/images/heart.png
Binary files differ
diff --git a/examples/widgets/desktop/systray/images/trash.png b/examples/widgets/desktop/systray/images/trash.png
new file mode 100644
index 0000000000..4c24db926d
--- /dev/null
+++ b/examples/widgets/desktop/systray/images/trash.png
Binary files differ
diff --git a/examples/widgets/desktop/systray/main.cpp b/examples/widgets/desktop/systray/main.cpp
new file mode 100644
index 0000000000..6695113f71
--- /dev/null
+++ b/examples/widgets/desktop/systray/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QMessageBox>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(systray);
+
+ QApplication app(argc, argv);
+
+ if (!QSystemTrayIcon::isSystemTrayAvailable()) {
+ QMessageBox::critical(0, QObject::tr("Systray"),
+ QObject::tr("I couldn't detect any system tray "
+ "on this system."));
+ return 1;
+ }
+ QApplication::setQuitOnLastWindowClosed(false);
+
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/desktop/systray/systray.desktop b/examples/widgets/desktop/systray/systray.desktop
new file mode 100644
index 0000000000..0490e71548
--- /dev/null
+++ b/examples/widgets/desktop/systray/systray.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=System Tray Icon
+Exec=/opt/usr/bin/systray
+Icon=systray
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/desktop/systray/systray.pro b/examples/widgets/desktop/systray/systray.pro
new file mode 100644
index 0000000000..5fdcf1f9c8
--- /dev/null
+++ b/examples/widgets/desktop/systray/systray.pro
@@ -0,0 +1,14 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+RESOURCES = systray.qrc
+
+QT += widgets
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop/systray
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS systray.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/desktop/systray
+INSTALLS += target sources
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/desktop/systray/systray.qrc b/examples/widgets/desktop/systray/systray.qrc
new file mode 100644
index 0000000000..a8b6535849
--- /dev/null
+++ b/examples/widgets/desktop/systray/systray.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>images/bad.png</file>
+ <file>images/heart.png</file>
+ <file>images/trash.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/desktop/systray/window.cpp b/examples/widgets/desktop/systray/window.cpp
new file mode 100644
index 0000000000..c75e3590ba
--- /dev/null
+++ b/examples/widgets/desktop/systray/window.cpp
@@ -0,0 +1,270 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "window.h"
+#include <QtGui>
+
+#include <QAction>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMenu>
+#include <QPushButton>
+#include <QSpinBox>
+#include <QTextEdit>
+#include <QVBoxLayout>
+#include <QMessageBox>
+
+//! [0]
+Window::Window()
+{
+ createIconGroupBox();
+ createMessageGroupBox();
+
+ iconLabel->setMinimumWidth(durationLabel->sizeHint().width());
+
+ createActions();
+ createTrayIcon();
+
+ connect(showMessageButton, SIGNAL(clicked()), this, SLOT(showMessage()));
+ connect(showIconCheckBox, SIGNAL(toggled(bool)),
+ trayIcon, SLOT(setVisible(bool)));
+ connect(iconComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(setIcon(int)));
+ connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
+ connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
+ this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(iconGroupBox);
+ mainLayout->addWidget(messageGroupBox);
+ setLayout(mainLayout);
+
+ iconComboBox->setCurrentIndex(1);
+ trayIcon->show();
+
+ setWindowTitle(tr("Systray"));
+ resize(400, 300);
+}
+//! [0]
+
+//! [1]
+void Window::setVisible(bool visible)
+{
+ minimizeAction->setEnabled(visible);
+ maximizeAction->setEnabled(!isMaximized());
+ restoreAction->setEnabled(isMaximized() || !visible);
+ QDialog::setVisible(visible);
+}
+//! [1]
+
+//! [2]
+void Window::closeEvent(QCloseEvent *event)
+{
+ if (trayIcon->isVisible()) {
+ QMessageBox::information(this, tr("Systray"),
+ tr("The program will keep running in the "
+ "system tray. To terminate the program, "
+ "choose <b>Quit</b> in the context menu "
+ "of the system tray entry."));
+ hide();
+ event->ignore();
+ }
+}
+//! [2]
+
+//! [3]
+void Window::setIcon(int index)
+{
+ QIcon icon = iconComboBox->itemIcon(index);
+ trayIcon->setIcon(icon);
+ setWindowIcon(icon);
+
+ trayIcon->setToolTip(iconComboBox->itemText(index));
+}
+//! [3]
+
+//! [4]
+void Window::iconActivated(QSystemTrayIcon::ActivationReason reason)
+{
+ switch (reason) {
+ case QSystemTrayIcon::Trigger:
+ case QSystemTrayIcon::DoubleClick:
+ iconComboBox->setCurrentIndex((iconComboBox->currentIndex() + 1)
+ % iconComboBox->count());
+ break;
+ case QSystemTrayIcon::MiddleClick:
+ showMessage();
+ break;
+ default:
+ ;
+ }
+}
+//! [4]
+
+//! [5]
+void Window::showMessage()
+{
+ QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(
+ typeComboBox->itemData(typeComboBox->currentIndex()).toInt());
+ trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), icon,
+ durationSpinBox->value() * 1000);
+}
+//! [5]
+
+//! [6]
+void Window::messageClicked()
+{
+ QMessageBox::information(0, tr("Systray"),
+ tr("Sorry, I already gave what help I could.\n"
+ "Maybe you should try asking a human?"));
+}
+//! [6]
+
+void Window::createIconGroupBox()
+{
+ iconGroupBox = new QGroupBox(tr("Tray Icon"));
+
+ iconLabel = new QLabel("Icon:");
+
+ iconComboBox = new QComboBox;
+ iconComboBox->addItem(QIcon(":/images/bad.png"), tr("Bad"));
+ iconComboBox->addItem(QIcon(":/images/heart.png"), tr("Heart"));
+ iconComboBox->addItem(QIcon(":/images/trash.png"), tr("Trash"));
+
+ showIconCheckBox = new QCheckBox(tr("Show icon"));
+ showIconCheckBox->setChecked(true);
+
+ QHBoxLayout *iconLayout = new QHBoxLayout;
+ iconLayout->addWidget(iconLabel);
+ iconLayout->addWidget(iconComboBox);
+ iconLayout->addStretch();
+ iconLayout->addWidget(showIconCheckBox);
+ iconGroupBox->setLayout(iconLayout);
+}
+
+void Window::createMessageGroupBox()
+{
+ messageGroupBox = new QGroupBox(tr("Balloon Message"));
+
+ typeLabel = new QLabel(tr("Type:"));
+
+ typeComboBox = new QComboBox;
+ typeComboBox->addItem(tr("None"), QSystemTrayIcon::NoIcon);
+ typeComboBox->addItem(style()->standardIcon(
+ QStyle::SP_MessageBoxInformation), tr("Information"),
+ QSystemTrayIcon::Information);
+ typeComboBox->addItem(style()->standardIcon(
+ QStyle::SP_MessageBoxWarning), tr("Warning"),
+ QSystemTrayIcon::Warning);
+ typeComboBox->addItem(style()->standardIcon(
+ QStyle::SP_MessageBoxCritical), tr("Critical"),
+ QSystemTrayIcon::Critical);
+ typeComboBox->setCurrentIndex(1);
+
+ durationLabel = new QLabel(tr("Duration:"));
+
+ durationSpinBox = new QSpinBox;
+ durationSpinBox->setRange(5, 60);
+ durationSpinBox->setSuffix(" s");
+ durationSpinBox->setValue(15);
+
+ durationWarningLabel = new QLabel(tr("(some systems might ignore this "
+ "hint)"));
+ durationWarningLabel->setIndent(10);
+
+ titleLabel = new QLabel(tr("Title:"));
+
+ titleEdit = new QLineEdit(tr("Cannot connect to network"));
+
+ bodyLabel = new QLabel(tr("Body:"));
+
+ bodyEdit = new QTextEdit;
+ bodyEdit->setPlainText(tr("Don't believe me. Honestly, I don't have a "
+ "clue.\nClick this balloon for details."));
+
+ showMessageButton = new QPushButton(tr("Show Message"));
+ showMessageButton->setDefault(true);
+
+ QGridLayout *messageLayout = new QGridLayout;
+ messageLayout->addWidget(typeLabel, 0, 0);
+ messageLayout->addWidget(typeComboBox, 0, 1, 1, 2);
+ messageLayout->addWidget(durationLabel, 1, 0);
+ messageLayout->addWidget(durationSpinBox, 1, 1);
+ messageLayout->addWidget(durationWarningLabel, 1, 2, 1, 3);
+ messageLayout->addWidget(titleLabel, 2, 0);
+ messageLayout->addWidget(titleEdit, 2, 1, 1, 4);
+ messageLayout->addWidget(bodyLabel, 3, 0);
+ messageLayout->addWidget(bodyEdit, 3, 1, 2, 4);
+ messageLayout->addWidget(showMessageButton, 5, 4);
+ messageLayout->setColumnStretch(3, 1);
+ messageLayout->setRowStretch(4, 1);
+ messageGroupBox->setLayout(messageLayout);
+}
+
+void Window::createActions()
+{
+ minimizeAction = new QAction(tr("Mi&nimize"), this);
+ connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
+
+ maximizeAction = new QAction(tr("Ma&ximize"), this);
+ connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
+
+ restoreAction = new QAction(tr("&Restore"), this);
+ connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
+
+ quitAction = new QAction(tr("&Quit"), this);
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+}
+
+void Window::createTrayIcon()
+{
+ trayIconMenu = new QMenu(this);
+ trayIconMenu->addAction(minimizeAction);
+ trayIconMenu->addAction(maximizeAction);
+ trayIconMenu->addAction(restoreAction);
+ trayIconMenu->addSeparator();
+ trayIconMenu->addAction(quitAction);
+
+ trayIcon = new QSystemTrayIcon(this);
+ trayIcon->setContextMenu(trayIconMenu);
+}
diff --git a/examples/widgets/desktop/systray/window.h b/examples/widgets/desktop/systray/window.h
new file mode 100644
index 0000000000..80b7a20754
--- /dev/null
+++ b/examples/widgets/desktop/systray/window.h
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QSystemTrayIcon>
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QCheckBox;
+class QComboBox;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QMenu;
+class QPushButton;
+class QSpinBox;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class Window : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+ void setVisible(bool visible);
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void setIcon(int index);
+ void iconActivated(QSystemTrayIcon::ActivationReason reason);
+ void showMessage();
+ void messageClicked();
+
+private:
+ void createIconGroupBox();
+ void createMessageGroupBox();
+ void createActions();
+ void createTrayIcon();
+
+ QGroupBox *iconGroupBox;
+ QLabel *iconLabel;
+ QComboBox *iconComboBox;
+ QCheckBox *showIconCheckBox;
+
+ QGroupBox *messageGroupBox;
+ QLabel *typeLabel;
+ QLabel *durationLabel;
+ QLabel *durationWarningLabel;
+ QLabel *titleLabel;
+ QLabel *bodyLabel;
+ QComboBox *typeComboBox;
+ QSpinBox *durationSpinBox;
+ QLineEdit *titleEdit;
+ QTextEdit *bodyEdit;
+ QPushButton *showMessageButton;
+
+ QAction *minimizeAction;
+ QAction *maximizeAction;
+ QAction *restoreAction;
+ QAction *quitAction;
+
+ QSystemTrayIcon *trayIcon;
+ QMenu *trayIconMenu;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/dialogs/README b/examples/widgets/dialogs/README
new file mode 100644
index 0000000000..090b011061
--- /dev/null
+++ b/examples/widgets/dialogs/README
@@ -0,0 +1,9 @@
+Qt includes standard dialogs for many common operations, such as file
+selection, printing, and color selection.
+
+Custom dialogs can also be created for specialized modal or modeless
+interactions with users.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/dialogs/classwizard/classwizard.cpp b/examples/widgets/dialogs/classwizard/classwizard.cpp
new file mode 100644
index 0000000000..eeb1fab55b
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/classwizard.cpp
@@ -0,0 +1,430 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "classwizard.h"
+
+//! [0] //! [1]
+ClassWizard::ClassWizard(QWidget *parent)
+ : QWizard(parent)
+{
+ addPage(new IntroPage);
+ addPage(new ClassInfoPage);
+ addPage(new CodeStylePage);
+ addPage(new OutputFilesPage);
+ addPage(new ConclusionPage);
+//! [0]
+
+ setPixmap(QWizard::BannerPixmap, QPixmap(":/images/banner.png"));
+ setPixmap(QWizard::BackgroundPixmap, QPixmap(":/images/background.png"));
+
+ setWindowTitle(tr("Class Wizard"));
+//! [2]
+}
+//! [1] //! [2]
+
+//! [3]
+void ClassWizard::accept()
+//! [3] //! [4]
+{
+ QByteArray className = field("className").toByteArray();
+ QByteArray baseClass = field("baseClass").toByteArray();
+ QByteArray macroName = field("macroName").toByteArray();
+ QByteArray baseInclude = field("baseInclude").toByteArray();
+
+ QString outputDir = field("outputDir").toString();
+ QString header = field("header").toString();
+ QString implementation = field("implementation").toString();
+//! [4]
+
+ QByteArray block;
+
+ if (field("comment").toBool()) {
+ block += "/*\n";
+ block += " " + header.toLatin1() + "\n";
+ block += "*/\n";
+ block += "\n";
+ }
+ if (field("protect").toBool()) {
+ block += "#ifndef " + macroName + "\n";
+ block += "#define " + macroName + "\n";
+ block += "\n";
+ }
+ if (field("includeBase").toBool()) {
+ block += "#include " + baseInclude + "\n";
+ block += "\n";
+ }
+
+ block += "class " + className;
+ if (!baseClass.isEmpty())
+ block += " : public " + baseClass;
+ block += "\n";
+ block += "{\n";
+
+ /* qmake ignore Q_OBJECT */
+
+ if (field("qobjectMacro").toBool()) {
+ block += " Q_OBJECT\n";
+ block += "\n";
+ }
+ block += "public:\n";
+
+ if (field("qobjectCtor").toBool()) {
+ block += " " + className + "(QObject *parent = 0);\n";
+ } else if (field("qwidgetCtor").toBool()) {
+ block += " " + className + "(QWidget *parent = 0);\n";
+ } else if (field("defaultCtor").toBool()) {
+ block += " " + className + "();\n";
+ if (field("copyCtor").toBool()) {
+ block += " " + className + "(const " + className + " &other);\n";
+ block += "\n";
+ block += " " + className + " &operator=" + "(const " + className
+ + " &other);\n";
+ }
+ }
+ block += "};\n";
+
+ if (field("protect").toBool()) {
+ block += "\n";
+ block += "#endif\n";
+ }
+
+ QFile headerFile(outputDir + "/" + header);
+ if (!headerFile.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(0, QObject::tr("Simple Wizard"),
+ QObject::tr("Cannot write file %1:\n%2")
+ .arg(headerFile.fileName())
+ .arg(headerFile.errorString()));
+ return;
+ }
+ headerFile.write(block);
+
+ block.clear();
+
+ if (field("comment").toBool()) {
+ block += "/*\n";
+ block += " " + implementation.toLatin1() + "\n";
+ block += "*/\n";
+ block += "\n";
+ }
+ block += "#include \"" + header.toLatin1() + "\"\n";
+ block += "\n";
+
+ if (field("qobjectCtor").toBool()) {
+ block += className + "::" + className + "(QObject *parent)\n";
+ block += " : " + baseClass + "(parent)\n";
+ block += "{\n";
+ block += "}\n";
+ } else if (field("qwidgetCtor").toBool()) {
+ block += className + "::" + className + "(QWidget *parent)\n";
+ block += " : " + baseClass + "(parent)\n";
+ block += "{\n";
+ block += "}\n";
+ } else if (field("defaultCtor").toBool()) {
+ block += className + "::" + className + "()\n";
+ block += "{\n";
+ block += " // missing code\n";
+ block += "}\n";
+
+ if (field("copyCtor").toBool()) {
+ block += "\n";
+ block += className + "::" + className + "(const " + className
+ + " &other)\n";
+ block += "{\n";
+ block += " *this = other;\n";
+ block += "}\n";
+ block += "\n";
+ block += className + " &" + className + "::operator=(const "
+ + className + " &other)\n";
+ block += "{\n";
+ if (!baseClass.isEmpty())
+ block += " " + baseClass + "::operator=(other);\n";
+ block += " // missing code\n";
+ block += " return *this;\n";
+ block += "}\n";
+ }
+ }
+
+ QFile implementationFile(outputDir + "/" + implementation);
+ if (!implementationFile.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(0, QObject::tr("Simple Wizard"),
+ QObject::tr("Cannot write file %1:\n%2")
+ .arg(implementationFile.fileName())
+ .arg(implementationFile.errorString()));
+ return;
+ }
+ implementationFile.write(block);
+
+//! [5]
+ QDialog::accept();
+//! [5] //! [6]
+}
+//! [6]
+
+//! [7]
+IntroPage::IntroPage(QWidget *parent)
+ : QWizardPage(parent)
+{
+ setTitle(tr("Introduction"));
+ setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark1.png"));
+
+ label = new QLabel(tr("This wizard will generate a skeleton C++ class "
+ "definition, including a few functions. You simply "
+ "need to specify the class name and set a few "
+ "options to produce a header file and an "
+ "implementation file for your new C++ class."));
+ label->setWordWrap(true);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(label);
+ setLayout(layout);
+}
+//! [7]
+
+//! [8] //! [9]
+ClassInfoPage::ClassInfoPage(QWidget *parent)
+ : QWizardPage(parent)
+{
+//! [8]
+ setTitle(tr("Class Information"));
+ setSubTitle(tr("Specify basic information about the class for which you "
+ "want to generate skeleton source code files."));
+ setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo1.png"));
+
+//! [10]
+ classNameLabel = new QLabel(tr("&Class name:"));
+ classNameLineEdit = new QLineEdit;
+ classNameLabel->setBuddy(classNameLineEdit);
+
+ baseClassLabel = new QLabel(tr("B&ase class:"));
+ baseClassLineEdit = new QLineEdit;
+ baseClassLabel->setBuddy(baseClassLineEdit);
+
+ qobjectMacroCheckBox = new QCheckBox(tr("Generate Q_OBJECT &macro"));
+
+//! [10]
+ groupBox = new QGroupBox(tr("C&onstructor"));
+//! [9]
+
+ qobjectCtorRadioButton = new QRadioButton(tr("&QObject-style constructor"));
+ qwidgetCtorRadioButton = new QRadioButton(tr("Q&Widget-style constructor"));
+ defaultCtorRadioButton = new QRadioButton(tr("&Default constructor"));
+ copyCtorCheckBox = new QCheckBox(tr("&Generate copy constructor and "
+ "operator="));
+
+ defaultCtorRadioButton->setChecked(true);
+
+ connect(defaultCtorRadioButton, SIGNAL(toggled(bool)),
+ copyCtorCheckBox, SLOT(setEnabled(bool)));
+
+//! [11] //! [12]
+ registerField("className*", classNameLineEdit);
+ registerField("baseClass", baseClassLineEdit);
+ registerField("qobjectMacro", qobjectMacroCheckBox);
+//! [11]
+ registerField("qobjectCtor", qobjectCtorRadioButton);
+ registerField("qwidgetCtor", qwidgetCtorRadioButton);
+ registerField("defaultCtor", defaultCtorRadioButton);
+ registerField("copyCtor", copyCtorCheckBox);
+
+ QVBoxLayout *groupBoxLayout = new QVBoxLayout;
+//! [12]
+ groupBoxLayout->addWidget(qobjectCtorRadioButton);
+ groupBoxLayout->addWidget(qwidgetCtorRadioButton);
+ groupBoxLayout->addWidget(defaultCtorRadioButton);
+ groupBoxLayout->addWidget(copyCtorCheckBox);
+ groupBox->setLayout(groupBoxLayout);
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(classNameLabel, 0, 0);
+ layout->addWidget(classNameLineEdit, 0, 1);
+ layout->addWidget(baseClassLabel, 1, 0);
+ layout->addWidget(baseClassLineEdit, 1, 1);
+ layout->addWidget(qobjectMacroCheckBox, 2, 0, 1, 2);
+ layout->addWidget(groupBox, 3, 0, 1, 2);
+ setLayout(layout);
+//! [13]
+}
+//! [13]
+
+//! [14]
+CodeStylePage::CodeStylePage(QWidget *parent)
+ : QWizardPage(parent)
+{
+ setTitle(tr("Code Style Options"));
+ setSubTitle(tr("Choose the formatting of the generated code."));
+ setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo2.png"));
+
+ commentCheckBox = new QCheckBox(tr("&Start generated files with a "
+//! [14]
+ "comment"));
+ commentCheckBox->setChecked(true);
+
+ protectCheckBox = new QCheckBox(tr("&Protect header file against multiple "
+ "inclusions"));
+ protectCheckBox->setChecked(true);
+
+ macroNameLabel = new QLabel(tr("&Macro name:"));
+ macroNameLineEdit = new QLineEdit;
+ macroNameLabel->setBuddy(macroNameLineEdit);
+
+ includeBaseCheckBox = new QCheckBox(tr("&Include base class definition"));
+ baseIncludeLabel = new QLabel(tr("Base class include:"));
+ baseIncludeLineEdit = new QLineEdit;
+ baseIncludeLabel->setBuddy(baseIncludeLineEdit);
+
+ connect(protectCheckBox, SIGNAL(toggled(bool)),
+ macroNameLabel, SLOT(setEnabled(bool)));
+ connect(protectCheckBox, SIGNAL(toggled(bool)),
+ macroNameLineEdit, SLOT(setEnabled(bool)));
+ connect(includeBaseCheckBox, SIGNAL(toggled(bool)),
+ baseIncludeLabel, SLOT(setEnabled(bool)));
+ connect(includeBaseCheckBox, SIGNAL(toggled(bool)),
+ baseIncludeLineEdit, SLOT(setEnabled(bool)));
+
+ registerField("comment", commentCheckBox);
+ registerField("protect", protectCheckBox);
+ registerField("macroName", macroNameLineEdit);
+ registerField("includeBase", includeBaseCheckBox);
+ registerField("baseInclude", baseIncludeLineEdit);
+
+ QGridLayout *layout = new QGridLayout;
+ layout->setColumnMinimumWidth(0, 20);
+ layout->addWidget(commentCheckBox, 0, 0, 1, 3);
+ layout->addWidget(protectCheckBox, 1, 0, 1, 3);
+ layout->addWidget(macroNameLabel, 2, 1);
+ layout->addWidget(macroNameLineEdit, 2, 2);
+ layout->addWidget(includeBaseCheckBox, 3, 0, 1, 3);
+ layout->addWidget(baseIncludeLabel, 4, 1);
+ layout->addWidget(baseIncludeLineEdit, 4, 2);
+//! [15]
+ setLayout(layout);
+}
+//! [15]
+
+//! [16]
+void CodeStylePage::initializePage()
+{
+ QString className = field("className").toString();
+ macroNameLineEdit->setText(className.toUpper() + "_H");
+
+ QString baseClass = field("baseClass").toString();
+
+ includeBaseCheckBox->setChecked(!baseClass.isEmpty());
+ includeBaseCheckBox->setEnabled(!baseClass.isEmpty());
+ baseIncludeLabel->setEnabled(!baseClass.isEmpty());
+ baseIncludeLineEdit->setEnabled(!baseClass.isEmpty());
+
+ if (baseClass.isEmpty()) {
+ baseIncludeLineEdit->clear();
+ } else if (QRegExp("Q[A-Z].*").exactMatch(baseClass)) {
+ baseIncludeLineEdit->setText("<" + baseClass + ">");
+ } else {
+ baseIncludeLineEdit->setText("\"" + baseClass.toLower() + ".h\"");
+ }
+}
+//! [16]
+
+OutputFilesPage::OutputFilesPage(QWidget *parent)
+ : QWizardPage(parent)
+{
+ setTitle(tr("Output Files"));
+ setSubTitle(tr("Specify where you want the wizard to put the generated "
+ "skeleton code."));
+ setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo3.png"));
+
+ outputDirLabel = new QLabel(tr("&Output directory:"));
+ outputDirLineEdit = new QLineEdit;
+ outputDirLabel->setBuddy(outputDirLineEdit);
+
+ headerLabel = new QLabel(tr("&Header file name:"));
+ headerLineEdit = new QLineEdit;
+ headerLabel->setBuddy(headerLineEdit);
+
+ implementationLabel = new QLabel(tr("&Implementation file name:"));
+ implementationLineEdit = new QLineEdit;
+ implementationLabel->setBuddy(implementationLineEdit);
+
+ registerField("outputDir*", outputDirLineEdit);
+ registerField("header*", headerLineEdit);
+ registerField("implementation*", implementationLineEdit);
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(outputDirLabel, 0, 0);
+ layout->addWidget(outputDirLineEdit, 0, 1);
+ layout->addWidget(headerLabel, 1, 0);
+ layout->addWidget(headerLineEdit, 1, 1);
+ layout->addWidget(implementationLabel, 2, 0);
+ layout->addWidget(implementationLineEdit, 2, 1);
+ setLayout(layout);
+}
+
+//! [17]
+void OutputFilesPage::initializePage()
+{
+ QString className = field("className").toString();
+ headerLineEdit->setText(className.toLower() + ".h");
+ implementationLineEdit->setText(className.toLower() + ".cpp");
+ outputDirLineEdit->setText(QDir::toNativeSeparators(QDir::tempPath()));
+}
+//! [17]
+
+ConclusionPage::ConclusionPage(QWidget *parent)
+ : QWizardPage(parent)
+{
+ setTitle(tr("Conclusion"));
+ setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark2.png"));
+
+ label = new QLabel;
+ label->setWordWrap(true);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(label);
+ setLayout(layout);
+}
+
+void ConclusionPage::initializePage()
+{
+ QString finishText = wizard()->buttonText(QWizard::FinishButton);
+ finishText.remove('&');
+ label->setText(tr("Click %1 to generate the class skeleton.")
+ .arg(finishText));
+}
diff --git a/examples/widgets/dialogs/classwizard/classwizard.desktop b/examples/widgets/dialogs/classwizard/classwizard.desktop
new file mode 100644
index 0000000000..7f7d232092
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/classwizard.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Class Wizard
+Exec=/opt/usr/bin/classwizard
+Icon=classwizard
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/dialogs/classwizard/classwizard.h b/examples/widgets/dialogs/classwizard/classwizard.h
new file mode 100644
index 0000000000..332025f207
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/classwizard.h
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CLASSWIZARD_H
+#define CLASSWIZARD_H
+
+#include <QWizard>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QRadioButton;
+QT_END_NAMESPACE
+
+//! [0]
+class ClassWizard : public QWizard
+{
+ Q_OBJECT
+
+public:
+ ClassWizard(QWidget *parent = 0);
+
+ void accept();
+};
+//! [0]
+
+//! [1]
+class IntroPage : public QWizardPage
+{
+ Q_OBJECT
+
+public:
+ IntroPage(QWidget *parent = 0);
+
+private:
+ QLabel *label;
+};
+//! [1]
+
+//! [2]
+class ClassInfoPage : public QWizardPage
+{
+ Q_OBJECT
+
+public:
+ ClassInfoPage(QWidget *parent = 0);
+
+private:
+ QLabel *classNameLabel;
+ QLabel *baseClassLabel;
+ QLineEdit *classNameLineEdit;
+ QLineEdit *baseClassLineEdit;
+ QCheckBox *qobjectMacroCheckBox;
+ QGroupBox *groupBox;
+ QRadioButton *qobjectCtorRadioButton;
+ QRadioButton *qwidgetCtorRadioButton;
+ QRadioButton *defaultCtorRadioButton;
+ QCheckBox *copyCtorCheckBox;
+};
+//! [2]
+
+//! [3]
+class CodeStylePage : public QWizardPage
+{
+ Q_OBJECT
+
+public:
+ CodeStylePage(QWidget *parent = 0);
+
+protected:
+ void initializePage();
+
+private:
+ QCheckBox *commentCheckBox;
+ QCheckBox *protectCheckBox;
+ QCheckBox *includeBaseCheckBox;
+ QLabel *macroNameLabel;
+ QLabel *baseIncludeLabel;
+ QLineEdit *macroNameLineEdit;
+ QLineEdit *baseIncludeLineEdit;
+};
+//! [3]
+
+class OutputFilesPage : public QWizardPage
+{
+ Q_OBJECT
+
+public:
+ OutputFilesPage(QWidget *parent = 0);
+
+protected:
+ void initializePage();
+
+private:
+ QLabel *outputDirLabel;
+ QLabel *headerLabel;
+ QLabel *implementationLabel;
+ QLineEdit *outputDirLineEdit;
+ QLineEdit *headerLineEdit;
+ QLineEdit *implementationLineEdit;
+};
+
+class ConclusionPage : public QWizardPage
+{
+ Q_OBJECT
+
+public:
+ ConclusionPage(QWidget *parent = 0);
+
+protected:
+ void initializePage();
+
+private:
+ QLabel *label;
+};
+
+#endif
diff --git a/examples/widgets/dialogs/classwizard/classwizard.pro b/examples/widgets/dialogs/classwizard/classwizard.pro
new file mode 100644
index 0000000000..d50ba675af
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/classwizard.pro
@@ -0,0 +1,13 @@
+HEADERS = classwizard.h
+SOURCES = classwizard.cpp \
+ main.cpp
+RESOURCES = classwizard.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/classwizard
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/classwizard
+INSTALLS += target sources
+
+QT += widgets
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/dialogs/classwizard/classwizard.qrc b/examples/widgets/dialogs/classwizard/classwizard.qrc
new file mode 100644
index 0000000000..41a5ddc7d1
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/classwizard.qrc
@@ -0,0 +1,11 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/background.png</file>
+ <file>images/banner.png</file>
+ <file>images/logo1.png</file>
+ <file>images/logo2.png</file>
+ <file>images/logo3.png</file>
+ <file>images/watermark1.png</file>
+ <file>images/watermark2.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/dialogs/classwizard/images/background.png b/examples/widgets/dialogs/classwizard/images/background.png
new file mode 100644
index 0000000000..44c7badb85
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/images/background.png
Binary files differ
diff --git a/examples/widgets/dialogs/classwizard/images/banner.png b/examples/widgets/dialogs/classwizard/images/banner.png
new file mode 100644
index 0000000000..3169152b8e
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/images/banner.png
Binary files differ
diff --git a/examples/widgets/dialogs/classwizard/images/logo1.png b/examples/widgets/dialogs/classwizard/images/logo1.png
new file mode 100644
index 0000000000..f9b594aafc
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/images/logo1.png
Binary files differ
diff --git a/examples/widgets/dialogs/classwizard/images/logo2.png b/examples/widgets/dialogs/classwizard/images/logo2.png
new file mode 100644
index 0000000000..5dcbd4669d
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/images/logo2.png
Binary files differ
diff --git a/examples/widgets/dialogs/classwizard/images/logo3.png b/examples/widgets/dialogs/classwizard/images/logo3.png
new file mode 100644
index 0000000000..9fd3ea2358
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/images/logo3.png
Binary files differ
diff --git a/examples/widgets/dialogs/classwizard/images/watermark1.png b/examples/widgets/dialogs/classwizard/images/watermark1.png
new file mode 100644
index 0000000000..0091f5c17a
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/images/watermark1.png
Binary files differ
diff --git a/examples/widgets/dialogs/classwizard/images/watermark2.png b/examples/widgets/dialogs/classwizard/images/watermark2.png
new file mode 100644
index 0000000000..3b88f2e360
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/images/watermark2.png
Binary files differ
diff --git a/examples/widgets/dialogs/classwizard/main.cpp b/examples/widgets/dialogs/classwizard/main.cpp
new file mode 100644
index 0000000000..03dd625ae4
--- /dev/null
+++ b/examples/widgets/dialogs/classwizard/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QTranslator>
+#include <QLocale>
+#include <QLibraryInfo>
+
+#include "classwizard.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(classwizard);
+
+ QApplication app(argc, argv);
+
+ QString translatorFileName = QLatin1String("qt_");
+ translatorFileName += QLocale::system().name();
+ QTranslator *translator = new QTranslator(&app);
+ if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+ app.installTranslator(translator);
+
+ ClassWizard wizard;
+ wizard.show();
+ return app.exec();
+}
diff --git a/examples/widgets/dialogs/configdialog/configdialog.cpp b/examples/widgets/dialogs/configdialog/configdialog.cpp
new file mode 100644
index 0000000000..2f70c816c4
--- /dev/null
+++ b/examples/widgets/dialogs/configdialog/configdialog.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "configdialog.h"
+#include "pages.h"
+
+ConfigDialog::ConfigDialog()
+{
+ contentsWidget = new QListWidget;
+ contentsWidget->setViewMode(QListView::IconMode);
+ contentsWidget->setIconSize(QSize(96, 84));
+ contentsWidget->setMovement(QListView::Static);
+ contentsWidget->setMaximumWidth(128);
+ contentsWidget->setSpacing(12);
+
+ pagesWidget = new QStackedWidget;
+ pagesWidget->addWidget(new ConfigurationPage);
+ pagesWidget->addWidget(new UpdatePage);
+ pagesWidget->addWidget(new QueryPage);
+
+ QPushButton *closeButton = new QPushButton(tr("Close"));
+
+ createIcons();
+ contentsWidget->setCurrentRow(0);
+
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+
+ QHBoxLayout *horizontalLayout = new QHBoxLayout;
+ horizontalLayout->addWidget(contentsWidget);
+ horizontalLayout->addWidget(pagesWidget, 1);
+
+ QHBoxLayout *buttonsLayout = new QHBoxLayout;
+ buttonsLayout->addStretch(1);
+ buttonsLayout->addWidget(closeButton);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(horizontalLayout);
+ mainLayout->addStretch(1);
+ mainLayout->addSpacing(12);
+ mainLayout->addLayout(buttonsLayout);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Config Dialog"));
+}
+
+void ConfigDialog::createIcons()
+{
+ QListWidgetItem *configButton = new QListWidgetItem(contentsWidget);
+ configButton->setIcon(QIcon(":/images/config.png"));
+ configButton->setText(tr("Configuration"));
+ configButton->setTextAlignment(Qt::AlignHCenter);
+ configButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+
+ QListWidgetItem *updateButton = new QListWidgetItem(contentsWidget);
+ updateButton->setIcon(QIcon(":/images/update.png"));
+ updateButton->setText(tr("Update"));
+ updateButton->setTextAlignment(Qt::AlignHCenter);
+ updateButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+
+ QListWidgetItem *queryButton = new QListWidgetItem(contentsWidget);
+ queryButton->setIcon(QIcon(":/images/query.png"));
+ queryButton->setText(tr("Query"));
+ queryButton->setTextAlignment(Qt::AlignHCenter);
+ queryButton->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+
+ connect(contentsWidget,
+ SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
+ this, SLOT(changePage(QListWidgetItem*,QListWidgetItem*)));
+}
+
+void ConfigDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
+{
+ if (!current)
+ current = previous;
+
+ pagesWidget->setCurrentIndex(contentsWidget->row(current));
+}
diff --git a/examples/widgets/dialogs/configdialog/configdialog.desktop b/examples/widgets/dialogs/configdialog/configdialog.desktop
new file mode 100644
index 0000000000..11a326813a
--- /dev/null
+++ b/examples/widgets/dialogs/configdialog/configdialog.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Config Dialog
+Exec=/opt/usr/bin/configdialog
+Icon=configdialog
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/dialogs/configdialog/configdialog.h b/examples/widgets/dialogs/configdialog/configdialog.h
new file mode 100644
index 0000000000..5b79e416ab
--- /dev/null
+++ b/examples/widgets/dialogs/configdialog/configdialog.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CONFIGDIALOG_H
+#define CONFIGDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QListWidget;
+class QListWidgetItem;
+class QStackedWidget;
+QT_END_NAMESPACE
+
+class ConfigDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ ConfigDialog();
+
+public slots:
+ void changePage(QListWidgetItem *current, QListWidgetItem *previous);
+
+private:
+ void createIcons();
+
+ QListWidget *contentsWidget;
+ QStackedWidget *pagesWidget;
+};
+
+#endif
diff --git a/examples/widgets/dialogs/configdialog/configdialog.pro b/examples/widgets/dialogs/configdialog/configdialog.pro
new file mode 100644
index 0000000000..643c2a238f
--- /dev/null
+++ b/examples/widgets/dialogs/configdialog/configdialog.pro
@@ -0,0 +1,17 @@
+HEADERS = configdialog.h \
+ pages.h
+SOURCES = configdialog.cpp \
+ main.cpp \
+ pages.cpp
+RESOURCES += configdialog.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/configdialog
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/configdialog
+INSTALLS += target sources
+
+wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib
+
+QT += widgets
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/dialogs/configdialog/configdialog.qrc b/examples/widgets/dialogs/configdialog/configdialog.qrc
new file mode 100644
index 0000000000..31d0d49666
--- /dev/null
+++ b/examples/widgets/dialogs/configdialog/configdialog.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/config.png</file>
+ <file>images/query.png</file>
+ <file>images/update.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/dialogs/configdialog/images/config.png b/examples/widgets/dialogs/configdialog/images/config.png
new file mode 100644
index 0000000000..5c14d5f470
--- /dev/null
+++ b/examples/widgets/dialogs/configdialog/images/config.png
Binary files differ
diff --git a/examples/widgets/dialogs/configdialog/images/query.png b/examples/widgets/dialogs/configdialog/images/query.png
new file mode 100644
index 0000000000..ea9e291eeb
--- /dev/null
+++ b/examples/widgets/dialogs/configdialog/images/query.png
Binary files differ
diff --git a/examples/widgets/dialogs/configdialog/images/update.png b/examples/widgets/dialogs/configdialog/images/update.png
new file mode 100644
index 0000000000..3cb8ba6c77
--- /dev/null
+++ b/examples/widgets/dialogs/configdialog/images/update.png
Binary files differ
diff --git a/examples/widgets/dialogs/configdialog/main.cpp b/examples/widgets/dialogs/configdialog/main.cpp
new file mode 100644
index 0000000000..42f3cf2f43
--- /dev/null
+++ b/examples/widgets/dialogs/configdialog/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "configdialog.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(configdialog);
+
+ QApplication app(argc, argv);
+ ConfigDialog dialog;
+ return dialog.exec();
+}
diff --git a/examples/widgets/dialogs/configdialog/pages.cpp b/examples/widgets/dialogs/configdialog/pages.cpp
new file mode 100644
index 0000000000..c89bc3c7c8
--- /dev/null
+++ b/examples/widgets/dialogs/configdialog/pages.cpp
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "pages.h"
+
+ConfigurationPage::ConfigurationPage(QWidget *parent)
+ : QWidget(parent)
+{
+ QGroupBox *configGroup = new QGroupBox(tr("Server configuration"));
+
+ QLabel *serverLabel = new QLabel(tr("Server:"));
+ QComboBox *serverCombo = new QComboBox;
+ serverCombo->addItem(tr("Qt (Australia)"));
+ serverCombo->addItem(tr("Qt (Germany)"));
+ serverCombo->addItem(tr("Qt (Norway)"));
+ serverCombo->addItem(tr("Qt (People's Republic of China)"));
+ serverCombo->addItem(tr("Qt (USA)"));
+
+ QHBoxLayout *serverLayout = new QHBoxLayout;
+ serverLayout->addWidget(serverLabel);
+ serverLayout->addWidget(serverCombo);
+
+ QVBoxLayout *configLayout = new QVBoxLayout;
+ configLayout->addLayout(serverLayout);
+ configGroup->setLayout(configLayout);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(configGroup);
+ mainLayout->addStretch(1);
+ setLayout(mainLayout);
+}
+
+UpdatePage::UpdatePage(QWidget *parent)
+ : QWidget(parent)
+{
+ QGroupBox *updateGroup = new QGroupBox(tr("Package selection"));
+ QCheckBox *systemCheckBox = new QCheckBox(tr("Update system"));
+ QCheckBox *appsCheckBox = new QCheckBox(tr("Update applications"));
+ QCheckBox *docsCheckBox = new QCheckBox(tr("Update documentation"));
+
+ QGroupBox *packageGroup = new QGroupBox(tr("Existing packages"));
+
+ QListWidget *packageList = new QListWidget;
+ QListWidgetItem *qtItem = new QListWidgetItem(packageList);
+ qtItem->setText(tr("Qt"));
+ QListWidgetItem *qsaItem = new QListWidgetItem(packageList);
+ qsaItem->setText(tr("QSA"));
+ QListWidgetItem *teamBuilderItem = new QListWidgetItem(packageList);
+ teamBuilderItem->setText(tr("Teambuilder"));
+
+ QPushButton *startUpdateButton = new QPushButton(tr("Start update"));
+
+ QVBoxLayout *updateLayout = new QVBoxLayout;
+ updateLayout->addWidget(systemCheckBox);
+ updateLayout->addWidget(appsCheckBox);
+ updateLayout->addWidget(docsCheckBox);
+ updateGroup->setLayout(updateLayout);
+
+ QVBoxLayout *packageLayout = new QVBoxLayout;
+ packageLayout->addWidget(packageList);
+ packageGroup->setLayout(packageLayout);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(updateGroup);
+ mainLayout->addWidget(packageGroup);
+ mainLayout->addSpacing(12);
+ mainLayout->addWidget(startUpdateButton);
+ mainLayout->addStretch(1);
+ setLayout(mainLayout);
+}
+
+QueryPage::QueryPage(QWidget *parent)
+ : QWidget(parent)
+{
+ QGroupBox *packagesGroup = new QGroupBox(tr("Look for packages"));
+
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ QLineEdit *nameEdit = new QLineEdit;
+
+ QLabel *dateLabel = new QLabel(tr("Released after:"));
+ QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate::currentDate());
+
+ QCheckBox *releasesCheckBox = new QCheckBox(tr("Releases"));
+ QCheckBox *upgradesCheckBox = new QCheckBox(tr("Upgrades"));
+
+ QSpinBox *hitsSpinBox = new QSpinBox;
+ hitsSpinBox->setPrefix(tr("Return up to "));
+ hitsSpinBox->setSuffix(tr(" results"));
+ hitsSpinBox->setSpecialValueText(tr("Return only the first result"));
+ hitsSpinBox->setMinimum(1);
+ hitsSpinBox->setMaximum(100);
+ hitsSpinBox->setSingleStep(10);
+
+ QPushButton *startQueryButton = new QPushButton(tr("Start query"));
+
+ QGridLayout *packagesLayout = new QGridLayout;
+ packagesLayout->addWidget(nameLabel, 0, 0);
+ packagesLayout->addWidget(nameEdit, 0, 1);
+ packagesLayout->addWidget(dateLabel, 1, 0);
+ packagesLayout->addWidget(dateEdit, 1, 1);
+ packagesLayout->addWidget(releasesCheckBox, 2, 0);
+ packagesLayout->addWidget(upgradesCheckBox, 3, 0);
+ packagesLayout->addWidget(hitsSpinBox, 4, 0, 1, 2);
+ packagesGroup->setLayout(packagesLayout);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(packagesGroup);
+ mainLayout->addSpacing(12);
+ mainLayout->addWidget(startQueryButton);
+ mainLayout->addStretch(1);
+ setLayout(mainLayout);
+}
diff --git a/examples/widgets/dialogs/configdialog/pages.h b/examples/widgets/dialogs/configdialog/pages.h
new file mode 100644
index 0000000000..938a2a74f7
--- /dev/null
+++ b/examples/widgets/dialogs/configdialog/pages.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PAGES_H
+#define PAGES_H
+
+#include <QWidget>
+
+class ConfigurationPage : public QWidget
+{
+public:
+ ConfigurationPage(QWidget *parent = 0);
+};
+
+class QueryPage : public QWidget
+{
+public:
+ QueryPage(QWidget *parent = 0);
+};
+
+class UpdatePage : public QWidget
+{
+public:
+ UpdatePage(QWidget *parent = 0);
+};
+
+#endif
diff --git a/examples/widgets/dialogs/dialogs.pro b/examples/widgets/dialogs/dialogs.pro
new file mode 100644
index 0000000000..a59e480efa
--- /dev/null
+++ b/examples/widgets/dialogs/dialogs.pro
@@ -0,0 +1,19 @@
+TEMPLATE = subdirs
+SUBDIRS = classwizard \
+ configdialog \
+ standarddialogs \
+ tabdialog \
+ trivialwizard
+
+!wince*: SUBDIRS += licensewizard \
+ extension \
+ findfiles
+
+wince*: SUBDIRS += sipdialog
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs
+INSTALLS += sources
+
+QT += widgets
diff --git a/examples/widgets/dialogs/extension/extension.desktop b/examples/widgets/dialogs/extension/extension.desktop
new file mode 100644
index 0000000000..374b1c8340
--- /dev/null
+++ b/examples/widgets/dialogs/extension/extension.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Extension
+Exec=/opt/usr/bin/extension
+Icon=extension
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/dialogs/extension/extension.pro b/examples/widgets/dialogs/extension/extension.pro
new file mode 100644
index 0000000000..7e11dda4ab
--- /dev/null
+++ b/examples/widgets/dialogs/extension/extension.pro
@@ -0,0 +1,12 @@
+HEADERS = finddialog.h
+SOURCES = finddialog.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/extension
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/extension
+INSTALLS += target sources
+
+QT += widgets
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/dialogs/extension/finddialog.cpp b/examples/widgets/dialogs/extension/finddialog.cpp
new file mode 100644
index 0000000000..c21ebf67c5
--- /dev/null
+++ b/examples/widgets/dialogs/extension/finddialog.cpp
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "finddialog.h"
+
+//! [0]
+FindDialog::FindDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ label = new QLabel(tr("Find &what:"));
+ lineEdit = new QLineEdit;
+ label->setBuddy(lineEdit);
+
+ caseCheckBox = new QCheckBox(tr("Match &case"));
+ fromStartCheckBox = new QCheckBox(tr("Search from &start"));
+ fromStartCheckBox->setChecked(true);
+
+//! [1]
+ findButton = new QPushButton(tr("&Find"));
+ findButton->setDefault(true);
+
+ moreButton = new QPushButton(tr("&More"));
+ moreButton->setCheckable(true);
+//! [0]
+ moreButton->setAutoDefault(false);
+
+//! [1]
+
+//! [2]
+ extension = new QWidget;
+
+ wholeWordsCheckBox = new QCheckBox(tr("&Whole words"));
+ backwardCheckBox = new QCheckBox(tr("Search &backward"));
+ searchSelectionCheckBox = new QCheckBox(tr("Search se&lection"));
+//! [2]
+
+//! [3]
+ buttonBox = new QDialogButtonBox(Qt::Vertical);
+ buttonBox->addButton(findButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(moreButton, QDialogButtonBox::ActionRole);
+
+ connect(moreButton, SIGNAL(toggled(bool)), extension, SLOT(setVisible(bool)));
+
+ QVBoxLayout *extensionLayout = new QVBoxLayout;
+ extensionLayout->setMargin(0);
+ extensionLayout->addWidget(wholeWordsCheckBox);
+ extensionLayout->addWidget(backwardCheckBox);
+ extensionLayout->addWidget(searchSelectionCheckBox);
+ extension->setLayout(extensionLayout);
+//! [3]
+
+//! [4]
+ QHBoxLayout *topLeftLayout = new QHBoxLayout;
+ topLeftLayout->addWidget(label);
+ topLeftLayout->addWidget(lineEdit);
+
+ QVBoxLayout *leftLayout = new QVBoxLayout;
+ leftLayout->addLayout(topLeftLayout);
+ leftLayout->addWidget(caseCheckBox);
+ leftLayout->addWidget(fromStartCheckBox);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->setSizeConstraint(QLayout::SetFixedSize);
+ mainLayout->addLayout(leftLayout, 0, 0);
+ mainLayout->addWidget(buttonBox, 0, 1);
+ mainLayout->addWidget(extension, 1, 0, 1, 2);
+ mainLayout->setRowStretch(2, 1);
+
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Extension"));
+//! [4] //! [5]
+ extension->hide();
+}
+//! [5]
diff --git a/examples/widgets/dialogs/extension/finddialog.h b/examples/widgets/dialogs/extension/finddialog.h
new file mode 100644
index 0000000000..5599ac2c09
--- /dev/null
+++ b/examples/widgets/dialogs/extension/finddialog.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FINDDIALOG_H
+#define FINDDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QDialogButtonBox;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QPushButton;
+QT_END_NAMESPACE
+
+//! [0]
+class FindDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FindDialog(QWidget *parent = 0);
+
+private:
+ QLabel *label;
+ QLineEdit *lineEdit;
+ QCheckBox *caseCheckBox;
+ QCheckBox *fromStartCheckBox;
+ QCheckBox *wholeWordsCheckBox;
+ QCheckBox *searchSelectionCheckBox;
+ QCheckBox *backwardCheckBox;
+ QDialogButtonBox *buttonBox;
+ QPushButton *findButton;
+ QPushButton *moreButton;
+ QWidget *extension;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/dialogs/extension/main.cpp b/examples/widgets/dialogs/extension/main.cpp
new file mode 100644
index 0000000000..f0eff079ed
--- /dev/null
+++ b/examples/widgets/dialogs/extension/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "finddialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ FindDialog dialog;
+
+ dialog.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/dialogs/findfiles/findfiles.desktop b/examples/widgets/dialogs/findfiles/findfiles.desktop
new file mode 100644
index 0000000000..04c91cd76d
--- /dev/null
+++ b/examples/widgets/dialogs/findfiles/findfiles.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Find Files
+Exec=/opt/usr/bin/findfiles
+Icon=findfiles
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/dialogs/findfiles/findfiles.pro b/examples/widgets/dialogs/findfiles/findfiles.pro
new file mode 100644
index 0000000000..51d1c0eed1
--- /dev/null
+++ b/examples/widgets/dialogs/findfiles/findfiles.pro
@@ -0,0 +1,11 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/findfiles
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/findfiles
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/groupbox/main.cpp b/examples/widgets/dialogs/findfiles/main.cpp
index dcbf1c0449..dcbf1c0449 100644
--- a/examples/widgets/groupbox/main.cpp
+++ b/examples/widgets/dialogs/findfiles/main.cpp
diff --git a/examples/widgets/dialogs/findfiles/window.cpp b/examples/widgets/dialogs/findfiles/window.cpp
new file mode 100644
index 0000000000..6b89436dc8
--- /dev/null
+++ b/examples/widgets/dialogs/findfiles/window.cpp
@@ -0,0 +1,247 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "window.h"
+
+//! [0]
+Window::Window(QWidget *parent)
+ : QWidget(parent)
+{
+ browseButton = createButton(tr("&Browse..."), SLOT(browse()));
+ findButton = createButton(tr("&Find"), SLOT(find()));
+
+ fileComboBox = createComboBox(tr("*"));
+ textComboBox = createComboBox();
+ directoryComboBox = createComboBox(QDir::currentPath());
+
+ fileLabel = new QLabel(tr("Named:"));
+ textLabel = new QLabel(tr("Containing text:"));
+ directoryLabel = new QLabel(tr("In directory:"));
+ filesFoundLabel = new QLabel;
+
+ createFilesTable();
+//! [0]
+
+//! [1]
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->setSizeConstraint(QLayout::SetNoConstraint);
+ mainLayout->addWidget(fileLabel, 0, 0);
+ mainLayout->addWidget(fileComboBox, 0, 1, 1, 2);
+ mainLayout->addWidget(textLabel, 1, 0);
+ mainLayout->addWidget(textComboBox, 1, 1, 1, 2);
+ mainLayout->addWidget(directoryLabel, 2, 0);
+ mainLayout->addWidget(directoryComboBox, 2, 1);
+ mainLayout->addWidget(browseButton, 2, 2);
+ mainLayout->addWidget(filesTable, 3, 0, 1, 3);
+ mainLayout->addWidget(filesFoundLabel, 4, 0, 1, 2);
+ mainLayout->addWidget(findButton, 4, 2);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Find Files"));
+ resize(700, 300);
+}
+//! [1]
+
+//! [2]
+void Window::browse()
+{
+ QString directory = QFileDialog::getExistingDirectory(this,
+ tr("Find Files"), QDir::currentPath());
+
+ if (!directory.isEmpty()) {
+ if (directoryComboBox->findText(directory) == -1)
+ directoryComboBox->addItem(directory);
+ directoryComboBox->setCurrentIndex(directoryComboBox->findText(directory));
+ }
+}
+//! [2]
+
+static void updateComboBox(QComboBox *comboBox)
+{
+ if (comboBox->findText(comboBox->currentText()) == -1)
+ comboBox->addItem(comboBox->currentText());
+}
+
+//! [3]
+void Window::find()
+{
+ filesTable->setRowCount(0);
+
+ QString fileName = fileComboBox->currentText();
+ QString text = textComboBox->currentText();
+ QString path = directoryComboBox->currentText();
+//! [3]
+
+ updateComboBox(fileComboBox);
+ updateComboBox(textComboBox);
+ updateComboBox(directoryComboBox);
+
+//! [4]
+ currentDir = QDir(path);
+ QStringList files;
+ if (fileName.isEmpty())
+ fileName = "*";
+ files = currentDir.entryList(QStringList(fileName),
+ QDir::Files | QDir::NoSymLinks);
+
+ if (!text.isEmpty())
+ files = findFiles(files, text);
+ showFiles(files);
+}
+//! [4]
+
+//! [5]
+QStringList Window::findFiles(const QStringList &files, const QString &text)
+{
+ QProgressDialog progressDialog(this);
+ progressDialog.setCancelButtonText(tr("&Cancel"));
+ progressDialog.setRange(0, files.size());
+ progressDialog.setWindowTitle(tr("Find Files"));
+
+//! [5] //! [6]
+ QStringList foundFiles;
+
+ for (int i = 0; i < files.size(); ++i) {
+ progressDialog.setValue(i);
+ progressDialog.setLabelText(tr("Searching file number %1 of %2...")
+ .arg(i).arg(files.size()));
+ qApp->processEvents();
+//! [6]
+
+ if (progressDialog.wasCanceled())
+ break;
+
+//! [7]
+ QFile file(currentDir.absoluteFilePath(files[i]));
+
+ if (file.open(QIODevice::ReadOnly)) {
+ QString line;
+ QTextStream in(&file);
+ while (!in.atEnd()) {
+ if (progressDialog.wasCanceled())
+ break;
+ line = in.readLine();
+ if (line.contains(text)) {
+ foundFiles << files[i];
+ break;
+ }
+ }
+ }
+ }
+ return foundFiles;
+}
+//! [7]
+
+//! [8]
+void Window::showFiles(const QStringList &files)
+{
+ for (int i = 0; i < files.size(); ++i) {
+ QFile file(currentDir.absoluteFilePath(files[i]));
+ qint64 size = QFileInfo(file).size();
+
+ QTableWidgetItem *fileNameItem = new QTableWidgetItem(files[i]);
+ fileNameItem->setFlags(fileNameItem->flags() ^ Qt::ItemIsEditable);
+ QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("%1 KB")
+ .arg(int((size + 1023) / 1024)));
+ sizeItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
+ sizeItem->setFlags(sizeItem->flags() ^ Qt::ItemIsEditable);
+
+ int row = filesTable->rowCount();
+ filesTable->insertRow(row);
+ filesTable->setItem(row, 0, fileNameItem);
+ filesTable->setItem(row, 1, sizeItem);
+ }
+ filesFoundLabel->setText(tr("%1 file(s) found").arg(files.size()) +
+ (" (Double click on a file to open it)"));
+ filesFoundLabel->setWordWrap(true);
+}
+//! [8]
+
+//! [9]
+QPushButton *Window::createButton(const QString &text, const char *member)
+{
+ QPushButton *button = new QPushButton(text);
+ connect(button, SIGNAL(clicked()), this, member);
+ return button;
+}
+//! [9]
+
+//! [10]
+QComboBox *Window::createComboBox(const QString &text)
+{
+ QComboBox *comboBox = new QComboBox;
+ comboBox->setEditable(true);
+ comboBox->addItem(text);
+ comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ return comboBox;
+}
+//! [10]
+
+//! [11]
+void Window::createFilesTable()
+{
+ filesTable = new QTableWidget(0, 2);
+ filesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
+
+ QStringList labels;
+ labels << tr("Filename") << tr("Size");
+ filesTable->setHorizontalHeaderLabels(labels);
+ filesTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
+ filesTable->verticalHeader()->hide();
+ filesTable->setShowGrid(false);
+
+ connect(filesTable, SIGNAL(cellActivated(int,int)),
+ this, SLOT(openFileOfItem(int,int)));
+}
+//! [11]
+
+//! [12]
+
+void Window::openFileOfItem(int row, int /* column */)
+{
+ QTableWidgetItem *item = filesTable->item(row, 0);
+
+ QDesktopServices::openUrl(QUrl::fromLocalFile(currentDir.absoluteFilePath(item->text())));
+}
+
+//! [12]
+
diff --git a/examples/widgets/dialogs/findfiles/window.h b/examples/widgets/dialogs/findfiles/window.h
new file mode 100644
index 0000000000..0203de8a17
--- /dev/null
+++ b/examples/widgets/dialogs/findfiles/window.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+#include <QDir>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QLabel;
+class QPushButton;
+class QTableWidget;
+class QTableWidgetItem;
+QT_END_NAMESPACE
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window(QWidget *parent = 0);
+
+private slots:
+ void browse();
+ void find();
+ void openFileOfItem(int row, int column);
+
+private:
+ QStringList findFiles(const QStringList &files, const QString &text);
+ void showFiles(const QStringList &files);
+ QPushButton *createButton(const QString &text, const char *member);
+ QComboBox *createComboBox(const QString &text = QString());
+ void createFilesTable();
+
+ QComboBox *fileComboBox;
+ QComboBox *textComboBox;
+ QComboBox *directoryComboBox;
+ QLabel *fileLabel;
+ QLabel *textLabel;
+ QLabel *directoryLabel;
+ QLabel *filesFoundLabel;
+ QPushButton *browseButton;
+ QPushButton *findButton;
+ QTableWidget *filesTable;
+
+ QDir currentDir;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/dialogs/licensewizard/images/logo.png b/examples/widgets/dialogs/licensewizard/images/logo.png
new file mode 100644
index 0000000000..56f17a3e5a
--- /dev/null
+++ b/examples/widgets/dialogs/licensewizard/images/logo.png
Binary files differ
diff --git a/examples/widgets/dialogs/licensewizard/images/watermark.png b/examples/widgets/dialogs/licensewizard/images/watermark.png
new file mode 100644
index 0000000000..124a05068b
--- /dev/null
+++ b/examples/widgets/dialogs/licensewizard/images/watermark.png
Binary files differ
diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.cpp b/examples/widgets/dialogs/licensewizard/licensewizard.cpp
new file mode 100644
index 0000000000..501f8e310c
--- /dev/null
+++ b/examples/widgets/dialogs/licensewizard/licensewizard.cpp
@@ -0,0 +1,363 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include <QPrinter>
+#include <QPrintDialog>
+
+#include "licensewizard.h"
+
+//! [0] //! [1] //! [2]
+LicenseWizard::LicenseWizard(QWidget *parent)
+ : QWizard(parent)
+{
+//! [0]
+ setPage(Page_Intro, new IntroPage);
+ setPage(Page_Evaluate, new EvaluatePage);
+ setPage(Page_Register, new RegisterPage);
+ setPage(Page_Details, new DetailsPage);
+ setPage(Page_Conclusion, new ConclusionPage);
+//! [1]
+
+ setStartId(Page_Intro);
+//! [2]
+
+//! [3]
+#ifndef Q_OS_MAC
+//! [3] //! [4]
+ setWizardStyle(ModernStyle);
+#endif
+//! [4] //! [5]
+ setOption(HaveHelpButton, true);
+//! [5] //! [6]
+ setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo.png"));
+
+//! [7]
+ connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp()));
+//! [7]
+
+ setWindowTitle(tr("License Wizard"));
+//! [8]
+}
+//! [6] //! [8]
+
+//! [9] //! [10]
+void LicenseWizard::showHelp()
+//! [9] //! [11]
+{
+ static QString lastHelpMessage;
+
+ QString message;
+
+ switch (currentId()) {
+ case Page_Intro:
+ message = tr("The decision you make here will affect which page you "
+ "get to see next.");
+ break;
+//! [10] //! [11]
+ case Page_Evaluate:
+ message = tr("Make sure to provide a valid email address, such as "
+ "toni.buddenbrook@example.de.");
+ break;
+ case Page_Register:
+ message = tr("If you don't provide an upgrade key, you will be "
+ "asked to fill in your details.");
+ break;
+ case Page_Details:
+ message = tr("Make sure to provide a valid email address, such as "
+ "thomas.gradgrind@example.co.uk.");
+ break;
+ case Page_Conclusion:
+ message = tr("You must accept the terms and conditions of the "
+ "license to proceed.");
+ break;
+//! [12] //! [13]
+ default:
+ message = tr("This help is likely not to be of any help.");
+ }
+//! [12]
+
+ if (lastHelpMessage == message)
+ message = tr("Sorry, I already gave what help I could. "
+ "Maybe you should try asking a human?");
+
+//! [14]
+ QMessageBox::information(this, tr("License Wizard Help"), message);
+//! [14]
+
+ lastHelpMessage = message;
+//! [15]
+}
+//! [13] //! [15]
+
+//! [16]
+IntroPage::IntroPage(QWidget *parent)
+ : QWizardPage(parent)
+{
+ setTitle(tr("Introduction"));
+ setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark.png"));
+
+ topLabel = new QLabel(tr("This wizard will help you register your copy of "
+ "<i>Super Product One</i>&trade; or start "
+ "evaluating the product."));
+ topLabel->setWordWrap(true);
+
+ registerRadioButton = new QRadioButton(tr("&Register your copy"));
+ evaluateRadioButton = new QRadioButton(tr("&Evaluate the product for 30 "
+ "days"));
+ registerRadioButton->setChecked(true);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(topLabel);
+ layout->addWidget(registerRadioButton);
+ layout->addWidget(evaluateRadioButton);
+ setLayout(layout);
+}
+//! [16] //! [17]
+
+//! [18]
+int IntroPage::nextId() const
+//! [17] //! [19]
+{
+ if (evaluateRadioButton->isChecked()) {
+ return LicenseWizard::Page_Evaluate;
+ } else {
+ return LicenseWizard::Page_Register;
+ }
+}
+//! [18] //! [19]
+
+//! [20]
+EvaluatePage::EvaluatePage(QWidget *parent)
+ : QWizardPage(parent)
+{
+ setTitle(tr("Evaluate <i>Super Product One</i>&trade;"));
+ setSubTitle(tr("Please fill both fields. Make sure to provide a valid "
+ "email address (e.g., john.smith@example.com)."));
+
+ nameLabel = new QLabel(tr("N&ame:"));
+ nameLineEdit = new QLineEdit;
+//! [20]
+ nameLabel->setBuddy(nameLineEdit);
+
+ emailLabel = new QLabel(tr("&Email address:"));
+ emailLineEdit = new QLineEdit;
+ emailLineEdit->setValidator(new QRegExpValidator(QRegExp(".*@.*"), this));
+ emailLabel->setBuddy(emailLineEdit);
+
+//! [21]
+ registerField("evaluate.name*", nameLineEdit);
+ registerField("evaluate.email*", emailLineEdit);
+//! [21]
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(nameLabel, 0, 0);
+ layout->addWidget(nameLineEdit, 0, 1);
+ layout->addWidget(emailLabel, 1, 0);
+ layout->addWidget(emailLineEdit, 1, 1);
+ setLayout(layout);
+//! [22]
+}
+//! [22]
+
+//! [23]
+int EvaluatePage::nextId() const
+{
+ return LicenseWizard::Page_Conclusion;
+}
+//! [23]
+
+RegisterPage::RegisterPage(QWidget *parent)
+ : QWizardPage(parent)
+{
+ setTitle(tr("Register Your Copy of <i>Super Product One</i>&trade;"));
+ setSubTitle(tr("If you have an upgrade key, please fill in "
+ "the appropriate field."));
+
+ nameLabel = new QLabel(tr("N&ame:"));
+ nameLineEdit = new QLineEdit;
+ nameLabel->setBuddy(nameLineEdit);
+
+ upgradeKeyLabel = new QLabel(tr("&Upgrade key:"));
+ upgradeKeyLineEdit = new QLineEdit;
+ upgradeKeyLabel->setBuddy(upgradeKeyLineEdit);
+
+ registerField("register.name*", nameLineEdit);
+ registerField("register.upgradeKey", upgradeKeyLineEdit);
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(nameLabel, 0, 0);
+ layout->addWidget(nameLineEdit, 0, 1);
+ layout->addWidget(upgradeKeyLabel, 1, 0);
+ layout->addWidget(upgradeKeyLineEdit, 1, 1);
+ setLayout(layout);
+}
+
+//! [24]
+int RegisterPage::nextId() const
+{
+ if (upgradeKeyLineEdit->text().isEmpty()) {
+ return LicenseWizard::Page_Details;
+ } else {
+ return LicenseWizard::Page_Conclusion;
+ }
+}
+//! [24]
+
+DetailsPage::DetailsPage(QWidget *parent)
+ : QWizardPage(parent)
+{
+ setTitle(tr("Fill In Your Details"));
+ setSubTitle(tr("Please fill all three fields. Make sure to provide a valid "
+ "email address (e.g., tanaka.aya@example.co.jp)."));
+
+ companyLabel = new QLabel(tr("&Company name:"));
+ companyLineEdit = new QLineEdit;
+ companyLabel->setBuddy(companyLineEdit);
+
+ emailLabel = new QLabel(tr("&Email address:"));
+ emailLineEdit = new QLineEdit;
+ emailLineEdit->setValidator(new QRegExpValidator(QRegExp(".*@.*"), this));
+ emailLabel->setBuddy(emailLineEdit);
+
+ postalLabel = new QLabel(tr("&Postal address:"));
+ postalLineEdit = new QLineEdit;
+ postalLabel->setBuddy(postalLineEdit);
+
+ registerField("details.company*", companyLineEdit);
+ registerField("details.email*", emailLineEdit);
+ registerField("details.postal*", postalLineEdit);
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(companyLabel, 0, 0);
+ layout->addWidget(companyLineEdit, 0, 1);
+ layout->addWidget(emailLabel, 1, 0);
+ layout->addWidget(emailLineEdit, 1, 1);
+ layout->addWidget(postalLabel, 2, 0);
+ layout->addWidget(postalLineEdit, 2, 1);
+ setLayout(layout);
+}
+
+//! [25]
+int DetailsPage::nextId() const
+{
+ return LicenseWizard::Page_Conclusion;
+}
+//! [25]
+
+ConclusionPage::ConclusionPage(QWidget *parent)
+ : QWizardPage(parent)
+{
+ setTitle(tr("Complete Your Registration"));
+ setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark.png"));
+
+ bottomLabel = new QLabel;
+ bottomLabel->setWordWrap(true);
+
+ agreeCheckBox = new QCheckBox(tr("I agree to the terms of the license"));
+
+ registerField("conclusion.agree*", agreeCheckBox);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(bottomLabel);
+ layout->addWidget(agreeCheckBox);
+ setLayout(layout);
+}
+
+//! [26]
+int ConclusionPage::nextId() const
+{
+ return -1;
+}
+//! [26]
+
+//! [27]
+void ConclusionPage::initializePage()
+{
+ QString licenseText;
+
+ if (wizard()->hasVisitedPage(LicenseWizard::Page_Evaluate)) {
+ licenseText = tr("<u>Evaluation License Agreement:</u> "
+ "You can use this software for 30 days and make one "
+ "backup, but you are not allowed to distribute it.");
+ } else if (wizard()->hasVisitedPage(LicenseWizard::Page_Details)) {
+ licenseText = tr("<u>First-Time License Agreement:</u> "
+ "You can use this software subject to the license "
+ "you will receive by email.");
+ } else {
+ licenseText = tr("<u>Upgrade License Agreement:</u> "
+ "This software is licensed under the terms of your "
+ "current license.");
+ }
+ bottomLabel->setText(licenseText);
+}
+//! [27]
+
+//! [28]
+void ConclusionPage::setVisible(bool visible)
+{
+ QWizardPage::setVisible(visible);
+
+ if (visible) {
+//! [29]
+ wizard()->setButtonText(QWizard::CustomButton1, tr("&Print"));
+ wizard()->setOption(QWizard::HaveCustomButton1, true);
+ connect(wizard(), SIGNAL(customButtonClicked(int)),
+ this, SLOT(printButtonClicked()));
+//! [29]
+ } else {
+ wizard()->setOption(QWizard::HaveCustomButton1, false);
+ disconnect(wizard(), SIGNAL(customButtonClicked(int)),
+ this, SLOT(printButtonClicked()));
+ }
+}
+//! [28]
+
+void ConclusionPage::printButtonClicked()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer;
+ QPrintDialog dialog(&printer, this);
+ if (dialog.exec())
+ QMessageBox::warning(this, tr("Print License"),
+ tr("As an environmentally friendly measure, the "
+ "license text will not actually be printed."));
+#endif
+}
diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.desktop b/examples/widgets/dialogs/licensewizard/licensewizard.desktop
new file mode 100644
index 0000000000..423d81e9b3
--- /dev/null
+++ b/examples/widgets/dialogs/licensewizard/licensewizard.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=License Wizard
+Exec=/opt/usr/bin/licensewizard
+Icon=licensewizard
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.h b/examples/widgets/dialogs/licensewizard/licensewizard.h
new file mode 100644
index 0000000000..24ee45d6dd
--- /dev/null
+++ b/examples/widgets/dialogs/licensewizard/licensewizard.h
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LICENSEWIZARD_H
+#define LICENSEWIZARD_H
+
+#include <QWizard>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QLabel;
+class QLineEdit;
+class QRadioButton;
+QT_END_NAMESPACE
+
+//! [0] //! [1]
+class LicenseWizard : public QWizard
+{
+//! [0]
+ Q_OBJECT
+
+public:
+//! [2]
+ enum { Page_Intro, Page_Evaluate, Page_Register, Page_Details,
+ Page_Conclusion };
+//! [2]
+
+ LicenseWizard(QWidget *parent = 0);
+
+private slots:
+ void showHelp();
+//! [3]
+};
+//! [1] //! [3]
+
+//! [4]
+class IntroPage : public QWizardPage
+{
+ Q_OBJECT
+
+public:
+ IntroPage(QWidget *parent = 0);
+
+ int nextId() const;
+
+private:
+ QLabel *topLabel;
+ QRadioButton *registerRadioButton;
+ QRadioButton *evaluateRadioButton;
+};
+//! [4]
+
+//! [5]
+class EvaluatePage : public QWizardPage
+{
+ Q_OBJECT
+
+public:
+ EvaluatePage(QWidget *parent = 0);
+
+ int nextId() const;
+
+private:
+ QLabel *nameLabel;
+ QLabel *emailLabel;
+ QLineEdit *nameLineEdit;
+ QLineEdit *emailLineEdit;
+};
+//! [5]
+
+class RegisterPage : public QWizardPage
+{
+ Q_OBJECT
+
+public:
+ RegisterPage(QWidget *parent = 0);
+
+ int nextId() const;
+
+private:
+ QLabel *nameLabel;
+ QLabel *upgradeKeyLabel;
+ QLineEdit *nameLineEdit;
+ QLineEdit *upgradeKeyLineEdit;
+};
+
+class DetailsPage : public QWizardPage
+{
+ Q_OBJECT
+
+public:
+ DetailsPage(QWidget *parent = 0);
+
+ int nextId() const;
+
+private:
+ QLabel *companyLabel;
+ QLabel *emailLabel;
+ QLabel *postalLabel;
+ QLineEdit *companyLineEdit;
+ QLineEdit *emailLineEdit;
+ QLineEdit *postalLineEdit;
+};
+
+//! [6]
+class ConclusionPage : public QWizardPage
+{
+ Q_OBJECT
+
+public:
+ ConclusionPage(QWidget *parent = 0);
+
+ void initializePage();
+ int nextId() const;
+ void setVisible(bool visible);
+
+private slots:
+ void printButtonClicked();
+
+private:
+ QLabel *bottomLabel;
+ QCheckBox *agreeCheckBox;
+};
+//! [6]
+
+#endif
diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.pro b/examples/widgets/dialogs/licensewizard/licensewizard.pro
new file mode 100644
index 0000000000..c61325772e
--- /dev/null
+++ b/examples/widgets/dialogs/licensewizard/licensewizard.pro
@@ -0,0 +1,13 @@
+HEADERS = licensewizard.h
+SOURCES = licensewizard.cpp \
+ main.cpp
+RESOURCES = licensewizard.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/licensewizard
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/licensewizard
+INSTALLS += target sources
+
+QT += widgets printsupport
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.qrc b/examples/widgets/dialogs/licensewizard/licensewizard.qrc
new file mode 100644
index 0000000000..b069938515
--- /dev/null
+++ b/examples/widgets/dialogs/licensewizard/licensewizard.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/logo.png</file>
+ <file>images/watermark.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/dialogs/licensewizard/main.cpp b/examples/widgets/dialogs/licensewizard/main.cpp
new file mode 100644
index 0000000000..c7771d7676
--- /dev/null
+++ b/examples/widgets/dialogs/licensewizard/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QTranslator>
+#include <QLocale>
+#include <QLibraryInfo>
+
+#include "licensewizard.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(licensewizard);
+
+ QApplication app(argc, argv);
+
+ QString translatorFileName = QLatin1String("qt_");
+ translatorFileName += QLocale::system().name();
+ QTranslator *translator = new QTranslator(&app);
+ if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+ app.installTranslator(translator);
+
+ LicenseWizard wizard;
+ wizard.show();
+ return app.exec();
+}
diff --git a/examples/widgets/dialogs/sipdialog/dialog.cpp b/examples/widgets/dialogs/sipdialog/dialog.cpp
new file mode 100644
index 0000000000..fdfbc94ca4
--- /dev/null
+++ b/examples/widgets/dialogs/sipdialog/dialog.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "dialog.h"
+
+//! [Dialog constructor part1]
+Dialog::Dialog()
+{
+ desktopGeometry = QApplication::desktop()->availableGeometry(0);
+
+ setWindowTitle(tr("SIP Dialog Example"));
+ QScrollArea *scrollArea = new QScrollArea(this);
+ QGroupBox *groupBox = new QGroupBox(scrollArea);
+ groupBox->setTitle(tr("SIP Dialog Example"));
+ QGridLayout *gridLayout = new QGridLayout(groupBox);
+ groupBox->setLayout(gridLayout);
+//! [Dialog constructor part1]
+
+//! [Dialog constructor part2]
+ QLineEdit* lineEdit = new QLineEdit(groupBox);
+ lineEdit->setText(tr("Open and close the SIP"));
+ lineEdit->setMinimumWidth(220);
+
+ QLabel* label = new QLabel(groupBox);
+ label->setText(tr("This dialog resizes if the SIP is opened"));
+ label->setMinimumWidth(220);
+
+ QPushButton* button = new QPushButton(groupBox);
+ button->setText(tr("Close Dialog"));
+ button->setMinimumWidth(220);
+//! [Dialog constructor part2]
+
+//! [Dialog constructor part3]
+ if (desktopGeometry.height() < 400)
+ gridLayout->setVerticalSpacing(80);
+ else
+ gridLayout->setVerticalSpacing(150);
+
+ gridLayout->addWidget(label);
+ gridLayout->addWidget(lineEdit);
+ gridLayout->addWidget(button);
+//! [Dialog constructor part3]
+
+//! [Dialog constructor part4]
+ scrollArea->setWidget(groupBox);
+ QHBoxLayout* layout = new QHBoxLayout();
+ layout->addWidget(scrollArea);
+ setLayout(layout);
+ scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+//! [Dialog constructor part4]
+
+//! [Dialog constructor part5]
+ connect(button, SIGNAL(clicked()),
+ qApp, SLOT(closeAllWindows()));
+ connect(QApplication::desktop(), SIGNAL(workAreaResized(int)),
+ this, SLOT(desktopResized(int)));
+}
+//! [Dialog constructor part5]
+
+//! [desktopResized() function]
+void Dialog::desktopResized(int screen)
+{
+ if (screen != 0)
+ return;
+ reactToSIP();
+}
+//! [desktopResized() function]
+
+//! [reactToSIP() function]
+void Dialog::reactToSIP()
+{
+ QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
+
+ if (desktopGeometry != availableGeometry) {
+ if (windowState() | Qt::WindowMaximized)
+ setWindowState(windowState() & ~Qt::WindowMaximized);
+
+ setGeometry(availableGeometry);
+ }
+
+ desktopGeometry = availableGeometry;
+}
+//! [reactToSIP() function]
diff --git a/examples/widgets/dialogs/sipdialog/dialog.h b/examples/widgets/dialogs/sipdialog/dialog.h
new file mode 100644
index 0000000000..18eb92d857
--- /dev/null
+++ b/examples/widgets/dialogs/sipdialog/dialog.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QDialog>
+
+//! [Dialog header]
+class Dialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Dialog();
+ void reactToSIP();
+
+private:
+ QRect desktopGeometry;
+
+public slots:
+ void desktopResized(int screen);
+};
+//! [Dialog header]
+
+#endif
diff --git a/examples/widgets/dialogs/sipdialog/main.cpp b/examples/widgets/dialogs/sipdialog/main.cpp
new file mode 100644
index 0000000000..79fd956fb9
--- /dev/null
+++ b/examples/widgets/dialogs/sipdialog/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "dialog.h"
+
+//! [main() function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Dialog dialog;
+ return dialog.exec();
+}
+//! [main() function]
diff --git a/examples/widgets/dialogs/sipdialog/sipdialog.desktop b/examples/widgets/dialogs/sipdialog/sipdialog.desktop
new file mode 100644
index 0000000000..b9c9955339
--- /dev/null
+++ b/examples/widgets/dialogs/sipdialog/sipdialog.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=SIP Dialog
+Exec=/opt/usr/bin/sipdialog
+Icon=sipdialog
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/dialogs/sipdialog/sipdialog.pro b/examples/widgets/dialogs/sipdialog/sipdialog.pro
new file mode 100644
index 0000000000..72db93f646
--- /dev/null
+++ b/examples/widgets/dialogs/sipdialog/sipdialog.pro
@@ -0,0 +1,15 @@
+HEADERS = dialog.h
+SOURCES = main.cpp \
+ dialog.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/sipdialog
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/sipdialog
+INSTALLS += target sources
+
+wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib
+
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp
new file mode 100644
index 0000000000..bde96c516b
--- /dev/null
+++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp
@@ -0,0 +1,471 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "dialog.h"
+
+#define MESSAGE \
+ Dialog::tr("<p>Message boxes have a caption, a text, " \
+ "and any number of buttons, each with standard or custom texts." \
+ "<p>Click a button to close the message box. Pressing the Esc button " \
+ "will activate the detected escape button (if any).")
+
+
+class DialogOptionsWidget : public QGroupBox
+{
+public:
+ explicit DialogOptionsWidget(QWidget *parent = 0);
+
+ void addCheckBox(const QString &text, int value);
+ void addSpacer();
+ int value() const;
+
+private:
+ typedef QPair<QCheckBox *, int> CheckBoxEntry;
+ QVBoxLayout *layout;
+ QList<CheckBoxEntry> checkBoxEntries;
+};
+
+DialogOptionsWidget::DialogOptionsWidget(QWidget *parent) :
+ QGroupBox(parent) , layout(new QVBoxLayout)
+{
+ setTitle(Dialog::tr("Options"));
+ setLayout(layout);
+}
+
+void DialogOptionsWidget::addCheckBox(const QString &text, int value)
+{
+ QCheckBox *checkBox = new QCheckBox(text);
+ layout->addWidget(checkBox);
+ checkBoxEntries.append(CheckBoxEntry(checkBox, value));
+}
+
+void DialogOptionsWidget::addSpacer()
+{
+ layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
+}
+
+int DialogOptionsWidget::value() const
+{
+ int result = 0;
+ foreach (const CheckBoxEntry &checkboxEntry, checkBoxEntries)
+ if (checkboxEntry.first->isChecked())
+ result |= checkboxEntry.second;
+ return result;
+}
+
+Dialog::Dialog(QWidget *parent)
+ : QWidget(parent)
+{
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ QToolBox *toolbox = new QToolBox;
+ mainLayout->addWidget(toolbox);
+
+ errorMessageDialog = new QErrorMessage(this);
+
+ int frameStyle = QFrame::Sunken | QFrame::Panel;
+
+ integerLabel = new QLabel;
+ integerLabel->setFrameStyle(frameStyle);
+ QPushButton *integerButton =
+ new QPushButton(tr("QInputDialog::get&Int()"));
+
+ doubleLabel = new QLabel;
+ doubleLabel->setFrameStyle(frameStyle);
+ QPushButton *doubleButton =
+ new QPushButton(tr("QInputDialog::get&Double()"));
+
+ itemLabel = new QLabel;
+ itemLabel->setFrameStyle(frameStyle);
+ QPushButton *itemButton = new QPushButton(tr("QInputDialog::getIte&m()"));
+
+ textLabel = new QLabel;
+ textLabel->setFrameStyle(frameStyle);
+ QPushButton *textButton = new QPushButton(tr("QInputDialog::get&Text()"));
+
+ colorLabel = new QLabel;
+ colorLabel->setFrameStyle(frameStyle);
+ QPushButton *colorButton = new QPushButton(tr("QColorDialog::get&Color()"));
+
+ fontLabel = new QLabel;
+ fontLabel->setFrameStyle(frameStyle);
+ QPushButton *fontButton = new QPushButton(tr("QFontDialog::get&Font()"));
+
+ directoryLabel = new QLabel;
+ directoryLabel->setFrameStyle(frameStyle);
+ QPushButton *directoryButton =
+ new QPushButton(tr("QFileDialog::getE&xistingDirectory()"));
+
+ openFileNameLabel = new QLabel;
+ openFileNameLabel->setFrameStyle(frameStyle);
+ QPushButton *openFileNameButton =
+ new QPushButton(tr("QFileDialog::get&OpenFileName()"));
+
+ openFileNamesLabel = new QLabel;
+ openFileNamesLabel->setFrameStyle(frameStyle);
+ QPushButton *openFileNamesButton =
+ new QPushButton(tr("QFileDialog::&getOpenFileNames()"));
+
+ saveFileNameLabel = new QLabel;
+ saveFileNameLabel->setFrameStyle(frameStyle);
+ QPushButton *saveFileNameButton =
+ new QPushButton(tr("QFileDialog::get&SaveFileName()"));
+
+ criticalLabel = new QLabel;
+ criticalLabel->setFrameStyle(frameStyle);
+ QPushButton *criticalButton =
+ new QPushButton(tr("QMessageBox::critica&l()"));
+
+ informationLabel = new QLabel;
+ informationLabel->setFrameStyle(frameStyle);
+ QPushButton *informationButton =
+ new QPushButton(tr("QMessageBox::i&nformation()"));
+
+ questionLabel = new QLabel;
+ questionLabel->setFrameStyle(frameStyle);
+ QPushButton *questionButton =
+ new QPushButton(tr("QMessageBox::&question()"));
+
+ warningLabel = new QLabel;
+ warningLabel->setFrameStyle(frameStyle);
+ QPushButton *warningButton = new QPushButton(tr("QMessageBox::&warning()"));
+
+ errorLabel = new QLabel;
+ errorLabel->setFrameStyle(frameStyle);
+ QPushButton *errorButton =
+ new QPushButton(tr("QErrorMessage::showM&essage()"));
+
+ connect(integerButton, SIGNAL(clicked()), this, SLOT(setInteger()));
+ connect(doubleButton, SIGNAL(clicked()), this, SLOT(setDouble()));
+ connect(itemButton, SIGNAL(clicked()), this, SLOT(setItem()));
+ connect(textButton, SIGNAL(clicked()), this, SLOT(setText()));
+ connect(colorButton, SIGNAL(clicked()), this, SLOT(setColor()));
+ connect(fontButton, SIGNAL(clicked()), this, SLOT(setFont()));
+ connect(directoryButton, SIGNAL(clicked()),
+ this, SLOT(setExistingDirectory()));
+ connect(openFileNameButton, SIGNAL(clicked()),
+ this, SLOT(setOpenFileName()));
+ connect(openFileNamesButton, SIGNAL(clicked()),
+ this, SLOT(setOpenFileNames()));
+ connect(saveFileNameButton, SIGNAL(clicked()),
+ this, SLOT(setSaveFileName()));
+ connect(criticalButton, SIGNAL(clicked()), this, SLOT(criticalMessage()));
+ connect(informationButton, SIGNAL(clicked()),
+ this, SLOT(informationMessage()));
+ connect(questionButton, SIGNAL(clicked()), this, SLOT(questionMessage()));
+ connect(warningButton, SIGNAL(clicked()), this, SLOT(warningMessage()));
+ connect(errorButton, SIGNAL(clicked()), this, SLOT(errorMessage()));
+
+ QWidget *page = new QWidget;
+ QGridLayout *layout = new QGridLayout(page);
+ layout->setColumnStretch(1, 1);
+ layout->setColumnMinimumWidth(1, 250);
+ layout->addWidget(integerButton, 0, 0);
+ layout->addWidget(integerLabel, 0, 1);
+ layout->addWidget(doubleButton, 1, 0);
+ layout->addWidget(doubleLabel, 1, 1);
+ layout->addWidget(itemButton, 2, 0);
+ layout->addWidget(itemLabel, 2, 1);
+ layout->addWidget(textButton, 3, 0);
+ layout->addWidget(textLabel, 3, 1);
+ layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 4, 0);
+ toolbox->addItem(page, tr("Input Dialogs"));
+
+ const QString doNotUseNativeDialog = tr("Do not use native dialog");
+
+ page = new QWidget;
+ layout = new QGridLayout(page);
+ layout->setColumnStretch(1, 1);
+ layout->addWidget(colorButton, 0, 0);
+ layout->addWidget(colorLabel, 0, 1);
+ colorDialogOptionsWidget = new DialogOptionsWidget;
+ colorDialogOptionsWidget->addCheckBox(doNotUseNativeDialog, QColorDialog::DontUseNativeDialog);
+ colorDialogOptionsWidget->addCheckBox(tr("Show alpha channel") , QColorDialog::ShowAlphaChannel);
+ colorDialogOptionsWidget->addCheckBox(tr("No buttons") , QColorDialog::NoButtons);
+ layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 1, 0);
+ layout->addWidget(colorDialogOptionsWidget, 2, 0, 1 ,2);
+
+ toolbox->addItem(page, tr("Color Dialog"));
+
+ page = new QWidget;
+ layout = new QGridLayout(page);
+ layout->setColumnStretch(1, 1);
+ layout->addWidget(fontButton, 0, 0);
+ layout->addWidget(fontLabel, 0, 1);
+ fontDialogOptionsWidget = new DialogOptionsWidget;
+ fontDialogOptionsWidget->addCheckBox(doNotUseNativeDialog, QFontDialog::DontUseNativeDialog);
+ fontDialogOptionsWidget->addCheckBox(tr("No buttons") , QFontDialog::NoButtons);
+ layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 1, 0);
+ layout->addWidget(fontDialogOptionsWidget, 2, 0, 1 ,2);
+ toolbox->addItem(page, tr("Font Dialog"));
+
+ page = new QWidget;
+ layout = new QGridLayout(page);
+ layout->setColumnStretch(1, 1);
+ layout->addWidget(directoryButton, 0, 0);
+ layout->addWidget(directoryLabel, 0, 1);
+ layout->addWidget(openFileNameButton, 1, 0);
+ layout->addWidget(openFileNameLabel, 1, 1);
+ layout->addWidget(openFileNamesButton, 2, 0);
+ layout->addWidget(openFileNamesLabel, 2, 1);
+ layout->addWidget(saveFileNameButton, 3, 0);
+ layout->addWidget(saveFileNameLabel, 3, 1);
+ fileDialogOptionsWidget = new DialogOptionsWidget;
+ fileDialogOptionsWidget->addCheckBox(doNotUseNativeDialog, QFileDialog::DontUseNativeDialog);
+ fileDialogOptionsWidget->addCheckBox(tr("Show directories only"), QFileDialog::ShowDirsOnly);
+ fileDialogOptionsWidget->addCheckBox(tr("Do not resolve symlinks"), QFileDialog::DontResolveSymlinks);
+ fileDialogOptionsWidget->addCheckBox(tr("Do not confirm overwrite"), QFileDialog::DontConfirmOverwrite);
+ fileDialogOptionsWidget->addCheckBox(tr("Do not use sheet"), QFileDialog::DontUseSheet);
+ fileDialogOptionsWidget->addCheckBox(tr("Readonly"), QFileDialog::ReadOnly);
+ fileDialogOptionsWidget->addCheckBox(tr("Hide name filter details"), QFileDialog::HideNameFilterDetails);
+ layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 4, 0);
+ layout->addWidget(fileDialogOptionsWidget, 5, 0, 1 ,2);
+ toolbox->addItem(page, tr("File Dialogs"));
+
+ page = new QWidget;
+ layout = new QGridLayout(page);
+ layout->setColumnStretch(1, 1);
+ layout->addWidget(criticalButton, 0, 0);
+ layout->addWidget(criticalLabel, 0, 1);
+ layout->addWidget(informationButton, 1, 0);
+ layout->addWidget(informationLabel, 1, 1);
+ layout->addWidget(questionButton, 2, 0);
+ layout->addWidget(questionLabel, 2, 1);
+ layout->addWidget(warningButton, 3, 0);
+ layout->addWidget(warningLabel, 3, 1);
+ layout->addWidget(errorButton, 4, 0);
+ layout->addWidget(errorLabel, 4, 1);
+ layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding), 5, 0);
+ toolbox->addItem(page, tr("Message Boxes"));
+
+ setWindowTitle(tr("Standard Dialogs"));
+}
+
+void Dialog::setInteger()
+{
+//! [0]
+ bool ok;
+ int i = QInputDialog::getInt(this, tr("QInputDialog::getInteger()"),
+ tr("Percentage:"), 25, 0, 100, 1, &ok);
+ if (ok)
+ integerLabel->setText(tr("%1%").arg(i));
+//! [0]
+}
+
+void Dialog::setDouble()
+{
+//! [1]
+ bool ok;
+ double d = QInputDialog::getDouble(this, tr("QInputDialog::getDouble()"),
+ tr("Amount:"), 37.56, -10000, 10000, 2, &ok);
+ if (ok)
+ doubleLabel->setText(QString("$%1").arg(d));
+//! [1]
+}
+
+void Dialog::setItem()
+{
+//! [2]
+ QStringList items;
+ items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter");
+
+ bool ok;
+ QString item = QInputDialog::getItem(this, tr("QInputDialog::getItem()"),
+ tr("Season:"), items, 0, false, &ok);
+ if (ok && !item.isEmpty())
+ itemLabel->setText(item);
+//! [2]
+}
+
+void Dialog::setText()
+{
+//! [3]
+ bool ok;
+ QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
+ tr("User name:"), QLineEdit::Normal,
+ QDir::home().dirName(), &ok);
+ if (ok && !text.isEmpty())
+ textLabel->setText(text);
+//! [3]
+}
+
+void Dialog::setColor()
+{
+ const QColorDialog::ColorDialogOptions options = QFlag(colorDialogOptionsWidget->value());
+ const QColor color = QColorDialog::getColor(Qt::green, this, "Select Color", options);
+
+ if (color.isValid()) {
+ colorLabel->setText(color.name());
+ colorLabel->setPalette(QPalette(color));
+ colorLabel->setAutoFillBackground(true);
+ }
+}
+
+void Dialog::setFont()
+{
+ const QFontDialog::FontDialogOptions options = QFlag(fontDialogOptionsWidget->value());
+ bool ok;
+ QFont font = QFontDialog::getFont(&ok, QFont(fontLabel->text()), this, "Select Font", options);
+ if (ok) {
+ fontLabel->setText(font.key());
+ fontLabel->setFont(font);
+ }
+}
+
+void Dialog::setExistingDirectory()
+{
+ QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
+ options |= QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly;
+ QString directory = QFileDialog::getExistingDirectory(this,
+ tr("QFileDialog::getExistingDirectory()"),
+ directoryLabel->text(),
+ options);
+ if (!directory.isEmpty())
+ directoryLabel->setText(directory);
+}
+
+void Dialog::setOpenFileName()
+{
+ const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
+ QString selectedFilter;
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("QFileDialog::getOpenFileName()"),
+ openFileNameLabel->text(),
+ tr("All Files (*);;Text Files (*.txt)"),
+ &selectedFilter,
+ options);
+ if (!fileName.isEmpty())
+ openFileNameLabel->setText(fileName);
+}
+
+void Dialog::setOpenFileNames()
+{
+ const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
+ QString selectedFilter;
+ QStringList files = QFileDialog::getOpenFileNames(
+ this, tr("QFileDialog::getOpenFileNames()"),
+ openFilesPath,
+ tr("All Files (*);;Text Files (*.txt)"),
+ &selectedFilter,
+ options);
+ if (files.count()) {
+ openFilesPath = files[0];
+ openFileNamesLabel->setText(QString("[%1]").arg(files.join(", ")));
+ }
+}
+
+void Dialog::setSaveFileName()
+{
+ const QFileDialog::Options options = QFlag(fileDialogOptionsWidget->value());
+ QString selectedFilter;
+ QString fileName = QFileDialog::getSaveFileName(this,
+ tr("QFileDialog::getSaveFileName()"),
+ saveFileNameLabel->text(),
+ tr("All Files (*);;Text Files (*.txt)"),
+ &selectedFilter,
+ options);
+ if (!fileName.isEmpty())
+ saveFileNameLabel->setText(fileName);
+}
+
+void Dialog::criticalMessage()
+{
+ QMessageBox::StandardButton reply;
+ reply = QMessageBox::critical(this, tr("QMessageBox::critical()"),
+ MESSAGE,
+ QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore);
+ if (reply == QMessageBox::Abort)
+ criticalLabel->setText(tr("Abort"));
+ else if (reply == QMessageBox::Retry)
+ criticalLabel->setText(tr("Retry"));
+ else
+ criticalLabel->setText(tr("Ignore"));
+}
+
+void Dialog::informationMessage()
+{
+ QMessageBox::StandardButton reply;
+ reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE);
+ if (reply == QMessageBox::Ok)
+ informationLabel->setText(tr("OK"));
+ else
+ informationLabel->setText(tr("Escape"));
+}
+
+void Dialog::questionMessage()
+{
+ QMessageBox::StandardButton reply;
+ reply = QMessageBox::question(this, tr("QMessageBox::question()"),
+ MESSAGE,
+ QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
+ if (reply == QMessageBox::Yes)
+ questionLabel->setText(tr("Yes"));
+ else if (reply == QMessageBox::No)
+ questionLabel->setText(tr("No"));
+ else
+ questionLabel->setText(tr("Cancel"));
+}
+
+void Dialog::warningMessage()
+{
+ QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"),
+ MESSAGE, 0, this);
+ msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole);
+ msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole);
+ if (msgBox.exec() == QMessageBox::AcceptRole)
+ warningLabel->setText(tr("Save Again"));
+ else
+ warningLabel->setText(tr("Continue"));
+
+}
+
+void Dialog::errorMessage()
+{
+ errorMessageDialog->showMessage(
+ tr("This dialog shows and remembers error messages. "
+ "If the checkbox is checked (as it is by default), "
+ "the shown message will be shown again, "
+ "but if the user unchecks the box the message "
+ "will not appear again if QErrorMessage::showMessage() "
+ "is called with the same message."));
+ errorLabel->setText(tr("If the box is unchecked, the message "
+ "won't appear again."));
+}
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.h b/examples/widgets/dialogs/standarddialogs/dialog.h
new file mode 100644
index 0000000000..2b14d793d6
--- /dev/null
+++ b/examples/widgets/dialogs/standarddialogs/dialog.h
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QLabel;
+class QErrorMessage;
+QT_END_NAMESPACE
+
+class DialogOptionsWidget;
+
+class Dialog : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Dialog(QWidget *parent = 0);
+
+private slots:
+ void setInteger();
+ void setDouble();
+ void setItem();
+ void setText();
+ void setColor();
+ void setFont();
+ void setExistingDirectory();
+ void setOpenFileName();
+ void setOpenFileNames();
+ void setSaveFileName();
+ void criticalMessage();
+ void informationMessage();
+ void questionMessage();
+ void warningMessage();
+ void errorMessage();
+
+private:
+ QLabel *integerLabel;
+ QLabel *doubleLabel;
+ QLabel *itemLabel;
+ QLabel *textLabel;
+ QLabel *colorLabel;
+ QLabel *fontLabel;
+ QLabel *directoryLabel;
+ QLabel *openFileNameLabel;
+ QLabel *openFileNamesLabel;
+ QLabel *saveFileNameLabel;
+ QLabel *criticalLabel;
+ QLabel *informationLabel;
+ QLabel *questionLabel;
+ QLabel *warningLabel;
+ QLabel *errorLabel;
+ QErrorMessage *errorMessageDialog;
+ DialogOptionsWidget *fileDialogOptionsWidget;
+ DialogOptionsWidget *colorDialogOptionsWidget;
+ DialogOptionsWidget *fontDialogOptionsWidget;
+ QString openFilesPath;
+};
+
+#endif
diff --git a/examples/widgets/dialogs/standarddialogs/main.cpp b/examples/widgets/dialogs/standarddialogs/main.cpp
new file mode 100644
index 0000000000..001239929e
--- /dev/null
+++ b/examples/widgets/dialogs/standarddialogs/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QTranslator>
+#include <QLocale>
+#include <QLibraryInfo>
+
+#include "dialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QString translatorFileName = QLatin1String("qt_");
+ translatorFileName += QLocale::system().name();
+ QTranslator *translator = new QTranslator(&app);
+ if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+ app.installTranslator(translator);
+
+ Dialog dialog;
+ dialog.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/dialogs/standarddialogs/standarddialogs.desktop b/examples/widgets/dialogs/standarddialogs/standarddialogs.desktop
new file mode 100644
index 0000000000..f74830317a
--- /dev/null
+++ b/examples/widgets/dialogs/standarddialogs/standarddialogs.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Standard Dialogs
+Exec=/opt/usr/bin/standarddialogs
+Icon=standarddialogs
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/dialogs/standarddialogs/standarddialogs.pro b/examples/widgets/dialogs/standarddialogs/standarddialogs.pro
new file mode 100644
index 0000000000..cbcb4d7302
--- /dev/null
+++ b/examples/widgets/dialogs/standarddialogs/standarddialogs.pro
@@ -0,0 +1,13 @@
+HEADERS = dialog.h
+SOURCES = dialog.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/standarddialogs
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/standarddialogs
+INSTALLS += target sources
+
+wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib
+
+QT += widgets
diff --git a/examples/widgets/dialogs/tabdialog/main.cpp b/examples/widgets/dialogs/tabdialog/main.cpp
new file mode 100644
index 0000000000..119a4c272c
--- /dev/null
+++ b/examples/widgets/dialogs/tabdialog/main.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "tabdialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ QString fileName;
+
+ if (argc >= 2)
+ fileName = argv[1];
+ else
+ fileName = ".";
+
+ TabDialog tabdialog(fileName);
+ tabdialog.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.cpp b/examples/widgets/dialogs/tabdialog/tabdialog.cpp
new file mode 100644
index 0000000000..00e3706c5c
--- /dev/null
+++ b/examples/widgets/dialogs/tabdialog/tabdialog.cpp
@@ -0,0 +1,196 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "tabdialog.h"
+
+//! [0]
+TabDialog::TabDialog(const QString &fileName, QWidget *parent)
+ : QDialog(parent)
+{
+ QFileInfo fileInfo(fileName);
+
+ tabWidget = new QTabWidget;
+ tabWidget->addTab(new GeneralTab(fileInfo), tr("General"));
+ tabWidget->addTab(new PermissionsTab(fileInfo), tr("Permissions"));
+ tabWidget->addTab(new ApplicationsTab(fileInfo), tr("Applications"));
+//! [0]
+
+//! [1] //! [2]
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+//! [1] //! [3]
+ | QDialogButtonBox::Cancel);
+
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+//! [2] //! [3]
+
+//! [4]
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->setSizeConstraint(QLayout::SetNoConstraint);
+ mainLayout->addWidget(tabWidget);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+//! [4]
+
+//! [5]
+ setWindowTitle(tr("Tab Dialog"));
+}
+//! [5]
+
+//! [6]
+GeneralTab::GeneralTab(const QFileInfo &fileInfo, QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *fileNameLabel = new QLabel(tr("File Name:"));
+ QLineEdit *fileNameEdit = new QLineEdit(fileInfo.fileName());
+
+ QLabel *pathLabel = new QLabel(tr("Path:"));
+ QLabel *pathValueLabel = new QLabel(fileInfo.absoluteFilePath());
+ pathValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+
+ QLabel *sizeLabel = new QLabel(tr("Size:"));
+ qlonglong size = fileInfo.size()/1024;
+ QLabel *sizeValueLabel = new QLabel(tr("%1 K").arg(size));
+ sizeValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+
+ QLabel *lastReadLabel = new QLabel(tr("Last Read:"));
+ QLabel *lastReadValueLabel = new QLabel(fileInfo.lastRead().toString());
+ lastReadValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+
+ QLabel *lastModLabel = new QLabel(tr("Last Modified:"));
+ QLabel *lastModValueLabel = new QLabel(fileInfo.lastModified().toString());
+ lastModValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(fileNameLabel);
+ mainLayout->addWidget(fileNameEdit);
+ mainLayout->addWidget(pathLabel);
+ mainLayout->addWidget(pathValueLabel);
+ mainLayout->addWidget(sizeLabel);
+ mainLayout->addWidget(sizeValueLabel);
+ mainLayout->addWidget(lastReadLabel);
+ mainLayout->addWidget(lastReadValueLabel);
+ mainLayout->addWidget(lastModLabel);
+ mainLayout->addWidget(lastModValueLabel);
+ mainLayout->addStretch(1);
+ setLayout(mainLayout);
+}
+//! [6]
+
+//! [7]
+PermissionsTab::PermissionsTab(const QFileInfo &fileInfo, QWidget *parent)
+ : QWidget(parent)
+{
+ QGroupBox *permissionsGroup = new QGroupBox(tr("Permissions"));
+
+ QCheckBox *readable = new QCheckBox(tr("Readable"));
+ if (fileInfo.isReadable())
+ readable->setChecked(true);
+
+ QCheckBox *writable = new QCheckBox(tr("Writable"));
+ if ( fileInfo.isWritable() )
+ writable->setChecked(true);
+
+ QCheckBox *executable = new QCheckBox(tr("Executable"));
+ if ( fileInfo.isExecutable() )
+ executable->setChecked(true);
+
+ QGroupBox *ownerGroup = new QGroupBox(tr("Ownership"));
+
+ QLabel *ownerLabel = new QLabel(tr("Owner"));
+ QLabel *ownerValueLabel = new QLabel(fileInfo.owner());
+ ownerValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+
+ QLabel *groupLabel = new QLabel(tr("Group"));
+ QLabel *groupValueLabel = new QLabel(fileInfo.group());
+ groupValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+
+ QVBoxLayout *permissionsLayout = new QVBoxLayout;
+ permissionsLayout->addWidget(readable);
+ permissionsLayout->addWidget(writable);
+ permissionsLayout->addWidget(executable);
+ permissionsGroup->setLayout(permissionsLayout);
+
+ QVBoxLayout *ownerLayout = new QVBoxLayout;
+ ownerLayout->addWidget(ownerLabel);
+ ownerLayout->addWidget(ownerValueLabel);
+ ownerLayout->addWidget(groupLabel);
+ ownerLayout->addWidget(groupValueLabel);
+ ownerGroup->setLayout(ownerLayout);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(permissionsGroup);
+ mainLayout->addWidget(ownerGroup);
+ mainLayout->addStretch(1);
+ setLayout(mainLayout);
+}
+//! [7]
+
+//! [8]
+ApplicationsTab::ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *topLabel = new QLabel(tr("Open with:"));
+
+ QListWidget *applicationsListBox = new QListWidget;
+ QStringList applications;
+
+ for (int i = 1; i <= 30; ++i)
+ applications.append(tr("Application %1").arg(i));
+ applicationsListBox->insertItems(0, applications);
+
+ QCheckBox *alwaysCheckBox;
+
+ if (fileInfo.suffix().isEmpty())
+ alwaysCheckBox = new QCheckBox(tr("Always use this application to "
+ "open this type of file"));
+ else
+ alwaysCheckBox = new QCheckBox(tr("Always use this application to "
+ "open files with the extension '%1'").arg(fileInfo.suffix()));
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(topLabel);
+ layout->addWidget(applicationsListBox);
+ layout->addWidget(alwaysCheckBox);
+ setLayout(layout);
+}
+//! [8]
diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.desktop b/examples/widgets/dialogs/tabdialog/tabdialog.desktop
new file mode 100644
index 0000000000..651f7d4068
--- /dev/null
+++ b/examples/widgets/dialogs/tabdialog/tabdialog.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Tab Dialog
+Exec=/opt/usr/bin/tabdialog
+Icon=tabdialog
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.h b/examples/widgets/dialogs/tabdialog/tabdialog.h
new file mode 100644
index 0000000000..c2b46f0e92
--- /dev/null
+++ b/examples/widgets/dialogs/tabdialog/tabdialog.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TABDIALOG_H
+#define TABDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QFileInfo;
+class QTabWidget;
+QT_END_NAMESPACE
+
+//! [0]
+class GeneralTab : public QWidget
+{
+ Q_OBJECT
+
+public:
+ GeneralTab(const QFileInfo &fileInfo, QWidget *parent = 0);
+};
+//! [0]
+
+
+//! [1]
+class PermissionsTab : public QWidget
+{
+ Q_OBJECT
+
+public:
+ PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = 0);
+};
+//! [1]
+
+
+//! [2]
+class ApplicationsTab : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = 0);
+};
+//! [2]
+
+
+//! [3]
+class TabDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ TabDialog(const QString &fileName, QWidget *parent = 0);
+
+private:
+ QTabWidget *tabWidget;
+ QDialogButtonBox *buttonBox;
+};
+//! [3]
+
+#endif
diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.pro b/examples/widgets/dialogs/tabdialog/tabdialog.pro
new file mode 100644
index 0000000000..66ac14daf2
--- /dev/null
+++ b/examples/widgets/dialogs/tabdialog/tabdialog.pro
@@ -0,0 +1,12 @@
+HEADERS = tabdialog.h
+SOURCES = main.cpp \
+ tabdialog.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/tabdialog
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/tabdialog
+INSTALLS += target sources
+
+wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib
+QT += widgets
diff --git a/examples/widgets/dialogs/trivialwizard/trivialwizard.cpp b/examples/widgets/dialogs/trivialwizard/trivialwizard.cpp
new file mode 100644
index 0000000000..f8209405d9
--- /dev/null
+++ b/examples/widgets/dialogs/trivialwizard/trivialwizard.cpp
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include <QTranslator>
+#include <QLocale>
+#include <QLibraryInfo>
+
+//! [0] //! [1]
+QWizardPage *createIntroPage()
+{
+ QWizardPage *page = new QWizardPage;
+ page->setTitle("Introduction");
+
+ QLabel *label = new QLabel("This wizard will help you register your copy "
+ "of Super Product Two.");
+ label->setWordWrap(true);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(label);
+ page->setLayout(layout);
+
+ return page;
+}
+//! [0]
+
+//! [2]
+QWizardPage *createRegistrationPage()
+//! [1] //! [3]
+{
+//! [3]
+ QWizardPage *page = new QWizardPage;
+ page->setTitle("Registration");
+ page->setSubTitle("Please fill both fields.");
+
+ QLabel *nameLabel = new QLabel("Name:");
+ QLineEdit *nameLineEdit = new QLineEdit;
+
+ QLabel *emailLabel = new QLabel("Email address:");
+ QLineEdit *emailLineEdit = new QLineEdit;
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(nameLabel, 0, 0);
+ layout->addWidget(nameLineEdit, 0, 1);
+ layout->addWidget(emailLabel, 1, 0);
+ layout->addWidget(emailLineEdit, 1, 1);
+ page->setLayout(layout);
+
+ return page;
+//! [4]
+}
+//! [2] //! [4]
+
+//! [5] //! [6]
+QWizardPage *createConclusionPage()
+//! [5] //! [7]
+{
+//! [7]
+ QWizardPage *page = new QWizardPage;
+ page->setTitle("Conclusion");
+
+ QLabel *label = new QLabel("You are now successfully registered. Have a "
+ "nice day!");
+ label->setWordWrap(true);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(label);
+ page->setLayout(layout);
+
+ return page;
+//! [8]
+}
+//! [6] //! [8]
+
+//! [9] //! [10]
+int main(int argc, char *argv[])
+//! [9] //! [11]
+{
+ QApplication app(argc, argv);
+
+ QString translatorFileName = QLatin1String("qt_");
+ translatorFileName += QLocale::system().name();
+ QTranslator *translator = new QTranslator(&app);
+ if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+ app.installTranslator(translator);
+
+
+ QWizard wizard;
+ wizard.addPage(createIntroPage());
+ wizard.addPage(createRegistrationPage());
+ wizard.addPage(createConclusionPage());
+
+ wizard.setWindowTitle("Trivial Wizard");
+ wizard.show();
+
+ return app.exec();
+}
+//! [10] //! [11]
diff --git a/examples/widgets/dialogs/trivialwizard/trivialwizard.desktop b/examples/widgets/dialogs/trivialwizard/trivialwizard.desktop
new file mode 100644
index 0000000000..fad568ecc8
--- /dev/null
+++ b/examples/widgets/dialogs/trivialwizard/trivialwizard.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Trivial Wizard
+Exec=/opt/usr/bin/trivialwizard
+Icon=trivialwizard
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/dialogs/trivialwizard/trivialwizard.pro b/examples/widgets/dialogs/trivialwizard/trivialwizard.pro
new file mode 100644
index 0000000000..26d488d99d
--- /dev/null
+++ b/examples/widgets/dialogs/trivialwizard/trivialwizard.pro
@@ -0,0 +1,10 @@
+SOURCES = trivialwizard.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/trivialwizard
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs/trivialwizard
+INSTALLS += target sources
+
+QT += widgets
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/doc/addressbook.qdoc b/examples/widgets/doc/addressbook.qdoc
new file mode 100644
index 0000000000..9b4ede5775
--- /dev/null
+++ b/examples/widgets/doc/addressbook.qdoc
@@ -0,0 +1,442 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/addressbook
+ \title Address Book Example
+
+ The address book example shows how to use proxy models to display
+ different views onto data from a single model.
+
+ \image addressbook-example.png Screenshot of the Address Book example
+
+ This example provides an address book that allows contacts to be
+ grouped alphabetically into 9 groups: ABC, DEF, GHI, ... , VW,
+ ..., XYZ. This is achieved by using multiple views on the same
+ model, each of which is filtered using an instance of the
+ QSortFilterProxyModel class.
+
+
+ \section1 Overview
+
+ The address book contains 5 classes: \c MainWindow,
+ \c AddressWidget, \c TableModel, \c NewAddressTab and
+ \c AddDialog. The \c MainWindow class uses \c AddressWidget as
+ its central widget and provides \uicontrol File and \uicontrol Tools menus.
+
+ \image addressbook-classes.png Diagram for Address Book Example
+
+ The \c AddressWidget class is a QTabWidget subclass that is used
+ to manipulate the 10 tabs displayed in the example: the 9
+ alphabet group tabs and an instance of \c NewAddressTab.
+ The \c NewAddressTab class is a subclass of QWidget that
+ is only used whenever the address book is empty, prompting the
+ user to add some contacts. \c AddressWidget also interacts with
+ an instance of \c TableModel to add, edit and remove entries to
+ the address book.
+
+ \c TableModel is a subclass of QAbstractTableModel that provides
+ the standard model/view API to access data. It also holds a
+ QList of \l{QPair}s corresponding to the contacts added.
+ However, this data is not all visible in a single tab. Instead,
+ QTableView is used to provide 9 different views of the same
+ data, according to the alphabet groups.
+
+ QSortFilterProxyModel is the class responsible for filtering
+ the contacts for each group of contacts. Each proxy model uses
+ a QRegExp to filter out contacts that do not belong in the
+ corresponding alphabetical group. The \c AddDialog class is
+ used to obtain information from the user for the address book.
+ This QDialog subclass is instantiated by \c NewAddressTab to
+ add contacts, and by \c AddressWidget to add and edit contacts.
+
+ We begin by looking at the \c TableModel implementation.
+
+
+ \section1 TableModel Class Definition
+
+ The \c TableModel class provides standard API to access data in
+ its QList of \l{QPair}s by subclassing QAbstractTableModel. The
+ basic functions that must be implemented in order to do so are:
+ \c rowCount(), \c columnCount(), \c data(), \c headerData().
+ For TableModel to be editable, it has to provide implementations
+ \c insertRows(), \c removeRows(), \c setData() and \c flags()
+ functions.
+
+ \snippet itemviews/addressbook/tablemodel.h 0
+
+ Two constructors are used, a default constructor which uses
+ \c TableModel's own \c {QList<QPair<QString, QString>>} and one
+ that takes \c {QList<QPair<QString, QString>} as an argument,
+ for convenience.
+
+
+ \section1 TableModel Class Implementation
+
+ We implement the two constructors as defined in the header file.
+ The second constructor initializes the list of pairs in the
+ model, with the parameter value.
+
+ \snippet itemviews/addressbook/tablemodel.cpp 0
+
+ The \c rowCount() and \c columnCount() functions return the
+ dimensions of the model. Whereas, \c rowCount()'s value will vary
+ depending on the number of contacts added to the address book,
+ \c columnCount()'s value is always 2 because we only need space
+ for the \b Name and \b Address columns.
+
+ \note The \c Q_UNUSED() macro prevents the compiler from
+ generating warnings regarding unused parameters.
+
+ \snippet itemviews/addressbook/tablemodel.cpp 1
+
+ The \c data() function returns either a \b Name or
+ \b {Address}, based on the contents of the model index
+ supplied. The row number stored in the model index is used to
+ reference an item in the list of pairs. Selection is handled
+ by the QItemSelectionModel, which will be explained with
+ \c AddressWidget.
+
+ \snippet itemviews/addressbook/tablemodel.cpp 2
+
+ The \c headerData() function displays the table's header,
+ \b Name and \b Address. If you require numbered entries
+ for your address book, you can use a vertical header which we
+ have hidden in this example (see the \c AddressWidget
+ implementation).
+
+ \snippet itemviews/addressbook/tablemodel.cpp 3
+
+ The \c insertRows() function is called before new data is added,
+ otherwise the data will not be displayed. The
+ \c beginInsertRows() and \c endInsertRows() functions are called
+ to ensure all connected views are aware of the changes.
+
+ \snippet itemviews/addressbook/tablemodel.cpp 4
+
+ The \c removeRows() function is called to remove data. Again,
+ \l{QAbstractItemModel::}{beginRemoveRows()} and
+ \l{QAbstractItemModel::}{endRemoveRows()} are called to ensure
+ all connected views are aware of the changes.
+
+ \snippet itemviews/addressbook/tablemodel.cpp 5
+
+ The \c setData() function is the function that inserts data into
+ the table, item by item and not row by row. This means that to
+ fill a row in the address book, \c setData() must be called
+ twice, as each row has 2 columns. It is important to emit the
+ \l{QAbstractItemModel::}{dataChanged()} signal as it tells all
+ connected views to update their displays.
+
+ \snippet itemviews/addressbook/tablemodel.cpp 6
+
+ The \c flags() function returns the item flags for the given
+ index.
+
+ \snippet itemviews/addressbook/tablemodel.cpp 7
+
+ We set the Qt::ItemIsEditable flag because we want to allow the
+ \c TableModel to be edited. Although for this example we don't
+ use the editing features of the QTableView object, we enable
+ them here so that we can reuse the model in other programs.
+
+ The last function in \c {TableModel}, \c getList() returns the
+ QList<QPair<QString, QString>> object that holds all the
+ contacts in the address book. We use this function later to
+ obtain the list of contacts to check for existing entries, write
+ the contacts to a file and read them back. Further explanation is
+ given with \c AddressWidget.
+
+ \snippet itemviews/addressbook/tablemodel.cpp 8
+
+
+ \section1 AddressWidget Class Definition
+
+ The \c AddressWidget class is technically the main class
+ involved in this example as it provides functions to add, edit
+ and remove contacts, to save the contacts to a file and to load
+ them from a file.
+
+ \snippet itemviews/addressbook/addresswidget.h 0
+
+ \c AddressWidget extends QTabWidget in order to hold 10 tabs
+ (\c NewAddressTab and the 9 alphabet group tabs) and also
+ manipulates \c table, the \c TableModel object, \c proxyModel,
+ the QSortFilterProxyModel object that we use to filter the
+ entries, and \c tableView, the QTableView object.
+
+
+ \section1 AddressWidget Class Implementation
+
+ The \c AddressWidget constructor accepts a parent widget and
+ instantiates \c NewAddressTab, \c TableModel and
+ QSortFilterProxyModel. The \c NewAddressTab object, which is
+ used to indicate that the address book is empty, is added
+ and the rest of the 9 tabs are set up with \c setupTabs().
+
+ \snippet itemviews/addressbook/addresswidget.cpp 0
+
+ The \c setupTabs() function is used to set up the 9 alphabet
+ group tabs, table views and proxy models in
+ \c AddressWidget. Each proxy model in turn is set to filter
+ contact names according to the relevant alphabet group using a
+ \l{Qt::CaseInsensitive}{case-insensitive} QRegExp object. The
+ table views are also sorted in ascending order using the
+ corresponding proxy model's \l{QSortFilterProxyModel::}{sort()}
+ function.
+
+ Each table view's \l{QTableView::}{selectionMode} is set to
+ QAbstractItemView::SingleSelection and
+ \l{QTableView::}{selectionBehavior} is set to
+ QAbstractItemView::SelectRows, allowing the user to select
+ all the items in one row at the same time. Each QTableView object
+ is automatically given a QItemSelectionModel that keeps track
+ of the selected indexes.
+
+ \snippet itemviews/addressbook/addresswidget.cpp 1
+
+ The QItemSelectionModel class provides a
+ \l{QItemSelectionModel::selectionChanged()}{selectionChanged}
+ signal that is connected to \c{AddressWidget}'s
+ \c selectionChanged() signal. This signal to signal connection
+ is necessary to enable the \uicontrol{Edit Entry...} and
+ \uicontrol{Remove Entry} actions in \c MainWindow's Tools menu. This
+ connection is further explained in \c MainWindow's
+ implementation.
+
+ Each table view in the address book is added as a tab to the
+ QTabWidget with the relevant label, obtained from the QStringList
+ of groups.
+
+ \image addressbook-signals.png Signals and Slots Connections
+
+ We provide 2 \c addEntry() functions: 1 which is intended to be
+ used to accept user input, and the other which performs the actual
+ task of adding new entries to the address book. We divide the
+ responsibility of adding entries into two parts to allow
+ \c newAddressTab to insert data without having to popup a dialog.
+
+ The first \c addEntry() function is a slot connected to the
+ \c MainWindow's \uicontrol{Add Entry...} action. This function creates an
+ \c AddDialog object and then calls the second \c addEntry()
+ function to actually add the contact to \c table.
+
+ \snippet itemviews/addressbook/addresswidget.cpp 2
+
+ Basic validation is done in the second \c addEntry() function to
+ prevent duplicate entries in the address book. As mentioned with
+ \c TableModel, this is part of the reason why we require the
+ getter method \c getList().
+
+ \snippet itemviews/addressbook/addresswidget.cpp 3
+
+ If the model does not already contain an entry with the same name,
+ we call \c setData() to insert the name and address into the
+ first and second columns. Otherwise, we display a QMessageBox
+ to inform the user.
+
+ \note The \c newAddressTab is removed once a contact is added
+ as the address book is no longer empty.
+
+ Editing an entry is a way to update the contact's address only,
+ as the example does not allow the user to change the name of an
+ existing contact.
+
+ Firstly, we obtain the active tab's QTableView object using
+ QTabWidget::currentWidget(). Then we extract the
+ \c selectionModel from the \c tableView to obtain the selected
+ indexes.
+
+ \snippet itemviews/addressbook/addresswidget.cpp 4a
+
+ Next we extract data from the row the user intends to
+ edit. This data is displayed in an instance of \c AddDialog
+ with a different window title. The \c table is only
+ updated if changes have been made to data in \c aDialog.
+
+ \snippet itemviews/addressbook/addresswidget.cpp 4b
+
+ \image addressbook-editdialog.png Screenshot of Dialog to Edit a Contact
+
+ Entries are removed using the \c removeEntry() function.
+ The selected row is removed by accessing it through the
+ QItemSelectionModel object, \c selectionModel. The
+ \c newAddressTab is re-added to the \c AddressWidget only if
+ the user removes all the contacts in the address book.
+
+ \snippet itemviews/addressbook/addresswidget.cpp 5
+
+ The \c writeToFile() function is used to save a file containing
+ all the contacts in the address book. The file is saved in a
+ custom \c{.dat} format. The contents of the QList of \l{QPair}s
+ are written to \c file using QDataStream. If the file cannot be
+ opened, a QMessageBox is displayed with the related error message.
+
+ \snippet itemviews/addressbook/addresswidget.cpp 6
+
+ The \c readFromFile() function loads a file containing all the
+ contacts in the address book, previously saved using
+ \c writeToFile(). QDataStream is used to read the contents of a
+ \c{.dat} file into a list of pairs and each of these is added
+ using \c addEntry().
+
+ \snippet itemviews/addressbook/addresswidget.cpp 7
+
+
+ \section1 NewAddressTab Class Definition
+
+ The \c NewAddressTab class provides an informative tab telling
+ the user that the address book is empty. It appears and
+ disappears according to the contents of the address book, as
+ mentioned in \c{AddressWidget}'s implementation.
+
+ \image addressbook-newaddresstab.png Screenshot of NewAddressTab
+
+ The \c NewAddressTab class extends QWidget and contains a QLabel
+ and QPushButton.
+
+ \snippet itemviews/addressbook/newaddresstab.h 0
+
+
+ \section1 NewAddressTab Class Implementation
+
+ The constructor instantiates the \c addButton,
+ \c descriptionLabel and connects the \c{addButton}'s signal to
+ the \c{addEntry()} slot.
+
+ \snippet itemviews/addressbook/newaddresstab.cpp 0
+
+ The \c addEntry() function is similar to \c AddressWidget's
+ \c addEntry() in the sense that both functions instantiate an
+ \c AddDialog object. Data from the dialog is extracted and sent
+ to \c AddressWidget's \c addEntry() slot by emitting the
+ \c sendDetails() signal.
+
+ \snippet itemviews/addressbook/newaddresstab.cpp 1
+
+ \image signals-n-slots-aw-nat.png
+
+
+ \section1 AddDialog Class Definition
+
+ The \c AddDialog class extends QDialog and provides the user
+ with a QLineEdit and a QTextEdit to input data into the
+ address book.
+
+ \snippet itemviews/addressbook/adddialog.h 0
+
+ \image addressbook-adddialog.png
+
+
+ \section1 AddDialog Class Implementation
+
+ The \c AddDialog's constructor sets up the user interface,
+ creating the necessary widgets and placing them into layouts.
+
+ \snippet itemviews/addressbook/adddialog.cpp 0
+
+ To give the dialog the desired behavior, we connect the \uicontrol OK
+ and \uicontrol Cancel buttons to the dialog's \l{QDialog::}{accept()} and
+ \l{QDialog::}{reject()} slots. Since the dialog only acts as a
+ container for name and address information, we do not need to
+ implement any other functions for it.
+
+
+ \section1 MainWindow Class Definition
+
+ The \c MainWindow class extends QMainWindow and implements the
+ menus and actions necessary to manipulate the address book.
+
+ \table
+ \row \li \inlineimage addressbook-filemenu.png
+ \li \inlineimage addressbook-toolsmenu.png
+ \endtable
+
+ \snippet itemviews/addressbook/mainwindow.h 0
+
+ The \c MainWindow class uses an \c AddressWidget as its central
+ widget and provides the File menu with \uicontrol Open, \uicontrol Close and
+ \uicontrol Exit actions, as well as the \uicontrol Tools menu with
+ \uicontrol{Add Entry...}, \uicontrol{Edit Entry...} and \uicontrol{Remove Entry}
+ actions.
+
+
+ \section1 MainWindow Class Implementation
+
+ The constructor for \c MainWindow instantiates AddressWidget,
+ sets it as its central widget and calls the \c createMenus()
+ function.
+
+ \snippet itemviews/addressbook/mainwindow.cpp 0
+
+ The \c createMenus() function sets up the \uicontrol File and
+ \uicontrol Tools menus, connecting the actions to their respective slots.
+ Both the \uicontrol{Edit Entry...} and \uicontrol{Remove Entry} actions are
+ disabled by default as such actions cannot be carried out on an empty
+ address book. They are only enabled when one or more contacts
+ are added.
+
+ \snippet itemviews/addressbook/mainwindow.cpp 1a
+ \dots
+ \codeline
+ \snippet itemviews/addressbook/mainwindow.cpp 1b
+
+ Apart from connecting all the actions' signals to their
+ respective slots, we also connect \c AddressWidget's
+ \c selectionChanged() signal to its \c updateActions() slot.
+
+ The \c openFile() function allows the user to choose a file with
+ the \l{QFileDialog::getOpenFileName()}{open file dialog}. The chosen
+ file has to be a custom \c{.dat} file that contains address book
+ contacts. This function is a slot connected to \c openAct in the
+ \uicontrol File menu.
+
+ \snippet itemviews/addressbook/mainwindow.cpp 2
+
+ The \c saveFile() function allows the user to save a file with
+ the \l{QFileDialog::getSaveFileName()}{save file dialog}. This function
+ is a slot connected to \c saveAct in the \uicontrol File menu.
+
+ \snippet itemviews/addressbook/mainwindow.cpp 3
+
+ The \c updateActions() function enables and disables
+ \uicontrol{Edit Entry...} and \uicontrol{Remove Entry} depending on the contents of
+ the address book. If the address book is empty, these actions
+ are disabled; otherwise, they are enabled. This function is a slot
+ is connected to the \c AddressWidget's \c selectionChanged()
+ signal.
+
+ \snippet itemviews/addressbook/mainwindow.cpp 4
+
+
+ \section1 main() Function
+
+ The main function for the address book instantiates QApplication
+ and opens a \c MainWindow before running the event loop.
+
+ \snippet itemviews/addressbook/main.cpp 0
+*/
diff --git a/examples/widgets/doc/affine.qdoc b/examples/widgets/doc/affine.qdoc
new file mode 100644
index 0000000000..c69794d511
--- /dev/null
+++ b/examples/widgets/doc/affine.qdoc
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example painting/affine
+ \title Affine Transformations
+
+ In this example we show Qt's ability to perform affine transformations
+ on painting operations.
+
+ \image affine-demo.png
+
+ Transformations can be performed on any kind of graphics drawn using QPainter.
+ The transformations used to display the vector graphics, images, and text can be adjusted
+ in the following ways:
+
+ \list
+ \li Dragging the red circle in the centre of each drawing moves it to a new position.
+ \li Dragging the displaced red circle causes the current drawing to be rotated about the
+ central circle. Rotation can also be controlled with the \uicontrol Rotate slider.
+ \li Scaling is controlled with the \uicontrol Scale slider.
+ \li Each drawing can be sheared with the \uicontrol Shear slider.
+ \endlist
+*/
diff --git a/examples/widgets/doc/analogclock.qdoc b/examples/widgets/doc/analogclock.qdoc
new file mode 100644
index 0000000000..bb4bdb54ae
--- /dev/null
+++ b/examples/widgets/doc/analogclock.qdoc
@@ -0,0 +1,154 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/analogclock
+ \title Analog Clock Example
+
+ The Analog Clock example shows how to draw the contents of a custom
+ widget.
+
+ \image analogclock-example.png Screenshot of the Analog Clock example
+
+ This example also demonstrates how the transformation and scaling
+ features of QPainter can be used to make drawing custom widgets
+ easier.
+
+ \section1 AnalogClock Class Definition
+
+ The \c AnalogClock class provides a clock widget with hour and minute
+ hands that is automatically updated every few seconds.
+ We subclass \l QWidget and reimplement the standard
+ \l{QWidget::paintEvent()}{paintEvent()} function to draw the clock face:
+
+ \snippet widgets/analogclock/analogclock.h 0
+
+ \section1 AnalogClock Class Implementation
+
+ \snippet widgets/analogclock/analogclock.cpp 1
+
+ When the widget is constructed, we set up a one-second timer to
+ keep track of the current time, and we connect it to the standard
+ \l{QWidget::update()}{update()} slot so that the clock face is
+ updated when the timer emits the \l{QTimer::timeout()}{timeout()}
+ signal.
+
+ Finally, we resize the widget so that it is displayed at a
+ reasonable size.
+
+ \snippet widgets/analogclock/analogclock.cpp 8
+ \snippet widgets/analogclock/analogclock.cpp 10
+
+ The \c paintEvent() function is called whenever the widget's
+ contents need to be updated. This happens when the widget is
+ first shown, and when it is covered then exposed, but it is also
+ executed when the widget's \l{QWidget::update()}{update()} slot
+ is called. Since we connected the timer's
+ \l{QTimer::timeout()}{timeout()} signal to this slot, it will be
+ called at least once every five seconds.
+
+ Before we set up the painter and draw the clock, we first define
+ two lists of \l {QPoint}s and two \l{QColor}s that will be used
+ for the hour and minute hands. The minute hand's color has an
+ alpha component of 191, meaning that it's 75% opaque.
+
+ We also determine the length of the widget's shortest side so that we
+ can fit the clock face inside the widget. It is also useful to determine
+ the current time before we start drawing.
+
+ \snippet widgets/analogclock/analogclock.cpp 11
+ \snippet widgets/analogclock/analogclock.cpp 12
+ \snippet widgets/analogclock/analogclock.cpp 13
+ \snippet widgets/analogclock/analogclock.cpp 14
+
+ The contents of custom widgets are drawn with a QPainter.
+ Painters can be used to draw on any QPaintDevice, but they are
+ usually used with widgets, so we pass the widget instance to the
+ painter's constructor.
+
+ We call QPainter::setRenderHint() with QPainter::Antialiasing to
+ turn on antialiasing. This makes drawing of diagonal lines much
+ smoother.
+
+ The translation moves the origin to the center of the widget, and
+ the scale operation ensures that the following drawing operations
+ are scaled to fit within the widget. We use a scale factor that
+ let's us use x and y coordinates between -100 and 100, and that
+ ensures that these lie within the length of the widget's shortest
+ side.
+
+ To make our code simpler, we will draw a fixed size clock face that will
+ be positioned and scaled so that it lies in the center of the widget.
+
+ The painter takes care of all the transformations made during the
+ paint event, and ensures that everything is drawn correctly. Letting
+ the painter handle transformations is often easier than performing
+ manual calculations just to draw the contents of a custom widget.
+
+ \image analogclock-viewport.png
+
+ We draw the hour hand first, using a formula that rotates the coordinate
+ system counterclockwise by a number of degrees determined by the current
+ hour and minute. This means that the hand will be shown rotated clockwise
+ by the required amount.
+
+ \snippet widgets/analogclock/analogclock.cpp 15
+ \snippet widgets/analogclock/analogclock.cpp 16
+
+ We set the pen to be Qt::NoPen because we don't want any outline,
+ and we use a solid brush with the color appropriate for
+ displaying hours. Brushes are used when filling in polygons and
+ other geometric shapes.
+
+ \snippet widgets/analogclock/analogclock.cpp 17
+ \snippet widgets/analogclock/analogclock.cpp 19
+
+ We save and restore the transformation matrix before and after the
+ rotation because we want to place the minute hand without having to
+ take into account any previous rotations.
+
+ \snippet widgets/analogclock/analogclock.cpp 20
+ \codeline
+ \snippet widgets/analogclock/analogclock.cpp 21
+
+ We draw markers around the edge of the clock for each hour. We
+ draw each marker then rotate the coordinate system so that the
+ painter is ready for the next one.
+
+ \snippet widgets/analogclock/analogclock.cpp 22
+ \snippet widgets/analogclock/analogclock.cpp 23
+
+ The minute hand is rotated in a similar way to the hour hand.
+
+ \snippet widgets/analogclock/analogclock.cpp 25
+ \codeline
+ \snippet widgets/analogclock/analogclock.cpp 26
+
+ Again, we draw markers around the edge of the clock, but this
+ time to indicate minutes. We skip multiples of 5 to avoid drawing
+ minute markers on top of hour markers.
+*/
diff --git a/examples/widgets/doc/animatedtiles.qdoc b/examples/widgets/doc/animatedtiles.qdoc
new file mode 100644
index 0000000000..4fe25388cf
--- /dev/null
+++ b/examples/widgets/doc/animatedtiles.qdoc
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example animation/animatedtiles
+ \title Animated Tiles Example
+
+ The Animated Tiles example animates items in a graphics scene.
+
+ \image animatedtiles-example.png
+*/
+
diff --git a/examples/widgets/doc/appchooser.qdoc b/examples/widgets/doc/appchooser.qdoc
new file mode 100644
index 0000000000..092db7c29e
--- /dev/null
+++ b/examples/widgets/doc/appchooser.qdoc
@@ -0,0 +1,38 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example animation/appchooser
+ \title Application Chooser Example
+
+ The Application Chooser example shows how to use the Qt state
+ machine and the animation framework to select between
+ applications.
+
+ \image appchooser-example.png
+
+*/
diff --git a/examples/widgets/doc/application.qdoc b/examples/widgets/doc/application.qdoc
new file mode 100644
index 0000000000..d99581fefd
--- /dev/null
+++ b/examples/widgets/doc/application.qdoc
@@ -0,0 +1,396 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example mainwindows/application
+ \title Application Example
+
+ The Application example shows how to implement a standard GUI
+ application with menus, toolbars, and a status bar. The example
+ itself is a simple text editor program built around QPlainTextEdit.
+
+ \image application.png Screenshot of the Application example
+
+ Nearly all of the code for the Application example is in the \c
+ MainWindow class, which inherits QMainWindow. QMainWindow
+ provides the framework for windows that have menus, toolbars,
+ dock windows, and a status bar. The application provides
+ \menu{File}, \menu{Edit}, and \menu{Help} entries in the menu
+ bar, with the following popup menus:
+
+ \image application-menus.png The Application example's menu system
+
+ The status bar at the bottom of the main window shows a
+ description of the menu item or toolbar button under the cursor.
+
+ To keep the example simple, recently opened files aren't shown in
+ the \menu{File} menu, even though this feature is desired in 90%
+ of applications. The \l{mainwindows/recentfiles}{Recent Files}
+ example shows how to implement this. Furthermore, this example
+ can only load one file at a time. The \l{mainwindows/sdi}{SDI}
+ and \l{mainwindows/mdi}{MDI} examples shows how to lift these
+ restrictions.
+
+ \section1 MainWindow Class Definition
+
+ Here's the class definition:
+
+ \snippet mainwindows/application/mainwindow.h 0
+
+ The public API is restricted to the constructor. In the \c
+ protected section, we reimplement QWidget::closeEvent() to detect
+ when the user attempts to close the window, and warn the user
+ about unsaved changes. In the \c{private slots} section, we
+ declare slots that correspond to menu entries, as well as a
+ mysterious \c documentWasModified() slot. Finally, in the \c
+ private section of the class, we have various members that will
+ be explained in due time.
+
+ \section1 MainWindow Class Implementation
+
+ \snippet mainwindows/application/mainwindow.cpp 0
+
+ We start by including \c <QtGui>, a header file that contains the
+ definition of all classes in the \l QtCore and \l QtGui
+ libraries. This saves us from the trouble of having to include
+ every class individually. We also include \c mainwindow.h.
+
+ You might wonder why we don't include \c <QtGui> in \c
+ mainwindow.h and be done with it. The reason is that including
+ such a large header from another header file can rapidly degrade
+ performances. Here, it wouldn't do any harm, but it's still
+ generally a good idea to include only the header files that are
+ strictly necessary from another header file.
+
+ \snippet mainwindows/application/mainwindow.cpp 1
+ \snippet mainwindows/application/mainwindow.cpp 2
+
+ In the constructor, we start by creating a QPlainTextEdit widget as a
+ child of the main window (the \c this object). Then we call
+ QMainWindow::setCentralWidget() to tell that this is going to be
+ the widget that occupies the central area of the main window,
+ between the toolbars and the status bar.
+
+ Then we call \c createActions(), \c createMenus(), \c
+ createToolBars(), and \c createStatusBar(), four private
+ functions that set up the user interface. After that, we call \c
+ readSettings() to restore the user's preferences.
+
+ We establish a signal-slot connection between the QPlainTextEdit's
+ document object and our \c documentWasModified() slot. Whenever
+ the user modifies the text in the QPlainTextEdit, we want to update
+ the title bar to show that the file was modified.
+
+ At the end, we set the window title using the private
+ \c setCurrentFile() function. We'll come back to this later.
+
+ \target close event handler
+ \snippet mainwindows/application/mainwindow.cpp 3
+ \snippet mainwindows/application/mainwindow.cpp 4
+
+ When the user attempts to close the window, we call the private
+ function \c maybeSave() to give the user the possibility to save
+ pending changes. The function returns true if the user wants the
+ application to close; otherwise, it returns false. In the first
+ case, we save the user's preferences to disk and accept the close
+ event; in the second case, we ignore the close event, meaning
+ that the application will stay up and running as if nothing
+ happened.
+
+ \snippet mainwindows/application/mainwindow.cpp 5
+ \snippet mainwindows/application/mainwindow.cpp 6
+
+ The \c newFile() slot is invoked when the user selects
+ \menu{File|New} from the menu. We call \c maybeSave() to save any
+ pending changes and if the user accepts to go on, we clear the
+ QPlainTextEdit and call the private function \c setCurrentFile() to
+ update the window title and clear the
+ \l{QWidget::windowModified}{windowModified} flag.
+
+ \snippet mainwindows/application/mainwindow.cpp 7
+ \snippet mainwindows/application/mainwindow.cpp 8
+
+ The \c open() slot is invoked when the user clicks
+ \menu{File|Open}. We pop up a QFileDialog asking the user to
+ choose a file. If the user chooses a file (i.e., \c fileName is
+ not an empty string), we call the private function \c loadFile()
+ to actually load the file.
+
+ \snippet mainwindows/application/mainwindow.cpp 9
+ \snippet mainwindows/application/mainwindow.cpp 10
+
+ The \c save() slot is invoked when the user clicks
+ \menu{File|Save}. If the user hasn't provided a name for the file
+ yet, we call \c saveAs(); otherwise, we call the private function
+ \c saveFile() to actually save the file.
+
+ \snippet mainwindows/application/mainwindow.cpp 11
+ \snippet mainwindows/application/mainwindow.cpp 12
+
+ In \c saveAs(), we start by popping up a QFileDialog asking the
+ user to provide a name. If the user clicks \uicontrol{Cancel}, the
+ returned file name is empty, and we do nothing.
+
+ \snippet mainwindows/application/mainwindow.cpp 13
+ \snippet mainwindows/application/mainwindow.cpp 14
+
+ The application's About box is done using one statement, using
+ the QMessageBox::about() static function and relying on its
+ support for an HTML subset.
+
+ The \l{QObject::tr()}{tr()} call around the literal string marks
+ the string for translation. It is a good habit to call
+ \l{QObject::tr()}{tr()} on all user-visible strings, in case you
+ later decide to translate your application to other languages.
+ The \l{Internationalization with Qt} overview covers
+ \l{QObject::tr()}{tr()} in more detail.
+
+ \snippet mainwindows/application/mainwindow.cpp 15
+ \snippet mainwindows/application/mainwindow.cpp 16
+
+ The \c documentWasModified() slot is invoked each time the text
+ in the QPlainTextEdit changes because of user edits. We call
+ QWidget::setWindowModified() to make the title bar show that the
+ file was modified. How this is done varies on each platform.
+
+ \snippet mainwindows/application/mainwindow.cpp 17
+ \snippet mainwindows/application/mainwindow.cpp 18
+ \dots
+ \snippet mainwindows/application/mainwindow.cpp 22
+
+ The \c createActions() private function, which is called from the
+ \c MainWindow constructor, creates \l{QAction}s. The code is very
+ repetitive, so we show only the actions corresponding to
+ \menu{File|New}, \menu{File|Open}, and \menu{Help|About Qt}.
+
+ A QAction is an object that represents one user action, such as
+ saving a file or invoking a dialog. An action can be put in a
+ QMenu or a QToolBar, or both, or in any other widget that
+ reimplements QWidget::actionEvent().
+
+ An action has a text that is shown in the menu, an icon, a
+ shortcut key, a tooltip, a status tip (shown in the status bar),
+ a "What's This?" text, and more. It emits a
+ \l{QAction::triggered()}{triggered()} signal whenever the user
+ invokes the action (e.g., by clicking the associated menu item or
+ toolbar button). We connect this signal to a slot that performs
+ the actual action.
+
+ The code above contains one more idiom that must be explained.
+ For some of the actions, we specify an icon as a QIcon to the
+ QAction constructor. The QIcon constructor takes the file name
+ of an image that it tries to load. Here, the file name starts
+ with \c{:}. Such file names aren't ordinary file names, but
+ rather path in the executable's stored resources. We'll come back
+ to this when we review the \c application.qrc file that's part of
+ the project.
+
+ \snippet mainwindows/application/mainwindow.cpp 23
+ \snippet mainwindows/application/mainwindow.cpp 24
+
+ The \uicontrol{Edit|Cut} and \uicontrol{Edit|Copy} actions must be available
+ only when the QPlainTextEdit contains selected text. We disable them
+ by default and connect the QPlainTextEdit::copyAvailable() signal to
+ the QAction::setEnabled() slot, ensuring that the actions are
+ disabled when the text editor has no selection.
+
+ \snippet mainwindows/application/mainwindow.cpp 25
+ \snippet mainwindows/application/mainwindow.cpp 27
+
+ Creating actions isn't sufficient to make them available to the
+ user; we must also add them to the menu system. This is what \c
+ createMenus() does. We create a \menu{File}, an \menu{Edit}, and
+ a \menu{Help} menu. QMainWindow::menuBar() lets us access the
+ window's menu bar widget. We don't have to worry about creating
+ the menu bar ourselves; the first time we call this function, the
+ QMenuBar is created.
+
+ Just before we create the \menu{Help} menu, we call
+ QMenuBar::addSeparator(). This has no effect for most widget
+ styles (e.g., Windows and Mac OS X styles), but for Motif-based
+ styles this makes sure that \menu{Help} is pushed to the right
+ side of the menu bar. Try running the application with various
+ styles and see the results:
+
+ \snippet doc/src/snippets/code/doc_src_examples_application.qdoc 0
+
+ Let's now review the toolbars:
+
+ \snippet mainwindows/application/mainwindow.cpp 30
+
+ Creating toolbars is very similar to creating menus. The same
+ actions that we put in the menus can be reused in the toolbars.
+
+ \snippet mainwindows/application/mainwindow.cpp 32
+ \snippet mainwindows/application/mainwindow.cpp 33
+
+ QMainWindow::statusBar() returns a pointer to the main window's
+ QStatusBar widget. Like with \l{QMainWindow::menuBar()}, the
+ widget is automatically created the first time the function is
+ called.
+
+ \snippet mainwindows/application/mainwindow.cpp 34
+ \snippet mainwindows/application/mainwindow.cpp 36
+
+ The \c readSettings() function is called from the constructor to
+ load the user's preferences and other application settings. The
+ QSettings class provides a high-level interface for storing
+ settings permanently on disk. On Windows, it uses the (in)famous
+ Windows registry; on Mac OS X, it uses the native XML-based
+ CFPreferences API; on Unix/X11, it uses text files.
+
+ The QSettings constructor takes arguments that identify your
+ company and the name of the product. This ensures that the
+ settings for different applications are kept separately.
+
+ We use QSettings::value() to extract the value of the "pos" and
+ "size" settings. The second argument to QSettings::value() is
+ optional and specifies a default value for the setting if there
+ exists none. This value is used the first time the application is
+ run.
+
+ When restoring the position and size of a window, it's important
+ to call QWidget::resize() before QWidget::move(). The reason why
+ is given in the \l{Window Geometry} overview.
+
+ \snippet mainwindows/application/mainwindow.cpp 37
+ \snippet mainwindows/application/mainwindow.cpp 39
+
+ The \c writeSettings() function is called from \c closeEvent().
+ Writing settings is similar to reading them, except simpler. The
+ arguments to the QSettings constructor must be the same as in \c
+ readSettings().
+
+ \snippet mainwindows/application/mainwindow.cpp 40
+ \snippet mainwindows/application/mainwindow.cpp 41
+
+ The \c maybeSave() function is called to save pending changes. If
+ there are pending changes, it pops up a QMessageBox giving the
+ user to save the document. The options are QMessageBox::Yes,
+ QMessageBox::No, and QMessageBox::Cancel. The \uicontrol{Yes} button is
+ made the default button (the button that is invoked when the user
+ presses \uicontrol{Return}) using the QMessageBox::Default flag; the
+ \uicontrol{Cancel} button is made the escape button (the button that is
+ invoked when the user presses \uicontrol{Esc}) using the
+ QMessageBox::Escape flag.
+
+ The \c maybeSave() function returns \c true in all cases, except
+ when the user clicks \uicontrol{Cancel}. The caller must check the
+ return value and stop whatever it was doing if the return value
+ is \c false.
+
+ \snippet mainwindows/application/mainwindow.cpp 42
+ \snippet mainwindows/application/mainwindow.cpp 43
+
+ In \c loadFile(), we use QFile and QTextStream to read in the
+ data. The QFile object provides access to the bytes stored in a
+ file.
+
+ We start by opening the file in read-only mode. The QFile::Text
+ flag indicates that the file is a text file, not a binary file.
+ On Unix and Mac OS X, this makes no difference, but on Windows,
+ it ensures that the "\\r\\n" end-of-line sequence is converted to
+ "\\n" when reading.
+
+ If we successfully opened the file, we use a QTextStream object
+ to read in the data. QTextStream automatically converts the 8-bit
+ data into a Unicode QString and supports various encodings. If no
+ encoding is specified, QTextStream assumes the file is written
+ using the system's default 8-bit encoding (for example, Latin-1;
+ see QTextCodec::codecForLocale() for details).
+
+ Since the call to QTextStream::readAll() might take some time, we
+ set the cursor to be Qt::WaitCursor for the entire application
+ while it goes on.
+
+ At the end, we call the private \c setCurrentFile() function,
+ which we'll cover in a moment, and we display the string "File
+ loaded" in the status bar for 2 seconds (2000 milliseconds).
+
+ \snippet mainwindows/application/mainwindow.cpp 44
+ \snippet mainwindows/application/mainwindow.cpp 45
+
+ Saving a file is very similar to loading one. Here, the
+ QFile::Text flag ensures that on Windows, "\\n" is converted into
+ "\\r\\n" to conform to the Windows convension.
+
+ \snippet mainwindows/application/mainwindow.cpp 46
+ \snippet mainwindows/application/mainwindow.cpp 47
+
+ The \c setCurrentFile() function is called to reset the state of
+ a few variables when a file is loaded or saved, or when the user
+ starts editing a new file (in which case \c fileName is empty).
+ We update the \c curFile variable, clear the
+ QTextDocument::modified flag and the associated \c
+ QWidget:windowModified flag, and update the window title to
+ contain the new file name (or \c untitled.txt).
+
+ The \c strippedName() function call around \c curFile in the
+ QWidget::setWindowTitle() call shortens the file name to exclude
+ the path. Here's the function:
+
+ \snippet mainwindows/application/mainwindow.cpp 48
+ \snippet mainwindows/application/mainwindow.cpp 49
+
+ \section1 The main() Function
+
+ The \c main() function for this application is typical of
+ applications that contain one main window:
+
+ \snippet mainwindows/application/main.cpp 0
+
+ \section1 The Resource File
+
+ As you will probably recall, for some of the actions, we
+ specified icons with file names starting with \c{:} and mentioned
+ that such file names aren't ordinary file names, but path in the
+ executable's stored resources. These resources are compiled
+
+ The resources associated with an application are specified in a
+ \c .qrc file, an XML-based file format that lists files on the
+ disk. Here's the \c application.qrc file that's used by the
+ Application example:
+
+ \quotefile mainwindows/application/application.qrc
+
+ The \c .png files listed in the \c application.qrc file are files
+ that are part of the Application example's source tree. Paths are
+ relative to the directory where the \c application.qrc file is
+ located (the \c mainwindows/application directory).
+
+ The resource file must be mentioned in the \c application.pro
+ file so that \c qmake knows about it:
+
+ \snippet mainwindows/application/application.pro 0
+
+ \c qmake will produce make rules to generate a file called \c
+ qrc_application.cpp that is linked into the application. This
+ file contains all the data for the images and other resources as
+ static C++ arrays of compressed binary data. See
+ \l{resources.html}{The Qt Resource System} for more information
+ about resources.
+*/
diff --git a/examples/widgets/doc/basicdrawing.qdoc b/examples/widgets/doc/basicdrawing.qdoc
new file mode 100644
index 0000000000..899aa361f8
--- /dev/null
+++ b/examples/widgets/doc/basicdrawing.qdoc
@@ -0,0 +1,454 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example painting/basicdrawing
+ \title Basic Drawing Example
+
+ The Basic Drawing example shows how to display basic graphics
+ primitives in a variety of styles using the QPainter class.
+
+ QPainter performs low-level painting on widgets and other paint
+ devices. The class can draw everything from simple lines to
+ complex shapes like pies and chords. It can also draw aligned text
+ and pixmaps. Normally, it draws in a "natural" coordinate system,
+ but it can in addition do view and world transformation.
+
+ \image basicdrawing-example.png
+
+ The example provides a render area, displaying the currently
+ active shape, and lets the user manipulate the rendered shape and
+ its appearance using the QPainter parameters: The user can change
+ the active shape (\uicontrol Shape), and modify the QPainter's pen (\uicontrol
+ {Pen Width}, \uicontrol {Pen Style}, \uicontrol {Pen Cap}, \uicontrol {Pen Join}),
+ brush (\uicontrol {Brush Style}) and render hints (\uicontrol
+ Antialiasing). In addition the user can rotate a shape (\uicontrol
+ Transformations); behind the scenes we use QPainter's ability to
+ manipulate the coordinate system to perform the rotation.
+
+ The Basic Drawing example consists of two classes:
+
+ \list
+ \li \c RenderArea is a custom widget that renders multiple
+ copies of the currently active shape.
+ \li \c Window is the application's main window displaying a
+ \c RenderArea widget in addition to several parameter widgets.
+ \endlist
+
+ First we will review the \c Window class, then we will take a
+ look at the \c RenderArea class.
+
+ \section1 Window Class Definition
+
+ The Window class inherits QWidget, and is the application's main
+ window displaying a \c RenderArea widget in addition to several
+ parameter widgets.
+
+ \snippet painting/basicdrawing/window.h 0
+
+ We declare the various widgets, and three private slots updating
+ the \c RenderArea widget: The \c shapeChanged() slot updates the
+ \c RenderArea widget when the user changes the currently active
+ shape. We call the \c penChanged() slot when either of the
+ QPainter's pen parameters changes. And the \c brushChanged() slot
+ updates the \c RenderArea widget when the user changes the
+ painter's brush style.
+
+ \section1 Window Class Implementation
+
+ In the constructor we create and initialize the various widgets
+ appearing in the main application window.
+
+ \snippet painting/basicdrawing/window.cpp 1
+
+ First we create the \c RenderArea widget that will render the
+ currently active shape. Then we create the \uicontrol Shape combobox,
+ and add the associated items (i.e. the different shapes a QPainter
+ can draw).
+
+ \snippet painting/basicdrawing/window.cpp 2
+
+ QPainter's pen is a QPen object; the QPen class defines how a
+ painter should draw lines and outlines of shapes. A pen has
+ several properties: Width, style, cap and join.
+
+ A pen's width can be \e zero or greater, but the most common width
+ is zero. Note that this doesn't mean 0 pixels, but implies that
+ the shape is drawn as smoothly as possible although perhaps not
+ mathematically correct.
+
+ We create a QSpinBox for the \uicontrol {Pen Width} parameter.
+
+ \snippet painting/basicdrawing/window.cpp 3
+
+ The pen style defines the line type. The default style is solid
+ (Qt::SolidLine). Setting the style to none (Qt::NoPen) tells the
+ painter to not draw lines or outlines. The pen cap defines how
+ the end points of lines are drawn. And the pen join defines how
+ two lines join when multiple connected lines are drawn. The cap
+ and join only apply to lines with a width of 1 pixel or greater.
+
+ We create \l {QComboBox}es for each of the \uicontrol {Pen Style}, \uicontrol
+ {Pen Cap} and \uicontrol {Pen Join} parameters, and adds the associated
+ items (i.e the values of the Qt::PenStyle, Qt::PenCapStyle and
+ Qt::PenJoinStyle enums respectively).
+
+ \snippet painting/basicdrawing/window.cpp 4
+
+ The QBrush class defines the fill pattern of shapes drawn by a
+ QPainter. The default brush style is Qt::NoBrush. This style tells
+ the painter to not fill shapes. The standard style for filling is
+ Qt::SolidPattern.
+
+ We create a QComboBox for the \uicontrol {Brush Style} parameter, and add
+ the associated items (i.e. the values of the Qt::BrushStyle enum).
+
+ \snippet painting/basicdrawing/window.cpp 5
+ \snippet painting/basicdrawing/window.cpp 6
+
+ Antialiasing is a feature that "smoothes" the pixels to create
+ more even and less jagged lines, and can be applied using
+ QPainter's render hints. QPainter::RenderHints are used to specify
+ flags to QPainter that may or may not be respected by any given
+ engine.
+
+ We simply create a QCheckBox for the \uicontrol Antialiasing option.
+
+ \snippet painting/basicdrawing/window.cpp 7
+
+ The \uicontrol Transformations option implies a manipulation of the
+ coordinate system that will appear as if the rendered shape is
+ rotated in three dimensions.
+
+ We use the QPainter::translate(), QPainter::rotate() and
+ QPainter::scale() functions to implement this feature represented
+ in the main application window by a simple QCheckBox.
+
+ \snippet painting/basicdrawing/window.cpp 8
+
+ Then we connect the parameter widgets with their associated slots
+ using the static QObject::connect() function, ensuring that the \c
+ RenderArea widget is updated whenever the user changes the shape,
+ or any of the other parameters.
+
+ \snippet painting/basicdrawing/window.cpp 9
+ \snippet painting/basicdrawing/window.cpp 10
+
+ Finally, we add the various widgets to a layout, and call the \c
+ shapeChanged(), \c penChanged(), and \c brushChanged() slots to
+ initialize the application. We also turn on antialiasing.
+
+ \snippet painting/basicdrawing/window.cpp 11
+
+ The \c shapeChanged() slot is called whenever the user changes the
+ currently active shape.
+
+ First we retrieve the shape the user has chosen using the
+ QComboBox::itemData() function. This function returns the data for
+ the given role in the given index in the combobox. We use
+ QComboBox::currentIndex() to retrieve the index of the shape, and
+ the role is defined by the Qt::ItemDataRole enum; \c IdRole is an
+ alias for Qt::UserRole.
+
+ Note that Qt::UserRole is only the first role that can be used for
+ application-specific purposes. If you need to store different data
+ in the same index, you can use different roles by simply
+ incrementing the value of Qt::UserRole, for example: 'Qt::UserRole
+ + 1' and 'Qt::UserRole + 2'. However, it is a good programming
+ practice to give each role their own name: 'myFirstRole =
+ Qt::UserRole + 1' and 'mySecondRole = Qt::UserRole + 2'. Even
+ though we only need a single role in this particular example, we
+ add the following line of code to the beginning of the \c
+ window.cpp file.
+
+ \snippet painting/basicdrawing/window.cpp 0
+
+ The QComboBox::itemData() function returns the data as a QVariant,
+ so we need to cast the data to \c RenderArea::Shape. If there is
+ no data for the given role, the function returns
+ QVariant::Invalid.
+
+ In the end we call the \c RenderArea::setShape() slot to update
+ the \c RenderArea widget.
+
+ \snippet painting/basicdrawing/window.cpp 12
+
+ We call the \c penChanged() slot whenever the user changes any of
+ the pen parameters. Again we use the QComboBox::itemData()
+ function to retrieve the parameters, and then we call the \c
+ RenderArea::setPen() slot to update the \c RenderArea widget.
+
+ \snippet painting/basicdrawing/window.cpp 13
+
+ The brushChanged() slot is called whenever the user changes the
+ brush parameter which we retrieve using the QComboBox::itemData()
+ function as before.
+
+ \snippet painting/basicdrawing/window.cpp 14
+
+ If the brush parameter is a gradient fill, special actions are
+ required.
+
+ The QGradient class is used in combination with QBrush to specify
+ gradient fills. Qt currently supports three types of gradient
+ fills: linear, radial and conical. Each of these is represented by
+ a subclass of QGradient: QLinearGradient, QRadialGradient and
+ QConicalGradient.
+
+ So if the brush style is Qt::LinearGradientPattern, we first
+ create a QLinearGradient object with interpolation area between
+ the coordinates passed as arguments to the constructor. The
+ positions are specified using logical coordinates. Then we set the
+ gradient's colors using the QGradient::setColorAt() function. The
+ colors is defined using stop points which are composed by a
+ position (between 0 and 1) and a QColor. The set of stop points
+ describes how the gradient area should be filled. A gradient can
+ have an arbitrary number of stop points.
+
+ In the end we call \c RenderArea::setBrush() slot to update the \c
+ RenderArea widget's brush with the QLinearGradient object.
+
+ \snippet painting/basicdrawing/window.cpp 15
+
+ A similar pattern of actions, as the one used for QLinearGradient,
+ is used in the cases of Qt::RadialGradientPattern and
+ Qt::ConicalGradientPattern.
+
+ The only difference is the arguments passed to the constructor:
+ Regarding the QRadialGradient constructor the first argument is
+ the center, and the second the radial gradient's radius. The third
+ argument is optional, but can be used to define the focal point of
+ the gradient inside the circle (the default focal point is the
+ circle center). Regarding the QConicalGradient constructor, the
+ first argument specifies the center of the conical, and the second
+ specifies the start angle of the interpolation.
+
+ \snippet painting/basicdrawing/window.cpp 16
+
+ If the brush style is Qt::TexturePattern we create a QBrush from a
+ QPixmap. Then we call \c RenderArea::setBrush() slot to update the
+ \c RenderArea widget with the newly created brush.
+
+ \snippet painting/basicdrawing/window.cpp 17
+
+ Otherwise we simply create a brush with the given style and a
+ green color, and then call \c RenderArea::setBrush() slot to
+ update the \c RenderArea widget with the newly created brush.
+
+ \section1 RenderArea Class Definition
+
+ The \c RenderArea class inherits QWidget, and renders multiple
+ copies of the currently active shape using a QPainter.
+
+ \snippet painting/basicdrawing/renderarea.h 0
+
+ First we define a public \c Shape enum to hold the different
+ shapes that can be rendered by the widget (i.e the shapes that can
+ be rendered by a QPainter). Then we reimplement the constructor as
+ well as two of QWidget's public functions: \l
+ {QWidget::minimumSizeHint()}{minimumSizeHint()} and \l
+ {QWidget::sizeHint()}{sizeHint()}.
+
+ We also reimplement the QWidget::paintEvent() function to be able
+ to draw the currently active shape according to the specified
+ parameters.
+
+ We declare several private slots: The \c setShape() slot changes
+ the \c RenderArea's shape, the \c setPen() and \c setBrush() slots
+ modify the widget's pen and brush, and the \c setAntialiased() and
+ \c setTransformed() slots modify the widget's respective
+ properties.
+
+ \section1 RenderArea Class Implementation
+
+ In the constructor we initialize some of the widget's variables.
+
+ \snippet painting/basicdrawing/renderarea.cpp 0
+
+ We set its shape to be a \uicontrol Polygon, its antialiased property to
+ be false and we load an image into the widget's pixmap
+ variable. In the end we set the widget's background role, defining
+ the brush from the widget's \l {QWidget::palette}{palette} that
+ will be used to render the background. QPalette::Base is typically
+ white.
+
+ \snippet painting/basicdrawing/renderarea.cpp 2
+
+ The \c RenderArea inherits QWidget's \l
+ {QWidget::sizeHint()}{sizeHint} property holding the recommended
+ size for the widget. If the value of this property is an invalid
+ size, no size is recommended.
+
+ The default implementation of the QWidget::sizeHint() function
+ returns an invalid size if there is no layout for the widget, and
+ returns the layout's preferred size otherwise.
+
+ Our reimplementation of the function returns a QSize with a 400
+ pixels width and a 200 pixels height.
+
+ \snippet painting/basicdrawing/renderarea.cpp 1
+
+ \c RenderArea also inherits QWidget's
+ \l{QWidget::minimumSizeHint()}{minimumSizeHint} property holding
+ the recommended minimum size for the widget. Again, if the value
+ of this property is an invalid size, no size is recommended.
+
+ The default implementation of QWidget::minimumSizeHint() returns
+ an invalid size if there is no layout for the widget, and returns
+ the layout's minimum size otherwise.
+
+ Our reimplementation of the function returns a QSize with a 100
+ pixels width and a 100 pixels height.
+
+ \snippet painting/basicdrawing/renderarea.cpp 3
+ \codeline
+ \snippet painting/basicdrawing/renderarea.cpp 4
+ \codeline
+ \snippet painting/basicdrawing/renderarea.cpp 5
+
+ The public \c setShape(), \c setPen() and \c setBrush() slots are
+ called whenever we want to modify a \c RenderArea widget's shape,
+ pen or brush. We set the shape, pen or brush according to the
+ slot parameter, and call QWidget::update() to make the changes
+ visible in the \c RenderArea widget.
+
+ The QWidget::update() slot does not cause an immediate
+ repaint; instead it schedules a paint event for processing when Qt
+ returns to the main event loop.
+
+ \snippet painting/basicdrawing/renderarea.cpp 6
+ \codeline
+ \snippet painting/basicdrawing/renderarea.cpp 7
+
+ With the \c setAntialiased() and \c setTransformed() slots we
+ change the state of the properties according to the slot
+ parameter, and call the QWidget::update() slot to make the changes
+ visible in the \c RenderArea widget.
+
+ \snippet painting/basicdrawing/renderarea.cpp 8
+
+ Then we reimplement the QWidget::paintEvent() function. The first
+ thing we do is to create the graphical objects we will need to
+ draw the various shapes.
+
+ We create a vector of four \l {QPoint}s. We use this vector to
+ render the \uicontrol Points, \uicontrol Polyline and \uicontrol Polygon
+ shapes. Then we create a QRect, defining a rectangle in the plane,
+ which we use as the bounding rectangle for all the shapes excluding
+ the \uicontrol Path and the \uicontrol Pixmap.
+
+ We also create a QPainterPath. The QPainterPath class provides a
+ container for painting operations, enabling graphical shapes to be
+ constructed and reused. A painter path is an object composed of a
+ number of graphical building blocks, such as rectangles, ellipses,
+ lines, and curves. For more information about the QPainterPath
+ class, see the \l {painting/painterpaths}{Painter Paths}
+ example. In this example, we create a painter path composed of one
+ straight line and a Bezier curve.
+
+ In addition we define a start angle and an arc length that we will
+ use when drawing the \uicontrol Arc, \uicontrol Chord and \uicontrol Pie shapes.
+
+ \snippet painting/basicdrawing/renderarea.cpp 9
+
+ We create a QPainter for the \c RenderArea widget, and set the
+ painters pen and brush according to the \c RenderArea's pen and
+ brush. If the \uicontrol Antialiasing parameter option is checked, we
+ also set the painter's render hints. QPainter::Antialiasing
+ indicates that the engine should antialias edges of primitives if
+ possible.
+
+ \snippet painting/basicdrawing/renderarea.cpp 10
+
+ Finally, we render the multiple copies of the \c RenderArea's
+ shape. The number of copies is depending on the size of the \c
+ RenderArea widget, and we calculate their positions using two \c
+ for loops and the widgets height and width.
+
+ For each copy we first save the current painter state (pushes the
+ state onto a stack). Then we translate the coordinate system,
+ using the QPainter::translate() function, to the position
+ determined by the variables of the \c for loops. If we omit this
+ translation of the coordinate system all the copies of the shape
+ will be rendered on top of each other in the top left cormer of
+ the \c RenderArea widget.
+
+ \snippet painting/basicdrawing/renderarea.cpp 11
+
+ If the \uicontrol Transformations parameter option is checked, we do an
+ additional translation of the coordinate system before we rotate
+ the coordinate system 60 degrees clockwise using the
+ QPainter::rotate() function and scale it down in size using the
+ QPainter::scale() function. In the end we translate the coordinate
+ system back to where it was before we rotated and scaled it.
+
+ Now, when rendering the shape, it will appear as if it was rotated
+ in three dimensions.
+
+ \snippet painting/basicdrawing/renderarea.cpp 12
+
+ Next, we identify the \c RenderArea's shape, and render it using
+ the associated QPainter drawing function:
+
+ \list
+ \li QPainter::drawLine(),
+ \li QPainter::drawPoints(),
+ \li QPainter::drawPolyline(),
+ \li QPainter::drawPolygon(),
+ \li QPainter::drawRect(),
+ \li QPainter::drawRoundedRect(),
+ \li QPainter::drawEllipse(),
+ \li QPainter::drawArc(),
+ \li QPainter::drawChord(),
+ \li QPainter::drawPie(),
+ \li QPainter::drawPath(),
+ \li QPainter::drawText() or
+ \li QPainter::drawPixmap()
+ \endlist
+
+ Before we started rendering, we saved the current painter state
+ (pushes the state onto a stack). The rationale for this is that we
+ calculate each shape copy's position relative to the same point in
+ the coordinate system. When translating the coordinate system, we
+ lose the knowledge of this point unless we save the current
+ painter state \e before we start the translating process.
+
+ \snippet painting/basicdrawing/renderarea.cpp 13
+
+ Then, when we are finished rendering a copy of the shape we can
+ restore the original painter state, with its associated coordinate
+ system, using the QPainter::restore() function. In this way we
+ ensure that the next shape copy will be rendered in the correct
+ position.
+
+ We could translate the coordinate system back using
+ QPainter::translate() instead of saving the painter state. But
+ since we in addition to translating the coordinate system (when
+ the \uicontrol Transformation parameter option is checked) both rotate
+ and scale the coordinate system, the easiest solution is to save
+ the current painter state.
+*/
diff --git a/examples/widgets/doc/basicgraphicslayouts.qdoc b/examples/widgets/doc/basicgraphicslayouts.qdoc
new file mode 100644
index 0000000000..9f52b3eafa
--- /dev/null
+++ b/examples/widgets/doc/basicgraphicslayouts.qdoc
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example graphicsview/basicgraphicslayouts
+ \title Basic Graphics Layouts Example
+
+ The Basic Graphics Layouts example shows how to use the layout classes
+ in QGraphicsView: QGraphicsLinearLayout and QGraphicsGridLayout.
+ In addition to that it shows how to write your own custom layout item.
+
+ \image basicgraphicslayouts-example.png Screenshot of the Basic Layouts Example
+
+ \section1 Window Class Definition
+
+ The \c Window class is a subclass of QGraphicsWidget. It has a
+ constructor with a QGraphicsWidget \a parent as its parameter.
+
+ \snippet graphicsview/basicgraphicslayouts/window.h 0
+
+ \section1 Window Class Implementation
+
+ The constructor of \c Window instantiates a QGraphicsLinearLayout object,
+ \c windowLayout, with vertical orientation. We instantiate another
+ QGraphicsLinearLayout object, \c linear, whose parent is \c windowLayout.
+ Next, we create a \c LayoutItem object, \c item and add it to \c linear
+ with the \l{QGraphicsLinearLayout::}{addItem()} function. We also provide
+ \c item with a \l{QGraphicsLinearLayout::setStretchFactor()}
+ {stretchFactor}.
+
+ \snippet graphicsview/basicgraphicslayouts/window.cpp 0
+
+ We repeat the process:
+
+ \list
+ \li create a new \c LayoutItem,
+ \li add the item \c linear, and
+ \li provide a stretch factor.
+ \endlist
+
+ \snippet graphicsview/basicgraphicslayouts/window.cpp 1
+
+ We then add \c linear to \c windowLayout, nesting two
+ QGraphicsLinearLayout objects. Apart from the QGraphicsLinearLayout, we
+ also use a QGraphicsGridLayout object, \c grid, which is a 4x3 grid with
+ some cells spanning to other rows.
+
+ We create seven \c LayoutItem objects and place them into \c grid with
+ the \l{QGraphicsGridLayout::}{addItem()} function as shown in the code
+ snippet below:
+
+ \snippet graphicsview/basicgraphicslayouts/window.cpp 2
+
+ The first item we add to \c grid is placed in the top left cell,
+ spanning four rows. The next two items are placed in the second column,
+ and they span two rows. Each item's \l{QGraphicsWidget::}{maximumHeight()}
+ and \l{QGraphicsWidget::}{minimumHeight()} are set to be equal so that
+ they do not expand vertically. As a result, these items will not
+ fit vertically in their cells. So, we specify that they should be
+ vertically aligned in the center of the cell using Qt::AlignVCenter.
+
+ Finally, \c grid itself is added to \c windowLayout. Unlike
+ QGridLayout::addItem(), QGraphicsGridLayout::addItem() requires a row
+ and a column for its argument, specifying which cell the item should be
+ positioned in. Also, if the \c rowSpan and \c columnSpan arguments
+ are omitted, they will default to 1.
+
+ Note that we do not specify a parent for each \c LayoutItem that we
+ construct, as all these items will be added to \c windowLayout. When we
+ add an item to a layout, it will be automatically reparented to the widget
+ on which the layout is installed.
+
+ \snippet graphicsview/basicgraphicslayouts/window.cpp 3
+
+ Now that we have set up \c grid and added it to \c windowLayout, we
+ install \c windowLayout onto the window object using
+ QGraphicsWidget::setLayout() and we set the window title.
+
+ \section1 LayoutItem Class Definition
+
+ The \c LayoutItem class is a subclass of QGraphicsLayoutItem and
+ QGraphicsItem. It has a constructor, a destructor, and some required
+ reimplementations.
+ Since it inherits QGraphicsLayoutItem it must reimplement
+ {QGraphicsLayoutItem::setGeometry()}{setGeometry()} and
+ {QGraphicsLayoutItem::sizeHint()}{sizeHint()}.
+ In addition to that it inherits QGraphicsItem, so it must reimplement
+ {QGraphicsItem::boundingRect()}{boundingRect()} and
+ {QGraphicsItem::paint()}{paint()}.
+
+ \snippet graphicsview/basicgraphicslayouts/layoutitem.h 0
+
+ The \c LayoutItem class also has a private instance of QPixmap, \c m_pix.
+
+ \section1 LayoutItem Class Implementation
+
+ In \c{LayoutItem}'s constructor, \c m_pix is instantiated and the
+ \c{block.png} image is loaded into it.
+
+ \snippet graphicsview/basicgraphicslayouts/layoutitem.cpp 0
+
+ We use the Q_UNUSED() macro to prevent the compiler from generating
+ warnings regarding unused parameters.
+
+ \snippet graphicsview/basicgraphicslayouts/layoutitem.cpp 1
+
+ The idea behind the \c paint() function is to paint the
+ background rect then paint a rect around the pixmap.
+
+ \snippet graphicsview/basicgraphicslayouts/layoutitem.cpp 2
+
+ The reimplementation of \l{QGraphicsItem::}{boundingRect()}
+ will set the top left corner at (0,0), and the size of it will be
+ the size of the layout items
+ \l{QGraphicsLayoutItem::}{geometry()}. This is the area that
+ we paint within.
+
+ \snippet graphicsview/basicgraphicslayouts/layoutitem.cpp 3
+
+
+ The reimplementation of \l{QGraphicsLayoutItem::setGeometry()}{setGeometry()}
+ simply calls its baseclass implementation. However, since this will change
+ the boundingRect we must also call
+ \l{QGraphicsItem::prepareGeometryChange()}{prepareGeometryChange()}.
+ Finally, we move the item according to \c geom.topLeft().
+
+ \snippet graphicsview/basicgraphicslayouts/layoutitem.cpp 4
+
+
+ Since we don't want the size of the item to be smaller than the pixmap, we
+ must make sure that we return a size hint that is larger than \c m_pix.
+ We also add some extra space around for borders that we will paint later.
+ Alternatively, you could scale the pixmap to prevent the item from
+ becoming smaller than the pixmap.
+ The preferred size is the same as the minimum size hint, while we set
+ maximum to be a large value
+
+ \snippet graphicsview/basicgraphicslayouts/layoutitem.cpp 5
+
+*/
diff --git a/examples/widgets/doc/basiclayouts.qdoc b/examples/widgets/doc/basiclayouts.qdoc
new file mode 100644
index 0000000000..a0f083ba58
--- /dev/null
+++ b/examples/widgets/doc/basiclayouts.qdoc
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example layouts/basiclayouts
+ \title Basic Layouts Example
+
+ The Basic Layouts example shows how to use the standard layout
+ managers that are available in Qt: QBoxLayout, QGridLayout and
+ QFormLayout.
+
+ \image basiclayouts-example.png Screenshot of the Basic Layouts example
+
+ The QBoxLayout class lines up widgets horizontally or vertically.
+ QHBoxLayout and QVBoxLayout are convenience subclasses of QBoxLayout.
+ QGridLayout lays out widgets in cells by dividing the available space
+ into rows and columns. QFormLayout, on the other hand, lays out its
+ children in a two-column form with labels in the left column and
+ input fields in the right column.
+
+ \section1 Dialog Class Definition
+
+ \snippet layouts/basiclayouts/dialog.h 0
+
+ The \c Dialog class inherits QDialog. It is a custom widget that
+ displays its child widgets using the geometry managers:
+ QHBoxLayout, QVBoxLayout, QGridLayout and QFormLayout.
+
+ We declare four private functions to simplify the class
+ constructor: The \c createMenu(), \c createHorizontalGroupBox(),
+ \c createGridGroupBox() and \c createFormGroupBox() functions create
+ several widgets that the example uses to demonstrate how the layout
+ affects their appearances.
+
+ \section1 Dialog Class Implementation
+
+ \snippet layouts/basiclayouts/dialog.cpp 0
+
+ In the constructor, we first use the \c createMenu() function to
+ create and populate a menu bar and the \c createHorizontalGroupBox()
+ function to create a group box containing four buttons with a
+ horizontal layout. Next we use the \c createGridGroupBox() function
+ to create a group box containing several line edits and a small text
+ editor which are displayed in a grid layout. Finally, we use the
+ \c createFormGroupBox() function to create a group box with
+ three labels and three input fields: a line edit, a combo box and
+ a spin box.
+
+ \snippet layouts/basiclayouts/dialog.cpp 1
+
+ We also create a big text editor and a dialog button box. The
+ QDialogButtonBox class is a widget that presents buttons in a
+ layout that is appropriate to the current widget style. The
+ preferred buttons can be specified as arguments to the
+ constructor, using the QDialogButtonBox::StandardButtons enum.
+
+ Note that we don't have to specify a parent for the widgets when
+ we create them. The reason is that all the widgets we create here
+ will be added to a layout, and when we add a widget to a layout,
+ it is automatically reparented to the widget the layout is
+ installed on.
+
+ \snippet layouts/basiclayouts/dialog.cpp 2
+
+ The main layout is a QVBoxLayout object. QVBoxLayout is a
+ convenience class for a box layout with vertical orientation.
+
+ In general, the QBoxLayout class takes the space it gets (from its
+ parent layout or from the parent widget), divides it up into a
+ series of boxes, and makes each managed widget fill one box. If
+ the QBoxLayout's orientation is Qt::Horizontal the boxes are
+ placed in a row. If the orientation is Qt::Vertical, the boxes are
+ placed in a column. The corresponding convenience classes are
+ QHBoxLayout and QVBoxLayout, respectively.
+
+ \snippet layouts/basiclayouts/dialog.cpp 3
+
+ When we call the QLayout::setMenuBar() function, the layout places
+ the provided menu bar at the top of the parent widget, and outside
+ the widget's \l {QWidget::contentsRect()}{content margins}. All
+ child widgets are placed below the bottom edge of the menu bar.
+
+ \snippet layouts/basiclayouts/dialog.cpp 4
+
+ We use the QBoxLayout::addWidget() function to add the widgets to
+ the end of layout. Each widget will get at least its minimum size
+ and at most its maximum size. It is possible to specify a stretch
+ factor in the \l {QBoxLayout::addWidget()}{addWidget()} function,
+ and any excess space is shared according to these stretch
+ factors. If not specified, a widget's stretch factor is 0.
+
+ \snippet layouts/basiclayouts/dialog.cpp 5
+
+ We install the main layout on the \c Dialog widget using the
+ QWidget::setLayout() function, and all of the layout's widgets are
+ automatically reparented to be children of the \c Dialog widget.
+
+ \snippet layouts/basiclayouts/dialog.cpp 6
+
+ In the private \c createMenu() function we create a menu bar, and
+ add a pull-down \uicontrol File menu containing an \uicontrol Exit option.
+
+ \snippet layouts/basiclayouts/dialog.cpp 7
+
+ When we create the horizontal group box, we use a QHBoxLayout as
+ the internal layout. We create the buttons we want to put in the
+ group box, add them to the layout and install the layout on the
+ group box.
+
+ \snippet layouts/basiclayouts/dialog.cpp 8
+
+ In the \c createGridGroupBox() function we use a QGridLayout which
+ lays out widgets in a grid. It takes the space made available to
+ it (by its parent layout or by the parent widget), divides it up
+ into rows and columns, and puts each widget it manages into the
+ correct cell.
+
+ \snippet layouts/basiclayouts/dialog.cpp 9
+
+ For each row in the grid we create a label and an associated line
+ edit, and add them to the layout. The QGridLayout::addWidget()
+ function differ from the corresponding function in QBoxLayout: It
+ needs the row and column specifying the grid cell to put the
+ widget in.
+
+ \snippet layouts/basiclayouts/dialog.cpp 10
+
+ QGridLayout::addWidget() can in addition take arguments
+ specifying the number of rows and columns the cell will be
+ spanning. In this example, we create a small editor which spans
+ three rows and one column.
+
+ For both the QBoxLayout::addWidget() and QGridLayout::addWidget()
+ functions it is also possible to add a last argument specifying
+ the widget's alignment. By default it fills the whole cell. But we
+ could, for example, align a widget with the right edge by
+ specifying the alignment to be Qt::AlignRight.
+
+ \snippet layouts/basiclayouts/dialog.cpp 11
+
+ Each column in a grid layout has a stretch factor. The stretch
+ factor is set using QGridLayout::setColumnStretch() and determines
+ how much of the available space the column will get over and above
+ its necessary minimum.
+
+ In this example, we set the stretch factors for columns 1 and 2.
+ The stretch factor is relative to the other columns in this grid;
+ columns with a higher stretch factor take more of the available
+ space. So column 2 in our grid layout will get more of the
+ available space than column 1, and column 0 will not grow at all
+ since its stretch factor is 0 (the default).
+
+ Columns and rows behave identically; there is an equivalent
+ stretch factor for rows, as well as a QGridLayout::setRowStretch()
+ function.
+
+ \snippet layouts/basiclayouts/dialog.cpp 12
+
+ In the \c createFormGroupBox() function, we use a QFormLayout
+ to neatly arrange objects into two columns - name and field.
+ There are three QLabel objects for names with three
+ corresponding input widgets as fields: a QLineEdit, a QComboBox
+ and a QSpinBox. Unlike QBoxLayout::addWidget() and
+ QGridLayout::addWidget(), we use QFormLayout::addRow() to add widgets
+ to the layout.
+*/
diff --git a/examples/widgets/doc/basicsortfiltermodel.qdoc b/examples/widgets/doc/basicsortfiltermodel.qdoc
new file mode 100644
index 0000000000..0ecf4a0629
--- /dev/null
+++ b/examples/widgets/doc/basicsortfiltermodel.qdoc
@@ -0,0 +1,37 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/basicsortfiltermodel
+ \title Basic Sort/Filter Model Example
+
+ The Basic Sort/Filter Model example illustrates how to use
+ QSortFilterProxyModel to perform basic sorting and filtering.
+
+ \image basicsortfiltermodel-example.png Screenshot of the Basic Sort/Filter Model Example
+
+*/
diff --git a/examples/widgets/doc/blurpicker.qdoc b/examples/widgets/doc/blurpicker.qdoc
new file mode 100644
index 0000000000..bd57acb061
--- /dev/null
+++ b/examples/widgets/doc/blurpicker.qdoc
@@ -0,0 +1,33 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example effects/blurpicker
+ \title Blur Picker Effect Example
+
+ \image blurpickereffect-example.png
+*/
diff --git a/examples/widgets/doc/borderlayout.qdoc b/examples/widgets/doc/borderlayout.qdoc
new file mode 100644
index 0000000000..aaff2dda1d
--- /dev/null
+++ b/examples/widgets/doc/borderlayout.qdoc
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example layouts/borderlayout
+ \title Border Layout Example
+
+ The Border Layout example shows how to create a custom layout that arranges
+ child widgets according to a simple set of rules.
+
+ \image borderlayout-example.png
+*/
diff --git a/examples/widgets/doc/boxes.qdoc b/examples/widgets/doc/boxes.qdoc
new file mode 100644
index 0000000000..aa34a61bc3
--- /dev/null
+++ b/examples/widgets/doc/boxes.qdoc
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example graphicsview/boxes
+ \title Boxes
+
+ This demo shows Qt's ability to combine advanced OpenGL rendering with the
+ the \l{Graphics View Framework}.
+
+ \image boxes-demo.png
+
+ Elements in the demo can be controlled using the mouse in the following
+ ways:
+ \list
+ \li Dragging the mouse while pressing the left mouse button rotates the
+ box in the center.
+ \li Dragging the mouse while pressing the right mouse button rotates the
+ satellite boxes.
+ \li Scrolling the mouse wheel zooms in and out of the scene.
+ \endlist
+
+ The options pane can be used to fine-tune various parameters in the demo,
+ including colors and pixel shaders.
+*/
diff --git a/examples/widgets/doc/calculator.qdoc b/examples/widgets/doc/calculator.qdoc
new file mode 100644
index 0000000000..8480d90477
--- /dev/null
+++ b/examples/widgets/doc/calculator.qdoc
@@ -0,0 +1,375 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/calculator
+ \title Calculator Example
+
+ The example shows how to use signals and slots to implement the
+ functionality of a calculator widget, and how to use QGridLayout
+ to place child widgets in a grid.
+
+ \image calculator-example.png Screenshot of the Calculator example
+
+ The example consists of two classes:
+
+ \list
+ \li \c Calculator is the calculator widget, with all the
+ calculator functionality.
+ \li \c Button is the widget used for each of the calculator
+ button. It derives from QToolButton.
+ \endlist
+
+ We will start by reviewing \c Calculator, then we will take a
+ look at \c Button.
+
+ \section1 Calculator Class Definition
+
+ \snippet widgets/calculator/calculator.h 0
+
+ The \c Calculator class provides a simple calculator widget. It
+ inherits from QDialog and has several private slots associated
+ with the calculator's buttons. QObject::eventFilter() is
+ reimplemented to handle mouse events on the calculator's display.
+
+ Buttons are grouped in categories according to their behavior.
+ For example, all the digit buttons (labeled \uicontrol 0 to \uicontrol 9)
+ append a digit to the current operand. For these, we connect
+ multiple buttons to the same slot (e.g., \c digitClicked()). The
+ categories are digits, unary operators (\uicontrol{Sqrt}, \uicontrol{x\unicode{178}},
+ \uicontrol{1/x}), additive operators (\uicontrol{+}, \uicontrol{-}), and
+ multiplicative operators (\uicontrol{\unicode{215}}, \uicontrol{\unicode{247}}). The other buttons
+ have their own slots.
+
+ \snippet widgets/calculator/calculator.h 1
+ \snippet widgets/calculator/calculator.h 2
+
+ The private \c createButton() function is used as part of the
+ widget construction. \c abortOperation() is called whenever a
+ division by zero occurs or when a square root operation is
+ applied to a negative number. \c calculate() applies a binary
+ operator (\uicontrol{+}, \uicontrol{-}, \uicontrol{\unicode{215}}, or \uicontrol{\unicode{247}}).
+
+ \snippet widgets/calculator/calculator.h 3
+ \snippet widgets/calculator/calculator.h 4
+ \snippet widgets/calculator/calculator.h 5
+ \snippet widgets/calculator/calculator.h 6
+ \snippet widgets/calculator/calculator.h 7
+ \snippet widgets/calculator/calculator.h 8
+
+ These variables, together with the contents of the calculator
+ display (a QLineEdit), encode the state of the calculator:
+
+ \list
+ \li \c sumInMemory contains the value stored in the calculator's memory
+ (using \uicontrol{MS}, \uicontrol{M+}, or \uicontrol{MC}).
+ \li \c sumSoFar stores the value accumulated so far. When the user
+ clicks \uicontrol{=}, \c sumSoFar is recomputed and shown on the
+ display. \uicontrol{Clear All} resets \c sumSoFar to zero.
+ \li \c factorSoFar stores a temporary value when doing
+ multiplications and divisions.
+ \li \c pendingAdditiveOperator stores the last additive operator
+ clicked by the user.
+ \li \c pendingMultiplicativeOperator stores the last multiplicative operator
+ clicked by the user.
+ \li \c waitingForOperand is \c true when the calculator is
+ expecting the user to start typing an operand.
+ \endlist
+
+ Additive and multiplicative operators are treated differently
+ because they have different precedences. For example, \uicontrol{1 + 2 \unicode{247}
+ 3} is interpreted as \uicontrol{1 + (2 \unicode{247} 3)} because \uicontrol{\unicode{247}} has higher
+ precedence than \uicontrol{+}.
+
+ The table below shows the evolution of the calculator state as
+ the user enters a mathematical expression.
+
+ \table
+ \header \li User Input \li Display \li Sum so Far \li Add. Op. \li Factor so Far \li Mult. Op. \li Waiting for Operand?
+ \row \li \li 0 \li 0 \li \li \li \li \c true
+ \row \li \uicontrol{1} \li 1 \li 0 \li \li \li \li \c false
+ \row \li \uicontrol{1 +} \li 1 \li 1 \li \uicontrol{+} \li \li \li \c true
+ \row \li \uicontrol{1 + 2} \li 2 \li 1 \li \uicontrol{+} \li \li \li \c false
+ \row \li \uicontrol{1 + 2 \unicode{247}} \li 2 \li 1 \li \uicontrol{+} \li 2 \li \uicontrol{\unicode{247}} \li \c true
+ \row \li \uicontrol{1 + 2 \unicode{247} 3} \li 3 \li 1 \li \uicontrol{+} \li 2 \li \uicontrol{\unicode{247}} \li \c false
+ \row \li \uicontrol{1 + 2 \unicode{247} 3 -} \li 1.66667 \li 1.66667 \li \uicontrol{-} \li \li \li \c true
+ \row \li \uicontrol{1 + 2 \unicode{247} 3 - 4} \li 4 \li 1.66667 \li \uicontrol{-} \li \li \li \c false
+ \row \li \uicontrol{1 + 2 \unicode{247} 3 - 4 =} \li -2.33333 \li 0 \li \li \li \li \c true
+ \endtable
+
+ Unary operators, such as \uicontrol Sqrt, require no special handling;
+ they can be applied immediately since the operand is already
+ known when the operator button is clicked.
+
+ \snippet widgets/calculator/calculator.h 9
+ \codeline
+ \snippet widgets/calculator/calculator.h 10
+
+ Finally, we declare the variables associated with the display and the
+ buttons used to display numerals.
+
+ \section1 Calculator Class Implementation
+
+ \snippet widgets/calculator/calculator.cpp 0
+
+ In the constructor, we initialize the calculator's state. The \c
+ pendingAdditiveOperator and \c pendingMultiplicativeOperator
+ variables don't need to be initialized explicitly, because the
+ QString constructor initializes them to empty strings.
+
+ \snippet widgets/calculator/calculator.cpp 1
+ \snippet widgets/calculator/calculator.cpp 2
+
+ We create the QLineEdit representing the calculator's display and
+ set up some of its properties. In particular, we set it to be
+ read-only.
+
+ We also enlarge \c{display}'s font by 8 points.
+
+ \snippet widgets/calculator/calculator.cpp 4
+
+ For each button, we call the private \c createButton() function with
+ the proper text label and a slot to connect to the button.
+
+ \snippet widgets/calculator/calculator.cpp 5
+ \snippet widgets/calculator/calculator.cpp 6
+
+ The layout is handled by a single QGridLayout. The
+ QLayout::setSizeConstraint() call ensures that the \c Calculator
+ widget is always shown as its optimal size (its
+ \l{QWidget::sizeHint()}{size hint}), preventing the user from
+ resizing the calculator. The size hint is determined by the size
+ and \l{QWidget::sizePolicy()}{size policy} of the child widgets.
+
+ Most child widgets occupy only one cell in the grid layout. For
+ these, we only need to pass a row and a column to
+ QGridLayout::addWidget(). The \c display, \c backspaceButton, \c
+ clearButton, and \c clearAllButton widgets occupy more than one
+ column; for these we must also pass a row span and a column
+ span.
+
+ \snippet widgets/calculator/calculator.cpp 7
+
+ Pressing one of the calculator's digit buttons will emit the
+ button's \l{QToolButton::clicked()}{clicked()} signal, which will
+ trigger the \c digitClicked() slot.
+
+ First, we find out which button sent the signal using
+ QObject::sender(). This function returns the sender as a QObject
+ pointer. Since we know that the sender is a \c Button object, we
+ can safely cast the QObject. We could have used a C-style cast or
+ a C++ \c static_cast<>(), but as a defensive programming
+ technique we use a \l qobject_cast(). The advantage is that if
+ the object has the wrong type, a null pointer is returned.
+ Crashes due to null pointers are much easier to diagnose than
+ crashes due to unsafe casts. Once we have the button, we extract
+ the operator using QToolButton::text().
+
+ The slot needs to consider two situations in particular. If \c
+ display contains "0" and the user clicks the \uicontrol{0} button, it
+ would be silly to show "00". And if the calculator is in
+ a state where it is waiting for a new operand,
+ the new digit is the first digit of that new operand; in that case,
+ any result of a previous calculation must be cleared first.
+
+ At the end, we append the new digit to the value in the display.
+
+ \snippet widgets/calculator/calculator.cpp 8
+ \snippet widgets/calculator/calculator.cpp 9
+
+ The \c unaryOperatorClicked() slot is called whenever one of the
+ unary operator buttons is clicked. Again a pointer to the clicked
+ button is retrieved using QObject::sender(). The operator is
+ extracted from the button's text and stored in \c
+ clickedOperator. The operand is obtained from \c display.
+
+ Then we perform the operation. If \uicontrol Sqrt is applied to a
+ negative number or \uicontrol{1/x} to zero, we call \c
+ abortOperation(). If everything goes well, we display the result
+ of the operation in the line edit and we set \c waitingForOperand
+ to \c true. This ensures that if the user types a new digit, the
+ digit will be considered as a new operand, instead of being
+ appended to the current value.
+
+ \snippet widgets/calculator/calculator.cpp 10
+ \snippet widgets/calculator/calculator.cpp 11
+
+ The \c additiveOperatorClicked() slot is called when the user
+ clicks the \uicontrol{+} or \uicontrol{-} button.
+
+ Before we can actually do something about the clicked operator,
+ we must handle any pending operations. We start with the
+ multiplicative operators, since these have higher precedence than
+ additive operators:
+
+ \snippet widgets/calculator/calculator.cpp 12
+ \snippet widgets/calculator/calculator.cpp 13
+
+ If \uicontrol{\unicode{215}} or \uicontrol{\unicode{247}} has been clicked earlier, without clicking
+ \uicontrol{=} afterward, the current value in the display is the right
+ operand of the \uicontrol{\unicode{215}} or \uicontrol{\unicode{247}} operator and we can finally
+ perform the operation and update the display.
+
+ \snippet widgets/calculator/calculator.cpp 14
+ \snippet widgets/calculator/calculator.cpp 15
+
+ If \uicontrol{+} or \uicontrol{-} has been clicked earlier, \c sumSoFar is
+ the left operand and the current value in the display is the
+ right operand of the operator. If there is no pending additive
+ operator, \c sumSoFar is simply set to be the text in the
+ display.
+
+ \snippet widgets/calculator/calculator.cpp 16
+ \snippet widgets/calculator/calculator.cpp 17
+
+ Finally, we can take care of the operator that was just clicked.
+ Since we don't have the right-hand operand yet, we store the clicked
+ operator in the \c pendingAdditiveOperator variable. We will
+ apply the operation later, when we have a right operand, with \c
+ sumSoFar as the left operand.
+
+ \snippet widgets/calculator/calculator.cpp 18
+
+ The \c multiplicativeOperatorClicked() slot is similar to \c
+ additiveOperatorClicked(). We don't need to worry about pending
+ additive operators here, because multiplicative operators have
+ precedence over additive operators.
+
+ \snippet widgets/calculator/calculator.cpp 20
+
+ Like in \c additiveOperatorClicked(), we start by handing any
+ pending multiplicative and additive operators. Then we display \c
+ sumSoFar and reset the variable to zero. Resetting the variable
+ to zero is necessary to avoid counting the value twice.
+
+ \snippet widgets/calculator/calculator.cpp 22
+
+ The \c pointClicked() slot adds a decimal point to the content in
+ \c display.
+
+ \snippet widgets/calculator/calculator.cpp 24
+
+ The \c changeSignClicked() slot changes the sign of the value in
+ \c display. If the current value is positive, we prepend a minus
+ sign; if the current value is negative, we remove the first
+ character from the value (the minus sign).
+
+ \snippet widgets/calculator/calculator.cpp 26
+
+ The \c backspaceClicked() removes the rightmost character in the
+ display. If we get an empty string, we show "0" and set \c
+ waitingForOperand to \c true.
+
+ \snippet widgets/calculator/calculator.cpp 28
+
+ The \c clear() slot resets the current operand to zero. It is
+ equivalent to clicking \uicontrol Backspace enough times to erase the
+ entire operand.
+
+ \snippet widgets/calculator/calculator.cpp 30
+
+ The \c clearAll() slot resets the calculator to its initial state.
+
+ \snippet widgets/calculator/calculator.cpp 32
+
+ The \c clearMemory() slot erases the sum kept in memory, \c
+ readMemory() displays the sum as an operand, \c setMemory()
+ replace the sum in memory with the current sum, and \c
+ addToMemory() adds the current value to the value in memory. For
+ \c setMemory() and \c addToMemory(), we start by calling \c
+ equalClicked() to update \c sumSoFar and the value in the
+ display.
+
+ \snippet widgets/calculator/calculator.cpp 34
+
+ The private \c createButton() function is called from the
+ constructor to create calculator buttons.
+
+ \snippet widgets/calculator/calculator.cpp 36
+
+ The private \c abortOperation() function is called whenever a
+ calculation fails. It resets the calculator state and displays
+ "####".
+
+ \snippet widgets/calculator/calculator.cpp 38
+
+ The private \c calculate() function performs a binary operation.
+ The right operand is given by \c rightOperand. For additive
+ operators, the left operand is \c sumSoFar; for multiplicative
+ operators, the left operand is \c factorSoFar. The function
+ return \c false if a division by zero occurs.
+
+ \section1 Button Class Definition
+
+ Let's now take a look at the \c Button class:
+
+ \snippet widgets/calculator/button.h 0
+
+ The \c Button class has a convenience constructor that takes a
+ text label and a parent widget, and it reimplements QWidget::sizeHint()
+ to provide more space around the text than the amount QToolButton
+ normally provides.
+
+ \section1 Button Class Implementation
+
+ \snippet widgets/calculator/button.cpp 0
+
+ The buttons' appearance is determined by the layout of the
+ calculator widget through the size and
+ \l{QWidget::sizePolicy}{size policy} of the layout's child
+ widgets. The call to the
+ \l{QWidget::setSizePolicy()}{setSizePolicy()} function in the
+ constructor ensures that the button will expand horizontally to
+ fill all the available space; by default, \l{QToolButton}s don't
+ expand to fill available space. Without this call, the different
+ buttons in a same column would have different widths.
+
+ \snippet widgets/calculator/button.cpp 1
+ \snippet widgets/calculator/button.cpp 2
+
+ In \l{QWidget::sizeHint()}{sizeHint()}, we try to return a size
+ that looks good for most buttons. We reuse the size hint of the
+ base class (QToolButton) but modify it in the following ways:
+
+ \list
+ \li We add 20 to the \l{QSize::height()}{height} component of the size hint.
+ \li We make the \l{QSize::width()}{width} component of the size
+ hint at least as much as the \l{QSize::width()}{height}.
+ \endlist
+
+ This ensures that with most fonts, the digit and operator buttons
+ will be square, without truncating the text on the
+ \uicontrol{Backspace}, \uicontrol{Clear}, and \uicontrol{Clear All} buttons.
+
+ The screenshot below shows how the \c Calculator widget would
+ look like if we \e didn't set the horizontal size policy to
+ QSizePolicy::Expanding in the constructor and if we didn't
+ reimplement QWidget::sizeHint().
+
+ \image calculator-ugly.png The Calculator example with default size policies and size hints
+
+*/
diff --git a/examples/widgets/doc/calendar.qdoc b/examples/widgets/doc/calendar.qdoc
new file mode 100644
index 0000000000..b7fa7c8617
--- /dev/null
+++ b/examples/widgets/doc/calendar.qdoc
@@ -0,0 +1,223 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example richtext/calendar
+ \title Calendar Example
+
+ The Calendar example shows how to create rich text content and display it using
+ a rich text editor.
+
+ \image calendar-example.png
+
+ Specifically, the example demonstrates the following:
+
+ \list
+ \li Use of a text editor with a text document
+ \li Insertion of tables and frames into a document
+ \li Navigation within a table
+ \li Insert text in different styles
+ \endlist
+
+ The rich text editor used to display the document is used within a main window
+ application.
+
+ \section1 MainWindow Class Definition
+
+ The \c MainWindow class provides a text editor widget and some controls to
+ allow the user to change the month and year shown. The font size used for the
+ text can also be adjusted.
+
+ \snippet richtext/calendar/mainwindow.h 0
+
+ The private \c insertCalendar() function performs most of the work, relying on
+ the \c fontSize and \c selectedDate variables to write useful information to
+ the \c editor.
+
+ \section1 MainWindow Class Implementation
+
+ The \c MainWindow constructor sets up the user interface and initializes
+ variables used to generate a calendar for each month.
+
+ \snippet richtext/calendar/mainwindow.cpp 0
+
+ We begin by setting default values for the selected date that will be highlighted
+ in the calendar and the font size to be used. Since we are using a QMainWindow
+ for the user interface, we construct a widget for use as the central widget.
+
+ The user interface will include a line of controls above the generated calendar;
+ we construct a label and a combobox to allow the month to be selected, and a
+ spin box for the year. These widgets are configured to provide a reasonable range
+ of values for the user to try:
+
+ \snippet richtext/calendar/mainwindow.cpp 1
+
+ We use the \c selectedDate object to obtain the current month and year, and we
+ set these in the combobox and spin box:
+
+ The font size is displayed in a spin box which we restrict to a sensible range
+ of values:
+
+ \snippet richtext/calendar/mainwindow.cpp 2
+
+ We construct an editor and use the \c insertCalendar() function to create
+ a calendar for it. Each calendar is displayed in the same text editor; in
+ this example we use a QTextBrowser since we do not allow the calendar to be
+ edited.
+
+ The controls used to set the month, year, and font size will not have any
+ effect on the appearance of the calendar unless we make some signal-slot
+ connections:
+
+ \snippet richtext/calendar/mainwindow.cpp 3
+
+ The signals are connected to some simple slots in the \c MainWindow class
+ which we will describe later.
+
+ We create layouts to manage the widgets we constructed:
+
+ \snippet richtext/calendar/mainwindow.cpp 4
+
+ Finally, the central widget is set for the window.
+
+ Each calendar is created for the editor by the \c insertCalendar() function
+ which uses the date and font size, defined by the private \a selectedDate
+ and \c fontSize variables, to produce a suitable plan for the specified
+ month and year.
+
+ \snippet richtext/calendar/mainwindow.cpp 5
+
+ We begin by clearing the editor's rich text document, and obtain a text
+ cursor from the editor that we will use to add content. We also create a
+ QDate object based on the currently selected date.
+
+ The calendar is made up of a table with a gray background color that contains
+ seven columns: one for each day of the week. It is placed in the center of the
+ page with equal space to the left and right of it. All of these properties are
+ set in a QTextTableFormat object:
+
+ \snippet richtext/calendar/mainwindow.cpp 6
+
+ Each cell in the table will be padded and spaced to make the text easier to
+ read.
+
+ We want the columns to have equal widths, so we provide a vector containing
+ percentage widths for each of them and set the constraints in the
+ QTextTableFormat:
+
+ \snippet richtext/calendar/mainwindow.cpp 7
+
+ The constraints used for the column widths are only useful if the table has
+ an appropriate number of columns. With the format for the table defined, we
+ construct a new table with one row and seven columns at the current cursor
+ position:
+
+ \snippet richtext/calendar/mainwindow.cpp 8
+
+ We only need one row to start with; more can be added as we need them. Using
+ this approach means that we do not need to perform any date calculations
+ until we add cells to the table.
+
+ When inserting objects into a document with the cursor's insertion functions,
+ the cursor is automatically moved inside the newly inserted object. This means
+ that we can immediately start modifying the table from within:
+
+ \snippet richtext/calendar/mainwindow.cpp 9
+
+ Since the table has an outer frame, we obtain the frame and its format so that
+ we can customize it. After making the changes we want, we set the frame's format
+ using the modified format object. We have given the table an outer border one
+ pixel wide.
+
+ \snippet richtext/calendar/mainwindow.cpp 10
+
+ In a similar way, we obtain the cursor's current character format and
+ create customized formats based on it.
+
+ We do not set the format on the cursor because this would change the default
+ character format; instead, we use the customized formats explicitly when we
+ insert text. The following loop inserts the days of the week into the table
+ as bold text:
+
+ \snippet richtext/calendar/mainwindow.cpp 11
+
+ For each day of the week, we obtain an existing table cell in the first row
+ (row 0) using the table's \l{QTextTable::cellAt()}{cellAt()} function. Since
+ we start counting the days of the week at day 1 (Monday), we subtract 1 from
+ \c weekDay to ensure that we obtain the cell for the correct column of the
+ table.
+
+ Before text can be inserted into a cell, we must obtain a cursor with the
+ correct position in the document. The cell provides a function for this
+ purpose, and we use this cursor to insert text using the \c boldFormat
+ character format that we created earlier:
+
+ \snippet richtext/calendar/mainwindow.cpp 12
+
+ Inserting text into document objects usually follows the same pattern.
+ Each object can provide a new cursor that corresponds to the first valid
+ position within itself, and this can be used to insert new content. We
+ continue to use this pattern as we insert the days of the month into the
+ table.
+
+ Since every month has more than seven days, we insert a single row to begin
+ and add days until we reach the end of the month. If the current date is
+ encountered, it is inserted with a special format (created earlier) that
+ makes it stand out:
+
+ \snippet richtext/calendar/mainwindow.cpp 13
+
+ We add a new row to the table at the end of each week only if the next week
+ falls within the currently selected month.
+
+ For each calendar that we create, we change the window title to reflect the
+ currently selected month and year:
+
+ \snippet richtext/calendar/mainwindow.cpp 14
+
+ The \c insertCalendar() function relies on up-to-date values for the month,
+ year, and font size. These are set in the following slots:
+
+ \snippet richtext/calendar/mainwindow.cpp 15
+
+ The \c setFontSize() function simply changes the private \c fontSize variable
+ before updating the calendar.
+
+ \snippet richtext/calendar/mainwindow.cpp 16
+
+ The \c setMonth slot is called when the QComboBox used to select the month is
+ updated. The value supplied is the currently selected row in the combobox.
+ We add 1 to this value to obtain a valid month number, and create a new QDate
+ based on the existing one. The calendar is then updated to use this new date.
+
+ \snippet richtext/calendar/mainwindow.cpp 17
+
+ The \c setYear() slot is called when the QDateTimeEdit used to select the
+ year is updated. The value supplied is a QDate object; this makes
+ the construction of a new value for \c selectedDate simple. We update the
+ calendar afterwards to use this new date.
+*/
diff --git a/examples/widgets/doc/calendarwidget.qdoc b/examples/widgets/doc/calendarwidget.qdoc
new file mode 100644
index 0000000000..ad15bbaa0c
--- /dev/null
+++ b/examples/widgets/doc/calendarwidget.qdoc
@@ -0,0 +1,291 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \title Calendar Widget Example
+ \example widgets/calendarwidget
+
+ The Calendar Widget example shows use of \c QCalendarWidget.
+
+ \image calendarwidgetexample.png
+
+ QCalendarWidget displays one calendar month
+ at a time and lets the user select a date.
+ The calendar consists of four components: a navigation
+ bar that lets the user change the month that is
+ displayed, a grid where each cell represents one day
+ in the month, and two headers that display weekday names
+ and week numbers.
+
+ The Calendar Widget example displays a QCalendarWidget and lets the user
+ configure its appearance and behavior using
+ \l{QComboBox}es, \l{QCheckBox}es, and \l{QDateEdit}s. In
+ addition, the user can influence the formatting of individual dates
+ and headers.
+
+ The properties of the QCalendarWidget are summarized in the table
+ below.
+
+ \table
+ \header \li Property
+ \li Description
+ \row \li \l{QCalendarWidget::}{selectedDate}
+ \li The currently selected date.
+ \row \li \l{QCalendarWidget::}{minimumDate}
+ \li The earliest date that can be selected.
+ \row \li \l{QCalendarWidget::}{maximumDate}
+ \li The latest date that can be selected.
+ \row \li \l{QCalendarWidget::}{firstDayOfWeek}
+ \li The day that is displayed as the first day of the week
+ (usually Sunday or Monday).
+ \row \li \l{QCalendarWidget::}{gridVisible}
+ \li Whether the grid should be shown.
+ \row \li \l{QCalendarWidget::}{selectionMode}
+ \li Whether the user can select a date or not.
+ \row \li \l{QCalendarWidget::}{horizontalHeaderFormat}
+ \li The format of the day names in the horizontal header
+ (e.g., "M", "Mon", or "Monday").
+ \row \li \l{QCalendarWidget::}{verticalHeaderFormat}
+ \li The format of the vertical header.
+ \row \li \l{QCalendarWidget::}{navigationBarVisible}
+ \li Whether the navigation bar at the top of the calendar
+ widget is shown.
+ \endtable
+
+ The example consists of one class, \c Window, which creates and
+ lays out the QCalendarWidget and the other widgets that let the
+ user configure the QCalendarWidget.
+
+ \section1 Window Class Definition
+
+ Here is the definition of the \c Window class:
+
+ \snippet widgets/calendarwidget/window.h 0
+ \dots
+ \snippet widgets/calendarwidget/window.h 1
+
+ As is often the case with classes that represent self-contained
+ windows, most of the API is private. We will review the private
+ members as we stumble upon them in the implementation.
+
+ \section1 Window Class Implementation
+
+ Let's now review the class implementation, starting with the constructor:
+
+ \snippet widgets/calendarwidget/window.cpp 0
+
+ We start by creating the four \l{QGroupBox}es and their child
+ widgets (including the QCalendarWidget) using four private \c
+ create...GroupBox() functions, described below. Then we arrange
+ the group boxes in a QGridLayout.
+
+ We set the grid layout's resize policy to QLayout::SetFixedSize to
+ prevent the user from resizing the window. In that mode, the
+ window's size is set automatically by QGridLayout based on the
+ size hints of its contents widgets.
+
+ To ensure that the window isn't automatically resized every time
+ we change a property of the QCalendarWidget (e.g., hiding the
+ navigation bar, trhe vertical header, or the grid), we set the
+ minimum height of row 0 and the minimum width of column 0 to the
+ initial size of the QCalendarWidget.
+
+ Let's move on to the \c createPreviewGroupBox() function:
+
+ \snippet widgets/calendarwidget/window.cpp 9
+
+ The \uicontrol Preview group box contains only one widget: the
+ QCalendarWidget. We set it up, connect its
+ \l{QCalendarWidget::}{currentPageChanged()} signal to our \c
+ reformatCalendarPage() slot to make sure that every new page gets
+ the formatting specified by the user.
+
+ The \c createGeneralOptionsGroupBox() function is somewhat large
+ and several widgets are set up the same way; we look at parts of
+ its implementation here and skip the rest:
+
+ \snippet widgets/calendarwidget/window.cpp 10
+ \dots
+
+ We start with the setup of the \uicontrol{Week starts on} combobox.
+ This combobox controls which day should be displayed as the first
+ day of the week.
+
+ The QComboBox class lets us attach user data as a QVariant to
+ each item. The data can later be retrieved with QComboBox's
+ \l{QComboBox::}{itemData()} function. QVariant doesn't directly
+ support the Qt::DayOfWeek data type, but it supports \c int, and
+ C++ will happily convert any enum value to \c int.
+
+ \dots
+ \snippet widgets/calendarwidget/window.cpp 11
+ \dots
+
+ After creating the widgets, we connect the signals and slots. We
+ connect the comboboxes to private slots of \c Window or to
+ public slots provided by QComboBox.
+
+ \dots
+ \snippet widgets/calendarwidget/window.cpp 12
+
+ At the end of the function, we call the slots that update the calendar to ensure
+ that the QCalendarWidget is synchronized with the other widgets on startup.
+
+ Let's now take a look at the \c createDatesGroupBox() private function:
+
+ \snippet widgets/calendarwidget/window.cpp 13
+
+ In this function, we create the \uicontrol {Minimum Date}, \uicontrol {Maximum Date},
+ and \uicontrol {Current Date} editor widgets,
+ which control the calendar's minimum, maximum, and selected dates.
+ The calendar's minimum and maximum dates have already been
+ set in \c createPrivewGroupBox(); we can then set the widgets
+ default values to the calendars values.
+
+ \snippet widgets/calendarwidget/window.cpp 14
+ \dots
+ \snippet widgets/calendarwidget/window.cpp 15
+
+ We connect the \c currentDateEdit's
+ \l{QDateEdit::}{dateChanged()} signal directly to the calendar's
+ \l{QCalendarWidget::}{setSelectedDate()} slot. When the calendar's
+ selected date changes, either as a result of a user action or
+ programmatically, our \c selectedDateChanged() slot updates
+ the \uicontrol {Current Date} editor. We also need to react when the user
+ changes the \uicontrol{Minimum Date} and \uicontrol{Maximum Date} editors.
+
+ Here is the \c createTextFormatsGroup() function:
+
+ \snippet widgets/calendarwidget/window.cpp 16
+
+ We set up the \uicontrol {Weekday Color} and \uicontrol {Weekend Color} comboboxes
+ using \c createColorCombo(), which instantiates a QComboBox and
+ populates it with colors ("Red", "Blue", etc.).
+
+ \snippet widgets/calendarwidget/window.cpp 17
+
+ The \uicontrol {Header Text Format} combobox lets the user change the
+ text format (bold, italic, or plain) used for horizontal and
+ vertical headers. The \uicontrol {First Friday in blue} and \uicontrol {May 1
+ in red} check box affect the rendering of specific dates.
+
+ \snippet widgets/calendarwidget/window.cpp 18
+
+ We connect the check boxes and comboboxes to various private
+ slots. The \uicontrol {First Friday in blue} and \uicontrol {May 1 in red}
+ check boxes are both connected to \c reformatCalendarPage(),
+ which is also called when the calendar switches month.
+
+ \dots
+ \snippet widgets/calendarwidget/window.cpp 19
+
+ At the end of \c createTextFormatsGroupBox(), we call private
+ slots to synchronize the QCalendarWidget with the other widgets.
+
+ We're now done reviewing the four \c create...GroupBox()
+ functions. Let's now take a look at the other private functions
+ and slots.
+
+ \snippet widgets/calendarwidget/window.cpp 20
+
+ In \c createColorCombo(), we create a combobox and populate it with
+ standard colors. The second argument to QComboBox::addItem()
+ is a QVariant storing user data (in this case, QColor objects).
+
+ This function was used to set up the \uicontrol {Weekday Color}
+ and \uicontrol {Weekend Color} comboboxes.
+
+ \snippet widgets/calendarwidget/window.cpp 1
+
+ When the user changes the \uicontrol {Week starts on} combobox's
+ value, \c firstDayChanged() is invoked with the index of the
+ combobox's new value. We retrieve the custom data item
+ associated with the new current item using
+ \l{QComboBox::}{itemData()} and cast it to a Qt::DayOfWeek.
+
+ \c selectionModeChanged(), \c horizontalHeaderChanged(), and \c
+ verticalHeaderChanged() are very similar to \c firstDayChanged(),
+ so they are omitted.
+
+ \snippet widgets/calendarwidget/window.cpp 2
+
+ The \c selectedDateChanged() updates the \uicontrol{Current Date}
+ editor to reflect the current state of the QCalendarWidget.
+
+ \snippet widgets/calendarwidget/window.cpp 3
+
+ When the user changes the minimum date, we tell the
+ QCalenderWidget. We also update the \uicontrol {Maximum Date} editor,
+ because if the new minimum date is later than the current maximum
+ date, QCalendarWidget will automatically adapt its maximum date
+ to avoid a contradicting state.
+
+ \snippet widgets/calendarwidget/window.cpp 4
+
+ \c maximumDateChanged() is implemented similarly to \c
+ minimumDateChanged().
+
+ \snippet widgets/calendarwidget/window.cpp 5
+
+ Each combobox item has a QColor object as user data corresponding to the
+ item's text. After fetching the colors from the comboboxes, we
+ set the text format of each day of the week.
+
+ The text format of a column in the calendar is given as a
+ QTextCharFormat, which besides the foreground color lets us
+ specify various character formatting information. In this
+ example, we only show a subset of the possibilities.
+
+ \snippet widgets/calendarwidget/window.cpp 6
+
+ \c weekendFormatChanged() is the same as \c
+ weekdayFormatChanged(), except that it affects Saturday and
+ Sunday instead of Monday to Friday.
+
+ \snippet widgets/calendarwidget/window.cpp 7
+
+ The \c reformatHeaders() slot is called when the user
+ changes the text format of
+ the headers. We compare the current text of the \uicontrol {Header Text Format}
+ combobox to determine which format to apply. (An alternative would
+ have been to store \l{QTextCharFormat} values alongside the combobox
+ items.)
+
+ \snippet widgets/calendarwidget/window.cpp 8
+
+ In \c reformatCalendarPage(), we set the text format of the first
+ Friday in the month and May 1 in the current year. The text
+ formats that are actually used depend on which check boxes are
+ checked.
+
+ QCalendarWidget lets us set the text format of individual dates
+ with the \l{QCalendarWidget::}{setDateTextFormat()}. We chose to
+ set the dates when the calendar page changes, i.e., a new month is
+ displayed. We check which of the \c mayFirstCheckBox and \c
+ firstDayCheckBox, if any, are checked
+ and set the text formats accordingly.
+*/
diff --git a/examples/widgets/doc/charactermap.qdoc b/examples/widgets/doc/charactermap.qdoc
new file mode 100644
index 0000000000..fee2a42156
--- /dev/null
+++ b/examples/widgets/doc/charactermap.qdoc
@@ -0,0 +1,274 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+\example widgets/charactermap
+\title Character Map Example
+
+The Character Map example shows how to create a custom widget that can
+both display its own content and respond to user input.
+
+The example displays an array of characters which the user can click on
+to enter text in a line edit. The contents of the line edit can then be
+copied into the clipboard, and pasted into other applications. The
+purpose behind this sort of tool is to allow users to enter characters
+that may be unavailable or difficult to locate on their keyboards.
+
+\image charactermap-example.png Screenshot of the Character Map example
+
+The example consists of the following classes:
+
+\list
+\li \c CharacterWidget displays the available characters in the current
+ font and style.
+\li \c MainWindow provides a standard main window that contains font and
+ style information, a view onto the characters, a line edit, and a push
+ button for submitting text to the clipboard.
+\endlist
+
+\section1 CharacterWidget Class Definition
+
+The \c CharacterWidget class is used to display an array of characters in
+a user-specified font and style. For flexibility, we subclass QWidget and
+reimplement only the functions that we need to provide basic rendering
+and interaction features.
+
+The class definition looks like this:
+
+\snippet widgets/charactermap/characterwidget.h 0
+
+The widget does not contain any other widgets, so it must provide its own
+size hint to allow its contents to be displayed correctly.
+We reimplement \l{QWidget::paintEvent()} to draw custom content. We also
+reimplement \l{QWidget::mousePressEvent()} to allow the user to interact
+with the widget.
+
+The updateFont() and updateStyle() slots are used to update the font and
+style of the characters in the widget whenever the user changes the
+settings in the application.
+The class defines the characterSelected() signal so that other parts
+of the application are informed whenever the user selects a character in
+the widget.
+As a courtesy, the widget provides a tooltip that shows the current
+character value. We reimplement the \l{QWidget::mouseMoveEvent()} event
+handler and define showToolTip() to enable this feature.
+
+The \c columns, \c displayFont and \c currentKey private data members
+are used to record the number of columns to be shown, the current font,
+and the currently highlighted character in the widget.
+
+\section1 CharacterWidget Class Implementation
+
+Since the widget is to be used as a simple canvas, the constructor just
+calls the base class constructor and defines some default values for
+private data members.
+
+\snippet widgets/charactermap/characterwidget.cpp 0
+
+We initialize \c currentKey with a value of -1 to indicate
+that no character is initially selected. We enable mouse tracking to
+allow us to follow the movement of the cursor across the widget.
+
+The class provides two functions to allow the font and style to be set up.
+Each of these modify the widget's display font and call update():
+
+\snippet widgets/charactermap/characterwidget.cpp 1
+\codeline
+\snippet widgets/charactermap/characterwidget.cpp 2
+
+We use a fixed size font for the display. Similarly, a fixed size hint is
+provided by the sizeHint() function:
+
+\snippet widgets/charactermap/characterwidget.cpp 3
+
+Three standard event functions are implemented so that the widget
+can respond to clicks, provide tooltips, and render the available
+characters. The paintEvent() shows how the contents of the widget are
+arranged and displayed:
+
+\snippet widgets/charactermap/characterwidget.cpp 6
+
+A QPainter is created for the widget and, in all cases, we ensure that the
+widget's background is painted. The painter's font is set to the
+user-specified display font.
+
+The area of the widget that needs to be redrawn is used to determine which
+characters need to be displayed:
+
+\snippet widgets/charactermap/characterwidget.cpp 7
+
+Using integer division, we obtain the row and column numbers of each
+characters that should be displayed, and we draw a square on the widget
+for each character displayed.
+
+\snippet widgets/charactermap/characterwidget.cpp 8
+\snippet widgets/charactermap/characterwidget.cpp 9
+
+The symbols for each character in the array are drawn within each square,
+with the symbol for the most recently selected character displayed in red:
+
+\snippet widgets/charactermap/characterwidget.cpp 10
+
+We do not need to take into account the difference between the area
+displayed in the viewport and the area we are drawing on because
+everything outside the visible area will be clipped.
+
+The mousePressEvent() defines how the widget responds to mouse clicks.
+
+\snippet widgets/charactermap/characterwidget.cpp 5
+
+We are only interested when the user clicks with the left mouse button
+over the widget. When this happens, we calculate which character was
+selected and emit the characterSelected() signal.
+The character's number is found by dividing the x and y-coordinates of
+the click by the size of each character's grid square. Since the number
+of columns in the widget is defined by the \c columns variable, we
+simply multiply the row index by that value and add the column number
+to obtain the character number.
+
+If any other mouse button is pressed, the event is passed on to the
+QWidget base class. This ensures that the event can be handled properly
+by any other interested widgets.
+
+The mouseMoveEvent() maps the mouse cursor's position in global
+coordinates to widget coordinates, and determines the character that
+was clicked by performing the calculation
+
+\snippet widgets/charactermap/characterwidget.cpp 4
+
+The tooltip is given a position defined in global coordinates.
+
+\section1 MainWindow Class Definition
+
+The \c MainWindow class provides a minimal user interface for the example,
+with only a constructor, slots that respond to signals emitted by standard
+widgets, and some convenience functions that are used to set up the user
+interface.
+
+The class definition looks like this:
+
+\snippet widgets/charactermap/mainwindow.h 0
+
+The main window contains various widgets that are used to control how
+the characters will be displayed, and defines the findFonts() function
+for clarity and convenience. The findStyles() slot is used by the widgets
+to determine the styles that are available, insertCharacter() inserts
+a user-selected character into the window's line edit, and
+updateClipboard() synchronizes the clipboard with the contents of the
+line edit.
+
+\section1 MainWindow Class Implementation
+
+In the constructor, we set up the window's central widget and fill it with
+some standard widgets (two comboboxes, a line edit, and a push button).
+We also construct a CharacterWidget custom widget, and add a QScrollArea
+so that we can view its contents:
+
+\snippet widgets/charactermap/mainwindow.cpp 0
+
+QScrollArea provides a viewport onto the \c CharacterWidget when we set
+its widget and handles much of the work needed to provide a scrolling
+viewport.
+
+The font combo box is automatically popuplated with a list of available
+fonts. We list the available styles for the current font in the style
+combobox using the following function:
+
+\snippet widgets/charactermap/mainwindow.cpp 1
+
+The line edit and push button are used to supply text to the clipboard:
+
+\snippet widgets/charactermap/mainwindow.cpp 2
+
+We also obtain a clipboard object so that we can send text entered by the
+user to other applications.
+
+Most of the signals emitted in the example come from standard widgets.
+We connect these signals to slots in this class, and to the slots provided
+by other widgets.
+
+\snippet widgets/charactermap/mainwindow.cpp 4
+
+The font combobox's
+\l{QFontComboBox::currentFontChanged()}{currentFontChanged()} signal is
+connected to the findStyles() function so that the list of available styles
+can be shown for each font that is used. Since both the font and the style
+can be changed by the user, the font combobox's currentFontChanged() signal
+and the style combobox's
+\l{QComboBox::currentIndexChanged()}{currentIndexChanged()} are connected
+directly to the character widget.
+
+The final two connections allow characters to be selected in the character
+widget, and text to be inserted into the clipboard:
+
+\snippet widgets/charactermap/mainwindow.cpp 5
+
+The character widget emits the characterSelected() custom signal when
+the user clicks on a character, and this is handled by the insertCharacter()
+function in this class. The clipboard is changed when the push button emits
+the clicked() signal, and we handle this with the updateClipboard() function.
+
+The remaining code in the constructor sets up the layout of the central widget,
+and provides a window title:
+
+\snippet widgets/charactermap/mainwindow.cpp 6
+
+The font combobox is automatically populated with a list of available font
+families. The styles that can be used with each font are found by the
+findStyles() function. This function is called whenever the user selects a
+different font in the font combobox.
+
+\snippet widgets/charactermap/mainwindow.cpp 7
+
+We begin by recording the currently selected style, and we clear the
+style combobox so that we can insert the styles associated with the
+current font family.
+
+\snippet widgets/charactermap/mainwindow.cpp 8
+
+We use the font database to collect the styles that are available for the
+current font, and insert them into the style combobox. The current item is
+reset if the original style is not available for this font.
+
+The last two functions are slots that respond to signals from the character
+widget and the main window's push button. The insertCharacter() function is
+used to insert characters from the character widget when the user clicks a
+character:
+
+\snippet widgets/charactermap/mainwindow.cpp 9
+
+The character is inserted into the line edit at the current cursor position.
+
+The main window's "To clipboard" push button is connected to the
+updateClipboard() function so that, when it is clicked, the clipboard is
+updated to contain the contents of the line edit:
+
+\snippet widgets/charactermap/mainwindow.cpp 10
+
+We copy all the text from the line edit to the clipboard, but we do not clear
+the line edit.
+*/
diff --git a/examples/widgets/doc/chart.qdoc b/examples/widgets/doc/chart.qdoc
new file mode 100644
index 0000000000..44263d1027
--- /dev/null
+++ b/examples/widgets/doc/chart.qdoc
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/chart
+ \title Chart Example
+
+ The Chart example shows how to create a custom view for the model/view framework.
+
+ \image chart-example.png
+
+ In this example, the items in a table model are represented as slices in a pie chart,
+ relying on the flexibility of the model/view architecture to handle custom editing
+ and selection features.
+
+ \b{Note that you only need to create a new view class if your data requires a
+ specialized representation.} You should first consider using a standard QListView,
+ QTableView, or QTreeView with a custom QItemDelegate subclass if you need to
+ represent data in a special way.
+
+ \omit
+ \section1 PieView Class Definition
+
+ The \c PieView class is a subclass of QAbstractItemView. The base class provides
+ much of the functionality required by view classes, so we only need to provide
+ implementations for three public functions: visualRect(), scrollTo(), and
+ indexAt(). However, the view needs to maintain strict control over its look and
+ feel, so we also provide implementations for a number of other functions:
+
+ \snippet itemviews/chart/pieview.h 0
+
+
+
+ \section1 PieView Class Implementation
+
+ The paint event renders the data from the standard item model as a pie chart.
+ We interpret the data in the following way:
+
+ \list
+ \li Column 0 contains data in two different roles:
+ The \l{Qt::ItemDataRole}{DisplayRole} contains a label, and the
+ \l{Qt::ItemDataRole}{DecorationRole} contains the color of the pie slice.
+ \li Column 1 contains a quantity which we will convert to the angular extent of
+ the slice.
+ \endlist
+
+ The figure is always drawn with the chart on the left and the key on
+ the right. This means that we must try and obtain an area that is wider
+ than it is tall. We do this by imposing a particular aspect ratio on
+ the chart and applying it to the available vertical space. This ensures
+ that we always obtain the maximum horizontal space for the aspect ratio
+ used.
+ We also apply fixed size margin around the figure.
+
+ We use logical coordinates to draw the chart and key, and position them
+ on the view using viewports.
+ \endomit
+*/
diff --git a/examples/widgets/doc/chip.qdoc b/examples/widgets/doc/chip.qdoc
new file mode 100644
index 0000000000..966c16900a
--- /dev/null
+++ b/examples/widgets/doc/chip.qdoc
@@ -0,0 +1,38 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example graphicsview/chip
+ \title 40000 Chips
+
+ This demo shows how to visualize a huge scene with 40000 chip items
+ using Graphics View. It also shows Graphics View's powerful navigation
+ and interaction features, allowing you to zoom and rotate each of four
+ views independently, and you can select and move items around the scene.
+
+ \image chip-demo.png
+*/
diff --git a/examples/widgets/doc/classwizard.qdoc b/examples/widgets/doc/classwizard.qdoc
new file mode 100644
index 0000000000..0c357b7286
--- /dev/null
+++ b/examples/widgets/doc/classwizard.qdoc
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example dialogs/classwizard
+ \title Class Wizard Example
+
+ The License Wizard example shows how to implement linear
+ wizards using QWizard.
+
+ \image classwizard.png Screenshot of the Class Wizard example
+
+ Most wizards have a linear structure, with page 1 followed by
+ page 2 and so on until the last page. Some wizards are more
+ complex in that they allow different traversal paths based on the
+ information provided by the user. The
+ \l{dialogs/licensewizard}{License Wizard} example shows how to
+ create such wizards.
+
+ The Class Wizard example consists of the following classes:
+
+ \list
+ \li \c ClassWizard inherits QWizard and provides a
+ three-step wizard that generates the skeleton of a C++ class
+ based on the user's input.
+ \li \c IntroPage, \c ClassInfoPage, \c CodeStylePage, \c
+ OutputFilesPage, and \c ConclusionPage are QWizardPage
+ subclasses that implement the wizard pages.
+ \endlist
+
+ \section1 ClassWizard Class Definition
+
+ \image classwizard-flow.png The Class Wizard pages
+
+ We will see how to subclass QWizard to implement our own wizard.
+ The concrete wizard class is called \c ClassWizard and provides
+ five pages:
+
+ \list
+ \li The first page is an introduction page, telling the user what
+ the wizard is going to do.
+ \li The second page asks for a class name and a base class, and
+ allows the user to specify whether the class should have a \c
+ Q_OBJECT macro and what constructors it should provide.
+ \li The third page allows the user to set some options related to the code
+ style, such as the macro used to protect the header file from
+ multiple inclusion (e.g., \c MYDIALOG_H).
+ \li The fourth page allows the user to specify the names of the
+ output files.
+ \li The fifth page is a conclusion page.
+ \endlist
+
+ Although the program is just an example, if you press \uicontrol Finish
+ (\uicontrol Done on Mac OS X), actual C++ source files will actually be
+ generated.
+
+ \section1 The ClassWizard Class
+
+ Here's the \c ClassWizard definition:
+
+ \snippet dialogs/classwizard/classwizard.h 0
+
+ The class reimplements QDialog's \l{QDialog::}{accept()} slot.
+ This slot is called when the user clicks \uicontrol{Finish}.
+
+ Here's the constructor:
+
+ \snippet dialogs/classwizard/classwizard.cpp 1
+
+ We instantiate the five pages and insert them into the wizard
+ using QWizard::addPage(). The order in which they are inserted
+ is also the order in which they will be shown later on.
+
+ We call QWizard::setPixmap() to set the banner and the
+ background pixmaps for all pages. The banner is used as a
+ background for the page header when the wizard's style is
+ \l{QWizard::}{ModernStyle}; the background is used as the
+ dialog's background in \l{QWizard::}{MacStyle}. (See \l{Elements
+ of a Wizard Page} for more information.)
+
+ \snippet dialogs/classwizard/classwizard.cpp 3
+ \snippet dialogs/classwizard/classwizard.cpp 4
+ \dots
+ \snippet dialogs/classwizard/classwizard.cpp 5
+ \snippet dialogs/classwizard/classwizard.cpp 6
+
+ If the user clicks \uicontrol Finish, we extract the information from
+ the various pages using QWizard::field() and generate the files.
+ The code is long and tedious (and has barely anything to do with
+ noble art of designing wizards), so most of it is skipped here.
+ See the actual example in the Qt distribution for the details if
+ you're curious.
+
+ \section1 The IntroPage Class
+
+ The pages are defined in \c classwizard.h and implemented in \c
+ classwizard.cpp, together with \c ClassWizard. We will start with
+ the easiest page:
+
+ \snippet dialogs/classwizard/classwizard.h 1
+ \codeline
+ \snippet dialogs/classwizard/classwizard.cpp 7
+
+ A page inherits from QWizardPage. We set a
+ \l{QWizardPage::}{title} and a
+ \l{QWizard::WatermarkPixmap}{watermark pixmap}. By not setting
+ any \l{QWizardPage::}{subTitle}, we ensure that no header is
+ displayed for this page. (On Windows, it is customary for wizards
+ to display a watermark pixmap on the first and last pages, and to
+ have a header on the other pages.)
+
+ Then we create a QLabel and add it to a layout.
+
+ \section1 The ClassInfoPage Class
+
+ The second page is defined and implemented as follows:
+
+ \snippet dialogs/classwizard/classwizard.h 2
+ \codeline
+ \snippet dialogs/classwizard/classwizard.cpp 9
+ \dots
+ \snippet dialogs/classwizard/classwizard.cpp 12
+ \dots
+ \snippet dialogs/classwizard/classwizard.cpp 13
+
+ First, we set the page's \l{QWizardPage::}{title},
+ \l{QWizardPage::}{subTitle}, and \l{QWizard::LogoPixmap}{logo
+ pixmap}. The logo pixmap is displayed in the page's header in
+ \l{QWizard::}{ClassicStyle} and \l{QWizard::}{ModernStyle}.
+
+ Then we create the child widgets, create \l{Registering and Using
+ Fields}{wizard fields} associated with them, and put them into
+ layouts. The \c className field is created with an asterisk (\c
+ *) next to its name. This makes it a \l{mandatory field}, that
+ is, a field that must be filled before the user can press the
+ \uicontrol Next button (\uicontrol Continue on Mac OS X). The fields' values
+ can be accessed from any other page using QWizardPage::field(),
+ or from the wizard code using QWizard::field().
+
+ \section1 The CodeStylePage Class
+
+ The third page is defined and implemented as follows:
+
+ \snippet dialogs/classwizard/classwizard.h 3
+ \codeline
+ \snippet dialogs/classwizard/classwizard.cpp 14
+ \dots
+ \snippet dialogs/classwizard/classwizard.cpp 15
+ \codeline
+ \snippet dialogs/classwizard/classwizard.cpp 16
+
+ The code in the constructor is very similar to what we did for \c
+ ClassInfoPage, so we skipped most of it.
+
+ The \c initializePage() function is what makes this class
+ interesting. It is reimplemented from QWizardPage and is used to
+ initialize some of the page's fields with values from the
+ previous page (namely, \c className and \c baseClass). For
+ example, if the class name on page 2 is \c SuperDuperWidget, the
+ default macro name on page 3 is \c SUPERDUPERWIDGET_H.
+
+ The \c OutputFilesPage and \c ConclusionPage classes are very
+ similar to \c CodeStylePage, so we won't review them here.
+
+ \sa QWizard, {License Wizard Example}, {Trivial Wizard Example}
+*/
diff --git a/examples/widgets/doc/codeeditor.qdoc b/examples/widgets/doc/codeeditor.qdoc
new file mode 100644
index 0000000000..695ac5c4ce
--- /dev/null
+++ b/examples/widgets/doc/codeeditor.qdoc
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/codeeditor
+ \title Code Editor Example
+
+ The Code Editor example shows how to create a simple editor that
+ has line numbers and that highlights the current line.
+
+ \image codeeditor-example.png
+
+ As can be seen from the image, the editor displays the line
+ numbers in an area to the left of the area for editing. The editor
+ will highlight the line containing the cursor.
+
+ We implement the editor in \c CodeEditor, which is a widget that
+ inherits QPlainTextEdit. We keep a separate widget in \c
+ CodeEditor (\c LineNumberArea) onto which we draw the line
+ numbers.
+
+ QPlainTextEdit inherits from QAbstractScrollArea, and editing
+ takes place within its \l{QAbstractScrollArea::}{viewport()}'s
+ margins. We make room for our line number area by setting the left
+ margin of the viewport to the size we need to draw the line
+ numbers.
+
+ When it comes to editing code, we prefer QPlainTextEdit over
+ QTextEdit because it is optimized for handling plain text. See
+ the QPlainTextEdit class description for details.
+
+ QPlainTextEdit lets us add selections in addition to the
+ selection the user can make with the mouse or keyboard. We use
+ this functionality to highlight the current line. More on this
+ later.
+
+ We will now move on to the definitions and implementations of \c
+ CodeEditor and \c LineNumberArea. Let's start with the \c
+ LineNumberArea class.
+
+ \section1 The LineNumberArea Class
+
+ We paint the line numbers on this widget, and place it over the \c
+ CodeEditor's \l{QAbstractScrollArea::}{viewport()}'s left margin
+ area.
+
+ We need to use protected functions in QPlainTextEdit while
+ painting the area. So to keep things simple, we paint the area in
+ the \c CodeEditor class. The area also asks the editor to
+ calculate its size hint.
+
+ Note that we could simply paint the line numbers directly on the
+ code editor, and drop the LineNumberArea class. However, the
+ QWidget class helps us to \l{QWidget::}{scroll()} its contents.
+ Also, having a separate widget is the right choice if we wish to
+ extend the editor with breakpoints or other code editor features.
+ The widget would then help in the handling of mouse events.
+
+ \snippet widgets/codeeditor/codeeditor.h extraarea
+
+ \section1 CodeEditor Class Definition
+
+ Here is the code editor's class definition:
+
+ \snippet widgets/codeeditor/codeeditor.h codeeditordefinition
+
+ In the editor we resize and draw the line numbers on the \c
+ LineNumberArea. We need to do this when the number of lines in the
+ editor changes, and when the editor's viewport() is scrolled. Of
+ course, it is also done when the editor's size changes. We do
+ this in \c updateLineNumberWidth() and \c updateLineNumberArea().
+
+ Whenever, the cursor's position changes, we highlight the current
+ line in \c highlightCurrentLine().
+
+ \section1 CodeEditor Class Implementation
+
+ We will now go through the code editors implementation, starting
+ off with the constructor.
+
+ \snippet widgets/codeeditor/codeeditor.cpp constructor
+
+ In the constructor we connect our slots to signals in
+ QPlainTextEdit. It is necessary to calculate the line number area
+ width and highlight the first line when the editor is created.
+
+ \snippet widgets/codeeditor/codeeditor.cpp extraAreaWidth
+
+ The \c lineNumberAreaWidth() function calculates the width of the
+ \c LineNumberArea widget. We take the number of digits in the last
+ line of the editor and multiply that with the maximum width of a
+ digit.
+
+ \snippet widgets/codeeditor/codeeditor.cpp slotUpdateExtraAreaWidth
+
+ When we update the width of the line number area, we simply call
+ QAbstractScrollArea::setViewportMargins().
+
+ \snippet widgets/codeeditor/codeeditor.cpp slotUpdateRequest
+
+ This slot is invoked when the editors viewport has been scrolled.
+ The QRect given as argument is the part of the editing area that
+ is do be updated (redrawn). \c dy holds the number of pixels the
+ view has been scrolled vertically.
+
+ \snippet widgets/codeeditor/codeeditor.cpp resizeEvent
+
+ When the size of the editor changes, we also need to resize the
+ line number area.
+
+ \snippet widgets/codeeditor/codeeditor.cpp cursorPositionChanged
+
+ When the cursor position changes, we highlight the current line,
+ i.e., the line containing the cursor.
+
+ QPlainTextEdit gives the possibility to have more than one
+ selection at the same time. we can set the character format
+ (QTextCharFormat) of these selections. We clear the cursors
+ selection before setting the new new
+ QPlainTextEdit::ExtraSelection, else several lines would get
+ highlighted when the user selects multiple lines with the mouse.
+ \omit ask someone how this works \endomit
+
+ One sets the selection with a text cursor. When using the
+ FullWidthSelection property, the current cursor text block (line)
+ will be selected. If you want to select just a portion of the text
+ block, the cursor should be moved with QTextCursor::movePosition()
+ from a position set with \l{QTextCursor::}{setPosition()}.
+
+ \snippet widgets/codeeditor/codeeditor.cpp extraAreaPaintEvent_0
+
+ The \c lineNumberAreaPaintEvent() is called from \c LineNumberArea
+ whenever it receives a paint event. We start off by painting the
+ widget's background.
+
+ \snippet widgets/codeeditor/codeeditor.cpp extraAreaPaintEvent_1
+
+ We will now loop through all visible lines and paint the line
+ numbers in the extra area for each line. Notice that in a plain
+ text edit each line will consist of one QTextBlock; though, if
+ line wrapping is enabled, a line may span several rows in the text
+ edit's viewport.
+
+ We get the top and bottom y-coordinate of the first text block,
+ and adjust these values by the height of the current text block in
+ each iteration in the loop.
+
+ \snippet widgets/codeeditor/codeeditor.cpp extraAreaPaintEvent_2
+
+ Notice that we check if the block is visible in addition to check
+ if it is in the areas viewport - a block can, for example, be
+ hidden by a window placed over the text edit.
+
+ \section1 Suggestions for Extending the Code Editor
+
+ No self-respecting code editor is without a syntax
+ highligther; the \l{Syntax Highlighter Example} shows how to
+ create one.
+
+ In addition to line numbers, you can add more to the extra area,
+ for instance, break points.
+
+ QSyntaxHighlighter gives the possibility to add user data to each
+ text block with
+ \l{QSyntaxHighlighter::}{setCurrentBlockUserData()}. This can be
+ used to implement parenthesis matching. In the \c
+ highlightCurrentLine(), the data of the currentBlock() can be
+ fetched with QTextBlock::userData(). Matching parentheses can be
+ highlighted with an extra selection. The "Matching Parentheses
+ with QSyntaxHighlighter" article in Qt Quarterly 31 implements
+ this. You find it here: \l{http://doc.qt.nokia.com/qq/}.
+
+*/
diff --git a/examples/widgets/doc/coloreditorfactory.qdoc b/examples/widgets/doc/coloreditorfactory.qdoc
new file mode 100644
index 0000000000..a2c02f8c1d
--- /dev/null
+++ b/examples/widgets/doc/coloreditorfactory.qdoc
@@ -0,0 +1,155 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/coloreditorfactory
+ \title Color Editor Factory Example
+
+ This example shows how to create an editor that can be used by
+ a QItemDelegate.
+
+ \image coloreditorfactoryimage.png
+
+ When editing data in a QListView, QTableView, or QTreeView,
+ editors are created and displayed by a \l{Delegate
+ Classes}{delegate}. QItemDelegate, which is the default delegate
+ used by Qt's \l{View Classes}{item views}, uses a
+ QItemEditorFactory to create editors for it. A unique instance
+ provided by QItemEditorFactory is by default installed on all
+ item delegates.
+
+ An item editor factory contains a collection of
+ QItemEditorCreatorBase instances, which are specialized factories
+ that produce editors for one particular QVariant data type (all
+ models in Qt store their data in \l{QVariant}s). An editor can be any
+ Qt or custom widget.
+
+ In this example, we will create an editor (implemented in the \c
+ ColorListEditor class) that can edit the QColor data type and be
+ used by \l{QItemDelegate}s. We do this by creating a new
+ QItemEditorCreatorBase that produces \c ColorListEditors and
+ register it with a new factory, which we set as the default editor
+ item factory (the unique factory instance). To test our editor, we
+ have implemented the \c Window class, which displays a
+ QTableWidget in which \l{QColor}s can be edited.
+
+ \section1 Window Class Implementation
+
+ In the Window class, we create the item editor creator
+ base for our color editor and add it to the default factory.
+ We also create a QTableWidget in which our editor can be
+ tested. It is filled with some data and displayed in a window.
+
+ We take a closer look at the constructor:
+
+ \snippet itemviews/coloreditorfactory/window.cpp 0
+
+ The QStandardItemEditorCreator is a convenience class that
+ inherits QItemEditorCreatorBase. Its constructor takes a template
+ class, of which instances are returned from
+ \l{QItemEditorCreatorBase::}{createWidget()}. The creator uses a
+ constructor that takes a QWidget as its only parameter; the
+ template class must provide this. This way, there is no need to
+ subclass QStandardItemEditorCreator.
+
+ After the new factory has been set, all standard item delegates
+ will use it (i.e, also delegates that were created before the new
+ default factory was set).
+
+ The \c createGUI() function sets up the table and fills it
+ with data.
+
+ \section1 ColorListEditor Definition
+
+ The ColorListEditor inherits QComboBox and lets the user
+ select a QColor from its popup list.
+
+ \snippet itemviews/coloreditorfactory/colorlisteditor.h 0
+
+ QItemDelegate manages the interaction between the editor and
+ the model, i.e., it retrieves data to edit from the model and
+ store data from the editor in the model. The data that is edited
+ by an editor is stored in the editor's user data property, and the
+ delegate uses Qt's \l{Qt's Property System}{property system} to
+ access it by name. We declare our user data property with the
+ Q_PROPERTY macro. The property is set to be the user type with the
+ USER keyword.
+
+ \section1 ColorListEditor Implementation
+
+ The constructor of \c ColorListEditor simply calls \c
+ populateList(), which we will look at later. We move on to the
+ \c color() function:
+
+ \snippet itemviews/coloreditorfactory/colorlisteditor.cpp 0
+
+ We return the data that is selected in the combobox. The data
+ is stored in the Qt::DecorationRole as the color is then also
+ displayed in the popup list (as shown in the image above).
+
+ \snippet itemviews/coloreditorfactory/colorlisteditor.cpp 1
+
+ The \c findData() function searches the items in the combobox
+ and returns the index of the item that has \c color in the
+ Qt::Decoration role.
+
+ \snippet itemviews/coloreditorfactory/colorlisteditor.cpp 2
+
+ Qt knows some predefined colors by name. We simply loop
+ through these to fill our editor with items.
+
+ \section1 Further Customization of Item View Editors
+
+ You can customize Qt's \l{Model/View Programming}{model view
+ framework} in many ways. The procedure shown in this example is
+ usually sufficient to provide custom editors. Further
+ customization is achieved by subclassing QItemEditorFactory
+ and QItemEditorCreatorBase. It is also possible to subclass
+ QItemDelegate if you don't wish to use a factory at all.
+
+ Possible suggestions are:
+
+ \list
+ \li If the editor widget has no user property defined, the delegate
+ asks the factory for the property name, which it in turn
+ asks the item editor creator for. In this case, you can use
+ the QItemEditorCreator class, which takes the property
+ name to use for editing as a constructor argument.
+ \li If the editor requires other constructors or other
+ initialization than provided by QItemEditorCreatorBase, you
+ must reimplement
+ QItemEditorCreatorBase::createWidget().
+ \li You could also subclass QItemEditorFactory if you only want
+ to provide editors for certain kinds of data or use another
+ method of creating the editors than using creator bases.
+ \endlist
+
+ In this example, we use a standard QVariant data type. You can
+ also use custom types. In the \l{Star Delegate Example}, we
+ show how to store a custom data type in a QVariant and paint
+ and edit it in a class that inherits QItemDelegate.
+*/
diff --git a/examples/widgets/doc/combowidgetmapper.qdoc b/examples/widgets/doc/combowidgetmapper.qdoc
new file mode 100644
index 0000000000..949014930d
--- /dev/null
+++ b/examples/widgets/doc/combowidgetmapper.qdoc
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/combowidgetmapper
+ \title Combo Widget Mapper Example
+
+ The Combo Widget Mapper example shows how to use a custom delegate to
+ map information from a model to specific widgets on a form.
+
+ \image combowidgetmapper-example.png
+
+ In the \l{Simple Widget Mapper Example}, we showed the basic use of a
+ widget mapper to relate data exposed by a model to simple input widgets
+ in a user interface. However, sometimes we want to use input widgets that
+ expose data as choices to the user, such as QComboBox, and we need a way
+ to relate their input to the values stored in the model.
+
+ This example is very similar to the \l{Simple Widget Mapper Example}.
+ Again, we create a \c Window class with an almost identical user interface,
+ except that, instead of providing a spin box so that each person's age
+ can be entered, we provide a combo box to allow their addresses to be
+ classified as "Home", "Work" or "Other".
+
+ \section1 Window Class Definition
+
+ The class provides a constructor, a slot to keep the buttons up to date,
+ and a private function to set up the model:
+
+ \snippet itemviews/combowidgetmapper/window.h Window definition
+
+ In addition to the QDataWidgetMapper object and the controls used to make
+ up the user interface, we use a QStandardItemModel to hold our data and
+ a QStringListModel to hold information about the types of address that
+ can be applied to each person's data.
+
+ \section1 Window Class Implementation
+
+ The constructor of the \c Window class can be explained in three parts.
+ In the first part, we set up the widgets used for the user interface:
+
+ \snippet itemviews/combowidgetmapper/window.cpp Set up widgets
+
+ Note that we set up the mapping the combo box in the same way as for other
+ widgets, but that we apply its own model to it so that it will display
+ data from its own model, the \c typeModel, rather than from the model
+ containing data about each person.
+
+ Next, we set up the widget mapper, relating each input widget to a column
+ in the model specified by the call to \l{QDataWidgetMapper::}{setModel()}:
+
+ \snippet itemviews/combowidgetmapper/window.cpp Set up the mapper
+
+ For the combo box, we pass an extra argument to tell the widget mapper
+ which property to relate to values from the model. As a result, the user
+ is able to select an item from the combo box, and the corresponding
+ value stored in the widget's \c currentIndex property will be stored in
+ the model.
+
+ \omit
+ However, we also set a delegate on the mapper. As with \l{Delegate Classes},
+ this changes the way that data is presented to the user. In this case, the
+ delegate acts as a proxy between the mapper and the input widgets,
+ translating the data into a suitable form for the combo box but not
+ interfering with the other input widgets. The implementation is shown later.
+ \endomit
+
+ The rest of the constructor is very similar to that of the
+ \l{Simple Widget Mapper Example}:
+
+ \snippet itemviews/combowidgetmapper/window.cpp Set up connections and layouts
+
+ The model is initialized in the window's \c{setupModel()} function. Here,
+ we create a standard model with 5 rows and 3 columns. In each row, we
+ insert a name, address, and a value that indicates the type of address.
+ The address types are stored in a string list model.
+
+ \snippet itemviews/combowidgetmapper/window.cpp Set up the model
+
+ As we insert each row into the model, like a record in a database, we
+ store values that correspond to items in \c typeModel for each person's
+ address type. When the widget mapper reads these values from the final
+ column of each row, it will need to use them as references to values in
+ \c typeModel, as shown in the following diagram. This is where the
+ delegate is used.
+
+ \image widgetmapper-combo-mapping.png
+
+ We show the implementation of the \c{updateButtons()} slot for
+ completeness:
+
+ \snippet itemviews/combowidgetmapper/window.cpp Slot for updating the buttons
+
+ \omit
+ \section1 Delegate Class Definition and Implementation
+
+ The delegate we use to mediate interaction between the widget mapper and
+ the input widgets is a small QItemDelegate subclass:
+
+ \snippet itemviews/combowidgetmapper/delegate.h Delegate class definition
+
+ This provides implementations of the two standard functions used to pass
+ data between editor widgets and the model (see the \l{Delegate Classes}
+ documentation for a more general description of these functions).
+
+ Since we only provide an empty implementation of the constructor, we
+ concentrate on the other two functions.
+
+ The \l{QItemDelegate::}{setEditorData()} implementation takes the data
+ referred to by the model index supplied and processes it according to
+ the presence of a \c currentIndex property in the editor widget:
+
+ \snippet itemviews/combowidgetmapper/delegate.cpp setEditorData implementation
+
+ If, like QComboBox, the editor widget has this property, it is set using
+ the value from the model. Since we are passing around QVariant values,
+ the strings stored in the model are automatically converted to the integer
+ values needed for the \c currentIndex property.
+
+ As a result, instead of showing "0", "1" or "2" in the combo box, one of
+ its predefined set of items is shown. We call QItemDelegate::setEditorData()
+ for widgets without the \c currentIndex property.
+
+ The \l{QItemDelegate::}{setModelData()} implementation performs the reverse
+ process, taking the value stored in the widget's \c currentIndex property
+ and storing it back in the model:
+
+ \snippet itemviews/combowidgetmapper/delegate.cpp setModelData implementation
+ \endomit
+
+ \section1 Summary and Further Reading
+
+ The use of a separate model for the combo box provides a menu of choices
+ that are separate from the data stored in the main model. Using a named
+ mapping that relates the combo box's \c currentIndex property to a column
+ in the model effectively allows us to store a look-up value in the model.
+
+ However, when reading the model outside the context of the widget mapper,
+ we need to know about the \c typeModel to make sense of these look-up
+ values. It would be useful to be able to store both the data and the
+ choices held by the \c typeModel in one place.
+ This is covered by the \l{SQL Widget Mapper Example}.
+*/
diff --git a/examples/widgets/doc/composition.qdoc b/examples/widgets/doc/composition.qdoc
new file mode 100644
index 0000000000..6aca01d255
--- /dev/null
+++ b/examples/widgets/doc/composition.qdoc
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example painting/composition
+ \title Composition Modes
+
+ This demo shows some of the more advanced composition modes supported by Qt.
+
+ \image composition-demo.png
+
+ The two most common forms of composition are \b{Source} and \b{SourceOver}.
+ \b{Source} is used to draw opaque objects onto a paint device. In this mode,
+ each pixel in the source replaces the corresponding pixel in the destination.
+ In \b{SourceOver} composition mode, the source object is transparent and is
+ drawn on top of the destination.
+
+ In addition to these standard modes, Qt defines the complete set of composition modes
+ as defined by X. Porter and Y. Duff. See the QPainter documentation for details.
+*/
diff --git a/examples/widgets/doc/concentriccircles.qdoc b/examples/widgets/doc/concentriccircles.qdoc
new file mode 100644
index 0000000000..67bc125dbe
--- /dev/null
+++ b/examples/widgets/doc/concentriccircles.qdoc
@@ -0,0 +1,231 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example painting/concentriccircles
+ \title Concentric Circles Example
+
+ The Concentric Circles example shows the improved rendering
+ quality that can be obtained using floating point precision and
+ anti-aliasing when drawing custom widgets. The example also shows
+ how to do simple animations.
+
+ The application's main window displays several widgets which are
+ drawn using the various combinations of precision and
+ anti-aliasing.
+
+ \image concentriccircles-example.png
+
+ Anti-aliasing is one of QPainter's render hints. The
+ QPainter::RenderHints are used to specify flags to QPainter that
+ may, or may not, be respected by any given
+ engine. QPainter::Antialiasing indicates that the engine should
+ anti-alias the edges of primitives if possible, i.e. put
+ additional pixels around the original ones to smooth the edges.
+
+ The difference between floating point precision and integer
+ precision is a matter of accuracy, and is visible in the
+ application's main window: Even though the logic that is
+ calculating the circles' geometry is the same, floating points
+ ensure that the white spaces between each circle are of the same
+ size, while integers make two and two circles appear as if they
+ belong together. The reason is that the integer based precision
+ rely on rounding off non-integer calculations.
+
+ The example consists of two classes:
+
+ \list
+ \li \c CircleWidget is a custom widget which renders several animated
+ concentric circles.
+ \li \c Window is the application's main window displaying four \c
+ {CircleWidget}s drawn using different combinations of precision
+ and aliasing.
+ \endlist
+
+ First we will review the CircleWidget class, then we will take a
+ look at the Window class.
+
+ \section1 CircleWidget Class Definition
+
+ The CircleWidget class inherits QWidget, and is a custom widget
+ which renders several animated concentric circles.
+
+ \snippet painting/concentriccircles/circlewidget.h 0
+
+ We declare the \c floatBased and \c antialiased variables to hold
+ whether an instance of the class should be rendered with integer
+ or float based precision, and whether the rendering should be
+ anti-aliased or not. We also declare functions setting each of
+ these variables.
+
+ In addition we reimplement the QWidget::paintEvent() function to
+ apply the various combinations of precision and anti-aliasing when
+ rendering, and to support the animation. We reimplement the
+ QWidget::minimumSizeHint() and QWidget::sizeHint() functions to
+ give the widget a reasonable size within our application.
+
+ We declare the private \c nextAnimationFrame() slot, and the
+ associated \c frameNo variable holding the number of "animation
+ frames" for the widget, to facilitate the animation.
+
+ \section1 CircleWidget Class Implementation
+
+ In the constructor we make the widget's rendering integer based
+ and aliased by default:
+
+ \snippet painting/concentriccircles/circlewidget.cpp 0
+
+ We initialize the widget's \c frameNo variable, and set the
+ widget's background color using the QWidget::setBackgroundColor()
+ function which takes a \l {QPalette::ColorRole}{color role} as
+ argument; the QPalette::Base color role is typically white.
+
+ Then we set the widgets size policy using the
+ QWidget::setSizePolicy() function. QSizePolicy::Expanding means
+ that the widget's \l {QWidget::sizeHint()}{sizeHint()} is a
+ sensible size, but that the widget can be shrunk and still be
+ useful. The widget can also make use of extra space, so it should
+ get as much space as possible.
+
+ \snippet painting/concentriccircles/circlewidget.cpp 1
+ \codeline
+ \snippet painting/concentriccircles/circlewidget.cpp 2
+
+ The public \c setFloatBased() and \c setAntialiased() functions
+ update the widget's rendering preferences, i.e. whether the widget
+ should be rendered with integer or float based precision, and
+ whether the rendering should be anti-aliased or not.
+
+ The functions also generate a paint event by calling the
+ QWidget::update() function, forcing a repaint of the widget with
+ the new rendering preferences.
+
+ \snippet painting/concentriccircles/circlewidget.cpp 3
+ \codeline
+ \snippet painting/concentriccircles/circlewidget.cpp 4
+
+ The default implementations of the QWidget::minimumSizeHint() and
+ QWidget::sizeHint() functions return invalid sizes if there is no
+ layout for the widget, otherwise they return the layout's minimum and
+ preferred size, respectively.
+
+ We reimplement the functions to give the widget minimum and
+ preferred sizes which are reasonable within our application.
+
+ \snippet painting/concentriccircles/circlewidget.cpp 5
+
+ The nextAnimationFrame() slot simply increments the \c frameNo
+ variable's value, and calls the QWidget::update() function which
+ schedules a paint event for processing when Qt returns to the main
+ event loop.
+
+ \snippet painting/concentriccircles/circlewidget.cpp 6
+
+ A paint event is a request to repaint all or part of the
+ widget. The \c paintEvent() function is an event handler that can
+ be reimplemented to receive the widget's paint events. We
+ reimplement the event handler to apply the various combinations of
+ precision and anti-aliasing when rendering the widget, and to
+ support the animation.
+
+ First, we create a QPainter for the widget, and set its
+ antialiased flag to the widget's preferred aliasing. We also
+ translate the painters coordinate system, preparing to draw the
+ widget's cocentric circles. The translation ensures that the
+ center of the circles will be equivalent to the widget's center.
+
+ \snippet painting/concentriccircles/circlewidget.cpp 7
+
+ When painting a circle, we use the number of "animation frames" to
+ determine the alpha channel of the circle's color. The alpha
+ channel specifies the color's transparency effect, 0 represents a
+ fully transparent color, while 255 represents a fully opaque
+ color.
+
+ \snippet painting/concentriccircles/circlewidget.cpp 8
+
+ If the calculated alpha channel is fully transparent, we don't
+ draw anything since that would be equivalent to drawing a white
+ circle on a white background. Instead we skip to the next circle
+ still creating a white space. If the calculated alpha channel is
+ fully opaque, we set the pen (the QColor passed to the QPen
+ constructor is converted into the required QBrush by default) and
+ draw the circle. If the widget's preferred precision is float
+ based, we specify the circle's bounding rectangle using QRectF and
+ double values, otherwise we use QRect and integers.
+
+ The animation is controlled by the public \c nextAnimationFrame()
+ slot: Whenever the \c nextAnimationFrame() slot is called the
+ number of frames is incremented and a paint event is
+ scheduled. Then, when the widget is repainted, the alpha-blending
+ of the circles' colors change and the circles appear as animated.
+
+ \section1 Window Class Definition
+
+ The Window class inherits QWidget, and is the application's main
+ window rendering four \c {CircleWidget}s using different
+ combinations of precision and aliasing.
+
+ \snippet painting/concentriccircles/window.h 0
+
+ We declare the various components of the main window, i.e., the text
+ labels and a double array that will hold reference to the four \c
+ {CircleWidget}s. In addition we declare the private \c
+ createLabel() function to simplify the constructor.
+
+ \section1 Window Class Implementation
+
+ \snippet painting/concentriccircles/window.cpp 0
+
+ In the constructor, we first create the various labels and put
+ them in a QGridLayout.
+
+ \snippet painting/concentriccircles/window.cpp 1
+
+ Then we create a QTimer. The QTimer class is a high-level
+ programming interface for timers, and provides repetitive and
+ single-shot timers.
+
+ We create a timer to facilitate the animation of our concentric
+ circles; when we create the four CircleWidget instances (and add
+ them to the layout), we connect the QTimer::timeout() signal to
+ each of the widgets' \c nextAnimationFrame() slots.
+
+ \snippet painting/concentriccircles/window.cpp 2
+
+ Before we set the layout and window title for our main window, we
+ make the timer start with a timeout interval of 100 milliseconds,
+ using the QTimer::start() function. That means that the
+ QTimer::timeout() signal will be emitted, forcing a repaint of the
+ four \c {CircleWidget}s, every 100 millisecond which is the reason
+ the circles appear as animated.
+
+ \snippet painting/concentriccircles/window.cpp 3
+
+ The private \c createLabel() function is implemented to simlify
+ the constructor.
+*/
diff --git a/examples/widgets/doc/configdialog.qdoc b/examples/widgets/doc/configdialog.qdoc
new file mode 100644
index 0000000000..9acea72a3b
--- /dev/null
+++ b/examples/widgets/doc/configdialog.qdoc
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example dialogs/configdialog
+ \title Config Dialog Example
+
+ The Config Dialog examples shows how a configuration dialog can be created by
+ using an icon view with a stacked widget.
+
+ \image configdialog-example.png
+*/
diff --git a/examples/widgets/doc/customsortfiltermodel.qdoc b/examples/widgets/doc/customsortfiltermodel.qdoc
new file mode 100644
index 0000000000..4dce820f9c
--- /dev/null
+++ b/examples/widgets/doc/customsortfiltermodel.qdoc
@@ -0,0 +1,289 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/customsortfiltermodel
+ \title Custom Sort/Filter Model Example
+
+ The Custom Sort/Filter Model example illustrates how to subclass
+ QSortFilterProxyModel to perform advanced sorting and filtering.
+
+ \image customsortfiltermodel-example.png Screenshot of the Custom Sort/Filter Model Example
+
+ The QSortFilterProxyModel class provides support for sorting and
+ filtering data passed between another model and a view.
+
+ The model transforms the structure of a source model by mapping
+ the model indexes it supplies to new indexes, corresponding to
+ different locations, for views to use. This approach allows a
+ given source model to be restructured as far as views are
+ concerned, without requiring any transformations on the underlying
+ data and without duplicating the data in memory.
+
+ The Custom Sort/Filter Model example consists of two classes:
+
+ \list
+
+ \li The \c MySortFilterProxyModel class provides a custom proxy
+ model.
+
+ \li The \c Window class provides the main application window,
+ using the custom proxy model to sort and filter a standard
+ item model.
+
+ \endlist
+
+ We will first take a look at the \c MySortFilterProxyModel class
+ to see how the custom proxy model is implemented, then we will
+ take a look at the \c Window class to see how the model is
+ used. Finally we will take a quick look at the \c main() function.
+
+ \section1 MySortFilterProxyModel Class Definition
+
+ The \c MySortFilterProxyModel class inherits the
+ QSortFilterProxyModel class.
+
+ Since QAbstractProxyModel and its subclasses are derived from
+ QAbstractItemModel, much of the same advice about subclassing
+ normal models also applies to proxy models.
+
+ On the other hand, it is worth noting that many of
+ QSortFilterProxyModel's default implementations of functions are
+ written so that they call the equivalent functions in the relevant
+ source model. This simple proxying mechanism may need to be
+ overridden for source models with more complex behavior; in this
+ example we derive from the QSortFilterProxyModel class to ensure
+ that our filter can recognize a valid range of dates, and to
+ control the sorting behavior.
+
+ \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.h 0
+
+ We want to be able to filter our data by specifying a given period
+ of time. For that reason, we implement the custom \c
+ setFilterMinimumDate() and \c setFilterMaximumDate() functions as
+ well as the corresponding \c filterMinimumDate() and \c
+ filterMaximumDate() functions. We reimplement
+ QSortFilterProxyModel's \l
+ {QSortFilterProxyModel::filterAcceptsRow()}{filterAcceptsRow()}
+ function to only accept rows with valid dates, and
+ QSortFilterProxyModel::lessThan() to be able to sort the senders
+ by their email addresses. Finally, we implement a \c dateInRange()
+ convenience function that we will use to determine if a date is
+ valid.
+
+ \section1 MySortFilterProxyModel Class Implementation
+
+ The \c MySortFilterProxyModel constructor is trivial, passing the
+ parent parameter on to the base class constructor:
+
+ \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 0
+
+ The most interesting parts of the \c MySortFilterProxyModel
+ implementation are the reimplementations of
+ QSortFilterProxyModel's \l
+ {QSortFilterProxyModel::filterAcceptsRow()}{filterAcceptsRow()}
+ and \l {QSortFilterProxyModel::lessThan()}{lessThan()}
+ functions. Let's first take a look at our customized \c lessThan()
+ function.
+
+ \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 4
+
+ We want to sort the senders by their email addresses. The \l
+ {QSortFilterProxyModel::}{lessThan()} function is used as the <
+ operator when sorting. The default implementation handles a
+ collection of types including QDateTime and String, but in order
+ to be able to sort the senders by their email addresses we must
+ first identify the address within the given string:
+
+ \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 6
+
+ We use QRegExp to define a pattern for the addresses we are looking
+ for. The QRegExp::indexIn() function attempts to find a match in
+ the given string and returns the position of the first match, or
+ -1 if there was no match. If the given string contains the
+ pattern, we use QRegExp's \l {QRegExp::cap()}{cap()} function to
+ retrieve the actual address. The \l {QRegExp::cap()}{cap()}
+ function returns the text captured by the \e nth
+ subexpression. The entire match has index 0 and the parenthesized
+ subexpressions have indexes starting from 1 (excluding
+ non-capturing parentheses).
+
+ \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 3
+
+ The \l
+ {QSortFilterProxyModel::filterAcceptsRow()}{filterAcceptsRow()}
+ function, on the other hand, is expected to return true if the
+ given row should be included in the model. In our example, a row
+ is accepted if either the subject or the sender contains the given
+ regular expression, and the date is valid.
+
+ \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 7
+
+ We use our custom \c dateInRange() function to determine if a date
+ is valid.
+
+ To be able to filter our data by specifying a given period of
+ time, we also implement functions for getting and setting the
+ minimum and maximum dates:
+
+ \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 1
+ \codeline
+ \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 2
+
+ The get functions, \c filterMinimumDate() and \c
+ filterMaximumDate(), are trivial and implemented as inline
+ function in the header file.
+
+ This completes our custom proxy model. Let's see how we can use it
+ in an application.
+
+ \section1 Window Class Definition
+
+ The \c CustomFilter class inherits QWidget, and provides this
+ example's main application window:
+
+ \snippet itemviews/customsortfiltermodel/window.h 0
+
+ We implement two private slots, \c textFilterChanged() and \c
+ dateFilterChanged(), to respond to the user changing the filter
+ pattern, case sensitivity or any of the dates. In addition, we
+ implement a public \c setSourceModel() convenience function to set
+ up the model/ view relation.
+
+ \section1 Window Class Implementation
+
+ In this example, we have chosen to create and set the source model
+ in the \c main () function (which we will come back to later). So
+ when constructing the main application window, we assume that a
+ source model already exists and start by creating an instance of
+ our custom proxy model:
+
+ \snippet itemviews/customsortfiltermodel/window.cpp 0
+
+ We set the \l
+ {QSortFilterProxyModel::dynamicSortFilter}{dynamicSortFilter}
+ property that holds whether the proxy model is dynamically sorted
+ and filtered. By setting this property to true, we ensure that the
+ model is sorted and filtered whenever the contents of the source
+ model change.
+
+ The main application window shows views of both the source model
+ and the proxy model. The source view is quite simple:
+
+ \snippet itemviews/customsortfiltermodel/window.cpp 1
+
+ The QTreeView class provides a default model/view implementation
+ of a tree view; our view implements a tree representation of items
+ in the application's source model.
+
+ \snippet itemviews/customsortfiltermodel/window.cpp 2
+
+ The QTreeView class provides a default model/view implementation
+ of a tree view; our view implements a tree representation of items
+ in the application's source model. We add our view widget to a
+ layout that we install on a corresponding group box.
+
+ The proxy model view, on the other hand, contains several widgets
+ controlling the various aspects of transforming the source model's
+ data structure:
+
+ \snippet itemviews/customsortfiltermodel/window.cpp 3
+ \snippet itemviews/customsortfiltermodel/window.cpp 4
+
+ Note that whenever the user changes one of the filtering options,
+ we must explicitly reapply the filter. This is done by connecting
+ the various editors to functions that update the proxy model.
+
+ \snippet itemviews/customsortfiltermodel/window.cpp 5
+
+ The sorting will be handled by the view. All we have to do is to
+ enable sorting for our proxy view by setting the
+ QTreeView::sortingEnabled property (which is false by
+ default). Then we add all the filtering widgets and the proxy view
+ to a layout that we install on a corresponding group box.
+
+ \snippet itemviews/customsortfiltermodel/window.cpp 6
+
+ Finally, after putting our two group boxes into another layout
+ that we install on our main application widget, we customize the
+ application window.
+
+ As mentioned above, we create the source model in the \c main ()
+ function, calling the \c Window::setSourceModel() function to make
+ the application use it:
+
+ \snippet itemviews/customsortfiltermodel/window.cpp 7
+
+ The QSortFilterProxyModel::setSourceModel() function makes the
+ proxy model process the data in the given model, in this case out
+ mail model. The \l {QAbstractItemView::}{setModel()} that the
+ view widget inherits from the QAbstractItemModel class, sets the
+ model for the view to present. Note that the latter function will
+ also create and set a new selection model.
+
+ \snippet itemviews/customsortfiltermodel/window.cpp 8
+
+ The \c textFilterChanged() function is called whenever the user
+ changes the filter pattern or the case sensitivity.
+
+ We first retrieve the preferred syntax (the QRegExp::PatternSyntax
+ enum is used to interpret the meaning of the given pattern), then
+ we determine the preferred case sensitivity. Based on these
+ preferences and the current filter pattern, we set the proxy
+ model's \l {QSortFilterProxyModel::}{filterRegExp} property. The
+ \l {QSortFilterProxyModel::}{filterRegExp} property holds the
+ regular expression used to filter the contents of the source
+ model. Note that calling QSortFilterProxyModel's \l
+ {QSortFilterProxyModel::}{setFilterRegExp()} function also updates
+ the model.
+
+ \snippet itemviews/customsortfiltermodel/window.cpp 9
+
+ The \c dateFilterChanged() function is called whenever the user
+ modifies the range of valid dates. We retrieve the new dates from
+ the user interface, and call the corresponding functions (provided
+ by our custom proxy model) to set the proxy model's minimum and
+ maximum dates. As we explained above, calling these functions also
+ updates the model.
+
+ \section1 The Main() Function
+
+ In this example, we have separated the application from the source
+ model by creating the model in the \c main () function. First we
+ create the application, then we create the source model:
+
+ \snippet itemviews/customsortfiltermodel/main.cpp 0
+
+ The \c createMailModel() function is a convenience function
+ provided to simplify the constructor. All it does is to create and
+ return a model describing a collection of emails. The model is an
+ instance of the QStandardItemModel class, i.e., a generic model
+ for storing custom data typically used as a repository for
+ standard Qt data types. Each mail description is added to the
+ model using \c addMail(), another convenience function. See \l
+ {itemviews/customsortfiltermodel/main.cpp}{main.cpp} for details.
+*/
diff --git a/examples/widgets/doc/deform.qdoc b/examples/widgets/doc/deform.qdoc
new file mode 100644
index 0000000000..8195f90ffa
--- /dev/null
+++ b/examples/widgets/doc/deform.qdoc
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example painting/deform
+ \title Vector Deformation
+
+ This example shows how to use advanced vector techniques to draw text
+ using a \c QPainterPath.
+
+ \image deform-demo.png
+
+ We define a vector deformation field in the shape of a lens and apply
+ this to all points in a path. This means that what is rendered on
+ screen is not pixel manipulation, but modified vector representations of
+ the glyphs themselves. This is visible from the high quality of the
+ antialiased edges for the deformed glyphs.
+
+ To get a fairly complex path we allow the user to type in text and
+ convert the text to paths. This is done using the
+ QPainterPath::addText() function.
+
+ The lens is drawn using a single call to QPainter::drawEllipse(),
+ using a QRadialGradient to fill it with a specialized color
+ table, giving the effect of the sun's reflection and a drop
+ shadow. The lens is cached as a pixmap for better performance.
+*/
diff --git a/examples/widgets/doc/diagramscene.qdoc b/examples/widgets/doc/diagramscene.qdoc
new file mode 100644
index 0000000000..b61a936d52
--- /dev/null
+++ b/examples/widgets/doc/diagramscene.qdoc
@@ -0,0 +1,834 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example graphicsview/diagramscene
+ \title Diagram Scene Example
+
+ This example shows use of Qt's graphics framework.
+
+ \image diagramscene.png
+
+ The Diagram Scene example is an application in which you can
+ create a flowchart diagram. It is possible to add flowchart shapes
+ and text and connect the shapes by arrows as shown in the image
+ above. The shapes, arrows, and text can be given different
+ colors, and it is possible to change the font, style, and
+ underline of the text.
+
+ The Qt graphics view framework is designed to manage and display
+ custom 2D graphics items. The main classes of the framework are
+ QGraphicsItem, QGraphicsScene and QGraphicsView. The graphics
+ scene manages the items and provides a surface for them.
+ QGraphicsView is a widget that is used to render a scene on the
+ screen. See the \l{Graphics View Framework} for a more detailed
+ description of the framework.
+
+ In this example we show how to create such custom graphics
+ scenes and items by implementing classes that inherit
+ QGraphicsScene and QGraphicsItem.
+
+ In particular we show how to:
+
+ \list
+ \li Create custom graphics items.
+ \li Handle mouse events and movement of items.
+ \li Implement a graphics scene that can manage our custom items.
+ \li Custom painting of items.
+ \li Create a movable and editable text item.
+ \endlist
+
+ The example consists of the following classes:
+ \list
+ \li \c MainWindow creates the widgets and display
+ them in a QMainWindow. It also manages the interaction
+ between the widgets and the graphics scene, view and
+ items.
+ \li \c DiagramItem inherits QGraphicsPolygonItem and
+ represents a flowchart shape.
+ \li \c TextDiagramItem inherits QGraphicsTextItem and
+ represents text items in the diagram. The class adds
+ support for moving the item with the mouse, which is not
+ supported by QGraphicsTextItem.
+ \li \c Arrow inherits QGraphicsLineItem and is an arrow
+ that connect two DiagramItems.
+ \li \c DiagramScene inherits QGraphicsDiagramScene and
+ provides support for \c DiagramItem, \c Arrow and
+ \c DiagramTextItem (In addition to the support already
+ handled by QGraphicsScene).
+ \endlist
+
+ \section1 MainWindow Class Definition
+
+ \snippet graphicsview/diagramscene/mainwindow.h 0
+
+ The \c MainWindow class creates and lays out the widgets in a
+ QMainWindow. The class forwards input from the widgets to the
+ DiagramScene. It also updates its widgets when the diagram
+ scene's text item changes, or a diagram item or a diagram text item
+ is inserted into the scene.
+
+ The class also deletes items from the scene and handles the
+ z-ordering, which decides the order in which items are drawn when
+ they overlap each other.
+
+ \section1 MainWindow Class Implementation
+
+
+ We start with a look at the constructor:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 0
+
+ In the constructor we call methods to create the widgets and
+ layouts of the example before we create the diagram scene.
+ The toolbars must be created after the scene as they connect
+ to its signals. We then lay the widgets out in the window.
+
+ We connect to the \c itemInserted() and \c textInserted() slots of
+ the diagram scenes as we want to uncheck the buttons in the tool
+ box when an item is inserted. When an item is selected in
+ the scene we receive the \c itemSelected() signal. We use this to
+ update the widgets that display font properties if the item
+ selected is a \c DiagramTextItem.
+
+ The \c createToolBox() function creates and lays out the widgets
+ of the \c toolBox QToolBox. We will not examine it with a
+ high level of detail as it does not deal with graphics framework
+ specific functionality. Here is its implementation:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 21
+
+ This part of the function sets up the tabbed widget item that
+ contains the flowchart shapes. An exclusive QButtonGroup always
+ keeps one button checked; we want the group to allow all buttons
+ to be unchecked.
+ We still use a button group since we can associate user
+ data, which we use to store the diagram type, with each button.
+ The \c createCellWidget() function sets up the buttons in the
+ tabbed widget item and is examined later.
+
+ The buttons of the background tabbed widget item is set up in the
+ same way, so we skip to the creation of the tool box:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 22
+
+ We set the preferred size of the toolbox as its maximum. This
+ way, more space is given to the graphics view.
+
+ Here is the \c createActions() function:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 23
+
+ We show an example of the creation of an action. The
+ functionality the actions trigger is discussed in the slots we
+ connect the actions to. You can see the \l{Application
+ Example}{application example} if you need a high-level
+ introduction to actions.
+
+ The is the \c createMenus() function:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 24
+
+ We create the three menus' of the example.
+
+ The \c createToolbars() function sets up the examples tool
+ bars. The three \l{QToolButton}s in the \c colorToolBar, the \c
+ fontColorToolButton, \c fillColorToolButton, and \c
+ lineColorToolButton, are interesting as we create icons for them
+ by drawing on a QPixmap with a QPainter. We show how the \c
+ fillColorToolButton is created. This button lets the user select a
+ color for the diagram items.
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 25
+ \dots
+ \snippet graphicsview/diagramscene/mainwindow.cpp 26
+
+ We set the menu of the tool button with
+ \l{QToolButton::}{setMenu()}. We need the \c fillAction QAction
+ object to always be pointing to the selected action of the menu.
+ The menu is created with the \c createColorMenu() function and, as
+ we shall see later, contains one menu item for each color that the
+ items can have. When the user presses the button, which trigger
+ the \l{QToolButton::}{clicked()} signal, we can set the color of
+ the selected item to the color of \c fillAction. It is with \c
+ createColorToolButtonIcon() we create the icon for the button.
+
+ \dots
+ \snippet graphicsview/diagramscene/mainwindow.cpp 27
+
+ Here is the \c createBackgroundCellWidget() function:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 28
+
+ This function creates \l{QWidget}s containing a tool button
+ and a label. The widgets created with this function are used for
+ the background tabbed widget item in the tool box.
+
+ Here is the \c createCellWidget() function:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 29
+
+ This function returns a QWidget containing a QToolButton with
+ an image of one of the \c DiagramItems, i.e., flowchart shapes.
+ The image is created by the \c DiagramItem through the \c image()
+ function. The QButtonGroup class lets us attach an id (int) with
+ each button; we store the diagram's type, i.e., the
+ DiagramItem::DiagramType enum. We use the stored diagram type when
+ we create new diagram items for the scene. The widgets created
+ with this function is used in the tool box.
+
+ Here is the \c createColorMenu() function:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 30
+
+ This function creates a color menu that is used as the
+ drop-down menu for the tool buttons in the \c colorToolBar. We
+ create an action for each color that we add to the menu. We fetch
+ the actions data when we set the color of items, lines, and text.
+
+ Here is the \c createColorToolButtonIcon() function:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 31
+
+ This function is used to create the QIcon of the \c
+ fillColorToolButton, \c fontColorToolButton, and \c
+ lineColorToolButton. The \a imageFile string is either the text,
+ flood-fill, or line symbol that is used for the buttons. Beneath
+ the image we draw a filled rectangle using \a color.
+
+ Here is the \c createColorIcon() function:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 32
+
+ This function creates an icon with a filled rectangle in the
+ color of \a color. It is used for creating icons for the color
+ menus in the \c fillColorToolButton, \c fontColorToolButton, and
+ \c lineColorToolButton.
+
+ Here is the \c backgroundButtonGroupClicked() slot:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 1
+
+ In this function we set the QBrush that is used to draw the
+ background of the diagramscene. The background can be a grid of
+ squares of blue, gray, or white tiles, or no grid at all. We have
+ \l{QPixmap}s of the tiles from png files that we create the brush
+ with.
+
+ When one of the buttons in the background tabbed widget item is
+ clicked we change the brush; we find out which button it is by
+ checking its text.
+
+ Here is the implementation of \c buttonGroupClicked():
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 2
+
+ This slot is called when a button in \c buttonGroup is checked.
+ When a button is checked the user can click on the graphics view
+ and a \c DiagramItem of the selected type will be inserted into
+ the \c DiagramScene. We must loop through the buttons in the group
+ to uncheck other buttons as only one button is allowed to be
+ checked at a time.
+
+ \c QButtonGroup assigns an id to each button. We have set the id
+ of each button to the diagram type, as given by DiagramItem::DiagramType
+ that will be inserted into the scene when it is clicked. We can
+ then use the button id when we set the diagram type with
+ \c setItemType(). In the case of text we assigned an id that has a
+ value that is not in the DiagramType enum.
+
+ Here is the implementation of \c deleteItem():
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 3
+
+ This slot deletes the selected item, if any, from the scene. It
+ deletes the arrows first in order to avoid to delete them twice. If
+ the item to be deleted is a \c DiagramItem, we also need to delete
+ arrows connected to it; we don't want arrows in the scene that
+ aren't connected to items in both ends.
+
+ This is the implementation of pointerGroupClicked():
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 4
+
+ The \c pointerTypeGroup decides whether the scene is in ItemMove
+ or InsertLine mode. This button group is exclusive, i.e., only
+ one button is checked at any time. As with the \c buttonGroup above
+ we have assigned an id to the buttons that matches values of the
+ DiagramScene::Mode enum, so that we can use the id to set the
+ correct mode.
+
+ Here is the \c bringToFront() slot:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 5
+
+ Several items may collide, i.e., overlap, with each other in
+ the scene. This slot is called when the user requests that an
+ item should be placed on top of the items it collides with.
+ \l{QGraphicsItem}{QGrapicsItems} have a z-value that decides the
+ order in which items are stacked in the scene; you can think of it
+ as the z-axis in a 3D coordinate system. When items collide the
+ items with higher z-values will be drawn on top of items with
+ lower values. When we bring an item to the front we can loop
+ through the items it collides with and set a z-value that is
+ higher than all of them.
+
+ Here is the \c sendToBack() slot:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 6
+
+ This slot works in the same way as \c bringToFront() described
+ above, but sets a z-value that is lower than items the item that
+ should be send to the back collides with.
+
+ This is the implementation of \c itemInserted():
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 7
+
+ This slot is called from the \c DiagramScene when an item has been
+ added to the scene. We set the mode of the scene back to the mode
+ before the item was inserted, which is ItemMove or InsertText
+ depending on which button is checked in the \c pointerTypeGroup.
+ We must also uncheck the button in the in the \c buttonGroup.
+
+ Here is the implementation of \c textInserted():
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 8
+
+ We simply set the mode of the scene back to the mode it had before
+ the text was inserted.
+
+ Here is the \c currentFontChanged() slot:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 9
+
+ When the user requests a font change, by using one of the
+ widgets in the \c fontToolBar, we create a new QFont object and
+ set its properties to match the state of the widgets. This is done
+ in \c handleFontChange(), so we simply call that slot.
+
+ Here is the \c fontSizeChanged() slot:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 10
+
+ When the user requests a font change, by using one of the
+ widgets in the \c fontToolBar, we create a new QFont object and
+ set its properties to match the state of the widgets. This is done
+ in \c handleFontChange(), so we simply call that slot.
+
+ Here is the implementation of \c sceneScaleChanged():
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 11
+
+ The user can increase or decrease the scale, with the \c
+ sceneScaleCombo, the scene is drawn in.
+ It is not the scene itself that changes its scale, but only the
+ view.
+
+ Here is the \c textColorChanged() slot:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 12
+
+ This slot is called when an item in the drop-down menu of the \c
+ fontColorToolButton is pressed. We need to change the icon on
+ the button to the color of the selected QAction. We keep a pointer
+ to the selected action in \c textAction. It is in \c
+ textButtonTriggered() we change the text color to the color of \c
+ textAction, so we call that slot.
+
+ Here is the \c itemColorChanged() implementation:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 13
+
+ This slot handles requests for changing the color of \c
+ DiagramItems in the same manner as \c textColorChanged() does for
+ \c DiagramTextItems.
+
+ Here is the implementation of \c lineColorChanged():
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 14
+
+ This slot handles requests for changing the color of \c Arrows in
+ the same manner that \c textColorChanged() does it for \c
+ DiagramTextItems.
+
+ Here is the \c textButtonTriggered() slot:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 15
+
+ \c textAction points to the QAction of the currently selected menu item
+ in the \c fontColorToolButton's color drop-down menu. We have set
+ the data of the action to the QColor the action represents, so we
+ can simply fetch this when we set the color of text with \c
+ setTextColor().
+
+ Here is the \c fillButtonTriggered() slot:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 16
+
+ \c fillAction points to the selected menu item in the drop-down
+ menu of \c fillColorToolButton(). We can therefore use the data of
+ this action when we set the item color with \c setItemColor().
+
+ Here is the \c lineButtonTriggered() slot:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 17
+
+ \c lineAction point to the selected item in the drop-down menu of
+ \c lineColorToolButton. We use its data when we set the arrow
+ color with \c setLineColor().
+
+ Here is the \c handleFontChange() function:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 18
+
+ \c handleFontChange() is called when any of the widgets that show
+ font properties changes. We create a new QFont object and set its
+ properties based on the widgets. We then call the \c setFont()
+ function of \c DiagramScene; it is the scene that set the font of
+ the \c DiagramTextItems it manages.
+
+ Here is the \c itemSelected() slot:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 19
+
+ This slot is called when an item in the \c DiagramScene is
+ selected. In the case of this example it is only text items that
+ emit signals when they are selected, so we do not need to check
+ what kind of graphics \a item is.
+
+ We set the state of the widgets to match the properties of the
+ font of the selected text item.
+
+ This is the \c about() slot:
+
+ \snippet graphicsview/diagramscene/mainwindow.cpp 20
+
+ This slot displays an about box for the example when the user
+ selects the about menu item from the help menu.
+
+ \section1 DiagramScene Class Definition
+
+ The \c DiagramScene class inherits QGraphicsScene and adds
+ functionality to handle \c DiagramItems, \c Arrows, and \c
+ DiagramTextItems in addition to the items handled by its super
+ class.
+
+
+ \snippet graphicsview/diagramscene/diagramscene.h 0
+
+ In the \c DiagramScene a mouse click can give three different
+ actions: the item under the mouse can be moved, an item may be
+ inserted, or an arrow may be connected between to diagram items.
+ Which action a mouse click has depends on the mode, given by the
+ Mode enum, the scene is in. The mode is set with the \c setMode()
+ function.
+
+ The scene also sets the color of its items and the font of its
+ text items. The colors and font used by the scene can be set with
+ the \c setLineColor(), \c setTextColor(), \c setItemColor() and \c
+ setFont() functions. The type of \c DiagramItem, given by the
+ DiagramItem::DiagramType function, to be created when an item is
+ inserted is set with the \c setItemType() slot.
+
+ The \c MainWindow and \c DiagramScene share responsibility for
+ the examples functionality. \c MainWindow handles the following
+ tasks: the deletion of items, text, and arrows; moving diagram
+ items to the back and front; and setting the scale of the scene.
+
+ \section1 DiagramScene Class Implementation
+
+
+ We start with the constructor:
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 0
+
+ The scene uses \c myItemMenu to set the context menu when it
+ creates \c DiagramItems. We set the default mode to \c
+ DiagramScene::MoveItem as this gives the default behavior of
+ QGraphicsScene.
+
+ Here is the \c setLineColor() function:
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 1
+
+ The \c isItemChange function returns true if an \c Arrow item is
+ selected in the scene in which case we want to change its color.
+ When the \c DiagramScene creates and adds new arrows to the scene
+ it will also use the new \a color.
+
+ Here is the \c setTextColor() function:
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 2
+
+ This function sets the color of \c DiagramTextItems equal to the
+ way \c setLineColor() sets the color of \c Arrows.
+
+ Here is the \c setItemColor() function:
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 3
+
+ This function sets the color the scene will use when creating
+ \c DiagramItems. It also changes the color of a selected \c
+ DiagramItem.
+
+ This is the implementation of \c setFont():
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 4
+
+ Set the font to use for new and selected, if a text item is
+ selected, \c DiagramTextItems.
+
+ This is the implementation of \c editorLostFocus() slot:
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 5
+
+ \c DiagramTextItems emit a signal when they loose focus, which is
+ connected to this slot. We remove the item if it has no text.
+ If not, we would leak memory and confuse the user as the items
+ will be edited when pressed on by the mouse.
+
+ The \c mousePressEvent() function handles mouse press event's
+ different depending on which mode the \c DiagramScene is in. We
+ examine its implementation for each mode:
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 6
+
+ We simply create a new \c DiagramItem and add it to the scene at
+ the position the mouse was pressed. Note that the origin of its
+ local coordinate system will be under the mouse pointer position.
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 7
+
+ The user adds \c Arrows to the scene by stretching a line between
+ the items the arrow should connect. The start of the line is fixed
+ in the place the user clicked the mouse and the end follows the
+ mouse pointer as long as the button is held down. When the user
+ releases the mouse button an \c Arrow will be added to the scene
+ if there is a \c DiagramItem under the start and end of the line.
+ We will see how this is implemented later; here we simply add the
+ line.
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 8
+
+ The \c DiagramTextItem is editable when the
+ Qt::TextEditorInteraction flag is set, else it is movable by the
+ mouse. We always want the text to be drawn on top of the other
+ items in the scene, so we set the value to a number higher
+ than other items in the scene.
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 9
+
+ We are in MoveItem mode if we get to the default switch; we
+ can then call the QGraphicsScene implementation, which
+ handles movement of items with the mouse. We make this call even
+ if we are in another mode making it possible to add an item and
+ then keep the mouse button pressed down and start moving
+ the item. In the case of text items, this is not possible as they
+ do not propagate mouse events when they are editable.
+
+ This is the \c mouseMoveEvent() function:
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 10
+
+ We must draw the line if we are in InsertMode and the mouse button
+ is pressed down (the line is not 0). As discussed in \c
+ mousePressEvent() the line is drawn from the position the mouse
+ was pressed to the current position of the mouse.
+
+ If we are in MoveItem mode, we call the QGraphicsScene
+ implementation, which handles movement of items.
+
+ In the \c mouseReleaseEvent() function we need to check if an arrow
+ should be added to the scene:
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 11
+
+ First we need to get the items (if any) under the line's start
+ and end points. The line itself is the first item at these points,
+ so we remove it from the lists. As a precaution, we check if the
+ lists are empty, but this should never happen.
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 12
+
+ Now we check if there are two different \c DiagramItems under
+ the lines start and end points. If there are we can create an \c
+ Arrow with the two items. The arrow is then added to each item and
+ finally the scene. The arrow must be updated to adjust its start
+ and end points to the items. We set the z-value of the arrow to
+ -1000.0 because we always want it to be drawn under the items.
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 13
+
+ Here is the \c isItemChange() function:
+
+ \snippet graphicsview/diagramscene/diagramscene.cpp 14
+
+ The scene has single selection, i.e., only one item can be
+ selected at any given time. The foreach will then loop one time
+ with the selected item or none if no item is selected. \c
+ isItemChange() is used to check whether a selected item exists
+ and also is of the specified diagram \a type.
+
+ \section1 DiagramItem Class Definition
+
+
+ \snippet graphicsview/diagramscene/diagramitem.h 0
+
+ The \c DiagramItem represents a flowchart shape in the \c
+ DiagramScene. It inherits QGraphicsPolygonItem and has a polygon
+ for each shape. The enum DiagramType has a value for each of the
+ flowchart shapes.
+
+ The class has a list of the arrows that are connected to it.
+ This is necessary because only the item knows when it is being
+ moved (with the \c itemChanged() function) at which time the
+ arrows must be updated. The item can also draw itself onto a
+ QPixmap with the \c image() function. This is used for the tool
+ buttons in \c MainWindow, see \c createColorToolButtonIcon() in
+ \c MainWindow.
+
+ The Type enum is a unique identifier of the class. It is used by
+ \c qgraphicsitem_cast(), which does dynamic casts of graphics
+ items. The UserType constant is the minimum value a custom
+ graphics item type can be.
+
+ \section1 DiagramItem Class Implementation
+
+
+ We start with a look at the constructor:
+
+ \snippet graphicsview/diagramscene/diagramitem.cpp 0
+
+ In the constructor we create the items polygon according to
+ \a diagramType. \l{QGraphicsItem}s are not movable or selectable
+ by default, so we must set these properties.
+
+ Here is the \c removeArrow() function:
+
+ \snippet graphicsview/diagramscene/diagramitem.cpp 1
+
+ \c removeArrow() is used to remove \c Arrow items when they
+ or \c DiagramItems they are connected to are removed from the
+ scene.
+
+ Here is the \c removeArrows() function:
+
+ \snippet graphicsview/diagramscene/diagramitem.cpp 2
+
+ This function is called when the item is removed from the scene
+ and removes all arrows that are connected to this item. The arrow
+ must be removed from the \c arrows list of both its start and end
+ item.
+
+ Here is the \c addArrow() function:
+
+ \snippet graphicsview/diagramscene/diagramitem.cpp 3
+
+ This function simply adds the \a arrow to the items \c arrows list.
+
+ Here is the \c image() function:
+
+ \snippet graphicsview/diagramscene/diagramitem.cpp 4
+
+ This function draws the polygon of the item onto a QPixmap. In
+ this example we use this to create icons for the tool buttons in
+ the tool box.
+
+ Here is the \c contextMenuEvent() function:
+
+ \snippet graphicsview/diagramscene/diagramitem.cpp 5
+
+ We show the context menu. As right mouse clicks, which shows the
+ menu, don't select items by default we set the item selected with
+ \l{QGraphicsItem::}{setSelected()}. This is necessary since an
+ item must be selected to change its elevation with the
+ \c bringToFront and \c sendToBack actions.
+
+ This is the implementation of \c itemChange():
+
+ \snippet graphicsview/diagramscene/diagramitem.cpp 6
+
+ If the item has moved, we need to update the positions of the
+ arrows connected to it. The implementation of QGraphicsItem does
+ nothing, so we just return \a value.
+
+ \section1 DiagramTextItem Class Definition
+
+ The \c TextDiagramItem class inherits QGraphicsTextItem and
+ adds the possibility to move editable text items. Editable
+ QGraphicsTextItems are designed to be fixed in place and editing
+ starts when the user single clicks on the item. With \c
+ DiagramTextItem the editing starts with a double click leaving
+ single click available to interact with and move it.
+
+ \snippet graphicsview/diagramscene/diagramtextitem.h 0
+
+ We use \c itemChange() and \c focusOutEvent() to notify the
+ \c DiagramScene when the text item loses focus and gets selected.
+
+ We reimplement the functions that handle mouse events to make it
+ possible to alter the mouse behavior of QGraphicsTextItem.
+
+ \section1 DiagramTextItem Implementation
+
+ We start with the constructor:
+
+ \snippet graphicsview/diagramscene/diagramtextitem.cpp 0
+
+ We simply set the item movable and selectable, as these flags are
+ off by default.
+
+ Here is the \c itemChange() function:
+
+ \snippet graphicsview/diagramscene/diagramtextitem.cpp 1
+
+ When the item is selected we emit the selectedChanged signal. The
+ \c MainWindow uses this signal to update the widgets that display
+ font properties to the font of the selected text item.
+
+ Here is the \c focusOutEvent() function:
+
+ \snippet graphicsview/diagramscene/diagramtextitem.cpp 2
+
+ \c DiagramScene uses the signal emitted when the text item looses
+ focus to remove the item if it is empty, i.e., it contains no
+ text.
+
+ This is the implementation of \c mouseDoubleClickEvent():
+
+ \snippet graphicsview/diagramscene/diagramtextitem.cpp 5
+
+ When we receive a double click event, we make the item editable by calling
+ QGraphicsTextItem::setTextInteractionFlags(). We then forward the
+ double-click to the item itself.
+
+ \section1 Arrow Class Definition
+
+ The \c Arrow class is a graphics item that connects two \c
+ DiagramItems. It draws an arrow head to one of the items. To
+ achieve this the item needs to paint itself and also re implement
+ methods used by the graphics scene to check for collisions and
+ selections. The class inherits QGraphicsLine item, and draws the
+ arrowhead and moves with the items it connects.
+
+ \snippet graphicsview/diagramscene/arrow.h 0
+
+ The item's color can be set with \c setColor().
+
+ \c boundingRect() and \c shape() are reimplemented
+ from QGraphicsLineItem and are used by the scene
+ to check for collisions and selections.
+
+ Calling \c updatePosition() causes the arrow to recalculate its
+ position and arrow head angle. \c paint() is reimplemented so that
+ we can paint an arrow rather than just a line between items.
+
+ \c myStartItem and \c myEndItem are the diagram items that the
+ arrow connects. The arrow is drawn with its head to the end item.
+ \c arrowHead is a polygon with three vertices's we use to draw the
+ arrow head.
+
+ \section1 Arrow Class Implementation
+
+ The constructor of the \c Arrow class looks like this:
+
+ \snippet graphicsview/diagramscene/arrow.cpp 0
+
+ We set the start and end diagram items of the arrow. The arrow
+ head will be drawn where the line intersects the end item.
+
+ Here is the \c boundingRect() function:
+
+ \snippet graphicsview/diagramscene/arrow.cpp 1
+
+ We need to reimplement this function because the arrow is
+ larger than the bounding rectangle of the QGraphicsLineItem. The
+ graphics scene uses the bounding rectangle to know which regions
+ of the scene to update.
+
+ Here is the \c shape() function:
+
+ \snippet graphicsview/diagramscene/arrow.cpp 2
+
+ The shape function returns a QPainterPath that is the exact
+ shape of the item. The QGraphicsLineItem::shape() returns a path
+ with a line drawn with the current pen, so we only need to add
+ the arrow head. This function is used to check for collisions and
+ selections with the mouse.
+
+ Here is the \c updatePosition() slot:
+
+ \snippet graphicsview/diagramscene/arrow.cpp 3
+
+ This slot updates the arrow by setting the start and end
+ points of its line to the center of the items it connects.
+
+ Here is the \c paint() function:
+
+ \snippet graphicsview/diagramscene/arrow.cpp 4
+
+ If the start and end items collide we do not draw the arrow; the
+ algorithm we use to find the point the arrow should be drawn at
+ may fail if the items collide.
+
+ We first set the pen and brush we will use for drawing the arrow.
+
+ \snippet graphicsview/diagramscene/arrow.cpp 5
+
+ We then need to find the position at which to draw the
+ arrowhead. The head should be drawn where the line and the end
+ item intersects. This is done by taking the line between each
+ point in the polygon and check if it intersects with the line of
+ the arrow. Since the line start and end points are set to the
+ center of the items the arrow line should intersect one and only
+ one of the lines of the polygon. Note that the points in the
+ polygon are relative to the local coordinate system of the item.
+ We must therefore add the position of the end item to make the
+ coordinates relative to the scene.
+
+ \snippet graphicsview/diagramscene/arrow.cpp 6
+
+ We calculate the angle between the x-axis and the line of the
+ arrow. We need to turn the arrow head to this angle so that it
+ follows the direction of the arrow. If the angle is negative we
+ must turn the direction of the arrow.
+
+ We can then calculate the three points of the arrow head polygon.
+ One of the points is the end of the line, which now is the
+ intersection between the arrow line and the end polygon. Then we
+ clear the \c arrowHead polygon from the previous calculated arrow
+ head and set these new points.
+
+ \snippet graphicsview/diagramscene/arrow.cpp 7
+
+ If the line is selected, we draw two dotted lines that are
+ parallel with the line of the arrow. We do not use the default
+ implementation, which uses \l{QGraphicsItem::}{boundingRect()}
+ because the QRect bounding rectangle is considerably larger than
+ the line.
+*/
diff --git a/examples/widgets/doc/digitalclock.qdoc b/examples/widgets/doc/digitalclock.qdoc
new file mode 100644
index 0000000000..92e8003205
--- /dev/null
+++ b/examples/widgets/doc/digitalclock.qdoc
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/digitalclock
+ \title Digital Clock Example
+
+ The Digital Clock example shows how to use QLCDNumber to display a
+ number with LCD-like digits.
+
+ \image digitalclock-example.png Screenshot of the Digital Clock example
+
+ This example also demonstrates how QTimer can be used to update a widget
+ at regular intervals.
+
+ \section1 DigitalClock Class Definition
+
+ The \c DigitalClock class provides a clock widget showing the time with
+ hours and minutes separated by a blinking colon. We subclass QLCDNumber
+ and implement a private slot called \c showTime() to update the clock
+ display:
+
+ \snippet widgets/digitalclock/digitalclock.h 0
+
+ \section1 DigitalClock Class Implementation
+
+ \snippet widgets/digitalclock/digitalclock.cpp 0
+
+ In the constructor, we first change the look of the LCD numbers. The
+ QLCDNumber::Filled style produces raised segments filled with the
+ foreground color (typically black). We also set up a one-second timer
+ to keep track of the current time, and we connect
+ its \l{QTimer::timeout()}{timeout()} signal to the private \c showTime() slot
+ so that the display is updated every second. Then, we
+ call the \c showTime() slot; without this call, there would be a one-second
+ delay at startup before the time is shown.
+
+ \snippet widgets/digitalclock/digitalclock.cpp 1
+ \snippet widgets/digitalclock/digitalclock.cpp 2
+
+ The \c showTime() slot is called whenever the clock display needs
+ to be updated.
+
+ The current time is converted into a string with the format "hh:mm".
+ When QTime::second() is a even number, the colon in the string is
+ replaced with a space. This makes the colon appear and vanish every
+ other second.
+
+ Finally, we call QLCDNumber::display() to update the widget.
+*/
diff --git a/examples/widgets/doc/dirview.qdoc b/examples/widgets/doc/dirview.qdoc
new file mode 100644
index 0000000000..a4b799678a
--- /dev/null
+++ b/examples/widgets/doc/dirview.qdoc
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/dirview
+ \title Dir View Example
+
+ The Dir View example shows a tree view onto the local filing system. It uses the
+ QDirModel class to provide file and directory information.
+
+ \image dirview-example.png
+*/
diff --git a/examples/widgets/doc/dockwidgets.qdoc b/examples/widgets/doc/dockwidgets.qdoc
new file mode 100644
index 0000000000..12f18a538f
--- /dev/null
+++ b/examples/widgets/doc/dockwidgets.qdoc
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example mainwindows/dockwidgets
+ \title Dock Widgets Example
+
+ The Dock Widgets example shows how to add dock windows to an
+ application. It also shows how to use Qt's rich text engine.
+
+ \image dockwidgets-example.png Screenshot of the Dock Widgets example
+
+ The application presents a simple business letter template, and has
+ a list of customer names and addresses and a list of standard
+ phrases in two dock windows. The user can click a customer to have
+ their name and address inserted into the template, and click one or
+ more of the standard phrases. Errors can be corrected by clicking
+ the Undo button. Once the letter has been prepared it can be printed
+ or saved as HTML.
+
+ \section1 MainWindow Class Definition
+
+ Here's the class definition:
+
+ \snippet mainwindows/dockwidgets/mainwindow.h 0
+
+ We will now review each function in turn.
+
+ \section1 MainWindow Class Implementation
+
+ \snippet mainwindows/dockwidgets/mainwindow.cpp 0
+
+ We start by including \c <QtGui>, a header file that contains the
+ definition of all classes in the \l QtCore and \l QtGui
+ libraries. This saves us from having to include
+ every class individually and is especially convenient if we add new
+ widgets. We also include \c mainwindow.h.
+
+ \snippet mainwindows/dockwidgets/mainwindow.cpp 1
+
+ In the constructor, we start by creating a QTextEdit widget. Then we call
+ QMainWindow::setCentralWidget(). This function passes ownership of
+ the QTextEdit to the \c MainWindow and tells the \c MainWindow that
+ the QTextEdit will occupy the \c MainWindow's central area.
+
+ Then we call \c createActions(), \c createMenus(), \c
+ createToolBars(), \c createStatusBar(), and \c createDockWindows()
+ to set up the user interface. Finally we call \c setWindowTitle() to
+ give the application a title, and \c newLetter() to create a new
+ letter template.
+
+ We won't quote the \c createActions(), \c createMenus(), \c
+ createToolBars(), and \c createStatusBar() functions since they
+ follow the same pattern as all the other Qt examples.
+
+ \snippet mainwindows/dockwidgets/mainwindow.cpp 9
+
+ We create the customers dock window first, and in addition to a
+ window title, we also pass it a \c this pointer so that it becomes a
+ child of \c MainWindow. Normally we don't have to pass a parent
+ because widgets are parented automatically when they are laid out:
+ but dock windows aren't laid out using layouts.
+
+ We've chosen to restrict the customers dock window to the left and
+ right dock areas. (So the user cannot drag the dock window to the
+ top or bottom dock areas.) The user can drag the dock window out of
+ the dock areas entirely so that it becomes a free floating window.
+ We can change this (and whether the dock window is moveable or
+ closable) using QDockWidget::setFeatures().
+
+ Once we've created the dock window we create a list widget with the
+ dock window as parent, then we populate the list and make it the
+ dock window's widget. Finally we add the dock widget to the \c
+ MainWindow using \c addDockWidget(), choosing to put it in the right
+ dock area.
+
+ We undertake a similar process for the paragraphs dock window,
+ except that we don't restrict which dock areas it can be dragged to.
+
+ Finally we set up the signal-slot connections. If the user clicks a
+ customer or a paragraph their \c currentTextChanged() signal will be
+ emitted and we connect these to \c insertCustomer() and
+ addParagraph() passing the text that was clicked.
+
+ We briefly discuss the rest of the implementation, but have now
+ covered everything relating to dock windows.
+
+ \snippet mainwindows/dockwidgets/mainwindow.cpp 2
+
+ In this function we clear the QTextEdit so that it is empty. Next we
+ create a QTextCursor on the QTextEdit. We move the cursor to the
+ start of the document and create and format a frame. We then create
+ some character formats and a table format. We insert a table into
+ the document and insert the company's name and address into a table
+ using the table and character formats we created earlier. Then we
+ insert the skeleton of the letter including two markers \c NAME and
+ \c ADDRESS. We will also use the \c{Yours sincerely,} text as a marker.
+
+ \snippet mainwindows/dockwidgets/mainwindow.cpp 6
+
+ If the user clicks a customer we split the customer details into
+ pieces. We then look for the \c NAME marker using the \c find()
+ function. This function selects the text it finds, so when we call
+ \c insertText() with the customer's name the name replaces the marker.
+ We then look for the \c ADDRESS marker and replace it with each line
+ of the customer's address. Notice that we wrapped all the insertions
+ between a \c beginEditBlock() and \c endEditBlock() pair. This means
+ that the entire name and address insertion is treated as a single
+ operation by the QTextEdit, so a single undo will revert all the
+ insertions.
+
+ \snippet mainwindows/dockwidgets/mainwindow.cpp 7
+
+ This function works in a similar way to \c insertCustomer(). First
+ we look for the marker, in this case, \c {Yours sincerely,}, and then
+ replace it with the standard paragraph that the user clicked. Again
+ we use a \c beginEditBlock() ... \c endEditBlock() pair so that the
+ insertion can be undone as a single operation.
+
+ \snippet mainwindows/dockwidgets/mainwindow.cpp 3
+
+ Qt's QTextDocument class makes printing documents easy. We simply
+ take the QTextEdit's QTextDocument, set up the printer and print the
+ document.
+
+ \snippet mainwindows/dockwidgets/mainwindow.cpp 4
+
+ QTextEdit can output its contents in HTML format, so we prompt the
+ user for the name of an HTML file and if they provide one we simply
+ write the QTextEdit's contents in HTML format to the file.
+
+ \snippet mainwindows/dockwidgets/mainwindow.cpp 5
+
+ If the focus is in the QTextEdit, pressing \uicontrol Ctrl+Z undoes as
+ expected. But for the user's convenience we provide an
+ application-wide undo function that simply calls the QTextEdit's
+ undo: this means that the user can undo regardless of where the
+ focus is in the application.
+*/
diff --git a/examples/widgets/doc/dragdroprobot.qdoc b/examples/widgets/doc/dragdroprobot.qdoc
new file mode 100644
index 0000000000..60bd4eb4d8
--- /dev/null
+++ b/examples/widgets/doc/dragdroprobot.qdoc
@@ -0,0 +1,365 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example graphicsview/dragdroprobot
+ \title Drag and Drop Robot Example
+
+ The Drag and Drop Robot example shows how to implement Drag and Drop in a
+ QGraphicsItem subclass, as well as how to animate items using Qt's
+ \l{Animation Framework}.
+
+ \image dragdroprobot-example.png
+
+ Graphics View provides the QGraphicsScene class for managing and
+ interacting with a large number of custom-made 2D graphical items derived
+ from the QGraphicsItem class, and a QGraphicsView widget for visualizing
+ the items, with support for zooming and rotation.
+
+ This example consists of a \c Robot class, a \c ColorItem class, and a main
+ function: the \c Robot class describes a simple robot consisting of several
+ \c RobotPart derived limbs, including \c RobotHead and \c RobotLimb, the \c
+ ColorItem class provides a draggable colored ellipse, and the \c main()
+ function provides the main application window.
+
+ We will first review the \c Robot class to see how to assemble the
+ different parts so that they can be individually rotated and animated using
+ QPropertyAnimation, and we will then review the \c ColorItem class to
+ demonstrate how to implement Drag and Drop between items. Finally we will
+ review the main() function to see how we can put all the pieces together,
+ to form the final application.
+
+ \section1 Robot Class Definition
+
+ The robot consists of three main classes: the \c RobotHead, the \c
+ RobotTorso, and the \c RobotLimb, which is used for the upper and lower
+ arms and legs. All parts derive from the \c RobotPart class, which in turn
+ inherits \c QGraphicsObject. The \c Robot class itself has no visual
+ appearance and serves only as a root node for the robot.
+
+ Let's start with the \c RobotPart class declaration.
+
+ \snippet graphicsview/dragdroprobot/robot.h 0
+
+ This base class inherits QGraphicsObject. QGraphicsObject provides signals
+ and slots through inheriting QObject, and it also declares QGraphicsItem's
+ properties using Q_PROPERTY, which makes the properties accessible for
+ QPropertyAnimation.
+
+ RobotPart also implements the three most important event handlers for
+ accepting drop events:
+ \l{QGraphicsItem::dragEnterEvent()}{dragEnterEvent()},
+ \l{QGraphicsItem::dragLeaveEvent()}{dragLeaveEvent()}, and
+ \l{QGraphicsItem::dropEvent()}{dropEvent()}.
+
+ The color is stored as a member variable, along with the \c dragOver
+ variable, which we will use later to indicate visually that the limb can
+ accept colors that are is dragged onto it.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 0
+
+ \c RobotPart's constructor initializes the dragOver member and sets the
+ color to Qt::lightGray. In the constructor body we enable support for
+ accepting drop events by calling
+ \l{QGraphicsItem::setAcceptDrops()}{setAcceptDrops(true)}.
+
+ The rest of this class's implementation is to support Drag and Drop.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 1
+
+ The \l{QGraphicsItem::dragEnterEvent()}{dragEnterEvent()} handler is called
+ when a Drag and Drop element is dragged into the robot part's area.
+
+ The handler implementation determines whether or not this item as a whole
+ can accept the mime data assiciated with the incoming drag object. \c
+ RobotPart provides a base behavior for all parts that accepts color drops.
+ So if the incoming drag object contains a color, the event is accepted, we
+ set \c dragOver to \c true and call update() to help provide positive
+ visual feedback to the user; otherwise the event is ignored, which in turn
+ allows the event to propagate to parent elements.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 2
+
+ The \l{QGraphicsItem::dragLeaveEvent()}{dragLeaveEvent()} handler is called
+ when a Drag and Drop element is dragged away from the robot part's area.
+ Our implementation simply resets \e dragOver to false and calls
+ \l{QGraphicsItem::update()}{update()} to help provide visual feedback that
+ the drag has left this item.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 3
+
+ The \l{QGraphicsItem::dropEvent()}{dropEvent()} handler is called when a
+ Drag and Drop element is dropped onto an item (i.e., when the mouse button
+ is released over the item while dragging).
+
+ We reset \c dragOver to false, assign the item's new color, and call
+ \l{QGraphicsItem::update()}{update()}.
+
+ The declaration and implementation of \c RobotHead, \c RobotTorso, and \c
+ RobotLimb are practically identical. We will review \c RobotHead in detail,
+ as this class has one minor difference, and leave the other classes as an
+ exercise for the reader.
+
+ \snippet graphicsview/dragdroprobot/robot.h 1
+
+ The \c RobotHead class inherits \c RobotPart and provides the necessary
+ implementations of \l{QGraphicsItem::boundingRect()}{boundingRect()} and
+ \l{QGraphicsItem::paint()}{paint()}. It also reimplements
+ \l{QGraphicsItem::dragEnterEvent()}{dragEnterEvent()} and dropEvent() to
+ provide special handling of image drops.
+
+ The class contains a private pixmap member that we can use to implement
+ support for accepting image drops.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 4
+
+ \c RobotHead has a rather plain constructor that simply forwards to
+ \c RobotPart's constructor.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 5
+
+ The \l{QGraphicsItem::boundingRect()}{boundingRect()} reimplementation
+ returns the extents for the head. Because we want the center of rotation to
+ be the bottom center of the item, we have chosen a bounding rectangle that
+ starts at (-15, -50) and extends to 30 units wide and 50 units tall. When
+ rotating the head, the "neck" will stay still while the top of the head
+ tilts from side to side.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 6
+
+ In \l{QGraphicsItem::paint()}{paint()} we draw the actual head. The
+ implementation is split into two sections; if an image has been dropped
+ onto the head, we draw the image, otherwise we draw a round rectangular
+ robot head with simple vector graphics.
+
+ For performance reasons, depending on the complexity of what is painted, it
+ can often be faster to draw the head as an image rather than using a
+ sequence of vector operations.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 7
+
+ The robot head can accept image drops. In order to support this, its
+ reimplementation of \l{QGraphicsItem::dragEnterEvent()}{dragEnterEvent()}
+ checks if the drag object contains image data, and if it does, then the
+ event is accepted. Otherwise we fall back to the base \c RobotPart
+ implementation.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 8
+
+ To follow up on image support, we must also implement
+ \l{QGraphicsItem::dropEvent()}{dropEvent()}. We check if the drag object
+ contains image data, and if it does, we store this data as a member pixmap
+ and call \l{QGraphicsItem::update()}{update()}. This pixmap is used inside
+ the \l{QGraphicsItem::paint()}{paint()} implementation that we reviewed
+ before.
+
+ \c RobotTorso and \c RobotLimb are similar to \c RobotHead, so let's
+ skip directly to the \c Robot class.
+
+ \snippet graphicsview/dragdroprobot/robot.h 4
+
+ The \c Robot class also inherits \c RobotPart, and like the other parts it
+ also implements \l{QGraphicsItem::boundingRect()}{boundingRect()} and
+ \l{QGraphicsItem::paint()}{paint()}. It provides a rather special
+ implementation, though:
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 9
+
+ Because the \c Robot class is only used as a base node for the rest of the
+ robot, it has no visual representation. Its
+ \l{QGraphicsItem::boundingRect()}{boundingRect()} implementation can
+ therefore return a null QRectF, and its paint() function does nothing.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 10
+
+ The constructor starts by setting the flag
+ \l{QGraphicsItem::ItemHasNoContents}{ItemHasNoContents}, which is a minor
+ optimization for items that have no visual appearance.
+
+ We then construct all the robot parts (head, torso, and upper/lower arms
+ and legs). The stacking order is very important, and we use the
+ parent-child hierarchy to ensure the elements rotate and move properly. We
+ construct the torso first, as this is the root element. We then construct
+ the head and pass the torso to \c HeadItem's constructor. This will make
+ the head a child of the torso; if you rotate the torso, the head will
+ follow. The same pattern is applied to the rest of the limbs.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 11
+
+ Each robot part is carefully positioned. For example, the upper left arm is
+ moved precisely to the top-left area of the torso, and the upper right arm
+ is moved to the top-right area.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 12
+
+ The next section creates all animation objects. This snippet shows the two
+ animations that operate on the head's scale and rotation. The two
+ QPropertyAnimation instances simply set the object, property, and
+ respective start and end values.
+
+ All animations are controlled by one top-level parallel animation group.
+ The scale and rotation animations are added to this group.
+
+ The rest of the animations are defined in a similar way.
+
+ \snippet graphicsview/dragdroprobot/robot.cpp 13
+
+ Finally we set an easing curve and duration on each animation, ensure the
+ toplevel animation group loops forever, and start the toplevel animation.
+
+ \section1 ColorItem Class Definition
+
+ The \c ColorItem class represents a circular item that can be pressed to
+ drag colors onto robot parts.
+
+ \snippet graphicsview/dragdroprobot/coloritem.h 0
+
+ This class is very simple. It does not use animations, and has no need for
+ properties nor signals and slots, so to save resources, it's most natural
+ that it inherits QGraphicsItem (as opposed to QGraphicsObject).
+
+ It declares the mandatory \l{QGraphicsItem::boundingRect()}{boundingRect()}
+ and \l{QGraphicsItem::paint()}{paint()} functions, and adds
+ reimplementations of
+ \l{QGraphicsItem::mousePressEvent()}{mousePressEvent()},
+ \l{QGraphicsItem::mouseMoveEvent()}{mouseMoveEvent()}, and
+ \l{QGraphicsItem::mouseReleaseEvent()}{mouseReleaseEvent()}. It contains a
+ single private color member.
+
+ Let's take a look at its implementation.
+
+ \snippet graphicsview/dragdroprobot/coloritem.cpp 0
+
+ \c ColorItem's constructor assigns an opaque random color to its color
+ member by making use of qrand(). For improved usability, it assigns a
+ tooltip that provides a useful hint to the user, and it also sets a
+ suitable cursor. This ensures that the cursor will chance to
+ Qt::OpenHandCursor when the mouse pointer hovers over the item.
+
+ Finally, we call
+ \l{QGraphicsItem::setAcceptedMouseButtons()}{setAcceptedMouseButtons()} to
+ ensure that this item can only process Qt::LeftButton. This simplifies the
+ mouse event handlers greatly, as we can always assume that only the left
+ mouse button is pressed and released.
+
+ \snippet graphicsview/dragdroprobot/coloritem.cpp 1
+
+ The item's bounding rect is a fixed 30x30 units centered around the item's
+ origin (0, 0), and adjusted by 0.5 units in all directions to allow a
+ scalable pen to draw its outline. For a final visual touch the bounds
+ also compensate with a few units down and to the right to make room
+ for a simple dropshadow.
+
+ \snippet graphicsview/dragdroprobot/coloritem.cpp 2
+
+ The \l{QGraphicsItem::paint()}{paint()} implementation draws an ellipse
+ with a 1-unit black outline, a plain color fill, and a dark gray
+ dropshadow.
+
+ \snippet graphicsview/dragdroprobot/coloritem.cpp 3
+
+ The \l{QGraphicsItem::mousePressEvent()}{mousePressEvent()} handler is
+ called when you press the mouse button inside the item's area. Our
+ implementation simply sets the cursor to Qt::ClosedHandCursor.
+
+ \snippet graphicsview/dragdroprobot/coloritem.cpp 4
+
+ The \l{QGraphicsItem::mouseReleaseEvent()}{mouseReleaseEvent()} handler is
+ called when you release the mouse button after having pressed it inside an
+ item's area. Our implementation sets the cursor back to Qt::OpenHandCursor.
+ The mouse press and release event handlers together provide useful visual
+ feedback to the user: when you move the mouse pointer over a \c CircleItem,
+ the cursor changes to an open hand. Pressing the item will show a closed
+ hand cursor. Releasing will restore to an open hand cursor again.
+
+ \snippet graphicsview/dragdroprobot/coloritem.cpp 5
+
+ The \l{QGraphicsItem::mouseMoveEvent()}{mouseMoveEvent()} handler is called
+ when you move the mouse around after pressing the mouse button inside the
+ \c ColorItem's area. This implementation provides the most important piece
+ of logic for \c CircleItem: the code that starts and manages drags.
+
+ The implementation starts by checking if the mouse has been dragged far
+ enough to eliminate mouse jitter noise. We only want to start a drag if the
+ mouse has been dragged farther than the application start drag distance.
+
+ Continuing, we create a QDrag object, passing the event
+ \l{QGraphicsSceneEvent::widget()}{widget} (i.e., the QGraphicsView
+ viewport) to its constructor. Qt will ensure that this object is deleted at
+ the right time. We also create a QMimeData instance that can contain our
+ color or image data, and assign this to the drag object.
+
+ \snippet graphicsview/dragdroprobot/coloritem.cpp 6
+
+ This snippet has a somewhat random outcome: once in a while, a special
+ image is assigned to the drag object's mime data. The pixmap is also
+ assiged as the drag object's pixmap. This will ensure that you can see the
+ image that is being dragged as a pixmap under the mouse cursor.
+
+ \snippet graphicsview/dragdroprobot/coloritem.cpp 7
+
+ Otherwise, and this is the most common outcome, a simple color is assigned
+ to the drag object's mime data. We render this \c ColorItem into a new
+ pixmap to give the user visual feedback that the color is being "dragged".
+
+ \snippet graphicsview/dragdroprobot/coloritem.cpp 8
+
+ Finally we execute the drag. QDrag::exec() will reenter the event loop, and
+ only exit if the drag has either been dropped, or canceled. In any case we
+ reset the cursor to Qt::OpenHandCursor.
+
+ \section1 The main() Function
+
+ Now that the \c Robot and \c ColorItem classes are complete, we can put all
+ the pieces together inside the main() function.
+
+ \snippet graphicsview/dragdroprobot/main.cpp 0
+
+ We start off by constructing QApplication, and initializing the random
+ number generator. This ensures that the color items have different colors
+ every time the application starts.
+
+ \snippet graphicsview/dragdroprobot/main.cpp 1
+
+ We construct a fixed size scene, and create 10 \c ColorItem instances
+ arranged in a circle. Each item is added to the scene.
+
+ In the center of this circle we create one \c Robot instance. The
+ robot is scaled and moved up a few units. It is then added to the scene.
+
+ \snippet graphicsview/dragdroprobot/main.cpp 2
+
+ Finally we create a QGraphicsView window, and assign the scene to it.
+
+ For increased visual quality, we enable antialiasing. We also choose to use
+ bounding rectangle updates to simplify visual update handling.
+ The view is given a fixed sand-colored background, and a window title.
+
+ We then show the view. The animations start immediately after
+ control enters the event loop.
+*/
+
diff --git a/examples/widgets/doc/dynamiclayouts.qdoc b/examples/widgets/doc/dynamiclayouts.qdoc
new file mode 100644
index 0000000000..318f719503
--- /dev/null
+++ b/examples/widgets/doc/dynamiclayouts.qdoc
@@ -0,0 +1,34 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example layouts/dynamiclayouts
+ \title Dynamic Layouts Example
+
+ The Dynamic Layouts example shows how to move widgets around in
+ existing layouts.
+*/
diff --git a/examples/widgets/doc/easing.qdoc b/examples/widgets/doc/easing.qdoc
new file mode 100644
index 0000000000..7fb7f59531
--- /dev/null
+++ b/examples/widgets/doc/easing.qdoc
@@ -0,0 +1,37 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example animation/easing
+ \title Easing Curves Example
+
+ The Easing Curves example shows how to use easing curves to
+ control the speed of an animation.
+
+ \image easing-example.png
+
+*/
diff --git a/examples/widgets/doc/editabletreemodel.qdoc b/examples/widgets/doc/editabletreemodel.qdoc
new file mode 100644
index 0000000000..423b9cee94
--- /dev/null
+++ b/examples/widgets/doc/editabletreemodel.qdoc
@@ -0,0 +1,446 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/editabletreemodel
+ \title Editable Tree Model Example
+
+ This example shows how to implement a simple item-based tree model that can
+ be used with other classes the model/view framework.
+
+ \image itemviews-editabletreemodel.png
+
+ The model supports editable items, custom headers, and the ability to
+ insert and remove rows and columns. With these features, it is also
+ possible to insert new child items, and this is shown in the supporting
+ example code.
+
+ \note The model only shows the basic principles used when creating an
+ editable, hierarchical model. You may wish to use the \l{ModelTest}
+ project to test production models.
+
+ \section1 Overview
+
+ As described in the \l{Model Subclassing Reference}, models must
+ provide implementations for the standard set of model functions:
+ \l{QAbstractItemModel::}{flags()}, \l{QAbstractItemModel::}{data()},
+ \l{QAbstractItemModel::}{headerData()},
+ \l{QAbstractItemModel::}{columnCount()}, and
+ \l{QAbstractItemModel::}{rowCount()}. In addition, hierarchical models,
+ such as this one, need to provide implementations of
+ \l{QAbstractItemModel::}{index()} and \l{QAbstractItemModel::}{parent()}.
+
+ An editable model needs to provide implementations of
+ \l{QAbstractItemModel::}{setData()} and
+ \l{QAbstractItemModel::}{setHeaderData()}, and must return a suitable
+ combination of flags from its \l{QAbstractItemModel::}{flags()} function.
+
+ Since this example allows the dimensions of the model to be changed,
+ we must also implement \l{QAbstractItemModel::}{insertRows()},
+ \l{QAbstractItemModel::}{insertColumns()},
+ \l{QAbstractItemModel::}{removeRows()}, and
+ \l{QAbstractItemModel::}{removeColumns()}.
+
+ \section1 Design
+
+ As with the \l{itemviews/simpletreemodel}{Simple Tree Model} example,
+ the model simply acts as a wrapper around a collection
+ of instances of a \c TreeItem class. Each \c TreeItem is designed to
+ hold data for a row of items in a tree view, so it contains a list of
+ values corresponding to the data shown in each column.
+
+ Since QTreeView provides a row-oriented view onto a model, it is
+ natural to choose a row-oriented design for data structures that
+ will supply data via a model to this kind of view. Although this makes
+ the tree model less flexible, and possibly less useful for use with
+ more sophisticated views, it makes it less complex to design and easier
+ to implement.
+
+ \target Relations-between-internal-items
+ \table
+ \row \li \inlineimage itemviews-editabletreemodel-items.png
+ \li \b{Relations between internal items}
+
+ When designing a data structure for use with a custom model, it is useful
+ to expose each item's parent via a function like
+ \l{TreeItem::parent}{TreeItem::parent()} because it will make
+ writing the model's own \l{QAbstractItemModel::}{parent()} function easier.
+ Similarly, a function like \l{TreeItem::child}{TreeItem::child()} is
+ helpful when implementing the model's \l{QAbstractItemModel::}{index()}
+ function. As a result, each \c TreeItem maintains information about
+ its parent and children, making it possible for us to traverse the tree
+ structure.
+
+ The diagram shows how \c TreeItem instances are connected via their
+ \l{TreeItem::parent}{parent()} and \l{TreeItem::child}{child()}
+ functions.
+
+ In the example shown, two top-level items, \b{A} and
+ \b{B}, can be obtained from the root item by calling its child()
+ function, and each of these items return the root node from their
+ parent() functions, though this is only shown for item \b{A}.
+ \endtable
+
+ Each \c TreeItem stores data for each column in the row it represents
+ in its \c itemData private member (a list of QVariant objects).
+ Since there is a one-to-one mapping between each column in the view
+ and each entry in the list, we provide a simple
+ \l{TreeItem::data}{data()} function to read entries in the \c itemData
+ list and a \l{TreeItem::setData}{setData()} function to allow them to
+ be modified.
+ As with other functions in the item, this simplifies the implemention
+ of the model's \l{QAbstractItemModel::}{data()} and
+ \l{QAbstractItemModel::}{setData()} functions.
+
+ We place an item at the root of the tree of items. This root item
+ corresponds to the null model index, \l{QModelIndex::}{QModelIndex()},
+ that is used to represent the parent of a top-level item when handling
+ model indexes.
+ Although the root item does not have a visible representation in any of
+ the standard views, we use its internal list of QVariant objects to
+ store a list of strings that will be passed to views for use as
+ horizontal header titles.
+
+ \table
+ \row \li \inlineimage itemviews-editabletreemodel-model.png
+ \li \b{Accessing data via the model}
+
+ In the case shown in the diagram, the piece of information represented
+ by \b{a} can be obtained using the standard model/view API:
+
+ \snippet doc/src/snippets/code/doc_src_examples_editabletreemodel.cpp 0
+
+ Since each items holds pieces of data for each column in a given row,
+ there can be many model indexes that map to the same \c TreeItem object.
+ For example, the information represented by \b{b} can be obtained
+ using the following code:
+
+ \snippet doc/src/snippets/code/doc_src_examples_editabletreemodel.cpp 1
+
+ The same underlying \c TreeItem would be accessed to obtain information
+ for the other model indexes in the same row as \b{b}.
+ \endtable
+
+ In the model class, \c TreeModel, we relate \c TreeItem objects to
+ model indexes by passing a pointer for each item when we create its
+ corresponding model index with QAbstractItemModel::createIndex() in
+ our \l{TreeModel::index}{index()} and \l{TreeModel::parent}{parent()}
+ implementations.
+ We can retrieve pointers stored in this way by calling the
+ \l{QModelIndex::}{internalPointer()} function on the relevant model
+ index - we create our own \l{TreeModel::getItem}{getItem()} function to
+ do this work for us, and call it from our \l{TreeModel::data}{data()}
+ and \l{TreeModel::parent}{parent()} implementations.
+
+ Storing pointers to items is convenient when we control how they are
+ created and destroyed since we can assume that an address obtained from
+ \l{QModelIndex::}{internalPointer()} is a valid pointer.
+ However, some models need to handle items that are obtained from other
+ components in a system, and in many cases it is not possible to fully
+ control how items are created or destroyed. In such situations, a pure
+ pointer-based approach needs to be supplemented by safeguards to ensure
+ that the model does not attempt to access items that have been deleted.
+
+ \table
+ \row \li \b{Storing information in the underlying data structure}
+
+ Several pieces of data are stored as QVariant objects in the \c itemData
+ member of each \c TreeItem instance
+
+ The diagram shows how pieces of information,
+ represented by the labels \b{a}, \b{b} and \b{c} in the
+ previous two diagrams, are stored in items \b{A}, \b{B} and
+ \b{C} in the underlying data structure. Note that pieces of
+ information from the same row in the model are all obtained from the
+ same item. Each element in a list corresponds to a piece of information
+ exposed by each column in a given row in the model.
+
+ \li \inlineimage itemviews-editabletreemodel-values.png
+ \endtable
+
+ Since the \c TreeModel implementation has been designed for use with
+ QTreeView, we have added a restriction on the way it uses \c TreeItem
+ instances: each item must expose the same number of columns of data.
+ This makes viewing the model consistent, allowing us to use the root
+ item to determine the number of columns for any given row, and only
+ adds the requirement that we create items containing enough data for
+ the total number of columns. As a result, inserting and removing
+ columns are time-consuming operations because we need to traverse the
+ entire tree to modify every item.
+
+ An alternative approach would be to design the \c TreeModel class so
+ that it truncates or expands the list of data in individual \c TreeItem
+ instances as items of data are modified. However, this "lazy" resizing
+ approach would only allow us to insert and remove columns at the end of
+ each row and would not allow columns to be inserted or removed at
+ arbitrary positions in each row.
+
+ \target Relating-items-using-model-indexes
+ \table
+ \row
+ \li \inlineimage itemviews-editabletreemodel-indexes.png
+ \li \b{Relating items using model indexes}
+
+ As with the \l{itemviews/simpletreemodel}{Simple Tree Model} example,
+ the \c TreeModel needs to be able to take a model index, find the
+ corresponding \c TreeItem, and return model indexes that correspond to
+ its parents and children.
+
+ In the diagram, we show how the model's \l{TreeModel::parent}{parent()}
+ implementation obtains the model index corresponding to the parent of
+ an item supplied by the caller, using the items shown in a
+ \l{Relations-between-internal-items}{previous diagram}.
+
+ A pointer to item \b{C} is obtained from the corresponding model index
+ using the \l{QModelIndex::internalPointer()} function. The pointer was
+ stored internally in the index when it was created. Since the child
+ contains a pointer to its parent, we use its \l{TreeItem::parent}{parent()}
+ function to obtain a pointer to item \b{B}. The parent model index is
+ created using the QAbstractItemModel::createIndex() function, passing
+ the pointer to item \b{B} as the internal pointer.
+ \endtable
+
+ \section1 TreeItem Class Definition
+
+ The \c TreeItem class provides simple items that contain several
+ pieces of data, and which can provide information about their parent
+ and child items:
+
+ \snippet itemviews/editabletreemodel/treeitem.h 0
+
+ We have designed the API to be similar to that provided by
+ QAbstractItemModel by giving each item functions to return the number
+ of columns of information, read and write data, and insert and remove
+ columns. However, we make the relationship between items explicit by
+ providing functions to deal with "children" rather than "rows".
+
+ Each item contains a list of pointers to child items, a pointer to its
+ parent item, and a list of QVariant objects that correspond to
+ information held in columns in a given row in the model.
+
+ \section1 TreeItem Class Implementation
+
+ Each \c TreeItem is constructed with a list of data and an optional
+ parent item:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 0
+
+ Initially, each item has no children. These are added to the item's
+ internal \c childItems member using the \c insertChildren() function
+ described later.
+
+ The destructor ensures that each child added to the item is deleted
+ when the item itself is deleted:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 1
+
+ \target TreeItem::parent
+ Since each item stores a pointer to its parent, the \c parent() function
+ is trivial:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 9
+
+ \target TreeItem::child
+ Three functions provide information about the children of an item.
+ \c child() returns a specific child from the internal list of children:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 2
+
+ The \c childCount() function returns the total number of children:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 3
+
+ The \c childNumber() function is used to determine the index of the child
+ in its parent's list of children. It accesses the parent's \c childItems
+ member directly to obtain this information:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 4
+
+ The root item has no parent item; for this item, we return zero to be
+ consistent with the other items.
+
+ The \c columnCount() function simply returns the number of elements in
+ the internal \c itemData list of QVariant objects:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 5
+
+ \target TreeItem::data
+ Data is retrieved using the \c data() function, which accesses the
+ appropriate element in the \c itemData list:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 6
+
+ \target TreeItem::setData
+ Data is set using the \c setData() function, which only stores values
+ in the \c itemData list for valid list indexes, corresponding to column
+ values in the model:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 11
+
+ To make implementation of the model easier, we return true to indicate
+ whether the data was set successfully, or false if an invalid column
+
+ Editable models often need to be resizable, enabling rows and columns to
+ be inserted and removed. The insertion of rows beneath a given model index
+ in the model leads to the insertion of new child items in the corresponding
+ item, handled by the \c insertChildren() function:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 7
+
+ This ensures that new items are created with the required number of columns
+ and inserted at a valid position in the internal \c childItems list.
+ Items are removed with the \c removeChildren() function:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 10
+
+ As discussed above, the functions for inserting and removing columns are
+ used differently to those for inserting and removing child items because
+ they are expected to be called on every item in the tree. We do this by
+ recursively calling this function on each child of the item:
+
+ \snippet itemviews/editabletreemodel/treeitem.cpp 8
+
+ \section1 TreeModel Class Definition
+
+ The \c TreeModel class provides an implementation of the QAbstractItemModel
+ class, exposing the necessary interface for a model that can be edited and
+ resized.
+
+ \snippet itemviews/editabletreemodel/treemodel.h 0
+
+ The constructor and destructor are specific to this model.
+
+ \snippet itemviews/editabletreemodel/treemodel.h 1
+
+ Read-only tree models only need to provide the above functions. The
+ following public functions provide support for editing and resizing:
+
+ \snippet itemviews/editabletreemodel/treemodel.h 2
+
+ To simplify this example, the data exposed by the model is organized into
+ a data structure by the model's \l{TreeModel::setupModelData}{setupModelData()}
+ function. Many real world models will not process the raw data at all, but
+ simply work with an existing data structure or library API.
+
+ \section1 TreeModel Class Implementation
+
+ The constructor creates a root item and initializes it with the header
+ data supplied:
+
+ \snippet itemviews/editabletreemodel/treemodel.cpp 0
+
+ We call the internal \l{TreeModel::setupModelData}{setupModelData()}
+ function to convert the textual data supplied to a data structure we can
+ use with the model. Other models may be initialized with a ready-made
+ data structure, or use an API to a library that maintains its own data.
+
+ The destructor only has to delete the root item; all child items will
+ be recursively deleted by the \c TreeItem destructor.
+
+ \snippet itemviews/editabletreemodel/treemodel.cpp 1
+
+ \target TreeModel::getItem
+ Since the model's interface to the other model/view components is based
+ on model indexes, and the internal data structure is item-based, many of
+ the functions implemented by the model need to be able to convert any
+ given model index to its corresponding item. For convenience and
+ consistency, we have defined a \c getItem() function to perform this
+ repetitive task:
+
+ \snippet itemviews/editabletreemodel/treemodel.cpp 4
+
+ This function assumes that each model index it is passed corresponds to
+ a valid item in memory. If the index is invalid, or its internal pointer
+ does not refer to a valid item, the root item is returned instead.
+
+ The model's \c rowCount() implementation is simple: it first uses the
+ \c getItem() function to obtain the relevant item, then returns the
+ number of children it contains:
+
+ \snippet itemviews/editabletreemodel/treemodel.cpp 8
+
+ By contrast, the \c columnCount() implementation does not need to look
+ for a particular item because all items are defined to have the same
+ number of columns associated with them.
+
+ \snippet itemviews/editabletreemodel/treemodel.cpp 2
+
+ As a result, the number of columns can be obtained directly from the root
+ item.
+
+ To enable items to be edited and selected, the \c flags() function needs
+ to be implemented so that it returns a combination of flags that includes
+ the Qt::ItemIsEditable and Qt::ItemIsSelectable flags as well as
+ Qt::ItemIsEnabled:
+
+ \snippet itemviews/editabletreemodel/treemodel.cpp 3
+
+ \target TreeModel::index
+ The model needs to be able to generate model indexes to allow other
+ components to request data and information about its structure. This task
+ is performed by the \c index() function, which is used to obtain model
+ indexes corresponding to children of a given parent item:
+
+ \snippet itemviews/editabletreemodel/treemodel.cpp 5
+
+ In this model, we only return model indexes for child items if the parent
+ index is invalid (corresponding to the root item) or if it has a zero
+ column number.
+
+ We use the custom \l{TreeModel::getItem}{getItem()} function to obtain
+ a \c TreeItem instance that corresponds to the model index supplied, and
+ request its child item that corresponds to the specified row.
+
+ \snippet itemviews/editabletreemodel/treemodel.cpp 6
+
+ Since each item contains information for an entire row of data, we create
+ a model index to uniquely identify it by calling
+ \l{QAbstractItemModel::}{createIndex()} it with the row and column numbers
+ and a pointer to the item. In the \l{TreeModel::data}{data()} function,
+ we will use the item pointer and column number to access the data
+ associated with the model index; in this model, the row number is not
+ needed to identify data.
+
+ \target TreeModel::parent
+ The \c parent() function supplies model indexes for parents of items
+ by finding the corresponding item for a given model index, using its
+ \l{TreeItem::parent}{parent()} function to obtain its parent item,
+ then creating a model index to represent the parent. (See
+ \l{Relating-items-using-model-indexes}{the above diagram}).
+
+ \snippet itemviews/editabletreemodel/treemodel.cpp 7
+
+ Items without parents, including the root item, are handled by returning
+ a null model index. Otherwise, a model index is created and returned as
+ in the \l{TreeModel::index}{index()} function, with a suitable row number,
+ but with a zero column number to be consistent with the scheme used in
+ the \l{TreeModel::index}{index()} implementation.
+
+ \target TreeModel::data
+ \target TreeModel::setupModelData
+
+*/
diff --git a/examples/widgets/doc/elasticnodes.qdoc b/examples/widgets/doc/elasticnodes.qdoc
new file mode 100644
index 0000000000..17f14124f8
--- /dev/null
+++ b/examples/widgets/doc/elasticnodes.qdoc
@@ -0,0 +1,430 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example graphicsview/elasticnodes
+ \title Elastic Nodes Example
+
+ The Elastic Nodes example shows how to implement edges between nodes in a
+ graph, with basic interaction. You can click to drag a node around, and
+ zoom in and out using the mouse wheel or the keyboard. Hitting the space
+ bar will randomize the nodes. The example is also resolution independent;
+ as you zoom in, the graphics remain crisp.
+
+ \image elasticnodes-example.png
+
+ Graphics View provides the QGraphicsScene class for managing and
+ interacting with a large number of custom-made 2D graphical items derived
+ from the QGraphicsItem class, and a QGraphicsView widget for visualizing
+ the items, with support for zooming and rotation.
+
+ This example consists of a \c Node class, an \c Edge class, a \c
+ GraphWidget test, and a \c main function: the \c Node class represents
+ draggable yellow nodes in a grid, the \c Edge class represents the lines
+ between the nodes, the \c GraphWidget class represents the application
+ window, and the \c main() function creates and shows this window, and runs
+ the event loop.
+
+ \section1 Node Class Definition
+
+ The \c Node class serves three purposes:
+
+ \list
+ \li Painting a yellow gradient "ball" in two states: sunken and raised.
+ \li Managing connections to other nodes.
+ \li Calculating forces pulling and pushing the nodes in the grid.
+ \endlist
+
+ Let's start by looking at the \c Node class declaration.
+
+ \snippet graphicsview/elasticnodes/node.h 0
+
+ The \c Node class inherits QGraphicsItem, and reimplements the two
+ mandatory functions \l{QGraphicsItem::boundingRect()}{boundingRect()} and
+ \l{QGraphicsItem::paint()}{paint()} to provide its visual appearance. It
+ also reimplements \l{QGraphicsItem::shape()}{shape()} to ensure its hit
+ area has an elliptic shape (as opposed to the default bounding rectangle).
+
+ For edge management purposes, the node provides a simple API for adding
+ edges to a node, and for listing all connected edges.
+
+ The \l{QGraphicsItem::advance()}{advance()} reimplementation is called
+ whenever the scene's state advances by one step. The calculateForces()
+ function is called to calculate the forces that push and pull on this node
+ and its neighbors.
+
+ The \c Node class also reimplements
+ \l{QGraphicsItem::itemChange()}{itemChange()} to react to state changes (in
+ this case, position changes), and
+ \l{QGraphicsItem::mousePressEvent()}{mousePressEvent()} and
+ \l{QGraphicsItem::mouseReleaseEvent()}{mouseReleaseEvent()} to update the
+ item's visual appearance.
+
+ We will start reviewing the \c Node implementation by looking at its
+ constructor:
+
+ \snippet graphicsview/elasticnodes/node.cpp 0
+
+ In the constructor, we set the
+ \l{QGraphicsItem::ItemIsMovable}{ItemIsMovable} flag to allow the item to
+ move in response to mouse dragging, and
+ \l{QGraphicsItem::ItemSendsGeometryChanges}{ItemSendsGeometryChanges} to
+ enable \l{QGraphicsItem::itemChange()}{itemChange()} notifications for
+ position and transformation changes. We also enable
+ \l{QGraphicsItem::DeviceCoordinateCache}{DeviceCoordinateCache} to speed up
+ rendering performance. To ensure that the nodes are always stacked on top
+ of edges, we finally set the item's Z value to -1.
+
+ \c Node's constructor takes a \c GraphWidget pointer and stores this as a
+ member variable. We will revisit this pointer later on.
+
+ \snippet graphicsview/elasticnodes/node.cpp 1
+
+ The addEdge() function adds the input edge to a list of attached edges. The
+ edge is then adjusted so that the end points for the edge match the
+ positions of the source and destination nodes.
+
+ The edges() function simply returns the list of attached edges.
+
+ \snippet graphicsview/elasticnodes/node.cpp 2
+
+ There are two ways to move a node. The \c calculateForces() function
+ implements the elastic effect that pulls and pushes on nodes in the grid.
+ In addition, the user can directly move one node around with the mouse.
+ Because we do not want the two approaches to operate at the same time on
+ the same node, we start \c calculateForces() by checking if this \c Node is
+ the current mouse grabber item (i.e., QGraphicsScene::mouseGrabberItem()).
+ Because we need to find all neighboring (but not necessarily connected)
+ nodes, we also make sure the item is part of a scene in the first place.
+
+ \snippet graphicsview/elasticnodes/node.cpp 3
+
+ The "elastic" effect comes from an algorithm that applies pushing and
+ pulling forces. The effect is impressive, and surprisingly simple to
+ implement.
+
+ The algorithm has two steps: the first is to calculate the forces that push
+ the nodes apart, and the second is to subtract the forces that pull the
+ nodes together. First we need to find all the nodes in the graph. We call
+ QGraphicsScene::items() to find all items in the scene, and then use
+ qgraphicsitem_cast() to look for \c Node instances.
+
+ We make use of \l{QGraphicsItem::mapFromItem()}{mapFromItem()} to create a
+ temporary vector pointing from this node to each other node, in \l{The
+ Graphics View Coordinate System}{local coordinates}. We use the decomposed
+ components of this vector to determine the direction and strength of force
+ that should apply to the node. The forces accumulate for each node, and are
+ then adjusted so that the closest nodes are given the strongest force, with
+ rapid degradation when distance increases. The sum of all forces is stored
+ in \c xvel (X-velocity) and \c yvel (Y-velocity).
+
+ \snippet graphicsview/elasticnodes/node.cpp 4
+
+ The edges between the nodes represent forces that pull the nodes together.
+ By visiting each edge that is connected to this node, we can use a similar
+ approach as above to find the direction and strength of all pulling forces.
+ These forces are subtracted from \c xvel and \c yvel.
+
+ \snippet graphicsview/elasticnodes/node.cpp 5
+
+ In theory, the sum of pushing and pulling forces should stabilize to
+ precisely 0. In practice, however, they never do. To circumvent errors in
+ numerical precision, we simply force the sum of forces to be 0 when they
+ are less than 0.1.
+
+ \snippet graphicsview/elasticnodes/node.cpp 6
+
+ The final step of \c calculateForces() determines the node's new position.
+ We add the force to the node's current position. We also make sure the new
+ position stays inside of our defined boundaries. We don't actually move the
+ item in this function; that's done in a separate step, from \c advance().
+
+ \snippet graphicsview/elasticnodes/node.cpp 7
+
+ The \c advance() function updates the item's current position. It is called
+ from \c GraphWidget::timerEvent(). If the node's position changed, the
+ function returns true; otherwise false is returned.
+
+ \snippet graphicsview/elasticnodes/node.cpp 8
+
+ The \c Node's bounding rectangle is a 20x20 sized rectangle centered around
+ its origin (0, 0), adjusted by 2 units in all directions to compensate for
+ the node's outline stroke, and by 3 units down and to the right to make
+ room for a simple drop shadow.
+
+ \snippet graphicsview/elasticnodes/node.cpp 9
+
+ The shape is a simple ellipse. This ensures that you must click inside the
+ node's elliptic shape in order to drag it around. You can test this effect
+ by running the example, and zooming far in so that the nodes are very
+ large. Without reimplementing \l{QGraphicsItem::shape()}{shape()}, the
+ item's hit area would be identical to its bounding rectangle (i.e.,
+ rectangular).
+
+ \snippet graphicsview/elasticnodes/node.cpp 10
+
+ This function implements the node's painting. We start by drawing a simple
+ dark gray elliptic drop shadow at (-7, -7), that is, (3, 3) units down and
+ to the right from the top-left corner (-10, -10) of the ellipse.
+
+ We then draw an ellipse with a radial gradient fill. This fill is either
+ Qt::yellow to Qt::darkYellow when raised, or the opposite when sunken. In
+ sunken state we also shift the center and focal point by (3, 3) to
+ emphasize the impression that something has been pushed down.
+
+ Drawing filled ellipses with gradients can be quite slow, especially when
+ using complex gradients such as QRadialGradient. This is why this example
+ uses \l{QGraphicsItem::DeviceCoordinateCache}{DeviceCoordinateCache}, a
+ simple yet effective measure that prevents unnecessary redrawing.
+
+ \snippet graphicsview/elasticnodes/node.cpp 11
+
+ We reimplement \l{QGraphicsItem::itemChange()}{itemChange()} to adjust the
+ position of all connected edges, and to notify the scene that an item has
+ moved (i.e., "something has happened"). This will trigger new force
+ calculations.
+
+ This notification is the only reason why the nodes need to keep a pointer
+ back to the \c GraphWidget. Another approach could be to provide such
+ notification using a signal; in such case, \c Node would need to inherit
+ from QGraphicsObject.
+
+ \snippet graphicsview/elasticnodes/node.cpp 12
+
+ Because we have set the \l{QGraphicsItem::ItemIsMovable}{ItemIsMovable}
+ flag, we don't need to implement the logic that moves the node according to
+ mouse input; this is already provided for us. We still need to reimplement
+ the mouse press and release handlers, though, to update the nodes' visual
+ appearance (i.e., sunken or raised).
+
+ \section1 Edge Class Definition
+
+ The \c Edge class represents the arrow-lines between the nodes in this
+ example. The class is very simple: it maintains a source- and destination
+ node pointer, and provides an \c adjust() function that makes sure the line
+ starts at the position of the source, and ends at the position of the
+ destination. The edges are the only items that change continuously as
+ forces pull and push on the nodes.
+
+ Let's take a look at the class declaration:
+
+ \snippet graphicsview/elasticnodes/edge.h 0
+
+ \c Edge inherits from QGraphicsItem, as it's a simple class that has no use
+ for signals, slots, and properties (compare to QGraphicsObject).
+
+ The constructor takes two node pointers as input. Both pointers are
+ mandatory in this example. We also provide get-functions for each node.
+
+ The \c adjust() function repositions the edge, and the item also implements
+ \l{QGraphicsItem::boundingRect()}{boundingRect()} and
+ \l{QGraphicsItem::paint()}{paint()}.
+
+ We will now review its implementation.
+
+ \snippet graphicsview/elasticnodes/edge.cpp 0
+
+ The \c Edge constructor initializes its \c arrowSize data member to 10 units;
+ this determines the size of the arrow which is drawn in
+ \l{QGraphicsItem::paint()}{paint()}.
+
+ In the constructor body, we call
+ \l{QGraphicsItem::setAcceptedMouseButtons()}{setAcceptedMouseButtons(0)}.
+ This ensures that the edge items are not considered for mouse input at all
+ (i.e., you cannot click the edges). Then, the source and destination
+ pointers are updated, this edge is registered with each node, and we call
+ \c adjust() to update this edge's start end end position.
+
+ \snippet graphicsview/elasticnodes/edge.cpp 1
+
+ The source and destination get-functions simply return the respective
+ pointers.
+
+ \snippet graphicsview/elasticnodes/edge.cpp 2
+
+ In \c adjust(), we define two points: \c sourcePoint, and \c destPoint,
+ pointing at the source and destination nodes' origins respectively. Each
+ point is calculated using \l{The Graphics View Coordinate System}{local
+ coordinates}.
+
+ We want the tip of the edge's arrows to point to the exact outline of the
+ nodes, as opposed to the center of the nodes. To find this point, we first
+ decompose the vector pointing from the center of the source to the center
+ of the destination node into X and Y, and then normalize the components by
+ dividing by the length of the vector. This gives us an X and Y unit delta
+ that, when multiplied by the radius of the node (which is 10), gives us the
+ offset that must be added to one point of the edge, and subtracted from the
+ other.
+
+ If the length of the vector is less than 20 (i.e., if two nodes overlap),
+ then we fix the source and destination pointer at the center of the source
+ node. In practice this case is very hard to reproduce manually, as the
+ forces between the two nodes is then at its maximum.
+
+ It's important to notice that we call
+ \l{QGraphicsItem::prepareGeometryChange()}{prepareGeometryChange()} in this
+ function. The reason is that the variables \c sourcePoint and \c destPoint
+ are used directly when painting, and they are returned from the
+ \l{QGraphicsItem::boundingRect()}{boundingRect()} reimplementation. We must
+ always call
+ \l{QGraphicsItem::prepareGeometryChange()}{prepareGeometryChange()} before
+ changing what \l{QGraphicsItem::boundingRect()}{boundingRect()} returns,
+ and before these variables can be used by
+ \l{QGraphicsItem::paint()}{paint()}, to keep Graphics View's internal
+ bookkeeping clean. It's safest to call this function once, immediately
+ before any such variable is modified.
+
+ \snippet graphicsview/elasticnodes/edge.cpp 3
+
+ The edge's bounding rectangle is defined as the smallest rectangle that
+ includes both the start and the end point of the edge. Because we draw an
+ arrow on each edge, we also need to compensate by adjusting with half the
+ arrow size and half the pen width in all directions. The pen is used to
+ draw the outline of the arrow, and we can assume that half of the outline
+ can be drawn outside of the arrow's area, and half will be drawn inside.
+
+ \snippet graphicsview/elasticnodes/edge.cpp 4
+
+ We start the reimplementation of \l{QGraphicsItem::paint()}{paint()} by
+ checking a few preconditions. Firstly, if either the source or destination
+ node is not set, then we return immediately; there is nothing to draw.
+
+ At the same time, we check if the length of the edge is approximately 0,
+ and if it is, then we also return.
+
+ \snippet graphicsview/elasticnodes/edge.cpp 5
+
+ We draw the line using a pen that has round joins and caps. If you run the
+ example, zoom in and study the edge in detail, you will see that there are
+ no sharp/square edges.
+
+ \snippet graphicsview/elasticnodes/edge.cpp 6
+
+ We proceed to drawing one arrow at each end of the edge. Each arrow is
+ drawn as a polygon with a black fill. The coordinates for the arrow are
+ determined using simple trigonometry.
+
+ \section1 GraphWidget Class Definition
+
+ \c GraphWidget is a subclass of QGraphicsView, which provides the main
+ window with scrollbars.
+
+ \snippet graphicsview/elasticnodes/graphwidget.h 0
+
+ The class provides a basic constructor that initializes the scene, an \c
+ itemMoved() function to notify changes in the scene's node graph, a few
+ event handlers, a reimplementation of
+ \l{QGraphicsView::drawBackground()}{drawBackground()}, and a helper
+ function for scaling the view by using the mouse wheel or keyboard.
+
+ \snippet graphicsview/elasticnodes/graphwidget.cpp 0
+
+ \c GraphicsWidget's constructor creates the scene, and because most items
+ move around most of the time, it sets QGraphicsScene::NoIndex. The scene
+ then gets a fixed \l{QGraphicsScene::sceneRect}{scene rectangle}, and is
+ assigned to the \c GraphWidget view.
+
+ The view enables QGraphicsView::CacheBackground to cache rendering of its
+ static, and somewhat complex, background. Because the graph renders a close
+ collection of small items that all move around, it's unnecessary for
+ Graphics View to waste time finding accurate update regions, so we set the
+ QGraphicsView::BoundingRectViewportUpdate viewport update mode. The default
+ would work fine, but this mode is noticably faster for this example.
+
+ To improve rendering quality, we set QPainter::Antialiasing.
+
+ The transformation anchor decides how the view should scroll when you
+ transform the view, or in our case, when we zoom in or out. We have chosen
+ QGraphicsView::AnchorUnderMouse, which centers the view on the point under
+ the mouse cursor. This makes it easy to zoom towards a point in the scene
+ by moving the mouse over it, and then rolling the mouse wheel.
+
+ Finally we give the window a minimum size that matches the scene's default
+ size, and set a suitable window title.
+
+ \snippet graphicsview/elasticnodes/graphwidget.cpp 1
+
+ The last part of the constructor creates the grid of nodes and edges, and
+ gives each node an initial position.
+
+ \snippet graphicsview/elasticnodes/graphwidget.cpp 2
+
+ \c GraphWidget is notified of node movement through this \c itemMoved()
+ function. Its job is simply to restart the main timer in case it's not
+ running already. The timer is designed to stop when the graph stabilizes,
+ and start once it's unstable again.
+
+ \snippet graphicsview/elasticnodes/graphwidget.cpp 3
+
+ This is \c GraphWidget's key event handler. The arrow keys move the center
+ node around, the '+' and '-' keys zoom in and out by calling \c
+ scaleView(), and the enter and space keys randomize the positions of the
+ nodes. All other key events (e.g., page up and page down) are handled by
+ QGraphicsView's default implementation.
+
+ \snippet graphicsview/elasticnodes/graphwidget.cpp 4
+
+ The timer event handler's job is to run the whole force calculation
+ machinery as a smooth animation. Each time the timer is triggered, the
+ handler will find all nodes in the scene, and call \c
+ Node::calculateForces() on each node, one at a time. Then, in a final step
+ it will call \c Node::advance() to move all nodes to their new positions.
+ By checking the return value of \c advance(), we can decide if the grid
+ stabilized (i.e., no nodes moved). If so, we can stop the timer.
+
+ \snippet graphicsview/elasticnodes/graphwidget.cpp 5
+
+ In the wheel event handler, we convert the mouse wheel delta to a scale
+ factor, and pass this factor to \c scaleView(). This approach takes into
+ account the speed that the wheel is rolled. The faster you roll the mouse
+ wheel, the faster the view will zoom.
+
+ \snippet graphicsview/elasticnodes/graphwidget.cpp 6
+
+ The view's background is rendered in a reimplementation of
+ QGraphicsView::drawBackground(). We draw a large rectangle filled with a
+ linear gradient, add a drop shadow, and then render text on top. The text
+ is rendered twice for a simple drop-shadow effect.
+
+ This background rendering is quite expensive; this is why the view enables
+ QGraphicsView::CacheBackground.
+
+ \snippet graphicsview/elasticnodes/graphwidget.cpp 7
+
+ The \c scaleView() helper function checks that the scale factor stays
+ within certain limits (i.e., you cannot zoom too far in nor too far out),
+ and then applies this scale to the view.
+
+ \section1 The main() Function
+
+ In contrast to the complexity of the rest of this example, the \c main()
+ function is very simple: We create a QApplication instance, seed the
+ randomizer using qsrand(), and then create and show an instance of \c
+ GraphWidget. Because all nodes in the grid are moved initially, the \c
+ GraphWidget timer will start immediately after control has returned to the
+ event loop.
+*/
diff --git a/examples/widgets/doc/elidedlabel.qdoc b/examples/widgets/doc/elidedlabel.qdoc
new file mode 100644
index 0000000000..2ce469d85f
--- /dev/null
+++ b/examples/widgets/doc/elidedlabel.qdoc
@@ -0,0 +1,162 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/elidedlabel
+ \group all-examples
+ \title Elided Label Example
+
+ This example creates a widget similar to QLabel, that elides the last
+ visible line, if the text is too long to fit the widget's geometry.
+
+ \image elidedlabel-example.png Elided Label example on XPressMusic 5800
+
+ When text of varying length has to be displayed in a uniformly sized
+ area, for instance within a list or grid view where all list items have the
+ same size, it can be useful to give the user a visual clue when not all
+ text is visible. QLabel can elide text that doesn't fit within it, but only
+ in one line. The \c ElidedLabel widget shown in this example word wraps its
+ text by its width, and elides the last visible line if some text is left
+ out. \c TestWidget gives control to the features of \c ElidedWidget and
+ forms the example application.
+
+
+ \section1 ElidedLabel Class Definition
+
+ Like QLabel, \c ElidedLabel inherits from QFrame. Here's the definition of
+ the \c ElidedLabel class:
+
+
+ \snippet widgets/elidedlabel/elidedlabel.h 0
+
+ The \c isElided property depends the font, text content and geometry of the
+ widget. Whenever any of these change, the \c elisionChanged() signal might
+ trigger. We cache the current elision value in \c elided, so that it
+ doesn't have to be recomputed every time it's asked for.
+
+
+ \section1 ElidedLabel Class Implementation
+
+ Except for initializing the member variables, the constructor sets the size
+ policy to be horizontally expanding, since it's meant to fill the width of
+ its container and grow vertically.
+
+ \snippet widgets/elidedlabel/elidedlabel.cpp 0
+
+ Changing the \c content require a repaint of the widget.
+
+ \snippet widgets/elidedlabel/elidedlabel.cpp 1
+
+ QTextLayout is used in the \c paintEvent() to divide the \c content into
+ lines, that wrap on word boundaries. Each line, except the last visible
+ one, is drawn \c lineSpacing pixels below the previous one. The \c draw()
+ method of QTextLine will draw the line using the coordinate point as the
+ top left corner.
+
+ \snippet widgets/elidedlabel/elidedlabel.cpp 2
+
+ Unfortunately, QTextLayout does not elide text, so the last visible line
+ has to be treated differently. This last line is elided if it is too wide.
+ The \c drawText() method of QPainter draws the text starting from the base
+ line, which is \c ascecnt() pixels below the last drawn line.
+
+ Finally, one more line is created to see if everything fit on this line.
+
+ \snippet widgets/elidedlabel/elidedlabel.cpp 3
+
+ If the text was elided and wasn't before or vice versa, cache it in
+ \c elided and emit the change.
+
+ \snippet widgets/elidedlabel/elidedlabel.cpp 4
+
+
+ \section1 TestWidget Class Definition
+
+ \c TestWidget is a QWidget and is the main window of the example. It
+ contains an \c ElidedLabel which can be resized with two QSlider widgets.
+
+ \snippet widgets/elidedlabel/testwidget.h 0
+
+ \section1 TestWidget Class Implementation
+
+ The constructor initializes the whole widget. Strings of different length
+ are stored in \c textSamples. The user is able to switch between these.
+
+ \snippet widgets/elidedlabel/testwidget.cpp 0
+
+ An \c ElidedLabel is created to contain the first of the sample strings.
+ The frame is made visible to make it easier to see the actual size of the
+ widget.
+
+ \snippet widgets/elidedlabel/testwidget.cpp 1
+
+ The buttons and the elision label are created. By connecting the
+ \c elisionChanged() signal to the \c setVisible() slot of the \c label,
+ it will act as an indicator to when the text is elided or not. This signal
+ could, for instance, be used to make a "More" button visible, or similar.
+
+ \snippet widgets/elidedlabel/testwidget.cpp 2
+
+ The \c widthSlider and \c heightSlider specify the size of the
+ \c elidedText. Since the y-axis is inverted, the \c heightSlider has to be
+ inverted to act appropriately.
+
+ \snippet widgets/elidedlabel/testwidget.cpp 3
+
+ The components are all stored in a QGridLayout, which is made the layout of
+ the \c TestWidget.
+
+ \snippet widgets/elidedlabel/testwidget.cpp 4
+
+ On the Maemo platform, windows are stuck in landscape mode by default. With
+ this attribute set, the window manager is aware that this window can be
+ rotated.
+
+ \snippet widgets/elidedlabel/testwidget.cpp 5
+
+ The \c widthSlider and \c heightSlider have the exact same length as the
+ dimensions of the \c elidedText. The maximum value for both of them is
+ thus their lengths, and each tick indicates one pixel.
+
+ \snippet widgets/elidedlabel/testwidget.cpp 6
+
+ The \c switchText() slot simply cycles through all the available sample
+ texts.
+
+ \snippet widgets/elidedlabel/testwidget.cpp 7
+
+ These slots set the width and height of the \c elided text, in response to
+ changes in the sliders.
+
+ \section1 The \c main() Function
+
+ The \c main() function creates an instance of \c TestWidget fullscreen and
+ enters the message loop.
+
+ \snippet widgets/elidedlabel/main.cpp 0
+*/
+
diff --git a/examples/widgets/doc/embeddeddialogs.qdoc b/examples/widgets/doc/embeddeddialogs.qdoc
new file mode 100644
index 0000000000..24b3abdb37
--- /dev/null
+++ b/examples/widgets/doc/embeddeddialogs.qdoc
@@ -0,0 +1,37 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example graphicsview/embeddeddialogs
+ \title Embedded Dialogs
+
+ This example shows how to embed standard dialogs into
+ Graphics View. It also shows how you can customize the
+ proxy class and add window shadows.
+
+ \image embeddeddialogs-demo.png
+*/
diff --git a/examples/widgets/doc/eventtransitions.qdoc b/examples/widgets/doc/eventtransitions.qdoc
new file mode 100644
index 0000000000..ef3f657c3d
--- /dev/null
+++ b/examples/widgets/doc/eventtransitions.qdoc
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \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 statemachine/eventtransitions/main.cpp 0
+
+ The \c Window class's constructors begins by creating a button.
+
+ \snippet 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 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 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 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 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 statemachine/eventtransitions/main.cpp 6
+
+ The main() function constructs a Window object and shows it.
+
+*/
diff --git a/examples/widgets/doc/extension.qdoc b/examples/widgets/doc/extension.qdoc
new file mode 100644
index 0000000000..040d5d38d9
--- /dev/null
+++ b/examples/widgets/doc/extension.qdoc
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example dialogs/extension
+ \title Extension Example
+
+ The Extension example shows how to add an extension to a QDialog
+ using the QAbstractButton::toggled() signal and the
+ QWidget::setVisible() slot.
+
+ \image extension-example.png Screenshot of the Extension example
+
+ The Extension application is a dialog that allows the user to
+ perform a simple search as well as a more advanced search.
+
+ The simple search has two options: \uicontrol {Match case} and \uicontrol
+ {Search from start}. The advanced search options include the
+ possibilities to search for \uicontrol {Whole words}, \uicontrol {Search
+ backward} and \uicontrol {Search selection}. Only the simple search is
+ visible when the application starts. The advanced search options
+ are located in the application's extension part, and can be made
+ visible by pressing the \uicontrol More button:
+
+ \image extension_more.png Screenshot of the Extension example
+
+ \section1 FindDialog Class Definition
+
+ The \c FindDialog class inherits QDialog. The QDialog class is the
+ base class of dialog windows. A dialog window is a top-level
+ window mostly used for short-term tasks and brief communications
+ with the user.
+
+ \snippet dialogs/extension/finddialog.h 0
+
+ The \c FindDialog widget is the main application widget, and
+ displays the application's search options and controlling
+ buttons.
+
+ In addition to a constructor, we declare the several child
+ widgets: We need a QLineEdit with an associated QLabel to let the
+ user type a word to search for, we need several \l
+ {QCheckBox}{QCheckBox}es to facilitate the search options, and we
+ need three \l {QPushButton}{QPushButton}s: the \uicontrol Find button to
+ start a search and the \uicontrol More button to enable an advanced search.
+ Finally, we need a QWidget representing the application's extension
+ part.
+
+ \section1 FindDialog Class Implementation
+
+ In the constructor we first create the standard child widgets for
+ the simple search: the QLineEdit with the associated QLabel, two
+ of the \l {QCheckBox}{QCheckBox}es and all the \l
+ {QPushButton}{QPushButton}s.
+
+ \snippet dialogs/extension/finddialog.cpp 0
+
+ We give the options and buttons a shortcut key using the &
+ character. In the \uicontrol {Find what} option's case, we also need to
+ use the QLabel::setBuddy() function to make the shortcut key work
+ as expected; then, when the user presses the shortcut key
+ indicated by the label, the keyboard focus is transferred to the
+ label's buddy widget, the QLineEdit.
+
+ We set the \uicontrol Find button's default property to true, using the
+ QPushButton::setDefault() function. Then the push button will be
+ pressed if the user presses the Enter (or Return) key. Note that a
+ QDialog can only have one default button.
+
+ \snippet dialogs/extension/finddialog.cpp 2
+
+ Then we create the extension widget, and the \l
+ {QCheckBox}{QCheckBox}es associated with the advanced search
+ options.
+
+ \snippet dialogs/extension/finddialog.cpp 3
+
+ Now that the extension widget is created, we can connect the \uicontrol
+ More button's \l{QAbstractButton::toggled()}{toggled()} signal to
+ the extension widget's \l{QWidget::setVisible()}{setVisible()} slot.
+
+ The QAbstractButton::toggled() signal is emitted whenever a
+ checkable button changes its state. The signal's argument is true
+ if the button is checked, or false if the button is unchecked. The
+ QWidget::setVisible() slot sets the widget's visible status. If
+ the status is true the widget is shown, otherwise the widget is
+ hidden.
+
+ Since we made the \uicontrol More button checkable when we created it,
+ the connection makes sure that the extension widget is shown
+ depending on the state of \uicontrol More button.
+
+ We also put the check boxes associated with the advanced
+ search options into a layout we install on the extension widget.
+
+ \snippet dialogs/extension/finddialog.cpp 4
+
+ Before we create the main layout, we create several child layouts
+ for the widgets: First we align the QLabel and its buddy, the
+ QLineEdit, using a QHBoxLayout. Then we vertically align the
+ QLabel and QLineEdit with the check boxes associated with the
+ simple search, using a QVBoxLayout. We also create a QVBoxLayout
+ for the buttons. In the end we lay out the two latter layouts and
+ the extension widget using a QGridLayout.
+
+ \snippet dialogs/extension/finddialog.cpp 5
+
+ Finally, we hide the extension widget using the QWidget::hide()
+ function, making the application only show the simple search
+ options when it starts. When the user wants to access the advanced
+ search options, the dialog only needs to change the visibility of
+ the extension widget. Qt's layout management takes care of the
+ dialog's appearance.
+*/
diff --git a/examples/widgets/doc/factorial.qdoc b/examples/widgets/doc/factorial.qdoc
new file mode 100644
index 0000000000..82ab5da536
--- /dev/null
+++ b/examples/widgets/doc/factorial.qdoc
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \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:
+
+ \image 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 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 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 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 statemachine/factorial/main.cpp 3
+
+ The application's main() function first creates the application object, a
+ Factorial object and a state machine.
+
+ \snippet 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 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 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/examples/widgets/doc/fademessage.qdoc b/examples/widgets/doc/fademessage.qdoc
new file mode 100644
index 0000000000..48f98c03ad
--- /dev/null
+++ b/examples/widgets/doc/fademessage.qdoc
@@ -0,0 +1,37 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example effects/fademessage
+ \title Fade Message Effect Example
+
+ \div { style="text-align: center"}
+ \inlineimage fademessageeffect-example.png
+ \inlineimage fademessageeffect-example-faded.png
+ \enddiv
+
+*/
diff --git a/examples/widgets/doc/fetchmore.qdoc b/examples/widgets/doc/fetchmore.qdoc
new file mode 100644
index 0000000000..7ea0b30edf
--- /dev/null
+++ b/examples/widgets/doc/fetchmore.qdoc
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/fetchmore
+ \title Fetch More Example
+
+ The Fetch More example shows how two add items to an item view
+ model on demand.
+
+ \image fetchmore-example.png
+
+ The user of the example can enter a directory in the \uicontrol
+ Directory line edit. The contents of the directory will
+ be listed in the list view below.
+
+ When you have large - or perhaps even infinite - data sets, you
+ will need to add items to the model in batches, and preferably only
+ when the items are needed by the view (i.e., when they are visible
+ in the view).
+
+ In this example, we implement \c FileListModel - an item view
+ model containing the entries of a directory. We also have \c
+ Window, which sets up the GUI and feeds the model with
+ directories.
+
+ Let's take a tour of \c {FileListModel}'s code.
+
+ \section1 FileListModel Class Definition
+
+ The \c FileListModel inherits QAbstractListModel and contains the
+ contents of a directory. It will add items to itself only when
+ requested to do so by the view.
+
+ \snippet itemviews/fetchmore/filelistmodel.h 0
+
+ The secret lies in the reimplementation of
+ \l{QAbstractItemModel::}{fetchMore()} and
+ \l{QAbstractItemModel::}{canFetchMore()} from QAbstractItemModel.
+ These functions are called by the item view when it needs more
+ items.
+
+ The \c setDirPath() function sets the directory the model will
+ work on. We emit \c numberPopulated() each time we add a batch of
+ items to the model.
+
+ We keep all directory entries in \c fileList. \c fileCount is the
+ number of items that have been added to the model.
+
+ \section1 FileListModel Class Implementation
+
+ We start by checking out the \c setDirPath().
+
+ \snippet itemviews/fetchmore/filelistmodel.cpp 0
+
+ We use a QDir to get the contents of the directory. We need to
+ inform QAbstractItemModel that we want to remove all items - if
+ any - from the model.
+
+ \snippet itemviews/fetchmore/filelistmodel.cpp 1
+
+ The \c canFetchMore() function is called by the view when it needs
+ more items. We return true if there still are entries that we have
+ not added to the model; otherwise, we return false.
+
+ And now, the \c fetchMore() function itself:
+
+ \snippet itemviews/fetchmore/filelistmodel.cpp 2
+
+ We first calculate the number of items to fetch.
+ \l{QAbstractItemModel::}{beginInsertRows()} and
+ \l{QAbstractItemModel::}{endInsertRows()} are mandatory for
+ QAbstractItemModel to keep up with the row insertions. Finally, we
+ emit \c numberPopulated(), which is picked up by \c Window.
+
+ To complete the tour, we also look at \c rowCount() and \c data().
+
+ \snippet itemviews/fetchmore/filelistmodel.cpp 4
+
+ Notice that the row count is only the items we have added so far,
+ i.e., not the number of entries in the directory.
+
+ In \c data(), we return the appropriate entry from the \c
+ fileList. We also separate the batches with a different background
+ color.
+*/
+
diff --git a/examples/widgets/doc/findfiles.qdoc b/examples/widgets/doc/findfiles.qdoc
new file mode 100644
index 0000000000..594d57472c
--- /dev/null
+++ b/examples/widgets/doc/findfiles.qdoc
@@ -0,0 +1,249 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example dialogs/findfiles
+ \title Find Files Example
+
+ The Find Files example shows how to use QProgressDialog to provide
+ feedback on the progress of a slow operation. The example also
+ shows how to use QFileDialog to facilitate browsing, how to use
+ QTextStream's streaming operators to read a file, and how to use
+ QTableWidget to provide standard table display facilities for
+ applications. In addition, files can be opened using the
+ QDesktopServices class.
+
+ \image findfiles-example.png Screenshot of the Find Files example
+
+ With the Find Files application the user can search for files in a
+ specified directory, matching a specified file name (using wild
+ cards if appropriate) and containing a specified text.
+
+ The user is provided with a \uicontrol Browse option, and the result of
+ the search is displayed in a table with the names of the files
+ found and their sizes. In addition the application provides a
+ total count of the files found.
+
+ \section1 Window Class Definition
+
+ The \c Window class inherits QWidget, and is the main application
+ widget. It shows the search options, and displays the search
+ results.
+
+ \snippet dialogs/findfiles/window.h 0
+
+ We need two private slots: The \c browse() slot is called whenever
+ the user wants to browse for a directory to search in, and the \c
+ find() slot is called whenever the user requests a search to be
+ performed by pressing the \uicontrol Find button.
+
+ In addition we declare several private functions: We use the \c
+ findFiles() function to search for files matching the user's
+ specifications, we call the \c showFiles() function to display the
+ results, and we use \c createButton(), \c createComboBox() and \c
+ createFilesTable() when we are constructing the widget.
+
+ \section1 Window Class Implementation
+
+ In the constructor we first create the application's widgets.
+
+ \snippet dialogs/findfiles/window.cpp 0
+
+ We create the application's buttons using the private \c
+ createButton() function. Then we create the comboboxes associated
+ with the search specifications, using the private \c
+ createComboBox() function. We also create the application's labels
+ before we use the private \c createFilesTable() function to create
+ the table displaying the search results.
+
+ \snippet dialogs/findfiles/window.cpp 1
+
+ Then we add all the widgets to a main layout using QGridLayout. We
+ have, however, put the \c Find and \c Quit buttons and a
+ stretchable space in a separate QHBoxLayout first, to make the
+ buttons appear in the \c Window widget's bottom right corner.
+
+ \snippet dialogs/findfiles/window.cpp 2
+
+ The \c browse() slot presents a file dialog to the user, using the
+ QFileDialog class. QFileDialog enables a user to traverse the file
+ system in order to select one or many files or a directory. The
+ easiest way to create a QFileDialog is to use the convenience
+ static functions.
+
+ Here we use the static QFileDialog::getExistingDirectory()
+ function which returns an existing directory selected by the
+ user. Then we display the directory in the directory combobox
+ using the QComboBox::addItem() function, and updates the current
+ index.
+
+ QComboBox::addItem() adds an item to the combobox with the given
+ text (if it is not already present in the list), and containing
+ the specified userData. The item is appended to the list of
+ existing items.
+
+ \snippet dialogs/findfiles/window.cpp 3
+
+ The \c find() slot is called whenever the user requests a new
+ search by pressing the \uicontrol Find button.
+
+ First we eliminate any previous search results by setting the
+ table widgets row count to zero. Then we retrieve the
+ specified file name, text and directory path from the respective
+ comboboxes.
+
+ \snippet dialogs/findfiles/window.cpp 4
+
+ We use the directory's path to create a QDir; the QDir class
+ provides access to directory structures and their contents. We
+ create a list of the files (contained in the newly created QDir)
+ that match the specified file name. If the file name is empty
+ the list will contain all the files in the directory.
+
+ Then we search through all the files in the list, using the private
+ \c findFiles() function, eliminating the ones that don't contain
+ the specified text. And finally, we display the results using the
+ private \c showFiles() function.
+
+ If the user didn't specify any text, there is no reason to search
+ through the files, and we display the results immediately.
+
+ \image findfiles_progress_dialog.png Screenshot of the Progress Dialog
+
+ \snippet dialogs/findfiles/window.cpp 5
+
+ In the private \c findFiles() function we search through a list of
+ files, looking for the ones that contain a specified text. This
+ can be a very slow operation depending on the number of files as
+ well as their sizes. In case there are a large number of files, or
+ there exists some large files on the list, we provide a
+ QProgressDialog.
+
+ The QProgressDialog class provides feedback on the progress of a
+ slow operation. It is used to give the user an indication of how
+ long an operation is going to take, and to demonstrate that the
+ application has not frozen. It can also give the user an
+ opportunity to abort the operation.
+
+ \snippet dialogs/findfiles/window.cpp 6
+
+ We run through the files, one at a time, and for each file we
+ update the QProgressDialog value. This property holds the current
+ amount of progress made. We also update the progress dialog's
+ label.
+
+ Then we call the QCoreApplication::processEvents() function using
+ the QApplication object. In this way we interleave the display of
+ the progress made with the process of searching through the files
+ so the application doesn't appear to be frozen.
+
+ The QApplication class manages the GUI application's control flow
+ and main settings. It contains the main event loop, where all
+ events from the window system and other sources are processed and
+ dispatched. QApplication inherits QCoreApplication. The
+ QCoreApplication::processEvents() function processes all pending
+ events according to the specified QEventLoop::ProcessEventFlags
+ until there are no more events to process. The default flags are
+ QEventLoop::AllEvents.
+
+ \snippet dialogs/findfiles/window.cpp 7
+
+ After updating the QProgressDialog, we create a QFile using the
+ QDir::absoluteFilePath() function which returns the absolute path
+ name of a file in the directory. We open the file in read-only
+ mode, and read one line at a time using QTextStream.
+
+ The QTextStream class provides a convenient interface for reading
+ and writing text. Using QTextStream's streaming operators, you can
+ conveniently read and write words, lines and numbers.
+
+ For each line we read we check if the QProgressDialog has been
+ canceled. If it has, we abort the operation, otherwise we check if
+ the line contains the specified text. When we find the text within
+ one of the files, we add the file's name to a list of found files
+ that contain the specified text, and start searching a new file.
+
+ Finally, we return the list of the files found.
+
+ \snippet dialogs/findfiles/window.cpp 8
+
+ Both the \c findFiles() and \c showFiles() functions are called from
+ the \c find() slot. In the \c showFiles() function we run through
+ the provided list of file names, adding each file name to the
+ first column in the table widget and retrieving the file's size using
+ QFile and QFileInfo for the second column.
+
+ We also update the total number of files found.
+
+ \snippet dialogs/findfiles/window.cpp 9
+
+ The private \c createButton() function is called from the
+ constructor. We create a QPushButton with the provided text,
+ connect it to the provided slot, and return a pointer to the
+ button.
+
+ \snippet dialogs/findfiles/window.cpp 10
+
+ The private \c createComboBox() function is also called from the
+ contructor. We create a QComboBox with the given text, and make it
+ editable.
+
+ When the user enters a new string in an editable combobox, the
+ widget may or may not insert it, and it can insert it in several
+ locations, depending on the QComboBox::InsertPolicy. The default
+ policy is is QComboBox::InsertAtBottom.
+
+ Then we add the provided text to the combobox, and specify the
+ widget's size policies, before we return a pointer to the
+ combobox.
+
+ \snippet dialogs/findfiles/window.cpp 11
+
+ The private \c createFilesTable() function is called from the
+ constructor. In this function we create the QTableWidget that
+ will display the search results. We set its horizontal headers and
+ their resize mode.
+
+ QTableWidget inherits QTableView which provides a default
+ model/view implementation of a table view. The
+ QTableView::horizontalHeader() function returns the table view's
+ horizontal header as a QHeaderView. The QHeaderView class provides
+ a header row or header column for item views, and the
+ QHeaderView::setResizeMode() function sets the constraints on how
+ the section in the header can be resized.
+
+ Finally, we hide the QTableWidget's vertical headers using the
+ QWidget::hide() function, and remove the default grid drawn for
+ the table using the QTableView::setShowGrid() function.
+
+ \snippet dialogs/findfiles/window.cpp 12
+
+ The \c openFileOfItem() slot is invoked when the user double
+ clicks on a cell in the table. The QDesktopServices::openUrl()
+ knows how to open a file given the file name.
+*/
+
diff --git a/examples/widgets/doc/flowlayout.qdoc b/examples/widgets/doc/flowlayout.qdoc
new file mode 100644
index 0000000000..b08b2283aa
--- /dev/null
+++ b/examples/widgets/doc/flowlayout.qdoc
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example layouts/flowlayout
+ \title Flow Layout Example
+
+ The Flow Layout example demonstrates a custom layout that arranges child
+ widgets from left to right and top to bottom in a top-level widget.
+
+ \image flowlayout-example.png Screenshot of the Flow Layout example
+
+ The items are first laid out horizontally and then vertically when each line
+ in the layout runs out of space.
+
+ The Flowlayout class mainly uses QLayout and QWidgetItem, while the
+ Window uses QWidget and QLabel. We will only document the definition
+ and implementation of \c FlowLayout below.
+
+ \section1 FlowLayout Class Definition
+
+ The \c FlowLayout class inherits QLayout. It is a custom layout class
+ that arranges its child widgets horizontally and vertically.
+
+ \snippet layouts/flowlayout/flowlayout.h 0
+
+ We reimplement functions inherited from QLayout. These functions add items to
+ the layout and handle their orientation and geometry.
+
+ We also declare two private methods, \c doLayout() and \c smartSpacing().
+ \c doLayout() lays out the layout items, while the \c
+ smartSpacing() function calculates the spacing between them.
+
+ \section1 FlowLayout Class Implementation
+
+ We start off by looking at the constructor:
+
+ \snippet layouts/flowlayout/flowlayout.cpp 1
+
+ In the constructor we call \c setContentsMargins() to set the left, top,
+ right and bottom margin. By default, QLayout uses values provided by
+ the current style (see QStyle::PixelMetric).
+
+ \snippet layouts/flowlayout/flowlayout.cpp 2
+
+ In this example we reimplement \c addItem(), which is a pure virtual
+ function. When using \c addItem() the ownership of the layout items is
+ transferred to the layout, and it is therefore the layout's
+ responsibility to delete them.
+
+ \snippet layouts/flowlayout/flowlayout.cpp 3
+
+ \c addItem() is implemented to add items to the layout.
+
+ \snippet layouts/flowlayout/flowlayout.cpp 4
+
+ We implement \c horizontalSpacing() and \c verticalSpacing() to get
+ hold of the spacing between the widgets inside the layout. If the value
+ is less than or equal to 0, this value will be used. If not,
+ \c smartSpacing() will be called to calculate the spacing.
+
+ \snippet layouts/flowlayout/flowlayout.cpp 5
+
+ We then implement \c count() to return the number of items in the
+ layout. To navigate the list of items we use \c itemAt() and
+ takeAt() to remove and return items from the list. If an item is
+ removed, the remaining items will be renumbered. All three
+ functions are pure virtual functions from QLayout.
+
+ \snippet layouts/flowlayout/flowlayout.cpp 6
+
+ \c expandingDirections() returns the \l{Qt::Orientation}s in which the
+ layout can make use of more space than its \c sizeHint().
+
+ \snippet layouts/flowlayout/flowlayout.cpp 7
+
+ To adjust to widgets of which height is dependent on width, we implement \c
+ heightForWidth(). The function \c hasHeightForWidth() is used to test for this
+ dependency, and \c heightForWidth() passes the width on to \c doLayout() which
+ in turn uses the width as an argument for the layout rect, i.e., the bounds in
+ which the items are laid out. This rect does not include the layout margin().
+
+ \snippet layouts/flowlayout/flowlayout.cpp 8
+
+ \c setGeometry() is normally used to do the actual layout, i.e., calculate
+ the geometry of the layout's items. In this example, it calls \c doLayout()
+ and passes the layout rect.
+
+ \c sizeHint() returns the preferred size of the layout and \c minimumSize()
+ returns the minimum size of the layout.
+
+ \snippet layouts/flowlayout/flowlayout.cpp 9
+
+ \c doLayout() handles the layout if \c horizontalSpacing() or \c
+ verticalSpacing() don't return the default value. It uses
+ \c getContentsMargins() to calculate the area available to the
+ layout items.
+
+ \snippet layouts/flowlayout/flowlayout.cpp 10
+
+ It then sets the proper amount of spacing for each widget in the
+ layout, based on the current style.
+
+ \snippet layouts/flowlayout/flowlayout.cpp 11
+
+ The position of each item in the layout is then calculated by
+ adding the items width and the line height to the initial x and y
+ coordinates. This in turn lets us find out whether the next item
+ will fit on the current line or if it must be moved down to the next.
+ We also find the height of the current line based on the widgets height.
+
+ \snippet layouts/flowlayout/flowlayout.cpp 12
+
+ \c smartSpacing() is designed to get the default spacing for either
+ the top-level layouts or the sublayouts. The default spacing for
+ top-level layouts, when the parent is a QWidget, will be determined
+ by querying the style. The default spacing for sublayouts, when
+ the parent is a QLayout, will be determined by querying the spacing
+ of the parent layout.
+
+*/
diff --git a/examples/widgets/doc/fontsampler.qdoc b/examples/widgets/doc/fontsampler.qdoc
new file mode 100644
index 0000000000..8d7f0e0460
--- /dev/null
+++ b/examples/widgets/doc/fontsampler.qdoc
@@ -0,0 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example painting/fontsampler
+ \title Font Sampler Example
+
+ The Font Sampler example shows how to preview and print multi-page documents.
+
+ \image fontsampler-example.png
+*/
diff --git a/examples/widgets/doc/frozencolumn.qdoc b/examples/widgets/doc/frozencolumn.qdoc
new file mode 100644
index 0000000000..c65ce1d524
--- /dev/null
+++ b/examples/widgets/doc/frozencolumn.qdoc
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/frozencolumn
+ \title Frozen Column Example
+
+ This example demonstrates how to freeze a column within a QTableView.
+
+ \image frozencolumn-example.png "Screenshot of the example"
+
+ We use Qt's model/view framework to implement a table with its first
+ column frozen. This technique can be aplied to several columns or rows,
+ as long as they are on the edge of the table.
+
+ The model/view framework allows for one model to be displayed in different
+ ways using multiple views. For this example, we use two views on the same
+ model - two \l {QTableView}{table views} sharing one model. The frozen
+ column is a child of the main tableview, and we provide the desired visual
+ effect using an overlay technique which will be described step by step in
+ the coming sections.
+
+ \image frozencolumn-tableview.png
+
+
+ \section1 FreezeTableWidget Class Definition
+
+ The \c FreezeTableWidget class has a constructor and a destructor. Also, it
+ has two private members: the table view that we will use as an overlay, and
+ the shared model for both table views. Two slots are added to help keep the
+ section sizes in sync, as well as a function to readjust the frozen
+ column's geometry. In addition, we reimplement two functions:
+ \l{QAbstractItemView::}{resizeEvent()} and \l{QTableView::}{moveCursor()}.
+
+ \snippet itemviews/frozencolumn/freezetablewidget.h Widget definition
+
+ \note QAbstractItemView is \l{QTableView}'s ancestor.
+
+
+ \section1 FreezeTableWidget Class Implementation
+
+ The constructor takes \a model as an argument and creates a table view that
+ we will use to display the frozen column. Then, within the constructor, we
+ invoke the \c init() function to set up the frozen column. Finally, we
+ connect the \l{QHeaderView::sectionResized()} signals (for horizontal and
+ vertical headers) to the appropriate slots. This ensures that our frozen
+ column's sections are in sync with the headers. We also connect the
+ vertical scrollbars together so that the frozen column scrolls vertically
+ with the rest of our table.
+
+ \snippet itemviews/frozencolumn/freezetablewidget.cpp constructor
+
+
+ In the \c init() function, we ensure that the overlay table view
+ responsible for displaying the frozen column, is set up properly. This
+ means that this table view, \c frozenTableView, has to have the same model
+ as the main table view. However, the difference here is: \c frozenTableView's
+ only visible column is its first column; we hide the others using
+ \l{QTableView::}{setColumnHidden()}
+
+ \snippet itemviews/frozencolumn/freezetablewidget.cpp init part1
+
+
+ In terms of the frozen column's z-order, we stack it on top of the
+ viewport. This is achieved by calling \l{QWidget::}{stackUnder()} on the
+ viewport. For appearance's sake, we prevent the column from stealing focus
+ from the main tableview. Also, we make sure that both views share the same
+ selection model, so only one cell can be selected at a time. A few other
+ tweaks are done to make our application look good and behave consistently
+ with the main tableview. Note that we called \c updateFrozenTableGeometry()
+ to make the column occupy the correct spot.
+
+ \snippet itemviews/frozencolumn/freezetablewidget.cpp init part2
+
+ When you resize the frozen column, the same column on the main table view
+ must resize accordingly, to provide seamless integration. This is
+ accomplished by getting the new size of the column from the \c newSize
+ value from the \l{QHeaderView::}{sectionResized()} signal, emitted by both
+ the horizontal and vertical header.
+
+ \snippet itemviews/frozencolumn/freezetablewidget.cpp sections
+
+ Since the width of the frozen column is modified, we adjust the geometry of
+ the widget accordingly by invoking \c updateFrozenTableGeometry(). This
+ function is further explained below.
+
+ In our reimplementation of QTableView::resizeEvent(), we call
+ \c updateFrozenTableGeometry() after invoking the base class
+ implementation.
+
+ \snippet itemviews/frozencolumn/freezetablewidget.cpp resize
+
+ When navigating around the table with the keyboard, we need to ensure that
+ the current selection does not disappear behind the frozen column. To
+ synchronize this, we reimplement QTableView::moveCursor() and adjust the
+ scrollbar positions if needed, after calling the base class implementation.
+
+ \snippet itemviews/frozencolumn/freezetablewidget.cpp navigate
+
+ The frozen column's geometry calculation is based on the geometry of the
+ table underneath, so it always appears in the right place. Using the
+ QFrame::frameWidth() function helps to calculate this geometry correctly,
+ no matter which style is used. We rely on the geometry of the viewport and
+ headers to set the boundaries for the frozen column.
+
+ \snippet itemviews/frozencolumn/freezetablewidget.cpp geometry
+
+*/
+
diff --git a/examples/widgets/doc/gradients.qdoc b/examples/widgets/doc/gradients.qdoc
new file mode 100644
index 0000000000..75f78b56ea
--- /dev/null
+++ b/examples/widgets/doc/gradients.qdoc
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example painting/gradients
+ \title Gradients
+
+ In this example we show the various types of gradients that can
+ be used in Qt.
+
+ \image gradients-demo.png
+
+ There are three types of gradients:
+
+ \list
+ \li \b{Linear} gradients interpolate colors between start and end points.
+ \li \b{Radial} gradients interpolate colors between a focal point and the
+ points on a circle surrounding it.
+ \li \b{Conical} gradients interpolate colors around a center point.
+ \endlist
+
+ The panel on the right contains a color table editor that defines
+ the colors in the gradient. The three topmost controls determine the red,
+ green and blue components while the last defines the alpha of the
+ gradient. You can move points, and add new ones, by clicking with the left
+ mouse button, and remove points by clicking with the right button.
+
+ There are three default configurations available at the bottom of
+ the page that are provided as suggestions on how a color table could be
+ configured.
+*/
diff --git a/examples/widgets/doc/groupbox.qdoc b/examples/widgets/doc/groupbox.qdoc
new file mode 100644
index 0000000000..d7384d409a
--- /dev/null
+++ b/examples/widgets/doc/groupbox.qdoc
@@ -0,0 +1,140 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/groupbox
+ \title Group Box Example
+
+ The Group Box example shows how to use the different kinds of group
+ boxes in Qt.
+
+ Group boxes are container widgets that organize buttons into groups,
+ both logically and on screen. They manage the interactions between
+ the user and the application so that you do not have to enforce
+ simple constraints.
+
+ Group boxes are usually used to organize check boxes and radio
+ buttons into exclusive groups.
+
+ \image groupbox-example.png
+
+ The Group Boxes example consists of a single \c Window class that
+ is used to show four group boxes: an exclusive radio button group,
+ a non-exclusive checkbox group, an exclusive radio button group
+ with an enabling checkbox, and a group box with normal push buttons.
+
+ \section1 Window Class Definition
+
+ The \c Window class is a subclass of \c QWidget that is used to
+ display a number of group boxes. The class definition contains
+ functions to construct each group box and populate it with different
+ selections of button widgets:
+
+ \snippet widgets/groupbox/window.h 0
+
+ In the example, the widget will be used as a top-level window, so
+ the constructor is defined so that we do not have to specify a parent
+ widget.
+
+ \section1 Window Class Implementation
+
+ The constructor creates a grid layout and fills it with each of the
+ group boxes that are to be displayed:
+
+ \snippet widgets/groupbox/window.cpp 0
+
+ The functions used to create each group box each return a
+ QGroupBox to be inserted into the grid layout.
+
+ \snippet widgets/groupbox/window.cpp 1
+
+ The first group box contains and manages three radio buttons. Since
+ the group box contains only radio buttons, it is exclusive by
+ default, so only one radio button can be checked at any given time.
+ We check the first radio button to ensure that the button group
+ contains one checked button.
+
+ \snippet widgets/groupbox/window.cpp 3
+
+ We use a vertical layout within the group box to present the
+ buttons in the form of a vertical list, and return the group
+ box to the constructor.
+
+ The second group box is itself checkable, providing a convenient
+ way to disable all the buttons inside it. Initially, it is
+ unchecked, so the group box itself must be checked before any of
+ the radio buttons inside can be checked.
+
+ \snippet widgets/groupbox/window.cpp 4
+
+ The group box contains three exclusive radio buttons, and an
+ independent checkbox. For consistency, one radio button must be
+ checked at all times, so we ensure that the first one is initially
+ checked.
+
+ \snippet widgets/groupbox/window.cpp 5
+
+ The buttons are arranged in the same way as those in the first
+ group box.
+
+ \snippet widgets/groupbox/window.cpp 6
+
+ The third group box is constructed with a "flat" style that is
+ better suited to certain types of dialog.
+
+ \snippet widgets/groupbox/window.cpp 7
+
+ This group box contains only checkboxes, so it is non-exclusive by
+ default. This means that each checkbox can be checked independently
+ of the others.
+
+ \snippet widgets/groupbox/window.cpp 8
+
+ Again, we use a vertical layout within the group box to present
+ the buttons in the form of a vertical list.
+
+ \snippet widgets/groupbox/window.cpp 9
+
+ The final group box contains only push buttons and, like the
+ second group box, it is checkable.
+
+ \snippet widgets/groupbox/window.cpp 10
+
+ We create a normal button, a toggle button, and a flat push button:
+
+ \snippet widgets/groupbox/window.cpp 11
+
+ Push buttons can be used to display popup menus. We create one, and
+ attach a simple menu to it:
+
+ \snippet widgets/groupbox/window.cpp 12
+
+ Finally, we lay out the widgets vertically, and return the group box
+ that we created:
+
+ \snippet widgets/groupbox/window.cpp 13
+*/
diff --git a/examples/widgets/doc/icons.qdoc b/examples/widgets/doc/icons.qdoc
new file mode 100644
index 0000000000..2ccf8cac43
--- /dev/null
+++ b/examples/widgets/doc/icons.qdoc
@@ -0,0 +1,780 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/icons
+ \title Icons Example
+
+ The Icons example shows how QIcon can generate pixmaps reflecting
+ an icon's state, mode and size. These pixmaps are generated from
+ the set of pixmaps made available to the icon, and are used by Qt
+ widgets to show an icon representing a particular action.
+
+ \image icons-example.png Screenshot of the Icons example
+
+ Contents:
+
+ \tableofcontents
+
+ \section1 QIcon Overview
+
+ The QIcon class provides scalable icons in different modes and
+ states. An icon's state and mode are depending on the intended use
+ of the icon. Qt currently defines four modes:
+
+ \table
+ \header \li Mode \li Description
+ \row
+ \li QIcon::Normal
+ \li Display the pixmap when the user is not interacting with the
+ icon, but the functionality represented by the icon is
+ available.
+ \row
+ \li QIcon::Active
+ \li Display the pixmap when the functionality represented by the
+ icon is available and the user is interacting with the icon,
+ for example, moving the mouse over it or clicking it.
+ \row
+ \li QIcon::Disabled
+ \li Display the pixmap when the functionality represented by
+ the icon is not available.
+ \row
+ \li QIcon::Selected
+ \li Display the pixmap when the icon is selected.
+ \endtable
+
+ QIcon's states are QIcon::On and QIcon::Off, which will display
+ the pixmap when the widget is in the respective state. The most
+ common usage of QIcon's states are when displaying checkable tool
+ buttons or menu entries (see QAbstractButton::setCheckable() and
+ QAction::setCheckable()). When a tool button or menu entry is
+ checked, the QIcon's state is \l{QIcon::}{On}, otherwise it's
+ \l{QIcon::}{Off}. You can, for example, use the QIcon's states to
+ display differing pixmaps depending on whether the tool button or
+ menu entry is checked or not.
+
+ A QIcon can generate smaller, larger, active, disabled, and
+ selected pixmaps from the set of pixmaps it is given. Such
+ pixmaps are used by Qt widgets to show an icon representing a
+ particular action.
+
+ \section1 Overview of the Icons Application
+
+ With the Icons application you get a preview of an icon's
+ generated pixmaps reflecting its different states, modes and size.
+
+ When an image is loaded into the application, it is converted into
+ a pixmap and becomes a part of the set of pixmaps available to the
+ icon. An image can be excluded from this set by checking off the
+ related checkbox. The application provides a sub directory
+ containing sets of images explicitly designed to illustrate how Qt
+ renders an icon in different modes and states.
+
+ The application allows you to manipulate the icon size with some
+ predefined sizes and a spin box. The predefined sizes are style
+ dependent, but most of the styles have the same values: Only the
+ Macintosh style differ by using 32 pixels, instead of 16 pixels,
+ for toolbar buttons. You can navigate between the available styles
+ using the \uicontrol View menu.
+
+ \image icons-view-menu.png Screenshot of the View menu
+
+ The \uicontrol View menu also provide the option to make the application
+ guess the icon state and mode from an image's file name. The \uicontrol
+ File menu provide the options of adding an image and removing all
+ images. These last options are also available through a context
+ menu that appears if you press the right mouse button within the
+ table of image files. In addition, the \uicontrol File menu provide an
+ \uicontrol Exit option, and the \uicontrol Help menu provide information about
+ the example and about Qt.
+
+ \image icons_find_normal.png Screenshot of the Find Files
+
+ The screenshot above shows the application with one image file
+ loaded. The \uicontrol {Guess Image Mode/State} is enabled and the
+ style is Plastique.
+
+ When QIcon is provided with only one available pixmap, that
+ pixmap is used for all the states and modes. In this case the
+ pixmap's icon mode is set to normal, and the generated pixmaps
+ for the normal and active modes will look the same. But in
+ disabled and selected mode, Qt will generate a slightly different
+ pixmap.
+
+ The next screenshot shows the application with an additional file
+ loaded, providing QIcon with two available pixmaps. Note that the
+ new image file's mode is set to disabled. When rendering the \uicontrol
+ Disabled mode pixmaps, Qt will now use the new image. We can see
+ the difference: The generated disabled pixmap in the first
+ screenshot is slightly darker than the pixmap with the originally
+ set disabled mode in the second screenshot.
+
+ \image icons_find_normal_disabled.png Screenshot of the Find Files
+
+ When Qt renders the icon's pixmaps it searches through the set of
+ available pixmaps following a particular algorithm. The algorithm
+ is documented in QIcon, but we will describe some particular cases
+ below.
+
+ \image icons_monkey_active.png Screenshot of the Find Files
+
+ In the screenshot above, we have set \c monkey_on_32x32 to be an
+ Active/On pixmap and \c monkey_off_64x64 to be Normal/Off. To
+ render the other six mode/state combinations, QIcon uses the
+ search algorithm described in the table below:
+
+ \table 100%
+ \header \li{2,1} Requested Pixmap \li {8,1} Preferred Alternatives (mode/state)
+ \header \li Mode \li State \li 1 \li 2 \li 3 \li 4 \li 5 \li 6 \li 7 \li 8
+ \row \li{1,2} Normal \li Off \li \b N0 \li A0 \li N1 \li A1 \li D0 \li S0 \li D1 \li S1
+ \row \li On \li N1 \li \b A1 \li N0 \li A0 \li D1 \li S1 \li D0 \li S0
+ \row \li{1,2} Active \li Off \li A0 \li \b N0 \li A1 \li N1 \li D0 \li S0 \li D1 \li S1
+ \row \li On \li \b A1 \li N1 \li A0 \li N0 \li D1 \li S1 \li D0 \li S0
+ \row \li{1,2} Disabled \li Off \li D0 \li \b {N0'} \li A0' \li D1 \li N1' \li A1' \li S0' \li S1'
+ \row \li On \li D1 \li N1' \li \b {A1'} \li D0 \li N0' \li A0' \li S1' \li S0'
+ \row \li{1,2} Selected \li Off \li S0 \li \b {N0''} \li A0'' \li S1 \li N1'' \li A1'' \li D0'' \li D1''
+ \row \li On \li S1 \li N1'' \li \b {A1''} \li S0 \li N0'' \li A0'' \li D1'' \li D0''
+ \endtable
+
+ In the table, "0" and "1" stand for Off" and "On", respectively.
+ Single quotes indicates that QIcon generates a disabled ("grayed
+ out") version of the pixmap; similarly, double quuote indicate
+ that QIcon generates a selected ("blued out") version of the
+ pixmap.
+
+ The alternatives used in the screenshot above are shown in bold.
+ For example, the Disabled/Off pixmap is derived by graying out
+ the Normal/Off pixmap (\c monkey_off_64x64).
+
+ In the next screenshots, we loaded the whole set of monkey
+ images. By checking or unchecking file names from the image list,
+ we get different results:
+
+ \table
+ \row
+ \li \inlineimage icons_monkey.png Screenshot of the Monkey Files
+ \li \inlineimage icons_monkey_mess.png Screenshot of the Monkey Files
+ \endtable
+
+ For any given mode/state combination, it is possible to specify
+ several images at different resolutions. When rendering an
+ icon, QIcon will automatically pick the most suitable image
+ and scale it down if necessary. (QIcon never scales up images,
+ because this rarely looks good.)
+
+ The screenshots below shows what happens when we provide QIcon
+ with three images (\c qt_extended_16x16.png, \c qt_extended_32x32.png, \c
+ qt_extended_48x48.png) and try to render the QIcon at various
+ resolutions:
+
+ \table
+ \row
+ \li
+ \li \inlineimage icons_qt_extended_8x8.png Qt Extended icon at 8 x 8
+ \li \inlineimage icons_qt_extended_16x16.png Qt Extended icon at 16 x 16
+ \li \inlineimage icons_qt_extended_17x17.png Qt Extended icon at 17 x 17
+ \row
+ \li
+ \li 8 x 8
+ \li \b {16 x 16}
+ \li 17 x 17
+ \row
+ \li \inlineimage icons_qt_extended_32x32.png Qt Extended icon at 32 x 32
+ \li \inlineimage icons_qt_extended_33x33.png Qt Extended icon at 33 x 33
+ \li \inlineimage icons_qt_extended_48x48.png Qt Extended icon at 48 x 48
+ \li \inlineimage icons_qt_extended_64x64.png Qt Extended icon at 64 x 64
+ \row
+ \li \b {32 x 32}
+ \li 33 x 33
+ \li \b {48 x 48}
+ \li 64 x 64
+ \endtable
+
+ For sizes up to 16 x 16, QIcon uses \c qt_extended_16x16.png and
+ scales it down if necessary. For sizes between 17 x 17 and 32 x
+ 32, it uses \c qt_extended_32x32.png. For sizes above 32 x 32, it uses
+ \c qt_extended_48x48.png.
+
+ \section1 Line-by-Line Walkthrough
+
+ The Icons example consists of four classes:
+
+ \list
+ \li \c MainWindow inherits QMainWindow and is the main application
+ window.
+ \li \c IconPreviewArea is a custom widget that displays all
+ combinations of states and modes for a given icon.
+ \li \c IconSizeSpinBox is a subclass of QSpinBox that lets the
+ user enter icon sizes (e.g., "48 x 48").
+ \li \c ImageDelegate is a subclass of QItemDelegate that provides
+ comboboxes for letting the user set the mode and state
+ associated with an image.
+ \endlist
+
+ We will start by reviewing the \c IconPreviewArea class before we
+ take a look at the \c MainWindow class. Finally, we will review the
+ \c IconSizeSpinBox and \c ImageDelegate classes.
+
+ \section2 IconPreviewArea Class Definition
+
+ An \c IconPreviewArea widget consists of a group box containing a grid of
+ QLabel widgets displaying headers and pixmaps.
+
+ \image icons_preview_area.png Screenshot of IconPreviewArea.
+
+ \snippet widgets/icons/iconpreviewarea.h 0
+
+ The \c IconPreviewArea class inherits QWidget. It displays the
+ generated pixmaps corresponding to an icon's possible states and
+ modes at a given size.
+
+ We need two public functions to set the current icon and the
+ icon's size. In addition the class has three private functions: We
+ use the \c createHeaderLabel() and \c createPixmapLabel()
+ functions when constructing the preview area, and we need the \c
+ updatePixmapLabels() function to update the preview area when
+ the icon or the icon's size has changed.
+
+ The \c NumModes and \c NumStates constants reflect \l{QIcon}'s
+ number of currently defined modes and states.
+
+ \section2 IconPreviewArea Class Implementation
+
+ \snippet widgets/icons/iconpreviewarea.cpp 0
+
+ In the constructor we create the labels displaying the headers and
+ the icon's generated pixmaps, and add them to a grid layout.
+
+ When creating the header labels, we make sure the enums \c
+ NumModes and \c NumStates defined in the \c .h file, correspond
+ with the number of labels that we create. Then if the enums at
+ some point are changed, the \c Q_ASSERT() macro will alert that this
+ part of the \c .cpp file needs to be updated as well.
+
+ If the application is built in debug mode, the \c Q_ASSERT()
+ macro will expand to
+
+ \snippet doc/src/snippets/code/doc_src_examples_icons.cpp 0
+
+ In release mode, the macro simply disappear. The mode can be set
+ in the application's \c .pro file. One way to do so is to add an
+ option to \c qmake when building the application:
+
+ \snippet doc/src/snippets/code/doc_src_examples_icons.qdoc 1
+
+ or
+
+ \snippet doc/src/snippets/code/doc_src_examples_icons.qdoc 2
+
+ Another approach is to add this line directly to the \c .pro
+ file.
+
+ \snippet widgets/icons/iconpreviewarea.cpp 1
+ \codeline
+ \snippet widgets/icons/iconpreviewarea.cpp 2
+
+ The public \c setIcon() and \c setSize() functions change the icon
+ or the icon size, and make sure that the generated pixmaps are
+ updated.
+
+ \snippet widgets/icons/iconpreviewarea.cpp 3
+ \codeline
+ \snippet widgets/icons/iconpreviewarea.cpp 4
+
+ We use the \c createHeaderLabel() and \c createPixmapLabel()
+ functions to create the preview area's labels displaying the
+ headers and the icon's generated pixmaps. Both functions return
+ the QLabel that is created.
+
+ \snippet widgets/icons/iconpreviewarea.cpp 5
+
+ We use the private \c updatePixmapLabel() function to update the
+ generated pixmaps displayed in the preview area.
+
+ For each mode, and for each state, we retrieve a pixmap using the
+ QIcon::pixmap() function, which generates a pixmap corresponding
+ to the given state, mode and size.
+
+ \section2 MainWindow Class Definition
+
+ The \c MainWindow widget consists of three main elements: an
+ images group box, an icon size group box and a preview area.
+
+ \image icons-example.png Screenshot of the Icons example
+
+ \snippet widgets/icons/mainwindow.h 0
+
+ The MainWindow class inherits from QMainWindow. We reimplement the
+ constructor, and declare several private slots:
+
+ \list
+ \li The \c about() slot simply provides information about the example.
+ \li The \c changeStyle() slot changes the application's GUI style and
+ adjust the style dependent size options.
+ \li The \c changeSize() slot changes the size of the preview area's icon.
+ \li The \c changeIcon() slot updates the set of pixmaps available to the
+ icon displayed in the preview area.
+ \li The \c addImage() slot allows the user to load a new image into the
+ application.
+ \endlist
+
+ In addition we declare several private functions to simplify the
+ constructor.
+
+ \section2 MainWindow Class Implementation
+
+ \snippet widgets/icons/mainwindow.cpp 0
+
+ In the constructor we first create the main window's central
+ widget and its child widgets, and put them in a grid layout. Then
+ we create the menus with their associated entries and actions.
+
+ Before we resize the application window to a suitable size, we set
+ the window title and determine the current style for the
+ application. We also enable the icon size spin box by clicking the
+ associated radio button, making the current value of the spin box
+ the icon's initial size.
+
+ \snippet widgets/icons/mainwindow.cpp 1
+
+ The \c about() slot displays a message box using the static
+ QMessageBox::about() function. In this example it displays a
+ simple box with information about the example.
+
+ The \c about() function looks for a suitable icon in four
+ locations: It prefers its parent's icon if that exists. If it
+ doesn't, the function tries the top-level widget containing
+ parent, and if that fails, it tries the active window. As a last
+ resort it uses the QMessageBox's Information icon.
+
+ \snippet widgets/icons/mainwindow.cpp 2
+
+ In the \c changeStyle() slot we first check the slot's
+ parameter. If it is false we immediately return, otherwise we find
+ out which style to change to, i.e. which action that triggered the
+ slot, using the QObject::sender() function.
+
+ This function returns the sender as a QObject pointer. Since we
+ know that the sender is a QAction object, we can safely cast the
+ QObject. We could have used a C-style cast or a C++ \c
+ static_cast(), but as a defensive programming technique we use a
+ \l qobject_cast(). The advantage is that if the object has the
+ wrong type, a null pointer is returned. Crashes due to null
+ pointers are much easier to diagnose than crashes due to unsafe
+ casts.
+
+ \snippet widgets/icons/mainwindow.cpp 3
+ \snippet widgets/icons/mainwindow.cpp 4
+
+ Once we have the action, we extract the style name using
+ QAction::data(). Then we create a QStyle object using the static
+ QStyleFactory::create() function.
+
+ Although we can assume that the style is supported by the
+ QStyleFactory: To be on the safe side, we use the \c Q_ASSERT()
+ macro to check if the created style is valid before we use the
+ QApplication::setStyle() function to set the application's GUI
+ style to the new style. QApplication will automatically delete
+ the style object when a new style is set or when the application
+ exits.
+
+ The predefined icon size options provided in the application are
+ style dependent, so we need to update the labels in the icon size
+ group box and in the end call the \c changeSize() slot to update
+ the icon's size.
+
+ \snippet widgets/icons/mainwindow.cpp 5
+
+ The \c changeSize() slot sets the size for the preview area's
+ icon.
+
+ To determine the new size we first check if the spin box is
+ enabled. If it is, we extract the extent of the new size from the
+ box. If it's not, we search through the predefined size options,
+ extract the QStyle::PixelMetric and use the QStyle::pixelMetric()
+ function to determine the extent. Then we create a QSize object
+ based on the extent, and use that object to set the size of the
+ preview area's icon.
+
+ \snippet widgets/icons/mainwindow.cpp 12
+
+ The first thing we do when the \c addImage() slot is called, is to
+ show a file dialog to the user. The easiest way to create a file
+ dialog is to use QFileDialog's static functions. Here we use the
+ \l {QFileDialog::getOpenFileNames()}{getOpenFileNames()} function
+ that will return one or more existing files selected by the user.
+
+ For each of the files the file dialog returns, we add a row to the
+ table widget. The table widget is listing the images the user has
+ loaded into the application.
+
+ \snippet widgets/icons/mainwindow.cpp 13
+ \snippet widgets/icons/mainwindow.cpp 14
+
+ We retrieve the image name using the QFileInfo::baseName()
+ function that returns the base name of the file without the path,
+ and create the first table widget item in the row. Then we add the
+ file's complete name to the item's data. Since an item can hold
+ several information pieces, we need to assign the file name a role
+ that will distinguish it from other data. This role can be Qt::UserRole
+ or any value above it.
+
+ We also make sure that the item is not editable by removing the
+ Qt::ItemIsEditable flag. Table items are editable by default.
+
+ \snippet widgets/icons/mainwindow.cpp 15
+ \snippet widgets/icons/mainwindow.cpp 16
+ \snippet widgets/icons/mainwindow.cpp 17
+
+ Then we create the second and third items in the row making the
+ default mode Normal and the default state Off. But if the \uicontrol
+ {Guess Image Mode/State} option is checked, and the file name
+ contains "_act", "_dis", or "_sel", the modes are changed to
+ Active, Disabled, or Selected. And if the file name contains
+ "_on", the state is changed to On. The sample files in the
+ example's \c images subdirectory respect this naming convension.
+
+ \snippet widgets/icons/mainwindow.cpp 18
+ \snippet widgets/icons/mainwindow.cpp 19
+
+ In the end we add the items to the associated row, and use the
+ QTableWidget::openPersistentEditor() function to create
+ comboboxes for the mode and state columns of the items.
+
+ Due to the connection between the table widget's \l
+ {QTableWidget::itemChanged()}{itemChanged()} signal and the \c
+ changeIcon() slot, the new image is automatically converted into a
+ pixmap and made part of the set of pixmaps available to the icon
+ in the preview area. So, corresponding to this fact, we need to
+ make sure that the new image's check box is enabled.
+
+ \snippet widgets/icons/mainwindow.cpp 6
+ \snippet widgets/icons/mainwindow.cpp 7
+
+ The \c changeIcon() slot is called when the user alters the set
+ of images listed in the QTableWidget, to update the QIcon object
+ rendered by the \c IconPreviewArea.
+
+ We first create a QIcon object, and then we run through the
+ QTableWidget, which lists the images the user has loaded into the
+ application.
+
+ \snippet widgets/icons/mainwindow.cpp 8
+ \snippet widgets/icons/mainwindow.cpp 9
+ \snippet widgets/icons/mainwindow.cpp 10
+
+ We also extract the image file's name using the
+ QTableWidgetItem::data() function. This function takes a
+ Qt::DataItemRole as an argument to retrieve the right data
+ (remember that an item can hold several pieces of information)
+ and returns it as a QVariant. Then we use the
+ QVariant::toString() function to get the file name as a QString.
+
+ To create a pixmap from the file, we need to first create an
+ image and then convert this image into a pixmap using
+ QPixmap::fromImage(). Once we have the final pixmap, we add it,
+ with its associated mode and state, to the QIcon's set of
+ available pixmaps.
+
+ \snippet widgets/icons/mainwindow.cpp 11
+
+ After running through the entire list of images, we change the
+ icon of the preview area to the one we just created.
+
+ \snippet widgets/icons/mainwindow.cpp 20
+
+ In the \c removeAllImages() slot, we simply set the table widget's
+ row count to zero, automatically removing all the images the user
+ has loaded into the application. Then we update the set of pixmaps
+ available to the preview area's icon using the \c changeIcon()
+ slot.
+
+ \image icons_images_groupbox.png Screenshot of the images group box
+
+ The \c createImagesGroupBox() function is implemented to simplify
+ the constructor. The main purpose of the function is to create a
+ QTableWidget that will keep track of the images the user has
+ loaded into the application.
+
+ \snippet widgets/icons/mainwindow.cpp 21
+
+ First we create a group box that will contain the table widget.
+ Then we create a QTableWidget and customize it to suit our
+ purposes.
+
+ We call QAbstractItemView::setSelectionMode() to prevent the user
+ from selecting items.
+
+ The QAbstractItemView::setItemDelegate() call sets the item
+ delegate for the table widget. We create a \c ImageDelegate that
+ we make the item delegate for our view.
+
+ The QItemDelegate class can be used to provide an editor for an item view
+ class that is subclassed from QAbstractItemView. Using a delegate
+ for this purpose allows the editing mechanism to be customized and
+ developed independently from the model and view.
+
+ In this example we derive \c ImageDelegate from QItemDelegate.
+ QItemDelegate usually provides line editors, while our subclass
+ \c ImageDelegate, provides comboboxes for the mode and state
+ fields.
+
+ \snippet widgets/icons/mainwindow.cpp 22
+ \snippet widgets/icons/mainwindow.cpp 23
+
+ Then we customize the QTableWidget's horizontal header, and hide
+ the vertical header.
+
+ \snippet widgets/icons/mainwindow.cpp 24
+ \snippet widgets/icons/mainwindow.cpp 25
+
+ At the end, we connect the QTableWidget::itemChanged() signal to
+ the \c changeIcon() slot to ensuret that the preview area is in
+ sync with the image table.
+
+ \image icons_size_groupbox.png Screenshot of the icon size group box
+
+ The \c createIconSizeGroupBox() function is called from the
+ constructor. It creates the widgets controlling the size of the
+ preview area's icon.
+
+ \snippet widgets/icons/mainwindow.cpp 26
+
+ First we create a group box that will contain all the widgets;
+ then we create the radio buttons and the spin box.
+
+ The spin box is not a regular QSpinBox but an \c IconSizeSpinBox.
+ The \c IconSizeSpinBox class inherits QSpinBox and reimplements
+ two functions: QSpinBox::textFromValue() and
+ QSpinBox::valueFromText(). The \c IconSizeSpinBox is designed to
+ handle icon sizes, e.g., "32 x 32", instead of plain integer
+ values.
+
+ \snippet widgets/icons/mainwindow.cpp 27
+
+ Then we connect all of the radio buttons
+ \l{QRadioButton::toggled()}{toggled()} signals and the spin box's
+ \l {QSpinBox::valueChanged()}{valueChanged()} signal to the \c
+ changeSize() slot to make sure that the size of the preview
+ area's icon is updated whenever the user changes the icon size.
+ In the end we put the widgets in a layout that we install on the
+ group box.
+
+ \snippet widgets/icons/mainwindow.cpp 28
+
+ In the \c createActions() function we create and customize all the
+ actions needed to implement the functionality associated with the
+ menu entries in the application.
+
+ In particular we create the \c styleActionGroup based on the
+ currently available GUI styles using
+ QStyleFactory. QStyleFactory::keys() returns a list of valid keys,
+ typically including "windows", "motif", "cde", and
+ "plastique". Depending on the platform, "windowsxp" and
+ "macintosh" may be available.
+
+ We create one action for each key, and adds the action to the
+ action group. Also, for each action, we call QAction::setData()
+ with the style name. We will retrieve it later using
+ QAction::data().
+
+ \snippet widgets/icons/mainwindow.cpp 29
+
+ In the \c createMenu() function, we add the previously created
+ actions to the \uicontrol File, \uicontrol View and \uicontrol Help menus.
+
+ The QMenu class provides a menu widget for use in menu bars,
+ context menus, and other popup menus. We put each menu in the
+ application's menu bar, which we retrieve using
+ QMainWindow::menuBar().
+
+ \snippet widgets/icons/mainwindow.cpp 30
+
+ QWidgets have a \l{QWidget::contextMenuPolicy}{contextMenuPolicy}
+ property that controls how the widget should behave when the user
+ requests a context menu (e.g., by right-clicking). We set the
+ QTableWidget's context menu policy to Qt::ActionsContextMenu,
+ meaning that the \l{QAction}s associated with the widget should
+ appear in its context menu.
+
+ Then we add the \uicontrol{Add Image} and \uicontrol{Remove All Images}
+ actions to the table widget. They will then appear in the table
+ widget's context menu.
+
+ \snippet widgets/icons/mainwindow.cpp 31
+
+ In the \c checkCurrentStyle() function we go through the group of
+ style actions, looking for the current GUI style.
+
+ For each action, we first extract the style name using
+ QAction::data(). Since this is only a QStyleFactory key (e.g.,
+ "macintosh"), we cannot compare it directly to the current
+ style's class name. We need to create a QStyle object using the
+ static QStyleFactory::create() function and compare the class
+ name of the created QStyle object with that of the current style.
+ As soon as we are done with a QStyle candidate, we delete it.
+
+ For all QObject subclasses that use the \c Q_OBJECT macro, the
+ class name of an object is available through its
+ \l{QObject::metaObject()}{meta-object}.
+
+ We can assume that the style is supported by
+ QStyleFactory, but to be on the safe side we use the \c
+ Q_ASSERT() macro to make sure that QStyleFactory::create()
+ returned a valid pointer.
+
+ \section2 IconSizeSpinBox Class Definition
+
+ \snippet widgets/icons/iconsizespinbox.h 0
+
+ The \c IconSizeSpinBox class is a subclass of QSpinBox. A plain
+ QSpinBox can only handle integers. But since we want to display
+ the spin box's values in a more sophisticated way, we need to
+ subclass QSpinBox and reimplement the QSpinBox::textFromValue()
+ and QSpinBox::valueFromText() functions.
+
+ \image icons_size_spinbox.png Screenshot of the icon size spinbox
+
+ \section2 IconSizeSpinBox Class Implementation
+
+ \snippet widgets/icons/iconsizespinbox.cpp 0
+
+ The constructor is trivial.
+
+ \snippet widgets/icons/iconsizespinbox.cpp 2
+
+ QSpinBox::textFromValue() is used by the spin box whenever it
+ needs to display a value. The default implementation returns a
+ base 10 representation of the \c value parameter.
+
+ Our reimplementation returns a QString of the form "32 x 32".
+
+ \snippet widgets/icons/iconsizespinbox.cpp 1
+
+ The QSpinBox::valueFromText() function is used by the spin box
+ whenever it needs to interpret text typed in by the user. Since
+ we reimplement the \c textFromValue() function we also need to
+ reimplement the \c valueFromText() function to interpret the
+ parameter text and return the associated int value.
+
+ We parse the text using a regular expression (a QRegExp). We
+ define an expression that matches one or several digits,
+ optionally followed by whitespace, an "x" or the times symbol,
+ whitespace and one or several digits again.
+
+ The first digits of the regular expression are captured using
+ parentheses. This enables us to use the QRegExp::cap() or
+ QRegExp::capturedTexts() functions to extract the matched
+ characters. If the first and second numbers of the spin box value
+ differ (e.g., "16 x 24"), we use the first number.
+
+ When the user presses \uicontrol Enter, QSpinBox first calls
+ QSpinBox::valueFromText() to interpret the text typed by the
+ user, then QSpinBox::textFromValue() to present it in a canonical
+ format (e.g., "16 x 16").
+
+ \section2 ImageDelegate Class Definition
+
+ \snippet widgets/icons/imagedelegate.h 0
+
+ The \c ImageDelegate class is a subclass of QItemDelegate. The
+ QItemDelegate class provides display and editing facilities for
+ data items from a model. A single QItemDelegate object is
+ responsible for all items displayed in a item view (in our case,
+ a QTableWidget).
+
+ A QItemDelegate can be used to provide an editor for an item view
+ class that is subclassed from QAbstractItemView. Using a delegate
+ for this purpose allows the editing mechanism to be customized and
+ developed independently from the model and view.
+
+ \snippet widgets/icons/imagedelegate.h 1
+
+ The default implementation of QItemDelegate creates a QLineEdit.
+ Since we want the editor to be a QComboBox, we need to subclass
+ QItemDelegate and reimplement the QItemDelegate::createEditor(),
+ QItemDelegate::setEditorData() and QItemDelegate::setModelData()
+ functions.
+
+ \snippet widgets/icons/imagedelegate.h 2
+
+ The \c emitCommitData() slot is used to emit the
+ QImageDelegate::commitData() signal with the appropriate
+ argument.
+
+ \section2 ImageDelegate Class Implementation
+
+ \snippet widgets/icons/imagedelegate.cpp 0
+
+ The constructor is trivial.
+
+ \snippet widgets/icons/imagedelegate.cpp 1
+
+ The default QItemDelegate::createEditor() implementation returns
+ the widget used to edit the item specified by the model and item
+ index for editing. The parent widget and style option are used to
+ control the appearance of the editor widget.
+
+ Our reimplementation create and populate a combobox instead of
+ the default line edit. The contents of the combobox depends on
+ the column in the table for which the editor is requested. Column
+ 1 contains the QIcon modes, whereas column 2 contains the QIcon
+ states.
+
+ In addition, we connect the combobox's \l
+ {QComboBox::activated()}{activated()} signal to the \c
+ emitCommitData() slot to emit the
+ QAbstractItemDelegate::commitData() signal whenever the user
+ chooses an item using the combobox. This ensures that the rest of
+ the application notices the change and updates itself.
+
+ \snippet widgets/icons/imagedelegate.cpp 2
+
+ The QItemDelegate::setEditorData() function is used by
+ QTableWidget to transfer data from a QTableWidgetItem to the
+ editor. The data is stored as a string; we use
+ QComboBox::findText() to locate it in the combobox.
+
+ Delegates work in terms of models, not items. This makes it
+ possible to use them with any item view class (e.g., QListView,
+ QListWidget, QTreeView, etc.). The transition between model and
+ items is done implicitly by QTableWidget; we don't need to worry
+ about it.
+
+ \snippet widgets/icons/imagedelegate.cpp 3
+
+ The QItemDelegate::setEditorData() function is used by QTableWidget
+ to transfer data back from the editor to the \l{QTableWidgetItem}.
+
+ \snippet widgets/icons/imagedelegate.cpp 4
+
+ The \c emitCommitData() slot simply emit the
+ QAbstractItemDelegate::commitData() signal for the editor that
+ triggered the slot. This signal must be emitted when the editor
+ widget has completed editing the data, and wants to write it back
+ into the model.
+*/
diff --git a/examples/widgets/doc/imagecomposition.qdoc b/examples/widgets/doc/imagecomposition.qdoc
new file mode 100644
index 0000000000..2eecfd46aa
--- /dev/null
+++ b/examples/widgets/doc/imagecomposition.qdoc
@@ -0,0 +1,165 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example painting/imagecomposition
+ \title Image Composition Example
+
+ The Image Composition example lets the user combine images
+ together using any composition mode supported by QPainter, described
+ in detail in \l{QPainter#Composition Modes}{Composition Modes}.
+
+ \image imagecomposition-example.png
+
+ \section1 Setting Up The Resource File
+
+ The Image Composition example requires two source images,
+ \e butterfly.png and \e checker.png that are embedded within
+ \e imagecomposition.qrc. The file contains the following code:
+
+ \quotefile examples/painting/imagecomposition/imagecomposition.qrc
+
+ For more information on resource files, see \l{The Qt Resource System}.
+
+ \section1 ImageComposer Class Definition
+
+ The \c ImageComposer class is a subclass of QWidget that implements three
+ private slots, \c chooseSource(), \c chooseDestination(), and
+ \c recalculateResult().
+
+ \snippet painting/imagecomposition/imagecomposer.h 0
+
+ In addition, \c ImageComposer consists of five private functions,
+ \c addOp(), \c chooseImage(), \c loadImage(), \c currentMode(), and
+ \c imagePos(), as well as private instances of QToolButton, QComboBox,
+ QLabel, and QImage.
+
+ \snippet painting/imagecomposition/imagecomposer.h 1
+
+ \section1 ImageComposer Class Implementation
+
+ We declare a QSize object, \c resultSize, as a static constant with width
+ and height equal to 200.
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 0
+
+ Within the constructor, we instantiate a QToolButton object,
+ \c sourceButton and set its \l{QAbstractButton::setIconSize()}{iconSize}
+ property to \c resultSize. The \c operatorComboBox is instantiated and
+ then populated using the \c addOp() function. This function accepts a
+ QPainter::CompositionMode, \a mode, and a QString, \a name, representing
+ the name of the composition mode.
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 1
+
+ The \c destinationButton is instantiated and its
+ \l{QAbstractButton::setIconSize()}{iconSize} property is set to
+ \c resultSize as well. The \l{QLabel}s \c equalLabel and \c resultLabel
+ are created and \c{resultLabel}'s \l{QWidget::setMinimumWidth()}
+ {minimumWidth} is set.
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 2
+
+ We connect the following signals to their corresponding slots:
+ \list
+ \li \c{sourceButton}'s \l{QPushButton::clicked()}{clicked()} signal is
+ connected to \c chooseSource(),
+ \li \c{operatorComboBox}'s \l{QComboBox::activated()}{activated()}
+ signal is connected to \c recalculateResult(), and
+ \li \c{destinationButton}'s \l{QToolButton::clicked()}{clicked()} signal
+ is connected to \c chooseDestination().
+ \endlist
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 3
+
+ A QGridLayout, \c mainLayout, is used to place all the widgets. Note
+ that \c{mainLayout}'s \l{QLayout::setSizeConstraint()}{sizeConstraint}
+ property is set to QLayout::SetFixedSize, which means that
+ \c{ImageComposer}'s size cannot be resized at all.
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 4
+
+ We create a QImage, \c resultImage, and we invoke \c loadImage() twice
+ to load both the image files in our \e imagecomposition.qrc file. Then,
+ we set the \l{QWidget::setWindowTitle()}{windowTitle} property to
+ "Image Composition".
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 5
+
+ The \c chooseSource() and \c chooseDestination() functions are
+ convenience functions that invoke \c chooseImage() with specific
+ parameters.
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 6
+ \codeline
+ \snippet painting/imagecomposition/imagecomposer.cpp 7
+
+ The \c chooseImage() function loads an image of the user's choice,
+ depending on the \a title, \a image, and \a button.
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 10
+
+ The \c recalculateResult() function is used to calculate amd display the
+ result of combining the two images together with the user's choice of
+ composition mode.
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 8
+
+ The \c addOp() function adds an item to the \c operatorComboBox using
+ \l{QComboBox}'s \l{QComboBox::addItem()}{addItem} function. This function
+ accepts a QPainter::CompositionMode, \a mode, and a QString, \a name. The
+ rectangle is filled with Qt::Transparent and both the \c sourceImage and
+ \c destinationImage are painted, before displaying it on \c resultLabel.
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 9
+
+ The \c loadImage() function paints a transparent background using
+ \l{QPainter::fillRect()}{fillRect()} and draws \c image in a
+ centralized position using \l{QPainter::drawImage()}{drawImage()}.
+ This \c image is then set as the \c{button}'s icon.
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 11
+
+ The \c currentMode() function returns the composition mode currently
+ selected in \c operatorComboBox.
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 12
+
+ We use the \c imagePos() function to ensure that images loaded onto the
+ QToolButton objects, \c sourceButton and \c destinationButton, are
+ centralized.
+
+ \snippet painting/imagecomposition/imagecomposer.cpp 13
+
+ \section1 The \c main() Function
+
+ The \c main() function instantiates QApplication and \c ImageComposer
+ and invokes its \l{QWidget::show()}{show()} function.
+
+ \snippet painting/imagecomposition/main.cpp 0
+
+ */
diff --git a/examples/widgets/doc/imageviewer.qdoc b/examples/widgets/doc/imageviewer.qdoc
new file mode 100644
index 0000000000..8f8e238046
--- /dev/null
+++ b/examples/widgets/doc/imageviewer.qdoc
@@ -0,0 +1,326 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/imageviewer
+ \title Image Viewer Example
+
+ The example shows how to combine QLabel and QScrollArea to
+ display an image. QLabel is typically used for displaying text,
+ but it can also display an image. QScrollArea provides a
+ scrolling view around another widget. If the child widget exceeds
+ the size of the frame, QScrollArea automatically provides scroll
+ bars.
+
+ The example demonstrates how QLabel's ability to scale its
+ contents (QLabel::scaledContents), and QScrollArea's ability to
+ automatically resize its contents (QScrollArea::widgetResizable),
+ can be used to implement zooming and scaling features. In
+ addition the example shows how to use QPainter to print an image.
+
+ \image imageviewer-example.png Screenshot of the Image Viewer example
+
+ With the Image Viewer application, the users can view an image of
+ their choice. The \uicontrol File menu gives the user the possibility
+ to:
+
+ \list
+ \li \uicontrol{Open...} - Open an image file
+ \li \uicontrol{Print...} - Print an image
+ \li \uicontrol{Exit} - Exit the application
+ \endlist
+
+ Once an image is loaded, the \uicontrol View menu allows the users to:
+
+ \list
+ \li \uicontrol{Zoom In} - Scale the image up by 25%
+ \li \uicontrol{Zoom Out} - Scale the image down by 25%
+ \li \uicontrol{Normal Size} - Show the image at its original size
+ \li \uicontrol{Fit to Window} - Stretch the image to occupy the entire window
+ \endlist
+
+ In addition the \uicontrol Help menu provides the users with information
+ about the Image Viewer example in particular, and about Qt in
+ general.
+
+ \section1 ImageViewer Class Definition
+
+ \snippet widgets/imageviewer/imageviewer.h 0
+
+ The \c ImageViewer class inherits from QMainWindow. We reimplement
+ the constructor, and create several private slots to facilitate
+ the menu entries. In addition we create four private functions.
+
+ We use \c createActions() and \c createMenus() when constructing
+ the \c ImageViewer widget. We use the \c updateActions() function
+ to update the menu entries when a new image is loaded, or when
+ the \uicontrol {Fit to Window} option is toggled. The zoom slots use \c
+ scaleImage() to perform the zooming. In turn, \c
+ scaleImage() uses \c adjustScrollBar() to preserve the focal point after
+ scaling an image.
+
+ \section1 ImageViewer Class Implementation
+
+ \snippet widgets/imageviewer/imageviewer.cpp 0
+
+ In the constructor we first create the label and the scroll area.
+
+ We set \c {imageLabel}'s size policy to \l
+ {QSizePolicy::Ignored}{ignored}, making the users able to scale
+ the image to whatever size they want when the \uicontrol {Fit to Window}
+ option is turned on. Otherwise, the default size polizy (\l
+ {QSizePolicy::Preferred}{preferred}) will make scroll bars appear
+ when the scroll area becomes smaller than the label's minimum size
+ hint.
+
+ We ensure that the label will scale its contents to fill all
+ available space, to enable the image to scale properly when
+ zooming. If we omitted to set the \c {imageLabel}'s \l
+ {QLabel::scaledContents}{scaledContents} property, zooming in
+ would enlarge the QLabel, but leave the pixmap at
+ its original size, exposing the QLabel's background.
+
+ We make \c imageLabel the scroll area's child widget, and we make
+ \c scrollArea the central widget of the QMainWindow. At the end
+ we create the associated actions and menus, and customize the \c
+ {ImageViewer}'s appearance.
+
+ \snippet widgets/imageviewer/imageviewer.cpp 1
+ \snippet widgets/imageviewer/imageviewer.cpp 2
+
+ In the \c open() slot, we show a file dialog to the user. The
+ easiest way to create a QFileDialog is to use the static
+ convenience functions. QFileDialog::getOpenFileName() returns an
+ existing file selected by the user. If the user presses \uicontrol
+ Cancel, QFileDialog returns an empty string.
+
+ Unless the file name is a empty string, we check if the file's
+ format is an image format by constructing a QImage which tries to
+ load the image from the file. If the constructor returns a null
+ image, we use a QMessageBox to alert the user.
+
+ The QMessageBox class provides a modal dialog with a short
+ message, an icon, and some buttons. As with QFileDialog the
+ easiest way to create a QMessageBox is to use its static
+ convenience functions. QMessageBox provides a range of different
+ messages arranged along two axes: severity (question,
+ information, warning and critical) and complexity (the number of
+ necessary response buttons). In this particular example an
+ information message with an \uicontrol OK button (the default) is
+ sufficient, since the message is part of a normal operation.
+
+ \snippet widgets/imageviewer/imageviewer.cpp 3
+ \snippet widgets/imageviewer/imageviewer.cpp 4
+
+ If the format is supported, we display the image in \c imageLabel
+ by setting the label's \l {QLabel::pixmap}{pixmap}. Then we enable
+ the \uicontrol Print and \uicontrol {Fit to Window} menu entries and update
+ the rest of the view menu entries. The \uicontrol Open and \uicontrol Exit
+ entries are enabled by default.
+
+ If the \uicontrol {Fit to Window} option is turned off, the
+ QScrollArea::widgetResizable property is \c false and it is
+ our responsibility (not QScrollArea's) to give the QLabel a
+ reasonable size based on its contents. We call
+ \{QWidget::adjustSize()}{adjustSize()} to achieve this, which is
+ essentially the same as
+
+ \snippet doc/src/snippets/code/doc_src_examples_imageviewer.cpp 0
+
+ In the \c print() slot, we first make sure that an image has been
+ loaded into the application:
+
+ \snippet widgets/imageviewer/imageviewer.cpp 5
+ \snippet widgets/imageviewer/imageviewer.cpp 6
+
+ If the application is built in debug mode, the \c Q_ASSERT() macro
+ will expand to
+
+ \snippet doc/src/snippets/code/doc_src_examples_imageviewer.cpp 1
+
+ In release mode, the macro simply disappear. The mode can be set
+ in the application's \c .pro file. One way to do so is to add an
+ option to \uicontrol qmake when building the application:
+
+ \snippet doc/src/snippets/code/doc_src_examples_imageviewer.qdoc 2
+
+ or
+
+ \snippet doc/src/snippets/code/doc_src_examples_imageviewer.qdoc 3
+
+ Another approach is to add this line directly to the \c .pro
+ file.
+
+ \snippet widgets/imageviewer/imageviewer.cpp 7
+ \snippet widgets/imageviewer/imageviewer.cpp 8
+
+ Then we present a print dialog allowing the user to choose a
+ printer and to set a few options. We construct a painter with a
+ QPrinter as the paint device. We set the painter's window
+ and viewport in such a way that the image is as large as possible
+ on the paper, but without altering its
+ \l{Qt::KeepAspectRatio}{aspect ratio}.
+
+ In the end we draw the pixmap at position (0, 0).
+
+ \snippet widgets/imageviewer/imageviewer.cpp 9
+ \snippet widgets/imageviewer/imageviewer.cpp 10
+
+ We implement the zooming slots using the private \c scaleImage()
+ function. We set the scaling factors to 1.25 and 0.8,
+ respectively. These factor values ensure that a \uicontrol {Zoom In}
+ action and a \uicontrol {Zoom Out} action will cancel each other (since
+ 1.25 * 0.8 == 1), and in that way the normal image size can be
+ restored using the zooming features.
+
+ The screenshots below show an image in its normal size, and the
+ same image after zooming in:
+
+ \table
+ \row
+ \li \inlineimage imageviewer-original_size.png
+ \li \inlineimage imageviewer-zoom_in_1.png
+ \li \inlineimage imageviewer-zoom_in_2.png
+ \endtable
+
+ \snippet widgets/imageviewer/imageviewer.cpp 11
+ \snippet widgets/imageviewer/imageviewer.cpp 12
+
+ When zooming, we use the QLabel's ability to scale its contents.
+ Such scaling doesn't change the actual size hint of the contents.
+ And since the \l {QLabel::adjustSize()}{adjustSize()} function
+ use those size hint, the only thing we need to do to restore the
+ normal size of the currently displayed image is to call \c
+ adjustSize() and reset the scale factor to 1.0.
+
+ \snippet widgets/imageviewer/imageviewer.cpp 13
+ \snippet widgets/imageviewer/imageviewer.cpp 14
+
+ The \c fitToWindow() slot is called each time the user toggled
+ the \uicontrol {Fit to Window} option. If the slot is called to turn on
+ the option, we tell the scroll area to resize its child widget
+ with the QScrollArea::setWidgetResizable() function. Then we
+ disable the \uicontrol {Zoom In}, \uicontrol {Zoom Out} and \uicontrol {Normal
+ Size} menu entries using the private \c updateActions() function.
+
+ If the \l {QScrollArea::widgetResizable} property is set to \c
+ false (the default), the scroll area honors the size of its child
+ widget. If this property is set to \c true, the scroll area will
+ automatically resize the widget in order to avoid scroll bars
+ where they can be avoided, or to take advantage of extra space.
+ But the scroll area will honor the minimum size hint of its child
+ widget independent of the widget resizable property. So in this
+ example we set \c {imageLabel}'s size policy to \l
+ {QSizePolicy::Ignored}{ignored} in the constructor, to avoid that
+ scroll bars appear when the scroll area becomes smaller than the
+ label's minimum size hint.
+
+ The screenshots below shows an image in its normal size, and the
+ same image with the \uicontrol {Fit to window} option turned on.
+ Enlarging the window will stretch the image further, as shown in
+ the third screenshot.
+
+ \table
+ \row
+ \li \inlineimage imageviewer-original_size.png
+ \li \inlineimage imageviewer-fit_to_window_1.png
+ \li \inlineimage imageviewer-fit_to_window_2.png
+ \endtable
+
+ If the slot is called to turn off the option, the
+ {QScrollArea::setWidgetResizable} property is set to \c false. We
+ also restore the image pixmap to its normal size by adjusting the
+ label's size to its content. And in the end we update the view
+ menu entries.
+
+ \snippet widgets/imageviewer/imageviewer.cpp 15
+ \snippet widgets/imageviewer/imageviewer.cpp 16
+
+ We implement the \c about() slot to create a message box
+ describing what the example is designed to show.
+
+ \snippet widgets/imageviewer/imageviewer.cpp 17
+ \snippet widgets/imageviewer/imageviewer.cpp 18
+
+ In the private \c createAction() function, we create the
+ actions providing the application features.
+
+ We assign a short-cut key to each action and connect them to the
+ appropriate slots. We only enable the \c openAct and \c exitAct at
+ the time of creation, the others are updated once an image has
+ been loaded into the application. In addition we make the \c
+ fitToWindowAct \l {QAction::checkable}{checkable}.
+
+ \snippet widgets/imageviewer/imageviewer.cpp 19
+ \snippet widgets/imageviewer/imageviewer.cpp 20
+
+ In the private \c createMenu() function, we add the previously
+ created actions to the \uicontrol File, \uicontrol View and \uicontrol Help menus.
+
+ The QMenu class provides a menu widget for use in menu bars,
+ context menus, and other popup menus. The QMenuBar class provides
+ a horizontal menu bar that consists of a list of pull-down menu
+ items. So at the end we put the menus in the \c {ImageViewer}'s
+ menu bar which we retrieve with the QMainWindow::menuBar()
+ function.
+
+ \snippet widgets/imageviewer/imageviewer.cpp 21
+ \snippet widgets/imageviewer/imageviewer.cpp 22
+
+ The private \c updateActions() function enables or disables the
+ \uicontrol {Zoom In}, \uicontrol {Zoom Out} and \uicontrol {Normal Size} menu
+ entries depending on whether the \uicontrol {Fit to Window} option is
+ turned on or off.
+
+ \snippet widgets/imageviewer/imageviewer.cpp 23
+ \snippet widgets/imageviewer/imageviewer.cpp 24
+
+ In \c scaleImage(), we use the \c factor parameter to calculate
+ the new scaling factor for the displayed image, and resize \c
+ imageLabel. Since we set the
+ \l{QLabel::scaledContents}{scaledContents} property to \c true in
+ the constructor, the call to QWidget::resize() will scale the
+ image displayed in the label. We also adjust the scroll bars to
+ preserve the focal point of the image.
+
+ At the end, if the scale factor is less than 33.3% or greater
+ than 300%, we disable the respective menu entry to prevent the
+ image pixmap from becoming too large, consuming too much
+ resources in the window system.
+
+ \snippet widgets/imageviewer/imageviewer.cpp 25
+ \snippet widgets/imageviewer/imageviewer.cpp 26
+
+ Whenever we zoom in or out, we need to adjust the scroll bars in
+ consequence. It would have been tempting to simply call
+
+ \snippet doc/src/snippets/code/doc_src_examples_imageviewer.cpp 4
+
+ but this would make the top-left corner the focal point, not the
+ center. Therefore we need to take into account the scroll bar
+ handle's size (the \l{QScrollBar::pageStep}{page step}).
+*/
diff --git a/examples/widgets/doc/interview.qdoc b/examples/widgets/doc/interview.qdoc
new file mode 100644
index 0000000000..35721ccfae
--- /dev/null
+++ b/examples/widgets/doc/interview.qdoc
@@ -0,0 +1,37 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/interview
+ \title Interview
+
+ The Interview example explores the flexibility and scalability of the
+ model/view framework by presenting an infinitely deep data structure using a model
+ and three different types of view.
+
+ \image interview-demo.png
+*/
diff --git a/examples/widgets/doc/licensewizard.qdoc b/examples/widgets/doc/licensewizard.qdoc
new file mode 100644
index 0000000000..125e0fec8f
--- /dev/null
+++ b/examples/widgets/doc/licensewizard.qdoc
@@ -0,0 +1,218 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example dialogs/licensewizard
+ \title License Wizard Example
+
+ The License Wizard example shows how to implement complex wizards in
+ Qt.
+
+ \image licensewizard-example.png Screenshot of the License Wizard example
+
+ Most wizards have a linear structure, with page 1 followed by
+ page 2 and so on until the last page. The
+ \l{dialogs/classwizard}{Class Wizard} example shows how to create
+ such wizards.
+
+ Some wizards are more complex in that they allow different
+ traversal paths based on the information provided by the user.
+ The License Wizard example illustrates this. It provides five
+ wizard pages; depending on which options are selected, the user
+ can reach different pages.
+
+ \image licensewizard-flow.png The License Wizard pages
+
+ The example consists of the following classes:
+
+ \list
+ \li \c LicenseWizard inherits QWizard and implements a non-linear
+ five-page wizard that leads the user through the process of
+ choosing a license agreement.
+ \li \c IntroPage, \c EvaluatePage, \c RegisterPage, \c
+ DetailsPage, and \c ConclusionPage are QWizardPage subclasses
+ that implement the wizard pages.
+ \endlist
+
+ \section1 The LicenseWizard Class
+
+ The \c LicenseWizard class derives from QWizard and provides a
+ five-page wizard that guides the user through the process of
+ registering their copy of a fictitious software product. Here's
+ the class definition:
+
+ \snippet dialogs/licensewizard/licensewizard.h 1
+
+ The class's public API is limited to a constructor and an enum.
+ The enum defines the IDs associated with the various pages:
+
+ \table
+ \header \li Class name \li Enum value \li Page ID
+ \row \li \c IntroPage \li \c Page_Intro \li 0
+ \row \li \c EvaluatePage \li \c Page_Evaluate \li 1
+ \row \li \c RegisterPage \li \c Page_Register \li 2
+ \row \li \c DetailsPage \li \c Page_Details \li 3
+ \row \li \c ConclusionPage \li \c Page_Conclusion \li 4
+ \endtable
+
+ For this example, the IDs are arbitrary. The only constraints are
+ that they must be unique and different from -1. IDs allow us to
+ refer to pages.
+
+ \snippet dialogs/licensewizard/licensewizard.cpp 2
+
+ In the constructor, we create the five pages, insert them into
+ the wizard using QWizard::setPage(), and set \c Page_Intro to be
+ the first page.
+
+ \snippet dialogs/licensewizard/licensewizard.cpp 3
+ \snippet dialogs/licensewizard/licensewizard.cpp 4
+
+ We set the style to \l{QWizard::}{ModernStyle} on all platforms
+ except Mac OS X,
+
+ \snippet dialogs/licensewizard/licensewizard.cpp 5
+ \snippet dialogs/licensewizard/licensewizard.cpp 6
+
+ We configure the QWizard to show a \uicontrol Help button, which is
+ connected to our \c showHelp() slot. We also set the
+ \l{QWizard::}{LogoPixmap} for all pages that have a header (i.e.,
+ \c EvaluatePage, \c RegisterPage, and \c DetailsPage).
+
+ \snippet dialogs/licensewizard/licensewizard.cpp 9
+ \snippet dialogs/licensewizard/licensewizard.cpp 11
+ \dots
+ \snippet dialogs/licensewizard/licensewizard.cpp 13
+
+ In \c showHelp(), we display help texts that are appropriate for
+ the current page. If the user clicks \uicontrol Help twice for the same
+ page, we say, "Sorry, I already gave what help I could. Maybe you
+ should try asking a human?"
+
+ \section1 The IntroPage Class
+
+ The pages are defined in \c licensewizard.h and implemented in \c
+ licensewizard.cpp, together with \c LicenseWizard.
+
+ Here's the definition and implementation of \c{IntroPage}:
+
+ \snippet dialogs/licensewizard/licensewizard.h 4
+ \codeline
+ \snippet dialogs/licensewizard/licensewizard.cpp 16
+
+ A page inherits from QWizardPage. We set a
+ \l{QWizardPage::}{title} and a
+ \l{QWizard::WatermarkPixmap}{watermark pixmap}. By not setting
+ any \l{QWizardPage::}{subTitle}, we ensure that no header is
+ displayed for this page. (On Windows, it is customary for wizards
+ to display a watermark pixmap on the first and last pages, and to
+ have a header on the other pages.)
+
+ \snippet dialogs/licensewizard/licensewizard.cpp 17
+ \snippet dialogs/licensewizard/licensewizard.cpp 19
+
+ The \c nextId() function returns the ID for \c EvaluatePage if
+ the \uicontrol{Evaluate the product for 30 days} option is checked;
+ otherwise it returns the ID for \c RegisterPage.
+
+ \section1 The EvaluatePage Class
+
+ The \c EvaluatePage is slightly more involved:
+
+ \snippet dialogs/licensewizard/licensewizard.h 5
+ \codeline
+ \snippet dialogs/licensewizard/licensewizard.cpp 20
+ \dots
+ \snippet dialogs/licensewizard/licensewizard.cpp 21
+ \dots
+ \snippet dialogs/licensewizard/licensewizard.cpp 22
+
+ First, we set the page's \l{QWizardPage::}{title}
+ and \l{QWizardPage::}{subTitle}.
+
+ Then we create the child widgets, create \l{Registering and Using
+ Fields}{wizard fields} associated with them, and put them into
+ layouts. The fields are created with an asterisk (\c
+ *) next to their name. This makes them \l{mandatory fields}, that
+ is, fields that must be filled before the user can press the
+ \uicontrol Next button (\uicontrol Continue on Mac OS X). The fields' values
+ can be accessed from any other page using QWizardPage::field().
+
+ Resetting the page amounts to clearing the two text fields.
+
+ \snippet dialogs/licensewizard/licensewizard.cpp 23
+
+ The next page is always the \c ConclusionPage.
+
+ \section1 The ConclusionPage Class
+
+ The \c RegisterPage and \c DetailsPage are very similar to \c
+ EvaluatePage. Let's go directly to the \c ConclusionPage:
+
+ \snippet dialogs/licensewizard/licensewizard.h 6
+
+ This time, we reimplement QWizardPage::initializePage() and
+ QWidget::setVisible(), in addition to
+ \l{QWizardPage::}{nextId()}. We also declare a private slot:
+ \c printButtonClicked().
+
+ \snippet dialogs/licensewizard/licensewizard.cpp 18
+
+ The default implementation of QWizardPage::nextId() returns
+ the page with the next ID, or -1 if the current page has the
+ highest ID. This behavior would work here, because \c
+ Page_Conclusion equals 5 and there is no page with a higher ID,
+ but to avoid relying on such subtle behavior, we reimplement
+ \l{QWizardPage::}{nextId()} to return -1.
+
+ \snippet dialogs/licensewizard/licensewizard.cpp 27
+
+ We use QWizard::hasVisitedPage() to determine the type of
+ license agreement the user has chosen. If the user filled the \c
+ EvaluatePage, the license text refers to an Evaluation License
+ Agreement. If the user filled the \c DetailsPage, the license
+ text is a First-Time License Agreement. If the user provided an
+ upgrade key and skipped the \c DetailsPage, the license text is
+ an Update License Agreement.
+
+ \snippet dialogs/licensewizard/licensewizard.cpp 28
+
+ We want to display a \uicontrol Print button in the wizard when the \c
+ ConclusionPage is up. One way to accomplish this is to reimplement
+ QWidget::setVisible():
+
+ \list
+ \li If the page is shown, we set the \l{QWizard::}{CustomButton1} button's
+ text to \uicontrol{\underline{P}rint}, we enable the \l{QWizard::}{HaveCustomButton1}
+ option, and we connect the QWizard's \l{QWizard::}{customButtonClicked()}
+ signal to our \c printButtonClicked() slot.
+ \li If the page is hidden, we disable the \l{QWizard::}{HaveCustomButton1}
+ option and disconnect the \c printButtonClicked() slot.
+ \endlist
+
+ \sa QWizard, {Class Wizard Example}, {Trivial Wizard Example}
+*/
diff --git a/examples/widgets/doc/lighting.qdoc b/examples/widgets/doc/lighting.qdoc
new file mode 100644
index 0000000000..aafa70f38c
--- /dev/null
+++ b/examples/widgets/doc/lighting.qdoc
@@ -0,0 +1,33 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example effects/lighting
+ \title Lighting Effect Example
+
+ \image lightingeffect-example.png
+*/
diff --git a/examples/widgets/doc/lineedits.qdoc b/examples/widgets/doc/lineedits.qdoc
new file mode 100644
index 0000000000..c9cb7b5f43
--- /dev/null
+++ b/examples/widgets/doc/lineedits.qdoc
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/lineedits
+ \title Line Edits Example
+
+ The Line Edits example demonstrates the many ways that QLineEdit can be used, and
+ shows the effects of various properties and validators on the input and output
+ supplied by the user.
+
+ \image lineedits-example.png
+
+ The example consists of a single \c Window class, containing a selection of
+ line edits with different input constraints and display properties that can be
+ changed by selecting items from comboboxes. Presenting these together helps
+ developers choose suitable properties to use with line edits, and makes it easy
+ to compare the effects of each validator on user input.
+
+ \section1 Window Class Definition
+
+ The \c Window class inherits QWidget and contains a constructor and several
+ slots:
+
+ \snippet widgets/lineedits/window.h 0
+
+ The slots are used to update the type of validator used for a given line edit when
+ a new validator has been selected in the associated combobox. The line edits
+ are stored in the window for use in these slots.
+
+ \section1 Window Class Implementation
+
+ The \c Window constructor is used to set up the line edits, validators,
+ and comboboxes, connect signals from the comboboxes to slots in the \c Window
+ class, and arrange the child widgets in layouts.
+
+ We begin by constructing a \l{QGroupBox}{group box} to hold a label, combobox,
+ and line edit so that we can demonstrate the QLineEdit::echoMode property:
+
+ \snippet widgets/lineedits/window.cpp 0
+
+ At this point, none of these widgets have been arranged in layouts. Eventually,
+ the \c echoLabel, \c echoComboBox, and \c echoLineEdit will be placed in a
+ vertical layout inside the \c echoGroup group box.
+
+ Similarly, we construct group boxes and collections of widgets to show the
+ effects of QIntValidator and QDoubleValidator on a line edit's contents:
+
+ \snippet widgets/lineedits/window.cpp 1
+
+ Text alignment is demonstrated by another group of widgets:
+
+ \snippet widgets/lineedits/window.cpp 2
+
+ QLineEdit supports the use of \l{QLineEdit::inputMask}{input masks}.
+ These only allow the user to type characters into the line edit that
+ follow a simple specification. We construct a group of widgets to
+ demonstrate a selection of predefined masks:
+
+ \snippet widgets/lineedits/window.cpp 3
+
+ Another useful feature of QLineEdit is its ability to make its contents
+ read-only. This property is used to control access to a line edit in the
+ following group of widgets:
+
+ \snippet widgets/lineedits/window.cpp 4
+
+ Now that all the child widgets have been constructed, we connect signals
+ from the comboboxes to slots in the \c Window object:
+
+ \snippet widgets/lineedits/window.cpp 5
+
+ Each of these connections use the QComboBox::activated() signal that
+ supplies an integer to the slot. This will be used to efficiently
+ make changes to the appropriate line edit in each slot.
+
+ We place each combobox, line edit, and label in a layout for each group
+ box, beginning with the layout for the \c echoGroup group box:
+
+ \snippet widgets/lineedits/window.cpp 6
+
+ The other layouts are constructed in the same way:
+
+ \snippet widgets/lineedits/window.cpp 7
+
+ Finally, we place each group box in a grid layout for the \c Window object
+ and set the window title:
+
+ \snippet widgets/lineedits/window.cpp 8
+
+ The slots respond to signals emitted when the comboboxes are changed by the
+ user.
+
+ When the combobox for the \uicontrol{Echo} group box is changed, the \c echoChanged()
+ slot is called:
+
+ \snippet widgets/lineedits/window.cpp 9
+
+ The slot updates the line edit in the same group box to use an echo mode that
+ corresponds to the entry described in the combobox.
+
+ When the combobox for the \uicontrol{Validator} group box is changed, the
+ \c validatorChanged() slot is called:
+
+ \snippet widgets/lineedits/window.cpp 10
+
+ The slot either creates a new validator for the line edit to use, or it removes
+ the validator in use by calling QLineEdit::setValidator() with a zero pointer.
+ We clear the line edit in this case to ensure that the new validator is
+ initially given valid input to work with.
+
+ When the combobox for the \uicontrol{Alignment} group box is changed, the
+ \c alignmentChanged() slot is called:
+
+ \snippet widgets/lineedits/window.cpp 11
+
+ This changes the way that text is displayed in the line edit to correspond with
+ the description selected in the combobox.
+
+ The \c inputMaskChanged() slot handles changes to the combobox in the
+ \uicontrol{Input Mask} group box:
+
+ \snippet widgets/lineedits/window.cpp 12
+
+ Each entry in the relevant combobox is associated with an input mask. We set
+ a new mask by calling the QLineEdit::setMask() function with a suitable string;
+ the mask is disabled if an empty string is used.
+
+ The \c accessChanged() slot handles changes to the combobox in the
+ \uicontrol{Access} group box:
+
+ \snippet widgets/lineedits/window.cpp 13
+
+ Here, we simply associate the \uicontrol{False} and \uicontrol{True} entries in the combobox
+ with \c false and \c true values to be passed to QLineEdit::setReadOnly(). This
+ allows the user to enable and disable input to the line edit.
+*/
diff --git a/examples/widgets/doc/mainwindow.qdoc b/examples/widgets/doc/mainwindow.qdoc
new file mode 100644
index 0000000000..b4f6aebed1
--- /dev/null
+++ b/examples/widgets/doc/mainwindow.qdoc
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example mainwindows/mainwindow
+ \title Main Window
+
+ The Main Window example shows Qt's extensive support for tool bars,
+ dock windows, menus, and other standard application features.
+
+ \image mainwindow-demo.png
+*/
diff --git a/examples/widgets/doc/mdi.qdoc b/examples/widgets/doc/mdi.qdoc
new file mode 100644
index 0000000000..e8b1b5c9ef
--- /dev/null
+++ b/examples/widgets/doc/mdi.qdoc
@@ -0,0 +1,37 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example mainwindows/mdi
+ \title MDI Example
+
+ The MDI example shows how to implement a Multiple Document Interface using Qt's
+ QMdiArea class.
+
+ \image mdi-example.png
+
+*/
diff --git a/examples/widgets/doc/menus.qdoc b/examples/widgets/doc/menus.qdoc
new file mode 100644
index 0000000000..3531e439c1
--- /dev/null
+++ b/examples/widgets/doc/menus.qdoc
@@ -0,0 +1,218 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example mainwindows/menus
+ \title Menus Example
+
+ The Menus example demonstrates how menus can be used in a main
+ window application.
+
+ A menu widget can be either a pull-down menu in a menu bar or a
+ standalone context menu. Pull-down menus are shown by the menu bar
+ when the user clicks on the respective item or presses the
+ specified shortcut key. Context menus are usually invoked by some
+ special keyboard key or by right-clicking.
+
+ \image menus-example.png
+
+ A menu consists of a list of \e action items. In applications,
+ many common commands can be invoked via menus, toolbar buttons as
+ well as keyboard shortcuts. Since the user expects the commands to
+ be performed in the same way, regardless of the user interface
+ used, it is useful to represent each command as an action.
+
+ The Menus example consists of one single class, \c MainWindow, derived
+ from the QMainWindow class. When choosing one of the
+ action items in our application, it will display the item's path
+ in its central widget.
+
+ \section1 MainWindow Class Definition
+
+ QMainWindow provides a main application window, with a menu bar,
+ tool bars, dock widgets and a status bar around a large central
+ widget.
+
+ \snippet mainwindows/menus/mainwindow.h 0
+
+ In this example, we will see how to implement pull-down menus as
+ well as a context menu. In order to implement a custom context
+ menu we must reimplement QWidget's \l
+ {QWidget::}{contextMenuEvent()} function to receive the context
+ menu events for our main window.
+
+ \snippet mainwindows/menus/mainwindow.h 1
+
+ We must also implement a collection of private slots to respond to
+ the user activating any of our menu entries. Note that these
+ slots are left out of this documentation since they are trivial,
+ i.e., most of them are only displaying the action's path in the
+ main window's central widget.
+
+ \snippet mainwindows/menus/mainwindow.h 2
+
+ We have chosen to simplify the constructor by implementing two
+ private convenience functions to create the various actions, to
+ add them to menus and to insert the menus into our main window's
+ menu bar.
+
+ \snippet mainwindows/menus/mainwindow.h 3
+
+ Finally, we declare the various menus and actions as well as a
+ simple information label in the application wide scope.
+
+ The QMenu class provides a menu widget for use in menu bars,
+ context menus, and other popup menus while the QAction class
+ provides an abstract user interface action that can be inserted
+ into widgets.
+
+ In some situations it is useful to group actions together, e.g.,
+ we have a \uicontrol {Left Align} action, a \uicontrol {Right Align} action, a
+ \uicontrol {Justify} action, and a \uicontrol {Center} action, and we want
+ only one of these actions to be active at any one time. One simple
+ way of achieving this is to group the actions together in an
+ action group using the QActionGroup class.
+
+ \section1 MainWindow Class Implementation
+
+ In the constructor, we start off by creating a regular QWidget and
+ make it our main window's central widget. Note that the main
+ window takes ownership of the widget pointer and deletes it at the
+ appropriate time.
+
+ \snippet mainwindows/menus/mainwindow.cpp 0
+ \codeline
+ \snippet mainwindows/menus/mainwindow.cpp 1
+
+ Then we create the information label as well as a top and bottom
+ filler that we add to a layout which we install on the central
+ widget. QMainWindow objects come with their own customized layout
+ and setting a layout on a the actual main window, or creating a
+ layout with a main window as a parent, is considered an error. You
+ should always set your own layout on the central widget instead.
+
+ \snippet mainwindows/menus/mainwindow.cpp 2
+
+ To create the actions and menus we call our two convenience
+ functions: \c createActions() and \c createMenus(). We will get
+ back to these shortly.
+
+ QMainWindow's \l {QMainWindow::statusBar()}{statusBar()} function
+ returns the status bar for the main window (if the status bar does
+ not exist, this function will create and return an empty status
+ bar). We initialize the status bar and window title, resize the
+ window to an appropriate size as well as ensure that the main
+ window cannot be resized to a smaller size than the given
+ one.
+
+ Now, let's take a closer look at the \c createActions() convenience
+ function that creates the various actions:
+
+ \snippet mainwindows/menus/mainwindow.cpp 4
+ \dots
+
+ A QAction object may contain an icon, a text, a shortcut, a status
+ tip, a "What's This?" text, and a tooltip. Most of these can be
+ set in the constructor, but they can also be set independently
+ using the provided convenience functions.
+
+ In the \c createActions() function, we first create a \c newAct
+ action. We make \uicontrol Ctrl+N its shortcut using the
+ QAction::setShortcut() function, and we set its status tip using the
+ QAction::setStatusTip() function (the status tip is displayed on all
+ status bars provided by the action's top-level parent widget). We
+ also connect its \l {QAction::}{triggered()} signal to the \c
+ newFile() slot.
+
+ The rest of the actions are created in a similar manner. Please
+ see the source code for details.
+
+ \snippet mainwindows/menus/mainwindow.cpp 7
+
+
+ Once we have created the \uicontrol {Left Align}, \uicontrol {Right Align},
+ \uicontrol {Justify}, and a \uicontrol {Center} actions, we can also create
+ the previously mentioned action group.
+
+ Each action is added to the group using QActionGroup's \l
+ {QActionGroup::}{addAction()} function. Note that an action also
+ can be added to a group by creating it with the group as its
+ parent. Since an action group is exclusive by default, only one of
+ the actions in the group is checked at any one time (this can be
+ altered using the QActionGroup::setExclusive() function).
+
+ When all the actions are created, we use the \c createMenus()
+ function to add the actions to the menus and to insert the menus
+ into the menu bar:
+
+ \snippet mainwindows/menus/mainwindow.cpp 8
+
+ QMenuBar's \l {QMenuBar::addMenu()}{addMenu()} function appends a
+ new QMenu with the given title, to the menu bar (note that the
+ menu bar takes ownership of the menu). We use QWidget's \l
+ {QWidget::addAction()}{addAction()} function to add each action to
+ the corresponding menu.
+
+ Alternatively, the QMenu class provides several \l
+ {QMenu::addAction()}{addAction()} convenience functions that create
+ and add new actions from given texts and/or icons. You can also
+ provide a member that will automatically connect to the new
+ action's \l {QAction::triggered()}{triggered()} signal, and a
+ shortcut represented by a QKeySequence instance.
+
+ The QMenu::addSeparator() function creates and returns a new
+ separator action, i.e. an action for which QAction::isSeparator()
+ returns true, and adds the new action to the menu's list of
+ actions.
+
+ \snippet mainwindows/menus/mainwindow.cpp 12
+
+ Note the \uicontrol Format menu. First of all, it is added as a submenu
+ to the \uicontrol Edit Menu using QMenu's \l
+ {QMenu::addMenu()}{addMenu()} function. Secondly, take a look at the
+ alignment actions: In the \c createActions() function we added the
+ \c leftAlignAct, \c rightAlignAct, \c justifyAct and \c centerAct
+ actions to an action group. Nevertheless, we must add each action
+ to the menu separately while the action group does its magic
+ behind the scene.
+
+ \snippet mainwindows/menus/mainwindow.cpp 3
+
+ To provide a custom context menu, we must reimplement QWidget's \l
+ {QWidget::}{contextMenuEvent()} function to receive the widget's
+ context menu events (note that the default implementation simply
+ ignores these events).
+
+ Whenever we receive such an event, we create a menu containing the
+ \uicontrol Cut, \uicontrol Copy and \uicontrol Paste actions. Context menus can be
+ executed either asynchronously using the \l {QMenu::}{popup()}
+ function or synchronously using the \l {QMenu::}{exec()}
+ function. In this example, we have chosen to show the menu using
+ its \l {QMenu::}{exec()} function. By passing the event's position
+ as argument we ensure that the context menu appears at the
+ expected position.
+*/
diff --git a/examples/widgets/doc/moveblocks.qdoc b/examples/widgets/doc/moveblocks.qdoc
new file mode 100644
index 0000000000..8c12280989
--- /dev/null
+++ b/examples/widgets/doc/moveblocks.qdoc
@@ -0,0 +1,214 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example animation/moveblocks
+ \title Move Blocks Example
+
+ The Move Blocks example shows how to animate items in a
+ QGraphicsScene using a QStateMachine with a custom transition.
+
+ \image moveblocks-example.png
+
+ The example animates the blue blocks that you can see in the image
+ above. The animation moves the blocks between four preset positions.
+
+ The example consists of the following classes:
+
+ \list
+ \li \c StateSwitcher inherits QState and can add
+ \c {StateSwitchTransition}s to other states.
+ When entered, it will randomly transition to one of these
+ states.
+ \li \c StateSwitchTransition is a custom transition that
+ triggers on \c{StateSwitchEvent}s.
+ \li \c StateSwitchEvent is a QEvent that triggers \c{StateSwitchTransition}s.
+ \li \c QGraphicsRectWidget is a QGraphicsWidget that simply
+ paints its background in a solid \l{Qt::}{blue} color.
+ \endlist
+
+ The blocks are instances of \c QGraphicsRectWidget and are
+ animated in a QGraphicsScene. We do this by building a state
+ graph, which we insert animations into. The graph is then executed
+ in a QStateMachine. All this is done in \c main().
+ Let's look at the \c main() function first.
+
+ \section1 The \c main() Function
+
+ After QApplication has been initialized, we set up the
+ QGraphicsScene with its \c{QGraphicsRectWidget}s.
+
+ \snippet animation/moveblocks/main.cpp 1
+
+ After adding the scene to a QGraphicsView, it is time to build the
+ state graph. Let's first look at a statechart of what we are
+ trying to build.
+
+ \image move-blocks-chart.png
+
+ Note that the \c group has seven sub states, but we have only
+ included three of them in the diagram. The code that builds this
+ graph will be examined line-by-line, and will show how the graph
+ works. First off, we construct the \c group state:
+
+ \snippet animation/moveblocks/main.cpp 2
+
+ The timer is used to add a delay between each time the blocks are
+ moved. The timer is started when \c group is entered. As we will
+ see later, \c group has a transition back to the \c StateSwitcher
+ when the timer times out. \c group is the initial state in the
+ machine, so an animation will be scheduled when the example is
+ started.
+
+ \snippet animation/moveblocks/main.cpp 3
+ \dots
+ \snippet animation/moveblocks/main.cpp 4
+
+ \c createGeometryState() returns a QState that will set the
+ geometry of our items upon entry. It also assigns \c group as the
+ parent of this state.
+
+ A QPropertyAnimation inserted into a transition will use the
+ values assigned to a QState (with QState::assignProperty()), i.e.,
+ the animation will interpolate between the current values of the
+ properties and the values in the target state. We add animated
+ transitions to the state graph later.
+
+ \snippet animation/moveblocks/main.cpp 5
+
+ We move the items in parallel. Each item is added to \c
+ animationGroup, which is the animation that is inserted into the
+ transitions.
+
+ \snippet animation/moveblocks/main.cpp 6
+
+ The sequential animation group, \c subGroup, helps us insert a
+ delay between the animation of each item.
+
+ \snippet animation/moveblocks/main.cpp 7
+ \dots
+ \snippet animation/moveblocks/main.cpp 8
+
+ A StateSwitchTransition is added to the state switcher
+ in \c StateSwitcher::addState(). We also add the animation in this
+ function. Since QPropertyAnimation uses the values from the
+ states, we can insert the same QPropertyAnimation instance in all
+ \c {StateSwitchTransition}s.
+
+ As mentioned previously, we add a transition to the state switcher
+ that triggers when the timer times out.
+
+ \snippet animation/moveblocks/main.cpp 9
+
+ Finally, we can create the state machine, add our initial state,
+ and start execution of the state graph.
+
+ \section2 The \c createGeometryState() Function
+
+ In \c createGeometryState(), we set up the geometry for each
+ graphics item.
+
+ \snippet animation/moveblocks/main.cpp 13
+
+ As mentioned before, QAbstractTransition will set up an animation
+ added with \l{QAbstractTransition::}{addAnimation()} using
+ property values set with \l{QState::}{assignProperty()}.
+
+ \section1 The StateSwitcher Class
+
+ \c StateSwitcher has state switch transitions to each \l{QState}s
+ we created with \c createGeometryState(). Its job is to transition
+ to one of these states at random when it is entered.
+
+ All functions in \c StateSwitcher are inlined. We'll step through
+ its definition.
+
+ \snippet animation/moveblocks/main.cpp 10
+
+ \c StateSwitcher is a state designed for a particular purpose and
+ will always be a top-level state. We use \c m_stateCount to keep
+ track of how many states we are managing, and \c m_lastIndex to
+ remember which state was the last state to which we transitioned.
+
+ \snippet animation/moveblocks/main.cpp 11
+
+ We select the next state we are going to transition to, and post a
+ \c StateSwitchEvent, which we know will trigger the \c
+ StateSwitchTransition to the selected state.
+
+ \snippet animation/moveblocks/main.cpp 12
+
+ This is where the magic happens. We assign a number to each state
+ added. This number is given to both a StateSwitchTransition and to
+ StateSwitchEvents. As we have seen, state switch events will
+ trigger a transition with the same number.
+
+ \section1 The StateSwitchTransition Class
+
+ \c StateSwitchTransition inherits QAbstractTransition and triggers
+ on \c{StateSwitchEvent}s. It contains only inline functions, so
+ let's take a look at its \l{QAbstractTransition::}{eventTest()}
+ function, which is the only function that we define..
+
+ \snippet animation/moveblocks/main.cpp 14
+
+ \c eventTest is called by QStateMachine when it checks whether a
+ transition should be triggered--a return value of true means that
+ it will. We simply check if our assigned number is equal to the
+ event's number (in which case we fire away).
+
+ \section1 The StateSwitchEvent Class
+
+ \c StateSwitchEvent inherits QEvent, and holds a number that has
+ been assigned to a state and state switch transition by
+ \c StateSwitcher. We have already seen how it is used to trigger
+ \c{StateSwitchTransition}s in \c StateSwitcher.
+
+ \snippet animation/moveblocks/main.cpp 15
+
+ We only have inlined functions in this class, so a look at its
+ definition will do.
+
+ \section1 The QGraphicsRectWidget Class
+
+ QGraphicsRectWidget inherits QGraphicsWidget and simply paints its
+ \l{QWidget::}{rect()} blue. We inline \l{QWidget::}{paintEvent()},
+ which is the only function we define. Here is the
+ QGraphicsRectWidget class definition:
+
+ \snippet animation/moveblocks/main.cpp 16
+
+ \section1 Moving On
+
+ The technique shown in this example works equally well for all
+ \l{QPropertyAnimation}s. As long as the value to be animated is a
+ Qt property, you can insert an animation of it into a state graph.
+
+ QState::addAnimation() takes a QAbstractAnimation, so any type
+ of animation can be inserted into the graph.
+*/
+
diff --git a/examples/widgets/doc/movie.qdoc b/examples/widgets/doc/movie.qdoc
new file mode 100644
index 0000000000..7573d796c3
--- /dev/null
+++ b/examples/widgets/doc/movie.qdoc
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/movie
+ \title Movie Example
+
+ The Movie example demonstrates how to use QMovie and QLabel to
+ display animations. Now that Qt comes with the \l{Phonon multimedia
+ framework} {Phonon multimedia framework}, QMovie is mostly
+ useful if one wants to play a simple animation without the added
+ complexity of a multimedia framework to install and deploy.
+
+ \image movie-example.png
+*/
diff --git a/examples/widgets/doc/orderform.qdoc b/examples/widgets/doc/orderform.qdoc
new file mode 100644
index 0000000000..ed40c65093
--- /dev/null
+++ b/examples/widgets/doc/orderform.qdoc
@@ -0,0 +1,364 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example richtext/orderform
+ \title Order Form Example
+
+ The Order Form example shows how to generate rich text documents by
+ combining a simple template with data input by the user in a dialog. Data
+ is extracted from a \c DetailsDialog object and displayed on a QTextEdit
+ with a QTextCursor, using various formats. Each form generated is added
+ to a QTabWidget for easy access.
+
+ \image orderform-example.png
+
+ \section1 DetailsDialog Definition
+
+ The \c DetailsDialog class is a subclass of QDialog, implementing a slot
+ \c verify() to allow contents of the \c DetailsDialog to be verified later.
+ This is further explained in \c DetailsDialog Implementation.
+
+ \snippet richtext/orderform/detailsdialog.h 0
+
+ The constructor of \c DetailsDialog accepts parameters \a title and
+ \a parent. The class defines four \e{getter} functions: \c orderItems(),
+ \c senderName(), \c senderAddress(), and \c sendOffers() to allow data
+ to be accessed externally.
+
+ The class definition includes input widgets for the required
+ fields, \c nameEdit and \c addressEdit. Also, a QCheckBox and a
+ QDialogButtonBox are defined; the former to provide the user with the
+ option to receive information on products and offers, and the latter
+ to ensure that buttons used are arranged according to the user's native
+ platform. In addition, a QTableWidget, \c itemsTable, is used to hold
+ order details.
+
+ The screenshot below shows the \c DetailsDialog we intend to create.
+
+ \image orderform-example-detailsdialog.png
+
+ \section1 DetailsDialog Implementation
+
+ The constructor of \c DetailsDialog instantiates the earlier defined fields
+ and their respective labels. The label for \c offersCheckBox is set and the
+ \c setupItemsTable() function is invoked to setup and populate
+ \c itemsTable. The QDialogButtonBox object, \c buttonBox, is instantiated
+ with \uicontrol OK and \uicontrol Cancel buttons. This \c buttonBox's \c accepted() and
+ \c rejected() signals are connected to the \c verify() and \c reject()
+ slots in \c DetailsDialog.
+
+ \snippet richtext/orderform/detailsdialog.cpp 0
+
+ A QGridLayout is used to place all the objects on the \c DetailsDialog.
+
+ \snippet richtext/orderform/detailsdialog.cpp 1
+
+ The \c setupItemsTable() function instantiates the QTableWidget object,
+ \c itemsTable, and sets the number of rows based on the QStringList
+ object, \c items, which holds the type of items ordered. The number of
+ columns is set to 2, providing a "name" and "quantity" layout. A \c for
+ loop is used to populate the \c itemsTable and the \c name item's flag
+ is set to Qt::ItemIsEnabled or Qt::ItemIsSelectable. For demonstration
+ purposes, the \c quantity item is set to a 1 and all items in the
+ \c itemsTable have this value for quantity; but this can be modified by
+ editing the contents of the cells at run time.
+
+ \snippet richtext/orderform/detailsdialog.cpp 2
+
+ The \c orderItems() function extracts data from the \c itemsTable and
+ returns it in the form of a QList<QPair<QString,int>> where each QPair
+ corresponds to an item and the quantity ordered.
+
+ \snippet richtext/orderform/detailsdialog.cpp 3
+
+ The \c senderName() function is used to return the value of the QLineEdit
+ used to store the name field for the order form.
+
+ \snippet richtext/orderform/detailsdialog.cpp 4
+
+ The \c senderAddress() function is used to return the value of the
+ QTextEdit containing the address for the order form.
+
+ \snippet richtext/orderform/detailsdialog.cpp 5
+
+ The \c sendOffers() function is used to return a \c true or \c false
+ value that is used to determine if the customer in the order form
+ wishes to receive more information on the company's offers and promotions.
+
+ \snippet richtext/orderform/detailsdialog.cpp 6
+
+ The \c verify() function is an additionally implemented slot used to
+ verify the details entered by the user into the \c DetailsDialog. If
+ the details entered are incomplete, a QMessageBox is displayed
+ providing the user the option to discard the \c DetailsDialog. Otherwise,
+ the details are accepted and the \c accept() function is invoked.
+
+ \snippet richtext/orderform/detailsdialog.cpp 7
+
+ \section1 MainWindow Definition
+
+ The \c MainWindow class is a subclass of QMainWindow, implementing two
+ slots - \c openDialog() and \c printFile(). It also contains a private
+ instance of QTabWidget, \c letters.
+
+ \snippet richtext/orderform/mainwindow.h 0
+
+ \section1 MainWindow Implementation
+
+ The \c MainWindow constructor sets up the \c fileMenu and the required
+ actions, \c newAction and \c printAction. These actions' \c triggered()
+ signals are connected to the additionally implemented openDialog() slot
+ and the default close() slot. The QTabWidget, \c letters, is
+ instantiated and set as the window's central widget.
+
+ \snippet richtext/orderform/mainwindow.cpp 0
+
+ The \c createLetter() function creates a new QTabWidget with a QTextEdit,
+ \c editor, as the parent. This function accepts four parameters that
+ correspond to we obtained through \c DetailsDialog, in order to "fill"
+ the \c editor.
+
+ \snippet richtext/orderform/mainwindow.cpp 1
+
+ We then obtain the cursor for the \c editor using QTextEdit::textCursor().
+ The \c cursor is then moved to the start of the document using
+ QTextCursor::Start.
+
+ \snippet richtext/orderform/mainwindow.cpp 2
+
+ Recall the structure of a \l{Rich Text Document Structure}
+ {Rich Text Document}, where sequences of frames and
+ tables are always separated by text blocks, some of which may contain no
+ information.
+
+ In the case of the Order Form Example, the document structure for this portion
+ is described by the table below:
+
+ \table
+ \row
+ \li {1, 8} frame with \e{referenceFrameFormat}
+ \row
+ \li block \li \c{A company}
+ \row
+ \li block
+ \row
+ \li block \li \c{321 City Street}
+ \row
+ \li block
+ \row
+ \li block \li \c{Industry Park}
+ \row
+ \li block
+ \row
+ \li block \li \c{Another country}
+ \endtable
+
+ This is accomplished with the following code:
+
+ \snippet richtext/orderform/mainwindow.cpp 3
+
+ Note that \c topFrame is the \c {editor}'s top-level frame and is not shown
+ in the document structure.
+
+ We then set the \c{cursor}'s position back to its last position in
+ \c topFrame and fill in the customer's name (provided by the constructor)
+ and address - using a \c foreach loop to traverse the QString, \c address.
+
+ \snippet richtext/orderform/mainwindow.cpp 4
+
+ The \c cursor is now back in \c topFrame and the document structure for
+ the above portion of code is:
+
+ \table
+ \row
+ \li block \li \c{Donald}
+ \row
+ \li block \li \c{47338 Park Avenue}
+ \row
+ \li block \li \c{Big City}
+ \endtable
+
+ For spacing purposes, we invoke \l{QTextCursor::insertBlock()}
+ {insertBlock()} twice. The \l{QDate::currentDate()}{currentDate()} is
+ obtained and displayed. We use \l{QTextFrameFormat::setWidth()}
+ {setWidth()} to increase the width of \c bodyFrameFormat and we insert
+ a new frame with that width.
+
+ \snippet richtext/orderform/mainwindow.cpp 5
+
+ The following code inserts standard text into the order form.
+
+ \snippet richtext/orderform/mainwindow.cpp 6
+ \snippet richtext/orderform/mainwindow.cpp 7
+
+ This part of the document structure now contains the date, a frame with
+ \c bodyFrameFormat, as well as the standard text.
+
+ \table
+ \row
+ \li block
+ \row
+ \li block
+ \row
+ \li block \li \c{Date: 25 May 2007}
+ \row
+ \li block
+ \row
+ \li {1, 4} frame with \e{bodyFrameFormat}
+ \row
+ \li block \li \c{I would like to place an order for the following items:}
+ \row
+ \li block
+ \row
+ \li block
+ \endtable
+
+ A QTextTableFormat object, \c orderTableFormat, is used to hold the type
+ of item and the quantity ordered.
+
+ \snippet richtext/orderform/mainwindow.cpp 8
+
+ We use \l{QTextTable::cellAt()}{cellAt()} to set the headers for the
+ \c orderTable.
+
+ \snippet richtext/orderform/mainwindow.cpp 9
+
+ Then, we iterate through the QList of QPair objects to populate
+ \c orderTable.
+
+ \snippet richtext/orderform/mainwindow.cpp 10
+
+ The resulting document structure for this section is:
+
+ \table
+ \row
+ \li {1, 11} \c{orderTable} with \e{orderTableFormat}
+ \row
+ \li block \li \c{Product}
+ \row
+ \li block \li \c{Quantity}
+ \row
+ \li block \li \c{T-shirt}
+ \row
+ \li block \li \c{4}
+ \row
+ \li block \li \c{Badge}
+ \row
+ \li block \li \c{3}
+ \row
+ \li block \li \c{Reference book}
+ \row
+ \li block \li \c{2}
+ \row
+ \li block \li \c{Coffee cup}
+ \row
+ \li block \li \c{5}
+ \endtable
+
+ The \c cursor is then moved back to \c{topFrame}'s
+ \l{QTextFrame::lastPosition()}{lastPosition()} and more standard text
+ is inserted.
+
+ \snippet richtext/orderform/mainwindow.cpp 11
+ \snippet richtext/orderform/mainwindow.cpp 12
+
+ Another QTextTable is inserted, to display the customer's
+ preference regarding offers.
+
+ \snippet richtext/orderform/mainwindow.cpp 13
+
+ The document structure for this portion is:
+
+ \table
+ \row
+ \li block
+ \row
+ \li block\li \c{Please update my...}
+ \row
+ \li {1, 5} block
+ \row
+ \li {1, 4} \c{offersTable}
+ \row
+ \li block \li \c{I want to receive...}
+ \row
+ \li block \li \c{I do not want to receive...}
+ \row
+ \li block \li \c{X}
+ \endtable
+
+ The \c cursor is moved to insert "Sincerely" along with the customer's
+ name. More blocks are inserted for spacing purposes. The \c printAction
+ is enabled to indicate that an order form can now be printed.
+
+ \snippet richtext/orderform/mainwindow.cpp 14
+
+ The bottom portion of the document structure is:
+
+ \table
+ \row
+ \li block
+ \row
+ \li {1, 5} block\li \c{Sincerely,}
+ \row
+ \li block
+ \row
+ \li block
+ \row
+ \li block
+ \row
+ \li block \li \c{Donald}
+ \endtable
+
+ The \c createSample() function is used for illustration purposes, to create
+ a sample order form.
+
+ \snippet richtext/orderform/mainwindow.cpp 15
+
+ The \c openDialog() function opens a \c DetailsDialog object. If the
+ details in \c dialog are accepted, the \c createLetter() function is
+ invoked using the parameters extracted from \c dialog.
+
+ \snippet richtext/orderform/mainwindow.cpp 16
+
+ In order to print out the order form, a \c printFile() function is
+ included, as shown below:
+
+ \snippet richtext/orderform/mainwindow.cpp 17
+
+ This function also allows the user to print a selected area with
+ QTextCursor::hasSelection(), instead of printing the entire document.
+
+ \section1 \c main() Function
+
+ The \c main() function instantiates \c MainWindow and sets its size to
+ 640x480 pixels before invoking the \c show() function and
+ \c createSample() function.
+
+ \snippet richtext/orderform/main.cpp 0
+
+*/
diff --git a/examples/widgets/doc/padnavigator.qdoc b/examples/widgets/doc/padnavigator.qdoc
new file mode 100644
index 0000000000..8b1da516b5
--- /dev/null
+++ b/examples/widgets/doc/padnavigator.qdoc
@@ -0,0 +1,583 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example graphicsview/padnavigator
+ \title Pad Navigator Example
+
+ The Pad Navigator Example shows how you can use Graphics View together with
+ embedded widgets and Qt's \l{State Machine Framework} to create a simple
+ but useful, dynamic, animated user interface.
+
+ \image padnavigator-example.png
+
+ The interface consists of a flippable, rotating pad with icons that can be
+ selected using the arrow keys on your keyboard or keypad. Pressing enter
+ will flip the pad around and reveal its back side, which has a form
+ embedded into a QGraphicsProxyWidget. You can interact with the form, and
+ press the enter key to flip back to the front side of the pad at any time.
+
+ Graphics View provides the QGraphicsScene class for managing and
+ interacting with a large number of custom-made 2D graphical items derived
+ from the QGraphicsItem class, and a QGraphicsView widget for visualizing
+ the items, with support for zooming and rotation.
+
+ This example consists of a \c RoundRectItem class, a \c FlippablePad class,
+ a \c PadNavigator class, a \c SplashItem class, and a \c main() function.
+
+ \section1 RoundRectItem Class Definition
+
+ The \c RoundRectItem class is used by itself to display the icons on the
+ pad, and as a base class for \c FlippablePad, the class for the pad itself.
+ The role of the class is to paint a round rectangle of a specified size and
+ gradient color, and optionally to paint a pixmap icon on top. To support \c
+ FlippablePad it also allows filling its contents with a plain window
+ background color.
+
+ Let's start by reviewing the \c RoundRectItem class declaration.
+
+ \snippet graphicsview/padnavigator/roundrectitem.h 0
+
+ \c RoundRectItem inherits QGraphicsObject, which makes it easy to control
+ its properties using QPropertyAnimation. Its constructor takes a rectangle
+ to determine its bounds, and a color.
+
+ Besides implementing the mandatory \l{QGraphicsItem::paint()}{paint()} and
+ \l{QGraphicsItem::boundingRect()}{boundingRect()} pure virtual functions,
+ it also provides the \c pixmap and \c fill properties.
+
+ The \c pixmap property sets an optional pixmap that is drawn on top of the
+ round rectangle. The \c fill property will, when true, fill the round
+ rectangle contents with a fixed QPalette::Window background color.
+ Otherwise the contents are filled using a gradient based on the color
+ passed to \c RoundRectItem's constructor.
+
+ \snippet graphicsview/padnavigator/roundrectitem.h 1
+
+ The private data members are:
+
+ \list
+ \li \c pix: The optional pixmap that is drawn on top of the rectangle.
+ \li \c fillRect: Corresponds to the \c fill property.
+ \li \c color: The configurable gradient color fill of the rectangle.
+ \li \c bounds: The bounds of the rectangle.
+ \li \c gradient: A precalculated gradient used to fill the rectangle.
+ \endlist
+
+ We will now review the \c RoundRectItem implementation. Let's start by
+ looking at its constructor:
+
+ \snippet graphicsview/padnavigator/roundrectitem.cpp 0
+
+ The constructor initializes its member variables and forwards the \c parent
+ argument to QGraphicsObject's constructor. It then constructs the linear
+ gradient that is used in \l{QGraphicsItem::paint()}{paint()} to draw the
+ round rectangle's gradient background. The linear gradient's starting point
+ is at the top-left corner of the bounds, and the end is at the bottom-left
+ corner. The start color is identical to the color passed as an argument,
+ and a slightly darker color is chosen for the final stop.
+
+ We store this gradient as a member variable to avoid having to recreate the
+ gradient every time the item is repainted.
+
+ Finally we set the cache mode
+ \l{QGraphicsItem::ItemCoordinateCache}{ItemCoordinateCache}. This mode
+ causes the item's rendering to be cached into an off-screen pixmap that
+ remains persistent as we move and transform the item. This mode is ideal
+ for this example, and works particularly well with OpenGL and OpenGL ES.
+
+ \snippet graphicsview/padnavigator/roundrectitem.cpp 1
+
+ The \c pixmap property implementation simple returns the member pixmap, or
+ sets it and then calls \l{QGraphicsItem::update()}{update()}.
+
+ \snippet graphicsview/padnavigator/roundrectitem.cpp 2
+
+ As the \l{QGraphicsItem::paint()}{paint()} implementation below draws a
+ simple drop shadow down and to the right of the item, we return a slightly
+ adjusted rectangle from \l{QGraphicsItem::boundingRect()}{boundingRect()}.
+
+ \snippet graphicsview/padnavigator/roundrectitem.cpp 3
+
+ The \l{QGraphicsItem::paint()}{paint()} implementation starts by rendering
+ a semi transparent black round rectangle drop shadow, two units down and to
+ the right of the main item.
+
+ \snippet graphicsview/padnavigator/roundrectitem.cpp 4
+
+ We then draw the "foreground" round rectangle itself. The fill depends on
+ the \c fill property; if true, we will with a plain QPalette::Window color.
+ We get the current brush from QApplication::palette(). We assign a single
+ unit wide pen for the stroke, assign the brush, and then draw the
+ rectangle.
+
+ \snippet graphicsview/padnavigator/roundrectitem.cpp 5
+
+ If a pixmap has been assigned to the \e pixmap property, we draw this
+ pixmap in the center of the rectangle item. The pixmaps are scaled to match
+ the size of the icons; in arguably a better approach would have been to
+ store the icons with the right size in the first places.
+
+ \snippet graphicsview/padnavigator/roundrectitem.cpp 6
+
+ Finally, for completeness we include the \c fill property implementation.
+ It returns the \c fill member variable's value, and when assigned to, it
+ calls \l{QGraphicsItem::update()}{update()}.
+
+ As mentioned already, \c RoundRectItem is the base class for \c
+ FlippablePad, which is the class representing the tilting pad itself. We
+ will proceed to reviewing \c FlippablePad.
+
+ \section1 FlippablePad Class Definition
+
+ \c FlippablePad is, in addition to its inherited \c RoundRectItem
+ responsibilities, responsible for creating and managing a grid of icons.
+
+ \snippet graphicsview/padnavigator/flippablepad.h 0
+
+ Its declaration is very simple: It inherits \c RoundRectItem and does not
+ need any special polymorphic behavior. It's suitable to declare its own
+ constructor, and a getter-function that allows \c PadNavigator to access
+ the icons in the grid by (row, column).
+
+ The example has no "real" behavior or logic of any kind, and because of
+ that, the icons do not need to provide any \e behavior or special
+ interactions management. In a real application, however, it would be
+ natural for the \c FlippablePad and its icons to handle more of the
+ navigation logic. In this example, we have chosen to leave this to
+ the \c PadNavigator class, which we will get back to below.
+
+ We will now review the \c FlippablePad implementation. This implementation
+ starts with two helper functions: \c boundsFromSize() and \c
+ posForLocation():
+
+ \snippet graphicsview/padnavigator/flippablepad.cpp 0
+
+ \c boundsForSize() takes a QSize argument, and returns the bounding
+ rectangle of the flippable pad item. The QSize determines how many rows and
+ columns the icon grid should have. Each icon is given 150x150 units of
+ space, and this determines the bounds.
+
+ \snippet graphicsview/padnavigator/flippablepad.cpp 1
+
+ \c posForLocation() returns the position of an icon given its row and
+ column position. Like \c boundsForSize(), the function assumes each icon is
+ given 150x150 units of space, and that all icons are centered around the
+ flippable pad item's origin (0, 0).
+
+ \snippet graphicsview/padnavigator/flippablepad.cpp 2
+
+ The \c FlippablePad constructor passes suitable bounds (using \c
+ boundsForSize()) and specific color to \c RoundRectItem's constructor.
+
+ \snippet graphicsview/padnavigator/flippablepad.cpp 3
+
+ It then loads pixmaps from compiled-in resources to use for its icons.
+ QDirIterator is very useful in this context, as it allows us to fetch all
+ resource "*.png" files inside the \c :/images directory without explicitly
+ naming the files.
+
+ We also make sure not to load more pixmaps than we need.
+
+ \snippet graphicsview/padnavigator/flippablepad.cpp 4
+
+ Now that we have the pixmaps, we can create icons, position then and assign
+ pixmaps. We start by finding a suitable size and color for the icons, and
+ initializing a convenient grid structure for storing the icons. This \c
+ iconGrid is also used later to find the icon for a specific (column, row)
+ location.
+
+ For each row and column in our grid, we proceed to constructing each icon
+ as an instance of \c RoundRectItem. The item is placed by using the \c
+ posForLocation() helper function. To make room for the slip-behind
+ selection item, we give each icon a \l{QGraphicsItem::zValue()}{Z-value} of
+ 1. The pixmaps are distributed to the icons in round-robin fasion.
+
+ Again, this approach is only suitable for example purposes. In a real-life
+ application where each icon represents a specific action, it would be more
+ natural to assign the pixmaps directly, or that the icons themselves
+ provide suitable pixmaps.
+
+ \snippet graphicsview/padnavigator/flippablepad.cpp 5
+
+ Finally, the \c iconAt() function returns a pointer to the icon at a
+ specific row and column. It makes a somewhat bold assumption that the input
+ is valid, which is fair because the \c PadNavigator class only calls this
+ function with correct input.
+
+ We will now review the \c SplashItem class.
+
+ \section1 SplashItem Class Definition
+
+ The \c SplashItem class represents the "splash window", a semitransparent
+ white overlay with text that appears immediately after the application has
+ started, and disappears after pressing any key. The animation is controlled
+ by \c PadNavigator; this class is very simple by itself.
+
+ \snippet graphicsview/padnavigator/splashitem.h 0
+
+ The class declaration shows that \c SplashItem inherits QGraphicsObject to
+ allow it to be controlled by QPropertyAnimation. It reimplements the
+ mandatory \l{QGraphicsItem::paint()}{paint()} and
+ \l{QGraphicsItem::boundingRect()}{boundingRect()} pure virtual functions,
+ and keeps a \c text member variable which will contain the information text
+ displayed on this splash item.
+
+ Let's look at its implementation.
+
+ \snippet graphicsview/padnavigator/splashitem.cpp 0
+
+ The constructor forwards to QGraphicsObject as expected, assigns a text
+ message to the \c text member variable, and enables
+ \l{QGraphicsItem::DeviceCoordinateCache}{DeviceCoordinateCache}. This cache
+ mode is suitable because the splash item only moves and is never
+ transformed, and because it contains text, it's important that it has a
+ pixel perfect visual appearance (in constrast to
+ \l{QGraphicsItem::ItemCoordinateCache}{ItemCoordinateCache}, where the
+ visual appearance is not as good).
+
+ We use caching to avoid having to relayout and rerender the text for each
+ frame. An alterative approach would be to use the new QStaticText class.
+
+ \snippet graphicsview/padnavigator/splashitem.cpp 1
+
+ \c SplashItem's bounding rectangle is fixed at (400x175).
+
+ \snippet graphicsview/padnavigator/splashitem.cpp 2
+
+ The \l{QGraphicsItem::paint()}{paint()} implementation draws a clipped
+ round rectangle with a thick 2-unit border and a semi-transparent white
+ background. It proceeds to finding a suitable text area by adjusting the
+ splash item's bounding rectangle with 10 units in each side. The text is
+ rendered inside this rectangle, with top-left alignment, and with word
+ wrapping enabled.
+
+ The main class now remains. We will proceed to reviewing \c PadNavigator.
+
+ \section1 PadNavigator Class Definition
+
+ \c PadNavigator represents the main window of our Pad Navigator Example
+ application. It creates and controls a somewhat complex state machine, and
+ several animations. Its class declaration is very simple:
+
+ \snippet graphicsview/padnavigator/padnavigator.h 0
+
+ It inherits QGraphicsView and reimplements only one function:
+ \l{QGraphicsView::resizeEvent()}{resizeEvent()}, to ensure the scene is
+ scaled to fit inside the view when resizing the main window.
+
+ The \c PadNavigator constructor takes a QSize argument that determines the
+ number or rows and columns in the grid.
+
+ It also keeps a private member instance, \c form, which is the generated
+ code for the pad's back side item's QGraphicsProxyWidget-embedded form.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 0
+
+ \c PadNavigator's constructor is a bit long. In short, its job is to create
+ all items, including the \c FlippablePad, the \c SplashItem and the
+ QGraphicsProxyWidget \c backItem, and then to set up all animations, states
+ and transitions that control the behavior of the application.
+
+ It starts out simple, by forwarding to QGraphicsView's constructor.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 1
+
+ The first item to be created is \c SplashItem. This is going to be a top-level
+ item in the scene, next to \c FlippablePad, and stacked on top of it, so we
+ assign it a \l{QGraphicsItem::zValue()}{Z-value} of 1.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 2
+
+ Now we construct the \c FlippablePad item, passing its column-row count to
+ its constructor.
+
+ The pad is controlled by three transformations, and we create one
+ QGraphicsRotation object for each of these.
+
+ \list
+ \li \c flipRotation: Rotates the grid around its Qt::YAxis. This rotation is
+ animated from 0 to 180, and eventually back, when enter is pressed on the
+ keyboard, flipping the pad around.
+ \li \c xRotation: Rotates the grid around its Qt::XAxis. This is used to
+ tilt the pad vertically corresponding to which item is currently selected.
+ This way, the selected item is always kept in front.
+ \li \c yRotation: Rotates the grid around its Qt::YAxis. This is used to
+ tilt the pad horizontally corresponding to which item is selected. This
+ way, the selected item is always kept in front.
+ \endlist
+
+ The combination of all three rotations is assigned via
+ QGraphicsItem::setTransformations().
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 3
+
+ Now we construct the QGraphicsProxyWidget-embedded \c backItem. The proxy
+ widget is created as a child of the pad. We create a new QWidget and
+ populate it with the \c form member. To ensure the \c hostName line edit is
+ the first to receive input focus when this item is shown, we call
+ \l{QWidget::setFocus()}{setFocus()} immediately. This will not give the
+ widget focus right away; it will only prepare the item to automatically
+ receive focus once it is shown.
+
+ The QWidget based form is embedded into the proxy widget. The proxy is
+ hidden initially; we only want to show it when the pad is rotated at least
+ 90 degrees, and we also rotate the proxy itself by 180 degrees. This way we
+ give the impression that the proxy widget is "behind" the flipped pad, when
+ in fact, it's actually \e{on top of it}.
+
+ We enable \l{QGraphicsItem::ItemCoordinateCache}{ItemCoordinateCache} to
+ ensure the flip animation can run smoothly.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 4
+
+ We now create the selection item. This is simply another instance of \c
+ RoundRectItem that is slightly larger than the icons on the pad. We create
+ it as an immediate child of the \c FlippablePad, so the selection item is a
+ sibling to all the icons. By giving it a
+ \l{QGraphicsItem::zValue()}{Z-value} of 0.5 we ensure it will slide between
+ the pad and its icons.
+
+ What follows now is a series of animation initializations.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 5
+
+ We begin with the animations that apply to the splash item. The first
+ animation, \c smoothSplashMove, ensures that the "y" property of \c splash
+ will be animated with a 250-millisecond duration
+ \l{QEasingCurve::InQuad}{InQuad} easing function. \c smoothSplashOpacity
+ ensures the opacity of \c splash eases in and out in 250 milliseconds.
+
+ The values are assigned by \c PadNavigator's state machine, which is
+ created later.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 6
+
+ These are the animations that control the selection item's movement and the
+ \c xRotation and \c yRotation QGraphicsRotation objects that tilt the pad.
+ All animations have a duration of 125 milliseconds, and they all use the
+ \l{QEasingCurve::InOutQuad}{InOutQuad} easing function.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 7
+
+ We now create the animations that control the flip-effect when you press
+ the enter key. The main goal is to rotate the pad by 180 degrees or back,
+ but we also need to make sure the selection item's tilt rotations are reset
+ back to 0 when the pad is flipped, and restored back to their original
+ values when flipped back:
+
+ \list
+ \li \c smoothFlipRotation: Animates the main 180 degree rotation of the pad.
+ \li \c smoothFlipScale: Scales the pad out and then in again while the pad is rotating.
+ \li \c smoothFlipXRotation: Animates the selection item's X-tilt to 0 and back.
+ \li \c smoothFlipYRotation: Animates the selection item's Y-tilt to 0 and back.
+ \li \c flipAnimation: A parallel animation group that ensures all the above animations are run in parallel.
+ \endlist
+
+ All animations are given a 500 millisecond duration and an
+ \l{QEasingCurve::InOutQuad}{InOutQuad} easing function.
+
+ It's worth taking a close look at \c smoothFlipScale. This animation's
+ start and end values are both 1.0, but at animation step 0.5 the
+ animation's value is 0.7. This means that after 50% of the animation's
+ duration, or 250 milliseconds, the pad will be scaled down to 0.7x of its
+ original size, which gives a great visual effect while flipping.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 8
+
+ This section uses a trick to ensure that certain properties are assigned
+ precisely when the flip animation passes 50%, or 90 degrees, rotation. In
+ short, the pad's icons and selection item are all hidden, the pad's \c fill
+ property is enabled, and \c backItem is shown when flipping over. When
+ flipping back, the reverse properties are applied.
+
+ The way this is achieved is by running a sequential animation in parallel
+ to the other animations. This sequence, dubbed \c setVariablesSequence,
+ starts with a 250 millisecond pause, and then executes several animations
+ with a duration of 0. Each animation will ensure that properties are set
+ immediate at this point.
+
+ This approach can also be used to call functions or set any other
+ properties at a specific time while an animation is running.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 9
+
+ We will now create the state machine. The whole \c PadNavigator state
+ machinery is controlled by one single state machine that has a
+ straight-forward state structure. The state engine itself is created
+ as a child of the \c PadNavigator itself. We then create three top level
+ states:
+
+ \list
+ \li \c splashState: The initial state where the splash item is visible.
+ \li \c frontState: The base state where the splash is gone and we can see
+ the front side of the pad, and navigate the selection item.
+ \li \c backState: The flipped state where the \c backItem is visible, and we
+ can interact with the QGraphicsProxyWidget-embedded form.
+ \endlist
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 10
+
+ Each state assigns specific properties to objects on entry. Most
+ interesting perhaps is the assignment of the value 0.0 to the pad's \c
+ flipRotation angle property when in \c frontState, and 180.0 when in \c
+ backState. At the end of this section we register default animations with
+ the state engine; these animations will apply to their respective objects
+ and properties for any state transition. Otherwise it's common to assign
+ animations to specific transitions.
+
+ The \c splashState state is set as the initial state. This is required
+ before we start the state engine. We proceed with creating some
+ transitions.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 11
+
+ QEventTransition defines a very flexible transition type. You can use this
+ class to trigger a transition based on an object receiving an event of a
+ specific type. In this case, we would like to transition from \c
+ splashState into \c frontState if \c PadNavigator receives any key press
+ event (QEvent::KeyPress).
+
+ We register the \c splashItem's animations to this transition to ensure they
+ are used to animate the item's movement and opacity.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 12
+
+ We use QKeyEventTransition to capture specific key events. In this case, we
+ detect that the user presses Qt::Key_Return or Qt::Key_Enter, and use this
+ to trigger transitions between \c frontState and backState. We register \c
+ flipAnimation, our complex parallel animation group, with these
+ transitions.
+
+ We continue by defining the states for each of the icons in the grid.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 13
+
+ We will use state groups to control transitions between icons. Each icon
+ represents a \e substate of \c frontState. We will then define transitions
+ between the states by detecting key presses, using QKeyEventTransition.
+
+ We start by creating all the substates, and at the same time we create a
+ temporary grid structure for the states to make it easier to find which
+ states represents icons that are up, down, left and to the right each
+ other.
+
+ Once the first substate is known, we set this up as the initial substate of
+ \c frontState. We will use the (0, 0), or top-left, icon for the initial
+ substate. We initialze the selection item's position to be exactly where
+ the top-left icon is.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 14
+
+ We can now create four transitions for each icon. Each transition ensures
+ that we move to the state corresponding to which arrow key has been
+ pressed. It's clear from this techinique that we could design any other
+ specific transitions to and from each of the sub states depending on these
+ and other keys.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 15
+
+ Also, for each of the icons, we assign suitable values to the \c xRotation
+ and \c yRotation objects' "angle"-properties. If you recall, these
+ properties "tilt" the pad corresponding to which item is currently
+ selected. We ensure each icon is invisible when the pad is flipped, and
+ visible when the pad is not flipped. To ensure the visible property is
+ assigned at the right time, we add property-controlling animations to the
+ \c setVariableSequence animation defined earlier.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 16
+
+ We are now finished with all states, transitions, and animations. We now
+ create the scene that will contain all our items. The scene gets a defined
+ background pixmap, and we disable item indexing (as most items in this
+ scene are animated). We add our \c pad item to the scene, and use its
+ bounding rectangle to fixate the scene rectangle. This rectangle is used by
+ the view to find a suitable size for the application window.
+
+ Then the scene is assigned to the view, or in our case, \c PadNavigator
+ itself.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 17
+
+ Now that the scene has received its final size, we can position the splash
+ item at the very top, find its fade-out position, and add it to the scene.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 18
+
+ The view toggles a few necessary properties:
+
+ \list
+ \li It disables its scroll bars - this application has no use for scroll bars.
+ \li It assigns a minimum size. This is necessary to avoid numerical errors
+ in our fit-in-view \c resizeEvent() implementation.
+ \li It sets \l{QGraphicsView::FullViewportUpdate}{FullViewportUpdate}, to
+ ensure QGraphicsView doesn't spend time figuring out precisely what needs
+ to be redrawn. This application is very simple - if anything changes,
+ everything is updated.
+ \li It enables background caching - this makes no performance difference
+ with OpenGL, but without OpenGL it avoids unnecessary re-scaling of the
+ background pixmap.
+ \li It sets render hints that increase rendering quality.
+ \li If OpenGL is supported, a QGLWidget viewport is assigned to the view.
+ \endlist
+
+ Finally, we start the state engine.
+
+ \snippet graphicsview/padnavigator/padnavigator.cpp 19
+
+ The \l{QGraphicsView::resizeEvent()}{resizeEvent()} implementation calls
+ the base implementation, and then calls QGraphicsView::fitInView() to scale
+ the scene so that it fits perfectly inside the view.
+
+ By resizing the main application window, you can see this effect yourself.
+ The scene contents grow when you make the window larger, and shrink when
+ you make it smaller, while keeping the aspect ratio intact.
+
+ \section1 The main() Function
+
+ \snippet graphicsview/padnavigator/main.cpp 0
+
+ The \c main function creates the QApplication instance, uses
+ Q_INIT_RESOURCE to ensure our compiled-in resources aren't removed by the
+ linker, and then creates a 3x3 \c PadNavigator instance and shows it.
+
+ Our flippable pad shows up with a suitable splash item once control returns
+ to the event loop.
+
+ \section1 Performance Notes
+
+ The example uses OpenGL if this is available, to achieve optimal
+ performance; otherwise perspective tranformations can be quite costly.
+
+ Although this example does use QGraphicsProxyWidget to demonstrate
+ integration of Qt widget components integrated into Graphics View, using
+ QGraphicsProxyWidget comes with a performance penalty, and is therefore not
+ recommended for embedded development.
+
+ This example uses extensive item caching to avoid rerendering of static
+ elements, at the expense of graphics memory.
+*/
diff --git a/examples/widgets/doc/painterpaths.qdoc b/examples/widgets/doc/painterpaths.qdoc
new file mode 100644
index 0000000000..45b0697cee
--- /dev/null
+++ b/examples/widgets/doc/painterpaths.qdoc
@@ -0,0 +1,418 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example painting/painterpaths
+ \title Painter Paths Example
+
+ The Painter Paths example shows how painter paths can be used to
+ build complex shapes for rendering.
+
+ \image painterpaths-example.png
+
+ The QPainterPath class provides a container for painting
+ operations, enabling graphical shapes to be constructed and
+ reused.
+
+ A painter path is an object composed of a number of graphical
+ building blocks (such as rectangles, ellipses, lines, and curves),
+ and can be used for filling, outlining, and clipping. The main
+ advantage of painter paths over normal drawing operations is that
+ complex shapes only need to be created once, but they can be drawn
+ many times using only calls to QPainter::drawPath().
+
+ The example consists of two classes:
+
+ \list
+ \li The \c RenderArea class which is a custom widget displaying
+ a single painter path.
+ \li The \c Window class which is the applications main window
+ displaying several \c RenderArea widgets, and allowing the user
+ to manipulate the painter paths' filling, pen, color
+ and rotation angle.
+ \endlist
+
+ First we will review the \c Window class, then we will take a look
+ at the \c RenderArea class.
+
+ \section1 Window Class Definition
+
+ The \c Window class inherits QWidget, and is the applications main
+ window displaying several \c RenderArea widgets, and allowing the
+ user to manipulate the painter paths' filling, pen, color and
+ rotation angle.
+
+ \snippet painting/painterpaths/window.h 0
+
+ We declare three private slots to respond to user input regarding
+ filling and color: \c fillRuleChanged(), \c fillGradientChanged()
+ and \c penColorChanged().
+
+ When the user changes the pen width and the rotation angle, the
+ new value is passed directly on to the \c RenderArea widgets using
+ the QSpinBox::valueChanged() signal. The reason why we must
+ implement slots to update the filling and color, is that QComboBox
+ doesn't provide a similar signal passing the new value as
+ argument; so we need to retrieve the new value, or values, before
+ we can update the \c RenderArea widgets.
+
+ \snippet painting/painterpaths/window.h 1
+
+ We also declare a couple of private convenience functions: \c
+ populateWithColors() populates a given QComboBox with items
+ corresponding to the color names Qt knows about, and \c
+ currentItemData() returns the current item for a given QComboBox.
+
+ \snippet painting/painterpaths/window.h 2
+
+ Then we declare the various components of the main window
+ widget. We also declare a convenience constant specifying the
+ number of \c RenderArea widgets.
+
+ \section1 Window Class Implementation
+
+ In the implementation of the \c Window class we first declare the
+ constant \c Pi with six significant figures:
+
+ \snippet painting/painterpaths/window.cpp 0
+
+ In the constructor, we then define the various painter paths and
+ create corresponding \c RenderArea widgets which will render the
+ graphical shapes:
+
+ \snippet painting/painterpaths/window.cpp 1
+
+ We construct a rectangle with sharp corners using the
+ QPainterPath::moveTo() and QPainterPath::lineTo()
+ functions.
+
+ QPainterPath::moveTo() moves the current point to the point passed
+ as argument. A painter path is an object composed of a number of
+ graphical building blocks, i.e. subpaths. Moving the current point
+ will also start a new subpath (implicitly closing the previously
+ current path when the new one is started). The
+ QPainterPath::lineTo() function adds a straight line from the
+ current point to the given end point. After the line is drawn, the
+ current point is updated to be at the end point of the line.
+
+ We first move the current point starting a new subpath, and we
+ draw three of the rectangle's sides. Then we call the
+ QPainterPath::closeSubpath() function which draws a line to the
+ beginning of the current subpath. A new subpath is automatically
+ begun when the current subpath is closed. The current point of the
+ new path is (0, 0). We could also have called
+ QPainterPath::lineTo() to draw the last line as well, and then
+ explicitly start a new subpath using the QPainterPath::moveTo()
+ function.
+
+ QPainterPath also provide the QPainterPath::addRect() convenience
+ function, which adds a given rectangle to the path as a closed
+ subpath. The rectangle is added as a clockwise set of lines. The
+ painter path's current position after the rect has been added is
+ at the top-left corner of the rectangle.
+
+ \snippet painting/painterpaths/window.cpp 2
+
+ Then we construct a rectangle with rounded corners. As before, we
+ use the QPainterPath::moveTo() and QPainterPath::lineTo()
+ functions to draw the rectangle's sides. To create the rounded
+ corners we use the QPainterPath::arcTo() function.
+
+ QPainterPath::arcTo() creates an arc that occupies the given
+ rectangle (specified by a QRect or the rectangle's coordinates),
+ beginning at the given start angle and extending the given degrees
+ counter-clockwise. Angles are specified in degrees. Clockwise arcs
+ can be specified using negative angles. The function connects the
+ current point to the starting point of the arc if they are not
+ already connected.
+
+ \snippet painting/painterpaths/window.cpp 3
+
+ We also use the QPainterPath::arcTo() function to construct the
+ ellipse path. First we move the current point starting a new
+ path. Then we call QPainterPath::arcTo() with starting angle 0.0
+ and 360.0 degrees as the last argument, creating an ellipse.
+
+ Again, QPainterPath provides a convenience function (
+ QPainterPath::addEllipse()) which creates an ellipse within a
+ given bounding rectangle and adds it to the painter path. If the
+ current subpath is closed, a new subpath is started. The ellipse
+ is composed of a clockwise curve, starting and finishing at zero
+ degrees (the 3 o'clock position).
+
+ \snippet painting/painterpaths/window.cpp 4
+
+ When constructing the pie chart path we continue to use a
+ combination of the mentioned functions: First we move the current
+ point, starting a new subpath. Then we create a line from the
+ center of the chart to the arc, and the arc itself. When we close
+ the subpath, we implicitly construct the last line back to the
+ center of the chart.
+
+ \snippet painting/painterpaths/window.cpp 5
+
+ Constructing a polygon is equivalent to constructing a rectangle.
+
+ QPainterPath also provide the QPainterPath::addPolygon()
+ convenience function which adds the given polygon to the path as a
+ new subpath. Current position after the polygon has been added is
+ the last point in polygon.
+
+ \snippet painting/painterpaths/window.cpp 6
+
+ Then we create a path consisting of a group of subpaths: First we
+ move the current point, and create a circle using the
+ QPainterPath::arcTo() function with starting angle 0.0, and 360
+ degrees as the last argument, as we did when we created the
+ ellipse path. Then we move the current point again, starting a
+ new subpath, and construct three sides of a square using the
+ QPainterPath::lineTo() function.
+
+ Now, when we call the QPainterPath::closeSubpath() function the
+ last side is created. Remember that the
+ QPainterPath::closeSubpath() function draws a line to the
+ beginning of the \e current subpath, i.e the square.
+
+ QPainterPath provide a convenience function,
+ QPainterPath::addPath() which adds a given path to the path that
+ calls the function.
+
+ \snippet painting/painterpaths/window.cpp 7
+
+ When creating the text path, we first create the font. Then we set
+ the font's style strategy which tells the font matching algorithm
+ what type of fonts should be used to find an appropriate default
+ family. QFont::ForceOutline forces the use of outline fonts.
+
+ To construct the text, we use the QPainterPath::addText() function
+ which adds the given text to the path as a set of closed subpaths
+ created from the supplied font. The subpaths are positioned so
+ that the left end of the text's baseline lies at the specified
+ point.
+
+ \snippet painting/painterpaths/window.cpp 8
+
+ To create the Bezier path, we use the QPainterPath::cubicTo()
+ function which adds a Bezier curve between the current point and
+ the given end point with the given control point. After the curve
+ is added, the current point is updated to be at the end point of
+ the curve.
+
+ In this case we omit to close the subpath so that we only have a
+ simple curve. But there is still a logical line from the curve's
+ endpoint back to the beginning of the subpath; it becomes visible
+ when filling the path as can be seen in the applications main
+ window.
+
+ \snippet painting/painterpaths/window.cpp 9
+
+ The final path that we construct shows that you can use
+ QPainterPath to construct rather complex shapes using only the
+ previous mentioned QPainterPath::moveTo(), QPainterPath::lineTo()
+ and QPainterPath::closeSubpath() functions.
+
+ \snippet painting/painterpaths/window.cpp 10
+
+ Now that we have created all the painter paths that we need, we
+ create a corresponding \c RenderArea widget for each. In the end,
+ we make sure that the number of render areas is correct using the
+ Q_ASSERT() macro.
+
+ \snippet painting/painterpaths/window.cpp 11
+
+ Then we create the widgets associated with the painter paths' fill
+ rule.
+
+ There are two available fill rules in Qt: The Qt::OddEvenFill rule
+ determine whether a point is inside the shape by drawing a
+ horizontal line from the point to a location outside the shape,
+ and count the number of intersections. If the number of
+ intersections is an odd number, the point is inside the
+ shape. This rule is the default.
+
+ The Qt::WindingFill rule determine whether a point is inside the
+ shape by drawing a horizontal line from the point to a location
+ outside the shape. Then it determines whether the direction of the
+ line at each intersection point is up or down. The winding number
+ is determined by summing the direction of each intersection. If
+ the number is non zero, the point is inside the shape.
+
+ The Qt::WindingFill rule can in most cases be considered as the
+ intersection of closed shapes.
+
+ \snippet painting/painterpaths/window.cpp 12
+
+ We also create the other widgets associated with the filling, the
+ pen and the rotation angle.
+
+ \snippet painting/painterpaths/window.cpp 16
+
+ We connect the comboboxes \l {QComboBox::activated()}{activated()}
+ signals to the associated slots in the \c Window class, while we
+ connect the spin boxes \l
+ {QSpinBox::valueChanged()}{valueChanged()} signal directly to the
+ \c RenderArea widget's respective slots.
+
+ \snippet painting/painterpaths/window.cpp 17
+
+ We add the \c RenderArea widgets to a separate layout which we
+ then add to the main layout along with the rest of the widgets.
+
+ \snippet painting/painterpaths/window.cpp 18
+
+ Finally, we initialize the \c RenderArea widgets by calling the \c
+ fillRuleChanged(), \c fillGradientChanged() and \c
+ penColorChanged() slots, and we set the initial pen width and
+ window title.
+
+ \snippet painting/painterpaths/window.cpp 19
+ \codeline
+ \snippet painting/painterpaths/window.cpp 20
+ \codeline
+ \snippet painting/painterpaths/window.cpp 21
+
+ The private slots are implemented to retrieve the new value, or
+ values, from the associated comboboxes and update the RenderArea
+ widgets.
+
+ First we determine the new value, or values, using the private \c
+ currentItemData() function and the qvariant_cast() template
+ function. Then we call the associated slot for each of the \c
+ RenderArea widgets to update the painter paths.
+
+ \snippet painting/painterpaths/window.cpp 22
+
+ The \c populateWithColors() function populates the given combobox
+ with items corresponding to the color names Qt knows about
+ provided by the static QColor::colorNames() function.
+
+ \snippet painting/painterpaths/window.cpp 23
+
+ The \c currentItemData() function simply return the current item
+ of the given combobox.
+
+ \section1 RenderArea Class Definition
+
+ The \c RenderArea class inherits QWidget, and is a custom widget
+ displaying a single painter path.
+
+ \snippet painting/painterpaths/renderarea.h 0
+
+ We declare several public slots updating the \c RenderArea
+ widget's associated painter path. In addition we reimplement the
+ QWidget::minimumSizeHint() and QWidget::sizeHint() functions to
+ give the \c RenderArea widget a reasonable size within our
+ application, and we reimplement the QWidget::paintEvent() event
+ handler to draw its painter path.
+
+ \snippet painting/painterpaths/renderarea.h 1
+
+ Each instance of the \c RenderArea class has a QPainterPath, a
+ couple of fill colors, a pen width, a pen color and a rotation
+ angle.
+
+ \section1 RenderArea Class Implementation
+
+ The constructor takes a QPainterPath as argument (in addition to
+ the optional QWidget parent):
+
+ \snippet painting/painterpaths/renderarea.cpp 0
+
+ In the constructor we initialize the \c RenderArea widget with the
+ QPainterPath parameter as well as initializing the pen width and
+ rotation angle. We also set the widgets \l
+ {QWidget::backgroundRole()}{background role}; QPalette::Base is
+ typically white.
+
+ \snippet painting/painterpaths/renderarea.cpp 1
+ \codeline
+ \snippet painting/painterpaths/renderarea.cpp 2
+
+ Then we reimplement the QWidget::minimumSizeHint() and
+ QWidget::sizeHint() functions to give the \c RenderArea widget a
+ reasonable size within our application.
+
+ \snippet painting/painterpaths/renderarea.cpp 3
+ \codeline
+ \snippet painting/painterpaths/renderarea.cpp 4
+ \codeline
+ \snippet painting/painterpaths/renderarea.cpp 5
+ \codeline
+ \snippet painting/painterpaths/renderarea.cpp 6
+ \codeline
+ \snippet painting/painterpaths/renderarea.cpp 7
+
+ The various public slots updates the \c RenderArea widget's
+ painter path by setting the associated property and make a call to
+ the QWidget::update() function, forcing a repaint of the widget
+ with the new rendering preferences.
+
+ The QWidget::update() slot does not cause an immediate repaint;
+ instead it schedules a paint event for processing when Qt returns
+ to the main event loop.
+
+ \snippet painting/painterpaths/renderarea.cpp 8
+
+ A paint event is a request to repaint all or parts of the
+ widget. The paintEvent() function is an event handler that can be
+ reimplemented to receive the widget's paint events. We reimplement
+ the event handler to render the \c RenderArea widget's painter
+ path.
+
+ First, we create a QPainter for the \c RenderArea instance, and
+ set the painter's render hints. The QPainter::RenderHints are used
+ to specify flags to QPainter that may, or may not, be respected by
+ any given engine. QPainter::Antialiasing indicates that the engine
+ should anti-alias the edges of primitives if possible, i.e. put
+ additional pixels around the original ones to smooth the edges.
+
+ \snippet painting/painterpaths/renderarea.cpp 9
+
+ Then we scale the QPainter's coordinate system to ensure that the
+ painter path is rendered in the right size, i.e that it grows with
+ the \c RenderArea widget when the application is resized. When we
+ constructed the various painter paths, they were all rnedered
+ within a square with a 100 pixel width which is equivalent to \c
+ RenderArea::sizeHint(). The QPainter::scale() function scales the
+ coordinate system by the \c RenderArea widget's \e current width
+ and height divided by 100.
+
+ Now, when we are sure that the painter path has the right size, we
+ can translate the coordinate system to make the painter path
+ rotate around the \c RenderArea widget's center. After we have
+ performed the rotation, we must remember to translate the
+ coordinate system back again.
+
+ \snippet painting/painterpaths/renderarea.cpp 10
+
+ Then we set the QPainter's pen with the instance's rendering
+ preferences. We create a QLinearGradient and set its colors
+ corresponding to the \c RenderArea widget's fill colors. Finally,
+ we set the QPainter's brush (the gradient is automatically
+ converted into a QBrush), and draw the \c RenderArea widget's
+ painter path using the QPainter::drawPath() function.
+*/
diff --git a/examples/widgets/doc/pathstroke.qdoc b/examples/widgets/doc/pathstroke.qdoc
new file mode 100644
index 0000000000..89a0182934
--- /dev/null
+++ b/examples/widgets/doc/pathstroke.qdoc
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example painting/pathstroke
+ \title Path Stroking
+
+ In this example we show some of the various types of pens that can be
+ used in Qt.
+
+ \image pathstroke-demo.png
+
+ Qt defines cap styles for how the end points are treated and join
+ styles for how path segments are joined together. A standard set of
+ predefined dash patterns are also included that can be used with
+ QPen.
+
+ In addition to the predefined patterns available in
+ QPen we also demonstrate direct use of the
+ QPainterPathStroker class which can be used to define
+ custom dash patterns. You can see this by enabling the
+ \e{Custom Pattern} option.
+*/
diff --git a/examples/widgets/doc/pingpong.qdoc b/examples/widgets/doc/pingpong.qdoc
new file mode 100644
index 0000000000..c56085d8cf
--- /dev/null
+++ b/examples/widgets/doc/pingpong.qdoc
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \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:
+
+ \image 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 statemachine/pingpong/main.cpp 0
+
+ Two custom events are defined, \c PingEvent and \c PongEvent.
+
+ \snippet 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 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 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 statemachine/pingpong/main.cpp 4
+
+ The main() function begins by creating a state machine and a parallel
+ state group.
+
+ \snippet 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 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/examples/widgets/doc/pixelator.qdoc b/examples/widgets/doc/pixelator.qdoc
new file mode 100644
index 0000000000..099c382c82
--- /dev/null
+++ b/examples/widgets/doc/pixelator.qdoc
@@ -0,0 +1,255 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/pixelator
+ \title Pixelator Example
+
+ The Pixelator example shows how delegates can be used to customize the way that
+ items are rendered in standard item views.
+
+ \image pixelator-example.png
+
+ By default, QTreeView, QTableView, and QListView use a standard item delegate
+ to display and edit a set of common data types that are sufficient for many
+ applications. However, an application may need to represent items of data in a
+ particular way, or provide support for rendering more specialized data types,
+ and this often requires the use of a custom delegate.
+
+ In this example, we show how to use custom delegates to modify the appearance
+ of standard views. To do this, we implement the following components:
+
+ \list
+ \li A model which represents each pixel in an image as an item of data, where each
+ item contains a value for the brightness of the corresponding pixel.
+ \li A custom delegate that uses the information supplied by the model to represent
+ each pixel as a black circle on a white background, where the radius of the
+ circle corresponds to the darkness of the pixel.
+ \endlist
+
+ This example may be useful for developers who want to implement their own table
+ models or custom delegates. The process of creating custom delegates for editing
+ item data is covered in the \l{Spin Box Delegate Example}{Spin Box Delegate}
+ example.
+
+ \section1 ImageModel Class Definition
+
+ The \c ImageModel class is defined as follows:
+
+ \snippet itemviews/pixelator/imagemodel.h 0
+
+ Since we only require a simple, read-only table model, we only need to implement
+ functions to indicate the dimensions of the image and supply data to other
+ components.
+
+ \section1 ImageModel Class Implementation
+
+ The constructor is trivial:
+
+ \snippet itemviews/pixelator/imagemodel.cpp 0
+
+ The \c setImage() function sets the image that will be used by the model:
+
+ \snippet itemviews/pixelator/imagemodel.cpp 1
+
+ The QAbstractItemModel::reset() call tells the view(s) that the model
+ has changed.
+
+ The \c rowCount() and \c columnCount() functions return the height and width of
+ the image respectively:
+
+ \snippet itemviews/pixelator/imagemodel.cpp 2
+ \snippet itemviews/pixelator/imagemodel.cpp 3
+
+ Since the image is a simple two-dimensional structure, the \c parent arguments
+ to these functions are unused. They both simply return the relevant size from
+ the underlying image object.
+
+ The \c data() function returns data for the item that corresponds to a given
+ model index in a format that is suitable for a particular role:
+
+ \snippet itemviews/pixelator/imagemodel.cpp 4
+
+ In this implementation, we only check that the model index is valid, and that
+ the role requested is the \l{Qt::ItemDataRole}{DisplayRole}. If so, the function
+ returns the grayscale value of the relevant pixel in the image; otherwise, a null
+ model index is returned.
+
+ This model can be used with QTableView to display the integer brightness values
+ for the pixels in the image. However, we will implement a custom delegate to
+ display this information in a more artistic way.
+
+ The \c headerData() function is also reimplemented:
+
+ \snippet itemviews/pixelator/imagemodel.cpp 5
+
+ We return (1, 1) as the size hint for a header item. If we
+ didn't, the headers would default to a larger size, preventing
+ us from displaying really small items (which can be specified
+ using the \uicontrol{Pixel size} combobox).
+
+ \section1 PixelDelegate Class Definition
+
+ The \c PixelDelegate class is defined as follows:
+
+ \snippet itemviews/pixelator/pixeldelegate.h 0
+
+ This class provides only basic features for a delegate so, unlike the
+ \l{Spin Box Delegate Example}{Spin Box Delegate} example, we subclass
+ QAbstractItemDelegate instead of QItemDelegate.
+
+ We only need to reimplement \l{QAbstractItemDelegate::paint()}{paint()} and
+ \l{QAbstractItemDelegate::sizeHint()}{sizeHint()} in this class.
+ However, we also provide a delegate-specific \c setPixelSize() function so
+ that we can change the delegate's behavior via the signals and slots mechanism.
+
+ \section1 PixelDelegate Class Implementation
+
+ The \c PixelDelegate constructor is used to set up a default value for
+ the size of each "pixel" that it renders. The base class constructor is
+ also called to ensure that the delegate is set up with a parent object,
+ if one is supplied:
+
+ \snippet itemviews/pixelator/pixeldelegate.cpp 0
+
+ Each item is rendered by the delegate's
+ \l{QAbstractItemDelegate::paint()}{paint()} function. The view calls this
+ function with a ready-to-use QPainter object, style information that the
+ delegate should use to correctly draw the item, and an index to the item in
+ the model:
+
+ \snippet itemviews/pixelator/pixeldelegate.cpp 1
+
+ The first task the delegate has to perform is to draw the item's background
+ correctly. Usually, selected items appear differently to non-selected items,
+ so we begin by testing the state passed in the style option and filling the
+ background if necessary.
+
+ The radius of each circle is calculated in the following lines of code:
+
+ \snippet itemviews/pixelator/pixeldelegate.cpp 3
+ \snippet itemviews/pixelator/pixeldelegate.cpp 4
+
+ First, the largest possible radius of the circle is determined by taking the
+ smallest dimension of the style option's \c rect attribute.
+ Using the model index supplied, we obtain a value for the brightness of the
+ relevant pixel in the image. The radius of the circle is calculated by
+ scaling the brightness to fit within the item and subtracting it from the
+ largest possible radius.
+
+ \snippet itemviews/pixelator/pixeldelegate.cpp 5
+ \snippet itemviews/pixelator/pixeldelegate.cpp 6
+ \snippet itemviews/pixelator/pixeldelegate.cpp 7
+
+ We save the painter's state, turn on antialiasing (to obtain smoother
+ curves), and turn off the pen.
+
+ \snippet itemviews/pixelator/pixeldelegate.cpp 8
+ \snippet itemviews/pixelator/pixeldelegate.cpp 9
+
+ The foreground of the item (the circle representing a pixel) must be
+ rendered using an appropriate brush. For unselected items, we will use a
+ solid black brush; selected items are drawn using a predefined brush from
+ the style option's palette.
+
+ \snippet itemviews/pixelator/pixeldelegate.cpp 10
+
+ Finally, we paint the circle within the rectangle specified by the style
+ option and we call \l{QPainter::}{restore()} on the painter.
+
+ The \c paint() function does not have to be particularly complicated; it is
+ only necessary to ensure that the state of the painter when the function
+ returns is the same as it was when it was called. This usually
+ means that any transformations applied to the painter must be preceded by
+ a call to QPainter::save() and followed by a call to QPainter::restore().
+
+ The delegate's \l{QAbstractItemDelegate::}{sizeHint()} function
+ returns a size for the item based on the predefined pixel size, initially set
+ up in the constructor:
+
+ \snippet itemviews/pixelator/pixeldelegate.cpp 11
+
+ The delegate's size is updated whenever the pixel size is changed.
+ We provide a custom slot to do this:
+
+ \snippet itemviews/pixelator/pixeldelegate.cpp 12
+
+ \section1 Using The Custom Delegate
+
+ In this example, we use a main window to display a table of data, using the
+ custom delegate to render each cell in a particular way. Much of the
+ \c MainWindow class performs tasks that are not related to item views. Here,
+ we only quote the parts that are relevant. You can look at the rest of the
+ implementation by following the links to the code at the top of this
+ document.
+
+ In the constructor, we set up a table view, turn off its grid, and hide its
+ headers:
+
+ \snippet itemviews/pixelator/mainwindow.cpp 0
+ \dots
+ \snippet itemviews/pixelator/mainwindow.cpp 1
+
+ This enables the items to be drawn without any gaps between them. Removing
+ the headers also prevents the user from adjusting the sizes of individual
+ rows and columns.
+
+ We also set the minimum section size to 1 on the headers. If we
+ didn't, the headers would default to a larger size, preventing
+ us from displaying really small items (which can be specified
+ using the \uicontrol{Pixel size} combobox).
+
+ The custom delegate is constructed with the main window as its parent, so
+ that it will be deleted correctly later, and we set it on the table view.
+
+ \snippet itemviews/pixelator/mainwindow.cpp 2
+
+ Each item in the table view will be rendered by the \c PixelDelegate
+ instance.
+
+ We construct a spin box to allow the user to change the size of each "pixel"
+ drawn by the delegate:
+
+ \snippet itemviews/pixelator/mainwindow.cpp 3
+
+ This spin box is connected to the custom slot we implemented in the
+ \c PixelDelegate class. This ensures that the delegate always draws each
+ pixel at the currently specified size:
+
+ \snippet itemviews/pixelator/mainwindow.cpp 4
+ \dots
+ \snippet itemviews/pixelator/mainwindow.cpp 5
+
+ We also connect the spin box to a slot in the \c MainWindow class. This
+ forces the view to take into account the new size hints for each item;
+ these are provided by the delegate in its \c sizeHint() function.
+
+ \snippet itemviews/pixelator/mainwindow.cpp 6
+
+ We explicitly resize the columns and rows to match the
+ \uicontrol{Pixel size} combobox.
+*/
diff --git a/examples/widgets/doc/recentfiles.qdoc b/examples/widgets/doc/recentfiles.qdoc
new file mode 100644
index 0000000000..e2e876b088
--- /dev/null
+++ b/examples/widgets/doc/recentfiles.qdoc
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example mainwindows/recentfiles
+ \title Recent Files Example
+
+ The Recent Files example shows how a standard File menu can be extended to show
+ the most recent files loaded by a main window application.
+
+ \image recentfiles-example.png
+*/
diff --git a/examples/widgets/doc/rogue.qdoc b/examples/widgets/doc/rogue.qdoc
new file mode 100644
index 0000000000..4c65dd2d6e
--- /dev/null
+++ b/examples/widgets/doc/rogue.qdoc
@@ -0,0 +1,208 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example statemachine/rogue
+ \title Rogue Example
+
+ The Rogue example shows how to use the Qt state machine for event
+ handling.
+
+ \image rogue-example.png
+
+ This example implements a simple text based game. Do you see the
+ \c{@} in the screenshot? That's you, the rogue. The \c{#}
+ characters are walls, and the dots represent floor. In a real
+ game, other ASCII characters would represent all kinds of objects
+ and creatures, for instance, ancient dragons (\c{D}s) or food
+ rations (\c{%}s). But let's not get carried away. In this game,
+ the rogue is simply running around in an empty room.
+
+ The rogue is moved with the keypad (2, 4, 8, 6). That aside, we
+ have implemented a \c quit command that triggers if the player
+ types \c {q}. The player is then asked if he/she really wants to
+ quit.
+
+ Most games have commands that need more than one key press (we
+ think of consecutive presses, i.e., not of several keys being
+ pressed at the same time). In this game, only the \c quit command
+ falls under this category, but for the sake of argument, let's
+ imagine a fully-fledged game with a rich set of commands. If we
+ were to implement these by catching key events in
+ \l{QWidget::}{keyPressEvent()}, we would have to keep a lot of
+ class member variables to track the sequence of keys already typed
+ (or find some other way of deducing the current state of a
+ command). This can easily lead to spaghetti, which is--as we all
+ well know, I'm sure--unpleasant. With a state machine, on the
+ other hand, separate states can wait for a single key press, and
+ that makes our lives a lot simpler.
+
+ The example consists of two classes:
+
+ \list
+ \li \c Window draws the text display of the game and sets
+ up the state machine. The window also has a status bar
+ above the area in which the rouge moves.
+ \li \c MovementTransition is a transition that carries out
+ a single move of the rogue.
+ \endlist
+
+ Before we embark on a code walkthrough, it is necessary to take a
+ closer look at the design of the machine. Here is a state chart
+ that shows what we want to achieve:
+
+ \image rogue-statechart.png
+
+ The input state waits for a key press to start a new command.
+ When receiving a key it recognizes, it transitions to one of the
+ two commands of the game; though, as we will see, movement is
+ handled by the transition itself. The quit state waits for the
+ player to answer yes or no (by typing \c y or \c n) when asked
+ whether he/she really wants to quit the game.
+
+ The chart demonstrates how we use one state to wait for a single
+ key press. The press received may trigger one of the transitions
+ connected to the state.
+
+ \section1 Window Class Definition
+
+ The \c Window class is a widget that draws the text display of the
+ game. It also sets up the state machine, i.e., creates and
+ connects the states in the machine. It is the key events from this
+ widget that are used by the machine.
+
+ \snippet statemachine/rogue/window.h 0
+
+ \c Direction specifies the direction in which the rogue is to
+ move. We use this in \c movePlayer(), which moves the rogue and
+ repaints the window. The game has a status line above the area in
+ which the rogue moves. The \c status property contains the text of
+ this line. We use a property because the QState class allows
+ setting any Qt \l{Qt's Property System}{property} when entered.
+ More on this later.
+
+ \snippet statemachine/rogue/window.h 1
+
+ The \c map is an array with the characters that are currently
+ displayed. We set up the array in \c setupMap(), and update it
+ when the rogue is moved. \c pX and \c pY is the current position
+ of the rogue. \c WIDTH and \c HEIGHT are macros specifying the
+ dimensions of the map.
+
+ The \c paintEvent() function is left out of this walkthrough. We
+ also do not discuss other code that does not concern the state
+ machine (the \c setupMap(), \c status(), \c setStatus(), \c
+ movePlayer(), and \c sizeHint() functions). If you wish to take a
+ look at the code, click on the link for the \c window.cpp file at
+ the top of this page.
+
+ \section1 Window Class Implementation
+
+ Here is the constructor of \c Window:
+
+ \snippet statemachine/rogue/window.cpp 0
+ \dots
+ \snippet statemachine/rogue/window.cpp 1
+
+ The player starts off at position (5, 5). We then set up the map
+ and statemachine. Let's proceed with the \c buildMachine()
+ function:
+
+ \snippet statemachine/rogue/window.cpp 2
+
+ We enter \c inputState when the machine is started and from the \c
+ quitState if the user wants to continue playing. We then set the
+ status to a helpful reminder of how to play the game.
+
+ First, the \c Movement transition is added to the input state.
+ This will enable the rogue to be moved with the keypad. Notice
+ that we don't set a target state for the movement transition. This
+ will cause the transition to be triggered (and the
+ \l{QAbstractTransition::}{onTransition()} function to be invoked),
+ but the machine will not leave the \c inputState. If we had set \c
+ inputState as the target state, we would first have left and then
+ entered the \c inputState again.
+
+ \snippet statemachine/rogue/window.cpp 3
+
+ When we enter \c quitState, we update the status bar of the
+ window.
+
+ \c QKeyEventTransition is a utility class that removes the hassle
+ of implementing transitions for \l{QKeyEvent}s. We simply need to
+ specify the key on which the transition should trigger and the
+ target state of the transition.
+
+ \snippet statemachine/rogue/window.cpp 4
+
+ The transition from \c inputState allows triggering the quit state
+ when the player types \c {q}.
+
+ \snippet statemachine/rogue/window.cpp 5
+
+ The machine is set up, so it's time to start it.
+
+ \section1 The MovementTransition Class
+
+ \c MovementTransition is triggered when the player request the
+ rogue to be moved (by typing 2, 4, 6, or 8) when the machine is in
+ the \c inputState.
+
+ \snippet statemachine/rogue/movementtransition.h 0
+
+ In the constructor, we tell QEventTransition to only send
+ \l{QEvent::}{KeyPress} events to the
+ \l{QAbstractTransition::}{eventTest()} function:
+
+ \snippet statemachine/rogue/movementtransition.h 1
+
+ The KeyPress events come wrapped in \l{QStateMachine::WrappedEvent}s. \c event
+ must be confirmed to be a wrapped event because Qt uses other
+ events internally. After that, it is simply a matter of checking
+ which key has been pressed.
+
+ Let's move on to the \c onTransition() function:
+
+ \snippet statemachine/rogue/movementtransition.h 2
+
+ When \c onTransition() is invoked, we know that we have a
+ \l{QEvent::}{KeyPress} event with 2, 4, 6, or 8, and can ask \c
+ Window to move the player.
+
+ \section1 The Roguelike Tradition
+
+ You might have been wondering why the game features a rogue. Well,
+ these kinds of text based dungeon exploration games date back to a
+ game called, yes, "Rogue". Although outflanked by the technology
+ of modern 3D computer games, roguelikes have a solid community of
+ hard-core, devoted followers.
+
+ Playing these games can be surprisingly addictive (despite the
+ lack of graphics). Angband, the perhaps most well-known rougelike,
+ is found here: \l{http://rephial.org/}.
+*/
+
diff --git a/examples/widgets/doc/screenshot.qdoc b/examples/widgets/doc/screenshot.qdoc
new file mode 100644
index 0000000000..2d41cf0d85
--- /dev/null
+++ b/examples/widgets/doc/screenshot.qdoc
@@ -0,0 +1,247 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example desktop/screenshot
+ \title Screenshot Example
+
+ The Screenshot example shows how to take a screenshot of the
+ desktop using QApplication and QDesktopWidget. It also shows how
+ to use QTimer to provide a single-shot timer, and how to
+ reimplement the QWidget::resizeEvent() event handler to make sure
+ that an application resizes smoothly and without data loss.
+
+ \image screenshot-example.png
+
+ With the application the users can take a screenshot of their
+ desktop. They are provided with a couple of options:
+
+ \list
+ \li Delaying the screenshot, giving them time to rearrange
+ their desktop.
+ \li Hiding the application's window while the screenshot is taken.
+ \endlist
+
+ In addition the application allows the users to save their
+ screenshot if they want to.
+
+ \section1 Screenshot Class Definition
+
+ \snippet desktop/screenshot/screenshot.h 0
+
+ The \c Screenshot class inherits QWidget and is the application's
+ main widget. It displays the application options and a preview of
+ the screenshot.
+
+ We reimplement the QWidget::resizeEvent() function to make sure
+ that the preview of the screenshot scales properly when the user
+ resizes the application widget. We also need several private slots
+ to facilitate the options:
+
+ \list
+ \li The \c newScreenshot() slot prepares a new screenshot.
+ \li The \c saveScreenshot() slot saves the last screenshot.
+ \li The \c shootScreen() slot takes the screenshot.
+ \li The \c updateCheckBox() slot enables or disables the
+ \uicontrol {Hide This Window} option.
+ \endlist
+
+ We also declare some private functions: We use the \c
+ createOptionsGroupBox(), \c createButtonsLayout() and \c
+ createButton() functions when we construct the widget. And we call
+ the private \c updateScreenshotLabel() function whenever a new
+ screenshot is taken or when a resize event changes the size of the
+ screenshot preview label.
+
+ In addition we need to store the screenshot's original pixmap. The
+ reason is that when we display the preview of the screenshot, we
+ need to scale its pixmap, storing the original we make sure that
+ no data are lost in that process.
+
+ \section1 Screenshot Class Implementation
+
+ \snippet desktop/screenshot/screenshot.cpp 0
+
+ In the constructor we first create the QLabel displaying the
+ screenshot preview.
+
+ We set the QLabel's size policy to be QSizePolicy::Expanding both
+ horizontally and vertically. This means that the QLabel's size
+ hint is a sensible size, but the widget can be shrunk and still be
+ useful. Also, the widget can make use of extra space, so it should
+ get as much space as possible. Then we make sure the QLabel is
+ aligned in the center of the \c Screenshot widget, and set its
+ minimum size.
+
+ We create the applications's buttons and the group box containing
+ the application's options, and put it all into a main
+ layout. Finally we take the initial screenshot, and set the initial
+ delay and the window title, before we resize the widget to a
+ suitable size.
+
+ \snippet desktop/screenshot/screenshot.cpp 1
+
+ The \c resizeEvent() function is reimplemented to receive the
+ resize events dispatched to the widget. The purpose is to scale
+ the preview screenshot pixmap without deformation of its content,
+ and also make sure that the application can be resized smoothly.
+
+ To achieve the first goal, we scale the screenshot pixmap using
+ Qt::KeepAspectRatio. We scale the pixmap to a rectangle as large
+ as possible inside the current size of the screenshot preview
+ label, preserving the aspect ratio. This means that if the user
+ resizes the application window in only one direction, the preview
+ screenshot keeps the same size.
+
+ To reach our second goal, we make sure that the preview screenshot
+ only is repainted (using the private \c updateScreenshotLabel()
+ function) when it actually changes its size.
+
+ \snippet desktop/screenshot/screenshot.cpp 2
+
+ The private \c newScreenshot() slot is called when the user
+ requests a new screenshot; but the slot only prepares a new
+ screenshot.
+
+ First we see if the \uicontrol {Hide This Window} option is checked, if
+ it is we hide the \c Screenshot widget. Then we disable the \uicontrol
+ {New Screenshot} button, to make sure the user only can request
+ one screenshot at a time.
+
+ We create a timer using the QTimer class which provides repetitive
+ and single-shot timers. We set the timer to time out only once,
+ using the static QTimer::singleShot() function. This function
+ calls the private \c shootScreen() slot after the time interval
+ specified by the \uicontrol {Screenshot Delay} option. It is \c
+ shootScreen() that actually performs the screenshot.
+
+ \snippet desktop/screenshot/screenshot.cpp 3
+
+ The \c saveScreenshot() slot is called when the user push the \uicontrol
+ Save button, and it presents a file dialog using the QFileDialog
+ class.
+
+ QFileDialog enables a user to traverse the file system in order to
+ select one or many files or a directory. The easiest way to create
+ a QFileDialog is to use the convenience static
+ functions.
+
+ We define the default file format to be png, and we make the file
+ dialog's initial path the path the application is run from. We
+ create the file dialog using the static
+ QFileDialog::getSaveFileName() function which returns a file name
+ selected by the user. The file does not have to exist. If the file
+ name is valid, we use the QPixmap::save() function to save the
+ screenshot's original pixmap in that file.
+
+ \snippet desktop/screenshot/screenshot.cpp 4
+
+ The \c shootScreen() slot is called to take the screenshot. If the
+ user has chosen to delay the screenshot, we make the application
+ beep when the screenshot is taken using the static
+ QApplication::beep() function.
+
+ The QApplication class manages the GUI application's control flow
+ and main settings. It contains the main event loop, where all
+ events from the window system and other sources are processed and
+ dispatched.
+
+ \snippet desktop/screenshot/screenshot.cpp 5
+
+ Using the static function QApplication::primaryScreen(), we
+ obtain the QScreen object for the application's main screen.
+
+ We take the screenshot using the QScreen::grabWindow()
+ function. The function grabs the contents of the window passed as
+ an argument, makes a pixmap out of it and returns that pixmap.
+ The window id can be obtained with QWidget::winId() or QWindow::winId().
+ Here, however, we just pass 0 as the window id, indicating that we
+ want to grab the entire screen.
+
+ We update the screenshot preview label using the private \c
+ updateScreenshotLabel() function. Then we enable the \uicontrol {New
+ Screenshot} button, and finally we make the \c Screenshot widget
+ visible if it was hidden during the screenshot.
+
+ \snippet desktop/screenshot/screenshot.cpp 6
+
+ The \uicontrol {Hide This Window} option is enabled or disabled
+ depending on the delay of the screenshot. If there is no delay,
+ the application window cannot be hidden and the option's checkbox
+ is disabled.
+
+ The \c updateCheckBox() slot is called whenever the user changes
+ the delay using the \uicontrol {Screenshot Delay} option.
+
+ \snippet desktop/screenshot/screenshot.cpp 7
+
+ The private \c createOptionsGroupBox() function is called from the
+ constructor.
+
+ First we create a group box that will contain all of the options'
+ widgets. Then we create a QSpinBox and a QLabel for the \uicontrol
+ {Screenshot Delay} option, and connect the spinbox to the \c
+ updateCheckBox() slot. Finally, we create a QCheckBox for the \uicontrol
+ {Hide This Window} option, add all the options' widgets to a
+ QGridLayout and install the layout on the group box.
+
+ Note that we don't have to specify any parents for the widgets
+ when we create them. The reason is that when we add a widget to a
+ layout and install the layout on another widget, the layout's
+ widgets are automatically reparented to the widget the layout is
+ installed on.
+
+ \snippet desktop/screenshot/screenshot.cpp 8
+
+ The private \c createButtonsLayout() function is called from the
+ constructor. We create the application's buttons using the private
+ \c createButton() function, and add them to a QHBoxLayout.
+
+ \snippet desktop/screenshot/screenshot.cpp 9
+
+ The private \c createButton() function is called from the \c
+ createButtonsLayout() function. It simply creates a QPushButton
+ with the provided text, connects it to the provided receiver and
+ slot, and returns a pointer to the button.
+
+ \snippet desktop/screenshot/screenshot.cpp 10
+
+ The private \c updateScreenshotLabel() function is called whenever
+ the screenshot changes, or when a resize event changes the size of
+ the screenshot preview label. It updates the screenshot preview's
+ label using the QLabel::setPixmap() and QPixmap::scaled()
+ functions.
+
+ QPixmap::scaled() returns a copy of the given pixmap scaled to a
+ rectangle of the given size according to the given
+ Qt::AspectRatioMode and Qt::TransformationMode.
+
+ We scale the original pixmap to fit the current screenshot label's
+ size, preserving the aspect ratio and giving the resulting pixmap
+ smoothed edges.
+*/
+
diff --git a/examples/widgets/doc/scribble.qdoc b/examples/widgets/doc/scribble.qdoc
new file mode 100644
index 0000000000..5749b9ed07
--- /dev/null
+++ b/examples/widgets/doc/scribble.qdoc
@@ -0,0 +1,417 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/scribble
+ \title Scribble Example
+
+ The Scribble example shows how to reimplement some of QWidget's
+ event handlers to receive the events generated for the
+ application's widgets.
+
+ We reimplement the mouse event handlers to implement drawing, the
+ paint event handler to update the application and the resize event
+ handler to optimize the application's appearance. In addition we
+ reimplement the close event handler to intercept the close events
+ before terminating the application.
+
+ The example also demonstrates how to use QPainter to draw an image
+ in real time, as well as to repaint widgets.
+
+ \image scribble-example.png Screenshot of the Scribble example
+
+ With the Scribble application the users can draw an image. The
+ \uicontrol File menu gives the users the possibility to open and edit an
+ existing image file, save an image and exit the application. While
+ drawing, the \uicontrol Options menu allows the users to to choose the
+ pen color and pen width, as well as clear the screen. In addition
+ the \uicontrol Help menu provides the users with information about the
+ Scribble example in particular, and about Qt in general.
+
+ The example consists of two classes:
+
+ \list
+ \li \c ScribbleArea is a custom widget that displays a QImage and
+ allows to the user to draw on it.
+ \li \c MainWindow provides a menu above the \c ScribbleArea.
+ \endlist
+
+ We will start by reviewing the \c ScribbleArea class. Then we will
+ review the \c MainWindow class, which uses \c ScribbleArea.
+
+ \section1 ScribbleArea Class Definition
+
+ \snippet widgets/scribble/scribblearea.h 0
+
+ The \c ScribbleArea class inherits from QWidget. We reimplement
+ the \c mousePressEvent(), \c mouseMoveEvent() and \c
+ mouseReleaseEvent() functions to implement the drawing. We
+ reimplement the \c paintEvent() function to update the scribble
+ area, and the \c resizeEvent() function to ensure that the QImage
+ on which we draw is at least as large as the widget at any time.
+
+ We need several public functions: \c openImage() loads an image
+ from a file into the scribble area, allowing the user to edit the
+ image; \c save() writes the currently displayed image to file; \c
+ clearImage() slot clears the image displayed in the scribble
+ area. We need the private \c drawLineTo() function to actually do
+ the drawing, and \c resizeImage() to change the size of a
+ QImage. The \c print() slot handles printing.
+
+ We also need the following private variables:
+
+ \list
+ \li \c modified is \c true if there are unsaved
+ changes to the image displayed in the scribble area.
+ \li \c scribbling is \c true while the user is pressing
+ the left mouse button within the scribble area.
+ \li \c penWidth and \c penColor hold the currently
+ set width and color for the pen used in the application.
+ \li \c image stores the image drawn by the user.
+ \li \c lastPoint holds the position of the cursor at the last
+ mouse press or mouse move event.
+ \endlist
+
+ \section1 ScribbleArea Class Implementation
+
+ \snippet widgets/scribble/scribblearea.cpp 0
+
+ In the constructor, we set the Qt::WA_StaticContents
+ attribute for the widget, indicating that the widget contents are
+ rooted to the top-left corner and don't change when the widget is
+ resized. Qt uses this attribute to optimize paint events on
+ resizes. This is purely an optimization and should only be used
+ for widgets whose contents are static and rooted to the top-left
+ corner.
+
+ \snippet widgets/scribble/scribblearea.cpp 1
+ \snippet widgets/scribble/scribblearea.cpp 2
+
+ In the \c openImage() function, we load the given image. Then we
+ resize the loaded QImage to be at least as large as the widget in
+ both directions using the private \c resizeImage() function and
+ we set the \c image member variable to be the loaded image. At
+ the end, we call QWidget::update() to schedule a repaint.
+
+ \snippet widgets/scribble/scribblearea.cpp 3
+ \snippet widgets/scribble/scribblearea.cpp 4
+
+ The \c saveImage() function creates a QImage object that covers
+ only the visible section of the actual \c image and saves it using
+ QImage::save(). If the image is successfully saved, we set the
+ scribble area's \c modified variable to \c false, because there is
+ no unsaved data.
+
+ \snippet widgets/scribble/scribblearea.cpp 5
+ \snippet widgets/scribble/scribblearea.cpp 6
+ \codeline
+ \snippet widgets/scribble/scribblearea.cpp 7
+ \snippet widgets/scribble/scribblearea.cpp 8
+
+ The \c setPenColor() and \c setPenWidth() functions set the
+ current pen color and width. These values will be used for future
+ drawing operations.
+
+ \snippet widgets/scribble/scribblearea.cpp 9
+ \snippet widgets/scribble/scribblearea.cpp 10
+
+ The public \c clearImage() slot clears the image displayed in the
+ scribble area. We simply fill the entire image with white, which
+ corresponds to RGB value (255, 255, 255). As usual when we modify
+ the image, we set \c modified to \c true and schedule a repaint.
+
+ \snippet widgets/scribble/scribblearea.cpp 11
+ \snippet widgets/scribble/scribblearea.cpp 12
+
+ For mouse press and mouse release events, we use the
+ QMouseEvent::button() function to find out which button caused
+ the event. For mose move events, we use QMouseEvent::buttons()
+ to find which buttons are currently held down (as an OR-combination).
+
+ If the users press the left mouse button, we store the position
+ of the mouse cursor in \c lastPoint. We also make a note that the
+ user is currently scribbling. (The \c scribbling variable is
+ necessary because we can't assume that a mouse move and mouse
+ release event is always preceded by a mouse press event on the
+ same widget.)
+
+ If the user moves the mouse with the left button pressed down or
+ releases the button, we call the private \c drawLineTo() function
+ to draw.
+
+ \snippet widgets/scribble/scribblearea.cpp 13
+ \snippet widgets/scribble/scribblearea.cpp 14
+
+ In the reimplementation of the \l
+ {QWidget::paintEvent()}{paintEvent()} function, we simply create
+ a QPainter for the scribble area, and draw the image.
+
+ At this point, you might wonder why we don't just draw directly
+ onto the widget instead of drawing in a QImage and copying the
+ QImage onto screen in \c paintEvent(). There are at least three
+ good reasons for this:
+
+ \list
+ \li The window system requires us to be able to redraw the widget
+ \e{at any time}. For example, if the window is minimized and
+ restored, the window system might have forgotten the contents
+ of the widget and send us a paint event. In other words, we
+ can't rely on the window system to remember our image.
+
+ \li Qt normally doesn't allow us to paint outside of \c
+ paintEvent(). In particular, we can't paint from the mouse
+ event handlers. (This behavior can be changed using the
+ Qt::WA_PaintOnScreen widget attribute, though.)
+
+ \li If initialized properly, a QImage is guaranteed to use 8-bit
+ for each color channel (red, green, blue, and alpha), whereas
+ a QWidget might have a lower color depth, depending on the
+ monitor configuration. This means that if we load a 24-bit or
+ 32-bit image and paint it onto a QWidget, then copy the
+ QWidget into a QImage again, we might lose some information.
+ \endlist
+
+ \snippet widgets/scribble/scribblearea.cpp 15
+ \snippet widgets/scribble/scribblearea.cpp 16
+
+ When the user starts the Scribble application, a resize event is
+ generated and an image is created and displayed in the scribble
+ area. We make this initial image slightly larger than the
+ application's main window and scribble area, to avoid always
+ resizing the image when the user resizes the main window (which
+ would be very inefficient). But when the main window becomes
+ larger than this initial size, the image needs to be resized.
+
+ \snippet widgets/scribble/scribblearea.cpp 17
+ \snippet widgets/scribble/scribblearea.cpp 18
+
+ In \c drawLineTo(), we draw a line from the point where the mouse
+ was located when the last mouse press or mouse move occurred, we
+ set \c modified to true, we generate a repaint event, and we
+ update \c lastPoint so that next time \c drawLineTo() is called,
+ we continue drawing from where we left.
+
+ We could call the \c update() function with no parameter, but as
+ an easy optimization we pass a QRect that specifies the rectangle
+ inside the scribble are needs updating, to avoid a complete
+ repaint of the widget.
+
+ \snippet widgets/scribble/scribblearea.cpp 19
+ \snippet widgets/scribble/scribblearea.cpp 20
+
+ QImage has no nice API for resizing an image. There's a
+ QImage::copy() function that could do the trick, but when used to
+ expand an image, it fills the new areas with black, whereas we
+ want white.
+
+ So the trick is to create a brand new QImage with the right size,
+ to fill it with white, and to draw the old image onto it using
+ QPainter. The new image is given the QImage::Format_RGB32
+ format, which means that each pixel is stored as 0xffRRGGBB
+ (where RR, GG, and BB are the red, green and blue
+ color channels, ff is the hexadecimal value 255).
+
+ Printing is handled by the \c print() slot:
+
+ \snippet widgets/scribble/scribblearea.cpp 21
+
+ We construct a high resolution QPrinter object for the required
+ output format, using a QPrintDialog to ask the user to specify a
+ page size and indicate how the output should be formatted on the page.
+
+ If the dialog is accepted, we perform the task of printing to the paint
+ device:
+
+ \snippet widgets/scribble/scribblearea.cpp 22
+
+ Printing an image to a file in this way is simply a matter of
+ painting onto the QPrinter. We scale the image to fit within the
+ available space on the page before painting it onto the paint
+ device.
+
+ \section1 MainWindow Class Definition
+
+ \snippet widgets/scribble/mainwindow.h 0
+
+ The \c MainWindow class inherits from QMainWindow. We reimplement
+ the \l{QWidget::closeEvent()}{closeEvent()} handler from QWidget.
+ The \c open(), \c save(), \c penColor() and \c penWidth()
+ slots correspond to menu entries. In addition we create four
+ private functions.
+
+ We use the boolean \c maybeSave() function to check if there are
+ any unsaved changes. If there are unsaved changes, we give the
+ user the opportunity to save these changes. The function returns
+ \c false if the user clicks \uicontrol Cancel. We use the \c saveFile()
+ function to let the user save the image currently displayed in
+ the scribble area.
+
+ \section1 MainWindow Class Implementation
+
+ \snippet widgets/scribble/mainwindow.cpp 0
+
+ In the constructor, we create a scribble area which we make the
+ central widget of the \c MainWindow widget. Then we create the
+ associated actions and menus.
+
+ \snippet widgets/scribble/mainwindow.cpp 1
+ \snippet widgets/scribble/mainwindow.cpp 2
+
+ Close events are sent to widgets that the users want to close,
+ usually by clicking \uicontrol{File|Exit} or by clicking the \uicontrol X
+ title bar button. By reimplementing the event handler, we can
+ intercept attempts to close the application.
+
+ In this example, we use the close event to ask the user to save
+ any unsaved changes. The logic for that is located in the \c
+ maybeSave() function. If \c maybeSave() returns true, there are
+ no modifications or the users successfully saved them, and we
+ accept the event. The application can then terminate normally. If
+ \c maybeSave() returns false, the user clicked \uicontrol Cancel, so we
+ "ignore" the event, leaving the application unaffected by it.
+
+ \snippet widgets/scribble/mainwindow.cpp 3
+ \snippet widgets/scribble/mainwindow.cpp 4
+
+ In the \c open() slot we first give the user the opportunity to
+ save any modifications to the currently displayed image, before a
+ new image is loaded into the scribble area. Then we ask the user
+ to choose a file and we load the file in the \c ScribbleArea.
+
+ \snippet widgets/scribble/mainwindow.cpp 5
+ \snippet widgets/scribble/mainwindow.cpp 6
+
+ The \c save() slot is called when the users choose the \uicontrol {Save
+ As} menu entry, and then choose an entry from the format menu. The
+ first thing we need to do is to find out which action sent the
+ signal using QObject::sender(). This function returns the sender
+ as a QObject pointer. Since we know that the sender is an action
+ object, we can safely cast the QObject. We could have used a
+ C-style cast or a C++ \c static_cast<>(), but as a defensive
+ programming technique we use a qobject_cast(). The advantage is
+ that if the object has the wrong type, a null pointer is
+ returned. Crashes due to null pointers are much easier to diagnose
+ than crashes due to unsafe casts.
+
+ Once we have the action, we extract the chosen format using
+ QAction::data(). (When the actions are created, we use
+ QAction::setData() to set our own custom data attached to the
+ action, as a QVariant. More on this when we review \c
+ createActions().)
+
+ Now that we know the format, we call the private \c saveFile()
+ function to save the currently displayed image.
+
+ \snippet widgets/scribble/mainwindow.cpp 7
+ \snippet widgets/scribble/mainwindow.cpp 8
+
+ We use the \c penColor() slot to retrieve a new color from the
+ user with a QColorDialog. If the user chooses a new color, we
+ make it the scribble area's color.
+
+ \snippet widgets/scribble/mainwindow.cpp 9
+ \snippet widgets/scribble/mainwindow.cpp 10
+
+ To retrieve a new pen width in the \c penWidth() slot, we use
+ QInputDialog. The QInputDialog class provides a simple
+ convenience dialog to get a single value from the user. We use
+ the static QInputDialog::getInt() function, which combines a
+ QLabel and a QSpinBox. The QSpinBox is initialized with the
+ scribble area's pen width, allows a range from 1 to 50, a step of
+ 1 (meaning that the up and down arrow increment or decrement the
+ value by 1).
+
+ The boolean \c ok variable will be set to \c true if the user
+ clicked \uicontrol OK and to \c false if the user pressed \uicontrol Cancel.
+
+ \snippet widgets/scribble/mainwindow.cpp 11
+ \snippet widgets/scribble/mainwindow.cpp 12
+
+ We implement the \c about() slot to create a message box
+ describing what the example is designed to show.
+
+ \snippet widgets/scribble/mainwindow.cpp 13
+ \snippet widgets/scribble/mainwindow.cpp 14
+
+ In the \c createAction() function we create the actions
+ representing the menu entries and connect them to the appropriate
+ slots. In particular we create the actions found in the \uicontrol
+ {Save As} sub-menu. We use QImageWriter::supportedImageFormats()
+ to get a list of the supported formats (as a QList<QByteArray>).
+
+ Then we iterate through the list, creating an action for each
+ format. We call QAction::setData() with the file format, so we
+ can retrieve it later as QAction::data(). We could also have
+ deduced the file format from the action's text, by truncating the
+ "...", but that would have been inelegant.
+
+ \snippet widgets/scribble/mainwindow.cpp 15
+ \snippet widgets/scribble/mainwindow.cpp 16
+
+ In the \c createMenu() function, we add the previously created
+ format actions to the \c saveAsMenu. Then we add the rest of the
+ actions as well as the \c saveAsMenu sub-menu to the \uicontrol File,
+ \uicontrol Options and \uicontrol Help menus.
+
+ The QMenu class provides a menu widget for use in menu bars,
+ context menus, and other popup menus. The QMenuBar class provides
+ a horizontal menu bar with a list of pull-down \l{QMenu}s. At the
+ end we put the \uicontrol File and \uicontrol Options menus in the \c
+ {MainWindow}'s menu bar, which we retrieve using the
+ QMainWindow::menuBar() function.
+
+ \snippet widgets/scribble/mainwindow.cpp 17
+ \snippet widgets/scribble/mainwindow.cpp 18
+
+ In \c mayBeSave(), we check if there are any unsaved changes. If
+ there are any, we use QMessageBox to give the user a warning that
+ the image has been modified and the opportunity to save the
+ modifications.
+
+ As with QColorDialog and QFileDialog, the easiest way to create a
+ QMessageBox is to use its static functions. QMessageBox provides
+ a range of different messages arranged along two axes: severity
+ (question, information, warning and critical) and complexity (the
+ number of necessary response buttons). Here we use the \c
+ warning() function sice the message is rather important.
+
+ If the user chooses to save, we call the private \c saveFile()
+ function. For simplicitly, we use PNG as the file format; the
+ user can always press \uicontrol Cancel and save the file using another
+ format.
+
+ The \c maybeSave() function returns \c false if the user clicks
+ \uicontrol Cancel; otherwise it returns \c true.
+
+ \snippet widgets/scribble/mainwindow.cpp 19
+ \snippet widgets/scribble/mainwindow.cpp 20
+
+ In \c saveFile(), we pop up a file dialog with a file name
+ suggestion. The static QFileDialog::getSaveFileName() function
+ returns a file name selected by the user. The file does not have
+ to exist.
+*/
diff --git a/examples/widgets/doc/sdi.qdoc b/examples/widgets/doc/sdi.qdoc
new file mode 100644
index 0000000000..b686888797
--- /dev/null
+++ b/examples/widgets/doc/sdi.qdoc
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example mainwindows/sdi
+ \title SDI Example
+
+ The SDI example shows how to create a Single Document Interface. It uses a number of
+ top-level windows to display the contents of different text files.
+
+ \image sdi-example.png
+*/
diff --git a/examples/widgets/doc/shapedclock.qdoc b/examples/widgets/doc/shapedclock.qdoc
new file mode 100644
index 0000000000..8d7b856fd6
--- /dev/null
+++ b/examples/widgets/doc/shapedclock.qdoc
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/shapedclock
+ \title Shaped Clock Example
+
+ The Shaped Clock example shows how to apply a widget mask to a top-level
+ widget to produce a shaped window.
+
+ \image shapedclock-example.png
+
+ Widget masks are used to customize the shapes of top-level widgets by restricting
+ the available area for painting. On some window systems, setting certain window flags
+ will cause the window decoration (title bar, window frame, buttons) to be disabled,
+ allowing specially-shaped windows to be created. In this example, we use this feature
+ to create a circular window containing an analog clock.
+
+ Since this example's window does not provide a \uicontrol File menu or a close
+ button, we provide a context menu with an \uicontrol Exit entry so that the example
+ can be closed. Click the right mouse button over the window to open this menu.
+
+ \section1 ShapedClock Class Definition
+
+ The \c ShapedClock class is based on the \c AnalogClock class defined in the
+ \l{Analog Clock Example}{Analog Clock} example. The whole class definition is
+ presented below:
+
+ \snippet widgets/shapedclock/shapedclock.h 0
+
+ The \l{QWidget::paintEvent()}{paintEvent()} implementation is the same as that found
+ in the \c AnalogClock class. We implement \l{QWidget::sizeHint()}{sizeHint()}
+ so that we don't have to resize the widget explicitly. We also provide an event
+ handler for resize events. This allows us to update the mask if the clock is resized.
+
+ Since the window containing the clock widget will have no title bar, we provide
+ implementations for \l{QWidget::mouseMoveEvent()}{mouseMoveEvent()} and
+ \l{QWidget::mousePressEvent()}{mousePressEvent()} to allow the clock to be dragged
+ around the screen. The \c dragPosition variable lets us keep track of where the user
+ last clicked on the widget.
+
+ \section1 ShapedClock Class Implementation
+
+ The \c ShapedClock constructor performs many of the same tasks as the \c AnalogClock
+ constructor. We set up a timer and connect it to the widget's update() slot:
+
+ \snippet widgets/shapedclock/shapedclock.cpp 0
+
+ We inform the window manager that the widget is not to be decorated with a window
+ frame by setting the Qt::FramelessWindowHint flag on the widget. As a result, we need
+ to provide a way for the user to move the clock around the screen.
+
+ Mouse button events are delivered to the \c mousePressEvent() handler:
+
+ \snippet widgets/shapedclock/shapedclock.cpp 1
+
+ If the left mouse button is pressed over the widget, we record the displacement in
+ global (screen) coordinates between the top-left position of the widget's frame (even
+ when hidden) and the point where the mouse click occurred. This displacement will be
+ used if the user moves the mouse while holding down the left button. Since we acted
+ on the event, we accept it by calling its \l{QEvent::accept()}{accept()} function.
+
+ \image shapedclock-dragging.png
+
+ The \c mouseMoveEvent() handler is called if the mouse is moved over the widget.
+
+ \snippet widgets/shapedclock/shapedclock.cpp 2
+
+ If the left button is held down while the mouse is moved, the top-left corner of the
+ widget is moved to the point given by subtracting the \c dragPosition from the current
+ cursor position in global coordinates. If we drag the widget, we also accept the event.
+
+ The \c paintEvent() function is given for completeness. See the
+ \l{Analog Clock Example}{Analog Clock} example for a description of the process used
+ to render the clock.
+
+ \snippet widgets/shapedclock/shapedclock.cpp 3
+
+ In the \c resizeEvent() handler, we re-use some of the code from the \c paintEvent()
+ to determine the region of the widget that is visible to the user:
+
+ \snippet widgets/shapedclock/shapedclock.cpp 4
+
+ Since the clock face is a circle drawn in the center of the widget, this is the region
+ we use as the mask.
+
+ Although the lack of a window frame may make it difficult for the user to resize the
+ widget on some platforms, it will not necessarily be impossible. The \c resizeEvent()
+ function ensures that the widget mask will always be updated if the widget's dimensions
+ change, and additionally ensures that it will be set up correctly when the widget is
+ first displayed.
+
+ Finally, we implement the \c sizeHint() for the widget so that it is given a reasonable
+ default size when it is first shown:
+
+ \snippet widgets/shapedclock/shapedclock.cpp 5
+
+ \section1 Notes on Widget Masks
+
+ Since QRegion allows arbitrarily complex regions to be created, widget masks can be
+ made to suit the most unconventionally-shaped windows, and even allow widgets to be
+ displayed with holes in them.
+
+ Widget masks can also be constructed by using the contents of pixmap to define the
+ opaque part of the widget. For a pixmap with an alpha channel, a suitable mask can be
+ obtained with QPixmap::mask().
+*/
diff --git a/examples/widgets/doc/simpledommodel.qdoc b/examples/widgets/doc/simpledommodel.qdoc
new file mode 100644
index 0000000000..2564c654fa
--- /dev/null
+++ b/examples/widgets/doc/simpledommodel.qdoc
@@ -0,0 +1,280 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/simpledommodel
+ \title Simple DOM Model Example
+
+ The Simple DOM Model example shows how an existing class can be adapted for use with
+ the model/view framework.
+
+ \image simpledommodel-example.png
+
+ Qt provides two complementary sets of classes for reading XML files: The classes based
+ around QXmlReader provide a SAX-style API for incremental reading of large files, and
+ the classes based around QDomDocument enable developers to access the contents of XML
+ files using a Document Object Model (DOM) API.
+
+ In this example, we create a model that uses the DOM API to expose the structure and
+ contents of XML documents to views via the standard QAbstractModel interface.
+
+ \section1 Design and Concepts
+
+ Reading an XML document with Qt's DOM classes is a straightforward process. Typically,
+ the contents of a file are supplied to QDomDocument, and nodes are accessed using the
+ functions provided by QDomNode and its subclasses.
+
+ \omit
+ For example, the following code
+ snippet reads the contents of a file into a QDomDocument object and traverses the
+ document, reading all the plain text that can be found:
+
+ \snippet doc/src/snippets/code/doc_src_examples_simpledommodel.cpp 0
+
+ In principle, the functions provided by QDomNode can be used to navigate from any
+ given starting point in a document to the piece of data requested by another component.
+ Since QDomDocument maintains information about the structure of a document, we can
+ use this to implement the required virtual functions in a QAbstractItemModel subclass.
+ \endomit
+
+ The aim is to use the structure provided by QDomDocument by wrapping QDomNode objects
+ in item objects similar to the \c TreeItem objects used in the
+ \l{Simple Tree Model Example}{Simple Tree Model} example.
+
+ \section1 DomModel Class Definition
+
+ Let us begin by examining the \c DomModel class:
+
+ \snippet itemviews/simpledommodel/dommodel.h 0
+
+ The class definition contains all the basic functions that are needed for a
+ read-only model. Only the constructor and \c document() function are specific to
+ this model. The private \c domDocument variable is used to hold the document
+ that is exposed by the model; the \c rootItem variable contains a pointer to
+ the root item in the model.
+
+ \section1 DomItem Class Definition
+
+ The \c DomItem class is used to hold information about a specific QDomNode in
+ the document:
+
+ \snippet itemviews/simpledommodel/domitem.h 0
+
+ Each \c DomItem provides a wrapper for a QDomNode obtained from the underlying
+ document which contains a reference to the node, it's location in the parent node's
+ list of child nodes, and a pointer to a parent wrapper item.
+
+ The \c parent(), \c child(), and \c row() functions are convenience functions for
+ the \c DomModel to use that provide basic information about the item to be discovered
+ quickly. The node() function provides access to the underlying QDomNode object.
+
+ As well as the information supplied in the constructor, the class maintains a cache
+ of information about any child items. This is used to provide a collection of
+ persistent item objects that the model can identify consistently and improve the
+ performance of the model when accessing child items.
+
+ \section1 DomItem Class Implementation
+
+ Since the \c DomItem class is only a thin wrapper around QDomNode objects, with a
+ few additional features to help improve performance and memory usage, we can provide
+ a brief outline of the class before discussing the model itself.
+
+ The constructor simply records details of the QDomNode that needs to be wrapped:
+
+ \snippet itemviews/simpledommodel/domitem.cpp 0
+ \snippet itemviews/simpledommodel/domitem.cpp 1
+
+ As a result, functions to provide the parent wrapper, the row number occupied by
+ the item in its parent's list of children, and the underlying QDomNode for each item
+ are straightforward to write:
+
+ \snippet itemviews/simpledommodel/domitem.cpp 4
+ \codeline
+ \snippet itemviews/simpledommodel/domitem.cpp 6
+ \codeline
+ \snippet itemviews/simpledommodel/domitem.cpp 3
+
+ It is necessary to maintain a collection of items which can be consistently identified
+ by the model. For that reason, we maintain a hash of child wrapper items that, to
+ minimize memory usage, is initially empty. The model uses the item's \c child()
+ function to help create model indexes, and this constructs wrappers for the children
+ of the item's QDomNode, relating the row number of each child to the newly-constructed
+ wrapper:
+
+ \snippet itemviews/simpledommodel/domitem.cpp 5
+
+ If a QDomNode was previously wrapped, the cached wrapper is returned; otherwise, a
+ new wrapper is constructed and stored for valid children, and zero is returned for
+ invalid ones.
+
+ The class's destructor deletes all the child items of the wrapper:
+
+ \snippet itemviews/simpledommodel/domitem.cpp 2
+
+ These, in turn, will delete their children and free any QDomNode objects in use.
+
+ \section1 DomModel Class Implementation
+
+ The structure provided by the \c DomItem class makes the implementation of \c DomModel
+ similar to the \c TreeModel shown in the
+ \l{Simple Tree Model Example}{Simple Tree Model} example.
+
+ The constructor accepts an existing document and a parent object for the model:
+
+ \snippet itemviews/simpledommodel/dommodel.cpp 0
+
+ A shallow copy of the document is stored for future reference, and a root item is
+ created to provide a wrapper around the document. We assign the root item a row
+ number of zero only to be consistent since the root item will have no siblings.
+
+ Since the model only contains information about the root item, the destructor only
+ needs to delete this one item:
+
+ \snippet itemviews/simpledommodel/dommodel.cpp 1
+
+ All of the child items in the tree will be deleted by the \c DomItem destructor as
+ their parent items are deleted.
+
+ \section2 Basic Properties of The Model
+
+ Some aspects of the model do not depend on the structure of the underlying document,
+ and these are simple to implement.
+
+ The number of columns exposed by the model is returned by the \c columnCount()
+ function:
+
+ \snippet itemviews/simpledommodel/dommodel.cpp 2
+
+ This value is fixed, and does not depend on the location or type of the underlying
+ node in the document. We will use these three columns to display different kinds of
+ data from the underlying document.
+
+ Since we only implement a read-only model, the \c flags() function is straightforward
+ to write:
+
+ \snippet itemviews/simpledommodel/dommodel.cpp 5
+
+ Since the model is intended for use in a tree view, the \c headerData() function only
+ provides a horizontal header:
+
+ \snippet itemviews/simpledommodel/dommodel.cpp 6
+
+ The model presents the names of nodes in the first column, element attributes in the
+ second, and any node values in the third.
+
+ \section2 Navigating The Document
+
+ The index() function creates a model index for the item with the given row, column,
+ and parent in the model:
+
+ \snippet itemviews/simpledommodel/dommodel.cpp 7
+
+ The function first has to relate the parent index to an item that contains a node
+ from the underlying document. If the parent index is invalid, it refers to the root
+ node in the document, so we retrieve the root item that wraps it; otherwise, we
+ obtain a pointer to the relevant item using the QModelIndex::internalPointer()
+ function. We are able to extract a pointer in this way because any valid model index
+ will have been created by this function, and we store pointers to item objects in
+ any new indexes that we create with QAbstractItemModel::createIndex():
+
+ \snippet itemviews/simpledommodel/dommodel.cpp 8
+
+ A child item for the given row is provided by the parent item's \c child() function.
+ If a suitable child item was found then we call
+ \l{QAbstractItemModel::createIndex()}{createIndex()} to produce a model index for the
+ requested row and column, passing a pointer to the child item for it to store
+ internally. If no suitable child item is found, an invalid model index is returned.
+
+ Note that the items themselves maintain ownership of their child items. This means
+ that the model does not need to keep track of the child items that have been created,
+ and can let the items themselves tidy up when they are deleted.
+
+ The number of rows beneath a given item in the model is returned by the \c rowCount()
+ function, and is the number of child nodes contained by the node that corresponds to
+ the specified model index:
+
+ \snippet itemviews/simpledommodel/dommodel.cpp 10
+
+ To obtain the relevant node in the underlying document, we access the item via the
+ internal pointer stored in the model index. If an invalid index is supplied, the
+ root item is used instead. We use the item's \c node() function to access the node
+ itself, and simply count the number of child nodes it contains.
+
+ Since the model is used to represent a hierarchical data structure, it needs to
+ provide an implementation for the \c parent() function. This returns a model index
+ that corresponds to the parent of a child model index supplied as its argument:
+
+ \snippet itemviews/simpledommodel/dommodel.cpp 9
+
+ For valid indexes other than the index corresponding to the root item, we obtain
+ a pointer to the relevant item using the method described in the \c index() function,
+ and use the item's \c parent() function to obtain a pointer to the parent item.
+
+ If no valid parent item exists, or if the parent item is the root item, we can simply
+ follow convention and return an invalid model index. For all other parent items, we
+ create a model index containing the appropriate row and column numbers, and a pointer
+ to the parent item we just obtained.
+
+ Data is provided by the \c data() function. For simplicity, we only provide data for
+ the \l{Qt::DisplayRole}{display role}, returning an invalid variant for all other
+ requests:
+
+ \snippet itemviews/simpledommodel/dommodel.cpp 3
+
+ As before, we obtain an item pointer for the index supplied, and use it to obtain
+ the underlying document node. Depending on the column specified, the data we return
+ is obtained in different ways:
+
+ \snippet itemviews/simpledommodel/dommodel.cpp 4
+
+ For the first column, we return the node's name. For the second column, we read any
+ attributes that the node may have, and return a string that contains a space-separated
+ list of attribute-value assignments. For the third column, we return any value that
+ the node may have; this allows the contents of text nodes to be displayed in a view.
+
+ If data from any other column is requested, an invalid variant is returned.
+
+ \section1 Implementation Notes
+
+ Ideally, we would rely on the structure provided by QDomDocument to help us write
+ the \l{QAbstractItemModel::parent()}{parent()} and
+ \l{QAbstractItemModel::index()}{index()} functions that are required when subclassing
+ QAbstractItemModel. However, since Qt's DOM classes use their own system for
+ dynamically allocating memory for DOM nodes, we cannot guarantee that the QDomNode
+ objects returned for a given piece of information will be the same for subsequent
+ accesses to the document.
+
+ We use item wrappers for each QDomNode to provide consistent pointers that the model
+ can use to navigate the document structure.
+ \omit
+ Since these items contain value references to the QDomNode objects themselves, this
+ has the side effect that the DOM nodes themselves can be used to reliably navigate
+ the document [not sure about this - QDom* may return different QDomNode objects for
+ the same piece of information]. However, this advantage is redundant since we need to
+ use wrapper items to obtain it. [Possible use of QDomNode cache in the model itself.]
+ \endomit
+*/
diff --git a/examples/widgets/doc/simpletreemodel.qdoc b/examples/widgets/doc/simpletreemodel.qdoc
new file mode 100644
index 0000000000..a2b6010441
--- /dev/null
+++ b/examples/widgets/doc/simpletreemodel.qdoc
@@ -0,0 +1,333 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/simpletreemodel
+ \title Simple Tree Model Example
+
+ The Simple Tree Model example shows how to create a basic, read-only
+ hierarchical model to use with Qt's standard view classes. For a
+ description of simple non-hierarchical list and table models, see the
+ \l{Model/View Programming} overview.
+
+ \image simpletreemodel-example.png
+
+ Qt's model/view architecture provides a standard way for views to
+ manipulate information in a data source, using an abstract model
+ of the data to simplify and standardize the way it is accessed.
+ Simple models represent data as a table of items, and allow views
+ to access this data via an
+ \l{Model/View Programming#Models}{index-based} system. More generally,
+ models can be used to represent data in the form of a tree structure
+ by allowing each item to act as a parent to a table of child items.
+
+ Before attempting to implement a tree model, it is worth considering whether
+ the data is supplied by an external source, or whether it is going to be
+ maintained within the model itself. In this example, we will implement an
+ internal structure to hold data rather than discuss how to package data from
+ an external source.
+
+ \section1 Design and Concepts
+
+ The data structure that we use to represent the structure of the data takes
+ the form of a tree built from \c TreeItem objects. Each \c TreeItem
+ represents an item in a tree view, and contains several columns of data.
+
+ \target SimpleTreeModelStructure
+ \table
+ \row \li \inlineimage treemodel-structure.png
+ \li \b{Simple Tree Model Structure}
+
+ The data is stored internally in the model using \c TreeItem objects that
+ are linked together in a pointer-based tree structure. Generally, each
+ \c TreeItem has a parent item, and can have a number of child items.
+ However, the root item in the tree structure has no parent item and it
+ is never referenced outside the model.
+
+ Each \c TreeItem contains information about its place in the tree
+ structure; it can return its parent item and its row number. Having
+ this information readily available makes implementing the model easier.
+
+ Since each item in a tree view usually contains several columns of data
+ (a title and a summary in this example), it is natural to store this
+ information in each item. For simplicity, we will use a list of QVariant
+ objects to store the data for each column in the item.
+ \endtable
+
+ The use of a pointer-based tree structure means that, when passing a
+ model index to a view, we can record the address of the corresponding
+ item in the index (see QAbstractItemModel::createIndex()) and retrieve
+ it later with QModelIndex::internalPointer(). This makes writing the
+ model easier and ensures that all model indexes that refer to the same
+ item have the same internal data pointer.
+
+ With the appropriate data structure in place, we can create a tree model
+ with a minimal amount of extra code to supply model indexes and data to
+ other components.
+
+ \section1 TreeItem Class Definition
+
+ The \c TreeItem class is defined as follows:
+
+ \snippet itemviews/simpletreemodel/treeitem.h 0
+
+ The class is a basic C++ class. It does not inherit from QObject or
+ provide signals and slots. It is used to hold a list of QVariants,
+ containing column data, and information about its position in the tree
+ structure. The functions provide the following features:
+
+ \list
+ \li The \c appendChildItem() is used to add data when the model is first
+ constructed and is not used during normal use.
+ \li The \c child() and \c childCount() functions allow the model to obtain
+ information about any child items.
+ \li Information about the number of columns associated with the item is
+ provided by \c columnCount(), and the data in each column can be
+ obtained with the data() function.
+ \li The \c row() and \c parent() functions are used to obtain the item's
+ row number and parent item.
+ \endlist
+
+ The parent item and column data are stored in the \c parentItem and
+ \c itemData private member variables. The \c childItems variable contains
+ a list of pointers to the item's own child items.
+
+ \section1 TreeItem Class Implementation
+
+ The constructor is only used to record the item's parent and the data
+ associated with each column.
+
+ \snippet itemviews/simpletreemodel/treeitem.cpp 0
+
+ A pointer to each of the child items belonging to this item will be
+ stored in the \c childItems private member variable. When the class's
+ destructor is called, it must delete each of these to ensure that
+ their memory is reused:
+
+ \snippet itemviews/simpletreemodel/treeitem.cpp 1
+
+ Since each of the child items are constructed when the model is initially
+ populated with data, the function to add child items is straightforward:
+
+ \snippet itemviews/simpletreemodel/treeitem.cpp 2
+
+ Each item is able to return any of its child items when given a suitable
+ row number. For example, in the \l{#SimpleTreeModelStructure}{above diagram},
+ the item marked with the letter "A" corresponds to the child of the root item
+ with \c{row = 0}, the "B" item is a child of the "A" item with \c{row = 1},
+ and the "C" item is a child of the root item with \c{row = 1}.
+
+ The \c child() function returns the child that corresponds to
+ the specified row number in the item's list of child items:
+
+ \snippet itemviews/simpletreemodel/treeitem.cpp 3
+
+ The number of child items held can be found with \c childCount():
+
+ \snippet itemviews/simpletreemodel/treeitem.cpp 4
+
+ The \c TreeModel uses this function to determine the number of rows that
+ exist for a given parent item.
+
+ The \c row() function reports the item's location within its parent's
+ list of items:
+
+ \snippet itemviews/simpletreemodel/treeitem.cpp 8
+
+ Note that, although the root item (with no parent item) is automatically
+ assigned a row number of 0, this information is never used by the model.
+
+ The number of columns of data in the item is trivially returned by the
+ \c columnCount() function.
+
+ \snippet itemviews/simpletreemodel/treeitem.cpp 5
+
+ Column data is returned by the \c data() function, taking advantage of
+ QList's ability to provide sensible default values if the column number
+ is out of range:
+
+ \snippet itemviews/simpletreemodel/treeitem.cpp 6
+
+ The item's parent is found with \c parent():
+
+ \snippet itemviews/simpletreemodel/treeitem.cpp 7
+
+ Note that, since the root item in the model will not have a parent, this
+ function will return zero in that case. We need to ensure that the model
+ handles this case correctly when we implement the \c TreeModel::parent()
+ function.
+
+ \section1 TreeModel Class Definition
+
+ The \c TreeModel class is defined as follows:
+
+ \snippet itemviews/simpletreemodel/treemodel.h 0
+
+ This class is similar to most other subclasses of QAbstractItemModel that
+ provide read-only models. Only the form of the constructor and the
+ \c setupModelData() function are specific to this model. In addition, we
+ provide a destructor to clean up when the model is destroyed.
+
+ \section1 TreeModel Class Implementation
+
+ For simplicity, the model does not allow its data to be edited. As a
+ result, the constructor takes an argument containing the data that the
+ model will share with views and delegates:
+
+ \snippet itemviews/simpletreemodel/treemodel.cpp 0
+
+ It is up to the constructor to create a root item for the model. This
+ item only contains vertical header data for convenience. We also use it
+ to reference the internal data structure that contains the model data,
+ and it is used to represent an imaginary parent of top-level items in
+ the model.
+
+ The model's internal data structure is populated with items by the
+ \c setupModelData() function. We will examine this function separately
+ at the end of this document.
+
+ The destructor ensures that the root item and all of its descendants
+ are deleted when the model is destroyed:
+
+ \snippet itemviews/simpletreemodel/treemodel.cpp 1
+
+ Since we cannot add data to the model after it is constructed and set
+ up, this simplifies the way that the internal tree of items is managed.
+
+ Models must implement an \c index() function to provide indexes for
+ views and delegates to use when accessing data. Indexes are created
+ for other components when they are referenced by their row and column
+ numbers, and their parent model index. If an invalid model
+ index is specified as the parent, it is up to the model to return an
+ index that corresponds to a top-level item in the model.
+
+ When supplied with a model index, we first check whether it is valid.
+ If it is not, we assume that a top-level item is being referred to;
+ otherwise, we obtain the data pointer from the model index with its
+ \l{QModelIndex::internalPointer()}{internalPointer()} function and use
+ it to reference a \c TreeItem object. Note that all the model indexes
+ that we construct will contain a pointer to an existing \c TreeItem,
+ so we can guarantee that any valid model indexes that we receive will
+ contain a valid data pointer.
+
+ \snippet itemviews/simpletreemodel/treemodel.cpp 6
+
+ Since the row and column arguments to this function refer to a
+ child item of the corresponding parent item, we obtain the item using
+ the \c TreeItem::child() function. The
+ \l{QAbstractItemModel::createIndex()}{createIndex()} function is used
+ to create a model index to be returned. We specify the row and column
+ numbers, and a pointer to the item itself. The model index can be used
+ later to obtain the item's data.
+
+ The way that the \c TreeItem objects are defined makes writing the
+ \c parent() function easy:
+
+ \snippet itemviews/simpletreemodel/treemodel.cpp 7
+
+ We only need to ensure that we never return a model index corresponding
+ to the root item. To be consistent with the way that the \c index()
+ function is implemented, we return an invalid model index for the
+ parent of any top-level items in the model.
+
+ When creating a model index to return, we must specify the row and
+ column numbers of the parent item within its own parent. We can
+ easily discover the row number with the \c TreeItem::row() function,
+ but we follow a convention of specifying 0 as the column number of
+ the parent. The model index is created with
+ \l{QAbstractItemModel::createIndex()}{createIndex()} in the same way
+ as in the \c index() function.
+
+ The \c rowCount() function simply returns the number of child items
+ for the \c TreeItem that corresponds to a given model index, or the
+ number of top-level items if an invalid index is specified:
+
+ \snippet itemviews/simpletreemodel/treemodel.cpp 8
+
+ Since each item manages its own column data, the \c columnCount()
+ function has to call the item's own \c columnCount() function to
+ determine how many columns are present for a given model index.
+ As with the \c rowCount() function, if an invalid model index is
+ specified, the number of columns returned is determined from the
+ root item:
+
+ \snippet itemviews/simpletreemodel/treemodel.cpp 2
+
+ Data is obtained from the model via \c data(). Since the item manages
+ its own columns, we need to use the column number to retrieve the data
+ with the \c TreeItem::data() function:
+
+ \snippet itemviews/simpletreemodel/treemodel.cpp 3
+
+ Note that we only support the \l{Qt::ItemDataRole}{DisplayRole}
+ in this implementation, and we also return invalid QVariant objects for
+ invalid model indexes.
+
+ We use the \c flags() function to ensure that views know that the
+ model is read-only:
+
+ \snippet itemviews/simpletreemodel/treemodel.cpp 4
+
+ The \c headerData() function returns data that we conveniently stored
+ in the root item:
+
+ \snippet itemviews/simpletreemodel/treemodel.cpp 5
+
+ This information could have been supplied in a different way: either
+ specified in the constructor, or hard coded into the \c headerData()
+ function.
+
+ \section1 Setting Up the Data in the Model
+
+ We use the \c setupModelData() function to set up the initial data in
+ the model. This function parses a text file, extracting strings of
+ text to use in the model, and creates item objects that record both
+ the data and the overall model structure.
+ Naturally, this function works in a way that is very specific to
+ this model. We provide the following description of its behavior,
+ and refer the reader to the example code itself for more information.
+
+ We begin with a text file in the following format:
+
+ \snippet doc/src/snippets/code/doc_src_examples_simpletreemodel.qdoc 0
+ \dots
+ \snippet doc/src/snippets/code/doc_src_examples_simpletreemodel.qdoc 1
+
+ We process the text file with the following two rules:
+
+ \list
+ \li For each pair of strings on each line, create an item (or node)
+ in a tree structure, and place each string in a column of data
+ in the item.
+ \li When the first string on a line is indented with respect to the
+ first string on the previous line, make the item a child of the
+ previous item created.
+ \endlist
+
+ To ensure that the model works correctly, it is only necessary to
+ create instances of \c TreeItem with the correct data and parent item.
+*/
diff --git a/examples/widgets/doc/simplewidgetmapper.qdoc b/examples/widgets/doc/simplewidgetmapper.qdoc
new file mode 100644
index 0000000000..2b7cd2d79a
--- /dev/null
+++ b/examples/widgets/doc/simplewidgetmapper.qdoc
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/simplewidgetmapper
+ \title Simple Widget Mapper Example
+
+ The Simple Widget Mapper example shows how to use a widget mapper to display
+ data from a model in a collection of widgets.
+
+ \image simplewidgetmapper-example.png
+
+ The QDataWidgetMapper class allows information obtained from a
+ \l{Model Classes}{model} to be viewed and edited in a collection of
+ widgets instead of in an \l{View Classes}{item view}.
+ Any model derived from QAbstractItemModel can be used as the source of
+ data and almost any input widget can be used to display it.
+
+ The example itself is very simple: we create \c Window, a QWidget subclass
+ that we use to hold the widgets used to present the data, and show it. The
+ \c Window class will provide buttons that the user can click to show
+ different records from the model.
+
+ \section1 Window Class Definition
+
+ The class provides a constructor, a slot to keep the buttons up to date,
+ and a private function to set up the model:
+
+ \snippet itemviews/simplewidgetmapper/window.h Window definition
+
+ In addition to the QDataWidgetMapper object and the controls used to make
+ up the user interface, we use a QStandardItemModel to hold our data.
+ We could use a custom model, but this standard implementation is sufficient
+ for our purposes.
+
+ \section1 Window Class Implementation
+
+ The constructor of the \c Window class can be explained in three parts.
+ In the first part, we set up the widgets used for the user interface:
+
+ \snippet itemviews/simplewidgetmapper/window.cpp Set up widgets
+
+ We also set up the buddy relationships between various labels and the
+ corresponding input widgets.
+
+ Next, we set up the widget mapper, relating each input widget to a column
+ in the model specified by the call to \l{QDataWidgetMapper::}{setModel()}:
+
+ \snippet itemviews/simplewidgetmapper/window.cpp Set up the mapper
+
+ We also connect the mapper to the \uicontrol{Next} and \uicontrol{Previous} buttons
+ via its \l{QDataWidgetMapper::}{toNext()} and
+ \l{QDataWidgetMapper::}{toPrevious()} slots. The mapper's
+ \l{QDataWidgetMapper::}{currentIndexChanged()} signal is connected to the
+ \c{updateButtons()} slot in the window which we'll show later.
+
+ In the final part of the constructor, we set up the layout, placing each
+ of the widgets in a grid (we could also use a QFormLayout for this):
+
+ \snippet itemviews/simplewidgetmapper/window.cpp Set up the layout
+
+ Lastly, we set the window title and initialize the mapper by setting it to
+ refer to the first row in the model.
+
+ The model is initialized in the window's \c{setupModel()} function. Here,
+ we create a standard model with 5 rows and 3 columns, and we insert some
+ sample names, addresses and ages into each row:
+
+ \snippet itemviews/simplewidgetmapper/window.cpp Set up the model
+
+ As a result, each row can be treated like a record in a database, and the
+ widget mapper will read the data from each row, using the column numbers
+ specified earlier to access the correct data for each widget. This is
+ shown in the following diagram:
+
+ \image widgetmapper-simple-mapping.png
+
+ Since the user can navigate using the buttons in the user interface, the
+ example is fully-functional at this point, but to make it a bit more
+ user-friendly, we implement the \c{updateButtons()} slot to show when the
+ user is viewing the first or last records:
+
+ \snippet itemviews/simplewidgetmapper/window.cpp Slot for updating the buttons
+
+ If the mapper is referring to the first row in the model, the \uicontrol{Previous}
+ button is disabled. Similarly, the \uicontrol{Next} button is disabled if the
+ mapper reaches the last row in the model.
+
+ \section1 More Complex Mappings
+
+ The QDataWidgetMapper class makes it easy to relate information from a
+ model to widgets in a user interface. However, it is sometimes necessary
+ to use input widgets which offer choices to the user, such as QComboBox,
+ in conjunction with a widget mapper.
+
+ In these situations, although the mapping to input widgets remains simple,
+ more work needs to be done to expose additional data to the widget mapper.
+ This is covered by the \l{Combo Widget Mapper Example}{Combo Widget Mapper}
+ and \l{SQL Widget Mapper Example}{SQL Widget Mapper}
+ examples.
+*/
diff --git a/examples/widgets/doc/sipdialog.qdoc b/examples/widgets/doc/sipdialog.qdoc
new file mode 100644
index 0000000000..b5f18cb4be
--- /dev/null
+++ b/examples/widgets/doc/sipdialog.qdoc
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example dialogs/sipdialog
+ \title SIP Dialog Example
+ \ingroup qtce
+
+ The SIP Dialog example shows how to create a dialog that is aware of
+ the Windows Mobile SIP (Software Input Panel) and reacts to it.
+
+ \table
+ \row \li \inlineimage sipdialog-closed.png
+ \li \inlineimage sipdialog-opened.png
+ \endtable
+
+ Sometimes it is necessary for a dialog to take the SIP into account,
+ as the SIP may hide important input widgets. The SIP Dialog Example
+ shows how a \c Dialog object, \c dialog, can be resized accordingly
+ if the SIP is opened, by embedding the contents of \c dialog in a
+ QScrollArea.
+
+ \section1 Dialog Class Definition
+
+ The \c Dialog class is a subclass of QDialog that implements a public
+ slot, \c desktopResized(), and a public function, \c reactToSIP(). Also,
+ it holds a private instance of QRect, \c desktopGeometry.
+
+ \snippet dialogs/sipdialog/dialog.h Dialog header
+
+ \section1 Dialog Class Implementation
+
+ In the constructor of \c Dialog, we start by obtaining the
+ available geometry of the screen with
+ \l{QDesktopWidget::availableGeometry()}{availableGeometry()}. The
+ parameter used is \c 0 to indicate that we require the primary screen.
+
+ \snippet dialogs/sipdialog/dialog.cpp Dialog constructor part1
+
+ We set the window's title to "SIP Dialog Example" and declare a QScrollArea
+ object, \c scrollArea. Next we instantiate a QGroupBox, \c groupBox, with
+ \c scrollArea as its parent. The title of \c groupBox is also set to
+ "SIP Dialog Example". A QGridLayout object, \c gridLayout, is then used
+ as \c{groupBox}'s layout.
+
+ We create a QLineEdit, a QLabel and a QPushButton and we set the
+ \l{QWidget::setMinimumWidth()}{minimumWidth} property to 220 pixels,
+ respectively.
+
+ \snippet dialogs/sipdialog/dialog.cpp Dialog constructor part2
+
+ Also, all three widgets' text are set accordingly. The
+ \l{QGridLayout::setVerticalSpacing()}{verticalSpacing} property of
+ \c gridLayout is set based on the height of \c desktopGeometry. This
+ is to adapt to the different form factors of Windows Mobile. Then, we
+ add our widgets to the layout.
+
+ \snippet dialogs/sipdialog/dialog.cpp Dialog constructor part3
+
+ The \c{scrollArea}'s widget is set to \c groupBox. We use a QHBoxLayout
+ object, \c layout, to contain \c scrollArea. The \c{Dialog}'s layout
+ is set to \c layout and the scroll area's horizontal scroll bar is turned
+ off.
+
+ \snippet dialogs/sipdialog/dialog.cpp Dialog constructor part4
+
+ The following signals are connected to their respective slots:
+ \list
+ \li \c{button}'s \l{QPushButton::pressed()}{pressed()} signal to
+ \l{QApplication}'s \l{QApplication::closeAllWindows()}
+ {closeAllWindows()} slot,
+ \li \l{QDesktopWidget}'s \l{QDesktopWidget::workAreaResized()}
+ {workAreaResized()} signal to \c{dialog}'s \c desktopResized() slot.
+ \endlist
+
+ \snippet dialogs/sipdialog/dialog.cpp Dialog constructor part5
+
+ The \c desktopResized() function accepts an integer, \a screen,
+ corresponding to the screen's index. We only invoke \c reactToSIP()
+ if \a screen is the primary screen (e.g. index = 0).
+
+ \snippet dialogs/sipdialog/dialog.cpp desktopResized() function
+
+ The \c reactToSIP() function resizes \c dialog accordingly if the
+ desktop's available geometry changed vertically, as this change signifies
+ that the SIP may have been opened or closed.
+
+ \snippet dialogs/sipdialog/dialog.cpp reactToSIP() function
+
+ If the height has decreased, we unset the maximized window state.
+ Otherwise, we set the maximized window state. Lastly, we update
+ \c desktopGeometry to the desktop's available geometry.
+
+ \section1 The \c main() function
+
+ The \c main() function for the SIP Dialog example instantiates \c Dialog
+ and invokes its \l{QDialog::exec()}{exec()} function.
+
+ \snippet dialogs/sipdialog/main.cpp main() function
+
+ \note Although this example uses a dialog, the techniques used here apply to
+ all top-level widgets respectively.
+*/
diff --git a/examples/widgets/doc/sliders.qdoc b/examples/widgets/doc/sliders.qdoc
new file mode 100644
index 0000000000..efc52e24d7
--- /dev/null
+++ b/examples/widgets/doc/sliders.qdoc
@@ -0,0 +1,255 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/sliders
+ \title Sliders Example
+
+ Qt provides three types of slider-like widgets: QSlider,
+ QScrollBar and QDial. They all inherit most of their
+ functionality from QAbstractSlider, and can in theory replace
+ each other in an application since the differences only concern
+ their look and feel. This example shows what they look like, how
+ they work and how their behavior and appearance can be
+ manipulated through their properties.
+
+ The example also demonstrates how signals and slots can be used to
+ synchronize the behavior of two or more widgets.
+
+ \image sliders-example.png Screenshot of the Sliders example
+
+ The Sliders example consists of two classes:
+
+ \list
+
+ \li \c SlidersGroup is a custom widget. It combines a QSlider, a
+ QScrollBar and a QDial.
+
+ \li \c Window is the main widget combining a QGroupBox and a
+ QStackedWidget. In this example, the QStackedWidget provides a
+ stack of two \c SlidersGroup widgets. The QGroupBox contain
+ several widgets that control the behavior of the slider-like
+ widgets.
+
+ \endlist
+
+ First we will review the \c Window class, then we
+ will take a look at the \c SlidersGroup class.
+
+ \section1 Window Class Definition
+
+ \snippet widgets/sliders/window.h 0
+
+ The \c Window class inherits from QWidget. It displays the slider
+ widgets and allows the user to set their minimum, maximum and
+ current values and to customize their appearance, key bindings
+ and orientation. We use a private \c createControls() function to
+ create the widgets that provide these controlling mechanisms and
+ to connect them to the slider widgets.
+
+ \section1 Window Class Implementation
+
+ \snippet widgets/sliders/window.cpp 0
+
+ In the constructor we first create the two \c SlidersGroup
+ widgets that display the slider widgets horizontally and
+ vertically, and add them to the QStackedWidget. QStackedWidget
+ provides a stack of widgets where only the top widget is visible.
+ With \c createControls() we create a connection from a
+ controlling widget to the QStackedWidget, making the user able to
+ choose between horizontal and vertical orientation of the slider
+ widgets. The rest of the controlling mechanisms is implemented by
+ the same function call.
+
+ \snippet widgets/sliders/window.cpp 1
+ \snippet widgets/sliders/window.cpp 2
+
+ Then we connect the \c horizontalSliders, \c verticalSliders and
+ \c valueSpinBox to each other, so that the slider widgets and the
+ control widget will behave synchronized when the current value of
+ one of them changes. The \c valueChanged() signal is emitted with
+ the new value as argument. The \c setValue() slot sets the
+ current value of the widget to the new value, and emits \c
+ valueChanged() if the new value is different from the old one.
+
+ We put the group of control widgets and the stacked widget in a
+ horizontal layout before we initialize the minimum, maximum and
+ current values. The initialization of the current value will
+ propagate to the slider widgets through the connection we made
+ between \c valueSpinBox and the \c SlidersGroup widgets. The
+ minimum and maximum values propagate through the connections we
+ created with \c createControls().
+
+ \snippet widgets/sliders/window.cpp 3
+ \snippet widgets/sliders/window.cpp 4
+
+ In the private \c createControls() function, we let a QGroupBox
+ (\c controlsGroup) display the control widgets. A group box can
+ provide a frame, a title and a keyboard shortcut, and displays
+ various other widgets inside itself. The group of control widgets
+ is composed by two checkboxes, three spin boxes (with labels) and
+ one combobox.
+
+ After creating the labels, we create the two checkboxes.
+ Checkboxes are typically used to represent features in an
+ application that can be enabled or disabled. When \c
+ invertedAppearance is enabled, the slider values are inverted.
+ The table below shows the appearance for the different
+ slider-like widgets:
+
+ \table
+ \header \li \li{2,1} QSlider \li{2,1} QScrollBar \li{2,1} QDial
+ \header \li \li Normal \li Inverted \li Normal \li Inverted \li Normal \li Inverted
+ \row \li Qt::Horizontal \li Left to right \li Right to left \li Left to right \li Right to left \li Clockwise \li Counterclockwise
+ \row \li Qt::Vertical \li Bottom to top \li Top to bottom \li Top to bottom \li Bottom to top \li Clockwise \li Counterclockwise
+ \endtable
+
+ It is common to invert the appearance of a vertical QSlider. A
+ vertical slider that controls volume, for example, will typically
+ go from bottom to top (the non-inverted appearance), whereas a
+ vertical slider that controls the position of an object on screen
+ might go from top to bottom, because screen coordinates go from
+ top to bottom.
+
+ When the \c invertedKeyBindings option is enabled (corresponding
+ to the QAbstractSlider::invertedControls property), the slider's
+ wheel and key events are inverted. The normal key bindings mean
+ that scrolling the mouse wheel "up" or using keys like page up
+ will increase the slider's current value towards its maximum.
+ Inverted, the same wheel and key events will move the value
+ toward the slider's minimum. This can be useful if the \e
+ appearance of a slider is inverted: Some users might expect the
+ keys to still work the same way on the value, whereas others
+ might expect \uicontrol PageUp to mean "up" on the screen.
+
+ Note that for horizontal and vertical scroll bars, the key
+ bindings are inverted by default: \uicontrol PageDown increases the
+ current value, and \uicontrol PageUp decreases it.
+
+ \snippet widgets/sliders/window.cpp 5
+ \snippet widgets/sliders/window.cpp 6
+
+ Then we create the spin boxes. QSpinBox allows the user to choose
+ a value by clicking the up and down buttons or pressing the \key
+ Up and \uicontrol Down keys on the keyboard to modify the value
+ currently displayed. The user can also type in the value
+ manually. The spin boxes control the minimum, maximum and current
+ values for the QSlider, QScrollBar, and QDial widgets.
+
+ We create a QComboBox that allows the user to choose the
+ orientation of the slider widgets. The QComboBox widget is a
+ combined button and popup list. It provides a means of presenting
+ a list of options to the user in a way that takes up the minimum
+ amount of screen space.
+
+ \snippet widgets/sliders/window.cpp 7
+ \snippet widgets/sliders/window.cpp 8
+
+ We synchronize the behavior of the control widgets and the slider
+ widgets through their signals and slots. We connect each control
+ widget to both the horizontal and vertical group of slider
+ widgets. We also connect \c orientationCombo to the
+ QStackedWidget, so that the correct "page" is shown. Finally, we
+ lay out the control widgets in a QGridLayout within the \c
+ controlsGroup group box.
+
+ \section1 SlidersGroup Class Definition
+
+ \snippet widgets/sliders/slidersgroup.h 0
+
+ The \c SlidersGroup class inherits from QGroupBox. It provides a
+ frame and a title, and contains a QSlider, a QScrollBar and a
+ QDial.
+
+ We provide a \c valueChanged() signal and a public \c setValue()
+ slot with equivalent functionality to the ones in QAbstractSlider
+ and QSpinBox. In addition, we implement several other public
+ slots to set the minimum and maximum value, and invert the slider
+ widgets' appearance as well as key bindings.
+
+ \section1 SlidersGroup Class Implementation
+
+ \snippet widgets/sliders/slidersgroup.cpp 0
+
+ First we create the slider-like widgets with the appropriate
+ properties. In particular we set the focus policy for each
+ widget. Qt::FocusPolicy is an enum type that defines the various
+ policies a widget can have with respect to acquiring keyboard
+ focus. The Qt::StrongFocus policy means that the widget accepts
+ focus by both tabbing and clicking.
+
+ Then we connect the widgets with each other, so that they will
+ stay synchronized when the current value of one of them changes.
+
+ \snippet widgets/sliders/slidersgroup.cpp 1
+ \snippet widgets/sliders/slidersgroup.cpp 2
+
+ We connect \c {dial}'s \c valueChanged() signal to the
+ \c{SlidersGroup}'s \c valueChanged() signal, to notify the other
+ widgets in the application (i.e., the control widgets) of the
+ changed value.
+
+ \snippet widgets/sliders/slidersgroup.cpp 3
+ \codeline
+ \snippet widgets/sliders/slidersgroup.cpp 4
+
+ Finally, depending on the \l {Qt::Orientation}{orientation} given
+ at the time of construction, we choose and create the layout for
+ the slider widgets within the group box.
+
+ \snippet widgets/sliders/slidersgroup.cpp 5
+ \snippet widgets/sliders/slidersgroup.cpp 6
+
+ The \c setValue() slot sets the value of the QSlider. We don't
+ need to explicitly call
+ \l{QAbstractSlider::setValue()}{setValue()} on the QScrollBar and
+ QDial widgets, since QSlider will emit the
+ \l{QAbstractSlider::valueChanged()}{valueChanged()} signal when
+ its value changes, triggering a domino effect.
+
+ \snippet widgets/sliders/slidersgroup.cpp 7
+ \snippet widgets/sliders/slidersgroup.cpp 8
+ \codeline
+ \snippet widgets/sliders/slidersgroup.cpp 9
+ \snippet widgets/sliders/slidersgroup.cpp 10
+
+ The \c setMinimum() and \c setMaximum() slots are used by the \c
+ Window class to set the range of the QSlider, QScrollBar, and
+ QDial widgets.
+
+ \snippet widgets/sliders/slidersgroup.cpp 11
+ \snippet widgets/sliders/slidersgroup.cpp 12
+ \codeline
+ \snippet widgets/sliders/slidersgroup.cpp 13
+ \snippet widgets/sliders/slidersgroup.cpp 14
+
+ The \c invertAppearance() and \c invertKeyBindings() slots
+ control the child widgets'
+ \l{QAbstractSlider::invertedAppearance}{invertedAppearance} and
+ \l{QAbstractSlider::invertedControls}{invertedControls}
+ properties.
+*/
diff --git a/examples/widgets/doc/spinboxdelegate.qdoc b/examples/widgets/doc/spinboxdelegate.qdoc
new file mode 100644
index 0000000000..95e764dd83
--- /dev/null
+++ b/examples/widgets/doc/spinboxdelegate.qdoc
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/spinboxdelegate
+ \title Spin Box Delegate Example
+
+ The Spin Box Delegate example shows how to create an editor for a custom delegate in
+ the model/view framework by reusing a standard Qt editor widget.
+
+ The model/view framework provides a standard delegate that is used by default
+ with the standard view classes. For most purposes, the selection of editor
+ widgets available through this delegate is sufficient for editing text, boolean
+ values, and other simple data types. However, for specific data types, it is
+ sometimes necessary to use a custom delegate to either display the data in a
+ specific way, or allow the user to edit it with a custom control.
+
+ \image spinboxdelegate-example.png
+
+ This concepts behind this example are covered in the
+ \l{Model/View Programming#Delegate Classes}{Delegate Classes} chapter
+ of the \l{Model/View Programming} overview.
+
+ \section1 SpinBoxDelegate Class Definition
+
+ The definition of the delegate is as follows:
+
+ \snippet itemviews/spinboxdelegate/delegate.h 0
+
+ The delegate class declares only those functions that are needed to
+ create an editor widget, display it at the correct location in a view,
+ and communicate with a model. Custom delegates can also provide their
+ own painting code by reimplementing the \c paintEvent() function.
+ Furthermore it is also possible to reuse (and avoid deleting) the editor
+ widget by reimplementing the \a destroyEditor() function. A reused widget
+ could be a mutable member created in the constructor and deleted in
+ the destructor.
+
+ \section1 SpinBoxDelegate Class Implementation
+
+ Delegates are often stateless. The constructor only needs to
+ call the base class's constructor with the parent QObject as its
+ argument:
+
+ \snippet itemviews/spinboxdelegate/delegate.cpp 0
+
+ Since the delegate is a subclass of QItemDelegate, the data it retrieves
+ from the model is displayed in a default style, and we do not need to
+ provide a custom \c paintEvent().
+
+ The \c createEditor() function returns an editor widget, in this case a
+ spin box that restricts values from the model to integers from 0 to 100
+ inclusive.
+
+ \snippet itemviews/spinboxdelegate/delegate.cpp 1
+
+ We install an event filter on the spin box to ensure that it behaves in
+ a way that is consistent with other delegates. The implementation for
+ the event filter is provided by the base class.
+
+ The \c setEditorData() function reads data from the model, converts it
+ to an integer value, and writes it to the editor widget.
+
+ \snippet itemviews/spinboxdelegate/delegate.cpp 2
+
+ Since the view treats delegates as ordinary QWidget instances, we have
+ to use a static cast before we can set the value in the spin box.
+
+ The \c setModelData() function reads the contents of the spin box, and
+ writes it to the model.
+
+ \snippet itemviews/spinboxdelegate/delegate.cpp 3
+
+ We call \l{QSpinBox::interpretText()}{interpretText()} to make sure that
+ we obtain the most up-to-date value in the spin box.
+
+ The \c updateEditorGeometry() function updates the editor widget's
+ geometry using the information supplied in the style option. This is the
+ minimum that the delegate must do in this case.
+
+ \snippet itemviews/spinboxdelegate/delegate.cpp 4
+
+ More complex editor widgets may divide the rectangle available in
+ \c{option.rect} between different child widgets if required.
+
+ \section1 The Main Function
+
+ This example is written in a slightly different way to many of the
+ other examples supplied with Qt. To demonstrate the use of a custom
+ editor widget in a standard view, it is necessary to set up a model
+ containing some arbitrary data and a view to display it.
+
+ We set up the application in the normal way, construct a standard item
+ model to hold some data, set up a table view to use the data in the
+ model, and construct a custom delegate to use for editing:
+
+ \snippet itemviews/spinboxdelegate/main.cpp 0
+
+ The table view is informed about the delegate, and will use it to
+ display each of the items. Since the delegate is a subclass of
+ QItemDelegate, each cell in the table will be rendered using standard
+ painting operations.
+
+ We insert some arbitrary data into the model for demonstration purposes:
+
+ \snippet itemviews/spinboxdelegate/main.cpp 1
+ \snippet itemviews/spinboxdelegate/main.cpp 2
+
+ Finally, the table view is displayed with a window title, and we start
+ the application's event loop:
+
+ \snippet itemviews/spinboxdelegate/main.cpp 3
+
+ Each of the cells in the table can now be edited in the usual way, but
+ the spin box ensures that the data returned to the model is always
+ constrained by the values allowed by the spin box delegate.
+*/
diff --git a/examples/widgets/doc/spinboxes.qdoc b/examples/widgets/doc/spinboxes.qdoc
new file mode 100644
index 0000000000..ed4eea6a60
--- /dev/null
+++ b/examples/widgets/doc/spinboxes.qdoc
@@ -0,0 +1,191 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/spinboxes
+ \title Spin Boxes Example
+
+ The Spin Boxes example shows how to use the many different types of spin boxes
+ available in Qt, from a simple QSpinBox widget to more complex editors like
+ the QDateTimeEdit widget.
+
+ \image spinboxes-example.png
+
+ The example consists of a single \c Window class that is used to display the
+ different spin box-based widgets available with Qt.
+
+ \section1 Window Class Definition
+
+ The \c Window class inherits QWidget and contains two slots that are used
+ to provide interactive features:
+
+ \snippet widgets/spinboxes/window.h 0
+
+ The private functions are used to set up each type of spin box in the window.
+ We use member variables to keep track of various widgets so that they can
+ be reconfigured when required.
+
+ \section1 Window Class Implementation
+
+ The constructor simply calls private functions to set up the different types
+ of spin box used in the example, and places each group in a layout:
+
+ \snippet widgets/spinboxes/window.cpp 0
+
+ We use the layout to manage the arrangement of the window's child widgets,
+ and change the window title.
+
+ The \c createSpinBoxes() function constructs a QGroupBox and places three
+ QSpinBox widgets inside it with descriptive labels to indicate the types of
+ input they expect.
+
+ \snippet widgets/spinboxes/window.cpp 1
+
+ The first spin box shows the simplest way to use QSpinBox. It accepts values
+ from -20 to 20, the current value can be increased or decreased by 1 with
+ either the arrow buttons or \uicontrol{Up} and \uicontrol{Down} keys, and the default
+ value is 0.
+
+ The second spin box uses a larger step size and displays a suffix to
+ provide more information about the type of data the number represents:
+
+ \snippet widgets/spinboxes/window.cpp 2
+
+ This spin box also displays a
+ \l{QAbstractSpinBox::specialValueText}{special value} instead of the minimum
+ value defined for it. This means that it will never show \uicontrol{0%}, but will
+ display \uicontrol{Automatic} when the minimum value is selected.
+
+ The third spin box shows how a prefix can be used:
+
+ \snippet widgets/spinboxes/window.cpp 4
+
+ For simplicity, we show a spin box with a prefix and no suffix. It is also
+ possible to use both at the same time.
+
+ \snippet widgets/spinboxes/window.cpp 5
+
+ The rest of the function sets up a layout for the group box and places each
+ of the widgets inside it.
+
+ The \c createDateTimeEdits() function constructs another group box with a
+ selection of spin boxes used for editing dates and times.
+
+ \snippet widgets/spinboxes/window.cpp 6
+
+ The first spin box is a QDateEdit widget that is able to accept dates
+ within a given range specified using QDate values. The arrow buttons and
+ \uicontrol{Up} and \uicontrol{Down} keys can be used to increase and decrease the
+ values for year, month, and day when the cursor is in the relevant section.
+
+ The second spin box is a QTimeEdit widget:
+
+ \snippet widgets/spinboxes/window.cpp 7
+
+ Acceptable values for the time are defined using QTime values.
+
+ The third spin box is a QDateTimeEdit widget that can display both date and
+ time values, and we place a label above it to indicate the range of allowed
+ times for a meeting. These widgets will be updated when the user changes a
+ format string.
+
+ \snippet widgets/spinboxes/window.cpp 8
+
+ The format string used for the date time editor, which is also shown in the
+ string displayed by the label, is chosen from a set of strings in a combobox:
+
+ \snippet widgets/spinboxes/window.cpp 9
+ \codeline
+ \snippet widgets/spinboxes/window.cpp 10
+
+ A signal from this combobox is connected to a slot in the \c Window class
+ (shown later).
+
+ \snippet widgets/spinboxes/window.cpp 11
+
+ Each child widget of the group box in placed in a layout.
+
+ The \c setFormatString() slot is called whenever the user selects a new
+ format string in the combobox. The display format for the QDateTimeEdit
+ widget is set using the raw string passed by the signal:
+
+ \snippet widgets/spinboxes/window.cpp 12
+
+ Depending on the visible sections in the widget, we set a new date or time
+ range, and update the associated label to provide relevant information for
+ the user:
+
+ \snippet widgets/spinboxes/window.cpp 13
+
+ When the format string is changed, there will be an appropriate label and
+ entry widget for dates, times, or both types of input.
+
+ The \c createDoubleSpinBoxes() function constructs three spin boxes that are
+ used to input double-precision floating point numbers:
+
+ \snippet widgets/spinboxes/window.cpp 14
+
+ Before the QDoubleSpinBox widgets are constructed, we create a spin box to
+ control how many decimal places they show. By default, only two decimal places
+ are shown in the following spin boxes, each of which is the equivalent of a
+ spin box in the group created by the \c createSpinBoxes() function.
+
+ The first double spin box shows a basic double-precision spin box with the
+ same range, step size, and default value as the first spin box in the
+ \c createSpinBoxes() function:
+
+ \snippet widgets/spinboxes/window.cpp 15
+
+ However, this spin box also allows non-integer values to be entered.
+
+ The second spin box displays a suffix and shows a special value instead
+ of the minimum value:
+
+ \snippet widgets/spinboxes/window.cpp 16
+
+ The third spin box displays a prefix instead of a suffix:
+
+ \snippet widgets/spinboxes/window.cpp 17
+
+ We connect the QSpinBox widget that specifies the precision to a slot in
+ the \c Window class.
+
+ \snippet widgets/spinboxes/window.cpp 18
+
+ The rest of the function places each of the widgets into a layout for the
+ group box.
+
+ The \c changePrecision() slot is called when the user changes the value in
+ the precision spin box:
+
+ \snippet widgets/spinboxes/window.cpp 19
+
+ This function simply uses the integer supplied by the signal to specify the
+ number of decimal places in each of the QDoubleSpinBox widgets. Each one
+ of these will be updated automatically when their
+ \l{QDoubleSpinBox::decimals}{decimals} property is changed.
+*/
diff --git a/examples/widgets/doc/spreadsheet.qdoc b/examples/widgets/doc/spreadsheet.qdoc
new file mode 100644
index 0000000000..7364f022cb
--- /dev/null
+++ b/examples/widgets/doc/spreadsheet.qdoc
@@ -0,0 +1,37 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/spreadsheet
+ \title Spreadsheet
+
+ The Spreadsheet example shows how a table view can be used to create a
+ simple spreadsheet application. Custom delegates are used to render different
+ types of data in distinctive colors.
+
+ \image spreadsheet-demo.png
+*/
diff --git a/examples/widgets/doc/standarddialogs.qdoc b/examples/widgets/doc/standarddialogs.qdoc
new file mode 100644
index 0000000000..b56642b6ec
--- /dev/null
+++ b/examples/widgets/doc/standarddialogs.qdoc
@@ -0,0 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example dialogs/standarddialogs
+ \title Standard Dialogs Example
+
+ The Standard Dialogs example shows the standard dialogs that are provided by Qt.
+
+ \image standarddialogs-example.png
+*/
diff --git a/examples/widgets/doc/stardelegate.qdoc b/examples/widgets/doc/stardelegate.qdoc
new file mode 100644
index 0000000000..aba8864c2b
--- /dev/null
+++ b/examples/widgets/doc/stardelegate.qdoc
@@ -0,0 +1,296 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example itemviews/stardelegate
+ \title Star Delegate Example
+
+ The Star Delegate example shows how to create a delegate that
+ can paint itself and that supports editing.
+
+ \image stardelegate.png The Star Delegate Example
+
+ When displaying data in a QListView, QTableView, or QTreeView,
+ the individual items are drawn by a
+ \l{Delegate Classes}{delegate}. Also, when the user starts
+ editing an item (e.g., by double-clicking the item), the delegate
+ provides an editor widget that is placed on top of the item while
+ editing takes place.
+
+ Delegates are subclasses of QAbstractItemDelegate. Qt provides
+ QItemDelegate, which inherits QAbstractItemDelegate and handles
+ the most common data types (notably \c int and QString). If we
+ need to support custom data types, or want to customize the
+ rendering or the editing for existing data types, we can subclass
+ QAbstractItemDelegate or QItemDelegate. See \l{Delegate Classes}
+ for more information about delegates, and \l{Model/View
+ Programming} if you need a high-level introduction to Qt's
+ model/view architecture (including delegates).
+
+ In this example, we will see how to implement a custom delegate
+ to render and edit a "star rating" data type, which can store
+ values such as "1 out of 5 stars".
+
+ The example consists of the following classes:
+
+ \list
+ \li \c StarRating is the custom data type. It stores a rating
+ expressed as stars, such as "2 out of 5 stars" or "5 out of
+ 6 stars".
+
+ \li \c StarDelegate inherits QItemDelegate and provides support
+ for \c StarRating (in addition to the data types already
+ handled by QItemDelegate).
+
+ \li \c StarEditor inherits QWidget and is used by \c StarDelegate
+ to let the user edit a star rating using the mouse.
+ \endlist
+
+ To show the \c StarDelegate in action, we will fill a
+ QTableWidget with some data and install the delegate on it.
+
+ \section1 StarDelegate Class Definition
+
+ Here's the definition of the \c StarDelegate class:
+
+ \snippet itemviews/stardelegate/stardelegate.h 0
+
+ All public functions are reimplemented virtual functions from
+ QItemDelegate to provide custom rendering and editing.
+
+ \section1 StarDelegate Class Implementation
+
+ The \l{QAbstractItemDelegate::}{paint()} function is
+ reimplemented from QItemDelegate and is called whenever the view
+ needs to repaint an item:
+
+ \snippet itemviews/stardelegate/stardelegate.cpp 0
+
+ The function is invoked once for each item, represented by a
+ QModelIndex object from the model. If the data stored in the item
+ is a \c StarRating, we paint it ourselves; otherwise, we let
+ QItemDelegate paint it for us. This ensures that the \c
+ StarDelegate can handle the most common data types.
+
+ In the case where the item is a \c StarRating, we draw the
+ background if the item is selected, and we draw the item using \c
+ StarRating::paint(), which we will review later.
+
+ \c{StartRating}s can be stored in a QVariant thanks to the
+ Q_DECLARE_METATYPE() macro appearing in \c starrating.h. More on
+ this later.
+
+ The \l{QAbstractItemDelegate::}{createEditor()} function is
+ called when the user starts editing an item:
+
+ \snippet itemviews/stardelegate/stardelegate.cpp 2
+
+ If the item is a \c StarRating, we create a \c StarEditor and
+ connect its \c editingFinished() signal to our \c
+ commitAndCloseEditor() slot, so we can update the model when the
+ editor closes.
+
+ Here's the implementation of \c commitAndCloseEditor():
+
+ \snippet itemviews/stardelegate/stardelegate.cpp 5
+
+ When the user is done editing, we emit
+ \l{QAbstractItemDelegate::}{commitData()} and
+ \l{QAbstractItemDelegate::}{closeEditor()} (both declared in
+ QAbstractItemDelegate), to tell the model that there is edited
+ data and to inform the view that the editor is no longer needed.
+
+ The \l{QAbstractItemDelegate::}{setEditorData()} function is
+ called when an editor is created to initialize it with data
+ from the model:
+
+ \snippet itemviews/stardelegate/stardelegate.cpp 3
+
+ We simply call \c setStarRating() on the editor.
+
+ The \l{QAbstractItemDelegate::}{setModelData()} function is
+ called when editing is finished, to commit data from the editor
+ to the model:
+
+ \snippet itemviews/stardelegate/stardelegate.cpp 4
+
+ The \c sizeHint() function returns an item's preferred size:
+
+ \snippet itemviews/stardelegate/stardelegate.cpp 1
+
+ We simply forward the call to \c StarRating.
+
+ \section1 StarEditor Class Definition
+
+ The \c StarEditor class was used when implementing \c
+ StarDelegate. Here's the class definition:
+
+ \snippet itemviews/stardelegate/stareditor.h 0
+
+ The class lets the user edit a \c StarRating by moving the mouse
+ over the editor. It emits the \c editingFinished() signal when
+ the user clicks on the editor.
+
+ The protected functions are reimplemented from QWidget to handle
+ mouse and paint events. The private function \c starAtPosition()
+ is a helper function that returns the number of the star under
+ the mouse pointer.
+
+ \section1 StarEditor Class Implementation
+
+ Let's start with the constructor:
+
+ \snippet itemviews/stardelegate/stareditor.cpp 0
+
+ We enable \l{QWidget::setMouseTracking()}{mouse tracking} on the
+ widget so we can follow the cursor even when the user doesn't
+ hold down any mouse button. We also turn on QWidget's
+ \l{QWidget::autoFillBackground}{auto-fill background} feature to
+ obtain an opaque background. (Without the call, the view's
+ background would shine through the editor.)
+
+ The \l{QWidget::}{paintEvent()} function is reimplemented from
+ QWidget:
+
+ \snippet itemviews/stardelegate/stareditor.cpp 1
+
+ We simply call \c StarRating::paint() to draw the stars, just
+ like we did when implementing \c StarDelegate.
+
+ \snippet itemviews/stardelegate/stareditor.cpp 2
+
+ In the mouse event handler, we call \c setStarCount() on the
+ private data member \c myStarRating to reflect the current cursor
+ position, and we call QWidget::update() to force a repaint.
+
+ \snippet itemviews/stardelegate/stareditor.cpp 3
+
+ When the user releases a mouse button, we simply emit the \c
+ editingFinished() signal.
+
+ \snippet itemviews/stardelegate/stareditor.cpp 4
+
+ The \c starAtPosition() function uses basic linear algebra to
+ find out which star is under the cursor.
+
+ \section1 StarRating Class Definition
+
+ \snippet itemviews/stardelegate/starrating.h 0
+ \codeline
+ \snippet itemviews/stardelegate/starrating.h 1
+
+ The \c StarRating class represents a rating as a number of stars.
+ In addition to holding the data, it is also capable of painting
+ the stars on a QPaintDevice, which in this example is either a
+ view or an editor. The \c myStarCount member variable stores the
+ current rating, and \c myMaxStarCount stores the highest possible
+ rating (typically 5).
+
+ The Q_DECLARE_METATYPE() macro makes the type \c StarRating known
+ to QVariant, making it possible to store \c StarRating values in
+ QVariant.
+
+ \section1 StarRating Class Implementation
+
+ The constructor initializes \c myStarCount and \c myMaxStarCount,
+ and sets up the polygons used to draw stars and diamonds:
+
+ \snippet itemviews/stardelegate/starrating.cpp 0
+
+ The \c paint() function paints the stars in this \c StarRating
+ object on a paint device:
+
+ \snippet itemviews/stardelegate/starrating.cpp 2
+
+ We first set the pen and brush we will use for painting. The \c
+ mode parameter can be either \c Editable or \c ReadOnly. If \c
+ mode is editable, we use the \l{QPalette::}{Highlight} color
+ instead of the \l{QPalette::}{Foreground} color to draw the
+ stars.
+
+ Then we draw the stars. If we are in \c Edit mode, we paint
+ diamonds in place of stars if the rating is less than the highest
+ rating.
+
+ The \c sizeHint() function returns the preferred size for an area
+ to paint the stars on:
+
+ \snippet itemviews/stardelegate/starrating.cpp 1
+
+ The preferred size is just enough to paint the maximum number of
+ stars. The function is called by both \c StarDelegate::sizeHint()
+ and \c StarEditor::sizeHint().
+
+ \section1 The \c main() Function
+
+ Here's the program's \c main() function:
+
+ \snippet itemviews/stardelegate/main.cpp 5
+
+ The \c main() function creates a QTableWidget and sets a \c
+ StarDelegate on it. \l{QAbstractItemView::}{DoubleClicked} and
+ \l{QAbstractItemView::}{SelectedClicked} are set as
+ \l{QAbstractItemView::editTriggers()}{edit triggers}, so that the
+ editor is opened with a single click when the star rating item is
+ selected.
+
+ The \c populateTableWidget() function fills the QTableWidget with
+ data:
+
+ \snippet itemviews/stardelegate/main.cpp 0
+ \snippet itemviews/stardelegate/main.cpp 1
+ \dots
+ \snippet itemviews/stardelegate/main.cpp 2
+ \snippet itemviews/stardelegate/main.cpp 3
+ \codeline
+ \snippet itemviews/stardelegate/main.cpp 4
+
+ Notice the call to qVariantFromValue to convert a \c
+ StarRating to a QVariant.
+
+ \section1 Possible Extensions and Suggestions
+
+ There are many ways to customize Qt's \l{Model/View
+ Programming}{model/view framework}. The approach used in this
+ example is appropriate for most custom delegates and editors.
+ Examples of possibilities not used by the star delegate and star
+ editor are:
+
+ \list
+ \li It is possible to open editors programmatically by calling
+ QAbstractItemView::edit(), instead of relying on edit
+ triggers. This could be use to support other edit triggers
+ than those offered by the QAbstractItemView::EditTrigger enum.
+ For example, in the Star Delegate example, hovering over an
+ item with the mouse might make sense as a way to pop up an
+ editor.
+
+ \li By reimplementing QAbstractItemDelegate::editorEvent(), it is
+ possible to implement the editor directly in the delegate,
+ instead of creating a separate QWidget subclass.
+ \endlist
+*/
diff --git a/examples/widgets/doc/states.qdoc b/examples/widgets/doc/states.qdoc
new file mode 100644
index 0000000000..52eda087f1
--- /dev/null
+++ b/examples/widgets/doc/states.qdoc
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example animation/states
+ \title States Example
+
+ The States example shows how to use the Qt state machine to play
+ animations.
+
+ \image states-example.png
+*/
diff --git a/examples/widgets/doc/stickman.qdoc b/examples/widgets/doc/stickman.qdoc
new file mode 100644
index 0000000000..cffdb64822
--- /dev/null
+++ b/examples/widgets/doc/stickman.qdoc
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \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 propertiesAssigned() 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 animation/stickman/lifecycle.cpp 1
+
+ The states are then bound together with signal transitions that listen to the
+ propertiesAssigned() signal.
+
+ \snippet 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 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 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 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 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/examples/widgets/doc/styles.qdoc b/examples/widgets/doc/styles.qdoc
new file mode 100644
index 0000000000..f8be98d2da
--- /dev/null
+++ b/examples/widgets/doc/styles.qdoc
@@ -0,0 +1,472 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/styles
+ \title Styles Example
+
+ The Styles example illustrates how to create custom widget
+ drawing styles using Qt, and demonstrates Qt's predefined styles.
+
+ \image styles-enabledwood.png Screenshot of the Styles example
+
+ A style in Qt is a subclass of QStyle or of one of its
+ subclasses. Styles perform drawing on behalf of widgets. Qt
+ provides a whole range of predefined styles, either built into
+ the \l QtGui library or found in plugins. Custom styles are
+ usually created by subclassing one of Qt's existing style and
+ reimplementing a few virtual functions.
+
+ In this example, the custom style is called \c NorwegianWoodStyle
+ and derives from QMotifStyle. Its main features are the wooden
+ textures used for filling most of the widgets and its round
+ buttons and comboboxes.
+
+ To implement the style, we use some advanced features provided by
+ QPainter, such as \l{QPainter::Antialiasing}{antialiasing} (to
+ obtain smoother button edges), \l{QColor::alpha()}{alpha blending}
+ (to make the buttons appeared raised or sunken), and
+ \l{QPainterPath}{painter paths} (to fill the buttons and draw the
+ outline). We also use many features of QBrush and QPalette.
+
+ The example consists of the following classes:
+
+ \list
+ \li \c NorwegianWoodStyle inherits from QMotifStyle and implements
+ the Norwegian Wood style.
+ \li \c WidgetGallery is a \c QDialog subclass that shows the most
+ common widgets and allows the user to switch style
+ dynamically.
+ \endlist
+
+ \section1 NorwegianWoodStyle Class Definition
+
+ Here's the definition of the \c NorwegianWoodStyle class:
+
+ \snippet widgets/styles/norwegianwoodstyle.h 0
+
+ The public functions are all declared in QStyle (QMotifStyle's
+ grandparent class) and reimplemented here to override the Motif
+ look and feel. The private functions are helper functions.
+
+ \section1 NorwegianWoodStyle Class Implementation
+
+ We will now review the implementation of the \c
+ NorwegianWoodStyle class.
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 0
+
+ The \c polish() function is reimplemented from QStyle. It takes a
+ QPalette as a reference and adapts the palette to fit the style.
+ Most styles don't need to reimplement that function. The
+ Norwegian Wood style reimplements it to set a "wooden" palette.
+
+ We start by defining a few \l{QColor}s that we'll need. Then we
+ load two PNG images. The \c : prefix in the file path indicates
+ that the PNG files are \l{The Qt Resource System}{embedded
+ resources}.
+
+ \table
+ \row \li \inlineimage widgets/styles/images/woodbackground.png
+
+ \li \b{woodbackground.png}
+
+ This texture is used as the background of most widgets.
+ The wood pattern is horizontal.
+
+ \row \li \inlineimage widgets/styles/images/woodbutton.png
+
+ \li \b{woodbutton.png}
+
+ This texture is used for filling push buttons and
+ comboboxes. The wood pattern is vertical and more reddish
+ than the texture used for the background.
+ \endtable
+
+ The \c midImage variable is initialized to be the same as \c
+ buttonImage, but then we use a QPainter and fill it with a 25%
+ opaque black color (a black with an \l{QColor::alpha()}{alpha
+ channel} of 63). The result is a somewhat darker image than \c
+ buttonImage. This image will be used for filling buttons that the
+ user is holding down.
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 1
+
+ We initialize the palette. Palettes have various
+ \l{QPalette::ColorRole}{color roles}, such as QPalette::Base
+ (used for filling text editors, item views, etc.), QPalette::Text
+ (used for foreground text), and QPalette::Background (used for
+ the background of most widgets). Each role has its own QBrush,
+ which usually is a plain color but can also be a brush pattern or
+ even a texture (a QPixmap).
+
+ In addition to the roles, palettes have several
+ \l{QPalette::ColorGroup}{color groups}: active, disabled, and
+ inactive. The active color group is used for painting widgets in
+ the active window. The disabled group is used for disabled
+ widgets. The inactive group is used for all other widgets. Most
+ palettes have identical active and inactive groups, while the
+ disabled group uses darker shades.
+
+ We initialize the QPalette object with a brown color. Qt
+ automatically derivates all color roles for all color groups from
+ that single color. We then override some of the default values. For
+ example, we use Qt::darkGreen instead of the default
+ (Qt::darkBlue) for the QPalette::Highlight role. The
+ QPalette::setBrush() overload that we use here sets the same
+ color or brush for all three color groups.
+
+ The \c setTexture() function is a private function that sets the
+ texture for a certain color role, while preserving the existing
+ color in the QBrush. A QBrush can hold both a solid color and a
+ texture at the same time. The solid color is used for drawing
+ text and other graphical elements where textures don't look good.
+
+ At the end, we set the brush for the disabled color group of the
+ palette. We use \c woodbackground.png as the texture for all
+ disabled widgets, including buttons, and use a darker color to
+ accompany the texture.
+
+ \image styles-disabledwood.png The Norwegian Wood style with disabled widgets
+
+ Let's move on to the other functions reimplemented from
+ QMotifStyle:
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 3
+ \snippet widgets/styles/norwegianwoodstyle.cpp 4
+
+ This QStyle::polish() overload is called once on every widget
+ drawn using the style. We reimplement it to set the Qt::WA_Hover
+ attribute on \l{QPushButton}s and \l{QComboBox}es. When this
+ attribute is set, Qt generates paint events when the mouse
+ pointer enters or leaves the widget. This makes it possible to
+ render push buttons and comboboxes differently when the mouse
+ pointer is over them.
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 5
+ \snippet widgets/styles/norwegianwoodstyle.cpp 6
+
+ This QStyle::unpolish() overload is called to undo any
+ modification done to the widget in \c polish(). For simplicity,
+ we assume that the flag wasn't set before \c polish() was called.
+ In an ideal world, we would remember the original state for each
+ widgets (e.g., using a QMap<QWidget *, bool>) and restore it in
+ \c unpolish().
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 7
+ \snippet widgets/styles/norwegianwoodstyle.cpp 8
+
+ The \l{QStyle::pixelMetric()}{pixelMetric()} function returns the
+ size in pixels for a certain user interface element. By
+ reimplementing this function, we can affect the way certain
+ widgets are drawn and their size hint. Here, we return 8 as the
+ width around a shown in a QComboBox, ensuring that there is
+ enough place around the text and the arrow for the Norwegian Wood
+ round corners. The default value for this setting in the Motif
+ style is 2.
+
+ We also change the extent of \l{QScrollBar}s, i.e., the height
+ for a horizontal scroll bar and the width for a vertical scroll
+ bar, to be 4 pixels more than in the Motif style. This makes the
+ style a bit more distinctive.
+
+ For all other QStyle::PixelMetric elements, we use the Motif
+ settings.
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 9
+ \snippet widgets/styles/norwegianwoodstyle.cpp 10
+
+ The \l{QStyle::styleHint()}{styleHint()} function returns some
+ hints to widgets or to the base style (in our case QMotifStyle)
+ about how to draw the widgets. The Motif style returns \c true
+ for the QStyle::SH_DitherDisabledText hint, resulting in a most
+ unpleasing visual effect. We override this behavior and return \c
+ false instead. We also return \c true for the
+ QStyle::SH_EtchDisabledText hint, meaning that disabled text is
+ rendered with an embossed look (as QWindowsStyle does).
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 11
+ \snippet widgets/styles/norwegianwoodstyle.cpp 12
+
+ The \l{QStyle::drawPrimitive()}{drawPrimitive()} function is
+ called by Qt widgets to draw various fundamental graphical
+ elements. Here we reimplement it to draw QPushButton and
+ QComboBox with round corners. The button part of these widgets is
+ drawn using the QStyle::PE_PanelButtonCommand primitive element.
+
+ The \c option parameter, of type QStyleOption, contains
+ everything we need to know about the widget we want to draw on.
+ In particular, \c option->rect gives the rectangle within which
+ to draw the primitive element. The \c painter parameter is a
+ QPainter object that we can use to draw on the widget.
+
+ The \c widget parameter is the widget itself. Normally, all the
+ information we need is available in \c option and \c painter, so
+ we don't need \c widget. We can use it to perform special
+ effects; for example, QMacStyle uses it to animate default
+ buttons. If you use it, be aware that the caller is allowed to
+ pass a null pointer.
+
+ We start by defining three \l{QColor}s that we'll need later on.
+ We also put the x, y, width, and height components of the
+ widget's rectangle in local variables. The value used for the \c
+ semiTransparentWhite and for the \c semiTransparentBlack color's
+ alpha channel depends on whether the mouse cursor is over the
+ widget or not. Since we set the Qt::WA_Hover attribute on
+ \l{QPushButton}s and \l{QComboBox}es, we can rely on the
+ QStyle::State_MouseOver flag to be set when the mouse is over the
+ widget.
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 13
+ \snippet widgets/styles/norwegianwoodstyle.cpp 14
+
+ The \c roundRect variable is a QPainterPath. A QPainterPath is is
+ a vectorial specification of a shape. Any shape (rectangle,
+ ellipse, spline, etc.) or combination of shapes can be expressed
+ as a path. We will use \c roundRect both for filling the button
+ background with a wooden texture and for drawing the outline. The
+ \c roundRectPath() function is a private function; we will come
+ back to it later.
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 15
+ \snippet widgets/styles/norwegianwoodstyle.cpp 16
+ \snippet widgets/styles/norwegianwoodstyle.cpp 17
+ \snippet widgets/styles/norwegianwoodstyle.cpp 18
+
+ We define two variables, \c brush and \c darker, and initialize
+ them based on the state of the button:
+
+ \list
+ \li If the button is a \l{QPushButton::flat}{flat button}, we use
+ the \l{QPalette::Background}{Background} brush. We set \c
+ darker to \c true if the button is
+ \l{QAbstractButton::down}{down} or
+ \l{QAbstractButton::checked}{checked}.
+ \li If the button is currently held down by the user or in the
+ \l{QAbstractButton::checked}{checked} state, we use the
+ \l{QPalette::Mid}{Mid} component of the palette. We set
+ \c darker to \c true if the button is
+ \l{QAbstractButton::checked}{checked}.
+ \li Otherwise, we use the \l{QPalette::Button}{Button} component
+ of the palette.
+ \endlist
+
+ The screenshot below illustrates how \l{QPushButton}s are
+ rendered based on their state:
+
+ \image styles-woodbuttons.png Norwegian Wood buttons in different states
+
+ To discover whether the button is flat or not, we need to cast
+ the \c option parameter to QStyleOptionButton and check if the
+ \l{QStyleOptionButton::features}{features} member specifies the
+ QStyleOptionButton::Flat flag. The qstyleoption_cast() function
+ performs a dynamic cast; if \c option is not a
+ QStyleOptionButton, qstyleoption_cast() returns a null pointer.
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 19
+ \snippet widgets/styles/norwegianwoodstyle.cpp 20
+ \snippet widgets/styles/norwegianwoodstyle.cpp 21
+ \snippet widgets/styles/norwegianwoodstyle.cpp 22
+ \snippet widgets/styles/norwegianwoodstyle.cpp 23
+
+ We turn on antialiasing on QPainter. Antialiasing is a technique
+ that reduces the visual distortion that occurs when the edges of
+ a shape are converted into pixels. For the Norwegian Wood style,
+ we use it to obtain smoother edges for the round buttons.
+
+ \image styles-aliasing.png Norwegian wood buttons with and without antialiasing
+
+ The first call to QPainter::fillPath() draws the background of
+ the button with a wooden texture. The second call to
+ \l{QPainter::fillPath()}{fillPath()} paints the same area with a
+ semi-transparent black color (a black color with an alpha channel
+ of 63) to make the area darker if \c darker is true.
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 24
+ \snippet widgets/styles/norwegianwoodstyle.cpp 25
+
+ Next, we draw the outline. The top-left half of the outline and
+ the bottom-right half of the outline are drawn using different
+ \l{QPen}s to produce a 3D effect. Normally, the top-left half of
+ the outline is drawn lighter whereas the bottom-right half is
+ drawn darker, but if the button is
+ \l{QAbstractButton::down}{down} or
+ \l{QAbstractButton::checked}{checked}, we invert the two
+ \l{QPen}s to give a sunken look to the button.
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 26
+
+ We draw the top-left part of the outline by calling
+ QPainter::drawPath() with an appropriate
+ \l{QPainter::setClipRegion()}{clip region}. If the
+ \l{QStyleOption::direction}{layout direction} is right-to-left
+ instead of left-to-right, we swap the \c x1, \c x2, \c x3, and \c
+ x4 variables to obtain correct results. On right-to-left desktop,
+ the "light" comes from the top-right corner of the screen instead
+ of the top-left corner; raised and sunken widgets must be drawn
+ accordingly.
+
+ The diagram below illustrates how 3D effects are drawn according
+ to the layout direction. The area in red on the diagram
+ corresponds to the \c topHalf polygon:
+
+ \image styles-3d.png
+
+ An easy way to test how a style looks in right-to-left mode is to
+ pass the \c -reverse command-line option to the application. This
+ option is recognized by the QApplication constructor.
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 32
+ \snippet widgets/styles/norwegianwoodstyle.cpp 33
+ \snippet widgets/styles/norwegianwoodstyle.cpp 34
+
+ The bottom-right part of the outline is drawn in a similar
+ fashion. Then we draw a one-pixel wide outline around the entire
+ button, using the \l{QPalette::Foreground}{Foreground} component
+ of the QPalette.
+
+ This completes the QStyle::PE_PanelButtonCommand case of the \c
+ switch statement. Other primitive elements are handled by the
+ base style. Let's now turn to the other \c NorwegianWoodStyle
+ member functions:
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 35
+ \snippet widgets/styles/norwegianwoodstyle.cpp 36
+
+ We reimplement QStyle::drawControl() to draw the text on a
+ QPushButton in a bright color when the button is
+ \l{QAbstractButton::down}{down} or
+ \l{QAbstractButton::checked}{checked}.
+
+ If the \c option parameter points to a QStyleOptionButton object
+ (it normally should), we take a copy of the object and modify its
+ \l{QStyleOption::palette}{palette} member to make the
+ QPalette::ButtonText be the same as the QPalette::BrightText
+ component (unless the widget is disabled).
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 37
+ \snippet widgets/styles/norwegianwoodstyle.cpp 38
+
+ The \c setTexture() function is a private function that sets the
+ \l{QBrush::texture()}{texture} component of the \l{QBrush}es for
+ a certain \l{QPalette::ColorRole}{color role}, for all three
+ \l{QPalette::ColorGroup}{color groups} (active, disabled,
+ inactive). We used it to initialize the Norwegian Wood palette in
+ \c polish(QPalette &).
+
+ \snippet widgets/styles/norwegianwoodstyle.cpp 39
+ \snippet widgets/styles/norwegianwoodstyle.cpp 40
+
+ The \c roundRectPath() function is a private function that
+ constructs a QPainterPath object for round buttons. The path
+ consists of eight segments: four arc segments for the corners and
+ four lines for the sides.
+
+ With around 250 lines of code, we have a fully functional custom
+ style based on one of the predefined styles. Custom styles can be
+ used to provide a distinct look to an application or family of
+ applications.
+
+ \section1 WidgetGallery Class
+
+ For completeness, we will quickly review the \c WidgetGallery
+ class, which contains the most common Qt widgets and allows the
+ user to change style dynamically. Here's the class definition:
+
+ \snippet widgets/styles/widgetgallery.h 0
+ \dots
+ \snippet widgets/styles/widgetgallery.h 1
+
+ Here's the \c WidgetGallery constructor:
+
+ \snippet widgets/styles/widgetgallery.cpp 0
+
+ We start by creating child widgets. The \uicontrol Style combobox is
+ initialized with all the styles known to QStyleFactory, in
+ addition to \c NorwegianWood. The \c create...() functions are
+ private functions that set up the various parts of the \c
+ WidgetGallery.
+
+ \snippet widgets/styles/widgetgallery.cpp 1
+ \snippet widgets/styles/widgetgallery.cpp 2
+
+ We connect the \uicontrol Style combobox to the \c changeStyle()
+ private slot, the \uicontrol{Use style's standard palette} check box to
+ the \c changePalette() slot, and the \uicontrol{Disable widgets} check
+ box to the child widgets'
+ \l{QWidget::setDisabled()}{setDisabled()} slot.
+
+ \snippet widgets/styles/widgetgallery.cpp 3
+ \snippet widgets/styles/widgetgallery.cpp 4
+
+ Finally, we put the child widgets in layouts.
+
+ \snippet widgets/styles/widgetgallery.cpp 5
+ \snippet widgets/styles/widgetgallery.cpp 6
+
+ When the user changes the style in the combobox, we call
+ QApplication::setStyle() to dynamically change the style of the
+ application.
+
+ \snippet widgets/styles/widgetgallery.cpp 7
+ \snippet widgets/styles/widgetgallery.cpp 8
+
+ If the user turns the \uicontrol{Use style's standard palette} on, the
+ current style's \l{QStyle::standardPalette()}{standard palette}
+ is used; otherwise, the system's default palette is honored.
+
+ For the Norwegian Wood style, this makes no difference because we
+ always override the palette with our own palette in \c
+ NorwegianWoodStyle::polish().
+
+ \snippet widgets/styles/widgetgallery.cpp 9
+ \snippet widgets/styles/widgetgallery.cpp 10
+
+ The \c advanceProgressBar() slot is called at regular intervals
+ to advance the progress bar. Since we don't know how long the
+ user will keep the Styles application running, we use a
+ logarithmic formula: The closer the progress bar gets to 100%,
+ the slower it advances.
+
+ We will review \c createProgressBar() in a moment.
+
+ \snippet widgets/styles/widgetgallery.cpp 11
+ \snippet widgets/styles/widgetgallery.cpp 12
+
+ The \c createTopLeftGroupBox() function creates the QGroupBox
+ that occupies the top-left corner of the \c WidgetGallery. We
+ skip the \c createTopRightGroupBox(), \c
+ createBottomLeftTabWidget(), and \c createBottomRightGroupBox()
+ functions, which are very similar.
+
+ \snippet widgets/styles/widgetgallery.cpp 13
+
+ In \c createProgressBar(), we create a QProgressBar at the bottom
+ of the \c WidgetGallery and connect its
+ \l{QTimer::timeout()}{timeout()} signal to the \c
+ advanceProgressBar() slot.
+*/
diff --git a/examples/widgets/doc/stylesheet.qdoc b/examples/widgets/doc/stylesheet.qdoc
new file mode 100644
index 0000000000..af45411f8c
--- /dev/null
+++ b/examples/widgets/doc/stylesheet.qdoc
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/stylesheet
+ \title Style Sheet Example
+
+ The Style Sheet Example shows how to use style sheets.
+
+ \image stylesheet-pagefold.png Screen Shot of the Pagefold style sheet
+*/
+
diff --git a/examples/widgets/doc/sub-attaq.qdoc b/examples/widgets/doc/sub-attaq.qdoc
new file mode 100644
index 0000000000..ae00eb0926
--- /dev/null
+++ b/examples/widgets/doc/sub-attaq.qdoc
@@ -0,0 +1,40 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example animation/sub-attaq
+ \title Sub-Attaq
+
+ This example shows Qt's ability to combine \l{The Animation Framework}{the animation framework}
+ and \l{The State Machine Framework}{the state machine framework} to create a game.
+
+ \image sub-attaq-demo.png
+
+ The purpose of the game is to destroy all submarines to win the current level.
+ The boat can be controlled using left and right keys. To fire a bomb you can press
+ up and down keys.
+*/
diff --git a/examples/widgets/doc/syntaxhighlighter.qdoc b/examples/widgets/doc/syntaxhighlighter.qdoc
new file mode 100644
index 0000000000..272152a3a1
--- /dev/null
+++ b/examples/widgets/doc/syntaxhighlighter.qdoc
@@ -0,0 +1,252 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example richtext/syntaxhighlighter
+ \title Syntax Highlighter Example
+
+ The Syntax Highlighter example shows how to perform simple syntax
+ highlighting by subclassing the QSyntaxHighlighter class.
+
+ \image syntaxhighlighter-example.png
+
+ The Syntax Highlighter application displays C++ files with custom
+ syntax highlighting.
+
+ The example consists of two classes:
+
+ \list
+ \li The \c Highlighter class defines and applies the
+ highlighting rules.
+ \li The \c MainWindow widget is the application's main window.
+ \endlist
+
+ We will first review the \c Highlighter class to see how you can
+ customize the QSyntaxHighlighter class to fit your preferences,
+ then we will take a look at the relevant parts of the \c
+ MainWindow class to see how you can use your custom highlighter
+ class in an application.
+
+ \section1 Highlighter Class Definition
+
+ \snippet richtext/syntaxhighlighter/highlighter.h 0
+
+ To provide your own syntax highlighting, you must subclass
+ QSyntaxHighlighter, reimplement the \l
+ {QSyntaxHighlighter::highlightBlock()}{highlightBlock()} function,
+ and define your own highlighting rules.
+
+ We have chosen to store our highlighting rules using a private
+ struct: A rule consists of a QRegExp pattern and a QTextCharFormat
+ instance. The various rules are then stored using a QVector.
+
+ The QTextCharFormat class provides formatting information for
+ characters in a QTextDocument specifying the visual properties of
+ the text, as well as information about its role in a hypertext
+ document. In this example, we will only define the font weight and
+ color using the QTextCharFormat::setFontWeight() and
+ QTextCharFormat::setForeground() functions.
+
+ \section1 Highlighter Class Implementation
+
+ When subclassing the QSyntaxHighlighter class you must pass the
+ parent parameter to the base class constructor. The parent is the
+ text document upon which the syntax highligning will be
+ applied. In this example, we have also chosen to define our
+ highlighting rules in the constructor:
+
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 0
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 1
+
+ First we define a keyword rule which recognizes the most common
+ C++ keywords. We give the \c keywordFormat a bold, dark blue
+ font. For each keyword, we assign the keyword and the specified
+ format to a HighlightingRule object and append the object to our
+ list of rules.
+
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 2
+ \codeline
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 4
+ \codeline
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 5
+
+ Then we create a format that we will apply to Qt class names. The
+ class names will be rendered with a dark magenta color and a bold
+ style. We specify a string pattern that is actually a regular
+ expression capturing all Qt class names. Then we assign the
+ regular expression and the specified format to a HighlightingRule
+ object and append the object to our list of rules.
+
+ We also define highlighting rules for quotations and functions
+ using the same approach: The patterns have the form of regular
+ expressions and are stored in HighlightingRule objects with the
+ associated format.
+
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 3
+ \codeline
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 6
+
+ The C++ language has two variations of comments: The single line
+ comment (\c //) and the multiline comment (\c{/*...}\starslash). The single
+ line comment can easily be defined through a highlighting rule
+ similar to the previous ones. But the multiline comment needs
+ special care due to the design of the QSyntaxHighlighter class.
+
+ After a QSyntaxHighlighter object is created, its \l
+ {QSyntaxHighlighter::highlightBlock()}{highlightBlock()} function
+ will be called automatically whenever it is necessary by the rich
+ text engine, highlighting the given text block. The problem
+ appears when a comment spans several text blocks. We will take a
+ closer look at how this problem can be solved when reviewing the
+ implementation of the \c Highlighter::highlightBlock()
+ function. At this point we only specify the multiline comment's
+ color.
+
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 7
+
+ The highlightBlock() function is called automatically whenever it
+ is necessary by the rich text engine, i.e. when there are text
+ blocks that have changed.
+
+ First we apply the syntax highlighting rules that we stored in the
+ \c highlightingRules vector. For each rule (i.e. for each
+ HighlightingRule object) we search for the pattern in the given
+ textblock using the QString::indexOf() function. When the first
+ occurrence of the pattern is found, we use the
+ QRegExp::matchedLength() function to determine the string that
+ will be formatted. QRegExp::matchedLength() returns the length of
+ the last matched string, or -1 if there was no match.
+
+ To perform the actual formatting the QSyntaxHighlighter class
+ provides the \l {QSyntaxHighlighter::setFormat()}{setFormat()}
+ function. This function operates on the text block that is passed
+ as argument to the \c highlightBlock() function. The specified
+ format is applied to the text from the given start position for
+ the given length. The formatting properties set in the given
+ format are merged at display time with the formatting information
+ stored directly in the document. Note that the document itself
+ remains unmodified by the format set through this function.
+
+ This process is repeated until the last occurrence of the pattern
+ in the current text block is found.
+
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 8
+
+ To deal with constructs that can span several text blocks (like
+ the C++ multiline comment), it is necessary to know the end state
+ of the previous text block (e.g. "in comment"). Inside your \c
+ highlightBlock() implementation you can query the end state of the
+ previous text block using the
+ QSyntaxHighlighter::previousBlockState() function. After parsing
+ the block you can save the last state using
+ QSyntaxHighlighter::setCurrentBlockState().
+
+ The \l
+ {QSyntaxHighlighter::previousBlockState()}{previousBlockState()}
+ function return an int value. If no state is set, the returned
+ value is -1. You can designate any other value to identify any
+ given state using the \l
+ {QSyntaxHighlighter::setCurrentBlockState()}{setCurrentBlockState()}
+ function. Once the state is set, the QTextBlock keeps that value
+ until it is set again or until the corresponding paragraph of text
+ is deleted.
+
+ In this example we have chosen to use 0 to represent the "not in
+ comment" state, and 1 for the "in comment" state. When the stored
+ syntax highlighting rules are applied we initialize the current
+ block state to 0.
+
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 9
+
+ If the previous block state was "in comment" (\c
+ {previousBlockState() == 1}), we start the search for an end
+ expression at the beginning of the text block. If the
+ previousBlockState() returns 0, we start the search at the
+ location of the first occurrence of a start expression.
+
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 10
+ \snippet richtext/syntaxhighlighter/highlighter.cpp 11
+
+ When an end expression is found, we calculate the length of the
+ comment and apply the multiline comment format. Then we search for
+ the next occurrence of the start expression and repeat the
+ process. If no end expression can be found in the current text
+ block we set the current block state to 1, i.e. "in comment".
+
+ This completes the \c Highlighter class implementation; it is now
+ ready for use.
+
+ \section1 MainWindow Class Definition
+
+ Using a QSyntaxHighlighter subclass is simple; just provide your
+ application with an instance of the class and pass it the document
+ upon which you want the highlighting to be applied.
+
+ \snippet richtext/syntaxhighlighter/mainwindow.h 0
+
+ In this example we declare a pointer to a \c Highlighter instance
+ which we later will initialize in the private \c setupEditor()
+ function.
+
+ \section1 MainWindow Class Implementation
+
+ The constructor of the main window is straight forward. We first
+ set up the menus, then we initialize the editor and make it the
+ central widget of the application. Finally we set the main
+ window's title.
+
+ \snippet richtext/syntaxhighlighter/mainwindow.cpp 0
+
+ We initialize and install the \c Highlighter object in the private
+ setupEditor() convenience function:
+
+ \snippet richtext/syntaxhighlighter/mainwindow.cpp 1
+
+ First we create the font we want to use in the editor, then we
+ create the editor itself which is an instance of the QTextEdit
+ class. Before we initialize the editor with the \c MainWindow
+ class definition file, we create a \c Highlighter instance passing
+ the editor's document as argument. This is the document that the
+ highlighting will be applied to. Then we are done.
+
+ A QSyntaxHighlighter object can only be installed on one document
+ at the time, but you can easily reinstall the highlighter on
+ another document using the QSyntaxHighlighter::setDocument()
+ function. The QSyntaxHighlighter class also provides the \l
+ {QSyntaxHighlighter::document()}{document()} function which
+ returns the currently set document.
+
+ \section1 Other Code Editor Features
+
+ It is possible to implement parenthesis matching with
+ QSyntaxHighlighter. The "Matching Parentheses with
+ QSyntaxHighlighter" article in Qt Quarterly 31
+ (\l{http://doc.qt.nokia.com/qq/}) implements this. We also have
+ the \l{Code Editor Example}, which shows how to implement line
+ numbers and how to highlight the current line.
+
+*/
diff --git a/examples/widgets/doc/tabdialog.qdoc b/examples/widgets/doc/tabdialog.qdoc
new file mode 100644
index 0000000000..98983d124b
--- /dev/null
+++ b/examples/widgets/doc/tabdialog.qdoc
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example dialogs/tabdialog
+ \title Tab Dialog Example
+
+ The Tab Dialog example shows how to construct a tab dialog using the
+ QTabWidget class.
+
+ Dialogs provide an efficient way for the application to communicate
+ with the user, but complex dialogs suffer from the problem that they
+ often take up too much screen area. By using a number of tabs in a
+ dialog, information can be split into different categories, while
+ remaining accessible.
+
+ \image tabdialog-example.png
+
+ The Tab Dialog example consists of a single \c TabDialog class that
+ provides three tabs, each containing information about a particular
+ file, and two standard push buttons that are used to accept or reject
+ the contents of the dialog.
+
+ \section1 TabDialog Class Definition
+
+ The \c TabDialog class is a subclass of QDialog that displays a
+ QTabWidget and two standard dialog buttons. The class definition
+ only contain the class constructor and a private data member for
+ the QTabWidget:
+
+ \snippet dialogs/tabdialog/tabdialog.h 3
+
+ In the example, the widget will be used as a top-level window, but
+ we define the constructor so that it can take a parent widget. This
+ allows the dialog to be centered on top of an application's main
+ window.
+
+ \section1 TabDialog Class Implementation
+
+ The constructor calls the QDialog constructor and creates a QFileInfo
+ object for the specified filename.
+
+ \snippet dialogs/tabdialog/tabdialog.cpp 0
+
+ The tab widget is populated with three custom widgets that each
+ contain information about the file. We construct each of these
+ without a parent widget because the tab widget will reparent
+ them as they are added to it.
+
+ We create two standard push buttons, and connect each of them to
+ the appropriate slots in the dialog:
+
+ \snippet dialogs/tabdialog/tabdialog.cpp 1
+ \snippet dialogs/tabdialog/tabdialog.cpp 3
+
+ We arrange the tab widget above the buttons in the dialog:
+
+ \snippet dialogs/tabdialog/tabdialog.cpp 4
+
+ Finally, we set the dialog's title:
+
+ \snippet dialogs/tabdialog/tabdialog.cpp 5
+
+ Each of the tabs are subclassed from QWidget, and only provide
+ constructors.
+
+ \section1 GeneralTab Class Definition
+
+ The GeneralTab widget definition is simple because we are only interested
+ in displaying the contents of a widget within a tab:
+
+ \snippet dialogs/tabdialog/tabdialog.h 0
+
+ \section1 GeneralTab Class Implementation
+
+ The GeneralTab widget simply displays some information about the file
+ passed by the TabDialog. Various widgets for this purpose, and these
+ are arranged within a vertical layout:
+
+ \snippet dialogs/tabdialog/tabdialog.cpp 6
+
+ \section1 PermissionsTab Class Definition
+
+ Like the GeneralTab, the PermissionsTab is just used as a placeholder
+ widget for its children:
+
+ \snippet dialogs/tabdialog/tabdialog.h 1
+
+ \section1 PermissionsTab Class Implementation
+
+ The PermissionsTab shows information about the file's access information,
+ displaying details of the file permissions and owner in widgets that are
+ arranged in nested layouts:
+
+ \snippet dialogs/tabdialog/tabdialog.cpp 7
+
+ \section1 ApplicationsTab Class Definition
+
+ The ApplicationsTab is another placeholder widget that is mostly
+ cosmetic:
+
+ \snippet dialogs/tabdialog/tabdialog.h 2
+
+ \section1 ApplicationsTab Class Implementation
+
+ The ApplicationsTab does not show any useful information, but could be
+ used as a template for a more complicated example:
+
+ \snippet dialogs/tabdialog/tabdialog.cpp 8
+*/
diff --git a/examples/widgets/doc/tablet.qdoc b/examples/widgets/doc/tablet.qdoc
new file mode 100644
index 0000000000..846a9a357b
--- /dev/null
+++ b/examples/widgets/doc/tablet.qdoc
@@ -0,0 +1,369 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/tablet
+ \title Tablet Example
+
+ This example shows how to use a Wacom tablet in Qt applications.
+
+ \image tabletexample.png
+
+ When you use a tablet with Qt applications, \l{QTabletEvent}s are
+ generated. You need to reimplement the
+ \l{QWidget::}{tabletEvent()} event handler if you want to handle
+ tablet events. Events are generated when the device used for
+ drawing enters and leaves the proximity of the tablet (i.e., when
+ it is close but not pressed down on it), when a device is pushed
+ down and released from it, and when a device is moved on the
+ tablet.
+
+ The information available in QTabletEvent depends on the device
+ used. The tablet in this example has two different devices for
+ drawing: a stylus and an airbrush. For both devices the event
+ contains the position of the device, pressure on the tablet,
+ vertical tilt, and horizontal tilt (i.e, the angle between the
+ device and the perpendicular of the tablet). The airbrush has a
+ finger wheel; the position of this is also available in the tablet
+ event.
+
+ In this example we implement a drawing program. You can use the
+ stylus to draw on the tablet as you use a pencil on paper. When
+ you draw with the airbrush you get a spray of paint; the finger
+ wheel is used to change the density of the spray. The pressure and
+ tilt can change the alpha and saturation values of the QColor and the
+ width of the QPen used for drawing.
+
+ The example consists of the following:
+
+ \list
+ \li The \c MainWindow class inherits QMainWindow and creates
+ the examples menus and connect their slots and signals.
+ \li The \c TabletCanvas class inherits QWidget and
+ receives tablet events. It uses the events to paint on a
+ offscreen pixmap, which it draws onto itself.
+ \li The \c TabletApplication class inherits QApplication. This
+ class handles tablet events that are not sent to \c tabletEvent().
+ We will look at this later.
+ \li The \c main() function creates a \c MainWindow and shows it
+ as a top level window.
+ \endlist
+
+
+ \section1 MainWindow Class Definition
+
+ The \c MainWindow creates a \c TabletCanvas and sets it as its
+ center widget.
+
+ \snippet widgets/tablet/mainwindow.h 0
+
+ The QActions let the user select if the tablets pressure and
+ tilt should change the pen width, color alpha component and color
+ saturation. \c createActions() creates all actions, and \c
+ createMenus() sets up the menus with the actions. We have one
+ QActionGroup for the actions that alter the alpha channel, color
+ saturation and line width respectively. The action groups are
+ connected to the \c alphaActionTriggered(), \c
+ colorSaturationActiontriggered(), and \c
+ lineWidthActionTriggered() slots, which calls functions in \c
+ myCanvas.
+
+
+ \section1 MainWindow Class Implementation
+
+ We start width a look at the constructor \c MainWindow():
+
+ \snippet widgets/tablet/mainwindow.cpp 0
+
+ In the constructor we create the canvas, actions, and menus.
+ We set the canvas as the center widget. We also initialize the
+ canvas to match the state of our menus and start drawing with a
+ red color.
+
+ Here is the implementation of \c brushColorAct():
+
+ \snippet widgets/tablet/mainwindow.cpp 1
+
+ We let the user pick a color with a QColorDialog. If it is valid,
+ we set a new drawing color with \c setColor().
+
+ Here is the implementation of \c alphaActionTriggered():
+
+ \snippet widgets/tablet/mainwindow.cpp 2
+
+ The \c TabletCanvas class supports two ways by which the alpha
+ channel of the drawing color can be changed: tablet pressure and
+ tilt. We have one action for each and an action if the alpha
+ channel should not be changed.
+
+ Here is the implementation of \c lineWidthActionTriggered():
+
+ \snippet widgets/tablet/mainwindow.cpp 3
+
+ We check which action is selected in \c lineWidthGroup, and set
+ how the canvas should change the drawing line width.
+
+ Here is the implementation of \c saturationActionTriggered():
+
+ \snippet widgets/tablet/mainwindow.cpp 4
+
+ We check which action is selected in \c colorSaturationGroup, and
+ set how the canvas should change the color saturation of the
+ drawing color.
+
+ Here is the implementation of \c saveAct():
+
+ \snippet widgets/tablet/mainwindow.cpp 5
+
+ We use the QFileDialog to let the user select a file to save the
+ drawing in. It is the \c TabletCanvas that save the drawing, so we
+ call its \c saveImage() function.
+
+ Here is the implementation of \c loadAct():
+
+ \snippet widgets/tablet/mainwindow.cpp 6
+
+ We let the user select the image file to be opened with
+ a QFileDialog; we then ask the canvas to load the image with \c
+ loadImage().
+
+ Here is the implementation of \c aboutAct():
+
+ \snippet widgets/tablet/mainwindow.cpp 7
+
+ We show a message box with a short description of the example.
+
+ \c createActions() creates all actions and action groups of
+ the example. We look at the creation of one action group and its
+ actions. See the \l{Application Example}{application example} if
+ you want a high-level introduction to QActions.
+
+ Here is the implementation of \c createActions:
+
+ \snippet widgets/tablet/mainwindow.cpp 8
+ \dots
+ \snippet widgets/tablet/mainwindow.cpp 9
+
+ We want the user to be able to choose if the drawing color's
+ alpha component should be changed by the tablet pressure or tilt.
+ We have one action for each choice and an action if the alpha
+ channel is not to be changed, i.e, the color is opaque. We make
+ the actions checkable; the \c alphaChannelGroup will then ensure
+ that only one of the actions are checked at any time. The \c
+ triggered() signal is emitted when an action is checked.
+
+ \dots
+ \snippet widgets/tablet/mainwindow.cpp 10
+
+ Here is the implementation of \c createMenus():
+
+ \snippet widgets/tablet/mainwindow.cpp 11
+
+ We create the menus of the example and add the actions to them.
+
+
+ \section1 TabletCanvas Class Definition
+
+ The \c TabletCanvas class provides a surface on which the
+ user can draw with a tablet.
+
+ \snippet widgets/tablet/tabletcanvas.h 0
+
+ The canvas can change the alpha channel, color saturation,
+ and line width of the drawing. We have one enum for each of
+ these; their values decide if it is the tablet pressure or tilt
+ that will alter them. We keep a private variable for each, the \c
+ alphaChannelType, \c colorSturationType, and \c penWidthType,
+ which we provide access functions for.
+
+ We draw on a QPixmap with \c myPen and \c myBrush using \c
+ myColor. The \c saveImage() and \c loadImage() saves and loads
+ the QPixmap to disk. The pixmap is drawn on the widget in \c
+ paintEvent(). The \c pointerType and \c deviceType keeps the type
+ of pointer, which is either a pen or an eraser, and device
+ currently used on the tablet, which is either a stylus or an
+ airbrush.
+
+ The interpretation of events from the tablet is done in \c
+ tabletEvent(); \c paintPixmap(), \c updateBrush(), and \c
+ brushPattern() are helper functions used by \c tabletEvent().
+
+
+ \section1 TabletCanvas Class Implementation
+
+ We start with a look at the constructor:
+
+ \snippet widgets/tablet/tabletcanvas.cpp 0
+
+ In the constructor we initialize our class variables. We need
+ to draw the background of our pixmap, as the default is gray.
+
+ Here is the implementation of \c saveImage():
+
+ \snippet widgets/tablet/tabletcanvas.cpp 1
+
+ QPixmap implements functionality to save itself to disk, so we
+ simply call \l{QPixmap::}{save()}.
+
+ Here is the implementation of \c loadImage():
+
+ \snippet widgets/tablet/tabletcanvas.cpp 2
+
+ We simply call \l{QPixmap::}{load()}, which loads the image in \a
+ file.
+
+ Here is the implementation of \c tabletEvent():
+
+ \snippet widgets/tablet/tabletcanvas.cpp 3
+
+ We get three kind of events to this function: TabletPress,
+ TabletRelease, and TabletMove, which is generated when a device
+ is pressed down on, leaves, or moves on the tablet. We set the \c
+ deviceDown to true when a device is pressed down on the tablet;
+ we then know when we should draw when we receive move events. We
+ have implemented the \c updateBrush() and \c paintPixmap() helper
+ functions to update \c myBrush and \c myPen after the state of \c
+ alphaChannelType, \c colorSaturationType, and \c lineWidthType.
+
+ Here is the implementation of \c paintEvent():
+
+ \snippet widgets/tablet/tabletcanvas.cpp 4
+
+ We simply draw the pixmap to the top left of the widget.
+
+ Here is the implementation of \c paintPixmap():
+
+ \snippet widgets/tablet/tabletcanvas.cpp 5
+
+ In this function we draw on the pixmap based on the movement of the
+ device. If the device used on the tablet is a stylus we want to draw a
+ line between the positions of the stylus recorded in \c polyLine. We
+ also assume that this is a reasonable handling of any unknown device,
+ but update the statusbar with a warning so that the user can see that
+ for his tablet he might have to implement special handling.
+ If it is an airbrush we want to draw a circle of points with a
+ point density based on the tangential pressure, which is the position
+ of the finger wheel on the airbrush. We use the Qt::BrushStyle to
+ draw the points as it has styles that draw points with different
+ density; we select the style based on the tangential pressure in
+ \c brushPattern().
+
+ \snippet widgets/tablet/tabletcanvas.cpp 6
+
+ We return a brush style with a point density that increases with
+ the tangential pressure.
+
+ In \c updateBrush() we set the pen and brush used for drawing
+ to match \c alphaChannelType, \c lineWidthType, \c
+ colorSaturationType, and \c myColor. We will examine the code to
+ set up \c myBrush and \c myPen for each of these variables:
+
+ \snippet widgets/tablet/tabletcanvas.cpp 7
+
+ We fetch the current drawingcolor's hue, saturation, value,
+ and alpha values. \c hValue and \c vValue are set to the
+ horizontal and vertical tilt as a number from 0 to 255. The
+ original values are in degrees from -60 to 60, i.e., 0 equals
+ -60, 127 equals 0, and 255 equals 60 degrees. The angle measured
+ is between the device and the perpendicular of the tablet (see
+ QTabletEvent for an illustration).
+
+ \snippet widgets/tablet/tabletcanvas.cpp 8
+
+ The alpha channel of QColor is given as a number between 0
+ and 255 where 0 is transparent and 255 is opaque.
+ \l{QTabletEvent::}{pressure()} returns the pressure as a qreal
+ between 0.0 and 1.0. By subtracting 127 from the tilt values and
+ taking the absolute value we get the smallest alpha values (i.e.,
+ the color is most transparent) when the pen is perpendicular to
+ the tablet. We select the largest of the vertical and horizontal
+ tilt value.
+
+ \snippet widgets/tablet/tabletcanvas.cpp 9
+
+ The colorsaturation is given as a number between 0 and 255. It is
+ set with \l{QColor::}{setHsv()}. We can set the tilt values
+ directly, but must multiply the pressure to a number between 0 and
+ 255.
+
+ \snippet widgets/tablet/tabletcanvas.cpp 10
+
+ The width of the pen increases with the pressure. When the pen
+ width is controlled with the tilt we let the width increse with
+ the angle between the device and the perpendicular of the tablet.
+
+ \snippet widgets/tablet/tabletcanvas.cpp 11
+
+ We finally check whether the pointer is the stylus or the eraser.
+ If it is the eraser, we set the color to the background color of
+ the pixmap an let the pressure decide the pen width, else we set
+ the colors we have set up previously in the function.
+
+
+ \section1 TabletApplication Class Definition
+
+ We inherit QApplication in this class because we want to
+ reimplement the \l{QApplication::}{event()} function.
+
+ \snippet widgets/tablet/tabletapplication.h 0
+
+ We keep a \c TabletCanvas we send the device type of the events we
+ handle in the \c event() function to. The TabletEnterProximity
+ and TabletLeaveProximity events are not sendt to the QApplication
+ object, while other tablet events are sendt to the QWidget's
+ \c event(), which sends them on to \l{QWidget::}{tabletEvent()}.
+ Since we want to handle these events we have implemented \c
+ TabletApplication.
+
+
+ \section1 TabletApplication Class Implementation
+
+ Here is the implementation of \c event():
+
+ \snippet widgets/tablet/tabletapplication.cpp 0
+
+ We use this function to handle the TabletEnterProximity and
+ TabletLeaveProximity events, which is generated when a device
+ enters and leaves the proximity of the tablet. The intended use of these
+ events is to do work that is dependent on what kind of device is
+ used on the tablet. This way, you don't have to do this work
+ when other events are generated, which is more frequently than the
+ leave and enter proximity events. We call \c setTabletDevice() in
+ \c TabletCanvas.
+
+ \section1 The \c main() function
+
+ Here is the examples \c main() function:
+
+ \snippet widgets/tablet/main.cpp 0
+
+ In the \c main() function we create a \c MainWinow and display it
+ as a top level window. We use the \c TabletApplication class. We
+ need to set the canvas after the application is created. We cannot
+ use classes that implement event handling before an QApplication
+ object is instantiated.
+*/
diff --git a/examples/widgets/doc/tetrix.qdoc b/examples/widgets/doc/tetrix.qdoc
new file mode 100644
index 0000000000..1a30845024
--- /dev/null
+++ b/examples/widgets/doc/tetrix.qdoc
@@ -0,0 +1,431 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/tetrix
+ \title Tetrix Example
+
+ The Tetrix example is a Qt version of the classic Tetrix game.
+
+ \image tetrix-example.png
+
+ The object of the game is to stack pieces dropped from the top of the
+ playing area so that they fill entire rows at the bottom of the playing area.
+
+ When a row is filled, all the blocks on that row are removed, the player earns
+ a number of points, and the pieces above are moved down to occupy that row.
+ If more than one row is filled, the blocks on each row are removed, and the
+ player earns extra points.
+
+ The \uicontrol{Left} cursor key moves the current piece one space to the left, the
+ \uicontrol{Right} cursor key moves it one space to the right, the \uicontrol{Up} cursor
+ key rotates the piece counter-clockwise by 90 degrees, and the \uicontrol{Down}
+ cursor key rotates the piece clockwise by 90 degrees.
+
+ To avoid waiting for a piece to fall to the bottom of the board, press \uicontrol{D}
+ to immediately move the piece down by one row, or press the \uicontrol{Space} key to
+ drop it as close to the bottom of the board as possible.
+
+ This example shows how a simple game can be created using only three classes:
+
+ \list
+ \li The \c TetrixWindow class is used to display the player's score, number of
+ lives, and information about the next piece to appear.
+ \li The \c TetrixBoard class contains the game logic, handles keyboard input, and
+ displays the pieces on the playing area.
+ \li The \c TetrixPiece class contains information about each piece.
+ \endlist
+
+ In this approach, the \c TetrixBoard class is the most complex class, since it
+ handles the game logic and rendering. One benefit of this is that the
+ \c TetrixWindow and \c TetrixPiece classes are very simple and contain only a
+ minimum of code.
+
+ \section1 TetrixWindow Class Definition
+
+ The \c TetrixWindow class is used to display the game information and contains
+ the playing area:
+
+ \snippet widgets/tetrix/tetrixwindow.h 0
+
+ We use private member variables for the board, various display widgets, and
+ buttons to allow the user to start a new game, pause the current game, and quit.
+
+ Although the window inherits QWidget, the constructor does not provide an
+ argument to allow a parent widget to be specified. This is because the window
+ will always be used as a top-level widget.
+
+ \section1 TetrixWindow Class Implementation
+
+ The constructor sets up the user interface elements for the game:
+
+ \snippet widgets/tetrix/tetrixwindow.cpp 0
+
+ We begin by constructing a \c TetrixBoard instance for the playing area and a
+ label that shows the next piece to be dropped into the playing area; the label
+ is initially empty.
+
+ Three QLCDNumber objects are used to display the score, number of lives, and
+ lines removed. These initially show default values, and will be filled in
+ when a game begins:
+
+ \snippet widgets/tetrix/tetrixwindow.cpp 1
+
+ Three buttons with shortcuts are constructed so that the user can start a
+ new game, pause the current game, and quit the application:
+
+ \snippet widgets/tetrix/tetrixwindow.cpp 2
+ \snippet widgets/tetrix/tetrixwindow.cpp 3
+
+ These buttons are configured so that they never receive the keyboard focus;
+ we want the keyboard focus to remain with the \c TetrixBoard instance so that
+ it receives all the keyboard events. Nonetheless, the buttons will still respond
+ to \uicontrol{Alt} key shortcuts.
+
+ We connect \l{QAbstractButton::}{clicked()} signals from the \uicontrol{Start}
+ and \uicontrol{Pause} buttons to the board, and from the \uicontrol{Quit} button to the
+ application's \l{QApplication::}{quit()} slot.
+
+ \snippet widgets/tetrix/tetrixwindow.cpp 4
+ \snippet widgets/tetrix/tetrixwindow.cpp 5
+
+ Signals from the board are also connected to the LCD widgets for the purpose of
+ updating the score, number of lives, and lines removed from the playing area.
+
+ We place the label, LCD widgets, and the board into a QGridLayout
+ along with some labels that we create with the \c createLabel() convenience
+ function:
+
+ \snippet widgets/tetrix/tetrixwindow.cpp 6
+
+ Finally, we set the grid layout on the widget, give the window a title, and
+ resize it to an appropriate size.
+
+ The \c createLabel() convenience function simply creates a new label on the
+ heap, gives it an appropriate alignment, and returns it to the caller:
+
+ \snippet widgets/tetrix/tetrixwindow.cpp 7
+
+ Since each label will be used in the widget's layout, it will become a child
+ of the \c TetrixWindow widget and, as a result, it will be deleted when the
+ window is deleted.
+
+ \section1 TetrixPiece Class Definition
+
+ The \c TetrixPiece class holds information about a piece in the game's
+ playing area, including its shape, position, and the range of positions it can
+ occupy on the board:
+
+ \snippet widgets/tetrix/tetrixpiece.h 0
+
+ Each shape contains four blocks, and these are defined by the \c coords private
+ member variable. Additionally, each piece has a high-level description that is
+ stored internally in the \c pieceShape variable.
+
+ The constructor is written inline in the definition, and simply ensures that
+ each piece is initially created with no shape. The \c shape() function simply
+ returns the contents of the \c pieceShape variable, and the \c x() and \c y()
+ functions return the x and y-coordinates of any given block in the shape.
+
+ \section1 TetrixPiece Class Implementation
+
+ The \c setRandomShape() function is used to select a random shape for a piece:
+
+ \snippet widgets/tetrix/tetrixpiece.cpp 0
+
+ For convenience, it simply chooses a random shape from the \c TetrixShape enum
+ and calls the \c setShape() function to perform the task of positioning the
+ blocks.
+
+ The \c setShape() function uses a look-up table of pieces to associate each
+ shape with an array of block positions:
+
+ \snippet widgets/tetrix/tetrixpiece.cpp 1
+ \snippet widgets/tetrix/tetrixpiece.cpp 2
+
+ These positions are read from the table into the piece's own array of positions,
+ and the piece's internal shape information is updated to use the new shape.
+
+ The \c x() and \c y() functions are implemented inline in the class definition,
+ returning positions defined on a grid that extends horizontally and vertically
+ with coordinates from -2 to 2. Although the predefined coordinates for each
+ piece only vary horizontally from -1 to 1 and vertically from -1 to 2, each
+ piece can be rotated by 90, 180, and 270 degrees.
+
+ The \c minX() and \c maxX() functions return the minimum and maximum horizontal
+ coordinates occupied by the blocks that make up the piece:
+
+ \snippet widgets/tetrix/tetrixpiece.cpp 3
+ \snippet widgets/tetrix/tetrixpiece.cpp 4
+
+ Similarly, the \c minY() and \c maxY() functions return the minimum and maximum
+ vertical coordinates occupied by the blocks:
+
+ \snippet widgets/tetrix/tetrixpiece.cpp 5
+ \snippet widgets/tetrix/tetrixpiece.cpp 6
+
+ The \c rotatedLeft() function returns a new piece with the same shape as an
+ existing piece, but rotated counter-clockwise by 90 degrees:
+
+ \snippet widgets/tetrix/tetrixpiece.cpp 7
+
+ Similarly, the \c rotatedRight() function returns a new piece with the same
+ shape as an existing piece, but rotated clockwise by 90 degrees:
+
+ \snippet widgets/tetrix/tetrixpiece.cpp 9
+
+ These last two functions enable each piece to create rotated copies of itself.
+
+ \section1 TetrixBoard Class Definition
+
+ The \c TetrixBoard class inherits from QFrame and contains the game logic and display features:
+
+ \snippet widgets/tetrix/tetrixboard.h 0
+
+ Apart from the \c setNextPieceLabel() function and the \c start() and \c pause()
+ public slots, we only provide public functions to reimplement QWidget::sizeHint()
+ and QWidget::minimumSizeHint(). The signals are used to communicate changes to
+ the player's information to the \c TetrixWindow instance.
+
+ The rest of the functionality is provided by reimplementations of protected event
+ handlers and private functions:
+
+ \snippet widgets/tetrix/tetrixboard.h 1
+
+ The board is composed of a fixed-size array whose elements correspond to
+ spaces for individual blocks. Each element in the array contains a \c TetrixShape
+ value corresponding to the type of shape that occupies that element.
+
+ Each shape on the board will occupy four elements in the array, and these will
+ all contain the enum value that corresponds to the type of the shape.
+
+ We use a QBasicTimer to control the rate at which pieces fall toward the bottom
+ of the playing area. This allows us to provide an implementation of
+ \l{QObject::}{timerEvent()} that we can use to update the widget.
+
+ \section1 TetrixBoard Class Implementation
+
+ In the constructor, we customize the frame style of the widget, ensure that
+ keyboard input will be received by the widget by using Qt::StrongFocus for the
+ focus policy, and initialize the game state:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 0
+
+ The first (next) piece is also set up with a random shape.
+
+ The \c setNextPieceLabel() function is used to pass in an externally-constructed
+ label to the board, so that it can be shown alongside the playing area:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 1
+
+ We provide a reasonable size hint and minimum size hint for the board, based on
+ the size of the space for each block in the playing area:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 2
+ \snippet widgets/tetrix/tetrixboard.cpp 3
+
+ By using a minimum size hint, we indicate to the layout in the parent widget
+ that the board should not shrink below a minimum size.
+
+ A new game is started when the \c start() slot is called. This resets the
+ game's state, the player's score and level, and the contents of the board:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 4
+
+ We also emit signals to inform other components of these changes before creating
+ a new piece that is ready to be dropped into the playing area. We start the
+ timer that determines how often the piece drops down one row on the board.
+
+ The \c pause() slot is used to temporarily stop the current game by stopping the
+ internal timer:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 5
+ \snippet widgets/tetrix/tetrixboard.cpp 6
+
+ We perform checks to ensure that the game can only be paused if it is already
+ running and not already paused.
+
+ The \c paintEvent() function is straightforward to implement. We begin by
+ calling the base class's implementation of \l{QWidget::}{paintEvent()} before
+ constructing a QPainter for use on the board:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 7
+
+ Since the board is a subclass of QFrame, we obtain a QRect that covers the area
+ \e inside the frame decoration before drawing our own content.
+
+ If the game is paused, we want to hide the existing state of the board and
+ show some text. We achieve this by painting text onto the widget and returning
+ early from the function. The rest of the painting is performed after this point.
+
+ The position of the top of the board is found by subtracting the total height
+ of each space on the board from the bottom of the frame's internal rectangle.
+ For each space on the board that is occupied by a piece, we call the
+ \c drawSquare() function to draw a block at that position.
+
+ \snippet widgets/tetrix/tetrixboard.cpp 8
+ \snippet widgets/tetrix/tetrixboard.cpp 9
+
+ Spaces that are not occupied by blocks are left blank.
+
+ Unlike the existing pieces on the board, the current piece is drawn
+ block-by-block at its current position:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 10
+ \snippet widgets/tetrix/tetrixboard.cpp 11
+ \snippet widgets/tetrix/tetrixboard.cpp 12
+
+ The \c keyPressEvent() handler is called whenever the player presses a key while
+ the \c TetrixBoard widget has the keyboard focus.
+
+ \snippet widgets/tetrix/tetrixboard.cpp 13
+
+ If there is no current game, the game is running but paused, or if there is no
+ current shape to control, we simply pass on the event to the base class.
+
+ We check whether the event is about any of the keys that the player uses to
+ control the current piece and, if so, we call the relevant function to handle
+ the input:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 14
+
+ In the case where the player presses a key that we are not interested in, we
+ again pass on the event to the base class's implementation of
+ \l{QWidget::}{keyPressEvent()}.
+
+ The \c timerEvent() handler is called every time the class's QBasicTimer
+ instance times out. We need to check that the event we receive corresponds to
+ our timer. If it does, we can update the board:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 15
+ \snippet widgets/tetrix/tetrixboard.cpp 16
+ \snippet widgets/tetrix/tetrixboard.cpp 17
+
+ If a row (or line) has just been filled, we create a new piece and reset the
+ timer; otherwise we move the current piece down by one row. We let the base
+ class handle other timer events that we receive.
+
+ The \c clearBoard() function simply fills the board with the
+ \c TetrixShape::NoShape value:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 18
+
+ The \c dropDown() function moves the current piece down as far as possible on
+ the board, either until it is touching the bottom of the playing area or it is
+ stacked on top of another piece:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 19
+ \snippet widgets/tetrix/tetrixboard.cpp 20
+
+ The number of rows the piece has dropped is recorded and passed to the
+ \c pieceDropped() function so that the player's score can be updated.
+
+ The \c oneLineDown() function is used to move the current piece down by one row
+ (line), either when the user presses the \uicontrol{D} key or when the piece is
+ scheduled to move:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 21
+
+ If the piece cannot drop down by one line, we call the \c pieceDropped() function
+ with zero as the argument to indicate that it cannot fall any further, and that
+ the player should receive no extra points for the fall.
+
+ The \c pieceDropped() function itself is responsible for awarding points to the
+ player for positioning the current piece, checking for full rows on the board
+ and, if no lines have been removed, creating a new piece to replace the current
+ one:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 22
+ \snippet widgets/tetrix/tetrixboard.cpp 23
+
+ We call \c removeFullLines() each time a piece has been dropped. This scans
+ the board from bottom to top, looking for blank spaces on each row.
+
+ \snippet widgets/tetrix/tetrixboard.cpp 24
+ \snippet widgets/tetrix/tetrixboard.cpp 25
+ \snippet widgets/tetrix/tetrixboard.cpp 26
+ \snippet widgets/tetrix/tetrixboard.cpp 27
+
+ If a row contains no blank spaces, the rows above it are copied down by one row
+ to compress the stack of pieces, the top row on the board is cleared, and the
+ number of full lines found is incremented.
+
+ \snippet widgets/tetrix/tetrixboard.cpp 28
+ \snippet widgets/tetrix/tetrixboard.cpp 29
+
+ If some lines have been removed, the player's score and the total number of lines
+ removed are updated. The \c linesRemoved() and \c scoreChanged() signals are
+ emitted to send these new values to other widgets in the window.
+
+ Additionally, we set the timer to elapse after half a second, set the
+ \c isWaitingAfterLine flag to indicate that lines have been removed, unset
+ the piece's shape to ensure that it is not drawn, and update the widget.
+ The next time that the \c timerEvent() handler is called, a new piece will be
+ created and the game will continue.
+
+ The \c newPiece() function places the next available piece at the top of the
+ board, and creates a new piece with a random shape:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 30
+ \snippet widgets/tetrix/tetrixboard.cpp 31
+
+ We place a new piece in the middle of the board at the top. The game is over if
+ the piece can't move, so we unset its shape to prevent it from being drawn, stop
+ the timer, and unset the \c isStarted flag.
+
+ The \c showNextPiece() function updates the label that shows the next piece to
+ be dropped:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 32
+ \snippet widgets/tetrix/tetrixboard.cpp 33
+
+ We draw the piece's component blocks onto a pixmap that is then set on the label.
+
+ The \c tryMove() function is used to determine whether a piece can be positioned
+ at the specified coordinates:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 34
+
+ We examine the spaces on the board that the piece needs to occupy and, if they
+ are already occupied by other pieces, we return \c false to indicate that the
+ move has failed.
+
+ \snippet widgets/tetrix/tetrixboard.cpp 35
+
+ If the piece could be placed on the board at the desired location, we update the
+ current piece and its position, update the widget, and return \c true to indicate
+ success.
+
+ The \c drawSquare() function draws the blocks (normally squares) that make up
+ each piece using different colors for pieces with different shapes:
+
+ \snippet widgets/tetrix/tetrixboard.cpp 36
+
+ We obtain the color to use from a look-up table that relates each shape to an
+ RGB value, and use the painter provided to draw the block at the specified
+ coordinates.
+*/
diff --git a/examples/widgets/doc/textedit.qdoc b/examples/widgets/doc/textedit.qdoc
new file mode 100644
index 0000000000..1bb596eb6e
--- /dev/null
+++ b/examples/widgets/doc/textedit.qdoc
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example richtext/textedit
+ \title Text Edit
+
+ The Text Edit example shows Qt's rich text editing facilities in action,
+ providing an example document for you to experiment with.
+
+ \image textedit-demo.png
+*/
diff --git a/examples/widgets/doc/tooltips.qdoc b/examples/widgets/doc/tooltips.qdoc
new file mode 100644
index 0000000000..e06f080a93
--- /dev/null
+++ b/examples/widgets/doc/tooltips.qdoc
@@ -0,0 +1,394 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/tooltips
+ \title Tool Tips Example
+
+ The Tool Tips example shows how to provide static and dynamic tool
+ tips for an application's widgets.
+
+ The simplest and most common way to set a widget's tool tip is by
+ calling its QWidget::setToolTip() function (static tool
+ tips). Then the tool tip is shown whenever the cursor points at
+ the widget. We show how to do this with our application's tool
+ buttons. But it is also possible to show different tool tips
+ depending on the cursor's position (dynamic tooltips). This
+ approach uses mouse tracking and event handling to determine what
+ widgets are located under the cursor at any point in time, and
+ displays their tool tips. The tool tips for the shape items in our
+ application are implemented using the latter approach.
+
+ \image tooltips-example.png
+
+ With the \c Tooltips application the user can create new shape
+ items with the provided tool buttons, and move the items around
+ using the mouse. Tooltips are provided whenever the cursor is
+ pointing to a shape item or one of the buttons.
+
+ The Tooltips example consists of two classes:
+
+ \list
+ \li \c ShapeItem is a custom widget representing one single shape item.
+ \li \c SortingBox inherits from QWidget and is the application's main
+ widget.
+ \endlist
+
+ First we will review the \c SortingBox class, then we will take a
+ look at the \c ShapeItem class.
+
+ \section1 SortingBox Class Definition
+
+ \snippet widgets/tooltips/sortingbox.h 0
+
+ The \c SortingBox class inherits QWidget, and it is the Tooltips
+ application's main widget. We reimplement several of the event
+ handlers.
+
+ The \c event() function provides tooltips, the \c resize()
+ function makes sure the application appears consistently when the
+ user resizes the main widget, and the \c paintEvent() function
+ displays the shape items within the \c SortingBox widget. The
+ mouse event handlers are reimplemented to make the user able to
+ move the items around.
+
+ In addition we need three private slots to make the user able to
+ create new shape items.
+
+ \snippet widgets/tooltips/sortingbox.h 1
+
+ We also create several private functions: We use the \c
+ initialItemPosition(), \c initialItemColor() and \c
+ createToolButton() functions when we are constructing the widget,
+ and we use the \c updateButtonGeometry() function whenever the
+ user is resizing the application's main widget.
+
+ The \c itemAt() function determines if there is a shape item at a
+ particular position, and the \c moveItemTo() function moves an
+ item to a new position. We use the \c createShapeItem(), \c
+ randomItemPosition() and \c randomItemColor() functions to create
+ new shape items.
+
+ \snippet widgets/tooltips/sortingbox.h 2
+
+ We keep all the shape items in a QList, and we keep three
+ QPainterPath objects holding the shapes of a circle, a square and
+ a triangle. We also need to have a pointer to an item when it is
+ moving, and we need to know its previous position.
+
+ \section1 SortingBox Class Implementation
+
+ \snippet widgets/tooltips/sortingbox.cpp 0
+
+ In the constructor, we first set the Qt::WA_StaticContents
+ attribute on the widget. This attribute indicates that the widget
+ contents are north-west aligned and static. On resize, such a
+ widget will receive paint events only for the newly visible part
+ of itself.
+
+ \snippet widgets/tooltips/sortingbox.cpp 1
+
+ To be able to show the appropriate tooltips while the user is
+ moving the cursor around, we need to enable mouse tracking for the
+ widget.
+
+ If mouse tracking is disabled (the default), the widget only
+ receives mouse move events when at least one mouse button is
+ pressed while the mouse is being moved. If mouse tracking is
+ enabled, the widget receives mouse move events even if no buttons
+ are pressed.
+
+ \snippet widgets/tooltips/sortingbox.cpp 2
+
+ A widget's background role defines the brush from the widget's
+ palette that is used to render the background, and QPalette::Base
+ is typically white.
+
+ \snippet widgets/tooltips/sortingbox.cpp 3
+
+ After creating the application's tool buttons using the private \c
+ createToolButton() function, we construct the shapes of a circle,
+ a square and a triangle using QPainterPath.
+
+ The QPainterPath class provides a container for painting
+ operations, enabling graphical shapes to be constructed and
+ reused. The main advantage of painter paths over normal drawing
+ operations is that complex shapes only need to be created once,
+ but they can be drawn many times using only calls to
+ QPainter::drawPath().
+
+ \snippet widgets/tooltips/sortingbox.cpp 4
+
+ Then we set the window title, resize the widget to a suitable
+ size, and finally create three initial shape items using the
+ private \c createShapeItem(), \c initialItemPosition() and \c
+ initialItemColor() functions.
+
+ \snippet widgets/tooltips/sortingbox.cpp 5
+
+ QWidget::event() is the main event handler and receives all the
+ widget's events. Normally, we recommend reimplementing one of the
+ specialized event handlers instead of this function. But here we
+ want to catch the QEvent::ToolTip events, and since these are
+ rather rare, there exists no specific event handler. For that
+ reason we reimplement the main event handler, and the first thing
+ we need to do is to determine the event's type:
+
+ \snippet widgets/tooltips/sortingbox.cpp 6
+
+ If the type is QEvent::ToolTip, we cast the event to a QHelpEvent,
+ otherwise we propagate the event using the QWidget::event()
+ function.
+
+ The QHelpEvent class provides an event that is used to request
+ helpful information about a particular point in a widget.
+
+ For example, the QHelpEvent::pos() function returns the event's
+ position relative to the widget to which the event is dispatched.
+ Here we use this information to determine if the position of the
+ event is contained within the area of any of the shape items. If
+ it is, we display the shape item's tooltip at the position of the
+ event. If not, we hide the tooltip and explicitly ignore the event.
+ This makes sure that the calling code does not start any tooltip
+ specific modes as a result of the event. Note that the
+ QToolTip::showText() function needs the event's position in global
+ coordinates provided by QHelpEvent::globalPos().
+
+ \snippet widgets/tooltips/sortingbox.cpp 7
+
+ The \c resizeEvent() function is reimplemented to receive the
+ resize events dispatched to the widget. It makes sure that the
+ tool buttons keep their position relative to the main widget when
+ the widget is resized. We want the buttons to always be vertically
+ aligned in the application's bottom right corner, so each time the
+ main widget is resized we update the buttons geometry.
+
+ \snippet widgets/tooltips/sortingbox.cpp 8
+
+ The \c paintEvent() function is reimplemented to receive paint
+ events for the widget. We create a QPainter for the \c SortingBox
+ widget, and run through the list of created shape items, drawing
+ each item at its defined position.
+
+ \snippet widgets/tooltips/sortingbox.cpp 9
+
+ The painter will by default draw all the shape items at position
+ (0,0) in the \c SortingBox widget. The QPainter::translate()
+ function translates the coordinate system by the given offset,
+ making each shape item appear at its defined position. But
+ remember to translate the coordinate system back when the item is
+ drawn, otherwise the next shape item will appear at a position
+ relative to the item we drawed last.
+
+ \snippet widgets/tooltips/sortingbox.cpp 10
+
+ The QPainter::setBrush() function sets the current brush used by
+ the painter. When the provided argument is a QColor, the function
+ calls the appropriate QBrush constructor which creates a brush with
+ the specified color and Qt::SolidPattern style. The
+ QPainter::drawPath() function draws the given path using the
+ current pen for outline and the current brush for filling.
+
+ \snippet widgets/tooltips/sortingbox.cpp 11
+
+ The \c mousePressEvent() function is reimplemented to receive the
+ mouse press events dispatched to the widget. It determines if an
+ event's position is contained within the area of any of the shape
+ items, using the private \c itemAt() function.
+
+ If an item covers the position, we store a pointer to that item
+ and the event's position. If several of the shape items cover the
+ position, we store the pointer to the uppermost item. Finally, we
+ move the shape item to the end of the list, and make a call to the
+ QWidget::update() function to make the item appear on top.
+
+ The QWidget::update() function does not cause an immediate
+ repaint; instead it schedules a paint event for processing when Qt
+ returns to the main event loop.
+
+ \snippet widgets/tooltips/sortingbox.cpp 12
+
+ The \c mouseMoveEvent() function is reimplemented to receive mouse
+ move events for the widget. If the left mouse button is pressed
+ and there exists a shape item in motion, we use the private \c
+ moveItemTo() function to move the item with an offset
+ corresponding to the offset between the positions of the current
+ mouse event and the previous one.
+
+ \snippet widgets/tooltips/sortingbox.cpp 13
+
+ The \c mouseReleaseEvent() function is reimplemented to receive
+ the mouse release events dispatched to the widget. If the left
+ mouse button is pressed and there exists a shape item in motion,
+ we use the private \c moveItemTo() function to move the item like
+ we did in \c mouseMoveEvent(). But then we remove the pointer to
+ the item in motion, making the shape item's position final for
+ now. To move the item further, the user will need to press the
+ left mouse button again.
+
+ \snippet widgets/tooltips/sortingbox.cpp 14
+ \codeline
+ \snippet widgets/tooltips/sortingbox.cpp 15
+ \codeline
+ \snippet widgets/tooltips/sortingbox.cpp 16
+
+ The \c createNewCircle(), \c createNewSquare() and \c
+ createNewTriangle() slots simply create new shape items, using the
+ private \c createShapeItem(), \c randomItemPosition() and \c
+ randomItemColor() functions.
+
+ \snippet widgets/tooltips/sortingbox.cpp 17
+
+ In the \c itemAt() function, we run through the list of created
+ shape items to check if the given position is contained within the
+ area of any of the shape items.
+
+ For each shape item we use the QPainterPath::contains() function
+ to find out if the item's painter path contains the position. If
+ it does we return the index of the item, otherwise we return
+ -1. We run through the list backwards to get the index of the
+ uppermost shape item in case several items cover the position.
+
+ \snippet widgets/tooltips/sortingbox.cpp 18
+
+ The \c moveItemTo() function moves the shape item in motion, and
+ the parameter \c pos is the position of a mouse event. First we
+ calculate the offset between the parameter \c pos and the previous
+ mouse event position. Then we add the offset to the current
+ position of the item in motion.
+
+ It is tempting to simply set the position of the item to be the
+ parameter \c pos. But an item's position defines the top left
+ corner of the item's bounding rectangle, and the parameter \c pos
+ can be any point; The suggested shortcut would cause the item to
+ jump to a position where the cursor is pointing to the bounding
+ rectangle's top left corner, regardless of the item's previous
+ position.
+
+ \snippet widgets/tooltips/sortingbox.cpp 19
+
+ Finally, we update the previous mouse event position, and make a
+ call to the QWidget::update() function to make the item appear at
+ its new position.
+
+ \snippet widgets/tooltips/sortingbox.cpp 20
+
+ In the \c updateButtonGeometry() function we set the geometry for
+ the given button. The parameter coordinates define the bottom
+ right corner of the button. We use these coordinates and the
+ button's size hint to determine the position of the upper left
+ corner. This position, and the button's width and height, are the
+ arguments required by the QWidget::setGeometry() function.
+
+ In the end, we calculate and return the y-coordinate of the bottom
+ right corner of the next button. We use the QWidget::style()
+ function to retrieve the widget's GUI style, and then
+ QStyle::pixelMetric() to determine the widget's preferred default
+ spacing between its child widgets.
+
+ \snippet widgets/tooltips/sortingbox.cpp 21
+
+ The \c createShapeItem() function creates a single shape item. It
+ sets the path, tooltip, position and color, using the item's own
+ functions. In the end, the function appends the new item to the
+ list of shape items, and calls the QWidget::update() function to
+ make it appear with the other items within the \c SortingBox
+ widget.
+
+ \snippet widgets/tooltips/sortingbox.cpp 22
+
+ The \c createToolButton() function is called from the \c
+ SortingBox constructor. We create a tool button with the given
+ tooltip and icon. The button's parent is the \c SortingBox widget,
+ and its size is 32 x 32 pixels. Before we return the button, we
+ connect it to the given slot.
+
+ \snippet widgets/tooltips/sortingbox.cpp 23
+
+ The \c initialItemPosition() function is also called from the
+ constructor. We want the three first items to initially be
+ centered in the middle of the \c SortingBox widget, and we use
+ this function to calculate their positions.
+
+ \snippet widgets/tooltips/sortingbox.cpp 24
+
+ Whenever the user creates a new shape item, we want the new item
+ to appear at a random position, and we use the \c
+ randomItemPosition() function to calculate such a position. We
+ make sure that the item appears within the visible area of the
+ \c SortingBox widget, using the widget's current width and height
+ when calculating the random coordinates.
+
+ \snippet widgets/tooltips/sortingbox.cpp 25
+
+ As with \c initialItemPosition(), the \c initialItemColor()
+ function is called from the constructor. The purposes of both
+ functions are purely cosmetic: We want to control the initial
+ position and color of the three first items.
+
+ \snippet widgets/tooltips/sortingbox.cpp 26
+
+ Finally the \c randomItemColor() function is implemented to give
+ the shape items the user creates, a random color.
+
+ \section1 ShapeItem Class Definition
+
+ \snippet widgets/tooltips/shapeitem.h 0
+
+ The \c ShapeItem class is a custom widget representing one single
+ shape item. The widget has a path, a position, a color and a
+ tooltip. We need functions to set or modify these objects, as well
+ as functions that return them. We make the latter functions \c
+ const to prohibit any modifications of the objects,
+ i.e. prohibiting unauthorized manipulation of the shape items
+ appearance.
+
+ \section1 ShapeItem Class Implementation
+
+ \snippet widgets/tooltips/shapeitem.cpp 0
+ \codeline
+ \snippet widgets/tooltips/shapeitem.cpp 1
+ \codeline
+ \snippet widgets/tooltips/shapeitem.cpp 2
+ \codeline
+ \snippet widgets/tooltips/shapeitem.cpp 3
+
+ This first group of functions simply return the objects that are
+ requested. The objects are returned as constants, i.e. they cannot
+ be modified.
+
+ \snippet widgets/tooltips/shapeitem.cpp 4
+ \codeline
+ \snippet widgets/tooltips/shapeitem.cpp 5
+ \codeline
+ \snippet widgets/tooltips/shapeitem.cpp 6
+ \codeline
+ \snippet widgets/tooltips/shapeitem.cpp 7
+
+ The last group of functions set or modify the shape item's path,
+ position, color and tooltip, respectively.
+*/
diff --git a/examples/widgets/doc/trafficlight.qdoc b/examples/widgets/doc/trafficlight.qdoc
new file mode 100644
index 0000000000..ec3578abaa
--- /dev/null
+++ b/examples/widgets/doc/trafficlight.qdoc
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \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 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 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 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:
+
+ \image trafficlight-example1.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ \snippet 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:
+
+ \image trafficlight-example2.png
+ \omit
+ \caption This is a caption
+ \endomit
+
+ \snippet statemachine/trafficlight/main.cpp 4
+
+ The main() function constructs a TrafficLight and shows it.
+
+*/
diff --git a/examples/widgets/doc/transformations.qdoc b/examples/widgets/doc/transformations.qdoc
new file mode 100644
index 0000000000..79681a2799
--- /dev/null
+++ b/examples/widgets/doc/transformations.qdoc
@@ -0,0 +1,371 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example painting/transformations
+ \title Transformations Example
+
+ The Transformations example shows how transformations influence
+ the way that QPainter renders graphics primitives. In particular
+ it shows how the order of transformations affect the result.
+
+ \image transformations-example.png
+
+ The application allows the user to manipulate the rendering of a
+ shape by changing the translation, rotation and scale of
+ QPainter's coordinate system.
+
+ The example consists of two classes and a global enum:
+
+ \list
+ \li The \c RenderArea class controls the rendering of a given shape.
+ \li The \c Window class is the application's main window.
+ \li The \c Operation enum describes the various transformation
+ operations available in the application.
+ \endlist
+
+ First we will take a quick look at the \c Operation enum, then we
+ will review the \c RenderArea class to see how a shape is
+ rendered. Finally, we will take a look at the Transformations
+ application's features implemented in the \c Window class.
+
+ \section1 Transformation Operations
+
+ Normally, the QPainter operates on the associated device's own
+ coordinate system, but it also has good support for coordinate
+ transformations.
+
+ The default coordinate system of a paint device has its origin at
+ the top-left corner. The x values increase to the right and the y
+ values increase downwards. You can scale the coordinate system by
+ a given offset using the QPainter::scale() function, you can
+ rotate it clockwise using the QPainter::rotate() function and you
+ can translate it (i.e. adding a given offset to the points) using
+ the QPainter::translate() function. You can also twist the
+ coordinate system around the origin (called shearing) using the
+ QPainter::shear() function.
+
+ All the tranformation operations operate on QPainter's
+ tranformation matrix that you can retrieve using the
+ QPainter::worldTransform() function. A matrix transforms a point in the
+ plane to another point. For more information about the
+ transformation matrix, see the \l {Coordinate System} and
+ QTransform documentation.
+
+ \snippet painting/transformations/renderarea.h 0
+
+ The global \c Operation enum is declared in the \c renderarea.h
+ file and describes the various transformation operations available
+ in the Transformations application.
+
+ \section1 RenderArea Class Definition
+
+ The \c RenderArea class inherits QWidget, and controls the
+ rendering of a given shape.
+
+ \snippet painting/transformations/renderarea.h 1
+
+ We declare two public functions, \c setOperations() and
+ \c setShape(), to be able to specify the \c RenderArea widget's shape
+ and to transform the coordinate system the shape is rendered
+ within.
+
+ We reimplement the QWidget's \l
+ {QWidget::minimumSizeHint()}{minimumSizeHint()} and \l
+ {QWidget::sizeHint()}{sizeHint()} functions to give the \c
+ RenderArea widget a reasonable size within our application, and we
+ reimplement the QWidget::paintEvent() event handler to draw the
+ render area's shape applying the user's transformation choices.
+
+ \snippet painting/transformations/renderarea.h 2
+
+ We also declare several convenience functions to draw the shape,
+ the coordinate system's outline and the coordinates, and to
+ transform the painter according to the chosen transformations.
+
+ In addition, the \c RenderArea widget keeps a list of the
+ currently applied transformation operations, a reference to its
+ shape, and a couple of convenience variables that we will use when
+ rendering the coordinates.
+
+ \section1 RenderArea Class Implementation
+
+ The \c RenderArea widget controls the rendering of a given shape,
+ including the transformations of the coordinate system, by
+ reimplementing the QWidget::paintEvent() event handler. But first
+ we will take a quick look at the constructor and at the functions
+ that provides access to the \c RenderArea widget:
+
+ \snippet painting/transformations/renderarea.cpp 0
+
+ In the constructor we pass the parent parameter on to the base
+ class, and customize the font that we will use to render the
+ coordinates. The QWidget::font() function returns the font
+ currently set for the widget. As long as no special font has been
+ set, or after QWidget::setFont() is called, this is either a
+ special font for the widget class, the parent's font or (if this
+ widget is a top level widget) the default application font.
+
+ After ensuring that the font's size is 12 points, we extract the
+ rectangles enclosing the coordinate letters, 'x' and 'y', using the
+ QFontMetrics class.
+
+ QFontMetrics provides functions to access the individual metrics
+ of the font, its characters, and for strings rendered in the
+ font. The QFontMetrics::boundingRect() function returns the
+ bounding rectangle of the given character relative to the
+ left-most point on the base line.
+
+ \snippet painting/transformations/renderarea.cpp 1
+ \codeline
+ \snippet painting/transformations/renderarea.cpp 2
+
+ In the \c setShape() and \c setOperations() functions we update
+ the \c RenderArea widget by storing the new value or values
+ followed by a call to the QWidget::update() slot which schedules a
+ paint event for processing when Qt returns to the main event loop.
+
+ \snippet painting/transformations/renderarea.cpp 3
+ \codeline
+ \snippet painting/transformations/renderarea.cpp 4
+
+ We reimplement the QWidget's \l
+ {QWidget::minimumSizeHint()}{minimumSizeHint()} and \l
+ {QWidget::sizeHint()}{sizeHint()} functions to give the \c
+ RenderArea widget a reasonable size within our application. The
+ default implementations of these functions returns an invalid size
+ if there is no layout for this widget, and returns the layout's
+ minimum size or preferred size, respectively, otherwise.
+
+ \snippet painting/transformations/renderarea.cpp 5
+
+ The \c paintEvent() event handler receives the \c RenderArea
+ widget's paint events. A paint event is a request to repaint all
+ or part of the widget. It can happen as a result of
+ QWidget::repaint() or QWidget::update(), or because the widget was
+ obscured and has now been uncovered, or for many other reasons.
+
+ First we create a QPainter for the \c RenderArea widget. The \l
+ {QPainter::RenderHint}{QPainter::Antialiasing} render hint
+ indicates that the engine should antialias edges of primitives if
+ possible. Then we erase the area that needs to be repainted using
+ the QPainter::fillRect() function.
+
+ We also translate the coordinate system with an constant offset to
+ ensure that the original shape is renderend with a suitable
+ margin.
+
+ \snippet painting/transformations/renderarea.cpp 6
+
+ Before we start to render the shape, we call the QPainter::save()
+ function.
+
+ QPainter::save() saves the current painter state (i.e. pushes the
+ state onto a stack) including the current coordinate system. The
+ rationale for saving the painter state is that the following call
+ to the \c transformPainter() function will transform the
+ coordinate system depending on the currently chosen transformation
+ operations, and we need a way to get back to the original state to
+ draw the outline.
+
+ After transforming the coordinate system, we draw the \c
+ RenderArea's shape, and then we restore the painter state using
+ the QPainter::restore() function (i.e. popping the saved state off
+ the stack).
+
+ \snippet painting/transformations/renderarea.cpp 7
+
+ Then we draw the square outline.
+
+ \snippet painting/transformations/renderarea.cpp 8
+
+ Since we want the coordinates to correspond with the coordinate
+ system the shape is rendered within, we must make another call to
+ the \c transformPainter() function.
+
+ The order of the painting operations is essential with respect to
+ the shared pixels. The reason why we don't render the coordinates
+ when the coordinate system already is transformed to render the
+ shape, but instead defer their rendering to the end, is that we
+ want the coordinates to appear on top of the shape and its
+ outline.
+
+ There is no need to save the QPainter state this time since
+ drawing the coordinates is the last painting operation.
+
+ \snippet painting/transformations/renderarea.cpp 9
+ \codeline
+ \snippet painting/transformations/renderarea.cpp 10
+ \codeline
+ \snippet painting/transformations/renderarea.cpp 11
+
+ The \c drawCoordinates(), \c drawOutline() and \c drawShape() are
+ convenience functions called from the \c paintEvent() event
+ handler. For more information about QPainter's basic drawing
+ operations and how to display basic graphics primitives, see the
+ \l {painting/basicdrawing}{Basic Drawing} example.
+
+ \snippet painting/transformations/renderarea.cpp 12
+
+ The \c transformPainter() convenience function is also called from
+ the \c paintEvent() event handler, and transforms the given
+ QPainter's coordinate system according to the user's
+ transformation choices.
+
+ \section1 Window Class Definition
+
+ The \c Window class is the Transformations application's main
+ window.
+
+ The application displays four \c RenderArea widgets. The left-most
+ widget renders the shape in QPainter's default coordinate system,
+ the others render the shape with the chosen transformation in
+ addition to all the transformations applied to the \c RenderArea
+ widgets to their left.
+
+ \snippet painting/transformations/window.h 0
+
+ We declare two public slots to make the application able to
+ respond to user interaction, updating the displayed \c RenderArea
+ widgets according to the user's transformation choices.
+
+ The \c operationChanged() slot updates each of the \c RenderArea
+ widgets applying the currently chosen transformation operations, and
+ is called whenever the user changes the selected operations. The
+ \c shapeSelected() slot updates the \c RenderArea widgets' shapes
+ whenever the user changes the preferred shape.
+
+ \snippet painting/transformations/window.h 1
+
+ We also declare a private convenience function, \c setupShapes(),
+ that is used when constructing the \c Window widget, and we
+ declare pointers to the various components of the widget. We
+ choose to keep the available shapes in a QList of \l
+ {QPainterPath}s. In addition we declare a private enum counting
+ the number of displayed \c RenderArea widgets except the widget
+ that renders the shape in QPainter's default coordinate system.
+
+ \section1 Window Class Implementation
+
+ In the constructor we create and initialize the application's
+ components:
+
+ \snippet painting/transformations/window.cpp 0
+
+ First we create the \c RenderArea widget that will render the
+ shape in the default coordinate system. We also create the
+ associated QComboBox that allows the user to choose among four
+ different shapes: A clock, a house, a text and a truck. The shapes
+ themselves are created at the end of the constructor, using the
+ \c setupShapes() convenience function.
+
+ \snippet painting/transformations/window.cpp 1
+
+ Then we create the \c RenderArea widgets that will render their
+ shapes with coordinate tranformations. By default the applied
+ operation is \uicontrol {No Transformation}, i.e. the shapes are
+ rendered within the default coordinate system. We create and
+ initialize the associated \l {QComboBox}es with items
+ corresponding to the various transformation operations decribed by
+ the global \c Operation enum.
+
+ We also connect the \l {QComboBox}es' \l
+ {QComboBox::activated()}{activated()} signal to the \c
+ operationChanged() slot to update the application whenever the
+ user changes the selected transformation operations.
+
+ \snippet painting/transformations/window.cpp 2
+
+ Finally, we set the layout for the application window using the
+ QWidget::setLayout() function, construct the available shapes
+ using the private \c setupShapes() convenience function, and make
+ the application show the clock shape on startup using the public
+ \c shapeSelected() slot before we set the window title.
+
+
+ \snippet painting/transformations/window.cpp 3
+ \snippet painting/transformations/window.cpp 4
+ \snippet painting/transformations/window.cpp 5
+ \snippet painting/transformations/window.cpp 6
+ \dots
+
+ \snippet painting/transformations/window.cpp 7
+
+ The \c setupShapes() function is called from the constructor and
+ create the QPainterPath objects representing the shapes that are
+ used in the application. For construction details, see the \l
+ {painting/transformations/window.cpp}{window.cpp} example
+ file. The shapes are stored in a QList. The QList::append()
+ function inserts the given shape at the end of the list.
+
+ We also connect the associated QComboBox's \l
+ {QComboBox::activated()}{activated()} signal to the \c
+ shapeSelected() slot to update the application when the user
+ changes the preferred shape.
+
+ \snippet painting/transformations/window.cpp 8
+
+ The public \c operationChanged() slot is called whenever the user
+ changes the selected operations.
+
+ We retrieve the chosen transformation operation for each of the
+ transformed \c RenderArea widgets by querying the associated \l
+ {QComboBox}{QComboBoxes}. The transformed \c RenderArea widgets
+ are supposed to render the shape with the transformation specified
+ by its associated combobox \e {in addition to} all the
+ transformations applied to the \c RenderArea widgets to its
+ left. For that reason, for each widget we query, we append the
+ associated operation to a QList of transformations which we apply
+ to the widget before proceeding to the next.
+
+ \snippet painting/transformations/window.cpp 9
+
+ The \c shapeSelected() slot is called whenever the user changes
+ the preferred shape, updating the \c RenderArea widgets using
+ their public \c setShape() function.
+
+ \section1 Summary
+
+ The Transformations example shows how transformations influence
+ the way that QPainter renders graphics primitives. Normally, the
+ QPainter operates on the device's own coordinate system, but it
+ also has good support for coordinate transformations. With the
+ Transformations application you can scale, rotate and translate
+ QPainter's coordinate system. The order in which these
+ tranformations are applied is essential for the result.
+
+ All the tranformation operations operate on QPainter's
+ tranformation matrix. For more information about the
+ transformation matrix, see the \l {Coordinate System} and
+ QTransform documentation.
+
+ The Qt reference documentation provides several painting
+ examples. Among these is the \l {painting/affine}{Affine
+ Transformations} example that shows Qt's ability to perform
+ transformations on painting operations. The example also allows the
+ user to experiment with the various transformation operations.
+*/
diff --git a/examples/widgets/doc/trivialwizard.qdoc b/examples/widgets/doc/trivialwizard.qdoc
new file mode 100644
index 0000000000..e27f9cadc2
--- /dev/null
+++ b/examples/widgets/doc/trivialwizard.qdoc
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example dialogs/trivialwizard
+ \title Trivial Wizard Example
+
+ The Trivial Wizard example illustrates how to create a linear three-page
+ registration wizard using three instances of QWizardPage and one instance
+ of QWizard.
+
+ \image trivialwizard-example-flow.png
+
+ \section1 Introduction Page
+
+ \image trivialwizard-example-introduction.png
+
+ The introduction page is created with the \c createIntroPage()
+ function where a QWizardPage is created and its title is set to
+ "Introduction". A QLabel is used to hold the description of \c page.
+ A QVBoxLayout is used to hold the \c label. This \c page is returned
+ when the \c createIntroPage() function is called.
+
+ \snippet dialogs/trivialwizard/trivialwizard.cpp 0
+
+ \section1 Registration Page
+
+ \image trivialwizard-example-registration.png
+
+ The registration page is created with the \c createRegistrationPage()
+ function. QLineEdit objects are used to allow the user to input a name
+ and an e-mail address. A QGridLayout is used to hold the QLabel and
+ QLineEdit objects.
+
+ \snippet dialogs/trivialwizard/trivialwizard.cpp 2
+
+ \section1 Conclusion Page
+
+ \image trivialwizard-example-conclusion.png
+
+ The conclusion page is created in the \c createConclusionPage()
+ function. This function's content is similar to \c createIntroPage(). A
+ QLabel is used to inform the user that the registration process has
+ completed successfully.
+
+ \snippet dialogs/trivialwizard/trivialwizard.cpp 6
+
+ \section1 \c main() Function
+
+ The \c main() function instantiates a QWizard object, \c wizard, and
+ adds all three QWizardPage objects to it. The \c wizard window title is
+ set to "Trivial Wizard" and its \c show() function is invoked to display
+ it.
+
+ \snippet dialogs/trivialwizard/trivialwizard.cpp 10
+
+ \sa QWizard, {Class Wizard Example}, {License Wizard Example}
+*/
diff --git a/examples/widgets/doc/twowaybutton.qdoc b/examples/widgets/doc/twowaybutton.qdoc
new file mode 100644
index 0000000000..40f8c6f1f3
--- /dev/null
+++ b/examples/widgets/doc/twowaybutton.qdoc
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \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 statemachine/twowaybutton/main.cpp 0
+
+ The application's main() function begins by constructing the application
+ object, a button and a state machine.
+
+ \snippet 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 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 statemachine/twowaybutton/main.cpp 3
+
+ The states are added to the state machine; they become top-level (sibling)
+ states.
+
+ \snippet 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 statemachine/twowaybutton/main.cpp 5
+
+ Finally, the button is resized and made visible, and the application event
+ loop is entered.
+
+*/
diff --git a/examples/widgets/doc/wiggly.qdoc b/examples/widgets/doc/wiggly.qdoc
new file mode 100644
index 0000000000..e84ab00e61
--- /dev/null
+++ b/examples/widgets/doc/wiggly.qdoc
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/wiggly
+ \title Wiggly Example
+
+ The Wiggly example shows how to animate a widget using
+ QBasicTimer and \l{QObject::timerEvent()}{timerEvent()}. In
+ addition, the example demonstrates how to use QFontMetrics to
+ determine the size of text on screen.
+
+ \image wiggly-example.png Screenshot of the Wiggly example
+
+ QBasicTimer is a low-level class for timers. Unlike QTimer,
+ QBasicTimer doesn't inherit from QObject; instead of emitting a
+ \l{QTimer::timeout()}{timeout()} signal when a certain amount of
+ time has passed, it sends a QTimerEvent to a QObject of our
+ choice. This makes QBasicTimer a more lightweight alternative to
+ QTimer. Qt's built-in widgets use it internally, and it is
+ provided in Qt's API for highly-optimized applications (e.g.,
+ \l{Qt for Embedded Linux} applications).
+
+ The example consists of two classes:
+
+ \list
+ \li \c WigglyWidget is the custom widget displaying the text
+ in a wiggly line.
+
+ \li \c Dialog is the dialog widget allowing the user to enter a
+ text. It combines a \c WigglyWidget and a \c QLineEdit.
+ \endlist
+
+ We will first take a quick look at the \c Dialog class, then we
+ will review the \c WigglyWidget class.
+
+ \section1 Dialog Class Definition
+
+ \snippet widgets/wiggly/dialog.h 0
+
+ The \c Dialog class provides a dialog widget that allows the user
+ to enter a text. The text is then rendered by \c WigglyWidget.
+
+ \section1 Dialog Class Implementation
+
+ \snippet widgets/wiggly/dialog.cpp 0
+
+ In the constructor we create a wiggly widget along with a
+ \l{QLineEdit}{line edit}, and we put the two widgets in a
+ vertical layout. We connect the line edit's \l
+ {QLineEdit::textChanged()}{textChanged()} signal to the wiggly
+ widget's \c setText() slot to obtain the real time interaction
+ with the wiggly widget. The widget's default text is "Hello
+ world!".
+
+ \section1 WigglyWidget Class Definition
+
+ \snippet widgets/wiggly/wigglywidget.h 0
+
+ The \c WigglyWidget class provides the wiggly line displaying the
+ text. We subclass QWidget and reimplement the standard \l
+ {QWidget::paintEvent()}{paintEvent()} and \l
+ {QObject::timerEvent()}{timerEvent()} functions to draw and update
+ the widget. In addition we implement a public \c setText() slot
+ that sets the widget's text.
+
+ The \c timer variable, of type QBasicTimer, is used to update the
+ widget at regular intervals, making the widget move. The \c text
+ variable is used to store the currently displayed text, and \c
+ step to calculate position and color for each character on the
+ wiggly line.
+
+ \section1 WigglyWidget Class Implementation
+
+ \snippet widgets/wiggly/wigglywidget.cpp 0
+
+ In the constructor, we make the widget's background slightly
+ lighter than the usual background using the QPalette::Midlight
+ color role. The background role defines the brush from the
+ widget's palette that Qt uses to paint the background. Then we
+ enlarge the widget's font with 20 points.
+
+ Finally we start the timer; the call to QBasicTimer::start()
+ makes sure that \e this particular wiggly widget will receive the
+ timer events generated when the timer times out (every 60
+ milliseconds).
+
+ \snippet widgets/wiggly/wigglywidget.cpp 1
+ \snippet widgets/wiggly/wigglywidget.cpp 2
+
+ The \c paintEvent() function is called whenever a QPaintEvent is
+ sent to the widget. Paint events are sent to widgets that need to
+ update themselves, for instance when part of a widget is exposed
+ because a covering widget was moved. For the wiggly widget, a
+ paint event will also be generated every 60 milliseconds from
+ the \c timerEvent() slot.
+
+ The \c sineTable represents y-values of the sine curve,
+ multiplied by 100. It is used to make the wiggly widget move
+ along the sine curve.
+
+ The QFontMetrics object provides information about the widget's
+ font. The \c x variable is the horizontal position where we start
+ drawing the text. The \c y variable is the vertical position of
+ the text's base line. Both variables are computed so that the
+ text is horizontally and vertically centered. To compute the base
+ line, we take into account the font's ascent (the height of the
+ font above the base line) and font's descent (the height of the
+ font below the base line). If the descent equals the ascent, they
+ cancel out each other and the base line is at \c height() / 2.
+
+ \snippet widgets/wiggly/wigglywidget.cpp 3
+ \snippet widgets/wiggly/wigglywidget.cpp 4
+
+ Each time the \c paintEvent() function is called, we create a
+ QPainter object \c painter to draw the contents of the widget.
+ For each character in \c text, we determine the color and the
+ position on the wiggly line based on \c step. In addition, \c x
+ is incremented by the character's width.
+
+ For simplicity, we assume that QFontMetrics::width(\c text)
+ returns the sum of the individual character widths
+ (QFontMetrics::width(\c text[i])). In practice, this is not
+ always the case because QFontMetrics::width(\c text) also takes
+ into account the kerning between certain letters (e.g., 'A' and
+ 'V'). The result is that the text isn't perfectly centered. You
+ can verify this by typing "AVAVAVAVAVAV" in the line edit.
+
+ \snippet widgets/wiggly/wigglywidget.cpp 5
+ \snippet widgets/wiggly/wigglywidget.cpp 6
+
+ The \c timerEvent() function receives all the timer events that
+ are generated for this widget. If a timer event is sent from the
+ widget's QBasicTimer, we increment \c step to make the text move,
+ and call QWidget::update() to refresh the display. Any other
+ timer event is passed on to the base class's implementation of
+ the \l{QWidget::timerEvent()}{timerEvent()} function.
+
+ The QWidget::update() slot does not cause an immediate repaint;
+ instead the slot schedules a paint event for processing when Qt
+ returns to the main event loop. The paint events are then handled
+ by \c{WigglyWidget}'s \c paintEvent() function.
+*/
diff --git a/examples/widgets/doc/windowflags.qdoc b/examples/widgets/doc/windowflags.qdoc
new file mode 100644
index 0000000000..e85842b30a
--- /dev/null
+++ b/examples/widgets/doc/windowflags.qdoc
@@ -0,0 +1,216 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example widgets/windowflags
+ \title Window Flags Example
+
+ The Window Flags example shows how to use the window flags
+ available in Qt.
+
+ A window flag is either a type or a hint. A type is used to
+ specify various window-system properties for the widget. A widget
+ can only have one type, and the default is Qt::Widget. However, a
+ widget can have zero or more hints. The hints are used to
+ customize the appearance of top-level windows.
+
+ A widget's flags are stored in a Qt::WindowFlags type which stores
+ an OR combination of the flags.
+
+ \image windowflags-example.png Screenshot of the Window Flags example
+
+ The example consists of two classes:
+
+ \list
+ \li \c ControllerWindow is the main application widget that allows
+ the user to choose among the available window flags, and displays
+ the effect on a separate preview window.
+ \li \c PreviewWindow is a custom widget displaying the name of
+ its currently set window flags in a read-only text editor.
+ \endlist
+
+ We will start by reviewing the \c ControllerWindow class, then we
+ will take a look at the \c PreviewWindow class.
+
+ \section1 ControllerWindow Class Definition
+
+ \snippet widgets/windowflags/controllerwindow.h 0
+
+ The \c ControllerWindow class inherits QWidget. The widget allows
+ the user to choose among the available window flags, and displays
+ the effect on a separate preview window.
+
+ We declare a private \c updatePreview() slot to refresh the
+ preview window whenever the user changes the window flags.
+
+ We also declare several private functions to simplify the
+ constructor: We call the \c createTypeGroupBox() function to
+ create a radio button for each available window type, using the
+ private \c createButton() function, and gather them within a group
+ box. In a similar way we use the \c createHintsGroupBox() function
+ to create a check box for each available hint, using the private
+ \c createCheckBox() function.
+
+ In addition to the various radio buttons and checkboxes, we need
+ an associated \c PreviewWindow to show the effect of the currently
+ chosen window flags.
+
+ \image windowflags_controllerwindow.png Screenshot of the Controller Window
+
+ \section1 ControllerWindow Class Implementation
+
+ \snippet widgets/windowflags/controllerwindow.cpp 0
+
+ In the constructor we first create the preview window. Then we
+ create the group boxes containing the available window flags using
+ the private \c createTypeGroupBox() and \c createHintsGroupBox()
+ functions. In addition we create a \uicontrol Quit button. We put the
+ button and a stretchable space in a separate layout to make the
+ button appear in the \c WindowFlag widget's right bottom corner.
+
+ Finally, we add the button's layout and the two goup boxes to a
+ QVBoxLayout, set the window title and refresh the preview window
+ using the \c updatePreview() slot.
+
+ \snippet widgets/windowflags/controllerwindow.cpp 1
+ \snippet widgets/windowflags/controllerwindow.cpp 2
+
+ The \c updatePreview() slot is called whenever the user changes
+ any of the window flags. First we create an empty Qt::WindowFlags
+ \c flags, then we determine which one of the types that is checked
+ and add it to \c flags.
+
+ \snippet widgets/windowflags/controllerwindow.cpp 3
+
+ We also determine which of the hints that are checked, and add
+ them to \c flags using an OR operator. We use \c flags to set the
+ window flags for the preview window.
+
+ \snippet widgets/windowflags/controllerwindow.cpp 4
+
+ We adjust the position of the preview window. The reason we do
+ that, is that playing around with the window's frame may on some
+ platforms cause the window's position to be changed behind our
+ back. If a window is located in the upper left corner of the
+ screen, parts of the window may not be visible. So we adjust the
+ widget's position to make sure that, if this happens, the window
+ is moved within the screen's boundaries. Finally, we call
+ QWidget::show() to make sure the preview window is visible.
+
+ \omit
+ \skipto pos
+ \printuntil /^\}/
+ \endomit
+
+ \snippet widgets/windowflags/controllerwindow.cpp 5
+
+ The private \c createTypeGroupBox() function is called from the
+ constructor.
+
+ First we create a group box, and then we create a radio button
+ (using the private \c createRadioButton() function) for each of
+ the available types among the window flags. We make Qt::Window the
+ initially applied type. We put the radio buttons into a
+ QGridLayout and install the layout on the group box.
+
+ We do not include the default Qt::Widget type. The reason is that
+ it behaves somewhat different than the other types. If the type is
+ not specified for a widget, and it has no parent, the widget is a
+ window. However, if it has a parent, it is a standard child
+ widget. The other types are all top-level windows, and since the
+ hints only affect top-level windows, we abandon the Qt::Widget
+ type.
+
+ \snippet widgets/windowflags/controllerwindow.cpp 6
+
+ The private \c createHintsGroupBox() function is also called from
+ the constructor.
+
+ Again, the first thing we do is to create a group box. Then we
+ create a checkbox, using the private \c createCheckBox() function,
+ for each of the available hints among the window flags. We put the
+ checkboxes into a QGridLayout and install the layout on the group
+ box.
+
+ \snippet widgets/windowflags/controllerwindow.cpp 7
+
+ The private \c createCheckBox() function is called from \c
+ createHintsGroupBox().
+
+ We simply create a QCheckBox with the provided text, connect it to
+ the private \c updatePreview() slot, and return a pointer to the
+ checkbox.
+
+ \snippet widgets/windowflags/controllerwindow.cpp 8
+
+ In the private \c createRadioButton() function it is a
+ QRadioButton we create with the provided text, and connect to the
+ private \c updatePreview() slot. The function is called from \c
+ createTypeGroupBox(), and returns a pointer to the button.
+
+ \section1 PreviewWindow Class Definition
+
+ \snippet widgets/windowflags/previewwindow.h 0
+
+ The \c PreviewWindow class inherits QWidget. It is a custom widget
+ that displays the names of its currently set window flags in a
+ read-only text editor. It is also provided with a QPushbutton that
+ closes the window.
+
+ We reimplement the constructor to create the \uicontrol Close button and
+ the text editor, and the QWidget::setWindowFlags() function to
+ display the names of the window flags.
+
+ \image windowflags_previewwindow.png Screenshot of the Preview Window
+
+ \section1 PreviewWindow Class Implementation
+
+ \snippet widgets/windowflags/previewwindow.cpp 0
+
+ In the constructor, we first create a QTextEdit and make sure that
+ it is read-only.
+
+ We also prohibit any line wrapping in the text editor using the
+ QTextEdit::setLineWrapMode() function. The result is that a
+ horizontal scrollbar appears when a window flag's name exceeds the
+ width of the editor. This is a reasonable solution since we
+ construct the displayed text with built-in line breaks. If no line
+ breaks were guaranteed, using another QTextEdit::LineWrapMode
+ would perhaps make more sense.
+
+ Then we create the \uicontrol Close button, and put both the widgets
+ into a QVBoxLayout before we set the window title.
+
+ \snippet widgets/windowflags/previewwindow.cpp 1
+
+ In our reimplementation of the \c setWindowFlags() function, we
+ first set the widgets flags using the QWidget::setWindowFlags()
+ function. Then we run through the available window flags, creating
+ a text that contains the names of the flags that matches the \c
+ flags parameter. Finally, we display the text in the widgets text
+ editor.
+*/
diff --git a/examples/widgets/draganddrop/README b/examples/widgets/draganddrop/README
new file mode 100644
index 0000000000..90dc55bf2f
--- /dev/null
+++ b/examples/widgets/draganddrop/README
@@ -0,0 +1,9 @@
+Qt supports native drag and drop on all platforms via an extensible
+MIME-based system that enables applications to send data to each other in the
+most appropriate formats.
+
+Drag and drop can also be implemented for internal use by applications.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/draganddrop/delayedencoding/delayedencoding.desktop b/examples/widgets/draganddrop/delayedencoding/delayedencoding.desktop
new file mode 100644
index 0000000000..629c497b6b
--- /dev/null
+++ b/examples/widgets/draganddrop/delayedencoding/delayedencoding.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Delayed Encoding
+Exec=/opt/usr/bin/delayedencoding
+Icon=delayedencoding
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/draganddrop/draganddrop.pro b/examples/widgets/draganddrop/draganddrop.pro
new file mode 100644
index 0000000000..a209ae31e4
--- /dev/null
+++ b/examples/widgets/draganddrop/draganddrop.pro
@@ -0,0 +1,13 @@
+TEMPLATE = subdirs
+SUBDIRS = draggableicons \
+ draggabletext \
+ dropsite \
+ fridgemagnets \
+ puzzle
+
+wince*: SUBDIRS -= dropsite
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop
+INSTALLS += sources
+QT += widgets
diff --git a/examples/widgets/draganddrop/draggableicons/draggableicons.desktop b/examples/widgets/draganddrop/draggableicons/draggableicons.desktop
new file mode 100644
index 0000000000..d14f758ce6
--- /dev/null
+++ b/examples/widgets/draganddrop/draggableicons/draggableicons.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Draggable Icons
+Exec=/opt/usr/bin/draggableicons
+Icon=draggableicons
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/draganddrop/draggableicons/draggableicons.pro b/examples/widgets/draganddrop/draggableicons/draggableicons.pro
new file mode 100644
index 0000000000..9f4156135f
--- /dev/null
+++ b/examples/widgets/draganddrop/draggableicons/draggableicons.pro
@@ -0,0 +1,12 @@
+HEADERS = dragwidget.h
+RESOURCES = draggableicons.qrc
+SOURCES = dragwidget.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/draggableicons
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/draggableicons
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/draganddrop/draggableicons/draggableicons.qrc b/examples/widgets/draganddrop/draggableicons/draggableicons.qrc
new file mode 100644
index 0000000000..63f84ac066
--- /dev/null
+++ b/examples/widgets/draganddrop/draggableicons/draggableicons.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="">
+ <file>images/boat.png</file>
+ <file>images/car.png</file>
+ <file>images/house.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/draganddrop/draggableicons/dragwidget.cpp b/examples/widgets/draganddrop/draggableicons/dragwidget.cpp
new file mode 100644
index 0000000000..93a02a4647
--- /dev/null
+++ b/examples/widgets/draganddrop/draggableicons/dragwidget.cpp
@@ -0,0 +1,168 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "dragwidget.h"
+
+//! [0]
+DragWidget::DragWidget(QWidget *parent)
+ : QFrame(parent)
+{
+ setMinimumSize(200, 200);
+ setFrameStyle(QFrame::Sunken | QFrame::StyledPanel);
+ setAcceptDrops(true);
+
+ QLabel *boatIcon = new QLabel(this);
+ boatIcon->setPixmap(QPixmap(":/images/boat.png"));
+ boatIcon->move(10, 10);
+ boatIcon->show();
+ boatIcon->setAttribute(Qt::WA_DeleteOnClose);
+
+ QLabel *carIcon = new QLabel(this);
+ carIcon->setPixmap(QPixmap(":/images/car.png"));
+ carIcon->move(100, 10);
+ carIcon->show();
+ carIcon->setAttribute(Qt::WA_DeleteOnClose);
+
+ QLabel *houseIcon = new QLabel(this);
+ houseIcon->setPixmap(QPixmap(":/images/house.png"));
+ houseIcon->move(10, 80);
+ houseIcon->show();
+ houseIcon->setAttribute(Qt::WA_DeleteOnClose);
+}
+//! [0]
+
+void DragWidget::dragEnterEvent(QDragEnterEvent *event)
+{
+ if (event->mimeData()->hasFormat("application/x-dnditemdata")) {
+ if (event->source() == this) {
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else {
+ event->acceptProposedAction();
+ }
+ } else {
+ event->ignore();
+ }
+}
+
+void DragWidget::dragMoveEvent(QDragMoveEvent *event)
+{
+ if (event->mimeData()->hasFormat("application/x-dnditemdata")) {
+ if (event->source() == this) {
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else {
+ event->acceptProposedAction();
+ }
+ } else {
+ event->ignore();
+ }
+}
+
+void DragWidget::dropEvent(QDropEvent *event)
+{
+ if (event->mimeData()->hasFormat("application/x-dnditemdata")) {
+ QByteArray itemData = event->mimeData()->data("application/x-dnditemdata");
+ QDataStream dataStream(&itemData, QIODevice::ReadOnly);
+
+ QPixmap pixmap;
+ QPoint offset;
+ dataStream >> pixmap >> offset;
+
+ QLabel *newIcon = new QLabel(this);
+ newIcon->setPixmap(pixmap);
+ newIcon->move(event->pos() - offset);
+ newIcon->show();
+ newIcon->setAttribute(Qt::WA_DeleteOnClose);
+
+ if (event->source() == this) {
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else {
+ event->acceptProposedAction();
+ }
+ } else {
+ event->ignore();
+ }
+}
+
+//! [1]
+void DragWidget::mousePressEvent(QMouseEvent *event)
+{
+ QLabel *child = static_cast<QLabel*>(childAt(event->pos()));
+ if (!child)
+ return;
+
+ QPixmap pixmap = *child->pixmap();
+
+ QByteArray itemData;
+ QDataStream dataStream(&itemData, QIODevice::WriteOnly);
+ dataStream << pixmap << QPoint(event->pos() - child->pos());
+//! [1]
+
+//! [2]
+ QMimeData *mimeData = new QMimeData;
+ mimeData->setData("application/x-dnditemdata", itemData);
+//! [2]
+
+//! [3]
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ drag->setPixmap(pixmap);
+ drag->setHotSpot(event->pos() - child->pos());
+//! [3]
+
+ QPixmap tempPixmap = pixmap;
+ QPainter painter;
+ painter.begin(&tempPixmap);
+ painter.fillRect(pixmap.rect(), QColor(127, 127, 127, 127));
+ painter.end();
+
+ child->setPixmap(tempPixmap);
+
+ if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction)
+ child->close();
+ else {
+ child->show();
+ child->setPixmap(pixmap);
+ }
+}
diff --git a/examples/widgets/draganddrop/draggableicons/dragwidget.h b/examples/widgets/draganddrop/draggableicons/dragwidget.h
new file mode 100644
index 0000000000..b2fae51c5e
--- /dev/null
+++ b/examples/widgets/draganddrop/draggableicons/dragwidget.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DRAGWIDGET_H
+#define DRAGWIDGET_H
+
+#include <QFrame>
+
+QT_BEGIN_NAMESPACE
+class QDragEnterEvent;
+class QDropEvent;
+QT_END_NAMESPACE
+
+//! [0]
+class DragWidget : public QFrame
+{
+public:
+ DragWidget(QWidget *parent=0);
+
+protected:
+ void dragEnterEvent(QDragEnterEvent *event);
+ void dragMoveEvent(QDragMoveEvent *event);
+ void dropEvent(QDropEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/draganddrop/draggableicons/images/boat.png b/examples/widgets/draganddrop/draggableicons/images/boat.png
new file mode 100644
index 0000000000..46c894f06b
--- /dev/null
+++ b/examples/widgets/draganddrop/draggableicons/images/boat.png
Binary files differ
diff --git a/examples/widgets/draganddrop/draggableicons/images/car.png b/examples/widgets/draganddrop/draggableicons/images/car.png
new file mode 100644
index 0000000000..3cb35e56cb
--- /dev/null
+++ b/examples/widgets/draganddrop/draggableicons/images/car.png
Binary files differ
diff --git a/examples/widgets/draganddrop/draggableicons/images/house.png b/examples/widgets/draganddrop/draggableicons/images/house.png
new file mode 100644
index 0000000000..ee9d5b1159
--- /dev/null
+++ b/examples/widgets/draganddrop/draggableicons/images/house.png
Binary files differ
diff --git a/examples/widgets/draganddrop/draggableicons/main.cpp b/examples/widgets/draganddrop/draggableicons/main.cpp
new file mode 100644
index 0000000000..5a7120c9d5
--- /dev/null
+++ b/examples/widgets/draganddrop/draggableicons/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QHBoxLayout>
+#include "dragwidget.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(draggableicons);
+
+ QApplication app(argc, argv);
+
+ QWidget mainWidget;
+ QHBoxLayout *horizontalLayout = new QHBoxLayout;
+ horizontalLayout->addWidget(new DragWidget);
+ horizontalLayout->addWidget(new DragWidget);
+
+ mainWidget.setLayout(horizontalLayout);
+ mainWidget.setWindowTitle(QObject::tr("Draggable Icons"));
+ mainWidget.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/draganddrop/draggabletext/draggabletext.desktop b/examples/widgets/draganddrop/draggabletext/draggabletext.desktop
new file mode 100644
index 0000000000..ceda807604
--- /dev/null
+++ b/examples/widgets/draganddrop/draggabletext/draggabletext.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Draggable Text
+Exec=/opt/usr/bin/draggabletext
+Icon=draggabletext
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/draganddrop/draggabletext/draggabletext.pro b/examples/widgets/draganddrop/draggabletext/draggabletext.pro
new file mode 100644
index 0000000000..1fd8e5ce6e
--- /dev/null
+++ b/examples/widgets/draganddrop/draggabletext/draggabletext.pro
@@ -0,0 +1,15 @@
+HEADERS = draglabel.h \
+ dragwidget.h
+RESOURCES = draggabletext.qrc
+SOURCES = draglabel.cpp \
+ dragwidget.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/draggabletext
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.txt *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/draggabletext
+INSTALLS += target sources
+
+QT += widgets
+
diff --git a/examples/widgets/draganddrop/draggabletext/draggabletext.qrc b/examples/widgets/draganddrop/draggabletext/draggabletext.qrc
new file mode 100644
index 0000000000..b72217d701
--- /dev/null
+++ b/examples/widgets/draganddrop/draggabletext/draggabletext.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/dictionary">
+ <file>words.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/draganddrop/draggabletext/draglabel.cpp b/examples/widgets/draganddrop/draggabletext/draglabel.cpp
new file mode 100644
index 0000000000..803e659157
--- /dev/null
+++ b/examples/widgets/draganddrop/draggabletext/draglabel.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "draglabel.h"
+
+DragLabel::DragLabel(const QString &text, QWidget *parent)
+ : QLabel(text, parent)
+{
+ setAutoFillBackground(true);
+ setFrameShape(QFrame::Panel);
+ setFrameShadow(QFrame::Raised);
+}
diff --git a/examples/widgets/draganddrop/draggabletext/draglabel.h b/examples/widgets/draganddrop/draggabletext/draglabel.h
new file mode 100644
index 0000000000..e067a37652
--- /dev/null
+++ b/examples/widgets/draganddrop/draggabletext/draglabel.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DRAGLABEL_H
+#define DRAGLABEL_H
+
+#include <QLabel>
+
+QT_BEGIN_NAMESPACE
+class QDragEnterEvent;
+class QDragMoveEvent;
+class QFrame;
+QT_END_NAMESPACE
+
+class DragLabel : public QLabel
+{
+public:
+ DragLabel(const QString &text, QWidget *parent);
+};
+
+#endif
diff --git a/examples/widgets/draganddrop/draggabletext/dragwidget.cpp b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp
new file mode 100644
index 0000000000..60d84ebb5b
--- /dev/null
+++ b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp
@@ -0,0 +1,165 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "draglabel.h"
+#include "dragwidget.h"
+
+DragWidget::DragWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ QFile dictionaryFile(":/dictionary/words.txt");
+ dictionaryFile.open(QIODevice::ReadOnly);
+ QTextStream inputStream(&dictionaryFile);
+
+ int x = 5;
+ int y = 5;
+
+ while (!inputStream.atEnd()) {
+ QString word;
+ inputStream >> word;
+ if (!word.isEmpty()) {
+ DragLabel *wordLabel = new DragLabel(word, this);
+ wordLabel->move(x, y);
+ wordLabel->show();
+ wordLabel->setAttribute(Qt::WA_DeleteOnClose);
+ x += wordLabel->width() + 2;
+ if (x >= 245) {
+ x = 5;
+ y += wordLabel->height() + 2;
+ }
+ }
+ }
+
+ /*
+ QPalette newPalette = palette();
+ newPalette.setColor(QPalette::Window, Qt::white);
+ setPalette(newPalette);
+ */
+
+ setAcceptDrops(true);
+ setMinimumSize(400, qMax(200, y));
+ setWindowTitle(tr("Draggable Text"));
+}
+
+void DragWidget::dragEnterEvent(QDragEnterEvent *event)
+{
+ if (event->mimeData()->hasText()) {
+ if (event->source() == this) {
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else {
+ event->acceptProposedAction();
+ }
+ } else {
+ event->ignore();
+ }
+}
+
+void DragWidget::dropEvent(QDropEvent *event)
+{
+ if (event->mimeData()->hasText()) {
+ const QMimeData *mime = event->mimeData();
+ QStringList pieces = mime->text().split(QRegExp("\\s+"),
+ QString::SkipEmptyParts);
+ QPoint position = event->pos();
+ QPoint hotSpot;
+
+ QList<QByteArray> hotSpotPos = mime->data("application/x-hotspot").split(' ');
+ if (hotSpotPos.size() == 2) {
+ hotSpot.setX(hotSpotPos.first().toInt());
+ hotSpot.setY(hotSpotPos.last().toInt());
+ }
+
+ foreach (QString piece, pieces) {
+ DragLabel *newLabel = new DragLabel(piece, this);
+ newLabel->move(position - hotSpot);
+ newLabel->show();
+ newLabel->setAttribute(Qt::WA_DeleteOnClose);
+
+ position += QPoint(newLabel->width(), 0);
+ }
+
+ if (event->source() == this) {
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else {
+ event->acceptProposedAction();
+ }
+ } else {
+ event->ignore();
+ }
+ foreach (QObject *child, children()) {
+ if (child->inherits("QWidget")) {
+ QWidget *widget = static_cast<QWidget *>(child);
+ if (!widget->isVisible())
+ widget->deleteLater();
+ }
+ }
+}
+
+void DragWidget::mousePressEvent(QMouseEvent *event)
+{
+ QLabel *child = static_cast<QLabel*>(childAt(event->pos()));
+ if (!child)
+ return;
+
+ QPoint hotSpot = event->pos() - child->pos();
+
+ QMimeData *mimeData = new QMimeData;
+ mimeData->setText(child->text());
+ mimeData->setData("application/x-hotspot",
+ QByteArray::number(hotSpot.x())
+ + " " + QByteArray::number(hotSpot.y()));
+
+ QPixmap pixmap(child->size());
+ child->render(&pixmap);
+
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ drag->setPixmap(pixmap);
+ drag->setHotSpot(hotSpot);
+
+ Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
+
+ if (dropAction == Qt::MoveAction)
+ child->close();
+}
diff --git a/examples/widgets/draganddrop/draggabletext/dragwidget.h b/examples/widgets/draganddrop/draggabletext/dragwidget.h
new file mode 100644
index 0000000000..deef7fe4dd
--- /dev/null
+++ b/examples/widgets/draganddrop/draggabletext/dragwidget.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DRAGWIDGET_H
+#define DRAGWIDGET_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QDragEnterEvent;
+class QDropEvent;
+QT_END_NAMESPACE
+
+class DragWidget : public QWidget
+{
+public:
+ DragWidget(QWidget *parent = 0);
+
+protected:
+ void dragEnterEvent(QDragEnterEvent *event);
+ void dropEvent(QDropEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+};
+
+#endif
diff --git a/examples/widgets/draganddrop/draggabletext/main.cpp b/examples/widgets/draganddrop/draggabletext/main.cpp
new file mode 100644
index 0000000000..3c57afff6a
--- /dev/null
+++ b/examples/widgets/draganddrop/draggabletext/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "dragwidget.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(draggabletext);
+
+ QApplication app(argc, argv);
+ DragWidget window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/draganddrop/draggabletext/words.txt b/examples/widgets/draganddrop/draggabletext/words.txt
new file mode 100644
index 0000000000..19b8b0325b
--- /dev/null
+++ b/examples/widgets/draganddrop/draggabletext/words.txt
@@ -0,0 +1,41 @@
+Qt
+Quarterly
+is
+a
+paper
+based
+newsletter
+exclusively
+available
+to
+Qt
+customers
+Every
+quarter
+we
+mail
+out
+an
+issue
+that
+we
+hope
+will
+bring
+added
+insight
+and
+pleasure
+to
+your
+Qt
+programming
+with
+high
+quality
+technical
+articles
+written
+by
+Qt
+experts
diff --git a/examples/widgets/draganddrop/dropsite/droparea.cpp b/examples/widgets/draganddrop/dropsite/droparea.cpp
new file mode 100644
index 0000000000..95bbd3000c
--- /dev/null
+++ b/examples/widgets/draganddrop/dropsite/droparea.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "droparea.h"
+
+//! [DropArea constructor]
+DropArea::DropArea(QWidget *parent)
+ : QLabel(parent)
+{
+ setMinimumSize(200, 200);
+ setFrameStyle(QFrame::Sunken | QFrame::StyledPanel);
+ setAlignment(Qt::AlignCenter);
+ setAcceptDrops(true);
+ setAutoFillBackground(true);
+ clear();
+}
+//! [DropArea constructor]
+
+//! [dragEnterEvent() function]
+void DropArea::dragEnterEvent(QDragEnterEvent *event)
+{
+ setText(tr("<drop content>"));
+ setBackgroundRole(QPalette::Highlight);
+
+ event->acceptProposedAction();
+ emit changed(event->mimeData());
+}
+//! [dragEnterEvent() function]
+
+//! [dragMoveEvent() function]
+void DropArea::dragMoveEvent(QDragMoveEvent *event)
+{
+ event->acceptProposedAction();
+}
+//! [dragMoveEvent() function]
+
+//! [dropEvent() function part1]
+void DropArea::dropEvent(QDropEvent *event)
+{
+ const QMimeData *mimeData = event->mimeData();
+//! [dropEvent() function part1]
+
+//! [dropEvent() function part2]
+ if (mimeData->hasImage()) {
+ setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
+ } else if (mimeData->hasHtml()) {
+ setText(mimeData->html());
+ setTextFormat(Qt::RichText);
+ } else if (mimeData->hasText()) {
+ setText(mimeData->text());
+ setTextFormat(Qt::PlainText);
+ } else if (mimeData->hasUrls()) {
+ QList<QUrl> urlList = mimeData->urls();
+ QString text;
+ for (int i = 0; i < urlList.size() && i < 32; ++i) {
+ QString url = urlList.at(i).path();
+ text += url + QString("\n");
+ }
+ setText(text);
+ } else {
+ setText(tr("Cannot display data"));
+ }
+//! [dropEvent() function part2]
+
+//! [dropEvent() function part3]
+ setBackgroundRole(QPalette::Dark);
+ event->acceptProposedAction();
+}
+//! [dropEvent() function part3]
+
+//! [dragLeaveEvent() function]
+void DropArea::dragLeaveEvent(QDragLeaveEvent *event)
+{
+ clear();
+ event->accept();
+}
+//! [dragLeaveEvent() function]
+
+//! [clear() function]
+void DropArea::clear()
+{
+ setText(tr("<drop content>"));
+ setBackgroundRole(QPalette::Dark);
+
+ emit changed();
+}
+//! [clear() function]
diff --git a/examples/widgets/draganddrop/dropsite/droparea.h b/examples/widgets/draganddrop/dropsite/droparea.h
new file mode 100644
index 0000000000..e1586990df
--- /dev/null
+++ b/examples/widgets/draganddrop/dropsite/droparea.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DROPAREA_H
+#define DROPAREA_H
+
+#include <QLabel>
+
+QT_BEGIN_NAMESPACE
+class QMimeData;
+QT_END_NAMESPACE
+
+//! [DropArea header part1]
+class DropArea : public QLabel
+{
+ Q_OBJECT
+
+public:
+ DropArea(QWidget *parent = 0);
+
+public slots:
+ void clear();
+
+signals:
+ void changed(const QMimeData *mimeData = 0);
+//! [DropArea header part1]
+
+//! [DropArea header part2]
+protected:
+ void dragEnterEvent(QDragEnterEvent *event);
+ void dragMoveEvent(QDragMoveEvent *event);
+ void dragLeaveEvent(QDragLeaveEvent *event);
+ void dropEvent(QDropEvent *event);
+
+private:
+ QLabel *label;
+};
+//! [DropArea header part2]
+
+#endif
diff --git a/examples/widgets/draganddrop/dropsite/dropsite.desktop b/examples/widgets/draganddrop/dropsite/dropsite.desktop
new file mode 100644
index 0000000000..70a192f2b1
--- /dev/null
+++ b/examples/widgets/draganddrop/dropsite/dropsite.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Drop Site
+Exec=/opt/usr/bin/dropsite
+Icon=dropsite
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/draganddrop/dropsite/dropsite.pro b/examples/widgets/draganddrop/dropsite/dropsite.pro
new file mode 100644
index 0000000000..8198b19e79
--- /dev/null
+++ b/examples/widgets/draganddrop/dropsite/dropsite.pro
@@ -0,0 +1,14 @@
+HEADERS = droparea.h \
+ dropsitewindow.h
+SOURCES = droparea.cpp \
+ dropsitewindow.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/dropsite
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/dropsite
+INSTALLS += target sources
+
+QT += widgets
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
new file mode 100644
index 0000000000..f7fc5aa1ab
--- /dev/null
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "droparea.h"
+#include "dropsitewindow.h"
+
+//! [constructor part1]
+DropSiteWindow::DropSiteWindow()
+{
+ abstractLabel = new QLabel(tr("This example accepts drags from other "
+ "applications and displays the MIME types "
+ "provided by the drag object."));
+ abstractLabel->setWordWrap(true);
+ abstractLabel->adjustSize();
+//! [constructor part1]
+
+//! [constructor part2]
+ dropArea = new DropArea;
+ connect(dropArea, SIGNAL(changed(const QMimeData*)),
+ this, SLOT(updateFormatsTable(const QMimeData*)));
+//! [constructor part2]
+
+//! [constructor part3]
+ QStringList labels;
+ labels << tr("Format") << tr("Content");
+
+ formatsTable = new QTableWidget;
+ formatsTable->setColumnCount(2);
+ formatsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ formatsTable->setHorizontalHeaderLabels(labels);
+ formatsTable->horizontalHeader()->setStretchLastSection(true);
+//! [constructor part3]
+
+//! [constructor part4]
+ clearButton = new QPushButton(tr("Clear"));
+ quitButton = new QPushButton(tr("Quit"));
+
+ buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
+
+ connect(quitButton, SIGNAL(pressed()), this, SLOT(close()));
+ connect(clearButton, SIGNAL(pressed()), dropArea, SLOT(clear()));
+//! [constructor part4]
+
+//! [constructor part5]
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(abstractLabel);
+ mainLayout->addWidget(dropArea);
+ mainLayout->addWidget(formatsTable);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Drop Site"));
+ setMinimumSize(350, 500);
+}
+//! [constructor part5]
+
+//! [updateFormatsTable() part1]
+void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
+{
+ formatsTable->setRowCount(0);
+ if (!mimeData)
+ return;
+//! [updateFormatsTable() part1]
+
+//! [updateFormatsTable() part2]
+ foreach (QString format, mimeData->formats()) {
+ QTableWidgetItem *formatItem = new QTableWidgetItem(format);
+ formatItem->setFlags(Qt::ItemIsEnabled);
+ formatItem->setTextAlignment(Qt::AlignTop | Qt::AlignLeft);
+//! [updateFormatsTable() part2]
+
+//! [updateFormatsTable() part3]
+ QString text;
+ if (format == "text/plain") {
+ text = mimeData->text().simplified();
+ } else if (format == "text/html") {
+ text = mimeData->html().simplified();
+ } else if (format == "text/uri-list") {
+ QList<QUrl> urlList = mimeData->urls();
+ for (int i = 0; i < urlList.size() && i < 32; ++i)
+ text.append(urlList[i].toString() + " ");
+ } else {
+ QByteArray data = mimeData->data(format);
+ for (int i = 0; i < data.size() && i < 32; ++i) {
+ QString hex = QString("%1").arg(uchar(data[i]), 2, 16,
+ QChar('0'))
+ .toUpper();
+ text.append(hex + " ");
+ }
+ }
+//! [updateFormatsTable() part3]
+
+//! [updateFormatsTable() part4]
+ int row = formatsTable->rowCount();
+ formatsTable->insertRow(row);
+ formatsTable->setItem(row, 0, new QTableWidgetItem(format));
+ formatsTable->setItem(row, 1, new QTableWidgetItem(text));
+ }
+
+ formatsTable->resizeColumnToContents(0);
+}
+//! [updateFormatsTable() part4]
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.h b/examples/widgets/draganddrop/dropsite/dropsitewindow.h
new file mode 100644
index 0000000000..049e9593f4
--- /dev/null
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DROPSITEWINDOW_H
+#define DROPSITEWINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QLabel;
+class QMimeData;
+class QPushButton;
+class QTableWidget;
+QT_END_NAMESPACE
+class DropArea;
+
+//! [DropSiteWindow header]
+class DropSiteWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ DropSiteWindow();
+
+public slots:
+ void updateFormatsTable(const QMimeData *mimeData);
+
+private:
+ DropArea *dropArea;
+ QLabel *abstractLabel;
+ QTableWidget *formatsTable;
+
+ QPushButton *clearButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+};
+//! [DropSiteWindow header]
+
+#endif
diff --git a/examples/widgets/draganddrop/dropsite/main.cpp b/examples/widgets/draganddrop/dropsite/main.cpp
new file mode 100644
index 0000000000..f6220fa42e
--- /dev/null
+++ b/examples/widgets/draganddrop/dropsite/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "dropsitewindow.h"
+
+//! [main() function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ DropSiteWindow window;
+ window.show();
+ return app.exec();
+}
+//! [main() function]
diff --git a/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp b/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp
new file mode 100644
index 0000000000..a4e52ed635
--- /dev/null
+++ b/examples/widgets/draganddrop/fridgemagnets/draglabel.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "draglabel.h"
+
+//! [0]
+DragLabel::DragLabel(const QString &text, QWidget *parent)
+ : QLabel(parent)
+{
+ QFontMetrics metric(font());
+ QSize size = metric.size(Qt::TextSingleLine, text);
+
+ QImage image(size.width() + 12, size.height() + 12,
+ QImage::Format_ARGB32_Premultiplied);
+ image.fill(qRgba(0, 0, 0, 0));
+
+ QFont font;
+ font.setStyleStrategy(QFont::ForceOutline);
+//! [0]
+
+//! [1]
+ QLinearGradient gradient(0, 0, 0, image.height()-1);
+ gradient.setColorAt(0.0, Qt::white);
+ gradient.setColorAt(0.2, QColor(200, 200, 255));
+ gradient.setColorAt(0.8, QColor(200, 200, 255));
+ gradient.setColorAt(1.0, QColor(127, 127, 200));
+
+ QPainter painter;
+ painter.begin(&image);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setBrush(gradient);
+ painter.drawRoundedRect(QRectF(0.5, 0.5, image.width()-1, image.height()-1),
+ 25, 25, Qt::RelativeSize);
+
+ painter.setFont(font);
+ painter.setBrush(Qt::black);
+ painter.drawText(QRect(QPoint(6, 6), size), Qt::AlignCenter, text);
+ painter.end();
+//! [1]
+
+//! [2]
+ setPixmap(QPixmap::fromImage(image));
+ m_labelText = text;
+}
+//! [2]
+
+QString DragLabel::labelText() const
+{
+ return m_labelText;
+}
diff --git a/examples/widgets/draganddrop/fridgemagnets/draglabel.h b/examples/widgets/draganddrop/fridgemagnets/draglabel.h
new file mode 100644
index 0000000000..ecbd02d896
--- /dev/null
+++ b/examples/widgets/draganddrop/fridgemagnets/draglabel.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DRAGLABEL_H
+#define DRAGLABEL_H
+
+#include <QLabel>
+
+QT_BEGIN_NAMESPACE
+class QDragEnterEvent;
+class QDragMoveEvent;
+class QFrame;
+QT_END_NAMESPACE
+
+//! [0]
+class DragLabel : public QLabel
+{
+public:
+ DragLabel(const QString &text, QWidget *parent);
+ QString labelText() const;
+
+private:
+ QString m_labelText;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp b/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp
new file mode 100644
index 0000000000..434fcecb22
--- /dev/null
+++ b/examples/widgets/draganddrop/fridgemagnets/dragwidget.cpp
@@ -0,0 +1,212 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "draglabel.h"
+#include "dragwidget.h"
+
+//! [0]
+DragWidget::DragWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ QFile dictionaryFile(":/dictionary/words.txt");
+ dictionaryFile.open(QFile::ReadOnly);
+ QTextStream inputStream(&dictionaryFile);
+//! [0]
+
+//! [1]
+ int x = 5;
+ int y = 5;
+
+ while (!inputStream.atEnd()) {
+ QString word;
+ inputStream >> word;
+ if (!word.isEmpty()) {
+ DragLabel *wordLabel = new DragLabel(word, this);
+ wordLabel->move(x, y);
+ wordLabel->show();
+ wordLabel->setAttribute(Qt::WA_DeleteOnClose);
+ x += wordLabel->width() + 2;
+ if (x >= 245) {
+ x = 5;
+ y += wordLabel->height() + 2;
+ }
+ }
+ }
+//! [1]
+
+//! [2]
+ //Fridge magnets is used for demoing Qt on S60 and themed backgrounds look better than white
+ QPalette newPalette = palette();
+ newPalette.setColor(QPalette::Window, Qt::white);
+ setPalette(newPalette);
+
+ setMinimumSize(400, qMax(200, y));
+ setWindowTitle(tr("Fridge Magnets"));
+//! [2] //! [3]
+ setAcceptDrops(true);
+}
+//! [3]
+
+//! [4]
+void DragWidget::dragEnterEvent(QDragEnterEvent *event)
+{
+//! [4] //! [5]
+ if (event->mimeData()->hasFormat("application/x-fridgemagnet")) {
+ if (children().contains(event->source())) {
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else {
+ event->acceptProposedAction();
+//! [5] //! [6]
+ }
+//! [6] //! [7]
+ } else if (event->mimeData()->hasText()) {
+ event->acceptProposedAction();
+ } else {
+ event->ignore();
+ }
+}
+//! [7]
+
+//! [8]
+void DragWidget::dragMoveEvent(QDragMoveEvent *event)
+{
+ if (event->mimeData()->hasFormat("application/x-fridgemagnet")) {
+ if (children().contains(event->source())) {
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else {
+ event->acceptProposedAction();
+ }
+ } else if (event->mimeData()->hasText()) {
+ event->acceptProposedAction();
+ } else {
+ event->ignore();
+ }
+}
+//! [8]
+
+//! [9]
+void DragWidget::dropEvent(QDropEvent *event)
+{
+ if (event->mimeData()->hasFormat("application/x-fridgemagnet")) {
+ const QMimeData *mime = event->mimeData();
+//! [9] //! [10]
+ QByteArray itemData = mime->data("application/x-fridgemagnet");
+ QDataStream dataStream(&itemData, QIODevice::ReadOnly);
+
+ QString text;
+ QPoint offset;
+ dataStream >> text >> offset;
+//! [10]
+//! [11]
+ DragLabel *newLabel = new DragLabel(text, this);
+ newLabel->move(event->pos() - offset);
+ newLabel->show();
+ newLabel->setAttribute(Qt::WA_DeleteOnClose);
+
+ if (event->source() == this) {
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else {
+ event->acceptProposedAction();
+ }
+//! [11] //! [12]
+ } else if (event->mimeData()->hasText()) {
+ QStringList pieces = event->mimeData()->text().split(QRegExp("\\s+"),
+ QString::SkipEmptyParts);
+ QPoint position = event->pos();
+
+ foreach (QString piece, pieces) {
+ DragLabel *newLabel = new DragLabel(piece, this);
+ newLabel->move(position);
+ newLabel->show();
+ newLabel->setAttribute(Qt::WA_DeleteOnClose);
+
+ position += QPoint(newLabel->width(), 0);
+ }
+
+ event->acceptProposedAction();
+ } else {
+ event->ignore();
+ }
+}
+//! [12]
+
+//! [13]
+void DragWidget::mousePressEvent(QMouseEvent *event)
+{
+//! [13]
+//! [14]
+ DragLabel *child = static_cast<DragLabel*>(childAt(event->pos()));
+ if (!child)
+ return;
+
+ QPoint hotSpot = event->pos() - child->pos();
+
+ QByteArray itemData;
+ QDataStream dataStream(&itemData, QIODevice::WriteOnly);
+ dataStream << child->labelText() << QPoint(hotSpot);
+//! [14]
+
+//! [15]
+ QMimeData *mimeData = new QMimeData;
+ mimeData->setData("application/x-fridgemagnet", itemData);
+ mimeData->setText(child->labelText());
+//! [15]
+
+//! [16]
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ drag->setPixmap(*child->pixmap());
+ drag->setHotSpot(hotSpot);
+
+ child->hide();
+//! [16]
+
+//! [17]
+ if (drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction)
+ child->close();
+ else
+ child->show();
+}
+//! [17]
diff --git a/examples/widgets/draganddrop/fridgemagnets/dragwidget.h b/examples/widgets/draganddrop/fridgemagnets/dragwidget.h
new file mode 100644
index 0000000000..a3e3ced25e
--- /dev/null
+++ b/examples/widgets/draganddrop/fridgemagnets/dragwidget.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DRAGWIDGET_H
+#define DRAGWIDGET_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QDragEnterEvent;
+class QDropEvent;
+QT_END_NAMESPACE
+
+//! [0]
+class DragWidget : public QWidget
+{
+public:
+ DragWidget(QWidget *parent = 0);
+
+protected:
+ void dragEnterEvent(QDragEnterEvent *event);
+ void dragMoveEvent(QDragMoveEvent *event);
+ void dropEvent(QDropEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.desktop b/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.desktop
new file mode 100644
index 0000000000..a240590c6b
--- /dev/null
+++ b/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Fridge Magnets
+Exec=/opt/usr/bin/fridgemagnets
+Icon=fridgemagnets
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro b/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro
new file mode 100644
index 0000000000..2bbfdf0b3a
--- /dev/null
+++ b/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.pro
@@ -0,0 +1,15 @@
+HEADERS = draglabel.h \
+ dragwidget.h
+RESOURCES = fridgemagnets.qrc
+SOURCES = draglabel.cpp \
+ dragwidget.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/fridgemagnets
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.txt
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/fridgemagnets
+INSTALLS += target sources
+
+QT += widgets
+
diff --git a/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc b/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc
new file mode 100644
index 0000000000..b72217d701
--- /dev/null
+++ b/examples/widgets/draganddrop/fridgemagnets/fridgemagnets.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/dictionary">
+ <file>words.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/draganddrop/fridgemagnets/main.cpp b/examples/widgets/draganddrop/fridgemagnets/main.cpp
new file mode 100644
index 0000000000..692a5e394a
--- /dev/null
+++ b/examples/widgets/draganddrop/fridgemagnets/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "dragwidget.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(fridgemagnets);
+
+ QApplication app(argc, argv);
+#ifdef QT_KEYPAD_NAVIGATION
+ QApplication::setNavigationMode(Qt::NavigationModeCursorAuto);
+#endif
+ DragWidget window;
+
+ bool smallScreen = QApplication::arguments().contains("-small-screen");
+ if (smallScreen)
+ window.showFullScreen();
+ else
+ window.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/draganddrop/fridgemagnets/words.txt b/examples/widgets/draganddrop/fridgemagnets/words.txt
new file mode 100644
index 0000000000..a7e1632b09
--- /dev/null
+++ b/examples/widgets/draganddrop/fridgemagnets/words.txt
@@ -0,0 +1,48 @@
+Colorless
+green
+ideas
+sleep
+furiously
+A
+colorless
+green
+idea
+is
+a
+new
+untried
+idea
+that
+is
+without
+vividness
+dull
+and
+unexciting
+To
+sleep
+furiously
+may
+seem
+a
+puzzling
+turn
+of
+phrase
+but
+the
+mind
+in
+sleep
+often
+indeed
+moves
+furiously
+with
+ideas
+and
+images
+flickering
+in
+and
+out
diff --git a/examples/widgets/draganddrop/puzzle/example.jpg b/examples/widgets/draganddrop/puzzle/example.jpg
new file mode 100644
index 0000000000..e09fb70757
--- /dev/null
+++ b/examples/widgets/draganddrop/puzzle/example.jpg
Binary files differ
diff --git a/examples/widgets/draganddrop/puzzle/main.cpp b/examples/widgets/draganddrop/puzzle/main.cpp
new file mode 100644
index 0000000000..31b7142819
--- /dev/null
+++ b/examples/widgets/draganddrop/puzzle/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(puzzle);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.openImage(":/images/example.jpg");
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/draganddrop/puzzle/mainwindow.cpp b/examples/widgets/draganddrop/puzzle/mainwindow.cpp
new file mode 100644
index 0000000000..0540aaef9f
--- /dev/null
+++ b/examples/widgets/draganddrop/puzzle/mainwindow.cpp
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include <stdlib.h>
+
+#include "mainwindow.h"
+#include "pieceslist.h"
+#include "puzzlewidget.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ setupMenus();
+ setupWidgets();
+
+ setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
+ setWindowTitle(tr("Puzzle"));
+}
+
+void MainWindow::openImage(const QString &path)
+{
+ QString fileName = path;
+
+ if (fileName.isNull())
+ fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Image"), "", "Image Files (*.png *.jpg *.bmp)");
+
+ if (!fileName.isEmpty()) {
+ QPixmap newImage;
+ if (!newImage.load(fileName)) {
+ QMessageBox::warning(this, tr("Open Image"),
+ tr("The image file could not be loaded."),
+ QMessageBox::Cancel);
+ return;
+ }
+ puzzleImage = newImage;
+ setupPuzzle();
+ }
+}
+
+void MainWindow::setCompleted()
+{
+ QMessageBox::information(this, tr("Puzzle Completed"),
+ tr("Congratulations! You have completed the puzzle!\n"
+ "Click OK to start again."),
+ QMessageBox::Ok);
+
+ setupPuzzle();
+}
+
+void MainWindow::setupPuzzle()
+{
+ int size = qMin(puzzleImage.width(), puzzleImage.height());
+ puzzleImage = puzzleImage.copy((puzzleImage.width() - size)/2,
+ (puzzleImage.height() - size)/2, size, size).scaled(puzzleWidget->width(),
+ puzzleWidget->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+
+ piecesList->clear();
+
+ for (int y = 0; y < 5; ++y) {
+ for (int x = 0; x < 5; ++x) {
+ int pieceSize = puzzleWidget->pieceSize();
+ QPixmap pieceImage = puzzleImage.copy(x * pieceSize, y * pieceSize, pieceSize, pieceSize);
+ piecesList->addPiece(pieceImage, QPoint(x, y));
+ }
+ }
+
+ qsrand(QCursor::pos().x() ^ QCursor::pos().y());
+
+ for (int i = 0; i < piecesList->count(); ++i) {
+ if (int(2.0*qrand()/(RAND_MAX+1.0)) == 1) {
+ QListWidgetItem *item = piecesList->takeItem(i);
+ piecesList->insertItem(0, item);
+ }
+ }
+
+ puzzleWidget->clear();
+}
+
+void MainWindow::setupMenus()
+{
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+
+ QAction *openAction = fileMenu->addAction(tr("&Open..."));
+ openAction->setShortcuts(QKeySequence::Open);
+
+ QAction *exitAction = fileMenu->addAction(tr("E&xit"));
+ exitAction->setShortcuts(QKeySequence::Quit);
+
+ QMenu *gameMenu = menuBar()->addMenu(tr("&Game"));
+
+ QAction *restartAction = gameMenu->addAction(tr("&Restart"));
+
+ connect(openAction, SIGNAL(triggered()), this, SLOT(openImage()));
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(restartAction, SIGNAL(triggered()), this, SLOT(setupPuzzle()));
+}
+
+void MainWindow::setupWidgets()
+{
+ QFrame *frame = new QFrame;
+ QHBoxLayout *frameLayout = new QHBoxLayout(frame);
+ puzzleWidget = new PuzzleWidget(400);
+
+ piecesList = new PiecesList(puzzleWidget->pieceSize(), this);
+
+
+ connect(puzzleWidget, SIGNAL(puzzleCompleted()),
+ this, SLOT(setCompleted()), Qt::QueuedConnection);
+
+ frameLayout->addWidget(piecesList);
+ frameLayout->addWidget(puzzleWidget);
+ setCentralWidget(frame);
+}
diff --git a/examples/widgets/draganddrop/puzzle/mainwindow.h b/examples/widgets/draganddrop/puzzle/mainwindow.h
new file mode 100644
index 0000000000..c7ce2c8ef3
--- /dev/null
+++ b/examples/widgets/draganddrop/puzzle/mainwindow.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QPixmap>
+#include <QMainWindow>
+
+class PiecesList;
+class PuzzleWidget;
+QT_BEGIN_NAMESPACE
+class QListWidgetItem;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+public slots:
+ void openImage(const QString &path = QString());
+ void setupPuzzle();
+
+private slots:
+ void setCompleted();
+
+private:
+ void setupMenus();
+ void setupWidgets();
+
+ QPixmap puzzleImage;
+ PiecesList *piecesList;
+ PuzzleWidget *puzzleWidget;
+};
+
+#endif
diff --git a/examples/widgets/draganddrop/puzzle/pieceslist.cpp b/examples/widgets/draganddrop/puzzle/pieceslist.cpp
new file mode 100644
index 0000000000..8e0892aae6
--- /dev/null
+++ b/examples/widgets/draganddrop/puzzle/pieceslist.cpp
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "pieceslist.h"
+
+PiecesList::PiecesList(int pieceSize, QWidget *parent)
+ : QListWidget(parent), m_PieceSize(pieceSize)
+{
+ setDragEnabled(true);
+ setViewMode(QListView::IconMode);
+ setIconSize(QSize(m_PieceSize, m_PieceSize));
+ setSpacing(10);
+ setAcceptDrops(true);
+ setDropIndicatorShown(true);
+}
+
+void PiecesList::dragEnterEvent(QDragEnterEvent *event)
+{
+ if (event->mimeData()->hasFormat("image/x-puzzle-piece"))
+ event->accept();
+ else
+ event->ignore();
+}
+
+void PiecesList::dragMoveEvent(QDragMoveEvent *event)
+{
+ if (event->mimeData()->hasFormat("image/x-puzzle-piece")) {
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else
+ event->ignore();
+}
+
+void PiecesList::dropEvent(QDropEvent *event)
+{
+ if (event->mimeData()->hasFormat("image/x-puzzle-piece")) {
+ QByteArray pieceData = event->mimeData()->data("image/x-puzzle-piece");
+ QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
+ QPixmap pixmap;
+ QPoint location;
+ dataStream >> pixmap >> location;
+
+ addPiece(pixmap, location);
+
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else
+ event->ignore();
+}
+
+void PiecesList::addPiece(QPixmap pixmap, QPoint location)
+{
+ QListWidgetItem *pieceItem = new QListWidgetItem(this);
+ pieceItem->setIcon(QIcon(pixmap));
+ pieceItem->setData(Qt::UserRole, QVariant(pixmap));
+ pieceItem->setData(Qt::UserRole+1, location);
+ pieceItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable
+ | Qt::ItemIsDragEnabled);
+}
+
+void PiecesList::startDrag(Qt::DropActions /*supportedActions*/)
+{
+ QListWidgetItem *item = currentItem();
+
+ QByteArray itemData;
+ QDataStream dataStream(&itemData, QIODevice::WriteOnly);
+ QPixmap pixmap = qvariant_cast<QPixmap>(item->data(Qt::UserRole));
+ QPoint location = item->data(Qt::UserRole+1).toPoint();
+
+ dataStream << pixmap << location;
+
+ QMimeData *mimeData = new QMimeData;
+ mimeData->setData("image/x-puzzle-piece", itemData);
+
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ drag->setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2));
+ drag->setPixmap(pixmap);
+
+ if (drag->exec(Qt::MoveAction) == Qt::MoveAction)
+ delete takeItem(row(item));
+}
diff --git a/examples/widgets/draganddrop/puzzle/pieceslist.h b/examples/widgets/draganddrop/puzzle/pieceslist.h
new file mode 100644
index 0000000000..3c6b042b4e
--- /dev/null
+++ b/examples/widgets/draganddrop/puzzle/pieceslist.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PIECESLIST_H
+#define PIECESLIST_H
+
+#include <QListWidget>
+
+class PiecesList : public QListWidget
+{
+ Q_OBJECT
+
+public:
+ PiecesList(int pieceSize, QWidget *parent = 0);
+ void addPiece(QPixmap pixmap, QPoint location);
+
+protected:
+ void dragEnterEvent(QDragEnterEvent *event);
+ void dragMoveEvent(QDragMoveEvent *event);
+ void dropEvent(QDropEvent *event);
+ void startDrag(Qt::DropActions supportedActions);
+
+ int m_PieceSize;
+};
+
+#endif
diff --git a/examples/widgets/draganddrop/puzzle/puzzle.desktop b/examples/widgets/draganddrop/puzzle/puzzle.desktop
new file mode 100644
index 0000000000..f6765e1e01
--- /dev/null
+++ b/examples/widgets/draganddrop/puzzle/puzzle.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Drag and Drop Puzzle
+Exec=/opt/usr/bin/puzzle
+Icon=puzzle
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/draganddrop/puzzle/puzzle.pro b/examples/widgets/draganddrop/puzzle/puzzle.pro
new file mode 100644
index 0000000000..7c69a41a39
--- /dev/null
+++ b/examples/widgets/draganddrop/puzzle/puzzle.pro
@@ -0,0 +1,23 @@
+HEADERS = mainwindow.h \
+ pieceslist.h \
+ puzzlewidget.h
+RESOURCES = puzzle.qrc
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ pieceslist.cpp \
+ puzzlewidget.cpp
+
+QMAKE_PROJECT_NAME = dndpuzzle
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/puzzle
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.jpg
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop/puzzle
+INSTALLS += target sources
+
+wince*: {
+ addFile.files = example.jpg
+ addFile.path = .
+ DEPLOYMENT += addFile
+}
+QT += widgets
diff --git a/examples/widgets/draganddrop/puzzle/puzzle.qrc b/examples/widgets/draganddrop/puzzle/puzzle.qrc
new file mode 100644
index 0000000000..4076cec026
--- /dev/null
+++ b/examples/widgets/draganddrop/puzzle/puzzle.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/images">
+ <file>example.jpg</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp b/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
new file mode 100644
index 0000000000..2e39f84e9e
--- /dev/null
+++ b/examples/widgets/draganddrop/puzzle/puzzlewidget.cpp
@@ -0,0 +1,214 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "puzzlewidget.h"
+
+PuzzleWidget::PuzzleWidget(int imageSize, QWidget *parent)
+ : QWidget(parent), m_ImageSize(imageSize)
+{
+ setAcceptDrops(true);
+ setMinimumSize(m_ImageSize, m_ImageSize);
+ setMaximumSize(m_ImageSize, m_ImageSize);
+}
+
+void PuzzleWidget::clear()
+{
+ pieceLocations.clear();
+ piecePixmaps.clear();
+ pieceRects.clear();
+ highlightedRect = QRect();
+ inPlace = 0;
+ update();
+}
+
+void PuzzleWidget::dragEnterEvent(QDragEnterEvent *event)
+{
+ if (event->mimeData()->hasFormat("image/x-puzzle-piece"))
+ event->accept();
+ else
+ event->ignore();
+}
+
+void PuzzleWidget::dragLeaveEvent(QDragLeaveEvent *event)
+{
+ QRect updateRect = highlightedRect;
+ highlightedRect = QRect();
+ update(updateRect);
+ event->accept();
+}
+
+void PuzzleWidget::dragMoveEvent(QDragMoveEvent *event)
+{
+ QRect updateRect = highlightedRect.united(targetSquare(event->pos()));
+
+ if (event->mimeData()->hasFormat("image/x-puzzle-piece")
+ && findPiece(targetSquare(event->pos())) == -1) {
+
+ highlightedRect = targetSquare(event->pos());
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else {
+ highlightedRect = QRect();
+ event->ignore();
+ }
+
+ update(updateRect);
+}
+
+void PuzzleWidget::dropEvent(QDropEvent *event)
+{
+ if (event->mimeData()->hasFormat("image/x-puzzle-piece")
+ && findPiece(targetSquare(event->pos())) == -1) {
+
+ QByteArray pieceData = event->mimeData()->data("image/x-puzzle-piece");
+ QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
+ QRect square = targetSquare(event->pos());
+ QPixmap pixmap;
+ QPoint location;
+ dataStream >> pixmap >> location;
+
+ pieceLocations.append(location);
+ piecePixmaps.append(pixmap);
+ pieceRects.append(square);
+
+ highlightedRect = QRect();
+ update(square);
+
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+
+ if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize())) {
+ inPlace++;
+ if (inPlace == 25)
+ emit puzzleCompleted();
+ }
+ } else {
+ highlightedRect = QRect();
+ event->ignore();
+ }
+}
+
+int PuzzleWidget::findPiece(const QRect &pieceRect) const
+{
+ for (int i = 0; i < pieceRects.size(); ++i) {
+ if (pieceRect == pieceRects[i]) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+void PuzzleWidget::mousePressEvent(QMouseEvent *event)
+{
+ QRect square = targetSquare(event->pos());
+ int found = findPiece(square);
+
+ if (found == -1)
+ return;
+
+ QPoint location = pieceLocations[found];
+ QPixmap pixmap = piecePixmaps[found];
+ pieceLocations.removeAt(found);
+ piecePixmaps.removeAt(found);
+ pieceRects.removeAt(found);
+
+ if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize()))
+ inPlace--;
+
+ update(square);
+
+ QByteArray itemData;
+ QDataStream dataStream(&itemData, QIODevice::WriteOnly);
+
+ dataStream << pixmap << location;
+
+ QMimeData *mimeData = new QMimeData;
+ mimeData->setData("image/x-puzzle-piece", itemData);
+
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ drag->setHotSpot(event->pos() - square.topLeft());
+ drag->setPixmap(pixmap);
+
+ if (!(drag->exec(Qt::MoveAction) == Qt::MoveAction)) {
+ pieceLocations.insert(found, location);
+ piecePixmaps.insert(found, pixmap);
+ pieceRects.insert(found, square);
+ update(targetSquare(event->pos()));
+
+ if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize()))
+ inPlace++;
+ }
+}
+
+void PuzzleWidget::paintEvent(QPaintEvent *event)
+{
+ QPainter painter;
+ painter.begin(this);
+ painter.fillRect(event->rect(), Qt::white);
+
+ if (highlightedRect.isValid()) {
+ painter.setBrush(QColor("#ffcccc"));
+ painter.setPen(Qt::NoPen);
+ painter.drawRect(highlightedRect.adjusted(0, 0, -1, -1));
+ }
+
+ for (int i = 0; i < pieceRects.size(); ++i) {
+ painter.drawPixmap(pieceRects[i], piecePixmaps[i]);
+ }
+ painter.end();
+}
+
+const QRect PuzzleWidget::targetSquare(const QPoint &position) const
+{
+ return QRect(position.x()/pieceSize() * pieceSize(), position.y()/pieceSize() * pieceSize(), pieceSize(), pieceSize());
+}
+
+int PuzzleWidget::pieceSize() const
+{
+ return m_ImageSize / 5;
+}
+
+int PuzzleWidget::imageSize() const
+{
+ return m_ImageSize;
+}
diff --git a/examples/widgets/draganddrop/puzzle/puzzlewidget.h b/examples/widgets/draganddrop/puzzle/puzzlewidget.h
new file mode 100644
index 0000000000..1c0fc77a5f
--- /dev/null
+++ b/examples/widgets/draganddrop/puzzle/puzzlewidget.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PUZZLEWIDGET_H
+#define PUZZLEWIDGET_H
+
+#include <QList>
+#include <QPoint>
+#include <QPixmap>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QDragEnterEvent;
+class QDropEvent;
+class QMouseEvent;
+QT_END_NAMESPACE
+
+class PuzzleWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ PuzzleWidget(int imageSize, QWidget *parent = 0);
+ void clear();
+
+ int pieceSize() const;
+ int imageSize() const;
+
+signals:
+ void puzzleCompleted();
+
+protected:
+ void dragEnterEvent(QDragEnterEvent *event);
+ void dragLeaveEvent(QDragLeaveEvent *event);
+ void dragMoveEvent(QDragMoveEvent *event);
+ void dropEvent(QDropEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event);
+
+private:
+ int findPiece(const QRect &pieceRect) const;
+ const QRect targetSquare(const QPoint &position) const;
+
+ QList<QPixmap> piecePixmaps;
+ QList<QRect> pieceRects;
+ QList<QPoint> pieceLocations;
+ QRect highlightedRect;
+ int inPlace;
+ int m_ImageSize;
+};
+
+#endif
diff --git a/examples/widgets/effects/blurpicker/blureffect.cpp b/examples/widgets/effects/blurpicker/blureffect.cpp
new file mode 100644
index 0000000000..d9a757722b
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/blureffect.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "blureffect.h"
+
+#include <QDebug>
+
+BlurEffect::BlurEffect(QGraphicsItem *item)
+ : QGraphicsBlurEffect()
+ , m_baseLine(200), item(item)
+{
+}
+
+void BlurEffect::adjustForItem()
+{
+ qreal y = m_baseLine - item->pos().y();
+ qreal radius = qBound(qreal(0.0), y / 32, qreal(16.0));
+ setBlurRadius(radius);
+}
+
+QRectF BlurEffect::boundingRect() const
+{
+ const_cast<BlurEffect *>(this)->adjustForItem();
+ return QGraphicsBlurEffect::boundingRect();
+}
+
+void BlurEffect::draw(QPainter *painter)
+{
+ adjustForItem();
+ QGraphicsBlurEffect::draw(painter);
+}
diff --git a/examples/widgets/effects/blurpicker/blureffect.h b/examples/widgets/effects/blurpicker/blureffect.h
new file mode 100644
index 0000000000..6cef9df4b5
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/blureffect.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BLUREFFECT_H
+#define BLUREFFECT_H
+
+#include <QGraphicsEffect>
+#include <QGraphicsItem>
+
+class BlurEffect: public QGraphicsBlurEffect
+{
+public:
+ BlurEffect(QGraphicsItem *item);
+
+ void setBaseLine(qreal y) { m_baseLine = y; }
+
+ QRectF boundingRect() const;
+
+ void draw(QPainter *painter);
+
+private:
+ void adjustForItem();
+
+private:
+ qreal m_baseLine;
+ QGraphicsItem *item;
+};
+
+#endif // BLUREFFECT_H
diff --git a/examples/widgets/effects/blurpicker/blurpicker.cpp b/examples/widgets/effects/blurpicker/blurpicker.cpp
new file mode 100644
index 0000000000..ab56b241f8
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/blurpicker.cpp
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "blurpicker.h"
+
+#include <QtWidgets>
+
+#include "blureffect.h"
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0), m_animation(this, "index")
+{
+ setBackgroundBrush(QPixmap(":/images/background.jpg"));
+ setScene(new QGraphicsScene(this));
+
+ setupScene();
+ setIndex(0);
+
+ m_animation.setDuration(400);
+ m_animation.setEasingCurve(QEasingCurve::InOutSine);
+
+ setRenderHint(QPainter::Antialiasing, true);
+ setFrameStyle(QFrame::NoFrame);
+}
+
+qreal BlurPicker::index() const
+{
+ return m_index;
+}
+
+void BlurPicker::setIndex(qreal index)
+{
+ m_index = index;
+
+ qreal baseline = 0;
+ for (int i = 0; i < m_icons.count(); ++i) {
+ QGraphicsItem *icon = m_icons[i];
+ qreal a = ((i + m_index) * 2 * M_PI) / m_icons.count();
+ qreal xs = 170 * sin(a);
+ qreal ys = 100 * cos(a);
+ QPointF pos(xs, ys);
+ pos = QTransform().rotate(-20).map(pos);
+ pos -= QPointF(40, 40);
+ icon->setPos(pos);
+ baseline = qMax(baseline, ys);
+ static_cast<BlurEffect *>(icon->graphicsEffect())->setBaseLine(baseline);
+ }
+
+ scene()->update();
+}
+
+void BlurPicker::setupScene()
+{
+ scene()->setSceneRect(-200, -120, 400, 240);
+
+ QStringList names;
+ names << ":/images/accessories-calculator.png";
+ names << ":/images/accessories-text-editor.png";
+ names << ":/images/help-browser.png";
+ names << ":/images/internet-group-chat.png";
+ names << ":/images/internet-mail.png";
+ names << ":/images/internet-web-browser.png";
+ names << ":/images/office-calendar.png";
+ names << ":/images/system-users.png";
+
+ for (int i = 0; i < names.count(); i++) {
+ QPixmap pixmap(names[i]);
+ QGraphicsPixmapItem *icon = scene()->addPixmap(pixmap);
+ icon->setZValue(1);
+ icon->setGraphicsEffect(new BlurEffect(icon));
+ m_icons << icon;
+ }
+
+ QGraphicsPixmapItem *bg = scene()->addPixmap(QPixmap(":/images/background.jpg"));
+ bg->setZValue(0);
+ bg->setPos(-200, -150);
+}
+
+void BlurPicker::keyPressEvent(QKeyEvent *event)
+{
+ int delta = 0;
+ switch (event->key())
+ {
+ case Qt::Key_Left:
+ delta = -1;
+ break;
+ case Qt::Key_Right:
+ delta = 1;
+ break;
+ default:
+ break;
+ }
+ if (m_animation.state() == QAbstractAnimation::Stopped && delta) {
+ m_animation.setEndValue(m_index + delta);
+ m_animation.start();
+ event->accept();
+ }
+}
+
+void BlurPicker::resizeEvent(QResizeEvent */*event*/)
+{
+}
+
+void BlurPicker::mousePressEvent(QMouseEvent *event)
+{
+ int delta = 0;
+ if(event->x() > (width() / 2))
+ {
+ delta = 1;
+ }
+ else
+ {
+ delta = -1;
+ }
+
+ if (m_animation.state() == QAbstractAnimation::Stopped && delta) {
+ m_animation.setEndValue(m_index + delta);
+ m_animation.start();
+ event->accept();
+ }
+}
diff --git a/examples/widgets/effects/blurpicker/blurpicker.desktop b/examples/widgets/effects/blurpicker/blurpicker.desktop
new file mode 100644
index 0000000000..0863ef7ba8
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/blurpicker.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Blur Picker Effect
+Exec=/opt/usr/bin/blurpicker
+Icon=blurpicker
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/effects/blurpicker/blurpicker.h b/examples/widgets/effects/blurpicker/blurpicker.h
new file mode 100644
index 0000000000..c0df0814d0
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/blurpicker.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BLURPICKER_H
+#define BLURPICKER_H
+
+#include <QGraphicsEffect>
+#include <QGraphicsView>
+#include <QPropertyAnimation>
+
+#include "blureffect.h"
+
+class BlurPicker: public QGraphicsView
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal index READ index WRITE setIndex)
+
+public:
+ BlurPicker(QWidget *parent = 0);
+
+ qreal index() const;
+ void setIndex(qreal);
+
+protected:
+ void keyPressEvent(QKeyEvent *event);
+ void resizeEvent(QResizeEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+
+private:
+ void setupScene();
+
+private:
+ qreal m_index;
+ QList<QGraphicsItem*> m_icons;
+ QPropertyAnimation m_animation;
+};
+
+#endif // BLURPICKER_H
diff --git a/examples/widgets/effects/blurpicker/blurpicker.pro b/examples/widgets/effects/blurpicker/blurpicker.pro
new file mode 100644
index 0000000000..c477ea6e39
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/blurpicker.pro
@@ -0,0 +1,11 @@
+SOURCES += main.cpp blurpicker.cpp blureffect.cpp
+HEADERS += blurpicker.h blureffect.h
+RESOURCES += blurpicker.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/effects/blurpicker
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS blurpicker.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/effects/blurpicker
+INSTALLS += target sources
+QT += widgets
+
diff --git a/examples/widgets/effects/blurpicker/blurpicker.qrc b/examples/widgets/effects/blurpicker/blurpicker.qrc
new file mode 100644
index 0000000000..e88eaca966
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/blurpicker.qrc
@@ -0,0 +1,14 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>images/background.jpg</file>
+ <file>images/accessories-calculator.png</file>
+ <file>images/accessories-text-editor.png</file>
+ <file>images/help-browser.png</file>
+ <file>images/internet-group-chat.png</file>
+ <file>images/internet-mail.png</file>
+ <file>images/internet-web-browser.png</file>
+ <file>images/office-calendar.png</file>
+ <file>images/system-users.png</file>
+ </qresource>
+</RCC>
+
diff --git a/examples/widgets/effects/blurpicker/images/README.txt b/examples/widgets/effects/blurpicker/images/README.txt
new file mode 100644
index 0000000000..0927e177d2
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/images/README.txt
@@ -0,0 +1,5 @@
+The background is taken from a public domain photo at:
+http://www.photos8.com/view/computer_board2-800x600.html
+
+All other icons are from the Tango Desktop project:
+http://tango.freedesktop.org/Tango_Desktop_Project
diff --git a/examples/widgets/effects/blurpicker/images/accessories-calculator.png b/examples/widgets/effects/blurpicker/images/accessories-calculator.png
new file mode 100644
index 0000000000..4e7661f65c
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/images/accessories-calculator.png
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/accessories-text-editor.png b/examples/widgets/effects/blurpicker/images/accessories-text-editor.png
new file mode 100644
index 0000000000..33bef0bc17
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/images/accessories-text-editor.png
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/background.jpg b/examples/widgets/effects/blurpicker/images/background.jpg
new file mode 100644
index 0000000000..e75b38899d
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/images/background.jpg
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/help-browser.png b/examples/widgets/effects/blurpicker/images/help-browser.png
new file mode 100644
index 0000000000..8ef4fae91b
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/images/help-browser.png
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/internet-group-chat.png b/examples/widgets/effects/blurpicker/images/internet-group-chat.png
new file mode 100644
index 0000000000..dd92d93947
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/images/internet-group-chat.png
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/internet-mail.png b/examples/widgets/effects/blurpicker/images/internet-mail.png
new file mode 100644
index 0000000000..7e6b93be83
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/images/internet-mail.png
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/internet-web-browser.png b/examples/widgets/effects/blurpicker/images/internet-web-browser.png
new file mode 100644
index 0000000000..a979a92b4f
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/images/internet-web-browser.png
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/office-calendar.png b/examples/widgets/effects/blurpicker/images/office-calendar.png
new file mode 100644
index 0000000000..e09590682b
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/images/office-calendar.png
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/images/system-users.png b/examples/widgets/effects/blurpicker/images/system-users.png
new file mode 100644
index 0000000000..a7f630a5bd
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/images/system-users.png
Binary files differ
diff --git a/examples/widgets/effects/blurpicker/main.cpp b/examples/widgets/effects/blurpicker/main.cpp
new file mode 100644
index 0000000000..662800596d
--- /dev/null
+++ b/examples/widgets/effects/blurpicker/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "blurpicker.h"
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ BlurPicker blurPicker;
+ blurPicker.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Application Picker"));
+
+ blurPicker.setFixedSize(400, 300);
+ blurPicker.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/effects/effects.pro b/examples/widgets/effects/effects.pro
new file mode 100644
index 0000000000..db7b8a723e
--- /dev/null
+++ b/examples/widgets/effects/effects.pro
@@ -0,0 +1,14 @@
+TEMPLATE = \
+ subdirs
+SUBDIRS = \
+ blurpicker \
+ lighting \
+ fademessage
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/effects
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS effects.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/effects
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/effects/fademessage/README.txt b/examples/widgets/effects/fademessage/README.txt
new file mode 100644
index 0000000000..f639e76508
--- /dev/null
+++ b/examples/widgets/effects/fademessage/README.txt
@@ -0,0 +1,2 @@
+The background is taken from a public domain photo at:
+http://www.photos8.com/view/windows_problem_blue-800x600.html
diff --git a/examples/widgets/effects/fademessage/background.jpg b/examples/widgets/effects/fademessage/background.jpg
new file mode 100644
index 0000000000..9884233a29
--- /dev/null
+++ b/examples/widgets/effects/fademessage/background.jpg
Binary files differ
diff --git a/examples/widgets/effects/fademessage/fademessage.cpp b/examples/widgets/effects/fademessage/fademessage.cpp
new file mode 100644
index 0000000000..0af0a57904
--- /dev/null
+++ b/examples/widgets/effects/fademessage/fademessage.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "fademessage.h"
+
+#include <QtWidgets>
+
+FadeMessage::FadeMessage(QWidget *parent): QGraphicsView(parent)
+{
+ setScene(&m_scene);
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+ setupScene();
+
+ m_animation = new QPropertyAnimation(m_effect, "strength", this);
+ m_animation->setDuration(500);
+ m_animation->setEasingCurve(QEasingCurve::InOutSine);
+ m_animation->setStartValue(0);
+ m_animation->setEndValue(1);
+
+ setRenderHint(QPainter::Antialiasing, true);
+ setFrameStyle(QFrame::NoFrame);
+}
+
+void FadeMessage::togglePopup()
+{
+ if (m_message->isVisible()) {
+ m_message->setVisible(false);
+ m_animation->setDirection(QAbstractAnimation::Backward);
+ } else {
+ m_message->setVisible(true);
+ m_animation->setDirection(QAbstractAnimation::Forward);
+ }
+ m_animation->start();
+}
+
+void FadeMessage::setupScene()
+{
+ QGraphicsRectItem *parent = m_scene.addRect(0, 0, 800, 600);
+ parent->setPen(Qt::NoPen);
+ parent->setZValue(0);
+
+ QGraphicsPixmapItem *bg = m_scene.addPixmap(QPixmap(":/background.jpg"));
+ bg->setParentItem(parent);
+ bg->setZValue(-1);
+
+ for (int i = 1; i < 5; ++i)
+ for (int j = 2; j < 5; ++j) {
+ QGraphicsRectItem *item = m_scene.addRect(i * 50, (j - 1) * 50, 38, 38);
+ item->setParentItem(parent);
+ item->setZValue(1);
+ int hue = 12 * (i * 5 + j);
+ item->setBrush(QColor::fromHsv(hue, 128, 128));
+ }
+
+ QFont font;
+ font.setPointSize(font.pointSize() * 2);
+ font.setBold(true);
+ QFontMetrics fontMetrics(font);
+ int fh = fontMetrics.height();
+
+ QString sceneText = "Qt Everywhere!";
+ int sceneTextWidth = fontMetrics.width(sceneText);
+
+ QGraphicsRectItem *block = m_scene.addRect(50, 300, sceneTextWidth, fh + 3);
+ block->setPen(Qt::NoPen);
+ block->setBrush(QColor(102, 153, 51));
+
+ QGraphicsTextItem *text = m_scene.addText(sceneText, font);
+ text->setDefaultTextColor(Qt::white);
+ text->setPos(50, 300);
+ block->setZValue(2);
+ block->hide();
+
+ text->setParentItem(block);
+ m_message = block;
+
+ m_effect = new QGraphicsColorizeEffect;
+ m_effect->setColor(QColor(122, 193, 66));
+ m_effect->setStrength(0);
+ m_effect->setEnabled(true);
+ parent->setGraphicsEffect(m_effect);
+
+ QPushButton *press = new QPushButton;
+ press->setText(tr("Press me"));
+ connect(press, SIGNAL(clicked()), SLOT(togglePopup()));
+ m_scene.addWidget(press);
+
+ press->move(300, 500);
+}
diff --git a/examples/widgets/effects/fademessage/fademessage.desktop b/examples/widgets/effects/fademessage/fademessage.desktop
new file mode 100644
index 0000000000..aa22ad7912
--- /dev/null
+++ b/examples/widgets/effects/fademessage/fademessage.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Fade Message Effect
+Exec=/opt/usr/bin/fademessage
+Icon=fademessage
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/effects/fademessage/fademessage.h b/examples/widgets/effects/fademessage/fademessage.h
new file mode 100644
index 0000000000..635f57a725
--- /dev/null
+++ b/examples/widgets/effects/fademessage/fademessage.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FADEMESSAGE_H
+#define FADEMESSAGE_H
+
+#include <QGraphicsEffect>
+#include <QGraphicsView>
+#include <QPropertyAnimation>
+
+#include "fademessage.h"
+
+class FadeMessage: public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ FadeMessage(QWidget *parent = 0);
+
+private:
+ void setupScene();
+
+private slots:
+ void togglePopup();
+
+private:
+ QGraphicsScene m_scene;
+ QGraphicsColorizeEffect *m_effect;
+ QGraphicsItem *m_message;
+ QPropertyAnimation *m_animation;
+};
+
+#endif // FADEMESSAGE_H
diff --git a/examples/widgets/effects/fademessage/fademessage.pro b/examples/widgets/effects/fademessage/fademessage.pro
new file mode 100644
index 0000000000..98161e0be4
--- /dev/null
+++ b/examples/widgets/effects/fademessage/fademessage.pro
@@ -0,0 +1,18 @@
+SOURCES += main.cpp fademessage.cpp
+HEADERS += fademessage.h
+RESOURCES += fademessage.qrc
+INSTALLS += target sources
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/effects/fademessage
+sources.files = $$SOURCES \
+ $$HEADERS \
+ $$RESOURCES \
+ $$FORMS \
+ fademessage.pro \
+ background.jpg
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/effects/fademessage
+
+
+QT += widgets
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/effects/fademessage/fademessage.qrc b/examples/widgets/effects/fademessage/fademessage.qrc
new file mode 100644
index 0000000000..9efea6a67d
--- /dev/null
+++ b/examples/widgets/effects/fademessage/fademessage.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>background.jpg</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/effects/fademessage/main.cpp b/examples/widgets/effects/fademessage/main.cpp
new file mode 100644
index 0000000000..d755ebeb7b
--- /dev/null
+++ b/examples/widgets/effects/fademessage/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "fademessage.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ FadeMessage widget;
+ widget.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Popup Message with Effect"));
+ widget.setFixedSize(400, 600);
+ widget.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/effects/lighting/lighting.cpp b/examples/widgets/effects/lighting/lighting.cpp
new file mode 100644
index 0000000000..713d0e0ec9
--- /dev/null
+++ b/examples/widgets/effects/lighting/lighting.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "lighting.h"
+
+#include <QtWidgets>
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+Lighting::Lighting(QWidget *parent): QGraphicsView(parent), angle(0.0)
+{
+ setScene(&m_scene);
+
+ setupScene();
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), SLOT(animate()));
+ timer->setInterval(30);
+ timer->start();
+
+ setRenderHint(QPainter::Antialiasing, true);
+ setFrameStyle(QFrame::NoFrame);
+}
+
+void Lighting::setupScene()
+{
+ m_scene.setSceneRect(-300, -200, 600, 460);
+
+ QLinearGradient linearGrad(QPointF(-100, -100), QPointF(100, 100));
+ linearGrad.setColorAt(0, QColor(255, 255, 255));
+ linearGrad.setColorAt(1, QColor(192, 192, 255));
+ setBackgroundBrush(linearGrad);
+
+ QRadialGradient radialGrad(30, 30, 30);
+ radialGrad.setColorAt(0, Qt::yellow);
+ radialGrad.setColorAt(0.2, Qt::yellow);
+ radialGrad.setColorAt(1, Qt::transparent);
+ QPixmap pixmap(60, 60);
+ pixmap.fill(Qt::transparent);
+ QPainter painter(&pixmap);
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(radialGrad);
+ painter.drawEllipse(0, 0, 60, 60);
+ painter.end();
+
+ m_lightSource = m_scene.addPixmap(pixmap);
+ m_lightSource->setZValue(2);
+
+ for (int i = -2; i < 3; ++i)
+ for (int j = -2; j < 3; ++j) {
+ QAbstractGraphicsShapeItem *item;
+ if ((i + j) & 1)
+ item = new QGraphicsEllipseItem(0, 0, 50, 50);
+ else
+ item = new QGraphicsRectItem(0, 0, 50, 50);
+
+ item->setPen(QPen(Qt::black, 1));
+ item->setBrush(QBrush(Qt::white));
+ QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
+ effect->setBlurRadius(8);
+ item->setGraphicsEffect(effect);
+ item->setZValue(1);
+ item->setPos(i * 80, j * 80);
+ m_scene.addItem(item);
+ m_items << item;
+ }
+
+
+}
+
+void Lighting::animate()
+{
+ angle += (M_PI / 30);
+ qreal xs = 200 * sin(angle) - 40 + 25;
+ qreal ys = 200 * cos(angle) - 40 + 25;
+ m_lightSource->setPos(xs, ys);
+
+ for (int i = 0; i < m_items.size(); ++i) {
+ QGraphicsItem *item = m_items.at(i);
+ Q_ASSERT(item);
+ QGraphicsDropShadowEffect *effect = static_cast<QGraphicsDropShadowEffect *>(item->graphicsEffect());
+ Q_ASSERT(effect);
+
+ QPointF delta(item->x() - xs, item->y() - ys);
+ effect->setOffset(delta.toPoint() / 30);
+
+ qreal dx = delta.x();
+ qreal dy = delta.y();
+ qreal dd = sqrt(dx * dx + dy * dy);
+ QColor color = effect->color();
+ color.setAlphaF(qBound(0.4, 1 - dd / 200.0, 0.7));
+ effect->setColor(color);
+ }
+
+ m_scene.update();
+}
+
+void Lighting::resizeEvent(QResizeEvent */*event*/)
+{
+}
diff --git a/examples/widgets/effects/lighting/lighting.desktop b/examples/widgets/effects/lighting/lighting.desktop
new file mode 100644
index 0000000000..806b3deca0
--- /dev/null
+++ b/examples/widgets/effects/lighting/lighting.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Lighting Effect
+Exec=/opt/usr/bin/lighting
+Icon=lighting
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/effects/lighting/lighting.h b/examples/widgets/effects/lighting/lighting.h
new file mode 100644
index 0000000000..2ed0d5ac12
--- /dev/null
+++ b/examples/widgets/effects/lighting/lighting.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LIGHTING_H
+#define LIGHTING_H
+
+#include <QGraphicsEffect>
+#include <QGraphicsView>
+
+class Lighting: public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ Lighting(QWidget *parent = 0);
+
+private slots:
+ void animate();
+
+private:
+ void setupScene();
+
+protected:
+ void resizeEvent(QResizeEvent *event);
+
+private:
+ qreal angle;
+ QGraphicsScene m_scene;
+ QGraphicsItem *m_lightSource;
+ QList<QGraphicsItem*> m_items;
+};
+
+#endif // LIGHTING_H
diff --git a/examples/widgets/effects/lighting/lighting.pro b/examples/widgets/effects/lighting/lighting.pro
new file mode 100644
index 0000000000..16be936b26
--- /dev/null
+++ b/examples/widgets/effects/lighting/lighting.pro
@@ -0,0 +1,11 @@
+SOURCES += main.cpp lighting.cpp
+HEADERS += lighting.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/effects/lighting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS lighting.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/effects/lighting
+INSTALLS += target sources
+QT += widgets
+
+
diff --git a/examples/widgets/effects/lighting/main.cpp b/examples/widgets/effects/lighting/main.cpp
new file mode 100644
index 0000000000..aedd9a24cb
--- /dev/null
+++ b/examples/widgets/effects/lighting/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "lighting.h"
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ Lighting lighting;
+ lighting.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Lighting and Shadows"));
+
+ lighting.resize(640, 480);
+ lighting.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/graphicsview/README b/examples/widgets/graphicsview/README
new file mode 100644
index 0000000000..e710fc3c13
--- /dev/null
+++ b/examples/widgets/graphicsview/README
@@ -0,0 +1,9 @@
+Qt is provided with a comprehensive canvas through the GraphicsView
+classes.
+
+These examples demonstrate the fundamental aspects of canvas programming
+with Qt.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/graphicsview/anchorlayout/anchorlayout.desktop b/examples/widgets/graphicsview/anchorlayout/anchorlayout.desktop
new file mode 100644
index 0000000000..6cf53c3f9b
--- /dev/null
+++ b/examples/widgets/graphicsview/anchorlayout/anchorlayout.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Anchor Layout
+Exec=/opt/usr/bin/anchorlayout
+Icon=anchorlayout
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/anchorlayout/anchorlayout.pro b/examples/widgets/graphicsview/anchorlayout/anchorlayout.pro
new file mode 100644
index 0000000000..7b18a621db
--- /dev/null
+++ b/examples/widgets/graphicsview/anchorlayout/anchorlayout.pro
@@ -0,0 +1,13 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/anchorlayout
+sources.files = $$SOURCES $$HEADERS $$RESOURCES anchorlayout.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/anchorlayout
+INSTALLS += target sources
+
+TARGET = anchorlayout
+QT += widgets
+
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/graphicsview/anchorlayout/main.cpp b/examples/widgets/graphicsview/anchorlayout/main.cpp
new file mode 100644
index 0000000000..839aef2e39
--- /dev/null
+++ b/examples/widgets/graphicsview/anchorlayout/main.cpp
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGraphicsWidget>
+#include <QGraphicsProxyWidget>
+#include <QGraphicsAnchorLayout>
+#include <QtWidgets>
+
+static QGraphicsProxyWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0),
+ const QSizeF &preferred = QSize(150.0, 100.0),
+ const QSizeF &maximum = QSizeF(200.0, 100.0),
+ const QString &name = "0")
+{
+ QGraphicsProxyWidget *w = new QGraphicsProxyWidget;
+ w->setWidget(new QPushButton(name));
+ w->setData(0, name);
+ w->setMinimumSize(minimum);
+ w->setPreferredSize(preferred);
+ w->setMaximumSize(maximum);
+
+ w->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ return w;
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ QGraphicsScene scene;
+ scene.setSceneRect(0, 0, 800, 480);
+
+ QSizeF minSize(30, 100);
+ QSizeF prefSize(210, 100);
+ QSizeF maxSize(300, 100);
+
+ QGraphicsProxyWidget *a = createItem(minSize, prefSize, maxSize, "A");
+ QGraphicsProxyWidget *b = createItem(minSize, prefSize, maxSize, "B");
+ QGraphicsProxyWidget *c = createItem(minSize, prefSize, maxSize, "C");
+ QGraphicsProxyWidget *d = createItem(minSize, prefSize, maxSize, "D");
+ QGraphicsProxyWidget *e = createItem(minSize, prefSize, maxSize, "E");
+ QGraphicsProxyWidget *f = createItem(QSizeF(30, 50), QSizeF(150, 50), maxSize, "F (overflow)");
+ QGraphicsProxyWidget *g = createItem(QSizeF(30, 50), QSizeF(30, 100), maxSize, "G (overflow)");
+
+ QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
+ l->setSpacing(0);
+
+ QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
+ w->setPos(20, 20);
+ w->setLayout(l);
+
+ // vertical
+ l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop);
+ l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop);
+
+ l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom);
+ l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom);
+ l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
+ l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop);
+
+ l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom);
+ l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom);
+
+ l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop);
+ l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom);
+ l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop);
+ l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom);
+
+ // horizontal
+ l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
+ l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft);
+ l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
+
+ l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);
+ l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft);
+
+ l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight);
+ l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight);
+ l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft);
+
+ l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft);
+ l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft);
+ l->addAnchor(f, Qt::AnchorRight, g, Qt::AnchorRight);
+
+
+ scene.addItem(w);
+ scene.setBackgroundBrush(Qt::darkGreen);
+ QGraphicsView view(&scene);
+
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.desktop b/examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.desktop
new file mode 100644
index 0000000000..be1c3e4a84
--- /dev/null
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Basic Graphics Layouts
+Exec=/opt/usr/bin/basicgraphicslayouts
+Icon=basicgraphicslayouts
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro b/examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro
new file mode 100644
index 0000000000..202c8d87a0
--- /dev/null
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro
@@ -0,0 +1,14 @@
+HEADERS = layoutitem.h \
+ window.h
+SOURCES = layoutitem.cpp \
+ main.cpp \
+ window.cpp
+RESOURCES = basicgraphicslayouts.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/basicgraphicslayouts
+sources.files = $$SOURCES $$HEADERS $$RESOURCES basicgraphicslayouts.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/basicgraphicslayouts
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.qrc b/examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.qrc
new file mode 100644
index 0000000000..fbe2efa572
--- /dev/null
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/basicgraphicslayouts.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource>
+ <file>images/block.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/images/block.png b/examples/widgets/graphicsview/basicgraphicslayouts/images/block.png
new file mode 100644
index 0000000000..4c72a3f508
--- /dev/null
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/images/block.png
Binary files differ
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp
new file mode 100644
index 0000000000..7067cddece
--- /dev/null
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "layoutitem.h"
+
+//! [0]
+LayoutItem::LayoutItem(QGraphicsItem *parent/* = 0*/)
+ : QGraphicsLayoutItem(), QGraphicsItem(parent)
+{
+ m_pix = new QPixmap(QLatin1String(":/images/block.png"));
+ setGraphicsItem(this);
+}
+//! [0]
+
+LayoutItem::~LayoutItem()
+{
+ delete m_pix;
+}
+
+//! [1]
+void LayoutItem::paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option, QWidget *widget /*= 0*/)
+{
+ Q_UNUSED(widget);
+ Q_UNUSED(option);
+
+ QRectF frame(QPointF(0,0), geometry().size());
+ qreal w = m_pix->width();
+ qreal h = m_pix->height();
+ QGradientStops stops;
+//! [1]
+
+//! [2]
+ // paint a background rect (with gradient)
+ QLinearGradient gradient(frame.topLeft(), frame.topLeft() + QPointF(200,200));
+ stops << QGradientStop(0.0, QColor(60, 60, 60));
+ stops << QGradientStop(frame.height()/2/frame.height(), QColor(102, 176, 54));
+
+ //stops << QGradientStop(((frame.height() + h)/2 )/frame.height(), QColor(157, 195, 55));
+ stops << QGradientStop(1.0, QColor(215, 215, 215));
+ gradient.setStops(stops);
+ painter->setBrush(QBrush(gradient));
+ painter->drawRoundedRect(frame, 10.0, 10.0);
+
+ // paint a rect around the pixmap (with gradient)
+ QPointF pixpos = frame.center() - (QPointF(w, h)/2);
+ QRectF innerFrame(pixpos, QSizeF(w, h));
+ innerFrame.adjust(-4, -4, +4, +4);
+ gradient.setStart(innerFrame.topLeft());
+ gradient.setFinalStop(innerFrame.bottomRight());
+ stops.clear();
+ stops << QGradientStop(0.0, QColor(215, 255, 200));
+ stops << QGradientStop(0.5, QColor(102, 176, 54));
+ stops << QGradientStop(1.0, QColor(0, 0, 0));
+ gradient.setStops(stops);
+ painter->setBrush(QBrush(gradient));
+ painter->drawRoundedRect(innerFrame, 10.0, 10.0);
+ painter->drawPixmap(pixpos, *m_pix);
+}
+//! [2]
+
+//! [3]
+QRectF LayoutItem::boundingRect() const
+{
+ return QRectF(QPointF(0,0), geometry().size());
+}
+//! [3]
+
+//! [4]
+void LayoutItem::setGeometry(const QRectF &geom)
+{
+ prepareGeometryChange();
+ QGraphicsLayoutItem::setGeometry(geom);
+ setPos(geom.topLeft());
+}
+//! [4]
+
+//! [5]
+QSizeF LayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
+{
+ switch (which) {
+ case Qt::MinimumSize:
+ case Qt::PreferredSize:
+ // Do not allow a size smaller than the pixmap with two frames around it.
+ return m_pix->size() + QSize(12, 12);
+ case Qt::MaximumSize:
+ return QSizeF(1000,1000);
+ default:
+ break;
+ }
+ return constraint;
+}
+//! [5]
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h
new file mode 100644
index 0000000000..798c4650c6
--- /dev/null
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LAYOUTITEM_H
+#define LAYOUTITEM_H
+#include <QtWidgets>
+
+//! [0]
+class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem
+{
+public:
+ LayoutItem(QGraphicsItem *parent = 0);
+ ~LayoutItem();
+ // Inherited from QGraphicsLayoutItem
+ void setGeometry(const QRectF &geom);
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
+
+ // Inherited from QGraphicsItem
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget = 0);
+
+private:
+ QPixmap *m_pix;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/main.cpp b/examples/widgets/graphicsview/basicgraphicslayouts/main.cpp
new file mode 100644
index 0000000000..ef482235a9
--- /dev/null
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "window.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ QGraphicsScene scene;
+
+ Window *window = new Window;
+ scene.addItem(window);
+ QGraphicsView view(&scene);
+ view.resize(600, 600);
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/window.cpp b/examples/widgets/graphicsview/basicgraphicslayouts/window.cpp
new file mode 100644
index 0000000000..e3786b61f1
--- /dev/null
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/window.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "window.h"
+#include "layoutitem.h"
+
+Window::Window(QGraphicsWidget *parent) : QGraphicsWidget(parent, Qt::Window)
+{
+//! [0]
+ QGraphicsLinearLayout *windowLayout = new QGraphicsLinearLayout(Qt::Vertical);
+ QGraphicsLinearLayout *linear = new QGraphicsLinearLayout(windowLayout);
+ LayoutItem *item = new LayoutItem;
+ linear->addItem(item);
+ linear->setStretchFactor(item, 1);
+//! [0]
+
+//! [1]
+ item = new LayoutItem;
+ linear->addItem(item);
+ linear->setStretchFactor(item, 3);
+ windowLayout->addItem(linear);
+//! [1]
+
+//! [2]
+ QGraphicsGridLayout *grid = new QGraphicsGridLayout(windowLayout);
+ item = new LayoutItem;
+ grid->addItem(item, 0, 0, 4, 1);
+ item = new LayoutItem;
+ item->setMaximumHeight(item->minimumHeight());
+ grid->addItem(item, 0, 1, 2, 1, Qt::AlignVCenter);
+ item = new LayoutItem;
+ item->setMaximumHeight(item->minimumHeight());
+ grid->addItem(item, 2, 1, 2, 1, Qt::AlignVCenter);
+ item = new LayoutItem;
+ grid->addItem(item, 0, 2);
+ item = new LayoutItem;
+ grid->addItem(item, 1, 2);
+ item = new LayoutItem;
+ grid->addItem(item, 2, 2);
+ item = new LayoutItem;
+ grid->addItem(item, 3, 2);
+ windowLayout->addItem(grid);
+//! [2]
+
+//! [3]
+ setLayout(windowLayout);
+ setWindowTitle(tr("Basic Graphics Layouts Example"));
+//! [3]
+
+}
+
+
+
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/window.h b/examples/widgets/graphicsview/basicgraphicslayouts/window.h
new file mode 100644
index 0000000000..5c1cc2ed4f
--- /dev/null
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/window.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QtWidgets/QGraphicsWidget>
+
+//! [0]
+class Window : public QGraphicsWidget {
+ Q_OBJECT
+
+public:
+ Window(QGraphicsWidget *parent = 0);
+
+};
+//! [0]
+
+#endif //WINDOW_H
+
diff --git a/examples/widgets/graphicsview/boxes/3rdparty/fbm.c b/examples/widgets/graphicsview/boxes/3rdparty/fbm.c
new file mode 100644
index 0000000000..98eb87a33b
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/3rdparty/fbm.c
@@ -0,0 +1,207 @@
+/*****************************************************************
+
+ Implementation of the fractional Brownian motion algorithm. These
+ functions were originally the work of F. Kenton Musgrave.
+ For documentation of the different functions please refer to the
+ book:
+ "Texturing and modeling: a procedural approach"
+ by David S. Ebert et. al.
+
+******************************************************************/
+
+#if defined (_MSC_VER)
+#include <qglobal.h>
+#endif
+
+#include <time.h>
+#include <stdlib.h>
+#include "fbm.h"
+
+#if defined(Q_CC_MSVC)
+#pragma warning(disable:4244)
+#endif
+
+/* Definitions used by the noise2() functions */
+
+//#define B 0x100
+//#define BM 0xff
+#define B 0x20
+#define BM 0x1f
+
+#define N 0x1000
+#define NP 12 /* 2^N */
+#define NM 0xfff
+
+static int p[B + B + 2];
+static float g3[B + B + 2][3];
+static float g2[B + B + 2][2];
+static float g1[B + B + 2];
+static int start = 1;
+
+static void init(void);
+
+#define s_curve(t) ( t * t * (3. - 2. * t) )
+
+#define lerp(t, a, b) ( a + t * (b - a) )
+
+#define setup(i,b0,b1,r0,r1)\
+ t = vec[i] + N;\
+ b0 = ((int)t) & BM;\
+ b1 = (b0+1) & BM;\
+ r0 = t - (int)t;\
+ r1 = r0 - 1.;
+#define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )
+
+/* Fractional Brownian Motion function */
+
+double fBm( Vector point, double H, double lacunarity, double octaves,
+ int init )
+{
+
+ double value, frequency, remainder;
+ int i;
+ static double exponent_array[10];
+ float vec[3];
+
+ /* precompute and store spectral weights */
+ if ( init ) {
+ start = 1;
+ srand( time(0) );
+ /* seize required memory for exponent_array */
+ frequency = 1.0;
+ for (i=0; i<=octaves; i++) {
+ /* compute weight for each frequency */
+ exponent_array[i] = pow( frequency, -H );
+ frequency *= lacunarity;
+ }
+ }
+
+ value = 0.0; /* initialize vars to proper values */
+ frequency = 1.0;
+ vec[0]=point.x;
+ vec[1]=point.y;
+ vec[2]=point.z;
+
+
+ /* inner loop of spectral construction */
+ for (i=0; i<octaves; i++) {
+ /* value += noise3( vec ) * exponent_array[i];*/
+ value += noise3( vec ) * exponent_array[i];
+ vec[0] *= lacunarity;
+ vec[1] *= lacunarity;
+ vec[2] *= lacunarity;
+ } /* for */
+
+ remainder = octaves - (int)octaves;
+ if ( remainder ) /* add in ``octaves'' remainder */
+ /* ``i'' and spatial freq. are preset in loop above */
+ value += remainder * noise3( vec ) * exponent_array[i];
+
+ return( value );
+
+} /* fBm() */
+
+
+float noise3(float vec[3])
+{
+ int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
+ float rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v;
+ register int i, j;
+
+ if (start) {
+ start = 0;
+ init();
+ }
+
+ setup(0, bx0,bx1, rx0,rx1);
+ setup(1, by0,by1, ry0,ry1);
+ setup(2, bz0,bz1, rz0,rz1);
+
+ i = p[ bx0 ];
+ j = p[ bx1 ];
+
+ b00 = p[ i + by0 ];
+ b10 = p[ j + by0 ];
+ b01 = p[ i + by1 ];
+ b11 = p[ j + by1 ];
+
+ t = s_curve(rx0);
+ sy = s_curve(ry0);
+ sz = s_curve(rz0);
+
+
+ q = g3[ b00 + bz0 ] ; u = at3(rx0,ry0,rz0);
+ q = g3[ b10 + bz0 ] ; v = at3(rx1,ry0,rz0);
+ a = lerp(t, u, v);
+
+ q = g3[ b01 + bz0 ] ; u = at3(rx0,ry1,rz0);
+ q = g3[ b11 + bz0 ] ; v = at3(rx1,ry1,rz0);
+ b = lerp(t, u, v);
+
+ c = lerp(sy, a, b);
+
+ q = g3[ b00 + bz1 ] ; u = at3(rx0,ry0,rz1);
+ q = g3[ b10 + bz1 ] ; v = at3(rx1,ry0,rz1);
+ a = lerp(t, u, v);
+
+ q = g3[ b01 + bz1 ] ; u = at3(rx0,ry1,rz1);
+ q = g3[ b11 + bz1 ] ; v = at3(rx1,ry1,rz1);
+ b = lerp(t, u, v);
+
+ d = lerp(sy, a, b);
+
+ return lerp(sz, c, d);
+}
+
+static void normalize2(float v[2])
+{
+ float s;
+
+ s = sqrt(v[0] * v[0] + v[1] * v[1]);
+ v[0] = v[0] / s;
+ v[1] = v[1] / s;
+}
+
+static void normalize3(float v[3])
+{
+ float s;
+
+ s = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
+ v[0] = v[0] / s;
+ v[1] = v[1] / s;
+ v[2] = v[2] / s;
+}
+
+static void init(void)
+{
+ int i, j, k;
+
+ for (i = 0 ; i < B ; i++) {
+ p[i] = i;
+
+ g1[i] = (float)((rand() % (B + B)) - B) / B;
+
+ for (j = 0 ; j < 2 ; j++)
+ g2[i][j] = (float)((rand() % (B + B)) - B) / B;
+ normalize2(g2[i]);
+
+ for (j = 0 ; j < 3 ; j++)
+ g3[i][j] = (float)((rand() % (B + B)) - B) / B;
+ normalize3(g3[i]);
+ }
+
+ while (--i) {
+ k = p[i];
+ p[i] = p[j = rand() % B];
+ p[j] = k;
+ }
+
+ for (i = 0 ; i < B + 2 ; i++) {
+ p[B + i] = p[i];
+ g1[B + i] = g1[i];
+ for (j = 0 ; j < 2 ; j++)
+ g2[B + i][j] = g2[i][j];
+ for (j = 0 ; j < 3 ; j++)
+ g3[B + i][j] = g3[i][j];
+ }
+}
diff --git a/examples/widgets/graphicsview/boxes/3rdparty/fbm.h b/examples/widgets/graphicsview/boxes/3rdparty/fbm.h
new file mode 100644
index 0000000000..b8a4a99ae4
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/3rdparty/fbm.h
@@ -0,0 +1,40 @@
+/*****************************************************************
+
+ Prototypes for the fractional Brownian motion algorithm. These
+ functions were originally the work of F. Kenton Musgrave. For
+ documentation of the different functions please refer to the book:
+ "Texturing and modeling: a procedural approach"
+ by David S. Ebert et. al.
+
+******************************************************************/
+
+#ifndef _fbm_h
+#define _fbm_h
+
+#include <math.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//#define TRUE 1
+//#define FALSE 0
+
+typedef struct {
+ double x;
+ double y;
+ double z;
+} Vector;
+
+float noise3(float vec[]);
+double fBm( Vector point, double H, double lacunarity, double octaves,
+ int init );
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+
diff --git a/examples/widgets/graphicsview/boxes/basic.fsh b/examples/widgets/graphicsview/boxes/basic.fsh
new file mode 100644
index 0000000000..917dbbaa0b
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/basic.fsh
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+varying vec3 position, normal;
+varying vec4 specular, ambient, diffuse, lightDirection;
+
+uniform sampler2D tex;
+uniform vec4 basicColor;
+
+void main()
+{
+ vec3 N = normalize(normal);
+ // assume directional light
+
+ gl_MaterialParameters M = gl_FrontMaterial;
+
+ float NdotL = dot(N, lightDirection.xyz);
+ float RdotL = dot(reflect(normalize(position), N), lightDirection.xyz);
+
+ vec3 absN = abs(gl_TexCoord[1].xyz);
+ vec3 texCoord;
+ if (absN.x > absN.y && absN.x > absN.z)
+ texCoord = gl_TexCoord[1].yzx;
+ else if (absN.y > absN.z)
+ texCoord = gl_TexCoord[1].zxy;
+ else
+ texCoord = gl_TexCoord[1].xyz;
+ texCoord.y *= -sign(texCoord.z);
+ texCoord += 0.5;
+
+ vec4 texColor = texture2D(tex, texCoord.xy);
+ vec4 unlitColor = gl_Color * mix(basicColor, vec4(texColor.xyz, 1.0), texColor.w);
+ gl_FragColor = (ambient + diffuse * max(NdotL, 0.0)) * unlitColor +
+ M.specular * specular * pow(max(RdotL, 0.0), M.shininess);
+}
diff --git a/examples/widgets/graphicsview/boxes/basic.vsh b/examples/widgets/graphicsview/boxes/basic.vsh
new file mode 100644
index 0000000000..db34a1a0d3
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/basic.vsh
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+varying vec3 position, normal;
+varying vec4 specular, ambient, diffuse, lightDirection;
+
+uniform mat4 view;
+
+void main()
+{
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+ gl_TexCoord[1] = gl_Vertex;
+ specular = gl_LightSource[0].specular;
+ ambient = gl_LightSource[0].ambient;
+ diffuse = gl_LightSource[0].diffuse;
+ lightDirection = view * gl_LightSource[0].position;
+
+ normal = gl_NormalMatrix * gl_Normal;
+ position = (gl_ModelViewMatrix * gl_Vertex).xyz;
+
+ gl_FrontColor = gl_Color;
+ gl_Position = ftransform();
+}
diff --git a/examples/widgets/graphicsview/boxes/boxes.pro b/examples/widgets/graphicsview/boxes/boxes.pro
new file mode 100644
index 0000000000..0564ae0ba6
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/boxes.pro
@@ -0,0 +1,39 @@
+QT += opengl widgets
+
+HEADERS += 3rdparty/fbm.h \
+ glbuffers.h \
+ glextensions.h \
+ gltrianglemesh.h \
+ qtbox.h \
+ roundedbox.h \
+ scene.h \
+ trackball.h
+SOURCES += 3rdparty/fbm.c \
+ glbuffers.cpp \
+ glextensions.cpp \
+ main.cpp \
+ qtbox.cpp \
+ roundedbox.cpp \
+ scene.cpp \
+ trackball.cpp
+
+RESOURCES += boxes.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/boxes
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html *.jpg *.png *.fsh *.vsh *.par
+sources.files -= 3rdparty/fbm.h 3rdparty/fbm.c
+sources.files += 3rdparty
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/boxes
+INSTALLS += target sources
+
+wince*: {
+ DEPLOYMENT_PLUGIN += qjpeg
+}
+
+win32-msvc* {
+ QMAKE_CXXFLAGS -= -Zm200
+ QMAKE_CFLAGS -= -Zm200
+ QMAKE_CXXFLAGS += -Zm500
+ QMAKE_CFLAGS += -Zm500
+}
diff --git a/examples/widgets/graphicsview/boxes/boxes.qrc b/examples/widgets/graphicsview/boxes/boxes.qrc
new file mode 100644
index 0000000000..d27506dc5a
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/boxes.qrc
@@ -0,0 +1,25 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res/boxes">
+ <file>cubemap_negx.jpg</file>
+ <file>cubemap_negy.jpg</file>
+ <file>cubemap_negz.jpg</file>
+ <file>cubemap_posx.jpg</file>
+ <file>cubemap_posy.jpg</file>
+ <file>cubemap_posz.jpg</file>
+ <file>square.jpg</file>
+ <file>basic.vsh</file>
+ <file>basic.fsh</file>
+ <file>dotted.fsh</file>
+ <file>fresnel.fsh</file>
+ <file>glass.fsh</file>
+ <file>granite.fsh</file>
+ <file>marble.fsh</file>
+ <file>reflection.fsh</file>
+ <file>refraction.fsh</file>
+ <file>wood.fsh</file>
+ <file>parameters.par</file>
+ <file>qt-logo.png</file>
+ <file>smiley.png</file>
+ <file>qt-logo.jpg</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/graphicsview/boxes/cubemap_negx.jpg b/examples/widgets/graphicsview/boxes/cubemap_negx.jpg
new file mode 100644
index 0000000000..07c282eab9
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/cubemap_negx.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/boxes/cubemap_negy.jpg b/examples/widgets/graphicsview/boxes/cubemap_negy.jpg
new file mode 100644
index 0000000000..46cd2f9cf3
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/cubemap_negy.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/boxes/cubemap_negz.jpg b/examples/widgets/graphicsview/boxes/cubemap_negz.jpg
new file mode 100644
index 0000000000..40c01ddff3
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/cubemap_negz.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/boxes/cubemap_posx.jpg b/examples/widgets/graphicsview/boxes/cubemap_posx.jpg
new file mode 100644
index 0000000000..0b42e8a1b1
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/cubemap_posx.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/boxes/cubemap_posy.jpg b/examples/widgets/graphicsview/boxes/cubemap_posy.jpg
new file mode 100644
index 0000000000..2aca9b1e98
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/cubemap_posy.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/boxes/cubemap_posz.jpg b/examples/widgets/graphicsview/boxes/cubemap_posz.jpg
new file mode 100644
index 0000000000..2e49173848
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/cubemap_posz.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/boxes/dotted.fsh b/examples/widgets/graphicsview/boxes/dotted.fsh
new file mode 100644
index 0000000000..2fe32b3b89
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/dotted.fsh
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+varying vec3 position, normal;
+varying vec4 specular, ambient, diffuse, lightDirection;
+
+uniform sampler2D tex;
+
+void main()
+{
+ vec3 N = normalize(normal);
+
+ gl_MaterialParameters M = gl_FrontMaterial;
+
+ // assume directional light
+ float NdotL = dot(N, lightDirection.xyz);
+ float RdotL = dot(reflect(normalize(position), N), lightDirection.xyz);
+
+ float r1 = length(fract(7.0 * gl_TexCoord[1].xyz) - 0.5);
+ float r2 = length(fract(5.0 * gl_TexCoord[1].xyz + 0.2) - 0.5);
+ float r3 = length(fract(11.0 * gl_TexCoord[1].xyz + 0.7) - 0.5);
+ vec4 rs = vec4(r1, r2, r3, 0.0);
+
+ vec4 unlitColor = gl_Color * (0.8 - clamp(10.0 * (0.4 - rs), 0.0, 0.2));
+ unlitColor.w = 1.0;
+ gl_FragColor = (ambient + diffuse * max(NdotL, 0.0)) * unlitColor +
+ M.specular * specular * pow(max(RdotL, 0.0), M.shininess);
+}
diff --git a/examples/widgets/graphicsview/boxes/fresnel.fsh b/examples/widgets/graphicsview/boxes/fresnel.fsh
new file mode 100644
index 0000000000..8750dd9f20
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/fresnel.fsh
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+varying vec3 position, normal;
+varying vec4 specular, ambient, diffuse, lightDirection;
+
+uniform sampler2D tex;
+uniform samplerCube env;
+uniform mat4 view;
+uniform vec4 basicColor;
+
+void main()
+{
+ vec3 N = normalize(normal);
+ // assume directional light
+
+ gl_MaterialParameters M = gl_FrontMaterial;
+
+ float NdotL = dot(N, lightDirection.xyz);
+ float RdotL = dot(reflect(normalize(position), N), lightDirection.xyz);
+
+ vec3 absN = abs(gl_TexCoord[1].xyz);
+ vec3 texCoord;
+ if (absN.x > absN.y && absN.x > absN.z)
+ texCoord = gl_TexCoord[1].yzx;
+ else if (absN.y > absN.z)
+ texCoord = gl_TexCoord[1].zxy;
+ else
+ texCoord = gl_TexCoord[1].xyz;
+ texCoord.y *= -sign(texCoord.z);
+ texCoord += 0.5;
+
+ vec4 texColor = texture2D(tex, texCoord.xy);
+ vec4 unlitColor = gl_Color * mix(basicColor, vec4(texColor.xyz, 1.0), texColor.w);
+ vec4 litColor = (ambient + diffuse * max(NdotL, 0.0)) * unlitColor +
+ M.specular * specular * pow(max(RdotL, 0.0), M.shininess);
+
+ vec3 R = 2.0 * dot(-position, N) * N + position;
+ vec4 reflectedColor = textureCube(env, R * mat3(view[0].xyz, view[1].xyz, view[2].xyz));
+ gl_FragColor = mix(litColor, reflectedColor, 0.2 + 0.8 * pow(1.0 + dot(N, normalize(position)), 2.0));
+}
diff --git a/examples/widgets/graphicsview/boxes/glass.fsh b/examples/widgets/graphicsview/boxes/glass.fsh
new file mode 100644
index 0000000000..d635b2cdc3
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/glass.fsh
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+varying vec3 position, normal;
+varying vec4 specular, ambient, diffuse, lightDirection;
+
+uniform sampler2D tex;
+uniform samplerCube env;
+uniform mat4 view;
+
+// Some arbitrary values
+// Arrays don't work here on glsl < 120, apparently.
+//const float coeffs[6] = float[6](1.0/4.0, 1.0/4.1, 1.0/4.2, 1.0/4.3, 1.0/4.4, 1.0/4.5);
+float coeffs(int i)
+{
+ return 1.0 / (3.0 + 0.1 * float(i));
+}
+
+void main()
+{
+ vec3 N = normalize(normal);
+ vec3 I = -normalize(position);
+ mat3 V = mat3(view[0].xyz, view[1].xyz, view[2].xyz);
+ float IdotN = dot(I, N);
+ float scales[6];
+ vec3 C[6];
+ for (int i = 0; i < 6; ++i) {
+ scales[i] = (IdotN - sqrt(1.0 - coeffs(i) + coeffs(i) * (IdotN * IdotN)));
+ C[i] = textureCube(env, (-I + coeffs(i) * N) * V).xyz;
+ }
+ vec4 refractedColor = 0.25 * vec4(C[5].x + 2.0*C[0].x + C[1].x, C[1].y + 2.0*C[2].y + C[3].y,
+ C[3].z + 2.0*C[4].z + C[5].z, 4.0);
+
+ vec3 R = 2.0 * dot(-position, N) * N + position;
+ vec4 reflectedColor = textureCube(env, R * V);
+
+ gl_FragColor = mix(refractedColor, reflectedColor, 0.4 + 0.6 * pow(1.0 - IdotN, 2.0));
+}
diff --git a/examples/widgets/graphicsview/boxes/glbuffers.cpp b/examples/widgets/graphicsview/boxes/glbuffers.cpp
new file mode 100644
index 0000000000..e2aa2a4789
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/glbuffers.cpp
@@ -0,0 +1,402 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "glbuffers.h"
+#include <QtGui/qmatrix4x4.h>
+
+
+void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
+{
+ const GLdouble ymax = zNear * tan(fovy * M_PI / 360.0);
+ const GLdouble ymin = -ymax;
+ const GLdouble xmin = ymin * aspect;
+ const GLdouble xmax = ymax * aspect;
+ glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
+}
+
+//============================================================================//
+// GLTexture //
+//============================================================================//
+
+GLTexture::GLTexture() : m_texture(0), m_failed(false)
+{
+ glGenTextures(1, &m_texture);
+}
+
+GLTexture::~GLTexture()
+{
+ glDeleteTextures(1, &m_texture);
+}
+
+//============================================================================//
+// GLTexture2D //
+//============================================================================//
+
+GLTexture2D::GLTexture2D(int width, int height)
+{
+ glBindTexture(GL_TEXTURE_2D, m_texture);
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0,
+ GL_BGRA, GL_UNSIGNED_BYTE, 0);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
+ glBindTexture(GL_TEXTURE_2D, 0);
+}
+
+
+GLTexture2D::GLTexture2D(const QString& fileName, int width, int height)
+{
+ // TODO: Add error handling.
+ QImage image(fileName);
+
+ if (image.isNull()) {
+ m_failed = true;
+ return;
+ }
+
+ image = image.convertToFormat(QImage::Format_ARGB32);
+
+ //qDebug() << "Image size:" << image.width() << "x" << image.height();
+ if (width <= 0)
+ width = image.width();
+ if (height <= 0)
+ height = image.height();
+ if (width != image.width() || height != image.height())
+ image = image.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+
+ glBindTexture(GL_TEXTURE_2D, m_texture);
+
+ // Works on x86, so probably works on all little-endian systems.
+ // Does it work on big-endian systems?
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, image.width(), image.height(), 0,
+ GL_BGRA, GL_UNSIGNED_BYTE, image.bits());
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
+ glBindTexture(GL_TEXTURE_2D, 0);
+}
+
+void GLTexture2D::load(int width, int height, QRgb *data)
+{
+ glBindTexture(GL_TEXTURE_2D, m_texture);
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0,
+ GL_BGRA, GL_UNSIGNED_BYTE, data);
+ glBindTexture(GL_TEXTURE_2D, 0);
+}
+
+void GLTexture2D::bind()
+{
+ glBindTexture(GL_TEXTURE_2D, m_texture);
+ glEnable(GL_TEXTURE_2D);
+}
+
+void GLTexture2D::unbind()
+{
+ glBindTexture(GL_TEXTURE_2D, 0);
+ glDisable(GL_TEXTURE_2D);
+}
+
+
+//============================================================================//
+// GLTexture3D //
+//============================================================================//
+
+GLTexture3D::GLTexture3D(int width, int height, int depth)
+{
+ GLBUFFERS_ASSERT_OPENGL("GLTexture3D::GLTexture3D", glTexImage3D, return)
+
+ glBindTexture(GL_TEXTURE_3D, m_texture);
+ glTexImage3D(GL_TEXTURE_3D, 0, 4, width, height, depth, 0,
+ GL_BGRA, GL_UNSIGNED_BYTE, 0);
+
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ //glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ //glTexParameteri(GL_TEXTURE_3D, GL_GENERATE_MIPMAP, GL_TRUE);
+ glBindTexture(GL_TEXTURE_3D, 0);
+}
+
+void GLTexture3D::load(int width, int height, int depth, QRgb *data)
+{
+ GLBUFFERS_ASSERT_OPENGL("GLTexture3D::load", glTexImage3D, return)
+
+ glBindTexture(GL_TEXTURE_3D, m_texture);
+ glTexImage3D(GL_TEXTURE_3D, 0, 4, width, height, depth, 0,
+ GL_BGRA, GL_UNSIGNED_BYTE, data);
+ glBindTexture(GL_TEXTURE_3D, 0);
+}
+
+void GLTexture3D::bind()
+{
+ glBindTexture(GL_TEXTURE_3D, m_texture);
+ glEnable(GL_TEXTURE_3D);
+}
+
+void GLTexture3D::unbind()
+{
+ glBindTexture(GL_TEXTURE_3D, 0);
+ glDisable(GL_TEXTURE_3D);
+}
+
+//============================================================================//
+// GLTextureCube //
+//============================================================================//
+
+GLTextureCube::GLTextureCube(int size)
+{
+ glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture);
+
+ for (int i = 0; i < 6; ++i)
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 4, size, size, 0,
+ GL_BGRA, GL_UNSIGNED_BYTE, 0);
+
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ //glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ //glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
+}
+
+GLTextureCube::GLTextureCube(const QStringList& fileNames, int size)
+{
+ // TODO: Add error handling.
+
+ glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture);
+
+ int index = 0;
+ foreach (QString file, fileNames) {
+ QImage image(file);
+ if (image.isNull()) {
+ m_failed = true;
+ break;
+ }
+
+ image = image.convertToFormat(QImage::Format_ARGB32);
+
+ //qDebug() << "Image size:" << image.width() << "x" << image.height();
+ if (size <= 0)
+ size = image.width();
+ if (size != image.width() || size != image.height())
+ image = image.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+
+ // Works on x86, so probably works on all little-endian systems.
+ // Does it work on big-endian systems?
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, 4, image.width(), image.height(), 0,
+ GL_BGRA, GL_UNSIGNED_BYTE, image.bits());
+
+ if (++index == 6)
+ break;
+ }
+
+ // Clear remaining faces.
+ while (index < 6) {
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, 4, size, size, 0,
+ GL_BGRA, GL_UNSIGNED_BYTE, 0);
+ ++index;
+ }
+
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ //glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ //glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
+}
+
+void GLTextureCube::load(int size, int face, QRgb *data)
+{
+ glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, 4, size, size, 0,
+ GL_BGRA, GL_UNSIGNED_BYTE, data);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
+}
+
+void GLTextureCube::bind()
+{
+ glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture);
+ glEnable(GL_TEXTURE_CUBE_MAP);
+}
+
+void GLTextureCube::unbind()
+{
+ glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
+ glDisable(GL_TEXTURE_CUBE_MAP);
+}
+
+//============================================================================//
+// GLFrameBufferObject //
+//============================================================================//
+
+GLFrameBufferObject::GLFrameBufferObject(int width, int height)
+ : m_fbo(0)
+ , m_depthBuffer(0)
+ , m_width(width)
+ , m_height(height)
+ , m_failed(false)
+{
+ GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::GLFrameBufferObject",
+ glGenFramebuffersEXT && glGenRenderbuffersEXT && glBindRenderbufferEXT && glRenderbufferStorageEXT, return)
+
+ // TODO: share depth buffers of same size
+ glGenFramebuffersEXT(1, &m_fbo);
+ //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
+ glGenRenderbuffersEXT(1, &m_depthBuffer);
+ glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthBuffer);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, m_width, m_height);
+ //glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBuffer);
+ //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+}
+
+GLFrameBufferObject::~GLFrameBufferObject()
+{
+ GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::~GLFrameBufferObject",
+ glDeleteFramebuffersEXT && glDeleteRenderbuffersEXT, return)
+
+ glDeleteFramebuffersEXT(1, &m_fbo);
+ glDeleteRenderbuffersEXT(1, &m_depthBuffer);
+}
+
+void GLFrameBufferObject::setAsRenderTarget(bool state)
+{
+ GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::setAsRenderTarget", glBindFramebufferEXT, return)
+
+ if (state) {
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
+ glPushAttrib(GL_VIEWPORT_BIT);
+ glViewport(0, 0, m_width, m_height);
+ } else {
+ glPopAttrib();
+ glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ }
+}
+
+bool GLFrameBufferObject::isComplete()
+{
+ GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::isComplete", glCheckFramebufferStatusEXT, return false)
+
+ return GL_FRAMEBUFFER_COMPLETE_EXT == glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+}
+
+//============================================================================//
+// GLRenderTargetCube //
+//============================================================================//
+
+GLRenderTargetCube::GLRenderTargetCube(int size)
+ : GLTextureCube(size)
+ , m_fbo(size, size)
+{
+}
+
+void GLRenderTargetCube::begin(int face)
+{
+ GLBUFFERS_ASSERT_OPENGL("GLRenderTargetCube::begin",
+ glFramebufferTexture2DEXT && glFramebufferRenderbufferEXT, return)
+
+ m_fbo.setAsRenderTarget(true);
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, m_texture, 0);
+ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_fbo.m_depthBuffer);
+}
+
+void GLRenderTargetCube::end()
+{
+ m_fbo.setAsRenderTarget(false);
+}
+
+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);
+ return;
+ }
+
+ static int perm[6][3] = {
+ {2, 1, 0},
+ {2, 1, 0},
+ {0, 2, 1},
+ {0, 2, 1},
+ {0, 1, 2},
+ {0, 1, 2},
+ };
+
+ static float signs[6][3] = {
+ {-1.0f, -1.0f, -1.0f},
+ {+1.0f, -1.0f, +1.0f},
+ {+1.0f, +1.0f, -1.0f},
+ {+1.0f, -1.0f, +1.0f},
+ {+1.0f, -1.0f, -1.0f},
+ {-1.0f, -1.0f, +1.0f},
+ };
+
+ mat.fill(0.0f);
+ for (int i = 0; i < 3; ++i)
+ mat(i, perm[face][i]) = signs[face][i];
+ mat(3, 3) = 1.0f;
+}
+
+void GLRenderTargetCube::getProjectionMatrix(QMatrix4x4& mat, float nearZ, float farZ)
+{
+ 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/examples/widgets/graphicsview/boxes/glbuffers.h b/examples/widgets/graphicsview/boxes/glbuffers.h
new file mode 100644
index 0000000000..2b91915e8e
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/glbuffers.h
@@ -0,0 +1,366 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLBUFFERS_H
+#define GLBUFFERS_H
+
+//#include <GL/glew.h>
+#include "glextensions.h"
+
+#include <QtWidgets>
+#include <QtOpenGL>
+
+#define BUFFER_OFFSET(i) ((char*)0 + (i))
+#define SIZE_OF_MEMBER(cls, member) sizeof(static_cast<cls *>(0)->member)
+
+#define GLBUFFERS_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; \
+}
+
+void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
+
+QT_BEGIN_NAMESPACE
+class QMatrix4x4;
+QT_END_NAMESPACE
+
+class GLTexture
+{
+public:
+ GLTexture();
+ virtual ~GLTexture();
+ virtual void bind() = 0;
+ virtual void unbind() = 0;
+ virtual bool failed() const {return m_failed;}
+protected:
+ GLuint m_texture;
+ bool m_failed;
+};
+
+class GLFrameBufferObject
+{
+public:
+ friend class GLRenderTargetCube;
+ // friend class GLRenderTarget2D;
+
+ GLFrameBufferObject(int width, int height);
+ virtual ~GLFrameBufferObject();
+ bool isComplete();
+ virtual bool failed() const {return m_failed;}
+protected:
+ void setAsRenderTarget(bool state = true);
+ GLuint m_fbo;
+ GLuint m_depthBuffer;
+ int m_width, m_height;
+ bool m_failed;
+};
+
+class GLTexture2D : public GLTexture
+{
+public:
+ GLTexture2D(int width, int height);
+ GLTexture2D(const QString& fileName, int width = 0, int height = 0);
+ void load(int width, int height, QRgb *data);
+ virtual void bind();
+ virtual void unbind();
+};
+
+class GLTexture3D : public GLTexture
+{
+public:
+ GLTexture3D(int width, int height, int depth);
+ // TODO: Implement function below
+ //GLTexture3D(const QString& fileName, int width = 0, int height = 0);
+ void load(int width, int height, int depth, QRgb *data);
+ virtual void bind();
+ virtual void unbind();
+};
+
+class GLTextureCube : public GLTexture
+{
+public:
+ GLTextureCube(int size);
+ GLTextureCube(const QStringList& fileNames, int size = 0);
+ void load(int size, int face, QRgb *data);
+ virtual void bind();
+ virtual void unbind();
+};
+
+// TODO: Define and implement class below
+//class GLRenderTarget2D : public GLTexture2D
+
+class GLRenderTargetCube : public GLTextureCube
+{
+public:
+ GLRenderTargetCube(int size);
+ // begin rendering to one of the cube's faces. 0 <= face < 6
+ void begin(int face);
+ // end rendering
+ void end();
+ virtual bool failed() const {return m_failed || m_fbo.failed();}
+
+ static void getViewMatrix(QMatrix4x4& mat, int face);
+ static void getProjectionMatrix(QMatrix4x4& mat, float nearZ, float farZ);
+private:
+ GLFrameBufferObject m_fbo;
+};
+
+struct VertexDescription
+{
+ enum
+ {
+ Null = 0, // Terminates a VertexDescription array
+ Position,
+ TexCoord,
+ Normal,
+ Color,
+ };
+ int field; // Position, TexCoord, Normal, Color
+ int type; // GL_FLOAT, GL_UNSIGNED_BYTE
+ int count; // number of elements
+ int offset; // field's offset into vertex struct
+ int index; // 0 (unused at the moment)
+};
+
+// Implementation of interleaved buffers.
+// 'T' is a struct which must include a null-terminated static array
+// 'VertexDescription* description'.
+// Example:
+/*
+struct Vertex
+{
+ GLfloat position[3];
+ GLfloat texCoord[2];
+ GLfloat normal[3];
+ GLbyte color[4];
+ static VertexDescription description[];
+};
+
+VertexDescription Vertex::description[] = {
+ {VertexDescription::Position, GL_FLOAT, SIZE_OF_MEMBER(Vertex, position) / sizeof(GLfloat), offsetof(Vertex, position), 0},
+ {VertexDescription::TexCoord, GL_FLOAT, SIZE_OF_MEMBER(Vertex, texCoord) / sizeof(GLfloat), offsetof(Vertex, texCoord), 0},
+ {VertexDescription::Normal, GL_FLOAT, SIZE_OF_MEMBER(Vertex, normal) / sizeof(GLfloat), offsetof(Vertex, normal), 0},
+ {VertexDescription::Color, GL_BYTE, SIZE_OF_MEMBER(Vertex, color) / sizeof(GLbyte), offsetof(Vertex, color), 0},
+ {VertexDescription::Null, 0, 0, 0, 0},
+};
+*/
+template<class T>
+class GLVertexBuffer
+{
+public:
+ GLVertexBuffer(int length, const T *data = 0, int mode = GL_STATIC_DRAW)
+ : m_length(0)
+ , m_mode(mode)
+ , m_buffer(0)
+ , m_failed(false)
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::GLVertexBuffer", glGenBuffers && glBindBuffer && glBufferData, return)
+
+ glGenBuffers(1, &m_buffer);
+ glBindBuffer(GL_ARRAY_BUFFER, m_buffer);
+ glBufferData(GL_ARRAY_BUFFER, (m_length = length) * sizeof(T), data, mode);
+ }
+
+ ~GLVertexBuffer()
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::~GLVertexBuffer", glDeleteBuffers, return)
+
+ glDeleteBuffers(1, &m_buffer);
+ }
+
+ void bind()
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::bind", glBindBuffer, return)
+
+ glBindBuffer(GL_ARRAY_BUFFER, m_buffer);
+ for (VertexDescription *desc = T::description; desc->field != VertexDescription::Null; ++desc) {
+ switch (desc->field) {
+ case VertexDescription::Position:
+ glVertexPointer(desc->count, desc->type, sizeof(T), BUFFER_OFFSET(desc->offset));
+ glEnableClientState(GL_VERTEX_ARRAY);
+ break;
+ case VertexDescription::TexCoord:
+ glTexCoordPointer(desc->count, desc->type, sizeof(T), BUFFER_OFFSET(desc->offset));
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ break;
+ case VertexDescription::Normal:
+ glNormalPointer(desc->type, sizeof(T), BUFFER_OFFSET(desc->offset));
+ glEnableClientState(GL_NORMAL_ARRAY);
+ break;
+ case VertexDescription::Color:
+ glColorPointer(desc->count, desc->type, sizeof(T), BUFFER_OFFSET(desc->offset));
+ glEnableClientState(GL_COLOR_ARRAY);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ void unbind()
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::unbind", glBindBuffer, return)
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ for (VertexDescription *desc = T::description; desc->field != VertexDescription::Null; ++desc) {
+ switch (desc->field) {
+ case VertexDescription::Position:
+ glDisableClientState(GL_VERTEX_ARRAY);
+ break;
+ case VertexDescription::TexCoord:
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ break;
+ case VertexDescription::Normal:
+ glDisableClientState(GL_NORMAL_ARRAY);
+ break;
+ case VertexDescription::Color:
+ glDisableClientState(GL_COLOR_ARRAY);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ int length() const {return m_length;}
+
+ T *lock()
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::lock", glBindBuffer && glMapBuffer, return 0)
+
+ glBindBuffer(GL_ARRAY_BUFFER, m_buffer);
+ //glBufferData(GL_ARRAY_BUFFER, m_length, NULL, m_mode);
+ GLvoid* buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
+ m_failed = (buffer == 0);
+ return reinterpret_cast<T *>(buffer);
+ }
+
+ void unlock()
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::unlock", glBindBuffer && glUnmapBuffer, return)
+
+ glBindBuffer(GL_ARRAY_BUFFER, m_buffer);
+ glUnmapBuffer(GL_ARRAY_BUFFER);
+ }
+
+ bool failed()
+ {
+ return m_failed;
+ }
+
+private:
+ int m_length, m_mode;
+ GLuint m_buffer;
+ bool m_failed;
+};
+
+template<class T>
+class GLIndexBuffer
+{
+public:
+ GLIndexBuffer(int length, const T *data = 0, int mode = GL_STATIC_DRAW)
+ : m_length(0)
+ , m_mode(mode)
+ , m_buffer(0)
+ , m_failed(false)
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::GLIndexBuffer", glGenBuffers && glBindBuffer && glBufferData, return)
+
+ glGenBuffers(1, &m_buffer);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffer);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, (m_length = length) * sizeof(T), data, mode);
+ }
+
+ ~GLIndexBuffer()
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::~GLIndexBuffer", glDeleteBuffers, return)
+
+ glDeleteBuffers(1, &m_buffer);
+ }
+
+ void bind()
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::bind", glBindBuffer, return)
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffer);
+ }
+
+ void unbind()
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::unbind", glBindBuffer, return)
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ }
+
+ int length() const {return m_length;}
+
+ T *lock()
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::lock", glBindBuffer && glMapBuffer, return 0)
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffer);
+ GLvoid* buffer = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_WRITE);
+ m_failed = (buffer == 0);
+ return reinterpret_cast<T *>(buffer);
+ }
+
+ void unlock()
+ {
+ GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::unlock", glBindBuffer && glUnmapBuffer, return)
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffer);
+ glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
+ }
+
+ bool failed()
+ {
+ return m_failed;
+ }
+
+private:
+ int m_length, m_mode;
+ GLuint m_buffer;
+ bool m_failed;
+};
+
+#endif
diff --git a/examples/widgets/graphicsview/boxes/glextensions.cpp b/examples/widgets/graphicsview/boxes/glextensions.cpp
new file mode 100644
index 0000000000..ada8f457f6
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/glextensions.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "glextensions.h"
+
+#define RESOLVE_GL_FUNC(f) ok &= bool((f = (_gl##f) context->getProcAddress(QLatin1String("gl" #f))));
+
+bool GLExtensionFunctions::resolve(const QGLContext *context)
+{
+ bool ok = true;
+
+ RESOLVE_GL_FUNC(GenFramebuffersEXT)
+ RESOLVE_GL_FUNC(GenRenderbuffersEXT)
+ RESOLVE_GL_FUNC(BindRenderbufferEXT)
+ RESOLVE_GL_FUNC(RenderbufferStorageEXT)
+ RESOLVE_GL_FUNC(DeleteFramebuffersEXT)
+ RESOLVE_GL_FUNC(DeleteRenderbuffersEXT)
+ RESOLVE_GL_FUNC(BindFramebufferEXT)
+ RESOLVE_GL_FUNC(FramebufferTexture2DEXT)
+ RESOLVE_GL_FUNC(FramebufferRenderbufferEXT)
+ RESOLVE_GL_FUNC(CheckFramebufferStatusEXT)
+
+ RESOLVE_GL_FUNC(ActiveTexture)
+ RESOLVE_GL_FUNC(TexImage3D)
+
+ RESOLVE_GL_FUNC(GenBuffers)
+ RESOLVE_GL_FUNC(BindBuffer)
+ RESOLVE_GL_FUNC(BufferData)
+ RESOLVE_GL_FUNC(DeleteBuffers)
+ RESOLVE_GL_FUNC(MapBuffer)
+ RESOLVE_GL_FUNC(UnmapBuffer)
+
+ return ok;
+}
+
+bool GLExtensionFunctions::fboSupported() {
+ return GenFramebuffersEXT
+ && GenRenderbuffersEXT
+ && BindRenderbufferEXT
+ && RenderbufferStorageEXT
+ && DeleteFramebuffersEXT
+ && DeleteRenderbuffersEXT
+ && BindFramebufferEXT
+ && FramebufferTexture2DEXT
+ && FramebufferRenderbufferEXT
+ && CheckFramebufferStatusEXT;
+}
+
+bool GLExtensionFunctions::openGL15Supported() {
+ return ActiveTexture
+ && TexImage3D
+ && GenBuffers
+ && BindBuffer
+ && BufferData
+ && DeleteBuffers
+ && MapBuffer
+ && UnmapBuffer;
+}
+
+#undef RESOLVE_GL_FUNC
diff --git a/examples/widgets/graphicsview/boxes/glextensions.h b/examples/widgets/graphicsview/boxes/glextensions.h
new file mode 100644
index 0000000000..35dd9a047c
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/glextensions.h
@@ -0,0 +1,202 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLEXTENSIONS_H
+#define GLEXTENSIONS_H
+
+#include <QtOpenGL>
+
+/*
+Functions resolved:
+
+glGenFramebuffersEXT
+glGenRenderbuffersEXT
+glBindRenderbufferEXT
+glRenderbufferStorageEXT
+glDeleteFramebuffersEXT
+glDeleteRenderbuffersEXT
+glBindFramebufferEXT
+glFramebufferTexture2DEXT
+glFramebufferRenderbufferEXT
+glCheckFramebufferStatusEXT
+
+glActiveTexture
+glTexImage3D
+
+glGenBuffers
+glBindBuffer
+glBufferData
+glDeleteBuffers
+glMapBuffer
+glUnmapBuffer
+*/
+
+#ifndef Q_OS_MAC
+# ifndef APIENTRYP
+# ifdef APIENTRY
+# define APIENTRYP APIENTRY *
+# else
+# define APIENTRY
+# define APIENTRYP *
+# endif
+# endif
+#else
+# define APIENTRY
+# define APIENTRYP *
+#endif
+
+#ifndef GL_VERSION_1_2
+#define GL_TEXTURE_3D 0x806F
+#define GL_TEXTURE_WRAP_R 0x8072
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_BGRA 0x80E1
+#endif
+
+#ifndef GL_VERSION_1_3
+#define GL_TEXTURE0 0x84C0
+#define GL_TEXTURE1 0x84C1
+#define GL_TEXTURE2 0x84C2
+#define GL_TEXTURE_CUBE_MAP 0x8513
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+//#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+//#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+//#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+//#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+//#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#endif
+
+#ifndef GL_ARB_vertex_buffer_object
+typedef ptrdiff_t GLsizeiptrARB;
+#endif
+
+#ifndef GL_VERSION_1_5
+#define GL_ARRAY_BUFFER 0x8892
+#define GL_ELEMENT_ARRAY_BUFFER 0x8893
+#define GL_READ_WRITE 0x88BA
+#define GL_STATIC_DRAW 0x88E4
+#endif
+
+#ifndef GL_EXT_framebuffer_object
+#define GL_RENDERBUFFER_EXT 0x8D41
+#define GL_FRAMEBUFFER_EXT 0x8D40
+#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
+#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
+#define GL_DEPTH_ATTACHMENT_EXT 0x8D00
+#endif
+
+typedef void (APIENTRY *_glGenFramebuffersEXT) (GLsizei, GLuint *);
+typedef void (APIENTRY *_glGenRenderbuffersEXT) (GLsizei, GLuint *);
+typedef void (APIENTRY *_glBindRenderbufferEXT) (GLenum, GLuint);
+typedef void (APIENTRY *_glRenderbufferStorageEXT) (GLenum, GLenum, GLsizei, GLsizei);
+typedef void (APIENTRY *_glDeleteFramebuffersEXT) (GLsizei, const GLuint*);
+typedef void (APIENTRY *_glDeleteRenderbuffersEXT) (GLsizei, const GLuint*);
+typedef void (APIENTRY *_glBindFramebufferEXT) (GLenum, GLuint);
+typedef void (APIENTRY *_glFramebufferTexture2DEXT) (GLenum, GLenum, GLenum, GLuint, GLint);
+typedef void (APIENTRY *_glFramebufferRenderbufferEXT) (GLenum, GLenum, GLenum, GLuint);
+typedef GLenum (APIENTRY *_glCheckFramebufferStatusEXT) (GLenum);
+
+typedef void (APIENTRY *_glActiveTexture) (GLenum);
+typedef void (APIENTRY *_glTexImage3D) (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *);
+
+typedef void (APIENTRY *_glGenBuffers) (GLsizei, GLuint *);
+typedef void (APIENTRY *_glBindBuffer) (GLenum, GLuint);
+typedef void (APIENTRY *_glBufferData) (GLenum, GLsizeiptrARB, const GLvoid *, GLenum);
+typedef void (APIENTRY *_glDeleteBuffers) (GLsizei, const GLuint *);
+typedef void *(APIENTRY *_glMapBuffer) (GLenum, GLenum);
+typedef GLboolean (APIENTRY *_glUnmapBuffer) (GLenum);
+
+struct GLExtensionFunctions
+{
+ bool resolve(const QGLContext *context);
+
+ bool fboSupported();
+ bool openGL15Supported(); // the rest: multi-texture, 3D-texture, vertex buffer objects
+
+ _glGenFramebuffersEXT GenFramebuffersEXT;
+ _glGenRenderbuffersEXT GenRenderbuffersEXT;
+ _glBindRenderbufferEXT BindRenderbufferEXT;
+ _glRenderbufferStorageEXT RenderbufferStorageEXT;
+ _glDeleteFramebuffersEXT DeleteFramebuffersEXT;
+ _glDeleteRenderbuffersEXT DeleteRenderbuffersEXT;
+ _glBindFramebufferEXT BindFramebufferEXT;
+ _glFramebufferTexture2DEXT FramebufferTexture2DEXT;
+ _glFramebufferRenderbufferEXT FramebufferRenderbufferEXT;
+ _glCheckFramebufferStatusEXT CheckFramebufferStatusEXT;
+
+ _glActiveTexture ActiveTexture;
+ _glTexImage3D TexImage3D;
+
+ _glGenBuffers GenBuffers;
+ _glBindBuffer BindBuffer;
+ _glBufferData BufferData;
+ _glDeleteBuffers DeleteBuffers;
+ _glMapBuffer MapBuffer;
+ _glUnmapBuffer UnmapBuffer;
+};
+
+inline GLExtensionFunctions &getGLExtensionFunctions()
+{
+ static GLExtensionFunctions funcs;
+ return funcs;
+}
+
+#define glGenFramebuffersEXT getGLExtensionFunctions().GenFramebuffersEXT
+#define glGenRenderbuffersEXT getGLExtensionFunctions().GenRenderbuffersEXT
+#define glBindRenderbufferEXT getGLExtensionFunctions().BindRenderbufferEXT
+#define glRenderbufferStorageEXT getGLExtensionFunctions().RenderbufferStorageEXT
+#define glDeleteFramebuffersEXT getGLExtensionFunctions().DeleteFramebuffersEXT
+#define glDeleteRenderbuffersEXT getGLExtensionFunctions().DeleteRenderbuffersEXT
+#define glBindFramebufferEXT getGLExtensionFunctions().BindFramebufferEXT
+#define glFramebufferTexture2DEXT getGLExtensionFunctions().FramebufferTexture2DEXT
+#define glFramebufferRenderbufferEXT getGLExtensionFunctions().FramebufferRenderbufferEXT
+#define glCheckFramebufferStatusEXT getGLExtensionFunctions().CheckFramebufferStatusEXT
+
+#define glActiveTexture getGLExtensionFunctions().ActiveTexture
+#define glTexImage3D getGLExtensionFunctions().TexImage3D
+
+#define glGenBuffers getGLExtensionFunctions().GenBuffers
+#define glBindBuffer getGLExtensionFunctions().BindBuffer
+#define glBufferData getGLExtensionFunctions().BufferData
+#define glDeleteBuffers getGLExtensionFunctions().DeleteBuffers
+#define glMapBuffer getGLExtensionFunctions().MapBuffer
+#define glUnmapBuffer getGLExtensionFunctions().UnmapBuffer
+
+#endif
diff --git a/examples/widgets/graphicsview/boxes/gltrianglemesh.h b/examples/widgets/graphicsview/boxes/gltrianglemesh.h
new file mode 100644
index 0000000000..2c9ab01c3f
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/gltrianglemesh.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLTRIANGLEMESH_H
+#define GLTRIANGLEMESH_H
+
+//#include <GL/glew.h>
+#include "glextensions.h"
+
+#include <QtWidgets>
+#include <QtOpenGL>
+
+#include "glbuffers.h"
+
+template<class TVertex, class TIndex>
+class GLTriangleMesh
+{
+public:
+ GLTriangleMesh(int vertexCount, int indexCount) : m_vb(vertexCount), m_ib(indexCount)
+ {
+ }
+
+ virtual ~GLTriangleMesh()
+ {
+ }
+
+ virtual void draw()
+ {
+ if (failed())
+ return;
+
+ int type = GL_UNSIGNED_INT;
+ if (sizeof(TIndex) == sizeof(char)) type = GL_UNSIGNED_BYTE;
+ if (sizeof(TIndex) == sizeof(short)) type = GL_UNSIGNED_SHORT;
+
+ m_vb.bind();
+ m_ib.bind();
+ glDrawElements(GL_TRIANGLES, m_ib.length(), type, BUFFER_OFFSET(0));
+ m_vb.unbind();
+ m_ib.unbind();
+ }
+
+ bool failed()
+ {
+ return m_vb.failed() || m_ib.failed();
+ }
+protected:
+ GLVertexBuffer<TVertex> m_vb;
+ GLIndexBuffer<TIndex> m_ib;
+};
+
+
+#endif
diff --git a/examples/widgets/graphicsview/boxes/granite.fsh b/examples/widgets/graphicsview/boxes/granite.fsh
new file mode 100644
index 0000000000..175420f351
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/granite.fsh
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+varying vec3 position, normal;
+varying vec4 specular, ambient, diffuse, lightDirection;
+
+uniform sampler2D tex;
+uniform sampler3D noise;
+
+//const vec4 graniteColors[3] = {vec4(0.0, 0.0, 0.0, 1), vec4(0.30, 0.15, 0.10, 1), vec4(0.80, 0.70, 0.75, 1)};
+uniform vec4 graniteColors[3];
+
+float steep(float x)
+{
+ return clamp(5.0 * x - 2.0, 0.0, 1.0);
+}
+
+void main()
+{
+ vec2 turbulence = vec2(0, 0);
+ float scale = 1.0;
+ for (int i = 0; i < 4; ++i) {
+ turbulence += scale * (texture3D(noise, gl_TexCoord[1].xyz / scale).xy - 0.5);
+ scale *= 0.5;
+ }
+
+ vec3 N = normalize(normal);
+ // assume directional light
+
+ gl_MaterialParameters M = gl_FrontMaterial;
+
+ float NdotL = dot(N, lightDirection.xyz);
+ float RdotL = dot(reflect(normalize(position), N), lightDirection.xyz);
+
+ vec4 unlitColor = mix(graniteColors[1], mix(graniteColors[0], graniteColors[2], steep(0.5 + turbulence.y)), 4.0 * abs(turbulence.x));
+ gl_FragColor = (ambient + diffuse * max(NdotL, 0.0)) * unlitColor +
+ M.specular * specular * pow(max(RdotL, 0.0), M.shininess);
+}
diff --git a/examples/widgets/graphicsview/boxes/main.cpp b/examples/widgets/graphicsview/boxes/main.cpp
new file mode 100644
index 0000000000..2baa539d3a
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/main.cpp
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//#include <GL/glew.h>
+#include "glextensions.h"
+
+#include "scene.h"
+
+#include <QtWidgets>
+#include <QGLWidget>
+
+class GraphicsView : public QGraphicsView
+{
+public:
+ GraphicsView()
+ {
+ setWindowTitle(tr("Boxes"));
+ setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
+ //setRenderHints(QPainter::SmoothPixmapTransform);
+ }
+
+protected:
+ void resizeEvent(QResizeEvent *event) {
+ if (scene())
+ scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
+ QGraphicsView::resizeEvent(event);
+ }
+};
+
+inline bool matchString(const char *extensionString, const char *subString)
+{
+ int subStringLength = strlen(subString);
+ return (strncmp(extensionString, subString, subStringLength) == 0)
+ && ((extensionString[subStringLength] == ' ') || (extensionString[subStringLength] == '\0'));
+}
+
+bool necessaryExtensionsSupported()
+{
+ const char *extensionString = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
+ const char *p = extensionString;
+
+ const int GL_EXT_FBO = 1;
+ const int GL_ARB_VS = 2;
+ const int GL_ARB_FS = 4;
+ const int GL_ARB_SO = 8;
+ int extensions = 0;
+
+ while (*p) {
+ if (matchString(p, "GL_EXT_framebuffer_object"))
+ extensions |= GL_EXT_FBO;
+ else if (matchString(p, "GL_ARB_vertex_shader"))
+ extensions |= GL_ARB_VS;
+ else if (matchString(p, "GL_ARB_fragment_shader"))
+ extensions |= GL_ARB_FS;
+ else if (matchString(p, "GL_ARB_shader_objects"))
+ extensions |= GL_ARB_SO;
+ while ((*p != ' ') && (*p != '\0'))
+ ++p;
+ if (*p == ' ')
+ ++p;
+ }
+ return (extensions == 15);
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5) == 0) {
+ QMessageBox::critical(0, "OpenGL features missing",
+ "OpenGL version 1.5 or higher is required to run this demo.\n"
+ "The program will now exit.");
+ return -1;
+ }
+
+ int maxTextureSize = 1024;
+ QGLWidget *widget = new QGLWidget(QGLFormat(QGL::SampleBuffers));
+ widget->makeCurrent();
+
+ if (!necessaryExtensionsSupported()) {
+ QMessageBox::critical(0, "OpenGL features missing",
+ "The OpenGL extensions required to run this demo are missing.\n"
+ "The program will now exit.");
+ delete widget;
+ return -2;
+ }
+
+ // Check if all the necessary functions are resolved.
+ if (!getGLExtensionFunctions().resolve(widget->context())) {
+ QMessageBox::critical(0, "OpenGL features missing",
+ "Failed to resolve OpenGL functions required to run this demo.\n"
+ "The program will now exit.");
+ delete widget;
+ return -3;
+ }
+
+ // TODO: Make conditional for final release
+ QMessageBox::information(0, "For your information",
+ "This demo can be GPU and CPU intensive and may\n"
+ "work poorly or not at all on your system.");
+
+ widget->makeCurrent(); // The current context must be set before calling Scene's constructor
+ Scene scene(1024, 768, maxTextureSize);
+ GraphicsView view;
+ view.setViewport(widget);
+ view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
+ view.setScene(&scene);
+ view.show();
+
+ return app.exec();
+}
+
diff --git a/examples/widgets/graphicsview/boxes/marble.fsh b/examples/widgets/graphicsview/boxes/marble.fsh
new file mode 100644
index 0000000000..3985a98e96
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/marble.fsh
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+varying vec3 position, normal;
+varying vec4 specular, ambient, diffuse, lightDirection;
+
+uniform sampler2D tex;
+uniform sampler3D noise;
+
+//const vec4 marbleColors[2] = {vec4(0.9, 0.9, 0.9, 1), vec4(0.6, 0.5, 0.5, 1)};
+uniform vec4 marbleColors[2];
+
+void main()
+{
+ float turbulence = 0.0;
+ float scale = 1.0;
+ for (int i = 0; i < 4; ++i) {
+ turbulence += scale * (texture3D(noise, 0.125 * gl_TexCoord[1].xyz / scale).x - 0.5);
+ scale *= 0.5;
+ }
+
+ vec3 N = normalize(normal);
+ // assume directional light
+
+ gl_MaterialParameters M = gl_FrontMaterial;
+
+ float NdotL = dot(N, lightDirection.xyz);
+ float RdotL = dot(reflect(normalize(position), N), lightDirection.xyz);
+
+ vec4 unlitColor = mix(marbleColors[0], marbleColors[1], exp(-4.0 * abs(turbulence)));
+ gl_FragColor = (ambient + diffuse * max(NdotL, 0.0)) * unlitColor +
+ M.specular * specular * pow(max(RdotL, 0.0), M.shininess);
+}
diff --git a/examples/widgets/graphicsview/boxes/parameters.par b/examples/widgets/graphicsview/boxes/parameters.par
new file mode 100644
index 0000000000..50e20739b9
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/parameters.par
@@ -0,0 +1,5 @@
+color basicColor ff0e3d0e
+color woodColors ff5e3d33 ffcc9966
+float woodTubulence 0.1
+color graniteColors ff000000 ff4d261a ffccb3bf
+color marbleColors ffe6e6e6 ff998080
diff --git a/examples/widgets/graphicsview/boxes/qt-logo.jpg b/examples/widgets/graphicsview/boxes/qt-logo.jpg
new file mode 100644
index 0000000000..4014b4659c
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/qt-logo.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/boxes/qt-logo.png b/examples/widgets/graphicsview/boxes/qt-logo.png
new file mode 100644
index 0000000000..7d3e97eb36
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/qt-logo.png
Binary files differ
diff --git a/examples/widgets/graphicsview/boxes/qtbox.cpp b/examples/widgets/graphicsview/boxes/qtbox.cpp
new file mode 100644
index 0000000000..cff4497253
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/qtbox.cpp
@@ -0,0 +1,480 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qtbox.h"
+
+const qreal ROTATE_SPEED_X = 30.0 / 1000.0;
+const qreal ROTATE_SPEED_Y = 20.0 / 1000.0;
+const qreal ROTATE_SPEED_Z = 40.0 / 1000.0;
+const int MAX_ITEM_SIZE = 512;
+const int MIN_ITEM_SIZE = 16;
+
+//============================================================================//
+// ItemBase //
+//============================================================================//
+
+ItemBase::ItemBase(int size, int x, int y) : m_size(size), m_isResizing(false)
+{
+ setFlag(QGraphicsItem::ItemIsMovable, true);
+ setFlag(QGraphicsItem::ItemIsSelectable, true);
+ setFlag(QGraphicsItem::ItemIsFocusable, true);
+ setAcceptHoverEvents(true);
+ setPos(x, y);
+ m_startTime = QTime::currentTime();
+}
+
+ItemBase::~ItemBase()
+{
+}
+
+QRectF ItemBase::boundingRect() const
+{
+ return QRectF(-m_size / 2, -m_size / 2, m_size, m_size);
+}
+
+void ItemBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
+{
+ if (option->state & QStyle::State_Selected) {
+ painter->setRenderHint(QPainter::Antialiasing, true);
+ if (option->state & QStyle::State_HasFocus)
+ painter->setPen(Qt::yellow);
+ else
+ painter->setPen(Qt::white);
+ painter->drawRect(boundingRect());
+
+ painter->drawLine(m_size / 2 - 9, m_size / 2, m_size / 2, m_size / 2 - 9);
+ painter->drawLine(m_size / 2 - 6, m_size / 2, m_size / 2, m_size / 2 - 6);
+ painter->drawLine(m_size / 2 - 3, m_size / 2, m_size / 2, m_size / 2 - 3);
+
+ painter->setRenderHint(QPainter::Antialiasing, false);
+ }
+}
+
+void ItemBase::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
+{
+ if (!isSelected() && scene()) {
+ scene()->clearSelection();
+ setSelected(true);
+ }
+
+ QMenu menu;
+ QAction *delAction = menu.addAction("Delete");
+ QAction *newAction = menu.addAction("New");
+ QAction *growAction = menu.addAction("Grow");
+ QAction *shrinkAction = menu.addAction("Shrink");
+
+ QAction *selectedAction = menu.exec(event->screenPos());
+
+ if (selectedAction == delAction)
+ deleteSelectedItems(scene());
+ else if (selectedAction == newAction)
+ duplicateSelectedItems(scene());
+ else if (selectedAction == growAction)
+ growSelectedItems(scene());
+ else if (selectedAction == shrinkAction)
+ shrinkSelectedItems(scene());
+}
+
+void ItemBase::duplicateSelectedItems(QGraphicsScene *scene)
+{
+ if (!scene)
+ return;
+
+ QList<QGraphicsItem *> selected;
+ selected = scene->selectedItems();
+
+ foreach (QGraphicsItem *item, selected) {
+ ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
+ if (itemBase)
+ scene->addItem(itemBase->createNew(itemBase->m_size, itemBase->pos().x() + itemBase->m_size, itemBase->pos().y()));
+ }
+}
+
+void ItemBase::deleteSelectedItems(QGraphicsScene *scene)
+{
+ if (!scene)
+ return;
+
+ QList<QGraphicsItem *> selected;
+ selected = scene->selectedItems();
+
+ foreach (QGraphicsItem *item, selected) {
+ ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
+ if (itemBase)
+ delete itemBase;
+ }
+}
+
+void ItemBase::growSelectedItems(QGraphicsScene *scene)
+{
+ if (!scene)
+ return;
+
+ QList<QGraphicsItem *> selected;
+ selected = scene->selectedItems();
+
+ foreach (QGraphicsItem *item, selected) {
+ ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
+ if (itemBase) {
+ itemBase->prepareGeometryChange();
+ itemBase->m_size *= 2;
+ if (itemBase->m_size > MAX_ITEM_SIZE)
+ itemBase->m_size = MAX_ITEM_SIZE;
+ }
+ }
+}
+
+void ItemBase::shrinkSelectedItems(QGraphicsScene *scene)
+{
+ if (!scene)
+ return;
+
+ QList<QGraphicsItem *> selected;
+ selected = scene->selectedItems();
+
+ foreach (QGraphicsItem *item, selected) {
+ ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
+ if (itemBase) {
+ itemBase->prepareGeometryChange();
+ itemBase->m_size /= 2;
+ if (itemBase->m_size < MIN_ITEM_SIZE)
+ itemBase->m_size = MIN_ITEM_SIZE;
+ }
+ }
+}
+
+void ItemBase::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (m_isResizing) {
+ int dx = int(2.0 * event->pos().x());
+ int dy = int(2.0 * event->pos().y());
+ prepareGeometryChange();
+ m_size = (dx > dy ? dx : dy);
+ if (m_size < MIN_ITEM_SIZE)
+ m_size = MIN_ITEM_SIZE;
+ else if (m_size > MAX_ITEM_SIZE)
+ m_size = MAX_ITEM_SIZE;
+ } else {
+ QGraphicsItem::mouseMoveEvent(event);
+ }
+}
+
+void ItemBase::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
+{
+ if (m_isResizing || (isInResizeArea(event->pos()) && isSelected()))
+ setCursor(Qt::SizeFDiagCursor);
+ else
+ setCursor(Qt::ArrowCursor);
+ QGraphicsItem::hoverMoveEvent(event);
+}
+
+void ItemBase::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ static qreal z = 0.0;
+ setZValue(z += 1.0);
+ if (event->button() == Qt::LeftButton && isInResizeArea(event->pos())) {
+ m_isResizing = true;
+ } else {
+ QGraphicsItem::mousePressEvent(event);
+ }
+}
+
+void ItemBase::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton && m_isResizing) {
+ m_isResizing = false;
+ } else {
+ QGraphicsItem::mouseReleaseEvent(event);
+ }
+}
+
+void ItemBase::keyPressEvent(QKeyEvent *event)
+{
+ switch (event->key()) {
+ case Qt::Key_Delete:
+ deleteSelectedItems(scene());
+ break;
+ case Qt::Key_Insert:
+ duplicateSelectedItems(scene());
+ break;
+ case Qt::Key_Plus:
+ growSelectedItems(scene());
+ break;
+ case Qt::Key_Minus:
+ shrinkSelectedItems(scene());
+ break;
+ default:
+ QGraphicsItem::keyPressEvent(event);
+ break;
+ }
+}
+
+void ItemBase::wheelEvent(QGraphicsSceneWheelEvent *event)
+{
+ prepareGeometryChange();
+ m_size = int(m_size * exp(-event->delta() / 600.0));
+ if (m_size > MAX_ITEM_SIZE)
+ m_size = MAX_ITEM_SIZE;
+ else if (m_size < MIN_ITEM_SIZE)
+ m_size = MIN_ITEM_SIZE;
+}
+
+int ItemBase::type() const
+{
+ return Type;
+}
+
+
+bool ItemBase::isInResizeArea(const QPointF &pos)
+{
+ return (-pos.y() < pos.x() - m_size + 9);
+}
+
+//============================================================================//
+// QtBox //
+//============================================================================//
+
+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].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].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()
+{
+ if (m_texture)
+ delete m_texture;
+}
+
+ItemBase *QtBox::createNew(int size, int x, int y)
+{
+ return new QtBox(size, x, y);
+}
+
+void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ QRectF rect = boundingRect().translated(pos());
+ float width = float(painter->device()->width());
+ float height = float(painter->device()->height());
+
+ float left = 2.0f * float(rect.left()) / width - 1.0f;
+ float right = 2.0f * float(rect.right()) / width - 1.0f;
+ float top = 1.0f - 2.0f * float(rect.top()) / height;
+ float bottom = 1.0f - 2.0f * float(rect.bottom()) / height;
+ float moveToRectMatrix[] = {
+ 0.5f * (right - left), 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.5f * (bottom - top), 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.5f * (right + left), 0.5f * (bottom + top), 0.0f, 1.0f
+ };
+
+ painter->beginNativePainting();
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadMatrixf(moveToRectMatrix);
+ qgluPerspective(60.0, 1.0, 0.01, 10.0);
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+
+ //glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_COLOR_MATERIAL);
+ glEnable(GL_NORMALIZE);
+
+ if(m_texture == 0)
+ m_texture = new GLTexture2D(":/res/boxes/qt-logo.jpg", 64, 64);
+ m_texture->bind();
+ glEnable(GL_TEXTURE_2D);
+
+ glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
+ float lightColour[] = {1.0f, 1.0f, 1.0f, 1.0f};
+ float lightDir[] = {0.0f, 0.0f, 1.0f, 0.0f};
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColour);
+ glLightfv(GL_LIGHT0, GL_POSITION, lightDir);
+ glEnable(GL_LIGHT0);
+
+ glTranslatef(0.0f, 0.0f, -1.5f);
+ glRotatef(ROTATE_SPEED_X * m_startTime.msecsTo(QTime::currentTime()), 1.0f, 0.0f, 0.0f);
+ glRotatef(ROTATE_SPEED_Y * m_startTime.msecsTo(QTime::currentTime()), 0.0f, 1.0f, 0.0f);
+ glRotatef(ROTATE_SPEED_Z * m_startTime.msecsTo(QTime::currentTime()), 0.0f, 0.0f, 1.0f);
+ int dt = m_startTime.msecsTo(QTime::currentTime());
+ if (dt < 500)
+ glScalef(dt / 500.0f, dt / 500.0f, dt / 500.0f);
+
+ for (int dir = 0; dir < 3; ++dir) {
+ glColor4f(1.0f, 1.0f, 1.0f, 1.0);
+
+ glBegin(GL_TRIANGLE_STRIP);
+ glNormal3fv(reinterpret_cast<float *>(&m_normals[2 * dir + 0]));
+ for (int i = 0; i < 2; ++i) {
+ for (int j = 0; j < 2; ++j) {
+ 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(reinterpret_cast<float *>(&m_normals[2 * dir + 1]));
+ for (int i = 0; i < 2; ++i) {
+ for (int j = 0; j < 2; ++j) {
+ 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();
+ }
+ m_texture->unbind();
+
+ //glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_LIGHTING);
+ glDisable(GL_COLOR_MATERIAL);
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_LIGHT0);
+ glDisable(GL_NORMALIZE);
+
+ glPopMatrix();
+
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+
+ painter->endNativePainting();
+
+ ItemBase::paint(painter, option, widget);
+}
+
+//============================================================================//
+// CircleItem //
+//============================================================================//
+
+CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y)
+{
+ m_color = QColor::fromHsv(rand() % 360, 255, 255);
+}
+
+void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ int dt = m_startTime.msecsTo(QTime::currentTime());
+
+ qreal r0 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 3800) % 4000)));
+ qreal r1 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 0) % 4000)));
+ qreal r2 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 1800) % 4000)));
+ qreal r3 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 2000) % 4000)));
+
+ if (r0 > r1)
+ r0 = 0.0;
+ if (r2 > r3)
+ r2 = 0.0;
+
+ QPainterPath path;
+ path.moveTo(r1, 0.0);
+ path.arcTo(-r1, -r1, 2 * r1, 2 * r1, 0.0, 360.0);
+ path.lineTo(r0, 0.0);
+ path.arcTo(-r0, -r0, 2 * r0, 2 * r0, 0.0, -360.0);
+ path.closeSubpath();
+ path.moveTo(r3, 0.0);
+ path.arcTo(-r3, -r3, 2 * r3, 2 * r3, 0.0, 360.0);
+ path.lineTo(r0, 0.0);
+ path.arcTo(-r2, -r2, 2 * r2, 2 * r2, 0.0, -360.0);
+ path.closeSubpath();
+ painter->setRenderHint(QPainter::Antialiasing, true);
+ painter->setBrush(QBrush(m_color));
+ painter->setPen(Qt::NoPen);
+ painter->drawPath(path);
+ painter->setBrush(Qt::NoBrush);
+ painter->setPen(Qt::SolidLine);
+ painter->setRenderHint(QPainter::Antialiasing, false);
+
+ ItemBase::paint(painter, option, widget);
+}
+
+ItemBase *CircleItem::createNew(int size, int x, int y)
+{
+ return new CircleItem(size, x, y);
+}
+
+//============================================================================//
+// SquareItem //
+//============================================================================//
+
+SquareItem::SquareItem(int size, int x, int y) : ItemBase(size, x, y)
+{
+ m_image = QPixmap(":/res/boxes/square.jpg");
+}
+
+void SquareItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ int dt = m_startTime.msecsTo(QTime::currentTime());
+ QTransform oldTransform = painter->worldTransform();
+ int dtMod = dt % 2000;
+ qreal amp = 0.002 * (dtMod < 1000 ? dtMod : 2000 - dtMod) - 1.0;
+
+ qreal scale = 0.6 + 0.2 * amp * amp;
+ painter->setWorldTransform(QTransform().rotate(15.0 * amp).scale(scale, scale), true);
+
+ painter->drawPixmap(-m_size / 2, -m_size / 2, m_size, m_size, m_image);
+
+ painter->setWorldTransform(oldTransform, false);
+ ItemBase::paint(painter, option, widget);
+}
+
+ItemBase *SquareItem::createNew(int size, int x, int y)
+{
+ return new SquareItem(size, x, y);
+}
diff --git a/examples/widgets/graphicsview/boxes/qtbox.h b/examples/widgets/graphicsview/boxes/qtbox.h
new file mode 100644
index 0000000000..66b9b17b7f
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/qtbox.h
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTBOX_H
+#define QTBOX_H
+
+#include <QtWidgets>
+
+#include <QtGui/qvector3d.h>
+#include "glbuffers.h"
+
+class ItemBase : public QGraphicsItem
+{
+public:
+ enum { Type = UserType + 1 };
+
+ ItemBase(int size, int x, int y);
+ virtual ~ItemBase();
+ virtual QRectF boundingRect() const;
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+protected:
+ virtual ItemBase *createNew(int size, int x, int y) = 0;
+ virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+ virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ virtual void keyPressEvent(QKeyEvent *event);
+ virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
+ virtual int type() const;
+ bool isInResizeArea(const QPointF &pos);
+
+ static void duplicateSelectedItems(QGraphicsScene *scene);
+ static void deleteSelectedItems(QGraphicsScene *scene);
+ static void growSelectedItems(QGraphicsScene *scene);
+ static void shrinkSelectedItems(QGraphicsScene *scene);
+
+ int m_size;
+ QTime m_startTime;
+ bool m_isResizing;
+};
+
+class QtBox : public ItemBase
+{
+public:
+ QtBox(int size, int x, int y);
+ virtual ~QtBox();
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+protected:
+ virtual ItemBase *createNew(int size, int x, int y);
+private:
+ QVector3D m_vertices[8];
+ QVector3D m_texCoords[4];
+ QVector3D m_normals[6];
+ GLTexture *m_texture;
+};
+
+class CircleItem : public ItemBase
+{
+public:
+ CircleItem(int size, int x, int y);
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+protected:
+ virtual ItemBase *createNew(int size, int x, int y);
+
+ QColor m_color;
+};
+
+class SquareItem : public ItemBase
+{
+public:
+ SquareItem(int size, int x, int y);
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+protected:
+ virtual ItemBase *createNew(int size, int x, int y);
+
+ QPixmap m_image;
+};
+
+#endif
diff --git a/examples/widgets/graphicsview/boxes/reflection.fsh b/examples/widgets/graphicsview/boxes/reflection.fsh
new file mode 100644
index 0000000000..95a21112ea
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/reflection.fsh
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+varying vec3 position, normal;
+varying vec4 specular, ambient, diffuse, lightDirection;
+
+uniform sampler2D tex;
+uniform samplerCube env;
+uniform mat4 view;
+
+void main()
+{
+ vec3 N = normalize(normal);
+ vec3 R = 2.0 * dot(-position, N) * N + position;
+ gl_FragColor = textureCube(env, R * mat3(view[0].xyz, view[1].xyz, view[2].xyz));
+}
diff --git a/examples/widgets/graphicsview/boxes/refraction.fsh b/examples/widgets/graphicsview/boxes/refraction.fsh
new file mode 100644
index 0000000000..5411478ea2
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/refraction.fsh
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+varying vec3 position, normal;
+varying vec4 specular, ambient, diffuse, lightDirection;
+
+uniform sampler2D tex;
+uniform samplerCube env;
+uniform mat4 view;
+
+// Arrays don't work here on glsl < 120, apparently.
+//const float coeffs[6] = float[6](1.0/2.0, 1.0/2.1, 1.0/2.2, 1.0/2.3, 1.0/2.4, 1.0/2.5);
+float coeffs(int i)
+{
+ return 1.0 / (2.0 + 0.1 * float(i));
+}
+
+void main()
+{
+ vec3 N = normalize(normal);
+ vec3 I = -normalize(position);
+ float IdotN = dot(I, N);
+ float scales[6];
+ vec3 C[6];
+ for (int i = 0; i < 6; ++i) {
+ scales[i] = (IdotN - sqrt(1.0 - coeffs(i) + coeffs(i) * (IdotN * IdotN)));
+ C[i] = textureCube(env, (-I + coeffs(i) * N) * mat3(view[0].xyz, view[1].xyz, view[2].xyz)).xyz;
+ }
+
+ gl_FragColor = 0.25 * vec4(C[5].x + 2.0*C[0].x + C[1].x, C[1].y + 2.0*C[2].y + C[3].y,
+ C[3].z + 2.0*C[4].z + C[5].z, 4.0);
+}
diff --git a/examples/widgets/graphicsview/boxes/roundedbox.cpp b/examples/widgets/graphicsview/boxes/roundedbox.cpp
new file mode 100644
index 0000000000..e205dbdb2b
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/roundedbox.cpp
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "roundedbox.h"
+
+//============================================================================//
+// P3T2N3Vertex //
+//============================================================================//
+
+VertexDescription P3T2N3Vertex::description[] = {
+ {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},
+};
+
+//============================================================================//
+// GLRoundedBox //
+//============================================================================//
+
+float lerp(float a, float b, float t)
+{
+ return a * (1.0f - t) + b * t;
+}
+
+GLRoundedBox::GLRoundedBox(float r, float scale, int n)
+ : GLTriangleMesh<P3T2N3Vertex, unsigned short>((n+2)*(n+3)*4, (n+1)*(n+1)*24+36+72*(n+1))
+{
+ int vidx = 0, iidx = 0;
+ int vertexCountPerCorner = (n + 2) * (n + 3) / 2;
+
+ P3T2N3Vertex *vp = m_vb.lock();
+ unsigned short *ip = m_ib.lock();
+
+ if (!vp || !ip) {
+ qWarning("GLRoundedBox::GLRoundedBox: Failed to lock vertex buffer and/or index buffer.");
+ m_ib.unlock();
+ m_vb.unlock();
+ return;
+ }
+
+ for (int corner = 0; corner < 8; ++corner) {
+ 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;
+ int offsZ = ((corner ^ 4) - corner) * vertexCountPerCorner;
+
+ // Face polygons
+ if (winding) {
+ ip[iidx++] = vidx;
+ ip[iidx++] = vidx + offsX;
+ ip[iidx++] = vidx + offsY;
+
+ ip[iidx++] = vidx + vertexCountPerCorner - n - 2;
+ ip[iidx++] = vidx + vertexCountPerCorner - n - 2 + offsY;
+ ip[iidx++] = vidx + vertexCountPerCorner - n - 2 + offsZ;
+
+ ip[iidx++] = vidx + vertexCountPerCorner - 1;
+ ip[iidx++] = vidx + vertexCountPerCorner - 1 + offsZ;
+ ip[iidx++] = vidx + vertexCountPerCorner - 1 + offsX;
+ }
+
+ for (int i = 0; i < n + 2; ++i) {
+
+ // Edge polygons
+ if (winding && i < n + 1) {
+ ip[iidx++] = vidx + i + 1;
+ ip[iidx++] = vidx;
+ ip[iidx++] = vidx + offsY + i + 1;
+ ip[iidx++] = vidx + offsY;
+ ip[iidx++] = vidx + offsY + i + 1;
+ ip[iidx++] = vidx;
+
+ ip[iidx++] = vidx + i;
+ ip[iidx++] = vidx + 2 * i + 2;
+ ip[iidx++] = vidx + i + offsX;
+ ip[iidx++] = vidx + 2 * i + offsX + 2;
+ ip[iidx++] = vidx + i + offsX;
+ ip[iidx++] = vidx + 2 * i + 2;
+
+ ip[iidx++] = (corner + 1) * vertexCountPerCorner - 1 - i;
+ ip[iidx++] = (corner + 1) * vertexCountPerCorner - 2 - i;
+ ip[iidx++] = (corner + 1) * vertexCountPerCorner - 1 - i + offsZ;
+ ip[iidx++] = (corner + 1) * vertexCountPerCorner - 2 - i + offsZ;
+ ip[iidx++] = (corner + 1) * vertexCountPerCorner - 1 - i + offsZ;
+ ip[iidx++] = (corner + 1) * vertexCountPerCorner - 2 - i;
+ }
+
+ for (int j = 0; j <= i; ++j) {
+ 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 = QVector2D(pos.x() + 0.5f, pos.y() + 0.5f);
+
+ // Corner polygons
+ if (i < n + 1) {
+ ip[iidx++] = vidx;
+ ip[iidx++] = vidx + i + 2 - winding;
+ ip[iidx++] = vidx + i + 1 + winding;
+ }
+ if (i < n) {
+ ip[iidx++] = vidx + i + 1 + winding;
+ ip[iidx++] = vidx + i + 2 - winding;
+ ip[iidx++] = vidx + 2 * i + 4;
+ }
+
+ ++vidx;
+ }
+ }
+
+ }
+
+ m_ib.unlock();
+ m_vb.unlock();
+}
+
diff --git a/examples/widgets/graphicsview/boxes/roundedbox.h b/examples/widgets/graphicsview/boxes/roundedbox.h
new file mode 100644
index 0000000000..3edfb69fa8
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/roundedbox.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ROUNDEDBOX_H
+#define ROUNDEDBOX_H
+
+//#include <GL/glew.h>
+#include "glextensions.h"
+
+#include <QtWidgets>
+#include <QtOpenGL>
+
+#include "gltrianglemesh.h"
+#include <QtGui/qvector3d.h>
+#include <QtGui/qvector2d.h>
+#include "glbuffers.h"
+
+struct P3T2N3Vertex
+{
+ QVector3D position;
+ QVector2D texCoord;
+ QVector3D normal;
+ static VertexDescription description[];
+};
+
+class GLRoundedBox : public GLTriangleMesh<P3T2N3Vertex, unsigned short>
+{
+public:
+ // 0 < r < 0.5, 0 <= n <= 125
+ GLRoundedBox(float r = 0.25f, float scale = 1.0f, int n = 10);
+};
+
+
+#endif
diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp
new file mode 100644
index 0000000000..5fb43d8c99
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/scene.cpp
@@ -0,0 +1,1085 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDebug>
+#include "scene.h"
+#include <QtGui/qmatrix4x4.h>
+#include <QtGui/qvector3d.h>
+
+#include "3rdparty/fbm.h"
+
+void checkGLErrors(const QString& prefix)
+{
+ switch (glGetError()) {
+ case GL_NO_ERROR:
+ //qDebug() << prefix << tr("No error.");
+ break;
+ case GL_INVALID_ENUM:
+ qDebug() << prefix << QObject::tr("Invalid enum.");
+ break;
+ case GL_INVALID_VALUE:
+ qDebug() << prefix << QObject::tr("Invalid value.");
+ break;
+ case GL_INVALID_OPERATION:
+ qDebug() << prefix << QObject::tr("Invalid operation.");
+ break;
+ case GL_STACK_OVERFLOW:
+ qDebug() << prefix << QObject::tr("Stack overflow.");
+ break;
+ case GL_STACK_UNDERFLOW:
+ qDebug() << prefix << QObject::tr("Stack underflow.");
+ break;
+ case GL_OUT_OF_MEMORY:
+ qDebug() << prefix << QObject::tr("Out of memory.");
+ break;
+ default:
+ qDebug() << prefix << QObject::tr("Unknown error.");
+ break;
+ }
+}
+
+//============================================================================//
+// ColorEdit //
+//============================================================================//
+
+ColorEdit::ColorEdit(QRgb initialColor, int id)
+ : m_color(initialColor), m_id(id)
+{
+ QHBoxLayout *layout = new QHBoxLayout;
+ setLayout(layout);
+ layout->setContentsMargins(0, 0, 0, 0);
+
+ m_lineEdit = new QLineEdit(QString::number(m_color, 16));
+ layout->addWidget(m_lineEdit);
+
+ m_button = new QFrame;
+ QPalette palette = m_button->palette();
+ palette.setColor(QPalette::Window, QColor(m_color));
+ m_button->setPalette(palette);
+ m_button->setAutoFillBackground(true);
+ m_button->setMinimumSize(32, 0);
+ m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
+ m_button->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
+ layout->addWidget(m_button);
+
+ connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(editDone()));
+}
+
+void ColorEdit::editDone()
+{
+ bool ok;
+ QRgb newColor = m_lineEdit->text().toUInt(&ok, 16);
+ if (ok)
+ setColor(newColor);
+}
+
+void ColorEdit::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ QColor color(m_color);
+ QColorDialog dialog(color, 0);
+ dialog.setOption(QColorDialog::ShowAlphaChannel, true);
+// The ifdef block is a workaround for the beta, TODO: remove when bug 238525 is fixed
+#ifdef Q_WS_MAC
+ dialog.setOption(QColorDialog::DontUseNativeDialog, true);
+#endif
+ dialog.move(280, 120);
+ if (dialog.exec() == QDialog::Rejected)
+ return;
+ QRgb newColor = dialog.selectedColor().rgba();
+ if (newColor == m_color)
+ return;
+ setColor(newColor);
+ }
+}
+
+void ColorEdit::setColor(QRgb color)
+{
+ m_color = color;
+ m_lineEdit->setText(QString::number(m_color, 16)); // "Clean up" text
+ QPalette palette = m_button->palette();
+ palette.setColor(QPalette::Window, QColor(m_color));
+ m_button->setPalette(palette);
+ emit colorChanged(m_color, m_id);
+}
+
+//============================================================================//
+// FloatEdit //
+//============================================================================//
+
+FloatEdit::FloatEdit(float initialValue, int id)
+ : m_value(initialValue), m_id(id)
+{
+ QHBoxLayout *layout = new QHBoxLayout;
+ setLayout(layout);
+ layout->setContentsMargins(0, 0, 0, 0);
+
+ m_lineEdit = new QLineEdit(QString::number(m_value));
+ layout->addWidget(m_lineEdit);
+
+ connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(editDone()));
+}
+
+void FloatEdit::editDone()
+{
+ bool ok;
+ float newValue = m_lineEdit->text().toFloat(&ok);
+ if (ok) {
+ m_value = newValue;
+ m_lineEdit->setText(QString::number(m_value)); // "Clean up" text
+ emit valueChanged(m_value, m_id);
+ }
+}
+
+//============================================================================//
+// TwoSidedGraphicsWidget //
+//============================================================================//
+
+TwoSidedGraphicsWidget::TwoSidedGraphicsWidget(QGraphicsScene *scene)
+ : QObject(scene)
+ , m_current(0)
+ , m_angle(0)
+ , m_delta(0)
+{
+ for (int i = 0; i < 2; ++i)
+ m_proxyWidgets[i] = 0;
+}
+
+void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget)
+{
+ if (index < 0 || index >= 2)
+ {
+ qWarning("TwoSidedGraphicsWidget::setWidget: Index out of bounds, index == %d", index);
+ return;
+ }
+
+ GraphicsWidget *proxy = new GraphicsWidget;
+ proxy->setWidget(widget);
+
+ if (m_proxyWidgets[index])
+ delete m_proxyWidgets[index];
+ m_proxyWidgets[index] = proxy;
+
+ proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache);
+ proxy->setZValue(1e30); // Make sure the dialog is drawn on top of all other (OpenGL) items
+
+ if (index != m_current)
+ proxy->setVisible(false);
+
+ qobject_cast<QGraphicsScene *>(parent())->addItem(proxy);
+}
+
+QWidget *TwoSidedGraphicsWidget::widget(int index)
+{
+ if (index < 0 || index >= 2)
+ {
+ qWarning("TwoSidedGraphicsWidget::widget: Index out of bounds, index == %d", index);
+ return 0;
+ }
+ return m_proxyWidgets[index]->widget();
+}
+
+void TwoSidedGraphicsWidget::flip()
+{
+ m_delta = (m_current == 0 ? 9 : -9);
+ animateFlip();
+}
+
+void TwoSidedGraphicsWidget::animateFlip()
+{
+ m_angle += m_delta;
+ if (m_angle == 90) {
+ int old = m_current;
+ m_current ^= 1;
+ m_proxyWidgets[old]->setVisible(false);
+ m_proxyWidgets[m_current]->setVisible(true);
+ m_proxyWidgets[m_current]->setGeometry(m_proxyWidgets[old]->geometry());
+ }
+
+ QRectF r = m_proxyWidgets[m_current]->boundingRect();
+ m_proxyWidgets[m_current]->setTransform(QTransform()
+ .translate(r.width() / 2, r.height() / 2)
+ .rotate(m_angle - 180 * m_current, Qt::YAxis)
+ .translate(-r.width() / 2, -r.height() / 2));
+
+ if ((m_current == 0 && m_angle > 0) || (m_current == 1 && m_angle < 180))
+ QTimer::singleShot(25, this, SLOT(animateFlip()));
+}
+
+QVariant GraphicsWidget::itemChange(GraphicsItemChange change, const QVariant &value)
+{
+ if (change == ItemPositionChange && scene()) {
+ QRectF rect = boundingRect();
+ QPointF pos = value.toPointF();
+ QRectF sceneRect = scene()->sceneRect();
+ if (pos.x() + rect.left() < sceneRect.left())
+ pos.setX(sceneRect.left() - rect.left());
+ else if (pos.x() + rect.right() >= sceneRect.right())
+ pos.setX(sceneRect.right() - rect.right());
+ if (pos.y() + rect.top() < sceneRect.top())
+ pos.setY(sceneRect.top() - rect.top());
+ else if (pos.y() + rect.bottom() >= sceneRect.bottom())
+ pos.setY(sceneRect.bottom() - rect.bottom());
+ return pos;
+ }
+ return QGraphicsProxyWidget::itemChange(change, value);
+}
+
+void GraphicsWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
+{
+ setCacheMode(QGraphicsItem::NoCache);
+ setCacheMode(QGraphicsItem::ItemCoordinateCache);
+ QGraphicsProxyWidget::resizeEvent(event);
+}
+
+void GraphicsWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ painter->setRenderHint(QPainter::Antialiasing, false);
+ QGraphicsProxyWidget::paint(painter, option, widget);
+ //painter->setRenderHint(QPainter::Antialiasing, true);
+}
+
+//============================================================================//
+// RenderOptionsDialog //
+//============================================================================//
+
+RenderOptionsDialog::RenderOptionsDialog()
+ : QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
+{
+ setWindowOpacity(0.75);
+ setWindowTitle(tr("Options (double click to flip)"));
+ QGridLayout *layout = new QGridLayout;
+ setLayout(layout);
+ layout->setColumnStretch(1, 1);
+
+ int row = 0;
+
+ QCheckBox *check = new QCheckBox(tr("Dynamic cube map"));
+ check->setCheckState(Qt::Unchecked);
+ // Dynamic cube maps are only enabled when multi-texturing and render to texture are available.
+ check->setEnabled(glActiveTexture && glGenFramebuffersEXT);
+ connect(check, SIGNAL(stateChanged(int)), this, SIGNAL(dynamicCubemapToggled(int)));
+ layout->addWidget(check, 0, 0, 1, 2);
+ ++row;
+
+ QPalette palette;
+
+ // Load all .par files
+ // .par files have a simple syntax for specifying user adjustable uniform variables.
+ QSet<QByteArray> uniforms;
+ QList<QString> filter = QStringList("*.par");
+ QList<QFileInfo> files = QDir(":/res/boxes/").entryInfoList(filter, QDir::Files | QDir::Readable);
+
+ foreach (QFileInfo fileInfo, files) {
+ QFile file(fileInfo.absoluteFilePath());
+ if (file.open(QIODevice::ReadOnly)) {
+ while (!file.atEnd()) {
+ QList<QByteArray> tokens = file.readLine().simplified().split(' ');
+ QList<QByteArray>::const_iterator it = tokens.begin();
+ if (it == tokens.end())
+ continue;
+ QByteArray type = *it;
+ if (++it == tokens.end())
+ continue;
+ QByteArray name = *it;
+ bool singleElement = (tokens.size() == 3); // type, name and one value
+ char counter[10] = "000000000";
+ int counterPos = 8; // position of last digit
+ while (++it != tokens.end()) {
+ m_parameterNames << name;
+ if (!singleElement) {
+ m_parameterNames.back() += "[";
+ m_parameterNames.back() += counter + counterPos;
+ m_parameterNames.back() += "]";
+ int j = 8; // position of last digit
+ ++counter[j];
+ while (j > 0 && counter[j] > '9') {
+ counter[j] = '0';
+ ++counter[--j];
+ }
+ if (j < counterPos)
+ counterPos = j;
+ }
+
+ if (type == "color") {
+ layout->addWidget(new QLabel(m_parameterNames.back()));
+ bool ok;
+ ColorEdit *colorEdit = new ColorEdit(it->toUInt(&ok, 16), m_parameterNames.size() - 1);
+ m_parameterEdits << colorEdit;
+ layout->addWidget(colorEdit);
+ connect(colorEdit, SIGNAL(colorChanged(QRgb,int)), this, SLOT(setColorParameter(QRgb,int)));
+ ++row;
+ } else if (type == "float") {
+ layout->addWidget(new QLabel(m_parameterNames.back()));
+ bool ok;
+ FloatEdit *floatEdit = new FloatEdit(it->toFloat(&ok), m_parameterNames.size() - 1);
+ m_parameterEdits << floatEdit;
+ layout->addWidget(floatEdit);
+ connect(floatEdit, SIGNAL(valueChanged(float,int)), this, SLOT(setFloatParameter(float,int)));
+ ++row;
+ }
+ }
+ }
+ file.close();
+ }
+ }
+
+ layout->addWidget(new QLabel(tr("Texture:")));
+ m_textureCombo = new QComboBox;
+ connect(m_textureCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(textureChanged(int)));
+ layout->addWidget(m_textureCombo);
+ ++row;
+
+ layout->addWidget(new QLabel(tr("Shader:")));
+ m_shaderCombo = new QComboBox;
+ connect(m_shaderCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(shaderChanged(int)));
+ layout->addWidget(m_shaderCombo);
+ ++row;
+
+ layout->setRowStretch(row, 1);
+}
+
+int RenderOptionsDialog::addTexture(const QString &name)
+{
+ m_textureCombo->addItem(name);
+ return m_textureCombo->count() - 1;
+}
+
+int RenderOptionsDialog::addShader(const QString &name)
+{
+ m_shaderCombo->addItem(name);
+ return m_shaderCombo->count() - 1;
+}
+
+void RenderOptionsDialog::emitParameterChanged()
+{
+ foreach (ParameterEdit *edit, m_parameterEdits)
+ edit->emitChange();
+}
+
+void RenderOptionsDialog::setColorParameter(QRgb color, int id)
+{
+ emit colorParameterChanged(m_parameterNames[id], color);
+}
+
+void RenderOptionsDialog::setFloatParameter(float value, int id)
+{
+ emit floatParameterChanged(m_parameterNames[id], value);
+}
+
+void RenderOptionsDialog::mouseDoubleClickEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton)
+ emit doubleClicked();
+}
+
+//============================================================================//
+// ItemDialog //
+//============================================================================//
+
+ItemDialog::ItemDialog()
+ : QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
+{
+ setWindowTitle(tr("Items (double click to flip)"));
+ setWindowOpacity(0.75);
+ resize(160, 100);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ setLayout(layout);
+ QPushButton *button;
+
+ button = new QPushButton(tr("Add Qt box"));
+ layout->addWidget(button);
+ connect(button, SIGNAL(clicked()), this, SLOT(triggerNewQtBox()));
+
+ button = new QPushButton(tr("Add circle"));
+ layout->addWidget(button);
+ connect(button, SIGNAL(clicked()), this, SLOT(triggerNewCircleItem()));
+
+ button = new QPushButton(tr("Add square"));
+ layout->addWidget(button);
+ connect(button, SIGNAL(clicked()), this, SLOT(triggerNewSquareItem()));
+
+ layout->addStretch(1);
+}
+
+void ItemDialog::triggerNewQtBox()
+{
+ emit newItemTriggered(QtBoxItem);
+}
+
+void ItemDialog::triggerNewCircleItem()
+{
+ emit newItemTriggered(CircleItem);
+}
+
+void ItemDialog::triggerNewSquareItem()
+{
+ emit newItemTriggered(SquareItem);
+}
+
+void ItemDialog::mouseDoubleClickEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton)
+ emit doubleClicked();
+}
+
+//============================================================================//
+// Scene //
+//============================================================================//
+
+const static char environmentShaderText[] =
+ "uniform samplerCube env;"
+ "void main() {"
+ "gl_FragColor = textureCube(env, gl_TexCoord[1].xyz);"
+ "}";
+
+Scene::Scene(int width, int height, int maxTextureSize)
+ : m_distExp(600)
+ , m_frame(0)
+ , m_maxTextureSize(maxTextureSize)
+ , m_currentShader(0)
+ , m_currentTexture(0)
+ , m_dynamicCubemap(false)
+ , m_updateAllCubemaps(true)
+ , m_box(0)
+ , m_vertexShader(0)
+ , m_environmentShader(0)
+ , m_environmentProgram(0)
+{
+ setSceneRect(0, 0, width, height);
+
+ 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);
+ m_renderOptions->resize(m_renderOptions->sizeHint());
+
+ connect(m_renderOptions, SIGNAL(dynamicCubemapToggled(int)), this, SLOT(toggleDynamicCubemap(int)));
+ connect(m_renderOptions, SIGNAL(colorParameterChanged(QString,QRgb)), this, SLOT(setColorParameter(QString,QRgb)));
+ connect(m_renderOptions, SIGNAL(floatParameterChanged(QString,float)), this, SLOT(setFloatParameter(QString,float)));
+ connect(m_renderOptions, SIGNAL(textureChanged(int)), this, SLOT(setTexture(int)));
+ connect(m_renderOptions, SIGNAL(shaderChanged(int)), this, SLOT(setShader(int)));
+
+ m_itemDialog = new ItemDialog;
+ connect(m_itemDialog, SIGNAL(newItemTriggered(ItemDialog::ItemType)), this, SLOT(newItem(ItemDialog::ItemType)));
+
+ TwoSidedGraphicsWidget *twoSided = new TwoSidedGraphicsWidget(this);
+ twoSided->setWidget(0, m_renderOptions);
+ twoSided->setWidget(1, m_itemDialog);
+
+ connect(m_renderOptions, SIGNAL(doubleClicked()), twoSided, SLOT(flip()));
+ connect(m_itemDialog, SIGNAL(doubleClicked()), twoSided, SLOT(flip()));
+
+ addItem(new QtBox(64, width - 64, height - 64));
+ addItem(new QtBox(64, width - 64, 64));
+ addItem(new QtBox(64, 64, height - 64));
+ addItem(new QtBox(64, 64, 64));
+
+ initGL();
+
+ m_timer = new QTimer(this);
+ m_timer->setInterval(20);
+ connect(m_timer, SIGNAL(timeout()), this, SLOT(update()));
+ m_timer->start();
+
+ m_time.start();
+}
+
+Scene::~Scene()
+{
+ if (m_box)
+ delete m_box;
+ foreach (GLTexture *texture, m_textures)
+ if (texture) delete texture;
+ if (m_mainCubemap)
+ delete m_mainCubemap;
+ foreach (QGLShaderProgram *program, m_programs)
+ if (program) delete program;
+ if (m_vertexShader)
+ delete m_vertexShader;
+ foreach (QGLShader *shader, m_fragmentShaders)
+ if (shader) delete shader;
+ foreach (GLRenderTargetCube *rt, m_cubemaps)
+ if (rt) delete rt;
+ if (m_environmentShader)
+ delete m_environmentShader;
+ if (m_environmentProgram)
+ delete m_environmentProgram;
+}
+
+void Scene::initGL()
+{
+ m_box = new GLRoundedBox(0.25f, 1.0f, 10);
+
+ m_vertexShader = new QGLShader(QGLShader::Vertex);
+ m_vertexShader->compileSourceFile(QLatin1String(":/res/boxes/basic.vsh"));
+
+ 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 QGLShader(QGLShader::Fragment);
+ m_environmentShader->compileSourceCode(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);
+ QRgb *data = new QRgb[NOISE_SIZE * NOISE_SIZE * NOISE_SIZE];
+ memset(data, 0, NOISE_SIZE * NOISE_SIZE * NOISE_SIZE * sizeof(QRgb));
+ QRgb *p = data;
+ float pos[3];
+ for (int k = 0; k < NOISE_SIZE; ++k) {
+ pos[2] = k * (0x20 / (float)NOISE_SIZE);
+ for (int j = 0; j < NOISE_SIZE; ++j) {
+ for (int i = 0; i < NOISE_SIZE; ++i) {
+ for (int byte = 0; byte < 4; ++byte) {
+ pos[0] = (i + (byte & 1) * 16) * (0x20 / (float)NOISE_SIZE);
+ pos[1] = (j + (byte & 2) * 8) * (0x20 / (float)NOISE_SIZE);
+ *p |= (int)(128.0f * (noise3(pos) + 1.0f)) << (byte * 8);
+ }
+ ++p;
+ }
+ }
+ }
+ m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data);
+ delete[] data;
+
+ m_mainCubemap = new GLRenderTargetCube(512);
+
+ QStringList filter;
+ QList<QFileInfo> files;
+
+ // Load all .png files as textures
+ m_currentTexture = 0;
+ filter = QStringList("*.png");
+ files = QDir(":/res/boxes/").entryInfoList(filter, QDir::Files | QDir::Readable);
+
+ foreach (QFileInfo file, files) {
+ GLTexture *texture = new GLTexture2D(file.absoluteFilePath(), qMin(256, m_maxTextureSize), qMin(256, m_maxTextureSize));
+ if (texture->failed()) {
+ delete texture;
+ continue;
+ }
+ m_textures << texture;
+ m_renderOptions->addTexture(file.baseName());
+ }
+
+ if (m_textures.size() == 0)
+ m_textures << new GLTexture2D(qMin(64, m_maxTextureSize), qMin(64, m_maxTextureSize));
+
+ // Load all .fsh files as fragment shaders
+ m_currentShader = 0;
+ filter = QStringList("*.fsh");
+ files = QDir(":/res/boxes/").entryInfoList(filter, QDir::Files | QDir::Readable);
+ foreach (QFileInfo file, files) {
+ QGLShaderProgram *program = new QGLShaderProgram;
+ QGLShader* shader = new QGLShader(QGLShader::Fragment);
+ shader->compileSourceFile(file.absoluteFilePath());
+ // The program does not take ownership over the shaders, so store them in a vector so they can be deleted afterwards.
+ 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();
+ qWarning() << "Fragment shader log ( file =" << file.absoluteFilePath() << "):";
+ qWarning() << shader->log();
+ qWarning("Shader program log:");
+ qWarning() << program->log();
+
+ delete shader;
+ delete program;
+ continue;
+ }
+
+ m_fragmentShaders << shader;
+ m_programs << program;
+ m_renderOptions->addShader(file.baseName());
+
+ program->bind();
+ m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0);
+ program->release();
+ }
+
+ if (m_programs.size() == 0)
+ m_programs << new QGLShaderProgram;
+
+ m_renderOptions->emitParameterChanged();
+}
+
+static void loadMatrix(const QMatrix4x4& m)
+{
+ // static to prevent glLoadMatrixf to fail on certain drivers
+ static GLfloat mat[16];
+ const qreal *data = m.constData();
+ for (int index = 0; index < 16; ++index)
+ mat[index] = data[index];
+ glLoadMatrixf(mat);
+}
+
+static void multMatrix(const QMatrix4x4& m)
+{
+ // static to prevent glMultMatrixf to fail on certain drivers
+ static GLfloat mat[16];
+ const qreal *data = m.constData();
+ for (int index = 0; index < 16; ++index)
+ mat[index] = data[index];
+ glMultMatrixf(mat);
+}
+
+// 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 QMatrix4x4 &view, int excludeBox)
+{
+ QMatrix4x4 invView = view.inverted();
+
+ // If multi-texturing is supported, use three saplers.
+ if (glActiveTexture) {
+ glActiveTexture(GL_TEXTURE0);
+ m_textures[m_currentTexture]->bind();
+ glActiveTexture(GL_TEXTURE2);
+ m_noise->bind();
+ glActiveTexture(GL_TEXTURE1);
+ } else {
+ m_textures[m_currentTexture]->bind();
+ }
+
+ glDisable(GL_LIGHTING);
+ glDisable(GL_CULL_FACE);
+
+ 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;
+ loadMatrix(viewRotation);
+ 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->setUniformValue("tex", GLint(0));
+ m_environmentProgram->setUniformValue("env", GLint(1));
+ m_environmentProgram->setUniformValue("noise", GLint(2));
+ m_box->draw();
+ m_environmentProgram->release();
+ m_environment->unbind();
+ }
+
+ loadMatrix(view);
+
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_LIGHTING);
+
+ for (int i = 0; i < m_programs.size(); ++i) {
+ if (i == excludeBox)
+ continue;
+
+ glPushMatrix();
+ QMatrix4x4 m;
+ m.rotate(m_trackBalls[1].rotation());
+ multMatrix(m);
+
+ glRotatef(360.0f * i / m_programs.size(), 0.0f, 0.0f, 1.0f);
+ glTranslatef(2.0f, 0.0f, 0.0f);
+ glScalef(0.3f, 0.6f, 0.6f);
+
+ if (glActiveTexture) {
+ if (m_dynamicCubemap && m_cubemaps[i])
+ m_cubemaps[i]->bind();
+ else
+ m_environment->bind();
+ }
+ m_programs[i]->bind();
+ 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]->release();
+
+ if (glActiveTexture) {
+ if (m_dynamicCubemap && m_cubemaps[i])
+ m_cubemaps[i]->unbind();
+ else
+ m_environment->unbind();
+ }
+ glPopMatrix();
+ }
+
+ if (-1 != excludeBox) {
+ QMatrix4x4 m;
+ m.rotate(m_trackBalls[0].rotation());
+ multMatrix(m);
+
+ if (glActiveTexture) {
+ if (m_dynamicCubemap)
+ m_mainCubemap->bind();
+ else
+ m_environment->bind();
+ }
+
+ m_programs[m_currentShader]->bind();
+ 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]->release();
+
+ if (glActiveTexture) {
+ if (m_dynamicCubemap)
+ m_mainCubemap->unbind();
+ else
+ m_environment->unbind();
+ }
+ }
+
+ if (glActiveTexture) {
+ glActiveTexture(GL_TEXTURE2);
+ m_noise->unbind();
+ glActiveTexture(GL_TEXTURE0);
+ }
+ m_textures[m_currentTexture]->unbind();
+}
+
+void Scene::setStates()
+{
+ //glClearColor(0.25f, 0.25f, 0.5f, 1.0f);
+
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_LIGHTING);
+ //glEnable(GL_COLOR_MATERIAL);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_NORMALIZE);
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+
+ setLights();
+
+ float materialSpecular[] = {0.5f, 0.5f, 0.5f, 1.0f};
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialSpecular);
+ glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 32.0f);
+}
+
+void Scene::setLights()
+{
+ glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
+ //float lightColour[] = {1.0f, 1.0f, 1.0f, 1.0f};
+ float lightDir[] = {0.0f, 0.0f, 1.0f, 0.0f};
+ //glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColour);
+ //glLightfv(GL_LIGHT0, GL_SPECULAR, lightColour);
+ glLightfv(GL_LIGHT0, GL_POSITION, lightDir);
+ glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 1.0f);
+ glEnable(GL_LIGHT0);
+}
+
+void Scene::defaultStates()
+{
+ //glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_LIGHTING);
+ //glDisable(GL_COLOR_MATERIAL);
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_LIGHT0);
+ glDisable(GL_NORMALIZE);
+
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+
+ glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 0.0f);
+ float defaultMaterialSpecular[] = {0.0f, 0.0f, 0.0f, 1.0f};
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, defaultMaterialSpecular);
+ glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f);
+}
+
+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);
+
+ QMatrix4x4 mat;
+ GLRenderTargetCube::getProjectionMatrix(mat, 0.1f, 100.0f);
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ loadMatrix(mat);
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+
+ 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().rotatedVector(QVector3D(cos(angle), sin(angle), 0.0f));
+
+ for (int face = 0; face < 6; ++face) {
+ m_cubemaps[i]->begin(face);
+
+ GLRenderTargetCube::getViewMatrix(mat, face);
+ QVector4D v = QVector4D(-center.x(), -center.y(), -center.z(), 1.0);
+ mat.setColumn(3, mat * v);
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ renderBoxes(mat, i);
+
+ m_cubemaps[i]->end();
+ }
+ }
+
+ for (int face = 0; face < 6; ++face) {
+ m_mainCubemap->begin(face);
+ GLRenderTargetCube::getViewMatrix(mat, face);
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ renderBoxes(mat, -1);
+
+ m_mainCubemap->end();
+ }
+
+ glPopMatrix();
+
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+
+ m_updateAllCubemaps = false;
+}
+
+void Scene::drawBackground(QPainter *painter, const QRectF &)
+{
+ float width = float(painter->device()->width());
+ float height = float(painter->device()->height());
+
+ painter->beginNativePainting();
+ setStates();
+
+ if (m_dynamicCubemap)
+ renderCubemaps();
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glMatrixMode(GL_PROJECTION);
+ qgluPerspective(60.0, width / height, 0.01, 15.0);
+
+ glMatrixMode(GL_MODELVIEW);
+
+ QMatrix4x4 view;
+ view.rotate(m_trackBalls[2].rotation());
+ view(2, 3) -= 2.0f * exp(m_distExp / 1200.0f);
+ renderBoxes(view);
+
+ defaultStates();
+ ++m_frame;
+
+ painter->endNativePainting();
+}
+
+QPointF Scene::pixelPosToViewPos(const QPointF& p)
+{
+ return QPointF(2.0 * float(p.x()) / width() - 1.0,
+ 1.0 - 2.0 * float(p.y()) / height());
+}
+
+void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsScene::mouseMoveEvent(event);
+ if (event->isAccepted())
+ return;
+
+ if (event->buttons() & Qt::LeftButton) {
+ m_trackBalls[0].move(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
+ event->accept();
+ } else {
+ m_trackBalls[0].release(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
+ }
+
+ if (event->buttons() & Qt::RightButton) {
+ m_trackBalls[1].move(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
+ event->accept();
+ } else {
+ m_trackBalls[1].release(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
+ }
+
+ if (event->buttons() & Qt::MidButton) {
+ m_trackBalls[2].move(pixelPosToViewPos(event->scenePos()), QQuaternion());
+ event->accept();
+ } else {
+ m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), QQuaternion());
+ }
+}
+
+void Scene::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsScene::mousePressEvent(event);
+ if (event->isAccepted())
+ return;
+
+ if (event->buttons() & Qt::LeftButton) {
+ m_trackBalls[0].push(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
+ event->accept();
+ }
+
+ if (event->buttons() & Qt::RightButton) {
+ m_trackBalls[1].push(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
+ event->accept();
+ }
+
+ if (event->buttons() & Qt::MidButton) {
+ m_trackBalls[2].push(pixelPosToViewPos(event->scenePos()), QQuaternion());
+ event->accept();
+ }
+}
+
+void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsScene::mouseReleaseEvent(event);
+ if (event->isAccepted())
+ return;
+
+ if (event->button() == Qt::LeftButton) {
+ m_trackBalls[0].release(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
+ event->accept();
+ }
+
+ if (event->button() == Qt::RightButton) {
+ m_trackBalls[1].release(pixelPosToViewPos(event->scenePos()), m_trackBalls[2].rotation().conjugate());
+ event->accept();
+ }
+
+ if (event->button() == Qt::MidButton) {
+ m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), QQuaternion());
+ event->accept();
+ }
+}
+
+void Scene::wheelEvent(QGraphicsSceneWheelEvent * event)
+{
+ QGraphicsScene::wheelEvent(event);
+ if (!event->isAccepted()) {
+ m_distExp += event->delta();
+ if (m_distExp < -8 * 120)
+ m_distExp = -8 * 120;
+ if (m_distExp > 10 * 120)
+ m_distExp = 10 * 120;
+ event->accept();
+ }
+}
+
+void Scene::setShader(int index)
+{
+ if (index >= 0 && index < m_fragmentShaders.size())
+ m_currentShader = index;
+}
+
+void Scene::setTexture(int index)
+{
+ if (index >= 0 && index < m_textures.size())
+ m_currentTexture = index;
+}
+
+void Scene::toggleDynamicCubemap(int state)
+{
+ if ((m_dynamicCubemap = (state == Qt::Checked)))
+ m_updateAllCubemaps = true;
+}
+
+void Scene::setColorParameter(const QString &name, QRgb color)
+{
+ // set the color in all programs
+ foreach (QGLShaderProgram *program, m_programs) {
+ program->bind();
+ program->setUniformValue(program->uniformLocation(name), QColor(color));
+ program->release();
+ }
+}
+
+void Scene::setFloatParameter(const QString &name, float value)
+{
+ // set the color in all programs
+ foreach (QGLShaderProgram *program, m_programs) {
+ program->bind();
+ program->setUniformValue(program->uniformLocation(name), value);
+ program->release();
+ }
+}
+
+void Scene::newItem(ItemDialog::ItemType type)
+{
+ QSize size = sceneRect().size().toSize();
+ switch (type) {
+ case ItemDialog::QtBoxItem:
+ addItem(new QtBox(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32));
+ break;
+ case ItemDialog::CircleItem:
+ addItem(new CircleItem(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32));
+ break;
+ case ItemDialog::SquareItem:
+ addItem(new SquareItem(64, rand() % (size.width() - 64) + 32, rand() % (size.height() - 64) + 32));
+ break;
+ default:
+ break;
+ }
+}
diff --git a/examples/widgets/graphicsview/boxes/scene.h b/examples/widgets/graphicsview/boxes/scene.h
new file mode 100644
index 0000000000..9410f7f994
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/scene.h
@@ -0,0 +1,245 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SCENE_H
+#define SCENE_H
+
+//#include <GL/glew.h>
+#include "glextensions.h"
+
+#include <QtWidgets>
+#include <QtOpenGL>
+
+#include "roundedbox.h"
+#include "gltrianglemesh.h"
+#include "trackball.h"
+#include "glbuffers.h"
+#include "qtbox.h"
+
+#define PI 3.14159265358979
+
+QT_BEGIN_NAMESPACE
+class QMatrix4x4;
+QT_END_NAMESPACE
+
+class ParameterEdit : public QWidget
+{
+public:
+ virtual void emitChange() = 0;
+};
+
+class ColorEdit : public ParameterEdit
+{
+ Q_OBJECT
+public:
+ ColorEdit(QRgb initialColor, int id);
+ QRgb color() const {return m_color;}
+ virtual void emitChange() {emit colorChanged(m_color, m_id);}
+public slots:
+ void editDone();
+signals:
+ void colorChanged(QRgb color, int id);
+protected:
+ virtual void mousePressEvent(QMouseEvent *event);
+ void setColor(QRgb color); // also emits colorChanged()
+private:
+ QGraphicsScene *m_dialogParentScene;
+ QLineEdit *m_lineEdit;
+ QFrame *m_button;
+ QRgb m_color;
+ int m_id;
+};
+
+class FloatEdit : public ParameterEdit
+{
+ Q_OBJECT
+public:
+ FloatEdit(float initialValue, int id);
+ float value() const {return m_value;}
+ virtual void emitChange() {emit valueChanged(m_value, m_id);}
+public slots:
+ void editDone();
+signals:
+ void valueChanged(float value, int id);
+private:
+ QGraphicsScene *m_dialogParentScene;
+ QLineEdit *m_lineEdit;
+ float m_value;
+ int m_id;
+};
+
+class GraphicsWidget : public QGraphicsProxyWidget
+{
+public:
+ GraphicsWidget() : QGraphicsProxyWidget(0, Qt::Window) {}
+protected:
+ virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+ virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+};
+
+class TwoSidedGraphicsWidget : public QObject
+{
+ Q_OBJECT
+public:
+ TwoSidedGraphicsWidget(QGraphicsScene *scene);
+ void setWidget(int index, QWidget *widget);
+ QWidget *widget(int index);
+public slots:
+ void flip();
+protected slots:
+ void animateFlip();
+private:
+ GraphicsWidget *m_proxyWidgets[2];
+ int m_current;
+ int m_angle; // angle in degrees
+ int m_delta;
+};
+
+class RenderOptionsDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ RenderOptionsDialog();
+ int addTexture(const QString &name);
+ int addShader(const QString &name);
+ void emitParameterChanged();
+protected slots:
+ void setColorParameter(QRgb color, int id);
+ void setFloatParameter(float value, int id);
+signals:
+ void dynamicCubemapToggled(int);
+ void colorParameterChanged(const QString &, QRgb);
+ void floatParameterChanged(const QString &, float);
+ void textureChanged(int);
+ void shaderChanged(int);
+ void doubleClicked();
+protected:
+ virtual void mouseDoubleClickEvent(QMouseEvent *event);
+
+ QVector<QByteArray> m_parameterNames;
+ QComboBox *m_textureCombo;
+ QComboBox *m_shaderCombo;
+ QVector<ParameterEdit *> m_parameterEdits;
+};
+
+class ItemDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ enum ItemType {
+ QtBoxItem,
+ CircleItem,
+ SquareItem,
+ };
+
+ ItemDialog();
+public slots:
+ void triggerNewQtBox();
+ void triggerNewCircleItem();
+ void triggerNewSquareItem();
+signals:
+ void doubleClicked();
+ void newItemTriggered(ItemDialog::ItemType type);
+protected:
+ virtual void mouseDoubleClickEvent(QMouseEvent *event);
+};
+
+class Scene : public QGraphicsScene
+{
+ Q_OBJECT
+public:
+ Scene(int width, int height, int maxTextureSize);
+ ~Scene();
+ virtual void drawBackground(QPainter *painter, const QRectF &rect);
+
+public slots:
+ void setShader(int index);
+ void setTexture(int index);
+ void toggleDynamicCubemap(int state);
+ void setColorParameter(const QString &name, QRgb color);
+ void setFloatParameter(const QString &name, float value);
+ void newItem(ItemDialog::ItemType type);
+protected:
+ void renderBoxes(const QMatrix4x4 &view, int excludeBox = -2);
+ void setStates();
+ void setLights();
+ void defaultStates();
+ void renderCubemaps();
+
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+ virtual void wheelEvent(QGraphicsSceneWheelEvent * event);
+private:
+ void initGL();
+ QPointF pixelPosToViewPos(const QPointF& p);
+
+ QTime m_time;
+ int m_lastTime;
+ int m_mouseEventTime;
+ int m_distExp;
+ int m_frame;
+ int m_maxTextureSize;
+
+ int m_currentShader;
+ int m_currentTexture;
+ bool m_dynamicCubemap;
+ bool m_updateAllCubemaps;
+
+ RenderOptionsDialog *m_renderOptions;
+ ItemDialog *m_itemDialog;
+ QTimer *m_timer;
+ GLRoundedBox *m_box;
+ TrackBall m_trackBalls[3];
+ QVector<GLTexture *> m_textures;
+ GLTextureCube *m_environment;
+ GLTexture3D *m_noise;
+ GLRenderTargetCube *m_mainCubemap;
+ QVector<GLRenderTargetCube *> m_cubemaps;
+ QVector<QGLShaderProgram *> m_programs;
+ QGLShader *m_vertexShader;
+ QVector<QGLShader *> m_fragmentShaders;
+ QGLShader *m_environmentShader;
+ QGLShaderProgram *m_environmentProgram;
+};
+
+#endif
diff --git a/examples/widgets/graphicsview/boxes/smiley.png b/examples/widgets/graphicsview/boxes/smiley.png
new file mode 100644
index 0000000000..41cfda6b23
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/smiley.png
Binary files differ
diff --git a/examples/widgets/graphicsview/boxes/square.jpg b/examples/widgets/graphicsview/boxes/square.jpg
new file mode 100644
index 0000000000..03f53bd530
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/square.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/boxes/trackball.cpp b/examples/widgets/graphicsview/boxes/trackball.cpp
new file mode 100644
index 0000000000..b0e9c44628
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/trackball.cpp
@@ -0,0 +1,160 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "trackball.h"
+#include "scene.h"
+
+//============================================================================//
+// TrackBall //
+//============================================================================//
+
+TrackBall::TrackBall(TrackMode mode)
+ : m_angularVelocity(0)
+ , m_paused(false)
+ , m_pressed(false)
+ , m_mode(mode)
+{
+ m_axis = QVector3D(0, 1, 0);
+ m_rotation = QQuaternion();
+ m_lastTime = QTime::currentTime();
+}
+
+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 = QQuaternion();
+ m_lastTime = QTime::currentTime();
+}
+
+void TrackBall::push(const QPointF& p, const QQuaternion &)
+{
+ m_rotation = rotation();
+ m_pressed = true;
+ m_lastTime = QTime::currentTime();
+ m_lastPos = p;
+ m_angularVelocity = 0.0f;
+}
+
+void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
+{
+ if (!m_pressed)
+ return;
+
+ QTime currentTime = QTime::currentTime();
+ int msecs = m_lastTime.msecsTo(currentTime);
+ if (msecs <= 20)
+ return;
+
+ switch (m_mode) {
+ case Plane:
+ {
+ QLineF delta(m_lastPos, p);
+ m_angularVelocity = 180*delta.length() / (PI*msecs);
+ m_axis = QVector3D(-delta.dy(), delta.dx(), 0.0f).normalized();
+ m_axis = transformation.rotatedVector(m_axis);
+ m_rotation = QQuaternion::fromAxisAndAngle(m_axis, 180 / PI * delta.length()) * m_rotation;
+ }
+ break;
+ case Sphere:
+ {
+ QVector3D lastPos3D = QVector3D(m_lastPos.x(), m_lastPos.y(), 0.0f);
+ float sqrZ = 1 - QVector3D::dotProduct(lastPos3D, lastPos3D);
+ if (sqrZ > 0)
+ lastPos3D.setZ(sqrt(sqrZ));
+ else
+ lastPos3D.normalize();
+
+ QVector3D currentPos3D = QVector3D(p.x(), p.y(), 0.0f);
+ sqrZ = 1 - QVector3D::dotProduct(currentPos3D, currentPos3D);
+ if (sqrZ > 0)
+ currentPos3D.setZ(sqrt(sqrZ));
+ else
+ currentPos3D.normalize();
+
+ m_axis = QVector3D::crossProduct(lastPos3D, currentPos3D);
+ float angle = 180 / PI * asin(sqrt(QVector3D::dotProduct(m_axis, m_axis)));
+
+ m_angularVelocity = angle / msecs;
+ m_axis.normalize();
+ m_axis = transformation.rotatedVector(m_axis);
+ m_rotation = QQuaternion::fromAxisAndAngle(m_axis, angle) * m_rotation;
+ }
+ break;
+ }
+
+
+ m_lastPos = p;
+ m_lastTime = currentTime;
+}
+
+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);
+ m_pressed = false;
+}
+
+void TrackBall::start()
+{
+ m_lastTime = QTime::currentTime();
+ m_paused = false;
+}
+
+void TrackBall::stop()
+{
+ m_rotation = rotation();
+ m_paused = true;
+}
+
+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 QQuaternion::fromAxisAndAngle(m_axis, angle) * m_rotation;
+}
+
diff --git a/examples/widgets/graphicsview/boxes/trackball.h b/examples/widgets/graphicsview/boxes/trackball.h
new file mode 100644
index 0000000000..42a233c4f8
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/trackball.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TRACKBALL_H
+#define TRACKBALL_H
+
+#include <QtWidgets>
+
+#include <QtGui/qvector3d.h>
+#include <QtGui/qquaternion.h>
+
+class TrackBall
+{
+public:
+ enum TrackMode
+ {
+ Plane,
+ Sphere,
+ };
+ TrackBall(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 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
+ QQuaternion rotation() const;
+private:
+ QQuaternion m_rotation;
+ QVector3D m_axis;
+ float m_angularVelocity;
+
+ QPointF m_lastPos;
+ QTime m_lastTime;
+ bool m_paused;
+ bool m_pressed;
+ TrackMode m_mode;
+};
+
+#endif
diff --git a/examples/widgets/graphicsview/boxes/wood.fsh b/examples/widgets/graphicsview/boxes/wood.fsh
new file mode 100644
index 0000000000..a722bac869
--- /dev/null
+++ b/examples/widgets/graphicsview/boxes/wood.fsh
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+varying vec3 position, normal;
+varying vec4 specular, ambient, diffuse, lightDirection;
+
+uniform sampler2D tex;
+uniform sampler3D noise;
+
+//const vec4 woodColors[2] = {vec4(0.37,0.24,0.20,1), vec4(0.8,0.6,0.4,1)};
+uniform vec4 woodColors[2];
+//const float woodTubulence = 0.1;
+uniform float woodTubulence;
+
+void main()
+{
+ float r = length(gl_TexCoord[1].yz);
+ r += woodTubulence * texture3D(noise, 0.25 * gl_TexCoord[1].xyz).x;
+
+ vec3 N = normalize(normal);
+ // assume directional light
+
+ gl_MaterialParameters M = gl_FrontMaterial;
+
+ float NdotL = dot(N, lightDirection.xyz);
+ float RdotL = dot(reflect(normalize(position), N), lightDirection.xyz);
+
+ float f = fract(16.0 * r);
+ vec4 unlitColor = mix(woodColors[0], woodColors[1], min(1.25 * f, 5.0 - 5.0 * f));
+ gl_FragColor = (ambient + diffuse * max(NdotL, 0.0)) * unlitColor +
+ M.specular * specular * pow(max(RdotL, 0.0), M.shininess);
+}
diff --git a/examples/widgets/graphicsview/chip/chip.cpp b/examples/widgets/graphicsview/chip/chip.cpp
new file mode 100644
index 0000000000..665daea1dc
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/chip.cpp
@@ -0,0 +1,183 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "chip.h"
+
+#include <QtWidgets>
+
+Chip::Chip(const QColor &color, int x, int y)
+{
+ this->x = x;
+ this->y = y;
+ this->color = color;
+ setZValue((x + y) % 2);
+
+ setFlags(ItemIsSelectable | ItemIsMovable);
+ setAcceptHoverEvents(true);
+}
+
+QRectF Chip::boundingRect() const
+{
+ return QRectF(0, 0, 110, 70);
+}
+
+QPainterPath Chip::shape() const
+{
+ QPainterPath path;
+ path.addRect(14, 14, 82, 42);
+ return path;
+}
+
+void Chip::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(widget);
+
+ QColor fillColor = (option->state & QStyle::State_Selected) ? color.dark(150) : color;
+ if (option->state & QStyle::State_MouseOver)
+ fillColor = fillColor.light(125);
+
+ const qreal lod = option->levelOfDetailFromTransform(painter->worldTransform());
+ if (lod < 0.2) {
+ if (lod < 0.125) {
+ painter->fillRect(QRectF(0, 0, 110, 70), fillColor);
+ return;
+ }
+
+ QBrush b = painter->brush();
+ painter->setBrush(fillColor);
+ painter->drawRect(13, 13, 97, 57);
+ painter->setBrush(b);
+ return;
+ }
+
+ QPen oldPen = painter->pen();
+ QPen pen = oldPen;
+ int width = 0;
+ if (option->state & QStyle::State_Selected)
+ width += 2;
+
+ pen.setWidth(width);
+ QBrush b = painter->brush();
+ painter->setBrush(QBrush(fillColor.dark(option->state & QStyle::State_Sunken ? 120 : 100)));
+
+ painter->drawRect(QRect(14, 14, 79, 39));
+ painter->setBrush(b);
+
+ if (lod >= 1) {
+ painter->setPen(QPen(Qt::gray, 1));
+ painter->drawLine(15, 54, 94, 54);
+ painter->drawLine(94, 53, 94, 15);
+ painter->setPen(QPen(Qt::black, 0));
+ }
+
+ // Draw text
+ if (lod >= 2) {
+ QFont font("Times", 10);
+ font.setStyleStrategy(QFont::ForceOutline);
+ painter->setFont(font);
+ painter->save();
+ painter->scale(0.1, 0.1);
+ painter->drawText(170, 180, QString("Model: VSC-2000 (Very Small Chip) at %1x%2").arg(x).arg(y));
+ painter->drawText(170, 200, QString("Serial number: DLWR-WEER-123L-ZZ33-SDSJ"));
+ painter->drawText(170, 220, QString("Manufacturer: Chip Manufacturer"));
+ painter->restore();
+ }
+
+ // Draw lines
+ QVarLengthArray<QLineF, 36> lines;
+ if (lod >= 0.5) {
+ for (int i = 0; i <= 10; i += (lod > 0.5 ? 1 : 2)) {
+ lines.append(QLineF(18 + 7 * i, 13, 18 + 7 * i, 5));
+ lines.append(QLineF(18 + 7 * i, 54, 18 + 7 * i, 62));
+ }
+ for (int i = 0; i <= 6; i += (lod > 0.5 ? 1 : 2)) {
+ lines.append(QLineF(5, 18 + i * 5, 13, 18 + i * 5));
+ lines.append(QLineF(94, 18 + i * 5, 102, 18 + i * 5));
+ }
+ }
+ if (lod >= 0.4) {
+ const QLineF lineData[] = {
+ QLineF(25, 35, 35, 35),
+ QLineF(35, 30, 35, 40),
+ QLineF(35, 30, 45, 35),
+ QLineF(35, 40, 45, 35),
+ QLineF(45, 30, 45, 40),
+ QLineF(45, 35, 55, 35)
+ };
+ lines.append(lineData, 6);
+ }
+ painter->drawLines(lines.data(), lines.size());
+
+ // Draw red ink
+ if (stuff.size() > 1) {
+ QPen p = painter->pen();
+ painter->setPen(QPen(Qt::red, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
+ painter->setBrush(Qt::NoBrush);
+ QPainterPath path;
+ path.moveTo(stuff.first());
+ for (int i = 1; i < stuff.size(); ++i)
+ path.lineTo(stuff.at(i));
+ painter->drawPath(path);
+ painter->setPen(p);
+ }
+}
+
+void Chip::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsItem::mousePressEvent(event);
+ update();
+}
+
+void Chip::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (event->modifiers() & Qt::ShiftModifier) {
+ stuff << event->pos();
+ update();
+ return;
+ }
+ QGraphicsItem::mouseMoveEvent(event);
+}
+
+void Chip::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsItem::mouseReleaseEvent(event);
+ update();
+}
diff --git a/examples/widgets/graphicsview/chip/chip.h b/examples/widgets/graphicsview/chip/chip.h
new file mode 100644
index 0000000000..4c1cfae37d
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/chip.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CHIP_H
+#define CHIP_H
+
+#include <QtGui/QColor>
+#include <QtWidgets/QGraphicsItem>
+
+class Chip : public QGraphicsItem
+{
+public:
+ Chip(const QColor &color, int x, int y);
+
+ QRectF boundingRect() const;
+ QPainterPath shape() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget);
+
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+
+private:
+ int x, y;
+ QColor color;
+ QVector<QPointF> stuff;
+};
+
+#endif
diff --git a/examples/widgets/graphicsview/chip/chip.pro b/examples/widgets/graphicsview/chip/chip.pro
new file mode 100644
index 0000000000..afe748946e
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/chip.pro
@@ -0,0 +1,21 @@
+RESOURCES += images.qrc
+
+HEADERS += mainwindow.h view.h chip.h
+SOURCES += main.cpp
+SOURCES += mainwindow.cpp view.cpp chip.cpp
+
+QT += widgets
+!isEmpty(QT.printsupport.name): QT += printsupport
+contains(QT_CONFIG, opengl):QT += opengl
+
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/chip
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.png *.pro *.html *.doc images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/chip
+INSTALLS += target sources
+
diff --git a/examples/widgets/graphicsview/chip/fileprint.png b/examples/widgets/graphicsview/chip/fileprint.png
new file mode 100644
index 0000000000..ba7c02dc18
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/fileprint.png
Binary files differ
diff --git a/examples/widgets/graphicsview/chip/images.qrc b/examples/widgets/graphicsview/chip/images.qrc
new file mode 100644
index 0000000000..c7cdf0c4c0
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/images.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>qt4logo.png</file>
+ <file>zoomin.png</file>
+ <file>zoomout.png</file>
+ <file>rotateleft.png</file>
+ <file>rotateright.png</file>
+ <file>fileprint.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/graphicsview/chip/main.cpp b/examples/widgets/graphicsview/chip/main.cpp
new file mode 100644
index 0000000000..689c806be8
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(images);
+
+ QApplication app(argc, argv);
+ app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
+
+ MainWindow window;
+ window.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/graphicsview/chip/mainwindow.cpp b/examples/widgets/graphicsview/chip/mainwindow.cpp
new file mode 100644
index 0000000000..3d0d295225
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/mainwindow.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "view.h"
+#include "chip.h"
+
+#include <QtWidgets>
+
+MainWindow::MainWindow(QWidget *parent)
+ : QWidget(parent)
+{
+ populateScene();
+
+ h1Splitter = new QSplitter;
+ h2Splitter = new QSplitter;
+
+ QSplitter *vSplitter = new QSplitter;
+ vSplitter->setOrientation(Qt::Vertical);
+ vSplitter->addWidget(h1Splitter);
+ vSplitter->addWidget(h2Splitter);
+
+ View *view = new View("Top left view");
+ view->view()->setScene(scene);
+ h1Splitter->addWidget(view);
+
+ view = new View("Top right view");
+ view->view()->setScene(scene);
+ h1Splitter->addWidget(view);
+
+ view = new View("Bottom left view");
+ view->view()->setScene(scene);
+ h2Splitter->addWidget(view);
+
+ view = new View("Bottom right view");
+ view->view()->setScene(scene);
+ h2Splitter->addWidget(view);
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(vSplitter);
+ setLayout(layout);
+
+ setWindowTitle(tr("Chip Example"));
+}
+
+void MainWindow::populateScene()
+{
+ scene = new QGraphicsScene;
+
+ QImage image(":/qt4logo.png");
+
+ // Populate scene
+ int xx = 0;
+ int nitems = 0;
+ for (int i = -11000; i < 11000; i += 110) {
+ ++xx;
+ int yy = 0;
+ for (int j = -7000; j < 7000; j += 70) {
+ ++yy;
+ qreal x = (i + 11000) / 22000.0;
+ qreal y = (j + 7000) / 14000.0;
+
+ QColor color(image.pixel(int(image.width() * x), int(image.height() * y)));
+ QGraphicsItem *item = new Chip(color, xx, yy);
+ item->setPos(QPointF(i, j));
+ scene->addItem(item);
+
+ ++nitems;
+ }
+ }
+}
diff --git a/examples/widgets/graphicsview/chip/mainwindow.h b/examples/widgets/graphicsview/chip/mainwindow.h
new file mode 100644
index 0000000000..18e27a0019
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/mainwindow.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtWidgets/qwidget.h>
+
+QT_FORWARD_DECLARE_CLASS(QGraphicsScene)
+QT_FORWARD_DECLARE_CLASS(QGraphicsView)
+QT_FORWARD_DECLARE_CLASS(QLabel)
+QT_FORWARD_DECLARE_CLASS(QSlider)
+QT_FORWARD_DECLARE_CLASS(QSplitter)
+
+class MainWindow : public QWidget
+{
+ Q_OBJECT
+public:
+ MainWindow(QWidget *parent = 0);
+
+private:
+ void setupMatrix();
+ void populateScene();
+
+ QGraphicsScene *scene;
+ QSplitter *h1Splitter;
+ QSplitter *h2Splitter;
+};
+
+#endif
diff --git a/examples/widgets/graphicsview/chip/qt4logo.png b/examples/widgets/graphicsview/chip/qt4logo.png
new file mode 100644
index 0000000000..157e86ed64
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/qt4logo.png
Binary files differ
diff --git a/examples/widgets/graphicsview/chip/rotateleft.png b/examples/widgets/graphicsview/chip/rotateleft.png
new file mode 100644
index 0000000000..8cfa931986
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/rotateleft.png
Binary files differ
diff --git a/examples/widgets/graphicsview/chip/rotateright.png b/examples/widgets/graphicsview/chip/rotateright.png
new file mode 100644
index 0000000000..ec5e8664a1
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/rotateright.png
Binary files differ
diff --git a/examples/widgets/graphicsview/chip/view.cpp b/examples/widgets/graphicsview/chip/view.cpp
new file mode 100644
index 0000000000..b755b8eadd
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/view.cpp
@@ -0,0 +1,279 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "view.h"
+
+#include <QtWidgets>
+#ifndef QT_NO_PRINTER
+#include <QPrinter>
+#include <QPrintDialog>
+#endif
+#ifndef QT_NO_OPENGL
+#include <QtOpenGL>
+#endif
+#include <qmath.h>
+
+void GraphicsView::wheelEvent(QWheelEvent *e)
+{
+ if (e->modifiers() & Qt::ControlModifier) {
+ if (e->delta() > 0)
+ view->zoomIn(6);
+ else
+ view->zoomOut(6);
+ e->accept();
+ } else {
+ QGraphicsView::wheelEvent(e);
+ }
+}
+
+View::View(const QString &name, QWidget *parent)
+ : QFrame(parent)
+{
+ setFrameStyle(Sunken | StyledPanel);
+ graphicsView = new GraphicsView(this);
+ graphicsView->setRenderHint(QPainter::Antialiasing, false);
+ graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
+ graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
+ graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
+ graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
+
+ int size = style()->pixelMetric(QStyle::PM_ToolBarIconSize);
+ QSize iconSize(size, size);
+
+ QToolButton *zoomInIcon = new QToolButton;
+ zoomInIcon->setAutoRepeat(true);
+ zoomInIcon->setAutoRepeatInterval(33);
+ zoomInIcon->setAutoRepeatDelay(0);
+ zoomInIcon->setIcon(QPixmap(":/zoomin.png"));
+ zoomInIcon->setIconSize(iconSize);
+ QToolButton *zoomOutIcon = new QToolButton;
+ zoomOutIcon->setAutoRepeat(true);
+ zoomOutIcon->setAutoRepeatInterval(33);
+ zoomOutIcon->setAutoRepeatDelay(0);
+ zoomOutIcon->setIcon(QPixmap(":/zoomout.png"));
+ zoomOutIcon->setIconSize(iconSize);
+ zoomSlider = new QSlider;
+ zoomSlider->setMinimum(0);
+ zoomSlider->setMaximum(500);
+ zoomSlider->setValue(250);
+ zoomSlider->setTickPosition(QSlider::TicksRight);
+
+ // Zoom slider layout
+ QVBoxLayout *zoomSliderLayout = new QVBoxLayout;
+ zoomSliderLayout->addWidget(zoomInIcon);
+ zoomSliderLayout->addWidget(zoomSlider);
+ zoomSliderLayout->addWidget(zoomOutIcon);
+
+ QToolButton *rotateLeftIcon = new QToolButton;
+ rotateLeftIcon->setIcon(QPixmap(":/rotateleft.png"));
+ rotateLeftIcon->setIconSize(iconSize);
+ QToolButton *rotateRightIcon = new QToolButton;
+ rotateRightIcon->setIcon(QPixmap(":/rotateright.png"));
+ rotateRightIcon->setIconSize(iconSize);
+ rotateSlider = new QSlider;
+ rotateSlider->setOrientation(Qt::Horizontal);
+ rotateSlider->setMinimum(-360);
+ rotateSlider->setMaximum(360);
+ rotateSlider->setValue(0);
+ rotateSlider->setTickPosition(QSlider::TicksBelow);
+
+ // Rotate slider layout
+ QHBoxLayout *rotateSliderLayout = new QHBoxLayout;
+ rotateSliderLayout->addWidget(rotateLeftIcon);
+ rotateSliderLayout->addWidget(rotateSlider);
+ rotateSliderLayout->addWidget(rotateRightIcon);
+
+ resetButton = new QToolButton;
+ resetButton->setText(tr("0"));
+ resetButton->setEnabled(false);
+
+ // Label layout
+ QHBoxLayout *labelLayout = new QHBoxLayout;
+ label = new QLabel(name);
+ label2 = new QLabel(tr("Pointer Mode"));
+ selectModeButton = new QToolButton;
+ selectModeButton->setText(tr("Select"));
+ selectModeButton->setCheckable(true);
+ selectModeButton->setChecked(true);
+ dragModeButton = new QToolButton;
+ dragModeButton->setText(tr("Drag"));
+ dragModeButton->setCheckable(true);
+ dragModeButton->setChecked(false);
+ antialiasButton = new QToolButton;
+ antialiasButton->setText(tr("Antialiasing"));
+ antialiasButton->setCheckable(true);
+ antialiasButton->setChecked(false);
+ openGlButton = new QToolButton;
+ openGlButton->setText(tr("OpenGL"));
+ openGlButton->setCheckable(true);
+#ifndef QT_NO_OPENGL
+ openGlButton->setEnabled(QGLFormat::hasOpenGL());
+#else
+ openGlButton->setEnabled(false);
+#endif
+ printButton = new QToolButton;
+ printButton->setIcon(QIcon(QPixmap(":/fileprint.png")));
+
+ QButtonGroup *pointerModeGroup = new QButtonGroup;
+ pointerModeGroup->setExclusive(true);
+ pointerModeGroup->addButton(selectModeButton);
+ pointerModeGroup->addButton(dragModeButton);
+
+ labelLayout->addWidget(label);
+ labelLayout->addStretch();
+ labelLayout->addWidget(label2);
+ labelLayout->addWidget(selectModeButton);
+ labelLayout->addWidget(dragModeButton);
+ labelLayout->addStretch();
+ labelLayout->addWidget(antialiasButton);
+ labelLayout->addWidget(openGlButton);
+ labelLayout->addWidget(printButton);
+
+ QGridLayout *topLayout = new QGridLayout;
+ topLayout->addLayout(labelLayout, 0, 0);
+ topLayout->addWidget(graphicsView, 1, 0);
+ topLayout->addLayout(zoomSliderLayout, 1, 1);
+ topLayout->addLayout(rotateSliderLayout, 2, 0);
+ topLayout->addWidget(resetButton, 2, 1);
+ setLayout(topLayout);
+
+ connect(resetButton, SIGNAL(clicked()), this, SLOT(resetView()));
+ connect(zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
+ connect(rotateSlider, SIGNAL(valueChanged(int)), this, SLOT(setupMatrix()));
+ connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
+ connect(graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setResetButtonEnabled()));
+ connect(selectModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode()));
+ connect(dragModeButton, SIGNAL(toggled(bool)), this, SLOT(togglePointerMode()));
+ connect(antialiasButton, SIGNAL(toggled(bool)), this, SLOT(toggleAntialiasing()));
+ connect(openGlButton, SIGNAL(toggled(bool)), this, SLOT(toggleOpenGL()));
+ connect(rotateLeftIcon, SIGNAL(clicked()), this, SLOT(rotateLeft()));
+ connect(rotateRightIcon, SIGNAL(clicked()), this, SLOT(rotateRight()));
+ connect(zoomInIcon, SIGNAL(clicked()), this, SLOT(zoomIn()));
+ connect(zoomOutIcon, SIGNAL(clicked()), this, SLOT(zoomOut()));
+ connect(printButton, SIGNAL(clicked()), this, SLOT(print()));
+
+ setupMatrix();
+}
+
+QGraphicsView *View::view() const
+{
+ return static_cast<QGraphicsView *>(graphicsView);
+}
+
+void View::resetView()
+{
+ zoomSlider->setValue(250);
+ rotateSlider->setValue(0);
+ setupMatrix();
+ graphicsView->ensureVisible(QRectF(0, 0, 0, 0));
+
+ resetButton->setEnabled(false);
+}
+
+void View::setResetButtonEnabled()
+{
+ resetButton->setEnabled(true);
+}
+
+void View::setupMatrix()
+{
+ qreal scale = qPow(qreal(2), (zoomSlider->value() - 250) / qreal(50));
+
+ QMatrix matrix;
+ matrix.scale(scale, scale);
+ matrix.rotate(rotateSlider->value());
+
+ graphicsView->setMatrix(matrix);
+ setResetButtonEnabled();
+}
+
+void View::togglePointerMode()
+{
+ graphicsView->setDragMode(selectModeButton->isChecked()
+ ? QGraphicsView::RubberBandDrag
+ : QGraphicsView::ScrollHandDrag);
+ graphicsView->setInteractive(selectModeButton->isChecked());
+}
+
+void View::toggleOpenGL()
+{
+#ifndef QT_NO_OPENGL
+ graphicsView->setViewport(openGlButton->isChecked() ? new QGLWidget(QGLFormat(QGL::SampleBuffers)) : new QWidget);
+#endif
+}
+
+void View::toggleAntialiasing()
+{
+ graphicsView->setRenderHint(QPainter::Antialiasing, antialiasButton->isChecked());
+}
+
+void View::print()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer;
+ QPrintDialog dialog(&printer, this);
+ if (dialog.exec() == QDialog::Accepted) {
+ QPainter painter(&printer);
+ graphicsView->render(&painter);
+ }
+#endif
+}
+
+void View::zoomIn(int level)
+{
+ zoomSlider->setValue(zoomSlider->value() + level);
+}
+
+void View::zoomOut(int level)
+{
+ zoomSlider->setValue(zoomSlider->value() - level);
+}
+
+void View::rotateLeft()
+{
+ rotateSlider->setValue(rotateSlider->value() - 10);
+}
+
+void View::rotateRight()
+{
+ rotateSlider->setValue(rotateSlider->value() + 10);
+}
+
diff --git a/examples/widgets/graphicsview/chip/view.h b/examples/widgets/graphicsview/chip/view.h
new file mode 100644
index 0000000000..7753efff55
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/view.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VIEW_H
+#define VIEW_H
+
+#include <QFrame>
+#include <QGraphicsView>
+
+QT_FORWARD_DECLARE_CLASS(QLabel)
+QT_FORWARD_DECLARE_CLASS(QSlider)
+QT_FORWARD_DECLARE_CLASS(QToolButton)
+
+class View;
+
+class GraphicsView : public QGraphicsView
+{
+ Q_OBJECT
+public:
+ GraphicsView(View *v) : QGraphicsView(), view(v) { }
+
+protected:
+ void wheelEvent(QWheelEvent *);
+
+private:
+ View *view;
+};
+
+class View : public QFrame
+{
+ Q_OBJECT
+public:
+ View(const QString &name, QWidget *parent = 0);
+
+ QGraphicsView *view() const;
+
+public slots:
+ void zoomIn(int level = 1);
+ void zoomOut(int level = 1);
+
+private slots:
+ void resetView();
+ void setResetButtonEnabled();
+ void setupMatrix();
+ void togglePointerMode();
+ void toggleOpenGL();
+ void toggleAntialiasing();
+ void print();
+ void rotateLeft();
+ void rotateRight();
+
+private:
+ GraphicsView *graphicsView;
+ QLabel *label;
+ QLabel *label2;
+ QToolButton *selectModeButton;
+ QToolButton *dragModeButton;
+ QToolButton *openGlButton;
+ QToolButton *antialiasButton;
+ QToolButton *printButton;
+ QToolButton *resetButton;
+ QSlider *zoomSlider;
+ QSlider *rotateSlider;
+};
+
+#endif
diff --git a/examples/widgets/graphicsview/chip/zoomin.png b/examples/widgets/graphicsview/chip/zoomin.png
new file mode 100644
index 0000000000..8b0daeea48
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/zoomin.png
Binary files differ
diff --git a/examples/widgets/graphicsview/chip/zoomout.png b/examples/widgets/graphicsview/chip/zoomout.png
new file mode 100644
index 0000000000..1575dd24f6
--- /dev/null
+++ b/examples/widgets/graphicsview/chip/zoomout.png
Binary files differ
diff --git a/examples/widgets/graphicsview/collidingmice/collidingmice.desktop b/examples/widgets/graphicsview/collidingmice/collidingmice.desktop
new file mode 100644
index 0000000000..f0064e7112
--- /dev/null
+++ b/examples/widgets/graphicsview/collidingmice/collidingmice.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Colliding Mice
+Exec=/opt/usr/bin/collidingmice
+Icon=collidingmice
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/collidingmice/collidingmice.pro b/examples/widgets/graphicsview/collidingmice/collidingmice.pro
new file mode 100644
index 0000000000..d8346023ba
--- /dev/null
+++ b/examples/widgets/graphicsview/collidingmice/collidingmice.pro
@@ -0,0 +1,17 @@
+HEADERS += \
+ mouse.h
+SOURCES += \
+ main.cpp \
+ mouse.cpp
+
+RESOURCES += \
+ mice.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/collidingmice
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS collidingmice.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/collidingmice
+INSTALLS += target sources
+
+QT += widgets
+
diff --git a/examples/widgets/graphicsview/collidingmice/images/cheese.jpg b/examples/widgets/graphicsview/collidingmice/images/cheese.jpg
new file mode 100644
index 0000000000..dea5795fd0
--- /dev/null
+++ b/examples/widgets/graphicsview/collidingmice/images/cheese.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/collidingmice/main.cpp b/examples/widgets/graphicsview/collidingmice/main.cpp
new file mode 100644
index 0000000000..63b14cf075
--- /dev/null
+++ b/examples/widgets/graphicsview/collidingmice/main.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mouse.h"
+
+#include <QtWidgets>
+
+#include <math.h>
+
+static const int MouseCount = 7;
+
+//! [0]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+//! [0]
+
+//! [1]
+ QGraphicsScene scene;
+ scene.setSceneRect(-300, -300, 600, 600);
+//! [1] //! [2]
+ scene.setItemIndexMethod(QGraphicsScene::NoIndex);
+//! [2]
+
+//! [3]
+ for (int i = 0; i < MouseCount; ++i) {
+ Mouse *mouse = new Mouse;
+ mouse->setPos(::sin((i * 6.28) / MouseCount) * 200,
+ ::cos((i * 6.28) / MouseCount) * 200);
+ scene.addItem(mouse);
+ }
+//! [3]
+
+//! [4]
+ QGraphicsView view(&scene);
+ view.setRenderHint(QPainter::Antialiasing);
+ view.setBackgroundBrush(QPixmap(":/images/cheese.jpg"));
+//! [4] //! [5]
+ view.setCacheMode(QGraphicsView::CacheBackground);
+ view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
+ view.setDragMode(QGraphicsView::ScrollHandDrag);
+//! [5] //! [6]
+ view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
+ view.resize(400, 300);
+ view.show();
+
+ QTimer timer;
+ QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance()));
+ timer.start(1000 / 33);
+
+ return app.exec();
+}
+//! [6]
diff --git a/examples/widgets/graphicsview/collidingmice/mice.qrc b/examples/widgets/graphicsview/collidingmice/mice.qrc
new file mode 100644
index 0000000000..accdb4d0a6
--- /dev/null
+++ b/examples/widgets/graphicsview/collidingmice/mice.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>images/cheese.jpg</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/graphicsview/collidingmice/mouse.cpp b/examples/widgets/graphicsview/collidingmice/mouse.cpp
new file mode 100644
index 0000000000..2ffbeff6d5
--- /dev/null
+++ b/examples/widgets/graphicsview/collidingmice/mouse.cpp
@@ -0,0 +1,200 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mouse.h"
+
+#include <QGraphicsScene>
+#include <QPainter>
+#include <QStyleOption>
+
+#include <math.h>
+
+static const double Pi = 3.14159265358979323846264338327950288419717;
+static double TwoPi = 2.0 * Pi;
+
+static qreal normalizeAngle(qreal angle)
+{
+ while (angle < 0)
+ angle += TwoPi;
+ while (angle > TwoPi)
+ angle -= TwoPi;
+ return angle;
+}
+
+//! [0]
+Mouse::Mouse()
+ : angle(0), speed(0), mouseEyeDirection(0),
+ color(qrand() % 256, qrand() % 256, qrand() % 256)
+{
+ setRotation(qrand() % (360 * 16));
+}
+//! [0]
+
+//! [1]
+QRectF Mouse::boundingRect() const
+{
+ qreal adjust = 0.5;
+ return QRectF(-18 - adjust, -22 - adjust,
+ 36 + adjust, 60 + adjust);
+}
+//! [1]
+
+//! [2]
+QPainterPath Mouse::shape() const
+{
+ QPainterPath path;
+ path.addRect(-10, -20, 20, 40);
+ return path;
+}
+//! [2]
+
+//! [3]
+void Mouse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ // Body
+ painter->setBrush(color);
+ painter->drawEllipse(-10, -20, 20, 40);
+
+ // Eyes
+ painter->setBrush(Qt::white);
+ painter->drawEllipse(-10, -17, 8, 8);
+ painter->drawEllipse(2, -17, 8, 8);
+
+ // Nose
+ painter->setBrush(Qt::black);
+ painter->drawEllipse(QRectF(-2, -22, 4, 4));
+
+ // Pupils
+ painter->drawEllipse(QRectF(-8.0 + mouseEyeDirection, -17, 4, 4));
+ painter->drawEllipse(QRectF(4.0 + mouseEyeDirection, -17, 4, 4));
+
+ // Ears
+ painter->setBrush(scene()->collidingItems(this).isEmpty() ? Qt::darkYellow : Qt::red);
+ painter->drawEllipse(-17, -12, 16, 16);
+ painter->drawEllipse(1, -12, 16, 16);
+
+ // Tail
+ QPainterPath path(QPointF(0, 20));
+ path.cubicTo(-5, 22, -5, 22, 0, 25);
+ path.cubicTo(5, 27, 5, 32, 0, 30);
+ path.cubicTo(-5, 32, -5, 42, 0, 35);
+ painter->setBrush(Qt::NoBrush);
+ painter->drawPath(path);
+}
+//! [3]
+
+//! [4]
+void Mouse::advance(int step)
+{
+ if (!step)
+ return;
+//! [4]
+ // Don't move too far away
+//! [5]
+ QLineF lineToCenter(QPointF(0, 0), mapFromScene(0, 0));
+ if (lineToCenter.length() > 150) {
+ qreal angleToCenter = ::acos(lineToCenter.dx() / lineToCenter.length());
+ if (lineToCenter.dy() < 0)
+ angleToCenter = TwoPi - angleToCenter;
+ angleToCenter = normalizeAngle((Pi - angleToCenter) + Pi / 2);
+
+ if (angleToCenter < Pi && angleToCenter > Pi / 4) {
+ // Rotate left
+ angle += (angle < -Pi / 2) ? 0.25 : -0.25;
+ } else if (angleToCenter >= Pi && angleToCenter < (Pi + Pi / 2 + Pi / 4)) {
+ // Rotate right
+ angle += (angle < Pi / 2) ? 0.25 : -0.25;
+ }
+ } else if (::sin(angle) < 0) {
+ angle += 0.25;
+ } else if (::sin(angle) > 0) {
+ angle -= 0.25;
+//! [5] //! [6]
+ }
+//! [6]
+
+ // Try not to crash with any other mice
+//! [7]
+ QList<QGraphicsItem *> dangerMice = scene()->items(QPolygonF()
+ << mapToScene(0, 0)
+ << mapToScene(-30, -50)
+ << mapToScene(30, -50));
+ foreach (QGraphicsItem *item, dangerMice) {
+ if (item == this)
+ continue;
+
+ QLineF lineToMouse(QPointF(0, 0), mapFromItem(item, 0, 0));
+ qreal angleToMouse = ::acos(lineToMouse.dx() / lineToMouse.length());
+ if (lineToMouse.dy() < 0)
+ angleToMouse = TwoPi - angleToMouse;
+ angleToMouse = normalizeAngle((Pi - angleToMouse) + Pi / 2);
+
+ if (angleToMouse >= 0 && angleToMouse < Pi / 2) {
+ // Rotate right
+ angle += 0.5;
+ } else if (angleToMouse <= TwoPi && angleToMouse > (TwoPi - Pi / 2)) {
+ // Rotate left
+ angle -= 0.5;
+//! [7] //! [8]
+ }
+//! [8] //! [9]
+ }
+//! [9]
+
+ // Add some random movement
+//! [10]
+ if (dangerMice.size() > 1 && (qrand() % 10) == 0) {
+ if (qrand() % 1)
+ angle += (qrand() % 100) / 500.0;
+ else
+ angle -= (qrand() % 100) / 500.0;
+ }
+//! [10]
+
+//! [11]
+ speed += (-50 + qrand() % 100) / 100.0;
+
+ qreal dx = ::sin(angle) * 10;
+ mouseEyeDirection = (qAbs(dx / 5) < 1) ? 0 : dx / 5;
+
+ setRotation(rotation() + dx);
+ setPos(mapToParent(0, -(3 + sin(speed) * 3)));
+}
+//! [11]
diff --git a/examples/widgets/graphicsview/collidingmice/mouse.h b/examples/widgets/graphicsview/collidingmice/mouse.h
new file mode 100644
index 0000000000..fd036e8b93
--- /dev/null
+++ b/examples/widgets/graphicsview/collidingmice/mouse.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MOUSE_H
+#define MOUSE_H
+
+#include <QGraphicsItem>
+
+//! [0]
+class Mouse : public QGraphicsItem
+{
+public:
+ Mouse();
+
+ QRectF boundingRect() const;
+ QPainterPath shape() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget);
+
+protected:
+ void advance(int step);
+
+private:
+ qreal angle;
+ qreal speed;
+ qreal mouseEyeDirection;
+ QColor color;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/graphicsview/diagramscene/arrow.cpp b/examples/widgets/graphicsview/diagramscene/arrow.cpp
new file mode 100644
index 0000000000..236d836e13
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/arrow.cpp
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "arrow.h"
+#include <math.h>
+
+const qreal Pi = 3.14;
+
+//! [0]
+Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem, QGraphicsItem *parent)
+ : QGraphicsLineItem(parent)
+{
+ myStartItem = startItem;
+ myEndItem = endItem;
+ setFlag(QGraphicsItem::ItemIsSelectable, true);
+ myColor = Qt::black;
+ setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
+}
+//! [0]
+
+//! [1]
+QRectF Arrow::boundingRect() const
+{
+ qreal extra = (pen().width() + 20) / 2.0;
+
+ return QRectF(line().p1(), QSizeF(line().p2().x() - line().p1().x(),
+ line().p2().y() - line().p1().y()))
+ .normalized()
+ .adjusted(-extra, -extra, extra, extra);
+}
+//! [1]
+
+//! [2]
+QPainterPath Arrow::shape() const
+{
+ QPainterPath path = QGraphicsLineItem::shape();
+ path.addPolygon(arrowHead);
+ return path;
+}
+//! [2]
+
+//! [3]
+void Arrow::updatePosition()
+{
+ QLineF line(mapFromItem(myStartItem, 0, 0), mapFromItem(myEndItem, 0, 0));
+ setLine(line);
+}
+//! [3]
+
+//! [4]
+void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
+ QWidget *)
+{
+ if (myStartItem->collidesWithItem(myEndItem))
+ return;
+
+ QPen myPen = pen();
+ myPen.setColor(myColor);
+ qreal arrowSize = 20;
+ painter->setPen(myPen);
+ painter->setBrush(myColor);
+//! [4] //! [5]
+
+ QLineF centerLine(myStartItem->pos(), myEndItem->pos());
+ QPolygonF endPolygon = myEndItem->polygon();
+ QPointF p1 = endPolygon.first() + myEndItem->pos();
+ QPointF p2;
+ QPointF intersectPoint;
+ QLineF polyLine;
+ for (int i = 1; i < endPolygon.count(); ++i) {
+ p2 = endPolygon.at(i) + myEndItem->pos();
+ polyLine = QLineF(p1, p2);
+ QLineF::IntersectType intersectType =
+ polyLine.intersect(centerLine, &intersectPoint);
+ if (intersectType == QLineF::BoundedIntersection)
+ break;
+ p1 = p2;
+ }
+
+ setLine(QLineF(intersectPoint, myStartItem->pos()));
+//! [5] //! [6]
+
+ double angle = ::acos(line().dx() / line().length());
+ if (line().dy() >= 0)
+ angle = (Pi * 2) - angle;
+
+ QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize,
+ cos(angle + Pi / 3) * arrowSize);
+ QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
+ cos(angle + Pi - Pi / 3) * arrowSize);
+
+ arrowHead.clear();
+ arrowHead << line().p1() << arrowP1 << arrowP2;
+//! [6] //! [7]
+ painter->drawLine(line());
+ painter->drawPolygon(arrowHead);
+ if (isSelected()) {
+ painter->setPen(QPen(myColor, 1, Qt::DashLine));
+ QLineF myLine = line();
+ myLine.translate(0, 4.0);
+ painter->drawLine(myLine);
+ myLine.translate(0,-8.0);
+ painter->drawLine(myLine);
+ }
+}
+//! [7]
diff --git a/examples/widgets/graphicsview/diagramscene/arrow.h b/examples/widgets/graphicsview/diagramscene/arrow.h
new file mode 100644
index 0000000000..ac09d6ad00
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/arrow.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ARROW_H
+#define ARROW_H
+
+#include <QGraphicsLineItem>
+
+#include "diagramitem.h"
+
+QT_BEGIN_NAMESPACE
+class QGraphicsPolygonItem;
+class QGraphicsLineItem;
+class QGraphicsScene;
+class QRectF;
+class QGraphicsSceneMouseEvent;
+class QPainterPath;
+QT_END_NAMESPACE
+
+//! [0]
+class Arrow : public QGraphicsLineItem
+{
+public:
+ enum { Type = UserType + 4 };
+
+ Arrow(DiagramItem *startItem, DiagramItem *endItem,
+ QGraphicsItem *parent = 0);
+
+ int type() const
+ { return Type; }
+ QRectF boundingRect() const;
+ QPainterPath shape() const;
+ void setColor(const QColor &color)
+ { myColor = color; }
+ DiagramItem *startItem() const
+ { return myStartItem; }
+ DiagramItem *endItem() const
+ { return myEndItem; }
+
+ void updatePosition();
+
+protected:
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget = 0);
+
+private:
+ DiagramItem *myStartItem;
+ DiagramItem *myEndItem;
+ QColor myColor;
+ QPolygonF arrowHead;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/graphicsview/diagramscene/diagramitem.cpp b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp
new file mode 100644
index 0000000000..9509c30270
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "diagramitem.h"
+#include "arrow.h"
+
+//! [0]
+DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
+ QGraphicsItem *parent)
+ : QGraphicsPolygonItem(parent)
+{
+ myDiagramType = diagramType;
+ myContextMenu = contextMenu;
+
+ QPainterPath path;
+ switch (myDiagramType) {
+ case StartEnd:
+ path.moveTo(200, 50);
+ path.arcTo(150, 0, 50, 50, 0, 90);
+ path.arcTo(50, 0, 50, 50, 90, 90);
+ path.arcTo(50, 50, 50, 50, 180, 90);
+ path.arcTo(150, 50, 50, 50, 270, 90);
+ path.lineTo(200, 25);
+ myPolygon = path.toFillPolygon();
+ break;
+ case Conditional:
+ myPolygon << QPointF(-100, 0) << QPointF(0, 100)
+ << QPointF(100, 0) << QPointF(0, -100)
+ << QPointF(-100, 0);
+ break;
+ case Step:
+ myPolygon << QPointF(-100, -100) << QPointF(100, -100)
+ << QPointF(100, 100) << QPointF(-100, 100)
+ << QPointF(-100, -100);
+ break;
+ default:
+ myPolygon << QPointF(-120, -80) << QPointF(-70, 80)
+ << QPointF(120, 80) << QPointF(70, -80)
+ << QPointF(-120, -80);
+ break;
+ }
+ setPolygon(myPolygon);
+ setFlag(QGraphicsItem::ItemIsMovable, true);
+ setFlag(QGraphicsItem::ItemIsSelectable, true);
+ setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
+}
+//! [0]
+
+//! [1]
+void DiagramItem::removeArrow(Arrow *arrow)
+{
+ int index = arrows.indexOf(arrow);
+
+ if (index != -1)
+ arrows.removeAt(index);
+}
+//! [1]
+
+//! [2]
+void DiagramItem::removeArrows()
+{
+ foreach (Arrow *arrow, arrows) {
+ arrow->startItem()->removeArrow(arrow);
+ arrow->endItem()->removeArrow(arrow);
+ scene()->removeItem(arrow);
+ delete arrow;
+ }
+}
+//! [2]
+
+//! [3]
+void DiagramItem::addArrow(Arrow *arrow)
+{
+ arrows.append(arrow);
+}
+//! [3]
+
+//! [4]
+QPixmap DiagramItem::image() const
+{
+ QPixmap pixmap(250, 250);
+ pixmap.fill(Qt::transparent);
+ QPainter painter(&pixmap);
+ painter.setPen(QPen(Qt::black, 8));
+ painter.translate(125, 125);
+ painter.drawPolyline(myPolygon);
+
+ return pixmap;
+}
+//! [4]
+
+//! [5]
+void DiagramItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
+{
+ scene()->clearSelection();
+ setSelected(true);
+ myContextMenu->exec(event->screenPos());
+}
+//! [5]
+
+//! [6]
+QVariant DiagramItem::itemChange(GraphicsItemChange change,
+ const QVariant &value)
+{
+ if (change == QGraphicsItem::ItemPositionChange) {
+ foreach (Arrow *arrow, arrows) {
+ arrow->updatePosition();
+ }
+ }
+
+ return value;
+}
+//! [6]
diff --git a/examples/widgets/graphicsview/diagramscene/diagramitem.h b/examples/widgets/graphicsview/diagramscene/diagramitem.h
new file mode 100644
index 0000000000..07b3b6e830
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/diagramitem.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIAGRAMITEM_H
+#define DIAGRAMITEM_H
+
+#include <QGraphicsPixmapItem>
+#include <QList>
+
+QT_BEGIN_NAMESPACE
+class QPixmap;
+class QGraphicsItem;
+class QGraphicsScene;
+class QTextEdit;
+class QGraphicsSceneMouseEvent;
+class QMenu;
+class QGraphicsSceneContextMenuEvent;
+class QPainter;
+class QStyleOptionGraphicsItem;
+class QWidget;
+class QPolygonF;
+QT_END_NAMESPACE
+
+class Arrow;
+
+//! [0]
+class DiagramItem : public QGraphicsPolygonItem
+{
+public:
+ enum { Type = UserType + 15 };
+ enum DiagramType { Step, Conditional, StartEnd, Io };
+
+ DiagramItem(DiagramType diagramType, QMenu *contextMenu,
+ QGraphicsItem *parent = 0);
+
+ void removeArrow(Arrow *arrow);
+ void removeArrows();
+ DiagramType diagramType() const
+ { return myDiagramType; }
+ QPolygonF polygon() const
+ { return myPolygon; }
+ void addArrow(Arrow *arrow);
+ QPixmap image() const;
+ int type() const
+ { return Type;}
+
+protected:
+ void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+
+private:
+ DiagramType myDiagramType;
+ QPolygonF myPolygon;
+ QMenu *myContextMenu;
+ QList<Arrow *> arrows;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.cpp b/examples/widgets/graphicsview/diagramscene/diagramscene.cpp
new file mode 100644
index 0000000000..c4a654aa99
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/diagramscene.cpp
@@ -0,0 +1,240 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "diagramscene.h"
+#include "arrow.h"
+
+//! [0]
+DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
+ : QGraphicsScene(parent)
+{
+ myItemMenu = itemMenu;
+ myMode = MoveItem;
+ myItemType = DiagramItem::Step;
+ line = 0;
+ textItem = 0;
+ myItemColor = Qt::white;
+ myTextColor = Qt::black;
+ myLineColor = Qt::black;
+}
+//! [0]
+
+//! [1]
+void DiagramScene::setLineColor(const QColor &color)
+{
+ myLineColor = color;
+ if (isItemChange(Arrow::Type)) {
+ Arrow *item =
+ qgraphicsitem_cast<Arrow *>(selectedItems().first());
+ item->setColor(myLineColor);
+ update();
+ }
+}
+//! [1]
+
+//! [2]
+void DiagramScene::setTextColor(const QColor &color)
+{
+ myTextColor = color;
+ if (isItemChange(DiagramTextItem::Type)) {
+ DiagramTextItem *item =
+ qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first());
+ item->setDefaultTextColor(myTextColor);
+ }
+}
+//! [2]
+
+//! [3]
+void DiagramScene::setItemColor(const QColor &color)
+{
+ myItemColor = color;
+ if (isItemChange(DiagramItem::Type)) {
+ DiagramItem *item =
+ qgraphicsitem_cast<DiagramItem *>(selectedItems().first());
+ item->setBrush(myItemColor);
+ }
+}
+//! [3]
+
+//! [4]
+void DiagramScene::setFont(const QFont &font)
+{
+ myFont = font;
+
+ if (isItemChange(DiagramTextItem::Type)) {
+ QGraphicsTextItem *item =
+ qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first());
+ //At this point the selection can change so the first selected item might not be a DiagramTextItem
+ if (item)
+ item->setFont(myFont);
+ }
+}
+//! [4]
+
+void DiagramScene::setMode(Mode mode)
+{
+ myMode = mode;
+}
+
+void DiagramScene::setItemType(DiagramItem::DiagramType type)
+{
+ myItemType = type;
+}
+
+//! [5]
+void DiagramScene::editorLostFocus(DiagramTextItem *item)
+{
+ QTextCursor cursor = item->textCursor();
+ cursor.clearSelection();
+ item->setTextCursor(cursor);
+
+ if (item->toPlainText().isEmpty()) {
+ removeItem(item);
+ item->deleteLater();
+ }
+}
+//! [5]
+
+//! [6]
+void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
+{
+ if (mouseEvent->button() != Qt::LeftButton)
+ return;
+
+ DiagramItem *item;
+ switch (myMode) {
+ case InsertItem:
+ item = new DiagramItem(myItemType, myItemMenu);
+ item->setBrush(myItemColor);
+ addItem(item);
+ item->setPos(mouseEvent->scenePos());
+ emit itemInserted(item);
+ break;
+//! [6] //! [7]
+ case InsertLine:
+ line = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(),
+ mouseEvent->scenePos()));
+ line->setPen(QPen(myLineColor, 2));
+ addItem(line);
+ break;
+//! [7] //! [8]
+ case InsertText:
+ textItem = new DiagramTextItem();
+ textItem->setFont(myFont);
+ textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
+ textItem->setZValue(1000.0);
+ connect(textItem, SIGNAL(lostFocus(DiagramTextItem*)),
+ this, SLOT(editorLostFocus(DiagramTextItem*)));
+ connect(textItem, SIGNAL(selectedChange(QGraphicsItem*)),
+ this, SIGNAL(itemSelected(QGraphicsItem*)));
+ addItem(textItem);
+ textItem->setDefaultTextColor(myTextColor);
+ textItem->setPos(mouseEvent->scenePos());
+ emit textInserted(textItem);
+//! [8] //! [9]
+ default:
+ ;
+ }
+ QGraphicsScene::mousePressEvent(mouseEvent);
+}
+//! [9]
+
+//! [10]
+void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
+{
+ if (myMode == InsertLine && line != 0) {
+ QLineF newLine(line->line().p1(), mouseEvent->scenePos());
+ line->setLine(newLine);
+ } else if (myMode == MoveItem) {
+ QGraphicsScene::mouseMoveEvent(mouseEvent);
+ }
+}
+//! [10]
+
+//! [11]
+void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
+{
+ if (line != 0 && myMode == InsertLine) {
+ QList<QGraphicsItem *> startItems = items(line->line().p1());
+ if (startItems.count() && startItems.first() == line)
+ startItems.removeFirst();
+ QList<QGraphicsItem *> endItems = items(line->line().p2());
+ if (endItems.count() && endItems.first() == line)
+ endItems.removeFirst();
+
+ removeItem(line);
+ delete line;
+//! [11] //! [12]
+
+ if (startItems.count() > 0 && endItems.count() > 0 &&
+ startItems.first()->type() == DiagramItem::Type &&
+ endItems.first()->type() == DiagramItem::Type &&
+ startItems.first() != endItems.first()) {
+ DiagramItem *startItem =
+ qgraphicsitem_cast<DiagramItem *>(startItems.first());
+ DiagramItem *endItem =
+ qgraphicsitem_cast<DiagramItem *>(endItems.first());
+ Arrow *arrow = new Arrow(startItem, endItem);
+ arrow->setColor(myLineColor);
+ startItem->addArrow(arrow);
+ endItem->addArrow(arrow);
+ arrow->setZValue(-1000.0);
+ addItem(arrow);
+ arrow->updatePosition();
+ }
+ }
+//! [12] //! [13]
+ line = 0;
+ QGraphicsScene::mouseReleaseEvent(mouseEvent);
+}
+//! [13]
+
+//! [14]
+bool DiagramScene::isItemChange(int type)
+{
+ foreach (QGraphicsItem *item, selectedItems()) {
+ if (item->type() == type)
+ return true;
+ }
+ return false;
+}
+//! [14]
diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.desktop b/examples/widgets/graphicsview/diagramscene/diagramscene.desktop
new file mode 100644
index 0000000000..54506ff979
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/diagramscene.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Diagram Scene
+Exec=/opt/usr/bin/diagramscene
+Icon=diagramscene
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.h b/examples/widgets/graphicsview/diagramscene/diagramscene.h
new file mode 100644
index 0000000000..9f65eba890
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/diagramscene.h
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIAGRAMSCENE_H
+#define DIAGRAMSCENE_H
+
+#include <QGraphicsScene>
+#include "diagramitem.h"
+#include "diagramtextitem.h"
+
+QT_BEGIN_NAMESPACE
+class QGraphicsSceneMouseEvent;
+class QMenu;
+class QPointF;
+class QGraphicsLineItem;
+class QFont;
+class QGraphicsTextItem;
+class QColor;
+QT_END_NAMESPACE
+
+//! [0]
+class DiagramScene : public QGraphicsScene
+{
+ Q_OBJECT
+
+public:
+ enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
+
+ DiagramScene(QMenu *itemMenu, QObject *parent = 0);
+ QFont font() const
+ { return myFont; }
+ QColor textColor() const
+ { return myTextColor; }
+ QColor itemColor() const
+ { return myItemColor; }
+ QColor lineColor() const
+ { return myLineColor; }
+ void setLineColor(const QColor &color);
+ void setTextColor(const QColor &color);
+ void setItemColor(const QColor &color);
+ void setFont(const QFont &font);
+
+public slots:
+ void setMode(Mode mode);
+ void setItemType(DiagramItem::DiagramType type);
+ void editorLostFocus(DiagramTextItem *item);
+
+signals:
+ void itemInserted(DiagramItem *item);
+ void textInserted(QGraphicsTextItem *item);
+ void itemSelected(QGraphicsItem *item);
+
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
+
+private:
+ bool isItemChange(int type);
+
+ DiagramItem::DiagramType myItemType;
+ QMenu *myItemMenu;
+ Mode myMode;
+ bool leftButtonDown;
+ QPointF startPoint;
+ QGraphicsLineItem *line;
+ QFont myFont;
+ DiagramTextItem *textItem;
+ QColor myTextColor;
+ QColor myItemColor;
+ QColor myLineColor;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.pro b/examples/widgets/graphicsview/diagramscene/diagramscene.pro
new file mode 100644
index 0000000000..e45f4a894b
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/diagramscene.pro
@@ -0,0 +1,23 @@
+HEADERS = mainwindow.h \
+ diagramitem.h \
+ diagramscene.h \
+ arrow.h \
+ diagramtextitem.h
+SOURCES = mainwindow.cpp \
+ diagramitem.cpp \
+ main.cpp \
+ arrow.cpp \
+ diagramtextitem.cpp \
+ diagramscene.cpp
+RESOURCES = diagramscene.qrc
+
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/diagramscene
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS diagramscene.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/diagramscene
+INSTALLS += target sources
+
+
+QT += widgets
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.qrc b/examples/widgets/graphicsview/diagramscene/diagramscene.qrc
new file mode 100644
index 0000000000..a11158402f
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/diagramscene.qrc
@@ -0,0 +1,20 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/pointer.png</file>
+ <file>images/linepointer.png</file>
+ <file>images/textpointer.png</file>
+ <file>images/bold.png</file>
+ <file>images/italic.png</file>
+ <file>images/underline.png</file>
+ <file>images/floodfill.png</file>
+ <file>images/bringtofront.png</file>
+ <file>images/delete.png</file>
+ <file>images/sendtoback.png</file>
+ <file>images/linecolor.png</file>
+ <file>images/background1.png</file>
+ <file>images/background2.png</file>
+ <file>images/background3.png</file>
+ <file>images/background4.png</file>
+</qresource>
+</RCC>
+
diff --git a/examples/widgets/graphicsview/diagramscene/diagramtextitem.cpp b/examples/widgets/graphicsview/diagramscene/diagramtextitem.cpp
new file mode 100644
index 0000000000..1e583045da
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/diagramtextitem.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "diagramtextitem.h"
+#include "diagramscene.h"
+
+//! [0]
+DiagramTextItem::DiagramTextItem(QGraphicsItem *parent)
+ : QGraphicsTextItem(parent)
+{
+ setFlag(QGraphicsItem::ItemIsMovable);
+ setFlag(QGraphicsItem::ItemIsSelectable);
+}
+//! [0]
+
+//! [1]
+QVariant DiagramTextItem::itemChange(GraphicsItemChange change,
+ const QVariant &value)
+{
+ if (change == QGraphicsItem::ItemSelectedHasChanged)
+ emit selectedChange(this);
+ return value;
+}
+//! [1]
+
+//! [2]
+void DiagramTextItem::focusOutEvent(QFocusEvent *event)
+{
+ setTextInteractionFlags(Qt::NoTextInteraction);
+ emit lostFocus(this);
+ QGraphicsTextItem::focusOutEvent(event);
+}
+//! [2]
+
+//! [5]
+void DiagramTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (textInteractionFlags() == Qt::NoTextInteraction)
+ setTextInteractionFlags(Qt::TextEditorInteraction);
+ QGraphicsTextItem::mouseDoubleClickEvent(event);
+}
+//! [5]
diff --git a/examples/widgets/graphicsview/diagramscene/diagramtextitem.h b/examples/widgets/graphicsview/diagramscene/diagramtextitem.h
new file mode 100644
index 0000000000..611e9b6700
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/diagramtextitem.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIAGRAMTEXTITEM_H
+#define DIAGRAMTEXTITEM_H
+
+#include <QGraphicsTextItem>
+#include <QPen>
+
+QT_BEGIN_NAMESPACE
+class QFocusEvent;
+class QGraphicsItem;
+class QGraphicsScene;
+class QGraphicsSceneMouseEvent;
+QT_END_NAMESPACE
+
+//! [0]
+class DiagramTextItem : public QGraphicsTextItem
+{
+ Q_OBJECT
+
+public:
+ enum { Type = UserType + 3 };
+
+ DiagramTextItem(QGraphicsItem *parent = 0);
+
+ int type() const
+ { return Type; }
+
+signals:
+ void lostFocus(DiagramTextItem *item);
+ void selectedChange(QGraphicsItem *item);
+
+protected:
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+ void focusOutEvent(QFocusEvent *event);
+ void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/graphicsview/diagramscene/images/background1.png b/examples/widgets/graphicsview/diagramscene/images/background1.png
new file mode 100644
index 0000000000..0f93c6bf42
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/background1.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/background2.png b/examples/widgets/graphicsview/diagramscene/images/background2.png
new file mode 100644
index 0000000000..1e293db67a
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/background2.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/background3.png b/examples/widgets/graphicsview/diagramscene/images/background3.png
new file mode 100644
index 0000000000..3db4f8ea5f
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/background3.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/background4.png b/examples/widgets/graphicsview/diagramscene/images/background4.png
new file mode 100644
index 0000000000..9c1f3bfd77
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/background4.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/bold.png b/examples/widgets/graphicsview/diagramscene/images/bold.png
new file mode 100644
index 0000000000..986e65e250
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/bold.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/bringtofront.png b/examples/widgets/graphicsview/diagramscene/images/bringtofront.png
new file mode 100644
index 0000000000..bda27578a2
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/bringtofront.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/delete.png b/examples/widgets/graphicsview/diagramscene/images/delete.png
new file mode 100644
index 0000000000..df2a147d24
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/delete.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/floodfill.png b/examples/widgets/graphicsview/diagramscene/images/floodfill.png
new file mode 100644
index 0000000000..54c0dae237
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/floodfill.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/italic.png b/examples/widgets/graphicsview/diagramscene/images/italic.png
new file mode 100644
index 0000000000..9a438b57ad
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/italic.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/linecolor.png b/examples/widgets/graphicsview/diagramscene/images/linecolor.png
new file mode 100644
index 0000000000..98a821f27e
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/linecolor.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/linepointer.png b/examples/widgets/graphicsview/diagramscene/images/linepointer.png
new file mode 100644
index 0000000000..66933d43b3
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/linepointer.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/pointer.png b/examples/widgets/graphicsview/diagramscene/images/pointer.png
new file mode 100644
index 0000000000..0b0b0aa69d
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/pointer.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/sendtoback.png b/examples/widgets/graphicsview/diagramscene/images/sendtoback.png
new file mode 100644
index 0000000000..5aa3b0a243
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/sendtoback.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/textpointer.png b/examples/widgets/graphicsview/diagramscene/images/textpointer.png
new file mode 100644
index 0000000000..b25832cada
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/textpointer.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/images/underline.png b/examples/widgets/graphicsview/diagramscene/images/underline.png
new file mode 100644
index 0000000000..9b8209f525
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/images/underline.png
Binary files differ
diff --git a/examples/widgets/graphicsview/diagramscene/main.cpp b/examples/widgets/graphicsview/diagramscene/main.cpp
new file mode 100644
index 0000000000..33bc97b71f
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+int main(int argv, char *args[])
+{
+ Q_INIT_RESOURCE(diagramscene);
+
+ QApplication app(argv, args);
+ MainWindow mainWindow;
+ mainWindow.setGeometry(100, 100, 800, 500);
+ mainWindow.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp
new file mode 100644
index 0000000000..977730a3bb
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp
@@ -0,0 +1,661 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include <QLabel>
+
+#include "mainwindow.h"
+#include "diagramitem.h"
+#include "diagramscene.h"
+#include "diagramtextitem.h"
+#include "arrow.h"
+
+const int InsertTextButton = 10;
+
+//! [0]
+MainWindow::MainWindow()
+{
+ createActions();
+ createToolBox();
+ createMenus();
+
+ scene = new DiagramScene(itemMenu, this);
+ scene->setSceneRect(QRectF(0, 0, 5000, 5000));
+ connect(scene, SIGNAL(itemInserted(DiagramItem*)),
+ this, SLOT(itemInserted(DiagramItem*)));
+ connect(scene, SIGNAL(textInserted(QGraphicsTextItem*)),
+ this, SLOT(textInserted(QGraphicsTextItem*)));
+ connect(scene, SIGNAL(itemSelected(QGraphicsItem*)),
+ this, SLOT(itemSelected(QGraphicsItem*)));
+ createToolbars();
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(toolBox);
+ view = new QGraphicsView(scene);
+ layout->addWidget(view);
+
+ QWidget *widget = new QWidget;
+ widget->setLayout(layout);
+
+ setCentralWidget(widget);
+ setWindowTitle(tr("Diagramscene"));
+ setUnifiedTitleAndToolBarOnMac(true);
+}
+//! [0]
+
+//! [1]
+void MainWindow::backgroundButtonGroupClicked(QAbstractButton *button)
+{
+ QList<QAbstractButton *> buttons = backgroundButtonGroup->buttons();
+ foreach (QAbstractButton *myButton, buttons) {
+ if (myButton != button)
+ button->setChecked(false);
+ }
+ QString text = button->text();
+ if (text == tr("Blue Grid"))
+ scene->setBackgroundBrush(QPixmap(":/images/background1.png"));
+ else if (text == tr("White Grid"))
+ scene->setBackgroundBrush(QPixmap(":/images/background2.png"));
+ else if (text == tr("Gray Grid"))
+ scene->setBackgroundBrush(QPixmap(":/images/background3.png"));
+ else
+ scene->setBackgroundBrush(QPixmap(":/images/background4.png"));
+
+ scene->update();
+ view->update();
+}
+//! [1]
+
+//! [2]
+void MainWindow::buttonGroupClicked(int id)
+{
+ QList<QAbstractButton *> buttons = buttonGroup->buttons();
+ foreach (QAbstractButton *button, buttons) {
+ if (buttonGroup->button(id) != button)
+ button->setChecked(false);
+ }
+ if (id == InsertTextButton) {
+ scene->setMode(DiagramScene::InsertText);
+ } else {
+ scene->setItemType(DiagramItem::DiagramType(id));
+ scene->setMode(DiagramScene::InsertItem);
+ }
+}
+//! [2]
+
+//! [3]
+void MainWindow::deleteItem()
+{
+ foreach (QGraphicsItem *item, scene->selectedItems()) {
+ if (item->type() == Arrow::Type) {
+ scene->removeItem(item);
+ Arrow *arrow = qgraphicsitem_cast<Arrow *>(item);
+ arrow->startItem()->removeArrow(arrow);
+ arrow->endItem()->removeArrow(arrow);
+ delete item;
+ }
+ }
+
+ foreach (QGraphicsItem *item, scene->selectedItems()) {
+ if (item->type() == DiagramItem::Type) {
+ qgraphicsitem_cast<DiagramItem *>(item)->removeArrows();
+ }
+ scene->removeItem(item);
+ delete item;
+ }
+}
+//! [3]
+
+//! [4]
+void MainWindow::pointerGroupClicked(int)
+{
+ scene->setMode(DiagramScene::Mode(pointerTypeGroup->checkedId()));
+}
+//! [4]
+
+//! [5]
+void MainWindow::bringToFront()
+{
+ if (scene->selectedItems().isEmpty())
+ return;
+
+ QGraphicsItem *selectedItem = scene->selectedItems().first();
+ QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems();
+
+ qreal zValue = 0;
+ foreach (QGraphicsItem *item, overlapItems) {
+ if (item->zValue() >= zValue &&
+ item->type() == DiagramItem::Type)
+ zValue = item->zValue() + 0.1;
+ }
+ selectedItem->setZValue(zValue);
+}
+//! [5]
+
+//! [6]
+void MainWindow::sendToBack()
+{
+ if (scene->selectedItems().isEmpty())
+ return;
+
+ QGraphicsItem *selectedItem = scene->selectedItems().first();
+ QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems();
+
+ qreal zValue = 0;
+ foreach (QGraphicsItem *item, overlapItems) {
+ if (item->zValue() <= zValue &&
+ item->type() == DiagramItem::Type)
+ zValue = item->zValue() - 0.1;
+ }
+ selectedItem->setZValue(zValue);
+}
+//! [6]
+
+//! [7]
+void MainWindow::itemInserted(DiagramItem *item)
+{
+ pointerTypeGroup->button(int(DiagramScene::MoveItem))->setChecked(true);
+ scene->setMode(DiagramScene::Mode(pointerTypeGroup->checkedId()));
+ buttonGroup->button(int(item->diagramType()))->setChecked(false);
+}
+//! [7]
+
+//! [8]
+void MainWindow::textInserted(QGraphicsTextItem *)
+{
+ buttonGroup->button(InsertTextButton)->setChecked(false);
+ scene->setMode(DiagramScene::Mode(pointerTypeGroup->checkedId()));
+}
+//! [8]
+
+//! [9]
+void MainWindow::currentFontChanged(const QFont &)
+{
+ handleFontChange();
+}
+//! [9]
+
+//! [10]
+void MainWindow::fontSizeChanged(const QString &)
+{
+ handleFontChange();
+}
+//! [10]
+
+//! [11]
+void MainWindow::sceneScaleChanged(const QString &scale)
+{
+ double newScale = scale.left(scale.indexOf(tr("%"))).toDouble() / 100.0;
+ QMatrix oldMatrix = view->matrix();
+ view->resetMatrix();
+ view->translate(oldMatrix.dx(), oldMatrix.dy());
+ view->scale(newScale, newScale);
+}
+//! [11]
+
+//! [12]
+void MainWindow::textColorChanged()
+{
+ textAction = qobject_cast<QAction *>(sender());
+ fontColorToolButton->setIcon(createColorToolButtonIcon(
+ ":/images/textpointer.png",
+ qvariant_cast<QColor>(textAction->data())));
+ textButtonTriggered();
+}
+//! [12]
+
+//! [13]
+void MainWindow::itemColorChanged()
+{
+ fillAction = qobject_cast<QAction *>(sender());
+ fillColorToolButton->setIcon(createColorToolButtonIcon(
+ ":/images/floodfill.png",
+ qvariant_cast<QColor>(fillAction->data())));
+ fillButtonTriggered();
+}
+//! [13]
+
+//! [14]
+void MainWindow::lineColorChanged()
+{
+ lineAction = qobject_cast<QAction *>(sender());
+ lineColorToolButton->setIcon(createColorToolButtonIcon(
+ ":/images/linecolor.png",
+ qvariant_cast<QColor>(lineAction->data())));
+ lineButtonTriggered();
+}
+//! [14]
+
+//! [15]
+void MainWindow::textButtonTriggered()
+{
+ scene->setTextColor(qvariant_cast<QColor>(textAction->data()));
+}
+//! [15]
+
+//! [16]
+void MainWindow::fillButtonTriggered()
+{
+ scene->setItemColor(qvariant_cast<QColor>(fillAction->data()));
+}
+//! [16]
+
+//! [17]
+void MainWindow::lineButtonTriggered()
+{
+ scene->setLineColor(qvariant_cast<QColor>(lineAction->data()));
+}
+//! [17]
+
+//! [18]
+void MainWindow::handleFontChange()
+{
+ QFont font = fontCombo->currentFont();
+ font.setPointSize(fontSizeCombo->currentText().toInt());
+ font.setWeight(boldAction->isChecked() ? QFont::Bold : QFont::Normal);
+ font.setItalic(italicAction->isChecked());
+ font.setUnderline(underlineAction->isChecked());
+
+ scene->setFont(font);
+}
+//! [18]
+
+//! [19]
+void MainWindow::itemSelected(QGraphicsItem *item)
+{
+ DiagramTextItem *textItem =
+ qgraphicsitem_cast<DiagramTextItem *>(item);
+
+ QFont font = textItem->font();
+ fontCombo->setCurrentFont(font);
+ fontSizeCombo->setEditText(QString().setNum(font.pointSize()));
+ boldAction->setChecked(font.weight() == QFont::Bold);
+ italicAction->setChecked(font.italic());
+ underlineAction->setChecked(font.underline());
+}
+//! [19]
+
+//! [20]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Diagram Scene"),
+ tr("The <b>Diagram Scene</b> example shows "
+ "use of the graphics framework."));
+}
+//! [20]
+
+//! [21]
+void MainWindow::createToolBox()
+{
+ buttonGroup = new QButtonGroup(this);
+ buttonGroup->setExclusive(false);
+ connect(buttonGroup, SIGNAL(buttonClicked(int)),
+ this, SLOT(buttonGroupClicked(int)));
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(createCellWidget(tr("Conditional"),
+ DiagramItem::Conditional), 0, 0);
+ layout->addWidget(createCellWidget(tr("Process"),
+ DiagramItem::Step),0, 1);
+ layout->addWidget(createCellWidget(tr("Input/Output"),
+ DiagramItem::Io), 1, 0);
+//! [21]
+
+ QToolButton *textButton = new QToolButton;
+ textButton->setCheckable(true);
+ buttonGroup->addButton(textButton, InsertTextButton);
+ textButton->setIcon(QIcon(QPixmap(":/images/textpointer.png")
+ .scaled(30, 30)));
+ textButton->setIconSize(QSize(50, 50));
+ QGridLayout *textLayout = new QGridLayout;
+ textLayout->addWidget(textButton, 0, 0, Qt::AlignHCenter);
+ textLayout->addWidget(new QLabel(tr("Text")), 1, 0, Qt::AlignCenter);
+ QWidget *textWidget = new QWidget;
+ textWidget->setLayout(textLayout);
+ layout->addWidget(textWidget, 1, 1);
+
+ layout->setRowStretch(3, 10);
+ layout->setColumnStretch(2, 10);
+
+ QWidget *itemWidget = new QWidget;
+ itemWidget->setLayout(layout);
+
+ backgroundButtonGroup = new QButtonGroup(this);
+ connect(backgroundButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)),
+ this, SLOT(backgroundButtonGroupClicked(QAbstractButton*)));
+
+ QGridLayout *backgroundLayout = new QGridLayout;
+ backgroundLayout->addWidget(createBackgroundCellWidget(tr("Blue Grid"),
+ ":/images/background1.png"), 0, 0);
+ backgroundLayout->addWidget(createBackgroundCellWidget(tr("White Grid"),
+ ":/images/background2.png"), 0, 1);
+ backgroundLayout->addWidget(createBackgroundCellWidget(tr("Gray Grid"),
+ ":/images/background3.png"), 1, 0);
+ backgroundLayout->addWidget(createBackgroundCellWidget(tr("No Grid"),
+ ":/images/background4.png"), 1, 1);
+
+ backgroundLayout->setRowStretch(2, 10);
+ backgroundLayout->setColumnStretch(2, 10);
+
+ QWidget *backgroundWidget = new QWidget;
+ backgroundWidget->setLayout(backgroundLayout);
+
+
+//! [22]
+ toolBox = new QToolBox;
+ toolBox->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Ignored));
+ toolBox->setMinimumWidth(itemWidget->sizeHint().width());
+ toolBox->addItem(itemWidget, tr("Basic Flowchart Shapes"));
+ toolBox->addItem(backgroundWidget, tr("Backgrounds"));
+}
+//! [22]
+
+//! [23]
+void MainWindow::createActions()
+{
+ toFrontAction = new QAction(QIcon(":/images/bringtofront.png"),
+ tr("Bring to &Front"), this);
+ toFrontAction->setShortcut(tr("Ctrl+F"));
+ toFrontAction->setStatusTip(tr("Bring item to front"));
+ connect(toFrontAction, SIGNAL(triggered()),
+ this, SLOT(bringToFront()));
+//! [23]
+
+ sendBackAction = new QAction(QIcon(":/images/sendtoback.png"),
+ tr("Send to &Back"), this);
+ sendBackAction->setShortcut(tr("Ctrl+B"));
+ sendBackAction->setStatusTip(tr("Send item to back"));
+ connect(sendBackAction, SIGNAL(triggered()),
+ this, SLOT(sendToBack()));
+
+ deleteAction = new QAction(QIcon(":/images/delete.png"),
+ tr("&Delete"), this);
+ deleteAction->setShortcut(tr("Delete"));
+ deleteAction->setStatusTip(tr("Delete item from diagram"));
+ connect(deleteAction, SIGNAL(triggered()),
+ this, SLOT(deleteItem()));
+
+ exitAction = new QAction(tr("E&xit"), this);
+ exitAction->setShortcuts(QKeySequence::Quit);
+ exitAction->setStatusTip(tr("Quit Scenediagram example"));
+ connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
+
+ boldAction = new QAction(tr("Bold"), this);
+ boldAction->setCheckable(true);
+ QPixmap pixmap(":/images/bold.png");
+ boldAction->setIcon(QIcon(pixmap));
+ boldAction->setShortcut(tr("Ctrl+B"));
+ connect(boldAction, SIGNAL(triggered()),
+ this, SLOT(handleFontChange()));
+
+ italicAction = new QAction(QIcon(":/images/italic.png"),
+ tr("Italic"), this);
+ italicAction->setCheckable(true);
+ italicAction->setShortcut(tr("Ctrl+I"));
+ connect(italicAction, SIGNAL(triggered()),
+ this, SLOT(handleFontChange()));
+
+ underlineAction = new QAction(QIcon(":/images/underline.png"),
+ tr("Underline"), this);
+ underlineAction->setCheckable(true);
+ underlineAction->setShortcut(tr("Ctrl+U"));
+ connect(underlineAction, SIGNAL(triggered()),
+ this, SLOT(handleFontChange()));
+
+ aboutAction = new QAction(tr("A&bout"), this);
+ aboutAction->setShortcut(tr("Ctrl+B"));
+ connect(aboutAction, SIGNAL(triggered()),
+ this, SLOT(about()));
+}
+
+//! [24]
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(exitAction);
+
+ itemMenu = menuBar()->addMenu(tr("&Item"));
+ itemMenu->addAction(deleteAction);
+ itemMenu->addSeparator();
+ itemMenu->addAction(toFrontAction);
+ itemMenu->addAction(sendBackAction);
+
+ aboutMenu = menuBar()->addMenu(tr("&Help"));
+ aboutMenu->addAction(aboutAction);
+}
+//! [24]
+
+//! [25]
+void MainWindow::createToolbars()
+{
+//! [25]
+ editToolBar = addToolBar(tr("Edit"));
+ editToolBar->addAction(deleteAction);
+ editToolBar->addAction(toFrontAction);
+ editToolBar->addAction(sendBackAction);
+
+ fontCombo = new QFontComboBox();
+ connect(fontCombo, SIGNAL(currentFontChanged(QFont)),
+ this, SLOT(currentFontChanged(QFont)));
+
+ fontSizeCombo = new QComboBox;
+ fontSizeCombo->setEditable(true);
+ for (int i = 8; i < 30; i = i + 2)
+ fontSizeCombo->addItem(QString().setNum(i));
+ QIntValidator *validator = new QIntValidator(2, 64, this);
+ fontSizeCombo->setValidator(validator);
+ connect(fontSizeCombo, SIGNAL(currentIndexChanged(QString)),
+ this, SLOT(fontSizeChanged(QString)));
+
+ fontColorToolButton = new QToolButton;
+ fontColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
+ fontColorToolButton->setMenu(createColorMenu(SLOT(textColorChanged()),
+ Qt::black));
+ textAction = fontColorToolButton->menu()->defaultAction();
+ fontColorToolButton->setIcon(createColorToolButtonIcon(
+ ":/images/textpointer.png", Qt::black));
+ fontColorToolButton->setAutoFillBackground(true);
+ connect(fontColorToolButton, SIGNAL(clicked()),
+ this, SLOT(textButtonTriggered()));
+
+//! [26]
+ fillColorToolButton = new QToolButton;
+ fillColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
+ fillColorToolButton->setMenu(createColorMenu(SLOT(itemColorChanged()),
+ Qt::white));
+ fillAction = fillColorToolButton->menu()->defaultAction();
+ fillColorToolButton->setIcon(createColorToolButtonIcon(
+ ":/images/floodfill.png", Qt::white));
+ connect(fillColorToolButton, SIGNAL(clicked()),
+ this, SLOT(fillButtonTriggered()));
+//! [26]
+
+ lineColorToolButton = new QToolButton;
+ lineColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
+ lineColorToolButton->setMenu(createColorMenu(SLOT(lineColorChanged()),
+ Qt::black));
+ lineAction = lineColorToolButton->menu()->defaultAction();
+ lineColorToolButton->setIcon(createColorToolButtonIcon(
+ ":/images/linecolor.png", Qt::black));
+ connect(lineColorToolButton, SIGNAL(clicked()),
+ this, SLOT(lineButtonTriggered()));
+
+ textToolBar = addToolBar(tr("Font"));
+ textToolBar->addWidget(fontCombo);
+ textToolBar->addWidget(fontSizeCombo);
+ textToolBar->addAction(boldAction);
+ textToolBar->addAction(italicAction);
+ textToolBar->addAction(underlineAction);
+
+ colorToolBar = addToolBar(tr("Color"));
+ colorToolBar->addWidget(fontColorToolButton);
+ colorToolBar->addWidget(fillColorToolButton);
+ colorToolBar->addWidget(lineColorToolButton);
+
+ QToolButton *pointerButton = new QToolButton;
+ pointerButton->setCheckable(true);
+ pointerButton->setChecked(true);
+ pointerButton->setIcon(QIcon(":/images/pointer.png"));
+ QToolButton *linePointerButton = new QToolButton;
+ linePointerButton->setCheckable(true);
+ linePointerButton->setIcon(QIcon(":/images/linepointer.png"));
+
+ pointerTypeGroup = new QButtonGroup(this);
+ pointerTypeGroup->addButton(pointerButton, int(DiagramScene::MoveItem));
+ pointerTypeGroup->addButton(linePointerButton,
+ int(DiagramScene::InsertLine));
+ connect(pointerTypeGroup, SIGNAL(buttonClicked(int)),
+ this, SLOT(pointerGroupClicked(int)));
+
+ sceneScaleCombo = new QComboBox;
+ QStringList scales;
+ scales << tr("50%") << tr("75%") << tr("100%") << tr("125%") << tr("150%");
+ sceneScaleCombo->addItems(scales);
+ sceneScaleCombo->setCurrentIndex(2);
+ connect(sceneScaleCombo, SIGNAL(currentIndexChanged(QString)),
+ this, SLOT(sceneScaleChanged(QString)));
+
+ pointerToolbar = addToolBar(tr("Pointer type"));
+ pointerToolbar->addWidget(pointerButton);
+ pointerToolbar->addWidget(linePointerButton);
+ pointerToolbar->addWidget(sceneScaleCombo);
+//! [27]
+}
+//! [27]
+
+//! [28]
+QWidget *MainWindow::createBackgroundCellWidget(const QString &text,
+ const QString &image)
+{
+ QToolButton *button = new QToolButton;
+ button->setText(text);
+ button->setIcon(QIcon(image));
+ button->setIconSize(QSize(50, 50));
+ button->setCheckable(true);
+ backgroundButtonGroup->addButton(button);
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(button, 0, 0, Qt::AlignHCenter);
+ layout->addWidget(new QLabel(text), 1, 0, Qt::AlignCenter);
+
+ QWidget *widget = new QWidget;
+ widget->setLayout(layout);
+
+ return widget;
+}
+//! [28]
+
+//! [29]
+QWidget *MainWindow::createCellWidget(const QString &text,
+ DiagramItem::DiagramType type)
+{
+
+ DiagramItem item(type, itemMenu);
+ QIcon icon(item.image());
+
+ QToolButton *button = new QToolButton;
+ button->setIcon(icon);
+ button->setIconSize(QSize(50, 50));
+ button->setCheckable(true);
+ buttonGroup->addButton(button, int(type));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(button, 0, 0, Qt::AlignHCenter);
+ layout->addWidget(new QLabel(text), 1, 0, Qt::AlignCenter);
+
+ QWidget *widget = new QWidget;
+ widget->setLayout(layout);
+
+ return widget;
+}
+//! [29]
+
+//! [30]
+QMenu *MainWindow::createColorMenu(const char *slot, QColor defaultColor)
+{
+ QList<QColor> colors;
+ colors << Qt::black << Qt::white << Qt::red << Qt::blue << Qt::yellow;
+ QStringList names;
+ names << tr("black") << tr("white") << tr("red") << tr("blue")
+ << tr("yellow");
+
+ QMenu *colorMenu = new QMenu(this);
+ for (int i = 0; i < colors.count(); ++i) {
+ QAction *action = new QAction(names.at(i), this);
+ action->setData(colors.at(i));
+ action->setIcon(createColorIcon(colors.at(i)));
+ connect(action, SIGNAL(triggered()),
+ this, slot);
+ colorMenu->addAction(action);
+ if (colors.at(i) == defaultColor) {
+ colorMenu->setDefaultAction(action);
+ }
+ }
+ return colorMenu;
+}
+//! [30]
+
+//! [31]
+QIcon MainWindow::createColorToolButtonIcon(const QString &imageFile,
+ QColor color)
+{
+ QPixmap pixmap(50, 80);
+ pixmap.fill(Qt::transparent);
+ QPainter painter(&pixmap);
+ QPixmap image(imageFile);
+ QRect target(0, 0, 50, 60);
+ QRect source(0, 0, 42, 42);
+ painter.fillRect(QRect(0, 60, 50, 80), color);
+ painter.drawPixmap(target, image, source);
+
+ return QIcon(pixmap);
+}
+//! [31]
+
+//! [32]
+QIcon MainWindow::createColorIcon(QColor color)
+{
+ QPixmap pixmap(20, 20);
+ QPainter painter(&pixmap);
+ painter.setPen(Qt::NoPen);
+ painter.fillRect(QRect(0, 0, 20, 20), color);
+
+ return QIcon(pixmap);
+}
+//! [32]
diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.h b/examples/widgets/graphicsview/diagramscene/mainwindow.h
new file mode 100644
index 0000000000..e3c0496c79
--- /dev/null
+++ b/examples/widgets/graphicsview/diagramscene/mainwindow.h
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include "diagramitem.h"
+
+class DiagramScene;
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QToolBox;
+class QSpinBox;
+class QComboBox;
+class QFontComboBox;
+class QButtonGroup;
+class QLineEdit;
+class QGraphicsTextItem;
+class QFont;
+class QToolButton;
+class QAbstractButton;
+class QGraphicsView;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void backgroundButtonGroupClicked(QAbstractButton *button);
+ void buttonGroupClicked(int id);
+ void deleteItem();
+ void pointerGroupClicked(int id);
+ void bringToFront();
+ void sendToBack();
+ void itemInserted(DiagramItem *item);
+ void textInserted(QGraphicsTextItem *item);
+ void currentFontChanged(const QFont &font);
+ void fontSizeChanged(const QString &size);
+ void sceneScaleChanged(const QString &scale);
+ void textColorChanged();
+ void itemColorChanged();
+ void lineColorChanged();
+ void textButtonTriggered();
+ void fillButtonTriggered();
+ void lineButtonTriggered();
+ void handleFontChange();
+ void itemSelected(QGraphicsItem *item);
+ void about();
+
+private:
+ void createToolBox();
+ void createActions();
+ void createMenus();
+ void createToolbars();
+ QWidget *createBackgroundCellWidget(const QString &text,
+ const QString &image);
+ QWidget *createCellWidget(const QString &text,
+ DiagramItem::DiagramType type);
+ QMenu *createColorMenu(const char *slot, QColor defaultColor);
+ QIcon createColorToolButtonIcon(const QString &image, QColor color);
+ QIcon createColorIcon(QColor color);
+
+ DiagramScene *scene;
+ QGraphicsView *view;
+
+ QAction *exitAction;
+ QAction *addAction;
+ QAction *deleteAction;
+
+ QAction *toFrontAction;
+ QAction *sendBackAction;
+ QAction *aboutAction;
+
+ QMenu *fileMenu;
+ QMenu *itemMenu;
+ QMenu *aboutMenu;
+
+ QToolBar *textToolBar;
+ QToolBar *editToolBar;
+ QToolBar *colorToolBar;
+ QToolBar *pointerToolbar;
+
+ QComboBox *sceneScaleCombo;
+ QComboBox *itemColorCombo;
+ QComboBox *textColorCombo;
+ QComboBox *fontSizeCombo;
+ QFontComboBox *fontCombo;
+
+ QToolBox *toolBox;
+ QButtonGroup *buttonGroup;
+ QButtonGroup *pointerTypeGroup;
+ QButtonGroup *backgroundButtonGroup;
+ QToolButton *fontColorToolButton;
+ QToolButton *fillColorToolButton;
+ QToolButton *lineColorToolButton;
+ QAction *boldAction;
+ QAction *underlineAction;
+ QAction *italicAction;
+ QAction *textAction;
+ QAction *fillAction;
+ QAction *lineAction;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp b/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp
new file mode 100644
index 0000000000..18e7a01af2
--- /dev/null
+++ b/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp
@@ -0,0 +1,142 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "coloritem.h"
+
+//! [0]
+ColorItem::ColorItem()
+ : color(qrand() % 256, qrand() % 256, qrand() % 256)
+{
+ setToolTip(QString("QColor(%1, %2, %3)\n%4")
+ .arg(color.red()).arg(color.green()).arg(color.blue())
+ .arg("Click and drag this color onto the robot!"));
+ setCursor(Qt::OpenHandCursor);
+ setAcceptedMouseButtons(Qt::LeftButton);
+}
+//! [0]
+
+//! [1]
+QRectF ColorItem::boundingRect() const
+{
+ return QRectF(-15.5, -15.5, 34, 34);
+}
+//! [1]
+
+//! [2]
+void ColorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(Qt::darkGray);
+ painter->drawEllipse(-12, -12, 30, 30);
+ painter->setPen(QPen(Qt::black, 1));
+ painter->setBrush(QBrush(color));
+ painter->drawEllipse(-15, -15, 30, 30);
+}
+//! [2]
+
+//! [3]
+void ColorItem::mousePressEvent(QGraphicsSceneMouseEvent *)
+{
+ setCursor(Qt::ClosedHandCursor);
+}
+//! [3]
+
+//! [5]
+void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton))
+ .length() < QApplication::startDragDistance()) {
+ return;
+ }
+
+ QDrag *drag = new QDrag(event->widget());
+ QMimeData *mime = new QMimeData;
+ drag->setMimeData(mime);
+//! [5]
+
+//! [6]
+ static int n = 0;
+ if (n++ > 2 && (qrand() % 3) == 0) {
+ QImage image(":/images/head.png");
+ mime->setImageData(image);
+
+ drag->setPixmap(QPixmap::fromImage(image).scaled(30, 40));
+ drag->setHotSpot(QPoint(15, 30));
+//! [6]
+//! [7]
+ } else {
+ mime->setColorData(color);
+ mime->setText(QString("#%1%2%3")
+ .arg(color.red(), 2, 16, QLatin1Char('0'))
+ .arg(color.green(), 2, 16, QLatin1Char('0'))
+ .arg(color.blue(), 2, 16, QLatin1Char('0')));
+
+ QPixmap pixmap(34, 34);
+ pixmap.fill(Qt::white);
+
+ QPainter painter(&pixmap);
+ painter.translate(15, 15);
+ painter.setRenderHint(QPainter::Antialiasing);
+ paint(&painter, 0, 0);
+ painter.end();
+
+ pixmap.setMask(pixmap.createHeuristicMask());
+
+ drag->setPixmap(pixmap);
+ drag->setHotSpot(QPoint(15, 20));
+ }
+//! [7]
+
+//! [8]
+ drag->exec();
+ setCursor(Qt::OpenHandCursor);
+}
+//! [8]
+
+//! [4]
+void ColorItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
+{
+ setCursor(Qt::OpenHandCursor);
+}
+//! [4]
diff --git a/examples/widgets/graphicsview/dragdroprobot/coloritem.h b/examples/widgets/graphicsview/dragdroprobot/coloritem.h
new file mode 100644
index 0000000000..9d3b4a9693
--- /dev/null
+++ b/examples/widgets/graphicsview/dragdroprobot/coloritem.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COLORITEM_H
+#define COLORITEM_H
+
+#include <QGraphicsItem>
+
+//! [0]
+class ColorItem : public QGraphicsItem
+{
+public:
+ ColorItem();
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+
+private:
+ QColor color;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.desktop b/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.desktop
new file mode 100644
index 0000000000..c01e3a3425
--- /dev/null
+++ b/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Drag and Drop Robot
+Exec=/opt/usr/bin/dragdroprobot
+Icon=dragdroprobot
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.pro b/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.pro
new file mode 100644
index 0000000000..3e33bad2f9
--- /dev/null
+++ b/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.pro
@@ -0,0 +1,22 @@
+HEADERS += \
+ coloritem.h \
+ robot.h
+
+SOURCES += \
+ coloritem.cpp \
+ main.cpp \
+ robot.cpp
+
+RESOURCES += \
+ robot.qrc
+
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/dragdroprobot
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS dragdroprobot.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/dragdroprobot
+INSTALLS += target sources
+
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/graphicsview/dragdroprobot/images/head.png b/examples/widgets/graphicsview/dragdroprobot/images/head.png
new file mode 100644
index 0000000000..1e520e09b8
--- /dev/null
+++ b/examples/widgets/graphicsview/dragdroprobot/images/head.png
Binary files differ
diff --git a/examples/widgets/graphicsview/dragdroprobot/main.cpp b/examples/widgets/graphicsview/dragdroprobot/main.cpp
new file mode 100644
index 0000000000..05d3c8f1b3
--- /dev/null
+++ b/examples/widgets/graphicsview/dragdroprobot/main.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "coloritem.h"
+#include "robot.h"
+
+#include <math.h>
+
+class GraphicsView : public QGraphicsView
+{
+public:
+ GraphicsView(QGraphicsScene *scene) : QGraphicsView(scene)
+ {
+ }
+
+protected:
+ virtual void resizeEvent(QResizeEvent *)
+ {
+ }
+};
+
+//! [0]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+//! [0]
+//! [1]
+ QGraphicsScene scene(-200, -200, 400, 400);
+
+ for (int i = 0; i < 10; ++i) {
+ ColorItem *item = new ColorItem;
+ item->setPos(::sin((i * 6.28) / 10.0) * 150,
+ ::cos((i * 6.28) / 10.0) * 150);
+
+ scene.addItem(item);
+ }
+
+ Robot *robot = new Robot;
+ robot->setTransform(QTransform::fromScale(1.2, 1.2), true);
+ robot->setPos(0, -20);
+ scene.addItem(robot);
+//! [1]
+//! [2]
+ GraphicsView view(&scene);
+ view.setRenderHint(QPainter::Antialiasing);
+ view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
+ view.setBackgroundBrush(QColor(230, 200, 167));
+ view.setWindowTitle("Drag and Drop Robot");
+ view.show();
+
+ return app.exec();
+}
+//! [2]
diff --git a/examples/widgets/graphicsview/dragdroprobot/robot.cpp b/examples/widgets/graphicsview/dragdroprobot/robot.cpp
new file mode 100644
index 0000000000..20935bf6c5
--- /dev/null
+++ b/examples/widgets/graphicsview/dragdroprobot/robot.cpp
@@ -0,0 +1,307 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "robot.h"
+
+//! [0]
+RobotPart::RobotPart(QGraphicsItem *parent)
+ : QGraphicsObject(parent), color(Qt::lightGray), dragOver(false)
+{
+ setAcceptDrops(true);
+}
+//! [0]
+
+//! [1]
+void RobotPart::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
+{
+ if (event->mimeData()->hasColor()) {
+ event->setAccepted(true);
+ dragOver = true;
+ update();
+ } else {
+ event->setAccepted(false);
+ }
+}
+//! [1]
+
+//! [2]
+void RobotPart::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
+{
+ Q_UNUSED(event);
+ dragOver = false;
+ update();
+}
+//! [2]
+
+//! [3]
+void RobotPart::dropEvent(QGraphicsSceneDragDropEvent *event)
+{
+ dragOver = false;
+ if (event->mimeData()->hasColor())
+ color = qvariant_cast<QColor>(event->mimeData()->colorData());
+ update();
+}
+//! [3]
+
+//! [4]
+RobotHead::RobotHead(QGraphicsItem *parent)
+ : RobotPart(parent)
+{
+}
+//! [4]
+
+//! [5]
+QRectF RobotHead::boundingRect() const
+{
+ return QRectF(-15, -50, 30, 50);
+}
+//! [5]
+
+//! [6]
+void RobotHead::paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+ if (pixmap.isNull()) {
+ painter->setBrush(dragOver ? color.light(130) : color);
+ painter->drawRoundedRect(-10, -30, 20, 30, 25, 25, Qt::RelativeSize);
+ painter->setBrush(Qt::white);
+ painter->drawEllipse(-7, -3 - 20, 7, 7);
+ painter->drawEllipse(0, -3 - 20, 7, 7);
+ painter->setBrush(Qt::black);
+ painter->drawEllipse(-5, -1 - 20, 2, 2);
+ painter->drawEllipse(2, -1 - 20, 2, 2);
+ painter->setPen(QPen(Qt::black, 2));
+ painter->setBrush(Qt::NoBrush);
+ painter->drawArc(-6, -2 - 20, 12, 15, 190 * 16, 160 * 16);
+ } else {
+ painter->scale(.2272, .2824);
+ painter->drawPixmap(QPointF(-15 * 4.4, -50 * 3.54), pixmap);
+ }
+}
+//! [6]
+
+//! [7]
+void RobotHead::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
+{
+ if (event->mimeData()->hasImage()) {
+ event->setAccepted(true);
+ dragOver = true;
+ update();
+ } else {
+ RobotPart::dragEnterEvent(event);
+ }
+}
+//! [7]
+
+//! [8]
+void RobotHead::dropEvent(QGraphicsSceneDragDropEvent *event)
+{
+ if (event->mimeData()->hasImage()) {
+ dragOver = false;
+ pixmap = qvariant_cast<QPixmap>(event->mimeData()->imageData());
+ update();
+ } else {
+ RobotPart::dropEvent(event);
+ }
+}
+//! [8]
+
+RobotTorso::RobotTorso(QGraphicsItem *parent)
+ : RobotPart(parent)
+{
+}
+
+QRectF RobotTorso::boundingRect() const
+{
+ return QRectF(-30, -20, 60, 60);
+}
+
+void RobotTorso::paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+
+ painter->setBrush(dragOver ? color.light(130) : color);
+ painter->drawRoundedRect(-20, -20, 40, 60, 25, 25, Qt::RelativeSize);
+ painter->drawEllipse(-25, -20, 20, 20);
+ painter->drawEllipse(5, -20, 20, 20);
+ painter->drawEllipse(-20, 22, 20, 20);
+ painter->drawEllipse(0, 22, 20, 20);
+}
+
+RobotLimb::RobotLimb(QGraphicsItem *parent)
+ : RobotPart(parent)
+{
+}
+
+QRectF RobotLimb::boundingRect() const
+{
+ return QRectF(-5, -5, 40, 10);
+}
+
+void RobotLimb::paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+
+ painter->setBrush(dragOver ? color.light(130) : color);
+ painter->drawRoundedRect(boundingRect(), 50, 50, Qt::RelativeSize);
+ painter->drawEllipse(-5, -5, 10, 10);
+}
+
+//! [10]
+Robot::Robot(QGraphicsItem *parent)
+ : RobotPart(parent)
+{
+ setFlag(ItemHasNoContents);
+
+ QGraphicsObject *torsoItem = new RobotTorso(this);
+ QGraphicsObject *headItem = new RobotHead(torsoItem);
+ QGraphicsObject *upperLeftArmItem = new RobotLimb(torsoItem);
+ QGraphicsObject *lowerLeftArmItem = new RobotLimb(upperLeftArmItem);
+ QGraphicsObject *upperRightArmItem = new RobotLimb(torsoItem);
+ QGraphicsObject *lowerRightArmItem = new RobotLimb(upperRightArmItem);
+ QGraphicsObject *upperRightLegItem = new RobotLimb(torsoItem);
+ QGraphicsObject *lowerRightLegItem = new RobotLimb(upperRightLegItem);
+ QGraphicsObject *upperLeftLegItem = new RobotLimb(torsoItem);
+ QGraphicsObject *lowerLeftLegItem = new RobotLimb(upperLeftLegItem);
+//! [10]
+
+//! [11]
+ headItem->setPos(0, -18);
+ upperLeftArmItem->setPos(-15, -10);
+ lowerLeftArmItem->setPos(30, 0);
+ upperRightArmItem->setPos(15, -10);
+ lowerRightArmItem->setPos(30, 0);
+ upperRightLegItem->setPos(10, 32);
+ lowerRightLegItem->setPos(30, 0);
+ upperLeftLegItem->setPos(-10, 32);
+ lowerLeftLegItem->setPos(30, 0);
+//! [11]
+
+//! [12]
+ QParallelAnimationGroup *animation = new QParallelAnimationGroup(this);
+
+ QPropertyAnimation *headAnimation = new QPropertyAnimation(headItem, "rotation");
+ headAnimation->setStartValue(20);
+ headAnimation->setEndValue(-20);
+ QPropertyAnimation *headScaleAnimation = new QPropertyAnimation(headItem, "scale");
+ headScaleAnimation->setEndValue(1.1);
+ animation->addAnimation(headAnimation);
+ animation->addAnimation(headScaleAnimation);
+//! [12]
+
+ QPropertyAnimation *upperLeftArmAnimation = new QPropertyAnimation(upperLeftArmItem, "rotation");
+ upperLeftArmAnimation->setStartValue(190);
+ upperLeftArmAnimation->setEndValue(180);
+ animation->addAnimation(upperLeftArmAnimation);
+
+ QPropertyAnimation *lowerLeftArmAnimation = new QPropertyAnimation(lowerLeftArmItem, "rotation");
+ lowerLeftArmAnimation->setStartValue(50);
+ lowerLeftArmAnimation->setEndValue(10);
+ animation->addAnimation(lowerLeftArmAnimation);
+
+ QPropertyAnimation *upperRightArmAnimation = new QPropertyAnimation(upperRightArmItem, "rotation");
+ upperRightArmAnimation->setStartValue(300);
+ upperRightArmAnimation->setEndValue(310);
+ animation->addAnimation(upperRightArmAnimation);
+
+ QPropertyAnimation *lowerRightArmAnimation = new QPropertyAnimation(lowerRightArmItem, "rotation");
+ lowerRightArmAnimation->setStartValue(0);
+ lowerRightArmAnimation->setEndValue(-70);
+ animation->addAnimation(lowerRightArmAnimation);
+
+ QPropertyAnimation *upperLeftLegAnimation = new QPropertyAnimation(upperLeftLegItem, "rotation");
+ upperLeftLegAnimation->setStartValue(150);
+ upperLeftLegAnimation->setEndValue(80);
+ animation->addAnimation(upperLeftLegAnimation);
+
+ QPropertyAnimation *lowerLeftLegAnimation = new QPropertyAnimation(lowerLeftLegItem, "rotation");
+ lowerLeftLegAnimation->setStartValue(70);
+ lowerLeftLegAnimation->setEndValue(10);
+ animation->addAnimation(lowerLeftLegAnimation);
+
+ QPropertyAnimation *upperRightLegAnimation = new QPropertyAnimation(upperRightLegItem, "rotation");
+ upperRightLegAnimation->setStartValue(40);
+ upperRightLegAnimation->setEndValue(120);
+ animation->addAnimation(upperRightLegAnimation);
+
+ QPropertyAnimation *lowerRightLegAnimation = new QPropertyAnimation(lowerRightLegItem, "rotation");
+ lowerRightLegAnimation->setStartValue(10);
+ lowerRightLegAnimation->setEndValue(50);
+ animation->addAnimation(lowerRightLegAnimation);
+
+ QPropertyAnimation *torsoAnimation = new QPropertyAnimation(torsoItem, "rotation");
+ torsoAnimation->setStartValue(5);
+ torsoAnimation->setEndValue(-20);
+ animation->addAnimation(torsoAnimation);
+
+//! [13]
+ for (int i = 0; i < animation->animationCount(); ++i) {
+ QPropertyAnimation *anim = qobject_cast<QPropertyAnimation *>(animation->animationAt(i));
+ anim->setEasingCurve(QEasingCurve::SineCurve);
+ anim->setDuration(2000);
+ }
+
+ animation->setLoopCount(-1);
+ animation->start();
+//! [13]
+}
+
+//! [9]
+QRectF Robot::boundingRect() const
+{
+ return QRectF();
+}
+
+void Robot::paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(painter);
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+}
+//! [9]
diff --git a/examples/widgets/graphicsview/dragdroprobot/robot.h b/examples/widgets/graphicsview/dragdroprobot/robot.h
new file mode 100644
index 0000000000..ff9fb49485
--- /dev/null
+++ b/examples/widgets/graphicsview/dragdroprobot/robot.h
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ROBOT_H
+#define ROBOT_H
+
+#include <QGraphicsItem>
+
+QT_BEGIN_NAMESPACE
+class QGraphicsSceneMouseEvent;
+class QParallelAnimationGroup;
+QT_END_NAMESPACE
+
+//! [0]
+class RobotPart : public QGraphicsObject
+{
+public:
+ RobotPart(QGraphicsItem *parent = 0);
+
+protected:
+ void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
+ void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
+ void dropEvent(QGraphicsSceneDragDropEvent *event);
+
+ QColor color;
+ bool dragOver;
+};
+//! [0]
+
+//! [1]
+class RobotHead : public RobotPart
+{
+public:
+ RobotHead(QGraphicsItem *parent = 0);
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+protected:
+ void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
+ void dropEvent(QGraphicsSceneDragDropEvent *event);
+
+private:
+ QPixmap pixmap;
+};
+//! [1]
+
+//! [2]
+class RobotTorso : public RobotPart
+{
+public:
+ RobotTorso(QGraphicsItem *parent = 0);
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+};
+//! [2]
+
+//! [3]
+class RobotLimb : public RobotPart
+{
+public:
+ RobotLimb(QGraphicsItem *parent = 0);
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+};
+//! [3]
+
+//! [4]
+class Robot : public RobotPart
+{
+public:
+ Robot(QGraphicsItem *parent = 0);
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+};
+//! [4]
+
+#endif
diff --git a/examples/widgets/graphicsview/dragdroprobot/robot.qrc b/examples/widgets/graphicsview/dragdroprobot/robot.qrc
new file mode 100644
index 0000000000..b0969d2a64
--- /dev/null
+++ b/examples/widgets/graphicsview/dragdroprobot/robot.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>images/head.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/graphicsview/elasticnodes/edge.cpp b/examples/widgets/graphicsview/elasticnodes/edge.cpp
new file mode 100644
index 0000000000..ee7334cdcc
--- /dev/null
+++ b/examples/widgets/graphicsview/elasticnodes/edge.cpp
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QPainter>
+
+#include "edge.h"
+#include "node.h"
+
+#include <math.h>
+
+static const double Pi = 3.14159265358979323846264338327950288419717;
+static double TwoPi = 2.0 * Pi;
+
+//! [0]
+Edge::Edge(Node *sourceNode, Node *destNode)
+ : arrowSize(10)
+{
+ setAcceptedMouseButtons(0);
+ source = sourceNode;
+ dest = destNode;
+ source->addEdge(this);
+ dest->addEdge(this);
+ adjust();
+}
+//! [0]
+
+//! [1]
+Node *Edge::sourceNode() const
+{
+ return source;
+}
+
+Node *Edge::destNode() const
+{
+ return dest;
+}
+//! [1]
+
+//! [2]
+void Edge::adjust()
+{
+ if (!source || !dest)
+ return;
+
+ QLineF line(mapFromItem(source, 0, 0), mapFromItem(dest, 0, 0));
+ qreal length = line.length();
+
+ prepareGeometryChange();
+
+ if (length > qreal(20.)) {
+ QPointF edgeOffset((line.dx() * 10) / length, (line.dy() * 10) / length);
+ sourcePoint = line.p1() + edgeOffset;
+ destPoint = line.p2() - edgeOffset;
+ } else {
+ sourcePoint = destPoint = line.p1();
+ }
+}
+//! [2]
+
+//! [3]
+QRectF Edge::boundingRect() const
+{
+ if (!source || !dest)
+ return QRectF();
+
+ qreal penWidth = 1;
+ qreal extra = (penWidth + arrowSize) / 2.0;
+
+ return QRectF(sourcePoint, QSizeF(destPoint.x() - sourcePoint.x(),
+ destPoint.y() - sourcePoint.y()))
+ .normalized()
+ .adjusted(-extra, -extra, extra, extra);
+}
+//! [3]
+
+//! [4]
+void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ if (!source || !dest)
+ return;
+
+ QLineF line(sourcePoint, destPoint);
+ if (qFuzzyCompare(line.length(), qreal(0.)))
+ return;
+//! [4]
+
+//! [5]
+ // Draw the line itself
+ painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
+ painter->drawLine(line);
+//! [5]
+
+//! [6]
+ // Draw the arrows
+ double angle = ::acos(line.dx() / line.length());
+ if (line.dy() >= 0)
+ angle = TwoPi - angle;
+
+ QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + Pi / 3) * arrowSize,
+ cos(angle + Pi / 3) * arrowSize);
+ QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
+ cos(angle + Pi - Pi / 3) * arrowSize);
+ QPointF destArrowP1 = destPoint + QPointF(sin(angle - Pi / 3) * arrowSize,
+ cos(angle - Pi / 3) * arrowSize);
+ QPointF destArrowP2 = destPoint + QPointF(sin(angle - Pi + Pi / 3) * arrowSize,
+ cos(angle - Pi + Pi / 3) * arrowSize);
+
+ painter->setBrush(Qt::black);
+ painter->drawPolygon(QPolygonF() << line.p1() << sourceArrowP1 << sourceArrowP2);
+ painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2);
+}
+//! [6]
diff --git a/examples/widgets/graphicsview/elasticnodes/edge.h b/examples/widgets/graphicsview/elasticnodes/edge.h
new file mode 100644
index 0000000000..9bf4112212
--- /dev/null
+++ b/examples/widgets/graphicsview/elasticnodes/edge.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef EDGE_H
+#define EDGE_H
+
+#include <QGraphicsItem>
+
+class Node;
+
+//! [0]
+class Edge : public QGraphicsItem
+{
+public:
+ Edge(Node *sourceNode, Node *destNode);
+
+ Node *sourceNode() const;
+ Node *destNode() const;
+
+ void adjust();
+
+ enum { Type = UserType + 2 };
+ int type() const { return Type; }
+
+protected:
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+private:
+ Node *source, *dest;
+
+ QPointF sourcePoint;
+ QPointF destPoint;
+ qreal arrowSize;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/graphicsview/elasticnodes/elasticnodes.desktop b/examples/widgets/graphicsview/elasticnodes/elasticnodes.desktop
new file mode 100644
index 0000000000..64402d080f
--- /dev/null
+++ b/examples/widgets/graphicsview/elasticnodes/elasticnodes.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Elastic Nodes
+Exec=/opt/usr/bin/elasticnodes
+Icon=elasticnodes
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/elasticnodes/elasticnodes.pro b/examples/widgets/graphicsview/elasticnodes/elasticnodes.pro
new file mode 100644
index 0000000000..2a61809457
--- /dev/null
+++ b/examples/widgets/graphicsview/elasticnodes/elasticnodes.pro
@@ -0,0 +1,20 @@
+HEADERS += \
+ edge.h \
+ node.h \
+ graphwidget.h
+
+SOURCES += \
+ edge.cpp \
+ main.cpp \
+ node.cpp \
+ graphwidget.cpp
+
+TARGET.EPOCHEAPSIZE = 0x200000 0xA00000
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/elasticnodes
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS elasticnodes.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/elasticnodes
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
new file mode 100644
index 0000000000..36005b85f4
--- /dev/null
+++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
@@ -0,0 +1,250 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "graphwidget.h"
+#include "edge.h"
+#include "node.h"
+
+#include <QtWidgets>
+
+#include <math.h>
+
+//! [0]
+GraphWidget::GraphWidget(QWidget *parent)
+ : QGraphicsView(parent), timerId(0)
+{
+ QGraphicsScene *scene = new QGraphicsScene(this);
+ scene->setItemIndexMethod(QGraphicsScene::NoIndex);
+ scene->setSceneRect(-200, -200, 400, 400);
+ setScene(scene);
+ setCacheMode(CacheBackground);
+ setViewportUpdateMode(BoundingRectViewportUpdate);
+ setRenderHint(QPainter::Antialiasing);
+ setTransformationAnchor(AnchorUnderMouse);
+ scale(qreal(0.8), qreal(0.8));
+ setMinimumSize(400, 400);
+ setWindowTitle(tr("Elastic Nodes"));
+//! [0]
+
+//! [1]
+ Node *node1 = new Node(this);
+ Node *node2 = new Node(this);
+ Node *node3 = new Node(this);
+ Node *node4 = new Node(this);
+ centerNode = new Node(this);
+ Node *node6 = new Node(this);
+ Node *node7 = new Node(this);
+ Node *node8 = new Node(this);
+ Node *node9 = new Node(this);
+ scene->addItem(node1);
+ scene->addItem(node2);
+ scene->addItem(node3);
+ scene->addItem(node4);
+ scene->addItem(centerNode);
+ scene->addItem(node6);
+ scene->addItem(node7);
+ scene->addItem(node8);
+ scene->addItem(node9);
+ scene->addItem(new Edge(node1, node2));
+ scene->addItem(new Edge(node2, node3));
+ scene->addItem(new Edge(node2, centerNode));
+ scene->addItem(new Edge(node3, node6));
+ scene->addItem(new Edge(node4, node1));
+ scene->addItem(new Edge(node4, centerNode));
+ scene->addItem(new Edge(centerNode, node6));
+ scene->addItem(new Edge(centerNode, node8));
+ scene->addItem(new Edge(node6, node9));
+ scene->addItem(new Edge(node7, node4));
+ scene->addItem(new Edge(node8, node7));
+ scene->addItem(new Edge(node9, node8));
+
+ node1->setPos(-50, -50);
+ node2->setPos(0, -50);
+ node3->setPos(50, -50);
+ node4->setPos(-50, 0);
+ centerNode->setPos(0, 0);
+ node6->setPos(50, 0);
+ node7->setPos(-50, 50);
+ node8->setPos(0, 50);
+ node9->setPos(50, 50);
+}
+//! [1]
+
+//! [2]
+void GraphWidget::itemMoved()
+{
+ if (!timerId)
+ timerId = startTimer(1000 / 25);
+}
+//! [2]
+
+//! [3]
+void GraphWidget::keyPressEvent(QKeyEvent *event)
+{
+ switch (event->key()) {
+ case Qt::Key_Up:
+ centerNode->moveBy(0, -20);
+ break;
+ case Qt::Key_Down:
+ centerNode->moveBy(0, 20);
+ break;
+ case Qt::Key_Left:
+ centerNode->moveBy(-20, 0);
+ break;
+ case Qt::Key_Right:
+ centerNode->moveBy(20, 0);
+ break;
+ case Qt::Key_Plus:
+ zoomIn();
+ break;
+ case Qt::Key_Minus:
+ zoomOut();
+ break;
+ case Qt::Key_Space:
+ case Qt::Key_Enter:
+ shuffle();
+ break;
+ default:
+ QGraphicsView::keyPressEvent(event);
+ }
+}
+//! [3]
+
+//! [4]
+void GraphWidget::timerEvent(QTimerEvent *event)
+{
+ Q_UNUSED(event);
+
+ QList<Node *> nodes;
+ foreach (QGraphicsItem *item, scene()->items()) {
+ if (Node *node = qgraphicsitem_cast<Node *>(item))
+ nodes << node;
+ }
+
+ foreach (Node *node, nodes)
+ node->calculateForces();
+
+ bool itemsMoved = false;
+ foreach (Node *node, nodes) {
+ if (node->advance())
+ itemsMoved = true;
+ }
+
+ if (!itemsMoved) {
+ killTimer(timerId);
+ timerId = 0;
+ }
+}
+//! [4]
+
+//! [5]
+void GraphWidget::wheelEvent(QWheelEvent *event)
+{
+ scaleView(pow((double)2, -event->delta() / 240.0));
+}
+//! [5]
+
+//! [6]
+void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
+{
+ Q_UNUSED(rect);
+
+ // Shadow
+ QRectF sceneRect = this->sceneRect();
+ QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
+ QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
+ if (rightShadow.intersects(rect) || rightShadow.contains(rect))
+ painter->fillRect(rightShadow, Qt::darkGray);
+ if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
+ painter->fillRect(bottomShadow, Qt::darkGray);
+
+ // Fill
+ QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
+ gradient.setColorAt(0, Qt::white);
+ gradient.setColorAt(1, Qt::lightGray);
+ painter->fillRect(rect.intersected(sceneRect), gradient);
+ painter->setBrush(Qt::NoBrush);
+ painter->drawRect(sceneRect);
+
+ // Text
+ QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4,
+ sceneRect.width() - 4, sceneRect.height() - 4);
+ QString message(tr("Click and drag the nodes around, and zoom with the mouse "
+ "wheel or the '+' and '-' keys"));
+
+ QFont font = painter->font();
+ font.setBold(true);
+ font.setPointSize(14);
+ painter->setFont(font);
+ painter->setPen(Qt::lightGray);
+ painter->drawText(textRect.translated(2, 2), message);
+ painter->setPen(Qt::black);
+ painter->drawText(textRect, message);
+}
+//! [6]
+
+//! [7]
+void GraphWidget::scaleView(qreal scaleFactor)
+{
+ qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
+ if (factor < 0.07 || factor > 100)
+ return;
+
+ scale(scaleFactor, scaleFactor);
+}
+//! [7]
+
+void GraphWidget::shuffle()
+{
+ foreach (QGraphicsItem *item, scene()->items()) {
+ if (qgraphicsitem_cast<Node *>(item))
+ item->setPos(-150 + qrand() % 300, -150 + qrand() % 300);
+ }
+}
+
+void GraphWidget::zoomIn()
+{
+ scaleView(qreal(1.2));
+}
+
+void GraphWidget::zoomOut()
+{
+ scaleView(1 / qreal(1.2));
+}
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.h b/examples/widgets/graphicsview/elasticnodes/graphwidget.h
new file mode 100644
index 0000000000..61bcfdb5cb
--- /dev/null
+++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GRAPHWIDGET_H
+#define GRAPHWIDGET_H
+
+#include <QtWidgets/QGraphicsView>
+
+class Node;
+
+//! [0]
+class GraphWidget : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ GraphWidget(QWidget *parent = 0);
+
+ void itemMoved();
+
+public slots:
+ void shuffle();
+ void zoomIn();
+ void zoomOut();
+
+protected:
+ void keyPressEvent(QKeyEvent *event);
+ void timerEvent(QTimerEvent *event);
+ void wheelEvent(QWheelEvent *event);
+ void drawBackground(QPainter *painter, const QRectF &rect);
+
+ void scaleView(qreal scaleFactor);
+
+private:
+ int timerId;
+ Node *centerNode;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/graphicsview/elasticnodes/main.cpp b/examples/widgets/graphicsview/elasticnodes/main.cpp
new file mode 100644
index 0000000000..239b8290ea
--- /dev/null
+++ b/examples/widgets/graphicsview/elasticnodes/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "graphwidget.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ GraphWidget *widget = new GraphWidget;
+
+ QMainWindow mainWindow;
+ mainWindow.setCentralWidget(widget);
+
+ mainWindow.show();
+ return app.exec();
+}
diff --git a/examples/widgets/graphicsview/elasticnodes/node.cpp b/examples/widgets/graphicsview/elasticnodes/node.cpp
new file mode 100644
index 0000000000..dad226a5e6
--- /dev/null
+++ b/examples/widgets/graphicsview/elasticnodes/node.cpp
@@ -0,0 +1,212 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGraphicsScene>
+#include <QGraphicsSceneMouseEvent>
+#include <QPainter>
+#include <QStyleOption>
+
+#include "edge.h"
+#include "node.h"
+#include "graphwidget.h"
+
+//! [0]
+Node::Node(GraphWidget *graphWidget)
+ : graph(graphWidget)
+{
+ setFlag(ItemIsMovable);
+ setFlag(ItemSendsGeometryChanges);
+ setCacheMode(DeviceCoordinateCache);
+ setZValue(-1);
+}
+//! [0]
+
+//! [1]
+void Node::addEdge(Edge *edge)
+{
+ edgeList << edge;
+ edge->adjust();
+}
+
+QList<Edge *> Node::edges() const
+{
+ return edgeList;
+}
+//! [1]
+
+//! [2]
+void Node::calculateForces()
+{
+ if (!scene() || scene()->mouseGrabberItem() == this) {
+ newPos = pos();
+ return;
+ }
+//! [2]
+
+//! [3]
+ // Sum up all forces pushing this item away
+ qreal xvel = 0;
+ qreal yvel = 0;
+ foreach (QGraphicsItem *item, scene()->items()) {
+ Node *node = qgraphicsitem_cast<Node *>(item);
+ if (!node)
+ continue;
+
+ QPointF vec = mapToItem(node, 0, 0);
+ qreal dx = vec.x();
+ qreal dy = vec.y();
+ double l = 2.0 * (dx * dx + dy * dy);
+ if (l > 0) {
+ xvel += (dx * 150.0) / l;
+ yvel += (dy * 150.0) / l;
+ }
+ }
+//! [3]
+
+//! [4]
+ // Now subtract all forces pulling items together
+ double weight = (edgeList.size() + 1) * 10;
+ foreach (Edge *edge, edgeList) {
+ QPointF vec;
+ if (edge->sourceNode() == this)
+ vec = mapToItem(edge->destNode(), 0, 0);
+ else
+ vec = mapToItem(edge->sourceNode(), 0, 0);
+ xvel -= vec.x() / weight;
+ yvel -= vec.y() / weight;
+ }
+//! [4]
+
+//! [5]
+ if (qAbs(xvel) < 0.1 && qAbs(yvel) < 0.1)
+ xvel = yvel = 0;
+//! [5]
+
+//! [6]
+ QRectF sceneRect = scene()->sceneRect();
+ newPos = pos() + QPointF(xvel, yvel);
+ newPos.setX(qMin(qMax(newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10));
+ newPos.setY(qMin(qMax(newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10));
+}
+//! [6]
+
+//! [7]
+bool Node::advance()
+{
+ if (newPos == pos())
+ return false;
+
+ setPos(newPos);
+ return true;
+}
+//! [7]
+
+//! [8]
+QRectF Node::boundingRect() const
+{
+ qreal adjust = 2;
+ return QRectF( -10 - adjust, -10 - adjust,
+ 23 + adjust, 23 + adjust);
+}
+//! [8]
+
+//! [9]
+QPainterPath Node::shape() const
+{
+ QPainterPath path;
+ path.addEllipse(-10, -10, 20, 20);
+ return path;
+}
+//! [9]
+
+//! [10]
+void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
+{
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(Qt::darkGray);
+ painter->drawEllipse(-7, -7, 20, 20);
+
+ QRadialGradient gradient(-3, -3, 10);
+ if (option->state & QStyle::State_Sunken) {
+ gradient.setCenter(3, 3);
+ gradient.setFocalPoint(3, 3);
+ gradient.setColorAt(1, QColor(Qt::yellow).light(120));
+ gradient.setColorAt(0, QColor(Qt::darkYellow).light(120));
+ } else {
+ gradient.setColorAt(0, Qt::yellow);
+ gradient.setColorAt(1, Qt::darkYellow);
+ }
+ painter->setBrush(gradient);
+
+ painter->setPen(QPen(Qt::black, 0));
+ painter->drawEllipse(-10, -10, 20, 20);
+}
+//! [10]
+
+//! [11]
+QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
+{
+ switch (change) {
+ case ItemPositionHasChanged:
+ foreach (Edge *edge, edgeList)
+ edge->adjust();
+ graph->itemMoved();
+ break;
+ default:
+ break;
+ };
+
+ return QGraphicsItem::itemChange(change, value);
+}
+//! [11]
+
+//! [12]
+void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ update();
+ QGraphicsItem::mousePressEvent(event);
+}
+
+void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ update();
+ QGraphicsItem::mouseReleaseEvent(event);
+}
+//! [12]
diff --git a/examples/widgets/graphicsview/elasticnodes/node.h b/examples/widgets/graphicsview/elasticnodes/node.h
new file mode 100644
index 0000000000..86ca407e08
--- /dev/null
+++ b/examples/widgets/graphicsview/elasticnodes/node.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef NODE_H
+#define NODE_H
+
+#include <QGraphicsItem>
+#include <QList>
+
+class Edge;
+class GraphWidget;
+QT_BEGIN_NAMESPACE
+class QGraphicsSceneMouseEvent;
+QT_END_NAMESPACE
+
+//! [0]
+class Node : public QGraphicsItem
+{
+public:
+ Node(GraphWidget *graphWidget);
+
+ void addEdge(Edge *edge);
+ QList<Edge *> edges() const;
+
+ enum { Type = UserType + 1 };
+ int type() const { return Type; }
+
+ void calculateForces();
+ bool advance();
+
+ QRectF boundingRect() const;
+ QPainterPath shape() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+protected:
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+
+ void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+
+private:
+ QList<Edge *> edgeList;
+ QPointF newPos;
+ GraphWidget *graph;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg b/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg
new file mode 100644
index 0000000000..445567fbda
--- /dev/null
+++ b/examples/widgets/graphicsview/embeddeddialogs/No-Ones-Laughing-3.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
new file mode 100644
index 0000000000..2aa2986014
--- /dev/null
+++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "customproxy.h"
+
+#include <QtWidgets>
+
+CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
+ : QGraphicsProxyWidget(parent, wFlags), popupShown(false), currentPopup(0)
+{
+ timeLine = new QTimeLine(250, this);
+ connect(timeLine, SIGNAL(valueChanged(qreal)),
+ this, SLOT(updateStep(qreal)));
+ connect(timeLine, SIGNAL(stateChanged(QTimeLine::State)),
+ this, SLOT(stateChanged(QTimeLine::State)));
+}
+
+QRectF CustomProxy::boundingRect() const
+{
+ return QGraphicsProxyWidget::boundingRect().adjusted(0, 0, 10, 10);
+}
+
+void CustomProxy::paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+{
+ const QColor color(0, 0, 0, 64);
+
+ QRectF r = windowFrameRect();
+ QRectF right(r.right(), r.top() + 10, 10, r.height() - 10);
+ QRectF bottom(r.left() + 10, r.bottom(), r.width(), 10);
+ bool intersectsRight = right.intersects(option->exposedRect);
+ bool intersectsBottom = bottom.intersects(option->exposedRect);
+ if (intersectsRight && intersectsBottom) {
+ QPainterPath path;
+ path.addRect(right);
+ path.addRect(bottom);
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(color);
+ painter->drawPath(path);
+ } else if (intersectsBottom) {
+ painter->fillRect(bottom, color);
+ } else if (intersectsRight) {
+ painter->fillRect(right, color);
+ }
+
+ QGraphicsProxyWidget::paintWindowFrame(painter, option, widget);
+}
+
+void CustomProxy::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
+{
+ QGraphicsProxyWidget::hoverEnterEvent(event);
+ scene()->setActiveWindow(this);
+ if (timeLine->currentValue() != 1)
+ zoomIn();
+}
+
+void CustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
+{
+ QGraphicsProxyWidget::hoverLeaveEvent(event);
+ if (!popupShown && (timeLine->direction() != QTimeLine::Backward || timeLine->currentValue() != 0))
+ zoomOut();
+}
+
+bool CustomProxy::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+{
+ if (watched->isWindow() && (event->type() == QEvent::UngrabMouse || event->type() == QEvent::GrabMouse)) {
+ popupShown = watched->isVisible();
+ if (!popupShown && !isUnderMouse())
+ zoomOut();
+ }
+ return QGraphicsProxyWidget::sceneEventFilter(watched, event);
+}
+
+QVariant CustomProxy::itemChange(GraphicsItemChange change, const QVariant &value)
+{
+ if (change == ItemChildAddedChange || change == ItemChildRemovedChange) {
+ if (change == ItemChildAddedChange) {
+ currentPopup = qvariant_cast<QGraphicsItem *>(value);
+ currentPopup->setCacheMode(ItemCoordinateCache);
+ if (scene())
+ currentPopup->installSceneEventFilter(this);
+ } else if (scene()) {
+ currentPopup->removeSceneEventFilter(this);
+ currentPopup = 0;
+ }
+ } else if (currentPopup && change == ItemSceneHasChanged) {
+ currentPopup->installSceneEventFilter(this);
+ }
+ return QGraphicsProxyWidget::itemChange(change, value);
+}
+
+void CustomProxy::updateStep(qreal step)
+{
+ QRectF r = boundingRect();
+ setTransform(QTransform()
+ .translate(r.width() / 2, r.height() / 2)
+ .rotate(step * 30, Qt::XAxis)
+ .rotate(step * 10, Qt::YAxis)
+ .rotate(step * 5, Qt::ZAxis)
+ .scale(1 + 1.5 * step, 1 + 1.5 * step)
+ .translate(-r.width() / 2, -r.height() / 2));
+}
+
+void CustomProxy::stateChanged(QTimeLine::State state)
+{
+ if (state == QTimeLine::Running) {
+ if (timeLine->direction() == QTimeLine::Forward)
+ setCacheMode(ItemCoordinateCache);
+ } else if (state == QTimeLine::NotRunning) {
+ if (timeLine->direction() == QTimeLine::Backward)
+ setCacheMode(DeviceCoordinateCache);
+ }
+}
+
+void CustomProxy::zoomIn()
+{
+ if (timeLine->direction() != QTimeLine::Forward)
+ timeLine->setDirection(QTimeLine::Forward);
+ if (timeLine->state() == QTimeLine::NotRunning)
+ timeLine->start();
+}
+
+void CustomProxy::zoomOut()
+{
+ if (timeLine->direction() != QTimeLine::Backward)
+ timeLine->setDirection(QTimeLine::Backward);
+ if (timeLine->state() == QTimeLine::NotRunning)
+ timeLine->start();
+}
diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
new file mode 100644
index 0000000000..c85bbaccd3
--- /dev/null
+++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CUSTOMPROXY_H
+#define CUSTOMPROXY_H
+
+#include <QtCore/qtimeline.h>
+#include <QtWidgets/qgraphicsproxywidget.h>
+
+class CustomProxy : public QGraphicsProxyWidget
+{
+ Q_OBJECT
+public:
+ CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
+
+ QRectF boundingRect() const;
+ void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget);
+
+protected:
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+
+private slots:
+ void updateStep(qreal step);
+ void stateChanged(QTimeLine::State);
+ void zoomIn();
+ void zoomOut();
+
+private:
+ QTimeLine *timeLine;
+ bool popupShown;
+ QGraphicsItem *currentPopup;
+};
+
+#endif
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp
new file mode 100644
index 0000000000..e306f32c71
--- /dev/null
+++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "embeddeddialog.h"
+#include "ui_embeddeddialog.h"
+
+#include <QtWidgets>
+
+EmbeddedDialog::EmbeddedDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ ui = new Ui_embeddedDialog;
+ ui->setupUi(this);
+ ui->layoutDirection->setCurrentIndex(layoutDirection() != Qt::LeftToRight);
+
+ foreach (QString styleName, QStyleFactory::keys()) {
+ ui->style->addItem(styleName);
+ if (style()->objectName().toLower() == styleName.toLower())
+ ui->style->setCurrentIndex(ui->style->count() - 1);
+ }
+
+ connect(ui->layoutDirection, SIGNAL(activated(int)),
+ this, SLOT(layoutDirectionChanged(int)));
+ connect(ui->spacing, SIGNAL(valueChanged(int)),
+ this, SLOT(spacingChanged(int)));
+ connect(ui->fontComboBox, SIGNAL(currentFontChanged(QFont)),
+ this, SLOT(fontChanged(QFont)));
+ connect(ui->style, SIGNAL(activated(QString)),
+ this, SLOT(styleChanged(QString)));
+}
+
+EmbeddedDialog::~EmbeddedDialog()
+{
+ delete ui;
+}
+
+void EmbeddedDialog::layoutDirectionChanged(int index)
+{
+ setLayoutDirection(index == 0 ? Qt::LeftToRight : Qt::RightToLeft);
+}
+
+void EmbeddedDialog::spacingChanged(int spacing)
+{
+ layout()->setSpacing(spacing);
+ adjustSize();
+}
+
+void EmbeddedDialog::fontChanged(const QFont &font)
+{
+ setFont(font);
+}
+
+static void setStyleHelper(QWidget *widget, QStyle *style)
+{
+ widget->setStyle(style);
+ widget->setPalette(style->standardPalette());
+ foreach (QObject *child, widget->children()) {
+ if (QWidget *childWidget = qobject_cast<QWidget *>(child))
+ setStyleHelper(childWidget, style);
+ }
+}
+
+void EmbeddedDialog::styleChanged(const QString &styleName)
+{
+ QStyle *style = QStyleFactory::create(styleName);
+ if (style)
+ setStyleHelper(this, style);
+}
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
new file mode 100644
index 0000000000..59aa4c244a
--- /dev/null
+++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef EMBEDDEDDIALOG_H
+#define EMBEDDEDDIALOG_H
+
+#include <QtWidgets/qdialog.h>
+
+QT_FORWARD_DECLARE_CLASS(Ui_embeddedDialog);
+
+class EmbeddedDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ EmbeddedDialog(QWidget *parent = 0);
+ ~EmbeddedDialog();
+
+private slots:
+ void layoutDirectionChanged(int index);
+ void spacingChanged(int spacing);
+ void fontChanged(const QFont &font);
+ void styleChanged(const QString &styleName);
+
+private:
+ Ui_embeddedDialog *ui;
+};
+
+#endif
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui
new file mode 100644
index 0000000000..f967b10085
--- /dev/null
+++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.ui
@@ -0,0 +1,87 @@
+<ui version="4.0" >
+ <class>embeddedDialog</class>
+ <widget class="QDialog" name="embeddedDialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>407</width>
+ <height>134</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Embedded Dialog</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Layout Direction:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>layoutDirection</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QComboBox" name="layoutDirection" >
+ <item>
+ <property name="text" >
+ <string>Left to Right</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Right to Left</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Select Font:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>fontComboBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QFontComboBox" name="fontComboBox" />
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>Style:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>style</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QComboBox" name="style" />
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="label_4" >
+ <property name="text" >
+ <string>Layout spacing:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>spacing</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <widget class="QSlider" name="spacing" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro
new file mode 100644
index 0000000000..6244df4b68
--- /dev/null
+++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.pro
@@ -0,0 +1,19 @@
+SOURCES += main.cpp
+SOURCES += customproxy.cpp embeddeddialog.cpp
+HEADERS += customproxy.h embeddeddialog.h
+
+FORMS += embeddeddialog.ui
+RESOURCES += embeddeddialogs.qrc
+
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/embeddeddialogs
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.png *.jpg *.plist *.icns *.ico *.rc *.pro *.html *.doc images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/embeddeddialogs
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc
new file mode 100644
index 0000000000..33be5038da
--- /dev/null
+++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialogs.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource>
+ <file>No-Ones-Laughing-3.jpg</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/graphicsview/embeddeddialogs/main.cpp b/examples/widgets/graphicsview/embeddeddialogs/main.cpp
new file mode 100644
index 0000000000..88b249e481
--- /dev/null
+++ b/examples/widgets/graphicsview/embeddeddialogs/main.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "customproxy.h"
+#include "embeddeddialog.h"
+
+#include <QtWidgets>
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(embeddeddialogs);
+ QApplication app(argc, argv);
+
+ QGraphicsScene scene;
+ scene.setStickyFocus(true);
+#ifndef Q_OS_WINCE
+ const int gridSize = 10;
+#else
+ const int gridSize = 5;
+#endif
+
+ for (int y = 0; y < gridSize; ++y) {
+ for (int x = 0; x < gridSize; ++x) {
+ CustomProxy *proxy = new CustomProxy(0, Qt::Window);
+ proxy->setWidget(new EmbeddedDialog);
+
+ QRectF rect = proxy->boundingRect();
+
+ proxy->setPos(x * rect.width() * 1.05, y * rect.height() * 1.05);
+ proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
+
+ scene.addItem(proxy);
+ }
+ }
+ scene.setSceneRect(scene.itemsBoundingRect());
+
+ QGraphicsView view(&scene);
+ view.scale(0.5, 0.5);
+ view.setRenderHints(view.renderHints() | QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
+ view.setBackgroundBrush(QPixmap(":/No-Ones-Laughing-3.jpg"));
+ view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
+ view.show();
+ view.setWindowTitle("Embedded Dialogs Example");
+ return app.exec();
+}
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp b/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
new file mode 100644
index 0000000000..3f787109eb
--- /dev/null
+++ b/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
@@ -0,0 +1,213 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "flowlayout.h"
+#include <QtWidgets/qwidget.h>
+#include <QtCore/qmath.h>
+
+FlowLayout::FlowLayout()
+{
+ m_spacing[0] = 6;
+ m_spacing[1] = 6;
+ QSizePolicy sp = sizePolicy();
+ sp.setHeightForWidth(true);
+ setSizePolicy(sp);
+}
+
+void FlowLayout::insertItem(int index, QGraphicsLayoutItem *item)
+{
+ item->setParentLayoutItem(this);
+ if (uint(index) > uint(m_items.count()))
+ index = m_items.count();
+ m_items.insert(index, item);
+ invalidate();
+}
+
+int FlowLayout::count() const
+{
+ return m_items.count();
+}
+
+QGraphicsLayoutItem *FlowLayout::itemAt(int index) const
+{
+ return m_items.value(index);
+}
+
+void FlowLayout::removeAt(int index)
+{
+ m_items.removeAt(index);
+ invalidate();
+}
+
+qreal FlowLayout::spacing(Qt::Orientation o) const
+{
+ return m_spacing[int(o) - 1];
+}
+
+void FlowLayout::setSpacing(Qt::Orientations o, qreal spacing)
+{
+ if (o & Qt::Horizontal)
+ m_spacing[0] = spacing;
+ if (o & Qt::Vertical)
+ m_spacing[1] = spacing;
+}
+
+void FlowLayout::setGeometry(const QRectF &geom)
+{
+ QGraphicsLayout::setGeometry(geom);
+ doLayout(geom, true);
+}
+
+qreal FlowLayout::doLayout(const QRectF &geom, bool applyNewGeometry) const
+{
+ qreal left, top, right, bottom;
+ getContentsMargins(&left, &top, &right, &bottom);
+ const qreal maxw = geom.width() - left - right;
+
+ qreal x = 0;
+ qreal y = 0;
+ qreal maxRowHeight = 0;
+ QSizeF pref;
+ for (int i = 0; i < m_items.count(); ++i) {
+ QGraphicsLayoutItem *item = m_items.at(i);
+ pref = item->effectiveSizeHint(Qt::PreferredSize);
+ maxRowHeight = qMax(maxRowHeight, pref.height());
+
+ qreal next_x;
+ next_x = x + pref.width();
+ if (next_x > maxw) {
+ if (x == 0) {
+ pref.setWidth(maxw);
+ } else {
+ x = 0;
+ next_x = pref.width();
+ }
+ y += maxRowHeight + spacing(Qt::Vertical);
+ maxRowHeight = 0;
+ }
+
+ if (applyNewGeometry)
+ item->setGeometry(QRectF(QPointF(left + x, top + y), pref));
+ x = next_x + spacing(Qt::Horizontal);
+ }
+ maxRowHeight = qMax(maxRowHeight, pref.height());
+ return top + y + maxRowHeight + bottom;
+}
+
+QSizeF FlowLayout::minSize(const QSizeF &constraint) const
+{
+ QSizeF size(0, 0);
+ qreal left, top, right, bottom;
+ getContentsMargins(&left, &top, &right, &bottom);
+ if (constraint.width() >= 0) { // height for width
+ const qreal height = doLayout(QRectF(QPointF(0,0), constraint), false);
+ size = QSizeF(constraint.width(), height);
+ } else if (constraint.height() >= 0) { // width for height?
+ // not supported
+ } else {
+ QGraphicsLayoutItem *item;
+ foreach (item, m_items)
+ size = size.expandedTo(item->effectiveSizeHint(Qt::MinimumSize));
+ size += QSize(left + right, top + bottom);
+ }
+ return size;
+}
+
+QSizeF FlowLayout::prefSize() const
+{
+ qreal left, right;
+ getContentsMargins(&left, 0, &right, 0);
+
+ QGraphicsLayoutItem *item;
+ qreal maxh = 0;
+ qreal totalWidth = 0;
+ foreach (item, m_items) {
+ if (totalWidth > 0)
+ totalWidth += spacing(Qt::Horizontal);
+ QSizeF pref = item->effectiveSizeHint(Qt::PreferredSize);
+ totalWidth += pref.width();
+ maxh = qMax(maxh, pref.height());
+ }
+ maxh += spacing(Qt::Vertical);
+
+ const qreal goldenAspectRatio = 1.61803399;
+ qreal w = qSqrt(totalWidth * maxh * goldenAspectRatio) + left + right;
+
+ return minSize(QSizeF(w, -1));
+}
+
+QSizeF FlowLayout::maxSize() const
+{
+ QGraphicsLayoutItem *item;
+ qreal totalWidth = 0;
+ qreal totalHeight = 0;
+ foreach (item, m_items) {
+ if (totalWidth > 0)
+ totalWidth += spacing(Qt::Horizontal);
+ if (totalHeight > 0)
+ totalHeight += spacing(Qt::Vertical);
+ QSizeF pref = item->effectiveSizeHint(Qt::PreferredSize);
+ totalWidth += pref.width();
+ totalHeight += pref.height();
+ }
+
+ qreal left, top, right, bottom;
+ getContentsMargins(&left, &top, &right, &bottom);
+ return QSizeF(left + totalWidth + right, top + totalHeight + bottom);
+}
+
+QSizeF FlowLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
+{
+ QSizeF sh = constraint;
+ switch (which) {
+ case Qt::PreferredSize:
+ sh = prefSize();
+ break;
+ case Qt::MinimumSize:
+ sh = minSize(constraint);
+ break;
+ case Qt::MaximumSize:
+ sh = maxSize();
+ break;
+ default:
+ break;
+ }
+ return sh;
+}
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.desktop b/examples/widgets/graphicsview/flowlayout/flowlayout.desktop
new file mode 100644
index 0000000000..54ea3b0290
--- /dev/null
+++ b/examples/widgets/graphicsview/flowlayout/flowlayout.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Flow Layout
+Exec=/opt/usr/bin/flowlayout
+Icon=flowlayout
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.h b/examples/widgets/graphicsview/flowlayout/flowlayout.h
new file mode 100644
index 0000000000..751e435ec0
--- /dev/null
+++ b/examples/widgets/graphicsview/flowlayout/flowlayout.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets/qgraphicslayout.h>
+
+class FlowLayout : public QGraphicsLayout
+{
+public:
+ FlowLayout();
+ inline void addItem(QGraphicsLayoutItem *item);
+ void insertItem(int index, QGraphicsLayoutItem *item);
+ void setSpacing(Qt::Orientations o, qreal spacing);
+ qreal spacing(Qt::Orientation o) const;
+
+ // inherited functions
+ void setGeometry(const QRectF &geom);
+
+ int count() const;
+ QGraphicsLayoutItem *itemAt(int index) const;
+ void removeAt(int index);
+
+protected:
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
+
+private:
+ qreal doLayout(const QRectF &geom, bool applyNewGeometry) const;
+ QSizeF minSize(const QSizeF &constraint) const;
+ QSizeF prefSize() const;
+ QSizeF maxSize() const;
+
+ QList<QGraphicsLayoutItem*> m_items;
+ qreal m_spacing[2];
+};
+
+
+inline void FlowLayout::addItem(QGraphicsLayoutItem *item)
+{
+ insertItem(-1, item);
+}
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.pro b/examples/widgets/graphicsview/flowlayout/flowlayout.pro
new file mode 100644
index 0000000000..5f69a74d60
--- /dev/null
+++ b/examples/widgets/graphicsview/flowlayout/flowlayout.pro
@@ -0,0 +1,14 @@
+QT += widgets
+
+QMAKE_PROJECT_NAME = flowlayout_graphicsview
+
+HEADERS += flowlayout.h window.h
+SOURCES += flowlayout.cpp main.cpp window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/flowlayout
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/flowlayout
+INSTALLS += target sources
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/graphicsview/flowlayout/main.cpp b/examples/widgets/graphicsview/flowlayout/main.cpp
new file mode 100644
index 0000000000..a7a1155224
--- /dev/null
+++ b/examples/widgets/graphicsview/flowlayout/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include "window.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ QGraphicsScene scene;
+ QGraphicsView *view = new QGraphicsView(&scene);
+ Window *w = new Window;
+ scene.addItem(w);
+
+ view->resize(400, 300);
+ view->show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/graphicsview/flowlayout/window.cpp b/examples/widgets/graphicsview/flowlayout/window.cpp
new file mode 100644
index 0000000000..193a2bbc6e
--- /dev/null
+++ b/examples/widgets/graphicsview/flowlayout/window.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets/qgraphicsproxywidget.h>
+#include <QtWidgets/qlabel.h>
+#include "flowlayout.h"
+#include "window.h"
+
+Window::Window()
+: QGraphicsWidget(0, Qt::Window)
+{
+ FlowLayout *lay = new FlowLayout;
+ QLatin1String wiseWords("I am not bothered by the fact that I am unknown."
+ " I am bothered when I do not know others. (Confucius)");
+ QString sentence(wiseWords);
+ QStringList words = sentence.split(QLatin1Char(' '), QString::SkipEmptyParts);
+ for (int i = 0; i < words.count(); ++i) {
+ QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
+ QLabel *label = new QLabel(words.at(i));
+ label->setFrameStyle(QFrame::Box | QFrame::Plain);
+ proxy->setWidget(label);
+ lay->addItem(proxy);
+ }
+ setLayout(lay);
+}
diff --git a/examples/widgets/graphicsview/flowlayout/window.h b/examples/widgets/graphicsview/flowlayout/window.h
new file mode 100644
index 0000000000..b1eb874c21
--- /dev/null
+++ b/examples/widgets/graphicsview/flowlayout/window.h
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets/qgraphicswidget.h>
+
+class Window : public QGraphicsWidget {
+ Q_OBJECT
+public:
+ Window();
+};
diff --git a/examples/widgets/graphicsview/graphicsview.pro b/examples/widgets/graphicsview/graphicsview.pro
new file mode 100644
index 0000000000..6b7de527c6
--- /dev/null
+++ b/examples/widgets/graphicsview/graphicsview.pro
@@ -0,0 +1,28 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ chip \
+ elasticnodes \
+ embeddeddialogs \
+ collidingmice \
+ padnavigator \
+ basicgraphicslayouts \
+ diagramscene \
+ dragdroprobot \
+ flowlayout \
+ anchorlayout \
+ simpleanchorlayout \
+ weatheranchorlayout
+
+contains(DEFINES, QT_NO_CURSOR)|contains(DEFINES, QT_NO_DRAGANDDROP): SUBDIRS -= dragdroprobot
+
+contains(QT_CONFIG, opengl):!contains(QT_CONFIG, opengles1):!contains(QT_CONFIG, opengles2):{
+ SUBDIRS += boxes
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS graphicsview.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/graphicsview/padnavigator/flippablepad.cpp b/examples/widgets/graphicsview/padnavigator/flippablepad.cpp
new file mode 100644
index 0000000000..a6c44af70c
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/flippablepad.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "flippablepad.h"
+
+#include <QtWidgets/QtWidgets>
+
+//! [0]
+static QRectF boundsFromSize(const QSize &size)
+{
+ return QRectF((-size.width() / 2.0) * 150, (-size.height() / 2.0) * 150,
+ size.width() * 150, size.height() * 150);
+}
+//! [0]
+
+//! [1]
+static QPointF posForLocation(int column, int row, const QSize &size)
+{
+ return QPointF(column * 150, row * 150)
+ - QPointF((size.width() - 1) * 75, (size.height() - 1) * 75);
+}
+//! [1]
+
+//! [2]
+FlippablePad::FlippablePad(const QSize &size, QGraphicsItem *parent)
+ : RoundRectItem(boundsFromSize(size), QColor(226, 255, 92, 64), parent)
+{
+//! [2]
+//! [3]
+ int numIcons = size.width() * size.height();
+ QList<QPixmap> pixmaps;
+ QDirIterator it(":/images", QStringList() << "*.png");
+ while (it.hasNext() && pixmaps.size() < numIcons)
+ pixmaps << it.next();
+//! [3]
+
+//! [4]
+ const QRectF iconRect(-54, -54, 108, 108);
+ const QColor iconColor(214, 240, 110, 128);
+ iconGrid.resize(size.height());
+ int n = 0;
+
+ for (int y = 0; y < size.height(); ++y) {
+ iconGrid[y].resize(size.width());
+ for (int x = 0; x < size.width(); ++x) {
+ RoundRectItem *rect = new RoundRectItem(iconRect, iconColor, this);
+ rect->setZValue(1);
+ rect->setPos(posForLocation(x, y, size));
+ rect->setPixmap(pixmaps.at(n++ % pixmaps.size()));
+ iconGrid[y][x] = rect;
+ }
+ }
+}
+//! [4]
+
+//! [5]
+RoundRectItem *FlippablePad::iconAt(int column, int row) const
+{
+ return iconGrid[row][column];
+}
+//! [5]
diff --git a/examples/widgets/graphicsview/padnavigator/flippablepad.h b/examples/widgets/graphicsview/padnavigator/flippablepad.h
new file mode 100644
index 0000000000..e0d1fe24e5
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/flippablepad.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FLIPPABLEPAD_H
+#define FLIPPABLEPAD_H
+
+#include "roundrectitem.h"
+
+#include <QGraphicsObject>
+#include <QLinearGradient>
+#include <QVector>
+
+//! [0]
+class FlippablePad : public RoundRectItem
+{
+public:
+ FlippablePad(const QSize &size, QGraphicsItem *parent = 0);
+
+ RoundRectItem *iconAt(int column, int row) const;
+
+private:
+ QVector<QVector<RoundRectItem *> > iconGrid;
+};
+//! [0]
+
+#endif // FLIPPABLEPAD_H
diff --git a/examples/widgets/graphicsview/padnavigator/form.ui b/examples/widgets/graphicsview/padnavigator/form.ui
new file mode 100644
index 0000000000..fc7d12321e
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/form.ui
@@ -0,0 +1,208 @@
+<ui version="4.0" >
+ <class>Form</class>
+ <widget class="QWidget" name="Form" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>378</width>
+ <height>385</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>BackSide</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <item>
+ <widget class="QGroupBox" name="groupBox" >
+ <property name="title" >
+ <string>Settings</string>
+ </property>
+ <property name="flat" >
+ <bool>true</bool>
+ </property>
+ <property name="checkable" >
+ <bool>true</bool>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Title:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="hostName" >
+ <property name="text" >
+ <string>Pad Navigator Example</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Modified:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>Extent</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <widget class="QSlider" name="horizontalSlider" >
+ <property name="value" >
+ <number>42</number>
+ </property>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="spinBox" >
+ <property name="value" >
+ <number>42</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QDateTimeEdit" name="dateTimeEdit" />
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox_2" >
+ <property name="title" >
+ <string>Other input</string>
+ </property>
+ <property name="flat" >
+ <bool>true</bool>
+ </property>
+ <property name="checkable" >
+ <bool>true</bool>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_2" >
+ <item>
+ <widget class="QTreeWidget" name="treeWidget" >
+ <column>
+ <property name="text" >
+ <string>Widgets On Graphics View</string>
+ </property>
+ </column>
+ <item>
+ <property name="text" >
+ <string>QGraphicsProxyWidget</string>
+ </property>
+ <item>
+ <property name="text" >
+ <string>QGraphicsWidget</string>
+ </property>
+ <item>
+ <property name="text" >
+ <string>QObject</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>QGraphicsItem</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>QGraphicsLayoutItem</string>
+ </property>
+ </item>
+ </item>
+ </item>
+ <item>
+ <property name="text" >
+ <string>QGraphicsGridLayout</string>
+ </property>
+ <item>
+ <property name="text" >
+ <string>QGraphicsLayout</string>
+ </property>
+ <item>
+ <property name="text" >
+ <string>QGraphicsLayoutItem</string>
+ </property>
+ </item>
+ </item>
+ </item>
+ <item>
+ <property name="text" >
+ <string>QGraphicsLinearLayout</string>
+ </property>
+ <item>
+ <property name="text" >
+ <string>QGraphicsLayout</string>
+ </property>
+ <item>
+ <property name="text" >
+ <string>QGraphicsLayoutItem</string>
+ </property>
+ </item>
+ </item>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <tabstops>
+ <tabstop>groupBox</tabstop>
+ <tabstop>hostName</tabstop>
+ <tabstop>dateTimeEdit</tabstop>
+ <tabstop>horizontalSlider</tabstop>
+ <tabstop>spinBox</tabstop>
+ <tabstop>groupBox_2</tabstop>
+ <tabstop>treeWidget</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>horizontalSlider</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>spinBox</receiver>
+ <slot>setValue(int)</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>184</x>
+ <y>125</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>275</x>
+ <y>127</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>spinBox</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>horizontalSlider</receiver>
+ <slot>setValue(int)</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>272</x>
+ <y>114</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>190</x>
+ <y>126</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/widgets/graphicsview/padnavigator/images/artsfftscope.png b/examples/widgets/graphicsview/padnavigator/images/artsfftscope.png
new file mode 100644
index 0000000000..4db003f8d2
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/images/artsfftscope.png
Binary files differ
diff --git a/examples/widgets/graphicsview/padnavigator/images/blue_angle_swirl.jpg b/examples/widgets/graphicsview/padnavigator/images/blue_angle_swirl.jpg
new file mode 100644
index 0000000000..5bf0debdbd
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/images/blue_angle_swirl.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/padnavigator/images/kontact_contacts.png b/examples/widgets/graphicsview/padnavigator/images/kontact_contacts.png
new file mode 100644
index 0000000000..6fb4cc8f38
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/images/kontact_contacts.png
Binary files differ
diff --git a/examples/widgets/graphicsview/padnavigator/images/kontact_journal.png b/examples/widgets/graphicsview/padnavigator/images/kontact_journal.png
new file mode 100644
index 0000000000..b1fedb6982
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/images/kontact_journal.png
Binary files differ
diff --git a/examples/widgets/graphicsview/padnavigator/images/kontact_mail.png b/examples/widgets/graphicsview/padnavigator/images/kontact_mail.png
new file mode 100644
index 0000000000..672f8fa3ab
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/images/kontact_mail.png
Binary files differ
diff --git a/examples/widgets/graphicsview/padnavigator/images/kontact_notes.png b/examples/widgets/graphicsview/padnavigator/images/kontact_notes.png
new file mode 100644
index 0000000000..229bf73ac6
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/images/kontact_notes.png
Binary files differ
diff --git a/examples/widgets/graphicsview/padnavigator/images/kopeteavailable.png b/examples/widgets/graphicsview/padnavigator/images/kopeteavailable.png
new file mode 100644
index 0000000000..2eaf41afec
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/images/kopeteavailable.png
Binary files differ
diff --git a/examples/widgets/graphicsview/padnavigator/images/metacontact_online.png b/examples/widgets/graphicsview/padnavigator/images/metacontact_online.png
new file mode 100644
index 0000000000..6a398dd10f
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/images/metacontact_online.png
Binary files differ
diff --git a/examples/widgets/graphicsview/padnavigator/images/minitools.png b/examples/widgets/graphicsview/padnavigator/images/minitools.png
new file mode 100644
index 0000000000..0248c9d50a
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/images/minitools.png
Binary files differ
diff --git a/examples/widgets/graphicsview/padnavigator/main.cpp b/examples/widgets/graphicsview/padnavigator/main.cpp
new file mode 100644
index 0000000000..380fde8cd9
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "padnavigator.h"
+
+#include <QtWidgets/QtWidgets>
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Q_INIT_RESOURCE(padnavigator);
+
+ PadNavigator navigator(QSize(3, 3));
+ navigator.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/widgets/graphicsview/padnavigator/padnavigator.cpp b/examples/widgets/graphicsview/padnavigator/padnavigator.cpp
new file mode 100644
index 0000000000..fcfe84bb72
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/padnavigator.cpp
@@ -0,0 +1,306 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "flippablepad.h"
+#include "padnavigator.h"
+#include "splashitem.h"
+
+#include <QtWidgets/QtWidgets>
+#ifndef QT_NO_OPENGL
+#include <QtOpenGL/QtOpenGL>
+#endif
+
+//! [0]
+PadNavigator::PadNavigator(const QSize &size, QWidget *parent)
+ : QGraphicsView(parent)
+{
+//! [0]
+//! [1]
+ // Splash item
+ SplashItem *splash = new SplashItem;
+ splash->setZValue(1);
+//! [1]
+
+//! [2]
+ // Pad item
+ FlippablePad *pad = new FlippablePad(size);
+ QGraphicsRotation *flipRotation = new QGraphicsRotation(pad);
+ QGraphicsRotation *xRotation = new QGraphicsRotation(pad);
+ QGraphicsRotation *yRotation = new QGraphicsRotation(pad);
+ flipRotation->setAxis(Qt::YAxis);
+ xRotation->setAxis(Qt::YAxis);
+ yRotation->setAxis(Qt::XAxis);
+ pad->setTransformations(QList<QGraphicsTransform *>()
+ << flipRotation
+ << xRotation << yRotation);
+//! [2]
+
+//! [3]
+ // Back (proxy widget) item
+ QGraphicsProxyWidget *backItem = new QGraphicsProxyWidget(pad);
+ QWidget *widget = new QWidget;
+ form.setupUi(widget);
+ form.hostName->setFocus();
+ backItem->setWidget(widget);
+ backItem->setVisible(false);
+ backItem->setFocus();
+ backItem->setCacheMode(QGraphicsItem::ItemCoordinateCache);
+ const QRectF r = backItem->rect();
+ backItem->setTransform(QTransform()
+ .rotate(180, Qt::YAxis)
+ .translate(-r.width()/2, -r.height()/2));
+//! [3]
+
+//! [4]
+ // Selection item
+ RoundRectItem *selectionItem = new RoundRectItem(QRectF(-60, -60, 120, 120),
+ Qt::gray, pad);
+ selectionItem->setZValue(0.5);
+//! [4]
+
+//! [5]
+ // Splash animations
+ QPropertyAnimation *smoothSplashMove = new QPropertyAnimation(splash, "y");
+ QPropertyAnimation *smoothSplashOpacity = new QPropertyAnimation(splash, "opacity");
+ smoothSplashMove->setEasingCurve(QEasingCurve::InQuad);
+ smoothSplashMove->setDuration(250);
+ smoothSplashOpacity->setDuration(250);
+//! [5]
+
+//! [6]
+ // Selection animation
+ QPropertyAnimation *smoothXSelection = new QPropertyAnimation(selectionItem, "x");
+ QPropertyAnimation *smoothYSelection = new QPropertyAnimation(selectionItem, "y");
+ QPropertyAnimation *smoothXRotation = new QPropertyAnimation(xRotation, "angle");
+ QPropertyAnimation *smoothYRotation = new QPropertyAnimation(yRotation, "angle");
+ smoothXSelection->setDuration(125);
+ smoothYSelection->setDuration(125);
+ smoothXRotation->setDuration(125);
+ smoothYRotation->setDuration(125);
+ smoothXSelection->setEasingCurve(QEasingCurve::InOutQuad);
+ smoothYSelection->setEasingCurve(QEasingCurve::InOutQuad);
+ smoothXRotation->setEasingCurve(QEasingCurve::InOutQuad);
+ smoothYRotation->setEasingCurve(QEasingCurve::InOutQuad);
+//! [6]
+
+//! [7]
+ // Flip animation setup
+ QPropertyAnimation *smoothFlipRotation = new QPropertyAnimation(flipRotation, "angle");
+ QPropertyAnimation *smoothFlipScale = new QPropertyAnimation(pad, "scale");
+ QPropertyAnimation *smoothFlipXRotation = new QPropertyAnimation(xRotation, "angle");
+ QPropertyAnimation *smoothFlipYRotation = new QPropertyAnimation(yRotation, "angle");
+ QParallelAnimationGroup *flipAnimation = new QParallelAnimationGroup(this);
+ smoothFlipScale->setDuration(500);
+ smoothFlipRotation->setDuration(500);
+ smoothFlipXRotation->setDuration(500);
+ smoothFlipYRotation->setDuration(500);
+ smoothFlipScale->setEasingCurve(QEasingCurve::InOutQuad);
+ smoothFlipRotation->setEasingCurve(QEasingCurve::InOutQuad);
+ smoothFlipXRotation->setEasingCurve(QEasingCurve::InOutQuad);
+ smoothFlipYRotation->setEasingCurve(QEasingCurve::InOutQuad);
+ smoothFlipScale->setKeyValueAt(0, qvariant_cast<qreal>(1.0));
+ smoothFlipScale->setKeyValueAt(0.5, qvariant_cast<qreal>(0.7));
+ smoothFlipScale->setKeyValueAt(1, qvariant_cast<qreal>(1.0));
+ flipAnimation->addAnimation(smoothFlipRotation);
+ flipAnimation->addAnimation(smoothFlipScale);
+ flipAnimation->addAnimation(smoothFlipXRotation);
+ flipAnimation->addAnimation(smoothFlipYRotation);
+//! [7]
+
+//! [8]
+ // Flip animation delayed property assignment
+ QSequentialAnimationGroup *setVariablesSequence = new QSequentialAnimationGroup;
+ QPropertyAnimation *setFillAnimation = new QPropertyAnimation(pad, "fill");
+ QPropertyAnimation *setBackItemVisibleAnimation = new QPropertyAnimation(backItem, "visible");
+ QPropertyAnimation *setSelectionItemVisibleAnimation = new QPropertyAnimation(selectionItem, "visible");
+ setFillAnimation->setDuration(0);
+ setBackItemVisibleAnimation->setDuration(0);
+ setSelectionItemVisibleAnimation->setDuration(0);
+ setVariablesSequence->addPause(250);
+ setVariablesSequence->addAnimation(setBackItemVisibleAnimation);
+ setVariablesSequence->addAnimation(setSelectionItemVisibleAnimation);
+ setVariablesSequence->addAnimation(setFillAnimation);
+ flipAnimation->addAnimation(setVariablesSequence);
+//! [8]
+
+//! [9]
+ // Build the state machine
+ QStateMachine *stateMachine = new QStateMachine(this);
+ QState *splashState = new QState(stateMachine);
+ QState *frontState = new QState(stateMachine);
+ QHistoryState *historyState = new QHistoryState(frontState);
+ QState *backState = new QState(stateMachine);
+//! [9]
+//! [10]
+ frontState->assignProperty(pad, "fill", false);
+ frontState->assignProperty(splash, "opacity", 0.0);
+ frontState->assignProperty(backItem, "visible", false);
+ frontState->assignProperty(flipRotation, "angle", qvariant_cast<qreal>(0.0));
+ frontState->assignProperty(selectionItem, "visible", true);
+ backState->assignProperty(pad, "fill", true);
+ backState->assignProperty(backItem, "visible", true);
+ backState->assignProperty(xRotation, "angle", qvariant_cast<qreal>(0.0));
+ backState->assignProperty(yRotation, "angle", qvariant_cast<qreal>(0.0));
+ backState->assignProperty(flipRotation, "angle", qvariant_cast<qreal>(180.0));
+ backState->assignProperty(selectionItem, "visible", false);
+ stateMachine->addDefaultAnimation(smoothXRotation);
+ stateMachine->addDefaultAnimation(smoothYRotation);
+ stateMachine->addDefaultAnimation(smoothXSelection);
+ stateMachine->addDefaultAnimation(smoothYSelection);
+ stateMachine->setInitialState(splashState);
+//! [10]
+
+//! [11]
+ // Transitions
+ QEventTransition *anyKeyTransition = new QEventTransition(this, QEvent::KeyPress, splashState);
+ anyKeyTransition->setTargetState(frontState);
+ anyKeyTransition->addAnimation(smoothSplashMove);
+ anyKeyTransition->addAnimation(smoothSplashOpacity);
+//! [11]
+
+//! [12]
+ QKeyEventTransition *enterTransition = new QKeyEventTransition(this, QEvent::KeyPress,
+ Qt::Key_Enter, backState);
+ QKeyEventTransition *returnTransition = new QKeyEventTransition(this, QEvent::KeyPress,
+ Qt::Key_Return, backState);
+ QKeyEventTransition *backEnterTransition = new QKeyEventTransition(this, QEvent::KeyPress,
+ Qt::Key_Enter, frontState);
+ QKeyEventTransition *backReturnTransition = new QKeyEventTransition(this, QEvent::KeyPress,
+ Qt::Key_Return, frontState);
+ enterTransition->setTargetState(historyState);
+ returnTransition->setTargetState(historyState);
+ backEnterTransition->setTargetState(backState);
+ backReturnTransition->setTargetState(backState);
+ enterTransition->addAnimation(flipAnimation);
+ returnTransition->addAnimation(flipAnimation);
+ backEnterTransition->addAnimation(flipAnimation);
+ backReturnTransition->addAnimation(flipAnimation);
+//! [12]
+
+//! [13]
+ // Create substates for each icon; store in temporary grid.
+ int columns = size.width();
+ int rows = size.height();
+ QVector< QVector< QState * > > stateGrid;
+ stateGrid.resize(rows);
+ for (int y = 0; y < rows; ++y) {
+ stateGrid[y].resize(columns);
+ for (int x = 0; x < columns; ++x)
+ stateGrid[y][x] = new QState(frontState);
+ }
+ frontState->setInitialState(stateGrid[0][0]);
+ selectionItem->setPos(pad->iconAt(0, 0)->pos());
+//! [13]
+
+//! [14]
+ // Enable key navigation using state transitions
+ for (int y = 0; y < rows; ++y) {
+ for (int x = 0; x < columns; ++x) {
+ QState *state = stateGrid[y][x];
+ QKeyEventTransition *rightTransition = new QKeyEventTransition(this, QEvent::KeyPress,
+ Qt::Key_Right, state);
+ QKeyEventTransition *leftTransition = new QKeyEventTransition(this, QEvent::KeyPress,
+ Qt::Key_Left, state);
+ QKeyEventTransition *downTransition = new QKeyEventTransition(this, QEvent::KeyPress,
+ Qt::Key_Down, state);
+ QKeyEventTransition *upTransition = new QKeyEventTransition(this, QEvent::KeyPress,
+ Qt::Key_Up, state);
+ rightTransition->setTargetState(stateGrid[y][(x + 1) % columns]);
+ leftTransition->setTargetState(stateGrid[y][((x - 1) + columns) % columns]);
+ downTransition->setTargetState(stateGrid[(y + 1) % rows][x]);
+ upTransition->setTargetState(stateGrid[((y - 1) + rows) % rows][x]);
+//! [14]
+//! [15]
+ RoundRectItem *icon = pad->iconAt(x, y);
+ state->assignProperty(xRotation, "angle", -icon->x() / 6.0);
+ state->assignProperty(yRotation, "angle", icon->y() / 6.0);
+ state->assignProperty(selectionItem, "x", icon->x());
+ state->assignProperty(selectionItem, "y", icon->y());
+ frontState->assignProperty(icon, "visible", true);
+ backState->assignProperty(icon, "visible", false);
+
+ QPropertyAnimation *setIconVisibleAnimation = new QPropertyAnimation(icon, "visible");
+ setIconVisibleAnimation->setDuration(0);
+ setVariablesSequence->addAnimation(setIconVisibleAnimation);
+ }
+ }
+//! [15]
+
+//! [16]
+ // Scene
+ QGraphicsScene *scene = new QGraphicsScene(this);
+ scene->setBackgroundBrush(QPixmap(":/images/blue_angle_swirl.jpg"));
+ scene->setItemIndexMethod(QGraphicsScene::NoIndex);
+ scene->addItem(pad);
+ scene->setSceneRect(scene->itemsBoundingRect());
+ setScene(scene);
+//! [16]
+
+//! [17]
+ // Adjust splash item to scene contents
+ const QRectF sbr = splash->boundingRect();
+ splash->setPos(-sbr.width() / 2, scene->sceneRect().top() - 2);
+ frontState->assignProperty(splash, "y", splash->y() - 100.0);
+ scene->addItem(splash);
+//! [17]
+
+//! [18]
+ // View
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setMinimumSize(50, 50);
+ setViewportUpdateMode(FullViewportUpdate);
+ setCacheMode(CacheBackground);
+ setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
+#ifndef QT_NO_OPENGL
+ setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
+#endif
+
+ stateMachine->start();
+//! [18]
+}
+
+//! [19]
+void PadNavigator::resizeEvent(QResizeEvent *event)
+{
+ QGraphicsView::resizeEvent(event);
+ fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
+}
+//! [19]
diff --git a/examples/widgets/graphicsview/padnavigator/padnavigator.desktop b/examples/widgets/graphicsview/padnavigator/padnavigator.desktop
new file mode 100644
index 0000000000..f0490730c6
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/padnavigator.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Pad Navigator
+Exec=/opt/usr/bin/padnavigator
+Icon=padnavigator
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/padnavigator/padnavigator.h b/examples/widgets/graphicsview/padnavigator/padnavigator.h
new file mode 100644
index 0000000000..659b901f5c
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/padnavigator.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PADNAVIGATOR_H
+#define PADNAVIGATOR_H
+
+#include <QGraphicsView>
+#include "ui_form.h"
+
+QT_BEGIN_NAMESPACE
+
+class QState;
+class QStateMachine;
+class Ui_Form;
+
+QT_END_NAMESPACE
+
+//! [0]
+class PadNavigator : public QGraphicsView
+{
+ Q_OBJECT
+public:
+ explicit PadNavigator(const QSize &size, QWidget *parent = 0);
+
+protected:
+ void resizeEvent(QResizeEvent *event);
+
+private:
+ Ui_Form form;
+};
+//! [0]
+
+#endif // PADNAVIGATOR_H
diff --git a/examples/widgets/graphicsview/padnavigator/padnavigator.pro b/examples/widgets/graphicsview/padnavigator/padnavigator.pro
new file mode 100644
index 0000000000..4b9733bb9b
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/padnavigator.pro
@@ -0,0 +1,28 @@
+SOURCES += main.cpp \
+ roundrectitem.cpp \
+ flippablepad.cpp \
+ padnavigator.cpp \
+ splashitem.cpp
+
+HEADERS += \
+ roundrectitem.h \
+ flippablepad.h \
+ padnavigator.h \
+ splashitem.h
+
+RESOURCES += \
+ padnavigator.qrc
+
+FORMS += \
+ form.ui
+
+QT += widgets
+contains(QT_CONFIG, opengl):QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/padnavigator
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS padnavigator.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/padnavigator
+INSTALLS += target sources
+
+CONFIG += console
diff --git a/examples/widgets/graphicsview/padnavigator/padnavigator.qrc b/examples/widgets/graphicsview/padnavigator/padnavigator.qrc
new file mode 100644
index 0000000000..b26ab92ae1
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/padnavigator.qrc
@@ -0,0 +1,13 @@
+<RCC>
+ <qresource>
+ <file>images/blue_angle_swirl.jpg</file>
+ <file>images/artsfftscope.png</file>
+ <file>images/kontact_contacts.png</file>
+ <file>images/kontact_journal.png</file>
+ <file>images/kontact_mail.png</file>
+ <file>images/kontact_notes.png</file>
+ <file>images/kopeteavailable.png</file>
+ <file>images/metacontact_online.png</file>
+ <file>images/minitools.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/graphicsview/padnavigator/roundrectitem.cpp b/examples/widgets/graphicsview/padnavigator/roundrectitem.cpp
new file mode 100644
index 0000000000..1438db3a9c
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/roundrectitem.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "roundrectitem.h"
+
+#include <QtWidgets/QtWidgets>
+
+//! [0]
+RoundRectItem::RoundRectItem(const QRectF &bounds, const QColor &color,
+ QGraphicsItem *parent)
+ : QGraphicsObject(parent), fillRect(false), bounds(bounds)
+{
+ gradient.setStart(bounds.topLeft());
+ gradient.setFinalStop(bounds.bottomRight());
+ gradient.setColorAt(0, color);
+ gradient.setColorAt(1, color.dark(200));
+ setCacheMode(ItemCoordinateCache);
+}
+//! [0]
+
+//! [1]
+QPixmap RoundRectItem::pixmap() const
+{
+ return pix;
+}
+void RoundRectItem::setPixmap(const QPixmap &pixmap)
+{
+ pix = pixmap;
+ update();
+}
+//! [1]
+
+//! [2]
+QRectF RoundRectItem::boundingRect() const
+{
+ return bounds.adjusted(0, 0, 2, 2);
+}
+//! [2]
+
+//! [3]
+void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(QColor(0, 0, 0, 64));
+ painter->drawRoundRect(bounds.translated(2, 2));
+//! [3]
+//! [4]
+ if (fillRect)
+ painter->setBrush(QApplication::palette().brush(QPalette::Window));
+ else
+ painter->setBrush(gradient);
+ painter->setPen(QPen(Qt::black, 1));
+ painter->drawRoundRect(bounds);
+//! [4]
+//! [5]
+ if (!pix.isNull()) {
+ painter->scale(1.95, 1.95);
+ painter->drawPixmap(-pix.width() / 2, -pix.height() / 2, pix);
+ }
+}
+//! [5]
+
+//! [6]
+bool RoundRectItem::fill() const
+{
+ return fillRect;
+}
+void RoundRectItem::setFill(bool fill)
+{
+ fillRect = fill;
+ update();
+}
+//! [6]
diff --git a/examples/widgets/graphicsview/padnavigator/roundrectitem.h b/examples/widgets/graphicsview/padnavigator/roundrectitem.h
new file mode 100644
index 0000000000..af84984d49
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/roundrectitem.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ROUNDRECTITEM_H
+#define ROUNDRECTITEM_H
+
+#include <QGraphicsObject>
+#include <QLinearGradient>
+
+//! [0]
+class RoundRectItem : public QGraphicsObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool fill READ fill WRITE setFill)
+public:
+ RoundRectItem(const QRectF &bounds, const QColor &color,
+ QGraphicsItem *parent = 0);
+
+ QPixmap pixmap() const;
+ void setPixmap(const QPixmap &pixmap);
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+ bool fill() const;
+ void setFill(bool fill);
+//! [0]
+
+//! [1]
+private:
+ QPixmap pix;
+ bool fillRect;
+ QRectF bounds;
+ QLinearGradient gradient;
+};
+//! [1]
+
+#endif // ROUNDRECTITEM_H
diff --git a/examples/widgets/graphicsview/padnavigator/splashitem.cpp b/examples/widgets/graphicsview/padnavigator/splashitem.cpp
new file mode 100644
index 0000000000..d87e8333bd
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/splashitem.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "splashitem.h"
+
+#include <QtWidgets/QtWidgets>
+
+//! [0]
+SplashItem::SplashItem(QGraphicsItem *parent)
+ : QGraphicsObject(parent)
+{
+ text = tr("Welcome to the Pad Navigator Example. You can use the"
+ " keyboard arrows to navigate the icons, and press enter"
+ " to activate an item. Press any key to begin.");
+ setCacheMode(DeviceCoordinateCache);
+}
+//! [0]
+
+//! [1]
+QRectF SplashItem::boundingRect() const
+{
+ return QRectF(0, 0, 400, 175);
+}
+//! [1]
+
+//! [2]
+void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+ painter->setPen(QPen(Qt::black, 2));
+ painter->setBrush(QColor(245, 245, 255, 220));
+ painter->setClipRect(boundingRect());
+ painter->drawRoundRect(3, -100 + 3, 400 - 6, 250 - 6);
+
+ QRectF textRect = boundingRect().adjusted(10, 10, -10, -10);
+ int flags = Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap;
+
+ QFont font;
+ font.setPixelSize(18);
+ painter->setPen(Qt::black);
+ painter->setFont(font);
+ painter->drawText(textRect, flags, text);
+}
+//! [2]
diff --git a/examples/widgets/graphicsview/padnavigator/splashitem.h b/examples/widgets/graphicsview/padnavigator/splashitem.h
new file mode 100644
index 0000000000..bc0917e3de
--- /dev/null
+++ b/examples/widgets/graphicsview/padnavigator/splashitem.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SPLASHITEM_H
+#define SPLASHITEM_H
+
+#include <QGraphicsObject>
+
+//! [0]
+class SplashItem : public QGraphicsObject
+{
+ Q_OBJECT
+public:
+ explicit SplashItem(QGraphicsItem *parent = 0);
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+private:
+ QString text;
+};
+//! [0]
+
+#endif // SPLASHITEM_H
diff --git a/examples/widgets/graphicsview/portedasteroids/portedasteroids.desktop b/examples/widgets/graphicsview/portedasteroids/portedasteroids.desktop
new file mode 100644
index 0000000000..abd061699b
--- /dev/null
+++ b/examples/widgets/graphicsview/portedasteroids/portedasteroids.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Ported Asteroids
+Exec=/opt/usr/bin/portedasteroids
+Icon=portedasteroids
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/portedcanvas/portedcanvas.desktop b/examples/widgets/graphicsview/portedcanvas/portedcanvas.desktop
new file mode 100644
index 0000000000..1217dc43de
--- /dev/null
+++ b/examples/widgets/graphicsview/portedcanvas/portedcanvas.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Ported Canvas
+Exec=/opt/usr/bin/portedcanvas
+Icon=portedcanvas
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/simpleanchorlayout/main.cpp b/examples/widgets/graphicsview/simpleanchorlayout/main.cpp
new file mode 100644
index 0000000000..50d8513c84
--- /dev/null
+++ b/examples/widgets/graphicsview/simpleanchorlayout/main.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+class Widget : public QGraphicsWidget
+{
+public:
+ Widget(const QColor &color, const QColor &textColor, const QString &caption,
+ QGraphicsItem *parent = 0)
+ : QGraphicsWidget(parent), caption(caption), color(color), textColor(textColor)
+ {
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * = 0)
+ {
+ QFont font;
+ font.setPixelSize(0.75 * qMin(boundingRect().width(), boundingRect().height()));
+
+ painter->fillRect(boundingRect(), color);
+ painter->save();
+ painter->setFont(font);
+ painter->setPen(textColor);
+ painter->drawText(boundingRect(), Qt::AlignCenter, caption);
+ painter->restore();
+ }
+
+private:
+ QString caption;
+ QColor color;
+ QColor textColor;
+};
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QGraphicsScene *scene = new QGraphicsScene();
+
+ Widget *a = new Widget(Qt::blue, Qt::white, "a");
+ a->setPreferredSize(100, 100);
+ Widget *b = new Widget(Qt::green, Qt::black, "b");
+ b->setPreferredSize(100, 100);
+ Widget *c = new Widget(Qt::red, Qt::black, "c");
+ c->setPreferredSize(100, 100);
+
+ QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout();
+/*
+ //! [adding a corner anchor in two steps]
+ layout->addAnchor(a, Qt::AnchorTop, layout, Qt::AnchorTop);
+ layout->addAnchor(a, Qt::AnchorLeft, layout, Qt::AnchorLeft);
+ //! [adding a corner anchor in two steps]
+*/
+ //! [adding a corner anchor]
+ layout->addCornerAnchors(a, Qt::TopLeftCorner, layout, Qt::TopLeftCorner);
+ //! [adding a corner anchor]
+
+ //! [adding anchors]
+ layout->addAnchor(b, Qt::AnchorLeft, a, Qt::AnchorRight);
+ layout->addAnchor(b, Qt::AnchorTop, a, Qt::AnchorBottom);
+ //! [adding anchors]
+
+ // Place a third widget below the second.
+ layout->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);
+
+/*
+ //! [adding anchors to match sizes in two steps]
+ layout->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft);
+ layout->addAnchor(b, Qt::AnchorRight, c, Qt::AnchorRight);
+ //! [adding anchors to match sizes in two steps]
+*/
+
+ //! [adding anchors to match sizes]
+ layout->addAnchors(b, c, Qt::Horizontal);
+ //! [adding anchors to match sizes]
+
+ // Anchor the bottom-right corner of the third widget to the bottom-right
+ // corner of the layout.
+ layout->addCornerAnchors(c, Qt::BottomRightCorner, layout, Qt::BottomRightCorner);
+
+ QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
+ w->setPos(20, 20);
+ w->setMinimumSize(100, 100);
+ w->setPreferredSize(320, 240);
+ w->setLayout(layout);
+ w->setWindowTitle(QApplication::translate("simpleanchorlayout", "QGraphicsAnchorLayout in use"));
+ scene->addItem(w);
+
+ QGraphicsView *view = new QGraphicsView();
+ view->setScene(scene);
+ view->setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout"));
+
+ view->resize(360, 320);
+ view->show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/graphicsview/simpleanchorlayout/simpleanchorlayout.desktop b/examples/widgets/graphicsview/simpleanchorlayout/simpleanchorlayout.desktop
new file mode 100644
index 0000000000..0e8d73a859
--- /dev/null
+++ b/examples/widgets/graphicsview/simpleanchorlayout/simpleanchorlayout.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Simple Anchor Layout
+Exec=/opt/usr/bin/simpleanchorlayout
+Icon=simpleanchorlayout
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/simpleanchorlayout/simpleanchorlayout.pro b/examples/widgets/graphicsview/simpleanchorlayout/simpleanchorlayout.pro
new file mode 100644
index 0000000000..b044d4e91c
--- /dev/null
+++ b/examples/widgets/graphicsview/simpleanchorlayout/simpleanchorlayout.pro
@@ -0,0 +1,12 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/simpleanchorlayout
+sources.files = $$SOURCES $$HEADERS $$RESOURCES simpleanchorlayout.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/simpleanchorlayout
+INSTALLS += target sources
+
+TARGET = simpleanchorlayout
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/images/5days.jpg b/examples/widgets/graphicsview/weatheranchorlayout/images/5days.jpg
new file mode 100644
index 0000000000..fd92ba8ba7
--- /dev/null
+++ b/examples/widgets/graphicsview/weatheranchorlayout/images/5days.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/images/details.jpg b/examples/widgets/graphicsview/weatheranchorlayout/images/details.jpg
new file mode 100644
index 0000000000..fde0448c69
--- /dev/null
+++ b/examples/widgets/graphicsview/weatheranchorlayout/images/details.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/images/place.jpg b/examples/widgets/graphicsview/weatheranchorlayout/images/place.jpg
new file mode 100644
index 0000000000..03e5344330
--- /dev/null
+++ b/examples/widgets/graphicsview/weatheranchorlayout/images/place.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/images/tabbar.jpg b/examples/widgets/graphicsview/weatheranchorlayout/images/tabbar.jpg
new file mode 100644
index 0000000000..7777662901
--- /dev/null
+++ b/examples/widgets/graphicsview/weatheranchorlayout/images/tabbar.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/images/title.jpg b/examples/widgets/graphicsview/weatheranchorlayout/images/title.jpg
new file mode 100644
index 0000000000..fa84c8156c
--- /dev/null
+++ b/examples/widgets/graphicsview/weatheranchorlayout/images/title.jpg
Binary files differ
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/images/weather-few-clouds.png b/examples/widgets/graphicsview/weatheranchorlayout/images/weather-few-clouds.png
new file mode 100644
index 0000000000..eea6ce6529
--- /dev/null
+++ b/examples/widgets/graphicsview/weatheranchorlayout/images/weather-few-clouds.png
Binary files differ
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/main.cpp b/examples/widgets/graphicsview/weatheranchorlayout/main.cpp
new file mode 100644
index 0000000000..64605bebc0
--- /dev/null
+++ b/examples/widgets/graphicsview/weatheranchorlayout/main.cpp
@@ -0,0 +1,274 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QLabel>
+#include <QPainter>
+#include <QPushButton>
+#include <QApplication>
+
+#include <QGraphicsView>
+#include <QGraphicsScene>
+#include <QGraphicsWidget>
+#include <QGraphicsProxyWidget>
+#include <QGraphicsAnchorLayout>
+#include <QGraphicsSceneResizeEvent>
+
+
+class GraphicsView : public QGraphicsView
+{
+public:
+ GraphicsView(QGraphicsScene *scene, QGraphicsWidget *widget) : QGraphicsView(scene), w(widget)
+ {
+ }
+
+ virtual void resizeEvent(QResizeEvent *event)
+ {
+ w->setGeometry(0, 0, event->size().width(), event->size().height());
+ }
+
+ QGraphicsWidget *w;
+};
+
+class PixmapWidget : public QGraphicsLayoutItem
+{
+
+public:
+ PixmapWidget(const QPixmap &pix) : QGraphicsLayoutItem()
+ {
+ original = new QGraphicsPixmapItem(pix);
+ setGraphicsItem(original);
+ original->show();
+ r = QRectF(QPointF(0, 0), pix.size());
+ }
+
+ ~PixmapWidget()
+ {
+ setGraphicsItem(0);
+ delete original;
+ }
+
+ void setZValue(qreal z)
+ {
+ original->setZValue(z);
+ }
+
+ void setGeometry (const QRectF &rect)
+ {
+ original->setTransform(QTransform::fromScale(rect.width() / r.width(), rect.height() / r.height()), true);
+ original->setPos(rect.x(), rect.y());
+ r = rect;
+ }
+
+protected:
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const
+ {
+ Q_UNUSED(constraint);
+ QSizeF sh;
+ switch (which) {
+ case Qt::MinimumSize:
+ sh = QSizeF(0, 0);
+ break;
+ case Qt::PreferredSize:
+ sh = QSizeF(50, 50);
+ break;
+ case Qt::MaximumSize:
+ sh = QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
+ break;
+ default:
+ break;
+ }
+ return sh;
+ }
+
+private:
+ QGraphicsPixmapItem *original;
+ QRectF r;
+};
+
+
+class PlaceWidget : public QGraphicsWidget
+{
+ Q_OBJECT
+
+public:
+ PlaceWidget(const QPixmap &pix) : QGraphicsWidget(), original(pix), scaled(pix)
+ {
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
+ {
+ QPointF reflection = QPointF();
+ reflection.setY(scaled.height() + 2);
+
+ painter->drawPixmap(QPointF(), scaled);
+
+ QPixmap tmp(scaled.size());
+ tmp.fill(Qt::transparent);
+ QPainter p(&tmp);
+
+ // create gradient
+ QPoint p1(scaled.width() / 2, 0);
+ QPoint p2(scaled.width() / 2, scaled.height());
+ QLinearGradient linearGrad(p1, p2);
+ linearGrad.setColorAt(0, QColor(0, 0, 0, 0));
+ linearGrad.setColorAt(0.65, QColor(0, 0, 0, 127));
+ linearGrad.setColorAt(1, QColor(0, 0, 0, 255));
+
+ // apply 'mask'
+ p.setBrush(linearGrad);
+ p.fillRect(0, 0, tmp.width(), tmp.height(), QBrush(linearGrad));
+ p.fillRect(0, 0, tmp.width(), tmp.height(), QBrush(linearGrad));
+
+ // paint the image flipped
+ p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
+ p.drawPixmap(0, 0, QPixmap::fromImage(scaled.toImage().mirrored(false, true)));
+ p.end();
+
+ painter->drawPixmap(reflection, tmp);
+ }
+
+ void resizeEvent(QGraphicsSceneResizeEvent *event)
+ {
+ QSize newSize = event->newSize().toSize();
+ newSize.setHeight(newSize.height() / 2);
+ scaled = original.scaled(newSize);
+ }
+
+ QRectF boundingRect() const
+ {
+ QSize size(scaled.width(), scaled.height() * 2 + 2);
+ return QRectF(QPointF(0, 0), size);
+ }
+
+private:
+ QPixmap original;
+ QPixmap scaled;
+};
+
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(weatheranchorlayout);
+
+ QApplication app(argc, argv);
+
+ QGraphicsScene scene;
+ scene.setSceneRect(0, 0, 800, 480);
+
+ // pixmaps widgets
+ PixmapWidget *title = new PixmapWidget(QPixmap(":/images/title.jpg"));
+ PlaceWidget *place = new PlaceWidget(QPixmap(":/images/place.jpg"));
+ PixmapWidget *details = new PixmapWidget(QPixmap(":/images/5days.jpg"));
+ PixmapWidget *sunnyWeather = new PixmapWidget(QPixmap(":/images/weather-few-clouds.png"));
+ PixmapWidget *tabbar = new PixmapWidget(QPixmap(":/images/tabbar.jpg"));
+
+
+ // setup sizes
+ title->setPreferredSize(QSizeF(348, 45));
+ title->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+
+ place->setPreferredSize(QSizeF(96, 72));
+ place->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+
+ details->setMinimumSize(QSizeF(200, 112));
+ details->setPreferredSize(QSizeF(200, 112));
+ details->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+
+ tabbar->setPreferredSize(QSizeF(70, 24));
+ tabbar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+
+ sunnyWeather->setPreferredSize(QSizeF(128, 97));
+ sunnyWeather->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+ sunnyWeather->setZValue(9999);
+
+ // start anchor layout
+ QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
+ l->setSpacing(0);
+
+ // setup the main widget
+ QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
+ QPalette p;
+ p.setColor(QPalette::Window, Qt::black);
+ w->setPalette(p);
+ w->setPos(20, 20);
+ w->setLayout(l);
+
+ // vertical anchors
+ QGraphicsAnchor *anchor = l->addAnchor(title, Qt::AnchorTop, l, Qt::AnchorTop);
+ anchor = l->addAnchor(place, Qt::AnchorTop, title, Qt::AnchorBottom);
+ anchor->setSpacing(12);
+ anchor = l->addAnchor(place, Qt::AnchorBottom, l, Qt::AnchorBottom);
+ anchor->setSpacing(12);
+
+ anchor = l->addAnchor(sunnyWeather, Qt::AnchorTop, title, Qt::AnchorTop);
+ anchor = l->addAnchor(sunnyWeather, Qt::AnchorBottom, l, Qt::AnchorVerticalCenter);
+
+ anchor = l->addAnchor(tabbar, Qt::AnchorTop, title, Qt::AnchorBottom);
+ anchor->setSpacing(5);
+ anchor = l->addAnchor(details, Qt::AnchorTop, tabbar, Qt::AnchorBottom);
+ anchor->setSpacing(2);
+ anchor = l->addAnchor(details, Qt::AnchorBottom, l, Qt::AnchorBottom);
+ anchor->setSpacing(12);
+
+ // horizontal anchors
+ anchor = l->addAnchor(l, Qt::AnchorLeft, title, Qt::AnchorLeft);
+ anchor = l->addAnchor(title, Qt::AnchorRight, l, Qt::AnchorRight);
+
+ anchor = l->addAnchor(place, Qt::AnchorLeft, l, Qt::AnchorLeft);
+ anchor->setSpacing(15);
+ anchor = l->addAnchor(place, Qt::AnchorRight, details, Qt::AnchorLeft);
+ anchor->setSpacing(35);
+
+ anchor = l->addAnchor(sunnyWeather, Qt::AnchorLeft, place, Qt::AnchorHorizontalCenter);
+ anchor = l->addAnchor(sunnyWeather, Qt::AnchorRight, l, Qt::AnchorHorizontalCenter);
+
+ anchor = l->addAnchor(tabbar, Qt::AnchorHorizontalCenter, details, Qt::AnchorHorizontalCenter);
+ anchor = l->addAnchor(details, Qt::AnchorRight, l, Qt::AnchorRight);
+
+ // QGV setup
+ scene.addItem(w);
+ scene.setBackgroundBrush(Qt::white);
+ QGraphicsView *view = new QGraphicsView(&scene);
+ view->show();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.desktop b/examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.desktop
new file mode 100644
index 0000000000..0c6ab89a68
--- /dev/null
+++ b/examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Weather Anchor Layout
+Exec=/opt/usr/bin/weatheranchorlayout
+Icon=weatheranchorlayout
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.pro b/examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.pro
new file mode 100644
index 0000000000..b6eb292a12
--- /dev/null
+++ b/examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.pro
@@ -0,0 +1,12 @@
+QT += widgets
+
+SOURCES += main.cpp
+RESOURCES += weatheranchorlayout.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/weatheranchorlayout
+sources.files = $$SOURCES $$HEADERS $$RESOURCES weatheranchorlayout.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/graphicsview/weatheranchorlayout
+INSTALLS += target sources
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.qrc b/examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.qrc
new file mode 100644
index 0000000000..e39f8c0423
--- /dev/null
+++ b/examples/widgets/graphicsview/weatheranchorlayout/weatheranchorlayout.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/5days.jpg</file>
+ <file>images/title.jpg</file>
+ <file>images/place.jpg</file>
+ <file>images/tabbar.jpg</file>
+ <file>images/details.jpg</file>
+ <file>images/weather-few-clouds.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/itemviews/README b/examples/widgets/itemviews/README
new file mode 100644
index 0000000000..bded96a849
--- /dev/null
+++ b/examples/widgets/itemviews/README
@@ -0,0 +1,8 @@
+Item views are widgets that typically display data sets. Qt 4's model/view
+framework lets you handle large data sets by separating the underlying data
+from the way it is represented to the user, and provides support for
+customized rendering through the use of delegates.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/itemviews/addressbook/adddialog.cpp b/examples/widgets/itemviews/addressbook/adddialog.cpp
new file mode 100644
index 0000000000..f34bd0d46e
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/adddialog.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include "adddialog.h"
+
+//! [0]
+AddDialog::AddDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ nameLabel = new QLabel("Name");
+ addressLabel = new QLabel("Address");
+ okButton = new QPushButton("OK");
+ cancelButton = new QPushButton("Cancel");
+
+ nameText = new QLineEdit;
+ addressText = new QTextEdit;
+
+ QGridLayout *gLayout = new QGridLayout;
+ gLayout->setColumnStretch(1, 2);
+ gLayout->addWidget(nameLabel, 0, 0);
+ gLayout->addWidget(nameText, 0, 1);
+
+ gLayout->addWidget(addressLabel, 1, 0, Qt::AlignLeft|Qt::AlignTop);
+ gLayout->addWidget(addressText, 1, 1, Qt::AlignLeft);
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addWidget(okButton);
+ buttonLayout->addWidget(cancelButton);
+
+ gLayout->addLayout(buttonLayout, 2, 1, Qt::AlignRight);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(gLayout);
+ setLayout(mainLayout);
+
+ connect(okButton, SIGNAL(clicked()),
+ this, SLOT(accept()));
+
+ connect(cancelButton, SIGNAL(clicked()),
+ this, SLOT(reject()));
+
+ setWindowTitle(tr("Add a Contact"));
+}
+//! [0]
diff --git a/examples/widgets/itemviews/addressbook/adddialog.h b/examples/widgets/itemviews/addressbook/adddialog.h
new file mode 100644
index 0000000000..6d9093b638
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/adddialog.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDDIALOG_H
+#define ADDDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QPushButton;
+class QTextEdit;
+class QLineEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class AddDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ AddDialog(QWidget *parent=0);
+ QLineEdit *nameText;
+ QTextEdit *addressText;
+
+private:
+ QLabel *nameLabel;
+ QLabel *addressLabel;
+ QPushButton *okButton;
+ QPushButton *cancelButton;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/addressbook/addressbook.desktop b/examples/widgets/itemviews/addressbook/addressbook.desktop
new file mode 100644
index 0000000000..11767f59d8
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/addressbook.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Address Book
+Exec=/opt/usr/bin/addressbook
+Icon=addressbook
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/addressbook/addressbook.pro b/examples/widgets/itemviews/addressbook/addressbook.pro
new file mode 100644
index 0000000000..32cbc4ca36
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/addressbook.pro
@@ -0,0 +1,19 @@
+SOURCES = adddialog.cpp \
+ addresswidget.cpp \
+ main.cpp \
+ mainwindow.cpp \
+ newaddresstab.cpp \
+ tablemodel.cpp
+HEADERS = adddialog.h \
+ addresswidget.h \
+ mainwindow.h \
+ newaddresstab.h \
+ tablemodel.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/addressbook
+sources.files = $$SOURCES $$HEADERS $$RESOURCES addressbook.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/addressbook
+INSTALLS += target sources
+QT += widgets
+
diff --git a/examples/widgets/itemviews/addressbook/addresswidget.cpp b/examples/widgets/itemviews/addressbook/addresswidget.cpp
new file mode 100644
index 0000000000..066d5588c7
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/addresswidget.cpp
@@ -0,0 +1,236 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include "addresswidget.h"
+#include "adddialog.h"
+
+//! [0]
+AddressWidget::AddressWidget(QWidget *parent)
+ : QTabWidget(parent)
+{
+ table = new TableModel(this);
+ newAddressTab = new NewAddressTab(this);
+ connect(newAddressTab, SIGNAL(sendDetails(QString,QString)),
+ this, SLOT(addEntry(QString,QString)));
+
+ addTab(newAddressTab, "Address Book");
+
+ setupTabs();
+}
+//! [0]
+
+//! [2]
+void AddressWidget::addEntry()
+{
+ AddDialog aDialog;
+
+ if (aDialog.exec()) {
+ QString name = aDialog.nameText->text();
+ QString address = aDialog.addressText->toPlainText();
+
+ addEntry(name, address);
+ }
+}
+//! [2]
+
+//! [3]
+void AddressWidget::addEntry(QString name, QString address)
+{
+ QList< QPair<QString, QString> >list = table->getList();
+ QPair<QString, QString> pair(name, address);
+
+ if (!list.contains(pair)) {
+ table->insertRows(0, 1, QModelIndex());
+
+ QModelIndex index = table->index(0, 0, QModelIndex());
+ table->setData(index, name, Qt::EditRole);
+ index = table->index(0, 1, QModelIndex());
+ table->setData(index, address, Qt::EditRole);
+ removeTab(indexOf(newAddressTab));
+ } else {
+ QMessageBox::information(this, tr("Duplicate Name"),
+ tr("The name \"%1\" already exists.").arg(name));
+ }
+}
+//! [3]
+
+//! [4a]
+void AddressWidget::editEntry()
+{
+ QTableView *temp = static_cast<QTableView*>(currentWidget());
+ QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(temp->model());
+ QItemSelectionModel *selectionModel = temp->selectionModel();
+
+ QModelIndexList indexes = selectionModel->selectedRows();
+ QModelIndex index, i;
+ QString name;
+ QString address;
+ int row = -1;
+
+ foreach (index, indexes) {
+ row = proxy->mapToSource(index).row();
+ i = table->index(row, 0, QModelIndex());
+ QVariant varName = table->data(i, Qt::DisplayRole);
+ name = varName.toString();
+
+ i = table->index(row, 1, QModelIndex());
+ QVariant varAddr = table->data(i, Qt::DisplayRole);
+ address = varAddr.toString();
+ }
+//! [4a]
+
+//! [4b]
+ AddDialog aDialog;
+ aDialog.setWindowTitle(tr("Edit a Contact"));
+
+ aDialog.nameText->setReadOnly(true);
+ aDialog.nameText->setText(name);
+ aDialog.addressText->setText(address);
+
+ if (aDialog.exec()) {
+ QString newAddress = aDialog.addressText->toPlainText();
+ if (newAddress != address) {
+ i = table->index(row, 1, QModelIndex());
+ table->setData(i, newAddress, Qt::EditRole);
+ }
+ }
+}
+//! [4b]
+
+//! [5]
+void AddressWidget::removeEntry()
+{
+ QTableView *temp = static_cast<QTableView*>(currentWidget());
+ QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(temp->model());
+ QItemSelectionModel *selectionModel = temp->selectionModel();
+
+ QModelIndexList indexes = selectionModel->selectedRows();
+ QModelIndex index;
+
+ foreach (index, indexes) {
+ int row = proxy->mapToSource(index).row();
+ table->removeRows(row, 1, QModelIndex());
+ }
+
+ if (table->rowCount(QModelIndex()) == 0) {
+ insertTab(0, newAddressTab, "Address Book");
+ }
+}
+//! [5]
+
+//! [1]
+void AddressWidget::setupTabs()
+{
+ QStringList groups;
+ groups << "ABC" << "DEF" << "GHI" << "JKL" << "MNO" << "PQR" << "STU" << "VW" << "XYZ";
+
+ for (int i = 0; i < groups.size(); ++i) {
+ QString str = groups.at(i);
+
+ proxyModel = new QSortFilterProxyModel(this);
+ proxyModel->setSourceModel(table);
+
+ QTableView *tableView = new QTableView;
+ tableView->setModel(proxyModel);
+ tableView->setSortingEnabled(true);
+ tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ tableView->horizontalHeader()->setStretchLastSection(true);
+ tableView->verticalHeader()->hide();
+ tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ tableView->setSelectionMode(QAbstractItemView::SingleSelection);
+
+ QString newStr = QString("^[%1].*").arg(str);
+
+ proxyModel->setFilterRegExp(QRegExp(newStr, Qt::CaseInsensitive));
+ proxyModel->setFilterKeyColumn(0);
+ proxyModel->sort(0, Qt::AscendingOrder);
+
+ connect(tableView->selectionModel(),
+ SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
+ this, SIGNAL(selectionChanged(QItemSelection)));
+
+ addTab(tableView, str);
+ }
+}
+//! [1]
+
+//! [7]
+void AddressWidget::readFromFile(QString fileName)
+{
+ QFile file(fileName);
+
+ if (!file.open(QIODevice::ReadOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+ QList< QPair<QString, QString> > pairs = table->getList();
+ QDataStream in(&file);
+ in >> pairs;
+
+ if (pairs.isEmpty()) {
+ QMessageBox::information(this, tr("No contacts in file"),
+ tr("The file you are attempting to open contains no contacts."));
+ } else {
+ for (int i=0; i<pairs.size(); ++i) {
+ QPair<QString, QString> p = pairs.at(i);
+ addEntry(p.first, p.second);
+ }
+ }
+}
+//! [7]
+
+//! [6]
+void AddressWidget::writeToFile(QString fileName)
+{
+ QFile file(fileName);
+
+ if (!file.open(QIODevice::WriteOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"), file.errorString());
+ return;
+ }
+
+ QList< QPair<QString, QString> > pairs = table->getList();
+ QDataStream out(&file);
+ out << pairs;
+}
+//! [6]
diff --git a/examples/widgets/itemviews/addressbook/addresswidget.h b/examples/widgets/itemviews/addressbook/addresswidget.h
new file mode 100644
index 0000000000..3a46818463
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/addresswidget.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSWIDGET_H
+#define ADDRESSWIDGET_H
+
+#include <QTabWidget>
+#include <QItemSelection>
+#include "tablemodel.h"
+#include "newaddresstab.h"
+
+QT_BEGIN_NAMESPACE
+class QSortFilterProxyModel;
+class QItemSelectionModel;
+QT_END_NAMESPACE
+
+//! [0]
+class AddressWidget : public QTabWidget
+{
+ Q_OBJECT
+
+public:
+ AddressWidget(QWidget *parent=0);
+ void readFromFile(QString fileName);
+ void writeToFile(QString fileName);
+
+public slots:
+ void addEntry();
+ void addEntry(QString name, QString address);
+ void editEntry();
+ void removeEntry();
+
+signals:
+ void selectionChanged (const QItemSelection &selected);
+
+private:
+ void setupTabs();
+
+ TableModel *table;
+ NewAddressTab *newAddressTab;
+ QSortFilterProxyModel *proxyModel;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/addressbook/main.cpp b/examples/widgets/itemviews/addressbook/main.cpp
new file mode 100644
index 0000000000..9f388dc123
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mw;
+ mw.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/widgets/itemviews/addressbook/mainwindow.cpp b/examples/widgets/itemviews/addressbook/mainwindow.cpp
new file mode 100644
index 0000000000..e16aec94b0
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/mainwindow.cpp
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ addressWidget = new AddressWidget;
+ setCentralWidget(addressWidget);
+ createMenus();
+ setWindowTitle(tr("Address Book"));
+}
+//! [0]
+
+//! [1a]
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+
+ openAct = new QAction(tr("&Open..."), this);
+ fileMenu->addAction(openAct);
+ connect(openAct, SIGNAL(triggered()),
+ this, SLOT(openFile()));
+//! [1a]
+
+ saveAct = new QAction(tr("&Save As..."), this);
+ fileMenu->addAction(saveAct);
+ connect(saveAct, SIGNAL(triggered()),
+ this, SLOT(saveFile()));
+
+ fileMenu->addSeparator();
+
+ exitAct = new QAction(tr("E&xit"), this);
+ fileMenu->addAction(exitAct);
+ connect(exitAct, SIGNAL(triggered()),
+ this, SLOT(close()));
+
+ toolMenu = menuBar()->addMenu(tr("&Tools"));
+
+ addAct = new QAction(tr("&Add Entry..."), this);
+ toolMenu->addAction(addAct);
+ connect(addAct, SIGNAL(triggered()),
+ addressWidget, SLOT(addEntry()));
+
+//! [1b]
+ editAct = new QAction(tr("&Edit Entry..."), this);
+ editAct->setEnabled(false);
+ toolMenu->addAction(editAct);
+ connect(editAct, SIGNAL(triggered()),
+ addressWidget, SLOT(editEntry()));
+
+ toolMenu->addSeparator();
+
+ removeAct = new QAction(tr("&Remove Entry"), this);
+ removeAct->setEnabled(false);
+ toolMenu->addAction(removeAct);
+ connect(removeAct, SIGNAL(triggered()),
+ addressWidget, SLOT(removeEntry()));
+
+ connect(addressWidget, SIGNAL(selectionChanged(QItemSelection)),
+ this, SLOT(updateActions(QItemSelection)));
+}
+//! [1b]
+
+//! [2]
+void MainWindow::openFile()
+{
+ QString fileName = QFileDialog::getOpenFileName(this);
+ if (!fileName.isEmpty()) {
+ addressWidget->readFromFile(fileName);
+ }
+}
+//! [2]
+
+//! [3]
+void MainWindow::saveFile()
+{
+ QString fileName = QFileDialog::getSaveFileName(this);
+ if (!fileName.isEmpty()) {
+ addressWidget->writeToFile(fileName);
+ }
+}
+//! [3]
+
+//! [4]
+void MainWindow::updateActions(const QItemSelection &selection)
+{
+ QModelIndexList indexes = selection.indexes();
+
+ if (!indexes.isEmpty()) {
+ removeAct->setEnabled(true);
+ editAct->setEnabled(true);
+ } else {
+ removeAct->setEnabled(false);
+ editAct->setEnabled(false);
+ }
+}
+//! [4]
diff --git a/examples/widgets/itemviews/addressbook/mainwindow.h b/examples/widgets/itemviews/addressbook/mainwindow.h
new file mode 100644
index 0000000000..284e492c4a
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/mainwindow.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtWidgets>
+#include "addresswidget.h"
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void updateActions(const QItemSelection &selection);
+ void openFile();
+ void saveFile();
+
+private:
+ void createMenus();
+
+ AddressWidget *addressWidget;
+ QMenu *fileMenu;
+ QMenu *toolMenu;
+ QAction *openAct;
+ QAction *saveAct;
+ QAction *exitAct;
+ QAction *addAct;
+ QAction *editAct;
+ QAction *removeAct;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/addressbook/newaddresstab.cpp b/examples/widgets/itemviews/addressbook/newaddresstab.cpp
new file mode 100644
index 0000000000..f27789a511
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/newaddresstab.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include "newaddresstab.h"
+#include "adddialog.h"
+
+//! [0]
+NewAddressTab::NewAddressTab(QWidget *parent)
+{
+ Q_UNUSED(parent);
+
+ descriptionLabel = new QLabel(tr("There are currently no contacts in your address book. "
+ "\nClick Add to add new contacts."));
+
+ addButton = new QPushButton(tr("Add"));
+
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addEntry()));
+
+ mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(descriptionLabel);
+ mainLayout->addWidget(addButton, 0, Qt::AlignCenter);
+
+ setLayout(mainLayout);
+}
+//! [0]
+
+//! [1]
+void NewAddressTab::addEntry()
+{
+ AddDialog aDialog;
+
+ if (aDialog.exec()) {
+ QString name = aDialog.nameText->text();
+ QString address = aDialog.addressText->toPlainText();
+
+ emit sendDetails(name, address);
+ }
+}
+//! [1]
diff --git a/examples/widgets/itemviews/addressbook/newaddresstab.h b/examples/widgets/itemviews/addressbook/newaddresstab.h
new file mode 100644
index 0000000000..4562050f75
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/newaddresstab.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef NEWADDRESSTAB_H
+#define NEWADDRESSTAB_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QPushButton;
+class QVBoxLayout;
+QT_END_NAMESPACE
+
+//! [0]
+class NewAddressTab : public QWidget
+{
+ Q_OBJECT
+
+public:
+ NewAddressTab(QWidget *parent=0);
+
+public slots:
+ void addEntry();
+
+signals:
+ void sendDetails(QString name, QString address);
+
+private:
+ QLabel *descriptionLabel;
+ QPushButton *addButton;
+ QVBoxLayout *mainLayout;
+
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/addressbook/tablemodel.cpp b/examples/widgets/itemviews/addressbook/tablemodel.cpp
new file mode 100644
index 0000000000..6d99a02b55
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/tablemodel.cpp
@@ -0,0 +1,184 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tablemodel.h"
+
+//! [0]
+TableModel::TableModel(QObject *parent)
+ : QAbstractTableModel(parent)
+{
+}
+
+TableModel::TableModel(QList< QPair<QString, QString> > pairs, QObject *parent)
+ : QAbstractTableModel(parent)
+{
+ listOfPairs=pairs;
+}
+//! [0]
+
+//! [1]
+int TableModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ return listOfPairs.size();
+}
+
+int TableModel::columnCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ return 2;
+}
+//! [1]
+
+//! [2]
+QVariant TableModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.row() >= listOfPairs.size() || index.row() < 0)
+ return QVariant();
+
+ if (role == Qt::DisplayRole) {
+ QPair<QString, QString> pair = listOfPairs.at(index.row());
+
+ if (index.column() == 0)
+ return pair.first;
+ else if (index.column() == 1)
+ return pair.second;
+ }
+ return QVariant();
+}
+//! [2]
+
+//! [3]
+QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ if (orientation == Qt::Horizontal) {
+ switch (section) {
+ case 0:
+ return tr("Name");
+
+ case 1:
+ return tr("Address");
+
+ default:
+ return QVariant();
+ }
+ }
+ return QVariant();
+}
+//! [3]
+
+//! [4]
+bool TableModel::insertRows(int position, int rows, const QModelIndex &index)
+{
+ Q_UNUSED(index);
+ beginInsertRows(QModelIndex(), position, position+rows-1);
+
+ for (int row=0; row < rows; row++) {
+ QPair<QString, QString> pair(" ", " ");
+ listOfPairs.insert(position, pair);
+ }
+
+ endInsertRows();
+ return true;
+}
+//! [4]
+
+//! [5]
+bool TableModel::removeRows(int position, int rows, const QModelIndex &index)
+{
+ Q_UNUSED(index);
+ beginRemoveRows(QModelIndex(), position, position+rows-1);
+
+ for (int row=0; row < rows; ++row) {
+ listOfPairs.removeAt(position);
+ }
+
+ endRemoveRows();
+ return true;
+}
+//! [5]
+
+//! [6]
+bool TableModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ if (index.isValid() && role == Qt::EditRole) {
+ int row = index.row();
+
+ QPair<QString, QString> p = listOfPairs.value(row);
+
+ if (index.column() == 0)
+ p.first = value.toString();
+ else if (index.column() == 1)
+ p.second = value.toString();
+ else
+ return false;
+
+ listOfPairs.replace(row, p);
+ emit(dataChanged(index, index));
+
+ return true;
+ }
+
+ return false;
+}
+//! [6]
+
+//! [7]
+Qt::ItemFlags TableModel::flags(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return Qt::ItemIsEnabled;
+
+ return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
+}
+//! [7]
+
+//! [8]
+QList< QPair<QString, QString> > TableModel::getList()
+{
+ return listOfPairs;
+}
+//! [8]
diff --git a/examples/widgets/itemviews/addressbook/tablemodel.h b/examples/widgets/itemviews/addressbook/tablemodel.h
new file mode 100644
index 0000000000..bb21af587f
--- /dev/null
+++ b/examples/widgets/itemviews/addressbook/tablemodel.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TABLEMODEL_H
+#define TABLEMODEL_H
+
+#include <QAbstractTableModel>
+#include <QPair>
+#include <QList>
+
+//! [0]
+class TableModel : public QAbstractTableModel
+{
+ Q_OBJECT
+
+public:
+ TableModel(QObject *parent=0);
+ TableModel(QList< QPair<QString, QString> > listofPairs, QObject *parent=0);
+
+ int rowCount(const QModelIndex &parent) const;
+ int columnCount(const QModelIndex &parent) const;
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole);
+ bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex());
+ bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex());
+ QList< QPair<QString, QString> > getList();
+
+private:
+ QList< QPair<QString, QString> > listOfPairs;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.desktop b/examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.desktop
new file mode 100644
index 0000000000..22621f3ba5
--- /dev/null
+++ b/examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Basic Sort Filter Model
+Exec=/opt/usr/bin/basicsortfiltermodel
+Icon=basicsortfiltermodel
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro b/examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro
new file mode 100644
index 0000000000..75f96e4d48
--- /dev/null
+++ b/examples/widgets/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro
@@ -0,0 +1,12 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+CONFIG += qt
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/basicsortfiltermodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/basicsortfiltermodel
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/itemviews/basicsortfiltermodel/main.cpp b/examples/widgets/itemviews/basicsortfiltermodel/main.cpp
new file mode 100644
index 0000000000..00b733090a
--- /dev/null
+++ b/examples/widgets/itemviews/basicsortfiltermodel/main.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "window.h"
+
+void addMail(QAbstractItemModel *model, const QString &subject,
+ const QString &sender, const QDateTime &date)
+{
+ model->insertRow(0);
+ model->setData(model->index(0, 0), subject);
+ model->setData(model->index(0, 1), sender);
+ model->setData(model->index(0, 2), date);
+}
+
+QAbstractItemModel *createMailModel(QObject *parent)
+{
+ QStandardItemModel *model = new QStandardItemModel(0, 3, parent);
+
+ model->setHeaderData(0, Qt::Horizontal, QObject::tr("Subject"));
+ model->setHeaderData(1, Qt::Horizontal, QObject::tr("Sender"));
+ model->setHeaderData(2, Qt::Horizontal, QObject::tr("Date"));
+
+ addMail(model, "Happy New Year!", "Grace K. <grace@software-inc.com>",
+ QDateTime(QDate(2006, 12, 31), QTime(17, 03)));
+ addMail(model, "Radically new concept", "Grace K. <grace@software-inc.com>",
+ QDateTime(QDate(2006, 12, 22), QTime(9, 44)));
+ addMail(model, "Accounts", "pascale@nospam.com",
+ QDateTime(QDate(2006, 12, 31), QTime(12, 50)));
+ addMail(model, "Expenses", "Joe Bloggs <joe@bloggs.com>",
+ QDateTime(QDate(2006, 12, 25), QTime(11, 39)));
+ addMail(model, "Re: Expenses", "Andy <andy@nospam.com>",
+ QDateTime(QDate(2007, 01, 02), QTime(16, 05)));
+ addMail(model, "Re: Accounts", "Joe Bloggs <joe@bloggs.com>",
+ QDateTime(QDate(2007, 01, 03), QTime(14, 18)));
+ addMail(model, "Re: Accounts", "Andy <andy@nospam.com>",
+ QDateTime(QDate(2007, 01, 03), QTime(14, 26)));
+ addMail(model, "Sports", "Linda Smith <linda.smith@nospam.com>",
+ QDateTime(QDate(2007, 01, 05), QTime(11, 33)));
+ addMail(model, "AW: Sports", "Rolf Newschweinstein <rolfn@nospam.com>",
+ QDateTime(QDate(2007, 01, 05), QTime(12, 00)));
+ addMail(model, "RE: Sports", "Petra Schmidt <petras@nospam.com>",
+ QDateTime(QDate(2007, 01, 05), QTime(12, 01)));
+
+ return model;
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.setSourceModel(createMailModel(&window));
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/basicsortfiltermodel/window.cpp b/examples/widgets/itemviews/basicsortfiltermodel/window.cpp
new file mode 100644
index 0000000000..f7f43c1753
--- /dev/null
+++ b/examples/widgets/itemviews/basicsortfiltermodel/window.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "window.h"
+
+Window::Window()
+{
+ proxyModel = new QSortFilterProxyModel;
+
+ sourceView = new QTreeView;
+ sourceView->setRootIsDecorated(false);
+ sourceView->setAlternatingRowColors(true);
+
+ proxyView = new QTreeView;
+ proxyView->setRootIsDecorated(false);
+ proxyView->setAlternatingRowColors(true);
+ proxyView->setModel(proxyModel);
+ proxyView->setSortingEnabled(true);
+
+ sortCaseSensitivityCheckBox = new QCheckBox(tr("Case sensitive sorting"));
+ filterCaseSensitivityCheckBox = new QCheckBox(tr("Case sensitive filter"));
+
+ filterPatternLineEdit = new QLineEdit;
+ filterPatternLabel = new QLabel(tr("&Filter pattern:"));
+ filterPatternLabel->setBuddy(filterPatternLineEdit);
+
+ filterSyntaxComboBox = new QComboBox;
+ filterSyntaxComboBox->addItem(tr("Regular expression"), QRegExp::RegExp);
+ filterSyntaxComboBox->addItem(tr("Wildcard"), QRegExp::Wildcard);
+ filterSyntaxComboBox->addItem(tr("Fixed string"), QRegExp::FixedString);
+ filterSyntaxLabel = new QLabel(tr("Filter &syntax:"));
+ filterSyntaxLabel->setBuddy(filterSyntaxComboBox);
+
+ filterColumnComboBox = new QComboBox;
+ filterColumnComboBox->addItem(tr("Subject"));
+ filterColumnComboBox->addItem(tr("Sender"));
+ filterColumnComboBox->addItem(tr("Date"));
+ filterColumnLabel = new QLabel(tr("Filter &column:"));
+ filterColumnLabel->setBuddy(filterColumnComboBox);
+
+ connect(filterPatternLineEdit, SIGNAL(textChanged(QString)),
+ this, SLOT(filterRegExpChanged()));
+ connect(filterSyntaxComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(filterRegExpChanged()));
+ connect(filterColumnComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(filterColumnChanged()));
+ connect(filterCaseSensitivityCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(filterRegExpChanged()));
+ connect(sortCaseSensitivityCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(sortChanged()));
+
+ sourceGroupBox = new QGroupBox(tr("Original Model"));
+ proxyGroupBox = new QGroupBox(tr("Sorted/Filtered Model"));
+
+ QHBoxLayout *sourceLayout = new QHBoxLayout;
+ sourceLayout->addWidget(sourceView);
+ sourceGroupBox->setLayout(sourceLayout);
+
+ QGridLayout *proxyLayout = new QGridLayout;
+ proxyLayout->addWidget(proxyView, 0, 0, 1, 3);
+ proxyLayout->addWidget(filterPatternLabel, 1, 0);
+ proxyLayout->addWidget(filterPatternLineEdit, 1, 1, 1, 2);
+ proxyLayout->addWidget(filterSyntaxLabel, 2, 0);
+ proxyLayout->addWidget(filterSyntaxComboBox, 2, 1, 1, 2);
+ proxyLayout->addWidget(filterColumnLabel, 3, 0);
+ proxyLayout->addWidget(filterColumnComboBox, 3, 1, 1, 2);
+ proxyLayout->addWidget(filterCaseSensitivityCheckBox, 4, 0, 1, 2);
+ proxyLayout->addWidget(sortCaseSensitivityCheckBox, 4, 2);
+ proxyGroupBox->setLayout(proxyLayout);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+
+ mainLayout->addWidget(sourceGroupBox);
+ mainLayout->addWidget(proxyGroupBox);
+
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Basic Sort/Filter Model"));
+ resize(500, 450);
+
+ proxyView->sortByColumn(1, Qt::AscendingOrder);
+ filterColumnComboBox->setCurrentIndex(1);
+
+ filterPatternLineEdit->setText("Andy|Grace");
+ filterCaseSensitivityCheckBox->setChecked(true);
+ sortCaseSensitivityCheckBox->setChecked(true);
+}
+
+void Window::setSourceModel(QAbstractItemModel *model)
+{
+ proxyModel->setSourceModel(model);
+ sourceView->setModel(model);
+}
+
+void Window::filterRegExpChanged()
+{
+ QRegExp::PatternSyntax syntax =
+ QRegExp::PatternSyntax(filterSyntaxComboBox->itemData(
+ filterSyntaxComboBox->currentIndex()).toInt());
+ Qt::CaseSensitivity caseSensitivity =
+ filterCaseSensitivityCheckBox->isChecked() ? Qt::CaseSensitive
+ : Qt::CaseInsensitive;
+
+ QRegExp regExp(filterPatternLineEdit->text(), caseSensitivity, syntax);
+ proxyModel->setFilterRegExp(regExp);
+}
+
+void Window::filterColumnChanged()
+{
+ proxyModel->setFilterKeyColumn(filterColumnComboBox->currentIndex());
+}
+
+void Window::sortChanged()
+{
+ proxyModel->setSortCaseSensitivity(
+ sortCaseSensitivityCheckBox->isChecked() ? Qt::CaseSensitive
+ : Qt::CaseInsensitive);
+}
diff --git a/examples/widgets/itemviews/basicsortfiltermodel/window.h b/examples/widgets/itemviews/basicsortfiltermodel/window.h
new file mode 100644
index 0000000000..f672a3eb66
--- /dev/null
+++ b/examples/widgets/itemviews/basicsortfiltermodel/window.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QCheckBox;
+class QComboBox;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QSortFilterProxyModel;
+class QTreeView;
+QT_END_NAMESPACE
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+ void setSourceModel(QAbstractItemModel *model);
+
+private slots:
+ void filterRegExpChanged();
+ void filterColumnChanged();
+ void sortChanged();
+
+private:
+ QSortFilterProxyModel *proxyModel;
+
+ QGroupBox *sourceGroupBox;
+ QGroupBox *proxyGroupBox;
+ QTreeView *sourceView;
+ QTreeView *proxyView;
+ QCheckBox *filterCaseSensitivityCheckBox;
+ QCheckBox *sortCaseSensitivityCheckBox;
+ QLabel *filterPatternLabel;
+ QLabel *filterSyntaxLabel;
+ QLabel *filterColumnLabel;
+ QLineEdit *filterPatternLineEdit;
+ QComboBox *filterSyntaxComboBox;
+ QComboBox *filterColumnComboBox;
+};
+
+#endif
diff --git a/examples/widgets/itemviews/chart/chart.desktop b/examples/widgets/itemviews/chart/chart.desktop
new file mode 100644
index 0000000000..73e017baeb
--- /dev/null
+++ b/examples/widgets/itemviews/chart/chart.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Chart
+Exec=/opt/usr/bin/chart
+Icon=chart
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/chart/chart.pro b/examples/widgets/itemviews/chart/chart.pro
new file mode 100644
index 0000000000..310bb85ad7
--- /dev/null
+++ b/examples/widgets/itemviews/chart/chart.pro
@@ -0,0 +1,18 @@
+HEADERS = mainwindow.h \
+ pieview.h
+RESOURCES = chart.qrc
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ pieview.cpp
+unix:!mac:!vxworks:!integrity:LIBS+= -lm
+
+TARGET.EPOCHEAPSIZE = 0x200000 0x800000
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/chart
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.cht
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/chart
+INSTALLS += target sources
+
+QT += widgets
+
diff --git a/examples/widgets/itemviews/chart/chart.qrc b/examples/widgets/itemviews/chart/chart.qrc
new file mode 100644
index 0000000000..7401d4d2f8
--- /dev/null
+++ b/examples/widgets/itemviews/chart/chart.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/Charts" >
+ <file>qtdata.cht</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/itemviews/chart/main.cpp b/examples/widgets/itemviews/chart/main.cpp
new file mode 100644
index 0000000000..b1c13116c9
--- /dev/null
+++ b/examples/widgets/itemviews/chart/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(chart);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/chart/mainwindow.cpp b/examples/widgets/itemviews/chart/mainwindow.cpp
new file mode 100644
index 0000000000..584390252b
--- /dev/null
+++ b/examples/widgets/itemviews/chart/mainwindow.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "pieview.h"
+#include "mainwindow.h"
+
+MainWindow::MainWindow()
+{
+ QMenu *fileMenu = new QMenu(tr("&File"), this);
+ QAction *openAction = fileMenu->addAction(tr("&Open..."));
+ openAction->setShortcuts(QKeySequence::Open);
+ QAction *saveAction = fileMenu->addAction(tr("&Save As..."));
+ saveAction->setShortcuts(QKeySequence::SaveAs);
+ QAction *quitAction = fileMenu->addAction(tr("E&xit"));
+ quitAction->setShortcuts(QKeySequence::Quit);
+
+ setupModel();
+ setupViews();
+
+ connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
+ connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ menuBar()->addMenu(fileMenu);
+ statusBar();
+
+ openFile(":/Charts/qtdata.cht");
+
+ setWindowTitle(tr("Chart"));
+ resize(870, 550);
+}
+
+void MainWindow::setupModel()
+{
+ model = new QStandardItemModel(8, 2, this);
+ model->setHeaderData(0, Qt::Horizontal, tr("Label"));
+ model->setHeaderData(1, Qt::Horizontal, tr("Quantity"));
+}
+
+void MainWindow::setupViews()
+{
+ QSplitter *splitter = new QSplitter;
+ QTableView *table = new QTableView;
+ pieChart = new PieView;
+ splitter->addWidget(table);
+ splitter->addWidget(pieChart);
+ splitter->setStretchFactor(0, 0);
+ splitter->setStretchFactor(1, 1);
+
+ table->setModel(model);
+ pieChart->setModel(model);
+
+ QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
+ table->setSelectionModel(selectionModel);
+ pieChart->setSelectionModel(selectionModel);
+
+ QHeaderView *headerView = table->horizontalHeader();
+ headerView->setStretchLastSection(true);
+
+ setCentralWidget(splitter);
+}
+
+void MainWindow::openFile(const QString &path)
+{
+ QString fileName;
+ if (path.isNull())
+ fileName = QFileDialog::getOpenFileName(this, tr("Choose a data file"),
+ "", "*.cht");
+ else
+ fileName = path;
+
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+
+ if (file.open(QFile::ReadOnly | QFile::Text)) {
+ QTextStream stream(&file);
+ QString line;
+
+ model->removeRows(0, model->rowCount(QModelIndex()), QModelIndex());
+
+ int row = 0;
+ do {
+ line = stream.readLine();
+ if (!line.isEmpty()) {
+
+ model->insertRows(row, 1, QModelIndex());
+
+ QStringList pieces = line.split(",", QString::SkipEmptyParts);
+ model->setData(model->index(row, 0, QModelIndex()),
+ pieces.value(0));
+ model->setData(model->index(row, 1, QModelIndex()),
+ pieces.value(1));
+ model->setData(model->index(row, 0, QModelIndex()),
+ QColor(pieces.value(2)), Qt::DecorationRole);
+ row++;
+ }
+ } while (!line.isEmpty());
+
+ file.close();
+ statusBar()->showMessage(tr("Loaded %1").arg(fileName), 2000);
+ }
+ }
+}
+
+void MainWindow::saveFile()
+{
+ QString fileName = QFileDialog::getSaveFileName(this,
+ tr("Save file as"), "", "*.cht");
+
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+ QTextStream stream(&file);
+
+ if (file.open(QFile::WriteOnly | QFile::Text)) {
+ for (int row = 0; row < model->rowCount(QModelIndex()); ++row) {
+
+ QStringList pieces;
+
+ pieces.append(model->data(model->index(row, 0, QModelIndex()),
+ Qt::DisplayRole).toString());
+ pieces.append(model->data(model->index(row, 1, QModelIndex()),
+ Qt::DisplayRole).toString());
+ pieces.append(model->data(model->index(row, 0, QModelIndex()),
+ Qt::DecorationRole).toString());
+
+ stream << pieces.join(",") << "\n";
+ }
+ }
+
+ file.close();
+ statusBar()->showMessage(tr("Saved %1").arg(fileName), 2000);
+ }
+}
diff --git a/examples/widgets/itemviews/chart/mainwindow.h b/examples/widgets/itemviews/chart/mainwindow.h
new file mode 100644
index 0000000000..5ce4f30e32
--- /dev/null
+++ b/examples/widgets/itemviews/chart/mainwindow.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QAbstractItemView;
+class QItemSelectionModel;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void openFile(const QString &path = QString());
+ void saveFile();
+
+private:
+ void setupModel();
+ void setupViews();
+
+ QAbstractItemModel *model;
+ QAbstractItemView *pieChart;
+ QItemSelectionModel *selectionModel;
+};
+
+#endif
diff --git a/examples/widgets/itemviews/chart/mydata.cht b/examples/widgets/itemviews/chart/mydata.cht
new file mode 100644
index 0000000000..029fd81458
--- /dev/null
+++ b/examples/widgets/itemviews/chart/mydata.cht
@@ -0,0 +1,8 @@
+London,4,red
+Stockholm,5,pink
+Paris,2,lightgreen
+Rome,11,green
+Lisbon,9,blue
+Madrid,8,lightblue
+Berlin,6,magenta
+Vienna,7,purple
diff --git a/examples/widgets/itemviews/chart/pieview.cpp b/examples/widgets/itemviews/chart/pieview.cpp
new file mode 100644
index 0000000000..30f3255689
--- /dev/null
+++ b/examples/widgets/itemviews/chart/pieview.cpp
@@ -0,0 +1,557 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <math.h>
+#include <QtWidgets>
+
+#ifndef M_PI
+#define M_PI 3.1415927
+#endif
+
+#include "pieview.h"
+
+PieView::PieView(QWidget *parent)
+ : QAbstractItemView(parent)
+{
+ horizontalScrollBar()->setRange(0, 0);
+ verticalScrollBar()->setRange(0, 0);
+
+ margin = 8;
+ totalSize = 300;
+ pieSize = totalSize - 2*margin;
+ validItems = 0;
+ totalValue = 0.0;
+ rubberBand = 0;
+}
+
+void PieView::dataChanged(const QModelIndex &topLeft,
+ const QModelIndex &bottomRight,
+ const QVector<int> &)
+{
+ QAbstractItemView::dataChanged(topLeft, bottomRight);
+
+ validItems = 0;
+ totalValue = 0.0;
+
+ for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
+
+ QModelIndex index = model()->index(row, 1, rootIndex());
+ double value = model()->data(index).toDouble();
+
+ if (value > 0.0) {
+ totalValue += value;
+ validItems++;
+ }
+ }
+ viewport()->update();
+}
+
+bool PieView::edit(const QModelIndex &index, EditTrigger trigger, QEvent *event)
+{
+ if (index.column() == 0)
+ return QAbstractItemView::edit(index, trigger, event);
+ else
+ return false;
+}
+
+/*
+ Returns the item that covers the coordinate given in the view.
+*/
+
+QModelIndex PieView::indexAt(const QPoint &point) const
+{
+ if (validItems == 0)
+ return QModelIndex();
+
+ // Transform the view coordinates into contents widget coordinates.
+ int wx = point.x() + horizontalScrollBar()->value();
+ int wy = point.y() + verticalScrollBar()->value();
+
+ if (wx < totalSize) {
+ double cx = wx - totalSize/2;
+ double cy = totalSize/2 - wy; // positive cy for items above the center
+
+ // Determine the distance from the center point of the pie chart.
+ double d = pow(pow(cx, 2) + pow(cy, 2), 0.5);
+
+ if (d == 0 || d > pieSize/2)
+ return QModelIndex();
+
+ // Determine the angle of the point.
+ double angle = (180 / M_PI) * acos(cx/d);
+ if (cy < 0)
+ angle = 360 - angle;
+
+ // Find the relevant slice of the pie.
+ double startAngle = 0.0;
+
+ for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
+
+ QModelIndex index = model()->index(row, 1, rootIndex());
+ double value = model()->data(index).toDouble();
+
+ if (value > 0.0) {
+ double sliceAngle = 360*value/totalValue;
+
+ if (angle >= startAngle && angle < (startAngle + sliceAngle))
+ return model()->index(row, 1, rootIndex());
+
+ startAngle += sliceAngle;
+ }
+ }
+ } else {
+ double itemHeight = QFontMetrics(viewOptions().font).height();
+ int listItem = int((wy - margin) / itemHeight);
+ int validRow = 0;
+
+ for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
+
+ QModelIndex index = model()->index(row, 1, rootIndex());
+ if (model()->data(index).toDouble() > 0.0) {
+
+ if (listItem == validRow)
+ return model()->index(row, 0, rootIndex());
+
+ // Update the list index that corresponds to the next valid row.
+ validRow++;
+ }
+ }
+ }
+
+ return QModelIndex();
+}
+
+bool PieView::isIndexHidden(const QModelIndex & /*index*/) const
+{
+ return false;
+}
+
+/*
+ Returns the rectangle of the item at position \a index in the
+ model. The rectangle is in contents coordinates.
+*/
+
+QRect PieView::itemRect(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return QRect();
+
+ // Check whether the index's row is in the list of rows represented
+ // by slices.
+ QModelIndex valueIndex;
+
+ if (index.column() != 1)
+ valueIndex = model()->index(index.row(), 1, rootIndex());
+ else
+ valueIndex = index;
+
+ if (model()->data(valueIndex).toDouble() > 0.0) {
+
+ int listItem = 0;
+ for (int row = index.row()-1; row >= 0; --row) {
+ if (model()->data(model()->index(row, 1, rootIndex())).toDouble() > 0.0)
+ listItem++;
+ }
+
+ double itemHeight;
+
+ switch (index.column()) {
+ case 0:
+ itemHeight = QFontMetrics(viewOptions().font).height();
+
+ return QRect(totalSize,
+ int(margin + listItem*itemHeight),
+ totalSize - margin, int(itemHeight));
+ case 1:
+ return viewport()->rect();
+ }
+
+ }
+ return QRect();
+}
+
+QRegion PieView::itemRegion(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return QRegion();
+
+ if (index.column() != 1)
+ return itemRect(index);
+
+ if (model()->data(index).toDouble() <= 0.0)
+ return QRegion();
+
+ double startAngle = 0.0;
+ for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
+
+ QModelIndex sliceIndex = model()->index(row, 1, rootIndex());
+ double value = model()->data(sliceIndex).toDouble();
+
+ if (value > 0.0) {
+ double angle = 360*value/totalValue;
+
+ if (sliceIndex == index) {
+ QPainterPath slicePath;
+ slicePath.moveTo(totalSize/2, totalSize/2);
+ slicePath.arcTo(margin, margin, margin+pieSize, margin+pieSize,
+ startAngle, angle);
+ slicePath.closeSubpath();
+
+ return QRegion(slicePath.toFillPolygon().toPolygon());
+ }
+
+ startAngle += angle;
+ }
+ }
+
+ return QRegion();
+}
+
+int PieView::horizontalOffset() const
+{
+ return horizontalScrollBar()->value();
+}
+
+void PieView::mousePressEvent(QMouseEvent *event)
+{
+ QAbstractItemView::mousePressEvent(event);
+ origin = event->pos();
+ if (!rubberBand)
+ rubberBand = new QRubberBand(QRubberBand::Rectangle, viewport());
+ rubberBand->setGeometry(QRect(origin, QSize()));
+ rubberBand->show();
+}
+
+void PieView::mouseMoveEvent(QMouseEvent *event)
+{
+ if (rubberBand)
+ rubberBand->setGeometry(QRect(origin, event->pos()).normalized());
+ QAbstractItemView::mouseMoveEvent(event);
+}
+
+void PieView::mouseReleaseEvent(QMouseEvent *event)
+{
+ QAbstractItemView::mouseReleaseEvent(event);
+ if (rubberBand)
+ rubberBand->hide();
+ viewport()->update();
+}
+
+QModelIndex PieView::moveCursor(QAbstractItemView::CursorAction cursorAction,
+ Qt::KeyboardModifiers /*modifiers*/)
+{
+ QModelIndex current = currentIndex();
+
+ switch (cursorAction) {
+ case MoveLeft:
+ case MoveUp:
+ if (current.row() > 0)
+ current = model()->index(current.row() - 1, current.column(),
+ rootIndex());
+ else
+ current = model()->index(0, current.column(), rootIndex());
+ break;
+ case MoveRight:
+ case MoveDown:
+ if (current.row() < rows(current) - 1)
+ current = model()->index(current.row() + 1, current.column(),
+ rootIndex());
+ else
+ current = model()->index(rows(current) - 1, current.column(),
+ rootIndex());
+ break;
+ default:
+ break;
+ }
+
+ viewport()->update();
+ return current;
+}
+
+void PieView::paintEvent(QPaintEvent *event)
+{
+ QItemSelectionModel *selections = selectionModel();
+ QStyleOptionViewItem option = viewOptions();
+
+ QBrush background = option.palette.base();
+ QPen foreground(option.palette.color(QPalette::WindowText));
+
+ QPainter painter(viewport());
+ painter.setRenderHint(QPainter::Antialiasing);
+
+ painter.fillRect(event->rect(), background);
+ painter.setPen(foreground);
+
+ // Viewport rectangles
+ QRect pieRect = QRect(margin, margin, pieSize, pieSize);
+
+ if (validItems > 0) {
+
+ painter.save();
+ painter.translate(pieRect.x() - horizontalScrollBar()->value(),
+ pieRect.y() - verticalScrollBar()->value());
+ painter.drawEllipse(0, 0, pieSize, pieSize);
+ double startAngle = 0.0;
+ int row;
+
+ for (row = 0; row < model()->rowCount(rootIndex()); ++row) {
+
+ QModelIndex index = model()->index(row, 1, rootIndex());
+ double value = model()->data(index).toDouble();
+
+ if (value > 0.0) {
+ double angle = 360*value/totalValue;
+
+ QModelIndex colorIndex = model()->index(row, 0, rootIndex());
+ QColor color = QColor(model()->data(colorIndex,
+ Qt::DecorationRole).toString());
+
+ if (currentIndex() == index)
+ painter.setBrush(QBrush(color, Qt::Dense4Pattern));
+ else if (selections->isSelected(index))
+ painter.setBrush(QBrush(color, Qt::Dense3Pattern));
+ else
+ painter.setBrush(QBrush(color));
+
+ painter.drawPie(0, 0, pieSize, pieSize, int(startAngle*16),
+ int(angle*16));
+
+ startAngle += angle;
+ }
+ }
+ painter.restore();
+
+ int keyNumber = 0;
+
+ for (row = 0; row < model()->rowCount(rootIndex()); ++row) {
+
+ QModelIndex index = model()->index(row, 1, rootIndex());
+ double value = model()->data(index).toDouble();
+
+ if (value > 0.0) {
+ QModelIndex labelIndex = model()->index(row, 0, rootIndex());
+
+ QStyleOptionViewItem option = viewOptions();
+ option.rect = visualRect(labelIndex);
+ if (selections->isSelected(labelIndex))
+ option.state |= QStyle::State_Selected;
+ if (currentIndex() == labelIndex)
+ option.state |= QStyle::State_HasFocus;
+ itemDelegate()->paint(&painter, option, labelIndex);
+
+ keyNumber++;
+ }
+ }
+ }
+}
+
+void PieView::resizeEvent(QResizeEvent * /* event */)
+{
+ updateGeometries();
+}
+
+int PieView::rows(const QModelIndex &index) const
+{
+ return model()->rowCount(model()->parent(index));
+}
+
+void PieView::rowsInserted(const QModelIndex &parent, int start, int end)
+{
+ for (int row = start; row <= end; ++row) {
+
+ QModelIndex index = model()->index(row, 1, rootIndex());
+ double value = model()->data(index).toDouble();
+
+ if (value > 0.0) {
+ totalValue += value;
+ validItems++;
+ }
+ }
+
+ QAbstractItemView::rowsInserted(parent, start, end);
+}
+
+void PieView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
+{
+ for (int row = start; row <= end; ++row) {
+
+ QModelIndex index = model()->index(row, 1, rootIndex());
+ double value = model()->data(index).toDouble();
+ if (value > 0.0) {
+ totalValue -= value;
+ validItems--;
+ }
+ }
+
+ QAbstractItemView::rowsAboutToBeRemoved(parent, start, end);
+}
+
+void PieView::scrollContentsBy(int dx, int dy)
+{
+ viewport()->scroll(dx, dy);
+}
+
+void PieView::scrollTo(const QModelIndex &index, ScrollHint)
+{
+ QRect area = viewport()->rect();
+ QRect rect = visualRect(index);
+
+ if (rect.left() < area.left())
+ horizontalScrollBar()->setValue(
+ horizontalScrollBar()->value() + rect.left() - area.left());
+ else if (rect.right() > area.right())
+ horizontalScrollBar()->setValue(
+ horizontalScrollBar()->value() + qMin(
+ rect.right() - area.right(), rect.left() - area.left()));
+
+ if (rect.top() < area.top())
+ verticalScrollBar()->setValue(
+ verticalScrollBar()->value() + rect.top() - area.top());
+ else if (rect.bottom() > area.bottom())
+ verticalScrollBar()->setValue(
+ verticalScrollBar()->value() + qMin(
+ rect.bottom() - area.bottom(), rect.top() - area.top()));
+
+ update();
+}
+
+/*
+ Find the indices corresponding to the extent of the selection.
+*/
+
+void PieView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
+{
+ // Use content widget coordinates because we will use the itemRegion()
+ // function to check for intersections.
+
+ QRect contentsRect = rect.translated(
+ horizontalScrollBar()->value(),
+ verticalScrollBar()->value()).normalized();
+
+ int rows = model()->rowCount(rootIndex());
+ int columns = model()->columnCount(rootIndex());
+ QModelIndexList indexes;
+
+ for (int row = 0; row < rows; ++row) {
+ for (int column = 0; column < columns; ++column) {
+ QModelIndex index = model()->index(row, column, rootIndex());
+ QRegion region = itemRegion(index);
+ if (region.intersects(contentsRect))
+ indexes.append(index);
+ }
+ }
+
+ if (indexes.size() > 0) {
+ int firstRow = indexes[0].row();
+ int lastRow = indexes[0].row();
+ int firstColumn = indexes[0].column();
+ int lastColumn = indexes[0].column();
+
+ for (int i = 1; i < indexes.size(); ++i) {
+ firstRow = qMin(firstRow, indexes[i].row());
+ lastRow = qMax(lastRow, indexes[i].row());
+ firstColumn = qMin(firstColumn, indexes[i].column());
+ lastColumn = qMax(lastColumn, indexes[i].column());
+ }
+
+ QItemSelection selection(
+ model()->index(firstRow, firstColumn, rootIndex()),
+ model()->index(lastRow, lastColumn, rootIndex()));
+ selectionModel()->select(selection, command);
+ } else {
+ QModelIndex noIndex;
+ QItemSelection selection(noIndex, noIndex);
+ selectionModel()->select(selection, command);
+ }
+
+ update();
+}
+
+void PieView::updateGeometries()
+{
+ horizontalScrollBar()->setPageStep(viewport()->width());
+ horizontalScrollBar()->setRange(0, qMax(0, 2*totalSize - viewport()->width()));
+ verticalScrollBar()->setPageStep(viewport()->height());
+ verticalScrollBar()->setRange(0, qMax(0, totalSize - viewport()->height()));
+}
+
+int PieView::verticalOffset() const
+{
+ return verticalScrollBar()->value();
+}
+
+/*
+ Returns the position of the item in viewport coordinates.
+*/
+
+QRect PieView::visualRect(const QModelIndex &index) const
+{
+ QRect rect = itemRect(index);
+ if (rect.isValid())
+ return QRect(rect.left() - horizontalScrollBar()->value(),
+ rect.top() - verticalScrollBar()->value(),
+ rect.width(), rect.height());
+ else
+ return rect;
+}
+
+/*
+ Returns a region corresponding to the selection in viewport coordinates.
+*/
+
+QRegion PieView::visualRegionForSelection(const QItemSelection &selection) const
+{
+ int ranges = selection.count();
+
+ if (ranges == 0)
+ return QRect();
+
+ QRegion region;
+ for (int i = 0; i < ranges; ++i) {
+ QItemSelectionRange range = selection.at(i);
+ for (int row = range.top(); row <= range.bottom(); ++row) {
+ for (int col = range.left(); col <= range.right(); ++col) {
+ QModelIndex index = model()->index(row, col, rootIndex());
+ region += visualRect(index);
+ }
+ }
+ }
+ return region;
+}
diff --git a/examples/widgets/itemviews/chart/pieview.h b/examples/widgets/itemviews/chart/pieview.h
new file mode 100644
index 0000000000..208159bf73
--- /dev/null
+++ b/examples/widgets/itemviews/chart/pieview.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PIEVIEW_H
+#define PIEVIEW_H
+
+#include <QAbstractItemView>
+#include <QFont>
+#include <QItemSelection>
+#include <QItemSelectionModel>
+#include <QModelIndex>
+#include <QRect>
+#include <QSize>
+#include <QPoint>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QRubberBand;
+QT_END_NAMESPACE
+
+//! [0]
+class PieView : public QAbstractItemView
+{
+ Q_OBJECT
+
+public:
+ PieView(QWidget *parent = 0);
+
+ QRect visualRect(const QModelIndex &index) const;
+ void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
+ QModelIndex indexAt(const QPoint &point) const;
+
+protected slots:
+ void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> & = QVector<int>());
+ void rowsInserted(const QModelIndex &parent, int start, int end);
+ void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
+
+protected:
+ bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event);
+ QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction,
+ Qt::KeyboardModifiers modifiers);
+
+ int horizontalOffset() const;
+ int verticalOffset() const;
+
+ bool isIndexHidden(const QModelIndex &index) const;
+
+ void setSelection(const QRect&, QItemSelectionModel::SelectionFlags command);
+
+ void mousePressEvent(QMouseEvent *event);
+
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+ void scrollContentsBy(int dx, int dy);
+
+ QRegion visualRegionForSelection(const QItemSelection &selection) const;
+
+private:
+ QRect itemRect(const QModelIndex &item) const;
+ QRegion itemRegion(const QModelIndex &index) const;
+ int rows(const QModelIndex &index = QModelIndex()) const;
+ void updateGeometries();
+
+ int margin;
+ int totalSize;
+ int pieSize;
+ int validItems;
+ double totalValue;
+ QPoint origin;
+ QRubberBand *rubberBand;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/chart/qtdata.cht b/examples/widgets/itemviews/chart/qtdata.cht
new file mode 100644
index 0000000000..6386246c4b
--- /dev/null
+++ b/examples/widgets/itemviews/chart/qtdata.cht
@@ -0,0 +1,14 @@
+Scientific Research,21,#99e600
+Engineering & Design,18,#99cc00
+Automotive,14,#99b300
+Aerospace,13,#9f991a
+Automation & Machine Tools,13,#a48033
+Medical & Bioinformatics,13,#a9664d
+Imaging & Special Effects,12,#ae4d66
+Defense,11,#b33380
+Test & Measurement Systems,9,#a64086
+Oil & Gas,9,#994d8d
+Entertainment & Broadcasting,7,#8d5a93
+Financial,6,#806699
+Consumer Electronics,4,#8073a6
+Other,38,#8080b3
diff --git a/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.desktop b/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.desktop
new file mode 100644
index 0000000000..70b966445c
--- /dev/null
+++ b/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Color Editor Factory
+Exec=/opt/usr/bin/coloreditorfactory
+Icon=coloreditorfactory
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro b/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro
new file mode 100644
index 0000000000..07e1296e06
--- /dev/null
+++ b/examples/widgets/itemviews/coloreditorfactory/coloreditorfactory.pro
@@ -0,0 +1,14 @@
+HEADERS = colorlisteditor.h \
+ window.h
+SOURCES = colorlisteditor.cpp \
+ window.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/coloreditorfactory
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/coloreditorfactory
+INSTALLS += target sources
+
+QT += widgets
+
diff --git a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp
new file mode 100644
index 0000000000..e8f1f2d719
--- /dev/null
+++ b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "colorlisteditor.h"
+
+ColorListEditor::ColorListEditor(QWidget *widget) : QComboBox(widget)
+{
+ populateList();
+}
+
+//! [0]
+QColor ColorListEditor::color() const
+{
+ return qvariant_cast<QColor>(itemData(currentIndex(), Qt::DecorationRole));
+}
+//! [0]
+
+//! [1]
+void ColorListEditor::setColor(QColor color)
+{
+ setCurrentIndex(findData(color, int(Qt::DecorationRole)));
+}
+//! [1]
+
+//! [2]
+void ColorListEditor::populateList()
+{
+ QStringList colorNames = QColor::colorNames();
+
+ for (int i = 0; i < colorNames.size(); ++i) {
+ QColor color(colorNames[i]);
+
+ insertItem(i, colorNames[i]);
+ setItemData(i, color, Qt::DecorationRole);
+ }
+}
+//! [2]
diff --git a/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h
new file mode 100644
index 0000000000..13ece8ef6d
--- /dev/null
+++ b/examples/widgets/itemviews/coloreditorfactory/colorlisteditor.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COLORLISTEDITOR_H
+#define COLORLISTEDITOR_H
+
+#include <QComboBox>
+
+QT_BEGIN_NAMESPACE
+class QColor;
+class QWidget;
+QT_END_NAMESPACE
+
+//! [0]
+class ColorListEditor : public QComboBox
+{
+ Q_OBJECT
+ Q_PROPERTY(QColor color READ color WRITE setColor USER true)
+
+public:
+ ColorListEditor(QWidget *widget = 0);
+
+public:
+ QColor color() const;
+ void setColor(QColor c);
+
+private:
+ void populateList();
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/coloreditorfactory/main.cpp b/examples/widgets/itemviews/coloreditorfactory/main.cpp
new file mode 100644
index 0000000000..5bbe817214
--- /dev/null
+++ b/examples/widgets/itemviews/coloreditorfactory/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "window.h"
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ Window window;
+ window.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/coloreditorfactory/window.cpp b/examples/widgets/itemviews/coloreditorfactory/window.cpp
new file mode 100644
index 0000000000..5c1b03ebbe
--- /dev/null
+++ b/examples/widgets/itemviews/coloreditorfactory/window.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "window.h"
+#include "colorlisteditor.h"
+
+//! [0]
+Window::Window()
+{
+ QItemEditorFactory *factory = new QItemEditorFactory;
+
+ QItemEditorCreatorBase *colorListCreator =
+ new QStandardItemEditorCreator<ColorListEditor>();
+
+ factory->registerEditor(QVariant::Color, colorListCreator);
+
+ QItemEditorFactory::setDefaultFactory(factory);
+
+ createGUI();
+}
+//! [0]
+
+void Window::createGUI()
+{
+ QList<QPair<QString, QColor> > list;
+ list << QPair<QString, QColor>(tr("Alice"), QColor("aliceblue")) <<
+ QPair<QString, QColor>(tr("Neptun"), QColor("aquamarine")) <<
+ QPair<QString, QColor>(tr("Ferdinand"), QColor("springgreen"));
+
+ QTableWidget *table = new QTableWidget(3, 2);
+ table->setHorizontalHeaderLabels(QStringList() << tr("Name")
+ << tr("Hair Color"));
+ table->verticalHeader()->setVisible(false);
+ table->resize(150, 50);
+
+ for (int i = 0; i < 3; ++i) {
+ QPair<QString, QColor> pair = list.at(i);
+
+ QTableWidgetItem *nameItem = new QTableWidgetItem(pair.first);
+ QTableWidgetItem *colorItem = new QTableWidgetItem;
+ colorItem->setData(Qt::DisplayRole, pair.second);
+
+ table->setItem(i, 0, nameItem);
+ table->setItem(i, 1, colorItem);
+ }
+ table->resizeColumnToContents(0);
+ table->horizontalHeader()->setStretchLastSection(true);
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(table, 0, 0);
+
+ setLayout(layout);
+
+ setWindowTitle(tr("Color Editor Factory"));
+}
diff --git a/examples/widgets/itemviews/coloreditorfactory/window.h b/examples/widgets/itemviews/coloreditorfactory/window.h
new file mode 100644
index 0000000000..65a9c8e854
--- /dev/null
+++ b/examples/widgets/itemviews/coloreditorfactory/window.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private:
+ void createGUI();
+};
+
+#endif
diff --git a/examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.desktop b/examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.desktop
new file mode 100644
index 0000000000..3bbf6ad5f3
--- /dev/null
+++ b/examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Combo Widget Mapper
+Exec=/opt/usr/bin/combowidgetmapper
+Icon=combowidgetmapper
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.pro b/examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.pro
new file mode 100644
index 0000000000..9ea1fa0e25
--- /dev/null
+++ b/examples/widgets/itemviews/combowidgetmapper/combowidgetmapper.pro
@@ -0,0 +1,11 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/combowidgetmapper
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/combowidgetmapper
+INSTALLS += target sources
+QT += widgets
+
diff --git a/examples/widgets/itemviews/combowidgetmapper/main.cpp b/examples/widgets/itemviews/combowidgetmapper/main.cpp
new file mode 100644
index 0000000000..0fc4966ccf
--- /dev/null
+++ b/examples/widgets/itemviews/combowidgetmapper/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/combowidgetmapper/window.cpp b/examples/widgets/itemviews/combowidgetmapper/window.cpp
new file mode 100644
index 0000000000..8c735c04c5
--- /dev/null
+++ b/examples/widgets/itemviews/combowidgetmapper/window.cpp
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include "window.h"
+
+//! [Set up widgets]
+Window::Window(QWidget *parent)
+ : QWidget(parent)
+{
+ setupModel();
+
+ nameLabel = new QLabel(tr("Na&me:"));
+ nameEdit = new QLineEdit();
+ addressLabel = new QLabel(tr("&Address:"));
+ addressEdit = new QTextEdit();
+ typeLabel = new QLabel(tr("&Type:"));
+ typeComboBox = new QComboBox();
+ nextButton = new QPushButton(tr("&Next"));
+ previousButton = new QPushButton(tr("&Previous"));
+
+ nameLabel->setBuddy(nameEdit);
+ addressLabel->setBuddy(addressEdit);
+ typeLabel->setBuddy(typeComboBox);
+
+ typeComboBox->setModel(typeModel);
+//! [Set up widgets]
+
+//! [Set up the mapper]
+ mapper = new QDataWidgetMapper(this);
+ mapper->setModel(model);
+ mapper->addMapping(nameEdit, 0);
+ mapper->addMapping(addressEdit, 1);
+ mapper->addMapping(typeComboBox, 2, "currentIndex");
+//! [Set up the mapper]
+
+//! [Set up connections and layouts]
+ connect(previousButton, SIGNAL(clicked()),
+ mapper, SLOT(toPrevious()));
+ connect(nextButton, SIGNAL(clicked()),
+ mapper, SLOT(toNext()));
+ connect(mapper, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(updateButtons(int)));
+
+ QGridLayout *layout = new QGridLayout();
+ layout->addWidget(nameLabel, 0, 0, 1, 1);
+ layout->addWidget(nameEdit, 0, 1, 1, 1);
+ layout->addWidget(previousButton, 0, 2, 1, 1);
+ layout->addWidget(addressLabel, 1, 0, 1, 1);
+ layout->addWidget(addressEdit, 1, 1, 2, 1);
+ layout->addWidget(nextButton, 1, 2, 1, 1);
+ layout->addWidget(typeLabel, 3, 0, 1, 1);
+ layout->addWidget(typeComboBox, 3, 1, 1, 1);
+ setLayout(layout);
+
+ setWindowTitle(tr("Delegate Widget Mapper"));
+ mapper->toFirst();
+}
+//! [Set up connections and layouts]
+
+//! [Set up the model]
+void Window::setupModel()
+{
+ QStringList items;
+ items << tr("Home") << tr("Work") << tr("Other");
+ typeModel = new QStringListModel(items, this);
+
+ model = new QStandardItemModel(5, 3, this);
+ QStringList names;
+ names << "Alice" << "Bob" << "Carol" << "Donald" << "Emma";
+ QStringList addresses;
+ addresses << "<qt>123 Main Street<br/>Market Town</qt>"
+ << "<qt>PO Box 32<br/>Mail Handling Service"
+ "<br/>Service City</qt>"
+ << "<qt>The Lighthouse<br/>Remote Island</qt>"
+ << "<qt>47338 Park Avenue<br/>Big City</qt>"
+ << "<qt>Research Station<br/>Base Camp<br/>Big Mountain</qt>";
+
+ QStringList types;
+ types << "0" << "1" << "2" << "0" << "2";
+
+ for (int row = 0; row < 5; ++row) {
+ QStandardItem *item = new QStandardItem(names[row]);
+ model->setItem(row, 0, item);
+ item = new QStandardItem(addresses[row]);
+ model->setItem(row, 1, item);
+ item = new QStandardItem(types[row]);
+ model->setItem(row, 2, item);
+ }
+}
+//! [Set up the model]
+
+//! [Slot for updating the buttons]
+void Window::updateButtons(int row)
+{
+ previousButton->setEnabled(row > 0);
+ nextButton->setEnabled(row < model->rowCount() - 1);
+}
+//! [Slot for updating the buttons]
diff --git a/examples/widgets/itemviews/combowidgetmapper/window.h b/examples/widgets/itemviews/combowidgetmapper/window.h
new file mode 100644
index 0000000000..8ec5523cf1
--- /dev/null
+++ b/examples/widgets/itemviews/combowidgetmapper/window.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QDataWidgetMapper;
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QStandardItemModel;
+class QStringListModel;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [Window definition]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window(QWidget *parent = 0);
+
+private slots:
+ void updateButtons(int row);
+
+private:
+ void setupModel();
+
+ QLabel *nameLabel;
+ QLabel *addressLabel;
+ QLabel *typeLabel;
+ QLineEdit *nameEdit;
+ QTextEdit *addressEdit;
+ QComboBox *typeComboBox;
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+
+ QStandardItemModel *model;
+ QStringListModel *typeModel;
+ QDataWidgetMapper *mapper;
+};
+//! [Window definition]
+
+#endif
diff --git a/examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.desktop b/examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.desktop
new file mode 100644
index 0000000000..3c961f7e65
--- /dev/null
+++ b/examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Custom Sort Filter Model
+Exec=/opt/usr/bin/customsortfiltermodel
+Icon=customsortfiltermodel
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.pro b/examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.pro
new file mode 100644
index 0000000000..a2288b953c
--- /dev/null
+++ b/examples/widgets/itemviews/customsortfiltermodel/customsortfiltermodel.pro
@@ -0,0 +1,14 @@
+HEADERS = mysortfilterproxymodel.h \
+ window.h
+SOURCES = main.cpp \
+ mysortfilterproxymodel.cpp \
+ window.cpp
+CONFIG += qt
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/customsortfiltermodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/customsortfiltermodel
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/itemviews/customsortfiltermodel/main.cpp b/examples/widgets/itemviews/customsortfiltermodel/main.cpp
new file mode 100644
index 0000000000..6df986324e
--- /dev/null
+++ b/examples/widgets/itemviews/customsortfiltermodel/main.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "window.h"
+
+void addMail(QAbstractItemModel *model, const QString &subject,
+ const QString &sender, const QDateTime &date)
+{
+ model->insertRow(0);
+ model->setData(model->index(0, 0), subject);
+ model->setData(model->index(0, 1), sender);
+ model->setData(model->index(0, 2), date);
+}
+
+QAbstractItemModel *createMailModel(QObject *parent)
+{
+ QStandardItemModel *model = new QStandardItemModel(0, 3, parent);
+
+ model->setHeaderData(0, Qt::Horizontal, QObject::tr("Subject"));
+ model->setHeaderData(1, Qt::Horizontal, QObject::tr("Sender"));
+ model->setHeaderData(2, Qt::Horizontal, QObject::tr("Date"));
+
+ addMail(model, "Happy New Year!", "Grace K. <grace@software-inc.com>",
+ QDateTime(QDate(2006, 12, 31), QTime(17, 03)));
+ addMail(model, "Radically new concept", "Grace K. <grace@software-inc.com>",
+ QDateTime(QDate(2006, 12, 22), QTime(9, 44)));
+ addMail(model, "Accounts", "pascale@nospam.com",
+ QDateTime(QDate(2006, 12, 31), QTime(12, 50)));
+ addMail(model, "Expenses", "Joe Bloggs <joe@bloggs.com>",
+ QDateTime(QDate(2006, 12, 25), QTime(11, 39)));
+ addMail(model, "Re: Expenses", "Andy <andy@nospam.com>",
+ QDateTime(QDate(2007, 01, 02), QTime(16, 05)));
+ addMail(model, "Re: Accounts", "Joe Bloggs <joe@bloggs.com>",
+ QDateTime(QDate(2007, 01, 03), QTime(14, 18)));
+ addMail(model, "Re: Accounts", "Andy <andy@nospam.com>",
+ QDateTime(QDate(2007, 01, 03), QTime(14, 26)));
+ addMail(model, "Sports", "Linda Smith <linda.smith@nospam.com>",
+ QDateTime(QDate(2007, 01, 05), QTime(11, 33)));
+ addMail(model, "AW: Sports", "Rolf Newschweinstein <rolfn@nospam.com>",
+ QDateTime(QDate(2007, 01, 05), QTime(12, 00)));
+ addMail(model, "RE: Sports", "Petra Schmidt <petras@nospam.com>",
+ QDateTime(QDate(2007, 01, 05), QTime(12, 01)));
+
+ return model;
+}
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.setSourceModel(createMailModel(&window));
+ window.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
new file mode 100644
index 0000000000..3100efa4ac
--- /dev/null
+++ b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mysortfilterproxymodel.h"
+
+//! [0]
+MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
+ : QSortFilterProxyModel(parent)
+{
+}
+//! [0]
+
+//! [1]
+void MySortFilterProxyModel::setFilterMinimumDate(const QDate &date)
+{
+ minDate = date;
+ invalidateFilter();
+}
+//! [1]
+
+//! [2]
+void MySortFilterProxyModel::setFilterMaximumDate(const QDate &date)
+{
+ maxDate = date;
+ invalidateFilter();
+}
+//! [2]
+
+//! [3]
+bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
+ const QModelIndex &sourceParent) const
+{
+ QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
+ QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
+ QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
+
+ return (sourceModel()->data(index0).toString().contains(filterRegExp())
+ || sourceModel()->data(index1).toString().contains(filterRegExp()))
+ && dateInRange(sourceModel()->data(index2).toDate());
+}
+//! [3]
+
+//! [4] //! [5]
+bool MySortFilterProxyModel::lessThan(const QModelIndex &left,
+ const QModelIndex &right) const
+{
+ QVariant leftData = sourceModel()->data(left);
+ QVariant rightData = sourceModel()->data(right);
+//! [4]
+
+//! [6]
+ if (leftData.type() == QVariant::DateTime) {
+ return leftData.toDateTime() < rightData.toDateTime();
+ } else {
+ QRegExp *emailPattern = new QRegExp("([\\w\\.]*@[\\w\\.]*)");
+
+ QString leftString = leftData.toString();
+ if(left.column() == 1 && emailPattern->indexIn(leftString) != -1)
+ leftString = emailPattern->cap(1);
+
+ QString rightString = rightData.toString();
+ if(right.column() == 1 && emailPattern->indexIn(rightString) != -1)
+ rightString = emailPattern->cap(1);
+
+ return QString::localeAwareCompare(leftString, rightString) < 0;
+ }
+}
+//! [5] //! [6]
+
+//! [7]
+bool MySortFilterProxyModel::dateInRange(const QDate &date) const
+{
+ return (!minDate.isValid() || date > minDate)
+ && (!maxDate.isValid() || date < maxDate);
+}
+//! [7]
diff --git a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.h b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.h
new file mode 100644
index 0000000000..8ca3e10fd5
--- /dev/null
+++ b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYSORTFILTERPROXYMODEL_H
+#define MYSORTFILTERPROXYMODEL_H
+
+#include <QDate>
+#include <QSortFilterProxyModel>
+
+//! [0]
+class MySortFilterProxyModel : public QSortFilterProxyModel
+{
+ Q_OBJECT
+
+public:
+ MySortFilterProxyModel(QObject *parent = 0);
+
+ QDate filterMinimumDate() const { return minDate; }
+ void setFilterMinimumDate(const QDate &date);
+
+ QDate filterMaximumDate() const { return maxDate; }
+ void setFilterMaximumDate(const QDate &date);
+
+protected:
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+ bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
+
+private:
+ bool dateInRange(const QDate &date) const;
+
+ QDate minDate;
+ QDate maxDate;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/customsortfiltermodel/window.cpp b/examples/widgets/itemviews/customsortfiltermodel/window.cpp
new file mode 100644
index 0000000000..0a8799dccb
--- /dev/null
+++ b/examples/widgets/itemviews/customsortfiltermodel/window.cpp
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mysortfilterproxymodel.h"
+#include "window.h"
+
+//! [0]
+Window::Window()
+{
+ proxyModel = new MySortFilterProxyModel(this);
+ //! [0]
+
+ //! [1]
+ sourceView = new QTreeView;
+ sourceView->setRootIsDecorated(false);
+ sourceView->setAlternatingRowColors(true);
+ //! [1]
+
+ QHBoxLayout *sourceLayout = new QHBoxLayout;
+ //! [2]
+ sourceLayout->addWidget(sourceView);
+ sourceGroupBox = new QGroupBox(tr("Original Model"));
+ sourceGroupBox->setLayout(sourceLayout);
+ //! [2]
+
+ //! [3]
+ filterCaseSensitivityCheckBox = new QCheckBox(tr("Case sensitive filter"));
+ filterCaseSensitivityCheckBox->setChecked(true);
+
+ filterPatternLineEdit = new QLineEdit;
+ filterPatternLineEdit->setText("Grace|Sports");
+
+ filterPatternLabel = new QLabel(tr("&Filter pattern:"));
+ filterPatternLabel->setBuddy(filterPatternLineEdit);
+
+ filterSyntaxComboBox = new QComboBox;
+ filterSyntaxComboBox->addItem(tr("Regular expression"), QRegExp::RegExp);
+ filterSyntaxComboBox->addItem(tr("Wildcard"), QRegExp::Wildcard);
+ filterSyntaxComboBox->addItem(tr("Fixed string"), QRegExp::FixedString);
+
+ fromDateEdit = new QDateEdit;
+ fromDateEdit->setDate(QDate(1970, 01, 01));
+ fromLabel = new QLabel(tr("F&rom:"));
+ fromLabel->setBuddy(fromDateEdit);
+
+ toDateEdit = new QDateEdit;
+ toDateEdit->setDate(QDate(2099, 12, 31));
+ toLabel = new QLabel(tr("&To:"));
+ toLabel->setBuddy(toDateEdit);
+
+ connect(filterPatternLineEdit, SIGNAL(textChanged(QString)),
+ this, SLOT(textFilterChanged()));
+ connect(filterSyntaxComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(textFilterChanged()));
+ connect(filterCaseSensitivityCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(textFilterChanged()));
+ connect(fromDateEdit, SIGNAL(dateChanged(QDate)),
+ this, SLOT(dateFilterChanged()));
+ connect(toDateEdit, SIGNAL(dateChanged(QDate)),
+ //! [3] //! [4]
+ this, SLOT(dateFilterChanged()));
+ //! [4]
+
+ //! [5]
+ proxyView = new QTreeView;
+ proxyView->setRootIsDecorated(false);
+ proxyView->setAlternatingRowColors(true);
+ proxyView->setModel(proxyModel);
+ proxyView->setSortingEnabled(true);
+ proxyView->sortByColumn(1, Qt::AscendingOrder);
+
+ QGridLayout *proxyLayout = new QGridLayout;
+ proxyLayout->addWidget(proxyView, 0, 0, 1, 3);
+ proxyLayout->addWidget(filterPatternLabel, 1, 0);
+ proxyLayout->addWidget(filterPatternLineEdit, 1, 1);
+ proxyLayout->addWidget(filterSyntaxComboBox, 1, 2);
+ proxyLayout->addWidget(filterCaseSensitivityCheckBox, 2, 0, 1, 3);
+ proxyLayout->addWidget(fromLabel, 3, 0);
+ proxyLayout->addWidget(fromDateEdit, 3, 1, 1, 2);
+ proxyLayout->addWidget(toLabel, 4, 0);
+ proxyLayout->addWidget(toDateEdit, 4, 1, 1, 2);
+
+ proxyGroupBox = new QGroupBox(tr("Sorted/Filtered Model"));
+ proxyGroupBox->setLayout(proxyLayout);
+ //! [5]
+
+ //! [6]
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(sourceGroupBox);
+ mainLayout->addWidget(proxyGroupBox);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Custom Sort/Filter Model"));
+ resize(500, 450);
+}
+//! [6]
+
+//! [7]
+void Window::setSourceModel(QAbstractItemModel *model)
+{
+ proxyModel->setSourceModel(model);
+ sourceView->setModel(model);
+}
+//! [7]
+
+//! [8]
+void Window::textFilterChanged()
+{
+ QRegExp::PatternSyntax syntax =
+ QRegExp::PatternSyntax(filterSyntaxComboBox->itemData(
+ filterSyntaxComboBox->currentIndex()).toInt());
+ Qt::CaseSensitivity caseSensitivity =
+ filterCaseSensitivityCheckBox->isChecked() ? Qt::CaseSensitive
+ : Qt::CaseInsensitive;
+
+ QRegExp regExp(filterPatternLineEdit->text(), caseSensitivity, syntax);
+ proxyModel->setFilterRegExp(regExp);
+}
+//! [8]
+
+//! [9]
+void Window::dateFilterChanged()
+{
+ proxyModel->setFilterMinimumDate(fromDateEdit->date());
+ proxyModel->setFilterMaximumDate(toDateEdit->date());
+}
+//! [9]
diff --git a/examples/widgets/itemviews/customsortfiltermodel/window.h b/examples/widgets/itemviews/customsortfiltermodel/window.h
new file mode 100644
index 0000000000..36650aedad
--- /dev/null
+++ b/examples/widgets/itemviews/customsortfiltermodel/window.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QCheckBox;
+class QComboBox;
+class QDateEdit;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QTreeView;
+QT_END_NAMESPACE
+class MySortFilterProxyModel;
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+ void setSourceModel(QAbstractItemModel *model);
+
+private slots:
+ void textFilterChanged();
+ void dateFilterChanged();
+
+private:
+ MySortFilterProxyModel *proxyModel;
+
+ QGroupBox *sourceGroupBox;
+ QGroupBox *proxyGroupBox;
+ QTreeView *sourceView;
+ QTreeView *proxyView;
+ QCheckBox *filterCaseSensitivityCheckBox;
+ QLabel *filterPatternLabel;
+ QLabel *fromLabel;
+ QLabel *toLabel;
+ QLineEdit *filterPatternLineEdit;
+ QComboBox *filterSyntaxComboBox;
+ QDateEdit *fromDateEdit;
+ QDateEdit *toDateEdit;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/dirview/dirview.desktop b/examples/widgets/itemviews/dirview/dirview.desktop
new file mode 100644
index 0000000000..51ec4df26c
--- /dev/null
+++ b/examples/widgets/itemviews/dirview/dirview.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Dir View
+Exec=/opt/usr/bin/dirview
+Icon=dirview
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/dirview/dirview.pro b/examples/widgets/itemviews/dirview/dirview.pro
new file mode 100644
index 0000000000..825f20c630
--- /dev/null
+++ b/examples/widgets/itemviews/dirview/dirview.pro
@@ -0,0 +1,9 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/dirview
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/dirview
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/itemviews/dirview/main.cpp b/examples/widgets/itemviews/dirview/main.cpp
new file mode 100644
index 0000000000..55083afa8f
--- /dev/null
+++ b/examples/widgets/itemviews/dirview/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QFileSystemModel model;
+ model.setRootPath("");
+ QTreeView tree;
+ tree.setModel(&model);
+
+ // Demonstrating look and feel features
+ tree.setAnimated(false);
+ tree.setIndentation(20);
+ tree.setSortingEnabled(true);
+
+ tree.setWindowTitle(QObject::tr("Dir View"));
+ tree.resize(640, 480);
+ tree.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/editabletreemodel/default.txt b/examples/widgets/itemviews/editabletreemodel/default.txt
new file mode 100644
index 0000000000..2b2fb579ae
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/default.txt
@@ -0,0 +1,40 @@
+Getting Started How to familiarize yourself with Qt Designer
+ Launching Designer Running the Qt Designer application
+ The User Interface How to interact with Qt Designer
+
+Designing a Component Creating a GUI for your application
+ Creating a Dialog How to create a dialog
+ Composing the Dialog Putting widgets into the dialog example
+ Creating a Layout Arranging widgets on a form
+ Signal and Slot Connections Making widget communicate with each other
+
+Using a Component in Your Application Generating code from forms
+ The Direct Approach Using a form without any adjustments
+ The Single Inheritance Approach Subclassing a form's base class
+ The Multiple Inheritance Approach Subclassing the form itself
+ Automatic Connections Connecting widgets using a naming scheme
+ A Dialog Without Auto-Connect How to connect widgets without a naming scheme
+ A Dialog With Auto-Connect Using automatic connections
+
+Form Editing Mode How to edit a form in Qt Designer
+ Managing Forms Loading and saving forms
+ Editing a Form Basic editing techniques
+ The Property Editor Changing widget properties
+ The Object Inspector Examining the hierarchy of objects on a form
+ Layouts Objects that arrange widgets on a form
+ Applying and Breaking Layouts Managing widgets in layouts
+ Horizontal and Vertical Layouts Standard row and column layouts
+ The Grid Layout Arranging widgets in a matrix
+ Previewing Forms Checking that the design works
+
+Using Containers How to group widgets together
+ General Features Common container features
+ Frames QFrame
+ Group Boxes QGroupBox
+ Stacked Widgets QStackedWidget
+ Tab Widgets QTabWidget
+ Toolbox Widgets QToolBox
+
+Connection Editing Mode Connecting widgets together with signals and slots
+ Connecting Objects Making connections in Qt Designer
+ Editing Connections Changing existing connections
diff --git a/examples/widgets/itemviews/editabletreemodel/editabletreemodel.desktop b/examples/widgets/itemviews/editabletreemodel/editabletreemodel.desktop
new file mode 100644
index 0000000000..17d17330df
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/editabletreemodel.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Editable Tree Model
+Exec=/opt/usr/bin/editabletreemodel
+Icon=editabletreemodel
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/editabletreemodel/editabletreemodel.pro b/examples/widgets/itemviews/editabletreemodel/editabletreemodel.pro
new file mode 100644
index 0000000000..f86298542d
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/editabletreemodel.pro
@@ -0,0 +1,18 @@
+FORMS = mainwindow.ui
+HEADERS = mainwindow.h \
+ treeitem.h \
+ treemodel.h
+RESOURCES = editabletreemodel.qrc
+SOURCES = mainwindow.cpp \
+ treeitem.cpp \
+ treemodel.cpp \
+ main.cpp
+CONFIG += qt
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/editabletreemodel
+sources.files = $$FORMS $$HEADERS $$RESOURCES $$SOURCES *.pro *.txt
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/editabletreemodel
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/itemviews/editabletreemodel/editabletreemodel.qrc b/examples/widgets/itemviews/editabletreemodel/editabletreemodel.qrc
new file mode 100644
index 0000000000..2fb48f2e62
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/editabletreemodel.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>default.txt</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/itemviews/editabletreemodel/main.cpp b/examples/widgets/itemviews/editabletreemodel/main.cpp
new file mode 100644
index 0000000000..516adf1543
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(editabletreemodel);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp b/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp
new file mode 100644
index 0000000000..115b02e28e
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+#include "treemodel.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ setupUi(this);
+
+
+ QStringList headers;
+ headers << tr("Title") << tr("Description");
+
+ QFile file(":/default.txt");
+ file.open(QIODevice::ReadOnly);
+ TreeModel *model = new TreeModel(headers, file.readAll());
+ file.close();
+
+ view->setModel(model);
+ for (int column = 0; column < model->columnCount(); ++column)
+ view->resizeColumnToContents(column);
+
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ connect(view->selectionModel(),
+ SIGNAL(selectionChanged(const QItemSelection &,
+ const QItemSelection &)),
+ this, SLOT(updateActions()));
+
+ connect(actionsMenu, SIGNAL(aboutToShow()), this, SLOT(updateActions()));
+ connect(insertRowAction, SIGNAL(triggered()), this, SLOT(insertRow()));
+ connect(insertColumnAction, SIGNAL(triggered()), this, SLOT(insertColumn()));
+ connect(removeRowAction, SIGNAL(triggered()), this, SLOT(removeRow()));
+ connect(removeColumnAction, SIGNAL(triggered()), this, SLOT(removeColumn()));
+ connect(insertChildAction, SIGNAL(triggered()), this, SLOT(insertChild()));
+
+ updateActions();
+}
+
+void MainWindow::insertChild()
+{
+ QModelIndex index = view->selectionModel()->currentIndex();
+ QAbstractItemModel *model = view->model();
+
+ if (model->columnCount(index) == 0) {
+ if (!model->insertColumn(0, index))
+ return;
+ }
+
+ if (!model->insertRow(0, index))
+ return;
+
+ for (int column = 0; column < model->columnCount(index); ++column) {
+ QModelIndex child = model->index(0, column, index);
+ model->setData(child, QVariant("[No data]"), Qt::EditRole);
+ if (!model->headerData(column, Qt::Horizontal).isValid())
+ model->setHeaderData(column, Qt::Horizontal, QVariant("[No header]"),
+ Qt::EditRole);
+ }
+
+ view->selectionModel()->setCurrentIndex(model->index(0, 0, index),
+ QItemSelectionModel::ClearAndSelect);
+ updateActions();
+}
+
+bool MainWindow::insertColumn(const QModelIndex &parent)
+{
+ QAbstractItemModel *model = view->model();
+ int column = view->selectionModel()->currentIndex().column();
+
+ // Insert a column in the parent item.
+ bool changed = model->insertColumn(column + 1, parent);
+ if (changed)
+ model->setHeaderData(column + 1, Qt::Horizontal, QVariant("[No header]"),
+ Qt::EditRole);
+
+ updateActions();
+
+ return changed;
+}
+
+void MainWindow::insertRow()
+{
+ QModelIndex index = view->selectionModel()->currentIndex();
+ QAbstractItemModel *model = view->model();
+
+ if (!model->insertRow(index.row()+1, index.parent()))
+ return;
+
+ updateActions();
+
+ for (int column = 0; column < model->columnCount(index.parent()); ++column) {
+ QModelIndex child = model->index(index.row()+1, column, index.parent());
+ model->setData(child, QVariant("[No data]"), Qt::EditRole);
+ }
+}
+
+bool MainWindow::removeColumn(const QModelIndex &parent)
+{
+ QAbstractItemModel *model = view->model();
+ int column = view->selectionModel()->currentIndex().column();
+
+ // Insert columns in each child of the parent item.
+ bool changed = model->removeColumn(column, parent);
+
+ if (!parent.isValid() && changed)
+ updateActions();
+
+ return changed;
+}
+
+void MainWindow::removeRow()
+{
+ QModelIndex index = view->selectionModel()->currentIndex();
+ QAbstractItemModel *model = view->model();
+ if (model->removeRow(index.row(), index.parent()))
+ updateActions();
+}
+
+void MainWindow::updateActions()
+{
+ bool hasSelection = !view->selectionModel()->selection().isEmpty();
+ removeRowAction->setEnabled(hasSelection);
+ removeColumnAction->setEnabled(hasSelection);
+
+ bool hasCurrent = view->selectionModel()->currentIndex().isValid();
+ insertRowAction->setEnabled(hasCurrent);
+ insertColumnAction->setEnabled(hasCurrent);
+
+ if (hasCurrent) {
+ view->closePersistentEditor(view->selectionModel()->currentIndex());
+
+ int row = view->selectionModel()->currentIndex().row();
+ int column = view->selectionModel()->currentIndex().column();
+ if (view->selectionModel()->currentIndex().parent().isValid())
+ statusBar()->showMessage(tr("Position: (%1,%2)").arg(row).arg(column));
+ else
+ statusBar()->showMessage(tr("Position: (%1,%2) in top level").arg(row).arg(column));
+ }
+}
diff --git a/examples/widgets/itemviews/editabletreemodel/mainwindow.h b/examples/widgets/itemviews/editabletreemodel/mainwindow.h
new file mode 100644
index 0000000000..e45037c2e0
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/mainwindow.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QModelIndex>
+
+#include "ui_mainwindow.h"
+
+class QAction;
+class QTreeView;
+class QWidget;
+
+class MainWindow : public QMainWindow, private Ui::MainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+public slots:
+ void updateActions();
+
+private slots:
+ void insertChild();
+ bool insertColumn(const QModelIndex &parent = QModelIndex());
+ void insertRow();
+ bool removeColumn(const QModelIndex &parent = QModelIndex());
+ void removeRow();
+};
+
+#endif
diff --git a/examples/widgets/itemviews/editabletreemodel/mainwindow.ui b/examples/widgets/itemviews/editabletreemodel/mainwindow.ui
new file mode 100644
index 0000000000..2ad084ae24
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/mainwindow.ui
@@ -0,0 +1,128 @@
+<ui version="4.0" >
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>573</width>
+ <height>468</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Editable Tree Model</string>
+ </property>
+ <widget class="QWidget" name="centralwidget" >
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTreeView" name="view" >
+ <property name="alternatingRowColors" >
+ <bool>true</bool>
+ </property>
+ <property name="selectionBehavior" >
+ <enum>QAbstractItemView::SelectItems</enum>
+ </property>
+ <property name="horizontalScrollMode" >
+ <enum>QAbstractItemView::ScrollPerPixel</enum>
+ </property>
+ <property name="animated" >
+ <bool>false</bool>
+ </property>
+ <property name="allColumnsShowFocus" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>573</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="fileMenu" >
+ <property name="title" >
+ <string>&amp;File</string>
+ </property>
+ <addaction name="exitAction" />
+ </widget>
+ <widget class="QMenu" name="actionsMenu" >
+ <property name="title" >
+ <string>&amp;Actions</string>
+ </property>
+ <addaction name="insertRowAction" />
+ <addaction name="insertColumnAction" />
+ <addaction name="separator" />
+ <addaction name="removeRowAction" />
+ <addaction name="removeColumnAction" />
+ <addaction name="separator" />
+ <addaction name="insertChildAction" />
+ </widget>
+ <addaction name="fileMenu" />
+ <addaction name="actionsMenu" />
+ </widget>
+ <widget class="QStatusBar" name="statusbar" />
+ <action name="exitAction" >
+ <property name="text" >
+ <string>E&amp;xit</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+Q</string>
+ </property>
+ </action>
+ <action name="insertRowAction" >
+ <property name="text" >
+ <string>Insert Row</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+I, R</string>
+ </property>
+ </action>
+ <action name="removeRowAction" >
+ <property name="text" >
+ <string>Remove Row</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+R, R</string>
+ </property>
+ </action>
+ <action name="insertColumnAction" >
+ <property name="text" >
+ <string>Insert Column</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+I, C</string>
+ </property>
+ </action>
+ <action name="removeColumnAction" >
+ <property name="text" >
+ <string>Remove Column</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+R, C</string>
+ </property>
+ </action>
+ <action name="insertChildAction" >
+ <property name="text" >
+ <string>Insert Child</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+N</string>
+ </property>
+ </action>
+ </widget>
+ <resources>
+ <include location="editabletreemodel.qrc" />
+ </resources>
+ <connections/>
+</ui>
diff --git a/examples/widgets/itemviews/editabletreemodel/treeitem.cpp b/examples/widgets/itemviews/editabletreemodel/treeitem.cpp
new file mode 100644
index 0000000000..c728f21a92
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/treeitem.cpp
@@ -0,0 +1,179 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ treeitem.cpp
+
+ A container for items of data supplied by the simple tree model.
+*/
+
+#include <QStringList>
+
+#include "treeitem.h"
+
+//! [0]
+TreeItem::TreeItem(const QVector<QVariant> &data, TreeItem *parent)
+{
+ parentItem = parent;
+ itemData = data;
+}
+//! [0]
+
+//! [1]
+TreeItem::~TreeItem()
+{
+ qDeleteAll(childItems);
+}
+//! [1]
+
+//! [2]
+TreeItem *TreeItem::child(int number)
+{
+ return childItems.value(number);
+}
+//! [2]
+
+//! [3]
+int TreeItem::childCount() const
+{
+ return childItems.count();
+}
+//! [3]
+
+//! [4]
+int TreeItem::childNumber() const
+{
+ if (parentItem)
+ return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
+
+ return 0;
+}
+//! [4]
+
+//! [5]
+int TreeItem::columnCount() const
+{
+ return itemData.count();
+}
+//! [5]
+
+//! [6]
+QVariant TreeItem::data(int column) const
+{
+ return itemData.value(column);
+}
+//! [6]
+
+//! [7]
+bool TreeItem::insertChildren(int position, int count, int columns)
+{
+ if (position < 0 || position > childItems.size())
+ return false;
+
+ for (int row = 0; row < count; ++row) {
+ QVector<QVariant> data(columns);
+ TreeItem *item = new TreeItem(data, this);
+ childItems.insert(position, item);
+ }
+
+ return true;
+}
+//! [7]
+
+//! [8]
+bool TreeItem::insertColumns(int position, int columns)
+{
+ if (position < 0 || position > itemData.size())
+ return false;
+
+ for (int column = 0; column < columns; ++column)
+ itemData.insert(position, QVariant());
+
+ foreach (TreeItem *child, childItems)
+ child->insertColumns(position, columns);
+
+ return true;
+}
+//! [8]
+
+//! [9]
+TreeItem *TreeItem::parent()
+{
+ return parentItem;
+}
+//! [9]
+
+//! [10]
+bool TreeItem::removeChildren(int position, int count)
+{
+ if (position < 0 || position + count > childItems.size())
+ return false;
+
+ for (int row = 0; row < count; ++row)
+ delete childItems.takeAt(position);
+
+ return true;
+}
+//! [10]
+
+bool TreeItem::removeColumns(int position, int columns)
+{
+ if (position < 0 || position + columns > itemData.size())
+ return false;
+
+ for (int column = 0; column < columns; ++column)
+ itemData.remove(position);
+
+ foreach (TreeItem *child, childItems)
+ child->removeColumns(position, columns);
+
+ return true;
+}
+
+//! [11]
+bool TreeItem::setData(int column, const QVariant &value)
+{
+ if (column < 0 || column >= itemData.size())
+ return false;
+
+ itemData[column] = value;
+ return true;
+}
+//! [11]
diff --git a/examples/widgets/itemviews/editabletreemodel/treeitem.h b/examples/widgets/itemviews/editabletreemodel/treeitem.h
new file mode 100644
index 0000000000..8426514759
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/treeitem.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TREEITEM_H
+#define TREEITEM_H
+
+#include <QList>
+#include <QVariant>
+#include <QVector>
+
+//! [0]
+class TreeItem
+{
+public:
+ TreeItem(const QVector<QVariant> &data, TreeItem *parent = 0);
+ ~TreeItem();
+
+ TreeItem *child(int number);
+ int childCount() const;
+ int columnCount() const;
+ QVariant data(int column) const;
+ bool insertChildren(int position, int count, int columns);
+ bool insertColumns(int position, int columns);
+ TreeItem *parent();
+ bool removeChildren(int position, int count);
+ bool removeColumns(int position, int columns);
+ int childNumber() const;
+ bool setData(int column, const QVariant &value);
+
+private:
+ QList<TreeItem*> childItems;
+ QVector<QVariant> itemData;
+ TreeItem *parentItem;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp
new file mode 100644
index 0000000000..8192c14e9f
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp
@@ -0,0 +1,288 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "treeitem.h"
+#include "treemodel.h"
+
+//! [0]
+TreeModel::TreeModel(const QStringList &headers, const QString &data,
+ QObject *parent)
+ : QAbstractItemModel(parent)
+{
+ QVector<QVariant> rootData;
+ foreach (QString header, headers)
+ rootData << header;
+
+ rootItem = new TreeItem(rootData);
+ setupModelData(data.split(QString("\n")), rootItem);
+}
+//! [0]
+
+//! [1]
+TreeModel::~TreeModel()
+{
+ delete rootItem;
+}
+//! [1]
+
+//! [2]
+int TreeModel::columnCount(const QModelIndex & /* parent */) const
+{
+ return rootItem->columnCount();
+}
+//! [2]
+
+QVariant TreeModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (role != Qt::DisplayRole && role != Qt::EditRole)
+ return QVariant();
+
+ TreeItem *item = getItem(index);
+
+ return item->data(index.column());
+}
+
+//! [3]
+Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return 0;
+
+ return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+}
+//! [3]
+
+//! [4]
+TreeItem *TreeModel::getItem(const QModelIndex &index) const
+{
+ if (index.isValid()) {
+ TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
+ if (item) return item;
+ }
+ return rootItem;
+}
+//! [4]
+
+QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
+ int role) const
+{
+ if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
+ return rootItem->data(section);
+
+ return QVariant();
+}
+
+//! [5]
+QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const
+{
+ if (parent.isValid() && parent.column() != 0)
+ return QModelIndex();
+//! [5]
+
+//! [6]
+ TreeItem *parentItem = getItem(parent);
+
+ TreeItem *childItem = parentItem->child(row);
+ if (childItem)
+ return createIndex(row, column, childItem);
+ else
+ return QModelIndex();
+}
+//! [6]
+
+bool TreeModel::insertColumns(int position, int columns, const QModelIndex &parent)
+{
+ bool success;
+
+ beginInsertColumns(parent, position, position + columns - 1);
+ success = rootItem->insertColumns(position, columns);
+ endInsertColumns();
+
+ return success;
+}
+
+bool TreeModel::insertRows(int position, int rows, const QModelIndex &parent)
+{
+ TreeItem *parentItem = getItem(parent);
+ bool success;
+
+ beginInsertRows(parent, position, position + rows - 1);
+ success = parentItem->insertChildren(position, rows, rootItem->columnCount());
+ endInsertRows();
+
+ return success;
+}
+
+//! [7]
+QModelIndex TreeModel::parent(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return QModelIndex();
+
+ TreeItem *childItem = getItem(index);
+ TreeItem *parentItem = childItem->parent();
+
+ if (parentItem == rootItem)
+ return QModelIndex();
+
+ return createIndex(parentItem->childNumber(), 0, parentItem);
+}
+//! [7]
+
+bool TreeModel::removeColumns(int position, int columns, const QModelIndex &parent)
+{
+ bool success;
+
+ beginRemoveColumns(parent, position, position + columns - 1);
+ success = rootItem->removeColumns(position, columns);
+ endRemoveColumns();
+
+ if (rootItem->columnCount() == 0)
+ removeRows(0, rowCount());
+
+ return success;
+}
+
+bool TreeModel::removeRows(int position, int rows, const QModelIndex &parent)
+{
+ TreeItem *parentItem = getItem(parent);
+ bool success = true;
+
+ beginRemoveRows(parent, position, position + rows - 1);
+ success = parentItem->removeChildren(position, rows);
+ endRemoveRows();
+
+ return success;
+}
+
+//! [8]
+int TreeModel::rowCount(const QModelIndex &parent) const
+{
+ TreeItem *parentItem = getItem(parent);
+
+ return parentItem->childCount();
+}
+//! [8]
+
+bool TreeModel::setData(const QModelIndex &index, const QVariant &value,
+ int role)
+{
+ if (role != Qt::EditRole)
+ return false;
+
+ TreeItem *item = getItem(index);
+ bool result = item->setData(index.column(), value);
+
+ if (result)
+ emit dataChanged(index, index);
+
+ return result;
+}
+
+bool TreeModel::setHeaderData(int section, Qt::Orientation orientation,
+ const QVariant &value, int role)
+{
+ if (role != Qt::EditRole || orientation != Qt::Horizontal)
+ return false;
+
+ bool result = rootItem->setData(section, value);
+
+ if (result)
+ emit headerDataChanged(orientation, section, section);
+
+ return result;
+}
+
+void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
+{
+ QList<TreeItem*> parents;
+ QList<int> indentations;
+ parents << parent;
+ indentations << 0;
+
+ int number = 0;
+
+ while (number < lines.count()) {
+ int position = 0;
+ while (position < lines[number].length()) {
+ if (lines[number].mid(position, 1) != " ")
+ break;
+ position++;
+ }
+
+ QString lineData = lines[number].mid(position).trimmed();
+
+ if (!lineData.isEmpty()) {
+ // Read the column data from the rest of the line.
+ QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts);
+ QVector<QVariant> columnData;
+ for (int column = 0; column < columnStrings.count(); ++column)
+ columnData << columnStrings[column];
+
+ if (position > indentations.last()) {
+ // The last child of the current parent is now the new parent
+ // unless the current parent has no children.
+
+ if (parents.last()->childCount() > 0) {
+ parents << parents.last()->child(parents.last()->childCount()-1);
+ indentations << position;
+ }
+ } else {
+ while (position < indentations.last() && parents.count() > 0) {
+ parents.pop_back();
+ indentations.pop_back();
+ }
+ }
+
+ // Append a new item to the current parent's list of children.
+ TreeItem *parent = parents.last();
+ parent->insertChildren(parent->childCount(), 1, rootItem->columnCount());
+ for (int column = 0; column < columnData.size(); ++column)
+ parent->child(parent->childCount() - 1)->setData(column, columnData[column]);
+ }
+
+ number++;
+ }
+}
diff --git a/examples/widgets/itemviews/editabletreemodel/treemodel.h b/examples/widgets/itemviews/editabletreemodel/treemodel.h
new file mode 100644
index 0000000000..f124df2e1d
--- /dev/null
+++ b/examples/widgets/itemviews/editabletreemodel/treemodel.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TREEMODEL_H
+#define TREEMODEL_H
+
+#include <QAbstractItemModel>
+#include <QModelIndex>
+#include <QVariant>
+
+class TreeItem;
+
+//! [0]
+class TreeModel : public QAbstractItemModel
+{
+ Q_OBJECT
+
+public:
+ TreeModel(const QStringList &headers, const QString &data,
+ QObject *parent = 0);
+ ~TreeModel();
+//! [0] //! [1]
+
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+
+ QModelIndex index(int row, int column,
+ const QModelIndex &parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex &index) const;
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+//! [1]
+
+//! [2]
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ bool setData(const QModelIndex &index, const QVariant &value,
+ int role = Qt::EditRole);
+ bool setHeaderData(int section, Qt::Orientation orientation,
+ const QVariant &value, int role = Qt::EditRole);
+
+ bool insertColumns(int position, int columns,
+ const QModelIndex &parent = QModelIndex());
+ bool removeColumns(int position, int columns,
+ const QModelIndex &parent = QModelIndex());
+ bool insertRows(int position, int rows,
+ const QModelIndex &parent = QModelIndex());
+ bool removeRows(int position, int rows,
+ const QModelIndex &parent = QModelIndex());
+
+private:
+ void setupModelData(const QStringList &lines, TreeItem *parent);
+ TreeItem *getItem(const QModelIndex &index) const;
+
+ TreeItem *rootItem;
+};
+//! [2]
+
+#endif
diff --git a/examples/widgets/itemviews/fetchmore/fetchmore.desktop b/examples/widgets/itemviews/fetchmore/fetchmore.desktop
new file mode 100644
index 0000000000..b8c9ff32cb
--- /dev/null
+++ b/examples/widgets/itemviews/fetchmore/fetchmore.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Fetch More
+Exec=/opt/usr/bin/fetchmore
+Icon=fetchmore
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/fetchmore/fetchmore.pro b/examples/widgets/itemviews/fetchmore/fetchmore.pro
new file mode 100644
index 0000000000..28af7e9ac0
--- /dev/null
+++ b/examples/widgets/itemviews/fetchmore/fetchmore.pro
@@ -0,0 +1,13 @@
+HEADERS = filelistmodel.h \
+ window.h
+SOURCES = filelistmodel.cpp \
+ main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/fetchmore
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/fetchmore
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/itemviews/fetchmore/filelistmodel.cpp b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
new file mode 100644
index 0000000000..d9678191d9
--- /dev/null
+++ b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "filelistmodel.h"
+#include <QApplication>
+#include <QPalette>
+#include <QBrush>
+#include <QDir>
+
+FileListModel::FileListModel(QObject *parent)
+ : QAbstractListModel(parent)
+{
+}
+
+//![4]
+int FileListModel::rowCount(const QModelIndex & /* parent */) const
+{
+ return fileCount;
+}
+
+QVariant FileListModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.row() >= fileList.size() || index.row() < 0)
+ return QVariant();
+
+ if (role == Qt::DisplayRole)
+ return fileList.at(index.row());
+ else if (role == Qt::BackgroundRole) {
+ int batch = (index.row() / 100) % 2;
+ if (batch == 0)
+ return qApp->palette().base();
+ else
+ return qApp->palette().alternateBase();
+ }
+ return QVariant();
+}
+//![4]
+
+//![1]
+bool FileListModel::canFetchMore(const QModelIndex & /* index */) const
+{
+ if (fileCount < fileList.size())
+ return true;
+ else
+ return false;
+}
+//![1]
+
+//![2]
+void FileListModel::fetchMore(const QModelIndex & /* index */)
+{
+ int remainder = fileList.size() - fileCount;
+ int itemsToFetch = qMin(100, remainder);
+
+ beginInsertRows(QModelIndex(), fileCount, fileCount+itemsToFetch-1);
+
+ fileCount += itemsToFetch;
+
+ endInsertRows();
+
+ emit numberPopulated(itemsToFetch);
+}
+//![2]
+
+//![0]
+void FileListModel::setDirPath(const QString &path)
+{
+ QDir dir(path);
+
+ beginResetModel();
+ fileList = dir.entryList();
+ fileCount = 0;
+ endResetModel();
+}
+//![0]
+
diff --git a/examples/widgets/itemviews/fetchmore/filelistmodel.h b/examples/widgets/itemviews/fetchmore/filelistmodel.h
new file mode 100644
index 0000000000..f3e9f758c7
--- /dev/null
+++ b/examples/widgets/itemviews/fetchmore/filelistmodel.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FILELISTMODEL_H
+#define FILELISTMODEL_H
+
+#include <QAbstractListModel>
+#include <QList>
+#include <QStringList>
+
+//![0]
+class FileListModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+public:
+ FileListModel(QObject *parent = 0);
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+signals:
+ void numberPopulated(int number);
+
+public slots:
+ void setDirPath(const QString &path);
+
+protected:
+ bool canFetchMore(const QModelIndex &parent) const;
+ void fetchMore(const QModelIndex &parent);
+
+private:
+ QStringList fileList;
+ int fileCount;
+};
+//![0]
+
+#endif
diff --git a/examples/widgets/itemviews/fetchmore/main.cpp b/examples/widgets/itemviews/fetchmore/main.cpp
new file mode 100644
index 0000000000..97b94d1d3c
--- /dev/null
+++ b/examples/widgets/itemviews/fetchmore/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/fetchmore/window.cpp b/examples/widgets/itemviews/fetchmore/window.cpp
new file mode 100644
index 0000000000..f138fb4bd4
--- /dev/null
+++ b/examples/widgets/itemviews/fetchmore/window.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include "filelistmodel.h"
+#include "window.h"
+
+Window::Window(QWidget *parent)
+ : QWidget(parent)
+{
+ FileListModel *model = new FileListModel(this);
+ model->setDirPath(QLibraryInfo::location(QLibraryInfo::PrefixPath));
+
+ QLabel *label = new QLabel(tr("&Directory:"));
+ QLineEdit *lineEdit = new QLineEdit;
+ label->setBuddy(lineEdit);
+
+ QListView *view = new QListView;
+ view->setModel(model);
+
+ logViewer = new QTextBrowser;
+ logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
+
+ connect(lineEdit, SIGNAL(textChanged(QString)),
+ model, SLOT(setDirPath(QString)));
+ connect(lineEdit, SIGNAL(textChanged(QString)),
+ logViewer, SLOT(clear()));
+ connect(model, SIGNAL(numberPopulated(int)),
+ this, SLOT(updateLog(int)));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(label, 0, 0);
+ layout->addWidget(lineEdit, 0, 1);
+ layout->addWidget(view, 1, 0, 1, 2);
+ layout->addWidget(logViewer, 2, 0, 1, 2);
+
+ setLayout(layout);
+ setWindowTitle(tr("Fetch More Example"));
+}
+
+void Window::updateLog(int number)
+{
+ logViewer->append(tr("%1 items added.").arg(number));
+}
diff --git a/examples/widgets/itemviews/fetchmore/window.h b/examples/widgets/itemviews/fetchmore/window.h
new file mode 100644
index 0000000000..cf6208b643
--- /dev/null
+++ b/examples/widgets/itemviews/fetchmore/window.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QTextBrowser;
+QT_END_NAMESPACE
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window(QWidget *parent = 0);
+
+public slots:
+ void updateLog(int number);
+
+private:
+ QTextBrowser *logViewer;
+};
+
+#endif
diff --git a/examples/widgets/itemviews/frozencolumn/freezetablewidget.cpp b/examples/widgets/itemviews/frozencolumn/freezetablewidget.cpp
new file mode 100644
index 0000000000..ae83c341c4
--- /dev/null
+++ b/examples/widgets/itemviews/frozencolumn/freezetablewidget.cpp
@@ -0,0 +1,165 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "freezetablewidget.h"
+
+//! [constructor]
+FreezeTableWidget::FreezeTableWidget(QAbstractItemModel * model)
+{
+ setModel(model);
+ frozenTableView = new QTableView(this);
+
+ init();
+
+ //connect the headers and scrollbars of both tableviews together
+ connect(horizontalHeader(),SIGNAL(sectionResized(int,int,int)), this,
+ SLOT(updateSectionWidth(int,int,int)));
+ connect(verticalHeader(),SIGNAL(sectionResized(int,int,int)), this,
+ SLOT(updateSectionHeight(int,int,int)));
+
+ connect(frozenTableView->verticalScrollBar(), SIGNAL(valueChanged(int)),
+ verticalScrollBar(), SLOT(setValue(int)));
+ connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
+ frozenTableView->verticalScrollBar(), SLOT(setValue(int)));
+
+
+}
+//! [constructor]
+
+FreezeTableWidget::~FreezeTableWidget()
+{
+ delete frozenTableView;
+}
+
+//! [init part1]
+void FreezeTableWidget::init()
+{
+ frozenTableView->setModel(model());
+ frozenTableView->setFocusPolicy(Qt::NoFocus);
+ frozenTableView->verticalHeader()->hide();
+ frozenTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
+
+ viewport()->stackUnder(frozenTableView);
+//! [init part1]
+
+//! [init part2]
+ frozenTableView->setStyleSheet("QTableView { border: none;"
+ "background-color: #8EDE21;"
+ "selection-background-color: #999}"); //for demo purposes
+ frozenTableView->setSelectionModel(selectionModel());
+ for(int col=1; col<model()->columnCount(); col++)
+ frozenTableView->setColumnHidden(col, true);
+
+ frozenTableView->setColumnWidth(0, columnWidth(0) );
+
+ frozenTableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ frozenTableView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ frozenTableView->show();
+
+ updateFrozenTableGeometry();
+
+ setHorizontalScrollMode(ScrollPerPixel);
+ setVerticalScrollMode(ScrollPerPixel);
+ frozenTableView->setVerticalScrollMode(ScrollPerPixel);
+}
+//! [init part2]
+
+
+//! [sections]
+void FreezeTableWidget::updateSectionWidth(int logicalIndex, int, int newSize)
+{
+ if(logicalIndex==0){
+ frozenTableView->setColumnWidth(0,newSize);
+ updateFrozenTableGeometry();
+ }
+}
+
+void FreezeTableWidget::updateSectionHeight(int logicalIndex, int, int newSize)
+{
+ frozenTableView->setRowHeight(logicalIndex, newSize);
+}
+//! [sections]
+
+
+//! [resize]
+void FreezeTableWidget::resizeEvent(QResizeEvent * event)
+{
+ QTableView::resizeEvent(event);
+ updateFrozenTableGeometry();
+ }
+//! [resize]
+
+
+//! [navigate]
+QModelIndex FreezeTableWidget::moveCursor(CursorAction cursorAction,
+ Qt::KeyboardModifiers modifiers)
+{
+ QModelIndex current = QTableView::moveCursor(cursorAction, modifiers);
+
+ if(cursorAction == MoveLeft && current.column()>0
+ && visualRect(current).topLeft().x() < frozenTableView->columnWidth(0) ){
+
+ const int newValue = horizontalScrollBar()->value() + visualRect(current).topLeft().x()
+ - frozenTableView->columnWidth(0);
+ horizontalScrollBar()->setValue(newValue);
+ }
+ return current;
+}
+//! [navigate]
+
+void FreezeTableWidget::scrollTo (const QModelIndex & index, ScrollHint hint){
+ if(index.column()>0)
+ QTableView::scrollTo(index, hint);
+}
+
+
+
+//! [geometry]
+void FreezeTableWidget::updateFrozenTableGeometry()
+{
+ frozenTableView->setGeometry( verticalHeader()->width()+frameWidth(),
+ frameWidth(), columnWidth(0),
+ viewport()->height()+horizontalHeader()->height());
+}
+//! [geometry]
+
+
diff --git a/examples/widgets/itemviews/frozencolumn/freezetablewidget.h b/examples/widgets/itemviews/frozencolumn/freezetablewidget.h
new file mode 100644
index 0000000000..1432c012f5
--- /dev/null
+++ b/examples/widgets/itemviews/frozencolumn/freezetablewidget.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FREEZETABLEWIDGET_H
+#define FREEZETABLEWIDGET_H
+
+#include <QTableView>
+
+//! [Widget definition]
+class FreezeTableWidget : public QTableView {
+ Q_OBJECT
+
+public:
+ FreezeTableWidget(QAbstractItemModel * model);
+ ~FreezeTableWidget();
+
+
+protected:
+ virtual void resizeEvent(QResizeEvent *event);
+ virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
+ void scrollTo (const QModelIndex & index, ScrollHint hint = EnsureVisible);
+
+private:
+ QTableView *frozenTableView;
+ void init();
+ void updateFrozenTableGeometry();
+
+
+private slots:
+ void updateSectionWidth(int logicalIndex,int, int newSize);
+ void updateSectionHeight(int logicalIndex, int, int newSize);
+
+};
+//! [Widget definition]
+#endif
diff --git a/examples/widgets/itemviews/frozencolumn/frozencolumn.desktop b/examples/widgets/itemviews/frozencolumn/frozencolumn.desktop
new file mode 100644
index 0000000000..3d1e3b430d
--- /dev/null
+++ b/examples/widgets/itemviews/frozencolumn/frozencolumn.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Frozen Column
+Exec=/opt/usr/bin/frozencolumn
+Icon=frozencolumn
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/frozencolumn/frozencolumn.pro b/examples/widgets/itemviews/frozencolumn/frozencolumn.pro
new file mode 100644
index 0000000000..34a4a4de8c
--- /dev/null
+++ b/examples/widgets/itemviews/frozencolumn/frozencolumn.pro
@@ -0,0 +1,11 @@
+HEADERS += freezetablewidget.h
+SOURCES += main.cpp freezetablewidget.cpp
+RESOURCES += grades.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/frozencolumn
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/frozencolumn
+INSTALLS += target sources
+QT += widgets
+
diff --git a/examples/widgets/itemviews/frozencolumn/grades.qrc b/examples/widgets/itemviews/frozencolumn/grades.qrc
new file mode 100644
index 0000000000..5f16d56931
--- /dev/null
+++ b/examples/widgets/itemviews/frozencolumn/grades.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>grades.txt</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/itemviews/frozencolumn/grades.txt b/examples/widgets/itemviews/frozencolumn/grades.txt
new file mode 100644
index 0000000000..e1c6fcc49e
--- /dev/null
+++ b/examples/widgets/itemviews/frozencolumn/grades.txt
@@ -0,0 +1,36 @@
+ France , Norway , YDS , UK(tech.), UK(adj.) , UIAA , Ger , Australia , Finland , Brazil
+
+1, , 5.2, , , I , I , , , Isup
+2, , 5.3, , , II , II , 11, , II
+3, 3, 5.4, , , III , III , 12, , IIsup
+4, 4, 5.5, 4a , VD , IV , IV , 12, , III
+5a , 5-, 5.6, , S , V- , V , 13, 5-, IIIsup
+5b , 5, 5.7, 4b , HS , V , VI , 14, 5, IV
+ , , , 4c , , V+ , , 15, ,
+5c , 5+, 5.8, , VS , VI- , VIIa , 16, 5, IVsup
+6a , 6-, 5.9, 5a , HVS , VI , VIIb , 17, , V
+6a+ , 6-/6 , 5.10a , , E1 , VI+ , VIIc , 18, 6-, VI
+6b , , 5.10b , 5b , , , , 19, , VI/VI+
+6b+ , 6, 5.10c , , E2 , VII- , VIIIa , 20, 6, VIsup/VI+
+6c , 6+, 5.10d , 5c , , VII , VIIIb , 21, , VIsup
+6c+ , 7-, 5.11a , , E3 , VII+ , VIIIc , 22, 6, 7a
+6c+ , 7, 5.11b , , , , , 23, , 7b
+7a , 7+, 5.11c , 6a , E4 , VIII- , IXa , 24, 7-, 7c
+7a , 7+/8- , 5.11d , , , VIII , IXb , , , 7c
+7a+ , 8-, 5.12a , , E5 , VIII+ , IXc , 25, 7, 8a
+7b , 8, 5.12b , 6b , , , , 26, 8-, 8b
+7b+ , 8/8+ , 5.12c , , E6 , IX- , Xa , 27, 8, 8c
+7c , 8+, 5.12d , 6c , , IX , Xb , 28, 8, 9a
+7c+ , 9-, 5.13a , , E7 , IX+ , Xc , 29, 9-, 9b
+8a , , 5.13b , , , , , , 9, 9c
+8a+ , 9-/9 , 5.13c , 7a , , X- , , 30, 9, 10a
+8b , 9, 5.13d , , E8 , X , , 31, 10-, 10b
+8b+ , 9/9+ , 5.14a , , , X+ , , 32, 10, 10c
+8c , 9+, 5.14b , 7b , , , , 33, 10, 11a
+8c+ , 10-, 5.14c , , E9 , XI- , , 34, 11-, 11b
+9a , 10, 5.14d , 7c , , XI , , 35, 11, 11c
+9a+ , , 5.15a , , , XI+ , , , , 12a
+9b , , 5.15b , , , , , , , 12b
+
+# Wikipedia contributors. Grade (climbing). Wikipedia, The Free Encyclopedia. May 15, 2009, 20:42 UTC.
+# Available at: http://en.wikipedia.org/w/index.php?title=Grade_(climbing)&oldid=290165724. Accessed May 28, 2009.
diff --git a/examples/widgets/itemviews/frozencolumn/main.cpp b/examples/widgets/itemviews/frozencolumn/main.cpp
new file mode 100644
index 0000000000..ff50e97db9
--- /dev/null
+++ b/examples/widgets/itemviews/frozencolumn/main.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QStandardItemModel>
+#include <QFile>
+
+#include "freezetablewidget.h"
+
+int main( int argc, char** argv )
+{
+
+ Q_INIT_RESOURCE(grades);
+
+
+ QApplication app( argc, argv );
+ QStandardItemModel *model=new QStandardItemModel();
+
+
+ QFile file(":/grades.txt");
+ QString line;
+ QStringList list;
+ if (file.open(QFile::ReadOnly)) {
+ line = file.readLine(200);
+ list= line.simplified().split(",");
+ model->setHorizontalHeaderLabels(list);
+
+ int row=0;
+ QStandardItem *newItem=0;
+ while(file.canReadLine()){
+ line = file.readLine(200);
+ if(!line.startsWith("#") && line.contains(",")){
+ list= line.simplified().split(",");
+ for(int col=0; col<list.length(); col++){
+ newItem = new QStandardItem(list.at(col));
+ model->setItem(row ,col, newItem);
+ }
+ row++;
+ }
+ }
+ }
+ file.close();
+
+ FreezeTableWidget *tableView = new FreezeTableWidget(model);
+
+ tableView->setWindowTitle(QObject::tr("Frozen Column Example"));
+ tableView->resize(560,680);
+ tableView->show();
+ return app.exec();
+}
+
diff --git a/examples/widgets/itemviews/interview/README b/examples/widgets/itemviews/interview/README
new file mode 100644
index 0000000000..50894428f6
--- /dev/null
+++ b/examples/widgets/itemviews/interview/README
@@ -0,0 +1,2 @@
+The interview example shows the same model and selection being shared
+between three different views.
diff --git a/examples/widgets/itemviews/interview/images/folder.png b/examples/widgets/itemviews/interview/images/folder.png
new file mode 100644
index 0000000000..589fd2df59
--- /dev/null
+++ b/examples/widgets/itemviews/interview/images/folder.png
Binary files differ
diff --git a/examples/widgets/itemviews/interview/images/interview.png b/examples/widgets/itemviews/interview/images/interview.png
new file mode 100644
index 0000000000..0c3d690258
--- /dev/null
+++ b/examples/widgets/itemviews/interview/images/interview.png
Binary files differ
diff --git a/examples/widgets/itemviews/interview/images/services.png b/examples/widgets/itemviews/interview/images/services.png
new file mode 100644
index 0000000000..6b2ad969d4
--- /dev/null
+++ b/examples/widgets/itemviews/interview/images/services.png
Binary files differ
diff --git a/examples/widgets/itemviews/interview/interview.pro b/examples/widgets/itemviews/interview/interview.pro
new file mode 100644
index 0000000000..5cd0d1f9fc
--- /dev/null
+++ b/examples/widgets/itemviews/interview/interview.pro
@@ -0,0 +1,19 @@
+TEMPLATE = app
+
+CONFIG += qt warn_on
+HEADERS += model.h
+SOURCES += model.cpp main.cpp
+RESOURCES += interview.qrc
+
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/interview
+sources.files = $$SOURCES $$HEADERS $$RESOURCES README *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/interview
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/itemviews/interview/interview.qrc b/examples/widgets/itemviews/interview/interview.qrc
new file mode 100644
index 0000000000..b28ea34d8a
--- /dev/null
+++ b/examples/widgets/itemviews/interview/interview.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>images/folder.png</file>
+ <file>images/services.png</file>
+ <file>images/interview.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/itemviews/interview/main.cpp b/examples/widgets/itemviews/interview/main.cpp
new file mode 100644
index 0000000000..fa059cdb53
--- /dev/null
+++ b/examples/widgets/itemviews/interview/main.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "model.h"
+
+#include <QApplication>
+#include <QTableView>
+#include <QTreeView>
+#include <QListView>
+#include <QSplitter>
+#include <QHeaderView>
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(interview);
+
+ QApplication app(argc, argv);
+ QSplitter page;
+
+ QAbstractItemModel *data = new Model(1000, 10, &page);
+ QItemSelectionModel *selections = new QItemSelectionModel(data);
+
+ QTableView *table = new QTableView;
+ table->setModel(data);
+ table->setSelectionModel(selections);
+ table->horizontalHeader()->setSectionsMovable(true);
+ table->verticalHeader()->setSectionsMovable(true);
+ // Set StaticContents to enable minimal repaints on resizes.
+ table->viewport()->setAttribute(Qt::WA_StaticContents);
+ page.addWidget(table);
+
+ QTreeView *tree = new QTreeView;
+ tree->setModel(data);
+ tree->setSelectionModel(selections);
+ tree->setUniformRowHeights(true);
+ tree->header()->setStretchLastSection(false);
+ tree->viewport()->setAttribute(Qt::WA_StaticContents);
+ // Disable the focus rect to get minimal repaints when scrolling on Mac.
+ tree->setAttribute(Qt::WA_MacShowFocusRect, false);
+ page.addWidget(tree);
+
+ QListView *list = new QListView;
+ list->setModel(data);
+ list->setSelectionModel(selections);
+ list->setViewMode(QListView::IconMode);
+ list->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ list->setAlternatingRowColors(false);
+ list->viewport()->setAttribute(Qt::WA_StaticContents);
+ list->setAttribute(Qt::WA_MacShowFocusRect, false);
+ page.addWidget(list);
+
+ page.setWindowIcon(QPixmap(":/images/interview.png"));
+ page.setWindowTitle("Interview");
+ page.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/interview/model.cpp b/examples/widgets/itemviews/interview/model.cpp
new file mode 100644
index 0000000000..3b20f91ed6
--- /dev/null
+++ b/examples/widgets/itemviews/interview/model.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "model.h"
+#include <QIcon>
+#include <QPixmap>
+
+Model::Model(int rows, int columns, QObject *parent)
+ : QAbstractItemModel(parent),
+ services(QPixmap(":/images/services.png")),
+ rc(rows), cc(columns),
+ tree(new QVector<Node>(rows, Node(0)))
+{
+
+}
+
+Model::~Model()
+{
+ delete tree;
+}
+
+QModelIndex Model::index(int row, int column, const QModelIndex &parent) const
+{
+ if (row < rc && row >= 0 && column < cc && column >= 0) {
+ Node *p = static_cast<Node*>(parent.internalPointer());
+ Node *n = node(row, p);
+ if (n)
+ return createIndex(row, column, n);
+ }
+ return QModelIndex();
+}
+
+QModelIndex Model::parent(const QModelIndex &child) const
+{
+ if (child.isValid()) {
+ Node *n = static_cast<Node*>(child.internalPointer());
+ Node *p = parent(n);
+ if (p)
+ return createIndex(row(p), 0, p);
+ }
+ return QModelIndex();
+}
+
+int Model::rowCount(const QModelIndex &parent) const
+{
+ return (parent.isValid() && parent.column() != 0) ? 0 : rc;
+}
+
+int Model::columnCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ return cc;
+}
+
+QVariant Model::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+ if (role == Qt::DisplayRole)
+ return QVariant("Item " + QString::number(index.row()) + ":" + QString::number(index.column()));
+ if (role == Qt::DecorationRole) {
+ if (index.column() == 0)
+ return iconProvider.icon(QFileIconProvider::Folder);
+ return iconProvider.icon(QFileIconProvider::File);
+ }
+ return QVariant();
+}
+
+QVariant Model::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role == Qt::DisplayRole)
+ return QString::number(section);
+ if (role == Qt::DecorationRole)
+ return QVariant::fromValue(services);
+ return QAbstractItemModel::headerData(section, orientation, role);
+}
+
+bool Model::hasChildren(const QModelIndex &parent) const
+{
+ if (parent.isValid() && parent.column() != 0)
+ return false;
+ return rc > 0 && cc > 0;
+}
+
+Qt::ItemFlags Model::flags(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return 0;
+ return (Qt::ItemIsDragEnabled|Qt::ItemIsSelectable|Qt::ItemIsEnabled);
+}
+
+Model::Node *Model::node(int row, Node *parent) const
+{
+ if (parent && !parent->children)
+ parent->children = new QVector<Node>(rc, Node(parent));
+ QVector<Node> *v = parent ? parent->children : tree;
+ return const_cast<Node*>(&(v->at(row)));
+}
+
+Model::Node *Model::parent(Node *child) const
+{
+ return child ? child->parent : 0;
+}
+
+int Model::row(Node *node) const
+{
+ const Node *first = node->parent ? &(node->parent->children->at(0)) : &(tree->at(0));
+ return (node - first);
+}
diff --git a/examples/widgets/itemviews/interview/model.h b/examples/widgets/itemviews/interview/model.h
new file mode 100644
index 0000000000..0480ce1763
--- /dev/null
+++ b/examples/widgets/itemviews/interview/model.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MODEL_H
+#define MODEL_H
+
+#include <QAbstractItemModel>
+#include <QFileIconProvider>
+#include <QIcon>
+#include <QVector>
+
+class Model : public QAbstractItemModel
+{
+ Q_OBJECT
+
+public:
+ Model(int rows, int columns, QObject *parent = 0);
+ ~Model();
+
+ QModelIndex index(int row, int column, const QModelIndex &parent) const;
+ QModelIndex parent(const QModelIndex &child) const;
+
+ int rowCount(const QModelIndex &parent) const;
+ int columnCount(const QModelIndex &parent) const;
+
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+
+ bool hasChildren(const QModelIndex &parent) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+
+private:
+
+ struct Node
+ {
+ Node(Node *parent = 0) : parent(parent), children(0) {}
+ ~Node() { delete children; }
+ Node *parent;
+ QVector<Node> *children;
+ };
+
+ Node *node(int row, Node *parent) const;
+ Node *parent(Node *child) const;
+ int row(Node *node) const;
+
+ QIcon services;
+ int rc, cc;
+ QVector<Node> *tree;
+ QFileIconProvider iconProvider;
+};
+
+#endif
diff --git a/examples/widgets/itemviews/itemviews.pro b/examples/widgets/itemviews/itemviews.pro
new file mode 100644
index 0000000000..347c259bc2
--- /dev/null
+++ b/examples/widgets/itemviews/itemviews.pro
@@ -0,0 +1,25 @@
+TEMPLATE = subdirs
+SUBDIRS = addressbook \
+ basicsortfiltermodel \
+ chart \
+ combowidgetmapper \
+ customsortfiltermodel \
+ dirview \
+ editabletreemodel \
+ fetchmore \
+ frozencolumn \
+ interview \
+ pixelator \
+ puzzle \
+ simpledommodel \
+ simpletreemodel \
+ simplewidgetmapper \
+ spinboxdelegate \
+ spreadsheet
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews
+INSTALLS += sources
+
+QT += widgets
diff --git a/examples/widgets/itemviews/pixelator/imagemodel.cpp b/examples/widgets/itemviews/pixelator/imagemodel.cpp
new file mode 100644
index 0000000000..efbf2d35bc
--- /dev/null
+++ b/examples/widgets/itemviews/pixelator/imagemodel.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "imagemodel.h"
+
+//! [0]
+ImageModel::ImageModel(QObject *parent)
+ : QAbstractTableModel(parent)
+{
+}
+//! [0]
+
+//! [1]
+void ImageModel::setImage(const QImage &image)
+{
+ beginResetModel();
+ modelImage = image;
+ endResetModel();
+}
+//! [1]
+
+//! [2]
+int ImageModel::rowCount(const QModelIndex & /* parent */) const
+{
+ return modelImage.height();
+}
+
+int ImageModel::columnCount(const QModelIndex & /* parent */) const
+//! [2] //! [3]
+{
+ return modelImage.width();
+}
+//! [3]
+
+//! [4]
+QVariant ImageModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid() || role != Qt::DisplayRole)
+ return QVariant();
+ return qGray(modelImage.pixel(index.column(), index.row()));
+}
+//! [4]
+
+//! [5]
+QVariant ImageModel::headerData(int /* section */,
+ Qt::Orientation /* orientation */,
+ int role) const
+{
+ if (role == Qt::SizeHintRole)
+ return QSize(1, 1);
+ return QVariant();
+}
+//! [5]
diff --git a/examples/widgets/itemviews/pixelator/imagemodel.h b/examples/widgets/itemviews/pixelator/imagemodel.h
new file mode 100644
index 0000000000..2f778ca927
--- /dev/null
+++ b/examples/widgets/itemviews/pixelator/imagemodel.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef IMAGEMODEL_H
+#define IMAGEMODEL_H
+
+#include <QAbstractTableModel>
+#include <QImage>
+
+//! [0]
+class ImageModel : public QAbstractTableModel
+{
+ Q_OBJECT
+
+public:
+ ImageModel(QObject *parent = 0);
+
+ void setImage(const QImage &image);
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+
+private:
+ QImage modelImage;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/pixelator/images.qrc b/examples/widgets/itemviews/pixelator/images.qrc
new file mode 100644
index 0000000000..c105e13895
--- /dev/null
+++ b/examples/widgets/itemviews/pixelator/images.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/qt.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/itemviews/pixelator/images/qt.png b/examples/widgets/itemviews/pixelator/images/qt.png
new file mode 100644
index 0000000000..a2c9c77c16
--- /dev/null
+++ b/examples/widgets/itemviews/pixelator/images/qt.png
Binary files differ
diff --git a/examples/widgets/itemviews/pixelator/main.cpp b/examples/widgets/itemviews/pixelator/main.cpp
new file mode 100644
index 0000000000..e877051775
--- /dev/null
+++ b/examples/widgets/itemviews/pixelator/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(images);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ window.openImage(":/images/qt.png");
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/pixelator/mainwindow.cpp b/examples/widgets/itemviews/pixelator/mainwindow.cpp
new file mode 100644
index 0000000000..20dfba18f4
--- /dev/null
+++ b/examples/widgets/itemviews/pixelator/mainwindow.cpp
@@ -0,0 +1,248 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#ifndef QT_NO_PRINTER
+#include <QPrinter>
+#include <QPrintDialog>
+#endif
+
+#include "imagemodel.h"
+#include "mainwindow.h"
+#include "pixeldelegate.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+//! [0]
+ currentPath = QDir::homePath();
+ model = new ImageModel(this);
+
+ QWidget *centralWidget = new QWidget;
+
+//! [1]
+ view = new QTableView;
+ view->setShowGrid(false);
+ view->horizontalHeader()->hide();
+ view->verticalHeader()->hide();
+ view->horizontalHeader()->setMinimumSectionSize(1);
+ view->verticalHeader()->setMinimumSectionSize(1);
+ view->setModel(model);
+//! [1]
+
+//! [2]
+ PixelDelegate *delegate = new PixelDelegate(this);
+ view->setItemDelegate(delegate);
+//! [2]
+
+//! [3]
+ QLabel *pixelSizeLabel = new QLabel(tr("Pixel size:"));
+ QSpinBox *pixelSizeSpinBox = new QSpinBox;
+ pixelSizeSpinBox->setMinimum(4);
+ pixelSizeSpinBox->setMaximum(32);
+ pixelSizeSpinBox->setValue(12);
+//! [3]
+
+ QMenu *fileMenu = new QMenu(tr("&File"), this);
+ QAction *openAction = fileMenu->addAction(tr("&Open..."));
+ openAction->setShortcuts(QKeySequence::Open);
+
+ printAction = fileMenu->addAction(tr("&Print..."));
+ printAction->setEnabled(false);
+ printAction->setShortcut(QKeySequence::Print);
+
+ QAction *quitAction = fileMenu->addAction(tr("E&xit"));
+ quitAction->setShortcuts(QKeySequence::Quit);
+
+ QMenu *helpMenu = new QMenu(tr("&Help"), this);
+ QAction *aboutAction = helpMenu->addAction(tr("&About"));
+
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addSeparator();
+ menuBar()->addMenu(helpMenu);
+
+ connect(openAction, SIGNAL(triggered()), this, SLOT(chooseImage()));
+ connect(printAction, SIGNAL(triggered()), this, SLOT(printImage()));
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAboutBox()));
+//! [4]
+ connect(pixelSizeSpinBox, SIGNAL(valueChanged(int)),
+ delegate, SLOT(setPixelSize(int)));
+ connect(pixelSizeSpinBox, SIGNAL(valueChanged(int)),
+ this, SLOT(updateView()));
+//! [4]
+
+ QHBoxLayout *controlsLayout = new QHBoxLayout;
+ controlsLayout->addWidget(pixelSizeLabel);
+ controlsLayout->addWidget(pixelSizeSpinBox);
+ controlsLayout->addStretch(1);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(view);
+ mainLayout->addLayout(controlsLayout);
+ centralWidget->setLayout(mainLayout);
+
+ setCentralWidget(centralWidget);
+
+ setWindowTitle(tr("Pixelator"));
+ resize(640, 480);
+//! [5]
+}
+//! [5]
+
+void MainWindow::chooseImage()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Choose an image"), currentPath, "*");
+
+ if (!fileName.isEmpty())
+ openImage(fileName);
+}
+
+void MainWindow::openImage(const QString &fileName)
+{
+ QImage image;
+
+ if (image.load(fileName)) {
+ model->setImage(image);
+ if (!fileName.startsWith(":/")) {
+ currentPath = fileName;
+ setWindowTitle(tr("%1 - Pixelator").arg(currentPath));
+ }
+
+ printAction->setEnabled(true);
+ updateView();
+ }
+}
+
+void MainWindow::printImage()
+{
+#ifndef QT_NO_PRINTER
+ if (model->rowCount(QModelIndex())*model->columnCount(QModelIndex())
+ > 90000) {
+ QMessageBox::StandardButton answer;
+ answer = QMessageBox::question(this, tr("Large Image Size"),
+ tr("The printed image may be very large. Are you sure that "
+ "you want to print it?"),
+ QMessageBox::Yes | QMessageBox::No);
+ if (answer == QMessageBox::No)
+ return;
+ }
+
+ QPrinter printer(QPrinter::HighResolution);
+
+ QPrintDialog *dlg = new QPrintDialog(&printer, this);
+ dlg->setWindowTitle(tr("Print Image"));
+
+ if (dlg->exec() != QDialog::Accepted)
+ return;
+
+ QPainter painter;
+ painter.begin(&printer);
+
+ int rows = model->rowCount(QModelIndex());
+ int columns = model->columnCount(QModelIndex());
+ int sourceWidth = (columns+1) * ItemSize;
+ int sourceHeight = (rows+1) * ItemSize;
+
+ painter.save();
+
+ double xscale = printer.pageRect().width()/double(sourceWidth);
+ double yscale = printer.pageRect().height()/double(sourceHeight);
+ double scale = qMin(xscale, yscale);
+
+ painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
+ printer.paperRect().y() + printer.pageRect().height()/2);
+ painter.scale(scale, scale);
+ painter.translate(-sourceWidth/2, -sourceHeight/2);
+
+ QStyleOptionViewItem option;
+ QModelIndex parent = QModelIndex();
+
+ QProgressDialog progress(tr("Printing..."), tr("Cancel"), 0, rows, this);
+ progress.setWindowModality(Qt::ApplicationModal);
+ float y = ItemSize/2;
+
+ for (int row = 0; row < rows; ++row) {
+ progress.setValue(row);
+ qApp->processEvents();
+ if (progress.wasCanceled())
+ break;
+
+ float x = ItemSize/2;
+
+ for (int column = 0; column < columns; ++column) {
+ option.rect = QRect(int(x), int(y), ItemSize, ItemSize);
+ view->itemDelegate()->paint(&painter, option,
+ model->index(row, column, parent));
+ x = x + ItemSize;
+ }
+ y = y + ItemSize;
+ }
+ progress.setValue(rows);
+
+ painter.restore();
+ painter.end();
+
+ if (progress.wasCanceled()) {
+ QMessageBox::information(this, tr("Printing canceled"),
+ tr("The printing process was canceled."), QMessageBox::Cancel);
+ }
+#else
+ QMessageBox::information(this, tr("Printing canceled"),
+ tr("Printing is not supported on this Qt build"), QMessageBox::Cancel);
+#endif
+}
+
+void MainWindow::showAboutBox()
+{
+ QMessageBox::about(this, tr("About the Pixelator example"),
+ tr("This example demonstrates how a standard view and a custom\n"
+ "delegate can be used to produce a specialized representation\n"
+ "of data in a simple custom model."));
+}
+
+//! [6]
+void MainWindow::updateView()
+{
+ view->resizeColumnsToContents();
+ view->resizeRowsToContents();
+}
+//! [6]
diff --git a/examples/widgets/itemviews/pixelator/mainwindow.h b/examples/widgets/itemviews/pixelator/mainwindow.h
new file mode 100644
index 0000000000..1aea1f9807
--- /dev/null
+++ b/examples/widgets/itemviews/pixelator/mainwindow.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+class ImageModel;
+QT_BEGIN_NAMESPACE
+class QAction;
+class QTableView;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+ void openImage(const QString &fileName);
+
+public slots:
+ void chooseImage();
+ void printImage();
+ void showAboutBox();
+ void updateView();
+
+private:
+ ImageModel *model;
+ QAction *printAction;
+ QString currentPath;
+ QTableView *view;
+};
+
+#endif
diff --git a/examples/widgets/itemviews/pixelator/pixelator.desktop b/examples/widgets/itemviews/pixelator/pixelator.desktop
new file mode 100644
index 0000000000..751deb13b3
--- /dev/null
+++ b/examples/widgets/itemviews/pixelator/pixelator.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Pixelator
+Exec=/opt/usr/bin/pixelator
+Icon=pixelator
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/pixelator/pixelator.pro b/examples/widgets/itemviews/pixelator/pixelator.pro
new file mode 100644
index 0000000000..48f8a58a58
--- /dev/null
+++ b/examples/widgets/itemviews/pixelator/pixelator.pro
@@ -0,0 +1,17 @@
+HEADERS = imagemodel.h \
+ mainwindow.h \
+ pixeldelegate.h
+SOURCES = imagemodel.cpp \
+ main.cpp \
+ mainwindow.cpp \
+ pixeldelegate.cpp
+RESOURCES += images.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/pixelator
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/pixelator
+INSTALLS += target sources
+
+QT += widgets
+!isEmpty(QT.printsupport.name): QT += printsupport
diff --git a/examples/widgets/itemviews/pixelator/pixeldelegate.cpp b/examples/widgets/itemviews/pixelator/pixeldelegate.cpp
new file mode 100644
index 0000000000..5904c2e680
--- /dev/null
+++ b/examples/widgets/itemviews/pixelator/pixeldelegate.cpp
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "pixeldelegate.h"
+
+//! [0]
+PixelDelegate::PixelDelegate(QObject *parent)
+ : QAbstractItemDelegate(parent)
+{
+ pixelSize = 12;
+}
+//! [0]
+
+//! [1]
+void PixelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+//! [2]
+ if (option.state & QStyle::State_Selected)
+ painter->fillRect(option.rect, option.palette.highlight());
+//! [1]
+
+//! [3]
+ int size = qMin(option.rect.width(), option.rect.height());
+//! [3] //! [4]
+ int brightness = index.model()->data(index, Qt::DisplayRole).toInt();
+ double radius = (size/2.0) - (brightness/255.0 * size/2.0);
+ if (radius == 0.0)
+ return;
+//! [4]
+
+//! [5]
+ painter->save();
+//! [5] //! [6]
+ painter->setRenderHint(QPainter::Antialiasing, true);
+//! [6] //! [7]
+ painter->setPen(Qt::NoPen);
+//! [7] //! [8]
+ if (option.state & QStyle::State_Selected)
+//! [8] //! [9]
+ painter->setBrush(option.palette.highlightedText());
+ else
+//! [2]
+ painter->setBrush(option.palette.text());
+//! [9]
+
+//! [10]
+ painter->drawEllipse(QRectF(option.rect.x() + option.rect.width()/2 - radius,
+ option.rect.y() + option.rect.height()/2 - radius,
+ 2*radius, 2*radius));
+ painter->restore();
+}
+//! [10]
+
+//! [11]
+QSize PixelDelegate::sizeHint(const QStyleOptionViewItem & /* option */,
+ const QModelIndex & /* index */) const
+{
+ return QSize(pixelSize, pixelSize);
+}
+//! [11]
+
+//! [12]
+void PixelDelegate::setPixelSize(int size)
+{
+ pixelSize = size;
+}
+//! [12]
diff --git a/examples/widgets/itemviews/pixelator/pixeldelegate.h b/examples/widgets/itemviews/pixelator/pixeldelegate.h
new file mode 100644
index 0000000000..4035bc4571
--- /dev/null
+++ b/examples/widgets/itemviews/pixelator/pixeldelegate.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PIXELDELEGATE_H
+#define PIXELDELEGATE_H
+
+#include <QAbstractItemDelegate>
+#include <QFontMetrics>
+#include <QModelIndex>
+#include <QSize>
+
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QObject;
+class QPainter;
+QT_END_NAMESPACE
+
+static const int ItemSize = 256;
+
+//! [0]
+class PixelDelegate : public QAbstractItemDelegate
+{
+ Q_OBJECT
+
+public:
+ PixelDelegate(QObject *parent = 0);
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+
+ QSize sizeHint(const QStyleOptionViewItem &option,
+ const QModelIndex &index ) const;
+
+public slots:
+ void setPixelSize(int size);
+
+private:
+ int pixelSize;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/puzzle/example.jpg b/examples/widgets/itemviews/puzzle/example.jpg
new file mode 100644
index 0000000000..e09fb70757
--- /dev/null
+++ b/examples/widgets/itemviews/puzzle/example.jpg
Binary files differ
diff --git a/examples/widgets/itemviews/puzzle/main.cpp b/examples/widgets/itemviews/puzzle/main.cpp
new file mode 100644
index 0000000000..31b7142819
--- /dev/null
+++ b/examples/widgets/itemviews/puzzle/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(puzzle);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.openImage(":/images/example.jpg");
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/puzzle/mainwindow.cpp b/examples/widgets/itemviews/puzzle/mainwindow.cpp
new file mode 100644
index 0000000000..4b9b10946a
--- /dev/null
+++ b/examples/widgets/itemviews/puzzle/mainwindow.cpp
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include <stdlib.h>
+
+#include "mainwindow.h"
+#include "piecesmodel.h"
+#include "puzzlewidget.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ setupMenus();
+ setupWidgets();
+ model = new PiecesModel(puzzleWidget->pieceSize(), this);
+ piecesList->setModel(model);
+
+ setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
+ setWindowTitle(tr("Puzzle"));
+}
+
+void MainWindow::openImage(const QString &path)
+{
+ QString fileName = path;
+
+ if (fileName.isNull())
+ fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)"));
+
+ if (!fileName.isEmpty()) {
+ QPixmap newImage;
+ if (!newImage.load(fileName)) {
+ QMessageBox::warning(this, tr("Open Image"),
+ tr("The image file could not be loaded."),
+ QMessageBox::Cancel);
+ return;
+ }
+ puzzleImage = newImage;
+ setupPuzzle();
+ }
+}
+
+void MainWindow::setCompleted()
+{
+ QMessageBox::information(this, tr("Puzzle Completed"),
+ tr("Congratulations! You have completed the puzzle!\n"
+ "Click OK to start again."),
+ QMessageBox::Ok);
+
+ setupPuzzle();
+}
+
+void MainWindow::setupPuzzle()
+{
+ int size = qMin(puzzleImage.width(), puzzleImage.height());
+ puzzleImage = puzzleImage.copy((puzzleImage.width() - size)/2,
+ (puzzleImage.height() - size)/2, size, size).scaled(puzzleWidget->imageSize(),
+ puzzleWidget->imageSize(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+
+ qsrand(QCursor::pos().x() ^ QCursor::pos().y());
+
+ model->addPieces(puzzleImage);
+ puzzleWidget->clear();
+}
+
+void MainWindow::setupMenus()
+{
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+
+ QAction *openAction = fileMenu->addAction(tr("&Open..."));
+ openAction->setShortcuts(QKeySequence::Open);
+
+ QAction *exitAction = fileMenu->addAction(tr("E&xit"));
+ exitAction->setShortcuts(QKeySequence::Quit);
+
+ QMenu *gameMenu = menuBar()->addMenu(tr("&Game"));
+
+ QAction *restartAction = gameMenu->addAction(tr("&Restart"));
+
+ connect(openAction, SIGNAL(triggered()), this, SLOT(openImage()));
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(restartAction, SIGNAL(triggered()), this, SLOT(setupPuzzle()));
+}
+
+void MainWindow::setupWidgets()
+{
+ QFrame *frame = new QFrame;
+ QHBoxLayout *frameLayout = new QHBoxLayout(frame);
+
+ puzzleWidget = new PuzzleWidget(400);
+
+ piecesList = new QListView;
+ piecesList->setDragEnabled(true);
+ piecesList->setViewMode(QListView::IconMode);
+ piecesList->setIconSize(QSize(puzzleWidget->pieceSize() - 20, puzzleWidget->pieceSize() - 20));
+ piecesList->setGridSize(QSize(puzzleWidget->pieceSize(), puzzleWidget->pieceSize()));
+ piecesList->setSpacing(10);
+ piecesList->setMovement(QListView::Snap);
+ piecesList->setAcceptDrops(true);
+ piecesList->setDropIndicatorShown(true);
+
+ PiecesModel *model = new PiecesModel(puzzleWidget->pieceSize(), this);
+ piecesList->setModel(model);
+
+ connect(puzzleWidget, SIGNAL(puzzleCompleted()),
+ this, SLOT(setCompleted()), Qt::QueuedConnection);
+
+ frameLayout->addWidget(piecesList);
+ frameLayout->addWidget(puzzleWidget);
+ setCentralWidget(frame);
+}
diff --git a/examples/widgets/itemviews/puzzle/mainwindow.h b/examples/widgets/itemviews/puzzle/mainwindow.h
new file mode 100644
index 0000000000..83704d9932
--- /dev/null
+++ b/examples/widgets/itemviews/puzzle/mainwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QPixmap>
+#include <QMainWindow>
+
+class PuzzleWidget;
+class PiecesModel;
+QT_BEGIN_NAMESPACE
+class QListView;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+public slots:
+ void openImage(const QString &path = QString());
+ void setupPuzzle();
+
+private slots:
+ void setCompleted();
+
+private:
+ void setupMenus();
+ void setupWidgets();
+
+ QPixmap puzzleImage;
+ QListView *piecesList;
+ PuzzleWidget *puzzleWidget;
+ PiecesModel *model;
+};
+
+#endif
diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.cpp b/examples/widgets/itemviews/puzzle/piecesmodel.cpp
new file mode 100644
index 0000000000..68574606e2
--- /dev/null
+++ b/examples/widgets/itemviews/puzzle/piecesmodel.cpp
@@ -0,0 +1,203 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "piecesmodel.h"
+
+PiecesModel::PiecesModel(int pieceSize, QObject *parent)
+ : QAbstractListModel(parent), m_PieceSize(pieceSize)
+{
+}
+
+QVariant PiecesModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (role == Qt::DecorationRole)
+ return QIcon(pixmaps.value(index.row()).scaled(m_PieceSize, m_PieceSize,
+ Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ else if (role == Qt::UserRole)
+ return pixmaps.value(index.row());
+ else if (role == Qt::UserRole + 1)
+ return locations.value(index.row());
+
+ return QVariant();
+}
+
+void PiecesModel::addPiece(const QPixmap &pixmap, const QPoint &location)
+{
+ int row;
+ if (int(2.0*qrand()/(RAND_MAX+1.0)) == 1)
+ row = 0;
+ else
+ row = pixmaps.size();
+
+ beginInsertRows(QModelIndex(), row, row);
+ pixmaps.insert(row, pixmap);
+ locations.insert(row, location);
+ endInsertRows();
+}
+
+Qt::ItemFlags PiecesModel::flags(const QModelIndex &index) const
+{
+ if (index.isValid())
+ return (Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
+
+ return Qt::ItemIsDropEnabled;
+}
+
+bool PiecesModel::removeRows(int row, int count, const QModelIndex &parent)
+{
+ if (parent.isValid())
+ return false;
+
+ if (row >= pixmaps.size() || row + count <= 0)
+ return false;
+
+ int beginRow = qMax(0, row);
+ int endRow = qMin(row + count - 1, pixmaps.size() - 1);
+
+ beginRemoveRows(parent, beginRow, endRow);
+
+ while (beginRow <= endRow) {
+ pixmaps.removeAt(beginRow);
+ locations.removeAt(beginRow);
+ ++beginRow;
+ }
+
+ endRemoveRows();
+ return true;
+}
+
+QStringList PiecesModel::mimeTypes() const
+{
+ QStringList types;
+ types << "image/x-puzzle-piece";
+ return types;
+}
+
+QMimeData *PiecesModel::mimeData(const QModelIndexList &indexes) const
+{
+ QMimeData *mimeData = new QMimeData();
+ QByteArray encodedData;
+
+ QDataStream stream(&encodedData, QIODevice::WriteOnly);
+
+ foreach (QModelIndex index, indexes) {
+ if (index.isValid()) {
+ QPixmap pixmap = qvariant_cast<QPixmap>(data(index, Qt::UserRole));
+ QPoint location = data(index, Qt::UserRole+1).toPoint();
+ stream << pixmap << location;
+ }
+ }
+
+ mimeData->setData("image/x-puzzle-piece", encodedData);
+ return mimeData;
+}
+
+bool PiecesModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
+ int row, int column, const QModelIndex &parent)
+{
+ if (!data->hasFormat("image/x-puzzle-piece"))
+ return false;
+
+ if (action == Qt::IgnoreAction)
+ return true;
+
+ if (column > 0)
+ return false;
+
+ int endRow;
+
+ if (!parent.isValid()) {
+ if (row < 0)
+ endRow = pixmaps.size();
+ else
+ endRow = qMin(row, pixmaps.size());
+ } else
+ endRow = parent.row();
+
+ QByteArray encodedData = data->data("image/x-puzzle-piece");
+ QDataStream stream(&encodedData, QIODevice::ReadOnly);
+
+ while (!stream.atEnd()) {
+ QPixmap pixmap;
+ QPoint location;
+ stream >> pixmap >> location;
+
+ beginInsertRows(QModelIndex(), endRow, endRow);
+ pixmaps.insert(endRow, pixmap);
+ locations.insert(endRow, location);
+ endInsertRows();
+
+ ++endRow;
+ }
+
+ return true;
+}
+
+int PiecesModel::rowCount(const QModelIndex &parent) const
+{
+ if (parent.isValid())
+ return 0;
+ else
+ return pixmaps.size();
+}
+
+Qt::DropActions PiecesModel::supportedDropActions() const
+{
+ return Qt::CopyAction | Qt::MoveAction;
+}
+
+void PiecesModel::addPieces(const QPixmap& pixmap)
+{
+ beginRemoveRows(QModelIndex(), 0, 24);
+ pixmaps.clear();
+ locations.clear();
+ endRemoveRows();
+ for (int y = 0; y < 5; ++y) {
+ for (int x = 0; x < 5; ++x) {
+ QPixmap pieceImage = pixmap.copy(x*m_PieceSize, y*m_PieceSize, m_PieceSize, m_PieceSize);
+ addPiece(pieceImage, QPoint(x, y));
+ }
+ }
+}
diff --git a/examples/widgets/itemviews/puzzle/piecesmodel.h b/examples/widgets/itemviews/puzzle/piecesmodel.h
new file mode 100644
index 0000000000..e8fa45a9a0
--- /dev/null
+++ b/examples/widgets/itemviews/puzzle/piecesmodel.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PIECESLIST_H
+#define PIECESLIST_H
+
+#include <QAbstractListModel>
+#include <QList>
+#include <QPixmap>
+#include <QPoint>
+#include <QStringList>
+
+QT_BEGIN_NAMESPACE
+class QMimeData;
+QT_END_NAMESPACE
+
+class PiecesModel : public QAbstractListModel
+{
+ Q_OBJECT
+
+public:
+ PiecesModel(int pieceSize, QObject *parent = 0);
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ bool removeRows(int row, int count, const QModelIndex &parent);
+
+ bool dropMimeData(const QMimeData *data, Qt::DropAction action,
+ int row, int column, const QModelIndex &parent);
+ QMimeData *mimeData(const QModelIndexList &indexes) const;
+ QStringList mimeTypes() const;
+ int rowCount(const QModelIndex &parent) const;
+ Qt::DropActions supportedDropActions() const;
+
+ void addPiece(const QPixmap &pixmap, const QPoint &location);
+ void addPieces(const QPixmap& pixmap);
+
+private:
+ QList<QPoint> locations;
+ QList<QPixmap> pixmaps;
+
+ int m_PieceSize;
+};
+
+#endif
diff --git a/examples/widgets/itemviews/puzzle/puzzle.desktop b/examples/widgets/itemviews/puzzle/puzzle.desktop
new file mode 100644
index 0000000000..d493e7dd41
--- /dev/null
+++ b/examples/widgets/itemviews/puzzle/puzzle.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Item Views Puzzle
+Exec=/opt/usr/bin/puzzle
+Icon=puzzle
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/puzzle/puzzle.pro b/examples/widgets/itemviews/puzzle/puzzle.pro
new file mode 100644
index 0000000000..3f76bd8fd5
--- /dev/null
+++ b/examples/widgets/itemviews/puzzle/puzzle.pro
@@ -0,0 +1,22 @@
+HEADERS = mainwindow.h \
+ piecesmodel.h \
+ puzzlewidget.h
+RESOURCES = puzzle.qrc
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ piecesmodel.cpp \
+ puzzlewidget.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/puzzle
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.jpg
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/puzzle
+INSTALLS += target sources
+
+
+wince* {
+ DEPLOYMENT_PLUGIN += qjpeg qgif
+}
+
+QT += widgets
+
diff --git a/examples/widgets/itemviews/puzzle/puzzle.qrc b/examples/widgets/itemviews/puzzle/puzzle.qrc
new file mode 100644
index 0000000000..4076cec026
--- /dev/null
+++ b/examples/widgets/itemviews/puzzle/puzzle.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/images">
+ <file>example.jpg</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/itemviews/puzzle/puzzlewidget.cpp b/examples/widgets/itemviews/puzzle/puzzlewidget.cpp
new file mode 100644
index 0000000000..96d8c6068f
--- /dev/null
+++ b/examples/widgets/itemviews/puzzle/puzzlewidget.cpp
@@ -0,0 +1,214 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "puzzlewidget.h"
+
+PuzzleWidget::PuzzleWidget(int imageSize, QWidget *parent)
+ : QWidget(parent), m_ImageSize(imageSize)
+{
+ setAcceptDrops(true);
+ setMinimumSize(m_ImageSize, m_ImageSize);
+ setMaximumSize(m_ImageSize, m_ImageSize);
+}
+
+void PuzzleWidget::clear()
+{
+ pieceLocations.clear();
+ piecePixmaps.clear();
+ pieceRects.clear();
+ highlightedRect = QRect();
+ inPlace = 0;
+ update();
+}
+
+void PuzzleWidget::dragEnterEvent(QDragEnterEvent *event)
+{
+ if (event->mimeData()->hasFormat("image/x-puzzle-piece"))
+ event->accept();
+ else
+ event->ignore();
+}
+
+void PuzzleWidget::dragLeaveEvent(QDragLeaveEvent *event)
+{
+ QRect updateRect = highlightedRect;
+ highlightedRect = QRect();
+ update(updateRect);
+ event->accept();
+}
+
+void PuzzleWidget::dragMoveEvent(QDragMoveEvent *event)
+{
+ QRect updateRect = highlightedRect.united(targetSquare(event->pos()));
+
+ if (event->mimeData()->hasFormat("image/x-puzzle-piece")
+ && findPiece(targetSquare(event->pos())) == -1) {
+
+ highlightedRect = targetSquare(event->pos());
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+ } else {
+ highlightedRect = QRect();
+ event->ignore();
+ }
+
+ update(updateRect);
+}
+
+void PuzzleWidget::dropEvent(QDropEvent *event)
+{
+ if (event->mimeData()->hasFormat("image/x-puzzle-piece")
+ && findPiece(targetSquare(event->pos())) == -1) {
+
+ QByteArray pieceData = event->mimeData()->data("image/x-puzzle-piece");
+ QDataStream stream(&pieceData, QIODevice::ReadOnly);
+ QRect square = targetSquare(event->pos());
+ QPixmap pixmap;
+ QPoint location;
+ stream >> pixmap >> location;
+
+ pieceLocations.append(location);
+ piecePixmaps.append(pixmap);
+ pieceRects.append(square);
+
+ highlightedRect = QRect();
+ update(square);
+
+ event->setDropAction(Qt::MoveAction);
+ event->accept();
+
+ if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize())) {
+ inPlace++;
+ if (inPlace == 25)
+ emit puzzleCompleted();
+ }
+ } else {
+ highlightedRect = QRect();
+ event->ignore();
+ }
+}
+
+int PuzzleWidget::findPiece(const QRect &pieceRect) const
+{
+ for (int i = 0; i < pieceRects.size(); ++i) {
+ if (pieceRect == pieceRects[i]) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+void PuzzleWidget::mousePressEvent(QMouseEvent *event)
+{
+ QRect square = targetSquare(event->pos());
+ int found = findPiece(square);
+
+ if (found == -1)
+ return;
+
+ QPoint location = pieceLocations[found];
+ QPixmap pixmap = piecePixmaps[found];
+ pieceLocations.removeAt(found);
+ piecePixmaps.removeAt(found);
+ pieceRects.removeAt(found);
+
+ if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize()))
+ inPlace--;
+
+ update(square);
+
+ QByteArray itemData;
+ QDataStream dataStream(&itemData, QIODevice::WriteOnly);
+
+ dataStream << pixmap << location;
+
+ QMimeData *mimeData = new QMimeData;
+ mimeData->setData("image/x-puzzle-piece", itemData);
+
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ drag->setHotSpot(event->pos() - square.topLeft());
+ drag->setPixmap(pixmap);
+
+ if (drag->start(Qt::MoveAction) == 0) {
+ pieceLocations.insert(found, location);
+ piecePixmaps.insert(found, pixmap);
+ pieceRects.insert(found, square);
+ update(targetSquare(event->pos()));
+
+ if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize()))
+ inPlace++;
+ }
+}
+
+void PuzzleWidget::paintEvent(QPaintEvent *event)
+{
+ QPainter painter;
+ painter.begin(this);
+ painter.fillRect(event->rect(), Qt::white);
+
+ if (highlightedRect.isValid()) {
+ painter.setBrush(QColor("#ffcccc"));
+ painter.setPen(Qt::NoPen);
+ painter.drawRect(highlightedRect.adjusted(0, 0, -1, -1));
+ }
+
+ for (int i = 0; i < pieceRects.size(); ++i) {
+ painter.drawPixmap(pieceRects[i], piecePixmaps[i]);
+ }
+ painter.end();
+}
+
+const QRect PuzzleWidget::targetSquare(const QPoint &position) const
+{
+ return QRect(position.x()/pieceSize() * pieceSize(), position.y()/pieceSize() * pieceSize(), pieceSize(), pieceSize());
+}
+
+int PuzzleWidget::pieceSize() const
+{
+ return m_ImageSize / 5;
+}
+
+int PuzzleWidget::imageSize() const
+{
+ return m_ImageSize;
+}
diff --git a/examples/widgets/itemviews/puzzle/puzzlewidget.h b/examples/widgets/itemviews/puzzle/puzzlewidget.h
new file mode 100644
index 0000000000..1c0fc77a5f
--- /dev/null
+++ b/examples/widgets/itemviews/puzzle/puzzlewidget.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PUZZLEWIDGET_H
+#define PUZZLEWIDGET_H
+
+#include <QList>
+#include <QPoint>
+#include <QPixmap>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QDragEnterEvent;
+class QDropEvent;
+class QMouseEvent;
+QT_END_NAMESPACE
+
+class PuzzleWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ PuzzleWidget(int imageSize, QWidget *parent = 0);
+ void clear();
+
+ int pieceSize() const;
+ int imageSize() const;
+
+signals:
+ void puzzleCompleted();
+
+protected:
+ void dragEnterEvent(QDragEnterEvent *event);
+ void dragLeaveEvent(QDragLeaveEvent *event);
+ void dragMoveEvent(QDragMoveEvent *event);
+ void dropEvent(QDropEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event);
+
+private:
+ int findPiece(const QRect &pieceRect) const;
+ const QRect targetSquare(const QPoint &position) const;
+
+ QList<QPixmap> piecePixmaps;
+ QList<QRect> pieceRects;
+ QList<QPoint> pieceLocations;
+ QRect highlightedRect;
+ int inPlace;
+ int m_ImageSize;
+};
+
+#endif
diff --git a/examples/widgets/itemviews/simpledommodel/domitem.cpp b/examples/widgets/itemviews/simpledommodel/domitem.cpp
new file mode 100644
index 0000000000..2d7ce5a31e
--- /dev/null
+++ b/examples/widgets/itemviews/simpledommodel/domitem.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtXml>
+
+#include "domitem.h"
+
+//! [0]
+DomItem::DomItem(QDomNode &node, int row, DomItem *parent)
+{
+ domNode = node;
+//! [0]
+ // Record the item's location within its parent.
+//! [1]
+ rowNumber = row;
+ parentItem = parent;
+}
+//! [1]
+
+//! [2]
+DomItem::~DomItem()
+{
+ QHash<int,DomItem*>::iterator it;
+ for (it = childItems.begin(); it != childItems.end(); ++it)
+ delete it.value();
+}
+//! [2]
+
+//! [3]
+QDomNode DomItem::node() const
+{
+ return domNode;
+}
+//! [3]
+
+//! [4]
+DomItem *DomItem::parent()
+{
+ return parentItem;
+}
+//! [4]
+
+//! [5]
+DomItem *DomItem::child(int i)
+{
+ if (childItems.contains(i))
+ return childItems[i];
+
+ if (i >= 0 && i < domNode.childNodes().count()) {
+ QDomNode childNode = domNode.childNodes().item(i);
+ DomItem *childItem = new DomItem(childNode, i, this);
+ childItems[i] = childItem;
+ return childItem;
+ }
+ return 0;
+}
+//! [5]
+
+//! [6]
+int DomItem::row()
+{
+ return rowNumber;
+}
+//! [6]
diff --git a/examples/widgets/itemviews/simpledommodel/domitem.h b/examples/widgets/itemviews/simpledommodel/domitem.h
new file mode 100644
index 0000000000..8e9da9dd27
--- /dev/null
+++ b/examples/widgets/itemviews/simpledommodel/domitem.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DOMITEM_H
+#define DOMITEM_H
+
+#include <QDomNode>
+#include <QHash>
+
+//! [0]
+class DomItem
+{
+public:
+ DomItem(QDomNode &node, int row, DomItem *parent = 0);
+ ~DomItem();
+ DomItem *child(int i);
+ DomItem *parent();
+ QDomNode node() const;
+ int row();
+
+private:
+ QDomNode domNode;
+ QHash<int,DomItem*> childItems;
+ DomItem *parentItem;
+ int rowNumber;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/simpledommodel/dommodel.cpp b/examples/widgets/itemviews/simpledommodel/dommodel.cpp
new file mode 100644
index 0000000000..75d4c3e723
--- /dev/null
+++ b/examples/widgets/itemviews/simpledommodel/dommodel.cpp
@@ -0,0 +1,189 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include <QtXml>
+
+#include "domitem.h"
+#include "dommodel.h"
+
+//! [0]
+DomModel::DomModel(QDomDocument document, QObject *parent)
+ : QAbstractItemModel(parent), domDocument(document)
+{
+ rootItem = new DomItem(domDocument, 0);
+}
+//! [0]
+
+//! [1]
+DomModel::~DomModel()
+{
+ delete rootItem;
+}
+//! [1]
+
+//! [2]
+int DomModel::columnCount(const QModelIndex &/*parent*/) const
+{
+ return 3;
+}
+//! [2]
+
+//! [3]
+QVariant DomModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ DomItem *item = static_cast<DomItem*>(index.internalPointer());
+
+ QDomNode node = item->node();
+//! [3] //! [4]
+ QStringList attributes;
+ QDomNamedNodeMap attributeMap = node.attributes();
+
+ switch (index.column()) {
+ case 0:
+ return node.nodeName();
+ case 1:
+ for (int i = 0; i < attributeMap.count(); ++i) {
+ QDomNode attribute = attributeMap.item(i);
+ attributes << attribute.nodeName() + "=\""
+ +attribute.nodeValue() + "\"";
+ }
+ return attributes.join(" ");
+ case 2:
+ return node.nodeValue().split("\n").join(" ");
+ default:
+ return QVariant();
+ }
+}
+//! [4]
+
+//! [5]
+Qt::ItemFlags DomModel::flags(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return 0;
+
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+}
+//! [5]
+
+//! [6]
+QVariant DomModel::headerData(int section, Qt::Orientation orientation,
+ int role) const
+{
+ if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
+ switch (section) {
+ case 0:
+ return tr("Name");
+ case 1:
+ return tr("Attributes");
+ case 2:
+ return tr("Value");
+ default:
+ return QVariant();
+ }
+ }
+
+ return QVariant();
+}
+//! [6]
+
+//! [7]
+QModelIndex DomModel::index(int row, int column, const QModelIndex &parent)
+ const
+{
+ if (!hasIndex(row, column, parent))
+ return QModelIndex();
+
+ DomItem *parentItem;
+
+ if (!parent.isValid())
+ parentItem = rootItem;
+ else
+ parentItem = static_cast<DomItem*>(parent.internalPointer());
+//! [7]
+
+//! [8]
+ DomItem *childItem = parentItem->child(row);
+ if (childItem)
+ return createIndex(row, column, childItem);
+ else
+ return QModelIndex();
+}
+//! [8]
+
+//! [9]
+QModelIndex DomModel::parent(const QModelIndex &child) const
+{
+ if (!child.isValid())
+ return QModelIndex();
+
+ DomItem *childItem = static_cast<DomItem*>(child.internalPointer());
+ DomItem *parentItem = childItem->parent();
+
+ if (!parentItem || parentItem == rootItem)
+ return QModelIndex();
+
+ return createIndex(parentItem->row(), 0, parentItem);
+}
+//! [9]
+
+//! [10]
+int DomModel::rowCount(const QModelIndex &parent) const
+{
+ if (parent.column() > 0)
+ return 0;
+
+ DomItem *parentItem;
+
+ if (!parent.isValid())
+ parentItem = rootItem;
+ else
+ parentItem = static_cast<DomItem*>(parent.internalPointer());
+
+ return parentItem->node().childNodes().count();
+}
+//! [10]
diff --git a/examples/widgets/itemviews/simpledommodel/dommodel.h b/examples/widgets/itemviews/simpledommodel/dommodel.h
new file mode 100644
index 0000000000..386f976f79
--- /dev/null
+++ b/examples/widgets/itemviews/simpledommodel/dommodel.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DOMMODEL_H
+#define DOMMODEL_H
+
+#include <QAbstractItemModel>
+#include <QDomDocument>
+#include <QModelIndex>
+#include <QVariant>
+
+class DomItem;
+
+//! [0]
+class DomModel : public QAbstractItemModel
+{
+ Q_OBJECT
+
+public:
+ DomModel(QDomDocument document, QObject *parent = 0);
+ ~DomModel();
+
+ QVariant data(const QModelIndex &index, int role) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+ QModelIndex index(int row, int column,
+ const QModelIndex &parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex &child) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+private:
+ QDomDocument domDocument;
+ DomItem *rootItem;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/simpledommodel/main.cpp b/examples/widgets/itemviews/simpledommodel/main.cpp
new file mode 100644
index 0000000000..e65d428bc6
--- /dev/null
+++ b/examples/widgets/itemviews/simpledommodel/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.resize(640, 480);
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/simpledommodel/mainwindow.cpp b/examples/widgets/itemviews/simpledommodel/mainwindow.cpp
new file mode 100644
index 0000000000..f84d8841e7
--- /dev/null
+++ b/examples/widgets/itemviews/simpledommodel/mainwindow.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDomDocument>
+#include <QFile>
+#include <QtWidgets>
+
+#include "dommodel.h"
+#include "mainwindow.h"
+
+MainWindow::MainWindow() : QMainWindow(), model(0)
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()),
+ QKeySequence::Open);
+ fileMenu->addAction(tr("E&xit"), this, SLOT(close()),
+ QKeySequence::Quit);
+
+ model = new DomModel(QDomDocument(), this);
+ view = new QTreeView(this);
+ view->setModel(model);
+
+ setCentralWidget(view);
+ setWindowTitle(tr("Simple DOM Model"));
+}
+
+void MainWindow::openFile()
+{
+ QString filePath = QFileDialog::getOpenFileName(this, tr("Open File"),
+ xmlPath, tr("XML files (*.xml);;HTML files (*.html);;"
+ "SVG files (*.svg);;User Interface files (*.ui)"));
+
+ if (!filePath.isEmpty()) {
+ QFile file(filePath);
+ if (file.open(QIODevice::ReadOnly)) {
+ QDomDocument document;
+ if (document.setContent(&file)) {
+ DomModel *newModel = new DomModel(document, this);
+ view->setModel(newModel);
+ delete model;
+ model = newModel;
+ xmlPath = filePath;
+ }
+ file.close();
+ }
+ }
+}
diff --git a/examples/widgets/itemviews/simpledommodel/mainwindow.h b/examples/widgets/itemviews/simpledommodel/mainwindow.h
new file mode 100644
index 0000000000..16e0b800f9
--- /dev/null
+++ b/examples/widgets/itemviews/simpledommodel/mainwindow.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QString>
+
+class DomModel;
+QT_BEGIN_NAMESPACE
+class QMenu;
+class QTreeView;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+public slots:
+ void openFile();
+
+private:
+ DomModel *model;
+ QMenu *fileMenu;
+ QString xmlPath;
+ QTreeView *view;
+};
+
+#endif
diff --git a/examples/widgets/itemviews/simpledommodel/simpledommodel.desktop b/examples/widgets/itemviews/simpledommodel/simpledommodel.desktop
new file mode 100644
index 0000000000..a53b896848
--- /dev/null
+++ b/examples/widgets/itemviews/simpledommodel/simpledommodel.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Simple DOM Model
+Exec=/opt/usr/bin/simpledommodel
+Icon=simpledommodel
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/simpledommodel/simpledommodel.pro b/examples/widgets/itemviews/simpledommodel/simpledommodel.pro
new file mode 100644
index 0000000000..2d30e71c1a
--- /dev/null
+++ b/examples/widgets/itemviews/simpledommodel/simpledommodel.pro
@@ -0,0 +1,16 @@
+HEADERS = domitem.h \
+ dommodel.h \
+ mainwindow.h
+SOURCES = domitem.cpp \
+ dommodel.cpp \
+ main.cpp \
+ mainwindow.cpp
+CONFIG += qt
+QT += xml widgets
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/simpledommodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/simpledommodel
+INSTALLS += target sources
+
diff --git a/examples/widgets/itemviews/simpletreemodel/default.txt b/examples/widgets/itemviews/simpletreemodel/default.txt
new file mode 100644
index 0000000000..2b2fb579ae
--- /dev/null
+++ b/examples/widgets/itemviews/simpletreemodel/default.txt
@@ -0,0 +1,40 @@
+Getting Started How to familiarize yourself with Qt Designer
+ Launching Designer Running the Qt Designer application
+ The User Interface How to interact with Qt Designer
+
+Designing a Component Creating a GUI for your application
+ Creating a Dialog How to create a dialog
+ Composing the Dialog Putting widgets into the dialog example
+ Creating a Layout Arranging widgets on a form
+ Signal and Slot Connections Making widget communicate with each other
+
+Using a Component in Your Application Generating code from forms
+ The Direct Approach Using a form without any adjustments
+ The Single Inheritance Approach Subclassing a form's base class
+ The Multiple Inheritance Approach Subclassing the form itself
+ Automatic Connections Connecting widgets using a naming scheme
+ A Dialog Without Auto-Connect How to connect widgets without a naming scheme
+ A Dialog With Auto-Connect Using automatic connections
+
+Form Editing Mode How to edit a form in Qt Designer
+ Managing Forms Loading and saving forms
+ Editing a Form Basic editing techniques
+ The Property Editor Changing widget properties
+ The Object Inspector Examining the hierarchy of objects on a form
+ Layouts Objects that arrange widgets on a form
+ Applying and Breaking Layouts Managing widgets in layouts
+ Horizontal and Vertical Layouts Standard row and column layouts
+ The Grid Layout Arranging widgets in a matrix
+ Previewing Forms Checking that the design works
+
+Using Containers How to group widgets together
+ General Features Common container features
+ Frames QFrame
+ Group Boxes QGroupBox
+ Stacked Widgets QStackedWidget
+ Tab Widgets QTabWidget
+ Toolbox Widgets QToolBox
+
+Connection Editing Mode Connecting widgets together with signals and slots
+ Connecting Objects Making connections in Qt Designer
+ Editing Connections Changing existing connections
diff --git a/examples/widgets/itemviews/simpletreemodel/main.cpp b/examples/widgets/itemviews/simpletreemodel/main.cpp
new file mode 100644
index 0000000000..a7dd720a2f
--- /dev/null
+++ b/examples/widgets/itemviews/simpletreemodel/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "treemodel.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(simpletreemodel);
+
+ QApplication app(argc, argv);
+
+ QFile file(":/default.txt");
+ file.open(QIODevice::ReadOnly);
+ TreeModel model(file.readAll());
+ file.close();
+
+ QTreeView view;
+ view.setModel(&model);
+ view.setWindowTitle(QObject::tr("Simple Tree Model"));
+ view.show();
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/simpletreemodel/simpletreemodel.desktop b/examples/widgets/itemviews/simpletreemodel/simpletreemodel.desktop
new file mode 100644
index 0000000000..361202f5c0
--- /dev/null
+++ b/examples/widgets/itemviews/simpletreemodel/simpletreemodel.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Simple Tree Model
+Exec=/opt/usr/bin/simpletreemodel
+Icon=simpletreemodel
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/simpletreemodel/simpletreemodel.pro b/examples/widgets/itemviews/simpletreemodel/simpletreemodel.pro
new file mode 100644
index 0000000000..cd4f8af604
--- /dev/null
+++ b/examples/widgets/itemviews/simpletreemodel/simpletreemodel.pro
@@ -0,0 +1,15 @@
+HEADERS = treeitem.h \
+ treemodel.h
+RESOURCES = simpletreemodel.qrc
+SOURCES = treeitem.cpp \
+ treemodel.cpp \
+ main.cpp
+CONFIG += qt
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/simpletreemodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.txt
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/simpletreemodel
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/itemviews/simpletreemodel/simpletreemodel.qrc b/examples/widgets/itemviews/simpletreemodel/simpletreemodel.qrc
new file mode 100644
index 0000000000..a8ecc98d28
--- /dev/null
+++ b/examples/widgets/itemviews/simpletreemodel/simpletreemodel.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>default.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/itemviews/simpletreemodel/treeitem.cpp b/examples/widgets/itemviews/simpletreemodel/treeitem.cpp
new file mode 100644
index 0000000000..a296f6ccd5
--- /dev/null
+++ b/examples/widgets/itemviews/simpletreemodel/treeitem.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ treeitem.cpp
+
+ A container for items of data supplied by the simple tree model.
+*/
+
+#include <QStringList>
+
+#include "treeitem.h"
+
+//! [0]
+TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
+{
+ parentItem = parent;
+ itemData = data;
+}
+//! [0]
+
+//! [1]
+TreeItem::~TreeItem()
+{
+ qDeleteAll(childItems);
+}
+//! [1]
+
+//! [2]
+void TreeItem::appendChild(TreeItem *item)
+{
+ childItems.append(item);
+}
+//! [2]
+
+//! [3]
+TreeItem *TreeItem::child(int row)
+{
+ return childItems.value(row);
+}
+//! [3]
+
+//! [4]
+int TreeItem::childCount() const
+{
+ return childItems.count();
+}
+//! [4]
+
+//! [5]
+int TreeItem::columnCount() const
+{
+ return itemData.count();
+}
+//! [5]
+
+//! [6]
+QVariant TreeItem::data(int column) const
+{
+ return itemData.value(column);
+}
+//! [6]
+
+//! [7]
+TreeItem *TreeItem::parent()
+{
+ return parentItem;
+}
+//! [7]
+
+//! [8]
+int TreeItem::row() const
+{
+ if (parentItem)
+ return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
+
+ return 0;
+}
+//! [8]
diff --git a/examples/widgets/itemviews/simpletreemodel/treeitem.h b/examples/widgets/itemviews/simpletreemodel/treeitem.h
new file mode 100644
index 0000000000..b2a7a83066
--- /dev/null
+++ b/examples/widgets/itemviews/simpletreemodel/treeitem.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TREEITEM_H
+#define TREEITEM_H
+
+#include <QList>
+#include <QVariant>
+
+//! [0]
+class TreeItem
+{
+public:
+ TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
+ ~TreeItem();
+
+ void appendChild(TreeItem *child);
+
+ TreeItem *child(int row);
+ int childCount() const;
+ int columnCount() const;
+ QVariant data(int column) const;
+ int row() const;
+ TreeItem *parent();
+
+private:
+ QList<TreeItem*> childItems;
+ QList<QVariant> itemData;
+ TreeItem *parentItem;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/simpletreemodel/treemodel.cpp b/examples/widgets/itemviews/simpletreemodel/treemodel.cpp
new file mode 100644
index 0000000000..1fad9ba347
--- /dev/null
+++ b/examples/widgets/itemviews/simpletreemodel/treemodel.cpp
@@ -0,0 +1,218 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ treemodel.cpp
+
+ Provides a simple tree model to show how to create and use hierarchical
+ models.
+*/
+
+#include <QtWidgets>
+
+#include "treeitem.h"
+#include "treemodel.h"
+
+//! [0]
+TreeModel::TreeModel(const QString &data, QObject *parent)
+ : QAbstractItemModel(parent)
+{
+ QList<QVariant> rootData;
+ rootData << "Title" << "Summary";
+ rootItem = new TreeItem(rootData);
+ setupModelData(data.split(QString("\n")), rootItem);
+}
+//! [0]
+
+//! [1]
+TreeModel::~TreeModel()
+{
+ delete rootItem;
+}
+//! [1]
+
+//! [2]
+int TreeModel::columnCount(const QModelIndex &parent) const
+{
+ if (parent.isValid())
+ return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
+ else
+ return rootItem->columnCount();
+}
+//! [2]
+
+//! [3]
+QVariant TreeModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
+
+ return item->data(index.column());
+}
+//! [3]
+
+//! [4]
+Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return 0;
+
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+}
+//! [4]
+
+//! [5]
+QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
+ int role) const
+{
+ if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
+ return rootItem->data(section);
+
+ return QVariant();
+}
+//! [5]
+
+//! [6]
+QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
+ const
+{
+ if (!hasIndex(row, column, parent))
+ return QModelIndex();
+
+ TreeItem *parentItem;
+
+ if (!parent.isValid())
+ parentItem = rootItem;
+ else
+ parentItem = static_cast<TreeItem*>(parent.internalPointer());
+
+ TreeItem *childItem = parentItem->child(row);
+ if (childItem)
+ return createIndex(row, column, childItem);
+ else
+ return QModelIndex();
+}
+//! [6]
+
+//! [7]
+QModelIndex TreeModel::parent(const QModelIndex &index) const
+{
+ if (!index.isValid())
+ return QModelIndex();
+
+ TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
+ TreeItem *parentItem = childItem->parent();
+
+ if (parentItem == rootItem)
+ return QModelIndex();
+
+ return createIndex(parentItem->row(), 0, parentItem);
+}
+//! [7]
+
+//! [8]
+int TreeModel::rowCount(const QModelIndex &parent) const
+{
+ TreeItem *parentItem;
+ if (parent.column() > 0)
+ return 0;
+
+ if (!parent.isValid())
+ parentItem = rootItem;
+ else
+ parentItem = static_cast<TreeItem*>(parent.internalPointer());
+
+ return parentItem->childCount();
+}
+//! [8]
+
+void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
+{
+ QList<TreeItem*> parents;
+ QList<int> indentations;
+ parents << parent;
+ indentations << 0;
+
+ int number = 0;
+
+ while (number < lines.count()) {
+ int position = 0;
+ while (position < lines[number].length()) {
+ if (lines[number].mid(position, 1) != " ")
+ break;
+ position++;
+ }
+
+ QString lineData = lines[number].mid(position).trimmed();
+
+ if (!lineData.isEmpty()) {
+ // Read the column data from the rest of the line.
+ QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts);
+ QList<QVariant> columnData;
+ for (int column = 0; column < columnStrings.count(); ++column)
+ columnData << columnStrings[column];
+
+ if (position > indentations.last()) {
+ // The last child of the current parent is now the new parent
+ // unless the current parent has no children.
+
+ if (parents.last()->childCount() > 0) {
+ parents << parents.last()->child(parents.last()->childCount()-1);
+ indentations << position;
+ }
+ } else {
+ while (position < indentations.last() && parents.count() > 0) {
+ parents.pop_back();
+ indentations.pop_back();
+ }
+ }
+
+ // Append a new item to the current parent's list of children.
+ parents.last()->appendChild(new TreeItem(columnData, parents.last()));
+ }
+
+ number++;
+ }
+}
diff --git a/examples/widgets/itemviews/simpletreemodel/treemodel.h b/examples/widgets/itemviews/simpletreemodel/treemodel.h
new file mode 100644
index 0000000000..9cf870c0fc
--- /dev/null
+++ b/examples/widgets/itemviews/simpletreemodel/treemodel.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TREEMODEL_H
+#define TREEMODEL_H
+
+#include <QAbstractItemModel>
+#include <QModelIndex>
+#include <QVariant>
+
+class TreeItem;
+
+//! [0]
+class TreeModel : public QAbstractItemModel
+{
+ Q_OBJECT
+
+public:
+ TreeModel(const QString &data, QObject *parent = 0);
+ ~TreeModel();
+
+ QVariant data(const QModelIndex &index, int role) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+ QModelIndex index(int row, int column,
+ const QModelIndex &parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex &index) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+private:
+ void setupModelData(const QStringList &lines, TreeItem *parent);
+
+ TreeItem *rootItem;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/simplewidgetmapper/main.cpp b/examples/widgets/itemviews/simplewidgetmapper/main.cpp
new file mode 100644
index 0000000000..0fc4966ccf
--- /dev/null
+++ b/examples/widgets/itemviews/simplewidgetmapper/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.desktop b/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.desktop
new file mode 100644
index 0000000000..6b09a236da
--- /dev/null
+++ b/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Simple Widget Mapper
+Exec=/opt/usr/bin/simplewidgetmapper
+Icon=simplewidgetmapper
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro b/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro
new file mode 100644
index 0000000000..3b2fd8b257
--- /dev/null
+++ b/examples/widgets/itemviews/simplewidgetmapper/simplewidgetmapper.pro
@@ -0,0 +1,11 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/simplewidgetmapper
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/simplewidgetmapper
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/itemviews/simplewidgetmapper/window.cpp b/examples/widgets/itemviews/simplewidgetmapper/window.cpp
new file mode 100644
index 0000000000..5b5ed8f231
--- /dev/null
+++ b/examples/widgets/itemviews/simplewidgetmapper/window.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "window.h"
+
+//! [Set up widgets]
+Window::Window(QWidget *parent)
+ : QWidget(parent)
+{
+ setupModel();
+
+ nameLabel = new QLabel(tr("Na&me:"));
+ nameEdit = new QLineEdit();
+ addressLabel = new QLabel(tr("&Address:"));
+ addressEdit = new QTextEdit();
+ ageLabel = new QLabel(tr("A&ge (in years):"));
+ ageSpinBox = new QSpinBox();
+ nextButton = new QPushButton(tr("&Next"));
+ previousButton = new QPushButton(tr("&Previous"));
+
+ nameLabel->setBuddy(nameEdit);
+ addressLabel->setBuddy(addressEdit);
+ ageLabel->setBuddy(ageSpinBox);
+//! [Set up widgets]
+
+//! [Set up the mapper]
+ mapper = new QDataWidgetMapper(this);
+ mapper->setModel(model);
+ mapper->addMapping(nameEdit, 0);
+ mapper->addMapping(addressEdit, 1);
+ mapper->addMapping(ageSpinBox, 2);
+
+ connect(previousButton, SIGNAL(clicked()),
+ mapper, SLOT(toPrevious()));
+ connect(nextButton, SIGNAL(clicked()),
+ mapper, SLOT(toNext()));
+ connect(mapper, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(updateButtons(int)));
+//! [Set up the mapper]
+
+//! [Set up the layout]
+ QGridLayout *layout = new QGridLayout();
+ layout->addWidget(nameLabel, 0, 0, 1, 1);
+ layout->addWidget(nameEdit, 0, 1, 1, 1);
+ layout->addWidget(previousButton, 0, 2, 1, 1);
+ layout->addWidget(addressLabel, 1, 0, 1, 1);
+ layout->addWidget(addressEdit, 1, 1, 2, 1);
+ layout->addWidget(nextButton, 1, 2, 1, 1);
+ layout->addWidget(ageLabel, 3, 0, 1, 1);
+ layout->addWidget(ageSpinBox, 3, 1, 1, 1);
+ setLayout(layout);
+
+ setWindowTitle(tr("Simple Widget Mapper"));
+ mapper->toFirst();
+}
+//! [Set up the layout]
+
+//! [Set up the model]
+void Window::setupModel()
+{
+ model = new QStandardItemModel(5, 3, this);
+
+ QStringList names;
+ names << "Alice" << "Bob" << "Carol" << "Donald" << "Emma";
+
+ QStringList addresses;
+ addresses << "<qt>123 Main Street<br/>Market Town</qt>"
+ << "<qt>PO Box 32<br/>Mail Handling Service"
+ "<br/>Service City</qt>"
+ << "<qt>The Lighthouse<br/>Remote Island</qt>"
+ << "<qt>47338 Park Avenue<br/>Big City</qt>"
+ << "<qt>Research Station<br/>Base Camp<br/>Big Mountain</qt>";
+
+ QStringList ages;
+ ages << "20" << "31" << "32" << "19" << "26";
+
+ for (int row = 0; row < 5; ++row) {
+ QStandardItem *item = new QStandardItem(names[row]);
+ model->setItem(row, 0, item);
+ item = new QStandardItem(addresses[row]);
+ model->setItem(row, 1, item);
+ item = new QStandardItem(ages[row]);
+ model->setItem(row, 2, item);
+ }
+}
+//! [Set up the model]
+
+//! [Slot for updating the buttons]
+void Window::updateButtons(int row)
+{
+ previousButton->setEnabled(row > 0);
+ nextButton->setEnabled(row < model->rowCount() - 1);
+}
+//! [Slot for updating the buttons]
diff --git a/examples/widgets/itemviews/simplewidgetmapper/window.h b/examples/widgets/itemviews/simplewidgetmapper/window.h
new file mode 100644
index 0000000000..77772e522f
--- /dev/null
+++ b/examples/widgets/itemviews/simplewidgetmapper/window.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QDataWidgetMapper;
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QSpinBox;
+class QStandardItemModel;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [Window definition]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window(QWidget *parent = 0);
+
+private slots:
+ void updateButtons(int row);
+
+private:
+ void setupModel();
+
+ QLabel *nameLabel;
+ QLabel *addressLabel;
+ QLabel *ageLabel;
+ QLineEdit *nameEdit;
+ QTextEdit *addressEdit;
+ QSpinBox *ageSpinBox;
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+
+ QStandardItemModel *model;
+ QDataWidgetMapper *mapper;
+};
+//! [Window definition]
+
+#endif
diff --git a/examples/widgets/itemviews/spinboxdelegate/delegate.cpp b/examples/widgets/itemviews/spinboxdelegate/delegate.cpp
new file mode 100644
index 0000000000..2967b6ae38
--- /dev/null
+++ b/examples/widgets/itemviews/spinboxdelegate/delegate.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ delegate.cpp
+
+ A delegate that allows the user to change integer values from the model
+ using a spin box widget.
+*/
+
+#include <QtWidgets>
+
+#include "delegate.h"
+
+
+//! [0]
+SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
+ : QItemDelegate(parent)
+{
+}
+//! [0]
+
+//! [1]
+QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem &/* option */,
+ const QModelIndex &/* index */) const
+{
+ QSpinBox *editor = new QSpinBox(parent);
+ editor->setMinimum(0);
+ editor->setMaximum(100);
+
+ return editor;
+}
+//! [1]
+
+//! [2]
+void SpinBoxDelegate::setEditorData(QWidget *editor,
+ const QModelIndex &index) const
+{
+ int value = index.model()->data(index, Qt::EditRole).toInt();
+
+ QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
+ spinBox->setValue(value);
+}
+//! [2]
+
+//! [3]
+void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const
+{
+ QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
+ spinBox->interpretText();
+ int value = spinBox->value();
+
+ model->setData(index, value, Qt::EditRole);
+}
+//! [3]
+
+//! [4]
+void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
+{
+ editor->setGeometry(option.rect);
+}
+//! [4]
diff --git a/examples/widgets/itemviews/spinboxdelegate/delegate.h b/examples/widgets/itemviews/spinboxdelegate/delegate.h
new file mode 100644
index 0000000000..19d647043d
--- /dev/null
+++ b/examples/widgets/itemviews/spinboxdelegate/delegate.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DELEGATE_H
+#define DELEGATE_H
+
+#include <QItemDelegate>
+#include <QModelIndex>
+#include <QObject>
+#include <QSize>
+#include <QSpinBox>
+
+//! [0]
+class SpinBoxDelegate : public QItemDelegate
+{
+ Q_OBJECT
+
+public:
+ SpinBoxDelegate(QObject *parent = 0);
+
+ QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+
+ void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ void setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const;
+
+ void updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem &option, const QModelIndex &index) const;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/spinboxdelegate/main.cpp b/examples/widgets/itemviews/spinboxdelegate/main.cpp
new file mode 100644
index 0000000000..6fdffad3ac
--- /dev/null
+++ b/examples/widgets/itemviews/spinboxdelegate/main.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ main.cpp
+
+ A simple example that shows how a view can use a custom delegate to edit
+ data obtained from a model.
+*/
+
+#include <QApplication>
+#include <QHeaderView>
+#include <QItemSelectionModel>
+#include <QStandardItemModel>
+#include <QTableView>
+
+#include "delegate.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QStandardItemModel model(4, 2);
+ QTableView tableView;
+ tableView.setModel(&model);
+
+ SpinBoxDelegate delegate;
+ tableView.setItemDelegate(&delegate);
+//! [0]
+
+ tableView.horizontalHeader()->setStretchLastSection(true);
+
+//! [1]
+ for (int row = 0; row < 4; ++row) {
+ for (int column = 0; column < 2; ++column) {
+ QModelIndex index = model.index(row, column, QModelIndex());
+ model.setData(index, QVariant((row+1) * (column+1)));
+ }
+//! [1] //! [2]
+ }
+//! [2]
+
+//! [3]
+ tableView.setWindowTitle(QObject::tr("Spin Box Delegate"));
+ tableView.show();
+ return app.exec();
+}
+//! [3]
diff --git a/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.desktop b/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.desktop
new file mode 100644
index 0000000000..347e408e96
--- /dev/null
+++ b/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Spin Box Delegate
+Exec=/opt/usr/bin/spinboxdelegate
+Icon=spinboxdelegate
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro b/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro
new file mode 100644
index 0000000000..f6416ff936
--- /dev/null
+++ b/examples/widgets/itemviews/spinboxdelegate/spinboxdelegate.pro
@@ -0,0 +1,13 @@
+HEADERS = delegate.h
+SOURCES = delegate.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/spinboxdelegate
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/spinboxdelegate
+INSTALLS += target sources
+
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/itemviews/spreadsheet/images/interview.png b/examples/widgets/itemviews/spreadsheet/images/interview.png
new file mode 100644
index 0000000000..0c3d690258
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/images/interview.png
Binary files differ
diff --git a/examples/widgets/itemviews/spreadsheet/main.cpp b/examples/widgets/itemviews/spreadsheet/main.cpp
new file mode 100644
index 0000000000..92b890f735
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets/QApplication>
+#include "spreadsheet.h"
+
+int main(int argc, char** argv) {
+ Q_INIT_RESOURCE(spreadsheet);
+ QApplication app(argc, argv);
+ SpreadSheet sheet(10, 6);
+ sheet.setWindowIcon(QPixmap(":/images/interview.png"));
+ sheet.resize(640, 420);
+ sheet.show();
+ return app.exec();
+}
+
+
diff --git a/examples/widgets/itemviews/spreadsheet/printview.cpp b/examples/widgets/itemviews/spreadsheet/printview.cpp
new file mode 100644
index 0000000000..fe94fde63c
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/printview.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "printview.h"
+
+#ifndef QT_NO_PRINTER
+#include <QPrinter>
+#endif
+#include <QStyleOptionViewItem>
+
+PrintView::PrintView()
+{
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+}
+
+void PrintView::print(QPrinter *printer)
+{
+#ifndef QT_NO_PRINTER
+ resize(printer->width(), printer->height());
+ render(printer);
+#endif
+}
+
diff --git a/examples/widgets/itemviews/spreadsheet/printview.h b/examples/widgets/itemviews/spreadsheet/printview.h
new file mode 100644
index 0000000000..c7674f88ce
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/printview.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PRINTVIEW_H
+#define PRINTVIEW_H
+
+#include <QTableView>
+QT_BEGIN_NAMESPACE
+class QPrinter;
+QT_END_NAMESPACE
+
+class PrintView : public QTableView
+{
+ Q_OBJECT
+
+public:
+ PrintView();
+
+public Q_SLOTS:
+ void print(QPrinter *printer);
+};
+
+#endif // PRINTVIEW_H
+
+
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp
new file mode 100644
index 0000000000..5dff7dc059
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp
@@ -0,0 +1,639 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#ifndef QT_NO_PRINTER
+#include <QPrinter>
+#include <QPrintDialog>
+#include <QPrintPreviewDialog>
+#endif
+
+#include "spreadsheet.h"
+#include "spreadsheetdelegate.h"
+#include "spreadsheetitem.h"
+#include "printview.h"
+
+SpreadSheet::SpreadSheet(int rows, int cols, QWidget *parent)
+ : QMainWindow(parent)
+{
+ addToolBar(toolBar = new QToolBar());
+ formulaInput = new QLineEdit();
+
+ cellLabel = new QLabel(toolBar);
+ cellLabel->setMinimumSize(80, 0);
+
+ toolBar->addWidget(cellLabel);
+ toolBar->addWidget(formulaInput);
+
+ table = new QTableWidget(rows, cols, this);
+ for (int c = 0; c < cols; ++c) {
+ QString character(QChar('A' + c));
+ table->setHorizontalHeaderItem(c, new QTableWidgetItem(character));
+ }
+
+ table->setItemPrototype(table->item(rows -1, cols - 1));
+ table->setItemDelegate(new SpreadSheetDelegate());
+
+ createActions();
+ updateColor(0);
+ setupMenuBar();
+ setupContents();
+ setupContextMenu();
+ setCentralWidget(table);
+
+ statusBar();
+ connect(table, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)),
+ this, SLOT(updateStatus(QTableWidgetItem*)));
+ connect(table, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)),
+ this, SLOT(updateColor(QTableWidgetItem*)));
+ connect(table, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)),
+ this, SLOT(updateLineEdit(QTableWidgetItem*)));
+ connect(table, SIGNAL(itemChanged(QTableWidgetItem*)),
+ this, SLOT(updateStatus(QTableWidgetItem*)));
+ connect(formulaInput, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
+ connect(table, SIGNAL(itemChanged(QTableWidgetItem*)),
+ this, SLOT(updateLineEdit(QTableWidgetItem*)));
+
+ setWindowTitle(tr("Spreadsheet"));
+}
+
+void SpreadSheet::createActions()
+{
+ cell_sumAction = new QAction(tr("Sum"), this);
+ connect(cell_sumAction, SIGNAL(triggered()), this, SLOT(actionSum()));
+
+ cell_addAction = new QAction(tr("&Add"), this);
+ cell_addAction->setShortcut(Qt::CTRL | Qt::Key_Plus);
+ connect(cell_addAction, SIGNAL(triggered()), this, SLOT(actionAdd()));
+
+ cell_subAction = new QAction(tr("&Subtract"), this);
+ cell_subAction->setShortcut(Qt::CTRL | Qt::Key_Minus);
+ connect(cell_subAction, SIGNAL(triggered()), this, SLOT(actionSubtract()));
+
+ cell_mulAction = new QAction(tr("&Multiply"), this);
+ cell_mulAction->setShortcut(Qt::CTRL | Qt::Key_multiply);
+ connect(cell_mulAction, SIGNAL(triggered()), this, SLOT(actionMultiply()));
+
+ cell_divAction = new QAction(tr("&Divide"), this);
+ cell_divAction->setShortcut(Qt::CTRL | Qt::Key_division);
+ connect(cell_divAction, SIGNAL(triggered()), this, SLOT(actionDivide()));
+
+ fontAction = new QAction(tr("Font..."), this);
+ fontAction->setShortcut(Qt::CTRL | Qt::Key_F);
+ connect(fontAction, SIGNAL(triggered()), this, SLOT(selectFont()));
+
+ colorAction = new QAction(QPixmap(16, 16), tr("Background &Color..."), this);
+ connect(colorAction, SIGNAL(triggered()), this, SLOT(selectColor()));
+
+ clearAction = new QAction(tr("Clear"), this);
+ clearAction->setShortcut(Qt::Key_Delete);
+ connect(clearAction, SIGNAL(triggered()), this, SLOT(clear()));
+
+ aboutSpreadSheet = new QAction(tr("About Spreadsheet"), this);
+ connect(aboutSpreadSheet, SIGNAL(triggered()), this, SLOT(showAbout()));
+
+ exitAction = new QAction(tr("E&xit"), this);
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ printAction = new QAction(tr("&Print"), this);
+ connect(printAction, SIGNAL(triggered()), this, SLOT(print()));
+
+ firstSeparator = new QAction(this);
+ firstSeparator->setSeparator(true);
+
+ secondSeparator = new QAction(this);
+ secondSeparator->setSeparator(true);
+}
+
+void SpreadSheet::setupMenuBar()
+{
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(printAction);
+ fileMenu->addAction(exitAction);
+
+ QMenu *cellMenu = menuBar()->addMenu(tr("&Cell"));
+ cellMenu->addAction(cell_addAction);
+ cellMenu->addAction(cell_subAction);
+ cellMenu->addAction(cell_mulAction);
+ cellMenu->addAction(cell_divAction);
+ cellMenu->addAction(cell_sumAction);
+ cellMenu->addSeparator();
+ cellMenu->addAction(colorAction);
+ cellMenu->addAction(fontAction);
+
+ menuBar()->addSeparator();
+
+ QMenu *aboutMenu = menuBar()->addMenu(tr("&Help"));
+ aboutMenu->addAction(aboutSpreadSheet);
+}
+
+void SpreadSheet::updateStatus(QTableWidgetItem *item)
+{
+ if (item && item == table->currentItem()) {
+ statusBar()->showMessage(item->data(Qt::StatusTipRole).toString(),
+ 1000);
+ cellLabel->setText(tr("Cell: (%1)").arg(encode_pos(table->row(item),
+ table->column(item))));
+ }
+}
+
+void SpreadSheet::updateColor(QTableWidgetItem *item)
+{
+ QPixmap pix(16, 16);
+ QColor col;
+ if (item)
+ col = item->backgroundColor();
+ if (!col.isValid())
+ col = palette().base().color();
+
+ QPainter pt(&pix);
+ pt.fillRect(0, 0, 16, 16, col);
+
+ QColor lighter = col.light();
+ pt.setPen(lighter);
+ QPoint lightFrame[] = { QPoint(0, 15), QPoint(0, 0), QPoint(15, 0) };
+ pt.drawPolyline(lightFrame, 3);
+
+ pt.setPen(col.dark());
+ QPoint darkFrame[] = { QPoint(1, 15), QPoint(15, 15), QPoint(15, 1) };
+ pt.drawPolyline(darkFrame, 3);
+
+ pt.end();
+
+ colorAction->setIcon(pix);
+}
+
+void SpreadSheet::updateLineEdit(QTableWidgetItem *item)
+{
+ if (item != table->currentItem())
+ return;
+ if (item)
+ formulaInput->setText(item->data(Qt::EditRole).toString());
+ else
+ formulaInput->clear();
+}
+
+void SpreadSheet::returnPressed()
+{
+ QString text = formulaInput->text();
+ int row = table->currentRow();
+ int col = table->currentColumn();
+ QTableWidgetItem *item = table->item(row, col);
+ if (!item)
+ table->setItem(row, col, new SpreadSheetItem(text));
+ else
+ item->setData(Qt::EditRole, text);
+ table->viewport()->update();
+}
+
+void SpreadSheet::selectColor()
+{
+ QTableWidgetItem *item = table->currentItem();
+ QColor col = item ? item->backgroundColor() : table->palette().base().color();
+ col = QColorDialog::getColor(col, this);
+ if (!col.isValid())
+ return;
+
+ QList<QTableWidgetItem*> selected = table->selectedItems();
+ if (selected.count() == 0)
+ return;
+
+ foreach(QTableWidgetItem *i, selected)
+ if (i)
+ i->setBackgroundColor(col);
+
+ updateColor(table->currentItem());
+}
+
+void SpreadSheet::selectFont()
+{
+ QList<QTableWidgetItem*> selected = table->selectedItems();
+ if (selected.count() == 0)
+ return;
+
+ bool ok = false;
+ QFont fnt = QFontDialog::getFont(&ok, font(), this);
+
+ if (!ok)
+ return;
+ foreach(QTableWidgetItem *i, selected)
+ if (i)
+ i->setFont(fnt);
+}
+
+bool SpreadSheet::runInputDialog(const QString &title,
+ const QString &c1Text,
+ const QString &c2Text,
+ const QString &opText,
+ const QString &outText,
+ QString *cell1, QString *cell2, QString *outCell)
+{
+ QStringList rows, cols;
+ for (int c = 0; c < table->columnCount(); ++c)
+ cols << QChar('A' + c);
+ for (int r = 0; r < table->rowCount(); ++r)
+ rows << QString::number(1 + r);
+
+ QDialog addDialog(this);
+ addDialog.setWindowTitle(title);
+
+ QGroupBox group(title, &addDialog);
+ group.setMinimumSize(250, 100);
+
+ QLabel cell1Label(c1Text, &group);
+ QComboBox cell1RowInput(&group);
+ int c1Row, c1Col;
+ decode_pos(*cell1, &c1Row, &c1Col);
+ cell1RowInput.addItems(rows);
+ cell1RowInput.setCurrentIndex(c1Row);
+
+ QComboBox cell1ColInput(&group);
+ cell1ColInput.addItems(cols);
+ cell1ColInput.setCurrentIndex(c1Col);
+
+ QLabel operatorLabel(opText, &group);
+ operatorLabel.setAlignment(Qt::AlignHCenter);
+
+ QLabel cell2Label(c2Text, &group);
+ QComboBox cell2RowInput(&group);
+ int c2Row, c2Col;
+ decode_pos(*cell2, &c2Row, &c2Col);
+ cell2RowInput.addItems(rows);
+ cell2RowInput.setCurrentIndex(c2Row);
+ QComboBox cell2ColInput(&group);
+ cell2ColInput.addItems(cols);
+ cell2ColInput.setCurrentIndex(c2Col);
+
+ QLabel equalsLabel("=", &group);
+ equalsLabel.setAlignment(Qt::AlignHCenter);
+
+ QLabel outLabel(outText, &group);
+ QComboBox outRowInput(&group);
+ int outRow, outCol;
+ decode_pos(*outCell, &outRow, &outCol);
+ outRowInput.addItems(rows);
+ outRowInput.setCurrentIndex(outRow);
+ QComboBox outColInput(&group);
+ outColInput.addItems(cols);
+ outColInput.setCurrentIndex(outCol);
+
+ QPushButton cancelButton(tr("Cancel"), &addDialog);
+ connect(&cancelButton, SIGNAL(clicked()), &addDialog, SLOT(reject()));
+
+ QPushButton okButton(tr("OK"), &addDialog);
+ okButton.setDefault(true);
+ connect(&okButton, SIGNAL(clicked()), &addDialog, SLOT(accept()));
+
+ QHBoxLayout *buttonsLayout = new QHBoxLayout;
+ buttonsLayout->addStretch(1);
+ buttonsLayout->addWidget(&okButton);
+ buttonsLayout->addSpacing(10);
+ buttonsLayout->addWidget(&cancelButton);
+
+ QVBoxLayout *dialogLayout = new QVBoxLayout(&addDialog);
+ dialogLayout->addWidget(&group);
+ dialogLayout->addStretch(1);
+ dialogLayout->addItem(buttonsLayout);
+
+ QHBoxLayout *cell1Layout = new QHBoxLayout;
+ cell1Layout->addWidget(&cell1Label);
+ cell1Layout->addSpacing(10);
+ cell1Layout->addWidget(&cell1ColInput);
+ cell1Layout->addSpacing(10);
+ cell1Layout->addWidget(&cell1RowInput);
+
+ QHBoxLayout *cell2Layout = new QHBoxLayout;
+ cell2Layout->addWidget(&cell2Label);
+ cell2Layout->addSpacing(10);
+ cell2Layout->addWidget(&cell2ColInput);
+ cell2Layout->addSpacing(10);
+ cell2Layout->addWidget(&cell2RowInput);
+
+ QHBoxLayout *outLayout = new QHBoxLayout;
+ outLayout->addWidget(&outLabel);
+ outLayout->addSpacing(10);
+ outLayout->addWidget(&outColInput);
+ outLayout->addSpacing(10);
+ outLayout->addWidget(&outRowInput);
+
+ QVBoxLayout *vLayout = new QVBoxLayout(&group);
+ vLayout->addItem(cell1Layout);
+ vLayout->addWidget(&operatorLabel);
+ vLayout->addItem(cell2Layout);
+ vLayout->addWidget(&equalsLabel);
+ vLayout->addStretch(1);
+ vLayout->addItem(outLayout);
+
+ if (addDialog.exec()) {
+ *cell1 = cell1ColInput.currentText() + cell1RowInput.currentText();
+ *cell2 = cell2ColInput.currentText() + cell2RowInput.currentText();
+ *outCell = outColInput.currentText() + outRowInput.currentText();
+ return true;
+ }
+
+ return false;
+}
+
+void SpreadSheet::actionSum()
+{
+ int row_first = 0;
+ int row_last = 0;
+ int row_cur = 0;
+
+ int col_first = 0;
+ int col_last = 0;
+ int col_cur = 0;
+
+ QList<QTableWidgetItem*> selected = table->selectedItems();
+
+ if (!selected.isEmpty()) {
+ QTableWidgetItem *first = selected.first();
+ QTableWidgetItem *last = selected.last();
+ row_first = table->row(first);
+ row_last = table->row(last);
+ col_first = table->column(first);
+ col_last = table->column(last);
+ }
+
+ QTableWidgetItem *current = table->currentItem();
+
+ if (current) {
+ row_cur = table->row(current);
+ col_cur = table->column(current);
+ }
+
+ QString cell1 = encode_pos(row_first, col_first);
+ QString cell2 = encode_pos(row_last, col_last);
+ QString out = encode_pos(row_cur, col_cur);
+
+ if (runInputDialog(tr("Sum cells"), tr("First cell:"), tr("Last cell:"),
+ QString("%1").arg(QChar(0x03a3)), tr("Output to:"),
+ &cell1, &cell2, &out)) {
+ int row, col;
+ decode_pos(out, &row, &col);
+ table->item(row, col)->setText(tr("sum %1 %2").arg(cell1, cell2));
+ }
+}
+
+void SpreadSheet::actionMath_helper(const QString &title, const QString &op)
+{
+ QString cell1 = "C1";
+ QString cell2 = "C2";
+ QString out = "C3";
+
+ QTableWidgetItem *current = table->currentItem();
+ if (current)
+ out = encode_pos(table->currentRow(), table->currentColumn());
+
+ if (runInputDialog(title, tr("Cell 1"), tr("Cell 2"), op, tr("Output to:"),
+ &cell1, &cell2, &out)) {
+ int row, col;
+ decode_pos(out, &row, &col);
+ table->item(row, col)->setText(tr("%1 %2 %3").arg(op, cell1, cell2));
+ }
+}
+
+void SpreadSheet::actionAdd()
+{
+ actionMath_helper(tr("Addition"), "+");
+}
+
+void SpreadSheet::actionSubtract()
+{
+ actionMath_helper(tr("Subtraction"), "-");
+}
+
+void SpreadSheet::actionMultiply()
+{
+ actionMath_helper(tr("Multiplication"), "*");
+}
+void SpreadSheet::actionDivide()
+{
+ actionMath_helper(tr("Division"), "/");
+}
+
+void SpreadSheet::clear()
+{
+ foreach (QTableWidgetItem *i, table->selectedItems())
+ i->setText("");
+}
+
+void SpreadSheet::setupContextMenu()
+{
+ addAction(cell_addAction);
+ addAction(cell_subAction);
+ addAction(cell_mulAction);
+ addAction(cell_divAction);
+ addAction(cell_sumAction);
+ addAction(firstSeparator);
+ addAction(colorAction);
+ addAction(fontAction);
+ addAction(secondSeparator);
+ addAction(clearAction);
+ setContextMenuPolicy(Qt::ActionsContextMenu);
+}
+
+void SpreadSheet::setupContents()
+{
+ QColor titleBackground(Qt::lightGray);
+ QFont titleFont = table->font();
+ titleFont.setBold(true);
+
+ // column 0
+ table->setItem(0, 0, new SpreadSheetItem("Item"));
+ table->item(0, 0)->setBackgroundColor(titleBackground);
+ table->item(0, 0)->setToolTip("This column shows the purchased item/service");
+ table->item(0, 0)->setFont(titleFont);
+
+ table->setItem(1, 0, new SpreadSheetItem("AirportBus"));
+ table->setItem(2, 0, new SpreadSheetItem("Flight (Munich)"));
+ table->setItem(3, 0, new SpreadSheetItem("Lunch"));
+ table->setItem(4, 0, new SpreadSheetItem("Flight (LA)"));
+ table->setItem(5, 0, new SpreadSheetItem("Taxi"));
+ table->setItem(6, 0, new SpreadSheetItem("Dinner"));
+ table->setItem(7, 0, new SpreadSheetItem("Hotel"));
+ table->setItem(8, 0, new SpreadSheetItem("Flight (Oslo)"));
+ table->setItem(9, 0, new SpreadSheetItem("Total:"));
+
+ table->item(9, 0)->setFont(titleFont);
+ table->item(9, 0)->setBackgroundColor(Qt::lightGray);
+
+ // column 1
+ table->setItem(0, 1, new SpreadSheetItem("Date"));
+ table->item(0, 1)->setBackgroundColor(titleBackground);
+ table->item(0, 1)->setToolTip("This column shows the purchase date, double click to change");
+ table->item(0, 1)->setFont(titleFont);
+
+ table->setItem(1, 1, new SpreadSheetItem("15/6/2006"));
+ table->setItem(2, 1, new SpreadSheetItem("15/6/2006"));
+ table->setItem(3, 1, new SpreadSheetItem("15/6/2006"));
+ table->setItem(4, 1, new SpreadSheetItem("21/5/2006"));
+ table->setItem(5, 1, new SpreadSheetItem("16/6/2006"));
+ table->setItem(6, 1, new SpreadSheetItem("16/6/2006"));
+ table->setItem(7, 1, new SpreadSheetItem("16/6/2006"));
+ table->setItem(8, 1, new SpreadSheetItem("18/6/2006"));
+
+ table->setItem(9, 1, new SpreadSheetItem());
+ table->item(9, 1)->setBackgroundColor(Qt::lightGray);
+
+ // column 2
+ table->setItem(0, 2, new SpreadSheetItem("Price"));
+ table->item(0, 2)->setBackgroundColor(titleBackground);
+ table->item(0, 2)->setToolTip("This column shows the price of the purchase");
+ table->item(0, 2)->setFont(titleFont);
+
+ table->setItem(1, 2, new SpreadSheetItem("150"));
+ table->setItem(2, 2, new SpreadSheetItem("2350"));
+ table->setItem(3, 2, new SpreadSheetItem("-14"));
+ table->setItem(4, 2, new SpreadSheetItem("980"));
+ table->setItem(5, 2, new SpreadSheetItem("5"));
+ table->setItem(6, 2, new SpreadSheetItem("120"));
+ table->setItem(7, 2, new SpreadSheetItem("300"));
+ table->setItem(8, 2, new SpreadSheetItem("1240"));
+
+ table->setItem(9, 2, new SpreadSheetItem());
+ table->item(9, 2)->setBackgroundColor(Qt::lightGray);
+
+ // column 3
+ table->setItem(0, 3, new SpreadSheetItem("Currency"));
+ table->item(0, 3)->setBackgroundColor(titleBackground);
+ table->item(0, 3)->setToolTip("This column shows the currency");
+ table->item(0, 3)->setFont(titleFont);
+
+ table->setItem(1, 3, new SpreadSheetItem("NOK"));
+ table->setItem(2, 3, new SpreadSheetItem("NOK"));
+ table->setItem(3, 3, new SpreadSheetItem("EUR"));
+ table->setItem(4, 3, new SpreadSheetItem("EUR"));
+ table->setItem(5, 3, new SpreadSheetItem("USD"));
+ table->setItem(6, 3, new SpreadSheetItem("USD"));
+ table->setItem(7, 3, new SpreadSheetItem("USD"));
+ table->setItem(8, 3, new SpreadSheetItem("USD"));
+
+ table->setItem(9, 3, new SpreadSheetItem());
+ table->item(9,3)->setBackgroundColor(Qt::lightGray);
+
+ // column 4
+ table->setItem(0, 4, new SpreadSheetItem("Ex. Rate"));
+ table->item(0, 4)->setBackgroundColor(titleBackground);
+ table->item(0, 4)->setToolTip("This column shows the exchange rate to NOK");
+ table->item(0, 4)->setFont(titleFont);
+
+ table->setItem(1, 4, new SpreadSheetItem("1"));
+ table->setItem(2, 4, new SpreadSheetItem("1"));
+ table->setItem(3, 4, new SpreadSheetItem("8"));
+ table->setItem(4, 4, new SpreadSheetItem("8"));
+ table->setItem(5, 4, new SpreadSheetItem("7"));
+ table->setItem(6, 4, new SpreadSheetItem("7"));
+ table->setItem(7, 4, new SpreadSheetItem("7"));
+ table->setItem(8, 4, new SpreadSheetItem("7"));
+
+ table->setItem(9, 4, new SpreadSheetItem());
+ table->item(9,4)->setBackgroundColor(Qt::lightGray);
+
+ // column 5
+ table->setItem(0, 5, new SpreadSheetItem("NOK"));
+ table->item(0, 5)->setBackgroundColor(titleBackground);
+ table->item(0, 5)->setToolTip("This column shows the expenses in NOK");
+ table->item(0, 5)->setFont(titleFont);
+
+ table->setItem(1, 5, new SpreadSheetItem("* C2 E2"));
+ table->setItem(2, 5, new SpreadSheetItem("* C3 E3"));
+ table->setItem(3, 5, new SpreadSheetItem("* C4 E4"));
+ table->setItem(4, 5, new SpreadSheetItem("* C5 E5"));
+ table->setItem(5, 5, new SpreadSheetItem("* C6 E6"));
+ table->setItem(6, 5, new SpreadSheetItem("* C7 E7"));
+ table->setItem(7, 5, new SpreadSheetItem("* C8 E8"));
+ table->setItem(8, 5, new SpreadSheetItem("* C9 E9"));
+
+ table->setItem(9, 5, new SpreadSheetItem("sum F2 F9"));
+ table->item(9,5)->setBackgroundColor(Qt::lightGray);
+}
+
+const char *htmlText =
+"<HTML>"
+"<p><b>This demo shows use of <c>QTableWidget</c> with custom handling for"
+" individual cells.</b></p>"
+"<p>Using a customized table item we make it possible to have dynamic"
+" output in different cells. The content that is implemented for this"
+" particular demo is:"
+"<ul>"
+"<li>Adding two cells.</li>"
+"<li>Subtracting one cell from another.</li>"
+"<li>Multiplying two cells.</li>"
+"<li>Dividing one cell with another.</li>"
+"<li>Summing the contents of an arbitrary number of cells.</li>"
+"</HTML>";
+
+void SpreadSheet::showAbout()
+{
+ QMessageBox::about(this, "About Spreadsheet", htmlText);
+}
+
+void decode_pos(const QString &pos, int *row, int *col)
+{
+ if (pos.isEmpty()) {
+ *col = -1;
+ *row = -1;
+ } else {
+ *col = pos.at(0).toLatin1() - 'A';
+ *row = pos.right(pos.size() - 1).toInt() - 1;
+ }
+}
+
+QString encode_pos(int row, int col)
+{
+ return QString(col + 'A') + QString::number(row + 1);
+}
+
+
+void SpreadSheet::print()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer(QPrinter::ScreenResolution);
+ QPrintPreviewDialog dlg(&printer);
+ PrintView view;
+ view.setModel(table->model());
+ connect(&dlg, SIGNAL(paintRequested(QPrinter*)),
+ &view, SLOT(print(QPrinter*)));
+ dlg.exec();
+#endif
+}
+
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheet.h b/examples/widgets/itemviews/spreadsheet/spreadsheet.h
new file mode 100644
index 0000000000..d2b76c9063
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheet.h
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SPREADSHEET_H
+#define SPREADSHEET_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QLabel;
+class QLineEdit;
+class QToolBar;
+class QTableWidgetItem;
+class QTableWidget;
+QT_END_NAMESPACE
+
+class SpreadSheet : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+
+ SpreadSheet(int rows, int cols, QWidget *parent = 0);
+
+public slots:
+ void updateStatus(QTableWidgetItem *item);
+ void updateColor(QTableWidgetItem *item);
+ void updateLineEdit(QTableWidgetItem *item);
+ void returnPressed();
+ void selectColor();
+ void selectFont();
+ void clear();
+ void showAbout();
+
+ void print();
+
+ void actionSum();
+ void actionSubtract();
+ void actionAdd();
+ void actionMultiply();
+ void actionDivide();
+
+protected:
+ void setupContextMenu();
+ void setupContents();
+
+ void setupMenuBar();
+ void createActions();
+
+ void actionMath_helper(const QString &title, const QString &op);
+ bool runInputDialog(const QString &title,
+ const QString &c1Text,
+ const QString &c2Text,
+ const QString &opText,
+ const QString &outText,
+ QString *cell1, QString *cell2, QString *outCell);
+private:
+ QToolBar *toolBar;
+ QAction *colorAction;
+ QAction *fontAction;
+ QAction *firstSeparator;
+ QAction *cell_sumAction;
+ QAction *cell_addAction;
+ QAction *cell_subAction;
+ QAction *cell_mulAction;
+ QAction *cell_divAction;
+ QAction *secondSeparator;
+ QAction *clearAction;
+ QAction *aboutSpreadSheet;
+ QAction *exitAction;
+
+ QAction *printAction;
+
+ QLabel *cellLabel;
+ QTableWidget *table;
+ QLineEdit *formulaInput;
+
+};
+
+void decode_pos(const QString &pos, int *row, int *col);
+QString encode_pos(int row, int col);
+
+
+#endif // SPREADSHEET_H
+
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheet.pro b/examples/widgets/itemviews/spreadsheet/spreadsheet.pro
new file mode 100644
index 0000000000..48fd07e7fd
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheet.pro
@@ -0,0 +1,23 @@
+QT += widgets
+!isEmpty(QT.printsupport.name): QT += printsupport
+#unix:contains(QT_CONFIG, dbus):QT += dbus widgets
+
+HEADERS += printview.h spreadsheet.h spreadsheetdelegate.h spreadsheetitem.h
+SOURCES += main.cpp \
+ printview.cpp \
+ spreadsheet.cpp \
+ spreadsheetdelegate.cpp \
+ spreadsheetitem.cpp
+RESOURCES += spreadsheet.qrc
+
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/spreadsheet
+sources.files = $$SOURCES $$RESOURCES *.pro images $$HEADERS
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/spreadsheet
+INSTALLS += target sources
+
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheet.qrc b/examples/widgets/itemviews/spreadsheet/spreadsheet.qrc
new file mode 100644
index 0000000000..13f496d8e3
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheet.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>images/interview.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp
new file mode 100644
index 0000000000..d5e747dc2f
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "spreadsheetdelegate.h"
+#include <QtWidgets>
+
+SpreadSheetDelegate::SpreadSheetDelegate(QObject *parent)
+ : QItemDelegate(parent) {}
+
+QWidget *SpreadSheetDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem &,
+ const QModelIndex &index) const
+{
+ if (index.column() == 1) {
+ QDateTimeEdit *editor = new QDateTimeEdit(parent);
+ editor->setDisplayFormat("dd/M/yyyy");
+ editor->setCalendarPopup(true);
+ return editor;
+ }
+
+ QLineEdit *editor = new QLineEdit(parent);
+
+ // create a completer with the strings in the column as model
+ QStringList allStrings;
+ for (int i = 1; i<index.model()->rowCount(); i++) {
+ QString strItem(index.model()->data(index.sibling(i, index.column()),
+ Qt::EditRole).toString());
+
+ if (!allStrings.contains(strItem))
+ allStrings.append(strItem);
+ }
+
+ QCompleter *autoComplete = new QCompleter(allStrings);
+ editor->setCompleter(autoComplete);
+ connect(editor, SIGNAL(editingFinished()),
+ this, SLOT(commitAndCloseEditor()));
+ return editor;
+}
+
+void SpreadSheetDelegate::commitAndCloseEditor()
+{
+ QLineEdit *editor = qobject_cast<QLineEdit *>(sender());
+ emit commitData(editor);
+ emit closeEditor(editor);
+}
+
+void SpreadSheetDelegate::setEditorData(QWidget *editor,
+ const QModelIndex &index) const
+{
+ QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
+ if (edit) {
+ edit->setText(index.model()->data(index, Qt::EditRole).toString());
+ } else {
+ QDateTimeEdit *dateEditor = qobject_cast<QDateTimeEdit *>(editor);
+ if (dateEditor) {
+ dateEditor->setDate(QDate::fromString(
+ index.model()->data(index, Qt::EditRole).toString(),
+ "d/M/yyyy"));
+ }
+ }
+}
+
+void SpreadSheetDelegate::setModelData(QWidget *editor,
+ QAbstractItemModel *model, const QModelIndex &index) const
+{
+ QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
+ if (edit) {
+ model->setData(index, edit->text());
+ } else {
+ QDateTimeEdit *dateEditor = qobject_cast<QDateTimeEdit *>(editor);
+ if (dateEditor) {
+ model->setData(index, dateEditor->date().toString("dd/M/yyyy"));
+ }
+ }
+}
+
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
new file mode 100644
index 0000000000..3487b16ab7
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SPREADSHEETDELEGATE_H
+#define SPREADSHEETDELEGATE_H
+
+#include <QItemDelegate>
+#include "spreadsheet.h"
+
+class SpreadSheetDelegate : public QItemDelegate
+{
+ Q_OBJECT
+
+public:
+ SpreadSheetDelegate(QObject *parent = 0);
+ QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
+ const QModelIndex &index) const;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ void setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const;
+
+private slots:
+ void commitAndCloseEditor();
+};
+
+#endif // SPREADSHEETDELEGATE_H
+
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp
new file mode 100644
index 0000000000..88f8afa325
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "spreadsheetitem.h"
+
+SpreadSheetItem::SpreadSheetItem()
+ : QTableWidgetItem(), isResolving(false)
+{
+}
+
+SpreadSheetItem::SpreadSheetItem(const QString &text)
+ : QTableWidgetItem(text), isResolving(false)
+{
+}
+
+QTableWidgetItem *SpreadSheetItem::clone() const
+{
+ SpreadSheetItem *item = new SpreadSheetItem();
+ *item = *this;
+ return item;
+}
+
+QVariant SpreadSheetItem::data(int role) const
+{
+ if (role == Qt::EditRole || role == Qt::StatusTipRole)
+ return formula();
+
+ if (role == Qt::DisplayRole)
+ return display();
+
+ QString t = display().toString();
+ bool isNumber = false;
+ int number = t.toInt(&isNumber);
+
+ if (role == Qt::TextColorRole) {
+ if (!isNumber)
+ return QVariant::fromValue(QColor(Qt::black));
+ else if (number < 0)
+ return QVariant::fromValue(QColor(Qt::red));
+ return QVariant::fromValue(QColor(Qt::blue));
+ }
+
+ if (role == Qt::TextAlignmentRole)
+ if (!t.isEmpty() && (t.at(0).isNumber() || t.at(0) == '-'))
+ return (int)(Qt::AlignRight | Qt::AlignVCenter);
+
+ return QTableWidgetItem::data(role);
+ }
+
+void SpreadSheetItem::setData(int role, const QVariant &value)
+{
+ QTableWidgetItem::setData(role, value);
+ if (tableWidget())
+ tableWidget()->viewport()->update();
+}
+
+QVariant SpreadSheetItem::display() const
+{
+ // avoid circular dependencies
+ if (isResolving)
+ return QVariant();
+
+ isResolving = true;
+ QVariant result = computeFormula(formula(), tableWidget(), this);
+ isResolving = false;
+ return result;
+}
+
+QVariant SpreadSheetItem::computeFormula(const QString &formula,
+ const QTableWidget *widget,
+ const QTableWidgetItem *self)
+{
+ // check if the s tring is actually a formula or not
+ QStringList list = formula.split(' ');
+ if (list.isEmpty() || !widget)
+ return formula; // it is a normal string
+
+ QString op = list.value(0).toLower();
+
+ int firstRow = -1;
+ int firstCol = -1;
+ int secondRow = -1;
+ int secondCol = -1;
+
+ if (list.count() > 1)
+ decode_pos(list.value(1), &firstRow, &firstCol);
+
+ if (list.count() > 2)
+ decode_pos(list.value(2), &secondRow, &secondCol);
+
+ const QTableWidgetItem *start = widget->item(firstRow, firstCol);
+ const QTableWidgetItem *end = widget->item(secondRow, secondCol);
+
+ int firstVal = start ? start->text().toInt() : 0;
+ int secondVal = end ? end->text().toInt() : 0;
+
+ QVariant result;
+ if (op == "sum") {
+ int sum = 0;
+ for (int r = firstRow; r <= secondRow; ++r) {
+ for (int c = firstCol; c <= secondCol; ++c) {
+ const QTableWidgetItem *tableItem = widget->item(r, c);
+ if (tableItem && tableItem != self)
+ sum += tableItem->text().toInt();
+ }
+ }
+
+ result = sum;
+ } else if (op == "+") {
+ result = (firstVal + secondVal);
+ } else if (op == "-") {
+ result = (firstVal - secondVal);
+ } else if (op == "*") {
+ result = (firstVal * secondVal);
+ } else if (op == "/") {
+ if (secondVal == 0)
+ result = QString("nan");
+ else
+ result = (firstVal / secondVal);
+ } else if (op == "=") {
+ if (start)
+ result = start->text();
+ } else {
+ result = formula;
+ }
+
+ return result;
+}
+
diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.h b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.h
new file mode 100644
index 0000000000..e61138c08b
--- /dev/null
+++ b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SPREADSHEETITEM_H
+#define SPREADSHEETITEM_H
+
+#include <QTableWidgetItem>
+#include <QtWidgets>
+#include "spreadsheet.h"
+
+class SpreadSheetItem : public QTableWidgetItem
+{
+public:
+ SpreadSheetItem();
+ SpreadSheetItem(const QString &text);
+
+ QTableWidgetItem *clone() const;
+
+ QVariant data(int role) const;
+ void setData(int role, const QVariant &value);
+ QVariant display() const;
+
+ inline QString formula() const
+ { return QTableWidgetItem::data(Qt::DisplayRole).toString(); }
+
+ static QVariant computeFormula(const QString &formula,
+ const QTableWidget *widget,
+ const QTableWidgetItem *self = 0);
+
+private:
+ mutable bool isResolving;
+};
+
+#endif // SPREADSHEETITEM_H
+
diff --git a/examples/widgets/itemviews/stardelegate/main.cpp b/examples/widgets/itemviews/stardelegate/main.cpp
new file mode 100644
index 0000000000..3c988e0a8a
--- /dev/null
+++ b/examples/widgets/itemviews/stardelegate/main.cpp
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "stardelegate.h"
+#include "stareditor.h"
+#include "starrating.h"
+
+//! [0]
+void populateTableWidget(QTableWidget *tableWidget)
+{
+ static const struct {
+ const char *title;
+ const char *genre;
+ const char *artist;
+ int rating;
+ } staticData[] = {
+//! [0] //! [1]
+ { "Mass in B-Minor", "Baroque", "J.S. Bach", 5 },
+//! [1]
+ { "Three More Foxes", "Jazz", "Maynard Ferguson", 4 },
+ { "Sex Bomb", "Pop", "Tom Jones", 3 },
+ { "Barbie Girl", "Pop", "Aqua", 5 },
+//! [2]
+ { 0, 0, 0, 0 }
+//! [2] //! [3]
+ };
+//! [3] //! [4]
+
+ for (int row = 0; staticData[row].title != 0; ++row) {
+ QTableWidgetItem *item0 = new QTableWidgetItem(staticData[row].title);
+ QTableWidgetItem *item1 = new QTableWidgetItem(staticData[row].genre);
+ QTableWidgetItem *item2 = new QTableWidgetItem(staticData[row].artist);
+ QTableWidgetItem *item3 = new QTableWidgetItem;
+ item3->setData(0,
+ QVariant::fromValue(StarRating(staticData[row].rating)));
+
+ tableWidget->setItem(row, 0, item0);
+ tableWidget->setItem(row, 1, item1);
+ tableWidget->setItem(row, 2, item2);
+ tableWidget->setItem(row, 3, item3);
+ }
+}
+//! [4]
+
+//! [5]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QTableWidget tableWidget(4, 4);
+ tableWidget.setItemDelegate(new StarDelegate);
+ tableWidget.setEditTriggers(QAbstractItemView::DoubleClicked
+ | QAbstractItemView::SelectedClicked);
+ tableWidget.setSelectionBehavior(QAbstractItemView::SelectRows);
+
+ QStringList headerLabels;
+ headerLabels << "Title" << "Genre" << "Artist" << "Rating";
+ tableWidget.setHorizontalHeaderLabels(headerLabels);
+
+ populateTableWidget(&tableWidget);
+
+ tableWidget.resizeColumnsToContents();
+ tableWidget.resize(500, 300);
+ tableWidget.show();
+
+ return app.exec();
+}
+//! [5]
diff --git a/examples/widgets/itemviews/stardelegate/stardelegate.cpp b/examples/widgets/itemviews/stardelegate/stardelegate.cpp
new file mode 100644
index 0000000000..3032c20088
--- /dev/null
+++ b/examples/widgets/itemviews/stardelegate/stardelegate.cpp
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "stardelegate.h"
+#include "stareditor.h"
+#include "starrating.h"
+
+//! [0]
+void StarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ if (index.data().canConvert<StarRating>()) {
+ StarRating starRating = qvariant_cast<StarRating>(index.data());
+
+ if (option.state & QStyle::State_Selected)
+ painter->fillRect(option.rect, option.palette.highlight());
+
+ starRating.paint(painter, option.rect, option.palette,
+ StarRating::ReadOnly);
+ } else {
+ QStyledItemDelegate::paint(painter, option, index);
+ }
+//! [0]
+}
+
+//! [1]
+QSize StarDelegate::sizeHint(const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ if (index.data().canConvert<StarRating>()) {
+ StarRating starRating = qvariant_cast<StarRating>(index.data());
+ return starRating.sizeHint();
+ } else {
+ return QStyledItemDelegate::sizeHint(option, index);
+ }
+}
+//! [1]
+
+//! [2]
+QWidget *StarDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+
+{
+ if (index.data().canConvert<StarRating>()) {
+ StarEditor *editor = new StarEditor(parent);
+ connect(editor, SIGNAL(editingFinished()),
+ this, SLOT(commitAndCloseEditor()));
+ return editor;
+ } else {
+ return QStyledItemDelegate::createEditor(parent, option, index);
+ }
+}
+//! [2]
+
+//! [3]
+void StarDelegate::setEditorData(QWidget *editor,
+ const QModelIndex &index) const
+{
+ if (index.data().canConvert<StarRating>()) {
+ StarRating starRating = qvariant_cast<StarRating>(index.data());
+ StarEditor *starEditor = qobject_cast<StarEditor *>(editor);
+ starEditor->setStarRating(starRating);
+ } else {
+ QStyledItemDelegate::setEditorData(editor, index);
+ }
+}
+//! [3]
+
+//! [4]
+void StarDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const
+{
+ if (index.data().canConvert<StarRating>()) {
+ StarEditor *starEditor = qobject_cast<StarEditor *>(editor);
+ model->setData(index, QVariant::fromValue(starEditor->starRating()));
+ } else {
+ QStyledItemDelegate::setModelData(editor, model, index);
+ }
+}
+//! [4]
+
+//! [5]
+void StarDelegate::commitAndCloseEditor()
+{
+ StarEditor *editor = qobject_cast<StarEditor *>(sender());
+ emit commitData(editor);
+ emit closeEditor(editor);
+}
+//! [5]
diff --git a/examples/widgets/itemviews/stardelegate/stardelegate.desktop b/examples/widgets/itemviews/stardelegate/stardelegate.desktop
new file mode 100644
index 0000000000..d508c3b286
--- /dev/null
+++ b/examples/widgets/itemviews/stardelegate/stardelegate.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Star Delegate
+Exec=/opt/usr/bin/stardelegate
+Icon=stardelegate
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/itemviews/stardelegate/stardelegate.h b/examples/widgets/itemviews/stardelegate/stardelegate.h
new file mode 100644
index 0000000000..6c53ab8833
--- /dev/null
+++ b/examples/widgets/itemviews/stardelegate/stardelegate.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STARDELEGATE_H
+#define STARDELEGATE_H
+
+#include <QStyledItemDelegate>
+
+//! [0]
+class StarDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+
+public:
+ StarDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {}
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+ QSize sizeHint(const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+ QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ void setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const;
+
+private slots:
+ void commitAndCloseEditor();
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/stardelegate/stardelegate.pro b/examples/widgets/itemviews/stardelegate/stardelegate.pro
new file mode 100644
index 0000000000..915c26a524
--- /dev/null
+++ b/examples/widgets/itemviews/stardelegate/stardelegate.pro
@@ -0,0 +1,17 @@
+HEADERS = stardelegate.h \
+ stareditor.h \
+ starrating.h
+SOURCES = main.cpp \
+ stardelegate.cpp \
+ stareditor.cpp \
+ starrating.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/stardelegate
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews/stardelegate
+INSTALLS += target sources
+
+
+QT += widgets
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/itemviews/stardelegate/stareditor.cpp b/examples/widgets/itemviews/stardelegate/stareditor.cpp
new file mode 100644
index 0000000000..795a748941
--- /dev/null
+++ b/examples/widgets/itemviews/stardelegate/stareditor.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "stareditor.h"
+#include "starrating.h"
+
+//! [0]
+StarEditor::StarEditor(QWidget *parent)
+ : QWidget(parent)
+{
+ setMouseTracking(true);
+ setAutoFillBackground(true);
+}
+//! [0]
+
+QSize StarEditor::sizeHint() const
+{
+ return myStarRating.sizeHint();
+}
+
+//! [1]
+void StarEditor::paintEvent(QPaintEvent *)
+{
+ QPainter painter(this);
+ myStarRating.paint(&painter, rect(), this->palette(),
+ StarRating::Editable);
+}
+//! [1]
+
+//! [2]
+void StarEditor::mouseMoveEvent(QMouseEvent *event)
+{
+ int star = starAtPosition(event->x());
+
+ if (star != myStarRating.starCount() && star != -1) {
+ myStarRating.setStarCount(star);
+ update();
+ }
+}
+//! [2]
+
+//! [3]
+void StarEditor::mouseReleaseEvent(QMouseEvent * /* event */)
+{
+ emit editingFinished();
+}
+//! [3]
+
+//! [4]
+int StarEditor::starAtPosition(int x)
+{
+ int star = (x / (myStarRating.sizeHint().width()
+ / myStarRating.maxStarCount())) + 1;
+ if (star <= 0 || star > myStarRating.maxStarCount())
+ return -1;
+
+ return star;
+}
+//! [4]
diff --git a/examples/widgets/itemviews/stardelegate/stareditor.h b/examples/widgets/itemviews/stardelegate/stareditor.h
new file mode 100644
index 0000000000..88bee7d28d
--- /dev/null
+++ b/examples/widgets/itemviews/stardelegate/stareditor.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STAREDITOR_H
+#define STAREDITOR_H
+
+#include <QWidget>
+
+#include "starrating.h"
+
+//! [0]
+class StarEditor : public QWidget
+{
+ Q_OBJECT
+
+public:
+ StarEditor(QWidget *parent = 0);
+
+ QSize sizeHint() const;
+ void setStarRating(const StarRating &starRating) {
+ myStarRating = starRating;
+ }
+ StarRating starRating() { return myStarRating; }
+
+signals:
+ void editingFinished();
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+
+private:
+ int starAtPosition(int x);
+
+ StarRating myStarRating;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/itemviews/stardelegate/starrating.cpp b/examples/widgets/itemviews/stardelegate/starrating.cpp
new file mode 100644
index 0000000000..cea9330db2
--- /dev/null
+++ b/examples/widgets/itemviews/stardelegate/starrating.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#include <math.h>
+
+#include "starrating.h"
+
+const int PaintingScaleFactor = 20;
+
+//! [0]
+StarRating::StarRating(int starCount, int maxStarCount)
+{
+ myStarCount = starCount;
+ myMaxStarCount = maxStarCount;
+
+ starPolygon << QPointF(1.0, 0.5);
+ for (int i = 1; i < 5; ++i)
+ starPolygon << QPointF(0.5 + 0.5 * cos(0.8 * i * 3.14),
+ 0.5 + 0.5 * sin(0.8 * i * 3.14));
+
+ diamondPolygon << QPointF(0.4, 0.5) << QPointF(0.5, 0.4)
+ << QPointF(0.6, 0.5) << QPointF(0.5, 0.6)
+ << QPointF(0.4, 0.5);
+}
+//! [0]
+
+//! [1]
+QSize StarRating::sizeHint() const
+{
+ return PaintingScaleFactor * QSize(myMaxStarCount, 1);
+}
+//! [1]
+
+//! [2]
+void StarRating::paint(QPainter *painter, const QRect &rect,
+ const QPalette &palette, EditMode mode) const
+{
+ painter->save();
+
+ painter->setRenderHint(QPainter::Antialiasing, true);
+ painter->setPen(Qt::NoPen);
+
+ if (mode == Editable) {
+ painter->setBrush(palette.highlight());
+ } else {
+ painter->setBrush(palette.foreground());
+ }
+
+ int yOffset = (rect.height() - PaintingScaleFactor) / 2;
+ painter->translate(rect.x(), rect.y() + yOffset);
+ painter->scale(PaintingScaleFactor, PaintingScaleFactor);
+
+ for (int i = 0; i < myMaxStarCount; ++i) {
+ if (i < myStarCount) {
+ painter->drawPolygon(starPolygon, Qt::WindingFill);
+ } else if (mode == Editable) {
+ painter->drawPolygon(diamondPolygon, Qt::WindingFill);
+ }
+ painter->translate(1.0, 0.0);
+ }
+
+ painter->restore();
+}
+//! [2]
diff --git a/examples/widgets/itemviews/stardelegate/starrating.h b/examples/widgets/itemviews/stardelegate/starrating.h
new file mode 100644
index 0000000000..04fae2509a
--- /dev/null
+++ b/examples/widgets/itemviews/stardelegate/starrating.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STARRATING_H
+#define STARRATING_H
+
+#include <QMetaType>
+#include <QPointF>
+#include <QVector>
+
+//! [0]
+class StarRating
+{
+public:
+ enum EditMode { Editable, ReadOnly };
+
+ StarRating(int starCount = 1, int maxStarCount = 5);
+
+ void paint(QPainter *painter, const QRect &rect,
+ const QPalette &palette, EditMode mode) const;
+ QSize sizeHint() const;
+ int starCount() const { return myStarCount; }
+ int maxStarCount() const { return myMaxStarCount; }
+ void setStarCount(int starCount) { myStarCount = starCount; }
+ void setMaxStarCount(int maxStarCount) { myMaxStarCount = maxStarCount; }
+
+private:
+ QPolygonF starPolygon;
+ QPolygonF diamondPolygon;
+ int myStarCount;
+ int myMaxStarCount;
+};
+//! [0]
+
+//! [1]
+Q_DECLARE_METATYPE(StarRating)
+//! [1]
+
+#endif
diff --git a/examples/widgets/layouts/README b/examples/widgets/layouts/README
new file mode 100644
index 0000000000..589400280d
--- /dev/null
+++ b/examples/widgets/layouts/README
@@ -0,0 +1,10 @@
+Qt uses a layout-based approach to widget management. Widgets are arranged in
+the optimal positions in windows based on simple layout rules, leading to a
+consistent look and feel.
+
+Custom layouts can be used to provide more control over the positions and
+sizes of child widgets.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/layouts/basiclayouts/basiclayouts.desktop b/examples/widgets/layouts/basiclayouts/basiclayouts.desktop
new file mode 100644
index 0000000000..6c612eed09
--- /dev/null
+++ b/examples/widgets/layouts/basiclayouts/basiclayouts.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Basic Layouts
+Exec=/opt/usr/bin/basiclayouts
+Icon=basiclayouts
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/layouts/basiclayouts/basiclayouts.pro b/examples/widgets/layouts/basiclayouts/basiclayouts.pro
new file mode 100644
index 0000000000..b2c4ad896f
--- /dev/null
+++ b/examples/widgets/layouts/basiclayouts/basiclayouts.pro
@@ -0,0 +1,13 @@
+HEADERS = dialog.h
+SOURCES = dialog.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/layouts/basiclayouts
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/layouts/basiclayouts
+INSTALLS += target sources
+
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/layouts/basiclayouts/dialog.cpp b/examples/widgets/layouts/basiclayouts/dialog.cpp
new file mode 100644
index 0000000000..ca8ab60923
--- /dev/null
+++ b/examples/widgets/layouts/basiclayouts/dialog.cpp
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "dialog.h"
+
+//! [0]
+Dialog::Dialog()
+{
+ createMenu();
+ createHorizontalGroupBox();
+ createGridGroupBox();
+ createFormGroupBox();
+//! [0]
+
+//! [1]
+ bigEditor = new QTextEdit;
+ bigEditor->setPlainText(tr("This widget takes up all the remaining space "
+ "in the top-level layout."));
+
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel);
+
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+//! [1]
+
+//! [2]
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+//! [2] //! [3]
+ mainLayout->setMenuBar(menuBar);
+//! [3] //! [4]
+ mainLayout->addWidget(horizontalGroupBox);
+ mainLayout->addWidget(gridGroupBox);
+ mainLayout->addWidget(formGroupBox);
+ mainLayout->addWidget(bigEditor);
+ mainLayout->addWidget(buttonBox);
+//! [4] //! [5]
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Basic Layouts"));
+}
+//! [5]
+
+//! [6]
+void Dialog::createMenu()
+{
+ menuBar = new QMenuBar;
+
+ fileMenu = new QMenu(tr("&File"), this);
+ exitAction = fileMenu->addAction(tr("E&xit"));
+ menuBar->addMenu(fileMenu);
+
+ connect(exitAction, SIGNAL(triggered()), this, SLOT(accept()));
+}
+//! [6]
+
+//! [7]
+void Dialog::createHorizontalGroupBox()
+{
+ horizontalGroupBox = new QGroupBox(tr("Horizontal layout"));
+ QHBoxLayout *layout = new QHBoxLayout;
+
+ for (int i = 0; i < NumButtons; ++i) {
+ buttons[i] = new QPushButton(tr("Button %1").arg(i + 1));
+ layout->addWidget(buttons[i]);
+ }
+ horizontalGroupBox->setLayout(layout);
+}
+//! [7]
+
+//! [8]
+void Dialog::createGridGroupBox()
+{
+ gridGroupBox = new QGroupBox(tr("Grid layout"));
+//! [8]
+ QGridLayout *layout = new QGridLayout;
+
+//! [9]
+ for (int i = 0; i < NumGridRows; ++i) {
+ labels[i] = new QLabel(tr("Line %1:").arg(i + 1));
+ lineEdits[i] = new QLineEdit;
+ layout->addWidget(labels[i], i + 1, 0);
+ layout->addWidget(lineEdits[i], i + 1, 1);
+ }
+
+//! [9] //! [10]
+ smallEditor = new QTextEdit;
+ smallEditor->setPlainText(tr("This widget takes up about two thirds of the "
+ "grid layout."));
+ layout->addWidget(smallEditor, 0, 2, 4, 1);
+//! [10]
+
+//! [11]
+ layout->setColumnStretch(1, 10);
+ layout->setColumnStretch(2, 20);
+ gridGroupBox->setLayout(layout);
+}
+//! [11]
+
+//! [12]
+void Dialog::createFormGroupBox()
+{
+ formGroupBox = new QGroupBox(tr("Form layout"));
+ QFormLayout *layout = new QFormLayout;
+ layout->addRow(new QLabel(tr("Line 1:")), new QLineEdit);
+ layout->addRow(new QLabel(tr("Line 2, long text:")), new QComboBox);
+ layout->addRow(new QLabel(tr("Line 3:")), new QSpinBox);
+ formGroupBox->setLayout(layout);
+}
+//! [12]
diff --git a/examples/widgets/layouts/basiclayouts/dialog.h b/examples/widgets/layouts/basiclayouts/dialog.h
new file mode 100644
index 0000000000..1d18a683ec
--- /dev/null
+++ b/examples/widgets/layouts/basiclayouts/dialog.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QDialogButtonBox;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QMenu;
+class QMenuBar;
+class QPushButton;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class Dialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Dialog();
+
+private:
+ void createMenu();
+ void createHorizontalGroupBox();
+ void createGridGroupBox();
+ void createFormGroupBox();
+
+ enum { NumGridRows = 3, NumButtons = 4 };
+
+ QMenuBar *menuBar;
+ QGroupBox *horizontalGroupBox;
+ QGroupBox *gridGroupBox;
+ QGroupBox *formGroupBox;
+ QTextEdit *smallEditor;
+ QTextEdit *bigEditor;
+ QLabel *labels[NumGridRows];
+ QLineEdit *lineEdits[NumGridRows];
+ QPushButton *buttons[NumButtons];
+ QDialogButtonBox *buttonBox;
+
+ QMenu *fileMenu;
+ QAction *exitAction;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/layouts/basiclayouts/main.cpp b/examples/widgets/layouts/basiclayouts/main.cpp
new file mode 100644
index 0000000000..fd68d43b72
--- /dev/null
+++ b/examples/widgets/layouts/basiclayouts/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "dialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Dialog dialog;
+ dialog.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/layouts/borderlayout/borderlayout.cpp b/examples/widgets/layouts/borderlayout/borderlayout.cpp
new file mode 100644
index 0000000000..fd08a32fe1
--- /dev/null
+++ b/examples/widgets/layouts/borderlayout/borderlayout.cpp
@@ -0,0 +1,213 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "borderlayout.h"
+
+BorderLayout::BorderLayout(QWidget *parent, int margin, int spacing)
+ : QLayout(parent)
+{
+ setMargin(margin);
+ setSpacing(spacing);
+}
+
+BorderLayout::BorderLayout(int spacing)
+{
+ setSpacing(spacing);
+}
+
+
+BorderLayout::~BorderLayout()
+{
+ QLayoutItem *l;
+ while ((l = takeAt(0)))
+ delete l;
+}
+
+void BorderLayout::addItem(QLayoutItem *item)
+{
+ add(item, West);
+}
+
+void BorderLayout::addWidget(QWidget *widget, Position position)
+{
+ add(new QWidgetItem(widget), position);
+}
+
+Qt::Orientations BorderLayout::expandingDirections() const
+{
+ return Qt::Horizontal | Qt::Vertical;
+}
+
+bool BorderLayout::hasHeightForWidth() const
+{
+ return false;
+}
+
+int BorderLayout::count() const
+{
+ return list.size();
+}
+
+QLayoutItem *BorderLayout::itemAt(int index) const
+{
+ ItemWrapper *wrapper = list.value(index);
+ if (wrapper)
+ return wrapper->item;
+ else
+ return 0;
+}
+
+QSize BorderLayout::minimumSize() const
+{
+ return calculateSize(MinimumSize);
+}
+
+void BorderLayout::setGeometry(const QRect &rect)
+{
+ ItemWrapper *center = 0;
+ int eastWidth = 0;
+ int westWidth = 0;
+ int northHeight = 0;
+ int southHeight = 0;
+ int centerHeight = 0;
+ int i;
+
+ QLayout::setGeometry(rect);
+
+ for (i = 0; i < list.size(); ++i) {
+ ItemWrapper *wrapper = list.at(i);
+ QLayoutItem *item = wrapper->item;
+ Position position = wrapper->position;
+
+ if (position == North) {
+ item->setGeometry(QRect(rect.x(), northHeight, rect.width(),
+ item->sizeHint().height()));
+
+ northHeight += item->geometry().height() + spacing();
+ } else if (position == South) {
+ item->setGeometry(QRect(item->geometry().x(),
+ item->geometry().y(), rect.width(),
+ item->sizeHint().height()));
+
+ southHeight += item->geometry().height() + spacing();
+
+ item->setGeometry(QRect(rect.x(),
+ rect.y() + rect.height() - southHeight + spacing(),
+ item->geometry().width(),
+ item->geometry().height()));
+ } else if (position == Center) {
+ center = wrapper;
+ }
+ }
+
+ centerHeight = rect.height() - northHeight - southHeight;
+
+ for (i = 0; i < list.size(); ++i) {
+ ItemWrapper *wrapper = list.at(i);
+ QLayoutItem *item = wrapper->item;
+ Position position = wrapper->position;
+
+ if (position == West) {
+ item->setGeometry(QRect(rect.x() + westWidth, northHeight,
+ item->sizeHint().width(), centerHeight));
+
+ westWidth += item->geometry().width() + spacing();
+ } else if (position == East) {
+ item->setGeometry(QRect(item->geometry().x(), item->geometry().y(),
+ item->sizeHint().width(), centerHeight));
+
+ eastWidth += item->geometry().width() + spacing();
+
+ item->setGeometry(QRect(
+ rect.x() + rect.width() - eastWidth + spacing(),
+ northHeight, item->geometry().width(),
+ item->geometry().height()));
+ }
+ }
+
+ if (center)
+ center->item->setGeometry(QRect(westWidth, northHeight,
+ rect.width() - eastWidth - westWidth,
+ centerHeight));
+}
+
+QSize BorderLayout::sizeHint() const
+{
+ return calculateSize(SizeHint);
+}
+
+QLayoutItem *BorderLayout::takeAt(int index)
+{
+ if (index >= 0 && index < list.size()) {
+ ItemWrapper *layoutStruct = list.takeAt(index);
+ return layoutStruct->item;
+ }
+ return 0;
+}
+
+void BorderLayout::add(QLayoutItem *item, Position position)
+{
+ list.append(new ItemWrapper(item, position));
+}
+
+QSize BorderLayout::calculateSize(SizeType sizeType) const
+{
+ QSize totalSize;
+
+ for (int i = 0; i < list.size(); ++i) {
+ ItemWrapper *wrapper = list.at(i);
+ Position position = wrapper->position;
+ QSize itemSize;
+
+ if (sizeType == MinimumSize)
+ itemSize = wrapper->item->minimumSize();
+ else // (sizeType == SizeHint)
+ itemSize = wrapper->item->sizeHint();
+
+ if (position == North || position == South || position == Center)
+ totalSize.rheight() += itemSize.height();
+
+ if (position == West || position == East || position == Center)
+ totalSize.rwidth() += itemSize.width();
+ }
+ return totalSize;
+}
diff --git a/examples/widgets/layouts/borderlayout/borderlayout.desktop b/examples/widgets/layouts/borderlayout/borderlayout.desktop
new file mode 100644
index 0000000000..3fd0641f1c
--- /dev/null
+++ b/examples/widgets/layouts/borderlayout/borderlayout.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Border Layout
+Exec=/opt/usr/bin/borderlayout
+Icon=borderlayout
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/layouts/borderlayout/borderlayout.h b/examples/widgets/layouts/borderlayout/borderlayout.h
new file mode 100644
index 0000000000..937517dc17
--- /dev/null
+++ b/examples/widgets/layouts/borderlayout/borderlayout.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BORDERLAYOUT_H
+#define BORDERLAYOUT_H
+
+#include <QLayout>
+#include <QRect>
+#include <QWidgetItem>
+
+class BorderLayout : public QLayout
+{
+public:
+ enum Position { West, North, South, East, Center };
+
+ BorderLayout(QWidget *parent, int margin = 0, int spacing = -1);
+ BorderLayout(int spacing = -1);
+ ~BorderLayout();
+
+ void addItem(QLayoutItem *item);
+ void addWidget(QWidget *widget, Position position);
+ Qt::Orientations expandingDirections() const;
+ bool hasHeightForWidth() const;
+ int count() const;
+ QLayoutItem *itemAt(int index) const;
+ QSize minimumSize() const;
+ void setGeometry(const QRect &rect);
+ QSize sizeHint() const;
+ QLayoutItem *takeAt(int index);
+
+ void add(QLayoutItem *item, Position position);
+
+private:
+ struct ItemWrapper
+ {
+ ItemWrapper(QLayoutItem *i, Position p) {
+ item = i;
+ position = p;
+ }
+
+ QLayoutItem *item;
+ Position position;
+ };
+
+ enum SizeType { MinimumSize, SizeHint };
+ QSize calculateSize(SizeType sizeType) const;
+
+ QList<ItemWrapper *> list;
+};
+
+#endif
diff --git a/examples/widgets/layouts/borderlayout/borderlayout.pro b/examples/widgets/layouts/borderlayout/borderlayout.pro
new file mode 100644
index 0000000000..6727af60d7
--- /dev/null
+++ b/examples/widgets/layouts/borderlayout/borderlayout.pro
@@ -0,0 +1,13 @@
+HEADERS = borderlayout.h \
+ window.h
+SOURCES = borderlayout.cpp \
+ main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/layouts/borderlayout
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/layouts/borderlayout
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/lineedits/main.cpp b/examples/widgets/layouts/borderlayout/main.cpp
index dcbf1c0449..dcbf1c0449 100644
--- a/examples/widgets/lineedits/main.cpp
+++ b/examples/widgets/layouts/borderlayout/main.cpp
diff --git a/examples/widgets/layouts/borderlayout/window.cpp b/examples/widgets/layouts/borderlayout/window.cpp
new file mode 100644
index 0000000000..73ad86a826
--- /dev/null
+++ b/examples/widgets/layouts/borderlayout/window.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "borderlayout.h"
+#include "window.h"
+
+Window::Window()
+{
+ QTextBrowser *centralWidget = new QTextBrowser;
+ centralWidget->setPlainText(tr("Central widget"));
+
+ BorderLayout *layout = new BorderLayout;
+ layout->addWidget(centralWidget, BorderLayout::Center);
+ layout->addWidget(createLabel("North"), BorderLayout::North);
+ layout->addWidget(createLabel("West"), BorderLayout::West);
+ layout->addWidget(createLabel("East 1"), BorderLayout::East);
+ layout->addWidget(createLabel("East 2") , BorderLayout::East);
+ layout->addWidget(createLabel("South"), BorderLayout::South);
+ setLayout(layout);
+
+ setWindowTitle(tr("Border Layout"));
+}
+
+QLabel *Window::createLabel(const QString &text)
+{
+ QLabel *label = new QLabel(text);
+ label->setFrameStyle(QFrame::Box | QFrame::Raised);
+ return label;
+}
diff --git a/examples/widgets/layouts/borderlayout/window.h b/examples/widgets/layouts/borderlayout/window.h
new file mode 100644
index 0000000000..3db08e1ab3
--- /dev/null
+++ b/examples/widgets/layouts/borderlayout/window.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+QT_END_NAMESPACE
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private:
+ QLabel *createLabel(const QString &text);
+};
+
+#endif
diff --git a/examples/widgets/layouts/dynamiclayouts/dialog.cpp b/examples/widgets/layouts/dynamiclayouts/dialog.cpp
new file mode 100644
index 0000000000..e3ebb66944
--- /dev/null
+++ b/examples/widgets/layouts/dynamiclayouts/dialog.cpp
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "dialog.h"
+
+Dialog::Dialog(QWidget *parent)
+ : QDialog(parent)
+{
+ createRotableGroupBox();
+ createOptionsGroupBox();
+ createButtonBox();
+
+ mainLayout = new QGridLayout;
+ mainLayout->addWidget(rotableGroupBox, 0, 0);
+ mainLayout->addWidget(optionsGroupBox, 1, 0);
+ mainLayout->addWidget(buttonBox, 2, 0);
+ setLayout(mainLayout);
+
+ mainLayout->setSizeConstraint(QLayout::SetMinimumSize);
+
+ setWindowTitle(tr("Dynamic Layouts"));
+}
+
+void Dialog::buttonsOrientationChanged(int index)
+{
+ mainLayout->setSizeConstraint(QLayout::SetNoConstraint);
+ setMinimumSize(0, 0);
+
+ Qt::Orientation orientation = Qt::Orientation(
+ buttonsOrientationComboBox->itemData(index).toInt());
+
+ if (orientation == buttonBox->orientation())
+ return;
+
+ mainLayout->removeWidget(buttonBox);
+
+ int spacing = mainLayout->spacing();
+
+ QSize oldSizeHint = buttonBox->sizeHint() + QSize(spacing, spacing);
+ buttonBox->setOrientation(orientation);
+ QSize newSizeHint = buttonBox->sizeHint() + QSize(spacing, spacing);
+
+ if (orientation == Qt::Horizontal) {
+ mainLayout->addWidget(buttonBox, 2, 0);
+ resize(size() + QSize(-oldSizeHint.width(), newSizeHint.height()));
+ } else {
+ mainLayout->addWidget(buttonBox, 0, 3, 2, 1);
+ resize(size() + QSize(newSizeHint.width(), -oldSizeHint.height()));
+ }
+
+ mainLayout->setSizeConstraint(QLayout::SetDefaultConstraint);
+}
+
+void Dialog::rotateWidgets()
+{
+ Q_ASSERT(rotableWidgets.count() % 2 == 0);
+
+ foreach (QWidget *widget, rotableWidgets)
+ rotableLayout->removeWidget(widget);
+
+ rotableWidgets.enqueue(rotableWidgets.dequeue());
+
+ const int n = rotableWidgets.count();
+ for (int i = 0; i < n / 2; ++i) {
+ rotableLayout->addWidget(rotableWidgets[n - i - 1], 0, i);
+ rotableLayout->addWidget(rotableWidgets[i], 1, i);
+ }
+}
+
+void Dialog::help()
+{
+ QMessageBox::information(this, tr("Dynamic Layouts Help"),
+ tr("This example shows how to change layouts "
+ "dynamically."));
+}
+
+void Dialog::createRotableGroupBox()
+{
+ rotableGroupBox = new QGroupBox(tr("Rotable Widgets"));
+
+ rotableWidgets.enqueue(new QSpinBox);
+ rotableWidgets.enqueue(new QSlider);
+ rotableWidgets.enqueue(new QDial);
+ rotableWidgets.enqueue(new QProgressBar);
+
+ int n = rotableWidgets.count();
+ for (int i = 0; i < n; ++i) {
+ connect(rotableWidgets[i], SIGNAL(valueChanged(int)),
+ rotableWidgets[(i + 1) % n], SLOT(setValue(int)));
+ }
+
+ rotableLayout = new QGridLayout;
+ rotableGroupBox->setLayout(rotableLayout);
+
+ rotateWidgets();
+}
+
+void Dialog::createOptionsGroupBox()
+{
+ optionsGroupBox = new QGroupBox(tr("Options"));
+
+ buttonsOrientationLabel = new QLabel(tr("Orientation of buttons:"));
+
+ buttonsOrientationComboBox = new QComboBox;
+ buttonsOrientationComboBox->addItem(tr("Horizontal"), Qt::Horizontal);
+ buttonsOrientationComboBox->addItem(tr("Vertical"), Qt::Vertical);
+
+ connect(buttonsOrientationComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(buttonsOrientationChanged(int)));
+
+ optionsLayout = new QGridLayout;
+ optionsLayout->addWidget(buttonsOrientationLabel, 0, 0);
+ optionsLayout->addWidget(buttonsOrientationComboBox, 0, 1);
+ optionsLayout->setColumnStretch(2, 1);
+ optionsGroupBox->setLayout(optionsLayout);
+}
+
+void Dialog::createButtonBox()
+{
+ buttonBox = new QDialogButtonBox;
+
+ closeButton = buttonBox->addButton(QDialogButtonBox::Close);
+ helpButton = buttonBox->addButton(QDialogButtonBox::Help);
+ rotateWidgetsButton = buttonBox->addButton(tr("Rotate &Widgets"),
+ QDialogButtonBox::ActionRole);
+
+ connect(rotateWidgetsButton, SIGNAL(clicked()), this, SLOT(rotateWidgets()));
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(helpButton, SIGNAL(clicked()), this, SLOT(help()));
+}
diff --git a/examples/widgets/layouts/dynamiclayouts/dialog.h b/examples/widgets/layouts/dynamiclayouts/dialog.h
new file mode 100644
index 0000000000..f8321abad4
--- /dev/null
+++ b/examples/widgets/layouts/dynamiclayouts/dialog.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QMainWindow>
+#include <QDialog>
+#include <QQueue>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QDialogButtonBox;
+class QGridLayout;
+class QGroupBox;
+class QLabel;
+class QPushButton;
+QT_END_NAMESPACE
+
+class Dialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Dialog(QWidget *parent = 0);
+
+private slots:
+ void buttonsOrientationChanged(int index);
+ void rotateWidgets();
+ void help();
+
+private:
+ void createRotableGroupBox();
+ void createOptionsGroupBox();
+ void createButtonBox();
+
+ QGroupBox *rotableGroupBox;
+ QQueue<QWidget *> rotableWidgets;
+
+ QGroupBox *optionsGroupBox;
+ QLabel *buttonsOrientationLabel;
+ QComboBox *buttonsOrientationComboBox;
+
+ QDialogButtonBox *buttonBox;
+ QPushButton *closeButton;
+ QPushButton *helpButton;
+ QPushButton *rotateWidgetsButton;
+
+ QGridLayout *mainLayout;
+ QGridLayout *rotableLayout;
+ QGridLayout *optionsLayout;
+};
+
+#endif
diff --git a/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.desktop b/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.desktop
new file mode 100644
index 0000000000..482286bfb8
--- /dev/null
+++ b/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Dynamic Layouts
+Exec=/opt/usr/bin/dynamiclayouts
+Icon=dynamiclayouts
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro b/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro
new file mode 100644
index 0000000000..3cc4c084a5
--- /dev/null
+++ b/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.pro
@@ -0,0 +1,13 @@
+HEADERS = dialog.h
+SOURCES = dialog.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/layouts/dynamiclayouts
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/layouts/dynamiclayouts
+INSTALLS += target sources
+
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/layouts/dynamiclayouts/main.cpp b/examples/widgets/layouts/dynamiclayouts/main.cpp
new file mode 100644
index 0000000000..b4dd37a9cf
--- /dev/null
+++ b/examples/widgets/layouts/dynamiclayouts/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "dialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Dialog dialog;
+ dialog.show();
+ return app.exec();
+}
diff --git a/examples/widgets/layouts/flowlayout/flowlayout.cpp b/examples/widgets/layouts/flowlayout/flowlayout.cpp
new file mode 100644
index 0000000000..b7a62c8f03
--- /dev/null
+++ b/examples/widgets/layouts/flowlayout/flowlayout.cpp
@@ -0,0 +1,213 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "flowlayout.h"
+//! [1]
+FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
+ : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
+{
+ setContentsMargins(margin, margin, margin, margin);
+}
+
+FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
+ : m_hSpace(hSpacing), m_vSpace(vSpacing)
+{
+ setContentsMargins(margin, margin, margin, margin);
+}
+//! [1]
+
+//! [2]
+FlowLayout::~FlowLayout()
+{
+ QLayoutItem *item;
+ while ((item = takeAt(0)))
+ delete item;
+}
+//! [2]
+
+//! [3]
+void FlowLayout::addItem(QLayoutItem *item)
+{
+ itemList.append(item);
+}
+//! [3]
+
+//! [4]
+int FlowLayout::horizontalSpacing() const
+{
+ if (m_hSpace >= 0) {
+ return m_hSpace;
+ } else {
+ return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
+ }
+}
+
+int FlowLayout::verticalSpacing() const
+{
+ if (m_vSpace >= 0) {
+ return m_vSpace;
+ } else {
+ return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
+ }
+}
+//! [4]
+
+//! [5]
+int FlowLayout::count() const
+{
+ return itemList.size();
+}
+
+QLayoutItem *FlowLayout::itemAt(int index) const
+{
+ return itemList.value(index);
+}
+
+QLayoutItem *FlowLayout::takeAt(int index)
+{
+ if (index >= 0 && index < itemList.size())
+ return itemList.takeAt(index);
+ else
+ return 0;
+}
+//! [5]
+
+//! [6]
+Qt::Orientations FlowLayout::expandingDirections() const
+{
+ return 0;
+}
+//! [6]
+
+//! [7]
+bool FlowLayout::hasHeightForWidth() const
+{
+ return true;
+}
+
+int FlowLayout::heightForWidth(int width) const
+{
+ int height = doLayout(QRect(0, 0, width, 0), true);
+ return height;
+}
+//! [7]
+
+//! [8]
+void FlowLayout::setGeometry(const QRect &rect)
+{
+ QLayout::setGeometry(rect);
+ doLayout(rect, false);
+}
+
+QSize FlowLayout::sizeHint() const
+{
+ return minimumSize();
+}
+
+QSize FlowLayout::minimumSize() const
+{
+ QSize size;
+ QLayoutItem *item;
+ foreach (item, itemList)
+ size = size.expandedTo(item->minimumSize());
+
+ size += QSize(2*margin(), 2*margin());
+ return size;
+}
+//! [8]
+
+//! [9]
+int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
+{
+ int left, top, right, bottom;
+ getContentsMargins(&left, &top, &right, &bottom);
+ QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
+ int x = effectiveRect.x();
+ int y = effectiveRect.y();
+ int lineHeight = 0;
+//! [9]
+
+//! [10]
+ QLayoutItem *item;
+ foreach (item, itemList) {
+ QWidget *wid = item->widget();
+ int spaceX = horizontalSpacing();
+ if (spaceX == -1)
+ spaceX = wid->style()->layoutSpacing(
+ QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
+ int spaceY = verticalSpacing();
+ if (spaceY == -1)
+ spaceY = wid->style()->layoutSpacing(
+ QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
+//! [10]
+//! [11]
+ int nextX = x + item->sizeHint().width() + spaceX;
+ if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
+ x = effectiveRect.x();
+ y = y + lineHeight + spaceY;
+ nextX = x + item->sizeHint().width() + spaceX;
+ lineHeight = 0;
+ }
+
+ if (!testOnly)
+ item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
+
+ x = nextX;
+ lineHeight = qMax(lineHeight, item->sizeHint().height());
+ }
+ return y + lineHeight - rect.y() + bottom;
+}
+//! [11]
+//! [12]
+int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
+{
+ QObject *parent = this->parent();
+ if (!parent) {
+ return -1;
+ } else if (parent->isWidgetType()) {
+ QWidget *pw = static_cast<QWidget *>(parent);
+ return pw->style()->pixelMetric(pm, 0, pw);
+ } else {
+ return static_cast<QLayout *>(parent)->spacing();
+ }
+}
+//! [12]
diff --git a/examples/widgets/layouts/flowlayout/flowlayout.desktop b/examples/widgets/layouts/flowlayout/flowlayout.desktop
new file mode 100644
index 0000000000..54ea3b0290
--- /dev/null
+++ b/examples/widgets/layouts/flowlayout/flowlayout.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Flow Layout
+Exec=/opt/usr/bin/flowlayout
+Icon=flowlayout
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/layouts/flowlayout/flowlayout.h b/examples/widgets/layouts/flowlayout/flowlayout.h
new file mode 100644
index 0000000000..2a27f93772
--- /dev/null
+++ b/examples/widgets/layouts/flowlayout/flowlayout.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FLOWLAYOUT_H
+#define FLOWLAYOUT_H
+
+#include <QLayout>
+#include <QRect>
+#include <QWidgetItem>
+//! [0]
+class FlowLayout : public QLayout
+{
+public:
+ FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
+ FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
+ ~FlowLayout();
+
+ void addItem(QLayoutItem *item);
+ int horizontalSpacing() const;
+ int verticalSpacing() const;
+ Qt::Orientations expandingDirections() const;
+ bool hasHeightForWidth() const;
+ int heightForWidth(int) const;
+ int count() const;
+ QLayoutItem *itemAt(int index) const;
+ QSize minimumSize() const;
+ void setGeometry(const QRect &rect);
+ QSize sizeHint() const;
+ QLayoutItem *takeAt(int index);
+
+private:
+ int doLayout(const QRect &rect, bool testOnly) const;
+ int smartSpacing(QStyle::PixelMetric pm) const;
+
+ QList<QLayoutItem *> itemList;
+ int m_hSpace;
+ int m_vSpace;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/layouts/flowlayout/flowlayout.pro b/examples/widgets/layouts/flowlayout/flowlayout.pro
new file mode 100644
index 0000000000..4ac0a43c26
--- /dev/null
+++ b/examples/widgets/layouts/flowlayout/flowlayout.pro
@@ -0,0 +1,13 @@
+HEADERS = flowlayout.h \
+ window.h
+SOURCES = flowlayout.cpp \
+ main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/layouts/flowlayout
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/layouts/flowlayout
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/sliders/main.cpp b/examples/widgets/layouts/flowlayout/main.cpp
index dcbf1c0449..dcbf1c0449 100644
--- a/examples/widgets/sliders/main.cpp
+++ b/examples/widgets/layouts/flowlayout/main.cpp
diff --git a/examples/widgets/layouts/flowlayout/window.cpp b/examples/widgets/layouts/flowlayout/window.cpp
new file mode 100644
index 0000000000..8a7dd32eac
--- /dev/null
+++ b/examples/widgets/layouts/flowlayout/window.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "flowlayout.h"
+#include "window.h"
+//! [1]
+Window::Window()
+{
+ FlowLayout *flowLayout = new FlowLayout;
+
+ flowLayout->addWidget(new QPushButton(tr("Short")));
+ flowLayout->addWidget(new QPushButton(tr("Longer")));
+ flowLayout->addWidget(new QPushButton(tr("Different text")));
+ flowLayout->addWidget(new QPushButton(tr("More text")));
+ flowLayout->addWidget(new QPushButton(tr("Even longer button text")));
+ setLayout(flowLayout);
+
+ setWindowTitle(tr("Flow Layout"));
+}
+//! [1]
diff --git a/examples/widgets/layouts/flowlayout/window.h b/examples/widgets/layouts/flowlayout/window.h
new file mode 100644
index 0000000000..e29813a91a
--- /dev/null
+++ b/examples/widgets/layouts/flowlayout/window.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+QT_END_NAMESPACE
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/layouts/layouts.pro b/examples/widgets/layouts/layouts.pro
new file mode 100644
index 0000000000..8299052d4f
--- /dev/null
+++ b/examples/widgets/layouts/layouts.pro
@@ -0,0 +1,12 @@
+TEMPLATE = subdirs
+SUBDIRS = basiclayouts \
+ borderlayout \
+ dynamiclayouts \
+ flowlayout
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/layouts
+INSTALLS += sources
+
+QT += widgets
diff --git a/examples/widgets/mainwindows/README b/examples/widgets/mainwindows/README
new file mode 100644
index 0000000000..b63adee6e3
--- /dev/null
+++ b/examples/widgets/mainwindows/README
@@ -0,0 +1,9 @@
+All the standard features of application main windows are provided by Qt.
+
+Main windows can have pull down menus, tool bars, and dock windows. These
+separate forms of user input are unified in an integrated action system that
+also supports keyboard shortcuts and accelerator keys in menu items.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/mainwindows/application/application.desktop b/examples/widgets/mainwindows/application/application.desktop
new file mode 100644
index 0000000000..b6fab1f1fe
--- /dev/null
+++ b/examples/widgets/mainwindows/application/application.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Application
+Exec=/opt/usr/bin/application
+Icon=application
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/mainwindows/application/application.pro b/examples/widgets/mainwindows/application/application.pro
new file mode 100644
index 0000000000..ef866a6d5f
--- /dev/null
+++ b/examples/widgets/mainwindows/application/application.pro
@@ -0,0 +1,16 @@
+HEADERS = mainwindow.h
+SOURCES = main.cpp \
+ mainwindow.cpp
+#! [0]
+RESOURCES = application.qrc
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/application
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS application.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/application
+INSTALLS += target sources
+
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/mainwindows/application/application.qrc b/examples/widgets/mainwindows/application/application.qrc
new file mode 100644
index 0000000000..0a776fab4d
--- /dev/null
+++ b/examples/widgets/mainwindows/application/application.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/copy.png</file>
+ <file>images/cut.png</file>
+ <file>images/new.png</file>
+ <file>images/open.png</file>
+ <file>images/paste.png</file>
+ <file>images/save.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/mainwindows/application/images/copy.png b/examples/widgets/mainwindows/application/images/copy.png
new file mode 100644
index 0000000000..2aeb28288f
--- /dev/null
+++ b/examples/widgets/mainwindows/application/images/copy.png
Binary files differ
diff --git a/examples/widgets/mainwindows/application/images/cut.png b/examples/widgets/mainwindows/application/images/cut.png
new file mode 100644
index 0000000000..54638e9386
--- /dev/null
+++ b/examples/widgets/mainwindows/application/images/cut.png
Binary files differ
diff --git a/examples/widgets/mainwindows/application/images/new.png b/examples/widgets/mainwindows/application/images/new.png
new file mode 100644
index 0000000000..12131b0100
--- /dev/null
+++ b/examples/widgets/mainwindows/application/images/new.png
Binary files differ
diff --git a/examples/widgets/mainwindows/application/images/open.png b/examples/widgets/mainwindows/application/images/open.png
new file mode 100644
index 0000000000..45fa2883a7
--- /dev/null
+++ b/examples/widgets/mainwindows/application/images/open.png
Binary files differ
diff --git a/examples/widgets/mainwindows/application/images/paste.png b/examples/widgets/mainwindows/application/images/paste.png
new file mode 100644
index 0000000000..c14425cad1
--- /dev/null
+++ b/examples/widgets/mainwindows/application/images/paste.png
Binary files differ
diff --git a/examples/widgets/mainwindows/application/images/save.png b/examples/widgets/mainwindows/application/images/save.png
new file mode 100644
index 0000000000..daba865faf
--- /dev/null
+++ b/examples/widgets/mainwindows/application/images/save.png
Binary files differ
diff --git a/examples/widgets/mainwindows/application/main.cpp b/examples/widgets/mainwindows/application/main.cpp
new file mode 100644
index 0000000000..9ff6799574
--- /dev/null
+++ b/examples/widgets/mainwindows/application/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(application);
+
+ QApplication app(argc, argv);
+ app.setOrganizationName("Trolltech");
+ app.setApplicationName("Application Example");
+ MainWindow mainWin;
+ mainWin.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/widgets/mainwindows/application/mainwindow.cpp b/examples/widgets/mainwindows/application/mainwindow.cpp
new file mode 100644
index 0000000000..8f60353da9
--- /dev/null
+++ b/examples/widgets/mainwindows/application/mainwindow.cpp
@@ -0,0 +1,392 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QtWidgets>
+
+#include "mainwindow.h"
+//! [0]
+
+//! [1]
+MainWindow::MainWindow()
+//! [1] //! [2]
+{
+ textEdit = new QPlainTextEdit;
+ setCentralWidget(textEdit);
+
+ createActions();
+ createMenus();
+ createToolBars();
+ createStatusBar();
+
+ readSettings();
+
+ connect(textEdit->document(), SIGNAL(contentsChanged()),
+ this, SLOT(documentWasModified()));
+
+ setCurrentFile("");
+ setUnifiedTitleAndToolBarOnMac(true);
+}
+//! [2]
+
+//! [3]
+void MainWindow::closeEvent(QCloseEvent *event)
+//! [3] //! [4]
+{
+ if (maybeSave()) {
+ writeSettings();
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+//! [4]
+
+//! [5]
+void MainWindow::newFile()
+//! [5] //! [6]
+{
+ if (maybeSave()) {
+ textEdit->clear();
+ setCurrentFile("");
+ }
+}
+//! [6]
+
+//! [7]
+void MainWindow::open()
+//! [7] //! [8]
+{
+ if (maybeSave()) {
+ QString fileName = QFileDialog::getOpenFileName(this);
+ if (!fileName.isEmpty())
+ loadFile(fileName);
+ }
+}
+//! [8]
+
+//! [9]
+bool MainWindow::save()
+//! [9] //! [10]
+{
+ if (curFile.isEmpty()) {
+ return saveAs();
+ } else {
+ return saveFile(curFile);
+ }
+}
+//! [10]
+
+//! [11]
+bool MainWindow::saveAs()
+//! [11] //! [12]
+{
+ QString fileName = QFileDialog::getSaveFileName(this);
+ if (fileName.isEmpty())
+ return false;
+
+ return saveFile(fileName);
+}
+//! [12]
+
+//! [13]
+void MainWindow::about()
+//! [13] //! [14]
+{
+ QMessageBox::about(this, tr("About Application"),
+ tr("The <b>Application</b> example demonstrates how to "
+ "write modern GUI applications using Qt, with a menu bar, "
+ "toolbars, and a status bar."));
+}
+//! [14]
+
+//! [15]
+void MainWindow::documentWasModified()
+//! [15] //! [16]
+{
+ setWindowModified(textEdit->document()->isModified());
+}
+//! [16]
+
+//! [17]
+void MainWindow::createActions()
+//! [17] //! [18]
+{
+ newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
+ newAct->setShortcuts(QKeySequence::New);
+ newAct->setStatusTip(tr("Create a new file"));
+ connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
+
+//! [19]
+ openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ openAct->setStatusTip(tr("Open an existing file"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+//! [18] //! [19]
+
+ saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this);
+ saveAct->setShortcuts(QKeySequence::Save);
+ saveAct->setStatusTip(tr("Save the document to disk"));
+ connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
+
+ saveAsAct = new QAction(tr("Save &As..."), this);
+ saveAsAct->setShortcuts(QKeySequence::SaveAs);
+ saveAsAct->setStatusTip(tr("Save the document under a new name"));
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+//! [20]
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+//! [20]
+ exitAct->setStatusTip(tr("Exit the application"));
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+//! [21]
+ cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this);
+//! [21]
+ cutAct->setShortcuts(QKeySequence::Cut);
+ cutAct->setStatusTip(tr("Cut the current selection's contents to the "
+ "clipboard"));
+ connect(cutAct, SIGNAL(triggered()), textEdit, SLOT(cut()));
+
+ copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this);
+ copyAct->setShortcuts(QKeySequence::Copy);
+ copyAct->setStatusTip(tr("Copy the current selection's contents to the "
+ "clipboard"));
+ connect(copyAct, SIGNAL(triggered()), textEdit, SLOT(copy()));
+
+ pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this);
+ pasteAct->setShortcuts(QKeySequence::Paste);
+ pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
+ "selection"));
+ connect(pasteAct, SIGNAL(triggered()), textEdit, SLOT(paste()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ aboutAct->setStatusTip(tr("Show the application's About box"));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+//! [22]
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+//! [22]
+
+//! [23]
+ cutAct->setEnabled(false);
+//! [23] //! [24]
+ copyAct->setEnabled(false);
+ connect(textEdit, SIGNAL(copyAvailable(bool)),
+ cutAct, SLOT(setEnabled(bool)));
+ connect(textEdit, SIGNAL(copyAvailable(bool)),
+ copyAct, SLOT(setEnabled(bool)));
+}
+//! [24]
+
+//! [25] //! [26]
+void MainWindow::createMenus()
+//! [25] //! [27]
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(newAct);
+//! [28]
+ fileMenu->addAction(openAct);
+//! [28]
+ fileMenu->addAction(saveAct);
+//! [26]
+ fileMenu->addAction(saveAsAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ editMenu = menuBar()->addMenu(tr("&Edit"));
+ editMenu->addAction(cutAct);
+ editMenu->addAction(copyAct);
+ editMenu->addAction(pasteAct);
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [27]
+
+//! [29] //! [30]
+void MainWindow::createToolBars()
+{
+ fileToolBar = addToolBar(tr("File"));
+ fileToolBar->addAction(newAct);
+//! [29] //! [31]
+ fileToolBar->addAction(openAct);
+//! [31]
+ fileToolBar->addAction(saveAct);
+
+ editToolBar = addToolBar(tr("Edit"));
+ editToolBar->addAction(cutAct);
+ editToolBar->addAction(copyAct);
+ editToolBar->addAction(pasteAct);
+}
+//! [30]
+
+//! [32]
+void MainWindow::createStatusBar()
+//! [32] //! [33]
+{
+ statusBar()->showMessage(tr("Ready"));
+}
+//! [33]
+
+//! [34] //! [35]
+void MainWindow::readSettings()
+//! [34] //! [36]
+{
+ QSettings settings("Trolltech", "Application Example");
+ QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
+ QSize size = settings.value("size", QSize(400, 400)).toSize();
+ resize(size);
+ move(pos);
+}
+//! [35] //! [36]
+
+//! [37] //! [38]
+void MainWindow::writeSettings()
+//! [37] //! [39]
+{
+ QSettings settings("Trolltech", "Application Example");
+ settings.setValue("pos", pos());
+ settings.setValue("size", size());
+}
+//! [38] //! [39]
+
+//! [40]
+bool MainWindow::maybeSave()
+//! [40] //! [41]
+{
+ if (textEdit->document()->isModified()) {
+ QMessageBox::StandardButton ret;
+ ret = QMessageBox::warning(this, tr("Application"),
+ tr("The document has been modified.\n"
+ "Do you want to save your changes?"),
+ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+ if (ret == QMessageBox::Save)
+ return save();
+ else if (ret == QMessageBox::Cancel)
+ return false;
+ }
+ return true;
+}
+//! [41]
+
+//! [42]
+void MainWindow::loadFile(const QString &fileName)
+//! [42] //! [43]
+{
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("Application"),
+ tr("Cannot read file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QTextStream in(&file);
+#ifndef QT_NO_CURSOR
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+#endif
+ textEdit->setPlainText(in.readAll());
+#ifndef QT_NO_CURSOR
+ QApplication::restoreOverrideCursor();
+#endif
+
+ setCurrentFile(fileName);
+ statusBar()->showMessage(tr("File loaded"), 2000);
+}
+//! [43]
+
+//! [44]
+bool MainWindow::saveFile(const QString &fileName)
+//! [44] //! [45]
+{
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("Application"),
+ tr("Cannot write file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return false;
+ }
+
+ QTextStream out(&file);
+#ifndef QT_NO_CURSOR
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+#endif
+ out << textEdit->toPlainText();
+#ifndef QT_NO_CURSOR
+ QApplication::restoreOverrideCursor();
+#endif
+
+ setCurrentFile(fileName);
+ statusBar()->showMessage(tr("File saved"), 2000);
+ return true;
+}
+//! [45]
+
+//! [46]
+void MainWindow::setCurrentFile(const QString &fileName)
+//! [46] //! [47]
+{
+ curFile = fileName;
+ textEdit->document()->setModified(false);
+ setWindowModified(false);
+
+ QString shownName = curFile;
+ if (curFile.isEmpty())
+ shownName = "untitled.txt";
+ setWindowFilePath(shownName);
+}
+//! [47]
+
+//! [48]
+QString MainWindow::strippedName(const QString &fullFileName)
+//! [48] //! [49]
+{
+ return QFileInfo(fullFileName).fileName();
+}
+//! [49]
diff --git a/examples/widgets/mainwindows/application/mainwindow.h b/examples/widgets/mainwindows/application/mainwindow.h
new file mode 100644
index 0000000000..7f429e0ea3
--- /dev/null
+++ b/examples/widgets/mainwindows/application/mainwindow.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+class QPlainTextEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void newFile();
+ void open();
+ bool save();
+ bool saveAs();
+ void about();
+ void documentWasModified();
+
+private:
+ void createActions();
+ void createMenus();
+ void createToolBars();
+ void createStatusBar();
+ void readSettings();
+ void writeSettings();
+ bool maybeSave();
+ void loadFile(const QString &fileName);
+ bool saveFile(const QString &fileName);
+ void setCurrentFile(const QString &fileName);
+ QString strippedName(const QString &fullFileName);
+
+ QPlainTextEdit *textEdit;
+ QString curFile;
+
+ QMenu *fileMenu;
+ QMenu *editMenu;
+ QMenu *helpMenu;
+ QToolBar *fileToolBar;
+ QToolBar *editToolBar;
+ QAction *newAct;
+ QAction *openAct;
+ QAction *saveAct;
+ QAction *saveAsAct;
+ QAction *exitAct;
+ QAction *cutAct;
+ QAction *copyAct;
+ QAction *pasteAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/mainwindows/dockwidgets/dockwidgets.desktop b/examples/widgets/mainwindows/dockwidgets/dockwidgets.desktop
new file mode 100644
index 0000000000..1f57cb613b
--- /dev/null
+++ b/examples/widgets/mainwindows/dockwidgets/dockwidgets.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Dock Widgets
+Exec=/opt/usr/bin/dockwidgets
+Icon=dockwidgets
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/mainwindows/dockwidgets/dockwidgets.pro b/examples/widgets/mainwindows/dockwidgets/dockwidgets.pro
new file mode 100644
index 0000000000..7e0da2496e
--- /dev/null
+++ b/examples/widgets/mainwindows/dockwidgets/dockwidgets.pro
@@ -0,0 +1,15 @@
+HEADERS = mainwindow.h
+SOURCES = main.cpp \
+ mainwindow.cpp
+RESOURCES = dockwidgets.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/dockwidgets
+sources.files = $$SOURCES $$HEADERS $$RESOURCES dockwidgets.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/dockwidgets
+INSTALLS += target sources
+
+QT += widgets
+!isEmpty(QT.printsupport.name): QT += printsupport
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/mainwindows/dockwidgets/dockwidgets.qrc b/examples/widgets/mainwindows/dockwidgets/dockwidgets.qrc
new file mode 100644
index 0000000000..968feac7ea
--- /dev/null
+++ b/examples/widgets/mainwindows/dockwidgets/dockwidgets.qrc
@@ -0,0 +1,8 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/new.png</file>
+ <file>images/print.png</file>
+ <file>images/save.png</file>
+ <file>images/undo.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/mainwindows/dockwidgets/images/new.png b/examples/widgets/mainwindows/dockwidgets/images/new.png
new file mode 100644
index 0000000000..dd795cfffc
--- /dev/null
+++ b/examples/widgets/mainwindows/dockwidgets/images/new.png
Binary files differ
diff --git a/examples/widgets/mainwindows/dockwidgets/images/print.png b/examples/widgets/mainwindows/dockwidgets/images/print.png
new file mode 100644
index 0000000000..2afb769ee2
--- /dev/null
+++ b/examples/widgets/mainwindows/dockwidgets/images/print.png
Binary files differ
diff --git a/examples/widgets/mainwindows/dockwidgets/images/save.png b/examples/widgets/mainwindows/dockwidgets/images/save.png
new file mode 100644
index 0000000000..46eac82ad1
--- /dev/null
+++ b/examples/widgets/mainwindows/dockwidgets/images/save.png
Binary files differ
diff --git a/examples/widgets/mainwindows/dockwidgets/images/undo.png b/examples/widgets/mainwindows/dockwidgets/images/undo.png
new file mode 100644
index 0000000000..eee23d24a3
--- /dev/null
+++ b/examples/widgets/mainwindows/dockwidgets/images/undo.png
Binary files differ
diff --git a/examples/widgets/mainwindows/dockwidgets/main.cpp b/examples/widgets/mainwindows/dockwidgets/main.cpp
new file mode 100644
index 0000000000..19deafbb86
--- /dev/null
+++ b/examples/widgets/mainwindows/dockwidgets/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Q_INIT_RESOURCE(dockwidgets);
+ MainWindow mainWin;
+ mainWin.show();
+ return app.exec();
+}
diff --git a/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp b/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp
new file mode 100644
index 0000000000..da01d56502
--- /dev/null
+++ b/examples/widgets/mainwindows/dockwidgets/mainwindow.cpp
@@ -0,0 +1,345 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QtWidgets>
+#ifndef QT_NO_PRINTDIALOG
+#include <QtPrintSupport>
+#endif
+
+#include "mainwindow.h"
+//! [0]
+
+//! [1]
+MainWindow::MainWindow()
+{
+ textEdit = new QTextEdit;
+ setCentralWidget(textEdit);
+
+ createActions();
+ createMenus();
+ createToolBars();
+ createStatusBar();
+ createDockWindows();
+
+ setWindowTitle(tr("Dock Widgets"));
+
+ newLetter();
+ setUnifiedTitleAndToolBarOnMac(true);
+}
+//! [1]
+
+//! [2]
+void MainWindow::newLetter()
+{
+ textEdit->clear();
+
+ QTextCursor cursor(textEdit->textCursor());
+ cursor.movePosition(QTextCursor::Start);
+ QTextFrame *topFrame = cursor.currentFrame();
+ QTextFrameFormat topFrameFormat = topFrame->frameFormat();
+ topFrameFormat.setPadding(16);
+ topFrame->setFrameFormat(topFrameFormat);
+
+ QTextCharFormat textFormat;
+ QTextCharFormat boldFormat;
+ boldFormat.setFontWeight(QFont::Bold);
+ QTextCharFormat italicFormat;
+ italicFormat.setFontItalic(true);
+
+ QTextTableFormat tableFormat;
+ tableFormat.setBorder(1);
+ tableFormat.setCellPadding(16);
+ tableFormat.setAlignment(Qt::AlignRight);
+ cursor.insertTable(1, 1, tableFormat);
+ cursor.insertText("The Firm", boldFormat);
+ cursor.insertBlock();
+ cursor.insertText("321 City Street", textFormat);
+ cursor.insertBlock();
+ cursor.insertText("Industry Park");
+ cursor.insertBlock();
+ cursor.insertText("Some Country");
+ cursor.setPosition(topFrame->lastPosition());
+ cursor.insertText(QDate::currentDate().toString("d MMMM yyyy"), textFormat);
+ cursor.insertBlock();
+ cursor.insertBlock();
+ cursor.insertText("Dear ", textFormat);
+ cursor.insertText("NAME", italicFormat);
+ cursor.insertText(",", textFormat);
+ for (int i = 0; i < 3; ++i)
+ cursor.insertBlock();
+ cursor.insertText(tr("Yours sincerely,"), textFormat);
+ for (int i = 0; i < 3; ++i)
+ cursor.insertBlock();
+ cursor.insertText("The Boss", textFormat);
+ cursor.insertBlock();
+ cursor.insertText("ADDRESS", italicFormat);
+}
+//! [2]
+
+//! [3]
+void MainWindow::print()
+{
+#ifndef QT_NO_PRINTDIALOG
+ QTextDocument *document = textEdit->document();
+ QPrinter printer;
+
+ QPrintDialog *dlg = new QPrintDialog(&printer, this);
+ if (dlg->exec() != QDialog::Accepted)
+ return;
+
+ document->print(&printer);
+
+ statusBar()->showMessage(tr("Ready"), 2000);
+#endif
+}
+//! [3]
+
+//! [4]
+void MainWindow::save()
+{
+ QString fileName = QFileDialog::getSaveFileName(this,
+ tr("Choose a file name"), ".",
+ tr("HTML (*.html *.htm)"));
+ if (fileName.isEmpty())
+ return;
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("Dock Widgets"),
+ tr("Cannot write file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QTextStream out(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ out << textEdit->toHtml();
+ QApplication::restoreOverrideCursor();
+
+ statusBar()->showMessage(tr("Saved '%1'").arg(fileName), 2000);
+}
+//! [4]
+
+//! [5]
+void MainWindow::undo()
+{
+ QTextDocument *document = textEdit->document();
+ document->undo();
+}
+//! [5]
+
+//! [6]
+void MainWindow::insertCustomer(const QString &customer)
+{
+ if (customer.isEmpty())
+ return;
+ QStringList customerList = customer.split(", ");
+ QTextDocument *document = textEdit->document();
+ QTextCursor cursor = document->find("NAME");
+ if (!cursor.isNull()) {
+ cursor.beginEditBlock();
+ cursor.insertText(customerList.at(0));
+ QTextCursor oldcursor = cursor;
+ cursor = document->find("ADDRESS");
+ if (!cursor.isNull()) {
+ for (int i = 1; i < customerList.size(); ++i) {
+ cursor.insertBlock();
+ cursor.insertText(customerList.at(i));
+ }
+ cursor.endEditBlock();
+ }
+ else
+ oldcursor.endEditBlock();
+ }
+}
+//! [6]
+
+//! [7]
+void MainWindow::addParagraph(const QString &paragraph)
+{
+ if (paragraph.isEmpty())
+ return;
+ QTextDocument *document = textEdit->document();
+ QTextCursor cursor = document->find(tr("Yours sincerely,"));
+ if (cursor.isNull())
+ return;
+ cursor.beginEditBlock();
+ cursor.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor, 2);
+ cursor.insertBlock();
+ cursor.insertText(paragraph);
+ cursor.insertBlock();
+ cursor.endEditBlock();
+
+}
+//! [7]
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Dock Widgets"),
+ tr("The <b>Dock Widgets</b> example demonstrates how to "
+ "use Qt's dock widgets. You can enter your own text, "
+ "click a customer to add a customer name and "
+ "address, and click standard paragraphs to add them."));
+}
+
+void MainWindow::createActions()
+{
+ newLetterAct = new QAction(QIcon(":/images/new.png"), tr("&New Letter"),
+ this);
+ newLetterAct->setShortcuts(QKeySequence::New);
+ newLetterAct->setStatusTip(tr("Create a new form letter"));
+ connect(newLetterAct, SIGNAL(triggered()), this, SLOT(newLetter()));
+
+ saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save..."), this);
+ saveAct->setShortcuts(QKeySequence::Save);
+ saveAct->setStatusTip(tr("Save the current form letter"));
+ connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
+
+ printAct = new QAction(QIcon(":/images/print.png"), tr("&Print..."), this);
+ printAct->setShortcuts(QKeySequence::Print);
+ printAct->setStatusTip(tr("Print the current form letter"));
+ connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
+
+ undoAct = new QAction(QIcon(":/images/undo.png"), tr("&Undo"), this);
+ undoAct->setShortcuts(QKeySequence::Undo);
+ undoAct->setStatusTip(tr("Undo the last editing action"));
+ connect(undoAct, SIGNAL(triggered()), this, SLOT(undo()));
+
+ quitAct = new QAction(tr("&Quit"), this);
+ quitAct->setShortcuts(QKeySequence::Quit);
+ quitAct->setStatusTip(tr("Quit the application"));
+ connect(quitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ aboutAct->setStatusTip(tr("Show the application's About box"));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(newLetterAct);
+ fileMenu->addAction(saveAct);
+ fileMenu->addAction(printAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(quitAct);
+
+ editMenu = menuBar()->addMenu(tr("&Edit"));
+ editMenu->addAction(undoAct);
+
+ viewMenu = menuBar()->addMenu(tr("&View"));
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+
+void MainWindow::createToolBars()
+{
+ fileToolBar = addToolBar(tr("File"));
+ fileToolBar->addAction(newLetterAct);
+ fileToolBar->addAction(saveAct);
+ fileToolBar->addAction(printAct);
+
+ editToolBar = addToolBar(tr("Edit"));
+ editToolBar->addAction(undoAct);
+}
+
+//! [8]
+void MainWindow::createStatusBar()
+{
+ statusBar()->showMessage(tr("Ready"));
+}
+//! [8]
+
+//! [9]
+void MainWindow::createDockWindows()
+{
+ QDockWidget *dock = new QDockWidget(tr("Customers"), this);
+ dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+ customerList = new QListWidget(dock);
+ customerList->addItems(QStringList()
+ << "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
+ << "Jane Doe, Memorabilia, 23 Watersedge, Beaton"
+ << "Tammy Shea, Tiblanka, 38 Sea Views, Carlton"
+ << "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal"
+ << "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston"
+ << "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
+ dock->setWidget(customerList);
+ addDockWidget(Qt::RightDockWidgetArea, dock);
+ viewMenu->addAction(dock->toggleViewAction());
+
+ dock = new QDockWidget(tr("Paragraphs"), this);
+ paragraphsList = new QListWidget(dock);
+ paragraphsList->addItems(QStringList()
+ << "Thank you for your payment which we have received today."
+ << "Your order has been dispatched and should be with you "
+ "within 28 days."
+ << "We have dispatched those items that were in stock. The "
+ "rest of your order will be dispatched once all the "
+ "remaining items have arrived at our warehouse. No "
+ "additional shipping charges will be made."
+ << "You made a small overpayment (less than $5) which we "
+ "will keep on account for you, or return at your request."
+ << "You made a small underpayment (less than $1), but we have "
+ "sent your order anyway. We'll add this underpayment to "
+ "your next bill."
+ << "Unfortunately you did not send enough money. Please remit "
+ "an additional $. Your order will be dispatched as soon as "
+ "the complete amount has been received."
+ << "You made an overpayment (more than $5). Do you wish to "
+ "buy more items, or should we return the excess to you?");
+ dock->setWidget(paragraphsList);
+ addDockWidget(Qt::RightDockWidgetArea, dock);
+ viewMenu->addAction(dock->toggleViewAction());
+
+ connect(customerList, SIGNAL(currentTextChanged(QString)),
+ this, SLOT(insertCustomer(QString)));
+ connect(paragraphsList, SIGNAL(currentTextChanged(QString)),
+ this, SLOT(addParagraph(QString)));
+}
+//! [9]
diff --git a/examples/widgets/mainwindows/dockwidgets/mainwindow.h b/examples/widgets/mainwindows/dockwidgets/mainwindow.h
new file mode 100644
index 0000000000..9f3eeb4e6b
--- /dev/null
+++ b/examples/widgets/mainwindows/dockwidgets/mainwindow.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QListWidget;
+class QMenu;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void newLetter();
+ void save();
+ void print();
+ void undo();
+ void about();
+ void insertCustomer(const QString &customer);
+ void addParagraph(const QString &paragraph);
+
+private:
+ void createActions();
+ void createMenus();
+ void createToolBars();
+ void createStatusBar();
+ void createDockWindows();
+
+ QTextEdit *textEdit;
+ QListWidget *customerList;
+ QListWidget *paragraphsList;
+
+ QMenu *fileMenu;
+ QMenu *editMenu;
+ QMenu *viewMenu;
+ QMenu *helpMenu;
+ QToolBar *fileToolBar;
+ QToolBar *editToolBar;
+ QAction *newLetterAct;
+ QAction *saveAct;
+ QAction *printAct;
+ QAction *undoAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+ QAction *quitAct;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.cpp b/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
new file mode 100644
index 0000000000..c84669d377
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/colorswatch.cpp
@@ -0,0 +1,746 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "colorswatch.h"
+
+#include <QAction>
+#include <QtEvents>
+#include <QFrame>
+#include <QMainWindow>
+#include <QMenu>
+#include <QPainter>
+#include <QImage>
+#include <QColor>
+#include <QDialog>
+#include <QGridLayout>
+#include <QSpinBox>
+#include <QLabel>
+#include <QPainterPath>
+#include <QPushButton>
+#include <QHBoxLayout>
+#include <QBitmap>
+#include <QtDebug>
+
+#undef DEBUG_SIZEHINTS
+
+QColor bgColorForName(const QString &name)
+{
+ if (name == "Black")
+ return QColor("#D8D8D8");
+ else if (name == "White")
+ return QColor("#F1F1F1");
+ else if (name == "Red")
+ return QColor("#F1D8D8");
+ else if (name == "Green")
+ return QColor("#D8E4D8");
+ else if (name == "Blue")
+ return QColor("#D8D8F1");
+ else if (name == "Yellow")
+ return QColor("#F1F0D8");
+ return QColor(name).light(110);
+}
+
+QColor fgColorForName(const QString &name)
+{
+ if (name == "Black")
+ return QColor("#6C6C6C");
+ else if (name == "White")
+ return QColor("#F8F8F8");
+ else if (name == "Red")
+ return QColor("#F86C6C");
+ else if (name == "Green")
+ return QColor("#6CB26C");
+ else if (name == "Blue")
+ return QColor("#6C6CF8");
+ else if (name == "Yellow")
+ return QColor("#F8F76C");
+ return QColor(name);
+}
+
+class ColorDock : public QFrame
+{
+ Q_OBJECT
+public:
+ ColorDock(const QString &c, QWidget *parent);
+
+ virtual QSize sizeHint() const;
+ virtual QSize minimumSizeHint() const;
+
+ void setCustomSizeHint(const QSize &size);
+
+public slots:
+ void changeSizeHints();
+
+protected:
+ void paintEvent(QPaintEvent *);
+ QString color;
+ QSize szHint, minSzHint;
+};
+
+ColorDock::ColorDock(const QString &c, QWidget *parent)
+ : QFrame(parent) , color(c)
+{
+ QFont font = this->font();
+ font.setPointSize(8);
+ setFont(font);
+ szHint = QSize(-1, -1);
+ minSzHint = QSize(125, 75);
+}
+
+QSize ColorDock::sizeHint() const
+{
+ return szHint;
+}
+
+QSize ColorDock::minimumSizeHint() const
+{
+ return minSzHint;
+}
+
+void ColorDock::paintEvent(QPaintEvent *)
+{
+ QPainter p(this);
+ p.setRenderHint(QPainter::Antialiasing);
+ p.fillRect(rect(), bgColorForName(color));
+
+ p.save();
+
+ extern void render_qt_text(QPainter *, int, int, const QColor &);
+ render_qt_text(&p, width(), height(), fgColorForName(color));
+
+ p.restore();
+
+#ifdef DEBUG_SIZEHINTS
+ p.setRenderHint(QPainter::Antialiasing, false);
+
+ QSize sz = size();
+ QSize szHint = sizeHint();
+ QSize minSzHint = minimumSizeHint();
+ QSize maxSz = maximumSize();
+ QString text = QString::fromLatin1("sz: %1x%2\nszHint: %3x%4\nminSzHint: %5x%6\n"
+ "maxSz: %8x%9")
+ .arg(sz.width()).arg(sz.height())
+ .arg(szHint.width()).arg(szHint.height())
+ .arg(minSzHint.width()).arg(minSzHint.height())
+ .arg(maxSz.width()).arg(maxSz.height());
+
+ QRect r = fontMetrics().boundingRect(rect(), Qt::AlignLeft|Qt::AlignTop, text);
+ r.adjust(-2, -2, 1, 1);
+ p.translate(4, 4);
+ QColor bg = Qt::yellow;
+ bg.setAlpha(120);
+ p.setBrush(bg);
+ p.setPen(Qt::black);
+ p.drawRect(r);
+ p.drawText(rect(), Qt::AlignLeft|Qt::AlignTop, text);
+#endif // DEBUG_SIZEHINTS
+}
+
+static QSpinBox *createSpinBox(int value, QWidget *parent, int max = 1000)
+{
+ QSpinBox *result = new QSpinBox(parent);
+ result->setMinimum(-1);
+ result->setMaximum(max);
+ result->setValue(value);
+ return result;
+}
+
+void ColorDock::changeSizeHints()
+{
+ QDialog dialog(this);
+ dialog.setWindowTitle(color);
+
+ QVBoxLayout *topLayout = new QVBoxLayout(&dialog);
+
+ QGridLayout *inputLayout = new QGridLayout();
+ topLayout->addLayout(inputLayout);
+
+ inputLayout->addWidget(new QLabel(tr("Size Hint:"), &dialog), 0, 0);
+ inputLayout->addWidget(new QLabel(tr("Min Size Hint:"), &dialog), 1, 0);
+ inputLayout->addWidget(new QLabel(tr("Max Size:"), &dialog), 2, 0);
+ inputLayout->addWidget(new QLabel(tr("Dockwgt Max Size:"), &dialog), 3, 0);
+
+ QSpinBox *szHintW = createSpinBox(szHint.width(), &dialog);
+ inputLayout->addWidget(szHintW, 0, 1);
+ QSpinBox *szHintH = createSpinBox(szHint.height(), &dialog);
+ inputLayout->addWidget(szHintH, 0, 2);
+
+ QSpinBox *minSzHintW = createSpinBox(minSzHint.width(), &dialog);
+ inputLayout->addWidget(minSzHintW, 1, 1);
+ QSpinBox *minSzHintH = createSpinBox(minSzHint.height(), &dialog);
+ inputLayout->addWidget(minSzHintH, 1, 2);
+
+ QSize maxSz = maximumSize();
+ QSpinBox *maxSzW = createSpinBox(maxSz.width(), &dialog, QWIDGETSIZE_MAX);
+ inputLayout->addWidget(maxSzW, 2, 1);
+ QSpinBox *maxSzH = createSpinBox(maxSz.height(), &dialog, QWIDGETSIZE_MAX);
+ inputLayout->addWidget(maxSzH, 2, 2);
+
+ QSize dwMaxSz = parentWidget()->maximumSize();
+ QSpinBox *dwMaxSzW = createSpinBox(dwMaxSz.width(), &dialog, QWIDGETSIZE_MAX);
+ inputLayout->addWidget(dwMaxSzW, 3, 1);
+ QSpinBox *dwMaxSzH = createSpinBox(dwMaxSz.height(), &dialog, QWIDGETSIZE_MAX);
+ inputLayout->addWidget(dwMaxSzH, 3, 2);
+
+ inputLayout->setColumnStretch(1, 1);
+ inputLayout->setColumnStretch(2, 1);
+
+ topLayout->addStretch();
+
+ QHBoxLayout *buttonBox = new QHBoxLayout();
+ topLayout->addLayout(buttonBox);
+
+ QPushButton *okButton = new QPushButton(tr("Ok"), &dialog);
+ QPushButton *cancelButton = new QPushButton(tr("Cancel"), &dialog);
+ connect(okButton, SIGNAL(clicked()), &dialog, SLOT(accept()));
+ connect(cancelButton, SIGNAL(clicked()), &dialog, SLOT(reject()));
+ buttonBox->addStretch();
+ buttonBox->addWidget(cancelButton);
+ buttonBox->addWidget(okButton);
+
+
+ if (!dialog.exec())
+ return;
+
+ szHint = QSize(szHintW->value(), szHintH->value());
+ minSzHint = QSize(minSzHintW->value(), minSzHintH->value());
+ maxSz = QSize(maxSzW->value(), maxSzH->value());
+ setMaximumSize(maxSz);
+ dwMaxSz = QSize(dwMaxSzW->value(), dwMaxSzH->value());
+ parentWidget()->setMaximumSize(dwMaxSz);
+ updateGeometry();
+ update();
+}
+
+void ColorDock::setCustomSizeHint(const QSize &size)
+{
+ szHint = size;
+ updateGeometry();
+}
+
+ColorSwatch::ColorSwatch(const QString &colorName, QWidget *parent, Qt::WindowFlags flags)
+ : QDockWidget(parent, flags)
+{
+ setObjectName(colorName + QLatin1String(" Dock Widget"));
+ setWindowTitle(objectName() + QLatin1String(" [*]"));
+
+ QFrame *swatch = new ColorDock(colorName, this);
+ swatch->setFrameStyle(QFrame::Box | QFrame::Sunken);
+
+ setWidget(swatch);
+
+ changeSizeHintsAction = new QAction(tr("Change Size Hints"), this);
+ connect(changeSizeHintsAction, SIGNAL(triggered()), swatch, SLOT(changeSizeHints()));
+
+ closableAction = new QAction(tr("Closable"), this);
+ closableAction->setCheckable(true);
+ connect(closableAction, SIGNAL(triggered(bool)), SLOT(changeClosable(bool)));
+
+ movableAction = new QAction(tr("Movable"), this);
+ movableAction->setCheckable(true);
+ connect(movableAction, SIGNAL(triggered(bool)), SLOT(changeMovable(bool)));
+
+ floatableAction = new QAction(tr("Floatable"), this);
+ floatableAction->setCheckable(true);
+ connect(floatableAction, SIGNAL(triggered(bool)), SLOT(changeFloatable(bool)));
+
+ verticalTitleBarAction = new QAction(tr("Vertical title bar"), this);
+ verticalTitleBarAction->setCheckable(true);
+ connect(verticalTitleBarAction, SIGNAL(triggered(bool)),
+ SLOT(changeVerticalTitleBar(bool)));
+
+ floatingAction = new QAction(tr("Floating"), this);
+ floatingAction->setCheckable(true);
+ connect(floatingAction, SIGNAL(triggered(bool)), SLOT(changeFloating(bool)));
+
+ allowedAreasActions = new QActionGroup(this);
+ allowedAreasActions->setExclusive(false);
+
+ allowLeftAction = new QAction(tr("Allow on Left"), this);
+ allowLeftAction->setCheckable(true);
+ connect(allowLeftAction, SIGNAL(triggered(bool)), SLOT(allowLeft(bool)));
+
+ allowRightAction = new QAction(tr("Allow on Right"), this);
+ allowRightAction->setCheckable(true);
+ connect(allowRightAction, SIGNAL(triggered(bool)), SLOT(allowRight(bool)));
+
+ allowTopAction = new QAction(tr("Allow on Top"), this);
+ allowTopAction->setCheckable(true);
+ connect(allowTopAction, SIGNAL(triggered(bool)), SLOT(allowTop(bool)));
+
+ allowBottomAction = new QAction(tr("Allow on Bottom"), this);
+ allowBottomAction->setCheckable(true);
+ connect(allowBottomAction, SIGNAL(triggered(bool)), SLOT(allowBottom(bool)));
+
+ allowedAreasActions->addAction(allowLeftAction);
+ allowedAreasActions->addAction(allowRightAction);
+ allowedAreasActions->addAction(allowTopAction);
+ allowedAreasActions->addAction(allowBottomAction);
+
+ areaActions = new QActionGroup(this);
+ areaActions->setExclusive(true);
+
+ leftAction = new QAction(tr("Place on Left") , this);
+ leftAction->setCheckable(true);
+ connect(leftAction, SIGNAL(triggered(bool)), SLOT(placeLeft(bool)));
+
+ rightAction = new QAction(tr("Place on Right") , this);
+ rightAction->setCheckable(true);
+ connect(rightAction, SIGNAL(triggered(bool)), SLOT(placeRight(bool)));
+
+ topAction = new QAction(tr("Place on Top") , this);
+ topAction->setCheckable(true);
+ connect(topAction, SIGNAL(triggered(bool)), SLOT(placeTop(bool)));
+
+ bottomAction = new QAction(tr("Place on Bottom") , this);
+ bottomAction->setCheckable(true);
+ connect(bottomAction, SIGNAL(triggered(bool)), SLOT(placeBottom(bool)));
+
+ areaActions->addAction(leftAction);
+ areaActions->addAction(rightAction);
+ areaActions->addAction(topAction);
+ areaActions->addAction(bottomAction);
+
+ connect(movableAction, SIGNAL(triggered(bool)), areaActions, SLOT(setEnabled(bool)));
+
+ connect(movableAction, SIGNAL(triggered(bool)), allowedAreasActions, SLOT(setEnabled(bool)));
+
+ connect(floatableAction, SIGNAL(triggered(bool)), floatingAction, SLOT(setEnabled(bool)));
+
+ connect(floatingAction, SIGNAL(triggered(bool)), floatableAction, SLOT(setDisabled(bool)));
+ connect(movableAction, SIGNAL(triggered(bool)), floatableAction, SLOT(setEnabled(bool)));
+
+ tabMenu = new QMenu(this);
+ tabMenu->setTitle(tr("Tab into"));
+ connect(tabMenu, SIGNAL(triggered(QAction*)), this, SLOT(tabInto(QAction*)));
+
+ splitHMenu = new QMenu(this);
+ splitHMenu->setTitle(tr("Split horizontally into"));
+ connect(splitHMenu, SIGNAL(triggered(QAction*)), this, SLOT(splitInto(QAction*)));
+
+ splitVMenu = new QMenu(this);
+ splitVMenu->setTitle(tr("Split vertically into"));
+ connect(splitVMenu, SIGNAL(triggered(QAction*)), this, SLOT(splitInto(QAction*)));
+
+ windowModifiedAction = new QAction(tr("Modified"), this);
+ windowModifiedAction->setCheckable(true);
+ windowModifiedAction->setChecked(false);
+ connect(windowModifiedAction, SIGNAL(toggled(bool)), this, SLOT(setWindowModified(bool)));
+
+ menu = new QMenu(colorName, this);
+ menu->addAction(toggleViewAction());
+ QAction *action = menu->addAction(tr("Raise"));
+ connect(action, SIGNAL(triggered()), this, SLOT(raise()));
+ menu->addAction(changeSizeHintsAction);
+ menu->addSeparator();
+ menu->addAction(closableAction);
+ menu->addAction(movableAction);
+ menu->addAction(floatableAction);
+ menu->addAction(floatingAction);
+ menu->addAction(verticalTitleBarAction);
+ menu->addSeparator();
+ menu->addActions(allowedAreasActions->actions());
+ menu->addSeparator();
+ menu->addActions(areaActions->actions());
+ menu->addSeparator();
+ menu->addMenu(splitHMenu);
+ menu->addMenu(splitVMenu);
+ menu->addMenu(tabMenu);
+ menu->addSeparator();
+ menu->addAction(windowModifiedAction);
+
+ connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateContextMenu()));
+
+ if(colorName == "Black") {
+ leftAction->setShortcut(Qt::CTRL|Qt::Key_W);
+ rightAction->setShortcut(Qt::CTRL|Qt::Key_E);
+ toggleViewAction()->setShortcut(Qt::CTRL|Qt::Key_R);
+ }
+}
+
+void ColorSwatch::updateContextMenu()
+{
+ QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
+ const Qt::DockWidgetArea area = mainWindow->dockWidgetArea(this);
+ const Qt::DockWidgetAreas areas = allowedAreas();
+
+ closableAction->setChecked(features() & QDockWidget::DockWidgetClosable);
+ if (windowType() == Qt::Drawer) {
+ floatableAction->setEnabled(false);
+ floatingAction->setEnabled(false);
+ movableAction->setEnabled(false);
+ verticalTitleBarAction->setChecked(false);
+ } else {
+ floatableAction->setChecked(features() & QDockWidget::DockWidgetFloatable);
+ floatingAction->setChecked(isWindow());
+ // done after floating, to get 'floatable' correctly initialized
+ movableAction->setChecked(features() & QDockWidget::DockWidgetMovable);
+ verticalTitleBarAction
+ ->setChecked(features() & QDockWidget::DockWidgetVerticalTitleBar);
+ }
+
+ allowLeftAction->setChecked(isAreaAllowed(Qt::LeftDockWidgetArea));
+ allowRightAction->setChecked(isAreaAllowed(Qt::RightDockWidgetArea));
+ allowTopAction->setChecked(isAreaAllowed(Qt::TopDockWidgetArea));
+ allowBottomAction->setChecked(isAreaAllowed(Qt::BottomDockWidgetArea));
+
+ if (allowedAreasActions->isEnabled()) {
+ allowLeftAction->setEnabled(area != Qt::LeftDockWidgetArea);
+ allowRightAction->setEnabled(area != Qt::RightDockWidgetArea);
+ allowTopAction->setEnabled(area != Qt::TopDockWidgetArea);
+ allowBottomAction->setEnabled(area != Qt::BottomDockWidgetArea);
+ }
+
+ leftAction->blockSignals(true);
+ rightAction->blockSignals(true);
+ topAction->blockSignals(true);
+ bottomAction->blockSignals(true);
+
+ leftAction->setChecked(area == Qt::LeftDockWidgetArea);
+ rightAction->setChecked(area == Qt::RightDockWidgetArea);
+ topAction->setChecked(area == Qt::TopDockWidgetArea);
+ bottomAction->setChecked(area == Qt::BottomDockWidgetArea);
+
+ leftAction->blockSignals(false);
+ rightAction->blockSignals(false);
+ topAction->blockSignals(false);
+ bottomAction->blockSignals(false);
+
+ if (areaActions->isEnabled()) {
+ leftAction->setEnabled(areas & Qt::LeftDockWidgetArea);
+ rightAction->setEnabled(areas & Qt::RightDockWidgetArea);
+ topAction->setEnabled(areas & Qt::TopDockWidgetArea);
+ bottomAction->setEnabled(areas & Qt::BottomDockWidgetArea);
+ }
+
+ tabMenu->clear();
+ splitHMenu->clear();
+ splitVMenu->clear();
+ QList<ColorSwatch*> dock_list = mainWindow->findChildren<ColorSwatch*>();
+ foreach (ColorSwatch *dock, dock_list) {
+// if (!dock->isVisible() || dock->isFloating())
+// continue;
+ tabMenu->addAction(dock->objectName());
+ splitHMenu->addAction(dock->objectName());
+ splitVMenu->addAction(dock->objectName());
+ }
+}
+
+void ColorSwatch::splitInto(QAction *action)
+{
+ QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
+ QList<ColorSwatch*> dock_list = mainWindow->findChildren<ColorSwatch*>();
+ ColorSwatch *target = 0;
+ foreach (ColorSwatch *dock, dock_list) {
+ if (action->text() == dock->objectName()) {
+ target = dock;
+ break;
+ }
+ }
+ if (target == 0)
+ return;
+
+ Qt::Orientation o = action->parent() == splitHMenu
+ ? Qt::Horizontal : Qt::Vertical;
+ mainWindow->splitDockWidget(target, this, o);
+}
+
+void ColorSwatch::tabInto(QAction *action)
+{
+ QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
+ QList<ColorSwatch*> dock_list = mainWindow->findChildren<ColorSwatch*>();
+ ColorSwatch *target = 0;
+ foreach (ColorSwatch *dock, dock_list) {
+ if (action->text() == dock->objectName()) {
+ target = dock;
+ break;
+ }
+ }
+ if (target == 0)
+ return;
+
+ mainWindow->tabifyDockWidget(target, this);
+}
+
+void ColorSwatch::contextMenuEvent(QContextMenuEvent *event)
+{
+ event->accept();
+ menu->exec(event->globalPos());
+}
+
+void ColorSwatch::resizeEvent(QResizeEvent *e)
+{
+ if (BlueTitleBar *btb = qobject_cast<BlueTitleBar*>(titleBarWidget()))
+ btb->updateMask();
+
+ QDockWidget::resizeEvent(e);
+}
+
+
+void ColorSwatch::allow(Qt::DockWidgetArea area, bool a)
+{
+ Qt::DockWidgetAreas areas = allowedAreas();
+ areas = a ? areas | area : areas & ~area;
+ setAllowedAreas(areas);
+
+ if (areaActions->isEnabled()) {
+ leftAction->setEnabled(areas & Qt::LeftDockWidgetArea);
+ rightAction->setEnabled(areas & Qt::RightDockWidgetArea);
+ topAction->setEnabled(areas & Qt::TopDockWidgetArea);
+ bottomAction->setEnabled(areas & Qt::BottomDockWidgetArea);
+ }
+}
+
+void ColorSwatch::place(Qt::DockWidgetArea area, bool p)
+{
+ if (!p) return;
+
+ QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
+ mainWindow->addDockWidget(area, this);
+
+ if (allowedAreasActions->isEnabled()) {
+ allowLeftAction->setEnabled(area != Qt::LeftDockWidgetArea);
+ allowRightAction->setEnabled(area != Qt::RightDockWidgetArea);
+ allowTopAction->setEnabled(area != Qt::TopDockWidgetArea);
+ allowBottomAction->setEnabled(area != Qt::BottomDockWidgetArea);
+ }
+}
+
+void ColorSwatch::setCustomSizeHint(const QSize &size)
+{
+ if (ColorDock *dock = qobject_cast<ColorDock*>(widget()))
+ dock->setCustomSizeHint(size);
+}
+
+void ColorSwatch::changeClosable(bool on)
+{ setFeatures(on ? features() | DockWidgetClosable : features() & ~DockWidgetClosable); }
+
+void ColorSwatch::changeMovable(bool on)
+{ setFeatures(on ? features() | DockWidgetMovable : features() & ~DockWidgetMovable); }
+
+void ColorSwatch::changeFloatable(bool on)
+{ setFeatures(on ? features() | DockWidgetFloatable : features() & ~DockWidgetFloatable); }
+
+void ColorSwatch::changeFloating(bool floating)
+{ setFloating(floating); }
+
+void ColorSwatch::allowLeft(bool a)
+{ allow(Qt::LeftDockWidgetArea, a); }
+
+void ColorSwatch::allowRight(bool a)
+{ allow(Qt::RightDockWidgetArea, a); }
+
+void ColorSwatch::allowTop(bool a)
+{ allow(Qt::TopDockWidgetArea, a); }
+
+void ColorSwatch::allowBottom(bool a)
+{ allow(Qt::BottomDockWidgetArea, a); }
+
+void ColorSwatch::placeLeft(bool p)
+{ place(Qt::LeftDockWidgetArea, p); }
+
+void ColorSwatch::placeRight(bool p)
+{ place(Qt::RightDockWidgetArea, p); }
+
+void ColorSwatch::placeTop(bool p)
+{ place(Qt::TopDockWidgetArea, p); }
+
+void ColorSwatch::placeBottom(bool p)
+{ place(Qt::BottomDockWidgetArea, p); }
+
+void ColorSwatch::changeVerticalTitleBar(bool on)
+{
+ setFeatures(on ? features() | DockWidgetVerticalTitleBar
+ : features() & ~DockWidgetVerticalTitleBar);
+}
+
+QSize BlueTitleBar::minimumSizeHint() const
+{
+ QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
+ Q_ASSERT(dw != 0);
+ QSize result(leftPm.width() + rightPm.width(), centerPm.height());
+ if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar)
+ result.transpose();
+ return result;
+}
+
+BlueTitleBar::BlueTitleBar(QWidget *parent)
+ : QWidget(parent)
+{
+ leftPm = QPixmap(":/res/titlebarLeft.png");
+ centerPm = QPixmap(":/res/titlebarCenter.png");
+ rightPm = QPixmap(":/res/titlebarRight.png");
+}
+
+void BlueTitleBar::paintEvent(QPaintEvent*)
+{
+ QPainter painter(this);
+ QRect rect = this->rect();
+
+ QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
+ Q_ASSERT(dw != 0);
+
+ if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
+ QSize s = rect.size();
+ s.transpose();
+ rect.setSize(s);
+
+ painter.translate(rect.left(), rect.top() + rect.width());
+ painter.rotate(-90);
+ painter.translate(-rect.left(), -rect.top());
+ }
+
+ painter.drawPixmap(rect.topLeft(), leftPm);
+ painter.drawPixmap(rect.topRight() - QPoint(rightPm.width() - 1, 0), rightPm);
+ QBrush brush(centerPm);
+ painter.fillRect(rect.left() + leftPm.width(), rect.top(),
+ rect.width() - leftPm.width() - rightPm.width(),
+ centerPm.height(), centerPm);
+}
+
+void BlueTitleBar::mousePressEvent(QMouseEvent *event)
+{
+ QPoint pos = event->pos();
+
+ QRect rect = this->rect();
+
+ QDockWidget *dw = qobject_cast<QDockWidget*>(parentWidget());
+ Q_ASSERT(dw != 0);
+
+ if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
+ QPoint p = pos;
+ pos.setX(rect.left() + rect.bottom() - p.y());
+ pos.setY(rect.top() + p.x() - rect.left());
+
+ QSize s = rect.size();
+ s.transpose();
+ rect.setSize(s);
+ }
+
+ const int buttonRight = 7;
+ const int buttonWidth = 20;
+ int right = rect.right() - pos.x();
+ int button = (right - buttonRight)/buttonWidth;
+ switch (button) {
+ case 0:
+ event->accept();
+ dw->close();
+ break;
+ case 1:
+ event->accept();
+ dw->setFloating(!dw->isFloating());
+ break;
+ case 2: {
+ event->accept();
+ QDockWidget::DockWidgetFeatures features = dw->features();
+ if (features & QDockWidget::DockWidgetVerticalTitleBar)
+ features &= ~QDockWidget::DockWidgetVerticalTitleBar;
+ else
+ features |= QDockWidget::DockWidgetVerticalTitleBar;
+ dw->setFeatures(features);
+ break;
+ }
+ default:
+ event->ignore();
+ break;
+ }
+}
+
+void BlueTitleBar::updateMask()
+{
+ QDockWidget *dw = qobject_cast<QDockWidget*>(parent());
+ Q_ASSERT(dw != 0);
+
+ QRect rect = dw->rect();
+ QPixmap bitmap(dw->size());
+
+ {
+ QPainter painter(&bitmap);
+
+ ///initialize to transparent
+ painter.fillRect(rect, Qt::color0);
+
+ QRect contents = rect;
+ contents.setTopLeft(geometry().bottomLeft());
+ contents.setRight(geometry().right());
+ contents.setBottom(contents.bottom()-y());
+ painter.fillRect(contents, Qt::color1);
+
+
+
+ //let's pait the titlebar
+
+ QRect titleRect = this->geometry();
+
+ if (dw->features() & QDockWidget::DockWidgetVerticalTitleBar) {
+ QSize s = rect.size();
+ s.transpose();
+ rect.setSize(s);
+
+ QSize s2 = size();
+ s2.transpose();
+ titleRect.setSize(s2);
+
+ painter.translate(rect.left(), rect.top() + rect.width());
+ painter.rotate(-90);
+ painter.translate(-rect.left(), -rect.top());
+ }
+
+ contents.setTopLeft(titleRect.bottomLeft());
+ contents.setRight(titleRect.right());
+ contents.setBottom(rect.bottom()-y());
+
+ QRect rect = titleRect;
+
+
+ painter.drawPixmap(rect.topLeft(), leftPm.mask());
+ painter.fillRect(rect.left() + leftPm.width(), rect.top(),
+ rect.width() - leftPm.width() - rightPm.width(),
+ centerPm.height(), Qt::color1);
+ painter.drawPixmap(rect.topRight() - QPoint(rightPm.width() - 1, 0), rightPm.mask());
+
+ painter.fillRect(contents, Qt::color1);
+ }
+
+ dw->setMask(bitmap);
+}
+
+#include "colorswatch.moc"
diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.h b/examples/widgets/mainwindows/mainwindow/colorswatch.h
new file mode 100644
index 0000000000..794a69cd6c
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/colorswatch.h
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COLORSWATCH_H
+#define COLORSWATCH_H
+
+#include <QDockWidget>
+
+QT_FORWARD_DECLARE_CLASS(QAction)
+QT_FORWARD_DECLARE_CLASS(QActionGroup)
+QT_FORWARD_DECLARE_CLASS(QMenu)
+
+class ColorSwatch : public QDockWidget
+{
+ Q_OBJECT
+
+ QAction *closableAction;
+ QAction *movableAction;
+ QAction *floatableAction;
+ QAction *floatingAction;
+ QAction *verticalTitleBarAction;
+
+ QActionGroup *allowedAreasActions;
+ QAction *allowLeftAction;
+ QAction *allowRightAction;
+ QAction *allowTopAction;
+ QAction *allowBottomAction;
+
+ QActionGroup *areaActions;
+ QAction *leftAction;
+ QAction *rightAction;
+ QAction *topAction;
+ QAction *bottomAction;
+
+ QAction *changeSizeHintsAction;
+
+ QMenu *tabMenu;
+ QMenu *splitHMenu;
+ QMenu *splitVMenu;
+
+ QAction *windowModifiedAction;
+
+public:
+ ColorSwatch(const QString &colorName, QWidget *parent = 0, Qt::WindowFlags flags = 0);
+
+ QMenu *menu;
+ void setCustomSizeHint(const QSize &size);
+
+protected:
+ virtual void contextMenuEvent(QContextMenuEvent *event);
+ virtual void resizeEvent(QResizeEvent *e);
+
+private:
+ void allow(Qt::DockWidgetArea area, bool allow);
+ void place(Qt::DockWidgetArea area, bool place);
+
+private slots:
+ void changeClosable(bool on);
+ void changeMovable(bool on);
+ void changeFloatable(bool on);
+ void changeFloating(bool on);
+ void changeVerticalTitleBar(bool on);
+ void updateContextMenu();
+
+ void allowLeft(bool a);
+ void allowRight(bool a);
+ void allowTop(bool a);
+ void allowBottom(bool a);
+
+ void placeLeft(bool p);
+ void placeRight(bool p);
+ void placeTop(bool p);
+ void placeBottom(bool p);
+
+ void splitInto(QAction *action);
+ void tabInto(QAction *action);
+};
+
+class BlueTitleBar : public QWidget
+{
+ Q_OBJECT
+public:
+ BlueTitleBar(QWidget *parent = 0);
+
+ QSize sizeHint() const { return minimumSizeHint(); }
+ QSize minimumSizeHint() const;
+protected:
+ void paintEvent(QPaintEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+public slots:
+ void updateMask();
+
+private:
+ QPixmap leftPm, centerPm, rightPm;
+};
+
+
+#endif
diff --git a/examples/widgets/mainwindows/mainwindow/main.cpp b/examples/widgets/mainwindows/mainwindow/main.cpp
new file mode 100644
index 0000000000..2b6342367a
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/main.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include <QApplication>
+#include <QPainterPath>
+#include <QPainter>
+#include <QMap>
+#include <qdebug.h>
+
+void render_qt_text(QPainter *painter, int w, int h, const QColor &color) {
+ QPainterPath path;
+ path.moveTo(-0.083695, 0.283849);
+ path.cubicTo(-0.049581, 0.349613, -0.012720, 0.397969, 0.026886, 0.428917);
+ path.cubicTo(0.066493, 0.459865, 0.111593, 0.477595, 0.162186, 0.482108);
+ path.lineTo(0.162186, 0.500000);
+ path.cubicTo(0.115929, 0.498066, 0.066565, 0.487669, 0.014094, 0.468810);
+ path.cubicTo(-0.038378, 0.449952, -0.088103, 0.423839, -0.135082, 0.390474);
+ path.cubicTo(-0.182061, 0.357108, -0.222608, 0.321567, -0.256722, 0.283849);
+ path.cubicTo(-0.304712, 0.262250, -0.342874, 0.239362, -0.371206, 0.215184);
+ path.cubicTo(-0.411969, 0.179078, -0.443625, 0.134671, -0.466175, 0.081963);
+ path.cubicTo(-0.488725, 0.029255, -0.500000, -0.033043, -0.500000, -0.104932);
+ path.cubicTo(-0.500000, -0.218407, -0.467042, -0.312621, -0.401127, -0.387573);
+ path.cubicTo(-0.335212, -0.462524, -0.255421, -0.500000, -0.161752, -0.500000);
+ path.cubicTo(-0.072998, -0.500000, 0.003903, -0.462444, 0.068951, -0.387331);
+ path.cubicTo(0.133998, -0.312218, 0.166522, -0.217440, 0.166522, -0.102998);
+ path.cubicTo(0.166522, -0.010155, 0.143394, 0.071325, 0.097138, 0.141441);
+ path.cubicTo(0.050882, 0.211557, -0.009396, 0.259026, -0.083695, 0.283849);
+ path.moveTo(-0.167823, -0.456963);
+ path.cubicTo(-0.228823, -0.456963, -0.277826, -0.432624, -0.314831, -0.383946);
+ path.cubicTo(-0.361665, -0.323340, -0.385082, -0.230335, -0.385082, -0.104932);
+ path.cubicTo(-0.385082, 0.017569, -0.361376, 0.112025, -0.313964, 0.178433);
+ path.cubicTo(-0.277248, 0.229368, -0.228534, 0.254836, -0.167823, 0.254836);
+ path.cubicTo(-0.105088, 0.254836, -0.054496, 0.229368, -0.016045, 0.178433);
+ path.cubicTo(0.029055, 0.117827, 0.051605, 0.028691, 0.051605, -0.088975);
+ path.cubicTo(0.051605, -0.179562, 0.039318, -0.255803, 0.014744, -0.317698);
+ path.cubicTo(-0.004337, -0.365409, -0.029705, -0.400548, -0.061362, -0.423114);
+ path.cubicTo(-0.093018, -0.445680, -0.128505, -0.456963, -0.167823, -0.456963);
+ path.moveTo(0.379011, -0.404739);
+ path.lineTo(0.379011, -0.236460);
+ path.lineTo(0.486123, -0.236460);
+ path.lineTo(0.486123, -0.197292);
+ path.lineTo(0.379011, -0.197292);
+ path.lineTo(0.379011, 0.134913);
+ path.cubicTo(0.379011, 0.168117, 0.383276, 0.190442, 0.391804, 0.201886);
+ path.cubicTo(0.400332, 0.213330, 0.411246, 0.219052, 0.424545, 0.219052);
+ path.cubicTo(0.435531, 0.219052, 0.446227, 0.215264, 0.456635, 0.207689);
+ path.cubicTo(0.467042, 0.200113, 0.474993, 0.188910, 0.480486, 0.174081);
+ path.lineTo(0.500000, 0.174081);
+ path.cubicTo(0.488436, 0.210509, 0.471957, 0.237911, 0.450564, 0.256286);
+ path.cubicTo(0.429170, 0.274662, 0.407054, 0.283849, 0.384215, 0.283849);
+ path.cubicTo(0.368893, 0.283849, 0.353859, 0.279094, 0.339115, 0.269584);
+ path.cubicTo(0.324371, 0.260074, 0.313530, 0.246534, 0.306592, 0.228965);
+ path.cubicTo(0.299653, 0.211396, 0.296184, 0.184075, 0.296184, 0.147002);
+ path.lineTo(0.296184, -0.197292);
+ path.lineTo(0.223330, -0.197292);
+ path.lineTo(0.223330, -0.215667);
+ path.cubicTo(0.241833, -0.224049, 0.260697, -0.237992, 0.279922, -0.257495);
+ path.cubicTo(0.299147, -0.276999, 0.316276, -0.300129, 0.331310, -0.326886);
+ path.cubicTo(0.338826, -0.341070, 0.349523, -0.367021, 0.363400, -0.404739);
+ path.lineTo(0.379011, -0.404739);
+ path.moveTo(-0.535993, 0.275629);
+
+ painter->translate(w / 2, h / 2);
+ double scale = qMin(w, h) * 8 / 10.0;
+ painter->scale(scale, scale);
+
+ painter->setRenderHint(QPainter::Antialiasing);
+
+ painter->save();
+ painter->translate(.1, .1);
+ painter->fillPath(path, QColor(0, 0, 0, 63));
+ painter->restore();
+
+ painter->setBrush(color);
+ painter->setPen(QPen(Qt::black, 0.02, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin));
+ painter->drawPath(path);
+}
+
+void usage()
+{
+ qWarning() << "Usage: mainwindow [-SizeHint<color> <width>x<height>] ...";
+ exit(1);
+}
+
+QMap<QString, QSize> parseCustomSizeHints(int argc, char **argv)
+{
+ QMap<QString, QSize> result;
+
+ for (int i = 1; i < argc; ++i) {
+ QString arg = QString::fromLocal8Bit(argv[i]);
+
+ if (arg.startsWith(QLatin1String("-SizeHint"))) {
+ QString name = arg.mid(9);
+ if (name.isEmpty())
+ usage();
+ if (++i == argc)
+ usage();
+ QString sizeStr = QString::fromLocal8Bit(argv[i]);
+ int idx = sizeStr.indexOf(QLatin1Char('x'));
+ if (idx == -1)
+ usage();
+ bool ok;
+ int w = sizeStr.left(idx).toInt(&ok);
+ if (!ok)
+ usage();
+ int h = sizeStr.mid(idx + 1).toInt(&ok);
+ if (!ok)
+ usage();
+ result[name] = QSize(w, h);
+ }
+ }
+
+ return result;
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ QMap<QString, QSize> customSizeHints = parseCustomSizeHints(argc, argv);
+ MainWindow mainWin(customSizeHints);
+ mainWin.resize(800, 600);
+ mainWin.show();
+ return app.exec();
+}
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.cpp b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
new file mode 100644
index 0000000000..2ac2b562f2
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.cpp
@@ -0,0 +1,509 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "colorswatch.h"
+#include "toolbar.h"
+
+#include <QAction>
+#include <QLayout>
+#include <QMenu>
+#include <QMenuBar>
+#include <QStatusBar>
+#include <QTextEdit>
+#include <QFile>
+#include <QDataStream>
+#include <QFileDialog>
+#include <QMessageBox>
+#include <QSignalMapper>
+#include <QApplication>
+#include <QPainter>
+#include <QMouseEvent>
+#include <QLineEdit>
+#include <QComboBox>
+#include <QLabel>
+#include <QPushButton>
+#include <qdebug.h>
+
+static const char * const message =
+ "<p><b>Qt Main Window Example</b></p>"
+
+ "<p>This is a demonstration of the QMainWindow, QToolBar and "
+ "QDockWidget classes.</p>"
+
+ "<p>The tool bar and dock widgets can be dragged around and rearranged "
+ "using the mouse or via the menu.</p>"
+
+ "<p>Each dock widget contains a colored frame and a context "
+ "(right-click) menu.</p>"
+
+#ifdef Q_OS_MAC
+ "<p>On Mac OS X, the \"Black\" dock widget has been created as a "
+ "<em>Drawer</em>, which is a special kind of QDockWidget.</p>"
+#endif
+ ;
+
+Q_DECLARE_METATYPE(QDockWidget::DockWidgetFeatures)
+
+MainWindow::MainWindow(const QMap<QString, QSize> &customSizeHints,
+ QWidget *parent, Qt::WindowFlags flags)
+ : QMainWindow(parent, flags)
+{
+ setObjectName("MainWindow");
+ setWindowTitle("Qt Main Window Example");
+
+ center = new QTextEdit(this);
+ center->setReadOnly(true);
+ center->setMinimumSize(400, 205);
+ setCentralWidget(center);
+
+ setupToolBar();
+ setupMenuBar();
+ setupDockWidgets(customSizeHints);
+
+ statusBar()->showMessage(tr("Status Bar"));
+}
+
+void MainWindow::actionTriggered(QAction *action)
+{
+ qDebug("action '%s' triggered", action->text().toLocal8Bit().data());
+}
+
+void MainWindow::setupToolBar()
+{
+ for (int i = 0; i < 3; ++i) {
+ ToolBar *tb = new ToolBar(QString::fromLatin1("Tool Bar %1").arg(i + 1), this);
+ toolBars.append(tb);
+ addToolBar(tb);
+ }
+}
+
+void MainWindow::setupMenuBar()
+{
+ QMenu *menu = menuBar()->addMenu(tr("&File"));
+
+ QAction *action = menu->addAction(tr("Save layout..."));
+ connect(action, SIGNAL(triggered()), this, SLOT(saveLayout()));
+
+ action = menu->addAction(tr("Load layout..."));
+ connect(action, SIGNAL(triggered()), this, SLOT(loadLayout()));
+
+ action = menu->addAction(tr("Switch layout direction"));
+ connect(action, SIGNAL(triggered()), this, SLOT(switchLayoutDirection()));
+
+ menu->addSeparator();
+
+ menu->addAction(tr("&Quit"), this, SLOT(close()));
+
+ mainWindowMenu = menuBar()->addMenu(tr("Main window"));
+
+ action = mainWindowMenu->addAction(tr("Animated docks"));
+ action->setCheckable(true);
+ action->setChecked(dockOptions() & AnimatedDocks);
+ connect(action, SIGNAL(toggled(bool)), this, SLOT(setDockOptions()));
+
+ action = mainWindowMenu->addAction(tr("Allow nested docks"));
+ action->setCheckable(true);
+ action->setChecked(dockOptions() & AllowNestedDocks);
+ connect(action, SIGNAL(toggled(bool)), this, SLOT(setDockOptions()));
+
+ action = mainWindowMenu->addAction(tr("Allow tabbed docks"));
+ action->setCheckable(true);
+ action->setChecked(dockOptions() & AllowTabbedDocks);
+ connect(action, SIGNAL(toggled(bool)), this, SLOT(setDockOptions()));
+
+ action = mainWindowMenu->addAction(tr("Force tabbed docks"));
+ action->setCheckable(true);
+ action->setChecked(dockOptions() & ForceTabbedDocks);
+ connect(action, SIGNAL(toggled(bool)), this, SLOT(setDockOptions()));
+
+ action = mainWindowMenu->addAction(tr("Vertical tabs"));
+ action->setCheckable(true);
+ action->setChecked(dockOptions() & VerticalTabs);
+ connect(action, SIGNAL(toggled(bool)), this, SLOT(setDockOptions()));
+
+ QMenu *toolBarMenu = menuBar()->addMenu(tr("Tool bars"));
+ for (int i = 0; i < toolBars.count(); ++i)
+ toolBarMenu->addMenu(toolBars.at(i)->menu);
+
+ dockWidgetMenu = menuBar()->addMenu(tr("&Dock Widgets"));
+}
+
+void MainWindow::setDockOptions()
+{
+ DockOptions opts;
+ QList<QAction*> actions = mainWindowMenu->actions();
+
+ if (actions.at(0)->isChecked())
+ opts |= AnimatedDocks;
+ if (actions.at(1)->isChecked())
+ opts |= AllowNestedDocks;
+ if (actions.at(2)->isChecked())
+ opts |= AllowTabbedDocks;
+ if (actions.at(3)->isChecked())
+ opts |= ForceTabbedDocks;
+ if (actions.at(4)->isChecked())
+ opts |= VerticalTabs;
+
+ QMainWindow::setDockOptions(opts);
+}
+
+void MainWindow::saveLayout()
+{
+ QString fileName
+ = QFileDialog::getSaveFileName(this, tr("Save layout"));
+ if (fileName.isEmpty())
+ return;
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly)) {
+ QString msg = tr("Failed to open %1\n%2")
+ .arg(fileName)
+ .arg(file.errorString());
+ QMessageBox::warning(this, tr("Error"), msg);
+ return;
+ }
+
+ QByteArray geo_data = saveGeometry();
+ QByteArray layout_data = saveState();
+
+ bool ok = file.putChar((uchar)geo_data.size());
+ if (ok)
+ ok = file.write(geo_data) == geo_data.size();
+ if (ok)
+ ok = file.write(layout_data) == layout_data.size();
+
+ if (!ok) {
+ QString msg = tr("Error writing to %1\n%2")
+ .arg(fileName)
+ .arg(file.errorString());
+ QMessageBox::warning(this, tr("Error"), msg);
+ return;
+ }
+}
+
+void MainWindow::loadLayout()
+{
+ QString fileName
+ = QFileDialog::getOpenFileName(this, tr("Load layout"));
+ if (fileName.isEmpty())
+ return;
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly)) {
+ QString msg = tr("Failed to open %1\n%2")
+ .arg(fileName)
+ .arg(file.errorString());
+ QMessageBox::warning(this, tr("Error"), msg);
+ return;
+ }
+
+ uchar geo_size;
+ QByteArray geo_data;
+ QByteArray layout_data;
+
+ bool ok = file.getChar((char*)&geo_size);
+ if (ok) {
+ geo_data = file.read(geo_size);
+ ok = geo_data.size() == geo_size;
+ }
+ if (ok) {
+ layout_data = file.readAll();
+ ok = layout_data.size() > 0;
+ }
+
+ if (ok)
+ ok = restoreGeometry(geo_data);
+ if (ok)
+ ok = restoreState(layout_data);
+
+ if (!ok) {
+ QString msg = tr("Error reading %1")
+ .arg(fileName);
+ QMessageBox::warning(this, tr("Error"), msg);
+ return;
+ }
+}
+
+QAction *addAction(QMenu *menu, const QString &text, QActionGroup *group, QSignalMapper *mapper,
+ int id)
+{
+ bool first = group->actions().isEmpty();
+ QAction *result = menu->addAction(text);
+ result->setCheckable(true);
+ result->setChecked(first);
+ group->addAction(result);
+ QObject::connect(result, SIGNAL(triggered()), mapper, SLOT(map()));
+ mapper->setMapping(result, id);
+ return result;
+}
+
+void MainWindow::setupDockWidgets(const QMap<QString, QSize> &customSizeHints)
+{
+ qRegisterMetaType<QDockWidget::DockWidgetFeatures>();
+
+ mapper = new QSignalMapper(this);
+ connect(mapper, SIGNAL(mapped(int)), this, SLOT(setCorner(int)));
+
+ QMenu *corner_menu = dockWidgetMenu->addMenu(tr("Top left corner"));
+ QActionGroup *group = new QActionGroup(this);
+ group->setExclusive(true);
+ ::addAction(corner_menu, tr("Top dock area"), group, mapper, 0);
+ ::addAction(corner_menu, tr("Left dock area"), group, mapper, 1);
+
+ corner_menu = dockWidgetMenu->addMenu(tr("Top right corner"));
+ group = new QActionGroup(this);
+ group->setExclusive(true);
+ ::addAction(corner_menu, tr("Top dock area"), group, mapper, 2);
+ ::addAction(corner_menu, tr("Right dock area"), group, mapper, 3);
+
+ corner_menu = dockWidgetMenu->addMenu(tr("Bottom left corner"));
+ group = new QActionGroup(this);
+ group->setExclusive(true);
+ ::addAction(corner_menu, tr("Bottom dock area"), group, mapper, 4);
+ ::addAction(corner_menu, tr("Left dock area"), group, mapper, 5);
+
+ corner_menu = dockWidgetMenu->addMenu(tr("Bottom right corner"));
+ group = new QActionGroup(this);
+ group->setExclusive(true);
+ ::addAction(corner_menu, tr("Bottom dock area"), group, mapper, 6);
+ ::addAction(corner_menu, tr("Right dock area"), group, mapper, 7);
+
+ dockWidgetMenu->addSeparator();
+
+ static const struct Set {
+ const char * name;
+ uint flags;
+ Qt::DockWidgetArea area;
+ } sets [] = {
+#ifndef Q_OS_MAC
+ { "Black", 0, Qt::LeftDockWidgetArea },
+#else
+ { "Black", Qt::Drawer, Qt::LeftDockWidgetArea },
+#endif
+ { "White", 0, Qt::RightDockWidgetArea },
+ { "Red", 0, Qt::TopDockWidgetArea },
+ { "Green", 0, Qt::TopDockWidgetArea },
+ { "Blue", 0, Qt::BottomDockWidgetArea },
+ { "Yellow", 0, Qt::BottomDockWidgetArea }
+ };
+ const int setCount = sizeof(sets) / sizeof(Set);
+
+ for (int i = 0; i < setCount; ++i) {
+ ColorSwatch *swatch = new ColorSwatch(tr(sets[i].name), this, Qt::WindowFlags(sets[i].flags));
+ if (i%2)
+ swatch->setWindowIcon(QIcon(QPixmap(":/res/qt.png")));
+ if (qstrcmp(sets[i].name, "Blue") == 0) {
+ BlueTitleBar *titlebar = new BlueTitleBar(swatch);
+ swatch->setTitleBarWidget(titlebar);
+ connect(swatch, SIGNAL(topLevelChanged(bool)), titlebar, SLOT(updateMask()));
+ connect(swatch, SIGNAL(featuresChanged(QDockWidget::DockWidgetFeatures)), titlebar, SLOT(updateMask()), Qt::QueuedConnection);
+
+ }
+
+ QString name = QString::fromLatin1(sets[i].name);
+ if (customSizeHints.contains(name))
+ swatch->setCustomSizeHint(customSizeHints.value(name));
+
+ addDockWidget(sets[i].area, swatch);
+ dockWidgetMenu->addMenu(swatch->menu);
+ }
+
+ createDockWidgetAction = new QAction(tr("Add dock widget..."), this);
+ connect(createDockWidgetAction, SIGNAL(triggered()), this, SLOT(createDockWidget()));
+ destroyDockWidgetMenu = new QMenu(tr("Destroy dock widget"), this);
+ destroyDockWidgetMenu->setEnabled(false);
+ connect(destroyDockWidgetMenu, SIGNAL(triggered(QAction*)), this, SLOT(destroyDockWidget(QAction*)));
+
+ dockWidgetMenu->addSeparator();
+ dockWidgetMenu->addAction(createDockWidgetAction);
+ dockWidgetMenu->addMenu(destroyDockWidgetMenu);
+}
+
+void MainWindow::setCorner(int id)
+{
+ switch (id) {
+ case 0:
+ QMainWindow::setCorner(Qt::TopLeftCorner, Qt::TopDockWidgetArea);
+ break;
+ case 1:
+ QMainWindow::setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
+ break;
+ case 2:
+ QMainWindow::setCorner(Qt::TopRightCorner, Qt::TopDockWidgetArea);
+ break;
+ case 3:
+ QMainWindow::setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
+ break;
+ case 4:
+ QMainWindow::setCorner(Qt::BottomLeftCorner, Qt::BottomDockWidgetArea);
+ break;
+ case 5:
+ QMainWindow::setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
+ break;
+ case 6:
+ QMainWindow::setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
+ break;
+ case 7:
+ QMainWindow::setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
+ break;
+ }
+}
+
+void MainWindow::showEvent(QShowEvent *event)
+{
+ QMainWindow::showEvent(event);
+}
+
+void MainWindow::switchLayoutDirection()
+{
+ if (layoutDirection() == Qt::LeftToRight)
+ qApp->setLayoutDirection(Qt::RightToLeft);
+ else
+ qApp->setLayoutDirection(Qt::LeftToRight);
+}
+
+class CreateDockWidgetDialog : public QDialog
+{
+public:
+ CreateDockWidgetDialog(QWidget *parent = 0);
+
+ QString objectName() const;
+ Qt::DockWidgetArea location() const;
+
+private:
+ QLineEdit *m_objectName;
+ QComboBox *m_location;
+};
+
+CreateDockWidgetDialog::CreateDockWidgetDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ QGridLayout *layout = new QGridLayout(this);
+
+ layout->addWidget(new QLabel(tr("Object name:")), 0, 0);
+ m_objectName = new QLineEdit;
+ layout->addWidget(m_objectName, 0, 1);
+
+ layout->addWidget(new QLabel(tr("Location:")), 1, 0);
+ m_location = new QComboBox;
+ m_location->setEditable(false);
+ m_location->addItem(tr("Top"));
+ m_location->addItem(tr("Left"));
+ m_location->addItem(tr("Right"));
+ m_location->addItem(tr("Bottom"));
+ m_location->addItem(tr("Restore"));
+ layout->addWidget(m_location, 1, 1);
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ layout->addLayout(buttonLayout, 2, 0, 1, 2);
+ buttonLayout->addStretch();
+
+ QPushButton *cancelButton = new QPushButton(tr("Cancel"));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
+ buttonLayout->addWidget(cancelButton);
+ QPushButton *okButton = new QPushButton(tr("Ok"));
+ connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
+ buttonLayout->addWidget(okButton);
+
+ okButton->setDefault(true);
+}
+
+QString CreateDockWidgetDialog::objectName() const
+{
+ return m_objectName->text();
+}
+
+Qt::DockWidgetArea CreateDockWidgetDialog::location() const
+{
+ switch (m_location->currentIndex()) {
+ case 0: return Qt::TopDockWidgetArea;
+ case 1: return Qt::LeftDockWidgetArea;
+ case 2: return Qt::RightDockWidgetArea;
+ case 3: return Qt::BottomDockWidgetArea;
+ default:
+ break;
+ }
+ return Qt::NoDockWidgetArea;
+}
+
+void MainWindow::createDockWidget()
+{
+ CreateDockWidgetDialog dialog(this);
+ int ret = dialog.exec();
+ if (ret == QDialog::Rejected)
+ return;
+
+ QDockWidget *dw = new QDockWidget;
+ dw->setObjectName(dialog.objectName());
+ dw->setWindowTitle(dialog.objectName());
+ dw->setWidget(new QTextEdit);
+
+ Qt::DockWidgetArea area = dialog.location();
+ switch (area) {
+ case Qt::LeftDockWidgetArea:
+ case Qt::RightDockWidgetArea:
+ case Qt::TopDockWidgetArea:
+ case Qt::BottomDockWidgetArea:
+ addDockWidget(area, dw);
+ break;
+ default:
+ if (!restoreDockWidget(dw)) {
+ QMessageBox::warning(this, QString(), tr("Failed to restore dock widget"));
+ delete dw;
+ return;
+ }
+ break;
+ }
+
+ extraDockWidgets.append(dw);
+ destroyDockWidgetMenu->setEnabled(true);
+ destroyDockWidgetMenu->addAction(new QAction(dialog.objectName(), this));
+}
+
+void MainWindow::destroyDockWidget(QAction *action)
+{
+ int index = destroyDockWidgetMenu->actions().indexOf(action);
+ delete extraDockWidgets.takeAt(index);
+ destroyDockWidgetMenu->removeAction(action);
+ action->deleteLater();
+
+ if (destroyDockWidgetMenu->isEmpty())
+ destroyDockWidgetMenu->setEnabled(false);
+}
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.h b/examples/widgets/mainwindows/mainwindow/mainwindow.h
new file mode 100644
index 0000000000..51969acaa3
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QTextEdit>
+
+class ToolBar;
+QT_FORWARD_DECLARE_CLASS(QMenu)
+QT_FORWARD_DECLARE_CLASS(QSignalMapper)
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+ QTextEdit *center;
+ QList<ToolBar*> toolBars;
+ QMenu *dockWidgetMenu;
+ QMenu *mainWindowMenu;
+ QSignalMapper *mapper;
+ QList<QDockWidget*> extraDockWidgets;
+ QAction *createDockWidgetAction;
+ QMenu *destroyDockWidgetMenu;
+
+public:
+ MainWindow(const QMap<QString, QSize> &customSizeHints,
+ QWidget *parent = 0, Qt::WindowFlags flags = 0);
+
+protected:
+ void showEvent(QShowEvent *event);
+
+public slots:
+ void actionTriggered(QAction *action);
+ void saveLayout();
+ void loadLayout();
+ void setCorner(int id);
+ void switchLayoutDirection();
+ void setDockOptions();
+
+ void createDockWidget();
+ void destroyDockWidget(QAction *action);
+
+private:
+ void setupToolBar();
+ void setupMenuBar();
+ void setupDockWidgets(const QMap<QString, QSize> &customSizeHints);
+};
+
+
+#endif
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.pro b/examples/widgets/mainwindows/mainwindow/mainwindow.pro
new file mode 100644
index 0000000000..1381c460c2
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.pro
@@ -0,0 +1,17 @@
+TEMPLATE = app
+HEADERS += colorswatch.h mainwindow.h toolbar.h
+SOURCES += colorswatch.cpp mainwindow.cpp toolbar.cpp main.cpp
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+
+RESOURCES += mainwindow.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/mainwindow
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.png *.jpg *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/mainwindow
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.qrc b/examples/widgets/mainwindows/mainwindow/mainwindow.qrc
new file mode 100644
index 0000000000..47ff22a3e4
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/mainwindow.qrc
@@ -0,0 +1,8 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res">
+ <file>qt.png</file>
+ <file>titlebarLeft.png</file>
+ <file>titlebarCenter.png</file>
+ <file>titlebarRight.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/mainwindows/mainwindow/qt.png b/examples/widgets/mainwindows/mainwindow/qt.png
new file mode 100644
index 0000000000..48fa9fc2ef
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/qt.png
Binary files differ
diff --git a/examples/widgets/mainwindows/mainwindow/titlebarCenter.png b/examples/widgets/mainwindows/mainwindow/titlebarCenter.png
new file mode 100644
index 0000000000..5cc141355c
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/titlebarCenter.png
Binary files differ
diff --git a/examples/widgets/mainwindows/mainwindow/titlebarLeft.png b/examples/widgets/mainwindows/mainwindow/titlebarLeft.png
new file mode 100644
index 0000000000..315166202b
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/titlebarLeft.png
Binary files differ
diff --git a/examples/widgets/mainwindows/mainwindow/titlebarRight.png b/examples/widgets/mainwindows/mainwindow/titlebarRight.png
new file mode 100644
index 0000000000..a4505268ec
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/titlebarRight.png
Binary files differ
diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.cpp b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
new file mode 100644
index 0000000000..d10eccb46d
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
@@ -0,0 +1,383 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "toolbar.h"
+
+#include <QMainWindow>
+#include <QMenu>
+#include <QPainter>
+#include <QPainterPath>
+#include <QSpinBox>
+#include <QLabel>
+#include <QToolTip>
+
+#include <stdlib.h>
+
+static QPixmap genIcon(const QSize &iconSize, const QString &, const QColor &color)
+{
+ int w = iconSize.width();
+ int h = iconSize.height();
+
+ QImage image(w, h, QImage::Format_ARGB32_Premultiplied);
+ image.fill(0);
+
+ QPainter p(&image);
+
+ extern void render_qt_text(QPainter *, int, int, const QColor &);
+ render_qt_text(&p, w, h, color);
+
+ return QPixmap::fromImage(image, Qt::DiffuseDither | Qt::DiffuseAlphaDither);
+}
+
+static QPixmap genIcon(const QSize &iconSize, int number, const QColor &color)
+{ return genIcon(iconSize, QString::number(number), color); }
+
+ToolBar::ToolBar(const QString &title, QWidget *parent)
+ : QToolBar(parent), spinbox(0), spinboxAction(0)
+{
+ tip = 0;
+ setWindowTitle(title);
+ setObjectName(title);
+
+ setIconSize(QSize(32, 32));
+
+ QColor bg(palette().background().color());
+ menu = new QMenu("One", this);
+ menu->setIcon(genIcon(iconSize(), 1, Qt::black));
+ menu->addAction(genIcon(iconSize(), "A", Qt::blue), "A");
+ menu->addAction(genIcon(iconSize(), "B", Qt::blue), "B");
+ menu->addAction(genIcon(iconSize(), "C", Qt::blue), "C");
+ addAction(menu->menuAction());
+
+ QAction *two = addAction(genIcon(iconSize(), 2, Qt::white), "Two");
+ QFont boldFont;
+ boldFont.setBold(true);
+ two->setFont(boldFont);
+
+ addAction(genIcon(iconSize(), 3, Qt::red), "Three");
+ addAction(genIcon(iconSize(), 4, Qt::green), "Four");
+ addAction(genIcon(iconSize(), 5, Qt::blue), "Five");
+ addAction(genIcon(iconSize(), 6, Qt::yellow), "Six");
+ orderAction = new QAction(this);
+ orderAction->setText(tr("Order Items in Tool Bar"));
+ connect(orderAction, SIGNAL(triggered()), SLOT(order()));
+
+ randomizeAction = new QAction(this);
+ randomizeAction->setText(tr("Randomize Items in Tool Bar"));
+ connect(randomizeAction, SIGNAL(triggered()), SLOT(randomize()));
+
+ addSpinBoxAction = new QAction(this);
+ addSpinBoxAction->setText(tr("Add Spin Box"));
+ connect(addSpinBoxAction, SIGNAL(triggered()), SLOT(addSpinBox()));
+
+ removeSpinBoxAction = new QAction(this);
+ removeSpinBoxAction->setText(tr("Remove Spin Box"));
+ removeSpinBoxAction->setEnabled(false);
+ connect(removeSpinBoxAction, SIGNAL(triggered()), SLOT(removeSpinBox()));
+
+ movableAction = new QAction(tr("Movable"), this);
+ movableAction->setCheckable(true);
+ connect(movableAction, SIGNAL(triggered(bool)), SLOT(changeMovable(bool)));
+
+ allowedAreasActions = new QActionGroup(this);
+ allowedAreasActions->setExclusive(false);
+
+ allowLeftAction = new QAction(tr("Allow on Left"), this);
+ allowLeftAction->setCheckable(true);
+ connect(allowLeftAction, SIGNAL(triggered(bool)), SLOT(allowLeft(bool)));
+
+ allowRightAction = new QAction(tr("Allow on Right"), this);
+ allowRightAction->setCheckable(true);
+ connect(allowRightAction, SIGNAL(triggered(bool)), SLOT(allowRight(bool)));
+
+ allowTopAction = new QAction(tr("Allow on Top"), this);
+ allowTopAction->setCheckable(true);
+ connect(allowTopAction, SIGNAL(triggered(bool)), SLOT(allowTop(bool)));
+
+ allowBottomAction = new QAction(tr("Allow on Bottom"), this);
+ allowBottomAction->setCheckable(true);
+ connect(allowBottomAction, SIGNAL(triggered(bool)), SLOT(allowBottom(bool)));
+
+ allowedAreasActions->addAction(allowLeftAction);
+ allowedAreasActions->addAction(allowRightAction);
+ allowedAreasActions->addAction(allowTopAction);
+ allowedAreasActions->addAction(allowBottomAction);
+
+ areaActions = new QActionGroup(this);
+ areaActions->setExclusive(true);
+
+ leftAction = new QAction(tr("Place on Left") , this);
+ leftAction->setCheckable(true);
+ connect(leftAction, SIGNAL(triggered(bool)), SLOT(placeLeft(bool)));
+
+ rightAction = new QAction(tr("Place on Right") , this);
+ rightAction->setCheckable(true);
+ connect(rightAction, SIGNAL(triggered(bool)), SLOT(placeRight(bool)));
+
+ topAction = new QAction(tr("Place on Top") , this);
+ topAction->setCheckable(true);
+ connect(topAction, SIGNAL(triggered(bool)), SLOT(placeTop(bool)));
+
+ bottomAction = new QAction(tr("Place on Bottom") , this);
+ bottomAction->setCheckable(true);
+ connect(bottomAction, SIGNAL(triggered(bool)), SLOT(placeBottom(bool)));
+
+ areaActions->addAction(leftAction);
+ areaActions->addAction(rightAction);
+ areaActions->addAction(topAction);
+ areaActions->addAction(bottomAction);
+
+ toolBarBreakAction = new QAction(tr("Insert break"), this);
+ connect(toolBarBreakAction, SIGNAL(triggered(bool)), this, SLOT(insertToolBarBreak()));
+
+ connect(movableAction, SIGNAL(triggered(bool)), areaActions, SLOT(setEnabled(bool)));
+
+ connect(movableAction, SIGNAL(triggered(bool)), allowedAreasActions, SLOT(setEnabled(bool)));
+
+ menu = new QMenu(title, this);
+ menu->addAction(toggleViewAction());
+ menu->addSeparator();
+ menu->addAction(orderAction);
+ menu->addAction(randomizeAction);
+ menu->addSeparator();
+ menu->addAction(addSpinBoxAction);
+ menu->addAction(removeSpinBoxAction);
+ menu->addSeparator();
+ menu->addAction(movableAction);
+ menu->addSeparator();
+ menu->addActions(allowedAreasActions->actions());
+ menu->addSeparator();
+ menu->addActions(areaActions->actions());
+ menu->addSeparator();
+ menu->addAction(toolBarBreakAction);
+
+ connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateMenu()));
+
+ randomize();
+}
+
+void ToolBar::updateMenu()
+{
+ QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
+ Q_ASSERT(mainWindow != 0);
+
+ const Qt::ToolBarArea area = mainWindow->toolBarArea(this);
+ const Qt::ToolBarAreas areas = allowedAreas();
+
+ movableAction->setChecked(isMovable());
+
+ allowLeftAction->setChecked(isAreaAllowed(Qt::LeftToolBarArea));
+ allowRightAction->setChecked(isAreaAllowed(Qt::RightToolBarArea));
+ allowTopAction->setChecked(isAreaAllowed(Qt::TopToolBarArea));
+ allowBottomAction->setChecked(isAreaAllowed(Qt::BottomToolBarArea));
+
+ if (allowedAreasActions->isEnabled()) {
+ allowLeftAction->setEnabled(area != Qt::LeftToolBarArea);
+ allowRightAction->setEnabled(area != Qt::RightToolBarArea);
+ allowTopAction->setEnabled(area != Qt::TopToolBarArea);
+ allowBottomAction->setEnabled(area != Qt::BottomToolBarArea);
+ }
+
+ leftAction->setChecked(area == Qt::LeftToolBarArea);
+ rightAction->setChecked(area == Qt::RightToolBarArea);
+ topAction->setChecked(area == Qt::TopToolBarArea);
+ bottomAction->setChecked(area == Qt::BottomToolBarArea);
+
+ if (areaActions->isEnabled()) {
+ leftAction->setEnabled(areas & Qt::LeftToolBarArea);
+ rightAction->setEnabled(areas & Qt::RightToolBarArea);
+ topAction->setEnabled(areas & Qt::TopToolBarArea);
+ bottomAction->setEnabled(areas & Qt::BottomToolBarArea);
+ }
+}
+
+void ToolBar::order()
+{
+ QList<QAction *> ordered, actions1 = actions(),
+ actions2 = findChildren<QAction *>();
+ while (!actions2.isEmpty()) {
+ QAction *action = actions2.takeFirst();
+ if (!actions1.contains(action))
+ continue;
+ actions1.removeAll(action);
+ ordered.append(action);
+ }
+
+ clear();
+ addActions(ordered);
+
+ orderAction->setEnabled(false);
+}
+
+void ToolBar::randomize()
+{
+ QList<QAction *> randomized, actions = this->actions();
+ while (!actions.isEmpty()) {
+ QAction *action = actions.takeAt(rand() % actions.size());
+ randomized.append(action);
+ }
+ clear();
+ addActions(randomized);
+
+ orderAction->setEnabled(true);
+}
+
+void ToolBar::addSpinBox()
+{
+ if (!spinbox) {
+ spinbox = new QSpinBox(this);
+ }
+ if (!spinboxAction)
+ spinboxAction = addWidget(spinbox);
+ else
+ addAction(spinboxAction);
+
+ addSpinBoxAction->setEnabled(false);
+ removeSpinBoxAction->setEnabled(true);
+}
+
+void ToolBar::removeSpinBox()
+{
+ if (spinboxAction)
+ removeAction(spinboxAction);
+
+ addSpinBoxAction->setEnabled(true);
+ removeSpinBoxAction->setEnabled(false);
+}
+
+void ToolBar::allow(Qt::ToolBarArea area, bool a)
+{
+ Qt::ToolBarAreas areas = allowedAreas();
+ areas = a ? areas | area : areas & ~area;
+ setAllowedAreas(areas);
+
+ if (areaActions->isEnabled()) {
+ leftAction->setEnabled(areas & Qt::LeftToolBarArea);
+ rightAction->setEnabled(areas & Qt::RightToolBarArea);
+ topAction->setEnabled(areas & Qt::TopToolBarArea);
+ bottomAction->setEnabled(areas & Qt::BottomToolBarArea);
+ }
+}
+
+void ToolBar::place(Qt::ToolBarArea area, bool p)
+{
+ if (!p)
+ return;
+
+ QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
+ Q_ASSERT(mainWindow != 0);
+
+ mainWindow->addToolBar(area, this);
+
+ if (allowedAreasActions->isEnabled()) {
+ allowLeftAction->setEnabled(area != Qt::LeftToolBarArea);
+ allowRightAction->setEnabled(area != Qt::RightToolBarArea);
+ allowTopAction->setEnabled(area != Qt::TopToolBarArea);
+ allowBottomAction->setEnabled(area != Qt::BottomToolBarArea);
+ }
+}
+
+void ToolBar::changeMovable(bool movable)
+{ setMovable(movable); }
+
+void ToolBar::allowLeft(bool a)
+{ allow(Qt::LeftToolBarArea, a); }
+
+void ToolBar::allowRight(bool a)
+{ allow(Qt::RightToolBarArea, a); }
+
+void ToolBar::allowTop(bool a)
+{ allow(Qt::TopToolBarArea, a); }
+
+void ToolBar::allowBottom(bool a)
+{ allow(Qt::BottomToolBarArea, a); }
+
+void ToolBar::placeLeft(bool p)
+{ place(Qt::LeftToolBarArea, p); }
+
+void ToolBar::placeRight(bool p)
+{ place(Qt::RightToolBarArea, p); }
+
+void ToolBar::placeTop(bool p)
+{ place(Qt::TopToolBarArea, p); }
+
+void ToolBar::placeBottom(bool p)
+{ place(Qt::BottomToolBarArea, p); }
+
+void ToolBar::insertToolBarBreak()
+{
+ QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget());
+ Q_ASSERT(mainWindow != 0);
+
+ mainWindow->insertToolBarBreak(this);
+}
+
+void ToolBar::enterEvent(QEvent*)
+{
+/*
+ These labels on top of toolbars look darn ugly
+
+ if (tip == 0) {
+ tip = new QLabel(windowTitle(), this);
+ QPalette pal = tip->palette();
+ QColor c = Qt::black;
+ c.setAlpha(100);
+ pal.setColor(QPalette::Window, c);
+ pal.setColor(QPalette::Foreground, Qt::white);
+ tip->setPalette(pal);
+ tip->setAutoFillBackground(true);
+ tip->setMargin(3);
+ tip->setText(windowTitle());
+ }
+ QPoint c = rect().center();
+ QSize hint = tip->sizeHint();
+ tip->setGeometry(c.x() - hint.width()/2, c.y() - hint.height()/2,
+ hint.width(), hint.height());
+
+ tip->show();
+*/
+}
+
+void ToolBar::leaveEvent(QEvent*)
+{
+ if (tip != 0)
+ tip->hide();
+}
diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.h b/examples/widgets/mainwindows/mainwindow/toolbar.h
new file mode 100644
index 0000000000..0ffb1eea5d
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindow/toolbar.h
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TOOLBAR_H
+#define TOOLBAR_H
+
+#include <QToolBar>
+
+QT_FORWARD_DECLARE_CLASS(QAction)
+QT_FORWARD_DECLARE_CLASS(QActionGroup)
+QT_FORWARD_DECLARE_CLASS(QMenu)
+QT_FORWARD_DECLARE_CLASS(QSpinBox)
+QT_FORWARD_DECLARE_CLASS(QLabel)
+
+class ToolBar : public QToolBar
+{
+ Q_OBJECT
+
+ QSpinBox *spinbox;
+ QAction *spinboxAction;
+
+ QAction *orderAction;
+ QAction *randomizeAction;
+ QAction *addSpinBoxAction;
+ QAction *removeSpinBoxAction;
+
+ QAction *movableAction;
+
+ QActionGroup *allowedAreasActions;
+ QAction *allowLeftAction;
+ QAction *allowRightAction;
+ QAction *allowTopAction;
+ QAction *allowBottomAction;
+
+ QActionGroup *areaActions;
+ QAction *leftAction;
+ QAction *rightAction;
+ QAction *topAction;
+ QAction *bottomAction;
+
+ QAction *toolBarBreakAction;
+
+public:
+ ToolBar(const QString &title, QWidget *parent);
+
+ QMenu *menu;
+
+protected:
+ void enterEvent(QEvent*);
+ void leaveEvent(QEvent*);
+
+private:
+ void allow(Qt::ToolBarArea area, bool allow);
+ void place(Qt::ToolBarArea area, bool place);
+ QLabel *tip;
+
+private slots:
+ void order();
+ void randomize();
+ void addSpinBox();
+ void removeSpinBox();
+
+ void changeMovable(bool movable);
+
+ void allowLeft(bool a);
+ void allowRight(bool a);
+ void allowTop(bool a);
+ void allowBottom(bool a);
+
+ void placeLeft(bool p);
+ void placeRight(bool p);
+ void placeTop(bool p);
+ void placeBottom(bool p);
+
+ void updateMenu();
+ void insertToolBarBreak();
+
+};
+
+#endif
diff --git a/examples/widgets/mainwindows/mainwindows.pro b/examples/widgets/mainwindows/mainwindows.pro
new file mode 100644
index 0000000000..c30d29e95a
--- /dev/null
+++ b/examples/widgets/mainwindows/mainwindows.pro
@@ -0,0 +1,16 @@
+TEMPLATE = subdirs
+SUBDIRS = application \
+ dockwidgets \
+ mainwindow \
+ mdi \
+ menus \
+ recentfiles \
+ sdi
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS mainwindows.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/mainwindows/mdi/images/copy.png b/examples/widgets/mainwindows/mdi/images/copy.png
new file mode 100644
index 0000000000..2aeb28288f
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/images/copy.png
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/images/cut.png b/examples/widgets/mainwindows/mdi/images/cut.png
new file mode 100644
index 0000000000..54638e9386
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/images/cut.png
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/images/new.png b/examples/widgets/mainwindows/mdi/images/new.png
new file mode 100644
index 0000000000..12131b0100
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/images/new.png
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/images/open.png b/examples/widgets/mainwindows/mdi/images/open.png
new file mode 100644
index 0000000000..45fa2883a7
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/images/open.png
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/images/paste.png b/examples/widgets/mainwindows/mdi/images/paste.png
new file mode 100644
index 0000000000..c14425cad1
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/images/paste.png
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/images/save.png b/examples/widgets/mainwindows/mdi/images/save.png
new file mode 100644
index 0000000000..daba865faf
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/images/save.png
Binary files differ
diff --git a/examples/widgets/mainwindows/mdi/main.cpp b/examples/widgets/mainwindows/mdi/main.cpp
new file mode 100644
index 0000000000..8beec478a4
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(mdi);
+
+ QApplication app(argc, argv);
+ MainWindow mainWin;
+ mainWin.show();
+ return app.exec();
+}
diff --git a/examples/widgets/mainwindows/mdi/mainwindow.cpp b/examples/widgets/mainwindows/mdi/mainwindow.cpp
new file mode 100644
index 0000000000..6ba15aa224
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/mainwindow.cpp
@@ -0,0 +1,411 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+#include "mdichild.h"
+
+MainWindow::MainWindow()
+{
+ mdiArea = new QMdiArea;
+ mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ setCentralWidget(mdiArea);
+ connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),
+ this, SLOT(updateMenus()));
+ windowMapper = new QSignalMapper(this);
+ connect(windowMapper, SIGNAL(mapped(QWidget*)),
+ this, SLOT(setActiveSubWindow(QWidget*)));
+
+ createActions();
+ createMenus();
+ createToolBars();
+ createStatusBar();
+ updateMenus();
+
+ readSettings();
+
+ setWindowTitle(tr("MDI"));
+ setUnifiedTitleAndToolBarOnMac(true);
+}
+
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ mdiArea->closeAllSubWindows();
+ if (mdiArea->currentSubWindow()) {
+ event->ignore();
+ } else {
+ writeSettings();
+ event->accept();
+ }
+}
+
+void MainWindow::newFile()
+{
+ MdiChild *child = createMdiChild();
+ child->newFile();
+ child->show();
+}
+
+void MainWindow::open()
+{
+ QString fileName = QFileDialog::getOpenFileName(this);
+ if (!fileName.isEmpty()) {
+ QMdiSubWindow *existing = findMdiChild(fileName);
+ if (existing) {
+ mdiArea->setActiveSubWindow(existing);
+ return;
+ }
+
+ MdiChild *child = createMdiChild();
+ if (child->loadFile(fileName)) {
+ statusBar()->showMessage(tr("File loaded"), 2000);
+ child->show();
+ } else {
+ child->close();
+ }
+ }
+}
+
+void MainWindow::save()
+{
+ if (activeMdiChild() && activeMdiChild()->save())
+ statusBar()->showMessage(tr("File saved"), 2000);
+}
+
+void MainWindow::saveAs()
+{
+ if (activeMdiChild() && activeMdiChild()->saveAs())
+ statusBar()->showMessage(tr("File saved"), 2000);
+}
+
+#ifndef QT_NO_CLIPBOARD
+void MainWindow::cut()
+{
+ if (activeMdiChild())
+ activeMdiChild()->cut();
+}
+
+void MainWindow::copy()
+{
+ if (activeMdiChild())
+ activeMdiChild()->copy();
+}
+
+void MainWindow::paste()
+{
+ if (activeMdiChild())
+ activeMdiChild()->paste();
+}
+#endif
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About MDI"),
+ tr("The <b>MDI</b> example demonstrates how to write multiple "
+ "document interface applications using Qt."));
+}
+
+void MainWindow::updateMenus()
+{
+ bool hasMdiChild = (activeMdiChild() != 0);
+ saveAct->setEnabled(hasMdiChild);
+ saveAsAct->setEnabled(hasMdiChild);
+#ifndef QT_NO_CLIPBOARD
+ pasteAct->setEnabled(hasMdiChild);
+#endif
+ closeAct->setEnabled(hasMdiChild);
+ closeAllAct->setEnabled(hasMdiChild);
+ tileAct->setEnabled(hasMdiChild);
+ cascadeAct->setEnabled(hasMdiChild);
+ nextAct->setEnabled(hasMdiChild);
+ previousAct->setEnabled(hasMdiChild);
+ separatorAct->setVisible(hasMdiChild);
+
+#ifndef QT_NO_CLIPBOARD
+ bool hasSelection = (activeMdiChild() &&
+ activeMdiChild()->textCursor().hasSelection());
+ cutAct->setEnabled(hasSelection);
+ copyAct->setEnabled(hasSelection);
+#endif
+}
+
+void MainWindow::updateWindowMenu()
+{
+ windowMenu->clear();
+ windowMenu->addAction(closeAct);
+ windowMenu->addAction(closeAllAct);
+ windowMenu->addSeparator();
+ windowMenu->addAction(tileAct);
+ windowMenu->addAction(cascadeAct);
+ windowMenu->addSeparator();
+ windowMenu->addAction(nextAct);
+ windowMenu->addAction(previousAct);
+ windowMenu->addAction(separatorAct);
+
+ QList<QMdiSubWindow *> windows = mdiArea->subWindowList();
+ separatorAct->setVisible(!windows.isEmpty());
+
+ for (int i = 0; i < windows.size(); ++i) {
+ MdiChild *child = qobject_cast<MdiChild *>(windows.at(i)->widget());
+
+ QString text;
+ if (i < 9) {
+ text = tr("&%1 %2").arg(i + 1)
+ .arg(child->userFriendlyCurrentFile());
+ } else {
+ text = tr("%1 %2").arg(i + 1)
+ .arg(child->userFriendlyCurrentFile());
+ }
+ QAction *action = windowMenu->addAction(text);
+ action->setCheckable(true);
+ action ->setChecked(child == activeMdiChild());
+ connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
+ windowMapper->setMapping(action, windows.at(i));
+ }
+}
+
+MdiChild *MainWindow::createMdiChild()
+{
+ MdiChild *child = new MdiChild;
+ mdiArea->addSubWindow(child);
+
+#ifndef QT_NO_CLIPBOARD
+ connect(child, SIGNAL(copyAvailable(bool)),
+ cutAct, SLOT(setEnabled(bool)));
+ connect(child, SIGNAL(copyAvailable(bool)),
+ copyAct, SLOT(setEnabled(bool)));
+#endif
+
+ return child;
+}
+
+void MainWindow::createActions()
+{
+ newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
+ newAct->setShortcuts(QKeySequence::New);
+ newAct->setStatusTip(tr("Create a new file"));
+ connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
+
+ openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ openAct->setStatusTip(tr("Open an existing file"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this);
+ saveAct->setShortcuts(QKeySequence::Save);
+ saveAct->setStatusTip(tr("Save the document to disk"));
+ connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
+
+ saveAsAct = new QAction(tr("Save &As..."), this);
+ saveAsAct->setShortcuts(QKeySequence::SaveAs);
+ saveAsAct->setStatusTip(tr("Save the document under a new name"));
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+//! [0]
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ exitAct->setStatusTip(tr("Exit the application"));
+ connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
+//! [0]
+
+#ifndef QT_NO_CLIPBOARD
+ cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this);
+ cutAct->setShortcuts(QKeySequence::Cut);
+ cutAct->setStatusTip(tr("Cut the current selection's contents to the "
+ "clipboard"));
+ connect(cutAct, SIGNAL(triggered()), this, SLOT(cut()));
+
+ copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this);
+ copyAct->setShortcuts(QKeySequence::Copy);
+ copyAct->setStatusTip(tr("Copy the current selection's contents to the "
+ "clipboard"));
+ connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));
+
+ pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this);
+ pasteAct->setShortcuts(QKeySequence::Paste);
+ pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
+ "selection"));
+ connect(pasteAct, SIGNAL(triggered()), this, SLOT(paste()));
+#endif
+
+ closeAct = new QAction(tr("Cl&ose"), this);
+ closeAct->setStatusTip(tr("Close the active window"));
+ connect(closeAct, SIGNAL(triggered()),
+ mdiArea, SLOT(closeActiveSubWindow()));
+
+ closeAllAct = new QAction(tr("Close &All"), this);
+ closeAllAct->setStatusTip(tr("Close all the windows"));
+ connect(closeAllAct, SIGNAL(triggered()),
+ mdiArea, SLOT(closeAllSubWindows()));
+
+ tileAct = new QAction(tr("&Tile"), this);
+ tileAct->setStatusTip(tr("Tile the windows"));
+ connect(tileAct, SIGNAL(triggered()), mdiArea, SLOT(tileSubWindows()));
+
+ cascadeAct = new QAction(tr("&Cascade"), this);
+ cascadeAct->setStatusTip(tr("Cascade the windows"));
+ connect(cascadeAct, SIGNAL(triggered()), mdiArea, SLOT(cascadeSubWindows()));
+
+ nextAct = new QAction(tr("Ne&xt"), this);
+ nextAct->setShortcuts(QKeySequence::NextChild);
+ nextAct->setStatusTip(tr("Move the focus to the next window"));
+ connect(nextAct, SIGNAL(triggered()),
+ mdiArea, SLOT(activateNextSubWindow()));
+
+ previousAct = new QAction(tr("Pre&vious"), this);
+ previousAct->setShortcuts(QKeySequence::PreviousChild);
+ previousAct->setStatusTip(tr("Move the focus to the previous "
+ "window"));
+ connect(previousAct, SIGNAL(triggered()),
+ mdiArea, SLOT(activatePreviousSubWindow()));
+
+ separatorAct = new QAction(this);
+ separatorAct->setSeparator(true);
+
+ aboutAct = new QAction(tr("&About"), this);
+ aboutAct->setStatusTip(tr("Show the application's About box"));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(newAct);
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(saveAct);
+ fileMenu->addAction(saveAsAct);
+ fileMenu->addSeparator();
+ QAction *action = fileMenu->addAction(tr("Switch layout direction"));
+ connect(action, SIGNAL(triggered()), this, SLOT(switchLayoutDirection()));
+ fileMenu->addAction(exitAct);
+
+ editMenu = menuBar()->addMenu(tr("&Edit"));
+#ifndef QT_NO_CLIPBOARD
+ editMenu->addAction(cutAct);
+ editMenu->addAction(copyAct);
+ editMenu->addAction(pasteAct);
+#endif
+
+ windowMenu = menuBar()->addMenu(tr("&Window"));
+ updateWindowMenu();
+ connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowMenu()));
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+
+void MainWindow::createToolBars()
+{
+ fileToolBar = addToolBar(tr("File"));
+ fileToolBar->addAction(newAct);
+ fileToolBar->addAction(openAct);
+ fileToolBar->addAction(saveAct);
+
+#ifndef QT_NO_CLIPBOARD
+ editToolBar = addToolBar(tr("Edit"));
+ editToolBar->addAction(cutAct);
+ editToolBar->addAction(copyAct);
+ editToolBar->addAction(pasteAct);
+#endif
+}
+
+void MainWindow::createStatusBar()
+{
+ statusBar()->showMessage(tr("Ready"));
+}
+
+void MainWindow::readSettings()
+{
+ QSettings settings("Trolltech", "MDI Example");
+ QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
+ QSize size = settings.value("size", QSize(400, 400)).toSize();
+ move(pos);
+ resize(size);
+}
+
+void MainWindow::writeSettings()
+{
+ QSettings settings("Trolltech", "MDI Example");
+ settings.setValue("pos", pos());
+ settings.setValue("size", size());
+}
+
+MdiChild *MainWindow::activeMdiChild()
+{
+ if (QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
+ return qobject_cast<MdiChild *>(activeSubWindow->widget());
+ return 0;
+}
+
+QMdiSubWindow *MainWindow::findMdiChild(const QString &fileName)
+{
+ QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
+
+ foreach (QMdiSubWindow *window, mdiArea->subWindowList()) {
+ MdiChild *mdiChild = qobject_cast<MdiChild *>(window->widget());
+ if (mdiChild->currentFile() == canonicalFilePath)
+ return window;
+ }
+ return 0;
+}
+
+void MainWindow::switchLayoutDirection()
+{
+ if (layoutDirection() == Qt::LeftToRight)
+ qApp->setLayoutDirection(Qt::RightToLeft);
+ else
+ qApp->setLayoutDirection(Qt::LeftToRight);
+}
+
+void MainWindow::setActiveSubWindow(QWidget *window)
+{
+ if (!window)
+ return;
+ mdiArea->setActiveSubWindow(qobject_cast<QMdiSubWindow *>(window));
+}
diff --git a/examples/widgets/mainwindows/mdi/mainwindow.h b/examples/widgets/mainwindows/mdi/mainwindow.h
new file mode 100644
index 0000000000..1652ca9749
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/mainwindow.h
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+class MdiChild;
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+class QMdiArea;
+class QMdiSubWindow;
+class QSignalMapper;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void newFile();
+ void open();
+ void save();
+ void saveAs();
+#ifndef QT_NO_CLIPBOARD
+ void cut();
+ void copy();
+ void paste();
+#endif
+ void about();
+ void updateMenus();
+ void updateWindowMenu();
+ MdiChild *createMdiChild();
+ void switchLayoutDirection();
+ void setActiveSubWindow(QWidget *window);
+
+private:
+ void createActions();
+ void createMenus();
+ void createToolBars();
+ void createStatusBar();
+ void readSettings();
+ void writeSettings();
+ MdiChild *activeMdiChild();
+ QMdiSubWindow *findMdiChild(const QString &fileName);
+
+ QMdiArea *mdiArea;
+ QSignalMapper *windowMapper;
+
+ QMenu *fileMenu;
+ QMenu *editMenu;
+ QMenu *windowMenu;
+ QMenu *helpMenu;
+ QToolBar *fileToolBar;
+ QToolBar *editToolBar;
+ QAction *newAct;
+ QAction *openAct;
+ QAction *saveAct;
+ QAction *saveAsAct;
+ QAction *exitAct;
+#ifndef QT_NO_CLIPBOARD
+ QAction *cutAct;
+ QAction *copyAct;
+ QAction *pasteAct;
+#endif
+ QAction *closeAct;
+ QAction *closeAllAct;
+ QAction *tileAct;
+ QAction *cascadeAct;
+ QAction *nextAct;
+ QAction *previousAct;
+ QAction *separatorAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/widgets/mainwindows/mdi/mdi.desktop b/examples/widgets/mainwindows/mdi/mdi.desktop
new file mode 100644
index 0000000000..267e6f19d0
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/mdi.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=MDI
+Exec=/opt/usr/bin/mdi
+Icon=mdi
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/mainwindows/mdi/mdi.pro b/examples/widgets/mainwindows/mdi/mdi.pro
new file mode 100644
index 0000000000..a4387fecd6
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/mdi.pro
@@ -0,0 +1,16 @@
+HEADERS = mainwindow.h \
+ mdichild.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ mdichild.cpp
+RESOURCES = mdi.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/mdi
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS mdi.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/mdi
+INSTALLS += target sources
+
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/mainwindows/mdi/mdi.qrc b/examples/widgets/mainwindows/mdi/mdi.qrc
new file mode 100644
index 0000000000..0a776fab4d
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/mdi.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/copy.png</file>
+ <file>images/cut.png</file>
+ <file>images/new.png</file>
+ <file>images/open.png</file>
+ <file>images/paste.png</file>
+ <file>images/save.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/mainwindows/mdi/mdichild.cpp b/examples/widgets/mainwindows/mdi/mdichild.cpp
new file mode 100644
index 0000000000..2279fe7044
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/mdichild.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mdichild.h"
+
+MdiChild::MdiChild()
+{
+ setAttribute(Qt::WA_DeleteOnClose);
+ isUntitled = true;
+}
+
+void MdiChild::newFile()
+{
+ static int sequenceNumber = 1;
+
+ isUntitled = true;
+ curFile = tr("document%1.txt").arg(sequenceNumber++);
+ setWindowTitle(curFile + "[*]");
+
+ connect(document(), SIGNAL(contentsChanged()),
+ this, SLOT(documentWasModified()));
+}
+
+bool MdiChild::loadFile(const QString &fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("MDI"),
+ tr("Cannot read file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return false;
+ }
+
+ QTextStream in(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ setPlainText(in.readAll());
+ QApplication::restoreOverrideCursor();
+
+ setCurrentFile(fileName);
+
+ connect(document(), SIGNAL(contentsChanged()),
+ this, SLOT(documentWasModified()));
+
+ return true;
+}
+
+bool MdiChild::save()
+{
+ if (isUntitled) {
+ return saveAs();
+ } else {
+ return saveFile(curFile);
+ }
+}
+
+bool MdiChild::saveAs()
+{
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
+ curFile);
+ if (fileName.isEmpty())
+ return false;
+
+ return saveFile(fileName);
+}
+
+bool MdiChild::saveFile(const QString &fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("MDI"),
+ tr("Cannot write file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return false;
+ }
+
+ QTextStream out(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ out << toPlainText();
+ QApplication::restoreOverrideCursor();
+
+ setCurrentFile(fileName);
+ return true;
+}
+
+QString MdiChild::userFriendlyCurrentFile()
+{
+ return strippedName(curFile);
+}
+
+void MdiChild::closeEvent(QCloseEvent *event)
+{
+ if (maybeSave()) {
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+
+void MdiChild::documentWasModified()
+{
+ setWindowModified(document()->isModified());
+}
+
+bool MdiChild::maybeSave()
+{
+ if (document()->isModified()) {
+ QMessageBox::StandardButton ret;
+ ret = QMessageBox::warning(this, tr("MDI"),
+ tr("'%1' has been modified.\n"
+ "Do you want to save your changes?")
+ .arg(userFriendlyCurrentFile()),
+ QMessageBox::Save | QMessageBox::Discard
+ | QMessageBox::Cancel);
+ if (ret == QMessageBox::Save)
+ return save();
+ else if (ret == QMessageBox::Cancel)
+ return false;
+ }
+ return true;
+}
+
+void MdiChild::setCurrentFile(const QString &fileName)
+{
+ curFile = QFileInfo(fileName).canonicalFilePath();
+ isUntitled = false;
+ document()->setModified(false);
+ setWindowModified(false);
+ setWindowTitle(userFriendlyCurrentFile() + "[*]");
+}
+
+QString MdiChild::strippedName(const QString &fullFileName)
+{
+ return QFileInfo(fullFileName).fileName();
+}
diff --git a/examples/widgets/mainwindows/mdi/mdichild.h b/examples/widgets/mainwindows/mdi/mdichild.h
new file mode 100644
index 0000000000..aacdd0f0f6
--- /dev/null
+++ b/examples/widgets/mainwindows/mdi/mdichild.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MDICHILD_H
+#define MDICHILD_H
+
+#include <QTextEdit>
+
+class MdiChild : public QTextEdit
+{
+ Q_OBJECT
+
+public:
+ MdiChild();
+
+ void newFile();
+ bool loadFile(const QString &fileName);
+ bool save();
+ bool saveAs();
+ bool saveFile(const QString &fileName);
+ QString userFriendlyCurrentFile();
+ QString currentFile() { return curFile; }
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void documentWasModified();
+
+private:
+ bool maybeSave();
+ void setCurrentFile(const QString &fileName);
+ QString strippedName(const QString &fullFileName);
+
+ QString curFile;
+ bool isUntitled;
+};
+
+#endif
diff --git a/examples/widgets/charactermap/main.cpp b/examples/widgets/mainwindows/menus/main.cpp
index 09a923477c..09a923477c 100644
--- a/examples/widgets/charactermap/main.cpp
+++ b/examples/widgets/mainwindows/menus/main.cpp
diff --git a/examples/widgets/mainwindows/menus/mainwindow.cpp b/examples/widgets/mainwindows/menus/mainwindow.cpp
new file mode 100644
index 0000000000..e1f3a0c099
--- /dev/null
+++ b/examples/widgets/mainwindows/menus/mainwindow.cpp
@@ -0,0 +1,370 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ QWidget *widget = new QWidget;
+ setCentralWidget(widget);
+//! [0]
+
+//! [1]
+ QWidget *topFiller = new QWidget;
+ topFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+
+ infoLabel = new QLabel(tr("<i>Choose a menu option, or right-click to "
+ "invoke a context menu</i>"));
+ infoLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
+ infoLabel->setAlignment(Qt::AlignCenter);
+
+ QWidget *bottomFiller = new QWidget;
+ bottomFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->setMargin(5);
+ layout->addWidget(topFiller);
+ layout->addWidget(infoLabel);
+ layout->addWidget(bottomFiller);
+ widget->setLayout(layout);
+//! [1]
+
+//! [2]
+ createActions();
+ createMenus();
+
+ QString message = tr("A context menu is available by right-clicking");
+ statusBar()->showMessage(message);
+
+ setWindowTitle(tr("Menus"));
+ setMinimumSize(160, 160);
+ resize(480, 320);
+}
+//! [2]
+
+//! [3]
+void MainWindow::contextMenuEvent(QContextMenuEvent *event)
+{
+ QMenu menu(this);
+ menu.addAction(cutAct);
+ menu.addAction(copyAct);
+ menu.addAction(pasteAct);
+ menu.exec(event->globalPos());
+}
+//! [3]
+
+void MainWindow::newFile()
+{
+ infoLabel->setText(tr("Invoked <b>File|New</b>"));
+}
+
+void MainWindow::open()
+{
+ infoLabel->setText(tr("Invoked <b>File|Open</b>"));
+}
+
+void MainWindow::save()
+{
+ infoLabel->setText(tr("Invoked <b>File|Save</b>"));
+}
+
+void MainWindow::print()
+{
+ infoLabel->setText(tr("Invoked <b>File|Print</b>"));
+}
+
+void MainWindow::undo()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Undo</b>"));
+}
+
+void MainWindow::redo()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Redo</b>"));
+}
+
+void MainWindow::cut()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Cut</b>"));
+}
+
+void MainWindow::copy()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Copy</b>"));
+}
+
+void MainWindow::paste()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Paste</b>"));
+}
+
+void MainWindow::bold()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Format|Bold</b>"));
+}
+
+void MainWindow::italic()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Format|Italic</b>"));
+}
+
+void MainWindow::leftAlign()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Format|Left Align</b>"));
+}
+
+void MainWindow::rightAlign()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Format|Right Align</b>"));
+}
+
+void MainWindow::justify()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Format|Justify</b>"));
+}
+
+void MainWindow::center()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Format|Center</b>"));
+}
+
+void MainWindow::setLineSpacing()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Format|Set Line Spacing</b>"));
+}
+
+void MainWindow::setParagraphSpacing()
+{
+ infoLabel->setText(tr("Invoked <b>Edit|Format|Set Paragraph Spacing</b>"));
+}
+
+void MainWindow::about()
+{
+ infoLabel->setText(tr("Invoked <b>Help|About</b>"));
+ QMessageBox::about(this, tr("About Menu"),
+ tr("The <b>Menu</b> example shows how to create "
+ "menu-bar menus and context menus."));
+}
+
+void MainWindow::aboutQt()
+{
+ infoLabel->setText(tr("Invoked <b>Help|About Qt</b>"));
+}
+
+//! [4]
+void MainWindow::createActions()
+{
+//! [5]
+ newAct = new QAction(tr("&New"), this);
+ newAct->setShortcuts(QKeySequence::New);
+ newAct->setStatusTip(tr("Create a new file"));
+ connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
+//! [4]
+
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ openAct->setStatusTip(tr("Open an existing file"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+//! [5]
+
+ saveAct = new QAction(tr("&Save"), this);
+ saveAct->setShortcuts(QKeySequence::Save);
+ saveAct->setStatusTip(tr("Save the document to disk"));
+ connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
+
+ printAct = new QAction(tr("&Print..."), this);
+ printAct->setShortcuts(QKeySequence::Print);
+ printAct->setStatusTip(tr("Print the document"));
+ connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ exitAct->setStatusTip(tr("Exit the application"));
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ undoAct = new QAction(tr("&Undo"), this);
+ undoAct->setShortcuts(QKeySequence::Undo);
+ undoAct->setStatusTip(tr("Undo the last operation"));
+ connect(undoAct, SIGNAL(triggered()), this, SLOT(undo()));
+
+ redoAct = new QAction(tr("&Redo"), this);
+ redoAct->setShortcuts(QKeySequence::Redo);
+ redoAct->setStatusTip(tr("Redo the last operation"));
+ connect(redoAct, SIGNAL(triggered()), this, SLOT(redo()));
+
+ cutAct = new QAction(tr("Cu&t"), this);
+ cutAct->setShortcuts(QKeySequence::Cut);
+ cutAct->setStatusTip(tr("Cut the current selection's contents to the "
+ "clipboard"));
+ connect(cutAct, SIGNAL(triggered()), this, SLOT(cut()));
+
+ copyAct = new QAction(tr("&Copy"), this);
+ copyAct->setShortcuts(QKeySequence::Copy);
+ copyAct->setStatusTip(tr("Copy the current selection's contents to the "
+ "clipboard"));
+ connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));
+
+ pasteAct = new QAction(tr("&Paste"), this);
+ pasteAct->setShortcuts(QKeySequence::Paste);
+ pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
+ "selection"));
+ connect(pasteAct, SIGNAL(triggered()), this, SLOT(paste()));
+
+ boldAct = new QAction(tr("&Bold"), this);
+ boldAct->setCheckable(true);
+ boldAct->setShortcut(QKeySequence::Bold);
+ boldAct->setStatusTip(tr("Make the text bold"));
+ connect(boldAct, SIGNAL(triggered()), this, SLOT(bold()));
+
+ QFont boldFont = boldAct->font();
+ boldFont.setBold(true);
+ boldAct->setFont(boldFont);
+
+ italicAct = new QAction(tr("&Italic"), this);
+ italicAct->setCheckable(true);
+ italicAct->setShortcut(QKeySequence::Italic);
+ italicAct->setStatusTip(tr("Make the text italic"));
+ connect(italicAct, SIGNAL(triggered()), this, SLOT(italic()));
+
+ QFont italicFont = italicAct->font();
+ italicFont.setItalic(true);
+ italicAct->setFont(italicFont);
+
+ setLineSpacingAct = new QAction(tr("Set &Line Spacing..."), this);
+ setLineSpacingAct->setStatusTip(tr("Change the gap between the lines of a "
+ "paragraph"));
+ connect(setLineSpacingAct, SIGNAL(triggered()), this, SLOT(setLineSpacing()));
+
+ setParagraphSpacingAct = new QAction(tr("Set &Paragraph Spacing..."), this);
+ setParagraphSpacingAct->setStatusTip(tr("Change the gap between paragraphs"));
+ connect(setParagraphSpacingAct, SIGNAL(triggered()),
+ this, SLOT(setParagraphSpacing()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ aboutAct->setStatusTip(tr("Show the application's About box"));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+ connect(aboutQtAct, SIGNAL(triggered()), this, SLOT(aboutQt()));
+
+ leftAlignAct = new QAction(tr("&Left Align"), this);
+ leftAlignAct->setCheckable(true);
+ leftAlignAct->setShortcut(tr("Ctrl+L"));
+ leftAlignAct->setStatusTip(tr("Left align the selected text"));
+ connect(leftAlignAct, SIGNAL(triggered()), this, SLOT(leftAlign()));
+
+ rightAlignAct = new QAction(tr("&Right Align"), this);
+ rightAlignAct->setCheckable(true);
+ rightAlignAct->setShortcut(tr("Ctrl+R"));
+ rightAlignAct->setStatusTip(tr("Right align the selected text"));
+ connect(rightAlignAct, SIGNAL(triggered()), this, SLOT(rightAlign()));
+
+ justifyAct = new QAction(tr("&Justify"), this);
+ justifyAct->setCheckable(true);
+ justifyAct->setShortcut(tr("Ctrl+J"));
+ justifyAct->setStatusTip(tr("Justify the selected text"));
+ connect(justifyAct, SIGNAL(triggered()), this, SLOT(justify()));
+
+ centerAct = new QAction(tr("&Center"), this);
+ centerAct->setCheckable(true);
+ centerAct->setShortcut(tr("Ctrl+E"));
+ centerAct->setStatusTip(tr("Center the selected text"));
+ connect(centerAct, SIGNAL(triggered()), this, SLOT(center()));
+
+//! [6] //! [7]
+ alignmentGroup = new QActionGroup(this);
+ alignmentGroup->addAction(leftAlignAct);
+ alignmentGroup->addAction(rightAlignAct);
+ alignmentGroup->addAction(justifyAct);
+ alignmentGroup->addAction(centerAct);
+ leftAlignAct->setChecked(true);
+//! [6]
+}
+//! [7]
+
+//! [8]
+void MainWindow::createMenus()
+{
+//! [9] //! [10]
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(newAct);
+//! [9]
+ fileMenu->addAction(openAct);
+//! [10]
+ fileMenu->addAction(saveAct);
+ fileMenu->addAction(printAct);
+//! [11]
+ fileMenu->addSeparator();
+//! [11]
+ fileMenu->addAction(exitAct);
+
+ editMenu = menuBar()->addMenu(tr("&Edit"));
+ editMenu->addAction(undoAct);
+ editMenu->addAction(redoAct);
+ editMenu->addSeparator();
+ editMenu->addAction(cutAct);
+ editMenu->addAction(copyAct);
+ editMenu->addAction(pasteAct);
+ editMenu->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+//! [8]
+
+//! [12]
+ formatMenu = editMenu->addMenu(tr("&Format"));
+ formatMenu->addAction(boldAct);
+ formatMenu->addAction(italicAct);
+ formatMenu->addSeparator()->setText(tr("Alignment"));
+ formatMenu->addAction(leftAlignAct);
+ formatMenu->addAction(rightAlignAct);
+ formatMenu->addAction(justifyAct);
+ formatMenu->addAction(centerAct);
+ formatMenu->addSeparator();
+ formatMenu->addAction(setLineSpacingAct);
+ formatMenu->addAction(setParagraphSpacingAct);
+}
+//! [12]
diff --git a/examples/widgets/mainwindows/menus/mainwindow.h b/examples/widgets/mainwindows/menus/mainwindow.h
new file mode 100644
index 0000000000..ebafb529eb
--- /dev/null
+++ b/examples/widgets/mainwindows/menus/mainwindow.h
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QActionGroup;
+class QLabel;
+class QMenu;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+protected:
+ void contextMenuEvent(QContextMenuEvent *event);
+//! [0]
+
+//! [1]
+private slots:
+ void newFile();
+ void open();
+ void save();
+ void print();
+ void undo();
+ void redo();
+ void cut();
+ void copy();
+ void paste();
+ void bold();
+ void italic();
+ void leftAlign();
+ void rightAlign();
+ void justify();
+ void center();
+ void setLineSpacing();
+ void setParagraphSpacing();
+ void about();
+ void aboutQt();
+//! [1]
+
+//! [2]
+private:
+ void createActions();
+ void createMenus();
+//! [2]
+
+//! [3]
+ QMenu *fileMenu;
+ QMenu *editMenu;
+ QMenu *formatMenu;
+ QMenu *helpMenu;
+ QActionGroup *alignmentGroup;
+ QAction *newAct;
+ QAction *openAct;
+ QAction *saveAct;
+ QAction *printAct;
+ QAction *exitAct;
+ QAction *undoAct;
+ QAction *redoAct;
+ QAction *cutAct;
+ QAction *copyAct;
+ QAction *pasteAct;
+ QAction *boldAct;
+ QAction *italicAct;
+ QAction *leftAlignAct;
+ QAction *rightAlignAct;
+ QAction *justifyAct;
+ QAction *centerAct;
+ QAction *setLineSpacingAct;
+ QAction *setParagraphSpacingAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+ QLabel *infoLabel;
+};
+//! [3]
+
+#endif
diff --git a/examples/widgets/mainwindows/menus/menus.desktop b/examples/widgets/mainwindows/menus/menus.desktop
new file mode 100644
index 0000000000..dc2bda92af
--- /dev/null
+++ b/examples/widgets/mainwindows/menus/menus.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Menus
+Exec=/opt/usr/bin/menus
+Icon=menus
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/mainwindows/menus/menus.pro b/examples/widgets/mainwindows/menus/menus.pro
new file mode 100644
index 0000000000..5ed1e0dae5
--- /dev/null
+++ b/examples/widgets/mainwindows/menus/menus.pro
@@ -0,0 +1,11 @@
+HEADERS = mainwindow.h
+SOURCES = mainwindow.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/menus
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS menus.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/menus
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/mainwindows/recentfiles/main.cpp b/examples/widgets/mainwindows/recentfiles/main.cpp
new file mode 100644
index 0000000000..023357719e
--- /dev/null
+++ b/examples/widgets/mainwindows/recentfiles/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ app.setOrganizationName("Trolltech");
+ app.setApplicationName("Recent Files Example");
+ MainWindow *mainWin = new MainWindow;
+ mainWin->show();
+ return app.exec();
+}
diff --git a/examples/widgets/mainwindows/recentfiles/mainwindow.cpp b/examples/widgets/mainwindows/recentfiles/mainwindow.cpp
new file mode 100644
index 0000000000..b439ae8950
--- /dev/null
+++ b/examples/widgets/mainwindows/recentfiles/mainwindow.cpp
@@ -0,0 +1,251 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+MainWindow::MainWindow()
+{
+ setAttribute(Qt::WA_DeleteOnClose);
+
+ textEdit = new QTextEdit;
+ setCentralWidget(textEdit);
+
+ createActions();
+ createMenus();
+ (void)statusBar();
+
+ setWindowFilePath(QString());
+ resize(400, 300);
+}
+
+void MainWindow::newFile()
+{
+ MainWindow *other = new MainWindow;
+ other->show();
+}
+
+void MainWindow::open()
+{
+ QString fileName = QFileDialog::getOpenFileName(this);
+ if (!fileName.isEmpty())
+ loadFile(fileName);
+}
+
+void MainWindow::save()
+{
+ if (curFile.isEmpty())
+ saveAs();
+ else
+ saveFile(curFile);
+}
+
+void MainWindow::saveAs()
+{
+ QString fileName = QFileDialog::getSaveFileName(this);
+ if (fileName.isEmpty())
+ return;
+
+ saveFile(fileName);
+}
+
+void MainWindow::openRecentFile()
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ if (action)
+ loadFile(action->data().toString());
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Recent Files"),
+ tr("The <b>Recent Files</b> example demonstrates how to provide a "
+ "recently used file menu in a Qt application."));
+}
+
+void MainWindow::createActions()
+{
+ newAct = new QAction(tr("&New"), this);
+ newAct->setShortcuts(QKeySequence::New);
+ newAct->setStatusTip(tr("Create a new file"));
+ connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
+
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ openAct->setStatusTip(tr("Open an existing file"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAct = new QAction(tr("&Save"), this);
+ saveAct->setShortcuts(QKeySequence::Save);
+ saveAct->setStatusTip(tr("Save the document to disk"));
+ connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
+
+ saveAsAct = new QAction(tr("Save &As..."), this);
+ saveAsAct->setShortcuts(QKeySequence::SaveAs);
+ saveAsAct->setStatusTip(tr("Save the document under a new name"));
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ for (int i = 0; i < MaxRecentFiles; ++i) {
+ recentFileActs[i] = new QAction(this);
+ recentFileActs[i]->setVisible(false);
+ connect(recentFileActs[i], SIGNAL(triggered()),
+ this, SLOT(openRecentFile()));
+ }
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ exitAct->setStatusTip(tr("Exit the application"));
+ connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ aboutAct->setStatusTip(tr("Show the application's About box"));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(newAct);
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(saveAct);
+ fileMenu->addAction(saveAsAct);
+ separatorAct = fileMenu->addSeparator();
+ for (int i = 0; i < MaxRecentFiles; ++i)
+ fileMenu->addAction(recentFileActs[i]);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+ updateRecentFileActions();
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+
+void MainWindow::loadFile(const QString &fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("Recent Files"),
+ tr("Cannot read file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QTextStream in(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ textEdit->setPlainText(in.readAll());
+ QApplication::restoreOverrideCursor();
+
+ setCurrentFile(fileName);
+ statusBar()->showMessage(tr("File loaded"), 2000);
+}
+
+void MainWindow::saveFile(const QString &fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("Recent Files"),
+ tr("Cannot write file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QTextStream out(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ out << textEdit->toPlainText();
+ QApplication::restoreOverrideCursor();
+
+ setCurrentFile(fileName);
+ statusBar()->showMessage(tr("File saved"), 2000);
+}
+
+void MainWindow::setCurrentFile(const QString &fileName)
+{
+ curFile = fileName;
+ setWindowFilePath(curFile);
+
+ QSettings settings;
+ QStringList files = settings.value("recentFileList").toStringList();
+ files.removeAll(fileName);
+ files.prepend(fileName);
+ while (files.size() > MaxRecentFiles)
+ files.removeLast();
+
+ settings.setValue("recentFileList", files);
+
+ foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ MainWindow *mainWin = qobject_cast<MainWindow *>(widget);
+ if (mainWin)
+ mainWin->updateRecentFileActions();
+ }
+}
+
+void MainWindow::updateRecentFileActions()
+{
+ QSettings settings;
+ QStringList files = settings.value("recentFileList").toStringList();
+
+ int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
+
+ for (int i = 0; i < numRecentFiles; ++i) {
+ QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
+ recentFileActs[i]->setText(text);
+ recentFileActs[i]->setData(files[i]);
+ recentFileActs[i]->setVisible(true);
+ }
+ for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
+ recentFileActs[j]->setVisible(false);
+
+ separatorAct->setVisible(numRecentFiles > 0);
+}
+
+QString MainWindow::strippedName(const QString &fullFileName)
+{
+ return QFileInfo(fullFileName).fileName();
+}
diff --git a/examples/widgets/mainwindows/recentfiles/mainwindow.h b/examples/widgets/mainwindows/recentfiles/mainwindow.h
new file mode 100644
index 0000000000..dd548838fc
--- /dev/null
+++ b/examples/widgets/mainwindows/recentfiles/mainwindow.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QList>
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+class QTextEdit;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void newFile();
+ void open();
+ void save();
+ void saveAs();
+ void openRecentFile();
+ void about();
+
+private:
+ void createActions();
+ void createMenus();
+ void loadFile(const QString &fileName);
+ void saveFile(const QString &fileName);
+ void setCurrentFile(const QString &fileName);
+ void updateRecentFileActions();
+ QString strippedName(const QString &fullFileName);
+
+ QString curFile;
+
+ QTextEdit *textEdit;
+ QMenu *fileMenu;
+ QMenu *recentFilesMenu;
+ QMenu *helpMenu;
+ QAction *newAct;
+ QAction *openAct;
+ QAction *saveAct;
+ QAction *saveAsAct;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+ QAction *separatorAct;
+
+ enum { MaxRecentFiles = 5 };
+ QAction *recentFileActs[MaxRecentFiles];
+};
+
+#endif
diff --git a/examples/widgets/mainwindows/recentfiles/recentfiles.desktop b/examples/widgets/mainwindows/recentfiles/recentfiles.desktop
new file mode 100644
index 0000000000..c314cf7f7c
--- /dev/null
+++ b/examples/widgets/mainwindows/recentfiles/recentfiles.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Recent Files
+Exec=/opt/usr/bin/recentfiles
+Icon=recentfiles
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/mainwindows/recentfiles/recentfiles.pro b/examples/widgets/mainwindows/recentfiles/recentfiles.pro
new file mode 100644
index 0000000000..5425efc68f
--- /dev/null
+++ b/examples/widgets/mainwindows/recentfiles/recentfiles.pro
@@ -0,0 +1,13 @@
+HEADERS = mainwindow.h
+SOURCES = main.cpp \
+ mainwindow.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/recentfiles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS recentfiles.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/recentfiles
+INSTALLS += target sources
+
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/mainwindows/sdi/images/copy.png b/examples/widgets/mainwindows/sdi/images/copy.png
new file mode 100644
index 0000000000..2aeb28288f
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/images/copy.png
Binary files differ
diff --git a/examples/widgets/mainwindows/sdi/images/cut.png b/examples/widgets/mainwindows/sdi/images/cut.png
new file mode 100644
index 0000000000..54638e9386
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/images/cut.png
Binary files differ
diff --git a/examples/widgets/mainwindows/sdi/images/new.png b/examples/widgets/mainwindows/sdi/images/new.png
new file mode 100644
index 0000000000..12131b0100
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/images/new.png
Binary files differ
diff --git a/examples/widgets/mainwindows/sdi/images/open.png b/examples/widgets/mainwindows/sdi/images/open.png
new file mode 100644
index 0000000000..45fa2883a7
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/images/open.png
Binary files differ
diff --git a/examples/widgets/mainwindows/sdi/images/paste.png b/examples/widgets/mainwindows/sdi/images/paste.png
new file mode 100644
index 0000000000..c14425cad1
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/images/paste.png
Binary files differ
diff --git a/examples/widgets/mainwindows/sdi/images/save.png b/examples/widgets/mainwindows/sdi/images/save.png
new file mode 100644
index 0000000000..daba865faf
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/images/save.png
Binary files differ
diff --git a/examples/widgets/mainwindows/sdi/main.cpp b/examples/widgets/mainwindows/sdi/main.cpp
new file mode 100644
index 0000000000..fbbedd9f0d
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(sdi);
+ QApplication app(argc, argv);
+ app.setApplicationName("SDI Example");
+ app.setOrganizationName("Trolltech");
+ MainWindow *mainWin = new MainWindow;
+ mainWin->show();
+ return app.exec();
+}
diff --git a/examples/widgets/mainwindows/sdi/mainwindow.cpp b/examples/widgets/mainwindows/sdi/mainwindow.cpp
new file mode 100644
index 0000000000..bc0685fd77
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/mainwindow.cpp
@@ -0,0 +1,372 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+MainWindow::MainWindow()
+{
+ init();
+ setCurrentFile("");
+}
+
+MainWindow::MainWindow(const QString &fileName)
+{
+ init();
+ loadFile(fileName);
+}
+
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ if (maybeSave()) {
+ writeSettings();
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+
+void MainWindow::newFile()
+{
+ MainWindow *other = new MainWindow;
+ other->move(x() + 40, y() + 40);
+ other->show();
+}
+
+void MainWindow::open()
+{
+ QString fileName = QFileDialog::getOpenFileName(this);
+ if (!fileName.isEmpty()) {
+ MainWindow *existing = findMainWindow(fileName);
+ if (existing) {
+ existing->show();
+ existing->raise();
+ existing->activateWindow();
+ return;
+ }
+
+ if (isUntitled && textEdit->document()->isEmpty()
+ && !isWindowModified()) {
+ loadFile(fileName);
+ } else {
+ MainWindow *other = new MainWindow(fileName);
+ if (other->isUntitled) {
+ delete other;
+ return;
+ }
+ other->move(x() + 40, y() + 40);
+ other->show();
+ }
+ }
+}
+
+bool MainWindow::save()
+{
+ if (isUntitled) {
+ return saveAs();
+ } else {
+ return saveFile(curFile);
+ }
+}
+
+bool MainWindow::saveAs()
+{
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
+ curFile);
+ if (fileName.isEmpty())
+ return false;
+
+ return saveFile(fileName);
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About SDI"),
+ tr("The <b>SDI</b> example demonstrates how to write single "
+ "document interface applications using Qt."));
+}
+
+void MainWindow::documentWasModified()
+{
+ setWindowModified(true);
+}
+
+void MainWindow::init()
+{
+ setAttribute(Qt::WA_DeleteOnClose);
+
+ isUntitled = true;
+
+ textEdit = new QTextEdit;
+ setCentralWidget(textEdit);
+
+ createActions();
+ createMenus();
+ createToolBars();
+ createStatusBar();
+
+ readSettings();
+
+ connect(textEdit->document(), SIGNAL(contentsChanged()),
+ this, SLOT(documentWasModified()));
+
+ setUnifiedTitleAndToolBarOnMac(true);
+}
+
+void MainWindow::createActions()
+{
+ newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
+ newAct->setShortcuts(QKeySequence::New);
+ newAct->setStatusTip(tr("Create a new file"));
+ connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
+
+ openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ openAct->setStatusTip(tr("Open an existing file"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this);
+ saveAct->setShortcuts(QKeySequence::Save);
+ saveAct->setStatusTip(tr("Save the document to disk"));
+ connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
+
+ saveAsAct = new QAction(tr("Save &As..."), this);
+ saveAsAct->setShortcuts(QKeySequence::SaveAs);
+ saveAsAct->setStatusTip(tr("Save the document under a new name"));
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ closeAct = new QAction(tr("&Close"), this);
+ closeAct->setShortcut(tr("Ctrl+W"));
+ closeAct->setStatusTip(tr("Close this window"));
+ connect(closeAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ exitAct->setStatusTip(tr("Exit the application"));
+ connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
+
+ cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this);
+ cutAct->setShortcuts(QKeySequence::Cut);
+ cutAct->setStatusTip(tr("Cut the current selection's contents to the "
+ "clipboard"));
+ connect(cutAct, SIGNAL(triggered()), textEdit, SLOT(cut()));
+
+ copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this);
+ copyAct->setShortcuts(QKeySequence::Copy);
+ copyAct->setStatusTip(tr("Copy the current selection's contents to the "
+ "clipboard"));
+ connect(copyAct, SIGNAL(triggered()), textEdit, SLOT(copy()));
+
+ pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this);
+ pasteAct->setShortcuts(QKeySequence::Paste);
+ pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
+ "selection"));
+ connect(pasteAct, SIGNAL(triggered()), textEdit, SLOT(paste()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ aboutAct->setStatusTip(tr("Show the application's About box"));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+
+ cutAct->setEnabled(false);
+ copyAct->setEnabled(false);
+ connect(textEdit, SIGNAL(copyAvailable(bool)),
+ cutAct, SLOT(setEnabled(bool)));
+ connect(textEdit, SIGNAL(copyAvailable(bool)),
+ copyAct, SLOT(setEnabled(bool)));
+}
+
+//! [implicit tr context]
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+//! [implicit tr context]
+ fileMenu->addAction(newAct);
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(saveAct);
+ fileMenu->addAction(saveAsAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(closeAct);
+ fileMenu->addAction(exitAct);
+
+ editMenu = menuBar()->addMenu(tr("&Edit"));
+ editMenu->addAction(cutAct);
+ editMenu->addAction(copyAct);
+ editMenu->addAction(pasteAct);
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+
+void MainWindow::createToolBars()
+{
+//! [0]
+ fileToolBar = addToolBar(tr("File"));
+ fileToolBar->addAction(newAct);
+ fileToolBar->addAction(openAct);
+//! [0]
+ fileToolBar->addAction(saveAct);
+
+ editToolBar = addToolBar(tr("Edit"));
+ editToolBar->addAction(cutAct);
+ editToolBar->addAction(copyAct);
+ editToolBar->addAction(pasteAct);
+}
+
+void MainWindow::createStatusBar()
+{
+ statusBar()->showMessage(tr("Ready"));
+}
+
+void MainWindow::readSettings()
+{
+ QSettings settings;
+ QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
+ QSize size = settings.value("size", QSize(400, 400)).toSize();
+ move(pos);
+ resize(size);
+}
+
+void MainWindow::writeSettings()
+{
+ QSettings settings;
+ settings.setValue("pos", pos());
+ settings.setValue("size", size());
+}
+
+bool MainWindow::maybeSave()
+{
+ if (textEdit->document()->isModified()) {
+ QMessageBox::StandardButton ret;
+ ret = QMessageBox::warning(this, tr("SDI"),
+ tr("The document has been modified.\n"
+ "Do you want to save your changes?"),
+ QMessageBox::Save | QMessageBox::Discard
+ | QMessageBox::Cancel);
+ if (ret == QMessageBox::Save)
+ return save();
+ else if (ret == QMessageBox::Cancel)
+ return false;
+ }
+ return true;
+}
+
+void MainWindow::loadFile(const QString &fileName)
+{
+
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("SDI"),
+ tr("Cannot read file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QTextStream in(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ textEdit->setPlainText(in.readAll());
+ QApplication::restoreOverrideCursor();
+
+ setCurrentFile(fileName);
+ statusBar()->showMessage(tr("File loaded"), 2000);
+}
+
+bool MainWindow::saveFile(const QString &fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("SDI"),
+ tr("Cannot write file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return false;
+ }
+
+ QTextStream out(&file);
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ out << textEdit->toPlainText();
+ QApplication::restoreOverrideCursor();
+
+ setCurrentFile(fileName);
+ statusBar()->showMessage(tr("File saved"), 2000);
+ return true;
+}
+
+void MainWindow::setCurrentFile(const QString &fileName)
+{
+ static int sequenceNumber = 1;
+
+ isUntitled = fileName.isEmpty();
+ if (isUntitled) {
+ curFile = tr("document%1.txt").arg(sequenceNumber++);
+ } else {
+ curFile = QFileInfo(fileName).canonicalFilePath();
+ }
+
+ textEdit->document()->setModified(false);
+ setWindowModified(false);
+ setWindowFilePath(curFile);
+}
+
+QString MainWindow::strippedName(const QString &fullFileName)
+{
+ return QFileInfo(fullFileName).fileName();
+}
+
+MainWindow *MainWindow::findMainWindow(const QString &fileName)
+{
+ QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
+
+ foreach (QWidget *widget, qApp->topLevelWidgets()) {
+ MainWindow *mainWin = qobject_cast<MainWindow *>(widget);
+ if (mainWin && mainWin->curFile == canonicalFilePath)
+ return mainWin;
+ }
+ return 0;
+}
diff --git a/examples/widgets/mainwindows/sdi/mainwindow.h b/examples/widgets/mainwindows/sdi/mainwindow.h
new file mode 100644
index 0000000000..4bf5ebe9b5
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/mainwindow.h
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [class definition with macro]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+//! [class definition with macro]
+ MainWindow(const QString &fileName);
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void newFile();
+ void open();
+ bool save();
+ bool saveAs();
+ void about();
+ void documentWasModified();
+
+private:
+ void init();
+ void createActions();
+ void createMenus();
+ void createToolBars();
+ void createStatusBar();
+ void readSettings();
+ void writeSettings();
+ bool maybeSave();
+ void loadFile(const QString &fileName);
+ bool saveFile(const QString &fileName);
+ void setCurrentFile(const QString &fileName);
+ QString strippedName(const QString &fullFileName);
+ MainWindow *findMainWindow(const QString &fileName);
+
+ QTextEdit *textEdit;
+ QString curFile;
+ bool isUntitled;
+
+ QMenu *fileMenu;
+ QMenu *editMenu;
+ QMenu *helpMenu;
+ QToolBar *fileToolBar;
+ QToolBar *editToolBar;
+ QAction *newAct;
+ QAction *openAct;
+ QAction *saveAct;
+ QAction *saveAsAct;
+ QAction *closeAct;
+ QAction *exitAct;
+ QAction *cutAct;
+ QAction *copyAct;
+ QAction *pasteAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/widgets/mainwindows/sdi/sdi.desktop b/examples/widgets/mainwindows/sdi/sdi.desktop
new file mode 100644
index 0000000000..06d7289c8b
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/sdi.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=SDI
+Exec=/opt/usr/bin/sdi
+Icon=sdi
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/mainwindows/sdi/sdi.pro b/examples/widgets/mainwindows/sdi/sdi.pro
new file mode 100644
index 0000000000..cd5e0f1616
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/sdi.pro
@@ -0,0 +1,14 @@
+HEADERS = mainwindow.h
+SOURCES = main.cpp \
+ mainwindow.cpp
+RESOURCES = sdi.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/sdi
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS sdi.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/mainwindows/sdi
+INSTALLS += target sources
+
+QT += widgets
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/mainwindows/sdi/sdi.qrc b/examples/widgets/mainwindows/sdi/sdi.qrc
new file mode 100644
index 0000000000..0a776fab4d
--- /dev/null
+++ b/examples/widgets/mainwindows/sdi/sdi.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/copy.png</file>
+ <file>images/cut.png</file>
+ <file>images/new.png</file>
+ <file>images/open.png</file>
+ <file>images/paste.png</file>
+ <file>images/save.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/painting/README b/examples/widgets/painting/README
new file mode 100644
index 0000000000..541c553159
--- /dev/null
+++ b/examples/widgets/painting/README
@@ -0,0 +1,11 @@
+Qt's painting system is able to render vector graphics, images, and outline
+font-based text with sub-pixel accuracy accuracy using anti-aliasing to
+improve rendering quality.
+
+These examples show the most common techniques that are used when painting
+with Qt, from basic concepts such as drawing simple primitives to the use of
+transformations.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/painting/affine/affine.pro b/examples/widgets/painting/affine/affine.pro
new file mode 100644
index 0000000000..0977ea1c5b
--- /dev/null
+++ b/examples/widgets/painting/affine/affine.pro
@@ -0,0 +1,24 @@
+SOURCES += main.cpp xform.cpp
+HEADERS += xform.h
+
+contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2) {
+ DEFINES += QT_OPENGL_SUPPORT
+ QT += opengl
+}
+QT += widgets
+
+SHARED_FOLDER = ../shared
+
+include($$SHARED_FOLDER/shared.pri)
+
+RESOURCES += affine.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/affine
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html *.jpg
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/affine
+INSTALLS += target sources
+
+wince*: {
+ DEPLOYMENT_PLUGIN += qjpeg
+}
diff --git a/examples/widgets/painting/affine/affine.qrc b/examples/widgets/painting/affine/affine.qrc
new file mode 100644
index 0000000000..d8a7ae40cb
--- /dev/null
+++ b/examples/widgets/painting/affine/affine.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res/affine">
+ <file>xform.cpp</file>
+ <file>xform.html</file>
+ <file>bg1.jpg</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/painting/affine/bg1.jpg b/examples/widgets/painting/affine/bg1.jpg
new file mode 100644
index 0000000000..dfc7cee6ad
--- /dev/null
+++ b/examples/widgets/painting/affine/bg1.jpg
Binary files differ
diff --git a/examples/widgets/painting/affine/main.cpp b/examples/widgets/painting/affine/main.cpp
new file mode 100644
index 0000000000..c27e3331f1
--- /dev/null
+++ b/examples/widgets/painting/affine/main.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "xform.h"
+
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(affine);
+
+ QApplication app(argc, argv);
+
+ XFormWidget xformWidget(0);
+ QStyle *arthurStyle = new ArthurStyle();
+ xformWidget.setStyle(arthurStyle);
+
+ QList<QWidget *> widgets = xformWidget.findChildren<QWidget *>();
+ foreach (QWidget *w, widgets) {
+ w->setStyle(arthurStyle);
+ w->setAttribute(Qt::WA_AcceptTouchEvents);
+ }
+
+ xformWidget.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/painting/affine/xform.cpp b/examples/widgets/painting/affine/xform.cpp
new file mode 100644
index 0000000000..8c9d37406c
--- /dev/null
+++ b/examples/widgets/painting/affine/xform.cpp
@@ -0,0 +1,902 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "xform.h"
+#include "hoverpoints.h"
+
+#include <QLayout>
+#include <QPainter>
+#include <QPainterPath>
+
+const int alpha = 155;
+
+XFormView::XFormView(QWidget *parent)
+ : ArthurFrame(parent)
+{
+ setAttribute(Qt::WA_MouseTracking);
+ m_type = VectorType;
+ m_rotation = 0.0;
+ m_scale = 1.0;
+ m_shear = 0.0;
+
+ m_pixmap = QPixmap(":res/affine/bg1.jpg");
+ pts = new HoverPoints(this, HoverPoints::CircleShape);
+ pts->setConnectionType(HoverPoints::LineConnection);
+ pts->setEditable(false);
+ pts->setPointSize(QSize(15, 15));
+ pts->setShapeBrush(QBrush(QColor(151, 0, 0, alpha)));
+ pts->setShapePen(QPen(QColor(255, 100, 50, alpha)));
+ pts->setConnectionPen(QPen(QColor(151, 0, 0, 50)));
+ pts->setBoundingRect(QRectF(0, 0, 500, 500));
+ ctrlPoints << QPointF(250, 250) << QPointF(350, 250);
+ pts->setPoints(ctrlPoints);
+ connect(pts, SIGNAL(pointsChanged(QPolygonF)),
+ this, SLOT(updateCtrlPoints(QPolygonF)));
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+}
+
+XFormView::XFormType XFormView::type() const
+{
+ return m_type;
+}
+
+QPixmap XFormView::pixmap() const
+{
+ return m_pixmap;
+}
+
+QString XFormView::text() const
+{
+ return m_text;
+}
+
+void XFormView::setText(const QString &t)
+{
+ m_text = t;
+ update();
+}
+
+void XFormView::setPixmap(const QPixmap &p)
+{
+ m_pixmap = p;
+ update();
+}
+
+void XFormView::setType(XFormType t)
+{
+ m_type = t;
+ update();
+}
+
+void XFormView::mousePressEvent(QMouseEvent *)
+{
+ setDescriptionEnabled(false);
+}
+
+void XFormView::resizeEvent(QResizeEvent *e)
+{
+ pts->setBoundingRect(rect());
+ ArthurFrame::resizeEvent(e);
+}
+
+void XFormView::paint(QPainter *p)
+{
+ p->save();
+ p->setRenderHint(QPainter::Antialiasing);
+ p->setRenderHint(QPainter::SmoothPixmapTransform);
+ switch (m_type) {
+ case VectorType:
+ drawVectorType(p);
+ break;
+ case PixmapType:
+ drawPixmapType(p);
+ break;
+ case TextType:
+ drawTextType(p);
+ break;
+ }
+ p->restore();
+}
+
+void XFormView::updateCtrlPoints(const QPolygonF &points)
+{
+ QPointF trans = points.at(0) - ctrlPoints.at(0);
+
+ if (qAbs(points.at(0).x() - points.at(1).x()) < 10
+ && qAbs(points.at(0).y() - points.at(1).y()) < 10)
+ pts->setPoints(ctrlPoints);
+ if (!trans.isNull()) {
+ ctrlPoints[0] = points.at(0);
+ ctrlPoints[1] += trans;
+ pts->setPoints(ctrlPoints);
+ }
+ ctrlPoints = points;
+
+ QLineF line(ctrlPoints.at(0), ctrlPoints.at(1));
+ m_rotation = line.angle(QLineF(0, 0, 1, 0));
+ if (line.dy() < 0)
+ m_rotation = 360 - m_rotation;
+
+ if (trans.isNull())
+ emit rotationChanged(int(m_rotation*10));
+}
+
+void XFormView::setVectorType()
+{
+ m_type = VectorType;
+ update();
+}
+
+void XFormView::setPixmapType()
+{
+ m_type = PixmapType;
+ update();
+}
+
+void XFormView::setTextType()
+{
+ m_type = TextType;
+ update();
+}
+
+void XFormView::setAnimation(bool animate)
+{
+ timer.stop();
+ if (animate)
+ timer.start(25, this);
+}
+
+void XFormView::changeRotation(int r)
+{
+ setRotation(qreal(r) / 10);
+}
+
+void XFormView::changeScale(int s)
+{
+ setScale(qreal(s) / 1000);
+}
+
+void XFormView::changeShear(int s)
+{
+ setShear(qreal(s) / 1000);
+}
+
+void XFormView::setShear(qreal s)
+{
+ m_shear = s;
+ update();
+}
+
+void XFormView::setScale(qreal s)
+{
+ m_scale = s;
+ update();
+}
+
+void XFormView::setRotation(qreal r)
+{
+ qreal old_rot = m_rotation;
+ m_rotation = r;
+
+ QPointF center(pts->points().at(0));
+ QMatrix m;
+ m.translate(center.x(), center.y());
+ m.rotate(m_rotation - old_rot);
+ m.translate(-center.x(), -center.y());
+ pts->setPoints(pts->points() * m);
+
+ update();
+}
+
+void XFormView::timerEvent(QTimerEvent *e)
+{
+ if (e->timerId() == timer.timerId()) {
+ QPointF center(pts->points().at(0));
+ QMatrix m;
+ m.translate(center.x(), center.y());
+ m.rotate(0.2);
+ m.translate(-center.x(), -center.y());
+ pts->setPoints(pts->points() * m);
+
+ setUpdatesEnabled(false);
+ static qreal scale_inc = 0.003;
+ static qreal shear_inc = -0.001;
+ emit scaleChanged(int((m_scale + scale_inc) * 1000));
+ emit shearChanged(int((m_shear + shear_inc) * 1000));
+ if (m_scale >= 4.0 || m_scale <= 0.1)
+ scale_inc = -scale_inc;
+ if (m_shear >= 1.0 || m_shear <= -1.0)
+ shear_inc = -shear_inc;
+ setUpdatesEnabled(true);
+
+ pts->firePointChange();
+ }
+}
+
+void XFormView::wheelEvent(QWheelEvent *e)
+{
+ m_scale += e->delta() / qreal(600);
+ m_scale = qMax(qreal(0.1), qMin(qreal(4), m_scale));
+ emit scaleChanged(int(m_scale*1000));
+}
+
+void XFormView::reset()
+{
+ emit rotationChanged(0);
+ emit scaleChanged(1000);
+ emit shearChanged(0);
+ ctrlPoints = QPolygonF();
+ ctrlPoints << QPointF(250, 250) << QPointF(350, 250);
+ pts->setPoints(ctrlPoints);
+ pts->firePointChange();
+}
+
+void XFormView::drawPixmapType(QPainter *painter)
+{
+ QPointF center(m_pixmap.width() / qreal(2), m_pixmap.height() / qreal(2));
+ painter->translate(ctrlPoints.at(0) - center);
+
+ painter->translate(center);
+ painter->rotate(m_rotation);
+ painter->scale(m_scale, m_scale);
+ painter->shear(0, m_shear);
+ painter->translate(-center);
+
+ painter->drawPixmap(QPointF(0, 0), m_pixmap);
+ painter->setPen(QPen(QColor(255, 0, 0, alpha), 0.25, Qt::SolidLine, Qt::FlatCap, Qt::BevelJoin));
+ painter->setBrush(Qt::NoBrush);
+ painter->drawRect(QRectF(0, 0, m_pixmap.width(), m_pixmap.height()).adjusted(-2, -2, 2, 2));
+}
+
+void XFormView::drawTextType(QPainter *painter)
+{
+ QPainterPath path;
+ QFont f("times new roman,utopia");
+ f.setStyleStrategy(QFont::ForceOutline);
+ f.setPointSize(72);
+ f.setStyleHint(QFont::Times);
+ path.addText(0, 0, f, m_text);
+
+ QFontMetrics fm(f);
+ QRectF br(fm.boundingRect(m_text));
+ QPointF center(br.center());
+ painter->translate(ctrlPoints.at(0) - center);
+
+ painter->translate(center);
+ painter->rotate(m_rotation);
+ painter->scale(m_scale, m_scale);
+ painter->shear(0, m_shear);
+ painter->translate(-center);
+
+ painter->fillPath(path, Qt::black);
+
+ painter->setPen(QPen(QColor(255, 0, 0, alpha), 0.25, Qt::SolidLine, Qt::FlatCap, Qt::BevelJoin));
+ painter->setBrush(Qt::NoBrush);
+ painter->drawRect(br.adjusted(-1, -1, 1, 1));
+}
+
+void XFormView::drawVectorType(QPainter *painter)
+{
+ QPainterPath path;
+ painter->translate(ctrlPoints.at(0) - QPointF(250,250));
+
+ painter->scale(0.77, 0.77);
+ painter->translate(98.9154 + 30 , -217.691 - 20);
+
+ QRect br(-55, 275, 500, 590);
+ QPoint center = br.center();
+ painter->translate(center.x(), center.y());
+ painter->rotate(m_rotation);
+ painter->scale(m_scale, m_scale);
+ painter->shear(0, m_shear);
+ painter->translate(-center.x(), -center.y());
+
+ painter->setPen(Qt::NoPen);
+ path.moveTo(120, 470);
+ path.lineTo(60+245, 470);
+ path.lineTo(60+245, 470+350);
+ path.lineTo(60, 470+350);
+ path.lineTo(60, 470+80);
+
+ painter->setBrush(Qt::white);
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor( 193, 193, 191, 255));
+ path.moveTo(329.336, 727.552);
+ path.cubicTo(QPointF(315.224, 726.328), QPointF(304.136, 715.816), QPointF(303.128, 694.936));
+ path.cubicTo(QPointF(306.368, 639.496), QPointF(309.608, 582.112), QPointF(271.232, 545.104));
+ path.cubicTo(QPointF(265.256, 499.024), QPointF(244.016, 482.104), QPointF(234.008, 452.512));
+ path.lineTo(218.24, 441.208);
+ path.lineTo(237.104, 411.688);
+ path.lineTo(245.168, 411.904);
+ path.lineTo(323.936, 571.168);
+ path.lineTo(340.424, 651.448);
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(136.232, 439.696);
+ path.cubicTo(QPointF(133.856, 455.248), QPointF(132.56, 470.512), QPointF(134.792, 485.272));
+ path.cubicTo(QPointF(118.376, 507.592), QPointF(105.92, 530.128), QPointF(104.48, 553.312));
+ path.cubicTo(QPointF(92.024, 586.504), QPointF(62.432, 614.584), QPointF(67.544, 680.104));
+ path.cubicTo(QPointF(84.176, 697.456), QPointF(107.432, 713.584), QPointF(127.376, 730.36));
+ path.cubicTo(QPointF(152.432, 751.312), QPointF(137.528, 778.96), QPointF(102.248, 772.408));
+ path.cubicTo(QPointF(94.4, 763.768), QPointF(76.616, 709.624), QPointF(42.92, 676.288));
+ path.lineTo(49.544, 632.584);
+ path.lineTo(81.368, 547.408);
+ path.lineTo(120.968, 484.048);
+ path.lineTo(125.36, 456.688);
+ path.lineTo(119.816, 386.776);
+ path.lineTo(124.424, 361.216);
+ path.lineTo(136.232, 439.696);
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(115.64, 341.416);
+ path.cubicTo(QPointF(116.576, 336.376), QPointF(117.8, 331.624), QPointF(119.312, 327.16));
+ path.lineTo(121.688, 342.784);
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(120.968, 500.464);
+ path.cubicTo(QPointF(108.368, 523.792), QPointF(103.976, 546.256), QPointF(132.92, 550.216));
+ path.cubicTo(QPointF(117.008, 553.888), QPointF(97.208, 568.648), QPointF(77.192, 593.488));
+ path.lineTo(77.624, 543.016);
+ path.lineTo(101.456, 503.272);
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(-33.256, 818.488);
+ path.cubicTo(QPointF(10.52, 838.144), QPointF(41.408, 837.064), QPointF(69.272, 850.96));
+ path.cubicTo(QPointF(91.304, 862.552), QPointF(113.552, 861.184), QPointF(126.944, 847.144));
+ path.cubicTo(QPointF(138.32, 832.456), QPointF(146.744, 831.736), QPointF(163.52, 830.224));
+ path.cubicTo(QPointF(190.952, 828.568), QPointF(217.736, 828.28), QPointF(241.928, 830.8));
+ path.lineTo(269.576, 833.032);
+ path.cubicTo(QPointF(269.072, 864.064), QPointF(328.04, 867.88), QPointF(345.392, 844.336));
+ path.cubicTo(QPointF(366.344, 819.424), QPointF(395.144, 808.264), QPointF(419.84, 790.192));
+ path.lineTo(289.304, 725.536);
+ path.cubicTo(QPointF(255.824, 806.464), QPointF(131.048, 827.632), QPointF(113.768, 763.264));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(286.424, 711.568);
+ path.cubicTo(QPointF(273.824, 711.496), QPointF(260.936, 715.6), QPointF(261.944, 732.16));
+ path.lineTo(266.192, 776.44);
+ path.lineTo(304.424, 756.64);
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(0, 0, 0, 255));
+ path.moveTo(-37.36, 821.224);
+ path.cubicTo(QPointF(7.136, 840.88), QPointF(38.6, 839.728), QPointF(66.968, 853.696));
+ path.cubicTo(QPointF(89.36, 865.216), QPointF(111.968, 863.92), QPointF(125.648, 849.808));
+ path.cubicTo(QPointF(137.24, 835.192), QPointF(145.808, 834.472), QPointF(162.872, 832.96));
+ path.cubicTo(QPointF(190.736, 831.232), QPointF(218.024, 831.016), QPointF(242.648, 833.464));
+ path.lineTo(270.728, 835.768);
+ path.cubicTo(QPointF(270.224, 866.8), QPointF(330.272, 870.544), QPointF(347.912, 847));
+ path.cubicTo(QPointF(369.224, 822.088), QPointF(398.528, 811), QPointF(423.656, 792.856));
+ path.lineTo(290.816, 728.272);
+ path.cubicTo(QPointF(256.76, 809.128), QPointF(129.824, 830.296), QPointF(112.256, 766));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(183, 114, 0, 255));
+ path.moveTo(382.328, 691.984);
+ path.cubicTo(QPointF(403.64, 698.968), QPointF(389.888, 720.28), QPointF(400.76, 732.52));
+ path.cubicTo(QPointF(405.44, 742.888), QPointF(415.304, 752.032), QPointF(431.792, 760.528));
+ path.cubicTo(QPointF(459.368, 774.424), QPointF(426.248, 799.336), QPointF(392.768, 812.08));
+ path.cubicTo(QPointF(351.944, 825.616), QPointF(344.024, 862.912), QPointF(299.312, 851.896));
+ path.cubicTo(QPointF(283.112, 846.496), QPointF(278.36, 831.808), QPointF(278.864, 809.128));
+ path.cubicTo(QPointF(284.264, 762.76), QPointF(277.784, 730.432), QPointF(278.792, 698.824));
+ path.cubicTo(QPointF(278.72, 686.152), QPointF(283.544, 684.64), QPointF(307.232, 687.952));
+ path.cubicTo(QPointF(310.04, 726.328), QPointF(352.376, 727.336), QPointF(382.328, 691.984));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(242, 183, 0, 255));
+ path.moveTo(339.632, 826.624);
+ path.cubicTo(QPointF(371.6, 814.312), QPointF(403.856, 798.112), QPointF(429.848, 782.128));
+ path.cubicTo(QPointF(437.84, 777.448), QPointF(438.92, 765.928), QPointF(427.688, 762.328));
+ path.cubicTo(QPointF(403.352, 748.504), QPointF(390.104, 731.224), QPointF(392.912, 708.76));
+ path.cubicTo(QPointF(393.344, 700.912), QPointF(383.696, 692.56), QPointF(381.104, 700.048));
+ path.cubicTo(QPointF(359.864, 771.472), QPointF(291.32, 767.656), QPointF(300.752, 696.952));
+ path.cubicTo(QPointF(301.256, 694.864), QPointF(301.76, 692.776), QPointF(302.264, 690.76));
+ path.cubicTo(QPointF(289.952, 688.24), QPointF(285.2, 690.976), QPointF(285.776, 700.408));
+ path.lineTo(295.28, 806.608);
+ path.cubicTo(QPointF(297.656, 830.8), QPointF(317.312, 836.128), QPointF(339.632, 826.624));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(0, 0, 0, 255));
+ path.moveTo(354.464, 537.544);
+ path.cubicTo(QPointF(379.16, 569.8), QPointF(404.432, 651.088), QPointF(384.416, 691.552));
+ path.cubicTo(QPointF(360.944, 737.776), QPointF(307.808, 743.248), QPointF(305.504, 695.8));
+ path.cubicTo(QPointF(308.816, 639.64), QPointF(311.984, 581.536), QPointF(273.68, 544.096));
+ path.cubicTo(QPointF(267.704, 497.368), QPointF(246.392, 480.232), QPointF(236.384, 450.28));
+ path.lineTo(203.12, 426.088);
+ path.lineTo(133.568, 435.088);
+ path.cubicTo(QPointF(130.76, 452.152), QPointF(129.104, 468.784), QPointF(131.552, 484.912));
+ path.cubicTo(QPointF(115.064, 507.376), QPointF(102.608, 530.056), QPointF(101.168, 553.312));
+ path.cubicTo(QPointF(88.712, 586.648), QPointF(59.12, 614.944), QPointF(64.232, 680.752));
+ path.cubicTo(QPointF(80.864, 698.248), QPointF(104.12, 714.448), QPointF(124.064, 731.296));
+ path.cubicTo(QPointF(149.12, 752.392), QPointF(135.512, 776.296), QPointF(100.232, 769.672));
+ path.cubicTo(QPointF(78.848, 746.056), QPointF(56.744, 722.872), QPointF(35.288, 699.328));
+ path.cubicTo(QPointF(12.392, 683.056), QPointF(3.896, 662.176), QPointF(27.368, 630.496));
+ path.cubicTo(QPointF(43.424, 609.04), QPointF(47.96, 562.456), QPointF(62, 543.664));
+ path.cubicTo(QPointF(74.312, 525.16), QPointF(92.24, 508.6), QPointF(105.272, 490.096));
+ path.cubicTo(QPointF(112.184, 477.928), QPointF(114.344, 468.568), QPointF(113.264, 454.456));
+ path.lineTo(110.312, 369.136);
+ path.cubicTo(QPointF(108.368, 307.216), QPointF(142.424, 274.24), QPointF(189.8, 275.248));
+ path.cubicTo(QPointF(243.512, 275.752), QPointF(287.576, 312.472), QPointF(288.152, 378.28));
+ path.cubicTo(QPointF(292.688, 410.32), QPointF(283.256, 428.68), QPointF(308.672, 474.472));
+ path.cubicTo(QPointF(334.52, 522.712), QPointF(338.552, 520.12), QPointF(354.464, 537.544));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(261.296, 503.632);
+ path.lineTo(263.528, 512.2);
+ path.cubicTo(QPointF(257.696, 501.688), QPointF(250.712, 483.616), QPointF(241.928, 475.696));
+ path.cubicTo(QPointF(239.264, 473.536), QPointF(235.808, 473.608), QPointF(233.72, 475.624));
+ path.cubicTo(QPointF(222.056, 486.928), QPointF(193.112, 510.112), QPointF(169.928, 507.088));
+ path.cubicTo(QPointF(152.072, 505.288), QPointF(134.648, 493.264), QPointF(130.832, 480.232));
+ path.cubicTo(QPointF(128.816, 470.872), QPointF(129.752, 463.168), QPointF(130.976, 455.32));
+ path.lineTo(240.704, 453.52);
+ path.cubicTo(QPointF(238.472, 463.168), QPointF(253.088, 487), QPointF(261.296, 503.632));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(143.144, 363.232);
+ path.cubicTo(QPointF(154.088, 363.232), QPointF(163.88, 376.84), QPointF(163.808, 395.632));
+ path.cubicTo(QPointF(163.736, 408.232), QPointF(155.528, 411.472), QPointF(149.336, 417.016));
+ path.cubicTo(QPointF(146.6, 419.536), QPointF(145.952, 433.144), QPointF(142.568, 433.144));
+ path.cubicTo(QPointF(131.696, 433.144), QPointF(123.488, 413.776), QPointF(123.488, 395.632));
+ path.cubicTo(QPointF(123.488, 377.56), QPointF(132.272, 363.232), QPointF(143.144, 363.232));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(255, 255, 255, 255));
+ path.moveTo(144.368, 375.04);
+ path.cubicTo(QPointF(154.088, 375.04), QPointF(160.856, 379.936), QPointF(161.648, 391.312));
+ path.cubicTo(QPointF(162.224, 399.16), QPointF(160.136, 411.76), QPointF(154.664, 414.424));
+ path.cubicTo(QPointF(152.144, 415.648), QPointF(143.432, 426.664), QPointF(140.408, 426.52));
+ path.cubicTo(QPointF(128.096, 425.944), QPointF(125, 402.112), QPointF(125.936, 390.736));
+ path.cubicTo(QPointF(126.8, 379.36), QPointF(134.72, 375.04), QPointF(144.368, 375.04));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(0, 0, 0, 255));
+ path.moveTo(141.848, 382.672);
+ path.cubicTo(QPointF(148.544, 382.096), QPointF(154.736, 389.728), QPointF(155.6, 399.664));
+ path.cubicTo(QPointF(156.464, 409.6), QPointF(151.64, 418.24), QPointF(144.944, 418.816));
+ path.cubicTo(QPointF(138.248, 419.392), QPointF(132.056, 411.76), QPointF(131.192, 401.752));
+ path.cubicTo(QPointF(130.328, 391.816), QPointF(135.152, 383.248), QPointF(141.848, 382.672));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(151.064, 397.288);
+ path.cubicTo(QPointF(151.424, 399.088), QPointF(149.408, 400.024), QPointF(148.832, 398.224));
+ path.cubicTo(QPointF(148.256, 395.992), QPointF(146.888, 393.328), QPointF(145.088, 391.168));
+ path.cubicTo(QPointF(143.936, 389.872), QPointF(145.088, 388.432), QPointF(146.528, 389.44));
+ path.cubicTo(QPointF(149.048, 391.528), QPointF(150.488, 394.12), QPointF(151.064, 397.288));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(216.944, 360.712);
+ path.cubicTo(QPointF(232.712, 360.712), QPointF(245.6, 377.416), QPointF(245.6, 397.792));
+ path.cubicTo(QPointF(245.6, 418.24), QPointF(232.712, 434.872), QPointF(216.944, 434.872));
+ path.cubicTo(QPointF(201.176, 434.872), QPointF(188.432, 418.24), QPointF(188.432, 397.792));
+ path.cubicTo(QPointF(188.432, 377.416), QPointF(201.176, 360.712), QPointF(216.944, 360.712));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(255, 255, 255, 255));
+ path.moveTo(224.792, 374.968);
+ path.cubicTo(QPointF(235.664, 378.856), QPointF(241.928, 387.424), QPointF(242.72, 396.568));
+ path.cubicTo(QPointF(243.656, 407.08), QPointF(239.408, 418.96), QPointF(230.264, 425.944));
+ path.cubicTo(QPointF(227.672, 427.888), QPointF(197.72, 416.08), QPointF(195.992, 411.616));
+ path.cubicTo(QPointF(193.4, 405.208), QPointF(191.816, 392.896), QPointF(193.76, 385.624));
+ path.cubicTo(QPointF(194.552, 382.744), QPointF(197.216, 378.568), QPointF(201.176, 376.336));
+ path.cubicTo(QPointF(207.44, 372.808), QPointF(216.656, 372.088), QPointF(224.792, 374.968));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(0, 0, 0, 255));
+ path.moveTo(216.872, 380.944);
+ path.cubicTo(QPointF(225.584, 380.944), QPointF(232.712, 389.296), QPointF(232.712, 399.448));
+ path.cubicTo(QPointF(232.712, 409.672), QPointF(225.584, 418.024), QPointF(216.872, 418.024));
+ path.cubicTo(QPointF(208.16, 418.024), QPointF(201.032, 409.672), QPointF(201.032, 399.448));
+ path.cubicTo(QPointF(201.032, 389.296), QPointF(208.16, 380.944), QPointF(216.872, 380.944));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(227.096, 392.392);
+ path.cubicTo(QPointF(228.104, 394.048), QPointF(226.448, 395.776), QPointF(225.224, 394.12));
+ path.cubicTo(QPointF(223.784, 392.104), QPointF(221.408, 389.944), QPointF(218.888, 388.432));
+ path.cubicTo(QPointF(217.232, 387.568), QPointF(217.808, 385.624), QPointF(219.68, 386.2));
+ path.cubicTo(QPointF(222.92, 387.28), QPointF(225.368, 389.368), QPointF(227.096, 392.392));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(183, 114, 0, 255));
+ path.moveTo(164.96, 404.488);
+ path.cubicTo(QPointF(172.376, 402.328), QPointF(184.112, 403.048), QPointF(192.248, 404.632));
+ path.cubicTo(QPointF(200.384, 406.792), QPointF(222.056, 418.24), QPointF(245.024, 430.696));
+ path.cubicTo(QPointF(247.976, 432.208), QPointF(248.84, 437.104), QPointF(245.024, 438.688));
+ path.cubicTo(QPointF(239.12, 439.12), QPointF(249.272, 453.664), QPointF(238.904, 458.848));
+ path.cubicTo(QPointF(223.352, 462.88), QPointF(198.44, 485.992), QPointF(186.128, 487.864));
+ path.cubicTo(QPointF(179.288, 489.376), QPointF(172.232, 489.592), QPointF(164.6, 487.864));
+ path.cubicTo(QPointF(140.552, 482.968), QPointF(134.216, 455.608), QPointF(122.912, 450.064));
+ path.cubicTo(QPointF(119.816, 446.824), QPointF(121.4, 441.208), QPointF(122.408, 440.056));
+ path.cubicTo(QPointF(123.632, 434.224), QPointF(149.696, 406.216), QPointF(164.96, 404.488));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(242, 183, 0, 255));
+ path.moveTo(185.408, 405.856);
+ path.cubicTo(QPointF(198.44, 407.296), QPointF(226.088, 423.928), QPointF(239.408, 430.624));
+ path.cubicTo(QPointF(242.72, 432.424), QPointF(242.504, 437.824), QPointF(239.552, 438.688));
+ path.cubicTo(QPointF(236.384, 440.488), QPointF(235.448, 438.256), QPointF(232.928, 437.896));
+ path.cubicTo(QPointF(228.896, 435.736), QPointF(222.272, 440.92), QPointF(217.016, 444.88));
+ path.cubicTo(QPointF(186.704, 467.776), QPointF(180.656, 465.256), QPointF(156.176, 462.664));
+ path.cubicTo(QPointF(147.68, 460.576), QPointF(142.136, 457.984), QPointF(139.688, 455.968));
+ path.cubicTo(QPointF(141.488, 445.888), QPointF(160.496, 407.656), QPointF(166.76, 406.792));
+ path.cubicTo(QPointF(168.344, 404.704), QPointF(179.936, 404.632), QPointF(185.408, 405.856));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(183, 114, 0, 255));
+ path.moveTo(190.664, 412.048);
+ path.lineTo(193.76, 413.416);
+ path.cubicTo(QPointF(196.064, 414.712), QPointF(193.256, 418.168), QPointF(190.736, 417.088));
+ path.lineTo(186.2, 415.504);
+ path.cubicTo(QPointF(183.536, 413.272), QPointF(186.704, 410.104), QPointF(190.664, 412.048));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(268.568, 452.368);
+ path.cubicTo(QPointF(273.032, 454.384), QPointF(279.224, 457.192), QPointF(282.536, 460.144));
+ path.cubicTo(QPointF(285.488, 464.104), QPointF(286.784, 468.064), QPointF(286.424, 472.024));
+ path.cubicTo(QPointF(285.776, 474.544), QPointF(284.12, 476.344), QPointF(281.24, 477.424));
+ path.cubicTo(QPointF(277.856, 478.216), QPointF(273.68, 477.424), QPointF(271.376, 474.112));
+ path.cubicTo(QPointF(269.864, 471.448), QPointF(265.256, 462.16), QPointF(263.96, 460.576));
+ path.cubicTo(QPointF(262.232, 457.12), QPointF(261.944, 454.456), QPointF(262.88, 452.368));
+ path.cubicTo(QPointF(264.032, 451.288), QPointF(266.048, 451), QPointF(268.568, 452.368));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(255, 255, 255, 255));
+ path.moveTo(273.752, 461.584);
+ path.cubicTo(QPointF(275.48, 462.376), QPointF(277.928, 463.456), QPointF(279.224, 464.68));
+ path.cubicTo(QPointF(280.376, 466.264), QPointF(280.88, 467.776), QPointF(280.736, 469.36));
+ path.cubicTo(QPointF(280.52, 470.296), QPointF(279.8, 471.016), QPointF(278.72, 471.448));
+ path.cubicTo(QPointF(277.352, 471.808), QPointF(275.768, 471.448), QPointF(274.832, 470.152));
+ path.cubicTo(QPointF(274.256, 469.144), QPointF(272.456, 465.472), QPointF(271.952, 464.824));
+ path.cubicTo(QPointF(271.232, 463.456), QPointF(271.088, 462.448), QPointF(271.448, 461.584));
+ path.cubicTo(QPointF(271.952, 461.152), QPointF(272.744, 461.08), QPointF(273.752, 461.584));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(238.616, 358.552);
+ path.cubicTo(QPointF(239.048, 359.2), QPointF(238.976, 359.776), QPointF(238.4, 360.28));
+ path.cubicTo(QPointF(237.896, 360.784), QPointF(237.176, 360.712), QPointF(236.24, 360.208));
+ path.lineTo(231.632, 356.248);
+ path.cubicTo(QPointF(231.056, 355.744), QPointF(230.912, 354.952), QPointF(231.272, 354.088));
+ path.cubicTo(QPointF(232.28, 353.44), QPointF(233.144, 353.44), QPointF(233.936, 354.088));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(235.592, 305.992);
+ path.cubicTo(QPointF(239.624, 308.224), QPointF(240.848, 313.912), QPointF(238.184, 318.592));
+ path.cubicTo(QPointF(235.592, 323.2), QPointF(230.12, 325.144), QPointF(226.016, 322.84));
+ path.cubicTo(QPointF(221.984, 320.536), QPointF(220.76, 314.92), QPointF(223.424, 310.24));
+ path.cubicTo(QPointF(226.016, 305.56), QPointF(231.488, 303.688), QPointF(235.592, 305.992));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(374.912, 680.536);
+ path.cubicTo(QPointF(378.296, 683.128), QPointF(373.256, 687.376), QPointF(371.024, 686.296));
+ path.cubicTo(QPointF(369.152, 685.648), QPointF(367.784, 683.488), QPointF(366.92, 682.408));
+ path.cubicTo(QPointF(366.128, 681.184), QPointF(366.2, 679.168), QPointF(366.92, 678.448));
+ path.cubicTo(QPointF(367.712, 677.44), QPointF(369.728, 677.656), QPointF(371.024, 678.52));
+ path.cubicTo(QPointF(372.32, 679.168), QPointF(373.616, 679.888), QPointF(374.912, 680.536));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(297.44, 551.512);
+ path.cubicTo(QPointF(338.984, 572.896), QPointF(350, 611.56), QPointF(332.072, 664.192));
+ path.cubicTo(QPointF(330.992, 666.64), QPointF(334.16, 668.368), QPointF(335.24, 666.064));
+ path.cubicTo(QPointF(354.824, 610.336), QPointF(341.432, 571.312), QPointF(299.024, 548.56));
+ path.cubicTo(QPointF(296.864, 547.552), QPointF(295.28, 550.432), QPointF(297.44, 551.512));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(72.008, 569.512);
+ path.cubicTo(QPointF(38.312, 627.256), QPointF(38.096, 662.68), QPointF(62.504, 681.328));
+ path.cubicTo(QPointF(63.728, 682.264), QPointF(64.448, 680.032), QPointF(63.296, 679.168));
+ path.cubicTo(QPointF(36.296, 655.48), QPointF(48.896, 615.52), QPointF(74.168, 570.88));
+ path.cubicTo(QPointF(74.888, 569.584), QPointF(72.512, 568.432), QPointF(72.008, 569.512));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(289.376, 586.864);
+ path.cubicTo(QPointF(289.232, 589.168), QPointF(288.368, 589.528), QPointF(286.424, 587.368));
+ path.cubicTo(QPointF(279.8, 575.848), QPointF(235.088, 551.44), QPointF(213.344, 548.704));
+ path.cubicTo(QPointF(209.24, 547.264), QPointF(209.456, 545.392), QPointF(213.488, 544.816));
+ path.cubicTo(QPointF(229.184, 544.816), QPointF(241.28, 537.904), QPointF(254.96, 537.904));
+ path.cubicTo(QPointF(258.704, 538.048), QPointF(262.304, 539.488), QPointF(264.392, 541.648));
+ path.cubicTo(QPointF(269.504, 544.96), QPointF(288.08, 570.592), QPointF(289.376, 586.864));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(180.152, 546.832);
+ path.cubicTo(QPointF(180.872, 550.792), QPointF(163.808, 545.68), QPointF(164.744, 556.696));
+ path.cubicTo(QPointF(165.032, 559.72), QPointF(160.496, 561.376), QPointF(160.64, 556.696));
+ path.cubicTo(QPointF(160.64, 548.272), QPointF(161.072, 548.416), QPointF(152.72, 546.832));
+ path.cubicTo(QPointF(151.208, 546.76), QPointF(151.352, 544.528), QPointF(152.72, 544.816));
+ path.lineTo(152.72, 544.816);
+ path.cubicTo(QPointF(158.696, 546.472), QPointF(166.76, 542.872), QPointF(166.4, 538.84));
+ path.cubicTo(QPointF(166.256, 537.472), QPointF(168.56, 537.688), QPointF(168.488, 538.84));
+ path.cubicTo(QPointF(167.984, 545.248), QPointF(181.664, 542.152), QPointF(180.152, 546.832));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(193, 193, 191, 255));
+ path.moveTo(151.568, 705.376);
+ path.cubicTo(QPointF(151.64, 708.328), QPointF(148.76, 707.68), QPointF(148.544, 705.592));
+ path.cubicTo(QPointF(140.192, 680.536), QPointF(143.72, 618.832), QPointF(151.856, 598.96));
+ path.cubicTo(QPointF(152.432, 596.08), QPointF(156.248, 596.944), QPointF(155.744, 598.96));
+ path.cubicTo(QPointF(147.104, 635.464), QPointF(147.248, 673.048), QPointF(151.568, 705.376));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(183, 114, 0, 255));
+ path.moveTo(51.704, 684.424);
+ path.cubicTo(QPointF(75.68, 707.824), QPointF(91.376, 743.248), QPointF(114.632, 775.288));
+ path.cubicTo(QPointF(148.472, 816.04), QPointF(121.472, 858.304), QPointF(66.464, 845.56));
+ path.cubicTo(QPointF(38.888, 835.192), QPointF(-0.784, 836.344), QPointF(-32.68, 825.832));
+ path.cubicTo(QPointF(-55.072, 820.36), QPointF(-55.864, 809.272), QPointF(-44.416, 787.6));
+ path.cubicTo(QPointF(-40.384, 773.776), QPointF(-40.024, 751.312), QPointF(-43.768, 732.592));
+ path.cubicTo(QPointF(-45.784, 718.408), QPointF(-39.232, 710.488), QPointF(-24.112, 708.832));
+ path.lineTo(-24.112, 708.832);
+ path.cubicTo(QPointF(-11.296, 708.688), QPointF(6.56, 713.872), QPointF(16.28, 686.44));
+ path.cubicTo(QPointF(23.552, 673.336), QPointF(40.976, 672.976), QPointF(51.704, 684.424));
+ path.closeSubpath();
+ painter->drawPath(path);
+ path = QPainterPath();
+
+ painter->setBrush(QColor(242, 183, 0, 255));
+ path.moveTo(24.632, 699.04);
+ path.cubicTo(QPointF(23.84, 680.968), QPointF(39.32, 677.296), QPointF(49.688, 688.312));
+ path.cubicTo(QPointF(68.192, 710.992), QPointF(85.112, 736.048), QPointF(100.376, 764.992));
+ path.cubicTo(QPointF(124.712, 804.16), QPointF(104.624, 842.68), QPointF(67.904, 828.064));
+ path.cubicTo(QPointF(49.688, 817.84), QPointF(6.128, 813.304), QPointF(-17.344, 809.128));
+ path.cubicTo(QPointF(-33.04, 807.832), QPointF(-35.128, 797.608), QPointF(-29.152, 791.848));
+ path.cubicTo(QPointF(-20.944, 782.416), QPointF(-20.08, 759.808), QPointF(-27.856, 740.512));
+ path.cubicTo(QPointF(-35.56, 728.56), QPointF(-21.088, 715.384), QPointF(-9.712, 720.856));
+ path.cubicTo(QPointF(0.8, 727.048), QPointF(25.64, 713.08), QPointF(24.632, 699.04));
+ path.closeSubpath();
+ painter->drawPath(path);
+
+ painter->setPen(QPen(QColor(255, 0, 0, alpha), 0.25, Qt::SolidLine, Qt::FlatCap, Qt::BevelJoin));
+ painter->setBrush(Qt::NoBrush);
+ painter->drawRect(br.adjusted(-1, -1, 1, 1));
+}
+
+
+XFormWidget::XFormWidget(QWidget *parent)
+ : QWidget(parent), textEditor(new QLineEdit)
+{
+ setWindowTitle(tr("Affine Transformations"));
+
+ view = new XFormView(this);
+ view->setMinimumSize(200, 200);
+
+ QGroupBox *mainGroup = new QGroupBox(this);
+ mainGroup->setFixedWidth(180);
+ mainGroup->setTitle(tr("Affine Transformations"));
+
+ QGroupBox *rotateGroup = new QGroupBox(mainGroup);
+ rotateGroup->setTitle(tr("Rotate"));
+ QSlider *rotateSlider = new QSlider(Qt::Horizontal, rotateGroup);
+ rotateSlider->setRange(0, 3600);
+ rotateSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+
+ QGroupBox *scaleGroup = new QGroupBox(mainGroup);
+ scaleGroup->setTitle(tr("Scale"));
+ QSlider *scaleSlider = new QSlider(Qt::Horizontal, scaleGroup);
+ scaleSlider->setRange(1, 4000);
+ scaleSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+
+ QGroupBox *shearGroup = new QGroupBox(mainGroup);
+ shearGroup->setTitle(tr("Shear"));
+ QSlider *shearSlider = new QSlider(Qt::Horizontal, shearGroup);
+ shearSlider->setRange(-990, 990);
+ shearSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+
+ QGroupBox *typeGroup = new QGroupBox(mainGroup);
+ typeGroup->setTitle(tr("Type"));
+ QRadioButton *vectorType = new QRadioButton(typeGroup);
+ QRadioButton *pixmapType = new QRadioButton(typeGroup);
+ QRadioButton *textType= new QRadioButton(typeGroup);
+ vectorType->setText(tr("Vector Image"));
+ pixmapType->setText(tr("Pixmap"));
+ textType->setText(tr("Text"));
+
+ QPushButton *resetButton = new QPushButton(mainGroup);
+ resetButton->setText(tr("Reset Transform"));
+
+ QPushButton *animateButton = new QPushButton(mainGroup);
+ animateButton->setText(tr("Animate"));
+ animateButton->setCheckable(true);
+
+ QPushButton *showSourceButton = new QPushButton(mainGroup);
+ showSourceButton->setText(tr("Show Source"));
+#ifdef QT_OPENGL_SUPPORT
+ QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(true);
+ enableOpenGLButton->setChecked(view->usesOpenGL());
+ if (!QGLFormat::hasOpenGL())
+ enableOpenGLButton->hide();
+#endif
+ QPushButton *whatsThisButton = new QPushButton(mainGroup);
+ whatsThisButton->setText(tr("What's This?"));
+ whatsThisButton->setCheckable(true);
+
+ QHBoxLayout *viewLayout = new QHBoxLayout(this);
+ viewLayout->addWidget(view);
+ viewLayout->addWidget(mainGroup);
+
+ QVBoxLayout *rotateGroupLayout = new QVBoxLayout(rotateGroup);
+ rotateGroupLayout->addWidget(rotateSlider);
+
+ QVBoxLayout *scaleGroupLayout = new QVBoxLayout(scaleGroup);
+ scaleGroupLayout->addWidget(scaleSlider);
+
+ QVBoxLayout *shearGroupLayout = new QVBoxLayout(shearGroup);
+ shearGroupLayout->addWidget(shearSlider);
+
+ QVBoxLayout *typeGroupLayout = new QVBoxLayout(typeGroup);
+ typeGroupLayout->addWidget(vectorType);
+ typeGroupLayout->addWidget(pixmapType);
+ typeGroupLayout->addWidget(textType);
+ typeGroupLayout->addSpacing(4);
+ typeGroupLayout->addWidget(textEditor);
+
+ QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
+ mainGroupLayout->addWidget(rotateGroup);
+ mainGroupLayout->addWidget(scaleGroup);
+ mainGroupLayout->addWidget(shearGroup);
+ mainGroupLayout->addWidget(typeGroup);
+ mainGroupLayout->addStretch(1);
+ mainGroupLayout->addWidget(resetButton);
+ mainGroupLayout->addWidget(animateButton);
+ mainGroupLayout->addWidget(showSourceButton);
+#ifdef QT_OPENGL_SUPPORT
+ mainGroupLayout->addWidget(enableOpenGLButton);
+#endif
+ mainGroupLayout->addWidget(whatsThisButton);
+
+ connect(rotateSlider, SIGNAL(valueChanged(int)), view, SLOT(changeRotation(int)));
+ connect(shearSlider, SIGNAL(valueChanged(int)), view, SLOT(changeShear(int)));
+ connect(scaleSlider, SIGNAL(valueChanged(int)), view, SLOT(changeScale(int)));
+
+ connect(vectorType, SIGNAL(clicked()), view, SLOT(setVectorType()));
+ connect(pixmapType, SIGNAL(clicked()), view, SLOT(setPixmapType()));
+ connect(textType, SIGNAL(clicked()), view, SLOT(setTextType()));
+ connect(textType, SIGNAL(toggled(bool)), textEditor, SLOT(setEnabled(bool)));
+ connect(textEditor, SIGNAL(textChanged(QString)), view, SLOT(setText(QString)));
+
+ connect(view, SIGNAL(rotationChanged(int)), rotateSlider, SLOT(setValue(int)));
+ connect(view, SIGNAL(scaleChanged(int)), scaleSlider, SLOT(setValue(int)));
+ connect(view, SIGNAL(shearChanged(int)), shearSlider, SLOT(setValue(int)));
+
+ connect(resetButton, SIGNAL(clicked()), view, SLOT(reset()));
+ connect(animateButton, SIGNAL(clicked(bool)), view, SLOT(setAnimation(bool)));
+ connect(whatsThisButton, SIGNAL(clicked(bool)), view, SLOT(setDescriptionEnabled(bool)));
+ connect(whatsThisButton, SIGNAL(clicked(bool)), view->hoverPoints(), SLOT(setDisabled(bool)));
+ connect(view, SIGNAL(descriptionEnabledChanged(bool)), view->hoverPoints(), SLOT(setDisabled(bool)));
+ connect(view, SIGNAL(descriptionEnabledChanged(bool)), whatsThisButton, SLOT(setChecked(bool)));
+ connect(showSourceButton, SIGNAL(clicked()), view, SLOT(showSource()));
+#ifdef QT_OPENGL_SUPPORT
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), view, SLOT(enableOpenGL(bool)));
+#endif
+ view->loadSourceFile(":res/affine/xform.cpp");
+ view->loadDescription(":res/affine/xform.html");
+
+ // defaults
+ view->reset();
+ vectorType->setChecked(true);
+ textEditor->setText("Qt Affine Transformation Example");
+ textEditor->setEnabled(false);
+
+ animateButton->animateClick();
+}
diff --git a/examples/widgets/painting/affine/xform.h b/examples/widgets/painting/affine/xform.h
new file mode 100644
index 0000000000..d710f5175e
--- /dev/null
+++ b/examples/widgets/painting/affine/xform.h
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XFORM_H
+#define XFORM_H
+
+#include "arthurwidgets.h"
+
+#include <QBasicTimer>
+#include <QPolygonF>
+
+class HoverPoints;
+QT_FORWARD_DECLARE_CLASS(QLineEdit)
+
+class XFormView : public ArthurFrame
+{
+public:
+ Q_OBJECT
+
+ Q_PROPERTY(XFormType type READ type WRITE setType)
+ Q_PROPERTY(bool animation READ animation WRITE setAnimation)
+ Q_PROPERTY(qreal shear READ shear WRITE setShear)
+ Q_PROPERTY(qreal rotation READ rotation WRITE setRotation)
+ Q_PROPERTY(qreal scale READ scale WRITE setScale)
+ Q_PROPERTY(QString text READ text WRITE setText)
+ Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
+ Q_ENUMS(XFormType)
+
+public:
+ enum XFormType { VectorType, PixmapType, TextType };
+
+ XFormView(QWidget *parent);
+ void paint(QPainter *);
+ void drawVectorType(QPainter *painter);
+ void drawPixmapType(QPainter *painter);
+ void drawTextType(QPainter *painter);
+ QSize sizeHint() const { return QSize(500, 500); }
+
+ void mousePressEvent(QMouseEvent *e);
+ void resizeEvent(QResizeEvent *e);
+ HoverPoints *hoverPoints() { return pts; }
+
+ bool animation() const { return timer.isActive(); }
+ qreal shear() const { return m_shear; }
+ qreal scale() const { return m_scale; }
+ qreal rotation() const { return m_rotation; }
+ void setShear(qreal s);
+ void setScale(qreal s);
+ void setRotation(qreal r);
+
+ XFormType type() const;
+ QPixmap pixmap() const;
+ QString text() const;
+
+public slots:
+ void setAnimation(bool animate);
+ void updateCtrlPoints(const QPolygonF &);
+ void changeRotation(int rotation);
+ void changeScale(int scale);
+ void changeShear(int shear);
+
+ void setText(const QString &);
+ void setPixmap(const QPixmap &);
+ void setType(XFormType t);
+
+ void setVectorType();
+ void setPixmapType();
+ void setTextType();
+ void reset();
+
+signals:
+ void rotationChanged(int rotation);
+ void scaleChanged(int scale);
+ void shearChanged(int shear);
+
+protected:
+ void timerEvent(QTimerEvent *e);
+ void wheelEvent(QWheelEvent *);
+
+private:
+ QPolygonF ctrlPoints;
+ HoverPoints *pts;
+ qreal m_rotation;
+ qreal m_scale;
+ qreal m_shear;
+ XFormType m_type;
+ QPixmap m_pixmap;
+ QString m_text;
+ QBasicTimer timer;
+};
+
+class XFormWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ XFormWidget(QWidget *parent);
+
+private:
+ XFormView *view;
+ QLineEdit *textEditor;
+};
+
+#endif // XFORM_H
diff --git a/examples/widgets/painting/affine/xform.html b/examples/widgets/painting/affine/xform.html
new file mode 100644
index 0000000000..17325ac2a0
--- /dev/null
+++ b/examples/widgets/painting/affine/xform.html
@@ -0,0 +1,23 @@
+<html>
+<center>
+<h2>Affine Transformations</h2>
+</center>
+
+<p>In this demo we demonstrate Qt's ability to perform affine transformations
+on painting operations.</p>
+
+<p>Transformations can be performed on any kind of graphics drawn using
+QPainter. The transformations used to display the vector graphics, images,
+and text can be adjusted in the following ways:</p>
+
+<ul>
+ <li>Dragging the red circle in the centre of each drawing moves it to a new
+ position.</li>
+ <li>Dragging the displaced red circle causes the current drawing to be
+ rotated about the central circle. Rotation can also be controlled with
+ the <b>Rotate</b> slider.</li>
+ <li>Scaling is controlled with the <b>Scale</b> slider.</li>
+ <li>Each drawing can be sheared with the <b>Shear</b> slider.</li>
+</ul>
+
+</html>
diff --git a/examples/widgets/painting/basicdrawing/basicdrawing.desktop b/examples/widgets/painting/basicdrawing/basicdrawing.desktop
new file mode 100644
index 0000000000..7f178ec8a7
--- /dev/null
+++ b/examples/widgets/painting/basicdrawing/basicdrawing.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Basic Drawing
+Exec=/opt/usr/bin/basicdrawing
+Icon=basicdrawing
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/painting/basicdrawing/basicdrawing.pro b/examples/widgets/painting/basicdrawing/basicdrawing.pro
new file mode 100644
index 0000000000..0e0328e61f
--- /dev/null
+++ b/examples/widgets/painting/basicdrawing/basicdrawing.pro
@@ -0,0 +1,14 @@
+HEADERS = renderarea.h \
+ window.h
+SOURCES = main.cpp \
+ renderarea.cpp \
+ window.cpp
+RESOURCES = basicdrawing.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/basicdrawing
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS basicdrawing.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/basicdrawing
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/painting/basicdrawing/basicdrawing.qrc b/examples/widgets/painting/basicdrawing/basicdrawing.qrc
new file mode 100644
index 0000000000..9d8a23a1c8
--- /dev/null
+++ b/examples/widgets/painting/basicdrawing/basicdrawing.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/brick.png</file>
+ <file>images/qt-logo.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/painting/basicdrawing/images/brick.png b/examples/widgets/painting/basicdrawing/images/brick.png
new file mode 100644
index 0000000000..87e7df5b04
--- /dev/null
+++ b/examples/widgets/painting/basicdrawing/images/brick.png
Binary files differ
diff --git a/examples/widgets/painting/basicdrawing/images/qt-logo.png b/examples/widgets/painting/basicdrawing/images/qt-logo.png
new file mode 100644
index 0000000000..a8b452e07a
--- /dev/null
+++ b/examples/widgets/painting/basicdrawing/images/qt-logo.png
Binary files differ
diff --git a/examples/widgets/painting/basicdrawing/main.cpp b/examples/widgets/painting/basicdrawing/main.cpp
new file mode 100644
index 0000000000..d80c9a2daa
--- /dev/null
+++ b/examples/widgets/painting/basicdrawing/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(basicdrawing);
+
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/painting/basicdrawing/renderarea.cpp b/examples/widgets/painting/basicdrawing/renderarea.cpp
new file mode 100644
index 0000000000..9fb4ab589d
--- /dev/null
+++ b/examples/widgets/painting/basicdrawing/renderarea.cpp
@@ -0,0 +1,207 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "renderarea.h"
+
+//! [0]
+RenderArea::RenderArea(QWidget *parent)
+ : QWidget(parent)
+{
+ shape = Polygon;
+ antialiased = false;
+ transformed = false;
+ pixmap.load(":/images/qt-logo.png");
+
+ setBackgroundRole(QPalette::Base);
+ setAutoFillBackground(true);
+}
+//! [0]
+
+//! [1]
+QSize RenderArea::minimumSizeHint() const
+{
+ return QSize(100, 100);
+}
+//! [1]
+
+//! [2]
+QSize RenderArea::sizeHint() const
+{
+ return QSize(400, 200);
+}
+//! [2]
+
+//! [3]
+void RenderArea::setShape(Shape shape)
+{
+ this->shape = shape;
+ update();
+}
+//! [3]
+
+//! [4]
+void RenderArea::setPen(const QPen &pen)
+{
+ this->pen = pen;
+ update();
+}
+//! [4]
+
+//! [5]
+void RenderArea::setBrush(const QBrush &brush)
+{
+ this->brush = brush;
+ update();
+}
+//! [5]
+
+//! [6]
+void RenderArea::setAntialiased(bool antialiased)
+{
+ this->antialiased = antialiased;
+ update();
+}
+//! [6]
+
+//! [7]
+void RenderArea::setTransformed(bool transformed)
+{
+ this->transformed = transformed;
+ update();
+}
+//! [7]
+
+//! [8]
+void RenderArea::paintEvent(QPaintEvent * /* event */)
+{
+ static const QPoint points[4] = {
+ QPoint(10, 80),
+ QPoint(20, 10),
+ QPoint(80, 30),
+ QPoint(90, 70)
+ };
+
+ QRect rect(10, 20, 80, 60);
+
+ QPainterPath path;
+ path.moveTo(20, 80);
+ path.lineTo(20, 30);
+ path.cubicTo(80, 0, 50, 50, 80, 80);
+
+ int startAngle = 20 * 16;
+ int arcLength = 120 * 16;
+//! [8]
+
+//! [9]
+ QPainter painter(this);
+ painter.setPen(pen);
+ painter.setBrush(brush);
+ if (antialiased)
+ painter.setRenderHint(QPainter::Antialiasing, true);
+//! [9]
+
+//! [10]
+ for (int x = 0; x < width(); x += 100) {
+ for (int y = 0; y < height(); y += 100) {
+ painter.save();
+ painter.translate(x, y);
+//! [10] //! [11]
+ if (transformed) {
+ painter.translate(50, 50);
+ painter.rotate(60.0);
+ painter.scale(0.6, 0.9);
+ painter.translate(-50, -50);
+ }
+//! [11]
+
+//! [12]
+ switch (shape) {
+ case Line:
+ painter.drawLine(rect.bottomLeft(), rect.topRight());
+ break;
+ case Points:
+ painter.drawPoints(points, 4);
+ break;
+ case Polyline:
+ painter.drawPolyline(points, 4);
+ break;
+ case Polygon:
+ painter.drawPolygon(points, 4);
+ break;
+ case Rect:
+ painter.drawRect(rect);
+ break;
+ case RoundedRect:
+ painter.drawRoundedRect(rect, 25, 25, Qt::RelativeSize);
+ break;
+ case Ellipse:
+ painter.drawEllipse(rect);
+ break;
+ case Arc:
+ painter.drawArc(rect, startAngle, arcLength);
+ break;
+ case Chord:
+ painter.drawChord(rect, startAngle, arcLength);
+ break;
+ case Pie:
+ painter.drawPie(rect, startAngle, arcLength);
+ break;
+ case Path:
+ painter.drawPath(path);
+ break;
+ case Text:
+ painter.drawText(rect, Qt::AlignCenter, tr("Qt by\nNokia"));
+ break;
+ case Pixmap:
+ painter.drawPixmap(10, 10, pixmap);
+ }
+//! [12] //! [13]
+ painter.restore();
+ }
+ }
+
+ painter.setRenderHint(QPainter::Antialiasing, false);
+ painter.setPen(palette().dark().color());
+ painter.setBrush(Qt::NoBrush);
+ painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
+}
+//! [13]
diff --git a/examples/widgets/painting/basicdrawing/renderarea.h b/examples/widgets/painting/basicdrawing/renderarea.h
new file mode 100644
index 0000000000..3ed9eb6321
--- /dev/null
+++ b/examples/widgets/painting/basicdrawing/renderarea.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RENDERAREA_H
+#define RENDERAREA_H
+
+#include <QBrush>
+#include <QPen>
+#include <QPixmap>
+#include <QWidget>
+
+//! [0]
+class RenderArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ enum Shape { Line, Points, Polyline, Polygon, Rect, RoundedRect, Ellipse, Arc,
+ Chord, Pie, Path, Text, Pixmap };
+
+ RenderArea(QWidget *parent = 0);
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+
+public slots:
+ void setShape(Shape shape);
+ void setPen(const QPen &pen);
+ void setBrush(const QBrush &brush);
+ void setAntialiased(bool antialiased);
+ void setTransformed(bool transformed);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ Shape shape;
+ QPen pen;
+ QBrush brush;
+ bool antialiased;
+ bool transformed;
+ QPixmap pixmap;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/painting/basicdrawing/window.cpp b/examples/widgets/painting/basicdrawing/window.cpp
new file mode 100644
index 0000000000..9579e40ae2
--- /dev/null
+++ b/examples/widgets/painting/basicdrawing/window.cpp
@@ -0,0 +1,259 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "renderarea.h"
+#include "window.h"
+
+//! [0]
+const int IdRole = Qt::UserRole;
+//! [0]
+
+//! [1]
+Window::Window()
+{
+ renderArea = new RenderArea;
+
+ shapeComboBox = new QComboBox;
+ shapeComboBox->addItem(tr("Polygon"), RenderArea::Polygon);
+ shapeComboBox->addItem(tr("Rectangle"), RenderArea::Rect);
+ shapeComboBox->addItem(tr("Rounded Rectangle"), RenderArea::RoundedRect);
+ shapeComboBox->addItem(tr("Ellipse"), RenderArea::Ellipse);
+ shapeComboBox->addItem(tr("Pie"), RenderArea::Pie);
+ shapeComboBox->addItem(tr("Chord"), RenderArea::Chord);
+ shapeComboBox->addItem(tr("Path"), RenderArea::Path);
+ shapeComboBox->addItem(tr("Line"), RenderArea::Line);
+ shapeComboBox->addItem(tr("Polyline"), RenderArea::Polyline);
+ shapeComboBox->addItem(tr("Arc"), RenderArea::Arc);
+ shapeComboBox->addItem(tr("Points"), RenderArea::Points);
+ shapeComboBox->addItem(tr("Text"), RenderArea::Text);
+ shapeComboBox->addItem(tr("Pixmap"), RenderArea::Pixmap);
+
+ shapeLabel = new QLabel(tr("&Shape:"));
+ shapeLabel->setBuddy(shapeComboBox);
+//! [1]
+
+//! [2]
+ penWidthSpinBox = new QSpinBox;
+ penWidthSpinBox->setRange(0, 20);
+ penWidthSpinBox->setSpecialValueText(tr("0 (cosmetic pen)"));
+
+ penWidthLabel = new QLabel(tr("Pen &Width:"));
+ penWidthLabel->setBuddy(penWidthSpinBox);
+//! [2]
+
+//! [3]
+ penStyleComboBox = new QComboBox;
+ penStyleComboBox->addItem(tr("Solid"), Qt::SolidLine);
+ penStyleComboBox->addItem(tr("Dash"), Qt::DashLine);
+ penStyleComboBox->addItem(tr("Dot"), Qt::DotLine);
+ penStyleComboBox->addItem(tr("Dash Dot"), Qt::DashDotLine);
+ penStyleComboBox->addItem(tr("Dash Dot Dot"), Qt::DashDotDotLine);
+ penStyleComboBox->addItem(tr("None"), Qt::NoPen);
+
+ penStyleLabel = new QLabel(tr("&Pen Style:"));
+ penStyleLabel->setBuddy(penStyleComboBox);
+
+ penCapComboBox = new QComboBox;
+ penCapComboBox->addItem(tr("Flat"), Qt::FlatCap);
+ penCapComboBox->addItem(tr("Square"), Qt::SquareCap);
+ penCapComboBox->addItem(tr("Round"), Qt::RoundCap);
+
+ penCapLabel = new QLabel(tr("Pen &Cap:"));
+ penCapLabel->setBuddy(penCapComboBox);
+
+ penJoinComboBox = new QComboBox;
+ penJoinComboBox->addItem(tr("Miter"), Qt::MiterJoin);
+ penJoinComboBox->addItem(tr("Bevel"), Qt::BevelJoin);
+ penJoinComboBox->addItem(tr("Round"), Qt::RoundJoin);
+
+ penJoinLabel = new QLabel(tr("Pen &Join:"));
+ penJoinLabel->setBuddy(penJoinComboBox);
+//! [3]
+
+//! [4]
+ brushStyleComboBox = new QComboBox;
+ brushStyleComboBox->addItem(tr("Linear Gradient"),
+ Qt::LinearGradientPattern);
+ brushStyleComboBox->addItem(tr("Radial Gradient"),
+ Qt::RadialGradientPattern);
+ brushStyleComboBox->addItem(tr("Conical Gradient"),
+ Qt::ConicalGradientPattern);
+ brushStyleComboBox->addItem(tr("Texture"), Qt::TexturePattern);
+ brushStyleComboBox->addItem(tr("Solid"), Qt::SolidPattern);
+ brushStyleComboBox->addItem(tr("Horizontal"), Qt::HorPattern);
+ brushStyleComboBox->addItem(tr("Vertical"), Qt::VerPattern);
+ brushStyleComboBox->addItem(tr("Cross"), Qt::CrossPattern);
+ brushStyleComboBox->addItem(tr("Backward Diagonal"), Qt::BDiagPattern);
+ brushStyleComboBox->addItem(tr("Forward Diagonal"), Qt::FDiagPattern);
+ brushStyleComboBox->addItem(tr("Diagonal Cross"), Qt::DiagCrossPattern);
+ brushStyleComboBox->addItem(tr("Dense 1"), Qt::Dense1Pattern);
+ brushStyleComboBox->addItem(tr("Dense 2"), Qt::Dense2Pattern);
+ brushStyleComboBox->addItem(tr("Dense 3"), Qt::Dense3Pattern);
+ brushStyleComboBox->addItem(tr("Dense 4"), Qt::Dense4Pattern);
+ brushStyleComboBox->addItem(tr("Dense 5"), Qt::Dense5Pattern);
+ brushStyleComboBox->addItem(tr("Dense 6"), Qt::Dense6Pattern);
+ brushStyleComboBox->addItem(tr("Dense 7"), Qt::Dense7Pattern);
+ brushStyleComboBox->addItem(tr("None"), Qt::NoBrush);
+
+ brushStyleLabel = new QLabel(tr("&Brush:"));
+ brushStyleLabel->setBuddy(brushStyleComboBox);
+//! [4]
+
+//! [5]
+ otherOptionsLabel = new QLabel(tr("Options:"));
+//! [5] //! [6]
+ antialiasingCheckBox = new QCheckBox(tr("&Antialiasing"));
+//! [6] //! [7]
+ transformationsCheckBox = new QCheckBox(tr("&Transformations"));
+//! [7]
+
+//! [8]
+ connect(shapeComboBox, SIGNAL(activated(int)),
+ this, SLOT(shapeChanged()));
+ connect(penWidthSpinBox, SIGNAL(valueChanged(int)),
+ this, SLOT(penChanged()));
+ connect(penStyleComboBox, SIGNAL(activated(int)),
+ this, SLOT(penChanged()));
+ connect(penCapComboBox, SIGNAL(activated(int)),
+ this, SLOT(penChanged()));
+ connect(penJoinComboBox, SIGNAL(activated(int)),
+ this, SLOT(penChanged()));
+ connect(brushStyleComboBox, SIGNAL(activated(int)),
+ this, SLOT(brushChanged()));
+ connect(antialiasingCheckBox, SIGNAL(toggled(bool)),
+ renderArea, SLOT(setAntialiased(bool)));
+ connect(transformationsCheckBox, SIGNAL(toggled(bool)),
+ renderArea, SLOT(setTransformed(bool)));
+//! [8]
+
+//! [9]
+ QGridLayout *mainLayout = new QGridLayout;
+//! [9] //! [10]
+ mainLayout->setColumnStretch(0, 1);
+ mainLayout->setColumnStretch(3, 1);
+ mainLayout->addWidget(renderArea, 0, 0, 1, 4);
+ mainLayout->addWidget(shapeLabel, 2, 0, Qt::AlignRight);
+ mainLayout->addWidget(shapeComboBox, 2, 1);
+ mainLayout->addWidget(penWidthLabel, 3, 0, Qt::AlignRight);
+ mainLayout->addWidget(penWidthSpinBox, 3, 1);
+ mainLayout->addWidget(penStyleLabel, 4, 0, Qt::AlignRight);
+ mainLayout->addWidget(penStyleComboBox, 4, 1);
+ mainLayout->addWidget(penCapLabel, 3, 2, Qt::AlignRight);
+ mainLayout->addWidget(penCapComboBox, 3, 3);
+ mainLayout->addWidget(penJoinLabel, 2, 2, Qt::AlignRight);
+ mainLayout->addWidget(penJoinComboBox, 2, 3);
+ mainLayout->addWidget(brushStyleLabel, 4, 2, Qt::AlignRight);
+ mainLayout->addWidget(brushStyleComboBox, 4, 3);
+ mainLayout->addWidget(otherOptionsLabel, 5, 0, Qt::AlignRight);
+ mainLayout->addWidget(antialiasingCheckBox, 5, 1, 1, 1, Qt::AlignRight);
+ mainLayout->addWidget(transformationsCheckBox, 5, 2, 1, 2, Qt::AlignRight);
+ setLayout(mainLayout);
+
+ shapeChanged();
+ penChanged();
+ brushChanged();
+ antialiasingCheckBox->setChecked(true);
+
+ setWindowTitle(tr("Basic Drawing"));
+}
+//! [10]
+
+//! [11]
+void Window::shapeChanged()
+{
+ RenderArea::Shape shape = RenderArea::Shape(shapeComboBox->itemData(
+ shapeComboBox->currentIndex(), IdRole).toInt());
+ renderArea->setShape(shape);
+}
+//! [11]
+
+//! [12]
+void Window::penChanged()
+{
+ int width = penWidthSpinBox->value();
+ Qt::PenStyle style = Qt::PenStyle(penStyleComboBox->itemData(
+ penStyleComboBox->currentIndex(), IdRole).toInt());
+ Qt::PenCapStyle cap = Qt::PenCapStyle(penCapComboBox->itemData(
+ penCapComboBox->currentIndex(), IdRole).toInt());
+ Qt::PenJoinStyle join = Qt::PenJoinStyle(penJoinComboBox->itemData(
+ penJoinComboBox->currentIndex(), IdRole).toInt());
+
+ renderArea->setPen(QPen(Qt::blue, width, style, cap, join));
+}
+//! [12]
+
+//! [13]
+void Window::brushChanged()
+{
+ Qt::BrushStyle style = Qt::BrushStyle(brushStyleComboBox->itemData(
+//! [13]
+ brushStyleComboBox->currentIndex(), IdRole).toInt());
+
+//! [14]
+ if (style == Qt::LinearGradientPattern) {
+ QLinearGradient linearGradient(0, 0, 100, 100);
+ linearGradient.setColorAt(0.0, Qt::white);
+ linearGradient.setColorAt(0.2, Qt::green);
+ linearGradient.setColorAt(1.0, Qt::black);
+ renderArea->setBrush(linearGradient);
+//! [14] //! [15]
+ } else if (style == Qt::RadialGradientPattern) {
+ QRadialGradient radialGradient(50, 50, 50, 70, 70);
+ radialGradient.setColorAt(0.0, Qt::white);
+ radialGradient.setColorAt(0.2, Qt::green);
+ radialGradient.setColorAt(1.0, Qt::black);
+ renderArea->setBrush(radialGradient);
+ } else if (style == Qt::ConicalGradientPattern) {
+ QConicalGradient conicalGradient(50, 50, 150);
+ conicalGradient.setColorAt(0.0, Qt::white);
+ conicalGradient.setColorAt(0.2, Qt::green);
+ conicalGradient.setColorAt(1.0, Qt::black);
+ renderArea->setBrush(conicalGradient);
+//! [15] //! [16]
+ } else if (style == Qt::TexturePattern) {
+ renderArea->setBrush(QBrush(QPixmap(":/images/brick.png")));
+//! [16] //! [17]
+ } else {
+ renderArea->setBrush(QBrush(Qt::green, style));
+ }
+}
+//! [17]
diff --git a/examples/widgets/painting/basicdrawing/window.h b/examples/widgets/painting/basicdrawing/window.h
new file mode 100644
index 0000000000..3f2c8fd561
--- /dev/null
+++ b/examples/widgets/painting/basicdrawing/window.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QComboBox;
+class QLabel;
+class QSpinBox;
+QT_END_NAMESPACE
+class RenderArea;
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private slots:
+ void shapeChanged();
+ void penChanged();
+ void brushChanged();
+
+private:
+ RenderArea *renderArea;
+ QLabel *shapeLabel;
+ QLabel *penWidthLabel;
+ QLabel *penStyleLabel;
+ QLabel *penCapLabel;
+ QLabel *penJoinLabel;
+ QLabel *brushStyleLabel;
+ QLabel *otherOptionsLabel;
+ QComboBox *shapeComboBox;
+ QSpinBox *penWidthSpinBox;
+ QComboBox *penStyleComboBox;
+ QComboBox *penCapComboBox;
+ QComboBox *penJoinComboBox;
+ QComboBox *brushStyleComboBox;
+ QCheckBox *antialiasingCheckBox;
+ QCheckBox *transformationsCheckBox;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp
new file mode 100644
index 0000000000..f46a658c17
--- /dev/null
+++ b/examples/widgets/painting/composition/composition.cpp
@@ -0,0 +1,522 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "composition.h"
+#include <QBoxLayout>
+#include <QRadioButton>
+#include <QTimer>
+#include <QDateTime>
+#include <QSlider>
+#include <QMouseEvent>
+#include <qmath.h>
+
+const int animationInterval = 15; // update every 16 ms = ~60FPS
+
+CompositionWidget::CompositionWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ CompositionRenderer *view = new CompositionRenderer(this);
+
+ QGroupBox *mainGroup = new QGroupBox(parent);
+ mainGroup->setTitle(tr("Composition Modes"));
+
+ QGroupBox *modesGroup = new QGroupBox(mainGroup);
+ modesGroup->setTitle(tr("Mode"));
+
+ rbClear = new QRadioButton(tr("Clear"), modesGroup);
+ connect(rbClear, SIGNAL(clicked()), view, SLOT(setClearMode()));
+ rbSource = new QRadioButton(tr("Source"), modesGroup);
+ connect(rbSource, SIGNAL(clicked()), view, SLOT(setSourceMode()));
+ rbDest = new QRadioButton(tr("Destination"), modesGroup);
+ connect(rbDest, SIGNAL(clicked()), view, SLOT(setDestMode()));
+ rbSourceOver = new QRadioButton(tr("Source Over"), modesGroup);
+ connect(rbSourceOver, SIGNAL(clicked()), view, SLOT(setSourceOverMode()));
+ rbDestOver = new QRadioButton(tr("Destination Over"), modesGroup);
+ connect(rbDestOver, SIGNAL(clicked()), view, SLOT(setDestOverMode()));
+ rbSourceIn = new QRadioButton(tr("Source In"), modesGroup);
+ connect(rbSourceIn, SIGNAL(clicked()), view, SLOT(setSourceInMode()));
+ rbDestIn = new QRadioButton(tr("Dest In"), modesGroup);
+ connect(rbDestIn, SIGNAL(clicked()), view, SLOT(setDestInMode()));
+ rbSourceOut = new QRadioButton(tr("Source Out"), modesGroup);
+ connect(rbSourceOut, SIGNAL(clicked()), view, SLOT(setSourceOutMode()));
+ rbDestOut = new QRadioButton(tr("Dest Out"), modesGroup);
+ connect(rbDestOut, SIGNAL(clicked()), view, SLOT(setDestOutMode()));
+ rbSourceAtop = new QRadioButton(tr("Source Atop"), modesGroup);
+ connect(rbSourceAtop, SIGNAL(clicked()), view, SLOT(setSourceAtopMode()));
+ rbDestAtop = new QRadioButton(tr("Dest Atop"), modesGroup);
+ connect(rbDestAtop, SIGNAL(clicked()), view, SLOT(setDestAtopMode()));
+ rbXor = new QRadioButton(tr("Xor"), modesGroup);
+ connect(rbXor, SIGNAL(clicked()), view, SLOT(setXorMode()));
+
+ rbPlus = new QRadioButton(tr("Plus"), modesGroup);
+ connect(rbPlus, SIGNAL(clicked()), view, SLOT(setPlusMode()));
+ rbMultiply = new QRadioButton(tr("Multiply"), modesGroup);
+ connect(rbMultiply, SIGNAL(clicked()), view, SLOT(setMultiplyMode()));
+ rbScreen = new QRadioButton(tr("Screen"), modesGroup);
+ connect(rbScreen, SIGNAL(clicked()), view, SLOT(setScreenMode()));
+ rbOverlay = new QRadioButton(tr("Overlay"), modesGroup);
+ connect(rbOverlay, SIGNAL(clicked()), view, SLOT(setOverlayMode()));
+ rbDarken = new QRadioButton(tr("Darken"), modesGroup);
+ connect(rbDarken, SIGNAL(clicked()), view, SLOT(setDarkenMode()));
+ rbLighten = new QRadioButton(tr("Lighten"), modesGroup);
+ connect(rbLighten, SIGNAL(clicked()), view, SLOT(setLightenMode()));
+ rbColorDodge = new QRadioButton(tr("Color Dodge"), modesGroup);
+ connect(rbColorDodge, SIGNAL(clicked()), view, SLOT(setColorDodgeMode()));
+ rbColorBurn = new QRadioButton(tr("Color Burn"), modesGroup);
+ connect(rbColorBurn, SIGNAL(clicked()), view, SLOT(setColorBurnMode()));
+ rbHardLight = new QRadioButton(tr("Hard Light"), modesGroup);
+ connect(rbHardLight, SIGNAL(clicked()), view, SLOT(setHardLightMode()));
+ rbSoftLight = new QRadioButton(tr("Soft Light"), modesGroup);
+ connect(rbSoftLight, SIGNAL(clicked()), view, SLOT(setSoftLightMode()));
+ rbDifference = new QRadioButton(tr("Difference"), modesGroup);
+ connect(rbDifference, SIGNAL(clicked()), view, SLOT(setDifferenceMode()));
+ rbExclusion = new QRadioButton(tr("Exclusion"), modesGroup);
+ connect(rbExclusion, SIGNAL(clicked()), view, SLOT(setExclusionMode()));
+
+ QGroupBox *circleColorGroup = new QGroupBox(mainGroup);
+ circleColorGroup->setTitle(tr("Circle color"));
+ QSlider *circleColorSlider = new QSlider(Qt::Horizontal, circleColorGroup);
+ circleColorSlider->setRange(0, 359);
+ circleColorSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ connect(circleColorSlider, SIGNAL(valueChanged(int)), view, SLOT(setCircleColor(int)));
+
+ QGroupBox *circleAlphaGroup = new QGroupBox(mainGroup);
+ circleAlphaGroup->setTitle(tr("Circle alpha"));
+ QSlider *circleAlphaSlider = new QSlider(Qt::Horizontal, circleAlphaGroup);
+ circleAlphaSlider->setRange(0, 255);
+ circleAlphaSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ connect(circleAlphaSlider, SIGNAL(valueChanged(int)), view, SLOT(setCircleAlpha(int)));
+
+ QPushButton *showSourceButton = new QPushButton(mainGroup);
+ showSourceButton->setText(tr("Show Source"));
+#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+ QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(true);
+ enableOpenGLButton->setChecked(view->usesOpenGL());
+
+ if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers())
+ enableOpenGLButton->hide();
+#endif
+ QPushButton *whatsThisButton = new QPushButton(mainGroup);
+ whatsThisButton->setText(tr("What's This?"));
+ whatsThisButton->setCheckable(true);
+
+ QPushButton *animateButton = new QPushButton(mainGroup);
+ animateButton->setText(tr("Animated"));
+ animateButton->setCheckable(true);
+ animateButton->setChecked(true);
+
+ QHBoxLayout *viewLayout = new QHBoxLayout(this);
+ viewLayout->addWidget(view);
+ viewLayout->addWidget(mainGroup);
+
+ QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
+ mainGroupLayout->addWidget(circleColorGroup);
+ mainGroupLayout->addWidget(circleAlphaGroup);
+ mainGroupLayout->addWidget(modesGroup);
+ mainGroupLayout->addStretch();
+ mainGroupLayout->addWidget(animateButton);
+ mainGroupLayout->addWidget(whatsThisButton);
+ mainGroupLayout->addWidget(showSourceButton);
+#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+ mainGroupLayout->addWidget(enableOpenGLButton);
+#endif
+
+ QGridLayout *modesLayout = new QGridLayout(modesGroup);
+ modesLayout->addWidget(rbClear, 0, 0);
+ modesLayout->addWidget(rbSource, 1, 0);
+ modesLayout->addWidget(rbDest, 2, 0);
+ modesLayout->addWidget(rbSourceOver, 3, 0);
+ modesLayout->addWidget(rbDestOver, 4, 0);
+ modesLayout->addWidget(rbSourceIn, 5, 0);
+ modesLayout->addWidget(rbDestIn, 6, 0);
+ modesLayout->addWidget(rbSourceOut, 7, 0);
+ modesLayout->addWidget(rbDestOut, 8, 0);
+ modesLayout->addWidget(rbSourceAtop, 9, 0);
+ modesLayout->addWidget(rbDestAtop, 10, 0);
+ modesLayout->addWidget(rbXor, 11, 0);
+
+ modesLayout->addWidget(rbPlus, 0, 1);
+ modesLayout->addWidget(rbMultiply, 1, 1);
+ modesLayout->addWidget(rbScreen, 2, 1);
+ modesLayout->addWidget(rbOverlay, 3, 1);
+ modesLayout->addWidget(rbDarken, 4, 1);
+ modesLayout->addWidget(rbLighten, 5, 1);
+ modesLayout->addWidget(rbColorDodge, 6, 1);
+ modesLayout->addWidget(rbColorBurn, 7, 1);
+ modesLayout->addWidget(rbHardLight, 8, 1);
+ modesLayout->addWidget(rbSoftLight, 9, 1);
+ modesLayout->addWidget(rbDifference, 10, 1);
+ modesLayout->addWidget(rbExclusion, 11, 1);
+
+
+ QVBoxLayout *circleColorLayout = new QVBoxLayout(circleColorGroup);
+ circleColorLayout->addWidget(circleColorSlider);
+
+ QVBoxLayout *circleAlphaLayout = new QVBoxLayout(circleAlphaGroup);
+ circleAlphaLayout->addWidget(circleAlphaSlider);
+
+ view->loadDescription(":res/composition/composition.html");
+ view->loadSourceFile(":res/composition/composition.cpp");
+
+ connect(whatsThisButton, SIGNAL(clicked(bool)), view, SLOT(setDescriptionEnabled(bool)));
+ connect(view, SIGNAL(descriptionEnabledChanged(bool)), whatsThisButton, SLOT(setChecked(bool)));
+ connect(showSourceButton, SIGNAL(clicked()), view, SLOT(showSource()));
+#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), view, SLOT(enableOpenGL(bool)));
+#endif
+ connect(animateButton, SIGNAL(toggled(bool)), view, SLOT(setAnimationEnabled(bool)));
+
+ circleColorSlider->setValue(270);
+ circleAlphaSlider->setValue(200);
+ rbSourceOut->animateClick();
+
+ setWindowTitle(tr("Composition Modes"));
+}
+
+
+void CompositionWidget::nextMode()
+{
+ /*
+ if (!m_animation_enabled)
+ return;
+ if (rbClear->isChecked()) rbSource->animateClick();
+ if (rbSource->isChecked()) rbDest->animateClick();
+ if (rbDest->isChecked()) rbSourceOver->animateClick();
+ if (rbSourceOver->isChecked()) rbDestOver->animateClick();
+ if (rbDestOver->isChecked()) rbSourceIn->animateClick();
+ if (rbSourceIn->isChecked()) rbDestIn->animateClick();
+ if (rbDestIn->isChecked()) rbSourceOut->animateClick();
+ if (rbSourceOut->isChecked()) rbDestOut->animateClick();
+ if (rbDestOut->isChecked()) rbSourceAtop->animateClick();
+ if (rbSourceAtop->isChecked()) rbDestAtop->animateClick();
+ if (rbDestAtop->isChecked()) rbXor->animateClick();
+ if (rbXor->isChecked()) rbClear->animateClick();
+ */
+}
+
+CompositionRenderer::CompositionRenderer(QWidget *parent)
+ : ArthurFrame(parent)
+{
+ m_animation_enabled = true;
+ m_animationTimer = startTimer(animationInterval);
+ m_image = QImage(":res/composition/flower.jpg");
+ m_image.setAlphaChannel(QImage(":res/composition/flower_alpha.jpg"));
+ m_circle_alpha = 127;
+ m_circle_hue = 255;
+ m_current_object = NoObject;
+ m_composition_mode = QPainter::CompositionMode_SourceOut;
+
+ m_circle_pos = QPoint(200, 100);
+
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+#ifdef QT_OPENGL_SUPPORT
+ m_pbuffer = 0;
+ m_pbuffer_size = 1024;
+#endif
+}
+
+QRectF rectangle_around(const QPointF &p, const QSizeF &size = QSize(250, 200))
+{
+ QRectF rect(p, size);
+ rect.translate(-size.width()/2, -size.height()/2);
+ return rect;
+}
+
+void CompositionRenderer::setAnimationEnabled(bool enabled)
+{
+ if (m_animation_enabled == enabled)
+ return;
+ m_animation_enabled = enabled;
+ if (enabled) {
+ Q_ASSERT(!m_animationTimer);
+ m_animationTimer = startTimer(animationInterval);
+ } else {
+ killTimer(m_animationTimer);
+ m_animationTimer = 0;
+ }
+}
+
+void CompositionRenderer::updateCirclePos()
+{
+ if (m_current_object != NoObject)
+ return;
+ QDateTime dt = QDateTime::currentDateTime();
+ qreal t = (dt.toTime_t() * 1000 + dt.time().msec()) / 1000.0;
+
+ qreal x = width() / qreal(2) + (qCos(t*8/11) + qSin(-t)) * width() / qreal(4);
+ qreal y = height() / qreal(2) + (qSin(t*6/7) + qCos(t * qreal(1.5))) * height() / qreal(4);
+
+ setCirclePos(QLineF(m_circle_pos, QPointF(x, y)).pointAt(0.02));
+}
+
+void CompositionRenderer::drawBase(QPainter &p)
+{
+ p.setPen(Qt::NoPen);
+
+ QLinearGradient rect_gradient(0, 0, 0, height());
+ rect_gradient.setColorAt(0, Qt::red);
+ rect_gradient.setColorAt(.17, Qt::yellow);
+ rect_gradient.setColorAt(.33, Qt::green);
+ rect_gradient.setColorAt(.50, Qt::cyan);
+ rect_gradient.setColorAt(.66, Qt::blue);
+ rect_gradient.setColorAt(.81, Qt::magenta);
+ rect_gradient.setColorAt(1, Qt::red);
+ p.setBrush(rect_gradient);
+ p.drawRect(width() / 2, 0, width() / 2, height());
+
+ QLinearGradient alpha_gradient(0, 0, width(), 0);
+ alpha_gradient.setColorAt(0, Qt::white);
+ alpha_gradient.setColorAt(0.2, Qt::white);
+ alpha_gradient.setColorAt(0.5, Qt::transparent);
+ alpha_gradient.setColorAt(0.8, Qt::white);
+ alpha_gradient.setColorAt(1, Qt::white);
+
+ p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
+ p.setBrush(alpha_gradient);
+ p.drawRect(0, 0, width(), height());
+
+ p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
+
+ p.setPen(Qt::NoPen);
+ p.setRenderHint(QPainter::SmoothPixmapTransform);
+ p.drawImage(rect(), m_image);
+}
+
+void CompositionRenderer::drawSource(QPainter &p)
+{
+ p.setPen(Qt::NoPen);
+ p.setRenderHint(QPainter::Antialiasing);
+ p.setCompositionMode(m_composition_mode);
+
+ QRectF circle_rect = rectangle_around(m_circle_pos);
+ QColor color = QColor::fromHsvF(m_circle_hue / 360.0, 1, 1, m_circle_alpha / 255.0);
+ QLinearGradient circle_gradient(circle_rect.topLeft(), circle_rect.bottomRight());
+ circle_gradient.setColorAt(0, color.light());
+ circle_gradient.setColorAt(0.5, color);
+ circle_gradient.setColorAt(1, color.dark());
+ p.setBrush(circle_gradient);
+
+ p.drawEllipse(circle_rect);
+}
+
+void CompositionRenderer::paint(QPainter *painter)
+{
+#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+ if (usesOpenGL()) {
+
+ int new_pbuf_size = m_pbuffer_size;
+ if (size().width() > m_pbuffer_size ||
+ size().height() > m_pbuffer_size)
+ new_pbuf_size *= 2;
+
+ if (size().width() < m_pbuffer_size/2 &&
+ size().height() < m_pbuffer_size/2)
+ new_pbuf_size /= 2;
+
+ if (!m_pbuffer || new_pbuf_size != m_pbuffer_size) {
+ if (m_pbuffer) {
+ m_pbuffer->deleteTexture(m_base_tex);
+ m_pbuffer->deleteTexture(m_compositing_tex);
+ delete m_pbuffer;
+ }
+
+ m_pbuffer = new QGLPixelBuffer(QSize(new_pbuf_size, new_pbuf_size), QGLFormat::defaultFormat(), glWidget());
+ m_pbuffer->makeCurrent();
+ m_base_tex = m_pbuffer->generateDynamicTexture();
+ m_compositing_tex = m_pbuffer->generateDynamicTexture();
+ m_pbuffer_size = new_pbuf_size;
+ }
+
+ if (size() != m_previous_size) {
+ m_previous_size = size();
+ QPainter p(m_pbuffer);
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ p.fillRect(QRect(0, 0, m_pbuffer->width(), m_pbuffer->height()), Qt::transparent);
+ drawBase(p);
+ p.end();
+ m_pbuffer->updateDynamicTexture(m_base_tex);
+ }
+
+ qreal x_fraction = width()/float(m_pbuffer->width());
+ qreal y_fraction = height()/float(m_pbuffer->height());
+
+ {
+ QPainter p(m_pbuffer);
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ p.fillRect(QRect(0, 0, m_pbuffer->width(), m_pbuffer->height()), Qt::transparent);
+
+ p.save(); // Needed when using the GL1 engine
+ p.beginNativePainting(); // Needed when using the GL2 engine
+
+ glBindTexture(GL_TEXTURE_2D, m_base_tex);
+ glEnable(GL_TEXTURE_2D);
+ glColor4f(1.,1.,1.,1.);
+
+ glBegin(GL_QUADS);
+ {
+ glTexCoord2f(0, 1.0);
+ glVertex2f(0, 0);
+
+ glTexCoord2f(x_fraction, 1.0);
+ glVertex2f(width(), 0);
+
+ glTexCoord2f(x_fraction, 1.0-y_fraction);
+ glVertex2f(width(), height());
+
+ glTexCoord2f(0, 1.0-y_fraction);
+ glVertex2f(0, height());
+ }
+ glEnd();
+
+ glDisable(GL_TEXTURE_2D);
+
+ p.endNativePainting(); // Needed when using the GL2 engine
+ p.restore(); // Needed when using the GL1 engine
+
+ drawSource(p);
+ p.end();
+ m_pbuffer->updateDynamicTexture(m_compositing_tex);
+ }
+
+ painter->beginNativePainting(); // Needed when using the GL2 engine
+ glWidget()->makeCurrent(); // Needed when using the GL1 engine
+ glBindTexture(GL_TEXTURE_2D, m_compositing_tex);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glColor4f(1.,1.,1.,1.);
+ glBegin(GL_QUADS);
+ {
+ glTexCoord2f(0, 1.0);
+ glVertex2f(0, 0);
+
+ glTexCoord2f(x_fraction, 1.0);
+ glVertex2f(width(), 0);
+
+ glTexCoord2f(x_fraction, 1.0-y_fraction);
+ glVertex2f(width(), height());
+
+ glTexCoord2f(0, 1.0-y_fraction);
+ glVertex2f(0, height());
+ }
+ glEnd();
+ glDisable(GL_TEXTURE_2D);
+ painter->endNativePainting(); // Needed when using the GL2 engine
+ } else
+#endif
+ {
+ // using a QImage
+ if (m_buffer.size() != size()) {
+ m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
+ m_base_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
+
+ m_base_buffer.fill(0);
+
+ QPainter p(&m_base_buffer);
+
+ drawBase(p);
+ }
+
+ memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.byteCount());
+
+ {
+ QPainter p(&m_buffer);
+ drawSource(p);
+ }
+
+ painter->drawImage(0, 0, m_buffer);
+ }
+}
+
+void CompositionRenderer::mousePressEvent(QMouseEvent *e)
+{
+ setDescriptionEnabled(false);
+
+ QRectF circle = rectangle_around(m_circle_pos);
+
+ if (circle.contains(e->pos())) {
+ m_current_object = Circle;
+ m_offset = circle.center() - e->pos();
+ } else {
+ m_current_object = NoObject;
+ }
+ if (m_animation_enabled) {
+ killTimer(m_animationTimer);
+ m_animationTimer = 0;
+ }
+}
+
+void CompositionRenderer::mouseMoveEvent(QMouseEvent *e)
+{
+ if (m_current_object == Circle) setCirclePos(e->pos() + m_offset);
+}
+
+void CompositionRenderer::mouseReleaseEvent(QMouseEvent *)
+{
+ m_current_object = NoObject;
+
+ if (m_animation_enabled) {
+ Q_ASSERT(!m_animationTimer);
+ m_animationTimer = startTimer(animationInterval);
+ }
+}
+
+void CompositionRenderer::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == m_animationTimer)
+ updateCirclePos();
+}
+
+void CompositionRenderer::setCirclePos(const QPointF &pos)
+{
+ const QRect oldRect = rectangle_around(m_circle_pos).toAlignedRect();
+ m_circle_pos = pos;
+ const QRect newRect = rectangle_around(m_circle_pos).toAlignedRect();
+#if defined(QT_OPENGL_SUPPORT) && !defined(QT_OPENGL_ES)
+ if (usesOpenGL())
+ update();
+ else
+#endif
+ update(oldRect | newRect);
+}
+
diff --git a/examples/widgets/painting/composition/composition.h b/examples/widgets/painting/composition/composition.h
new file mode 100644
index 0000000000..ebf278f145
--- /dev/null
+++ b/examples/widgets/painting/composition/composition.h
@@ -0,0 +1,187 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COMPOSITION_H
+#define COMPOSITION_H
+
+#include "arthurwidgets.h"
+
+#include <QPainter>
+#include <QEvent>
+
+QT_FORWARD_DECLARE_CLASS(QPushButton)
+QT_FORWARD_DECLARE_CLASS(QRadioButton)
+
+#ifdef QT_OPENGL_SUPPORT
+#include <QtOpenGL>
+#endif
+
+class CompositionWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ CompositionWidget(QWidget *parent);
+
+public slots:
+void nextMode();
+
+private:
+ bool m_cycle_enabled;
+
+ QRadioButton *rbClear;
+ QRadioButton *rbSource;
+ QRadioButton *rbDest;
+ QRadioButton *rbSourceOver;
+ QRadioButton *rbDestOver;
+ QRadioButton *rbSourceIn;
+ QRadioButton *rbDestIn;
+ QRadioButton *rbSourceOut;
+ QRadioButton *rbDestOut;
+ QRadioButton *rbSourceAtop;
+ QRadioButton *rbDestAtop;
+ QRadioButton *rbXor;
+
+ QRadioButton *rbPlus;
+ QRadioButton *rbMultiply;
+ QRadioButton *rbScreen;
+ QRadioButton *rbOverlay;
+ QRadioButton *rbDarken;
+ QRadioButton *rbLighten;
+ QRadioButton *rbColorDodge;
+ QRadioButton *rbColorBurn;
+ QRadioButton *rbHardLight;
+ QRadioButton *rbSoftLight;
+ QRadioButton *rbDifference;
+ QRadioButton *rbExclusion;
+};
+
+class CompositionRenderer : public ArthurFrame
+{
+ Q_OBJECT
+
+ enum ObjectType { NoObject, Circle, Rectangle, Image };
+
+ Q_PROPERTY(int circleColor READ circleColor WRITE setCircleColor)
+ Q_PROPERTY(int circleAlpha READ circleAlpha WRITE setCircleAlpha)
+ Q_PROPERTY(bool animation READ animationEnabled WRITE setAnimationEnabled)
+
+public:
+ CompositionRenderer(QWidget *parent);
+
+ void paint(QPainter *);
+
+ void setCirclePos(const QPointF &pos);
+
+ QSize sizeHint() const { return QSize(500, 400); }
+
+ bool animationEnabled() const { return m_animation_enabled; }
+ int circleColor() const { return m_circle_hue; }
+ int circleAlpha() const { return m_circle_alpha; }
+
+protected:
+ void mousePressEvent(QMouseEvent *);
+ void mouseMoveEvent(QMouseEvent *);
+ void mouseReleaseEvent(QMouseEvent *);
+ void timerEvent(QTimerEvent *);
+
+public slots:
+ void setClearMode() { m_composition_mode = QPainter::CompositionMode_Clear; update(); }
+ void setSourceMode() { m_composition_mode = QPainter::CompositionMode_Source; update(); }
+ void setDestMode() { m_composition_mode = QPainter::CompositionMode_Destination; update(); }
+ void setSourceOverMode() { m_composition_mode = QPainter::CompositionMode_SourceOver; update(); }
+ void setDestOverMode() { m_composition_mode = QPainter::CompositionMode_DestinationOver; update(); }
+ void setSourceInMode() { m_composition_mode = QPainter::CompositionMode_SourceIn; update(); }
+ void setDestInMode() { m_composition_mode = QPainter::CompositionMode_DestinationIn; update(); }
+ void setSourceOutMode() { m_composition_mode = QPainter::CompositionMode_SourceOut; update(); }
+ void setDestOutMode() { m_composition_mode = QPainter::CompositionMode_DestinationOut; update(); }
+ void setSourceAtopMode() { m_composition_mode = QPainter::CompositionMode_SourceAtop; update(); }
+ void setDestAtopMode() { m_composition_mode = QPainter::CompositionMode_DestinationAtop; update(); }
+ void setXorMode() { m_composition_mode = QPainter::CompositionMode_Xor; update(); }
+
+ void setPlusMode() { m_composition_mode = QPainter::CompositionMode_Plus; update(); }
+ void setMultiplyMode() { m_composition_mode = QPainter::CompositionMode_Multiply; update(); }
+ void setScreenMode() { m_composition_mode = QPainter::CompositionMode_Screen; update(); }
+ void setOverlayMode() { m_composition_mode = QPainter::CompositionMode_Overlay; update(); }
+ void setDarkenMode() { m_composition_mode = QPainter::CompositionMode_Darken; update(); }
+ void setLightenMode() { m_composition_mode = QPainter::CompositionMode_Lighten; update(); }
+ void setColorDodgeMode() { m_composition_mode = QPainter::CompositionMode_ColorDodge; update(); }
+ void setColorBurnMode() { m_composition_mode = QPainter::CompositionMode_ColorBurn; update(); }
+ void setHardLightMode() { m_composition_mode = QPainter::CompositionMode_HardLight; update(); }
+ void setSoftLightMode() { m_composition_mode = QPainter::CompositionMode_SoftLight; update(); }
+ void setDifferenceMode() { m_composition_mode = QPainter::CompositionMode_Difference; update(); }
+ void setExclusionMode() { m_composition_mode = QPainter::CompositionMode_Exclusion; update(); }
+
+ void setCircleAlpha(int alpha) { m_circle_alpha = alpha; update(); }
+ void setCircleColor(int hue) { m_circle_hue = hue; update(); }
+ void setAnimationEnabled(bool enabled);
+
+private:
+ void updateCirclePos();
+ void drawBase(QPainter &p);
+ void drawSource(QPainter &p);
+
+ QPainter::CompositionMode m_composition_mode;
+
+ QImage m_image;
+ QImage m_buffer;
+ QImage m_base_buffer;
+
+ int m_circle_alpha;
+ int m_circle_hue;
+
+ QPointF m_circle_pos;
+ QPointF m_offset;
+
+ ObjectType m_current_object;
+ bool m_animation_enabled;
+ int m_animationTimer;
+
+#ifdef QT_OPENGL_SUPPORT
+ QGLPixelBuffer *m_pbuffer;
+ GLuint m_base_tex;
+ GLuint m_compositing_tex;
+ int m_pbuffer_size; // width==height==size of pbuffer
+ QSize m_previous_size;
+#endif
+};
+
+#endif // COMPOSITION_H
diff --git a/examples/widgets/painting/composition/composition.html b/examples/widgets/painting/composition/composition.html
new file mode 100644
index 0000000000..82b8991e8f
--- /dev/null
+++ b/examples/widgets/painting/composition/composition.html
@@ -0,0 +1,23 @@
+<html>
+
+<h1>Example for composition modes</h1>
+
+<p>
+ This example shows some of the more advanced composition modes supported by Qt.
+</p>
+
+<p>
+ The two most common forms of composition are <b>Source</b> and <b>SourceOver</b>.
+ <b>Source</b> is used to draw opaque objects onto a paint device. In this mode,
+ each pixel in the source replaces the corresponding pixel in the destination.
+ In <b>SourceOver</b> composition mode, the source object is transparent and is
+ drawn on top of the destination.
+</p>
+
+<p>
+ In addition to these standard modes, Qt defines the complete set of composition
+ modes as defined by Thomas Porter and Tom Duff. See the <tt>QPainter</tt> documentation
+ for details.
+</p>
+
+</html>
diff --git a/examples/widgets/painting/composition/composition.pro b/examples/widgets/painting/composition/composition.pro
new file mode 100644
index 0000000000..eb63d0c47a
--- /dev/null
+++ b/examples/widgets/painting/composition/composition.pro
@@ -0,0 +1,29 @@
+SOURCES += main.cpp composition.cpp
+HEADERS += composition.h
+
+SHARED_FOLDER = ../shared
+
+include($$SHARED_FOLDER/shared.pri)
+
+RESOURCES += composition.qrc
+contains(QT_CONFIG, opengl) {
+ DEFINES += QT_OPENGL_SUPPORT
+ QT += opengl
+}
+QT += widgets
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/composition
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.png *.jpg *.pro *.html
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/composition
+INSTALLS += target sources
+
+
+win32-msvc* {
+ QMAKE_CXXFLAGS += /Zm500
+ QMAKE_CFLAGS += /Zm500
+}
+
+wince* {
+ DEPLOYMENT_PLUGIN += qjpeg
+}
diff --git a/examples/widgets/painting/composition/composition.qrc b/examples/widgets/painting/composition/composition.qrc
new file mode 100644
index 0000000000..d02c397ee8
--- /dev/null
+++ b/examples/widgets/painting/composition/composition.qrc
@@ -0,0 +1,8 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res/composition">
+ <file>composition.cpp</file>
+ <file>composition.html</file>
+ <file>flower.jpg</file>
+ <file>flower_alpha.jpg</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/painting/composition/flower.jpg b/examples/widgets/painting/composition/flower.jpg
new file mode 100644
index 0000000000..f8e022c98c
--- /dev/null
+++ b/examples/widgets/painting/composition/flower.jpg
Binary files differ
diff --git a/examples/widgets/painting/composition/flower_alpha.jpg b/examples/widgets/painting/composition/flower_alpha.jpg
new file mode 100644
index 0000000000..6a3c2a02ef
--- /dev/null
+++ b/examples/widgets/painting/composition/flower_alpha.jpg
Binary files differ
diff --git a/examples/widgets/painting/composition/main.cpp b/examples/widgets/painting/composition/main.cpp
new file mode 100644
index 0000000000..370069a33a
--- /dev/null
+++ b/examples/widgets/painting/composition/main.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "composition.h"
+
+#include <QApplication>
+#ifdef QT_OPENGL_SUPPORT
+#include <QtOpenGL>
+#endif
+
+int main(int argc, char **argv)
+{
+ // Q_INIT_RESOURCE(deform);
+
+ QApplication app(argc, argv);
+
+ CompositionWidget compWidget(0);
+ QStyle *arthurStyle = new ArthurStyle();
+ compWidget.setStyle(arthurStyle);
+
+ QList<QWidget *> widgets = compWidget.findChildren<QWidget *>();
+ foreach (QWidget *w, widgets)
+ w->setStyle(arthurStyle);
+ compWidget.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/painting/concentriccircles/circlewidget.cpp b/examples/widgets/painting/concentriccircles/circlewidget.cpp
new file mode 100644
index 0000000000..2691f20602
--- /dev/null
+++ b/examples/widgets/painting/concentriccircles/circlewidget.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "circlewidget.h"
+
+#include <stdlib.h>
+
+//! [0]
+CircleWidget::CircleWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ floatBased = false;
+ antialiased = false;
+ frameNo = 0;
+
+ setBackgroundRole(QPalette::Base);
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+}
+//! [0]
+
+//! [1]
+void CircleWidget::setFloatBased(bool floatBased)
+{
+ this->floatBased = floatBased;
+ update();
+}
+//! [1]
+
+//! [2]
+void CircleWidget::setAntialiased(bool antialiased)
+{
+ this->antialiased = antialiased;
+ update();
+}
+//! [2]
+
+//! [3]
+QSize CircleWidget::minimumSizeHint() const
+{
+ return QSize(50, 50);
+}
+//! [3]
+
+//! [4]
+QSize CircleWidget::sizeHint() const
+{
+ return QSize(180, 180);
+}
+//! [4]
+
+//! [5]
+void CircleWidget::nextAnimationFrame()
+{
+ ++frameNo;
+ update();
+}
+//! [5]
+
+//! [6]
+void CircleWidget::paintEvent(QPaintEvent *)
+{
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing, antialiased);
+ painter.translate(width() / 2, height() / 2);
+//! [6]
+
+//! [7]
+ for (int diameter = 0; diameter < 256; diameter += 9) {
+ int delta = abs((frameNo % 128) - diameter / 2);
+ int alpha = 255 - (delta * delta) / 4 - diameter;
+//! [7] //! [8]
+ if (alpha > 0) {
+ painter.setPen(QPen(QColor(0, diameter / 2, 127, alpha), 3));
+
+ if (floatBased) {
+ painter.drawEllipse(QRectF(-diameter / 2.0, -diameter / 2.0,
+ diameter, diameter));
+ } else {
+ painter.drawEllipse(QRect(-diameter / 2, -diameter / 2,
+ diameter, diameter));
+ }
+ }
+ }
+}
+//! [8]
diff --git a/examples/widgets/painting/concentriccircles/circlewidget.h b/examples/widgets/painting/concentriccircles/circlewidget.h
new file mode 100644
index 0000000000..c2d4de7092
--- /dev/null
+++ b/examples/widgets/painting/concentriccircles/circlewidget.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CIRCLEWIDGET_H
+#define CIRCLEWIDGET_H
+
+#include <QWidget>
+
+//! [0]
+class CircleWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ CircleWidget(QWidget *parent = 0);
+
+ void setFloatBased(bool floatBased);
+ void setAntialiased(bool antialiased);
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+
+public slots:
+ void nextAnimationFrame();
+
+protected:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ bool floatBased;
+ bool antialiased;
+ int frameNo;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/painting/concentriccircles/concentriccircles.desktop b/examples/widgets/painting/concentriccircles/concentriccircles.desktop
new file mode 100644
index 0000000000..7007f192bc
--- /dev/null
+++ b/examples/widgets/painting/concentriccircles/concentriccircles.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Concentric Circles
+Exec=/opt/usr/bin/concentriccircles
+Icon=concentriccircles
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/painting/concentriccircles/concentriccircles.pro b/examples/widgets/painting/concentriccircles/concentriccircles.pro
new file mode 100644
index 0000000000..0f87b991ed
--- /dev/null
+++ b/examples/widgets/painting/concentriccircles/concentriccircles.pro
@@ -0,0 +1,14 @@
+HEADERS = circlewidget.h \
+ window.h
+SOURCES = circlewidget.cpp \
+ main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/concentriccircles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS concentriccircles.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/concentriccircles
+INSTALLS += target sources
+
+QT += widgets
+
diff --git a/examples/widgets/spinboxes/main.cpp b/examples/widgets/painting/concentriccircles/main.cpp
index dcbf1c0449..dcbf1c0449 100644
--- a/examples/widgets/spinboxes/main.cpp
+++ b/examples/widgets/painting/concentriccircles/main.cpp
diff --git a/examples/widgets/painting/concentriccircles/window.cpp b/examples/widgets/painting/concentriccircles/window.cpp
new file mode 100644
index 0000000000..d946842029
--- /dev/null
+++ b/examples/widgets/painting/concentriccircles/window.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "circlewidget.h"
+#include "window.h"
+
+//! [0]
+Window::Window()
+{
+ aliasedLabel = createLabel(tr("Aliased"));
+ antialiasedLabel = createLabel(tr("Antialiased"));
+ intLabel = createLabel(tr("Int"));
+ floatLabel = createLabel(tr("Float"));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(aliasedLabel, 0, 1);
+ layout->addWidget(antialiasedLabel, 0, 2);
+ layout->addWidget(intLabel, 1, 0);
+ layout->addWidget(floatLabel, 2, 0);
+//! [0]
+
+//! [1]
+ QTimer *timer = new QTimer(this);
+
+ for (int i = 0; i < 2; ++i) {
+ for (int j = 0; j < 2; ++j) {
+ circleWidgets[i][j] = new CircleWidget;
+ circleWidgets[i][j]->setAntialiased(j != 0);
+ circleWidgets[i][j]->setFloatBased(i != 0);
+
+ connect(timer, SIGNAL(timeout()),
+ circleWidgets[i][j], SLOT(nextAnimationFrame()));
+
+ layout->addWidget(circleWidgets[i][j], i + 1, j + 1);
+ }
+ }
+//! [1] //! [2]
+ timer->start(100);
+ setLayout(layout);
+
+ setWindowTitle(tr("Concentric Circles"));
+}
+//! [2]
+
+//! [3]
+QLabel *Window::createLabel(const QString &text)
+{
+ QLabel *label = new QLabel(text);
+ label->setAlignment(Qt::AlignCenter);
+ label->setMargin(2);
+ label->setFrameStyle(QFrame::Box | QFrame::Sunken);
+ return label;
+}
+//! [3]
diff --git a/examples/widgets/painting/concentriccircles/window.h b/examples/widgets/painting/concentriccircles/window.h
new file mode 100644
index 0000000000..a066ddb702
--- /dev/null
+++ b/examples/widgets/painting/concentriccircles/window.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+QT_END_NAMESPACE
+class CircleWidget;
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private:
+ QLabel *createLabel(const QString &text);
+
+ QLabel *aliasedLabel;
+ QLabel *antialiasedLabel;
+ QLabel *intLabel;
+ QLabel *floatLabel;
+ CircleWidget *circleWidgets[2][2];
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/painting/deform/deform.pro b/examples/widgets/painting/deform/deform.pro
new file mode 100644
index 0000000000..527133e7e5
--- /dev/null
+++ b/examples/widgets/painting/deform/deform.pro
@@ -0,0 +1,20 @@
+SOURCES += main.cpp pathdeform.cpp
+HEADERS += pathdeform.h
+
+SHARED_FOLDER = ../shared
+
+include($$SHARED_FOLDER/shared.pri)
+
+RESOURCES += deform.qrc
+
+contains(QT_CONFIG, opengl) {
+ DEFINES += QT_OPENGL_SUPPORT
+ QT += opengl
+}
+QT += widgets
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/deform
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/deform
+INSTALLS += target sources
diff --git a/examples/widgets/painting/deform/deform.qrc b/examples/widgets/painting/deform/deform.qrc
new file mode 100644
index 0000000000..2e59ebcfc5
--- /dev/null
+++ b/examples/widgets/painting/deform/deform.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res/deform">
+ <file>pathdeform.cpp</file>
+ <file>pathdeform.html</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/painting/deform/main.cpp b/examples/widgets/painting/deform/main.cpp
new file mode 100644
index 0000000000..eeed9b8939
--- /dev/null
+++ b/examples/widgets/painting/deform/main.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "pathdeform.h"
+
+#include <QApplication>
+#include <QDebug>
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(deform);
+
+ QApplication app(argc, argv);
+
+ bool smallScreen = QApplication::arguments().contains("-small-screen");
+
+ PathDeformWidget deformWidget(0, smallScreen);
+
+ QStyle *arthurStyle = new ArthurStyle();
+ deformWidget.setStyle(arthurStyle);
+ QList<QWidget *> widgets = deformWidget.findChildren<QWidget *>();
+ foreach (QWidget *w, widgets)
+ w->setStyle(arthurStyle);
+
+ if (smallScreen)
+ deformWidget.showFullScreen();
+ else
+ deformWidget.show();
+
+#ifdef QT_KEYPAD_NAVIGATION
+ QApplication::setNavigationMode(Qt::NavigationModeCursorAuto);
+#endif
+ return app.exec();
+}
diff --git a/examples/widgets/painting/deform/pathdeform.cpp b/examples/widgets/painting/deform/pathdeform.cpp
new file mode 100644
index 0000000000..d5880fb786
--- /dev/null
+++ b/examples/widgets/painting/deform/pathdeform.cpp
@@ -0,0 +1,646 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "pathdeform.h"
+
+#include <QApplication>
+#include <QtDebug>
+#include <QMouseEvent>
+#include <QTimerEvent>
+#include <QLayout>
+#include <QLineEdit>
+#include <QPainter>
+#include <QSlider>
+#include <QLabel>
+#include <QDesktopWidget>
+#include <qmath.h>
+
+PathDeformControls::PathDeformControls(QWidget *parent, PathDeformRenderer* renderer, bool smallScreen)
+ : QWidget(parent)
+{
+ m_renderer = renderer;
+
+ if (smallScreen)
+ layoutForSmallScreen();
+ else
+ layoutForDesktop();
+}
+
+
+void PathDeformControls::layoutForDesktop()
+{
+ QGroupBox* mainGroup = new QGroupBox(this);
+ mainGroup->setTitle(tr("Controls"));
+
+ QGroupBox *radiusGroup = new QGroupBox(mainGroup);
+ radiusGroup->setTitle(tr("Lens Radius"));
+ QSlider *radiusSlider = new QSlider(Qt::Horizontal, radiusGroup);
+ radiusSlider->setRange(15, 150);
+ radiusSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+
+ QGroupBox *deformGroup = new QGroupBox(mainGroup);
+ deformGroup->setTitle(tr("Deformation"));
+ QSlider *deformSlider = new QSlider(Qt::Horizontal, deformGroup);
+ deformSlider->setRange(-100, 100);
+ deformSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+
+ QGroupBox *fontSizeGroup = new QGroupBox(mainGroup);
+ fontSizeGroup->setTitle(tr("Font Size"));
+ QSlider *fontSizeSlider = new QSlider(Qt::Horizontal, fontSizeGroup);
+ fontSizeSlider->setRange(16, 200);
+ fontSizeSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+
+ QGroupBox *textGroup = new QGroupBox(mainGroup);
+ textGroup->setTitle(tr("Text"));
+ QLineEdit *textInput = new QLineEdit(textGroup);
+
+ QPushButton *animateButton = new QPushButton(mainGroup);
+ animateButton->setText(tr("Animated"));
+ animateButton->setCheckable(true);
+
+ QPushButton *showSourceButton = new QPushButton(mainGroup);
+ showSourceButton->setText(tr("Show Source"));
+
+#ifdef QT_OPENGL_SUPPORT
+ QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(true);
+ enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
+ if (!QGLFormat::hasOpenGL())
+ enableOpenGLButton->hide();
+#endif
+
+ QPushButton *whatsThisButton = new QPushButton(mainGroup);
+ whatsThisButton->setText(tr("What's This?"));
+ whatsThisButton->setCheckable(true);
+
+
+ mainGroup->setFixedWidth(180);
+
+ QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
+ mainGroupLayout->addWidget(radiusGroup);
+ mainGroupLayout->addWidget(deformGroup);
+ mainGroupLayout->addWidget(fontSizeGroup);
+ mainGroupLayout->addWidget(textGroup);
+ mainGroupLayout->addWidget(animateButton);
+ mainGroupLayout->addStretch(1);
+#ifdef QT_OPENGL_SUPPORT
+ mainGroupLayout->addWidget(enableOpenGLButton);
+#endif
+ mainGroupLayout->addWidget(showSourceButton);
+ mainGroupLayout->addWidget(whatsThisButton);
+
+ QVBoxLayout *radiusGroupLayout = new QVBoxLayout(radiusGroup);
+ radiusGroupLayout->addWidget(radiusSlider);
+
+ QVBoxLayout *deformGroupLayout = new QVBoxLayout(deformGroup);
+ deformGroupLayout->addWidget(deformSlider);
+
+ QVBoxLayout *fontSizeGroupLayout = new QVBoxLayout(fontSizeGroup);
+ fontSizeGroupLayout->addWidget(fontSizeSlider);
+
+ QVBoxLayout *textGroupLayout = new QVBoxLayout(textGroup);
+ textGroupLayout->addWidget(textInput);
+
+ QVBoxLayout * mainLayout = new QVBoxLayout(this);
+ mainLayout->addWidget(mainGroup);
+ mainLayout->setMargin(0);
+
+ connect(radiusSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setRadius(int)));
+ connect(deformSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setIntensity(int)));
+ connect(fontSizeSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setFontSize(int)));
+ connect(animateButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setAnimated(bool)));
+#ifdef QT_OPENGL_SUPPORT
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));
+#endif
+
+ connect(textInput, SIGNAL(textChanged(QString)), m_renderer, SLOT(setText(QString)));
+ connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)),
+ whatsThisButton, SLOT(setChecked(bool)));
+ connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool)));
+ connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource()));
+
+ animateButton->animateClick();
+ deformSlider->setValue(80);
+ fontSizeSlider->setValue(120);
+ radiusSlider->setValue(100);
+ textInput->setText(tr("Qt"));
+}
+
+void PathDeformControls::layoutForSmallScreen()
+{
+ QGroupBox* mainGroup = new QGroupBox(this);
+ mainGroup->setTitle(tr("Controls"));
+
+ QLabel *radiusLabel = new QLabel(mainGroup);
+ radiusLabel->setText(tr("Lens Radius:"));
+ QSlider *radiusSlider = new QSlider(Qt::Horizontal, mainGroup);
+ radiusSlider->setRange(15, 150);
+ radiusSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+ QLabel *deformLabel = new QLabel(mainGroup);
+ deformLabel->setText(tr("Deformation:"));
+ QSlider *deformSlider = new QSlider(Qt::Horizontal, mainGroup);
+ deformSlider->setRange(-100, 100);
+ deformSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+ QLabel *fontSizeLabel = new QLabel(mainGroup);
+ fontSizeLabel->setText(tr("Font Size:"));
+ QSlider *fontSizeSlider = new QSlider(Qt::Horizontal, mainGroup);
+ fontSizeSlider->setRange(16, 200);
+ fontSizeSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+ QPushButton *animateButton = new QPushButton(tr("Animated"), mainGroup);
+ animateButton->setCheckable(true);
+
+#ifdef QT_OPENGL_SUPPORT
+ QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(mainGroup);
+ enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
+ if (!QGLFormat::hasOpenGL())
+ enableOpenGLButton->hide();
+#endif
+
+ QPushButton *quitButton = new QPushButton(tr("Quit"), mainGroup);
+ QPushButton *okButton = new QPushButton(tr("OK"), mainGroup);
+
+
+ QGridLayout *mainGroupLayout = new QGridLayout(mainGroup);
+ mainGroupLayout->setMargin(0);
+ mainGroupLayout->addWidget(radiusLabel, 0, 0, Qt::AlignRight);
+ mainGroupLayout->addWidget(radiusSlider, 0, 1);
+ mainGroupLayout->addWidget(deformLabel, 1, 0, Qt::AlignRight);
+ mainGroupLayout->addWidget(deformSlider, 1, 1);
+ mainGroupLayout->addWidget(fontSizeLabel, 2, 0, Qt::AlignRight);
+ mainGroupLayout->addWidget(fontSizeSlider, 2, 1);
+ mainGroupLayout->addWidget(animateButton, 3,0, 1,2);
+#ifdef QT_OPENGL_SUPPORT
+ mainGroupLayout->addWidget(enableOpenGLButton, 4,0, 1,2);
+#endif
+
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ mainLayout->addWidget(mainGroup);
+ mainLayout->addStretch(1);
+ mainLayout->addWidget(okButton);
+ mainLayout->addWidget(quitButton);
+
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(emitQuitSignal()));
+ connect(okButton, SIGNAL(clicked()), this, SLOT(emitOkSignal()));
+ connect(radiusSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setRadius(int)));
+ connect(deformSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setIntensity(int)));
+ connect(fontSizeSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setFontSize(int)));
+ connect(animateButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setAnimated(bool)));
+#ifdef QT_OPENGL_SUPPORT
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));
+#endif
+
+
+ animateButton->animateClick();
+ deformSlider->setValue(80);
+ fontSizeSlider->setValue(120);
+
+ QRect screen_size = QApplication::desktop()->screenGeometry();
+ radiusSlider->setValue(qMin(screen_size.width(), screen_size.height())/5);
+
+ m_renderer->setText(tr("Qt"));
+}
+
+
+void PathDeformControls::emitQuitSignal()
+{ emit quitPressed(); }
+
+void PathDeformControls::emitOkSignal()
+{ emit okPressed(); }
+
+
+PathDeformWidget::PathDeformWidget(QWidget *parent, bool smallScreen)
+ : QWidget(parent)
+{
+ setWindowTitle(tr("Vector Deformation"));
+
+ m_renderer = new PathDeformRenderer(this, smallScreen);
+ m_renderer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+
+ // Layouts
+ QHBoxLayout *mainLayout = new QHBoxLayout(this);
+ mainLayout->addWidget(m_renderer);
+
+ m_controls = new PathDeformControls(0, m_renderer, smallScreen);
+ m_controls->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
+
+ if (!smallScreen)
+ mainLayout->addWidget(m_controls);
+
+ m_renderer->loadSourceFile(":res/deform/pathdeform.cpp");
+ m_renderer->loadDescription(":res/deform/pathdeform.html");
+ m_renderer->setDescriptionEnabled(false);
+
+ connect(m_renderer, SIGNAL(clicked()), this, SLOT(showControls()));
+ connect(m_controls, SIGNAL(okPressed()), this, SLOT(hideControls()));
+ connect(m_controls, SIGNAL(quitPressed()), QApplication::instance(), SLOT(quit()));
+}
+
+
+void PathDeformWidget::showControls()
+{
+ m_controls->showFullScreen();
+}
+
+void PathDeformWidget::hideControls()
+{
+ m_controls->hide();
+}
+
+void PathDeformWidget::setStyle( QStyle * style )
+{
+ QWidget::setStyle(style);
+ if (m_controls != 0)
+ {
+ m_controls->setStyle(style);
+
+ QList<QWidget *> widgets = m_controls->findChildren<QWidget *>();
+ foreach (QWidget *w, widgets)
+ w->setStyle(style);
+ }
+}
+
+static inline QRect circle_bounds(const QPointF &center, qreal radius, qreal compensation)
+{
+ return QRect(qRound(center.x() - radius - compensation),
+ qRound(center.y() - radius - compensation),
+ qRound((radius + compensation) * 2),
+ qRound((radius + compensation) * 2));
+
+}
+
+const int LENS_EXTENT = 10;
+
+PathDeformRenderer::PathDeformRenderer(QWidget *widget, bool smallScreen)
+ : ArthurFrame(widget)
+{
+ m_radius = 100;
+ m_pos = QPointF(m_radius, m_radius);
+ m_direction = QPointF(1, 1);
+ m_fontSize = 24;
+ m_animated = true;
+ m_repaintTimer.start(25, this);
+ m_repaintTracker.start();
+ m_intensity = 100;
+ m_smallScreen = smallScreen;
+
+// m_fpsTimer.start(1000, this);
+// m_fpsCounter = 0;
+
+ generateLensPixmap();
+}
+
+void PathDeformRenderer::setText(const QString &text)
+{
+ m_text = text;
+
+ QFont f("times new roman,utopia");
+ f.setStyleStrategy(QFont::ForceOutline);
+ f.setPointSize(m_fontSize);
+ f.setStyleHint(QFont::Times);
+
+ QFontMetrics fm(f);
+
+ m_paths.clear();
+ m_pathBounds = QRect();
+
+ QPointF advance(0, 0);
+
+ bool do_quick = true;
+ for (int i=0; i<text.size(); ++i) {
+ if (text.at(i).unicode() >= 0x4ff && text.at(i).unicode() <= 0x1e00) {
+ do_quick = false;
+ break;
+ }
+ }
+
+ if (do_quick) {
+ for (int i=0; i<text.size(); ++i) {
+ QPainterPath path;
+ path.addText(advance, f, text.mid(i, 1));
+ m_pathBounds |= path.boundingRect();
+ m_paths << path;
+ advance += QPointF(fm.width(text.mid(i, 1)), 0);
+ }
+ } else {
+ QPainterPath path;
+ path.addText(advance, f, text);
+ m_pathBounds |= path.boundingRect();
+ m_paths << path;
+ }
+
+ for (int i=0; i<m_paths.size(); ++i)
+ m_paths[i] = m_paths[i] * QMatrix(1, 0, 0, 1, -m_pathBounds.x(), -m_pathBounds.y());
+
+ update();
+}
+
+
+void PathDeformRenderer::generateLensPixmap()
+{
+ qreal rad = m_radius + LENS_EXTENT;
+
+ QRect bounds = circle_bounds(QPointF(), rad, 0);
+
+ QPainter painter;
+
+ if (preferImage()) {
+ m_lens_image = QImage(bounds.size(), QImage::Format_ARGB32_Premultiplied);
+ m_lens_image.fill(0);
+ painter.begin(&m_lens_image);
+ } else {
+ m_lens_pixmap = QPixmap(bounds.size());
+ m_lens_pixmap.fill(Qt::transparent);
+ painter.begin(&m_lens_pixmap);
+ }
+
+ QRadialGradient gr(rad, rad, rad, 3 * rad / 5, 3 * rad / 5);
+ gr.setColorAt(0.0, QColor(255, 255, 255, 191));
+ gr.setColorAt(0.2, QColor(255, 255, 127, 191));
+ gr.setColorAt(0.9, QColor(150, 150, 200, 63));
+ gr.setColorAt(0.95, QColor(0, 0, 0, 127));
+ gr.setColorAt(1, QColor(0, 0, 0, 0));
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setBrush(gr);
+ painter.setPen(Qt::NoPen);
+ painter.drawEllipse(0, 0, bounds.width(), bounds.height());
+}
+
+
+void PathDeformRenderer::setAnimated(bool animated)
+{
+ m_animated = animated;
+
+ if (m_animated) {
+// m_fpsTimer.start(1000, this);
+// m_fpsCounter = 0;
+ m_repaintTimer.start(25, this);
+ m_repaintTracker.start();
+ } else {
+// m_fpsTimer.stop();
+ m_repaintTimer.stop();
+ }
+}
+
+void PathDeformRenderer::timerEvent(QTimerEvent *e)
+{
+
+ if (e->timerId() == m_repaintTimer.timerId()) {
+
+ if (QLineF(QPointF(0,0), m_direction).length() > 1)
+ m_direction *= 0.995;
+ qreal time = m_repaintTracker.restart();
+
+ QRect rectBefore = circle_bounds(m_pos, m_radius, m_fontSize);
+
+ qreal dx = m_direction.x();
+ qreal dy = m_direction.y();
+ if (time > 0) {
+ dx = dx * time * .1;
+ dy = dy * time * .1;
+ }
+
+ m_pos += QPointF(dx, dy);
+
+
+
+ if (m_pos.x() - m_radius < 0) {
+ m_direction.setX(-m_direction.x());
+ m_pos.setX(m_radius);
+ } else if (m_pos.x() + m_radius > width()) {
+ m_direction.setX(-m_direction.x());
+ m_pos.setX(width() - m_radius);
+ }
+
+ if (m_pos.y() - m_radius < 0) {
+ m_direction.setY(-m_direction.y());
+ m_pos.setY(m_radius);
+ } else if (m_pos.y() + m_radius > height()) {
+ m_direction.setY(-m_direction.y());
+ m_pos.setY(height() - m_radius);
+ }
+
+#ifdef QT_OPENGL_SUPPORT
+ if (usesOpenGL()) {
+ update();
+ } else
+#endif
+ {
+ QRect rectAfter = circle_bounds(m_pos, m_radius, m_fontSize);
+ update(rectAfter | rectBefore);
+ }
+ }
+// else if (e->timerId() == m_fpsTimer.timerId()) {
+// printf("fps: %d\n", m_fpsCounter);
+// emit frameRate(m_fpsCounter);
+// m_fpsCounter = 0;
+
+// }
+}
+
+void PathDeformRenderer::mousePressEvent(QMouseEvent *e)
+{
+ setDescriptionEnabled(false);
+
+ m_repaintTimer.stop();
+ m_offset = QPointF();
+ if (QLineF(m_pos, e->pos()).length() <= m_radius)
+ m_offset = m_pos - e->pos();
+
+ m_mousePress = e->pos();
+
+ // If we're not running in small screen mode, always assume we're dragging
+ m_mouseDrag = !m_smallScreen;
+
+ mouseMoveEvent(e);
+}
+
+void PathDeformRenderer::mouseReleaseEvent(QMouseEvent *e)
+{
+ if (e->buttons() == Qt::NoButton && m_animated) {
+ m_repaintTimer.start(10, this);
+ m_repaintTracker.start();
+ }
+
+ if (!m_mouseDrag && m_smallScreen)
+ emit clicked();
+}
+
+void PathDeformRenderer::mouseMoveEvent(QMouseEvent *e)
+{
+ if (!m_mouseDrag && (QLineF(m_mousePress, e->pos()).length() > 25.0) )
+ m_mouseDrag = true;
+
+ if (m_mouseDrag) {
+ QRect rectBefore = circle_bounds(m_pos, m_radius, m_fontSize);
+ if (e->type() == QEvent::MouseMove) {
+ QLineF line(m_pos, e->pos() + m_offset);
+ line.setLength(line.length() * .1);
+ QPointF dir(line.dx(), line.dy());
+ m_direction = (m_direction + dir) / 2;
+ }
+ m_pos = e->pos() + m_offset;
+#ifdef QT_OPENGL_SUPPORT
+ if (usesOpenGL()) {
+ update();
+ } else
+#endif
+ {
+ QRect rectAfter = circle_bounds(m_pos, m_radius, m_fontSize);
+ update(rectBefore | rectAfter);
+ }
+ }
+}
+
+QPainterPath PathDeformRenderer::lensDeform(const QPainterPath &source, const QPointF &offset)
+{
+ QPainterPath path;
+ path.addPath(source);
+
+ qreal flip = m_intensity / qreal(100);
+
+ for (int i=0; i<path.elementCount(); ++i) {
+ const QPainterPath::Element &e = path.elementAt(i);
+
+ qreal x = e.x + offset.x();
+ qreal y = e.y + offset.y();
+
+ qreal dx = x - m_pos.x();
+ qreal dy = y - m_pos.y();
+ qreal len = m_radius - qSqrt(dx * dx + dy * dy);
+
+ if (len > 0) {
+ path.setElementPositionAt(i,
+ x + flip * dx * len / m_radius,
+ y + flip * dy * len / m_radius);
+ } else {
+ path.setElementPositionAt(i, x, y);
+ }
+
+ }
+
+ return path;
+}
+
+
+void PathDeformRenderer::paint(QPainter *painter)
+{
+ int pad_x = 5;
+ int pad_y = 5;
+
+ int skip_x = qRound(m_pathBounds.width() + pad_x + m_fontSize/2);
+ int skip_y = qRound(m_pathBounds.height() + pad_y);
+
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(Qt::black);
+
+ QRectF clip(painter->clipPath().boundingRect());
+
+ int overlap = pad_x / 2;
+
+ for (int start_y=0; start_y < height(); start_y += skip_y) {
+
+ if (start_y > clip.bottom())
+ break;
+
+ int start_x = -overlap;
+ for (; start_x < width(); start_x += skip_x) {
+
+ if (start_y + skip_y >= clip.top() &&
+ start_x + skip_x >= clip.left() &&
+ start_x <= clip.right()) {
+ for (int i=0; i<m_paths.size(); ++i) {
+ QPainterPath path = lensDeform(m_paths[i], QPointF(start_x, start_y));
+ painter->drawPath(path);
+ }
+ }
+ }
+ overlap = skip_x - (start_x - width());
+
+ }
+
+ if (preferImage()) {
+ painter->drawImage(m_pos - QPointF(m_radius + LENS_EXTENT, m_radius + LENS_EXTENT),
+ m_lens_image);
+ } else {
+ painter->drawPixmap(m_pos - QPointF(m_radius + LENS_EXTENT, m_radius + LENS_EXTENT),
+ m_lens_pixmap);
+ }
+}
+
+
+
+void PathDeformRenderer::setRadius(int radius)
+{
+ qreal max = qMax(m_radius, (qreal)radius);
+ m_radius = radius;
+ generateLensPixmap();
+ if (!m_animated || m_radius < max) {
+#ifdef QT_OPENGL_SUPPORT
+ if (usesOpenGL()) {
+ update();
+ } else
+#endif
+ {
+ update(circle_bounds(m_pos, max, m_fontSize));
+ }
+ }
+}
+
+void PathDeformRenderer::setIntensity(int intensity)
+{
+ m_intensity = intensity;
+ if (!m_animated) {
+#ifdef QT_OPENGL_SUPPORT
+ if (usesOpenGL()) {
+ update();
+ } else
+#endif
+ {
+ update(circle_bounds(m_pos, m_radius, m_fontSize));
+ }
+ }
+}
diff --git a/examples/widgets/painting/deform/pathdeform.h b/examples/widgets/painting/deform/pathdeform.h
new file mode 100644
index 0000000000..6f0d647f4e
--- /dev/null
+++ b/examples/widgets/painting/deform/pathdeform.h
@@ -0,0 +1,153 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PATHDEFORM_H
+#define PATHDEFORM_H
+
+#include "arthurwidgets.h"
+
+#include <QPainterPath>
+#include <QBasicTimer>
+#include <QDateTime>
+
+class PathDeformRenderer : public ArthurFrame
+{
+ Q_OBJECT
+ Q_PROPERTY(bool animated READ animated WRITE setAnimated)
+ Q_PROPERTY(int radius READ radius WRITE setRadius)
+ Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize)
+ Q_PROPERTY(int intensity READ intensity WRITE setIntensity)
+ Q_PROPERTY(QString text READ text WRITE setText)
+
+public:
+ PathDeformRenderer(QWidget *widget, bool smallScreen = false);
+
+ void paint(QPainter *painter);
+
+ void mousePressEvent(QMouseEvent *e);
+ void mouseReleaseEvent(QMouseEvent *e);
+ void mouseMoveEvent(QMouseEvent *e);
+ void timerEvent(QTimerEvent *e);
+
+ QSize sizeHint() const { return QSize(600, 500); }
+
+ bool animated() const { return m_animated; }
+ int radius() const { return int(m_radius); }
+ int fontSize() const { return m_fontSize; }
+ int intensity() const { return int(m_intensity); }
+ QString text() const { return m_text; }
+
+public slots:
+ void setRadius(int radius);
+ void setFontSize(int fontSize) { m_fontSize = fontSize; setText(m_text); }
+ void setText(const QString &text);
+ void setIntensity(int intensity);
+
+ void setAnimated(bool animated);
+
+signals:
+ void clicked();
+// void frameRate(double fps);
+
+private:
+ void generateLensPixmap();
+ QPainterPath lensDeform(const QPainterPath &source, const QPointF &offset);
+
+ QBasicTimer m_repaintTimer;
+// QBasicTimer m_fpsTimer;
+// int m_fpsCounter;
+ QTime m_repaintTracker;
+
+ QVector<QPainterPath> m_paths;
+ QVector<QPointF> m_advances;
+ QRectF m_pathBounds;
+ QString m_text;
+
+ QPixmap m_lens_pixmap;
+ QImage m_lens_image;
+
+ int m_fontSize;
+ bool m_animated;
+
+ qreal m_intensity;
+ qreal m_radius;
+ QPointF m_pos;
+ QPointF m_offset;
+ QPointF m_direction;
+ QPointF m_mousePress;
+ bool m_mouseDrag;
+ bool m_smallScreen;
+};
+
+class PathDeformControls : public QWidget
+{
+ Q_OBJECT
+public:
+ PathDeformControls(QWidget *parent, PathDeformRenderer* renderer, bool smallScreen);
+signals:
+ void okPressed();
+ void quitPressed();
+private:
+ PathDeformRenderer* m_renderer;
+ void layoutForDesktop();
+ void layoutForSmallScreen();
+private slots:
+ void emitQuitSignal();
+ void emitOkSignal();
+};
+
+class PathDeformWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ PathDeformWidget(QWidget *parent, bool smallScreen);
+ void setStyle ( QStyle * style );
+
+private:
+ PathDeformRenderer *m_renderer;
+ PathDeformControls *m_controls;
+
+private slots:
+ void showControls();
+ void hideControls();
+};
+
+#endif // PATHDEFORM_H
diff --git a/examples/widgets/painting/deform/pathdeform.html b/examples/widgets/painting/deform/pathdeform.html
new file mode 100644
index 0000000000..b3f63a8e0a
--- /dev/null
+++ b/examples/widgets/painting/deform/pathdeform.html
@@ -0,0 +1,24 @@
+<html>
+<center>
+<h2>Vector deformation</h2>
+</center>
+
+<p>This demo shows how to use advanced vector techniques to draw text
+using a <code>QPainterPath</code>.</p>
+
+<p>We define a vector deformation field in the shape of a lens and apply
+this to all points in a path. This means that what is rendered on
+screen is not pixel manipulation, but modified vector representations of
+the glyphs themselves. This is visible from the high quality of the
+antialiased edges for the deformed glyphs.</p>
+
+<p>To get a fairly complex path we allow the user to type in text and
+convert the text to paths. This is done using the
+<code>QPainterPath::addText()</code> function.</p>
+
+<p>The lens is drawn using a single call to <code>drawEllipse()</code>, using
+a <code>QRadialGradient</code> to fill it with a specialized color table,
+giving the effect of the Sun's reflection and a drop shadow. The lens
+is cached as a pixmap for better performance.</p>
+
+</html>
diff --git a/examples/widgets/painting/fontsampler/fontsampler.desktop b/examples/widgets/painting/fontsampler/fontsampler.desktop
new file mode 100644
index 0000000000..8582891fcf
--- /dev/null
+++ b/examples/widgets/painting/fontsampler/fontsampler.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Font Sampler
+Exec=/opt/usr/bin/fontsampler
+Icon=fontsampler
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/painting/fontsampler/fontsampler.pro b/examples/widgets/painting/fontsampler/fontsampler.pro
new file mode 100644
index 0000000000..b918c51837
--- /dev/null
+++ b/examples/widgets/painting/fontsampler/fontsampler.pro
@@ -0,0 +1,13 @@
+FORMS = mainwindowbase.ui
+HEADERS = mainwindow.h
+SOURCES = main.cpp \
+ mainwindow.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/fontsampler
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS fontsampler.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/fontsampler
+INSTALLS += target sources
+
+QT += widgets
+!isEmpty(QT.printsupport.name): QT += printsupport
diff --git a/examples/widgets/scribble/main.cpp b/examples/widgets/painting/fontsampler/main.cpp
index 09a923477c..09a923477c 100644
--- a/examples/widgets/scribble/main.cpp
+++ b/examples/widgets/painting/fontsampler/main.cpp
diff --git a/examples/widgets/painting/fontsampler/mainwindow.cpp b/examples/widgets/painting/fontsampler/mainwindow.cpp
new file mode 100644
index 0000000000..ae45613abf
--- /dev/null
+++ b/examples/widgets/painting/fontsampler/mainwindow.cpp
@@ -0,0 +1,380 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#ifndef QT_NO_PRINTER
+#include <QPrinter>
+#include <QPrintDialog>
+#include <QPrintPreviewDialog>
+#endif
+
+#include "mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ setupUi(this);
+
+
+ sampleSizes << 32 << 24 << 16 << 14 << 12 << 8 << 4 << 2 << 1;
+ markedCount = 0;
+ setupFontTree();
+
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(fontTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
+ this, SLOT(showFont(QTreeWidgetItem*)));
+ connect(fontTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
+ this, SLOT(updateStyles(QTreeWidgetItem*,int)));
+
+ fontTree->setItemSelected(fontTree->topLevelItem(0), true);
+ showFont(fontTree->topLevelItem(0));
+}
+
+void MainWindow::setupFontTree()
+{
+ QFontDatabase database;
+ fontTree->setColumnCount(1);
+ fontTree->setHeaderLabels(QStringList() << tr("Font"));
+
+ foreach (QString family, database.families()) {
+ const QStringList styles = database.styles(family);
+ if (styles.isEmpty())
+ continue;
+
+ QTreeWidgetItem *familyItem = new QTreeWidgetItem(fontTree);
+ familyItem->setText(0, family);
+ familyItem->setCheckState(0, Qt::Unchecked);
+
+ foreach (QString style, styles) {
+ QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem);
+ styleItem->setText(0, style);
+ styleItem->setCheckState(0, Qt::Unchecked);
+ styleItem->setData(0, Qt::UserRole,
+ QVariant(database.weight(family, style)));
+ styleItem->setData(0, Qt::UserRole + 1,
+ QVariant(database.italic(family, style)));
+ }
+ }
+}
+
+void MainWindow::on_clearAction_triggered()
+{
+ QTreeWidgetItem *currentItem = fontTree->currentItem();
+ foreach (QTreeWidgetItem *item, fontTree->selectedItems())
+ fontTree->setItemSelected(item, false);
+ fontTree->setItemSelected(currentItem, true);
+}
+
+void MainWindow::on_markAction_triggered()
+{
+ markUnmarkFonts(Qt::Checked);
+}
+
+void MainWindow::on_unmarkAction_triggered()
+{
+ markUnmarkFonts(Qt::Unchecked);
+}
+
+void MainWindow::markUnmarkFonts(Qt::CheckState state)
+{
+ QList<QTreeWidgetItem *> items = fontTree->selectedItems();
+ foreach (QTreeWidgetItem *item, items) {
+ if (item->checkState(0) != state)
+ item->setCheckState(0, state);
+ }
+}
+
+void MainWindow::showFont(QTreeWidgetItem *item)
+{
+ if (!item)
+ return;
+
+ QString family;
+ QString style;
+ int weight;
+ bool italic;
+
+ if (item->parent()) {
+ family = item->parent()->text(0);
+ style = item->text(0);
+ weight = item->data(0, Qt::UserRole).toInt();
+ italic = item->data(0, Qt::UserRole + 1).toBool();
+ } else {
+ family = item->text(0);
+ style = item->child(0)->text(0);
+ weight = item->child(0)->data(0, Qt::UserRole).toInt();
+ italic = item->child(0)->data(0, Qt::UserRole + 1).toBool();
+ }
+
+ QString oldText = textEdit->toPlainText().trimmed();
+ bool modified = textEdit->document()->isModified();
+ textEdit->clear();
+ textEdit->document()->setDefaultFont(QFont(family, 32, weight, italic));
+
+ QTextCursor cursor = textEdit->textCursor();
+ QTextBlockFormat blockFormat;
+ blockFormat.setAlignment(Qt::AlignCenter);
+ cursor.insertBlock(blockFormat);
+
+ if (modified)
+ cursor.insertText(QString(oldText));
+ else
+ cursor.insertText(QString("%1 %2").arg(family).arg(style));
+
+ textEdit->document()->setModified(modified);
+}
+
+void MainWindow::updateStyles(QTreeWidgetItem *item, int column)
+{
+ if (!item || column != 0)
+ return;
+
+ Qt::CheckState state = item->checkState(0);
+ QTreeWidgetItem *parent = item->parent();
+
+ if (parent) {
+
+ // Only count style items.
+ if (state == Qt::Checked)
+ ++markedCount;
+ else
+ --markedCount;
+
+ if (state == Qt::Checked &&
+ parent->checkState(0) == Qt::Unchecked) {
+ // Mark parent items when child items are checked.
+ parent->setCheckState(0, Qt::Checked);
+
+ } else if (state == Qt::Unchecked &&
+ parent->checkState(0) == Qt::Checked) {
+
+ bool marked = false;
+ for (int row = 0; row < parent->childCount(); ++row) {
+ if (parent->child(row)->checkState(0) == Qt::Checked) {
+ marked = true;
+ break;
+ }
+ }
+ // Unmark parent items when all child items are unchecked.
+ if (!marked)
+ parent->setCheckState(0, Qt::Unchecked);
+ }
+ } else {
+ int row;
+ int number = 0;
+ for (row = 0; row < item->childCount(); ++row) {
+ if (item->child(row)->checkState(0) == Qt::Checked)
+ ++number;
+ }
+
+ // Mark/unmark all child items when marking/unmarking top-level
+ // items.
+ if (state == Qt::Checked && number == 0) {
+ for (row = 0; row < item->childCount(); ++row) {
+ if (item->child(row)->checkState(0) == Qt::Unchecked)
+ item->child(row)->setCheckState(0, Qt::Checked);
+ }
+ } else if (state == Qt::Unchecked && number > 0) {
+ for (row = 0; row < item->childCount(); ++row) {
+ if (item->child(row)->checkState(0) == Qt::Checked)
+ item->child(row)->setCheckState(0, Qt::Unchecked);
+ }
+ }
+ }
+
+ printAction->setEnabled(markedCount > 0);
+ printPreviewAction->setEnabled(markedCount > 0);
+}
+
+QMap<QString, StyleItems> MainWindow::currentPageMap()
+{
+ QMap<QString, StyleItems> pageMap;
+
+ for (int row = 0; row < fontTree->topLevelItemCount(); ++row) {
+ QTreeWidgetItem *familyItem = fontTree->topLevelItem(row);
+ QString family;
+
+ if (familyItem->checkState(0) == Qt::Checked) {
+ family = familyItem->text(0);
+ pageMap[family] = StyleItems();
+ }
+
+ for (int childRow = 0; childRow < familyItem->childCount(); ++childRow) {
+ QTreeWidgetItem *styleItem = familyItem->child(childRow);
+ if (styleItem->checkState(0) == Qt::Checked)
+ pageMap[family].append(styleItem);
+ }
+ }
+
+ return pageMap;
+}
+
+#ifndef QT_NO_PRINTER
+void MainWindow::on_printAction_triggered()
+{
+ pageMap = currentPageMap();
+
+ if (pageMap.count() == 0)
+ return;
+
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintDialog dialog(&printer, this);
+ if (dialog.exec() != QDialog::Accepted)
+ return;
+
+ int from = printer.fromPage();
+ int to = printer.toPage();
+ if (from <= 0 && to <= 0)
+ printer.setFromTo(1, pageMap.keys().count());
+
+ printDocument(&printer);
+}
+
+void MainWindow::printDocument(QPrinter *printer)
+{
+ printer->setFromTo(1, pageMap.count());
+
+ QProgressDialog progress(tr("Preparing font samples..."), tr("&Cancel"),
+ 0, pageMap.count(), this);
+ progress.setWindowModality(Qt::ApplicationModal);
+ progress.setWindowTitle(tr("Font Sampler"));
+ progress.setMinimum(printer->fromPage() - 1);
+ progress.setMaximum(printer->toPage());
+
+ QPainter painter;
+ painter.begin(printer);
+ bool firstPage = true;
+
+ for (int page = printer->fromPage(); page <= printer->toPage(); ++page) {
+
+ if (!firstPage)
+ printer->newPage();
+
+ qApp->processEvents();
+ if (progress.wasCanceled())
+ break;
+
+ printPage(page - 1, &painter, printer);
+ progress.setValue(page);
+ firstPage = false;
+ }
+
+ painter.end();
+}
+
+void MainWindow::on_printPreviewAction_triggered()
+{
+ pageMap = currentPageMap();
+
+ if (pageMap.count() == 0)
+ return;
+
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintPreviewDialog preview(&printer, this);
+ connect(&preview, SIGNAL(paintRequested(QPrinter*)),
+ this, SLOT(printDocument(QPrinter*)));
+ preview.exec();
+}
+
+void MainWindow::printPage(int index, QPainter *painter, QPrinter *printer)
+{
+ QString family = pageMap.keys()[index];
+ StyleItems items = pageMap[family];
+
+ // Find the dimensions of the text on each page.
+ qreal width = 0.0;
+ qreal height = 0.0;
+ foreach (QTreeWidgetItem *item, items) {
+ QString style = item->text(0);
+ int weight = item->data(0, Qt::UserRole).toInt();
+ bool italic = item->data(0, Qt::UserRole + 1).toBool();
+
+ // Calculate the maximum width and total height of the text.
+ foreach (int size, sampleSizes) {
+ QFont font(family, size, weight, italic);
+ font = QFont(font, painter->device());
+ QFontMetricsF fontMetrics(font);
+ QRectF rect = fontMetrics.boundingRect(
+ QString("%1 %2").arg(family).arg(style));
+ width = qMax(rect.width(), width);
+ height += rect.height();
+ }
+ }
+
+ qreal xScale = printer->pageRect().width() / width;
+ qreal yScale = printer->pageRect().height() / height;
+ qreal scale = qMin(xScale, yScale);
+
+ qreal remainingHeight = printer->pageRect().height()/scale - height;
+ qreal spaceHeight = (remainingHeight/4.0) / (items.count() + 1);
+ qreal interLineHeight = (remainingHeight/4.0) / (sampleSizes.count() * items.count());
+
+ painter->save();
+ painter->translate(printer->pageRect().width()/2.0, printer->pageRect().height()/2.0);
+ painter->scale(scale, scale);
+ painter->setBrush(QBrush(Qt::black));
+
+ qreal x = -width/2.0;
+ qreal y = -height/2.0 - remainingHeight/4.0 + spaceHeight;
+
+ foreach (QTreeWidgetItem *item, items) {
+ QString style = item->text(0);
+ int weight = item->data(0, Qt::UserRole).toInt();
+ bool italic = item->data(0, Qt::UserRole + 1).toBool();
+
+ // Draw each line of text.
+ foreach (int size, sampleSizes) {
+ QFont font(family, size, weight, italic);
+ font = QFont(font, painter->device());
+ QFontMetricsF fontMetrics(font);
+ QRectF rect = fontMetrics.boundingRect(QString("%1 %2").arg(
+ font.family()).arg(style));
+ y += rect.height();
+ painter->setFont(font);
+ painter->drawText(QPointF(x, y),
+ QString("%1 %2").arg(family).arg(style));
+ y += interLineHeight;
+ }
+ y += spaceHeight;
+ }
+
+ painter->restore();
+}
+#endif
diff --git a/examples/widgets/painting/fontsampler/mainwindow.h b/examples/widgets/painting/fontsampler/mainwindow.h
new file mode 100644
index 0000000000..fbb99333db
--- /dev/null
+++ b/examples/widgets/painting/fontsampler/mainwindow.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include "ui_mainwindowbase.h"
+
+QT_BEGIN_NAMESPACE
+class QPrinter;
+class QTextEdit;
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+typedef QList<QTreeWidgetItem *> StyleItems;
+
+class MainWindow : public QMainWindow, private Ui::MainWindowBase
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+public slots:
+ void on_clearAction_triggered();
+ void on_markAction_triggered();
+#ifndef QT_NO_PRINTER
+ void on_printAction_triggered();
+ void on_printPreviewAction_triggered();
+#endif
+ void on_unmarkAction_triggered();
+#ifndef QT_NO_PRINTER
+ void printDocument(QPrinter *printer);
+ void printPage(int index, QPainter *painter, QPrinter *printer);
+#endif
+ void showFont(QTreeWidgetItem *item);
+ void updateStyles(QTreeWidgetItem *item, int column);
+
+private:
+ QMap<QString, StyleItems> currentPageMap();
+ void markUnmarkFonts(Qt::CheckState state);
+ void setupFontTree();
+
+ QList<int> sampleSizes;
+ QMap<QString, StyleItems> pageMap;
+ int markedCount;
+};
+
+#endif
diff --git a/examples/widgets/painting/fontsampler/mainwindowbase.ui b/examples/widgets/painting/fontsampler/mainwindowbase.ui
new file mode 100644
index 0000000000..1a95ebd6d1
--- /dev/null
+++ b/examples/widgets/painting/fontsampler/mainwindowbase.ui
@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindowBase</class>
+ <widget class="QMainWindow" name="MainWindowBase">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>345</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Font Sampler</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QVBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>9</number>
+ </property>
+ <item>
+ <widget class="QTextEdit" name="textEdit"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>18</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menu_Selection">
+ <property name="title">
+ <string>&amp;Selection</string>
+ </property>
+ <addaction name="markAction"/>
+ <addaction name="unmarkAction"/>
+ <addaction name="clearAction"/>
+ </widget>
+ <widget class="QMenu" name="menu_File">
+ <property name="title">
+ <string>&amp;File</string>
+ </property>
+ <addaction name="printPreviewAction"/>
+ <addaction name="printAction"/>
+ <addaction name="quitAction"/>
+ </widget>
+ <addaction name="menu_File"/>
+ <addaction name="menu_Selection"/>
+ </widget>
+ <widget class="QStatusBar" name="statusbar"/>
+ <widget class="QDockWidget" name="dockWidget">
+ <property name="features">
+ <set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set>
+ </property>
+ <property name="windowTitle">
+ <string>Available Fonts</string>
+ </property>
+ <attribute name="dockWidgetArea">
+ <number>1</number>
+ </attribute>
+ <widget class="QWidget" name="dockWidgetContents">
+ <layout class="QVBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>9</number>
+ </property>
+ <item>
+ <widget class="QTreeWidget" name="fontTree">
+ <property name="selectionMode">
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
+ <column>
+ <property name="text">
+ <string notr="true">1</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <action name="printAction">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>&amp;Print...</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+P</string>
+ </property>
+ </action>
+ <action name="quitAction">
+ <property name="text">
+ <string>E&amp;xit</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Q</string>
+ </property>
+ </action>
+ <action name="markAction">
+ <property name="text">
+ <string>&amp;Mark</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+M</string>
+ </property>
+ </action>
+ <action name="unmarkAction">
+ <property name="text">
+ <string>&amp;Unmark</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+U</string>
+ </property>
+ </action>
+ <action name="clearAction">
+ <property name="text">
+ <string>&amp;Clear</string>
+ </property>
+ </action>
+ <action name="printPreviewAction">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Print Preview...</string>
+ </property>
+ </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp
new file mode 100644
index 0000000000..9dad51a8e4
--- /dev/null
+++ b/examples/widgets/painting/gradients/gradients.cpp
@@ -0,0 +1,516 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "gradients.h"
+#include "hoverpoints.h"
+
+ShadeWidget::ShadeWidget(ShadeType type, QWidget *parent)
+ : QWidget(parent), m_shade_type(type), m_alpha_gradient(QLinearGradient(0, 0, 0, 0))
+{
+
+ // Checkers background
+ if (m_shade_type == ARGBShade) {
+ QPixmap pm(20, 20);
+ QPainter pmp(&pm);
+ pmp.fillRect(0, 0, 10, 10, Qt::lightGray);
+ pmp.fillRect(10, 10, 10, 10, Qt::lightGray);
+ pmp.fillRect(0, 10, 10, 10, Qt::darkGray);
+ pmp.fillRect(10, 0, 10, 10, Qt::darkGray);
+ pmp.end();
+ QPalette pal = palette();
+ pal.setBrush(backgroundRole(), QBrush(pm));
+ setAutoFillBackground(true);
+ setPalette(pal);
+
+ } else {
+ setAttribute(Qt::WA_NoBackground);
+
+ }
+
+ QPolygonF points;
+ points << QPointF(0, sizeHint().height())
+ << QPointF(sizeHint().width(), 0);
+
+ m_hoverPoints = new HoverPoints(this, HoverPoints::CircleShape);
+// m_hoverPoints->setConnectionType(HoverPoints::LineConnection);
+ m_hoverPoints->setPoints(points);
+ m_hoverPoints->setPointLock(0, HoverPoints::LockToLeft);
+ m_hoverPoints->setPointLock(1, HoverPoints::LockToRight);
+ m_hoverPoints->setSortType(HoverPoints::XSort);
+
+ setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+
+ connect(m_hoverPoints, SIGNAL(pointsChanged(QPolygonF)), this, SIGNAL(colorsChanged()));
+}
+
+
+QPolygonF ShadeWidget::points() const
+{
+ return m_hoverPoints->points();
+}
+
+
+uint ShadeWidget::colorAt(int x)
+{
+ generateShade();
+
+ QPolygonF pts = m_hoverPoints->points();
+ for (int i=1; i < pts.size(); ++i) {
+ if (pts.at(i-1).x() <= x && pts.at(i).x() >= x) {
+ QLineF l(pts.at(i-1), pts.at(i));
+ l.setLength(l.length() * ((x - l.x1()) / l.dx()));
+ return m_shade.pixel(qRound(qMin(l.x2(), (qreal(m_shade.width() - 1)))),
+ qRound(qMin(l.y2(), qreal(m_shade.height() - 1))));
+ }
+ }
+ return 0;
+}
+
+
+void ShadeWidget::setGradientStops(const QGradientStops &stops)
+{
+ if (m_shade_type == ARGBShade) {
+ m_alpha_gradient = QLinearGradient(0, 0, width(), 0);
+
+ for (int i=0; i<stops.size(); ++i) {
+ QColor c = stops.at(i).second;
+ m_alpha_gradient.setColorAt(stops.at(i).first, QColor(c.red(), c.green(), c.blue()));
+ }
+
+ m_shade = QImage();
+ generateShade();
+ update();
+ }
+}
+
+
+void ShadeWidget::paintEvent(QPaintEvent *)
+{
+ generateShade();
+
+ QPainter p(this);
+ p.drawImage(0, 0, m_shade);
+
+ p.setPen(QColor(146, 146, 146));
+ p.drawRect(0, 0, width() - 1, height() - 1);
+}
+
+
+void ShadeWidget::generateShade()
+{
+ if (m_shade.isNull() || m_shade.size() != size()) {
+
+ if (m_shade_type == ARGBShade) {
+ m_shade = QImage(size(), QImage::Format_ARGB32_Premultiplied);
+ m_shade.fill(0);
+
+ QPainter p(&m_shade);
+ p.fillRect(rect(), m_alpha_gradient);
+
+ p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
+ QLinearGradient fade(0, 0, 0, height());
+ fade.setColorAt(0, QColor(0, 0, 0, 255));
+ fade.setColorAt(1, QColor(0, 0, 0, 0));
+ p.fillRect(rect(), fade);
+
+ } else {
+ m_shade = QImage(size(), QImage::Format_RGB32);
+ QLinearGradient shade(0, 0, 0, height());
+ shade.setColorAt(1, Qt::black);
+
+ if (m_shade_type == RedShade)
+ shade.setColorAt(0, Qt::red);
+ else if (m_shade_type == GreenShade)
+ shade.setColorAt(0, Qt::green);
+ else
+ shade.setColorAt(0, Qt::blue);
+
+ QPainter p(&m_shade);
+ p.fillRect(rect(), shade);
+ }
+ }
+
+
+}
+
+
+GradientEditor::GradientEditor(QWidget *parent)
+ : QWidget(parent)
+{
+ QVBoxLayout *vbox = new QVBoxLayout(this);
+ vbox->setSpacing(1);
+ vbox->setMargin(1);
+
+ m_red_shade = new ShadeWidget(ShadeWidget::RedShade, this);
+ m_green_shade = new ShadeWidget(ShadeWidget::GreenShade, this);
+ m_blue_shade = new ShadeWidget(ShadeWidget::BlueShade, this);
+ m_alpha_shade = new ShadeWidget(ShadeWidget::ARGBShade, this);
+
+ vbox->addWidget(m_red_shade);
+ vbox->addWidget(m_green_shade);
+ vbox->addWidget(m_blue_shade);
+ vbox->addWidget(m_alpha_shade);
+
+ connect(m_red_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
+ connect(m_green_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
+ connect(m_blue_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
+ connect(m_alpha_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
+}
+
+
+inline static bool x_less_than(const QPointF &p1, const QPointF &p2)
+{
+ return p1.x() < p2.x();
+}
+
+
+void GradientEditor::pointsUpdated()
+{
+ qreal w = m_alpha_shade->width();
+
+ QGradientStops stops;
+
+ QPolygonF points;
+
+ points += m_red_shade->points();
+ points += m_green_shade->points();
+ points += m_blue_shade->points();
+ points += m_alpha_shade->points();
+
+ qSort(points.begin(), points.end(), x_less_than);
+
+ for (int i=0; i<points.size(); ++i) {
+ qreal x = int(points.at(i).x());
+ if (i+1 < points.size() && x == points.at(i+1).x())
+ continue;
+ QColor color((0x00ff0000 & m_red_shade->colorAt(int(x))) >> 16,
+ (0x0000ff00 & m_green_shade->colorAt(int(x))) >> 8,
+ (0x000000ff & m_blue_shade->colorAt(int(x))),
+ (0xff000000 & m_alpha_shade->colorAt(int(x))) >> 24);
+
+ if (x / w > 1)
+ return;
+
+ stops << QGradientStop(x / w, color);
+ }
+
+ m_alpha_shade->setGradientStops(stops);
+
+ emit gradientStopsChanged(stops);
+}
+
+
+static void set_shade_points(const QPolygonF &points, ShadeWidget *shade)
+{
+ shade->hoverPoints()->setPoints(points);
+ shade->hoverPoints()->setPointLock(0, HoverPoints::LockToLeft);
+ shade->hoverPoints()->setPointLock(points.size() - 1, HoverPoints::LockToRight);
+ shade->update();
+}
+
+void GradientEditor::setGradientStops(const QGradientStops &stops)
+{
+ QPolygonF pts_red, pts_green, pts_blue, pts_alpha;
+
+ qreal h_red = m_red_shade->height();
+ qreal h_green = m_green_shade->height();
+ qreal h_blue = m_blue_shade->height();
+ qreal h_alpha = m_alpha_shade->height();
+
+ for (int i=0; i<stops.size(); ++i) {
+ qreal pos = stops.at(i).first;
+ QRgb color = stops.at(i).second.rgba();
+ pts_red << QPointF(pos * m_red_shade->width(), h_red - qRed(color) * h_red / 255);
+ pts_green << QPointF(pos * m_green_shade->width(), h_green - qGreen(color) * h_green / 255);
+ pts_blue << QPointF(pos * m_blue_shade->width(), h_blue - qBlue(color) * h_blue / 255);
+ pts_alpha << QPointF(pos * m_alpha_shade->width(), h_alpha - qAlpha(color) * h_alpha / 255);
+ }
+
+ set_shade_points(pts_red, m_red_shade);
+ set_shade_points(pts_green, m_green_shade);
+ set_shade_points(pts_blue, m_blue_shade);
+ set_shade_points(pts_alpha, m_alpha_shade);
+
+}
+
+GradientWidget::GradientWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ setWindowTitle(tr("Gradients"));
+
+ m_renderer = new GradientRenderer(this);
+
+ QGroupBox *mainGroup = new QGroupBox(this);
+ mainGroup->setTitle(tr("Gradients"));
+
+ QGroupBox *editorGroup = new QGroupBox(mainGroup);
+ editorGroup->setTitle(tr("Color Editor"));
+ m_editor = new GradientEditor(editorGroup);
+
+ QGroupBox *typeGroup = new QGroupBox(mainGroup);
+ typeGroup->setTitle(tr("Gradient Type"));
+ m_linearButton = new QRadioButton(tr("Linear Gradient"), typeGroup);
+ m_radialButton = new QRadioButton(tr("Radial Gradient"), typeGroup);
+ m_conicalButton = new QRadioButton(tr("Conical Gradient"), typeGroup);
+
+ QGroupBox *spreadGroup = new QGroupBox(mainGroup);
+ spreadGroup->setTitle(tr("Spread Method"));
+ m_padSpreadButton = new QRadioButton(tr("Pad Spread"), spreadGroup);
+ m_reflectSpreadButton = new QRadioButton(tr("Reflect Spread"), spreadGroup);
+ m_repeatSpreadButton = new QRadioButton(tr("Repeat Spread"), spreadGroup);
+
+ QGroupBox *defaultsGroup = new QGroupBox(mainGroup);
+ defaultsGroup->setTitle(tr("Defaults"));
+ QPushButton *default1Button = new QPushButton(tr("1"), defaultsGroup);
+ QPushButton *default2Button = new QPushButton(tr("2"), defaultsGroup);
+ QPushButton *default3Button = new QPushButton(tr("3"), defaultsGroup);
+ QPushButton *default4Button = new QPushButton(tr("Reset"), editorGroup);
+
+ QPushButton *showSourceButton = new QPushButton(mainGroup);
+ showSourceButton->setText(tr("Show Source"));
+#ifdef QT_OPENGL_SUPPORT
+ QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(true);
+ enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
+ if (!QGLFormat::hasOpenGL())
+ enableOpenGLButton->hide();
+#endif
+ QPushButton *whatsThisButton = new QPushButton(mainGroup);
+ whatsThisButton->setText(tr("What's This?"));
+ whatsThisButton->setCheckable(true);
+
+ // Layouts
+ QHBoxLayout *mainLayout = new QHBoxLayout(this);
+ mainLayout->addWidget(m_renderer);
+ mainLayout->addWidget(mainGroup);
+
+ mainGroup->setFixedWidth(180);
+ QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
+ mainGroupLayout->addWidget(editorGroup);
+ mainGroupLayout->addWidget(typeGroup);
+ mainGroupLayout->addWidget(spreadGroup);
+ mainGroupLayout->addWidget(defaultsGroup);
+ mainGroupLayout->addStretch(1);
+ mainGroupLayout->addWidget(showSourceButton);
+#ifdef QT_OPENGL_SUPPORT
+ mainGroupLayout->addWidget(enableOpenGLButton);
+#endif
+ mainGroupLayout->addWidget(whatsThisButton);
+
+ QVBoxLayout *editorGroupLayout = new QVBoxLayout(editorGroup);
+ editorGroupLayout->addWidget(m_editor);
+
+ QVBoxLayout *typeGroupLayout = new QVBoxLayout(typeGroup);
+ typeGroupLayout->addWidget(m_linearButton);
+ typeGroupLayout->addWidget(m_radialButton);
+ typeGroupLayout->addWidget(m_conicalButton);
+
+ QVBoxLayout *spreadGroupLayout = new QVBoxLayout(spreadGroup);
+ spreadGroupLayout->addWidget(m_padSpreadButton);
+ spreadGroupLayout->addWidget(m_repeatSpreadButton);
+ spreadGroupLayout->addWidget(m_reflectSpreadButton);
+
+ QHBoxLayout *defaultsGroupLayout = new QHBoxLayout(defaultsGroup);
+ defaultsGroupLayout->addWidget(default1Button);
+ defaultsGroupLayout->addWidget(default2Button);
+ defaultsGroupLayout->addWidget(default3Button);
+ editorGroupLayout->addWidget(default4Button);
+
+ connect(m_editor, SIGNAL(gradientStopsChanged(QGradientStops)),
+ m_renderer, SLOT(setGradientStops(QGradientStops)));
+
+ connect(m_linearButton, SIGNAL(clicked()), m_renderer, SLOT(setLinearGradient()));
+ connect(m_radialButton, SIGNAL(clicked()), m_renderer, SLOT(setRadialGradient()));
+ connect(m_conicalButton, SIGNAL(clicked()), m_renderer, SLOT(setConicalGradient()));
+
+ connect(m_padSpreadButton, SIGNAL(clicked()), m_renderer, SLOT(setPadSpread()));
+ connect(m_reflectSpreadButton, SIGNAL(clicked()), m_renderer, SLOT(setReflectSpread()));
+ connect(m_repeatSpreadButton, SIGNAL(clicked()), m_renderer, SLOT(setRepeatSpread()));
+
+ connect(default1Button, SIGNAL(clicked()), this, SLOT(setDefault1()));
+ connect(default2Button, SIGNAL(clicked()), this, SLOT(setDefault2()));
+ connect(default3Button, SIGNAL(clicked()), this, SLOT(setDefault3()));
+ connect(default4Button, SIGNAL(clicked()), this, SLOT(setDefault4()));
+
+ connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource()));
+#ifdef QT_OPENGL_SUPPORT
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));
+#endif
+ connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool)));
+ connect(whatsThisButton, SIGNAL(clicked(bool)),
+ m_renderer->hoverPoints(), SLOT(setDisabled(bool)));
+ connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)),
+ whatsThisButton, SLOT(setChecked(bool)));
+ connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)),
+ m_renderer->hoverPoints(), SLOT(setDisabled(bool)));
+
+ m_renderer->loadSourceFile(":res/gradients/gradients.cpp");
+ m_renderer->loadDescription(":res/gradients/gradients.html");
+
+ QTimer::singleShot(50, this, SLOT(setDefault1()));
+}
+
+void GradientWidget::setDefault(int config)
+{
+ QGradientStops stops;
+ QPolygonF points;
+ switch (config) {
+ case 1:
+ stops << QGradientStop(0.00, QColor::fromRgba(0));
+ stops << QGradientStop(0.04, QColor::fromRgba(0xff131360));
+ stops << QGradientStop(0.08, QColor::fromRgba(0xff202ccc));
+ stops << QGradientStop(0.42, QColor::fromRgba(0xff93d3f9));
+ stops << QGradientStop(0.51, QColor::fromRgba(0xffb3e6ff));
+ stops << QGradientStop(0.73, QColor::fromRgba(0xffffffec));
+ stops << QGradientStop(0.92, QColor::fromRgba(0xff5353d9));
+ stops << QGradientStop(0.96, QColor::fromRgba(0xff262666));
+ stops << QGradientStop(1.00, QColor::fromRgba(0));
+ m_linearButton->animateClick();
+ m_repeatSpreadButton->animateClick();
+ break;
+
+ case 2:
+ stops << QGradientStop(0.00, QColor::fromRgba(0xffffffff));
+ stops << QGradientStop(0.11, QColor::fromRgba(0xfff9ffa0));
+ stops << QGradientStop(0.13, QColor::fromRgba(0xfff9ff99));
+ stops << QGradientStop(0.14, QColor::fromRgba(0xfff3ff86));
+ stops << QGradientStop(0.49, QColor::fromRgba(0xff93b353));
+ stops << QGradientStop(0.87, QColor::fromRgba(0xff264619));
+ stops << QGradientStop(0.96, QColor::fromRgba(0xff0c1306));
+ stops << QGradientStop(1.00, QColor::fromRgba(0));
+ m_radialButton->animateClick();
+ m_padSpreadButton->animateClick();
+ break;
+
+ case 3:
+ stops << QGradientStop(0.00, QColor::fromRgba(0));
+ stops << QGradientStop(0.10, QColor::fromRgba(0xffe0cc73));
+ stops << QGradientStop(0.17, QColor::fromRgba(0xffc6a006));
+ stops << QGradientStop(0.46, QColor::fromRgba(0xff600659));
+ stops << QGradientStop(0.72, QColor::fromRgba(0xff0680ac));
+ stops << QGradientStop(0.92, QColor::fromRgba(0xffb9d9e6));
+ stops << QGradientStop(1.00, QColor::fromRgba(0));
+ m_conicalButton->animateClick();
+ m_padSpreadButton->animateClick();
+ break;
+
+ case 4:
+ stops << QGradientStop(0.00, QColor::fromRgba(0xff000000));
+ stops << QGradientStop(1.00, QColor::fromRgba(0xffffffff));
+ break;
+
+ default:
+ qWarning("bad default: %d\n", config);
+ break;
+ }
+
+ QPolygonF pts;
+ int h_off = m_renderer->width() / 10;
+ int v_off = m_renderer->height() / 8;
+ pts << QPointF(m_renderer->width() / 2, m_renderer->height() / 2)
+ << QPointF(m_renderer->width() / 2 - h_off, m_renderer->height() / 2 - v_off);
+
+ m_editor->setGradientStops(stops);
+ m_renderer->hoverPoints()->setPoints(pts);
+ m_renderer->setGradientStops(stops);
+}
+
+
+GradientRenderer::GradientRenderer(QWidget *parent)
+ : ArthurFrame(parent)
+{
+ m_hoverPoints = new HoverPoints(this, HoverPoints::CircleShape);
+ m_hoverPoints->setPointSize(QSize(20, 20));
+ m_hoverPoints->setConnectionType(HoverPoints::NoConnection);
+ m_hoverPoints->setEditable(false);
+
+ QVector<QPointF> points;
+ points << QPointF(100, 100) << QPointF(200, 200);
+ m_hoverPoints->setPoints(points);
+
+ m_spread = QGradient::PadSpread;
+ m_gradientType = Qt::LinearGradientPattern;
+}
+
+void GradientRenderer::setGradientStops(const QGradientStops &stops)
+{
+ m_stops = stops;
+ update();
+}
+
+
+void GradientRenderer::mousePressEvent(QMouseEvent *)
+{
+ setDescriptionEnabled(false);
+}
+
+void GradientRenderer::paint(QPainter *p)
+{
+ QPolygonF pts = m_hoverPoints->points();
+
+ QGradient g;
+
+ if (m_gradientType == Qt::LinearGradientPattern) {
+ g = QLinearGradient(pts.at(0), pts.at(1));
+
+ } else if (m_gradientType == Qt::RadialGradientPattern) {
+ g = QRadialGradient(pts.at(0), qMin(width(), height()) / 3.0, pts.at(1));
+
+ } else {
+ QLineF l(pts.at(0), pts.at(1));
+ qreal angle = l.angle(QLineF(0, 0, 1, 0));
+ if (l.dy() > 0)
+ angle = 360 - angle;
+ g = QConicalGradient(pts.at(0), angle);
+ }
+
+ for (int i=0; i<m_stops.size(); ++i)
+ g.setColorAt(m_stops.at(i).first, m_stops.at(i).second);
+
+ g.setSpread(m_spread);
+
+ p->setBrush(g);
+ p->setPen(Qt::NoPen);
+
+ p->drawRect(rect());
+
+}
diff --git a/examples/widgets/painting/gradients/gradients.h b/examples/widgets/painting/gradients/gradients.h
new file mode 100644
index 0000000000..0fed2de82a
--- /dev/null
+++ b/examples/widgets/painting/gradients/gradients.h
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GRADIENTS_H
+#define GRADIENTS_H
+
+#include "arthurwidgets.h"
+
+#include <QtWidgets>
+
+class HoverPoints;
+
+
+class ShadeWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ enum ShadeType {
+ RedShade,
+ GreenShade,
+ BlueShade,
+ ARGBShade
+ };
+
+ ShadeWidget(ShadeType type, QWidget *parent);
+
+ void setGradientStops(const QGradientStops &stops);
+
+ void paintEvent(QPaintEvent *e);
+
+ QSize sizeHint() const { return QSize(150, 40); }
+ QPolygonF points() const;
+
+ HoverPoints *hoverPoints() const { return m_hoverPoints; }
+
+ uint colorAt(int x);
+
+signals:
+ void colorsChanged();
+
+private:
+ void generateShade();
+
+ ShadeType m_shade_type;
+ QImage m_shade;
+ HoverPoints *m_hoverPoints;
+ QLinearGradient m_alpha_gradient;
+};
+
+class GradientEditor : public QWidget
+{
+ Q_OBJECT
+public:
+ GradientEditor(QWidget *parent);
+
+ void setGradientStops(const QGradientStops &stops);
+
+public slots:
+ void pointsUpdated();
+
+signals:
+ void gradientStopsChanged(const QGradientStops &stops);
+
+private:
+ ShadeWidget *m_red_shade;
+ ShadeWidget *m_green_shade;
+ ShadeWidget *m_blue_shade;
+ ShadeWidget *m_alpha_shade;
+};
+
+
+class GradientRenderer : public ArthurFrame
+{
+ Q_OBJECT
+public:
+ GradientRenderer(QWidget *parent);
+ void paint(QPainter *p);
+
+ QSize sizeHint() const { return QSize(400, 400); }
+
+ HoverPoints *hoverPoints() const { return m_hoverPoints; }
+ void mousePressEvent(QMouseEvent *e);
+
+public slots:
+ void setGradientStops(const QGradientStops &stops);
+
+ void setPadSpread() { m_spread = QGradient::PadSpread; update(); }
+ void setRepeatSpread() { m_spread = QGradient::RepeatSpread; update(); }
+ void setReflectSpread() { m_spread = QGradient::ReflectSpread; update(); }
+
+ void setLinearGradient() { m_gradientType = Qt::LinearGradientPattern; update(); }
+ void setRadialGradient() { m_gradientType = Qt::RadialGradientPattern; update(); }
+ void setConicalGradient() { m_gradientType = Qt::ConicalGradientPattern; update(); }
+
+
+private:
+ QGradientStops m_stops;
+ HoverPoints *m_hoverPoints;
+
+ QGradient::Spread m_spread;
+ Qt::BrushStyle m_gradientType;
+};
+
+
+class GradientWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ GradientWidget(QWidget *parent);
+
+public slots:
+ void setDefault1() { setDefault(1); }
+ void setDefault2() { setDefault(2); }
+ void setDefault3() { setDefault(3); }
+ void setDefault4() { setDefault(4); }
+
+private:
+ void setDefault(int i);
+
+ GradientRenderer *m_renderer;
+ GradientEditor *m_editor;
+
+ QRadioButton *m_linearButton;
+ QRadioButton *m_radialButton;
+ QRadioButton *m_conicalButton;
+ QRadioButton *m_padSpreadButton;
+ QRadioButton *m_reflectSpreadButton;
+ QRadioButton *m_repeatSpreadButton;
+
+};
+
+#endif // GRADIENTS_H
diff --git a/examples/widgets/painting/gradients/gradients.html b/examples/widgets/painting/gradients/gradients.html
new file mode 100644
index 0000000000..1ea2c0ed6c
--- /dev/null
+++ b/examples/widgets/painting/gradients/gradients.html
@@ -0,0 +1,31 @@
+<html>
+<center>
+<h2>Gradients</h2>
+</center>
+
+<p>In this demo we show the various types of gradients that can
+be used in Qt.</p>
+
+<p>There are three types of gradients:
+
+<ul>
+ <li><b>Linear</b> gradients interpolate colors between start and end
+ points.</li>
+ <li><b>Radial</b> gradients interpolate colors between a focal point and the
+ points on a circle surrounding it.</li>
+ <li><b>Conical</b> gradients interpolate colors around a center point.</li>
+</ul>
+
+</p>
+
+<p>The panel on the right contains a color table editor that defines
+the colors in the gradient. The three topmost controls determine the red,
+green and blue components while the last defines the alpha of the
+gradient. You can move points, and add new ones, by clicking with the left
+mouse button, and remove points by clicking with the right button.</p>
+
+<p>There are three default configurations available at the bottom of
+the page that are provided as suggestions on how a color table could be
+configured.</p>
+
+</html>
diff --git a/examples/widgets/painting/gradients/gradients.pro b/examples/widgets/painting/gradients/gradients.pro
new file mode 100644
index 0000000000..4362d283ee
--- /dev/null
+++ b/examples/widgets/painting/gradients/gradients.pro
@@ -0,0 +1,20 @@
+SOURCES += main.cpp gradients.cpp
+HEADERS += gradients.h
+
+SHARED_FOLDER = ../shared
+
+include($$SHARED_FOLDER/shared.pri)
+
+RESOURCES += gradients.qrc
+contains(QT_CONFIG, opengl) {
+ DEFINES += QT_OPENGL_SUPPORT
+ QT += opengl
+}
+QT += widgets
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/gradients
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/gradients
+INSTALLS += target sources
+
diff --git a/examples/widgets/painting/gradients/gradients.qrc b/examples/widgets/painting/gradients/gradients.qrc
new file mode 100644
index 0000000000..fb971eb17b
--- /dev/null
+++ b/examples/widgets/painting/gradients/gradients.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res/gradients">
+ <file>gradients.cpp</file>
+ <file>gradients.html</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/painting/gradients/main.cpp b/examples/widgets/painting/gradients/main.cpp
new file mode 100644
index 0000000000..eaf8bdc333
--- /dev/null
+++ b/examples/widgets/painting/gradients/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "gradients.h"
+
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(gradients);
+
+ QApplication app(argc, argv);
+
+ GradientWidget gradientWidget(0);
+ QStyle *arthurStyle = new ArthurStyle();
+ gradientWidget.setStyle(arthurStyle);
+ QList<QWidget *> widgets = gradientWidget.findChildren<QWidget *>();
+ foreach (QWidget *w, widgets) {
+ w->setStyle(arthurStyle);
+ w->setAttribute(Qt::WA_AcceptTouchEvents);
+ }
+ gradientWidget.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/painting/imagecomposition/imagecomposer.cpp b/examples/widgets/painting/imagecomposition/imagecomposer.cpp
new file mode 100644
index 0000000000..38b04a27b0
--- /dev/null
+++ b/examples/widgets/painting/imagecomposition/imagecomposer.cpp
@@ -0,0 +1,211 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "imagecomposer.h"
+
+//! [0]
+static const QSize resultSize(200, 200);
+//! [0]
+
+//! [1]
+ImageComposer::ImageComposer()
+{
+ sourceButton = new QToolButton;
+ sourceButton->setIconSize(resultSize);
+
+ operatorComboBox = new QComboBox;
+ addOp(QPainter::CompositionMode_SourceOver, tr("SourceOver"));
+ addOp(QPainter::CompositionMode_DestinationOver, tr("DestinationOver"));
+ addOp(QPainter::CompositionMode_Clear, tr("Clear"));
+ addOp(QPainter::CompositionMode_Source, tr("Source"));
+ addOp(QPainter::CompositionMode_Destination, tr("Destination"));
+ addOp(QPainter::CompositionMode_SourceIn, tr("SourceIn"));
+ addOp(QPainter::CompositionMode_DestinationIn, tr("DestinationIn"));
+ addOp(QPainter::CompositionMode_SourceOut, tr("SourceOut"));
+ addOp(QPainter::CompositionMode_DestinationOut, tr("DestinationOut"));
+ addOp(QPainter::CompositionMode_SourceAtop, tr("SourceAtop"));
+ addOp(QPainter::CompositionMode_DestinationAtop, tr("DestinationAtop"));
+ addOp(QPainter::CompositionMode_Xor, tr("Xor"));
+ addOp(QPainter::CompositionMode_Plus, tr("Plus"));
+ addOp(QPainter::CompositionMode_Multiply, tr("Multiply"));
+ addOp(QPainter::CompositionMode_Screen, tr("Screen"));
+ addOp(QPainter::CompositionMode_Overlay, tr("Overlay"));
+ addOp(QPainter::CompositionMode_Darken, tr("Darken"));
+ addOp(QPainter::CompositionMode_Lighten, tr("Lighten"));
+ addOp(QPainter::CompositionMode_ColorDodge, tr("ColorDodge"));
+ addOp(QPainter::CompositionMode_ColorBurn, tr("ColorBurn"));
+ addOp(QPainter::CompositionMode_HardLight, tr("HardLight"));
+ addOp(QPainter::CompositionMode_SoftLight, tr("SoftLight"));
+ addOp(QPainter::CompositionMode_Difference, tr("Difference"));
+ addOp(QPainter::CompositionMode_Exclusion, tr("Exclusion"));
+//! [1]
+
+//! [2]
+ destinationButton = new QToolButton;
+ destinationButton->setIconSize(resultSize);
+
+ equalLabel = new QLabel(tr("="));
+
+ resultLabel = new QLabel;
+ resultLabel->setMinimumWidth(resultSize.width());
+//! [2]
+
+//! [3]
+ connect(sourceButton, SIGNAL(clicked()), this, SLOT(chooseSource()));
+ connect(operatorComboBox, SIGNAL(activated(int)),
+ this, SLOT(recalculateResult()));
+ connect(destinationButton, SIGNAL(clicked()),
+ this, SLOT(chooseDestination()));
+//! [3]
+
+//! [4]
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(sourceButton, 0, 0, 3, 1);
+ mainLayout->addWidget(operatorComboBox, 1, 1);
+ mainLayout->addWidget(destinationButton, 0, 2, 3, 1);
+ mainLayout->addWidget(equalLabel, 1, 3);
+ mainLayout->addWidget(resultLabel, 0, 4, 3, 1);
+ mainLayout->setSizeConstraint(QLayout::SetFixedSize);
+ setLayout(mainLayout);
+//! [4]
+
+//! [5]
+ resultImage = QImage(resultSize, QImage::Format_ARGB32_Premultiplied);
+
+ loadImage(":/images/butterfly.png", &sourceImage, sourceButton);
+ loadImage(":/images/checker.png", &destinationImage, destinationButton);
+
+ setWindowTitle(tr("Image Composition"));
+}
+//! [5]
+
+//! [6]
+void ImageComposer::chooseSource()
+{
+ chooseImage(tr("Choose Source Image"), &sourceImage, sourceButton);
+}
+//! [6]
+
+//! [7]
+void ImageComposer::chooseDestination()
+{
+ chooseImage(tr("Choose Destination Image"), &destinationImage,
+ destinationButton);
+}
+//! [7]
+
+//! [8]
+void ImageComposer::recalculateResult()
+{
+ QPainter::CompositionMode mode = currentMode();
+
+ QPainter painter(&resultImage);
+ painter.setCompositionMode(QPainter::CompositionMode_Source);
+ painter.fillRect(resultImage.rect(), Qt::transparent);
+ painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
+ painter.drawImage(0, 0, destinationImage);
+ painter.setCompositionMode(mode);
+ painter.drawImage(0, 0, sourceImage);
+ painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
+ painter.fillRect(resultImage.rect(), Qt::white);
+ painter.end();
+
+ resultLabel->setPixmap(QPixmap::fromImage(resultImage));
+}
+//! [8]
+
+//! [9]
+void ImageComposer::addOp(QPainter::CompositionMode mode, const QString &name)
+{
+ operatorComboBox->addItem(name, mode);
+}
+//! [9]
+
+//! [10]
+void ImageComposer::chooseImage(const QString &title, QImage *image,
+ QToolButton *button)
+{
+ QString fileName = QFileDialog::getOpenFileName(this, title);
+ if (!fileName.isEmpty())
+ loadImage(fileName, image, button);
+}
+//! [10]
+
+//! [11]
+void ImageComposer::loadImage(const QString &fileName, QImage *image,
+ QToolButton *button)
+{
+ image->load(fileName);
+
+ // Scale the image to given size
+ *image = image->scaled(resultSize, Qt::KeepAspectRatio);
+
+ QImage fixedImage(resultSize, QImage::Format_ARGB32_Premultiplied);
+ QPainter painter(&fixedImage);
+ painter.setCompositionMode(QPainter::CompositionMode_Source);
+ painter.fillRect(fixedImage.rect(), Qt::transparent);
+ painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
+ painter.drawImage(imagePos(*image), *image);
+ painter.end();
+ button->setIcon(QPixmap::fromImage(fixedImage));
+
+ *image = fixedImage;
+
+ recalculateResult();
+}
+//! [11]
+
+//! [12]
+QPainter::CompositionMode ImageComposer::currentMode() const
+{
+ return (QPainter::CompositionMode)
+ operatorComboBox->itemData(operatorComboBox->currentIndex()).toInt();
+}
+//! [12]
+
+//! [13]
+QPoint ImageComposer::imagePos(const QImage &image) const
+{
+ return QPoint((resultSize.width() - image.width()) / 2,
+ (resultSize.height() - image.height()) / 2);
+}
+//! [13]
diff --git a/examples/widgets/painting/imagecomposition/imagecomposer.h b/examples/widgets/painting/imagecomposition/imagecomposer.h
new file mode 100644
index 0000000000..7ec0207e2c
--- /dev/null
+++ b/examples/widgets/painting/imagecomposition/imagecomposer.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef IMAGECOMPOSER_H
+#define IMAGECOMPOSER_H
+
+#include <QPainter>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QLabel;
+class QToolButton;
+QT_END_NAMESPACE
+
+//! [0]
+class ImageComposer : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ImageComposer();
+
+private slots:
+ void chooseSource();
+ void chooseDestination();
+ void recalculateResult();
+//! [0]
+
+//! [1]
+private:
+ void addOp(QPainter::CompositionMode mode, const QString &name);
+ void chooseImage(const QString &title, QImage *image, QToolButton *button);
+ void loadImage(const QString &fileName, QImage *image, QToolButton *button);
+ QPainter::CompositionMode currentMode() const;
+ QPoint imagePos(const QImage &image) const;
+
+ QToolButton *sourceButton;
+ QToolButton *destinationButton;
+ QComboBox *operatorComboBox;
+ QLabel *equalLabel;
+ QLabel *resultLabel;
+
+ QImage sourceImage;
+ QImage destinationImage;
+ QImage resultImage;
+};
+//! [1]
+
+#endif
diff --git a/examples/widgets/painting/imagecomposition/imagecomposition.desktop b/examples/widgets/painting/imagecomposition/imagecomposition.desktop
new file mode 100644
index 0000000000..854fc862f0
--- /dev/null
+++ b/examples/widgets/painting/imagecomposition/imagecomposition.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Image Composition
+Exec=/opt/usr/bin/imagecomposition
+Icon=imagecomposition
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/painting/imagecomposition/imagecomposition.pro b/examples/widgets/painting/imagecomposition/imagecomposition.pro
new file mode 100644
index 0000000000..edf434f5d2
--- /dev/null
+++ b/examples/widgets/painting/imagecomposition/imagecomposition.pro
@@ -0,0 +1,13 @@
+HEADERS = imagecomposer.h
+SOURCES = imagecomposer.cpp \
+ main.cpp
+RESOURCES = imagecomposition.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/imagecomposition
+sources.files = $$SOURCES $$HEADERS $$RESOURCES images *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/imagecomposition
+INSTALLS += target sources
+
+QT += widgets
+
diff --git a/examples/widgets/painting/imagecomposition/imagecomposition.qrc b/examples/widgets/painting/imagecomposition/imagecomposition.qrc
new file mode 100644
index 0000000000..ebba7b2913
--- /dev/null
+++ b/examples/widgets/painting/imagecomposition/imagecomposition.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/butterfly.png</file>
+ <file>images/checker.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/painting/imagecomposition/images/background.png b/examples/widgets/painting/imagecomposition/images/background.png
new file mode 100644
index 0000000000..f6ad899823
--- /dev/null
+++ b/examples/widgets/painting/imagecomposition/images/background.png
Binary files differ
diff --git a/examples/widgets/painting/imagecomposition/images/blackrectangle.png b/examples/widgets/painting/imagecomposition/images/blackrectangle.png
new file mode 100644
index 0000000000..5f2ecf8318
--- /dev/null
+++ b/examples/widgets/painting/imagecomposition/images/blackrectangle.png
Binary files differ
diff --git a/examples/widgets/painting/imagecomposition/images/butterfly.png b/examples/widgets/painting/imagecomposition/images/butterfly.png
new file mode 100644
index 0000000000..f3e050eca2
--- /dev/null
+++ b/examples/widgets/painting/imagecomposition/images/butterfly.png
Binary files differ
diff --git a/examples/widgets/painting/imagecomposition/images/checker.png b/examples/widgets/painting/imagecomposition/images/checker.png
new file mode 100644
index 0000000000..546609de3f
--- /dev/null
+++ b/examples/widgets/painting/imagecomposition/images/checker.png
Binary files differ
diff --git a/examples/widgets/painting/imagecomposition/main.cpp b/examples/widgets/painting/imagecomposition/main.cpp
new file mode 100644
index 0000000000..6b17c4d370
--- /dev/null
+++ b/examples/widgets/painting/imagecomposition/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "imagecomposer.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(imagecomposition);
+
+ QApplication app(argc, argv);
+ ImageComposer composer;
+ composer.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/widgets/painting/painterpaths/main.cpp b/examples/widgets/painting/painterpaths/main.cpp
new file mode 100644
index 0000000000..dcbf1c0449
--- /dev/null
+++ b/examples/widgets/painting/painterpaths/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/painting/painterpaths/painterpaths.desktop b/examples/widgets/painting/painterpaths/painterpaths.desktop
new file mode 100644
index 0000000000..ae92f2c589
--- /dev/null
+++ b/examples/widgets/painting/painterpaths/painterpaths.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Painter Paths
+Exec=/opt/usr/bin/painterpaths
+Icon=painterpaths
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/painting/painterpaths/painterpaths.pro b/examples/widgets/painting/painterpaths/painterpaths.pro
new file mode 100644
index 0000000000..c988ba26e0
--- /dev/null
+++ b/examples/widgets/painting/painterpaths/painterpaths.pro
@@ -0,0 +1,15 @@
+HEADERS = renderarea.h \
+ window.h
+SOURCES = main.cpp \
+ renderarea.cpp \
+ window.cpp
+unix:!mac:!vxworks:!integrity:LIBS += -lm
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/painterpaths
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS painterpaths.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/painterpaths
+INSTALLS += target sources
+
+QT += widgets
+
diff --git a/examples/widgets/painting/painterpaths/renderarea.cpp b/examples/widgets/painting/painterpaths/renderarea.cpp
new file mode 100644
index 0000000000..0b3f1fdc0d
--- /dev/null
+++ b/examples/widgets/painting/painterpaths/renderarea.cpp
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "renderarea.h"
+
+//! [0]
+RenderArea::RenderArea(const QPainterPath &path, QWidget *parent)
+ : QWidget(parent), path(path)
+{
+ penWidth = 1;
+ rotationAngle = 0;
+ setBackgroundRole(QPalette::Base);
+}
+//! [0]
+
+//! [1]
+QSize RenderArea::minimumSizeHint() const
+{
+ return QSize(50, 50);
+}
+//! [1]
+
+//! [2]
+QSize RenderArea::sizeHint() const
+{
+ return QSize(100, 100);
+}
+//! [2]
+
+//! [3]
+void RenderArea::setFillRule(Qt::FillRule rule)
+{
+ path.setFillRule(rule);
+ update();
+}
+//! [3]
+
+//! [4]
+void RenderArea::setFillGradient(const QColor &color1, const QColor &color2)
+{
+ fillColor1 = color1;
+ fillColor2 = color2;
+ update();
+}
+//! [4]
+
+//! [5]
+void RenderArea::setPenWidth(int width)
+{
+ penWidth = width;
+ update();
+}
+//! [5]
+
+//! [6]
+void RenderArea::setPenColor(const QColor &color)
+{
+ penColor = color;
+ update();
+}
+//! [6]
+
+//! [7]
+void RenderArea::setRotationAngle(int degrees)
+{
+ rotationAngle = degrees;
+ update();
+}
+//! [7]
+
+//! [8]
+void RenderArea::paintEvent(QPaintEvent *)
+{
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+//! [8] //! [9]
+ painter.scale(width() / 100.0, height() / 100.0);
+ painter.translate(50.0, 50.0);
+ painter.rotate(-rotationAngle);
+ painter.translate(-50.0, -50.0);
+
+//! [9] //! [10]
+ painter.setPen(QPen(penColor, penWidth, Qt::SolidLine, Qt::RoundCap,
+ Qt::RoundJoin));
+ QLinearGradient gradient(0, 0, 0, 100);
+ gradient.setColorAt(0.0, fillColor1);
+ gradient.setColorAt(1.0, fillColor2);
+ painter.setBrush(gradient);
+ painter.drawPath(path);
+}
+//! [10]
diff --git a/examples/widgets/painting/painterpaths/renderarea.h b/examples/widgets/painting/painterpaths/renderarea.h
new file mode 100644
index 0000000000..5c310fdf62
--- /dev/null
+++ b/examples/widgets/painting/painterpaths/renderarea.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RENDERAREA_H
+#define RENDERAREA_H
+
+#include <QPainterPath>
+#include <QWidget>
+
+//! [0]
+class RenderArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ RenderArea(const QPainterPath &path, QWidget *parent = 0);
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+
+public slots:
+ void setFillRule(Qt::FillRule rule);
+ void setFillGradient(const QColor &color1, const QColor &color2);
+ void setPenWidth(int width);
+ void setPenColor(const QColor &color);
+ void setRotationAngle(int degrees);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+//! [0]
+
+//! [1]
+private:
+ QPainterPath path;
+ QColor fillColor1;
+ QColor fillColor2;
+ int penWidth;
+ QColor penColor;
+ int rotationAngle;
+};
+//! [1]
+
+#endif
diff --git a/examples/widgets/painting/painterpaths/window.cpp b/examples/widgets/painting/painterpaths/window.cpp
new file mode 100644
index 0000000000..3d3eef9d2b
--- /dev/null
+++ b/examples/widgets/painting/painterpaths/window.cpp
@@ -0,0 +1,289 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include <math.h>
+
+#include "renderarea.h"
+#include "window.h"
+
+//! [0]
+const float Pi = 3.14159f;
+//! [0]
+
+//! [1]
+Window::Window()
+{
+ QPainterPath rectPath;
+ rectPath.moveTo(20.0, 30.0);
+ rectPath.lineTo(80.0, 30.0);
+ rectPath.lineTo(80.0, 70.0);
+ rectPath.lineTo(20.0, 70.0);
+ rectPath.closeSubpath();
+//! [1]
+
+//! [2]
+ QPainterPath roundRectPath;
+ roundRectPath.moveTo(80.0, 35.0);
+ roundRectPath.arcTo(70.0, 30.0, 10.0, 10.0, 0.0, 90.0);
+ roundRectPath.lineTo(25.0, 30.0);
+ roundRectPath.arcTo(20.0, 30.0, 10.0, 10.0, 90.0, 90.0);
+ roundRectPath.lineTo(20.0, 65.0);
+ roundRectPath.arcTo(20.0, 60.0, 10.0, 10.0, 180.0, 90.0);
+ roundRectPath.lineTo(75.0, 70.0);
+ roundRectPath.arcTo(70.0, 60.0, 10.0, 10.0, 270.0, 90.0);
+ roundRectPath.closeSubpath();
+//! [2]
+
+//! [3]
+ QPainterPath ellipsePath;
+ ellipsePath.moveTo(80.0, 50.0);
+ ellipsePath.arcTo(20.0, 30.0, 60.0, 40.0, 0.0, 360.0);
+//! [3]
+
+//! [4]
+ QPainterPath piePath;
+ piePath.moveTo(50.0, 50.0);
+ piePath.arcTo(20.0, 30.0, 60.0, 40.0, 60.0, 240.0);
+ piePath.closeSubpath();
+//! [4]
+
+//! [5]
+ QPainterPath polygonPath;
+ polygonPath.moveTo(10.0, 80.0);
+ polygonPath.lineTo(20.0, 10.0);
+ polygonPath.lineTo(80.0, 30.0);
+ polygonPath.lineTo(90.0, 70.0);
+ polygonPath.closeSubpath();
+//! [5]
+
+//! [6]
+ QPainterPath groupPath;
+ groupPath.moveTo(60.0, 40.0);
+ groupPath.arcTo(20.0, 20.0, 40.0, 40.0, 0.0, 360.0);
+ groupPath.moveTo(40.0, 40.0);
+ groupPath.lineTo(40.0, 80.0);
+ groupPath.lineTo(80.0, 80.0);
+ groupPath.lineTo(80.0, 40.0);
+ groupPath.closeSubpath();
+//! [6]
+
+//! [7]
+ QPainterPath textPath;
+ QFont timesFont("Times", 50);
+ timesFont.setStyleStrategy(QFont::ForceOutline);
+ textPath.addText(10, 70, timesFont, tr("Qt"));
+//! [7]
+
+//! [8]
+ QPainterPath bezierPath;
+ bezierPath.moveTo(20, 30);
+ bezierPath.cubicTo(80, 0, 50, 50, 80, 80);
+//! [8]
+
+//! [9]
+ QPainterPath starPath;
+ starPath.moveTo(90, 50);
+ for (int i = 1; i < 5; ++i) {
+ starPath.lineTo(50 + 40 * cos(0.8 * i * Pi),
+ 50 + 40 * sin(0.8 * i * Pi));
+ }
+ starPath.closeSubpath();
+//! [9]
+
+//! [10]
+ renderAreas.push_back(new RenderArea(rectPath));
+ renderAreas.push_back(new RenderArea(roundRectPath));
+ renderAreas.push_back(new RenderArea(ellipsePath));
+ renderAreas.push_back(new RenderArea(piePath));
+ renderAreas.push_back(new RenderArea(polygonPath));
+ renderAreas.push_back(new RenderArea(groupPath));
+ renderAreas.push_back(new RenderArea(textPath));
+ renderAreas.push_back(new RenderArea(bezierPath));
+ renderAreas.push_back(new RenderArea(starPath));
+//! [10]
+
+//! [11]
+ fillRuleComboBox = new QComboBox;
+ fillRuleComboBox->addItem(tr("Odd Even"), Qt::OddEvenFill);
+ fillRuleComboBox->addItem(tr("Winding"), Qt::WindingFill);
+
+ fillRuleLabel = new QLabel(tr("Fill &Rule:"));
+ fillRuleLabel->setBuddy(fillRuleComboBox);
+//! [11]
+
+//! [12]
+ fillColor1ComboBox = new QComboBox;
+ populateWithColors(fillColor1ComboBox);
+ fillColor1ComboBox->setCurrentIndex(
+ fillColor1ComboBox->findText("mediumslateblue"));
+
+ fillColor2ComboBox = new QComboBox;
+ populateWithColors(fillColor2ComboBox);
+ fillColor2ComboBox->setCurrentIndex(
+ fillColor2ComboBox->findText("cornsilk"));
+
+ fillGradientLabel = new QLabel(tr("&Fill Gradient:"));
+ fillGradientLabel->setBuddy(fillColor1ComboBox);
+
+ fillToLabel = new QLabel(tr("to"));
+ fillToLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
+ penWidthSpinBox = new QSpinBox;
+ penWidthSpinBox->setRange(0, 20);
+
+ penWidthLabel = new QLabel(tr("&Pen Width:"));
+ penWidthLabel->setBuddy(penWidthSpinBox);
+
+ penColorComboBox = new QComboBox;
+ populateWithColors(penColorComboBox);
+ penColorComboBox->setCurrentIndex(
+ penColorComboBox->findText("darkslateblue"));
+
+ penColorLabel = new QLabel(tr("Pen &Color:"));
+ penColorLabel->setBuddy(penColorComboBox);
+
+ rotationAngleSpinBox = new QSpinBox;
+ rotationAngleSpinBox->setRange(0, 359);
+ rotationAngleSpinBox->setWrapping(true);
+ rotationAngleSpinBox->setSuffix(QLatin1String("\xB0"));
+
+ rotationAngleLabel = new QLabel(tr("&Rotation Angle:"));
+ rotationAngleLabel->setBuddy(rotationAngleSpinBox);
+//! [12]
+
+//! [16]
+ connect(fillRuleComboBox, SIGNAL(activated(int)),
+ this, SLOT(fillRuleChanged()));
+ connect(fillColor1ComboBox, SIGNAL(activated(int)),
+ this, SLOT(fillGradientChanged()));
+ connect(fillColor2ComboBox, SIGNAL(activated(int)),
+ this, SLOT(fillGradientChanged()));
+ connect(penColorComboBox, SIGNAL(activated(int)),
+ this, SLOT(penColorChanged()));
+
+ for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++) {
+ connect(penWidthSpinBox, SIGNAL(valueChanged(int)),
+ *it, SLOT(setPenWidth(int)));
+ connect(rotationAngleSpinBox, SIGNAL(valueChanged(int)),
+ *it, SLOT(setRotationAngle(int)));
+ }
+
+//! [16] //! [17]
+ QGridLayout *topLayout = new QGridLayout;
+
+ int i=0;
+ for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++, i++)
+ topLayout->addWidget(*it, i / 3, i % 3);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addLayout(topLayout, 0, 0, 1, 4);
+ mainLayout->addWidget(fillRuleLabel, 1, 0);
+ mainLayout->addWidget(fillRuleComboBox, 1, 1, 1, 3);
+ mainLayout->addWidget(fillGradientLabel, 2, 0);
+ mainLayout->addWidget(fillColor1ComboBox, 2, 1);
+ mainLayout->addWidget(fillToLabel, 2, 2);
+ mainLayout->addWidget(fillColor2ComboBox, 2, 3);
+ mainLayout->addWidget(penWidthLabel, 3, 0);
+ mainLayout->addWidget(penWidthSpinBox, 3, 1, 1, 3);
+ mainLayout->addWidget(penColorLabel, 4, 0);
+ mainLayout->addWidget(penColorComboBox, 4, 1, 1, 3);
+ mainLayout->addWidget(rotationAngleLabel, 5, 0);
+ mainLayout->addWidget(rotationAngleSpinBox, 5, 1, 1, 3);
+ setLayout(mainLayout);
+//! [17]
+
+//! [18]
+ fillRuleChanged();
+ fillGradientChanged();
+ penColorChanged();
+ penWidthSpinBox->setValue(2);
+
+ setWindowTitle(tr("Painter Paths"));
+}
+//! [18]
+
+//! [19]
+void Window::fillRuleChanged()
+{
+ Qt::FillRule rule = (Qt::FillRule)currentItemData(fillRuleComboBox).toInt();
+
+ for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++)
+ (*it)->setFillRule(rule);
+}
+//! [19]
+
+//! [20]
+void Window::fillGradientChanged()
+{
+ QColor color1 = qvariant_cast<QColor>(currentItemData(fillColor1ComboBox));
+ QColor color2 = qvariant_cast<QColor>(currentItemData(fillColor2ComboBox));
+
+ for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++)
+ (*it)->setFillGradient(color1, color2);
+}
+//! [20]
+
+//! [21]
+void Window::penColorChanged()
+{
+ QColor color = qvariant_cast<QColor>(currentItemData(penColorComboBox));
+
+ for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++)
+ (*it)->setPenColor(color);
+}
+//! [21]
+
+//! [22]
+void Window::populateWithColors(QComboBox *comboBox)
+{
+ QStringList colorNames = QColor::colorNames();
+ foreach (QString name, colorNames)
+ comboBox->addItem(name, QColor(name));
+}
+//! [22]
+
+//! [23]
+QVariant Window::currentItemData(QComboBox *comboBox)
+{
+ return comboBox->itemData(comboBox->currentIndex());
+}
+//! [23]
diff --git a/examples/widgets/painting/painterpaths/window.h b/examples/widgets/painting/painterpaths/window.h
new file mode 100644
index 0000000000..4c01719b16
--- /dev/null
+++ b/examples/widgets/painting/painterpaths/window.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QLabel;
+class QSpinBox;
+QT_END_NAMESPACE
+class RenderArea;
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private slots:
+ void fillRuleChanged();
+ void fillGradientChanged();
+ void penColorChanged();
+//! [0]
+
+//! [1]
+private:
+ void populateWithColors(QComboBox *comboBox);
+ QVariant currentItemData(QComboBox *comboBox);
+//! [1]
+
+//! [2]
+ QList<RenderArea*> renderAreas;
+ QLabel *fillRuleLabel;
+ QLabel *fillGradientLabel;
+ QLabel *fillToLabel;
+ QLabel *penWidthLabel;
+ QLabel *penColorLabel;
+ QLabel *rotationAngleLabel;
+ QComboBox *fillRuleComboBox;
+ QComboBox *fillColor1ComboBox;
+ QComboBox *fillColor2ComboBox;
+ QSpinBox *penWidthSpinBox;
+ QComboBox *penColorComboBox;
+ QSpinBox *rotationAngleSpinBox;
+};
+//! [2]
+
+#endif
diff --git a/examples/widgets/painting/painting.pro b/examples/widgets/painting/painting.pro
new file mode 100644
index 0000000000..927d94006b
--- /dev/null
+++ b/examples/widgets/painting/painting.pro
@@ -0,0 +1,36 @@
+TEMPLATE = subdirs
+SUBDIRS = basicdrawing \
+ concentriccircles \
+ examples_affine \
+ examples_composition \
+ examples_deform \
+ examples_gradients \
+ examples_pathstroke \
+ painting_shared \
+ imagecomposition \
+ painterpaths \
+ transformations \
+ fontsampler
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS painting.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting
+INSTALLS += target sources
+
+QT += widgets
+
+examples_affine.subdir = affine
+examples_composition.subdir = composition
+examples_deform.subdir = deform
+examples_gradients.subdir = gradients
+examples_pathstroke.subdir = pathstroke
+painting_shared.subdir = shared
+
+!ordered {
+ examples_affine.depends = painting_shared
+ examples_deform.depends = painting_shared
+ examples_gradients.depends = painting_shared
+ examples_composition.depends = painting_shared
+ examples_pathstroke.depends = painting_shared
+}
diff --git a/examples/widgets/painting/pathstroke/main.cpp b/examples/widgets/painting/pathstroke/main.cpp
new file mode 100644
index 0000000000..c969d975a3
--- /dev/null
+++ b/examples/widgets/painting/pathstroke/main.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "pathstroke.h"
+#include <QApplication>
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(pathstroke);
+
+ QApplication app(argc, argv);
+
+ bool smallScreen = QApplication::arguments().contains("-small-screen");
+
+ PathStrokeWidget pathStrokeWidget(smallScreen);
+ QStyle *arthurStyle = new ArthurStyle();
+ pathStrokeWidget.setStyle(arthurStyle);
+ QList<QWidget *> widgets = pathStrokeWidget.findChildren<QWidget *>();
+ foreach (QWidget *w, widgets) {
+ w->setStyle(arthurStyle);
+ w->setAttribute(Qt::WA_AcceptTouchEvents);
+ }
+
+ if (smallScreen)
+ pathStrokeWidget.showFullScreen();
+ else
+ pathStrokeWidget.show();
+
+#ifdef QT_KEYPAD_NAVIGATION
+ QApplication::setNavigationMode(Qt::NavigationModeCursorAuto);
+#endif
+ return app.exec();
+}
diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp
new file mode 100644
index 0000000000..76495cafea
--- /dev/null
+++ b/examples/widgets/painting/pathstroke/pathstroke.cpp
@@ -0,0 +1,685 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "pathstroke.h"
+#include "arthurstyle.h"
+#include "arthurwidgets.h"
+
+#include <stdio.h>
+
+extern void draw_round_rect(QPainter *p, const QRect &bounds, int radius);
+
+
+PathStrokeControls::PathStrokeControls(QWidget* parent, PathStrokeRenderer* renderer, bool smallScreen)
+ : QWidget(parent)
+{
+ m_renderer = renderer;
+
+ if (smallScreen)
+ layoutForSmallScreens();
+ else
+ layoutForDesktop();
+}
+
+void PathStrokeControls::createCommonControls(QWidget* parent)
+{
+ m_capGroup = new QGroupBox(parent);
+ m_capGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
+ QRadioButton *flatCap = new QRadioButton(m_capGroup);
+ QRadioButton *squareCap = new QRadioButton(m_capGroup);
+ QRadioButton *roundCap = new QRadioButton(m_capGroup);
+ m_capGroup->setTitle(tr("Cap Style"));
+ flatCap->setText(tr("Flat"));
+ squareCap->setText(tr("Square"));
+ roundCap->setText(tr("Round"));
+ flatCap->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ squareCap->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ roundCap->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
+ m_joinGroup = new QGroupBox(parent);
+ m_joinGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
+ QRadioButton *bevelJoin = new QRadioButton(m_joinGroup);
+ QRadioButton *miterJoin = new QRadioButton(m_joinGroup);
+ QRadioButton *roundJoin = new QRadioButton(m_joinGroup);
+ m_joinGroup->setTitle(tr("Join Style"));
+ bevelJoin->setText(tr("Bevel"));
+ miterJoin->setText(tr("Miter"));
+ roundJoin->setText(tr("Round"));
+
+ m_styleGroup = new QGroupBox(parent);
+ m_styleGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
+ QRadioButton *solidLine = new QRadioButton(m_styleGroup);
+ QRadioButton *dashLine = new QRadioButton(m_styleGroup);
+ QRadioButton *dotLine = new QRadioButton(m_styleGroup);
+ QRadioButton *dashDotLine = new QRadioButton(m_styleGroup);
+ QRadioButton *dashDotDotLine = new QRadioButton(m_styleGroup);
+ QRadioButton *customDashLine = new QRadioButton(m_styleGroup);
+ m_styleGroup->setTitle(tr("Pen Style"));
+
+ QPixmap line_solid(":res/images/line_solid.png");
+ solidLine->setIcon(line_solid);
+ solidLine->setIconSize(line_solid.size());
+ QPixmap line_dashed(":res/images/line_dashed.png");
+ dashLine->setIcon(line_dashed);
+ dashLine->setIconSize(line_dashed.size());
+ QPixmap line_dotted(":res/images/line_dotted.png");
+ dotLine->setIcon(line_dotted);
+ dotLine->setIconSize(line_dotted.size());
+ QPixmap line_dash_dot(":res/images/line_dash_dot.png");
+ dashDotLine->setIcon(line_dash_dot);
+ dashDotLine->setIconSize(line_dash_dot.size());
+ QPixmap line_dash_dot_dot(":res/images/line_dash_dot_dot.png");
+ dashDotDotLine->setIcon(line_dash_dot_dot);
+ dashDotDotLine->setIconSize(line_dash_dot_dot.size());
+ customDashLine->setText(tr("Custom"));
+
+ int fixedHeight = bevelJoin->sizeHint().height();
+ solidLine->setFixedHeight(fixedHeight);
+ dashLine->setFixedHeight(fixedHeight);
+ dotLine->setFixedHeight(fixedHeight);
+ dashDotLine->setFixedHeight(fixedHeight);
+ dashDotDotLine->setFixedHeight(fixedHeight);
+
+ m_pathModeGroup = new QGroupBox(parent);
+ m_pathModeGroup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
+ QRadioButton *curveMode = new QRadioButton(m_pathModeGroup);
+ QRadioButton *lineMode = new QRadioButton(m_pathModeGroup);
+ m_pathModeGroup->setTitle(tr("Line Style"));
+ curveMode->setText(tr("Curves"));
+ lineMode->setText(tr("Lines"));
+
+
+ // Layouts
+ QVBoxLayout *capGroupLayout = new QVBoxLayout(m_capGroup);
+ capGroupLayout->addWidget(flatCap);
+ capGroupLayout->addWidget(squareCap);
+ capGroupLayout->addWidget(roundCap);
+
+ QVBoxLayout *joinGroupLayout = new QVBoxLayout(m_joinGroup);
+ joinGroupLayout->addWidget(bevelJoin);
+ joinGroupLayout->addWidget(miterJoin);
+ joinGroupLayout->addWidget(roundJoin);
+
+ QVBoxLayout *styleGroupLayout = new QVBoxLayout(m_styleGroup);
+ styleGroupLayout->addWidget(solidLine);
+ styleGroupLayout->addWidget(dashLine);
+ styleGroupLayout->addWidget(dotLine);
+ styleGroupLayout->addWidget(dashDotLine);
+ styleGroupLayout->addWidget(dashDotDotLine);
+ styleGroupLayout->addWidget(customDashLine);
+
+ QVBoxLayout *pathModeGroupLayout = new QVBoxLayout(m_pathModeGroup);
+ pathModeGroupLayout->addWidget(curveMode);
+ pathModeGroupLayout->addWidget(lineMode);
+
+
+ // Connections
+ connect(flatCap, SIGNAL(clicked()), m_renderer, SLOT(setFlatCap()));
+ connect(squareCap, SIGNAL(clicked()), m_renderer, SLOT(setSquareCap()));
+ connect(roundCap, SIGNAL(clicked()), m_renderer, SLOT(setRoundCap()));
+
+ connect(bevelJoin, SIGNAL(clicked()), m_renderer, SLOT(setBevelJoin()));
+ connect(miterJoin, SIGNAL(clicked()), m_renderer, SLOT(setMiterJoin()));
+ connect(roundJoin, SIGNAL(clicked()), m_renderer, SLOT(setRoundJoin()));
+
+ connect(curveMode, SIGNAL(clicked()), m_renderer, SLOT(setCurveMode()));
+ connect(lineMode, SIGNAL(clicked()), m_renderer, SLOT(setLineMode()));
+
+ connect(solidLine, SIGNAL(clicked()), m_renderer, SLOT(setSolidLine()));
+ connect(dashLine, SIGNAL(clicked()), m_renderer, SLOT(setDashLine()));
+ connect(dotLine, SIGNAL(clicked()), m_renderer, SLOT(setDotLine()));
+ connect(dashDotLine, SIGNAL(clicked()), m_renderer, SLOT(setDashDotLine()));
+ connect(dashDotDotLine, SIGNAL(clicked()), m_renderer, SLOT(setDashDotDotLine()));
+ connect(customDashLine, SIGNAL(clicked()), m_renderer, SLOT(setCustomDashLine()));
+
+ // Set the defaults:
+ flatCap->setChecked(true);
+ bevelJoin->setChecked(true);
+ curveMode->setChecked(true);
+ solidLine->setChecked(true);
+}
+
+
+void PathStrokeControls::layoutForDesktop()
+{
+ QGroupBox *mainGroup = new QGroupBox(this);
+ mainGroup->setFixedWidth(180);
+ mainGroup->setTitle(tr("Path Stroking"));
+
+ createCommonControls(mainGroup);
+
+ QGroupBox* penWidthGroup = new QGroupBox(mainGroup);
+ QSlider *penWidth = new QSlider(Qt::Horizontal, penWidthGroup);
+ penWidth->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ penWidthGroup->setTitle(tr("Pen Width"));
+ penWidth->setRange(0, 500);
+
+ QPushButton *animated = new QPushButton(mainGroup);
+ animated->setText(tr("Animate"));
+ animated->setCheckable(true);
+
+ QPushButton *showSourceButton = new QPushButton(mainGroup);
+ showSourceButton->setText(tr("Show Source"));
+#ifdef QT_OPENGL_SUPPORT
+ QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(true);
+ enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
+ if (!QGLFormat::hasOpenGL())
+ enableOpenGLButton->hide();
+#endif
+ QPushButton *whatsThisButton = new QPushButton(mainGroup);
+ whatsThisButton->setText(tr("What's This?"));
+ whatsThisButton->setCheckable(true);
+
+
+ // Layouts:
+ QVBoxLayout *penWidthLayout = new QVBoxLayout(penWidthGroup);
+ penWidthLayout->addWidget(penWidth);
+
+ QVBoxLayout * mainLayout = new QVBoxLayout(this);
+ mainLayout->setMargin(0);
+ mainLayout->addWidget(mainGroup);
+
+ QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
+ mainGroupLayout->setMargin(3);
+ mainGroupLayout->addWidget(m_capGroup);
+ mainGroupLayout->addWidget(m_joinGroup);
+ mainGroupLayout->addWidget(m_styleGroup);
+ mainGroupLayout->addWidget(penWidthGroup);
+ mainGroupLayout->addWidget(m_pathModeGroup);
+ mainGroupLayout->addWidget(animated);
+ mainGroupLayout->addStretch(1);
+ mainGroupLayout->addWidget(showSourceButton);
+#ifdef QT_OPENGL_SUPPORT
+ mainGroupLayout->addWidget(enableOpenGLButton);
+#endif
+ mainGroupLayout->addWidget(whatsThisButton);
+
+
+ // Set up connections
+ connect(animated, SIGNAL(toggled(bool)),
+ m_renderer, SLOT(setAnimation(bool)));
+
+ connect(penWidth, SIGNAL(valueChanged(int)),
+ m_renderer, SLOT(setPenWidth(int)));
+
+ connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource()));
+#ifdef QT_OPENGL_SUPPORT
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));
+#endif
+ connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool)));
+ connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)),
+ whatsThisButton, SLOT(setChecked(bool)));
+
+
+ // Set the defaults
+ animated->setChecked(true);
+ penWidth->setValue(50);
+
+}
+
+void PathStrokeControls::layoutForSmallScreens()
+{
+ createCommonControls(this);
+
+ m_capGroup->layout()->setMargin(0);
+ m_joinGroup->layout()->setMargin(0);
+ m_styleGroup->layout()->setMargin(0);
+ m_pathModeGroup->layout()->setMargin(0);
+
+ QPushButton* okBtn = new QPushButton(tr("OK"), this);
+ okBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ okBtn->setMinimumSize(100,okBtn->minimumSize().height());
+
+ QPushButton* quitBtn = new QPushButton(tr("Quit"), this);
+ quitBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ quitBtn->setMinimumSize(100, okBtn->minimumSize().height());
+
+ QLabel *penWidthLabel = new QLabel(tr(" Width:"));
+ QSlider *penWidth = new QSlider(Qt::Horizontal, this);
+ penWidth->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ penWidth->setRange(0, 500);
+
+#ifdef QT_OPENGL_SUPPORT
+ QPushButton *enableOpenGLButton = new QPushButton(this);
+ enableOpenGLButton->setText(tr("Use OpenGL"));
+ enableOpenGLButton->setCheckable(true);
+ enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
+ if (!QGLFormat::hasOpenGL())
+ enableOpenGLButton->hide();
+#endif
+
+ // Layouts:
+ QHBoxLayout *penWidthLayout = new QHBoxLayout(0);
+ penWidthLayout->addWidget(penWidthLabel, 0, Qt::AlignRight);
+ penWidthLayout->addWidget(penWidth);
+
+ QVBoxLayout *leftLayout = new QVBoxLayout(0);
+ leftLayout->addWidget(m_capGroup);
+ leftLayout->addWidget(m_joinGroup);
+#ifdef QT_OPENGL_SUPPORT
+ leftLayout->addWidget(enableOpenGLButton);
+#endif
+ leftLayout->addLayout(penWidthLayout);
+
+ QVBoxLayout *rightLayout = new QVBoxLayout(0);
+ rightLayout->addWidget(m_styleGroup);
+ rightLayout->addWidget(m_pathModeGroup);
+
+ QGridLayout *mainLayout = new QGridLayout(this);
+ mainLayout->setMargin(0);
+
+ // Add spacers around the form items so we don't look stupid at higher resolutions
+ mainLayout->addItem(new QSpacerItem(0,0), 0, 0, 1, 4);
+ mainLayout->addItem(new QSpacerItem(0,0), 1, 0, 2, 1);
+ mainLayout->addItem(new QSpacerItem(0,0), 1, 3, 2, 1);
+ mainLayout->addItem(new QSpacerItem(0,0), 3, 0, 1, 4);
+
+ mainLayout->addLayout(leftLayout, 1, 1);
+ mainLayout->addLayout(rightLayout, 1, 2);
+ mainLayout->addWidget(quitBtn, 2, 1, Qt::AlignHCenter | Qt::AlignTop);
+ mainLayout->addWidget(okBtn, 2, 2, Qt::AlignHCenter | Qt::AlignTop);
+
+#ifdef QT_OPENGL_SUPPORT
+ connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));
+#endif
+
+ connect(penWidth, SIGNAL(valueChanged(int)), m_renderer, SLOT(setPenWidth(int)));
+ connect(quitBtn, SIGNAL(clicked()), this, SLOT(emitQuitSignal()));
+ connect(okBtn, SIGNAL(clicked()), this, SLOT(emitOkSignal()));
+
+ m_renderer->setAnimation(true);
+ penWidth->setValue(50);
+}
+
+void PathStrokeControls::emitQuitSignal()
+{ emit quitPressed(); }
+
+void PathStrokeControls::emitOkSignal()
+{ emit okPressed(); }
+
+
+PathStrokeWidget::PathStrokeWidget(bool smallScreen)
+{
+ setWindowTitle(tr("Path Stroking"));
+
+ // Widget construction and property setting
+ m_renderer = new PathStrokeRenderer(this, smallScreen);
+
+ m_controls = new PathStrokeControls(0, m_renderer, smallScreen);
+
+ // Layouting
+ QHBoxLayout *viewLayout = new QHBoxLayout(this);
+ viewLayout->addWidget(m_renderer);
+
+ if (!smallScreen)
+ viewLayout->addWidget(m_controls);
+
+ m_renderer->loadSourceFile(":res/pathstroke/pathstroke.cpp");
+ m_renderer->loadDescription(":res/pathstroke/pathstroke.html");
+
+ connect(m_renderer, SIGNAL(clicked()), this, SLOT(showControls()));
+ connect(m_controls, SIGNAL(okPressed()), this, SLOT(hideControls()));
+ connect(m_controls, SIGNAL(quitPressed()), QApplication::instance(), SLOT(quit()));
+}
+
+
+void PathStrokeWidget::showControls()
+{
+ m_controls->showFullScreen();
+}
+
+
+void PathStrokeWidget::hideControls()
+{
+ m_controls->hide();
+}
+
+
+void PathStrokeWidget::setStyle( QStyle * style )
+{
+ QWidget::setStyle(style);
+ if (m_controls != 0)
+ {
+ m_controls->setStyle(style);
+
+ QList<QWidget *> widgets = m_controls->findChildren<QWidget *>();
+ foreach (QWidget *w, widgets)
+ w->setStyle(style);
+ }
+}
+
+
+PathStrokeRenderer::PathStrokeRenderer(QWidget *parent, bool smallScreen)
+ : ArthurFrame(parent)
+{
+ m_smallScreen = smallScreen;
+ m_pointSize = 10;
+ m_activePoint = -1;
+ m_capStyle = Qt::FlatCap;
+ m_joinStyle = Qt::BevelJoin;
+ m_pathMode = CurveMode;
+ m_penWidth = 1;
+ m_penStyle = Qt::SolidLine;
+ m_wasAnimated = true;
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ setAttribute(Qt::WA_AcceptTouchEvents);
+}
+
+void PathStrokeRenderer::paint(QPainter *painter)
+{
+ if (m_points.isEmpty())
+ initializePoints();
+
+ painter->setRenderHint(QPainter::Antialiasing);
+
+ QPalette pal = palette();
+ painter->setPen(Qt::NoPen);
+
+ // Construct the path
+ QPainterPath path;
+ path.moveTo(m_points.at(0));
+
+ if (m_pathMode == LineMode) {
+ for (int i=1; i<m_points.size(); ++i) {
+ path.lineTo(m_points.at(i));
+ }
+ } else {
+ int i=1;
+ while (i + 2 < m_points.size()) {
+ path.cubicTo(m_points.at(i), m_points.at(i+1), m_points.at(i+2));
+ i += 3;
+ }
+ while (i < m_points.size()) {
+ path.lineTo(m_points.at(i));
+ ++i;
+ }
+ }
+
+ // Draw the path
+ {
+ QColor lg = Qt::red;
+
+ // The "custom" pen
+ if (m_penStyle == Qt::NoPen) {
+ QPainterPathStroker stroker;
+ stroker.setWidth(m_penWidth);
+ stroker.setJoinStyle(m_joinStyle);
+ stroker.setCapStyle(m_capStyle);
+
+ QVector<qreal> dashes;
+ qreal space = 4;
+ dashes << 1 << space
+ << 3 << space
+ << 9 << space
+ << 27 << space
+ << 9 << space
+ << 3 << space;
+ stroker.setDashPattern(dashes);
+ QPainterPath stroke = stroker.createStroke(path);
+ painter->fillPath(stroke, lg);
+
+ } else {
+ QPen pen(lg, m_penWidth, m_penStyle, m_capStyle, m_joinStyle);
+ painter->strokePath(path, pen);
+ }
+ }
+
+ if (1) {
+ // Draw the control points
+ painter->setPen(QColor(50, 100, 120, 200));
+ painter->setBrush(QColor(200, 200, 210, 120));
+ for (int i=0; i<m_points.size(); ++i) {
+ QPointF pos = m_points.at(i);
+ painter->drawEllipse(QRectF(pos.x() - m_pointSize,
+ pos.y() - m_pointSize,
+ m_pointSize*2, m_pointSize*2));
+ }
+ painter->setPen(QPen(Qt::lightGray, 0, Qt::SolidLine));
+ painter->setBrush(Qt::NoBrush);
+ painter->drawPolyline(m_points);
+ }
+
+}
+
+void PathStrokeRenderer::initializePoints()
+{
+ const int count = 7;
+ m_points.clear();
+ m_vectors.clear();
+
+ QMatrix m;
+ qreal rot = 360 / count;
+ QPointF center(width() / 2, height() / 2);
+ QMatrix vm;
+ vm.shear(2, -1);
+ vm.scale(3, 3);
+
+ for (int i=0; i<count; ++i) {
+ m_vectors << QPointF(.1f, .25f) * (m * vm);
+ m_points << QPointF(0, 100) * m + center;
+ m.rotate(rot);
+ }
+}
+
+void PathStrokeRenderer::updatePoints()
+{
+ qreal pad = 10;
+ qreal left = pad;
+ qreal right = width() - pad;
+ qreal top = pad;
+ qreal bottom = height() - pad;
+
+ Q_ASSERT(m_points.size() == m_vectors.size());
+ for (int i=0; i<m_points.size(); ++i) {
+ QPointF pos = m_points.at(i);
+ QPointF vec = m_vectors.at(i);
+ pos += vec;
+ if (pos.x() < left || pos.x() > right) {
+ vec.setX(-vec.x());
+ pos.setX(pos.x() < left ? left : right);
+ } if (pos.y() < top || pos.y() > bottom) {
+ vec.setY(-vec.y());
+ pos.setY(pos.y() < top ? top : bottom);
+ }
+ m_points[i] = pos;
+ m_vectors[i] = vec;
+ }
+ update();
+}
+
+void PathStrokeRenderer::mousePressEvent(QMouseEvent *e)
+{
+ if (!m_fingerPointMapping.isEmpty())
+ return;
+ setDescriptionEnabled(false);
+ m_activePoint = -1;
+ qreal distance = -1;
+ for (int i=0; i<m_points.size(); ++i) {
+ qreal d = QLineF(e->pos(), m_points.at(i)).length();
+ if ((distance < 0 && d < 8 * m_pointSize) || d < distance) {
+ distance = d;
+ m_activePoint = i;
+ }
+ }
+
+ if (m_activePoint != -1) {
+ m_wasAnimated = m_timer.isActive();
+ setAnimation(false);
+ mouseMoveEvent(e);
+ }
+
+ // If we're not running in small screen mode, always assume we're dragging
+ m_mouseDrag = !m_smallScreen;
+ m_mousePress = e->pos();
+}
+
+void PathStrokeRenderer::mouseMoveEvent(QMouseEvent *e)
+{
+ if (!m_fingerPointMapping.isEmpty())
+ return;
+ // If we've moved more then 25 pixels, assume user is dragging
+ if (!m_mouseDrag && QPoint(m_mousePress - e->pos()).manhattanLength() > 25)
+ m_mouseDrag = true;
+
+ if (m_mouseDrag && m_activePoint >= 0 && m_activePoint < m_points.size()) {
+ m_points[m_activePoint] = e->pos();
+ update();
+ }
+}
+
+void PathStrokeRenderer::mouseReleaseEvent(QMouseEvent *)
+{
+ if (!m_fingerPointMapping.isEmpty())
+ return;
+ m_activePoint = -1;
+ setAnimation(m_wasAnimated);
+
+ if (!m_mouseDrag && m_smallScreen)
+ emit clicked();
+}
+
+void PathStrokeRenderer::timerEvent(QTimerEvent *e)
+{
+ if (e->timerId() == m_timer.timerId()) {
+ updatePoints();
+ } // else if (e->timerId() == m_fpsTimer.timerId()) {
+// emit frameRate(m_frameCount);
+// m_frameCount = 0;
+// }
+}
+
+bool PathStrokeRenderer::event(QEvent *e)
+{
+ bool touchBegin = false;
+ switch (e->type()) {
+ case QEvent::TouchBegin:
+ touchBegin = true;
+ case QEvent::TouchUpdate:
+ {
+ const QTouchEvent *const event = static_cast<const QTouchEvent*>(e);
+ const QList<QTouchEvent::TouchPoint> points = event->touchPoints();
+ foreach (const QTouchEvent::TouchPoint &touchPoint, points) {
+ const int id = touchPoint.id();
+ switch (touchPoint.state()) {
+ case Qt::TouchPointPressed:
+ {
+ // find the point, move it
+ QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
+ int activePoint = -1;
+ qreal distance = -1;
+ const int pointsCount = m_points.size();
+ for (int i=0; i<pointsCount; ++i) {
+ if (activePoints.contains(i))
+ continue;
+
+ qreal d = QLineF(touchPoint.pos(), m_points.at(i)).length();
+ if ((distance < 0 && d < 12 * m_pointSize) || d < distance) {
+ distance = d;
+ activePoint = i;
+ }
+ }
+ if (activePoint != -1) {
+ m_fingerPointMapping.insert(touchPoint.id(), activePoint);
+ m_points[activePoint] = touchPoint.pos();
+ }
+ }
+ break;
+ case Qt::TouchPointReleased:
+ {
+ // move the point and release
+ QHash<int,int>::iterator it = m_fingerPointMapping.find(id);
+ m_points[it.value()] = touchPoint.pos();
+ m_fingerPointMapping.erase(it);
+ }
+ break;
+ case Qt::TouchPointMoved:
+ {
+ // move the point
+ const int pointIdx = m_fingerPointMapping.value(id, -1);
+ if (pointIdx >= 0)
+ m_points[pointIdx] = touchPoint.pos();
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ if (m_fingerPointMapping.isEmpty()) {
+ e->ignore();
+ return false;
+ } else {
+ if (touchBegin) {
+ m_wasAnimated = m_timer.isActive();
+ setAnimation(false);
+ }
+ update();
+ return true;
+ }
+ }
+ break;
+ case QEvent::TouchEnd:
+ if (m_fingerPointMapping.isEmpty()) {
+ e->ignore();
+ return false;
+ }
+ m_fingerPointMapping.clear();
+ setAnimation(m_wasAnimated);
+ return true;
+ break;
+ default:
+ break;
+ }
+ return QWidget::event(e);
+}
+
+void PathStrokeRenderer::setAnimation(bool animation)
+{
+ m_timer.stop();
+// m_fpsTimer.stop();
+
+ if (animation) {
+ m_timer.start(25, this);
+// m_fpsTimer.start(1000, this);
+// m_frameCount = 0;
+ }
+}
diff --git a/examples/widgets/painting/pathstroke/pathstroke.h b/examples/widgets/painting/pathstroke/pathstroke.h
new file mode 100644
index 0000000000..743a757b0a
--- /dev/null
+++ b/examples/widgets/painting/pathstroke/pathstroke.h
@@ -0,0 +1,171 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PATHSTROKE_H
+#define PATHSTROKE_H
+
+#include "arthurwidgets.h"
+#include <QtWidgets>
+
+class PathStrokeRenderer : public ArthurFrame
+{
+ Q_OBJECT
+ Q_PROPERTY(bool animation READ animation WRITE setAnimation)
+ Q_PROPERTY(qreal penWidth READ realPenWidth WRITE setRealPenWidth)
+public:
+ enum PathMode { CurveMode, LineMode };
+
+ PathStrokeRenderer(QWidget *parent, bool smallScreen = false);
+
+ void paint(QPainter *);
+ void mousePressEvent(QMouseEvent *e);
+ void mouseMoveEvent(QMouseEvent *e);
+ void mouseReleaseEvent(QMouseEvent *e);
+ void timerEvent(QTimerEvent *e);
+ bool event(QEvent *e);
+
+ QSize sizeHint() const { return QSize(500, 500); }
+
+ bool animation() const { return m_timer.isActive(); }
+
+ qreal realPenWidth() const { return m_penWidth; }
+ void setRealPenWidth(qreal penWidth) { m_penWidth = penWidth; update(); }
+
+signals:
+ void clicked();
+
+public slots:
+ void setPenWidth(int penWidth) { m_penWidth = penWidth / 10.0; update(); }
+ void setAnimation(bool animation);
+
+ void setFlatCap() { m_capStyle = Qt::FlatCap; update(); }
+ void setSquareCap() { m_capStyle = Qt::SquareCap; update(); }
+ void setRoundCap() { m_capStyle = Qt::RoundCap; update(); }
+
+ void setBevelJoin() { m_joinStyle = Qt::BevelJoin; update(); }
+ void setMiterJoin() { m_joinStyle = Qt::MiterJoin; update(); }
+ void setRoundJoin() { m_joinStyle = Qt::RoundJoin; update(); }
+
+ void setCurveMode() { m_pathMode = CurveMode; update(); }
+ void setLineMode() { m_pathMode = LineMode; update(); }
+
+ void setSolidLine() { m_penStyle = Qt::SolidLine; update(); }
+ void setDashLine() { m_penStyle = Qt::DashLine; update(); }
+ void setDotLine() { m_penStyle = Qt::DotLine; update(); }
+ void setDashDotLine() { m_penStyle = Qt::DashDotLine; update(); }
+ void setDashDotDotLine() { m_penStyle = Qt::DashDotDotLine; update(); }
+ void setCustomDashLine() { m_penStyle = Qt::NoPen; update(); }
+
+private:
+ void initializePoints();
+ void updatePoints();
+
+ QBasicTimer m_timer;
+
+ PathMode m_pathMode;
+
+ bool m_wasAnimated;
+
+ qreal m_penWidth;
+ int m_pointCount;
+ int m_pointSize;
+ int m_activePoint;
+ QVector<QPointF> m_points;
+ QVector<QPointF> m_vectors;
+
+ Qt::PenJoinStyle m_joinStyle;
+ Qt::PenCapStyle m_capStyle;
+
+ Qt::PenStyle m_penStyle;
+
+ bool m_smallScreen;
+ QPoint m_mousePress;
+ bool m_mouseDrag;
+
+ QHash<int, int> m_fingerPointMapping;
+};
+
+class PathStrokeControls : public QWidget
+{
+ Q_OBJECT
+public:
+ PathStrokeControls(QWidget* parent, PathStrokeRenderer* renderer, bool smallScreen);
+
+signals:
+ void okPressed();
+ void quitPressed();
+
+private:
+ PathStrokeRenderer* m_renderer;
+
+ QGroupBox *m_capGroup;
+ QGroupBox *m_joinGroup;
+ QGroupBox *m_styleGroup;
+ QGroupBox *m_pathModeGroup;
+
+ void createCommonControls(QWidget* parent);
+ void layoutForDesktop();
+ void layoutForSmallScreens();
+
+private slots:
+ void emitQuitSignal();
+ void emitOkSignal();
+
+};
+
+class PathStrokeWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ PathStrokeWidget(bool smallScreen);
+ void setStyle ( QStyle * style );
+
+private:
+ PathStrokeRenderer *m_renderer;
+ PathStrokeControls *m_controls;
+
+private slots:
+ void showControls();
+ void hideControls();
+
+};
+
+#endif // PATHSTROKE_H
diff --git a/examples/widgets/painting/pathstroke/pathstroke.html b/examples/widgets/painting/pathstroke/pathstroke.html
new file mode 100644
index 0000000000..9e7e50de76
--- /dev/null
+++ b/examples/widgets/painting/pathstroke/pathstroke.html
@@ -0,0 +1,20 @@
+<html>
+<center>
+<h2>Primitive Stroking</h2>
+</center>
+
+<p>In this demo we show some of the various types of pens that can be
+used in Qt.</p>
+
+<p>Qt defines cap styles for how the end points are treated and join
+styles for how path segments are joined together. A standard set of
+predefined dash patterns are also included that can be used with
+<code>QPen</code>.</p>
+
+<p>In addition to the predefined patterns available in
+<code>QPen</code> we also demonstrate direct use of the
+<code>QPainterPathStroker</code> class which can be used to define
+custom dash patterns. You can see this by enabling the
+<i>Custom Pattern</i> option.</p>
+
+</html>
diff --git a/examples/widgets/painting/pathstroke/pathstroke.pro b/examples/widgets/painting/pathstroke/pathstroke.pro
new file mode 100644
index 0000000000..916866d1f2
--- /dev/null
+++ b/examples/widgets/painting/pathstroke/pathstroke.pro
@@ -0,0 +1,21 @@
+SOURCES += main.cpp pathstroke.cpp
+HEADERS += pathstroke.h
+
+SHARED_FOLDER = ../shared
+
+include($$SHARED_FOLDER/shared.pri)
+
+RESOURCES += pathstroke.qrc
+
+contains(QT_CONFIG, opengl) {
+ DEFINES += QT_OPENGL_SUPPORT
+ QT += opengl
+}
+QT += widgets
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/pathstroke
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/pathstroke
+INSTALLS += target sources
+
diff --git a/examples/widgets/painting/pathstroke/pathstroke.qrc b/examples/widgets/painting/pathstroke/pathstroke.qrc
new file mode 100644
index 0000000000..a9a723409e
--- /dev/null
+++ b/examples/widgets/painting/pathstroke/pathstroke.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res/pathstroke">
+ <file>pathstroke.cpp</file>
+ <file>pathstroke.html</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/painting/shared/arthurstyle.cpp b/examples/widgets/painting/shared/arthurstyle.cpp
new file mode 100644
index 0000000000..4bd34464bf
--- /dev/null
+++ b/examples/widgets/painting/shared/arthurstyle.cpp
@@ -0,0 +1,452 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "arthurstyle.h"
+#include "arthurwidgets.h"
+#include <QLayout>
+#include <QPainter>
+#include <QPainterPath>
+#include <QPixmapCache>
+#include <QRadioButton>
+#include <QString>
+#include <QStyleOption>
+#include <QtDebug>
+
+QPixmap cached(const QString &img)
+{
+ if (QPixmap *p = QPixmapCache::find(img))
+ return *p;
+
+ QPixmap pm;
+ pm = QPixmap::fromImage(QImage(img), Qt::OrderedDither | Qt::OrderedAlphaDither);
+ if (pm.isNull())
+ return QPixmap();
+
+ QPixmapCache::insert(img, pm);
+ return pm;
+}
+
+
+ArthurStyle::ArthurStyle()
+ : QWindowsStyle()
+{
+ Q_INIT_RESOURCE(shared);
+}
+
+
+void ArthurStyle::drawHoverRect(QPainter *painter, const QRect &r) const
+{
+ qreal h = r.height();
+ qreal h2 = r.height() / qreal(2);
+ QPainterPath path;
+ path.addRect(r.x() + h2, r.y() + 0, r.width() - h2 * 2, r.height());
+ path.addEllipse(r.x(), r.y(), h, h);
+ path.addEllipse(r.x() + r.width() - h, r.y(), h, h);
+ path.setFillRule(Qt::WindingFill);
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(QColor(191, 215, 191));
+ painter->setRenderHint(QPainter::Antialiasing);
+ painter->drawPath(path);
+}
+
+
+void ArthurStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
+ QPainter *painter, const QWidget *widget) const
+{
+
+ Q_ASSERT(option);
+ switch (element) {
+ case PE_FrameFocusRect:
+ break;
+
+ case PE_IndicatorRadioButton:
+ if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
+ bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);
+ painter->save();
+ QPixmap radio;
+ if (hover)
+ drawHoverRect(painter, widget->rect());
+
+ if (button->state & State_Sunken)
+ radio = cached(":res/images/radiobutton-on.png");
+ else if (button->state & State_On)
+ radio = cached(":res/images/radiobutton_on.png");
+ else
+ radio = cached(":res/images/radiobutton_off.png");
+ painter->drawPixmap(button->rect.topLeft(), radio);
+
+ painter->restore();
+ }
+ break;
+
+ case PE_PanelButtonCommand:
+ if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
+ bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);
+
+ painter->save();
+ const QPushButton *pushButton = qobject_cast<const QPushButton *>(widget);
+ Q_ASSERT(pushButton);
+ QWidget *parent = pushButton->parentWidget();
+ if (parent && qobject_cast<QGroupBox *>(parent)) {
+ QLinearGradient lg(0, 0, 0, parent->height());
+ lg.setColorAt(0, QColor(224,224,224));
+ lg.setColorAt(1, QColor(255,255,255));
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(lg);
+ painter->setBrushOrigin(-widget->mapToParent(QPoint(0,0)));
+ painter->drawRect(button->rect);
+ painter->setBrushOrigin(0,0);
+ }
+
+ bool down = (button->state & State_Sunken) || (button->state & State_On);
+
+ QPixmap left, right, mid;
+ if (down) {
+ left = cached(":res/images/button_pressed_cap_left.png");
+ right = cached(":res/images/button_pressed_cap_right.png");
+ mid = cached(":res/images/button_pressed_stretch.png");
+ } else {
+ left = cached(":res/images/button_normal_cap_left.png");
+ right = cached(":res/images/button_normal_cap_right.png");
+ mid = cached(":res/images/button_normal_stretch.png");
+ }
+ painter->drawPixmap(button->rect.topLeft(), left);
+ painter->drawTiledPixmap(QRect(button->rect.x() + left.width(),
+ button->rect.y(),
+ button->rect.width() - left.width() - right.width(),
+ left.height()),
+ mid);
+ painter->drawPixmap(button->rect.x() + button->rect.width() - right.width(),
+ button->rect.y(),
+ right);
+ if (hover)
+ painter->fillRect(widget->rect().adjusted(3,5,-3,-5), QColor(31,127,31,63));
+ painter->restore();
+ }
+ break;
+
+ case PE_FrameGroupBox:
+ if (const QStyleOptionFrameV2 *group
+ = qstyleoption_cast<const QStyleOptionFrameV2 *>(option)) {
+ const QRect &r = group->rect;
+
+ painter->save();
+ int radius = 14;
+ int radius2 = radius*2;
+ QPainterPath clipPath;
+ clipPath.moveTo(radius, 0);
+ clipPath.arcTo(r.right() - radius2, 0, radius2, radius2, 90, -90);
+ clipPath.arcTo(r.right() - radius2, r.bottom() - radius2, radius2, radius2, 0, -90);
+ clipPath.arcTo(r.left(), r.bottom() - radius2, radius2, radius2, 270, -90);
+ clipPath.arcTo(r.left(), r.top(), radius2, radius2, 180, -90);
+ painter->setClipPath(clipPath);
+ QPixmap titleStretch = cached(":res/images/title_stretch.png");
+ QPixmap topLeft = cached(":res/images/groupframe_topleft.png");
+ QPixmap topRight = cached(":res/images/groupframe_topright.png");
+ QPixmap bottomLeft = cached(":res/images/groupframe_bottom_left.png");
+ QPixmap bottomRight = cached(":res/images/groupframe_bottom_right.png");
+ QPixmap leftStretch = cached(":res/images/groupframe_left_stretch.png");
+ QPixmap topStretch = cached(":res/images/groupframe_top_stretch.png");
+ QPixmap rightStretch = cached(":res/images/groupframe_right_stretch.png");
+ QPixmap bottomStretch = cached(":res/images/groupframe_bottom_stretch.png");
+ QLinearGradient lg(0, 0, 0, r.height());
+ lg.setColorAt(0, QColor(224,224,224));
+ lg.setColorAt(1, QColor(255,255,255));
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(lg);
+ painter->drawRect(r.adjusted(0, titleStretch.height()/2, 0, 0));
+ painter->setClipping(false);
+
+ int topFrameOffset = titleStretch.height()/2 - 2;
+ painter->drawPixmap(r.topLeft() + QPoint(0, topFrameOffset), topLeft);
+ painter->drawPixmap(r.topRight() - QPoint(topRight.width()-1, 0)
+ + QPoint(0, topFrameOffset), topRight);
+ painter->drawPixmap(r.bottomLeft() - QPoint(0, bottomLeft.height()-1), bottomLeft);
+ painter->drawPixmap(r.bottomRight() - QPoint(bottomRight.width()-1,
+ bottomRight.height()-1), bottomRight);
+
+ QRect left = r;
+ left.setY(r.y() + topLeft.height() + topFrameOffset);
+ left.setWidth(leftStretch.width());
+ left.setHeight(r.height() - topLeft.height() - bottomLeft.height() - topFrameOffset);
+ painter->drawTiledPixmap(left, leftStretch);
+
+ QRect top = r;
+ top.setX(r.x() + topLeft.width());
+ top.setY(r.y() + topFrameOffset);
+ top.setWidth(r.width() - topLeft.width() - topRight.width());
+ top.setHeight(topLeft.height());
+ painter->drawTiledPixmap(top, topStretch);
+
+ QRect right = r;
+ right.setX(r.right() - rightStretch.width()+1);
+ right.setY(r.y() + topRight.height() + topFrameOffset);
+ right.setWidth(rightStretch.width());
+ right.setHeight(r.height() - topRight.height()
+ - bottomRight.height() - topFrameOffset);
+ painter->drawTiledPixmap(right, rightStretch);
+
+ QRect bottom = r;
+ bottom.setX(r.x() + bottomLeft.width());
+ bottom.setY(r.bottom() - bottomStretch.height()+1);
+ bottom.setWidth(r.width() - bottomLeft.width() - bottomRight.width());
+ bottom.setHeight(bottomLeft.height());
+ painter->drawTiledPixmap(bottom, bottomStretch);
+ painter->restore();
+ }
+ break;
+
+ default:
+ QWindowsStyle::drawPrimitive(element, option, painter, widget);
+ break;
+ }
+ return;
+}
+
+
+void ArthurStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
+ QPainter *painter, const QWidget *widget) const
+{
+ switch (control) {
+ case CC_Slider:
+ if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
+ QRect groove = subControlRect(CC_Slider, option, SC_SliderGroove, widget);
+ QRect handle = subControlRect(CC_Slider, option, SC_SliderHandle, widget);
+
+ painter->save();
+
+ bool hover = (slider->state & State_Enabled) && (slider->state & State_MouseOver);
+ if (hover) {
+ QRect moderated = widget->rect().adjusted(0, 4, 0, -4);
+ drawHoverRect(painter, moderated);
+ }
+
+ if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
+ QPixmap grv = cached(":res/images/slider_bar.png");
+ painter->drawPixmap(QRect(groove.x() + 5, groove.y(),
+ groove.width() - 10, grv.height()),
+ grv);
+ }
+ if ((option->subControls & SC_SliderHandle) && handle.isValid()) {
+ QPixmap hndl = cached(":res/images/slider_thumb_on.png");
+ painter->drawPixmap(handle.topLeft(), hndl);
+ }
+
+ painter->restore();
+ }
+ break;
+ case CC_GroupBox:
+ if (const QStyleOptionGroupBox *groupBox
+ = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
+ QStyleOptionGroupBox groupBoxCopy(*groupBox);
+ groupBoxCopy.subControls &= ~SC_GroupBoxLabel;
+ QWindowsStyle::drawComplexControl(control, &groupBoxCopy, painter, widget);
+
+ if (groupBox->subControls & SC_GroupBoxLabel) {
+ const QRect &r = groupBox->rect;
+ QPixmap titleLeft = cached(":res/images/title_cap_left.png");
+ QPixmap titleRight = cached(":res/images/title_cap_right.png");
+ QPixmap titleStretch = cached(":res/images/title_stretch.png");
+ int txt_width = groupBox->fontMetrics.width(groupBox->text) + 20;
+ painter->drawPixmap(r.center().x() - txt_width/2, 0, titleLeft);
+ QRect tileRect = subControlRect(control, groupBox, SC_GroupBoxLabel, widget);
+ painter->drawTiledPixmap(tileRect, titleStretch);
+ painter->drawPixmap(tileRect.x() + tileRect.width(), 0, titleRight);
+ int opacity = 31;
+ painter->setPen(QColor(0, 0, 0, opacity));
+ painter->drawText(tileRect.translated(0, 1),
+ Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
+ painter->drawText(tileRect.translated(2, 1),
+ Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
+ painter->setPen(QColor(0, 0, 0, opacity * 2));
+ painter->drawText(tileRect.translated(1, 1),
+ Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
+ painter->setPen(Qt::white);
+ painter->drawText(tileRect, Qt::AlignVCenter | Qt::AlignHCenter, groupBox->text);
+ }
+ }
+ break;
+ default:
+ QWindowsStyle::drawComplexControl(control, option, painter, widget);
+ break;
+ }
+ return;
+}
+
+QRect ArthurStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
+ SubControl subControl, const QWidget *widget) const
+{
+ QRect rect;
+
+ switch (control) {
+ default:
+ rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
+ break;
+ case CC_GroupBox:
+ if (const QStyleOptionGroupBox *group
+ = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
+ switch (subControl) {
+ default:
+ rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
+ break;
+ case SC_GroupBoxContents:
+ rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
+ rect.adjust(0, -8, 0, 0);
+ break;
+ case SC_GroupBoxFrame:
+ rect = group->rect;
+ break;
+ case SC_GroupBoxLabel:
+ QPixmap titleLeft = cached(":res/images/title_cap_left.png");
+ QPixmap titleRight = cached(":res/images/title_cap_right.png");
+ QPixmap titleStretch = cached(":res/images/title_stretch.png");
+ int txt_width = group->fontMetrics.width(group->text) + 20;
+ rect = QRect(group->rect.center().x() - txt_width/2 + titleLeft.width(), 0,
+ txt_width - titleLeft.width() - titleRight.width(),
+ titleStretch.height());
+ break;
+ }
+ }
+ break;
+ }
+
+ if (control == CC_Slider && subControl == SC_SliderHandle) {
+ rect.setWidth(13);
+ rect.setHeight(27);
+ } else if (control == CC_Slider && subControl == SC_SliderGroove) {
+ rect.setHeight(9);
+ rect.moveTop(27/2 - 9/2);
+ }
+ return rect;
+}
+
+QSize ArthurStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
+ const QSize &size, const QWidget *widget) const
+{
+ QSize newSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
+
+
+ switch (type) {
+ case CT_RadioButton:
+ newSize += QSize(20, 0);
+ break;
+
+ case CT_PushButton:
+ newSize.setHeight(26);
+ break;
+
+ case CT_Slider:
+ newSize.setHeight(27);
+ break;
+
+ default:
+ break;
+ }
+
+ return newSize;
+}
+
+int ArthurStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const
+{
+ if (pm == PM_SliderLength)
+ return 13;
+ return QWindowsStyle::pixelMetric(pm, opt, widget);
+}
+
+void ArthurStyle::polish(QWidget *widget)
+{
+ if (widget->layout() && qobject_cast<QGroupBox *>(widget)) {
+ if (widget->findChildren<QGroupBox *>().size() == 0) {
+ widget->layout()->setSpacing(0);
+ widget->layout()->setMargin(12);
+ } else {
+ widget->layout()->setMargin(13);
+ }
+ }
+
+ if (qobject_cast<QPushButton *>(widget)
+ || qobject_cast<QRadioButton *>(widget)
+ || qobject_cast<QSlider *>(widget)) {
+ widget->setAttribute(Qt::WA_Hover);
+ }
+
+ QPalette pal = widget->palette();
+ if (widget->isWindow()) {
+ pal.setColor(QPalette::Background, QColor(241, 241, 241));
+ widget->setPalette(pal);
+ }
+
+}
+
+void ArthurStyle::unpolish(QWidget *widget)
+{
+ if (qobject_cast<QPushButton *>(widget)
+ || qobject_cast<QRadioButton *>(widget)
+ || qobject_cast<QSlider *>(widget)) {
+ widget->setAttribute(Qt::WA_Hover, false);
+ }
+}
+
+void ArthurStyle::polish(QPalette &palette)
+{
+ palette.setColor(QPalette::Background, QColor(241, 241, 241));
+}
+
+QRect ArthurStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
+{
+ QRect r;
+ switch(element) {
+ case SE_RadioButtonClickRect:
+ r = widget->rect();
+ break;
+ case SE_RadioButtonContents:
+ r = widget->rect().adjusted(20, 0, 0, 0);
+ break;
+ default:
+ r = QWindowsStyle::subElementRect(element, option, widget);
+ break;
+ }
+
+ if (qobject_cast<const QRadioButton*>(widget))
+ r = r.adjusted(5, 0, -5, 0);
+
+ return r;
+}
diff --git a/examples/widgets/painting/shared/arthurstyle.h b/examples/widgets/painting/shared/arthurstyle.h
new file mode 100644
index 0000000000..1d6a573a4e
--- /dev/null
+++ b/examples/widgets/painting/shared/arthurstyle.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ARTHURSTYLE_H
+#define ARTHURSTYLE_H
+
+#include <QWindowsStyle>
+
+QT_USE_NAMESPACE
+
+class ArthurStyle : public QWindowsStyle
+{
+public:
+ ArthurStyle();
+
+ void drawHoverRect(QPainter *painter, const QRect &rect) const;
+
+ void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
+ QPainter *painter, const QWidget *widget = 0) const;
+// void drawControl(ControlElement element, const QStyleOption *option,
+// QPainter *painter, const QWidget *widget) const;
+ void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
+ QPainter *painter, const QWidget *widget) const;
+ QSize sizeFromContents(ContentsType type, const QStyleOption *option,
+ const QSize &size, const QWidget *widget) const;
+
+ QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const;
+ QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt,
+ SubControl sc, const QWidget *widget) const;
+
+// SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option,
+// const QPoint &pos, const QWidget *widget = 0) const;
+
+ int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const;
+
+ void polish(QPalette &palette);
+ void polish(QWidget *widget);
+ void unpolish(QWidget *widget);
+};
+
+#endif
diff --git a/examples/widgets/painting/shared/arthurwidgets.cpp b/examples/widgets/painting/shared/arthurwidgets.cpp
new file mode 100644
index 0000000000..cf790fea3b
--- /dev/null
+++ b/examples/widgets/painting/shared/arthurwidgets.cpp
@@ -0,0 +1,355 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "arthurwidgets.h"
+#include <QApplication>
+#include <QPainter>
+#include <QPainterPath>
+#include <QPixmapCache>
+#include <QtEvents>
+#include <QTextDocument>
+#include <QAbstractTextDocumentLayout>
+#include <QFile>
+#include <QTextBrowser>
+#include <QBoxLayout>
+
+extern QPixmap cached(const QString &img);
+
+ArthurFrame::ArthurFrame(QWidget *parent)
+ : QWidget(parent)
+ , m_prefer_image(false)
+{
+#ifdef QT_OPENGL_SUPPORT
+ glw = 0;
+ m_use_opengl = false;
+ QGLFormat f = QGLFormat::defaultFormat();
+ f.setSampleBuffers(true);
+ f.setStencil(true);
+ f.setAlpha(true);
+ f.setAlphaBufferSize(8);
+ QGLFormat::setDefaultFormat(f);
+#endif
+ m_document = 0;
+ m_show_doc = false;
+
+ m_tile = QPixmap(128, 128);
+ m_tile.fill(Qt::white);
+ QPainter pt(&m_tile);
+ QColor color(230, 230, 230);
+ pt.fillRect(0, 0, 64, 64, color);
+ pt.fillRect(64, 64, 64, 64, color);
+ pt.end();
+
+// QPalette pal = palette();
+// pal.setBrush(backgroundRole(), m_tile);
+// setPalette(pal);
+}
+
+
+#ifdef QT_OPENGL_SUPPORT
+void ArthurFrame::enableOpenGL(bool use_opengl)
+{
+ if (m_use_opengl == use_opengl)
+ return;
+
+ if (!glw && use_opengl) {
+ glw = new GLWidget(this);
+ glw->setAutoFillBackground(false);
+ glw->disableAutoBufferSwap();
+ QApplication::postEvent(this, new QResizeEvent(size(), size()));
+ }
+
+ m_use_opengl = use_opengl;
+ if (use_opengl) {
+ glw->show();
+ } else {
+ if (glw)
+ glw->hide();
+ }
+
+ update();
+}
+#endif
+
+void ArthurFrame::paintEvent(QPaintEvent *e)
+{
+ static QImage *static_image = 0;
+ QPainter painter;
+ if (preferImage()
+#ifdef QT_OPENGL_SUPPORT
+ && !m_use_opengl
+#endif
+ ) {
+ if (!static_image || static_image->size() != size()) {
+ delete static_image;
+ static_image = new QImage(size(), QImage::Format_RGB32);
+ }
+ painter.begin(static_image);
+
+ int o = 10;
+
+ QBrush bg = palette().brush(QPalette::Background);
+ painter.fillRect(0, 0, o, o, bg);
+ painter.fillRect(width() - o, 0, o, o, bg);
+ painter.fillRect(0, height() - o, o, o, bg);
+ painter.fillRect(width() - o, height() - o, o, o, bg);
+ } else {
+#ifdef QT_OPENGL_SUPPORT
+ if (m_use_opengl) {
+ painter.begin(glw);
+ painter.fillRect(QRectF(0, 0, glw->width(), glw->height()), palette().color(backgroundRole()));
+ } else {
+ painter.begin(this);
+ }
+#else
+ painter.begin(this);
+#endif
+ }
+
+ painter.setClipRect(e->rect());
+
+ painter.setRenderHint(QPainter::Antialiasing);
+
+ QPainterPath clipPath;
+
+ QRect r = rect();
+ qreal left = r.x() + 1;
+ qreal top = r.y() + 1;
+ qreal right = r.right();
+ qreal bottom = r.bottom();
+ qreal radius2 = 8 * 2;
+
+ clipPath.moveTo(right - radius2, top);
+ clipPath.arcTo(right - radius2, top, radius2, radius2, 90, -90);
+ clipPath.arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90);
+ clipPath.arcTo(left, bottom - radius2, radius2, radius2, 270, -90);
+ clipPath.arcTo(left, top, radius2, radius2, 180, -90);
+ clipPath.closeSubpath();
+
+ painter.save();
+ painter.setClipPath(clipPath, Qt::IntersectClip);
+
+ painter.drawTiledPixmap(rect(), m_tile);
+
+ // client painting
+
+ paint(&painter);
+
+ painter.restore();
+
+ painter.save();
+ if (m_show_doc)
+ paintDescription(&painter);
+ painter.restore();
+
+ int level = 180;
+ painter.setPen(QPen(QColor(level, level, level), 2));
+ painter.setBrush(Qt::NoBrush);
+ painter.drawPath(clipPath);
+
+ if (preferImage()
+#ifdef QT_OPENGL_SUPPORT
+ && !m_use_opengl
+#endif
+ ) {
+ painter.end();
+ painter.begin(this);
+ painter.drawImage(e->rect(), *static_image, e->rect());
+ }
+
+#ifdef QT_OPENGL_SUPPORT
+ if (m_use_opengl && (inherits("PathDeformRenderer") || inherits("PathStrokeRenderer") || inherits("CompositionRenderer") || m_show_doc))
+ glw->swapBuffers();
+#endif
+}
+
+void ArthurFrame::resizeEvent(QResizeEvent *e)
+{
+#ifdef QT_OPENGL_SUPPORT
+ if (glw)
+ glw->setGeometry(0, 0, e->size().width()-1, e->size().height()-1);
+#endif
+ QWidget::resizeEvent(e);
+}
+
+void ArthurFrame::setDescriptionEnabled(bool enabled)
+{
+ if (m_show_doc != enabled) {
+ m_show_doc = enabled;
+ emit descriptionEnabledChanged(m_show_doc);
+ update();
+ }
+}
+
+void ArthurFrame::loadDescription(const QString &fileName)
+{
+ QFile textFile(fileName);
+ QString text;
+ if (!textFile.open(QFile::ReadOnly))
+ text = QString("Unable to load resource file: '%1'").arg(fileName);
+ else
+ text = textFile.readAll();
+ setDescription(text);
+}
+
+
+void ArthurFrame::setDescription(const QString &text)
+{
+ m_document = new QTextDocument(this);
+ m_document->setHtml(text);
+}
+
+void ArthurFrame::paintDescription(QPainter *painter)
+{
+ if (!m_document)
+ return;
+
+ int pageWidth = qMax(width() - 100, 100);
+ int pageHeight = qMax(height() - 100, 100);
+ if (pageWidth != m_document->pageSize().width()) {
+ m_document->setPageSize(QSize(pageWidth, pageHeight));
+ }
+
+ QRect textRect(width() / 2 - pageWidth / 2,
+ height() / 2 - pageHeight / 2,
+ pageWidth,
+ pageHeight);
+ int pad = 10;
+ QRect clearRect = textRect.adjusted(-pad, -pad, pad, pad);
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(QColor(0, 0, 0, 63));
+ int shade = 10;
+ painter->drawRect(clearRect.x() + clearRect.width() + 1,
+ clearRect.y() + shade,
+ shade,
+ clearRect.height() + 1);
+ painter->drawRect(clearRect.x() + shade,
+ clearRect.y() + clearRect.height() + 1,
+ clearRect.width() - shade + 1,
+ shade);
+
+ painter->setRenderHint(QPainter::Antialiasing, false);
+ painter->setBrush(QColor(255, 255, 255, 220));
+ painter->setPen(Qt::black);
+ painter->drawRect(clearRect);
+
+ painter->setClipRegion(textRect, Qt::IntersectClip);
+ painter->translate(textRect.topLeft());
+
+ QAbstractTextDocumentLayout::PaintContext ctx;
+
+ QLinearGradient g(0, 0, 0, textRect.height());
+ g.setColorAt(0, Qt::black);
+ g.setColorAt(0.9, Qt::black);
+ g.setColorAt(1, Qt::transparent);
+
+ QPalette pal = palette();
+ pal.setBrush(QPalette::Text, g);
+
+ ctx.palette = pal;
+ ctx.clip = QRect(0, 0, textRect.width(), textRect.height());
+ m_document->documentLayout()->draw(painter, ctx);
+}
+
+void ArthurFrame::loadSourceFile(const QString &sourceFile)
+{
+ m_sourceFileName = sourceFile;
+}
+
+void ArthurFrame::showSource()
+{
+ // Check for existing source
+ if (findChild<QTextBrowser *>())
+ return;
+
+ QString contents;
+ if (m_sourceFileName.isEmpty()) {
+ contents = QString("No source for widget: '%1'").arg(objectName());
+ } else {
+ QFile f(m_sourceFileName);
+ if (!f.open(QFile::ReadOnly))
+ contents = QString("Could not open file: '%1'").arg(m_sourceFileName);
+ else
+ contents = f.readAll();
+ }
+
+ contents.replace('&', "&amp;");
+ contents.replace('<', "&lt;");
+ contents.replace('>', "&gt;");
+
+ QStringList keywords;
+ keywords << "for " << "if " << "switch " << " int " << "#include " << "const"
+ << "void " << "uint " << "case " << "double " << "#define " << "static"
+ << "new" << "this";
+
+ foreach (QString keyword, keywords)
+ contents.replace(keyword, QLatin1String("<font color=olive>") + keyword + QLatin1String("</font>"));
+ contents.replace("(int ", "(<font color=olive><b>int </b></font>");
+
+ QStringList ppKeywords;
+ ppKeywords << "#ifdef" << "#ifndef" << "#if" << "#endif" << "#else";
+
+ foreach (QString keyword, ppKeywords)
+ contents.replace(keyword, QLatin1String("<font color=navy>") + keyword + QLatin1String("</font>"));
+
+ contents.replace(QRegExp("(\\d\\d?)"), QLatin1String("<font color=navy>\\1</font>"));
+
+ QRegExp commentRe("(//.+)\\n");
+ commentRe.setMinimal(true);
+ contents.replace(commentRe, QLatin1String("<font color=red>\\1</font>\n"));
+
+ QRegExp stringLiteralRe("(\".+\")");
+ stringLiteralRe.setMinimal(true);
+ contents.replace(stringLiteralRe, QLatin1String("<font color=green>\\1</font>"));
+
+ QString html = contents;
+ html.prepend("<html><pre>");
+ html.append("</pre></html>");
+
+ QTextBrowser *sourceViewer = new QTextBrowser(0);
+ sourceViewer->setWindowTitle("Source: " + m_sourceFileName.mid(5));
+ sourceViewer->setParent(this, Qt::Dialog);
+ sourceViewer->setAttribute(Qt::WA_DeleteOnClose);
+ sourceViewer->setLineWrapMode(QTextEdit::NoWrap);
+ sourceViewer->setHtml(html);
+ sourceViewer->resize(600, 600);
+ sourceViewer->show();
+}
diff --git a/examples/widgets/painting/shared/arthurwidgets.h b/examples/widgets/painting/shared/arthurwidgets.h
new file mode 100644
index 0000000000..28b986dd0b
--- /dev/null
+++ b/examples/widgets/painting/shared/arthurwidgets.h
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ARTHURWIDGETS_H
+#define ARTHURWIDGETS_H
+
+#include "arthurstyle.h"
+#include <QBitmap>
+#include <QPushButton>
+#include <QGroupBox>
+
+#if defined(QT_OPENGL_SUPPORT)
+#include <QGLWidget>
+#include <QEvent>
+class GLWidget : public QGLWidget
+{
+public:
+ GLWidget(QWidget *parent)
+ : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
+ {
+ setAttribute(Qt::WA_AcceptTouchEvents);
+ }
+ void disableAutoBufferSwap() { setAutoBufferSwap(false); }
+ void paintEvent(QPaintEvent *) { parentWidget()->update(); }
+protected:
+ bool event(QEvent *event)
+ {
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ event->ignore();
+ return false;
+ break;
+ default:
+ break;
+ }
+ return QGLWidget::event(event);
+ }
+};
+#endif
+
+QT_FORWARD_DECLARE_CLASS(QTextDocument)
+QT_FORWARD_DECLARE_CLASS(QTextEdit)
+QT_FORWARD_DECLARE_CLASS(QVBoxLayout)
+
+class ArthurFrame : public QWidget
+{
+ Q_OBJECT
+public:
+ ArthurFrame(QWidget *parent);
+ virtual void paint(QPainter *) {}
+
+
+ void paintDescription(QPainter *p);
+
+ void loadDescription(const QString &filename);
+ void setDescription(const QString &htmlDesc);
+
+ void loadSourceFile(const QString &fileName);
+
+ bool preferImage() const { return m_prefer_image; }
+
+#if defined(QT_OPENGL_SUPPORT)
+ QGLWidget *glWidget() const { return glw; }
+#endif
+
+public slots:
+ void setPreferImage(bool pi) { m_prefer_image = pi; }
+ void setDescriptionEnabled(bool enabled);
+ void showSource();
+
+#if defined(QT_OPENGL_SUPPORT)
+ void enableOpenGL(bool use_opengl);
+ bool usesOpenGL() { return m_use_opengl; }
+#endif
+
+signals:
+ void descriptionEnabledChanged(bool);
+
+protected:
+ void paintEvent(QPaintEvent *);
+ void resizeEvent(QResizeEvent *);
+
+#if defined(QT_OPENGL_SUPPORT)
+ GLWidget *glw;
+ bool m_use_opengl;
+#endif
+ QPixmap m_tile;
+
+ bool m_show_doc;
+ bool m_prefer_image;
+ QTextDocument *m_document;
+
+ QString m_sourceFileName;
+
+};
+
+#endif
diff --git a/examples/widgets/painting/shared/hoverpoints.cpp b/examples/widgets/painting/shared/hoverpoints.cpp
new file mode 100644
index 0000000000..824d92eb30
--- /dev/null
+++ b/examples/widgets/painting/shared/hoverpoints.cpp
@@ -0,0 +1,415 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifdef QT_OPENGL_SUPPORT
+#include <QGLWidget>
+#endif
+
+#include "arthurwidgets.h"
+#include "hoverpoints.h"
+
+#define printf
+
+HoverPoints::HoverPoints(QWidget *widget, PointShape shape)
+ : QObject(widget)
+{
+ m_widget = widget;
+ widget->installEventFilter(this);
+ widget->setAttribute(Qt::WA_AcceptTouchEvents);
+
+ m_connectionType = CurveConnection;
+ m_sortType = NoSort;
+ m_shape = shape;
+ m_pointPen = QPen(QColor(255, 255, 255, 191), 1);
+ m_connectionPen = QPen(QColor(255, 255, 255, 127), 2);
+ m_pointBrush = QBrush(QColor(191, 191, 191, 127));
+ m_pointSize = QSize(11, 11);
+ m_currentIndex = -1;
+ m_editable = true;
+ m_enabled = true;
+
+ connect(this, SIGNAL(pointsChanged(QPolygonF)),
+ m_widget, SLOT(update()));
+}
+
+
+void HoverPoints::setEnabled(bool enabled)
+{
+ if (m_enabled != enabled) {
+ m_enabled = enabled;
+ m_widget->update();
+ }
+}
+
+
+bool HoverPoints::eventFilter(QObject *object, QEvent *event)
+{
+ if (object == m_widget && m_enabled) {
+ switch (event->type()) {
+
+ case QEvent::MouseButtonPress:
+ {
+ if (!m_fingerPointMapping.isEmpty())
+ return true;
+ QMouseEvent *me = (QMouseEvent *) event;
+
+ QPointF clickPos = me->pos();
+ int index = -1;
+ for (int i=0; i<m_points.size(); ++i) {
+ QPainterPath path;
+ if (m_shape == CircleShape)
+ path.addEllipse(pointBoundingRect(i));
+ else
+ path.addRect(pointBoundingRect(i));
+
+ if (path.contains(clickPos)) {
+ index = i;
+ break;
+ }
+ }
+
+ if (me->button() == Qt::LeftButton) {
+ if (index == -1) {
+ if (!m_editable)
+ return false;
+ int pos = 0;
+ // Insert sort for x or y
+ if (m_sortType == XSort) {
+ for (int i=0; i<m_points.size(); ++i)
+ if (m_points.at(i).x() > clickPos.x()) {
+ pos = i;
+ break;
+ }
+ } else if (m_sortType == YSort) {
+ for (int i=0; i<m_points.size(); ++i)
+ if (m_points.at(i).y() > clickPos.y()) {
+ pos = i;
+ break;
+ }
+ }
+
+ m_points.insert(pos, clickPos);
+ m_locks.insert(pos, 0);
+ m_currentIndex = pos;
+ firePointChange();
+ } else {
+ m_currentIndex = index;
+ }
+ return true;
+
+ } else if (me->button() == Qt::RightButton) {
+ if (index >= 0 && m_editable) {
+ if (m_locks[index] == 0) {
+ m_locks.remove(index);
+ m_points.remove(index);
+ }
+ firePointChange();
+ return true;
+ }
+ }
+
+ }
+ break;
+
+ case QEvent::MouseButtonRelease:
+ if (!m_fingerPointMapping.isEmpty())
+ return true;
+ m_currentIndex = -1;
+ break;
+
+ case QEvent::MouseMove:
+ if (!m_fingerPointMapping.isEmpty())
+ return true;
+ if (m_currentIndex >= 0)
+ movePoint(m_currentIndex, ((QMouseEvent *)event)->pos());
+ break;
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ {
+ const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event);
+ const QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints();
+ const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height());
+ foreach (const QTouchEvent::TouchPoint &touchPoint, points) {
+ const int id = touchPoint.id();
+ switch (touchPoint.state()) {
+ case Qt::TouchPointPressed:
+ {
+ // find the point, move it
+ QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
+ int activePoint = -1;
+ qreal distance = -1;
+ const int pointsCount = m_points.size();
+ const int activePointCount = activePoints.size();
+ if (pointsCount == 2 && activePointCount == 1) { // only two points
+ activePoint = activePoints.contains(0) ? 1 : 0;
+ } else {
+ for (int i=0; i<pointsCount; ++i) {
+ if (activePoints.contains(i))
+ continue;
+
+ qreal d = QLineF(touchPoint.pos(), m_points.at(i)).length();
+ if ((distance < 0 && d < 12 * pointSize) || d < distance) {
+ distance = d;
+ activePoint = i;
+ }
+
+ }
+ }
+ if (activePoint != -1) {
+ m_fingerPointMapping.insert(touchPoint.id(), activePoint);
+ movePoint(activePoint, touchPoint.pos());
+ }
+ }
+ break;
+ case Qt::TouchPointReleased:
+ {
+ // move the point and release
+ QHash<int,int>::iterator it = m_fingerPointMapping.find(id);
+ movePoint(it.value(), touchPoint.pos());
+ m_fingerPointMapping.erase(it);
+ }
+ break;
+ case Qt::TouchPointMoved:
+ {
+ // move the point
+ const int pointIdx = m_fingerPointMapping.value(id, -1);
+ if (pointIdx >= 0) // do we track this point?
+ movePoint(pointIdx, touchPoint.pos());
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ if (m_fingerPointMapping.isEmpty()) {
+ event->ignore();
+ return false;
+ } else {
+ return true;
+ }
+ }
+ break;
+ case QEvent::TouchEnd:
+ if (m_fingerPointMapping.isEmpty()) {
+ event->ignore();
+ return false;
+ }
+ return true;
+ break;
+
+ case QEvent::Resize:
+ {
+ QResizeEvent *e = (QResizeEvent *) event;
+ if (e->oldSize().width() == 0 || e->oldSize().height() == 0)
+ break;
+ qreal stretch_x = e->size().width() / qreal(e->oldSize().width());
+ qreal stretch_y = e->size().height() / qreal(e->oldSize().height());
+ for (int i=0; i<m_points.size(); ++i) {
+ QPointF p = m_points[i];
+ movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false);
+ }
+
+ firePointChange();
+ break;
+ }
+
+ case QEvent::Paint:
+ {
+ QWidget *that_widget = m_widget;
+ m_widget = 0;
+ QApplication::sendEvent(object, event);
+ m_widget = that_widget;
+ paintPoints();
+#ifdef QT_OPENGL_SUPPORT
+ ArthurFrame *af = qobject_cast<ArthurFrame *>(that_widget);
+ if (af && af->usesOpenGL())
+ af->glWidget()->swapBuffers();
+#endif
+ return true;
+ }
+ default:
+ break;
+ }
+ }
+
+ return false;
+}
+
+
+void HoverPoints::paintPoints()
+{
+ QPainter p;
+#ifdef QT_OPENGL_SUPPORT
+ ArthurFrame *af = qobject_cast<ArthurFrame *>(m_widget);
+ if (af && af->usesOpenGL())
+ p.begin(af->glWidget());
+ else
+ p.begin(m_widget);
+#else
+ p.begin(m_widget);
+#endif
+
+ p.setRenderHint(QPainter::Antialiasing);
+
+ if (m_connectionPen.style() != Qt::NoPen && m_connectionType != NoConnection) {
+ p.setPen(m_connectionPen);
+
+ if (m_connectionType == CurveConnection) {
+ QPainterPath path;
+ path.moveTo(m_points.at(0));
+ for (int i=1; i<m_points.size(); ++i) {
+ QPointF p1 = m_points.at(i-1);
+ QPointF p2 = m_points.at(i);
+ qreal distance = p2.x() - p1.x();
+
+ path.cubicTo(p1.x() + distance / 2, p1.y(),
+ p1.x() + distance / 2, p2.y(),
+ p2.x(), p2.y());
+ }
+ p.drawPath(path);
+ } else {
+ p.drawPolyline(m_points);
+ }
+ }
+
+ p.setPen(m_pointPen);
+ p.setBrush(m_pointBrush);
+
+ for (int i=0; i<m_points.size(); ++i) {
+ QRectF bounds = pointBoundingRect(i);
+ if (m_shape == CircleShape)
+ p.drawEllipse(bounds);
+ else
+ p.drawRect(bounds);
+ }
+}
+
+static QPointF bound_point(const QPointF &point, const QRectF &bounds, int lock)
+{
+ QPointF p = point;
+
+ qreal left = bounds.left();
+ qreal right = bounds.right();
+ qreal top = bounds.top();
+ qreal bottom = bounds.bottom();
+
+ if (p.x() < left || (lock & HoverPoints::LockToLeft)) p.setX(left);
+ else if (p.x() > right || (lock & HoverPoints::LockToRight)) p.setX(right);
+
+ if (p.y() < top || (lock & HoverPoints::LockToTop)) p.setY(top);
+ else if (p.y() > bottom || (lock & HoverPoints::LockToBottom)) p.setY(bottom);
+
+ return p;
+}
+
+void HoverPoints::setPoints(const QPolygonF &points)
+{
+ if (points.size() != m_points.size())
+ m_fingerPointMapping.clear();
+ m_points.clear();
+ for (int i=0; i<points.size(); ++i)
+ m_points << bound_point(points.at(i), boundingRect(), 0);
+
+ m_locks.clear();
+ if (m_points.size() > 0) {
+ m_locks.resize(m_points.size());
+
+ m_locks.fill(0);
+ }
+}
+
+
+void HoverPoints::movePoint(int index, const QPointF &point, bool emitUpdate)
+{
+ m_points[index] = bound_point(point, boundingRect(), m_locks.at(index));
+ if (emitUpdate)
+ firePointChange();
+}
+
+
+inline static bool x_less_than(const QPointF &p1, const QPointF &p2)
+{
+ return p1.x() < p2.x();
+}
+
+
+inline static bool y_less_than(const QPointF &p1, const QPointF &p2)
+{
+ return p1.y() < p2.y();
+}
+
+void HoverPoints::firePointChange()
+{
+// printf("HoverPoints::firePointChange(), current=%d\n", m_currentIndex);
+
+ if (m_sortType != NoSort) {
+
+ QPointF oldCurrent;
+ if (m_currentIndex != -1) {
+ oldCurrent = m_points[m_currentIndex];
+ }
+
+ if (m_sortType == XSort)
+ qSort(m_points.begin(), m_points.end(), x_less_than);
+ else if (m_sortType == YSort)
+ qSort(m_points.begin(), m_points.end(), y_less_than);
+
+ // Compensate for changed order...
+ if (m_currentIndex != -1) {
+ for (int i=0; i<m_points.size(); ++i) {
+ if (m_points[i] == oldCurrent) {
+ m_currentIndex = i;
+ break;
+ }
+ }
+ }
+
+// printf(" - firePointChange(), current=%d\n", m_currentIndex);
+
+ }
+
+// for (int i=0; i<m_points.size(); ++i) {
+// printf(" - point(%2d)=[%.2f, %.2f], lock=%d\n",
+// i, m_points.at(i).x(), m_points.at(i).y(), m_locks.at(i));
+// }
+
+ emit pointsChanged(m_points);
+}
diff --git a/examples/widgets/painting/shared/hoverpoints.h b/examples/widgets/painting/shared/hoverpoints.h
new file mode 100644
index 0000000000..5472f10a3a
--- /dev/null
+++ b/examples/widgets/painting/shared/hoverpoints.h
@@ -0,0 +1,162 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef HOVERPOINTS_H
+#define HOVERPOINTS_H
+
+#include <QtWidgets>
+
+QT_FORWARD_DECLARE_CLASS(QBypassWidget)
+
+class HoverPoints : public QObject
+{
+ Q_OBJECT
+public:
+ enum PointShape {
+ CircleShape,
+ RectangleShape
+ };
+
+ enum LockType {
+ LockToLeft = 0x01,
+ LockToRight = 0x02,
+ LockToTop = 0x04,
+ LockToBottom = 0x08
+ };
+
+ enum SortType {
+ NoSort,
+ XSort,
+ YSort
+ };
+
+ enum ConnectionType {
+ NoConnection,
+ LineConnection,
+ CurveConnection
+ };
+
+ HoverPoints(QWidget *widget, PointShape shape);
+
+ bool eventFilter(QObject *object, QEvent *event);
+
+ void paintPoints();
+
+ inline QRectF boundingRect() const;
+ void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
+
+ QPolygonF points() const { return m_points; }
+ void setPoints(const QPolygonF &points);
+
+ QSizeF pointSize() const { return m_pointSize; }
+ void setPointSize(const QSizeF &size) { m_pointSize = size; }
+
+ SortType sortType() const { return m_sortType; }
+ void setSortType(SortType sortType) { m_sortType = sortType; }
+
+ ConnectionType connectionType() const { return m_connectionType; }
+ void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
+
+ void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
+ void setShapePen(const QPen &pen) { m_pointPen = pen; }
+ void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
+
+ void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
+
+ void setEditable(bool editable) { m_editable = editable; }
+ bool editable() const { return m_editable; }
+
+public slots:
+ void setEnabled(bool enabled);
+ void setDisabled(bool disabled) { setEnabled(!disabled); }
+
+signals:
+ void pointsChanged(const QPolygonF &points);
+
+public:
+ void firePointChange();
+
+private:
+ inline QRectF pointBoundingRect(int i) const;
+ void movePoint(int i, const QPointF &newPos, bool emitChange = true);
+
+ QWidget *m_widget;
+
+ QPolygonF m_points;
+ QRectF m_bounds;
+ PointShape m_shape;
+ SortType m_sortType;
+ ConnectionType m_connectionType;
+
+ QVector<uint> m_locks;
+
+ QSizeF m_pointSize;
+ int m_currentIndex;
+ bool m_editable;
+ bool m_enabled;
+
+ QHash<int, int> m_fingerPointMapping;
+
+ QPen m_pointPen;
+ QBrush m_pointBrush;
+ QPen m_connectionPen;
+};
+
+
+inline QRectF HoverPoints::pointBoundingRect(int i) const
+{
+ QPointF p = m_points.at(i);
+ qreal w = m_pointSize.width();
+ qreal h = m_pointSize.height();
+ qreal x = p.x() - w / 2;
+ qreal y = p.y() - h / 2;
+ return QRectF(x, y, w, h);
+}
+
+inline QRectF HoverPoints::boundingRect() const
+{
+ if (m_bounds.isEmpty())
+ return m_widget->rect();
+ else
+ return m_bounds;
+}
+
+#endif // HOVERPOINTS_H
diff --git a/examples/widgets/painting/shared/images/bg_pattern.png b/examples/widgets/painting/shared/images/bg_pattern.png
new file mode 100644
index 0000000000..ee670266f0
--- /dev/null
+++ b/examples/widgets/painting/shared/images/bg_pattern.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/button_normal_cap_left.png b/examples/widgets/painting/shared/images/button_normal_cap_left.png
new file mode 100644
index 0000000000..db31dd971d
--- /dev/null
+++ b/examples/widgets/painting/shared/images/button_normal_cap_left.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/button_normal_cap_right.png b/examples/widgets/painting/shared/images/button_normal_cap_right.png
new file mode 100644
index 0000000000..38ead1c719
--- /dev/null
+++ b/examples/widgets/painting/shared/images/button_normal_cap_right.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/button_normal_stretch.png b/examples/widgets/painting/shared/images/button_normal_stretch.png
new file mode 100644
index 0000000000..87abe67ac9
--- /dev/null
+++ b/examples/widgets/painting/shared/images/button_normal_stretch.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/button_pressed_cap_left.png b/examples/widgets/painting/shared/images/button_pressed_cap_left.png
new file mode 100644
index 0000000000..66bfc13cb4
--- /dev/null
+++ b/examples/widgets/painting/shared/images/button_pressed_cap_left.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/button_pressed_cap_right.png b/examples/widgets/painting/shared/images/button_pressed_cap_right.png
new file mode 100644
index 0000000000..3d4cfe25b1
--- /dev/null
+++ b/examples/widgets/painting/shared/images/button_pressed_cap_right.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/button_pressed_stretch.png b/examples/widgets/painting/shared/images/button_pressed_stretch.png
new file mode 100644
index 0000000000..4dd4ad11e6
--- /dev/null
+++ b/examples/widgets/painting/shared/images/button_pressed_stretch.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/curve_thing_edit-6.png b/examples/widgets/painting/shared/images/curve_thing_edit-6.png
new file mode 100644
index 0000000000..034b474d02
--- /dev/null
+++ b/examples/widgets/painting/shared/images/curve_thing_edit-6.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/frame_bottom.png b/examples/widgets/painting/shared/images/frame_bottom.png
new file mode 100644
index 0000000000..889b40d304
--- /dev/null
+++ b/examples/widgets/painting/shared/images/frame_bottom.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/frame_bottomleft.png b/examples/widgets/painting/shared/images/frame_bottomleft.png
new file mode 100644
index 0000000000..0b3023f397
--- /dev/null
+++ b/examples/widgets/painting/shared/images/frame_bottomleft.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/frame_bottomright.png b/examples/widgets/painting/shared/images/frame_bottomright.png
new file mode 100644
index 0000000000..0021e35864
--- /dev/null
+++ b/examples/widgets/painting/shared/images/frame_bottomright.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/frame_left.png b/examples/widgets/painting/shared/images/frame_left.png
new file mode 100644
index 0000000000..40f331c293
--- /dev/null
+++ b/examples/widgets/painting/shared/images/frame_left.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/frame_right.png b/examples/widgets/painting/shared/images/frame_right.png
new file mode 100644
index 0000000000..023af8c700
--- /dev/null
+++ b/examples/widgets/painting/shared/images/frame_right.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/frame_top.png b/examples/widgets/painting/shared/images/frame_top.png
new file mode 100644
index 0000000000..001f3a7144
--- /dev/null
+++ b/examples/widgets/painting/shared/images/frame_top.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/frame_topleft.png b/examples/widgets/painting/shared/images/frame_topleft.png
new file mode 100644
index 0000000000..58c68d407a
--- /dev/null
+++ b/examples/widgets/painting/shared/images/frame_topleft.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/frame_topright.png b/examples/widgets/painting/shared/images/frame_topright.png
new file mode 100644
index 0000000000..6a7e8d3eb3
--- /dev/null
+++ b/examples/widgets/painting/shared/images/frame_topright.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/groupframe_bottom_left.png b/examples/widgets/painting/shared/images/groupframe_bottom_left.png
new file mode 100644
index 0000000000..af2fe061e3
--- /dev/null
+++ b/examples/widgets/painting/shared/images/groupframe_bottom_left.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/groupframe_bottom_right.png b/examples/widgets/painting/shared/images/groupframe_bottom_right.png
new file mode 100644
index 0000000000..fdf2e97b13
--- /dev/null
+++ b/examples/widgets/painting/shared/images/groupframe_bottom_right.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/groupframe_bottom_stretch.png b/examples/widgets/painting/shared/images/groupframe_bottom_stretch.png
new file mode 100644
index 0000000000..f47b67d7c0
--- /dev/null
+++ b/examples/widgets/painting/shared/images/groupframe_bottom_stretch.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/groupframe_left_stretch.png b/examples/widgets/painting/shared/images/groupframe_left_stretch.png
new file mode 100644
index 0000000000..c122f462ed
--- /dev/null
+++ b/examples/widgets/painting/shared/images/groupframe_left_stretch.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/groupframe_right_stretch.png b/examples/widgets/painting/shared/images/groupframe_right_stretch.png
new file mode 100644
index 0000000000..1056b7812a
--- /dev/null
+++ b/examples/widgets/painting/shared/images/groupframe_right_stretch.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/groupframe_top_stretch.png b/examples/widgets/painting/shared/images/groupframe_top_stretch.png
new file mode 100644
index 0000000000..5746ef96fc
--- /dev/null
+++ b/examples/widgets/painting/shared/images/groupframe_top_stretch.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/groupframe_topleft.png b/examples/widgets/painting/shared/images/groupframe_topleft.png
new file mode 100644
index 0000000000..98d9cd96b4
--- /dev/null
+++ b/examples/widgets/painting/shared/images/groupframe_topleft.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/groupframe_topright.png b/examples/widgets/painting/shared/images/groupframe_topright.png
new file mode 100644
index 0000000000..1a0a328c20
--- /dev/null
+++ b/examples/widgets/painting/shared/images/groupframe_topright.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/line_dash_dot.png b/examples/widgets/painting/shared/images/line_dash_dot.png
new file mode 100644
index 0000000000..1c61442d9f
--- /dev/null
+++ b/examples/widgets/painting/shared/images/line_dash_dot.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/line_dash_dot_dot.png b/examples/widgets/painting/shared/images/line_dash_dot_dot.png
new file mode 100644
index 0000000000..0d9bb972f9
--- /dev/null
+++ b/examples/widgets/painting/shared/images/line_dash_dot_dot.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/line_dashed.png b/examples/widgets/painting/shared/images/line_dashed.png
new file mode 100644
index 0000000000..d5bc7ea5fe
--- /dev/null
+++ b/examples/widgets/painting/shared/images/line_dashed.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/line_dotted.png b/examples/widgets/painting/shared/images/line_dotted.png
new file mode 100644
index 0000000000..a2f9a35925
--- /dev/null
+++ b/examples/widgets/painting/shared/images/line_dotted.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/line_solid.png b/examples/widgets/painting/shared/images/line_solid.png
new file mode 100644
index 0000000000..60ef3f9485
--- /dev/null
+++ b/examples/widgets/painting/shared/images/line_solid.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/radiobutton-off.png b/examples/widgets/painting/shared/images/radiobutton-off.png
new file mode 100644
index 0000000000..af1753a3e7
--- /dev/null
+++ b/examples/widgets/painting/shared/images/radiobutton-off.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/radiobutton-on.png b/examples/widgets/painting/shared/images/radiobutton-on.png
new file mode 100644
index 0000000000..f875838bb5
--- /dev/null
+++ b/examples/widgets/painting/shared/images/radiobutton-on.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/radiobutton_off.png b/examples/widgets/painting/shared/images/radiobutton_off.png
new file mode 100644
index 0000000000..400906ebfa
--- /dev/null
+++ b/examples/widgets/painting/shared/images/radiobutton_off.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/radiobutton_on.png b/examples/widgets/painting/shared/images/radiobutton_on.png
new file mode 100644
index 0000000000..50a049ec56
--- /dev/null
+++ b/examples/widgets/painting/shared/images/radiobutton_on.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/slider_bar.png b/examples/widgets/painting/shared/images/slider_bar.png
new file mode 100644
index 0000000000..1b3d62c007
--- /dev/null
+++ b/examples/widgets/painting/shared/images/slider_bar.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/slider_thumb_off.png b/examples/widgets/painting/shared/images/slider_thumb_off.png
new file mode 100644
index 0000000000..d7f141daef
--- /dev/null
+++ b/examples/widgets/painting/shared/images/slider_thumb_off.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/slider_thumb_on.png b/examples/widgets/painting/shared/images/slider_thumb_on.png
new file mode 100644
index 0000000000..8e1f510813
--- /dev/null
+++ b/examples/widgets/painting/shared/images/slider_thumb_on.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/title_cap_left.png b/examples/widgets/painting/shared/images/title_cap_left.png
new file mode 100644
index 0000000000..2d475070c8
--- /dev/null
+++ b/examples/widgets/painting/shared/images/title_cap_left.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/title_cap_right.png b/examples/widgets/painting/shared/images/title_cap_right.png
new file mode 100644
index 0000000000..dc3ff8536c
--- /dev/null
+++ b/examples/widgets/painting/shared/images/title_cap_right.png
Binary files differ
diff --git a/examples/widgets/painting/shared/images/title_stretch.png b/examples/widgets/painting/shared/images/title_stretch.png
new file mode 100644
index 0000000000..11043345d0
--- /dev/null
+++ b/examples/widgets/painting/shared/images/title_stretch.png
Binary files differ
diff --git a/examples/widgets/painting/shared/shared.pri b/examples/widgets/painting/shared/shared.pri
new file mode 100644
index 0000000000..2d6b3c78f9
--- /dev/null
+++ b/examples/widgets/painting/shared/shared.pri
@@ -0,0 +1,20 @@
+INCLUDEPATH += $$SHARED_FOLDER
+
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+contains(CONFIG, debug_and_release_target) {
+ CONFIG(debug, debug|release) {
+ QMAKE_LIBDIR += $$SHARED_FOLDER/debug
+ } else {
+ QMAKE_LIBDIR += $$SHARED_FOLDER/release
+ }
+} else {
+ QMAKE_LIBDIR += $$SHARED_FOLDER
+}
+
+hpux-acc*:LIBS += $$SHARED_FOLDER/libdemo_shared.a
+hpuxi-acc*:LIBS += $$SHARED_FOLDER/libdemo_shared.a
+!hpuxi-acc*:!hpux-acc*:LIBS += -ldemo_shared
+
diff --git a/examples/widgets/painting/shared/shared.pro b/examples/widgets/painting/shared/shared.pro
new file mode 100644
index 0000000000..212f3a20d7
--- /dev/null
+++ b/examples/widgets/painting/shared/shared.pro
@@ -0,0 +1,34 @@
+TEMPLATE = lib
+CONFIG += static
+
+contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2) {
+ DEFINES += QT_OPENGL_SUPPORT
+ QT += opengl widgets
+}
+
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+TARGET = demo_shared
+QT += widgets
+
+SOURCES += \
+ arthurstyle.cpp\
+ arthurwidgets.cpp \
+ hoverpoints.cpp
+
+HEADERS += \
+ arthurstyle.h \
+ arthurwidgets.h \
+ hoverpoints.h
+
+RESOURCES += shared.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/shared
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.pri images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/shared
+INSTALLS += sources
+
+!cross_compile:INSTALLS += target
diff --git a/examples/widgets/painting/shared/shared.qrc b/examples/widgets/painting/shared/shared.qrc
new file mode 100644
index 0000000000..17336ecf80
--- /dev/null
+++ b/examples/widgets/painting/shared/shared.qrc
@@ -0,0 +1,39 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res">
+ <file>images/button_normal_cap_left.png</file>
+ <file>images/button_normal_cap_right.png</file>
+ <file>images/button_normal_stretch.png</file>
+ <file>images/button_pressed_cap_left.png</file>
+ <file>images/button_pressed_cap_right.png</file>
+ <file>images/button_pressed_stretch.png</file>
+ <file>images/radiobutton-on.png</file>
+ <file>images/radiobutton_on.png</file>
+ <file>images/radiobutton_off.png</file>
+ <file>images/slider_bar.png</file>
+ <file>images/slider_thumb_on.png</file>
+ <file>images/groupframe_topleft.png</file>
+ <file>images/groupframe_topright.png</file>
+ <file>images/groupframe_bottom_left.png</file>
+ <file>images/groupframe_bottom_right.png</file>
+ <file>images/groupframe_top_stretch.png</file>
+ <file>images/groupframe_bottom_stretch.png</file>
+ <file>images/groupframe_left_stretch.png</file>
+ <file>images/groupframe_right_stretch.png</file>
+ <file>images/frame_topleft.png</file>
+ <file>images/frame_topright.png</file>
+ <file>images/frame_bottomleft.png</file>
+ <file>images/frame_bottomright.png</file>
+ <file>images/frame_left.png</file>
+ <file>images/frame_top.png</file>
+ <file>images/frame_right.png</file>
+ <file>images/frame_bottom.png</file>
+ <file>images/title_cap_left.png</file>
+ <file>images/title_cap_right.png</file>
+ <file>images/title_stretch.png</file>
+ <file>images/line_dash_dot.png</file>
+ <file>images/line_dotted.png</file>
+ <file>images/line_dashed.png</file>
+ <file>images/line_solid.png</file>
+ <file>images/line_dash_dot_dot.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/painting/svggenerator/svggenerator.desktop b/examples/widgets/painting/svggenerator/svggenerator.desktop
new file mode 100644
index 0000000000..3ae32a4908
--- /dev/null
+++ b/examples/widgets/painting/svggenerator/svggenerator.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=SVG Generator
+Exec=/opt/usr/bin/svggenerator
+Icon=svggenerator
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/painting/svgviewer/svgviewer.desktop b/examples/widgets/painting/svgviewer/svgviewer.desktop
new file mode 100644
index 0000000000..477ef789d8
--- /dev/null
+++ b/examples/widgets/painting/svgviewer/svgviewer.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=SVG Viewer
+Exec=/opt/usr/bin/svgviewer
+Icon=svgviewer
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/painting/transformations/main.cpp b/examples/widgets/painting/transformations/main.cpp
new file mode 100644
index 0000000000..dcbf1c0449
--- /dev/null
+++ b/examples/widgets/painting/transformations/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/painting/transformations/renderarea.cpp b/examples/widgets/painting/transformations/renderarea.cpp
new file mode 100644
index 0000000000..58be8143c3
--- /dev/null
+++ b/examples/widgets/painting/transformations/renderarea.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "renderarea.h"
+
+//! [0]
+RenderArea::RenderArea(QWidget *parent)
+ : QWidget(parent)
+{
+ QFont newFont = font();
+ newFont.setPixelSize(12);
+ setFont(newFont);
+
+ QFontMetrics fontMetrics(newFont);
+ xBoundingRect = fontMetrics.boundingRect(tr("x"));
+ yBoundingRect = fontMetrics.boundingRect(tr("y"));
+}
+//! [0]
+
+//! [1]
+void RenderArea::setOperations(const QList<Operation> &operations)
+{
+ this->operations = operations;
+ update();
+}
+//! [1]
+
+//! [2]
+void RenderArea::setShape(const QPainterPath &shape)
+{
+ this->shape = shape;
+ update();
+}
+//! [2]
+
+//! [3]
+QSize RenderArea::minimumSizeHint() const
+{
+ return QSize(182, 182);
+}
+//! [3]
+
+//! [4]
+QSize RenderArea::sizeHint() const
+{
+ return QSize(232, 232);
+}
+//! [4]
+
+//! [5]
+void RenderArea::paintEvent(QPaintEvent *event)
+{
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.fillRect(event->rect(), QBrush(Qt::white));
+
+ painter.translate(66, 66);
+//! [5]
+
+//! [6]
+ painter.save();
+ transformPainter(painter);
+ drawShape(painter);
+ painter.restore();
+//! [6]
+
+//! [7]
+ drawOutline(painter);
+//! [7]
+
+//! [8]
+ transformPainter(painter);
+ drawCoordinates(painter);
+}
+//! [8]
+
+//! [9]
+void RenderArea::drawCoordinates(QPainter &painter)
+{
+ painter.setPen(Qt::red);
+
+ painter.drawLine(0, 0, 50, 0);
+ painter.drawLine(48, -2, 50, 0);
+ painter.drawLine(48, 2, 50, 0);
+ painter.drawText(60 - xBoundingRect.width() / 2,
+ 0 + xBoundingRect.height() / 2, tr("x"));
+
+ painter.drawLine(0, 0, 0, 50);
+ painter.drawLine(-2, 48, 0, 50);
+ painter.drawLine(2, 48, 0, 50);
+ painter.drawText(0 - yBoundingRect.width() / 2,
+ 60 + yBoundingRect.height() / 2, tr("y"));
+}
+//! [9]
+
+//! [10]
+void RenderArea::drawOutline(QPainter &painter)
+{
+ painter.setPen(Qt::darkGreen);
+ painter.setPen(Qt::DashLine);
+ painter.setBrush(Qt::NoBrush);
+ painter.drawRect(0, 0, 100, 100);
+}
+//! [10]
+
+//! [11]
+void RenderArea::drawShape(QPainter &painter)
+{
+ painter.fillPath(shape, Qt::blue);
+}
+//! [11]
+
+//! [12]
+void RenderArea::transformPainter(QPainter &painter)
+{
+ for (int i = 0; i < operations.size(); ++i) {
+ switch (operations[i]) {
+ case Translate:
+ painter.translate(50, 50);
+ break;
+ case Scale:
+ painter.scale(0.75, 0.75);
+ break;
+ case Rotate:
+ painter.rotate(60);
+ break;
+ case NoTransformation:
+ default:
+ ;
+ }
+ }
+}
+//! [12]
diff --git a/examples/widgets/painting/transformations/renderarea.h b/examples/widgets/painting/transformations/renderarea.h
new file mode 100644
index 0000000000..adc6c1ad7f
--- /dev/null
+++ b/examples/widgets/painting/transformations/renderarea.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RENDERAREA_H
+#define RENDERAREA_H
+
+#include <QFont>
+#include <QList>
+#include <QPainterPath>
+#include <QRect>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QPaintEvent;
+QT_END_NAMESPACE
+
+//! [0]
+enum Operation { NoTransformation, Translate, Rotate, Scale };
+//! [0]
+
+//! [1]
+class RenderArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ RenderArea(QWidget *parent = 0);
+
+ void setOperations(const QList<Operation> &operations);
+ void setShape(const QPainterPath &shape);
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+
+protected:
+ void paintEvent(QPaintEvent *event);
+//! [1]
+
+//! [2]
+private:
+ void drawCoordinates(QPainter &painter);
+ void drawOutline(QPainter &painter);
+ void drawShape(QPainter &painter);
+ void transformPainter(QPainter &painter);
+
+ QList<Operation> operations;
+ QPainterPath shape;
+ QRect xBoundingRect;
+ QRect yBoundingRect;
+};
+//! [2]
+
+#endif
diff --git a/examples/widgets/painting/transformations/transformations.desktop b/examples/widgets/painting/transformations/transformations.desktop
new file mode 100644
index 0000000000..2f53891069
--- /dev/null
+++ b/examples/widgets/painting/transformations/transformations.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Transformations
+Exec=/opt/usr/bin/transformations
+Icon=transformations
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/painting/transformations/transformations.pro b/examples/widgets/painting/transformations/transformations.pro
new file mode 100644
index 0000000000..a261c53371
--- /dev/null
+++ b/examples/widgets/painting/transformations/transformations.pro
@@ -0,0 +1,13 @@
+HEADERS = renderarea.h \
+ window.h
+SOURCES = main.cpp \
+ renderarea.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/transformations
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS transformations.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/painting/transformations
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/painting/transformations/window.cpp b/examples/widgets/painting/transformations/window.cpp
new file mode 100644
index 0000000000..5f9296be7f
--- /dev/null
+++ b/examples/widgets/painting/transformations/window.cpp
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "window.h"
+
+//! [0]
+Window::Window()
+{
+ originalRenderArea = new RenderArea;
+
+ shapeComboBox = new QComboBox;
+ shapeComboBox->addItem(tr("Clock"));
+ shapeComboBox->addItem(tr("House"));
+ shapeComboBox->addItem(tr("Text"));
+ shapeComboBox->addItem(tr("Truck"));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(originalRenderArea, 0, 0);
+ layout->addWidget(shapeComboBox, 1, 0);
+//! [0]
+
+//! [1]
+ for (int i = 0; i < NumTransformedAreas; ++i) {
+ transformedRenderAreas[i] = new RenderArea;
+
+ operationComboBoxes[i] = new QComboBox;
+ operationComboBoxes[i]->addItem(tr("No transformation"));
+ operationComboBoxes[i]->addItem(tr("Rotate by 60\xC2\xB0"));
+ operationComboBoxes[i]->addItem(tr("Scale to 75%"));
+ operationComboBoxes[i]->addItem(tr("Translate by (50, 50)"));
+
+ connect(operationComboBoxes[i], SIGNAL(activated(int)),
+ this, SLOT(operationChanged()));
+
+ layout->addWidget(transformedRenderAreas[i], 0, i + 1);
+ layout->addWidget(operationComboBoxes[i], 1, i + 1);
+ }
+//! [1]
+
+//! [2]
+ setLayout(layout);
+ setupShapes();
+ shapeSelected(0);
+
+ setWindowTitle(tr("Transformations"));
+}
+//! [2]
+
+//! [3]
+void Window::setupShapes()
+{
+ QPainterPath truck;
+//! [3]
+ truck.setFillRule(Qt::WindingFill);
+ truck.moveTo(0.0, 87.0);
+ truck.lineTo(0.0, 60.0);
+ truck.lineTo(10.0, 60.0);
+ truck.lineTo(35.0, 35.0);
+ truck.lineTo(100.0, 35.0);
+ truck.lineTo(100.0, 87.0);
+ truck.lineTo(0.0, 87.0);
+ truck.moveTo(17.0, 60.0);
+ truck.lineTo(55.0, 60.0);
+ truck.lineTo(55.0, 40.0);
+ truck.lineTo(37.0, 40.0);
+ truck.lineTo(17.0, 60.0);
+ truck.addEllipse(17.0, 75.0, 25.0, 25.0);
+ truck.addEllipse(63.0, 75.0, 25.0, 25.0);
+
+//! [4]
+ QPainterPath clock;
+//! [4]
+ clock.addEllipse(-50.0, -50.0, 100.0, 100.0);
+ clock.addEllipse(-48.0, -48.0, 96.0, 96.0);
+ clock.moveTo(0.0, 0.0);
+ clock.lineTo(-2.0, -2.0);
+ clock.lineTo(0.0, -42.0);
+ clock.lineTo(2.0, -2.0);
+ clock.lineTo(0.0, 0.0);
+ clock.moveTo(0.0, 0.0);
+ clock.lineTo(2.732, -0.732);
+ clock.lineTo(24.495, 14.142);
+ clock.lineTo(0.732, 2.732);
+ clock.lineTo(0.0, 0.0);
+
+//! [5]
+ QPainterPath house;
+//! [5]
+ house.moveTo(-45.0, -20.0);
+ house.lineTo(0.0, -45.0);
+ house.lineTo(45.0, -20.0);
+ house.lineTo(45.0, 45.0);
+ house.lineTo(-45.0, 45.0);
+ house.lineTo(-45.0, -20.0);
+ house.addRect(15.0, 5.0, 20.0, 35.0);
+ house.addRect(-35.0, -15.0, 25.0, 25.0);
+
+//! [6]
+ QPainterPath text;
+//! [6]
+ QFont font;
+ font.setPixelSize(50);
+ QRect fontBoundingRect = QFontMetrics(font).boundingRect(tr("Qt"));
+ text.addText(-QPointF(fontBoundingRect.center()), font, tr("Qt"));
+
+//! [7]
+ shapes.append(clock);
+ shapes.append(house);
+ shapes.append(text);
+ shapes.append(truck);
+
+ connect(shapeComboBox, SIGNAL(activated(int)),
+ this, SLOT(shapeSelected(int)));
+}
+//! [7]
+
+//! [8]
+void Window::operationChanged()
+{
+ static const Operation operationTable[] = {
+ NoTransformation, Rotate, Scale, Translate
+ };
+
+ QList<Operation> operations;
+ for (int i = 0; i < NumTransformedAreas; ++i) {
+ int index = operationComboBoxes[i]->currentIndex();
+ operations.append(operationTable[index]);
+ transformedRenderAreas[i]->setOperations(operations);
+ }
+}
+//! [8]
+
+//! [9]
+void Window::shapeSelected(int index)
+{
+ QPainterPath shape = shapes[index];
+ originalRenderArea->setShape(shape);
+ for (int i = 0; i < NumTransformedAreas; ++i)
+ transformedRenderAreas[i]->setShape(shape);
+}
+//! [9]
diff --git a/examples/widgets/painting/transformations/window.h b/examples/widgets/painting/transformations/window.h
new file mode 100644
index 0000000000..f28e53e494
--- /dev/null
+++ b/examples/widgets/painting/transformations/window.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QList>
+#include <QPainterPath>
+#include <QWidget>
+
+#include "renderarea.h"
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+QT_END_NAMESPACE
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+public slots:
+ void operationChanged();
+ void shapeSelected(int index);
+//! [0]
+
+//! [1]
+private:
+ void setupShapes();
+
+ enum { NumTransformedAreas = 3 };
+ RenderArea *originalRenderArea;
+ RenderArea *transformedRenderAreas[NumTransformedAreas];
+ QComboBox *shapeComboBox;
+ QComboBox *operationComboBoxes[NumTransformedAreas];
+ QList<QPainterPath> shapes;
+};
+//! [1]
+
+#endif
diff --git a/examples/widgets/richtext/README b/examples/widgets/richtext/README
new file mode 100644
index 0000000000..647029b8a2
--- /dev/null
+++ b/examples/widgets/richtext/README
@@ -0,0 +1,11 @@
+Qt provides powerful document-oriented rich text engine that supports Unicode
+and right-to-left scripts. Documents can be manipulated using a cursor-based
+API, and their contents can be imported and exported as both HTML and in a
+custom XML format.
+
+Text is rendered using anti-aliased outline fonts to provide the best
+possible on-screen representation.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/richtext/calendar/calendar.desktop b/examples/widgets/richtext/calendar/calendar.desktop
new file mode 100644
index 0000000000..41ba6dd95a
--- /dev/null
+++ b/examples/widgets/richtext/calendar/calendar.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Calendar
+Exec=/opt/usr/bin/calendar
+Icon=calendar
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/richtext/calendar/calendar.pro b/examples/widgets/richtext/calendar/calendar.pro
new file mode 100644
index 0000000000..3867a027cf
--- /dev/null
+++ b/examples/widgets/richtext/calendar/calendar.pro
@@ -0,0 +1,11 @@
+HEADERS = mainwindow.h
+SOURCES = main.cpp \
+ mainwindow.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/calendar
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS calendar.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/calendar
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/richtext/calendar/main.cpp b/examples/widgets/richtext/calendar/main.cpp
new file mode 100644
index 0000000000..35b6b90c13
--- /dev/null
+++ b/examples/widgets/richtext/calendar/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.resize(640, 256);
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/richtext/calendar/mainwindow.cpp b/examples/widgets/richtext/calendar/mainwindow.cpp
new file mode 100644
index 0000000000..366ebff2a9
--- /dev/null
+++ b/examples/widgets/richtext/calendar/mainwindow.cpp
@@ -0,0 +1,215 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ selectedDate = QDate::currentDate();
+ fontSize = 10;
+
+ QWidget *centralWidget = new QWidget;
+//! [0]
+
+//! [1]
+ QLabel *dateLabel = new QLabel(tr("Date:"));
+ QComboBox *monthCombo = new QComboBox;
+
+ for (int month = 1; month <= 12; ++month)
+ monthCombo->addItem(QDate::longMonthName(month));
+
+ QDateTimeEdit *yearEdit = new QDateTimeEdit;
+ yearEdit->setDisplayFormat("yyyy");
+ yearEdit->setDateRange(QDate(1753, 1, 1), QDate(8000, 1, 1));
+//! [1]
+
+ monthCombo->setCurrentIndex(selectedDate.month() - 1);
+ yearEdit->setDate(selectedDate);
+
+//! [2]
+ QLabel *fontSizeLabel = new QLabel(tr("Font size:"));
+ QSpinBox *fontSizeSpinBox = new QSpinBox;
+ fontSizeSpinBox->setRange(1, 64);
+
+ editor = new QTextBrowser;
+ insertCalendar();
+//! [2]
+
+//! [3]
+ connect(monthCombo, SIGNAL(activated(int)), this, SLOT(setMonth(int)));
+ connect(yearEdit, SIGNAL(dateChanged(QDate)), this, SLOT(setYear(QDate)));
+ connect(fontSizeSpinBox, SIGNAL(valueChanged(int)),
+ this, SLOT(setFontSize(int)));
+//! [3]
+
+ fontSizeSpinBox->setValue(10);
+
+//! [4]
+ QHBoxLayout *controlsLayout = new QHBoxLayout;
+ controlsLayout->addWidget(dateLabel);
+ controlsLayout->addWidget(monthCombo);
+ controlsLayout->addWidget(yearEdit);
+ controlsLayout->addSpacing(24);
+ controlsLayout->addWidget(fontSizeLabel);
+ controlsLayout->addWidget(fontSizeSpinBox);
+ controlsLayout->addStretch(1);
+
+ QVBoxLayout *centralLayout = new QVBoxLayout;
+ centralLayout->addLayout(controlsLayout);
+ centralLayout->addWidget(editor, 1);
+ centralWidget->setLayout(centralLayout);
+
+ setCentralWidget(centralWidget);
+//! [4]
+}
+
+//! [5]
+void MainWindow::insertCalendar()
+{
+ editor->clear();
+ QTextCursor cursor = editor->textCursor();
+ cursor.beginEditBlock();
+
+ QDate date(selectedDate.year(), selectedDate.month(), 1);
+//! [5]
+
+//! [6]
+ QTextTableFormat tableFormat;
+ tableFormat.setAlignment(Qt::AlignHCenter);
+ tableFormat.setBackground(QColor("#e0e0e0"));
+ tableFormat.setCellPadding(2);
+ tableFormat.setCellSpacing(4);
+//! [6] //! [7]
+ QVector<QTextLength> constraints;
+ constraints << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14);
+ tableFormat.setColumnWidthConstraints(constraints);
+//! [7]
+
+//! [8]
+ QTextTable *table = cursor.insertTable(1, 7, tableFormat);
+//! [8]
+
+//! [9]
+ QTextFrame *frame = cursor.currentFrame();
+ QTextFrameFormat frameFormat = frame->frameFormat();
+ frameFormat.setBorder(1);
+ frame->setFrameFormat(frameFormat);
+//! [9]
+
+//! [10]
+ QTextCharFormat format = cursor.charFormat();
+ format.setFontPointSize(fontSize);
+
+ QTextCharFormat boldFormat = format;
+ boldFormat.setFontWeight(QFont::Bold);
+
+ QTextCharFormat highlightedFormat = boldFormat;
+ highlightedFormat.setBackground(Qt::yellow);
+//! [10]
+
+//! [11]
+ for (int weekDay = 1; weekDay <= 7; ++weekDay) {
+ QTextTableCell cell = table->cellAt(0, weekDay-1);
+//! [11] //! [12]
+ QTextCursor cellCursor = cell.firstCursorPosition();
+ cellCursor.insertText(QString("%1").arg(QDate::longDayName(weekDay)),
+ boldFormat);
+ }
+//! [12]
+
+//! [13]
+ table->insertRows(table->rows(), 1);
+//! [13]
+
+ while (date.month() == selectedDate.month()) {
+ int weekDay = date.dayOfWeek();
+ QTextTableCell cell = table->cellAt(table->rows()-1, weekDay-1);
+ QTextCursor cellCursor = cell.firstCursorPosition();
+
+ if (date == QDate::currentDate())
+ cellCursor.insertText(QString("%1").arg(date.day()), highlightedFormat);
+ else
+ cellCursor.insertText(QString("%1").arg(date.day()), format);
+
+ date = date.addDays(1);
+ if (weekDay == 7 && date.month() == selectedDate.month())
+ table->insertRows(table->rows(), 1);
+ }
+
+ cursor.endEditBlock();
+//! [14]
+ setWindowTitle(tr("Calendar for %1 %2"
+ ).arg(QDate::longMonthName(selectedDate.month())
+ ).arg(selectedDate.year()));
+}
+//! [14]
+
+//! [15]
+void MainWindow::setFontSize(int size)
+{
+ fontSize = size;
+ insertCalendar();
+}
+//! [15]
+
+//! [16]
+void MainWindow::setMonth(int month)
+{
+ selectedDate = QDate(selectedDate.year(), month + 1, selectedDate.day());
+ insertCalendar();
+}
+//! [16]
+
+//! [17]
+void MainWindow::setYear(QDate date)
+{
+ selectedDate = QDate(date.year(), selectedDate.month(), selectedDate.day());
+ insertCalendar();
+}
+//! [17]
diff --git a/examples/widgets/richtext/calendar/mainwindow.h b/examples/widgets/richtext/calendar/mainwindow.h
new file mode 100644
index 0000000000..665452b688
--- /dev/null
+++ b/examples/widgets/richtext/calendar/mainwindow.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QDate>
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QTextBrowser;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+public slots:
+ void setFontSize(int size);
+ void setMonth(int month);
+ void setYear(QDate date);
+
+private:
+ void insertCalendar();
+
+ int fontSize;
+ QDate selectedDate;
+ QTextBrowser *editor;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/richtext/orderform/detailsdialog.cpp b/examples/widgets/richtext/orderform/detailsdialog.cpp
new file mode 100644
index 0000000000..3dbdee58c7
--- /dev/null
+++ b/examples/widgets/richtext/orderform/detailsdialog.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "detailsdialog.h"
+
+//! [0]
+DetailsDialog::DetailsDialog(const QString &title, QWidget *parent)
+ : QDialog(parent)
+{
+ nameLabel = new QLabel(tr("Name:"));
+ addressLabel = new QLabel(tr("Address:"));
+ addressLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
+
+ nameEdit = new QLineEdit;
+ addressEdit = new QTextEdit;
+
+ offersCheckBox = new QCheckBox(tr("Send information about products and "
+ "special offers"));
+
+ setupItemsTable();
+
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel);
+
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(verify()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+//! [0]
+
+//! [1]
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameEdit, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0);
+ mainLayout->addWidget(addressEdit, 1, 1);
+ mainLayout->addWidget(itemsTable, 0, 2, 2, 1);
+ mainLayout->addWidget(offersCheckBox, 2, 1, 1, 2);
+ mainLayout->addWidget(buttonBox, 3, 0, 1, 3);
+ setLayout(mainLayout);
+
+ setWindowTitle(title);
+}
+//! [1]
+
+//! [2]
+void DetailsDialog::setupItemsTable()
+{
+ items << tr("T-shirt") << tr("Badge") << tr("Reference book")
+ << tr("Coffee cup");
+
+ itemsTable = new QTableWidget(items.count(), 2);
+
+ for (int row = 0; row < items.count(); ++row) {
+ QTableWidgetItem *name = new QTableWidgetItem(items[row]);
+ name->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ itemsTable->setItem(row, 0, name);
+ QTableWidgetItem *quantity = new QTableWidgetItem("1");
+ itemsTable->setItem(row, 1, quantity);
+ }
+}
+//! [2]
+
+//! [3]
+QList<QPair<QString, int> > DetailsDialog::orderItems()
+{
+ QList<QPair<QString, int> > orderList;
+
+ for (int row = 0; row < items.count(); ++row) {
+ QPair<QString, int> item;
+ item.first = itemsTable->item(row, 0)->text();
+ int quantity = itemsTable->item(row, 1)->data(Qt::DisplayRole).toInt();
+ item.second = qMax(0, quantity);
+ orderList.append(item);
+ }
+
+ return orderList;
+}
+//! [3]
+
+//! [4]
+QString DetailsDialog::senderName() const
+{
+ return nameEdit->text();
+}
+//! [4]
+
+//! [5]
+QString DetailsDialog::senderAddress() const
+{
+ return addressEdit->toPlainText();
+}
+//! [5]
+
+//! [6]
+bool DetailsDialog::sendOffers()
+{
+ return offersCheckBox->isChecked();
+}
+//! [6]
+
+//! [7]
+void DetailsDialog::verify()
+{
+ if (!nameEdit->text().isEmpty() && !addressEdit->toPlainText().isEmpty()) {
+ accept();
+ return;
+ }
+
+ QMessageBox::StandardButton answer;
+ answer = QMessageBox::warning(this, tr("Incomplete Form"),
+ tr("The form does not contain all the necessary information.\n"
+ "Do you want to discard it?"),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (answer == QMessageBox::Yes)
+ reject();
+}
+//! [7]
diff --git a/examples/widgets/richtext/orderform/detailsdialog.h b/examples/widgets/richtext/orderform/detailsdialog.h
new file mode 100644
index 0000000000..ee964d082e
--- /dev/null
+++ b/examples/widgets/richtext/orderform/detailsdialog.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DETAILSDIALOG_H
+#define DETAILSDIALOG_H
+
+#include <QDialog>
+#include <QList>
+#include <QPair>
+#include <QString>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QDialogButtonBox;
+class QLabel;
+class QLineEdit;
+class QTableWidget;
+class QTextEdit;
+class QWidget;
+QT_END_NAMESPACE
+
+//! [0]
+class DetailsDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ DetailsDialog(const QString &title, QWidget *parent);
+
+public slots:
+ void verify();
+
+public:
+ QList<QPair<QString, int> > orderItems();
+ QString senderName() const;
+ QString senderAddress() const;
+ bool sendOffers();
+
+private:
+ void setupItemsTable();
+
+ QLabel *nameLabel;
+ QLabel *addressLabel;
+ QCheckBox *offersCheckBox;
+ QLineEdit *nameEdit;
+ QStringList items;
+ QTableWidget *itemsTable;
+ QTextEdit *addressEdit;
+ QDialogButtonBox *buttonBox;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/richtext/orderform/main.cpp b/examples/widgets/richtext/orderform/main.cpp
new file mode 100644
index 0000000000..fc14fbb625
--- /dev/null
+++ b/examples/widgets/richtext/orderform/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.resize(640, 480);
+ window.show();
+ window.createSample();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/widgets/richtext/orderform/mainwindow.cpp b/examples/widgets/richtext/orderform/mainwindow.cpp
new file mode 100644
index 0000000000..44b3cb4f9a
--- /dev/null
+++ b/examples/widgets/richtext/orderform/mainwindow.cpp
@@ -0,0 +1,253 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#ifndef QT_NO_PRINTER
+#include <QPrinter>
+#include <QPrintDialog>
+#endif
+
+#include "detailsdialog.h"
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ QMenu *fileMenu = new QMenu(tr("&File"), this);
+ QAction *newAction = fileMenu->addAction(tr("&New..."));
+ newAction->setShortcuts(QKeySequence::New);
+ printAction = fileMenu->addAction(tr("&Print..."), this, SLOT(printFile()));
+ printAction->setShortcuts(QKeySequence::Print);
+ printAction->setEnabled(false);
+ QAction *quitAction = fileMenu->addAction(tr("E&xit"));
+ quitAction->setShortcuts(QKeySequence::Quit);
+ menuBar()->addMenu(fileMenu);
+
+ letters = new QTabWidget;
+
+ connect(newAction, SIGNAL(triggered()), this, SLOT(openDialog()));
+ connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
+
+ setCentralWidget(letters);
+ setWindowTitle(tr("Order Form"));
+}
+//! [0]
+
+//! [1]
+void MainWindow::createLetter(const QString &name, const QString &address,
+ QList<QPair<QString,int> > orderItems,
+ bool sendOffers)
+{
+ QTextEdit *editor = new QTextEdit;
+ int tabIndex = letters->addTab(editor, name);
+ letters->setCurrentIndex(tabIndex);
+//! [1]
+
+//! [2]
+ QTextCursor cursor(editor->textCursor());
+ cursor.movePosition(QTextCursor::Start);
+//! [2] //! [3]
+ QTextFrame *topFrame = cursor.currentFrame();
+ QTextFrameFormat topFrameFormat = topFrame->frameFormat();
+ topFrameFormat.setPadding(16);
+ topFrame->setFrameFormat(topFrameFormat);
+
+ QTextCharFormat textFormat;
+ QTextCharFormat boldFormat;
+ boldFormat.setFontWeight(QFont::Bold);
+
+ QTextFrameFormat referenceFrameFormat;
+ referenceFrameFormat.setBorder(1);
+ referenceFrameFormat.setPadding(8);
+ referenceFrameFormat.setPosition(QTextFrameFormat::FloatRight);
+ referenceFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 40));
+ cursor.insertFrame(referenceFrameFormat);
+
+ cursor.insertText("A company", boldFormat);
+ cursor.insertBlock();
+ cursor.insertText("321 City Street");
+ cursor.insertBlock();
+ cursor.insertText("Industry Park");
+ cursor.insertBlock();
+ cursor.insertText("Another country");
+//! [3]
+
+//! [4]
+ cursor.setPosition(topFrame->lastPosition());
+
+ cursor.insertText(name, textFormat);
+ QString line;
+ foreach (line, address.split("\n")) {
+ cursor.insertBlock();
+ cursor.insertText(line);
+ }
+//! [4] //! [5]
+ cursor.insertBlock();
+ cursor.insertBlock();
+
+ QDate date = QDate::currentDate();
+ cursor.insertText(tr("Date: %1").arg(date.toString("d MMMM yyyy")),
+ textFormat);
+ cursor.insertBlock();
+
+ QTextFrameFormat bodyFrameFormat;
+ bodyFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
+ cursor.insertFrame(bodyFrameFormat);
+//! [5]
+
+//! [6]
+ cursor.insertText(tr("I would like to place an order for the following "
+ "items:"), textFormat);
+ cursor.insertBlock();
+//! [6] //! [7]
+ cursor.insertBlock();
+//! [7]
+
+//! [8]
+ QTextTableFormat orderTableFormat;
+ orderTableFormat.setAlignment(Qt::AlignHCenter);
+ QTextTable *orderTable = cursor.insertTable(1, 2, orderTableFormat);
+
+ QTextFrameFormat orderFrameFormat = cursor.currentFrame()->frameFormat();
+ orderFrameFormat.setBorder(1);
+ cursor.currentFrame()->setFrameFormat(orderFrameFormat);
+//! [8]
+
+//! [9]
+ cursor = orderTable->cellAt(0, 0).firstCursorPosition();
+ cursor.insertText(tr("Product"), boldFormat);
+ cursor = orderTable->cellAt(0, 1).firstCursorPosition();
+ cursor.insertText(tr("Quantity"), boldFormat);
+//! [9]
+
+//! [10]
+ for (int i = 0; i < orderItems.count(); ++i) {
+ QPair<QString,int> item = orderItems[i];
+ int row = orderTable->rows();
+
+ orderTable->insertRows(row, 1);
+ cursor = orderTable->cellAt(row, 0).firstCursorPosition();
+ cursor.insertText(item.first, textFormat);
+ cursor = orderTable->cellAt(row, 1).firstCursorPosition();
+ cursor.insertText(QString("%1").arg(item.second), textFormat);
+ }
+//! [10]
+
+//! [11]
+ cursor.setPosition(topFrame->lastPosition());
+
+ cursor.insertBlock();
+//! [11] //! [12]
+ cursor.insertText(tr("Please update my records to take account of the "
+ "following privacy information:"));
+ cursor.insertBlock();
+//! [12]
+
+//! [13]
+ QTextTable *offersTable = cursor.insertTable(2, 2);
+
+ cursor = offersTable->cellAt(0, 1).firstCursorPosition();
+ cursor.insertText(tr("I want to receive more information about your "
+ "company's products and special offers."), textFormat);
+ cursor = offersTable->cellAt(1, 1).firstCursorPosition();
+ cursor.insertText(tr("I do not want to receive any promotional information "
+ "from your company."), textFormat);
+
+ if (sendOffers)
+ cursor = offersTable->cellAt(0, 0).firstCursorPosition();
+ else
+ cursor = offersTable->cellAt(1, 0).firstCursorPosition();
+
+ cursor.insertText("X", boldFormat);
+//! [13]
+
+//! [14]
+ cursor.setPosition(topFrame->lastPosition());
+ cursor.insertBlock();
+ cursor.insertText(tr("Sincerely,"), textFormat);
+ cursor.insertBlock();
+ cursor.insertBlock();
+ cursor.insertBlock();
+ cursor.insertText(name);
+
+ printAction->setEnabled(true);
+}
+//! [14]
+
+//! [15]
+void MainWindow::createSample()
+{
+ DetailsDialog dialog("Dialog with default values", this);
+ createLetter("Mr. Smith", "12 High Street\nSmall Town\nThis country",
+ dialog.orderItems(), true);
+}
+//! [15]
+
+//! [16]
+void MainWindow::openDialog()
+{
+ DetailsDialog dialog(tr("Enter Customer Details"), this);
+
+ if (dialog.exec() == QDialog::Accepted)
+ createLetter(dialog.senderName(), dialog.senderAddress(),
+ dialog.orderItems(), dialog.sendOffers());
+}
+//! [16]
+
+//! [17]
+void MainWindow::printFile()
+{
+#ifndef QT_NO_PRINTER
+ QTextEdit *editor = static_cast<QTextEdit*>(letters->currentWidget());
+//! [18]
+ QPrinter printer;
+
+ QPrintDialog *dialog = new QPrintDialog(&printer, this);
+ dialog->setWindowTitle(tr("Print Document"));
+ if (editor->textCursor().hasSelection())
+ dialog->addEnabledOption(QAbstractPrintDialog::PrintSelection);
+ if (dialog->exec() != QDialog::Accepted)
+ return;
+//! [18]
+
+ editor->print(&printer);
+#endif
+}
+//! [17]
diff --git a/examples/widgets/richtext/orderform/mainwindow.h b/examples/widgets/richtext/orderform/mainwindow.h
new file mode 100644
index 0000000000..e688f42a80
--- /dev/null
+++ b/examples/widgets/richtext/orderform/mainwindow.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QList>
+#include <QMainWindow>
+#include <QPair>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QTabWidget;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+ void createSample();
+
+public slots:
+ void openDialog();
+ void printFile();
+
+private:
+ void createLetter(const QString &name, const QString &address,
+ QList<QPair<QString,int> > orderItems,
+ bool sendOffers);
+
+ QAction *printAction;
+ QTabWidget *letters;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/richtext/orderform/orderform.desktop b/examples/widgets/richtext/orderform/orderform.desktop
new file mode 100644
index 0000000000..4690cbc876
--- /dev/null
+++ b/examples/widgets/richtext/orderform/orderform.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Order Form
+Exec=/opt/usr/bin/orderform
+Icon=orderform
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/richtext/orderform/orderform.pro b/examples/widgets/richtext/orderform/orderform.pro
new file mode 100644
index 0000000000..4aefb99428
--- /dev/null
+++ b/examples/widgets/richtext/orderform/orderform.pro
@@ -0,0 +1,14 @@
+HEADERS = detailsdialog.h \
+ mainwindow.h
+SOURCES = detailsdialog.cpp \
+ main.cpp \
+ mainwindow.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/orderform
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS orderform.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/orderform
+INSTALLS += target sources
+
+QT += widgets
+!isEmpty(QT.printsupport.name): QT += printsupport
diff --git a/examples/widgets/richtext/richtext.pro b/examples/widgets/richtext/richtext.pro
new file mode 100644
index 0000000000..511edb9ea9
--- /dev/null
+++ b/examples/widgets/richtext/richtext.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+SUBDIRS = calendar \
+ orderform \
+ syntaxhighlighter \
+ textedit
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS richtext.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext
+INSTALLS += target sources
diff --git a/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
new file mode 100644
index 0000000000..826e132110
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "highlighter.h"
+
+//! [0]
+Highlighter::Highlighter(QTextDocument *parent)
+ : QSyntaxHighlighter(parent)
+{
+ HighlightingRule rule;
+
+ keywordFormat.setForeground(Qt::darkBlue);
+ keywordFormat.setFontWeight(QFont::Bold);
+ QStringList keywordPatterns;
+ keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b"
+ << "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b"
+ << "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b"
+ << "\\blong\\b" << "\\bnamespace\\b" << "\\boperator\\b"
+ << "\\bprivate\\b" << "\\bprotected\\b" << "\\bpublic\\b"
+ << "\\bshort\\b" << "\\bsignals\\b" << "\\bsigned\\b"
+ << "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b"
+ << "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b"
+ << "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b"
+ << "\\bvoid\\b" << "\\bvolatile\\b";
+ foreach (const QString &pattern, keywordPatterns) {
+ rule.pattern = QRegExp(pattern);
+ rule.format = keywordFormat;
+ highlightingRules.append(rule);
+//! [0] //! [1]
+ }
+//! [1]
+
+//! [2]
+ classFormat.setFontWeight(QFont::Bold);
+ classFormat.setForeground(Qt::darkMagenta);
+ rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
+ rule.format = classFormat;
+ highlightingRules.append(rule);
+//! [2]
+
+//! [3]
+ singleLineCommentFormat.setForeground(Qt::red);
+ rule.pattern = QRegExp("//[^\n]*");
+ rule.format = singleLineCommentFormat;
+ highlightingRules.append(rule);
+
+ multiLineCommentFormat.setForeground(Qt::red);
+//! [3]
+
+//! [4]
+ quotationFormat.setForeground(Qt::darkGreen);
+ rule.pattern = QRegExp("\".*\"");
+ rule.format = quotationFormat;
+ highlightingRules.append(rule);
+//! [4]
+
+//! [5]
+ functionFormat.setFontItalic(true);
+ functionFormat.setForeground(Qt::blue);
+ rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
+ rule.format = functionFormat;
+ highlightingRules.append(rule);
+//! [5]
+
+//! [6]
+ commentStartExpression = QRegExp("/\\*");
+ commentEndExpression = QRegExp("\\*/");
+}
+//! [6]
+
+//! [7]
+void Highlighter::highlightBlock(const QString &text)
+{
+ foreach (const HighlightingRule &rule, highlightingRules) {
+ QRegExp expression(rule.pattern);
+ int index = expression.indexIn(text);
+ while (index >= 0) {
+ int length = expression.matchedLength();
+ setFormat(index, length, rule.format);
+ index = expression.indexIn(text, index + length);
+ }
+ }
+//! [7] //! [8]
+ setCurrentBlockState(0);
+//! [8]
+
+//! [9]
+ int startIndex = 0;
+ if (previousBlockState() != 1)
+ startIndex = commentStartExpression.indexIn(text);
+
+//! [9] //! [10]
+ while (startIndex >= 0) {
+//! [10] //! [11]
+ int endIndex = commentEndExpression.indexIn(text, startIndex);
+ int commentLength;
+ if (endIndex == -1) {
+ setCurrentBlockState(1);
+ commentLength = text.length() - startIndex;
+ } else {
+ commentLength = endIndex - startIndex
+ + commentEndExpression.matchedLength();
+ }
+ setFormat(startIndex, commentLength, multiLineCommentFormat);
+ startIndex = commentStartExpression.indexIn(text, startIndex + commentLength);
+ }
+}
+//! [11]
diff --git a/examples/widgets/richtext/syntaxhighlighter/highlighter.h b/examples/widgets/richtext/syntaxhighlighter/highlighter.h
new file mode 100644
index 0000000000..3f75063f89
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/highlighter.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef HIGHLIGHTER_H
+#define HIGHLIGHTER_H
+
+#include <QSyntaxHighlighter>
+
+#include <QHash>
+#include <QTextCharFormat>
+
+QT_BEGIN_NAMESPACE
+class QTextDocument;
+QT_END_NAMESPACE
+
+//! [0]
+class Highlighter : public QSyntaxHighlighter
+{
+ Q_OBJECT
+
+public:
+ Highlighter(QTextDocument *parent = 0);
+
+protected:
+ void highlightBlock(const QString &text);
+
+private:
+ struct HighlightingRule
+ {
+ QRegExp pattern;
+ QTextCharFormat format;
+ };
+ QVector<HighlightingRule> highlightingRules;
+
+ QRegExp commentStartExpression;
+ QRegExp commentEndExpression;
+
+ QTextCharFormat keywordFormat;
+ QTextCharFormat classFormat;
+ QTextCharFormat singleLineCommentFormat;
+ QTextCharFormat multiLineCommentFormat;
+ QTextCharFormat quotationFormat;
+ QTextCharFormat functionFormat;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/richtext/syntaxhighlighter/main.cpp b/examples/widgets/richtext/syntaxhighlighter/main.cpp
new file mode 100644
index 0000000000..5c2f0f236d
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.resize(640, 512);
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp b/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp
new file mode 100644
index 0000000000..ffb02ebb9b
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ setupFileMenu();
+ setupHelpMenu();
+ setupEditor();
+
+ setCentralWidget(editor);
+ setWindowTitle(tr("Syntax Highlighter"));
+}
+//! [0]
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Syntax Highlighter"),
+ tr("<p>The <b>Syntax Highlighter</b> example shows how " \
+ "to perform simple syntax highlighting by subclassing " \
+ "the QSyntaxHighlighter class and describing " \
+ "highlighting rules using regular expressions.</p>"));
+}
+
+void MainWindow::newFile()
+{
+ editor->clear();
+}
+
+void MainWindow::openFile(const QString &path)
+{
+ QString fileName = path;
+
+ if (fileName.isNull())
+ fileName = QFileDialog::getOpenFileName(this,
+ tr("Open File"), "", "C++ Files (*.cpp *.h)");
+
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+ if (file.open(QFile::ReadOnly | QFile::Text))
+ editor->setPlainText(file.readAll());
+ }
+}
+
+//! [1]
+void MainWindow::setupEditor()
+{
+ QFont font;
+ font.setFamily("Courier");
+ font.setFixedPitch(true);
+ font.setPointSize(10);
+
+ editor = new QTextEdit;
+ editor->setFont(font);
+
+ highlighter = new Highlighter(editor->document());
+
+ QFile file("mainwindow.h");
+ if (file.open(QFile::ReadOnly | QFile::Text))
+ editor->setPlainText(file.readAll());
+}
+//! [1]
+
+void MainWindow::setupFileMenu()
+{
+ QMenu *fileMenu = new QMenu(tr("&File"), this);
+ menuBar()->addMenu(fileMenu);
+
+ fileMenu->addAction(tr("&New"), this, SLOT(newFile()),
+ QKeySequence::New);
+
+ fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()),
+ QKeySequence::Open);
+
+ fileMenu->addAction(tr("E&xit"), qApp, SLOT(quit()),
+ QKeySequence::Quit);
+}
+
+void MainWindow::setupHelpMenu()
+{
+ QMenu *helpMenu = new QMenu(tr("&Help"), this);
+ menuBar()->addMenu(helpMenu);
+
+ helpMenu->addAction(tr("&About"), this, SLOT(about()));
+ helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
+}
diff --git a/examples/widgets/richtext/syntaxhighlighter/mainwindow.h b/examples/widgets/richtext/syntaxhighlighter/mainwindow.h
new file mode 100644
index 0000000000..082ea77ba4
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/mainwindow.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include "highlighter.h"
+
+QT_BEGIN_NAMESPACE
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+public slots:
+ void about();
+ void newFile();
+ void openFile(const QString &path = QString());
+
+private:
+ void setupEditor();
+ void setupFileMenu();
+ void setupHelpMenu();
+
+ QTextEdit *editor;
+ Highlighter *highlighter;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.desktop b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.desktop
new file mode 100644
index 0000000000..2e3c833f0e
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Syntax Highlighter
+Exec=/opt/usr/bin/syntaxhighlighter
+Icon=syntaxhighlighter
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro
new file mode 100644
index 0000000000..0f9b447a74
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro
@@ -0,0 +1,20 @@
+HEADERS = highlighter.h \
+ mainwindow.h
+SOURCES = highlighter.cpp \
+ mainwindow.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/syntaxhighlighter
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS syntaxhighlighter.pro examples
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/syntaxhighlighter
+INSTALLS += target sources
+
+
+wince*: {
+ addFiles.files = main.cpp mainwindow.cpp
+ addFiles.path = .
+ DEPLOYMENT += addFiles
+}
+QT += widgets
+
diff --git a/examples/widgets/richtext/textedit/example.html b/examples/widgets/richtext/textedit/example.html
new file mode 100644
index 0000000000..cdc8d2a23d
--- /dev/null
+++ b/examples/widgets/richtext/textedit/example.html
@@ -0,0 +1,79 @@
+<html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>QTextEdit Example</title><style type="text/css">
+p, li { white-space: pre-wrap; }
+</style></head><body style=" font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
+<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:20pt; font-weight:600;">QTextEdit</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">The QTextEdit widget is an advanced editor that supports formatted rich text. It can be used to display HTML and other rich document formats. Internally, QTextEdit uses the QTextDocument class to describe both the high-level structure of each document and the low-level formatting of paragraphs.</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">If you are viewing this document in the <span style=" font-style:italic;">textedit</span> example, you can edit this document to explore Qt's rich text editing features. We have included some comments in each of the following sections to encourage you to experiment. </p>
+<p style=" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:18pt; font-weight:600;"><span style=" font-size:16pt;">Font and Paragraph Styles</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">QTextEdit supports </span><span style=" font-size:11pt; font-weight:600;">bold</span><span style=" font-size:11pt;">, </span><span style=" font-size:11pt; font-style:italic;">italic</span><span style=" font-size:11pt;">, and </span><span style=" font-size:11pt; text-decoration: underline;">underlined</span><span style=" font-size:11pt;"> font styles, and can display </span><span style=" font-size:11pt; font-weight:600; color:#00007f;">multicolored</span><span style=" font-size:11pt;"> </span><span style=" font-size:11pt; font-weight:600; color:#aa0000;">text</span><span style=" font-size:11pt;">. Font families such as </span><span style=" font-family:'Times'; font-size:11pt; font-weight:600;">Times New Roman</span><span style=" font-size:11pt;"> and </span><span style=" font-family:'Courier'; font-size:11pt; font-weight:600;">Courier</span><span style=" font-size:11pt;"> can also be used directly. </span><span style=" font-size:11pt; font-style:italic;">If you place the cursor in a region of styled text, the controls in the tool bars will change to reflect the current style.</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Paragraphs can be formatted so that the text is left-aligned, right-aligned, centered, or fully justified.</p>
+<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try changing the alignment of some text and resize the editor to see how the text layout changes.</span> </p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:16pt; font-weight:600;">Lists</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">Different kinds of lists can be included in rich text documents. Standard bullet lists can be nested, using different symbols for each level of the list: </span></p>
+<ul style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Disc symbols are typically used for top-level list items. </li></ul>
+<ul type=circle style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Circle symbols can be used to distinguish between items in lower-level lists.</li></ul>
+<ul type=square style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Square symbols provide a reasonable alternative to discs and circles. </li></ul>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Ordered lists can be created that can be used for tables of contents. Different characters can be used to enumerate items, and we can use both Roman and Arabic numerals in the same list structure: </p>
+<ol style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction</li>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Tools </li></ol>
+<ol type=a style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Assistant</li>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Designer</li>
+<ol type=A style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Form Editor</li>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Component Architecture</li></ol>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Linguist</li></ol>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">The list will automatically be renumbered if you add or remove items. <span style=" font-style:italic;">Try adding new sections to the above list or removing existing item to see the numbers change.</span> </p>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Images</span></p>
+<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">Inline images are treated like ordinary ranges of characters in the text editor, so they flow with the surrounding text. Images can also be selected in the same way as text, making it easy to cut, copy, and paste them. </span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><img src=":/images/logo32.png" /><span style=" font-style:italic;"> Try to select this image by clicking and dragging over it with the mouse, or use the text cursor to select it by holding down Shift and using the arrow keys. You can then cut or copy it, and paste it into different parts of this document.</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Tables</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">QTextEdit can arrange and format tables, supporting features such as row and column spans, text formatting within cells, and size constraints for columns. </span></p>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<table border="1" align="center" width="90%" cellspacing="0" cellpadding="4">
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Development Tools </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Programming Techniques </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Graphical User Interfaces </span></p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">9:00 - 11:00 </span></p></td>
+<td colspan="3">
+<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction to <span style=" font-style:italic;">Qt </span></p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">11:00 - 13:00 </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Using <span style=" font-style:italic;">qmake</span> </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Object-oriented Programming </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Layouts in <span style=" font-style:italic;">Qt</span> </p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">13:00 - 15:00 </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Designer</span> Tutorial </p></td>
+<td rowspan="2">
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Extreme Programming </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Writing Custom Styles </p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">15:00 - 17:00 </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Linguist</span> and Internationalization </p></td>
+<td></td></tr></table>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt; font-style:italic;">Try adding text to the cells in the table and experiment with the alignment of the paragraphs.</p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Hyperlinks</span></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">QTextEdit is designed to support hyperlinks between documents, and this feature is used extensively in </span><span style=" font-size:11pt; font-style:italic;">Qt Assistant</span><span style=" font-size:11pt;">. Hyperlinks are automatically created when an HTML file is imported into an editor. Since the rich text framework supports hyperlinks natively, they can also be created programatically.</span></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Undo and Redo</span></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Full support for undo and redo operations is built into QTextEdit and the underlying rich text framework. Operations on a document can be packaged together to make editing a more comfortable experience for the user.</p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try making changes to this document and press Ctrl+Z to undo them. You can always recover the original contents of the document.</span> </p></body></html>
diff --git a/examples/widgets/richtext/textedit/images/logo32.png b/examples/widgets/richtext/textedit/images/logo32.png
new file mode 100644
index 0000000000..5f91e9873b
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/logo32.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editcopy.png b/examples/widgets/richtext/textedit/images/mac/editcopy.png
new file mode 100644
index 0000000000..f551364464
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/editcopy.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editcut.png b/examples/widgets/richtext/textedit/images/mac/editcut.png
new file mode 100644
index 0000000000..a784fd5709
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/editcut.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editpaste.png b/examples/widgets/richtext/textedit/images/mac/editpaste.png
new file mode 100644
index 0000000000..64c0b2d6ab
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/editpaste.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editredo.png b/examples/widgets/richtext/textedit/images/mac/editredo.png
new file mode 100644
index 0000000000..8875bf246c
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/editredo.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editundo.png b/examples/widgets/richtext/textedit/images/mac/editundo.png
new file mode 100644
index 0000000000..a3bd5e0bf2
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/editundo.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/exportpdf.png b/examples/widgets/richtext/textedit/images/mac/exportpdf.png
new file mode 100644
index 0000000000..ebb44e6b88
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/exportpdf.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/filenew.png b/examples/widgets/richtext/textedit/images/mac/filenew.png
new file mode 100644
index 0000000000..d3882c7b3f
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/filenew.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/fileopen.png b/examples/widgets/richtext/textedit/images/mac/fileopen.png
new file mode 100644
index 0000000000..fc06c5ec63
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/fileopen.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/fileprint.png b/examples/widgets/richtext/textedit/images/mac/fileprint.png
new file mode 100644
index 0000000000..10ca56c82a
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/fileprint.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/filesave.png b/examples/widgets/richtext/textedit/images/mac/filesave.png
new file mode 100644
index 0000000000..b41ecf5319
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/filesave.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textbold.png b/examples/widgets/richtext/textedit/images/mac/textbold.png
new file mode 100644
index 0000000000..38400bd1f6
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textbold.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textcenter.png b/examples/widgets/richtext/textedit/images/mac/textcenter.png
new file mode 100644
index 0000000000..2ef5b2ee6f
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textcenter.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textitalic.png b/examples/widgets/richtext/textedit/images/mac/textitalic.png
new file mode 100644
index 0000000000..0170ee26a6
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textitalic.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textjustify.png b/examples/widgets/richtext/textedit/images/mac/textjustify.png
new file mode 100644
index 0000000000..39cd6c1a9d
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textjustify.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textleft.png b/examples/widgets/richtext/textedit/images/mac/textleft.png
new file mode 100644
index 0000000000..83a66d5535
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textleft.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textright.png b/examples/widgets/richtext/textedit/images/mac/textright.png
new file mode 100644
index 0000000000..e7c04645cf
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textright.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textunder.png b/examples/widgets/richtext/textedit/images/mac/textunder.png
new file mode 100644
index 0000000000..968bac5e90
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textunder.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/zoomin.png b/examples/widgets/richtext/textedit/images/mac/zoomin.png
new file mode 100644
index 0000000000..d46f5aff0d
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/zoomin.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/zoomout.png b/examples/widgets/richtext/textedit/images/mac/zoomout.png
new file mode 100644
index 0000000000..46326566d1
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/zoomout.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editcopy.png b/examples/widgets/richtext/textedit/images/win/editcopy.png
new file mode 100644
index 0000000000..1121b47d8b
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/editcopy.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editcut.png b/examples/widgets/richtext/textedit/images/win/editcut.png
new file mode 100644
index 0000000000..38e55f7420
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/editcut.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editpaste.png b/examples/widgets/richtext/textedit/images/win/editpaste.png
new file mode 100644
index 0000000000..ffab15aaf8
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/editpaste.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editredo.png b/examples/widgets/richtext/textedit/images/win/editredo.png
new file mode 100644
index 0000000000..9d679fe6fc
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/editredo.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editundo.png b/examples/widgets/richtext/textedit/images/win/editundo.png
new file mode 100644
index 0000000000..eee23d24a3
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/editundo.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/exportpdf.png b/examples/widgets/richtext/textedit/images/win/exportpdf.png
new file mode 100644
index 0000000000..eef5132928
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/exportpdf.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/filenew.png b/examples/widgets/richtext/textedit/images/win/filenew.png
new file mode 100644
index 0000000000..af5d122141
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/filenew.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/fileopen.png b/examples/widgets/richtext/textedit/images/win/fileopen.png
new file mode 100644
index 0000000000..fc6f17e977
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/fileopen.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/fileprint.png b/examples/widgets/richtext/textedit/images/win/fileprint.png
new file mode 100644
index 0000000000..ba7c02dc18
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/fileprint.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/filesave.png b/examples/widgets/richtext/textedit/images/win/filesave.png
new file mode 100644
index 0000000000..8feec99bee
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/filesave.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textbold.png b/examples/widgets/richtext/textedit/images/win/textbold.png
new file mode 100644
index 0000000000..9cbc7138b9
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textbold.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textcenter.png b/examples/widgets/richtext/textedit/images/win/textcenter.png
new file mode 100644
index 0000000000..11efb4b852
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textcenter.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textitalic.png b/examples/widgets/richtext/textedit/images/win/textitalic.png
new file mode 100644
index 0000000000..b30ce14c14
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textitalic.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textjustify.png b/examples/widgets/richtext/textedit/images/win/textjustify.png
new file mode 100644
index 0000000000..9de0c88085
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textjustify.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textleft.png b/examples/widgets/richtext/textedit/images/win/textleft.png
new file mode 100644
index 0000000000..16f80bc325
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textleft.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textright.png b/examples/widgets/richtext/textedit/images/win/textright.png
new file mode 100644
index 0000000000..16872df62a
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textright.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textunder.png b/examples/widgets/richtext/textedit/images/win/textunder.png
new file mode 100644
index 0000000000..c72eff53fb
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textunder.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/zoomin.png b/examples/widgets/richtext/textedit/images/win/zoomin.png
new file mode 100644
index 0000000000..2e586fc7bf
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/zoomin.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/zoomout.png b/examples/widgets/richtext/textedit/images/win/zoomout.png
new file mode 100644
index 0000000000..a736d39343
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/zoomout.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/main.cpp b/examples/widgets/richtext/textedit/main.cpp
new file mode 100644
index 0000000000..ae12cd9979
--- /dev/null
+++ b/examples/widgets/richtext/textedit/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "textedit.h"
+#include <QApplication>
+
+int main( int argc, char ** argv )
+{
+ Q_INIT_RESOURCE(textedit);
+
+ QApplication a( argc, argv );
+ TextEdit mw;
+ mw.resize( 700, 800 );
+ mw.show();
+ return a.exec();
+}
diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp
new file mode 100644
index 0000000000..0be60230ca
--- /dev/null
+++ b/examples/widgets/richtext/textedit/textedit.cpp
@@ -0,0 +1,737 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "textedit.h"
+
+#include <QAction>
+#include <QApplication>
+#include <QClipboard>
+#include <QColorDialog>
+#include <QComboBox>
+#include <QFontComboBox>
+#include <QFile>
+#include <QFileDialog>
+#include <QFileInfo>
+#include <QFontDatabase>
+#include <QMenu>
+#include <QMenuBar>
+#include <QTextCodec>
+#include <QTextEdit>
+#include <QToolBar>
+#include <QTextCursor>
+#include <QTextDocumentWriter>
+#include <QTextList>
+#include <QtDebug>
+#include <QCloseEvent>
+#include <QMessageBox>
+#include <QMimeData>
+#ifndef QT_NO_PRINTER
+#include <QPrintDialog>
+#include <QPrinter>
+#include <QPrintPreviewDialog>
+#endif
+
+#ifdef Q_OS_MAC
+const QString rsrcPath = ":/images/mac";
+#else
+const QString rsrcPath = ":/images/win";
+#endif
+
+TextEdit::TextEdit(QWidget *parent)
+ : QMainWindow(parent)
+{
+ setToolButtonStyle(Qt::ToolButtonFollowStyle);
+ setupFileActions();
+ setupEditActions();
+ setupTextActions();
+
+ {
+ QMenu *helpMenu = new QMenu(tr("Help"), this);
+ menuBar()->addMenu(helpMenu);
+ helpMenu->addAction(tr("About"), this, SLOT(about()));
+ helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
+ }
+
+ textEdit = new QTextEdit(this);
+ connect(textEdit, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
+ this, SLOT(currentCharFormatChanged(QTextCharFormat)));
+ connect(textEdit, SIGNAL(cursorPositionChanged()),
+ this, SLOT(cursorPositionChanged()));
+
+ setCentralWidget(textEdit);
+ textEdit->setFocus();
+ setCurrentFileName(QString());
+
+ fontChanged(textEdit->font());
+ colorChanged(textEdit->textColor());
+ alignmentChanged(textEdit->alignment());
+
+ connect(textEdit->document(), SIGNAL(modificationChanged(bool)),
+ actionSave, SLOT(setEnabled(bool)));
+ connect(textEdit->document(), SIGNAL(modificationChanged(bool)),
+ this, SLOT(setWindowModified(bool)));
+ connect(textEdit->document(), SIGNAL(undoAvailable(bool)),
+ actionUndo, SLOT(setEnabled(bool)));
+ connect(textEdit->document(), SIGNAL(redoAvailable(bool)),
+ actionRedo, SLOT(setEnabled(bool)));
+
+ setWindowModified(textEdit->document()->isModified());
+ actionSave->setEnabled(textEdit->document()->isModified());
+ actionUndo->setEnabled(textEdit->document()->isUndoAvailable());
+ actionRedo->setEnabled(textEdit->document()->isRedoAvailable());
+
+ connect(actionUndo, SIGNAL(triggered()), textEdit, SLOT(undo()));
+ connect(actionRedo, SIGNAL(triggered()), textEdit, SLOT(redo()));
+
+ actionCut->setEnabled(false);
+ actionCopy->setEnabled(false);
+
+ connect(actionCut, SIGNAL(triggered()), textEdit, SLOT(cut()));
+ connect(actionCopy, SIGNAL(triggered()), textEdit, SLOT(copy()));
+ connect(actionPaste, SIGNAL(triggered()), textEdit, SLOT(paste()));
+
+ connect(textEdit, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
+ connect(textEdit, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));
+
+#ifndef QT_NO_CLIPBOARD
+ connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
+#endif
+
+ QString initialFile = ":/example.html";
+ const QStringList args = QCoreApplication::arguments();
+ if (args.count() == 2)
+ initialFile = args.at(1);
+
+ if (!load(initialFile))
+ fileNew();
+}
+
+void TextEdit::closeEvent(QCloseEvent *e)
+{
+ if (maybeSave())
+ e->accept();
+ else
+ e->ignore();
+}
+
+void TextEdit::setupFileActions()
+{
+ QToolBar *tb = new QToolBar(this);
+ tb->setWindowTitle(tr("File Actions"));
+ addToolBar(tb);
+
+ QMenu *menu = new QMenu(tr("&File"), this);
+ menuBar()->addMenu(menu);
+
+ QAction *a;
+
+ QIcon newIcon = QIcon::fromTheme("document-new", QIcon(rsrcPath + "/filenew.png"));
+ a = new QAction( newIcon, tr("&New"), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::New);
+ connect(a, SIGNAL(triggered()), this, SLOT(fileNew()));
+ tb->addAction(a);
+ menu->addAction(a);
+
+ a = new QAction(QIcon::fromTheme("document-open", QIcon(rsrcPath + "/fileopen.png")),
+ tr("&Open..."), this);
+ a->setShortcut(QKeySequence::Open);
+ connect(a, SIGNAL(triggered()), this, SLOT(fileOpen()));
+ tb->addAction(a);
+ menu->addAction(a);
+
+ menu->addSeparator();
+
+ actionSave = a = new QAction(QIcon::fromTheme("document-save", QIcon(rsrcPath + "/filesave.png")),
+ tr("&Save"), this);
+ a->setShortcut(QKeySequence::Save);
+ connect(a, SIGNAL(triggered()), this, SLOT(fileSave()));
+ a->setEnabled(false);
+ tb->addAction(a);
+ menu->addAction(a);
+
+ a = new QAction(tr("Save &As..."), this);
+ a->setPriority(QAction::LowPriority);
+ connect(a, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
+ menu->addAction(a);
+ menu->addSeparator();
+
+#ifndef QT_NO_PRINTER
+ a = new QAction(QIcon::fromTheme("document-print", QIcon(rsrcPath + "/fileprint.png")),
+ tr("&Print..."), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::Print);
+ connect(a, SIGNAL(triggered()), this, SLOT(filePrint()));
+ tb->addAction(a);
+ menu->addAction(a);
+
+ a = new QAction(QIcon::fromTheme("fileprint", QIcon(rsrcPath + "/fileprint.png")),
+ tr("Print Preview..."), this);
+ connect(a, SIGNAL(triggered()), this, SLOT(filePrintPreview()));
+ menu->addAction(a);
+
+ a = new QAction(QIcon::fromTheme("exportpdf", QIcon(rsrcPath + "/exportpdf.png")),
+ tr("&Export PDF..."), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(Qt::CTRL + Qt::Key_D);
+ connect(a, SIGNAL(triggered()), this, SLOT(filePrintPdf()));
+ tb->addAction(a);
+ menu->addAction(a);
+
+ menu->addSeparator();
+#endif
+
+ a = new QAction(tr("&Quit"), this);
+ a->setShortcut(Qt::CTRL + Qt::Key_Q);
+ connect(a, SIGNAL(triggered()), this, SLOT(close()));
+ menu->addAction(a);
+}
+
+void TextEdit::setupEditActions()
+{
+ QToolBar *tb = new QToolBar(this);
+ tb->setWindowTitle(tr("Edit Actions"));
+ addToolBar(tb);
+ QMenu *menu = new QMenu(tr("&Edit"), this);
+ menuBar()->addMenu(menu);
+
+ QAction *a;
+ a = actionUndo = new QAction(QIcon::fromTheme("edit-undo", QIcon(rsrcPath + "/editundo.png")),
+ tr("&Undo"), this);
+ a->setShortcut(QKeySequence::Undo);
+ tb->addAction(a);
+ menu->addAction(a);
+ a = actionRedo = new QAction(QIcon::fromTheme("edit-redo", QIcon(rsrcPath + "/editredo.png")),
+ tr("&Redo"), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::Redo);
+ tb->addAction(a);
+ menu->addAction(a);
+ menu->addSeparator();
+ a = actionCut = new QAction(QIcon::fromTheme("edit-cut", QIcon(rsrcPath + "/editcut.png")),
+ tr("Cu&t"), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::Cut);
+ tb->addAction(a);
+ menu->addAction(a);
+ a = actionCopy = new QAction(QIcon::fromTheme("edit-copy", QIcon(rsrcPath + "/editcopy.png")),
+ tr("&Copy"), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::Copy);
+ tb->addAction(a);
+ menu->addAction(a);
+ a = actionPaste = new QAction(QIcon::fromTheme("edit-paste", QIcon(rsrcPath + "/editpaste.png")),
+ tr("&Paste"), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::Paste);
+ tb->addAction(a);
+ menu->addAction(a);
+#ifndef QT_NO_CLIPBOARD
+ if (const QMimeData *md = QApplication::clipboard()->mimeData())
+ actionPaste->setEnabled(md->hasText());
+#endif
+}
+
+void TextEdit::setupTextActions()
+{
+ QToolBar *tb = new QToolBar(this);
+ tb->setWindowTitle(tr("Format Actions"));
+ addToolBar(tb);
+
+ QMenu *menu = new QMenu(tr("F&ormat"), this);
+ menuBar()->addMenu(menu);
+
+ actionTextBold = new QAction(QIcon::fromTheme("format-text-bold", QIcon(rsrcPath + "/textbold.png")),
+ tr("&Bold"), this);
+ actionTextBold->setShortcut(Qt::CTRL + Qt::Key_B);
+ actionTextBold->setPriority(QAction::LowPriority);
+ QFont bold;
+ bold.setBold(true);
+ actionTextBold->setFont(bold);
+ connect(actionTextBold, SIGNAL(triggered()), this, SLOT(textBold()));
+ tb->addAction(actionTextBold);
+ menu->addAction(actionTextBold);
+ actionTextBold->setCheckable(true);
+
+ actionTextItalic = new QAction(QIcon::fromTheme("format-text-italic", QIcon(rsrcPath + "/textitalic.png")),
+ tr("&Italic"), this);
+ actionTextItalic->setPriority(QAction::LowPriority);
+ actionTextItalic->setShortcut(Qt::CTRL + Qt::Key_I);
+ QFont italic;
+ italic.setItalic(true);
+ actionTextItalic->setFont(italic);
+ connect(actionTextItalic, SIGNAL(triggered()), this, SLOT(textItalic()));
+ tb->addAction(actionTextItalic);
+ menu->addAction(actionTextItalic);
+ actionTextItalic->setCheckable(true);
+
+ actionTextUnderline = new QAction(QIcon::fromTheme("format-text-underline", QIcon(rsrcPath + "/textunder.png")),
+ tr("&Underline"), this);
+ actionTextUnderline->setShortcut(Qt::CTRL + Qt::Key_U);
+ actionTextUnderline->setPriority(QAction::LowPriority);
+ QFont underline;
+ underline.setUnderline(true);
+ actionTextUnderline->setFont(underline);
+ connect(actionTextUnderline, SIGNAL(triggered()), this, SLOT(textUnderline()));
+ tb->addAction(actionTextUnderline);
+ menu->addAction(actionTextUnderline);
+ actionTextUnderline->setCheckable(true);
+
+ menu->addSeparator();
+
+ QActionGroup *grp = new QActionGroup(this);
+ connect(grp, SIGNAL(triggered(QAction*)), this, SLOT(textAlign(QAction*)));
+
+ // Make sure the alignLeft is always left of the alignRight
+ if (QApplication::isLeftToRight()) {
+ actionAlignLeft = new QAction(QIcon::fromTheme("format-justify-left", QIcon(rsrcPath + "/textleft.png")),
+ tr("&Left"), grp);
+ actionAlignCenter = new QAction(QIcon::fromTheme("format-justify-center", QIcon(rsrcPath + "/textcenter.png")), tr("C&enter"), grp);
+ actionAlignRight = new QAction(QIcon::fromTheme("format-justify-right", QIcon(rsrcPath + "/textright.png")), tr("&Right"), grp);
+ } else {
+ actionAlignRight = new QAction(QIcon::fromTheme("format-justify-right", QIcon(rsrcPath + "/textright.png")), tr("&Right"), grp);
+ actionAlignCenter = new QAction(QIcon::fromTheme("format-justify-center", QIcon(rsrcPath + "/textcenter.png")), tr("C&enter"), grp);
+ actionAlignLeft = new QAction(QIcon::fromTheme("format-justify-left", QIcon(rsrcPath + "/textleft.png")), tr("&Left"), grp);
+ }
+ actionAlignJustify = new QAction(QIcon::fromTheme("format-justify-fill", QIcon(rsrcPath + "/textjustify.png")), tr("&Justify"), grp);
+
+ actionAlignLeft->setShortcut(Qt::CTRL + Qt::Key_L);
+ actionAlignLeft->setCheckable(true);
+ actionAlignLeft->setPriority(QAction::LowPriority);
+ actionAlignCenter->setShortcut(Qt::CTRL + Qt::Key_E);
+ actionAlignCenter->setCheckable(true);
+ actionAlignCenter->setPriority(QAction::LowPriority);
+ actionAlignRight->setShortcut(Qt::CTRL + Qt::Key_R);
+ actionAlignRight->setCheckable(true);
+ actionAlignRight->setPriority(QAction::LowPriority);
+ actionAlignJustify->setShortcut(Qt::CTRL + Qt::Key_J);
+ actionAlignJustify->setCheckable(true);
+ actionAlignJustify->setPriority(QAction::LowPriority);
+
+ tb->addActions(grp->actions());
+ menu->addActions(grp->actions());
+
+ menu->addSeparator();
+
+ QPixmap pix(16, 16);
+ pix.fill(Qt::black);
+ actionTextColor = new QAction(pix, tr("&Color..."), this);
+ connect(actionTextColor, SIGNAL(triggered()), this, SLOT(textColor()));
+ tb->addAction(actionTextColor);
+ menu->addAction(actionTextColor);
+
+
+ tb = new QToolBar(this);
+ tb->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
+ tb->setWindowTitle(tr("Format Actions"));
+ addToolBarBreak(Qt::TopToolBarArea);
+ addToolBar(tb);
+
+ comboStyle = new QComboBox(tb);
+ tb->addWidget(comboStyle);
+ comboStyle->addItem("Standard");
+ comboStyle->addItem("Bullet List (Disc)");
+ comboStyle->addItem("Bullet List (Circle)");
+ comboStyle->addItem("Bullet List (Square)");
+ comboStyle->addItem("Ordered List (Decimal)");
+ comboStyle->addItem("Ordered List (Alpha lower)");
+ comboStyle->addItem("Ordered List (Alpha upper)");
+ comboStyle->addItem("Ordered List (Roman lower)");
+ comboStyle->addItem("Ordered List (Roman upper)");
+ connect(comboStyle, SIGNAL(activated(int)),
+ this, SLOT(textStyle(int)));
+
+ comboFont = new QFontComboBox(tb);
+ tb->addWidget(comboFont);
+ connect(comboFont, SIGNAL(activated(QString)),
+ this, SLOT(textFamily(QString)));
+
+ comboSize = new QComboBox(tb);
+ comboSize->setObjectName("comboSize");
+ tb->addWidget(comboSize);
+ comboSize->setEditable(true);
+
+ QFontDatabase db;
+ foreach(int size, db.standardSizes())
+ comboSize->addItem(QString::number(size));
+
+ connect(comboSize, SIGNAL(activated(QString)),
+ this, SLOT(textSize(QString)));
+ comboSize->setCurrentIndex(comboSize->findText(QString::number(QApplication::font()
+ .pointSize())));
+}
+
+bool TextEdit::load(const QString &f)
+{
+ if (!QFile::exists(f))
+ return false;
+ QFile file(f);
+ if (!file.open(QFile::ReadOnly))
+ return false;
+
+ QByteArray data = file.readAll();
+ QTextCodec *codec = Qt::codecForHtml(data);
+ QString str = codec->toUnicode(data);
+ if (Qt::mightBeRichText(str)) {
+ textEdit->setHtml(str);
+ } else {
+ str = QString::fromLocal8Bit(data);
+ textEdit->setPlainText(str);
+ }
+
+ setCurrentFileName(f);
+ return true;
+}
+
+bool TextEdit::maybeSave()
+{
+ if (!textEdit->document()->isModified())
+ return true;
+ if (fileName.startsWith(QLatin1String(":/")))
+ return true;
+ QMessageBox::StandardButton ret;
+ ret = QMessageBox::warning(this, tr("Application"),
+ tr("The document has been modified.\n"
+ "Do you want to save your changes?"),
+ QMessageBox::Save | QMessageBox::Discard
+ | QMessageBox::Cancel);
+ if (ret == QMessageBox::Save)
+ return fileSave();
+ else if (ret == QMessageBox::Cancel)
+ return false;
+ return true;
+}
+
+void TextEdit::setCurrentFileName(const QString &fileName)
+{
+ this->fileName = fileName;
+ textEdit->document()->setModified(false);
+
+ QString shownName;
+ if (fileName.isEmpty())
+ shownName = "untitled.txt";
+ else
+ shownName = QFileInfo(fileName).fileName();
+
+ setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("Rich Text")));
+ setWindowModified(false);
+}
+
+void TextEdit::fileNew()
+{
+ if (maybeSave()) {
+ textEdit->clear();
+ setCurrentFileName(QString());
+ }
+}
+
+void TextEdit::fileOpen()
+{
+ QString fn = QFileDialog::getOpenFileName(this, tr("Open File..."),
+ QString(), tr("HTML-Files (*.htm *.html);;All Files (*)"));
+ if (!fn.isEmpty())
+ load(fn);
+}
+
+bool TextEdit::fileSave()
+{
+ if (fileName.isEmpty())
+ return fileSaveAs();
+
+ QTextDocumentWriter writer(fileName);
+ bool success = writer.write(textEdit->document());
+ if (success)
+ textEdit->document()->setModified(false);
+ return success;
+}
+
+bool TextEdit::fileSaveAs()
+{
+ QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."),
+ QString(), tr("ODF files (*.odt);;HTML-Files (*.htm *.html);;All Files (*)"));
+ if (fn.isEmpty())
+ return false;
+ if (! (fn.endsWith(".odt", Qt::CaseInsensitive) || fn.endsWith(".htm", Qt::CaseInsensitive) || fn.endsWith(".html", Qt::CaseInsensitive)) )
+ fn += ".odt"; // default
+ setCurrentFileName(fn);
+ return fileSave();
+}
+
+void TextEdit::filePrint()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintDialog *dlg = new QPrintDialog(&printer, this);
+ if (textEdit->textCursor().hasSelection())
+ dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection);
+ dlg->setWindowTitle(tr("Print Document"));
+ if (dlg->exec() == QDialog::Accepted) {
+ textEdit->print(&printer);
+ }
+ delete dlg;
+#endif
+}
+
+void TextEdit::filePrintPreview()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintPreviewDialog preview(&printer, this);
+ connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(printPreview(QPrinter*)));
+ preview.exec();
+#endif
+}
+
+void TextEdit::printPreview(QPrinter *printer)
+{
+#ifdef QT_NO_PRINTER
+ Q_UNUSED(printer);
+#else
+ textEdit->print(printer);
+#endif
+}
+
+
+void TextEdit::filePrintPdf()
+{
+#ifndef QT_NO_PRINTER
+//! [0]
+ QString fileName = QFileDialog::getSaveFileName(this, "Export PDF",
+ QString(), "*.pdf");
+ if (!fileName.isEmpty()) {
+ if (QFileInfo(fileName).suffix().isEmpty())
+ fileName.append(".pdf");
+ QPrinter printer(QPrinter::HighResolution);
+ printer.setOutputFormat(QPrinter::PdfFormat);
+ printer.setOutputFileName(fileName);
+ textEdit->document()->print(&printer);
+ }
+//! [0]
+#endif
+}
+
+void TextEdit::textBold()
+{
+ QTextCharFormat fmt;
+ fmt.setFontWeight(actionTextBold->isChecked() ? QFont::Bold : QFont::Normal);
+ mergeFormatOnWordOrSelection(fmt);
+}
+
+void TextEdit::textUnderline()
+{
+ QTextCharFormat fmt;
+ fmt.setFontUnderline(actionTextUnderline->isChecked());
+ mergeFormatOnWordOrSelection(fmt);
+}
+
+void TextEdit::textItalic()
+{
+ QTextCharFormat fmt;
+ fmt.setFontItalic(actionTextItalic->isChecked());
+ mergeFormatOnWordOrSelection(fmt);
+}
+
+void TextEdit::textFamily(const QString &f)
+{
+ QTextCharFormat fmt;
+ fmt.setFontFamily(f);
+ mergeFormatOnWordOrSelection(fmt);
+}
+
+void TextEdit::textSize(const QString &p)
+{
+ qreal pointSize = p.toFloat();
+ if (p.toFloat() > 0) {
+ QTextCharFormat fmt;
+ fmt.setFontPointSize(pointSize);
+ mergeFormatOnWordOrSelection(fmt);
+ }
+}
+
+void TextEdit::textStyle(int styleIndex)
+{
+ QTextCursor cursor = textEdit->textCursor();
+
+ if (styleIndex != 0) {
+ QTextListFormat::Style style = QTextListFormat::ListDisc;
+
+ switch (styleIndex) {
+ default:
+ case 1:
+ style = QTextListFormat::ListDisc;
+ break;
+ case 2:
+ style = QTextListFormat::ListCircle;
+ break;
+ case 3:
+ style = QTextListFormat::ListSquare;
+ break;
+ case 4:
+ style = QTextListFormat::ListDecimal;
+ break;
+ case 5:
+ style = QTextListFormat::ListLowerAlpha;
+ break;
+ case 6:
+ style = QTextListFormat::ListUpperAlpha;
+ break;
+ case 7:
+ style = QTextListFormat::ListLowerRoman;
+ break;
+ case 8:
+ style = QTextListFormat::ListUpperRoman;
+ break;
+ }
+
+ cursor.beginEditBlock();
+
+ QTextBlockFormat blockFmt = cursor.blockFormat();
+
+ QTextListFormat listFmt;
+
+ if (cursor.currentList()) {
+ listFmt = cursor.currentList()->format();
+ } else {
+ listFmt.setIndent(blockFmt.indent() + 1);
+ blockFmt.setIndent(0);
+ cursor.setBlockFormat(blockFmt);
+ }
+
+ listFmt.setStyle(style);
+
+ cursor.createList(listFmt);
+
+ cursor.endEditBlock();
+ } else {
+ // ####
+ QTextBlockFormat bfmt;
+ bfmt.setObjectIndex(-1);
+ cursor.mergeBlockFormat(bfmt);
+ }
+}
+
+void TextEdit::textColor()
+{
+ QColor col = QColorDialog::getColor(textEdit->textColor(), this);
+ if (!col.isValid())
+ return;
+ QTextCharFormat fmt;
+ fmt.setForeground(col);
+ mergeFormatOnWordOrSelection(fmt);
+ colorChanged(col);
+}
+
+void TextEdit::textAlign(QAction *a)
+{
+ if (a == actionAlignLeft)
+ textEdit->setAlignment(Qt::AlignLeft | Qt::AlignAbsolute);
+ else if (a == actionAlignCenter)
+ textEdit->setAlignment(Qt::AlignHCenter);
+ else if (a == actionAlignRight)
+ textEdit->setAlignment(Qt::AlignRight | Qt::AlignAbsolute);
+ else if (a == actionAlignJustify)
+ textEdit->setAlignment(Qt::AlignJustify);
+}
+
+void TextEdit::currentCharFormatChanged(const QTextCharFormat &format)
+{
+ fontChanged(format.font());
+ colorChanged(format.foreground().color());
+}
+
+void TextEdit::cursorPositionChanged()
+{
+ alignmentChanged(textEdit->alignment());
+}
+
+void TextEdit::clipboardDataChanged()
+{
+#ifndef QT_NO_CLIPBOARD
+ if (const QMimeData *md = QApplication::clipboard()->mimeData())
+ actionPaste->setEnabled(md->hasText());
+#endif
+}
+
+void TextEdit::about()
+{
+ QMessageBox::about(this, tr("About"), tr("This example demonstrates Qt's "
+ "rich text editing facilities in action, providing an example "
+ "document for you to experiment with."));
+}
+
+void TextEdit::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
+{
+ QTextCursor cursor = textEdit->textCursor();
+ if (!cursor.hasSelection())
+ cursor.select(QTextCursor::WordUnderCursor);
+ cursor.mergeCharFormat(format);
+ textEdit->mergeCurrentCharFormat(format);
+}
+
+void TextEdit::fontChanged(const QFont &f)
+{
+ comboFont->setCurrentIndex(comboFont->findText(QFontInfo(f).family()));
+ comboSize->setCurrentIndex(comboSize->findText(QString::number(f.pointSize())));
+ actionTextBold->setChecked(f.bold());
+ actionTextItalic->setChecked(f.italic());
+ actionTextUnderline->setChecked(f.underline());
+}
+
+void TextEdit::colorChanged(const QColor &c)
+{
+ QPixmap pix(16, 16);
+ pix.fill(c);
+ actionTextColor->setIcon(pix);
+}
+
+void TextEdit::alignmentChanged(Qt::Alignment a)
+{
+ if (a & Qt::AlignLeft) {
+ actionAlignLeft->setChecked(true);
+ } else if (a & Qt::AlignHCenter) {
+ actionAlignCenter->setChecked(true);
+ } else if (a & Qt::AlignRight) {
+ actionAlignRight->setChecked(true);
+ } else if (a & Qt::AlignJustify) {
+ actionAlignJustify->setChecked(true);
+ }
+}
+
diff --git a/examples/widgets/richtext/textedit/textedit.h b/examples/widgets/richtext/textedit/textedit.h
new file mode 100644
index 0000000000..e04fde4604
--- /dev/null
+++ b/examples/widgets/richtext/textedit/textedit.h
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TEXTEDIT_H
+#define TEXTEDIT_H
+
+#include <QMainWindow>
+#include <QMap>
+#include <QPointer>
+
+QT_FORWARD_DECLARE_CLASS(QAction)
+QT_FORWARD_DECLARE_CLASS(QComboBox)
+QT_FORWARD_DECLARE_CLASS(QFontComboBox)
+QT_FORWARD_DECLARE_CLASS(QTextEdit)
+QT_FORWARD_DECLARE_CLASS(QTextCharFormat)
+QT_FORWARD_DECLARE_CLASS(QMenu)
+QT_FORWARD_DECLARE_CLASS(QPrinter)
+
+class TextEdit : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ TextEdit(QWidget *parent = 0);
+
+protected:
+ virtual void closeEvent(QCloseEvent *e);
+
+private:
+ void setupFileActions();
+ void setupEditActions();
+ void setupTextActions();
+ bool load(const QString &f);
+ bool maybeSave();
+ void setCurrentFileName(const QString &fileName);
+
+private slots:
+ void fileNew();
+ void fileOpen();
+ bool fileSave();
+ bool fileSaveAs();
+ void filePrint();
+ void filePrintPreview();
+ void filePrintPdf();
+
+ void textBold();
+ void textUnderline();
+ void textItalic();
+ void textFamily(const QString &f);
+ void textSize(const QString &p);
+ void textStyle(int styleIndex);
+ void textColor();
+ void textAlign(QAction *a);
+
+ void currentCharFormatChanged(const QTextCharFormat &format);
+ void cursorPositionChanged();
+
+ void clipboardDataChanged();
+ void about();
+ void printPreview(QPrinter *);
+
+private:
+ void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
+ void fontChanged(const QFont &f);
+ void colorChanged(const QColor &c);
+ void alignmentChanged(Qt::Alignment a);
+
+ QAction *actionSave,
+ *actionTextBold,
+ *actionTextUnderline,
+ *actionTextItalic,
+ *actionTextColor,
+ *actionAlignLeft,
+ *actionAlignCenter,
+ *actionAlignRight,
+ *actionAlignJustify,
+ *actionUndo,
+ *actionRedo,
+ *actionCut,
+ *actionCopy,
+ *actionPaste;
+
+ QComboBox *comboStyle;
+ QFontComboBox *comboFont;
+ QComboBox *comboSize;
+
+ QToolBar *tb;
+ QString fileName;
+ QTextEdit *textEdit;
+};
+
+#endif
diff --git a/examples/widgets/richtext/textedit/textedit.pro b/examples/widgets/richtext/textedit/textedit.pro
new file mode 100644
index 0000000000..e172e79fe6
--- /dev/null
+++ b/examples/widgets/richtext/textedit/textedit.pro
@@ -0,0 +1,23 @@
+TEMPLATE = app
+TARGET = textedit
+
+CONFIG += qt warn_on
+
+HEADERS = textedit.h
+SOURCES = textedit.cpp \
+ main.cpp
+
+RESOURCES += textedit.qrc
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/textedit
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html *.doc images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/textedit
+INSTALLS += target sources
+
+QT += widgets
+!isEmpty(QT.printsupport.name): QT += printsupport
diff --git a/examples/widgets/richtext/textedit/textedit.qdoc b/examples/widgets/richtext/textedit/textedit.qdoc
new file mode 100644
index 0000000000..7a3aa76ab6
--- /dev/null
+++ b/examples/widgets/richtext/textedit/textedit.qdoc
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*! \page textedit-example.html
+
+ \ingroup examples
+ \title Text Edit Example
+
+ This example displays a text editor with the user interface written
+ in pure C++.
+
+ A similar example which uses \link designer-manual.book Qt
+ Designer\endlink to produce the user interface is in the \link
+ designer-manual.book Qt Designer manual\endlink.
+
+
+ See \c{$QTDIR/examples/textedit} for the source code.
+
+*/
+
+
diff --git a/examples/widgets/richtext/textedit/textedit.qrc b/examples/widgets/richtext/textedit/textedit.qrc
new file mode 100644
index 0000000000..7d6efd7d67
--- /dev/null
+++ b/examples/widgets/richtext/textedit/textedit.qrc
@@ -0,0 +1,44 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>images/logo32.png</file>
+ <file>images/mac/editcopy.png</file>
+ <file>images/mac/editcut.png</file>
+ <file>images/mac/editpaste.png</file>
+ <file>images/mac/editredo.png</file>
+ <file>images/mac/editundo.png</file>
+ <file>images/mac/exportpdf.png</file>
+ <file>images/mac/filenew.png</file>
+ <file>images/mac/fileopen.png</file>
+ <file>images/mac/fileprint.png</file>
+ <file>images/mac/filesave.png</file>
+ <file>images/mac/textbold.png</file>
+ <file>images/mac/textcenter.png</file>
+ <file>images/mac/textitalic.png</file>
+ <file>images/mac/textjustify.png</file>
+ <file>images/mac/textleft.png</file>
+ <file>images/mac/textright.png</file>
+ <file>images/mac/textunder.png</file>
+ <file>images/mac/zoomin.png</file>
+ <file>images/mac/zoomout.png</file>
+ <file>images/win/editcopy.png</file>
+ <file>images/win/editcut.png</file>
+ <file>images/win/editpaste.png</file>
+ <file>images/win/editredo.png</file>
+ <file>images/win/editundo.png</file>
+ <file>images/win/exportpdf.png</file>
+ <file>images/win/filenew.png</file>
+ <file>images/win/fileopen.png</file>
+ <file>images/win/fileprint.png</file>
+ <file>images/win/filesave.png</file>
+ <file>images/win/textbold.png</file>
+ <file>images/win/textcenter.png</file>
+ <file>images/win/textitalic.png</file>
+ <file>images/win/textjustify.png</file>
+ <file>images/win/textleft.png</file>
+ <file>images/win/textright.png</file>
+ <file>images/win/textunder.png</file>
+ <file>images/win/zoomin.png</file>
+ <file>images/win/zoomout.png</file>
+ <file>example.html</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/scroller/graphicsview/graphicsview.pro b/examples/widgets/scroller/graphicsview/graphicsview.pro
new file mode 100644
index 0000000000..ccfb82d0ca
--- /dev/null
+++ b/examples/widgets/scroller/graphicsview/graphicsview.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/scroller/graphicsview
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS graphicsview.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/scroller/graphicsview
+INSTALLS += target sources
+QT += widgets
diff --git a/examples/widgets/scroller/graphicsview/main.cpp b/examples/widgets/scroller/graphicsview/main.cpp
new file mode 100644
index 0000000000..0837719bb5
--- /dev/null
+++ b/examples/widgets/scroller/graphicsview/main.cpp
@@ -0,0 +1,291 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <QtWidgets>
+
+#define NUM_ITEMS 100
+#define NUM_LISTS 10
+
+/*!
+ \class RectObject
+ Note that it needs to be a QGraphicsObject or else the gestures will not work correctly.
+*/
+class RectObject : public QGraphicsObject
+{
+ Q_OBJECT
+
+public:
+
+ RectObject(const QString &text, qreal x, qreal y, qreal width, qreal height, QBrush brush, QGraphicsItem *parent = 0)
+ : QGraphicsObject(parent)
+ , m_text(text)
+ , m_rect(x, y, width, height)
+ , m_pen(brush.color().lighter(), 3.0)
+ , m_brush(brush)
+ {
+ setFlag(QGraphicsItem::ItemClipsToShape, true);
+ }
+
+ QRectF boundingRect() const
+ {
+ // here we only want the size of the children and not the size of the children of the children...
+ qreal halfpw = m_pen.widthF() / 2;
+ QRectF rect = m_rect;
+ if (halfpw > 0.0)
+ rect.adjust(-halfpw, -halfpw, halfpw, halfpw);
+
+ return rect;
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ {
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+ painter->setPen(m_pen);
+ painter->setBrush(m_brush);
+ painter->drawRect(m_rect);
+
+ painter->setPen(Qt::black);
+ QFont f;
+ f.setPixelSize(m_rect.height());
+ painter->setFont(f);
+ painter->drawText(m_rect, Qt::AlignCenter, m_text);
+ }
+
+ QString m_text;
+ QRectF m_rect;
+ QPen m_pen;
+ QBrush m_brush;
+};
+
+class ViewObject : public QGraphicsObject
+{
+ Q_OBJECT
+public:
+ ViewObject(QGraphicsObject *parent)
+ : QGraphicsObject(parent)
+ { }
+
+ QRectF boundingRect() const
+ {
+ QRectF rect;
+ foreach (QGraphicsItem *item, childItems())
+ rect |= item->boundingRect().translated(item->pos());
+ return rect;
+ }
+
+ void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
+ { }
+};
+
+class ListObject : public QGraphicsObject
+{
+ Q_OBJECT
+
+public:
+ ListObject(const QSizeF &size, bool useTouch)
+ {
+ m_size = size;
+ setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
+ // grab gesture via Touch or Mouse events
+ QScroller::grabGesture(this, useTouch ? QScroller::TouchGesture : QScroller::LeftMouseButtonGesture);
+
+ // this needs to be QGraphicsOBJECT - otherwise gesture recognition
+ // will not work for the parent of the viewport (in this case the
+ // list)
+ m_viewport = new ViewObject(this);
+
+ }
+
+ QGraphicsObject *viewport() const
+ {
+ return m_viewport;
+ }
+
+ bool event(QEvent *e)
+ {
+ switch (e->type()) {
+// ![2]
+ case QEvent::ScrollPrepare: {
+ QScrollPrepareEvent *se = static_cast<QScrollPrepareEvent *>(e);
+ se->setViewportSize(m_size);
+ QRectF br = m_viewport->boundingRect();
+ se->setContentPosRange(QRectF(0, 0,
+ qMax(qreal(0), br.width() - m_size.width()),
+ qMax(qreal(0), br.height() - m_size.height())));
+ se->setContentPos(-m_viewport->pos());
+ se->accept();
+ return true;
+ }
+// ![1]
+// ![2]
+ case QEvent::Scroll: {
+ QScrollEvent *se = static_cast<QScrollEvent *>(e);
+ m_viewport->setPos(-se->contentPos() - se->overshootDistance());
+ return true;
+ }
+// ![2]
+ default:
+ break;
+ }
+ return QGraphicsObject::event(e);
+ }
+
+ bool sceneEvent(QEvent *e)
+ {
+ switch (e->type()) {
+ case QEvent::TouchBegin: {
+ // We need to return true for the TouchBegin here in the
+ // top-most graphics object - otherwise gestures in our parent
+ // objects will NOT work at all (the accept() flag is already
+ // set due to our setAcceptTouchEvents(true) call in the c'tor
+ return true;
+
+ }
+ case QEvent::GraphicsSceneMousePress: {
+ // We need to return true for the MousePress here in the
+ // top-most graphics object - otherwise gestures in our parent
+ // objects will NOT work at all (the accept() flag is already
+ // set to true by Qt)
+ return true;
+
+ }
+ default:
+ break;
+ }
+ return QGraphicsObject::sceneEvent(e);
+ }
+
+ QRectF boundingRect() const
+ {
+ return QRectF(0, 0, m_size.width() + 3, m_size.height());
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ {
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+ painter->setPen(QPen(QColor(100, 100, 100), 3.0));
+ painter->drawRect(QRect(1.5, 1.5, m_size.width() - 3, m_size.height() - 3));
+ }
+
+ QSizeF m_size;
+ ViewObject *m_viewport;
+};
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(bool useTouch)
+ {
+ m_scene = new QGraphicsScene();
+
+ // -- make the main list
+ ListObject *mainList = new ListObject(QSizeF(780, 400), useTouch);
+ mainList->setObjectName(QLatin1String("MainList"));
+ m_scene->addItem(mainList);
+// ![3]
+ for (int i=0; i<NUM_LISTS; i++) {
+ ListObject *childList = new ListObject(QSizeF(mainList->m_size.width()/3, mainList->m_size.height()), useTouch);
+ childList->setObjectName(QString("ChildList %1").arg(i));
+ fillList(childList);
+ childList->setParentItem(mainList->viewport());
+ childList->setPos(i*mainList->m_size.width()/3, 0);
+ }
+ mainList->viewport()->setPos(0, 0);
+
+
+ /*
+ list1->setTransformOriginPoint(200, 200);
+ list1->setRotation(135);
+ list1->setPos(20 + 200 * .41, 20 + 200 * .41);
+ */
+// ![3]
+
+ m_view = new QGraphicsView(m_scene);
+ setCentralWidget(m_view);
+ setWindowTitle(tr("Gesture example"));
+ m_scene->setSceneRect(0, 0, m_view->viewport()->width(), m_view->viewport()->height());
+ }
+
+ /**
+ * Fills the list object \a list with RectObjects.
+ */
+ void fillList(ListObject *list)
+ {
+ qreal h = list->m_size.height() / 10;
+ for (int i=0; i<NUM_ITEMS; i++) {
+ QColor color = QColor(255*i/NUM_ITEMS, 255*(NUM_ITEMS-i)/NUM_ITEMS, 127*(i%2)+64*(i/2%2));
+ QString text = QLatin1String("Item #") + QString::number(i);
+ QGraphicsItem *rect = new RectObject(text, 0, 0, list->m_size.width() - 6, h - 3, QBrush(color), list->viewport());
+ rect->setPos(3, h*i+3);
+ }
+ list->viewport()->setPos(0, 0);
+ }
+
+
+protected:
+ void resizeEvent(QResizeEvent *e)
+ {
+ // resize the scene according to our own size to prevent scrolling
+ m_scene->setSceneRect(0, 0, m_view->viewport()->width(), m_view->viewport()->height());
+ QMainWindow::resizeEvent(e);
+ }
+
+ QGraphicsScene *m_scene;
+ QGraphicsView *m_view;
+};
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ bool touch = (a.arguments().contains(QLatin1String("--touch")));
+ MainWindow mw(touch);
+ mw.show();
+#ifdef Q_OS_MAC
+ mw.raise();
+#endif
+ return a.exec();
+}
+
+#include "main.moc"
diff --git a/examples/widgets/scroller/scroller.pro b/examples/widgets/scroller/scroller.pro
new file mode 100644
index 0000000000..bac3f26554
--- /dev/null
+++ b/examples/widgets/scroller/scroller.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += graphicsview
diff --git a/examples/widgets/statemachine/README b/examples/widgets/statemachine/README
new file mode 100644
index 0000000000..a0ac35a89b
--- /dev/null
+++ b/examples/widgets/statemachine/README
@@ -0,0 +1,6 @@
+Qt is provided with a powerful hierchical finite state machine through
+the Qt State Machine classes.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/statemachine/eventtransitions/eventtransitions.desktop b/examples/widgets/statemachine/eventtransitions/eventtransitions.desktop
new file mode 100644
index 0000000000..c1bceb2240
--- /dev/null
+++ b/examples/widgets/statemachine/eventtransitions/eventtransitions.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Event Transitions
+Exec=/opt/usr/bin/eventtransitions
+Icon=eventtransitions
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/statemachine/eventtransitions/eventtransitions.pro b/examples/widgets/statemachine/eventtransitions/eventtransitions.pro
new file mode 100644
index 0000000000..8a9d84e646
--- /dev/null
+++ b/examples/widgets/statemachine/eventtransitions/eventtransitions.pro
@@ -0,0 +1,11 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/eventtransitions
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS eventtransitions.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/eventtransitions
+INSTALLS += target sources
+QT += widgets
+
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/statemachine/eventtransitions/main.cpp b/examples/widgets/statemachine/eventtransitions/main.cpp
new file mode 100644
index 0000000000..b3af3b825f
--- /dev/null
+++ b/examples/widgets/statemachine/eventtransitions/main.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+//! [0]
+class Window : public QWidget
+{
+public:
+ Window(QWidget *parent = 0)
+ : QWidget(parent)
+ {
+ QPushButton *button = new QPushButton(this);
+ button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(button);
+ layout->setContentsMargins(80, 80, 80, 80);
+ setLayout(layout);
+//! [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/widgets/statemachine/factorial/factorial.desktop b/examples/widgets/statemachine/factorial/factorial.desktop
new file mode 100644
index 0000000000..41b27227f9
--- /dev/null
+++ b/examples/widgets/statemachine/factorial/factorial.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Factorial States
+Exec=/opt/usr/bin/factorial
+Icon=factorial
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/statemachine/factorial/factorial.pro b/examples/widgets/statemachine/factorial/factorial.pro
new file mode 100644
index 0000000000..fe3dd23e87
--- /dev/null
+++ b/examples/widgets/statemachine/factorial/factorial.pro
@@ -0,0 +1,13 @@
+QT = core
+win32: CONFIG += console
+mac:CONFIG -= app_bundle
+
+SOURCES += main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/factorial
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS factorial.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/factorial
+INSTALLS += target sources
+
+
diff --git a/examples/widgets/statemachine/factorial/main.cpp b/examples/widgets/statemachine/factorial/main.cpp
new file mode 100644
index 0000000000..df50cab02f
--- /dev/null
+++ b/examples/widgets/statemachine/factorial/main.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <stdio.h>
+
+//! [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;
+ QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(e);
+ return se->arguments().at(0).toInt() > 1;
+ }
+
+ virtual void onTransition(QEvent *e)
+ {
+ QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(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;
+ QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(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);
+ compute->assignProperty(&factorial, "fac", 1);
+ compute->assignProperty(&factorial, "x", 6);
+ compute->addTransition(new FactorialLoopTransition(&factorial));
+//! [4]
+
+//! [5]
+ QFinalState *done = new QFinalState(&machine);
+ 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/widgets/statemachine/pingpong/main.cpp b/examples/widgets/statemachine/pingpong/main.cpp
new file mode 100644
index 0000000000..636e7193b2
--- /dev/null
+++ b/examples/widgets/statemachine/pingpong/main.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <stdio.h>
+
+//! [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()->postDelayedEvent(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()->postDelayedEvent(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/widgets/statemachine/pingpong/pingpong.desktop b/examples/widgets/statemachine/pingpong/pingpong.desktop
new file mode 100644
index 0000000000..79646a2cc8
--- /dev/null
+++ b/examples/widgets/statemachine/pingpong/pingpong.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Ping Pong States
+Exec=/opt/usr/bin/pingpong
+Icon=pingpong
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/statemachine/pingpong/pingpong.pro b/examples/widgets/statemachine/pingpong/pingpong.pro
new file mode 100644
index 0000000000..1cfddaf282
--- /dev/null
+++ b/examples/widgets/statemachine/pingpong/pingpong.pro
@@ -0,0 +1,13 @@
+QT = core
+win32: CONFIG += console
+mac:CONFIG -= app_bundle
+
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/pingpong
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS pingpong.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/pingpong
+INSTALLS += target sources
+
+
diff --git a/examples/widgets/statemachine/rogue/main.cpp b/examples/widgets/statemachine/rogue/main.cpp
new file mode 100644
index 0000000000..c909c17cde
--- /dev/null
+++ b/examples/widgets/statemachine/rogue/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "window.h"
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ Window window;
+ window.show();
+
+ return app.exec();
+}
+
diff --git a/examples/widgets/statemachine/rogue/movementtransition.h b/examples/widgets/statemachine/rogue/movementtransition.h
new file mode 100644
index 0000000000..6f27da93b8
--- /dev/null
+++ b/examples/widgets/statemachine/rogue/movementtransition.h
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MOVEMENTTRANSITION_H
+#define MOVEMENTTRANSITION_H
+
+#include <QtWidgets>
+
+#include "window.h"
+
+//![0]
+class MovementTransition : public QEventTransition
+{
+ Q_OBJECT
+
+public:
+ MovementTransition(Window *window) :
+ QEventTransition(window, QEvent::KeyPress) {
+ this->window = window;
+ }
+//![0]
+
+//![1]
+protected:
+ bool eventTest(QEvent *event) {
+ if (event->type() == QEvent::StateMachineWrapped &&
+ static_cast<QStateMachine::WrappedEvent *>(event)->event()->type() == QEvent::KeyPress) {
+ QEvent *wrappedEvent = static_cast<QStateMachine::WrappedEvent *>(event)->event();
+
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(wrappedEvent);
+ int key = keyEvent->key();
+
+ return key == Qt::Key_2 || key == Qt::Key_8 || key == Qt::Key_6 ||
+ key == Qt::Key_4 || key == Qt::Key_Down || key == Qt::Key_Up ||
+ key == Qt::Key_Right || key == Qt::Key_Left;
+ }
+ return false;
+ }
+//![1]
+
+//![2]
+ void onTransition(QEvent *event) {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(
+ static_cast<QStateMachine::WrappedEvent *>(event)->event());
+
+ int key = keyEvent->key();
+ switch (key) {
+ case Qt::Key_Left:
+ case Qt::Key_4:
+ window->movePlayer(Window::Left);
+ break;
+ case Qt::Key_Up:
+ case Qt::Key_8:
+ window->movePlayer(Window::Up);
+ break;
+ case Qt::Key_Right:
+ case Qt::Key_6:
+ window->movePlayer(Window::Right);
+ break;
+ case Qt::Key_Down:
+ case Qt::Key_2:
+ window->movePlayer(Window::Down);
+ break;
+ default:
+ ;
+ }
+ }
+//![2]
+
+private:
+ Window *window;
+};
+
+#endif
+
diff --git a/examples/widgets/statemachine/rogue/rogue.desktop b/examples/widgets/statemachine/rogue/rogue.desktop
new file mode 100644
index 0000000000..71ca4b6511
--- /dev/null
+++ b/examples/widgets/statemachine/rogue/rogue.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Rogue
+Exec=/opt/usr/bin/rogue
+Icon=rogue
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/statemachine/rogue/rogue.pro b/examples/widgets/statemachine/rogue/rogue.pro
new file mode 100644
index 0000000000..4ed132db06
--- /dev/null
+++ b/examples/widgets/statemachine/rogue/rogue.pro
@@ -0,0 +1,13 @@
+HEADERS = window.h \
+ movementtransition.h
+SOURCES = main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/rogue
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/rogue
+INSTALLS += target sources
+
+QT += widgets
+
diff --git a/examples/widgets/statemachine/rogue/window.cpp b/examples/widgets/statemachine/rogue/window.cpp
new file mode 100644
index 0000000000..0c57b2c2d7
--- /dev/null
+++ b/examples/widgets/statemachine/rogue/window.cpp
@@ -0,0 +1,251 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "window.h"
+#include "movementtransition.h"
+
+//![0]
+Window::Window()
+{
+ pX = 5;
+ pY = 5;
+//![0]
+
+ QFontDatabase database;
+ QFont font;
+ if (database.families().contains("Monospace")) {
+ font = QFont("Monospace");
+ }
+ else {
+ foreach (QString family, database.families()) {
+ if (database.isFixedPitch(family)) {
+ font = QFont(family);
+ break;
+ }
+ }
+ }
+ font.setPointSize(12);
+ setFont(font);
+
+//![1]
+ setupMap();
+ buildMachine();
+}
+//![1]
+
+void Window::setStatus(const QString &status)
+{
+ myStatus = status;
+ repaint();
+}
+
+QString Window::status() const
+{
+ return myStatus;
+}
+
+void Window::paintEvent(QPaintEvent * /* event */)
+{
+ QFontMetrics metrics(font());
+ QPainter painter(this);
+ int fontHeight = metrics.height();
+ int fontWidth = metrics.width('X');
+ int yPos = fontHeight;
+ int xPos;
+
+ painter.fillRect(rect(), Qt::black);
+ painter.setPen(Qt::white);
+
+ painter.drawText(QPoint(0, yPos), status());
+
+ for (int y = 0; y < HEIGHT; ++y) {
+ yPos += fontHeight;
+ xPos = 0;
+
+ for (int x = 0; x < WIDTH; ++x) {
+ if (y == pY && x == pX) {
+ xPos += fontWidth;
+ continue;
+ }
+
+ painter.setPen(Qt::white);
+
+ double x1 = static_cast<double>(pX);
+ double y1 = static_cast<double>(pY);
+ double x2 = static_cast<double>(x);
+ double y2 = static_cast<double>(y);
+
+ if (x2<x1) {
+ x2+=0.5;
+ } else if (x2>x1) {
+ x2-=0.5;
+ }
+
+ if (y2<y1) {
+ y2+=0.5;
+ } else if (y2>y1) {
+ y2-=0.5;
+ }
+
+ double dx = x2 - x1;
+ double dy = y2 - y1;
+
+ double length = qSqrt(dx*dx+dy*dy);
+
+ dx /= length;
+ dy /= length;
+
+ double xi = x1;
+ double yi = y1;
+
+ while (length > 0) {
+ int cx = static_cast<int>(xi+0.5);
+ int cy = static_cast<int>(yi+0.5);
+
+ if (x2 == cx && y2 == cy)
+ break;
+
+ if (!(x1==cx && y1==cy)
+ && (map[cx][cy] == '#' || (length-10) > 0)) {
+ painter.setPen(QColor(60,60,60));
+ break;
+ }
+
+ xi += dx;
+ yi += dy;
+ --length;
+ }
+
+ painter.drawText(QPoint(xPos, yPos), map[x][y]);
+ xPos += fontWidth;
+ }
+ }
+ painter.setPen(Qt::white);
+ painter.drawText(QPoint(pX * fontWidth, (pY + 2) * fontHeight), QChar('@'));
+}
+
+QSize Window::sizeHint() const
+{
+ QFontMetrics metrics(font());
+
+ return QSize(metrics.width('X') * WIDTH, metrics.height() * (HEIGHT + 1));
+}
+
+//![2]
+void Window::buildMachine()
+{
+ machine = new QStateMachine;
+
+ QState *inputState = new QState(machine);
+ inputState->assignProperty(this, "status", "Move the rogue with 2, 4, 6, and 8");
+
+ MovementTransition *transition = new MovementTransition(this);
+ inputState->addTransition(transition);
+//![2]
+
+//![3]
+ QState *quitState = new QState(machine);
+ quitState->assignProperty(this, "status", "Really quit(y/n)?");
+
+ QKeyEventTransition *yesTransition = new
+ QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Y);
+ yesTransition->setTargetState(new QFinalState(machine));
+ quitState->addTransition(yesTransition);
+
+ QKeyEventTransition *noTransition =
+ new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_N);
+ noTransition->setTargetState(inputState);
+ quitState->addTransition(noTransition);
+//![3]
+
+//![4]
+ QKeyEventTransition *quitTransition =
+ new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Q);
+ quitTransition->setTargetState(quitState);
+ inputState->addTransition(quitTransition);
+//![4]
+
+//![5]
+ machine->setInitialState(inputState);
+
+ connect(machine, SIGNAL(finished()), qApp, SLOT(quit()));
+
+ machine->start();
+}
+//![5]
+
+void Window::movePlayer(Direction direction)
+{
+ switch (direction) {
+ case Left:
+ if (map[pX - 1][pY] != '#')
+ --pX;
+ break;
+ case Right:
+ if (map[pX + 1][pY] != '#')
+ ++pX;
+ break;
+ case Up:
+ if (map[pX][pY - 1] != '#')
+ --pY;
+ break;
+ case Down:
+ if (map[pX][pY + 1] != '#')
+ ++pY;
+ break;
+ }
+ repaint();
+}
+
+void Window::setupMap()
+{
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ for (int x = 0; x < WIDTH; ++x)
+ for (int y = 0; y < HEIGHT; ++y) {
+ if (x == 0 || x == WIDTH - 1 || y == 0 || y == HEIGHT - 1 || qrand() % 40 == 0)
+ map[x][y] = '#';
+ else
+ map[x][y] = '.';
+ }
+}
+
diff --git a/examples/widgets/statemachine/rogue/window.h b/examples/widgets/statemachine/rogue/window.h
new file mode 100644
index 0000000000..8ef3591e96
--- /dev/null
+++ b/examples/widgets/statemachine/rogue/window.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QState;
+class QStateMachine;
+class QTransition;
+QT_END_NAMESPACE
+
+#define WIDTH 35
+#define HEIGHT 20
+
+//![0]
+class Window : public QWidget
+{
+ Q_OBJECT
+ Q_PROPERTY(QString status READ status WRITE setStatus)
+
+public:
+ enum Direction { Up, Down, Left, Right };
+
+ Window();
+
+ void movePlayer(Direction direction);
+ void setStatus(const QString &status);
+ QString status() const;
+
+ QSize sizeHint() const;
+
+protected:
+ void paintEvent(QPaintEvent *event);
+//![0]
+
+//![1]
+private:
+ void buildMachine();
+ void setupMap();
+
+ QChar map[WIDTH][HEIGHT];
+ int pX, pY;
+
+ QStateMachine *machine;
+ QString myStatus;
+};
+//![1]
+
+#endif
+
diff --git a/examples/widgets/statemachine/statemachine.pro b/examples/widgets/statemachine/statemachine.pro
new file mode 100644
index 0000000000..7d510b29be
--- /dev/null
+++ b/examples/widgets/statemachine/statemachine.pro
@@ -0,0 +1,18 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ factorial \
+ pingpong
+
+!contains(QT_CONFIG, no-widgets) {
+ SUBDIRS += \
+ eventtransitions \
+ rogue \
+ trafficlight \
+ twowaybutton
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS statemachine.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine
+INSTALLS += target sources
diff --git a/examples/widgets/statemachine/trafficlight/main.cpp b/examples/widgets/statemachine/trafficlight/main.cpp
new file mode 100644
index 0000000000..624e3f1559
--- /dev/null
+++ b/examples/widgets/statemachine/trafficlight/main.cpp
@@ -0,0 +1,184 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+//! [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/widgets/statemachine/trafficlight/trafficlight.desktop b/examples/widgets/statemachine/trafficlight/trafficlight.desktop
new file mode 100644
index 0000000000..8a5cc1673b
--- /dev/null
+++ b/examples/widgets/statemachine/trafficlight/trafficlight.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Traffic Light
+Exec=/opt/usr/bin/trafficlight
+Icon=trafficlight
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/statemachine/trafficlight/trafficlight.pro b/examples/widgets/statemachine/trafficlight/trafficlight.pro
new file mode 100644
index 0000000000..5bc0cdaef5
--- /dev/null
+++ b/examples/widgets/statemachine/trafficlight/trafficlight.pro
@@ -0,0 +1,10 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/trafficlight
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS trafficlight.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/trafficlight
+INSTALLS += target sources
+QT += widgets
+
+
diff --git a/examples/widgets/statemachine/twowaybutton/main.cpp b/examples/widgets/statemachine/twowaybutton/main.cpp
new file mode 100644
index 0000000000..05f82538ff
--- /dev/null
+++ b/examples/widgets/statemachine/twowaybutton/main.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+//! [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/widgets/statemachine/twowaybutton/twowaybutton.desktop b/examples/widgets/statemachine/twowaybutton/twowaybutton.desktop
new file mode 100644
index 0000000000..9dd0918937
--- /dev/null
+++ b/examples/widgets/statemachine/twowaybutton/twowaybutton.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Two-way Button
+Exec=/opt/usr/bin/twowaybutton
+Icon=twowaybutton
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/statemachine/twowaybutton/twowaybutton.pro b/examples/widgets/statemachine/twowaybutton/twowaybutton.pro
new file mode 100644
index 0000000000..ffbd982845
--- /dev/null
+++ b/examples/widgets/statemachine/twowaybutton/twowaybutton.pro
@@ -0,0 +1,10 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/twowaybutton
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS twowaybutton.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/statemachine/twowaybutton
+INSTALLS += target sources
+QT += widgets
+
+
diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro
index 8ec33b42ea..8c68b3721e 100644
--- a/examples/widgets/widgets.pro
+++ b/examples/widgets/widgets.pro
@@ -1,35 +1,25 @@
TEMPLATE = subdirs
-SUBDIRS = analogclock \
- applicationicon \
- calculator \
- calendarwidget \
- charactermap \
- codeeditor \
- digitalclock \
- elidedlabel \
- groupbox \
- icons \
- imageviewer \
- lineedits \
- movie \
- mousebuttons \
- orientation \
- scribble \
- shapedclock \
- sliders \
- spinboxes \
- stylesheet \
- tablet \
- tetrix \
- tooltips \
- validators \
- wiggly \
- windowflags
+CONFIG += no_docs_target
-contains(styles, motif): SUBDIRS += styles
+SUBDIRS = \
+ animation \
+ desktop \
+ dialogs \
+ draganddrop \
+ effects \
+ graphicsview \
+ itemviews \
+ layouts \
+ mainwindows \
+ painting \
+ richtext \
+ scroller \
+ statemachine \
+ widgets
+
+contains(DEFINES, QT_NO_CURSOR): SUBDIRS -= mainwindows
# install
-target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets
-sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS widgets.pro README
-sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets
-INSTALLS += target sources
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]
+INSTALLS += sources \ No newline at end of file
diff --git a/examples/widgets/README b/examples/widgets/widgets/README
index e862f07b71..e862f07b71 100644
--- a/examples/widgets/README
+++ b/examples/widgets/widgets/README
diff --git a/examples/widgets/analogclock/analogclock.cpp b/examples/widgets/widgets/analogclock/analogclock.cpp
index 029ca1031a..029ca1031a 100644
--- a/examples/widgets/analogclock/analogclock.cpp
+++ b/examples/widgets/widgets/analogclock/analogclock.cpp
diff --git a/examples/widgets/analogclock/analogclock.desktop b/examples/widgets/widgets/analogclock/analogclock.desktop
index b177a62d35..b177a62d35 100644
--- a/examples/widgets/analogclock/analogclock.desktop
+++ b/examples/widgets/widgets/analogclock/analogclock.desktop
diff --git a/examples/widgets/analogclock/analogclock.h b/examples/widgets/widgets/analogclock/analogclock.h
index f95a095712..f95a095712 100644
--- a/examples/widgets/analogclock/analogclock.h
+++ b/examples/widgets/widgets/analogclock/analogclock.h
diff --git a/examples/widgets/analogclock/analogclock.pro b/examples/widgets/widgets/analogclock/analogclock.pro
index a2641150e2..a2641150e2 100644
--- a/examples/widgets/analogclock/analogclock.pro
+++ b/examples/widgets/widgets/analogclock/analogclock.pro
diff --git a/examples/widgets/analogclock/main.cpp b/examples/widgets/widgets/analogclock/main.cpp
index 0efedc7acf..0efedc7acf 100644
--- a/examples/widgets/analogclock/main.cpp
+++ b/examples/widgets/widgets/analogclock/main.cpp
diff --git a/examples/widgets/applicationicon/applicationicon.desktop b/examples/widgets/widgets/applicationicon/applicationicon.desktop
index 9645802195..9645802195 100644
--- a/examples/widgets/applicationicon/applicationicon.desktop
+++ b/examples/widgets/widgets/applicationicon/applicationicon.desktop
diff --git a/examples/widgets/applicationicon/applicationicon.png b/examples/widgets/widgets/applicationicon/applicationicon.png
index 83a186ee56..83a186ee56 100644
--- a/examples/widgets/applicationicon/applicationicon.png
+++ b/examples/widgets/widgets/applicationicon/applicationicon.png
Binary files differ
diff --git a/examples/widgets/applicationicon/applicationicon.pro b/examples/widgets/widgets/applicationicon/applicationicon.pro
index 0a3ba8bbdd..0a3ba8bbdd 100644
--- a/examples/widgets/applicationicon/applicationicon.pro
+++ b/examples/widgets/widgets/applicationicon/applicationicon.pro
diff --git a/examples/widgets/applicationicon/applicationicon.svg b/examples/widgets/widgets/applicationicon/applicationicon.svg
index aa2835b08f..aa2835b08f 100644
--- a/examples/widgets/applicationicon/applicationicon.svg
+++ b/examples/widgets/widgets/applicationicon/applicationicon.svg
diff --git a/examples/widgets/applicationicon/main.cpp b/examples/widgets/widgets/applicationicon/main.cpp
index 1314de1cbf..1314de1cbf 100644
--- a/examples/widgets/applicationicon/main.cpp
+++ b/examples/widgets/widgets/applicationicon/main.cpp
diff --git a/examples/widgets/calculator/button.cpp b/examples/widgets/widgets/calculator/button.cpp
index 14c3ebe20d..14c3ebe20d 100644
--- a/examples/widgets/calculator/button.cpp
+++ b/examples/widgets/widgets/calculator/button.cpp
diff --git a/examples/widgets/calculator/button.h b/examples/widgets/widgets/calculator/button.h
index 50874ea574..50874ea574 100644
--- a/examples/widgets/calculator/button.h
+++ b/examples/widgets/widgets/calculator/button.h
diff --git a/examples/widgets/calculator/calculator.cpp b/examples/widgets/widgets/calculator/calculator.cpp
index 29503befc5..29503befc5 100644
--- a/examples/widgets/calculator/calculator.cpp
+++ b/examples/widgets/widgets/calculator/calculator.cpp
diff --git a/examples/widgets/calculator/calculator.desktop b/examples/widgets/widgets/calculator/calculator.desktop
index d0ae81d5a9..d0ae81d5a9 100644
--- a/examples/widgets/calculator/calculator.desktop
+++ b/examples/widgets/widgets/calculator/calculator.desktop
diff --git a/examples/widgets/calculator/calculator.h b/examples/widgets/widgets/calculator/calculator.h
index 6727d9b733..6727d9b733 100644
--- a/examples/widgets/calculator/calculator.h
+++ b/examples/widgets/widgets/calculator/calculator.h
diff --git a/examples/widgets/calculator/calculator.pro b/examples/widgets/widgets/calculator/calculator.pro
index d237871e0d..d237871e0d 100644
--- a/examples/widgets/calculator/calculator.pro
+++ b/examples/widgets/widgets/calculator/calculator.pro
diff --git a/examples/widgets/calculator/main.cpp b/examples/widgets/widgets/calculator/main.cpp
index e4f591aabe..e4f591aabe 100644
--- a/examples/widgets/calculator/main.cpp
+++ b/examples/widgets/widgets/calculator/main.cpp
diff --git a/examples/widgets/calculator/releasenotes.txt b/examples/widgets/widgets/calculator/releasenotes.txt
index 053f651dba..053f651dba 100644
--- a/examples/widgets/calculator/releasenotes.txt
+++ b/examples/widgets/widgets/calculator/releasenotes.txt
diff --git a/examples/widgets/calendarwidget/calendarwidget.desktop b/examples/widgets/widgets/calendarwidget/calendarwidget.desktop
index 645dc412e3..645dc412e3 100644
--- a/examples/widgets/calendarwidget/calendarwidget.desktop
+++ b/examples/widgets/widgets/calendarwidget/calendarwidget.desktop
diff --git a/examples/widgets/calendarwidget/calendarwidget.pro b/examples/widgets/widgets/calendarwidget/calendarwidget.pro
index 3c75fb6a33..3c75fb6a33 100644
--- a/examples/widgets/calendarwidget/calendarwidget.pro
+++ b/examples/widgets/widgets/calendarwidget/calendarwidget.pro
diff --git a/examples/widgets/calendarwidget/main.cpp b/examples/widgets/widgets/calendarwidget/main.cpp
index 8c4e2573d5..8c4e2573d5 100644
--- a/examples/widgets/calendarwidget/main.cpp
+++ b/examples/widgets/widgets/calendarwidget/main.cpp
diff --git a/examples/widgets/calendarwidget/window.cpp b/examples/widgets/widgets/calendarwidget/window.cpp
index 8ba044bf11..8ba044bf11 100644
--- a/examples/widgets/calendarwidget/window.cpp
+++ b/examples/widgets/widgets/calendarwidget/window.cpp
diff --git a/examples/widgets/calendarwidget/window.h b/examples/widgets/widgets/calendarwidget/window.h
index 68587400d3..68587400d3 100644
--- a/examples/widgets/calendarwidget/window.h
+++ b/examples/widgets/widgets/calendarwidget/window.h
diff --git a/examples/widgets/charactermap/charactermap.desktop b/examples/widgets/widgets/charactermap/charactermap.desktop
index 7f1919470a..7f1919470a 100644
--- a/examples/widgets/charactermap/charactermap.desktop
+++ b/examples/widgets/widgets/charactermap/charactermap.desktop
diff --git a/examples/widgets/charactermap/charactermap.pro b/examples/widgets/widgets/charactermap/charactermap.pro
index 0a9d6e7b5c..0a9d6e7b5c 100644
--- a/examples/widgets/charactermap/charactermap.pro
+++ b/examples/widgets/widgets/charactermap/charactermap.pro
diff --git a/examples/widgets/charactermap/characterwidget.cpp b/examples/widgets/widgets/charactermap/characterwidget.cpp
index 7ce5d61cf7..7ce5d61cf7 100644
--- a/examples/widgets/charactermap/characterwidget.cpp
+++ b/examples/widgets/widgets/charactermap/characterwidget.cpp
diff --git a/examples/widgets/charactermap/characterwidget.h b/examples/widgets/widgets/charactermap/characterwidget.h
index d523c13011..d523c13011 100644
--- a/examples/widgets/charactermap/characterwidget.h
+++ b/examples/widgets/widgets/charactermap/characterwidget.h
diff --git a/examples/widgets/widgets/charactermap/main.cpp b/examples/widgets/widgets/charactermap/main.cpp
new file mode 100644
index 0000000000..09a923477c
--- /dev/null
+++ b/examples/widgets/widgets/charactermap/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/charactermap/mainwindow.cpp b/examples/widgets/widgets/charactermap/mainwindow.cpp
index fbe0df616c..fbe0df616c 100644
--- a/examples/widgets/charactermap/mainwindow.cpp
+++ b/examples/widgets/widgets/charactermap/mainwindow.cpp
diff --git a/examples/widgets/charactermap/mainwindow.h b/examples/widgets/widgets/charactermap/mainwindow.h
index 37109827ab..37109827ab 100644
--- a/examples/widgets/charactermap/mainwindow.h
+++ b/examples/widgets/widgets/charactermap/mainwindow.h
diff --git a/examples/widgets/codeeditor/codeeditor.cpp b/examples/widgets/widgets/codeeditor/codeeditor.cpp
index 2a2750c035..2a2750c035 100644
--- a/examples/widgets/codeeditor/codeeditor.cpp
+++ b/examples/widgets/widgets/codeeditor/codeeditor.cpp
diff --git a/examples/widgets/codeeditor/codeeditor.desktop b/examples/widgets/widgets/codeeditor/codeeditor.desktop
index 9347479e11..9347479e11 100644
--- a/examples/widgets/codeeditor/codeeditor.desktop
+++ b/examples/widgets/widgets/codeeditor/codeeditor.desktop
diff --git a/examples/widgets/codeeditor/codeeditor.h b/examples/widgets/widgets/codeeditor/codeeditor.h
index 71de46ed61..71de46ed61 100644
--- a/examples/widgets/codeeditor/codeeditor.h
+++ b/examples/widgets/widgets/codeeditor/codeeditor.h
diff --git a/examples/widgets/codeeditor/codeeditor.pro b/examples/widgets/widgets/codeeditor/codeeditor.pro
index ec38770cc6..ec38770cc6 100644
--- a/examples/widgets/codeeditor/codeeditor.pro
+++ b/examples/widgets/widgets/codeeditor/codeeditor.pro
diff --git a/examples/widgets/codeeditor/main.cpp b/examples/widgets/widgets/codeeditor/main.cpp
index 8c60c26f06..8c60c26f06 100644
--- a/examples/widgets/codeeditor/main.cpp
+++ b/examples/widgets/widgets/codeeditor/main.cpp
diff --git a/examples/widgets/digitalclock/digitalclock.cpp b/examples/widgets/widgets/digitalclock/digitalclock.cpp
index 4f11286114..4f11286114 100644
--- a/examples/widgets/digitalclock/digitalclock.cpp
+++ b/examples/widgets/widgets/digitalclock/digitalclock.cpp
diff --git a/examples/widgets/digitalclock/digitalclock.desktop b/examples/widgets/widgets/digitalclock/digitalclock.desktop
index b13876878c..b13876878c 100644
--- a/examples/widgets/digitalclock/digitalclock.desktop
+++ b/examples/widgets/widgets/digitalclock/digitalclock.desktop
diff --git a/examples/widgets/digitalclock/digitalclock.h b/examples/widgets/widgets/digitalclock/digitalclock.h
index 791633f12d..791633f12d 100644
--- a/examples/widgets/digitalclock/digitalclock.h
+++ b/examples/widgets/widgets/digitalclock/digitalclock.h
diff --git a/examples/widgets/digitalclock/digitalclock.pro b/examples/widgets/widgets/digitalclock/digitalclock.pro
index c0ad11e146..c0ad11e146 100644
--- a/examples/widgets/digitalclock/digitalclock.pro
+++ b/examples/widgets/widgets/digitalclock/digitalclock.pro
diff --git a/examples/widgets/digitalclock/main.cpp b/examples/widgets/widgets/digitalclock/main.cpp
index d28c7d36f2..d28c7d36f2 100644
--- a/examples/widgets/digitalclock/main.cpp
+++ b/examples/widgets/widgets/digitalclock/main.cpp
diff --git a/examples/widgets/elidedlabel/elidedlabel.cpp b/examples/widgets/widgets/elidedlabel/elidedlabel.cpp
index 5f58bbcca8..5f58bbcca8 100644
--- a/examples/widgets/elidedlabel/elidedlabel.cpp
+++ b/examples/widgets/widgets/elidedlabel/elidedlabel.cpp
diff --git a/examples/widgets/elidedlabel/elidedlabel.desktop b/examples/widgets/widgets/elidedlabel/elidedlabel.desktop
index 5da3a6c15a..5da3a6c15a 100644
--- a/examples/widgets/elidedlabel/elidedlabel.desktop
+++ b/examples/widgets/widgets/elidedlabel/elidedlabel.desktop
diff --git a/examples/widgets/elidedlabel/elidedlabel.h b/examples/widgets/widgets/elidedlabel/elidedlabel.h
index 2c19589bc2..2c19589bc2 100644
--- a/examples/widgets/elidedlabel/elidedlabel.h
+++ b/examples/widgets/widgets/elidedlabel/elidedlabel.h
diff --git a/examples/widgets/elidedlabel/elidedlabel.pro b/examples/widgets/widgets/elidedlabel/elidedlabel.pro
index f3fbc23d96..f3fbc23d96 100644
--- a/examples/widgets/elidedlabel/elidedlabel.pro
+++ b/examples/widgets/widgets/elidedlabel/elidedlabel.pro
diff --git a/examples/widgets/elidedlabel/main.cpp b/examples/widgets/widgets/elidedlabel/main.cpp
index a79284e729..a79284e729 100644
--- a/examples/widgets/elidedlabel/main.cpp
+++ b/examples/widgets/widgets/elidedlabel/main.cpp
diff --git a/examples/widgets/elidedlabel/testwidget.cpp b/examples/widgets/widgets/elidedlabel/testwidget.cpp
index a60ed655a5..a60ed655a5 100644
--- a/examples/widgets/elidedlabel/testwidget.cpp
+++ b/examples/widgets/widgets/elidedlabel/testwidget.cpp
diff --git a/examples/widgets/elidedlabel/testwidget.h b/examples/widgets/widgets/elidedlabel/testwidget.h
index aff90e6ae2..aff90e6ae2 100644
--- a/examples/widgets/elidedlabel/testwidget.h
+++ b/examples/widgets/widgets/elidedlabel/testwidget.h
diff --git a/examples/widgets/groupbox/groupbox.desktop b/examples/widgets/widgets/groupbox/groupbox.desktop
index 8239bbf5d0..8239bbf5d0 100644
--- a/examples/widgets/groupbox/groupbox.desktop
+++ b/examples/widgets/widgets/groupbox/groupbox.desktop
diff --git a/examples/widgets/groupbox/groupbox.pro b/examples/widgets/widgets/groupbox/groupbox.pro
index 07c0ed8818..07c0ed8818 100644
--- a/examples/widgets/groupbox/groupbox.pro
+++ b/examples/widgets/widgets/groupbox/groupbox.pro
diff --git a/examples/widgets/widgets/groupbox/main.cpp b/examples/widgets/widgets/groupbox/main.cpp
new file mode 100644
index 0000000000..dcbf1c0449
--- /dev/null
+++ b/examples/widgets/widgets/groupbox/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/groupbox/window.cpp b/examples/widgets/widgets/groupbox/window.cpp
index 7436e2dfb6..7436e2dfb6 100644
--- a/examples/widgets/groupbox/window.cpp
+++ b/examples/widgets/widgets/groupbox/window.cpp
diff --git a/examples/widgets/groupbox/window.h b/examples/widgets/widgets/groupbox/window.h
index a88374b429..a88374b429 100644
--- a/examples/widgets/groupbox/window.h
+++ b/examples/widgets/widgets/groupbox/window.h
diff --git a/examples/widgets/icons/iconpreviewarea.cpp b/examples/widgets/widgets/icons/iconpreviewarea.cpp
index 53391c7f4f..53391c7f4f 100644
--- a/examples/widgets/icons/iconpreviewarea.cpp
+++ b/examples/widgets/widgets/icons/iconpreviewarea.cpp
diff --git a/examples/widgets/icons/iconpreviewarea.h b/examples/widgets/widgets/icons/iconpreviewarea.h
index 4c6bc92dbc..4c6bc92dbc 100644
--- a/examples/widgets/icons/iconpreviewarea.h
+++ b/examples/widgets/widgets/icons/iconpreviewarea.h
diff --git a/examples/widgets/icons/icons.desktop b/examples/widgets/widgets/icons/icons.desktop
index df90cc5e6f..df90cc5e6f 100644
--- a/examples/widgets/icons/icons.desktop
+++ b/examples/widgets/widgets/icons/icons.desktop
diff --git a/examples/widgets/icons/icons.pro b/examples/widgets/widgets/icons/icons.pro
index 8b0831117c..8b0831117c 100644
--- a/examples/widgets/icons/icons.pro
+++ b/examples/widgets/widgets/icons/icons.pro
diff --git a/examples/widgets/icons/iconsizespinbox.cpp b/examples/widgets/widgets/icons/iconsizespinbox.cpp
index bc3609ccb3..bc3609ccb3 100644
--- a/examples/widgets/icons/iconsizespinbox.cpp
+++ b/examples/widgets/widgets/icons/iconsizespinbox.cpp
diff --git a/examples/widgets/icons/iconsizespinbox.h b/examples/widgets/widgets/icons/iconsizespinbox.h
index c163c0f597..c163c0f597 100644
--- a/examples/widgets/icons/iconsizespinbox.h
+++ b/examples/widgets/widgets/icons/iconsizespinbox.h
diff --git a/examples/widgets/icons/imagedelegate.cpp b/examples/widgets/widgets/icons/imagedelegate.cpp
index b801fc2171..b801fc2171 100644
--- a/examples/widgets/icons/imagedelegate.cpp
+++ b/examples/widgets/widgets/icons/imagedelegate.cpp
diff --git a/examples/widgets/icons/imagedelegate.h b/examples/widgets/widgets/icons/imagedelegate.h
index a07dc4b9ad..a07dc4b9ad 100644
--- a/examples/widgets/icons/imagedelegate.h
+++ b/examples/widgets/widgets/icons/imagedelegate.h
diff --git a/examples/widgets/icons/images/designer.png b/examples/widgets/widgets/icons/images/designer.png
index 0988fcee3f..0988fcee3f 100644
--- a/examples/widgets/icons/images/designer.png
+++ b/examples/widgets/widgets/icons/images/designer.png
Binary files differ
diff --git a/examples/widgets/icons/images/find_disabled.png b/examples/widgets/widgets/icons/images/find_disabled.png
index e85e33fe05..e85e33fe05 100644
--- a/examples/widgets/icons/images/find_disabled.png
+++ b/examples/widgets/widgets/icons/images/find_disabled.png
Binary files differ
diff --git a/examples/widgets/icons/images/find_normal.png b/examples/widgets/widgets/icons/images/find_normal.png
index 728c27f905..728c27f905 100644
--- a/examples/widgets/icons/images/find_normal.png
+++ b/examples/widgets/widgets/icons/images/find_normal.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_off_128x128.png b/examples/widgets/widgets/icons/images/monkey_off_128x128.png
index f878267287..f878267287 100644
--- a/examples/widgets/icons/images/monkey_off_128x128.png
+++ b/examples/widgets/widgets/icons/images/monkey_off_128x128.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_off_16x16.png b/examples/widgets/widgets/icons/images/monkey_off_16x16.png
index 0ac57d7d4f..0ac57d7d4f 100644
--- a/examples/widgets/icons/images/monkey_off_16x16.png
+++ b/examples/widgets/widgets/icons/images/monkey_off_16x16.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_off_32x32.png b/examples/widgets/widgets/icons/images/monkey_off_32x32.png
index 1f7fab694c..1f7fab694c 100644
--- a/examples/widgets/icons/images/monkey_off_32x32.png
+++ b/examples/widgets/widgets/icons/images/monkey_off_32x32.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_off_64x64.png b/examples/widgets/widgets/icons/images/monkey_off_64x64.png
index 47d8f6de35..47d8f6de35 100644
--- a/examples/widgets/icons/images/monkey_off_64x64.png
+++ b/examples/widgets/widgets/icons/images/monkey_off_64x64.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_on_128x128.png b/examples/widgets/widgets/icons/images/monkey_on_128x128.png
index 8e1c7468bf..8e1c7468bf 100644
--- a/examples/widgets/icons/images/monkey_on_128x128.png
+++ b/examples/widgets/widgets/icons/images/monkey_on_128x128.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_on_16x16.png b/examples/widgets/widgets/icons/images/monkey_on_16x16.png
index 082e8527f1..082e8527f1 100644
--- a/examples/widgets/icons/images/monkey_on_16x16.png
+++ b/examples/widgets/widgets/icons/images/monkey_on_16x16.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_on_32x32.png b/examples/widgets/widgets/icons/images/monkey_on_32x32.png
index bf9acc6cae..bf9acc6cae 100644
--- a/examples/widgets/icons/images/monkey_on_32x32.png
+++ b/examples/widgets/widgets/icons/images/monkey_on_32x32.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_on_64x64.png b/examples/widgets/widgets/icons/images/monkey_on_64x64.png
index 990f604d98..990f604d98 100644
--- a/examples/widgets/icons/images/monkey_on_64x64.png
+++ b/examples/widgets/widgets/icons/images/monkey_on_64x64.png
Binary files differ
diff --git a/examples/widgets/icons/images/qt_extended_16x16.png b/examples/widgets/widgets/icons/images/qt_extended_16x16.png
index 95d3bae838..95d3bae838 100644
--- a/examples/widgets/icons/images/qt_extended_16x16.png
+++ b/examples/widgets/widgets/icons/images/qt_extended_16x16.png
Binary files differ
diff --git a/examples/widgets/icons/images/qt_extended_32x32.png b/examples/widgets/widgets/icons/images/qt_extended_32x32.png
index 7b7a790c12..7b7a790c12 100644
--- a/examples/widgets/icons/images/qt_extended_32x32.png
+++ b/examples/widgets/widgets/icons/images/qt_extended_32x32.png
Binary files differ
diff --git a/examples/widgets/icons/images/qt_extended_48x48.png b/examples/widgets/widgets/icons/images/qt_extended_48x48.png
index 8434dc26db..8434dc26db 100644
--- a/examples/widgets/icons/images/qt_extended_48x48.png
+++ b/examples/widgets/widgets/icons/images/qt_extended_48x48.png
Binary files differ
diff --git a/examples/widgets/icons/main.cpp b/examples/widgets/widgets/icons/main.cpp
index e96d256e9b..e96d256e9b 100644
--- a/examples/widgets/icons/main.cpp
+++ b/examples/widgets/widgets/icons/main.cpp
diff --git a/examples/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp
index 00f5a21854..00f5a21854 100644
--- a/examples/widgets/icons/mainwindow.cpp
+++ b/examples/widgets/widgets/icons/mainwindow.cpp
diff --git a/examples/widgets/icons/mainwindow.h b/examples/widgets/widgets/icons/mainwindow.h
index 8afaf9496e..8afaf9496e 100644
--- a/examples/widgets/icons/mainwindow.h
+++ b/examples/widgets/widgets/icons/mainwindow.h
diff --git a/examples/widgets/imageviewer/imageviewer.cpp b/examples/widgets/widgets/imageviewer/imageviewer.cpp
index 97ab1d77f8..97ab1d77f8 100644
--- a/examples/widgets/imageviewer/imageviewer.cpp
+++ b/examples/widgets/widgets/imageviewer/imageviewer.cpp
diff --git a/examples/widgets/imageviewer/imageviewer.desktop b/examples/widgets/widgets/imageviewer/imageviewer.desktop
index 63f2408c38..63f2408c38 100644
--- a/examples/widgets/imageviewer/imageviewer.desktop
+++ b/examples/widgets/widgets/imageviewer/imageviewer.desktop
diff --git a/examples/widgets/imageviewer/imageviewer.h b/examples/widgets/widgets/imageviewer/imageviewer.h
index 98300794a2..98300794a2 100644
--- a/examples/widgets/imageviewer/imageviewer.h
+++ b/examples/widgets/widgets/imageviewer/imageviewer.h
diff --git a/examples/widgets/imageviewer/imageviewer.pro b/examples/widgets/widgets/imageviewer/imageviewer.pro
index 15751ff3d9..15751ff3d9 100644
--- a/examples/widgets/imageviewer/imageviewer.pro
+++ b/examples/widgets/widgets/imageviewer/imageviewer.pro
diff --git a/examples/widgets/imageviewer/main.cpp b/examples/widgets/widgets/imageviewer/main.cpp
index 4d735d4c46..4d735d4c46 100644
--- a/examples/widgets/imageviewer/main.cpp
+++ b/examples/widgets/widgets/imageviewer/main.cpp
diff --git a/examples/widgets/lineedits/lineedits.desktop b/examples/widgets/widgets/lineedits/lineedits.desktop
index 7d8dea3ec0..7d8dea3ec0 100644
--- a/examples/widgets/lineedits/lineedits.desktop
+++ b/examples/widgets/widgets/lineedits/lineedits.desktop
diff --git a/examples/widgets/lineedits/lineedits.pro b/examples/widgets/widgets/lineedits/lineedits.pro
index 01d4b2f1b7..01d4b2f1b7 100644
--- a/examples/widgets/lineedits/lineedits.pro
+++ b/examples/widgets/widgets/lineedits/lineedits.pro
diff --git a/examples/widgets/widgets/lineedits/main.cpp b/examples/widgets/widgets/lineedits/main.cpp
new file mode 100644
index 0000000000..dcbf1c0449
--- /dev/null
+++ b/examples/widgets/widgets/lineedits/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/lineedits/window.cpp b/examples/widgets/widgets/lineedits/window.cpp
index 7628132e5b..7628132e5b 100644
--- a/examples/widgets/lineedits/window.cpp
+++ b/examples/widgets/widgets/lineedits/window.cpp
diff --git a/examples/widgets/lineedits/window.h b/examples/widgets/widgets/lineedits/window.h
index 82e5f9e965..82e5f9e965 100644
--- a/examples/widgets/lineedits/window.h
+++ b/examples/widgets/widgets/lineedits/window.h
diff --git a/examples/widgets/mousebuttons/buttontester.cpp b/examples/widgets/widgets/mousebuttons/buttontester.cpp
index 32f73ebb72..32f73ebb72 100644
--- a/examples/widgets/mousebuttons/buttontester.cpp
+++ b/examples/widgets/widgets/mousebuttons/buttontester.cpp
diff --git a/examples/widgets/mousebuttons/buttontester.h b/examples/widgets/widgets/mousebuttons/buttontester.h
index 0801a9ae5c..0801a9ae5c 100644
--- a/examples/widgets/mousebuttons/buttontester.h
+++ b/examples/widgets/widgets/mousebuttons/buttontester.h
diff --git a/examples/widgets/mousebuttons/main.cpp b/examples/widgets/widgets/mousebuttons/main.cpp
index 7c9674a9d9..7c9674a9d9 100644
--- a/examples/widgets/mousebuttons/main.cpp
+++ b/examples/widgets/widgets/mousebuttons/main.cpp
diff --git a/examples/widgets/mousebuttons/mousebuttons.pro b/examples/widgets/widgets/mousebuttons/mousebuttons.pro
index ed181d082c..ed181d082c 100644
--- a/examples/widgets/mousebuttons/mousebuttons.pro
+++ b/examples/widgets/widgets/mousebuttons/mousebuttons.pro
diff --git a/examples/widgets/movie/animation.gif b/examples/widgets/widgets/movie/animation.gif
index f674369efc..f674369efc 100644
--- a/examples/widgets/movie/animation.gif
+++ b/examples/widgets/widgets/movie/animation.gif
Binary files differ
diff --git a/examples/widgets/movie/main.cpp b/examples/widgets/widgets/movie/main.cpp
index f0d36bc04e..f0d36bc04e 100644
--- a/examples/widgets/movie/main.cpp
+++ b/examples/widgets/widgets/movie/main.cpp
diff --git a/examples/widgets/movie/movie.desktop b/examples/widgets/widgets/movie/movie.desktop
index 5c7ae21896..5c7ae21896 100644
--- a/examples/widgets/movie/movie.desktop
+++ b/examples/widgets/widgets/movie/movie.desktop
diff --git a/examples/widgets/movie/movie.pro b/examples/widgets/widgets/movie/movie.pro
index dd6e40b83c..dd6e40b83c 100644
--- a/examples/widgets/movie/movie.pro
+++ b/examples/widgets/widgets/movie/movie.pro
diff --git a/examples/widgets/movie/movieplayer.cpp b/examples/widgets/widgets/movie/movieplayer.cpp
index 885fbdd0c6..885fbdd0c6 100644
--- a/examples/widgets/movie/movieplayer.cpp
+++ b/examples/widgets/widgets/movie/movieplayer.cpp
diff --git a/examples/widgets/movie/movieplayer.h b/examples/widgets/widgets/movie/movieplayer.h
index f21fef5a92..f21fef5a92 100644
--- a/examples/widgets/movie/movieplayer.h
+++ b/examples/widgets/widgets/movie/movieplayer.h
diff --git a/examples/widgets/orientation/image_a.png b/examples/widgets/widgets/orientation/image_a.png
index 4a1a0d3252..4a1a0d3252 100644
--- a/examples/widgets/orientation/image_a.png
+++ b/examples/widgets/widgets/orientation/image_a.png
Binary files differ
diff --git a/examples/widgets/orientation/image_b.png b/examples/widgets/widgets/orientation/image_b.png
index 8722d1edee..8722d1edee 100644
--- a/examples/widgets/orientation/image_b.png
+++ b/examples/widgets/widgets/orientation/image_b.png
Binary files differ
diff --git a/examples/widgets/orientation/image_c.png b/examples/widgets/widgets/orientation/image_c.png
index 6c9304fda0..6c9304fda0 100644
--- a/examples/widgets/orientation/image_c.png
+++ b/examples/widgets/widgets/orientation/image_c.png
Binary files differ
diff --git a/examples/widgets/orientation/images.qrc b/examples/widgets/widgets/orientation/images.qrc
index b258291e6f..b258291e6f 100644
--- a/examples/widgets/orientation/images.qrc
+++ b/examples/widgets/widgets/orientation/images.qrc
diff --git a/examples/widgets/orientation/landscape.ui b/examples/widgets/widgets/orientation/landscape.ui
index 4616c041dc..4616c041dc 100644
--- a/examples/widgets/orientation/landscape.ui
+++ b/examples/widgets/widgets/orientation/landscape.ui
diff --git a/examples/widgets/orientation/main.cpp b/examples/widgets/widgets/orientation/main.cpp
index d92ae0c16f..d92ae0c16f 100644
--- a/examples/widgets/orientation/main.cpp
+++ b/examples/widgets/widgets/orientation/main.cpp
diff --git a/examples/widgets/orientation/mainwindow.cpp b/examples/widgets/widgets/orientation/mainwindow.cpp
index 3acbef12f8..3acbef12f8 100644
--- a/examples/widgets/orientation/mainwindow.cpp
+++ b/examples/widgets/widgets/orientation/mainwindow.cpp
diff --git a/examples/widgets/orientation/mainwindow.h b/examples/widgets/widgets/orientation/mainwindow.h
index d0f1b07242..d0f1b07242 100644
--- a/examples/widgets/orientation/mainwindow.h
+++ b/examples/widgets/widgets/orientation/mainwindow.h
diff --git a/examples/widgets/orientation/orientation.desktop b/examples/widgets/widgets/orientation/orientation.desktop
index 7bbf5584d3..7bbf5584d3 100644
--- a/examples/widgets/orientation/orientation.desktop
+++ b/examples/widgets/widgets/orientation/orientation.desktop
diff --git a/examples/widgets/orientation/orientation.pro b/examples/widgets/widgets/orientation/orientation.pro
index 36a3e91a9c..36a3e91a9c 100644
--- a/examples/widgets/orientation/orientation.pro
+++ b/examples/widgets/widgets/orientation/orientation.pro
diff --git a/examples/widgets/orientation/portrait.ui b/examples/widgets/widgets/orientation/portrait.ui
index 31a55aff73..31a55aff73 100644
--- a/examples/widgets/orientation/portrait.ui
+++ b/examples/widgets/widgets/orientation/portrait.ui
diff --git a/examples/widgets/widgets/scribble/main.cpp b/examples/widgets/widgets/scribble/main.cpp
new file mode 100644
index 0000000000..09a923477c
--- /dev/null
+++ b/examples/widgets/widgets/scribble/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/scribble/mainwindow.cpp b/examples/widgets/widgets/scribble/mainwindow.cpp
index 6db7b39b4c..6db7b39b4c 100644
--- a/examples/widgets/scribble/mainwindow.cpp
+++ b/examples/widgets/widgets/scribble/mainwindow.cpp
diff --git a/examples/widgets/scribble/mainwindow.h b/examples/widgets/widgets/scribble/mainwindow.h
index 54144340f3..54144340f3 100644
--- a/examples/widgets/scribble/mainwindow.h
+++ b/examples/widgets/widgets/scribble/mainwindow.h
diff --git a/examples/widgets/scribble/scribble.desktop b/examples/widgets/widgets/scribble/scribble.desktop
index 9c1ee0c482..9c1ee0c482 100644
--- a/examples/widgets/scribble/scribble.desktop
+++ b/examples/widgets/widgets/scribble/scribble.desktop
diff --git a/examples/widgets/scribble/scribble.pro b/examples/widgets/widgets/scribble/scribble.pro
index 9c6e3cb100..9c6e3cb100 100644
--- a/examples/widgets/scribble/scribble.pro
+++ b/examples/widgets/widgets/scribble/scribble.pro
diff --git a/examples/widgets/scribble/scribblearea.cpp b/examples/widgets/widgets/scribble/scribblearea.cpp
index ab527e1d63..ab527e1d63 100644
--- a/examples/widgets/scribble/scribblearea.cpp
+++ b/examples/widgets/widgets/scribble/scribblearea.cpp
diff --git a/examples/widgets/scribble/scribblearea.h b/examples/widgets/widgets/scribble/scribblearea.h
index c95cca7b8d..c95cca7b8d 100644
--- a/examples/widgets/scribble/scribblearea.h
+++ b/examples/widgets/widgets/scribble/scribblearea.h
diff --git a/examples/widgets/shapedclock/main.cpp b/examples/widgets/widgets/shapedclock/main.cpp
index 45ae5d14b7..45ae5d14b7 100644
--- a/examples/widgets/shapedclock/main.cpp
+++ b/examples/widgets/widgets/shapedclock/main.cpp
diff --git a/examples/widgets/shapedclock/shapedclock.cpp b/examples/widgets/widgets/shapedclock/shapedclock.cpp
index 20b98d134d..20b98d134d 100644
--- a/examples/widgets/shapedclock/shapedclock.cpp
+++ b/examples/widgets/widgets/shapedclock/shapedclock.cpp
diff --git a/examples/widgets/shapedclock/shapedclock.desktop b/examples/widgets/widgets/shapedclock/shapedclock.desktop
index bae58e30d5..bae58e30d5 100644
--- a/examples/widgets/shapedclock/shapedclock.desktop
+++ b/examples/widgets/widgets/shapedclock/shapedclock.desktop
diff --git a/examples/widgets/shapedclock/shapedclock.h b/examples/widgets/widgets/shapedclock/shapedclock.h
index b37ef69a8d..b37ef69a8d 100644
--- a/examples/widgets/shapedclock/shapedclock.h
+++ b/examples/widgets/widgets/shapedclock/shapedclock.h
diff --git a/examples/widgets/shapedclock/shapedclock.pro b/examples/widgets/widgets/shapedclock/shapedclock.pro
index 5bc1cb8706..5bc1cb8706 100644
--- a/examples/widgets/shapedclock/shapedclock.pro
+++ b/examples/widgets/widgets/shapedclock/shapedclock.pro
diff --git a/examples/widgets/widgets/sliders/main.cpp b/examples/widgets/widgets/sliders/main.cpp
new file mode 100644
index 0000000000..dcbf1c0449
--- /dev/null
+++ b/examples/widgets/widgets/sliders/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/sliders/sliders.desktop b/examples/widgets/widgets/sliders/sliders.desktop
index bc8904317b..bc8904317b 100644
--- a/examples/widgets/sliders/sliders.desktop
+++ b/examples/widgets/widgets/sliders/sliders.desktop
diff --git a/examples/widgets/sliders/sliders.pro b/examples/widgets/widgets/sliders/sliders.pro
index b0438072ec..b0438072ec 100644
--- a/examples/widgets/sliders/sliders.pro
+++ b/examples/widgets/widgets/sliders/sliders.pro
diff --git a/examples/widgets/sliders/slidersgroup.cpp b/examples/widgets/widgets/sliders/slidersgroup.cpp
index 6091db99ed..6091db99ed 100644
--- a/examples/widgets/sliders/slidersgroup.cpp
+++ b/examples/widgets/widgets/sliders/slidersgroup.cpp
diff --git a/examples/widgets/sliders/slidersgroup.h b/examples/widgets/widgets/sliders/slidersgroup.h
index ea1939cbc7..ea1939cbc7 100644
--- a/examples/widgets/sliders/slidersgroup.h
+++ b/examples/widgets/widgets/sliders/slidersgroup.h
diff --git a/examples/widgets/sliders/window.cpp b/examples/widgets/widgets/sliders/window.cpp
index ad4c4cb4d4..ad4c4cb4d4 100644
--- a/examples/widgets/sliders/window.cpp
+++ b/examples/widgets/widgets/sliders/window.cpp
diff --git a/examples/widgets/sliders/window.h b/examples/widgets/widgets/sliders/window.h
index 382f953e8d..382f953e8d 100644
--- a/examples/widgets/sliders/window.h
+++ b/examples/widgets/widgets/sliders/window.h
diff --git a/examples/widgets/softkeys/main.cpp b/examples/widgets/widgets/softkeys/main.cpp
index 8d30783556..8d30783556 100644
--- a/examples/widgets/softkeys/main.cpp
+++ b/examples/widgets/widgets/softkeys/main.cpp
diff --git a/examples/widgets/softkeys/softkeys.cpp b/examples/widgets/widgets/softkeys/softkeys.cpp
index 2b16ebf3b7..2b16ebf3b7 100644
--- a/examples/widgets/softkeys/softkeys.cpp
+++ b/examples/widgets/widgets/softkeys/softkeys.cpp
diff --git a/examples/widgets/softkeys/softkeys.desktop b/examples/widgets/widgets/softkeys/softkeys.desktop
index 7f4993a588..7f4993a588 100644
--- a/examples/widgets/softkeys/softkeys.desktop
+++ b/examples/widgets/widgets/softkeys/softkeys.desktop
diff --git a/examples/widgets/softkeys/softkeys.h b/examples/widgets/widgets/softkeys/softkeys.h
index 36991d35ed..36991d35ed 100644
--- a/examples/widgets/softkeys/softkeys.h
+++ b/examples/widgets/widgets/softkeys/softkeys.h
diff --git a/examples/widgets/softkeys/softkeys.pro b/examples/widgets/widgets/softkeys/softkeys.pro
index 5473069bb1..5473069bb1 100644
--- a/examples/widgets/softkeys/softkeys.pro
+++ b/examples/widgets/widgets/softkeys/softkeys.pro
diff --git a/examples/widgets/widgets/spinboxes/main.cpp b/examples/widgets/widgets/spinboxes/main.cpp
new file mode 100644
index 0000000000..dcbf1c0449
--- /dev/null
+++ b/examples/widgets/widgets/spinboxes/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/spinboxes/spinboxes.desktop b/examples/widgets/widgets/spinboxes/spinboxes.desktop
index 7de30383f2..7de30383f2 100644
--- a/examples/widgets/spinboxes/spinboxes.desktop
+++ b/examples/widgets/widgets/spinboxes/spinboxes.desktop
diff --git a/examples/widgets/spinboxes/spinboxes.pro b/examples/widgets/widgets/spinboxes/spinboxes.pro
index e19e33178d..e19e33178d 100644
--- a/examples/widgets/spinboxes/spinboxes.pro
+++ b/examples/widgets/widgets/spinboxes/spinboxes.pro
diff --git a/examples/widgets/spinboxes/window.cpp b/examples/widgets/widgets/spinboxes/window.cpp
index 1e01386d31..1e01386d31 100644
--- a/examples/widgets/spinboxes/window.cpp
+++ b/examples/widgets/widgets/spinboxes/window.cpp
diff --git a/examples/widgets/spinboxes/window.h b/examples/widgets/widgets/spinboxes/window.h
index 17f18e710d..17f18e710d 100644
--- a/examples/widgets/spinboxes/window.h
+++ b/examples/widgets/widgets/spinboxes/window.h
diff --git a/examples/widgets/styles/images/woodbackground.png b/examples/widgets/widgets/styles/images/woodbackground.png
index 8be3366bb4..8be3366bb4 100644
--- a/examples/widgets/styles/images/woodbackground.png
+++ b/examples/widgets/widgets/styles/images/woodbackground.png
Binary files differ
diff --git a/examples/widgets/styles/images/woodbutton.png b/examples/widgets/widgets/styles/images/woodbutton.png
index adb59ef633..adb59ef633 100644
--- a/examples/widgets/styles/images/woodbutton.png
+++ b/examples/widgets/widgets/styles/images/woodbutton.png
Binary files differ
diff --git a/examples/widgets/styles/main.cpp b/examples/widgets/widgets/styles/main.cpp
index 65d8459542..65d8459542 100644
--- a/examples/widgets/styles/main.cpp
+++ b/examples/widgets/widgets/styles/main.cpp
diff --git a/examples/widgets/styles/norwegianwoodstyle.cpp b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
index d609c54eb3..d609c54eb3 100644
--- a/examples/widgets/styles/norwegianwoodstyle.cpp
+++ b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
diff --git a/examples/widgets/styles/norwegianwoodstyle.h b/examples/widgets/widgets/styles/norwegianwoodstyle.h
index 99a206e753..99a206e753 100644
--- a/examples/widgets/styles/norwegianwoodstyle.h
+++ b/examples/widgets/widgets/styles/norwegianwoodstyle.h
diff --git a/examples/widgets/styles/styles.desktop b/examples/widgets/widgets/styles/styles.desktop
index fb9ef42994..fb9ef42994 100644
--- a/examples/widgets/styles/styles.desktop
+++ b/examples/widgets/widgets/styles/styles.desktop
diff --git a/examples/widgets/styles/styles.pro b/examples/widgets/widgets/styles/styles.pro
index fef1dc6084..fef1dc6084 100644
--- a/examples/widgets/styles/styles.pro
+++ b/examples/widgets/widgets/styles/styles.pro
diff --git a/examples/widgets/styles/styles.qrc b/examples/widgets/widgets/styles/styles.qrc
index 4fdad8d914..4fdad8d914 100644
--- a/examples/widgets/styles/styles.qrc
+++ b/examples/widgets/widgets/styles/styles.qrc
diff --git a/examples/widgets/styles/widgetgallery.cpp b/examples/widgets/widgets/styles/widgetgallery.cpp
index d00f689183..d00f689183 100644
--- a/examples/widgets/styles/widgetgallery.cpp
+++ b/examples/widgets/widgets/styles/widgetgallery.cpp
diff --git a/examples/widgets/styles/widgetgallery.h b/examples/widgets/widgets/styles/widgetgallery.h
index 93b5cce984..93b5cce984 100644
--- a/examples/widgets/styles/widgetgallery.h
+++ b/examples/widgets/widgets/styles/widgetgallery.h
diff --git a/examples/widgets/stylesheet/images/checkbox_checked.png b/examples/widgets/widgets/stylesheet/images/checkbox_checked.png
index cbf06f6513..cbf06f6513 100644
--- a/examples/widgets/stylesheet/images/checkbox_checked.png
+++ b/examples/widgets/widgets/stylesheet/images/checkbox_checked.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/checkbox_checked_hover.png b/examples/widgets/widgets/stylesheet/images/checkbox_checked_hover.png
index fb4d4d3fdb..fb4d4d3fdb 100644
--- a/examples/widgets/stylesheet/images/checkbox_checked_hover.png
+++ b/examples/widgets/widgets/stylesheet/images/checkbox_checked_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/checkbox_checked_pressed.png b/examples/widgets/widgets/stylesheet/images/checkbox_checked_pressed.png
index 852fcc0306..852fcc0306 100644
--- a/examples/widgets/stylesheet/images/checkbox_checked_pressed.png
+++ b/examples/widgets/widgets/stylesheet/images/checkbox_checked_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/checkbox_unchecked.png b/examples/widgets/widgets/stylesheet/images/checkbox_unchecked.png
index 5f5465582a..5f5465582a 100644
--- a/examples/widgets/stylesheet/images/checkbox_unchecked.png
+++ b/examples/widgets/widgets/stylesheet/images/checkbox_unchecked.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/checkbox_unchecked_hover.png b/examples/widgets/widgets/stylesheet/images/checkbox_unchecked_hover.png
index 687364497e..687364497e 100644
--- a/examples/widgets/stylesheet/images/checkbox_unchecked_hover.png
+++ b/examples/widgets/widgets/stylesheet/images/checkbox_unchecked_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/checkbox_unchecked_pressed.png b/examples/widgets/widgets/stylesheet/images/checkbox_unchecked_pressed.png
index 6a768c44de..6a768c44de 100644
--- a/examples/widgets/stylesheet/images/checkbox_unchecked_pressed.png
+++ b/examples/widgets/widgets/stylesheet/images/checkbox_unchecked_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/down_arrow.png b/examples/widgets/widgets/stylesheet/images/down_arrow.png
index 85004aeaf6..85004aeaf6 100644
--- a/examples/widgets/stylesheet/images/down_arrow.png
+++ b/examples/widgets/widgets/stylesheet/images/down_arrow.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/down_arrow_disabled.png b/examples/widgets/widgets/stylesheet/images/down_arrow_disabled.png
index d9eefed4c8..d9eefed4c8 100644
--- a/examples/widgets/stylesheet/images/down_arrow_disabled.png
+++ b/examples/widgets/widgets/stylesheet/images/down_arrow_disabled.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/frame.png b/examples/widgets/widgets/stylesheet/images/frame.png
index 05a600502e..05a600502e 100644
--- a/examples/widgets/stylesheet/images/frame.png
+++ b/examples/widgets/widgets/stylesheet/images/frame.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/pagefold.png b/examples/widgets/widgets/stylesheet/images/pagefold.png
index 69be8f2a38..69be8f2a38 100644
--- a/examples/widgets/stylesheet/images/pagefold.png
+++ b/examples/widgets/widgets/stylesheet/images/pagefold.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/pushbutton.png b/examples/widgets/widgets/stylesheet/images/pushbutton.png
index c7529ba02d..c7529ba02d 100644
--- a/examples/widgets/stylesheet/images/pushbutton.png
+++ b/examples/widgets/widgets/stylesheet/images/pushbutton.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/pushbutton_hover.png b/examples/widgets/widgets/stylesheet/images/pushbutton_hover.png
index af0ef9d561..af0ef9d561 100644
--- a/examples/widgets/stylesheet/images/pushbutton_hover.png
+++ b/examples/widgets/widgets/stylesheet/images/pushbutton_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/pushbutton_pressed.png b/examples/widgets/widgets/stylesheet/images/pushbutton_pressed.png
index f7381f752a..f7381f752a 100644
--- a/examples/widgets/stylesheet/images/pushbutton_pressed.png
+++ b/examples/widgets/widgets/stylesheet/images/pushbutton_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_checked.png b/examples/widgets/widgets/stylesheet/images/radiobutton_checked.png
index 8ab9157578..8ab9157578 100644
--- a/examples/widgets/stylesheet/images/radiobutton_checked.png
+++ b/examples/widgets/widgets/stylesheet/images/radiobutton_checked.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_checked_hover.png b/examples/widgets/widgets/stylesheet/images/radiobutton_checked_hover.png
index d68cb009a7..d68cb009a7 100644
--- a/examples/widgets/stylesheet/images/radiobutton_checked_hover.png
+++ b/examples/widgets/widgets/stylesheet/images/radiobutton_checked_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_checked_pressed.png b/examples/widgets/widgets/stylesheet/images/radiobutton_checked_pressed.png
index e3cd5a59e4..e3cd5a59e4 100644
--- a/examples/widgets/stylesheet/images/radiobutton_checked_pressed.png
+++ b/examples/widgets/widgets/stylesheet/images/radiobutton_checked_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_unchecked.png b/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked.png
index 321a9a1558..321a9a1558 100644
--- a/examples/widgets/stylesheet/images/radiobutton_unchecked.png
+++ b/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_unchecked_hover.png b/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_hover.png
index 666a3b0bdd..666a3b0bdd 100644
--- a/examples/widgets/stylesheet/images/radiobutton_unchecked_hover.png
+++ b/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_unchecked_pressed.png b/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_pressed.png
index c4b0567aa9..c4b0567aa9 100644
--- a/examples/widgets/stylesheet/images/radiobutton_unchecked_pressed.png
+++ b/examples/widgets/widgets/stylesheet/images/radiobutton_unchecked_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/sizegrip.png b/examples/widgets/widgets/stylesheet/images/sizegrip.png
index 350583aaac..350583aaac 100644
--- a/examples/widgets/stylesheet/images/sizegrip.png
+++ b/examples/widgets/widgets/stylesheet/images/sizegrip.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spindown.png b/examples/widgets/widgets/stylesheet/images/spindown.png
index 7ff3c64926..7ff3c64926 100644
--- a/examples/widgets/stylesheet/images/spindown.png
+++ b/examples/widgets/widgets/stylesheet/images/spindown.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spindown_hover.png b/examples/widgets/widgets/stylesheet/images/spindown_hover.png
index 1486c4dfe4..1486c4dfe4 100644
--- a/examples/widgets/stylesheet/images/spindown_hover.png
+++ b/examples/widgets/widgets/stylesheet/images/spindown_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spindown_off.png b/examples/widgets/widgets/stylesheet/images/spindown_off.png
index a90ab3f038..a90ab3f038 100644
--- a/examples/widgets/stylesheet/images/spindown_off.png
+++ b/examples/widgets/widgets/stylesheet/images/spindown_off.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spindown_pressed.png b/examples/widgets/widgets/stylesheet/images/spindown_pressed.png
index f6271cbde2..f6271cbde2 100644
--- a/examples/widgets/stylesheet/images/spindown_pressed.png
+++ b/examples/widgets/widgets/stylesheet/images/spindown_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spinup.png b/examples/widgets/widgets/stylesheet/images/spinup.png
index 1069dd00df..1069dd00df 100644
--- a/examples/widgets/stylesheet/images/spinup.png
+++ b/examples/widgets/widgets/stylesheet/images/spinup.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spinup_hover.png b/examples/widgets/widgets/stylesheet/images/spinup_hover.png
index 884c8d77c5..884c8d77c5 100644
--- a/examples/widgets/stylesheet/images/spinup_hover.png
+++ b/examples/widgets/widgets/stylesheet/images/spinup_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spinup_off.png b/examples/widgets/widgets/stylesheet/images/spinup_off.png
index 02dad1fb29..02dad1fb29 100644
--- a/examples/widgets/stylesheet/images/spinup_off.png
+++ b/examples/widgets/widgets/stylesheet/images/spinup_off.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spinup_pressed.png b/examples/widgets/widgets/stylesheet/images/spinup_pressed.png
index b1843e2a1f..b1843e2a1f 100644
--- a/examples/widgets/stylesheet/images/spinup_pressed.png
+++ b/examples/widgets/widgets/stylesheet/images/spinup_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/up_arrow.png b/examples/widgets/widgets/stylesheet/images/up_arrow.png
index e7f7ddb3a6..e7f7ddb3a6 100644
--- a/examples/widgets/stylesheet/images/up_arrow.png
+++ b/examples/widgets/widgets/stylesheet/images/up_arrow.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/up_arrow_disabled.png b/examples/widgets/widgets/stylesheet/images/up_arrow_disabled.png
index 4d2c27770f..4d2c27770f 100644
--- a/examples/widgets/stylesheet/images/up_arrow_disabled.png
+++ b/examples/widgets/widgets/stylesheet/images/up_arrow_disabled.png
Binary files differ
diff --git a/examples/widgets/stylesheet/layouts/default.ui b/examples/widgets/widgets/stylesheet/layouts/default.ui
index 431a40956e..431a40956e 100644
--- a/examples/widgets/stylesheet/layouts/default.ui
+++ b/examples/widgets/widgets/stylesheet/layouts/default.ui
diff --git a/examples/widgets/stylesheet/layouts/pagefold.ui b/examples/widgets/widgets/stylesheet/layouts/pagefold.ui
index 7ae313c331..7ae313c331 100644
--- a/examples/widgets/stylesheet/layouts/pagefold.ui
+++ b/examples/widgets/widgets/stylesheet/layouts/pagefold.ui
diff --git a/examples/widgets/stylesheet/main.cpp b/examples/widgets/widgets/stylesheet/main.cpp
index 0ddd63c298..0ddd63c298 100644
--- a/examples/widgets/stylesheet/main.cpp
+++ b/examples/widgets/widgets/stylesheet/main.cpp
diff --git a/examples/widgets/stylesheet/mainwindow.cpp b/examples/widgets/widgets/stylesheet/mainwindow.cpp
index 0732d78347..0732d78347 100644
--- a/examples/widgets/stylesheet/mainwindow.cpp
+++ b/examples/widgets/widgets/stylesheet/mainwindow.cpp
diff --git a/examples/widgets/stylesheet/mainwindow.h b/examples/widgets/widgets/stylesheet/mainwindow.h
index 2ccaf9ba02..2ccaf9ba02 100644
--- a/examples/widgets/stylesheet/mainwindow.h
+++ b/examples/widgets/widgets/stylesheet/mainwindow.h
diff --git a/examples/widgets/stylesheet/mainwindow.ui b/examples/widgets/widgets/stylesheet/mainwindow.ui
index cc29257afb..cc29257afb 100644
--- a/examples/widgets/stylesheet/mainwindow.ui
+++ b/examples/widgets/widgets/stylesheet/mainwindow.ui
diff --git a/examples/widgets/stylesheet/qss/coffee.qss b/examples/widgets/widgets/stylesheet/qss/coffee.qss
index 4571d42d7e..4571d42d7e 100644
--- a/examples/widgets/stylesheet/qss/coffee.qss
+++ b/examples/widgets/widgets/stylesheet/qss/coffee.qss
diff --git a/examples/widgets/stylesheet/qss/default.qss b/examples/widgets/widgets/stylesheet/qss/default.qss
index 84eb5e0bc2..84eb5e0bc2 100644
--- a/examples/widgets/stylesheet/qss/default.qss
+++ b/examples/widgets/widgets/stylesheet/qss/default.qss
diff --git a/examples/widgets/stylesheet/qss/pagefold.qss b/examples/widgets/widgets/stylesheet/qss/pagefold.qss
index 3701fc713c..3701fc713c 100644
--- a/examples/widgets/stylesheet/qss/pagefold.qss
+++ b/examples/widgets/widgets/stylesheet/qss/pagefold.qss
diff --git a/examples/widgets/stylesheet/stylesheet.desktop b/examples/widgets/widgets/stylesheet/stylesheet.desktop
index 0550b19ba2..0550b19ba2 100644
--- a/examples/widgets/stylesheet/stylesheet.desktop
+++ b/examples/widgets/widgets/stylesheet/stylesheet.desktop
diff --git a/examples/widgets/stylesheet/stylesheet.pro b/examples/widgets/widgets/stylesheet/stylesheet.pro
index 4d609a9210..4d609a9210 100644
--- a/examples/widgets/stylesheet/stylesheet.pro
+++ b/examples/widgets/widgets/stylesheet/stylesheet.pro
diff --git a/examples/widgets/stylesheet/stylesheet.qrc b/examples/widgets/widgets/stylesheet/stylesheet.qrc
index e1e61a920a..e1e61a920a 100644
--- a/examples/widgets/stylesheet/stylesheet.qrc
+++ b/examples/widgets/widgets/stylesheet/stylesheet.qrc
diff --git a/examples/widgets/stylesheet/stylesheeteditor.cpp b/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp
index 5514291a7f..5514291a7f 100644
--- a/examples/widgets/stylesheet/stylesheeteditor.cpp
+++ b/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp
diff --git a/examples/widgets/stylesheet/stylesheeteditor.h b/examples/widgets/widgets/stylesheet/stylesheeteditor.h
index 36b18d91fb..36b18d91fb 100644
--- a/examples/widgets/stylesheet/stylesheeteditor.h
+++ b/examples/widgets/widgets/stylesheet/stylesheeteditor.h
diff --git a/examples/widgets/stylesheet/stylesheeteditor.ui b/examples/widgets/widgets/stylesheet/stylesheeteditor.ui
index 34cd7f6d04..34cd7f6d04 100644
--- a/examples/widgets/stylesheet/stylesheeteditor.ui
+++ b/examples/widgets/widgets/stylesheet/stylesheeteditor.ui
diff --git a/examples/widgets/tablet/main.cpp b/examples/widgets/widgets/tablet/main.cpp
index bca3076cfc..bca3076cfc 100644
--- a/examples/widgets/tablet/main.cpp
+++ b/examples/widgets/widgets/tablet/main.cpp
diff --git a/examples/widgets/tablet/mainwindow.cpp b/examples/widgets/widgets/tablet/mainwindow.cpp
index 3b87346583..3b87346583 100644
--- a/examples/widgets/tablet/mainwindow.cpp
+++ b/examples/widgets/widgets/tablet/mainwindow.cpp
diff --git a/examples/widgets/tablet/mainwindow.h b/examples/widgets/widgets/tablet/mainwindow.h
index dcab683b4e..dcab683b4e 100644
--- a/examples/widgets/tablet/mainwindow.h
+++ b/examples/widgets/widgets/tablet/mainwindow.h
diff --git a/examples/widgets/tablet/tablet.desktop b/examples/widgets/widgets/tablet/tablet.desktop
index 9b40dc25d4..9b40dc25d4 100644
--- a/examples/widgets/tablet/tablet.desktop
+++ b/examples/widgets/widgets/tablet/tablet.desktop
diff --git a/examples/widgets/tablet/tablet.pro b/examples/widgets/widgets/tablet/tablet.pro
index 9ad533fc64..9ad533fc64 100644
--- a/examples/widgets/tablet/tablet.pro
+++ b/examples/widgets/widgets/tablet/tablet.pro
diff --git a/examples/widgets/tablet/tabletapplication.cpp b/examples/widgets/widgets/tablet/tabletapplication.cpp
index 68038d2f84..68038d2f84 100644
--- a/examples/widgets/tablet/tabletapplication.cpp
+++ b/examples/widgets/widgets/tablet/tabletapplication.cpp
diff --git a/examples/widgets/tablet/tabletapplication.h b/examples/widgets/widgets/tablet/tabletapplication.h
index 4f981b9074..4f981b9074 100644
--- a/examples/widgets/tablet/tabletapplication.h
+++ b/examples/widgets/widgets/tablet/tabletapplication.h
diff --git a/examples/widgets/tablet/tabletcanvas.cpp b/examples/widgets/widgets/tablet/tabletcanvas.cpp
index 184de57c64..184de57c64 100644
--- a/examples/widgets/tablet/tabletcanvas.cpp
+++ b/examples/widgets/widgets/tablet/tabletcanvas.cpp
diff --git a/examples/widgets/tablet/tabletcanvas.h b/examples/widgets/widgets/tablet/tabletcanvas.h
index c778578928..c778578928 100644
--- a/examples/widgets/tablet/tabletcanvas.h
+++ b/examples/widgets/widgets/tablet/tabletcanvas.h
diff --git a/examples/widgets/tetrix/main.cpp b/examples/widgets/widgets/tetrix/main.cpp
index fdf76a294c..fdf76a294c 100644
--- a/examples/widgets/tetrix/main.cpp
+++ b/examples/widgets/widgets/tetrix/main.cpp
diff --git a/examples/widgets/tetrix/tetrix.desktop b/examples/widgets/widgets/tetrix/tetrix.desktop
index 4d7a3de417..4d7a3de417 100644
--- a/examples/widgets/tetrix/tetrix.desktop
+++ b/examples/widgets/widgets/tetrix/tetrix.desktop
diff --git a/examples/widgets/tetrix/tetrix.pro b/examples/widgets/widgets/tetrix/tetrix.pro
index 6e8a270335..6e8a270335 100644
--- a/examples/widgets/tetrix/tetrix.pro
+++ b/examples/widgets/widgets/tetrix/tetrix.pro
diff --git a/examples/widgets/tetrix/tetrixboard.cpp b/examples/widgets/widgets/tetrix/tetrixboard.cpp
index ebc001826a..ebc001826a 100644
--- a/examples/widgets/tetrix/tetrixboard.cpp
+++ b/examples/widgets/widgets/tetrix/tetrixboard.cpp
diff --git a/examples/widgets/tetrix/tetrixboard.h b/examples/widgets/widgets/tetrix/tetrixboard.h
index 6a511325c5..6a511325c5 100644
--- a/examples/widgets/tetrix/tetrixboard.h
+++ b/examples/widgets/widgets/tetrix/tetrixboard.h
diff --git a/examples/widgets/tetrix/tetrixpiece.cpp b/examples/widgets/widgets/tetrix/tetrixpiece.cpp
index 26da0fca5b..26da0fca5b 100644
--- a/examples/widgets/tetrix/tetrixpiece.cpp
+++ b/examples/widgets/widgets/tetrix/tetrixpiece.cpp
diff --git a/examples/widgets/tetrix/tetrixpiece.h b/examples/widgets/widgets/tetrix/tetrixpiece.h
index 884b848e77..884b848e77 100644
--- a/examples/widgets/tetrix/tetrixpiece.h
+++ b/examples/widgets/widgets/tetrix/tetrixpiece.h
diff --git a/examples/widgets/tetrix/tetrixwindow.cpp b/examples/widgets/widgets/tetrix/tetrixwindow.cpp
index a6cea3555b..a6cea3555b 100644
--- a/examples/widgets/tetrix/tetrixwindow.cpp
+++ b/examples/widgets/widgets/tetrix/tetrixwindow.cpp
diff --git a/examples/widgets/tetrix/tetrixwindow.h b/examples/widgets/widgets/tetrix/tetrixwindow.h
index 521b9cc7c4..521b9cc7c4 100644
--- a/examples/widgets/tetrix/tetrixwindow.h
+++ b/examples/widgets/widgets/tetrix/tetrixwindow.h
diff --git a/examples/widgets/tooltips/images/circle.png b/examples/widgets/widgets/tooltips/images/circle.png
index dc392cb3f7..dc392cb3f7 100644
--- a/examples/widgets/tooltips/images/circle.png
+++ b/examples/widgets/widgets/tooltips/images/circle.png
Binary files differ
diff --git a/examples/widgets/tooltips/images/square.png b/examples/widgets/widgets/tooltips/images/square.png
index c0fd2d540a..c0fd2d540a 100644
--- a/examples/widgets/tooltips/images/square.png
+++ b/examples/widgets/widgets/tooltips/images/square.png
Binary files differ
diff --git a/examples/widgets/tooltips/images/triangle.png b/examples/widgets/widgets/tooltips/images/triangle.png
index 2ee15f8f1f..2ee15f8f1f 100644
--- a/examples/widgets/tooltips/images/triangle.png
+++ b/examples/widgets/widgets/tooltips/images/triangle.png
Binary files differ
diff --git a/examples/widgets/tooltips/main.cpp b/examples/widgets/widgets/tooltips/main.cpp
index c416eb19fd..c416eb19fd 100644
--- a/examples/widgets/tooltips/main.cpp
+++ b/examples/widgets/widgets/tooltips/main.cpp
diff --git a/examples/widgets/tooltips/shapeitem.cpp b/examples/widgets/widgets/tooltips/shapeitem.cpp
index c77df25119..c77df25119 100644
--- a/examples/widgets/tooltips/shapeitem.cpp
+++ b/examples/widgets/widgets/tooltips/shapeitem.cpp
diff --git a/examples/widgets/tooltips/shapeitem.h b/examples/widgets/widgets/tooltips/shapeitem.h
index f0d71a7c30..f0d71a7c30 100644
--- a/examples/widgets/tooltips/shapeitem.h
+++ b/examples/widgets/widgets/tooltips/shapeitem.h
diff --git a/examples/widgets/tooltips/sortingbox.cpp b/examples/widgets/widgets/tooltips/sortingbox.cpp
index 7c72dc41c5..7c72dc41c5 100644
--- a/examples/widgets/tooltips/sortingbox.cpp
+++ b/examples/widgets/widgets/tooltips/sortingbox.cpp
diff --git a/examples/widgets/tooltips/sortingbox.h b/examples/widgets/widgets/tooltips/sortingbox.h
index 318a1c459e..318a1c459e 100644
--- a/examples/widgets/tooltips/sortingbox.h
+++ b/examples/widgets/widgets/tooltips/sortingbox.h
diff --git a/examples/widgets/tooltips/tooltips.desktop b/examples/widgets/widgets/tooltips/tooltips.desktop
index 7dade26cc3..7dade26cc3 100644
--- a/examples/widgets/tooltips/tooltips.desktop
+++ b/examples/widgets/widgets/tooltips/tooltips.desktop
diff --git a/examples/widgets/tooltips/tooltips.pro b/examples/widgets/widgets/tooltips/tooltips.pro
index 76a6cd00f8..76a6cd00f8 100644
--- a/examples/widgets/tooltips/tooltips.pro
+++ b/examples/widgets/widgets/tooltips/tooltips.pro
diff --git a/examples/widgets/tooltips/tooltips.qrc b/examples/widgets/widgets/tooltips/tooltips.qrc
index dabc894e9b..dabc894e9b 100644
--- a/examples/widgets/tooltips/tooltips.qrc
+++ b/examples/widgets/widgets/tooltips/tooltips.qrc
diff --git a/examples/widgets/validators/ledoff.png b/examples/widgets/widgets/validators/ledoff.png
index 8b1f2ed123..8b1f2ed123 100644
--- a/examples/widgets/validators/ledoff.png
+++ b/examples/widgets/widgets/validators/ledoff.png
Binary files differ
diff --git a/examples/widgets/validators/ledon.png b/examples/widgets/widgets/validators/ledon.png
index 601c34d5a8..601c34d5a8 100644
--- a/examples/widgets/validators/ledon.png
+++ b/examples/widgets/widgets/validators/ledon.png
Binary files differ
diff --git a/examples/widgets/validators/ledwidget.cpp b/examples/widgets/widgets/validators/ledwidget.cpp
index a5f0454494..a5f0454494 100644
--- a/examples/widgets/validators/ledwidget.cpp
+++ b/examples/widgets/widgets/validators/ledwidget.cpp
diff --git a/examples/widgets/validators/ledwidget.h b/examples/widgets/widgets/validators/ledwidget.h
index 15bbeb23cd..15bbeb23cd 100644
--- a/examples/widgets/validators/ledwidget.h
+++ b/examples/widgets/widgets/validators/ledwidget.h
diff --git a/examples/widgets/validators/localeselector.cpp b/examples/widgets/widgets/validators/localeselector.cpp
index c367ca5d34..c367ca5d34 100644
--- a/examples/widgets/validators/localeselector.cpp
+++ b/examples/widgets/widgets/validators/localeselector.cpp
diff --git a/examples/widgets/validators/localeselector.h b/examples/widgets/widgets/validators/localeselector.h
index 6cec8d3bac..6cec8d3bac 100644
--- a/examples/widgets/validators/localeselector.h
+++ b/examples/widgets/widgets/validators/localeselector.h
diff --git a/examples/widgets/validators/main.cpp b/examples/widgets/widgets/validators/main.cpp
index 85304b9138..85304b9138 100644
--- a/examples/widgets/validators/main.cpp
+++ b/examples/widgets/widgets/validators/main.cpp
diff --git a/examples/widgets/validators/validators.desktop b/examples/widgets/widgets/validators/validators.desktop
index 073131632f..073131632f 100644
--- a/examples/widgets/validators/validators.desktop
+++ b/examples/widgets/widgets/validators/validators.desktop
diff --git a/examples/widgets/validators/validators.pro b/examples/widgets/widgets/validators/validators.pro
index 7970f961cd..7970f961cd 100644
--- a/examples/widgets/validators/validators.pro
+++ b/examples/widgets/widgets/validators/validators.pro
diff --git a/examples/widgets/validators/validators.qrc b/examples/widgets/widgets/validators/validators.qrc
index 94874317a8..94874317a8 100644
--- a/examples/widgets/validators/validators.qrc
+++ b/examples/widgets/widgets/validators/validators.qrc
diff --git a/examples/widgets/validators/validators.ui b/examples/widgets/widgets/validators/validators.ui
index cd984e6b97..cd984e6b97 100644
--- a/examples/widgets/validators/validators.ui
+++ b/examples/widgets/widgets/validators/validators.ui
diff --git a/examples/widgets/widgets/widgets.pro b/examples/widgets/widgets/widgets.pro
new file mode 100644
index 0000000000..65289da995
--- /dev/null
+++ b/examples/widgets/widgets/widgets.pro
@@ -0,0 +1,34 @@
+TEMPLATE = subdirs
+SUBDIRS = analogclock \
+ applicationicon \
+ calculator \
+ calendarwidget \
+ charactermap \
+ codeeditor \
+ digitalclock \
+ elidedlabel \
+ groupbox \
+ icons \
+ imageviewer \
+ lineedits \
+ movie \
+ mousebuttons \
+ orientation \
+ scribble \
+ shapedclock \
+ sliders \
+ spinboxes \
+ stylesheet \
+ tablet \
+ tetrix \
+ tooltips \
+ validators \
+ wiggly \
+ windowflags
+
+contains(styles, motif): SUBDIRS += styles
+
+# install
+sources.files = widgets.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets
+INSTALLS += sources
diff --git a/examples/widgets/wiggly/dialog.cpp b/examples/widgets/widgets/wiggly/dialog.cpp
index e808b77e87..e808b77e87 100644
--- a/examples/widgets/wiggly/dialog.cpp
+++ b/examples/widgets/widgets/wiggly/dialog.cpp
diff --git a/examples/widgets/wiggly/dialog.h b/examples/widgets/widgets/wiggly/dialog.h
index 84167d9153..84167d9153 100644
--- a/examples/widgets/wiggly/dialog.h
+++ b/examples/widgets/widgets/wiggly/dialog.h
diff --git a/examples/widgets/wiggly/main.cpp b/examples/widgets/widgets/wiggly/main.cpp
index ccf50e7411..ccf50e7411 100644
--- a/examples/widgets/wiggly/main.cpp
+++ b/examples/widgets/widgets/wiggly/main.cpp
diff --git a/examples/widgets/wiggly/wiggly.desktop b/examples/widgets/widgets/wiggly/wiggly.desktop
index b83e1ab3f0..b83e1ab3f0 100644
--- a/examples/widgets/wiggly/wiggly.desktop
+++ b/examples/widgets/widgets/wiggly/wiggly.desktop
diff --git a/examples/widgets/wiggly/wiggly.pro b/examples/widgets/widgets/wiggly/wiggly.pro
index 6b89cd1769..6b89cd1769 100644
--- a/examples/widgets/wiggly/wiggly.pro
+++ b/examples/widgets/widgets/wiggly/wiggly.pro
diff --git a/examples/widgets/wiggly/wigglywidget.cpp b/examples/widgets/widgets/wiggly/wigglywidget.cpp
index bf9a13cbca..bf9a13cbca 100644
--- a/examples/widgets/wiggly/wigglywidget.cpp
+++ b/examples/widgets/widgets/wiggly/wigglywidget.cpp
diff --git a/examples/widgets/wiggly/wigglywidget.h b/examples/widgets/widgets/wiggly/wigglywidget.h
index 9dae9cfb2e..9dae9cfb2e 100644
--- a/examples/widgets/wiggly/wigglywidget.h
+++ b/examples/widgets/widgets/wiggly/wigglywidget.h
diff --git a/examples/widgets/windowflags/controllerwindow.cpp b/examples/widgets/widgets/windowflags/controllerwindow.cpp
index 15d5bcf23b..15d5bcf23b 100644
--- a/examples/widgets/windowflags/controllerwindow.cpp
+++ b/examples/widgets/widgets/windowflags/controllerwindow.cpp
diff --git a/examples/widgets/windowflags/controllerwindow.h b/examples/widgets/widgets/windowflags/controllerwindow.h
index 7479fe8bee..7479fe8bee 100644
--- a/examples/widgets/windowflags/controllerwindow.h
+++ b/examples/widgets/widgets/windowflags/controllerwindow.h
diff --git a/examples/widgets/windowflags/main.cpp b/examples/widgets/widgets/windowflags/main.cpp
index 1cb90f7031..1cb90f7031 100644
--- a/examples/widgets/windowflags/main.cpp
+++ b/examples/widgets/widgets/windowflags/main.cpp
diff --git a/examples/widgets/windowflags/previewwindow.cpp b/examples/widgets/widgets/windowflags/previewwindow.cpp
index f8c297a41e..f8c297a41e 100644
--- a/examples/widgets/windowflags/previewwindow.cpp
+++ b/examples/widgets/widgets/windowflags/previewwindow.cpp
diff --git a/examples/widgets/windowflags/previewwindow.h b/examples/widgets/widgets/windowflags/previewwindow.h
index afe88957a0..afe88957a0 100644
--- a/examples/widgets/windowflags/previewwindow.h
+++ b/examples/widgets/widgets/windowflags/previewwindow.h
diff --git a/examples/widgets/windowflags/windowflags.desktop b/examples/widgets/widgets/windowflags/windowflags.desktop
index 27fd7bd364..27fd7bd364 100644
--- a/examples/widgets/windowflags/windowflags.desktop
+++ b/examples/widgets/widgets/windowflags/windowflags.desktop
diff --git a/examples/widgets/windowflags/windowflags.pro b/examples/widgets/widgets/windowflags/windowflags.pro
index b063b8ab2c..b063b8ab2c 100644
--- a/examples/widgets/windowflags/windowflags.pro
+++ b/examples/widgets/widgets/windowflags/windowflags.pro